Skip to content

Commit 26a6a0f

Browse files
committed
pcapfilter: rename files and consolidate API
- Rename filter.go → bpf_filter.go, spec.go → bpf_spec.go - Name stub layout constants in elfpatch_didi.go - Consolidate function names (Apply/Load final form) - Move README to docs/ Change-Id: I0c7806cdc02791f498fb609d1118f4f367186c51 (cherry picked from commit f4498302461c402688327619774c191677a9de5a)
1 parent 4b264b4 commit 26a6a0f

3 files changed

Lines changed: 12 additions & 10 deletions

File tree

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
// Usage:
1919
//
2020
// spec, _ := ebpf.LoadCollectionSpec("prog.o")
21-
// if err := pcapfilter.Apply(spec, "host 10.0.0.1"); err != nil { ... }
21+
// if err := pcapfilter.InjectFilter(spec, "host 10.0.0.1"); err != nil { ... }
2222
// coll, _ := ebpf.NewCollection(spec)
2323
//
2424
// Limitations inherited from go-pcap's pure-Go compiler:
@@ -60,6 +60,13 @@ const (
6060
etherTypeIPv6 = 0x86dd
6161
)
6262

63+
// L2StubSymbol and L3StubSymbol are the __noinline BPF function names that mark
64+
// the injection points. The C program must declare both pcap_stub_l2 and pcap_stub_l3.
65+
const (
66+
L2StubSymbol = "pcap_stub_l2"
67+
L3StubSymbol = "pcap_stub_l3"
68+
)
69+
6370
// stack slot offsets used by patchPacketLoads.
6471
// R4/R5 hold packet data/data_end on entry; cbpfc scratch starts at +cbpfcStackOffset.
6572
// These slots must not overlap cbpfc's StackOffset region.
Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
// See the License for the specific language governing permissions and
1313
// limitations under the License.
1414

15+
//go:build !didi
16+
1517
package pcapfilter
1618

1719
import (
@@ -21,13 +23,6 @@ import (
2123
"github.com/cilium/ebpf/asm"
2224
)
2325

24-
// L2StubSymbol and L3StubSymbol are the __noinline BPF function names that mark
25-
// the injection points. The C program must declare both pcap_stub_l2 and pcap_stub_l3.
26-
const (
27-
L2StubSymbol = "pcap_stub_l2"
28-
L3StubSymbol = "pcap_stub_l3"
29-
)
30-
3126
// Apply compiles filterExpr for both L2 (DLT_EN10MB) and L3 (DLT_RAW), then splices
3227
// the resulting eBPF programs into their matching stub functions in spec.
3328
// Must be called before ebpf.NewCollection.

internal/pcapfilter/load_default_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ func dumpPrograms(t *testing.T, spec *ebpf.CollectionSpec, prefix string) {
6262
}
6363
}
6464

65-
func TestApply(t *testing.T) {
65+
func TestInjectFilter(t *testing.T) {
6666
if os.Getuid() != 0 {
6767
t.Skip("Skipping: requires root")
6868
}
@@ -79,7 +79,7 @@ func TestApply(t *testing.T) {
7979

8080
filterExpr := "ip and src net 192.168.1.0/24 and tcp dst port 3306"
8181
if err := Apply(specs, filterExpr); err != nil {
82-
t.Fatalf("Apply: %v", err)
82+
t.Fatalf("InjectFilter: %v", err)
8383
}
8484

8585
dumpPrograms(t, specs, "Program")

0 commit comments

Comments
 (0)