[OpenWrt-Devel] [PATCH 1/2] base-files: add network_get_ipaddrs_all()

Mathias Kresin openwrt at kresin.me
Mon Oct 6 15:47:35 EDT 2014


Hi Bastian,

the short answer for all your questions is: Because all the existing
functions in network.sh are written this way. The function I would
like to introduce is a dupe of network_get_ipaddrs6() which is a dupe
of network_get_ipaddr6(). All three functions only differ by the value
which is passed to jsonfilter later on.

2014-10-06 20:54 GMT+02:00 Bastian Bittorf <bittorf at bluebottle.com>:
> 1)
> is there a special reason for starting everything with '__'?
> (the vars are local anyway).
To be honest. I don't know why its done this way. Maybe someone can
enlighten me.

> 2)
> is there a special reason not to name the vars $1 and $2? e.g.
>
> local dest_var="$1"
> local interface="$2"
>
> 3)
> why you append a '1' to the list if it's IPv6? (make it clear in the code)
>
> 4)
> use a special var for the list and for the element of the list.
> ("for __addr in $__addr; do" -> for ELEMENT in $LIST)
>
>> +     if __network_ifstatus "__addr" "$2" "['ipv4-address','ipv6-address','ipv6-prefix-assignment'][*].address"; then
>> +             for __addr in $__addr; do
>> +                     case "$__addr" in
>> +                             *:) __list="${__list:+$__list }${__addr}1" ;;
>> +                             *)  __list="${__list:+$__list }${__addr}"  ;;
>> +                     esac
>> +             done
>> +
>> +             export "$1=$__list"
>> +             return 0
>> +     fi
>> +
>> +     unset "$1"
>> +     return 1
>> +}
I'm with you. It would improve the readability. But as already said,
that's the coding style of the existing functions...

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