aboutsummaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-lapd.c
diff options
context:
space:
mode:
authorGuy Harris <gharris@sonic.net>2020-07-25 02:20:10 -0700
committerGuy Harris <gharris@sonic.net>2020-07-25 18:31:34 +0000
commit75c739e4b71f1fb6d907b8d5ceb31db50dbd1fc7 (patch)
treec42c2d08471c75cecbb7a85251d7f9ef7ea6f050 /epan/dissectors/packet-lapd.c
parentac2883f5e8e0a461ba06733294738358eb527b8c (diff)
ISDN, LAPD: clean up the way they connect to other dissectors.
Have the ISDN dissector take the ISDN pseudo-header through its data argument, rather than assuming it's in pinfo->pseudo_header, so it can be used if the link-layer type of the capture isn't ISDN. Have it add the direction to its protocol tree, so it's there for all ISDN packets. Have more versions of the LAPD dissector: one where the ISDN direction information is available through an ISDN pseudo-header passed as its data argument; one for use when the link-layer type *is* LAPD, where the ISDN direction information may be available through the direction part of the packet flags. Pass more flags to the routine that does LAPD dissection to indicate the direction (user->network or network->user) and whether the user or network side is on another machine; set those appropriately in the dissector routines that call it. To set those flags: in the routine that handles WTAP_ENCAP_LAPD, check the direction flags in pinfo->rec->rec_header.packet_header.pack_flags; in the routine that handles WTAP_ENCAP_LINUX_LAPD, check the SLL header; in the routine that's called from the ISDN dissector and other dissectors that can supply an ISDN pseudo-header, check the struct isdn_phdr passed to it via the data argument; for the routine that's to be called from L2TP pseudowire type and SCTP dissector tables, pass nothing, as there's currently no direction indication supplied - if that information is available from the encapsulating protocol in some fashion, we should make changes to supply that information. Have the AudioCodes Trunk trace protocol dissector call the LAPD-with-pseudoheader dissector, handing it an ISDN pseudo-header with a direction indication from the direction field (and a channel of 0 to indicate the D channel). Have the Ascend text dump reader in libwiretap use WTAP_ENCAP_ASCEND for all packets, even Ethernet and ISDN packets, and have the Ascend text dump dissector handle that, calling the "no FCS" version of the Ethernet dissector and calling the LAPD-with-pseudoheader dissector with a pseudo-header filled in with the direction (and a channel of 0). Have the Catapult DCT 2000 text dump dissector call the LAPD-with-pseudoheader dissector with the pseudo-header supplied by libwireshark. Have the V5 envelope function frame get its ISDN pseudo-header from its data argument, and call the LAPD-with-pseudoheader dissector with that pseudo-header. Have the ISDN dissector treat its data argument as pointing to the ISDN pseudo-header, rather than assuming it's the one in pinfo->pseudo_header->isdn - the latter is the one supplied by libwiretap, but there's no guarantee that an ISDN pseudo-header was supplied by libwiretap, as the lowest-level protocol layer might not have been ISDN. Change-Id: I9f702b879bbc3fb42bcb43c28f797bfc327562c6 Reviewed-on: https://code.wireshark.org/review/37953 Petri-Dish: Guy Harris <gharris@sonic.net> Tested-by: Petri Dish Buildbot Reviewed-by: Guy Harris <gharris@sonic.net>
Diffstat (limited to 'epan/dissectors/packet-lapd.c')
-rw-r--r--epan/dissectors/packet-lapd.c197
1 files changed, 139 insertions, 58 deletions
diff --git a/epan/dissectors/packet-lapd.c b/epan/dissectors/packet-lapd.c
index 414de55e97..413e9296c4 100644
--- a/epan/dissectors/packet-lapd.c
+++ b/epan/dissectors/packet-lapd.c
@@ -76,6 +76,7 @@ static expert_field ei_lapd_abort = EI_INIT;
static expert_field ei_lapd_checksum_bad = EI_INIT;
static dissector_handle_t lapd_handle;
+static dissector_handle_t lapd_phdr_handle;
static dissector_handle_t linux_lapd_handle;
static dissector_handle_t lapd_bitstream_handle;
@@ -96,10 +97,13 @@ static gboolean global_lapd_gsm_sapis = FALSE;
#define LAPD_TEI_SHIFT 1
#define LAPD_EA2 0x0001 /* Second Address Extension bit */
+#define LAPD_DIR_USER_TO_NETWORK 0
+#define LAPD_DIR_NETWORK_TO_USER 1
+
static const value_string lapd_direction_vals[] = {
- { P2P_DIR_RECV, "Network->User"},
- { P2P_DIR_SENT, "User->Network"},
- { 0, NULL }
+ { LAPD_DIR_USER_TO_NETWORK, "User->Network"},
+ { LAPD_DIR_NETWORK_TO_USER, "Network->User"},
+ { 0, NULL }
};
static const value_string lapd_sapi_vals[] = {
@@ -212,8 +216,12 @@ lapd_log_abort(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint offset
/*
* Flags to pass to dissect_lapd_full.
*/
-#define LAPD_HAS_CRC 0x00000001
-#define LAPD_HAS_LINUX_SLL 0x00000002
+#define LAPD_HAS_CRC 0x00000001
+#define LAPD_HAS_DIRECTION 0x00000002
+#define LAPD_HAS_LINUX_SLL 0x00000004
+#define LAPD_USER_TO_NETWORK 0x00000008
+#define LAPD_NETWORK_IS_REMOTE 0x00000010
+#define LAPD_USER_IS_REMOTE 0x00000020
static int
dissect_lapd_bitstream(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* dissector_data _U_)
@@ -403,13 +411,107 @@ dissect_lapd_bitstream(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void
static int
dissect_linux_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
- dissect_lapd_full(tvb, pinfo, tree, LAPD_HAS_LINUX_SLL);
+ guint32 flags = LAPD_HAS_LINUX_SLL | LAPD_HAS_DIRECTION;
+
+ /* frame is captured via libpcap */
+ if (pinfo->pseudo_header->lapd.pkttype == 4 /*PACKET_OUTGOING*/) {
+ if (pinfo->pseudo_header->lapd.we_network) {
+ /*
+ * We're the network side, so the user is remote,
+ * and we're sending it, so this is Network->User.
+ */
+ flags |= LAPD_USER_IS_REMOTE;
+ } else {
+ /*
+ * We're the user side, so the network is remote,
+ * and we're sending it, so this is User->Network.
+ */
+ flags |= LAPD_NETWORK_IS_REMOTE | LAPD_USER_TO_NETWORK;
+ }
+ }
+ else if (pinfo->pseudo_header->lapd.pkttype == 3 /*PACKET_OTHERHOST*/) {
+ /*
+ * We must be a TE, sniffing what other TE transmit, so
+ * both sides are remote.
+ *
+ * XXX - do we know whether it's User->Network or
+ * Network->User?
+ */
+ flags |= LAPD_USER_IS_REMOTE | LAPD_NETWORK_IS_REMOTE | LAPD_USER_TO_NETWORK;
+ }
+ else {
+ /* The frame is incoming */
+ if (pinfo->pseudo_header->lapd.we_network) {
+ /*
+ * We're the network side, so the user is remote,
+ * and we received it, so this is User->Network.
+ */
+ flags |= LAPD_USER_IS_REMOTE | LAPD_USER_TO_NETWORK;
+ } else {
+ /*
+ * We're the user side, so the network is remote,
+ * and we received it, so this is Network->User.
+ */
+ flags |= LAPD_NETWORK_IS_REMOTE;
+ }
+ }
+ dissect_lapd_full(tvb, pinfo, tree, flags);
+ return tvb_captured_length(tvb);
+}
+
+/*
+ * Called from dissectors, such as the ISDN dissector, that supply a
+ * struct isdn_pndr giving the packet direction.
+ */
+static int
+dissect_lapd_phdr(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+ struct isdn_phdr *isdn = (struct isdn_phdr *)data;
+ guint32 flags = LAPD_HAS_DIRECTION;
+
+ if (isdn->uton)
+ flags |= LAPD_USER_TO_NETWORK;
+ dissect_lapd_full(tvb, pinfo, tree, flags);
+ return tvb_captured_length(tvb);
+}
+
+/*
+ * Called for link-layer encapsulation.
+ */
+static int
+dissect_lapd_frame(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
+{
+ guint32 flags = 0;
+
+ /*
+ * If we have direction flags, we have a direction;
+ * "outbound" packets are presumed to be User->Network and
+ * "inbound" packets are presumed to be Network->User.
+ * Other packets, we have no idea.
+ */
+ if (pinfo->rec->presence_flags & WTAP_HAS_PACK_FLAGS) {
+ switch (PACK_FLAGS_DIRECTION(pinfo->rec->rec_header.packet_header.pack_flags)) {
+
+ case PACK_FLAGS_DIRECTION_OUTBOUND:
+ flags |= LAPD_HAS_DIRECTION | LAPD_USER_TO_NETWORK;
+ break;
+
+ case PACK_FLAGS_DIRECTION_INBOUND:
+ flags |= LAPD_HAS_DIRECTION;
+ break;
+
+ default:
+ break;
+ }
+ }
+ dissect_lapd_full(tvb, pinfo, tree, flags);
return tvb_captured_length(tvb);
}
static int
-dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
+dissect_lapd(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
{
+ /* XXX - direction is unknown */
dissect_lapd_full(tvb, pinfo, tree, 0);
return tvb_captured_length(tvb);
}
@@ -419,7 +521,6 @@ dissect_lapd_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 f
{
proto_tree *lapd_tree, *addr_tree;
proto_item *lapd_ti, *addr_ti;
- int direction;
guint16 control;
int lapd_header_len, checksum_offset;
guint16 addr, cr, sapi, tei;
@@ -443,56 +544,31 @@ dissect_lapd_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 f
col_append_fstr(pinfo->cinfo, COL_INFO, "TEI:%02u ", tei);
col_set_fence(pinfo->cinfo, COL_INFO);
- if (flags & LAPD_HAS_LINUX_SLL) {
- /* frame is captured via libpcap */
- if (pinfo->pseudo_header->lapd.pkttype == 4 /*PACKET_OUTGOING*/) {
- if (pinfo->pseudo_header->lapd.we_network) {
- is_response = cr ? FALSE : TRUE;
- srcname = "Local Network";
- dstname = "Remote User";
- direction = P2P_DIR_RECV; /* Network->User */
- } else {
- srcname = "Local User";
- dstname = "Remote Network";
- direction = P2P_DIR_SENT; /* User->Network */
- }
- }
- else if (pinfo->pseudo_header->lapd.pkttype == 3 /*PACKET_OTHERHOST*/) {
- /* We must be a TE, sniffing what other TE transmit */
-
+ if (flags & LAPD_HAS_DIRECTION) {
+ if (flags & LAPD_USER_TO_NETWORK) {
is_response = cr ? TRUE : FALSE;
- srcname = "Remote User";
- dstname = "Remote Network";
- direction = P2P_DIR_SENT; /* User->Network */
- }
- else {
- /* The frame is incoming */
- if (pinfo->pseudo_header->lapd.we_network) {
- is_response = cr ? TRUE : FALSE;
- srcname = "Remote User";
- dstname = "Local Network";
- direction = P2P_DIR_SENT; /* User->Network */
+ if (flags & LAPD_HAS_LINUX_SLL) {
+ srcname = (flags & LAPD_USER_IS_REMOTE) ?
+ "Remote User" : "Local User";
+ dstname = (flags & LAPD_NETWORK_IS_REMOTE) ?
+ "Remote Network" : "Local Network";
} else {
- is_response = cr ? FALSE : TRUE;
- srcname = "Remote Network";
- dstname = "Local User";
- direction = P2P_DIR_RECV; /* Network->User */
+ srcname = "User";
+ dstname = "Network";
}
- }
- } else {
- direction = pinfo->p2p_dir;
- if (pinfo->p2p_dir == P2P_DIR_RECV) {
+ } else {
is_response = cr ? FALSE : TRUE;
- srcname = "Network";
- dstname = "User";
- }
- else if (pinfo->p2p_dir == P2P_DIR_SENT) {
- is_response = cr ? TRUE : FALSE;
- srcname = "User";
- dstname = "Network";
+ if (flags & LAPD_HAS_LINUX_SLL) {
+ srcname = (flags & LAPD_NETWORK_IS_REMOTE) ?
+ "Remote Network" : "Local Network";
+ dstname = (flags & LAPD_USER_IS_REMOTE) ?
+ "Remote User" : "Local User";
+ } else {
+ srcname = "Network";
+ dstname = "User";
+ }
}
}
-
col_set_str(pinfo->cinfo, COL_RES_DL_SRC, srcname);
col_set_str(pinfo->cinfo, COL_RES_DL_DST, dstname);
@@ -506,9 +582,10 @@ dissect_lapd_full(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, guint32 f
/*
* Don't show the direction if we don't know it.
*/
- if (direction != P2P_DIR_UNKNOWN) {
+ if (flags & LAPD_HAS_DIRECTION) {
direction_ti = proto_tree_add_uint(lapd_tree, hf_lapd_direction,
- tvb, 0, 0, pinfo->p2p_dir);
+ tvb, 0, 0,
+ (flags & LAPD_USER_TO_NETWORK) ? LAPD_DIR_USER_TO_NETWORK : LAPD_DIR_NETWORK_TO_USER);
proto_item_set_generated(direction_ti);
}
@@ -577,7 +654,7 @@ proto_register_lapd(void)
static hf_register_info hf[] = {
{ &hf_lapd_direction,
- { "Direction", "lapd.direction", FT_UINT8, BASE_DEC, VALS(lapd_direction_vals), 0x0,
+ { "Direction", "lapd.direction", FT_UINT32, BASE_DEC, VALS(lapd_direction_vals), 0x0,
NULL, HFILL }},
{ &hf_lapd_address,
@@ -690,7 +767,8 @@ proto_register_lapd(void)
expert_lapd = expert_register_protocol(proto_lapd);
expert_register_field_array(expert_lapd, ei, array_length(ei));
- lapd_handle = register_dissector("lapd", dissect_lapd, proto_lapd);
+ lapd_handle = create_dissector_handle(dissect_lapd, proto_lapd);
+ lapd_phdr_handle = register_dissector("lapd-phdr", dissect_lapd_phdr, proto_lapd);
linux_lapd_handle = register_dissector("linux-lapd", dissect_linux_lapd, proto_lapd);
lapd_bitstream_handle = register_dissector("lapd-bitstream", dissect_lapd_bitstream, proto_lapd);
@@ -724,12 +802,15 @@ proto_reg_handoff_lapd(void)
static gboolean init = FALSE;
static range_t* lapd_rtp_payload_type_range = NULL;
static guint lapd_sctp_ppi;
+ dissector_handle_t lapd_frame_handle;
if (!init) {
dissector_add_uint("wtap_encap", WTAP_ENCAP_LINUX_LAPD, linux_lapd_handle);
- dissector_add_uint("wtap_encap", WTAP_ENCAP_LAPD, lapd_handle);
- dissector_add_uint("l2tp.pw_type", L2TPv3_PROTOCOL_LAPD, lapd_handle);
+ lapd_frame_handle = create_dissector_handle(dissect_lapd_frame, proto_lapd);
+ dissector_add_uint("wtap_encap", WTAP_ENCAP_LAPD, lapd_frame_handle);
+
+ dissector_add_uint("l2tp.pw_type", L2TPv3_PROTOCOL_LAPD, lapd_handle);
dissector_add_for_decode_as("sctp.ppi", lapd_handle);
dissector_add_for_decode_as("sctp.port", lapd_handle);
dissector_add_uint_range_with_preference("udp.port", "", lapd_handle);