Skip to content

Commit b8a6b55

Browse files
Port the sensors/tracing package on Windows.
Add platform specific and platform common code in sensors/tracing package Signed-off-by: Anadi Anadi <[email protected]>
1 parent 0055bd6 commit b8a6b55

File tree

5 files changed

+154
-82
lines changed

5 files changed

+154
-82
lines changed

pkg/sensors/tracing/lists_windows.go

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Authors of Tetragon
3+
4+
package tracing
5+
6+
import (
7+
"errors"
8+
9+
"github.com/cilium/tetragon/pkg/k8s/apis/cilium.io/v1alpha1"
10+
)
11+
12+
var (
13+
notSupportedWinErr = errors.New("not supported on windows")
14+
)
15+
16+
// isList checks if a value specifies a list, and if so it returns it (or nil if list does not exist)
17+
func isList(val string, lists []v1alpha1.ListSpec) (bool, *v1alpha1.ListSpec) {
18+
return false, nil
19+
}
20+
21+
func preValidateLists(lists []v1alpha1.ListSpec) (err error) {
22+
return notSupportedWinErr
23+
}
24+
25+
type listReader struct {
26+
lists []v1alpha1.ListSpec
27+
}
28+
29+
func (lr *listReader) Read(name string, ty uint32) ([]uint32, error) {
30+
return []uint32{}, notSupportedWinErr
31+
}
32+
33+
func getSyscallListSymbols(list *v1alpha1.ListSpec) ([]string, error) {
34+
return nil, notSupportedWinErr
35+
}

pkg/sensors/tracing/loader_windows.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package tracing
2+
3+
import "errors"
4+
5+
func createLoaderEvents() error {
6+
7+
return errors.New("not supported on windows")
8+
}

pkg/sensors/tracing/policyhandler.go

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

pkg/sensors/tracing/policyhandler_linux.go

Lines changed: 0 additions & 82 deletions
Original file line numberDiff line numberDiff line change
@@ -7,93 +7,11 @@ import (
77
"errors"
88
"fmt"
99

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"
1410
"github.com/cilium/tetragon/pkg/policyfilter"
1511
"github.com/cilium/tetragon/pkg/sensors"
16-
"github.com/cilium/tetragon/pkg/sensors/program"
1712
"github.com/cilium/tetragon/pkg/tracingpolicy"
1813
)
1914

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-
9715
func (h policyHandler) PolicyHandler(
9816
policy tracingpolicy.TracingPolicy,
9917
policyID policyfilter.PolicyID,
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
// SPDX-License-Identifier: Apache-2.0
2+
// Copyright Authors of Tetragon
3+
4+
package tracing
5+
6+
import (
7+
"errors"
8+
9+
"github.com/cilium/tetragon/pkg/policyfilter"
10+
"github.com/cilium/tetragon/pkg/sensors"
11+
"github.com/cilium/tetragon/pkg/tracingpolicy"
12+
)
13+
14+
func (h policyHandler) PolicyHandler(
15+
policy tracingpolicy.TracingPolicy,
16+
policyID policyfilter.PolicyID,
17+
) (sensors.SensorIface, error) {
18+
return nil, errors.New("not supported on windows")
19+
}

0 commit comments

Comments
 (0)