]> The Tcpdump Group git mirrors - tcpdump/blob - print-eigrp.c
ICMP6 RPL: don't use inet_ntop()
[tcpdump] / print-eigrp.c
1 /*
2 * Copyright (c) 1998-2004 Hannes Gredler <hannes@tcpdump.org>
3 * The TCPDUMP project
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code
7 * distributions retain the above copyright notice and this paragraph
8 * in its entirety, and (2) distributions including binary code include
9 * the above copyright notice and this paragraph in its entirety in
10 * the documentation or other materials provided with the distribution.
11 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND
12 * WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, WITHOUT
13 * LIMITATION, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
14 * FOR A PARTICULAR PURPOSE.
15 */
16
17 #ifdef HAVE_CONFIG_H
18 #include "config.h"
19 #endif
20
21 #include <netdissect-stdinc.h>
22
23 #include <string.h>
24
25 #include "netdissect.h"
26 #include "extract.h"
27 #include "addrtoname.h"
28
29 /*
30 * packet format documented at
31 * http://www.rhyshaden.com/eigrp.htm
32 */
33
34 struct eigrp_common_header {
35 uint8_t version;
36 uint8_t opcode;
37 uint8_t checksum[2];
38 uint8_t flags[4];
39 uint8_t seq[4];
40 uint8_t ack[4];
41 uint8_t asn[4];
42 };
43
44 #define EIGRP_VERSION 2
45
46 #define EIGRP_OPCODE_UPDATE 1
47 #define EIGRP_OPCODE_QUERY 3
48 #define EIGRP_OPCODE_REPLY 4
49 #define EIGRP_OPCODE_HELLO 5
50 #define EIGRP_OPCODE_IPXSAP 6
51 #define EIGRP_OPCODE_PROBE 7
52
53 static const struct tok eigrp_opcode_values[] = {
54 { EIGRP_OPCODE_UPDATE, "Update" },
55 { EIGRP_OPCODE_QUERY, "Query" },
56 { EIGRP_OPCODE_REPLY, "Reply" },
57 { EIGRP_OPCODE_HELLO, "Hello" },
58 { EIGRP_OPCODE_IPXSAP, "IPX SAP" },
59 { EIGRP_OPCODE_PROBE, "Probe" },
60 { 0, NULL}
61 };
62
63 static const struct tok eigrp_common_header_flag_values[] = {
64 { 0x01, "Init" },
65 { 0x02, "Conditionally Received" },
66 { 0, NULL}
67 };
68
69 struct eigrp_tlv_header {
70 uint8_t type[2];
71 uint8_t length[2];
72 };
73
74 #define EIGRP_TLV_GENERAL_PARM 0x0001
75 #define EIGRP_TLV_AUTH 0x0002
76 #define EIGRP_TLV_SEQ 0x0003
77 #define EIGRP_TLV_SW_VERSION 0x0004
78 #define EIGRP_TLV_MCAST_SEQ 0x0005
79 #define EIGRP_TLV_IP_INT 0x0102
80 #define EIGRP_TLV_IP_EXT 0x0103
81 #define EIGRP_TLV_AT_INT 0x0202
82 #define EIGRP_TLV_AT_EXT 0x0203
83 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
84 #define EIGRP_TLV_IPX_INT 0x0302
85 #define EIGRP_TLV_IPX_EXT 0x0303
86
87 static const struct tok eigrp_tlv_values[] = {
88 { EIGRP_TLV_GENERAL_PARM, "General Parameters"},
89 { EIGRP_TLV_AUTH, "Authentication"},
90 { EIGRP_TLV_SEQ, "Sequence"},
91 { EIGRP_TLV_SW_VERSION, "Software Version"},
92 { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"},
93 { EIGRP_TLV_IP_INT, "IP Internal routes"},
94 { EIGRP_TLV_IP_EXT, "IP External routes"},
95 { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"},
96 { EIGRP_TLV_AT_EXT, "AppleTalk External routes"},
97 { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"},
98 { EIGRP_TLV_IPX_INT, "IPX Internal routes"},
99 { EIGRP_TLV_IPX_EXT, "IPX External routes"},
100 { 0, NULL}
101 };
102
103 struct eigrp_tlv_general_parm_t {
104 uint8_t k1;
105 uint8_t k2;
106 uint8_t k3;
107 uint8_t k4;
108 uint8_t k5;
109 uint8_t res;
110 uint8_t holdtime[2];
111 };
112
113 struct eigrp_tlv_sw_version_t {
114 uint8_t ios_major;
115 uint8_t ios_minor;
116 uint8_t eigrp_major;
117 uint8_t eigrp_minor;
118 };
119
120 struct eigrp_tlv_ip_int_t {
121 uint8_t nexthop[4];
122 uint8_t delay[4];
123 uint8_t bandwidth[4];
124 uint8_t mtu[3];
125 uint8_t hopcount;
126 uint8_t reliability;
127 uint8_t load;
128 uint8_t reserved[2];
129 uint8_t plen;
130 uint8_t destination; /* variable length [1-4] bytes encoding */
131 };
132
133 struct eigrp_tlv_ip_ext_t {
134 uint8_t nexthop[4];
135 uint8_t origin_router[4];
136 uint8_t origin_as[4];
137 uint8_t tag[4];
138 uint8_t metric[4];
139 uint8_t reserved[2];
140 uint8_t proto_id;
141 uint8_t flags;
142 uint8_t delay[4];
143 uint8_t bandwidth[4];
144 uint8_t mtu[3];
145 uint8_t hopcount;
146 uint8_t reliability;
147 uint8_t load;
148 uint8_t reserved2[2];
149 uint8_t plen;
150 uint8_t destination; /* variable length [1-4] bytes encoding */
151 };
152
153 struct eigrp_tlv_at_cable_setup_t {
154 uint8_t cable_start[2];
155 uint8_t cable_end[2];
156 uint8_t router_id[4];
157 };
158
159 struct eigrp_tlv_at_int_t {
160 uint8_t nexthop[4];
161 uint8_t delay[4];
162 uint8_t bandwidth[4];
163 uint8_t mtu[3];
164 uint8_t hopcount;
165 uint8_t reliability;
166 uint8_t load;
167 uint8_t reserved[2];
168 uint8_t cable_start[2];
169 uint8_t cable_end[2];
170 };
171
172 struct eigrp_tlv_at_ext_t {
173 uint8_t nexthop[4];
174 uint8_t origin_router[4];
175 uint8_t origin_as[4];
176 uint8_t tag[4];
177 uint8_t proto_id;
178 uint8_t flags;
179 uint8_t metric[2];
180 uint8_t delay[4];
181 uint8_t bandwidth[4];
182 uint8_t mtu[3];
183 uint8_t hopcount;
184 uint8_t reliability;
185 uint8_t load;
186 uint8_t reserved2[2];
187 uint8_t cable_start[2];
188 uint8_t cable_end[2];
189 };
190
191 static const struct tok eigrp_ext_proto_id_values[] = {
192 { 0x01, "IGRP" },
193 { 0x02, "EIGRP" },
194 { 0x03, "Static" },
195 { 0x04, "RIP" },
196 { 0x05, "Hello" },
197 { 0x06, "OSPF" },
198 { 0x07, "IS-IS" },
199 { 0x08, "EGP" },
200 { 0x09, "BGP" },
201 { 0x0a, "IDRP" },
202 { 0x0b, "Connected" },
203 { 0, NULL}
204 };
205
206 void
207 eigrp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len)
208 {
209 const struct eigrp_common_header *eigrp_com_header;
210 const struct eigrp_tlv_header *eigrp_tlv_header;
211 const u_char *tptr,*tlv_tptr;
212 u_int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen, byte_length, bit_length;
213 uint8_t prefix[4];
214
215 union {
216 const struct eigrp_tlv_general_parm_t *eigrp_tlv_general_parm;
217 const struct eigrp_tlv_sw_version_t *eigrp_tlv_sw_version;
218 const struct eigrp_tlv_ip_int_t *eigrp_tlv_ip_int;
219 const struct eigrp_tlv_ip_ext_t *eigrp_tlv_ip_ext;
220 const struct eigrp_tlv_at_cable_setup_t *eigrp_tlv_at_cable_setup;
221 const struct eigrp_tlv_at_int_t *eigrp_tlv_at_int;
222 const struct eigrp_tlv_at_ext_t *eigrp_tlv_at_ext;
223 } tlv_ptr;
224
225 tptr=pptr;
226 eigrp_com_header = (const struct eigrp_common_header *)pptr;
227 ND_TCHECK(*eigrp_com_header);
228
229 /*
230 * Sanity checking of the header.
231 */
232 if (eigrp_com_header->version != EIGRP_VERSION) {
233 ND_PRINT((ndo, "EIGRP version %u packet not supported",eigrp_com_header->version));
234 return;
235 }
236
237 /* in non-verbose mode just lets print the basic Message Type*/
238 if (ndo->ndo_vflag < 1) {
239 ND_PRINT((ndo, "EIGRP %s, length: %u",
240 tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
241 len));
242 return;
243 }
244
245 /* ok they seem to want to know everything - lets fully decode it */
246
247 tlen=len-sizeof(struct eigrp_common_header);
248
249 /* FIXME print other header info */
250 ND_PRINT((ndo, "\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
251 eigrp_com_header->version,
252 tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode),
253 eigrp_com_header->opcode,
254 EXTRACT_16BITS(&eigrp_com_header->checksum),
255 tok2str(eigrp_common_header_flag_values,
256 "none",
257 EXTRACT_32BITS(&eigrp_com_header->flags)),
258 EXTRACT_32BITS(&eigrp_com_header->seq),
259 EXTRACT_32BITS(&eigrp_com_header->ack),
260 EXTRACT_32BITS(&eigrp_com_header->asn),
261 tlen));
262
263 tptr+=sizeof(const struct eigrp_common_header);
264
265 while(tlen>0) {
266 /* did we capture enough for fully decoding the object header ? */
267 ND_TCHECK2(*tptr, sizeof(struct eigrp_tlv_header));
268
269 eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
270 eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length);
271 eigrp_tlv_type=EXTRACT_16BITS(&eigrp_tlv_header->type);
272
273
274 if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header) ||
275 eigrp_tlv_len > tlen) {
276 print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",tlen);
277 return;
278 }
279
280 ND_PRINT((ndo, "\n\t %s TLV (0x%04x), length: %u",
281 tok2str(eigrp_tlv_values,
282 "Unknown",
283 eigrp_tlv_type),
284 eigrp_tlv_type,
285 eigrp_tlv_len));
286
287 tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
288 tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
289
290 /* did we capture enough for fully decoding the object ? */
291 ND_TCHECK2(*tptr, eigrp_tlv_len);
292
293 switch(eigrp_tlv_type) {
294
295 case EIGRP_TLV_GENERAL_PARM:
296 tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr;
297
298 ND_PRINT((ndo, "\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
299 EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime),
300 tlv_ptr.eigrp_tlv_general_parm->k1,
301 tlv_ptr.eigrp_tlv_general_parm->k2,
302 tlv_ptr.eigrp_tlv_general_parm->k3,
303 tlv_ptr.eigrp_tlv_general_parm->k4,
304 tlv_ptr.eigrp_tlv_general_parm->k5));
305 break;
306
307 case EIGRP_TLV_SW_VERSION:
308 tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr;
309
310 ND_PRINT((ndo, "\n\t IOS version: %u.%u, EIGRP version %u.%u",
311 tlv_ptr.eigrp_tlv_sw_version->ios_major,
312 tlv_ptr.eigrp_tlv_sw_version->ios_minor,
313 tlv_ptr.eigrp_tlv_sw_version->eigrp_major,
314 tlv_ptr.eigrp_tlv_sw_version->eigrp_minor));
315 break;
316
317 case EIGRP_TLV_IP_INT:
318 tlv_ptr.eigrp_tlv_ip_int = (const struct eigrp_tlv_ip_int_t *)tlv_tptr;
319
320 bit_length = tlv_ptr.eigrp_tlv_ip_int->plen;
321 if (bit_length > 32) {
322 ND_PRINT((ndo, "\n\t illegal prefix length %u",bit_length));
323 break;
324 }
325 byte_length = (bit_length + 7) / 8; /* variable length encoding */
326 memset(prefix, 0, 4);
327 memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_int->destination,byte_length);
328
329 ND_PRINT((ndo, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
330 ipaddr_string(ndo, prefix),
331 bit_length));
332 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0)
333 ND_PRINT((ndo, "self"));
334 else
335 ND_PRINT((ndo, "%s",ipaddr_string(ndo, &tlv_ptr.eigrp_tlv_ip_int->nexthop)));
336
337 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
338 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->delay)/100),
339 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->bandwidth),
340 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_int->mtu),
341 tlv_ptr.eigrp_tlv_ip_int->hopcount,
342 tlv_ptr.eigrp_tlv_ip_int->reliability,
343 tlv_ptr.eigrp_tlv_ip_int->load));
344 break;
345
346 case EIGRP_TLV_IP_EXT:
347 tlv_ptr.eigrp_tlv_ip_ext = (const struct eigrp_tlv_ip_ext_t *)tlv_tptr;
348
349 bit_length = tlv_ptr.eigrp_tlv_ip_ext->plen;
350 if (bit_length > 32) {
351 ND_PRINT((ndo, "\n\t illegal prefix length %u",bit_length));
352 break;
353 }
354 byte_length = (bit_length + 7) / 8; /* variable length encoding */
355 memset(prefix, 0, 4);
356 memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_ext->destination,byte_length);
357
358 ND_PRINT((ndo, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
359 ipaddr_string(ndo, prefix),
360 bit_length));
361 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->nexthop) == 0)
362 ND_PRINT((ndo, "self"));
363 else
364 ND_PRINT((ndo, "%s",ipaddr_string(ndo, &tlv_ptr.eigrp_tlv_ip_ext->nexthop)));
365
366 ND_PRINT((ndo, "\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
367 ipaddr_string(ndo, tlv_ptr.eigrp_tlv_ip_ext->origin_router),
368 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->origin_as),
369 tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_ip_ext->proto_id),
370 tlv_ptr.eigrp_tlv_ip_ext->flags,
371 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->tag),
372 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->metric)));
373
374 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
375 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->delay)/100),
376 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->bandwidth),
377 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_ext->mtu),
378 tlv_ptr.eigrp_tlv_ip_ext->hopcount,
379 tlv_ptr.eigrp_tlv_ip_ext->reliability,
380 tlv_ptr.eigrp_tlv_ip_ext->load));
381 break;
382
383 case EIGRP_TLV_AT_CABLE_SETUP:
384 tlv_ptr.eigrp_tlv_at_cable_setup = (const struct eigrp_tlv_at_cable_setup_t *)tlv_tptr;
385
386 ND_PRINT((ndo, "\n\t Cable-range: %u-%u, Router-ID %u",
387 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_start),
388 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_end),
389 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->router_id)));
390 break;
391
392 case EIGRP_TLV_AT_INT:
393 tlv_ptr.eigrp_tlv_at_int = (const struct eigrp_tlv_at_int_t *)tlv_tptr;
394
395 ND_PRINT((ndo, "\n\t Cable-Range: %u-%u, nexthop: ",
396 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_start),
397 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_end)));
398
399 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop) == 0)
400 ND_PRINT((ndo, "self"));
401 else
402 ND_PRINT((ndo, "%u.%u",
403 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop),
404 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop[2])));
405
406 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
407 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->delay)/100),
408 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->bandwidth),
409 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_int->mtu),
410 tlv_ptr.eigrp_tlv_at_int->hopcount,
411 tlv_ptr.eigrp_tlv_at_int->reliability,
412 tlv_ptr.eigrp_tlv_at_int->load));
413 break;
414
415 case EIGRP_TLV_AT_EXT:
416 tlv_ptr.eigrp_tlv_at_ext = (const struct eigrp_tlv_at_ext_t *)tlv_tptr;
417
418 ND_PRINT((ndo, "\n\t Cable-Range: %u-%u, nexthop: ",
419 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_start),
420 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_end)));
421
422 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop) == 0)
423 ND_PRINT((ndo, "self"));
424 else
425 ND_PRINT((ndo, "%u.%u",
426 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop),
427 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2])));
428
429 ND_PRINT((ndo, "\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
430 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_router),
431 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_as),
432 tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_at_ext->proto_id),
433 tlv_ptr.eigrp_tlv_at_ext->flags,
434 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->tag),
435 EXTRACT_16BITS(tlv_ptr.eigrp_tlv_at_ext->metric)));
436
437 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
438 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->delay)/100),
439 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->bandwidth),
440 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_ext->mtu),
441 tlv_ptr.eigrp_tlv_at_ext->hopcount,
442 tlv_ptr.eigrp_tlv_at_ext->reliability,
443 tlv_ptr.eigrp_tlv_at_ext->load));
444 break;
445
446 /*
447 * FIXME those are the defined TLVs that lack a decoder
448 * you are welcome to contribute code ;-)
449 */
450
451 case EIGRP_TLV_AUTH:
452 case EIGRP_TLV_SEQ:
453 case EIGRP_TLV_MCAST_SEQ:
454 case EIGRP_TLV_IPX_INT:
455 case EIGRP_TLV_IPX_EXT:
456
457 default:
458 if (ndo->ndo_vflag <= 1)
459 print_unknown_data(ndo,tlv_tptr,"\n\t ",tlv_tlen);
460 break;
461 }
462 /* do we want to see an additionally hexdump ? */
463 if (ndo->ndo_vflag > 1)
464 print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",
465 eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
466
467 tptr+=eigrp_tlv_len;
468 tlen-=eigrp_tlv_len;
469 }
470 return;
471 trunc:
472 ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));
473 }