From 7619fe0848dc5f31d5c4c4cadd2ec067bd5c55d1 Mon Sep 17 00:00:00 2001 From: nbd Date: Sun, 17 Jul 2005 22:52:59 +0000 Subject: move target/default/target_skeleton into package/base-files, put all the default files in ipkg packages, cleanup some junk in toolchain/, toolchain/ no longer changes build_mipsel/root git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1494 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/sbin/ifup | 59 ++++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) create mode 100755 package/base-files/default/sbin/ifup (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup new file mode 100755 index 0000000000..3d81364d08 --- /dev/null +++ b/package/base-files/default/sbin/ifup @@ -0,0 +1,59 @@ +#!/bin/ash +[ $# = 0 ] && { echo " $0 "; exit; } +. /etc/functions.sh +type=$1 +debug "### ifup $type ###" + +if_proto=$(nvram get ${type}_proto) +if=$(nvram get ${type}_ifname) +[ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) + +if_valid $if || exit +mac=$(nvram get ${type}_hwaddr) +$DEBUG ifconfig $if down 2>&- + +if [ "${if%%[0-9]}" = "br" ]; then + stp=$(nvram get ${type}_stp) + $DEBUG brctl delbr $if 2>&- + $DEBUG brctl addbr $if + $DEBUG brctl setfd $if 0 + $DEBUG brctl stp $if ${stp:-0} + + for sif in $(nvram get ${type}_ifnames); do + if_valid $sif || continue + ${mac:+$DEBUG ifconfig $sif down hw ether $mac} + $DEBUG ifconfig $sif 0.0.0.0 up + $DEBUG brctl addif $if $sif + done +else + ${mac:+$DEBUG ifconfig $if down hw ether $mac} +fi + +case "$if_proto" in + static) + ip=$(nvram get ${type}_ipaddr) + netmask=$(nvram get ${type}_netmask) + gateway=$(nvram get ${type}_gateway) + + $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up + ${gateway:+$DEBUG route add default gw $gateway} + + [ -f /etc/resolv.conf ] && return + + debug "# --- creating /etc/resolv.conf ---" + for dns in $(nvram get ${type}_dns); do + echo "nameserver $dns" >> /etc/resolv.conf + done + ;; + dhcp) + ip=$(nvram get ${type}_ipaddr) + [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) + ${DEBUG:-eval} "udhcpc -R -i $if ${ip:+-r $ip} -b -p $pidfile &" + ;; + none|"") + ;; + *) + [ -x "/sbin/ifup.${if_proto}" ] && { $DEBUG /sbin/ifup.${if_proto} $*; exit; } + echo "### ifup $type: ignored ${type}_proto=\"$if_proto\" (not supported)" + ;; +esac -- cgit v1.2.3 From a44985f42c551baae99a2c6f461c94ec86d9e310 Mon Sep 17 00:00:00 2001 From: mbm Date: Wed, 20 Jul 2005 19:58:40 +0000 Subject: updates from whiterussian git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1504 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/etc/firewall.user | 2 +- package/base-files/default/etc/init.d/S10boot | 5 +++-- package/base-files/default/etc/init.d/S45firewall | 1 + package/base-files/default/etc/init.d/rcS | 7 ++++--- package/base-files/default/etc/preinit | 11 ++++++----- package/base-files/default/sbin/ifup | 4 +++- package/base-files/default/sbin/mount_root | 14 ++++++++------ 7 files changed, 26 insertions(+), 18 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/firewall.user b/package/base-files/default/etc/firewall.user index 1781bd4ea0..7a13141623 100755 --- a/package/base-files/default/etc/firewall.user +++ b/package/base-files/default/etc/firewall.user @@ -14,7 +14,7 @@ iptables -t nat -F postrouting_rule ### The "-i $WAN" literally means packets that came in over the $WAN interface; ### this WILL NOT MATCH packets sent from the LAN to the WAN address. -### Allow SSH from WAN +### Allow SSH on the WAN interface # iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j ACCEPT # iptables -A input_rule -i $WAN -p tcp --dport 22 -j ACCEPT diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index 22096d5fbb..ead73521b1 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -16,7 +16,8 @@ touch /var/log/lastlog # if they don't already exist [ "$(nvram get boardtype)" = "bcm95365r" \ -a "$(nvram get boardnum)" = "45" \ --a -z "$(nvram get vlan0ports)$(nvram get vlan1ports)" ] && { +-a -z "$(nvram get vlan0ports)" +-a -z "$(nvram get vlan1ports)" ] && { nvram set vlan0ports="1 2 3 4 5*" nvram set vlan1ports="0 5" } @@ -33,6 +34,6 @@ echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname vconfig set_name_type VLAN_PLUS_VID_NO_PAD # automagically run firstboot -[ -z "$FAILSAFE" ] && { +[ -z "$FAILSAFE" -a -z "$(nvram get no_root_swap)" ] && { { mount|grep "on / type jffs2" 1>&-; } || firstboot } diff --git a/package/base-files/default/etc/init.d/S45firewall b/package/base-files/default/etc/init.d/S45firewall index 8350ccbfef..cb779792d5 100755 --- a/package/base-files/default/etc/init.d/S45firewall +++ b/package/base-files/default/etc/init.d/S45firewall @@ -1,6 +1,7 @@ #!/bin/sh ## Please make changes in /etc/firewall.user +${FAILSAFE:+exit} . /etc/functions.sh WAN=$(nvram get wan_ifname) diff --git a/package/base-files/default/etc/init.d/rcS b/package/base-files/default/etc/init.d/rcS index e6daddc593..706585801c 100755 --- a/package/base-files/default/etc/init.d/rcS +++ b/package/base-files/default/etc/init.d/rcS @@ -1,8 +1,9 @@ #!/bin/sh -syslogd -C 16 +syslog_ip=$(nvram get log_ipaddr) +ipcalc -s "$syslog_ip" || syslog_ip="" +syslogd -C 16 ${syslog_ip:+-L -R $syslog_ip} klogd -${FAILSAFE:+telnetd -l /bin/login; ifup lan; exit} - +#${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/package/base-files/default/etc/preinit b/package/base-files/default/etc/preinit index 0c59893f75..b23f8833ef 100755 --- a/package/base-files/default/etc/preinit +++ b/package/base-files/default/etc/preinit @@ -1,17 +1,18 @@ #!/bin/sh +export PATH=/bin:/sbin:/usr/bin:/usr/sbin mount none /proc -t proc insmod diag echo 0x01 > /proc/sys/diag sleep 1 -if [ $(cat /proc/sys/reset) = 1 ] || [ "$(/usr/sbin/nvram get failsafe)" = 1 ]; then +if [ $(cat /proc/sys/reset) = 1 -o "$(nvram get failsafe)" = 1 ]; then export FAILSAFE=true - [ "$(/usr/sbin/nvram get boot_wait)" != "on" ] && { - /usr/sbin/nvram set boot_wait=on - /usr/sbin/nvram commit + [ "$(nvram get boot_wait)" != "on" ] && { + nvram set boot_wait=on + nvram commit } while :; do { echo $(((X=(X+1)%8)%2)) > /proc/sys/diag; sleep $((X==0)); } done & fi -/sbin/mount_root ${FAILSAFE:+failsafe} +mount_root ${FAILSAFE:+failsafe} exec /sbin/init diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 3d81364d08..5dac3f9987 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -12,6 +12,9 @@ if_valid $if || exit mac=$(nvram get ${type}_hwaddr) $DEBUG ifconfig $if down 2>&- +pidfile=/var/run/${if}.pid +[ -f $pidfile ] && $DEBUG kill $(cat $pidfile) + if [ "${if%%[0-9]}" = "br" ]; then stp=$(nvram get ${type}_stp) $DEBUG brctl delbr $if 2>&- @@ -47,7 +50,6 @@ case "$if_proto" in ;; dhcp) ip=$(nvram get ${type}_ipaddr) - [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) ${DEBUG:-eval} "udhcpc -R -i $if ${ip:+-r $ip} -b -p $pidfile &" ;; none|"") diff --git a/package/base-files/default/sbin/mount_root b/package/base-files/default/sbin/mount_root index b4ec2ca563..29c5126ba1 100755 --- a/package/base-files/default/sbin/mount_root +++ b/package/base-files/default/sbin/mount_root @@ -12,12 +12,14 @@ if [ "$1" != "failsafe" ]; then mount -o remount,rw /dev/root / fi else - mtd unlock OpenWrt - mount -t jffs2 /dev/mtdblock/4 /jffs - pivot_root /jffs /jffs/rom - mount none /proc -t proc - mount none /dev -t devfs - umount /rom/proc rom/dev >&- + if [ -z "$(nvram get no_root_swap)" ]; then + mtd unlock OpenWrt + mount -t jffs2 /dev/mtdblock/4 /jffs + pivot_root /jffs /jffs/rom + mount none /proc -t proc + mount none /dev -t devfs + umount /rom/proc rom/dev >&- + fi fi fi mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50% -- cgit v1.2.3 From f80d4fdc68858ba956a39e19ad6efa868beb827e Mon Sep 17 00:00:00 2001 From: nbd Date: Thu, 21 Jul 2005 14:02:53 +0000 Subject: add config file /etc/config/network, add board-specific network.overrides (instead of nvram.overrides) git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1519 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/bin/firstboot | 2 +- package/base-files/default/etc/config/network | 9 ++ package/base-files/default/etc/functions.sh | 16 ++-- package/base-files/default/etc/init.d/S10boot | 30 ++++--- package/base-files/default/etc/init.d/S40network | 1 + package/base-files/default/etc/init.d/S45firewall | 2 + package/base-files/default/etc/init.d/S50dnsmasq | 2 + package/base-files/default/etc/nvram.overrides | 96 -------------------- package/base-files/default/sbin/ifdown | 2 + package/base-files/default/sbin/ifup | 3 + package/ppp/files/ifup.pppoe | 2 + package/pptp/files/ifup.pptp | 2 + scripts/configtest.pl | 9 +- target/linux/package/Makefile | 3 +- target/linux/package/openwrt/Makefile | 23 +++-- .../package/openwrt/files/network.overrides.ar7 | 26 ++++++ .../package/openwrt/files/network.overrides.brcm | 100 +++++++++++++++++++++ .../package/openwrt/ipkg/base-files-arch.control | 6 ++ .../package/openwrt/ipkg/openwrt-utils.control | 9 -- 19 files changed, 206 insertions(+), 137 deletions(-) create mode 100644 package/base-files/default/etc/config/network delete mode 100644 package/base-files/default/etc/nvram.overrides create mode 100644 target/linux/package/openwrt/files/network.overrides.ar7 create mode 100644 target/linux/package/openwrt/files/network.overrides.brcm create mode 100644 target/linux/package/openwrt/ipkg/base-files-arch.control delete mode 100644 target/linux/package/openwrt/ipkg/openwrt-utils.control (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/bin/firstboot b/package/base-files/default/bin/firstboot index cef258cf39..1c3d1a7d66 100755 --- a/package/base-files/default/bin/firstboot +++ b/package/base-files/default/bin/firstboot @@ -42,7 +42,7 @@ echo "done" echo -n "setting up symlinks... " for file in $(cd /rom; find * -type f; find * -type l;) do { - [ "${file%/*}" = "usr/lib/ipkg/info" ] && { + [ "${file%/*}" = "usr/lib/ipkg/info" -o "${file%/*}" = "etc/config" ] && { cp -f /rom/$file $file } || { ln -sf /rom/$file $file diff --git a/package/base-files/default/etc/config/network b/package/base-files/default/etc/config/network new file mode 100644 index 0000000000..049460160a --- /dev/null +++ b/package/base-files/default/etc/config/network @@ -0,0 +1,9 @@ +# Network configuration file + +# Uncomment the following statements to override the default or nvram config +# lan_ifame="br0" +# lan_proto="static" +# lan_ipaddr="192.168.1.1" +# lan_netmask="255.255.255.0" +# lan_gateway="" +# lan_dns="" diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh index 60d6231f8a..14f5011db7 100755 --- a/package/base-files/default/etc/functions.sh +++ b/package/base-files/default/etc/functions.sh @@ -4,12 +4,18 @@ alias debug=${DEBUG:-:} # allow env to override nvram nvram () { - case $1 in - get) eval "echo \${NVRAM_$2:-\$(command nvram get $2)}";; - *) command nvram $*;; - esac + if [ -x /usr/sbin/nvram ]; then + case $1 in + get) eval "echo \${$2:-\$(command nvram get $2)}";; + *) command nvram $*;; + esac + else + case $1 in + get) eval "echo \${$2:-\${DEFAULT_$2}}";; + *);; + esac + fi } -. /etc/nvram.overrides # valid interface? if_valid () ( diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index ead73521b1..d45f8e809b 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -6,20 +6,22 @@ mkdir -p /var/log touch /var/log/wtmp touch /var/log/lastlog -[ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && { - # if default wifi mac, set two higher than the lan mac - nvram set il0macaddr=$(nvram get et0macaddr| - awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}') -} - -# set up the vlan*ports variables for the asus wl-500g deluxe -# if they don't already exist -[ "$(nvram get boardtype)" = "bcm95365r" \ --a "$(nvram get boardnum)" = "45" \ --a -z "$(nvram get vlan0ports)" --a -z "$(nvram get vlan1ports)" ] && { - nvram set vlan0ports="1 2 3 4 5*" - nvram set vlan1ports="0 5" +[ -x /usr/sbin/nvram ] && { + [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && { + # if default wifi mac, set two higher than the lan mac + nvram set il0macaddr=$(nvram get et0macaddr| + awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}') + } + + # set up the vlan*ports variables for the asus wl-500g deluxe + # if they don't already exist + [ "$(nvram get boardtype)" = "bcm95365r" \ + -a "$(nvram get boardnum)" = "45" \ + -a -z "$(nvram get vlan0ports)" + -a -z "$(nvram get vlan1ports)" ] && { + nvram set vlan0ports="1 2 3 4 5*" + nvram set vlan1ports="0 5" + } } sed 's/^[^#]/insmod &/' /etc/modules /etc/modules.d/* 2>&-|ash diff --git a/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network index d8b4e4125e..a5afe5266f 100755 --- a/package/base-files/default/etc/init.d/S40network +++ b/package/base-files/default/etc/init.d/S40network @@ -1,4 +1,5 @@ #!/bin/sh +[ -e /etc/config/network] && . /etc/config/network case "$1" in start|restart) ifup lan diff --git a/package/base-files/default/etc/init.d/S45firewall b/package/base-files/default/etc/init.d/S45firewall index cb779792d5..188b9aaa8a 100755 --- a/package/base-files/default/etc/init.d/S45firewall +++ b/package/base-files/default/etc/init.d/S45firewall @@ -4,6 +4,8 @@ ${FAILSAFE:+exit} . /etc/functions.sh +. /etc/network.overrides +[ -e /etc/config/network] && . /etc/config/network WAN=$(nvram get wan_ifname) LAN=$(nvram get lan_ifname) diff --git a/package/base-files/default/etc/init.d/S50dnsmasq b/package/base-files/default/etc/init.d/S50dnsmasq index 6a5af0f05f..31d0a36976 100755 --- a/package/base-files/default/etc/init.d/S50dnsmasq +++ b/package/base-files/default/etc/init.d/S50dnsmasq @@ -1,5 +1,7 @@ #!/bin/sh . /etc/functions.sh +. /etc/network.overrides +[ -e /etc/config/network] && . /etc/config/network # interface to use for DHCP iface=lan diff --git a/package/base-files/default/etc/nvram.overrides b/package/base-files/default/etc/nvram.overrides deleted file mode 100644 index d457af48ee..0000000000 --- a/package/base-files/default/etc/nvram.overrides +++ /dev/null @@ -1,96 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -# linksys bug; remove when not using static configuration for lan -NVRAM_lan_proto="static" - -remap () { - for type in lan wifi wan pppoe - do - for s in '' s - do - eval NVRAM_${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\" - done - done -} - -# hacks for wrt54g 1.x hardware -[ "$(nvram get boardnum)" = "42" \ --a "$(nvram get boardtype)" = "bcm94710dev" ] && { - debug "### wrt54g 1.x hack ###" - NVRAM_vlan1hwname="et0" - NVRAM_vlan2hwname="et0" - FAILSAFE_ifnames="vlan1 vlan2 eth2" - remap eth0 vlan2 - remap eth1 vlan1 -} - -# hacks for asus wl-500g deluxe -[ "$(nvram get boardtype)" = "bcm95365r" \ --a "$(nvram get boardnum)" = "45" ] && { - debug "### wl-500g deluxe hacks ###" - NVRAM_vlan0hwname="et0" - NVRAM_vlan1hwname="et0" - FAILSAFE_ifnames="vlan0 eth1" - remap eth0.1 vlan0 - remap eth0 vlan1 -} - -# hacks for asus wl-300g -[ "$(nvram get productid)" = "WL300g" ] && { - debug "### wl-300g hacks ###" - NVRAM_lan_ifnames="eth0 eth2" - NVRAM_wan_ifname="none" -} - -# hacks for wap54g hardware -[ "$(nvram get boardnum)" = "2" \ --o "$(nvram get boardnum)" = "1024" ] && { - debug "### wap54g hack ###" - NVRAM_wan_ifname="none" - FAILSAFE_ifnames="eth0 eth1" -} - -# hacks for buffalo wla2-g54l -[ "$(nvram get boardnum)" = "00" \ --a "$(nvram get product_name)" = "Product_name" \ --o "$(nvram get product_name)" = "WLA2-G54L" ] && { - debug "### wla2-g54l hacks ###" - NVRAM_wan_ifname="none" - NVRAM_lan_ifnames="vlan0" -} - -# hack for asus wl-500g hardware -[ "$(nvram get boardnum)" = "asusX" \ --a "$(nvram get boardtype)" = "bcm94710dev" ] && { - FAILSAFE_ifnames="eth0 eth2" -} - -# defaults if lan_ifname is missing -[ -z "$(nvram get lan_ifname)" ] && { - NVRAM_lan_ifname="br0" - NVRAM_lan_ifnames=${FAILSAFE_ifnames:-"vlan0 vlan2 eth1 eth2 eth3"} -} - -# defaults if wan_ifname is missing -[ -z "$(nvram get wan_ifname)" ] && { - NVRAM_wan_ifname="vlan1" - NVRAM_wan_proto="dhcp" -} - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - NVRAM_lan_ifname="br0" - NVRAM_lan_ifnames=${FAILSAFE_ifnames:-"vlan0 vlan1 eth1 eth2 eth3"} - NVRAM_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} - NVRAM_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} - NVRAM_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} - NVRAM_wan_ifname="none" - NVRAM_wifi_ifname="none" -} diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 6b255cc1b8..950ee12db5 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -1,6 +1,8 @@ #!/bin/ash [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh +. /etc/network.overrides +[ -e /etc/config/network ] && . /etc/config/network type=$1 debug "### ifdown $type ###" if=$(nvram get ${type}_ifname) diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 5dac3f9987..6aa998713c 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -1,6 +1,9 @@ #!/bin/ash [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh +. /etc/network.overrides +[ -e /etc/config/network ] && . /etc/config/network + type=$1 debug "### ifup $type ###" diff --git a/package/ppp/files/ifup.pppoe b/package/ppp/files/ifup.pppoe index 6bac6a6d15..94179a3eaa 100644 --- a/package/ppp/files/ifup.pppoe +++ b/package/ppp/files/ifup.pppoe @@ -1,6 +1,8 @@ #!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh +. /etc/nvram.overrides +[ -e /etc/config/network ] && . /etc/config/network type=$1 [ "$(nvram get ${type}_proto)" = "pppoe" ] || { diff --git a/package/pptp/files/ifup.pptp b/package/pptp/files/ifup.pptp index 21a574acb7..8335440777 100644 --- a/package/pptp/files/ifup.pptp +++ b/package/pptp/files/ifup.pptp @@ -1,5 +1,7 @@ #!/bin/sh . /etc/functions.sh +. /etc/nvram.overrides +[ -e /etc/config/network ] && . /etc/config/network type=$1 [ "$(nvram get ${type}_proto)" = "pptp" ] || exit diff --git a/scripts/configtest.pl b/scripts/configtest.pl index 3ca33d86c5..709d2be74b 100755 --- a/scripts/configtest.pl +++ b/scripts/configtest.pl @@ -1,13 +1,14 @@ #!/usr/bin/perl my %change = ( - 'BUSYBOX' => 'make -C package busybox-clean', - 'OPENVPN_' => 'make -C package openvpn-clean', + 'BUSYBOX' => 'make package/busybox-clean', + 'OPENVPN_' => 'make package/openvpn-clean', + 'SYSCONF_' => 'make package/base-files-clean target_clean', '' => 'make target_clean' ); my @configfiles = ( - ['package/linux/linux.config', 'build_mipsel/linux/.config' => - 'make -C package linux-clean'] +# ['package/linux/linux.config', 'build_mipsel/linux/.config' => +# 'make -C package linux-clean'] ); diff --git a/target/linux/package/Makefile b/target/linux/package/Makefile index adce4d4eed..a08d9048ab 100644 --- a/target/linux/package/Makefile +++ b/target/linux/package/Makefile @@ -5,9 +5,10 @@ package-$(BR2_PACKAGE_KMOD_FUSE) += fuse package-$(BR2_PACKAGE_KMOD_MINI_FO) += mini_fo package-$(BR2_PACKAGE_KMOD_SHFS) += shfs package-$(BR2_PACKAGE_KMOD_OPENSWAN) += openswan +package-y += openwrt ifeq ($(BOARD),brcm) -package-y += nvram openwrt +package-y += nvram ifeq ($(LINUX_VERSION),2.4.30) package-$(BR2_PACKAGE_KMOD_WLCOMPAT) += wlcompat diff --git a/target/linux/package/openwrt/Makefile b/target/linux/package/openwrt/Makefile index ee38f75a15..5d2ea199ec 100644 --- a/target/linux/package/openwrt/Makefile +++ b/target/linux/package/openwrt/Makefile @@ -2,29 +2,38 @@ include $(TOPDIR)/rules.mk -PKG_NAME := openwrt-utils -PKG_RELEASE := 2 +PKG_NAME := base-files-arch +PKG_RELEASE := 1 PKG_BUILD_DIR := $(BUILD_DIR)/$(PKG_NAME) include $(TOPDIR)/package/rules.mk BR2_PACKAGE_OPENWRT:=y # ignore menuconfig -$(eval $(call PKG_template,OPENWRT,openwrt-utils,$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH))) - +$(eval $(call PKG_template,OPENWRT,$(PKG_NAME),$(PKG_VERSION)-$(PKG_RELEASE),$(ARCH))) $(PKG_BUILD_DIR)/.prepared: mkdir -p $(PKG_BUILD_DIR) touch $@ - + +ifeq ($(BOARD),brcm) $(PKG_BUILD_DIR)/jffs2root: jffs2root.c $(TARGET_CC) -o $@ $< $(PKG_BUILD_DIR)/.built: $(PKG_BUILD_DIR)/jffs2root - touch $@ -$(IPKG_OPENWRT): +$(IDIR_OPENWRT)/sbin/jffs2root: mkdir -p $(IDIR_OPENWRT)/sbin cp $(PKG_BUILD_DIR)/jffs2root $(IDIR_OPENWRT)/sbin + +$(IPKG_OPENWRT): $(IDIR_OPENWRT)/sbin/jffs2root +endif + +$(PKG_BUILD_DIR)/.built: + touch $@ + +$(IPKG_OPENWRT): + mkdir -p $(IDIR_OPENWRT)/etc + cp files/network.overrides.$(BOARD) $(IDIR_OPENWRT)/etc/network.overrides $(RSTRIP) $(IDIR_OPENWRT) $(IPKG_BUILD) $(IDIR_OPENWRT) $(PACKAGE_DIR) diff --git a/target/linux/package/openwrt/files/network.overrides.ar7 b/target/linux/package/openwrt/files/network.overrides.ar7 new file mode 100644 index 0000000000..dc58a7e591 --- /dev/null +++ b/target/linux/package/openwrt/files/network.overrides.ar7 @@ -0,0 +1,26 @@ +# NVRAM overrides +# +# This file handles the NVRAM quirks of various hardware. +# THIS FILE IS NOT A REPLACEMENT FOR NVRAM + +# Load sysconf defaults +[ -f /etc/sysconf ] && . /etc/sysconf + +DEFAULT_lan_proto="static" +DEFAULT_lan_ifname="eth0" +DEFAULT_lan_ifnames="eth0" +DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} +DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} +DEFAULT_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} + +# failsafe if reset is held +[ "$FAILSAFE" = "true" ] && { + echo "### YOU ARE IN FAILSAFE MODE ####" + lan_ifname=${DEFAULT_lan_proto} + lan_ifnames=${FAILSAFE_ifnames:-${DEFAULT_lan_ifnames}} + lan_ipaddr=$DEFAULT_lan_ipaddr + lan_netmask=$DEFAULT_lan_netmask + lan_hwaddr=$DEFAULT_lan_hwaddr + wan_ifname="none" + wifi_ifname="none" +} diff --git a/target/linux/package/openwrt/files/network.overrides.brcm b/target/linux/package/openwrt/files/network.overrides.brcm new file mode 100644 index 0000000000..9766108a96 --- /dev/null +++ b/target/linux/package/openwrt/files/network.overrides.brcm @@ -0,0 +1,100 @@ +# NVRAM overrides +# +# This file handles the NVRAM quirks of various hardware. +# THIS FILE IS NOT A REPLACEMENT FOR NVRAM + +# Load sysconf defaults +[ -f /etc/sysconf ] && . /etc/sysconf + +# linksys bug; remove when not using static configuration for lan +lan_proto="static" + +remap () { + for type in lan wifi wan pppoe + do + for s in '' s + do + eval ${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\" + done + done +} + +# hacks for wrt54g 1.x hardware +[ "$(nvram get boardnum)" = "42" \ +-a "$(nvram get boardtype)" = "bcm94710dev" ] && { + debug "### wrt54g 1.x hack ###" + vlan1hwname="et0" + vlan2hwname="et0" + FAILSAFE_ifnames="vlan1 vlan2 eth2" + remap eth0 vlan2 + remap eth1 vlan1 +} + +# hacks for asus wl-500g deluxe +[ "$(nvram get boardtype)" = "bcm95365r" \ +-a "$(nvram get boardnum)" = "45" ] && { + debug "### wl-500g deluxe hacks ###" + vlan0hwname="et0" + vlan1hwname="et0" + FAILSAFE_ifnames="vlan0 eth1" + remap eth0.1 vlan0 + remap eth0 vlan1 +} + +# hacks for asus wl-300g +[ "$(nvram get productid)" = "WL300g" ] && { + debug "### wl-300g hacks ###" + lan_ifnames="eth0 eth2" + wan_ifname="none" +} + +# hacks for wap54g hardware +[ "$(nvram get boardnum)" = "2" \ +-o "$(nvram get boardnum)" = "1024" ] && { + debug "### wap54g hack ###" + wan_ifname="none" + FAILSAFE_ifnames="eth0 eth1" +} + +# hacks for buffalo wla2-g54l +[ "$(nvram get boardnum)" = "00" \ +-a "$(nvram get product_name)" = "Product_name" \ +-o "$(nvram get product_name)" = "WLA2-G54L" ] && { + debug "### wla2-g54l hacks ###" + wan_ifname="none" + lan_ifnames="vlan0" +} + +# hack for asus wl-500g hardware +[ "$(nvram get boardnum)" = "asusX" \ +-a "$(nvram get boardtype)" = "bcm94710dev" ] && { + FAILSAFE_ifnames="eth0 eth2" +} + +# defaults if lan_ifname is missing +[ -z "$(nvram get lan_ifname)" ] && { + lan_ifname="br0" + lan_ifnames=${FAILSAFE_ifnames:-"vlan0 vlan2 eth1 eth2 eth3"} +} + +# defaults if wan_ifname is missing +[ -z "$(nvram get wan_ifname)" ] && { + wan_ifname="vlan1" + wan_proto="dhcp" +} + +DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} +DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} +DEFAULT_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} + +# failsafe if reset is held +[ "$FAILSAFE" = "true" ] && { + echo "### YOU ARE IN FAILSAFE MODE ####" + lan_ifname="br0" + lan_ifnames=${FAILSAFE_ifnames:-"vlan0 vlan1 eth1 eth2 eth3"} + lan_ipaddr=$DEFAULT_lan_ipaddr + lan_netmask=$DEFAULT_lan_netmask + lan_hwaddr=$DEFAULT_lan_hwaddr + wan_ifname="none" + wifi_ifname="none" +} diff --git a/target/linux/package/openwrt/ipkg/base-files-arch.control b/target/linux/package/openwrt/ipkg/base-files-arch.control new file mode 100644 index 0000000000..5396f6817a --- /dev/null +++ b/target/linux/package/openwrt/ipkg/base-files-arch.control @@ -0,0 +1,6 @@ +Package: base-files-arch +Priority: optional +Section: sys +Maintainer: Felix Fietkau +Source: buildroot internal +Description: Board/architecture specific files diff --git a/target/linux/package/openwrt/ipkg/openwrt-utils.control b/target/linux/package/openwrt/ipkg/openwrt-utils.control deleted file mode 100644 index 37ef63276b..0000000000 --- a/target/linux/package/openwrt/ipkg/openwrt-utils.control +++ /dev/null @@ -1,9 +0,0 @@ -Package: openwrt-utils -Priority: optional -Section: sys -Maintainer: Felix Fietkau -Source: buildroot internal -Description: Basic OpenWrt utilities - This package contains: - mtd: Tool for modifying the flash chip - jffs2root: Expands the jffs2 root partition -- cgit v1.2.3 From 84e5ae23cefdd6c8c713483fe13fdcdba045de4e Mon Sep 17 00:00:00 2001 From: nbd Date: Thu, 25 Aug 2005 11:57:56 +0000 Subject: don't load config files in failsafe mode git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1750 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/etc/init.d/S40network | 2 +- package/base-files/default/etc/init.d/S45firewall | 2 +- package/base-files/default/etc/init.d/S50dnsmasq | 2 +- package/base-files/default/sbin/ifdown | 2 +- package/base-files/default/sbin/ifup | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network index c4226d3437..df7c6b3515 100755 --- a/package/base-files/default/etc/init.d/S40network +++ b/package/base-files/default/etc/init.d/S40network @@ -1,6 +1,6 @@ #!/bin/sh . /etc/functions.sh -[ -e /etc/config/network ] && . /etc/config/network +[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network case "$1" in start|restart) ifup lan diff --git a/package/base-files/default/etc/init.d/S45firewall b/package/base-files/default/etc/init.d/S45firewall index c9986011ad..066bded5bf 100755 --- a/package/base-files/default/etc/init.d/S45firewall +++ b/package/base-files/default/etc/init.d/S45firewall @@ -5,7 +5,7 @@ ${FAILSAFE:+exit} . /etc/functions.sh . /etc/network.overrides -[ -e /etc/config/network ] && . /etc/config/network +[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network WAN=$(nvram get wan_ifname) LAN=$(nvram get lan_ifname) diff --git a/package/base-files/default/etc/init.d/S50dnsmasq b/package/base-files/default/etc/init.d/S50dnsmasq index 31d0a36976..cce957573c 100755 --- a/package/base-files/default/etc/init.d/S50dnsmasq +++ b/package/base-files/default/etc/init.d/S50dnsmasq @@ -1,7 +1,7 @@ #!/bin/sh . /etc/functions.sh . /etc/network.overrides -[ -e /etc/config/network] && . /etc/config/network +[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network # interface to use for DHCP iface=lan diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 950ee12db5..2d4054d8b3 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -2,7 +2,7 @@ [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh . /etc/network.overrides -[ -e /etc/config/network ] && . /etc/config/network +[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network type=$1 debug "### ifdown $type ###" if=$(nvram get ${type}_ifname) diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 6aa998713c..c46fff65c3 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -2,7 +2,7 @@ [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh . /etc/network.overrides -[ -e /etc/config/network ] && . /etc/config/network +[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network type=$1 debug "### ifup $type ###" -- cgit v1.2.3 From d7a58579b4f59c73a3844c20649d6d7483402e58 Mon Sep 17 00:00:00 2001 From: nbd Date: Tue, 30 Aug 2005 22:24:30 +0000 Subject: fix ifup for pppoa git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@1803 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/sbin/ifup | 46 +++++++++++++++++++----------------- 1 file changed, 24 insertions(+), 22 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index c46fff65c3..1f78061a2a 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -8,32 +8,34 @@ type=$1 debug "### ifup $type ###" if_proto=$(nvram get ${type}_proto) -if=$(nvram get ${type}_ifname) -[ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) +[ "${if_proto}" = "pppoa" ] || { + if=$(nvram get ${type}_ifname) + [ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) -if_valid $if || exit -mac=$(nvram get ${type}_hwaddr) -$DEBUG ifconfig $if down 2>&- + if_valid $if || exit + mac=$(nvram get ${type}_hwaddr) + $DEBUG ifconfig $if down 2>&- -pidfile=/var/run/${if}.pid -[ -f $pidfile ] && $DEBUG kill $(cat $pidfile) + pidfile=/var/run/${if}.pid + [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) -if [ "${if%%[0-9]}" = "br" ]; then - stp=$(nvram get ${type}_stp) - $DEBUG brctl delbr $if 2>&- - $DEBUG brctl addbr $if - $DEBUG brctl setfd $if 0 - $DEBUG brctl stp $if ${stp:-0} + if [ "${if%%[0-9]}" = "br" ]; then + stp=$(nvram get ${type}_stp) + $DEBUG brctl delbr $if 2>&- + $DEBUG brctl addbr $if + $DEBUG brctl setfd $if 0 + $DEBUG brctl stp $if ${stp:-0} - for sif in $(nvram get ${type}_ifnames); do - if_valid $sif || continue - ${mac:+$DEBUG ifconfig $sif down hw ether $mac} - $DEBUG ifconfig $sif 0.0.0.0 up - $DEBUG brctl addif $if $sif - done -else - ${mac:+$DEBUG ifconfig $if down hw ether $mac} -fi + for sif in $(nvram get ${type}_ifnames); do + if_valid $sif || continue + ${mac:+$DEBUG ifconfig $sif down hw ether $mac} + $DEBUG ifconfig $sif 0.0.0.0 up + $DEBUG brctl addif $if $sif + done + else + ${mac:+$DEBUG ifconfig $if down hw ether $mac} + fi +} case "$if_proto" in static) -- cgit v1.2.3 From 15713b2da9a57d19a4b04af0dd77362c92979966 Mon Sep 17 00:00:00 2001 From: nbd Date: Sat, 22 Oct 2005 20:47:19 +0000 Subject: sync base-files with whiterussian git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@2260 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/etc/functions.sh | 50 ++++++++++++++++ package/base-files/default/etc/init.d/S10boot | 20 +------ package/base-files/default/etc/profile | 1 + package/base-files/default/sbin/ifdown | 6 +- package/base-files/default/sbin/ifup | 82 +++++++++------------------ 5 files changed, 82 insertions(+), 77 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh index c813e39a61..bc9767f491 100755 --- a/package/base-files/default/etc/functions.sh +++ b/package/base-files/default/etc/functions.sh @@ -24,6 +24,56 @@ if_valid () ( { debug "# missing interface '$1' ignored"; false; } ) +do_ifup() { + if_proto=$(nvram get ${2}_proto) + if=$(nvram get ${2}_ifname) + [ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) + + pidfile=/var/run/${if}.pid + [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) + + case "$1" in + static) + ip=$(nvram get ${2}_ipaddr) + netmask=$(nvram get ${2}_netmask) + gateway=$(nvram get ${2}_gateway) + + $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up + ${gateway:+$DEBUG route add default gw $gateway} + + [ -f /etc/resolv.conf ] && return + + debug "# --- creating /etc/resolv.conf ---" + for dns in $(nvram get ${2}_dns); do + echo "nameserver $dns" >> /etc/resolv.conf + done + ;; + dhcp) + DHCP_IP=$(nvram get ${2}_ipaddr) + DHCP_NETMASK=$(nvram get ${2}_netmask) + $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up + + DHCP_ARGS="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile" + DHCP_HOSTNAME=$(nvram get ${2}_hostname) + DHCP_HOSTNAME=${DHCP_HOSTNAME%%.*} + [ -z $DHCP_HOSTNAME ] || DHCP_ARGS="$DHCP_ARGS -H $DHCP_HOSTNAME" + [ "$if_proto" = "pptp" ] && DHCP_ARGS="$DHCP_ARGS -n -q" || DHCP_ARGS="$DHCP_ARGS -R &" + oldpid=$(cat $pidfile) + ${DEBUG:-eval} "udhcpc $DHCP_ARGS" + pidof udhcpc | grep "$oldpid" >&- 2>&- && { + sleep 1 + kill -9 $oldpid + } + ;; + none|"") + ;; + *) + [ -x "/sbin/ifup.$1" ] && { $DEBUG /sbin/ifup.$1 ${2}; exit; } + echo "### ifup ${2}: ignored ${2}_proto=\"$1\" (not supported)" + ;; + esac +} + bitcount () { local c=$1 echo $(( diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index 66fece1d73..b0dc04eb7e 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -10,30 +10,12 @@ mkdir -p /var/log touch /var/log/wtmp touch /var/log/lastlog -[ -x /usr/sbin/nvram ] && { - [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && { - # if default wifi mac, set two higher than the lan mac - nvram set il0macaddr=$(nvram get et0macaddr| - awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}') - } - - # set up the vlan*ports variables for the asus wl-500g deluxe - # if they don't already exist - [ "$(nvram get boardtype)" = "bcm95365r" \ - -a "$(nvram get boardnum)" = "45" \ - -a -z "$(nvram get vlan0ports)" \ - -a -z "$(nvram get vlan1ports)" ] && { - nvram set vlan0ports="1 2 3 4 5*" - nvram set vlan1ports="0 5" - } -} - sed 's/^[^#]/insmod &/' /etc/modules /etc/modules.d/* 2>&-|ash ifconfig lo 127.0.0.1 up ifconfig eth0 promisc -[ "$(uname -r|grep -c 2.6)" = "1" ] && [ -x /sbin/robocfg ] && { +[ "$(uname -r|grep -c 2.6)" = "1" ] && [ -x /sbin/robocfg ] && { # FIXME: replace when the new switch driver is integrated... robocfg switch disable vlans enable reset vlan 0 ports "0 1 2 3 5t" vlan 1 ports "4 5t" port 4 state enabled stp none switch enable robocfg show } diff --git a/package/base-files/default/etc/profile b/package/base-files/default/etc/profile index 1d98ae3402..e3abe6967f 100644 --- a/package/base-files/default/etc/profile +++ b/package/base-files/default/etc/profile @@ -9,3 +9,4 @@ alias vim=vi arp() { cat /proc/net/arp; } ldd() { LD_TRACE_LOADED_OBJECTS=1 $*; } +reboot() { ifdown wan 2>&1 >/dev/null ; /sbin/reboot; } diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 2d4054d8b3..1471369498 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -6,6 +6,8 @@ type=$1 debug "### ifdown $type ###" if=$(nvram get ${type}_ifname) -if_valid $if || exit -$DEBUG ifconfig $if down +proto=$(nvram get ${type}_proto) +if_valid $if && $DEBUG ifconfig $if down kill $(cat /var/run/${if}.pid 2>&-) 2>&- +[ "$if" = "ppp0" ] && killall pppd +killall ifup.$proto >&- 2>&- diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 1f78061a2a..be7075bf14 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -1,5 +1,6 @@ #!/bin/ash [ $# = 0 ] && { echo " $0 "; exit; } + . /etc/functions.sh . /etc/network.overrides [ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network @@ -8,59 +9,28 @@ type=$1 debug "### ifup $type ###" if_proto=$(nvram get ${type}_proto) -[ "${if_proto}" = "pppoa" ] || { - if=$(nvram get ${type}_ifname) - [ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) - - if_valid $if || exit - mac=$(nvram get ${type}_hwaddr) - $DEBUG ifconfig $if down 2>&- - - pidfile=/var/run/${if}.pid - [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) - - if [ "${if%%[0-9]}" = "br" ]; then - stp=$(nvram get ${type}_stp) - $DEBUG brctl delbr $if 2>&- - $DEBUG brctl addbr $if - $DEBUG brctl setfd $if 0 - $DEBUG brctl stp $if ${stp:-0} - - for sif in $(nvram get ${type}_ifnames); do - if_valid $sif || continue - ${mac:+$DEBUG ifconfig $sif down hw ether $mac} - $DEBUG ifconfig $sif 0.0.0.0 up - $DEBUG brctl addif $if $sif - done - else - ${mac:+$DEBUG ifconfig $if down hw ether $mac} - fi -} - -case "$if_proto" in - static) - ip=$(nvram get ${type}_ipaddr) - netmask=$(nvram get ${type}_netmask) - gateway=$(nvram get ${type}_gateway) - - $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up - ${gateway:+$DEBUG route add default gw $gateway} - - [ -f /etc/resolv.conf ] && return - - debug "# --- creating /etc/resolv.conf ---" - for dns in $(nvram get ${type}_dns); do - echo "nameserver $dns" >> /etc/resolv.conf - done - ;; - dhcp) - ip=$(nvram get ${type}_ipaddr) - ${DEBUG:-eval} "udhcpc -R -i $if ${ip:+-r $ip} -b -p $pidfile &" - ;; - none|"") - ;; - *) - [ -x "/sbin/ifup.${if_proto}" ] && { $DEBUG /sbin/ifup.${if_proto} $*; exit; } - echo "### ifup $type: ignored ${type}_proto=\"$if_proto\" (not supported)" - ;; -esac +if=$(nvram get ${type}_ifname) +[ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) + +if_valid $if || [ "$if_proto" = "pptp" ] || exit +mac=$(nvram get ${type}_hwaddr) +$DEBUG ifconfig $if down 2>&- + +if [ "${if%%[0-9]}" = "br" ]; then + stp=$(nvram get ${type}_stp) + $DEBUG brctl delbr $if 2>&- + $DEBUG brctl addbr $if + $DEBUG brctl setfd $if 0 + $DEBUG brctl stp $if ${stp:-0} + + for sif in $(nvram get ${type}_ifnames); do + if_valid $sif || continue + ${mac:+$DEBUG ifconfig $sif down hw ether $mac} + $DEBUG ifconfig $sif 0.0.0.0 up + $DEBUG brctl addif $if $sif + done +else + ${mac:+$DEBUG ifconfig $if down hw ether $mac} +fi + +do_ifup $if_proto $type -- cgit v1.2.3 From 2af90479fbd25ca63d9697200d43ea614d657184 Mon Sep 17 00:00:00 2001 From: nbd Date: Sat, 19 Nov 2005 03:17:20 +0000 Subject: hotplug-based network script rewrite git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@2531 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/bin/firstboot | 3 - package/base-files/default/etc/functions.sh | 69 +------- .../base-files/default/etc/hotplug.d/net/01-wds | 5 - .../base-files/default/etc/hotplug.d/net/10-net | 190 +++++++++++++++++++++ package/base-files/default/etc/init.d/S10boot | 21 ++- package/base-files/default/etc/init.d/S40network | 8 +- package/base-files/default/etc/nvram.sh | 4 +- package/base-files/default/sbin/hotplug | 6 +- package/base-files/default/sbin/ifdown | 28 ++- package/base-files/default/sbin/ifup | 35 ++-- package/linux-atm/Makefile | 4 +- package/linux-atm/files/br2684.init | 41 +++-- package/ppp/files/ifup.pppoa | 57 +++---- package/ppp/files/ifup.pppoe | 64 ++++--- package/pptp/files/ifup.pptp | 82 +++++---- 15 files changed, 368 insertions(+), 249 deletions(-) delete mode 100644 package/base-files/default/etc/hotplug.d/net/01-wds create mode 100644 package/base-files/default/etc/hotplug.d/net/10-net (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/bin/firstboot b/package/base-files/default/bin/firstboot index 604721873a..eff7063b1c 100755 --- a/package/base-files/default/bin/firstboot +++ b/package/base-files/default/bin/firstboot @@ -60,6 +60,3 @@ mount none /tmp -t ramfs umount /rom/proc umount /rom/tmp umount /rom/dev - -# normally created by boot script -mkdir -p /var/run diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh index 9cfc802357..e7126473f4 100755 --- a/package/base-files/default/etc/functions.sh +++ b/package/base-files/default/etc/functions.sh @@ -1,4 +1,4 @@ -#!/bin/ash +#!/bin/sh . /etc/nvram.sh alias debug=${DEBUG:-:} @@ -7,74 +7,11 @@ alias debug=${DEBUG:-:} if_valid () ( ifconfig "$1" >&- 2>&- || [ "${1%%[0-9]}" = "br" ] || - { - [ "${1%%[0-9]}" = "vlan" ] && ( - i=${1#vlan} - hwname=$(nvram get vlan${i}hwname) - hwaddr=$(nvram get ${hwname}macaddr) - [ -z "$hwaddr" ] && return 1 - - vif=$(ifconfig -a | awk '/^eth.*'$hwaddr'/ {print $1; exit}' IGNORECASE=1) - debug "# vlan$i => $vif" - - $DEBUG ifconfig $vif up - $DEBUG vconfig add $vif $i 2>&- - ) - } || { debug "# missing interface '$1' ignored"; false; } ) -do_ifup() { - if_proto=$(nvram get ${2}_proto) - if=$(nvram get ${2}_ifname) - [ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) - - pidfile=/var/run/${if}.pid - [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) - - case "$1" in - static) - ip=$(nvram get ${2}_ipaddr) - netmask=$(nvram get ${2}_netmask) - gateway=$(nvram get ${2}_gateway) - - $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up - ${gateway:+$DEBUG route add default gw $gateway} - - [ -f /etc/resolv.conf ] || { - debug "# --- creating /etc/resolv.conf ---" - for dns in $(nvram get ${2}_dns); do - echo "nameserver $dns" >> /etc/resolv.conf - done - } - - env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" & - ;; - dhcp) - DHCP_IP=$(nvram get ${2}_ipaddr) - DHCP_NETMASK=$(nvram get ${2}_netmask) - $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up - - DHCP_ARGS="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile" - DHCP_HOSTNAME=$(nvram get ${2}_hostname) - DHCP_HOSTNAME=${DHCP_HOSTNAME%%.*} - [ -z $DHCP_HOSTNAME ] || DHCP_ARGS="$DHCP_ARGS -H $DHCP_HOSTNAME" - [ "$if_proto" = "pptp" ] && DHCP_ARGS="$DHCP_ARGS -n -q" || DHCP_ARGS="$DHCP_ARGS -R &" - oldpid=$(cat $pidfile) - ${DEBUG:-eval} "udhcpc $DHCP_ARGS" - pidof udhcpc | grep "$oldpid" >&- 2>&- && { - sleep 1 - kill -9 $oldpid - } - # hotplug events are handled by /usr/share/udhcpc/default.script - ;; - none|"") - ;; - *) - [ -x "/sbin/ifup.$1" ] && { $DEBUG /sbin/ifup.$1 ${2}; exit; } - echo "### ifup ${2}: ignored ${2}_proto=\"$1\" (not supported)" - ;; - esac +hotplug_dev() { + env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net } bitcount () { diff --git a/package/base-files/default/etc/hotplug.d/net/01-wds b/package/base-files/default/etc/hotplug.d/net/01-wds deleted file mode 100644 index 38bd69667f..0000000000 --- a/package/base-files/default/etc/hotplug.d/net/01-wds +++ /dev/null @@ -1,5 +0,0 @@ -[ "${INTERFACE%%[0-9]*}" = "wds" ] && { - ifconfig $INTERFACE 0.0.0.0 up - /usr/sbin/brctl addif br0 $INTERFACE -} - diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net new file mode 100644 index 0000000000..29df1d2ce8 --- /dev/null +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -0,0 +1,190 @@ +#!/bin/sh +setup_eth() +{ + [ -f /proc/net/wl0 ] && { + lsmod | grep wlcompat >&- || insmod wlcompat + } + iwconfig "$INTERFACE" 2>&- | grep -v 'no wireless' >&- && { + /sbin/wifi + } + if="$(echo "$INTERFACE" | sed s,eth,et,)" + ifconfig "$INTERFACE" up 2>&- >&- + for vlan in $(seq 0 15); do + [ "$(nvram get vlan${vlan}hwname)" = "$if" ] && \ + $DEBUG vconfig add "$INTERFACE" "$vlan" + done +} + +find_name() +{ + pppoa_ifname="atm0" # hack for ppp over atm, which has no ${proto}_ifname + interfaces="lan wan wifi $(nvram get ifnames)" + for ifname in $interfaces; do + IFTYPE="${ifname}" + IFPROTO="$(nvram get ${IFTYPE}_proto)" + IFACE="$(nvram get ${IFTYPE}_ifname)" + [ -z "$IFPROTO" -o "$IFPROTO" = "none" ] || { + [ "${IFACE}" = "$INTERFACE" ] && return 0 + case "$IFPROTO" in + static|dhcp) + [ "${IFACE%%[0-9]*}" = "br" ] && { + for part in $(nvram get ${IFTYPE}_ifnames); do + [ "$part" = "$INTERFACE" ] && return 0 + done + } + ;; + *) + [ "$(nvram get ${IFPROTO}_ifname)" = "$INTERFACE" \ + -a -x /sbin/ifup.${IFPROTO} ] && return 0 + ;; + esac + } + done + IFACE="" + IFTYPE="" + IFPROTO="" + return 255 +} + +do_ifup() { + if="$3" + if_proto="$(nvram get ${2}_proto)" + + pidfile=/var/run/${if}.pid + [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) + + case "$1" in + static) + ip=$(nvram get ${2}_ipaddr) + netmask=$(nvram get ${2}_netmask) + gateway=$(nvram get ${2}_gateway) + + $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up + ${gateway:+$DEBUG route add default gw $gateway} + + [ -f /etc/resolv.conf ] || { + debug "# --- creating /etc/resolv.conf ---" + for dns in $(nvram get ${2}_dns); do + echo "nameserver $dns" >> /etc/resolv.conf + done + } + + env -i ACTION="ifup" INTERFACE="${2}" PROTO=static /sbin/hotplug "iface" & + ;; + dhcp) + DHCP_IP=$(nvram get ${2}_ipaddr) + DHCP_NETMASK=$(nvram get ${2}_netmask) + $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up + + DHCP_ARGS="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile" + DHCP_HOSTNAME=$(nvram get ${2}_hostname) + DHCP_HOSTNAME=${DHCP_HOSTNAME%%.*} + [ -z $DHCP_HOSTNAME ] || DHCP_ARGS="$DHCP_ARGS -H $DHCP_HOSTNAME" + [ "$if_proto" = "pptp" ] && DHCP_ARGS="$DHCP_ARGS -n -q" || DHCP_ARGS="$DHCP_ARGS -R &" + oldpid=$(cat $pidfile) + ${DEBUG:-eval} "udhcpc $DHCP_ARGS" + pidof udhcpc | grep "$oldpid" >&- 2>&- && { + sleep 1 + kill -9 $oldpid + } + # 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() +{ + case "${INTERFACE%%[0-9]*}" in + eth) setup_eth;; + esac + + [ -z "$IFTYPE" -o -z "$IFPROTO" ] && { + find_name || { + case "${INTERFACE%%[0-9]*}" in + wds) + for tmp in lan wifi; do + [ -z "$IFPROTO" ] && [ "$(nvram get ${tmp}_ifname)" = "br0" ] && { + IFPROTO="$(nvram get ${tmp}_proto)" + IFTYPE="${tmp}" + } + done + [ -z "$IFPROTO" ] && return 0 + ;; + atm) + for tmp in lan wan wifi $(nvram get ifnames); do + [ "$(nvram get ${tmp}_proto)" = "pppoa" ] && { + do_ifup "pppoa" "$tmp" "$INTERFACE" + return 0 + } + done + ;; + *) + return 0 + ;; + esac + } + } + + case "${INTERFACE%%[0-9]*}" in + ppp|atm);; + *) + mac=$(nvram get ${IFTYPE}_hwaddr) + ${mac:+$DEBUG ifconfig $INTERFACE down hw ether $mac} + ;; + esac + + if="$(nvram get ${IFTYPE}_ifname)" + if [ "${if%%[0-9]}" = "br" ]; then + if_valid "$INTERFACE" && { + ifconfig "$if" 2>&- >&- || { + stp=$(nvram get ${IFTYPE}_stp) + $DEBUG brctl addbr "$if" + $DEBUG brctl setfd "$if" 0 + $DEBUG brctl stp "$if" "${stp:-0}" + } + + if [ "$INTERFACE" != "$if" ]; then + $DEBUG ifconfig "$INTERFACE" 0.0.0.0 up + brctl addif "$if" "$INTERFACE" + else + do_ifup "$IFPROTO" "$IFTYPE" "$if" + fi + } + else + do_ifup "$IFPROTO" "$IFTYPE" "$if" + fi +} + +do_unregister() { + [ "${INTERFACE%%[0-9]*}" = "atm" ] || ifconfig "$INTERFACE" 0.0.0.0 down 2>&- + [ -z "$IFTYPE" -o -z "$IFPROTO" ] && find_name + [ -z "$IFTYPE" -o -z "$IFPROTO" ] && 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 ifup.${IFPROTO} + killall pppd + ;; + dhcp) + [ -f /var/run/${INTERFACE}.pid ] && kill "$(cat /var/run/${INTERFACE}.pid)" 2>&- >&- + ;; + esac +} + +case "$ACTION" in + register) do_register;; + unregister) do_unregister;; +esac diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index b0dc04eb7e..d5ec19436a 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -5,10 +5,22 @@ echo "S" > /proc/jffs2_bbc } +vconfig set_name_type VLAN_PLUS_VID_NO_PAD + +HOSTNAME=$(nvram get wan_hostname) +HOSTNAME=${HOSTNAME%%.*} +echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname + +# automagically run firstboot +[ -z "$FAILSAFE" -a -z "$(nvram get no_root_swap)" ] && { + { mount|grep "on / type jffs2" 1>&-; } || firstboot +} + mkdir -p /var/run mkdir -p /var/log touch /var/log/wtmp touch /var/log/lastlog +[ "$FAILSAFE" = "true" ] && touch /tmp/.failsafe sed 's/^[^#]/insmod &/' /etc/modules /etc/modules.d/* 2>&-|ash @@ -20,13 +32,4 @@ ifconfig eth0 promisc robocfg show } -HOSTNAME=$(nvram get wan_hostname) -HOSTNAME=${HOSTNAME%%.*} -echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname - -vconfig set_name_type VLAN_PLUS_VID_NO_PAD -# automagically run firstboot -[ -z "$FAILSAFE" -a -z "$(nvram get no_root_swap)" ] && { - { mount|grep "on / type jffs2" 1>&-; } || firstboot -} diff --git a/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network index df7c6b3515..168fd2979b 100755 --- a/package/base-files/default/etc/init.d/S40network +++ b/package/base-files/default/etc/init.d/S40network @@ -3,10 +3,10 @@ [ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network case "$1" in start|restart) - ifup lan - ifup wan - ifup wifi - wifi up +# ifup lan +# ifup wan +# ifup wifi +# wifi up for route in $(nvram get static_route); do { eval "set $(echo $route | sed 's/:/ /g')" diff --git a/package/base-files/default/etc/nvram.sh b/package/base-files/default/etc/nvram.sh index f1170ac470..4d39a10204 100644 --- a/package/base-files/default/etc/nvram.sh +++ b/package/base-files/default/etc/nvram.sh @@ -4,8 +4,8 @@ nvram () { if [ -x /usr/sbin/nvram ]; then case $1 in - get) eval "echo \${$2:-\$(command nvram get $2)}";; - *) command nvram $*;; + get) eval "echo \${$2:-\$(/usr/sbin/nvram get $2)}";; + *) /usr/sbin/nvram $*;; esac else case $1 in diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug index 4e009593af..e53b2afcc5 100755 --- a/package/base-files/default/sbin/hotplug +++ b/package/base-files/default/sbin/hotplug @@ -1,7 +1,11 @@ #!/bin/sh +[ -e /tmp/.failsafe ] && { + export FAILSAFE=true +} || { + [ -e /etc/config/network ] && . /etc/config/network +} . /etc/functions.sh . /etc/network.overrides -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network PATH=/bin:/sbin:/usr/bin:/usr/sbin LOGNAME=root diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index f2f8bbfe81..3ebc251f72 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -1,19 +1,29 @@ #!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh -. /etc/network.overrides +. /etc/network.overrides [ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network -type=$1 debug "### ifdown $type ###" +type=$1 +if_proto=$(nvram get ${type}_proto) if=$(nvram get ${type}_ifname) -proto=$(nvram get ${type}_proto) -if_valid $if && $DEBUG ifconfig $if down -kill $(cat /var/run/${if}.pid 2>&-) 2>&- -killall ifup.$proto >&- 2>&- -case "$proto" in - pptp|pppoe) killall pppd >&- 2>&- ;; - static) env -i ACTION="ifdown" INTERFACE="$if" PROTO=static /sbin/hotplug "iface" ;; + +case "$if_proto" in + pppoa) hotplug_dev unregister atm0; exit 0 ;; + pppoe) + [ "$(nvram get pppoe_atm)" = 1 ] && { + hotplug_dev unregister atm0 + exit + } + ;; esac +if [ "${if%%[0-9]}" = "br" ]; then + for sif in $(nvram get ${type}_ifnames); do + hotplug_dev unregister "$sif" + done +fi + +hotplug_dev unregister "$if" diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index be7075bf14..0d75cefeb6 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -1,36 +1,31 @@ -#!/bin/ash +#!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } - . /etc/functions.sh . /etc/network.overrides [ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network -type=$1 +ifdown $1 + debug "### ifup $type ###" +type=$1 if_proto=$(nvram get ${type}_proto) if=$(nvram get ${type}_ifname) -[ "${if%%[0-9]}" = "ppp" ] && if=$(nvram get ${if_proto}_ifname) -if_valid $if || [ "$if_proto" = "pptp" ] || exit -mac=$(nvram get ${type}_hwaddr) -$DEBUG ifconfig $if down 2>&- +case "$if_proto" in + pppoa) hotplug_dev register atm0; exit 0 ;; + pppoe) + [ "$(nvram get pppoe_atm)" = 1 ] && { + hotplug_dev register atm0 + exit + } + ;; +esac if [ "${if%%[0-9]}" = "br" ]; then - stp=$(nvram get ${type}_stp) - $DEBUG brctl delbr $if 2>&- - $DEBUG brctl addbr $if - $DEBUG brctl setfd $if 0 - $DEBUG brctl stp $if ${stp:-0} - for sif in $(nvram get ${type}_ifnames); do - if_valid $sif || continue - ${mac:+$DEBUG ifconfig $sif down hw ether $mac} - $DEBUG ifconfig $sif 0.0.0.0 up - $DEBUG brctl addif $if $sif + hotplug_dev register "$sif" done else - ${mac:+$DEBUG ifconfig $if down hw ether $mac} + hotplug_dev register "$if" fi - -do_ifup $if_proto $type diff --git a/package/linux-atm/Makefile b/package/linux-atm/Makefile index d36c7c39e3..3c7bf9c5b5 100644 --- a/package/linux-atm/Makefile +++ b/package/linux-atm/Makefile @@ -63,8 +63,8 @@ $(IPKG_LINUX_ATM): $(IPKG_BR2684CTL): install -d -m0755 $(IDIR_BR2684CTL)/usr/sbin cp -fpR $(PKG_INSTALL_DIR)/usr/sbin/br2684ctl $(IDIR_BR2684CTL)/usr/sbin/ - install -d -m0755 $(IDIR_BR2684CTL)/etc/init.d - install -m0755 ./files/br2684.init $(IDIR_BR2684CTL)/etc/init.d/S30br2684 + install -d -m0755 $(IDIR_BR2684CTL)/etc/hotplug.d/net + install -m0644 ./files/br2684.init $(IDIR_BR2684CTL)/etc/hotplug.d/net/30-br2684 $(RSTRIP) $(IDIR_BR2684CTL)/ $(IPKG_BUILD) $(IDIR_BR2684CTL) $(PACKAGE_DIR) diff --git a/package/linux-atm/files/br2684.init b/package/linux-atm/files/br2684.init index 90ba36521d..88f40e76b6 100644 --- a/package/linux-atm/files/br2684.init +++ b/package/linux-atm/files/br2684.init @@ -1,22 +1,21 @@ -#!/bin/sh -. /etc/functions.sh -[ -e /etc/config/network ] && . /etc/config/network - -killall br2684ctl 2>&- >&- -[ "$(nvram get pppoe_atm)" = 1 ] && { - VPI=$(nvram get atm_vpi) - VCI=$(nvram get atm_vci) - case "$(nvram get atm_encaps)" in - 0|vc) - ENCAPS=0 - ;; - 1|llc) - ENCAPS=1 - ;; - *) - ENCAPS=0 - ;; - esac - insmod br2684 - br2684ctl -c0 -e${ENCAPS} -a${VPI:-8}.${VCI:-35} & +[ "${INTERFACE%%[0-9]*}" = "atm" ] && { + case "$ACTION" in + register) + [ "$(nvram get pppoe_atm)" = 1 ] && { + VPI=$(nvram get atm_vpi) + VCI=$(nvram get atm_vci) + case "$(nvram get atm_encaps)" in + 0|vc) ENCAPS=0 ;; + 1|llc) ENCAPS=1 ;; + *) ENCAPS=0 ;; + esac + insmod br2684 2>&- >&- + br2684ctl -c0 -e${ENCAPS} -a${VPI:-8}.${VCI:-35} & + } + ;; + unregister) + killall br2684ctl 2>&- >&- + rmmod br2684 + ;; + esac } diff --git a/package/ppp/files/ifup.pppoa b/package/ppp/files/ifup.pppoa index 5f42a39d08..6539c3ae8e 100644 --- a/package/ppp/files/ifup.pppoa +++ b/package/ppp/files/ifup.pppoa @@ -14,36 +14,31 @@ for module in slhc ppp_generic pppoatm; do /sbin/insmod $module 2>&- >&- done -while :; do - VPI=$(nvram get atm_vpi) - VCI=$(nvram get atm_vci) - USERNAME=$(nvram get ppp_username) - PASSWORD=$(nvram get ppp_passwd) - KEEPALIVE=$(nvram get ppp_redialperiod) - KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} - DEMAND=$(nvram get ppp_demand) - case "$DEMAND" in - on|1|enabled) - DEMAND=$(nvram get ppp_idletime) - DEMAND=${IDLETIME:+demand idle $IDLETIME} - ;; - *) DEMAND="";; - esac - MTU=$(nvram get ppp_mtu) - MTU=${MTU:-1500} +VPI=$(nvram get atm_vpi) +VCI=$(nvram get atm_vci) +USERNAME=$(nvram get ppp_username) +PASSWORD=$(nvram get ppp_passwd) +KEEPALIVE=$(nvram get ppp_redialperiod) +KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} +DEMAND=$(nvram get ppp_demand) +case "$DEMAND" in + on|1|enabled) + DEMAND=$(nvram get ppp_idletime) + DEMAND=${IDLETIME:+demand idle $IDLETIME} + ;; + *) DEMAND="persist";; +esac +MTU=$(nvram get ppp_mtu) +MTU=${MTU:-1500} - /usr/sbin/pppd nodetach \ +/usr/sbin/pppd nodetach \ plugin pppoatm.so ${VPI:-8}.${VCI:-35} \ - usepeerdns \ - defaultroute \ - linkname $type \ - ipparam $type \ - user "$USERNAME" \ - password "$PASSWORD" \ - mtu $MTU mru $MTU \ - $DEMAND \ - $KEEPALIVE - - # Read settings again (might have changed) - [ -e /etc/config/network ] && . /etc/config/network -done & + usepeerdns \ + defaultroute \ + linkname $type \ + ipparam $type \ + user "$USERNAME" \ + password "$PASSWORD" \ + mtu $MTU mru $MTU \ + $DEMAND \ + $KEEPALIVE diff --git a/package/ppp/files/ifup.pppoe b/package/ppp/files/ifup.pppoe index 36bbe30299..4c42fa5bb2 100644 --- a/package/ppp/files/ifup.pppoe +++ b/package/ppp/files/ifup.pppoe @@ -14,38 +14,34 @@ for module in slhc ppp_generic pppox pppoe; do /sbin/insmod $module 2>&- >&- done -while :; do - IFNAME=$(nvram get pppoe_ifname) - USERNAME=$(nvram get ppp_username) - PASSWORD=$(nvram get ppp_passwd) - KEEPALIVE=$(nvram get ppp_redialperiod) - KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} - DEMAND=$(nvram get ppp_demand) - case "$DEMAND" in - on|1|enabled) - DEMAND=$(nvram get ppp_idletime) - DEMAND=${IDLETIME:+demand idle $IDLETIME} - ;; - *) DEMAND="";; - esac - MTU=$(nvram get ppp_mtu) - MTU=${MTU:-1492} +IFNAME=$(nvram get pppoe_ifname) +USERNAME=$(nvram get ppp_username) +PASSWORD=$(nvram get ppp_passwd) +KEEPALIVE=$(nvram get ppp_redialperiod) +KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} +DEMAND=$(nvram get ppp_demand) +case "$DEMAND" in + on|1|enabled) + DEMAND=$(nvram get ppp_idletime) + DEMAND=${IDLETIME:+demand idle $IDLETIME} + ;; + *) DEMAND="persist";; +esac +MTU=$(nvram get ppp_mtu) +MTU=${MTU:-1492} + +ifconfig $IFNAME up +/usr/sbin/pppd nodetach \ + plugin rp-pppoe.so \ + connect /bin/true \ + usepeerdns \ + defaultroute \ + linkname $type \ + ipparam $type \ + user "$USERNAME" \ + password "$PASSWORD" \ + mtu $MTU mru $MTU \ + $DEMAND \ + $KEEPALIVE \ + nic-$IFNAME - ifconfig $IFNAME up - /usr/sbin/pppd nodetach \ - plugin rp-pppoe.so \ - connect /bin/true \ - usepeerdns \ - defaultroute \ - linkname $type \ - ipparam $type \ - user "$USERNAME" \ - password "$PASSWORD" \ - mtu $MTU mru $MTU \ - $DEMAND \ - $KEEPALIVE \ - nic-$IFNAME - - # Read settings again (might have changed) - [ -e /etc/config/network ] && . /etc/config/network -done & diff --git a/package/pptp/files/ifup.pptp b/package/pptp/files/ifup.pptp index 23cad08050..eda78e4402 100644 --- a/package/pptp/files/ifup.pptp +++ b/package/pptp/files/ifup.pptp @@ -10,46 +10,44 @@ for module in slhc ppp_generic ppp_async ip_gre; do /sbin/insmod $module 2>&- >&- done -while :; do - PPTP_PROTO="$(nvram get pptp_proto)" - [ "$PPTP_PROTO" = "static" ] || PPTP_PROTO="" - PPTP_PROTO="${PPTP_PROTO:-dhcp}" - IP=$(nvram get pptp_server_ip) - USERNAME=$(nvram get ppp_username) - PASSWORD=$(nvram get ppp_passwd) - KEEPALIVE=$(nvram get ppp_redialperiod) - KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} - DEMAND=$(nvram get ppp_demand) - case "$DEMAND" in - on|1|enabled) - DEMAND=$(nvram get ppp_idletime) - DEMAND=${IDLETIME:+demand idle $IDLETIME} - ;; - *) DEMAND="";; - esac - MTU=$(nvram get ppp_mtu) - MTU=${MTU:-1452} - - do_ifup $PPTP_PROTO $type - - # hack for some buggy ISPs - NETMASK=$(nvram get ${type}_netmask) - IFNAME=$(nvram get pptp_ifname) - [ -z "$NETMASK" -o -z "$IFNAME" ] || ifconfig $IFNAME netmask $NETMASK - - /usr/sbin/pppd nodetach \ - pty "/usr/sbin/pptp $IP --loglevel 0 --nolaunchpppd" \ - file /etc/ppp/options.pptp \ - connect /bin/true \ - usepeerdns \ - defaultroute \ - replacedefaultroute \ - linkname "$type" \ - ipparam "$type" \ - user "$USERNAME" \ - password "$PASSWORD" \ - mtu $MTU mru $MTU \ - $DEMAND \ - $KEEPALIVE -done & +PPTP_PROTO="$(nvram get pptp_proto)" +[ "$PPTP_PROTO" = "static" ] || PPTP_PROTO="" +PPTP_PROTO="${PPTP_PROTO:-dhcp}" +IP=$(nvram get pptp_server_ip) +USERNAME=$(nvram get ppp_username) +PASSWORD=$(nvram get ppp_passwd) +KEEPALIVE=$(nvram get ppp_redialperiod) +KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} +DEMAND=$(nvram get ppp_demand) +case "$DEMAND" in + on|1|enabled) + DEMAND=$(nvram get ppp_idletime) + DEMAND=${IDLETIME:+demand idle $IDLETIME} + ;; + *) DEMAND="persist";; +esac +MTU=$(nvram get ppp_mtu) +MTU=${MTU:-1452} + +do_ifup $PPTP_PROTO $type + +# hack for some buggy ISPs +NETMASK=$(nvram get ${type}_netmask) +IFNAME=$(nvram get pptp_ifname) +[ -z "$NETMASK" -o -z "$IFNAME" ] || ifconfig $IFNAME netmask $NETMASK + +/usr/sbin/pppd nodetach \ + pty "/usr/sbin/pptp $IP --loglevel 0 --nolaunchpppd" \ + file /etc/ppp/options.pptp \ + connect /bin/true \ + usepeerdns \ + defaultroute \ + replacedefaultroute \ + linkname "$type" \ + ipparam "$type" \ + user "$USERNAME" \ + password "$PASSWORD" \ + mtu $MTU mru $MTU \ + $DEMAND \ + $KEEPALIVE -- cgit v1.2.3 From 76dec73b0b803f861192efe08b95f2cf331a96e2 Mon Sep 17 00:00:00 2001 From: nbd Date: Sat, 19 Nov 2005 14:53:21 +0000 Subject: fix ifup/down for ppp-based stuff git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@2536 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/etc/hotplug.d/net/10-net | 4 ++-- package/base-files/default/sbin/ifdown | 7 +------ package/base-files/default/sbin/ifup | 7 ++++--- 3 files changed, 7 insertions(+), 11 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index 29df1d2ce8..3bc980f86f 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -175,8 +175,8 @@ do_unregister() { case "$IFPROTO" in pppoe|pppoa|pptp) - killall ifup.${IFPROTO} - killall pppd + killall ifup.${IFPROTO} 2>&- >&- + killall pppd 2>&- >&- ;; dhcp) [ -f /var/run/${INTERFACE}.pid ] && kill "$(cat /var/run/${INTERFACE}.pid)" 2>&- >&- diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 3ebc251f72..8818d46145 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -12,12 +12,7 @@ if=$(nvram get ${type}_ifname) case "$if_proto" in pppoa) hotplug_dev unregister atm0; exit 0 ;; - pppoe) - [ "$(nvram get pppoe_atm)" = 1 ] && { - hotplug_dev unregister atm0 - exit - } - ;; + ""|none) exit 0;; esac if [ "${if%%[0-9]}" = "br" ]; then diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 0d75cefeb6..0a2cdf5331 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -14,12 +14,13 @@ if=$(nvram get ${type}_ifname) case "$if_proto" in pppoa) hotplug_dev register atm0; exit 0 ;; - pppoe) - [ "$(nvram get pppoe_atm)" = 1 ] && { + pppoe) + ifconfig nas0 2>&- >&- || { hotplug_dev register atm0 - exit + exit 0 } ;; + none|"") exit 0;; esac if [ "${if%%[0-9]}" = "br" ]; then -- cgit v1.2.3 From 777e76abb47dd74816ea063c471359b0db3aa2e7 Mon Sep 17 00:00:00 2001 From: nbd Date: Sat, 19 Nov 2005 19:04:15 +0000 Subject: more fixes for the network scripts git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@2537 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../base-files/default/etc/hotplug.d/net/10-net | 39 +++++++++++----------- package/base-files/default/sbin/ifdown | 2 ++ package/base-files/default/sbin/ifup | 2 ++ 3 files changed, 23 insertions(+), 20 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index 3bc980f86f..19f53abd7d 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -23,22 +23,21 @@ find_name() IFTYPE="${ifname}" IFPROTO="$(nvram get ${IFTYPE}_proto)" IFACE="$(nvram get ${IFTYPE}_ifname)" - [ -z "$IFPROTO" -o "$IFPROTO" = "none" ] || { - [ "${IFACE}" = "$INTERFACE" ] && return 0 - case "$IFPROTO" in - static|dhcp) - [ "${IFACE%%[0-9]*}" = "br" ] && { - for part in $(nvram get ${IFTYPE}_ifnames); do - [ "$part" = "$INTERFACE" ] && return 0 - done - } - ;; - *) - [ "$(nvram get ${IFPROTO}_ifname)" = "$INTERFACE" \ - -a -x /sbin/ifup.${IFPROTO} ] && return 0 - ;; - esac - } + case "$IFPROTO" in + ""|none);; + static|dhcp) + [ "${IFACE}" = "$INTERFACE" ] && return 0 + [ "${IFACE%%[0-9]*}" = "br" ] && { + for part in $(nvram get ${IFTYPE}_ifnames); do + [ "$part" = "$INTERFACE" ] && return 0 + done + } + ;; + *) + [ "$(nvram get ${IFPROTO}_ifname)" = "$INTERFACE" \ + -a -x /sbin/ifup.${IFPROTO} ] && return 0 + ;; + esac done IFACE="" IFTYPE="" @@ -155,13 +154,12 @@ do_register() do_ifup "$IFPROTO" "$IFTYPE" "$if" fi } - else - do_ifup "$IFPROTO" "$IFTYPE" "$if" + else + [ "${INTERFACE%%[0-9]*}" = "ppp" ] || do_ifup "$IFPROTO" "$IFTYPE" "$if" fi } do_unregister() { - [ "${INTERFACE%%[0-9]*}" = "atm" ] || ifconfig "$INTERFACE" 0.0.0.0 down 2>&- [ -z "$IFTYPE" -o -z "$IFPROTO" ] && find_name [ -z "$IFTYPE" -o -z "$IFPROTO" ] && return 0 @@ -175,13 +173,14 @@ do_unregister() { case "$IFPROTO" in pppoe|pppoa|pptp) - killall ifup.${IFPROTO} 2>&- >&- 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>&- } case "$ACTION" in diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 8818d46145..85bb2fbc5d 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -15,6 +15,8 @@ case "$if_proto" in ""|none) exit 0;; esac +[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${if_proto}_ifname)" + if [ "${if%%[0-9]}" = "br" ]; then for sif in $(nvram get ${type}_ifnames); do hotplug_dev unregister "$sif" diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 0a2cdf5331..67e01a3e90 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -23,6 +23,8 @@ case "$if_proto" in none|"") exit 0;; esac +[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${if_proto}_ifname)" + if [ "${if%%[0-9]}" = "br" ]; then for sif in $(nvram get ${type}_ifnames); do hotplug_dev register "$sif" -- cgit v1.2.3 From 23e86550c9c59436cc5f253292774861dd6ca62e Mon Sep 17 00:00:00 2001 From: nbd Date: Mon, 16 Jan 2006 03:14:59 +0000 Subject: port wan_device changes from whiterussian to kamikaze git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@2993 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- .../base-files/default/etc/hotplug.d/net/10-net | 2 +- package/base-files/default/sbin/ifdown | 2 +- package/base-files/default/sbin/ifup | 2 +- package/ppp/files/ifup.pppoe | 2 +- package/pptp/files/ifup.pptp | 2 +- .../files/brcm-2.4/etc/init.d/S05netconfig | 4 +--- .../base-files/files/brcm-2.4/etc/init.d/S05nvram | 26 +++++++++++++--------- .../files/brcm-2.6/etc/init.d/S05netconfig | 8 ++----- 8 files changed, 24 insertions(+), 24 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index 8d2c6a8034..dd4ee8863a 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -26,7 +26,7 @@ find_name() } ;; *) - [ "$(nvram get ${IFPROTO}_ifname)" = "$INTERFACE" \ + [ "$(nvram get ${IFTYPE}_device)" = "$INTERFACE" \ -a -x /sbin/ifup.${IFPROTO} ] && return 0 ;; esac diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 85bb2fbc5d..d0120dcbe8 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -15,7 +15,7 @@ case "$if_proto" in ""|none) exit 0;; esac -[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${if_proto}_ifname)" +[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${type}_device)" if [ "${if%%[0-9]}" = "br" ]; then for sif in $(nvram get ${type}_ifnames); do diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 67e01a3e90..8ae6416685 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -23,7 +23,7 @@ case "$if_proto" in none|"") exit 0;; esac -[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${if_proto}_ifname)" +[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${type}_device)" if [ "${if%%[0-9]}" = "br" ]; then for sif in $(nvram get ${type}_ifnames); do diff --git a/package/ppp/files/ifup.pppoe b/package/ppp/files/ifup.pppoe index a038b34279..b43d2689bd 100644 --- a/package/ppp/files/ifup.pppoe +++ b/package/ppp/files/ifup.pppoe @@ -14,7 +14,7 @@ for module in slhc ppp_generic pppox pppoe; do /sbin/insmod $module 2>&- >&- done -IFNAME=$(nvram get pppoe_ifname) +IFNAME=$(nvram get ${type}_device) USERNAME=$(nvram get ppp_username) PASSWORD=$(nvram get ppp_passwd) KEEPALIVE=$(nvram get ppp_redialperiod) diff --git a/package/pptp/files/ifup.pptp b/package/pptp/files/ifup.pptp index c8a1a5eee8..fe04d97848 100644 --- a/package/pptp/files/ifup.pptp +++ b/package/pptp/files/ifup.pptp @@ -33,7 +33,7 @@ do_ifup $PPTP_PROTO $type # hack for some buggy ISPs NETMASK=$(nvram get ${type}_netmask) -IFNAME=$(nvram get pptp_ifname) +IFNAME=$(nvram get ${type}_device) [ -z "$NETMASK" -o -z "$IFNAME" ] || ifconfig $IFNAME netmask $NETMASK /usr/sbin/pppd \ diff --git a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig index 27336e112e..72d5b63ac7 100755 --- a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig +++ b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig @@ -88,10 +88,10 @@ END { 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 "# and {pppoe,pptp}ifname=\"" c["wan_ifname"] "\")" 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\"" @@ -99,8 +99,6 @@ END { print "" print "## PPP over Ethernet and PPTP" print "# wan_ifname=\"ppp0\"" - print "# pppoe_ifname=\"" c["wan_ifname"] "\"" - print "# pptp_ifname=\"" c["wan_ifname"] "\"" print "# pptp_server_ip=\"192.168.0.1\"" } ' > /etc/config/network diff --git a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram index 70fbd46624..a561b3965b 100755 --- a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram +++ b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram @@ -107,6 +107,14 @@ case "$(nvram get productid)" in nvram set lan_ifnames="eth1 eth2" nvram set wan_ifname="none" ;; + *) + # wl-500g defaults. these are placed here, because WL-HDD and WL-300g + # might have the same nvram settings. + [ "$(nvram get boardnum)" = "asusX" \ + -a "$(nvram get boardtype)" = "bcm94710dev" ] && { + nvram_default wan_device "eth1" + } + ;; esac # hacks for wap54g hardware @@ -130,21 +138,12 @@ esac nvram_default wl0id 0x4320 } -WAN_PROTO="$(nvram get wan_proto)" -[ "$WAN_PROTO" = "pptp" \ --o "$WAN_PROTO" = "pppoe" ] && { - WAN_IFNAME="$(nvram get wan_ifname)" - [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || { - nvram set wan_ifname=ppp0 - nvram set ${WAN_PROTO}_ifname="$WAN_IFNAME" - } -} - # defaults nvram_default lan_ifname "br0" nvram_default lan_ifnames "$FAILSAFE_ifnames" nvram_default wan_ifname "vlan1" +nvram_default wan_device "vlan1" nvram_default wan_proto "dhcp" nvram_default wl0_ssid OpenWrt @@ -152,6 +151,13 @@ nvram_default wl0_mode ap nvram_default wl0_infra 1 nvram_default wl0_radio 1 +WAN_PROTO="$(nvram get wan_proto)" +WAN_IFNAME="$(nvram get wan_ifname)" +case "$WAN_PROTO" in + pp*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || nvram set wan_ifname=ppp0;; + *) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] && nvram set wan_ifname="$(nvram get wan_device)";; +esac + [ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && { # if default wifi mac, set two higher than the lan mac nvram set il0macaddr=$(nvram get et0macaddr| diff --git a/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig b/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig index 0cafa17402..72d5b63ac7 100755 --- a/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig +++ b/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig @@ -57,9 +57,8 @@ END { # WAP54G if ((nvram["boardnum"] == "2") || \ (nvram["boardnum"] == "1024")) { - c["lan_ifnames"]="eth1 eth2" + c["lan_ifnames"]="eth0 eth1" c["wan_ifname"]="" - c["unused_ifnames"]="eth0" } print "#### VLAN configuration " @@ -79,7 +78,6 @@ END { print "# lan_gateway=\"192.168.1.1\"" print "" - p("unused_ifnames") print "" print "#### WAN configuration" @@ -90,10 +88,10 @@ END { 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 "# and {pppoe,pptp}ifname=\"" c["wan_ifname"] "\")" 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\"" @@ -101,8 +99,6 @@ END { print "" print "## PPP over Ethernet and PPTP" print "# wan_ifname=\"ppp0\"" - print "# pppoe_ifname=\"" c["wan_ifname"] "\"" - print "# pptp_ifname=\"" c["wan_ifname"] "\"" print "# pptp_server_ip=\"192.168.0.1\"" } ' > /etc/config/network -- cgit v1.2.3 From 676c017ecfced2e37aeec176f8aa6b9df90024f3 Mon Sep 17 00:00:00 2001 From: nbd Date: Wed, 5 Apr 2006 02:09:22 +0000 Subject: large init script cleanup and merge of whiterussian changes, new dnsmasq config handling git-svn-id: svn://svn.openwrt.org/openwrt/trunk/openwrt@3588 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/Config.in | 3 - package/Sysconf.in | 31 ---- package/base-files/Makefile | 12 +- package/base-files/default/bin/firstboot | 134 ++++++++++------- package/base-files/default/bin/ipcalc | 32 ++++ package/base-files/default/bin/login | 12 +- package/base-files/default/etc/firewall.user | 29 ---- package/base-files/default/etc/functions.sh | 26 ---- .../base-files/default/etc/hotplug.d/net/10-net | 85 +++++------ package/base-files/default/etc/init.d/S10boot | 9 +- package/base-files/default/etc/init.d/S40network | 16 -- package/base-files/default/etc/init.d/S45firewall | 96 ------------ package/base-files/default/etc/init.d/S50telnet | 2 +- package/base-files/default/etc/init.d/S60cron | 8 +- package/base-files/default/etc/init.d/S98done | 9 ++ package/base-files/default/etc/init.d/S99done | 4 - package/base-files/default/etc/init.d/rcS | 10 +- package/base-files/default/etc/inittab | 1 - package/base-files/default/etc/preinit | 23 +-- package/base-files/default/sbin/halt | 3 - package/base-files/default/sbin/hotplug | 10 +- package/base-files/default/sbin/ifdown | 16 +- package/base-files/default/sbin/ifup | 22 +-- package/base-files/default/sbin/mount_root | 40 +++-- package/base-files/default/usr/lib/common.awk | 66 ++++++++ .../base-files/default/usr/lib/parse-config.awk | 40 +++++ .../default/usr/share/udhcpc/default.script | 37 +++-- package/busybox/config/miscutils/Config.in | 6 + package/busybox/config/networking/Config.in | 4 +- package/busybox/patches/220-awk_bitops.patch | 61 ++++++++ package/busybox/patches/230-passwd_salt.patch | 13 ++ package/busybox/patches/340-lock_util.patch | 167 +++++++++++++++++++++ package/dnsmasq/Makefile | 2 +- package/dnsmasq/files/S50dnsmasq | 30 ---- package/dnsmasq/files/dnsmasq.conf | 8 +- package/dnsmasq/files/dnsmasq.init | 45 ++++++ package/ez-ipupdate/files/ez-ipupdate.hotplug | 6 +- package/iptables/Makefile | 7 + package/iptables/files/firewall.awk | 64 ++++++++ package/iptables/files/firewall.config | 46 ++++++ package/iptables/files/firewall.init | 95 ++++++++++++ package/iptables/files/firewall.user | 31 ++++ package/linux-atm/files/br2684.init | 8 +- package/mtd/mtd.c | 17 ++- package/ntpclient/files/ntpclient.init | 3 +- package/parprouted/files/parprouted.default | 4 +- package/ppp/files/ifup.pppoa | 29 ++-- package/ppp/files/ifup.pppoe | 27 ++-- package/pptp/files/ifup.pptp | 41 ++--- .../base-files/files/ar7-2.4/etc/network.overrides | 28 ---- .../files/aruba-2.6/etc/network.overrides | 26 ---- .../base-files/files/brcm-2.4/etc/init.d/S04nvram | 66 ++++++++ .../files/brcm-2.4/etc/init.d/S05netconfig | 4 +- .../base-files/files/brcm-2.4/etc/init.d/S05nvram | 166 -------------------- .../files/brcm-2.4/etc/network.overrides | 41 ----- .../files/brcm-2.6/etc/init.d/S05netconfig | 4 +- .../files/brcm-2.6/etc/network.overrides | 31 ---- .../base-files/files/x86-2.4/etc/network.overrides | 26 ---- .../base-files/files/x86-2.6/etc/network.overrides | 26 ---- 59 files changed, 1022 insertions(+), 886 deletions(-) delete mode 100644 package/Sysconf.in create mode 100755 package/base-files/default/bin/ipcalc delete mode 100755 package/base-files/default/etc/firewall.user delete mode 100755 package/base-files/default/etc/init.d/S40network delete mode 100755 package/base-files/default/etc/init.d/S45firewall create mode 100755 package/base-files/default/etc/init.d/S98done delete mode 100755 package/base-files/default/etc/init.d/S99done delete mode 100755 package/base-files/default/sbin/halt create mode 100644 package/base-files/default/usr/lib/common.awk create mode 100644 package/base-files/default/usr/lib/parse-config.awk create mode 100644 package/busybox/patches/220-awk_bitops.patch create mode 100644 package/busybox/patches/230-passwd_salt.patch create mode 100644 package/busybox/patches/340-lock_util.patch delete mode 100755 package/dnsmasq/files/S50dnsmasq create mode 100644 package/dnsmasq/files/dnsmasq.init create mode 100644 package/iptables/files/firewall.awk create mode 100644 package/iptables/files/firewall.config create mode 100755 package/iptables/files/firewall.init create mode 100755 package/iptables/files/firewall.user delete mode 100644 target/linux/package/base-files/files/ar7-2.4/etc/network.overrides delete mode 100644 target/linux/package/base-files/files/aruba-2.6/etc/network.overrides create mode 100755 target/linux/package/base-files/files/brcm-2.4/etc/init.d/S04nvram delete mode 100755 target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram delete mode 100644 target/linux/package/base-files/files/brcm-2.4/etc/network.overrides delete mode 100644 target/linux/package/base-files/files/brcm-2.6/etc/network.overrides delete mode 100644 target/linux/package/base-files/files/x86-2.4/etc/network.overrides delete mode 100644 target/linux/package/base-files/files/x86-2.6/etc/network.overrides (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/Config.in b/package/Config.in index 55fdba073a..619578024e 100644 --- a/package/Config.in +++ b/package/Config.in @@ -333,6 +333,3 @@ config BR2_PACKAGE_IMAGEBUILDER endmenu -source "package/Sysconf.in" - - diff --git a/package/Sysconf.in b/package/Sysconf.in deleted file mode 100644 index 6c0cac3cd8..0000000000 --- a/package/Sysconf.in +++ /dev/null @@ -1,31 +0,0 @@ -# - -menu "Runtime Configuration" - choice - bool "Telnet access" - default BR2_SYSCONF_TELNET_FAILSAFE_ONLY - - config BR2_SYSCONF_TELNET_FAILSAFE_ONLY - bool "open, failsafe only" - - config BR2_SYSCONF_TELNET_OPEN - bool "open" - - endchoice - - menu "Failsafe configuration" - - config BR2_SYSCONF_FAILSAFE_IP - string "IP Address" - default "192.168.1.1" - - config BR2_SYSCONF_FAILSAFE_NETMASK - string "Netmask" - default "255.255.255.0" - - config BR2_SYSCONF_FAILSAFE_MAC - string "MAC Address" - default "00:00:BA:DC:0D:ED" - - endmenu -endmenu diff --git a/package/base-files/Makefile b/package/base-files/Makefile index 1fb0c14498..8517dcc685 100644 --- a/package/base-files/Makefile +++ b/package/base-files/Makefile @@ -55,23 +55,25 @@ $(IPKG_BASE): $(CP) ./default/* $(IDIR_BASE) $(SED) 's,$$R,r$(REV),g' $(IDIR_BASE)/etc/banner $(SED) 's,$$S,$(BOARD)-$(KERNEL),g' $(IDIR_BASE)/etc/ipkg.conf - mkdir -p $(IDIR_BASE)/sys - mkdir -p $(IDIR_BASE)/jffs mkdir -p $(IDIR_BASE)/dev + mkdir -p $(IDIR_BASE)/etc/crontabs + mkdir -p $(IDIR_BASE)/jffs + mkdir -p $(IDIR_BASE)/lib + mkdir -p $(IDIR_BASE)/mnt mkdir -p $(IDIR_BASE)/proc mkdir -p $(IDIR_BASE)/tmp - mkdir -p $(IDIR_BASE)/lib mkdir -p $(IDIR_BASE)/usr/lib mkdir -p $(IDIR_BASE)/usr/bin + mkdir -p $(IDIR_BASE)/sys + mkdir -p $(IDIR_BASE)/www ln -sf /tmp/resolv.conf $(IDIR_BASE)/etc/resolv.conf ln -sf /proc/mounts $(IDIR_BASE)/etc/mtab - rm -rf $(IDIR_BASE)/var + rm -f $(IDIR_BASE)/var ln -sf /tmp $(IDIR_BASE)/var -find $(IDIR_BASE) -type d -name CVS | xargs rm -rf -find $(IDIR_BASE) -type d -name .svn | xargs rm -rf -find $(IDIR_BASE) -name '.#*' | xargs rm -f mkdir -p $(IDIR_BASE)/etc - -grep \^BR2_SYSCONF $(TOPDIR)/.config > $(IDIR_BASE)/etc/sysconf $(IPKG_BUILD) $(IDIR_BASE) $(PACKAGE_DIR) $(IPKG_UCLIBC): diff --git a/package/base-files/default/bin/firstboot b/package/base-files/default/bin/firstboot index eff7063b1c..1d9b658b69 100755 --- a/package/base-files/default/bin/firstboot +++ b/package/base-files/default/bin/firstboot @@ -1,62 +1,88 @@ #!/bin/sh # $Id$ -mount | grep squashfs >&- || { - echo "You do not have a squashfs partition; aborting" - echo "(firstboot cannot be run on jffs2 based firmwares)" - return +rom=$(awk '/squashfs/ {print $2}' /proc/mounts) +jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) + +dupe() { # + cd $1 + echo -n "creating directories... " + { + cd $2 + find . -xdev -type d + echo "./dev ./jffs ./mnt ./proc ./tmp ./sys" + # xdev skips mounted directories + cd $1 + } | xargs mkdir -p + echo "done" + + echo -n "setting up symlinks... " + for file in $(cd $2; find . -xdev -type f;); do + case "$file" in + "./rom/note") ;; #nothing + "./etc/config"|\ + "./etc/resolv.conf"|\ + "./usr/lib/ipkg/info") cp -af $2/$file $file;; + *) ln -sf /rom/${file#./*} $file;; + esac + done + for file in $(cd $2; find . -xdev -type l;); do + cp -af $2/${file#./*} $file + done + echo "done" } -[ -f "/tmp/.firstboot" ] && { - echo "firstboot is already running" - return +pivot() { # + mount -o move /proc $1/proc && \ + pivot_root $1 $1$2 && { + mount -o move $2/dev /dev + mount -o move $2/tmp /tmp + } } -touch /tmp/.firstboot -jdev=$(mount | awk '/jffs2/ {print $3}') +mountdp() { # + dev=$1; mnt=$2; shift 2; opt=$* + mount $dev $mnt $opt + dupe $mnt $rom + pivot $mnt /rom +} -if [ -z "$jdev" ]; then - echo -n "Creating jffs2 partition... " - mtd erase OpenWrt >&- 2>&- - mount -t jffs2 /dev/mtdblock/4 /jffs - echo "done" - cd /jffs -else - echo "firstboot has already been run" - echo "jffs2 partition is mounted, only resetting files" - cd $jdev -fi - -exec 2>/dev/null - -mount /dev/mtdblock/2 /rom -o ro - -echo -n "creating directories... " -{ - cd /rom - find . -type d - cd - -} | xargs mkdir -echo "done" - -echo -n "setting up symlinks... " -for file in $(cd /rom; find * -type f; find * -type l;) -do { - case "${file%/*}" in - "usr/lib/ipkg/info"|"etc/config") cp -f /rom/$file $file;; - *) ln -sf /rom/$file $file;; - esac -} done -echo "done" - -touch /tmp/resolv.conf -ln -s /tmp/resolv.conf /etc/resolv.conf - -umount /rom -mount none /jffs/proc -t proc -pivot_root /jffs /jffs/rom -mount none /dev -t devfs -mount none /tmp -t ramfs -umount /rom/proc -umount /rom/tmp -umount /rom/dev +ramoverlay() { + mkdir -p /tmp/root + mountdp /tmp/root /mnt -o bind +} + +[ "${0##*/}" = "firstboot" ] && { + [ -z "$rom" ] && { + echo "You do not have a squashfs partition; aborting" + echo "(firstboot cannot be run on jffs2 based firmwares)" + exit 1 + } + + [ "$1" = "switch2jffs" ] && { + mtd erase OpenWrt + mount -o remount,ro none / # try to avoid fs changing while copying + mount -o bind / /mnt + mount /dev/mtdblock/4 /rom/jffs -t jffs2 + echo -n "copying files ... " + cp -a /mnt/* /rom/jffs + umount /mnt + echo "done" + pivot /rom /mnt + mount -o move /mnt /tmp/root + pivot /jffs /rom + jffs2root --clean + exit 0 + } + + # script run manually + [ \! -z "$jffs" ] && { + echo "firstboot has already been run" + echo "jffs2 partition is mounted, only resetting files" + dupe $jffs $rom + exit 0 + } + + mtd erase OpenWrt + mountdp /dev/mtdblock/4 /jffs -t jffs2 +} diff --git a/package/base-files/default/bin/ipcalc b/package/base-files/default/bin/ipcalc new file mode 100755 index 0000000000..318980e5a2 --- /dev/null +++ b/package/base-files/default/bin/ipcalc @@ -0,0 +1,32 @@ +#!/bin/sh + +awk -f /usr/lib/common.awk -f - $* <limit) end=limit + + print "IP="int2ip(ipaddr) + print "NETMASK="int2ip(netmask) + print "BROADCAST="int2ip(broadcast) + print "NETWORK="int2ip(network) + print "PREFIX="32-bitcount(compl(netmask)) + + # range calculations: + # ipcalc + + if (ARGC > 3) { + print "START="int2ip(start) + print "END="int2ip(end) + } +} +EOF diff --git a/package/base-files/default/bin/login b/package/base-files/default/bin/login index bb065e54a1..8f9281726d 100755 --- a/package/base-files/default/bin/login +++ b/package/base-files/default/bin/login @@ -1,20 +1,16 @@ #!/bin/sh -. /etc/sysconf 2>&- - -[ "$FAILSAFE" != "true" ] && -[ "$BR2_SYSCONF_TELNET_FAILSAFE_ONLY" = "y" ] && +grep '^root:[^!]' /etc/passwd >&- 2>&- +[ "$?" = "0" -a -z "$FAILSAFE" ] && { - grep '^root:[^!]' /etc/passwd >&- 2>&- && - { echo "Login failed." exit 0 - } || { +} || { cat << EOF === IMPORTANT ============================ Use 'passwd' to set your login password this will disable telnet and enable SSH ------------------------------------------ EOF - } } + exec /bin/ash --login diff --git a/package/base-files/default/etc/firewall.user b/package/base-files/default/etc/firewall.user deleted file mode 100755 index 5774f0c64a..0000000000 --- a/package/base-files/default/etc/firewall.user +++ /dev/null @@ -1,29 +0,0 @@ -#!/bin/sh -. /etc/functions.sh -. /etc/network.overrides -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network - -WAN=$(nvram get wan_ifname) -LAN=$(nvram get lan_ifname) - -iptables -F input_rule -iptables -F output_rule -iptables -F forwarding_rule -iptables -t nat -F prerouting_rule -iptables -t nat -F postrouting_rule - -### BIG FAT DISCLAIMER -### The "-i $WAN" literally means packets that came in over the $WAN interface; -### this WILL NOT MATCH packets sent from the LAN to the WAN address. - -### Allow SSH on the WAN interface -# iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j ACCEPT -# iptables -A input_rule -i $WAN -p tcp --dport 22 -j ACCEPT - -### Port forwarding -# iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j DNAT --to 192.168.1.2 -# iptables -A forwarding_rule -i $WAN -p tcp --dport 22 -d 192.168.1.2 -j ACCEPT - -### DMZ (should be placed after port forwarding / accept rules) -# iptables -t nat -A prerouting_rule -i $WAN -j DNAT --to 192.168.1.2 -# iptables -A forwarding_rule -i $WAN -d 192.168.1.2 -j ACCEPT diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh index e7126473f4..526ca52dda 100755 --- a/package/base-files/default/etc/functions.sh +++ b/package/base-files/default/etc/functions.sh @@ -1,6 +1,4 @@ #!/bin/sh -. /etc/nvram.sh - alias debug=${DEBUG:-:} # valid interface? @@ -13,27 +11,3 @@ if_valid () ( hotplug_dev() { env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net } - -bitcount () { - local c=$1 - echo $(( - c=((c>> 1)&0x55555555)+(c&0x55555555), - c=((c>> 2)&0x33333333)+(c&0x33333333), - c=((c>> 4)&0x0f0f0f0f)+(c&0x0f0f0f0f), - c=((c>> 8)&0x00ff00ff)+(c&0x00ff00ff), - c=((c>>16)&0x0000ffff)+(c&0x0000ffff) - )) -} - -valid_netmask () { - return $((-($1)&~$1)) -} - -ip2int () ( - set $(echo $1 | tr '\.' ' ') - echo $(($1<<24|$2<<16|$3<<8|$4)) -) - -int2ip () { - echo $(($1>>24&255)).$(($1>>16&255)).$(($1>>8&255)).$(($1&255)) -} diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index 0f384ec46b..4bb69378ff 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -1,32 +1,28 @@ #!/bin/sh -setup_eth() -{ - for part in $(nvram get unused_ifnames); do - [ "$part" = "$INTERFACE" ] && exit 0 - done - ifconfig "$INTERFACE" up 2>&- >&- -} - find_name() { - pppoa_ifname="atm0" # hack for ppp over atm, which has no ${proto}_ifname - interfaces="lan wan wifi $(nvram get ifnames)" - for ifname in $interfaces; do + for ifname in lan wan wifi ${ifnames}; do IFTYPE="${ifname}" - IFPROTO="$(nvram get ${IFTYPE}_proto)" - IFACE="$(nvram get ${IFTYPE}_ifname)" + eval "IFPROTO=\"\${${IFTYPE}_proto}\"" + eval "IFACE=\"\${${IFTYPE}_ifname}\"" case "$IFPROTO" in ""|none);; static|dhcp) [ "${IFACE}" = "$INTERFACE" ] && return 0 [ "${IFACE%%[0-9]*}" = "br" ] && { - for part in $(nvram get ${IFTYPE}_ifnames); do + eval "ifs=\"\${${IFTYPE}_ifnames}\"" + for part in $ifs; do [ "$part" = "$INTERFACE" ] && return 0 done } ;; + pppoa) + [ "$INTERFACE" = "atm0" \ + -a -x /sbin/ifup.${IFPROTO} ] && return 0 + ;; *) - [ "$(nvram get ${IFTYPE}_device)" = "$INTERFACE" \ + eval "device=\"\${${IFTYPE}_device}\"" + [ "$device" = "$INTERFACE" \ -a -x /sbin/ifup.${IFPROTO} ] && return 0 ;; esac @@ -39,17 +35,18 @@ find_name() do_ifup() { if="$3" - if_proto="$(nvram get ${2}_proto)" + eval "if_proto=\"\${${2}_proto}\"" pidfile=/var/run/${if}.pid [ -f $pidfile ] && $DEBUG kill $(cat $pidfile) case "$1" in static) - ip=$(nvram get ${2}_ipaddr) - ip6=$(nvram get ${2}_ip6addr) - netmask=$(nvram get ${2}_netmask) - gateway=$(nvram get ${2}_gateway) + eval "ip=\"\${${2}_ipaddr}\"" + eval "ip6=\"\${${2}_ip6addr}\"" + eval "netmask=\"\${${2}_netmask}\"" + eval "gateway=\"\${${2}_gateway}\"" + eval "dns=\"\${${2}_dns}\"" $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up [ -n "$ip6" ] && $DEBUG ifconfig $if add $ip6 @@ -58,24 +55,25 @@ do_ifup() { [ -f /tmp/resolv.conf ] || { debug "# --- creating /tmp/resolv.conf ---" - for dns in $(nvram get ${2}_dns); do - echo "nameserver $dns" >> /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) - DHCP_IP=$(nvram get ${2}_ipaddr) - DHCP_NETMASK=$(nvram get ${2}_netmask) + eval "ip=\"\${${2}_ipaddr}\"" + eval "netmask=\"\${${2}_netmask}\"" + eval "hostname=\"\${${2}_hostname}\"" + $DEBUG ifconfig $if $ip ${netmask:+netmask $netmask} broadcast + up - DHCP_ARGS="-i $if ${DHCP_IP:+-r $DHCP_IP} -b -p $pidfile" - DHCP_HOSTNAME=$(nvram get ${2}_hostname) - DHCP_HOSTNAME=${DHCP_HOSTNAME%%.*} - [ -z $DHCP_HOSTNAME ] || DHCP_ARGS="$DHCP_ARGS -H $DHCP_HOSTNAME" - [ "$if_proto" = "pptp" ] && DHCP_ARGS="$DHCP_ARGS -n -q" || DHCP_ARGS="$DHCP_ARGS -R &" - ${DEBUG:-eval} "udhcpc $DHCP_ARGS" + 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 ;; *) @@ -88,25 +86,23 @@ do_ifup() { do_register() { - case "${INTERFACE%%[0-9]*}" in - eth) setup_eth;; - esac - [ -z "$IFTYPE" -o -z "$IFPROTO" ] && { find_name || { case "${INTERFACE%%[0-9]*}" in wds) - for tmp in lan wifi; do - [ -z "$IFPROTO" ] && [ "$(nvram get ${tmp}_ifname)" = "br0" ] && { - IFPROTO="$(nvram get ${tmp}_proto)" + 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 $(nvram get ifnames); do - [ "$(nvram get ${tmp}_proto)" = "pppoa" ] && { + for tmp in lan wan wifi ${ifnames}; do + eval "if_proto=\"\${${2}_proto}\"" + [ "$if_proto" = "pppoa" ] && { do_ifup "pppoa" "$tmp" "$INTERFACE" return 0 } @@ -122,16 +118,16 @@ do_register() case "${INTERFACE%%[0-9]*}" in ppp|atm);; *) - mac=$(nvram get ${IFTYPE}_hwaddr) + eval "mac=\"\${${IFTYPE}_hwaddr}\"" ${mac:+$DEBUG ifconfig $INTERFACE down hw ether $mac} ;; esac - if="$(nvram get ${IFTYPE}_ifname)" + eval "if=\"\${${IFTYPE}_ifname}\"" if [ "${if%%[0-9]}" = "br" ]; then if_valid "$INTERFACE" && { ifconfig "$if" 2>&- >&- || { - stp=$(nvram get ${IFTYPE}_stp) + eval "stp=\"\${${IFTYPE}_stp}\"" $DEBUG brctl addbr "$if" $DEBUG brctl setfd "$if" 0 $DEBUG brctl stp "$if" "${stp:-0}" @@ -151,8 +147,9 @@ do_register() } do_unregister() { - [ -z "$IFTYPE" -o -z "$IFPROTO" ] && find_name - [ -z "$IFTYPE" -o -z "$IFPROTO" ] && return 0 + [ -z "$IFTYPE" -o -z "$IFPROTO" ] && { + find_name || return 0 + } [ "${IFACE%%[0-9]*}" = "br" ] && { if [ "$INTERFACE" != "$IFACE" ]; then diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index 02fddee7ba..0cc519d8eb 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -1,14 +1,9 @@ #!/bin/sh -. /etc/nvram.sh - -[ "$(uname -r|grep -c 2.4)" = "1" ] && { - echo "S" > /proc/jffs2_bbc -} +[ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc vconfig set_name_type VLAN_PLUS_VID_NO_PAD -HOSTNAME=$(nvram get wan_hostname) -HOSTNAME=${HOSTNAME%%.*} +HOSTNAME=${wan_hostname%%.*} echo ${HOSTNAME:=OpenWrt}>/proc/sys/kernel/hostname mkdir -p /var/run diff --git a/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network deleted file mode 100755 index 168fd2979b..0000000000 --- a/package/base-files/default/etc/init.d/S40network +++ /dev/null @@ -1,16 +0,0 @@ -#!/bin/sh -. /etc/functions.sh -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network -case "$1" in - start|restart) -# ifup lan -# ifup wan -# ifup wifi -# wifi up - - for route in $(nvram get static_route); do { - eval "set $(echo $route | sed 's/:/ /g')" - $DEBUG route add -net $1 netmask $2 gw $3 metric $4 dev $5 - } done - ;; -esac diff --git a/package/base-files/default/etc/init.d/S45firewall b/package/base-files/default/etc/init.d/S45firewall deleted file mode 100755 index 8c67d82b18..0000000000 --- a/package/base-files/default/etc/init.d/S45firewall +++ /dev/null @@ -1,96 +0,0 @@ -#!/bin/sh - -## Please make changes in /etc/firewall.user -${FAILSAFE:+exit} - -. /etc/functions.sh -. /etc/network.overrides -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network - -WAN=$(nvram get wan_ifname) -LAN=$(nvram get lan_ifname) - -## CLEAR TABLES -for T in filter nat; do - iptables -t $T -F - iptables -t $T -X -done - -iptables -N input_rule -iptables -N output_rule -iptables -N forwarding_rule - -iptables -t nat -N prerouting_rule -iptables -t nat -N postrouting_rule - -### INPUT -### (connections with the router as destination) - - # base case - iptables -P INPUT DROP - iptables -A INPUT -m state --state INVALID -j DROP - iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT - iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP - - # - # insert accept rule or to jump to new accept-check table here - # - iptables -A INPUT -j input_rule - - # allow - 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 - - # reject (what to do with anything not allowed earlier) - iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset - iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable - -### OUTPUT -### (connections with the router as source) - - # base case - iptables -P OUTPUT DROP - iptables -A OUTPUT -m state --state INVALID -j DROP - iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT - - # - # insert accept rule or to jump to new accept-check table here - # - iptables -A OUTPUT -j output_rule - - # allow - iptables -A OUTPUT -j ACCEPT #allow everything out - - # reject (what to do with anything not allowed earlier) - iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset - iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable - -### FORWARDING -### (connections routed through the router) - - # base case - iptables -P FORWARD DROP - iptables -A FORWARD -m state --state INVALID -j DROP - iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu - iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT - - # - # insert accept rule or to jump to new accept-check table here - # - iptables -A FORWARD -j forwarding_rule - - # allow - iptables -A FORWARD -i br0 -o br0 -j ACCEPT - [ -z "$WAN" ] || iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT - - # reject (what to do with anything not allowed earlier) - # uses the default -P DROP - -### MASQ - iptables -t nat -A PREROUTING -j prerouting_rule - iptables -t nat -A POSTROUTING -j postrouting_rule - [ -z "$WAN" ] || iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE - -## USER RULES -[ -f /etc/firewall.user ] && . /etc/firewall.user diff --git a/package/base-files/default/etc/init.d/S50telnet b/package/base-files/default/etc/init.d/S50telnet index ff5659ed47..fb9687c8aa 100755 --- a/package/base-files/default/etc/init.d/S50telnet +++ b/package/base-files/default/etc/init.d/S50telnet @@ -1,2 +1,2 @@ #!/bin/sh -if awk -F: '/^root:/ && $2 !~ /\!/ {exit 1}' /etc/passwd 2>/dev/null || test $FAILSAFE; then telnetd -l /bin/login; fi +if awk -F: '/^root:/ && $2 !~ /\!/ {exit 1}' /etc/passwd 2>/dev/null; then telnetd -l /bin/login; fi diff --git a/package/base-files/default/etc/init.d/S60cron b/package/base-files/default/etc/init.d/S60cron index 6069b8177e..1752734267 100755 --- a/package/base-files/default/etc/init.d/S60cron +++ b/package/base-files/default/etc/init.d/S60cron @@ -1,6 +1,4 @@ #!/bin/sh -[ -d /etc/crontabs ] || mkdir -p /etc/crontabs -[ -e /var/spool/cron/crontabs ] || { - mkdir -p /var/spool/cron - ln -s /etc/crontabs /var/spool/cron/crontabs -} && crond -c /etc/crontabs +mkdir -p /var/spool/cron +ln -s /etc/crontabs /var/spool/cron/crontabs +crond -c /etc/crontabs diff --git a/package/base-files/default/etc/init.d/S98done b/package/base-files/default/etc/init.d/S98done new file mode 100755 index 0000000000..5d5ab49ce3 --- /dev/null +++ b/package/base-files/default/etc/init.d/S98done @@ -0,0 +1,9 @@ +#!/bin/sh +sysctl -p >&- + +# automagically run firstboot +{ mount|grep "on / type tmpfs" 1>&-; } && { + lock /tmp/.switch2jffs + firstboot switch2jffs + lock -u /tmp/.switch2jffs +} diff --git a/package/base-files/default/etc/init.d/S99done b/package/base-files/default/etc/init.d/S99done deleted file mode 100755 index a260ac3d6f..0000000000 --- a/package/base-files/default/etc/init.d/S99done +++ /dev/null @@ -1,4 +0,0 @@ -#!/bin/sh -# set leds to normal state -[ -f /proc/sys/diag ] && echo "0x00" > /proc/sys/diag -sysctl -p >&- diff --git a/package/base-files/default/etc/init.d/rcS b/package/base-files/default/etc/init.d/rcS index 10079c5932..b38e449781 100755 --- a/package/base-files/default/etc/init.d/rcS +++ b/package/base-files/default/etc/init.d/rcS @@ -1,8 +1,10 @@ #!/bin/sh -. /etc/nvram.sh -syslog_ip=$(nvram get log_ipaddr) -ipcalc -s "$syslog_ip" || syslog_ip="" -syslogd -C 16 ${syslog_ip:+-L -R $syslog_ip} +${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} klogd #${FAILSAFE:+telnetd -l /bin/login; ifup lan; exit} for i in /etc/init.d/S*; do diff --git a/package/base-files/default/etc/inittab b/package/base-files/default/etc/inittab index 5916311e17..39e134cb16 100644 --- a/package/base-files/default/etc/inittab +++ b/package/base-files/default/etc/inittab @@ -1,4 +1,3 @@ ::sysinit:/etc/init.d/rcS -::shutdown:/sbin/halt tts/0::askfirst:/bin/ash --login #tts/1::askfirst:/bin/ash --login diff --git a/package/base-files/default/etc/preinit b/package/base-files/default/etc/preinit index ac9039ca71..5b676ca3ac 100755 --- a/package/base-files/default/etc/preinit +++ b/package/base-files/default/etc/preinit @@ -1,24 +1,11 @@ #!/bin/sh -. /etc/nvram.sh export PATH=/bin:/sbin:/usr/bin:/usr/sbin mount none /proc -t proc -insmod diag -[ -f /proc/sys/diag ] && echo 0x01 > /proc/sys/diag -sleep 1 -if [ -f /proc/sys/reset ] && [ $(cat /proc/sys/reset) = 1 -o "$(nvram get failsafe)" = 1 ]; then - export FAILSAFE=true - [ -x /usr/sbin/nvram -a "$(nvram get boot_wait)" != "on" ] && { - nvram set boot_wait=on - nvram commit - } - while :; do { echo $(((X=(X+1)%8)%2)) > /proc/sys/diag; sleep $((X==0)); } done & -fi -mount_root ${FAILSAFE:+failsafe} - -# automagically run firstboot -[ -z "$FAILSAFE" -a -z "$(nvram get no_root_swap)" ] && { - { mount|grep "on / type jffs2" 1>&-; } || firstboot +[ -f /etc/preinit.arch ] && . /etc/preinit.arch +[ -z "$FAILSAFE" ] || { + echo /bin/true > /proc/sys/kernel/hotplug + telnetd -l /bin/login <> /dev/null 2>&1 } - +mount_root ${FAILSAFE:+failsafe} exec /sbin/init diff --git a/package/base-files/default/sbin/halt b/package/base-files/default/sbin/halt deleted file mode 100755 index 39eed2612e..0000000000 --- a/package/base-files/default/sbin/halt +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/sh -/usr/bin/killall5 -9 -#umount -ar diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug index 3500f75201..106299343a 100755 --- a/package/base-files/default/sbin/hotplug +++ b/package/base-files/default/sbin/hotplug @@ -1,4 +1,7 @@ #!/bin/sh + +# bypass the normal hotplug path for firmware loading +# would otherwise cause problems with drivers like bcm43xx [ "$1" = "firmware" -a "$ACTION" = "add" ] && { [ -f "/lib/firmware/$FIRMWARE" ] && { echo 1 > "/sys$DEVPATH/loading" @@ -8,13 +11,8 @@ exit 0 } -[ -e /tmp/.failsafe ] && { - export FAILSAFE=true -} || { - [ -e /etc/config/network ] && . /etc/config/network -} . /etc/functions.sh -. /etc/network.overrides +. /etc/config/network PATH=/bin:/sbin:/usr/bin:/usr/sbin LOGNAME=root diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index d0120dcbe8..0d85ca8eab 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -1,26 +1,18 @@ #!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh -. /etc/network.overrides -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network +. /etc/config/network debug "### ifdown $type ###" type=$1 -if_proto=$(nvram get ${type}_proto) -if=$(nvram get ${type}_ifname) +eval "if_proto=\"\${${type}_proto}\"" +eval "if=\"\${${type}_ifname}\"" +[ "${if%%[0-9]}" = "ppp" ] && eval "if=\"\${${type}_device}\"" case "$if_proto" in pppoa) hotplug_dev unregister atm0; exit 0 ;; ""|none) exit 0;; esac -[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${type}_device)" - -if [ "${if%%[0-9]}" = "br" ]; then - for sif in $(nvram get ${type}_ifnames); do - hotplug_dev unregister "$sif" - done -fi - hotplug_dev unregister "$if" diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 8ae6416685..a86a7671e8 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -1,32 +1,34 @@ #!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh -. /etc/network.overrides -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network +. /etc/config/network ifdown $1 debug "### ifup $type ###" type=$1 -if_proto=$(nvram get ${type}_proto) -if=$(nvram get ${type}_ifname) +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) - ifconfig nas0 2>&- >&- || { - hotplug_dev register atm0 - exit 0 + # PPPoE over ATM + [ "$if" = "nas0" ] && { + ifconfig nas0 2>&- >&- || { + hotplug_dev register atm0 + exit 0 + } } ;; none|"") exit 0;; esac -[ "${if%%[0-9]*}" = "ppp" ] && if="$(nvram get ${type}_device)" - if [ "${if%%[0-9]}" = "br" ]; then - for sif in $(nvram get ${type}_ifnames); do + eval "ifnames=\"\${${type}_ifnames}\"" + for sif in $ifnames; do hotplug_dev register "$sif" done else diff --git a/package/base-files/default/sbin/mount_root b/package/base-files/default/sbin/mount_root index 427ff0444f..38252e83fe 100755 --- a/package/base-files/default/sbin/mount_root +++ b/package/base-files/default/sbin/mount_root @@ -1,40 +1,34 @@ #!/bin/sh -. /etc/nvram.sh -is_clean() { - grep Broadcom /proc/cpuinfo 2>&- >&- || return 0 - OFFSET="$((0x$(dd if=/dev/mtdblock/1 bs=1 skip=$((0x14)) count=2 2>&- | hexdump | grep 0000000 | cut -d ' ' -f 2) - 1))" - dd if=/dev/mtdblock/1 bs=1 skip=$OFFSET count=1 2>&- | hexdump -v | grep ' 0000' > /dev/null && return 255 || return 0 +is_dirty() { + grep Broadcom /proc/cpuinfo >&- || return 1 + OFFSET="$(($(hexdump -v /dev/mtdblock/1 -s 20 -n 2 -e '"%d"')-1))" + return $(hexdump -v /dev/mtdblock/1 -s $OFFSET -n 1 -e '"%d"') } +size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)&- if [ $? = 0 ] ; then if [ $(cat /proc/mtd | wc -l) = 6 ]; then - echo 5 > /proc/sys/diag - mtd unlock linux mtd erase OpenWrt jffs2root --move else - mtd unlock rootfs mount -o remount,rw /dev/root / fi else - if [ -z "$(nvram get no_root_swap)" ]; then - is_clean || { - mtd erase OpenWrt - mtd unlock linux - jffs2root --clean - } - mtd unlock OpenWrt - mount -t jffs2 /dev/mtdblock/4 /jffs - pivot_root /jffs /jffs/rom - mount none /proc -t proc - mount none /dev -t devfs - umount /rom/proc /rom/dev >&- - fi + . /bin/firstboot + is_dirty + [ $? != 0 ] && { + mount /dev/mtdblock/4 /jffs + pivot /jffs /rom + } || ramoverlay fi fi -mount none /tmp -t tmpfs -o nosuid,nodev,mode=1777,size=50% + +mount none /tmp -t tmpfs -o remount,nosuid,nodev,mode=1777 mkdir -p /dev/pts mount none /dev/pts -t devpts -grep sysfs /proc/filesystems >&- && mount -t sysfs none /sys +mount -t sysfs none /sys 2>&- diff --git a/package/base-files/default/usr/lib/common.awk b/package/base-files/default/usr/lib/common.awk new file mode 100644 index 0000000000..63a8cf23d8 --- /dev/null +++ b/package/base-files/default/usr/lib/common.awk @@ -0,0 +1,66 @@ +function portstr(type, str) { + gsub(/-/, ":", str) + if (insmod_mport != 1) { + print "insmod ipt_multiport >&- 2>&-" + insmod_mport = 1 + } + if (type == "src") return " -m multiport --sports " str + else return " -m multiport --dports " str +} + +function str2ipt(str) { + str2data(str) + _cmd = "" + if (_l["src"] != "") _cmd = _cmd " -s " _l["src"] + if (_l["dest"] != "") _cmd = _cmd " -d " _l["dest"] + if (_l["proto"] != "") { + _cmd = _cmd " -p " _l["proto"] + } + # scripts need to check for proto="" and emit two rules in that case + if ((_l["proto"] == "") || (_l["proto"] == "tcp") || (_l["proto"] == "udp")) { + if (_l["sport"] != "") _cmd = _cmd portstr("src", _l["sport"]) + if (_l["dport"] != "") _cmd = _cmd portstr("dest", _l["dport"]) + } + if (_l["layer7"] != "") { + if (insmod_l7 != 1) { + print "insmod ipt_layer7 >&- 2>&-" + insmod_l7 = 1 + } + _cmd = _cmd " -m layer7 --l7proto " _l["layer7"] + } + return _cmd +} + +function str2data(str) { + delete _l + _n = split(str, _o, "[\t ]") + for (_i = 1; _i <= _n; _i++) { + _n2 = split(_o[_i], _c, "=") + if (_n2 == 2) _l[_c[1]] = _c[2] + } +} + +function bitcount(c) { + c=and(rshift(c, 1),0x55555555)+and(c,0x55555555) + c=and(rshift(c, 2),0x33333333)+and(c,0x33333333) + c=and(rshift(c, 4),0x0f0f0f0f)+and(c,0x0f0f0f0f) + c=and(rshift(c, 8),0x00ff00ff)+and(c,0x00ff00ff) + c=and(rshift(c,16),0x0000ffff)+and(c,0x0000ffff) + return c +} + +function validate_netmask(nm) { + return and(-nm,compl(nm)) +} + +function ip2int(ip) { + for (ret=0,n=split(ip,a,"\."),x=1;x<=n;x++) ret=or(lshift(ret,8),a[x]) + return ret +} + +function int2ip(ip,ret,x) { + ret=and(ip,255) + ip=rshift(ip,8) + for(;x<3;ret=and(ip,255)"."ret,ip=rshift(ip,8),x++); + return ret +} diff --git a/package/base-files/default/usr/lib/parse-config.awk b/package/base-files/default/usr/lib/parse-config.awk new file mode 100644 index 0000000000..bde5c0072b --- /dev/null +++ b/package/base-files/default/usr/lib/parse-config.awk @@ -0,0 +1,40 @@ +{ + line=$0 + gsub(/^[ \t]*/, "") + gsub(/[ \t]*$/, "") +} + +$1 == "@define" { + v[$2] = $3 +} + +$1 == "@ifdef" { + if_open = 1 + if (v[$2] != "") noprint = 0 + else noprint = 1 +} + +$1 == "@ifndef" { + if_open = 1 + if (v[$2] != "") noprint = 1 + else noprint = 0 +} + +$1 == "@else" { + if (noprint == 1) noprint = 0 + else noprint = 1 +} + +($1 !~ /^@/) && (noprint != 1) { + n=split(line "@@", a, /@@/) + for (i=1; i<=n; i++) { + if ((i % 2) == 1) printf a[i] + else printf v[a[i]] + } + print "" +} + +$1 == "@endif" { + if_open = 0 + noprint = 0 +} diff --git a/package/base-files/default/usr/share/udhcpc/default.script b/package/base-files/default/usr/share/udhcpc/default.script index 42d3eaf0c2..4604648e6b 100755 --- a/package/base-files/default/usr/share/udhcpc/default.script +++ b/package/base-files/default/usr/share/udhcpc/default.script @@ -1,18 +1,17 @@ #!/bin/sh [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1 +. /etc/config/network RESOLV_CONF="/tmp/resolv.conf" hotplug_event() { - nvram show 2>&- | grep _proto=dhcp | { - while :; do - read FOO - [ -z "$FOO" ] && break - FOO="${FOO%%_*}" - [ "$(nvram get ${FOO}_ifname)" = "${interface}" ] || continue - env -i ACTION="$1" INTERFACE="${FOO}" PROTO=dhcp /sbin/hotplug iface - done - } + for ifname in lan wan wifi ${ifnames}; do + eval "proto=\"\${${ifname}_proto}\"" + eval "if=\"\${${ifname}_ifname}\"" + [ "$proto" = "dhcp" ] || continue + [ "$if" = "$interface" ] || continue + env -i ACTION="$1" INTERFACE="$ifname" PROTO=dhcp /sbin/hotplug iface + done } case "$1" in @@ -26,22 +25,20 @@ case "$1" in broadcast ${broadcast:-+} if [ -n "$router" ] ; then - - if [ "$router" != "$(route -n | grep '^0.0.0.0' | grep $interface | awk '{ print $2 }')" ] ; then - while route del default gw 0.0.0.0 dev $interface 2>&- ; do - echo "removing old default route" - done - for i in $router ; do - route add default gw $i dev $interface - done - fi + echo "deleting routers" + while route del default gw 0.0.0.0 dev $interface >&- 2>&- ; do :; done + + for i in $router ; do + echo "adding router $i" + route add default gw $i dev $interface + done fi echo -n > $RESOLV_CONF ${domain:+echo search $domain} >> $RESOLV_CONF for i in $dns ; do - echo adding dns $i - echo nameserver $i >> $RESOLV_CONF + echo "adding dns $i" + echo "nameserver $i" >> $RESOLV_CONF done hotplug_event ifup diff --git a/package/busybox/config/miscutils/Config.in b/package/busybox/config/miscutils/Config.in index 1ffb8c6536..404170188e 100644 --- a/package/busybox/config/miscutils/Config.in +++ b/package/busybox/config/miscutils/Config.in @@ -209,6 +209,12 @@ config BUSYBOX_CONFIG_FEATURE_HDPARM_HDIO_GETSET_DMA Enables the 'hdparm -d' option to get/set using_dma flag. This is dangerous stuff, so you should probably say N. +config BUSYBOX_CONFIG_LOCK + bool "lock" + default y + help + Small utility for using locks in scripts + config BUSYBOX_CONFIG_MAKEDEVS bool "makedevs" default n diff --git a/package/busybox/config/networking/Config.in b/package/busybox/config/networking/Config.in index 14e6b5f79a..7e280b76e2 100644 --- a/package/busybox/config/networking/Config.in +++ b/package/busybox/config/networking/Config.in @@ -395,14 +395,14 @@ endif config BUSYBOX_CONFIG_IPCALC bool "ipcalc" - default y + default n help ipcalc takes an IP address and netmask and calculates the resulting broadcast, network, and host range. config BUSYBOX_CONFIG_FEATURE_IPCALC_FANCY bool " Fancy IPCALC, more options, adds 1 kbyte" - default y + default n depends on BUSYBOX_CONFIG_IPCALC help Adds the options hostname, prefix and silent to the output of "ipcalc". diff --git a/package/busybox/patches/220-awk_bitops.patch b/package/busybox/patches/220-awk_bitops.patch new file mode 100644 index 0000000000..2b85729135 --- /dev/null +++ b/package/busybox/patches/220-awk_bitops.patch @@ -0,0 +1,61 @@ +--- busybox-1.00/editors/awk.c.orig 2004-09-24 05:24:27 -04:00 ++++ busybox-1.00/editors/awk.c 2006-03-08 02:16:52 -05:00 +@@ -271,7 +271,8 @@ + /* builtins */ + enum { + B_a2=0, B_ix, B_ma, B_sp, B_ss, B_ti, B_lo, B_up, +- B_ge, B_gs, B_su ++ B_ge, B_gs, B_su, ++ B_an, B_co, B_ls, B_or, B_rs, B_xo, + }; + + /* tokens and their corresponding info values */ +@@ -311,6 +312,8 @@ + "\5while" NTC + "\4else" NTC + ++ "\3and" "\5compl" "\6lshift" "\2or" ++ "\6rshift" "\3xor" + "\5close" "\6system" "\6fflush" "\5atan2" /* BUILTIN */ + "\3cos" "\3exp" "\3int" "\3log" + "\4rand" "\3sin" "\4sqrt" "\5srand" +@@ -364,6 +367,8 @@ + ST_WHILE, + 0, + ++ OC_B|B_an|P(0x83), OC_B|B_co|P(0x41), OC_B|B_ls|P(0x83), OC_B|B_or|P(0x83), ++ OC_B|B_rs|P(0x83), OC_B|B_xo|P(0x83), + OC_FBLTIN|Sx|F_cl, OC_FBLTIN|Sx|F_sy, OC_FBLTIN|Sx|F_ff, OC_B|B_a2|P(0x83), + OC_FBLTIN|Nx|F_co, OC_FBLTIN|Nx|F_ex, OC_FBLTIN|Nx|F_in, OC_FBLTIN|Nx|F_lg, + OC_FBLTIN|F_rn, OC_FBLTIN|Nx|F_si, OC_FBLTIN|Nx|F_sq, OC_FBLTIN|Nx|F_sr, +@@ -1942,6 +1947,30 @@ + strncpy(s, as[0]+i, n); + s[n] = '\0'; + setvar_p(res, s); ++ break; ++ ++ case B_an: ++ setvar_i(res, (long)getvar_i(av[0]) & (long)getvar_i(av[1])); ++ break; ++ ++ case B_co: ++ setvar_i(res, ~(long)getvar_i(av[0])); ++ break; ++ ++ case B_ls: ++ setvar_i(res, (long)getvar_i(av[0]) << (long)getvar_i(av[1])); ++ break; ++ ++ case B_or: ++ setvar_i(res, (long)getvar_i(av[0]) | (long)getvar_i(av[1])); ++ break; ++ ++ case B_rs: ++ setvar_i(res, (long)((unsigned long)getvar_i(av[0]) >> (unsigned long)getvar_i(av[1]))); ++ break; ++ ++ case B_xo: ++ setvar_i(res, (long)getvar_i(av[0]) ^ (long)getvar_i(av[1])); + break; + + case B_lo: diff --git a/package/busybox/patches/230-passwd_salt.patch b/package/busybox/patches/230-passwd_salt.patch new file mode 100644 index 0000000000..0322a98439 --- /dev/null +++ b/package/busybox/patches/230-passwd_salt.patch @@ -0,0 +1,13 @@ +--- busybox-1.00/loginutils/passwd.c 2006-03-26 06:07:37 -05:00 ++++ busybox-1.00/loginutils/passwd.c 2006-03-26 06:09:03 -05:00 +@@ -386,7 +386,9 @@ + bzero(orig, sizeof(orig)); + + if (algo == 1) { +- cp = pw_encrypt(pass, "$1$"); ++ char salt[6]="$1$\0\0\0"; ++ memcpy(salt+3,crypt_make_salt(),3); ++ cp = pw_encrypt(pass, salt); + } else + cp = pw_encrypt(pass, crypt_make_salt()); + bzero(pass, sizeof pass); diff --git a/package/busybox/patches/340-lock_util.patch b/package/busybox/patches/340-lock_util.patch new file mode 100644 index 0000000000..f5c0c2e89e --- /dev/null +++ b/package/busybox/patches/340-lock_util.patch @@ -0,0 +1,167 @@ +diff -urN busybox.old/include/applets.h busybox.dev/include/applets.h +--- busybox.old/include/applets.h 2006-04-05 01:06:29.000000000 +0200 ++++ busybox.dev/include/applets.h 2006-04-05 01:19:09.000000000 +0200 +@@ -167,6 +167,7 @@ + USE_LN(APPLET(ln, ln_main, _BB_DIR_BIN, _BB_SUID_NEVER)) + USE_LOADFONT(APPLET(loadfont, loadfont_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) + USE_LOADKMAP(APPLET(loadkmap, loadkmap_main, _BB_DIR_SBIN, _BB_SUID_NEVER)) ++USE_LOCK(APPLET_NOUSAGE(lock, lock_main, _BB_DIR_BIN, _BB_SUID_NEVER)) + USE_LOGGER(APPLET(logger, logger_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) + USE_LOGIN(APPLET(login, login_main, _BB_DIR_BIN, _BB_SUID_ALWAYS)) + USE_LOGNAME(APPLET(logname, logname_main, _BB_DIR_USR_BIN, _BB_SUID_NEVER)) +diff -urN busybox.old/miscutils/Config.in busybox.dev/miscutils/Config.in +--- busybox.old/miscutils/Config.in 2006-03-22 22:16:24.000000000 +0100 ++++ busybox.dev/miscutils/Config.in 2006-04-05 01:07:12.000000000 +0200 +@@ -209,6 +209,12 @@ + Enables the 'hdparm -d' option to get/set using_dma flag. + This is dangerous stuff, so you should probably say N. + ++config CONFIG_LOCK ++ bool "lock" ++ default y ++ help ++ Small utility for using locks in scripts ++ + config CONFIG_MAKEDEVS + bool "makedevs" + default n +diff -urN busybox.old/miscutils/Makefile.in busybox.dev/miscutils/Makefile.in +--- busybox.old/miscutils/Makefile.in 2006-03-22 22:16:24.000000000 +0100 ++++ busybox.dev/miscutils/Makefile.in 2006-04-05 01:10:50.000000000 +0200 +@@ -20,6 +20,7 @@ + MISCUTILS-$(CONFIG_EJECT) += eject.o + MISCUTILS-$(CONFIG_HDPARM) += hdparm.o + MISCUTILS-$(CONFIG_LAST) += last.o ++MISCUTILS-$(CONFIG_LOCK) += lock.o + MISCUTILS-${CONFIG_LESS} += less.o + MISCUTILS-$(CONFIG_MAKEDEVS) += makedevs.o + MISCUTILS-$(CONFIG_MOUNTPOINT) += mountpoint.o +diff -urN busybox.old/miscutils/lock.c busybox.dev/miscutils/lock.c +--- busybox.old/miscutils/lock.c 1970-01-01 01:00:00.000000000 +0100 ++++ busybox.dev/miscutils/lock.c 2006-04-05 01:07:12.000000000 +0200 +@@ -0,0 +1,125 @@ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "busybox.h" ++ ++static int unlock = 0; ++static int shared = 0; ++static int waitonly = 0; ++static int fd; ++static char *file; ++ ++static void usage(char *name) ++{ ++ fprintf(stderr, "Usage: %s [-suw] \n" ++ " -s Use shared locking\n" ++ " -u Unlock\n" ++ " -w Wait for the lock to become free, don't acquire lock\n" ++ "\n", name); ++ exit(1); ++} ++ ++static void exit_unlock(int sig) ++{ ++ flock(fd, LOCK_UN); ++ unlink(file); ++ exit(0); ++} ++ ++static int do_unlock(void) ++{ ++ FILE *f; ++ int i; ++ ++ f = fopen(file, "r"); ++ fscanf(f, "%d", &i); ++ if (i > 0) ++ kill(i, SIGTERM); ++ fclose(f); ++ ++ return 0; ++} ++ ++static int do_lock(void) ++{ ++ int pid; ++ char pidstr[8]; ++ ++ if ((fd = open(file, O_RDWR | O_CREAT, 0700)) < 0) { ++ fprintf(stderr, "Can't open %s\n", file); ++ return 1; ++ } ++ ++ if (flock(fd, (shared ? LOCK_SH : LOCK_EX)) < 0) { ++ fprintf(stderr, "Can't lock %s\n", file); ++ return 1; ++ } ++ ++ pid = fork(); ++ ++ if (pid < 0) ++ return -1; ++ ++ if (pid == 0) { ++ signal(SIGKILL, exit_unlock); ++ signal(SIGTERM, exit_unlock); ++ signal(SIGINT, exit_unlock); ++ if (waitonly) ++ exit_unlock(0); ++ else ++ while (1) ++ sleep(1); ++ } else { ++ if (!waitonly) { ++ lseek(fd, 0, SEEK_SET); ++ ftruncate(fd, 0); ++ sprintf(pidstr, "%d\n", pid); ++ write(fd, pidstr, strlen(pidstr)); ++ close(fd); ++ } ++ ++ return 0; ++ } ++} ++ ++#ifndef CONFIG_LOCK ++int main(int argc, char **argv) ++#else ++int lock_main(int argc, char **argv) ++#endif ++{ ++ char **args = &argv[1]; ++ int c = argc - 1; ++ ++ while ((*args != NULL) && (*args)[0] == '-') { ++ char *ch = *args; ++ while (*(++ch) > 0) { ++ switch(*ch) { ++ case 'w': ++ waitonly = 1; ++ break; ++ case 's': ++ shared = 1; ++ break; ++ case 'u': ++ unlock = 1; ++ break; ++ } ++ } ++ c--; ++ args++; ++ } ++ ++ if (c != 1) ++ usage(argv[0]); ++ ++ file = *args; ++ if (unlock) ++ return do_unlock(); ++ else ++ return do_lock(); ++} diff --git a/package/dnsmasq/Makefile b/package/dnsmasq/Makefile index 393f0f014d..88bd9f21b9 100644 --- a/package/dnsmasq/Makefile +++ b/package/dnsmasq/Makefile @@ -31,6 +31,6 @@ $(IPKG_DNSMASQ): $(STRIP) $(IDIR_DNSMASQ)/usr/sbin/* install -d -m0755 $(IDIR_DNSMASQ)/etc/init.d/ install -m0644 ./files/dnsmasq.conf $(IDIR_DNSMASQ)/etc/dnsmasq.conf - install -m0755 ./files/S50dnsmasq $(IDIR_DNSMASQ)/etc/init.d/S50dnsmasq + install -m0755 ./files/dnsmasq.init $(IDIR_DNSMASQ)/etc/init.d/S50dnsmasq $(IPKG_BUILD) $(IDIR_DNSMASQ) $(PACKAGE_DIR) diff --git a/package/dnsmasq/files/S50dnsmasq b/package/dnsmasq/files/S50dnsmasq deleted file mode 100755 index 17e331fac8..0000000000 --- a/package/dnsmasq/files/S50dnsmasq +++ /dev/null @@ -1,30 +0,0 @@ -#!/bin/sh -. /etc/functions.sh -. /etc/network.overrides -[ "$FAILSAFE" != "true" -a -e /etc/config/network ] && . /etc/config/network - -# interface to use for DHCP -iface=lan - -ifname=$(nvram get ${iface}_ifname) -ipaddr=$(nvram get ${iface}_ipaddr) -netmask=$(nvram get ${iface}_netmask) - -# check for existing DHCP server -udhcpc -n -q -R -s /bin/true -i $ifname >&- || { - - ipaddr=$(ip2int $ipaddr) - netmask=$(ip2int ${netmask:-255.255.255.0}) - network=$((ipaddr&netmask)) - - start=$(nvram get dhcp_start) - start=$((network+${start:-100})) - end=$(nvram get dhcp_num) - end=$((start+${end:-150})) - - wanproto=$(nvram get wan_proto) - [ -z "$wanproto" -o "$wanproto" = "none" ] || wanif=$(nvram get wan_ifname) - - args="-K -F $(int2ip $start),$(int2ip $end),$(int2ip $netmask),12h ${wanif:+-I ${wanif} }" -} -dnsmasq ${args} diff --git a/package/dnsmasq/files/dnsmasq.conf b/package/dnsmasq/files/dnsmasq.conf index d4a9f082ca..7aed3a3da4 100644 --- a/package/dnsmasq/files/dnsmasq.conf +++ b/package/dnsmasq/files/dnsmasq.conf @@ -9,9 +9,15 @@ local=/lan/ domain=lan expand-hosts +@ifdef dhcp_enable +dhcp-range=@@start@@,@@end@@,@@netmask@@,@@lease@@ +@endif +@ifdef wan_ifname +except-interface=@@wan_ifname@@ +@endif + # enable dhcp (start,end,netmask,leasetime) dhcp-authoritative -#dhcp-range=192.168.1.100,192.168.1.250,255.255.255.0,12h dhcp-leasefile=/tmp/dhcp.leases # use /etc/ethers for static hosts; same format as --dhcp-host diff --git a/package/dnsmasq/files/dnsmasq.init b/package/dnsmasq/files/dnsmasq.init new file mode 100644 index 0000000000..17ef43c3d5 --- /dev/null +++ b/package/dnsmasq/files/dnsmasq.init @@ -0,0 +1,45 @@ +#!/bin/sh +. /etc/config/network + +# The following is to automatically configure the DHCP settings +# based on config settings. Feel free to replace all this crap +# with a simple "dnsmasq" and manage everything via the +# /etc/dnsmasq.conf config file + +[ -f /etc/dnsmasq.conf ] || exit + +args="" +iface=lan +eval "ifname=\${${iface}_ifname}" + +dhcp_enable="${dhcp_enable:-1}" +dhcp_start="${dhcp_start:-100}" +dhcp_num="${dhcp_num:-50}" +dhcp_lease="${dhcp_lease:-12h}" + +# if dhcp_enable is unset and there is a dhcp server on the network already, default to dhcp_enable=0 +[ -z "$dhcp_enable" ] && udhcpc -n -q -R -s /bin/true -i $ifname >&- && dhcp_enable="${dhcp_enable:-0}" + +# dhcp_enable=0 disables the dhcp server +( + [ -z "$dhcp_enable" -o "$dhcp_enable" -eq 1 ] && { + # no existing DHCP server? + + # calculate settings + eval "ipaddr=\${${iface}_ipaddr}" + eval "netmask=\${${iface}_netmask}" + eval $(ipcalc $ipaddr $netmask ${dhcp_start:-100} ${dhcp_num:-150}) + + # and pass the args via config parser defines + echo "@define dhcp_enable 1" + echo "@define netmask $NETMASK" + echo "@define start $START" + echo "@define end $END" + echo "@define lease ${dhcp_lease:-12h}" + } + + # ignore requests from wan interface + [ -z "$wan_proto" -o "$wan_proto" = "none" ] || echo "@define wan_ifname $wan_ifname" + + cat /etc/dnsmasq.conf +) | awk -f /usr/lib/parse-config.awk | dnsmasq -C /proc/self/fd/0 diff --git a/package/ez-ipupdate/files/ez-ipupdate.hotplug b/package/ez-ipupdate/files/ez-ipupdate.hotplug index eb7ab326c4..c305458b1a 100644 --- a/package/ez-ipupdate/files/ez-ipupdate.hotplug +++ b/package/ez-ipupdate/files/ez-ipupdate.hotplug @@ -1,10 +1,10 @@ -. /etc/functions.sh NAME=ez-ipupdate CONFIG=/etc/$NAME.conf COMMAND=/usr/sbin/$NAME + [ "$ACTION" = "ifup" -a "$INTERFACE" = "wan" ] && { [ -x $COMMAND ] && [ -r $CONFIG ] && { - IFNAME=$(nvram get ${INTERFACE}_ifname) - $COMMAND -c $CONFIG -i $IFNAME 2>&1 | logger -t $NAME + eval "ifname=\"\${${INTERFACE}_ifname}\"" + $COMMAND -c $CONFIG -i $ifname 2>&1 | logger -t $NAME } & } diff --git a/package/iptables/Makefile b/package/iptables/Makefile index 298a9a9e0f..f16ac8be48 100644 --- a/package/iptables/Makefile +++ b/package/iptables/Makefile @@ -72,6 +72,13 @@ $(PKG_BUILD_DIR)/.built: touch $@ $(IPKG_IPTABLES): + install -d -m0755 $(IDIR_IPTABLES)/etc/config + install -m0644 ./files/firewall.config $(IDIR_IPTABLES)/etc/config/firewall + install -d -m0755 $(IDIR_IPTABLES)/etc/init.d + install -m0755 ./files/firewall.init $(IDIR_IPTABLES)/etc/init.d/S45firewall + install -m0755 ./files/firewall.user $(IDIR_IPTABLES)/etc/ + install -d -m0755 $(IDIR_IPTABLES)/usr/lib + install -m0644 ./files/firewall.awk $(IDIR_IPTABLES)/usr/lib install -d -m0755 $(IDIR_IPTABLES)/usr/sbin $(CP) $(PKG_INSTALL_DIR)/usr/sbin/iptables $(IDIR_IPTABLES)/usr/sbin/ install -d -m0755 $(IDIR_IPTABLES)/usr/lib/iptables diff --git a/package/iptables/files/firewall.awk b/package/iptables/files/firewall.awk new file mode 100644 index 0000000000..1b63f83862 --- /dev/null +++ b/package/iptables/files/firewall.awk @@ -0,0 +1,64 @@ +BEGIN { + print "proto=\"$wan_proto\"" + print "[ -z \"$proto\" -o \"$proto\" = \"none\" ] && exit" + print "ifname=\"$wan_ifname\"" + print "[ -z \"$ifname\" ] && exit" + print "" + print "iptables -X input_$ifname 2>&- >&-" + print "iptables -N input_$ifname" + print "iptables -X forward_$ifname 2>&- >&-" + print "iptables -N forward_$ifname" + print "iptables -t nat -X prerouting_$ifname 2>&- >&-" + print "iptables -t nat -N prerouting_$ifname" + print "" + print "iptables -A input_rule -i \"$ifname\" -j input_$ifname" + print "iptables -A forwarding_rule -i \"$ifname\" -j forward_$ifname" + print "iptables -t nat -A prerouting_rule -i \"$ifname\" -j prerouting_$ifname" + print "" + FS=":" +} + +($1 == "accept") || ($1 == "drop") || ($1 == "forward") { + delete _opt + str2data($2) + if ((_l["proto"] == "") && (_l["sport"] _l["dport"] != "")) { + _opt[0] = " -p tcp" + _opt[1] = " -p udp" + } else { + _opt[0] = "" + } +} + +($1 == "accept") { + target = " -j ACCEPT" + for (o in _opt) { + print "iptables -t nat -A prerouting_$ifname" _opt[o] str2ipt($2) target + print "iptables -A input_$ifname " _opt[o] str2ipt($2) target + print "" + } +} + +($1 == "drop") { + for (o in _opt) { + print "iptables -t nat -A prerouting_$ifname" _opt[o] str2ipt($2) " -j DROP" + print "" + } +} + +($1 == "forward") { + target = " -j DNAT --to " $3 + fwopts = "" + if ($4 != "") { + if ((_l["proto"] == "tcp") || (_l["proto"] == "udp") || (_l["proto"] == "")) { + if (_l["proto"] != "") fwopts = " -p " _l["proto"] + fwopts = fwopts " --dport " $4 + target = target ":" $4 + } + else fwopts = "" + } + for (o in _opt) { + print "iptables -t nat -A prerouting_$ifname" _opt[o] str2ipt($2) target + print "iptables -A forward_$ifname " _opt[o] " -d " $3 fwopts " -j ACCEPT" + print "" + } +} diff --git a/package/iptables/files/firewall.config b/package/iptables/files/firewall.config new file mode 100644 index 0000000000..7edd4ba4e4 --- /dev/null +++ b/package/iptables/files/firewall.config @@ -0,0 +1,46 @@ +# RULE SYNTAX: +# +# forward::[:] +# - forwards all packets matched by to , +# optionally changing the port to +# +# accept: +# - accepts all traffic matched by +# +# drop: +# - drops all traffic matched by +# +# +# MATCHING OPTIONS: +# +# src= +# - match the source ip +# +# dest= +# - match the destination ip +# +# proto= +# - match the protocol by name or number +# +# sport= +# - match the source port(s), see below for syntax +# +# dport= +# - match the destination port(s), see below for syntax +# +# +# +# PORT SYNTAX: +# +# You can enter an arbitrary list of ports and port ranges in the following format: +# - 22,53,993,1000-1024 +# +# If you don't set the protocol to tcp or udp, it will apply to both +# +# +# +# EXAMPLES: +# +# drop:dport=22 src=1.3.3.7 +# accept:proto=tcp dport=22 +# forward:dport=60168:192.168.1.2:60169 diff --git a/package/iptables/files/firewall.init b/package/iptables/files/firewall.init new file mode 100755 index 0000000000..3804d044f8 --- /dev/null +++ b/package/iptables/files/firewall.init @@ -0,0 +1,95 @@ +#!/bin/sh + +## Please make changes in /etc/firewall.user + +. /etc/config/network +WAN="$wan_ifname" +LAN="$lan_ifname" + +## CLEAR TABLES +for T in filter nat; do + iptables -t $T -F + iptables -t $T -X +done + +iptables -N input_rule +iptables -N output_rule +iptables -N forwarding_rule + +iptables -t nat -N prerouting_rule +iptables -t nat -N postrouting_rule + +### INPUT +### (connections with the router as destination) + + # base case + iptables -P INPUT DROP + iptables -A INPUT -m state --state INVALID -j DROP + iptables -A INPUT -m state --state RELATED,ESTABLISHED -j ACCEPT + iptables -A INPUT -p tcp --tcp-flags SYN SYN --tcp-option \! 2 -j DROP + + # + # insert accept rule or to jump to new accept-check table here + # + iptables -A INPUT -j input_rule + + # allow + [ -z "$WAN" ] || iptables -A INPUT -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 + + # reject (what to do with anything not allowed earlier) + iptables -A INPUT -p tcp -j REJECT --reject-with tcp-reset + iptables -A INPUT -j REJECT --reject-with icmp-port-unreachable + +### OUTPUT +### (connections with the router as source) + + # base case + iptables -P OUTPUT DROP + iptables -A OUTPUT -m state --state INVALID -j DROP + iptables -A OUTPUT -m state --state RELATED,ESTABLISHED -j ACCEPT + + # + # insert accept rule or to jump to new accept-check table here + # + iptables -A OUTPUT -j output_rule + + # allow + iptables -A OUTPUT -j ACCEPT #allow everything out + + # reject (what to do with anything not allowed earlier) + iptables -A OUTPUT -p tcp -j REJECT --reject-with tcp-reset + iptables -A OUTPUT -j REJECT --reject-with icmp-port-unreachable + +### FORWARDING +### (connections routed through the router) + + # base case + iptables -P FORWARD DROP + iptables -A FORWARD -m state --state INVALID -j DROP + iptables -A FORWARD -p tcp --tcp-flags SYN,RST SYN -j TCPMSS --clamp-mss-to-pmtu + iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT + + # + # insert accept rule or to jump to new accept-check table here + # + iptables -A FORWARD -j forwarding_rule + + # allow + iptables -A FORWARD -i br0 -o br0 -j ACCEPT + [ -z "$WAN" ] || iptables -A FORWARD -i $LAN -o $WAN -j ACCEPT + + # reject (what to do with anything not allowed earlier) + # uses the default -P DROP + +### MASQ + iptables -t nat -A PREROUTING -j prerouting_rule + iptables -t nat -A POSTROUTING -j postrouting_rule + [ -z "$WAN" ] || iptables -t nat -A POSTROUTING -o $WAN -j MASQUERADE + +## USER RULES +[ -f /etc/firewall.user ] && . /etc/firewall.user +[ -n "$WAN" -a -e /etc/config/firewall ] && { + awk -f /usr/lib/common.awk -f /usr/lib/firewall.awk /etc/config/firewall | ash +} diff --git a/package/iptables/files/firewall.user b/package/iptables/files/firewall.user new file mode 100755 index 0000000000..f13f50bf66 --- /dev/null +++ b/package/iptables/files/firewall.user @@ -0,0 +1,31 @@ +#!/bin/sh +. /etc/config/network + +WAN="$wan_ifname" +LAN="$lan_ifname" + +iptables -F input_rule +iptables -F output_rule +iptables -F forwarding_rule +iptables -t nat -F prerouting_rule +iptables -t nat -F postrouting_rule + +### BIG FAT DISCLAIMER +## The "-i $WAN" is used to match packets that come in via the $WAN interface. +## it WILL NOT MATCH packets sent from the $WAN ip address -- you won't be able +## to see the effects from within the LAN. + +### Open port to WAN +## -- This allows port 22 to be answered by (dropbear on) the router +# iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 22 -j ACCEPT +# iptables -A input_rule -i $WAN -p tcp --dport 22 -j ACCEPT + +### Port forwarding +## -- This forwards port 8080 on the WAN to port 80 on 192.168.1.2 +# iptables -t nat -A prerouting_rule -i $WAN -p tcp --dport 8080 -j DNAT --to 192.168.1.2:80 +# iptables -A forwarding_rule -i $WAN -p tcp --dport 80 -d 192.168.1.2 -j ACCEPT + +### DMZ +## -- Connections to ports not handled above will be forwarded to 192.168.1.2 +# iptables -t nat -A prerouting_rule -i $WAN -j DNAT --to 192.168.1.2 +# iptables -A forwarding_rule -i $WAN -d 192.168.1.2 -j ACCEPT diff --git a/package/linux-atm/files/br2684.init b/package/linux-atm/files/br2684.init index 88f40e76b6..242e7e5152 100644 --- a/package/linux-atm/files/br2684.init +++ b/package/linux-atm/files/br2684.init @@ -1,16 +1,14 @@ [ "${INTERFACE%%[0-9]*}" = "atm" ] && { case "$ACTION" in register) - [ "$(nvram get pppoe_atm)" = 1 ] && { - VPI=$(nvram get atm_vpi) - VCI=$(nvram get atm_vci) - case "$(nvram get atm_encaps)" in + [ "$pppoe_atm" = 1 ] && { + case "$atm_encaps" in 0|vc) ENCAPS=0 ;; 1|llc) ENCAPS=1 ;; *) ENCAPS=0 ;; esac insmod br2684 2>&- >&- - br2684ctl -c0 -e${ENCAPS} -a${VPI:-8}.${VCI:-35} & + br2684ctl -c0 -e${ENCAPS} -a${atm_vpi:-8}.${atm_vci:-35} & } ;; unregister) diff --git a/package/mtd/mtd.c b/package/mtd/mtd.c index 78d38fb6a9..23e99160a1 100644 --- a/package/mtd/mtd.c +++ b/package/mtd/mtd.c @@ -96,7 +96,7 @@ image_check_bcom(int imagefd, const char *mtd) } /* check if image fits to mtd device */ - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -113,6 +113,7 @@ image_check_bcom(int imagefd, const char *mtd) return 0; } + close(fd); return 1; } @@ -148,7 +149,7 @@ int mtd_check(char *mtd) struct mtd_info_user mtdInfo; int fd; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); return 0; @@ -171,7 +172,7 @@ mtd_unlock(const char *mtd) struct mtd_info_user mtdInfo; struct erase_info_user mtdLockInfo; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -222,7 +223,7 @@ mtd_erase(const char *mtd) struct mtd_info_user mtdInfo; struct erase_info_user mtdEraseInfo; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -260,8 +261,9 @@ mtd_write(int imagefd, const char *mtd, int quiet) size_t r, w, e; struct mtd_info_user mtdInfo; struct erase_info_user mtdEraseInfo; + int ret = 0; - fd = mtd_open(mtd, O_RDWR); + fd = mtd_open(mtd, O_RDWR | O_SYNC); if(fd < 0) { fprintf(stderr, "Could not open mtd device: %s\n", mtd); exit(1); @@ -318,7 +320,8 @@ mtd_write(int imagefd, const char *mtd, int quiet) } if (!quiet) fprintf(stderr, "\b\b\b\b"); - + + close(fd); return 0; } @@ -463,6 +466,8 @@ int main (int argc, char **argv) break; } + sync(); + if (boot) kill(1, 15); // send SIGTERM to init for reboot diff --git a/package/ntpclient/files/ntpclient.init b/package/ntpclient/files/ntpclient.init index c8505c5cad..a8944c60eb 100644 --- a/package/ntpclient/files/ntpclient.init +++ b/package/ntpclient/files/ntpclient.init @@ -1,9 +1,8 @@ #!/bin/sh -server=$(nvram get ntp_server) case "$ACTION" in ifup) ps x | grep '[n]tpclient' >&- || { - route -n 2>&- | grep '^0.0.0.0' >&- && /usr/sbin/ntpclient -c 1 -s -h ${server:-pool.ntp.org} & + route -n 2>&- | grep '^0.0.0.0' >&- && /usr/sbin/ntpclient -c 1 -s -h ${ntp_server:-pool.ntp.org} & } ;; ifdown) diff --git a/package/parprouted/files/parprouted.default b/package/parprouted/files/parprouted.default index 17169c4b37..7128a56a74 100755 --- a/package/parprouted/files/parprouted.default +++ b/package/parprouted/files/parprouted.default @@ -1,3 +1 @@ -LAN_IF=$(nvram get lan_ifname) -WIFI_IF=$(nvram get wifi_ifname) -OPTIONS="$LAN_IF $WIFI_IF" +OPTIONS="$lan_ifname $wifi_ifname" diff --git a/package/ppp/files/ifup.pppoa b/package/ppp/files/ifup.pppoa index baea25ebf2..277266c0f5 100644 --- a/package/ppp/files/ifup.pppoa +++ b/package/ppp/files/ifup.pppoa @@ -1,11 +1,10 @@ #!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } -. /etc/functions.sh -. /etc/network.overrides -[ -e /etc/config/network ] && . /etc/config/network +. /etc/config/network type=$1 -[ "$(nvram get ${type}_proto)" = "pppoa" ] || { +eval "proto=\"\${${type}_proto}\"" +[ "$proto" = "pppoa" ] || { echo "$0: ${type}_proto isn't pppoa" exit } @@ -14,32 +13,24 @@ for module in slhc ppp_generic pppoatm; do /sbin/insmod $module 2>&- >&- done -VPI=$(nvram get atm_vpi) -VCI=$(nvram get atm_vci) -USERNAME=$(nvram get ppp_username) -PASSWORD=$(nvram get ppp_passwd) -KEEPALIVE=$(nvram get ppp_redialperiod) -KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 1 lcp-echo-failure $KEEPALIVE} -DEMAND=$(nvram get ppp_demand) -case "$DEMAND" in +KEEPALIVE=${ppp_redialperiod:+lcp-echo-interval $ppp_redialperiod lcp-echo-failure 5} +case "$ppp_demand" in on|1|enabled) - DEMAND=$(nvram get ppp_idletime) - DEMAND=${IDLETIME:+demand idle $IDLETIME} + DEMAND=${ppp_idletime:+demand idle $ppp_idletime} [ -f /etc/ppp/filter ] && DEMAND=${DEMAND:+precompiled-active-filter /etc/ppp/filter $DEMAND} ;; *) DEMAND="persist";; esac -MTU=$(nvram get ppp_mtu) -MTU=${MTU:-1500} +MTU=${ppp_mtu:-1500} /usr/sbin/pppd \ - plugin pppoatm.so ${VPI:-8}.${VCI:-35} \ + plugin pppoatm.so ${atm_vpi:-8}.${atm_vci:-35} \ usepeerdns \ defaultroute \ linkname $type \ ipparam $type \ - user "$USERNAME" \ - password "$PASSWORD" \ + user "$ppp_username" \ + password "$ppp_passwd" \ mtu $MTU mru $MTU \ $DEMAND \ $KEEPALIVE diff --git a/package/ppp/files/ifup.pppoe b/package/ppp/files/ifup.pppoe index 1f9cd739c3..0f3c14ed0d 100644 --- a/package/ppp/files/ifup.pppoe +++ b/package/ppp/files/ifup.pppoe @@ -1,11 +1,10 @@ #!/bin/sh [ $# = 0 ] && { echo " $0 "; exit; } -. /etc/functions.sh -. /etc/network.overrides -[ -e /etc/config/network ] && . /etc/config/network +. /etc/config/network type=$1 -[ "$(nvram get ${type}_proto)" = "pppoe" ] || { +eval "proto=\"\${${type}_proto}\"" +[ "$proto" = "pppoe" ] || { echo "$0: ${type}_proto isn't pppoe" exit } @@ -14,22 +13,16 @@ for module in slhc ppp_generic pppox pppoe; do /sbin/insmod $module 2>&- >&- done -IFNAME=$(nvram get ${type}_device) -USERNAME=$(nvram get ppp_username) -PASSWORD=$(nvram get ppp_passwd) -KEEPALIVE=$(nvram get ppp_redialperiod) -KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 1 lcp-echo-failure $KEEPALIVE} -DEMAND=$(nvram get ppp_demand) -case "$DEMAND" in +eval "IFNAME=\"\${${type}_device}\"" +KEEPALIVE=${ppp_redialperiod:+lcp-echo-interval $ppp_redialperiod lcp-echo-failure 5} +case "$ppp_demand" in on|1|enabled) - DEMAND=$(nvram get ppp_idletime) - DEMAND=${IDLETIME:+demand idle $IDLETIME} + DEMAND=${ppp_idletime:+demand idle $ppp_idletime} [ -f /etc/ppp/filter ] && DEMAND=${DEMAND:+precompiled-active-filter /etc/ppp/filter $DEMAND} ;; *) DEMAND="persist";; esac -MTU=$(nvram get ppp_mtu) -MTU=${MTU:-1492} +MTU=${ppp_mtu:-1492} ifconfig $IFNAME up /usr/sbin/pppd \ @@ -39,8 +32,8 @@ ifconfig $IFNAME up defaultroute \ linkname $type \ ipparam $type \ - user "$USERNAME" \ - password "$PASSWORD" \ + user "$ppp_username" \ + password "$ppp_passwd" \ mtu $MTU mru $MTU \ $DEMAND \ $KEEPALIVE \ diff --git a/package/pptp/files/ifup.pptp b/package/pptp/files/ifup.pptp index 9b1ac07c26..a9bc579b56 100644 --- a/package/pptp/files/ifup.pptp +++ b/package/pptp/files/ifup.pptp @@ -1,8 +1,13 @@ #!/bin/sh -. /etc/functions.sh +[ $# = 0 ] && { echo " $0 "; exit; } +. /etc/config/network type=$1 -[ "$(nvram get ${type}_proto)" = "pptp" ] || exit +eval "proto=\"\${${type}_proto}\"" +[ "$proto" = "pptp" ] || { + echo "$0: ${type}_proto isn't pptp" + exit +} [ -d "/var/lock" ] || mkdir -p /var/lock || exit 1 @@ -10,35 +15,21 @@ for module in slhc ppp_generic ppp_async ip_gre; do /sbin/insmod $module 2>&- >&- done -PPTP_PROTO="$(nvram get pptp_proto)" -[ "$PPTP_PROTO" = "static" ] || PPTP_PROTO="" -PPTP_PROTO="${PPTP_PROTO:-dhcp}" -IP=$(nvram get pptp_server_ip) -USERNAME=$(nvram get ppp_username) -PASSWORD=$(nvram get ppp_passwd) -KEEPALIVE=$(nvram get ppp_redialperiod) -KEEPALIVE=${KEEPALIVE:+lcp-echo-interval 10 lcp-echo-failure $KEEPALIVE} -DEMAND=$(nvram get ppp_demand) -case "$DEMAND" in +KEEPALIVE=${ppp_redialperiod:+lcp-echo-interval $ppp_redialperiod lcp-echo-failure 5} +case "$ppp_demand" in on|1|enabled) - DEMAND=$(nvram get ppp_idletime) - DEMAND=${IDLETIME:+demand idle $IDLETIME} + DEMAND=${ppp_idletime:+demand idle $ppp_idletime} [ -f /etc/ppp/filter ] && DEMAND=${DEMAND:+precompiled-active-filter /etc/ppp/filter $DEMAND} ;; *) DEMAND="persist";; esac -MTU=$(nvram get ppp_mtu) -MTU=${MTU:-1452} +MTU=${ppp_mtu:-1452} -do_ifup $PPTP_PROTO $type - -# hack for some buggy ISPs -NETMASK=$(nvram get ${type}_netmask) -IFNAME=$(nvram get ${type}_device) -[ -z "$NETMASK" -o -z "$IFNAME" ] || ifconfig $IFNAME netmask $NETMASK +[ "$pptp_proto" = "static" ] || pptp_proto="dhcp" +do_ifup $pptp_proto $type /usr/sbin/pppd \ - pty "/usr/sbin/pptp $IP --loglevel 0 --nolaunchpppd" \ + pty "/usr/sbin/pptp $pptp_server_ip --loglevel 0 --nolaunchpppd" \ file /etc/ppp/options.pptp \ connect /bin/true \ usepeerdns \ @@ -46,8 +37,8 @@ IFNAME=$(nvram get ${type}_device) replacedefaultroute \ linkname "$type" \ ipparam "$type" \ - user "$USERNAME" \ - password "$PASSWORD" \ + user "$ppp_username" \ + password "$ppp_passwd" \ mtu $MTU mru $MTU \ $DEMAND \ $KEEPALIVE diff --git a/target/linux/package/base-files/files/ar7-2.4/etc/network.overrides b/target/linux/package/base-files/files/ar7-2.4/etc/network.overrides deleted file mode 100644 index 9aa74aa934..0000000000 --- a/target/linux/package/base-files/files/ar7-2.4/etc/network.overrides +++ /dev/null @@ -1,28 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -DEFAULT_lan_proto="static" -DEFAULT_lan_ifname="br0" -DEFAULT_lan_ifnames="eth0" -DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} -DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} -DEFAULT_lan_hwaddr=`echo $(strings /dev/mtdblock/3 | grep -A1 maca | grep :)` -DEFAULT_lan_hwaddr=${DEFAULT_lan_hwaddr##* } -DEFAULT_lan_hwaddr=${DEFAULT_lan_hwaddr:-${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"}} - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - lan_ifname=${DEFAULT_lan_proto} - lan_ifnames=${FAILSAFE_ifnames:-${DEFAULT_lan_ifnames}} - lan_ipaddr=$DEFAULT_lan_ipaddr - lan_netmask=$DEFAULT_lan_netmask - lan_hwaddr=$DEFAULT_lan_hwaddr - wan_ifname="none" - wifi_ifname="none" -} diff --git a/target/linux/package/base-files/files/aruba-2.6/etc/network.overrides b/target/linux/package/base-files/files/aruba-2.6/etc/network.overrides deleted file mode 100644 index 2df6acdd3d..0000000000 --- a/target/linux/package/base-files/files/aruba-2.6/etc/network.overrides +++ /dev/null @@ -1,26 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -DEFAULT_lan_proto="static" -DEFAULT_lan_ifname="br0" -DEFAULT_lan_ifnames="eth0" -DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} -DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} -# DEFAULT_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - lan_ifname=${DEFAULT_lan_proto} - lan_ifnames=${FAILSAFE_ifnames:-${DEFAULT_lan_ifnames}} - lan_ipaddr=$DEFAULT_lan_ipaddr - lan_netmask=$DEFAULT_lan_netmask - lan_hwaddr=$DEFAULT_lan_hwaddr - wan_ifname="none" - wifi_ifname="none" -} diff --git a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S04nvram b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S04nvram new file mode 100755 index 0000000000..4de124735b --- /dev/null +++ b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S04nvram @@ -0,0 +1,66 @@ +#!/bin/sh +# NVRAM setup +# +# This file handles the NVRAM quirks of various hardware. + +# WGT634u +grep 'mtd0: 00060000' /proc/mtd 2>&- >&- && exit + +alias debug=${DEBUG:-:} + +nvram_default() { + [ -z "$(nvram get $1)" ] && nvram set "$1=$2" +} + +nvram_set() { # for the linksys fixup part + [ "$(nvram get "$1")" = "$2" -a "$2" != "" ] || { + COMMIT=1 + /usr/sbin/nvram set "$1=$2" + } +} + +# work around braindead CFE defaults in linksys routers +boardtype=$(nvram get boardtype) +boardnum=$(nvram get boardnum) +boardflags=$(($(nvram get boardflags))) +adm_switch="$(( ($boardflags & 0x80) >> 7 ))" + +case "$(( $boardtype ))" in + "1800") #0x708 + if [ "$adm_switch" = 0 ]; then + nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))" + [ "$COMMIT" = 1 ] && { + nvram_set sdram_config 0x0062 + nvram_set clkfreq 216 + nvram_set sdram_ncdl 0x0 + nvram_set pa0itssit 62 + nvram_set pa0b0 0x15eb + nvram_set pa0b1 0xfa82 + nvram_set pa0b2 0xfe66 + nvram_set pa0maxpwr 0x4e + } + fi + ;; + "1127") #0x467 + nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))" + [ "$COMMIT" = 1 ] && { + nvram_set sdram_config 0x0062 + nvram_set sdram_ncdl 0x0 + nvram_set pa0itssit 62 + nvram_set pa0b0 0x168b + nvram_set pa0b1 0xfabf + nvram_set pa0b2 0xfeaf + nvram_set pa0maxpwr 0x4e + } + ;; +esac +[ "$COMMIT" = "1" ] && nvram commit + +# hack for some motorola routers +nvram unset wl0gpio0 + +[ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && { + # if default wifi mac, set two higher than the lan mac + nvram set il0macaddr=$(nvram get et0macaddr| + awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}') +} diff --git a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig index 51be73b5ba..6a626f54a5 100755 --- a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig +++ b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05netconfig @@ -50,7 +50,7 @@ END { c["vlan1ports"] = "4 5" c["lan_ifnames"] = "vlan0 ath0" } - if (nvram["boardtype"] == "0x0467") { + if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) { c["vlan0ports"] = "0 1 2 3 5*" c["vlan1ports"] = "4 5" } @@ -101,6 +101,8 @@ END { 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\"" } ' > /etc/config/network diff --git a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram b/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram deleted file mode 100755 index b985948d78..0000000000 --- a/target/linux/package/base-files/files/brcm-2.4/etc/init.d/S05nvram +++ /dev/null @@ -1,166 +0,0 @@ -#!/bin/sh -# NVRAM setup -# -# This file handles the NVRAM quirks of various hardware. - -. /etc/network.overrides -alias debug=${DEBUG:-:} - -# WGT634u -grep 'mtd0: 00060000' /proc/mtd 2>&- >&- && exit - -remap () { - for type in lan wifi wan pppoe - do - for s in '' s - do - eval nvram set ${type}_ifname$s=\"$(nvram get ${type}_ifname$s|sed s/$1/$2/g)\" - done - done -} - -nvram_default() { - [ -z "$(nvram get $1)" ] && nvram set "$1=$2" -} - -nvram_set() { # for the linksys fixup part - [ "$(nvram get "$1")" = "$2" -a "$2" != "" ] || { - COMMIT=1 - /usr/sbin/nvram set "$1=$2" - } -} - -# work around braindead CFE defaults in linksys routers -boardtype=$(nvram get boardtype) -boardflags=$(($(nvram get boardflags))) -[ "$boardtype" = "bcm94710dev" ] && boardtype="0xdeadbeef" -adm_switch="$(( ($boardflags & 0x80) >> 7 ))" -case "$(( $boardtype ))" in - "$((0x708))") - if [ "$adm_switch" = 0 ]; then - nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))" - [ "$COMMIT" = 1 ] && { - nvram_set sdram_config 0x0062 - nvram_set clkfreq 216 - nvram_set sdram_ncdl 0x0 - nvram_set pa0itssit 62 - nvram_set pa0b0 0x15eb - nvram_set pa0b1 0xfa82 - nvram_set pa0b2 0xfe66 - nvram_set pa0maxpwr 0x4e - } - fi - ;; - "$((0x467))") - nvram_set sdram_init "$(printf 0x%04x $(( $(/usr/sbin/nvram get sdram_init) | 0x0100 )))" - [ "$COMMIT" = 1 ] && { - nvram_set sdram_config 0x0062 - nvram_set sdram_ncdl 0x0 - nvram_set pa0itssit 62 - nvram_set pa0b0 0x168b - nvram_set pa0b1 0xfabf - nvram_set pa0b2 0xfeaf - nvram_set pa0maxpwr 0x4e - } - ;; -esac -[ "$COMMIT" = "1" ] && nvram commit - - -# linksys bug; remove when not using static configuration for lan -nvram set lan_proto="static" - -# hacks for wrt54g 1.x hardware -[ "$(nvram get boardnum)" = "42" \ --a "$(nvram get boardtype)" = "bcm94710dev" ] && { - debug "### wrt54g 1.x hack ###" - nvram set vlan1hwname="et0" - nvram set vlan2hwname="et0" - remap eth0 vlan2 - remap eth1 vlan1 -} - -# hacks for asus wl-500g deluxe -[ "$(nvram get boardtype)" = "bcm95365r" \ --a "$(nvram get boardnum)" = "45" ] && { - debug "### wl-500g deluxe hacks ###" - nvram set vlan0hwname="et0" - nvram set vlan1hwname="et0" - remap eth0.1 vlan0 - remap eth0 vlan1 - - # set up the vlan*ports variables for the asus wl-500g deluxe - # if they don't already exist - nvram_default vlan0ports "1 2 3 4 5*" - nvram_default vlan1ports "0 5" -} - -# hacks for asus -case "$(nvram get productid)" in - WL300g) - debug "### wl-300g hacks ###" - nvram set lan_ifnames="eth0 eth2" - nvram set wan_ifname="none" - ;; - WLHDD) - debug "### wl-hdd hacks ###" - nvram set lan_ifnames="eth1 eth2" - nvram set wan_ifname="none" - ;; - *) - # wl-500g defaults. these are placed here, because WL-HDD and WL-300g - # might have the same nvram settings. - [ "$(nvram get boardnum)" = "asusX" \ - -a "$(nvram get boardtype)" = "bcm94710dev" ] && { - nvram_default wan_device "eth1" - } - ;; -esac - -# hacks for wap54g hardware -[ "$(nvram get boardnum)" = "2" \ --o "$(nvram get boardnum)" = "1024" ] && { - debug "### wap54g hack ###" - nvram set wan_ifname="none" -} - -# hacks for buffalo wla2-g54l -[ "$(nvram get boardnum)" = "00" \ --a "$(nvram get product_name)" = "Product_name" \ --o "$(nvram get product_name)" = "WLA2-G54L" ] && { - debug "### wla2-g54l hacks ###" - nvram set wan_ifname="none" - nvram set lan_ifnames="vlan0" -} - -# needed at least for wrt54gs v1.1 and wrt54g v2.0, v2.2 -[ \! -z "$(nvram get boardrev)" ] && { - nvram_default wl0id 0x4320 -} - -# defaults -nvram_default lan_ifname "br0" -nvram_default lan_ifnames "$FAILSAFE_ifnames" - -nvram_default wan_ifname "vlan1" -nvram_default wan_device "vlan1" -nvram_default wan_proto "dhcp" - -nvram_default wl0_ssid OpenWrt -nvram_default wl0_mode ap -nvram_default wl0_infra 1 -nvram_default wl0_radio 1 - -WAN_PROTO="$(nvram get wan_proto)" -WAN_IFNAME="$(nvram get wan_ifname)" -case "$WAN_PROTO" in - pp*) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] || nvram set wan_ifname=ppp0;; - *) [ "${WAN_IFNAME%%[0-9]*}" = "ppp" ] && nvram set wan_ifname="$(nvram get wan_device)";; -esac - -[ "$(nvram get il0macaddr)" = "00:90:4c:5f:00:2a" ] && { - # if default wifi mac, set two higher than the lan mac - nvram set il0macaddr=$(nvram get et0macaddr| - awk '{OFS=FS=":";for(x=7,y=2;--x;){$x=sprintf("%02x",(y+="0x"$x)%256);y/=256}print}') -} - diff --git a/target/linux/package/base-files/files/brcm-2.4/etc/network.overrides b/target/linux/package/base-files/files/brcm-2.4/etc/network.overrides deleted file mode 100644 index 72ef012653..0000000000 --- a/target/linux/package/base-files/files/brcm-2.4/etc/network.overrides +++ /dev/null @@ -1,41 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -# hacks for wrt54g 1.x hardware -[ "$(nvram get boardnum)" = "42" \ --a "$(nvram get boardtype)" = "bcm94710dev" ] && FAILSAFE_ifnames="vlan0 vlan2 eth2" - -# hacks for asus wl-500g deluxe -[ "$(nvram get boardtype)" = "bcm95365r" \ --a "$(nvram get boardnum)" = "45" ] && FAILSAFE_ifnames="vlan0 eth1" - -# hacks for wap54g hardware -[ "$(nvram get boardnum)" = "2" \ --o "$(nvram get boardnum)" = "1024" ] && FAILSAFE_ifnames="eth0 eth1" - -# hack for asus wl-500g hardware -[ "$(nvram get boardnum)" = "asusX" \ --a "$(nvram get boardtype)" = "bcm94710dev" ] && FAILSAFE_ifnames="eth0 eth1 eth2" - -FAILSAFE_ifnames=${FAILSAFE_ifnames:-"vlan0 eth1 eth2"} - -DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} -DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} -DEFAULT_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - lan_ifname="br0" - lan_ifnames=$FAILSAFE_ifnames - lan_ipaddr=$DEFAULT_lan_ipaddr - lan_netmask=$DEFAULT_lan_netmask - lan_hwaddr=$DEFAULT_lan_hwaddr - wan_ifname="none" - wifi_ifname="none" -} diff --git a/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig b/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig index 51be73b5ba..6a626f54a5 100755 --- a/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig +++ b/target/linux/package/base-files/files/brcm-2.6/etc/init.d/S05netconfig @@ -50,7 +50,7 @@ END { c["vlan1ports"] = "4 5" c["lan_ifnames"] = "vlan0 ath0" } - if (nvram["boardtype"] == "0x0467") { + if ((nvram["boardtype"] == "0x0467") || (nvram["boardtype"] == "0x042f")) { c["vlan0ports"] = "0 1 2 3 5*" c["vlan1ports"] = "4 5" } @@ -101,6 +101,8 @@ END { 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\"" } ' > /etc/config/network diff --git a/target/linux/package/base-files/files/brcm-2.6/etc/network.overrides b/target/linux/package/base-files/files/brcm-2.6/etc/network.overrides deleted file mode 100644 index ded748b260..0000000000 --- a/target/linux/package/base-files/files/brcm-2.6/etc/network.overrides +++ /dev/null @@ -1,31 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -DEFAULT_lan_proto="static" -DEFAULT_lan_ifname="br0" -DEFAULT_lan_ifnames="vlan0 ath0" -DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} -DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} -DEFAULT_lan_hwaddr=${DEFAULT_lan_hwaddr:-${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"}} -DEFAULT_vlan0hwname="et0" -DEFAULT_vlan1hwname="et0" -DEFAULT_et0macaddr=$(ifconfig eth0| awk '/eth0/ {print $5 }') -DEFAULT_wan_proto="dhcp" -DEFAULT_wan_ifname="vlan1" - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - lan_ifname=${DEFAULT_lan_proto} - lan_ifnames=${FAILSAFE_ifnames:-${DEFAULT_lan_ifnames}} - lan_ipaddr=$DEFAULT_lan_ipaddr - lan_netmask=$DEFAULT_lan_netmask - lan_hwaddr=$DEFAULT_lan_hwaddr - wan_ifname="none" - wifi_ifname="none" -} diff --git a/target/linux/package/base-files/files/x86-2.4/etc/network.overrides b/target/linux/package/base-files/files/x86-2.4/etc/network.overrides deleted file mode 100644 index e857d5b5f1..0000000000 --- a/target/linux/package/base-files/files/x86-2.4/etc/network.overrides +++ /dev/null @@ -1,26 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -DEFAULT_lan_proto="static" -DEFAULT_lan_ifname="br0" -DEFAULT_lan_ifnames="eth0" -DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} -DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} -DEFAULT_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - lan_ifname=${DEFAULT_lan_proto} - lan_ifnames=${FAILSAFE_ifnames:-${DEFAULT_lan_ifnames}} - lan_ipaddr=$DEFAULT_lan_ipaddr - lan_netmask=$DEFAULT_lan_netmask - lan_hwaddr=$DEFAULT_lan_hwaddr - wan_ifname="none" - wifi_ifname="none" -} diff --git a/target/linux/package/base-files/files/x86-2.6/etc/network.overrides b/target/linux/package/base-files/files/x86-2.6/etc/network.overrides deleted file mode 100644 index e857d5b5f1..0000000000 --- a/target/linux/package/base-files/files/x86-2.6/etc/network.overrides +++ /dev/null @@ -1,26 +0,0 @@ -# NVRAM overrides -# -# This file handles the NVRAM quirks of various hardware. -# THIS FILE IS NOT A REPLACEMENT FOR NVRAM - -# Load sysconf defaults -[ -f /etc/sysconf ] && . /etc/sysconf - -DEFAULT_lan_proto="static" -DEFAULT_lan_ifname="br0" -DEFAULT_lan_ifnames="eth0" -DEFAULT_lan_ipaddr=${BR2_SYSCONF_FAILSAFE_IP:-"192.168.1.1"} -DEFAULT_lan_netmask=${BR2_SYSCONF_FAILSAFE_NETMASK:-"255.255.255.0"} -DEFAULT_lan_hwaddr=${BR2_SYSCONF_FAILSAFE_MAC:-"00:0B:AD:0A:DD:00"} - -# failsafe if reset is held -[ "$FAILSAFE" = "true" ] && { - echo "### YOU ARE IN FAILSAFE MODE ####" - lan_ifname=${DEFAULT_lan_proto} - lan_ifnames=${FAILSAFE_ifnames:-${DEFAULT_lan_ifnames}} - lan_ipaddr=$DEFAULT_lan_ipaddr - lan_netmask=$DEFAULT_lan_netmask - lan_hwaddr=$DEFAULT_lan_hwaddr - wan_ifname="none" - wifi_ifname="none" -} -- cgit v1.2.3 From ed5ef674d100ca0ffa8bc00160718f69af5515c3 Mon Sep 17 00:00:00 2001 From: nbd Date: Tue, 27 Jun 2006 00:36:13 +0000 Subject: add copyright headers to base-files scripts and config files git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4090 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/ar7-2.4/bin/firstboot | 2 +- package/base-files/aruba-2.6/etc/config/network | 2 ++ package/base-files/au1000-2.6/etc/config/network | 1 + package/base-files/au1000-2.6/sbin/mount_root | 2 ++ package/base-files/brcm-2.4/bin/firstboot | 2 +- package/base-files/brcm-2.4/etc/config/wireless | 2 ++ package/base-files/brcm-2.4/etc/hotplug.d/net/09-net | 2 ++ package/base-files/brcm-2.4/etc/init.d/S05netconfig | 2 ++ package/base-files/brcm-2.4/etc/preinit | 2 ++ package/base-files/brcm-2.4/sbin/mount_root | 2 ++ package/base-files/brcm-2.6/bin/firstboot | 2 +- package/base-files/brcm-2.6/etc/hotplug.d/net/09-net | 2 ++ package/base-files/brcm-2.6/etc/init.d/S05netconfig | 2 ++ package/base-files/brcm-2.6/etc/preinit | 2 ++ package/base-files/brcm-2.6/sbin/mount_root | 2 ++ package/base-files/default/bin/ipcalc | 1 + package/base-files/default/bin/login | 2 ++ package/base-files/default/etc/functions.sh | 2 ++ package/base-files/default/etc/hotplug.d/net/10-net | 2 ++ package/base-files/default/etc/hotplug.d/usb/01-mount | 3 +++ package/base-files/default/etc/init.d/S10boot | 2 ++ package/base-files/default/etc/init.d/S50httpd | 2 ++ package/base-files/default/etc/init.d/S50telnet | 2 ++ package/base-files/default/etc/init.d/S60cron | 2 ++ package/base-files/default/etc/init.d/S98done | 2 ++ package/base-files/default/etc/init.d/rcS | 2 ++ package/base-files/default/etc/nvram.sh | 2 ++ package/base-files/default/sbin/hotplug | 1 + package/base-files/default/sbin/ifdown | 2 ++ package/base-files/default/sbin/ifup | 2 ++ package/base-files/default/sbin/mount_root | 2 ++ package/base-files/default/sbin/wifi | 2 ++ package/base-files/default/usr/lib/common.awk | 2 ++ package/base-files/default/usr/lib/parse-config.awk | 2 ++ package/base-files/rb532-2.6/etc/config/network | 1 + package/base-files/sibyte-2.6/etc/config/network | 1 + package/base-files/sibyte-2.6/etc/inittab | 2 ++ package/base-files/x86-2.4/etc/config/network | 1 + package/base-files/x86-2.6/etc/config/network | 1 + package/base-files/xscale-2.6/etc/config/network | 1 + 40 files changed, 70 insertions(+), 3 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/ar7-2.4/bin/firstboot b/package/base-files/ar7-2.4/bin/firstboot index 955423be09..774bbc754b 100755 --- a/package/base-files/ar7-2.4/bin/firstboot +++ b/package/base-files/ar7-2.4/bin/firstboot @@ -1,5 +1,5 @@ #!/bin/sh -# $Id$ +# Copyright (C) 2006 OpenWrt.org rom=$(awk '/squashfs/ {print $2}' /proc/mounts) jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) diff --git a/package/base-files/aruba-2.6/etc/config/network b/package/base-files/aruba-2.6/etc/config/network index f60332cd8c..65797797ee 100644 --- a/package/base-files/aruba-2.6/etc/config/network +++ b/package/base-files/aruba-2.6/etc/config/network @@ -1,4 +1,6 @@ # Network configuration file +# Copyright (C) 2006 OpenWrt.org + ## LAN configuration lan_ifname="eth0" diff --git a/package/base-files/au1000-2.6/etc/config/network b/package/base-files/au1000-2.6/etc/config/network index 2cc9e26717..576677bf7c 100644 --- a/package/base-files/au1000-2.6/etc/config/network +++ b/package/base-files/au1000-2.6/etc/config/network @@ -1,4 +1,5 @@ # Network configuration file +# Copyright (C) 2006 OpenWrt.org ## LAN configuration lan_ifname="br0" diff --git a/package/base-files/au1000-2.6/sbin/mount_root b/package/base-files/au1000-2.6/sbin/mount_root index bc4165ca30..718394ca4c 100755 --- a/package/base-files/au1000-2.6/sbin/mount_root +++ b/package/base-files/au1000-2.6/sbin/mount_root @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + mount none /proc -t proc size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)&- || return 1 OFFSET="$(($(hexdump -v /dev/mtdblock/1 -s 20 -n 2 -e '"%d"')-1))" diff --git a/package/base-files/brcm-2.6/bin/firstboot b/package/base-files/brcm-2.6/bin/firstboot index 28189780bd..d37ce4f90b 100755 --- a/package/base-files/brcm-2.6/bin/firstboot +++ b/package/base-files/brcm-2.6/bin/firstboot @@ -1,5 +1,5 @@ #!/bin/sh -# $Id$ +# Copyright (C) 2006 OpenWrt.org rom=$(awk '/squashfs/ {print $2}' /proc/mounts) jffs=$(awk '/jffs2/ {print $2}' /proc/mounts) diff --git a/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net b/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net index 8bbf604df8..90a92bd2b0 100644 --- a/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net +++ b/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + setup_eth() { [ -d /proc/switch ] || { diff --git a/package/base-files/brcm-2.6/etc/init.d/S05netconfig b/package/base-files/brcm-2.6/etc/init.d/S05netconfig index 6a626f54a5..0f53c0c9c9 100755 --- a/package/base-files/brcm-2.6/etc/init.d/S05netconfig +++ b/package/base-files/brcm-2.6/etc/init.d/S05netconfig @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + [ -e /etc/config/network ] && exit 0 mkdir -p /etc/config diff --git a/package/base-files/brcm-2.6/etc/preinit b/package/base-files/brcm-2.6/etc/preinit index 5b676ca3ac..fb13e107e5 100755 --- a/package/base-files/brcm-2.6/etc/preinit +++ b/package/base-files/brcm-2.6/etc/preinit @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + export PATH=/bin:/sbin:/usr/bin:/usr/sbin mount none /proc -t proc diff --git a/package/base-files/brcm-2.6/sbin/mount_root b/package/base-files/brcm-2.6/sbin/mount_root index a3ada58908..e3bdd3655c 100755 --- a/package/base-files/brcm-2.6/sbin/mount_root +++ b/package/base-files/brcm-2.6/sbin/mount_root @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + is_dirty() { grep Broadcom /proc/cpuinfo >&- || return 1 OFFSET="$(($(hexdump -v /dev/mtdblock/1 -s 20 -n 2 -e '"%d"')-1))" diff --git a/package/base-files/default/bin/ipcalc b/package/base-files/default/bin/ipcalc index 318980e5a2..23af6a0c3b 100755 --- a/package/base-files/default/bin/ipcalc +++ b/package/base-files/default/bin/ipcalc @@ -1,4 +1,5 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org awk -f /usr/lib/common.awk -f - $* <&- 2>&- [ "$?" = "0" -a -z "$FAILSAFE" ] && { diff --git a/package/base-files/default/etc/functions.sh b/package/base-files/default/etc/functions.sh index 3010196171..a7f7c42e22 100755 --- a/package/base-files/default/etc/functions.sh +++ b/package/base-files/default/etc/functions.sh @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + alias debug=${DEBUG:-:} # newline diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index b68ec1be28..f306ae342d 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + find_name() { for ifname in lan wan wifi ${ifnames}; do diff --git a/package/base-files/default/etc/hotplug.d/usb/01-mount b/package/base-files/default/etc/hotplug.d/usb/01-mount index c28ada204e..c4d356b0da 100644 --- a/package/base-files/default/etc/hotplug.d/usb/01-mount +++ b/package/base-files/default/etc/hotplug.d/usb/01-mount @@ -1,3 +1,6 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.org + mount_storage() { cd /dev/discs for dev in disc*; do diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index e0d15db0e0..cb5c6ac4a7 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + . /etc/functions.sh [ -f /proc/mounts ] || /sbin/mount_root diff --git a/package/base-files/default/etc/init.d/S50httpd b/package/base-files/default/etc/init.d/S50httpd index a1b883d0a8..d278519e98 100755 --- a/package/base-files/default/etc/init.d/S50httpd +++ b/package/base-files/default/etc/init.d/S50httpd @@ -1,2 +1,4 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + [ -d /www ] && httpd -p 80 -h /www -r OpenWrt diff --git a/package/base-files/default/etc/init.d/S50telnet b/package/base-files/default/etc/init.d/S50telnet index fb9687c8aa..25242bdef8 100755 --- a/package/base-files/default/etc/init.d/S50telnet +++ b/package/base-files/default/etc/init.d/S50telnet @@ -1,2 +1,4 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + if awk -F: '/^root:/ && $2 !~ /\!/ {exit 1}' /etc/passwd 2>/dev/null; then telnetd -l /bin/login; fi diff --git a/package/base-files/default/etc/init.d/S60cron b/package/base-files/default/etc/init.d/S60cron index 1752734267..6df9b7dee9 100755 --- a/package/base-files/default/etc/init.d/S60cron +++ b/package/base-files/default/etc/init.d/S60cron @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + mkdir -p /var/spool/cron ln -s /etc/crontabs /var/spool/cron/crontabs crond -c /etc/crontabs diff --git a/package/base-files/default/etc/init.d/S98done b/package/base-files/default/etc/init.d/S98done index 5d5ab49ce3..a1ea5ad438 100755 --- a/package/base-files/default/etc/init.d/S98done +++ b/package/base-files/default/etc/init.d/S98done @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + sysctl -p >&- # automagically run firstboot diff --git a/package/base-files/default/etc/init.d/rcS b/package/base-files/default/etc/init.d/rcS index b38e449781..dad989fe09 100755 --- a/package/base-files/default/etc/init.d/rcS +++ b/package/base-files/default/etc/init.d/rcS @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + ${FAILSAFE:+exit} [ -f /etc/config/network ] && . /etc/config/network diff --git a/package/base-files/default/etc/nvram.sh b/package/base-files/default/etc/nvram.sh index 4d39a10204..ddbd88b52f 100644 --- a/package/base-files/default/etc/nvram.sh +++ b/package/base-files/default/etc/nvram.sh @@ -1,4 +1,6 @@ #!/bin/ash +# Copyright (C) 2006 OpenWrt.org + # allow env to override nvram nvram () { diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug index 106299343a..afe52a446f 100755 --- a/package/base-files/default/sbin/hotplug +++ b/package/base-files/default/sbin/hotplug @@ -1,4 +1,5 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org # bypass the normal hotplug path for firmware loading # would otherwise cause problems with drivers like bcm43xx diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 0d85ca8eab..50ffee5304 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh . /etc/config/network diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index a86a7671e8..390f960395 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + [ $# = 0 ] && { echo " $0 "; exit; } . /etc/functions.sh . /etc/config/network diff --git a/package/base-files/default/sbin/mount_root b/package/base-files/default/sbin/mount_root index 647c25327a..81660f0067 100755 --- a/package/base-files/default/sbin/mount_root +++ b/package/base-files/default/sbin/mount_root @@ -1,4 +1,6 @@ #!/bin/sh +# Copyright (C) 2006 OpenWrt.org + mount none /proc -t proc size=$(awk '/Mem:/ {l=5242880;print((s=$2/2) Date: Sun, 30 Jul 2006 03:09:09 +0000 Subject: rewrite of the network scripts and configuration git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4323 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/ar7-2.4/etc/config/network | 29 +-- package/base-files/aruba-2.6/etc/config/network | 8 +- package/base-files/au1000-2.6/etc/config/network | 17 +- .../base-files/brcm-2.4/etc/hotplug.d/net/09-net | 45 ----- .../base-files/brcm-2.4/etc/init.d/S05netconfig | 70 ++----- .../base-files/brcm-2.6/etc/hotplug.d/net/09-net | 35 ---- .../base-files/brcm-2.6/etc/init.d/S05netconfig | 70 ++----- .../base-files/default/etc/hotplug.d/net/10-net | 201 ++------------------- package/base-files/default/etc/init.d/S10boot | 3 +- package/base-files/default/etc/init.d/S40network | 9 + package/base-files/default/etc/init.d/rcS | 11 +- package/base-files/default/lib/network/config.sh | 147 +++++++++++++++ package/base-files/default/sbin/hotplug | 1 - package/base-files/default/sbin/ifdown | 32 +++- package/base-files/default/sbin/ifup | 42 ++--- package/base-files/default/sbin/wifi | 7 +- .../default/usr/share/udhcpc/default.script | 14 +- package/base-files/rb532-2.6/etc/config/network | 8 +- package/base-files/sibyte-2.6/etc/config/network | 17 +- package/base-files/x86-2.4/etc/config/network | 20 +- package/base-files/x86-2.6/etc/config/network | 20 +- package/base-files/xscale-2.6/etc/config/network | 7 +- package/broadcom-wl/files/lib/wifi/broadcom.sh | 14 +- package/dnsmasq/files/dnsmasq.init | 12 +- package/iptables/files/firewall.awk | 5 +- package/iptables/files/firewall.init | 11 +- package/iptables/files/firewall.user | 5 - package/ppp/Makefile | 10 +- package/ppp/files/ifup.pppoa | 38 ---- package/ppp/files/ifup.pppoe | 43 ----- package/ppp/files/ppp.sh | 27 +++ package/ppp/files/pppoa.sh | 20 ++ package/ppp/files/pppoe.sh | 21 +++ package/ppp/files/pptp.sh | 3 + package/pptp/Makefile | 4 +- package/pptp/files/ifup.pptp | 45 ----- package/pptp/files/pptp.sh | 22 +++ package/switch/Makefile | 4 + package/switch/files/switch.sh | 33 ++++ 39 files changed, 481 insertions(+), 649 deletions(-) delete mode 100644 package/base-files/brcm-2.4/etc/hotplug.d/net/09-net delete mode 100644 package/base-files/brcm-2.6/etc/hotplug.d/net/09-net create mode 100755 package/base-files/default/etc/init.d/S40network create mode 100755 package/base-files/default/lib/network/config.sh mode change 100755 => 100644 package/iptables/files/firewall.user delete mode 100644 package/ppp/files/ifup.pppoa delete mode 100644 package/ppp/files/ifup.pppoe create mode 100644 package/ppp/files/ppp.sh create mode 100644 package/ppp/files/pppoa.sh create mode 100644 package/ppp/files/pppoe.sh create mode 100644 package/ppp/files/pptp.sh delete mode 100644 package/pptp/files/ifup.pptp create mode 100644 package/pptp/files/pptp.sh create mode 100644 package/switch/files/switch.sh (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/ar7-2.4/etc/config/network b/package/base-files/ar7-2.4/etc/config/network index 353538bf49..19a858e163 100644 --- a/package/base-files/ar7-2.4/etc/config/network +++ b/package/base-files/ar7-2.4/etc/config/network @@ -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 diff --git a/package/base-files/aruba-2.6/etc/config/network b/package/base-files/aruba-2.6/etc/config/network index 65797797ee..aadd4aa8ed 100644 --- a/package/base-files/aruba-2.6/etc/config/network +++ b/package/base-files/aruba-2.6/etc/config/network @@ -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 diff --git a/package/base-files/au1000-2.6/etc/config/network b/package/base-files/au1000-2.6/etc/config/network index 576677bf7c..95d7575c92 100644 --- a/package/base-files/au1000-2.6/etc/config/network +++ b/package/base-files/au1000-2.6/etc/config/network @@ -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/package/base-files/brcm-2.4/etc/hotplug.d/net/09-net b/package/base-files/brcm-2.4/etc/hotplug.d/net/09-net deleted file mode 100644 index 48abdf4062..0000000000 --- a/package/base-files/brcm-2.4/etc/hotplug.d/net/09-net +++ /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 diff --git a/package/base-files/brcm-2.4/etc/init.d/S05netconfig b/package/base-files/brcm-2.4/etc/init.d/S05netconfig index 0f53c0c9c9..82e4ab9986 100755 --- a/package/base-files/brcm-2.4/etc/init.d/S05netconfig +++ b/package/base-files/brcm-2.4/etc/init.d/S05netconfig @@ -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/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net b/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net deleted file mode 100644 index 90a92bd2b0..0000000000 --- a/package/base-files/brcm-2.6/etc/hotplug.d/net/09-net +++ /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 diff --git a/package/base-files/brcm-2.6/etc/init.d/S05netconfig b/package/base-files/brcm-2.6/etc/init.d/S05netconfig index 0f53c0c9c9..82e4ab9986 100755 --- a/package/base-files/brcm-2.6/etc/init.d/S05netconfig +++ b/package/base-files/brcm-2.6/etc/init.d/S05netconfig @@ -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/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index f306ae342d..d5b7f6b0fa 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -1,191 +1,28 @@ -#!/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 diff --git a/package/base-files/default/etc/init.d/S10boot b/package/base-files/default/etc/init.d/S10boot index cb5c6ac4a7..19420eda53 100755 --- a/package/base-files/default/etc/init.d/S10boot +++ b/package/base-files/default/etc/init.d/S10boot @@ -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/package/base-files/default/etc/init.d/S40network b/package/base-files/default/etc/init.d/S40network new file mode 100755 index 0000000000..20a11845b6 --- /dev/null +++ b/package/base-files/default/etc/init.d/S40network @@ -0,0 +1,9 @@ +#!/bin/sh +# Copyright (C) 2006 OpenWrt.orga + +setup_switch() { return 0; } + +. /etc/functions.sh +include network +setup_switch +/sbin/wifi diff --git a/package/base-files/default/etc/init.d/rcS b/package/base-files/default/etc/init.d/rcS index dad989fe09..2aa70910c3 100755 --- a/package/base-files/default/etc/init.d/rcS +++ b/package/base-files/default/etc/init.d/rcS @@ -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/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh new file mode 100755 index 0000000000..59ec84aba8 --- /dev/null +++ b/package/base-files/default/lib/network/config.sh @@ -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 +} + diff --git a/package/base-files/default/sbin/hotplug b/package/base-files/default/sbin/hotplug index afe52a446f..b1b6f97b23 100755 --- a/package/base-files/default/sbin/hotplug +++ b/package/base-files/default/sbin/hotplug @@ -13,7 +13,6 @@ } . /etc/functions.sh -. /etc/config/network PATH=/bin:/sbin:/usr/bin:/usr/sbin LOGNAME=root diff --git a/package/base-files/default/sbin/ifdown b/package/base-files/default/sbin/ifdown index 50ffee5304..7debb9559f 100755 --- a/package/base-files/default/sbin/ifdown +++ b/package/base-files/default/sbin/ifdown @@ -3,18 +3,32 @@ [ $# = 0 ] && { echo " $0 "; 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" +} diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 390f960395..c40de38ad8 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -1,38 +1,18 @@ #!/bin/sh # Copyright (C) 2006 OpenWrt.org -[ $# = 0 ] && { echo " $0 "; 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 diff --git a/package/base-files/default/sbin/wifi b/package/base-files/default/sbin/wifi index 63b2f121bd..f1ac94fa3a 100755 --- a/package/base-files/default/sbin/wifi +++ b/package/base-files/default/sbin/wifi @@ -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 diff --git a/package/base-files/default/usr/share/udhcpc/default.script b/package/base-files/default/usr/share/udhcpc/default.script index 4604648e6b..a244e05a15 100755 --- a/package/base-files/default/usr/share/udhcpc/default.script +++ b/package/base-files/default/usr/share/udhcpc/default.script @@ -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 } diff --git a/package/base-files/rb532-2.6/etc/config/network b/package/base-files/rb532-2.6/etc/config/network index 2bb48b8863..6f089fe992 100644 --- a/package/base-files/rb532-2.6/etc/config/network +++ b/package/base-files/rb532-2.6/etc/config/network @@ -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 + diff --git a/package/base-files/sibyte-2.6/etc/config/network b/package/base-files/sibyte-2.6/etc/config/network index 576677bf7c..95d7575c92 100644 --- a/package/base-files/sibyte-2.6/etc/config/network +++ b/package/base-files/sibyte-2.6/etc/config/network @@ -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/package/base-files/x86-2.4/etc/config/network b/package/base-files/x86-2.4/etc/config/network index 7bcfd0870a..9f521c05bf 100644 --- a/package/base-files/x86-2.4/etc/config/network +++ b/package/base-files/x86-2.4/etc/config/network @@ -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" diff --git a/package/base-files/x86-2.6/etc/config/network b/package/base-files/x86-2.6/etc/config/network index 7bcfd0870a..9f521c05bf 100644 --- a/package/base-files/x86-2.6/etc/config/network +++ b/package/base-files/x86-2.6/etc/config/network @@ -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" diff --git a/package/base-files/xscale-2.6/etc/config/network b/package/base-files/xscale-2.6/etc/config/network index 2bb48b8863..aadd4aa8ed 100644 --- a/package/base-files/xscale-2.6/etc/config/network +++ b/package/base-files/xscale-2.6/etc/config/network @@ -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 diff --git a/package/broadcom-wl/files/lib/wifi/broadcom.sh b/package/broadcom-wl/files/lib/wifi/broadcom.sh index 6cac60c0b7..53d1cf7925 100644 --- a/package/broadcom-wl/files/lib/wifi/broadcom.sh +++ b/package/broadcom-wl/files/lib/wifi/broadcom.sh @@ -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" diff --git a/package/dnsmasq/files/dnsmasq.init b/package/dnsmasq/files/dnsmasq.init index 17ef43c3d5..140f727f46 100644 --- a/package/dnsmasq/files/dnsmasq.init +++ b/package/dnsmasq/files/dnsmasq.init @@ -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 diff --git a/package/iptables/files/firewall.awk b/package/iptables/files/firewall.awk index 5378330045..902c7b1888 100644 --- a/package/iptables/files/firewall.awk +++ b/package/iptables/files/firewall.awk @@ -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>&- >&-" diff --git a/package/iptables/files/firewall.init b/package/iptables/files/firewall.init index e174d84bb2..a0bd99ef9a 100755 --- a/package/iptables/files/firewall.init +++ b/package/iptables/files/firewall.init @@ -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 diff --git a/package/iptables/files/firewall.user b/package/iptables/files/firewall.user old mode 100755 new mode 100644 index 1fb862e9b0..5f295babf2 --- a/package/iptables/files/firewall.user +++ b/package/iptables/files/firewall.user @@ -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 diff --git a/package/ppp/Makefile b/package/ppp/Makefile index 85d52d0542..e49b610c36 100644 --- a/package/ppp/Makefile +++ b/package/ppp/Makefile @@ -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/package/ppp/files/ifup.pppoa b/package/ppp/files/ifup.pppoa deleted file mode 100644 index f78a162ce5..0000000000 --- a/package/ppp/files/ifup.pppoa +++ /dev/null @@ -1,38 +0,0 @@ -#!/bin/sh -[ $# = 0 ] && { echo " $0 "; 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/package/ppp/files/ifup.pppoe b/package/ppp/files/ifup.pppoe deleted file mode 100644 index c7019fc398..0000000000 --- a/package/ppp/files/ifup.pppoe +++ /dev/null @@ -1,43 +0,0 @@ -#!/bin/sh -[ $# = 0 ] && { echo " $0 "; 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/package/ppp/files/ppp.sh b/package/ppp/files/ppp.sh new file mode 100644 index 0000000000..0bb77b8284 --- /dev/null +++ b/package/ppp/files/ppp.sh @@ -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/package/ppp/files/pppoa.sh b/package/ppp/files/pppoa.sh new file mode 100644 index 0000000000..e6530b073e --- /dev/null +++ b/package/ppp/files/pppoa.sh @@ -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/package/ppp/files/pppoe.sh b/package/ppp/files/pppoe.sh new file mode 100644 index 0000000000..f263caaeef --- /dev/null +++ b/package/ppp/files/pppoe.sh @@ -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/package/ppp/files/pptp.sh b/package/ppp/files/pptp.sh new file mode 100644 index 0000000000..7b33ac1ff7 --- /dev/null +++ b/package/ppp/files/pptp.sh @@ -0,0 +1,3 @@ +scan_pptp() { + scan_ppp "$@" +} diff --git a/package/pptp/Makefile b/package/pptp/Makefile index 061e55395e..b060c12a79 100644 --- a/package/pptp/Makefile +++ b/package/pptp/Makefile @@ -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/package/pptp/files/ifup.pptp b/package/pptp/files/ifup.pptp deleted file mode 100644 index f401a36b2f..0000000000 --- a/package/pptp/files/ifup.pptp +++ /dev/null @@ -1,45 +0,0 @@ -#!/bin/sh -[ $# = 0 ] && { echo " $0 "; 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/package/pptp/files/pptp.sh b/package/pptp/files/pptp.sh new file mode 100644 index 0000000000..7847802041 --- /dev/null +++ b/package/pptp/files/pptp.sh @@ -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" +} diff --git a/package/switch/Makefile b/package/switch/Makefile index 5513394fd6..860e530c4c 100644 --- a/package/switch/Makefile +++ b/package/switch/Makefile @@ -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/package/switch/files/switch.sh b/package/switch/files/switch.sh new file mode 100644 index 0000000000..a787a8cf38 --- /dev/null +++ b/package/switch/files/switch.sh @@ -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 +} -- cgit v1.2.3 From 4092003baf587af80df1b9c6f9dbc49a9dd23483 Mon Sep 17 00:00:00 2001 From: nbd Date: Thu, 24 Aug 2006 12:20:02 +0000 Subject: fix remaining *_ifnames references git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4650 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/brcm-2.4/etc/init.d/S05netconfig | 2 +- package/base-files/brcm-2.6/etc/init.d/S05netconfig | 2 +- package/base-files/default/etc/hotplug.d/net/10-net | 7 ++----- package/base-files/default/sbin/ifup | 9 +-------- 4 files changed, 5 insertions(+), 15 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/brcm-2.4/etc/init.d/S05netconfig b/package/base-files/brcm-2.4/etc/init.d/S05netconfig index a4d29358bc..2efd596aa8 100755 --- a/package/base-files/brcm-2.4/etc/init.d/S05netconfig +++ b/package/base-files/brcm-2.4/etc/init.d/S05netconfig @@ -64,7 +64,7 @@ END { print "#### LAN configuration" print "config interface lan" print " option type bridge" - p("ifnames", "lan_ifname") + p("ifname", "lan_ifname") print " option proto static" print " option ipaddr 192.168.1.1" print " option netmask 255.255.255.0" diff --git a/package/base-files/brcm-2.6/etc/init.d/S05netconfig b/package/base-files/brcm-2.6/etc/init.d/S05netconfig index a4d29358bc..2efd596aa8 100755 --- a/package/base-files/brcm-2.6/etc/init.d/S05netconfig +++ b/package/base-files/brcm-2.6/etc/init.d/S05netconfig @@ -64,7 +64,7 @@ END { print "#### LAN configuration" print "config interface lan" print " option type bridge" - p("ifnames", "lan_ifname") + p("ifname", "lan_ifname") print " option proto static" print " option ipaddr 192.168.1.1" print " option netmask 255.255.255.0" diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index 72146a1d78..8661a2851d 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -5,14 +5,11 @@ include network addif() { scan_interfaces setup_interface "$INTERFACE" - + # find all vlan configurations for this interface and set them up as well for ifc in $interfaces; do config_get iftype "$ifc" type - case "$iftype" in - bridge) config_get ifs "$ifc" ifnames;; - *) config_get ifs "$ifc" ifname;; - esac + config_get ifs "$ifc" ifname for dev in $ifs; do [ "${dev%%\.*}" = "$INTERFACE" -a "$dev" != "$INTERFACE" ] && { add_vlan "$dev" diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index c40de38ad8..86d10d7ca3 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -4,14 +4,7 @@ . /sbin/ifdown "$@" config_get iftype "$1" type -case "$iftype" in - bridge) - config_get ifname "$1" ifnames - ;; - *) - config_get ifname "$1" ifname - ;; -esac +config_get ifname "$1" ifname for dev in $ifname; do setup_interface "$dev" "$1" -- cgit v1.2.3 From 00394c57717f28bb3b9860020729cd73036a8cf8 Mon Sep 17 00:00:00 2001 From: nbd Date: Thu, 24 Aug 2006 13:46:47 +0000 Subject: revert to using *_ifnames internally, too many problems with firewall, ppp, etc. otherwise git-svn-id: svn://svn.openwrt.org/openwrt/branches/buildroot-ng/openwrt@4653 3c298f89-4303-0410-b956-a3cf2f4a3e73 --- package/base-files/default/etc/hotplug.d/net/10-net | 5 ++++- package/base-files/default/lib/network/config.sh | 13 +++++++++---- package/base-files/default/sbin/ifup | 5 ++++- 3 files changed, 17 insertions(+), 6 deletions(-) (limited to 'package/base-files/default/sbin/ifup') diff --git a/package/base-files/default/etc/hotplug.d/net/10-net b/package/base-files/default/etc/hotplug.d/net/10-net index 8661a2851d..b5140758af 100644 --- a/package/base-files/default/etc/hotplug.d/net/10-net +++ b/package/base-files/default/etc/hotplug.d/net/10-net @@ -9,7 +9,10 @@ addif() { # find all vlan configurations for this interface and set them up as well for ifc in $interfaces; do config_get iftype "$ifc" type - config_get ifs "$ifc" ifname + case "$iftype" 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" diff --git a/package/base-files/default/lib/network/config.sh b/package/base-files/default/lib/network/config.sh index d4864ae86e..5bc74d1285 100755 --- a/package/base-files/default/lib/network/config.sh +++ b/package/base-files/default/lib/network/config.sh @@ -21,7 +21,7 @@ find_config() { } scan_interfaces() { - local mode iftype iface + local mode iftype iface ifname device interfaces= config_cb() { config_get iftype "$CONFIG_SECTION" TYPE @@ -29,10 +29,15 @@ scan_interfaces() { interface) config_get proto "$CONFIG_SECTION" proto append interfaces "$CONFIG_SECTION" + config_get iftype "$CONFIG_SECTION" iftype + case "$iftype" in + bridge) + config_get ifname "$CONFIG_SECTION" ifname + config_set "$CONFIG_SECTION" ifnames "$ifname" + config_set "$CONFIG_SECTION" ifname br-"$CONFIG_SECTION" + ;; + esac ( type "scan_$proto" ) >/dev/null 2>/dev/null && eval "scan_$proto '$CONFIG_SECTION'" - config_get ifname "$CONFIG_SECTION" ifname - config_get device "$CONFIG_SECTION" device - config_set "$CONFIG_SECTION" device "${device:-$ifname}" ;; esac } diff --git a/package/base-files/default/sbin/ifup b/package/base-files/default/sbin/ifup index 86d10d7ca3..c7055d4807 100755 --- a/package/base-files/default/sbin/ifup +++ b/package/base-files/default/sbin/ifup @@ -4,7 +4,10 @@ . /sbin/ifdown "$@" config_get iftype "$1" type -config_get ifname "$1" ifname +case "$iftype" in + bridge) config_get ifname "$1" ifnames;; + *) config_get ifname "$1" ifname;; +esac for dev in $ifname; do setup_interface "$dev" "$1" -- cgit v1.2.3