Skip to content

Commit

Permalink
all: imp code, names, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Jun 19, 2023
1 parent 4c4613c commit c58284a
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 22 deletions.
5 changes: 3 additions & 2 deletions internal/dhcpd/dhcpd.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,9 @@ const (
defaultBackoff time.Duration = 500 * time.Millisecond
)

// Lease contains the necessary information about a DHCP lease. It's used in
// various places. So don't change it without good reason.
// Lease contains the necessary information about a DHCP lease. It's used as is
// in the database, so don't change it until it's absolutely necessary, see
// [dataVersion].
type Lease struct {
// Expiry is the expiration time of the lease.
Expiry time.Time `json:"expires"`
Expand Down
16 changes: 8 additions & 8 deletions internal/dhcpsvc/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,15 @@ type Config struct {

// InterfaceConfig is the configuration of a single DHCP interface.
type InterfaceConfig struct {
// DHCPv4 is the configuration of DHCP protocol for IPv4.
DHCPv4 *DHCPv4Config
// IPv4 is the configuration of DHCP protocol for IPv4.
IPv4 *IPv4Config

// DHCPv6 is the configuration of DHCP protocol for IPv6.
DHCPv6 *DHCPv6Config
// IPv6 is the configuration of DHCP protocol for IPv6.
IPv6 *IPv6Config
}

// DHCPv4Config is the interface-specific configuration for DHCPv4.
type DHCPv4Config struct {
// IPv4Config is the interface-specific configuration for DHCPv4.
type IPv4Config struct {
// GatewayIP is the IPv4 address of the network's gateway. It is used as
// the default gateway for DHCP clients and also used in calculating the
// network-specific broadcast address.
Expand All @@ -61,8 +61,8 @@ type DHCPv4Config struct {
Enabled bool
}

// DHCPv6Config is the interface-specific configuration for DHCPv6.
type DHCPv6Config struct {
// IPv6Config is the interface-specific configuration for DHCPv6.
type IPv6Config struct {
// RangeStart is the first address in the range to assign to DHCP clients.
RangeStart netip.Addr

Expand Down
15 changes: 6 additions & 9 deletions internal/dhcpsvc/dhcpsvc.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@ import (
"time"

"github.com/AdguardTeam/AdGuardHome/internal/next/agh"
"github.com/miekg/dns"
)

// Lease is a DHCP lease.
Expand Down Expand Up @@ -38,6 +37,9 @@ type Lease struct {
type Interface interface {
agh.ServiceWithConfig[*Config]

// Enabled returns true if DHCP provides information about clients.
Enabled() (ok bool)

// HostByIP returns the hostname of the DHCP client with the given IP
// address. The address will be netip.Addr{} if there is no such client,
// due to an assumption that a DHCP client must always have an IP address.
Expand All @@ -54,11 +56,6 @@ type Interface interface {
// hostname, either set by the client or assigned automatically.
IPByHost(host string) (ip netip.Addr)

// IsClientHost returns true if the given question matches one of the DHCP
// client hostnames. It is safe to call this method concurrently, but q
// shouldn't be accessed for writing until it returned.
IsClientHost(q *dns.Question) (ok bool)

// Leases returns all the DHCP leases.
Leases() (leases []*Lease)

Expand Down Expand Up @@ -95,6 +92,9 @@ var _ agh.ServiceWithConfig[*Config] = Empty{}
// Config implements the [ServiceWithConfig] interface for Empty.
func (Empty) Config() (conf *Config) { return nil }

// Enabled implements the [Interface] interface for Empty.
func (Empty) Enabled() (ok bool) { return false }

// HostByIP implements the [Interface] interface for Empty.
func (Empty) HostByIP(_ netip.Addr) (host string) { return "" }

Expand All @@ -104,9 +104,6 @@ func (Empty) MACByIP(_ netip.Addr) (mac net.HardwareAddr) { return nil }
// IPByHost implements the [Interface] interface for Empty.
func (Empty) IPByHost(_ string) (ip netip.Addr) { return netip.Addr{} }

// IsClientHost implements the [Interface] interface for Empty.
func (Empty) IsClientHost(_ *dns.Question) (ok bool) { return false }

// Leases implements the [Interface] interface for Empty.
func (Empty) Leases() (leases []*Lease) { return nil }

Expand Down
5 changes: 2 additions & 3 deletions internal/dnsforward/dnsforward.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,8 @@ type DHCP interface {
// hostname, either set by the client or assigned automatically.
IPByHost(host string) (ip netip.Addr)

// IsClientHost returns true if the given question should be served from
// DHCP lease data. q shouldn't be accessed for writing until it returned.
IsClientHost(q *dns.Question) (ok bool)
// Enabled returns true if DHCP provides information about clients.
Enabled() (ok bool)
}

// Server is the main way to start a DNS server.
Expand Down

0 comments on commit c58284a

Please sign in to comment.