Report persistent connections in states other than ESTABLISHED

This aligns the `/proc` connection tracking (persistent connections) with
conntrack (short-lived connections).
This commit is contained in:
Alfonso Acosta
2017-01-03 18:37:56 +00:00
parent 5c3ea83846
commit 7716d96810
3 changed files with 4 additions and 14 deletions

View File

@@ -9,17 +9,15 @@ import (
type ProcNet struct {
b []byte
c Connection
wantedState uint
bytesLocal, bytesRemote [16]byte
seen map[uint64]struct{}
}
// NewProcNet gives a new ProcNet parser.
func NewProcNet(b []byte, wantedState uint) *ProcNet {
func NewProcNet(b []byte) *ProcNet {
return &ProcNet{
b: b,
c: Connection{},
wantedState: wantedState,
seen: map[uint64]struct{}{},
}
}
@@ -40,16 +38,12 @@ again:
}
var (
local, remote, state, inode []byte
local, remote, inode []byte
)
_, b = nextField(b) // 'sl' column
local, b = nextField(b)
remote, b = nextField(b)
state, b = nextField(b)
if parseHex(state) != p.wantedState {
p.b = nextLine(b)
goto again
}
_, b = nextField(b) // 'st' column
_, b = nextField(b) // 'tx_queue' column
_, b = nextField(b) // 'rx_queue' column
_, b = nextField(b) // 'tr' column

View File

@@ -7,10 +7,6 @@ import (
"net"
)
const (
tcpEstablished = 1 // according to /include/net/tcp_states.h
)
// Connection is a (TCP) connection. The Proc struct might not be filled in.
type Connection struct {
Transport string

View File

@@ -61,7 +61,7 @@ func (s *linuxScanner) Connections(processes bool) (ConnIter, error) {
}
return &pnConnIter{
pn: NewProcNet(buf.Bytes(), tcpEstablished),
pn: NewProcNet(buf.Bytes()),
buf: buf,
procs: procs,
}, nil