2 * Routines for B.A.T.M.A.N. Layer 3 dissection
3 * Copyright 2008-2010 Sven Eckelmann <sven@narfation.org>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
16 #include <epan/addr_resolv.h>
18 #include <epan/unit_strings.h>
20 void proto_register_bat(void);
21 void proto_reg_handoff_bat(void);
23 static dissector_handle_t batman_handle
;
24 static dissector_handle_t gw_handle
;
25 static dissector_handle_t vis_handle
;
27 #define BAT_BATMAN_PORT 4305
28 #define BAT_GW_PORT 4306 /* Not IANA registered */
29 #define BAT_VIS_PORT 4307 /* Not IANA registered */
31 #define UNIDIRECTIONAL 0x80
32 #define DIRECTLINK 0x40
34 struct batman_packet_v5
{
35 uint8_t version
; /* batman version field */
36 uint8_t flags
; /* 0x80: UNIDIRECTIONAL link, 0x40: DIRECTLINK flag, ... */
38 uint8_t gwflags
; /* flags related to gateway functions: gateway class */
46 #define BATMAN_PACKET_V5_SIZE 18
51 #define GW_PACKET_SIZE 1
53 #define TUNNEL_DATA 0x01
54 #define TUNNEL_IP_REQUEST 0x02
55 #define TUNNEL_IP_INVALID 0x03
56 #define TUNNEL_KEEPALIVE_REQUEST 0x04
57 #define TUNNEL_KEEPALIVE_REPLY 0x05
59 #define DATA_TYPE_NEIGH 1
60 #define DATA_TYPE_SEC_IF 2
61 #define DATA_TYPE_HNA 3
63 struct vis_packet_v22
{
69 #define VIS_PACKET_V22_SIZE 8
76 #define VIS_PACKET_V22_DATA_SIZE 7
78 struct vis_packet_v23
{
84 #define VIS_PACKET_V23_SIZE 7
91 #define VIS_PACKET_V23_DATA_SIZE 6
92 /* End content from packet-bat.h */
95 static int ett_bat_batman
;
96 static int ett_bat_batman_flags
;
97 static int ett_bat_batman_gwflags
;
98 static int ett_bat_batman_hna
;
99 static int ett_bat_gw
;
100 static int ett_bat_vis
;
101 static int ett_bat_vis_entry
;
104 static int hf_bat_batman_version
;
105 static int hf_bat_batman_flags
;
106 static int hf_bat_batman_ttl
;
107 static int hf_bat_batman_gwflags
;
108 static int hf_bat_batman_gwflags_dl_speed
;
109 static int hf_bat_batman_gwflags_ul_speed
;
110 static int hf_bat_batman_seqno
;
111 static int hf_bat_batman_gwport
;
112 static int hf_bat_batman_orig
;
113 static int hf_bat_batman_old_orig
;
114 static int hf_bat_batman_tq
;
115 static int hf_bat_batman_hna_len
;
116 static int hf_bat_batman_hna_network
;
117 static int hf_bat_batman_hna_netmask
;
119 static int hf_bat_gw_type
;
120 static int hf_bat_gw_ip
;
122 static int hf_bat_vis_vis_orig
;
123 static int hf_bat_vis_version
;
124 static int hf_bat_vis_gwflags
;
125 static int hf_bat_max_tq_v22
;
126 static int hf_bat_max_tq_v23
;
127 static int hf_bat_vis_data_type
;
128 static int hf_bat_vis_netmask
;
129 static int hf_bat_vis_tq_v22
;
130 static int hf_bat_vis_tq_v23
;
131 static int hf_bat_vis_data_ip
;
134 static int hf_bat_batman_flags_unidirectional
;
135 static int hf_bat_batman_flags_directlink
;
137 static const value_string gw_packettypenames
[] = {
138 { TUNNEL_DATA
, "DATA" },
139 { TUNNEL_IP_REQUEST
, "IP_REQUEST" },
140 { TUNNEL_IP_INVALID
, "IP_INVALID" },
141 { TUNNEL_KEEPALIVE_REQUEST
, "KEEPALIVE_REQUEST" },
142 { TUNNEL_KEEPALIVE_REPLY
, "KEEPALIVE_REPLY" },
146 static const value_string vis_packettypenames
[] = {
147 { DATA_TYPE_NEIGH
, "NEIGH" },
148 { DATA_TYPE_SEC_IF
, "SEC_IF" },
149 { DATA_TYPE_HNA
, "HNA" },
153 /* supported packet dissectors */
154 static int dissect_bat_batman_v5(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
);
157 static void dissect_bat_vis_v22(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
158 static void dissect_vis_entry_v22(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
159 static void dissect_bat_vis_v23(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
160 static void dissect_vis_entry_v23(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
162 static void dissect_bat_hna(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
);
164 /* other dissectors */
165 static dissector_handle_t ip_handle
;
167 static int proto_bat_plugin
;
168 static int proto_bat_gw
;
169 static int proto_bat_vis
;
173 static int bat_follow_tap
;
175 static int dissect_bat_batman(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
180 /* set protocol name */
181 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "BAT_BATMAN");
182 col_clear(pinfo
->cinfo
, COL_INFO
);
184 version
= tvb_get_uint8(tvb
, 0);
187 while (tvb_reported_length_remaining(tvb
, offset
) > 0) {
188 offset
= dissect_bat_batman_v5(tvb
, offset
, pinfo
, tree
);
192 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unsupported Version %d", version
);
193 call_data_dissector(tvb
, pinfo
, tree
);
196 return tvb_captured_length(tvb
);
199 static void dissect_bat_gwflags(tvbuff_t
*tvb
, uint8_t gwflags
, int offset
, proto_item
*tgw
)
201 proto_tree
*gwflags_tree
;
202 uint8_t s
= (gwflags
& 0x80) >> 7;
203 uint8_t downbits
= (gwflags
& 0x78) >> 3;
204 uint8_t upbits
= (gwflags
& 0x07);
207 down
= 32 * (s
+ 2) * (1 << downbits
);
208 up
= ((upbits
+ 1) * down
) / 8;
210 gwflags_tree
= proto_item_add_subtree(tgw
, ett_bat_batman_gwflags
);
211 proto_tree_add_uint(gwflags_tree
, hf_bat_batman_gwflags_dl_speed
, tvb
, offset
, 1, down
);
212 proto_tree_add_uint(gwflags_tree
, hf_bat_batman_gwflags_ul_speed
, tvb
, offset
, 1, up
);
216 static int dissect_bat_batman_v5(tvbuff_t
*tvb
, int offset
, packet_info
*pinfo
, proto_tree
*tree
)
219 proto_tree
*bat_batman_tree
= NULL
;
220 struct batman_packet_v5
*batman_packeth
;
221 uint32_t old_orig
, orig
;
223 static int * const batman_flags
[] = {
224 &hf_bat_batman_flags_unidirectional
,
225 &hf_bat_batman_flags_directlink
,
231 batman_packeth
= wmem_new(pinfo
->pool
, struct batman_packet_v5
);
233 batman_packeth
->version
= tvb_get_uint8(tvb
, offset
+0);
234 batman_packeth
->flags
= tvb_get_uint8(tvb
, offset
+1);
235 batman_packeth
->ttl
= tvb_get_uint8(tvb
, offset
+2);
236 batman_packeth
->gwflags
= tvb_get_uint8(tvb
, offset
+3);
237 batman_packeth
->seqno
= tvb_get_ntohs(tvb
, offset
+4);
238 batman_packeth
->gwport
= tvb_get_ntohs(tvb
, offset
+6);
239 orig
= tvb_get_ipv4(tvb
, offset
+8);
240 set_address_tvb(&batman_packeth
->orig
, AT_IPv4
, 4, tvb
, offset
+8);
241 old_orig
= tvb_get_ipv4(tvb
, offset
+12);
242 set_address_tvb(&batman_packeth
->old_orig
, AT_IPv4
, 4, tvb
, offset
+12);
243 batman_packeth
->tq
= tvb_get_uint8(tvb
, offset
+16);
244 batman_packeth
->hna_len
= tvb_get_uint8(tvb
, offset
+17);
246 /* Set info column */
247 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Seq=%u", batman_packeth
->seqno
);
253 ti
= proto_tree_add_protocol_format(tree
, proto_bat_plugin
, tvb
, offset
, BATMAN_PACKET_V5_SIZE
,
254 "B.A.T.M.A.N., Orig: %s",
255 address_with_resolution_to_str(pinfo
->pool
, &batman_packeth
->orig
));
256 bat_batman_tree
= proto_item_add_subtree(ti
, ett_bat_batman
);
260 proto_tree_add_item(bat_batman_tree
, hf_bat_batman_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
263 proto_tree_add_bitmask(bat_batman_tree
, tvb
, offset
, hf_bat_batman_flags
,
264 ett_bat_batman_flags
, batman_flags
, ENC_NA
);
267 proto_tree_add_item(bat_batman_tree
, hf_bat_batman_ttl
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
270 tgw
= proto_tree_add_item(bat_batman_tree
, hf_bat_batman_gwflags
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
271 dissect_bat_gwflags(tvb
, batman_packeth
->gwflags
, offset
, tgw
);
274 proto_tree_add_item(bat_batman_tree
, hf_bat_batman_seqno
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
277 proto_tree_add_item(bat_batman_tree
, hf_bat_batman_gwport
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
280 proto_tree_add_ipv4(bat_batman_tree
, hf_bat_batman_orig
, tvb
, offset
, 4, orig
);
283 proto_tree_add_ipv4(bat_batman_tree
, hf_bat_batman_old_orig
, tvb
, offset
, 4, old_orig
);
286 proto_tree_add_item(bat_batman_tree
, hf_bat_batman_tq
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
289 proto_tree_add_item(bat_batman_tree
, hf_bat_batman_hna_len
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
292 tap_queue_packet(bat_tap
, pinfo
, batman_packeth
);
294 for (i
= 0; i
< batman_packeth
->hna_len
; i
++) {
295 next_tvb
= tvb_new_subset_length(tvb
, offset
, 5);
297 if (have_tap_listener(bat_follow_tap
)) {
298 tap_queue_packet(bat_follow_tap
, pinfo
, next_tvb
);
301 dissect_bat_hna(next_tvb
, pinfo
, bat_batman_tree
);
308 static void dissect_bat_hna(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
)
313 hna
= tvb_get_ipv4(tvb
, 0);
314 hna_netmask
= tvb_get_uint8(tvb
, 4);
320 proto_tree
*bat_batman_hna_tree
;
322 if (PTREE_DATA(tree
)->visible
) {
323 ti
= proto_tree_add_protocol_format(tree
, proto_bat_plugin
, tvb
, 0, 5,
324 "B.A.T.M.A.N. HNA: %s/%d",
325 tvb_ip_to_str(pinfo
->pool
, tvb
, 0), hna_netmask
);
327 ti
= proto_tree_add_item(tree
, proto_bat_plugin
, tvb
, 0, 5, ENC_NA
);
329 bat_batman_hna_tree
= proto_item_add_subtree(ti
, ett_bat_batman_hna
);
331 proto_tree_add_ipv4(bat_batman_hna_tree
, hf_bat_batman_hna_network
, tvb
, 0, 4, hna
);
332 proto_tree_add_item(bat_batman_hna_tree
, hf_bat_batman_hna_netmask
, tvb
, 4, 1, ENC_BIG_ENDIAN
);
337 static int dissect_bat_gw(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
339 struct gw_packet
*gw_packeth
;
344 int length_remaining
;
347 gw_packeth
= wmem_new(pinfo
->pool
, struct gw_packet
);
348 gw_packeth
->type
= tvb_get_uint8(tvb
, 0);
350 switch (gw_packeth
->type
) {
351 case TUNNEL_IP_INVALID
:
357 ip
= tvb_get_ipv4(tvb
, ip_pos
);
359 /* set protocol name */
360 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "BAT_GW");
362 /* Set info column */
363 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Type=%s",
364 val_to_str(gw_packeth
->type
, gw_packettypenames
, "Unknown (0x%02x)"));
366 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " IP: %s",
367 tvb_address_with_resolution_to_str(pinfo
->pool
, tvb
, AT_IPv4
, ip_pos
));
374 proto_tree
*bat_gw_entry_tree
;
376 ti
= proto_tree_add_protocol_format(tree
, proto_bat_gw
, tvb
, 0, 1,
377 "B.A.T.M.A.N. GW [%s]",
378 val_to_str(gw_packeth
->type
, gw_packettypenames
, "Unknown (0x%02x)"));
379 bat_gw_entry_tree
= proto_item_add_subtree(ti
, ett_bat_gw
);
381 proto_tree_add_item(bat_gw_entry_tree
, hf_bat_gw_type
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
384 if (gw_packeth
->type
!= TUNNEL_DATA
&& ip
!= 0) {
385 proto_tree_add_ipv4(bat_gw_entry_tree
, hf_bat_gw_ip
, tvb
, ip_pos
, 4, ip
);
386 /*offset = ip_pos + 4;*/
390 /* Calculate offset even when we got no tree */
392 if (gw_packeth
->type
!= TUNNEL_DATA
&& ip
!= 0)
395 length_remaining
= tvb_reported_length_remaining(tvb
, offset
);
396 if (length_remaining
> 0) {
397 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
399 if (have_tap_listener(bat_follow_tap
)) {
400 tap_queue_packet(bat_follow_tap
, pinfo
, next_tvb
);
403 if (gw_packeth
->type
== TUNNEL_DATA
) {
404 call_dissector(ip_handle
, next_tvb
, pinfo
, tree
);
406 call_data_dissector(next_tvb
, pinfo
, tree
);
409 return tvb_captured_length(tvb
);
412 static int dissect_bat_vis(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
416 /* set protocol name */
417 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "BAT_VIS");
419 version
= tvb_get_uint8(tvb
, 4);
422 dissect_bat_vis_v22(tvb
, pinfo
, tree
);
425 dissect_bat_vis_v23(tvb
, pinfo
, tree
);
428 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Unsupported Version %d", version
);
429 call_data_dissector(tvb
, pinfo
, tree
);
432 return tvb_captured_length(tvb
);
435 static void dissect_bat_vis_v22(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
437 struct vis_packet_v22
*vis_packeth
;
439 proto_tree
*bat_vis_tree
= NULL
;
442 int length_remaining
, i
;
445 vis_packeth
= wmem_new(pinfo
->pool
, struct vis_packet_v22
);
447 sender_ip
= tvb_get_ipv4(tvb
, 0);
448 set_address_tvb(&vis_packeth
->sender_ip
, AT_IPv4
, 4, tvb
, 0);
449 vis_packeth
->version
= tvb_get_uint8(tvb
, 4);
450 vis_packeth
->gw_class
= tvb_get_uint8(tvb
, 5);
451 vis_packeth
->tq_max
= tvb_get_ntohs(tvb
, 6);
453 /* set protocol name */
454 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "BAT_VIS");
456 /* Set info column */
457 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Src: %s",
458 address_with_resolution_to_str(pinfo
->pool
, &vis_packeth
->sender_ip
));
464 ti
= proto_tree_add_protocol_format(tree
, proto_bat_vis
, tvb
, 0, VIS_PACKET_V22_SIZE
,
465 "B.A.T.M.A.N. Vis, Src: %s",
466 address_with_resolution_to_str(pinfo
->pool
, &vis_packeth
->sender_ip
));
467 bat_vis_tree
= proto_item_add_subtree(ti
, ett_bat_vis
);
470 proto_tree_add_ipv4(bat_vis_tree
, hf_bat_vis_vis_orig
, tvb
, offset
, 4, sender_ip
);
473 proto_tree_add_item(bat_vis_tree
, hf_bat_vis_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
476 proto_tree_add_item(bat_vis_tree
, hf_bat_vis_gwflags
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
479 proto_tree_add_item(bat_vis_tree
, hf_bat_max_tq_v22
, tvb
, offset
, 2, ENC_BIG_ENDIAN
);
483 /* Calculate offset even when we got no tree */
484 offset
= VIS_PACKET_V22_SIZE
;
486 tap_queue_packet(bat_tap
, pinfo
, vis_packeth
);
488 length_remaining
= tvb_reported_length_remaining(tvb
, offset
);
490 for (i
= 0; i
< length_remaining
; i
+= VIS_PACKET_V22_DATA_SIZE
) {
491 next_tvb
= tvb_new_subset_length(tvb
, offset
, VIS_PACKET_V22_DATA_SIZE
);
493 if (have_tap_listener(bat_follow_tap
)) {
494 tap_queue_packet(bat_follow_tap
, pinfo
, next_tvb
);
497 if (bat_vis_tree
!= NULL
) {
498 dissect_vis_entry_v22(next_tvb
, pinfo
, tree
);
501 offset
+= VIS_PACKET_V22_DATA_SIZE
;
504 length_remaining
= tvb_reported_length_remaining(tvb
, offset
);
505 if (length_remaining
> 0) {
506 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
508 if (have_tap_listener(bat_follow_tap
)) {
509 tap_queue_packet(bat_follow_tap
, pinfo
, next_tvb
);
512 call_data_dissector(next_tvb
, pinfo
, tree
);
516 static void dissect_vis_entry_v22(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
)
518 struct vis_data_v22
*vis_datah
;
521 vis_datah
= wmem_new(pinfo
->pool
, struct vis_data_v22
);
522 vis_datah
->type
= tvb_get_uint8(tvb
, 0);
523 vis_datah
->data
= tvb_get_ntohs(tvb
, 1);
524 ip
= tvb_get_ipv4(tvb
, 3);
525 set_address_tvb(&vis_datah
->ip
, AT_IPv4
, 4, tvb
, 3);
531 proto_tree
*bat_vis_entry_tree
;
533 ti
= proto_tree_add_protocol_format(tree
, proto_bat_plugin
, tvb
, 0, 7,
534 "VIS Entry: [%s] %s",
535 val_to_str(vis_datah
->type
, vis_packettypenames
, "Unknown (0x%02x)"),
536 address_with_resolution_to_str(pinfo
->pool
, &vis_datah
->ip
));
537 bat_vis_entry_tree
= proto_item_add_subtree(ti
, ett_bat_vis_entry
);
539 proto_tree_add_item(bat_vis_entry_tree
, hf_bat_vis_data_type
, tvb
, 0, 1, ENC_BIG_ENDIAN
);
541 switch (vis_datah
->type
) {
542 case DATA_TYPE_NEIGH
:
543 proto_tree_add_item(bat_vis_entry_tree
, hf_bat_vis_tq_v22
, tvb
, 1, 2, ENC_BIG_ENDIAN
);
546 proto_tree_add_item(bat_vis_entry_tree
, hf_bat_vis_netmask
, tvb
, 1, 1, ENC_BIG_ENDIAN
);
548 case DATA_TYPE_SEC_IF
:
552 proto_tree_add_ipv4(bat_vis_entry_tree
, hf_bat_vis_data_ip
, tvb
, 3, 4, ip
);
556 static void dissect_bat_vis_v23(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
)
558 struct vis_packet_v23
*vis_packeth
;
560 proto_tree
*bat_vis_tree
= NULL
;
563 int length_remaining
, i
;
566 vis_packeth
= wmem_new(pinfo
->pool
, struct vis_packet_v23
);
568 sender_ip
= tvb_get_ipv4(tvb
, 0);
569 set_address_tvb(&vis_packeth
->sender_ip
, AT_IPv4
, 4, tvb
, 0);
570 vis_packeth
->version
= tvb_get_uint8(tvb
, 4);
571 vis_packeth
->gw_class
= tvb_get_uint8(tvb
, 5);
572 vis_packeth
->tq_max
= tvb_get_uint8(tvb
, 6);
574 /* set protocol name */
575 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "BAT_VIS");
577 /* Set info column */
578 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "Src: %s",
579 address_with_resolution_to_str(pinfo
->pool
, &vis_packeth
->sender_ip
));
585 ti
= proto_tree_add_protocol_format(tree
, proto_bat_vis
, tvb
, 0, VIS_PACKET_V23_SIZE
,
586 "B.A.T.M.A.N. Vis, Src: %s",
587 address_with_resolution_to_str(pinfo
->pool
, &vis_packeth
->sender_ip
));
588 bat_vis_tree
= proto_item_add_subtree(ti
, ett_bat_vis
);
591 proto_tree_add_ipv4(bat_vis_tree
, hf_bat_vis_vis_orig
, tvb
, offset
, 4, sender_ip
);
594 proto_tree_add_item(bat_vis_tree
, hf_bat_vis_version
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
597 proto_tree_add_item(bat_vis_tree
, hf_bat_vis_gwflags
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
600 proto_tree_add_item(bat_vis_tree
, hf_bat_max_tq_v23
, tvb
, offset
, 1, ENC_BIG_ENDIAN
);
604 /* Calculate offset even when we got no tree */
605 offset
= VIS_PACKET_V23_SIZE
;
607 tap_queue_packet(bat_tap
, pinfo
, vis_packeth
);
609 length_remaining
= tvb_reported_length_remaining(tvb
, offset
);
611 for (i
= 0; i
< length_remaining
; i
+= VIS_PACKET_V23_DATA_SIZE
) {
612 next_tvb
= tvb_new_subset_length(tvb
, offset
, VIS_PACKET_V23_DATA_SIZE
);
614 if (have_tap_listener(bat_follow_tap
)) {
615 tap_queue_packet(bat_follow_tap
, pinfo
, next_tvb
);
618 if (bat_vis_tree
!= NULL
) {
619 dissect_vis_entry_v23(next_tvb
, pinfo
, tree
);
622 offset
+= VIS_PACKET_V23_DATA_SIZE
;
625 length_remaining
= tvb_reported_length_remaining(tvb
, offset
);
626 if (length_remaining
> 0) {
627 next_tvb
= tvb_new_subset_remaining(tvb
, offset
);
629 if (have_tap_listener(bat_follow_tap
)) {
630 tap_queue_packet(bat_follow_tap
, pinfo
, next_tvb
);
633 call_data_dissector(next_tvb
, pinfo
, tree
);
637 static void dissect_vis_entry_v23(tvbuff_t
*tvb
, packet_info
*pinfo _U_
, proto_tree
*tree
)
639 struct vis_data_v23
*vis_datah
;
642 vis_datah
= wmem_new(pinfo
->pool
, struct vis_data_v23
);
643 vis_datah
->type
= tvb_get_uint8(tvb
, 0);
644 vis_datah
->data
= tvb_get_uint8(tvb
, 1);
645 ip
= tvb_get_ipv4(tvb
, 2);
646 set_address_tvb(&vis_datah
->ip
, AT_IPv4
, 4, tvb
, 2);
652 proto_tree
*bat_vis_entry_tree
;
654 ti
= proto_tree_add_protocol_format(tree
, proto_bat_plugin
, tvb
, 0, 7,
655 "VIS Entry: [%s] %s",
656 val_to_str(vis_datah
->type
, vis_packettypenames
, "Unknown (0x%02x)"),
657 address_with_resolution_to_str(pinfo
->pool
, &vis_datah
->ip
));
658 bat_vis_entry_tree
= proto_item_add_subtree(ti
, ett_bat_vis_entry
);
660 proto_tree_add_item(bat_vis_entry_tree
, hf_bat_vis_data_type
, tvb
, 0, 1, ENC_BIG_ENDIAN
);
662 switch (vis_datah
->type
) {
663 case DATA_TYPE_NEIGH
:
664 proto_tree_add_item(bat_vis_entry_tree
, hf_bat_vis_tq_v23
, tvb
, 1, 1, ENC_BIG_ENDIAN
);
667 proto_tree_add_item(bat_vis_entry_tree
, hf_bat_vis_netmask
, tvb
, 1, 1, ENC_BIG_ENDIAN
);
669 case DATA_TYPE_SEC_IF
:
673 proto_tree_add_ipv4(bat_vis_entry_tree
, hf_bat_vis_data_ip
, tvb
, 2, 4, ip
);
677 void proto_register_bat(void)
679 static hf_register_info hf
[] = {
680 { &hf_bat_batman_version
,
681 { "Version", "bat.batman.version",
682 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
685 { &hf_bat_batman_flags
,
686 { "Flags", "bat.batman.flags",
687 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
690 { &hf_bat_batman_ttl
,
691 { "Time to Live", "bat.batman.ttl",
692 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
695 { &hf_bat_batman_gwflags
,
696 { "Gateway Flags", "bat.batman.gwflags",
697 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
700 { &hf_bat_batman_gwflags_dl_speed
,
701 { "Download Speed", "bat.batman.gwflags.dl_speed",
702 FT_UINT32
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_kbit
), 0x0,
705 { &hf_bat_batman_gwflags_ul_speed
,
706 { "Upload Speed", "bat.batman.gwflags.ul_speed",
707 FT_UINT32
, BASE_DEC
|BASE_UNIT_STRING
, UNS(&units_kbit
), 0x0,
710 { &hf_bat_batman_seqno
,
711 { "Sequence number", "bat.batman.seq",
712 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
715 { &hf_bat_batman_gwport
,
716 { "Gateway Port", "bat.batman.gwport",
717 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
720 { &hf_bat_batman_orig
,
721 { "Originator", "bat.batman.orig",
722 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
725 { &hf_bat_batman_old_orig
,
726 { "Received from", "bat.batman.old_orig",
727 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
731 { "Transmission Quality", "bat.batman.tq",
732 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
735 { &hf_bat_batman_hna_len
,
736 { "Number of HNAs", "bat.batman.hna_len",
737 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
740 { &hf_bat_batman_flags_unidirectional
,
741 { "Unidirectional", "bat.batman.flags.unidirectional",
742 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), 0x80,
745 { &hf_bat_batman_flags_directlink
,
746 { "DirectLink", "bat.batman.flags.directlink",
747 FT_BOOLEAN
, 8, TFS(&tfs_set_notset
), 0x40,
750 { &hf_bat_batman_hna_network
,
751 { "HNA Network", "bat.batman.hna_network",
752 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
755 { &hf_bat_batman_hna_netmask
,
756 { "HNA Netmask", "bat.batman.hna_netmask",
757 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
761 { "Type", "bat.gw.type",
762 FT_UINT8
, BASE_DEC
, VALS(gw_packettypenames
), 0x0,
767 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
770 { &hf_bat_vis_vis_orig
,
771 { "Originator", "bat.vis.sender_ip",
772 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
775 { &hf_bat_vis_version
,
776 { "Version", "bat.vis.version",
777 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
780 { &hf_bat_vis_gwflags
,
781 { "Gateway Flags", "bat.vis.gwflags",
782 FT_UINT8
, BASE_HEX
, NULL
, 0x0,
785 { &hf_bat_max_tq_v22
,
786 { "Maximum Transmission Quality", "bat.vis.tq_max",
787 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
790 { &hf_bat_max_tq_v23
,
791 { "Maximum Transmission Quality", "bat.vis.tq_max",
792 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
795 { &hf_bat_vis_data_type
,
796 { "Type", "bat.vis.data_type",
797 FT_UINT8
, BASE_DEC
, VALS(vis_packettypenames
), 0x0,
800 { &hf_bat_vis_tq_v22
,
801 { "Transmission Quality", "bat.vis.tq",
802 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
805 { &hf_bat_vis_tq_v23
,
806 { "Transmission Quality", "bat.vis.tq",
807 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
810 { &hf_bat_vis_netmask
,
811 { "Netmask", "bat.vis.netmask",
812 FT_UINT8
, BASE_DEC
, NULL
, 0x0,
815 { &hf_bat_vis_data_ip
,
816 { "IP", "bat.vis.data_ip",
817 FT_IPv4
, BASE_NONE
, NULL
, 0x0,
822 /* Setup protocol subtree array */
823 static int *ett
[] = {
825 &ett_bat_batman_flags
,
826 &ett_bat_batman_gwflags
,
833 proto_bat_plugin
= proto_register_protocol("B.A.T.M.A.N. Layer 3 Protocol", "BAT", "bat");
834 proto_bat_gw
= proto_register_protocol("B.A.T.M.A.N. GW", "BAT GW", "bat.gw");
835 proto_bat_vis
= proto_register_protocol("B.A.T.M.A.N. Vis", "BAT VIS", "bat.vis");
837 batman_handle
= register_dissector("bat", dissect_bat_batman
, proto_bat_plugin
);
838 gw_handle
= register_dissector("bat.gw", dissect_bat_gw
, proto_bat_gw
);
839 vis_handle
= register_dissector("bat.vis", dissect_bat_vis
, proto_bat_vis
);
841 proto_register_field_array(proto_bat_plugin
, hf
, array_length(hf
));
842 proto_register_subtree_array(ett
, array_length(ett
));
844 bat_tap
= register_tap("batman");
845 bat_follow_tap
= register_tap("batman_follow");
848 void proto_reg_handoff_bat(void)
850 ip_handle
= find_dissector_add_dependency("ip", proto_bat_gw
);
852 dissector_add_uint_with_preference("udp.port", BAT_BATMAN_PORT
, batman_handle
);
853 dissector_add_uint_with_preference("udp.port", BAT_GW_PORT
, gw_handle
);
854 dissector_add_uint_with_preference("udp.port", BAT_VIS_PORT
, vis_handle
);
858 * Editor modelines - https://www.wireshark.org/tools/modelines.html
863 * indent-tabs-mode: t
866 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
867 * :indentSize=8:tabSize=8:noTabs=false: