Skip to content

Commit

Permalink
Interface name wasn't populated yet so add func to find ifname
Browse files Browse the repository at this point in the history
Signed-off-by: Mohamed Mahmoud <[email protected]>
  • Loading branch information
msherif1234 committed Nov 27, 2023
1 parent 0c43b4a commit ae3b1e6
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
9 changes: 7 additions & 2 deletions pkg/flow/deduper.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"github.com/sirupsen/logrus"

"github.com/netobserv/netobserv-ebpf-agent/pkg/ebpf"
"github.com/netobserv/netobserv-ebpf-agent/pkg/utils"
)

var dlog = logrus.WithField("component", "flow/Deduper")
Expand Down Expand Up @@ -89,8 +90,11 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
*fwd = append(*fwd, r)
}
if mergeDup {
mergeEntry[r.Interface] = r.Id.Direction
ifName := utils.GetInterfaceName(r.Id.IfIndex)
mergeEntry[ifName] = r.Id.Direction
*fEntry.dupList = append(*fEntry.dupList, mergeEntry)
dlog.Debugf("add entry to merge list interface %s dir %d count %d",
ifName, r.Id.Direction, len(*fEntry.dupList))
}
return
}
Expand All @@ -106,7 +110,8 @@ func (c *deduperCache) checkDupe(r *Record, justMark, mergeDup bool, fwd *[]*Rec
expiryTime: timeNow().Add(c.expire),
}
if mergeDup {
mergeEntry[r.Interface] = r.Id.Direction
ifName := utils.GetInterfaceName(r.Id.IfIndex)
mergeEntry[ifName] = r.Id.Direction
r.DupList = append(r.DupList, mergeEntry)
e.dupList = &r.DupList
}
Expand Down
8 changes: 8 additions & 0 deletions pkg/utils/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,3 +91,11 @@ func utsnameStr[T int8 | uint8](in []T) string {
}
return string(out)
}

func GetInterfaceName(ifIndex uint32) string {
iface, err := net.InterfaceByIndex(int(ifIndex))
if err != nil {
return ""
}
return iface.Name
}

0 comments on commit ae3b1e6

Please sign in to comment.