@@ -62,6 +62,7 @@ const (
62
62
rhNetworkEventsMonitoringHook = "rh_psample_sample_packet"
63
63
networkEventsMonitoringHook = "psample_sample_packet"
64
64
defaultNetworkEventsGroupID = 10
65
+ constEnableIPsec = "enable_ipsec"
65
66
)
66
67
67
68
var log = logrus .WithField ("component" , "ebpf.FlowFetcher" )
@@ -87,6 +88,8 @@ type FlowFetcher struct {
87
88
ingressTCXLink map [ifaces.Interface ]link.Link
88
89
networkEventsMonitoringLink link.Link
89
90
nfNatManIPLink link.Link
91
+ xfrmInputLink link.Link
92
+ xfrmOutputLink link.Link
90
93
lookupAndDeleteSupported bool
91
94
useEbpfManager bool
92
95
pinDir string
@@ -109,6 +112,7 @@ type FlowFetcherConfig struct {
109
112
EnablePktTranslation bool
110
113
UseEbpfManager bool
111
114
BpfManBpfFSPath string
115
+ EnableIPsecTracker bool
112
116
FilterConfig []* FilterConfig
113
117
}
114
118
@@ -120,7 +124,7 @@ type variablesMapping struct {
120
124
// nolint:golint,cyclop
121
125
func NewFlowFetcher (cfg * FlowFetcherConfig ) (* FlowFetcher , error ) {
122
126
var pktDropsLink , networkEventsMonitoringLink , rttFentryLink , rttKprobeLink link.Link
123
- var nfNatManIPLink link.Link
127
+ var nfNatManIPLink , xfrmInputLink , xfrmOutputLink link.Link
124
128
var err error
125
129
objects := ebpf.BpfObjects {}
126
130
var pinDir string
@@ -243,6 +247,19 @@ func NewFlowFetcher(cfg *FlowFetcherConfig) (*FlowFetcher, error) {
243
247
return nil , fmt .Errorf ("failed to attach the BPF program to nat_manip kprobe: %w" , err )
244
248
}
245
249
}
250
+
251
+ if cfg .EnableIPsecTracker {
252
+ xfrmInputLink , err = link .Kretprobe ("xfrm_input" , objects .XfrmInputKprobe , nil )
253
+ if err != nil {
254
+ log .Warningf ("failed to attach the BPF program to xfrm_input: %v" , err )
255
+ return nil , fmt .Errorf ("failed to attach the BPF program to xfrm_input: %w" , err )
256
+ }
257
+ xfrmOutputLink , err = link .Kretprobe ("xfrm_output" , objects .XfrmOutputKprobe , nil )
258
+ if err != nil {
259
+ log .Warningf ("failed to attach the BPF program to xfrm_output: %v" , err )
260
+ return nil , fmt .Errorf ("failed to attach the BPF program to xfrm_output: %w" , err )
261
+ }
262
+ }
246
263
} else {
247
264
pinDir = cfg .BpfManBpfFSPath
248
265
opts := & cilium.LoadPinOptions {
@@ -325,6 +342,8 @@ func NewFlowFetcher(cfg *FlowFetcherConfig) (*FlowFetcher, error) {
325
342
rttFentryLink : rttFentryLink ,
326
343
rttKprobeLink : rttKprobeLink ,
327
344
nfNatManIPLink : nfNatManIPLink ,
345
+ xfrmInputLink : xfrmInputLink ,
346
+ xfrmOutputLink : xfrmOutputLink ,
328
347
egressTCXLink : map [ifaces.Interface ]link.Link {},
329
348
ingressTCXLink : map [ifaces.Interface ]link.Link {},
330
349
networkEventsMonitoringLink : networkEventsMonitoringLink ,
@@ -703,6 +722,18 @@ func (m *FlowFetcher) Close() error {
703
722
errs = append (errs , err )
704
723
}
705
724
}
725
+
726
+ if m .xfrmInputLink != nil {
727
+ if err := m .xfrmInputLink .Close (); err != nil {
728
+ errs = append (errs , err )
729
+ }
730
+ }
731
+
732
+ if m .xfrmOutputLink != nil {
733
+ if err := m .xfrmOutputLink .Close (); err != nil {
734
+ errs = append (errs , err )
735
+ }
736
+ }
706
737
// m.ringbufReader.Read is a blocking operation, so we need to close the ring buffer
707
738
// from another goroutine to avoid the system not being able to exit if there
708
739
// isn't traffic in a given interface
@@ -1063,6 +1094,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1063
1094
TcxEgressPcaParse * cilium.Program `ebpf:"tcx_egress_pca_parse"`
1064
1095
TcxIngressPcaParse * cilium.Program `ebpf:"tcx_ingress_pca_parse"`
1065
1096
TrackNatManipPkt * cilium.Program `ebpf:"track_nat_manip_pkt"`
1097
+ XfrmInputKprobe * cilium.Program `ebpf:"xfrm_input_kprobe"`
1098
+ XfrmOutputKprobe * cilium.Program `ebpf:"xfrm_output_kprobe"`
1066
1099
}
1067
1100
type newBpfObjects struct {
1068
1101
newBpfPrograms
@@ -1088,6 +1121,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1088
1121
TcxEgressPcaParse : newObjects .TcxEgressPcaParse ,
1089
1122
TcxIngressPcaParse : newObjects .TcxIngressPcaParse ,
1090
1123
TrackNatManipPkt : newObjects .TrackNatManipPkt ,
1124
+ XfrmInputKprobe : newObjects .XfrmInputKprobe ,
1125
+ XfrmOutputKprobe : newObjects .XfrmOutputKprobe ,
1091
1126
TcpRcvKprobe : nil ,
1092
1127
TcpRcvFentry : nil ,
1093
1128
KfreeSkb : nil ,
@@ -1116,6 +1151,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1116
1151
TcxIngressPcaParse * cilium.Program `ebpf:"tcx_ingress_pca_parse"`
1117
1152
TCPRcvKprobe * cilium.Program `ebpf:"tcp_rcv_kprobe"`
1118
1153
TrackNatManipPkt * cilium.Program `ebpf:"track_nat_manip_pkt"`
1154
+ XfrmInputKprobe * cilium.Program `ebpf:"xfrm_input_kprobe"`
1155
+ XfrmOutputKprobe * cilium.Program `ebpf:"xfrm_output_kprobe"`
1119
1156
}
1120
1157
type newBpfObjects struct {
1121
1158
newBpfPrograms
@@ -1141,6 +1178,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1141
1178
TcxIngressPcaParse : newObjects .TcxIngressPcaParse ,
1142
1179
TcpRcvKprobe : newObjects .TCPRcvKprobe ,
1143
1180
TrackNatManipPkt : newObjects .TrackNatManipPkt ,
1181
+ XfrmInputKprobe : newObjects .XfrmInputKprobe ,
1182
+ XfrmOutputKprobe : newObjects .XfrmOutputKprobe ,
1144
1183
TcpRcvFentry : nil ,
1145
1184
KfreeSkb : nil ,
1146
1185
RhNetworkEventsMonitoring : nil ,
@@ -1168,6 +1207,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1168
1207
TcxIngressPcaParse * cilium.Program `ebpf:"tcx_ingress_pca_parse"`
1169
1208
TCPRcvFentry * cilium.Program `ebpf:"tcp_rcv_fentry"`
1170
1209
TrackNatManipPkt * cilium.Program `ebpf:"track_nat_manip_pkt"`
1210
+ XfrmInputKprobe * cilium.Program `ebpf:"xfrm_input_kprobe"`
1211
+ XfrmOutputKprobe * cilium.Program `ebpf:"xfrm_output_kprobe"`
1171
1212
}
1172
1213
type newBpfObjects struct {
1173
1214
newBpfPrograms
@@ -1193,6 +1234,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1193
1234
TcxIngressPcaParse : newObjects .TcxIngressPcaParse ,
1194
1235
TcpRcvFentry : newObjects .TCPRcvFentry ,
1195
1236
TrackNatManipPkt : newObjects .TrackNatManipPkt ,
1237
+ XfrmInputKprobe : newObjects .XfrmInputKprobe ,
1238
+ XfrmOutputKprobe : newObjects .XfrmOutputKprobe ,
1196
1239
TcpRcvKprobe : nil ,
1197
1240
KfreeSkb : nil ,
1198
1241
RhNetworkEventsMonitoring : nil ,
@@ -1222,6 +1265,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1222
1265
TCPRcvKprobe * cilium.Program `ebpf:"tcp_rcv_kprobe"`
1223
1266
KfreeSkb * cilium.Program `ebpf:"kfree_skb"`
1224
1267
TrackNatManipPkt * cilium.Program `ebpf:"track_nat_manip_pkt"`
1268
+ XfrmInputKprobe * cilium.Program `ebpf:"xfrm_input_kprobe"`
1269
+ XfrmOutputKprobe * cilium.Program `ebpf:"xfrm_output_kprobe"`
1225
1270
}
1226
1271
type newBpfObjects struct {
1227
1272
newBpfPrograms
@@ -1248,6 +1293,8 @@ func kernelSpecificLoadAndAssign(oldKernel, rtKernel, supportNetworkEvents bool,
1248
1293
TcpRcvKprobe : newObjects .TCPRcvKprobe ,
1249
1294
KfreeSkb : newObjects .KfreeSkb ,
1250
1295
TrackNatManipPkt : newObjects .TrackNatManipPkt ,
1296
+ XfrmInputKprobe : newObjects .XfrmInputKprobe ,
1297
+ XfrmOutputKprobe : newObjects .XfrmOutputKprobe ,
1251
1298
RhNetworkEventsMonitoring : nil ,
1252
1299
},
1253
1300
BpfMaps : ebpf.BpfMaps {
@@ -1838,6 +1885,10 @@ func configureFlowSpecVariables(spec *cilium.CollectionSpec, cfg *FlowFetcherCon
1838
1885
if cfg .EnablePktTranslation {
1839
1886
enablePktTranslation = 1
1840
1887
}
1888
+ enableIPsec := 0
1889
+ if cfg .EnableIPsecTracker {
1890
+ enableIPsec = 1
1891
+ }
1841
1892
// When adding constants here, remember to delete them in NewPacketFetcher
1842
1893
variables := []variablesMapping {
1843
1894
{constSampling , uint32 (cfg .Sampling )},
@@ -1850,6 +1901,7 @@ func configureFlowSpecVariables(spec *cilium.CollectionSpec, cfg *FlowFetcherCon
1850
1901
{constEnableNetworkEventsMonitoring , uint8 (enableNetworkEventsMonitoring )},
1851
1902
{constNetworkEventsMonitoringGroupID , uint8 (networkEventsMonitoringGroupID )},
1852
1903
{constEnablePktTranslation , uint8 (enablePktTranslation )},
1904
+ {constEnableIPsec , uint8 (enableIPsec )},
1853
1905
}
1854
1906
1855
1907
for _ , mapping := range variables {
0 commit comments