summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2012-02-27 16:23:39 +0000
committerFelix Fietkau <nbd@openwrt.org>2012-02-27 16:23:39 +0000
commit8ad6213f599436363534327a005eaac024bc08db (patch)
tree3c99acec49f663e3691b91b35b1ba5ebc5835572
parente5b04d57ef4cc333eb567b7e1bc7319ffa5126c2 (diff)
downloadmtk-20170518-8ad6213f599436363534327a005eaac024bc08db.zip
mtk-20170518-8ad6213f599436363534327a005eaac024bc08db.tar.gz
mtk-20170518-8ad6213f599436363534327a005eaac024bc08db.tar.bz2
netifd: add a new udhcpc default script for command line use (no uci support)
SVN-Revision: 30741
-rwxr-xr-xpackage/netifd/files/usr/share/udhcpc/default.script57
1 files changed, 57 insertions, 0 deletions
diff --git a/package/netifd/files/usr/share/udhcpc/default.script b/package/netifd/files/usr/share/udhcpc/default.script
new file mode 100755
index 0000000..ac765a6
--- /dev/null
+++ b/package/netifd/files/usr/share/udhcpc/default.script
@@ -0,0 +1,57 @@
+#!/bin/sh
+[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+
+set_classless_routes() {
+ local max=128
+ local type
+ while [ -n "$1" -a -n "$2" -a $max -gt 0 ]; do
+ [ ${1##*/} -eq 32 ] && type=host || type=net
+ echo "udhcpc: adding route for $type $1 via $2"
+ route add -$type "$1" gw "$2" dev "$interface"
+ max=$(($max-1))
+ shift 2
+ done
+}
+
+setup_interface() {
+ echo "udhcpc: ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}"
+ ifconfig $interface $ip netmask ${subnet:-255.255.255.0} broadcast ${broadcast:-+}
+
+ [ -n "$router" ] && [ "$router" != "0.0.0.0" ] && [ "$router" != "255.255.255.255" ] && {
+ echo "udhcpc: setting default routers: $router"
+
+ local valid_gw=""
+ for i in $router ; do
+ route add default gw $i dev $interface
+ valid_gw="${valid_gw:+$valid_gw|}$i"
+ done
+
+ eval $(route -n | awk '
+ /^0.0.0.0\W{9}('$valid_gw')\W/ {next}
+ /^0.0.0.0/ {print "route del -net "$1" gw "$2";"}
+ ')
+ }
+
+ # CIDR STATIC ROUTES (rfc3442)
+ [ -n "$staticroutes" ] && set_classless_routes $staticroutes
+ [ -n "$msstaticroutes" ] && set_classless_routes $msstaticroutes
+}
+
+
+applied=
+case "$1" in
+ deconfig)
+ ifconfig "$interface" 0.0.0.0
+ ;;
+ renew)
+ setup_interface update
+ ;;
+ bound)
+ setup_interface ifup
+ ;;
+esac
+
+# user rules
+[ -f /etc/udhcpc.user ] && . /etc/udhcpc.user
+
+exit 0