1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
|
/* packet-olsr.c
* Routines for OLSR (IPv4 & IPv6 compatible) RFC parsing
* Compatible with RFC-compliant OLSR implementations such as
* NRLOLSRD (http://pf.itd.nrl.navy.mil/projects/olsr/).
* Parser created by Aaron Woo <woo@itd.nrl.navy.mil> of
* the Naval Research Laboratory
* Currently maintained by Jeff Weston <weston@itd.nrl.navy.mil>.
*
* Updated to Olsr.org and NRLOLSR packages by Henning Rogge <rogge@fgan.de>
* https://www.ietf.org/rfc/rfc3626
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <epan/packet.h>
#include <epan/prefs.h>
#include <epan/expert.h>
#include <epan/to_str.h>
void proto_register_olsr(void);
void proto_reg_handoff_olsr(void);
static dissector_handle_t olsr_handle;
#define UDP_PORT_OLSR 698
#define HELLO 1
#define TC 2
#define MID 3
#define HNA 4
#define OLSR_ORG_NAMESERVICE 130
#define OLSR_ORG_LQ_HELLO 201
#define OLSR_ORG_LQ_TC 202
#define NRLOLSR_TC_EXTRA 241
/* Initialize the protocol and registered fields */
static int proto_olsr = -1;
static int hf_olsr_packet_len = -1;
static int hf_olsr_packet_seq_num = -1;
static int hf_olsr_message = -1;
static int hf_olsr_message_type = -1;
static int hf_olsr_vtime = -1;
static int hf_olsr_message_size = -1;
static int hf_olsr_ttl = -1;
static int hf_olsr_hop_count = -1;
static int hf_olsr_message_seq_num = -1;
static int hf_olsr_htime = -1;
static int hf_olsr_willingness = -1;
static int hf_olsr_link_type = -1;
static int hf_olsr_link_message_size = -1;
static int hf_olsr_ansn = -1;
static int hf_olsr_neighbor = -1;
static int hf_olsr_origin_addr = -1;
static int hf_olsr_neighbor_addr = -1;
static int hf_olsr_interface_addr = -1;
static int hf_olsr_netmask = -1;
static int hf_olsr_network_addr = -1;
/* static int hf_olsr_neighbor6 = -1; */
static int hf_olsr_origin6_addr = -1;
static int hf_olsr_neighbor6_addr = -1;
static int hf_olsr_interface6_addr = -1;
static int hf_olsr_netmask6 = -1;
static int hf_olsr_network6_addr = -1;
static int hf_olsrorg_lq = -1;
static int hf_olsrorg_nlq = -1;
static int hf_nrlolsr_f1 = -1;
static int hf_nrlolsr_f2 = -1;
static int hf_olsrorg_ns_version = -1;
static int hf_olsrorg_ns_count = -1;
static int hf_olsrorg_ns = -1;
static int hf_olsrorg_ns_type = -1;
static int hf_olsrorg_ns_length = -1;
static int hf_olsrorg_ns_ip = -1;
static int hf_olsrorg_ns_ip6 = -1;
static int hf_olsrorg_ns_content = -1;
static int hf_olsr_data = -1;
/* Initialize the subtree pointers*/
static gint ett_olsr = -1;
static gint ett_olsr_message[G_MAXUINT8 + 1];
static gint ett_olsr_message_linktype = -1;
static gint ett_olsr_message_neigh = -1;
static gint ett_olsr_message_neigh6 = -1;
static gint ett_olsr_message_ns = -1;
static expert_field ei_olsr_not_enough_bytes = EI_INIT;
static expert_field ei_olsrorg_ns_version = EI_INIT;
static expert_field ei_olsr_data_misaligned = EI_INIT;
static const value_string message_type_vals[] = {
{ HELLO, "HELLO" },
{ TC, "TC" },
{ MID, "MID" },
{ HNA, "HNA" },
{ OLSR_ORG_LQ_HELLO, "HELLO (LQ, olsr.org)" },
{ OLSR_ORG_LQ_TC, "TC (LQ, olsr.org)" },
{ OLSR_ORG_NAMESERVICE, "Nameservice (olsr.org)" },
{ NRLOLSR_TC_EXTRA, "TC (LQ, nrlolsr)" },
{ 0, NULL }
};
static const value_string link_type_vals[] = {
{ 0, "Unspecified Link" },
{ 1, "Asymmetric Link" },
{ 3, "Lost Link" },
{ 5, "Pending Link" },
{ 6, "Symmetric Link" },
{ 10, "MPR Link" },
{ 0, NULL }
};
static const value_string willingness_type_vals[] = {
{ 0, "never" },
{ 7, "always" },
{ 0, NULL }
};
static const value_string nameservice_type_vals[] = {
{ 0, "HOST" },
{ 1, "FORWARDER" },
{ 2, "SERVICE" },
{ 3, "LATLON" },
{ 0, NULL }
};
static gboolean global_olsr_olsrorg = TRUE;
static gboolean global_olsr_nrlolsr = TRUE;
static double getOlsrTime(guint8 timeval) {
int high_bits, low_bits;
high_bits = ((timeval & 0xF0) >> 4);
low_bits = (timeval & 0x0F);
return ((G_GUINT64_CONSTANT(1) << low_bits) / 16.0) * (1 + (high_bits / 16.0));
}
/*------------------------- TC Dissecting Code-------------------------*/
static int dissect_olsr_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for TC");
return message_end;
}
proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 4;
while (offset < message_end) {
if (message_end - offset < pinfo->src.len) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last neighbor");
return message_end;
}
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
}
return message_end;
}
static int dissect_olsrorg_lq_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for Olsr.org LQ-TC");
return message_end;
}
proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 4;
while (offset < message_end) {
proto_item *address_group;
proto_tree *address_tree;
guint8 lq, nlq;
if (pinfo->src.type == AT_IPv4) {
if (message_end - offset < 8) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last entry (need 8 bytes)");
return message_end;
}
lq = tvb_get_guint8(tvb, offset + 4);
nlq = tvb_get_guint8(tvb, offset + 5);
address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 8,
NULL, "%s (%d/%d)", tvb_ip_to_str(pinfo->pool, tvb, offset), lq, nlq);
address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
proto_tree_add_item(address_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
if (message_end - offset < 20) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last entry (need 20 bytes)");
return message_end;
}
lq = tvb_get_guint8(tvb, offset + 16);
nlq = tvb_get_guint8(tvb, offset + 17);
address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 20,
NULL, "%s (%d/%d)", tvb_ip6_to_str(pinfo->pool, tvb, offset), lq, nlq);
address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
proto_tree_add_item(address_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
proto_tree_add_item(address_tree, hf_olsrorg_lq, tvb, offset++, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(address_tree, hf_olsrorg_nlq, tvb, offset++, 1, ENC_BIG_ENDIAN);
offset += 2;
}
return message_end;
}
static int dissect_nrlolsr_tc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
int field1Ptr, field2Ptr, saneEnd;
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for NRLOLSR LQ-TC");
return message_end;
}
proto_tree_add_item(olsr_tree, hf_olsr_ansn, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 4;
field1Ptr = offset + (message_end - offset) / (pinfo->src.len + 2) * (pinfo->src.len);
field2Ptr = offset + (message_end - offset) / (pinfo->src.len + 2) * (pinfo->src.len + 1);
saneEnd = message_end - ((message_end - offset) % (pinfo->src.len + 2));
while (field2Ptr < saneEnd) {
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
proto_tree_add_item(olsr_tree, hf_nrlolsr_f1, tvb, field1Ptr++, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(olsr_tree, hf_nrlolsr_f2, tvb, field2Ptr++, 1, ENC_BIG_ENDIAN);
}
return message_end;
}
/*------------------------- Hello Dissecting Code-------------------------*/
static int dissect_olsr_hello(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end,
int(*handleNeighbors)(tvbuff_t *, packet_info *, proto_tree *, int, int)) {
double hTime;
proto_item *ti;
proto_tree *link_type_tree;
guint16 message_size;
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for Hello");
return message_end;
}
offset += 2;
/*---------------------Dissect Hello Emission Invertal-------------------*/
hTime = getOlsrTime(tvb_get_guint8(tvb, offset));
proto_tree_add_double_format_value(olsr_tree, hf_olsr_htime, tvb, offset, 1, hTime,
"%.3f (in seconds)", hTime);
offset += 1;
/*-------------------------Dissect Willingness---------------------------*/
proto_tree_add_item(olsr_tree, hf_olsr_willingness, tvb, offset++, 1, ENC_BIG_ENDIAN);
while (offset < message_end) {
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last Hello entry");
return message_end;
}
/*------------------------------Dissect Link Type---------------------------------- */
ti = proto_tree_add_item(olsr_tree, hf_olsr_link_type, tvb, offset++, 1, ENC_BIG_ENDIAN);
link_type_tree = proto_item_add_subtree(ti, ett_olsr_message_linktype);
/* reserved byte */
offset += 1;
/*----------------------Dissect Link Message Size--------------------------*/
message_size = tvb_get_ntohs(tvb, offset);
ti = proto_tree_add_item(link_type_tree, hf_olsr_link_message_size, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
if (message_size < 4) {
expert_add_info_format(pinfo, ti, &ei_olsr_not_enough_bytes, "(too short, must be >= 4)");
return message_end;
}
offset = handleNeighbors(tvb, pinfo, link_type_tree, offset, offset + message_size - 4);
}
return message_end;
}
static int handle_olsr_hello_rfc(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
int link_message_end) {
/*-------------------Dissect Neighbor Addresses--------------------*/
while (offset < link_message_end) {
if (link_message_end - offset < pinfo->src.len) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, link_message_end - offset,
"Not enough bytes for last Hello entry");
return link_message_end;
}
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(olsr_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(olsr_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
} /* end while */
return link_message_end;
}
static int handle_olsr_hello_olsrorg(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
int link_message_end) {
/*-------------------Dissect Neighbor Addresses--------------------*/
while (offset < link_message_end) {
proto_item *address_group;
proto_tree *address_tree;
guint8 lq, nlq;
if (link_message_end - offset < pinfo->src.len + 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, link_message_end - offset,
"Not enough bytes for last Olsr.org LQ-Hello entry");
return link_message_end;
}
if (pinfo->src.type == AT_IPv4) {
lq = tvb_get_guint8(tvb, offset + 4);
nlq = tvb_get_guint8(tvb, offset + 5);
address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 8,
NULL, "%s (%d/%d)", tvb_ip_to_str(pinfo->pool, tvb, offset), lq, nlq);
address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
proto_tree_add_item(address_tree, hf_olsr_neighbor_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
lq = tvb_get_guint8(tvb, offset + 16);
nlq = tvb_get_guint8(tvb, offset + 17);
address_group = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_neighbor, tvb, offset, 20,
NULL, "%s (%d/%d)", tvb_ip6_to_str(pinfo->pool, tvb, offset), lq, nlq);
address_tree = proto_item_add_subtree(address_group, ett_olsr_message_neigh);
proto_tree_add_item(address_tree, hf_olsr_neighbor6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
proto_tree_add_item(address_tree, hf_olsrorg_lq, tvb, offset++, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(address_tree, hf_olsrorg_nlq, tvb, offset++, 1, ENC_BIG_ENDIAN);
offset += 2;
} /* end while */
return link_message_end;
}
/*------------------------- MID Dissecting Code-------------------------*/
static int dissect_olsr_mid(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
while (offset < message_end) {
if (message_end - offset < pinfo->src.len) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last MID entry");
return message_end;
}
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(olsr_tree, hf_olsr_interface_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(olsr_tree, hf_olsr_interface6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
} /* end while for MID */
return message_end;
}
/*------------------------- HNA Dissecting Code-------------------------*/
static int dissect_olsr_hna(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset, int message_end) {
while (offset < message_end) {
if (message_end - offset < pinfo->src.len * 2) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last HNA entry");
return message_end;
}
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(olsr_tree, hf_olsr_network_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
proto_tree_add_item(olsr_tree, hf_olsr_netmask, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(olsr_tree, hf_olsr_network6_addr, tvb, offset, 4, ENC_NA);
offset += 16;
proto_tree_add_item(olsr_tree, hf_olsr_netmask6, tvb, offset, 4, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
} /* end while for HNA */
return message_end;
}
/*------------------------- MID Dissecting Code-------------------------*/
static int dissect_olsrorg_nameservice(tvbuff_t *tvb, packet_info *pinfo, proto_tree *olsr_tree, int offset,
int message_end) {
guint16 version, count;
proto_item *olsr_ns_item, *ti;
proto_tree *olsr_ns_tree;
if (message_end - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for Olsr.org Nameservice message");
return message_end;
}
version = tvb_get_ntohs(tvb, offset);
ti = proto_tree_add_item(olsr_tree, hf_olsrorg_ns_version, tvb, offset, 2, ENC_BIG_ENDIAN);
count = tvb_get_ntohs(tvb, offset + 2);
proto_tree_add_item(olsr_tree, hf_olsrorg_ns_count, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
offset += 4;
if (version != 1) {
expert_add_info(pinfo, ti, &ei_olsrorg_ns_version);
proto_tree_add_item(olsr_tree, hf_olsr_data, tvb, offset, message_end - offset, ENC_NA);
return message_end;
}
while (offset < message_end && count-- > 0) {
guint16 type, length;
int total_length;
if (message_end - offset < 20) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for last nameservice entry");
return message_end;
}
type = tvb_get_ntohs(tvb, offset);
length = tvb_get_ntohs(tvb, offset + 2);
total_length = 4 + 16 + ((length - 1) | 3) + 1;
olsr_ns_item = proto_tree_add_bytes_format_value(olsr_tree, hf_olsrorg_ns, tvb, offset, total_length,
NULL, "%s (%d)", val_to_str_const(type, nameservice_type_vals, "UNKNOWN"), type);
olsr_ns_tree = proto_item_add_subtree(olsr_ns_item, ett_olsr_message_ns);
proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_type, tvb, offset, 2, ENC_BIG_ENDIAN);
proto_tree_add_uint(olsr_ns_tree, hf_olsrorg_ns_length, tvb, offset + 2, 2, length);
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_ip, tvb, offset + 4, 4, ENC_BIG_ENDIAN);
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_ip6, tvb, offset + 4, 16, ENC_NA);
} else {
break; /* unknown address type should be handled in dissect_olsr, just be sure */
}
if (message_end - offset < total_length) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, message_end - offset,
"Not enough bytes for content of last nameservice entry");
return message_end;
}
proto_tree_add_item(olsr_ns_tree, hf_olsrorg_ns_content, tvb, offset + 20, length, ENC_ASCII);
offset += 4 + 16 + ((length - 1) | 3) + 1;
}
return message_end;
}
/*------------------------- Packet Dissecting Code-------------------------*/
static int dissect_olsr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_) {
proto_item *ti;
proto_tree *olsr_tree;
int offset, message_len, message_end;
guint message_type;
double vTime;
guint16 packet_len;
/* Does this packet have a valid message type at the beginning? */
if (tvb_captured_length(tvb) < 4) {
col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR Packet, Length: %u Bytes (not enough data in packet)",
tvb_captured_length(tvb));
return 0; /* not enough bytes for the packet length */
}
packet_len = tvb_get_ntohs(tvb, 0);
if (packet_len > tvb_reported_length(tvb)) {
col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR Packet, Length: %u Bytes (not enough data in packet)", packet_len);
return 0;
}
/*-------------Setting the Protocol and Info Columns in the Wireshark Display----------*/
col_set_str(pinfo->cinfo, COL_PROTOCOL, "OLSR v1");
col_clear(pinfo->cinfo, COL_INFO);
if ((pinfo->src.type != AT_IPv4) && (pinfo->src.type != AT_IPv6)) {
col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (unknown address type) Packet, Length: %u Bytes", packet_len);
return 0;
}
if (pinfo->src.type == AT_IPv4) {
col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (IPv4) Packet, Length: %u Bytes", packet_len);
} else if (pinfo->src.type == AT_IPv6) {
col_add_fstr(pinfo->cinfo, COL_INFO, "OLSR (IPv6) Packet, Length: %u Bytes", packet_len);
}
/*-----------------Fetching Info from IP Packet and Adding to Tree------------------------*/
ti = proto_tree_add_item(tree, proto_olsr, tvb, 0, -1, ENC_NA);
olsr_tree = proto_item_add_subtree(ti, ett_olsr);
proto_tree_add_item(olsr_tree, hf_olsr_packet_len, tvb, 0, 2, ENC_BIG_ENDIAN);
proto_tree_add_item(olsr_tree, hf_olsr_packet_seq_num, tvb, 2, 2, ENC_BIG_ENDIAN);
offset = 4;
while (offset < packet_len) {
proto_item *message_item;
proto_tree *message_tree;
if (packet_len - offset < 4) {
proto_tree_add_expert_format(olsr_tree, pinfo, &ei_olsr_not_enough_bytes, tvb, offset, packet_len - offset,
"Message too short !");
break;
}
message_type = tvb_get_guint8(tvb, offset);
vTime = getOlsrTime(tvb_get_guint8(tvb, offset + 1));
message_len = tvb_get_ntohs(tvb, offset + 2);
message_item = proto_tree_add_bytes_format_value(olsr_tree, hf_olsr_message, tvb, offset, message_len,
NULL, "%s (%d)", val_to_str_const(message_type, message_type_vals, "UNKNOWN"),
message_type);
message_tree = proto_item_add_subtree(message_item, ett_olsr_message[message_type]);
proto_tree_add_uint(message_tree, hf_olsr_message_type, tvb, offset, 1, message_type);
offset += 1;
/*-------------Dissect Validity Time-------------------------*/
proto_tree_add_double_format_value(message_tree, hf_olsr_vtime, tvb, offset, 1, vTime,
"%.3f (in seconds)", vTime);
offset += 1;
/*-------------Dissect Message Size---------------------------*/
ti = proto_tree_add_item(message_tree, hf_olsr_message_size, tvb, offset, 2, ENC_BIG_ENDIAN);
offset += 2;
if (message_len < 8 + pinfo->src.len) {
expert_add_info_format(pinfo, ti, &ei_olsr_not_enough_bytes, "(too short, must be >= %d)", 8 + pinfo->src.len);
break;
}
message_end = offset + message_len - 4;
if (message_end > packet_len) {
expert_add_info_format(pinfo, ti, &ei_olsr_not_enough_bytes, "(not enough data for message)");
break;
}
/*-----------------Dissecting: Origin Addr, TTL, Hop Count, and Message Seq Number*/
if (pinfo->src.type == AT_IPv4) {
proto_tree_add_item(message_tree, hf_olsr_origin_addr, tvb, offset, 4, ENC_BIG_ENDIAN);
offset += 4;
} else if (pinfo->src.type == AT_IPv6) {
proto_tree_add_item(message_tree, hf_olsr_origin6_addr, tvb, offset, 16, ENC_NA);
offset += 16;
} else {
break; /* unknown address type should be handled before this loop, just be sure */
}
proto_tree_add_item(message_tree, hf_olsr_ttl, tvb, offset, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(message_tree, hf_olsr_hop_count, tvb, offset + 1, 1, ENC_BIG_ENDIAN);
proto_tree_add_item(message_tree, hf_olsr_message_seq_num, tvb, offset + 2, 2, ENC_BIG_ENDIAN);
offset += 4;
if (offset < message_end) {
/* --------------Dissecting TC message--------------------- */
if (message_type == TC) {
dissect_olsr_tc(tvb, pinfo, message_tree, offset, message_end);
}
/* -------------Dissect HELLO message----------------------- */
else if (message_type == HELLO) {
dissect_olsr_hello(tvb, pinfo, message_tree, offset, message_end, &handle_olsr_hello_rfc);
}
/*---------------------------------Dissect MID Message----------------------------------*/
else if (message_type == MID) {
dissect_olsr_mid(tvb, pinfo, message_tree, offset, message_end);
}
/*-----------------------------Dissect HNA Message--------------------------------*/
else if (message_type == HNA) {
dissect_olsr_hna(tvb, pinfo, message_tree, offset, message_end);
}
/*-----------------------------Dissect Olsr.org Hello Message--------------------------------*/
else if (global_olsr_olsrorg && message_type == OLSR_ORG_LQ_HELLO) {
dissect_olsr_hello(tvb, pinfo, message_tree, offset, message_end, &handle_olsr_hello_olsrorg);
}
/*-----------------------------Dissect Olsr.org TC Message--------------------------------*/
else if (global_olsr_olsrorg && message_type == OLSR_ORG_LQ_TC) {
dissect_olsrorg_lq_tc(tvb, pinfo, message_tree, offset, message_end);
}
/*-----------------------------Dissect Olsr.org NS Message--------------------------------*/
else if (global_olsr_olsrorg && message_type == OLSR_ORG_NAMESERVICE) {
dissect_olsrorg_nameservice(tvb, pinfo, message_tree, offset, message_end);
}
/*-----------------------Dissect NRL OLSR TC Message-------------------------------------*/
else if (global_olsr_nrlolsr && message_type == NRLOLSR_TC_EXTRA) {
dissect_nrlolsr_tc(tvb, pinfo, message_tree, offset, message_end);
}
/*-----------------------------Undefined message types-----------------------------*/
else {
ti = proto_tree_add_bytes_format(message_tree, hf_olsr_data, tvb, offset, message_len - 12,
NULL, "Data (%u bytes)", message_len - 12);
if ((message_len - 12) % 4) {
expert_add_info(pinfo, ti, &ei_olsr_data_misaligned);
break;
}
/*offset += message_len - 12;*/
} /* end if for undefined message types */
}
offset = message_end;
} /* end while for message alive */
return tvb_captured_length(tvb);
} /* end Dissecting */
/*-----------Register the Dissector for OLSR--------------*/
void proto_register_olsr(void) {
static hf_register_info hf[] = {
{ &hf_olsr_packet_len,
{ "Packet Length", "olsr.packet_len",
FT_UINT16, BASE_DEC, NULL, 0,
"Packet Length in Bytes", HFILL
}
},
{ &hf_olsr_packet_seq_num,
{ "Packet Sequence Number", "olsr.packet_seq_num",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_message,
{ "Message", "olsr.message",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_message_type,
{ "Message Type", "olsr.message_type",
FT_UINT8, BASE_DEC, VALS(message_type_vals), 0,
NULL, HFILL
}
},
{ &hf_olsr_message_size,
{ "Message", "olsr.message_size",
FT_UINT16, BASE_DEC, NULL, 0,
"Message Size in Bytes", HFILL
}
},
{ &hf_olsr_message_seq_num,
{ "Message Sequence Number", "olsr.message_seq_num",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_vtime,
{ "Validity Time", "olsr.vtime",
FT_DOUBLE, BASE_NONE, NULL, 0,
"Validity Time in seconds", HFILL
}
},
{ &hf_olsr_ansn,
{ "Advertised Neighbor Sequence Number (ANSN)", "olsr.ansn",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_htime,
{ "Hello Emission Interval", "olsr.htime",
FT_DOUBLE, BASE_NONE, NULL, 0,
"Hello emission interval in seconds", HFILL
}
},
{ &hf_olsr_willingness,
{ "Willingness to forward messages", "olsr.willingness",
FT_UINT8, BASE_DEC, VALS(willingness_type_vals), 0,
NULL, HFILL
}
},
{ &hf_olsr_ttl,
{ "TTL", "olsr.ttl",
FT_UINT8, BASE_DEC, NULL, 0,
"Time to Live in hops", HFILL
}
},
{ &hf_olsr_link_type,
{ "Link Type", "olsr.link_type",
FT_UINT8, BASE_DEC, VALS(link_type_vals), 0,
NULL, HFILL
}
},
{ &hf_olsr_link_message_size,
{ "Link Message Size", "olsr.link_message_size",
FT_UINT16, BASE_DEC, NULL, 0,
"Link Message Size in bytes", HFILL
}
},
{ &hf_olsr_hop_count,
{ "Hop Count", "olsr.hop_count",
FT_UINT8, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_neighbor,
{ "Neighbor Address", "olsr.neighbor",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_origin_addr,
{ "Originator Address", "olsr.origin_addr",
FT_IPv4, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_neighbor_addr,
{ "Neighbor Address", "olsr.neighbor_addr",
FT_IPv4, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_network_addr,
{ "Network Address", "olsr.network_addr",
FT_IPv4, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_interface_addr,
{ "Interface Address", "olsr.interface_addr",
FT_IPv4, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_netmask,
{ "Netmask", "olsr.netmask",
FT_IPv4, BASE_NETMASK, NULL, 0,
NULL, HFILL
}
},
#if 0
{ &hf_olsr_neighbor6,
{ "Neighbor Address", "olsr.neighbor6",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
#endif
{ &hf_olsr_origin6_addr,
{ "Originator Address", "olsr.origin6_addr",
FT_IPv6, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_neighbor6_addr,
{ "Neighbor Address", "olsr.neighbor6_addr",
FT_IPv6, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_network6_addr,
{ "Network Address", "olsr.network6_addr",
FT_IPv6, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_interface6_addr,
{ "Interface Address", "olsr.interface6_addr",
FT_IPv6, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_netmask6,
{ "Netmask", "olsr.netmask6",
FT_IPv6, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsr_data,
{ "Data", "olsr.data",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsrorg_lq,
{ "LQ", "olsr.lq",
FT_UINT8, BASE_DEC, NULL, 0,
"Link quality", HFILL
}
},
{ &hf_olsrorg_nlq,
{ "NLQ", "olsr.nlq",
FT_UINT8, BASE_DEC, NULL, 0,
"Neighbor link quality", HFILL
}
},
{ &hf_olsrorg_ns,
{ "Nameservice", "olsr.ns",
FT_BYTES, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsrorg_ns_version,
{ "Version", "olsr.ns.version",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsrorg_ns_count,
{ "Count", "olsr.ns.count",
FT_UINT16, BASE_DEC, NULL, 0,
"Number of nameservice messages", HFILL
}
},
{ &hf_olsrorg_ns_type,
{ "Message Type", "olsr.ns.type",
FT_UINT16, BASE_DEC, VALS(nameservice_type_vals), 0,
NULL, HFILL
}
},
{ &hf_olsrorg_ns_length,
{ "Length", "olsr.ns.length",
FT_UINT16, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsrorg_ns_ip,
{ "Address", "olsr.ns.ip",
FT_IPv4, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsrorg_ns_ip6,
{ "Address", "olsr.ns.ip6",
FT_IPv6, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_olsrorg_ns_content,
{ "Content", "olsr.ns.content",
FT_STRING, BASE_NONE, NULL, 0,
NULL, HFILL
}
},
{ &hf_nrlolsr_f1,
{ "NRL MINMAX", "olsr.nrl.minmax",
FT_UINT8, BASE_DEC, NULL, 0,
NULL, HFILL
}
},
{ &hf_nrlolsr_f2,
{ "NRL SPF", "olsr.nrl.spf",
FT_UINT8, BASE_DEC, NULL, 0,
NULL, HFILL
}
}
};
static gint *ett_base[] = {
&ett_olsr,
&ett_olsr_message_linktype,
&ett_olsr_message_neigh,
&ett_olsr_message_neigh6,
&ett_olsr_message_ns
};
static ei_register_info ei[] = {
{ &ei_olsr_not_enough_bytes, { "olsr.not_enough_bytes", PI_MALFORMED, PI_ERROR, "Not enough bytes for field", EXPFILL }},
{ &ei_olsrorg_ns_version, { "olsr.ns.version.unknown", PI_PROTOCOL, PI_WARN, "Unknown nameservice protocol version", EXPFILL }},
{ &ei_olsr_data_misaligned, { "olsr.data.misaligned", PI_PROTOCOL, PI_WARN, "Must be aligned on 32 bits", EXPFILL }},
};
gint *ett[array_length(ett_base) + (G_MAXUINT8+1)];
module_t *olsr_module;
expert_module_t *expert_olsr;
int i,j;
memcpy(ett, ett_base, sizeof(ett_base));
j = array_length(ett_base);
for (i=0; i<G_MAXUINT8+1; i++) {
ett_olsr_message[i] = -1;
ett[j++] = &ett_olsr_message[i];
}
proto_olsr = proto_register_protocol("Optimized Link State Routing Protocol", "OLSR", "olsr");
olsr_handle = register_dissector("olsr", dissect_olsr, proto_olsr);
proto_register_field_array(proto_olsr, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
expert_olsr = expert_register_protocol(proto_olsr);
expert_register_field_array(expert_olsr, ei, array_length(ei));
olsr_module = prefs_register_protocol(proto_olsr, NULL);
prefs_register_bool_preference(olsr_module, "ff_olsrorg",
"Dissect olsr.org messages","Dissect custom olsr.org message types (compatible with rfc routing agents)",
&global_olsr_olsrorg);
prefs_register_bool_preference(olsr_module, "nrlolsr",
"Dissect NRL-Olsr TC messages", "Dissect custom nrlolsr tc message (incompatible with rfc routing agents)",
&global_olsr_nrlolsr);
}
void proto_reg_handoff_olsr(void) {
dissector_add_uint_with_preference("udp.port", UDP_PORT_OLSR, olsr_handle);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 2
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=2 tabstop=8 expandtab:
* :indentSize=2:tabSize=8:noTabs=true:
*/
|