From bedbbac318b26b21bc5bc0f6a2b2c32a399c21a254da3294f129488051811521 Mon Sep 17 00:00:00 2001 From: Christian Goll Date: Thu, 12 Oct 2023 07:44:53 +0000 Subject: [PATCH] - check if automatic configured ip range doesn'y contain ip address of ww4 host OBS-URL: https://build.opensuse.org/package/show/network:cluster/warewulf4?expand=0&rev=42 --- config-ww4.sh | 30 +++++++++++++++++++++++++++++- warewulf4.changes | 6 ++++++ 2 files changed, 35 insertions(+), 1 deletion(-) diff --git a/config-ww4.sh b/config-ww4.sh index eda006b..1a33d30 100644 --- a/config-ww4.sh +++ b/config-ww4.sh @@ -27,6 +27,21 @@ network_address() { echo $( IFS=.; echo "${octets[*]}" ) } +# Check if last Octed is in range +function is_ip_in_range() { + # split the ip addresses into their octets. + local ip_start_octets=($(echo $DYNSTART | tr "." " ")) + local ip_end_octets=($(echo $DYNEND | tr "." " ")) + local ip_address_octets=($(echo $1 | tr "." " ")) + + # compare the octets one at a time to see if the ip address is within the range. + if [[ ${ip_address_octets[3]} -lt ${ip_start_octets[3]} || ${ip_address_octets[3]} -gt ${ip_end_octets[3]} ]]; then + return 1 + fi + # if we reach this point, the ip address is in the range. + return 0 +} + echo "-- WW4 CONFIGURAION $* --" # Make sure that a ip address was defined for out network so that @@ -39,13 +54,21 @@ IP4NET=$(network_address "$IP4/$IP4PREFIX") if [ "$IP4PREFIX" -gt 25 ] ; then echo "ERROR: warewulf does at least a /25 network for dynamic addresses" + cat << EOF +ipaddr: $IP4 +netmask: $IP4MASK +network: $IP4NET + range start: $DYNSTART + range end: $DYNEND +EOF exit 1 fi DYNSIZE=20 DYNSTART=${IP4#*.*.*.} +DYNSTART=$(( $DYNSTART + 2)) DYNPRE=${IP4%.*} -DYNEND=$(( $DYNSTART + $DYNSIZE )) +DYNEND=$(( $DYNSTART + $DYNSIZE + 1 )) if [ $DYNEND -gt 254 ] ; then DYNEND=$(( $IPNET + 2 + $DYNSIZE )) DYNSTART=$(( $IPNET + 2 )) @@ -53,6 +76,11 @@ fi DYNSTART="${DYNPRE}.${DYNSTART}" DYNEND="${DYNPRE}.${DYNEND}" +if is_ip_in_range $IP4 ; then + echo "ERROR: ip address is in range for dynamic address, please set this manually" + exit 1 +fi + if [ -e $WW4CONF ] ; then test -n $IP4 && sed -i 's/^ipaddr:.*/ipaddr: '$IP4'/' $WW4CONF diff --git a/warewulf4.changes b/warewulf4.changes index 954c44e..f4429a7 100644 --- a/warewulf4.changes +++ b/warewulf4.changes @@ -1,3 +1,9 @@ +------------------------------------------------------------------- +Thu Oct 12 07:43:32 UTC 2023 - Christian Goll + +- check if automatic configured ip range doesn'y contain ip address + of ww4 host + ------------------------------------------------------------------- Thu Sep 21 09:23:31 UTC 2023 - Christian Goll