Merge pull request #31 from safing/fix/travis/deps-and-golangci-lint

Fix Travis deps, testing and golangci lint
This commit is contained in:
Patrick Pacher 2020-04-10 14:23:32 +02:00 committed by GitHub
commit 61d31d4426
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
28 changed files with 124 additions and 119 deletions

View file

@ -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; fi
install:
- go get -d -u github.com/golang/dep
- go install github.com/golang/dep/cmd/dep

View file

@ -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 {

View file

@ -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 {

View file

@ -1,2 +1,4 @@
// +build linux
// Package nfqueue provides network interception capabilities on linux via iptables nfqueue.
package nfqueue

View file

@ -1,3 +1,5 @@
// +build linux
package nfqueue
// suspended for now

View file

@ -1,3 +1,5 @@
// +build linux
package nfqueue
/*

View file

@ -1,3 +1,5 @@
// +build linux
package nfqueue
import (

View file

@ -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

View file

@ -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.

View file

@ -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)
}
}
}

View file

@ -1,12 +0,0 @@
// +build !linux
package netenv
func getNameserversFromDbus() ([]Nameserver, error) {
var nameservers []Nameserver
return nameservers, nil
}
func getConnectivityStateFromDbus() (uint8, error) {
return StatusUnknown, nil
}

View file

@ -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

View file

@ -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

View file

@ -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()

View file

@ -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
}

View file

@ -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

View file

@ -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)

View file

@ -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

View file

@ -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()

View file

@ -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
}

View file

@ -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() {

View file

@ -1,3 +1,5 @@
// +build linux
package proc
import (

View file

@ -1,3 +1,5 @@
// +build linux
package proc
import (

View file

@ -1,3 +1,5 @@
// +build linux
package proc
import (

View file

@ -1,3 +1,5 @@
// +build linux
package proc
import (

View file

@ -1,3 +1,5 @@
// +build linux
package proc
import (

View file

@ -1,3 +1,5 @@
// +build linux
package proc
import (

30
test
View file

@ -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