Skip to content

Commit

Permalink
Merge pull request #130 from coroot/tcp_listen_sockets
Browse files Browse the repository at this point in the history
remove `ipsByNs` cache
  • Loading branch information
def authored Oct 1, 2024
2 parents 93f0d1f + f4f3b0d commit ccd14a5
Showing 1 changed file with 5 additions and 17 deletions.
22 changes: 5 additions & 17 deletions containers/container.go
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,6 @@ type Container struct {
delaysLock sync.Mutex

listens map[netaddr.IPPort]map[uint32]*ListenDetails
ipsByNs map[string][]netaddr.IP

connectsSuccessful map[AddrPair]*ConnectionStats // dst:actual_dst -> count
connectsFailed map[netaddr.IPPort]int64 // dst -> count
Expand Down Expand Up @@ -164,7 +163,6 @@ func NewContainer(id ContainerID, cg *cgroup.Cgroup, md *ContainerMetadata, host
delaysByPid: map[uint32]Delays{},

listens: map[netaddr.IPPort]map[uint32]*ListenDetails{},
ipsByNs: map[string][]netaddr.IP{},

connectsSuccessful: map[AddrPair]*ConnectionStats{},
connectsFailed: map[netaddr.IPPort]int64{},
Expand Down Expand Up @@ -486,16 +484,12 @@ func (c *Container) onListenOpen(pid uint32, addr netaddr.IPPort, safe bool) {
return
}
defer ns.Close()
nsId := ns.UniqueId()
ips, ok := c.ipsByNs[nsId]
if !ok {
if ips, err = proc.GetNsIps(ns); err != nil {
klog.Warningln(err)
} else {
klog.Infof("got IPs %s for %s", ips, nsId)
c.ipsByNs[nsId] = ips
}
ips, err := proc.GetNsIps(ns)
if err != nil {
klog.Warningln(err)
return
}
klog.Infof("got IPs %s for %s", ips, ns.UniqueId())
details.NsIPs = ips
}
}
Expand Down Expand Up @@ -1024,12 +1018,6 @@ func (c *Container) gc(now time.Time) {
seenNamespaces[p.NetNsId()] = true
}

for ns := range c.ipsByNs {
if !seenNamespaces[ns] {
delete(c.ipsByNs, ns)
}
}

c.revalidateListens(now, listens)

for srcDst, conn := range c.connectionsActive {
Expand Down

0 comments on commit ccd14a5

Please sign in to comment.