Browse Source

Merge pull request #1973 from gravitl/bugfix_staticchecks

Fix static checks
dcarns 2 years ago
parent
commit
a5aa510b20

+ 10 - 16
nm-proxy/manager/manager.go

@@ -67,23 +67,17 @@ type ManagerAction struct {
 }
 }
 
 
 func StartProxyManager(manageChan chan *ManagerAction) {
 func StartProxyManager(manageChan chan *ManagerAction) {
-	for {
-
-		select {
-		case mI := <-manageChan:
-			log.Printf("-------> PROXY-MANAGER: %+v\n", mI)
-			switch mI.Action {
-			case AddInterface:
-
-				mI.SetIngressGateway()
-				err := mI.AddInterfaceToProxy()
-				if err != nil {
-					log.Printf("failed to add interface: [%s] to proxy: %v\n  ", mI.Payload.InterfaceName, err)
-				}
-			case DeleteInterface:
-				mI.DeleteInterface()
+	for mI := range manageChan {
+		log.Printf("-------> PROXY-MANAGER: %+v\n", mI)
+		switch mI.Action {
+		case AddInterface:
+			mI.SetIngressGateway()
+			err := mI.AddInterfaceToProxy()
+			if err != nil {
+				log.Printf("failed to add interface: [%s] to proxy: %v\n  ", mI.Payload.InterfaceName, err)
 			}
 			}
-
+		case DeleteInterface:
+			mI.DeleteInterface()
 		}
 		}
 	}
 	}
 }
 }

+ 4 - 3
nm-proxy/packet/packet_helper.go

@@ -3,11 +3,12 @@ package packet
 import (
 import (
 	"golang.org/x/crypto/blake2s"
 	"golang.org/x/crypto/blake2s"
 	"golang.org/x/crypto/chacha20poly1305"
 	"golang.org/x/crypto/chacha20poly1305"
-	"golang.org/x/crypto/poly1305"
 	"golang.zx2c4.com/wireguard/tai64n"
 	"golang.zx2c4.com/wireguard/tai64n"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 	"golang.zx2c4.com/wireguard/wgctrl/wgtypes"
 )
 )
 
 
+const poly1305TagSize = 16
+
 var (
 var (
 	InitialChainKey [blake2s.Size]byte
 	InitialChainKey [blake2s.Size]byte
 	InitialHash     [blake2s.Size]byte
 	InitialHash     [blake2s.Size]byte
@@ -23,8 +24,8 @@ type MessageInitiation struct {
 	Type      MessageType
 	Type      MessageType
 	Sender    uint32
 	Sender    uint32
 	Ephemeral NoisePublicKey
 	Ephemeral NoisePublicKey
-	Static    [NoisePublicKeySize + poly1305.TagSize]byte
-	Timestamp [tai64n.TimestampSize + poly1305.TagSize]byte
+	Static    [NoisePublicKeySize + poly1305TagSize]byte
+	Timestamp [tai64n.TimestampSize + poly1305TagSize]byte
 	MAC1      [blake2s.Size128]byte
 	MAC1      [blake2s.Size128]byte
 	MAC2      [blake2s.Size128]byte
 	MAC2      [blake2s.Size128]byte
 }
 }

+ 1 - 0
nm-proxy/packet/utils.go

@@ -108,6 +108,7 @@ type (
 func sharedSecret(sk *NoisePrivateKey, pk NoisePublicKey) (ss [NoisePublicKeySize]byte) {
 func sharedSecret(sk *NoisePrivateKey, pk NoisePublicKey) (ss [NoisePublicKeySize]byte) {
 	apk := (*[NoisePublicKeySize]byte)(&pk)
 	apk := (*[NoisePublicKeySize]byte)(&pk)
 	ask := (*[NoisePrivateKeySize]byte)(sk)
 	ask := (*[NoisePrivateKeySize]byte)(sk)
+	//lint:ignore SA1019 no need of back and forth conversion between arrays and slices required by curve25519.X25519 function
 	curve25519.ScalarMult(&ss, ask, apk)
 	curve25519.ScalarMult(&ss, ask, apk)
 	return ss
 	return ss
 }
 }

+ 0 - 22
nm-proxy/proxy/proxy.go

@@ -2,7 +2,6 @@ package proxy
 
 
 import (
 import (
 	"context"
 	"context"
-	"errors"
 	"fmt"
 	"fmt"
 	"log"
 	"log"
 	"net"
 	"net"
@@ -97,27 +96,6 @@ func GetInterfaceListenAddr(port int) (*net.UDPAddr, error) {
 	return udpAddr, nil
 	return udpAddr, nil
 }
 }
 
 
-func getBoardCastAddress() ([]net.Addr, error) {
-	localnets, err := net.Interfaces()
-	if err != nil {
-		return nil, err
-	}
-	var (
-		ief   net.Interface
-		addrs []net.Addr
-	)
-	for _, ief = range localnets {
-		if ief.Flags&net.FlagBroadcast != 0 && ief.Flags&net.FlagUp != 0 {
-			addrs, err = ief.Addrs()
-			if err == nil {
-				return addrs, nil
-			}
-
-		}
-	}
-	return nil, errors.New("couldn't obtain the broadcast addr")
-}
-
 // func StartSniffer(ctx context.Context, ifaceName, ingGwAddr, extClientAddr string, port int) {
 // func StartSniffer(ctx context.Context, ifaceName, ingGwAddr, extClientAddr string, port int) {
 // 	log.Println("Starting Packet Sniffer for iface: ", ifaceName)
 // 	log.Println("Starting Packet Sniffer for iface: ", ifaceName)
 // 	var (
 // 	var (

+ 0 - 6
nm-proxy/proxy/proxy_helper.go

@@ -174,12 +174,6 @@ func (p *Proxy) ProxyPeer() {
 	wg.Wait()
 	wg.Wait()
 
 
 }
 }
-func test(n int, buffer []byte) {
-	data := buffer[:n]
-	srcKeyHash := data[n-32 : n-16]
-	dstKeyHash := data[n-16:]
-	log.Printf("--------> TEST PACKET [ SRCKEYHASH: %x ], [ DSTKEYHASH: %x ] \n", srcKeyHash, dstKeyHash)
-}
 
 
 func (p *Proxy) updateEndpoint() error {
 func (p *Proxy) updateEndpoint() error {
 	udpAddr, err := net.ResolveUDPAddr("udp", p.LocalConn.LocalAddr().String())
 	udpAddr, err := net.ResolveUDPAddr("udp", p.LocalConn.LocalAddr().String())