add an ubus method for dumping available protocol handlers
authorFelix Fietkau <nbd@openwrt.org>
Thu, 31 May 2012 16:18:52 +0000 (18:18 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Thu, 31 May 2012 16:18:52 +0000 (18:18 +0200)
proto.c
proto.h
ubus.c

diff --git a/proto.c b/proto.c
index c3bd19d..ccc5f25 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -450,6 +450,19 @@ get_proto_handler(const char *name)
 }
 
 void
 }
 
 void
+proto_dump_handlers(struct blob_buf *b)
+{
+       struct proto_handler *p;
+       void *c;
+
+       avl_for_each_element(&handlers, p, avl) {
+               c = blobmsg_open_table(b, p->name);
+               blobmsg_add_u8(b, "no_device", !!(p->flags & PROTO_FLAG_NODEV));
+               blobmsg_close_table(b, c);
+       }
+}
+
+void
 proto_init_interface(struct interface *iface, struct blob_attr *attr)
 {
        const struct proto_handler *proto = iface->proto_handler;
 proto_init_interface(struct interface *iface, struct blob_attr *attr)
 {
        const struct proto_handler *proto = iface->proto_handler;
diff --git a/proto.h b/proto.h
index 12653cd..4ed70a3 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -72,6 +72,6 @@ int interface_proto_event(struct interface_proto_state *proto,
 unsigned int parse_netmask_string(const char *str, bool v6);
 int proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr);
 int proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ext);
 unsigned int parse_netmask_string(const char *str, bool v6);
 int proto_apply_static_ip_settings(struct interface *iface, struct blob_attr *attr);
 int proto_apply_ip_settings(struct interface *iface, struct blob_attr *attr, bool ext);
-
+void proto_dump_handlers(struct blob_buf *b);
 
 #endif
 
 #endif
diff --git a/ubus.c b/ubus.c
index 438b08c..dcc4098 100644 (file)
--- a/ubus.c
+++ b/ubus.c
@@ -92,10 +92,23 @@ netifd_add_host_route(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
        return 0;
 }
 
+static int
+netifd_get_proto_handlers(struct ubus_context *ctx, struct ubus_object *obj,
+                         struct ubus_request_data *req, const char *method,
+                         struct blob_attr *msg)
+{
+       blob_buf_init(&b, 0);
+       proto_dump_handlers(&b);
+       ubus_send_reply(ctx, req, b.head);
+
+       return 0;
+}
+
 static struct ubus_method main_object_methods[] = {
        { .name = "restart", .handler = netifd_handle_restart },
        { .name = "reload", .handler = netifd_handle_reload },
        UBUS_METHOD("add_host_route", netifd_add_host_route, route_policy),
 static struct ubus_method main_object_methods[] = {
        { .name = "restart", .handler = netifd_handle_restart },
        { .name = "reload", .handler = netifd_handle_reload },
        UBUS_METHOD("add_host_route", netifd_add_host_route, route_policy),
+       { .name = "get_proto_handlers", .handler = netifd_get_proto_handlers },
 };
 
 static struct ubus_object_type main_object_type =
 };
 
 static struct ubus_object_type main_object_type =