allow proto handlers to attach data items in notify
authorFelix Fietkau <nbd@openwrt.org>
Fri, 23 Mar 2012 13:45:43 +0000 (15:45 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Fri, 23 Mar 2012 13:45:43 +0000 (15:45 +0200)
dummy/netifd-proto.sh
dummy/proto/ppp.sh
proto-shell.c

index 7482a83..f1ddd1a 100755 (executable)
@@ -58,17 +58,30 @@ proto_init_update() {
        [ -n "$3" ] && json_add_boolean "address-external" "$external"
 }
 
        [ -n "$3" ] && json_add_boolean "address-external" "$external"
 }
 
-proto_add_tunnel() {
-       proto_close_tunnel
+proto_close_nested() {
+       [ -n "$PROTO_NESTED_OPEN" ] && json_close_object
+       PROTO_NESTED_OPEN=
+}
+
+proto_add_nested() {
+       PROTO_NESTED_OPEN=1
+       json_add_object "$1"
+}
 
 
-       PROTO_TUNNEL_OPEN=1
-       json_add_object "tunnel"
+proto_add_tunnel() {
+       proto_add_nested "tunnel"
 }
 
 proto_close_tunnel() {
 }
 
 proto_close_tunnel() {
-       [ -n "$PROTO_TUNNEL_OPEN" ] || return
-       json_close_object
-       PROTO_TUNNEL_OPEN=
+       proto_close_nested
+}
+
+proto_add_data() {
+       proto_add_nested "data"
+}
+
+proto_close_data() {
+       proto_close_nested
 }
 
 proto_add_dns_server() {
 }
 
 proto_add_dns_server() {
@@ -152,7 +165,7 @@ _proto_notify() {
 proto_send_update() {
        local interface="$1"
 
 proto_send_update() {
        local interface="$1"
 
-       proto_close_tunnel
+       proto_close_nested
        _proto_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ip
        _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ip
        _proto_push_array "routes" "$PROTO_ROUTE" _proto_push_route
        _proto_push_array "ipaddr" "$PROTO_IPADDR" _proto_push_ip
        _proto_push_array "ip6addr" "$PROTO_IP6ADDR" _proto_push_ip
        _proto_push_array "routes" "$PROTO_ROUTE" _proto_push_route
index bc7fd3c..4ca2650 100755 (executable)
@@ -39,6 +39,9 @@ proto_pppoe_setup() {
        proto_init_update ppp0 1
        proto_add_ipv4_address "192.168.2.1" 32
        proto_add_dns_server "192.168.2.2"
        proto_init_update ppp0 1
        proto_add_ipv4_address "192.168.2.1" 32
        proto_add_dns_server "192.168.2.2"
+       proto_add_data
+       json_add_string "ppp-type" "pppoe"
+       proto_close_data
        proto_send_update "$interface"
        proto_run_command "$interface" sleep 30
 }
        proto_send_update "$interface"
        proto_run_command "$interface" sleep 30
 }
index b5d436a..aba7298 100644 (file)
@@ -222,6 +222,16 @@ proto_shell_parse_route_list(struct interface *iface, struct blob_attr *attr,
        }
 }
 
        }
 }
 
+static void
+proto_shell_parse_data(struct interface *iface, struct blob_attr *attr)
+{
+       struct blob_attr *cur;
+       int rem;
+
+       blobmsg_for_each_attr(cur, attr, rem)
+               interface_add_data(iface, cur);
+}
+
 static struct device *
 proto_shell_create_tunnel(const char *name, struct blob_attr *attr)
 {
 static struct device *
 proto_shell_create_tunnel(const char *name, struct blob_attr *attr)
 {
@@ -250,6 +260,7 @@ enum {
        NOTIFY_ROUTES,
        NOTIFY_ROUTES6,
        NOTIFY_TUNNEL,
        NOTIFY_ROUTES,
        NOTIFY_ROUTES6,
        NOTIFY_TUNNEL,
+       NOTIFY_DATA,
        __NOTIFY_LAST
 };
 
        __NOTIFY_LAST
 };
 
@@ -266,6 +277,7 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = {
        [NOTIFY_ROUTES] = { .name = "routes", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_ROUTES6] = { .name = "routes6", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_TUNNEL] = { .name = "tunnel", .type = BLOBMSG_TYPE_TABLE },
        [NOTIFY_ROUTES] = { .name = "routes", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_ROUTES6] = { .name = "routes6", .type = BLOBMSG_TYPE_ARRAY },
        [NOTIFY_TUNNEL] = { .name = "tunnel", .type = BLOBMSG_TYPE_TABLE },
+       [NOTIFY_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE },
 };
 
 static int
 };
 
 static int
@@ -327,6 +339,9 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data,
 
        state->proto.proto_event(&state->proto, IFPEV_UP);
 
 
        state->proto.proto_event(&state->proto, IFPEV_UP);
 
+       if ((cur = tb[NOTIFY_DATA]))
+               proto_shell_parse_data(state->proto.iface, cur);
+
        return 0;
 }
 
        return 0;
 }