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 */
22 * https://web.archive.org/web/20190722221712/https://www.rhyshaden.com/eigrp.htm
28 #include "netdissect-stdinc.h"
32 #include "netdissect.h"
34 #include "addrtoname.h"
37 struct eigrp_common_header
{
48 #define EIGRP_VERSION 2
50 #define EIGRP_OPCODE_UPDATE 1
51 #define EIGRP_OPCODE_QUERY 3
52 #define EIGRP_OPCODE_REPLY 4
53 #define EIGRP_OPCODE_HELLO 5
54 #define EIGRP_OPCODE_IPXSAP 6
55 #define EIGRP_OPCODE_PROBE 7
57 static const struct tok eigrp_opcode_values
[] = {
58 { EIGRP_OPCODE_UPDATE
, "Update" },
59 { EIGRP_OPCODE_QUERY
, "Query" },
60 { EIGRP_OPCODE_REPLY
, "Reply" },
61 { EIGRP_OPCODE_HELLO
, "Hello" },
62 { EIGRP_OPCODE_IPXSAP
, "IPX SAP" },
63 { EIGRP_OPCODE_PROBE
, "Probe" },
67 static const struct tok eigrp_common_header_flag_values
[] = {
69 { 0x02, "Conditionally Received" },
71 { 0x08, "End-of-Table" },
75 struct eigrp_tlv_header
{
80 #define EIGRP_TLV_GENERAL_PARM 0x0001
81 #define EIGRP_TLV_AUTH 0x0002
82 #define EIGRP_TLV_SEQ 0x0003
83 #define EIGRP_TLV_SW_VERSION 0x0004
84 #define EIGRP_TLV_MCAST_SEQ 0x0005
85 #define EIGRP_TLV_IP_INT 0x0102
86 #define EIGRP_TLV_IP_EXT 0x0103
87 #define EIGRP_TLV_AT_INT 0x0202
88 #define EIGRP_TLV_AT_EXT 0x0203
89 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
90 #define EIGRP_TLV_IPX_INT 0x0302
91 #define EIGRP_TLV_IPX_EXT 0x0303
93 static const struct tok eigrp_tlv_values
[] = {
94 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
95 { EIGRP_TLV_AUTH
, "Authentication"},
96 { EIGRP_TLV_SEQ
, "Sequence"},
97 { EIGRP_TLV_SW_VERSION
, "Software Version"},
98 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
99 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
100 { EIGRP_TLV_IP_EXT
, "IP External routes"},
101 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
102 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
103 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
104 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
105 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
109 struct eigrp_tlv_general_parm_t
{
116 nd_uint16_t holdtime
;
119 struct eigrp_tlv_sw_version_t
{
120 nd_uint8_t ios_major
;
121 nd_uint8_t ios_minor
;
122 nd_uint8_t eigrp_major
;
123 nd_uint8_t eigrp_minor
;
126 struct eigrp_tlv_ip_int_t
{
129 nd_uint32_t bandwidth
;
132 nd_uint8_t reliability
;
136 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
139 struct eigrp_tlv_ip_ext_t
{
141 nd_ipv4 origin_router
;
142 nd_uint32_t origin_as
;
149 nd_uint32_t bandwidth
;
152 nd_uint8_t reliability
;
154 nd_byte reserved2
[2];
156 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
159 struct eigrp_tlv_at_cable_setup_t
{
160 nd_uint16_t cable_start
;
161 nd_uint16_t cable_end
;
162 nd_uint32_t router_id
;
165 struct eigrp_tlv_at_int_t
{
168 nd_uint32_t bandwidth
;
171 nd_uint8_t reliability
;
174 nd_uint16_t cable_start
;
175 nd_uint16_t cable_end
;
178 struct eigrp_tlv_at_ext_t
{
180 nd_uint32_t origin_router
;
181 nd_uint32_t origin_as
;
187 nd_uint32_t bandwidth
;
190 nd_uint8_t reliability
;
192 nd_byte reserved2
[2];
193 nd_uint16_t cable_start
;
194 nd_uint16_t cable_end
;
197 static const struct tok eigrp_ext_proto_id_values
[] = {
208 { 0x0b, "Connected" },
213 eigrp_print(netdissect_options
*ndo
, const u_char
*pptr
, u_int len
)
215 const struct eigrp_common_header
*eigrp_com_header
;
216 const struct eigrp_tlv_header
*eigrp_tlv_header
;
217 const u_char
*tptr
,*tlv_tptr
;
218 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
222 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
223 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
224 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
225 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
226 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
227 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
228 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
231 ndo
->ndo_protocol
= "eigrp";
233 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
234 ND_TCHECK_SIZE(eigrp_com_header
);
237 * Sanity checking of the header.
239 if (GET_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
240 ND_PRINT("EIGRP version %u packet not supported",
241 GET_U_1(eigrp_com_header
->version
));
245 /* in non-verbose mode just lets print the basic Message Type*/
246 if (ndo
->ndo_vflag
< 1) {
247 ND_PRINT("EIGRP %s, length: %u",
248 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
253 /* ok they seem to want to know everything - lets fully decode it */
255 if (len
< sizeof(struct eigrp_common_header
)) {
256 ND_PRINT("EIGRP %s, length: %u (too short, < %zu)",
257 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
258 len
, sizeof(struct eigrp_common_header
));
261 tlen
=len
-sizeof(struct eigrp_common_header
);
263 ND_PRINT("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]"
264 "\n\tseq: 0x%08x, ack: 0x%08x, VRID: %u, AS: %u, length: %u",
265 GET_U_1(eigrp_com_header
->version
),
266 tok2str(eigrp_opcode_values
, "unknown, type: %u",GET_U_1(eigrp_com_header
->opcode
)),
267 GET_U_1(eigrp_com_header
->opcode
),
268 GET_BE_U_2(eigrp_com_header
->checksum
),
269 bittok2str(eigrp_common_header_flag_values
,
271 GET_BE_U_4(eigrp_com_header
->flags
)),
272 GET_BE_U_4(eigrp_com_header
->seq
),
273 GET_BE_U_4(eigrp_com_header
->ack
),
274 GET_BE_U_2(eigrp_com_header
->vrid
),
275 GET_BE_U_2(eigrp_com_header
->asn
),
278 tptr
+=sizeof(struct eigrp_common_header
);
281 /* did we capture enough for fully decoding the object header ? */
282 ND_TCHECK_LEN(tptr
, sizeof(struct eigrp_tlv_header
));
284 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
285 eigrp_tlv_len
=GET_BE_U_2(eigrp_tlv_header
->length
);
286 eigrp_tlv_type
=GET_BE_U_2(eigrp_tlv_header
->type
);
289 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
290 eigrp_tlv_len
> tlen
) {
291 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
295 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
296 tok2str(eigrp_tlv_values
,
302 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
)) {
303 ND_PRINT(" (too short, < %zu)",
304 sizeof(struct eigrp_tlv_header
));
307 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
308 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
310 /* did we capture enough for fully decoding the object ? */
311 ND_TCHECK_LEN(tptr
, eigrp_tlv_len
);
313 switch(eigrp_tlv_type
) {
315 case EIGRP_TLV_GENERAL_PARM
:
316 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
317 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)) {
318 ND_PRINT(" (too short, < %zu)",
319 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_general_parm
));
323 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
324 GET_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
325 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
326 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
327 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
328 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
329 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k5
));
332 case EIGRP_TLV_SW_VERSION
:
333 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
334 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)) {
335 ND_PRINT(" (too short, < %zu)",
336 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_sw_version
));
340 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
341 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
342 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
343 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
344 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
347 case EIGRP_TLV_IP_INT
:
348 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
349 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)) {
350 ND_PRINT(" (too short, < %zu)",
351 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
));
355 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->plen
);
356 if (bit_length
> 32) {
357 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
360 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
361 memset(prefix
, 0, 4);
362 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_int
->destination
, byte_length
);
364 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
365 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
367 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
371 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
));
373 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
374 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
375 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
376 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
377 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
378 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
379 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->load
));
382 case EIGRP_TLV_IP_EXT
:
383 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
384 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)) {
385 ND_PRINT(" (too short, < %zu)",
386 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
));
390 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->plen
);
391 if (bit_length
> 32) {
392 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
395 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
396 memset(prefix
, 0, 4);
397 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_ext
->destination
, byte_length
);
399 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
400 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
402 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
406 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
));
408 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
409 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
410 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
411 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
412 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
413 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
414 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->metric
));
416 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
417 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
418 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
419 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
420 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
421 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
422 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->load
));
425 case EIGRP_TLV_AT_CABLE_SETUP
:
426 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
427 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)) {
428 ND_PRINT(" (too short, < %zu)",
429 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
));
433 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
434 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
435 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
436 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
));
439 case EIGRP_TLV_AT_INT
:
440 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
441 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_int
)) {
442 ND_PRINT(" (too short, < %zu)",
443 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
));
447 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
448 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
449 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
451 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
455 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
456 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2]));
458 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
459 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
460 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
461 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
462 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
463 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
464 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->load
));
467 case EIGRP_TLV_AT_EXT
:
468 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
469 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)) {
470 ND_PRINT(" (too short, < %zu)",
471 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
));
475 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
476 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
477 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
479 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
483 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
484 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2]));
486 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
487 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
488 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
489 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
490 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
491 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
492 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->metric
));
494 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
495 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
496 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
497 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
498 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
499 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
500 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->load
));
504 * FIXME those are the defined TLVs that lack a decoder
505 * you are welcome to contribute code ;-)
510 case EIGRP_TLV_MCAST_SEQ
:
511 case EIGRP_TLV_IPX_INT
:
512 case EIGRP_TLV_IPX_EXT
:
515 if (ndo
->ndo_vflag
<= 1)
516 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
519 /* do we want to see an additionally hexdump ? */
520 if (ndo
->ndo_vflag
> 1)
521 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
522 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));