move target/default/target_skeleton into package/base-files, put all the default...
[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 if [ "${if%%[0-9]}" = "br" ]; then
16         stp=$(nvram get ${type}_stp)
17         $DEBUG brctl delbr $if 2>&-
18         $DEBUG brctl addbr $if
19         $DEBUG brctl setfd $if 0
20         $DEBUG brctl stp $if ${stp:-0}
21
22         for sif in $(nvram get ${type}_ifnames); do
23                 if_valid $sif || continue
24                 ${mac:+$DEBUG ifconfig $sif down hw ether $mac}
25                 $DEBUG ifconfig $sif 0.0.0.0 up
26                 $DEBUG brctl addif $if $sif
27         done
28 else
29         ${mac:+$DEBUG ifconfig $if down hw ether $mac}
30 fi
31
32 case "$if_proto" in
33         static)
34                 ip=$(nvram get ${type}_ipaddr)
35                 netmask=$(nvram get ${type}_netmask)
36                 gateway=$(nvram get ${type}_gateway)
37
38                 $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
39                 ${gateway:+$DEBUG route add default gw $gateway}
40
41                 [ -f /etc/resolv.conf ] && return
42
43                 debug "# --- creating /etc/resolv.conf ---"
44                 for dns in $(nvram get ${type}_dns); do
45                         echo "nameserver $dns" >> /etc/resolv.conf
46                 done
47         ;;
48         dhcp)
49                 ip=$(nvram get ${type}_ipaddr)
50                 [ -f $pidfile ] && $DEBUG kill $(cat $pidfile)
51                 ${DEBUG:-eval} "udhcpc -R -i $if ${ip:+-r $ip} -b -p $pidfile &" 
52         ;;
53         none|"")
54         ;;
55         *)
56                 [ -x "/sbin/ifup.${if_proto}" ] && { $DEBUG /sbin/ifup.${if_proto} $*; exit; }
57                 echo "### ifup $type: ignored ${type}_proto=\"$if_proto\" (not supported)"
58         ;;
59 esac