From 1e091a1493fc3f54396bfc4d4cbfd559dee95264 Mon Sep 17 00:00:00 2001 From: Darren 'Tadgy' Austin Date: Thu, 7 Nov 2019 03:32:06 +0000 Subject: Initial commit of VLAN support. --- rc.inet1 | 35 +++++++++++++++++++++++++++++++---- rc.inet1.conf | 14 ++++++++++++++ 2 files changed, 45 insertions(+), 4 deletions(-) diff --git a/rc.inet1 b/rc.inet1 index ebbd243..baeeddb 100644 --- a/rc.inet1 +++ b/rc.inet1 @@ -177,10 +177,33 @@ if_up() { debug_log "skipping ${1} early, interface is not configured in /etc/rc.d/rc.inet1.conf" return fi - if [ -e /sys/class/net/${1%%:*} ]; then # interface exists + if [ -e /sys/class/net/${1%%:*} ] || [ -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 - # Set hardware address _before_ the interface goes up: + local IF_UP=0 + # Handle VLAN interfaces before trying to configure IP addresses. + if echo "${IFNAME[$i]}" | grep -Fq .; then + iface="${IFNAME[$i]%.*}" + vlan="${IFNAME[$i]#*.}" + # Check if the underlying interface is already up. + if ! /sbin/ip link show dev ${iface} 2>/dev/null| grep -wq "state UP"; then + # Bring up the underlying interface. + echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${iface} up" | $LOGGER + if ! /sbin/ip link set dev ${iface} up; then + echo "/etc/rc.d/rc.inet1: failed to bring up ${iface} for ${1}" | $LOGGER + return + fi + IF_UP=1 + fi + # Configure the VLAN interface. + echo "/etc/rc.d/rc.inet1: /sbin/ip link add link ${iface} name ${1} type vlan id ${vlan}" | $LOGGER + if ! /sbin/ip link add link ${iface} name ${1} type vlan id ${vlan}; then + echo "/etc/rc.d/rc.inet1: failed to bring up VLAN interface ${1}" | $LOGGER + ((IF_UP == 1)) && /sbin/ip link set dev ${iface} down + return + fi + fi + # Set hardware address: if [ -n "${HWADDR[$i]}" ]; then echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} address ${HWADDR[$i]}" | $LOGGER /sbin/ip link set dev ${1} address ${HWADDR[$i]} @@ -200,7 +223,7 @@ if_up() { echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra fi fi - local IF_UP=0 + IF_UP=0 # Slackware historically favours dynamic configuration over fixed IP to configure interfaces, so keep that tradition: if [ "${USE_DHCP[$i]}" = "yes" ] || { [ -e /proc/sys/net/ipv6 ] && [ "${USE_DHCP6[$i]}" = "yes" ]; }; then # use dhcpcd # Declare DHCP_OPTIONS array before adding new options to it: @@ -379,7 +402,7 @@ if_down() { echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra fi - sleep 0.5 # allow time for dhcp/ra to unconfigure the interface + sleep 0.5 # allow time for DHCP/RA to unconfigure the interface # Flush any remaining IPs: echo "/etc/rc.d/rc.inet1: /sbin/ip address flush dev ${1}" | $LOGGER /sbin/ip address flush dev ${1} @@ -391,6 +414,10 @@ if_down() { 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 fi + # Take down VLAN interface, if configured. + if echo "${1}" | grep -Fq .; then + /sbin/ip link delete ${1} + fi # Kill wireless daemons if any: if [ -x /etc/rc.d/rc.wireless ]; then . /etc/rc.d/rc.wireless ${1} stop diff --git a/rc.inet1.conf b/rc.inet1.conf index a39e5a1..c47497f 100644 --- a/rc.inet1.conf +++ b/rc.inet1.conf @@ -73,6 +73,20 @@ DEBUG_ETH_UP="no" # ============================================================================= +# Example of how to configure a VLAN interface. +# The VLAN ID is taken from the full interface name. +# IFNAME[0]="eth0.10" +# IPADDR[0]="192.168.10.1" +# NETMASK[0]="24" +# IPALIASES[0]="" +# USE_DHCP[0]="" +# DHCP_HOSTNAME[0]="" +# IP6ADDRS[0]="" +# USE_SLAAC[0]="" +# USE_DHCP6[0]="" + +# ============================================================================= + # Example of how to configure a bridge: # Note the added "BRNICS" variable which contains a space-separated list # of the physical or virtual network interfaces you want to add to the bridge. -- cgit v1.2.3