diff options
author | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-12-09 17:55:50 +0100 |
---|---|---|
committer | Jason A. Donenfeld <Jason@zx2c4.com> | 2021-12-09 23:15:55 +0100 |
commit | 9c9e7e2724340280d0ca4ff29c067f2d144562c0 (patch) | |
tree | 239826ccafe70e5cee73936d9bcea8989dd33899 | |
parent | 2dd424e2d808703339688ff78e32ed30cd0dfe87 (diff) |
global: apply gofumpt
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
-rw-r--r-- | conn/bind_linux.go | 19 | ||||
-rw-r--r-- | conn/bind_std.go | 6 | ||||
-rw-r--r-- | conn/bind_windows.go | 8 | ||||
-rw-r--r-- | conn/bindtest/bindtest.go | 6 | ||||
-rw-r--r-- | conn/winrio/rio_windows.go | 8 | ||||
-rw-r--r-- | device/allowedips_test.go | 3 | ||||
-rw-r--r-- | device/cookie.go | 5 | ||||
-rw-r--r-- | device/cookie_test.go | 5 | ||||
-rw-r--r-- | device/device_test.go | 2 | ||||
-rw-r--r-- | device/kdf_test.go | 2 | ||||
-rw-r--r-- | device/noise-protocol.go | 7 | ||||
-rw-r--r-- | device/send.go | 1 | ||||
-rw-r--r-- | device/timers.go | 1 | ||||
-rw-r--r-- | device/uapi.go | 1 | ||||
-rw-r--r-- | ipc/namedpipe/file.go | 6 | ||||
-rw-r--r-- | ipc/namedpipe/namedpipe_test.go | 2 | ||||
-rw-r--r-- | ipc/uapi_bsd.go | 1 | ||||
-rw-r--r-- | ipc/uapi_linux.go | 1 | ||||
-rw-r--r-- | ipc/uapi_unix.go | 4 | ||||
-rw-r--r-- | main.go | 1 | ||||
-rw-r--r-- | replay/replay.go | 2 | ||||
-rw-r--r-- | rwcancel/rwcancel_stub.go | 3 | ||||
-rw-r--r-- | tai64n/tai64n.go | 8 | ||||
-rw-r--r-- | tun/netstack/tun.go | 7 | ||||
-rw-r--r-- | tun/tun_darwin.go | 5 | ||||
-rw-r--r-- | tun/tun_linux.go | 2 | ||||
-rw-r--r-- | tun/tun_openbsd.go | 5 | ||||
-rw-r--r-- | tun/tun_windows.go | 6 |
28 files changed, 56 insertions, 71 deletions
diff --git a/conn/bind_linux.go b/conn/bind_linux.go index da0670a..b3d755c 100644 --- a/conn/bind_linux.go +++ b/conn/bind_linux.go @@ -66,8 +66,10 @@ type LinuxSocketBind struct { func NewLinuxSocketBind() Bind { return &LinuxSocketBind{sock4: -1, sock6: -1} } func NewDefaultBind() Bind { return NewLinuxSocketBind() } -var _ Endpoint = (*LinuxSocketEndpoint)(nil) -var _ Bind = (*LinuxSocketBind)(nil) +var ( + _ Endpoint = (*LinuxSocketEndpoint)(nil) + _ Bind = (*LinuxSocketBind)(nil) +) func (*LinuxSocketBind) ParseEndpoint(s string) (Endpoint, error) { var end LinuxSocketEndpoint @@ -171,7 +173,6 @@ func (bind *LinuxSocketBind) SetMark(value uint32) error { unix.SO_MARK, int(value), ) - if err != nil { return err } @@ -184,7 +185,6 @@ func (bind *LinuxSocketBind) SetMark(value uint32) error { unix.SO_MARK, int(value), ) - if err != nil { return err } @@ -327,7 +327,6 @@ func zoneToUint32(zone string) (uint32, error) { } func create4(port uint16) (int, uint16, error) { - // create socket fd, err := unix.Socket( @@ -335,7 +334,6 @@ func create4(port uint16) (int, uint16, error) { unix.SOCK_DGRAM, 0, ) - if err != nil { return -1, 0, err } @@ -371,7 +369,6 @@ func create4(port uint16) (int, uint16, error) { } func create6(port uint16) (int, uint16, error) { - // create socket fd, err := unix.Socket( @@ -379,7 +376,6 @@ func create6(port uint16) (int, uint16, error) { unix.SOCK_DGRAM, 0, ) - if err != nil { return -1, 0, err } @@ -410,7 +406,6 @@ func create6(port uint16) (int, uint16, error) { } return unix.Bind(fd, &addr) - }(); err != nil { unix.Close(fd) return -1, 0, err @@ -425,7 +420,6 @@ func create6(port uint16) (int, uint16, error) { } func send4(sock int, end *LinuxSocketEndpoint, buff []byte) error { - // construct message header cmsg := struct { @@ -465,7 +459,6 @@ func send4(sock int, end *LinuxSocketEndpoint, buff []byte) error { } func send6(sock int, end *LinuxSocketEndpoint, buff []byte) error { - // construct message header cmsg := struct { @@ -509,7 +502,6 @@ func send6(sock int, end *LinuxSocketEndpoint, buff []byte) error { } func receive4(sock int, buff []byte, end *LinuxSocketEndpoint) (int, error) { - // construct message header var cmsg struct { @@ -518,7 +510,6 @@ func receive4(sock int, buff []byte, end *LinuxSocketEndpoint) (int, error) { } size, _, _, newDst, err := unix.Recvmsg(sock, buff, (*[unsafe.Sizeof(cmsg)]byte)(unsafe.Pointer(&cmsg))[:], 0) - if err != nil { return 0, err } @@ -541,7 +532,6 @@ func receive4(sock int, buff []byte, end *LinuxSocketEndpoint) (int, error) { } func receive6(sock int, buff []byte, end *LinuxSocketEndpoint) (int, error) { - // construct message header var cmsg struct { @@ -550,7 +540,6 @@ func receive6(sock int, buff []byte, end *LinuxSocketEndpoint) (int, error) { } size, _, _, newDst, err := unix.Recvmsg(sock, buff, (*[unsafe.Sizeof(cmsg)]byte)(unsafe.Pointer(&cmsg))[:], 0) - if err != nil { return 0, err } diff --git a/conn/bind_std.go b/conn/bind_std.go index a3cbb15..de03b10 100644 --- a/conn/bind_std.go +++ b/conn/bind_std.go @@ -30,8 +30,10 @@ func NewStdNetBind() Bind { return &StdNetBind{} } type StdNetEndpoint net.UDPAddr -var _ Bind = (*StdNetBind)(nil) -var _ Endpoint = (*StdNetEndpoint)(nil) +var ( + _ Bind = (*StdNetBind)(nil) + _ Endpoint = (*StdNetEndpoint)(nil) +) func (*StdNetBind) ParseEndpoint(s string) (Endpoint, error) { e, err := netip.ParseAddrPort(s) diff --git a/conn/bind_windows.go b/conn/bind_windows.go index 26a3af8..476e277 100644 --- a/conn/bind_windows.go +++ b/conn/bind_windows.go @@ -91,8 +91,10 @@ type WinRingEndpoint struct { data [30]byte } -var _ Bind = (*WinRingBind)(nil) -var _ Endpoint = (*WinRingEndpoint)(nil) +var ( + _ Bind = (*WinRingBind)(nil) + _ Endpoint = (*WinRingEndpoint)(nil) +) func (*WinRingBind) ParseEndpoint(s string) (Endpoint, error) { host, port, err := net.SplitHostPort(s) @@ -382,7 +384,6 @@ retry: count = winrio.DequeueCompletion(bind.rx.cq, results[:]) if count == 0 { return 0, nil, io.ErrNoProgress - } } bind.rx.Return(1) @@ -533,6 +534,7 @@ func (bind *StdNetBind) BindSocketToInterface6(interfaceIndex uint32, blackhole bind.blackhole6 = blackhole return nil } + func (bind *WinRingBind) BindSocketToInterface4(interfaceIndex uint32, blackhole bool) error { bind.mu.RLock() defer bind.mu.RUnlock() diff --git a/conn/bindtest/bindtest.go b/conn/bindtest/bindtest.go index 6a45896..6fc1972 100644 --- a/conn/bindtest/bindtest.go +++ b/conn/bindtest/bindtest.go @@ -25,8 +25,10 @@ type ChannelBind struct { type ChannelEndpoint uint16 -var _ conn.Bind = (*ChannelBind)(nil) -var _ conn.Endpoint = (*ChannelEndpoint)(nil) +var ( + _ conn.Bind = (*ChannelBind)(nil) + _ conn.Endpoint = (*ChannelEndpoint)(nil) +) func NewChannelBinds() [2]conn.Bind { arx4 := make(chan []byte, 8192) diff --git a/conn/winrio/rio_windows.go b/conn/winrio/rio_windows.go index 0a07c65..0911998 100644 --- a/conn/winrio/rio_windows.go +++ b/conn/winrio/rio_windows.go @@ -84,8 +84,10 @@ type iocpNotificationCompletion struct { overlapped *windows.Overlapped } -var initialized sync.Once -var available bool +var ( + initialized sync.Once + available bool +) func Initialize() bool { initialized.Do(func() { @@ -108,7 +110,7 @@ func Initialize() bool { return } defer windows.CloseHandle(socket) - var WSAID_MULTIPLE_RIO = &windows.GUID{0x8509e081, 0x96dd, 0x4005, [8]byte{0xb1, 0x65, 0x9e, 0x2e, 0xe8, 0xc7, 0x9e, 0x3f}} + WSAID_MULTIPLE_RIO := &windows.GUID{0x8509e081, 0x96dd, 0x4005, [8]byte{0xb1, 0x65, 0x9e, 0x2e, 0xe8, 0xc7, 0x9e, 0x3f}} const SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER = 0xc8000024 ob := uint32(0) err = windows.WSAIoctl(socket, SIO_GET_MULTIPLE_EXTENSION_FUNCTION_POINTER, diff --git a/device/allowedips_test.go b/device/allowedips_test.go index a274997..68f382b 100644 --- a/device/allowedips_test.go +++ b/device/allowedips_test.go @@ -20,7 +20,6 @@ type testPairCommonBits struct { } func TestCommonBits(t *testing.T) { - tests := []testPairCommonBits{ {s1: []byte{1, 4, 53, 128}, s2: []byte{0, 0, 0, 0}, match: 7}, {s1: []byte{0, 4, 53, 128}, s2: []byte{0, 0, 0, 0}, match: 13}, @@ -41,7 +40,7 @@ func TestCommonBits(t *testing.T) { } } -func benchmarkTrie(peerNumber int, addressNumber int, addressLength int, b *testing.B) { +func benchmarkTrie(peerNumber, addressNumber, addressLength int, b *testing.B) { var trie *trieEntry var peers []*Peer root := parentIndirection{&trie, 2} diff --git a/device/cookie.go b/device/cookie.go index b02b769..840f709 100644 --- a/device/cookie.go +++ b/device/cookie.go @@ -83,7 +83,7 @@ func (st *CookieChecker) CheckMAC1(msg []byte) bool { return hmac.Equal(mac1[:], msg[smac1:smac2]) } -func (st *CookieChecker) CheckMAC2(msg []byte, src []byte) bool { +func (st *CookieChecker) CheckMAC2(msg, src []byte) bool { st.RLock() defer st.RUnlock() @@ -119,7 +119,6 @@ func (st *CookieChecker) CreateReply( recv uint32, src []byte, ) (*MessageCookieReply, error) { - st.RLock() // refresh cookie secret @@ -204,7 +203,6 @@ func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool { xchapoly, _ := chacha20poly1305.NewX(st.mac2.encryptionKey[:]) _, err := xchapoly.Open(cookie[:0], msg.Nonce[:], msg.Cookie[:], st.mac2.lastMAC1[:]) - if err != nil { return false } @@ -215,7 +213,6 @@ func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool { } func (st *CookieGenerator) AddMacs(msg []byte) { - size := len(msg) smac2 := size - blake2s.Size128 diff --git a/device/cookie_test.go b/device/cookie_test.go index 02e01d1..06f306f 100644 --- a/device/cookie_test.go +++ b/device/cookie_test.go @@ -10,7 +10,6 @@ import ( ) func TestCookieMAC1(t *testing.T) { - // setup generator / checker var ( @@ -132,12 +131,12 @@ func TestCookieMAC1(t *testing.T) { msg[5] ^= 0x20 - srcBad1 := []byte{192, 168, 13, 37, 40, 01} + srcBad1 := []byte{192, 168, 13, 37, 40, 1} if checker.CheckMAC2(msg, srcBad1) { t.Fatal("MAC2 generation/verification failed") } - srcBad2 := []byte{192, 168, 13, 38, 40, 01} + srcBad2 := []byte{192, 168, 13, 38, 40, 1} if checker.CheckMAC2(msg, srcBad2) { t.Fatal("MAC2 generation/verification failed") } diff --git a/device/device_test.go b/device/device_test.go index 84221be..b484ca2 100644 --- a/device/device_test.go +++ b/device/device_test.go @@ -48,7 +48,7 @@ func uapiCfg(cfg ...string) string { // genConfigs generates a pair of configs that connect to each other. // The configs use distinct, probably-usable ports. -func genConfigs(tb testing.TB) (cfgs [2]string, endpointCfgs [2]string) { +func genConfigs(tb testing.TB) (cfgs, endpointCfgs [2]string) { var key1, key2 NoisePrivateKey _, err := rand.Read(key1[:]) if err != nil { diff --git a/device/kdf_test.go b/device/kdf_test.go index b14aa6d..872195c 100644 --- a/device/kdf_test.go +++ b/device/kdf_test.go @@ -20,7 +20,7 @@ type KDFTest struct { t2 string } -func assertEquals(t *testing.T, a string, b string) { +func assertEquals(t *testing.T, a, b string) { if a != b { t.Fatal("expected", a, "=", b) } diff --git a/device/noise-protocol.go b/device/noise-protocol.go index e31ceda..ffa0452 100644 --- a/device/noise-protocol.go +++ b/device/noise-protocol.go @@ -138,11 +138,11 @@ var ( ZeroNonce [chacha20poly1305.NonceSize]byte ) -func mixKey(dst *[blake2s.Size]byte, c *[blake2s.Size]byte, data []byte) { +func mixKey(dst, c *[blake2s.Size]byte, data []byte) { KDF1(dst, c[:], data) } -func mixHash(dst *[blake2s.Size]byte, h *[blake2s.Size]byte, data []byte) { +func mixHash(dst, h *[blake2s.Size]byte, data []byte) { hash, _ := blake2s.New256(nil) hash.Write(h[:]) hash.Write(data) @@ -175,7 +175,7 @@ func init() { } func (device *Device) CreateMessageInitiation(peer *Peer) (*MessageInitiation, error) { - var errZeroECDHResult = errors.New("ECDH returned all zeros") + errZeroECDHResult := errors.New("ECDH returned all zeros") device.staticIdentity.RLock() defer device.staticIdentity.RUnlock() @@ -436,7 +436,6 @@ func (device *Device) ConsumeMessageResponse(msg *MessageResponse) *Peer { ) ok := func() bool { - // lock handshake state handshake.mutex.RLock() diff --git a/device/send.go b/device/send.go index b05c69e..0a7135f 100644 --- a/device/send.go +++ b/device/send.go @@ -226,7 +226,6 @@ func (device *Device) RoutineReadFromTUN() { offset := MessageTransportHeaderSize size, err := device.tun.device.Read(elem.buffer[:], offset) - if err != nil { if !device.isClosed() { if !errors.Is(err, os.ErrClosed) { diff --git a/device/timers.go b/device/timers.go index 176976d..4d2d0f8 100644 --- a/device/timers.go +++ b/device/timers.go @@ -130,7 +130,6 @@ func expiredNewHandshake(peer *Peer) { } peer.Unlock() peer.SendHandshakeInitiation(false) - } func expiredZeroKeyMaterial(peer *Peer) { diff --git a/device/uapi.go b/device/uapi.go index 0f98c68..1994d46 100644 --- a/device/uapi.go +++ b/device/uapi.go @@ -73,7 +73,6 @@ func (device *Device) IpcGetOperation(w io.Writer) error { } func() { - // lock required resources device.net.RLock() diff --git a/ipc/namedpipe/file.go b/ipc/namedpipe/file.go index 9c2481d..c5dd48a 100644 --- a/ipc/namedpipe/file.go +++ b/ipc/namedpipe/file.go @@ -22,8 +22,10 @@ import ( type timeoutChan chan struct{} -var ioInitOnce sync.Once -var ioCompletionPort windows.Handle +var ( + ioInitOnce sync.Once + ioCompletionPort windows.Handle +) // ioResult contains the result of an asynchronous IO operation type ioResult struct { diff --git a/ipc/namedpipe/namedpipe_test.go b/ipc/namedpipe/namedpipe_test.go index 0573d0f..84d2987 100644 --- a/ipc/namedpipe/namedpipe_test.go +++ b/ipc/namedpipe/namedpipe_test.go @@ -169,7 +169,7 @@ func TestDialAccessDeniedWithRestrictedSD(t *testing.T) { } } -func getConnection(cfg *namedpipe.ListenConfig) (client net.Conn, server net.Conn, err error) { +func getConnection(cfg *namedpipe.ListenConfig) (client, server net.Conn, err error) { pipePath := randomPipePath() if cfg == nil { cfg = &namedpipe.ListenConfig{} diff --git a/ipc/uapi_bsd.go b/ipc/uapi_bsd.go index 6deaa87..6c85b40 100644 --- a/ipc/uapi_bsd.go +++ b/ipc/uapi_bsd.go @@ -54,7 +54,6 @@ func (l *UAPIListener) Addr() net.Addr { } func UAPIListen(name string, file *os.File) (net.Listener, error) { - // wrap file in listener listener, err := net.FileListener(file) diff --git a/ipc/uapi_linux.go b/ipc/uapi_linux.go index e03a00b..30a8eb4 100644 --- a/ipc/uapi_linux.go +++ b/ipc/uapi_linux.go @@ -51,7 +51,6 @@ func (l *UAPIListener) Addr() net.Addr { } func UAPIListen(name string, file *os.File) (net.Listener, error) { - // wrap file in listener listener, err := net.FileListener(file) diff --git a/ipc/uapi_unix.go b/ipc/uapi_unix.go index 57caf21..6f1ee47 100644 --- a/ipc/uapi_unix.go +++ b/ipc/uapi_unix.go @@ -33,7 +33,7 @@ func sockPath(iface string) string { } func UAPIOpen(name string) (*os.File, error) { - if err := os.MkdirAll(socketDirectory, 0755); err != nil { + if err := os.MkdirAll(socketDirectory, 0o755); err != nil { return nil, err } @@ -43,7 +43,7 @@ func UAPIOpen(name string) (*os.File, error) { return nil, err } - oldUmask := unix.Umask(0077) + oldUmask := unix.Umask(0o077) defer unix.Umask(oldUmask) listener, err := net.ListenUnix("unix", addr) @@ -169,7 +169,6 @@ func main() { return os.NewFile(uintptr(fd), ""), nil }() - if err != nil { logger.Errorf("UAPI listen error: %v", err) os.Exit(ExitSetupFailed) diff --git a/replay/replay.go b/replay/replay.go index fac7ab2..f140272 100644 --- a/replay/replay.go +++ b/replay/replay.go @@ -34,7 +34,7 @@ func (f *Filter) Reset() { // ValidateCounter checks if the counter should be accepted. // Overlimit counters (>= limit) are always rejected. -func (f *Filter) ValidateCounter(counter uint64, limit uint64) bool { +func (f *Filter) ValidateCounter(counter, limit uint64) bool { if counter >= limit { return false } diff --git a/rwcancel/rwcancel_stub.go b/rwcancel/rwcancel_stub.go index fae47b4..182940b 100644 --- a/rwcancel/rwcancel_stub.go +++ b/rwcancel/rwcancel_stub.go @@ -4,7 +4,6 @@ package rwcancel -type RWCancel struct { -} +type RWCancel struct{} func (*RWCancel) Cancel() {} diff --git a/tai64n/tai64n.go b/tai64n/tai64n.go index e1fa26a..de0f5bf 100644 --- a/tai64n/tai64n.go +++ b/tai64n/tai64n.go @@ -11,9 +11,11 @@ import ( "time" ) -const TimestampSize = 12 -const base = uint64(0x400000000000000a) -const whitenerMask = uint32(0x1000000 - 1) +const ( + TimestampSize = 12 + base = uint64(0x400000000000000a) + whitenerMask = uint32(0x1000000 - 1) +) type Timestamp [TimestampSize]byte diff --git a/tun/netstack/tun.go b/tun/netstack/tun.go index f1c03f4..fb7f07d 100644 --- a/tun/netstack/tun.go +++ b/tun/netstack/tun.go @@ -42,8 +42,11 @@ type netTun struct { dnsServers []netip.Addr hasV4, hasV6 bool } -type endpoint netTun -type Net netTun + +type ( + endpoint netTun + Net netTun +) func (e *endpoint) Attach(dispatcher stack.NetworkDispatcher) { e.dispatcher = dispatcher diff --git a/tun/tun_darwin.go b/tun/tun_darwin.go index 35d3085..94bbfa6 100644 --- a/tun/tun_darwin.go +++ b/tun/tun_darwin.go @@ -141,7 +141,7 @@ func CreateTUN(name string, mtu int) (Device, error) { if err == nil && name == "utun" { fname := os.Getenv("WG_TUN_NAME_FILE") if fname != "" { - os.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0400) + os.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0o400) } } @@ -232,7 +232,6 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { } func (tun *NativeTun) Write(buff []byte, offset int) (int, error) { - // reserve space for header buff = buff[offset-4:] @@ -282,7 +281,6 @@ func (tun *NativeTun) setMTU(n int) error { unix.SOCK_DGRAM, 0, ) - if err != nil { return err } @@ -306,7 +304,6 @@ func (tun *NativeTun) MTU() (int, error) { unix.SOCK_DGRAM, 0, ) - if err != nil { return 0, err } diff --git a/tun/tun_linux.go b/tun/tun_linux.go index 1cc84cb..89b716d 100644 --- a/tun/tun_linux.go +++ b/tun/tun_linux.go @@ -232,7 +232,6 @@ func (tun *NativeTun) setMTU(n int) error { unix.SOCK_DGRAM, 0, ) - if err != nil { return err } @@ -269,7 +268,6 @@ func (tun *NativeTun) MTU() (int, error) { unix.SOCK_DGRAM, 0, ) - if err != nil { return 0, err } diff --git a/tun/tun_openbsd.go b/tun/tun_openbsd.go index 7ef62f4..ff845bc 100644 --- a/tun/tun_openbsd.go +++ b/tun/tun_openbsd.go @@ -133,7 +133,7 @@ func CreateTUN(name string, mtu int) (Device, error) { if err == nil && name == "tun" { fname := os.Getenv("WG_TUN_NAME_FILE") if fname != "" { - os.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0400) + os.WriteFile(fname, []byte(tun.(*NativeTun).name+"\n"), 0o400) } } @@ -219,7 +219,6 @@ func (tun *NativeTun) Read(buff []byte, offset int) (int, error) { } func (tun *NativeTun) Write(buff []byte, offset int) (int, error) { - // reserve space for header buff = buff[offset-4:] @@ -274,7 +273,6 @@ func (tun *NativeTun) setMTU(n int) error { unix.SOCK_DGRAM, 0, ) - if err != nil { return err } @@ -309,7 +307,6 @@ func (tun *NativeTun) MTU() (int, error) { unix.SOCK_DGRAM, 0, ) - if err != nil { return 0, err } diff --git a/tun/tun_windows.go b/tun/tun_windows.go index 3101ed9..d057150 100644 --- a/tun/tun_windows.go +++ b/tun/tun_windows.go @@ -46,8 +46,10 @@ type NativeTun struct { forcedMTU int } -var WintunTunnelType = "WireGuard" -var WintunStaticRequestedGUID *windows.GUID +var ( + WintunTunnelType = "WireGuard" + WintunStaticRequestedGUID *windows.GUID +) //go:linkname procyield runtime.procyield func procyield(cycles uint32) |