diff options
Diffstat (limited to 'rc.inet1')
-rw-r--r-- | rc.inet1 | 49 |
1 files changed, 29 insertions, 20 deletions
@@ -159,15 +159,17 @@ if_up() { 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 - if [ -n "${HWADDR[$i]}" ]; then # Set hardware address _before_ the interface goes up: + # Set hardware address _before_ the interface goes up: + 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]} fi + # Initialize any wireless parameters: if [ -x /etc/rc.d/rc.wireless ]; then - . /etc/rc.d/rc.wireless ${1} start # Initialize any wireless parameters + . /etc/rc.d/rc.wireless ${1} start fi if [ "${USE_DHCP[$i]}" = "yes" ] || [ "${USE_DHCP6[$i]}" = "yes" ]; then # use dhcpcd to bring interface up - # Disable v6 IP auto configuration. + # Disable v6 IP auto configuration: echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf # Clear DHCP_OPTIONS before adding new options to it: unset DHCP_OPTIONS @@ -214,42 +216,47 @@ if_up() { done fi fi - elif [ -n "${IPADDR[$i]}" ] || [ -n "${IPADDR6[$i]}" ]; then # Use a fixed IP to bring interface up - # Disable v6 IP auto configuration. + elif [ -n "${IPADDR[$i]}" ] || [ -n "${IPADDR6[$i]}" ]; then # use a fixed IP to bring interface up + # Disable v6 IP auto configuration: echo "0" >/proc/sys/net/ipv6/conf/$1/autoconf - if [ -n "${IPADDR[$i]}" ]; then # Configure interface with a v4 IP + # Configure interface with a v4 IP: + if [ -n "${IPADDR[$i]}" ]; then if [ -z "${NETMASK[$i]}"; then - echo "/etc/rc.d/rc.inet1: no NETMASK set for ${1} - assuming a /24 (aka, 255.255.255.0)" + echo "/etc/rc.d/rc.inet1: no NETMASK set for ${1} - assuming a /24 (aka, 255.255.255.0)" | $LOGGER NETMASK[$i]="24" fi echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]} broadcast + dev ${1}" | $LOGGER /sbin/ip -4 address add ${IPADDR[$i]}/${NETMASK[$i]} broadcast + dev ${1} if [ "$?" != "0" ]; then - echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR[$i]} for ${1}" + echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR[$i]} for ${1}" | $LOGGER return fi fi - if [ -n "${IPADDR6[$i]}" ]; then # Configure interface with a v6 IP + # Configure interface with a v6 IP: + if [ -n "${IPADDR6[$i]}" ]; then if [ -z "${NETMASK6[$i]}"; then - echo "/etc/rc.d/rc.inet1: no NETMASK6 set for ${1} - assuming a /64" + echo "/etc/rc.d/rc.inet1: no NETMASK6 set for ${1} - assuming a /64" | $LOGGER NETMASK[$i]="64" fi echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]} dev ${1}" | $LOGGER /sbin/ip -6 address add ${IPADDR6[$i]}/${NETMASK6[$i]} dev ${1} if [ "$?" != "0" ]; then - echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR6[$i]} for ${1}" + echo "/etc/rc.d/rc.inet1: failed to a set IP ${IPADDR6[$i]} for ${1}" | $LOGGER return fi fi - /sbin/ip link set dev ${1} up # Bring up interface + # Bring up the interface if it's not already up: + /sbin/ip link set dev ${1} up elif [ "${USE_STATELESS[$i]}" = "yes" ]; then # interface should configure itself via stateless RA auto config echo "/etc/rc.d/rc.inet1: using stateless Router Advertisement auto configuration for ${1}" | $LOGGER + # Enable accepting of router advertisment packets, and auto configuration of interfaces: echo "1" >/proc/sys/net/ipv6/conf/$1/accept_ra echo "1" >/proc/sys/net/ipv6/conf/$1/autoconf + # Bring the interface up: /sbin/ip link set dev ${1} up - for i in {1..10}; do # Give some time for the interface to configure + for ((j = 20; j--;)); do # give some time for the interface to configure /sbin/ip -6 address show dynamic dev ${1} 2>/dev/null | grep -Ewq 'inet6' && break - sleep 1 + sleep 0.5 done if ! /sbin/ip -6 address show dynamic dev ${1} 2>/dev/null | grep -Ewq 'inet6'; then echo "/etc/rc.d/rc.inet1: failed to auto configure ${1} after 10 seconds" | $LOGGER @@ -259,15 +266,15 @@ if_up() { debug_log "${1} interface is not configured in /etc/rc.d/rc.inet1.conf" return fi - # Add extra IPv4 and v6 addresses, if defined, to the interface + # Add extra IPv4 and v6 addresses, if defined, 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" - echo "/etc/rc.d/rc.inet1: /sbin/ip address add ${ip}/${nm} dev ${1} label ${1}:${num}" | $LOGGER - /sbin/ip address add ${ip}/${nm} dev ${1} label ${1}:${num} + echo "/etc/rc.d/rc.inet1: /sbin/ip -4 address add ${ip}/${nm} dev ${1} label ${1}:${num}" | $LOGGER + /sbin/ip -4 address add ${ip}/${nm} dev ${1} label ${1}:${num} num=$(($num + 1)) done fi @@ -276,16 +283,18 @@ if_up() { ip="${ipalias%/*}" nm="${ipalias#*/}" [ -z "$nm" ] || [ "$ip" == "$nm" ] && nm="64" - # Unluke IPv4, v6 addresses don't get a label. + # Unluke IPv4, v6 addresses don't get a label: echo "/etc/rc.d/rc.inet1: /sbin/ip -6 address add ${ip}/${nm} dev ${1}" | $LOGGER /sbin/ip -6 address add ${ip}/${nm} dev ${1} done fi - if [ -n "${MTU[$i]}" ]; then # Force an MTU (possibly over-riding that set by DHCP) + # Force an MTU (possibly over-riding that set by DHCP): + if [ -n "${MTU[$i]}" ]; then echo "/etc/rc.d/rc.inet1: /sbin/ip link set dev ${1} mtu ${MTU[$i]}" | $LOGGER /sbin/ip link set dev ${1} mtu ${MTU[$i]} fi - if [ "${PROMISCUOUS[$i]}" = "yes" ]; then # Set promiscuous mode on the interface + # Set promiscuous mode on the interface: + if [ "${PROMISCUOUS[$i]}" = "yes" ]; then /sbin/ip link set dev ${1} promisc on fi else |