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 #define ND_LONGJMP_FROM_TCHECK
35 #include "netdissect.h"
37 #include "addrtoname.h"
40 struct eigrp_common_header
{
51 #define EIGRP_VERSION 2
53 #define EIGRP_OPCODE_UPDATE 1
54 #define EIGRP_OPCODE_QUERY 3
55 #define EIGRP_OPCODE_REPLY 4
56 #define EIGRP_OPCODE_HELLO 5
57 #define EIGRP_OPCODE_IPXSAP 6
58 #define EIGRP_OPCODE_PROBE 7
60 static const struct tok eigrp_opcode_values
[] = {
61 { EIGRP_OPCODE_UPDATE
, "Update" },
62 { EIGRP_OPCODE_QUERY
, "Query" },
63 { EIGRP_OPCODE_REPLY
, "Reply" },
64 { EIGRP_OPCODE_HELLO
, "Hello" },
65 { EIGRP_OPCODE_IPXSAP
, "IPX SAP" },
66 { EIGRP_OPCODE_PROBE
, "Probe" },
70 static const struct tok eigrp_common_header_flag_values
[] = {
72 { 0x02, "Conditionally Received" },
74 { 0x08, "End-of-Table" },
78 struct eigrp_tlv_header
{
83 #define EIGRP_TLV_GENERAL_PARM 0x0001
84 #define EIGRP_TLV_AUTH 0x0002
85 #define EIGRP_TLV_SEQ 0x0003
86 #define EIGRP_TLV_SW_VERSION 0x0004
87 #define EIGRP_TLV_MCAST_SEQ 0x0005
88 #define EIGRP_TLV_IP_INT 0x0102
89 #define EIGRP_TLV_IP_EXT 0x0103
90 #define EIGRP_TLV_AT_INT 0x0202
91 #define EIGRP_TLV_AT_EXT 0x0203
92 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
93 #define EIGRP_TLV_IPX_INT 0x0302
94 #define EIGRP_TLV_IPX_EXT 0x0303
96 static const struct tok eigrp_tlv_values
[] = {
97 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
98 { EIGRP_TLV_AUTH
, "Authentication"},
99 { EIGRP_TLV_SEQ
, "Sequence"},
100 { EIGRP_TLV_SW_VERSION
, "Software Version"},
101 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
102 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
103 { EIGRP_TLV_IP_EXT
, "IP External routes"},
104 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
105 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
106 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
107 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
108 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
112 struct eigrp_tlv_general_parm_t
{
119 nd_uint16_t holdtime
;
122 struct eigrp_tlv_sw_version_t
{
123 nd_uint8_t ios_major
;
124 nd_uint8_t ios_minor
;
125 nd_uint8_t eigrp_major
;
126 nd_uint8_t eigrp_minor
;
129 struct eigrp_tlv_ip_int_t
{
132 nd_uint32_t bandwidth
;
135 nd_uint8_t reliability
;
139 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
142 struct eigrp_tlv_ip_ext_t
{
144 nd_ipv4 origin_router
;
145 nd_uint32_t origin_as
;
152 nd_uint32_t bandwidth
;
155 nd_uint8_t reliability
;
157 nd_byte reserved2
[2];
159 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
162 struct eigrp_tlv_at_cable_setup_t
{
163 nd_uint16_t cable_start
;
164 nd_uint16_t cable_end
;
165 nd_uint32_t router_id
;
168 struct eigrp_tlv_at_int_t
{
171 nd_uint32_t bandwidth
;
174 nd_uint8_t reliability
;
177 nd_uint16_t cable_start
;
178 nd_uint16_t cable_end
;
181 struct eigrp_tlv_at_ext_t
{
183 nd_uint32_t origin_router
;
184 nd_uint32_t origin_as
;
190 nd_uint32_t bandwidth
;
193 nd_uint8_t reliability
;
195 nd_byte reserved2
[2];
196 nd_uint16_t cable_start
;
197 nd_uint16_t cable_end
;
200 static const struct tok eigrp_ext_proto_id_values
[] = {
211 { 0x0b, "Connected" },
216 eigrp_print(netdissect_options
*ndo
, const u_char
*pptr
, u_int len
)
218 const struct eigrp_common_header
*eigrp_com_header
;
219 const struct eigrp_tlv_header
*eigrp_tlv_header
;
220 const u_char
*tptr
,*tlv_tptr
;
221 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
225 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
226 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
227 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
228 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
229 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
230 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
231 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
234 ndo
->ndo_protocol
= "eigrp";
237 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
240 * Sanity checking of the header.
242 if (len
< sizeof(struct eigrp_common_header
)) {
243 ND_PRINT("EIGRP %s, length: %u (too short, < %zu)",
244 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
245 len
, sizeof(struct eigrp_common_header
));
246 goto check_remainder
;
248 if (GET_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
249 ND_PRINT("EIGRP version %u packet not supported",
250 GET_U_1(eigrp_com_header
->version
));
251 goto check_remainder
;
254 /* in non-verbose mode just lets print the basic Message Type*/
255 if (ndo
->ndo_vflag
< 1) {
256 ND_PRINT("EIGRP %s, length: %u",
257 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
259 goto check_remainder
;
262 /* ok they seem to want to know everything - lets fully decode it */
263 tlen
-= 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 if (tlen
< sizeof(struct eigrp_tlv_header
)) {
284 ND_PRINT("\n\t (only %u bytes of data)", tlen
);
287 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
288 eigrp_tlv_len
=GET_BE_U_2(eigrp_tlv_header
->length
);
289 eigrp_tlv_type
=GET_BE_U_2(eigrp_tlv_header
->type
);
291 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
292 tok2str(eigrp_tlv_values
,
298 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
299 eigrp_tlv_len
> tlen
) {
302 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
303 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
305 /* did we capture enough for fully decoding the object ? */
306 ND_TCHECK_LEN(tptr
, eigrp_tlv_len
);
308 switch(eigrp_tlv_type
) {
310 case EIGRP_TLV_GENERAL_PARM
:
311 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
312 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)) {
313 ND_PRINT(" (too short, < %zu)",
314 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_general_parm
));
318 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
319 GET_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
320 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
321 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
322 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
323 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
324 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k5
));
327 case EIGRP_TLV_SW_VERSION
:
328 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
329 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)) {
330 ND_PRINT(" (too short, < %zu)",
331 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_sw_version
));
335 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
336 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
337 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
338 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
339 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
342 case EIGRP_TLV_IP_INT
:
343 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
344 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)) {
345 ND_PRINT(" (too short, < %zu)",
346 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
));
350 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->plen
);
351 if (bit_length
> 32) {
352 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
355 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
356 memset(prefix
, 0, 4);
357 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_int
->destination
, byte_length
);
359 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
360 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
362 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
366 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
));
368 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
369 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
370 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
371 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
372 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
373 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
374 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->load
));
377 case EIGRP_TLV_IP_EXT
:
378 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
379 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)) {
380 ND_PRINT(" (too short, < %zu)",
381 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
));
385 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->plen
);
386 if (bit_length
> 32) {
387 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
390 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
391 memset(prefix
, 0, 4);
392 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_ext
->destination
, byte_length
);
394 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
395 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
397 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
401 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
));
403 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
404 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
405 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
406 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
407 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
408 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
409 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->metric
));
411 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
412 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
413 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
414 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
415 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
416 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
417 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->load
));
420 case EIGRP_TLV_AT_CABLE_SETUP
:
421 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
422 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)) {
423 ND_PRINT(" (too short, < %zu)",
424 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
));
428 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
429 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
430 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
431 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
));
434 case EIGRP_TLV_AT_INT
:
435 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
436 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_int
)) {
437 ND_PRINT(" (too short, < %zu)",
438 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
));
442 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
443 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
444 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
446 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
450 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
451 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2]));
453 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
454 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
455 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
456 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
457 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
458 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
459 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->load
));
462 case EIGRP_TLV_AT_EXT
:
463 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
464 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)) {
465 ND_PRINT(" (too short, < %zu)",
466 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
));
470 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
471 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
472 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
474 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
478 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
479 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2]));
481 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
482 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
483 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
484 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
485 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
486 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
487 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->metric
));
489 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
490 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
491 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
492 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
493 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
494 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
495 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->load
));
499 * FIXME those are the defined TLVs that lack a decoder
500 * you are welcome to contribute code ;-)
505 case EIGRP_TLV_MCAST_SEQ
:
506 case EIGRP_TLV_IPX_INT
:
507 case EIGRP_TLV_IPX_EXT
:
510 if (ndo
->ndo_vflag
<= 1)
511 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
514 /* do we want to see an additionally hexdump ? */
515 if (ndo
->ndo_vflag
> 1)
516 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
517 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));
524 nd_print_invalid(ndo
);
526 ND_TCHECK_LEN(tptr
, tlen
);