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, u_int length)
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);
157 length -= sizeof(*egp);
159 t_gateways = egp->egp_intgw + egp->egp_extgw;
160 for (gateways = 0; gateways < t_gateways; ++gateways) {
161 /* Pickup host part of gateway address */
163 if (length < 4 - netlen)
165 ND_TCHECK2(cp[0], 4 - netlen);
172 addr = (addr << 8) | *cp++;
175 addr = (addr << 8) | *cp++;
178 length -= 4 - netlen;
181 ND_TCHECK2(cp[0], 1);
184 ND_PRINT((ndo, " %s %s ",
185 gateways < (int)egp->egp_intgw ? "int" : "ext",
186 ipaddr_string(ndo, &addr)));
189 ND_PRINT((ndo, "("));
190 while (--distances >= 0) {
193 ND_TCHECK2(cp[0], 2);
194 ND_PRINT((ndo, "%sd%d:", comma, (int)*cp++));
198 while (--networks >= 0) {
199 /* Pickup network number */
202 ND_TCHECK2(cp[0], 1);
203 addr = (uint32_t)*cp++ << 24;
205 if (IN_CLASSB(addr)) {
208 ND_TCHECK2(cp[0], 1);
209 addr |= (uint32_t)*cp++ << 16;
211 } else if (!IN_CLASSA(addr)) {
214 ND_TCHECK2(cp[0], 2);
215 addr |= (uint32_t)*cp++ << 16;
216 addr |= (uint32_t)*cp++ << 8;
219 ND_PRINT((ndo, " %s", ipaddr_string(ndo, &addr)));
222 ND_PRINT((ndo, ")"));
226 ND_PRINT((ndo, "[|]"));
230 egp_print(netdissect_options *ndo,
231 register const uint8_t *bp, register u_int length)
233 register const struct egp_packet *egp;
238 egp = (const struct egp_packet *)bp;
239 if (length < sizeof(*egp) || !ND_TTEST(*egp)) {
240 ND_PRINT((ndo, "[|egp]"));
244 if (!ndo->ndo_vflag) {
245 ND_PRINT((ndo, "EGPv%u, AS %u, seq %u, length %u",
247 EXTRACT_16BITS(&egp->egp_as),
248 EXTRACT_16BITS(&egp->egp_sequence),
252 ND_PRINT((ndo, "EGPv%u, length %u",
256 if (egp->egp_version != EGP_VERSION) {
257 ND_PRINT((ndo, "[version %d]", egp->egp_version));
261 type = egp->egp_type;
262 code = egp->egp_code;
263 status = egp->egp_status;
267 ND_PRINT((ndo, " acquire"));
271 ND_PRINT((ndo, " %s", egp_acquire_codes[code]));
276 ND_PRINT((ndo, " %s", egp_acquire_status[status]));
280 ND_PRINT((ndo, " [status %d]", status));
283 ND_PRINT((ndo, " hello:%d poll:%d",
284 EXTRACT_16BITS(&egp->egp_hello),
285 EXTRACT_16BITS(&egp->egp_poll)));
291 ND_PRINT((ndo, " %s", egp_acquire_codes[code]));
299 ND_PRINT((ndo, " %s", egp_acquire_status[status]));
303 ND_PRINT((ndo, "[status %d]", status));
309 ND_PRINT((ndo, "[code %d]", code));
319 ND_PRINT((ndo, " %s", egp_reach_codes[code]));
320 if (status <= EGPS_DOWN)
321 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
323 ND_PRINT((ndo, " [status %d]", status));
327 ND_PRINT((ndo, "[reach code %d]", code));
333 ND_PRINT((ndo, " poll"));
334 if (egp->egp_status <= EGPS_DOWN)
335 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
337 ND_PRINT((ndo, " [status %d]", status));
338 ND_PRINT((ndo, " net:%s", ipaddr_string(ndo, &egp->egp_sourcenet)));
342 ND_PRINT((ndo, " update"));
343 if (status & EGPS_UNSOL) {
344 status &= ~EGPS_UNSOL;
345 ND_PRINT((ndo, " unsolicited"));
347 if (status <= EGPS_DOWN)
348 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
350 ND_PRINT((ndo, " [status %d]", status));
351 ND_PRINT((ndo, " %s int %d ext %d",
352 ipaddr_string(ndo, &egp->egp_sourcenet),
356 egpnrprint(ndo, egp, length);
360 ND_PRINT((ndo, " error"));
361 if (status <= EGPS_DOWN)
362 ND_PRINT((ndo, " state:%s", egp_status_updown[status]));
364 ND_PRINT((ndo, " [status %d]", status));
366 if (EXTRACT_16BITS(&egp->egp_reason) <= EGPR_UVERSION)
367 ND_PRINT((ndo, " %s", egp_reasons[EXTRACT_16BITS(&egp->egp_reason)]));
369 ND_PRINT((ndo, " [reason %d]", EXTRACT_16BITS(&egp->egp_reason)));
373 ND_PRINT((ndo, "[type %d]", type));