summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDarren 'Tadgy' Austin <darren@afterdark.org.uk>2018-07-30 10:15:18 +0100
committerRobby Workman <rworkman@slackware.com>2018-11-25 19:46:15 -0600
commitc24fd260e457826e6cd93b33c88572fe1066ce9e (patch)
tree41588663b5472267e5368e2994eba9fcaa5d7bf3
parent3a273172aebf1f0566e30cefab3454a7b498fa9b (diff)
downloadslacknetsetup-c24fd260e457826e6cd93b33c88572fe1066ce9e.tar.xz
Changed if_up logic to allow interfaces to be configured by any method
Signed-off-by: Robby Workman <rworkman@slackware.com>
-rw-r--r--rc.inet178
1 files changed, 43 insertions, 35 deletions
diff --git a/rc.inet1 b/rc.inet1
index 5cb4d0c..622d487 100644
--- a/rc.inet1
+++ b/rc.inet1
@@ -168,12 +168,14 @@ if_up() {
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} start
fi
+ IF_UP=0
+ # Slackware historically favours DHCP over fixed IP to configure interfaces, so keep that tradition.
if [ "${USE_DHCP[$i]}" = "yes" ] || [ "${USE_DHCP6[$i]}" = "yes" ]; then # use dhcpcd to bring interface up
- # Disable v6 IP auto configuration:
- echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf
- # Clear DHCP_OPTIONS before adding new options to it:
- unset DHCP_OPTIONS
- declare -a DHCP_OPTIONS
+# FIXME: This block needs some attention after talking to Robby:
+ # Disable v6 IP auto configuration before trying to set up the interface:
+ [ "${USE_DHCP6[$i]}" = "yes" ] && echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf
+ # Declare DHCP_OPTIONS array before adding new options to it:
+ declare -a DHCP_OPTIONS=()
# Set DHCP_OPTIONS for this interface:
if [ "${USE_DHCP[$i]}" = "yes" ] && [ "${USE_DHCP6[$i]}" != "yes" ]; then # only try v4 dhcp
DHCP_OPTIONS+=("-4")
@@ -191,38 +193,40 @@ if_up() {
# 15 seconds should be a reasonable default DHCP timeout. 30 was too much.
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd -L -t ${DHCP_TIMEOUT[$i]:-15} ${DHCP_OPTIONS[@]} ${1}" | $LOGGER
/sbin/dhcpcd -L -t "${DHCP_TIMEOUT[$i]:-15}" "${DHCP_OPTIONS[@]}" ${1}
- elif [ -n "${IPADDR[$i]}" ] || [ -n "${IPADDR6[$i]}" ]; then # use a fixed IP to bring interface up
- # Disable v6 IP auto configuration:
+ IF_UP=1
+ fi
+ if [ "${USE_DHCP[$i]}" != "yes" ] && [ -n "${IPADDR[$i]}" ]; then # use a fixed v4 IP to bring interface up
+ if [ -z "${NETMASK[$i]}"; then
+ echo "/etc/rc.d/rc.inet1: no NETMASK set for ${1} - assuming /24 (aka, 255.255.255.0)" | $LOGGER
+ NETMASK[$i]="24"
+ fi
+ echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]##/} broadcast + dev ${1}" | $LOGGER
+ /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]##/} broadcast + dev ${1} && \
+ /sbin/ip link set dev ${1} up
+ if (($? == 0)); then
+ IF_UP=1
+ else
+ echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR[$i]} for ${1}" | $LOGGER
+ fi
+ fi
+ if [ "${USE_DHCP6[$i]}" != "yes" ] && [ -n "${IPADDR6[$i]}" ]; then # use a fixed v6 IP to bring up/add to the interface
+ # Disable v6 IP auto configuration before trying to configure with a fixed IP:
echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf
- # Configure interface with a v4 IP:
- if [ -n "${IPADDR[$i]}" ]; then
- if [ -z "${NETMASK[$i]}"; then
- echo "/etc/rc.d/rc.inet1: no NETMASK set for ${1} - assuming a /24 (aka, 255.255.255.0)" | $LOGGER
- NETMASK[$i]="24"
- fi
- echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]} broadcast + dev ${1}" | $LOGGER
- /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]} broadcast + dev ${1}
- if [ "$?" != "0" ]; then
- echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR[$i]} for ${1}" | $LOGGER
- return
- fi
+ if [ -z "${NETMASK6[$i]}"; then
+ echo "/etc/rc.d/rc.inet1: no NETMASK6 set for ${1} - assuming /64" | $LOGGER
+ NETMASK6[$i]="64"
fi
- # Configure interface with a v6 IP:
- if [ -n "${IPADDR6[$i]}" ]; then
- if [ -z "${NETMASK6[$i]}"; then
- echo "/etc/rc.d/rc.inet1: no NETMASK6 set for ${1} - assuming a /64" | $LOGGER
- NETMASK[$i]="64"
- fi
- echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]} dev ${1}" | $LOGGER
- /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]} dev ${1}
- if [ "$?" != "0" ]; then
- echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR6[$i]} for ${1}" | $LOGGER
- return
- fi
+ echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]##/} dev ${1}" | $LOGGER
+ /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]##/} dev ${1} && \
+ /sbin/ip link set dev ${1} up
+ if (($? == 0)); then
+ IF_UP=1
+ else
+ echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR6[$i]} for ${1}" | $LOGGER
fi
- # Bring up the interface if it's not already up:
- /sbin/ip link set dev ${1} up
- elif [ "${USE_STATELESS[$i]}" = "yes" ]; then # interface should configure itself via stateless RA auto config
+ fi
+ if [ "${USE_DHCP6[$i]}" != "yes" ] && [ -z "${IPADDR6[$i]}" ] && \
+ [ "${USE_STATELESS[$i]}" = "yes" ]; then # interface should configure itself via stateless RA auto config:
echo "/etc/rc.d/rc.inet1: using stateless Router Advertisement auto configuration for ${1}" | $LOGGER
# Enable accepting of router advertisment packets, and auto configuration of interfaces:
echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra
@@ -236,9 +240,13 @@ if_up() {
done
if ! /sbin/ip -6 address show dynamic dev ${1} 2>/dev/null | grep -Ewq 'inet6'; then
echo "/etc/rc.d/rc.inet1: failed to auto configure ${1} after 10 seconds" | $LOGGER
+ else
+ IF_UP=1
fi
+ # Don't continue on to alias configuration.
return
- else # interface is unconfigured
+ if [ "${USE_DHCP[$i]}" != "yes" ] && [ "${USE_DHCP6[$i]}" != "yes" ] && [ -n "${IPADDR6[$i]}" ] && \
+ [ -z "${IPADDR6[$i]}" ]; then # interface is unconfigured
debug_log "${1} interface is not configured in /etc/rc.d/rc.inet1.conf"
return
fi