From: Michael Tremer Date: Thu, 8 Sep 2016 16:23:34 +0000 (+0200) Subject: DHCP: Make removing subnet ranges more robust X-Git-Tag: 009~292 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=1b9e7008dac524eff4f9ea36b0b1962b405fa30e;p=network.git DHCP: Make removing subnet ranges more robust Signed-off-by: Michael Tremer --- diff --git a/src/functions/functions.dhcpd b/src/functions/functions.dhcpd index dcd1e797..562aee07 100644 --- a/src/functions/functions.dhcpd +++ b/src/functions/functions.dhcpd @@ -773,18 +773,31 @@ dhcpd_subnet_range_new() { } dhcpd_subnet_range_remove() { - local path=$(dhcpd_subnet_range_path $@) + assert [ $# -eq 3 ] + + local proto=${1} + local subnet=${2} + local range=${3} + + if ! dhcpd_subnet_range_exists ${proto} ${subnet} ${range}; then + error "DHCP subnet range ${range} does not exist" + return ${EXIT_ERROR} + fi + + local path=$(dhcpd_subnet_range_path ${proto} ${subnet} ${range}) assert isset path rm -f ${path} + + log INFO "DHCP subnet range ${range} removed" + return ${EXIT_OK} } dhcpd_subnet_range_list() { - local proto=${1} - assert isset proto + assert [ $# -eq 2 ] + local proto=${1} local subnet=${2} - assert isset subnet local path=$(dhcpd_subnet_range_path ${proto} ${subnet}) @@ -810,6 +823,34 @@ dhcpd_subnet_range_read() { settings_read ${file} } +dhcpd_subnet_range_exists() { + assert [ $# -eq 3 ] + + local proto=${1} + local subnet=${2} + local range=${3} + + local start=${range%-*} + local end=${range#*-} + + assert isset start + assert isset end + + local settings=$(dhcpd_subnet_range_settings ${proto}) + + local r ${settings} + for r in $(dhcpd_subnet_range_list ${proto} ${subnet}); do + dhcpd_subnet_range_read ${proto} ${subnet} ${r} + + # If start and end addresses equal we got a match + if ${proto}_addr_eq "${START}" "${start}" && ${proto}_addr_eq "${END}" "${end}"; then + return ${EXIT_TRUE} + fi + done + + return ${EXIT_FALSE} +} + dhcpd_subnet_settings() { local proto=${1}