dhcpsvc: imp code, docs

This commit is contained in:
Eugene Burkov 2024-07-10 15:28:16 +03:00
parent 5463fdde47
commit 0e40b41aa1
3 changed files with 9 additions and 7 deletions

View file

@ -13,7 +13,8 @@ import (
type macKey any type macKey any
// macToKey converts mac into macKey, which is used as the key for the lease // 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) { func macToKey(mac net.HardwareAddr) (key macKey) {
switch len(mac) { switch len(mac) {
case 6: case 6:

View file

@ -105,8 +105,8 @@ func newInterfaces(
// TODO(e.burkov): Add validations scoped to the network interfaces set. // TODO(e.burkov): Add validations scoped to the network interfaces set.
v4 = make(dhcpInterfacesV4, 0, len(ifaces)) v4 = make(dhcpInterfacesV4, 0, len(ifaces))
v6 = make(dhcpInterfacesV6, 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) { mapsutil.SortedRange(ifaces, func(name string, iface *InterfaceConfig) (cont bool) {
var i4 *dhcpInterfaceV4 var i4 *dhcpInterfaceV4
i4, err = newDHCPInterfaceV4(ctx, l, name, iface.IPv4) i4, err = newDHCPInterfaceV4(ctx, l, name, iface.IPv4)
@ -216,7 +216,7 @@ func (srv *DHCPServer) resetLeases() {
iface.common.reset() iface.common.reset()
} }
for _, iface := range srv.interfaces6 { for _, iface := range srv.interfaces6 {
iface.netInterface.reset() iface.common.reset()
} }
srv.leases.clear() srv.leases.clear()
} }

View file

@ -64,8 +64,9 @@ func (c *IPv6Config) validate() (err error) {
// dhcpInterfaceV6 is a DHCP interface for IPv6 address family. // dhcpInterfaceV6 is a DHCP interface for IPv6 address family.
type dhcpInterfaceV6 struct { type dhcpInterfaceV6 struct {
// netInterface is a network interface handled by DHCP. // common is the common part of any network interface within the DHCP
netInterface *netInterface // server.
common *netInterface
// rangeStart is the first IP address in the range. // rangeStart is the first IP address in the range.
rangeStart netip.Addr rangeStart netip.Addr
@ -106,7 +107,7 @@ func newDHCPInterfaceV6(
i = &dhcpInterfaceV6{ i = &dhcpInterfaceV6{
rangeStart: conf.RangeStart, rangeStart: conf.RangeStart,
netInterface: newNetInterface(name, l, conf.LeaseDuration), common: newNetInterface(name, l, conf.LeaseDuration),
raSLAACOnly: conf.RASLAACOnly, raSLAACOnly: conf.RASLAACOnly,
raAllowSLAAC: conf.RAAllowSLAAC, raAllowSLAAC: conf.RAAllowSLAAC,
} }
@ -137,7 +138,7 @@ func (ifaces dhcpInterfacesV6) find(ip netip.Addr) (iface6 *netInterface, ok boo
return nil, false 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 // options returns the implicit and explicit options for the interface. The two