]>
The Tcpdump Group git mirrors - tcpdump/blob - print-egp.c
2 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms are permitted
6 * provided that the above copyright notice and this paragraph are
7 * duplicated in all such forms and that any documentation,
8 * advertising materials, and other materials related to such
9 * distribution and use acknowledge that the software was developed
10 * by the University of California, Lawrence Berkeley Laboratory,
11 * Berkeley, CA. The name of the University may not be used to
12 * endorse or promote products derived from this software without
13 * specific prior written permission.
14 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
18 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
25 #include <tcpdump-stdinc.h>
27 #include "interface.h"
28 #include "addrtoname.h"
35 #define EGPT_ACQUIRE 3
41 #define EGPC_REQUEST 0
42 #define EGPC_CONFIRM 1
45 #define EGPC_CEASEACK 4
51 #define EGPS_PASSIVE 2
60 #define EGPS_UNSOL 0x80
61 uint16_t egp_checksum
;
63 uint16_t egp_sequence
;
69 #define EGPR_BADHEAD 1
70 #define EGPR_BADDATA 2
71 #define EGPR_NOREACH 3
74 #define EGPR_UVERSION 6
76 #define egp_hello egp_handg.egpu_hello
77 #define egp_intgw egp_handg.egpu_gws[0]
78 #define egp_extgw egp_handg.egpu_gws[1]
79 #define egp_reason egp_handg.egpu_reason
82 uint32_t egpu_sourcenet
;
84 #define egp_poll egp_pands.egpu_poll
85 #define egp_sourcenet egp_pands.egpu_sourcenet
88 static const char *egp_acquire_codes
[] = {
96 static const char *egp_acquire_status
[] = {
100 "insufficient_resources",
101 "administratively_prohibited",
103 "parameter_violation",
107 static const char *egp_reach_codes
[] = {
112 static const char *egp_status_updown
[] = {
118 static const char *egp_reasons
[] = {
120 "bad_EGP_header_format",
121 "bad_EGP_data_field_format",
122 "reachability_info_unavailable",
123 "excessive_polling_rate",
125 "unsupported_version"
129 egpnrprint(netdissect_options
*ndo
,
130 register const struct egp_packet
*egp
)
132 register const uint8_t *cp
;
134 register uint32_t net
;
135 register u_int netlen
;
136 int gateways
, distances
, networks
;
140 addr
= egp
->egp_sourcenet
;
141 if (IN_CLASSA(addr
)) {
142 net
= addr
& IN_CLASSA_NET
;
144 } else if (IN_CLASSB(addr
)) {
145 net
= addr
& IN_CLASSB_NET
;
147 } else if (IN_CLASSC(addr
)) {
148 net
= addr
& IN_CLASSC_NET
;
154 cp
= (uint8_t *)(egp
+ 1);
156 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
157 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
158 /* Pickup host part of gateway address */
160 ND_TCHECK2(cp
[0], 4 - netlen
);
167 addr
= (addr
<< 8) | *cp
++;
170 addr
= (addr
<< 8) | *cp
++;
173 ND_TCHECK2(cp
[0], 1);
175 ND_PRINT((ndo
, " %s %s ",
176 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
177 ipaddr_string(ndo
, &addr
)));
180 ND_PRINT((ndo
, "("));
181 while (--distances
>= 0) {
182 ND_TCHECK2(cp
[0], 2);
183 ND_PRINT((ndo
, "%sd%d:", comma
, (int)*cp
++));
186 while (--networks
>= 0) {
187 /* Pickup network number */
188 ND_TCHECK2(cp
[0], 1);
189 addr
= (uint32_t)*cp
++ << 24;
190 if (IN_CLASSB(addr
)) {
191 ND_TCHECK2(cp
[0], 1);
192 addr
|= (uint32_t)*cp
++ << 16;
193 } else if (!IN_CLASSA(addr
)) {
194 ND_TCHECK2(cp
[0], 2);
195 addr
|= (uint32_t)*cp
++ << 16;
196 addr
|= (uint32_t)*cp
++ << 8;
198 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &addr
)));
201 ND_PRINT((ndo
, ")"));
205 ND_PRINT((ndo
, "[|]"));
209 egp_print(netdissect_options
*ndo
,
210 register const uint8_t *bp
, register u_int length
)
212 register const struct egp_packet
*egp
;
217 egp
= (struct egp_packet
*)bp
;
218 if (!ND_TTEST2(*egp
, length
)) {
219 ND_PRINT((ndo
, "[|egp]"));
223 if (!ndo
->ndo_vflag
) {
224 ND_PRINT((ndo
, "EGPv%u, AS %u, seq %u, length %u",
226 EXTRACT_16BITS(&egp
->egp_as
),
227 EXTRACT_16BITS(&egp
->egp_sequence
),
231 ND_PRINT((ndo
, "EGPv%u, length %u",
235 if (egp
->egp_version
!= EGP_VERSION
) {
236 ND_PRINT((ndo
, "[version %d]", egp
->egp_version
));
240 type
= egp
->egp_type
;
241 code
= egp
->egp_code
;
242 status
= egp
->egp_status
;
246 ND_PRINT((ndo
, " acquire"));
250 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
255 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
259 ND_PRINT((ndo
, " [status %d]", status
));
262 ND_PRINT((ndo
, " hello:%d poll:%d",
263 EXTRACT_16BITS(&egp
->egp_hello
),
264 EXTRACT_16BITS(&egp
->egp_poll
)));
270 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
278 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
282 ND_PRINT((ndo
, "[status %d]", status
));
288 ND_PRINT((ndo
, "[code %d]", code
));
298 ND_PRINT((ndo
, " %s", egp_reach_codes
[code
]));
299 if (status
<= EGPS_DOWN
)
300 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
302 ND_PRINT((ndo
, " [status %d]", status
));
306 ND_PRINT((ndo
, "[reach code %d]", code
));
312 ND_PRINT((ndo
, " poll"));
313 if (egp
->egp_status
<= EGPS_DOWN
)
314 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
316 ND_PRINT((ndo
, " [status %d]", status
));
317 ND_PRINT((ndo
, " net:%s", ipaddr_string(ndo
, &egp
->egp_sourcenet
)));
321 ND_PRINT((ndo
, " update"));
322 if (status
& EGPS_UNSOL
) {
323 status
&= ~EGPS_UNSOL
;
324 ND_PRINT((ndo
, " unsolicited"));
326 if (status
<= EGPS_DOWN
)
327 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
329 ND_PRINT((ndo
, " [status %d]", status
));
330 ND_PRINT((ndo
, " %s int %d ext %d",
331 ipaddr_string(ndo
, &egp
->egp_sourcenet
),
335 egpnrprint(ndo
, egp
);
339 ND_PRINT((ndo
, " error"));
340 if (status
<= EGPS_DOWN
)
341 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
343 ND_PRINT((ndo
, " [status %d]", status
));
345 if (EXTRACT_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
346 ND_PRINT((ndo
, " %s", egp_reasons
[EXTRACT_16BITS(&egp
->egp_reason
)]));
348 ND_PRINT((ndo
, " [reason %d]", EXTRACT_16BITS(&egp
->egp_reason
)));
352 ND_PRINT((ndo
, "[type %d]", type
));