Skip to content

Commit

Permalink
Make all checks happy (#1)
Browse files Browse the repository at this point in the history
  • Loading branch information
Doridian authored Sep 1, 2022
1 parent f6bfa17 commit c140e69
Show file tree
Hide file tree
Showing 11 changed files with 26 additions and 20 deletions.
9 changes: 5 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ jobs:
- name: Build
run: go build ./...
- name: Test
run: go test ./...
run: sudo go test ./...

test-windows:
runs-on: windows-latest
Expand All @@ -33,8 +33,9 @@ jobs:
cache: true
- name: Build
run: go build ./...
- name: Test
run: go test ./...
# TODO: wintun + OpenVPN install
#- name: Test
# run: go test ./...

test-darwin:
runs-on: macos-latest
Expand All @@ -48,4 +49,4 @@ jobs:
- name: Build
run: go build ./...
- name: Test
run: go test ./...
run: sudo go test ./...
2 changes: 1 addition & 1 deletion if.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ type Interface struct {
isTAP bool
io.ReadWriteCloser
name string
secondaryName string
secondaryName string //lint:ignore U1000 This is unused on some operating systems
}

// DeviceType is the type for specifying device types.
Expand Down
1 change: 1 addition & 0 deletions ipv4_other_test.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux && !windows && !darwin
// +build !linux,!windows,!darwin

package water
Expand Down
4 changes: 2 additions & 2 deletions ipv4_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -83,14 +83,14 @@ func TestCloseUnblockPendingRead(t *testing.T) {

c := make(chan struct{})
go func() {
ifce.Read(make([]byte, 1<<16))
_, _ = ifce.Read(make([]byte, 1<<16))
close(c)
}()

// make sure ifce.Close() happens after ifce.Read() blocks
time.Sleep(1 * time.Second)

ifce.Close()
_ = ifce.Close()
ctx, cancel := context.WithTimeout(context.Background(), time.Second)
defer cancel()

Expand Down
1 change: 1 addition & 0 deletions params_others.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux && !darwin && !windows
// +build !linux,!darwin,!windows

package water
Expand Down
14 changes: 7 additions & 7 deletions syscalls_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -92,15 +92,15 @@ type ifaceCloser struct {
additional []io.Closer
}

func (i *ifaceCloser) Close() error {
func (c *ifaceCloser) Close() error {
var err error
for _, add := range i.additional {
for _, add := range c.additional {
newErr := add.Close()
if err == nil {
err = newErr
}
}
for _, iface := range i.ifaces {
for _, iface := range c.ifaces {
newErr := exec.Command("ifconfig", iface, "destroy").Run()
if err == nil {
err = newErr
Expand Down Expand Up @@ -546,17 +546,17 @@ func EnsureMTUAdjust(mtu uint32) error {
return err
}

func (i *Interface) SetMTU(mtu int) error {
if i.secondaryName != "" {
func (ifce *Interface) SetMTU(mtu int) error {
if ifce.secondaryName != "" {
err := EnsureMTUAdjust(uint32(mtu))
if err != nil {
return err
}

err = exec.Command("ifconfig", i.secondaryName, "mtu", fmt.Sprintf("%d", mtu)).Run()
err = exec.Command("ifconfig", ifce.secondaryName, "mtu", fmt.Sprintf("%d", mtu)).Run()
if err != nil {
return err
}
}
return exec.Command("ifconfig", i.name, "mtu", fmt.Sprintf("%d", mtu)).Run()
return exec.Command("ifconfig", ifce.name, "mtu", fmt.Sprintf("%d", mtu)).Run()
}
6 changes: 3 additions & 3 deletions syscalls_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ func createInterface(fd uintptr, ifName string, flags uint16) (createdIFName str
req.Flags = flags
copy(req.Name[:], ifName)

err = ioctl(fd, syscall.TUNSETIFF, uintptr(unsafe.Pointer(&req)))
err = ioctl(fd, syscall.TUNSETIFF, uintptr(unsafe.Pointer(&req))) // #nosec G103 -- This is sadly required for now
if err != nil {
return
}
Expand Down Expand Up @@ -103,6 +103,6 @@ func openDev(config Config) (ifce *Interface, err error) {
}, nil
}

func (i *Interface) SetMTU(mtu int) error {
return exec.Command("ip", "link", "set", "dev", i.name, "mtu", fmt.Sprintf("%d", mtu)).Run()
func (ifce *Interface) SetMTU(mtu int) error {
return exec.Command("ip", "link", "set", "dev", ifce.name, "mtu", fmt.Sprintf("%d", mtu)).Run() // #nosec G204 -- This is exactly what it needs to be
}
1 change: 1 addition & 0 deletions syscalls_other.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//go:build !linux && !darwin && !windows
// +build !linux,!darwin,!windows

package water
Expand Down
6 changes: 3 additions & 3 deletions syscalls_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -338,13 +338,13 @@ func openDev(config Config) (ifce *Interface, err error) {
return &Interface{ReadWriteCloser: &wintunRWC{ad: ad}, name: name}, nil
}

func (i *Interface) SetMTU(mtu int) error {
err := exec.Command("netsh", "interface", "ipv4", "set", "subinterface", i.name, fmt.Sprintf("mtu=%d", mtu)).Run()
func (ifce *Interface) SetMTU(mtu int) error {
err := exec.Command("netsh", "interface", "ipv4", "set", "subinterface", ifce.name, fmt.Sprintf("mtu=%d", mtu)).Run()
if err != nil {
return err
}

wtun, ok := i.ReadWriteCloser.(*wintunRWC)
wtun, ok := ifce.ReadWriteCloser.(*wintunRWC)
if !ok {
return nil // TAP interface
}
Expand Down
1 change: 1 addition & 0 deletions waterutil/ethertypes.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//lint:file-ignore ST1003 These constants are from external sources
package waterutil

type Ethertype [2]byte
Expand Down
1 change: 1 addition & 0 deletions waterutil/ip_protocols.go
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
//lint:file-ignore ST1003 These constants are from external sources
package waterutil

type IPProtocol byte
Expand Down

0 comments on commit c140e69

Please sign in to comment.