Skip to content

Commit

Permalink
dhcpsvc: imp docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jan 30, 2024
1 parent 310ed67 commit 280a4db
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 3 deletions.
4 changes: 4 additions & 0 deletions internal/dhcpsvc/dhcpsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@ import (
"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
)

// Interface is a DHCP service.
//
// TODO(e.burkov): Separate HostByIP, MACByIP, IPByHost into a separate
// interface. This is also valid for Enabled method.
type Interface interface {
agh.ServiceWithConfig[*Config]

Expand Down
2 changes: 1 addition & 1 deletion internal/dhcpsvc/v4.go
Original file line number Diff line number Diff line change
Expand Up @@ -326,7 +326,7 @@ type netInterfacesV4 []*netInterfaceV4
// find returns the first network interface within ifaces containing ip. It
// returns false if there is no such interface.
func (ifaces netInterfacesV4) find(ip netip.Addr) (iface4 *netInterface, ok bool) {
i := slices.IndexFunc(ifaces, func(iface *netInterfaceV4) bool {
i := slices.IndexFunc(ifaces, func(iface *netInterfaceV4) (contains bool) {
return iface.subnet.Contains(ip)
})
if i < 0 {
Expand Down
14 changes: 12 additions & 2 deletions internal/dhcpsvc/v6.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/AdguardTeam/golibs/log"
"github.com/AdguardTeam/golibs/netutil"
"github.com/google/gopacket/layers"
"golang.org/x/exp/slices"
)
Expand Down Expand Up @@ -140,8 +141,17 @@ type netInterfacesV6 []*netInterfaceV6
// find returns the first network interface within ifaces containing ip. It
// returns false if there is no such interface.
func (ifaces netInterfacesV6) find(ip netip.Addr) (iface6 *netInterface, ok bool) {
i := slices.IndexFunc(ifaces, func(iface *netInterfaceV6) bool {
return !iface.rangeStart.Less(ip) && netip.PrefixFrom(iface.rangeStart, 120).Contains(ip)
// prefLen is the length of prefix to match ip against.
//
// TODO(e.burkov): DHCPv6 inherits the weird behavior of legacy
// implementation where the allocated range constrained by the first address
// and the first address with last byte set to 0xff. Proper prefixes should
// be used instead.
const prefLen = netutil.IPv6BitLen - 8

i := slices.IndexFunc(ifaces, func(iface *netInterfaceV6) (contains bool) {
return !iface.rangeStart.Less(ip) &&
netip.PrefixFrom(iface.rangeStart, prefLen).Contains(ip)
})
if i < 0 {
return nil, false
Expand Down

0 comments on commit 280a4db

Please sign in to comment.