summaryrefslogtreecommitdiffhomepage
path: root/dhcpv6/server6/server.go
diff options
context:
space:
mode:
authorAnatole Denis <natolumin@unverle.fr>2019-09-17 16:02:29 +0200
committerAnatole Denis <natolumin@unverle.fr>2019-09-18 11:13:40 +0200
commita8311dfaca587339aa1d905598ac0f2093ad7ea9 (patch)
tree3f1bf71af187d4a4f12042d44cb4514fae4a3d1c /dhcpv6/server6/server.go
parenteac77666371b0272d980e9ea739cc890957971a9 (diff)
server6: Create UDP conn manually for more control
Similar to server4 where the UDP connection is manually created using the socket interfaces, this creates a connection with adequate options: * SO_BINDTODEVICE or equivalent if an interface is requested * V6ONLY when supported by the operating system * Allows binding to a multicast address specifically instead of falling back to wildcard Signed-off-by: Anatole Denis <natolumin@unverle.fr>
Diffstat (limited to 'dhcpv6/server6/server.go')
-rw-r--r--dhcpv6/server6/server.go32
1 files changed, 22 insertions, 10 deletions
diff --git a/dhcpv6/server6/server.go b/dhcpv6/server6/server.go
index 4506195..ac25076 100644
--- a/dhcpv6/server6/server.go
+++ b/dhcpv6/server6/server.go
@@ -112,9 +112,14 @@ func WithConn(conn net.PacketConn) ServerOpt {
}
}
-// NewServer initializes and returns a new Server object, listening on `addr`,
-// and joining the multicast group ff02::1:2 . If `addr` is nil, IPv6 unspec is
-// used. If `WithConn` is used with a non-nil address, `addr` and `ifname` have
+// NewServer initializes and returns a new Server object, listening on `addr`.
+// * If `addr` is a multicast group, the group will be additionally joined
+// * If `addr` is the wildcard address on the DHCPv6 server port (`[::]:547), the
+// multicast groups All_DHCP_Relay_Agents_and_Servers(`[ff02::1:2]`) and
+// All_DHCP_Servers(`[ff05::1:3]:547`) will be joined.
+// * If `addr` is nil, IPv6 unspec on the DHCP server port is used and the above
+// behaviour applies
+// If `WithConn` is used with a non-nil address, `addr` and `ifname` have
// no effect. In such case, joining the multicast group is the caller's
// responsibility.
func NewServer(ifname string, addr *net.UDPAddr, handler Handler, opt ...ServerOpt) (*Server, error) {
@@ -125,19 +130,21 @@ func NewServer(ifname string, addr *net.UDPAddr, handler Handler, opt ...ServerO
for _, o := range opt {
o(s)
}
-
if s.conn != nil {
return s, nil
}
- var err error
- // no connection provided by the user, create a new one
- s.conn, err = net.ListenUDP("udp6", addr)
- if err != nil {
- return nil, err
+ if addr == nil {
+ addr = &net.UDPAddr{
+ IP: net.IPv6unspecified,
+ Port: dhcpv6.DefaultServerPort,
+ }
}
- var iface *net.Interface
+ var (
+ err error
+ iface *net.Interface
+ )
if ifname == "" {
iface = nil
} else {
@@ -146,6 +153,11 @@ func NewServer(ifname string, addr *net.UDPAddr, handler Handler, opt ...ServerO
return nil, err
}
}
+ // no connection provided by the user, create a new one
+ s.conn, err = NewIPv6UDPConn(ifname, addr)
+ if err != nil {
+ return nil, err
+ }
p := ipv6.NewPacketConn(s.conn)
if addr.IP.IsMulticast() {