Wireshark  4.3.0
The Wireshark network protocol analyzer
packet-lbm.h
1 /* packet-lbm.h
2  * Definitions for LBM packet dissection
3  *
4  * Copyright (c) 2005-2014 Informatica Corporation. All Rights Reserved.
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 #ifndef PACKET_LBM_H_INCLUDED
14 #define PACKET_LBM_H_INCLUDED
15 
16 /* A list of the taps etc. made available by these dissectors:
17  Taps:
18  lbm_stream
19  - A packet is queued for each UIM (unicast immediate message) LBMC message (or fragment)
20  - The data associated with each tap entry is described by lbm_uim_stream_tap_info_t
21  - A single packet may generate multiple tap entries (in the case that a single packet
22  contains multiple LBMC messages)
23  - An LBMC message that spans multiple packets will cause a single entry to be queued,
24  corresponding to the last packet spanned
25  lbm_uim
26  - A packet is queued for each complete (possibly reassembled) UIM message
27  - The data associated with each tap entry is described by lbm_uim_stream_info_t
28  - A single packet may generate multiple tap entries (in the case that a single packet
29  contains multiple complete UIM messages)
30  - An complete UIM message that spans multiple packets will cause a single entry to be queued,
31  corresponding to the last packet spanned
32  lbm_lbmr_topic_advertisement
33  - A packet is queued for each LBMR topic advertisement (TIR)
34  - The data associated with each tap entry is described by lbm_lbmr_topic_advertisement_tap_info_t
35  - A single LBMR message (which may span multiple IP frames, reassembled into a single UDP packet)
36  may generate multiple tap entries (in the case that a single LBMR message contains multiple topic
37  advertisements)
38  lbm_lbmr_topic_query
39  - A packet is queued for each LBMR topic query (TQR)
40  - The data associated with each tap entry is described by lbm_lbmr_topic_query_tap_info_t
41  - A single LBMR message (which may span multiple IP frames, reassembled into a single UDP packet)
42  may generate multiple tap entries (in the case that a single LBMR message contains multiple topic
43  queries)
44  lbm_lbmr_pattern_query
45  - A packet is queued for each LBMR pattern query (TQR specifying a pattern)
46  - The data associated with each tap entry is described by lbm_lbmr_pattern_query_tap_info_t
47  - A single LBMR message (which may span multiple IP frames, reassembled into a single UDP packet)
48  may generate multiple tap entries (in the case that a single LBMR message contains multiple pattern
49  queries)
50  lbm_lbmr_queue_advertisement
51  - A packet is queued for each LBMR queue advertisement (QIR)
52  - The data associated with each tap entry is described by lbm_lbmr_queue_advertisement_tap_info_t
53  - A single LBMR message (which may span multiple IP frames, reassembled into a single UDP packet)
54  may generate multiple tap entries (in the case that a single LBMR message contains multiple queue
55  advertisements)
56  lbm_lbmr_queue_query
57  - A packet is queued for each LBMR queue query (QQR)
58  - The data associated with each tap entry is described by lbm_lbmr_queue_query_tap_info_t
59  - A single LBMR message (which may span multiple IP frames, reassembled into a single UDP packet)
60  may generate multiple tap entries (in the case that a single LBMR message contains multiple queue
61  queries)
62  lbm_lbtrm
63  - A packet is queued for each LBTRM transport message
64  - The data associated with each tap entry is described by lbm_lbtrm_tap_info_t
65  - A single LBTRM transport message (which may span multiple IP frames, reassembled into a single UDP
66  packet) will generate a single tap entry
67  lbm_lbtru
68  - A packet is queued for each LBTRU transport message
69  - The data associated with each tap entry is described by lbm_lbtru_tap_info_t
70  - A single LBTRU transport message (which may span multiple IP frames, reassembled into a single UDP
71  packet) will generate a single tap entry
72  Heuristic subdissector tables:
73  lbm_msg_payload
74  - If the LBMC preference "Use heuristic sub-dissectors" is enabled, the dissector will call any dissector
75  registered in this table via heur_dissector_add(). This allows a customer plugin to dissect the
76  actual payload of their messages.
77 */
78 
79 #if defined(__FreeBSD__)
80 #include <sys/types.h>
81 #include <netinet/in.h>
82 #endif
83 #include <stddef.h>
84 
85 #ifdef HAVE_NETINET_IN_H
86 # include <netinet/in.h>
87 #endif
88 
89 #ifdef _WIN32
90 #include <winsock2.h>
91 #endif
92 
93 typedef guint8 lbm_uint8_t;
94 typedef guint16 lbm_uint16_t;
95 typedef guint32 lbm_uint32_t;
96 typedef guint64 lbm_uint64_t;
97 #define SIZEOF(TYPE, MEMBER) (gint)(sizeof(((TYPE *)0)->MEMBER))
98 #define OFFSETOF(TYPE, MEMBER) (gint)(offsetof(TYPE, MEMBER))
99 #define STRINGIZE(a) #a
100 #define MAKESTRING(a) STRINGIZE(a)
101 #define LBM_OTID_BLOCK_SZ 32
102 #define LBM_CONTEXT_INSTANCE_BLOCK_SZ 8
103 #define LBM_HMAC_BLOCK_SZ 20
104 
105 /* UAT macros for IPV4 fields. */
106 #define UAT_IPV4_CB_DEF(basename,field_name,rec_t) \
107  static bool basename ## _ ## field_name ## _chk_cb(void * u1 _U_, const char * strptr, unsigned len _U_, const void * u2 _U_, const void * u3 _U_, char ** err) \
108  { \
109  guint32 addr; \
110  if (!ws_inet_pton4(strptr, &addr)) \
111  { \
112  *err = g_strdup("invalid address"); \
113  return FALSE; \
114  } \
115  return TRUE; \
116  } \
117  static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* u1 _U_, const void* u2 _U_) \
118  { \
119  guint32 addr; \
120  char* new_buf = g_strndup(buf,len); \
121  g_free((((rec_t*)rec)->field_name)); \
122  (((rec_t*)rec)->field_name) = new_buf; \
123  ws_inet_pton4(new_buf, &addr); \
124  (((rec_t*)rec)->field_name ## _val_h) = g_ntohl(addr); \
125  } \
126  static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) \
127  {\
128  if (((rec_t*)rec)->field_name ) \
129  { \
130  *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
131  *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
132  } \
133  else \
134  { \
135  *out_ptr = g_strdup(""); \
136  *out_len = 0; \
137  } \
138  }
139 
140 #define UAT_FLD_IPV4(basename,field_name,title,desc) \
141  {#field_name, title, PT_TXTMOD_STRING,{basename ## _ ## field_name ## _chk_cb,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
142 
143 /* UAT macros for IPV4 Multicast fields. */
144 #define UAT_IPV4_MC_CB_DEF(basename,field_name,rec_t) \
145  static bool basename ## _ ## field_name ## _chk_cb(void * u1 _U_, const char * strptr, unsigned len _U_, const void * u2 _U_, const void * u3 _U_, char ** err) \
146  { \
147  guint32 addr; \
148  if (!ws_inet_pton4(strptr, &addr)) \
149  { \
150  *err = g_strdup("invalid address"); \
151  return FALSE; \
152  } \
153  if (!IN_MULTICAST(g_ntohl(addr)) && (g_ntohl(addr) != 0)) \
154  { \
155  *err = g_strdup("invalid multicast address"); \
156  return FALSE; \
157  } \
158  return TRUE; \
159  } \
160  static void basename ## _ ## field_name ## _set_cb(void* rec, const char* buf, unsigned len, const void* u1 _U_, const void* u2 _U_) \
161  { \
162  guint32 addr; \
163  char* new_buf = g_strndup(buf,len); \
164  g_free((((rec_t*)rec)->field_name)); \
165  (((rec_t*)rec)->field_name) = new_buf; \
166  ws_inet_pton4(new_buf, &addr); \
167  (((rec_t*)rec)->field_name ## _val_h) = g_ntohl(addr); \
168  } \
169  static void basename ## _ ## field_name ## _tostr_cb(void* rec, char** out_ptr, unsigned* out_len, const void* u1 _U_, const void* u2 _U_) \
170  {\
171  if (((rec_t*)rec)->field_name ) \
172  { \
173  *out_ptr = g_strdup((((rec_t*)rec)->field_name)); \
174  *out_len = (unsigned)strlen((((rec_t*)rec)->field_name)); \
175  } \
176  else \
177  { \
178  *out_ptr = g_strdup(""); \
179  *out_len = 0; \
180  } \
181  }
182 
183 #define UAT_FLD_IPV4_MC(basename,field_name,title,desc) \
184  {#field_name, title, PT_TXTMOD_STRING,{basename ## _ ## field_name ## _chk_cb,basename ## _ ## field_name ## _set_cb,basename ## _ ## field_name ## _tostr_cb},{0,0,0},0,desc,FLDFILL}
185 
186 typedef struct
187 {
188  guint32 domain;
189  address addr;
190  guint16 port;
192 
193 typedef struct
194 {
195  guint8 ctxinst[LBM_CONTEXT_INSTANCE_BLOCK_SZ];
197 
198 typedef enum
199 {
200  lbm_uim_instance_stream,
201  lbm_uim_domain_stream
202 } lbm_uim_stream_type_t;
203 
204 typedef struct
205 {
206  lbm_uim_stream_type_t type;
207  union
208  {
210  lbm_uim_stream_ctxinst_t ctxinst;
211  } stream_info;
213 
214 typedef struct
215 {
216  guint64 channel;
217  guint32 substream_id;
218  guint32 bytes;
219  lbm_uim_stream_endpoint_t endpoint_a;
220  lbm_uim_stream_endpoint_t endpoint_b;
222 
223 typedef struct
224 {
225  gchar * transport;
226  guint8 type;
227  gboolean retransmission;
228  guint32 sqn;
229  guint8 ncf_reason;
230  guint16 num_sqns;
231  guint32 * sqns;
233 
234 typedef struct
235 {
236  gchar * transport;
237  guint8 type;
238  gboolean retransmission;
239  guint32 sqn;
240  guint8 ncf_reason;
241  guint16 num_sqns;
242  guint16 creq_type;
243  guint16 rst_type;
244  guint32 * sqns;
246 
247 typedef struct
248 {
249  guint16 size;
250  guint8 topic_length;
251  guint8 source_length;
252  guint32 topic_index;
253  char topic[256];
254  char source[256];
256 
257 typedef struct
258 {
259  guint16 size;
260  guint8 topic_length;
261  char topic[256];
263 
264 typedef struct
265 {
266  guint16 size;
267  guint8 type;
268  guint8 pattern_length;
269  char pattern[256];
271 
272 #define LBMR_WILDCARD_PATTERN_TYPE_PCRE 1
273 #define LBMR_WILDCARD_PATTERN_TYPE_REGEX 2
274 
275 typedef struct
276 {
277  guint16 size;
278  guint16 port;
279  guint8 queue_length;
280  guint8 topic_length;
281  char queue[256];
282  char topic[256];
284 
285 typedef struct
286 {
287  guint16 size;
288  guint8 queue_length;
289  char queue[256];
291 
292 #define LBM_TOPIC_OPT_EXFUNC_FFLAG_LJ 0x00000001
293 #define LBM_TOPIC_OPT_EXFUNC_FFLAG_UME 0x00000002
294 #define LBM_TOPIC_OPT_EXFUNC_FFLAG_UMQ 0x00000004
295 #define LBM_TOPIC_OPT_EXFUNC_FFLAG_ULB 0x00000008
296 
297 /* LBT-RM packet types */
298 #define LBTRM_PACKET_TYPE_DATA 0x00
299 #define LBTRM_PACKET_TYPE_SM 0x02
300 #define LBTRM_PACKET_TYPE_NAK 0x03
301 #define LBTRM_PACKET_TYPE_NCF 0x04
302 
303 /* LBT-RM NCF reason types */
304 #define LBTRM_NCF_REASON_NO_RETRY 0x0
305 #define LBTRM_NCF_REASON_IGNORED 0x1
306 #define LBTRM_NCF_REASON_RX_DELAY 0x2
307 #define LBTRM_NCF_REASON_SHED 0x3
308 
309 /* LBT-RU packet types */
310 #define LBTRU_PACKET_TYPE_DATA 0x00
311 #define LBTRU_PACKET_TYPE_SM 0x02
312 #define LBTRU_PACKET_TYPE_NAK 0x03
313 #define LBTRU_PACKET_TYPE_NCF 0x04
314 #define LBTRU_PACKET_TYPE_ACK 0x05
315 #define LBTRU_PACKET_TYPE_CREQ 0x06
316 #define LBTRU_PACKET_TYPE_RST 0x07
317 
318 /* LBT-RU NCF reason types */
319 #define LBTRU_NCF_REASON_NO_RETRY 0x0
320 #define LBTRU_NCF_REASON_IGNORED 0x1
321 #define LBTRU_NCF_REASON_RX_DELAY 0x2
322 #define LBTRU_NCF_REASON_SHED 0x3
323 
324 /* LBT-RU CREQ types */
325 #define LBTRU_CREQ_REQUEST_SYN 0x0
326 
327 /* LBT-RU RST reasons */
328 #define LBTRU_RST_REASON_DEFAULT 0x0
329 
330 gboolean lbmc_test_lbmc_header(tvbuff_t * tvb, int offset);
331 int lbmc_dissect_lbmc_packet(tvbuff_t * tvb, int offset, packet_info * pinfo, proto_tree * tree, const char * tag_name, guint64 channel);
332 int lbmc_get_minimum_length(void);
333 guint16 lbmc_get_message_length(tvbuff_t * tvb, int offset);
334 gboolean lbmpdm_verify_payload(tvbuff_t * tvb, int offset, int * encoding, int * length);
335 int lbmpdm_dissect_lbmpdm_payload(tvbuff_t * tvb, int offset, packet_info * pinfo, proto_tree * tree, guint64 channel);
336 int lbmpdm_get_minimum_length(void);
337 int lbmr_dissect_umq_qmgmt(tvbuff_t * tvb, int offset, packet_info * pinfo, proto_tree * tree);
338 
339 extern const true_false_string lbm_ignore_flag;
340 extern const value_string lbm_wildcard_pattern_type[];
341 extern const value_string lbm_wildcard_pattern_type_short[];
342 
343 /*----------------------------------------------------------------------------*/
344 /* Channel interface. */
345 /*----------------------------------------------------------------------------*/
346 #define LBM_CHANNEL_NO_CHANNEL (~((guint64) 0))
347 
348 #define LBM_CHANNEL_TRANSPORT_LBTTCP 0x00
349 #define LBM_CHANNEL_TRANSPORT_LBTRU 0x01
350 #define LBM_CHANNEL_TRANSPORT_LBTRM 0x02
351 #define LBM_CHANNEL_TRANSPORT_LBTIPC 0x03
352 #define LBM_CHANNEL_TRANSPORT_LBTRDMA 0x04
353 #define LBM_CHANNEL_TRANSPORT_LBTSMX 0x05
354 #define LBM_CHANNEL_STREAM_TCP 0x10
355 #define LBM_CHANNEL_TCP 0x20
356 
357 #define LBM_CHANNEL_VALUE_MASK G_GUINT64_CONSTANT(0xfffffffffffff000)
358 #define LBM_CHANNEL_VALUE_SHIFT_COUNT 12
359 
360 void lbm_channel_reset(void);
361 guint64 lbm_channel_assign(guint8 channel_type);
362 gboolean lbm_channel_is_transport(guint64 channel);
363 guint8 lbm_channel_type(guint64 channel);
364 guint64 lbm_channel_assign_unknown_transport_source_lbttcp(void);
365 guint64 lbm_channel_assign_unknown_transport_client_lbttcp(void);
366 guint64 lbm_channel_assign_unknown_stream_tcp(void);
367 gboolean lbm_channel_is_unknown_transport_lbttcp(guint64 channel);
368 gboolean lbm_channel_is_unknown_transport_source_lbttcp(guint64 channel);
369 gboolean lbm_channel_is_unknown_transport_client_lbttcp(guint64 channel);
370 gboolean lbm_channel_is_unknown_stream_tcp(guint64 channel);
371 gboolean lbm_channel_is_known(guint64 channel);
372 
373 #define LBM_CHANNEL_ID(ch) ((ch & LBM_CHANNEL_VALUE_MASK) >> LBM_CHANNEL_VALUE_SHIFT_COUNT)
374 
375 /*----------------------------------------------------------------------------*/
376 /* Frame/SQN interface. */
377 /*----------------------------------------------------------------------------*/
378 typedef struct
379 {
380  guint32 frame;
381  guint8 type;
382  guint32 sqn;
383  guint32 previous_frame;
384  guint32 previous_type_frame;
385  guint32 next_frame;
386  guint32 next_type_frame;
387  gboolean retransmission;
388  guint32 sqn_gap;
389  guint32 ooo_gap;
390  gboolean duplicate;
392 
393 typedef struct
394 {
395  guint32 frame;
396  gboolean retransmission;
398 
399 typedef struct
400 {
401  guint32 sqn;
402  guint32 frame_count;
403  wmem_tree_t * frame; /* List of lbm_transport_sqn_frame_t */
405 
406 lbm_transport_frame_t * lbm_transport_frame_add(wmem_tree_t * list, guint8 type, guint32 frame, guint32 sqn, gboolean retransmission);
407 lbm_transport_sqn_t * lbm_transport_sqn_add(wmem_tree_t * list, lbm_transport_frame_t * frame);
408 
409 /*----------------------------------------------------------------------------*/
410 /* Topic interface. */
411 /*----------------------------------------------------------------------------*/
412 void lbm_topic_init(void);
413 const char * lbm_topic_find(guint64 channel, guint32 topic_index);
414 void lbm_topic_add(guint64 channel, guint32 topic_index, const char * name);
415 
416 #endif
417 
418 /*
419  * Editor modelines - https://www.wireshark.org/tools/modelines.html
420  *
421  * Local variables:
422  * c-basic-offset: 4
423  * tab-width: 8
424  * indent-tabs-mode: nil
425  * End:
426  *
427  * vi: set shiftwidth=4 tabstop=8 expandtab:
428  * :indentSize=4:tabSize=8:noTabs=true:
429  */
Definition: address.h:56
Definition: packet_info.h:44
Definition: proto.h:904
Definition: value_string.h:26
Definition: wmem_tree-int.h:48
Definition: packet-lbm.h:265
Definition: packet-lbm.h:276
Definition: packet-lbm.h:286
Definition: packet-lbm.h:248
Definition: packet-lbm.h:258
Definition: packet-lbm.h:224
Definition: packet-lbm.h:235
Definition: packet-lbm.h:379
Definition: packet-lbm.h:394
Definition: packet-lbm.h:400
Definition: packet-lbm.h:194
Definition: packet-lbm.h:187
Definition: packet-lbm.h:205
Definition: packet-lbm.h:215
Definition: tfs.h:27
Definition: tvbuff-int.h:35