Skip to content

Commit

Permalink
dhcpsvc: imp code, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jul 10, 2024
1 parent 5463fdd commit 0e40b41
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 7 deletions.
3 changes: 2 additions & 1 deletion internal/dhcpsvc/interface.go
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
4 changes: 2 additions & 2 deletions internal/dhcpsvc/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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()
}
Expand Down
9 changes: 5 additions & 4 deletions internal/dhcpsvc/v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 0e40b41

Please sign in to comment.