Skip to content

Commit

Permalink
global: apply gofumpt
Browse files Browse the repository at this point in the history
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
  • Loading branch information
zx2c4 committed Dec 9, 2021
1 parent 2dd424e commit 9c9e7e2
Show file tree
Hide file tree
Showing 28 changed files with 56 additions and 71 deletions.
19 changes: 4 additions & 15 deletions conn/bind_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -171,7 +173,6 @@ func (bind *LinuxSocketBind) SetMark(value uint32) error {
unix.SO_MARK,
int(value),
)

if err != nil {
return err
}
Expand All @@ -184,7 +185,6 @@ func (bind *LinuxSocketBind) SetMark(value uint32) error {
unix.SO_MARK,
int(value),
)

if err != nil {
return err
}
Expand Down Expand Up @@ -327,15 +327,13 @@ func zoneToUint32(zone string) (uint32, error) {
}

func create4(port uint16) (int, uint16, error) {

// create socket

fd, err := unix.Socket(
unix.AF_INET,
unix.SOCK_DGRAM,
0,
)

if err != nil {
return -1, 0, err
}
Expand Down Expand Up @@ -371,15 +369,13 @@ func create4(port uint16) (int, uint16, error) {
}

func create6(port uint16) (int, uint16, error) {

// create socket

fd, err := unix.Socket(
unix.AF_INET6,
unix.SOCK_DGRAM,
0,
)

if err != nil {
return -1, 0, err
}
Expand Down Expand Up @@ -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
Expand All @@ -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 {
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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 {
Expand All @@ -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
}
Expand All @@ -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 {
Expand All @@ -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
}
Expand Down
6 changes: 4 additions & 2 deletions conn/bind_std.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions conn/bind_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -382,7 +384,6 @@ retry:
count = winrio.DequeueCompletion(bind.rx.cq, results[:])
if count == 0 {
return 0, nil, io.ErrNoProgress

}
}
bind.rx.Return(1)
Expand Down Expand Up @@ -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()
Expand Down
6 changes: 4 additions & 2 deletions conn/bindtest/bindtest.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
8 changes: 5 additions & 3 deletions conn/winrio/rio_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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,
Expand Down
3 changes: 1 addition & 2 deletions device/allowedips_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand All @@ -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}
Expand Down
5 changes: 1 addition & 4 deletions device/cookie.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -119,7 +119,6 @@ func (st *CookieChecker) CreateReply(
recv uint32,
src []byte,
) (*MessageCookieReply, error) {

st.RLock()

// refresh cookie secret
Expand Down Expand Up @@ -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
}
Expand All @@ -215,7 +213,6 @@ func (st *CookieGenerator) ConsumeReply(msg *MessageCookieReply) bool {
}

func (st *CookieGenerator) AddMacs(msg []byte) {

size := len(msg)

smac2 := size - blake2s.Size128
Expand Down
5 changes: 2 additions & 3 deletions device/cookie_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
)

func TestCookieMAC1(t *testing.T) {

// setup generator / checker

var (
Expand Down Expand Up @@ -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")
}
Expand Down
2 changes: 1 addition & 1 deletion device/device_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion device/kdf_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand Down
7 changes: 3 additions & 4 deletions device/noise-protocol.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -436,7 +436,6 @@ func (device *Device) ConsumeMessageResponse(msg *MessageResponse) *Peer {
)

ok := func() bool {

// lock handshake state

handshake.mutex.RLock()
Expand Down
1 change: 0 additions & 1 deletion device/send.go
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
1 change: 0 additions & 1 deletion device/timers.go
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@ func expiredNewHandshake(peer *Peer) {
}
peer.Unlock()
peer.SendHandshakeInitiation(false)

}

func expiredZeroKeyMaterial(peer *Peer) {
Expand Down
1 change: 0 additions & 1 deletion device/uapi.go
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,6 @@ func (device *Device) IpcGetOperation(w io.Writer) error {
}

func() {

// lock required resources

device.net.RLock()
Expand Down
6 changes: 4 additions & 2 deletions ipc/namedpipe/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
2 changes: 1 addition & 1 deletion ipc/namedpipe/namedpipe_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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{}
Expand Down
1 change: 0 additions & 1 deletion ipc/uapi_bsd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 0 additions & 1 deletion ipc/uapi_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions ipc/uapi_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand All @@ -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)
Expand Down
Loading

0 comments on commit 9c9e7e2

Please sign in to comment.