-
Notifications
You must be signed in to change notification settings - Fork 10
/
tailcall_route.go
77 lines (66 loc) · 2.32 KB
/
tailcall_route.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
package manager
import (
"fmt"
"github.com/cilium/ebpf"
)
// TailCallRoute - A tail call route defines how tail calls should be routed between eBPF programs.
//
// The provided eBPF program will be inserted in the provided eBPF program array, at the provided key. The eBPF program
// can be provided by its function name or by its *ebpf.Program representation.
type TailCallRoute struct {
// ProgArrayName - Name of the BPF_MAP_TYPE_PROG_ARRAY map as defined in its section SEC("maps/[ProgArray]")
ProgArrayName string
// Key - Key at which the program will be inserted in the ProgArray map
Key uint32
// ProbeIdentificationPair - Selector of the program to insert in the ProgArray map
ProbeIdentificationPair ProbeIdentificationPair
// Program - Program to insert in the ProgArray map
Program *ebpf.Program
}
// UpdateTailCallRoutes - Update one or multiple program arrays so that the provided keys point to the provided programs.
func (m *Manager) UpdateTailCallRoutes(router ...TailCallRoute) error {
m.stateLock.Lock()
defer m.stateLock.Unlock()
if m.collection == nil || m.state < initialized {
return ErrManagerNotInitialized
}
for _, route := range router {
if err := m.updateTailCallRoute(route); err != nil {
return err
}
}
return nil
}
// updateTailCallRoute - Update a program array so that the provided key point to the provided program.
func (m *Manager) updateTailCallRoute(route TailCallRoute) error {
// Select the routing map
routingMap, found, err := m.getMap(route.ProgArrayName)
if err != nil {
return err
}
if !found {
return fmt.Errorf("couldn't find routing map %s: %w", route.ProgArrayName, ErrUnknownSection)
}
// Get file descriptor of the routed program
var fd uint32
if route.Program != nil {
fd = uint32(route.Program.FD())
} else {
progs, found, err := m.getProgram(route.ProbeIdentificationPair)
if err != nil {
return err
}
if !found || len(progs) == 0 {
return fmt.Errorf("couldn't find program %v: %w", route.ProbeIdentificationPair, ErrUnknownSectionOrFuncName)
}
if progs[0] == nil {
return fmt.Errorf("the program that you are trying to route to is empty")
}
fd = uint32(progs[0].FD())
}
// Insert tail call
if err = routingMap.Put(route.Key, fd); err != nil {
return fmt.Errorf("couldn't update routing map %s: %w", route.ProgArrayName, err)
}
return nil
}