From 434968e1d41e05dea89fa96d5652f9ed126a09a0 Mon Sep 17 00:00:00 2001
From: "Mohamed S. Mahmoud" <mmahmoud@redhat.com>
Date: Wed, 3 Jul 2024 12:20:02 -0400
Subject: [PATCH] NETOBSERV-1743: handle file exits error using TCx hooks and
 update FC (#363)

Signed-off-by: Mohamed Mahmoud <mmahmoud@redhat.com>
---
 pkg/ebpf/tracer.go | 28 ++++++++++++++++++++++++----
 1 file changed, 24 insertions(+), 4 deletions(-)

diff --git a/pkg/ebpf/tracer.go b/pkg/ebpf/tracer.go
index a4af0f2c..a2598c43 100644
--- a/pkg/ebpf/tracer.go
+++ b/pkg/ebpf/tracer.go
@@ -230,7 +230,12 @@ func (m *FlowFetcher) AttachTCX(iface ifaces.Interface) error {
 			Interface: iface.Index,
 		})
 		if err != nil {
-			return fmt.Errorf("failed to attach TCX egress: %w", err)
+			if errors.Is(err, fs.ErrExist) {
+				// The interface already has a TCX egress hook
+				log.WithField("iface", iface.Name).Debug("interface already has a TCX egress hook ignore")
+			} else {
+				return fmt.Errorf("failed to attach TCX egress: %w", err)
+			}
 		}
 		m.egressTCXLink[iface] = egrLink
 		ilog.WithField("interface", iface.Name).Debug("successfully attach egressTCX hook")
@@ -243,7 +248,12 @@ func (m *FlowFetcher) AttachTCX(iface ifaces.Interface) error {
 			Interface: iface.Index,
 		})
 		if err != nil {
-			return fmt.Errorf("failed to attach TCX ingress: %w", err)
+			if errors.Is(err, fs.ErrExist) {
+				// The interface already has a TCX ingress hook
+				log.WithField("iface", iface.Name).Debug("interface already has a TCX ingress hook ignore")
+			} else {
+				return fmt.Errorf("failed to attach TCX ingress: %w", err)
+			}
 		}
 		m.ingressTCXLink[iface] = ingLink
 		ilog.WithField("interface", iface.Name).Debug("successfully attach ingressTCX hook")
@@ -928,7 +938,12 @@ func (p *PacketFetcher) AttachTCX(iface ifaces.Interface) error {
 			Interface: iface.Index,
 		})
 		if err != nil {
-			return fmt.Errorf("failed to attach PCA TCX egress: %w", err)
+			if errors.Is(err, fs.ErrExist) {
+				// The interface already has a TCX egress hook
+				log.WithField("iface", iface.Name).Debug("interface already has a TCX PCA egress hook ignore")
+			} else {
+				return fmt.Errorf("failed to attach PCA TCX egress: %w", err)
+			}
 		}
 		p.egressTCXLink[iface] = egrLink
 		ilog.WithField("interface", iface.Name).Debug("successfully attach PCA egressTCX hook")
@@ -941,7 +956,12 @@ func (p *PacketFetcher) AttachTCX(iface ifaces.Interface) error {
 			Interface: iface.Index,
 		})
 		if err != nil {
-			return fmt.Errorf("failed to attach PCA TCX ingress: %w", err)
+			if errors.Is(err, fs.ErrExist) {
+				// The interface already has a TCX ingress hook
+				log.WithField("iface", iface.Name).Debug("interface already has a TCX PCA ingress hook ignore")
+			} else {
+				return fmt.Errorf("failed to attach PCA TCX ingress: %w", err)
+			}
 		}
 		p.ingressTCXLink[iface] = ingLink
 		ilog.WithField("interface", iface.Name).Debug("successfully attach PCA ingressTCX hook")
-- 
GitLab