SourceForge.net Logo

B.27. /etc/sysconfig/network/ifup

#!/bin/ash
# 
# GPL $Id: ifup,v 1.6 2005/10/09 16:39:06 cvonk Exp $
# system network script bring up a network interface

error_exit() {
    echo "ifup: error: $@" >&2; exit 1
}

list_additional_functionality() {
    EXTRAFUNCT=${EXTRAFUNCT}${EXTRAFUNCT:+,}$1
}

bootproto_static() {
    if [ ! $DEV = lo ] ; then
	if ! arping -q -c 2 -w 3 -D -I ${DEV} ${IPADDR} ; then
	    error_exit "another host already uses address ${IPADDR} on ${DEV}."
	fi
    fi
    
    if ! ip address add $IPADDR/$NETMASKBITS brd + dev $DEV 2>/dev/null >devnull ; then
        if [ ! $DEV = lo ] ; then
   	    error_exit "failed to configure $IPADDR/$NETMASKBITS on $DEV."
	fi
    fi
    
    # update ARP cache of neighboring computers
    if [ ! $DEV = lo ] ; then
	arping -q -A -c 1 -I $DEV $IPADDR 2>/dev/null >/dev/null </dev/null
	arping -q -U -c 1 -I $DEV $IPADDR 2>/dev/null >/dev/null </dev/null
    fi
}

bootproto_dhcp() {
    /sbin/udhcpc -i $DEV -s /etc/sysconfig/network/udhcpc.script $DHCP_EXTRA \
	2>/dev/null >/dev/null </dev/null
}

bootproto_pppoe() {
    /usr/sbin/adsl-start /etc/sysconfig/network/${DEV}.cfg
}

EXTRAFUNCT=
DEV=$1
if [ ! -f /etc/sysconfig/network/$DEV.conf ] ; then
    error_exit "missing dev config" >&2
fi
. /etc/sysconfig/network/$DEV.conf

if ! iwconfig $1 2>&1 | grep -q "no wireless extensions" ; then
    for kmod in $WIRELESS_KMODS; do
	case "$kmod" in
	    ath_pci.ko)
		INSMOD_PARAMS="autocreate=ap ratectl=sample"
		if [ -n "$WIRELESS_ATHEROS_COUNTRYCODE" ] ; then
		    INSMOD_PARAMS="$INSMOD_PARAMS countrycode=$WIRELESS_ATHEROS_COUNTRYCODE"
		fi
		;;
	    *)
		INSMOD_PARAMS=
		;;
	esac
	insmod /lib/modules/`uname -r`/net/$kmod $INSMOD_PARAMS
    done

#    CUR_REGDOMAIN=`cat /proc/sys/dev/$DEV/regdomain`
#    if [  -x /usr/sbin/regdomain -a -n "$WIRELESS_ATHEROS_REGDOMAIN" -a \
#	$CUR_REGDOMAIN != "$WIRELESS_ATHEROS_REGDOMAIN" ] ; then
#	/usr/sbin/regdomain 0x80080000 $WIRELESS_ATHEROS_REGDOMAIN
#	echo "changing regdomain requires a reboot" >&2
#    fi

    if ! ip -oneline link | grep -q -c $DEV ; then
	error_exit "$DEV not present"
    fi
    iwconfig $DEV channel  ${WIRELESS_CHANNEL:-1}
    iwconfig $DEV mode     ${WIRELESS_MODE:-Managed}
    iwconfig $DEV enc      ${WIRELESS_KEY:-off}
    iwpriv   $DEV mode     ${WIRELESS_MADWIFI_MODE:-0}
    iwpriv   $DEV authmode ${WIRELESS_MADWIFI_AUTHMODE:-2}
    iwpriv   $DEV turbo    ${WIRELESS_MADWIFI_TURBO:-0}
    iwconfig $DEV essid    ${WIRELESS_ESSID:-any} # triggers scanning/discovery
fi

# the firewall.fw script also configures the interfaces, but somehow this
# does not with for DHCP requests over the wireless link

if ! ip link set up dev $DEV ; then
    error_exit "cannot enable interface $dev."
fi

# the IP address is not configured for i.e. when DHCP is used for the external
# interface
case "$BOOTPROTO" in
    dhcp)
	list_additional_functionality dhcp
	bootproto_dhcp
	;;
    pppoe)
	list_additional_functionality pppoe
	bootproto_pppoe
	;;
    static|*)
	bootproto_static
	;;
esac

if [ ! -z "$DEFAULTGW" ] ; then
    list_additional_functionality gw
    ip route add default via $DEFAULTGW
fi

if [ ! -z "$EXTRAFUNCT" ] ; then
    echo -n "($EXTRAFUNCT)"
fi
# 

Example B.27. /etc/sysconfig/network/ifup