1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
|
/* packet-lbm.c
* Routines for LBM Packet dissection
*
* Copyright (c) 2005-2014 Informatica Corporation. All Rights Reserved.
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald@wireshark.org>
* Copyright 1998 Gerald Combs
*
* SPDX-License-Identifier: GPL-2.0-or-later
*/
#include "config.h"
#include <epan/packet.h>
#include "packet-lbm.h"
void proto_register_lbm(void);
/*----------------------------------------------------------------------------*/
/* Value translation tables. */
/*----------------------------------------------------------------------------*/
const true_false_string lbm_ignore_flag =
{
"May be ignored",
"Must be processed"
};
#define LBM_WILDCARD_PATTERN_TYPE_PCRE 1
#define LBM_WILDCARD_PATTERN_TYPE_REGEX 2
const value_string lbm_wildcard_pattern_type[] =
{
{ LBM_WILDCARD_PATTERN_TYPE_PCRE, "Perl Compatible Regular Expression (PCRE)" },
{ LBM_WILDCARD_PATTERN_TYPE_REGEX, "POSIX Extended Regular Expression (REGEX)" },
{ 0x0, NULL }
};
const value_string lbm_wildcard_pattern_type_short[] =
{
{ LBM_WILDCARD_PATTERN_TYPE_PCRE, "PCRE" },
{ LBM_WILDCARD_PATTERN_TYPE_REGEX, "REGEX" },
{ 0x0, NULL }
};
/* Initialization function, called whenever Wireshark loads a new capture, etc. */
static void lbm_init(void)
{
lbm_channel_reset();
}
/* Register all the bits needed with the filtering engine */
void proto_register_lbm(void)
{
register_init_routine(lbm_init);
}
/*----------------------------------------------------------------------------*/
/* Channel interface. */
/*----------------------------------------------------------------------------*/
/*
lbm_next_channel_value is a counter (akin to tcp_stream_count in packet-tcp.c) used to assign a unique index to an LBM communication
stream or transport session. The actual channel value consists of:
- The lower 52 bits of the counter, shifted left 12 bits
- A 4-bit source/client classification (for unicast channels), shifted left 8 bits
- An 8-bit channel type
6 1 1 0 0 0
3 2 1 8 7 0
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Counter | S/C | Type |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
The counter wraps at 0x000ffffffffffffe, and is reset to 1 whenever Wireshark invokes any init routines registered via
register_init_routine() (the call to lbm_channel_reset() is in packet-lbm.c).
Special values are used as placeholders to indicate an as-yet-unknown transport or stream TCP channel.
*/
static guint64 lbm_next_channel_value = 1;
#define LBM_CHANNEL_TYPE_MASK G_GUINT64_CONSTANT(0x00000000000000ff)
#define LBM_CHANNEL_VALUE_LIMIT_MASK G_GUINT64_CONSTANT(0x000ffffffffffffff)
#define LBM_CHANNEL_MAX_VALUE G_GUINT64_CONSTANT(0x000ffffffffffffe)
#define LBM_CHANNEL_VALUE_UNKNOWN G_GUINT64_CONSTANT(0xfffffffffffff000)
#define LBM_CHANNEL_VALUE_UNKNOWN_SOURCE G_GUINT64_CONSTANT(0xfffffffffffff100)
#define LBM_CHANNEL_VALUE_UNKNOWN_CLIENT G_GUINT64_CONSTANT(0xfffffffffffff200)
#define LBM_CHANNEL_UNKNOWN_TRANSPORT_SOURCE_LBTTCP (LBM_CHANNEL_VALUE_UNKNOWN_SOURCE | LBM_CHANNEL_TRANSPORT_LBTTCP)
#define LBM_CHANNEL_UNKNOWN_TRANSPORT_CLIENT_LBTTCP (LBM_CHANNEL_VALUE_UNKNOWN_CLIENT | LBM_CHANNEL_TRANSPORT_LBTTCP)
#define LBM_CHANNEL_UNKNOWN_STREAM_TCP (LBM_CHANNEL_VALUE_UNKNOWN | LBM_CHANNEL_STREAM_TCP)
#define LBM_CHANNEL_TYPE(ch) ((guint8)(ch & LBM_CHANNEL_TYPE_MASK))
void lbm_channel_reset(void)
{
lbm_next_channel_value = 1;
}
guint64 lbm_channel_assign(guint8 channel_type)
{
guint64 ch;
guint64 ch_counter = lbm_next_channel_value++;
if (lbm_next_channel_value == LBM_CHANNEL_MAX_VALUE)
{
lbm_next_channel_value = 1;
}
ch = ((guint64)((ch_counter & LBM_CHANNEL_VALUE_LIMIT_MASK) << LBM_CHANNEL_VALUE_SHIFT_COUNT)) | channel_type;
return (ch);
}
gboolean lbm_channel_is_transport(guint64 channel)
{
guint8 ch_type;
ch_type = LBM_CHANNEL_TYPE(channel);
switch (ch_type)
{
case LBM_CHANNEL_TRANSPORT_LBTTCP:
case LBM_CHANNEL_TRANSPORT_LBTRU:
case LBM_CHANNEL_TRANSPORT_LBTRM:
case LBM_CHANNEL_TRANSPORT_LBTIPC:
case LBM_CHANNEL_TRANSPORT_LBTRDMA:
case LBM_CHANNEL_TRANSPORT_LBTSMX:
return (TRUE);
break;
default:
break;
}
return (FALSE);
}
guint8 lbm_channel_type(guint64 channel)
{
guint8 ch_type;
ch_type = LBM_CHANNEL_TYPE(channel);
return (ch_type);
}
guint64 lbm_channel_assign_unknown_transport_source_lbttcp(void)
{
return (LBM_CHANNEL_UNKNOWN_TRANSPORT_SOURCE_LBTTCP);
}
guint64 lbm_channel_assign_unknown_transport_client_lbttcp(void)
{
return (LBM_CHANNEL_UNKNOWN_TRANSPORT_CLIENT_LBTTCP);
}
guint64 lbm_channel_assign_unknown_stream_tcp(void)
{
return (LBM_CHANNEL_UNKNOWN_STREAM_TCP);
}
gboolean lbm_channel_is_unknown_transport_lbttcp(guint64 channel)
{
return (lbm_channel_is_unknown_transport_source_lbttcp(channel) || lbm_channel_is_unknown_transport_client_lbttcp(channel));
}
gboolean lbm_channel_is_unknown_transport_source_lbttcp(guint64 channel)
{
if (channel == LBM_CHANNEL_UNKNOWN_TRANSPORT_SOURCE_LBTTCP)
{
return (TRUE);
}
return (FALSE);
}
gboolean lbm_channel_is_unknown_transport_client_lbttcp(guint64 channel)
{
if (channel == LBM_CHANNEL_UNKNOWN_TRANSPORT_CLIENT_LBTTCP)
{
return (TRUE);
}
return (FALSE);
}
gboolean lbm_channel_is_unknown_stream_tcp(guint64 channel)
{
if (channel == LBM_CHANNEL_UNKNOWN_STREAM_TCP)
{
return (TRUE);
}
return (FALSE);
}
gboolean lbm_channel_is_known(guint64 channel)
{
return (!lbm_channel_is_unknown_transport_lbttcp(channel) && !lbm_channel_is_unknown_stream_tcp(channel));
}
/*----------------------------------------------------------------------------*/
/* Frame/SQN interface. */
/*----------------------------------------------------------------------------*/
lbm_transport_frame_t * lbm_transport_frame_add(wmem_tree_t * list, guint8 type, guint32 frame, guint32 sqn, gboolean retransmission)
{
lbm_transport_frame_t * frame_entry = NULL;
/* Locate the frame. */
frame_entry = (lbm_transport_frame_t *) wmem_tree_lookup32(list, frame);
if (frame_entry != NULL)
{
return (frame_entry);
}
frame_entry = wmem_new(wmem_file_scope(), lbm_transport_frame_t);
frame_entry->frame = frame;
frame_entry->type = type;
frame_entry->sqn = sqn;
frame_entry->previous_frame = 0;
frame_entry->previous_type_frame = 0;
frame_entry->next_frame = 0;
frame_entry->next_type_frame = 0;
frame_entry->retransmission = retransmission;
frame_entry->sqn_gap = 0;
frame_entry->ooo_gap = 0;
frame_entry->duplicate = FALSE;
wmem_tree_insert32(list, frame, (void *) frame_entry);
return (frame_entry);
}
lbm_transport_sqn_t * lbm_transport_sqn_add(wmem_tree_t * list, lbm_transport_frame_t * frame)
{
lbm_transport_sqn_t * sqn_entry = NULL;
lbm_transport_sqn_frame_t * frame_entry = NULL;
/* Locate the SQN. */
sqn_entry = (lbm_transport_sqn_t *) wmem_tree_lookup32(list, frame->sqn);
if (sqn_entry == NULL)
{
sqn_entry = wmem_new(wmem_file_scope(), lbm_transport_sqn_t);
sqn_entry->sqn = frame->sqn;
sqn_entry->frame_count = 0;
sqn_entry->frame = wmem_tree_new(wmem_file_scope());
wmem_tree_insert32(list, frame->sqn, (void *) sqn_entry);
}
/* Add this frame to the list of frames this SQN appears in. */
frame_entry = wmem_new(wmem_file_scope(), lbm_transport_sqn_frame_t);
frame_entry->frame = frame->frame;
frame_entry->retransmission = frame->retransmission;
wmem_tree_insert32(sqn_entry->frame, frame->frame, (void *) frame_entry);
sqn_entry->frame_count++;
return (sqn_entry);
}
/*----------------------------------------------------------------------------*/
/* Topic interface. */
/*----------------------------------------------------------------------------*/
static wmem_tree_t * lbm_topic_table = NULL;
#define LBM_TOPIC_KEY_ELEMENT_COUNT 3
#define LBM_TOPIC_KEY_ELEMENT_CHANNEL_HIGH 0
#define LBM_TOPIC_KEY_ELEMENT_CHANNEL_LOW 1
#define LBM_TOPIC_KEY_ELEMENT_TOPIC_INDEX 2
struct lbm_topic_t_stct;
typedef struct lbm_topic_t_stct lbm_topic_t;
typedef struct
{
guint64 channel;
guint32 topic_idx;
lbm_topic_t * topic;
} lbm_topic_key_t;
struct lbm_topic_t_stct
{
lbm_topic_key_t key;
char * topic;
};
void lbm_topic_init(void)
{
lbm_topic_table = wmem_tree_new_autoreset(wmem_epan_scope(), wmem_file_scope());
}
static void lbm_topic_build_key(guint32 * key_value, wmem_tree_key_t * key, guint64 channel, guint32 topic_index)
{
key_value[LBM_TOPIC_KEY_ELEMENT_CHANNEL_HIGH] = (guint32) ((channel >> 32) & 0xffffffff);
key_value[LBM_TOPIC_KEY_ELEMENT_CHANNEL_LOW] = (guint32) (channel & 0xffffffff);
key_value[LBM_TOPIC_KEY_ELEMENT_TOPIC_INDEX] = topic_index;
key[0].length = LBM_TOPIC_KEY_ELEMENT_COUNT;
key[0].key = key_value;
key[1].length = 0;
key[1].key = NULL;
}
static lbm_topic_t * lbm_topic_locate(guint64 channel, guint32 topic_index)
{
lbm_topic_t * entry = NULL;
guint32 keyval[LBM_TOPIC_KEY_ELEMENT_COUNT];
wmem_tree_key_t tkey[2];
lbm_topic_build_key(keyval, tkey, channel, topic_index);
entry = (lbm_topic_t *) wmem_tree_lookup32_array(lbm_topic_table, tkey);
return (entry);
}
const char * lbm_topic_find(guint64 channel, guint32 topic_index)
{
lbm_topic_t * entry = NULL;
const char * topic = NULL;
entry = lbm_topic_locate(channel, topic_index);
if (entry != NULL)
{
topic = entry->topic;
}
return (topic);
}
void lbm_topic_add(guint64 channel, guint32 topic_index, const char * name)
{
lbm_topic_t * entry;
guint32 keyval[LBM_TOPIC_KEY_ELEMENT_COUNT];
wmem_tree_key_t tkey[2];
entry = lbm_topic_locate(channel, topic_index);
if (entry != NULL)
{
return;
}
entry = wmem_new(wmem_file_scope(), lbm_topic_t);
entry->key.channel = channel;
entry->key.topic_idx = topic_index;
entry->key.topic = entry;
entry->topic = wmem_strdup(wmem_file_scope(), name);
lbm_topic_build_key(keyval, tkey, channel, topic_index);
wmem_tree_insert32_array(lbm_topic_table, tkey, (void *) entry);
}
/*
* Editor modelines - https://www.wireshark.org/tools/modelines.html
*
* Local variables:
* c-basic-offset: 4
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* vi: set shiftwidth=4 tabstop=8 expandtab:
* :indentSize=4:tabSize=8:noTabs=true:
*/
|