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 | awk '{IGNORECASE=1} /^eth.*'$1'/ {print $1; exit}')
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 2>/dev/null
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 $DEBUG ifconfig $if down
59 if [ "${if%[0-9]}" = "br" ]; then
60 stp=$(nvram_get ${type}_stp)
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 [ -z "$if_mac" ] || $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 "$if_gateway" || return
88 $DEBUG route add default gw $if_gateway
90 [ -f /etc/resolv.conf ] && return
92 echo "# --- creating /etc/resolv.conf ---"
93 for dns in $(nvram_get ${type}_dns); do {
94 echo "nameserver $dns" >> /etc/resolv.conf
98 pidfile=/tmp/dhcp-${type}.pid
99 if [ -f $pidfile ]; then
100 $DEBUG kill $(cat $pidfile)
102 $DEBUG udhcpc -i $if -b -p /tmp/dhcp-${type}.pid
105 if_username=$(nvram_get ppp_username)
106 if_password=$(nvram_get ppp_passwd)
107 if_redial=$(nvram_get ppp_redialperiod)
108 if_idletime=$(nvram_get ppp_idletime)
110 $DEBUG ifconfig $if 0.0.0.0 up
112 $DEBUG /sbin/pppoecd $if -u $if_username -p $if_password -i 0 -I $if_redial -T $if_idletime -k
115 echo "$if: $if_proto is not supported"
120 ### START NETWORKING ###
123 $DEBUG vconfig set_name_type VLAN_PLUS_VID_NO_PAD
125 # hacks for 1.x hardware
126 [ -z "$(nvram_get vlan0hwname)" ] && {
131 # we remap old device names to new
132 # it's recommended that you continue to
133 # use the old names to preserve backwards
136 eval $1=\"$(nvram_get $1 | awk '{
152 # failsafe if reset is held
153 [ "$FAILSAFE" = "true" ] && {
155 lan_ifnames="vlan0 vlan2 eth1 eth2 eth3"
156 lan_ipaddr="192.168.1.1"
157 lan_netmask="255.255.255.0"
158 lan_hwaddr="00:0B:AD:0A:DD:00"
163 # linksys bug has lan doing dhcp; force static
170 for route in $(nvram_get static_route); do {
171 ip=${route%%:*} route=${route#*:}
172 netmask=${route%%:*} route=${route#*:}
173 gateway=${route%%:*} route=${route#*:}
174 metric=${route%%:*} route=${route#*:}
176 $DEBUG route add -net $ip netmask $netmask gw $gateway metric $metric dev $if