2 * Routines for AODV dissection
3 * Copyright 2000, Erik Nordström <erik.nordstrom@it.uu.se>
5 * $Id: packet-aodv.c,v 1.6 2002/08/28 21:00:07 jmayer Exp $
7 * Ethereal - Network traffic analyzer
8 * By Gerald Combs <gerald@ethereal.com>
9 * Copyright 1998 Gerald Combs
11 * This program is free software; you can redistribute it and/or
12 * modify it under the terms of the GNU General Public License
13 * as published by the Free Software Foundation; either version 2
14 * of the License, or (at your option) any later version.
16 * This program is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU General Public License for more details.
21 * You should have received a copy of the GNU General Public License
22 * along with this program; if not, write to the Free Software
23 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
36 #include <epan/packet.h>
38 #define UDP_PORT_AODV 654
45 #define RREQ_GRAT 0x20
47 #define RREQ_JOIN 0x80
52 #define RERR_NODEL 0x80
54 static const value_string type_vals[] = {
93 /* Initialize the protocol and registered fields */
94 static int proto_aodv = -1;
95 static int hf_aodv_type = -1;
96 static int hf_aodv_flags = -1;
97 static int hf_aodv_prefix_sz = -1;
98 static int hf_aodv_hopcount = -1;
99 static int hf_aodv_rreq_id = -1;
100 static int hf_aodv_dest_ip = -1;
101 static int hf_aodv_dest_seqno = -1;
102 static int hf_aodv_orig_ip = -1;
103 static int hf_aodv_orig_seqno = -1;
104 static int hf_aodv_lifetime = -1;
105 static int hf_aodv_destcount = -1;
106 static int hf_aodv_unreach_dest_ip = -1;
107 static int hf_aodv_unreach_dest_seqno = -1;
108 static int hf_aodv_flags_rreq_join = -1;
109 static int hf_aodv_flags_rreq_repair = -1;
110 static int hf_aodv_flags_rreq_gratuitous = -1;
111 static int hf_aodv_flags_rrep_repair = -1;
112 static int hf_aodv_flags_rrep_ack = -1;
113 static int hf_aodv_flags_rerr_nodelete = -1;
115 /* Initialize the subtree pointers */
116 static gint ett_aodv = -1;
117 static gint ett_aodv_flags = -1;
118 static gint ett_aodv_unreach_dest = -1;
120 /* Code to actually dissect the packets */
122 dissect_aodv(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
124 proto_item *ti = NULL, *tj = NULL, *tk = NULL;
125 proto_tree *aodv_tree = NULL, *aodv_flags_tree = NULL,
126 *aodv_unreach_dest_tree = NULL;
129 struct aodv_rreq rreq;
130 struct aodv_rrep rrep;
131 struct aodv_rerr rerr;
133 /* Make entries in Protocol column and Info column on summary display */
134 if (check_col(pinfo->cinfo, COL_PROTOCOL))
135 col_set_str(pinfo->cinfo, COL_PROTOCOL, "AODV");
137 if (check_col(pinfo->cinfo, COL_INFO))
138 col_clear(pinfo->cinfo, COL_INFO);
140 /* Check the type of AODV packet. */
141 type = tvb_get_guint8(tvb, 0);
142 if (type < 1 || type > 3) {
144 * We assume this is not an AODV packet.
150 ti = proto_tree_add_protocol_format(tree, proto_aodv, tvb, 0, -1,
151 "Ad hoc On-demand Distance Vector Routing Protocol, %s",
152 val_to_str(type, type_vals, "Unknown AODV Packet Type (%u)"));
153 aodv_tree = proto_item_add_subtree(ti, ett_aodv);
155 proto_tree_add_uint(aodv_tree, hf_aodv_type, tvb, 0, 1, type);
156 tj = proto_tree_add_text(aodv_tree, tvb, 1, 1, "Flags:");
157 aodv_flags_tree = proto_item_add_subtree(tj, ett_aodv_flags);
164 rreq.flags = tvb_get_guint8(tvb, 1);
165 rreq.hop_count = tvb_get_guint8(tvb, 3);
166 rreq.rreq_id = tvb_get_ntohl(tvb, 4);
167 tvb_memcpy(tvb, (guint8 *)&rreq.dest_addr, 8, 4);
168 rreq.dest_seqno = tvb_get_ntohl(tvb, 12);
169 tvb_memcpy(tvb, (guint8 *)&rreq.orig_addr, 16, 4);
170 rreq.orig_seqno = tvb_get_ntohl(tvb, 20);
173 proto_tree_add_boolean(aodv_flags_tree, hf_aodv_flags_rreq_join, tvb, 1, 1, rreq.flags);
174 proto_tree_add_boolean(aodv_flags_tree, hf_aodv_flags_rreq_repair, tvb, 1, 1, rreq.flags);
175 proto_tree_add_boolean(aodv_flags_tree, hf_aodv_flags_rreq_gratuitous, tvb, 1, 1, rreq.flags);
176 if (rreq.flags & RREQ_JOIN)
177 proto_item_append_text(tj, " J");
178 if (rreq.flags & RREQ_REP)
179 proto_item_append_text(tj, " R");
180 if (rreq.flags & RREQ_GRAT)
181 proto_item_append_text(tj, " G");
182 proto_tree_add_uint(aodv_tree, hf_aodv_hopcount, tvb, 3, 1, rreq.hop_count);
183 proto_tree_add_uint(aodv_tree, hf_aodv_rreq_id, tvb, 4, 4, rreq.rreq_id);
184 proto_tree_add_ipv4(aodv_tree, hf_aodv_dest_ip, tvb, 8, 4, rreq.dest_addr);
185 proto_tree_add_uint(aodv_tree, hf_aodv_dest_seqno, tvb, 12, 4, rreq.dest_seqno);
186 proto_tree_add_ipv4(aodv_tree, hf_aodv_orig_ip, tvb, 16, 4, rreq.orig_addr);
187 proto_tree_add_uint(aodv_tree, hf_aodv_orig_seqno, tvb, 20, 4, rreq.orig_seqno);
188 proto_item_append_text(ti, ", Dest IP: %s, Orig IP: %s, Id=%u", ip_to_str(tvb_get_ptr(tvb, 8, 4)), ip_to_str(tvb_get_ptr(tvb, 16, 4)), rreq.rreq_id);
191 if (check_col(pinfo->cinfo, COL_INFO))
192 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, D: %s O: %s Id=%u Hcnt=%u DSN=%u OSN=%u",
193 val_to_str(type, type_vals,
194 "Unknown AODV Packet Type (%u)"),
195 ip_to_str(tvb_get_ptr(tvb, 8, 4)),
196 ip_to_str(tvb_get_ptr(tvb, 16, 4)),
205 rrep.flags = tvb_get_guint8(tvb, 1);
206 rrep.prefix_sz = tvb_get_guint8(tvb, 2) & 0x1F;
207 rrep.hop_count = tvb_get_guint8(tvb, 3);
208 tvb_memcpy(tvb, (guint8 *)&rrep.dest_addr, 4, 4);
209 rrep.dest_seqno = tvb_get_ntohl(tvb, 8);
210 tvb_memcpy(tvb, (guint8 *)&rrep.orig_addr, 12, 4);
211 rrep.lifetime = tvb_get_ntohl(tvb, 16);
214 proto_tree_add_boolean(aodv_flags_tree, hf_aodv_flags_rrep_repair, tvb, 1, 1, rrep.flags);
215 proto_tree_add_boolean(aodv_flags_tree, hf_aodv_flags_rrep_ack, tvb, 1, 1, rrep.flags);
216 if (rrep.flags & RREP_REP)
217 proto_item_append_text(tj, " R");
218 if (rrep.flags & RREP_ACK)
219 proto_item_append_text(tj, " A");
220 proto_tree_add_uint(aodv_tree, hf_aodv_prefix_sz, tvb, 3, 1, rrep.prefix_sz);
221 proto_tree_add_uint(aodv_tree, hf_aodv_hopcount, tvb, 3, 1, rrep.hop_count);
222 proto_tree_add_ipv4(aodv_tree, hf_aodv_dest_ip, tvb, 4, 4, rrep.dest_addr);
223 proto_tree_add_uint(aodv_tree, hf_aodv_dest_seqno, tvb, 8, 4, rrep.dest_seqno);
224 proto_tree_add_ipv4(aodv_tree, hf_aodv_orig_ip, tvb, 12, 4, rrep.orig_addr);
225 proto_tree_add_uint(aodv_tree, hf_aodv_lifetime, tvb, 16, 4, rrep.lifetime);
226 proto_item_append_text(ti, ", Dest IP: %s, Orig IP: %s, Lifetime=%u", ip_to_str(tvb_get_ptr(tvb, 4, 4)), ip_to_str(tvb_get_ptr(tvb, 12, 4)), rrep.lifetime);
229 if (check_col(pinfo->cinfo, COL_INFO))
230 col_add_fstr(pinfo->cinfo, COL_INFO, "%s D: %s O: %s Hcnt=%u DSN=%u Lifetime=%u",
231 val_to_str(type, type_vals,
232 "Unknown AODV Packet Type (%u)"),
233 ip_to_str(tvb_get_ptr(tvb, 4, 4)),
234 ip_to_str(tvb_get_ptr(tvb, 12, 4)),
241 rerr.flags = tvb_get_guint8(tvb, 1);
242 rerr.dest_count = tvb_get_guint8(tvb, 3);
245 proto_tree_add_boolean(aodv_flags_tree, hf_aodv_flags_rerr_nodelete, tvb, 1, 1, rerr.flags);
246 if (rerr.flags & RERR_NODEL)
247 proto_item_append_text(tj, " N");
248 proto_tree_add_uint(aodv_tree, hf_aodv_destcount, tvb, 3, 1, rerr.dest_count);
249 tk = proto_tree_add_text(aodv_tree, tvb, 4, 8*rerr.dest_count, "Unreachable Destinations:");
251 aodv_unreach_dest_tree = proto_item_add_subtree(tk, ett_aodv_unreach_dest);
252 for (i = 0; i < rerr.dest_count; i++) {
253 tvb_memcpy(tvb, (guint8 *)&rerr.dest_addr, 4+8*i, 4);
254 rerr.dest_seqno = tvb_get_ntohl(tvb, 8+8*i);
255 proto_tree_add_ipv4(aodv_unreach_dest_tree, hf_aodv_dest_ip, tvb, 4+8*i, 4, rerr.dest_addr);
256 proto_tree_add_uint(aodv_unreach_dest_tree, hf_aodv_dest_seqno, tvb, 8+8*i, 4, rerr.dest_seqno);
260 if (check_col(pinfo->cinfo, COL_INFO))
261 col_add_fstr(pinfo->cinfo, COL_INFO, "%s, Dest Count=%u",
262 val_to_str(type, type_vals,
263 "Unknown AODV Packet Type (%u)"),
267 proto_tree_add_text(aodv_tree, tvb, 0,
268 1, "Unknown AODV Packet Type (%u)",
272 return tvb_length(tvb);
276 /* Register the protocol with Ethereal */
278 proto_register_aodv(void)
280 static hf_register_info hf[] = {
282 { "Type", "aodv.type",
283 FT_UINT8, BASE_DEC, VALS(type_vals), 0x0,
284 "AODV packet type", HFILL }
287 { "Flags", "aodv.flags",
288 FT_UINT16, BASE_DEC, NULL, 0x0,
291 { &hf_aodv_flags_rreq_join,
292 { "RREQ Join", "aodv.flags.rreq_join",
293 FT_BOOLEAN, 8, TFS(&flags_set_truth), RREQ_JOIN,
296 { &hf_aodv_flags_rreq_repair,
297 { "RREQ Repair", "aodv.flags.rreq_repair",
298 FT_BOOLEAN, 8, TFS(&flags_set_truth), RREQ_REP,
301 { &hf_aodv_flags_rreq_gratuitous,
302 { "RREQ Gratuitous", "aodv.flags.rreq_gratuitous",
303 FT_BOOLEAN, 8, TFS(&flags_set_truth), RREQ_GRAT,
306 { &hf_aodv_flags_rrep_repair,
307 { "RREP Repair", "aodv.flags.rrep_repair",
308 FT_BOOLEAN, 8, TFS(&flags_set_truth), RREP_REP,
311 { &hf_aodv_flags_rrep_ack,
312 { "RREP Acknowledgement", "aodv.flags.rrep_ack",
313 FT_BOOLEAN, 8, TFS(&flags_set_truth), RREP_ACK,
316 { &hf_aodv_flags_rerr_nodelete,
317 { "RERR No Delete", "aodv.flags.rerr_nodelete",
318 FT_BOOLEAN, 8, TFS(&flags_set_truth), RERR_NODEL,
321 { &hf_aodv_prefix_sz,
322 { "Prefix Size", "aodv.prefix_sz",
323 FT_UINT8, BASE_DEC, NULL, 0x0,
324 "Prefix_size", HFILL }
327 { "Hop Count", "aodv.hopcount",
328 FT_UINT8, BASE_DEC, NULL, 0x0,
332 { "RREQ Id", "aodv.rreq_id",
333 FT_UINT32, BASE_DEC, NULL, 0x0,
337 { "Destination IP", "aodv.dest_ip",
338 FT_IPv4, BASE_DEC, NULL, 0x0,
339 "Destination IP Address", HFILL }
341 { &hf_aodv_dest_seqno,
342 { "Destination Sequence Number", "aodv.dest_seqno",
343 FT_UINT32, BASE_DEC, NULL, 0x0,
344 "Destination Sequence Number", HFILL }
347 { "Originator IP", "aodv.orig_ip",
348 FT_IPv4, BASE_DEC, NULL, 0x0,
349 "Originator IP Address", HFILL }
351 { &hf_aodv_orig_seqno,
352 { "Originator Sequence Number", "aodv.orig_seqno",
353 FT_UINT32, BASE_DEC, NULL, 0x0,
354 "Originator Sequence Number", HFILL }
357 { "Lifetime", "aodv.lifetime",
358 FT_UINT32, BASE_DEC, NULL, 0x0,
361 { &hf_aodv_destcount,
362 { "Destination Count", "aodv.destcount",
363 FT_UINT8, BASE_DEC, NULL, 0x0,
364 "Unreachable Destinations Count", HFILL }
366 { &hf_aodv_unreach_dest_ip,
367 { "Unreachable Destination IP", "aodv.unreach_dest_ip",
368 FT_IPv4, BASE_DEC, NULL, 0x0,
369 "Unreachable Destination IP Address", HFILL }
371 { &hf_aodv_unreach_dest_seqno,
372 { "Unreachable Destination Sequence Number", "aodv.unreach_dest_seqno",
373 FT_UINT32, BASE_DEC, NULL, 0x0,
374 "Unreachable Destination Sequence Number", HFILL }
378 /* Setup protocol subtree array */
379 static gint *ett[] = {
382 &ett_aodv_unreach_dest,
385 /* Register the protocol name and description */
386 proto_aodv = proto_register_protocol("Ad hoc On-demand Distance Vector Routing Protocol", "AODV", "aodv");
388 /* Required function calls to register the header fields and subtrees used */
389 proto_register_field_array(proto_aodv, hf, array_length(hf));
390 proto_register_subtree_array(ett, array_length(ett));
395 proto_reg_handoff_aodv(void)
397 dissector_handle_t aodv_handle;
399 aodv_handle = new_create_dissector_handle(dissect_aodv,
401 dissector_add("udp.port", UDP_PORT_AODV, aodv_handle);