]>
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 */
27 #include "netdissect-stdinc.h"
29 #include "netdissect.h"
30 #include "addrtoname.h"
34 nd_uint8_t egp_version
;
37 #define EGPT_ACQUIRE 3
43 #define EGPC_REQUEST 0
44 #define EGPC_CONFIRM 1
47 #define EGPC_CEASEACK 4
50 nd_uint8_t egp_status
;
53 #define EGPS_PASSIVE 2
62 #define EGPS_UNSOL 0x80
63 nd_uint16_t egp_checksum
;
65 nd_uint16_t egp_sequence
;
67 nd_uint16_t egpu_hello
;
68 nd_uint8_t egpu_gws
[2];
69 nd_uint16_t egpu_reason
;
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
83 nd_uint16_t egpu_poll
;
84 nd_ipv4 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 egpnr_print(netdissect_options
*ndo
,
132 const struct egp_packet
*egp
, u_int length
)
138 u_int gateways
, distances
, networks
;
139 u_int intgw
, extgw
, t_gateways
;
142 addr
= GET_IPV4_TO_NETWORK_ORDER(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 intgw
= GET_U_1(egp
->egp_intgw
);
160 extgw
= GET_U_1(egp
->egp_extgw
);
161 t_gateways
= intgw
+ extgw
;
162 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
163 /* Pickup host part of gateway address */
165 if (length
< 4 - netlen
)
167 ND_TCHECK_LEN(cp
, 4 - netlen
);
175 addr
= (addr
<< 8) | GET_U_1(cp
);
179 addr
= (addr
<< 8) | GET_U_1(cp
);
184 length
-= 4 - netlen
;
187 distances
= GET_U_1(cp
);
191 gateways
< intgw
? "int" : "ext",
192 ipaddr_string(ndo
, (const u_char
*)&addr
)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
196 while (distances
!= 0) {
199 ND_PRINT("%sd%u:", comma
, GET_U_1(cp
));
202 networks
= GET_U_1(cp
);
205 while (networks
!= 0) {
206 /* Pickup network number */
209 addr
= ((uint32_t) GET_U_1(cp
)) << 24;
212 if (IN_CLASSB(addr
)) {
215 addr
|= ((uint32_t) GET_U_1(cp
)) << 16;
218 } else if (!IN_CLASSA(addr
)) {
221 addr
|= ((uint32_t) GET_U_1(cp
)) << 16;
223 addr
|= ((uint32_t) GET_U_1(cp
)) << 8;
227 ND_PRINT(" %s", ipaddr_string(ndo
, (const u_char
*)&addr
)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
240 egp_print(netdissect_options
*ndo
,
241 const uint8_t *bp
, u_int length
)
243 const struct egp_packet
*egp
;
249 ndo
->ndo_protocol
= "egp";
250 egp
= (const struct egp_packet
*)bp
;
251 if (length
< sizeof(*egp
) || !ND_TTEST_SIZE(egp
)) {
256 version
= GET_U_1(egp
->egp_version
);
257 if (!ndo
->ndo_vflag
) {
258 ND_PRINT("EGPv%u, AS %u, seq %u, length %u",
260 GET_BE_U_2(egp
->egp_as
),
261 GET_BE_U_2(egp
->egp_sequence
),
265 ND_PRINT("EGPv%u, length %u",
269 if (version
!= EGP_VERSION
) {
270 ND_PRINT("[version %u]", version
);
274 type
= GET_U_1(egp
->egp_type
);
275 code
= GET_U_1(egp
->egp_code
);
276 status
= GET_U_1(egp
->egp_status
);
280 ND_PRINT(" acquire");
284 ND_PRINT(" %s", egp_acquire_codes
[code
]);
289 ND_PRINT(" %s", egp_acquire_status
[status
]);
293 ND_PRINT(" [status %u]", status
);
296 ND_PRINT(" hello:%u poll:%u",
297 GET_BE_U_2(egp
->egp_hello
),
298 GET_BE_U_2(egp
->egp_poll
));
304 ND_PRINT(" %s", egp_acquire_codes
[code
]);
312 ND_PRINT(" %s", egp_acquire_status
[status
]);
316 ND_PRINT("[status %u]", status
);
322 ND_PRINT("[code %u]", code
);
332 ND_PRINT(" %s", egp_reach_codes
[code
]);
333 if (status
<= EGPS_DOWN
)
334 ND_PRINT(" state:%s", egp_status_updown
[status
]);
336 ND_PRINT(" [status %u]", status
);
340 ND_PRINT("[reach code %u]", code
);
347 if (status
<= EGPS_DOWN
)
348 ND_PRINT(" state:%s", egp_status_updown
[status
]);
350 ND_PRINT(" [status %u]", status
);
351 ND_PRINT(" net:%s", GET_IPADDR_STRING(egp
->egp_sourcenet
));
356 if (status
& EGPS_UNSOL
) {
357 status
&= ~EGPS_UNSOL
;
358 ND_PRINT(" unsolicited");
360 if (status
<= EGPS_DOWN
)
361 ND_PRINT(" state:%s", egp_status_updown
[status
]);
363 ND_PRINT(" [status %u]", status
);
364 ND_PRINT(" %s int %u ext %u",
365 GET_IPADDR_STRING(egp
->egp_sourcenet
),
366 GET_U_1(egp
->egp_intgw
),
367 GET_U_1(egp
->egp_extgw
));
369 egpnr_print(ndo
, egp
, length
);
374 if (status
<= EGPS_DOWN
)
375 ND_PRINT(" state:%s", egp_status_updown
[status
]);
377 ND_PRINT(" [status %u]", status
);
379 if (GET_BE_U_2(egp
->egp_reason
) <= EGPR_UVERSION
)
381 egp_reasons
[GET_BE_U_2(egp
->egp_reason
)]);
383 ND_PRINT(" [reason %u]", GET_BE_U_2(egp
->egp_reason
));
387 ND_PRINT("[type %u]", type
);