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
30 #include "netdissect-stdinc.h"
34 #include "netdissect.h"
36 #include "addrtoname.h"
39 struct eigrp_common_header
{
50 #define EIGRP_VERSION 2
52 #define EIGRP_OPCODE_UPDATE 1
53 #define EIGRP_OPCODE_QUERY 3
54 #define EIGRP_OPCODE_REPLY 4
55 #define EIGRP_OPCODE_HELLO 5
56 #define EIGRP_OPCODE_IPXSAP 6
57 #define EIGRP_OPCODE_PROBE 7
59 static const struct tok eigrp_opcode_values
[] = {
60 { EIGRP_OPCODE_UPDATE
, "Update" },
61 { EIGRP_OPCODE_QUERY
, "Query" },
62 { EIGRP_OPCODE_REPLY
, "Reply" },
63 { EIGRP_OPCODE_HELLO
, "Hello" },
64 { EIGRP_OPCODE_IPXSAP
, "IPX SAP" },
65 { EIGRP_OPCODE_PROBE
, "Probe" },
69 static const struct tok eigrp_common_header_flag_values
[] = {
71 { 0x02, "Conditionally Received" },
73 { 0x08, "End-of-Table" },
77 struct eigrp_tlv_header
{
82 #define EIGRP_TLV_GENERAL_PARM 0x0001
83 #define EIGRP_TLV_AUTH 0x0002
84 #define EIGRP_TLV_SEQ 0x0003
85 #define EIGRP_TLV_SW_VERSION 0x0004
86 #define EIGRP_TLV_MCAST_SEQ 0x0005
87 #define EIGRP_TLV_IP_INT 0x0102
88 #define EIGRP_TLV_IP_EXT 0x0103
89 #define EIGRP_TLV_AT_INT 0x0202
90 #define EIGRP_TLV_AT_EXT 0x0203
91 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
92 #define EIGRP_TLV_IPX_INT 0x0302
93 #define EIGRP_TLV_IPX_EXT 0x0303
95 static const struct tok eigrp_tlv_values
[] = {
96 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
97 { EIGRP_TLV_AUTH
, "Authentication"},
98 { EIGRP_TLV_SEQ
, "Sequence"},
99 { EIGRP_TLV_SW_VERSION
, "Software Version"},
100 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
101 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
102 { EIGRP_TLV_IP_EXT
, "IP External routes"},
103 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
104 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
105 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
106 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
107 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
111 struct eigrp_tlv_general_parm_t
{
118 nd_uint16_t holdtime
;
121 struct eigrp_tlv_sw_version_t
{
122 nd_uint8_t ios_major
;
123 nd_uint8_t ios_minor
;
124 nd_uint8_t eigrp_major
;
125 nd_uint8_t eigrp_minor
;
128 struct eigrp_tlv_ip_int_t
{
131 nd_uint32_t bandwidth
;
134 nd_uint8_t reliability
;
138 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
141 struct eigrp_tlv_ip_ext_t
{
143 nd_ipv4 origin_router
;
144 nd_uint32_t origin_as
;
151 nd_uint32_t bandwidth
;
154 nd_uint8_t reliability
;
156 nd_byte reserved2
[2];
158 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
161 struct eigrp_tlv_at_cable_setup_t
{
162 nd_uint16_t cable_start
;
163 nd_uint16_t cable_end
;
164 nd_uint32_t router_id
;
167 struct eigrp_tlv_at_int_t
{
170 nd_uint32_t bandwidth
;
173 nd_uint8_t reliability
;
176 nd_uint16_t cable_start
;
177 nd_uint16_t cable_end
;
180 struct eigrp_tlv_at_ext_t
{
182 nd_uint32_t origin_router
;
183 nd_uint32_t origin_as
;
189 nd_uint32_t bandwidth
;
192 nd_uint8_t reliability
;
194 nd_byte reserved2
[2];
195 nd_uint16_t cable_start
;
196 nd_uint16_t cable_end
;
199 static const struct tok eigrp_ext_proto_id_values
[] = {
210 { 0x0b, "Connected" },
215 eigrp_print(netdissect_options
*ndo
, const u_char
*pptr
, u_int len
)
217 const struct eigrp_common_header
*eigrp_com_header
;
218 const struct eigrp_tlv_header
*eigrp_tlv_header
;
219 const u_char
*tptr
,*tlv_tptr
;
220 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
224 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
225 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
226 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
227 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
228 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
229 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
230 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
233 ndo
->ndo_protocol
= "eigrp";
235 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
236 ND_TCHECK_SIZE(eigrp_com_header
);
239 * Sanity checking of the header.
241 if (GET_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
242 ND_PRINT("EIGRP version %u packet not supported",
243 GET_U_1(eigrp_com_header
->version
));
247 /* in non-verbose mode just lets print the basic Message Type*/
248 if (ndo
->ndo_vflag
< 1) {
249 ND_PRINT("EIGRP %s, length: %u",
250 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
255 /* ok they seem to want to know everything - lets fully decode it */
257 if (len
< sizeof(struct eigrp_common_header
)) {
258 ND_PRINT("EIGRP %s, length: %u (too short, < %zu)",
259 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
260 len
, sizeof(struct eigrp_common_header
));
263 tlen
=len
-sizeof(struct eigrp_common_header
);
265 ND_PRINT("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]"
266 "\n\tseq: 0x%08x, ack: 0x%08x, VRID: %u, AS: %u, length: %u",
267 GET_U_1(eigrp_com_header
->version
),
268 tok2str(eigrp_opcode_values
, "unknown, type: %u",GET_U_1(eigrp_com_header
->opcode
)),
269 GET_U_1(eigrp_com_header
->opcode
),
270 GET_BE_U_2(eigrp_com_header
->checksum
),
271 bittok2str(eigrp_common_header_flag_values
,
273 GET_BE_U_4(eigrp_com_header
->flags
)),
274 GET_BE_U_4(eigrp_com_header
->seq
),
275 GET_BE_U_4(eigrp_com_header
->ack
),
276 GET_BE_U_2(eigrp_com_header
->vrid
),
277 GET_BE_U_2(eigrp_com_header
->asn
),
280 tptr
+=sizeof(struct eigrp_common_header
);
283 /* did we capture enough for fully decoding the object header ? */
284 ND_TCHECK_LEN(tptr
, sizeof(struct eigrp_tlv_header
));
286 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
287 eigrp_tlv_len
=GET_BE_U_2(eigrp_tlv_header
->length
);
288 eigrp_tlv_type
=GET_BE_U_2(eigrp_tlv_header
->type
);
291 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
292 eigrp_tlv_len
> tlen
) {
293 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
297 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
298 tok2str(eigrp_tlv_values
,
304 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
)) {
305 ND_PRINT(" (too short, < %zu)",
306 sizeof(struct eigrp_tlv_header
));
309 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
310 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
312 /* did we capture enough for fully decoding the object ? */
313 ND_TCHECK_LEN(tptr
, eigrp_tlv_len
);
315 switch(eigrp_tlv_type
) {
317 case EIGRP_TLV_GENERAL_PARM
:
318 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
319 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)) {
320 ND_PRINT(" (too short, < %zu)",
321 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_general_parm
));
325 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
326 GET_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
327 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
328 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
329 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
330 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
331 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k5
));
334 case EIGRP_TLV_SW_VERSION
:
335 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
336 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)) {
337 ND_PRINT(" (too short, < %zu)",
338 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_sw_version
));
342 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
343 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
344 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
345 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
346 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
349 case EIGRP_TLV_IP_INT
:
350 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
351 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)) {
352 ND_PRINT(" (too short, < %zu)",
353 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
));
357 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->plen
);
358 if (bit_length
> 32) {
359 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
362 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
363 memset(prefix
, 0, 4);
364 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_int
->destination
, byte_length
);
366 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
367 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
369 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
373 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
));
375 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
376 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
377 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
378 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
379 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
380 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
381 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->load
));
384 case EIGRP_TLV_IP_EXT
:
385 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
386 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)) {
387 ND_PRINT(" (too short, < %zu)",
388 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
));
392 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->plen
);
393 if (bit_length
> 32) {
394 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
397 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
398 memset(prefix
, 0, 4);
399 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_ext
->destination
, byte_length
);
401 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
402 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
404 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
408 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
));
410 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
411 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
412 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
413 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
414 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
415 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
416 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->metric
));
418 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
419 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
420 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
421 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
422 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
423 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
424 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->load
));
427 case EIGRP_TLV_AT_CABLE_SETUP
:
428 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
429 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)) {
430 ND_PRINT(" (too short, < %zu)",
431 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
));
435 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
436 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
437 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
438 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
));
441 case EIGRP_TLV_AT_INT
:
442 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
443 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_int
)) {
444 ND_PRINT(" (too short, < %zu)",
445 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
));
449 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
450 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
451 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
453 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
457 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
458 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2]));
460 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
461 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
462 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
463 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
464 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
465 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
466 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->load
));
469 case EIGRP_TLV_AT_EXT
:
470 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
471 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)) {
472 ND_PRINT(" (too short, < %zu)",
473 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
));
477 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
478 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
479 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
481 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
485 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
486 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2]));
488 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
489 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
490 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
491 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
492 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
493 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
494 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->metric
));
496 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
497 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
498 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
499 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
500 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
501 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
502 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->load
));
506 * FIXME those are the defined TLVs that lack a decoder
507 * you are welcome to contribute code ;-)
512 case EIGRP_TLV_MCAST_SEQ
:
513 case EIGRP_TLV_IPX_INT
:
514 case EIGRP_TLV_IPX_EXT
:
517 if (ndo
->ndo_vflag
<= 1)
518 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
521 /* do we want to see an additionally hexdump ? */
522 if (ndo
->ndo_vflag
> 1)
523 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
524 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));