From 936a7057fd17809bb3c8e49ec590abd48a12c0b3 Mon Sep 17 00:00:00 2001 From: Ildar Kamalov Date: Wed, 24 Nov 2021 13:57:50 +0300 Subject: [PATCH] Pull request: 3824 fix DHCP empty form validation Closes #3824 Squashed commit of the following: commit 24d5770e2f276f710c011bf94e36702881ccbf1a Merge: 8f539900 32294407 Author: Ildar Kamalov Date: Wed Nov 24 12:21:23 2021 +0300 Merge branch 'master' into 3824-empty-values commit 8f539900489c940c6d7068d672420a553a1da299 Merge: 4be77268 51f11d2f Author: Ildar Kamalov Date: Tue Nov 23 19:06:44 2021 +0300 Merge branch 'master' into 3824-empty-values commit 4be77268ab1b3dc99b754b8002320a615db2d99e Author: Eugene Burkov Date: Tue Nov 23 19:04:06 2021 +0300 all: use new consts commit 701fd9a2b82d69c6b813a4a1889c65404ac3571b Author: Ildar Kamalov Date: Tue Nov 23 18:58:03 2021 +0300 client: get status on reset commit a20734cbf26a57ec96fdb6e0f868a8656751e80a Author: Eugene Burkov Date: Tue Nov 23 18:31:59 2021 +0300 dhcpd: fix reset defaults commit e2cb0cb0995e7b2dd3e194c5bb9fe944cf7be8f5 Author: Ildar Kamalov Date: Tue Nov 23 17:33:22 2021 +0300 client: fix DHCP empty form validation --- client/src/components/Settings/Dhcp/index.js | 1 + client/src/helpers/validators.js | 4 +++ internal/dhcpd/http.go | 34 ++++++++++++++------ internal/home/config.go | 6 ++-- 4 files changed, 32 insertions(+), 13 deletions(-) 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