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 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" },
73 struct eigrp_tlv_header
{
78 #define EIGRP_TLV_GENERAL_PARM 0x0001
79 #define EIGRP_TLV_AUTH 0x0002
80 #define EIGRP_TLV_SEQ 0x0003
81 #define EIGRP_TLV_SW_VERSION 0x0004
82 #define EIGRP_TLV_MCAST_SEQ 0x0005
83 #define EIGRP_TLV_IP_INT 0x0102
84 #define EIGRP_TLV_IP_EXT 0x0103
85 #define EIGRP_TLV_AT_INT 0x0202
86 #define EIGRP_TLV_AT_EXT 0x0203
87 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
88 #define EIGRP_TLV_IPX_INT 0x0302
89 #define EIGRP_TLV_IPX_EXT 0x0303
91 static const struct tok eigrp_tlv_values
[] = {
92 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
93 { EIGRP_TLV_AUTH
, "Authentication"},
94 { EIGRP_TLV_SEQ
, "Sequence"},
95 { EIGRP_TLV_SW_VERSION
, "Software Version"},
96 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
97 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
98 { EIGRP_TLV_IP_EXT
, "IP External routes"},
99 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
100 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
101 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
102 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
103 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
107 struct eigrp_tlv_general_parm_t
{
114 nd_uint16_t holdtime
;
117 struct eigrp_tlv_sw_version_t
{
118 nd_uint8_t ios_major
;
119 nd_uint8_t ios_minor
;
120 nd_uint8_t eigrp_major
;
121 nd_uint8_t eigrp_minor
;
124 struct eigrp_tlv_ip_int_t
{
127 nd_uint32_t bandwidth
;
130 nd_uint8_t reliability
;
134 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
137 struct eigrp_tlv_ip_ext_t
{
139 nd_ipv4 origin_router
;
140 nd_uint32_t origin_as
;
147 nd_uint32_t bandwidth
;
150 nd_uint8_t reliability
;
152 nd_byte reserved2
[2];
154 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
157 struct eigrp_tlv_at_cable_setup_t
{
158 nd_uint16_t cable_start
;
159 nd_uint16_t cable_end
;
160 nd_uint32_t router_id
;
163 struct eigrp_tlv_at_int_t
{
166 nd_uint32_t bandwidth
;
169 nd_uint8_t reliability
;
172 nd_uint16_t cable_start
;
173 nd_uint16_t cable_end
;
176 struct eigrp_tlv_at_ext_t
{
178 nd_uint32_t origin_router
;
179 nd_uint32_t origin_as
;
185 nd_uint32_t bandwidth
;
188 nd_uint8_t reliability
;
190 nd_byte reserved2
[2];
191 nd_uint16_t cable_start
;
192 nd_uint16_t cable_end
;
195 static const struct tok eigrp_ext_proto_id_values
[] = {
206 { 0x0b, "Connected" },
211 eigrp_print(netdissect_options
*ndo
, const u_char
*pptr
, u_int len
)
213 const struct eigrp_common_header
*eigrp_com_header
;
214 const struct eigrp_tlv_header
*eigrp_tlv_header
;
215 const u_char
*tptr
,*tlv_tptr
;
216 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
220 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
221 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
222 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
223 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
224 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
225 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
226 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
230 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
231 ND_TCHECK_SIZE(eigrp_com_header
);
234 * Sanity checking of the header.
236 if (EXTRACT_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
237 ND_PRINT("EIGRP version %u packet not supported",EXTRACT_U_1(eigrp_com_header
->version
));
241 /* in non-verbose mode just lets print the basic Message Type*/
242 if (ndo
->ndo_vflag
< 1) {
243 ND_PRINT("EIGRP %s, length: %u",
244 tok2str(eigrp_opcode_values
, "unknown (%u)",EXTRACT_U_1(eigrp_com_header
->opcode
)),
249 /* ok they seem to want to know everything - lets fully decode it */
251 if (len
< sizeof(struct eigrp_common_header
)) {
252 ND_PRINT("EIGRP %s, length: %u (too short, < %u)",
253 tok2str(eigrp_opcode_values
, "unknown (%u)",EXTRACT_U_1(eigrp_com_header
->opcode
)),
254 len
, (u_int
) sizeof(struct eigrp_common_header
));
257 tlen
=len
-sizeof(struct eigrp_common_header
);
259 /* FIXME print other header info */
260 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",
261 EXTRACT_U_1(eigrp_com_header
->version
),
262 tok2str(eigrp_opcode_values
, "unknown, type: %u",EXTRACT_U_1(eigrp_com_header
->opcode
)),
263 EXTRACT_U_1(eigrp_com_header
->opcode
),
264 EXTRACT_BE_U_2(eigrp_com_header
->checksum
),
265 tok2str(eigrp_common_header_flag_values
,
267 EXTRACT_BE_U_4(eigrp_com_header
->flags
)),
268 EXTRACT_BE_U_4(eigrp_com_header
->seq
),
269 EXTRACT_BE_U_4(eigrp_com_header
->ack
),
270 EXTRACT_BE_U_4(eigrp_com_header
->asn
),
273 tptr
+=sizeof(struct eigrp_common_header
);
276 /* did we capture enough for fully decoding the object header ? */
277 ND_TCHECK_LEN(tptr
, sizeof(struct eigrp_tlv_header
));
279 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
280 eigrp_tlv_len
=EXTRACT_BE_U_2(eigrp_tlv_header
->length
);
281 eigrp_tlv_type
=EXTRACT_BE_U_2(eigrp_tlv_header
->type
);
284 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
285 eigrp_tlv_len
> tlen
) {
286 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
290 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
291 tok2str(eigrp_tlv_values
,
297 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
)) {
298 ND_PRINT(" (too short, < %u)",
299 (u_int
) sizeof(struct eigrp_tlv_header
));
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, < %u)",
314 (u_int
) (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 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
320 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
321 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
322 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
323 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
324 EXTRACT_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, < %u)",
331 (u_int
) (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 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
337 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
338 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
339 EXTRACT_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, < %u)",
346 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)));
350 bit_length
= EXTRACT_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 memcpy(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
),
362 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
366 ipaddr_string(ndo
, 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 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
370 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
371 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
372 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
373 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
374 EXTRACT_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, < %u)",
381 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)));
385 bit_length
= EXTRACT_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 memcpy(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
),
397 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
401 ipaddr_string(ndo
, 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 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
405 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
406 tok2str(eigrp_ext_proto_id_values
,"unknown",EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
407 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
408 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
409 EXTRACT_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 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
413 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
414 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
415 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
416 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
417 EXTRACT_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, < %u)",
424 (u_int
) (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 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
430 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
431 EXTRACT_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, < %u)",
438 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
)));
442 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
443 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
444 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
446 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
450 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
451 EXTRACT_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 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
455 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
456 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
457 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
458 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
459 EXTRACT_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, < %u)",
466 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)));
470 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
471 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
472 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
474 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
478 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
479 EXTRACT_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 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
483 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
484 tok2str(eigrp_ext_proto_id_values
,"unknown",EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
485 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
486 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
487 EXTRACT_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 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
491 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
492 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
493 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
494 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
495 EXTRACT_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("\n\t\t packet exceeded snapshot");