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