aboutsummaryrefslogtreecommitdiffstats
path: root/package/base-files/files
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2006-11-22 23:30:57 +0000
committerFelix Fietkau <nbd@openwrt.org>2006-11-22 23:30:57 +0000
commit59a06c71cbf7ee5ecb453bbb2e9d4c2df6f194ed (patch)
treeb8c70b7085d8a3e66a6b3bf434ae1ec1ecc9f4d6 /package/base-files/files
parent37362df7ea5978750f4584d2ce48623c59ef0695 (diff)
downloadupstream-59a06c71cbf7ee5ecb453bbb2e9d4c2df6f194ed.tar.gz
upstream-59a06c71cbf7ee5ecb453bbb2e9d4c2df6f194ed.tar.bz2
upstream-59a06c71cbf7ee5ecb453bbb2e9d4c2df6f194ed.zip
rename default/ to files/
SVN-Revision: 5622
Diffstat (limited to 'package/base-files/files')
-rwxr-xr-xpackage/base-files/files/bin/ipcalc32
-rwxr-xr-xpackage/base-files/files/bin/login18
-rwxr-xr-xpackage/base-files/files/bin/uci178
-rw-r--r--package/base-files/files/etc/banner10
-rw-r--r--package/base-files/files/etc/config/network13
-rwxr-xr-xpackage/base-files/files/etc/functions.sh149
-rw-r--r--package/base-files/files/etc/group2
-rw-r--r--package/base-files/files/etc/hosts1
-rwxr-xr-xpackage/base-files/files/etc/hotplug.d/block/01-mount26
-rw-r--r--package/base-files/files/etc/hotplug.d/net/10-net35
-rwxr-xr-xpackage/base-files/files/etc/hotplug.d/usb/01-ln33
-rwxr-xr-xpackage/base-files/files/etc/init.d/boot26
-rwxr-xr-xpackage/base-files/files/etc/init.d/network14
-rwxr-xr-xpackage/base-files/files/etc/init.d/rcS19
-rw-r--r--package/base-files/files/etc/inittab3
-rw-r--r--package/base-files/files/etc/ipkg.conf3
-rw-r--r--package/base-files/files/etc/passwd2
-rw-r--r--package/base-files/files/etc/profile12
-rw-r--r--package/base-files/files/etc/protocols56
-rwxr-xr-xpackage/base-files/files/etc/rc.common83
-rw-r--r--package/base-files/files/etc/resolv.conf2
-rw-r--r--package/base-files/files/etc/shells1
-rw-r--r--package/base-files/files/etc/sysctl.conf12
-rw-r--r--package/base-files/files/lib/config/template.awk42
-rw-r--r--package/base-files/files/lib/config/uci-update.awk160
-rwxr-xr-xpackage/base-files/files/lib/config/uci.sh139
-rwxr-xr-xpackage/base-files/files/lib/network/config.sh171
-rw-r--r--package/base-files/files/rom/note3
-rwxr-xr-xpackage/base-files/files/sbin/hotplug26
-rwxr-xr-xpackage/base-files/files/sbin/ifdown55
-rwxr-xr-xpackage/base-files/files/sbin/ifup11
-rwxr-xr-xpackage/base-files/files/sbin/mount_root10
-rwxr-xr-xpackage/base-files/files/sbin/wifi116
-rw-r--r--package/base-files/files/usr/lib/common.awk68
-rwxr-xr-xpackage/base-files/files/usr/share/udhcpc/default.script57
35 files changed, 1588 insertions, 0 deletions
diff --git a/package/base-files/files/bin/ipcalc b/package/base-files/files/bin/ipcalc
new file mode 100755
index 0000000000..e8efa6b96c
--- /dev/null
+++ b/package/base-files/files/bin/ipcalc
@@ -0,0 +1,32 @@
+#!/bin/sh
+
+awk -f /usr/lib/common.awk -f - $* <<EOF
+BEGIN {
+ ipaddr=ip2int(ARGV[1])
+ netmask=ip2int(ARGV[2])
+ network=and(ipaddr,netmask)
+ broadcast=or(network,compl(netmask))
+
+ start=or(network,and(ip2int(ARGV[3]),compl(netmask)))
+ limit=network+1
+ if (start<limit) start=limit
+
+ end=start+ARGV[4]
+ limit=or(network,compl(netmask))-1
+ if (end>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 <ip> <netmask> <start> <num>
+
+ if (ARGC > 3) {
+ print "START="int2ip(start)
+ print "END="int2ip(end-1)
+ }
+}
+EOF
diff --git a/package/base-files/files/bin/login b/package/base-files/files/bin/login
new file mode 100755
index 0000000000..ff5d3660e4
--- /dev/null
+++ b/package/base-files/files/bin/login
@@ -0,0 +1,18 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+grep '^root:[^!]' /etc/passwd >&- 2>&-
+[ "$?" = "0" -a -z "$FAILSAFE" ] &&
+{
+ 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/files/bin/uci b/package/base-files/files/bin/uci
new file mode 100755
index 0000000000..9b50380df2
--- /dev/null
+++ b/package/base-files/files/bin/uci
@@ -0,0 +1,178 @@
+#!/bin/sh
+# Shell script for interacting with config files
+#
+# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
+# Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+. /etc/functions.sh
+include /lib/config
+
+SEP="[^0-9A-Za-z_]"
+
+do_get() {
+ local PACKAGE
+ local CONFIG
+ local OPTION
+ local DUMMY
+
+ strtok "$*" PACKAGE . CONFIG . OPTION $SEP DUMMY
+
+ [ $? -ne 3 ] && {
+ uci_usage get
+ exit 1
+ }
+
+ uci_load "$PACKAGE"
+ config_get "$CONFIG" "$OPTION"
+}
+
+do_set() {
+ local PACKAGE
+ local CONFIG
+ local OPTION
+ local VALUE
+
+ strtok "$1" PACKAGE . CONFIG = VALUE
+ [ $? -ne 3 ] && {
+ uci_usage set
+ exit 1
+ }
+
+ strtok "$CONFIG" CONFIG . OPTION
+
+ if [ $? -eq 1 ]; then
+ uci_add "$PACKAGE" "$VALUE" "$CONFIG"
+ else
+ uci_set "$PACKAGE" "$CONFIG" "$OPTION" "$VALUE"
+ fi
+}
+
+do_rename() {
+ [ $# -ne 3 ] && {
+ uci_usage rename
+ exit 1
+ }
+ uci_rename "$@"
+}
+
+do_remove() {
+ local PACKAGE
+ local CONFIG
+ local OPTION
+ local DUMMY
+
+ strtok "$*" PACKAGE . CONFIG . OPTION $SEP DUMMY
+ [ $? -ne 3 -a $? -ne 2 ] && {
+ uci_usage rename
+ exit 1
+ }
+ uci_remove "$PACKAGE" "$CONFIG" ${OPTION:+"$OPTION"}
+}
+
+do_commit() {
+ local PACKAGE="$1"
+ for package in ${PACKAGE:-$(cd /tmp/.uci; ls)}; do
+ uci_commit "$package"
+ done
+}
+
+do_show() {
+ local PACKAGE
+ local CONFIG
+ local DUMMY
+
+ strtok "$*" PACKAGE . CONFIG $SEP DUMMY
+ [ $? -gt 2 ] && {
+ uci_usage show
+ exit 1
+ }
+
+ for package in ${PACKAGE:-$(cd /etc/config; ls)}; do
+ SECTION=""
+
+ config_cb() {
+ if [ -z "$CONFIG" -o "$CONFIG" = "$2" ]; then
+ append SECTION "$2"
+ option_cb() {
+ append "${CONFIG_SECTION}_VARS" "$1"
+ }
+ else
+ option_cb() {
+ return 0
+ }
+ fi
+ }
+
+ uci_load "$package"
+
+ for section in $SECTION; do
+ config_get type "$section" TYPE
+ [ -z "$type" ] && continue
+ echo "$package.$section=$type"
+ eval "VARS=\"\${${section}_VARS}\""
+ for var in $VARS; do
+ config_get val "$section" "$var"
+ [ -n "$val" ] && {
+ echo "$package.$section.$var=$val"
+ config_set "$section" "$var" ""
+ }
+ done
+ config_set "$section" TYPE ""
+ done
+ done
+}
+
+uci_usage() {
+ case "$1" in
+ show) echo "$0 show [<package>[.<config>]]";;
+ get) echo "$0 get <package>.<config>.<option>";;
+ set) echo "$0 set <package>.<config>[.<option>]=<value>";;
+ del) echo "$0 del <package>.<config>[.<option>]";;
+ rename) echo "$0 rename <package> <config> <name>";;
+ commit) echo "$0 commit [<package> ... ]";;
+ *)
+ echo "Syntax: $0 <command> <arguments...>"
+ echo
+ uci_usage show
+ uci_usage get
+ uci_usage set
+ uci_usage del
+ uci_usage rename
+ uci_usage commit
+ echo
+ exit 1
+ ;;
+ esac
+}
+
+if [ $# -eq 0 ] ; then
+ uci_usage
+ exit 0
+fi
+
+local CMD="$1"
+shift
+case "$CMD" in
+ set) do_set "$@";;
+ del) do_remove "$@";;
+ rename) do_rename "$@";;
+ get) do_get "$@";;
+ show) do_show "$@";;
+ commit) do_commit "$@";;
+ *) uci_usage;;
+esac
+exit 0
diff --git a/package/base-files/files/etc/banner b/package/base-files/files/etc/banner
new file mode 100644
index 0000000000..c2fbc12680
--- /dev/null
+++ b/package/base-files/files/etc/banner
@@ -0,0 +1,10 @@
+ _______ ________ __
+ | |.-----.-----.-----.| | | |.----.| |_
+ | - || _ | -__| || | | || _|| _|
+ |_______|| __|_____|__|__||________||__| |____|
+ |__| W I R E L E S S F R E E D O M
+ KAMIKAZE (bleeding edge, $R) -------------------
+ * 10 oz Vodka Shake well with ice and strain
+ * 10 oz Triple sec mixture into 10 shot glasses.
+ * 10 oz lime juice Salute!
+ ---------------------------------------------------
diff --git a/package/base-files/files/etc/config/network b/package/base-files/files/etc/config/network
new file mode 100644
index 0000000000..1d5ded3728
--- /dev/null
+++ b/package/base-files/files/etc/config/network
@@ -0,0 +1,13 @@
+# Copyright (C) 2006 OpenWrt.org
+
+config interface loopback
+ option ifname lo
+ option proto static
+ option ipaddr 127.0.0.1
+ option netmask 255.0.0.0
+
+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/files/etc/functions.sh b/package/base-files/files/etc/functions.sh
new file mode 100755
index 0000000000..bf412df6d5
--- /dev/null
+++ b/package/base-files/files/etc/functions.sh
@@ -0,0 +1,149 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+# Copyright (C) 2006 Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
+
+alias debug=${DEBUG:-:}
+
+# newline
+readonly N="
+"
+
+_C=0
+
+hotplug_dev() {
+ env -i ACTION=$1 INTERFACE=$2 /sbin/hotplug net
+}
+
+append() {
+ local var="$1"
+ local value="$2"
+ local sep="${3:- }"
+
+ eval "export -n -- \"$var=\${$var:+\${$var}\${value:+\$sep}}\$value\""
+}
+
+reset_cb() {
+ config_cb() { return 0; }
+ option_cb() { return 0; }
+}
+reset_cb
+
+config () {
+ local cfgtype="$1"
+ local name="$2"
+
+ _C=$((_C + 1))
+ name="${name:-cfg${_C}}"
+ config_cb "$cfgtype" "$name"
+ CONFIG_SECTION="$name"
+ export -n "CONFIG_${CONFIG_SECTION}_TYPE=$cfgtype"
+}
+
+option () {
+ local varname="$1"; shift
+ local value="$*"
+
+ export -n "CONFIG_${CONFIG_SECTION}_${varname}=$value"
+ option_cb "$varname" "$*"
+}
+
+config_rename() {
+ local OLD="$1"
+ local NEW="$2"
+ local oldvar
+ local newvar
+
+ [ "$OLD" -a "$NEW" ] || return
+ for oldvar in `set | grep ^CONFIG_${OLD}_ | \
+ sed -e 's/\(.*\)=.*$/\1/'` ; do
+ newvar="CONFIG_${NEW}_${oldvar##CONFIG_${OLD}_}"
+ eval "export -n \"$newvar=\${$oldvar}\""
+ unset "$oldvar"
+ done
+
+ [ "$CONFIG_SECTION" = "$OLD" ] && CONFIG_SECTION="$NEW"
+}
+
+config_unset() {
+ config_set "$1" "$2" ""
+}
+
+config_clear() {
+ local SECTION="$1"
+ local oldvar
+
+ for oldvar in `set | grep ^CONFIG_${SECTION}_ | \
+ sed -e 's/\(.*\)=.*$/\1/'` ; do
+ unset $oldvar
+ done
+}
+
+config_load() {
+ local file="/etc/config/$1"
+ _C=0
+ CONFIG_SECTION=
+
+ [ -e "$file" ] && {
+ . $file
+ } || return 1
+
+ ${CONFIG_SECTION:+config_cb}
+}
+
+config_get() {
+ case "$3" in
+ "") eval "echo \"\${CONFIG_${1}_${2}}\"";;
+ *) eval "export -n -- \"$1=\${CONFIG_${2}_${3}}\"";;
+ esac
+}
+
+config_set() {
+ local section="$1"
+ local option="$2"
+ local value="$3"
+ export -n "CONFIG_${section}_${option}=$value"
+}
+
+load_modules() {
+ sed 's/^[^#]/insmod &/' $* | ash 2>&- || :
+}
+
+include() {
+ local file
+
+ for file in $(ls $1/*.sh 2>/dev/null); do
+ . $file
+ done
+}
+
+find_mtd_part() {
+ local PART="$(grep "\"$1\"" /proc/mtd | awk -F: '{print $1}')"
+
+ PART="${PART##mtd}"
+ echo "${PART:+/dev/mtdblock/$PART}"
+}
+
+strtok() { # <string> { <variable> [<separator>] ... }
+ local tmp
+ local val="$1"
+ local count=0
+
+ shift
+
+ while [ $# -gt 1 ]; do
+ tmp="${val%%$2*}"
+
+ [ "$tmp" = "$val" ] && break
+
+ val="${val#$tmp$2}"
+
+ export -n "$1=$tmp"; count=$((count+1))
+ shift 2
+ done
+
+ if [ $# -gt 0 -a "$val" ]; then
+ export -n "$1=$val"; count=$((count+1))
+ fi
+
+ return $count
+}
diff --git a/package/base-files/files/etc/group b/package/base-files/files/etc/group
new file mode 100644
index 0000000000..c4e77f316a
--- /dev/null
+++ b/package/base-files/files/etc/group
@@ -0,0 +1,2 @@
+root:x:0:
+nogroup:x:65534:
diff --git a/package/base-files/files/etc/hosts b/package/base-files/files/etc/hosts
new file mode 100644
index 0000000000..ce138ec1e6
--- /dev/null
+++ b/package/base-files/files/etc/hosts
@@ -0,0 +1 @@
+127.0.0.1 localhost OpenWrt
diff --git a/package/base-files/files/etc/hotplug.d/block/01-mount b/package/base-files/files/etc/hotplug.d/block/01-mount
new file mode 100755
index 0000000000..db8ccdabd6
--- /dev/null
+++ b/package/base-files/files/etc/hotplug.d/block/01-mount
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+DEV=${DEVPATH##*/}
+{
+echo "ACTION=$ACTION DEVPATH=$DEVPATH $0 $*"
+case "$ACTION" in
+add)
+ echo -ne "waiting for $DEV"
+ while [ ! -b /dev/$DEV ]; do {
+ echo -ne "."
+ sleep 1
+ time=$((time+1)); [ $time -gt 10 ] && break
+ }; done
+
+ [ ${DEV%%[0-9]} != ${DEV} ] && {
+ mkdir -p /tmp/$DEV
+ mount /dev/$DEV /tmp/$DEV -t auto -o sync
+ }
+ ;;
+remove)
+ umount /tmp/$DEV && rmdir /tmp/$DEV
+ rm -f /dev/$DEV /tmp/$DEV
+ ;;
+esac
+} 2>&1 | logger
diff --git a/package/base-files/files/etc/hotplug.d/net/10-net b/package/base-files/files/etc/hotplug.d/net/10-net
new file mode 100644
index 0000000000..9b72338ce8
--- /dev/null
+++ b/package/base-files/files/etc/hotplug.d/net/10-net
@@ -0,0 +1,35 @@
+# Copyright (C) 2006 OpenWrt.org
+
+include /lib/network
+
+addif() {
+ scan_interfaces
+ local cfg="$(find_config "$INTERFACE")"
+
+ # check the autoload setting
+ config_get auto "$cfg" auto
+ case "$auto" in
+ 1|on|enabled) setup_interface "$INTERFACE";;
+ esac
+
+
+ # 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" device
+ for dev in $ifs; do
+ [ "${dev%%\.*}" = "$INTERFACE" -a "$dev" != "$INTERFACE" ] && {
+ add_vlan "$dev"
+ }
+ done
+ done
+}
+
+case "$ACTION" in
+ add|register)
+ case "$PHYSDEVDRIVER" in
+ natsemi) sleep 1;;
+ esac
+ addif
+ ;;
+esac
diff --git a/package/base-files/files/etc/hotplug.d/usb/01-ln b/package/base-files/files/etc/hotplug.d/usb/01-ln
new file mode 100755
index 0000000000..f9eda02988
--- /dev/null
+++ b/package/base-files/files/etc/hotplug.d/usb/01-ln
@@ -0,0 +1,33 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+case "$ACTION" in
+add)
+ [ -f /sys/${DEVPATH}/idVendor -a "$(cat /sys/${DEVPATH}/idVendor)" -ne "0000" ] && {
+ cd /sys/${DEVPATH}
+
+ NUM=${DEVPATH##*/}
+ HOST=$(find ${NUM}:*/host* -type d)
+ HOST=${HOST##*/host}
+
+ echo -ne "waiting for disk"
+
+ while [ ! -d "/dev/scsi/host${HOST}/bus0/target0/lun0" ]; do {
+ echo -ne "."
+ sleep 1;
+ time=$((time+1)); [ $time -gt 10 ] && break
+ }; done
+ echo
+
+ cd /sys/bus/scsi/devices/${HOST}\:0\:0\:0
+ for BLOCK in block:* ; do {
+ cd ${BLOCK}
+ BLOCK=${BLOCK##block\:}
+ ln -sf /dev/scsi/host${HOST}/bus0/target0/lun0/disc /dev/${BLOCK}
+ for DEV in ${BLOCK}*; do {
+ ln -sf /dev/scsi/host${HOST}/bus0/target0/lun0/part${DEV##$BLOCK} /dev/$DEV
+ }; done
+ }; done
+ } 2>&1 | logger
+ ;;
+esac
diff --git a/package/base-files/files/etc/init.d/boot b/package/base-files/files/etc/init.d/boot
new file mode 100755
index 0000000000..c583652347
--- /dev/null
+++ b/package/base-files/files/etc/init.d/boot
@@ -0,0 +1,26 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006 OpenWrt.org
+
+START=10
+start() {
+ [ -f /proc/mounts ] || /sbin/mount_root
+ [ -f /proc/jffs2_bbc ] && echo "S" > /proc/jffs2_bbc
+ 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
+
+ # manually trigger hotplug before loading modules
+ for iface in $(awk -F: '/:/ {print $1}' /proc/net/dev); do
+ /usr/bin/env -i ACTION=add INTERFACE="$iface" /sbin/hotplug net
+ done
+
+ load_modules /etc/modules.d/*
+}
diff --git a/package/base-files/files/etc/init.d/network b/package/base-files/files/etc/init.d/network
new file mode 100755
index 0000000000..45d5311a7a
--- /dev/null
+++ b/package/base-files/files/etc/init.d/network
@@ -0,0 +1,14 @@
+#!/bin/sh /etc/rc.common
+# Copyright (C) 2006 OpenWrt.org
+
+START=40
+start() {
+ setup_switch() { return 0; }
+
+ include /lib/network
+ setup_switch
+ [ -e /etc/config/wireless ] || \
+ /sbin/wifi detect > /etc/config/wireless
+ /sbin/wifi up
+}
+
diff --git a/package/base-files/files/etc/init.d/rcS b/package/base-files/files/etc/init.d/rcS
new file mode 100755
index 0000000000..fe21d0398c
--- /dev/null
+++ b/package/base-files/files/etc/init.d/rcS
@@ -0,0 +1,19 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+${FAILSAFE:+exit}
+
+# 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
+
+(
+ for i in /etc/rc.d/S*; do
+ $i boot 2>&1
+ done
+
+ sysctl -p >&-
+) | logger -s -p 6 -t '' &
diff --git a/package/base-files/files/etc/inittab b/package/base-files/files/etc/inittab
new file mode 100644
index 0000000000..39e134cb16
--- /dev/null
+++ b/package/base-files/files/etc/inittab
@@ -0,0 +1,3 @@
+::sysinit:/etc/init.d/rcS
+tts/0::askfirst:/bin/ash --login
+#tts/1::askfirst:/bin/ash --login
diff --git a/package/base-files/files/etc/ipkg.conf b/package/base-files/files/etc/ipkg.conf
new file mode 100644
index 0000000000..2931d2cf80
--- /dev/null
+++ b/package/base-files/files/etc/ipkg.conf
@@ -0,0 +1,3 @@
+src snapshots http://openwrt.org/downloads/snapshots/$S/packages
+dest root /
+dest ram /tmp
diff --git a/package/base-files/files/etc/passwd b/package/base-files/files/etc/passwd
new file mode 100644
index 0000000000..3b660a0d4e
--- /dev/null
+++ b/package/base-files/files/etc/passwd
@@ -0,0 +1,2 @@
+root:!:0:0:root:/tmp:/bin/ash
+nobody:*:65534:65534:nobody:/var:/bin/false
diff --git a/package/base-files/files/etc/profile b/package/base-files/files/etc/profile
new file mode 100644
index 0000000000..ae514b0924
--- /dev/null
+++ b/package/base-files/files/etc/profile
@@ -0,0 +1,12 @@
+#!/bin/sh
+[ -f /etc/banner ] && cat /etc/banner
+
+export PATH=/bin:/sbin:/usr/bin:/usr/sbin
+export PS1='\u@\h:\w\$ '
+
+alias more=less
+[ -x /usr/bin/vim ] || 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/files/etc/protocols b/package/base-files/files/etc/protocols
new file mode 100644
index 0000000000..53fecb6d3c
--- /dev/null
+++ b/package/base-files/files/etc/protocols
@@ -0,0 +1,56 @@
+# Internet (IP) protocols
+#
+# Updated from http://www.iana.org/assignments/protocol-numbers and other
+# sources.
+# New protocols will be added on request if they have been officially
+# assigned by IANA and are not historical.
+# If you need a huge list of used numbers please install the nmap package.
+
+ip 0 IP # internet protocol, pseudo protocol number
+#hopopt 0 HOPOPT # IPv6 Hop-by-Hop Option [RFC1883]
+icmp 1 ICMP # internet control message protocol
+igmp 2 IGMP # Internet Group Management
+ggp 3 GGP # gateway-gateway protocol
+ipencap 4 IP-ENCAP # IP encapsulated in IP (officially ``IP'')
+st 5 ST # ST datagram mode
+tcp 6 TCP # transmission control protocol
+egp 8 EGP # exterior gateway protocol
+igp 9 IGP # any private interior gateway (Cisco)
+pup 12 PUP # PARC universal packet protocol
+udp 17 UDP # user datagram protocol
+hmp 20 HMP # host monitoring protocol
+xns-idp 22 XNS-IDP # Xerox NS IDP
+rdp 27 RDP # "reliable datagram" protocol
+iso-tp4 29 ISO-TP4 # ISO Transport Protocol class 4 [RFC905]
+xtp 36 XTP # Xpress Transfer Protocol
+ddp 37 DDP # Datagram Delivery Protocol
+idpr-cmtp 38 IDPR-CMTP # IDPR Control Message Transport
+ipv6 41 IPv6 # Internet Protocol, version 6
+ipv6-route 43 IPv6-Route # Routing Header for IPv6
+ipv6-frag 44 IPv6-Frag # Fragment Header for IPv6
+idrp 45 IDRP # Inter-Domain Routing Protocol
+rsvp 46 RSVP # Reservation Protocol
+gre 47 GRE # General Routing Encapsulation
+esp 50 IPSEC-ESP # Encap Security Payload [RFC2046]
+ah 51 IPSEC-AH # Authentication Header [RFC2402]
+skip 57 SKIP # SKIP
+ipv6-icmp 58 IPv6-ICMP # ICMP for IPv6
+ipv6-nonxt 59 IPv6-NoNxt # No Next Header for IPv6
+ipv6-opts 60 IPv6-Opts # Destination Options for IPv6
+rspf 73 RSPF CPHB # Radio Shortest Path First (officially CPHB)
+vmtp 81 VMTP # Versatile Message Transport
+eigrp 88 EIGRP # Enhanced Interior Routing Protocol (Cisco)
+ospf 89 OSPFIGP # Open Shortest Path First IGP
+ax.25 93 AX.25 # AX.25 frames
+ipip 94 IPIP # IP-within-IP Encapsulation Protocol
+etherip 97 ETHERIP # Ethernet-within-IP Encapsulation [RFC3378]
+encap 98 ENCAP # Yet Another IP encapsulation [RFC1241]
+# 99 # any private encryption scheme
+pim 103 PIM # Protocol Independent Multicast
+ipcomp 108 IPCOMP # IP Payload Compression Protocol
+vrrp 112 VRRP # Virtual Router Redundancy Protocol
+l2tp 115 L2TP # Layer Two Tunneling Protocol [RFC2661]
+isis 124 ISIS # IS-IS over IPv4
+sctp 132 SCTP # Stream Control Transmission Protocol
+fc 133 FC # Fibre Channel
+
diff --git a/package/base-files/files/etc/rc.common b/package/base-files/files/etc/rc.common
new file mode 100755
index 0000000000..7180b0f7fa
--- /dev/null
+++ b/package/base-files/files/etc/rc.common
@@ -0,0 +1,83 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+. $IPKG_INSTROOT/etc/functions.sh
+
+START=50
+
+start() {
+ return 0
+}
+
+stop() {
+ return 0
+}
+
+reload() {
+ return 1
+}
+
+restart() {
+ stop
+ start
+}
+
+boot() {
+ start
+}
+
+shutdown() {
+ return 0
+}
+
+disable() {
+ name="$(basename "${initscript}")"
+ rm -f "$IPKG_INSTROOT"/etc/rc.d/S??$name
+}
+
+enable() {
+ name="$(basename "${initscript}")"
+ disable
+ ln -s "/etc/init.d/$name" "$IPKG_INSTROOT/etc/rc.d/S${START}${name##S[0-9][0-9]}"
+}
+
+depends() {
+ return 0
+}
+
+help() {
+ cat <<EOF
+Syntax: $initscript [command]
+
+Available commands:
+ start Start the service
+ stop Stop the service
+ restart Restart the service
+ reload Reload configuration files (or restart if that fails)
+ enable Enable service autostart
+ disable Disable service autostart
+$EXTRA_HELP
+EOF
+}
+
+initscript="$1"
+action="$2"
+
+. "$initscript"
+
+cmds=
+for cmd in $EXTRA_COMMANDS; do
+ cmds="${cmds:+$cmds$N}$cmd) $cmd;;"
+done
+eval "case \"\$action\" in
+ start) start;;
+ stop) stop;;
+ reload) reload || restart;;
+ restart) restart;;
+ boot) boot;;
+ shutdown) shutdown;;
+ enable) enable;;
+ disable) disable;;
+ $cmds
+ *) help;;
+esac"
diff --git a/package/base-files/files/etc/resolv.conf b/package/base-files/files/etc/resolv.conf
new file mode 100644
index 0000000000..9617eacda7
--- /dev/null
+++ b/package/base-files/files/etc/resolv.conf
@@ -0,0 +1,2 @@
+nameserver 127.0.0.1
+search lan
diff --git a/package/base-files/files/etc/shells b/package/base-files/files/etc/shells
new file mode 100644
index 0000000000..006aa38ced
--- /dev/null
+++ b/package/base-files/files/etc/shells
@@ -0,0 +1 @@
+/bin/ash
diff --git a/package/base-files/files/etc/sysctl.conf b/package/base-files/files/etc/sysctl.conf
new file mode 100644
index 0000000000..e60038cf35
--- /dev/null
+++ b/package/base-files/files/etc/sysctl.conf
@@ -0,0 +1,12 @@
+kernel.panic=3
+net.ipv4.conf.default.arp_ignore=1
+net.ipv4.conf.all.arp_ignore=1
+net.ipv4.ip_forward=1
+net.ipv4.icmp_echo_ignore_broadcasts=1
+net.ipv4.icmp_ignore_bogus_error_responses=1
+net.ipv4.tcp_fin_timeout=30
+net.ipv4.tcp_keepalive_time=120
+net.ipv4.tcp_syncookies=1
+net.ipv4.tcp_timestamps=0
+net.ipv4.ip_conntrack_tcp_timeouts="300 43200 120 60 120 120 10 60 30 120"
+net.ipv4.ip_conntrack_udp_timeouts="60 180"
diff --git a/package/base-files/files/lib/config/template.awk b/package/base-files/files/lib/config/template.awk
new file mode 100644
index 0000000000..faae8b345c
--- /dev/null
+++ b/package/base-files/files/lib/config/template.awk
@@ -0,0 +1,42 @@
+# Copyright (C) 2006 OpenWrt.org
+
+{
+ 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 !~ /^@[a-zA-Z0-9_]/) && (noprint != 1) {
+ n=split(line "@@", a, /@@/)
+ for (i=1; i<=n; i++) {
+ if ((i % 2) == 1) printf "%s" a[i]
+ else printf "%s" v[a[i]]
+ }
+ print ""
+}
+
+$1 == "@endif" {
+ if_open = 0
+ noprint = 0
+}
diff --git a/package/base-files/files/lib/config/uci-update.awk b/package/base-files/files/lib/config/uci-update.awk
new file mode 100644
index 0000000000..efa8758507
--- /dev/null
+++ b/package/base-files/files/lib/config/uci-update.awk
@@ -0,0 +1,160 @@
+# Configuration update functions
+#
+# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
+# Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+function read_file(filename, result) {
+ while ((getline <filename) == 1) {
+ result = result $0 "\n"
+ }
+ gsub(/\n*$/, "", result)
+ return result
+}
+
+function cmd2option(str, tmp) {
+ if (match(str,"=")!=0) {
+ res = "\toption " substr(str,1,RSTART-1) "\t'" substr(str,RSTART+1) "'"
+ } else {
+ res= ""
+ }
+ return res
+}
+
+function cmd2config(atype, aname) {
+ return "config \"" atype "\" \"" aname "\""
+}
+
+function update_config(cfg, update, \
+ lines, line, l, n, i, i2, section, scnt, remove, tmp, aidx, rest) {
+ scnt = 1
+ linecnt=split(cfg "\n", lines, "\n")
+
+ cfg = ""
+ for (n = 1; n < linecnt; n++) {
+ # stupid parser for quoted arguments (e.g. for the type string).
+ # not to be used to gather variable values (backslash escaping doesn't work)
+ line = lines[n]
+ gsub(/^[ \t]*/, "", line)
+ gsub(/#.*$/, "", line)
+ i2 = 1
+ delete l
+ rest = line
+ while (length(rest)) {
+ if (match(rest, /[ \t\"]+/)) {
+ if (RSTART>1) {
+ l[i2] = substr(rest,1,RSTART-1)
+ i2++
+ }
+ aidx=index(rest,"\"")
+ if (aidx>=RSTART && aidx<=RSTART+RLENGTH) {
+ rest=substr(rest,aidx+1)
+ # find the end of the string
+ match(rest,/\"/)
+ l[i2]=substr(rest,1,RSTART-1)
+ i2++
+ }
+ rest=substr(rest,RSTART+RLENGTH)
+ } else {
+ l[i2] = rest
+ i2++
+ rest = ""
+ }
+ }
+ line = lines[n]
+
+ # when a command wants to set a config value for the current
+ # section and a blank line is encountered before an option with
+ # the same name, insert it here to maintain some coherency between
+ # manually and automatically created option lines
+ # if an option with the same name appears after this point, simply
+ # ignore it, because it is already set.
+ if ((section != "") && (l[1] != "option")) {
+ if (line ~ /^[ \t]*$/) {
+ if (update ~ "^" section "\\.") {
+ gsub("^" section ".", "", update)
+ cfg = cfg cmd2option(update) "\n"
+ gsub(/=.*$/, "", update)
+ update = "-" section "." update
+ }
+ }
+ }
+
+ if (l[1] == "config") {
+ # look for all unset values
+ if (section != "") {
+ flag=0
+ if (update ~ "^" section "\\.") {
+ flag=1
+ gsub("^" section ".", "", update)
+ cfg = cfg cmd2option(update) "\n"
+
+ update = "-" section "." update
+ }
+ if (flag!=0) cfg = cfg "\n"
+ }
+
+ remove = ""
+ section = l[3]
+ if (!length(section)) {
+ section = "cfg" scnt
+ }
+ scnt++
+ if (update == "-" section) {
+ remove = "section"
+ update = ""
+ } else if (update ~ "^@" section "=") {
+ update = ""
+ } else if (update ~ "^&" section "=") {
+ gsub("^&" section "=", "", update)
+ line = cmd2config(l[2],update)
+ update = ""
+ }
+ }
+ if (remove == "option") remove = ""
+ if (l[1] == "option") {
+ if (update ~ "^-" section "\\." l[2] "$") remove = "option"
+ # if a supplied config value already exists, replace the whole line
+ if (match(update, "^" section "." l[2] "=")) {
+ gsub("^" section ".", "", update)
+ line = cmd2option(update)
+ update = ""
+ }
+ }
+ if (remove == "") cfg = cfg line "\n"
+ }
+
+ # any new options for the last section??
+ if (section != "") {
+ if (update ~ "^" section "\\.") {
+ gsub("^" section ".", "", update)
+ cfg = cfg cmd2option(update) "\n"
+
+ update = "-" section "." update
+ }
+ }
+
+ if (update ~ "^@") {
+ # new section
+ section = stype = substr(update,2)
+ gsub(/=.*$/,"",section)
+ gsub(/^.*=/,"",stype)
+ cfg = cfg "\nconfig \"" stype "\" \"" section "\"\n"
+ }
+
+ return cfg
+}
diff --git a/package/base-files/files/lib/config/uci.sh b/package/base-files/files/lib/config/uci.sh
new file mode 100755
index 0000000000..957c1bb7ca
--- /dev/null
+++ b/package/base-files/files/lib/config/uci.sh
@@ -0,0 +1,139 @@
+#!/bin/sh
+# Shell script defining macros for manipulating config files
+#
+# Copyright (C) 2006 by Fokus Fraunhofer <carsten.tittel@fokus.fraunhofer.de>
+# Copyright (C) 2006 by Felix Fietkau <nbd@openwrt.org>
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+# General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+uci_load() {
+ local PACKAGE="$1"
+ config_load "$PACKAGE"
+ local PACKAGE_BASE="$(basename "$PACKAGE")"
+ [ -f "/tmp/.uci/${PACKAGE_BASE}" ] && {
+ . "/tmp/.uci/${PACKAGE_BASE}"
+ config_cb
+ }
+}
+
+uci_do_update() {
+ local FILENAME="$1"
+ local UPDATE="$2"
+ awk -f /lib/config/uci-update.awk -f - <<EOF
+BEGIN {
+ config = read_file("$FILENAME")
+ $UPDATE
+ print config
+}
+EOF
+}
+
+uci_add_update() {
+ local PACKAGE="$1"
+ local UPDATE="$2"
+ local PACKAGE_BASE="$(basename "$PACKAGE")"
+
+ # FIXME: add locking?
+ mkdir -p "/tmp/.uci"
+ echo "$UPDATE" >> "/tmp/.uci/${PACKAGE_BASE}"
+}
+
+uci_set() {
+ local PACKAGE="$1"
+ local CONFIG="$2"
+ local OPTION="$3"
+ local VALUE="$4"
+
+ ( # spawn a subshell so you don't mess up the current environment
+ uci_load "$PACKAGE"
+ config_get type "$CONFIG" TYPE
+ [ -z "$type" ]
+ ) || uci_add_update "$PACKAGE" "CONFIG_SECTION='$CONFIG'${N}option '$OPTION' '$VALUE'"
+}
+
+uci_add() {
+ local PACKAGE="$1"
+ local TYPE="$2"
+ local CONFIG="$3"
+
+ uci_add_update "$PACKAGE" "config '$TYPE' '$CONFIG'"
+}
+
+uci_rename() {
+ local PACKAGE="$1"
+ local CONFIG="$2"
+ local VALUE="$3"
+
+ uci_add_update "$PACKAGE" "config_rename '$CONFIG' '$VALUE'"
+}
+
+uci_remove() {
+ local PACKAGE="$1"
+ local CONFIG="$2"
+ local OPTION="$3"
+
+ if [ -z "$OPTION" ]; then
+ uci_add_update "$PACKAGE" "config_clear '$CONFIG'"
+ else
+ uci_add_update "$PACKAGE" "config_unset '$CONFIG' '$OPTION'"
+ fi
+}
+
+uci_commit() {
+ local PACKAGE="$1"
+ local PACKAGE_BASE="$(basename "$PACKAGE")"
+
+ mkdir -p /tmp/.uci
+ lock "/tmp/.uci/$PACKAGE_BASE.lock"
+ [ -f "/tmp/.uci/$PACKAGE_BASE" ] && (
+ updatestr=""
+
+ # replace handlers
+ config() {
+ append updatestr "config = update_config(config, \"@$2=$1\")" "$N"
+ }
+ option() {
+ append updatestr "config = update_config(config, \"$CONFIG_SECTION.$1=$2\")" "$N"
+ }
+ config_rename() {
+ append updatestr "config = update_config(config, \"&$1=$2\")" "$N"
+ }
+ config_unset() {
+ append updatestr "config = update_config(config, \"-$1.$2\")" "$N"
+ }
+ config_clear() {
+ append updatestr "config = update_config(config, \"-$1\")" "$N"
+ }
+
+ . "/tmp/.uci/$PACKAGE_BASE"
+
+ # completely disable handlers so that they don't get in the way
+ config() {
+ return 0
+ }
+ option() {
+ return 0
+ }
+
+ config_load "$PACKAGE" || CONFIG_FILENAME="$ROOT/etc/config/$PACKAGE_BASE"
+ uci_do_update "$CONFIG_FILENAME" "$updatestr" > "/tmp/.uci/$PACKAGE_BASE.new" && {
+ mv -f "/tmp/.uci/$PACKAGE_BASE.new" "$CONFIG_FILENAME" && \
+ rm -f "/tmp/.uci/$PACKAGE_BASE"
+ }
+ )
+ lock -u "/tmp/.uci/$PACKAGE_BASE.lock"
+}
+
+
diff --git a/package/base-files/files/lib/network/config.sh b/package/base-files/files/lib/network/config.sh
new file mode 100755
index 0000000000..90f5bf7424
--- /dev/null
+++ b/package/base-files/files/lib/network/config.sh
@@ -0,0 +1,171 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+# DEBUG="echo"
+
+find_config() {
+ local iftype device iface ifaces ifn
+ for ifn in $interfaces; do
+ config_get iftype "$ifn" type
+ config_get iface "$ifn" ifname
+ case "$iftype" in
+ bridge) config_get ifaces "$ifn" ifnames;;
+ esac
+ config_get device "$ifn" device
+ for ifc in $device $iface $ifaces; do
+ [ "$ifc" = "$1" ] && {
+ echo "$ifn"
+ return 0
+ }
+ done
+ done
+
+ return 1;
+}
+
+scan_interfaces() {
+ local mode iftype iface ifname device
+ interfaces=
+ config_cb() {
+ case "$1" in
+ interface)
+ config_set "$2" auto 1
+ ;;
+ esac
+ config_get iftype "$CONFIG_SECTION" TYPE
+ case "$iftype" in
+ interface)
+ config_get proto "$CONFIG_SECTION" proto
+ append interfaces "$CONFIG_SECTION"
+ config_get iftype "$CONFIG_SECTION" type
+ config_get ifname "$CONFIG_SECTION" ifname
+ config_set "$CONFIG_SECTION" device "$ifname"
+ case "$iftype" in
+ bridge)
+ 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'"
+ ;;
+ 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
+
+ [ -n "$config" ] || {
+ config=$(find_config "$iface")
+ [ "$?" = 0 ] || return 1
+ }
+
+ proto="${3:-$(config_get "$config" proto)}"
+ config_get iftype "$config" type
+
+ ifconfig "$iface" 2>/dev/null >/dev/null && {
+ # make sure the interface is removed from any existing bridge
+ unbridge "$iface"
+ }
+
+ # Setup VLAN interfaces
+ add_vlan "$iface"
+
+ # Setup bridging
+ case "$iftype" in
+ bridge)
+ ifconfig "$iface" up 2>/dev/null >/dev/null
+ ifconfig "br-$config" 2>/dev/null >/dev/null && {
+ $DEBUG brctl addif "br-$config" "$iface"
+ return 0
+ } || {
+ $DEBUG brctl addbr "br-$config"
+ $DEBUG brctl setfd "br-$config" 0
+ $DEBUG brctl addif "br-$config" "$iface"
+ iface="br-$config"
+ }
+ ;;
+ 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)
+ # prevent udhcpc from starting more than once
+ lock "/var/lock/dhcp-$iface"
+ pid="$(cat "$pidfile" 2>/dev/null)"
+ [ -d "/proc/$pid" ] && grep udhcpc "/proc/${pid}/cmdline" >/dev/null 2>/dev/null && {
+ lock -u "/var/lock/dhcp-$iface"
+ return 0
+ }
+
+ 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 eval udhcpc -t 0 -i "$iface" ${ipaddr:+-r $ipaddr} ${hostname:+-H $hostname} -b -p "$pidfile" ${dhcpopts:- -R &}
+ lock -u "/var/lock/dhcp-$iface"
+ ;;
+ *)
+ 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
+}
+
+unbridge() {
+ local dev="$1"
+ local brdev
+
+ brctl show | grep "$dev" >/dev/null && {
+ # interface is still part of a bridge, correct that
+
+ for brdev in $(brctl show | awk '$2 ~ /^[0-9].*\./ { print $1 }'); do
+ brctl delif "$brdev" "$dev" 2>/dev/null >/dev/null
+ done
+ }
+}
diff --git a/package/base-files/files/rom/note b/package/base-files/files/rom/note
new file mode 100644
index 0000000000..1746eb0509
--- /dev/null
+++ b/package/base-files/files/rom/note
@@ -0,0 +1,3 @@
+SQUASHFS USERS:
+After firstboot has been run, / will be jffs2 and /rom will be squashfs
+(* except when in failsafe)
diff --git a/package/base-files/files/sbin/hotplug b/package/base-files/files/sbin/hotplug
new file mode 100755
index 0000000000..b1b6f97b23
--- /dev/null
+++ b/package/base-files/files/sbin/hotplug
@@ -0,0 +1,26 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+# 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"
+ cp "/lib/firmware/$FIRMWARE" "/sys$DEVPATH/data"
+ echo 0 > "/sys$DEVPATH/loading"
+ }
+ exit 0
+}
+
+. /etc/functions.sh
+
+PATH=/bin:/sbin:/usr/bin:/usr/sbin
+LOGNAME=root
+USER=root
+export PATH LOGNAME USER
+
+[ \! -z "$1" -a -d /etc/hotplug.d/$1 ] && {
+ for script in $(ls /etc/hotplug.d/$1/* 2>&-); do (
+ [ -f $script ] && . $script
+ ); done
+}
diff --git a/package/base-files/files/sbin/ifdown b/package/base-files/files/sbin/ifdown
new file mode 100755
index 0000000000..26d0e626d2
--- /dev/null
+++ b/package/base-files/files/sbin/ifdown
@@ -0,0 +1,55 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+[ $# = 0 ] && { echo " $0 <group>"; exit; }
+. /etc/functions.sh
+include /lib/network
+scan_interfaces
+
+cfg=$1
+debug "### ifdown $cfg ###"
+
+config_get proto "$cfg" proto
+[ -z "$proto" ] && { echo "interface not found."; exit; }
+
+config_get iface "$cfg" device
+[ "$proto" = "static" ] && {
+ env -i ACTION="ifdown" INTERFACE="$config" DEVICE="$iface" PROTO=static /sbin/hotplug "iface" &
+}
+
+# call interface stop handler
+( type "stop_interface_$proto" ) >/dev/null 2>/dev/null && eval "stop_interface_$proto '$cfg'"
+
+# make sure all locks are removed
+for lock in "/var/lock/dhcp-$iface" "/var/lock/ppp-$iface"; do
+ [ -f "$lock" ] && {
+ lock -u "$lock"
+ sleep 1
+ }
+done
+
+# kill active ppp daemon and other processes
+config_get ifname "$cfg" ifname
+pids="$(head -n1 -q /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid 2>/dev/null)"
+for pid in $pids; do
+ [ -d "/proc/$pid" ] && {
+ kill $pid
+ [ -d "/proc/$pid" ] && {
+ sleep 1
+ kill -9 $pid 2>/dev/null >/dev/null
+ }
+ }
+done
+rm -f /var/run/${ifname}.pid /var/run/ppp-${cfg}.pid
+
+config_get ifname "$cfg" ifname
+config_get device "$cfg" ifname
+
+[ ."$device" != ."$ifname" ] || device=
+for dev in $ifname $device; do
+ ifconfig "$ifname" 0.0.0.0 down >/dev/null 2>/dev/null
+done
+
+config_get iftype "$cfg" type
+[ "$iftype" = "bridge" ] && brctl delbr "$ifname" >/dev/null 2>/dev/null
+
diff --git a/package/base-files/files/sbin/ifup b/package/base-files/files/sbin/ifup
new file mode 100755
index 0000000000..81ec2c0890
--- /dev/null
+++ b/package/base-files/files/sbin/ifup
@@ -0,0 +1,11 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+. /sbin/ifdown "$@"
+
+config_get iftype "$1" type
+config_get ifname "$1" device
+
+for dev in $ifname; do
+ setup_interface "$dev" "$1"
+done
diff --git a/package/base-files/files/sbin/mount_root b/package/base-files/files/sbin/mount_root
new file mode 100755
index 0000000000..81660f0067
--- /dev/null
+++ b/package/base-files/files/sbin/mount_root
@@ -0,0 +1,10 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+mount none /proc -t proc
+size=$(awk '/Mem:/ {l=5242880;print((s=$2/2)<l)?$2-l:s}' /proc/meminfo)
+mount none /tmp -t tmpfs -o size=$size,nosuid,nodev,mode=1777
+mkdir -p /dev/pts
+mount none /dev/pts -t devpts
+mount -t sysfs none /sys 2>&-
+mount -o remount,rw /dev/root /
diff --git a/package/base-files/files/sbin/wifi b/package/base-files/files/sbin/wifi
new file mode 100755
index 0000000000..d877c73980
--- /dev/null
+++ b/package/base-files/files/sbin/wifi
@@ -0,0 +1,116 @@
+#!/bin/sh
+# Copyright (C) 2006 OpenWrt.org
+
+. /etc/functions.sh
+
+find_net_config() {(
+ local vif="$1"
+ local cfg
+ local ifname
+
+ config_get cfg "$vif" network
+
+ [ -z "$cfg" ] && {
+ include /lib/network
+ scan_interfaces
+
+ config_get ifname "$vif" ifnamea
+
+ cfg="$(find_config "$ifname")"
+ }
+ [ -z "$cfg" ] && return 0
+ echo "$cfg"
+)}
+
+
+bridge_interface() {(
+ local cfg="$1"
+ [ -z "$cfg" ] && return 0
+
+ include /lib/network
+ scan_interfaces
+
+ config_get iftype "$cfg" type
+ [ "$iftype" = bridge ] && config_get "$cfg" ifname
+)}
+
+
+wifi_up() {
+ for device in ${2:-$DEVICES}; do (
+ config_get iftype "$device" type
+ if eval "type enable_$iftype" 2>/dev/null >/dev/null; then
+ eval "scan_$iftype '$device'"
+ eval "enable_$iftype '$device'" || echo "$device($iftype): Setup failed"
+ else
+ echo "$device($iftype): Interface type not supported"
+ fi
+ ); done
+}
+
+wifi_down() {
+ for device in ${2:-$DEVICES}; do (
+ config_get iftype "$device" type
+ if eval "type disable_$iftype" 2>/dev/null >/dev/null; then
+ eval "scan_$iftype '$device'"
+ eval "disable_$iftype '$device'" || echo "$device($iftype): Disable failed"
+ else
+ echo "$device($iftype): Interface type not supported"
+ fi
+ ); done
+}
+
+wifi_detect() {
+ for driver in ${2:-$DRIVERS}; do (
+ if eval "type detect_$driver" 2>/dev/null >/dev/null; then
+ eval "detect_$driver" || echo "$driver: Detect failed" >&2
+ else
+ echo "$driver: Hardware detection not supported" >&2
+ fi
+ ); done
+}
+
+start_net() {(
+ local iface="$1"
+ local config="$2"
+
+ include /lib/network
+ scan_interfaces
+ setup_interface "$1" "$2"
+)}
+
+config_get_bool() {
+ local _tmp
+ config_get "$1" "$2" "$3"
+ eval "_tmp=\$$1"
+ case "$_tmp" in
+ 1|on|enabled) eval "$1=1";;
+ 0|off|disabled) eval "$1=0";;
+ *) eval "$1=${4:-0}";;
+ esac
+}
+
+config_cb() {
+ config_get TYPE "$CONFIG_SECTION" TYPE
+ case "$TYPE" in
+ wifi-device)
+ append DEVICES "$CONFIG_SECTION"
+ ;;
+ wifi-iface)
+ config_get device "$CONFIG_SECTION" device
+ config_get vifs "$device" vifs
+ append vifs "$CONFIG_SECTION"
+ config_set "$device" vifs "$vifs"
+ ;;
+ esac
+}
+
+DEVICES=
+DRIVERS=
+config_load wireless
+include /lib/wifi
+
+case "$1" in
+ down) wifi_down "$2";;
+ detect) wifi_detect "$2";;
+ *) wifi_up "$2";;
+esac
diff --git a/package/base-files/files/usr/lib/common.awk b/package/base-files/files/usr/lib/common.awk
new file mode 100644
index 0000000000..c5ce680fa6
--- /dev/null
+++ b/package/base-files/files/usr/lib/common.awk
@@ -0,0 +1,68 @@
+# Copyright (C) 2006 OpenWrt.org
+
+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/files/usr/share/udhcpc/default.script b/package/base-files/files/usr/share/udhcpc/default.script
new file mode 100755
index 0000000000..53c8faf316
--- /dev/null
+++ b/package/base-files/files/usr/share/udhcpc/default.script
@@ -0,0 +1,57 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+. /etc/functions.sh
+include /lib/network
+
+RESOLV_CONF="/tmp/resolv.conf"
+
+hotplug_event() {
+ scan_interfaces
+ for ifc in $interfaces; do
+ config_get ifname $ifc ifname
+ [ "$ifname" = "$interface" ] || continue
+
+ config_get proto $ifc proto
+ [ "$proto" = "dhcp" ] || continue
+
+ env -i ACTION="$1" INTERFACE="$ifc" DEVICE="$ifname" PROTO=dhcp /sbin/hotplug iface
+ done
+}
+
+case "$1" in
+ deconfig)
+ ifconfig $interface 0.0.0.0
+ hotplug_event ifdown
+ ;;
+ renew|bound)
+ ifconfig $interface $ip \
+ netmask ${subnet:-255.255.255.0} \
+ broadcast ${broadcast:-+}
+
+ if [ -n "$router" ] ; then
+ 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
+
+ [ -n "$dns" ] && {
+ echo -n > $RESOLV_CONF
+ ${domain:+echo search $domain} >> $RESOLV_CONF
+ for i in $dns ; do
+ echo "adding dns $i"
+ echo "nameserver $i" >> $RESOLV_CONF
+ done
+ }
+
+ hotplug_event ifup
+
+ # user rules
+ [ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+ ;;
+esac
+
+exit 0