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
|
||||
|
||||
import (
|
||||
"context"
|
||||
"fmt"
|
||||
"net"
|
||||
"syscall"
|
||||
|
||||
"golang.org/x/net/ipv6"
|
||||
"inet.af/netaddr"
|
||||
|
@ -34,10 +36,21 @@ func Listen(group string, port uint16, ifaces ...string) (Conn, error) {
|
|||
func ListenPort(port uint16) (Conn, error) {
|
||||
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 {
|
||||
return c, err
|
||||
}
|
||||
|
||||
c.v6pc = ipv6.NewPacketConn(uc)
|
||||
|
||||
return c, c.v6pc.SetControlMessage(
|
||||
|
|
Loading…
Reference in New Issue