Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Travis configuration for gardener.
# Travis configuration for tcp-info fast sidestream tool.
language: go
services:
- docker
Expand Down Expand Up @@ -37,7 +37,8 @@ cache:

install:
# Install dependencies
- GO_IMPORTS=$(go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}' ./... | sort | uniq | grep -v etl-gardener)
# This filters out all imports from the local project, and all "base" imports that don't contain slash.
- GO_IMPORTS=$(go list -f '{{join .Imports "\n"}}{{"\n"}}{{join .TestImports "\n"}}' ./... | sort | uniq | grep -e / | grep -v m-lab/tcp-info)
- go get -u -v -d $GO_IMPORTS
- go get github.com/golang/protobuf/protoc-gen-go/

Expand All @@ -55,7 +56,7 @@ script:
- cd $TRAVIS_BUILD_DIR

# To start, run all the non-integration tests.
- MODULES="inetdiag zstd"
- MODULES="inetdiag zstd nl-proto/tools"
- for module in $MODULES; do
COVER_PKGS=${COVER_PKGS}./$module/..., ;
done
Expand Down
58 changes: 25 additions & 33 deletions inetdiag/inetdiag.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ import (
"net"
"syscall"
"unsafe"

tcpinfo "github.com/m-lab/tcp-info/nl-proto"
)

// Constants from linux.
Expand All @@ -42,40 +44,30 @@ const (
SOCK_DIAG_BY_FAMILY = 20 // uapi/linux/sock_diag.h
)

// netinet/tcp.h
const (
_ = iota
TCP_ESTABLISHED = iota
TCP_SYN_SENT
TCP_SYN_RECV
TCP_FIN_WAIT1
TCP_FIN_WAIT2
TCP_TIME_WAIT
TCP_CLOSE
TCP_CLOSE_WAIT
TCP_LAST_ACK
TCP_LISTEN
TCP_CLOSING
)

// inet_diag.h
const (
TCP_ALL_STATES = 0xFFF
INET_DIAG_NONE = iota
INET_DIAG_MEMINFO
INET_DIAG_INFO
INET_DIAG_VEGASINFO
INET_DIAG_CONG
INET_DIAG_TOS
INET_DIAG_TCLASS
INET_DIAG_SKMEMINFO
INET_DIAG_SHUTDOWN
INET_DIAG_DCTCPINFO
INET_DIAG_PROTOCOL
INET_DIAG_SKV6ONLY
INET_DIAG_LOCALS
INET_DIAG_PEERS
INET_DIAG_PAD
INET_DIAG_MARK
INET_DIAG_BBRINFO
INET_DIAG_CLASS_ID
INET_DIAG_MD5SIG
INET_DIAG_MAX
)

var tcpStatesMap = map[uint8]string{
TCP_ESTABLISHED: "established",
TCP_SYN_SENT: "syn_sent",
TCP_SYN_RECV: "syn_recv",
TCP_FIN_WAIT1: "fin_wait1",
TCP_FIN_WAIT2: "fin_wait2",
TCP_TIME_WAIT: "time_wait",
TCP_CLOSE: "close",
TCP_CLOSE_WAIT: "close_wait",
TCP_LAST_ACK: "last_ack",
TCP_LISTEN: "listen",
TCP_CLOSING: "closing",
}

var diagFamilyMap = map[uint8]string{
syscall.AF_INET: "tcp",
syscall.AF_INET6: "tcp6",
Expand Down Expand Up @@ -121,7 +113,7 @@ func isIpv6(original [16]byte) bool {
}

func ipv4(original [16]byte) net.IP {
return net.IPv4(original[0], original[1], original[2], original[3])
return net.IPv4(original[0], original[1], original[2], original[3]).To4()
}

func ipv6(original [16]byte) net.IP {
Expand Down Expand Up @@ -183,7 +175,7 @@ type InetDiagMsg struct {
}

func (msg *InetDiagMsg) String() string {
return fmt.Sprintf("%s, %s, %s", diagFamilyMap[msg.IDiagFamily], tcpStatesMap[msg.IDiagState], msg.ID.String())
return fmt.Sprintf("%s, %s, %s", diagFamilyMap[msg.IDiagFamily], tcpinfo.TCPState(msg.IDiagState), msg.ID.String())
}

// rtaAlignOf round the length of a netlink route attribute up to align it
Expand Down
6 changes: 4 additions & 2 deletions inetdiag/inetdiag_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ import (
"unsafe"

"github.com/m-lab/tcp-info/inetdiag"

tcpinfo "github.com/m-lab/tcp-info/nl-proto"
)

// This is not exhaustive, but covers the basics. Integration tests will expose any more subtle
Expand All @@ -32,7 +34,7 @@ func TestParseInetDiagMsg(t *testing.T) {
if hdr.IDiagFamily != syscall.AF_INET {
t.Errorf("Failed %+v\n", hdr)
}
if hdr.IDiagState != inetdiag.TCP_SYN_RECV {
if tcpinfo.TCPState(hdr.IDiagState) != tcpinfo.TCPState_SYN_RECV {
t.Errorf("Failed %+v\n", hdr)
}

Expand All @@ -45,7 +47,7 @@ func TestSerialize(t *testing.T) {
v2 := inetdiag.NewInetDiagReqV2(syscall.AF_INET, 23, 0x0E)
data := v2.Serialize()
if v2.Len() != len(data) {
t.Error("That's odd")
t.Error(data, "should be length", v2.Len())
}
}

Expand Down
Loading