2 * Routines for LBM TCP Packet dissection
4 * Copyright (c) 2005-2014 Informatica Corporation. All Rights Reserved.
6 * Wireshark - Network traffic analyzer
7 * By Gerald Combs <gerald@wireshark.org>
8 * Copyright 1998 Gerald Combs
10 * SPDX-License-Identifier: GPL-2.0-or-later
15 #include <epan/packet.h>
16 #include <epan/prefs.h>
18 #include <epan/to_str.h>
19 #include "packet-tcp.h"
20 #include "packet-lbm.h"
21 #include "packet-lbttcp.h"
23 void proto_register_lbttcp(void);
24 void proto_reg_handoff_lbttcp(void);
27 static int proto_lbttcp
;
29 /* Dissector handle */
30 static dissector_handle_t lbttcp_dissector_handle
;
32 /*----------------------------------------------------------------------------*/
33 /* LBT-TCP protocol management. */
34 /*----------------------------------------------------------------------------*/
38 wmem_tree_t
* frame_tree
;
39 wmem_tree_t
* session_tree
;
40 } lbttcp_transport_conv_data_t
;
42 static const address lbttcp_null_address
= ADDRESS_INIT_NONE
;
44 lbttcp_transport_t
* lbttcp_transport_find(const address
* source_address
, uint16_t source_port
, uint32_t session_id
, uint32_t frame
)
46 lbttcp_transport_t
* entry
= NULL
;
47 conversation_t
* conv
= NULL
;
48 lbttcp_transport_conv_data_t
* conv_data
= NULL
;
50 conv
= find_conversation(frame
, source_address
, &lbttcp_null_address
, CONVERSATION_TCP
, source_port
, 0, 0);
53 conv_data
= (lbttcp_transport_conv_data_t
*) conversation_get_proto_data(conv
, proto_lbttcp
);
54 if (conv_data
!= NULL
)
56 entry
= (lbttcp_transport_t
*) wmem_tree_lookup32(conv_data
->session_tree
, session_id
);
62 static lbttcp_transport_t
* lbttcp_transport_create(const address
* source_address
, uint16_t source_port
, uint32_t session_id
)
64 lbttcp_transport_t
* transport
= NULL
;
66 transport
= wmem_new(wmem_file_scope(), lbttcp_transport_t
);
67 copy_address_wmem(wmem_file_scope(), &(transport
->source_address
), source_address
);
68 transport
->source_port
= source_port
;
69 transport
->session_id
= session_id
;
70 transport
->channel
= lbm_channel_assign(LBM_CHANNEL_TRANSPORT_LBTTCP
);
71 transport
->next_client_id
= 1;
72 transport
->client_list
= wmem_list_new(wmem_file_scope());
76 lbttcp_transport_t
* lbttcp_transport_add(const address
* source_address
, uint16_t source_port
, uint32_t session_id
, uint32_t frame
)
78 lbttcp_transport_t
* entry
= NULL
;
79 conversation_t
* conv
= NULL
;
80 lbttcp_transport_conv_data_t
* conv_data
= NULL
;
82 conv
= find_conversation(frame
, source_address
, &lbttcp_null_address
, CONVERSATION_TCP
, source_port
, 0, 0);
85 conv
= conversation_new(frame
, source_address
, &lbttcp_null_address
, CONVERSATION_TCP
, source_port
, 0, 0);
87 conv_data
= (lbttcp_transport_conv_data_t
*) conversation_get_proto_data(conv
, proto_lbttcp
);
88 if (conv_data
== NULL
)
90 conv_data
= wmem_new(wmem_file_scope(), lbttcp_transport_conv_data_t
);
91 conv_data
->frame_tree
= wmem_tree_new(wmem_file_scope());
92 conv_data
->session_tree
= wmem_tree_new(wmem_file_scope());
93 conversation_add_proto_data(conv
, proto_lbttcp
, (void *) conv_data
);
95 entry
= (lbttcp_transport_t
*) wmem_tree_lookup32(conv_data
->session_tree
, session_id
);
100 entry
= lbttcp_transport_create(source_address
, source_port
, session_id
);
101 wmem_tree_insert32(conv_data
->session_tree
, session_id
, (void *) entry
);
102 wmem_tree_insert32(conv_data
->frame_tree
, frame
, (void *) entry
);
106 static lbttcp_client_transport_t
* lbttcp_client_transport_find(lbttcp_transport_t
* transport
, const address
* receiver_address
, uint16_t receiver_port
, uint32_t frame
)
108 lbttcp_client_transport_t
* entry
= NULL
;
109 conversation_t
* client_conv
= NULL
;
111 if (transport
== NULL
)
115 client_conv
= find_conversation(frame
, &(transport
->source_address
), receiver_address
, CONVERSATION_TCP
, transport
->source_port
, receiver_port
, 0);
116 if (client_conv
!= NULL
)
118 wmem_tree_t
* session_tree
= NULL
;
120 session_tree
= (wmem_tree_t
*) conversation_get_proto_data(client_conv
, proto_lbttcp
);
121 if (session_tree
!= NULL
)
123 entry
= (lbttcp_client_transport_t
*) wmem_tree_lookup32(session_tree
, transport
->session_id
);
129 static lbttcp_client_transport_t
* lbttcp_client_transport_add(lbttcp_transport_t
* transport
, const address
* receiver_address
, uint16_t receiver_port
, uint32_t frame
)
131 lbttcp_client_transport_t
* entry
;
132 conversation_t
* client_conv
= NULL
;
133 wmem_tree_t
* session_tree
= NULL
;
135 if (transport
== NULL
)
139 entry
= lbttcp_client_transport_find(transport
, receiver_address
, receiver_port
, frame
);
144 entry
= wmem_new(wmem_file_scope(), lbttcp_client_transport_t
);
145 copy_address_wmem(wmem_file_scope(), &(entry
->receiver_address
), receiver_address
);
146 entry
->receiver_port
= receiver_port
;
147 entry
->id
= transport
->next_client_id
++;
149 /* See if a conversation for this address/port pair exists. */
150 client_conv
= find_conversation(frame
, &(transport
->source_address
), receiver_address
, CONVERSATION_TCP
, transport
->source_port
, receiver_port
, 0);
151 if (client_conv
== NULL
)
153 client_conv
= conversation_new(frame
, &(transport
->source_address
), receiver_address
, CONVERSATION_TCP
, transport
->source_port
, receiver_port
, 0);
154 session_tree
= wmem_tree_new(wmem_file_scope());
155 conversation_add_proto_data(client_conv
, proto_lbttcp
, (void *) session_tree
);
157 session_tree
= (wmem_tree_t
*) conversation_get_proto_data(client_conv
, proto_lbttcp
);
158 if (session_tree
== NULL
)
160 session_tree
= wmem_tree_new(wmem_file_scope());
161 conversation_add_proto_data(client_conv
, proto_lbttcp
, (void *) session_tree
);
163 wmem_tree_insert32(session_tree
, transport
->session_id
, (void *) entry
);
165 /* Add this client to the transport. */
166 wmem_list_append(transport
->client_list
, (void *) entry
);
170 char * lbttcp_transport_source_string(const address
* source_address
, uint16_t source_port
, uint32_t session_id
)
172 char * bufptr
= NULL
;
176 bufptr
= wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" PRIu16
, address_to_str(wmem_packet_scope(), source_address
), source_port
);
180 bufptr
= wmem_strdup_printf(wmem_file_scope(), "TCP:%s:%" PRIu16
":%08x", address_to_str(wmem_packet_scope(), source_address
), source_port
, session_id
);
185 bool lbttcp_transport_sid_find(const address
* source_address
, uint16_t source_port
, uint32_t frame
, uint32_t * session_id
)
187 conversation_t
* conv
= NULL
;
188 lbttcp_transport_conv_data_t
* conv_data
= NULL
;
189 lbttcp_transport_t
* transport
= NULL
;
191 conv
= find_conversation(frame
, source_address
, &lbttcp_null_address
, CONVERSATION_TCP
, source_port
, 0, 0);
196 conv_data
= (lbttcp_transport_conv_data_t
*) conversation_get_proto_data(conv
, proto_lbttcp
);
197 if (conv_data
== NULL
)
201 if (conv_data
->frame_tree
== NULL
)
205 transport
= (lbttcp_transport_t
*)wmem_tree_lookup32_le(conv_data
->frame_tree
, frame
);
206 if (transport
== NULL
)
210 *session_id
= transport
->session_id
;
214 void lbttcp_transport_sid_add(const address
* source_address
, uint16_t source_port
, uint32_t frame
, uint32_t session_id
)
216 conversation_t
* conv
= NULL
;
217 lbttcp_transport_conv_data_t
* conv_data
= NULL
;
218 lbttcp_transport_t
* transport
= NULL
;
220 conv
= find_conversation(frame
, source_address
, &lbttcp_null_address
, CONVERSATION_TCP
, source_port
, 0, 0);
223 conv
= conversation_new(frame
, source_address
, &lbttcp_null_address
, CONVERSATION_TCP
, source_port
, 0, 0);
225 conv_data
= (lbttcp_transport_conv_data_t
*) conversation_get_proto_data(conv
, proto_lbttcp
);
226 if (conv_data
== NULL
)
228 conv_data
= wmem_new(wmem_file_scope(), lbttcp_transport_conv_data_t
);
229 conv_data
->frame_tree
= wmem_tree_new(wmem_file_scope());
230 conv_data
->session_tree
= wmem_tree_new(wmem_file_scope());
231 conversation_add_proto_data(conv
, proto_lbttcp
, (void *) conv_data
);
233 /* Lookup by frame */
234 transport
= (lbttcp_transport_t
*) wmem_tree_lookup32_le(conv_data
->frame_tree
, frame
);
235 if (transport
!= NULL
)
237 if (transport
->session_id
!= session_id
)
242 if (transport
== NULL
)
244 transport
= lbttcp_transport_create(source_address
, source_port
, session_id
);
245 wmem_tree_insert32(conv_data
->session_tree
, session_id
, (void *) transport
);
246 wmem_tree_insert32(conv_data
->frame_tree
, frame
, (void *) transport
);
250 /*----------------------------------------------------------------------------*/
252 /*----------------------------------------------------------------------------*/
254 /* Preferences default values. */
255 #define LBTTCP_DEFAULT_SOURCE_PORT_LOW 14371
256 #define LBTTCP_DEFAULT_SOURCE_PORT_HIGH 14390
257 #define LBTTCP_DEFAULT_REQUEST_PORT_LOW 14391
258 #define LBTTCP_DEFAULT_REQUEST_PORT_HIGH 14395
259 #define LBTTCP_DEFAULT_STORE_PORT_LOW 0
260 #define LBTTCP_DEFAULT_STORE_PORT_HIGH 0
262 /* Global preferences variables (altered by the preferences dialog). */
263 static uint32_t global_lbttcp_source_port_low
= LBTTCP_DEFAULT_SOURCE_PORT_LOW
;
264 static uint32_t global_lbttcp_source_port_high
= LBTTCP_DEFAULT_SOURCE_PORT_HIGH
;
265 static uint32_t global_lbttcp_request_port_low
= LBTTCP_DEFAULT_REQUEST_PORT_LOW
;
266 static uint32_t global_lbttcp_request_port_high
= LBTTCP_DEFAULT_REQUEST_PORT_HIGH
;
267 static uint32_t global_lbttcp_store_port_low
= LBTTCP_DEFAULT_STORE_PORT_LOW
;
268 static uint32_t global_lbttcp_store_port_high
= LBTTCP_DEFAULT_STORE_PORT_HIGH
;
269 static bool global_lbttcp_use_tag
;
271 /* Local preferences variables (used by the dissector). */
272 static uint32_t lbttcp_source_port_low
= LBTTCP_DEFAULT_SOURCE_PORT_LOW
;
273 static uint32_t lbttcp_source_port_high
= LBTTCP_DEFAULT_SOURCE_PORT_HIGH
;
274 static uint32_t lbttcp_request_port_low
= LBTTCP_DEFAULT_REQUEST_PORT_LOW
;
275 static uint32_t lbttcp_request_port_high
= LBTTCP_DEFAULT_REQUEST_PORT_HIGH
;
276 static uint32_t lbttcp_store_port_low
= LBTTCP_DEFAULT_STORE_PORT_LOW
;
277 static uint32_t lbttcp_store_port_high
= LBTTCP_DEFAULT_STORE_PORT_HIGH
;
278 static bool lbttcp_use_tag
;
280 /* Tag definitions. */
284 uint32_t source_port_low
;
285 uint32_t source_port_high
;
286 uint32_t request_port_low
;
287 uint32_t request_port_high
;
288 uint32_t store_port_low
;
289 uint32_t store_port_high
;
290 } lbttcp_tag_entry_t
;
292 static lbttcp_tag_entry_t
* lbttcp_tag_entry
;
293 static unsigned lbttcp_tag_count
;
295 UAT_CSTRING_CB_DEF(lbttcp_tag
, name
, lbttcp_tag_entry_t
)
296 UAT_DEC_CB_DEF(lbttcp_tag
, source_port_low
, lbttcp_tag_entry_t
)
297 UAT_DEC_CB_DEF(lbttcp_tag
, source_port_high
, lbttcp_tag_entry_t
)
298 UAT_DEC_CB_DEF(lbttcp_tag
, request_port_low
, lbttcp_tag_entry_t
)
299 UAT_DEC_CB_DEF(lbttcp_tag
, request_port_high
, lbttcp_tag_entry_t
)
300 UAT_DEC_CB_DEF(lbttcp_tag
, store_port_low
, lbttcp_tag_entry_t
)
301 UAT_DEC_CB_DEF(lbttcp_tag
, store_port_high
, lbttcp_tag_entry_t
)
302 static uat_field_t lbttcp_tag_array
[] =
304 UAT_FLD_CSTRING(lbttcp_tag
, name
, "Tag name", "Tag name"),
305 UAT_FLD_DEC(lbttcp_tag
, source_port_low
, "Source port low", "Source port low"),
306 UAT_FLD_DEC(lbttcp_tag
, source_port_high
, "Source port high", "Source port high"),
307 UAT_FLD_DEC(lbttcp_tag
, request_port_low
, "Request port low", "Request port low"),
308 UAT_FLD_DEC(lbttcp_tag
, request_port_high
, "Request port high", "Request port high"),
309 UAT_FLD_DEC(lbttcp_tag
, store_port_low
, "Store port low", "Store port low"),
310 UAT_FLD_DEC(lbttcp_tag
, store_port_high
, "Store port high", "Store port high"),
314 /*----------------------------------------------------------------------------*/
315 /* UAT callback functions. */
316 /*----------------------------------------------------------------------------*/
317 static bool lbttcp_tag_update_cb(void * record
, char * * error_string
)
319 lbttcp_tag_entry_t
* tag
= (lbttcp_tag_entry_t
*)record
;
321 if (tag
->name
== NULL
)
323 *error_string
= g_strdup("Tag name can't be empty");
328 g_strstrip(tag
->name
);
329 if (tag
->name
[0] == 0)
331 *error_string
= g_strdup("Tag name can't be empty");
338 static void * lbttcp_tag_copy_cb(void * destination
, const void * source
, size_t length _U_
)
340 const lbttcp_tag_entry_t
* src
= (const lbttcp_tag_entry_t
*)source
;
341 lbttcp_tag_entry_t
* dest
= (lbttcp_tag_entry_t
*)destination
;
343 dest
->name
= g_strdup(src
->name
);
344 dest
->source_port_low
= src
->source_port_low
;
345 dest
->source_port_high
= src
->source_port_high
;
346 dest
->request_port_low
= src
->request_port_low
;
347 dest
->request_port_high
= src
->request_port_high
;
348 dest
->store_port_low
= src
->store_port_low
;
349 dest
->store_port_high
= src
->store_port_high
;
353 static void lbttcp_tag_free_cb(void * record
)
355 lbttcp_tag_entry_t
* tag
= (lbttcp_tag_entry_t
*)record
;
357 if (tag
->name
!= NULL
)
364 static const lbttcp_tag_entry_t
* lbttcp_tag_locate(packet_info
* pinfo
)
367 const lbttcp_tag_entry_t
* tag
= NULL
;
374 for (idx
= 0; idx
< lbttcp_tag_count
; ++idx
)
376 tag
= &(lbttcp_tag_entry
[idx
]);
377 if (((pinfo
->srcport
>= tag
->source_port_low
) && (pinfo
->srcport
<= tag
->source_port_high
))
378 || ((pinfo
->destport
>= tag
->source_port_low
) && (pinfo
->destport
<= tag
->source_port_high
))
379 || ((pinfo
->srcport
>= tag
->request_port_low
) && (pinfo
->srcport
<= tag
->request_port_high
))
380 || ((pinfo
->destport
>= tag
->request_port_low
) && (pinfo
->destport
<= tag
->request_port_high
))
381 || ((pinfo
->srcport
>= tag
->store_port_low
) && (pinfo
->srcport
<= tag
->store_port_high
))
382 || ((pinfo
->destport
>= tag
->store_port_low
) && (pinfo
->destport
<= tag
->store_port_high
)))
390 static char * lbttcp_tag_find(packet_info
* pinfo
)
392 const lbttcp_tag_entry_t
* tag
= NULL
;
399 tag
= lbttcp_tag_locate(pinfo
);
407 /*----------------------------------------------------------------------------*/
408 /* Handles of all types. */
409 /*----------------------------------------------------------------------------*/
411 /* Dissector tree handles */
412 static int ett_lbttcp
;
413 static int ett_lbttcp_channel
;
415 /* Dissector field handles */
416 static int hf_lbttcp_tag
;
417 static int hf_lbttcp_channel
;
418 static int hf_lbttcp_channel_id
;
419 static int hf_lbttcp_channel_client
;
421 static bool lbttcp_packet_is_transport_source(packet_info
* pinfo
, const lbttcp_tag_entry_t
* tag
)
423 bool is_transport_source_packet
= false;
427 if ((pinfo
->srcport
>= lbttcp_source_port_low
) && (pinfo
->srcport
<= lbttcp_source_port_high
))
429 is_transport_source_packet
= true;
434 if ((pinfo
->srcport
>= tag
->source_port_low
) && (pinfo
->srcport
<= tag
->source_port_high
))
436 is_transport_source_packet
= true;
439 return (is_transport_source_packet
);
442 static bool lbttcp_packet_is_transport_client(packet_info
* pinfo
, const lbttcp_tag_entry_t
* tag
)
444 bool is_transport_client_packet
= false;
448 if ((pinfo
->destport
>= lbttcp_source_port_low
) && (pinfo
->destport
<= lbttcp_source_port_high
))
450 is_transport_client_packet
= true;
455 if ((pinfo
->destport
>= tag
->source_port_low
) && (pinfo
->destport
<= tag
->source_port_high
))
457 is_transport_client_packet
= true;
460 return (is_transport_client_packet
);
463 static unsigned get_lbttcp_pdu_length(packet_info
* pinfo _U_
, tvbuff_t
* tvb
,
464 int offset
, void *data _U_
)
466 return lbmc_get_message_length(tvb
, offset
);
469 static int dissect_lbttcp_pdu(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void * dissector_data _U_
)
471 proto_tree
* lbttcp_tree
= NULL
;
472 proto_item
* ti
= NULL
;
473 char * tag_name
= NULL
;
475 const lbttcp_tag_entry_t
* tag
= NULL
;
476 uint64_t channel
= LBM_CHANNEL_NO_CHANNEL
;
477 uint32_t client_id
= 0;
478 bool from_source
= false;
479 bool transport_packet
= false;
483 tag
= lbttcp_tag_locate(pinfo
);
484 tag_name
= lbttcp_tag_find(pinfo
);
486 if (tag_name
!= NULL
)
488 ti
= proto_tree_add_protocol_format(tree
, proto_lbttcp
, tvb
, 0, -1, "LBT-TCP Protocol (Tag: %s)", tag_name
);
492 ti
= proto_tree_add_protocol_format(tree
, proto_lbttcp
, tvb
, 0, -1, "LBT-TCP Protocol");
494 lbttcp_tree
= proto_item_add_subtree(ti
, ett_lbttcp
);
495 if (tag_name
!= NULL
)
497 proto_item
* item
= NULL
;
499 item
= proto_tree_add_string(lbttcp_tree
, hf_lbttcp_tag
, tvb
, 0, 0, tag_name
);
500 proto_item_set_generated(item
);
502 if (lbttcp_packet_is_transport_source(pinfo
, tag
))
505 transport_packet
= true;
507 else if (lbttcp_packet_is_transport_client(pinfo
, tag
))
510 transport_packet
= true;
512 if (transport_packet
)
514 address source_address
;
515 address client_address
;
519 lbttcp_transport_t
* transport
= NULL
;
520 lbttcp_client_transport_t
* client
= NULL
;
524 copy_address_shallow(&source_address
, &(pinfo
->src
));
525 srcport
= pinfo
->srcport
;
526 copy_address_shallow(&client_address
, &(pinfo
->dst
));
527 clntport
= pinfo
->destport
;
531 copy_address_shallow(&source_address
, &(pinfo
->dst
));
532 srcport
= pinfo
->destport
;
533 copy_address_shallow(&client_address
, &(pinfo
->src
));
534 clntport
= pinfo
->srcport
;
536 /* See if we have a matching transport with no session ID. */
537 transport
= lbttcp_transport_find(&source_address
, srcport
, sid
, pinfo
->num
);
538 if (transport
== NULL
)
540 /* See if we know about a SID */
541 if (lbttcp_transport_sid_find(&source_address
, srcport
, pinfo
->num
, &sid
))
543 transport
= lbttcp_transport_find(&source_address
, srcport
, sid
, pinfo
->num
);
546 if (transport
!= NULL
)
548 channel
= transport
->channel
;
549 /* See if we already know about this client */
550 client
= lbttcp_client_transport_find(transport
, &client_address
, clntport
, pinfo
->num
);
554 client
= lbttcp_client_transport_add(transport
, &client_address
, clntport
, pinfo
->num
);
558 client_id
= client
->id
;
563 if (PINFO_FD_VISITED(pinfo
))
565 /* No TIR and no session ID seen, so create the transport */
566 transport
= lbttcp_transport_add(&source_address
, srcport
, 0, pinfo
->num
);
567 if (transport
!= NULL
)
569 channel
= transport
->channel
;
570 client
= lbttcp_client_transport_add(transport
, &client_address
, clntport
, pinfo
->num
);
573 client_id
= client
->id
;
579 /* Defer determining the channel. */
582 channel
= lbm_channel_assign_unknown_transport_source_lbttcp();
586 channel
= lbm_channel_assign_unknown_transport_client_lbttcp();
593 channel
= lbm_channel_assign_unknown_stream_tcp();
595 if (lbm_channel_is_known(channel
))
597 proto_item
* channel_item
= NULL
;
598 proto_tree
* channel_tree
= NULL
;
600 channel_item
= proto_tree_add_item(lbttcp_tree
, hf_lbttcp_channel
, tvb
, 0, 0, ENC_NA
);
601 proto_item_set_generated(channel_item
);
602 channel_tree
= proto_item_add_subtree(channel_item
, ett_lbttcp_channel
);
603 channel_item
= proto_tree_add_uint64(channel_tree
, hf_lbttcp_channel_id
, tvb
, 0, 0, channel
);
604 proto_item_set_generated(channel_item
);
605 channel_item
= proto_tree_add_uint(channel_tree
, hf_lbttcp_channel_client
, tvb
, 0, 0, client_id
);
606 proto_item_set_generated(channel_item
);
608 len_dissected
= lbmc_dissect_lbmc_packet(tvb
, 0, pinfo
, tree
, tag_name
, channel
);
609 return (len_dissected
);
613 * dissect_lbttcp_real - The "common" dissection for LBT-TCP
615 static int dissect_lbttcp_real(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void * data _U_
)
617 char * tag_name
= NULL
;
619 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "LBT-TCP");
620 col_clear(pinfo
->cinfo
, COL_INFO
);
623 tag_name
= lbttcp_tag_find(pinfo
);
625 if (tag_name
!= NULL
)
627 col_add_fstr(pinfo
->cinfo
, COL_INFO
, "[Tag: %s]", tag_name
);
629 col_set_fence(pinfo
->cinfo
, COL_INFO
);
630 tcp_dissect_pdus(tvb
, pinfo
, tree
, true, lbmc_get_minimum_length(), /* Need at least the msglen */
631 get_lbttcp_pdu_length
, dissect_lbttcp_pdu
, NULL
);
633 return tvb_captured_length(tvb
);
637 * dissect_lbttcp - The dissector for LBT-TCP
639 static int dissect_lbttcp(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void * data
)
641 if (!lbmc_test_lbmc_header(tvb
, 0))
644 return dissect_lbttcp_real(tvb
, pinfo
, tree
, data
);
647 static bool test_lbttcp_packet(tvbuff_t
* tvb
, packet_info
* pinfo
, proto_tree
* tree
, void * data
)
649 /* Destination address must be IPV4 and 4 bytes in length. */
650 if ((pinfo
->dst
.type
!= AT_IPv4
) || (pinfo
->dst
.len
!= 4))
657 if (lbttcp_tag_find(pinfo
) != NULL
)
659 dissect_lbttcp_real(tvb
, pinfo
, tree
, data
);
669 Source port or destination port must be in the source port range, or destination port must be in
670 the request port range, or either port in the UME store port range.
672 if (!(((pinfo
->srcport
>= lbttcp_source_port_low
) && (pinfo
->srcport
<= lbttcp_source_port_high
))
673 || ((pinfo
->destport
>= lbttcp_source_port_low
) && (pinfo
->destport
<= lbttcp_source_port_high
))
674 || ((pinfo
->srcport
>= lbttcp_request_port_low
) && (pinfo
->srcport
<= lbttcp_request_port_high
))
675 || ((pinfo
->destport
>= lbttcp_request_port_low
) && (pinfo
->destport
<= lbttcp_request_port_high
))
676 || ((pinfo
->srcport
>= lbttcp_store_port_low
) && (pinfo
->srcport
<= lbttcp_store_port_high
))
677 || ((pinfo
->destport
>= lbttcp_store_port_low
) && (pinfo
->destport
<= lbttcp_store_port_high
))))
682 if (!lbmc_test_lbmc_header(tvb
, 0))
685 /* One of ours. Probably. */
686 dissect_lbttcp_real(tvb
, pinfo
, tree
, data
);
690 /* Register all the bits needed with the filtering engine */
691 void proto_register_lbttcp(void)
693 static hf_register_info hf
[] =
696 { "Tag", "lbttcp.tag", FT_STRING
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} },
697 { &hf_lbttcp_channel
,
698 { "Channel", "lbttcp.channel", FT_NONE
, BASE_NONE
, NULL
, 0x0, NULL
, HFILL
} },
699 { &hf_lbttcp_channel_id
,
700 { "Channel ID", "lbttcp.channel.channel", FT_UINT64
, BASE_HEX_DEC
, NULL
, 0x0, NULL
, HFILL
} },
701 { &hf_lbttcp_channel_client
,
702 { "Channel Client", "lbttcp.channel.client", FT_UINT32
, BASE_DEC
, NULL
, 0x0, NULL
, HFILL
} },
709 module_t
* lbttcp_module
;
712 proto_lbttcp
= proto_register_protocol("LBT TCP Protocol", "LBT-TCP", "lbttcp");
714 proto_register_field_array(proto_lbttcp
, hf
, array_length(hf
));
715 proto_register_subtree_array(ett
, array_length(ett
));
717 lbttcp_dissector_handle
= register_dissector("lbttcp", dissect_lbttcp
, proto_lbttcp
);
719 lbttcp_module
= prefs_register_protocol_subtree("29West", proto_lbttcp
, proto_reg_handoff_lbttcp
);
720 prefs_register_uint_preference(lbttcp_module
,
722 "Source port range low (default " MAKESTRING(LBTTCP_DEFAULT_SOURCE_PORT_LOW
)")",
723 "Set the low end of the LBT-TCP source TCP port range (context transport_tcp_port_low)",
725 &global_lbttcp_source_port_low
);
727 prefs_register_uint_preference(lbttcp_module
,
729 "Source port range high (default " MAKESTRING(LBTTCP_DEFAULT_SOURCE_PORT_HIGH
)")",
730 "Set the high end of the LBT-TCP source TCP port range (context transport_tcp_port_high)",
732 &global_lbttcp_source_port_high
);
734 prefs_register_uint_preference(lbttcp_module
,
736 "Request port range low (default " MAKESTRING(LBTTCP_DEFAULT_REQUEST_PORT_LOW
)")",
737 "Set the low end of the LBT-TCP request TCP port range (context request_tcp_port_low)",
739 &global_lbttcp_request_port_low
);
741 prefs_register_uint_preference(lbttcp_module
,
743 "Request port range high (default " MAKESTRING(LBTTCP_DEFAULT_REQUEST_PORT_HIGH
)")",
744 "Set the high end of the LBT-TCP request TCP port range (context request_tcp_port_high)",
746 &global_lbttcp_request_port_high
);
748 prefs_register_uint_preference(lbttcp_module
,
750 "UME Store port range low (default " MAKESTRING(LBTTCP_DEFAULT_STORE_PORT_LOW
)")",
751 "Set the low end of the LBT-TCP UME Store TCP port range",
753 &global_lbttcp_store_port_low
);
755 prefs_register_uint_preference(lbttcp_module
,
757 "UME Store port range high (default " MAKESTRING(LBTTCP_DEFAULT_STORE_PORT_HIGH
)")",
758 "Set the high end of the LBT-TCP UME Store TCP port range",
760 &global_lbttcp_store_port_high
);
762 prefs_register_bool_preference(lbttcp_module
,
764 "Use LBT-TCP tag table",
765 "Use table of LBT-TCP tags to decode the packet instead of above values",
766 &global_lbttcp_use_tag
);
767 tag_uat
= uat_new("LBT-TCP tag definitions",
768 sizeof(lbttcp_tag_entry_t
),
771 (void * *)&lbttcp_tag_entry
,
773 UAT_AFFECTS_DISSECTION
,
776 lbttcp_tag_update_cb
,
781 prefs_register_uat_preference(lbttcp_module
,
784 "A table to define LBT-TCP tags",
788 /* The registration hand-off routine */
789 void proto_reg_handoff_lbttcp(void)
791 static bool already_registered
= false;
793 if (!already_registered
)
795 dissector_add_for_decode_as_with_preference("tcp.port", lbttcp_dissector_handle
);
796 heur_dissector_add("tcp", test_lbttcp_packet
, "LBT over TCP", "lbttcp_tcp", proto_lbttcp
, HEURISTIC_ENABLE
);
799 /* Make sure the source port low is <= the source port high. If not, don't change them. */
800 if (global_lbttcp_source_port_low
<= global_lbttcp_source_port_high
)
802 lbttcp_source_port_low
= global_lbttcp_source_port_low
;
803 lbttcp_source_port_high
= global_lbttcp_source_port_high
;
806 /* Make sure the request port low is <= the request port high. If not, don't change them. */
807 if (global_lbttcp_request_port_low
<= global_lbttcp_request_port_high
)
809 lbttcp_request_port_low
= global_lbttcp_request_port_low
;
810 lbttcp_request_port_high
= global_lbttcp_request_port_high
;
813 /* Make sure the store port low is <= the store port high. If not, don't change them. */
814 if (global_lbttcp_store_port_low
<= global_lbttcp_store_port_high
)
816 lbttcp_store_port_low
= global_lbttcp_store_port_low
;
817 lbttcp_store_port_high
= global_lbttcp_store_port_high
;
820 lbttcp_use_tag
= global_lbttcp_use_tag
;
822 already_registered
= true;
826 * Editor modelines - https://www.wireshark.org/tools/modelines.html
831 * indent-tabs-mode: nil
834 * vi: set shiftwidth=4 tabstop=8 expandtab:
835 * :indentSize=4:tabSize=8:noTabs=true: