From 08989e46b9030671ce57b8872538d40e2ddcbbe0 Mon Sep 17 00:00:00 2001 From: meurisa Date: Fri, 12 Apr 2019 09:56:28 +0200 Subject: interface: add neighbor config support The neighbor or neighbor6 network section makes neighbours configurable via UCI or proto shell handlers. It allows to install neighbor proxy entries or static neighbor entries The neighbor or neighbor6 section has the following types: interface : declares the logical OpenWrt interface ipaddr : the ip address of the neighbor mac : the mac address of the neighbor proxy : specifies whether the neighbor ia a proxy entry (can be 1 or 0) router : specifies whether the neighbor is a router (can be 1 or 0) Signed-off-by: Alexander Meuris Signed-off-by: Hans Dedecker --- ubus.c | 45 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 45 insertions(+) (limited to 'ubus.c') diff --git a/ubus.c b/ubus.c index 14688c2..e7cbfb9 100644 --- a/ubus.c +++ b/ubus.c @@ -458,6 +458,43 @@ interface_ip_dump_address_list(struct interface_ip_settings *ip, bool v6, bool e } } +static void +interface_ip_dump_neighbor_list(struct interface_ip_settings *ip, bool enabled) +{ + struct device_neighbor *neighbor; + int buflen = 128; + char *buf; + void *r; + int af; + + vlist_for_each_element(&ip->neighbor, neighbor, node) { + if (neighbor->enabled != enabled) + continue; + + if ((neighbor->flags & DEVADDR_FAMILY) == DEVADDR_INET4) + af = AF_INET; + else + af = AF_INET6; + + r = blobmsg_open_table(&b, NULL); + + if (neighbor->flags & DEVNEIGH_MAC) + blobmsg_add_string(&b, "mac", format_macaddr(neighbor->macaddr)); + + buf = blobmsg_alloc_string_buffer(&b , "address", buflen); + inet_ntop(af, &neighbor->addr, buf, buflen); + blobmsg_add_string_buffer(&b); + + if (neighbor->proxy) + blobmsg_add_u32(&b, "proxy", neighbor->proxy); + + if (neighbor->router) + blobmsg_add_u32(&b, "router", neighbor->router); + + blobmsg_close_table(&b, r); + } +} + static void interface_ip_dump_route_list(struct interface_ip_settings *ip, bool enabled) { @@ -737,6 +774,10 @@ netifd_dump_status(struct interface *iface) interface_ip_dump_dns_search_list(&iface->config_ip, true); interface_ip_dump_dns_search_list(&iface->proto_ip, true); blobmsg_close_array(&b, a); + a = blobmsg_open_array(&b, "neighbors"); + interface_ip_dump_neighbor_list(&iface->config_ip, true); + interface_ip_dump_neighbor_list(&iface->proto_ip, true); + blobmsg_close_array(&b, a); inactive = blobmsg_open_table(&b, "inactive"); a = blobmsg_open_array(&b, "ipv4-address"); @@ -759,6 +800,10 @@ netifd_dump_status(struct interface *iface) interface_ip_dump_dns_search_list(&iface->config_ip, false); interface_ip_dump_dns_search_list(&iface->proto_ip, false); blobmsg_close_array(&b, a); + a = blobmsg_open_array(&b, "neighbors"); + interface_ip_dump_neighbor_list(&iface->config_ip, false); + interface_ip_dump_neighbor_list(&iface->proto_ip, false); + blobmsg_close_array(&b, a); blobmsg_close_table(&b, inactive); } -- cgit v1.2.1