From 730501c3b18687c6257d789667cde20d680ba000 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Apr 2020 16:50:41 +0200 Subject: [PATCH 01/10] Install libnetfilter-queue-dev on linux --- .travis.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/.travis.yml b/.travis.yml index ae28e8da..43da632f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -14,6 +14,13 @@ branches: - /^feature\/travis\/.+$/ # feature/travis/* - /^fix\/travis\/.+$/ # fix/travis/* +addons: + apt: + update: true + +before_install: + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -y install libnetfilter-queue-dev + install: - go get -d -u github.com/golang/dep - go install github.com/golang/dep/cmd/dep From fceec09790a9ba0aba79961ed08395bde423c837 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Apr 2020 16:50:58 +0200 Subject: [PATCH 02/10] Always run golangci-lint, as the service is going offline --- test | 30 +++++++++++------------------- 1 file changed, 11 insertions(+), 19 deletions(-) diff --git a/test b/test index 003aa41e..45eb276f 100755 --- a/test +++ b/test @@ -4,7 +4,6 @@ warnings=0 errors=0 scripted=0 goUp="\\e[1A" -all=0 fullTestFlags="-short" install=0 @@ -99,7 +98,6 @@ while true; do shift 1 ;; "all") - all=1 fullTestFlags="" shift 1 ;; @@ -119,10 +117,8 @@ if [[ $install -eq 1 ]]; then echo "installing dependencies..." echo "$ go get -u golang.org/x/lint/golint" go get -u golang.org/x/lint/golint - if [[ $all -eq 1 ]]; then - echo "$ go get -u github.com/golangci/golangci-lint/cmd/golangci-lint" - go get -u github.com/golangci/golangci-lint/cmd/golangci-lint - fi + echo "$ go get -u github.com/golangci/golangci-lint/cmd/golangci-lint" + go get -u github.com/golangci/golangci-lint/cmd/golangci-lint exit 0 fi @@ -141,16 +137,14 @@ if [[ $(which golint) == "" ]]; then echo "or run: ./test install" exit 1 fi -if [[ $all -eq 1 ]]; then - if [[ $(which golangci-lint) == "" ]]; then - echo "golangci-lint command not found" - echo "install locally with: go get -u github.com/golangci/golangci-lint/cmd/golangci-lint" - echo "or run: ./test install all" - echo "" - echo "hint: install for CI with: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin vX.Y.Z" - echo "don't forget to specify the version you want" - exit 1 - fi +if [[ $(which golangci-lint) == "" ]]; then + echo "golangci-lint command not found" + echo "install locally with: go get -u github.com/golangci/golangci-lint/cmd/golangci-lint" + echo "or run: ./test install all" + echo "" + echo "hint: install for CI with: curl -sfL https://raw.githubusercontent.com/golangci/golangci-lint/master/install.sh | sh -s -- -b $(go env GOPATH)/bin vX.Y.Z" + echo "don't forget to specify the version you want" + exit 1 fi # target selection @@ -179,9 +173,7 @@ for package in $packages; do checkformat $package run golint -set_exit_status -min_confidence 1.0 $package run go vet $package - if [[ $all -eq 1 ]]; then - run golangci-lint run $GOPATH/src/$package - fi + run golangci-lint run $GOPATH/src/$package run go test -cover $fullTestFlags $package done From 3840ab470c528b8cff57af932311e14f60d4516a Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Apr 2020 16:56:26 +0200 Subject: [PATCH 03/10] Fix install cmd --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 43da632f..4153e657 100644 --- a/.travis.yml +++ b/.travis.yml @@ -19,7 +19,7 @@ addons: update: true before_install: - - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -y install libnetfilter-queue-dev + - if [ "$TRAVIS_OS_NAME" = "linux" ]; then sudo apt-get -y install libnetfilter-queue-dev; fi install: - go get -d -u github.com/golang/dep From 2b6fbd2bfc8860ad6dad6003df6b8b075a12f254 Mon Sep 17 00:00:00 2001 From: Daniel Date: Thu, 9 Apr 2020 17:06:08 +0200 Subject: [PATCH 04/10] Skip test that fails in CI --- netenv/dbus_linux_test.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/netenv/dbus_linux_test.go b/netenv/dbus_linux_test.go index c9e4369f..f69bcd2c 100644 --- a/netenv/dbus_linux_test.go +++ b/netenv/dbus_linux_test.go @@ -6,6 +6,10 @@ import ( ) func TestDbus(t *testing.T) { + if testing.Short() { + t.Skip("skipping test in short mode because it fails in the CI") + } + if _, err := os.Stat("/var/run/dbus/system_bus_socket"); os.IsNotExist(err) { t.Logf("skipping dbus tests, as dbus does not seem to be installed: %s", err) return From 541cf702adc63dc5b8d6cdc236520ea609c1ffa9 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 10:50:43 +0200 Subject: [PATCH 05/10] Explicitly mark the nfqueue package for building on linux --- firewall/interception/nfqueue/doc.go | 2 ++ firewall/interception/nfqueue/multiqueue.go | 2 ++ firewall/interception/nfqueue/nfqueue.go | 2 ++ firewall/interception/nfqueue/packet.go | 2 ++ 4 files changed, 8 insertions(+) diff --git a/firewall/interception/nfqueue/doc.go b/firewall/interception/nfqueue/doc.go index 13be9112..9fc4ab21 100644 --- a/firewall/interception/nfqueue/doc.go +++ b/firewall/interception/nfqueue/doc.go @@ -1,2 +1,4 @@ +// +build linux + // Package nfqueue provides network interception capabilities on linux via iptables nfqueue. package nfqueue diff --git a/firewall/interception/nfqueue/multiqueue.go b/firewall/interception/nfqueue/multiqueue.go index 884947bd..ce60b8f1 100644 --- a/firewall/interception/nfqueue/multiqueue.go +++ b/firewall/interception/nfqueue/multiqueue.go @@ -1,3 +1,5 @@ +// +build linux + package nfqueue // suspended for now diff --git a/firewall/interception/nfqueue/nfqueue.go b/firewall/interception/nfqueue/nfqueue.go index fc238744..22ab3bca 100644 --- a/firewall/interception/nfqueue/nfqueue.go +++ b/firewall/interception/nfqueue/nfqueue.go @@ -1,3 +1,5 @@ +// +build linux + package nfqueue /* diff --git a/firewall/interception/nfqueue/packet.go b/firewall/interception/nfqueue/packet.go index 98b214c3..cfd948b1 100644 --- a/firewall/interception/nfqueue/packet.go +++ b/firewall/interception/nfqueue/packet.go @@ -1,3 +1,5 @@ +// +build linux + package nfqueue import ( From ddc01e648f64ed2d732588a60c01d045ed4a39c7 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 10:50:55 +0200 Subject: [PATCH 06/10] Fix windows mock --- netenv/dbus_linux_mock.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/netenv/dbus_linux_mock.go b/netenv/dbus_linux_mock.go index 1c3a7ebe..cb0084c3 100644 --- a/netenv/dbus_linux_mock.go +++ b/netenv/dbus_linux_mock.go @@ -7,6 +7,6 @@ func getNameserversFromDbus() ([]Nameserver, error) { return nameservers, nil } -func getConnectivityStateFromDbus() (uint8, error) { +func getConnectivityStateFromDbus() (OnlineStatus, error) { return StatusUnknown, nil } From fd4f059ebba6993b1d3eb046041383ecc2ae9606 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 13:18:37 +0200 Subject: [PATCH 07/10] Fix windowskext linter errors --- firewall/interception/interception_linux.go | 6 ++-- firewall/interception/interception_windows.go | 8 ++---- firewall/interception/windowskext/doc.go | 2 +- firewall/interception/windowskext/handler.go | 28 +++++++++---------- .../interception/windowskext/test/main.go | 14 +++++++--- 5 files changed, 29 insertions(+), 29 deletions(-) diff --git a/firewall/interception/interception_linux.go b/firewall/interception/interception_linux.go index 0021d9e3..aecbf6e2 100644 --- a/firewall/interception/interception_linux.go +++ b/firewall/interception/interception_linux.go @@ -2,10 +2,8 @@ package interception import "github.com/safing/portmaster/network/packet" -var ( - // Packets channel for feeding the firewall. - Packets = make(chan packet.Packet, 1000) -) +// Packets channel for feeding the firewall. +var Packets = make(chan packet.Packet, 1000) // Start starts the interception. func Start() error { diff --git a/firewall/interception/interception_windows.go b/firewall/interception/interception_windows.go index 3844022e..1a5d4e44 100644 --- a/firewall/interception/interception_windows.go +++ b/firewall/interception/interception_windows.go @@ -11,12 +11,8 @@ import ( "github.com/safing/portmaster/updates" ) -var Packets chan packet.Packet - -func init() { - // Packets channel for feeding the firewall. - Packets = make(chan packet.Packet, 1000) -} +// Packets channel for feeding the firewall. +var Packets = make(chan packet.Packet, 1000) // Start starts the interception. func Start() error { diff --git a/firewall/interception/windowskext/doc.go b/firewall/interception/windowskext/doc.go index dc37d6a3..c68a942f 100644 --- a/firewall/interception/windowskext/doc.go +++ b/firewall/interception/windowskext/doc.go @@ -1,4 +1,4 @@ // +build windows -// Package windowskext provides network interception capabilites on windows via the Portmaster Kernel Extension. +// Package windowskext provides network interception capabilities on windows via the Portmaster Kernel Extension. package windowskext diff --git a/firewall/interception/windowskext/handler.go b/firewall/interception/windowskext/handler.go index f33cf025..99ad9b59 100644 --- a/firewall/interception/windowskext/handler.go +++ b/firewall/interception/windowskext/handler.go @@ -14,20 +14,20 @@ import ( // VerdictRequest is the request structure from the Kext. type VerdictRequest struct { - id uint32 /* ID from RegisterPacket */ - processID uint64 /* Process ID. Nice to have*/ - direction uint8 - ipV6 uint8 /* True: IPv6, False: IPv4 */ - protocol uint8 /* Protocol */ - _ uint8 - localIP [4]uint32 /* Source Address */ - remoteIP [4]uint32 /* Destination Address */ - localPort uint16 /* Source Port */ - remotePort uint16 /* Destination port */ - compartmentID uint32 - interfaceIndex uint32 - subInterfaceIndex uint32 - packetSize uint32 + id uint32 // ID from RegisterPacket + _ uint64 // Process ID - does not yet work + direction uint8 + ipV6 uint8 // True: IPv6, False: IPv4 + protocol uint8 // Protocol + _ uint8 + localIP [4]uint32 // Source Address + remoteIP [4]uint32 // Destination Address + localPort uint16 // Source Port + remotePort uint16 // Destination port + _ uint32 // compartmentID + _ uint32 // interfaceIndex + _ uint32 // subInterfaceIndex + packetSize uint32 } // Handler transforms received packets to the Packet interface. diff --git a/firewall/interception/windowskext/test/main.go b/firewall/interception/windowskext/test/main.go index 0b3642c8..c36a4094 100644 --- a/firewall/interception/windowskext/test/main.go +++ b/firewall/interception/windowskext/test/main.go @@ -32,7 +32,7 @@ func main() { } // logging - log.Start() + _ = log.Start() log.Info("starting Portmaster Windows Kext Test Program") // init @@ -52,7 +52,7 @@ func main() { go handlePackets() // catch interrupt for clean shutdown - signalCh := make(chan os.Signal) + signalCh := make(chan os.Signal, 1) signal.Notify( signalCh, os.Interrupt, @@ -98,13 +98,19 @@ func handlePackets() { // reroute dns requests to nameserver if pkt.IsOutbound() && !pkt.Info().Src.Equal(pkt.Info().Dst) && pkt.Info().DstPort == 53 { log.Infof("rerouting %s", pkt) - pkt.RerouteToNameserver() + err = pkt.RerouteToNameserver() + if err != nil { + log.Errorf("failed to reroute: %s", err) + } continue } // accept all log.Infof("accepting %s", pkt) - pkt.PermanentAccept() + err = pkt.PermanentAccept() + if err != nil { + log.Errorf("failed to accept: %s", err) + } } } From 881c269c1ba1d1d37604b893b2ab2f14d73580b5 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 13:18:52 +0200 Subject: [PATCH 08/10] Fix netenv linter errors --- netenv/dbus_linux_mock.go | 12 ------------ netenv/environment.go | 21 --------------------- netenv/environment_linux.go | 20 ++++++++++++++++++-- netenv/environment_windows.go | 2 ++ 4 files changed, 20 insertions(+), 35 deletions(-) delete mode 100644 netenv/dbus_linux_mock.go diff --git a/netenv/dbus_linux_mock.go b/netenv/dbus_linux_mock.go deleted file mode 100644 index cb0084c3..00000000 --- a/netenv/dbus_linux_mock.go +++ /dev/null @@ -1,12 +0,0 @@ -// +build !linux - -package netenv - -func getNameserversFromDbus() ([]Nameserver, error) { - var nameservers []Nameserver - return nameservers, nil -} - -func getConnectivityStateFromDbus() (OnlineStatus, error) { - return StatusUnknown, nil -} diff --git a/netenv/environment.go b/netenv/environment.go index 59fb3f83..09fda8a4 100644 --- a/netenv/environment.go +++ b/netenv/environment.go @@ -2,8 +2,6 @@ package netenv import ( "net" - "sync" - "time" ) // TODO: find a good way to identify a network @@ -15,25 +13,6 @@ import ( // windows: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365917 // this info might already be included in the interfaces api provided by golang! -const ( - gatewaysRecheck = 2 * time.Second - nameserversRecheck = 2 * time.Second -) - -var ( - // interfaces = make(map[*net.IP]net.Flags) - // interfacesLock sync.Mutex - // interfacesExpires = time.Now() - - gateways = make([]*net.IP, 0) - gatewaysLock sync.Mutex - gatewaysExpires = time.Now() - - nameservers = make([]Nameserver, 0) - nameserversLock sync.Mutex - nameserversExpires = time.Now() -) - // Nameserver describes a system assigned namserver. type Nameserver struct { IP net.IP diff --git a/netenv/environment_linux.go b/netenv/environment_linux.go index 363443f2..f704e8d5 100644 --- a/netenv/environment_linux.go +++ b/netenv/environment_linux.go @@ -6,6 +6,7 @@ import ( "net" "os" "strings" + "sync" "time" "github.com/miekg/dns" @@ -14,7 +15,22 @@ import ( "github.com/safing/portmaster/network/netutils" ) -// Gateways returns the currently active gateways +const ( + gatewaysRecheck = 2 * time.Second + nameserversRecheck = 2 * time.Second +) + +var ( + gateways = make([]*net.IP, 0) + gatewaysLock sync.Mutex + gatewaysExpires = time.Now() + + nameservers = make([]Nameserver, 0) + nameserversLock sync.Mutex + nameserversExpires = time.Now() +) + +// Gateways returns the currently active gateways. func Gateways() []*net.IP { // locking gatewaysLock.Lock() @@ -101,7 +117,7 @@ func Gateways() []*net.IP { return newGateways } -// Nameservers returns the currently active nameservers +// Nameservers returns the currently active nameservers. func Nameservers() []Nameserver { // locking nameserversLock.Lock() diff --git a/netenv/environment_windows.go b/netenv/environment_windows.go index 4f40e3e5..c2bc4e81 100644 --- a/netenv/environment_windows.go +++ b/netenv/environment_windows.go @@ -2,10 +2,12 @@ package netenv import "net" +// Nameservers returns the currently active nameservers. func Nameservers() []Nameserver { return nil } +// Gateways returns the currently active gateways. func Gateways() []*net.IP { return nil } From c20c73a2d82faf48a58b0786696b95121411d097 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 13:19:07 +0200 Subject: [PATCH 09/10] Fix pmctl linter errors --- pmctl/console_windows.go | 2 +- pmctl/install_windows.go | 26 +++++++++++--------------- pmctl/service_windows.go | 9 +++++---- 3 files changed, 17 insertions(+), 20 deletions(-) diff --git a/pmctl/console_windows.go b/pmctl/console_windows.go index 5a1c09b3..1148d90e 100644 --- a/pmctl/console_windows.go +++ b/pmctl/console_windows.go @@ -83,7 +83,7 @@ func attachToParentConsole() (attached bool, err error) { if err != nil { return false, err } - r1, _, err := procAttachConsole.Call(windowsAttachParentProcess) + r1, _, _ := procAttachConsole.Call(windowsAttachParentProcess) if r1 == 0 { // possible errors: // ERROR_ACCESS_DENIED: already attached to console diff --git a/pmctl/install_windows.go b/pmctl/install_windows.go index b06db6f4..3446c493 100644 --- a/pmctl/install_windows.go +++ b/pmctl/install_windows.go @@ -1,6 +1,6 @@ package main -// Based on the offical Go examples from +// Based on the official Go examples from // https://github.com/golang/sys/blob/master/windows/svc/example // by The Go Authors. // Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory. @@ -19,6 +19,10 @@ import ( "golang.org/x/sys/windows/svc/mgr" ) +const ( + exeSuffix = ".exe" +) + func init() { rootCmd.AddCommand(installCmd) installCmd.AddCommand(installService) @@ -70,8 +74,8 @@ func getExePath() (string, error) { } // check if we have a .exe extension, add and check if not if filepath.Ext(p) == "" { - p += ".exe" - fi, err := os.Stat(p) + p += exeSuffix + fi, err = os.Stat(p) if err == nil { if !fi.Mode().IsDir() { return p, nil @@ -113,15 +117,7 @@ func getServiceConfig(exePath string) mgr.Config { func getRecoveryActions() (recoveryActions []mgr.RecoveryAction, resetPeriod uint32) { return []mgr.RecoveryAction{ - //mgr.RecoveryAction{ - // Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand - // Delay: 1 * time.Minute, // the time to wait before performing the specified action - //}, - // mgr.RecoveryAction{ - // Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand - // Delay: 1 * time.Minute, // the time to wait before performing the specified action - // }, - mgr.RecoveryAction{ + { Type: mgr.ServiceRestart, // one of NoAction, ComputerReboot, ServiceRestart or RunCommand Delay: 1 * time.Minute, // the time to wait before performing the specified action }, @@ -140,7 +136,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error { if err != nil { return fmt.Errorf("failed to connect to service manager: %s", err) } - defer m.Disconnect() + defer m.Disconnect() //nolint:errcheck // TODO // open service created := false @@ -156,7 +152,7 @@ func installWindowsService(cmd *cobra.Command, args []string) error { created = true } else { // update service - s.UpdateConfig(getServiceConfig(exePath)) + err = s.UpdateConfig(getServiceConfig(exePath)) if err != nil { return fmt.Errorf("failed to update service: %s", err) } @@ -184,7 +180,7 @@ func uninstallWindowsService(cmd *cobra.Command, args []string) error { if err != nil { return err } - defer m.Disconnect() + defer m.Disconnect() //nolint:errcheck // TODO // open service s, err := m.OpenService(serviceName) diff --git a/pmctl/service_windows.go b/pmctl/service_windows.go index 4fb68bc6..8b02815d 100644 --- a/pmctl/service_windows.go +++ b/pmctl/service_windows.go @@ -1,6 +1,6 @@ package main -// Based on the offical Go examples from +// Based on the official Go examples from // https://github.com/golang/sys/blob/master/windows/svc/example // by The Go Authors. // Original LICENSE (sha256sum: 2d36597f7117c38b006835ae7f537487207d8ec407aa9d9980794b2030cbc067) can be found in vendor/pkg cache directory. @@ -84,7 +84,8 @@ service: changes <- svc.Status{State: svc.Stopped} // wait a little for the status to reach Windows time.Sleep(100 * time.Millisecond) - return + + return ssec, errno } func runService(cmd *cobra.Command, opts *Options) error { @@ -121,7 +122,7 @@ func runService(cmd *cobra.Command, opts *Options) error { go func() { // run slightly delayed time.Sleep(250 * time.Millisecond) - handleRun(cmd, opts) + _ = handleRun(cmd, opts) // error handled by shutdown routine finishWg.Done() runWg.Done() }() @@ -131,7 +132,7 @@ func runService(cmd *cobra.Command, opts *Options) error { err = getShutdownError() if err != nil { log.Printf("%s service experienced an error: %s\n", serviceName, err) - elog.Error(1, fmt.Sprintf("%s experienced an error: %s", serviceName, err)) + _ = elog.Error(1, fmt.Sprintf("%s experienced an error: %s", serviceName, err)) } return err From bb778f2cf7dcdd7c9348fcb6c24caf045d4dfef8 Mon Sep 17 00:00:00 2001 From: Daniel Date: Fri, 10 Apr 2020 13:19:17 +0200 Subject: [PATCH 10/10] Fix process linter errors --- process/iphelper/get.go | 2 +- process/iphelper/iphelper.go | 2 +- process/iphelper/tables.go | 28 ++++++++++++++-------------- process/proc/gather.go | 2 ++ process/proc/get.go | 2 ++ process/proc/processfinder.go | 2 ++ process/proc/processfinder_test.go | 2 ++ process/proc/sockets.go | 2 ++ process/proc/sockets_test.go | 2 ++ 9 files changed, 28 insertions(+), 16 deletions(-) diff --git a/process/iphelper/get.go b/process/iphelper/get.go index 78c6bb12..99c0f821 100644 --- a/process/iphelper/get.go +++ b/process/iphelper/get.go @@ -178,7 +178,7 @@ func GetUDP6PacketInfo(localIP net.IP, localPort uint16, remoteIP net.IP, remote return -1, pktDirection, nil } -func search(connections, listeners []*ConnectionEntry, localIP, remoteIP net.IP, localPort, remotePort uint16, pktDirection bool) (pid int, direction bool) { +func search(connections, listeners []*ConnectionEntry, localIP, remoteIP net.IP, localPort, remotePort uint16, pktDirection bool) (pid int, direction bool) { //nolint:unparam // TODO: use direction, it may not be used because results caused problems, investigate. lock.RLock() defer lock.RUnlock() diff --git a/process/iphelper/iphelper.go b/process/iphelper/iphelper.go index f4799fe9..a7c259da 100644 --- a/process/iphelper/iphelper.go +++ b/process/iphelper/iphelper.go @@ -37,7 +37,7 @@ func New() (*IPHelper, error) { // load dll new.dll = windows.NewLazySystemDLL("iphlpapi.dll") - new.dll.Load() + err = new.dll.Load() if err != nil { return nil, err } diff --git a/process/iphelper/tables.go b/process/iphelper/tables.go index d80ab0c5..8ffecfd7 100644 --- a/process/iphelper/tables.go +++ b/process/iphelper/tables.go @@ -59,14 +59,14 @@ type iphelperTCP6Table struct { type iphelperTCP6Row struct { // docs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366896(v=vs.85).aspx - localAddr [16]byte - localScopeID uint32 - localPort uint32 - remoteAddr [16]byte - remoteScopeID uint32 - remotePort uint32 - state uint32 - owningPid uint32 + localAddr [16]byte + _ uint32 // localScopeID + localPort uint32 + remoteAddr [16]byte + _ uint32 // remoteScopeID + remotePort uint32 + state uint32 + owningPid uint32 } type iphelperUDPTable struct { @@ -90,10 +90,10 @@ type iphelperUDP6Table struct { type iphelperUDP6Row struct { // docs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa366923(v=vs.85).aspx - localAddr [16]byte - localScopeID uint32 - localPort uint32 - owningPid uint32 + localAddr [16]byte + _ uint32 // localScopeID + localPort uint32 + owningPid uint32 } // IP and Protocol constants @@ -137,7 +137,7 @@ func increaseBufSize() int { defer bufSizeLock.Unlock() // increase - bufSize = bufSize * 2 + bufSize *= 2 // not too much if bufSize > 65536 { bufSize = 65536 @@ -149,7 +149,7 @@ func increaseBufSize() int { } // GetTables returns the current connection state table of Windows of the given protocol and IP version. -func (ipHelper *IPHelper) GetTables(protocol uint8, ipVersion uint8) (connections []*ConnectionEntry, listeners []*ConnectionEntry, err error) { +func (ipHelper *IPHelper) GetTables(protocol uint8, ipVersion uint8) (connections []*ConnectionEntry, listeners []*ConnectionEntry, err error) { //nolint:gocognit,gocycle // TODO // docs: https://msdn.microsoft.com/en-us/library/windows/desktop/aa365928(v=vs.85).aspx if !ipHelper.valid.IsSet() { diff --git a/process/proc/gather.go b/process/proc/gather.go index a912b958..436b0bb2 100644 --- a/process/proc/gather.go +++ b/process/proc/gather.go @@ -1,3 +1,5 @@ +// +build linux + package proc import ( diff --git a/process/proc/get.go b/process/proc/get.go index 1fe68940..dec27e23 100644 --- a/process/proc/get.go +++ b/process/proc/get.go @@ -1,3 +1,5 @@ +// +build linux + package proc import ( diff --git a/process/proc/processfinder.go b/process/proc/processfinder.go index f6f57408..5ee1bb4b 100644 --- a/process/proc/processfinder.go +++ b/process/proc/processfinder.go @@ -1,3 +1,5 @@ +// +build linux + package proc import ( diff --git a/process/proc/processfinder_test.go b/process/proc/processfinder_test.go index 30df4483..16d3d181 100644 --- a/process/proc/processfinder_test.go +++ b/process/proc/processfinder_test.go @@ -1,3 +1,5 @@ +// +build linux + package proc import ( diff --git a/process/proc/sockets.go b/process/proc/sockets.go index 49027119..c82b078c 100644 --- a/process/proc/sockets.go +++ b/process/proc/sockets.go @@ -1,3 +1,5 @@ +// +build linux + package proc import ( diff --git a/process/proc/sockets_test.go b/process/proc/sockets_test.go index 71574ffe..44e8fd34 100644 --- a/process/proc/sockets_test.go +++ b/process/proc/sockets_test.go @@ -1,3 +1,5 @@ +// +build linux + package proc import (