diff options
author | Darren 'Tadgy' Austin <darren@afterdark.org.uk> | 2019-11-13 04:18:45 +0000 |
---|---|---|
committer | Robby Workman <rworkman@slackware.com> | 2019-11-13 00:22:00 -0600 |
commit | 81f8f8a24fa6d91eb67c8b6bd215afb779722b65 (patch) | |
tree | 6d81b73698fcdcecf10b89a6651aedd025aedb84 | |
parent | 7ac0561ab349bb33a1b6bb6c31fb73bbe5ca3dbd (diff) | |
download | slacknetsetup-81f8f8a24fa6d91eb67c8b6bd215afb779722b65.tar.xz |
Be consistent with variable case. Emit warning when assuming netmask.
-rw-r--r-- | rc.inet1 | 97 |
1 files changed, 50 insertions, 47 deletions
@@ -230,7 +230,7 @@ if_up() { i=$(($i+1)) done # If "i" is greater or equal to "MAXNICS" at this point, it means we didn't - # find an entry in IFNAME array corresponding to "$1", which likely means + # find an entry in IFNAME array corresponding to "${1}", which likely means # there are more interfaces configured than MAXNICS. Let's err on the # side of caution and do nothing instead of possibly doing the wrong thing. if [ $i -ge $MAXNICS ]; then @@ -251,24 +251,24 @@ if_up() { local IF_UP=0 # Handle VLAN interfaces before trying to configure IP addresses. if echo "${1}" | grep -Fq .; then - iface="${1%.*}" - vlan="${1##*.}" + IFACE="${1%.*}" + VLAN="${1##*.}" # Check if the underlying interface is already up. - if ! /sbin/ip link show dev ${iface} 2>/dev/null| grep -wq "state UP"; then + if ! /sbin/ip link show dev $IFACE 2>/dev/null| grep -wq "state UP"; then # Bring up the underlying interface. - debug_log "/sbin/ip link set dev ${iface} up" - if ! /sbin/ip link set dev ${iface} up; then - info_log "${1}: failed to bring up interface ${iface}" + debug_log "/sbin/ip link set dev $IFACE up" + if ! /sbin/ip link set dev $IFACE up; then + info_log "${1}: failed to bring up interface $IFACE" return fi IF_UP=1 fi # Configure the VLAN interface. info_log "${1}: creating VLAN interface" - debug_log "/sbin/ip link add link ${iface} name ${1} type vlan id ${vlan}" - if ! /sbin/ip link add link ${iface} name ${1} type vlan id ${vlan}; then + debug_log "/sbin/ip link add link $IFACE name ${1} type vlan id $VLAN" + if ! /sbin/ip link add link $IFACE name ${1} type vlan id $VLAN; then info_log "${1}: failed to create VLAN interface" - ((IF_UP == 1)) && /sbin/ip link set dev ${iface} down + ((IF_UP == 1)) && /sbin/ip link set dev $IFACE down return fi while read -r -d \| VLANOPT; do @@ -292,15 +292,15 @@ if_up() { if [ -e /proc/sys/net/ipv6 ]; then # ipv6 networking is available # Disable v6 IP auto configuration before trying to bring up the interface: debug_log "${1}: disabling IPv6 autoconf" - echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf + echo "0" >/proc/sys/net/ipv6/conf/${1}/autoconf if [ "${USE_RA[$i]}" = "yes" ]; then # Unconditionally accept router advertisements on this interface: debug_log "${1}: accepting IPv6 RA" - echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra + echo "1" >/proc/sys/net/ipv6/conf/${1}/accept_ra else # Disable router advertisments on this interface until SLAAC is enabled: debug_log "${1}: ignoring IPv6 RA" - echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra + echo "0" >/proc/sys/net/ipv6/conf/${1}/accept_ra fi fi IF_UP=0 @@ -336,7 +336,7 @@ if_up() { # Enable accepting of RA packets if explicitly told to: if [ -e /proc/sys/net/ipv6 ] && [ "${USE_RA[$i]}" = "yes" ]; then debug_log "${1}: unconditionally accepting IPv6 RA" - echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra + echo "1" >/proc/sys/net/ipv6/conf/${1}/accept_ra fi IF_UP=1 else @@ -350,13 +350,13 @@ if_up() { # Enable accepting of RA packets, unless explicitly configured not to: if [ "${USE_RA[$i]}" = "no" ]; then debug_log "${1}: ignoring IPv6 RA" - echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra + echo "0" >/proc/sys/net/ipv6/conf/${1}/accept_ra else debug_log "${1}: accepting IPv6 RA" - echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra + echo "1" >/proc/sys/net/ipv6/conf/${1}/accept_ra fi # Enable auto configuration of interfaces: - echo "1" >/proc/sys/net/ipv6/conf/$1/autoconf + echo "1" >/proc/sys/net/ipv6/conf/${1}/autoconf # Bring the interface up: debug_log "/sbin/ip link set dev ${1} up" /sbin/ip link set dev ${1} up @@ -375,7 +375,7 @@ if_up() { if [ "${USE_DHCP[$i]}" != "yes" ] && [ -n "${IPADDR[$i]}" ]; then # add a fixed v4 IP to the interface info_log "${1}: setting fixed IPv4 address" if [ -z "${NETMASK[$i]}" ]; then - info_log "${1}: no NETMASK set for IP ${IPADDR[$i]} - assuming 24 (aka, 255.255.255.0)" + info_log "${1}: no NETMASK set for primary IP ${IPADDR[$i]} - assuming 24 (aka, 255.255.255.0)" NETMASK[$i]="24" fi debug_log "/sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]#/} broadcast + dev ${1}" @@ -396,25 +396,25 @@ if_up() { # Disable DAD while bringing up the interface - but note that this means the loss of detection of a # duplicate address. It's a trade off, unfortunately. debug_log "${1}: disabling IPv6 DAD" - echo "0" >/proc/sys/net/ipv6/conf/$1/accept_dad - for v6ip in ${IP6ADDRS[$i]}; do - ip="${v6ip%/*}" - prefix="${v6ip#*/}" - if [ -z "$prefix" ] || [ "$ip" == "$prefix" ]; then - info_log "${1}: no prefix length set for IP ${ip} - assuming 64" - prefix="64" + echo "0" >/proc/sys/net/ipv6/conf/${1}/accept_dad + for V6IP in ${IP6ADDRS[$i]}; do + IP="${V6IP%/*}" + PREFIX="${V6IP#*/}" + if [ -z "$PREFIX" ] || [ "$IP" == "$PREFIX" ]; then + info_log "${1}: no prefix length set for IP $IP - assuming 64" + PREFIX="64" fi - debug_log "/sbin/ip -6 address add ${ip}/${prefix} dev ${1}" - if /sbin/ip -6 address add ${ip}/${prefix} dev ${1} && \ + debug_log "/sbin/ip -6 address add $IP/$PREFIX dev ${1}" + if /sbin/ip -6 address add $IP/$PREFIX dev ${1} && \ /sbin/ip link set dev ${1} up; then # Enable accepting of RA packets if explicitly told to. if [ "${USE_RA[$i]}" = "yes" ]; then debug_log "${1}: unconditionally accepting IPv6 RA" - echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra + echo "1" >/proc/sys/net/ipv6/conf/${1}/accept_ra fi IF_UP=1 else - info_log "${1}: failed to set IP ${ip}" + info_log "${1}: failed to set IP $IP" if (($IF_UP != 1)); then # a v4 address was configured, don't flush it /sbin/ip address flush dev ${1} /sbin/ip link set dev ${1} down @@ -423,22 +423,25 @@ if_up() { done # Reset accept_dad back to default now all the IPs are configured: debug_log "${1}: resetting IPv6 DAD to default" - cat /proc/sys/net/ipv6/conf/default/accept_dad >/proc/sys/net/ipv6/conf/$1/accept_dad + cat /proc/sys/net/ipv6/conf/default/accept_dad >/proc/sys/net/ipv6/conf/${1}/accept_dad fi if (($IF_UP == 1)); then # only do further config if the interface came up info_log "${1}: setting fixed IPv4 alias addresses" # Add extra IPv4 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" - debug_log "/sbin/ip -4 address add ${ip}/${nm} broadcast + dev ${1} label ${1}:${num}" - if /sbin/ip -4 address add ${ip}/${nm} broadcast + dev ${1} label ${1}:${num}; then - num=$(($num + 1)) + NUM=0 + for IPALIAS in ${IPALIASES[$i]}; do + IP="${IPALIAS%/*}" + NM="${IPALIAS#*/}" + if [ -z "$NM" ] || [ "$IP" == "$NM" ]; then + info_log "${1}: no netmask set for alias IP $IP - assuming 24 (aka, 255.255.255.0)" + NM="24" + fi + debug_log "/sbin/ip -4 address add $IP/$NM broadcast + dev ${1} label ${1}:$NUM" + if /sbin/ip -4 address add $IP/$NM broadcast + dev ${1} label ${1}:$NUM; then + NUM=$(($NUM + 1)) else - info_log "${1}: failed to add alias IP ${ip}" + info_log "${1}: failed to add alias IP $IP" fi done fi @@ -495,8 +498,8 @@ if_down() { # Disable v6 IP auto configuration and RA before trying to clear the IP from the interface: if [ -e /proc/sys/net/ipv6 ]; then debug_log "${1}: disabling IPv6 autoconf and RA" - echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf - echo "0" >/proc/sys/net/ipv6/conf/$1/accept_ra + 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 # Flush any remaining IPs: @@ -508,8 +511,8 @@ if_down() { # Reset autoconf and accept_ra back to defaults: if [ -e /proc/sys/net/ipv6 ]; then debug_log "${1}: resetting IPv6 autoconf and RA 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 + 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 # If the interface is a bridge, then destroy it now: [ -n "${BRNICS[$i]}" ] && br_close $i @@ -589,7 +592,7 @@ stop() { ### MAIN ### ############ -case "$1" in +case "${1}" in start|up) # "start" (or "up") brings up all configured interfaces: start ;; @@ -607,16 +610,16 @@ lo_stop|lo_down) # Stop the loopback interface: lo_down ;; *_start|*_up) # Example: "eth1_start" (or "eth1_up") will start the specified interface 'eth1' - INTERFACE=$(echo $1 | /bin/cut -d '_' -f 1) + INTERFACE=$(echo ${1} | /bin/cut -d '_' -f 1) if_up $INTERFACE gateway_up ;; *_stop|*_down) # Example: "eth0_stop" (or "eth0_down") will stop the specified interface 'eth0' - INTERFACE=$(echo $1 | /bin/cut -d '_' -f 1) + INTERFACE=$(echo ${1} | /bin/cut -d '_' -f 1) if_down $INTERFACE ;; *_restart) # Example: "wlan0_restart" will take 'wlan0' down and up again - INTERFACE=$(echo $1 | /bin/cut -d '_' -f 1) + INTERFACE=$(echo ${1} | /bin/cut -d '_' -f 1) if_down $INTERFACE sleep 1 if_up $INTERFACE |