[OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
openwrt at daniel.thecshore.com
openwrt at daniel.thecshore.com
Wed Jan 20 07:51:37 EST 2016
From: Daniel Dickinson <openwrt at daniel.thecshore.com>
v2: Also update previously missed deconfig use of ifconfig
: Replace ipcalc.sh callout with pure shell mask2cidr
: Remove unused local variable
ip from busybox is now standard and it would be good to
eventually drop the ancient and 10+ year deprecated
upstream commands ifconfig and route, so eliminate
one of the last consumers of ifconfig and route in
the base system.
Signed-off-by: Daniel Dickinson <openwrt at daniel.thecshore.com>
---
.../netifd/files/usr/share/udhcpc/default.script | 34 +++++++++++++++-------
1 file changed, 24 insertions(+), 10 deletions(-)
diff --git a/package/network/config/netifd/files/usr/share/udhcpc/default.script b/package/network/config/netifd/files/usr/share/udhcpc/default.script
index ac765a6..78cfe36 100755
--- a/package/network/config/netifd/files/usr/share/udhcpc/default.script
+++ b/package/network/config/netifd/files/usr/share/udhcpc/default.script
@@ -1,34 +1,48 @@
#!/bin/sh
[ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1
+# From Bastian Bittorf <bittorf at bluebottle.com>
+# Included in this file to avoid dependencies
+mask2cidr()
+{
+ local x=${1##*255.}
+ local allones=$(( (${#1} - ${#x}) * 2 ))
+ local tbl='0^^^128^192^224^240^248^252^254^'
+
+ x=${tbl%%${x%%.*}*}
+ CIDR=$(( allones + (${#x}/4) ))
+}
+
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"
+ ip route add "$1" via "$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:-+}
+ local CIDR
+
+ mask2cidr ${subnet:-255.255.255.0}
+
+ echo "udhcpc: ip address add $ip/${CIDR} ${broadcast:-+} dev $interface"
+ ip address add $ip/${prefix:-24} ${broadcast:-+} dev $interface"
[ -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
+ ip route add default via $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";"}
+ eval $(ip route | awk '
+ /^default\Wvia\W('$valid_gw')/ {next}
+ /^default/ {print "ip route del "$1" via "$3";"}
')
}
@@ -41,7 +55,7 @@ setup_interface() {
applied=
case "$1" in
deconfig)
- ifconfig "$interface" 0.0.0.0
+ ip -f inet addr flush dev "$interface"
;;
renew)
setup_interface update
--
2.4.3
_______________________________________________
openwrt-devel mailing list
openwrt-devel at lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
More information about the openwrt-devel
mailing list