| 1 |
|
| 2 |
|
| 3 |
package link |
| 4 |
|
| 5 |
import ( |
| 6 |
"testing" |
| 7 |
|
| 8 |
"github.com/go-quicktest/qt" |
| 9 |
|
| 10 |
"github.com/cilium/ebpf" |
| 11 |
"github.com/cilium/ebpf/internal/testutils" |
| 12 |
) |
| 13 |
|
| 14 |
func TestAttachNetfilter(t *testing.T) { |
| 15 |
testutils.SkipOnOldKernel(t, "6.4", "BPF_LINK_TYPE_NETFILTER") |
| 16 |
|
| 17 |
prog := mustLoadProgram(t, ebpf.Netfilter, ebpf.AttachNetfilter, "") |
| 18 |
|
| 19 |
l, err := AttachNetfilter(NetfilterOptions{ |
| 20 |
Program: prog, |
| 21 |
ProtocolFamily: NetfilterProtoIPv4, |
| 22 |
Hook: NetfilterInetLocalOut, |
| 23 |
Priority: -128, |
| 24 |
}) |
| 25 |
if err != nil { |
| 26 |
t.Fatal(err) |
| 27 |
} |
| 28 |
|
| 29 |
info, err := l.Info() |
| 30 |
if err != nil { |
| 31 |
t.Fatal(err) |
| 32 |
} |
| 33 |
nfInfo := info.Netfilter() |
| 34 |
qt.Assert(t, qt.Equals(nfInfo.ProtocolFamily, NetfilterProtoIPv4)) |
| 35 |
qt.Assert(t, qt.Equals(nfInfo.Hook, NetfilterInetLocalOut)) |
| 36 |
qt.Assert(t, qt.Equals(nfInfo.Priority, -128)) |
| 37 |
|
| 38 |
testLink(t, l, prog) |
| 39 |
} |