Skip to content

Commit c207823

Browse files
committed
Broadcom DSA tag: fix various issues.
To tell whether a tag is ingress or egress, test exactly the three most significant bits, not the entire octet (as was done to print the opcode) and not one bit only (as was done to branch just after). Fetch an ingress tag TC and TE fields from octet 0, not 1. Use tok2str() to print the opcode. Use three hexadecimal digits to print Destination map value, which does not exceed 0x1FF. In an egress tag the TC field is a bitmap, so name the two reserved bits and use bittok2str(). Lose a few unused constants. Add a reference to the specification and update the tests.
1 parent fb594d5 commit c207823

File tree

5 files changed

+95
-82
lines changed

5 files changed

+95
-82
lines changed

CHANGES

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ DayOfTheWeek, Month DD, YYYY / The Tcpdump Group
1717
BGP: Add support for BGP Role capability and OTC attribute
1818
BGP: Fix most printing code to print directly rather than filling
1919
in a fixed-size buffer to be printed later
20+
Broadcom DSA tag: fix various issues.
2021
ICMP: add dissector for ICMP Interface Identification Object
2122
ICMP: print RFC8335 PROBE extended echo/reply messages.
2223
IEEE 802.11: include the Mesh ID field while printing management frames.

print-brcmtag.c

Lines changed: 33 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
*/
2121

2222
/* \summary: Broadcom Ethernet switches tag (4 bytes) printer */
23+
// specification: https://www.tcpdump.org/linktypes/broadcom-switch-tag.html
2324

2425
#include <config.h>
2526

@@ -32,7 +33,8 @@
3233

3334
#define BRCM_TAG_LEN 4
3435
#define BRCM_OPCODE_SHIFT 5
35-
#define BRCM_OPCODE_MASK 0x7
36+
#define BRCM_EGRESS 0 // 0b000xxxxx
37+
#define BRCM_INGRESS 1 // 0b001xxxxx
3638

3739
/* Ingress fields */
3840
#define BRCM_IG_TC_SHIFT 2
@@ -42,9 +44,8 @@
4244
#define BRCM_IG_DSTMAP_MASK 0x1ff
4345

4446
/* Egress fields */
45-
#define BRCM_EG_CID_MASK 0xff
46-
#define BRCM_EG_RC_MASK 0xff
47-
#define BRCM_EG_RC_RSVD (3 << 6)
47+
#define BRCM_EG_RC_RSVD7 (1 << 7)
48+
#define BRCM_EG_RC_RSVD6 (1 << 6)
4849
#define BRCM_EG_RC_EXCEPTION (1 << 5)
4950
#define BRCM_EG_RC_PROT_SNOOP (1 << 4)
5051
#define BRCM_EG_RC_PROT_TERM (1 << 3)
@@ -55,6 +56,12 @@
5556
#define BRCM_EG_TC_MASK 0x7
5657
#define BRCM_EG_PID_MASK 0x1f
5758

59+
static const struct tok brcm_tag_opcodes[] = {
60+
{ BRCM_EGRESS, "EG" },
61+
{ BRCM_INGRESS, "IG" },
62+
{ 0, NULL }
63+
};
64+
5865
static const struct tok brcm_tag_te_values[] = {
5966
{ 0, "None" },
6067
{ 1, "Untag" },
@@ -63,13 +70,15 @@ static const struct tok brcm_tag_te_values[] = {
6370
{ 0, NULL }
6471
};
6572

66-
static const struct tok brcm_tag_rc_values[] = {
67-
{ 1, "mirror" },
68-
{ 2, "MAC learning" },
69-
{ 4, "switching" },
70-
{ 8, "prot term" },
71-
{ 16, "prot snoop" },
72-
{ 32, "exception" },
73+
static const struct tok brcm_tag_rc_bm[] = {
74+
{ BRCM_EG_RC_MIRROR, "mirror" },
75+
{ BRCM_EG_RC_MAC_LEARN, "MAC learning" },
76+
{ BRCM_EG_RC_SWITCH, "switching" },
77+
{ BRCM_EG_RC_PROT_TERM, "prot term" },
78+
{ BRCM_EG_RC_PROT_SNOOP, "prot snoop" },
79+
{ BRCM_EG_RC_EXCEPTION, "exception" },
80+
{ BRCM_EG_RC_RSVD6, "reserved-6" },
81+
{ BRCM_EG_RC_RSVD7, "reserved-7" },
7382
{ 0, NULL }
7483
};
7584

@@ -83,26 +92,29 @@ brcm_tag_print(netdissect_options *ndo, const u_char *bp)
8392
for (i = 0; i < BRCM_TAG_LEN; i++)
8493
tag[i] = GET_U_1(bp + i);
8594

86-
ND_PRINT("BRCM tag OP: %s", tag[0] ? "IG" : "EG");
87-
if (tag[0] & (1 << BRCM_OPCODE_SHIFT)) {
88-
/* Ingress Broadcom tag */
89-
ND_PRINT(", TC: %d", (tag[1] >> BRCM_IG_TC_SHIFT) &
95+
uint8_t opcode = tag[0] >> BRCM_OPCODE_SHIFT;
96+
ND_PRINT("BRCM tag OP: %s", tok2str(brcm_tag_opcodes, NULL, opcode));
97+
switch (opcode) {
98+
case BRCM_INGRESS:
99+
ND_PRINT(", TC: %d", (tag[0] >> BRCM_IG_TC_SHIFT) &
90100
BRCM_IG_TC_MASK);
91101
ND_PRINT(", TE: %s",
92102
tok2str(brcm_tag_te_values, "unknown",
93-
(tag[1] & BRCM_IG_TE_MASK)));
103+
(tag[0] & BRCM_IG_TE_MASK)));
94104
ND_PRINT(", TS: %d", tag[1] >> BRCM_IG_TS_SHIFT);
95105
dst_map = (uint16_t)tag[2] << 8 | tag[3];
96-
ND_PRINT(", DST map: 0x%04x", dst_map & BRCM_IG_DSTMAP_MASK);
97-
} else {
98-
/* Egress Broadcom tag */
106+
ND_PRINT(", DST map: 0x%03x", dst_map & BRCM_IG_DSTMAP_MASK);
107+
break;
108+
case BRCM_EGRESS:
99109
ND_PRINT(", CID: %d", tag[1]);
100-
ND_PRINT(", RC: %s", tok2str(brcm_tag_rc_values,
101-
"reserved", tag[2]));
110+
ND_PRINT(", RC: [%s]", bittok2str(brcm_tag_rc_bm,
111+
"none", tag[2]));
102112
ND_PRINT(", TC: %d", (tag[3] >> BRCM_EG_TC_SHIFT) &
103113
BRCM_EG_TC_MASK);
104114
ND_PRINT(", port: %d", tag[3] & BRCM_EG_PID_MASK);
115+
break;
105116
}
117+
106118
ND_PRINT(", ");
107119
}
108120

tests/brcm-tag-e.out

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,23 @@
1-
1 1970-01-01 02:10:20.634030 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0080, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
2-
2 1970-01-01 02:10:20.696008 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0020, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
3-
3 1970-01-01 02:10:23.151503 68:05:ca:18:47:70 > ff:ff:ff:ff:ff:ff, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.255: ICMP echo request, id 22737, seq 1, length 64
4-
4 1970-01-01 02:10:23.650963 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0080, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
5-
5 1970-01-01 02:10:23.712960 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0020, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
6-
6 1970-01-01 02:10:24.177588 68:05:ca:18:47:70 > ff:ff:ff:ff:ff:ff, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.255: ICMP echo request, id 22737, seq 2, length 64
7-
7 1970-01-01 02:10:25.201640 68:05:ca:18:47:70 > ff:ff:ff:ff:ff:ff, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.255: ICMP echo request, id 22737, seq 3, length 64
8-
8 1970-01-01 02:10:30.015266 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.115: ICMP echo request, id 22744, seq 1, length 64
9-
9 1970-01-01 02:10:30.015480 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0001, ethertype IPv4 (0x0800), length 102: 192.168.1.115 > 192.168.1.1: ICMP echo reply, id 22744, seq 1, length 64
10-
10 1970-01-01 02:10:30.158348 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0001, ethertype IPv4 (0x0800), length 346: 192.168.1.115.68 > 192.168.1.1.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
11-
11 1970-01-01 02:10:30.170023 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype IPv4 (0x0800), length 346: 192.168.1.1.67 > 192.168.1.115.68: BOOTP/DHCP, Reply, length 300
12-
12 1970-01-01 02:10:33.178632 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0002, ethertype IPv4 (0x0800), length 346: 192.168.3.23.68 > 192.168.3.1.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
13-
13 1970-01-01 02:10:33.191027 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 1, ethertype IPv4 (0x0800), length 346: 192.168.3.1.67 > 192.168.3.23.68: BOOTP/DHCP, Reply, length 300
14-
14 1970-01-01 02:10:35.080973 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0001, ethertype ARP (0x0806), length 68: Request who-has 192.168.1.1 tell 192.168.1.115, length 50
15-
15 1970-01-01 02:10:35.081198 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype ARP (0x0806), length 64: Reply 192.168.1.1 is-at 68:05:ca:18:47:70, length 46
16-
16 1970-01-01 02:10:35.249563 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 0, ethertype ARP (0x0806), length 64: Request who-has 192.168.1.115 tell 192.168.1.1, length 46
17-
17 1970-01-01 02:10:35.249634 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0001, ethertype ARP (0x0806), length 68: Reply 192.168.1.115 is-at 00:10:18:de:38:1e, length 50
18-
18 1970-01-01 02:10:36.495763 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 1, ethertype IPv4 (0x0800), length 102: 192.168.3.1 > 192.168.3.23: ICMP echo request, id 22748, seq 1, length 64
19-
19 1970-01-01 02:10:36.495906 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0002, ethertype IPv4 (0x0800), length 102: 192.168.3.23 > 192.168.3.1: ICMP echo reply, id 22748, seq 1, length 64
20-
20 1970-01-01 02:10:37.521654 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 1, ethertype IPv4 (0x0800), length 102: 192.168.3.1 > 192.168.3.23: ICMP echo request, id 22748, seq 2, length 64
21-
21 1970-01-01 02:10:37.521717 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0002, ethertype IPv4 (0x0800), length 102: 192.168.3.23 > 192.168.3.1: ICMP echo reply, id 22748, seq 2, length 64
22-
22 1970-01-01 02:10:38.321557 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: exception, TC: 0, port: 1, ethertype ARP (0x0806), length 64: Request who-has 192.168.3.23 tell 192.168.3.1, length 46
23-
23 1970-01-01 02:10:38.321602 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x0002, ethertype ARP (0x0806), length 68: Reply 192.168.3.23 is-at 00:10:18:de:38:1e, length 50
1+
1 1970-01-01 02:10:20.634030 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 3, TE: None, TS: 0, DST map: 0x080, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
2+
2 1970-01-01 02:10:20.696008 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 3, TE: None, TS: 0, DST map: 0x020, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
3+
3 1970-01-01 02:10:23.151503 68:05:ca:18:47:70 > ff:ff:ff:ff:ff:ff, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.255: ICMP echo request, id 22737, seq 1, length 64
4+
4 1970-01-01 02:10:23.650963 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 3, TE: None, TS: 0, DST map: 0x080, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
5+
5 1970-01-01 02:10:23.712960 00:10:18:de:38:1e > ff:ff:ff:ff:ff:ff, BRCM tag OP: IG, TC: 3, TE: None, TS: 0, DST map: 0x020, ethertype IPv4 (0x0800), length 346: 0.0.0.0.68 > 255.255.255.255.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
6+
6 1970-01-01 02:10:24.177588 68:05:ca:18:47:70 > ff:ff:ff:ff:ff:ff, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.255: ICMP echo request, id 22737, seq 2, length 64
7+
7 1970-01-01 02:10:25.201640 68:05:ca:18:47:70 > ff:ff:ff:ff:ff:ff, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.255: ICMP echo request, id 22737, seq 3, length 64
8+
8 1970-01-01 02:10:30.015266 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype IPv4 (0x0800), length 102: 192.168.1.1 > 192.168.1.115: ICMP echo request, id 22744, seq 1, length 64
9+
9 1970-01-01 02:10:30.015480 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 1, TE: None, TS: 0, DST map: 0x001, ethertype IPv4 (0x0800), length 102: 192.168.1.115 > 192.168.1.1: ICMP echo reply, id 22744, seq 1, length 64
10+
10 1970-01-01 02:10:30.158348 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x001, ethertype IPv4 (0x0800), length 346: 192.168.1.115.68 > 192.168.1.1.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
11+
11 1970-01-01 02:10:30.170023 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype IPv4 (0x0800), length 346: 192.168.1.1.67 > 192.168.1.115.68: BOOTP/DHCP, Reply, length 300
12+
12 1970-01-01 02:10:33.178632 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 3, TE: None, TS: 0, DST map: 0x002, ethertype IPv4 (0x0800), length 346: 192.168.3.23.68 > 192.168.3.1.67: BOOTP/DHCP, Request from 00:10:18:de:38:1e, length 300
13+
13 1970-01-01 02:10:33.191027 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 1, ethertype IPv4 (0x0800), length 346: 192.168.3.1.67 > 192.168.3.23.68: BOOTP/DHCP, Reply, length 300
14+
14 1970-01-01 02:10:35.080973 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x001, ethertype ARP (0x0806), length 68: Request who-has 192.168.1.1 tell 192.168.1.115, length 50
15+
15 1970-01-01 02:10:35.081198 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype ARP (0x0806), length 64: Reply 192.168.1.1 is-at 68:05:ca:18:47:70, length 46
16+
16 1970-01-01 02:10:35.249563 68:05:ca:18:47:70 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 0, ethertype ARP (0x0806), length 64: Request who-has 192.168.1.115 tell 192.168.1.1, length 46
17+
17 1970-01-01 02:10:35.249634 00:10:18:de:38:1e > 68:05:ca:18:47:70, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x001, ethertype ARP (0x0806), length 68: Reply 192.168.1.115 is-at 00:10:18:de:38:1e, length 50
18+
18 1970-01-01 02:10:36.495763 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 1, ethertype IPv4 (0x0800), length 102: 192.168.3.1 > 192.168.3.23: ICMP echo request, id 22748, seq 1, length 64
19+
19 1970-01-01 02:10:36.495906 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 1, TE: None, TS: 0, DST map: 0x002, ethertype IPv4 (0x0800), length 102: 192.168.3.23 > 192.168.3.1: ICMP echo reply, id 22748, seq 1, length 64
20+
20 1970-01-01 02:10:37.521654 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 1, ethertype IPv4 (0x0800), length 102: 192.168.3.1 > 192.168.3.23: ICMP echo request, id 22748, seq 2, length 64
21+
21 1970-01-01 02:10:37.521717 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 1, TE: None, TS: 0, DST map: 0x002, ethertype IPv4 (0x0800), length 102: 192.168.3.23 > 192.168.3.1: ICMP echo reply, id 22748, seq 2, length 64
22+
22 1970-01-01 02:10:38.321557 68:05:ca:18:47:74 > 00:10:18:de:38:1e, BRCM tag OP: EG, CID: 0, RC: [exception], TC: 0, port: 1, ethertype ARP (0x0806), length 64: Request who-has 192.168.3.23 tell 192.168.3.1, length 46
23+
23 1970-01-01 02:10:38.321602 00:10:18:de:38:1e > 68:05:ca:18:47:74, BRCM tag OP: IG, TC: 0, TE: None, TS: 0, DST map: 0x002, ethertype ARP (0x0806), length 68: Reply 192.168.3.23 is-at 00:10:18:de:38:1e, length 50

0 commit comments

Comments
 (0)