github.com/cilium/ebpf@v0.15.1-0.20240517100537-8079b37aa138/link/xdp_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 IfIndexLO = 1
    11  
    12  func TestAttachXDP(t *testing.T) {
    13  	testutils.SkipOnOldKernel(t, "5.9", "BPF_LINK_TYPE_XDP")
    14  
    15  	prog := mustLoadProgram(t, ebpf.XDP, 0, "")
    16  
    17  	l, err := AttachXDP(XDPOptions{
    18  		Program:   prog,
    19  		Interface: IfIndexLO,
    20  	})
    21  	if err != nil {
    22  		t.Fatal(err)
    23  	}
    24  
    25  	testLink(t, l, prog)
    26  }