blob: 1bcdf1793e36bf0341152e18c5c1e3ea38d2b754 [file] [log] [blame]
The Android Open Source Project2949f582009-03-03 19:30:46 -08001/*
Elliott Hughescec480a2017-12-19 16:54:57 -08002 * Copyright (c) 1998-2004 Hannes Gredler <hannes@gredler.at>
The Android Open Source Project2949f582009-03-03 19:30:46 -08003 * The TCPDUMP project
4 *
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.
15 */
16
Elliott Hughese2e3bd12017-05-15 10:59:29 -070017/* \summary: Enhanced Interior Gateway Routing Protocol (EIGRP) printer */
18
Elliott Hughes820eced2021-08-20 18:00:50 -070019/*
20 * specification:
21 *
22 * https://web.archive.org/web/20190722221712/https://www.rhyshaden.com/eigrp.htm
23 * RFC 7868
24 */
25
The Android Open Source Project2949f582009-03-03 19:30:46 -080026#ifdef HAVE_CONFIG_H
Elliott Hughes820eced2021-08-20 18:00:50 -070027#include <config.h>
The Android Open Source Project2949f582009-03-03 19:30:46 -080028#endif
29
Elliott Hughes820eced2021-08-20 18:00:50 -070030#include "netdissect-stdinc.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080031
The Android Open Source Project2949f582009-03-03 19:30:46 -080032#include <string.h>
33
Elliott Hughese2e3bd12017-05-15 10:59:29 -070034#include "netdissect.h"
The Android Open Source Project2949f582009-03-03 19:30:46 -080035#include "extract.h"
36#include "addrtoname.h"
37
The Android Open Source Project2949f582009-03-03 19:30:46 -080038
39struct eigrp_common_header {
Elliott Hughes820eced2021-08-20 18:00:50 -070040 nd_uint8_t version;
41 nd_uint8_t opcode;
42 nd_uint16_t checksum;
43 nd_uint32_t flags;
44 nd_uint32_t seq;
45 nd_uint32_t ack;
46 nd_uint16_t vrid;
47 nd_uint16_t asn;
The Android Open Source Project2949f582009-03-03 19:30:46 -080048};
49
50#define EIGRP_VERSION 2
51
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
58
59static 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" },
66 { 0, NULL}
67};
68
69static const struct tok eigrp_common_header_flag_values[] = {
70 { 0x01, "Init" },
71 { 0x02, "Conditionally Received" },
Elliott Hughes820eced2021-08-20 18:00:50 -070072 { 0x04, "Restart" },
73 { 0x08, "End-of-Table" },
The Android Open Source Project2949f582009-03-03 19:30:46 -080074 { 0, NULL}
75};
76
77struct eigrp_tlv_header {
Elliott Hughes820eced2021-08-20 18:00:50 -070078 nd_uint16_t type;
79 nd_uint16_t length;
The Android Open Source Project2949f582009-03-03 19:30:46 -080080};
81
82#define EIGRP_TLV_GENERAL_PARM 0x0001
83#define EIGRP_TLV_AUTH 0x0002
84#define EIGRP_TLV_SEQ 0x0003
85#define EIGRP_TLV_SW_VERSION 0x0004
86#define EIGRP_TLV_MCAST_SEQ 0x0005
87#define EIGRP_TLV_IP_INT 0x0102
88#define EIGRP_TLV_IP_EXT 0x0103
89#define EIGRP_TLV_AT_INT 0x0202
90#define EIGRP_TLV_AT_EXT 0x0203
91#define EIGRP_TLV_AT_CABLE_SETUP 0x0204
92#define EIGRP_TLV_IPX_INT 0x0302
93#define EIGRP_TLV_IPX_EXT 0x0303
94
95static const struct tok eigrp_tlv_values[] = {
96 { EIGRP_TLV_GENERAL_PARM, "General Parameters"},
97 { EIGRP_TLV_AUTH, "Authentication"},
98 { EIGRP_TLV_SEQ, "Sequence"},
99 { EIGRP_TLV_SW_VERSION, "Software Version"},
100 { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"},
101 { EIGRP_TLV_IP_INT, "IP Internal routes"},
102 { EIGRP_TLV_IP_EXT, "IP External routes"},
103 { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"},
104 { EIGRP_TLV_AT_EXT, "AppleTalk External routes"},
105 { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"},
106 { EIGRP_TLV_IPX_INT, "IPX Internal routes"},
107 { EIGRP_TLV_IPX_EXT, "IPX External routes"},
108 { 0, NULL}
109};
110
111struct eigrp_tlv_general_parm_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700112 nd_uint8_t k1;
113 nd_uint8_t k2;
114 nd_uint8_t k3;
115 nd_uint8_t k4;
116 nd_uint8_t k5;
117 nd_uint8_t res;
118 nd_uint16_t holdtime;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700119};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800120
121struct eigrp_tlv_sw_version_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700122 nd_uint8_t ios_major;
123 nd_uint8_t ios_minor;
124 nd_uint8_t eigrp_major;
125 nd_uint8_t eigrp_minor;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700126};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800127
128struct eigrp_tlv_ip_int_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700129 nd_ipv4 nexthop;
130 nd_uint32_t delay;
131 nd_uint32_t bandwidth;
132 nd_uint24_t mtu;
133 nd_uint8_t hopcount;
134 nd_uint8_t reliability;
135 nd_uint8_t load;
136 nd_byte reserved[2];
137 nd_uint8_t plen;
138 nd_uint8_t destination; /* variable length [1-4] bytes encoding */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700139};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800140
141struct eigrp_tlv_ip_ext_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700142 nd_ipv4 nexthop;
143 nd_ipv4 origin_router;
144 nd_uint32_t origin_as;
145 nd_uint32_t tag;
146 nd_uint32_t metric;
147 nd_byte reserved[2];
148 nd_uint8_t proto_id;
149 nd_uint8_t flags;
150 nd_uint32_t delay;
151 nd_uint32_t bandwidth;
152 nd_uint24_t mtu;
153 nd_uint8_t hopcount;
154 nd_uint8_t reliability;
155 nd_uint8_t load;
156 nd_byte reserved2[2];
157 nd_uint8_t plen;
158 nd_uint8_t destination; /* variable length [1-4] bytes encoding */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700159};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800160
161struct eigrp_tlv_at_cable_setup_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700162 nd_uint16_t cable_start;
163 nd_uint16_t cable_end;
164 nd_uint32_t router_id;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800165};
166
167struct eigrp_tlv_at_int_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700168 nd_byte nexthop[4];
169 nd_uint32_t delay;
170 nd_uint32_t bandwidth;
171 nd_uint24_t mtu;
172 nd_uint8_t hopcount;
173 nd_uint8_t reliability;
174 nd_uint8_t load;
175 nd_byte reserved[2];
176 nd_uint16_t cable_start;
177 nd_uint16_t cable_end;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700178};
The Android Open Source Project2949f582009-03-03 19:30:46 -0800179
180struct eigrp_tlv_at_ext_t {
Elliott Hughes820eced2021-08-20 18:00:50 -0700181 nd_byte nexthop[4];
182 nd_uint32_t origin_router;
183 nd_uint32_t origin_as;
184 nd_uint32_t tag;
185 nd_uint8_t proto_id;
186 nd_uint8_t flags;
187 nd_uint16_t metric;
188 nd_uint32_t delay;
189 nd_uint32_t bandwidth;
190 nd_uint24_t mtu;
191 nd_uint8_t hopcount;
192 nd_uint8_t reliability;
193 nd_uint8_t load;
194 nd_byte reserved2[2];
195 nd_uint16_t cable_start;
196 nd_uint16_t cable_end;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800197};
198
199static const struct tok eigrp_ext_proto_id_values[] = {
200 { 0x01, "IGRP" },
201 { 0x02, "EIGRP" },
202 { 0x03, "Static" },
203 { 0x04, "RIP" },
204 { 0x05, "Hello" },
205 { 0x06, "OSPF" },
206 { 0x07, "IS-IS" },
207 { 0x08, "EGP" },
208 { 0x09, "BGP" },
209 { 0x0a, "IDRP" },
210 { 0x0b, "Connected" },
211 { 0, NULL}
212};
213
214void
Elliott Hughes820eced2021-08-20 18:00:50 -0700215eigrp_print(netdissect_options *ndo, const u_char *pptr, u_int len)
Elliott Hughes892a68b2015-10-19 14:43:53 -0700216{
The Android Open Source Project2949f582009-03-03 19:30:46 -0800217 const struct eigrp_common_header *eigrp_com_header;
218 const struct eigrp_tlv_header *eigrp_tlv_header;
219 const u_char *tptr,*tlv_tptr;
220 u_int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen, byte_length, bit_length;
Elliott Hughes892a68b2015-10-19 14:43:53 -0700221 uint8_t prefix[4];
The Android Open Source Project2949f582009-03-03 19:30:46 -0800222
223 union {
224 const struct eigrp_tlv_general_parm_t *eigrp_tlv_general_parm;
225 const struct eigrp_tlv_sw_version_t *eigrp_tlv_sw_version;
226 const struct eigrp_tlv_ip_int_t *eigrp_tlv_ip_int;
227 const struct eigrp_tlv_ip_ext_t *eigrp_tlv_ip_ext;
228 const struct eigrp_tlv_at_cable_setup_t *eigrp_tlv_at_cable_setup;
229 const struct eigrp_tlv_at_int_t *eigrp_tlv_at_int;
230 const struct eigrp_tlv_at_ext_t *eigrp_tlv_at_ext;
231 } tlv_ptr;
232
Elliott Hughes820eced2021-08-20 18:00:50 -0700233 ndo->ndo_protocol = "eigrp";
The Android Open Source Project2949f582009-03-03 19:30:46 -0800234 tptr=pptr;
235 eigrp_com_header = (const struct eigrp_common_header *)pptr;
Elliott Hughes820eced2021-08-20 18:00:50 -0700236 ND_TCHECK_SIZE(eigrp_com_header);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800237
238 /*
239 * Sanity checking of the header.
240 */
Elliott Hughes820eced2021-08-20 18:00:50 -0700241 if (GET_U_1(eigrp_com_header->version) != EIGRP_VERSION) {
242 ND_PRINT("EIGRP version %u packet not supported",
243 GET_U_1(eigrp_com_header->version));
244 return;
The Android Open Source Project2949f582009-03-03 19:30:46 -0800245 }
246
247 /* in non-verbose mode just lets print the basic Message Type*/
Elliott Hughes892a68b2015-10-19 14:43:53 -0700248 if (ndo->ndo_vflag < 1) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700249 ND_PRINT("EIGRP %s, length: %u",
250 tok2str(eigrp_opcode_values, "unknown (%u)",GET_U_1(eigrp_com_header->opcode)),
251 len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800252 return;
253 }
254
255 /* ok they seem to want to know everything - lets fully decode it */
256
Elliott Hughescec480a2017-12-19 16:54:57 -0800257 if (len < sizeof(struct eigrp_common_header)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700258 ND_PRINT("EIGRP %s, length: %u (too short, < %zu)",
259 tok2str(eigrp_opcode_values, "unknown (%u)",GET_U_1(eigrp_com_header->opcode)),
260 len, sizeof(struct eigrp_common_header));
Elliott Hughescec480a2017-12-19 16:54:57 -0800261 return;
262 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800263 tlen=len-sizeof(struct eigrp_common_header);
264
Elliott Hughes820eced2021-08-20 18:00:50 -0700265 ND_PRINT("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]"
266 "\n\tseq: 0x%08x, ack: 0x%08x, VRID: %u, AS: %u, length: %u",
267 GET_U_1(eigrp_com_header->version),
268 tok2str(eigrp_opcode_values, "unknown, type: %u",GET_U_1(eigrp_com_header->opcode)),
269 GET_U_1(eigrp_com_header->opcode),
270 GET_BE_U_2(eigrp_com_header->checksum),
271 bittok2str(eigrp_common_header_flag_values,
The Android Open Source Project2949f582009-03-03 19:30:46 -0800272 "none",
Elliott Hughes820eced2021-08-20 18:00:50 -0700273 GET_BE_U_4(eigrp_com_header->flags)),
274 GET_BE_U_4(eigrp_com_header->seq),
275 GET_BE_U_4(eigrp_com_header->ack),
276 GET_BE_U_2(eigrp_com_header->vrid),
277 GET_BE_U_2(eigrp_com_header->asn),
278 tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800279
Elliott Hughes820eced2021-08-20 18:00:50 -0700280 tptr+=sizeof(struct eigrp_common_header);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800281
282 while(tlen>0) {
283 /* did we capture enough for fully decoding the object header ? */
Elliott Hughes820eced2021-08-20 18:00:50 -0700284 ND_TCHECK_LEN(tptr, sizeof(struct eigrp_tlv_header));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800285
286 eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
Elliott Hughes820eced2021-08-20 18:00:50 -0700287 eigrp_tlv_len=GET_BE_U_2(eigrp_tlv_header->length);
288 eigrp_tlv_type=GET_BE_U_2(eigrp_tlv_header->type);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800289
290
291 if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header) ||
292 eigrp_tlv_len > tlen) {
Elliott Hughes892a68b2015-10-19 14:43:53 -0700293 print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800294 return;
295 }
296
Elliott Hughes820eced2021-08-20 18:00:50 -0700297 ND_PRINT("\n\t %s TLV (0x%04x), length: %u",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800298 tok2str(eigrp_tlv_values,
299 "Unknown",
300 eigrp_tlv_type),
301 eigrp_tlv_type,
Elliott Hughes820eced2021-08-20 18:00:50 -0700302 eigrp_tlv_len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800303
Elliott Hughescec480a2017-12-19 16:54:57 -0800304 if (eigrp_tlv_len < sizeof(struct eigrp_tlv_header)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700305 ND_PRINT(" (too short, < %zu)",
306 sizeof(struct eigrp_tlv_header));
Elliott Hughescec480a2017-12-19 16:54:57 -0800307 break;
308 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800309 tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
310 tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
311
312 /* did we capture enough for fully decoding the object ? */
Elliott Hughes820eced2021-08-20 18:00:50 -0700313 ND_TCHECK_LEN(tptr, eigrp_tlv_len);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800314
315 switch(eigrp_tlv_type) {
316
317 case EIGRP_TLV_GENERAL_PARM:
318 tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800319 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_general_parm)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700320 ND_PRINT(" (too short, < %zu)",
321 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_general_parm));
Elliott Hughescec480a2017-12-19 16:54:57 -0800322 break;
323 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800324
Elliott Hughes820eced2021-08-20 18:00:50 -0700325 ND_PRINT("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
326 GET_BE_U_2(tlv_ptr.eigrp_tlv_general_parm->holdtime),
327 GET_U_1(tlv_ptr.eigrp_tlv_general_parm->k1),
328 GET_U_1(tlv_ptr.eigrp_tlv_general_parm->k2),
329 GET_U_1(tlv_ptr.eigrp_tlv_general_parm->k3),
330 GET_U_1(tlv_ptr.eigrp_tlv_general_parm->k4),
331 GET_U_1(tlv_ptr.eigrp_tlv_general_parm->k5));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800332 break;
333
334 case EIGRP_TLV_SW_VERSION:
335 tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800336 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_sw_version)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700337 ND_PRINT(" (too short, < %zu)",
338 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_sw_version));
Elliott Hughescec480a2017-12-19 16:54:57 -0800339 break;
340 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800341
Elliott Hughes820eced2021-08-20 18:00:50 -0700342 ND_PRINT("\n\t IOS version: %u.%u, EIGRP version %u.%u",
343 GET_U_1(tlv_ptr.eigrp_tlv_sw_version->ios_major),
344 GET_U_1(tlv_ptr.eigrp_tlv_sw_version->ios_minor),
345 GET_U_1(tlv_ptr.eigrp_tlv_sw_version->eigrp_major),
346 GET_U_1(tlv_ptr.eigrp_tlv_sw_version->eigrp_minor));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800347 break;
348
349 case EIGRP_TLV_IP_INT:
350 tlv_ptr.eigrp_tlv_ip_int = (const struct eigrp_tlv_ip_int_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800351 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_ip_int)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700352 ND_PRINT(" (too short, < %zu)",
353 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_ip_int));
Elliott Hughescec480a2017-12-19 16:54:57 -0800354 break;
355 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800356
Elliott Hughes820eced2021-08-20 18:00:50 -0700357 bit_length = GET_U_1(tlv_ptr.eigrp_tlv_ip_int->plen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800358 if (bit_length > 32) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700359 ND_PRINT("\n\t illegal prefix length %u",bit_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800360 break;
361 }
362 byte_length = (bit_length + 7) / 8; /* variable length encoding */
363 memset(prefix, 0, 4);
Elliott Hughes820eced2021-08-20 18:00:50 -0700364 GET_CPY_BYTES(prefix, tlv_ptr.eigrp_tlv_ip_int->destination, byte_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800365
Elliott Hughes820eced2021-08-20 18:00:50 -0700366 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
367 ipaddr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
368 bit_length);
369 if (GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0)
370 ND_PRINT("self");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800371 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700372 ND_PRINT("%s",
373 GET_IPADDR_STRING(tlv_ptr.eigrp_tlv_ip_int->nexthop));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800374
Elliott Hughes820eced2021-08-20 18:00:50 -0700375 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
376 (GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_int->delay)/100),
377 GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_int->bandwidth),
378 GET_BE_U_3(tlv_ptr.eigrp_tlv_ip_int->mtu),
379 GET_U_1(tlv_ptr.eigrp_tlv_ip_int->hopcount),
380 GET_U_1(tlv_ptr.eigrp_tlv_ip_int->reliability),
381 GET_U_1(tlv_ptr.eigrp_tlv_ip_int->load));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800382 break;
383
384 case EIGRP_TLV_IP_EXT:
385 tlv_ptr.eigrp_tlv_ip_ext = (const struct eigrp_tlv_ip_ext_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800386 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_ip_ext)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700387 ND_PRINT(" (too short, < %zu)",
388 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_ip_ext));
Elliott Hughescec480a2017-12-19 16:54:57 -0800389 break;
390 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800391
Elliott Hughes820eced2021-08-20 18:00:50 -0700392 bit_length = GET_U_1(tlv_ptr.eigrp_tlv_ip_ext->plen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800393 if (bit_length > 32) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700394 ND_PRINT("\n\t illegal prefix length %u",bit_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800395 break;
396 }
397 byte_length = (bit_length + 7) / 8; /* variable length encoding */
398 memset(prefix, 0, 4);
Elliott Hughes820eced2021-08-20 18:00:50 -0700399 GET_CPY_BYTES(prefix, tlv_ptr.eigrp_tlv_ip_ext->destination, byte_length);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800400
Elliott Hughes820eced2021-08-20 18:00:50 -0700401 ND_PRINT("\n\t IPv4 prefix: %15s/%u, nexthop: ",
402 ipaddr_string(ndo, prefix), /* local buffer, not packet data; don't use GET_IPADDR_STRING() */
403 bit_length);
404 if (GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_ext->nexthop) == 0)
405 ND_PRINT("self");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800406 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700407 ND_PRINT("%s",
408 GET_IPADDR_STRING(tlv_ptr.eigrp_tlv_ip_ext->nexthop));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800409
Elliott Hughes820eced2021-08-20 18:00:50 -0700410 ND_PRINT("\n\t origin-router %s, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
411 GET_IPADDR_STRING(tlv_ptr.eigrp_tlv_ip_ext->origin_router),
412 GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_ext->origin_as),
413 tok2str(eigrp_ext_proto_id_values,"unknown",GET_U_1(tlv_ptr.eigrp_tlv_ip_ext->proto_id)),
414 GET_U_1(tlv_ptr.eigrp_tlv_ip_ext->flags),
415 GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_ext->tag),
416 GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_ext->metric));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800417
Elliott Hughes820eced2021-08-20 18:00:50 -0700418 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
419 (GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_ext->delay)/100),
420 GET_BE_U_4(tlv_ptr.eigrp_tlv_ip_ext->bandwidth),
421 GET_BE_U_3(tlv_ptr.eigrp_tlv_ip_ext->mtu),
422 GET_U_1(tlv_ptr.eigrp_tlv_ip_ext->hopcount),
423 GET_U_1(tlv_ptr.eigrp_tlv_ip_ext->reliability),
424 GET_U_1(tlv_ptr.eigrp_tlv_ip_ext->load));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800425 break;
426
427 case EIGRP_TLV_AT_CABLE_SETUP:
428 tlv_ptr.eigrp_tlv_at_cable_setup = (const struct eigrp_tlv_at_cable_setup_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800429 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_cable_setup)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700430 ND_PRINT(" (too short, < %zu)",
431 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_cable_setup));
Elliott Hughescec480a2017-12-19 16:54:57 -0800432 break;
433 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800434
Elliott Hughes820eced2021-08-20 18:00:50 -0700435 ND_PRINT("\n\t Cable-range: %u-%u, Router-ID %u",
436 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_cable_setup->cable_start),
437 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_cable_setup->cable_end),
438 GET_BE_U_4(tlv_ptr.eigrp_tlv_at_cable_setup->router_id));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800439 break;
440
441 case EIGRP_TLV_AT_INT:
442 tlv_ptr.eigrp_tlv_at_int = (const struct eigrp_tlv_at_int_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800443 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_int)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700444 ND_PRINT(" (too short, < %zu)",
445 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_int));
Elliott Hughescec480a2017-12-19 16:54:57 -0800446 break;
447 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800448
Elliott Hughes820eced2021-08-20 18:00:50 -0700449 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
450 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_int->cable_start),
451 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_int->cable_end));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800452
Elliott Hughes820eced2021-08-20 18:00:50 -0700453 if (GET_BE_U_4(tlv_ptr.eigrp_tlv_at_int->nexthop) == 0)
454 ND_PRINT("self");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800455 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700456 ND_PRINT("%u.%u",
457 GET_BE_U_2(&tlv_ptr.eigrp_tlv_at_int->nexthop[0]),
458 GET_BE_U_2(&tlv_ptr.eigrp_tlv_at_int->nexthop[2]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800459
Elliott Hughes820eced2021-08-20 18:00:50 -0700460 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
461 (GET_BE_U_4(tlv_ptr.eigrp_tlv_at_int->delay)/100),
462 GET_BE_U_4(tlv_ptr.eigrp_tlv_at_int->bandwidth),
463 GET_BE_U_3(tlv_ptr.eigrp_tlv_at_int->mtu),
464 GET_U_1(tlv_ptr.eigrp_tlv_at_int->hopcount),
465 GET_U_1(tlv_ptr.eigrp_tlv_at_int->reliability),
466 GET_U_1(tlv_ptr.eigrp_tlv_at_int->load));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800467 break;
468
469 case EIGRP_TLV_AT_EXT:
470 tlv_ptr.eigrp_tlv_at_ext = (const struct eigrp_tlv_at_ext_t *)tlv_tptr;
Elliott Hughescec480a2017-12-19 16:54:57 -0800471 if (tlv_tlen < sizeof(*tlv_ptr.eigrp_tlv_at_ext)) {
Elliott Hughes820eced2021-08-20 18:00:50 -0700472 ND_PRINT(" (too short, < %zu)",
473 sizeof(struct eigrp_tlv_header) + sizeof(*tlv_ptr.eigrp_tlv_at_ext));
Elliott Hughescec480a2017-12-19 16:54:57 -0800474 break;
475 }
The Android Open Source Project2949f582009-03-03 19:30:46 -0800476
Elliott Hughes820eced2021-08-20 18:00:50 -0700477 ND_PRINT("\n\t Cable-Range: %u-%u, nexthop: ",
478 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_ext->cable_start),
479 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_ext->cable_end));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800480
Elliott Hughes820eced2021-08-20 18:00:50 -0700481 if (GET_BE_U_4(tlv_ptr.eigrp_tlv_at_ext->nexthop) == 0)
482 ND_PRINT("self");
The Android Open Source Project2949f582009-03-03 19:30:46 -0800483 else
Elliott Hughes820eced2021-08-20 18:00:50 -0700484 ND_PRINT("%u.%u",
485 GET_BE_U_2(&tlv_ptr.eigrp_tlv_at_ext->nexthop[0]),
486 GET_BE_U_2(&tlv_ptr.eigrp_tlv_at_ext->nexthop[2]));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800487
Elliott Hughes820eced2021-08-20 18:00:50 -0700488 ND_PRINT("\n\t origin-router %u, origin-as %u, origin-proto %s, flags [0x%02x], tag 0x%08x, metric %u",
489 GET_BE_U_4(tlv_ptr.eigrp_tlv_at_ext->origin_router),
490 GET_BE_U_4(tlv_ptr.eigrp_tlv_at_ext->origin_as),
491 tok2str(eigrp_ext_proto_id_values,"unknown",GET_U_1(tlv_ptr.eigrp_tlv_at_ext->proto_id)),
492 GET_U_1(tlv_ptr.eigrp_tlv_at_ext->flags),
493 GET_BE_U_4(tlv_ptr.eigrp_tlv_at_ext->tag),
494 GET_BE_U_2(tlv_ptr.eigrp_tlv_at_ext->metric));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800495
Elliott Hughes820eced2021-08-20 18:00:50 -0700496 ND_PRINT("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
497 (GET_BE_U_4(tlv_ptr.eigrp_tlv_at_ext->delay)/100),
498 GET_BE_U_4(tlv_ptr.eigrp_tlv_at_ext->bandwidth),
499 GET_BE_U_3(tlv_ptr.eigrp_tlv_at_ext->mtu),
500 GET_U_1(tlv_ptr.eigrp_tlv_at_ext->hopcount),
501 GET_U_1(tlv_ptr.eigrp_tlv_at_ext->reliability),
502 GET_U_1(tlv_ptr.eigrp_tlv_at_ext->load));
The Android Open Source Project2949f582009-03-03 19:30:46 -0800503 break;
504
505 /*
506 * FIXME those are the defined TLVs that lack a decoder
507 * you are welcome to contribute code ;-)
508 */
509
510 case EIGRP_TLV_AUTH:
511 case EIGRP_TLV_SEQ:
512 case EIGRP_TLV_MCAST_SEQ:
513 case EIGRP_TLV_IPX_INT:
514 case EIGRP_TLV_IPX_EXT:
515
516 default:
Elliott Hughes892a68b2015-10-19 14:43:53 -0700517 if (ndo->ndo_vflag <= 1)
518 print_unknown_data(ndo,tlv_tptr,"\n\t ",tlv_tlen);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800519 break;
520 }
521 /* do we want to see an additionally hexdump ? */
Elliott Hughes892a68b2015-10-19 14:43:53 -0700522 if (ndo->ndo_vflag > 1)
523 print_unknown_data(ndo,tptr+sizeof(struct eigrp_tlv_header),"\n\t ",
The Android Open Source Project2949f582009-03-03 19:30:46 -0800524 eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
525
526 tptr+=eigrp_tlv_len;
527 tlen-=eigrp_tlv_len;
528 }
529 return;
530trunc:
Elliott Hughes820eced2021-08-20 18:00:50 -0700531 nd_print_trunc(ndo);
The Android Open Source Project2949f582009-03-03 19:30:46 -0800532}