github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/link/netfilter_test.go (about)

     1  package link
     2  
     3  import (
     4  	"testing"
     5  
     6  	"github.com/cilium/ebpf"
     7  	"github.com/cilium/ebpf/internal/testutils"
     8  )
     9  
    10  const (
    11  	NFPROTO_IPV4      = 0x2
    12  	NF_INET_LOCAL_OUT = 0x3
    13  )
    14  
    15  func TestAttachNetfilter(t *testing.T) {
    16  	testutils.SkipOnOldKernel(t, "6.4", "BPF_LINK_TYPE_NETFILTER")
    17  
    18  	prog := mustLoadProgram(t, ebpf.Netfilter, ebpf.AttachNetfilter, "")
    19  
    20  	l, err := AttachNetfilter(NetfilterOptions{
    21  		Program:        prog,
    22  		ProtocolFamily: NFPROTO_IPV4,
    23  		HookNumber:     NF_INET_LOCAL_OUT,
    24  		Priority:       -128,
    25  	})
    26  	if err != nil {
    27  		t.Fatal(err)
    28  	}
    29  
    30  	testLink(t, l, prog)
    31  }