From 8932ab051916416eb71452e7febc4de0ab8b8378 Mon Sep 17 00:00:00 2001 From: Neil Alexander Date: Wed, 2 Jun 2021 14:40:09 +0100 Subject: [PATCH] Fix lint errors --- cmd/yggdrasil/main.go | 25 +++++++++++++++---------- cmd/yggdrasilctl/main.go | 4 ++-- src/core/core.go | 2 +- src/core/link.go | 12 ------------ src/core/tcp.go | 4 ++-- src/multicast/multicast.go | 6 +++--- src/multicast/multicast_darwin.go | 2 -- src/tuntap/iface.go | 6 +----- src/tuntap/keystore.go | 8 ++++---- src/tuntap/nodeinfo.go | 4 ++-- src/tuntap/proto.go | 2 +- src/tuntap/tun.go | 4 ++-- src/tuntap/tun_darwin.go | 15 +++++++++------ src/tuntap/types.go | 4 ++-- 14 files changed, 44 insertions(+), 54 deletions(-) diff --git a/cmd/yggdrasil/main.go b/cmd/yggdrasil/main.go index 6484edf..0f830bb 100644 --- a/cmd/yggdrasil/main.go +++ b/cmd/yggdrasil/main.go @@ -107,7 +107,9 @@ func readConfig(useconf *bool, useconffile *string, normaliseconf *bool) *config if err != nil { panic(err) } - json.Unmarshal(confJson, &cfg) + if err := json.Unmarshal(confJson, &cfg); err != nil { + panic(err) + } // Overlay our newly mapped configuration onto the autoconf node config that // we generated above. if err = mapstructure.Decode(dat, &cfg); err != nil { @@ -283,20 +285,23 @@ func main() { n.tuntap = &tuntap.TunAdapter{} n.tuntap.(*tuntap.TunAdapter).SetSessionGatekeeper(n.sessionFirewall) // Start the admin socket - n.admin.Init(&n.core, cfg, logger, nil) - if err := n.admin.Start(); err != nil { + if err := n.admin.Init(&n.core, cfg, logger, nil); err != nil { + logger.Errorln("An error occured initialising admin socket:", err) + } else if err := n.admin.Start(); err != nil { logger.Errorln("An error occurred starting admin socket:", err) } n.admin.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) // Start the multicast interface - n.multicast.Init(&n.core, cfg, logger, nil) - if err := n.multicast.Start(); err != nil { + if err := n.multicast.Init(&n.core, cfg, logger, nil); err != nil { + logger.Errorln("An error occured initialising multicast:", err) + } else if err := n.multicast.Start(); err != nil { logger.Errorln("An error occurred starting multicast:", err) } n.multicast.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) // Start the TUN/TAP interface - n.tuntap.Init(&n.core, cfg, logger, nil) - if err := n.tuntap.Start(); err != nil { + if err := n.tuntap.Init(&n.core, cfg, logger, nil); err != nil { + logger.Errorln("An error occurred initialising TUN/TAP:", err) + } else if err := n.tuntap.Start(); err != nil { logger.Errorln("An error occurred starting TUN/TAP:", err) } n.tuntap.SetupAdminHandlers(n.admin.(*admin.AdminSocket)) @@ -316,9 +321,9 @@ func main() { } func (n *node) shutdown() { - n.admin.Stop() - n.multicast.Stop() - n.tuntap.Stop() + _ = n.admin.Stop() + _ = n.multicast.Stop() + _ = n.tuntap.Stop() n.core.Stop() } diff --git a/cmd/yggdrasilctl/main.go b/cmd/yggdrasilctl/main.go index 38d935a..884656d 100644 --- a/cmd/yggdrasilctl/main.go +++ b/cmd/yggdrasilctl/main.go @@ -47,8 +47,8 @@ func run() int { fmt.Fprintf(flag.CommandLine.Output(), "Usage: %s [options] command [key=value] [key=value] ...\n\n", os.Args[0]) fmt.Println("Options:") flag.PrintDefaults() - fmt.Println("\nPlease note that options must always specified BEFORE the command\non the command line or they will be ignored.\n") - fmt.Println("Commands:\n - Use \"list\" for a list of available commands\n") + fmt.Println("\nPlease note that options must always specified BEFORE the command\non the command line or they will be ignored.\n") // nolint:govet + fmt.Println("Commands:\n - Use \"list\" for a list of available commands\n") // nolint:govet fmt.Println("Examples:") fmt.Println(" - ", os.Args[0], "list") fmt.Println(" - ", os.Args[0], "getPeers") diff --git a/src/core/core.go b/src/core/core.go index b98776b..de916c1 100644 --- a/src/core/core.go +++ b/src/core/core.go @@ -158,7 +158,7 @@ func (c *Core) _stop() { c.addPeerTimer.Stop() c.addPeerTimer = nil } - c.links.stop() + _ = c.links.stop() /* FIXME this deadlocks, need a waitgroup or something to coordinate shutdown for _, peer := range c.GetPeers() { c.DisconnectPeer(peer.Port) diff --git a/src/core/link.go b/src/core/link.go index b4cd15f..51b679a 100644 --- a/src/core/link.go +++ b/src/core/link.go @@ -250,15 +250,3 @@ func (intf *link) close() { func (intf *link) name() string { return intf.lname } - -func (intf *link) local() string { - return intf.info.local -} - -func (intf *link) remote() string { - return intf.info.remote -} - -func (intf *link) interfaceType() string { - return intf.info.linkType -} diff --git a/src/core/tcp.go b/src/core/tcp.go index 17e3766..21a3ba7 100644 --- a/src/core/tcp.go +++ b/src/core/tcp.go @@ -67,7 +67,7 @@ type tcpOptions struct { } func (l *TcpListener) Stop() { - defer func() { recover() }() + defer func() { _ = recover() }() close(l.stop) } @@ -75,7 +75,7 @@ func (l *TcpListener) Stop() { func (t *tcp) setExtraOptions(c net.Conn) { switch sock := c.(type) { case *net.TCPConn: - sock.SetNoDelay(true) + _ = sock.SetNoDelay(true) // TODO something for socks5 default: } diff --git a/src/multicast/multicast.go b/src/multicast/multicast.go index 02ff0c4..8f8054d 100644 --- a/src/multicast/multicast.go +++ b/src/multicast/multicast.go @@ -91,7 +91,7 @@ func (m *Multicast) _start() error { return err } m.sock = ipv6.NewPacketConn(conn) - if err = m.sock.SetControlMessage(ipv6.FlagDst, true); err != nil { + if err = m.sock.SetControlMessage(ipv6.FlagDst, true); err != nil { // nolint:staticcheck // Windows can't set this flag, so we need to handle it in other ways } @@ -269,7 +269,7 @@ func (m *Multicast) _announce() { continue } // Join the multicast group - m.sock.JoinGroup(&iface, groupAddr) + _ = m.sock.JoinGroup(&iface, groupAddr) // Try and see if we already have a TCP listener for this interface var info *listenerInfo if nfo, ok := m.listeners[iface.Name]; !ok || nfo.listener.Listener == nil { @@ -304,7 +304,7 @@ func (m *Multicast) _announce() { a.Zone = "" destAddr.Zone = iface.Name msg := []byte(a.String()) - m.sock.WriteTo(msg, nil, destAddr) + _, _ = m.sock.WriteTo(msg, nil, destAddr) } if info.interval.Seconds() < 15 { info.interval += time.Second diff --git a/src/multicast/multicast_darwin.go b/src/multicast/multicast_darwin.go index ceff5b4..e7075c0 100644 --- a/src/multicast/multicast_darwin.go +++ b/src/multicast/multicast_darwin.go @@ -29,8 +29,6 @@ import ( "golang.org/x/sys/unix" ) -var awdlGoroutineStarted bool - func (m *Multicast) _multicastStarted() { if !m.isOpen { return diff --git a/src/tuntap/iface.go b/src/tuntap/iface.go index 81fbe4d..da66e9d 100644 --- a/src/tuntap/iface.go +++ b/src/tuntap/iface.go @@ -123,16 +123,12 @@ func (tun *TunAdapter) write() { continue // bad remote address/subnet } bs = buf[:TUN_OFFSET_BYTES+len(bs)] - n, err = tun.iface.Write(bs, TUN_OFFSET_BYTES) - if err != nil { + if _, err = tun.iface.Write(bs, TUN_OFFSET_BYTES); err != nil { tun.Act(nil, func() { if !tun.isOpen { tun.log.Errorln("TUN iface write error:", err) } }) } - if n != len(bs) { - // TODO some kind of error reporting for a partial write - } } } diff --git a/src/tuntap/keystore.go b/src/tuntap/keystore.go index 7974874..03f429f 100644 --- a/src/tuntap/keystore.go +++ b/src/tuntap/keystore.go @@ -50,7 +50,7 @@ func (k *keyStore) sendToAddress(addr address.Address, bs []byte) { if info := k.addrToInfo[addr]; info != nil { k.resetTimeout(info) k.mutex.Unlock() - k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) + _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) } else { var buf *buffer if buf = k.addrBuffer[addr]; buf == nil { @@ -79,7 +79,7 @@ func (k *keyStore) sendToSubnet(subnet address.Subnet, bs []byte) { if info := k.subnetToInfo[subnet]; info != nil { k.resetTimeout(info) k.mutex.Unlock() - k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) + _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) } else { var buf *buffer if buf = k.subnetBuffer[subnet]; buf == nil { @@ -132,13 +132,13 @@ func (k *keyStore) update(key ed25519.PublicKey) *keyInfo { k.mutex.Unlock() if buf := k.addrBuffer[info.address]; buf != nil { for _, bs := range buf.packets { - k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) + _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) } delete(k.addrBuffer, info.address) } if buf := k.subnetBuffer[info.subnet]; buf != nil { for _, bs := range buf.packets { - k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) + _, _ = k.tun.core.WriteTo(bs, iwt.Addr(info.key[:])) } delete(k.subnetBuffer, info.subnet) } diff --git a/src/tuntap/nodeinfo.go b/src/tuntap/nodeinfo.go index 3249b20..a61a442 100644 --- a/src/tuntap/nodeinfo.go +++ b/src/tuntap/nodeinfo.go @@ -129,7 +129,7 @@ func (m *nodeinfo) _sendReq(key keyArray, callback func(nodeinfo NodeInfoPayload if callback != nil { m._addCallback(key, callback) } - m.proto.tun.core.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:])) + _, _ = m.proto.tun.core.WriteTo([]byte{typeSessionProto, typeProtoNodeInfoRequest}, iwt.Addr(key[:])) } func (m *nodeinfo) handleReq(from phony.Actor, key keyArray) { @@ -146,7 +146,7 @@ func (m *nodeinfo) handleRes(from phony.Actor, key keyArray, info NodeInfoPayloa func (m *nodeinfo) _sendRes(key keyArray) { bs := append([]byte{typeSessionProto, typeProtoNodeInfoResponse}, m._getNodeInfo()...) - m.proto.tun.core.WriteTo(bs, iwt.Addr(key[:])) + _, _ = m.proto.tun.core.WriteTo(bs, iwt.Addr(key[:])) } // Admin socket stuff diff --git a/src/tuntap/proto.go b/src/tuntap/proto.go index 79d84b2..62b2156 100644 --- a/src/tuntap/proto.go +++ b/src/tuntap/proto.go @@ -209,7 +209,7 @@ func (p *protoHandler) _handleGetDHTResponse(key keyArray, bs []byte) { func (p *protoHandler) _sendDebug(key keyArray, dType uint8, data []byte) { bs := append([]byte{typeSessionProto, typeProtoDebug, dType}, data...) - p.tun.core.WriteTo(bs, iwt.Addr(key[:])) + _, _ = p.tun.core.WriteTo(bs, iwt.Addr(key[:])) } // Admin socket stuff diff --git a/src/tuntap/tun.go b/src/tuntap/tun.go index ecc7c06..c1b90e7 100644 --- a/src/tuntap/tun.go +++ b/src/tuntap/tun.go @@ -221,13 +221,13 @@ func (tun *TunAdapter) oobHandler(fromKey, toKey ed25519.PublicKey, data []byte) func (tun *TunAdapter) sendKeyLookup(partial ed25519.PublicKey) { sig := ed25519.Sign(tun.core.PrivateKey(), partial[:]) bs := append([]byte{typeKeyLookup}, sig...) - tun.core.SendOutOfBand(partial, bs) + _ = tun.core.SendOutOfBand(partial, bs) } func (tun *TunAdapter) sendKeyResponse(dest ed25519.PublicKey) { sig := ed25519.Sign(tun.core.PrivateKey(), dest[:]) bs := append([]byte{typeKeyResponse}, sig...) - tun.core.SendOutOfBand(dest, bs) + _ = tun.core.SendOutOfBand(dest, bs) } func (tun *TunAdapter) maxSessionMTU() uint64 { diff --git a/src/tuntap/tun_darwin.go b/src/tuntap/tun_darwin.go index 609b42e..060ad14 100644 --- a/src/tuntap/tun_darwin.go +++ b/src/tuntap/tun_darwin.go @@ -40,26 +40,29 @@ const ( darwin_ND6_INFINITE_LIFETIME = 0xFFFFFFFF // netinet6/nd6.h ) +// nolint:structcheck type in6_addrlifetime struct { - ia6t_expire float64 - ia6t_preferred float64 + ia6t_expire float64 // nolint:unused + ia6t_preferred float64 // nolint:unused ia6t_vltime uint32 ia6t_pltime uint32 } +// nolint:structcheck type sockaddr_in6 struct { sin6_len uint8 sin6_family uint8 - sin6_port uint8 - sin6_flowinfo uint32 + sin6_port uint8 // nolint:unused + sin6_flowinfo uint32 // nolint:unused sin6_addr [8]uint16 - sin6_scope_id uint32 + sin6_scope_id uint32 // nolint:unused } +// nolint:structcheck type in6_aliasreq struct { ifra_name [16]byte ifra_addr sockaddr_in6 - ifra_dstaddr sockaddr_in6 + ifra_dstaddr sockaddr_in6 // nolint:unused ifra_prefixmask sockaddr_in6 ifra_flags uint32 ifra_lifetime in6_addrlifetime diff --git a/src/tuntap/types.go b/src/tuntap/types.go index 4d8bba1..a8084e0 100644 --- a/src/tuntap/types.go +++ b/src/tuntap/types.go @@ -2,14 +2,14 @@ package tuntap // Out-of-band packet types const ( - typeKeyDummy = iota + typeKeyDummy = iota // nolint:deadcode,varcheck typeKeyLookup typeKeyResponse ) // In-band packet types const ( - typeSessionDummy = iota + typeSessionDummy = iota // nolint:deadcode,varcheck typeSessionTraffic typeSessionProto )