diff options
author | Felix Fietkau <nbd@openwrt.org> | 2012-03-23 13:48:53 +0200 |
---|---|---|
committer | Felix Fietkau <nbd@openwrt.org> | 2012-03-23 13:48:55 +0200 |
commit | c7a52ed70eaae0207d7f7e6c4a31035f5ec3757e (patch) | |
tree | 77d6849c42f1b21cc39186247e2e746b3aa17bfc /ubus.c | |
parent | 3cac4ab6ac9c26d5360b1826b85aac4845414423 (diff) |
dump interface routes via ubus
Diffstat (limited to 'ubus.c')
-rw-r--r-- | ubus.c | 34 |
1 files changed, 34 insertions, 0 deletions
@@ -253,6 +253,36 @@ interface_ip_dump_address_list(struct interface_ip_settings *ip) } } +static void +interface_ip_dump_route_list(struct interface_ip_settings *ip) +{ + struct device_route *route; + static char *buf; + int buflen = 128; + void *r; + int af; + + vlist_for_each_element(&ip->route, route, node) { + if ((route->flags & DEVADDR_FAMILY) == DEVADDR_INET4) + af = AF_INET; + else + af = AF_INET6; + + r = blobmsg_open_table(&b, NULL); + buf = blobmsg_alloc_string_buffer(&b, "target", buflen); + inet_ntop(af, &route->addr, buf, buflen - 5); + buf += strlen(buf); + sprintf(buf, "/%d", route->mask); + blobmsg_add_string_buffer(&b); + + buf = blobmsg_alloc_string_buffer(&b, "nexthop", buflen); + inet_ntop(af, &route->nexthop, buf, buflen); + blobmsg_add_string_buffer(&b); + + blobmsg_close_table(&b, r); + } +} + static int netifd_handle_status(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, @@ -285,6 +315,10 @@ netifd_handle_status(struct ubus_context *ctx, struct ubus_object *obj, interface_ip_dump_address_list(&iface->config_ip); interface_ip_dump_address_list(&iface->proto_ip); blobmsg_close_array(&b, a); + a = blobmsg_open_array(&b, "route"); + interface_ip_dump_route_list(&iface->config_ip); + interface_ip_dump_route_list(&iface->proto_ip); + blobmsg_close_array(&b, a); } if (!list_is_empty(&iface->errors)) |