From 0e40b41aa1e517a62d6076c4e7a57c607792ef01 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Wed, 10 Jul 2024 15:28:16 +0300 Subject: [PATCH] dhcpsvc: imp code, docs --- internal/dhcpsvc/interface.go | 3 ++- internal/dhcpsvc/server.go | 4 ++-- internal/dhcpsvc/v6.go | 9 +++++---- 3 files changed, 9 insertions(+), 7 deletions(-) diff --git a/internal/dhcpsvc/interface.go b/internal/dhcpsvc/interface.go index 19aeef77..87c3de4d 100644 --- a/internal/dhcpsvc/interface.go +++ b/internal/dhcpsvc/interface.go @@ -13,7 +13,8 @@ import ( type macKey any // macToKey converts mac into macKey, which is used as the key for the lease -// maps. +// maps. mac must be a valid hardware address of length 6, 8, or 20 bytes, see +// [netutil.ValidateMAC]. func macToKey(mac net.HardwareAddr) (key macKey) { switch len(mac) { case 6: diff --git a/internal/dhcpsvc/server.go b/internal/dhcpsvc/server.go index fdb651df..c8bab6e6 100644 --- a/internal/dhcpsvc/server.go +++ b/internal/dhcpsvc/server.go @@ -105,8 +105,8 @@ func newInterfaces( // TODO(e.burkov): Add validations scoped to the network interfaces set. v4 = make(dhcpInterfacesV4, 0, len(ifaces)) v6 = make(dhcpInterfacesV6, 0, len(ifaces)) - var errs []error + var errs []error mapsutil.SortedRange(ifaces, func(name string, iface *InterfaceConfig) (cont bool) { var i4 *dhcpInterfaceV4 i4, err = newDHCPInterfaceV4(ctx, l, name, iface.IPv4) @@ -216,7 +216,7 @@ func (srv *DHCPServer) resetLeases() { iface.common.reset() } for _, iface := range srv.interfaces6 { - iface.netInterface.reset() + iface.common.reset() } srv.leases.clear() } diff --git a/internal/dhcpsvc/v6.go b/internal/dhcpsvc/v6.go index a7598dcc..dd75184e 100644 --- a/internal/dhcpsvc/v6.go +++ b/internal/dhcpsvc/v6.go @@ -64,8 +64,9 @@ func (c *IPv6Config) validate() (err error) { // dhcpInterfaceV6 is a DHCP interface for IPv6 address family. type dhcpInterfaceV6 struct { - // netInterface is a network interface handled by DHCP. - netInterface *netInterface + // common is the common part of any network interface within the DHCP + // server. + common *netInterface // rangeStart is the first IP address in the range. rangeStart netip.Addr @@ -106,7 +107,7 @@ func newDHCPInterfaceV6( i = &dhcpInterfaceV6{ rangeStart: conf.RangeStart, - netInterface: newNetInterface(name, l, conf.LeaseDuration), + common: newNetInterface(name, l, conf.LeaseDuration), raSLAACOnly: conf.RASLAACOnly, raAllowSLAAC: conf.RAAllowSLAAC, } @@ -137,7 +138,7 @@ func (ifaces dhcpInterfacesV6) find(ip netip.Addr) (iface6 *netInterface, ok boo return nil, false } - return ifaces[i].netInterface, true + return ifaces[i].common, true } // options returns the implicit and explicit options for the interface. The two