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 * http://www.rhyshaden.com/eigrp.htm
30 #include "netdissect-stdinc.h"
34 #include "netdissect.h"
36 #include "addrtoname.h"
38 static const char tstr
[] = " [|eigrp]";
40 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" },
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 (EXTRACT_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
240 ND_PRINT("EIGRP version %u packet not supported",EXTRACT_U_1(eigrp_com_header
->version
));
244 /* in non-verbose mode just lets print the basic Message Type*/
245 if (ndo
->ndo_vflag
< 1) {
246 ND_PRINT("EIGRP %s, length: %u",
247 tok2str(eigrp_opcode_values
, "unknown (%u)",EXTRACT_U_1(eigrp_com_header
->opcode
)),
252 /* ok they seem to want to know everything - lets fully decode it */
254 if (len
< sizeof(struct eigrp_common_header
)) {
255 ND_PRINT("EIGRP %s, length: %u (too short, < %u)",
256 tok2str(eigrp_opcode_values
, "unknown (%u)",EXTRACT_U_1(eigrp_com_header
->opcode
)),
257 len
, (u_int
) sizeof(struct eigrp_common_header
));
260 tlen
=len
-sizeof(struct eigrp_common_header
);
262 /* FIXME print other header info */
263 ND_PRINT("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
264 EXTRACT_U_1(eigrp_com_header
->version
),
265 tok2str(eigrp_opcode_values
, "unknown, type: %u",EXTRACT_U_1(eigrp_com_header
->opcode
)),
266 EXTRACT_U_1(eigrp_com_header
->opcode
),
267 EXTRACT_BE_U_2(eigrp_com_header
->checksum
),
268 tok2str(eigrp_common_header_flag_values
,
270 EXTRACT_BE_U_4(eigrp_com_header
->flags
)),
271 EXTRACT_BE_U_4(eigrp_com_header
->seq
),
272 EXTRACT_BE_U_4(eigrp_com_header
->ack
),
273 EXTRACT_BE_U_4(eigrp_com_header
->asn
),
276 tptr
+=sizeof(struct eigrp_common_header
);
279 /* did we capture enough for fully decoding the object header ? */
280 ND_TCHECK_LEN(tptr
, sizeof(struct eigrp_tlv_header
));
282 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
283 eigrp_tlv_len
=EXTRACT_BE_U_2(eigrp_tlv_header
->length
);
284 eigrp_tlv_type
=EXTRACT_BE_U_2(eigrp_tlv_header
->type
);
287 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
288 eigrp_tlv_len
> tlen
) {
289 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
293 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
294 tok2str(eigrp_tlv_values
,
300 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
)) {
301 ND_PRINT(" (too short, < %u)",
302 (u_int
) sizeof(struct eigrp_tlv_header
));
305 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
306 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
308 /* did we capture enough for fully decoding the object ? */
309 ND_TCHECK_LEN(tptr
, eigrp_tlv_len
);
311 switch(eigrp_tlv_type
) {
313 case EIGRP_TLV_GENERAL_PARM
:
314 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
315 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)) {
316 ND_PRINT(" (too short, < %u)",
317 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)));
321 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
322 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
323 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
324 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
325 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
326 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
327 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k5
));
330 case EIGRP_TLV_SW_VERSION
:
331 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
332 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)) {
333 ND_PRINT(" (too short, < %u)",
334 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)));
338 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
339 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
340 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
341 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
342 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
345 case EIGRP_TLV_IP_INT
:
346 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
347 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)) {
348 ND_PRINT(" (too short, < %u)",
349 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)));
353 bit_length
= EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->plen
);
354 if (bit_length
> 32) {
355 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
358 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
359 memset(prefix
, 0, 4);
360 memcpy(prefix
, tlv_ptr
.eigrp_tlv_ip_int
->destination
, byte_length
);
362 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
363 ipaddr_string(ndo
, prefix
),
365 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
369 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_int
->nexthop
));
371 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
372 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
373 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
374 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
375 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
376 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
377 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->load
));
380 case EIGRP_TLV_IP_EXT
:
381 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
382 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)) {
383 ND_PRINT(" (too short, < %u)",
384 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)));
388 bit_length
= EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->plen
);
389 if (bit_length
> 32) {
390 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
393 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
394 memset(prefix
, 0, 4);
395 memcpy(prefix
, tlv_ptr
.eigrp_tlv_ip_ext
->destination
, byte_length
);
397 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
398 ipaddr_string(ndo
, prefix
),
400 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
404 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
));
406 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
407 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
408 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
409 tok2str(eigrp_ext_proto_id_values
,"unknown",EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
410 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
411 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
412 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->metric
));
414 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
415 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
416 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
417 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
418 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
419 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
420 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->load
));
423 case EIGRP_TLV_AT_CABLE_SETUP
:
424 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
425 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)) {
426 ND_PRINT(" (too short, < %u)",
427 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)));
431 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
432 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
433 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
434 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
));
437 case EIGRP_TLV_AT_INT
:
438 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
439 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_int
)) {
440 ND_PRINT(" (too short, < %u)",
441 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
)));
445 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
446 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
447 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
449 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
453 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
454 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2]));
456 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
457 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
458 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
459 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
460 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
461 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
462 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->load
));
465 case EIGRP_TLV_AT_EXT
:
466 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
467 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)) {
468 ND_PRINT(" (too short, < %u)",
469 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)));
473 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
474 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
475 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
477 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
481 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
482 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2]));
484 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
485 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
486 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
487 tok2str(eigrp_ext_proto_id_values
,"unknown",EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
488 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
489 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
490 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->metric
));
492 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
493 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
494 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
495 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
496 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
497 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
498 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->load
));
502 * FIXME those are the defined TLVs that lack a decoder
503 * you are welcome to contribute code ;-)
508 case EIGRP_TLV_MCAST_SEQ
:
509 case EIGRP_TLV_IPX_INT
:
510 case EIGRP_TLV_IPX_EXT
:
513 if (ndo
->ndo_vflag
<= 1)
514 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
517 /* do we want to see an additionally hexdump ? */
518 if (ndo
->ndo_vflag
> 1)
519 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
520 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));
527 ND_PRINT("%s", tstr
);