2 * Copyright (c) 1998-2004 Hannes Gredler <hannes@tcpdump.org>
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 #include <sys/cdefs.h>
19 __RCSID("$NetBSD: print-eigrp.c,v 1.6 2015/03/31 21:59:35 christos Exp $");
22 #define NETDISSECT_REWORKED
27 #include <tcpdump-stdinc.h>
31 #include "interface.h"
33 #include "addrtoname.h"
36 * packet format documented at
37 * http://www.rhyshaden.com/eigrp.htm
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
{
119 struct eigrp_tlv_sw_version_t
{
126 struct eigrp_tlv_ip_int_t
{
129 uint8_t bandwidth
[4];
136 uint8_t destination
; /* variable length [1-4] bytes encoding */
139 struct eigrp_tlv_ip_ext_t
{
141 uint8_t origin_router
[4];
142 uint8_t origin_as
[4];
149 uint8_t bandwidth
[4];
154 uint8_t reserved2
[2];
156 uint8_t destination
; /* variable length [1-4] bytes encoding */
159 struct eigrp_tlv_at_cable_setup_t
{
160 uint8_t cable_start
[2];
161 uint8_t cable_end
[2];
162 uint8_t router_id
[4];
165 struct eigrp_tlv_at_int_t
{
168 uint8_t bandwidth
[4];
174 uint8_t cable_start
[2];
175 uint8_t cable_end
[2];
178 struct eigrp_tlv_at_ext_t
{
180 uint8_t origin_router
[4];
181 uint8_t origin_as
[4];
187 uint8_t bandwidth
[4];
192 uint8_t reserved2
[2];
193 uint8_t cable_start
[2];
194 uint8_t cable_end
[2];
197 static const struct tok eigrp_ext_proto_id_values
[] = {
208 { 0x0b, "Connected" },
213 eigrp_print(netdissect_options
*ndo
, register const u_char
*pptr
, register 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
;
232 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
233 ND_TCHECK(*eigrp_com_header
);
236 * Sanity checking of the header.
238 if (eigrp_com_header
->version
!= EIGRP_VERSION
) {
239 ND_PRINT((ndo
, "EIGRP version %u packet not supported",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((ndo
, "EIGRP %s, length: %u",
246 tok2str(eigrp_opcode_values
, "unknown (%u)",eigrp_com_header
->opcode
),
251 /* ok they seem to want to know everything - lets fully decode it */
253 tlen
=len
-sizeof(struct eigrp_common_header
);
255 /* FIXME print other header info */
256 ND_PRINT((ndo
, "\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
257 eigrp_com_header
->version
,
258 tok2str(eigrp_opcode_values
, "unknown, type: %u",eigrp_com_header
->opcode
),
259 eigrp_com_header
->opcode
,
260 EXTRACT_16BITS(&eigrp_com_header
->checksum
),
261 tok2str(eigrp_common_header_flag_values
,
263 EXTRACT_32BITS(&eigrp_com_header
->flags
)),
264 EXTRACT_32BITS(&eigrp_com_header
->seq
),
265 EXTRACT_32BITS(&eigrp_com_header
->ack
),
266 EXTRACT_32BITS(&eigrp_com_header
->asn
),
269 tptr
+=sizeof(const struct eigrp_common_header
);
272 /* did we capture enough for fully decoding the object header ? */
273 ND_TCHECK2(*tptr
, sizeof(struct eigrp_tlv_header
));
275 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
276 eigrp_tlv_len
=EXTRACT_16BITS(&eigrp_tlv_header
->length
);
277 eigrp_tlv_type
=EXTRACT_16BITS(&eigrp_tlv_header
->type
);
280 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
281 eigrp_tlv_len
> tlen
) {
282 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
286 ND_PRINT((ndo
, "\n\t %s TLV (0x%04x), length: %u",
287 tok2str(eigrp_tlv_values
,
293 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
294 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
296 /* did we capture enough for fully decoding the object ? */
297 ND_TCHECK2(*tptr
, eigrp_tlv_len
);
299 switch(eigrp_tlv_type
) {
301 case EIGRP_TLV_GENERAL_PARM
:
302 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
304 ND_PRINT((ndo
, "\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
305 EXTRACT_16BITS(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
306 tlv_ptr
.eigrp_tlv_general_parm
->k1
,
307 tlv_ptr
.eigrp_tlv_general_parm
->k2
,
308 tlv_ptr
.eigrp_tlv_general_parm
->k3
,
309 tlv_ptr
.eigrp_tlv_general_parm
->k4
,
310 tlv_ptr
.eigrp_tlv_general_parm
->k5
));
313 case EIGRP_TLV_SW_VERSION
:
314 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
316 ND_PRINT((ndo
, "\n\t IOS version: %u.%u, EIGRP version %u.%u",
317 tlv_ptr
.eigrp_tlv_sw_version
->ios_major
,
318 tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
,
319 tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
,
320 tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
323 case EIGRP_TLV_IP_INT
:
324 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
326 bit_length
= tlv_ptr
.eigrp_tlv_ip_int
->plen
;
327 if (bit_length
> 32) {
328 ND_PRINT((ndo
, "\n\t illegal prefix length %u",bit_length
));
331 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
332 memset(prefix
, 0, 4);
333 memcpy(prefix
,&tlv_ptr
.eigrp_tlv_ip_int
->destination
,byte_length
);
335 ND_PRINT((ndo
, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
336 ipaddr_string(ndo
, prefix
),
338 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
339 ND_PRINT((ndo
, "self"));
341 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, &tlv_ptr
.eigrp_tlv_ip_int
->nexthop
)));
343 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
344 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
345 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
346 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
347 tlv_ptr
.eigrp_tlv_ip_int
->hopcount
,
348 tlv_ptr
.eigrp_tlv_ip_int
->reliability
,
349 tlv_ptr
.eigrp_tlv_ip_int
->load
));
352 case EIGRP_TLV_IP_EXT
:
353 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
355 bit_length
= tlv_ptr
.eigrp_tlv_ip_ext
->plen
;
356 if (bit_length
> 32) {
357 ND_PRINT((ndo
, "\n\t illegal prefix length %u",bit_length
));
360 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
361 memset(prefix
, 0, 4);
362 memcpy(prefix
,&tlv_ptr
.eigrp_tlv_ip_ext
->destination
,byte_length
);
364 ND_PRINT((ndo
, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
365 ipaddr_string(ndo
, prefix
),
367 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
368 ND_PRINT((ndo
, "self"));
370 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, &tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
)));
372 ND_PRINT((ndo
, "\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
373 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
374 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
375 tok2str(eigrp_ext_proto_id_values
,"unknown",tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
),
376 tlv_ptr
.eigrp_tlv_ip_ext
->flags
,
377 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
378 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_ip_ext
->metric
)));
380 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
381 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
382 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
383 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
384 tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
,
385 tlv_ptr
.eigrp_tlv_ip_ext
->reliability
,
386 tlv_ptr
.eigrp_tlv_ip_ext
->load
));
389 case EIGRP_TLV_AT_CABLE_SETUP
:
390 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
392 ND_PRINT((ndo
, "\n\t Cable-range: %u-%u, Router-ID %u",
393 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
394 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
395 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
)));
398 case EIGRP_TLV_AT_INT
:
399 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
401 ND_PRINT((ndo
, "\n\t Cable-Range: %u-%u, nexthop: ",
402 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
403 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->cable_end
)));
405 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
406 ND_PRINT((ndo
, "self"));
408 ND_PRINT((ndo
, "%u.%u",
409 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
),
410 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2])));
412 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
413 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
414 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
415 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_at_int
->mtu
),
416 tlv_ptr
.eigrp_tlv_at_int
->hopcount
,
417 tlv_ptr
.eigrp_tlv_at_int
->reliability
,
418 tlv_ptr
.eigrp_tlv_at_int
->load
));
421 case EIGRP_TLV_AT_EXT
:
422 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
424 ND_PRINT((ndo
, "\n\t Cable-Range: %u-%u, nexthop: ",
425 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
426 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->cable_end
)));
428 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
429 ND_PRINT((ndo
, "self"));
431 ND_PRINT((ndo
, "%u.%u",
432 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
),
433 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2])));
435 ND_PRINT((ndo
, "\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
436 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
437 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
438 tok2str(eigrp_ext_proto_id_values
,"unknown",tlv_ptr
.eigrp_tlv_at_ext
->proto_id
),
439 tlv_ptr
.eigrp_tlv_at_ext
->flags
,
440 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
441 EXTRACT_16BITS(tlv_ptr
.eigrp_tlv_at_ext
->metric
)));
443 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
444 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
445 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
446 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
447 tlv_ptr
.eigrp_tlv_at_ext
->hopcount
,
448 tlv_ptr
.eigrp_tlv_at_ext
->reliability
,
449 tlv_ptr
.eigrp_tlv_at_ext
->load
));
453 * FIXME those are the defined TLVs that lack a decoder
454 * you are welcome to contribute code ;-)
459 case EIGRP_TLV_MCAST_SEQ
:
460 case EIGRP_TLV_IPX_INT
:
461 case EIGRP_TLV_IPX_EXT
:
464 if (ndo
->ndo_vflag
<= 1)
465 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
468 /* do we want to see an additionally hexdump ? */
469 if (ndo
->ndo_vflag
> 1)
470 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
471 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));
478 ND_PRINT((ndo
, "\n\t\t packet exceeded snapshot"));