Debian Codegraph @

link/tcx_test.go

raw symbols SCIP
1 //go:build !windows
2
3 package link
4
5 import (
6 "fmt"
7 "math"
8 "net"
9 "testing"
10
11 "github.com/go-quicktest/qt"
12
13 "github.com/cilium/ebpf"
14 "github.com/cilium/ebpf/internal/testutils"
15 "github.com/cilium/ebpf/internal/unix"
16 )
17
18 func TestAttachTCX(t *testing.T) {
19 testutils.SkipOnOldKernel(t, "6.6", "TCX link")
20
21 prog := mustLoadProgram(t, ebpf.SchedCLS, ebpf.AttachNone, "")
22 link, _ := mustAttachTCX(t, prog, ebpf.AttachTCXIngress)
23
24 testLink(t, link, prog)
25 }
26
27 func TestTCXAnchor(t *testing.T) {
28 testutils.SkipOnOldKernel(t, "6.6", "TCX link")
29
30 a := mustLoadProgram(t, ebpf.SchedCLS, ebpf.AttachNone, "")
31 b := mustLoadProgram(t, ebpf.SchedCLS, ebpf.AttachNone, "")
32
33 linkA, iface := mustAttachTCX(t, a, ebpf.AttachTCXEgress)
34
35 programInfo, err := a.Info()
36 qt.Assert(t, qt.IsNil(err))
37 programID, _ := programInfo.ID()
38
39 linkInfo, err := linkA.Info()
40 qt.Assert(t, qt.IsNil(err))
41 linkID := linkInfo.ID
42
43 for _, anchor := range []Anchor{
44 Head(),
45 Tail(),
46 BeforeProgram(a),
47 BeforeProgramByID(programID),
48 AfterLink(linkA),
49 AfterLinkByID(linkID),
50 } {
51 t.Run(fmt.Sprintf("%T", anchor), func(t *testing.T) {
52 linkB, err := AttachTCX(TCXOptions{
53 Program: b,
54 Attach: ebpf.AttachTCXEgress,
55 Interface: iface,
56 Anchor: anchor,
57 })
58 qt.Assert(t, qt.IsNil(err))
59 qt.Assert(t, qt.IsNil(linkB.Close()))
60 })
61 }
62 }
63
64 func TestTCXExpectedRevision(t *testing.T) {
65 testutils.SkipOnOldKernel(t, "6.6", "TCX link")
66
67 iface, err := net.InterfaceByName("lo")
68 qt.Assert(t, qt.IsNil(err))
69
70 _, err = AttachTCX(TCXOptions{
71 Program: mustLoadProgram(t, ebpf.SchedCLS, ebpf.AttachNone, ""),
72 Attach: ebpf.AttachTCXEgress,
73 Interface: iface.Index,
74 ExpectedRevision: math.MaxUint64,
75 })
76 qt.Assert(t, qt.ErrorIs(err, unix.ESTALE))
77 }
78
79 func mustAttachTCX(tb testing.TB, prog *ebpf.Program, attachType ebpf.AttachType) (Link, int) {
80 iface, err := net.InterfaceByName("lo")
81 qt.Assert(tb, qt.IsNil(err))
82
83 link, err := AttachTCX(TCXOptions{
84 Program: prog,
85 Attach: attachType,
86 Interface: iface.Index,
87 })
88 qt.Assert(tb, qt.IsNil(err))
89 tb.Cleanup(func() { qt.Assert(tb, qt.IsNil(link.Close())) })
90
91 return link, iface.Index
92 }