summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorYousong Zhou <yszhou4tech@gmail.com>2020-10-14 14:37:13 +0800
committerYousong Zhou <yszhou4tech@gmail.com>2020-10-22 10:22:18 +0800
commit5722218eb523133b688dcc4e5880a7eaddc26e11 (patch)
tree3490ee6a21e1f9d175f75415b406b729888f80bf
parentced0d5358335304773078066f6f683361bbfd907 (diff)
proto: rework parse_addr to return struct device_addr
This is a preparation for the next commit to record address index for the returned device_addr struct Signed-off-by: Yousong Zhou <yszhou4tech@gmail.com> Acked-by: Hans Dedecker <dedeckeh@gmail.com>
-rw-r--r--proto.c26
1 files changed, 15 insertions, 11 deletions
diff --git a/proto.c b/proto.c
index cbc92b1..d80cae0 100644
--- a/proto.c
+++ b/proto.c
@@ -116,16 +116,16 @@ alloc_device_addr(bool v6, bool ext)
return addr;
}
-static bool
-parse_addr(struct interface *iface, const char *str, bool v6, int mask,
- bool ext, uint32_t broadcast, uint32_t ptp, bool deprecated)
+static struct device_addr *
+parse_addr(const char *str, bool v6, int mask, bool ext, uint32_t broadcast,
+ uint32_t ptp, bool deprecated)
{
struct device_addr *addr;
int af = v6 ? AF_INET6 : AF_INET;
addr = alloc_device_addr(v6, ext);
if (!addr)
- return false;
+ return NULL;
addr->mask = mask;
if (!parse_ip_and_netmask(af, str, &addr->addr, &addr->mask))
@@ -143,14 +143,12 @@ parse_addr(struct interface *iface, const char *str, bool v6, int mask,
if (deprecated)
addr->preferred_until = system_get_rtime();
- vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags);
- return true;
+ return addr;
error:
- interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1);
free(addr);
- return false;
+ return NULL;
}
static int
@@ -159,6 +157,8 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr,
uint32_t ptp, bool deprecated)
{
struct blob_attr *cur;
+ struct device_addr *addr;
+ const char *str;
int n_addr = 0;
int rem;
@@ -166,10 +166,14 @@ parse_static_address_option(struct interface *iface, struct blob_attr *attr,
if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
return -1;
- n_addr++;
- if (!parse_addr(iface, blobmsg_data(cur), v6, netmask, ext,
- broadcast, ptp, deprecated))
+ str = blobmsg_data(cur);
+ addr = parse_addr(str, v6, netmask, ext, broadcast, ptp, deprecated);
+ if (addr == NULL) {
+ interface_add_error(iface, "proto", "INVALID_ADDRESS", &str, 1);
return -1;
+ }
+ n_addr++;
+ vlist_add(&iface->proto_ip.addr, &addr->node, &addr->flags);
}
return n_addr;