Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
On 2016-01-30 05:55, Daniel Dickinson wrote: > It worked with a /24 subnet but that might be because of defaults. I do > not currently have test bed for testing other configurations. > > I plan on setting that up once I'm back from travelling. Please avoid top posting, it is a rather inconvenient quoting style. The broken line is this: > ip address add $ip/${CIDR} ${broadcast:-+} dev $interface" It seems to me that you simply kept pieces of ifconfig syntax (the broadcast +) without testing if they can be used with ip. Please be more careful with that sort of stuff - Felix ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
It worked with a /24 subnet but that might be because of defaults. I do not currently have test bed for testing other configurations. I plan on setting that up once I'm back from travelling. Regards, Daniel On 28/01/16 05:52 PM, Felix Fietkau wrote: On 2016-01-20 19:21, open...@daniel.thecshore.com wrote: From: Daniel Dickinsonv3: Drop comment thanking user who gave mask2cidr at their request : Fix echo had correct CIDR but actual command did not : Fix style issue : Use full -family in ip command line instead of -f 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 --- .../netifd/files/usr/share/udhcpc/default.script | 34 +++--- 1 file changed, 23 insertions(+), 11 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..5c0 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,46 @@ 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/${CIDR} ${broadcast:-+} dev $interface" This doesn't work. Did you test this code? - Felix ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
On 2016-01-20 19:21, open...@daniel.thecshore.com wrote: > From: Daniel Dickinson> > v3: Drop comment thanking user who gave mask2cidr at their > request > : Fix echo had correct CIDR but actual command did not > : Fix style issue > : Use full -family in ip command line instead of -f > > 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 > --- > .../netifd/files/usr/share/udhcpc/default.script | 34 > +++--- > 1 file changed, 23 insertions(+), 11 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..5c0 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,46 @@ > 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/${CIDR} ${broadcast:-+} dev $interface" This doesn't work. Did you test this code? - Felix ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
From: Daniel Dickinsonv3: Drop comment thanking user who gave mask2cidr at their request : Fix echo had correct CIDR but actual command did not : Fix style issue : Use full -family in ip command line instead of -f 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 --- .../netifd/files/usr/share/udhcpc/default.script | 34 +++--- 1 file changed, 23 insertions(+), 11 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..5c0 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,46 @@ #!/bin/sh [ -z "$1" ] && echo "Error: should be run by udhcpc" && exit 1 +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" - max=$(($max-1)) + 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/${CIDR} ${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 +53,7 @@ setup_interface() { applied= case "$1" in deconfig) - ifconfig "$interface" 0.0.0.0 + ip -family inet addr flush dev "$interface" ;; renew) setup_interface update -- 2.4.3 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
* Daniel Dickinson[20.01.2016 10:18]: > >>+ local prefix="$( > >>+ eval "$(ipcalc.sh 0.0.0.0 ${subnet:-255.255.255.0})" > >>+ echo -n $PREFIX > > > >dont use '-n' > > Why not? It prevents echo from emitting an unwanted newline. by the way: is somebody fluent enough in AWK to fix this ipcalc-issue https://dev.openwrt.org/ticket/20750 maybe i should ask 'TheMozg' 8-) https://github.com/TheMozg/awk-raycaster bye, bastian ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
* Daniel Dickinson[20.01.2016 10:18]: > >>+ local prefix="$( > >>+ eval "$(ipcalc.sh 0.0.0.0 ${subnet:-255.255.255.0})" > >>+ echo -n $PREFIX > > > >dont use '-n' > > Why not? It prevents echo from emitting an unwanted newline. it's not POSIX and really unneeded here (it does not matter for eval). BTW: if you need this, use: printf '%s' "$string" or just: printf "$string" > >>+ 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 > > The second fallback is in case the interpolation fails. ok, i will not discuss this and accept. > >>- 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: > > I wasn't planning on reworking the udhcpc script beyond making it > work with ip vs ifconfig/route. You're talking about changing more > unrelated things, which really should go in a separate patch. ok. > >the rest looks good! there are still a lot of other users > >for route/ifconfig, but thats a good start! > > Actually according to grep, only openvpn after this in base (there > are < 10 others in packages feed as well, and I am planning on > creating a minimalist busybox package (calling the binary e.g. > net-tools) to supply ifconfig/route for those packages that aren't > converted yet, or for third party use of ifconfig/route (in the > packages feeds; doesn't belong in base). git grep 'ifconfig' shows a *lot* - but dont mind - thanks for your input. bye, bastian ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
On 20/01/16 04:24 AM, Bastian Bittorf wrote: * Daniel Dickinson[20.01.2016 10:18]: + local prefix="$( + eval "$(ipcalc.sh 0.0.0.0 ${subnet:-255.255.255.0})" + echo -n $PREFIX dont use '-n' Why not? It prevents echo from emitting an unwanted newline. it's not POSIX and really unneeded here (it does not matter for eval). ah, ok didn't know it wasn't POSIX and forgot about eval. BTW: if you need this, use: printf '%s' "$string" or just: printf "$string" + 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 The second fallback is in case the interpolation fails. ok, i will not discuss this and accept. - 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: I wasn't planning on reworking the udhcpc script beyond making it work with ip vs ifconfig/route. You're talking about changing more unrelated things, which really should go in a separate patch. ok. the rest looks good! there are still a lot of other users for route/ifconfig, but thats a good start! Actually according to grep, only openvpn after this in base (there are < 10 others in packages feed as well, and I am planning on creating a minimalist busybox package (calling the binary e.g. net-tools) to supply ifconfig/route for those packages that aren't converted yet, or for third party use of ifconfig/route (in the packages feeds; doesn't belong in base). git grep 'ifconfig' shows a *lot* - but dont mind - thanks for your input. There is are only two uses in packages after this (qos-scripts (which I missed) and openvpn), but I missed target, which has a bunch of preinit use. Regards, Daniel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
On 20/01/16 02:10 AM, Bastian Bittorf wrote: * 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. Missed that. 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' Why not? It prevents echo from emitting an unwanted newline. + )" + + 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 The second fallback is in case the interpolation fails. 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: I wasn't planning on reworking the udhcpc script beyond making it work with ip vs ifconfig/route. You're talking about changing more unrelated things, which really should go in a separate patch. 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! Actually according to grep, only openvpn after this in base (there are < 10 others in packages feed as well, and I am planning on creating a minimalist busybox package (calling the binary e.g. net-tools) to supply ifconfig/route for those packages that aren't converted yet, or for third party use of ifconfig/route (in the packages feeds; doesn't belong in base). Regards, Daniel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
On 20/01/16 04:24 AM, Bastian Bittorf wrote: please dont double-fallback. It's ok to have it once default to '255.255.255.0', so just use $prefix The second fallback is in case the interpolation fails. ok, i will not discuss this and accept. On second thought I don't like relying on ipcalc.sh and would prefer the replace that bit (which is new new anyway with something like the code you posted), and what would kill two birds with one stone. Regards, Daniel ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
From: Daniel Dickinsonv2: 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 --- .../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 +# 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@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
* open...@daniel.thecshore.com[20.01.2016 14:01]: > +# From Bastian Bittorf > +# 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@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
[OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
From: Daniel Dickinsonip from busybox is now standard and carrying both sets of commands is undesirale, therefore move the only consumer of ifconfig/route still in base to using ip command. Signed-off-by: Daniel Dickinson --- .../netifd/files/usr/share/udhcpc/default.script | 20 1 file changed, 12 insertions(+), 8 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..9e002c8 100755 --- a/package/network/config/netifd/files/usr/share/udhcpc/default.script +++ b/package/network/config/netifd/files/usr/share/udhcpc/default.script @@ -5,30 +5,34 @@ 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 prefix="$( + eval "$(ipcalc.sh 0.0.0.0 ${subnet:-255.255.255.0})" + echo -n $PREFIX + )" + + echo "udhcpc: ip address add $ip/${prefix:-24} ${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";"} ') } -- 2.4.3 ___ openwrt-devel mailing list openwrt-devel@lists.openwrt.org https://lists.openwrt.org/cgi-bin/mailman/listinfo/openwrt-devel
Re: [OpenWrt-Devel] [PATCH] package/config/netifd: Replace ifconfig/route with ip command
* 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