]> The Tcpdump Group git mirrors - tcpdump/blob - print-egp.c
VRRP: add a sample capture and two test cases
[tcpdump] / print-egp.c
1 /*
2 * Copyright (c) 1991, 1992, 1993, 1994, 1995, 1996
3 * The Regents of the University of California. All rights reserved.
4 *
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.
17 *
18 * Initial contribution from Jeff Honig (jch@MITCHELL.CIT.CORNELL.EDU).
19 */
20
21 #ifdef HAVE_CONFIG_H
22 #include "config.h"
23 #endif
24
25 #include <tcpdump-stdinc.h>
26
27 #include <stdio.h>
28
29 #include "interface.h"
30 #include "addrtoname.h"
31 #include "extract.h"
32
33 #include "ip.h"
34
35 struct egp_packet {
36 u_int8_t egp_version;
37 #define EGP_VERSION 2
38 u_int8_t egp_type;
39 #define EGPT_ACQUIRE 3
40 #define EGPT_REACH 5
41 #define EGPT_POLL 2
42 #define EGPT_UPDATE 1
43 #define EGPT_ERROR 8
44 u_int8_t egp_code;
45 #define EGPC_REQUEST 0
46 #define EGPC_CONFIRM 1
47 #define EGPC_REFUSE 2
48 #define EGPC_CEASE 3
49 #define EGPC_CEASEACK 4
50 #define EGPC_HELLO 0
51 #define EGPC_HEARDU 1
52 u_int8_t egp_status;
53 #define EGPS_UNSPEC 0
54 #define EGPS_ACTIVE 1
55 #define EGPS_PASSIVE 2
56 #define EGPS_NORES 3
57 #define EGPS_ADMIN 4
58 #define EGPS_GODOWN 5
59 #define EGPS_PARAM 6
60 #define EGPS_PROTO 7
61 #define EGPS_INDET 0
62 #define EGPS_UP 1
63 #define EGPS_DOWN 2
64 #define EGPS_UNSOL 0x80
65 u_int16_t egp_checksum;
66 u_int16_t egp_as;
67 u_int16_t egp_sequence;
68 union {
69 u_int16_t egpu_hello;
70 u_int8_t egpu_gws[2];
71 u_int16_t egpu_reason;
72 #define EGPR_UNSPEC 0
73 #define EGPR_BADHEAD 1
74 #define EGPR_BADDATA 2
75 #define EGPR_NOREACH 3
76 #define EGPR_XSPOLL 4
77 #define EGPR_NORESP 5
78 #define EGPR_UVERSION 6
79 } egp_handg;
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
84 union {
85 u_int16_t egpu_poll;
86 u_int32_t egpu_sourcenet;
87 } egp_pands;
88 #define egp_poll egp_pands.egpu_poll
89 #define egp_sourcenet egp_pands.egpu_sourcenet
90 };
91
92 static const char *egp_acquire_codes[] = {
93 "request",
94 "confirm",
95 "refuse",
96 "cease",
97 "cease_ack"
98 };
99
100 static const char *egp_acquire_status[] = {
101 "unspecified",
102 "active_mode",
103 "passive_mode",
104 "insufficient_resources",
105 "administratively_prohibited",
106 "going_down",
107 "parameter_violation",
108 "protocol_violation"
109 };
110
111 static const char *egp_reach_codes[] = {
112 "hello",
113 "i-h-u"
114 };
115
116 static const char *egp_status_updown[] = {
117 "indeterminate",
118 "up",
119 "down"
120 };
121
122 static const char *egp_reasons[] = {
123 "unspecified",
124 "bad_EGP_header_format",
125 "bad_EGP_data_field_format",
126 "reachability_info_unavailable",
127 "excessive_polling_rate",
128 "no_response",
129 "unsupported_version"
130 };
131
132 static void
133 egpnrprint(register const struct egp_packet *egp)
134 {
135 register const u_int8_t *cp;
136 u_int32_t addr;
137 register u_int32_t net;
138 register u_int netlen;
139 int gateways, distances, networks;
140 int t_gateways;
141 const char *comma;
142
143 addr = egp->egp_sourcenet;
144 if (IN_CLASSA(addr)) {
145 net = addr & IN_CLASSA_NET;
146 netlen = 1;
147 } else if (IN_CLASSB(addr)) {
148 net = addr & IN_CLASSB_NET;
149 netlen = 2;
150 } else if (IN_CLASSC(addr)) {
151 net = addr & IN_CLASSC_NET;
152 netlen = 3;
153 } else {
154 net = 0;
155 netlen = 0;
156 }
157 cp = (u_int8_t *)(egp + 1);
158
159 t_gateways = egp->egp_intgw + egp->egp_extgw;
160 for (gateways = 0; gateways < t_gateways; ++gateways) {
161 /* Pickup host part of gateway address */
162 addr = 0;
163 TCHECK2(cp[0], 4 - netlen);
164 switch (netlen) {
165
166 case 1:
167 addr = *cp++;
168 /* fall through */
169 case 2:
170 addr = (addr << 8) | *cp++;
171 /* fall through */
172 case 3:
173 addr = (addr << 8) | *cp++;
174 }
175 addr |= net;
176 TCHECK2(cp[0], 1);
177 distances = *cp++;
178 printf(" %s %s ",
179 gateways < (int)egp->egp_intgw ? "int" : "ext",
180 ipaddr_string(&addr));
181
182 comma = "";
183 putchar('(');
184 while (--distances >= 0) {
185 TCHECK2(cp[0], 2);
186 printf("%sd%d:", comma, (int)*cp++);
187 comma = ", ";
188 networks = *cp++;
189 while (--networks >= 0) {
190 /* Pickup network number */
191 TCHECK2(cp[0], 1);
192 addr = (u_int32_t)*cp++ << 24;
193 if (IN_CLASSB(addr)) {
194 TCHECK2(cp[0], 1);
195 addr |= (u_int32_t)*cp++ << 16;
196 } else if (!IN_CLASSA(addr)) {
197 TCHECK2(cp[0], 2);
198 addr |= (u_int32_t)*cp++ << 16;
199 addr |= (u_int32_t)*cp++ << 8;
200 }
201 printf(" %s", ipaddr_string(&addr));
202 }
203 }
204 putchar(')');
205 }
206 return;
207 trunc:
208 fputs("[|]", stdout);
209 }
210
211 void
212 egp_print(register const u_int8_t *bp, register u_int length)
213 {
214 register const struct egp_packet *egp;
215 register int status;
216 register int code;
217 register int type;
218
219 egp = (struct egp_packet *)bp;
220 if (!TTEST2(*egp, length)) {
221 printf("[|egp]");
222 return;
223 }
224
225 if (!vflag) {
226 printf("EGPv%u, AS %u, seq %u, length %u",
227 egp->egp_version,
228 EXTRACT_16BITS(&egp->egp_as),
229 EXTRACT_16BITS(&egp->egp_sequence),
230 length);
231 return;
232 } else
233 printf("EGPv%u, length %u",
234 egp->egp_version,
235 length);
236
237 if (egp->egp_version != EGP_VERSION) {
238 printf("[version %d]", egp->egp_version);
239 return;
240 }
241
242 type = egp->egp_type;
243 code = egp->egp_code;
244 status = egp->egp_status;
245
246 switch (type) {
247 case EGPT_ACQUIRE:
248 printf(" acquire");
249 switch (code) {
250 case EGPC_REQUEST:
251 case EGPC_CONFIRM:
252 printf(" %s", egp_acquire_codes[code]);
253 switch (status) {
254 case EGPS_UNSPEC:
255 case EGPS_ACTIVE:
256 case EGPS_PASSIVE:
257 printf(" %s", egp_acquire_status[status]);
258 break;
259
260 default:
261 printf(" [status %d]", status);
262 break;
263 }
264 printf(" hello:%d poll:%d",
265 EXTRACT_16BITS(&egp->egp_hello),
266 EXTRACT_16BITS(&egp->egp_poll));
267 break;
268
269 case EGPC_REFUSE:
270 case EGPC_CEASE:
271 case EGPC_CEASEACK:
272 printf(" %s", egp_acquire_codes[code]);
273 switch (status ) {
274 case EGPS_UNSPEC:
275 case EGPS_NORES:
276 case EGPS_ADMIN:
277 case EGPS_GODOWN:
278 case EGPS_PARAM:
279 case EGPS_PROTO:
280 printf(" %s", egp_acquire_status[status]);
281 break;
282
283 default:
284 printf("[status %d]", status);
285 break;
286 }
287 break;
288
289 default:
290 printf("[code %d]", code);
291 break;
292 }
293 break;
294
295 case EGPT_REACH:
296 switch (code) {
297
298 case EGPC_HELLO:
299 case EGPC_HEARDU:
300 printf(" %s", egp_reach_codes[code]);
301 if (status <= EGPS_DOWN)
302 printf(" state:%s", egp_status_updown[status]);
303 else
304 printf(" [status %d]", status);
305 break;
306
307 default:
308 printf("[reach code %d]", code);
309 break;
310 }
311 break;
312
313 case EGPT_POLL:
314 printf(" poll");
315 if (egp->egp_status <= EGPS_DOWN)
316 printf(" state:%s", egp_status_updown[status]);
317 else
318 printf(" [status %d]", status);
319 printf(" net:%s", ipaddr_string(&egp->egp_sourcenet));
320 break;
321
322 case EGPT_UPDATE:
323 printf(" update");
324 if (status & EGPS_UNSOL) {
325 status &= ~EGPS_UNSOL;
326 printf(" unsolicited");
327 }
328 if (status <= EGPS_DOWN)
329 printf(" state:%s", egp_status_updown[status]);
330 else
331 printf(" [status %d]", status);
332 printf(" %s int %d ext %d",
333 ipaddr_string(&egp->egp_sourcenet),
334 egp->egp_intgw,
335 egp->egp_extgw);
336 if (vflag)
337 egpnrprint(egp);
338 break;
339
340 case EGPT_ERROR:
341 printf(" error");
342 if (status <= EGPS_DOWN)
343 printf(" state:%s", egp_status_updown[status]);
344 else
345 printf(" [status %d]", status);
346
347 if (EXTRACT_16BITS(&egp->egp_reason) <= EGPR_UVERSION)
348 printf(" %s", egp_reasons[EXTRACT_16BITS(&egp->egp_reason)]);
349 else
350 printf(" [reason %d]", EXTRACT_16BITS(&egp->egp_reason));
351 break;
352
353 default:
354 printf("[type %d]", type);
355 break;
356 }
357 }