From c7a52ed70eaae0207d7f7e6c4a31035f5ec3757e Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Fri, 23 Mar 2012 13:48:53 +0200 Subject: [PATCH] dump interface routes via ubus --- ubus.c | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/ubus.c b/ubus.c index d34cc87..6d79a0a 100644 --- a/ubus.c +++ b/ubus.c @@ -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)) -- 2.30.2