Coverage Report

Created: 2026-05-14 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-clique-rm.c
Line
Count
Source
1
/* packet-clique-rm.c
2
 * Routines for clique reliable multicast dissector
3
 * Copyright 2007, Collabora Ltd.
4
 *   @author: Sjoerd Simons <sjoerd.simons@collabora.co.uk>
5
 *
6
 * Wireshark - Network traffic analyzer
7
 * By Gerald Combs <gerald@wireshark.org>
8
 * Copyright 1998 Gerald Combs
9
 *
10
 * SPDX-License-Identifier: GPL-2.0-or-later
11
 */
12
13
#include "config.h"
14
15
#include <epan/packet.h>
16
17
void proto_register_clique_rm(void);
18
void proto_reg_handoff_clique_rm(void);
19
20
/* Initialize the protocol and registered fields */
21
static int proto_clique_rm;
22
23
static int hf_clique_rm_version;
24
static int hf_clique_rm_type;
25
static int hf_clique_rm_sender;
26
static int hf_clique_rm_packet_id;
27
static int hf_clique_rm_depends;
28
static int hf_clique_rm_depend_sender;
29
static int hf_clique_rm_depend_packet_id;
30
static int hf_clique_rm_failures;
31
static int hf_clique_rm_failures_senders;
32
static int hf_clique_rm_attempt_join;
33
static int hf_clique_rm_attempt_join_senders;
34
static int hf_clique_rm_join_failures;
35
static int hf_clique_rm_join_failures_senders;
36
static int hf_clique_rm_data_flags;
37
static int hf_clique_rm_data_size;
38
static int hf_clique_rm_data_stream_id;
39
static int hf_clique_rm_data_data;
40
static int hf_clique_rm_whois_request_id;
41
static int hf_clique_rm_whois_reply_name;
42
static int hf_clique_rm_whois_reply_name_length;
43
static int hf_clique_rm_repair_request_sender_id;
44
static int hf_clique_rm_repair_request_packet_id;
45
46
/* Initialize the subtree pointers */
47
static int ett_clique_rm;
48
static int ett_clique_rm_data;
49
static int ett_clique_rm_depends;
50
static int ett_clique_rm_depends_item;
51
static int ett_clique_rm_failures;
52
static int ett_clique_rm_join_failures;
53
static int ett_clique_rm_attempt_join;
54
static int ett_clique_rm_join;
55
56
/* Packet types */
57
typedef enum {
58
  /* Unreliable packets */
59
  PACKET_TYPE_WHOIS_REQUEST = 0,
60
  PACKET_TYPE_WHOIS_REPLY,
61
  PACKET_TYPE_REPAIR_REQUEST,
62
  PACKET_TYPE_SESSION,
63
  /* Reliable packets */
64
  FIRST_RELIABLE_PACKET = 0xf,
65
  PACKET_TYPE_DATA = FIRST_RELIABLE_PACKET,
66
  /* No data just acknowledgement */
67
  PACKET_TYPE_NO_DATA,
68
  /* Some nodes failed */
69
  PACKET_TYPE_FAILURE,
70
  /* Start a joining attempt */
71
  PACKET_TYPE_ATTEMPT_JOIN,
72
  /* The real join */
73
  PACKET_TYPE_JOIN,
74
  /* Leaving now, bye */
75
  PACKET_TYPE_BYE,
76
  PACKET_TYPE_INVALID
77
} GibberRMulticastPacketType;
78
79
0
#define IS_RELIABLE(type) (type >= FIRST_RELIABLE_PACKET)
80
81
static const value_string packet_type_vals[] = {
82
  { PACKET_TYPE_WHOIS_REQUEST,   "Whois request" },
83
  { PACKET_TYPE_WHOIS_REPLY,     "Whois reply"   },
84
  { PACKET_TYPE_REPAIR_REQUEST,  "Repair request"},
85
  { PACKET_TYPE_SESSION,         "Session"       },
86
  { PACKET_TYPE_DATA,            "Data"          },
87
  /* No data just acknowledgement */
88
  { PACKET_TYPE_NO_DATA,         "No data"       },
89
  /* Some nodes failed */
90
  { PACKET_TYPE_FAILURE,         "Failure"       },
91
  /* Start a joining attempt */
92
  { PACKET_TYPE_ATTEMPT_JOIN,    "Attempt join"  },
93
  /* The real join */
94
  { PACKET_TYPE_JOIN,            "Join"          },
95
  /* Leaving now, bye */
96
  { PACKET_TYPE_BYE,             "Bye"           },
97
98
  { 0,                 NULL                 }
99
};
100
101
static void
102
dissect_sender_array(proto_tree *clique_rm_tree, int hf_header, int ett_header,
103
    int hf_header_sender, tvbuff_t *tvb, int offset)
104
0
{
105
0
  unsigned    i, count;
106
0
  int         len;
107
0
  proto_item *ti;
108
0
  proto_tree *tree;
109
110
111
0
  count = tvb_get_uint8(tvb, offset);
112
0
  len   = 1 + 4 * count;
113
0
  ti    = proto_tree_add_item(clique_rm_tree, hf_header, tvb, offset, 1, ENC_BIG_ENDIAN);
114
0
  proto_item_set_len(ti, len);
115
0
  tree  = proto_item_add_subtree(ti, ett_header);
116
0
  offset++;
117
118
0
  for (i = 0; i < count; i++, offset += 4)
119
0
    proto_tree_add_item(tree, hf_header_sender, tvb, offset, 4, ENC_BIG_ENDIAN);
120
0
}
121
122
static void
123
dissect_data_packet(proto_tree *clique_rm_tree, tvbuff_t *tvb, int offset)
124
0
{
125
0
  proto_tree *tree;
126
127
0
  tree = proto_tree_add_subtree(clique_rm_tree, tvb, offset, -1, ett_clique_rm_data, NULL, "Data");
128
129
0
  proto_tree_add_item(tree, hf_clique_rm_data_flags, tvb, offset, 1, ENC_BIG_ENDIAN);
130
0
  offset += 1;
131
132
0
  proto_tree_add_item(tree, hf_clique_rm_data_stream_id, tvb, offset, 2,
133
0
      ENC_BIG_ENDIAN);
134
0
  offset += 2;
135
136
0
  proto_tree_add_item(tree, hf_clique_rm_data_size, tvb, offset, 4, ENC_BIG_ENDIAN);
137
0
  offset += 4;
138
139
140
0
  proto_tree_add_item(tree, hf_clique_rm_data_data, tvb, offset, -1, ENC_NA);
141
0
}
142
143
static int
144
dissect_depends(proto_tree *clique_rm_tree, tvbuff_t *tvb, int offset)
145
0
{
146
0
  proto_item *ti;
147
0
  proto_tree *tree, *depend_tree;
148
0
  unsigned    ii, count;
149
0
  int         len;
150
151
0
  count = tvb_get_uint8(tvb, offset);
152
0
  len   = 1 + count * 8;
153
154
0
  ti = proto_tree_add_item(clique_rm_tree,
155
0
          hf_clique_rm_depends, tvb, offset, 1, ENC_BIG_ENDIAN);
156
0
  proto_item_set_len(ti, len);
157
0
  offset += 1;
158
159
0
  tree = proto_item_add_subtree(ti, ett_clique_rm_depends);
160
0
  for (ii = 0; ii < count; ii++)
161
0
  {
162
0
     depend_tree = proto_tree_add_subtree_format(tree, tvb, offset, 8,
163
0
                    ett_clique_rm_depends_item, NULL, "Depend item %d", ii+1);
164
165
0
     proto_tree_add_item(depend_tree, hf_clique_rm_depend_sender,
166
0
           tvb, offset, 4, ENC_BIG_ENDIAN);
167
0
     proto_tree_add_item(depend_tree, hf_clique_rm_depend_packet_id,
168
0
           tvb, offset+4, 4, ENC_BIG_ENDIAN);
169
0
     offset += 8;
170
0
  }
171
172
0
  return len;
173
0
}
174
175
/* Code to actually dissect the packets */
176
static void
177
dissect_reliable_packet(proto_tree *clique_rm_tree, uint8_t type, tvbuff_t *tvb, int offset)
178
0
{
179
0
  if (!clique_rm_tree)
180
0
    return; /* no col_..() or expert...() calls in following */
181
182
0
  proto_tree_add_item(clique_rm_tree, hf_clique_rm_packet_id, tvb, offset, 4,
183
0
     ENC_BIG_ENDIAN);
184
0
  offset += 4;
185
186
0
  offset += dissect_depends(clique_rm_tree, tvb, offset);
187
188
0
  switch (type)
189
0
    {
190
0
      case PACKET_TYPE_DATA:
191
0
        dissect_data_packet(clique_rm_tree, tvb, offset);
192
0
        break;
193
0
      case PACKET_TYPE_NO_DATA:
194
0
        break;
195
0
      case PACKET_TYPE_FAILURE:
196
0
        dissect_sender_array(clique_rm_tree, hf_clique_rm_failures,
197
0
            ett_clique_rm_failures, hf_clique_rm_failures_senders, tvb, offset);
198
0
        break;
199
0
      case PACKET_TYPE_ATTEMPT_JOIN:
200
0
        dissect_sender_array(clique_rm_tree, hf_clique_rm_attempt_join,
201
0
            ett_clique_rm_attempt_join, hf_clique_rm_attempt_join_senders, tvb, offset);
202
0
        break;
203
0
      case PACKET_TYPE_JOIN:
204
0
        dissect_sender_array(clique_rm_tree, hf_clique_rm_join_failures,
205
0
            ett_clique_rm_join_failures, hf_clique_rm_join_failures_senders, tvb, offset);
206
0
        break;
207
0
      case PACKET_TYPE_BYE:
208
0
        break;
209
0
      default:
210
0
        break;
211
0
    }
212
0
}
213
214
static void
215
dissect_unreliable_packet(proto_tree *clique_rm_tree, uint8_t type, tvbuff_t *tvb, int offset)
216
0
{
217
0
  unsigned len;
218
219
0
  if (!clique_rm_tree)
220
0
    return; /* no col_..() or expert...() calls in following */
221
222
0
  switch (type)
223
0
    {
224
0
      case PACKET_TYPE_WHOIS_REQUEST:
225
0
        proto_tree_add_item(clique_rm_tree,
226
0
          hf_clique_rm_whois_request_id, tvb, offset, 4, ENC_BIG_ENDIAN);
227
0
        break;
228
0
      case PACKET_TYPE_WHOIS_REPLY:
229
0
        len = tvb_get_uint8(tvb, offset);
230
0
        proto_tree_add_item(clique_rm_tree,
231
0
          hf_clique_rm_whois_reply_name_length, tvb, offset, 1, ENC_BIG_ENDIAN);
232
0
        offset += 1;
233
0
        proto_tree_add_item(clique_rm_tree,
234
0
          hf_clique_rm_whois_reply_name, tvb, offset, len, ENC_ASCII);
235
0
        break;
236
0
      case PACKET_TYPE_REPAIR_REQUEST:
237
0
        proto_tree_add_item(clique_rm_tree,
238
0
          hf_clique_rm_repair_request_sender_id, tvb, offset, 4, ENC_BIG_ENDIAN);
239
0
        offset += 4;
240
241
0
        proto_tree_add_item(clique_rm_tree,
242
0
          hf_clique_rm_repair_request_packet_id, tvb, offset, 4, ENC_BIG_ENDIAN);
243
0
        break;
244
0
      case PACKET_TYPE_SESSION:
245
0
        dissect_depends(clique_rm_tree, tvb, offset);
246
0
        break;
247
0
      default:
248
0
        break;
249
0
    }
250
0
}
251
252
253
static bool
254
dissect_clique_rm_heur(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
255
0
{
256
0
  proto_item *ti;
257
0
  proto_tree *clique_rm_tree;
258
0
  uint8_t     version;
259
0
  uint8_t     type;
260
0
  int         offset = 0;
261
0
  uint64_t    qword;
262
263
0
  if (tvb_captured_length(tvb) < 12)
264
0
    return false;
265
266
0
  qword = tvb_get_ntoh48(tvb,0);
267
  /* ASCII str for 'Clique' = 0x436c69717565 */
268
0
  if(qword != UINT64_C (0x436c69717565))
269
0
    return false;
270
0
  offset += 6;
271
272
0
  version = tvb_get_uint8(tvb, offset);
273
0
  if (version != 1)
274
0
    return false;
275
0
  offset++;
276
277
0
  type = tvb_get_uint8(tvb, offset);
278
0
  offset++;
279
280
0
  col_set_str(pinfo->cinfo, COL_PROTOCOL, "Clique-rm");
281
0
  col_add_str(pinfo->cinfo, COL_INFO,
282
0
               val_to_str(pinfo->pool, type, packet_type_vals, "Unknown (0x%02x)"));
283
284
  /* rewind back to just behind the prefix */
285
0
  offset = 6;
286
287
0
  ti = proto_tree_add_item(tree, proto_clique_rm, tvb, 0, -1, ENC_NA);
288
0
  clique_rm_tree = proto_item_add_subtree(ti, ett_clique_rm);
289
290
0
  proto_tree_add_item(clique_rm_tree, hf_clique_rm_version, tvb, offset, 1,
291
0
                      ENC_BIG_ENDIAN);
292
0
  offset++;
293
294
0
  proto_tree_add_item(clique_rm_tree, hf_clique_rm_type, tvb, offset, 1,
295
0
                      ENC_BIG_ENDIAN);
296
0
  offset++;
297
298
0
  col_append_fstr(pinfo->cinfo, COL_INFO, ", sender: 0x%x",
299
0
                    tvb_get_ntohl(tvb, offset));
300
301
0
  proto_tree_add_item(clique_rm_tree, hf_clique_rm_sender, tvb, offset,
302
0
                      4, ENC_BIG_ENDIAN);
303
0
  offset += 4;
304
305
0
  if (IS_RELIABLE(type)) {
306
0
    col_append_fstr(pinfo->cinfo, COL_INFO, ", id: 0x%x",
307
0
                      tvb_get_ntohl(tvb, offset));
308
309
0
    dissect_reliable_packet(clique_rm_tree,   type, tvb, offset);
310
0
  } else {
311
0
    dissect_unreliable_packet(clique_rm_tree, type, tvb, offset);
312
0
  }
313
314
0
  return true;
315
0
}
316
317
318
/* Register the protocol with Wireshark */
319
320
void
321
proto_register_clique_rm(void)
322
15
{
323
324
/* Setup list of header fields  See Section 1.6.1 for details*/
325
15
  static hf_register_info hf[] = {
326
15
    { &hf_clique_rm_version,
327
15
      { "Version",           "clique_rm.version",
328
15
        FT_UINT8, BASE_DEC, NULL, 0x0,
329
15
        NULL, HFILL }
330
15
    },
331
15
    { &hf_clique_rm_type,
332
15
      { "Type",           "clique_rm.type",
333
15
        FT_UINT8, BASE_HEX, VALS(packet_type_vals), 0x0,
334
15
        NULL, HFILL }
335
15
    },
336
15
    { &hf_clique_rm_sender,
337
15
      { "Sender",           "clique_rm.sender",
338
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
339
15
        NULL, HFILL }
340
15
    },
341
15
    { &hf_clique_rm_packet_id,
342
15
      { "Packet id",           "clique_rm.packet_id",
343
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
344
15
        NULL, HFILL }
345
15
    },
346
15
    { &hf_clique_rm_depends,
347
15
      { "Depends",           "clique_rm.depends",
348
15
        FT_UINT8, BASE_HEX, NULL, 0x0,
349
15
        NULL, HFILL }
350
15
    },
351
15
    { &hf_clique_rm_depend_sender,
352
15
      { "Sender",           "clique_rm.depends.sender",
353
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
354
15
        NULL, HFILL }
355
15
    },
356
15
    { &hf_clique_rm_depend_packet_id,
357
15
      { "Packet id",           "clique_rm.depends.packet_id",
358
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
359
15
        NULL, HFILL }
360
15
    },
361
15
    { &hf_clique_rm_failures,
362
15
      { "Failures",           "clique_rm.failures",
363
15
        FT_UINT8, BASE_HEX, NULL, 0x0,
364
15
        NULL, HFILL }
365
15
    },
366
15
    { &hf_clique_rm_failures_senders,
367
15
      { "Sender",           "clique_rm.failures.sender",
368
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
369
15
        NULL, HFILL }
370
15
    },
371
15
    { &hf_clique_rm_attempt_join,
372
15
      { "New attempt join senders", "clique_rm.attempt_join",
373
15
        FT_UINT8, BASE_HEX, NULL, 0x0,
374
15
        NULL, HFILL }
375
15
    },
376
15
    { &hf_clique_rm_attempt_join_senders,
377
15
      { "Sender",           "clique_rm.attempt_join.sender",
378
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
379
15
        NULL, HFILL }
380
15
    },
381
15
    { &hf_clique_rm_join_failures,
382
15
      { "Join failures",           "clique_rm.join_failures",
383
15
        FT_UINT8, BASE_HEX, NULL, 0x0,
384
15
        NULL, HFILL }
385
15
    },
386
15
    { &hf_clique_rm_join_failures_senders,
387
15
      { "Sender",           "clique_rm.join_failures.sender",
388
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
389
15
        NULL, HFILL }
390
15
    },
391
15
    { &hf_clique_rm_data_flags,
392
15
      { "Data flags",           "clique_rm.data.flags",
393
15
        FT_UINT8, BASE_HEX, NULL, 0x0,
394
15
        NULL, HFILL }
395
15
    },
396
15
    { &hf_clique_rm_data_size,
397
15
      { "Data total size",           "clique_rm.data.size",
398
15
        FT_UINT32, BASE_DEC, NULL, 0x0,
399
15
        NULL, HFILL }
400
15
    },
401
15
    { &hf_clique_rm_data_stream_id,
402
15
      { "Data stream id",           "clique_rm.data.stream_id",
403
15
        FT_UINT16, BASE_HEX, NULL, 0x0,
404
15
        NULL, HFILL }
405
15
    },
406
15
    { &hf_clique_rm_data_data,
407
15
      { "Raw data",           "clique_rm.data.data",
408
15
        FT_BYTES, BASE_NONE, NULL, 0x0,
409
15
        NULL, HFILL }
410
15
    },
411
15
    { &hf_clique_rm_whois_request_id,
412
15
      { "Whois request id",           "clique_rm.whois_request.id",
413
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
414
15
        NULL, HFILL }
415
15
    },
416
15
    { &hf_clique_rm_whois_reply_name_length,
417
15
      { "Whois reply name length",    "clique_rm.whois_reply.length",
418
15
        FT_UINT8, BASE_DEC, NULL, 0x0,
419
15
        NULL, HFILL }
420
15
    },
421
15
    { &hf_clique_rm_whois_reply_name,
422
15
      { "Whois reply name",           "clique_rm.whois_reply.name",
423
15
        FT_STRINGZ, BASE_NONE, NULL, 0x0,
424
15
        NULL, HFILL }
425
15
    },
426
15
    { &hf_clique_rm_repair_request_sender_id,
427
15
      { "Repair request for sender",
428
15
        "clique_rm.repair_request.sender_id",
429
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
430
15
        NULL, HFILL }
431
15
    },
432
15
    { &hf_clique_rm_repair_request_packet_id,
433
15
      { "Repair request for packet",
434
15
        "clique_rm.repair_request.packet_id",
435
15
        FT_UINT32, BASE_HEX, NULL, 0x0,
436
15
        NULL, HFILL }
437
15
    },
438
15
  };
439
440
/* Setup protocol subtree array */
441
15
  static int *ett[] = {
442
15
    &ett_clique_rm,
443
15
    &ett_clique_rm_depends,
444
15
    &ett_clique_rm_depends_item,
445
15
    &ett_clique_rm_data,
446
15
    &ett_clique_rm_failures,
447
15
    &ett_clique_rm_join_failures,
448
15
    &ett_clique_rm_attempt_join,
449
15
    &ett_clique_rm_join,
450
15
  };
451
452
/* Register the protocol name and description */
453
15
  proto_clique_rm = proto_register_protocol("Clique Reliable Multicast Protocol", "Clique-rm", "clique-rm");
454
455
/* Required function calls to register the header fields and subtrees used */
456
15
  proto_register_field_array(proto_clique_rm, hf, array_length(hf));
457
15
  proto_register_subtree_array(ett, array_length(ett));
458
459
15
}
460
461
void
462
proto_reg_handoff_clique_rm(void)
463
15
{
464
15
  heur_dissector_add("udp", dissect_clique_rm_heur, "Clique RM over UDP", "clique_rm_udp", proto_clique_rm, HEURISTIC_DISABLE);
465
15
}
466
467
/*
468
 * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
469
 *
470
 * Local Variables:
471
 * c-basic-offset: 2
472
 * tab-width: 8
473
 * indent-tabs-mode: nil
474
 * End:
475
 *
476
 * ex: set shiftwidth=2 tabstop=8 expandtab:
477
 * :indentSize=2:tabSize=8:noTabs=true:
478
 */