From 552b84f630fdfc386dc5fa101531327d6b95bcb2 Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Sat, 2 Oct 2021 17:19:13 +0200 Subject: [PATCH] collector: set IPV6_MULTICAST_IF on UDP socket Required to use the correct interface for non-link-local bind address. Closes: #167 --- go.mod | 2 +- go.sum | 2 ++ respond/collector.go | 16 ++++++++++++++++ 3 files changed, 19 insertions(+), 1 deletion(-) diff --git a/go.mod b/go.mod index 0c09c20..7bbd349 100644 --- a/go.mod +++ b/go.mod @@ -19,7 +19,7 @@ require ( github.com/stretchr/testify v1.5.1 github.com/tidwall/gjson v1.6.5 golang.org/x/net v0.0.0-20201021035429-f5854403a974 // indirect - golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 // indirect + golang.org/x/sys v0.0.0-20211002104244-808efd93c36d // indirect golang.org/x/xerrors v0.0.0-20200804184101-5ec99f83aff1 // indirect gopkg.in/fgrosse/graphigo.v2 v2.0.0-20151220153422-55a0a92a7030 // indirect gopkg.in/yaml.v2 v2.2.8 // indirect diff --git a/go.sum b/go.sum index cd1d2c9..868dd8f 100644 --- a/go.sum +++ b/go.sum @@ -165,6 +165,8 @@ golang.org/x/sys v0.0.0-20191120155948-bd437916bb0e/go.mod h1:h1NjWce9XRLGQEsW7w golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4 h1:myAQVi0cGEoqQVR5POX+8RR2mrocKqNN1hmeMqhX27k= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= +golang.org/x/sys v0.0.0-20211002104244-808efd93c36d h1:SABT8Vei3iTiu+Gy8KOzpSNz+W1EQ5YBCRtiEETxF+0= +golang.org/x/sys v0.0.0-20211002104244-808efd93c36d/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3 h1:cokOdA+Jmi5PJGXLlLllQSgYigAEfHXJAERHVMaCc2k= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= diff --git a/respond/collector.go b/respond/collector.go index 97037d7..79472b1 100644 --- a/respond/collector.go +++ b/respond/collector.go @@ -5,6 +5,8 @@ import ( "net" "time" + "golang.org/x/sys/unix" + "github.com/bdlm/log" "github.com/FreifunkBremen/yanic/data" @@ -89,6 +91,20 @@ func (coll *Collector) listenUDP(iface InterfaceConfig) { } conn.SetReadBuffer(MaxDataGramSize) + raw, err := conn.SyscallConn() + if err != nil { + log.Panic(err) + } + err = raw.Control(func(fd uintptr) { + err = unix.SetsockoptInt(int(fd), unix.IPPROTO_IPV6, unix.IPV6_MULTICAST_IF, ifaceInfo.Index) + if err != nil { + log.Panic(err) + } + }) + if err != nil { + log.Panic(err) + } + coll.connections = append(coll.connections, multicastConn{ Conn: conn, SendRequest: !iface.SendNoRequest,