-
Notifications
You must be signed in to change notification settings - Fork 1
/
config.go
100 lines (80 loc) · 1.71 KB
/
config.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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package netflow
import (
"bytes"
"io"
"net/netip"
"time"
)
type (
EBPFProgramLoader interface {
LoadProgram() io.ReaderAt
}
Service interface {
SetErrorSink(sink ErrorSink)
SetEBPFProgramLoader(loader EBPFProgramLoader)
enableMocking(toMock bool)
}
Option interface {
ApplyTo(svc Service)
}
)
type EBPFProgramBytesLoader []byte
func (l EBPFProgramBytesLoader) LoadProgram() io.ReaderAt {
return bytes.NewReader(l)
}
type OptionFunc func(svc Service)
func (f OptionFunc) ApplyTo(svc Service) {
f(svc)
}
func WithErrorSink(sink ErrorSink) Option {
return OptionFunc(func(svc Service) {
svc.SetErrorSink(sink)
})
}
type ErrorSinkOption struct {
ErrorSink
}
func (s ErrorSinkOption) ApplyTo(svc Service) {
svc.SetErrorSink(s.ErrorSink)
}
func (s ErrorSinkOption) Apply(opt *epochOptions) {
opt.ErrorHandler = s.ErrorSink
}
func WithMockingEnabled(mockingEnabled bool) Option {
return OptionFunc(func(svc Service) {
svc.enableMocking(mockingEnabled)
})
}
func BoolP(val bool) *bool {
return &val
}
type RuleEntry struct {
Policy PacketPolicy
Destination IPPortProto `mapstructure:"dest"`
Monitor *bool
}
func (e RuleEntry) MonitorTraffic(defaultValue bool) bool {
if e.Monitor == nil {
return defaultValue
}
return *e.Monitor
}
type FirewallInterfaceConfig struct {
RemoveMemLock bool
DefaultPolicy PacketPolicy
Monitor bool
Rules []RuleEntry
}
type NATTargetSpec struct {
Destination IPPortProto `mapstructure:"dest"`
RedirectTo NATTarget
TranslateTo netip.Addr `mapstructure:"translateTo"`
}
type ConnTrackConfig struct {
HighWaterMark float64
CleanupWindow time.Duration
}
type NATTableSpec struct {
ConnTrack ConnTrackConfig
Translations []NATTargetSpec
}