source: freewrt/package/webif/files/network-nvram.sh@ 6fc4520e

freewrt_1_0 freewrt_2_0
Last change on this file since 6fc4520e was 7669240, checked in by Waldemar Brodkorb <wbx@…>, 19 years ago
  • add a generic network init script which is using busybox ifup/ifdown
  • move ifup/ifdown with nvram calls to webif package
  • add specific dnsmasq.conf and startup script for dnsmasq for webif
  • add version file

This unbreaks DNS/DHCP options in Webif. Even WPA/WPA2 seems possible
if you install broadcom-nas package. I have no WPA/WPA2 enabled box
or operating system to test..

tg@ will add some rc.conf checks so that either webif network
configuration is used or ifup/ifdown from busybox

git-svn-id: svn://www.freewrt.org/trunk/freewrt@673 afb5a338-a214-0410-bd46-81f09a774fd1

  • Property mode set to 100644
File size: 2.4 KB
Line 
1alias debug=${DEBUG:-:}
2
3# valid interface?
4if_valid() (
5 ifconfig "$1" >&- 2>&- ||
6 [ "${1%%[0-9]}" = br ] || {
7 [ "${1%%[0-9]}" = vlan ] && (
8 i=${1#vlan}
9 hwname=$(nvram get vlan${i}hwname)
10 hwaddr=$(nvram get ${hwname}macaddr)
11 [ -z "$hwaddr" ] && return 1
12
13 vif=$(ifconfig -a | awk \
14 '/^eth.*'$hwaddr'/ {print $1; exit}' IGNORECASE=1)
15 debug "# vlan$i => $vif"
16
17 $DEBUG ifconfig $vif up
18 $DEBUG vconfig add $vif $i 2>&-
19 )
20 } || { debug "# missing interface '$1' ignored"; false; }
21)
22
23do_ifup() {
24 if_proto=$(nvram get ${2}_proto)
25 if=$(nvram get ${2}_ifname)
26 [ "${if%%[0-9]}" = ppp ] && if=$(nvram get ${2}_device)
27
28 pidfile=/var/run/${if}.pid
29 [ -f $pidfile ] && $DEBUG kill $(<$pidfile)
30
31 case $1 in
32 static)
33 ip=$(nvram get ${2}_ipaddr)
34 netmask=$(nvram get ${2}_netmask)
35 gateway=$(nvram get ${2}_gateway)
36 mtu=$(nvram get ${2}_mtu)
37 static_route=$(nvram get ${2}_static_route)
38
39 $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} ${mtu:+mtu $(($mtu))} broadcast + up
40 ${gateway:+$DEBUG route add default gw $gateway}
41
42 [ -n "$static_route" ] && for route in $static_route; do
43 eval "set $(echo $route | sed 's/:/ /g')"
44 [ "$2" = "255.255.255.255" ] && opt=-host
45 $DEBUG route add ${opt:-"-net"} $1 netmask $2 gw $3 metric $4
46 done
47
48 [ -f /etc/resolv.conf ] || {
49 debug "# --- creating /etc/resolv.conf ---"
50 for dns in $(nvram get ${2}_dns); do
51 echo "nameserver $dns" >>/etc/resolv.conf
52 done
53 }
54
55 env -i ACTION=ifup INTERFACE="${2}" PROTO=static /sbin/hotplug iface &
56 ;;
57 dhcp)
58 DHCP_IP=$(nvram get ${2}_ipaddr)
59 DHCP_NETMASK=$(nvram get ${2}_netmask)
60 mtu=$(nvram get ${2}_mtu)
61 $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} ${mtu:+mtu $(($mtu))} broadcast + up
62
63 DHCP_ARGS="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile"
64 DHCP_HOSTNAME=$(nvram get ${2}_hostname)
65 DHCP_HOSTNAME=${DHCP_HOSTNAME%%.*}
66 [ -z $DHCP_HOSTNAME ] || DHCP_ARGS="$DHCP_ARGS -H $DHCP_HOSTNAME"
67 [ "$if_proto" = pptp ] && DHCP_ARGS="$DHCP_ARGS -n -q" || DHCP_ARGS="$DHCP_ARGS -R &"
68 [ -r $pidfile ] && oldpid=$(<$pidfile)
69 ${DEBUG:-eval} "udhcpc $DHCP_ARGS"
70 [ -n "$oldpid" ] && pidof udhcpc | grep "$oldpid" >&- 2>&- && {
71 sleep 1
72 kill -9 $oldpid
73 }
74 # hotplug events are handled by /usr/share/udhcpc/default.script
75 ;;
76 none|"")
77 ;;
78 *)
79 [ -x "/sbin/ifup.$1" ] && { $DEBUG /sbin/ifup.$1 ${2}; exit; }
80 echo "### ifup ${2}: ignored ${2}_proto=\"$1\" (not supported)"
81 ;;
82 esac
83}
84
Note: See TracBrowser for help on using the repository browser.