diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-10 20:34:10 +0000 |
commit | e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc (patch) | |
tree | 68cb5ef9081156392f1dd62a00c6ccc1451b93df /epan/dissectors/packet-mpls-mac.c | |
parent | Initial commit. (diff) | |
download | wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.tar.xz wireshark-e4ba6dbc3f1e76890b22773807ea37fe8fa2b1bc.zip |
Adding upstream version 4.2.2.upstream/4.2.2
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'epan/dissectors/packet-mpls-mac.c')
-rw-r--r-- | epan/dissectors/packet-mpls-mac.c | 246 |
1 files changed, 246 insertions, 0 deletions
diff --git a/epan/dissectors/packet-mpls-mac.c b/epan/dissectors/packet-mpls-mac.c new file mode 100644 index 00000000..7bb27724 --- /dev/null +++ b/epan/dissectors/packet-mpls-mac.c @@ -0,0 +1,246 @@ +/* packet-mpls-mac.c + * + * Routines for MPLS Media Access Control (MAC) Address Withdrawal over Static Pseudowire. + * + * 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-mpls.h" + +void proto_register_mpls_mac(void); +void proto_reg_handoff_mpls_mac(void); + +static dissector_handle_t mpls_mac_handle; + +static gint proto_mpls_mac = -1; + +static gint ett_mpls_mac = -1; +static gint ett_mpls_mac_flags = -1; +static gint ett_mpls_mac_tlv = -1; + +static int hf_mpls_mac_reserved = -1; +static int hf_mpls_mac_tlv_length_total = -1; +static int hf_mpls_mac_flags = -1; +static int hf_mpls_mac_flags_a = -1; +static int hf_mpls_mac_flags_r = -1; +static int hf_mpls_mac_flags_reserved = -1; +static int hf_mpls_mac_tlv = -1; +static int hf_mpls_mac_tlv_res = -1; +static int hf_mpls_mac_tlv_type = -1; +static int hf_mpls_mac_tlv_length = -1; +static int hf_mpls_mac_tlv_value = -1; +static int hf_mpls_mac_tlv_sequence_number = -1; + + +static int * const mpls_mac_flags[] = { + &hf_mpls_mac_flags_a, + &hf_mpls_mac_flags_r, + &hf_mpls_mac_flags_reserved, + NULL +}; + +static int +dissect_mpls_mac(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_) +{ + proto_item *ti; + proto_tree *mac_tree; + guint32 offset = 0, tlv_length, offset_end; + + col_set_str(pinfo->cinfo, COL_PROTOCOL, "MPLS-MAC"); + col_clear(pinfo->cinfo, COL_INFO); + + ti = proto_tree_add_item(tree, proto_mpls_mac, tvb, 0, -1, ENC_NA); + mac_tree = proto_item_add_subtree(ti, ett_mpls_mac); + /* Reserved */ + proto_tree_add_item(mac_tree, hf_mpls_mac_reserved, tvb, offset, 2, ENC_NA); + offset += 2; + /* TLV length */ + proto_tree_add_item_ret_uint(mac_tree, hf_mpls_mac_tlv_length_total, tvb, offset, 1, ENC_BIG_ENDIAN, &tlv_length); + offset += 1; + /* Flags */ + proto_tree_add_bitmask(mac_tree, tvb, offset, hf_mpls_mac_flags, + ett_mpls_mac_flags, + mpls_mac_flags, + ENC_BIG_ENDIAN); + offset += 1; + offset_end = offset + tlv_length; + + while(offset < offset_end){ + guint32 type, length; + proto_tree *tlv_tree; + + ti = proto_tree_add_item(mac_tree, hf_mpls_mac_tlv, tvb, offset, 4, ENC_NA); + + tlv_tree = proto_item_add_subtree(ti, ett_mpls_mac_tlv); + /* res(erved) */ + proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_res, tvb, offset, 2, ENC_BIG_ENDIAN); + + /* TLV Type */ + proto_tree_add_item_ret_uint(tlv_tree, hf_mpls_mac_tlv_type, tvb, offset, 2, ENC_BIG_ENDIAN, &type); + offset += 2; + + /* TLV Length */ + proto_tree_add_item_ret_uint(tlv_tree, hf_mpls_mac_tlv_length, tvb, offset, 2, ENC_BIG_ENDIAN, &length); + offset += 2; + proto_item_set_len(ti, 2+2+length); + proto_item_append_text(ti, " (t=0x%x, l=%u)", type, length); + + /* TLV Value */ + proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_value, tvb, offset, length, ENC_NA); + + switch(type){ + case 0x0001: + proto_tree_add_item(tlv_tree, hf_mpls_mac_tlv_sequence_number, tvb, offset, 4, ENC_BIG_ENDIAN); + offset += 4; + break; + default: + offset += length; + break; + } + + } + return offset; +} + +void +proto_register_mpls_mac(void) +{ + static hf_register_info hf[] = { + { + &hf_mpls_mac_reserved, + { + "Reserved", "mpls_mac.reserved", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv_length_total, + { + "TLV Length (Total)", "mpls_mac.tlv_length_total", + FT_UINT8, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_mpls_mac_flags, + { + "Flags", "mpls_mac.flags", + FT_UINT8, BASE_HEX, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_mpls_mac_flags_a, + { + "Flags A", "mpls_mac.flags.a", + FT_BOOLEAN, 8, NULL, 0x80, + "set by a receiver to acknowledge receipt and processing of a MAC Address Withdraw OAM Message", HFILL + } + }, + { + &hf_mpls_mac_flags_r, + { + "Flags R", "mpls_mac.flags.r", + FT_BOOLEAN, 8, NULL, 0x40, + "Set to indicate if the sender is requesting reset of the sequence numbers", HFILL + } + }, + { + &hf_mpls_mac_flags_reserved, + { + "Flags Reserved", "mpls_mac.flags.reserved", + FT_UINT8, BASE_HEX, NULL, 0x3F, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv, + { + "TLV", "mpls_mac.tlv", + FT_NONE, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv_res, + { + "Res(erved)", "mpls_mac.tlv.res", + FT_UINT16, BASE_HEX, NULL, 0xC000, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv_type, + { + "TLV Type", "mpls_mac.tlv.type", + FT_UINT16, BASE_HEX, NULL, 0x3FFF, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv_length, + { + "TLV Length", "mpls_mac.tlv.length", + FT_UINT16, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv_value, + { + "TLV Value", "mpls_mac.tlv.value", + FT_BYTES, BASE_NONE, NULL, 0x0, + NULL, HFILL + } + }, + { + &hf_mpls_mac_tlv_sequence_number, + { + "Sequence Number", "mpls_mac.tlv.sequence_number", + FT_UINT32, BASE_DEC, NULL, 0x0, + NULL, HFILL + } + }, + }; + + static gint *ett[] = { + &ett_mpls_mac, + &ett_mpls_mac_flags, + &ett_mpls_mac_tlv, + }; + + proto_mpls_mac = + proto_register_protocol("Media Access Control (MAC) Address Withdrawal over Static Pseudowire", "MPLS-MAC", "mpls_mac"); + + proto_register_field_array(proto_mpls_mac, hf, array_length(hf)); + proto_register_subtree_array(ett, array_length(ett)); + + mpls_mac_handle = register_dissector("mpls_mac", dissect_mpls_mac, proto_mpls_mac); +} + +void +proto_reg_handoff_mpls_mac(void) +{ + dissector_add_uint("pwach.channel_type", PW_ACH_TYPE_MAC, mpls_mac_handle); +} + +/* + * 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: + */ |