Skip to content

Commit 90543f3

Browse files
committed
Add inbound/outbound support for two DSA DLTs.
In gen_inbound_outbound() add cases for DLT_DSA_TAG_BRCM and DLT_DSA_TAG_DSA. Cover the new code paths with accept and filter tests. For the latter use the existing savefiles. Annotate the contents of dsa.pcap better to make it easier to interpret the results. Make the definition of inbound/outbound in pcap-filter(7) a bit more up to date. In my tests the new code handles DLT_DSA_TAG_BRCM correctly for a live capture as well.
1 parent 4fd6780 commit 90543f3

File tree

3 files changed

+141
-17
lines changed

3 files changed

+141
-17
lines changed

gencode.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8232,6 +8232,33 @@ gen_inbound_outbound(compiler_state_t *cstate, const int outbound)
82328232
* the byte after the 3-byte magic number */
82338233
return gen_mcmp(cstate, OR_LINKHDR, 3, BPF_B, outbound ? 0 : 1, 0x01);
82348234

8235+
case DLT_DSA_TAG_BRCM:
8236+
/*
8237+
* This DSA tag encodes the frame direction in the three most
8238+
* significant bits of its first octet: 0b000***** ("egress",
8239+
* switch -> CPU) means "inbound" in libpcap terms and
8240+
* 0b001***** ("ingress", CPU -> switch) means "outbound".
8241+
*/
8242+
return gen_mcmp(cstate, OR_LINKHDR, 6 + 6, BPF_B,
8243+
outbound ? 0x20 : 0x00, 0xe0);
8244+
8245+
case DLT_DSA_TAG_DSA:
8246+
/*
8247+
* This DSA tag does not encode the frame direction, but it
8248+
* encodes the frame mode, and some modes imply exactly one
8249+
* direction. The mode is the two most significant bits of the
8250+
* first octet. 0b00****** ("To_CPU ingress") and 0b10******
8251+
* ("To_Sniffer ingress") mean "inbound" in libpcap terms and
8252+
* 0b01****** ("From_CPU egress") means "outbound". 0x11******
8253+
* ("Forward") can mean either direction, so cannot be used for
8254+
* this purpose.
8255+
*
8256+
* So match 0b01****** for outbound and 0b*0****** otherwise.
8257+
*/
8258+
return gen_mcmp(cstate, OR_LINKHDR, 6 + 6, BPF_B,
8259+
outbound ? 0x40 : 0x00,
8260+
outbound ? 0xc0 : 0x40);
8261+
82358262
default:
82368263
/*
82378264
* If we have packet meta-data indicating a direction,

pcap-filter.manmisc.in

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
1919
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
2020
.\"
21-
.TH PCAP-FILTER @MAN_MISC_INFO@ "2 November 2025"
21+
.TH PCAP-FILTER @MAN_MISC_INFO@ "22 November 2025"
2222
.SH NAME
2323
pcap-filter \- packet filter syntax
2424
.br
@@ -870,15 +870,26 @@ Exchange Identification (XID) U PDUs
870870
Frame Reject (FRMR) U PDUs
871871
.RE
872872
.IP \fBinbound\fP
873-
Packet was received by the host performing the capture rather than being
874-
sent by that host. This is only supported for certain link-layer types,
875-
such as SLIP and the ``cooked'' Linux capture mode
876-
used for the ``any'' device and for some other device types.
873+
True if the packet was received by the host performing the capture rather than
874+
sent by that host. This primitive is supported for certain link-layer types
875+
only, namely,
876+
.BR DLT_SLIP ,
877+
.BR DLT_IPNET ,
878+
.BR DLT_LINUX_SLL ,
879+
.BR DLT_LINUX_SLL2 ,
880+
.BR DLT_PFLOG ,
881+
.BR DLT_PPP_PPPD ,
882+
a number of Juniper Networks private types and some types of Linux DSA tag.
883+
For reference, the ``any'' pseudo-interface uses
884+
.B DLT_LINUX_SLL
885+
or
886+
.B DLT_LINUX_SLL2
887+
on Linux, and
888+
.B DLT_IPNET
889+
on Solaris.
877890
.IP \fBoutbound\fP
878-
Packet was sent by the host performing the capture rather than being
879-
received by that host. This is only supported for certain link-layer types,
880-
such as SLIP and the ``cooked'' Linux capture mode
881-
used for the ``any'' device and for some other device types.
891+
Same as the above, but for the opposite direction (from the capturing host
892+
to the network).
882893
.IP "\fBifindex \fIinterface_index\fR"
883894
True if the packet was logged via the specified interface (applies only to
884895
packets logged by the Linux "any" cooked v2 interface).

testprogs/TESTrun

Lines changed: 94 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,6 +1083,66 @@ my @accept_blocks = (
10831083
(004) ret #0
10841084
',
10851085
}, # juniper_mfr_outbound
1086+
{
1087+
name => 'inbound_DSA_TAG_BRCM',
1088+
DLT => 'DSA_TAG_BRCM',
1089+
aliases => ['inbound'],
1090+
opt => '
1091+
(000) ldb [12]
1092+
(001) jset #0xe0 jt 2 jf 3
1093+
(002) ret #0
1094+
(003) ret #262144
1095+
',
1096+
unopt => '
1097+
(000) ldb [12]
1098+
(001) and #0xe0
1099+
(002) jeq #0x0 jt 3 jf 4
1100+
(003) ret #262144
1101+
(004) ret #0
1102+
',
1103+
},
1104+
{
1105+
name => 'outbound_DSA_TAG_BRCM',
1106+
DLT => 'DSA_TAG_BRCM',
1107+
aliases => ['outbound'],
1108+
optunopt => '
1109+
(000) ldb [12]
1110+
(001) and #0xe0
1111+
(002) jeq #0x20 jt 3 jf 4
1112+
(003) ret #262144
1113+
(004) ret #0
1114+
',
1115+
},
1116+
{
1117+
name => 'inbound_DSA_TAG_DSA',
1118+
DLT => 'DSA_TAG_DSA',
1119+
aliases => ['inbound'],
1120+
opt => '
1121+
(000) ldb [12]
1122+
(001) jset #0x40 jt 2 jf 3
1123+
(002) ret #0
1124+
(003) ret #262144
1125+
',
1126+
unopt => '
1127+
(000) ldb [12]
1128+
(001) and #0x40
1129+
(002) jeq #0x0 jt 3 jf 4
1130+
(003) ret #262144
1131+
(004) ret #0
1132+
',
1133+
},
1134+
{
1135+
name => 'outbound_DSA_TAG_DSA',
1136+
DLT => 'DSA_TAG_DSA',
1137+
aliases => ['outbound'],
1138+
optunopt => '
1139+
(000) ldb [12]
1140+
(001) and #0xc0
1141+
(002) jeq #0x40 jt 3 jf 4
1142+
(003) ret #262144
1143+
(004) ret #0
1144+
',
1145+
},
10861146
{
10871147
name => 'inbound_linuxext',
10881148
skip => skip_os_not ('linux'),
@@ -20174,16 +20234,28 @@ my @apply_blocks = (
2017420234
expr => 'multicast',
2017520235
results => [64, 64, 64, 64],
2017620236
},
20237+
{
20238+
name => 'inbound_DSA_TAG_BRCM',
20239+
savefile => 'brcm-tag-stp.pcap',
20240+
expr => 'inbound',
20241+
results => [64, 0, 0, 64],
20242+
},
20243+
{
20244+
name => 'outbound_DSA_TAG_BRCM',
20245+
savefile => 'brcm-tag-stp.pcap',
20246+
expr => 'outbound',
20247+
results => [0, 64, 64, 0],
20248+
},
2017720249

2017820250
# Protocol exchange for the packets in dsa.pcap:
20179-
# 1. 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, 192.168.30.1 > 192.168.30.2, ICMP echo request
20180-
# 2. d6:c5:28:21:3e:af > 00:50:b6:29:10:70, 192.168.30.2 > 192.168.30.1, ICMP echo reply
20181-
# 3. 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, 192.168.30.1 > 192.168.30.2, ICMP echo request
20182-
# 4. d6:c5:28:21:3e:af > 00:50:b6:29:10:70, 192.168.30.2 > 192.168.30.1, ICMP echo reply
20183-
# 5. 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, 192.168.30.1 > 192.168.30.2, ICMP echo request
20184-
# 6. d6:c5:28:21:3e:af > 00:50:b6:29:10:70, 192.168.30.2 > 192.168.30.1, ICMP echo reply
20185-
# 7. d6:c5:28:21:3e:af > 00:50:b6:29:10:70, ARP Request who-has 192.168.30.1 tell 192.168.30.2
20186-
# 8. 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, ARP Reply 192.168.30.1 is-at 00:50:b6:29:10:70
20251+
# 1. Forward, 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, 192.168.30.1 > 192.168.30.2, ICMP echo request
20252+
# 2. From CPU, d6:c5:28:21:3e:af > 00:50:b6:29:10:70, 192.168.30.2 > 192.168.30.1, ICMP echo reply
20253+
# 3. Forward, 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, 192.168.30.1 > 192.168.30.2, ICMP echo request
20254+
# 4. From CPU, d6:c5:28:21:3e:af > 00:50:b6:29:10:70, 192.168.30.2 > 192.168.30.1, ICMP echo reply
20255+
# 5. Forward, 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, 192.168.30.1 > 192.168.30.2, ICMP echo request
20256+
# 6. From CPU, d6:c5:28:21:3e:af > 00:50:b6:29:10:70, 192.168.30.2 > 192.168.30.1, ICMP echo reply
20257+
# 7. From CPU, d6:c5:28:21:3e:af > 00:50:b6:29:10:70, ARP Request who-has 192.168.30.1 tell 192.168.30.2
20258+
# 8. Forward, 00:50:b6:29:10:70 > d6:c5:28:21:3e:af, ARP Reply 192.168.30.1 is-at 00:50:b6:29:10:70
2018720259
{
2018820260
name => 'link_dst_DSA_TAG_DSA',
2018920261
savefile => 'dsa.pcap',
@@ -20220,6 +20292,18 @@ my @apply_blocks = (
2022020292
expr => 'icmp[icmptype] == icmp-echo',
2022120293
results => [262144, 0, 262144, 0, 262144, 0, 0, 0],
2022220294
},
20295+
{
20296+
name => 'inbound_DSA_TAG_DSA',
20297+
savefile => 'dsa.pcap',
20298+
expr => 'inbound',
20299+
results => [0, 0, 0, 0, 0, 0, 0, 0],
20300+
},
20301+
{
20302+
name => 'outbound_DSA_TAG_DSA',
20303+
savefile => 'dsa.pcap',
20304+
expr => 'outbound',
20305+
results => [0, 262144, 0, 262144, 0, 262144, 262144, 0],
20306+
},
2022320307
);
2022420308

2022520309
# yyerror()
@@ -21690,6 +21774,7 @@ my %DLTfeatures = (
2169021774
vlan => 1,
2169121775
mpls => 1,
2169221776
llc => 1,
21777+
inout => 1,
2169321778
},
2169421779
DSA_TAG_BRCM_PREPEND => {
2169521780
},
@@ -21701,6 +21786,7 @@ my %DLTfeatures = (
2170121786
vlan => 1,
2170221787
mpls => 1,
2170321788
llc => 1,
21789+
inout => 1,
2170421790
},
2170521791
DSA_TAG_EDSA => {
2170621792
},

0 commit comments

Comments
 (0)