mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-17 02:48:28 -07:00
5cc2a2cd0c
Merge in DNS/adguard-home from 4863-fix-dhcp-request to master
Closes #4863.
Squashed commit of the following:
commit f8872015e315eab3b2ce0249e552d12cbcf72f63
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 20:34:35 2022 +0300
dhcpd: imp code
commit b63c5d98c2055c3a3b76ff47737551840409f324
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 20:19:22 2022 +0300
dhcpd: fix deadlock
commit 5c03b54a86ab05efde9716faef60b84ecab01d19
Merge: f076cf8f 8733f55c
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 19:12:27 2022 +0300
Merge branch 'master' into 4863-fix-dhcp-request
commit f076cf8fc13944613b7127aac86ca78f68009f93
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 19:08:04 2022 +0300
dhcpd: imp code, names
commit a09540b6db6b86b80b8eb84c08187bfd9f960190
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 17:28:39 2022 +0300
dhcpd: imp code, docs
commit 38b12235509aaf55fa130f820213410b6b3022bb
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 16:42:32 2022 +0300
dhcpd: imp docs more
commit ff07c2f90f097754beb736fd5bd5cafc337ac65c
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 16:41:42 2022 +0300
dhcpd: fix docs
commit fafbc2ec2317f2320d8e1db167a1ae6c1c7c3790
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 16:35:42 2022 +0300
dhcpd: imp code
commit 9fe30190a7f125fd640b58e17661a4c33c078eba
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 15:00:56 2022 +0300
all: imp chlog
commit 1067fe95df5cb2252d1b9b70d2f3f8463997aea1
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 14:54:03 2022 +0300
dhcpd: log changes
commit 20de395c2bdcfb8e0554bb1c45385c15d617be65
Author: Eugene Burkov <E.Burkov@AdGuard.COM>
Date: Tue Aug 30 14:49:58 2022 +0300
dhcpd: impl rfc 2131 for req
104 lines
3.5 KiB
Go
104 lines
3.5 KiB
Go
package dhcpd
|
|
|
|
import (
|
|
"net"
|
|
"time"
|
|
)
|
|
|
|
// DHCPServer - DHCP server interface
|
|
type DHCPServer interface {
|
|
// ResetLeases resets leases.
|
|
ResetLeases(leases []*Lease) (err error)
|
|
// GetLeases returns deep clones of the current leases.
|
|
GetLeases(flags GetLeasesFlags) (leases []*Lease)
|
|
// AddStaticLease - add a static lease
|
|
AddStaticLease(l *Lease) (err error)
|
|
// RemoveStaticLease - remove a static lease
|
|
RemoveStaticLease(l *Lease) (err error)
|
|
// FindMACbyIP - find a MAC address by IP address in the currently active DHCP leases
|
|
FindMACbyIP(ip net.IP) net.HardwareAddr
|
|
|
|
// WriteDiskConfig4 - copy disk configuration
|
|
WriteDiskConfig4(c *V4ServerConf)
|
|
// WriteDiskConfig6 - copy disk configuration
|
|
WriteDiskConfig6(c *V6ServerConf)
|
|
|
|
// Start - start server
|
|
Start() (err error)
|
|
// Stop - stop server
|
|
Stop() (err error)
|
|
getLeasesRef() []*Lease
|
|
}
|
|
|
|
// V4ServerConf - server configuration
|
|
type V4ServerConf struct {
|
|
Enabled bool `yaml:"-" json:"-"`
|
|
InterfaceName string `yaml:"-" json:"-"`
|
|
|
|
GatewayIP net.IP `yaml:"gateway_ip" json:"gateway_ip"`
|
|
SubnetMask net.IP `yaml:"subnet_mask" json:"subnet_mask"`
|
|
// broadcastIP is the broadcasting address pre-calculated from the
|
|
// configured gateway IP and subnet mask.
|
|
broadcastIP net.IP
|
|
|
|
// The first & the last IP address for dynamic leases
|
|
// Bytes [0..2] of the last allowed IP address must match the first IP
|
|
RangeStart net.IP `yaml:"range_start" json:"range_start"`
|
|
RangeEnd net.IP `yaml:"range_end" json:"range_end"`
|
|
|
|
LeaseDuration uint32 `yaml:"lease_duration" json:"lease_duration"` // in seconds
|
|
|
|
// IP conflict detector: time (ms) to wait for ICMP reply
|
|
// 0: disable
|
|
ICMPTimeout uint32 `yaml:"icmp_timeout_msec" json:"-"`
|
|
|
|
// Custom Options.
|
|
//
|
|
// Option with arbitrary hexadecimal data:
|
|
// DEC_CODE hex HEX_DATA
|
|
// where DEC_CODE is a decimal DHCPv4 option code in range [1..255]
|
|
//
|
|
// Option with IP data (only 1 IP is supported):
|
|
// DEC_CODE ip IP_ADDR
|
|
Options []string `yaml:"options" json:"-"`
|
|
|
|
ipRange *ipRange
|
|
|
|
leaseTime time.Duration // the time during which a dynamic lease is considered valid
|
|
dnsIPAddrs []net.IP // IPv4 addresses to return to DHCP clients as DNS server addresses
|
|
|
|
// subnet contains the DHCP server's subnet. The IP is the IP of the
|
|
// gateway.
|
|
subnet *net.IPNet
|
|
|
|
// notify is a way to signal to other components that leases have been
|
|
// changed. notify must be called outside of locked sections, since the
|
|
// clients might want to get the new data.
|
|
//
|
|
// TODO(a.garipov): This is utter madness and must be refactored. It just
|
|
// begs for deadlock bugs and other nastiness.
|
|
notify func(uint32)
|
|
}
|
|
|
|
// V6ServerConf - server configuration
|
|
type V6ServerConf struct {
|
|
Enabled bool `yaml:"-" json:"-"`
|
|
InterfaceName string `yaml:"-" json:"-"`
|
|
|
|
// The first IP address for dynamic leases
|
|
// The last allowed IP address ends with 0xff byte
|
|
RangeStart net.IP `yaml:"range_start" json:"range_start"`
|
|
|
|
LeaseDuration uint32 `yaml:"lease_duration" json:"lease_duration"` // in seconds
|
|
|
|
RASLAACOnly bool `yaml:"ra_slaac_only" json:"-"` // send ICMPv6.RA packets without MO flags
|
|
RAAllowSLAAC bool `yaml:"ra_allow_slaac" json:"-"` // send ICMPv6.RA packets with MO flags
|
|
|
|
ipStart net.IP // starting IP address for dynamic leases
|
|
leaseTime time.Duration // the time during which a dynamic lease is considered valid
|
|
dnsIPAddrs []net.IP // IPv6 addresses to return to DHCP clients as DNS server addresses
|
|
|
|
// Server calls this function when leases data changes
|
|
notify func(uint32)
|
|
}
|