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 */
29 #include "netdissect-stdinc.h"
31 #include "netdissect.h"
32 #include "addrtoname.h"
36 nd_uint8_t egp_version;
39 #define EGPT_ACQUIRE 3
45 #define EGPC_REQUEST 0
46 #define EGPC_CONFIRM 1
49 #define EGPC_CEASEACK 4
52 nd_uint8_t egp_status;
55 #define EGPS_PASSIVE 2
64 #define EGPS_UNSOL 0x80
65 nd_uint16_t egp_checksum;
67 nd_uint16_t egp_sequence;
69 nd_uint16_t egpu_hello;
70 nd_uint8_t egpu_gws[2];
71 nd_uint16_t egpu_reason;
73 #define EGPR_BADHEAD 1
74 #define EGPR_BADDATA 2
75 #define EGPR_NOREACH 3
78 #define EGPR_UVERSION 6
80 #define egp_hello egp_handg.egpu_hello
81 #define egp_intgw egp_handg.egpu_gws[0]
82 #define egp_extgw egp_handg.egpu_gws[1]
83 #define egp_reason egp_handg.egpu_reason
85 nd_uint16_t egpu_poll;
86 nd_ipv4 egpu_sourcenet;
88 #define egp_poll egp_pands.egpu_poll
89 #define egp_sourcenet egp_pands.egpu_sourcenet
92 static const char *egp_acquire_codes[] = {
100 static const char *egp_acquire_status[] = {
104 "insufficient_resources",
105 "administratively_prohibited",
107 "parameter_violation",
111 static const char *egp_reach_codes[] = {
116 static const char *egp_status_updown[] = {
122 static const char *egp_reasons[] = {
124 "bad_EGP_header_format",
125 "bad_EGP_data_field_format",
126 "reachability_info_unavailable",
127 "excessive_polling_rate",
129 "unsupported_version"
133 egpnr_print(netdissect_options *ndo,
134 const struct egp_packet *egp, u_int length)
140 u_int gateways, distances, networks;
141 u_int intgw, extgw, t_gateways;
144 addr = GET_IPV4_TO_NETWORK_ORDER(egp->egp_sourcenet);
145 if (IN_CLASSA(addr)) {
146 net = addr & IN_CLASSA_NET;
148 } else if (IN_CLASSB(addr)) {
149 net = addr & IN_CLASSB_NET;
151 } else if (IN_CLASSC(addr)) {
152 net = addr & IN_CLASSC_NET;
158 cp = (const uint8_t *)(egp + 1);
159 length -= sizeof(*egp);
161 intgw = GET_U_1(egp->egp_intgw);
162 extgw = GET_U_1(egp->egp_extgw);
163 t_gateways = intgw + extgw;
164 for (gateways = 0; gateways < t_gateways; ++gateways) {
165 /* Pickup host part of gateway address */
167 if (length < 4 - netlen)
169 ND_TCHECK_LEN(cp, 4 - netlen);
177 addr = (addr << 8) | GET_U_1(cp);
181 addr = (addr << 8) | GET_U_1(cp);
186 length -= 4 - netlen;
189 distances = GET_U_1(cp);
193 gateways < intgw ? "int" : "ext",
194 ipaddr_string(ndo, (const u_char *)&addr)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
198 while (distances != 0) {
201 ND_PRINT("%sd%u:", comma, GET_U_1(cp));
204 networks = GET_U_1(cp);
207 while (networks != 0) {
208 /* Pickup network number */
211 addr = ((uint32_t) GET_U_1(cp)) << 24;
214 if (IN_CLASSB(addr)) {
217 addr |= ((uint32_t) GET_U_1(cp)) << 16;
220 } else if (!IN_CLASSA(addr)) {
223 addr |= ((uint32_t) GET_U_1(cp)) << 16;
225 addr |= ((uint32_t) GET_U_1(cp)) << 8;
229 ND_PRINT(" %s", ipaddr_string(ndo, (const u_char *)&addr)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
242 egp_print(netdissect_options *ndo,
243 const uint8_t *bp, u_int length)
245 const struct egp_packet *egp;
251 ndo->ndo_protocol = "egp";
252 egp = (const struct egp_packet *)bp;
253 if (length < sizeof(*egp) || !ND_TTEST_SIZE(egp)) {
258 version = GET_U_1(egp->egp_version);
259 if (!ndo->ndo_vflag) {
260 ND_PRINT("EGPv%u, AS %u, seq %u, length %u",
262 GET_BE_U_2(egp->egp_as),
263 GET_BE_U_2(egp->egp_sequence),
267 ND_PRINT("EGPv%u, length %u",
271 if (version != EGP_VERSION) {
272 ND_PRINT("[version %u]", version);
276 type = GET_U_1(egp->egp_type);
277 code = GET_U_1(egp->egp_code);
278 status = GET_U_1(egp->egp_status);
282 ND_PRINT(" acquire");
286 ND_PRINT(" %s", egp_acquire_codes[code]);
291 ND_PRINT(" %s", egp_acquire_status[status]);
295 ND_PRINT(" [status %u]", status);
298 ND_PRINT(" hello:%u poll:%u",
299 GET_BE_U_2(egp->egp_hello),
300 GET_BE_U_2(egp->egp_poll));
306 ND_PRINT(" %s", egp_acquire_codes[code]);
314 ND_PRINT(" %s", egp_acquire_status[status]);
318 ND_PRINT("[status %u]", status);
324 ND_PRINT("[code %u]", code);
334 ND_PRINT(" %s", egp_reach_codes[code]);
335 if (status <= EGPS_DOWN)
336 ND_PRINT(" state:%s", egp_status_updown[status]);
338 ND_PRINT(" [status %u]", status);
342 ND_PRINT("[reach code %u]", code);
349 if (status <= EGPS_DOWN)
350 ND_PRINT(" state:%s", egp_status_updown[status]);
352 ND_PRINT(" [status %u]", status);
353 ND_PRINT(" net:%s", GET_IPADDR_STRING(egp->egp_sourcenet));
358 if (status & EGPS_UNSOL) {
359 status &= ~EGPS_UNSOL;
360 ND_PRINT(" unsolicited");
362 if (status <= EGPS_DOWN)
363 ND_PRINT(" state:%s", egp_status_updown[status]);
365 ND_PRINT(" [status %u]", status);
366 ND_PRINT(" %s int %u ext %u",
367 GET_IPADDR_STRING(egp->egp_sourcenet),
368 GET_U_1(egp->egp_intgw),
369 GET_U_1(egp->egp_extgw));
371 egpnr_print(ndo, egp, length);
376 if (status <= EGPS_DOWN)
377 ND_PRINT(" state:%s", egp_status_updown[status]);
379 ND_PRINT(" [status %u]", status);
381 if (GET_BE_U_2(egp->egp_reason) <= EGPR_UVERSION)
383 egp_reasons[GET_BE_U_2(egp->egp_reason)]);
385 ND_PRINT(" [reason %u]", GET_BE_U_2(egp->egp_reason));
389 ND_PRINT("[type %u]", type);