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
14 * Wireshark - Network traffic analyzer
15 * By Gerald Combs <gerald@wireshark.org>
16 * Copyright 1998 Gerald Combs
18 * This program is free software; you can redistribute it and/or
19 * modify it under the terms of the GNU General Public License
20 * as published by the Free Software Foundation; either version 2
21 * of the License, or (at your option) any later version.
23 * This program is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with this program; if not, write to the Free Software
30 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
40 #ifdef HAVE_SYS_TYPES_H
41 # include <sys/types.h>
44 #ifdef HAVE_NETINET_IN_H
45 # include <netinet/in.h>
50 #include <epan/packet.h>
51 #include <epan/prefs.h>
53 #define UDP_PORT_OLSR 698
59 #define OLSR_ORG_NAMESERVICE 130
60 #define OLSR_ORG_LQ_HELLO 201
61 #define OLSR_ORG_LQ_TC 202
62 #define NRLOLSR_TC_EXTRA 241
64 /* Initialize the protocol and registered fields */
65 static int proto_olsr = -1;
67 static int hf_olsr_packet_len = -1;
68 static int hf_olsr_packet_seq_num = -1;
70 static int hf_olsr_message = -1;
71 static int hf_olsr_message_type = -1;
72 static int hf_olsr_vtime = -1;
73 static int hf_olsr_message_size = -1;
74 static int hf_olsr_ttl = -1;
75 static int hf_olsr_hop_count = -1;
76 static int hf_olsr_message_seq_num = -1;
78 static int hf_olsr_htime = -1;
79 static int hf_olsr_willingness = -1;
81 static int hf_olsr_link_type = -1;
82 static int hf_olsr_link_message_size = -1;
83 static int hf_olsr_ansn = -1;
85 static int hf_olsr_neighbor = -1;
86 static int hf_olsr_origin_addr = -1;
87 static int hf_olsr_neighbor_addr = -1;
88 static int hf_olsr_interface_addr = -1;
89 static int hf_olsr_netmask = -1;
90 static int hf_olsr_network_addr = -1;
92 static int hf_olsr_neighbor6 = -1;
93 static int hf_olsr_origin6_addr = -1;
94 static int hf_olsr_neighbor6_addr = -1;
95 static int hf_olsr_interface6_addr = -1;
96 static int hf_olsr_netmask6 = -1;
97 static int hf_olsr_network6_addr = -1;
99 static int hf_olsrorg_lq = -1;
100 static int hf_olsrorg_nlq = -1;
101 static int hf_nrlolsr_f1 = -1;
102 static int hf_nrlolsr_f2 = -1;
104 static int hf_olsrorg_ns_version = -1;
105 static int hf_olsrorg_ns_count = -1;
107 static int hf_olsrorg_ns = -1;
108 static int hf_olsrorg_ns_type = -1;
109 static int hf_olsrorg_ns_length = -1;
110 static int hf_olsrorg_ns_ip = -1;
111 static int hf_olsrorg_ns_ip6 = -1;
112 static int hf_olsrorg_ns_content = -1;
114 static int hf_olsr_data = -1;
116 /* Initialize the subtree pointers*/
117 static gint ett_olsr = -1;
118 static gint ett_olsr_message[G_MAXUINT8 + 1];
119 static gint ett_olsr_message_linktype = -1;
120 static gint ett_olsr_message_neigh = -1;
121 static gint ett_olsr_message_neigh6 = -1;
122 static gint ett_olsr_message_ns = -1;
124 static const value_string message_type_vals[] = {
129 { OLSR_ORG_LQ_HELLO, "HELLO (LQ, olsr.org)" },
130 { OLSR_ORG_LQ_TC, "TC (LQ, olsr.org)" },
131 { OLSR_ORG_NAMESERVICE, "Nameservice (olsr.org)" },
132 { NRLOLSR_TC_EXTRA, "TC (LQ, nrlolsr)" },
136 static const value_string link_type_vals[] = {
137 { 0, "Unspecified Link" },
138 { 1, "Asymmetric Link" },
140 { 5, "Pending Link" },
141 { 6, "Symmetric Link" },
146 static const value_string willingness_type_vals[] = {
152 static const value_string nameservice_type_vals[] = {
160 static gboolean global_olsr_olsrorg = TRUE;
161 static gboolean global_olsr_nrlolsr = TRUE;
163 static double getOlsrTime(guint8 timeval) {
164 int high_bits, low_bits;
166 high_bits = ((timeval & 0xF0) >> 4);
167 low_bits = (timeval & 0x0F);
168 return ((1 << low_bits) / 16.0) * (1 + (high_bits / 16.0));
171 /*------------------------- TC Dissecting Code-------------------------*/
172 static int dissect_olsr_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
173 if (message_end - offset < 4) {
174 proto_tree_add_bytes_format(olsr_tree, hf_olsr_ansn, tvb, offset, message_end - offset,
175 NULL, "Not enough bytes for TC");
179 proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, FALSE);
182 while (offset < message_end) {
183 if (message_end - offset < pinfo->src.len) {
184 proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, message_end - offset,
185 NULL, "Not enough bytes for last neighbor");
188 if (pinfo->src.type == AT_IPv4) {
189 proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, FALSE);
191 } else if (pinfo->src.type == AT_IPv6) {
192 proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, FALSE);
195 break; /* unknown address type should be handled in dissect_olsr, just be sure */
201 static int dissect_olsrorg_lq_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
203 if (message_end - offset < 4) {
204 proto_tree_add_bytes_format(olsr_tree, hf_olsr_ansn, tvb, offset, message_end - offset,
205 NULL, "Not enough bytes for Olsr.org LQ-TC");
208 proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, FALSE);
211 while (offset < message_end) {
212 proto_item *address_group;
213 proto_tree *address_tree;
216 if (pinfo->src.type == AT_IPv4) {
217 if (message_end - offset < 8) {
218 proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, message_end - offset,
219 NULL, "Not enough bytes for last entry (need 8 bytes)");
222 lq = tvb_get_guint8(tvb, offset + 4);
223 nlq = tvb_get_guint8(tvb, offset + 5);
225 address_group = proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, 8,
226 NULL, "Neighbor Address: %s (%d/%d)", tvb_ip_to_str(tvb, offset), lq, nlq);
228 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
230 proto_tree_add_item(address_tree, hf_olsr_neighbor_addr, tvb, offset, 4, FALSE);
232 } else if (pinfo->src.type == AT_IPv6) {
233 if (message_end - offset < 20) {
234 proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, message_end - offset,
235 NULL, "Not enough bytes for last entry (need 20 bytes)");
238 lq = tvb_get_guint8(tvb, offset + 16);
239 nlq = tvb_get_guint8(tvb, offset + 17);
241 address_group = proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, 20,
242 NULL, "Neighbor Address: %s (%d/%d)", tvb_ip6_to_str(tvb, offset), lq, nlq);
244 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
246 proto_tree_add_item(address_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, FALSE);
249 break; /* unknown address type should be handled in dissect_olsr, just be sure */
252 proto_tree_add_item(address_tree, hf_olsrorg_lq, tvb, offset++, 1, FALSE);
253 proto_tree_add_item(address_tree, hf_olsrorg_nlq, tvb, offset++, 1, FALSE);
259 static int dissect_nrlolsr_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
260 int field1Ptr, field2Ptr, saneEnd;
261 if (message_end - offset < 4) {
262 proto_tree_add_bytes_format(olsr_tree, hf_olsr_ansn, tvb, offset, message_end - offset,
263 NULL, "Not enough bytes for NRLOLSR LQ-TC");
267 proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, FALSE);
270 field1Ptr = offset + (message_end - offset) / (pinfo->src.len + 2) * (pinfo->src.len);
271 field2Ptr = offset + (message_end - offset) / (pinfo->src.len + 2) * (pinfo->src.len + 1);
273 saneEnd = message_end - ((message_end - offset) % (pinfo->src.len + 2));
274 while (field2Ptr < saneEnd) {
275 if (pinfo->src.type == AT_IPv4) {
276 proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, FALSE);
278 } else if (pinfo->src.type == AT_IPv6) {
279 proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, FALSE);
282 break; /* unknown address type should be handled in dissect_olsr, just be sure */
285 proto_tree_add_item(olsr_tree, hf_nrlolsr_f1, tvb, field1Ptr++, 1, FALSE);
286 proto_tree_add_item(olsr_tree, hf_nrlolsr_f2, tvb, field2Ptr++, 1, FALSE);
291 /*------------------------- Hello Dissecting Code-------------------------*/
292 static int dissect_olsr_hello(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end,
293 int(*handleNeighbors)(tvbuff_t *, packet_info *, proto_tree *, int, int)) {
296 proto_tree *link_type_tree;
298 guint16 message_size = 0;
300 if (message_end - offset < 4) {
301 proto_tree_add_bytes_format(olsr_tree, hf_olsr_htime, tvb, offset, message_end - offset,
302 NULL, "Not enough bytes for Hello");
308 /*---------------------Dissect Hello Emission Invertal-------------------*/
309 hTime = getOlsrTime(tvb_get_guint8(tvb, offset));
310 proto_tree_add_double_format(olsr_tree, hf_olsr_htime, tvb, offset, 1, hTime,
311 "Hello Emission Interval: %.3f (in seconds)", hTime);
314 /*-------------------------Dissect Willingness---------------------------*/
315 proto_tree_add_item(olsr_tree, hf_olsr_willingness, tvb, offset++, 1, FALSE);
317 while (offset < message_end) {
318 if (message_end - offset < 4) {
319 proto_tree_add_bytes_format(olsr_tree, hf_olsr_link_type, tvb, offset, message_end - offset,
320 NULL, "Not enough bytes for last Hello entry");
324 /*------------------------------Dissect Link Type---------------------------------- */
325 ti = proto_tree_add_item(olsr_tree, hf_olsr_link_type, tvb, offset++, 1, FALSE);
326 link_type_tree = proto_item_add_subtree(ti, ett_olsr_message_linktype);
331 /*----------------------Dissect Link Message Size--------------------------*/
332 message_size = tvb_get_ntohs(tvb, offset);
333 ti = proto_tree_add_item(link_type_tree, hf_olsr_link_message_size, tvb, offset, 2, FALSE);
336 if (message_size < 4) {
337 proto_item_append_string(ti, "(too short, must be >= 4)");
340 offset = handleNeighbors(tvb, pinfo, link_type_tree, offset, offset + message_size - 4);
345 static int handle_olsr_hello_rfc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
346 int link_message_end) {
347 /*-------------------Dissect Neighbor Addresses--------------------*/
348 while (offset < link_message_end) {
349 if (link_message_end - offset < pinfo->src.len) {
350 proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, link_message_end - offset,
351 NULL, "Not enough bytes for last Hello entry");
352 return link_message_end;
354 if (pinfo->src.type == AT_IPv4) {
355 proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, FALSE);
357 } else if (pinfo->src.type == AT_IPv6) {
358 proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, FALSE);
361 break; /* unknown address type should be handled in dissect_olsr, just be sure */
364 return link_message_end;
367 static int handle_olsr_hello_olsrorg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
368 int link_message_end) {
369 /*-------------------Dissect Neighbor Addresses--------------------*/
371 while (offset < link_message_end) {
372 proto_item *address_group;
373 proto_tree *address_tree;
376 if (link_message_end - offset < pinfo->src.len + 4) {
377 proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, link_message_end - offset,
378 NULL, "Not enough bytes for last Olsr.org LQ-Hello entry");
379 return link_message_end;
382 if (pinfo->src.type == AT_IPv4) {
383 lq = tvb_get_guint8(tvb, offset + 4);
384 nlq = tvb_get_guint8(tvb, offset + 5);
386 address_group = proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, 8,
387 NULL, "Neighbor Address: %s (%d/%d)", tvb_ip_to_str(tvb, offset), lq, nlq);
389 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
391 proto_tree_add_item(address_tree, hf_olsr_neighbor_addr, tvb, offset, 4, FALSE);
393 } else if (pinfo->src.type == AT_IPv6) {
394 lq = tvb_get_guint8(tvb, offset + 16);
395 nlq = tvb_get_guint8(tvb, offset + 17);
397 address_group = proto_tree_add_bytes_format(olsr_tree, hf_olsr_neighbor, tvb, offset, 20,
398 NULL, "Neighbor Address: %s (%d/%d)", tvb_ip6_to_str(tvb, offset), lq, nlq);
400 address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
402 proto_tree_add_item(address_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, FALSE);
405 break; /* unknown address type should be handled in dissect_olsr, just be sure */
408 proto_tree_add_item(address_tree, hf_olsrorg_lq, tvb, offset++, 1, FALSE);
409 proto_tree_add_item(address_tree, hf_olsrorg_nlq, tvb, offset++, 1, FALSE);
412 return link_message_end;
415 /*------------------------- MID Dissecting Code-------------------------*/
416 static int dissect_olsr_mid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
417 while (offset < message_end) {
418 if (message_end - offset < pinfo->src.len) {
419 proto_tree_add_bytes_format(olsr_tree, hf_olsr_interface_addr, tvb, offset, message_end - offset,
420 NULL, "Not enough bytes for last MID entry");
423 if (pinfo->src.type == AT_IPv4) {
424 proto_tree_add_item(olsr_tree, hf_olsr_interface_addr, tvb, offset, 4, FALSE);
426 } else if (pinfo->src.type == AT_IPv6) {
427 proto_tree_add_item(olsr_tree, hf_olsr_interface6_addr, tvb, offset, 16, FALSE);
430 break; /* unknown address type should be handled in dissect_olsr, just be sure */
432 } /* end while for MID */
436 /*------------------------- HNA Dissecting Code-------------------------*/
437 static int dissect_olsr_hna(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
438 while (offset < message_end) {
439 if (message_end - offset < pinfo->src.len * 2) {
440 proto_tree_add_bytes_format(olsr_tree, hf_olsr_network_addr, tvb, offset, message_end - offset,
441 NULL, "Not enough bytes for last HNA entry");
445 if (pinfo->src.type == AT_IPv4) {
446 proto_tree_add_item(olsr_tree, hf_olsr_network_addr, tvb, offset, 4, FALSE);
448 proto_tree_add_item(olsr_tree, hf_olsr_netmask, tvb, offset, 4, FALSE);
450 } else if (pinfo->src.type == AT_IPv6) {
451 proto_tree_add_item(olsr_tree, hf_olsr_network6_addr, tvb, offset, 4, FALSE);
453 proto_tree_add_item(olsr_tree, hf_olsr_netmask6, tvb, offset, 4, FALSE);
456 break; /* unknown address type should be handled in dissect_olsr, just be sure */
458 } /* end while for HNA */
462 /*------------------------- MID Dissecting Code-------------------------*/
463 static int dissect_olsrorg_nameservice(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
465 guint16 version, count;
467 proto_item *olsr_ns_item;
468 proto_tree *olsr_ns_tree;
470 if (message_end - offset < 4) {
471 proto_tree_add_bytes_format(olsr_tree, hf_olsrorg_ns_version, tvb, offset, message_end - offset,
472 NULL, "Not enough bytes for Olsr.org Nameservice message");
476 version = tvb_get_ntohs(tvb, offset);
477 proto_tree_add_item(olsr_tree, hf_olsrorg_ns_version, tvb, offset, 2, FALSE);
479 count = tvb_get_ntohs(tvb, offset + 2);
480 proto_tree_add_item(olsr_tree, hf_olsrorg_ns_count, tvb, offset + 2, 2, FALSE);
485 proto_tree_add_bytes_format(olsr_tree, hf_olsr_data, tvb, offset, message_end - offset,
486 NULL, "Unkown nameservice protocol version %d", version);
490 while (offset < message_end && count-- > 0) {
491 guint16 type, length;
494 if (message_end - offset < 20) {
495 proto_tree_add_bytes_format(olsr_tree, hf_olsrorg_ns, tvb, offset, message_end - offset,
496 NULL, "Not enough bytes for last nameservice entry");
500 type = tvb_get_ntohs(tvb, offset);
501 length = tvb_get_ntohs(tvb, offset + 2);
503 total_length = 4 + 16 + ((length - 1) | 3) + 1;
505 olsr_ns_item = proto_tree_add_bytes_format(olsr_tree, hf_olsrorg_ns, tvb, offset, total_length,
506 NULL, "Nameservice: %s (%d)", val_to_str(type, nameservice_type_vals, "UNKNOWN"), type);
508 olsr_ns_tree = proto_item_add_subtree(olsr_ns_item, ett_olsr_message_ns);
510 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_type, tvb, offset, 2, FALSE);
511 proto_tree_add_uint(olsr_ns_tree, hf_olsrorg_ns_length, tvb, offset + 2, 2, length);
513 if (pinfo->src.type == AT_IPv4) {
514 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_ip, tvb, offset + 4, 4, FALSE);
515 } else if (pinfo->src.type == AT_IPv6) {
516 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_ip6, tvb, offset + 4, 16, FALSE);
518 break; /* unknown address type should be handled in dissect_olsr, just be sure */
521 if (message_end - offset < total_length) {
522 proto_tree_add_bytes_format(olsr_tree, hf_olsrorg_ns, tvb, offset, message_end - offset,
523 NULL, "Not enough bytes for content of last nameservice entry");
526 proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_content, tvb, offset + 20, length, FALSE);
527 offset += 4 + 16 + ((length - 1) | 3) + 1;
532 /*------------------------- Packet Dissecting Code-------------------------*/
533 static int dissect_olsr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree) {
535 proto_tree *olsr_tree;
537 int offset, message_len, message_end;
543 /* Does this packet have a valid message type at the beginning? */
544 if (tvb_length(tvb) < 4) {
545 if (check_col(pinfo->cinfo, COL_INFO)) {
546 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR Packet, Length: %u Bytes (not enough data in packet)",
549 return 0; /* not enough bytes for the packet length */
551 packet_len = tvb_get_ntohs(tvb, 0);
552 if (packet_len > tvb_length(tvb)) {
553 if (check_col(pinfo->cinfo, COL_INFO)) {
554 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR Packet, Length: %u Bytes (not enough data in packet)", packet_len);
558 /*-------------Setting the Protocol and Info Columns in the Wireshark Display----------*/
559 col_set_str(pinfo->cinfo, COL_PROTOCOL, "OLSR v1");
560 col_clear(pinfo->cinfo, COL_INFO);
562 if ((pinfo->src.type != AT_IPv4) && (pinfo->src.type != AT_IPv6)) {
563 if (check_col(pinfo->cinfo, COL_INFO)) {
564 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (unknown address type) Packet, Length: %u Bytes", packet_len);
568 if (check_col(pinfo->cinfo, COL_INFO) && (pinfo->src.type == AT_IPv4)) {
569 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (IPv4) Packet, Length: %u Bytes", packet_len);
570 } else if (check_col(pinfo->cinfo, COL_INFO) && (pinfo->src.type == AT_IPv6)) {
571 col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (IPv6) Packet, Length: %u Bytes", packet_len);
574 /*-----------------Fetching Info from IP Packet and Adding to Tree------------------------*/
576 ti = proto_tree_add_item(tree, proto_olsr, tvb, 0, -1, FALSE);
577 olsr_tree = proto_item_add_subtree(ti, ett_olsr);
579 proto_tree_add_item(olsr_tree, hf_olsr_packet_len, tvb, 0, 2, FALSE);
580 proto_tree_add_item(olsr_tree, hf_olsr_packet_seq_num, tvb, 2, 2, FALSE);
584 while (offset < packet_len) {
585 proto_item *message_item;
586 proto_tree *message_tree;
588 if (packet_len - offset < 4) {
589 proto_tree_add_bytes_format(olsr_tree, hf_olsr_message, tvb, offset, packet_len - offset,
590 NULL, "Message too short !");
594 message_type = tvb_get_guint8(tvb, offset);
595 vTime = getOlsrTime(tvb_get_guint8(tvb, offset + 1));
596 message_len = tvb_get_ntohs(tvb, offset + 2);
598 message_item = proto_tree_add_bytes_format(olsr_tree, hf_olsr_message, tvb, offset, message_len,
599 NULL, "Message: %s (%d)", val_to_str(message_type, message_type_vals, "UNKNOWN"),
601 message_tree = proto_item_add_subtree(message_item, ett_olsr_message[message_type]);
603 proto_tree_add_uint(message_tree, hf_olsr_message_type, tvb, offset, 1, message_type);
606 /*-------------Dissect Validity Time-------------------------*/
607 proto_tree_add_double_format(message_tree, hf_olsr_vtime, tvb, offset, 1, vTime,
608 "Validity Time: %.3f (in seconds)", vTime);
611 /*-------------Dissect Message Size---------------------------*/
612 ti = proto_tree_add_item(message_tree, hf_olsr_message_size, tvb, offset, 2, FALSE);
615 if (message_len < 8 + pinfo->src.len) {
616 proto_item_append_text(ti, "(too short, must be >= %d)", 8 + pinfo->src.len);
620 message_end = offset + message_len - 4;
621 if (message_end > packet_len) {
622 proto_item_append_string(ti, "(not enough data for message)");
626 /*-----------------Dissecting: Origin Addr, TTL, Hop Count, and Message Seq Number*/
627 if (pinfo->src.type == AT_IPv4) {
628 proto_tree_add_item(message_tree, hf_olsr_origin_addr, tvb, offset, 4, FALSE);
630 } else if (pinfo->src.type == AT_IPv6) {
631 proto_tree_add_item(message_tree, hf_olsr_origin6_addr, tvb, offset, 16, FALSE);
634 break; /* unknown address type should be handled before this loop, just be sure */
637 proto_tree_add_item(message_tree, hf_olsr_ttl, tvb, offset, 1, FALSE);
638 proto_tree_add_item(message_tree, hf_olsr_hop_count, tvb, offset + 1, 1, FALSE);
639 proto_tree_add_item(message_tree, hf_olsr_message_seq_num, tvb, offset + 2, 2, FALSE);
642 if (offset < message_end) {
643 /* --------------Dissecting TC message--------------------- */
644 if (message_type == TC) {
645 dissect_olsr_tc(tvb, pinfo, message_tree, offset, message_end);
647 /* -------------Dissect HELLO message----------------------- */
648 else if (message_type == HELLO) {
649 dissect_olsr_hello(tvb, pinfo, message_tree, offset, message_end, &handle_olsr_hello_rfc);
651 /*---------------------------------Dissect MID Message----------------------------------*/
652 else if (message_type == MID) {
653 dissect_olsr_mid(tvb, pinfo, message_tree, offset, message_end);
655 /*-----------------------------Dissect HNA Message--------------------------------*/
656 else if (message_type == HNA) {
657 dissect_olsr_hna(tvb, pinfo, message_tree, offset, message_end);
659 /*-----------------------------Dissect Olsr.org Hello Message--------------------------------*/
660 else if (global_olsr_olsrorg && message_type == OLSR_ORG_LQ_HELLO) {
661 dissect_olsr_hello(tvb, pinfo, message_tree, offset, message_end, &handle_olsr_hello_olsrorg);
663 /*-----------------------------Dissect Olsr.org TC Message--------------------------------*/
664 else if (global_olsr_olsrorg && message_type == OLSR_ORG_LQ_TC) {
665 dissect_olsrorg_lq_tc(tvb, pinfo, message_tree, offset, message_end);
668 /*-----------------------------Dissect Olsr.org NS Message--------------------------------*/
669 else if (global_olsr_olsrorg && message_type == OLSR_ORG_NAMESERVICE) {
670 dissect_olsrorg_nameservice(tvb, pinfo, message_tree, offset, message_end);
672 /*-----------------------Dissect NRL OLSR TC Message-------------------------------------*/
673 else if (global_olsr_nrlolsr && message_type == NRLOLSR_TC_EXTRA) {
674 dissect_nrlolsr_tc(tvb, pinfo, message_tree, offset, message_end);
677 /*-----------------------------Undefined message types-----------------------------*/
679 if ((message_len - 12) % 4) {
680 proto_tree_add_bytes_format(message_tree, hf_olsr_data, tvb, offset, message_len - 12,
681 NULL, "Data (%u bytes) (must be aligned on 32 bits)", message_len - 12);
684 proto_tree_add_bytes_format(message_tree, hf_olsr_data, tvb, offset, message_len - 12,
685 NULL, "Data (%u bytes)", message_len - 12);
686 offset += message_len - 12;
687 } /* end if for undefined message types */
689 offset = message_end;
690 } /* end while for message alive */
693 return tvb_length(tvb);
694 } /* end Dissecting */
696 /*-----------Register the Dissector for OLSR--------------*/
697 void proto_register_olsr(void) {
698 static hf_register_info hf[] = {
699 { &hf_olsr_packet_len,
700 { "Packet Length", "olsr.packet_len",
701 FT_UINT16, BASE_DEC, NULL, 0,
702 "Packet Length in Bytes", HFILL
706 { &hf_olsr_packet_seq_num,
707 { "Packet Sequence Number", "olsr.packet_seq_num",
708 FT_UINT16, BASE_DEC, NULL, 0,
714 { "Message", "olsr.message",
715 FT_BYTES, BASE_NONE, NULL, 0,
720 { &hf_olsr_message_type,
721 { "Message Type", "olsr.message_type",
722 FT_UINT8, BASE_DEC, VALS(message_type_vals), 0,
727 { &hf_olsr_message_size,
728 { "Message", "olsr.message_size",
729 FT_UINT16, BASE_DEC, NULL, 0,
730 "Message Size in Bytes", HFILL
734 { &hf_olsr_message_seq_num,
735 { "Message Sequence Number", "olsr.message_seq_num",
736 FT_UINT16, BASE_DEC, NULL, 0,
742 { "Validity Time", "olsr.vtime",
743 FT_DOUBLE, BASE_NONE, NULL, 0,
744 "Validity Time in seconds", HFILL
749 { "Advertised Neighbor Sequence Number (ANSN)", "olsr.ansn",
750 FT_UINT16, BASE_DEC, NULL, 0,
756 { "Hello emission interval", "olsr.htime",
757 FT_DOUBLE, BASE_NONE, NULL, 0,
758 "Hello emission interval in seconds", HFILL
762 { &hf_olsr_willingness,
763 { "Willingness to forward messages", "olsr.willingness",
764 FT_UINT8, BASE_DEC, VALS(willingness_type_vals), 0,
771 FT_UINT8, BASE_DEC, NULL, 0,
772 "Time to Live in hops", HFILL
776 { &hf_olsr_link_type,
777 { "Link Type", "olsr.link_type",
778 FT_UINT8, BASE_DEC, VALS(link_type_vals), 0,
783 { &hf_olsr_link_message_size,
784 { "Link Message Size", "olsr.link_message_size",
785 FT_UINT16, BASE_DEC, NULL, 0,
786 "Link Message Size in bytes", HFILL
790 { &hf_olsr_hop_count,
791 { "Hop Count", "olsr.hop_count",
792 FT_UINT8, BASE_DEC, NULL, 0,
798 { "Neighbor Address", "olsr.neighbor",
799 FT_BYTES, BASE_NONE, NULL, 0,
804 { &hf_olsr_origin_addr,
805 { "Originator Address", "olsr.origin_addr",
806 FT_IPv4, BASE_NONE, NULL, 0,
811 { &hf_olsr_neighbor_addr,
812 { "Neighbor Address", "olsr.neighbor_addr",
813 FT_IPv4, BASE_NONE, NULL, 0,
818 { &hf_olsr_network_addr,
819 { "Network Address", "olsr.network_addr",
820 FT_IPv4, BASE_NONE, NULL, 0,
825 { &hf_olsr_interface_addr,
826 { "Interface Address", "olsr.interface_addr",
827 FT_IPv4, BASE_NONE, NULL, 0,
833 { "Netmask", "olsr.netmask",
834 FT_IPv4, BASE_NONE, NULL, 0,
839 { &hf_olsr_neighbor6,
840 { "Neighbor Address", "olsr.neighbor6",
841 FT_BYTES, BASE_NONE, NULL, 0,
846 { &hf_olsr_origin6_addr,
847 { "Originator Address", "olsr.origin6_addr",
848 FT_IPv6, BASE_NONE, NULL, 0,
853 { &hf_olsr_neighbor6_addr,
854 { "Neighbor Address", "olsr.neighbor6_addr",
855 FT_IPv6, BASE_NONE, NULL, 0,
860 { &hf_olsr_network6_addr,
861 { "Network Address", "olsr.network6_addr",
862 FT_IPv6, BASE_NONE, NULL, 0,
867 { &hf_olsr_interface6_addr,
868 { "Interface Address", "olsr.interface6_addr",
869 FT_IPv6, BASE_NONE, NULL, 0,
875 { "Netmask", "olsr.netmask6",
876 FT_IPv6, BASE_NONE, NULL, 0,
882 { "Data", "olsr.data",
883 FT_BYTES, BASE_NONE, NULL, 0,
890 FT_UINT8, BASE_DEC, NULL, 0,
891 "Link quality", HFILL
896 FT_UINT8, BASE_DEC, NULL, 0,
897 "Neighbor link quality", HFILL
902 { "Nameservice message", "olsr.ns",
903 FT_BYTES, BASE_NONE, NULL, 0,
907 { &hf_olsrorg_ns_version,
908 { "Version", "olsr.ns.version",
909 FT_UINT16, BASE_DEC, NULL, 0,
913 { &hf_olsrorg_ns_count,
914 { "Count", "olsr.nlq",
915 FT_UINT16, BASE_DEC, NULL, 0,
916 "Number of nameservice messages", HFILL
919 { &hf_olsrorg_ns_type,
920 { "Message Type", "olsr.ns.type",
921 FT_UINT16, BASE_DEC, VALS(nameservice_type_vals), 0,
925 { &hf_olsrorg_ns_length,
926 { "Length", "olsr.ns.length",
927 FT_UINT16, BASE_DEC, NULL, 0,
932 { "Address", "olsr.ns.ip",
933 FT_IPv4, BASE_NONE, NULL, 0,
937 { &hf_olsrorg_ns_ip6,
938 { "Address", "olsr.ns.ip6",
939 FT_IPv6, BASE_NONE, NULL, 0,
943 { &hf_olsrorg_ns_content,
944 { "Content", "olsr.ns.content",
945 FT_STRING, BASE_NONE, NULL, 0,
951 { "NRL MINMAX", "olsr.nrl.minmax",
952 FT_UINT8, BASE_DEC, NULL, 0,
957 { "NRL SPF", "olsr.nrl.spf",
958 FT_UINT8, BASE_DEC, NULL, 0,
964 static gint *ett_base[] = {
966 &ett_olsr_message_linktype,
967 &ett_olsr_message_neigh,
968 &ett_olsr_message_neigh6,
972 gint *ett[array_length(ett_base) + (G_MAXUINT8+1)];
974 module_t *olsr_module;
977 memcpy(ett, ett_base, sizeof(ett_base));
978 j = array_length(ett_base);
979 for (i=0; i<G_MAXUINT8+1; i++) {
980 ett_olsr_message[i] = -1;
981 ett[j++] = &ett_olsr_message[i];
984 proto_olsr = proto_register_protocol("Optimized Link State Routing Protocol", "OLSR", "olsr");
986 proto_register_field_array(proto_olsr, hf, array_length(hf));
987 proto_register_subtree_array(ett, array_length(ett));
989 olsr_module = prefs_register_protocol(proto_olsr, NULL);
990 prefs_register_bool_preference(olsr_module, "ff_olsrorg",
991 "Dissect olsr.org messages","Dissect custom olsr.org message types (compatible with rfc routing agents)",
992 &global_olsr_olsrorg);
993 prefs_register_bool_preference(olsr_module, "nrlolsr",
994 "Dissect NRL-Olsr TC messages", "Dissect custom nrlolsr tc message (incompatible with rfc routing agents)",
995 &global_olsr_nrlolsr);
998 void proto_reg_handoff_olsr(void) {
999 dissector_handle_t olsr_handle;
1001 olsr_handle = new_create_dissector_handle(dissect_olsr, proto_olsr);
1002 dissector_add_uint("udp.port", UDP_PORT_OLSR, olsr_handle);