]> The Tcpdump Group git mirrors - tcpdump/blob - print-eigrp.c
add support for the TLV_IP_INT dissector, changed header flag processing
[tcpdump] / print-eigrp.c
1 /*
2 * Copyright (c) 1998-2004 Hannes Gredler <hannes@tcpdump.org>
3 * 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
17 #ifndef lint
18 static const char rcsid[] _U_ =
19 "@(#) $Header: /tcpdump/master/tcpdump/print-eigrp.c,v 1.3 2004-05-01 09:07:01 hannes Exp $";
20 #endif
21
22 #ifdef HAVE_CONFIG_H
23 #include "config.h"
24 #endif
25
26 #include <tcpdump-stdinc.h>
27
28 #include <stdio.h>
29 #include <stdlib.h>
30 #include <string.h>
31
32 #include "interface.h"
33 #include "extract.h"
34 #include "addrtoname.h"
35
36 /*
37 * packet format documented at
38 * http://www.rhyshaden.com/eigrp.htm
39 */
40
41 struct eigrp_common_header {
42 u_int8_t version;
43 u_int8_t opcode;
44 u_int8_t checksum[2];
45 u_int8_t flags[4];
46 u_int8_t seq[4];
47 u_int8_t ack[4];
48 u_int8_t asn[4];
49 };
50
51 #define EIGRP_VERSION 2
52
53 #define EIGRP_OPCODE_UPDATE 1
54 #define EIGRP_OPCODE_QUERY 3
55 #define EIGRP_OPCODE_REPLY 4
56 #define EIGRP_OPCODE_HELLO 5
57 #define EIGRP_OPCODE_IPXSAP 6
58 #define EIGRP_OPCODE_PROBE 7
59
60 static const struct tok eigrp_opcode_values[] = {
61 { EIGRP_OPCODE_UPDATE, "Update" },
62 { EIGRP_OPCODE_QUERY, "Query" },
63 { EIGRP_OPCODE_REPLY, "Reply" },
64 { EIGRP_OPCODE_HELLO, "Hello" },
65 { EIGRP_OPCODE_IPXSAP, "IPX SAP" },
66 { EIGRP_OPCODE_PROBE, "Probe" },
67 { 0, NULL}
68 };
69
70 static const struct tok eigrp_common_header_flag_values[] = {
71 { 0x01, "Init" },
72 { 0x02, "Conditionally Received" },
73 { 0, NULL}
74 };
75
76 struct eigrp_tlv_header {
77 u_int8_t type[2];
78 u_int8_t length[2];
79 };
80
81 #define EIGRP_TLV_GENERAL_PARM 0x0001
82 #define EIGRP_TLV_AUTH 0x0002
83 #define EIGRP_TLV_SEQ 0x0003
84 #define EIGRP_TLV_SW_VERSION 0x0004
85 #define EIGRP_TLV_MCAST_SEQ 0x0005
86 #define EIGRP_TLV_IP_INT 0x0102
87 #define EIGRP_TLV_IP_EXT 0x0103
88 #define EIGRP_TLV_AT_INT 0x0202
89 #define EIGRP_TLV_AT_EXT 0x0203
90 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
91 #define EIGRP_TLV_IPX_INT 0x0302
92 #define EIGRP_TLV_IPX_EXT 0x0303
93
94 static const struct tok eigrp_tlv_values[] = {
95 { EIGRP_TLV_GENERAL_PARM, "General Parameters"},
96 { EIGRP_TLV_AUTH, "Authentication"},
97 { EIGRP_TLV_SEQ, "Sequence"},
98 { EIGRP_TLV_SW_VERSION, "Software Version"},
99 { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"},
100 { EIGRP_TLV_IP_INT, "IP Internal routes"},
101 { EIGRP_TLV_IP_EXT, "IP External routes"},
102 { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"},
103 { EIGRP_TLV_AT_EXT, "AppleTalk External routes"},
104 { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"},
105 { EIGRP_TLV_IPX_INT, "IPX Internal routes"},
106 { EIGRP_TLV_IPX_EXT, "IPX External routes"},
107 { 0, NULL}
108 };
109
110 struct eigrp_tlv_general_parm_t {
111 u_int8_t k1;
112 u_int8_t k2;
113 u_int8_t k3;
114 u_int8_t k4;
115 u_int8_t k5;
116 u_int8_t res;
117 u_int8_t holdtime[2];
118 };
119
120 struct eigrp_tlv_sw_version_t {
121 u_int8_t ios_major;
122 u_int8_t ios_minor;
123 u_int8_t eigrp_major;
124 u_int8_t eigrp_minor;
125 };
126
127 struct eigrp_tlv_ip_int_t {
128 u_int8_t nexthop[4];
129 u_int8_t delay[4];
130 u_int8_t bandwidth[4];
131 u_int8_t mtu[3];
132 u_int8_t hopcount;
133 u_int8_t reliability;
134 u_int8_t load;
135 u_int8_t reserved[2];
136 u_int8_t plen;
137 u_int8_t destination; /* variable length [0-4] bytes encoding */
138 };
139
140 void
141 eigrp_print(register const u_char *pptr, register u_int len) {
142
143 const struct eigrp_common_header *eigrp_com_header;
144 const struct eigrp_tlv_header *eigrp_tlv_header;
145 const u_char *tptr,*tlv_tptr;
146 int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen,byte_length, bit_length;
147 u_int8_t prefix[4];
148
149 union {
150 const struct eigrp_tlv_general_parm_t *eigrp_tlv_general_parm;
151 const struct eigrp_tlv_sw_version_t *eigrp_tlv_sw_version;
152 const struct eigrp_tlv_ip_int_t *eigrp_tlv_ip_int;
153 } tlv_ptr;
154
155 tptr=pptr;
156 eigrp_com_header = (const struct eigrp_common_header *)pptr;
157 TCHECK(*eigrp_com_header);
158
159 /*
160 * Sanity checking of the header.
161 */
162 if (eigrp_com_header->version != EIGRP_VERSION) {
163 printf("EIGRP version %u packet not supported",eigrp_com_header->version);
164 return;
165 }
166
167 /* in non-verbose mode just lets print the basic Message Type*/
168 if (vflag < 1) {
169 printf("EIGRP %s, length: %u",
170 tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
171 len);
172 return;
173 }
174
175 /* ok they seem to want to know everything - lets fully decode it */
176
177 tlen=len-sizeof(struct eigrp_common_header);
178
179 /* FIXME print other header info */
180 printf("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [%s]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
181 eigrp_com_header->version,
182 tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode),
183 eigrp_com_header->opcode,
184 EXTRACT_16BITS(&eigrp_com_header->checksum),
185 tok2str(eigrp_common_header_flag_values,
186 "none",
187 EXTRACT_32BITS(&eigrp_com_header->flags)),
188 EXTRACT_32BITS(&eigrp_com_header->seq),
189 EXTRACT_32BITS(&eigrp_com_header->ack),
190 EXTRACT_32BITS(&eigrp_com_header->asn),
191 tlen);
192
193 tptr+=sizeof(const struct eigrp_common_header);
194
195 while(tlen>0) {
196 /* did we capture enough for fully decoding the object header ? */
197 if (!TTEST2(*tptr, sizeof(struct eigrp_tlv_header)))
198 goto trunc;
199
200 eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
201 eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length);
202 eigrp_tlv_type=EXTRACT_16BITS(&eigrp_tlv_header->type);
203
204
205 if (eigrp_tlv_len == 0 || eigrp_tlv_len > tlen) {
206 print_unknown_data(tptr+sizeof(sizeof(struct eigrp_tlv_header)),"\n\t ",tlen);
207 return;
208 }
209
210 printf("\n\t %s TLV (0x%04x), length: %u",
211 tok2str(eigrp_tlv_values,
212 "Unknown",
213 eigrp_tlv_type),
214 eigrp_tlv_type,
215 eigrp_tlv_len);
216
217 tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
218 tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
219
220 /* did we capture enough for fully decoding the object ? */
221 if (!TTEST2(*tptr, eigrp_tlv_len))
222 goto trunc;
223
224 switch(eigrp_tlv_type) {
225
226 case EIGRP_TLV_GENERAL_PARM:
227 tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm_t *)tlv_tptr;
228
229 printf("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
230 EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime),
231 tlv_ptr.eigrp_tlv_general_parm->k1,
232 tlv_ptr.eigrp_tlv_general_parm->k2,
233 tlv_ptr.eigrp_tlv_general_parm->k3,
234 tlv_ptr.eigrp_tlv_general_parm->k4,
235 tlv_ptr.eigrp_tlv_general_parm->k5);
236 break;
237
238 case EIGRP_TLV_SW_VERSION:
239 tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version_t *)tlv_tptr;
240
241 printf("\n\t IOS version: %u.%u, EIGRP version %u.%u",
242 tlv_ptr.eigrp_tlv_sw_version->ios_major,
243 tlv_ptr.eigrp_tlv_sw_version->ios_minor,
244 tlv_ptr.eigrp_tlv_sw_version->eigrp_major,
245 tlv_ptr.eigrp_tlv_sw_version->eigrp_minor);
246 break;
247
248 case EIGRP_TLV_IP_INT:
249 tlv_ptr.eigrp_tlv_ip_int = (const struct eigrp_tlv_ip_int_t *)tlv_tptr;
250
251 bit_length = tlv_ptr.eigrp_tlv_ip_int->plen;
252 if (bit_length < 0 || bit_length > 32) {
253 printf("\n\t illegal prefix length %u",bit_length);
254 break;
255 }
256 byte_length = (bit_length + 7) / 8; /* variable length encoding */
257 memset(prefix, 0, 4);
258 memcpy(prefix,&tlv_ptr.eigrp_tlv_ip_int->destination,byte_length);
259
260 printf("\n\t IPv4 prefix: %15s/%u, nexthop: ",
261 ipaddr_string(prefix),
262 bit_length);
263 if (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop) == 0)
264 printf("self");
265 else
266 printf("%s",ipaddr_string(EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->nexthop)));
267
268 printf("\n\t delay %u ms, bandwidth %u Kbps, mtu %u, hop %u, reliability %u, load %u",
269 (EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->delay)/100),
270 EXTRACT_32BITS(&tlv_ptr.eigrp_tlv_ip_int->bandwidth),
271 EXTRACT_24BITS(&tlv_ptr.eigrp_tlv_ip_int->mtu),
272 tlv_ptr.eigrp_tlv_ip_int->hopcount,
273 tlv_ptr.eigrp_tlv_ip_int->reliability,
274 tlv_ptr.eigrp_tlv_ip_int->load);
275 break;
276
277 /*
278 * FIXME those are the defined TLVs that lack a decoder
279 * you are welcome to contribute code ;-)
280 */
281
282 case EIGRP_TLV_AUTH:
283 case EIGRP_TLV_SEQ:
284 case EIGRP_TLV_MCAST_SEQ:
285 case EIGRP_TLV_IP_EXT:
286 case EIGRP_TLV_AT_INT:
287 case EIGRP_TLV_AT_EXT:
288 case EIGRP_TLV_AT_CABLE_SETUP:
289 case EIGRP_TLV_IPX_INT:
290 case EIGRP_TLV_IPX_EXT:
291
292 default:
293 if (vflag <= 1)
294 print_unknown_data(tlv_tptr,"\n\t ",tlv_tlen);
295 break;
296 }
297 /* do we want to see an additionally hexdump ? */
298 if (vflag > 1)
299 print_unknown_data(tptr+sizeof(sizeof(struct eigrp_tlv_header)),"\n\t ",
300 eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
301
302 tptr+=eigrp_tlv_len;
303 tlen-=eigrp_tlv_len;
304 }
305 return;
306 trunc:
307 printf("\n\t\t packet exceeded snapshot");
308 }