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 rem vlan${i}
35 $DEBUG vconfig add $vif $i
37 ifconfig "$1" >/dev/null 2>&1 || [ "${1%[0-9]}" = "br" ]
42 echo "# --- wifi init ---"
43 hwaddr=$(nvram_get il0macaddr)
44 [ -z "$hwaddr" ] && hwaddr=$(nvram_get wl0_hwaddr)
51 echo "# --- $type ---"
53 if=$(nvram_get ${type}_ifname)
54 if [ "${if%[0-9]}" = "ppp" ]; then
55 if=$(nvram get pppoe_ifname)
57 if_valid $if || return
59 if [ "${if%[0-9]}" = "br" ]; then
60 $DEBUG ifconfig $if down
61 $DEBUG brctl delbr $if
62 $DEBUG brctl addbr $if
63 $DEBUG brctl setfd $if 0
64 if_list=$(nvram_get ${type}_ifnames)
65 for sif in $if_list; do {
66 if_valid $sif || continue
67 $DEBUG ifconfig $sif 0.0.0.0 up
68 $DEBUG brctl addif $if $sif
72 if_mac=$(nvram_get ${type}_hwaddr)
73 $DEBUG ifconfig $if hw ether $if_mac
75 if_proto=$(nvram_get ${type}_proto)
78 if_ip=$(nvram_get ${type}_ipaddr)
79 if_netmask=$(nvram_get ${type}_netmask)
80 if_gateway=$(nvram_get ${type}_gateway)
82 ipcalc -s "$if_ip" || return
83 ipcalc -s "$if_netmask" || return
84 $DEBUG ifconfig $if $if_ip netmask $if_netmask up
86 ipcalc -s "$ip_gateway" || return
87 $DEBUG route add default gw $ip_gateway
90 pidfile=/tmp/dhcp-${type}.pid
91 if [ -f $pidfile ]; then
92 $DEBUG kill $(cat $pidfile)
94 $DEBUG udhcpc -i $if -b -p /tmp/dhcp-${type}.pid
97 if_username=$(nvram_get ppp_username)
98 if_password=$(nvram_get ppp_passwd)
99 if_redial=$(nvram_get ppp_redialperiod)
100 if_idletime=$(nvram_get ppp_idletime)
102 $DEBUG ifconfig $if 0.0.0.0 up
104 $DEBUG pppd user "$if_username" password "$if_password" defaultroute
107 echo "$if: $if_proto is not supported"
112 ### START NETWORKING ###
115 $DEBUG vconfig set_name_type VLAN_PLUS_VID_NO_PAD
117 # hacks for 1.x hardware
118 [ -z "$(nvram_get vlan0hwname)" ] && {
123 # we remap old device names to new
124 # it's recommended that you continue to
125 # use the old names to preserve backwards
128 eval $1=\"$(nvram_get $1 | awk '{
144 # failsafe if reset is held
145 [ "$FAILSAFE" = "true" ] && {
147 lan_ifnames="vlan0 vlan2 eth1 eth2 eth3"
148 lan_ipaddr="192.168.1.1"
149 lan_netmask="255.255.255.0"
150 lan_hwaddr="00:0B:AD:0A:DD:00"
155 # linksys bug has lan doing dhcp; force static