@@ -7,93 +7,11 @@ import (
7
7
"errors"
8
8
"fmt"
9
9
10
- "github.com/cilium/ebpf"
11
- "github.com/cilium/tetragon/pkg/eventhandler"
12
- "github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1"
13
- "github.com/cilium/tetragon/pkg/policyconf"
14
10
"github.com/cilium/tetragon/pkg/policyfilter"
15
11
"github.com/cilium/tetragon/pkg/sensors"
16
- "github.com/cilium/tetragon/pkg/sensors/program"
17
12
"github.com/cilium/tetragon/pkg/tracingpolicy"
18
13
)
19
14
20
- type policyHandler struct {}
21
-
22
- func init () {
23
- sensors .RegisterPolicyHandlerAtInit ("tracing" , policyHandler {})
24
- }
25
-
26
- type policyInfo struct {
27
- name string
28
- namespace string
29
- policyID policyfilter.PolicyID
30
- customHandler eventhandler.Handler
31
- policyConf * program.Map
32
- specOpts * specOptions
33
- }
34
-
35
- func newPolicyInfo (
36
- policy tracingpolicy.TracingPolicy ,
37
- policyID policyfilter.PolicyID ,
38
- ) (* policyInfo , error ) {
39
- namespace := ""
40
- if tpn , ok := policy .(tracingpolicy.TracingPolicyNamespaced ); ok {
41
- namespace = tpn .TpNamespace ()
42
- }
43
-
44
- return newPolicyInfoFromSpec (
45
- namespace ,
46
- policy .TpName (),
47
- policyID ,
48
- policy .TpSpec (),
49
- eventhandler .GetCustomEventhandler (policy ),
50
- )
51
-
52
- }
53
-
54
- func newPolicyInfoFromSpec (
55
- namespace , name string ,
56
- policyID policyfilter.PolicyID ,
57
- spec * v1alpha1.TracingPolicySpec ,
58
- customHandler eventhandler.Handler ,
59
- ) (* policyInfo , error ) {
60
- opts , err := getSpecOptions (spec .Options )
61
- if err != nil {
62
- return nil , err
63
- }
64
- return & policyInfo {
65
- name : name ,
66
- namespace : namespace ,
67
- policyID : policyID ,
68
- customHandler : customHandler ,
69
- policyConf : nil ,
70
- specOpts : opts ,
71
- }, nil
72
- }
73
-
74
- func (pi * policyInfo ) policyConfMap (prog * program.Program ) * program.Map {
75
- if pi .policyConf != nil {
76
- return program .MapUserFrom (pi .policyConf )
77
- }
78
- pi .policyConf = program .MapBuilderPolicy ("policy_conf" , prog )
79
- prog .MapLoad = append (prog .MapLoad , & program.MapLoad {
80
- Index : 0 ,
81
- Name : policyconf .PolicyConfMapName ,
82
- Load : func (m * ebpf.Map , _ string , _ uint32 ) error {
83
- mode := policyconf .EnforceMode
84
- if pi .specOpts != nil {
85
- mode = pi .specOpts .policyMode
86
- }
87
- conf := policyconf.PolicyConf {
88
- Mode : mode ,
89
- }
90
- key := uint32 (0 )
91
- return m .Update (key , & conf , ebpf .UpdateAny )
92
- },
93
- })
94
- return pi .policyConf
95
- }
96
-
97
15
func (h policyHandler ) PolicyHandler (
98
16
policy tracingpolicy.TracingPolicy ,
99
17
policyID policyfilter.PolicyID ,
0 commit comments