summaryrefslogtreecommitdiffstats
path: root/rc.inet1
diff options
context:
space:
mode:
Diffstat (limited to 'rc.inet1')
-rw-r--r--rc.inet194
1 files changed, 51 insertions, 43 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]}"