github.com/cilium/ebpf@v0.16.0/link/xdp_test.go (about)

     1  package link
     2  
     3  import (
     4  	"math"
     5  	"testing"
     6  
     7  	"github.com/cilium/ebpf"
     8  	"github.com/cilium/ebpf/internal/testutils"
     9  	"github.com/go-quicktest/qt"
    10  )
    11  
    12  const IfIndexLO = 1
    13  
    14  func TestAttachXDP(t *testing.T) {
    15  	testutils.SkipOnOldKernel(t, "5.9", "BPF_LINK_TYPE_XDP")
    16  
    17  	prog := mustLoadProgram(t, ebpf.XDP, 0, "")
    18  
    19  	_, err := AttachXDP(XDPOptions{
    20  		Program:   prog,
    21  		Interface: math.MaxInt,
    22  	})
    23  	qt.Assert(t, qt.IsNotNil(err))
    24  
    25  	l, err := AttachXDP(XDPOptions{
    26  		Program:   prog,
    27  		Interface: IfIndexLO,
    28  	})
    29  	qt.Assert(t, qt.IsNil(err))
    30  
    31  	testLink(t, l, prog)
    32  }