@@ -65,6 +65,12 @@ const (
6565 constEnableIPsec = "enable_ipsec"
6666)
6767
68+ const (
69+ tcxAnchorNone = "none"
70+ tcxAnchorHead = "head"
71+ tcxAnchorTail = "tail"
72+ )
73+
6874var log = logrus .WithField ("component" , "ebpf.FlowFetcher" )
6975var plog = logrus .WithField ("component" , "ebpf.PacketFetcher" )
7076
@@ -86,6 +92,8 @@ type FlowFetcher struct {
8692 rttKprobeLink link.Link
8793 egressTCXLink map [ifaces.InterfaceKey ]link.Link
8894 ingressTCXLink map [ifaces.InterfaceKey ]link.Link
95+ egressTCXAnchor link.Anchor
96+ ingressTCXAnchor link.Anchor
8997 networkEventsMonitoringLink link.Link
9098 nfNatManIPLink link.Link
9199 xfrmInputKretProbeLink link.Link
@@ -100,6 +108,8 @@ type FlowFetcher struct {
100108type FlowFetcherConfig struct {
101109 EnableIngress bool
102110 EnableEgress bool
111+ IngressTCXAnchor string
112+ EgressTCXAnchor string
103113 Debug bool
104114 Sampling int
105115 CacheMaxSize int
@@ -369,6 +379,8 @@ func NewFlowFetcher(cfg *FlowFetcherConfig, m *metrics.Metrics) (*FlowFetcher, e
369379 xfrmOutputKProbeLink : xfrmOutputKProbeLink ,
370380 egressTCXLink : egressTCXLink ,
371381 ingressTCXLink : ingressTCXLink ,
382+ egressTCXAnchor : tcxAnchor (cfg .EgressTCXAnchor ),
383+ ingressTCXAnchor : tcxAnchor (cfg .IngressTCXAnchor ),
372384 networkEventsMonitoringLink : networkEventsMonitoringLink ,
373385 lookupAndDeleteSupported : true , // this will be turned off later if found to be not supported
374386 useEbpfManager : cfg .UseEbpfManager ,
@@ -378,15 +390,15 @@ func NewFlowFetcher(cfg *FlowFetcherConfig, m *metrics.Metrics) (*FlowFetcher, e
378390
379391func (m * FlowFetcher ) AttachTCX (iface * ifaces.Interface ) error {
380392 if m .enableEgress {
381- egrLink , err := m .attachTCXOnDirection (iface , "Egress" , m .objects .BpfPrograms .TcxEgressFlowParse , cilium .AttachTCXEgress )
393+ egrLink , err := m .attachTCXOnDirection (iface , "Egress" , m .objects .BpfPrograms .TcxEgressFlowParse , cilium .AttachTCXEgress , m . egressTCXAnchor )
382394 if err != nil {
383395 return err
384396 }
385397 m .egressTCXLink [iface .InterfaceKey ] = egrLink
386398 }
387399
388400 if m .enableIngress {
389- ingLink , err := m .attachTCXOnDirection (iface , "Ingress" , m .objects .BpfPrograms .TcxIngressFlowParse , cilium .AttachTCXIngress )
401+ ingLink , err := m .attachTCXOnDirection (iface , "Ingress" , m .objects .BpfPrograms .TcxIngressFlowParse , cilium .AttachTCXIngress , m . ingressTCXAnchor )
390402 if err != nil {
391403 return err
392404 }
@@ -396,13 +408,14 @@ func (m *FlowFetcher) AttachTCX(iface *ifaces.Interface) error {
396408 return nil
397409}
398410
399- func (m * FlowFetcher ) attachTCXOnDirection (iface * ifaces.Interface , dirName string , prg * cilium.Program , attach cilium.AttachType ) (link.Link , error ) {
411+ func (m * FlowFetcher ) attachTCXOnDirection (iface * ifaces.Interface , dirName string , prg * cilium.Program , attach cilium.AttachType , anchor link. Anchor ) (link.Link , error ) {
400412 ilog := log .WithField ("iface" , iface )
401413
402414 lnk , err := link .AttachTCX (link.TCXOptions {
403415 Program : prg ,
404416 Attach : attach ,
405417 Interface : iface .Index ,
418+ Anchor : anchor ,
406419 })
407420 if err != nil {
408421 errPrefix := "Attach" + dirName
@@ -1357,6 +1370,8 @@ type PacketFetcher struct {
13571370 cacheMaxSize int
13581371 enableIngress bool
13591372 enableEgress bool
1373+ ingressAnchor link.Anchor
1374+ egressAnchor link.Anchor
13601375 egressTCXLink map [ifaces.InterfaceKey ]link.Link
13611376 ingressTCXLink map [ifaces.InterfaceKey ]link.Link
13621377 lookupAndDeleteSupported bool
@@ -1605,6 +1620,7 @@ func (p *PacketFetcher) AttachTCX(iface *ifaces.Interface) error {
16051620 Program : p .objects .BpfPrograms .TcxEgressPcaParse ,
16061621 Attach : cilium .AttachTCXEgress ,
16071622 Interface : iface .Index ,
1623+ Anchor : p .egressAnchor ,
16081624 })
16091625 if err != nil {
16101626 if errors .Is (err , fs .ErrExist ) {
@@ -1640,6 +1656,7 @@ func (p *PacketFetcher) AttachTCX(iface *ifaces.Interface) error {
16401656 Program : p .objects .BpfPrograms .TcxIngressPcaParse ,
16411657 Attach : cilium .AttachTCXIngress ,
16421658 Interface : iface .Index ,
1659+ Anchor : p .ingressAnchor ,
16431660 })
16441661 if err != nil {
16451662 if errors .Is (err , fs .ErrExist ) {
@@ -1944,3 +1961,16 @@ func configureFlowSpecVariables(spec *cilium.CollectionSpec, cfg *FlowFetcherCon
19441961
19451962 return nil
19461963}
1964+
1965+ func tcxAnchor (anchor string ) link.Anchor {
1966+ switch anchor {
1967+ case tcxAnchorHead :
1968+ return link .Head ()
1969+ case tcxAnchorTail :
1970+ return link .Tail ()
1971+ case tcxAnchorNone :
1972+ return nil
1973+ default :
1974+ return nil
1975+ }
1976+ }
0 commit comments