summaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
authorJeff Bean <bean@uber.com>2018-06-27 10:31:26 -0700
committerJeff Bean <bean@uber.com>2018-06-27 10:31:26 -0700
commit00a3b726dd9f81474df867b834d67b25e9d6ade4 (patch)
treed6eb0f31a6ba0ac571177934bdb26e07de37e115 /server
parent29d0e59af48c843b686f6a77c3cb7f34fc59568d (diff)
Fixing staticcheck errors from linux files
Diffstat (limited to 'server')
-rw-r--r--server/sockopt_linux.go22
-rw-r--r--server/sockopt_linux_test.go4
2 files changed, 16 insertions, 10 deletions
diff --git a/server/sockopt_linux.go b/server/sockopt_linux.go
index 336caf15..9fe02ba5 100644
--- a/server/sockopt_linux.go
+++ b/server/sockopt_linux.go
@@ -32,10 +32,12 @@ const (
type tcpmd5sig struct {
ss_family uint16
ss [126]byte
- pad1 uint16
- keylen uint16
- pad2 uint32
- key [80]byte
+ // padding the struct
+ _ uint16
+ keylen uint16
+ // padding the struct
+ _ uint32
+ key [80]byte
}
func buildTcpMD5Sig(address string, key string) (tcpmd5sig, error) {
@@ -66,10 +68,11 @@ func setsockoptTcpMD5Sig(fd int, address string, key string) error {
func SetTcpMD5SigSockopt(l *net.TCPListener, address string, key string) error {
fi, _, err := extractFileAndFamilyFromTCPListener(l)
- defer fi.Close()
if err != nil {
return err
}
+ defer fi.Close()
+
return setsockoptTcpMD5Sig(int(fi.Fd()), address, key)
}
@@ -85,19 +88,21 @@ func setsockoptIpTtl(fd int, family int, value int) error {
func SetListenTcpTTLSockopt(l *net.TCPListener, ttl int) error {
fi, family, err := extractFileAndFamilyFromTCPListener(l)
- defer fi.Close()
if err != nil {
return err
}
+ defer fi.Close()
+
return setsockoptIpTtl(int(fi.Fd()), family, ttl)
}
func SetTcpTTLSockopt(conn *net.TCPConn, ttl int) error {
fi, family, err := extractFileAndFamilyFromTCPConn(conn)
- defer fi.Close()
if err != nil {
return err
}
+ defer fi.Close()
+
return setsockoptIpTtl(int(fi.Fd()), family, ttl)
}
@@ -113,10 +118,11 @@ func setsockoptIpMinTtl(fd int, family int, value int) error {
func SetTcpMinTTLSockopt(conn *net.TCPConn, ttl int) error {
fi, family, err := extractFileAndFamilyFromTCPConn(conn)
- defer fi.Close()
if err != nil {
return err
}
+ defer fi.Close()
+
return setsockoptIpMinTtl(int(fi.Fd()), family, ttl)
}
diff --git a/server/sockopt_linux_test.go b/server/sockopt_linux_test.go
index 3730672c..a08e7fc7 100644
--- a/server/sockopt_linux_test.go
+++ b/server/sockopt_linux_test.go
@@ -42,7 +42,7 @@ func Test_buildTcpMD5Sig(t *testing.T) {
buf2 := []uint8{2, 0, 0, 0, 1, 2, 3, 4, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 5, 0, 0, 0, 0, 0, 104, 101, 108, 108, 111, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0}
- if bytes.Compare(buf1, buf2) == 0 {
+ if bytes.Equal(buf1, buf2) {
t.Log("OK")
} else {
t.Error("Something wrong v4")
@@ -62,7 +62,7 @@ func Test_buildTcpMD5Sigv6(t *testing.T) {
buf2[0] = syscall.AF_INET6
- if bytes.Compare(buf1, buf2) == 0 {
+ if bytes.Equal(buf1, buf2) {
t.Log("OK")
} else {
t.Error("Something wrong v6")