From c627802664e795832e4327d6912c595cb86fa68d Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Sun, 5 Aug 2018 12:53:21 +0000 Subject: [PATCH] Refactor: remove some code that is now unnecessary - don't need another wrapper round `conntrack.Connections()` - logPipe() was only for the command-line conntrack - nobody closes the `event` chan now, so no need to pre-check for quit --- probe/endpoint/conntrack.go | 35 ++--------------------------------- 1 file changed, 2 insertions(+), 33 deletions(-) diff --git a/probe/endpoint/conntrack.go b/probe/endpoint/conntrack.go index 02a1dc93d..c49e409da 100644 --- a/probe/endpoint/conntrack.go +++ b/probe/endpoint/conntrack.go @@ -1,9 +1,7 @@ package endpoint import ( - "bufio" "fmt" - "io" "io/ioutil" "path/filepath" "sync" @@ -102,20 +100,10 @@ func (c *conntrackWalker) clearFlows() { c.activeFlows = map[uint32]conntrack.Conn{} } -func logPipe(prefix string, reader io.Reader) { - scanner := bufio.NewScanner(reader) - for scanner.Scan() { - log.Error(prefix, scanner.Text()) - } - if err := scanner.Err(); err != nil { - log.Error(prefix, err) - } -} - func (c *conntrackWalker) run() { - existingFlows, err := c.existingConnections() + existingFlows, err := conntrack.ConnectionsSize(c.bufferSize) if err != nil { - log.Errorf("conntrack existingConnections error: %v", err) + log.Errorf("conntrack Connections error: %v", err) return } for _, flow := range existingFlows { @@ -128,17 +116,6 @@ func (c *conntrackWalker) run() { return } - c.Lock() - // We may have stopped in the mean time, - // so check to see if the channel is open - // under the lock. - select { - default: - case <-c.quit: - return - } - c.Unlock() - defer log.Infof("conntrack exiting") // Handle conntrack events from netlink socket @@ -156,14 +133,6 @@ func (c *conntrackWalker) run() { } } -func (c *conntrackWalker) existingConnections() ([]conntrack.Conn, error) { - flows, err := conntrack.ConnectionsSize(c.bufferSize) - if err != nil { - return []conntrack.Conn{}, err - } - return flows, nil -} - func (c *conntrackWalker) stop() { c.Lock() defer c.Unlock()