proto-shell: ensure that l3_dev is always set
authorFelix Fietkau <nbd@openwrt.org>
Mon, 7 Apr 2014 11:09:09 +0000 (13:09 +0200)
committerFelix Fietkau <nbd@openwrt.org>
Mon, 7 Apr 2014 11:09:12 +0000 (13:09 +0200)
A link-down event clears l3_dev, so even if the proto handler does not
provide a new ifname, it still needs to be set explicitly

Signed-off-by: Felix Fietkau <nbd@openwrt.org>
proto-shell.c

index de1b084c5359da330e3a0304fb9c25a186eae6c2..45717bf1f9716d174d2ebd6cc85f208688cb06fc 100644 (file)
@@ -445,28 +445,26 @@ proto_shell_update_link(struct proto_shell_state *state, struct blob_attr *data,
                        dev_create = 2;
        }
 
-       if (!tb[NOTIFY_IFNAME]) {
-               if (!iface->main_dev.dev)
-                       return UBUS_STATUS_INVALID_ARGUMENT;
-       } else if (!keep || iface->state != IFS_UP) {
+       if (iface->state != IFS_UP)
+               keep = false;
+
+       dev = iface->main_dev.dev;
+       if (tb[NOTIFY_IFNAME] && !keep) {
                keep = false;
                devname = blobmsg_data(tb[NOTIFY_IFNAME]);
-               if (tb[NOTIFY_TUNNEL]) {
-                       dev = proto_shell_create_tunnel(devname,
-                               tb[NOTIFY_TUNNEL]);
-                       if (!dev)
-                               return UBUS_STATUS_INVALID_ARGUMENT;
-               } else {
+               if (tb[NOTIFY_TUNNEL])
+                       dev = proto_shell_create_tunnel(devname, tb[NOTIFY_TUNNEL]);
+               else
                        dev = device_get(devname, dev_create);
-                       if (!dev)
-                               return UBUS_STATUS_NOT_FOUND;
-               }
-
-               interface_set_l3_dev(iface, dev);
-               device_claim(&iface->l3_dev);
-               device_set_present(dev, true);
        }
 
+       if (!dev)
+               return UBUS_STATUS_INVALID_ARGUMENT;
+
+       interface_set_l3_dev(iface, dev);
+       device_claim(&iface->l3_dev);
+       device_set_present(dev, true);
+
        if (!keep)
                interface_update_start(iface);