Pull request: 4337 Add del option
Merge in DNS/adguard-home from 4337-dhcp-cli-id to master Updates #4337. Squashed commit of the following: commit c393bf7c5964b64f6b4528db0418e54416dd246c Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 26 14:18:48 2022 +0300 dhcpd: ip docs commit bfeef3e881ed04eab6285c1ac62005c7cb57c11f Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 26 13:54:33 2022 +0300 all: finish chlog fmt commit e5fbb7385450825ca81fc7622feb7beb390a8bad Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 26 13:49:10 2022 +0300 dhcpd: imp naming commit cb49eeb536afd8dc1dd2ea9169dd024c7d4a3a25 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Fri Aug 26 12:23:54 2022 +0300 dhcpd: imp docs commit c4ea72a5e7572d40a885125c4f61ef6694e38170 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 25 20:15:15 2022 +0300 dhcpd: imp code, docs commit 36d0e309e7ef0abdcdd94673e87f4d0af67b9cb3 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Thu Aug 25 19:45:24 2022 +0300 dhcpd: add del opt
This commit is contained in:
@@ -875,28 +875,32 @@ func (s *v4Server) process(req, resp *dhcpv4.DHCPv4) int {
|
||||
resp.YourIPAddr = netutil.CloneIP(l.IP)
|
||||
}
|
||||
|
||||
// Set IP address lease time for all DHCPOFFER messages and DHCPACK
|
||||
// messages replied for DHCPREQUEST.
|
||||
// Set IP address lease time for all DHCPOFFER messages and DHCPACK messages
|
||||
// replied for DHCPREQUEST.
|
||||
//
|
||||
// TODO(e.burkov): Inspect why this is always set to configured value.
|
||||
resp.UpdateOption(dhcpv4.OptIPAddressLeaseTime(s.conf.leaseTime))
|
||||
|
||||
// Delete options explicitly configured to be removed.
|
||||
for code := range resp.Options {
|
||||
if val, ok := s.options[code]; ok && val == nil {
|
||||
delete(resp.Options, code)
|
||||
}
|
||||
}
|
||||
|
||||
// Update values for each explicitly configured parameter requested by
|
||||
// client.
|
||||
//
|
||||
// See https://datatracker.ietf.org/doc/html/rfc2131#section-4.3.1.
|
||||
requested := req.ParameterRequestList()
|
||||
for _, code := range requested {
|
||||
if configured := s.options; configured.Has(code) {
|
||||
resp.UpdateOption(dhcpv4.OptGeneric(code, configured.Get(code)))
|
||||
if val := s.options.Get(code); val != nil {
|
||||
resp.UpdateOption(dhcpv4.Option{
|
||||
Code: code,
|
||||
Value: dhcpv4.OptionGeneric{Data: s.options.Get(code)},
|
||||
})
|
||||
}
|
||||
}
|
||||
// Update the value of Domain Name Server option separately from others if
|
||||
// not assigned yet since its value is set after server's creating.
|
||||
if requested.Has(dhcpv4.OptionDomainNameServer) &&
|
||||
!resp.Options.Has(dhcpv4.OptionDomainNameServer) {
|
||||
resp.UpdateOption(dhcpv4.OptDNS(s.conf.dnsIPAddrs...))
|
||||
}
|
||||
|
||||
return 1
|
||||
}
|
||||
@@ -924,6 +928,7 @@ func (s *v4Server) packetHandler(conn net.PacketConn, peer net.Addr, req *dhcpv4
|
||||
resp, err := dhcpv4.NewReplyFromRequest(req)
|
||||
if err != nil {
|
||||
log.Debug("dhcpv4: dhcpv4.New: %s", err)
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
@@ -1020,6 +1025,11 @@ func (s *v4Server) Start() (err error) {
|
||||
// No available IP addresses which may appear later.
|
||||
return nil
|
||||
}
|
||||
// Update the value of Domain Name Server option separately from others if
|
||||
// not assigned yet since its value is available only at server's start.
|
||||
if !s.options.Has(dhcpv4.OptionDomainNameServer) {
|
||||
s.options.Update(dhcpv4.OptDNS(dnsIPAddrs...))
|
||||
}
|
||||
|
||||
s.conf.dnsIPAddrs = dnsIPAddrs
|
||||
|
||||
|
||||
Reference in New Issue
Block a user