...
1 package link
2
3 import (
4 "fmt"
5
6 "github.com/cilium/ebpf"
7 )
8
9
10 type NetNsLink struct {
11 RawLink
12 }
13
14
15 func AttachNetNs(ns int, prog *ebpf.Program) (*NetNsLink, error) {
16 var attach ebpf.AttachType
17 switch t := prog.Type(); t {
18 case ebpf.FlowDissector:
19 attach = ebpf.AttachFlowDissector
20 case ebpf.SkLookup:
21 attach = ebpf.AttachSkLookup
22 default:
23 return nil, fmt.Errorf("can't attach %v to network namespace", t)
24 }
25
26 link, err := AttachRawLink(RawLinkOptions{
27 Target: ns,
28 Program: prog,
29 Attach: attach,
30 })
31 if err != nil {
32 return nil, err
33 }
34
35 return &NetNsLink{*link}, nil
36 }
37
View as plain text