[OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command

Bastian Bittorf bittorf at bluebottle.com
Wed Jan 20 08:08:17 EST 2016


* openwrt at daniel.thecshore.com <openwrt at daniel.thecshore.com> [20.01.2016 14:01]:
> +# From Bastian Bittorf <bittorf at bluebottle.com>
> +# Included in this file to avoid dependencies
> +mask2cidr()

please drop the comment, thank you.

> +{
> +	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))

please use max=$((max-1))
the '$' is unneeded (just style).

>  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"

a mistake: "add $ip/${prefix:-24} " -> "add $ip/$CIDR" like in the 'echo'

> @@ -41,7 +55,7 @@ setup_interface() {
>  applied=
>  case "$1" in
>  	deconfig)
> -		ifconfig "$interface" 0.0.0.0
> +		ip -f inet addr flush dev "$interface"

during scripting i like to use '-family' which makes
it clearer for the unpractised reader. (so dont abbrev. 8-)

thank you!

bye, bastian
_______________________________________________
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