2 * Routines for OLSR (IPv4 & IPv6 compatible) RFC parsing
3 * Compatible with RFC-compliant OLSR implementations such as
4 * NRLOLSRD (http://pf.itd.nrl.navy.mil/projects/olsr/).
5 * Parser created by Aaron Woo <woo@itd.nrl.navy.mil> of
6 * the Naval Research Laboratory
7 * Currently maintained by Jeff Weston <weston@itd.nrl.navy.mil>.
9 * Updated to Olsr.org and NRLOLSR packages by Henning Rogge <rogge@fgan.de>
10 * http://www.ietf.org/rfc/rfc3626.txt
12 * Wireshark - Network traffic analyzer
13 * By Gerald Combs <gerald@wireshark.org>
14 * Copyright 1998 Gerald Combs
16 * This program is free software; you can redistribute it and/or
17 * modify it under the terms of the GNU General Public License
18 * as published by the Free Software Foundation; either version 2
19 * of the License, or (at your option) any later version.
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
26 * You should have received a copy of the GNU General Public License
27 * along with this program; if not, write to the Free Software
28 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
37 #include <epan/packet.h>
38 #include <epan/prefs.h>
39 #include <epan/expert.h>
40 #include <epan/to_str.h>
42 void proto_register_olsr(void);
43 void proto_reg_handoff_olsr(void);
45 #define UDP_PORT_OLSR 698
51 #define OLSR_ORG_NAMESERVICE 130
52 #define OLSR_ORG_LQ_HELLO 201
53 #define OLSR_ORG_LQ_TC 202
54 #define NRLOLSR_TC_EXTRA 241
56 /* Initialize the protocol and registered fields */
57 static int proto_olsr = -1;
59 static int hf_olsr_packet_len = -1;
60 static int hf_olsr_packet_seq_num = -1;
62 static int hf_olsr_message = -1;
63 static int hf_olsr_message_type = -1;
64 static int hf_olsr_vtime = -1;
65 static int hf_olsr_message_size = -1;
66 static int hf_olsr_ttl = -1;
67 static int hf_olsr_hop_count = -1;
68 static int hf_olsr_message_seq_num = -1;
70 static int hf_olsr_htime = -1;
71 static int hf_olsr_willingness = -1;
73 static int hf_olsr_link_type = -1;
74 static int hf_olsr_link_message_size = -1;
75 static int hf_olsr_ansn = -1;
77 static int hf_olsr_neighbor = -1;
78 static int hf_olsr_origin_addr = -1;
79 static int hf_olsr_neighbor_addr = -1;
80 static int hf_olsr_interface_addr = -1;
81 static int hf_olsr_netmask = -1;
82 static int hf_olsr_network_addr = -1;
84 /* static int hf_olsr_neighbor6 = -1; */
85 static int hf_olsr_origin6_addr = -1;
86 static int hf_olsr_neighbor6_addr = -1;
87 static int hf_olsr_interface6_addr = -1;
88 static int hf_olsr_netmask6 = -1;
89 static int hf_olsr_network6_addr = -1;
91 static int hf_olsrorg_lq = -1;
92 static int hf_olsrorg_nlq = -1;
93 static int hf_nrlolsr_f1 = -1;
94 static int hf_nrlolsr_f2 = -1;
96 static int hf_olsrorg_ns_version = -1;
97 static int hf_olsrorg_ns_count = -1;
99 static int hf_olsrorg_ns = -1;
100 static int hf_olsrorg_ns_type = -1;
101 static int hf_olsrorg_ns_length = -1;
102 static int hf_olsrorg_ns_ip = -1;
103 static int hf_olsrorg_ns_ip6 = -1;
104 static int hf_olsrorg_ns_content = -1;
106 static int hf_olsr_data = -1;
108 /* Initialize the subtree pointers*/
109 static gint ett_olsr = -1;
110 static gint ett_olsr_message[G_MAXUINT8 + 1];
111 static gint ett_olsr_message_linktype = -1;
112 static gint ett_olsr_message_neigh = -1;
113 static gint ett_olsr_message_neigh6 = -1;
114 static gint ett_olsr_message_ns = -1;
116 static expert_field ei_olsr_not_enough_bytes = EI_INIT;
117 static expert_field ei_olsrorg_ns_version = EI_INIT;
118 static expert_field ei_olsr_data_misaligned = EI_INIT;
120 static const value_string message_type_vals[] = {
125 { OLSR_ORG_LQ_HELLO, "HELLO (LQ, olsr.org)" },
126 { OLSR_ORG_LQ_TC, "TC (LQ, olsr.org)" },
127 { OLSR_ORG_NAMESERVICE, "Nameservice (olsr.org)" },
128 { NRLOLSR_TC_EXTRA, "TC (LQ, nrlolsr)" },
132 static const value_string link_type_vals[] = {
133 { 0, "Unspecified Link" },
134 { 1, "Asymmetric Link" },
136 { 5, "Pending Link" },
137 { 6, "Symmetric Link" },
142 static const value_string willingness_type_vals[] = {
148 static const value_string nameservice_type_vals[] = {
156 static gboolean global_olsr_olsrorg = TRUE;
157 static gboolean global_olsr_nrlolsr = TRUE;
159 static double getOlsrTime(guint8 timeval) {
160 int high_bits, low_bits;
162 high_bits = ((timeval & 0xF0) >> 4);
163 low_bits = (timeval & 0x0F);
164 return ((G_GUINT64_CONSTANT(1) << low_bits) / 16.0) * (1 + (high_bits / 16.0));
167 /*------------------------- TC Dissecting Code-------------------------*/
168 static int dissect_olsr_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
169 if (message_end - offset < 4) {
170 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
171 "Not enough bytes for TC");
175 proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, ENC_BIG_ENDIAN);
178 while (offset < message_end) {
179 if (message_end - offset < pinfo->src.len) {
180 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
181 "Not enough bytes for last neighbor");
184 if (pinfo->src.type == AT_IPv4) {
185 proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
187 } else if (pinfo->src.type == AT_IPv6) {
188 proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
191 break; /* unknown address type should be handled in dissect_olsr, just be sure */
197 static int dissect_olsrorg_lq_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
199 if (message_end - offset < 4) {
200 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
201 "Not enough bytes for Olsr.org LQ-TC");
204 proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, ENC_BIG_ENDIAN);
207 while (offset < message_end) {
208 proto_item *address_group;
209 proto_tree *address_tree;
212 if (pinfo->src.type == AT_IPv4) {
213 if (message_end - offset < 8) {
214 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
215 "Not enough bytes for last entry (need 8 bytes)");
218 lq = tvb_get_guint8(tvb, offset + 4);
219 nlq = tvb_get_guint8(tvb, offset + 5);
221 address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 8,
222 NULL, "%s (%d/%d)", tvb_ip_to_str(tvb, offset), lq, nlq);
224 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
226 proto_tree_add_item(address_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
228 } else if (pinfo->src.type == AT_IPv6) {
229 if (message_end - offset < 20) {
230 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
231 "Not enough bytes for last entry (need 20 bytes)");
234 lq = tvb_get_guint8(tvb, offset + 16);
235 nlq = tvb_get_guint8(tvb, offset + 17);
237 address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 20,
238 NULL, "%s (%d/%d)", tvb_ip6_to_str(tvb, offset), lq, nlq);
240 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
242 proto_tree_add_item(address_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
245 break; /* unknown address type should be handled in dissect_olsr, just be sure */
248 proto_tree_add_item(address_tree, hf_olsrorg_lq, tvb, offset++, 1, ENC_BIG_ENDIAN);
249 proto_tree_add_item(address_tree, hf_olsrorg_nlq, tvb, offset++, 1, ENC_BIG_ENDIAN);
255 static int dissect_nrlolsr_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
256 int field1Ptr, field2Ptr, saneEnd;
257 if (message_end - offset < 4) {
258 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
259 "Not enough bytes for NRLOLSR LQ-TC");
263 proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, ENC_BIG_ENDIAN);
266 field1Ptr = offset + (message_end - offset) / (pinfo->src.len + 2) * (pinfo->src.len);
267 field2Ptr = offset + (message_end - offset) / (pinfo->src.len + 2) * (pinfo->src.len + 1);
269 saneEnd = message_end - ((message_end - offset) % (pinfo->src.len + 2));
270 while (field2Ptr < saneEnd) {
271 if (pinfo->src.type == AT_IPv4) {
272 proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
274 } else if (pinfo->src.type == AT_IPv6) {
275 proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
278 break; /* unknown address type should be handled in dissect_olsr, just be sure */
281 proto_tree_add_item(olsr_tree, hf_nrlolsr_f1, tvb, field1Ptr++, 1, ENC_BIG_ENDIAN);
282 proto_tree_add_item(olsr_tree, hf_nrlolsr_f2, tvb, field2Ptr++, 1, ENC_BIG_ENDIAN);
287 /*------------------------- Hello Dissecting Code-------------------------*/
288 static int dissect_olsr_hello(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end,
289 int(*handleNeighbors)(tvbuff_t *, packet_info *, proto_tree *, int, int)) {
292 proto_tree *link_type_tree;
294 guint16 message_size = 0;
296 if (message_end - offset < 4) {
297 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
298 "Not enough bytes for Hello");
304 /*---------------------Dissect Hello Emission Invertal-------------------*/
305 hTime = getOlsrTime(tvb_get_guint8(tvb, offset));
306 proto_tree_add_double_format_value(olsr_tree, hf_olsr_htime, tvb, offset, 1, hTime,
307 "%.3f (in seconds)", hTime);
310 /*-------------------------Dissect Willingness---------------------------*/
311 proto_tree_add_item(olsr_tree, hf_olsr_willingness, tvb, offset++, 1, ENC_BIG_ENDIAN);
313 while (offset < message_end) {
314 if (message_end - offset < 4) {
315 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
316 "Not enough bytes for last Hello entry");
320 /*------------------------------Dissect Link Type---------------------------------- */
321 ti = proto_tree_add_item(olsr_tree, hf_olsr_link_type, tvb, offset++, 1, ENC_BIG_ENDIAN);
322 link_type_tree = proto_item_add_subtree(ti, ett_olsr_message_linktype);
327 /*----------------------Dissect Link Message Size--------------------------*/
328 message_size = tvb_get_ntohs(tvb, offset);
329 ti = proto_tree_add_item(link_type_tree, hf_olsr_link_message_size, tvb, offset, 2, ENC_BIG_ENDIAN);
332 if (message_size < 4) {
333 proto_item_append_string(ti, "(too short, must be >= 4)");
336 offset = handleNeighbors(tvb, pinfo, link_type_tree, offset, offset + message_size - 4);
341 static int handle_olsr_hello_rfc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
342 int link_message_end) {
343 /*-------------------Dissect Neighbor Addresses--------------------*/
344 while (offset < link_message_end) {
345 if (link_message_end - offset < pinfo->src.len) {
346 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, link_message_end - offset,
347 "Not enough bytes for last Hello entry");
348 return link_message_end;
350 if (pinfo->src.type == AT_IPv4) {
351 proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
353 } else if (pinfo->src.type == AT_IPv6) {
354 proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
357 break; /* unknown address type should be handled in dissect_olsr, just be sure */
360 return link_message_end;
363 static int handle_olsr_hello_olsrorg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
364 int link_message_end) {
365 /*-------------------Dissect Neighbor Addresses--------------------*/
367 while (offset < link_message_end) {
368 proto_item *address_group;
369 proto_tree *address_tree;
372 if (link_message_end - offset < pinfo->src.len + 4) {
373 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, link_message_end - offset,
374 "Not enough bytes for last Olsr.org LQ-Hello entry");
375 return link_message_end;
378 if (pinfo->src.type == AT_IPv4) {
379 lq = tvb_get_guint8(tvb, offset + 4);
380 nlq = tvb_get_guint8(tvb, offset + 5);
382 address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 8,
383 NULL, "%s (%d/%d)", tvb_ip_to_str(tvb, offset), lq, nlq);
385 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
387 proto_tree_add_item(address_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
389 } else if (pinfo->src.type == AT_IPv6) {
390 lq = tvb_get_guint8(tvb, offset + 16);
391 nlq = tvb_get_guint8(tvb, offset + 17);
393 address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 20,
394 NULL, "%s (%d/%d)", tvb_ip6_to_str(tvb, offset), lq, nlq);
396 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
398 proto_tree_add_item(address_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
401 break; /* unknown address type should be handled in dissect_olsr, just be sure */
404 proto_tree_add_item(address_tree, hf_olsrorg_lq, tvb, offset++, 1, ENC_BIG_ENDIAN);
405 proto_tree_add_item(address_tree, hf_olsrorg_nlq, tvb, offset++, 1, ENC_BIG_ENDIAN);
408 return link_message_end;
411 /*------------------------- MID Dissecting Code-------------------------*/
412 static int dissect_olsr_mid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
413 while (offset < message_end) {
414 if (message_end - offset < pinfo->src.len) {
415 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
416 "Not enough bytes for last MID entry");
419 if (pinfo->src.type == AT_IPv4) {
420 proto_tree_add_item(olsr_tree, hf_olsr_interface_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
422 } else if (pinfo->src.type == AT_IPv6) {
423 proto_tree_add_item(olsr_tree, hf_olsr_interface6_addr, tvb, offset, 16, ENC_NA);
426 break; /* unknown address type should be handled in dissect_olsr, just be sure */
428 } /* end while for MID */
432 /*------------------------- HNA Dissecting Code-------------------------*/
433 static int dissect_olsr_hna(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
434 while (offset < message_end) {
435 if (message_end - offset < pinfo->src.len * 2) {
436 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
437 "Not enough bytes for last HNA entry");
441 if (pinfo->src.type == AT_IPv4) {
442 proto_tree_add_item(olsr_tree, hf_olsr_network_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
444 proto_tree_add_item(olsr_tree, hf_olsr_netmask, tvb, offset, 4, ENC_BIG_ENDIAN);
446 } else if (pinfo->src.type == AT_IPv6) {
447 proto_tree_add_item(olsr_tree, hf_olsr_network6_addr, tvb, offset, 4, ENC_NA);
449 proto_tree_add_item(olsr_tree, hf_olsr_netmask6, tvb, offset, 4, ENC_NA);
452 break; /* unknown address type should be handled in dissect_olsr, just be sure */
454 } /* end while for HNA */
458 /*------------------------- MID Dissecting Code-------------------------*/
459 static int dissect_olsrorg_nameservice(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
461 guint16 version, count;
463 proto_item *olsr_ns_item, *ti;
464 proto_tree *olsr_ns_tree;
466 if (message_end - offset < 4) {
467 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
468 "Not enough bytes for Olsr.org Nameservice message");
472 version = tvb_get_ntohs(tvb, offset);
473 ti = proto_tree_add_item(olsr_tree, hf_olsrorg_ns_version, tvb, offset, 2, ENC_BIG_ENDIAN);
475 count = tvb_get_ntohs(tvb, offset + 2);
476 proto_tree_add_item(olsr_tree, hf_olsrorg_ns_count, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
482 expert_add_info(pinfo, ti, &ei_olsrorg_ns_version);
483 proto_tree_add_item(olsr_tree, hf_olsr_data, tvb, offset, message_end - offset, ENC_NA);
487 while (offset < message_end && count-- > 0) {
488 guint16 type, length;
491 if (message_end - offset < 20) {
492 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
493 "Not enough bytes for last nameservice entry");
497 type = tvb_get_ntohs(tvb, offset);
498 length = tvb_get_ntohs(tvb, offset + 2);
500 total_length = 4 + 16 + ((length - 1) | 3) + 1;
502 olsr_ns_item = proto_tree_add_bytes_format_value(olsr_tree, hf_olsrorg_ns, tvb, offset, total_length,
503 NULL, "%s (%d)", val_to_str_const(type, nameservice_type_vals, "UNKNOWN"), type);
505 olsr_ns_tree = proto_item_add_subtree(olsr_ns_item, ett_olsr_message_ns);
507 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_type, tvb, offset, 2, ENC_BIG_ENDIAN);
508 proto_tree_add_uint(olsr_ns_tree, hf_olsrorg_ns_length, tvb, offset + 2, 2, length);
510 if (pinfo->src.type == AT_IPv4) {
511 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_ip, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
512 } else if (pinfo->src.type == AT_IPv6) {
513 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_ip6, tvb, offset + 4, 16, ENC_NA);
515 break; /* unknown address type should be handled in dissect_olsr, just be sure */
518 if (message_end - offset < total_length) {
519 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
520 "Not enough bytes for content of last nameservice entry");
523 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_content, tvb, offset + 20, length, ENC_ASCII|ENC_NA);
524 offset += 4 + 16 + ((length - 1) | 3) + 1;
529 /*------------------------- Packet Dissecting Code-------------------------*/
530 static int dissect_olsr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
532 proto_tree *olsr_tree;
534 int offset, message_len, message_end;
540 /* Does this packet have a valid message type at the beginning? */
541 if (tvb_length(tvb) < 4) {
542 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR Packet, Length: %u Bytes (not enough data in packet)",
544 return 0; /* not enough bytes for the packet length */
546 packet_len = tvb_get_ntohs(tvb, 0);
547 if (packet_len > tvb_length(tvb)) {
548 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR Packet, Length: %u Bytes (not enough data in packet)", packet_len);
551 /*-------------Setting the Protocol and Info Columns in the Wireshark Display----------*/
552 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OLSR v1");
553 col_clear(pinfo->cinfo, COL_INFO);
555 if ((pinfo->src.type != AT_IPv4) && (pinfo->src.type != AT_IPv6)) {
556 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (unknown address type) Packet, Length: %u Bytes", packet_len);
559 if (pinfo->src.type == AT_IPv4) {
560 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (IPv4) Packet, Length: %u Bytes", packet_len);
561 } else if (pinfo->src.type == AT_IPv6) {
562 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (IPv6) Packet, Length: %u Bytes", packet_len);
565 /*-----------------Fetching Info from IP Packet and Adding to Tree------------------------*/
566 ti = proto_tree_add_item(tree, proto_olsr, tvb, 0, -1, ENC_NA);
567 olsr_tree = proto_item_add_subtree(ti, ett_olsr);
569 proto_tree_add_item(olsr_tree, hf_olsr_packet_len, tvb, 0, 2, ENC_BIG_ENDIAN);
570 proto_tree_add_item(olsr_tree, hf_olsr_packet_seq_num, tvb, 2, 2, ENC_BIG_ENDIAN);
574 while (offset < packet_len) {
575 proto_item *message_item;
576 proto_tree *message_tree;
578 if (packet_len - offset < 4) {
579 proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, packet_len - offset,
580 "Message too short !");
584 message_type = tvb_get_guint8(tvb, offset);
585 vTime = getOlsrTime(tvb_get_guint8(tvb, offset + 1));
586 message_len = tvb_get_ntohs(tvb, offset + 2);
588 message_item = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_message, tvb, offset, message_len,
589 NULL, "%s (%d)", val_to_str_const(message_type, message_type_vals, "UNKNOWN"),
591 message_tree = proto_item_add_subtree(message_item, ett_olsr_message[message_type]);
593 proto_tree_add_uint(message_tree, hf_olsr_message_type, tvb, offset, 1, message_type);
596 /*-------------Dissect Validity Time-------------------------*/
597 proto_tree_add_double_format_value(message_tree, hf_olsr_vtime, tvb, offset, 1, vTime,
598 "%.3f (in seconds)", vTime);
601 /*-------------Dissect Message Size---------------------------*/
602 ti = proto_tree_add_item(message_tree, hf_olsr_message_size, tvb, offset, 2, ENC_BIG_ENDIAN);
605 if (message_len < 8 + pinfo->src.len) {
606 proto_item_append_text(ti, "(too short, must be >= %d)", 8 + pinfo->src.len);
610 message_end = offset + message_len - 4;
611 if (message_end > packet_len) {
612 proto_item_append_string(ti, "(not enough data for message)");
616 /*-----------------Dissecting: Origin Addr, TTL, Hop Count, and Message Seq Number*/
617 if (pinfo->src.type == AT_IPv4) {
618 proto_tree_add_item(message_tree, hf_olsr_origin_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
620 } else if (pinfo->src.type == AT_IPv6) {
621 proto_tree_add_item(message_tree, hf_olsr_origin6_addr, tvb, offset, 16, ENC_NA);
624 break; /* unknown address type should be handled before this loop, just be sure */
627 proto_tree_add_item(message_tree, hf_olsr_ttl, tvb, offset, 1, ENC_BIG_ENDIAN);
628 proto_tree_add_item(message_tree, hf_olsr_hop_count, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
629 proto_tree_add_item(message_tree, hf_olsr_message_seq_num, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
632 if (offset < message_end) {
633 /* --------------Dissecting TC message--------------------- */
634 if (message_type == TC) {
635 dissect_olsr_tc(tvb, pinfo, message_tree, offset, message_end);
637 /* -------------Dissect HELLO message----------------------- */
638 else if (message_type == HELLO) {
639 dissect_olsr_hello(tvb, pinfo, message_tree, offset, message_end, &handle_olsr_hello_rfc);
641 /*---------------------------------Dissect MID Message----------------------------------*/
642 else if (message_type == MID) {
643 dissect_olsr_mid(tvb, pinfo, message_tree, offset, message_end);
645 /*-----------------------------Dissect HNA Message--------------------------------*/
646 else if (message_type == HNA) {
647 dissect_olsr_hna(tvb, pinfo, message_tree, offset, message_end);
649 /*-----------------------------Dissect Olsr.org Hello Message--------------------------------*/
650 else if (global_olsr_olsrorg && message_type == OLSR_ORG_LQ_HELLO) {
651 dissect_olsr_hello(tvb, pinfo, message_tree, offset, message_end, &handle_olsr_hello_olsrorg);
653 /*-----------------------------Dissect Olsr.org TC Message--------------------------------*/
654 else if (global_olsr_olsrorg && message_type == OLSR_ORG_LQ_TC) {
655 dissect_olsrorg_lq_tc(tvb, pinfo, message_tree, offset, message_end);
658 /*-----------------------------Dissect Olsr.org NS Message--------------------------------*/
659 else if (global_olsr_olsrorg && message_type == OLSR_ORG_NAMESERVICE) {
660 dissect_olsrorg_nameservice(tvb, pinfo, message_tree, offset, message_end);
662 /*-----------------------Dissect NRL OLSR TC Message-------------------------------------*/
663 else if (global_olsr_nrlolsr && message_type == NRLOLSR_TC_EXTRA) {
664 dissect_nrlolsr_tc(tvb, pinfo, message_tree, offset, message_end);
667 /*-----------------------------Undefined message types-----------------------------*/
669 ti = proto_tree_add_bytes_format(message_tree, hf_olsr_data, tvb, offset, message_len - 12,
670 NULL, "Data (%u bytes)", message_len - 12);
671 if ((message_len - 12) % 4) {
672 expert_add_info(pinfo, ti, &ei_olsr_data_misaligned);
675 /*offset += message_len - 12;*/
676 } /* end if for undefined message types */
678 offset = message_end;
679 } /* end while for message alive */
681 return tvb_length(tvb);
682 } /* end Dissecting */
684 /*-----------Register the Dissector for OLSR--------------*/
685 void proto_register_olsr(void) {
686 static hf_register_info hf[] = {
687 { &hf_olsr_packet_len,
688 { "Packet Length", "olsr.packet_len",
689 FT_UINT16, BASE_DEC, NULL, 0,
690 "Packet Length in Bytes", HFILL
694 { &hf_olsr_packet_seq_num,
695 { "Packet Sequence Number", "olsr.packet_seq_num",
696 FT_UINT16, BASE_DEC, NULL, 0,
702 { "Message", "olsr.message",
703 FT_BYTES, BASE_NONE, NULL, 0,
708 { &hf_olsr_message_type,
709 { "Message Type", "olsr.message_type",
710 FT_UINT8, BASE_DEC, VALS(message_type_vals), 0,
715 { &hf_olsr_message_size,
716 { "Message", "olsr.message_size",
717 FT_UINT16, BASE_DEC, NULL, 0,
718 "Message Size in Bytes", HFILL
722 { &hf_olsr_message_seq_num,
723 { "Message Sequence Number", "olsr.message_seq_num",
724 FT_UINT16, BASE_DEC, NULL, 0,
730 { "Validity Time", "olsr.vtime",
731 FT_DOUBLE, BASE_NONE, NULL, 0,
732 "Validity Time in seconds", HFILL
737 { "Advertised Neighbor Sequence Number (ANSN)", "olsr.ansn",
738 FT_UINT16, BASE_DEC, NULL, 0,
744 { "Hello Emission Interval", "olsr.htime",
745 FT_DOUBLE, BASE_NONE, NULL, 0,
746 "Hello emission interval in seconds", HFILL
750 { &hf_olsr_willingness,
751 { "Willingness to forward messages", "olsr.willingness",
752 FT_UINT8, BASE_DEC, VALS(willingness_type_vals), 0,
759 FT_UINT8, BASE_DEC, NULL, 0,
760 "Time to Live in hops", HFILL
764 { &hf_olsr_link_type,
765 { "Link Type", "olsr.link_type",
766 FT_UINT8, BASE_DEC, VALS(link_type_vals), 0,
771 { &hf_olsr_link_message_size,
772 { "Link Message Size", "olsr.link_message_size",
773 FT_UINT16, BASE_DEC, NULL, 0,
774 "Link Message Size in bytes", HFILL
778 { &hf_olsr_hop_count,
779 { "Hop Count", "olsr.hop_count",
780 FT_UINT8, BASE_DEC, NULL, 0,
786 { "Neighbor Address", "olsr.neighbor",
787 FT_BYTES, BASE_NONE, NULL, 0,
792 { &hf_olsr_origin_addr,
793 { "Originator Address", "olsr.origin_addr",
794 FT_IPv4, BASE_NONE, NULL, 0,
799 { &hf_olsr_neighbor_addr,
800 { "Neighbor Address", "olsr.neighbor_addr",
801 FT_IPv4, BASE_NONE, NULL, 0,
806 { &hf_olsr_network_addr,
807 { "Network Address", "olsr.network_addr",
808 FT_IPv4, BASE_NONE, NULL, 0,
813 { &hf_olsr_interface_addr,
814 { "Interface Address", "olsr.interface_addr",
815 FT_IPv4, BASE_NONE, NULL, 0,
821 { "Netmask", "olsr.netmask",
822 FT_IPv4, BASE_NONE, NULL, 0,
828 { &hf_olsr_neighbor6,
829 { "Neighbor Address", "olsr.neighbor6",
830 FT_BYTES, BASE_NONE, NULL, 0,
836 { &hf_olsr_origin6_addr,
837 { "Originator Address", "olsr.origin6_addr",
838 FT_IPv6, BASE_NONE, NULL, 0,
843 { &hf_olsr_neighbor6_addr,
844 { "Neighbor Address", "olsr.neighbor6_addr",
845 FT_IPv6, BASE_NONE, NULL, 0,
850 { &hf_olsr_network6_addr,
851 { "Network Address", "olsr.network6_addr",
852 FT_IPv6, BASE_NONE, NULL, 0,
857 { &hf_olsr_interface6_addr,
858 { "Interface Address", "olsr.interface6_addr",
859 FT_IPv6, BASE_NONE, NULL, 0,
865 { "Netmask", "olsr.netmask6",
866 FT_IPv6, BASE_NONE, NULL, 0,
872 { "Data", "olsr.data",
873 FT_BYTES, BASE_NONE, NULL, 0,
880 FT_UINT8, BASE_DEC, NULL, 0,
881 "Link quality", HFILL
886 FT_UINT8, BASE_DEC, NULL, 0,
887 "Neighbor link quality", HFILL
892 { "Nameservice", "olsr.ns",
893 FT_BYTES, BASE_NONE, NULL, 0,
897 { &hf_olsrorg_ns_version,
898 { "Version", "olsr.ns.version",
899 FT_UINT16, BASE_DEC, NULL, 0,
903 { &hf_olsrorg_ns_count,
904 { "Count", "olsr.ns.count",
905 FT_UINT16, BASE_DEC, NULL, 0,
906 "Number of nameservice messages", HFILL
909 { &hf_olsrorg_ns_type,
910 { "Message Type", "olsr.ns.type",
911 FT_UINT16, BASE_DEC, VALS(nameservice_type_vals), 0,
915 { &hf_olsrorg_ns_length,
916 { "Length", "olsr.ns.length",
917 FT_UINT16, BASE_DEC, NULL, 0,
922 { "Address", "olsr.ns.ip",
923 FT_IPv4, BASE_NONE, NULL, 0,
927 { &hf_olsrorg_ns_ip6,
928 { "Address", "olsr.ns.ip6",
929 FT_IPv6, BASE_NONE, NULL, 0,
933 { &hf_olsrorg_ns_content,
934 { "Content", "olsr.ns.content",
935 FT_STRING, BASE_NONE, NULL, 0,
941 { "NRL MINMAX", "olsr.nrl.minmax",
942 FT_UINT8, BASE_DEC, NULL, 0,
947 { "NRL SPF", "olsr.nrl.spf",
948 FT_UINT8, BASE_DEC, NULL, 0,
954 static gint *ett_base[] = {
956 &ett_olsr_message_linktype,
957 &ett_olsr_message_neigh,
958 &ett_olsr_message_neigh6,
962 static ei_register_info ei[] = {
963 { &ei_olsr_not_enough_bytes, { "olsr.not_enough_bytes", PI_MALFORMED, PI_ERROR, "Not enough bytes for field", EXPFILL }},
964 { &ei_olsrorg_ns_version, { "olsr.ns.version.unknown", PI_PROTOCOL, PI_WARN, "Unknown nameservice protocol version", EXPFILL }},
965 { &ei_olsr_data_misaligned, { "olsr.data.misaligned", PI_PROTOCOL, PI_WARN, "Must be aligned on 32 bits", EXPFILL }},
968 gint *ett[array_length(ett_base) + (G_MAXUINT8+1)];
970 module_t *olsr_module;
971 expert_module_t *expert_olsr;
974 memcpy(ett, ett_base, sizeof(ett_base));
975 j = array_length(ett_base);
976 for (i=0; i<G_MAXUINT8+1; i++) {
977 ett_olsr_message[i] = -1;
978 ett[j++] = &ett_olsr_message[i];
981 proto_olsr = proto_register_protocol("Optimized Link State Routing Protocol", "OLSR", "olsr");
983 proto_register_field_array(proto_olsr, hf, array_length(hf));
984 proto_register_subtree_array(ett, array_length(ett));
985 expert_olsr = expert_register_protocol(proto_olsr);
986 expert_register_field_array(expert_olsr, ei, array_length(ei));
988 olsr_module = prefs_register_protocol(proto_olsr, NULL);
989 prefs_register_bool_preference(olsr_module, "ff_olsrorg",
990 "Dissect olsr.org messages","Dissect custom olsr.org message types (compatible with rfc routing agents)",
991 &global_olsr_olsrorg);
992 prefs_register_bool_preference(olsr_module, "nrlolsr",
993 "Dissect NRL-Olsr TC messages", "Dissect custom nrlolsr tc message (incompatible with rfc routing agents)",
994 &global_olsr_nrlolsr);
997 void proto_reg_handoff_olsr(void) {
998 dissector_handle_t olsr_handle;
1000 olsr_handle = new_create_dissector_handle(dissect_olsr, proto_olsr);
1001 dissector_add_uint("udp.port", UDP_PORT_OLSR, olsr_handle);
1010 * indent-tabs-mode: nil
1013 * ex: set shiftwidth=2 tabstop=8 expandtab:
1014 * :indentSize=2:tabSize=8:noTabs=true: