summaryrefslogtreecommitdiffhomepage
path: root/proto-static.c
diff options
context:
space:
mode:
authorFelix Fietkau <nbd@openwrt.org>2011-04-14 03:00:52 +0200
committerFelix Fietkau <nbd@openwrt.org>2011-04-14 03:00:52 +0200
commitabe9ac8a972f610783349062a0e3b91b3891121e (patch)
tree9b9b3f6de44d078460489cbee4d1b05828121b4d /proto-static.c
parent20adacee2080e29cad3571da073d7fb4909230b1 (diff)
cleanup entry counting loop
Diffstat (limited to 'proto-static.c')
-rw-r--r--proto-static.c20
1 files changed, 14 insertions, 6 deletions
diff --git a/proto-static.c b/proto-static.c
index 4e7c052..cdaea76 100644
--- a/proto-static.c
+++ b/proto-static.c
@@ -123,6 +123,18 @@ parse_v6(const char *str, struct v6_addr *v6, int netmask)
return parse_ip_and_netmask(AF_INET6, str, &v6->addr, &v6->prefix);
}
+static int
+count_list_entries(struct uci_option *o)
+{
+ struct uci_element *e;
+ int n = 0;
+
+ uci_foreach_element(&o->v.list, e)
+ n++;
+
+ return n;
+}
+
enum {
OPT_IPADDR,
OPT_IP6ADDR,
@@ -172,10 +184,8 @@ static_attach(struct proto_handler *h, struct interface *iface,
if (!parse_v4(tb[OPT_IPADDR]->v.string, v4, netmask))
goto invalid_addr;
} else {
- uci_foreach_element(&tb[OPT_IPADDR]->v.list, e)
- n_v4++;
-
i = 0;
+ n_v4 = count_list_entries(tb[OPT_IPADDR]);
v4 = alloca(sizeof(*v4) * n_v4);
uci_foreach_element(&tb[OPT_IPADDR]->v.list, e) {
if (!parse_v4(e->name, &v4[i++], netmask))
@@ -192,10 +202,8 @@ static_attach(struct proto_handler *h, struct interface *iface,
if (!parse_v6(tb[OPT_IP6ADDR]->v.string, v6, netmask))
goto invalid_addr;
} else {
- uci_foreach_element(&tb[OPT_IP6ADDR]->v.list, e)
- n_v6++;
-
i = 0;
+ n_v6 = count_list_entries(tb[OPT_IP6ADDR]);
v6 = alloca(sizeof(*v6) * n_v6);
uci_foreach_element(&tb[OPT_IP6ADDR]->v.list, e) {
if (!parse_v6(e->name, &v6[i++], netmask))