* open...@daniel.thecshore.com <open...@daniel.thecshore.com> [20.01.2016 
07:21]:
> @@ -5,30 +5,34 @@ set_classless_routes() {
>       local max=128
>       local type

thanks for that, i have it also on my todo-list.
please remove also the 'local type' here.

>       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 prefix="$(
> +             eval "$(ipcalc.sh 0.0.0.0 ${subnet:-255.255.255.0})"
> +             echo -n $PREFIX

dont use '-n'

> +     )"
> +             
> +     echo "udhcpc: ip address add $ip/${prefix:-24} ${broadcast:-+} dev 
> $interface"
> +     ip address add $ip/${prefix:-24} ${broadcast:-+} dev $interface"

please dont double-fallback. It's ok to have it once default to '255.255.255.0',
so just use $prefix

maybe we can even have a function in /lib/functions.sh for that:

!#/bin/sh
mask2cidr()
{
        local x=${1##*255.}
        local allones=$(( (${#1} - ${#x}) * 2 ))
        local tbl='0^^^128^192^224^240^248^252^254^'

        x=${tbl%%${x%%.*}*}
        export CIDR=$(( allones + (${#x}/4) ))
}

mask2cidr 255.255.255.224
echo $CIDR


>  
>       [ -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";"}

the code leaves the default-gateway if already set and removes all other
default routes. i dont like the awk-approach, maybe something like:

root@box:~ ip route list exact '0.0.0.0/0'
default via 217.0.116.253 dev pppoe-wan  proto static 
default via 10.63.21.98 dev eth0.1  metric 7 

#!/bin/sh

replace_default_gw()
{
        ip route list exact '0.0.0.0/0' | while read LINE; do
                set -- $LINE
                [ "$3" = "$valid_gw" ] || ip route del default via $3
        done
}

the rest looks good! there are still a lot of other users
for route/ifconfig, but thats a good start!

bye, bastian
_______________________________________________
openwrt-devel mailing list
openwrt-devel@lists.openwrt.org
https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel

Reply via email to