diff --git a/client/src/components/Settings/Dhcp/index.js b/client/src/components/Settings/Dhcp/index.js index 6208d4a6..a84e0a93 100644 --- a/client/src/components/Settings/Dhcp/index.js +++ b/client/src/components/Settings/Dhcp/index.js @@ -102,6 +102,7 @@ const Dhcp = () => { Object.values(DHCP_FORM_NAMES) .forEach((formName) => dispatch(destroy(formName))); dispatch(resetDhcp()); + dispatch(getDhcpStatus()); } }; diff --git a/client/src/helpers/validators.js b/client/src/helpers/validators.js index 54bf0341..2ac98a6b 100644 --- a/client/src/helpers/validators.js +++ b/client/src/helpers/validators.js @@ -68,6 +68,10 @@ export const validateIpv4 = (value) => { * @param allValues */ export const validateNotInRange = (value, allValues) => { + if (!allValues.v4) { + return undefined; + } + const { range_start, range_end } = allValues.v4; if (range_start && validateIpv4(range_start)) { diff --git a/internal/dhcpd/http.go b/internal/dhcpd/http.go index 990d3c7c..e016dee8 100644 --- a/internal/dhcpd/http.go +++ b/internal/dhcpd/http.go @@ -8,10 +8,12 @@ import ( "net/http" "os" "strings" + "time" "github.com/AdguardTeam/AdGuardHome/internal/aghnet" "github.com/AdguardTeam/golibs/errors" "github.com/AdguardTeam/golibs/log" + "github.com/AdguardTeam/golibs/timeutil" ) func httpError(r *http.Request, w http.ResponseWriter, code int, format string, args ...interface{}) { @@ -533,6 +535,13 @@ func (s *Server) handleDHCPRemoveStaticLease(w http.ResponseWriter, r *http.Requ } } +const ( + // DefaultDHCPLeaseTTL is the default time-to-live for leases. + DefaultDHCPLeaseTTL = uint32(timeutil.Day / time.Second) + // DefaultDHCPTimeoutICMP is the default timeout for waiting ICMP responses. + DefaultDHCPTimeoutICMP = 1000 +) + func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) { err := s.Stop() if err != nil { @@ -547,19 +556,24 @@ func (s *Server) handleReset(w http.ResponseWriter, r *http.Request) { } oldconf := s.conf - s.conf = ServerConfig{} - s.conf.WorkDir = oldconf.WorkDir - s.conf.HTTPRegister = oldconf.HTTPRegister - s.conf.ConfigModified = oldconf.ConfigModified - s.conf.DBFilePath = oldconf.DBFilePath + s.conf = ServerConfig{ + WorkDir: oldconf.WorkDir, + HTTPRegister: oldconf.HTTPRegister, + ConfigModified: oldconf.ConfigModified, + DBFilePath: oldconf.DBFilePath, + } - v4conf := V4ServerConf{} - v4conf.ICMPTimeout = 1000 - v4conf.notify = s.onNotify + v4conf := V4ServerConf{ + LeaseDuration: DefaultDHCPLeaseTTL, + ICMPTimeout: DefaultDHCPTimeoutICMP, + notify: s.onNotify, + } s.srv4, _ = v4Create(v4conf) - v6conf := V6ServerConf{} - v6conf.notify = s.onNotify + v6conf := V6ServerConf{ + LeaseDuration: DefaultDHCPLeaseTTL, + notify: s.onNotify, + } s.srv6, _ = v6Create(v6conf) s.conf.ConfigModified() diff --git a/internal/home/config.go b/internal/home/config.go index 44afe953..3465c26f 100644 --- a/internal/home/config.go +++ b/internal/home/config.go @@ -232,9 +232,9 @@ func initConfig() { config.DNS.DnsfilterConf.CacheTime = 30 config.Filters = defaultFilters() - config.DHCP.Conf4.LeaseDuration = 86400 - config.DHCP.Conf4.ICMPTimeout = 1000 - config.DHCP.Conf6.LeaseDuration = 86400 + config.DHCP.Conf4.LeaseDuration = dhcpd.DefaultDHCPLeaseTTL + config.DHCP.Conf4.ICMPTimeout = dhcpd.DefaultDHCPTimeoutICMP + config.DHCP.Conf6.LeaseDuration = dhcpd.DefaultDHCPLeaseTTL if ch := version.Channel(); ch == version.ChannelEdge || ch == version.ChannelDevelopment { config.BetaBindPort = 3001