# lookup an interface by mac address
mac2if () {
- if=$(ifconfig -a | grep -i "$1" | grep -e "^eth" | awk '{print $1}')
+ if=$(ifconfig -a | awk '{IGNORECASE=1} /^eth.*'$1'/ {print $1; exit}')
echo $if
}
# allow env to override nvram
nvram_get () {
- eval "echo \${$1:=\$(nvram get $1)}"
+ eval "echo \${$1:-\$(nvram get $1)}"
}
# valid interface?
if_valid () {
- [ "${1%[0-9]}" = "vlan" ] && {
- i=${1##vlan}
+ [ "${1%%[0-9]}" = "vlan" ] && {
+ i=${1#vlan}
hwname=$(nvram_get vlan${i}hwname)
hwaddr=$(nvram_get ${hwname}macaddr)
[ -z "$hwaddr" ] && return 1
vif=$(mac2if $hwaddr)
- echo "# vlan${i}: $hwname $hwaddr => $vif"
+ echo "# vlan$i: $hwname $hwaddr => $vif"
$DEBUG ifconfig $vif up
- $DEBUG vconfig add $vif $i
+ $DEBUG vconfig add $vif $i 2>/dev/null
}
- ifconfig "$1" >/dev/null 2>&1 || [ "${1%[0-9]}" = "br" ]
+ ifconfig "$1" >/dev/null 2>&1 || [ "${1%%[0-9]}" = "br" ]
return $?
}
wifi_init () {
echo "# --- wifi init ---"
- hwaddr=$(nvram_get il0macaddr)
- [ -z "$hwaddr" ] && hwaddr=$(nvram_get wl0_hwaddr)
- if=$(mac2if $hwaddr)
+ if=$(awk 'gsub(":","") {print $1}' /proc/net/wireless)
$DEBUG wlconf $if up
}
echo "# --- $type ---"
if=$(nvram_get ${type}_ifname)
- if [ "${if%[0-9]}" = "ppp" ]; then
- if=$(nvram get pppoe_ifname)
+ if [ "${if%%[0-9]}" = "ppp" ]; then
+ if=$(nvram_get pppoe_ifname)
fi
if_valid $if || return
- if [ "${if%[0-9]}" = "br" ]; then
- stp=$(nvram get ${type}_stp)
- $DEBUG ifconfig $if down
+ $DEBUG ifconfig $if down
+ if [ "${if%%[0-9]}" = "br" ]; then
+ stp=$(nvram_get ${type}_stp)
$DEBUG brctl delbr $if
$DEBUG brctl addbr $if
$DEBUG brctl setfd $if 0
if_valid $sif || continue
$DEBUG ifconfig $sif 0.0.0.0 up
$DEBUG brctl addif $if $sif
- }; done
+ } done
fi
if_mac=$(nvram_get ${type}_hwaddr)
- $DEBUG ifconfig $if hw ether $if_mac
+ [ -z "$if_mac" ] || $DEBUG ifconfig $if hw ether $if_mac
if_proto=$(nvram_get ${type}_proto)
case "$if_proto" in
ipcalc -s "$if_netmask" || return
$DEBUG ifconfig $if $if_ip netmask $if_netmask up
- ipcalc -s "$ip_gateway" || return
- $DEBUG route add default gw $ip_gateway
+ ipcalc -s "$if_gateway" || return
+ $DEBUG route add default gw $if_gateway
+
+ [ -f /etc/resolv.conf ] && return
+
+ echo "# --- creating /etc/resolv.conf ---"
+ for dns in $(nvram_get ${type}_dns); do {
+ echo "nameserver $dns" >> /etc/resolv.conf
+ } done
;;
dhcp)
pidfile=/tmp/dhcp-${type}.pid
$DEBUG ifconfig $if 0.0.0.0 up
$DEBUG /sbin/pppoecd $if -u $if_username -p $if_password -i 0 -I $if_redial -T $if_idletime -k
- sleep 5
- $DEBUG /sbin/route add default $if
;;
*)
echo "$if: $if_proto is not supported"
}
### START NETWORKING ###
-wifi_init
-
$DEBUG vconfig set_name_type VLAN_PLUS_VID_NO_PAD
# hacks for 1.x hardware
-[ -z "$(nvram_get vlan0hwname)" ] && {
+[ "$(nvram get boardnum)" = "42" ] && \
+[ "$(nvram get boardtype)" = "bcm94710dev" ] && {
echo "# 1.x HACK"
vlan1hwname="et0"
vlan2hwname="et0"
# use the old names to preserve backwards
# compatibility
remap () {
- eval $1=\"$(nvram_get $1 | awk '{
- gsub(/eth0/,"vlan2")
- gsub(/eth1/,"vlan1")
- print $0
- }')\"
+ eval $1=\"$(nvram_get $1 | awk 'gsub("eth0","vlan2") gsub("eth1","vlan1")')\"
}
remap lan_ifname
configure lan
configure wifi
configure wan
+
+wifi_init
+
+for route in $(nvram_get static_route); do {
+ ip=${route%%:*} route=${route#*:}
+ netmask=${route%%:*} route=${route#*:}
+ gateway=${route%%:*} route=${route#*:}
+ metric=${route%%:*} route=${route#*:}
+ if=${route%%:*}
+ $DEBUG route add -net $ip netmask $netmask gw $gateway metric $metric dev $if
+} done