collector: set IPV6_MULTICAST_IF on UDP socket

Required to use the correct interface for non-link-local bind address.

Closes: #167
This commit is contained in:
Matthias Schiffer 2021-10-02 17:19:13 +02:00 committed by genofire
parent 0349e372ac
commit 552b84f630
3 changed files with 19 additions and 1 deletions

2
go.mod
View File

@ -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

2
go.sum
View File

@ -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=

View File

@ -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,