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 #include <sys/cdefs.h>
23 __RCSID("$NetBSD: print-egp.c,v 1.4 2014/11/20 03:05:03 christos Exp $");
26 #define NETDISSECT_REWORKED
31 #include <tcpdump-stdinc.h>
33 #include "interface.h"
34 #include "addrtoname.h"
41 #define EGPT_ACQUIRE 3
47 #define EGPC_REQUEST 0
48 #define EGPC_CONFIRM 1
51 #define EGPC_CEASEACK 4
57 #define EGPS_PASSIVE 2
66 #define EGPS_UNSOL 0x80
67 uint16_t egp_checksum
;
69 uint16_t egp_sequence
;
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
88 uint32_t 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 register const struct egp_packet
*egp
)
138 register const uint8_t *cp
;
140 register uint32_t net
;
141 register u_int netlen
;
142 int gateways
, distances
, networks
;
146 addr
= 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
= (uint8_t *)(egp
+ 1);
162 t_gateways
= egp
->egp_intgw
+ egp
->egp_extgw
;
163 for (gateways
= 0; gateways
< t_gateways
; ++gateways
) {
164 /* Pickup host part of gateway address */
166 ND_TCHECK2(cp
[0], 4 - netlen
);
173 addr
= (addr
<< 8) | *cp
++;
176 addr
= (addr
<< 8) | *cp
++;
179 ND_TCHECK2(cp
[0], 1);
181 ND_PRINT((ndo
, " %s %s ",
182 gateways
< (int)egp
->egp_intgw
? "int" : "ext",
183 ipaddr_string(ndo
, &addr
)));
186 ND_PRINT((ndo
, "("));
187 while (--distances
>= 0) {
188 ND_TCHECK2(cp
[0], 2);
189 ND_PRINT((ndo
, "%sd%d:", comma
, (int)*cp
++));
192 while (--networks
>= 0) {
193 /* Pickup network number */
194 ND_TCHECK2(cp
[0], 1);
195 addr
= (uint32_t)*cp
++ << 24;
196 if (IN_CLASSB(addr
)) {
197 ND_TCHECK2(cp
[0], 1);
198 addr
|= (uint32_t)*cp
++ << 16;
199 } else if (!IN_CLASSA(addr
)) {
200 ND_TCHECK2(cp
[0], 2);
201 addr
|= (uint32_t)*cp
++ << 16;
202 addr
|= (uint32_t)*cp
++ << 8;
204 ND_PRINT((ndo
, " %s", ipaddr_string(ndo
, &addr
)));
207 ND_PRINT((ndo
, ")"));
211 ND_PRINT((ndo
, "[|]"));
215 egp_print(netdissect_options
*ndo
,
216 register const uint8_t *bp
, register u_int length
)
218 register const struct egp_packet
*egp
;
223 egp
= (struct egp_packet
*)bp
;
224 if (!ND_TTEST2(*egp
, length
)) {
225 ND_PRINT((ndo
, "[|egp]"));
229 if (!ndo
->ndo_vflag
) {
230 ND_PRINT((ndo
, "EGPv%u, AS %u, seq %u, length %u",
232 EXTRACT_16BITS(&egp
->egp_as
),
233 EXTRACT_16BITS(&egp
->egp_sequence
),
237 ND_PRINT((ndo
, "EGPv%u, length %u",
241 if (egp
->egp_version
!= EGP_VERSION
) {
242 ND_PRINT((ndo
, "[version %d]", egp
->egp_version
));
246 type
= egp
->egp_type
;
247 code
= egp
->egp_code
;
248 status
= egp
->egp_status
;
252 ND_PRINT((ndo
, " acquire"));
256 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
261 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
265 ND_PRINT((ndo
, " [status %d]", status
));
268 ND_PRINT((ndo
, " hello:%d poll:%d",
269 EXTRACT_16BITS(&egp
->egp_hello
),
270 EXTRACT_16BITS(&egp
->egp_poll
)));
276 ND_PRINT((ndo
, " %s", egp_acquire_codes
[code
]));
284 ND_PRINT((ndo
, " %s", egp_acquire_status
[status
]));
288 ND_PRINT((ndo
, "[status %d]", status
));
294 ND_PRINT((ndo
, "[code %d]", code
));
304 ND_PRINT((ndo
, " %s", egp_reach_codes
[code
]));
305 if (status
<= EGPS_DOWN
)
306 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
308 ND_PRINT((ndo
, " [status %d]", status
));
312 ND_PRINT((ndo
, "[reach code %d]", code
));
318 ND_PRINT((ndo
, " poll"));
319 if (egp
->egp_status
<= EGPS_DOWN
)
320 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
322 ND_PRINT((ndo
, " [status %d]", status
));
323 ND_PRINT((ndo
, " net:%s", ipaddr_string(ndo
, &egp
->egp_sourcenet
)));
327 ND_PRINT((ndo
, " update"));
328 if (status
& EGPS_UNSOL
) {
329 status
&= ~EGPS_UNSOL
;
330 ND_PRINT((ndo
, " unsolicited"));
332 if (status
<= EGPS_DOWN
)
333 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
335 ND_PRINT((ndo
, " [status %d]", status
));
336 ND_PRINT((ndo
, " %s int %d ext %d",
337 ipaddr_string(ndo
, &egp
->egp_sourcenet
),
341 egpnrprint(ndo
, egp
);
345 ND_PRINT((ndo
, " error"));
346 if (status
<= EGPS_DOWN
)
347 ND_PRINT((ndo
, " state:%s", egp_status_updown
[status
]));
349 ND_PRINT((ndo
, " [status %d]", status
));
351 if (EXTRACT_16BITS(&egp
->egp_reason
) <= EGPR_UVERSION
)
352 ND_PRINT((ndo
, " %s", egp_reasons
[EXTRACT_16BITS(&egp
->egp_reason
)]));
354 ND_PRINT((ndo
, " [reason %d]", EXTRACT_16BITS(&egp
->egp_reason
)));
358 ND_PRINT((ndo
, "[type %d]", type
));