]>
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).
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 const struct egp_packet
*egp
, u_int length
)
138 u_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_TCHECK_LEN(cp
, 4 - netlen
);
169 addr
= EXTRACT_U_1(cp
);
173 addr
= (addr
<< 8) | EXTRACT_U_1(cp
);
177 addr
= (addr
<< 8) | EXTRACT_U_1(cp
);
182 length
-= 4 - netlen
;
186 distances
= EXTRACT_U_1(cp
);
189 ND_PRINT((ndo
, " %s %s ",
190 gateways
< egp
->egp_intgw
? "int" : "ext",
191 ipaddr_string(ndo
, &addr
)));
194 ND_PRINT((ndo
, "("));
195 while (distances
!= 0) {
199 ND_PRINT((ndo
, "%sd%d:", comma
, EXTRACT_U_1(cp
)));
202 networks
= EXTRACT_U_1(cp
);
205 while (networks
!= 0) {
206 /* Pickup network number */
210 addr
= ((uint32_t) EXTRACT_U_1(cp
)) << 24;
213 if (IN_CLASSB(addr
)) {
217 addr
|= ((uint32_t) EXTRACT_U_1(cp
)) << 16;
220 } else if (!IN_CLASSA(addr
)) {
224 addr
|= ((uint32_t) EXTRACT_U_1(cp
)) << 16;
226 addr
|= ((uint32_t) EXTRACT_U_1(cp
)) << 8;
230 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &addr
)));
235 ND_PRINT((ndo
, ")"));
239 ND_PRINT((ndo
, "[|]"));
243 egp_print(netdissect_options
*ndo
,
244 const uint8_t *bp
, u_int length
)
246 const struct egp_packet
*egp
;
251 egp
= (const struct egp_packet
*)bp
;
252 if (length
< sizeof(*egp
) || !ND_TTEST(*egp
)) {
253 ND_PRINT((ndo
, "[|egp]"));
257 if (!ndo
->ndo_vflag
) {
258 ND_PRINT((ndo
, "EGPv%u, AS %u, seq %u, length %u",
260 EXTRACT_BE_U_2(&egp
->egp_as
),
261 EXTRACT_BE_U_2(&egp
->egp_sequence
),
265 ND_PRINT((ndo
, "EGPv%u, length %u",
269 if (egp
->egp_version
!= EGP_VERSION
) {
270 ND_PRINT((ndo
, "[version %d]", egp
->egp_version
));
274 type
= egp
->egp_type
;
275 code
= egp
->egp_code
;
276 status
= egp
->egp_status
;
280 ND_PRINT((ndo
, " acquire"));
284 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
289 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
293 ND_PRINT((ndo
, " [status %d]", status
));
296 ND_PRINT((ndo
, " hello:%d poll:%d",
297 EXTRACT_BE_U_2(&egp
->egp_hello
),
298 EXTRACT_BE_U_2(&egp
->egp_poll
)));
304 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
312 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
316 ND_PRINT((ndo
, "[status %d]", status
));
322 ND_PRINT((ndo
, "[code %d]", code
));
332 ND_PRINT((ndo
, " %s", egp_reach_codes
[code
]));
333 if (status
<= EGPS_DOWN
)
334 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
336 ND_PRINT((ndo
, " [status %d]", status
));
340 ND_PRINT((ndo
, "[reach code %d]", code
));
346 ND_PRINT((ndo
, " poll"));
347 if (egp
->egp_status
<= EGPS_DOWN
)
348 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
350 ND_PRINT((ndo
, " [status %d]", status
));
351 ND_PRINT((ndo
, " net:%s", ipaddr_string(ndo
, &egp
->egp_sourcenet
)));
355 ND_PRINT((ndo
, " update"));
356 if (status
& EGPS_UNSOL
) {
357 status
&= ~EGPS_UNSOL
;
358 ND_PRINT((ndo
, " unsolicited"));
360 if (status
<= EGPS_DOWN
)
361 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
363 ND_PRINT((ndo
, " [status %d]", status
));
364 ND_PRINT((ndo
, " %s int %d ext %d",
365 ipaddr_string(ndo
, &egp
->egp_sourcenet
),
369 egpnrprint(ndo
, egp
, length
);
373 ND_PRINT((ndo
, " error"));
374 if (status
<= EGPS_DOWN
)
375 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
377 ND_PRINT((ndo
, " [status %d]", status
));
379 if (EXTRACT_BE_U_2(&egp
->egp_reason
) <= EGPR_UVERSION
)
380 ND_PRINT((ndo
, " %s", egp_reasons
[EXTRACT_BE_U_2(&egp
->egp_reason
)]));
382 ND_PRINT((ndo
, " [reason %d]", EXTRACT_BE_U_2(&egp
->egp_reason
)));
386 ND_PRINT((ndo
, "[type %d]", type
));