@@ -62,6 +62,7 @@ type FlowFetcher struct {
6262 enableEgress bool
6363 pktDropsTracePoint link.Link
6464 rttFentryLink link.Link
65+ rttKprobeLink link.Link
6566}
6667
6768type FlowFetcherConfig struct {
@@ -141,13 +142,18 @@ func NewFlowFetcher(cfg *FlowFetcherConfig) (*FlowFetcher, error) {
141142 }
142143 }
143144
144- var rttFentryLink link.Link
145+ var rttFentryLink , rttKprobeLink link.Link
145146 if cfg .EnableRTT {
146147 rttFentryLink , err = link .AttachTracing (link.TracingOptions {
147148 Program : objects .BpfPrograms .TcpRcvFentry ,
148149 })
149150 if err != nil {
150- return nil , fmt .Errorf ("failed to attach the BPF program to tcpReceiveFentry: %w" , err )
151+ log .Warningf ("failed to attach the BPF program to tcpReceiveFentry: %v fallback to use kprobe" , err )
152+ // try to use kprobe for older kernels
153+ rttKprobeLink , err = link .Kprobe ("tcp_rcv_established" , objects .TcpRcvKprobe , nil )
154+ if err != nil {
155+ return nil , fmt .Errorf ("failed to attach the BPF program to tcpReceiveKprobe: %w" , err )
156+ }
151157 }
152158 }
153159
@@ -167,6 +173,7 @@ func NewFlowFetcher(cfg *FlowFetcherConfig) (*FlowFetcher, error) {
167173 enableEgress : cfg .EnableEgress ,
168174 pktDropsTracePoint : pktDropsLink ,
169175 rttFentryLink : rttFentryLink ,
176+ rttKprobeLink : rttKprobeLink ,
170177 }, nil
171178}
172179
@@ -300,6 +307,11 @@ func (m *FlowFetcher) Close() error {
300307 errs = append (errs , err )
301308 }
302309 }
310+ if m .rttKprobeLink != nil {
311+ if err := m .rttKprobeLink .Close (); err != nil {
312+ errs = append (errs , err )
313+ }
314+ }
303315 // m.ringbufReader.Read is a blocking operation, so we need to close the ring buffer
304316 // from another goroutine to avoid the system not being able to exit if there
305317 // isn't traffic in a given interface
@@ -460,6 +472,7 @@ func kernelSpecificLoadAndAssign(oldKernel bool, spec *ebpf.CollectionSpec) (Bpf
460472 EgressFlowParse * ebpf.Program `ebpf:"egress_flow_parse"`
461473 IngressFlowParse * ebpf.Program `ebpf:"ingress_flow_parse"`
462474 TCPRcvFentry * ebpf.Program `ebpf:"tcp_rcv_fentry"`
475+ TCPRcvKprobe * ebpf.Program `ebpf:"tcp_rcv_kprobe"`
463476 }
464477 type NewBpfObjects struct {
465478 NewBpfPrograms
@@ -485,6 +498,7 @@ func kernelSpecificLoadAndAssign(oldKernel bool, spec *ebpf.CollectionSpec) (Bpf
485498 objects .EgressFlowParse = newObjects .EgressFlowParse
486499 objects .IngressFlowParse = newObjects .IngressFlowParse
487500 objects .TcpRcvFentry = newObjects .TCPRcvFentry
501+ objects .TcpRcvKprobe = newObjects .TCPRcvKprobe
488502 objects .KfreeSkb = nil
489503 } else {
490504 if err := spec .LoadAndAssign (& objects , nil ); err != nil {
0 commit comments