packet-brcm-tag: Add Broadcom tag dissection

Add support for dissecting the old-style Broadcom tag with Ethertype 0x8874,
this was supported by switches like Broadcom BCM5325. Newer switches use a
different tag format (with no Ethertype) which will be supported later.

Change-Id: Iec26f8d13058399a35fb258ccadc48f7f5ac8474
Reviewed-on: https://code.wireshark.org/review/23592
Petri-Dish: Alexis La Goutte <alexis.lagoutte@gmail.com>
Tested-by: Petri Dish Buildbot <buildbot-no-reply@wireshark.org>
Reviewed-by: Alexis La Goutte <alexis.lagoutte@gmail.com>
Reviewed-by: Michael Mann <mmann78@netscape.net>
This commit is contained in:
Florian Fainelli 2017-09-16 21:45:49 -07:00 committed by Michael Mann
parent dc011cc53e
commit 194d30badf
6 changed files with 210 additions and 0 deletions

View File

@ -67,6 +67,7 @@ QUIC (IETF)
Wi-Fi Device Provisioning Protocol
PFCP (Packet Forwarding Control Protocol)
Tibia
Broadcom tags (Broadcom Ethernet switch management frames)
--sort-and-group--
=== Updated Protocol Support

View File

@ -679,6 +679,7 @@ set(DISSECTOR_SRC
packet-bootparams.c
packet-bpdu.c
packet-bpq.c
packet-brcm-tag.c
packet-brdwlk.c
packet-brp.c
packet-bssap.c

View File

@ -334,6 +334,7 @@ DISSECTOR_SRC = \
packet-bootparams.c \
packet-bpdu.c \
packet-bpq.c \
packet-brcm-tag.c \
packet-brdwlk.c \
packet-brp.c \
packet-bssap.c \

View File

@ -0,0 +1,202 @@
/* packet-brcm-tag.c
* Routines for Broadcom tag dissection
*
* Copyright 2017, Florian Fainelli <f.fainelli[AT]gmail.com>
*
* Wireshark - Network traffic analyzer
* By Gerald Combs <gerald[AT]wireshark.org>
* Copyright 1998 Gerald Combs
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation; either version 2
* of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
#include "config.h"
#include <epan/packet.h>
#include <epan/etypes.h>
#include <epan/ptvcursor.h>
void proto_register_brcm_tag(void);
void proto_reg_handoff_brcm_tag(void);
#define BRCM_TAG_LEN 4
#define BRCM_TAG_OPCODE_MASK 0x7
#define BRCM_TAG_DEV_ID_MASK 0x3
#define BRCM_TAG_SRC_DEV_ID_SHIFT 4
#define BRCM_TAG_PORT_ID_MASK 0xF
#define BRCM_TAG_OPCODE_UNICAST 0x0
#define BRCM_TAG_OPCODE_MULTICAST 0x1
#define BRCM_TAG_OPCODE_EG_DIRECT 0x2
#define BRCM_TAG_OPCODE_IG_DIRECT 0x3
#define BRCM_TAG_OPCODE_SHIFT 5
#define BRCM_TAG_MR_SHIFT 4
#define BRCM_TAG_MO_SHIFT 3
static int proto_brcm_tag = -1;
static int hf_brcm_tag_opcode = -1;
static int hf_brcm_tag_frame_octet_cnt = -1;
static int hf_brcm_tag_mr = -1;
static int hf_brcm_tag_mo = -1;
static int hf_brcm_tag_reserved = -1;
static int hf_brcm_tag_dest_dev_id = -1;
static int hf_brcm_tag_dest_port_id = -1;
static int hf_brcm_tag_src_dev_id = -1;
static int hf_brcm_tag_src_port_id = -1;
static gint ett_brcm_tag = -1;
#define TVB_LEN_GREATEST 1
#define TVB_LEN_UNDEF 0
#define TVB_LEN_SHORTEST -1
static int check_tvb_length(ptvcursor_t *cursor, const gint length)
{
if (!cursor)
return TVB_LEN_UNDEF;
if (tvb_reported_length_remaining(ptvcursor_tvbuff(cursor),
ptvcursor_current_offset(cursor)) < length)
return TVB_LEN_SHORTEST;
return TVB_LEN_GREATEST;
}
static const value_string brcm_tag_opcode_vals[] = {
{ BRCM_TAG_OPCODE_UNICAST, "Unicast" },
{ BRCM_TAG_OPCODE_MULTICAST, "Multicast" },
{ BRCM_TAG_OPCODE_EG_DIRECT, "Egress directed" },
{ BRCM_TAG_OPCODE_IG_DIRECT, "Ingress directed" },
{ 0, NULL }
};
static int
dissect_brcm_tag(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
{
proto_item *ti;
proto_tree *brcm_tag_tree;
ptvcursor_t *cursor;
guint8 opcode_mr_mo;
guint8 opcode;
col_set_str(pinfo->cinfo, COL_PROTOCOL, "Broadcom tag");
col_set_str(pinfo->cinfo, COL_INFO, "MAC Management");
ti = proto_tree_add_item(tree, proto_brcm_tag, tvb, 0, -1, ENC_NA);
brcm_tag_tree = proto_item_add_subtree(ti, ett_brcm_tag);
cursor = ptvcursor_new(brcm_tag_tree, tvb, 0);
/* Check if we have enough data to process the header */
if (check_tvb_length(cursor, BRCM_TAG_LEN) != TVB_LEN_SHORTEST) {
opcode_mr_mo = tvb_get_guint8(ptvcursor_tvbuff(cursor), ptvcursor_current_offset(cursor));
opcode = (opcode_mr_mo >> BRCM_TAG_OPCODE_SHIFT) & BRCM_TAG_OPCODE_MASK;
ptvcursor_add_no_advance(cursor, hf_brcm_tag_opcode, 1, ENC_NA);
ptvcursor_add_no_advance(cursor, hf_brcm_tag_mr, 1, ENC_NA);
ptvcursor_add(cursor, hf_brcm_tag_mo, 1, ENC_NA);
ptvcursor_add(cursor, hf_brcm_tag_frame_octet_cnt, 2, ENC_BIG_ENDIAN);
if (opcode == BRCM_TAG_OPCODE_UNICAST || opcode == BRCM_TAG_OPCODE_EG_DIRECT)
ptvcursor_add(cursor, hf_brcm_tag_dest_dev_id, 1, ENC_NA);
else
ptvcursor_add(cursor, hf_brcm_tag_reserved, 1, ENC_NA);
ptvcursor_add_no_advance(cursor, hf_brcm_tag_src_dev_id, 1, ENC_NA);
if (opcode == BRCM_TAG_OPCODE_EG_DIRECT)
ptvcursor_add_no_advance(cursor, hf_brcm_tag_dest_port_id, 1, ENC_NA);
else
ptvcursor_add_no_advance(cursor, hf_brcm_tag_src_port_id, 1, ENC_NA);
}
ptvcursor_free(cursor);
return tvb_captured_length(tvb);
}
void
proto_register_brcm_tag(void)
{
static hf_register_info hf[] = {
{ &hf_brcm_tag_opcode,
{ "Opcode", "brcm_tag.opcode",
FT_UINT8, BASE_HEX, VALS(brcm_tag_opcode_vals),
BRCM_TAG_OPCODE_MASK << BRCM_TAG_OPCODE_SHIFT, NULL, HFILL }
},
{ &hf_brcm_tag_mr,
{ "Mirror bit", "brcm_tag.mr",
FT_UINT8, BASE_HEX, NULL, 1 << BRCM_TAG_MR_SHIFT, NULL, HFILL }
},
{ &hf_brcm_tag_mo,
{ "Mirror only", "brcm_tag.mo",
FT_UINT8, BASE_HEX, NULL, 1 << BRCM_TAG_MO_SHIFT, NULL, HFILL }
},
{ &hf_brcm_tag_reserved,
{ "Reserved", "brcm_tag.reserved",
FT_UINT8, BASE_DEC, NULL, 0x0, NULL, HFILL }
},
{ &hf_brcm_tag_frame_octet_cnt,
{ "Frame octet count", "brcm_tag.frame_octet_cnt",
FT_UINT16, BASE_DEC, NULL, 0xFFF, NULL, HFILL }
},
{ &hf_brcm_tag_dest_dev_id,
{ "Destination device ID", "brcm_tag.dest_dev_id",
FT_UINT8, BASE_DEC, NULL, BRCM_TAG_DEV_ID_MASK, NULL, HFILL }
},
{ &hf_brcm_tag_dest_port_id,
{ "Destination port ID", "brcm_tag.dest_port_id",
FT_UINT8, BASE_DEC, NULL, BRCM_TAG_PORT_ID_MASK, NULL, HFILL }
},
{ &hf_brcm_tag_src_dev_id,
{ "Source device ID", "brcm_tag.src_dev_id",
FT_UINT8, BASE_DEC, NULL, BRCM_TAG_DEV_ID_MASK << BRCM_TAG_SRC_DEV_ID_SHIFT, NULL, HFILL }
},
{ &hf_brcm_tag_src_port_id,
{ "Source port ID", "brcm_tag.src_port_id",
FT_UINT8, BASE_DEC, NULL, BRCM_TAG_PORT_ID_MASK, NULL, HFILL }
},
};
static gint *ett[] = {
&ett_brcm_tag,
};
proto_brcm_tag = proto_register_protocol("Broadcom tag protocol", "Broadcom tag", "brcm-tag");
proto_register_field_array(proto_brcm_tag, hf, array_length(hf));
proto_register_subtree_array(ett, array_length(ett));
}
void
proto_reg_handoff_brcm_tag(void)
{
dissector_handle_t brcm_tag_handle;
brcm_tag_handle = create_dissector_handle(dissect_brcm_tag, proto_brcm_tag);
dissector_add_uint("ethertype", ETHERTYPE_BRCM_TYPE, brcm_tag_handle);
}
/*
* Editor modelines
*
* Local Variables:
* c-basic-offset: 3
* tab-width: 8
* indent-tabs-mode: nil
* End:
*
* ex: set shiftwidth=3 tabstop=8 expandtab:
* :indentSize=3:tabSize=8:noTabs=true:
*/

View File

@ -82,6 +82,7 @@ const value_string etype_vals[] = {
{ ETHERTYPE_INTEL_ANS, "Intel ANS probe" },
{ ETHERTYPE_MS_NLB_HEARTBEAT, "MS NLB heartbeat" },
{ ETHERTYPE_JUMBO_LLC, "Jumbo LLC" },
{ ETHERTYPE_BRCM_TYPE, "Broadcom tag" },
{ ETHERTYPE_HOMEPLUG, "Homeplug" },
{ ETHERTYPE_HOMEPLUG_AV, "Homeplug AV" },
{ ETHERTYPE_MRP, "MRP" },

View File

@ -324,6 +324,10 @@ extern "C" {
#define ETHERTYPE_JUMBO_LLC 0x8870 /* 802.2 jumbo frames http://tools.ietf.org/html/draft-ietf-isis-ext-eth */
#endif
#ifndef ETHERTYPE_BRCM_TYPE
#define ETHERTYPE_BRCM_TYPE 0x8874 /* Broadcom Ethernet switches management tag */
#endif
#ifndef ETHERTYPE_HOMEPLUG
#define ETHERTYPE_HOMEPLUG 0x887B /* IEEE assigned Ethertype */
#endif