9759f8d4d516ab79debfa2c0e041ec6f2a8a284b
[openwrt.git] / openwrt / target / default / target_skeleton / sbin / ifup
1 #!/bin/ash
2 . /etc/functions.sh
3   type=$1
4   debug "### ifup $type ###"
5
6   if=$(nvram get ${type}_ifname)
7   if [ "${if%%[0-9]}" = "ppp" ]; then
8     if=$(nvram get pppoe_ifname)
9   fi
10
11   if_valid $if || return
12
13   $DEBUG ifconfig $if down 2>&-
14   if [ "${if%%[0-9]}" = "br" ]; then
15     stp=$(nvram get ${type}_stp)
16     $DEBUG brctl delbr $if 2>&-
17     $DEBUG brctl addbr $if
18     $DEBUG brctl setfd $if 0
19     $DEBUG brctl stp $if ${stp:-0}
20     for sif in $(nvram get ${type}_ifnames); do {
21       if_valid $sif || continue
22       $DEBUG ifconfig $sif 0.0.0.0 up
23       $DEBUG brctl addif $if $sif
24     } done
25   fi
26
27   mac=$(nvram get ${type}_hwaddr)
28   ${mac:+$DEBUG ifconfig $if hw ether $mac}
29
30   if_proto=$(nvram get ${type}_proto)
31   case "$if_proto" in
32     static)
33       ip=$(nvram get ${type}_ipaddr)
34       netmask=$(nvram get ${type}_netmask)
35       gateway=$(nvram get ${type}_gateway)
36
37       $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
38       ${gateway:+$DEBUG route add default gw $gateway}
39
40       [ -f /etc/resolv.conf ] && return
41
42       debug "# --- creating /etc/resolv.conf ---"
43       for dns in $(nvram get ${type}_dns); do {
44         echo "nameserver $dns" >> /etc/resolv.conf
45       } done
46     ;;
47     dhcp)
48       ip=$(nvram get ${type}_ipaddr)
49       pidfile=/tmp/dhcp-${type}.pid
50       if [ -f $pidfile ]; then
51         $DEBUG kill $(cat $pidfile)
52       fi
53       ${DEBUG:-eval} "udhcpc -i $if ${ip:+-r $ip} -b -p $pidfile &" 
54     ;;
55     none|"")
56         # pppoe is handled by /etc/init.d/S50pppoe
57     ;;
58     *)
59       echo "### ifup $type: ignored ${type}_proto=\"$if_proto\" (not supported)"
60     ;;
61   esac