From cd4b616312da6714fcd7768c4271a1b69261180f Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Sun, 29 Apr 2012 14:03:11 +0200 Subject: [PATCH] proto-shell: add support for appending configuration data over multiple update_link notifications --- dummy/netifd-proto.sh | 6 ++++++ dummy/proto/ppp.sh | 11 +++++++++++ proto-shell.c | 16 +++++++++++++--- 3 files changed, 30 insertions(+), 3 deletions(-) diff --git a/dummy/netifd-proto.sh b/dummy/netifd-proto.sh index f1ddd1a..31af697 100755 --- a/dummy/netifd-proto.sh +++ b/dummy/netifd-proto.sh @@ -43,6 +43,7 @@ proto_init_update() { local up="$2" local external="$3" + PROTO_KEEP=0 PROTO_INIT=1 PROTO_TUNNEL_OPEN= PROTO_IPADDR= @@ -58,6 +59,10 @@ proto_init_update() { [ -n "$3" ] && json_add_boolean "address-external" "$external" } +proto_set_keep() { + PROTO_KEEP="$1" +} + proto_close_nested() { [ -n "$PROTO_NESTED_OPEN" ] && json_close_object PROTO_NESTED_OPEN= @@ -166,6 +171,7 @@ proto_send_update() { local interface="$1" proto_close_nested + json_add_boolean keep "$PROTO_KEEP" _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 diff --git a/dummy/proto/ppp.sh b/dummy/proto/ppp.sh index 9f0c050..5bc3ea6 100755 --- a/dummy/proto/ppp.sh +++ b/dummy/proto/ppp.sh @@ -37,6 +37,7 @@ proto_pppoe_setup() { json_get_var password password echo "pppoe_setup($interface, $device), username=$username, password=$password" proto_init_update ppp0 1 + proto_set_keep 1 proto_add_ipv4_address "192.168.2.1" 32 proto_add_dns_server "192.168.2.2" proto_add_ipv4_route "0.0.0.0" 0 192.168.2.2 @@ -44,6 +45,16 @@ proto_pppoe_setup() { json_add_string "ppp-type" "pppoe" proto_close_data proto_send_update "$interface" + + proto_init_update ppp0 1 + proto_set_keep 1 + proto_add_ipv6_address "fe80::2" 64 + proto_add_ipv6_route "::0" 0 "fe80::1" + proto_add_data + json_add_string "ppp-type" "pppoe" + proto_close_data + proto_send_update "$interface" + proto_run_command "$interface" sleep 30 } diff --git a/proto-shell.c b/proto-shell.c index 4cff091..ea15fd9 100644 --- a/proto-shell.c +++ b/proto-shell.c @@ -261,6 +261,7 @@ enum { NOTIFY_ROUTES6, NOTIFY_TUNNEL, NOTIFY_DATA, + NOTIFY_KEEP, __NOTIFY_LAST }; @@ -278,6 +279,7 @@ static const struct blobmsg_policy notify_attr[__NOTIFY_LAST] = { [NOTIFY_ROUTES6] = { .name = "routes6", .type = BLOBMSG_TYPE_ARRAY }, [NOTIFY_TUNNEL] = { .name = "tunnel", .type = BLOBMSG_TYPE_TABLE }, [NOTIFY_DATA] = { .name = "data", .type = BLOBMSG_TYPE_TABLE }, + [NOTIFY_KEEP] = { .name = "keep", .type = BLOBMSG_TYPE_BOOL }, }; static int @@ -289,6 +291,7 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, const char *devname; int dev_create = 1; bool addr_ext = false; + bool keep = false; bool up; if (!tb[NOTIFY_LINK_UP]) @@ -300,6 +303,9 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, return 0; } + if ((cur = tb[NOTIFY_KEEP]) != NULL) + keep = blobmsg_get_bool(cur); + if ((cur = tb[NOTIFY_ADDR_EXT]) != NULL) { addr_ext = blobmsg_get_bool(cur); if (addr_ext) @@ -309,7 +315,8 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, if (!tb[NOTIFY_IFNAME]) { if (!iface->main_dev.dev) return UBUS_STATUS_INVALID_ARGUMENT; - } else { + } else if (!keep || iface->state != IFS_UP) { + keep = false; devname = blobmsg_data(tb[NOTIFY_IFNAME]); if (tb[NOTIFY_TUNNEL]) { dev = proto_shell_create_tunnel(devname, @@ -326,7 +333,9 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, device_claim(&iface->l3_dev); } - interface_update_start(iface); + if (!keep) + interface_update_start(iface); + proto_apply_ip_settings(iface, data, addr_ext); if ((cur = tb[NOTIFY_ROUTES]) != NULL) @@ -337,7 +346,8 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data, interface_update_complete(state->proto.iface); - state->proto.proto_event(&state->proto, IFPEV_UP); + if (!keep) + state->proto.proto_event(&state->proto, IFPEV_UP); state->sm = S_IDLE; if ((cur = tb[NOTIFY_DATA])) -- 2.25.1