Coverage Report

Created: 2026-01-02 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/wireshark/epan/dissectors/packet-db-lsp.c
Line
Count
Source
1
/* packet-db-lsp.c
2
 * Routines for Dropbox LAN sync Protocol
3
 *
4
 * Copyright 2010, Stig Bjorlykke <stig@bjorlykke.org>
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
#include <epan/asn1.h>
17
#include <epan/prefs.h>
18
19
#include "packet-tcp.h"
20
#include "packet-x509af.h"
21
22
16
#define PNAME  "Dropbox LAN sync Protocol"
23
16
#define PSNAME "DB-LSP"
24
14
#define PFNAME "db-lsp"
25
26
15
#define PNAME_DISC  "Dropbox LAN sync Discovery Protocol"
27
29
#define PSNAME_DISC "DB-LSP-DISC"
28
14
#define PFNAME_DISC "db-lsp-disc"
29
30
28
#define DB_LSP_PORT  17500
31
32
void proto_register_db_lsp(void);
33
void proto_reg_handoff_db_lsp(void);
34
35
static int proto_db_lsp;
36
static int proto_db_lsp_disc;
37
38
static int hf_type;
39
static int hf_magic;
40
static int hf_length;
41
static int hf_opvalue;
42
static int hf_data;
43
static int hf_value;
44
static int hf_text;
45
46
static int ett_db_lsp;
47
48
static heur_dissector_list_t heur_subdissector_list;
49
50
static dissector_handle_t db_lsp_tcp_handle;
51
static dissector_handle_t db_lsp_udp_handle;
52
53
/* Use heuristic */
54
static bool try_heuristic = true;
55
/* desegmentation of tcp payload */
56
static bool db_lsp_desegment = true;
57
58
0
#define TYPE_CONFIG   0x16
59
0
#define TYPE_DATA     0x17
60
61
static const value_string type_vals[] = {
62
  { TYPE_CONFIG,    "Configuration" },
63
  { TYPE_DATA,      "Data" },
64
  { 0, NULL }
65
};
66
67
0
#define OP_CERT       0x0B
68
69
static const value_string op_vals[] = {
70
  { OP_CERT,   "Certificate" },
71
  { 0, NULL }
72
};
73
74
static int
75
dissect_db_lsp_pdu (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
76
2
{
77
2
  proto_tree *db_lsp_tree;
78
2
  proto_item *db_lsp_item;
79
2
  int         offset = 0;
80
2
  uint8_t     type, opvalue;
81
2
  uint16_t    magic, length;
82
83
2
  col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME);
84
2
  col_set_str (pinfo->cinfo, COL_INFO, PNAME);
85
86
2
  db_lsp_item = proto_tree_add_item (tree, proto_db_lsp, tvb, offset, -1, ENC_NA);
87
2
  db_lsp_tree = proto_item_add_subtree (db_lsp_item, ett_db_lsp);
88
89
2
  type = tvb_get_uint8 (tvb, offset);
90
2
  proto_tree_add_item (db_lsp_tree, hf_type, tvb, offset, 1, ENC_BIG_ENDIAN);
91
2
  offset += 1;
92
93
2
  if (type == 0x80) {
94
    /* Two unknown bytes */
95
1
    offset += 2;
96
1
  }
97
98
2
  magic = tvb_get_ntohs (tvb, offset);
99
2
  proto_tree_add_item (db_lsp_tree, hf_magic, tvb, offset, 2, ENC_BIG_ENDIAN);
100
2
  offset += 2;
101
102
2
  length = tvb_get_ntohs (tvb, offset);
103
2
  proto_tree_add_item (db_lsp_tree, hf_length, tvb, offset, 2, ENC_BIG_ENDIAN);
104
2
  offset += 2;
105
106
2
  if (magic != 0x0301 || length > tvb_reported_length_remaining (tvb, offset)) {
107
    /* Probably an unknown packet */
108
    /* expert_add_info_format (pinfo, db_lsp_item, PI_UNDECODED, PI_WARN, "Unknown packet"); */
109
2
    return 0;
110
2
  }
111
112
0
  if (type == TYPE_CONFIG) {
113
0
    opvalue = tvb_get_uint8 (tvb, offset);
114
0
    proto_tree_add_item (db_lsp_tree, hf_opvalue, tvb, offset, 1, ENC_BIG_ENDIAN);
115
116
0
    if (opvalue == OP_CERT) {
117
      /* X509 Certificate */
118
0
      tvbuff_t *cert_tvb = tvb_new_subset_length (tvb, offset+10, length-10);
119
0
      dissect_x509af_Certificate_PDU (cert_tvb, pinfo, db_lsp_tree, NULL);
120
0
    } else {
121
0
      proto_tree_add_item (db_lsp_tree, hf_value, tvb, offset, length, ENC_NA);
122
0
    }
123
0
  } else if (type == TYPE_DATA) {
124
0
    proto_tree_add_item (db_lsp_tree, hf_data, tvb, offset, length, ENC_NA);
125
0
  } else {
126
0
    proto_tree_add_item (db_lsp_tree, hf_value, tvb, offset, length, ENC_NA);
127
0
  }
128
  /*offset += length;*/
129
130
0
  proto_item_append_text (db_lsp_item, ", Type: %d, Length: %d", type, length);
131
0
  proto_item_set_len (db_lsp_item, length + 5);
132
0
  return tvb_reported_length(tvb);
133
2
}
134
135
static unsigned
136
get_db_lsp_pdu_len (packet_info *pinfo _U_, tvbuff_t *tvb,
137
                    int offset, void *data _U_)
138
3
{
139
3
  if (tvb_get_ntohs (tvb, offset + 1) != 0x0301) {
140
    /* Unknown data, eat remaining data for this frame */
141
2
    return tvb_reported_length_remaining (tvb, offset);
142
2
  }
143
144
1
  return tvb_get_ntohs (tvb, offset + 3) + 5;
145
3
}
146
147
static int
148
dissect_db_lsp_tcp (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data)
149
3
{
150
3
  tcp_dissect_pdus (tvb, pinfo, tree, db_lsp_desegment, 5,
151
3
                    get_db_lsp_pdu_len, dissect_db_lsp_pdu, data);
152
3
  return tvb_reported_length(tvb);
153
3
}
154
155
static int
156
dissect_db_lsp_disc (tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
157
1
{
158
1
  proto_tree *db_lsp_tree;
159
1
  proto_item *db_lsp_item;
160
1
  int         offset = 0;
161
1
  heur_dtbl_entry_t *hdtbl_entry;
162
1
  proto_tree *data_subtree;
163
164
1
  col_set_str (pinfo->cinfo, COL_PROTOCOL, PSNAME_DISC);
165
1
  col_set_str (pinfo->cinfo, COL_INFO, PNAME_DISC);
166
167
1
  db_lsp_item = proto_tree_add_item (tree, proto_db_lsp_disc, tvb, offset, -1, ENC_NA);
168
1
  db_lsp_tree = proto_item_add_subtree (db_lsp_item, ett_db_lsp);
169
170
  /* try the heuristic dissectors */
171
1
  if (try_heuristic) {
172
1
    data_subtree = proto_item_add_subtree(db_lsp_item, ett_db_lsp);
173
1
    if (dissector_try_heuristic(heur_subdissector_list, tvb, pinfo, data_subtree, &hdtbl_entry, NULL)) {
174
0
      return tvb_captured_length(tvb);
175
0
    }
176
1
  }
177
178
  /* heuristic failed. Print remaining bytes as text */
179
1
  proto_tree_add_item (db_lsp_tree, hf_text, tvb, offset, -1, ENC_ASCII);
180
1
  return tvb_captured_length(tvb);
181
1
}
182
183
void
184
proto_register_db_lsp (void)
185
14
{
186
14
  static hf_register_info hf[] = {
187
14
    { &hf_type,
188
14
      { "Type", "db-lsp.type",
189
14
        FT_UINT8, BASE_DEC_HEX, VALS(type_vals), 0x0,
190
14
        NULL, HFILL } },
191
192
14
    { &hf_magic,
193
14
      { "Magic", "db-lsp.magic",
194
14
        FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
195
14
        "Magic number", HFILL } },
196
197
14
    { &hf_length,
198
14
      { "Length", "db-lsp.length",
199
14
        FT_UINT16, BASE_DEC_HEX, NULL, 0x0,
200
14
        "Length in bytes", HFILL } },
201
202
14
    { &hf_opvalue,
203
14
      { "OP Value", "db-lsp.op",
204
14
        FT_UINT8, BASE_DEC_HEX, VALS(op_vals), 0x0,
205
14
        NULL, HFILL } },
206
207
14
    { &hf_value,
208
14
      { "Value", "db-lsp.value",
209
14
        FT_BYTES, BASE_NONE, NULL, 0x0,
210
14
        NULL, HFILL } },
211
212
14
    { &hf_data,
213
14
      { "Data", "db-lsp.data",
214
14
        FT_BYTES, BASE_NONE, NULL, 0x0,
215
14
        NULL, HFILL } },
216
217
14
    { &hf_text,
218
14
      { "Text", "db-lsp.text",
219
14
        FT_STRING, BASE_NONE, NULL, 0x0,
220
14
        NULL, HFILL } },
221
14
  };
222
223
14
  static int *ett[] = {
224
14
    &ett_db_lsp,
225
14
  };
226
227
14
  module_t *db_lsp_module;
228
229
14
  proto_db_lsp = proto_register_protocol (PNAME, PSNAME, PFNAME);
230
14
  proto_db_lsp_disc = proto_register_protocol (PNAME_DISC, PSNAME_DISC, PFNAME_DISC);
231
14
  db_lsp_tcp_handle = register_dissector ("db-lsp.tcp", dissect_db_lsp_tcp, proto_db_lsp);
232
14
  db_lsp_udp_handle = register_dissector ("db-lsp.udp", dissect_db_lsp_disc, proto_db_lsp_disc);
233
234
14
  heur_subdissector_list = register_heur_dissector_list_with_description("db-lsp", PSNAME_DISC " payload", proto_db_lsp);
235
236
14
  proto_register_field_array (proto_db_lsp, hf, array_length (hf));
237
14
  proto_register_subtree_array (ett, array_length (ett));
238
239
  /* Register our configuration options */
240
14
  db_lsp_module = prefs_register_protocol (proto_db_lsp, NULL);
241
242
14
  prefs_register_bool_preference (db_lsp_module, "desegment_pdus",
243
14
                                  "Reassemble PDUs spanning multiple TCP segments",
244
14
                                  "Whether the LAN sync dissector should reassemble PDUs"
245
14
                                  " spanning multiple TCP segments."
246
14
                                  " To use this option, you must also enable \"Allow subdissectors"
247
14
                                  " to reassemble TCP streams\" in the TCP protocol settings.",
248
14
                                  &db_lsp_desegment);
249
250
14
  prefs_register_bool_preference(db_lsp_module, "try_heuristic",
251
14
                                  "Try heuristic sub-dissectors",
252
14
                                  "Try to decode the payload using an heuristic sub-dissector",
253
14
                                  &try_heuristic);
254
14
}
255
256
void
257
proto_reg_handoff_db_lsp (void)
258
14
{
259
14
  dissector_add_uint_with_preference("tcp.port", DB_LSP_PORT, db_lsp_tcp_handle);
260
14
  dissector_add_uint_with_preference("udp.port", DB_LSP_PORT, db_lsp_udp_handle);
261
14
}
262
263
/*
264
 * Editor modelines
265
 *
266
 * Local Variables:
267
 * c-basic-offset: 2
268
 * tab-width: 8
269
 * indent-tabs-mode: nil
270
 * End:
271
 *
272
 * ex: set shiftwidth=2 tabstop=8 expandtab:
273
 * :indentSize=2:tabSize=8:noTabs=true:
274
 */