2 * Copyright (c) 1998-2004 Hannes Gredler <hannes@gredler.at>
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.
17 /* \summary: Enhanced Interior Gateway Routing Protocol (EIGRP) printer */
23 #include <netdissect-stdinc.h>
27 #include "netdissect.h"
29 #include "addrtoname.h"
32 * packet format documented at
33 * http://www.rhyshaden.com/eigrp.htm
37 struct eigrp_common_header {
47 #define EIGRP_VERSION 2
49 #define EIGRP_OPCODE_UPDATE 1
50 #define EIGRP_OPCODE_QUERY 3
51 #define EIGRP_OPCODE_REPLY 4
52 #define EIGRP_OPCODE_HELLO 5
53 #define EIGRP_OPCODE_IPXSAP 6
54 #define EIGRP_OPCODE_PROBE 7
56 static const struct tok eigrp_opcode_values[] = {
57 { EIGRP_OPCODE_UPDATE, "Update" },
58 { EIGRP_OPCODE_QUERY, "Query" },
59 { EIGRP_OPCODE_REPLY, "Reply" },
60 { EIGRP_OPCODE_HELLO, "Hello" },
61 { EIGRP_OPCODE_IPXSAP, "IPX SAP" },
62 { EIGRP_OPCODE_PROBE, "Probe" },
66 static const struct tok eigrp_common_header_flag_values[] = {
68 { 0x02, "Conditionally Received" },
72 struct eigrp_tlv_header {
77 #define EIGRP_TLV_GENERAL_PARM 0x0001
78 #define EIGRP_TLV_AUTH 0x0002
79 #define EIGRP_TLV_SEQ 0x0003
80 #define EIGRP_TLV_SW_VERSION 0x0004
81 #define EIGRP_TLV_MCAST_SEQ 0x0005
82 #define EIGRP_TLV_IP_INT 0x0102
83 #define EIGRP_TLV_IP_EXT 0x0103
84 #define EIGRP_TLV_AT_INT 0x0202
85 #define EIGRP_TLV_AT_EXT 0x0203
86 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
87 #define EIGRP_TLV_IPX_INT 0x0302
88 #define EIGRP_TLV_IPX_EXT 0x0303
90 static const struct tok eigrp_tlv_values[] = {
91 { EIGRP_TLV_GENERAL_PARM, "General Parameters"},
92 { EIGRP_TLV_AUTH, "Authentication"},
93 { EIGRP_TLV_SEQ, "Sequence"},
94 { EIGRP_TLV_SW_VERSION, "Software Version"},
95 { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"},
96 { EIGRP_TLV_IP_INT, "IP Internal routes"},
97 { EIGRP_TLV_IP_EXT, "IP External routes"},
98 { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"},
99 { EIGRP_TLV_AT_EXT, "AppleTalk External routes"},
100 { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"},
101 { EIGRP_TLV_IPX_INT, "IPX Internal routes"},
102 { EIGRP_TLV_IPX_EXT, "IPX External routes"},
106 struct eigrp_tlv_general_parm_t {
116 struct eigrp_tlv_sw_version_t {
123 struct eigrp_tlv_ip_int_t {
126 uint8_t bandwidth[4];
133 uint8_t destination; /* variable length [1-4] bytes encoding */
136 struct eigrp_tlv_ip_ext_t {
138 uint8_t origin_router[4];
139 uint8_t origin_as[4];
146 uint8_t bandwidth[4];
151 uint8_t reserved2[2];
153 uint8_t destination; /* variable length [1-4] bytes encoding */
156 struct eigrp_tlv_at_cable_setup_t {
157 uint8_t cable_start[2];
158 uint8_t cable_end[2];
159 uint8_t router_id[4];
162 struct eigrp_tlv_at_int_t {
165 uint8_t bandwidth[4];
171 uint8_t cable_start[2];
172 uint8_t cable_end[2];
175 struct eigrp_tlv_at_ext_t {
177 uint8_t origin_router[4];
178 uint8_t origin_as[4];
184 uint8_t bandwidth[4];
189 uint8_t reserved2[2];
190 uint8_t cable_start[2];
191 uint8_t cable_end[2];
194 static const struct tok eigrp_ext_proto_id_values[] = {
205 { 0x0b, "Connected" },
210 eigrp_print(netdissect_options *ndo, register const u_char *pptr, register u_int len)
212 const struct eigrp_common_header *eigrp_com_header;
213 const struct eigrp_tlv_header *eigrp_tlv_header;
214 const u_char *tptr,*tlv_tptr;
215 u_int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen, byte_length, bit_length;
219 const struct eigrp_tlv_general_parm_t *eigrp_tlv_general_parm;
220 const struct eigrp_tlv_sw_version_t *eigrp_tlv_sw_version;
221 const struct eigrp_tlv_ip_int_t *eigrp_tlv_ip_int;
222 const struct eigrp_tlv_ip_ext_t *eigrp_tlv_ip_ext;
223 const struct eigrp_tlv_at_cable_setup_t *eigrp_tlv_at_cable_setup;
224 const struct eigrp_tlv_at_int_t *eigrp_tlv_at_int;
225 const struct eigrp_tlv_at_ext_t *eigrp_tlv_at_ext;
229 eigrp_com_header = (const struct eigrp_common_header *)pptr;
230 ND_TCHECK(*eigrp_com_header);
233 * Sanity checking of the header.
235 if (eigrp_com_header->version != EIGRP_VERSION) {
236 ND_PRINT((ndo, "EIGRP version %u packet not supported",eigrp_com_header->version));
240 /* in non-verbose mode just lets print the basic Message Type*/
241 if (ndo->ndo_vflag < 1) {
242 ND_PRINT((ndo, "EIGRP %s, length: %u",
243 tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
248 /* ok they seem to want to know everything - lets fully decode it */
250 if (len < sizeof(struct eigrp_common_header)) {
251 ND_PRINT((ndo, "EIGRP %s, length: %u (too short, < %u)",
252 tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
253 len, (u_int) sizeof(struct eigrp_common_header)));
256 tlen=len-sizeof(struct eigrp_common_header);
258 /* FIXME print other header info */
259 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",
260 eigrp_com_header->version,
261 tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode),
262 eigrp_com_header->opcode,
263 EXTRACT_16BITS(&eigrp_com_header->checksum),
264 tok2str(eigrp_common_header_flag_values,
266 EXTRACT_32BITS(&eigrp_com_header->flags)),
267 EXTRACT_32BITS(&eigrp_com_header->seq),
268 EXTRACT_32BITS(&eigrp_com_header->ack),
269 EXTRACT_32BITS(&eigrp_com_header->asn),
272 tptr+=sizeof(const struct eigrp_common_header);
275 /* did we capture enough for fully decoding the object header ? */
276 ND_TCHECK2(*tptr, sizeof(struct eigrp_tlv_header));
278 eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
279 eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length);
280 eigrp_tlv_type=EXTRACT_16BITS(&eigrp_tlv_header->type);
283 if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header) ||
284 eigrp_tlv_len > tlen) {
285 print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",tlen);
289 ND_PRINT((ndo, "\n\t %s TLV (0x%04x), length: %u",
290 tok2str(eigrp_tlv_values,
296 if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header)) {
297 ND_PRINT((ndo, " (too short, < %u)",
298 (u_int) sizeof(struct eigrp_tlv_header)));
301 tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
302 tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
304 /* did we capture enough for fully decoding the object ? */
305 ND_TCHECK2(*tptr, eigrp_tlv_len);
307 switch(eigrp_tlv_type) {
309 case EIGRP_TLV_GENERAL_PARM:
310 tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr;
311 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_general_parm)) {
312 ND_PRINT((ndo, " (too short, < %u)",
313 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_general_parm))));
317 ND_PRINT((ndo, "\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
318 EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime),
319 tlv_ptr.eigrp_tlv_general_parm->k1,
320 tlv_ptr.eigrp_tlv_general_parm->k2,
321 tlv_ptr.eigrp_tlv_general_parm->k3,
322 tlv_ptr.eigrp_tlv_general_parm->k4,
323 tlv_ptr.eigrp_tlv_general_parm->k5));
326 case EIGRP_TLV_SW_VERSION:
327 tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr;
328 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_sw_version)) {
329 ND_PRINT((ndo, " (too short, < %u)",
330 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_sw_version))));
334 ND_PRINT((ndo, "\n\t IOS version: %u.%u, EIGRP version %u.%u",
335 tlv_ptr.eigrp_tlv_sw_version->ios_major,
336 tlv_ptr.eigrp_tlv_sw_version->ios_minor,
337 tlv_ptr.eigrp_tlv_sw_version->eigrp_major,
338 tlv_ptr.eigrp_tlv_sw_version->eigrp_minor));
341 case EIGRP_TLV_IP_INT:
342 tlv_ptr.eigrp_tlv_ip_int = (const struct eigrp_tlv_ip_int_t *)tlv_tptr;
343 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_ip_int)) {
344 ND_PRINT((ndo, " (too short, < %u)",
345 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_ip_int))));
349 bit_length = tlv_ptr.eigrp_tlv_ip_int->plen;
350 if (bit_length > 32) {
351 ND_PRINT((ndo, "\n\t illegal prefix length %u",bit_length));
354 byte_length = (bit_length + 7) / 8; /* variable length encoding */
355 memset(prefix, 0, 4);
356 ND_TCHECK2(tlv_ptr.eigrp_tlv_ip_int->destination, byte_length);
357 memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_int->destination,byte_length);
359 ND_PRINT((ndo, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
360 ipaddr_string(ndo, prefix),
362 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0)
363 ND_PRINT((ndo, "self"));
365 ND_PRINT((ndo, "%s",ipaddr_string(ndo, &tlv_ptr.eigrp_tlv_ip_int->nexthop)));
367 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
368 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->delay)/100),
369 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->bandwidth),
370 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_int->mtu),
371 tlv_ptr.eigrp_tlv_ip_int->hopcount,
372 tlv_ptr.eigrp_tlv_ip_int->reliability,
373 tlv_ptr.eigrp_tlv_ip_int->load));
376 case EIGRP_TLV_IP_EXT:
377 tlv_ptr.eigrp_tlv_ip_ext = (const struct eigrp_tlv_ip_ext_t *)tlv_tptr;
378 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_ip_ext)) {
379 ND_PRINT((ndo, " (too short, < %u)",
380 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_ip_ext))));
384 bit_length = tlv_ptr.eigrp_tlv_ip_ext->plen;
385 if (bit_length > 32) {
386 ND_PRINT((ndo, "\n\t illegal prefix length %u",bit_length));
389 byte_length = (bit_length + 7) / 8; /* variable length encoding */
390 memset(prefix, 0, 4);
391 ND_TCHECK2(tlv_ptr.eigrp_tlv_ip_ext->destination, byte_length);
392 memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_ext->destination,byte_length);
394 ND_PRINT((ndo, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
395 ipaddr_string(ndo, prefix),
397 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->nexthop) == 0)
398 ND_PRINT((ndo, "self"));
400 ND_PRINT((ndo, "%s",ipaddr_string(ndo, &tlv_ptr.eigrp_tlv_ip_ext->nexthop)));
402 ND_PRINT((ndo, "\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
403 ipaddr_string(ndo, tlv_ptr.eigrp_tlv_ip_ext->origin_router),
404 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->origin_as),
405 tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_ip_ext->proto_id),
406 tlv_ptr.eigrp_tlv_ip_ext->flags,
407 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->tag),
408 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_ip_ext->metric)));
410 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
411 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->delay)/100),
412 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_ext->bandwidth),
413 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_ext->mtu),
414 tlv_ptr.eigrp_tlv_ip_ext->hopcount,
415 tlv_ptr.eigrp_tlv_ip_ext->reliability,
416 tlv_ptr.eigrp_tlv_ip_ext->load));
419 case EIGRP_TLV_AT_CABLE_SETUP:
420 tlv_ptr.eigrp_tlv_at_cable_setup = (const struct eigrp_tlv_at_cable_setup_t *)tlv_tptr;
421 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_cable_setup)) {
422 ND_PRINT((ndo, " (too short, < %u)",
423 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_cable_setup))));
427 ND_PRINT((ndo, "\n\t Cable-range: %u-%u, Router-ID %u",
428 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_start),
429 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->cable_end),
430 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_cable_setup->router_id)));
433 case EIGRP_TLV_AT_INT:
434 tlv_ptr.eigrp_tlv_at_int = (const struct eigrp_tlv_at_int_t *)tlv_tptr;
435 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_int)) {
436 ND_PRINT((ndo, " (too short, < %u)",
437 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_int))));
441 ND_PRINT((ndo, "\n\t Cable-Range: %u-%u, nexthop: ",
442 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_start),
443 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->cable_end)));
445 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop) == 0)
446 ND_PRINT((ndo, "self"));
448 ND_PRINT((ndo, "%u.%u",
449 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop),
450 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_int->nexthop[2])));
452 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
453 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->delay)/100),
454 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_int->bandwidth),
455 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_int->mtu),
456 tlv_ptr.eigrp_tlv_at_int->hopcount,
457 tlv_ptr.eigrp_tlv_at_int->reliability,
458 tlv_ptr.eigrp_tlv_at_int->load));
461 case EIGRP_TLV_AT_EXT:
462 tlv_ptr.eigrp_tlv_at_ext = (const struct eigrp_tlv_at_ext_t *)tlv_tptr;
463 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_ext)) {
464 ND_PRINT((ndo, " (too short, < %u)",
465 (u_int) (sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_ext))));
469 ND_PRINT((ndo, "\n\t Cable-Range: %u-%u, nexthop: ",
470 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_start),
471 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->cable_end)));
473 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop) == 0)
474 ND_PRINT((ndo, "self"));
476 ND_PRINT((ndo, "%u.%u",
477 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop),
478 EXTRACT_16BITS(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2])));
480 ND_PRINT((ndo, "\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
481 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_router),
482 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->origin_as),
483 tok2str(eigrp_ext_proto_id_values,"unknown",tlv_ptr.eigrp_tlv_at_ext->proto_id),
484 tlv_ptr.eigrp_tlv_at_ext->flags,
485 EXTRACT_32BITS(tlv_ptr.eigrp_tlv_at_ext->tag),
486 EXTRACT_16BITS(tlv_ptr.eigrp_tlv_at_ext->metric)));
488 ND_PRINT((ndo, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
489 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->delay)/100),
490 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_at_ext->bandwidth),
491 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_at_ext->mtu),
492 tlv_ptr.eigrp_tlv_at_ext->hopcount,
493 tlv_ptr.eigrp_tlv_at_ext->reliability,
494 tlv_ptr.eigrp_tlv_at_ext->load));
498 * FIXME those are the defined TLVs that lack a decoder
499 * you are welcome to contribute code ;-)
504 case EIGRP_TLV_MCAST_SEQ:
505 case EIGRP_TLV_IPX_INT:
506 case EIGRP_TLV_IPX_EXT:
509 if (ndo->ndo_vflag <= 1)
510 print_unknown_data(ndo,tlv_tptr,"\n\t ",tlv_tlen);
513 /* do we want to see an additionally hexdump ? */
514 if (ndo->ndo_vflag > 1)
515 print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",
516 eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
523 ND_PRINT((ndo, "\n\t\t packet exceeded snapshot"));