diff --git a/go-controller/go.mod b/go-controller/go.mod index 9884229455..3e034792af 100644 --- a/go-controller/go.mod +++ b/go-controller/go.mod @@ -130,4 +130,5 @@ replace ( github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.8.20 github.com/coreos/go-iptables => github.com/trozet/go-iptables v0.0.0-20240328221912-077e672b3808 github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 + github.com/j-keck/arping => github.com/JacobTanenbaum/arping v0.0.0-20240209152419-3987db83bd51 ) diff --git a/go-controller/go.sum b/go-controller/go.sum index e911cddd1d..4867947195 100644 --- a/go-controller/go.sum +++ b/go-controller/go.sum @@ -59,6 +59,8 @@ github.com/Azure/go-autorest/tracing v0.6.0/go.mod h1:+vhtPC754Xsa23ID7GlGsrdKBp github.com/BurntSushi/toml v0.3.1 h1:WXkYYl6Yr3qBf1K79EBnL4mak0OimBfB0XUf9Vl28OQ= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo= +github.com/JacobTanenbaum/arping v0.0.0-20240209152419-3987db83bd51 h1:1SKfGydyhYFbei8ZThFEeLNEjN3M7CCTssgkGuru93Q= +github.com/JacobTanenbaum/arping v0.0.0-20240209152419-3987db83bd51/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw= github.com/Microsoft/go-winio v0.4.11/go.mod h1:VhR8bwka0BXejwEJY73c50VrPtXAaKcyvVC4A4RozmA= github.com/Microsoft/go-winio v0.4.14/go.mod h1:qXqCSQ3Xa7+6tgxaGTIe4Kpcdsi+P8jBhyzoq1bpyYA= github.com/Microsoft/go-winio v0.4.16-0.20201130162521-d1ffc52c7331/go.mod h1:XB6nPKklQyQ7GC9LdcBEcBl8PF76WugXOPRXwdLnMv0= @@ -455,9 +457,6 @@ github.com/imdario/mergo v0.3.11/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH github.com/imdario/mergo v0.3.12 h1:b6R2BslTbIEToALKP7LxUvijTsNI9TAe80pLWN2g/HU= github.com/imdario/mergo v0.3.12/go.mod h1:jmQim1M+e3UYxmgPu/WyfjB3N3VflVyUjjjwH0dnCYA= github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8= -github.com/j-keck/arping v0.0.0-20160618110441-2cf9dc699c56/go.mod h1:ymszkNOg6tORTn+6F6j+Jc8TOr5osrynvN6ivFWZ2GA= -github.com/j-keck/arping v1.0.2 h1:hlLhuXgQkzIJTZuhMigvG/CuSkaspeaD9hRDk2zuiMI= -github.com/j-keck/arping v1.0.2/go.mod h1:aJbELhR92bSk7tp79AWM/ftfc90EfEi2bQJrbBFOsPw= github.com/jessevdk/go-flags v1.4.0/go.mod h1:4FA24M0QyGHXBuZZK/XkWh8h0e1EYbRYJSGM75WSRxI= github.com/jmespath/go-jmespath v0.0.0-20160202185014-0b12d6b521d8/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= github.com/jmespath/go-jmespath v0.0.0-20160803190731-bd40a432e4c7/go.mod h1:Nht3zPeWKUH0NzdCt2Blrr5ys8VGpn0CEB0cQHVjt7k= diff --git a/go-controller/vendor/github.com/j-keck/arping/arping.go b/go-controller/vendor/github.com/j-keck/arping/arping.go index b305731db0..570ef9d803 100644 --- a/go-controller/vendor/github.com/j-keck/arping/arping.go +++ b/go-controller/vendor/github.com/j-keck/arping/arping.go @@ -121,7 +121,6 @@ func PingOverIface(dstIP net.IP, iface net.Interface) (net.HardwareAddr, time.Du if err != nil { return nil, 0, err } - defer sock.deinitialize() type PingResult struct { mac net.HardwareAddr @@ -131,6 +130,7 @@ func PingOverIface(dstIP net.IP, iface net.Interface) (net.HardwareAddr, time.Du pingResultChan := make(chan PingResult, 1) go func() { + defer sock.deinitialize() // send arp request verboseLog.Printf("arping '%s' over interface: '%s' with address: '%s'\n", dstIP, iface.Name, srcIP) if sendTime, err := sock.send(request); err != nil { @@ -163,7 +163,6 @@ func PingOverIface(dstIP net.IP, iface net.Interface) (net.HardwareAddr, time.Du case pingResult := <-pingResultChan: return pingResult.mac, pingResult.duration, pingResult.err case <-time.After(timeout): - sock.deinitialize() return nil, 0, ErrTimeout } } diff --git a/go-controller/vendor/github.com/j-keck/arping/arping_bsd.go b/go-controller/vendor/github.com/j-keck/arping/arping_bsd.go index 5176fc65bd..5b2ed101ea 100644 --- a/go-controller/vendor/github.com/j-keck/arping/arping_bsd.go +++ b/go-controller/vendor/github.com/j-keck/arping/arping_bsd.go @@ -96,6 +96,11 @@ func (s *BsdSocket) receive() (arpDatagram, time.Time, error) { // skip bpf header + 14 bytes ethernet header var hdrLength = bpfHdrLength + 14 + if n <= hdrLength || len(buffer) <= hdrLength { + // amount of bytes read by socket is less than an ethernet header. clearly not what we look for + return arpDatagram{}, time.Now(), fmt.Errorf("buffer with invalid length") + + } return parseArpDatagram(buffer[hdrLength:n]), time.Now(), nil } diff --git a/go-controller/vendor/github.com/j-keck/arping/arping_linux.go b/go-controller/vendor/github.com/j-keck/arping/arping_linux.go index b03df6c965..9492a5ed50 100644 --- a/go-controller/vendor/github.com/j-keck/arping/arping_linux.go +++ b/go-controller/vendor/github.com/j-keck/arping/arping_linux.go @@ -1,6 +1,7 @@ package arping import ( + "fmt" "net" "syscall" "time" @@ -22,18 +23,26 @@ func initialize(iface net.Interface) (s *LinuxSocket, err error) { } func (s *LinuxSocket) send(request arpDatagram) (time.Time, error) { + socketTimeout := timeout.Nanoseconds() + t := syscall.NsecToTimeval(socketTimeout) + syscall.SetsockoptTimeval(s.sock, syscall.SOL_SOCKET, syscall.SO_SNDTIMEO, &t) return time.Now(), syscall.Sendto(s.sock, request.MarshalWithEthernetHeader(), 0, &s.toSockaddr) } func (s *LinuxSocket) receive() (arpDatagram, time.Time, error) { buffer := make([]byte, 128) - socketTimeout := timeout.Nanoseconds() * 2 + socketTimeout := timeout.Nanoseconds() t := syscall.NsecToTimeval(socketTimeout) syscall.SetsockoptTimeval(s.sock, syscall.SOL_SOCKET, syscall.SO_RCVTIMEO, &t) n, _, err := syscall.Recvfrom(s.sock, buffer, 0) if err != nil { return arpDatagram{}, time.Now(), err } + if n <= 14 { + // amount of bytes read by socket is less than an ethernet header. clearly not what we look for + return arpDatagram{}, time.Now(), fmt.Errorf("buffer with invalid length") + + } // skip 14 bytes ethernet header return parseArpDatagram(buffer[14:n]), time.Now(), nil } diff --git a/go-controller/vendor/github.com/j-keck/arping/arping_windows.go b/go-controller/vendor/github.com/j-keck/arping/arping_windows.go deleted file mode 100644 index abe302d915..0000000000 --- a/go-controller/vendor/github.com/j-keck/arping/arping_windows.go +++ /dev/null @@ -1,28 +0,0 @@ -// windows currently not supported. -// dummy implementation to prevent compilation errors under windows - -package arping - -import ( - "errors" - "net" - "time" -) - -var errWindowsNotSupported = errors.New("arping under windows not supported") - -func initialize(iface net.Interface) error { - return errWindowsNotSupported -} - -func send(request arpDatagram) (time.Time, error) { - return time.Now(), errWindowsNotSupported -} - -func receive() (arpDatagram, time.Time, error) { - return arpDatagram{}, time.Now(), errWindowsNotSupported -} - -func deinitialize() error { - return errWindowsNotSupported -} diff --git a/go-controller/vendor/modules.txt b/go-controller/vendor/modules.txt index 71e0a1c86a..4fd80d9cb9 100644 --- a/go-controller/vendor/modules.txt +++ b/go-controller/vendor/modules.txt @@ -160,7 +160,7 @@ github.com/gorilla/mux # github.com/imdario/mergo v0.3.12 ## explicit; go 1.13 github.com/imdario/mergo -# github.com/j-keck/arping v1.0.2 +# github.com/j-keck/arping v1.0.2 => github.com/JacobTanenbaum/arping v0.0.0-20240209152419-3987db83bd51 ## explicit; go 1.12 github.com/j-keck/arping # github.com/josharian/intern v1.0.0 @@ -1142,3 +1142,4 @@ sigs.k8s.io/yaml # github.com/Microsoft/hcsshim => github.com/Microsoft/hcsshim v0.8.20 # github.com/coreos/go-iptables => github.com/trozet/go-iptables v0.0.0-20240328221912-077e672b3808 # github.com/gogo/protobuf => github.com/gogo/protobuf v1.3.2 +# github.com/j-keck/arping => github.com/JacobTanenbaum/arping v0.0.0-20240209152419-3987db83bd51