cleanup
[openwrt.git] / root / etc / networking.sh
index 5242952..bb85511 100755 (executable)
@@ -10,7 +10,7 @@ export PATH=/usr/bin:/bin:/usr/sbin:/sbin
 
 # 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
 }
 
@@ -31,8 +31,7 @@ if_valid () {
     echo "# vlan${i}: $hwname $hwaddr => $vif"
 
     $DEBUG ifconfig $vif up
-    #$DEBUG vconfig rem vlan${i}
-    $DEBUG vconfig add $vif $i
+    $DEBUG vconfig add $vif $i 2>/dev/null
   }
   ifconfig "$1" >/dev/null 2>&1 || [ "${1%[0-9]}" = "br" ] 
   return $?
@@ -52,15 +51,17 @@ configure () {
   
   if=$(nvram_get ${type}_ifname)
   if [ "${if%[0-9]}" = "ppp" ]; then
-    if=$(nvram get pppoe_ifname) 
+    if=$(nvram_get pppoe_ifname) 
   fi
   if_valid $if || return
   
+  $DEBUG ifconfig $if down
   if [ "${if%[0-9]}" = "br" ]; then
-    $DEBUG ifconfig $if down
+    stp=$(nvram_get ${type}_stp)
     $DEBUG brctl delbr $if
     $DEBUG brctl addbr $if
     $DEBUG brctl setfd $if 0
+    $DEBUG brctl stp $if $stp
     if_list=$(nvram_get ${type}_ifnames)
     for sif in $if_list; do {
       if_valid $sif || continue
@@ -70,7 +71,7 @@ configure () {
   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
@@ -83,8 +84,15 @@ configure () {
       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
@@ -101,7 +109,7 @@ configure () {
       
       $DEBUG ifconfig $if 0.0.0.0 up
       
-      $DEBUG pppd user "$if_username" password "$if_password" defaultroute  
+      $DEBUG /sbin/pppoecd $if -u $if_username -p $if_password -i 0 -I $if_redial -T $if_idletime -k
     ;;
     *)
       echo "$if: $if_proto is not supported"
@@ -158,3 +166,12 @@ lan_proto="static"
 configure lan
 configure wifi
 configure wan
+
+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
This page took 0.04343 seconds and 4 git commands to generate.