rewrite of the network scripts and configuration
authorFelix Fietkau <nbd@openwrt.org>
Sun, 30 Jul 2006 03:09:09 +0000 (03:09 +0000)
committerFelix Fietkau <nbd@openwrt.org>
Sun, 30 Jul 2006 03:09:09 +0000 (03:09 +0000)
SVN-Revision: 4323

39 files changed:
openwrt/package/base-files/ar7-2.4/etc/config/network
openwrt/package/base-files/aruba-2.6/etc/config/network
openwrt/package/base-files/au1000-2.6/etc/config/network
openwrt/package/base-files/brcm-2.4/etc/hotplug.d/net/09-net [deleted file]
openwrt/package/base-files/brcm-2.4/etc/init.d/S05netconfig
openwrt/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net [deleted file]
openwrt/package/base-files/brcm-2.6/etc/init.d/S05netconfig
openwrt/package/base-files/default/etc/hotplug.d/net/10-net
openwrt/package/base-files/default/etc/init.d/S10boot
openwrt/package/base-files/default/etc/init.d/S40network [new file with mode: 0755]
openwrt/package/base-files/default/etc/init.d/rcS
openwrt/package/base-files/default/lib/network/config.sh [new file with mode: 0755]
openwrt/package/base-files/default/sbin/hotplug
openwrt/package/base-files/default/sbin/ifdown
openwrt/package/base-files/default/sbin/ifup
openwrt/package/base-files/default/sbin/wifi
openwrt/package/base-files/default/usr/share/udhcpc/default.script
openwrt/package/base-files/rb532-2.6/etc/config/network
openwrt/package/base-files/sibyte-2.6/etc/config/network
openwrt/package/base-files/x86-2.4/etc/config/network
openwrt/package/base-files/x86-2.6/etc/config/network
openwrt/package/base-files/xscale-2.6/etc/config/network
openwrt/package/broadcom-wl/files/lib/wifi/broadcom.sh
openwrt/package/dnsmasq/files/dnsmasq.init
openwrt/package/iptables/files/firewall.awk
openwrt/package/iptables/files/firewall.init
openwrt/package/iptables/files/firewall.user [changed mode: 0755->0644]
openwrt/package/ppp/Makefile
openwrt/package/ppp/files/ifup.pppoa [deleted file]
openwrt/package/ppp/files/ifup.pppoe [deleted file]
openwrt/package/ppp/files/ppp.sh [new file with mode: 0644]
openwrt/package/ppp/files/pppoa.sh [new file with mode: 0644]
openwrt/package/ppp/files/pppoe.sh [new file with mode: 0644]
openwrt/package/ppp/files/pptp.sh [new file with mode: 0644]
openwrt/package/pptp/Makefile
openwrt/package/pptp/files/ifup.pptp [deleted file]
openwrt/package/pptp/files/pptp.sh [new file with mode: 0644]
openwrt/package/switch/Makefile
openwrt/package/switch/files/switch.sh [new file with mode: 0644]

index 353538bf4969763e49b91026598f13127dce07e3..19a858e163bb30df71eb55424ab704658e42f5c4 100644 (file)
@@ -1,27 +1,8 @@
 # Network configuration file
-# Uncomment the following statements to change the network configuration
 
-## LAN configuration
-lan_ifname="eth0"
-lan_proto="static"
-lan_ipaddr="192.168.1.1"
-lan_netmask="255.255.255.0"
-# lan_gateway=""
-# lan_dns=""
-
-## WAN configuration
-# wan_proto=pppoe
-wan_ifname=ppp0
-wan_device=nas0
-atm_vpi=8
-atm_vci=35
-# ppp_username=my_username
-# ppp_passwd=my_passwd
-
-## WAN configuration (pppoe)
-pppoe_atm=1
-ppp_mtu=1492
-
-## WAN configuration (pppoa)
-# ppp_mtu=1500
+config interface lan
+       option ifname   eth0
+       option proto    static
+       option ipaddr   192.168.1.1
+       option netmask  255.255.255.0
 
index 65797797eee1666e5ee7afd08e040a62960afa97..aadd4aa8ed033a8ea679af8682955cd41457fff9 100644 (file)
@@ -1,7 +1,5 @@
 # Network configuration file
-# Copyright (C) 2006 OpenWrt.org
 
-
-## LAN configuration
-lan_ifname="eth0"
-lan_proto="dhcp"
+config interface lan
+       option ifname   eth0
+       option proto    dhcp
index 576677bf7c44aa375217a88cf351713c192f73c4..95d7575c92f8d6248f0cca2b819b2b5b44c3ffaa 100644 (file)
@@ -1,13 +1,8 @@
-# Network configuration file
 # Copyright (C) 2006 OpenWrt.org
 
-## LAN configuration
-lan_ifname="br0"
-lan_ifnames="eth0 ath0"
-lan_proto="static"
-lan_ipaddr="192.168.1.1"
-lan_netmask="255.255.255.0"
-
-## WAN configuration
-wan_ifname=""
-wan_proto="none"
+config interface lan
+       option type     bridge
+       option ifnames  "eth0 ath0"
+       option proto    static
+       option ipaddr   192.168.1.1
+       option netmask  255.255.255.0
diff --git a/openwrt/package/base-files/brcm-2.4/etc/hotplug.d/net/09-net b/openwrt/package/base-files/brcm-2.4/etc/hotplug.d/net/09-net
deleted file mode 100644 (file)
index 48abdf4..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-
-setup_wl()
-{
-       [ -f /proc/net/wl0 ] && {
-               lsmod | grep wlcompat >&- || insmod wlcompat
-       }
-       iwconfig "$INTERFACE" 2>&- | grep -v 'no wireless' >&- && {
-               /sbin/wifi
-       }
-}
-setup_eth()
-{
-       [ -d /proc/switch ] || {
-               insmod switch-core
-               insmod switch-robo || insmod switch-adm
-       }
-       if="$(echo "$INTERFACE" | sed s,eth,et,)"
-       ifconfig "$INTERFACE" up 2>&- >&-
-       [ -d "/proc/switch/$INTERFACE" ] || return 0
-       echo "1" > "/proc/switch/$INTERFACE/reset"
-       echo "1" > "/proc/switch/$INTERFACE/enable_vlan"
-       for vlan in $(seq 0 15); do
-               eval "hwname=\"\${vlan${vlan}hwname}\""
-               [ "$hwname" = "$if" ] && {
-                       eval "vports=\"\${vlan${vlan}ports}\""
-                       [ -n "$vports" ] && echo "$vports" > "/proc/switch/$INTERFACE/vlan/$vlan/ports"
-                       $DEBUG vconfig add "$INTERFACE" "$vlan"
-               }
-       done
-}
-
-do_register()
-{
-       case "${INTERFACE%%[0-9]*}" in
-               eth) setup_eth;;
-               wl) setup_wl;;
-       esac
-}
-
-
-case "$ACTION" in
-       add|register) do_register;;
-esac
index 0f53c0c9c97535ce29a24d3adfe8402d8c1d9386..82e4ab9986ccc78ada21dd03cef8118454f5fb69 100755 (executable)
@@ -13,16 +13,16 @@ mkdir -p /etc/config
                strings /dev/mtdblock/3
        fi
 ) | awk '
-function p(name) {
-       if (c[name] != "") print name "=\"" c[name] "\""
+function p(cfgname, name) {
+       if (c[name] != "") print "      option " cfgname "      \"" c[name] "\""
 }
 
 BEGIN {
        FS="="
        c["lan_ifname"]="br0"
-       c["lan_ifnames"]="vlan0 eth1"
+       c["lan_ifnames"]="eth0.0 wl0"
        c["wan_proto"]="none"
-       c["wan_ifname"]="vlan1"
+       c["wan_ifname"]="eth0.1"
        c["vlan0ports"]="1 2 3 4 5*"
        c["vlan1ports"]="0 5"
 }
@@ -34,23 +34,16 @@ BEGIN {
 END {
        # v1 hardware
        if (nvram["boardtype"] == "bcm94710dev") {
-               # Linksys WRT54G v1.x
-               if (nvram["boardnum"] == "42") {
-                       c["vlan0ports"]=""
-                       c["vlan1ports"]=""
-                       c["lan_ifnames"]="vlan2 eth2"
-               }
-
                # Asus WL-500g
                if (nvram["boardnum"] == "asusX") {
-                       c["lan_ifnames"]="eth0 eth1 eth2" # FIXME
-                       # wan_ifname=eth1
+                       c["lan_ifnames"]="eth0 eth1 wl0" # FIXME
+                       c["wan_ifname"]=""
                }
        }
        if (nvram["boardtype"] == "wgt634u") {
                c["vlan0ports"] = "0 1 2 3 5*"
                c["vlan1ports"] = "4 5"
-               c["lan_ifnames"] = "vlan0 ath0"
+               c["lan_ifnames"] = "eth0.0 ath0"
        }
        if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) {
                c["vlan0ports"] = "0 1 2 3 5*"
@@ -60,51 +53,28 @@ END {
        # WAP54G
        if ((nvram["boardnum"] == "2") || \
                (nvram["boardnum"] == "1024")) {
-               c["lan_ifnames"]="eth0 eth1"
+               c["lan_ifnames"]="eth0 wl0"
                c["wan_ifname"]=""
        }
 
        print "#### VLAN configuration "
-       print "vlan0hwname=et0"
-       print "vlan1hwname=et0"
-       p("vlan0ports")
-       p("vlan1ports")
+       print "config switch eth0"
+       p("vlan0", "vlan0ports")
+       p("vlan1", "vlan1ports")
        print ""
        print ""
-       
        print "#### LAN configuration"
-       print "lan_proto=\"static\""
-       p("lan_ifname")
-       p("lan_ifnames")
-       print "lan_ipaddr=\"192.168.1.1\""
-       print "lan_netmask=\"255.255.255.0\""
-       print "# lan_dns=\"192.168.1.1\""
-       print "# lan_gateway=\"192.168.1.1\""
-
+       print "config interface lan"
+       print " option type     bridge"
+       p("ifnames", "lan_ifnames")
+       print " option proto    static"
+       print " option ipaddr   192.168.1.1"
+       print " option netmask  255.255.255.0"
        print ""
        print ""
-
        print "#### WAN configuration"
-       print "# wan_proto: WAN protocol, available protocols:"
-       print "#   none: disable"
-       print "#   dhcp: DHCP"
-       print "#   static: Static IP"
-       print "#   pppoe: PPP over Ethernet"
-       print "#   pptp: Point-to-Point tunneling Protocol"
-       print "#     for pppoe and pptp you need to use wan_ifname=\"ppp0\""
-       print ""
-       print "wan_proto=dhcp"
-       p("wan_ifname")
-       print "wan_device=\"" c["wan_ifname"] "\""
-       print "# wan_ipaddr=\"192.168.0.2\""
-       print "# wan_netmask=\"255.255.255.0\""
-       print "# wan_gateway=\"192.168.0.1\""
-       print "# wan_dns=\"192.168.0.1\""
-       print ""
-       print "## PPP over Ethernet and PPTP"
-       print "# wan_ifname=\"ppp0\""
-       print "# ppp_username=\"my_username\""
-       print "# ppp_passwd=\"my_password\""
-       print "# pptp_server_ip=\"192.168.0.1\""
+       print "config interface wan"
+       p("ifname", "wan_ifname")
+       print " option proto    dhcp"
 }
 ' > /etc/config/network
diff --git a/openwrt/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net b/openwrt/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net
deleted file mode 100644 (file)
index 90a92bd..0000000
+++ /dev/null
@@ -1,35 +0,0 @@
-#!/bin/sh
-# Copyright (C) 2006 OpenWrt.org
-
-setup_eth()
-{
-       [ -d /proc/switch ] || {
-               insmod switch-core
-               insmod switch-robo || insmod switch-adm
-       }
-       if="$(echo "$INTERFACE" | sed s,eth,et,)"
-       ifconfig "$INTERFACE" up 2>&- >&-
-       [ -d "/proc/switch/$INTERFACE" ] || return 0
-       echo "1" > "/proc/switch/$INTERFACE/reset"
-       echo "1" > "/proc/switch/$INTERFACE/enable_vlan"
-       for vlan in $(seq 0 15); do
-               eval "hwname=\"\${vlan${vlan}hwname}\""
-               [ "$hwname" = "$if" ] && {
-                       eval "vports=\"\${vlan${vlan}ports}\""
-                       [ -n "$vports" ] && echo "$vports" > "/proc/switch/$INTERFACE/vlan/$vlan/ports"
-                       $DEBUG vconfig add "$INTERFACE" "$vlan"
-               }
-       done
-}
-
-do_register()
-{
-       case "${INTERFACE%%[0-9]*}" in
-               eth) setup_eth;;
-       esac
-}
-
-
-case "$ACTION" in
-       add|register) do_register;;
-esac
index 0f53c0c9c97535ce29a24d3adfe8402d8c1d9386..82e4ab9986ccc78ada21dd03cef8118454f5fb69 100755 (executable)
@@ -13,16 +13,16 @@ mkdir -p /etc/config
                strings /dev/mtdblock/3
        fi
 ) | awk '
-function p(name) {
-       if (c[name] != "") print name "=\"" c[name] "\""
+function p(cfgname, name) {
+       if (c[name] != "") print "      option " cfgname "      \"" c[name] "\""
 }
 
 BEGIN {
        FS="="
        c["lan_ifname"]="br0"
-       c["lan_ifnames"]="vlan0 eth1"
+       c["lan_ifnames"]="eth0.0 wl0"
        c["wan_proto"]="none"
-       c["wan_ifname"]="vlan1"
+       c["wan_ifname"]="eth0.1"
        c["vlan0ports"]="1 2 3 4 5*"
        c["vlan1ports"]="0 5"
 }
@@ -34,23 +34,16 @@ BEGIN {
 END {
        # v1 hardware
        if (nvram["boardtype"] == "bcm94710dev") {
-               # Linksys WRT54G v1.x
-               if (nvram["boardnum"] == "42") {
-                       c["vlan0ports"]=""
-                       c["vlan1ports"]=""
-                       c["lan_ifnames"]="vlan2 eth2"
-               }
-
                # Asus WL-500g
                if (nvram["boardnum"] == "asusX") {
-                       c["lan_ifnames"]="eth0 eth1 eth2" # FIXME
-                       # wan_ifname=eth1
+                       c["lan_ifnames"]="eth0 eth1 wl0" # FIXME
+                       c["wan_ifname"]=""
                }
        }
        if (nvram["boardtype"] == "wgt634u") {
                c["vlan0ports"] = "0 1 2 3 5*"
                c["vlan1ports"] = "4 5"
-               c["lan_ifnames"] = "vlan0 ath0"
+               c["lan_ifnames"] = "eth0.0 ath0"
        }
        if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) {
                c["vlan0ports"] = "0 1 2 3 5*"
@@ -60,51 +53,28 @@ END {
        # WAP54G
        if ((nvram["boardnum"] == "2") || \
                (nvram["boardnum"] == "1024")) {
-               c["lan_ifnames"]="eth0 eth1"
+               c["lan_ifnames"]="eth0 wl0"
                c["wan_ifname"]=""
        }
 
        print "#### VLAN configuration "
-       print "vlan0hwname=et0"
-       print "vlan1hwname=et0"
-       p("vlan0ports")
-       p("vlan1ports")
+       print "config switch eth0"
+       p("vlan0", "vlan0ports")
+       p("vlan1", "vlan1ports")
        print ""
        print ""
-       
        print "#### LAN configuration"
-       print "lan_proto=\"static\""
-       p("lan_ifname")
-       p("lan_ifnames")
-       print "lan_ipaddr=\"192.168.1.1\""
-       print "lan_netmask=\"255.255.255.0\""
-       print "# lan_dns=\"192.168.1.1\""
-       print "# lan_gateway=\"192.168.1.1\""
-
+       print "config interface lan"
+       print " option type     bridge"
+       p("ifnames", "lan_ifnames")
+       print " option proto    static"
+       print " option ipaddr   192.168.1.1"
+       print " option netmask  255.255.255.0"
        print ""
        print ""
-
        print "#### WAN configuration"
-       print "# wan_proto: WAN protocol, available protocols:"
-       print "#   none: disable"
-       print "#   dhcp: DHCP"
-       print "#   static: Static IP"
-       print "#   pppoe: PPP over Ethernet"
-       print "#   pptp: Point-to-Point tunneling Protocol"
-       print "#     for pppoe and pptp you need to use wan_ifname=\"ppp0\""
-       print ""
-       print "wan_proto=dhcp"
-       p("wan_ifname")
-       print "wan_device=\"" c["wan_ifname"] "\""
-       print "# wan_ipaddr=\"192.168.0.2\""
-       print "# wan_netmask=\"255.255.255.0\""
-       print "# wan_gateway=\"192.168.0.1\""
-       print "# wan_dns=\"192.168.0.1\""
-       print ""
-       print "## PPP over Ethernet and PPTP"
-       print "# wan_ifname=\"ppp0\""
-       print "# ppp_username=\"my_username\""
-       print "# ppp_passwd=\"my_password\""
-       print "# pptp_server_ip=\"192.168.0.1\""
+       print "config interface wan"
+       p("ifname", "wan_ifname")
+       print " option proto    dhcp"
 }
 ' > /etc/config/network
index f306ae342d79bca35e8c9ee341ab635bf07ac198..d5b7f6b0fadf2d5f5c0bdcee594cc8d1f0c2bc13 100644 (file)
-#!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
 
-find_name()
-{
-       for ifname in lan wan wifi ${ifnames}; do
-               IFTYPE="${ifname}"
-               eval "IFPROTO=\"\${${IFTYPE}_proto}\""
-               eval "IFACE=\"\${${IFTYPE}_ifname}\""
-               case "$IFPROTO" in
-                       ""|none);;
-                       static|dhcp)
-                               [ "${IFACE}" = "$INTERFACE" ] && return 0
-                               [ "${IFACE%%[0-9]*}" = "br" ] && {
-                                       eval "ifs=\"\${${IFTYPE}_ifnames}\""
-                                       for part in $ifs; do
-                                               [ "$part" = "$INTERFACE" ] && return 0
-                                       done
-                               }
-                       ;;
-                       pppoa)
-                               [ "$INTERFACE" = "atm0" \
-                                 -a -x /sbin/ifup.${IFPROTO} ] && return 0
-                       ;;
-                       *)
-                               eval "device=\"\${${IFTYPE}_device}\""
-                               [ "$device" = "$INTERFACE" \
-                                 -a -x /sbin/ifup.${IFPROTO} ] && return 0
-                       ;;
-               esac
-       done
-       IFACE=""
-       IFTYPE=""
-       IFPROTO=""
-       return 255
-}
-
-do_ifup() {
-       if="$3"
-       eval "if_proto=\"\${${2}_proto}\""
-       
-       pidfile=/var/run/${if}.pid
-       [ -f $pidfile ] && $DEBUG kill $(cat $pidfile)
-
-       case "$1" in
-               static)
-                       eval "ip=\"\${${2}_ipaddr}\""
-                       eval "ip6=\"\${${2}_ip6addr}\""
-                       eval "netmask=\"\${${2}_netmask}\""
-                       eval "gateway=\"\${${2}_gateway}\""
-                       eval "dns=\"\${${2}_dns}\""
-                       eval "static_route=\"\${${2}_static_route}\""
-       
-                       $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
-                       [ -n "$ip6" ] && $DEBUG ifconfig $if add $ip6
-
-                       [ -n "$static_route" ] && {
-                               for route in $static_route; do
-                                       if [ "$(echo $route | cut -d \/ -f2)" != "32" ];
-                                       then
-                                               route add -net $(echo $route | cut -d \/ -f1) netmask $(echo $route | cut -d \/ -f1) dev $if
-                                       else
-                                               route add -host $(echo $route | cut -d \/ -f1) dev $if
-                                       fi
-                               done
-                       }
+include network
 
-                       ${gateway:+$DEBUG route add default gw $gateway}
+addif() {
+       scan_interfaces
+       setup_interface "$INTERFACE"
        
-                       [ -f /tmp/resolv.conf ] || {
-                               debug "# --- creating /tmp/resolv.conf ---"
-                               for ns in $dns; do
-                                       echo "nameserver $ns" >> /tmp/resolv.conf
-                               done
-                       }
-                       
-                       env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" &
-               ;;
-               dhcp)
-                       eval "ip=\"\${${2}_ipaddr}\""
-                       eval "netmask=\"\${${2}_netmask}\""
-                       eval "hostname=\"\${${2}_hostname}\""
-                       
-                       $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up
-       
-                       args="-i $if ${ip:+-r $ip} -b -p $pidfile"
-                       hostname="${hostname%%.*}"
-                       args="$args${hostname:+ -H $hostname}"
-                       [ "$if_proto" = "pptp" ] && args="$args -n -q" || args="$args -R &"
-                       ${DEBUG:-eval} "udhcpc $args"
-                       # hotplug events are handled by /usr/share/udhcpc/default.script
-               ;;
-               *)
-                       if [ -x "/sbin/ifup.$1" ]; then
-                               ( $DEBUG . /sbin/ifup.$1 ${2} $3 )
-                       fi
-               ;;
-       esac
-}
-
-do_register()
-{
-       [ -z "$IFTYPE" -o -z "$IFPROTO" ] && {
-               find_name || {
-                       case "${INTERFACE%%[0-9]*}" in
-                               wds) 
-                                       for ifname in lan wifi; do
-                                               eval "if=\"\${${ifname}_ifname}\""
-                                               [ -z "$IFPROTO" ] && [ "$if" = "br0" ] && {
-                                                       eval "IFPROTO=\"\${${2}_proto}\""
-                                                       IFTYPE="${tmp}"
-                                               }
-                                       done
-                                       [ -z "$IFPROTO" ] && return 0
-                               ;;
-                               atm)
-                                       for tmp in lan wan wifi ${ifnames}; do
-                                               eval "if_proto=\"\${${2}_proto}\""
-                                               [ "$if_proto" = "pppoa" ] && {
-                                                       do_ifup "pppoa" "$tmp" "$INTERFACE"
-                                                       return 0
-                                               }
-                                       done
-                               ;;
-                               *)
-                                       return 0
-                               ;;
-                       esac
-               }
-       }
-
-       case "${INTERFACE%%[0-9]*}" in 
-               ppp|atm);;
-               *)
-                       eval "mac=\"\${${IFTYPE}_hwaddr}\""
-                       ${mac:+$DEBUG ifconfig $INTERFACE down hw ether $mac}
-               ;;
-       esac
-
-       eval "if=\"\${${IFTYPE}_ifname}\""
-       if [ "${if%%[0-9]}" = "br" ]; then
-               if_valid "$INTERFACE" && {
-                       ifconfig "$if" 2>&- >&- || {
-                               eval "stp=\"\${${IFTYPE}_stp}\""
-                               $DEBUG brctl addbr "$if"
-                               $DEBUG brctl setfd "$if" 0
-                               $DEBUG brctl stp "$if" "${stp:-0}"
+       # find all vlan configurations for this interface and set them up as well
+       for ifc in $interfaces; do
+               config_get type "$ifc" type
+               case "$type" in
+                       bridge) config_get ifs "$ifc" ifnames;;
+                       *) config_get ifs "$ifc" ifname;;
+               esac
+               for dev in $ifs; do
+                       [ "${dev%%\.*}" = "$INTERFACE" -a "$dev" != "$INTERFACE" ] && {
+                               add_vlan "$dev"
                        }
-
-                       if [ "$INTERFACE" != "$if" ]; then
-                               $DEBUG ifconfig "$INTERFACE" 0.0.0.0 up
-                               $DEBUG brctl addif "$if" "$INTERFACE"
-                               $DEBUG ifconfig "$INTERFACE" allmulti
-                       else
-                               do_ifup "$IFPROTO" "$IFTYPE" "$if"
-                       fi
-               }
-       else 
-               [ "${INTERFACE%%[0-9]*}" = "ppp" ] || do_ifup "$IFPROTO" "$IFTYPE" "$if"
-       fi
-}
-
-do_unregister() {
-       [ -z "$IFTYPE" -o -z "$IFPROTO" ] && {
-               find_name || return 0
-       }
-       
-       [ "${IFACE%%[0-9]*}" = "br" ] && {
-               if [ "$INTERFACE" != "$IFACE" ]; then
-                       brctl delif "$IFACE" "$INTERFACE" 2>&- >&-
-               else
-                       brctl delbr "$IFACE" 2>&- >&-
-               fi
-       }
-       
-       case "$IFPROTO" in
-               pppoe|pppoa|pptp) 
-                       killall pppd 2>&- >&-
-               ;;
-               dhcp)
-                       [ -f /var/run/${INTERFACE}.pid ] && kill "$(cat /var/run/${INTERFACE}.pid)" 2>&- >&-
-               ;;
-       esac
-
-       [ "${INTERFACE%%[0-9]*}" = "atm" ] || ifconfig "$INTERFACE" 0.0.0.0 down 2>&-
+               done
+       done
 }
 
 case "$ACTION" in
-       add|register) do_register;;
-       remove|unregister) do_unregister;;
+       add|register)
+               addif
+       ;;
 esac
index cb5c6ac4a7750c949aaa8f90941cdde8d290b83a..19420eda530e67be0e542cb19ce8ebb41568d380 100755 (executable)
@@ -5,13 +5,14 @@
 
 [ -f /proc/mounts ] || /sbin/mount_root
 [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
-vconfig set_name_type VLAN_PLUS_VID_NO_PAD
+vconfig set_name_type DEV_PLUS_VID_NO_PAD
 
 HOSTNAME=${wan_hostname%%.*}
 echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname
 
 mkdir -p /var/run
 mkdir -p /var/log
+mkdir -p /var/lock
 touch /var/log/wtmp
 touch /var/log/lastlog
 [ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe
diff --git a/openwrt/package/base-files/default/etc/init.d/S40network b/openwrt/package/base-files/default/etc/init.d/S40network
new file mode 100755 (executable)
index 0000000..20a1184
--- /dev/null
@@ -0,0 +1,9 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.orga
+
+setup_switch() { return 0; }
+
+. /etc/functions.sh
+include network
+setup_switch
+/sbin/wifi
index dad989fe09e1a9a0b42fda950902d533a22b9b0b..2aa70910c391af2749ed2859d2fb88472519f22b 100755 (executable)
@@ -3,12 +3,13 @@
 
 ${FAILSAFE:+exit}
 
-[ -f /etc/config/network ] && . /etc/config/network
-eval $(ipcalc "$log_ipaddr")
-[ "$log_ipaddr" = "$IP" ] || log_ipaddr=""
-syslogd -C 16 ${log_ipaddr:+-L -R $log_ipaddr}
+# FIXME: add logging configuration
+#[ -f /etc/config/network ] && . /etc/config/network
+#eval $(ipcalc "$log_ipaddr")
+#[ "$log_ipaddr" = "$IP" ] || log_ipaddr=""
+syslogd -C 16 #${log_ipaddr:+-L -R $log_ipaddr}
 klogd
-#${FAILSAFE:+telnetd -l /bin/login; ifup lan; exit}
+
 for i in /etc/init.d/S*; do
   $i start 2>&1
 done | logger -s -p 6 -t '' &
diff --git a/openwrt/package/base-files/default/lib/network/config.sh b/openwrt/package/base-files/default/lib/network/config.sh
new file mode 100755 (executable)
index 0000000..59ec84a
--- /dev/null
@@ -0,0 +1,147 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+# DEBUG="echo"
+
+find_config() {
+       local type iface ifn
+       for ifn in $interfaces; do
+               config_get type "$ifn" type
+               config_get iface "$ifn" ifname
+               case "$type" in
+                       bridge)
+                               config_get iface "$ifn" ifnames
+                       ;;
+               esac
+               for ifc in $iface; do
+                       [ "$ifc" = "$1" ] && {
+                               echo "$ifn"
+                               return 0
+                       }
+               done
+       done
+
+       return 1;
+}
+
+scan_interfaces() {
+       local mode type iface
+       interfaces=
+       config_cb() {
+               config_get type "$CONFIG_SECTION" TYPE
+               case "$type" in
+                       interface)
+                               config_get type "$CONFIG_SECTION" type
+                               config_get mode "$CONFIG_SECTION" proto
+                               case "$type" in
+                                       bridge)
+                                               config_get iface "$CONFIG_SECTION" ifname
+                                               iface="${iface:-br-$CONFIG_SECTION}"
+                                               config_set "$CONFIG_SECTION" ifname "$iface"
+                                       ;;
+                               esac
+                               append interfaces "$CONFIG_SECTION"
+                               ( type "scan_$mode" ) >/dev/null 2>/dev/null && eval "scan_$mode '$CONFIG_SECTION'"
+                       ;;
+               esac
+       }
+       config_load network
+}
+
+add_vlan() {
+       local vif="${1%\.*}"
+       
+       [ "$1" = "$vif" ] || ifconfig "$1" >/dev/null 2>/dev/null || {
+               ifconfig "$vif" up 2>/dev/null >/dev/null || add_vlan "$vif"
+               $DEBUG vconfig add "$vif" "${1##*\.}"
+       }
+}
+
+setup_interface() {
+       local iface="$1"
+       local config="$2"
+       local proto="$3"
+
+       [ -n "$config" ] || {
+               config=$(find_config "$iface")
+               [ "$?" = 0 ] || return 1
+       }
+
+       [ -n "$proto" ] || {
+               config_get proto "$config" proto
+       }
+
+       config_get iftype "$config" type
+       
+       # Setup VLAN interfaces
+       add_vlan "$iface"
+
+       # Setup bridging
+       case "$iftype" in
+               bridge)
+                       config_get bridge_ifname "$config" ifname
+                       ifconfig "$iface" up 2>/dev/null >/dev/null
+                       ifconfig "$bridge_ifname" 2>/dev/null >/dev/null && {
+                               $DEBUG brctl addif "$bridge_ifname" "$iface"
+                               return 0
+                       } || {
+                               $DEBUG brctl addbr "$bridge_ifname"
+                               $DEBUG brctl setfd "$bridge_ifname" 0
+                               $DEBUG brctl addif "$bridge_ifname" "$iface"
+                               iface="$bridge_ifname"
+                       }
+               ;;
+       esac
+       
+       # Interface settings
+       config_get mtu "$config" mtu
+       $DEBUG ifconfig "$iface" ${mtu:+mtu $mtu} up
+
+       pidfile="/var/run/$iface.pid"
+       case "$proto" in
+               static)
+                       config_get ipaddr "$config" ipaddr
+                       config_get netmask "$config" netmask
+                       [ -z "$ipaddr" -o -z "$netmask" ] && return 1
+                       
+                       config_get ip6addr "$config" ip6addr
+                       config_get gateway "$config" gateway
+                       config_get dns "$config" dns
+                       
+                       $DEBUG ifconfig "$iface" "$ipaddr" netmask "$netmask"
+                       [ -z "$gateway" ] || route add default gw "$gateway"
+                       [ -z "$dns" -o -f /tmp/resolv.conf ] || {
+                               for ns in $dns; do
+                                       echo "nameserver $ns" >> /tmp/resolv.conf
+                               done
+                       }
+
+                       env -i ACTION="ifup" INTERFACE="config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" &
+               ;;
+               dhcp)
+                       pid="$(cat "$pidfile" 2>/dev/null)"
+                       [ -n "$pid" -a -d "/proc/$pid" ] && kill -9 "$pid"
+
+                       config_get ipaddr "$config" ipaddr
+                       config_get netmask "$config" netmask
+                       config_get hostname "$config" hostname
+                       config_get proto1 "$config" proto
+
+                       [ -z "$ipaddr" ] || \
+                               $DEBUG ifconfig "$iface" "$ipaddr" ${netmask:+netmask "$netmask"}
+
+                       # don't stay running in background if dhcp is not the main proto on the interface (e.g. when using pptp)
+                       [ "$proto1" != "$proto" ] && dhcpopts="-n -q"
+                       $DEBUG udhcpc -i "$iface" ${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} -b -p "$pidfile" ${dhcpopts:- -R &}
+               ;;
+               *)
+                       if ( eval "type setup_interface_$proto" ) >/dev/null 2>/dev/null; then
+                               eval "setup_interface_$proto '$iface' '$config' '$proto'" 
+                       else
+                               echo "Interface type $proto not supported."
+                               return 1
+                       fi
+               ;;
+       esac
+}
+
index afe52a446f9cf3b9ef8a2a92adfe25a49378417c..b1b6f97b234820107f24a6e1a8dbcd64d398362b 100755 (executable)
@@ -13,7 +13,6 @@
 }
 
 . /etc/functions.sh
-. /etc/config/network
 
 PATH=/bin:/sbin:/usr/bin:/usr/sbin
 LOGNAME=root
index 50ffee53040bb5e76cb23f822c1e89a106bbf481..7debb9559fdb5fbdad1f7ba4ba2b27018d646855 100755 (executable)
@@ -3,18 +3,32 @@
 
 [ $# = 0 ] && { echo "  $0 <group>"; exit; }
 . /etc/functions.sh
-. /etc/config/network
+include network
+scan_interfaces
 
 debug "### ifdown $type ###"
 type=$1
 
-eval "if_proto=\"\${${type}_proto}\""
-eval "if=\"\${${type}_ifname}\""
-[ "${if%%[0-9]}" = "ppp" ] && eval "if=\"\${${type}_device}\""
+config_get proto "$type" proto
+[ -z "$proto" ] && { echo "interface not found."; exit; }
 
-case "$if_proto" in
-       pppoa) hotplug_dev unregister atm0; exit 0 ;;
-       ""|none) exit 0;;
-esac
+# kill active ppp daemon
+pid="$(cat /var/run/ppp-${type}.pid 2>/dev/null)"
+[ -n "$pid" -a -d "/proc/$pid" ] && {
+       kill $pid
+       sleep 1
+       [ -d "/proc/$pid" ] && kill -9 $pid
+}
 
-hotplug_dev unregister "$if"
+# kill any other process associated with the interface
+config_get ifname "$type" ifname
+pid="$(cat /var/run/${ifname}.pid 2>/dev/null)"
+[ -n "$pid" -a -d "/proc/$pid" ] && kill -9 $pid
+
+config_get ifname "$type" ifname
+ifconfig "$ifname" >/dev/null 2>/dev/null && {
+       ifconfig "$ifname" 0.0.0.0 down
+
+       config_get iftype "$type" type
+       [ "$iftype" = "bridge" ] && brctl delbr "$ifname"
+}
index 390f96039502382887fc73453e4af5f4b5728f5d..c40de38ad8f13a947f29b4f0a2b258db5feccd71 100755 (executable)
@@ -1,38 +1,18 @@
 #!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
 
-[ $# = 0 ] && { echo "  $0 <group>"; exit; }
-. /etc/functions.sh
-. /etc/config/network
+. /sbin/ifdown "$@"
 
-ifdown $1
-
-debug "### ifup $type ###"
-type=$1
-
-eval "if_proto=\"\${${type}_proto}\""
-eval "if=\"\${${type}_ifname}\""
-[ "${if%%[0-9]}" = "ppp" ] && eval "if=\"\${${type}_device}\""
-
-case "$if_proto" in
-       pppoa) hotplug_dev register atm0; exit 0 ;;
-       pppoe)
-               # PPPoE over ATM
-               [ "$if" = "nas0" ] && {
-                       ifconfig nas0 2>&- >&- || {
-                               hotplug_dev register atm0
-                               exit 0
-                       }
-               }
+config_get iftype "$1" type
+case "$iftype" in
+       bridge)
+               config_get ifname "$1" ifnames
+       ;;
+       *)
+               config_get ifname "$1" ifname
        ;;
-       none|"") exit 0;;
 esac
 
-if [ "${if%%[0-9]}" = "br" ]; then
-       eval "ifnames=\"\${${type}_ifnames}\""
-       for sif in $ifnames; do
-               hotplug_dev register "$sif"
-       done
-else
-       hotplug_dev register "$if"
-fi
+for dev in $ifname; do
+       setup_interface "$dev" "$1"
+done
index 63b2f121bda4547b3fd1aa724b9db9e5b1df329c..f1ac94fa3a02469dceb9af6eaa3461b33c35d1bc 100755 (executable)
@@ -30,12 +30,7 @@ config_cb() {
 }
 
 config_load wireless
-
-[ -d /lib/wifi -a -n "$(ls /lib/wifi/*.sh 2>&-)" ] && {
-       for script in /lib/wifi/*.sh; do
-               . $script
-       done
-}
+include wifi
 
 for device in $DEVICES; do (
        config_get type "$device" type
index 4604648e6b082b487b446e767625e60ab08d2fa2..a244e05a157da9a45e6abbc89f4ee5f3d8e47fc6 100755 (executable)
@@ -1,15 +1,19 @@
 #!/bin/sh
 [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
-. /etc/config/network
+. /etc/functions.sh
+include network
 
 RESOLV_CONF="/tmp/resolv.conf"
 
 hotplug_event() {
-       for ifname in lan wan wifi ${ifnames}; do
-               eval "proto=\"\${${ifname}_proto}\""
-               eval "if=\"\${${ifname}_ifname}\""
+       scan_interfaces
+       for ifc in $interfaces; do
+               config_get ifname $ifc ifname
+               [ "$ifname" = "$interface" ] || continue
+
+               config_get proto $ifc proto
                [ "$proto" = "dhcp" ] || continue
-               [ "$if" = "$interface" ] || continue
+
                env -i ACTION="$1" INTERFACE="$ifname" PROTO=dhcp /sbin/hotplug iface
        done
 }
index 2bb48b886391bddee1befab5eb8a1a3e19ad9f08..6f089fe992628e6f068d6aa37a2c5272b807696a 100644 (file)
@@ -1,6 +1,6 @@
-# Network configuration file
 # Copyright (C) 2006 OpenWrt.org
 
-## LAN configuration
-lan_ifname="eth0"
-lan_proto="dhcp"
+config interface lan
+       option ifname   eth0
+       option proto    dhcp
+
index 576677bf7c44aa375217a88cf351713c192f73c4..95d7575c92f8d6248f0cca2b819b2b5b44c3ffaa 100644 (file)
@@ -1,13 +1,8 @@
-# Network configuration file
 # Copyright (C) 2006 OpenWrt.org
 
-## LAN configuration
-lan_ifname="br0"
-lan_ifnames="eth0 ath0"
-lan_proto="static"
-lan_ipaddr="192.168.1.1"
-lan_netmask="255.255.255.0"
-
-## WAN configuration
-wan_ifname=""
-wan_proto="none"
+config interface lan
+       option type     bridge
+       option ifnames  "eth0 ath0"
+       option proto    static
+       option ipaddr   192.168.1.1
+       option netmask  255.255.255.0
index 7bcfd0870a06a16e1aab4f09a9e045f5409c6477..9f521c05bf484df04575435ccffa6eb4d4fdc6f9 100644 (file)
@@ -1,13 +1,13 @@
-# Network configuration file
 # Copyright (C) 2006 OpenWrt.org
 
-## LAN configuration
-lan_ifname="br0"
-lan_ifnames="eth1 eth2"
-lan_proto="static"
-lan_ipaddr="192.168.1.1"
-lan_netmask="255.255.255.0"
+config interface lan
+       option type     bridge
+       option ifnames  "eth1 eth2"
+       option proto    static
+       option ipaddr   192.168.1.1
+       option netmask  255.255.255.0
+
+config interface wan
+       option ifname   eth0
+       option proto    dhcp
 
-## WAN configuration
-wan_ifname="eth0"
-wan_proto="dhcp"
index 7bcfd0870a06a16e1aab4f09a9e045f5409c6477..9f521c05bf484df04575435ccffa6eb4d4fdc6f9 100644 (file)
@@ -1,13 +1,13 @@
-# Network configuration file
 # Copyright (C) 2006 OpenWrt.org
 
-## LAN configuration
-lan_ifname="br0"
-lan_ifnames="eth1 eth2"
-lan_proto="static"
-lan_ipaddr="192.168.1.1"
-lan_netmask="255.255.255.0"
+config interface lan
+       option type     bridge
+       option ifnames  "eth1 eth2"
+       option proto    static
+       option ipaddr   192.168.1.1
+       option netmask  255.255.255.0
+
+config interface wan
+       option ifname   eth0
+       option proto    dhcp
 
-## WAN configuration
-wan_ifname="eth0"
-wan_proto="dhcp"
index 2bb48b886391bddee1befab5eb8a1a3e19ad9f08..aadd4aa8ed033a8ea679af8682955cd41457fff9 100644 (file)
@@ -1,6 +1,5 @@
 # Network configuration file
-# Copyright (C) 2006 OpenWrt.org
 
-## LAN configuration
-lan_ifname="eth0"
-lan_proto="dhcp"
+config interface lan
+       option ifname   eth0
+       option proto    dhcp
index 6cac60c0b76ed0f34ccb00662c62daf7f4194fce..53d1cf7925348f2676b8b97e86c06ee56b5f95c0 100644 (file)
@@ -1,3 +1,15 @@
+bridge_interface() {
+       (
+               . /etc/functions.sh
+               include network
+               scan_interfaces
+               cfg="$(find_config "$1")"
+               [ -z "$cfg" ] && return 0
+               config_get type "$cfg" type
+               [ "$type" = bridge ] && config_get "$type" bridge
+       )
+}
+
 scan_broadcom() {
        local device="$1"
 
@@ -127,7 +139,7 @@ setup_broadcom() {
                config_get ifname "$vif" ifname
                append if_up "ifconfig $ifname up" ";$N"
                [ -z "$nasopts" ] || {
-                       config_get bridge "$vif" bridge # XXX: integrate with /etc/config/network later
+                       bridge="$(bridge_interface "$ifname")"
                        eval "${vif}_ssid=\"\$ssid\""
                        mode="-A"
                        [ "$vif" = "$sta_if" ] && mode="-S"
index 17ef43c3d5f1c1884786f2c6271b5005a58fd808..140f727f4683ff2789a23bac71ed595885e7785a 100644 (file)
@@ -1,5 +1,7 @@
 #!/bin/sh
-. /etc/config/network
+. /etc/functions.sh
+include network
+scan_interfaces
 
 # The following is to automatically configure the DHCP settings
 # based on config settings. Feel free to replace all this crap
@@ -10,7 +12,7 @@
 
 args=""
 iface=lan
-eval "ifname=\${${iface}_ifname}"
+config_get ifname "$iface" ifname
 
 dhcp_enable="${dhcp_enable:-1}"
 dhcp_start="${dhcp_start:-100}"
@@ -26,8 +28,8 @@ dhcp_lease="${dhcp_lease:-12h}"
                # no existing DHCP server?
 
                # calculate settings
-               eval "ipaddr=\${${iface}_ipaddr}"
-               eval "netmask=\${${iface}_netmask}"
+               config_get ipaddr "$iface" ipaddr
+               config_get netmask "$iface" netmask
                eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150})
                
                # and pass the args via config parser defines
@@ -39,6 +41,8 @@ dhcp_lease="${dhcp_lease:-12h}"
        }
 
        # ignore requests from wan interface
+       config_get wan_proto wan proto
+       config_get wan_ifname wan ifname
        [ -z "$wan_proto" -o "$wan_proto" = "none" ] || echo "@define wan_ifname $wan_ifname"
 
        cat /etc/dnsmasq.conf
index 53783300453b5aa48028a8198738294ee4683a41..902c7b188842cf7826893f6db539fab9d36f1870 100644 (file)
@@ -1,10 +1,7 @@
 # Copyright (C) 2006 OpenWrt.org
 
 BEGIN {
-       print ". /etc/config/network"
-       print "proto=\"$wan_proto\""
-       print "[ -z \"$proto\" -o \"$proto\" = \"none\" ] && exit"
-       print "ifname=\"$wan_ifname\""
+       print "ifname=\"$WAN\""
        print "[ -z \"$ifname\" ] && exit"
        print ""
        print "iptables -X input_$ifname 2>&- >&-"
index e174d84bb2326334de032be30f17c814fc792b68..a0bd99ef9a9de84a21debebc5268b2661fab6a12 100755 (executable)
@@ -3,9 +3,12 @@
 
 ## Please make changes in /etc/firewall.user
 
-. /etc/config/network
-WAN="$wan_ifname"
-LAN="$lan_ifname"
+. /etc/functions.sh
+include network
+
+scan_interfaces
+config_get WAN wan ifname
+config_get LAN lan ifname
 
 ## CLEAR TABLES
 for T in filter nat; do
@@ -35,7 +38,7 @@ iptables -t nat -N postrouting_rule
   iptables -A INPUT -j input_rule
 
   # allow
-  [ -z "$WAN" ] || iptables -A INPUT -i \! $WAN        -j ACCEPT       # allow from lan/wifi interfaces 
+  iptables -A INPUT ${WAN:+-i \! $WAN} -j ACCEPT       # allow from lan/wifi interfaces 
   iptables -A INPUT -p icmp    -j ACCEPT       # allow ICMP
   iptables -A INPUT -p gre     -j ACCEPT       # allow GRE
 
old mode 100755 (executable)
new mode 100644 (file)
index 1fb862e..5f295ba
@@ -1,11 +1,6 @@
 #!/bin/sh
 # Copyright (C) 2006 OpenWrt.org
 
-. /etc/config/network
-
-WAN="$wan_ifname"
-LAN="$lan_ifname"
-
 iptables -F input_rule
 iptables -F output_rule
 iptables -F forwarding_rule
index 85d52d0542435512fee1711e9869cf4df4920cdf..e49b610c36b49e878e2d3323b3c98c47c879d890 100644 (file)
@@ -95,6 +95,8 @@ define Build/Compile
 endef
 
 define Package/ppp/install
+       install -d -m0755 $(1)/lib/network
+       install -m0755 ./files/ppp.sh $(1)/lib/network/
        install -d -m0755 $(1)/etc/ppp
        install -m0600 ./files/etc/ppp/chap-secrets $(1)/etc/ppp/
        install -m0644 ./files/etc/ppp/filter $(1)/etc/ppp/
@@ -110,19 +112,19 @@ define Package/ppp/install
 endef
        
 define Package/ppp-mod-pppoa/install
+       install -d -m0755 $(1)/lib/network
+       install -m0755 ./files/pppoa.sh $(1)/lib/network/
        install -d -m0755 $(1)/usr/lib/pppd/$(PKG_VERSION)
        install -m0755 $(PKG_INSTALL_DIR)/usr/lib/pppd/$(PKG_VERSION)/pppoatm.so \
                $(1)/usr/lib/pppd/$(PKG_VERSION)/
-       install -d -m0755 $(1)/sbin
-       install -m0755 ./files/ifup.pppoa $(1)/sbin/
 endef
 
 define Package/ppp-mod-pppoe/install
+       install -d -m0755 $(1)/lib/network
+       install -m0755 ./files/pppoe.sh $(1)/lib/network/
        install -d -m0755 $(1)/usr/lib/pppd/$(PKG_VERSION)
        install -m0755 $(PKG_INSTALL_DIR)/usr/lib/pppd/$(PKG_VERSION)/rp-pppoe.so \
                $(1)/usr/lib/pppd/$(PKG_VERSION)/
-       install -d -m0755 $(1)/sbin
-       install -m0755 ./files/ifup.pppoe $(1)/sbin/
 endef
 
 define Package/ppp-mod-radius/install
diff --git a/openwrt/package/ppp/files/ifup.pppoa b/openwrt/package/ppp/files/ifup.pppoa
deleted file mode 100644 (file)
index f78a162..0000000
+++ /dev/null
@@ -1,38 +0,0 @@
-#!/bin/sh
-[ $# = 0 ] && { echo "  $0 <group>"; exit; }
-. /etc/config/network
-type=$1
-
-eval "proto=\"\${${type}_proto}\""
-[ "$proto" = "pppoa" ] || {
-       echo "$0: ${type}_proto isn't pppoa"
-       exit
-}
-
-mkdir -p /var/lock
-
-for module in slhc ppp_generic pppoatm; do
-       /sbin/insmod $module 2>&- >&-
-done
-
-KEEPALIVE=${ppp_redialperiod:+lcp-echo-interval $ppp_redialperiod lcp-echo-failure 5}
-case "$ppp_demand" in
-       on|1|enabled)
-               DEMAND=${ppp_idletime:+demand idle $ppp_idletime}
-               [ -f /etc/ppp/filter ] && DEMAND=${DEMAND:+precompiled-active-filter /etc/ppp/filter $DEMAND}
-       ;;
-       *) DEMAND="persist";;
-esac
-MTU=${ppp_mtu:-1500}
-
-/usr/sbin/pppd \
-       plugin pppoatm.so ${atm_vpi:-8}.${atm_vci:-35} \
-       usepeerdns \
-       defaultroute \
-       linkname $type \
-       ipparam $type \
-       user "$ppp_username" \
-       password "$ppp_passwd" \
-       mtu $MTU mru $MTU \
-       $DEMAND \
-       $KEEPALIVE
diff --git a/openwrt/package/ppp/files/ifup.pppoe b/openwrt/package/ppp/files/ifup.pppoe
deleted file mode 100644 (file)
index c7019fc..0000000
+++ /dev/null
@@ -1,43 +0,0 @@
-#!/bin/sh
-[ $# = 0 ] && { echo "  $0 <group>"; exit; }
-. /etc/config/network
-type=$1
-
-eval "proto=\"\${${type}_proto}\""
-[ "$proto" = "pppoe" ] || {
-       echo "$0: ${type}_proto isn't pppoe"
-       exit
-}
-
-mkdir -p /var/lock
-
-for module in slhc ppp_generic pppox pppoe; do
-       /sbin/insmod $module 2>&- >&-
-done
-
-eval "IFNAME=\"\${${type}_device}\""
-KEEPALIVE=${ppp_redialperiod:+lcp-echo-interval $ppp_redialperiod lcp-echo-failure 5}
-case "$ppp_demand" in
-       on|1|enabled)
-               DEMAND=${ppp_idletime:+demand idle $ppp_idletime}
-               [ -f /etc/ppp/filter ] && DEMAND=${DEMAND:+precompiled-active-filter /etc/ppp/filter $DEMAND}
-       ;;
-       *) DEMAND="persist";;
-esac
-MTU=${ppp_mtu:-1492}
-
-ifconfig $IFNAME up
-/usr/sbin/pppd \
-       plugin rp-pppoe.so \
-       connect /bin/true \
-       usepeerdns \
-       defaultroute \
-       linkname $type \
-       ipparam $type \
-       user "$ppp_username" \
-       password "$ppp_passwd" \
-       mtu $MTU mru $MTU \
-       $DEMAND \
-       $KEEPALIVE \
-       nic-$IFNAME
-
diff --git a/openwrt/package/ppp/files/ppp.sh b/openwrt/package/ppp/files/ppp.sh
new file mode 100644 (file)
index 0000000..0bb77b8
--- /dev/null
@@ -0,0 +1,27 @@
+scan_ppp() {
+       config_get ifname "$1" ifname
+       pppdev="${pppdev:-0}"
+       config_set "$1" device "$ifname"
+       config_set "$1" ifname "ppp$pppdev"
+       config_set "$1" unit "$pppdev"
+}
+
+start_pppd() {
+       local cfg="$1"; shift
+       config_get device "$cfg" device
+       config_get unit "$cfg" unit
+       config_get username "$cfg" username
+       config_get password "$cfg" password
+       config_get keepalive "$cfg" keepalive
+       config_get demand "$cfg" demand
+       [ -n "$demand" ] && echo "nameserver 1.1.1.1" > /tmp/resolv.conf
+       /usr/sbin/pppd "$@" \
+               ${keepalive:+lcp-echo-interval 5 lcp-echo-failure $keepalive} \
+               ${demand:+precompiled-active-filter /etc/ppp/filter demand idle }${demand:-persist} \
+               usepeerdns \
+               defaultroute \
+               replacedefaultroute \
+               ${username:+username "$username" password "$password"} \
+               linkname "$cfg" \
+               ipparam "$cfg"
+}
diff --git a/openwrt/package/ppp/files/pppoa.sh b/openwrt/package/ppp/files/pppoa.sh
new file mode 100644 (file)
index 0000000..e6530b0
--- /dev/null
@@ -0,0 +1,20 @@
+scan_pppoa() {
+       scan_ppp "$@"
+}
+
+setup_interface_pppoa() {
+       local iface="$1"
+       local config="$2"
+       
+       config_get device "$config" device
+
+       for module in slhc ppp_generic pppoatm; do
+               /sbin/insmod $module 2>&- >&-
+       done
+
+       config_get mtu "$cfg" mtu
+       mtu=${mtu:-1492}
+       start_pppd "$config" \
+               plugin pppoatm.so ${atm_vpi:-8}.${atm_vci:-35} \
+               mtu $mtu mru $mtu
+}
diff --git a/openwrt/package/ppp/files/pppoe.sh b/openwrt/package/ppp/files/pppoe.sh
new file mode 100644 (file)
index 0000000..f263caa
--- /dev/null
@@ -0,0 +1,21 @@
+scan_pppoe() {
+       scan_ppp "$@"
+}
+
+setup_interface_pppoe() {
+       local iface="$1"
+       local config="$2"
+       
+       config_get device "$config" device
+
+       for module in slhc ppp_generic pppox pppoe; do
+               /sbin/insmod $module 2>&- >&-
+       done
+
+       config_get mtu "$cfg" mtu
+       mtu=${mtu:-1480}
+       start_pppd "$config" \
+               plugin rp-pppoe.so \
+               mtu $mtu mru $mtu \
+               "nic-$device"
+}
diff --git a/openwrt/package/ppp/files/pptp.sh b/openwrt/package/ppp/files/pptp.sh
new file mode 100644 (file)
index 0000000..7b33ac1
--- /dev/null
@@ -0,0 +1,3 @@
+scan_pptp() {
+       scan_ppp "$@"
+}
index 061e55395ebd143b332387ac05334d545468349a..b060c12a793b90ef46cf4b9c84f61cdb2928d4bb 100644 (file)
@@ -31,8 +31,8 @@ endef
 define Package/pptp/install
        install -d -m0755 $(1)/etc/ppp
        install -m0644 ./files/options.pptp $(1)/etc/ppp/
-       install -d -m0755 $(1)/sbin
-       install -m0755 ./files/ifup.pptp $(1)/sbin/
+       install -d -m0755 $(1)/lib/network
+       install -m0755 ./files/pptp.sh $(1)/lib/network/
        install -d -m0755 $(1)/usr/sbin
        install -m0755 $(PKG_BUILD_DIR)/pptp $(1)/usr/sbin/
 endef
diff --git a/openwrt/package/pptp/files/ifup.pptp b/openwrt/package/pptp/files/ifup.pptp
deleted file mode 100644 (file)
index f401a36..0000000
+++ /dev/null
@@ -1,45 +0,0 @@
-#!/bin/sh
-[ $# = 0 ] && { echo "  $0 <group>"; exit; }
-. /etc/config/network
-type=$1
-
-eval "proto=\"\${${type}_proto}\""
-[ "$proto" = "pptp" ] || {
-       echo "$0: ${type}_proto isn't pptp"
-       exit
-}
-
-mkdir -p /var/lock
-
-for module in slhc ppp_generic ppp_async ip_gre; do
-       /sbin/insmod $module 2>&- >&-
-done
-
-KEEPALIVE=${ppp_redialperiod:+lcp-echo-interval $ppp_redialperiod lcp-echo-failure 5}
-case "$ppp_demand" in
-       on|1|enabled)
-               DEMAND=${ppp_idletime:+demand idle $ppp_idletime}
-               [ -f /etc/ppp/filter ] && DEMAND=${DEMAND:+precompiled-active-filter /etc/ppp/filter $DEMAND}
-       ;;
-       *) DEMAND="persist";;
-esac
-MTU=${ppp_mtu:-1452}
-
-[ "$pptp_proto" = "static" ] || pptp_proto="dhcp"
-do_ifup $pptp_proto $type
-
-/usr/sbin/pppd \
-       pty "/usr/sbin/pptp $pptp_server_ip --loglevel 0 --nolaunchpppd" \
-       file /etc/ppp/options.pptp \
-       connect /bin/true \
-       usepeerdns \
-       defaultroute \
-       replacedefaultroute \
-       linkname "$type" \
-       ipparam "$type" \
-       user "$ppp_username" \
-       password "$ppp_passwd" \
-       mtu $MTU mru $MTU \
-       $DEMAND \
-       $KEEPALIVE
-
diff --git a/openwrt/package/pptp/files/pptp.sh b/openwrt/package/pptp/files/pptp.sh
new file mode 100644 (file)
index 0000000..7847802
--- /dev/null
@@ -0,0 +1,22 @@
+scan_pppoe() {
+       scan_ppp "$@"
+}
+
+setup_interface_pppoe() {
+       local iface="$1"
+       local config="$2"
+       
+       config_get device "$config" device
+
+       for module in slhc ppp_generic ppp_async ip_gre; do
+               /sbin/insmod $module 2>&- >&-
+       done
+       setup_interface "$iface" "$config" "dhcp"
+
+       config_get mtu "$cfg" mtu
+       mtu=${mtu:-1452}
+       start_pppd "$config" \
+               plugin rp-pppoe.so \
+               mtu $mtu mru $mtu \
+               "nic-$device"
+}
index 5513394fd6ace2b877488fbd9dae923f58968fa8..860e530c4c972c14cc27ba3d4a6f93d4cf4ad7d0 100644 (file)
@@ -42,6 +42,10 @@ define Build/Compile
 endef
        
 define Package/kmod-switch/install
+       install -m0755 -d $(1)/lib/network/
+       install -m0755 ./files/switch.sh $(1)/lib/network/
+       install -m0755 -d $(1)/etc/modules.d/
+       printf 'switch-core\nswitch-robo\nswitch-adm\n' > $(1)/etc/modules.d/20-switch
        install -m0755 -d $(1)/lib/modules/$(LINUX_VERSION)
        $(CP) $(PKG_BUILD_DIR)/*.$(LINUX_KMOD_SUFFIX) \
                $(1)/lib/modules/$(LINUX_VERSION)
diff --git a/openwrt/package/switch/files/switch.sh b/openwrt/package/switch/files/switch.sh
new file mode 100644 (file)
index 0000000..a787a8c
--- /dev/null
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+setup_switch_vlan() {
+       DIR="/proc/switch/$CONFIG_SECTION/vlan/$1"
+       [ -d "$DIR" ] || return 0
+       
+       config_get ports "$CONFIG_SECTION" "vlan$1"
+       echo "$ports" > "$DIR/ports"
+}
+
+setup_switch() {
+       config_cb() {
+               case "$1" in
+                       switch)
+                               [ -n "$2" -a -d "/proc/switch/$2" ] && {
+                                       echo 1 > "/proc/switch/$2/reset"
+                                       echo 1 > "/proc/switch/$2/enable"
+                                       echo 1 > "/proc/switch/$2/enable_vlan"
+                                       option_cb() {
+                                               case "$1" in
+                                                       vlan*) setup_switch_vlan "${1##vlan}";;
+                                               esac
+                                       }
+                               }
+                       ;;
+                       *)
+                               option_cb() { return 0; }
+                       ;;
+               esac
+       }
+       config_load network
+}