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 #define NETDISSECT_REWORKED
26 #include <tcpdump-stdinc.h>
28 #include "interface.h"
29 #include "addrtoname.h"
36 #define EGPT_ACQUIRE 3
42 #define EGPC_REQUEST 0
43 #define EGPC_CONFIRM 1
46 #define EGPC_CEASEACK 4
52 #define EGPS_PASSIVE 2
61 #define EGPS_UNSOL 0x80
62 uint16_t egp_checksum;
64 uint16_t egp_sequence;
70 #define EGPR_BADHEAD 1
71 #define EGPR_BADDATA 2
72 #define EGPR_NOREACH 3
75 #define EGPR_UVERSION 6
77 #define egp_hello egp_handg.egpu_hello
78 #define egp_intgw egp_handg.egpu_gws[0]
79 #define egp_extgw egp_handg.egpu_gws[1]
80 #define egp_reason egp_handg.egpu_reason
83 uint32_t egpu_sourcenet;
85 #define egp_poll egp_pands.egpu_poll
86 #define egp_sourcenet egp_pands.egpu_sourcenet
89 static const char *egp_acquire_codes[] = {
97 static const char *egp_acquire_status[] = {
101 "insufficient_resources",
102 "administratively_prohibited",
104 "parameter_violation",
108 static const char *egp_reach_codes[] = {
113 static const char *egp_status_updown[] = {
119 static const char *egp_reasons[] = {
121 "bad_EGP_header_format",
122 "bad_EGP_data_field_format",
123 "reachability_info_unavailable",
124 "excessive_polling_rate",
126 "unsupported_version"
130 egpnrprint(netdissect_options *ndo,
131 register const struct egp_packet *egp)
133 register const uint8_t *cp;
135 register uint32_t net;
136 register u_int netlen;
137 int gateways, distances, networks;
141 addr = egp->egp_sourcenet;
142 if (IN_CLASSA(addr)) {
143 net = addr & IN_CLASSA_NET;
145 } else if (IN_CLASSB(addr)) {
146 net = addr & IN_CLASSB_NET;
148 } else if (IN_CLASSC(addr)) {
149 net = addr & IN_CLASSC_NET;
155 cp = (uint8_t *)(egp + 1);
157 t_gateways = egp->egp_intgw + egp->egp_extgw;
158 for (gateways = 0; gateways < t_gateways; ++gateways) {
159 /* Pickup host part of gateway address */
161 ND_TCHECK2(cp[0], 4 - netlen);
168 addr = (addr << 8) | *cp++;
171 addr = (addr << 8) | *cp++;
174 ND_TCHECK2(cp[0], 1);
176 ND_PRINT((ndo, " %s %s ",
177 gateways < (int)egp->egp_intgw ? "int" : "ext",
178 ipaddr_string(ndo, &addr)));
181 ND_PRINT((ndo, "("));
182 while (--distances >= 0) {
183 ND_TCHECK2(cp[0], 2);
184 ND_PRINT((ndo, "%sd%d:", comma, (int)*cp++));
187 while (--networks >= 0) {
188 /* Pickup network number */
189 ND_TCHECK2(cp[0], 1);
190 addr = (uint32_t)*cp++ << 24;
191 if (IN_CLASSB(addr)) {
192 ND_TCHECK2(cp[0], 1);
193 addr |= (uint32_t)*cp++ << 16;
194 } else if (!IN_CLASSA(addr)) {
195 ND_TCHECK2(cp[0], 2);
196 addr |= (uint32_t)*cp++ << 16;
197 addr |= (uint32_t)*cp++ << 8;
199 ND_PRINT((ndo, " %s", ipaddr_string(ndo, &addr)));
202 ND_PRINT((ndo, ")"));
206 ND_PRINT((ndo, "[|]"));
210 egp_print(netdissect_options *ndo,
211 register const uint8_t *bp, register u_int length)
213 register const struct egp_packet *egp;
218 egp = (struct egp_packet *)bp;
219 if (!ND_TTEST2(*egp, length)) {
220 ND_PRINT((ndo, "[|egp]"));
224 if (!ndo->ndo_vflag) {
225 ND_PRINT((ndo, "EGPv%u, AS %u, seq %u, length %u",
227 EXTRACT_16BITS(&egp->egp_as),
228 EXTRACT_16BITS(&egp->egp_sequence),
232 ND_PRINT((ndo, "EGPv%u, length %u",
236 if (egp->egp_version != EGP_VERSION) {
237 ND_PRINT((ndo, "[version %d]", egp->egp_version));
241 type = egp->egp_type;
242 code = egp->egp_code;
243 status = egp->egp_status;
247 ND_PRINT((ndo, " acquire"));
251 ND_PRINT((ndo, " %s", egp_acquire_codes[code]));
256 ND_PRINT((ndo, " %s", egp_acquire_status[status]));
260 ND_PRINT((ndo, " [status %d]", status));
263 ND_PRINT((ndo, " hello:%d poll:%d",
264 EXTRACT_16BITS(&egp->egp_hello),
265 EXTRACT_16BITS(&egp->egp_poll)));
271 ND_PRINT((ndo, " %s", egp_acquire_codes[code]));
279 ND_PRINT((ndo, " %s", egp_acquire_status[status]));
283 ND_PRINT((ndo, "[status %d]", status));
289 ND_PRINT((ndo, "[code %d]", code));
299 ND_PRINT((ndo, " %s", egp_reach_codes[code]));
300 if (status <= EGPS_DOWN)
301 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
303 ND_PRINT((ndo, " [status %d]", status));
307 ND_PRINT((ndo, "[reach code %d]", code));
313 ND_PRINT((ndo, " poll"));
314 if (egp->egp_status <= EGPS_DOWN)
315 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
317 ND_PRINT((ndo, " [status %d]", status));
318 ND_PRINT((ndo, " net:%s", ipaddr_string(ndo, &egp->egp_sourcenet)));
322 ND_PRINT((ndo, " update"));
323 if (status & EGPS_UNSOL) {
324 status &= ~EGPS_UNSOL;
325 ND_PRINT((ndo, " unsolicited"));
327 if (status <= EGPS_DOWN)
328 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
330 ND_PRINT((ndo, " [status %d]", status));
331 ND_PRINT((ndo, " %s int %d ext %d",
332 ipaddr_string(ndo, &egp->egp_sourcenet),
336 egpnrprint(ndo, egp);
340 ND_PRINT((ndo, " error"));
341 if (status <= EGPS_DOWN)
342 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
344 ND_PRINT((ndo, " [status %d]", status));
346 if (EXTRACT_16BITS(&egp->egp_reason) <= EGPR_UVERSION)
347 ND_PRINT((ndo, " %s", egp_reasons[EXTRACT_16BITS(&egp->egp_reason)]));
349 ND_PRINT((ndo, " [reason %d]", EXTRACT_16BITS(&egp->egp_reason)));
353 ND_PRINT((ndo, "[type %d]", type));