device: Don't process link events anymore in device user specific callback handlers
[project/netifd.git] / system-linux.c
index f51c0785911e486ca40bdd886e9e2b82cb846fcb..4ccc9d251d15ccc9f34153cc59e8054200fba3b9 100644 (file)
@@ -424,7 +424,7 @@ static int cb_rtnl_event(struct nl_msg *msg, void *arg)
                goto out;
 
        struct device *dev = device_get(nla_data(nla[IFLA_IFNAME]), false);
-       if (!dev || dev->type->keep_link_status)
+       if (!dev)
                goto out;
 
        if (!system_get_dev_sysctl("/sys/class/net/%s/carrier", dev->ifname, buf, sizeof(buf)))
@@ -1295,10 +1295,13 @@ int system_if_check(struct device *dev)
        int ret = 1;
 
        msg = nlmsg_alloc_simple(RTM_GETLINK, 0);
-       if (!msg || nlmsg_append(msg, &ifi, sizeof(ifi), 0) ||
-           nla_put_string(msg, IFLA_IFNAME, dev->ifname))
+       if (!msg)
                goto out;
 
+       if (nlmsg_append(msg, &ifi, sizeof(ifi), 0) ||
+           nla_put_string(msg, IFLA_IFNAME, dev->ifname))
+               goto free;
+
        nl_cb_set(cb, NL_CB_VALID, NL_CB_CUSTOM, cb_if_check_valid, &chk);
        nl_cb_set(cb, NL_CB_ACK, NL_CB_CUSTOM, cb_if_check_ack, &chk);
        nl_cb_err(cb, NL_CB_CUSTOM, cb_if_check_error, &chk);
@@ -1307,9 +1310,10 @@ int system_if_check(struct device *dev)
        while (chk.pending > 0)
                nl_recvmsgs(sock_rtnl, cb);
 
-       nlmsg_free(msg);
        ret = chk.pending;
 
+free:
+       nlmsg_free(msg);
 out:
        nl_cb_put(cb);
        return ret;
@@ -1532,8 +1536,10 @@ static int system_addr(struct device *dev, struct device_addr *addr, int cmd)
 
                if (addr->valid_until) {
                        int64_t valid = addr->valid_until - now;
-                       if (valid <= 0)
+                       if (valid <= 0) {
+                               nlmsg_free(msg);
                                return -1;
+                       }
                        else if (valid > UINT32_MAX)
                                valid = UINT32_MAX;