packet: set SO_REUSEADDR on babel port
This allows to listen to incoming babel packets along side another babel instance.
This commit is contained in:
parent
5d3ff44341
commit
cbf92bec2e
|
@ -1,8 +1,10 @@
|
||||||
package packet
|
package packet
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"context"
|
||||||
"fmt"
|
"fmt"
|
||||||
"net"
|
"net"
|
||||||
|
"syscall"
|
||||||
|
|
||||||
"golang.org/x/net/ipv6"
|
"golang.org/x/net/ipv6"
|
||||||
"inet.af/netaddr"
|
"inet.af/netaddr"
|
||||||
|
@ -34,10 +36,21 @@ func Listen(group string, port uint16, ifaces ...string) (Conn, error) {
|
||||||
func ListenPort(port uint16) (Conn, error) {
|
func ListenPort(port uint16) (Conn, error) {
|
||||||
var c Conn
|
var c Conn
|
||||||
|
|
||||||
uc, err := net.ListenUDP("udp6", &net.UDPAddr{Port: int(port)})
|
lc := net.ListenConfig{
|
||||||
|
Control: func(network, address string, c syscall.RawConn) error {
|
||||||
|
var err error
|
||||||
|
c.Control(func(fd uintptr) {
|
||||||
|
err = syscall.SetsockoptInt(int(fd), syscall.SOL_SOCKET, syscall.SO_REUSEADDR, 1)
|
||||||
|
})
|
||||||
|
return err
|
||||||
|
},
|
||||||
|
}
|
||||||
|
uc, err := lc.ListenPacket(context.Background(), "udp6", fmt.Sprintf(":%d", port))
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return c, err
|
return c, err
|
||||||
}
|
}
|
||||||
|
|
||||||
c.v6pc = ipv6.NewPacketConn(uc)
|
c.v6pc = ipv6.NewPacketConn(uc)
|
||||||
|
|
||||||
return c, c.v6pc.SetControlMessage(
|
return c, c.v6pc.SetControlMessage(
|
||||||
|
|
Loading…
Reference in New Issue