Skip to content

Commit 6c2ff6e

Browse files
committed
use seperate pcap flags for tunnel.
Trying to use a l2 based expression such as 'host ether xx-xx-xx-xx-xx-xx' results in a error as it is not a valid l3 expression (thus compilation fails) however, in order to be able to have both l2&l3 expressions we need to seperate out the flags and pass them seperately. Signed-off-by: Tom Hadlaw <[email protected]>
1 parent c30d64f commit 6c2ff6e

File tree

3 files changed

+10
-6
lines changed

3 files changed

+10
-6
lines changed

internal/libpcap/inject.go

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ func InjectL2Filter(program *ebpf.ProgramSpec, filterExpr string) (err error) {
1717
return injectFilter(program, filterExpr, false, false)
1818
}
1919

20-
func InjectFilters(program *ebpf.ProgramSpec, filterExpr, tunnelFilterExpr string) (err error) {
20+
func InjectFilters(program *ebpf.ProgramSpec, filterExpr, tunnelFilterExprL2, tunnelFilterExprL3 string) (err error) {
2121
if err = injectFilter(program, filterExpr, false, false); err != nil {
2222
return
2323
}
@@ -28,10 +28,10 @@ func InjectFilters(program *ebpf.ProgramSpec, filterExpr, tunnelFilterExpr strin
2828
return injectFilter(program, "__pwru_reject_all__", true, false)
2929
}
3030
// Attach any tunnel filters.
31-
if err := injectFilter(program, tunnelFilterExpr, false, true); err != nil {
31+
if err := injectFilter(program, tunnelFilterExprL2, false, true); err != nil {
3232
return fmt.Errorf("l2 tunnel filter: %w", err)
3333
}
34-
if err := injectFilter(program, tunnelFilterExpr, true, true); err != nil {
34+
if err := injectFilter(program, tunnelFilterExprL3, true, true); err != nil {
3535
return fmt.Errorf("l3 tunnel filter: %w", err)
3636
}
3737
return nil

internal/pwru/types.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,8 @@ type Flags struct {
3838
FilterTrackBpfHelpers bool
3939
FilterIfname string
4040
FilterPcap string
41-
FilterTunnelPcap string
41+
FilterTunnelPcapL2 string
42+
FilterTunnelPcapL3 string
4243
FilterKprobeBatch uint
4344

4445
OutputTS string
@@ -76,7 +77,8 @@ func (f *Flags) SetFlags() {
7677
flag.BoolVar(&f.FilterTrackSkb, "filter-track-skb", false, "trace a packet even if it does not match given filters (e.g., after NAT or tunnel decapsulation)")
7778
flag.BoolVar(&f.FilterTrackSkbByStackid, "filter-track-skb-by-stackid", false, "trace a packet even after it is kfreed (e.g., traffic going through bridge)")
7879
flag.BoolVar(&f.FilterTraceTc, "filter-trace-tc", false, "trace TC bpf progs")
79-
flag.StringVar(&f.FilterTunnelPcap, "filter-tunnel-pcap", "", "pcap expression for vxlan/geneve tunnel (l3)")
80+
flag.StringVar(&f.FilterTunnelPcapL2, "filter-tunnel-pcap-l2", "", "pcap expression for vxlan/geneve tunnel (l2)")
81+
flag.StringVar(&f.FilterTunnelPcapL3, "filter-tunnel-pcap-l3", "", "pcap expression for vxlan/geneve tunnel (l3)")
8082
flag.BoolVar(&f.FilterTraceXdp, "filter-trace-xdp", false, "trace XDP bpf progs")
8183
flag.BoolVar(&f.FilterTrackBpfHelpers, "filter-track-bpf-helpers", false, "trace BPF helper functions")
8284
flag.StringVar(&f.FilterIfname, "filter-ifname", "", "filter skb ifname in --filter-netns (if not specified, use current netns)")

main.go

+3-1
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,9 @@ func main() {
151151
continue
152152
}
153153
if err = libpcap.InjectFilters(program,
154-
flags.FilterPcap, flags.FilterTunnelPcap); err != nil {
154+
flags.FilterPcap,
155+
flags.FilterTunnelPcapL2,
156+
flags.FilterTunnelPcapL3); err != nil {
155157
log.Fatalf("Failed to inject filter ebpf for %s: %v", name, err)
156158
}
157159
}

0 commit comments

Comments
 (0)