Release new version 1:20210208+grml.5
[live-boot-grml.git] / components / 9990-grml-networking.sh
index f4031cd..b899461 100644 (file)
@@ -8,6 +8,8 @@ if [ -n "${NONETWORKING}" ]; then
    return 0
 fi
 
+log_begin_msg "Preconfiguring Grml networking"
+
 modprobe af_packet # req'd for DHCP
 
 # initialize udev
@@ -37,7 +39,11 @@ fi
 
 # config for loopback networking
 cat > $IFFILE << EOF
-# Initially generated on boot by initramfs' 23networking.
+# Initially generated on boot by initramfs,
+# interfaces(5) file used by ifup(8) and ifdown(8)
+
+# Include files from /etc/network/interfaces.d:
+source /etc/network/interfaces.d/*
 
 auto lo
 iface lo inet loopback
@@ -47,9 +53,10 @@ EOF
 unset HOSTNAME
 
 # generate config for each present network device
-for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; do
+for interface in /sys/class/net/; do
     [ -e ${interface} ] || continue
     interface=$(basename ${interface})
+    [ "${interface}" = "lo" ] && continue
     method="dhcp"
 
     # NODHCP or a previously run ipconfig mean that ifupdown should never
@@ -67,10 +74,39 @@ for interface in /sys/class/net/eth* /sys/class/net/ath* /sys/class/net/wlan*; d
         method="dhcp"
     fi
 
-    cat >> $IFFILE << EOF
+    if [ -n "$VLANS" ] ; then
+      modprobe 8021q
+
+      # vlan=<vid>:<phydevice>
+      for line in $(echo $VLANS | sed 's/ /\n'/) ; do
+        vlandev=${line#*:}
+        vlanid=${line%:*}
+
+        if [ -n "$vlandev" ] && [ -n "$vlanid" ] ; then
+          case "$vlandev" in
+            "$interface")
+              vlan_raw_dev=$interface
+              interface="${vlandev}.${vlanid}"
+              ;;
+          esac
+        fi
+      done
+    fi
+
+    if [ -n "$vlan_raw_dev" ] ; then
+      cat >> $IFFILE << EOF
+auto ${interface}
+iface ${interface} inet ${method}
+        vlan-raw-device $vlan_raw_dev
+EOF
+    else
+      cat >> $IFFILE << EOF
 allow-hotplug ${interface}
 iface ${interface} inet ${method}
 EOF
+    fi
+
+    unset vlandev vlanid vlan_raw_dev # unset variables to have clean state for next device
 
     # DNS for resolvconf and /etc/resolv.conf
     if [ -e "${netconfig}" ]; then
@@ -104,14 +140,14 @@ EOF
 done
 
 # dns bootoption
-if [ -n "$DNSSERVER1" ]
+if [ -n "$DNSSERVERS" ]
 then
        # disable any existing entries
        if [ -r $RESOLVCONF ]
        then
                sed -i 's/nameserver/# nameserver/' $RESOLVCONF
        fi
-       for i in $DNSSERVER1 $DNSSERVER2
+       for i in $DNSSERVERS
        do
                echo "nameserver $i" >> $RESOLVCONF
        done