print-egp.c revision 1.1.1.8 1 1.1 christos /*
2 1.1 christos * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
3 1.1 christos * The Regents of the University of California. All rights reserved.
4 1.1 christos *
5 1.1 christos * Redistribution and use in source and binary forms are permitted
6 1.1 christos * provided that the above copyright notice and this paragraph are
7 1.1 christos * duplicated in all such forms and that any documentation,
8 1.1 christos * advertising materials, and other materials related to such
9 1.1 christos * distribution and use acknowledge that the software was developed
10 1.1 christos * by the University of California, Lawrence Berkeley Laboratory,
11 1.1 christos * Berkeley, CA. The name of the University may not be used to
12 1.1 christos * endorse or promote products derived from this software without
13 1.1 christos * specific prior written permission.
14 1.1 christos * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
15 1.1 christos * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
16 1.1 christos * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
17 1.1 christos *
18 1.1 christos * Initial contribution from Jeff Honig (jch (at) MITCHELL.CIT.CORNELL.EDU).
19 1.1 christos */
20 1.1 christos
21 1.1.1.5 spz /* \summary: Exterior Gateway Protocol (EGP) printer */
22 1.1.1.5 spz
23 1.1.1.6 christos /* specification: RFC 827 */
24 1.1.1.6 christos
25 1.1.1.6 christos #include <config.h>
26 1.1 christos
27 1.1.1.6 christos #include "netdissect-stdinc.h"
28 1.1 christos
29 1.1.1.8 christos #define ND_LONGJMP_FROM_TCHECK
30 1.1.1.4 christos #include "netdissect.h"
31 1.1 christos #include "addrtoname.h"
32 1.1 christos #include "extract.h"
33 1.1 christos
34 1.1 christos struct egp_packet {
35 1.1.1.6 christos nd_uint8_t egp_version;
36 1.1 christos #define EGP_VERSION 2
37 1.1.1.6 christos nd_uint8_t egp_type;
38 1.1 christos #define EGPT_ACQUIRE 3
39 1.1 christos #define EGPT_REACH 5
40 1.1 christos #define EGPT_POLL 2
41 1.1 christos #define EGPT_UPDATE 1
42 1.1 christos #define EGPT_ERROR 8
43 1.1.1.6 christos nd_uint8_t egp_code;
44 1.1 christos #define EGPC_REQUEST 0
45 1.1 christos #define EGPC_CONFIRM 1
46 1.1 christos #define EGPC_REFUSE 2
47 1.1 christos #define EGPC_CEASE 3
48 1.1 christos #define EGPC_CEASEACK 4
49 1.1 christos #define EGPC_HELLO 0
50 1.1 christos #define EGPC_HEARDU 1
51 1.1.1.6 christos nd_uint8_t egp_status;
52 1.1 christos #define EGPS_UNSPEC 0
53 1.1 christos #define EGPS_ACTIVE 1
54 1.1 christos #define EGPS_PASSIVE 2
55 1.1 christos #define EGPS_NORES 3
56 1.1 christos #define EGPS_ADMIN 4
57 1.1 christos #define EGPS_GODOWN 5
58 1.1 christos #define EGPS_PARAM 6
59 1.1 christos #define EGPS_PROTO 7
60 1.1 christos #define EGPS_INDET 0
61 1.1 christos #define EGPS_UP 1
62 1.1 christos #define EGPS_DOWN 2
63 1.1 christos #define EGPS_UNSOL 0x80
64 1.1.1.6 christos nd_uint16_t egp_checksum;
65 1.1.1.6 christos nd_uint16_t egp_as;
66 1.1.1.6 christos nd_uint16_t egp_sequence;
67 1.1 christos union {
68 1.1.1.6 christos nd_uint16_t egpu_hello;
69 1.1.1.6 christos nd_uint8_t egpu_gws[2];
70 1.1.1.6 christos nd_uint16_t egpu_reason;
71 1.1 christos #define EGPR_UNSPEC 0
72 1.1 christos #define EGPR_BADHEAD 1
73 1.1 christos #define EGPR_BADDATA 2
74 1.1 christos #define EGPR_NOREACH 3
75 1.1 christos #define EGPR_XSPOLL 4
76 1.1 christos #define EGPR_NORESP 5
77 1.1 christos #define EGPR_UVERSION 6
78 1.1 christos } egp_handg;
79 1.1 christos #define egp_hello egp_handg.egpu_hello
80 1.1 christos #define egp_intgw egp_handg.egpu_gws[0]
81 1.1 christos #define egp_extgw egp_handg.egpu_gws[1]
82 1.1 christos #define egp_reason egp_handg.egpu_reason
83 1.1 christos union {
84 1.1.1.6 christos nd_uint16_t egpu_poll;
85 1.1.1.6 christos nd_ipv4 egpu_sourcenet;
86 1.1 christos } egp_pands;
87 1.1 christos #define egp_poll egp_pands.egpu_poll
88 1.1 christos #define egp_sourcenet egp_pands.egpu_sourcenet
89 1.1 christos };
90 1.1 christos
91 1.1.1.8 christos static const struct tok egp_type_str[] = {
92 1.1.1.8 christos { EGPT_ACQUIRE, "acquire" },
93 1.1.1.8 christos { EGPT_REACH, "reach" },
94 1.1.1.8 christos { EGPT_POLL, "poll" },
95 1.1.1.8 christos { EGPT_UPDATE, "update" },
96 1.1.1.8 christos { EGPT_ERROR, "error" },
97 1.1.1.8 christos { 0, NULL }
98 1.1 christos };
99 1.1 christos
100 1.1.1.8 christos static const struct tok egp_acquire_codes_str[] = {
101 1.1.1.8 christos { EGPC_REQUEST, "request" },
102 1.1.1.8 christos { EGPC_CONFIRM, "confirm" },
103 1.1.1.8 christos { EGPC_REFUSE, "refuse" },
104 1.1.1.8 christos { EGPC_CEASE, "cease" },
105 1.1.1.8 christos { EGPC_CEASEACK, "cease_ack" },
106 1.1.1.8 christos { 0, NULL }
107 1.1 christos };
108 1.1 christos
109 1.1.1.8 christos static const struct tok egp_acquire_status_str[] = {
110 1.1.1.8 christos { EGPS_UNSPEC, "unspecified" },
111 1.1.1.8 christos { EGPS_ACTIVE, "active_mode" },
112 1.1.1.8 christos { EGPS_PASSIVE, "passive_mode" },
113 1.1.1.8 christos { EGPS_NORES, "insufficient_resources" },
114 1.1.1.8 christos { EGPS_ADMIN, "administratively_prohibited" },
115 1.1.1.8 christos { EGPS_GODOWN, "going_down" },
116 1.1.1.8 christos { EGPS_PARAM, "parameter_violation" },
117 1.1.1.8 christos { EGPS_PROTO, "protocol_violation" },
118 1.1.1.8 christos { 0, NULL }
119 1.1 christos };
120 1.1 christos
121 1.1.1.8 christos static const struct tok egp_reach_codes_str[] = {
122 1.1.1.8 christos { EGPC_HELLO, "hello" },
123 1.1.1.8 christos { EGPC_HEARDU, "i-h-u" },
124 1.1.1.8 christos { 0, NULL }
125 1.1 christos };
126 1.1 christos
127 1.1.1.8 christos static const struct tok egp_status_updown_str[] = {
128 1.1.1.8 christos { EGPS_INDET, "indeterminate" },
129 1.1.1.8 christos { EGPS_UP, "up" },
130 1.1.1.8 christos { EGPS_DOWN, "down" },
131 1.1.1.8 christos { 0, NULL }
132 1.1.1.8 christos };
133 1.1.1.8 christos
134 1.1.1.8 christos static const struct tok egp_reasons_str[] = {
135 1.1.1.8 christos { EGPR_UNSPEC, "unspecified" },
136 1.1.1.8 christos { EGPR_BADHEAD, "bad_EGP_header_format" },
137 1.1.1.8 christos { EGPR_BADDATA, "bad_EGP_data_field_format" },
138 1.1.1.8 christos { EGPR_NOREACH, "reachability_info_unavailable" },
139 1.1.1.8 christos { EGPR_XSPOLL, "excessive_polling_rate" },
140 1.1.1.8 christos { EGPR_NORESP, "no_response" },
141 1.1.1.8 christos { EGPR_UVERSION, "unsupported_version" },
142 1.1.1.8 christos { 0, NULL }
143 1.1 christos };
144 1.1 christos
145 1.1 christos static void
146 1.1.1.6 christos egpnr_print(netdissect_options *ndo,
147 1.1.1.6 christos const struct egp_packet *egp, u_int length)
148 1.1 christos {
149 1.1.1.6 christos const uint8_t *cp;
150 1.1.1.3 christos uint32_t addr;
151 1.1.1.6 christos uint32_t net;
152 1.1.1.6 christos u_int netlen;
153 1.1.1.6 christos u_int gateways, distances, networks;
154 1.1.1.6 christos u_int intgw, extgw, t_gateways;
155 1.1 christos const char *comma;
156 1.1 christos
157 1.1.1.6 christos addr = GET_IPV4_TO_NETWORK_ORDER(egp->egp_sourcenet);
158 1.1 christos if (IN_CLASSA(addr)) {
159 1.1 christos net = addr & IN_CLASSA_NET;
160 1.1 christos netlen = 1;
161 1.1 christos } else if (IN_CLASSB(addr)) {
162 1.1 christos net = addr & IN_CLASSB_NET;
163 1.1 christos netlen = 2;
164 1.1 christos } else if (IN_CLASSC(addr)) {
165 1.1 christos net = addr & IN_CLASSC_NET;
166 1.1 christos netlen = 3;
167 1.1 christos } else {
168 1.1 christos net = 0;
169 1.1 christos netlen = 0;
170 1.1 christos }
171 1.1.1.4 christos cp = (const uint8_t *)(egp + 1);
172 1.1.1.5 spz length -= sizeof(*egp);
173 1.1 christos
174 1.1.1.6 christos intgw = GET_U_1(egp->egp_intgw);
175 1.1.1.6 christos extgw = GET_U_1(egp->egp_extgw);
176 1.1.1.6 christos t_gateways = intgw + extgw;
177 1.1 christos for (gateways = 0; gateways < t_gateways; ++gateways) {
178 1.1 christos /* Pickup host part of gateway address */
179 1.1 christos addr = 0;
180 1.1.1.8 christos ND_ICHECK_U(length, <, 4 - netlen);
181 1.1.1.6 christos ND_TCHECK_LEN(cp, 4 - netlen);
182 1.1 christos switch (netlen) {
183 1.1 christos
184 1.1 christos case 1:
185 1.1.1.6 christos addr = GET_U_1(cp);
186 1.1.1.6 christos cp++;
187 1.1 christos /* fall through */
188 1.1 christos case 2:
189 1.1.1.6 christos addr = (addr << 8) | GET_U_1(cp);
190 1.1.1.6 christos cp++;
191 1.1 christos /* fall through */
192 1.1 christos case 3:
193 1.1.1.6 christos addr = (addr << 8) | GET_U_1(cp);
194 1.1.1.6 christos cp++;
195 1.1.1.6 christos break;
196 1.1 christos }
197 1.1 christos addr |= net;
198 1.1.1.5 spz length -= 4 - netlen;
199 1.1.1.8 christos ND_ICHECK_U(length, <, 1);
200 1.1.1.6 christos distances = GET_U_1(cp);
201 1.1.1.6 christos cp++;
202 1.1.1.5 spz length--;
203 1.1.1.6 christos ND_PRINT(" %s %s ",
204 1.1.1.6 christos gateways < intgw ? "int" : "ext",
205 1.1.1.6 christos ipaddr_string(ndo, (const u_char *)&addr)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
206 1.1 christos
207 1.1 christos comma = "";
208 1.1.1.6 christos ND_PRINT("(");
209 1.1.1.6 christos while (distances != 0) {
210 1.1.1.8 christos ND_ICHECK_U(length, <, 2);
211 1.1.1.6 christos ND_PRINT("%sd%u:", comma, GET_U_1(cp));
212 1.1.1.6 christos cp++;
213 1.1 christos comma = ", ";
214 1.1.1.6 christos networks = GET_U_1(cp);
215 1.1.1.6 christos cp++;
216 1.1.1.5 spz length -= 2;
217 1.1.1.6 christos while (networks != 0) {
218 1.1 christos /* Pickup network number */
219 1.1.1.8 christos ND_ICHECK_U(length, <, 1);
220 1.1.1.6 christos addr = ((uint32_t) GET_U_1(cp)) << 24;
221 1.1.1.6 christos cp++;
222 1.1.1.5 spz length--;
223 1.1 christos if (IN_CLASSB(addr)) {
224 1.1.1.8 christos ND_ICHECK_U(length, <, 1);
225 1.1.1.6 christos addr |= ((uint32_t) GET_U_1(cp)) << 16;
226 1.1.1.6 christos cp++;
227 1.1.1.5 spz length--;
228 1.1 christos } else if (!IN_CLASSA(addr)) {
229 1.1.1.8 christos ND_ICHECK_U(length, <, 2);
230 1.1.1.6 christos addr |= ((uint32_t) GET_U_1(cp)) << 16;
231 1.1.1.6 christos cp++;
232 1.1.1.6 christos addr |= ((uint32_t) GET_U_1(cp)) << 8;
233 1.1.1.6 christos cp++;
234 1.1.1.5 spz length -= 2;
235 1.1 christos }
236 1.1.1.6 christos ND_PRINT(" %s", ipaddr_string(ndo, (const u_char *)&addr)); /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
237 1.1.1.6 christos networks--;
238 1.1 christos }
239 1.1.1.6 christos distances--;
240 1.1 christos }
241 1.1.1.6 christos ND_PRINT(")");
242 1.1 christos }
243 1.1 christos return;
244 1.1.1.8 christos invalid:
245 1.1.1.8 christos nd_print_invalid(ndo);
246 1.1 christos }
247 1.1 christos
248 1.1 christos void
249 1.1.1.3 christos egp_print(netdissect_options *ndo,
250 1.1.1.6 christos const uint8_t *bp, u_int length)
251 1.1 christos {
252 1.1.1.6 christos const struct egp_packet *egp;
253 1.1.1.6 christos u_int version;
254 1.1.1.6 christos u_int type;
255 1.1.1.6 christos u_int code;
256 1.1.1.6 christos u_int status;
257 1.1 christos
258 1.1.1.6 christos ndo->ndo_protocol = "egp";
259 1.1.1.8 christos nd_print_protocol_caps(ndo);
260 1.1.1.8 christos
261 1.1.1.4 christos egp = (const struct egp_packet *)bp;
262 1.1.1.8 christos ND_ICHECK_ZU(length, <, sizeof(*egp));
263 1.1 christos
264 1.1.1.6 christos version = GET_U_1(egp->egp_version);
265 1.1.1.8 christos ND_ICHECK_U(version, !=, EGP_VERSION);
266 1.1.1.8 christos ND_TCHECK_SIZE(egp);
267 1.1 christos
268 1.1.1.8 christos ND_PRINT("v%u", version);
269 1.1.1.8 christos if (ndo->ndo_vflag) {
270 1.1.1.8 christos ND_PRINT(", AS %u, seq %u, length %u",
271 1.1.1.8 christos GET_BE_U_2(egp->egp_as),
272 1.1.1.8 christos GET_BE_U_2(egp->egp_sequence),
273 1.1.1.8 christos length);
274 1.1.1.8 christos } else {
275 1.1.1.8 christos ND_PRINT(", length %u", length);
276 1.1 christos return;
277 1.1 christos }
278 1.1 christos
279 1.1.1.6 christos type = GET_U_1(egp->egp_type);
280 1.1.1.8 christos ND_PRINT(", %s", tok2str(egp_type_str, "[type %u]", type));
281 1.1.1.6 christos code = GET_U_1(egp->egp_code);
282 1.1.1.6 christos status = GET_U_1(egp->egp_status);
283 1.1 christos
284 1.1 christos switch (type) {
285 1.1 christos case EGPT_ACQUIRE:
286 1.1.1.8 christos ND_PRINT(" %s", tok2str(egp_acquire_codes_str, "[code %u]", code));
287 1.1 christos switch (code) {
288 1.1 christos case EGPC_REQUEST:
289 1.1 christos case EGPC_CONFIRM:
290 1.1 christos switch (status) {
291 1.1 christos case EGPS_UNSPEC:
292 1.1 christos case EGPS_ACTIVE:
293 1.1 christos case EGPS_PASSIVE:
294 1.1.1.8 christos ND_PRINT(" %s", tok2str(egp_acquire_status_str, "%u", status));
295 1.1 christos break;
296 1.1 christos
297 1.1 christos default:
298 1.1.1.6 christos ND_PRINT(" [status %u]", status);
299 1.1 christos break;
300 1.1 christos }
301 1.1.1.6 christos ND_PRINT(" hello:%u poll:%u",
302 1.1.1.6 christos GET_BE_U_2(egp->egp_hello),
303 1.1.1.6 christos GET_BE_U_2(egp->egp_poll));
304 1.1 christos break;
305 1.1 christos
306 1.1 christos case EGPC_REFUSE:
307 1.1 christos case EGPC_CEASE:
308 1.1 christos case EGPC_CEASEACK:
309 1.1 christos switch (status ) {
310 1.1 christos case EGPS_UNSPEC:
311 1.1 christos case EGPS_NORES:
312 1.1 christos case EGPS_ADMIN:
313 1.1 christos case EGPS_GODOWN:
314 1.1 christos case EGPS_PARAM:
315 1.1 christos case EGPS_PROTO:
316 1.1.1.8 christos ND_PRINT(" %s", tok2str(egp_acquire_status_str, "%u", status));
317 1.1 christos break;
318 1.1 christos
319 1.1 christos default:
320 1.1.1.6 christos ND_PRINT("[status %u]", status);
321 1.1 christos break;
322 1.1 christos }
323 1.1 christos break;
324 1.1 christos }
325 1.1 christos break;
326 1.1 christos
327 1.1 christos case EGPT_REACH:
328 1.1.1.8 christos ND_PRINT(" %s", tok2str(egp_reach_codes_str, "[reach code %u]", code));
329 1.1 christos switch (code) {
330 1.1 christos case EGPC_HELLO:
331 1.1 christos case EGPC_HEARDU:
332 1.1.1.8 christos ND_PRINT(" state:%s", tok2str(egp_status_updown_str, "%u", status));
333 1.1 christos break;
334 1.1 christos }
335 1.1 christos break;
336 1.1 christos
337 1.1 christos case EGPT_POLL:
338 1.1.1.8 christos ND_PRINT(" state:%s", tok2str(egp_status_updown_str, "%u", status));
339 1.1.1.6 christos ND_PRINT(" net:%s", GET_IPADDR_STRING(egp->egp_sourcenet));
340 1.1 christos break;
341 1.1 christos
342 1.1 christos case EGPT_UPDATE:
343 1.1 christos if (status & EGPS_UNSOL) {
344 1.1 christos status &= ~EGPS_UNSOL;
345 1.1.1.6 christos ND_PRINT(" unsolicited");
346 1.1 christos }
347 1.1.1.8 christos ND_PRINT(" state:%s", tok2str(egp_status_updown_str, "%u", status));
348 1.1.1.6 christos ND_PRINT(" %s int %u ext %u",
349 1.1.1.6 christos GET_IPADDR_STRING(egp->egp_sourcenet),
350 1.1.1.6 christos GET_U_1(egp->egp_intgw),
351 1.1.1.6 christos GET_U_1(egp->egp_extgw));
352 1.1.1.3 christos if (ndo->ndo_vflag)
353 1.1.1.6 christos egpnr_print(ndo, egp, length);
354 1.1 christos break;
355 1.1 christos
356 1.1 christos case EGPT_ERROR:
357 1.1.1.8 christos ND_PRINT(" state:%s", tok2str(egp_status_updown_str, "%u", status));
358 1.1.1.8 christos ND_PRINT(" %s", tok2str(egp_reasons_str, "[reason %u]", GET_BE_U_2(egp->egp_reason)));
359 1.1 christos break;
360 1.1 christos }
361 1.1.1.8 christos return;
362 1.1.1.8 christos invalid:
363 1.1.1.8 christos nd_print_invalid(ndo);
364 1.1 christos }
365