2 # OpenWrt Networking script
4 # Copyright (c) 2004 Mike Baker <mbm at alt.org>
9 export PATH=/usr/bin:/bin:/usr/sbin:/sbin
11 # lookup an interface by mac address
13 if=$(ifconfig -a | grep -i "$1" | grep -e "^eth" | awk '{print $1}')
17 # allow env to override nvram
19 eval "echo \${$1:=\$(nvram get $1)}"
24 [ "${1%[0-9]}" = "vlan" ] && {
26 hwname=$(nvram_get vlan${i}hwname)
27 hwaddr=$(nvram_get ${hwname}macaddr)
28 [ -z "$hwaddr" ] && return 1
31 echo "# vlan${i}: $hwname $hwaddr => $vif"
33 $DEBUG ifconfig $vif up
34 $DEBUG vconfig add $vif $i
36 ifconfig "$1" >/dev/null 2>&1 || [ "${1%[0-9]}" = "br" ]
41 echo "# --- wifi init ---"
42 hwaddr=$(nvram_get il0macaddr)
43 [ -z "$hwaddr" ] && hwaddr=$(nvram_get wl0_hwaddr)
50 echo "# --- $type ---"
52 if=$(nvram_get ${type}_ifname)
53 if [ "${if%[0-9]}" = "ppp" ]; then
54 if=$(nvram get pppoe_ifname)
56 if_valid $if || return
58 if [ "${if%[0-9]}" = "br" ]; then
59 stp=$(nvram get ${type}_stp)
60 $DEBUG ifconfig $if down
61 $DEBUG brctl delbr $if
62 $DEBUG brctl addbr $if
63 $DEBUG brctl setfd $if 0
64 $DEBUG brctl stp $if $stp
65 if_list=$(nvram_get ${type}_ifnames)
66 for sif in $if_list; do {
67 if_valid $sif || continue
68 $DEBUG ifconfig $sif 0.0.0.0 up
69 $DEBUG brctl addif $if $sif
73 if_mac=$(nvram_get ${type}_hwaddr)
74 $DEBUG ifconfig $if hw ether $if_mac
76 if_proto=$(nvram_get ${type}_proto)
79 if_ip=$(nvram_get ${type}_ipaddr)
80 if_netmask=$(nvram_get ${type}_netmask)
81 if_gateway=$(nvram_get ${type}_gateway)
83 ipcalc -s "$if_ip" || return
84 ipcalc -s "$if_netmask" || return
85 $DEBUG ifconfig $if $if_ip netmask $if_netmask up
87 ipcalc -s "$ip_gateway" || return
88 $DEBUG route add default gw $ip_gateway
91 pidfile=/tmp/dhcp-${type}.pid
92 if [ -f $pidfile ]; then
93 $DEBUG kill $(cat $pidfile)
95 $DEBUG udhcpc -i $if -b -p /tmp/dhcp-${type}.pid
98 if_username=$(nvram_get ppp_username)
99 if_password=$(nvram_get ppp_passwd)
100 if_redial=$(nvram_get ppp_redialperiod)
101 if_idletime=$(nvram_get ppp_idletime)
103 $DEBUG ifconfig $if 0.0.0.0 up
105 $DEBUG /sbin/pppoecd $if -u $if_username -p $if_password -i 0 -I $if_redial -T $if_idletime -k
107 $DEBUG /sbin/route add default $if
110 echo "$if: $if_proto is not supported"
115 ### START NETWORKING ###
118 $DEBUG vconfig set_name_type VLAN_PLUS_VID_NO_PAD
120 # hacks for 1.x hardware
121 [ -z "$(nvram_get vlan0hwname)" ] && {
126 # we remap old device names to new
127 # it's recommended that you continue to
128 # use the old names to preserve backwards
131 eval $1=\"$(nvram_get $1 | awk '{
147 # failsafe if reset is held
148 [ "$FAILSAFE" = "true" ] && {
150 lan_ifnames="vlan0 vlan2 eth1 eth2 eth3"
151 lan_ipaddr="192.168.1.1"
152 lan_netmask="255.255.255.0"
153 lan_hwaddr="00:0B:AD:0A:DD:00"
158 # linksys bug has lan doing dhcp; force static