Coverage Report

Created: 2026-11-12 07:01

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