summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren 'Tadgy' Austin <darren@afterdark.org.uk>2020-07-24 17:30:55 +0100
committerRobby Workman <rworkman@slackware.com>2021-02-27 23:47:12 -0600
commite73a1f9586eaa40f02f9d187951ef96c3767ac82 (patch)
tree0845bbbd2fa748999687c301a0956fd507759beb
parent81ff9e9faaee332e9e1f168f85d3d9f6bc158c14 (diff)
downloadslacknetsetup-e73a1f9586eaa40f02f9d187951ef96c3767ac82.tar.xz
Implement a new IPADDRS array for v4 IPs - read full commit message
This commit introduces the logic for a new IPADDRS array which will work in a similar way to the IPv6 IP6ADDRS array. The IPADDRS array can hold multiple IPv4 addresses with netmasks, which are used in preference to, but maintaining backwards compatibility with, the old IPADDR/NETMASK arrays. If IPADDRS is set for an interface, the IPs and netmasks configured in the array are set before an also configured IPADDR/NETMASK. This maintains backwards compatibility - users can continue to use the IPADDR/NETMASK and IPALIASES arrays to configure the interface and completely ignore IPADDRS, or keep their old rc.inet1.conf files, if they so wish. If the IPADDRS arrays contains multiple IPs, those IPs are all added to the interface regardles of whether any IP in IPADDRS is or is not set. These IPs will also be added to the interface just as with IPALIASES if DHCP/SLAAC is used to set the first IP. The IPALIASES IPs are also added to the interface to maintain backwards compatibility. IPa set in IPADDRS to be used as 'alias' interfaces, are NOT given the usual ethX:Y name, like the IPs listed in IPALIASES. To get an ethX:Y interface the iPALIASES array should be used; to have the IPs simply added to the interface the user should use the IPADDRS array with multiple (space separated) IPs and netmasks. Using IPALIASES along side IPADDRS is completly legal and maintains backwards compatibility - it would yield a mixture of IPs set with and without ethX:Y aliases. This changeset moves the IPv4 configuration to be on par with the new IPv6 configuration syntax, but maintains FULL backwards compatibility with the old style syntax. Additionally, handling of IP4ADDRS has been modified such that it matches the IPADDRS usage. That is, any IPs listed in IP6ADDRS are also added to the interface (just as IPADDRS and IPALIASES are added for v4) whether the interface is configured with DHCP/DHCP6/SLAAC or not. This is a change to the IP6ADDRS usage, but since this script hasn't been officially accepted, there is no backwards compatibility issues. Again, note that these changes DO NOT change previous behaviour or damage backwards compatability. New functionallity and semantics only change behaviour of non-released features, so there is no bother to the changes. netconfig will be modified to output the new IPADDRS syntax, just as it does for IP6ADDRS and both will allow multiple IPs to be specified at configuration time - this is an improvement on the current netconfig behaviour.
-rw-r--r--rc.inet194
-rw-r--r--rc.inet1.conf44
2 files changed, 71 insertions, 67 deletions
diff --git a/rc.inet1 b/rc.inet1
index cfb3bdd..b18d535 100644
--- a/rc.inet1
+++ b/rc.inet1
@@ -397,27 +397,8 @@ if_up() {
/sbin/ip link set dev ${1} down
fi
fi
- if [ "${USE_DHCP[$i]}" != "yes" ] && [ -n "${IPADDR[$i]}" ]; then # add a fixed v4 IP to the interface
- info_log "${1}: setting fixed IPv4 address"
- if [ -z "${NETMASK[$i]}" ]; then
- info_log "${1}: no NETMASK set for primary IP ${IPADDR[$i]} - assuming 24 (aka, 255.255.255.0)"
- NETMASK[$i]="24"
- fi
- debug_log "/sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]#/} broadcast + dev ${1}"
- if /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]#/} broadcast + dev ${1} && \
- /sbin/ip link set dev ${1} up; then
- IF_UP=1
- else
- info_log "${1}: failed to set IP ${IPADDR[$i]}"
- debug_log "/sbin/ip address flush dev ${1}"
- /sbin/ip address flush dev ${1}
- debug_log "/sbin/ip link set dev ${1} down"
- /sbin/ip link set dev ${1} down
- fi
- fi
- if [ -e /proc/sys/net/ipv6 ] && [ "${USE_DHCP6[$i]}" != "yes" ] && [ "${USE_SLAAC[$i]}" != "yes" ] && \
- [ -n "${IP6ADDRS[$i]}" ]; then # add fixed v6 IPs
- info_log "${1}: setting fixed IPv6 addresses"
+ if [ -e /proc/sys/net/ipv6 ] && [ -n "${IP6ADDRS[$i]}" ]; then # add v6 IPs
+ info_log "${1}: setting IPv6 addresses"
# IPv6's Duplicate Address Detection (DAD) causes a race condition when bringing up interfaces, as
# described here: https://www.agwa.name/blog/post/beware_the_ipv6_dad_race_condition
# Disable DAD while bringing up the interface - but note that this means the loss of detection of a
@@ -432,8 +413,7 @@ if_up() {
PREFIX="64"
fi
debug_log "/sbin/ip -6 address add $IP/$PREFIX dev ${1}"
- if /sbin/ip -6 address add $IP/$PREFIX dev ${1} && \
- /sbin/ip link set dev ${1} up; then
+ if /sbin/ip -6 address add $IP/$PREFIX dev ${1} && /sbin/ip link set dev ${1} up; then
# Enable accepting of RA packets if explicitly told to.
if [ "${USE_RA[$i]}" = "yes" ]; then
debug_log "${1}: unconditionally accepting IPv6 RA"
@@ -454,27 +434,55 @@ if_up() {
debug_log "${1}: resetting IPv6 DAD to default"
cat /proc/sys/net/ipv6/conf/default/accept_dad >/proc/sys/net/ipv6/conf/${1}/accept_dad
fi
- if (($IF_UP == 1)); then # only do further config if the interface came up
- info_log "${1}: setting fixed IPv4 alias addresses"
- # Add extra IPv4 addresses to the interface:
- if [ -n "${IPALIASES[$i]}" ]; then
- NUM=0
- for IPALIAS in ${IPALIASES[$i]}; do
- IP="${IPALIAS%/*}"
- NM="${IPALIAS#*/}"
- if [ -z "$NM" ] || [ "$IP" == "$NM" ]; then
- info_log "${1}: no netmask set for alias IP $IP - assuming 24 (aka, 255.255.255.0)"
- NM="24"
- fi
- debug_log "/sbin/ip -4 address add $IP/$NM broadcast + dev ${1} label ${1}:$NUM"
- if /sbin/ip -4 address add $IP/$NM broadcast + dev ${1} label ${1}:$NUM; then
- NUM=$(($NUM + 1))
- else
- info_log "${1}: failed to add alias IP $IP"
- fi
- done
+ if [ -n "IPADDRS[$i]" ] || [ -n "IPADDR[$i]" ]; then # add v4 IPs
+ info_log "${1}: setting IPv4 addresses"
+ # Only use IPADDR if no dynamic configuration was done.
+ if [ "${USE_DHCP[$i]}" == "yes" ] || [ "${USE_DHCP6[$i]}" == "yes" ] || [ "${USE_SLAAC[$i]}" == "yes" ]; then
+ V4IPS="${IPADDRS[$i]}"
+ else
+ V4IPS="${IPADDRS[$i]} ${IPADDR[$i]}${NETMASK[$i]:+/${NETMASK[$i]}}"
fi
- # Force an MTU (possibly over-riding that set by DHCP or RA):
+ for V4IP in $V4IPS; do
+ IP="${V4IP%/*}"
+ NM="${V4IP#*/}"
+ if [ -z "$NM" ] || [ "$IP" == "$NM" ]; then
+ info_log "${1}: no netmask set for IP $IP - assuming 24 (aka, 255.255.255.0)"
+ NM="24"
+ fi
+ debug_log "/sbin/ip -4 address add $IP/$NM broadcast + dev ${1}"
+ if /sbin/ip -4 address add $IP/$NM broadcast + dev ${1} && /sbin/ip link set dev ${1} up; then
+ IF_UP=1
+ else
+ info_log "${1}: failed to set IP $IP"
+ if (($IF_UP != 1)); then # if at least one address was configured, don't flush the device
+ debug_log "/sbin/ip address flush dev ${1}"
+ /sbin/ip address flush dev ${1}
+ debug_log "/sbin/ip link set dev ${1} down"
+ /sbin/ip link set dev ${1} down
+ fi
+ fi
+ done
+ fi
+ if (($IF_UP == 1)) && [ -n "${IPALIASES[$i]}" ]; then # Only apply IPALIASES onto an up interface
+ info_log "${1}: setting extra IPv4 addresses"
+ NUM=0
+ for EXTRAIP in ${IPALIASES[$i]}; do
+ IP="${EXTRAIP%/*}"
+ NM="${EXTRAIP#*/}"
+ if [ -z "$NM" ] || [ "$IP" == "$NM" ]; then
+ info_log "${1}: no netmask set for alias IP $IP - assuming 24 (aka, 255.255.255.0)"
+ NM="24"
+ fi
+ debug_log "/sbin/ip -4 address add $IP/$NM broadcast + dev ${1} label ${1}:$NUM"
+ if /sbin/ip -4 address add $IP/$NM broadcast + dev ${1} label ${1}:$NUM; then
+ NUM=$(($NUM + 1))
+ else
+ info_log "${1}: failed to add alias IP $IP"
+ fi
+ done
+ fi
+ if (($IF_UP == 1)); then
+ # Force an MTU (possibly overriding that set by DHCP or RA):
if [ -n "${MTU[$i]}" ]; then
info_log "${1}: setting custom MTU"
debug_log "/sbin/ip link set dev ${1} mtu ${MTU[$i]}"
diff --git a/rc.inet1.conf b/rc.inet1.conf
index 5081ee5..48b94db 100644
--- a/rc.inet1.conf
+++ b/rc.inet1.conf
@@ -17,49 +17,45 @@
# =============================================================================
-# IPv4 config information for eth0:
-IPADDR[0]=""
-NETMASK[0]=""
-IPALIASES[0]=""
+# IPv4 config options for eth0:
+IPADDRS[0]=""
USE_DHCP[0]=""
-DHCP_HOSTNAME[0]=""
-# IPv6 config information for eth0:
+# IPv6 config options for eth0:
IP6ADDRS[0]=""
USE_SLAAC[0]=""
USE_DHCP6[0]=""
+# Generic options for eth0:
+DHCP_HOSTNAME[0]=""
-# IPv4 config information for eth1:
-IPADDR[1]=""
-NETMASK[1]=""
-IPALIASES[1]=""
+# IPv4 config options for eth1:
+IPADDRS[1]=""
USE_DHCP[1]=""
-DHCP_HOSTNAME[1]=""
-# IPv6 config information for eth1:
+# IPv6 config options for eth1:
IP6ADDRS[1]=""
USE_SLAAC[1]=""
USE_DHCP6[1]=""
+# Generic options for eth1:
+DHCP_HOSTNAME[1]=""
-# IPv4 config information for eth2:
-IPADDR[2]=""
-NETMASK[2]=""
-IPALIASES[2]=""
+# IPv4 config options for eth2:
+IPADDRS[2]=""
USE_DHCP[2]=""
-DHCP_HOSTNAME[2]=""
-# IPv6 config information for eth2:
+# IPv6 config options for eth2:
IP6ADDRS[2]=""
USE_SLAAC[2]=""
USE_DHCP6[2]=""
+# Generic options for eth2:
+DHCP_HOSTNAME[2]=""
-# IPv4 config information for eth3:
-IPADDR[3]=""
-NETMASK[3]=""
-IPALIASES[3]=""
+# IPv4 config options for eth3:
+IPADDRS[3]=""
USE_DHCP[3]=""
-DHCP_HOSTNAME[3]=""
-# IPv6 config information for eth3:
+# IPv6 config options for eth3:
IP6ADDRS[3]=""
USE_SLAAC[3]=""
USE_DHCP6[3]=""
+# Generic options for eth3:
+DHCP_HOSTNAME[3]=""
# IPv4 default gateway IP address:
GATEWAY=""