From a832987f7c6d7f7ad0339f8a280e24263ef1b661 Mon Sep 17 00:00:00 2001 From: Eugene Burkov Date: Fri, 8 Jul 2022 15:17:47 +0300 Subject: [PATCH] Pull request: 4698 Gateway IP in DHCP Lease Closes #4698. Squashed commit of the following: commit 6be0caee58926f8cea1e10650fbde0c8d97d0dac Author: Ildar Kamalov Date: Fri Jul 8 13:41:50 2022 +0300 update translation commit e0370656d05e8463d73ea73568cae81187c6b2e3 Author: Ildar Kamalov Date: Fri Jul 8 13:40:54 2022 +0300 client: validate static lease ip commit 7f4d00f9f3a54dc93ce5d5c45e9c21745f6e39d1 Merge: 2ee79626 77e5e27d Author: Eugene Burkov Date: Fri Jul 8 13:20:15 2022 +0300 Merge branch 'master' into 4698-lease-with-gateway commit 2ee79626a1b0c7b113dbd22ba4ef6e85ea9913ec Merge: 471b96b8 3505ce87 Author: Eugene Burkov Date: Thu Jul 7 19:34:33 2022 +0300 Merge branch 'master' into 4698-lease-with-gateway commit 471b96b81da8920c1e71b7110050154f912677d2 Author: Eugene Burkov Date: Thu Jul 7 16:07:23 2022 +0300 dhcpd: imp docs commit 67dd6c76f7d2df4712a57281e0f40f2ee1a1efa2 Author: Eugene Burkov Date: Thu Jul 7 15:48:47 2022 +0300 dhcpd: restrict gateway ip for lease --- CHANGELOG.md | 3 + client/src/__locales/en.json | 1 + .../Settings/Dhcp/StaticLeases/Form.js | 3 + .../Settings/Dhcp/StaticLeases/Modal.js | 3 + .../Settings/Dhcp/StaticLeases/index.js | 3 + client/src/components/Settings/Dhcp/index.js | 1 + client/src/helpers/validators.js | 11 ++ internal/dhcpd/http.go | 1 - internal/dhcpd/v4.go | 12 +- internal/dhcpd/v4_test.go | 124 ++++++++++++------ 10 files changed, 120 insertions(+), 42 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 21046925..7b8f5d97 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -32,6 +32,8 @@ and this project adheres to ### Fixed +- DHCP lease validation incorrectly letting users assign the IP address of the + gateway as the address of the lease ([#4698]). - Updater no longer expects a hardcoded name for `AdGuardHome` executable ([#4219]). - Inconsistent names of runtime clients from hosts files ([#4683]). @@ -44,6 +46,7 @@ and this project adheres to [#4219]: https://github.com/AdguardTeam/AdGuardHome/issues/4219 [#4677]: https://github.com/AdguardTeam/AdGuardHome/issues/4677 [#4683]: https://github.com/AdguardTeam/AdGuardHome/issues/4683 +[#4698]: https://github.com/AdguardTeam/AdGuardHome/issues/4698 [#4699]: https://github.com/AdguardTeam/AdGuardHome/issues/4699 [ddr-draft]: https://datatracker.ietf.org/doc/html/draft-ietf-add-ddr-08 diff --git a/client/src/__locales/en.json b/client/src/__locales/en.json index dd885677..9fc65cac 100644 --- a/client/src/__locales/en.json +++ b/client/src/__locales/en.json @@ -47,6 +47,7 @@ "form_error_server_name": "Invalid server name", "form_error_subnet": "Subnet \"{{cidr}}\" does not contain the IP address \"{{ip}}\"", "form_error_positive": "Must be greater than 0", + "form_error_gateway_ip": "Lease can't have the IP address of the gateway", "out_of_range_error": "Must be out of range \"{{start}}\"-\"{{end}}\"", "lower_range_start_error": "Must be lower than range start", "greater_range_start_error": "Must be greater than range start", diff --git a/client/src/components/Settings/Dhcp/StaticLeases/Form.js b/client/src/components/Settings/Dhcp/StaticLeases/Form.js index 625e87e2..0525f6a3 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/Form.js +++ b/client/src/components/Settings/Dhcp/StaticLeases/Form.js @@ -10,6 +10,7 @@ import { validateMac, validateRequiredValue, validateIpv4InCidr, + validateIpGateway, } from '../../../../helpers/validators'; import { FORM_NAME } from '../../../../helpers/constants'; import { toggleLeaseModal } from '../../../../actions'; @@ -57,6 +58,7 @@ const Form = ({ validateRequiredValue, validateIpv4, validateIpv4InCidr, + validateIpGateway, ]} /> @@ -101,6 +103,7 @@ Form.propTypes = { ip: PropTypes.string.isRequired, hostname: PropTypes.string.isRequired, cidr: PropTypes.string.isRequired, + gatewayIp: PropTypes.string, }), pristine: PropTypes.bool.isRequired, handleSubmit: PropTypes.func.isRequired, diff --git a/client/src/components/Settings/Dhcp/StaticLeases/Modal.js b/client/src/components/Settings/Dhcp/StaticLeases/Modal.js index 8ad0f009..0baf487e 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/Modal.js +++ b/client/src/components/Settings/Dhcp/StaticLeases/Modal.js @@ -13,6 +13,7 @@ const Modal = ({ cidr, rangeStart, rangeEnd, + gatewayIp, }) => { const dispatch = useDispatch(); @@ -42,6 +43,7 @@ const Modal = ({ cidr, rangeStart, rangeEnd, + gatewayIp, }} onSubmit={handleSubmit} processingAdding={processingAdding} @@ -61,6 +63,7 @@ Modal.propTypes = { cidr: PropTypes.string.isRequired, rangeStart: PropTypes.string, rangeEnd: PropTypes.string, + gatewayIp: PropTypes.string, }; export default withTranslation()(Modal); diff --git a/client/src/components/Settings/Dhcp/StaticLeases/index.js b/client/src/components/Settings/Dhcp/StaticLeases/index.js index a63f78cd..2374f044 100644 --- a/client/src/components/Settings/Dhcp/StaticLeases/index.js +++ b/client/src/components/Settings/Dhcp/StaticLeases/index.js @@ -24,6 +24,7 @@ const StaticLeases = ({ cidr, rangeStart, rangeEnd, + gatewayIp, }) => { const [t] = useTranslation(); const dispatch = useDispatch(); @@ -106,6 +107,7 @@ const StaticLeases = ({ cidr={cidr} rangeStart={rangeStart} rangeEnd={rangeEnd} + gatewayIp={gatewayIp} /> ); @@ -119,6 +121,7 @@ StaticLeases.propTypes = { cidr: PropTypes.string.isRequired, rangeStart: PropTypes.string, rangeEnd: PropTypes.string, + gatewayIp: PropTypes.string, }; cellWrap.propTypes = { diff --git a/client/src/components/Settings/Dhcp/index.js b/client/src/components/Settings/Dhcp/index.js index a84e0a93..bd3a45e3 100644 --- a/client/src/components/Settings/Dhcp/index.js +++ b/client/src/components/Settings/Dhcp/index.js @@ -278,6 +278,7 @@ const Dhcp = () => { cidr={cidr} rangeStart={dhcp?.values?.v4?.range_start} rangeEnd={dhcp?.values?.v4?.range_end} + gatewayIp={dhcp?.values?.v4?.gateway_ip} />