diff options
author | Felix Fietkau <nbd@openwrt.org> | 2011-09-12 13:52:48 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2011-09-12 13:52:48 +0200 |
commit | 2f871f137cf0d91a4a12dde4deff7e7cd829d5e5 (patch) | |
tree | 804a4b1188912ad3e1368bcc482c31e3e83f1c80 | |
parent | a7d0fa57b4bbc3c61a94dfe4d47490b296e12b6c (diff) |
proto-shell: parse ipv4/ipv6 address lists
-rw-r--r-- | proto-shell.c | 46 |
1 files changed, 45 insertions, 1 deletions
diff --git a/proto-shell.c b/proto-shell.c index 73a241c..4f457e5 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -151,22 +151,57 @@ proto_shell_free(struct interface_proto_state *proto) free(state); } +static void +proto_shell_parse_addr_list(struct interface *iface, struct blob_attr *attr, + bool v6, bool external) +{ + struct device_addr *addr; + struct blob_attr *cur; + int rem; + + blobmsg_for_each_attr(cur, attr, rem) { + if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING) { + DPRINTF("Ignore wrong address type: %d\n", blobmsg_type(cur)); + continue; + } + + addr = proto_parse_ip_addr_string(blobmsg_data(cur), v6, v6 ? 32 : 128); + if (!addr) { + DPRINTF("Failed to parse IP address string: %s\n", (char *) blobmsg_data(cur)); + continue; + } + + if (external) + addr->flags |= DEVADDR_EXTERNAL; + + vlist_add(&iface->proto_addr, &addr->node); + } +} + + enum { NOTIFY_LINK_UP, NOTIFY_IFNAME, + NOTIFY_ADDR_EXT, + NOTIFY_IPADDR, + NOTIFY_IP6ADDR, __NOTIFY_LAST }; static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = { [NOTIFY_LINK_UP] = { .name = "link-up", .type = BLOBMSG_TYPE_BOOL }, [NOTIFY_IFNAME] = { .name = "ifname", .type = BLOBMSG_TYPE_STRING }, + [NOTIFY_ADDR_EXT] = { .name = "address-external", .type = BLOBMSG_TYPE_BOOL }, + [NOTIFY_IPADDR] = { .name = "ipaddr", .type = BLOBMSG_TYPE_ARRAY }, + [NOTIFY_IP6ADDR] = { .name = "ip6addr", .type = BLOBMSG_TYPE_ARRAY }, }; static int proto_shell_notify(struct interface_proto_state *proto, struct blob_attr *attr) { struct proto_shell_state *state; - struct blob_attr *tb[__NOTIFY_LAST]; + struct blob_attr *tb[__NOTIFY_LAST], *cur; + bool addr_ext = false; bool up; state = container_of(proto, struct proto_shell_state, proto); @@ -191,6 +226,15 @@ proto_shell_notify(struct interface_proto_state *proto, struct blob_attr *attr) state->proto.proto_event(&state->proto, IFPEV_LINK_LOST); } + if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) + addr_ext = blobmsg_get_bool(cur); + + if ((cur = tb[NOTIFY_IPADDR]) != NULL) + proto_shell_parse_addr_list(state->proto.iface, cur, false, addr_ext); + + if ((cur = tb[NOTIFY_IP6ADDR]) != NULL) + proto_shell_parse_addr_list(state->proto.iface, cur, true, addr_ext); + return 0; } |