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"
39 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" },
74 struct eigrp_tlv_header
{
79 #define EIGRP_TLV_GENERAL_PARM 0x0001
80 #define EIGRP_TLV_AUTH 0x0002
81 #define EIGRP_TLV_SEQ 0x0003
82 #define EIGRP_TLV_SW_VERSION 0x0004
83 #define EIGRP_TLV_MCAST_SEQ 0x0005
84 #define EIGRP_TLV_IP_INT 0x0102
85 #define EIGRP_TLV_IP_EXT 0x0103
86 #define EIGRP_TLV_AT_INT 0x0202
87 #define EIGRP_TLV_AT_EXT 0x0203
88 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
89 #define EIGRP_TLV_IPX_INT 0x0302
90 #define EIGRP_TLV_IPX_EXT 0x0303
92 static const struct tok eigrp_tlv_values
[] = {
93 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
94 { EIGRP_TLV_AUTH
, "Authentication"},
95 { EIGRP_TLV_SEQ
, "Sequence"},
96 { EIGRP_TLV_SW_VERSION
, "Software Version"},
97 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
98 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
99 { EIGRP_TLV_IP_EXT
, "IP External routes"},
100 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
101 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
102 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
103 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
104 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
108 struct eigrp_tlv_general_parm_t
{
115 nd_uint16_t holdtime
;
118 struct eigrp_tlv_sw_version_t
{
119 nd_uint8_t ios_major
;
120 nd_uint8_t ios_minor
;
121 nd_uint8_t eigrp_major
;
122 nd_uint8_t eigrp_minor
;
125 struct eigrp_tlv_ip_int_t
{
128 nd_uint32_t bandwidth
;
131 nd_uint8_t reliability
;
135 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
138 struct eigrp_tlv_ip_ext_t
{
140 nd_ipv4 origin_router
;
141 nd_uint32_t origin_as
;
148 nd_uint32_t bandwidth
;
151 nd_uint8_t reliability
;
153 nd_byte reserved2
[2];
155 nd_uint8_t destination
; /* variable length [1-4] bytes encoding */
158 struct eigrp_tlv_at_cable_setup_t
{
159 nd_uint16_t cable_start
;
160 nd_uint16_t cable_end
;
161 nd_uint32_t router_id
;
164 struct eigrp_tlv_at_int_t
{
167 nd_uint32_t bandwidth
;
170 nd_uint8_t reliability
;
173 nd_uint16_t cable_start
;
174 nd_uint16_t cable_end
;
177 struct eigrp_tlv_at_ext_t
{
179 nd_uint32_t origin_router
;
180 nd_uint32_t origin_as
;
186 nd_uint32_t bandwidth
;
189 nd_uint8_t reliability
;
191 nd_byte reserved2
[2];
192 nd_uint16_t cable_start
;
193 nd_uint16_t cable_end
;
196 static const struct tok eigrp_ext_proto_id_values
[] = {
207 { 0x0b, "Connected" },
212 eigrp_print(netdissect_options
*ndo
, const u_char
*pptr
, u_int len
)
214 const struct eigrp_common_header
*eigrp_com_header
;
215 const struct eigrp_tlv_header
*eigrp_tlv_header
;
216 const u_char
*tptr
,*tlv_tptr
;
217 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
221 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
222 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
223 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
224 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
225 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
226 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
227 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
230 ndo
->ndo_protocol
= "eigrp";
232 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
233 ND_TCHECK_SIZE(eigrp_com_header
);
236 * Sanity checking of the header.
238 if (EXTRACT_U_1(eigrp_com_header
->version
) != EIGRP_VERSION
) {
239 ND_PRINT("EIGRP version %u packet not supported",EXTRACT_U_1(eigrp_com_header
->version
));
243 /* in non-verbose mode just lets print the basic Message Type*/
244 if (ndo
->ndo_vflag
< 1) {
245 ND_PRINT("EIGRP %s, length: %u",
246 tok2str(eigrp_opcode_values
, "unknown (%u)",EXTRACT_U_1(eigrp_com_header
->opcode
)),
251 /* ok they seem to want to know everything - lets fully decode it */
253 if (len
< sizeof(struct eigrp_common_header
)) {
254 ND_PRINT("EIGRP %s, length: %u (too short, < %u)",
255 tok2str(eigrp_opcode_values
, "unknown (%u)",EXTRACT_U_1(eigrp_com_header
->opcode
)),
256 len
, (u_int
) sizeof(struct eigrp_common_header
));
259 tlen
=len
-sizeof(struct eigrp_common_header
);
261 /* FIXME print other header info */
262 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",
263 EXTRACT_U_1(eigrp_com_header
->version
),
264 tok2str(eigrp_opcode_values
, "unknown, type: %u",EXTRACT_U_1(eigrp_com_header
->opcode
)),
265 EXTRACT_U_1(eigrp_com_header
->opcode
),
266 EXTRACT_BE_U_2(eigrp_com_header
->checksum
),
267 tok2str(eigrp_common_header_flag_values
,
269 EXTRACT_BE_U_4(eigrp_com_header
->flags
)),
270 EXTRACT_BE_U_4(eigrp_com_header
->seq
),
271 EXTRACT_BE_U_4(eigrp_com_header
->ack
),
272 EXTRACT_BE_U_4(eigrp_com_header
->asn
),
275 tptr
+=sizeof(struct eigrp_common_header
);
278 /* did we capture enough for fully decoding the object header ? */
279 ND_TCHECK_LEN(tptr
, sizeof(struct eigrp_tlv_header
));
281 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
282 eigrp_tlv_len
=EXTRACT_BE_U_2(eigrp_tlv_header
->length
);
283 eigrp_tlv_type
=EXTRACT_BE_U_2(eigrp_tlv_header
->type
);
286 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
287 eigrp_tlv_len
> tlen
) {
288 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
292 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
293 tok2str(eigrp_tlv_values
,
299 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
)) {
300 ND_PRINT(" (too short, < %u)",
301 (u_int
) sizeof(struct eigrp_tlv_header
));
304 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
305 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
307 /* did we capture enough for fully decoding the object ? */
308 ND_TCHECK_LEN(tptr
, eigrp_tlv_len
);
310 switch(eigrp_tlv_type
) {
312 case EIGRP_TLV_GENERAL_PARM
:
313 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
314 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)) {
315 ND_PRINT(" (too short, < %u)",
316 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_general_parm
)));
320 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
321 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
322 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k1
),
323 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k2
),
324 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k3
),
325 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k4
),
326 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_general_parm
->k5
));
329 case EIGRP_TLV_SW_VERSION
:
330 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
331 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)) {
332 ND_PRINT(" (too short, < %u)",
333 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_sw_version
)));
337 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
338 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_major
),
339 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
),
340 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
),
341 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
344 case EIGRP_TLV_IP_INT
:
345 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
346 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)) {
347 ND_PRINT(" (too short, < %u)",
348 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_int
)));
352 bit_length
= EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->plen
);
353 if (bit_length
> 32) {
354 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
357 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
358 memset(prefix
, 0, 4);
359 memcpy(prefix
, tlv_ptr
.eigrp_tlv_ip_int
->destination
, byte_length
);
361 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
362 ipaddr_string(ndo
, prefix
),
364 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
368 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_int
->nexthop
));
370 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
371 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
372 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
373 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
374 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->hopcount
),
375 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->reliability
),
376 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_int
->load
));
379 case EIGRP_TLV_IP_EXT
:
380 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
381 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)) {
382 ND_PRINT(" (too short, < %u)",
383 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_ip_ext
)));
387 bit_length
= EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->plen
);
388 if (bit_length
> 32) {
389 ND_PRINT("\n\t illegal prefix length %u",bit_length
);
392 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
393 memset(prefix
, 0, 4);
394 memcpy(prefix
, tlv_ptr
.eigrp_tlv_ip_ext
->destination
, byte_length
);
396 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
397 ipaddr_string(ndo
, prefix
),
399 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
403 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
));
405 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
406 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
407 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
408 tok2str(eigrp_ext_proto_id_values
,"unknown",EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
)),
409 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->flags
),
410 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
411 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->metric
));
413 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
414 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
415 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
416 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
417 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
),
418 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->reliability
),
419 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_ip_ext
->load
));
422 case EIGRP_TLV_AT_CABLE_SETUP
:
423 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
424 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)) {
425 ND_PRINT(" (too short, < %u)",
426 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_cable_setup
)));
430 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
431 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
432 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
433 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
));
436 case EIGRP_TLV_AT_INT
:
437 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
438 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_int
)) {
439 ND_PRINT(" (too short, < %u)",
440 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_int
)));
444 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
445 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
446 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_int
->cable_end
));
448 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
452 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[0]),
453 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2]));
455 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
456 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
457 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
458 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_at_int
->mtu
),
459 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->hopcount
),
460 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->reliability
),
461 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_int
->load
));
464 case EIGRP_TLV_AT_EXT
:
465 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
466 if (tlv_tlen
< sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)) {
467 ND_PRINT(" (too short, < %u)",
468 (u_int
) (sizeof(struct eigrp_tlv_header
) + sizeof(*tlv_ptr
.eigrp_tlv_at_ext
)));
472 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
473 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
474 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->cable_end
));
476 if (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
480 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[0]),
481 EXTRACT_BE_U_2(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2]));
483 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
484 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
485 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
486 tok2str(eigrp_ext_proto_id_values
,"unknown",EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->proto_id
)),
487 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->flags
),
488 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
489 EXTRACT_BE_U_2(tlv_ptr
.eigrp_tlv_at_ext
->metric
));
491 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
492 (EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
493 EXTRACT_BE_U_4(tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
494 EXTRACT_BE_U_3(tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
495 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->hopcount
),
496 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->reliability
),
497 EXTRACT_U_1(tlv_ptr
.eigrp_tlv_at_ext
->load
));
501 * FIXME those are the defined TLVs that lack a decoder
502 * you are welcome to contribute code ;-)
507 case EIGRP_TLV_MCAST_SEQ
:
508 case EIGRP_TLV_IPX_INT
:
509 case EIGRP_TLV_IPX_EXT
:
512 if (ndo
->ndo_vflag
<= 1)
513 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
516 /* do we want to see an additionally hexdump ? */
517 if (ndo
->ndo_vflag
> 1)
518 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
519 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));