Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion link/xdp.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,11 @@ func AttachXDP(opts XDPOptions) (Link, error) {
Flags: uint32(opts.Flags),
})

return &xdpLink{*rawLink}, err
if err != nil {
return nil, fmt.Errorf("failed to attach link: %w", err)
}

return &xdpLink{*rawLink}, nil
}

type xdpLink struct {
Expand Down
12 changes: 9 additions & 3 deletions link/xdp_test.go
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
package link

import (
"math"
"testing"

"github.com/cilium/ebpf"
"github.com/cilium/ebpf/internal/testutils"
"github.com/go-quicktest/qt"
)

const IfIndexLO = 1
Expand All @@ -14,13 +16,17 @@ func TestAttachXDP(t *testing.T) {

prog := mustLoadProgram(t, ebpf.XDP, 0, "")

_, err := AttachXDP(XDPOptions{
Program: prog,
Interface: math.MaxInt,
})
qt.Assert(t, qt.IsNotNil(err))

l, err := AttachXDP(XDPOptions{
Program: prog,
Interface: IfIndexLO,
})
if err != nil {
t.Fatal(err)
}
qt.Assert(t, qt.IsNil(err))

testLink(t, l, prog)
}