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 #define ND_LONGJMP_FROM_TCHECK
33 #include "netdissect.h"
35 #include "addrtoname.h"
38 struct eigrp_common_header
{
49 #define EIGRP_VERSION 2
51 #define EIGRP_OPCODE_UPDATE 1
52 #define EIGRP_OPCODE_QUERY 3
53 #define EIGRP_OPCODE_REPLY 4
54 #define EIGRP_OPCODE_HELLO 5
55 #define EIGRP_OPCODE_IPXSAP 6
56 #define EIGRP_OPCODE_PROBE 7
58 static const struct tok eigrp_opcode_values
[] = {
59 { EIGRP_OPCODE_UPDATE
, "Update" },
60 { EIGRP_OPCODE_QUERY
, "Query" },
61 { EIGRP_OPCODE_REPLY
, "Reply" },
62 { EIGRP_OPCODE_HELLO
, "Hello" },
63 { EIGRP_OPCODE_IPXSAP
, "IPX SAP" },
64 { EIGRP_OPCODE_PROBE
, "Probe" },
68 static const struct tok eigrp_common_header_flag_values
[] = {
70 { 0x02, "Conditionally Received" },
72 { 0x08, "End-of-Table" },
76 struct eigrp_tlv_header
{
81 #define EIGRP_TLV_GENERAL_PARM 0x0001
82 #define EIGRP_TLV_AUTH 0x0002
83 #define EIGRP_TLV_SEQ 0x0003
84 #define EIGRP_TLV_SW_VERSION 0x0004
85 #define EIGRP_TLV_MCAST_SEQ 0x0005
86 #define EIGRP_TLV_IP_INT 0x0102
87 #define EIGRP_TLV_IP_EXT 0x0103
88 #define EIGRP_TLV_AT_INT 0x0202
89 #define EIGRP_TLV_AT_EXT 0x0203
90 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
91 #define EIGRP_TLV_IPX_INT 0x0302
92 #define EIGRP_TLV_IPX_EXT 0x0303
94 static const struct tok eigrp_tlv_values
[] = {
95 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
96 { EIGRP_TLV_AUTH
, "Authentication"},
97 { EIGRP_TLV_SEQ
, "Sequence"},
98 { EIGRP_TLV_SW_VERSION
, "Software Version"},
99 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
100 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
101 { EIGRP_TLV_IP_EXT
, "IP External routes"},
102 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
103 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
104 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
105 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
106 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
110 struct eigrp_tlv_general_parm_t
{
117 nd_uint16_t holdtime
;
120 struct eigrp_tlv_sw_version_t
{
121 nd_uint8_t ios_major
;
122 nd_uint8_t ios_minor
;
123 nd_uint8_t eigrp_major
;
124 nd_uint8_t eigrp_minor
;
127 struct eigrp_tlv_ip_int_t
{
130 nd_uint32_t bandwidth
;
133 nd_uint8_t reliability
;
137 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
140 struct eigrp_tlv_ip_ext_t
{
142 nd_ipv4 origin_router
;
143 nd_uint32_t origin_as
;
150 nd_uint32_t bandwidth
;
153 nd_uint8_t reliability
;
155 nd_byte reserved2
[2];
157 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
160 struct eigrp_tlv_at_cable_setup_t
{
161 nd_uint16_t cable_start
;
162 nd_uint16_t cable_end
;
163 nd_uint32_t router_id
;
166 struct eigrp_tlv_at_int_t
{
169 nd_uint32_t bandwidth
;
172 nd_uint8_t reliability
;
175 nd_uint16_t cable_start
;
176 nd_uint16_t cable_end
;
179 struct eigrp_tlv_at_ext_t
{
181 nd_uint32_t origin_router
;
182 nd_uint32_t origin_as
;
188 nd_uint32_t bandwidth
;
191 nd_uint8_t reliability
;
193 nd_byte reserved2
[2];
194 nd_uint16_t cable_start
;
195 nd_uint16_t cable_end
;
198 static const struct tok eigrp_ext_proto_id_values
[] = {
209 { 0x0b, "Connected" },
214 eigrp_print(netdissect_options
*ndo
, const u_char
*pptr
, u_int len
)
216 const struct eigrp_common_header
*eigrp_com_header
;
217 const struct eigrp_tlv_header
*eigrp_tlv_header
;
218 const u_char
*tptr
,*tlv_tptr
;
219 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
223 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
224 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
225 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
226 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
227 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
228 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
229 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
232 ndo
->ndo_protocol
= "eigrp";
235 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
238 * Sanity checking of the header.
240 if (len
< sizeof(struct eigrp_common_header
)) {
241 ND_PRINT("EIGRP %s, length: %u (too short, < %zu)",
242 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
243 len
, sizeof(struct eigrp_common_header
));
244 goto check_remainder
;
246 if (GET_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
247 ND_PRINT("EIGRP version %u packet not supported",
248 GET_U_1(eigrp_com_header
->version
));
249 goto check_remainder
;
252 /* in non-verbose mode just lets print the basic Message Type*/
253 if (ndo
->ndo_vflag
< 1) {
254 ND_PRINT("EIGRP %s, length: %u",
255 tok2str(eigrp_opcode_values
, "unknown (%u)",GET_U_1(eigrp_com_header
->opcode
)),
257 goto check_remainder
;
260 /* ok they seem to want to know everything - lets fully decode it */
261 tlen
-= 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 if (tlen
< sizeof(struct eigrp_tlv_header
)) {
282 ND_PRINT("\n\t (only %u bytes of data)", tlen
);
285 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
286 eigrp_tlv_len
=GET_BE_U_2(eigrp_tlv_header
->length
);
287 eigrp_tlv_type
=GET_BE_U_2(eigrp_tlv_header
->type
);
289 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
290 tok2str(eigrp_tlv_values
,
296 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
297 eigrp_tlv_len
> tlen
) {
300 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
301 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
303 /* did we capture enough for fully decoding the object ? */
304 ND_TCHECK_LEN(tptr
, eigrp_tlv_len
);
306 switch(eigrp_tlv_type
) {
308 case EIGRP_TLV_GENERAL_PARM
:
309 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
310 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)) {
311 ND_PRINT(" (too short, < %zu)",
312 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_general_parm
));
316 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
317 GET_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
318 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
319 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
320 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
321 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
322 GET_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k5
));
325 case EIGRP_TLV_SW_VERSION
:
326 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
327 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)) {
328 ND_PRINT(" (too short, < %zu)",
329 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_sw_version
));
333 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
334 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
335 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
336 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
337 GET_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
340 case EIGRP_TLV_IP_INT
:
341 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
342 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)) {
343 ND_PRINT(" (too short, < %zu)",
344 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
));
348 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->plen
);
349 if (bit_length
> 32) {
350 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
353 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
354 memset(prefix
, 0, 4);
355 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_int
->destination
, byte_length
);
357 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
358 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
360 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
364 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
));
366 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
367 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
368 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
369 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
370 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
371 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
372 GET_U_1(tlv_ptr
.eigrp_tlv_ip_int
->load
));
375 case EIGRP_TLV_IP_EXT
:
376 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
377 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)) {
378 ND_PRINT(" (too short, < %zu)",
379 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
));
383 bit_length
= GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->plen
);
384 if (bit_length
> 32) {
385 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
388 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
389 memset(prefix
, 0, 4);
390 GET_CPY_BYTES(prefix
, tlv_ptr
.eigrp_tlv_ip_ext
->destination
, byte_length
);
392 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
393 ipaddr_string(ndo
, prefix
), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
395 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
399 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
));
401 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
402 GET_IPADDR_STRING(tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
403 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
404 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
405 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
406 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
407 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->metric
));
409 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
410 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
411 GET_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
412 GET_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
413 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
414 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
415 GET_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->load
));
418 case EIGRP_TLV_AT_CABLE_SETUP
:
419 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
420 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)) {
421 ND_PRINT(" (too short, < %zu)",
422 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
));
426 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
427 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
428 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
429 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
));
432 case EIGRP_TLV_AT_INT
:
433 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
434 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_int
)) {
435 ND_PRINT(" (too short, < %zu)",
436 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
));
440 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
441 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
442 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
444 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
448 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
449 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2]));
451 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
452 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
453 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
454 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
455 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
456 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
457 GET_U_1(tlv_ptr
.eigrp_tlv_at_int
->load
));
460 case EIGRP_TLV_AT_EXT
:
461 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
462 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)) {
463 ND_PRINT(" (too short, < %zu)",
464 sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
));
468 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
469 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
470 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
472 if (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
476 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
477 GET_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2]));
479 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
480 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
481 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
482 tok2str(eigrp_ext_proto_id_values
,"unknown",GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
483 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
484 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
485 GET_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->metric
));
487 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
488 (GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
489 GET_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
490 GET_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
491 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
492 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
493 GET_U_1(tlv_ptr
.eigrp_tlv_at_ext
->load
));
497 * FIXME those are the defined TLVs that lack a decoder
498 * you are welcome to contribute code ;-)
503 case EIGRP_TLV_MCAST_SEQ
:
504 case EIGRP_TLV_IPX_INT
:
505 case EIGRP_TLV_IPX_EXT
:
508 if (ndo
->ndo_vflag
<= 1)
509 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
512 /* do we want to see an additionally hexdump ? */
513 if (ndo
->ndo_vflag
> 1)
514 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
515 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));
522 nd_print_invalid(ndo
);
524 ND_TCHECK_LEN(tptr
, tlen
);