]>
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 */
23 /* specification: RFC 827 */
31 #include "netdissect-stdinc.h"
33 #include "netdissect.h"
34 #include "addrtoname.h"
38 nd_uint8_t egp_version
;
41 #define EGPT_ACQUIRE 3
47 #define EGPC_REQUEST 0
48 #define EGPC_CONFIRM 1
51 #define EGPC_CEASEACK 4
54 nd_uint8_t egp_status
;
57 #define EGPS_PASSIVE 2
66 #define EGPS_UNSOL 0x80
67 nd_uint16_t egp_checksum
;
69 nd_uint16_t egp_sequence
;
71 nd_uint16_t egpu_hello
;
72 nd_uint8_t egpu_gws
[2];
73 nd_uint16_t egpu_reason
;
75 #define EGPR_BADHEAD 1
76 #define EGPR_BADDATA 2
77 #define EGPR_NOREACH 3
80 #define EGPR_UVERSION 6
82 #define egp_hello egp_handg.egpu_hello
83 #define egp_intgw egp_handg.egpu_gws[0]
84 #define egp_extgw egp_handg.egpu_gws[1]
85 #define egp_reason egp_handg.egpu_reason
87 nd_uint16_t egpu_poll
;
88 nd_ipv4 egpu_sourcenet
;
90 #define egp_poll egp_pands.egpu_poll
91 #define egp_sourcenet egp_pands.egpu_sourcenet
94 static const char *egp_acquire_codes
[] = {
102 static const char *egp_acquire_status
[] = {
106 "insufficient_resources",
107 "administratively_prohibited",
109 "parameter_violation",
113 static const char *egp_reach_codes
[] = {
118 static const char *egp_status_updown
[] = {
124 static const char *egp_reasons
[] = {
126 "bad_EGP_header_format",
127 "bad_EGP_data_field_format",
128 "reachability_info_unavailable",
129 "excessive_polling_rate",
131 "unsupported_version"
135 egpnrprint(netdissect_options
*ndo
,
136 const struct egp_packet
*egp
, u_int length
)
142 u_int gateways
, distances
, networks
;
143 u_int intgw
, extgw
, t_gateways
;
146 addr
= EXTRACT_IPV4_TO_NETWORK_ORDER(egp
->egp_sourcenet
);
147 if (IN_CLASSA(addr
)) {
148 net
= addr
& IN_CLASSA_NET
;
150 } else if (IN_CLASSB(addr
)) {
151 net
= addr
& IN_CLASSB_NET
;
153 } else if (IN_CLASSC(addr
)) {
154 net
= addr
& IN_CLASSC_NET
;
160 cp
= (const uint8_t *)(egp
+ 1);
161 length
-= sizeof(*egp
);
163 intgw
= EXTRACT_U_1(egp
->egp_intgw
);
164 extgw
= EXTRACT_U_1(egp
->egp_extgw
);
165 t_gateways
= intgw
+ extgw
;
166 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
167 /* Pickup host part of gateway address */
169 if (length
< 4 - netlen
)
171 ND_TCHECK_LEN(cp
, 4 - netlen
);
175 addr
= EXTRACT_U_1(cp
);
179 addr
= (addr
<< 8) | EXTRACT_U_1(cp
);
183 addr
= (addr
<< 8) | EXTRACT_U_1(cp
);
188 length
-= 4 - netlen
;
192 distances
= EXTRACT_U_1(cp
);
196 gateways
< intgw
? "int" : "ext",
197 ipaddr_string(ndo
, (const u_char
*)&addr
));
201 while (distances
!= 0) {
205 ND_PRINT("%sd%u:", comma
, EXTRACT_U_1(cp
));
208 networks
= EXTRACT_U_1(cp
);
211 while (networks
!= 0) {
212 /* Pickup network number */
216 addr
= ((uint32_t) EXTRACT_U_1(cp
)) << 24;
219 if (IN_CLASSB(addr
)) {
223 addr
|= ((uint32_t) EXTRACT_U_1(cp
)) << 16;
226 } else if (!IN_CLASSA(addr
)) {
230 addr
|= ((uint32_t) EXTRACT_U_1(cp
)) << 16;
232 addr
|= ((uint32_t) EXTRACT_U_1(cp
)) << 8;
236 ND_PRINT(" %s", ipaddr_string(ndo
, (const u_char
*)&addr
));
249 egp_print(netdissect_options
*ndo
,
250 const uint8_t *bp
, u_int length
)
252 const struct egp_packet
*egp
;
258 ndo
->ndo_protocol
= "egp";
259 egp
= (const struct egp_packet
*)bp
;
260 if (length
< sizeof(*egp
) || !ND_TTEST_SIZE(egp
)) {
265 version
= EXTRACT_U_1(egp
->egp_version
);
266 if (!ndo
->ndo_vflag
) {
267 ND_PRINT("EGPv%u, AS %u, seq %u, length %u",
269 EXTRACT_BE_U_2(egp
->egp_as
),
270 EXTRACT_BE_U_2(egp
->egp_sequence
),
274 ND_PRINT("EGPv%u, length %u",
278 if (version
!= EGP_VERSION
) {
279 ND_PRINT("[version %u]", version
);
283 type
= EXTRACT_U_1(egp
->egp_type
);
284 code
= EXTRACT_U_1(egp
->egp_code
);
285 status
= EXTRACT_U_1(egp
->egp_status
);
289 ND_PRINT(" acquire");
293 ND_PRINT(" %s", egp_acquire_codes
[code
]);
298 ND_PRINT(" %s", egp_acquire_status
[status
]);
302 ND_PRINT(" [status %u]", status
);
305 ND_PRINT(" hello:%u poll:%u",
306 EXTRACT_BE_U_2(egp
->egp_hello
),
307 EXTRACT_BE_U_2(egp
->egp_poll
));
313 ND_PRINT(" %s", egp_acquire_codes
[code
]);
321 ND_PRINT(" %s", egp_acquire_status
[status
]);
325 ND_PRINT("[status %u]", status
);
331 ND_PRINT("[code %u]", code
);
341 ND_PRINT(" %s", egp_reach_codes
[code
]);
342 if (status
<= EGPS_DOWN
)
343 ND_PRINT(" state:%s", egp_status_updown
[status
]);
345 ND_PRINT(" [status %u]", status
);
349 ND_PRINT("[reach code %u]", code
);
356 if (status
<= EGPS_DOWN
)
357 ND_PRINT(" state:%s", egp_status_updown
[status
]);
359 ND_PRINT(" [status %u]", status
);
360 ND_PRINT(" net:%s", ipaddr_string(ndo
, egp
->egp_sourcenet
));
365 if (status
& EGPS_UNSOL
) {
366 status
&= ~EGPS_UNSOL
;
367 ND_PRINT(" unsolicited");
369 if (status
<= EGPS_DOWN
)
370 ND_PRINT(" state:%s", egp_status_updown
[status
]);
372 ND_PRINT(" [status %u]", status
);
373 ND_PRINT(" %s int %u ext %u",
374 ipaddr_string(ndo
, egp
->egp_sourcenet
),
375 EXTRACT_U_1(egp
->egp_intgw
),
376 EXTRACT_U_1(egp
->egp_extgw
));
378 egpnrprint(ndo
, egp
, length
);
383 if (status
<= EGPS_DOWN
)
384 ND_PRINT(" state:%s", egp_status_updown
[status
]);
386 ND_PRINT(" [status %u]", status
);
388 if (EXTRACT_BE_U_2(egp
->egp_reason
) <= EGPR_UVERSION
)
389 ND_PRINT(" %s", egp_reasons
[EXTRACT_BE_U_2(egp
->egp_reason
)]);
391 ND_PRINT(" [reason %u]", EXTRACT_BE_U_2(egp
->egp_reason
));
395 ND_PRINT("[type %u]", type
);