]>
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 register const struct egp_packet
*egp
)
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);
158 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
159 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
160 /* Pickup host part of gateway address */
162 ND_TCHECK2(cp
[0], 4 - netlen
);
169 addr
= (addr
<< 8) | *cp
++;
172 addr
= (addr
<< 8) | *cp
++;
175 ND_TCHECK2(cp
[0], 1);
177 ND_PRINT((ndo
, " %s %s ",
178 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
179 ipaddr_string(ndo
, &addr
)));
182 ND_PRINT((ndo
, "("));
183 while (--distances
>= 0) {
184 ND_TCHECK2(cp
[0], 2);
185 ND_PRINT((ndo
, "%sd%d:", comma
, (int)*cp
++));
188 while (--networks
>= 0) {
189 /* Pickup network number */
190 ND_TCHECK2(cp
[0], 1);
191 addr
= (uint32_t)*cp
++ << 24;
192 if (IN_CLASSB(addr
)) {
193 ND_TCHECK2(cp
[0], 1);
194 addr
|= (uint32_t)*cp
++ << 16;
195 } else if (!IN_CLASSA(addr
)) {
196 ND_TCHECK2(cp
[0], 2);
197 addr
|= (uint32_t)*cp
++ << 16;
198 addr
|= (uint32_t)*cp
++ << 8;
200 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &addr
)));
203 ND_PRINT((ndo
, ")"));
207 ND_PRINT((ndo
, "[|]"));
211 egp_print(netdissect_options
*ndo
,
212 register const uint8_t *bp
, register u_int length
)
214 register const struct egp_packet
*egp
;
219 egp
= (const struct egp_packet
*)bp
;
220 if (!ND_TTEST2(*egp
, length
)) {
221 ND_PRINT((ndo
, "[|egp]"));
225 if (!ndo
->ndo_vflag
) {
226 ND_PRINT((ndo
, "EGPv%u, AS %u, seq %u, length %u",
228 EXTRACT_16BITS(&egp
->egp_as
),
229 EXTRACT_16BITS(&egp
->egp_sequence
),
233 ND_PRINT((ndo
, "EGPv%u, length %u",
237 if (egp
->egp_version
!= EGP_VERSION
) {
238 ND_PRINT((ndo
, "[version %d]", egp
->egp_version
));
242 type
= egp
->egp_type
;
243 code
= egp
->egp_code
;
244 status
= egp
->egp_status
;
248 ND_PRINT((ndo
, " acquire"));
252 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
257 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
261 ND_PRINT((ndo
, " [status %d]", status
));
264 ND_PRINT((ndo
, " hello:%d poll:%d",
265 EXTRACT_16BITS(&egp
->egp_hello
),
266 EXTRACT_16BITS(&egp
->egp_poll
)));
272 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
280 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
284 ND_PRINT((ndo
, "[status %d]", status
));
290 ND_PRINT((ndo
, "[code %d]", code
));
300 ND_PRINT((ndo
, " %s", egp_reach_codes
[code
]));
301 if (status
<= EGPS_DOWN
)
302 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
304 ND_PRINT((ndo
, " [status %d]", status
));
308 ND_PRINT((ndo
, "[reach code %d]", code
));
314 ND_PRINT((ndo
, " poll"));
315 if (egp
->egp_status
<= EGPS_DOWN
)
316 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
318 ND_PRINT((ndo
, " [status %d]", status
));
319 ND_PRINT((ndo
, " net:%s", ipaddr_string(ndo
, &egp
->egp_sourcenet
)));
323 ND_PRINT((ndo
, " update"));
324 if (status
& EGPS_UNSOL
) {
325 status
&= ~EGPS_UNSOL
;
326 ND_PRINT((ndo
, " unsolicited"));
328 if (status
<= EGPS_DOWN
)
329 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
331 ND_PRINT((ndo
, " [status %d]", status
));
332 ND_PRINT((ndo
, " %s int %d ext %d",
333 ipaddr_string(ndo
, &egp
->egp_sourcenet
),
337 egpnrprint(ndo
, egp
);
341 ND_PRINT((ndo
, " error"));
342 if (status
<= EGPS_DOWN
)
343 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
345 ND_PRINT((ndo
, " [status %d]", status
));
347 if (EXTRACT_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
348 ND_PRINT((ndo
, " %s", egp_reasons
[EXTRACT_16BITS(&egp
->egp_reason
)]));
350 ND_PRINT((ndo
, " [reason %d]", EXTRACT_16BITS(&egp
->egp_reason
)));
354 ND_PRINT((ndo
, "[type %d]", type
));