瀏覽代碼

Merge pull request #130 from coroot/tcp_listen_sockets

remove `ipsByNs` cache
Nikolay Sivko 1 年之前
父節點
當前提交
ccd14a56e3
共有 1 個文件被更改,包括 5 次插入17 次删除
  1. 5 17
      containers/container.go

+ 5 - 17
containers/container.go

@@ -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
@@ -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{},
@@ -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
 	}
 }
@@ -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 {