~jelmer/wireshark/daily-ppa

« back to all changes in this revision

Viewing changes to epan/dissectors/packet-batadv.c

  • Committer: Bazaar Package Importer
  • Author(s): Balint Reczey
  • Date: 2010-11-20 18:41:41 UTC
  • mfrom: (1.1.28 upstream) (42.1.5 experimental)
  • Revision ID: james.westby@ubuntu.com-20101120184141-19e4sxq2kfsdnc9i
Tags: 1.4.2-1
* New upstream release 1.4.2
  - release notes:
    http://www.wireshark.org/docs/relnotes/wireshark-1.4.2.html
  - security fixes
     - Nephi Johnson of BreakingPoint discovered that the LDSS dissector
       could overflow a buffer. (No assigned CVE number.)
     - The ZigBee ZCL dissector could go into an infinite loop.
       (No assigned CVE number.)
* drop 05_fix-display-filter-update-when-changing-profile.patch
  patch since it has been integrated upstream

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* packet-batadv.c
 
2
 * Routines for B.A.T.M.A.N. Advanced dissection
 
3
 * Copyright 2008-2010  Sven Eckelmann <sven.eckelmann@gmx.de>
 
4
 *
 
5
 * $Id: packet-batadv.c 33075 2010-06-03 18:56:39Z wmeier $
 
6
 *
 
7
 * Wireshark - Network traffic analyzer
 
8
 * By Gerald Combs <gerald@wireshark.org>
 
9
 * Copyright 1998 Gerald Combs
 
10
 *
 
11
 * This program is free software; you can redistribute it and/or
 
12
 * modify it under the terms of the GNU General Public License
 
13
 * as published by the Free Software Foundation; either version 2
 
14
 * of the License, or (at your option) any later version.
 
15
 *
 
16
 * This program is distributed in the hope that it will be useful,
 
17
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
18
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
19
 * GNU General Public License for more details.
 
20
 *
 
21
 * You should have received a copy of the GNU General Public License
 
22
 * along with this program; if not, write to the Free Software
 
23
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
24
 */
 
25
 
 
26
#ifdef HAVE_CONFIG_H
 
27
# include "config.h"
 
28
#endif
 
29
 
 
30
#include <epan/packet.h>
 
31
#include <epan/prefs.h>
 
32
#include <epan/tap.h>
 
33
#include <epan/addr_resolv.h>
 
34
 
 
35
/* Start content from packet-batadv.h */
 
36
#define ETH_P_BATMAN  0x4305
 
37
 
 
38
#define BATADV_PACKET    0x01
 
39
#define BATADV_ICMP      0x02
 
40
#define BATADV_UNICAST   0x03
 
41
#define BATADV_BCAST     0x04
 
42
#define BATADV_VIS       0x05
 
43
 
 
44
#define ECHO_REPLY 0
 
45
#define DESTINATION_UNREACHABLE 3
 
46
#define ECHO_REQUEST 8
 
47
#define TTL_EXCEEDED 11
 
48
 
 
49
struct batman_packet_v5 {
 
50
        guint8  packet_type;
 
51
        guint8  version;  /* batman version field */
 
52
        guint8  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
 
53
        guint8  ttl;
 
54
        guint8  gwflags;  /* flags related to gateway functions: gateway class */
 
55
        guint8  tq;
 
56
        guint16 seqno;
 
57
        address orig;
 
58
        address prev_sender;
 
59
        guint8  num_hna;
 
60
        guint8  pad;
 
61
};
 
62
#define BATMAN_PACKET_V5_SIZE 22
 
63
 
 
64
struct batman_packet_v7 {
 
65
        guint8  packet_type;
 
66
        guint8  version;  /* batman version field */
 
67
        guint8  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
 
68
        guint8  tq;
 
69
        guint16 seqno;
 
70
        address orig;
 
71
        address prev_sender;
 
72
        guint8  ttl;
 
73
        guint8  num_hna;
 
74
};
 
75
#define BATMAN_PACKET_V7_SIZE 20
 
76
 
 
77
struct batman_packet_v9 {
 
78
        guint8  packet_type;
 
79
        guint8  version;  /* batman version field */
 
80
        guint8  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
 
81
        guint8  tq;
 
82
        guint16 seqno;
 
83
        address orig;
 
84
        address prev_sender;
 
85
        guint8  ttl;
 
86
        guint8  num_hna;
 
87
        guint8  gwflags;
 
88
        guint8  pad;
 
89
};
 
90
#define BATMAN_PACKET_V9_SIZE 22
 
91
 
 
92
struct batman_packet_v10 {
 
93
        guint8  packet_type;
 
94
        guint8  version;  /* batman version field */
 
95
        guint8  flags;    /* 0x40: DIRECTLINK flag, 0x20 VIS_SERVER flag... */
 
96
        guint8  tq;
 
97
        guint32 seqno;
 
98
        address orig;
 
99
        address prev_sender;
 
100
        guint8  ttl;
 
101
        guint8  num_hna;
 
102
        guint8  gwflags;
 
103
        guint8  pad;
 
104
};
 
105
#define BATMAN_PACKET_V10_SIZE 24
 
106
 
 
107
struct icmp_packet_v6 {
 
108
        guint8  packet_type;
 
109
        guint8  version;  /* batman version field */
 
110
        guint8  msg_type;   /* 0 = ECHO REPLY, 3 = DESTINATION_UNREACHABLE, 8 = ECHO_REQUEST, 11 = TTL exceeded */
 
111
        address dst;
 
112
        address orig;
 
113
        guint8  ttl;
 
114
        guint8  uid;
 
115
        guint16 seqno;
 
116
};
 
117
#define ICMP_PACKET_V6_SIZE 19
 
118
 
 
119
struct icmp_packet_v7 {
 
120
        guint8  packet_type;
 
121
        guint8  version;  /* batman version field */
 
122
        guint8  msg_type;   /* 0 = ECHO REPLY, 3 = DESTINATION_UNREACHABLE, 8 = ECHO_REQUEST, 11 = TTL exceeded */
 
123
        guint8  ttl;
 
124
        address dst;
 
125
        address orig;
 
126
        guint16 seqno;
 
127
        guint8  uid;
 
128
};
 
129
#define ICMP_PACKET_V7_SIZE 18
 
130
 
 
131
struct unicast_packet_v6 {
 
132
        guint8  packet_type;
 
133
        guint8  version;
 
134
        address dest;
 
135
        guint8  ttl;
 
136
};
 
137
#define UNICAST_PACKET_V6_SIZE 9
 
138
 
 
139
struct bcast_packet_v6 {
 
140
        guint8  packet_type;
 
141
        guint8  version;  /* batman version field */
 
142
        address orig;
 
143
        guint16 seqno;
 
144
};
 
145
#define BCAST_PACKET_V6_SIZE 10
 
146
 
 
147
struct bcast_packet_v10 {
 
148
        guint8  packet_type;
 
149
        guint8  version;  /* batman version field */
 
150
        address orig;
 
151
        guint8  ttl;
 
152
        guint32 seqno;
 
153
};
 
154
#define BCAST_PACKET_V10_SIZE 13
 
155
 
 
156
struct vis_packet_v6 {
 
157
        guint8  packet_type;
 
158
        guint8  version;      /* batman version field */
 
159
        guint8  vis_type;     /* which type of vis-participant sent this? */
 
160
        guint8  seqno;        /* sequence number */
 
161
        guint8  entries;      /* number of entries behind this struct */
 
162
        guint8  ttl;          /* TTL */
 
163
        address vis_orig;     /* originator that informs about its neighbours */
 
164
        address target_orig;  /* who should receive this packet */
 
165
        address sender_orig;  /* who sent or rebroadcasted this packet */
 
166
};
 
167
#define VIS_PACKET_V6_SIZE 24
 
168
 
 
169
struct vis_packet_v10 {
 
170
        guint8  packet_type;
 
171
        guint8  version;      /* batman version field */
 
172
        guint8  vis_type;     /* which type of vis-participant sent this? */
 
173
        guint8  entries;      /* number of entries behind this struct */
 
174
        guint32 seqno;        /* sequence number */
 
175
        guint8  ttl;          /* TTL */
 
176
        address vis_orig;     /* originator that informs about its neighbours */
 
177
        address target_orig;  /* who should receive this packet */
 
178
        address sender_orig;  /* who sent or rebroadcasted this packet */
 
179
};
 
180
#define VIS_PACKET_V10_SIZE 27
 
181
 
 
182
#define VIS_ENTRY_V6_SIZE 7
 
183
#define VIS_ENTRY_V8_SIZE 13
 
184
 
 
185
#define VIS_TYPE_SERVER_SYNC  0
 
186
#define VIS_TYPE_CLIENT_UPDATE  1
 
187
/* End content from packet-batadv.h */
 
188
 
 
189
/* trees */
 
190
static gint ett_batadv_batman = -1;
 
191
static gint ett_batadv_batman_flags = -1;
 
192
static gint ett_batadv_batman_gwflags = -1;
 
193
static gint ett_batadv_batman_hna = -1;
 
194
static gint ett_batadv_bcast = -1;
 
195
static gint ett_batadv_icmp = -1;
 
196
static gint ett_batadv_unicast = -1;
 
197
static gint ett_batadv_vis = -1;
 
198
static gint ett_batadv_vis_entry = -1;
 
199
 
 
200
/* hfs */
 
201
static int hf_batadv_packet_type = -1;
 
202
 
 
203
static int hf_batadv_batman_version = -1;
 
204
static int hf_batadv_batman_flags = -1;
 
205
static int hf_batadv_batman_ttl = -1;
 
206
static int hf_batadv_batman_gwflags = -1;
 
207
static int hf_batadv_batman_tq = -1;
 
208
static int hf_batadv_batman_seqno = -1;
 
209
static int hf_batadv_batman_seqno32 = -1;
 
210
static int hf_batadv_batman_orig = -1;
 
211
static int hf_batadv_batman_prev_sender = -1;
 
212
static int hf_batadv_batman_num_hna = -1;
 
213
static int hf_batadv_batman_pad = -1;
 
214
static int hf_batadv_batman_hna = -1;
 
215
 
 
216
static int hf_batadv_bcast_version = -1;
 
217
static int hf_batadv_bcast_pad = -1;
 
218
static int hf_batadv_bcast_orig = -1;
 
219
static int hf_batadv_bcast_seqno = -1;
 
220
static int hf_batadv_bcast_seqno32 = -1;
 
221
static int hf_batadv_bcast_ttl = -1;
 
222
 
 
223
static int hf_batadv_icmp_version = -1;
 
224
static int hf_batadv_icmp_msg_type = -1;
 
225
static int hf_batadv_icmp_dst = -1;
 
226
static int hf_batadv_icmp_orig = -1;
 
227
static int hf_batadv_icmp_ttl = -1;
 
228
static int hf_batadv_icmp_uid = -1;
 
229
static int hf_batadv_icmp_seqno = -1;
 
230
 
 
231
static int hf_batadv_unicast_version = -1;
 
232
static int hf_batadv_unicast_dst = -1;
 
233
static int hf_batadv_unicast_ttl = -1;
 
234
 
 
235
static int hf_batadv_vis_version = -1;
 
236
static int hf_batadv_vis_type = -1;
 
237
static int hf_batadv_vis_seqno = -1;
 
238
static int hf_batadv_vis_seqno32 = -1;
 
239
static int hf_batadv_vis_entries = -1;
 
240
static int hf_batadv_vis_ttl = -1;
 
241
static int hf_batadv_vis_vis_orig = -1;
 
242
static int hf_batadv_vis_target_orig = -1;
 
243
static int hf_batadv_vis_sender_orig = -1;
 
244
static int hf_batadv_vis_entry_src = -1;
 
245
static int hf_batadv_vis_entry_dst = -1;
 
246
static int hf_batadv_vis_entry_quality = -1;
 
247
 
 
248
/* flags */
 
249
static int hf_batadv_batman_flags_directlink = -1;
 
250
static int hf_batadv_batman_flags_vis_server = -1;
 
251
static int hf_batadv_batman_flags_primaries_first_hop = -1;
 
252
 
 
253
static const value_string icmp_packettypenames[] = {
 
254
        { ECHO_REPLY, "ECHO_REPLY" },
 
255
        { DESTINATION_UNREACHABLE, "DESTINATION UNREACHABLE" },
 
256
        { ECHO_REQUEST, "ECHO_REQUEST" },
 
257
        { TTL_EXCEEDED, "TTL exceeded" },
 
258
        { 0, NULL }
 
259
};
 
260
 
 
261
static const value_string vis_packettypenames[] = {
 
262
        { VIS_TYPE_SERVER_SYNC, "SERVER_SYNC" },
 
263
        { VIS_TYPE_CLIENT_UPDATE, "CLIENT_UPDATE" },
 
264
        { 0, NULL }
 
265
};
 
266
 
 
267
 
 
268
/* forward declaration */
 
269
void proto_reg_handoff_batadv(void);
 
270
 
 
271
static dissector_handle_t batman_handle;
 
272
 
 
273
/* supported packet dissectors */
 
274
static void dissect_batadv_batman(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
275
static int dissect_batadv_batman_v5(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
 
276
static int dissect_batadv_batman_v7(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
 
277
static int dissect_batadv_batman_v9(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
 
278
static int dissect_batadv_batman_v10(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree);
 
279
 
 
280
static void dissect_batadv_bcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
281
static void dissect_batadv_bcast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
282
static void dissect_batadv_bcast_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
283
 
 
284
static void dissect_batadv_icmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
285
static void dissect_batadv_icmp_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
286
static void dissect_batadv_icmp_v7(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
287
 
 
288
static void dissect_batadv_unicast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
289
static void dissect_batadv_unicast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
290
 
 
291
static void dissect_batadv_vis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
292
static void dissect_batadv_vis_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
293
static void dissect_batadv_vis_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
294
 
 
295
static void dissect_batadv_hna(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
296
static void dissect_vis_entry_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
297
static void dissect_vis_entry_v8(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
 
298
 
 
299
/* other dissectors */
 
300
static dissector_handle_t data_handle;
 
301
static dissector_handle_t eth_handle;
 
302
 
 
303
static int proto_batadv_plugin = -1;
 
304
 
 
305
/* tap */
 
306
static int batadv_tap = -1;
 
307
static int batadv_follow_tap = -1;
 
308
 
 
309
static unsigned int batadv_ethertype = ETH_P_BATMAN;
 
310
 
 
311
static void dissect_batman_plugin(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
312
{
 
313
        guint8 type;
 
314
 
 
315
        col_clear(pinfo->cinfo, COL_INFO);
 
316
 
 
317
        type = tvb_get_guint8(tvb, 0);
 
318
 
 
319
        switch (type) {
 
320
        case BATADV_PACKET:
 
321
                dissect_batadv_batman(tvb, pinfo, tree);
 
322
                break;
 
323
        case BATADV_ICMP:
 
324
                dissect_batadv_icmp(tvb, pinfo, tree);
 
325
                break;
 
326
        case BATADV_UNICAST:
 
327
                dissect_batadv_unicast(tvb, pinfo, tree);
 
328
                break;
 
329
        case BATADV_BCAST:
 
330
                dissect_batadv_bcast(tvb, pinfo, tree);
 
331
                break;
 
332
        case BATADV_VIS:
 
333
                dissect_batadv_vis(tvb, pinfo, tree);
 
334
                break;
 
335
        default:
 
336
                /* dunno */
 
337
        {
 
338
                tvbuff_t *next_tvb;
 
339
                guint length_remaining;
 
340
 
 
341
                col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_???");
 
342
 
 
343
                length_remaining = tvb_length_remaining(tvb, 1);
 
344
                next_tvb = tvb_new_subset(tvb, 0, length_remaining, -1);
 
345
                call_dissector(data_handle, next_tvb, pinfo, tree);
 
346
                break;
 
347
        }
 
348
        }
 
349
}
 
350
 
 
351
static void dissect_batadv_batman(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
352
{
 
353
        guint8 version;
 
354
        int offset = 0;
 
355
 
 
356
        /* set protocol name */
 
357
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_BATMAN");
 
358
 
 
359
        version = tvb_get_guint8(tvb, 1);
 
360
        switch (version) {
 
361
        case 5:
 
362
        case 6:
 
363
                while (offset != -1 && tvb_length_remaining(tvb, offset) >= BATMAN_PACKET_V5_SIZE) {
 
364
                        offset = dissect_batadv_batman_v5(tvb, offset, pinfo, tree);
 
365
                }
 
366
                break;
 
367
        case 7:
 
368
        case 8:
 
369
                while (offset != -1 && tvb_length_remaining(tvb, offset) >= BATMAN_PACKET_V7_SIZE) {
 
370
                        offset = dissect_batadv_batman_v7(tvb, offset, pinfo, tree);
 
371
                }
 
372
                break;
 
373
        case 9:
 
374
                while (offset != -1 && tvb_length_remaining(tvb, offset) >= BATMAN_PACKET_V9_SIZE) {
 
375
                        offset = dissect_batadv_batman_v9(tvb, offset, pinfo, tree);
 
376
                }
 
377
                break;
 
378
        case 10:
 
379
                while (offset != -1 && tvb_length_remaining(tvb, offset) >= BATMAN_PACKET_V10_SIZE) {
 
380
                        offset = dissect_batadv_batman_v10(tvb, offset, pinfo, tree);
 
381
                }
 
382
                break;
 
383
        default:
 
384
                col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported Version %d", version);
 
385
                call_dissector(data_handle, tvb, pinfo, tree);
 
386
                break;
 
387
        }
 
388
}
 
389
 
 
390
static void dissect_batadv_gwflags(tvbuff_t *tvb, guint8 gwflags, int offset, proto_item *tgw)
 
391
{
 
392
        proto_tree *gwflags_tree;
 
393
        guint8 s = (gwflags & 0x80) >> 7;
 
394
        guint8 downbits = (gwflags & 0x78) >> 3;
 
395
        guint8 upbits = (gwflags & 0x07);
 
396
        guint down, up;
 
397
 
 
398
        if (gwflags == 0) {
 
399
                down = 0;
 
400
                up = 0;
 
401
        } else {
 
402
                down = 32 * (s + 2) * (1 << downbits);
 
403
                up = ((upbits + 1) * down) / 8;
 
404
        }
 
405
 
 
406
        gwflags_tree =  proto_item_add_subtree(tgw, ett_batadv_batman_gwflags);
 
407
        proto_tree_add_text(gwflags_tree, tvb, offset, 1, "Download Speed: %dkbit", down);
 
408
        proto_tree_add_text(gwflags_tree, tvb, offset, 1, "Upload Speed: %dkbit", up);
 
409
 
 
410
}
 
411
 
 
412
static int dissect_batadv_batman_v5(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
 
413
{
 
414
        proto_item *tf, *tgw;
 
415
        proto_tree *batadv_batman_tree = NULL, *flag_tree;
 
416
        guint8 type;
 
417
        struct batman_packet_v5 *batman_packeth;
 
418
        const guint8  *prev_sender_addr, *orig_addr;
 
419
        gint i;
 
420
 
 
421
        tvbuff_t *next_tvb;
 
422
 
 
423
        batman_packeth = ep_alloc(sizeof(struct batman_packet_v5));
 
424
 
 
425
        type = tvb_get_guint8(tvb, offset+0);
 
426
        batman_packeth->version = tvb_get_guint8(tvb, offset+1);
 
427
 
 
428
        /* don't interpret padding as B.A.T.M.A.N. advanced packet */
 
429
        if (batman_packeth->version == 0 || type != BATADV_PACKET) {
 
430
                return -1;
 
431
        }
 
432
 
 
433
        batman_packeth->flags = tvb_get_guint8(tvb, offset+2);
 
434
        batman_packeth->ttl = tvb_get_guint8(tvb, offset+3);
 
435
        batman_packeth->gwflags = tvb_get_guint8(tvb, offset+4);
 
436
        batman_packeth->tq = tvb_get_guint8(tvb, offset+5);
 
437
        batman_packeth->seqno = tvb_get_ntohs(tvb, offset+6);
 
438
        orig_addr = tvb_get_ptr(tvb, offset+8, 6);
 
439
        SET_ADDRESS(&batman_packeth->orig, AT_ETHER, 6, orig_addr);
 
440
        prev_sender_addr = tvb_get_ptr(tvb, offset+14, 6);
 
441
        SET_ADDRESS(&batman_packeth->prev_sender, AT_ETHER, 6, prev_sender_addr);
 
442
        batman_packeth->num_hna = tvb_get_guint8(tvb, offset+20);
 
443
        batman_packeth->pad = tvb_get_guint8(tvb, offset+21);
 
444
 
 
445
        /* Set info column */
 
446
        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq=%u", batman_packeth->seqno);
 
447
 
 
448
        /* Set tree info */
 
449
        if (tree) {
 
450
                proto_item *ti;
 
451
 
 
452
                if (PTREE_DATA(tree)->visible) {
 
453
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V5_SIZE,
 
454
                                                            "B.A.T.M.A.N., Orig: %s (%s)",
 
455
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr));
 
456
                } else {
 
457
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V5_SIZE, FALSE);
 
458
                }
 
459
                batadv_batman_tree = proto_item_add_subtree(ti, ett_batadv_batman);
 
460
        }
 
461
 
 
462
        /* items */
 
463
        proto_tree_add_uint_format(batadv_batman_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_PACKET,
 
464
                                        "Packet Type: %s (%u)", "BATADV_PACKET", BATADV_PACKET);
 
465
        offset += 1;
 
466
 
 
467
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_version, tvb, offset, 1, FALSE);
 
468
        offset += 1;
 
469
 
 
470
        tf = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_flags, tvb, offset, 1, FALSE);
 
471
        /* <flags> */
 
472
        flag_tree =  proto_item_add_subtree(tf, ett_batadv_batman_flags);
 
473
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_directlink, tvb, offset, 1, batman_packeth->flags);
 
474
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_vis_server, tvb, offset, 1, batman_packeth->flags);
 
475
        /* </flags> */
 
476
        offset += 1;
 
477
 
 
478
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_ttl, tvb, offset, 1, FALSE);
 
479
        offset += 1;
 
480
 
 
481
        tgw = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_gwflags, tvb, offset, 1, FALSE);
 
482
        dissect_batadv_gwflags(tvb, batman_packeth->gwflags, offset, tgw);
 
483
        offset += 1;
 
484
 
 
485
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_tq, tvb, offset, 1, FALSE);
 
486
        offset += 1;
 
487
 
 
488
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_seqno, tvb, offset, 2, FALSE);
 
489
        offset += 2;
 
490
 
 
491
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_orig, tvb, offset, 6, orig_addr);
 
492
        offset += 6;
 
493
 
 
494
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_prev_sender, tvb, offset, 6, prev_sender_addr);
 
495
        offset += 6;
 
496
 
 
497
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_num_hna, tvb, offset, 1, FALSE);
 
498
        offset += 1;
 
499
 
 
500
        /* Hidden: proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_pad, tvb, offset, 1, FALSE); */
 
501
        offset += 1;
 
502
 
 
503
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
504
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
505
 
 
506
        tap_queue_packet(batadv_tap, pinfo, batman_packeth);
 
507
 
 
508
        for (i = 0; i < batman_packeth->num_hna; i++) {
 
509
                next_tvb = tvb_new_subset(tvb, offset, 6, 6);
 
510
 
 
511
                if (have_tap_listener(batadv_follow_tap)) {
 
512
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
513
                }
 
514
 
 
515
                dissect_batadv_hna(next_tvb, pinfo, batadv_batman_tree);
 
516
                offset += 6;
 
517
        }
 
518
 
 
519
        return offset;
 
520
}
 
521
 
 
522
static int dissect_batadv_batman_v7(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
 
523
{
 
524
        proto_item *tf;
 
525
        proto_tree *batadv_batman_tree = NULL, *flag_tree;
 
526
        guint8 type;
 
527
        struct batman_packet_v7 *batman_packeth;
 
528
        const guint8  *prev_sender_addr, *orig_addr;
 
529
        gint i;
 
530
 
 
531
        tvbuff_t *next_tvb;
 
532
 
 
533
        batman_packeth = ep_alloc(sizeof(struct batman_packet_v7));
 
534
 
 
535
        type = tvb_get_guint8(tvb, offset+0);
 
536
        batman_packeth->version = tvb_get_guint8(tvb, offset+1);
 
537
 
 
538
        /* don't interpret padding as B.A.T.M.A.N. advanced packet */
 
539
        if (batman_packeth->version == 0 || type != BATADV_PACKET) {
 
540
                return -1;
 
541
        }
 
542
 
 
543
        batman_packeth->flags = tvb_get_guint8(tvb, offset+2);
 
544
        batman_packeth->tq = tvb_get_guint8(tvb, offset+3);
 
545
        batman_packeth->seqno = tvb_get_ntohs(tvb, offset+4);
 
546
        orig_addr = tvb_get_ptr(tvb, offset+6, 6);
 
547
        SET_ADDRESS(&batman_packeth->orig, AT_ETHER, 6, orig_addr);
 
548
        prev_sender_addr = tvb_get_ptr(tvb, offset+12, 6);
 
549
        SET_ADDRESS(&batman_packeth->prev_sender, AT_ETHER, 6, prev_sender_addr);
 
550
        batman_packeth->ttl = tvb_get_guint8(tvb, offset+18);
 
551
        batman_packeth->num_hna = tvb_get_guint8(tvb, offset+19);
 
552
 
 
553
        /* Set info column */
 
554
        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq=%u", batman_packeth->seqno);
 
555
 
 
556
        /* Set tree info */
 
557
        if (tree) {
 
558
                proto_item *ti;
 
559
 
 
560
                if (PTREE_DATA(tree)->visible) {
 
561
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V7_SIZE,
 
562
                                                            "B.A.T.M.A.N., Orig: %s (%s)",
 
563
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr));
 
564
                } else {
 
565
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V7_SIZE, FALSE);
 
566
                }
 
567
                batadv_batman_tree = proto_item_add_subtree(ti, ett_batadv_batman);
 
568
        }
 
569
 
 
570
        /* items */
 
571
        proto_tree_add_uint_format(batadv_batman_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_PACKET,
 
572
                                        "Packet Type: %s (%u)", "BATADV_PACKET", BATADV_PACKET);
 
573
        offset += 1;
 
574
 
 
575
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_version, tvb, offset, 1, FALSE);
 
576
        offset += 1;
 
577
 
 
578
        tf = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_flags, tvb, offset, 1, FALSE);
 
579
        /* <flags> */
 
580
        flag_tree =  proto_item_add_subtree(tf, ett_batadv_batman_flags);
 
581
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_directlink, tvb, offset, 1, batman_packeth->flags);
 
582
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_vis_server, tvb, offset, 1, batman_packeth->flags);
 
583
        /* </flags> */
 
584
        offset += 1;
 
585
 
 
586
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_tq, tvb, offset, 1, FALSE);
 
587
        offset += 1;
 
588
 
 
589
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_seqno, tvb, offset, 2, FALSE);
 
590
        offset += 2;
 
591
 
 
592
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_orig, tvb, offset, 6, orig_addr);
 
593
        offset += 6;
 
594
 
 
595
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_prev_sender, tvb, offset, 6, prev_sender_addr);
 
596
        offset += 6;
 
597
 
 
598
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_ttl, tvb, offset, 1, FALSE);
 
599
        offset += 1;
 
600
 
 
601
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_num_hna, tvb, offset, 1, FALSE);
 
602
        offset += 1;
 
603
 
 
604
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
605
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
606
 
 
607
        tap_queue_packet(batadv_tap, pinfo, batman_packeth);
 
608
 
 
609
        for (i = 0; i < batman_packeth->num_hna; i++) {
 
610
                next_tvb = tvb_new_subset(tvb, offset, 6, 6);
 
611
 
 
612
                if (have_tap_listener(batadv_follow_tap)) {
 
613
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
614
                }
 
615
 
 
616
                dissect_batadv_hna(next_tvb, pinfo, batadv_batman_tree);
 
617
                offset += 6;
 
618
        }
 
619
 
 
620
        return offset;
 
621
}
 
622
 
 
623
static int dissect_batadv_batman_v9(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
 
624
{
 
625
        proto_item *tf, *tgw;
 
626
        proto_tree *batadv_batman_tree = NULL, *flag_tree;
 
627
        guint8 type;
 
628
        struct batman_packet_v9 *batman_packeth;
 
629
        const guint8  *prev_sender_addr, *orig_addr;
 
630
        gint i;
 
631
 
 
632
        tvbuff_t *next_tvb;
 
633
 
 
634
        batman_packeth = ep_alloc(sizeof(struct batman_packet_v9));
 
635
 
 
636
        type = tvb_get_guint8(tvb, offset+0);
 
637
        batman_packeth->version = tvb_get_guint8(tvb, offset+1);
 
638
 
 
639
        /* don't interpret padding as B.A.T.M.A.N. advanced packet */
 
640
        if (batman_packeth->version == 0 || type != BATADV_PACKET) {
 
641
                return -1;
 
642
        }
 
643
 
 
644
        batman_packeth->flags = tvb_get_guint8(tvb, offset+2);
 
645
        batman_packeth->tq = tvb_get_guint8(tvb, offset+3);
 
646
        batman_packeth->seqno = tvb_get_ntohs(tvb, offset+4);
 
647
        orig_addr = tvb_get_ptr(tvb, offset+6, 6);
 
648
        SET_ADDRESS(&batman_packeth->orig, AT_ETHER, 6, orig_addr);
 
649
        prev_sender_addr = tvb_get_ptr(tvb, offset+12, 6);
 
650
        SET_ADDRESS(&batman_packeth->prev_sender, AT_ETHER, 6, prev_sender_addr);
 
651
        batman_packeth->ttl = tvb_get_guint8(tvb, offset+18);
 
652
        batman_packeth->num_hna = tvb_get_guint8(tvb, offset+19);
 
653
        batman_packeth->gwflags = tvb_get_guint8(tvb, offset+20);
 
654
 
 
655
        /* Set info column */
 
656
        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq=%u", batman_packeth->seqno);
 
657
 
 
658
        /* Set tree info */
 
659
        if (tree) {
 
660
                proto_item *ti;
 
661
 
 
662
                if (PTREE_DATA(tree)->visible) {
 
663
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V9_SIZE,
 
664
                                                            "B.A.T.M.A.N., Orig: %s (%s)",
 
665
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr));
 
666
                } else {
 
667
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V9_SIZE, FALSE);
 
668
                }
 
669
                batadv_batman_tree = proto_item_add_subtree(ti, ett_batadv_batman);
 
670
        }
 
671
 
 
672
        /* items */
 
673
        proto_tree_add_uint_format(batadv_batman_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_PACKET,
 
674
                                        "Packet Type: %s (%u)", "BATADV_PACKET", BATADV_PACKET);
 
675
        offset += 1;
 
676
 
 
677
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_version, tvb, offset, 1, FALSE);
 
678
        offset += 1;
 
679
 
 
680
        tf = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_flags, tvb, offset, 1, FALSE);
 
681
        /* <flags> */
 
682
        flag_tree =  proto_item_add_subtree(tf, ett_batadv_batman_flags);
 
683
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_directlink, tvb, offset, 1, batman_packeth->flags);
 
684
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_vis_server, tvb, offset, 1, batman_packeth->flags);
 
685
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_primaries_first_hop, tvb, offset, 1, batman_packeth->flags);
 
686
        /* </flags> */
 
687
        offset += 1;
 
688
 
 
689
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_tq, tvb, offset, 1, FALSE);
 
690
        offset += 1;
 
691
 
 
692
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_seqno, tvb, offset, 2, FALSE);
 
693
        offset += 2;
 
694
 
 
695
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_orig, tvb, offset, 6, orig_addr);
 
696
        offset += 6;
 
697
 
 
698
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_prev_sender, tvb, offset, 6, prev_sender_addr);
 
699
        offset += 6;
 
700
 
 
701
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_ttl, tvb, offset, 1, FALSE);
 
702
        offset += 1;
 
703
 
 
704
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_num_hna, tvb, offset, 1, FALSE);
 
705
        offset += 1;
 
706
 
 
707
        tgw = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_gwflags, tvb, offset, 1, FALSE);
 
708
        dissect_batadv_gwflags(tvb, batman_packeth->gwflags, offset, tgw);
 
709
        offset += 1;
 
710
 
 
711
        /* Hidden: proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_pad, tvb, offset, 1, FALSE); */
 
712
        offset += 1;
 
713
 
 
714
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
715
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
716
 
 
717
        tap_queue_packet(batadv_tap, pinfo, batman_packeth);
 
718
 
 
719
        for (i = 0; i < batman_packeth->num_hna; i++) {
 
720
                next_tvb = tvb_new_subset(tvb, offset, 6, 6);
 
721
 
 
722
                if (have_tap_listener(batadv_follow_tap)) {
 
723
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
724
                }
 
725
 
 
726
                dissect_batadv_hna(next_tvb, pinfo, batadv_batman_tree);
 
727
                offset += 6;
 
728
        }
 
729
 
 
730
        return offset;
 
731
}
 
732
 
 
733
static int dissect_batadv_batman_v10(tvbuff_t *tvb, int offset, packet_info *pinfo, proto_tree *tree)
 
734
{
 
735
        proto_item *tf, *tgw;
 
736
        proto_tree *batadv_batman_tree = NULL, *flag_tree;
 
737
        guint8 type;
 
738
        struct batman_packet_v10 *batman_packeth;
 
739
        const guint8  *prev_sender_addr, *orig_addr;
 
740
        gint i;
 
741
 
 
742
        tvbuff_t *next_tvb;
 
743
 
 
744
        batman_packeth = ep_alloc(sizeof(struct batman_packet_v10));
 
745
 
 
746
        type = tvb_get_guint8(tvb, offset+0);
 
747
        batman_packeth->version = tvb_get_guint8(tvb, offset+1);
 
748
 
 
749
        /* don't interpret padding as B.A.T.M.A.N. advanced packet */
 
750
        if (batman_packeth->version == 0 || type != BATADV_PACKET) {
 
751
                return -1;
 
752
        }
 
753
 
 
754
        batman_packeth->flags = tvb_get_guint8(tvb, offset+2);
 
755
        batman_packeth->tq = tvb_get_guint8(tvb, offset+3);
 
756
        batman_packeth->seqno = tvb_get_ntohl(tvb, offset+4);
 
757
        orig_addr = tvb_get_ptr(tvb, offset+8, 6);
 
758
        SET_ADDRESS(&batman_packeth->orig, AT_ETHER, 6, orig_addr);
 
759
        prev_sender_addr = tvb_get_ptr(tvb, offset+14, 6);
 
760
        SET_ADDRESS(&batman_packeth->prev_sender, AT_ETHER, 6, prev_sender_addr);
 
761
        batman_packeth->ttl = tvb_get_guint8(tvb, offset+20);
 
762
        batman_packeth->num_hna = tvb_get_guint8(tvb, offset+21);
 
763
        batman_packeth->gwflags = tvb_get_guint8(tvb, offset+22);
 
764
 
 
765
        /* Set info column */
 
766
        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq=%u", batman_packeth->seqno);
 
767
 
 
768
        /* Set tree info */
 
769
        if (tree) {
 
770
                proto_item *ti;
 
771
 
 
772
                if (PTREE_DATA(tree)->visible) {
 
773
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V10_SIZE,
 
774
                                                            "B.A.T.M.A.N., Orig: %s (%s)",
 
775
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr));
 
776
                } else {
 
777
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, offset, BATMAN_PACKET_V10_SIZE, FALSE);
 
778
                }
 
779
                batadv_batman_tree = proto_item_add_subtree(ti, ett_batadv_batman);
 
780
        }
 
781
 
 
782
        /* items */
 
783
        proto_tree_add_uint_format(batadv_batman_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_PACKET,
 
784
                                        "Packet Type: %s (%u)", "BATADV_PACKET", BATADV_PACKET);
 
785
        offset += 1;
 
786
 
 
787
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_version, tvb, offset, 1, FALSE);
 
788
        offset += 1;
 
789
 
 
790
        tf = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_flags, tvb, offset, 1, FALSE);
 
791
        /* <flags> */
 
792
        flag_tree =  proto_item_add_subtree(tf, ett_batadv_batman_flags);
 
793
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_directlink, tvb, offset, 1, batman_packeth->flags);
 
794
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_vis_server, tvb, offset, 1, batman_packeth->flags);
 
795
        proto_tree_add_boolean(flag_tree, hf_batadv_batman_flags_primaries_first_hop, tvb, offset, 1, batman_packeth->flags);
 
796
        /* </flags> */
 
797
        offset += 1;
 
798
 
 
799
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_tq, tvb, offset, 1, FALSE);
 
800
        offset += 1;
 
801
 
 
802
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_seqno32, tvb, offset, 4, FALSE);
 
803
        offset += 4;
 
804
 
 
805
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_orig, tvb, offset, 6, orig_addr);
 
806
        offset += 6;
 
807
 
 
808
        proto_tree_add_ether(batadv_batman_tree, hf_batadv_batman_prev_sender, tvb, offset, 6, prev_sender_addr);
 
809
        offset += 6;
 
810
 
 
811
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_ttl, tvb, offset, 1, FALSE);
 
812
        offset += 1;
 
813
 
 
814
        proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_num_hna, tvb, offset, 1, FALSE);
 
815
        offset += 1;
 
816
 
 
817
        tgw = proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_gwflags, tvb, offset, 1, FALSE);
 
818
        dissect_batadv_gwflags(tvb, batman_packeth->gwflags, offset, tgw);
 
819
        offset += 1;
 
820
 
 
821
        /* Hidden: proto_tree_add_item(batadv_batman_tree, hf_batadv_batman_pad, tvb, offset, 1, FALSE); */
 
822
        offset += 1;
 
823
 
 
824
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
825
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
826
 
 
827
        tap_queue_packet(batadv_tap, pinfo, batman_packeth);
 
828
 
 
829
        for (i = 0; i < batman_packeth->num_hna; i++) {
 
830
                next_tvb = tvb_new_subset(tvb, offset, 6, 6);
 
831
 
 
832
                if (have_tap_listener(batadv_follow_tap)) {
 
833
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
834
                }
 
835
 
 
836
                dissect_batadv_hna(next_tvb, pinfo, batadv_batman_tree);
 
837
                offset += 6;
 
838
        }
 
839
 
 
840
        return offset;
 
841
}
 
842
 
 
843
static void dissect_batadv_hna(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
 
844
{
 
845
        const guint8  *hna;
 
846
 
 
847
        hna = tvb_get_ptr(tvb, 0, 6);
 
848
 
 
849
        /* Set tree info */
 
850
        if (tree) {
 
851
                proto_item *ti;
 
852
                proto_tree *batadv_batman_hna_tree;
 
853
 
 
854
                if (PTREE_DATA(tree)->visible) {
 
855
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, 6,
 
856
                                                            "B.A.T.M.A.N. HNA: %s (%s)",
 
857
                                                            get_ether_name(hna), ether_to_str(hna));
 
858
                } else {
 
859
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, 6, FALSE);
 
860
                }
 
861
                batadv_batman_hna_tree = proto_item_add_subtree(ti, ett_batadv_batman_hna);
 
862
 
 
863
                proto_tree_add_ether(batadv_batman_hna_tree, hf_batadv_batman_hna, tvb, 0, 6, hna);
 
864
        }
 
865
}
 
866
 
 
867
static void dissect_batadv_bcast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
868
{
 
869
        guint8 version;
 
870
 
 
871
        /* set protocol name */
 
872
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_BCAST");
 
873
 
 
874
        version = tvb_get_guint8(tvb, 1);
 
875
        switch (version) {
 
876
        case 6:
 
877
        case 7:
 
878
        case 8:
 
879
        case 9:
 
880
                dissect_batadv_bcast_v6(tvb, pinfo, tree);
 
881
                break;
 
882
        case 10:
 
883
                dissect_batadv_bcast_v10(tvb, pinfo, tree);
 
884
                break;
 
885
        default:
 
886
                col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported Version %d", version);
 
887
                call_dissector(data_handle, tvb, pinfo, tree);
 
888
                break;
 
889
        }
 
890
}
 
891
 
 
892
static void dissect_batadv_bcast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
893
{
 
894
        struct bcast_packet_v6 *bcast_packeth;
 
895
        const guint8  *orig_addr;
 
896
 
 
897
        tvbuff_t *next_tvb;
 
898
        guint length_remaining;
 
899
        int offset = 0;
 
900
 
 
901
        bcast_packeth = ep_alloc(sizeof(struct bcast_packet_v6));
 
902
 
 
903
        bcast_packeth->version = tvb_get_guint8(tvb, 1);
 
904
        orig_addr = tvb_get_ptr(tvb, 2, 6);
 
905
        SET_ADDRESS(&bcast_packeth->orig, AT_ETHER, 6, orig_addr);
 
906
        bcast_packeth->seqno = tvb_get_ntohs(tvb, 8);
 
907
 
 
908
        /* Set info column */
 
909
        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq=%u", bcast_packeth->seqno);
 
910
 
 
911
        /* Set tree info */
 
912
        if (tree) {
 
913
                proto_item *ti;
 
914
                proto_tree *batadv_bcast_tree;
 
915
 
 
916
                if (PTREE_DATA(tree)->visible) {
 
917
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, BCAST_PACKET_V6_SIZE,
 
918
                                                            "B.A.T.M.A.N. Bcast, Orig: %s (%s)",
 
919
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr));
 
920
                } else {
 
921
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, BCAST_PACKET_V6_SIZE, FALSE);
 
922
                }
 
923
                batadv_bcast_tree = proto_item_add_subtree(ti, ett_batadv_bcast);
 
924
 
 
925
                /* items */
 
926
                proto_tree_add_uint_format(batadv_bcast_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_BCAST,
 
927
                                           "Packet Type: %s (%u)", "BATADV_BCAST", BATADV_BCAST);
 
928
                offset += 1;
 
929
 
 
930
                proto_tree_add_item(batadv_bcast_tree, hf_batadv_bcast_version, tvb, offset, 1, FALSE);
 
931
                offset += 1;
 
932
 
 
933
                proto_tree_add_ether(batadv_bcast_tree, hf_batadv_bcast_orig, tvb, offset, 6, orig_addr);
 
934
                offset += 6;
 
935
 
 
936
                proto_tree_add_item(batadv_bcast_tree, hf_batadv_bcast_seqno, tvb, offset, 2, FALSE);
 
937
                offset += 2;
 
938
        }
 
939
 
 
940
        /* Calculate offset even when we got no tree */
 
941
        offset = BCAST_PACKET_V6_SIZE;
 
942
 
 
943
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
944
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
945
 
 
946
        tap_queue_packet(batadv_tap, pinfo, bcast_packeth);
 
947
 
 
948
        length_remaining = tvb_length_remaining(tvb, offset);
 
949
 
 
950
        if (length_remaining != 0) {
 
951
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
952
 
 
953
                if (have_tap_listener(batadv_follow_tap)) {
 
954
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
955
                }
 
956
 
 
957
                call_dissector(eth_handle, next_tvb, pinfo, tree);
 
958
        }
 
959
}
 
960
 
 
961
static void dissect_batadv_bcast_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
962
{
 
963
        struct bcast_packet_v10 *bcast_packeth;
 
964
        const guint8  *orig_addr;
 
965
 
 
966
        tvbuff_t *next_tvb;
 
967
        guint length_remaining;
 
968
        int offset = 0;
 
969
 
 
970
        bcast_packeth = ep_alloc(sizeof(struct bcast_packet_v10));
 
971
 
 
972
        bcast_packeth->version = tvb_get_guint8(tvb, 1);
 
973
        orig_addr = tvb_get_ptr(tvb, 2, 6);
 
974
        SET_ADDRESS(&bcast_packeth->orig, AT_ETHER, 6, orig_addr);
 
975
        bcast_packeth->ttl = tvb_get_guint8(tvb, 8);
 
976
        bcast_packeth->seqno = tvb_get_ntohl(tvb, 9);
 
977
 
 
978
        /* Set info column */
 
979
        col_add_fstr(pinfo->cinfo, COL_INFO, "Seq=%u", bcast_packeth->seqno);
 
980
 
 
981
        /* Set tree info */
 
982
        if (tree) {
 
983
                proto_item *ti;
 
984
                proto_tree *batadv_bcast_tree;
 
985
 
 
986
                if (PTREE_DATA(tree)->visible) {
 
987
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, BCAST_PACKET_V10_SIZE,
 
988
                                                            "B.A.T.M.A.N. Bcast, Orig: %s (%s)",
 
989
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr));
 
990
                } else {
 
991
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, BCAST_PACKET_V10_SIZE, FALSE);
 
992
                }
 
993
                batadv_bcast_tree = proto_item_add_subtree(ti, ett_batadv_bcast);
 
994
 
 
995
                /* items */
 
996
                proto_tree_add_uint_format(batadv_bcast_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_BCAST,
 
997
                                           "Packet Type: %s (%u)", "BATADV_BCAST", BATADV_BCAST);
 
998
                offset += 1;
 
999
 
 
1000
                proto_tree_add_item(batadv_bcast_tree, hf_batadv_bcast_version, tvb, offset, 1, FALSE);
 
1001
                offset += 1;
 
1002
 
 
1003
                proto_tree_add_ether(batadv_bcast_tree, hf_batadv_bcast_orig, tvb, offset, 6, orig_addr);
 
1004
                offset += 6;
 
1005
 
 
1006
                proto_tree_add_item(batadv_bcast_tree, hf_batadv_bcast_ttl, tvb, offset, 1, FALSE);
 
1007
                offset += 1;
 
1008
 
 
1009
                proto_tree_add_item(batadv_bcast_tree, hf_batadv_bcast_seqno32, tvb, offset, 4, FALSE);
 
1010
                offset += 4;
 
1011
        }
 
1012
 
 
1013
        /* Calculate offset even when we got no tree */
 
1014
        offset = BCAST_PACKET_V10_SIZE;
 
1015
 
 
1016
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
1017
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
1018
 
 
1019
        tap_queue_packet(batadv_tap, pinfo, bcast_packeth);
 
1020
 
 
1021
        length_remaining = tvb_length_remaining(tvb, offset);
 
1022
 
 
1023
        if (length_remaining != 0) {
 
1024
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
1025
 
 
1026
                if (have_tap_listener(batadv_follow_tap)) {
 
1027
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
1028
                }
 
1029
 
 
1030
                call_dissector(eth_handle, next_tvb, pinfo, tree);
 
1031
        }
 
1032
}
 
1033
 
 
1034
static void dissect_batadv_icmp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1035
{
 
1036
        guint8 version;
 
1037
 
 
1038
        /* set protocol name */
 
1039
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_ICMP");
 
1040
 
 
1041
        version = tvb_get_guint8(tvb, 1);
 
1042
        switch (version) {
 
1043
        case 6:
 
1044
                dissect_batadv_icmp_v6(tvb, pinfo, tree);
 
1045
                break;
 
1046
        case 7:
 
1047
        case 8:
 
1048
        case 9:
 
1049
        case 10:
 
1050
                dissect_batadv_icmp_v7(tvb, pinfo, tree);
 
1051
                break;
 
1052
        default:
 
1053
                col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported Version %d", version);
 
1054
                call_dissector(data_handle, tvb, pinfo, tree);
 
1055
                break;
 
1056
        }
 
1057
}
 
1058
 
 
1059
static void dissect_batadv_icmp_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1060
{
 
1061
        struct icmp_packet_v6 *icmp_packeth;
 
1062
        const guint8  *dst_addr, *orig_addr;
 
1063
 
 
1064
        tvbuff_t *next_tvb;
 
1065
        guint length_remaining;
 
1066
        int offset = 0;
 
1067
 
 
1068
        icmp_packeth = ep_alloc(sizeof(struct icmp_packet_v6));
 
1069
 
 
1070
        icmp_packeth->version = tvb_get_guint8(tvb, 1);
 
1071
        icmp_packeth->msg_type = tvb_get_guint8(tvb, 2);
 
1072
        dst_addr = tvb_get_ptr(tvb, 3, 6);
 
1073
        SET_ADDRESS(&icmp_packeth->dst, AT_ETHER, 6, dst_addr);
 
1074
        orig_addr = tvb_get_ptr(tvb, 9, 6);
 
1075
        SET_ADDRESS(&icmp_packeth->orig, AT_ETHER, 6, orig_addr);
 
1076
        icmp_packeth->ttl = tvb_get_guint8(tvb, 15);
 
1077
        icmp_packeth->uid = tvb_get_guint8(tvb, 16);
 
1078
        icmp_packeth->seqno = tvb_get_ntohs(tvb, 17);
 
1079
 
 
1080
        /* Set info column */
 
1081
        if (check_col(pinfo->cinfo, COL_INFO)) {
 
1082
                col_add_fstr(pinfo->cinfo, COL_INFO, "[%s] Seq=%u",
 
1083
                             val_to_str(icmp_packeth->msg_type, icmp_packettypenames, "Unknown (0x%02x)"),
 
1084
                             icmp_packeth->seqno);
 
1085
        }
 
1086
        /* Set tree info */
 
1087
        if (tree) {
 
1088
                proto_item *ti;
 
1089
                proto_tree *batadv_icmp_tree;
 
1090
 
 
1091
                if (PTREE_DATA(tree)->visible) {
 
1092
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, ICMP_PACKET_V6_SIZE,
 
1093
                                                            "B.A.T.M.A.N. ICMP, Orig: %s (%s), Dst: %s (%s)",
 
1094
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr), get_ether_name(dst_addr), ether_to_str(dst_addr));
 
1095
                } else {
 
1096
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, ICMP_PACKET_V6_SIZE, FALSE);
 
1097
                }
 
1098
                batadv_icmp_tree = proto_item_add_subtree(ti, ett_batadv_icmp);
 
1099
 
 
1100
                /* items */
 
1101
                proto_tree_add_uint_format(batadv_icmp_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_ICMP,
 
1102
                                           "Packet Type: %s (%u)", "BATADV_ICMP", BATADV_ICMP);
 
1103
                offset += 1;
 
1104
 
 
1105
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_version, tvb, offset, 1, FALSE);
 
1106
                offset += 1;
 
1107
 
 
1108
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_msg_type, tvb, offset, 1, FALSE);
 
1109
                offset += 1;
 
1110
 
 
1111
                proto_tree_add_ether(batadv_icmp_tree, hf_batadv_icmp_dst, tvb, offset, 6, dst_addr);
 
1112
                offset += 6;
 
1113
 
 
1114
                proto_tree_add_ether(batadv_icmp_tree, hf_batadv_icmp_orig, tvb, offset, 6, orig_addr);
 
1115
                offset += 6;
 
1116
 
 
1117
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_ttl, tvb, offset, 1, FALSE);
 
1118
                offset += 1;
 
1119
 
 
1120
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_uid, tvb, offset, 1, FALSE);
 
1121
                offset += 1;
 
1122
 
 
1123
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_seqno, tvb, offset, 1, FALSE);
 
1124
                offset += 1;
 
1125
        }
 
1126
 
 
1127
        /* Calculate offset even when we got no tree */
 
1128
        offset = ICMP_PACKET_V6_SIZE;
 
1129
 
 
1130
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
1131
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
1132
 
 
1133
        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, orig_addr);
 
1134
        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, orig_addr);
 
1135
 
 
1136
        tap_queue_packet(batadv_tap, pinfo, icmp_packeth);
 
1137
 
 
1138
        length_remaining = tvb_length_remaining(tvb, offset);
 
1139
 
 
1140
        if (length_remaining != 0) {
 
1141
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
1142
 
 
1143
                call_dissector(data_handle, next_tvb, pinfo, tree);
 
1144
        }
 
1145
}
 
1146
 
 
1147
static void dissect_batadv_icmp_v7(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1148
{
 
1149
        struct icmp_packet_v7 *icmp_packeth;
 
1150
        const guint8  *dst_addr, *orig_addr;
 
1151
 
 
1152
        tvbuff_t *next_tvb;
 
1153
        guint length_remaining;
 
1154
        int offset = 0;
 
1155
 
 
1156
        icmp_packeth = ep_alloc(sizeof(struct icmp_packet_v7));
 
1157
 
 
1158
        icmp_packeth->version = tvb_get_guint8(tvb, 1);
 
1159
        icmp_packeth->msg_type = tvb_get_guint8(tvb, 2);
 
1160
        icmp_packeth->ttl = tvb_get_guint8(tvb, 3);
 
1161
        dst_addr = tvb_get_ptr(tvb, 4, 6);
 
1162
        SET_ADDRESS(&icmp_packeth->dst, AT_ETHER, 6, dst_addr);
 
1163
        orig_addr = tvb_get_ptr(tvb, 10, 6);
 
1164
        SET_ADDRESS(&icmp_packeth->orig, AT_ETHER, 6, orig_addr);
 
1165
        icmp_packeth->seqno = tvb_get_ntohs(tvb, 16);
 
1166
        icmp_packeth->uid = tvb_get_guint8(tvb, 17);
 
1167
 
 
1168
        /* Set info column */
 
1169
        if (check_col(pinfo->cinfo, COL_INFO)) {
 
1170
                col_add_fstr(pinfo->cinfo, COL_INFO, "[%s] Seq=%u",
 
1171
                             val_to_str(icmp_packeth->msg_type, icmp_packettypenames, "Unknown (0x%02x)"),
 
1172
                             icmp_packeth->seqno);
 
1173
        }
 
1174
        /* Set tree info */
 
1175
        if (tree) {
 
1176
                proto_item *ti;
 
1177
                proto_tree *batadv_icmp_tree;
 
1178
 
 
1179
                if (PTREE_DATA(tree)->visible) {
 
1180
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, ICMP_PACKET_V7_SIZE,
 
1181
                                                            "B.A.T.M.A.N. ICMP, Orig: %s (%s), Dst: %s (%s)",
 
1182
                                                            get_ether_name(orig_addr), ether_to_str(orig_addr), get_ether_name(dst_addr), ether_to_str(dst_addr));
 
1183
                } else {
 
1184
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, ICMP_PACKET_V7_SIZE, FALSE);
 
1185
                }
 
1186
                batadv_icmp_tree = proto_item_add_subtree(ti, ett_batadv_icmp);
 
1187
 
 
1188
                /* items */
 
1189
                proto_tree_add_uint_format(batadv_icmp_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_ICMP,
 
1190
                                           "Packet Type: %s (%u)", "BATADV_ICMP", BATADV_ICMP);
 
1191
                offset += 1;
 
1192
 
 
1193
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_version, tvb, offset, 1, FALSE);
 
1194
                offset += 1;
 
1195
 
 
1196
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_msg_type, tvb, offset, 1, FALSE);
 
1197
                offset += 1;
 
1198
 
 
1199
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_ttl, tvb, offset, 1, FALSE);
 
1200
                offset += 1;
 
1201
 
 
1202
                proto_tree_add_ether(batadv_icmp_tree, hf_batadv_icmp_dst, tvb, offset, 6, dst_addr);
 
1203
                offset += 6;
 
1204
 
 
1205
                proto_tree_add_ether(batadv_icmp_tree, hf_batadv_icmp_orig, tvb, offset, 6, orig_addr);
 
1206
                offset += 6;
 
1207
 
 
1208
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_seqno, tvb, offset, 1, FALSE);
 
1209
                offset += 1;
 
1210
 
 
1211
                proto_tree_add_item(batadv_icmp_tree, hf_batadv_icmp_uid, tvb, offset, 1, FALSE);
 
1212
                offset += 1;
 
1213
        }
 
1214
 
 
1215
        /* Calculate offset even when we got no tree */
 
1216
        offset = ICMP_PACKET_V7_SIZE;
 
1217
 
 
1218
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, orig_addr);
 
1219
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, orig_addr);
 
1220
 
 
1221
        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, orig_addr);
 
1222
        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, orig_addr);
 
1223
 
 
1224
        tap_queue_packet(batadv_tap, pinfo, icmp_packeth);
 
1225
 
 
1226
        length_remaining = tvb_length_remaining(tvb, offset);
 
1227
 
 
1228
        if (length_remaining != 0) {
 
1229
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
1230
 
 
1231
                call_dissector(data_handle, next_tvb, pinfo, tree);
 
1232
        }
 
1233
}
 
1234
 
 
1235
static void dissect_batadv_unicast(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1236
{
 
1237
        guint8 version;
 
1238
 
 
1239
        /* set protocol name */
 
1240
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_UNICAST");
 
1241
 
 
1242
        version = tvb_get_guint8(tvb, 1);
 
1243
        switch (version) {
 
1244
        case 6:
 
1245
        case 7:
 
1246
        case 8:
 
1247
        case 9:
 
1248
        case 10:
 
1249
                dissect_batadv_unicast_v6(tvb, pinfo, tree);
 
1250
                break;
 
1251
        default:
 
1252
                col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported Version %d", version);
 
1253
                call_dissector(data_handle, tvb, pinfo, tree);
 
1254
                break;
 
1255
        }
 
1256
}
 
1257
 
 
1258
static void dissect_batadv_unicast_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1259
{
 
1260
        struct unicast_packet_v6 *unicast_packeth;
 
1261
        const guint8  *dest_addr;
 
1262
 
 
1263
        tvbuff_t *next_tvb;
 
1264
        guint length_remaining;
 
1265
        int offset = 0;
 
1266
 
 
1267
        unicast_packeth = ep_alloc(sizeof(struct unicast_packet_v6));
 
1268
 
 
1269
        unicast_packeth->version = tvb_get_guint8(tvb, 1);
 
1270
        dest_addr = tvb_get_ptr(tvb, 2, 6);
 
1271
        SET_ADDRESS(&unicast_packeth->dest, AT_ETHER, 6, dest_addr);
 
1272
        unicast_packeth->ttl = tvb_get_guint8(tvb, 8);
 
1273
 
 
1274
        /* Set info column */
 
1275
        col_clear(pinfo->cinfo, COL_INFO);
 
1276
 
 
1277
        /* Set tree info */
 
1278
        if (tree) {
 
1279
                proto_item *ti;
 
1280
                proto_tree *batadv_unicast_tree;
 
1281
 
 
1282
                if (PTREE_DATA(tree)->visible) {
 
1283
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, UNICAST_PACKET_V6_SIZE,
 
1284
                                                            "B.A.T.M.A.N. Unicast, Dst: %s (%s)",
 
1285
                                                            get_ether_name(dest_addr), ether_to_str(dest_addr));
 
1286
                } else {
 
1287
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, UNICAST_PACKET_V6_SIZE, FALSE);
 
1288
                }
 
1289
                batadv_unicast_tree = proto_item_add_subtree(ti, ett_batadv_unicast);
 
1290
 
 
1291
                /* items */
 
1292
                proto_tree_add_uint_format(batadv_unicast_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_UNICAST,
 
1293
                                           "Packet Type: %s (%u)", "BATADV_UNICAST", BATADV_UNICAST);
 
1294
                offset += 1;
 
1295
 
 
1296
                proto_tree_add_item(batadv_unicast_tree, hf_batadv_unicast_version, tvb, offset, 1, FALSE);
 
1297
                offset += 1;
 
1298
 
 
1299
                proto_tree_add_ether(batadv_unicast_tree, hf_batadv_unicast_dst, tvb, offset, 6, dest_addr);
 
1300
                offset += 6;
 
1301
 
 
1302
                proto_tree_add_item(batadv_unicast_tree, hf_batadv_unicast_ttl, tvb, offset, 1, FALSE);
 
1303
                offset += 1;
 
1304
        }
 
1305
 
 
1306
        /* Calculate offset even when we got no tree */
 
1307
        offset = UNICAST_PACKET_V6_SIZE;
 
1308
 
 
1309
        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, dest_addr);
 
1310
        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, dest_addr);
 
1311
 
 
1312
        tap_queue_packet(batadv_tap, pinfo, unicast_packeth);
 
1313
 
 
1314
        length_remaining = tvb_length_remaining(tvb, offset);
 
1315
 
 
1316
        if (length_remaining != 0) {
 
1317
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
1318
 
 
1319
                if (have_tap_listener(batadv_follow_tap)) {
 
1320
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
1321
                }
 
1322
 
 
1323
                call_dissector(eth_handle, next_tvb, pinfo, tree);
 
1324
        }
 
1325
}
 
1326
 
 
1327
static void dissect_batadv_vis(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1328
{
 
1329
        guint8 version;
 
1330
 
 
1331
        /* set protocol name */
 
1332
        col_set_str(pinfo->cinfo, COL_PROTOCOL, "BATADV_VIS");
 
1333
 
 
1334
        version = tvb_get_guint8(tvb, 1);
 
1335
        switch (version) {
 
1336
        case 6:
 
1337
        case 7:
 
1338
        case 8:
 
1339
        case 9:
 
1340
                dissect_batadv_vis_v6(tvb, pinfo, tree);
 
1341
                break;
 
1342
        case 10:
 
1343
                dissect_batadv_vis_v10(tvb, pinfo, tree);
 
1344
                break;
 
1345
        default:
 
1346
                col_add_fstr(pinfo->cinfo, COL_INFO, "Unsupported Version %d", version);
 
1347
                call_dissector(data_handle, tvb, pinfo, tree);
 
1348
                break;
 
1349
        }
 
1350
}
 
1351
 
 
1352
static void dissect_batadv_vis_v6(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1353
{
 
1354
        struct vis_packet_v6 *vis_packeth;
 
1355
        const guint8  *vis_orig_addr, *target_orig_addr, *sender_orig_addr;
 
1356
        proto_tree *batadv_vis_tree = NULL;
 
1357
 
 
1358
        tvbuff_t *next_tvb;
 
1359
        guint length_remaining, entry_size;
 
1360
        int offset = 0, i;
 
1361
 
 
1362
        vis_packeth = ep_alloc(sizeof(struct vis_packet_v6));
 
1363
 
 
1364
        vis_packeth->version = tvb_get_guint8(tvb, 1);
 
1365
        vis_packeth->vis_type = tvb_get_guint8(tvb, 2);
 
1366
        vis_packeth->seqno = tvb_get_guint8(tvb, 3);
 
1367
        vis_packeth->entries = tvb_get_guint8(tvb, 4);
 
1368
        vis_packeth->ttl = tvb_get_guint8(tvb, 5);
 
1369
 
 
1370
        vis_orig_addr = tvb_get_ptr(tvb, 6, 6);
 
1371
        SET_ADDRESS(&vis_packeth->vis_orig, AT_ETHER, 6, vis_orig_addr);
 
1372
        target_orig_addr = tvb_get_ptr(tvb, 12, 6);
 
1373
        SET_ADDRESS(&vis_packeth->target_orig, AT_ETHER, 6, target_orig_addr);
 
1374
        sender_orig_addr = tvb_get_ptr(tvb, 18, 6);
 
1375
        SET_ADDRESS(&vis_packeth->sender_orig, AT_ETHER, 6, sender_orig_addr);
 
1376
 
 
1377
        /* Set info column */
 
1378
        if (check_col(pinfo->cinfo, COL_INFO)) {
 
1379
                col_add_fstr(pinfo->cinfo, COL_INFO, "[%s] Seq=%u",
 
1380
                             val_to_str(vis_packeth->vis_type, vis_packettypenames, "Unknown (0x%02x)"),
 
1381
                             vis_packeth->seqno);
 
1382
        }
 
1383
        /* Set tree info */
 
1384
        if (tree) {
 
1385
                proto_item *ti;
 
1386
 
 
1387
                if (PTREE_DATA(tree)->visible) {
 
1388
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, VIS_PACKET_V6_SIZE,
 
1389
                                                            "B.A.T.M.A.N. Vis, Orig: %s (%s)",
 
1390
                                                            get_ether_name(vis_orig_addr), ether_to_str(vis_orig_addr));
 
1391
                } else {
 
1392
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, VIS_PACKET_V6_SIZE, FALSE);
 
1393
                }
 
1394
                batadv_vis_tree = proto_item_add_subtree(ti, ett_batadv_vis);
 
1395
 
 
1396
                /* items */
 
1397
                proto_tree_add_uint_format(batadv_vis_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_VIS,
 
1398
                                           "Packet Type: %s (%u)", "BATADV_VIS", BATADV_VIS);
 
1399
                offset += 1;
 
1400
 
 
1401
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_version, tvb, offset, 1, FALSE);
 
1402
                offset += 1;
 
1403
 
 
1404
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_type, tvb, offset, 1, FALSE);
 
1405
                offset += 1;
 
1406
 
 
1407
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_seqno, tvb, offset, 1, FALSE);
 
1408
                offset += 1;
 
1409
 
 
1410
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_entries, tvb, offset, 1, FALSE);
 
1411
                offset += 1;
 
1412
 
 
1413
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_ttl, tvb, offset, 1, FALSE);
 
1414
                offset += 1;
 
1415
 
 
1416
                proto_tree_add_ether(batadv_vis_tree, hf_batadv_vis_vis_orig, tvb, offset, 6, vis_orig_addr);
 
1417
                offset += 6;
 
1418
 
 
1419
                proto_tree_add_ether(batadv_vis_tree, hf_batadv_vis_target_orig, tvb, offset, 6, target_orig_addr);
 
1420
                offset += 6;
 
1421
 
 
1422
                proto_tree_add_ether(batadv_vis_tree, hf_batadv_vis_sender_orig, tvb, offset, 6, sender_orig_addr);
 
1423
                offset += 6;
 
1424
        }
 
1425
 
 
1426
        /* Calculate offset even when we got no tree */
 
1427
        offset = VIS_PACKET_V6_SIZE;
 
1428
 
 
1429
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, sender_orig_addr);
 
1430
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, vis_orig_addr);
 
1431
 
 
1432
        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, target_orig_addr);
 
1433
        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, target_orig_addr);
 
1434
 
 
1435
        tap_queue_packet(batadv_tap, pinfo, vis_packeth);
 
1436
 
 
1437
        switch (vis_packeth->version) {
 
1438
        case 6:
 
1439
        case 7:
 
1440
                entry_size = VIS_ENTRY_V6_SIZE;
 
1441
                break;
 
1442
        default:
 
1443
        case 8:
 
1444
        case 9:
 
1445
                entry_size = VIS_ENTRY_V8_SIZE;
 
1446
                break;
 
1447
        }
 
1448
 
 
1449
        for (i = 0; i < vis_packeth->entries; i++) {
 
1450
                next_tvb = tvb_new_subset(tvb, offset, entry_size, entry_size);
 
1451
 
 
1452
                if (have_tap_listener(batadv_follow_tap)) {
 
1453
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
1454
                }
 
1455
 
 
1456
                if (batadv_vis_tree != NULL) {
 
1457
                        switch (vis_packeth->version) {
 
1458
                        case 6:
 
1459
                        case 7:
 
1460
                                dissect_vis_entry_v6(next_tvb, pinfo, batadv_vis_tree);
 
1461
                                break;
 
1462
                        default:
 
1463
                        case 8:
 
1464
                        case 9:
 
1465
                                dissect_vis_entry_v8(next_tvb, pinfo, batadv_vis_tree);
 
1466
                                break;
 
1467
                        }
 
1468
                }
 
1469
 
 
1470
                offset += entry_size;
 
1471
        }
 
1472
 
 
1473
        length_remaining = tvb_length_remaining(tvb, offset);
 
1474
        if (length_remaining != 0) {
 
1475
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
1476
 
 
1477
                if (have_tap_listener(batadv_follow_tap)) {
 
1478
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
1479
                }
 
1480
 
 
1481
                call_dissector(data_handle, next_tvb, pinfo, tree);
 
1482
        }
 
1483
}
 
1484
 
 
1485
static void dissect_batadv_vis_v10(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
 
1486
{
 
1487
        struct vis_packet_v10 *vis_packeth;
 
1488
        const guint8  *vis_orig_addr, *target_orig_addr, *sender_orig_addr;
 
1489
        proto_tree *batadv_vis_tree = NULL;
 
1490
 
 
1491
        tvbuff_t *next_tvb;
 
1492
        guint length_remaining;
 
1493
        int offset = 0, i;
 
1494
 
 
1495
        vis_packeth = ep_alloc(sizeof(struct vis_packet_v10));
 
1496
 
 
1497
        vis_packeth->version = tvb_get_guint8(tvb, 1);
 
1498
        vis_packeth->vis_type = tvb_get_guint8(tvb, 2);
 
1499
        vis_packeth->entries = tvb_get_guint8(tvb, 3);
 
1500
        vis_packeth->seqno = tvb_get_ntohl(tvb, 4);
 
1501
        vis_packeth->ttl = tvb_get_guint8(tvb, 8);
 
1502
 
 
1503
        vis_orig_addr = tvb_get_ptr(tvb, 9, 6);
 
1504
        SET_ADDRESS(&vis_packeth->vis_orig, AT_ETHER, 6, vis_orig_addr);
 
1505
        target_orig_addr = tvb_get_ptr(tvb, 15, 6);
 
1506
        SET_ADDRESS(&vis_packeth->target_orig, AT_ETHER, 6, target_orig_addr);
 
1507
        sender_orig_addr = tvb_get_ptr(tvb, 21, 6);
 
1508
        SET_ADDRESS(&vis_packeth->sender_orig, AT_ETHER, 6, sender_orig_addr);
 
1509
 
 
1510
        /* Set info column */
 
1511
        col_add_fstr(pinfo->cinfo, COL_INFO, "[%s] Seq=%u",
 
1512
                     val_to_str(vis_packeth->vis_type, vis_packettypenames, "Unknown (0x%02x)"),
 
1513
                     vis_packeth->seqno);
 
1514
 
 
1515
        /* Set tree info */
 
1516
        if (tree) {
 
1517
                proto_item *ti;
 
1518
 
 
1519
                if (PTREE_DATA(tree)->visible) {
 
1520
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, VIS_PACKET_V10_SIZE,
 
1521
                                                            "B.A.T.M.A.N. Vis, Orig: %s (%s)",
 
1522
                                                            get_ether_name(vis_orig_addr), ether_to_str(vis_orig_addr));
 
1523
                } else {
 
1524
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, VIS_PACKET_V10_SIZE, FALSE);
 
1525
                }
 
1526
                batadv_vis_tree = proto_item_add_subtree(ti, ett_batadv_vis);
 
1527
 
 
1528
                /* items */
 
1529
                proto_tree_add_uint_format(batadv_vis_tree, hf_batadv_packet_type, tvb, offset, 1, BATADV_VIS,
 
1530
                                           "Packet Type: %s (%u)", "BATADV_VIS", BATADV_VIS);
 
1531
                offset += 1;
 
1532
 
 
1533
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_version, tvb, offset, 1, FALSE);
 
1534
                offset += 1;
 
1535
 
 
1536
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_type, tvb, offset, 1, FALSE);
 
1537
                offset += 1;
 
1538
 
 
1539
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_entries, tvb, offset, 1, FALSE);
 
1540
                offset += 1;
 
1541
 
 
1542
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_seqno32, tvb, offset, 4, FALSE);
 
1543
                offset += 4;
 
1544
 
 
1545
                proto_tree_add_item(batadv_vis_tree, hf_batadv_vis_ttl, tvb, offset, 1, FALSE);
 
1546
                offset += 1;
 
1547
 
 
1548
                proto_tree_add_ether(batadv_vis_tree, hf_batadv_vis_vis_orig, tvb, offset, 6, vis_orig_addr);
 
1549
                offset += 6;
 
1550
 
 
1551
                proto_tree_add_ether(batadv_vis_tree, hf_batadv_vis_target_orig, tvb, offset, 6, target_orig_addr);
 
1552
                offset += 6;
 
1553
 
 
1554
                proto_tree_add_ether(batadv_vis_tree, hf_batadv_vis_sender_orig, tvb, offset, 6, sender_orig_addr);
 
1555
                offset += 6;
 
1556
        }
 
1557
 
 
1558
        /* Calculate offset even when we got no tree */
 
1559
        offset = VIS_PACKET_V10_SIZE;
 
1560
 
 
1561
        SET_ADDRESS(&pinfo->dl_src, AT_ETHER, 6, sender_orig_addr);
 
1562
        SET_ADDRESS(&pinfo->src, AT_ETHER, 6, vis_orig_addr);
 
1563
 
 
1564
        SET_ADDRESS(&pinfo->dl_dst, AT_ETHER, 6, target_orig_addr);
 
1565
        SET_ADDRESS(&pinfo->dst, AT_ETHER, 6, target_orig_addr);
 
1566
 
 
1567
        tap_queue_packet(batadv_tap, pinfo, vis_packeth);
 
1568
 
 
1569
        for (i = 0; i < vis_packeth->entries; i++) {
 
1570
                next_tvb = tvb_new_subset(tvb, offset, VIS_ENTRY_V8_SIZE, VIS_ENTRY_V8_SIZE);
 
1571
 
 
1572
                if (have_tap_listener(batadv_follow_tap)) {
 
1573
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
1574
                }
 
1575
 
 
1576
                dissect_vis_entry_v8(next_tvb, pinfo, batadv_vis_tree);
 
1577
                offset += VIS_ENTRY_V8_SIZE;
 
1578
        }
 
1579
 
 
1580
        length_remaining = tvb_length_remaining(tvb, offset);
 
1581
        if (length_remaining != 0) {
 
1582
                next_tvb = tvb_new_subset(tvb, offset, length_remaining, -1);
 
1583
 
 
1584
                if (have_tap_listener(batadv_follow_tap)) {
 
1585
                        tap_queue_packet(batadv_follow_tap, pinfo, next_tvb);
 
1586
                }
 
1587
 
 
1588
                call_dissector(data_handle, next_tvb, pinfo, tree);
 
1589
        }
 
1590
}
 
1591
 
 
1592
static void dissect_vis_entry_v6(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
 
1593
{
 
1594
        /* Set tree info */
 
1595
        if (tree) {
 
1596
                const guint8  *dst;
 
1597
                proto_item    *ti;
 
1598
                proto_tree    *batadv_vis_entry_tree;
 
1599
 
 
1600
                dst = tvb_get_ptr(tvb, 0, 6);
 
1601
 
 
1602
                if (PTREE_DATA(tree)->visible) {
 
1603
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, VIS_ENTRY_V6_SIZE,
 
1604
                                                            "VIS Entry: %s (%s)",
 
1605
                                                            get_ether_name(dst), ether_to_str(dst));
 
1606
                } else {
 
1607
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, VIS_ENTRY_V6_SIZE, FALSE);
 
1608
                }
 
1609
                batadv_vis_entry_tree = proto_item_add_subtree(ti, ett_batadv_vis_entry);
 
1610
 
 
1611
                proto_tree_add_ether(batadv_vis_entry_tree, hf_batadv_vis_entry_dst, tvb, 0, 6, dst);
 
1612
                proto_tree_add_item(batadv_vis_entry_tree, hf_batadv_vis_entry_quality, tvb, 6, 1, FALSE);
 
1613
        }
 
1614
}
 
1615
 
 
1616
static void dissect_vis_entry_v8(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree)
 
1617
{
 
1618
        /* Set tree info */
 
1619
        if (tree) {
 
1620
                const guint8  *dst, *src;
 
1621
                proto_item *ti;
 
1622
                proto_tree *batadv_vis_entry_tree;
 
1623
 
 
1624
                src = tvb_get_ptr(tvb, 0, 6);
 
1625
                dst = tvb_get_ptr(tvb, 6, 6);
 
1626
 
 
1627
                if (PTREE_DATA(tree)->visible) {
 
1628
                        ti = proto_tree_add_protocol_format(tree, proto_batadv_plugin, tvb, 0, VIS_ENTRY_V8_SIZE,
 
1629
                                                            "VIS Entry: %s (%s)",
 
1630
                                                            get_ether_name(dst), ether_to_str(dst));
 
1631
                } else {
 
1632
                        ti = proto_tree_add_item(tree, proto_batadv_plugin, tvb, 0, VIS_ENTRY_V8_SIZE, FALSE);
 
1633
                }
 
1634
                batadv_vis_entry_tree = proto_item_add_subtree(ti, ett_batadv_vis_entry);
 
1635
 
 
1636
                proto_tree_add_ether(batadv_vis_entry_tree, hf_batadv_vis_entry_src, tvb, 0, 6, src);
 
1637
                proto_tree_add_ether(batadv_vis_entry_tree, hf_batadv_vis_entry_dst, tvb, 6, 6, dst);
 
1638
                proto_tree_add_item(batadv_vis_entry_tree, hf_batadv_vis_entry_quality, tvb, 12, 1, FALSE);
 
1639
        }
 
1640
}
 
1641
 
 
1642
void proto_register_batadv(void)
 
1643
{
 
1644
        module_t *batadv_module;
 
1645
 
 
1646
        static hf_register_info hf[] = {
 
1647
                { &hf_batadv_packet_type,
 
1648
                  { "Packet Type", "batadv.batman.packet_type",
 
1649
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1650
                    NULL, HFILL }
 
1651
                },
 
1652
                { &hf_batadv_batman_version,
 
1653
                  { "Version", "batadv.batman.version",
 
1654
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1655
                    NULL, HFILL }
 
1656
                },
 
1657
                { &hf_batadv_batman_flags,
 
1658
                  { "Flags", "batadv.batman.flags",
 
1659
                    FT_UINT8, BASE_HEX, NULL, 0x0,
 
1660
                    NULL, HFILL }
 
1661
                },
 
1662
                { &hf_batadv_batman_ttl,
 
1663
                  { "Time to Live", "batadv.batman.ttl",
 
1664
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1665
                    NULL, HFILL }
 
1666
                },
 
1667
                { &hf_batadv_batman_gwflags,
 
1668
                  { "Gateway Flags", "batadv.batman.gwflags",
 
1669
                    FT_UINT8, BASE_HEX, NULL, 0x0,
 
1670
                    NULL, HFILL }
 
1671
                },
 
1672
                { &hf_batadv_batman_tq,
 
1673
                  { "Transmission Quality", "batadv.batman.tq",
 
1674
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1675
                    NULL, HFILL }
 
1676
                },
 
1677
                { &hf_batadv_batman_seqno,
 
1678
                  { "Sequence number", "batadv.batman.seq",
 
1679
                    FT_UINT16, BASE_DEC, NULL, 0x0,
 
1680
                    NULL, HFILL }
 
1681
                },
 
1682
                { &hf_batadv_batman_seqno32,
 
1683
                  { "Sequence number", "batadv.batman.seq",
 
1684
                    FT_UINT32, BASE_DEC, NULL, 0x0,
 
1685
                    NULL, HFILL }
 
1686
                },
 
1687
                { &hf_batadv_batman_orig,
 
1688
                  { "Originator", "batadv.batman.orig",
 
1689
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1690
                    NULL, HFILL }
 
1691
                },
 
1692
                { &hf_batadv_batman_prev_sender,
 
1693
                  { "Received from", "batadv.batman.prev_sender",
 
1694
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1695
                    NULL, HFILL }
 
1696
                },
 
1697
                { &hf_batadv_batman_num_hna,
 
1698
                  { "Number of HNAs", "batadv.batman.num_hna",
 
1699
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1700
                    NULL, HFILL }
 
1701
                },
 
1702
                { &hf_batadv_batman_pad,
 
1703
                  { "Padding", "batadv.batman.pad",
 
1704
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1705
                    NULL, HFILL }
 
1706
                },
 
1707
                { &hf_batadv_batman_flags_directlink,
 
1708
                  { "DirectLink", "batadv.batman.flags.directlink",
 
1709
                    FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x40,
 
1710
                    NULL, HFILL }
 
1711
                },
 
1712
                { &hf_batadv_batman_flags_vis_server,
 
1713
                  { "VIS_SERVER", "batadv.batman.flags.vis_server",
 
1714
                    FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x20,
 
1715
                    NULL, HFILL }
 
1716
                },
 
1717
                { &hf_batadv_batman_flags_primaries_first_hop,
 
1718
                  { "PRIMARIES_FIRST_HOP", "batadv.batman.flags.primaries_first_hop",
 
1719
                    FT_BOOLEAN, 8, TFS(&tfs_set_notset), 0x10,
 
1720
                    NULL, HFILL }
 
1721
                },
 
1722
                { &hf_batadv_batman_hna,
 
1723
                  { "Host Network Announcement", "batadv.batman.hna",
 
1724
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1725
                    NULL, HFILL }
 
1726
                },
 
1727
                { &hf_batadv_bcast_version,
 
1728
                  { "Version", "batadv.bcast.version",
 
1729
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1730
                    NULL, HFILL }
 
1731
                },
 
1732
                { &hf_batadv_bcast_pad,
 
1733
                  { "Padding", "batadv.bcast.pad",
 
1734
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1735
                    NULL, HFILL }
 
1736
                },
 
1737
                { &hf_batadv_bcast_orig,
 
1738
                  { "Originator", "batadv.bcast.orig",
 
1739
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1740
                    NULL, HFILL }
 
1741
                },
 
1742
                { &hf_batadv_bcast_seqno,
 
1743
                  { "Sequence number", "batadv.bcast.seq",
 
1744
                    FT_UINT16, BASE_DEC, NULL, 0x0,
 
1745
                    NULL, HFILL }
 
1746
                },
 
1747
                { &hf_batadv_bcast_seqno32,
 
1748
                  { "Sequence number", "batadv.bcast.seq",
 
1749
                    FT_UINT32, BASE_DEC, NULL, 0x0,
 
1750
                    NULL, HFILL }
 
1751
                },
 
1752
                { &hf_batadv_bcast_ttl,
 
1753
                  { "Time to Live", "batadv.bcast.ttl",
 
1754
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1755
                    NULL, HFILL }
 
1756
                },
 
1757
                { &hf_batadv_icmp_version,
 
1758
                  { "Version", "batadv.icmp.version",
 
1759
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1760
                    NULL, HFILL }
 
1761
                },
 
1762
                { &hf_batadv_icmp_msg_type,
 
1763
                  { "Message Type", "batadv.icmp.msg_type",
 
1764
                    FT_UINT8, BASE_DEC, VALS(icmp_packettypenames), 0x0,
 
1765
                    NULL, HFILL }
 
1766
                },
 
1767
                { &hf_batadv_icmp_dst,
 
1768
                  { "Destination", "batadv.icmp.dst",
 
1769
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1770
                    NULL, HFILL }
 
1771
                },
 
1772
                { &hf_batadv_icmp_orig,
 
1773
                  { "Originator", "batadv.icmp.orig",
 
1774
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1775
                    NULL, HFILL }
 
1776
                },
 
1777
                { &hf_batadv_icmp_ttl,
 
1778
                  { "Time to Live", "batadv.icmp.ttl",
 
1779
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1780
                    NULL, HFILL}
 
1781
                },
 
1782
                { &hf_batadv_icmp_uid,
 
1783
                  { "UID", "batadv.icmp.uid",
 
1784
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1785
                    NULL, HFILL}
 
1786
                },
 
1787
                { &hf_batadv_icmp_seqno,
 
1788
                  { "Sequence number", "batadv.icmp.seq",
 
1789
                    FT_UINT16, BASE_DEC, NULL, 0x0,
 
1790
                    NULL, HFILL}
 
1791
                },
 
1792
                { &hf_batadv_unicast_version,
 
1793
                  { "Version", "batadv.unicast.version",
 
1794
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1795
                    NULL, HFILL }
 
1796
                },
 
1797
                { &hf_batadv_unicast_dst,
 
1798
                  { "Destination", "batadv.unicast.dst",
 
1799
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1800
                    NULL, HFILL }
 
1801
                },
 
1802
                { &hf_batadv_unicast_ttl,
 
1803
                  { "Time to Live", "batadv.unicast.ttl",
 
1804
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1805
                    NULL, HFILL }
 
1806
                },
 
1807
                { &hf_batadv_vis_version,
 
1808
                  { "Version", "batadv.vis.version",
 
1809
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1810
                    NULL, HFILL }
 
1811
                },
 
1812
                { &hf_batadv_vis_type,
 
1813
                  { "Type", "batadv.vis.type",
 
1814
                    FT_UINT8, BASE_DEC, VALS(vis_packettypenames), 0x0,
 
1815
                    NULL, HFILL }
 
1816
                },
 
1817
                { &hf_batadv_vis_seqno,
 
1818
                  { "Sequence number", "batadv.vis.seq",
 
1819
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1820
                    NULL, HFILL}
 
1821
                },
 
1822
                { &hf_batadv_vis_seqno32,
 
1823
                  { "Sequence number", "batadv.vis.seq",
 
1824
                    FT_UINT32, BASE_DEC, NULL, 0x0,
 
1825
                    NULL, HFILL}
 
1826
                },
 
1827
                { &hf_batadv_vis_entries,
 
1828
                  { "Entries", "batadv.vis.entries",
 
1829
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1830
                    "Number of entries", HFILL}
 
1831
                },
 
1832
                { &hf_batadv_vis_ttl,
 
1833
                  { "Time to Live", "batadv.vis.ttl",
 
1834
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1835
                    NULL, HFILL}
 
1836
                },
 
1837
                { &hf_batadv_vis_vis_orig,
 
1838
                  { "Originator", "batadv.vis.vis_orig",
 
1839
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1840
                    NULL, HFILL }
 
1841
                },
 
1842
                { &hf_batadv_vis_target_orig,
 
1843
                  { "Target Originator", "batadv.vis.target_orig",
 
1844
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1845
                    NULL, HFILL }
 
1846
                },
 
1847
                { &hf_batadv_vis_sender_orig,
 
1848
                  { "Forwarding Originator", "batadv.vis.sender_orig",
 
1849
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1850
                    NULL, HFILL }
 
1851
                },
 
1852
                { &hf_batadv_vis_entry_src,
 
1853
                  { "Source", "hf_batadv_vis_entry.src",
 
1854
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1855
                    NULL, HFILL }
 
1856
                },
 
1857
                { &hf_batadv_vis_entry_dst,
 
1858
                  { "Destination", "hf_batadv_vis_entry.dst",
 
1859
                    FT_ETHER, BASE_NONE, NULL, 0x0,
 
1860
                    NULL, HFILL }
 
1861
                },
 
1862
                { &hf_batadv_vis_entry_quality,
 
1863
                  { "Quality", "batadv.vis.quality",
 
1864
                    FT_UINT8, BASE_DEC, NULL, 0x0,
 
1865
                    NULL, HFILL }
 
1866
                }
 
1867
        };
 
1868
 
 
1869
        /* Setup protocol subtree array */
 
1870
        static gint *ett[] = {
 
1871
                &ett_batadv_batman,
 
1872
                &ett_batadv_batman_flags,
 
1873
                &ett_batadv_batman_hna,
 
1874
                &ett_batadv_batman_gwflags,
 
1875
                &ett_batadv_bcast,
 
1876
                &ett_batadv_icmp,
 
1877
                &ett_batadv_unicast,
 
1878
                &ett_batadv_vis,
 
1879
                &ett_batadv_vis_entry
 
1880
        };
 
1881
 
 
1882
        proto_batadv_plugin = proto_register_protocol(
 
1883
                                      "B.A.T.M.A.N. Advanced Protocol",
 
1884
                                      "BATADV",          /* short name */
 
1885
                                      "batadv"           /* abbrev */
 
1886
                              );
 
1887
 
 
1888
        batadv_module = prefs_register_protocol(proto_batadv_plugin,
 
1889
                                                proto_reg_handoff_batadv);
 
1890
 
 
1891
        prefs_register_uint_preference(batadv_module, "batmanadv.ethertype",
 
1892
                                       "Ethertype",
 
1893
                                       "Ethertype used to indicate B.A.T.M.A.N. packet.",
 
1894
                                       16, &batadv_ethertype);
 
1895
 
 
1896
        proto_register_subtree_array(ett, array_length(ett));
 
1897
        proto_register_field_array(proto_batadv_plugin, hf, array_length(hf));
 
1898
}
 
1899
 
 
1900
void proto_reg_handoff_batadv(void)
 
1901
{
 
1902
        static gboolean inited = FALSE;
 
1903
        static unsigned int old_batadv_ethertype;
 
1904
 
 
1905
        if (!inited) {
 
1906
                batman_handle = create_dissector_handle(dissect_batman_plugin, proto_batadv_plugin);
 
1907
 
 
1908
                data_handle = find_dissector("data");
 
1909
                eth_handle = find_dissector("eth");
 
1910
 
 
1911
                batadv_tap = register_tap("batman");
 
1912
                batadv_follow_tap = register_tap("batman_follow");
 
1913
 
 
1914
                inited = TRUE;
 
1915
        } else {
 
1916
                dissector_delete("ethertype", old_batadv_ethertype, batman_handle);
 
1917
        }
 
1918
 
 
1919
        old_batadv_ethertype = batadv_ethertype;
 
1920
        dissector_add("ethertype", batadv_ethertype, batman_handle);
 
1921
}