]> The Tcpdump Group git mirrors - tcpdump/blob - print-eigrp.c
add support for the GENERAL_PARM and SW_VERSION TLV
[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.2 2004-04-30 23:52:00 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 struct eigrp_tlv_header {
71 u_int8_t type[2];
72 u_int8_t length[2];
73 };
74
75 #define EIGRP_TLV_GENERAL_PARM 0x0001
76 #define EIGRP_TLV_AUTH 0x0002
77 #define EIGRP_TLV_SEQ 0x0003
78 #define EIGRP_TLV_SW_VERSION 0x0004
79 #define EIGRP_TLV_MCAST_SEQ 0x0005
80 #define EIGRP_TLV_IP_INT 0x0102
81 #define EIGRP_TLV_IP_EXT 0x0103
82 #define EIGRP_TLV_AT_INT 0x0202
83 #define EIGRP_TLV_AT_EXT 0x0203
84 #define EIGRP_TLV_AT_CABLE_SETUP 0x0204
85 #define EIGRP_TLV_IPX_INT 0x0302
86 #define EIGRP_TLV_IPX_EXT 0x0303
87
88 static const struct tok eigrp_tlv_values[] = {
89 { EIGRP_TLV_GENERAL_PARM, "General Parameters"},
90 { EIGRP_TLV_AUTH, "Authentication"},
91 { EIGRP_TLV_SEQ, "Sequence"},
92 { EIGRP_TLV_SW_VERSION, "Software Version"},
93 { EIGRP_TLV_MCAST_SEQ, "Next Multicast Sequence"},
94 { EIGRP_TLV_IP_INT, "IP Internal routes"},
95 { EIGRP_TLV_IP_EXT, "IP External routes"},
96 { EIGRP_TLV_AT_INT, "AppleTalk Internal routes"},
97 { EIGRP_TLV_AT_EXT, "AppleTalk External routes"},
98 { EIGRP_TLV_AT_CABLE_SETUP, "AppleTalk Cable setup"},
99 { EIGRP_TLV_IPX_INT, "IPX Internal routes"},
100 { EIGRP_TLV_IPX_EXT, "IPX External routes"},
101 { 0, NULL}
102 };
103
104 struct eigrp_tlv_general_parm {
105 u_int8_t k1;
106 u_int8_t k2;
107 u_int8_t k3;
108 u_int8_t k4;
109 u_int8_t k5;
110 u_int8_t res;
111 u_int8_t holdtime[2];
112 };
113
114 struct eigrp_tlv_sw_version {
115 u_int8_t ios_major;
116 u_int8_t ios_minor;
117 u_int8_t eigrp_major;
118 u_int8_t eigrp_minor;
119 };
120
121 void
122 eigrp_print(register const u_char *pptr, register u_int len) {
123
124 const struct eigrp_common_header *eigrp_com_header;
125 const struct eigrp_tlv_header *eigrp_tlv_header;
126 const u_char *tptr,*tlv_tptr;
127 int tlen,eigrp_tlv_len,eigrp_tlv_type,tlv_tlen;
128
129 union {
130 const struct eigrp_tlv_general_parm *eigrp_tlv_general_parm;
131 const struct eigrp_tlv_sw_version *eigrp_tlv_sw_version;
132 } tlv_ptr;
133
134 tptr=pptr;
135 eigrp_com_header = (const struct eigrp_common_header *)pptr;
136 TCHECK(*eigrp_com_header);
137
138 /*
139 * Sanity checking of the header.
140 */
141 if (eigrp_com_header->version != EIGRP_VERSION) {
142 printf("EIGRP version %u packet not supported",eigrp_com_header->version);
143 return;
144 }
145
146 /* in non-verbose mode just lets print the basic Message Type*/
147 if (vflag < 1) {
148 printf("EIGRP %s, length: %u",
149 tok2str(eigrp_opcode_values, "unknown (%u)",eigrp_com_header->opcode),
150 len);
151 return;
152 }
153
154 /* ok they seem to want to know everything - lets fully decode it */
155
156 tlen=len-sizeof(struct eigrp_common_header);
157
158 /* FIXME print other header info */
159 printf("\n\tEIGRP v%u, opcode: %s (%u), chksum: 0x%04x, Flags: [0x%08x]\n\tseq: 0x%08x, ack: 0x%08x, AS: %u, length: %u",
160 eigrp_com_header->version,
161 tok2str(eigrp_opcode_values, "unknown, type: %u",eigrp_com_header->opcode),
162 eigrp_com_header->opcode,
163 EXTRACT_16BITS(&eigrp_com_header->checksum),
164 EXTRACT_32BITS(&eigrp_com_header->flags),
165 EXTRACT_32BITS(&eigrp_com_header->seq),
166 EXTRACT_32BITS(&eigrp_com_header->ack),
167 EXTRACT_32BITS(&eigrp_com_header->asn),
168 tlen);
169
170 tptr+=sizeof(const struct eigrp_common_header);
171
172 while(tlen>0) {
173 /* did we capture enough for fully decoding the object header ? */
174 if (!TTEST2(*tptr, sizeof(struct eigrp_tlv_header)))
175 goto trunc;
176
177 eigrp_tlv_header = (const struct eigrp_tlv_header *)tptr;
178 eigrp_tlv_len=EXTRACT_16BITS(&eigrp_tlv_header->length);
179 eigrp_tlv_type=EXTRACT_16BITS(&eigrp_tlv_header->type);
180
181
182 if (eigrp_tlv_len == 0 || eigrp_tlv_len > tlen) {
183 print_unknown_data(tptr+sizeof(sizeof(struct eigrp_tlv_header)),"\n\t ",tlen);
184 return;
185 }
186
187 printf("\n\t %s TLV (0x%04x), length: %u",
188 tok2str(eigrp_tlv_values,
189 "Unknown",
190 eigrp_tlv_type),
191 eigrp_tlv_type,
192 eigrp_tlv_len);
193
194 tlv_tptr=tptr+sizeof(struct eigrp_tlv_header);
195 tlv_tlen=eigrp_tlv_len-sizeof(struct eigrp_tlv_header);
196
197 /* did we capture enough for fully decoding the object ? */
198 if (!TTEST2(*tptr, eigrp_tlv_len))
199 goto trunc;
200
201 switch(eigrp_tlv_type) {
202
203 case EIGRP_TLV_GENERAL_PARM:
204 tlv_ptr.eigrp_tlv_general_parm = (const struct eigrp_tlv_general_parm *)tlv_tptr;
205 printf("\n\t holdtime: %us, k1 %u, k2 %u, k3 %u, k4 %u, k5 %u",
206 EXTRACT_16BITS(tlv_ptr.eigrp_tlv_general_parm->holdtime),
207 tlv_ptr.eigrp_tlv_general_parm->k1,
208 tlv_ptr.eigrp_tlv_general_parm->k2,
209 tlv_ptr.eigrp_tlv_general_parm->k3,
210 tlv_ptr.eigrp_tlv_general_parm->k4,
211 tlv_ptr.eigrp_tlv_general_parm->k5);
212 break;
213
214 case EIGRP_TLV_SW_VERSION:
215 tlv_ptr.eigrp_tlv_sw_version = (const struct eigrp_tlv_sw_version *)tlv_tptr;
216 printf("\n\t IOS version: %u.%u, EIGRP version %u.%u",
217 tlv_ptr.eigrp_tlv_sw_version->ios_major,
218 tlv_ptr.eigrp_tlv_sw_version->ios_minor,
219 tlv_ptr.eigrp_tlv_sw_version->eigrp_major,
220 tlv_ptr.eigrp_tlv_sw_version->eigrp_minor);
221 break;
222
223 /*
224 * FIXME those are the defined TLVs that lack a decoder
225 * you are welcome to contribute code ;-)
226 */
227
228 case EIGRP_TLV_AUTH:
229 case EIGRP_TLV_SEQ:
230 case EIGRP_TLV_MCAST_SEQ:
231 case EIGRP_TLV_IP_INT:
232 case EIGRP_TLV_IP_EXT:
233 case EIGRP_TLV_AT_INT:
234 case EIGRP_TLV_AT_EXT:
235 case EIGRP_TLV_AT_CABLE_SETUP:
236 case EIGRP_TLV_IPX_INT:
237 case EIGRP_TLV_IPX_EXT:
238
239 default:
240 if (vflag <= 1)
241 print_unknown_data(tlv_tptr,"\n\t ",tlv_tlen);
242 break;
243 }
244 /* do we want to see an additionally hexdump ? */
245 if (vflag > 1)
246 print_unknown_data(tptr+sizeof(sizeof(struct eigrp_tlv_header)),"\n\t ",
247 eigrp_tlv_len-sizeof(struct eigrp_tlv_header));
248
249 tptr+=eigrp_tlv_len;
250 tlen-=eigrp_tlv_len;
251 }
252 return;
253 trunc:
254 printf("\n\t\t packet exceeded snapshot");
255 }