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.
21 #include <netdissect-stdinc.h>
25 #include "netdissect.h"
27 #include "addrtoname.h"
30 * packet format documented at
31 * http://www.rhyshaden.com/eigrp.htm
34 struct eigrp_common_header
{
44 #define EIGRP_VERSION 2
46 #define EIGRP_OPCODE_UPDATE 1
47 #define EIGRP_OPCODE_QUERY 3
48 #define EIGRP_OPCODE_REPLY 4
49 #define EIGRP_OPCODE_HELLO 5
50 #define EIGRP_OPCODE_IPXSAP 6
51 #define EIGRP_OPCODE_PROBE 7
53 static const struct tok eigrp_opcode_values
[] = {
54 { EIGRP_OPCODE_UPDATE
, "Update" },
55 { EIGRP_OPCODE_QUERY
, "Query" },
56 { EIGRP_OPCODE_REPLY
, "Reply" },
57 { EIGRP_OPCODE_HELLO
, "Hello" },
58 { EIGRP_OPCODE_IPXSAP
, "IPX SAP" },
59 { EIGRP_OPCODE_PROBE
, "Probe" },
63 static const struct tok eigrp_common_header_flag_values
[] = {
65 { 0x02, "Conditionally Received" },
69 struct eigrp_tlv_header
{
74 #define EIGRP_TLV_GENERAL_PARM 0x0001
75 #define EIGRP_TLV_AUTH 0x0002
76 #define EIGRP_TLV_SEQ 0x0003
77 #define EIGRP_TLV_SW_VERSION 0x0004
78 #define EIGRP_TLV_MCAST_SEQ 0x0005
79 #define EIGRP_TLV_IP_INT 0x0102
80 #define EIGRP_TLV_IP_EXT 0x0103
81 #define EIGRP_TLV_AT_INT 0x0202
82 #define EIGRP_TLV_AT_EXT 0x0203
83 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
84 #define EIGRP_TLV_IPX_INT 0x0302
85 #define EIGRP_TLV_IPX_EXT 0x0303
87 static const struct tok eigrp_tlv_values
[] = {
88 { EIGRP_TLV_GENERAL_PARM
, "General Parameters"},
89 { EIGRP_TLV_AUTH
, "Authentication"},
90 { EIGRP_TLV_SEQ
, "Sequence"},
91 { EIGRP_TLV_SW_VERSION
, "Software Version"},
92 { EIGRP_TLV_MCAST_SEQ
, "Next Multicast Sequence"},
93 { EIGRP_TLV_IP_INT
, "IP Internal routes"},
94 { EIGRP_TLV_IP_EXT
, "IP External routes"},
95 { EIGRP_TLV_AT_INT
, "AppleTalk Internal routes"},
96 { EIGRP_TLV_AT_EXT
, "AppleTalk External routes"},
97 { EIGRP_TLV_AT_CABLE_SETUP
, "AppleTalk Cable setup"},
98 { EIGRP_TLV_IPX_INT
, "IPX Internal routes"},
99 { EIGRP_TLV_IPX_EXT
, "IPX External routes"},
103 struct eigrp_tlv_general_parm_t
{
113 struct eigrp_tlv_sw_version_t
{
120 struct eigrp_tlv_ip_int_t
{
123 uint8_t bandwidth
[4];
130 uint8_t destination
; /* variable length [1-4] bytes encoding */
133 struct eigrp_tlv_ip_ext_t
{
135 uint8_t origin_router
[4];
136 uint8_t origin_as
[4];
143 uint8_t bandwidth
[4];
148 uint8_t reserved2
[2];
150 uint8_t destination
; /* variable length [1-4] bytes encoding */
153 struct eigrp_tlv_at_cable_setup_t
{
154 uint8_t cable_start
[2];
155 uint8_t cable_end
[2];
156 uint8_t router_id
[4];
159 struct eigrp_tlv_at_int_t
{
162 uint8_t bandwidth
[4];
168 uint8_t cable_start
[2];
169 uint8_t cable_end
[2];
172 struct eigrp_tlv_at_ext_t
{
174 uint8_t origin_router
[4];
175 uint8_t origin_as
[4];
181 uint8_t bandwidth
[4];
186 uint8_t reserved2
[2];
187 uint8_t cable_start
[2];
188 uint8_t cable_end
[2];
191 static const struct tok eigrp_ext_proto_id_values
[] = {
202 { 0x0b, "Connected" },
207 eigrp_print(netdissect_options
*ndo
, register const u_char
*pptr
, register u_int len
)
209 const struct eigrp_common_header
*eigrp_com_header
;
210 const struct eigrp_tlv_header
*eigrp_tlv_header
;
211 const u_char
*tptr
,*tlv_tptr
;
212 u_int tlen
,eigrp_tlv_len
,eigrp_tlv_type
,tlv_tlen
, byte_length
, bit_length
;
216 const struct eigrp_tlv_general_parm_t
*eigrp_tlv_general_parm
;
217 const struct eigrp_tlv_sw_version_t
*eigrp_tlv_sw_version
;
218 const struct eigrp_tlv_ip_int_t
*eigrp_tlv_ip_int
;
219 const struct eigrp_tlv_ip_ext_t
*eigrp_tlv_ip_ext
;
220 const struct eigrp_tlv_at_cable_setup_t
*eigrp_tlv_at_cable_setup
;
221 const struct eigrp_tlv_at_int_t
*eigrp_tlv_at_int
;
222 const struct eigrp_tlv_at_ext_t
*eigrp_tlv_at_ext
;
226 eigrp_com_header
= (const struct eigrp_common_header
*)pptr
;
227 ND_TCHECK(*eigrp_com_header
);
230 * Sanity checking of the header.
232 if (eigrp_com_header
->version
!= EIGRP_VERSION
) {
233 ND_PRINT((ndo
, "EIGRP version %u packet not supported",eigrp_com_header
->version
));
237 /* in non-verbose mode just lets print the basic Message Type*/
238 if (ndo
->ndo_vflag
< 1) {
239 ND_PRINT((ndo
, "EIGRP %s, length: %u",
240 tok2str(eigrp_opcode_values
, "unknown (%u)",eigrp_com_header
->opcode
),
245 /* ok they seem to want to know everything - lets fully decode it */
247 tlen
=len
-sizeof(struct eigrp_common_header
);
249 /* FIXME print other header info */
250 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",
251 eigrp_com_header
->version
,
252 tok2str(eigrp_opcode_values
, "unknown, type: %u",eigrp_com_header
->opcode
),
253 eigrp_com_header
->opcode
,
254 EXTRACT_16BITS(&eigrp_com_header
->checksum
),
255 tok2str(eigrp_common_header_flag_values
,
257 EXTRACT_32BITS(&eigrp_com_header
->flags
)),
258 EXTRACT_32BITS(&eigrp_com_header
->seq
),
259 EXTRACT_32BITS(&eigrp_com_header
->ack
),
260 EXTRACT_32BITS(&eigrp_com_header
->asn
),
263 tptr
+=sizeof(const struct eigrp_common_header
);
266 /* did we capture enough for fully decoding the object header ? */
267 ND_TCHECK2(*tptr
, sizeof(struct eigrp_tlv_header
));
269 eigrp_tlv_header
= (const struct eigrp_tlv_header
*)tptr
;
270 eigrp_tlv_len
=EXTRACT_16BITS(&eigrp_tlv_header
->length
);
271 eigrp_tlv_type
=EXTRACT_16BITS(&eigrp_tlv_header
->type
);
274 if (eigrp_tlv_len
< sizeof(struct eigrp_tlv_header
) ||
275 eigrp_tlv_len
> tlen
) {
276 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",tlen
);
280 ND_PRINT((ndo
, "\n\t %s TLV (0x%04x), length: %u",
281 tok2str(eigrp_tlv_values
,
287 tlv_tptr
=tptr
+sizeof(struct eigrp_tlv_header
);
288 tlv_tlen
=eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
);
290 /* did we capture enough for fully decoding the object ? */
291 ND_TCHECK2(*tptr
, eigrp_tlv_len
);
293 switch(eigrp_tlv_type
) {
295 case EIGRP_TLV_GENERAL_PARM
:
296 tlv_ptr
.eigrp_tlv_general_parm
= (const struct eigrp_tlv_general_parm_t
*)tlv_tptr
;
298 ND_PRINT((ndo
, "\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
299 EXTRACT_16BITS(tlv_ptr
.eigrp_tlv_general_parm
->holdtime
),
300 tlv_ptr
.eigrp_tlv_general_parm
->k1
,
301 tlv_ptr
.eigrp_tlv_general_parm
->k2
,
302 tlv_ptr
.eigrp_tlv_general_parm
->k3
,
303 tlv_ptr
.eigrp_tlv_general_parm
->k4
,
304 tlv_ptr
.eigrp_tlv_general_parm
->k5
));
307 case EIGRP_TLV_SW_VERSION
:
308 tlv_ptr
.eigrp_tlv_sw_version
= (const struct eigrp_tlv_sw_version_t
*)tlv_tptr
;
310 ND_PRINT((ndo
, "\n\t IOS version: %u.%u, EIGRP version %u.%u",
311 tlv_ptr
.eigrp_tlv_sw_version
->ios_major
,
312 tlv_ptr
.eigrp_tlv_sw_version
->ios_minor
,
313 tlv_ptr
.eigrp_tlv_sw_version
->eigrp_major
,
314 tlv_ptr
.eigrp_tlv_sw_version
->eigrp_minor
));
317 case EIGRP_TLV_IP_INT
:
318 tlv_ptr
.eigrp_tlv_ip_int
= (const struct eigrp_tlv_ip_int_t
*)tlv_tptr
;
320 bit_length
= tlv_ptr
.eigrp_tlv_ip_int
->plen
;
321 if (bit_length
> 32) {
322 ND_PRINT((ndo
, "\n\t illegal prefix length %u",bit_length
));
325 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
326 memset(prefix
, 0, 4);
327 memcpy(prefix
,&tlv_ptr
.eigrp_tlv_ip_int
->destination
,byte_length
);
329 ND_PRINT((ndo
, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
330 ipaddr_string(ndo
, prefix
),
332 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_int
->nexthop
) == 0)
333 ND_PRINT((ndo
, "self"));
335 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, &tlv_ptr
.eigrp_tlv_ip_int
->nexthop
)));
337 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
338 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_int
->delay
)/100),
339 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_int
->bandwidth
),
340 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_ip_int
->mtu
),
341 tlv_ptr
.eigrp_tlv_ip_int
->hopcount
,
342 tlv_ptr
.eigrp_tlv_ip_int
->reliability
,
343 tlv_ptr
.eigrp_tlv_ip_int
->load
));
346 case EIGRP_TLV_IP_EXT
:
347 tlv_ptr
.eigrp_tlv_ip_ext
= (const struct eigrp_tlv_ip_ext_t
*)tlv_tptr
;
349 bit_length
= tlv_ptr
.eigrp_tlv_ip_ext
->plen
;
350 if (bit_length
> 32) {
351 ND_PRINT((ndo
, "\n\t illegal prefix length %u",bit_length
));
354 byte_length
= (bit_length
+ 7) / 8; /* variable length encoding */
355 memset(prefix
, 0, 4);
356 memcpy(prefix
,&tlv_ptr
.eigrp_tlv_ip_ext
->destination
,byte_length
);
358 ND_PRINT((ndo
, "\n\t IPv4 prefix: %15s/%u, nexthop: ",
359 ipaddr_string(ndo
, prefix
),
361 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
) == 0)
362 ND_PRINT((ndo
, "self"));
364 ND_PRINT((ndo
, "%s",ipaddr_string(ndo
, &tlv_ptr
.eigrp_tlv_ip_ext
->nexthop
)));
366 ND_PRINT((ndo
, "\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
367 ipaddr_string(ndo
, tlv_ptr
.eigrp_tlv_ip_ext
->origin_router
),
368 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_ip_ext
->origin_as
),
369 tok2str(eigrp_ext_proto_id_values
,"unknown",tlv_ptr
.eigrp_tlv_ip_ext
->proto_id
),
370 tlv_ptr
.eigrp_tlv_ip_ext
->flags
,
371 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_ip_ext
->tag
),
372 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_ip_ext
->metric
)));
374 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
375 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->delay
)/100),
376 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->bandwidth
),
377 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_ip_ext
->mtu
),
378 tlv_ptr
.eigrp_tlv_ip_ext
->hopcount
,
379 tlv_ptr
.eigrp_tlv_ip_ext
->reliability
,
380 tlv_ptr
.eigrp_tlv_ip_ext
->load
));
383 case EIGRP_TLV_AT_CABLE_SETUP
:
384 tlv_ptr
.eigrp_tlv_at_cable_setup
= (const struct eigrp_tlv_at_cable_setup_t
*)tlv_tptr
;
386 ND_PRINT((ndo
, "\n\t Cable-range: %u-%u, Router-ID %u",
387 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_start
),
388 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_cable_setup
->cable_end
),
389 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_cable_setup
->router_id
)));
392 case EIGRP_TLV_AT_INT
:
393 tlv_ptr
.eigrp_tlv_at_int
= (const struct eigrp_tlv_at_int_t
*)tlv_tptr
;
395 ND_PRINT((ndo
, "\n\t Cable-Range: %u-%u, nexthop: ",
396 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->cable_start
),
397 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->cable_end
)));
399 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
) == 0)
400 ND_PRINT((ndo
, "self"));
402 ND_PRINT((ndo
, "%u.%u",
403 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
),
404 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_int
->nexthop
[2])));
406 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
407 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_int
->delay
)/100),
408 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_int
->bandwidth
),
409 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_at_int
->mtu
),
410 tlv_ptr
.eigrp_tlv_at_int
->hopcount
,
411 tlv_ptr
.eigrp_tlv_at_int
->reliability
,
412 tlv_ptr
.eigrp_tlv_at_int
->load
));
415 case EIGRP_TLV_AT_EXT
:
416 tlv_ptr
.eigrp_tlv_at_ext
= (const struct eigrp_tlv_at_ext_t
*)tlv_tptr
;
418 ND_PRINT((ndo
, "\n\t Cable-Range: %u-%u, nexthop: ",
419 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->cable_start
),
420 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->cable_end
)));
422 if (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
) == 0)
423 ND_PRINT((ndo
, "self"));
425 ND_PRINT((ndo
, "%u.%u",
426 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
),
427 EXTRACT_16BITS(&tlv_ptr
.eigrp_tlv_at_ext
->nexthop
[2])));
429 ND_PRINT((ndo
, "\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
430 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_at_ext
->origin_router
),
431 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_at_ext
->origin_as
),
432 tok2str(eigrp_ext_proto_id_values
,"unknown",tlv_ptr
.eigrp_tlv_at_ext
->proto_id
),
433 tlv_ptr
.eigrp_tlv_at_ext
->flags
,
434 EXTRACT_32BITS(tlv_ptr
.eigrp_tlv_at_ext
->tag
),
435 EXTRACT_16BITS(tlv_ptr
.eigrp_tlv_at_ext
->metric
)));
437 ND_PRINT((ndo
, "\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
438 (EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_ext
->delay
)/100),
439 EXTRACT_32BITS(&tlv_ptr
.eigrp_tlv_at_ext
->bandwidth
),
440 EXTRACT_24BITS(&tlv_ptr
.eigrp_tlv_at_ext
->mtu
),
441 tlv_ptr
.eigrp_tlv_at_ext
->hopcount
,
442 tlv_ptr
.eigrp_tlv_at_ext
->reliability
,
443 tlv_ptr
.eigrp_tlv_at_ext
->load
));
447 * FIXME those are the defined TLVs that lack a decoder
448 * you are welcome to contribute code ;-)
453 case EIGRP_TLV_MCAST_SEQ
:
454 case EIGRP_TLV_IPX_INT
:
455 case EIGRP_TLV_IPX_EXT
:
458 if (ndo
->ndo_vflag
<= 1)
459 print_unknown_data(ndo
,tlv_tptr
,"\n\t ",tlv_tlen
);
462 /* do we want to see an additionally hexdump ? */
463 if (ndo
->ndo_vflag
> 1)
464 print_unknown_data(ndo
,tptr
+sizeof(struct eigrp_tlv_header
),"\n\t ",
465 eigrp_tlv_len
-sizeof(struct eigrp_tlv_header
));
472 ND_PRINT((ndo
, "\n\t\t packet exceeded snapshot"));