summaryrefslogtreecommitdiffstats
path: root/rc.inet1
diff options
context:
space:
mode:
authorDarren 'Tadgy' Austin <darren@afterdark.org.uk>2018-08-11 17:41:32 +0100
committerRobby Workman <rworkman@slackware.com>2018-11-25 19:51:50 -0600
commit895aa3741e87e38b75373f5f870517cf5b8751c4 (patch)
tree49a15948bbb2640ceffed6d4babfa677a520526c /rc.inet1
parent01c5ea1f994b9003cc17aca2db2ec3c9755a9e3c (diff)
downloadslacknetsetup-895aa3741e87e38b75373f5f870517cf5b8751c4.tar.xz
Various fixes and enhancements (see full commit message)
* Rename rc.inet1.conf options USE_STATELESS6 -> USE_AUTOCONF6 NETMASK6 -> PREFIX6 * Shell syntax and comment fixes * Removed some redundant code * Sleep after loading the network card module to allow it to register * Added error checking when adding IPs to an interface * Modify if_down() to bring all types of interface down * Only do MTU and PROMISC set up if the interface comes up * No longer skip alias config if using USE_AUTOCONF. Signed-off-by: Robby Workman <rworkman@slackware.com>
Diffstat (limited to 'rc.inet1')
-rw-r--r--rc.inet1130
1 files changed, 63 insertions, 67 deletions
diff --git a/rc.inet1 b/rc.inet1
index 367aaca..1f5fc45 100644
--- a/rc.inet1
+++ b/rc.inet1
@@ -144,9 +144,9 @@ if_up() {
[ -n "${BRNICS[$i]}" ] && br_open $i
# Skip unconfigured interfaces:
if [ -z "${IPADDR[$i]}" ] && [ "${USE_DHCP[$i]}" != "yes" ] && [ -z "${IPADDR6[$i]}" ] && \
- [ "${USE_DHCP6[$i]}" != "yes" ] && [ "${USE_STATELESS6[$i]}" != "yes" ]; then
+ [ "${USE_DHCP6[$i]}" != "yes" ] && [ "${USE_AUTOCONF6[$i]}" != "yes" ]; then
debug_log "skipping ${1} early, interface is not configured in /etc/rc.d/rc.inet1.conf"
- return 0
+ return
fi
# If the interface isn't in the kernel yet (but there's an alias for it in
# modules.conf), then it should be loaded first:
@@ -154,11 +154,12 @@ if_up() {
if /sbin/modprobe -c | grep -v "^#" | grep -w "alias ${1}" | grep -vw "alias ${1} off" > /dev/null ; then
echo "/etc/rc.d/rc.inet1: /sbin/modprobe ${1}" | $LOGGER
/sbin/modprobe ${1}
+ sleep 1
fi
fi
if [ -e /sys/class/net/${1%%:*} ]; then # interface exists
if ! /sbin/ip address show scope global dev ${1} 2>/dev/null | grep -Ewq '(inet|inet6)' || \
- ! /sbin/ip link show dev ${1} | grep -wq "state UP" ; then # interface not up or not configured
+ ! /sbin/ip link show dev ${1} | grep -wq "state UP"; then # interface not up or not configured
# Set hardware address _before_ the interface goes up:
if [ -n "${HWADDR[$i]}" ]; then
echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} address ${HWADDR[$i]}" | $LOGGER
@@ -168,11 +169,13 @@ if_up() {
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} start
fi
+ # Disable v6 IP auto configuration before trying to bring up the interface:
+ echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf
+ # Disable Router Advertisment for this interface until it's needed:
+ echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra
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 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:
@@ -194,74 +197,68 @@ if_up() {
if /sbin/dhcpcd -L -t "${DHCP_TIMEOUT[$i]:-15}" "${DHCP_OPTIONS[@]}" ${1}; then
IF_UP=1
else
- echo "/etc/rc.d/rc.inet1: failed to obtain DHCP lease for ${1}" | $LOGGER
+ echo "/etc/rc.d/rc.inet1: failed to obtain DHCP lease for ${1}" | $LOGGER
fi
fi
- if [ "${USE_DHCP[$i]}" != "yes" ] && [ -n "${IPADDR[$i]}" ]; then # use a fixed v4 IP to bring interface up
+ if [ "${USE_DHCP[$i]}" != "yes" ] && [ -n "${IPADDR[$i]}" ]; then # add a fixed v4 IP to the interface
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
- if /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]##/} broadcast + dev ${1} && \
+ echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]#/} broadcast + dev ${1}" | $LOGGER
+ 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
- echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR[$i]} for ${1}" | $LOGGER
+ 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
- if [ -z "${NETMASK6[$i]}" ]; then
- echo "/etc/rc.d/rc.inet1: no NETMASK6 set for ${1} - assuming /64" | $LOGGER
- NETMASK6[$i]="64"
+ if [ "${USE_DHCP6[$i]}" != "yes" ] && [ -n "${IPADDR6[$i]}" ]; then # add a fixed v6 IP to the interface
+ if [ -z "${PREFIX6[$i]}" ]; then
+ echo "/etc/rc.d/rc.inet1: no PREFIX6 set for ${1} - assuming /64" | $LOGGER
+ PREFIX6[$i]="64"
fi
- echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]##/} dev ${1}" | $LOGGER
- if /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]##/} dev ${1} && \
+ echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${IPADDR6[$i]}/${PREFIX6[$i]#/} dev ${1}" | $LOGGER
+ if /sbin/ip -6 address add ${IPADDR6[$i]}/${PREFIX6[$i]#/} dev ${1} && \
/sbin/ip link set dev ${1} up; then
IF_UP=1
else
- echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR6[$i]} for ${1}" | $LOGGER
+ echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR6[$i]} for ${1}" | $LOGGER
fi
fi
if [ "${USE_DHCP6[$i]}" != "yes" ] && [ -z "${IPADDR6[$i]}" ] && \
- [ "${USE_STATELESS6[$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
+ [ "${USE_AUTOCONF6[$i]}" = "yes" ]; then # interface should configure itself via stateless auto config:
+ echo "/etc/rc.d/rc.inet1: using Router Advertisement stateless 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
echo "1" >/proc/sys/net/ipv6/conf/$1/autoconf
# Bring the interface up:
/sbin/ip link set dev ${1} up
- echo "Waiting for Router Announcement on ${1}..."
- for ((j = 20; j--;)); do # wait a max of 10 seconds for the interface to configure
- /sbin/ip -6 address show dynamic dev ${1} 2>/dev/null | grep -Ewq 'inet6' && break
+ echo "Waiting for router announcement on ${1}..."
+ for ((j = 30; j--;)); do # wait a max of 15 seconds for the interface to configure
+ /sbin/ip -6 address show dynamic dev ${1} 2>/dev/null | grep -Ewq 'inet6' && { IF_UP=1; break; }
sleep 0.5
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
+ if (($IF_UP != 1)); then
+ /sbin/ip link set dev ${1} down
+ echo "Timed out!"
+ echo "/etc/rc.d/rc.inet1: failed to auto configure ${1} after 15 seconds" | $LOGGER
fi
- # Don't continue on to alias configuration.
- return
fi
- 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
- # Add extra IPv4 and v6 addresses, if defined, to the interface only if it came up:
- if (($IF_UP == 1)); then
+ if (($IF_UP == 1)); then # only do further config if the interface came up
+ # Add extra IPv4 and v6 addresses to the interface:
if [ -n "${IPALIASES[$i]}" ]; then
num=0
for ipalias in ${IPALIASES[$i]}; do
ip="${ipalias%/*}"
nm="${ipalias#*/}"
[ -z "$nm" ] || [ "$ip" == "$nm" ] && nm="24"
- echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${ip}/${nm} dev ${1} label ${1}:${num}" | $LOGGER
- /sbin/ip -4 address add ${ip}/${nm} dev ${1} label ${1}:${num}
- num=$(($num + 1))
+ echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${ip}/${nm} dev ${1} label ${1}:${num}" | $LOGGER
+ if /sbin/ip -4 address add ${ip}/${nm} dev ${1} label ${1}:${num}; then
+ num=$(($num + 1))
+ else
+ echo "/etc/rc.d/rc.inet1: failed to add IP ${ip} to ${1}" | $LOGGER
+ fi
done
fi
if [ -n "${IPALIASES6[$i]}" ]; then
@@ -270,19 +267,21 @@ if_up() {
nm="${ipalias#*/}"
[ -z "$nm" ] || [ "$ip" == "$nm" ] && nm="64"
# Unlike IPv4, v6 addresses don't get a label:
- echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${ip}/${nm} dev ${1}" | $LOGGER
- /sbin/ip -6 address add ${ip}/${nm} dev ${1}
+ echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${ip}/${nm} dev ${1}" | $LOGGER
+ /sbin/ip -6 address add ${ip}/${nm} dev ${1} || \
+ echo "/etc/rc.d/rc.inet1: failed to add IP ${ip} to ${1}" | $LOGGER
done
fi
- fi
- # Force an MTU (possibly over-riding that set by DHCP):
- if [ -n "${MTU[$i]}" ]; then
- echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} mtu ${MTU[$i]}" | $LOGGER
- /sbin/ip link set dev ${1} mtu ${MTU[$i]}
- fi
- # Set promiscuous mode on the interface:
- if [ "${PROMISCUOUS[$i]}" = "yes" ]; then
- /sbin/ip link set dev ${1} promisc on
+ # Force an MTU (possibly over-riding that set by DHCP or RA):
+ if [ -n "${MTU[$i]}" ]; then
+ echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} mtu ${MTU[$i]}" | $LOGGER
+ /sbin/ip link set dev ${1} mtu ${MTU[$i]}
+ fi
+ # Set promiscuous mode on the interface:
+ if [ "${PROMISCUOUS[$i]}" = "yes" ]; then
+ echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} promisc on" | $LOGGER
+ /sbin/ip link set dev ${1} promisc on
+ fi
fi
else
debug_log "${1} is already up, skipping"
@@ -313,26 +312,23 @@ if_down() {
DHCP_OPTIONS="-6"
fi
echo "/etc/rc.d/rc.inet1: /sbin/dhcpcd $DHCP_OPTIONS -k -d ${1}" | $LOGGER
- if ! /sbin/dhcpcd $DHCP_OPTIONS -k -d ${1} 2>/dev/null; then
- echo "/etc/rc.d/rc.inet1: failed to stop dhcpcd for interface ${1}" | $LOGGER
- fi
- sleep 2
- fi
- if [ -n "${IPADDR[$i]}" ] || [ -n "${IPADDR6[$i]}" ]; then # flush any fixed IPs
- echo "/etc/rc.d/rc.inet1: /sbin/ip address flush dev ${1}" | $LOGGER
- /sbin/ip address flush dev ${1}
- fi
- if [ "${USE_STATELESS6[$i]}" = "yes" ]; then # disable stateless RA auto config
- # Disable auto configuration of the interface:
- echo "/etc/rc.d/rc.inet1: disabling stateless Router Advertisement auto configuration on ${1}" | $LOGGER
- echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf
- sleep 1
+ /sbin/dhcpcd $DHCP_OPTIONS -k -d ${1} 2>/dev/null || \
+ echo "/etc/rc.d/rc.inet1: failed to stop dhcpcd for interface ${1}" | $LOGGER
+ sleep 0.5
fi
+ # Disable v6 IP auto configuration and RA before trying to clear the IP from the interface:
+ echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf
+ echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra
+ sleep 0.5
+ # Flush any remaining IPs:
+ echo "/etc/rc.d/rc.inet1: /sbin/ip address flush dev ${1}" | $LOGGER
+ /sbin/ip address flush dev ${1}
# Bring the interface down:
echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} down" | $LOGGER
/sbin/ip link set dev ${1} down
- # One final flush of the interface:
- /sbin/ip address flush dev ${1}
+ # Reset autoconf and accept_ra back to defaults:
+ cat /proc/sys/net/ipv6/conf/default/autoconf >/proc/sys/net/ipv6/conf/$1/autoconf
+ cat /proc/sys/net/ipv6/conf/default/accept_ra >/proc/sys/net/ipv6/conf/$1/accept_ra
# Kill wireless daemons if any:
if [ -x /etc/rc.d/rc.wireless ]; then
. /etc/rc.d/rc.wireless ${1} stop