summaryrefslogtreecommitdiffstats
path: root/rc.inet1
diff options
context:
space:
mode:
authorDarren 'Tadgy' Austin <darren@afterdark.org.uk>2019-11-07 03:32:06 +0000
committerDarren 'Tadgy' Austin <darren@afterdark.org.uk>2019-11-07 03:32:06 +0000
commit1e091a1493fc3f54396bfc4d4cbfd559dee95264 (patch)
tree8160303b2f778f9a80c9cf72a2e137d3dd0c6916 /rc.inet1
parent114536e707d30487de2b9ede1d3ff933fb28cafd (diff)
downloadslacknetsetup-1e091a1493fc3f54396bfc4d4cbfd559dee95264.tar.xz
Initial commit of VLAN support.
Diffstat (limited to 'rc.inet1')
-rw-r--r--rc.inet135
1 files changed, 31 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