From 50519b6e540ff1a445ca4a57a2eade3f45092432 Mon Sep 17 00:00:00 2001
From: Darren 'Tadgy' Austin <darren@afterdark.org.uk>
Date: Fri, 7 Sep 2018 21:39:19 +0100
Subject: Move interface module loading into a 'pre-load' section

Also fix loading of interface modules - previously just $i was used,
where it should have been ${i%%:*}

Also added pre-loading of ipv6 module

Signed-off-by: Robby Workman <rworkman@slackware.com>
---
 rc.inet1 | 30 +++++++++++++++++++++---------
 1 file changed, 21 insertions(+), 9 deletions(-)

diff --git a/rc.inet1 b/rc.inet1
index 325ee56..1e54098 100644
--- a/rc.inet1
+++ b/rc.inet1
@@ -48,6 +48,27 @@ do
 done
 debug_log "List of interfaces: '${IFNAME[*]}'"
 
+####################
+# PRE-LOAD MODULES #
+####################
+
+for i in "${IFNAME[@]}"; do
+  # 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:
+  if [ ! -e /sys/class/net/${i%%:*} ]; then # no interface yet
+    if /sbin/modprobe -c | grep -v "^#" | grep -w "alias ${i%%:*}" | grep -vw "alias ${i%%:*} off" >/dev/null; then
+      echo "/etc/rc.d/rc.inet1:  /sbin/modprobe ${i%%:*}" | $LOGGER
+      /sbin/modprobe ${i%%:*}
+    fi
+  fi
+done
+# Normally the ipv6 module would be automatically loaded when the first IP is assigned to an interface,
+# but autoconf/accept_ra need to be set to 0 before that happens, so pre-load ipv6 here.
+if [ ! -e /proc/sys/net/ipv6 ]; then
+  /sbin/modprobe ipv6
+fi
+sleep 1
+
 ######################
 # LOOPBACK FUNCTIONS #
 ######################
@@ -148,15 +169,6 @@ if_up() {
     debug_log "skipping ${1} early, interface is not configured in /etc/rc.d/rc.inet1.conf"
     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:
-  if [ ! -e /sys/class/net/${1%%:*} ]; then # no interface yet
-    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
-- 
cgit v1.2.3