]>
The Tcpdump Group git mirrors - tcpdump/blob - print-egp.c
51d78599abb2b738ec3fe5931c7aed27dd337bee
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).
21 /* \summary: Exterior Gateway Protocol (EGP) printer */
27 #include <netdissect-stdinc.h>
29 #include "netdissect.h"
30 #include "addrtoname.h"
37 #define EGPT_ACQUIRE 3
43 #define EGPC_REQUEST 0
44 #define EGPC_CONFIRM 1
47 #define EGPC_CEASEACK 4
53 #define EGPS_PASSIVE 2
62 #define EGPS_UNSOL 0x80
63 uint16_t egp_checksum
;
65 uint16_t egp_sequence
;
71 #define EGPR_BADHEAD 1
72 #define EGPR_BADDATA 2
73 #define EGPR_NOREACH 3
76 #define EGPR_UVERSION 6
78 #define egp_hello egp_handg.egpu_hello
79 #define egp_intgw egp_handg.egpu_gws[0]
80 #define egp_extgw egp_handg.egpu_gws[1]
81 #define egp_reason egp_handg.egpu_reason
84 uint32_t egpu_sourcenet
;
86 #define egp_poll egp_pands.egpu_poll
87 #define egp_sourcenet egp_pands.egpu_sourcenet
90 static const char *egp_acquire_codes
[] = {
98 static const char *egp_acquire_status
[] = {
102 "insufficient_resources",
103 "administratively_prohibited",
105 "parameter_violation",
109 static const char *egp_reach_codes
[] = {
114 static const char *egp_status_updown
[] = {
120 static const char *egp_reasons
[] = {
122 "bad_EGP_header_format",
123 "bad_EGP_data_field_format",
124 "reachability_info_unavailable",
125 "excessive_polling_rate",
127 "unsupported_version"
131 egpnrprint(netdissect_options
*ndo
,
132 register const struct egp_packet
*egp
, u_int length
)
134 register const uint8_t *cp
;
136 register uint32_t net
;
137 register u_int netlen
;
138 int gateways
, distances
, networks
;
142 addr
= egp
->egp_sourcenet
;
143 if (IN_CLASSA(addr
)) {
144 net
= addr
& IN_CLASSA_NET
;
146 } else if (IN_CLASSB(addr
)) {
147 net
= addr
& IN_CLASSB_NET
;
149 } else if (IN_CLASSC(addr
)) {
150 net
= addr
& IN_CLASSC_NET
;
156 cp
= (const uint8_t *)(egp
+ 1);
157 length
-= sizeof(*egp
);
159 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
160 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
161 /* Pickup host part of gateway address */
163 if (length
< 4 - netlen
)
165 ND_TCHECK2(cp
[0], 4 - netlen
);
169 addr
= EXTRACT_8BITS(cp
);
173 addr
= (addr
<< 8) | *cp
++;
176 addr
= (addr
<< 8) | *cp
++;
179 length
-= 4 - netlen
;
182 ND_TCHECK2(cp
[0], 1);
183 distances
= EXTRACT_8BITS(cp
);
186 ND_PRINT((ndo
, " %s %s ",
187 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
188 ipaddr_string(ndo
, &addr
)));
191 ND_PRINT((ndo
, "("));
192 while (--distances
>= 0) {
195 ND_TCHECK2(cp
[0], 2);
196 ND_PRINT((ndo
, "%sd%d:", comma
, (int)*cp
++));
198 networks
= EXTRACT_8BITS(cp
);
201 while (--networks
>= 0) {
202 /* Pickup network number */
205 ND_TCHECK2(cp
[0], 1);
206 addr
= (uint32_t)*cp
++ << 24;
208 if (IN_CLASSB(addr
)) {
211 ND_TCHECK2(cp
[0], 1);
212 addr
|= (uint32_t)*cp
++ << 16;
214 } else if (!IN_CLASSA(addr
)) {
217 ND_TCHECK2(cp
[0], 2);
218 addr
|= (uint32_t)*cp
++ << 16;
219 addr
|= (uint32_t)*cp
++ << 8;
222 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &addr
)));
225 ND_PRINT((ndo
, ")"));
229 ND_PRINT((ndo
, "[|]"));
233 egp_print(netdissect_options
*ndo
,
234 register const uint8_t *bp
, register u_int length
)
236 register const struct egp_packet
*egp
;
241 egp
= (const struct egp_packet
*)bp
;
242 if (length
< sizeof(*egp
) || !ND_TTEST(*egp
)) {
243 ND_PRINT((ndo
, "[|egp]"));
247 if (!ndo
->ndo_vflag
) {
248 ND_PRINT((ndo
, "EGPv%u, AS %u, seq %u, length %u",
250 EXTRACT_BE_16BITS(&egp
->egp_as
),
251 EXTRACT_BE_16BITS(&egp
->egp_sequence
),
255 ND_PRINT((ndo
, "EGPv%u, length %u",
259 if (egp
->egp_version
!= EGP_VERSION
) {
260 ND_PRINT((ndo
, "[version %d]", egp
->egp_version
));
264 type
= egp
->egp_type
;
265 code
= egp
->egp_code
;
266 status
= egp
->egp_status
;
270 ND_PRINT((ndo
, " acquire"));
274 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
279 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
283 ND_PRINT((ndo
, " [status %d]", status
));
286 ND_PRINT((ndo
, " hello:%d poll:%d",
287 EXTRACT_BE_16BITS(&egp
->egp_hello
),
288 EXTRACT_BE_16BITS(&egp
->egp_poll
)));
294 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
302 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
306 ND_PRINT((ndo
, "[status %d]", status
));
312 ND_PRINT((ndo
, "[code %d]", code
));
322 ND_PRINT((ndo
, " %s", egp_reach_codes
[code
]));
323 if (status
<= EGPS_DOWN
)
324 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
326 ND_PRINT((ndo
, " [status %d]", status
));
330 ND_PRINT((ndo
, "[reach code %d]", code
));
336 ND_PRINT((ndo
, " poll"));
337 if (egp
->egp_status
<= EGPS_DOWN
)
338 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
340 ND_PRINT((ndo
, " [status %d]", status
));
341 ND_PRINT((ndo
, " net:%s", ipaddr_string(ndo
, &egp
->egp_sourcenet
)));
345 ND_PRINT((ndo
, " update"));
346 if (status
& EGPS_UNSOL
) {
347 status
&= ~EGPS_UNSOL
;
348 ND_PRINT((ndo
, " unsolicited"));
350 if (status
<= EGPS_DOWN
)
351 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
353 ND_PRINT((ndo
, " [status %d]", status
));
354 ND_PRINT((ndo
, " %s int %d ext %d",
355 ipaddr_string(ndo
, &egp
->egp_sourcenet
),
359 egpnrprint(ndo
, egp
, length
);
363 ND_PRINT((ndo
, " error"));
364 if (status
<= EGPS_DOWN
)
365 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
367 ND_PRINT((ndo
, " [status %d]", status
));
369 if (EXTRACT_BE_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
370 ND_PRINT((ndo
, " %s", egp_reasons
[EXTRACT_BE_16BITS(&egp
->egp_reason
)]));
372 ND_PRINT((ndo
, " [reason %d]", EXTRACT_BE_16BITS(&egp
->egp_reason
)));
376 ND_PRINT((ndo
, "[type %d]", type
));