]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Use nla_put_nested() to set NL80211_ATTR_MAC_ADDRS
authorJouni Malinen <jouni@qca.qualcomm.com>
Thu, 13 Aug 2015 13:03:23 +0000 (16:03 +0300)
committerJouni Malinen <j@w1.fi>
Fri, 28 Aug 2015 09:49:17 +0000 (12:49 +0300)
This allows an empty nested list (i.e., no MAC addresses) to be included
in the NL80211_CMD_SET_MAC_ACL message unlike with
nla_nest_start()/nla_nest_end() where the current libnl implementation
removes the "empty" attribute and causes cfg80211 to reject the command.

Signed-off-by: Jouni Malinen <jouni@qca.qualcomm.com>
src/drivers/driver_nl80211.c

index 96eb90b5f152a847ddc4cb046ff36c4ce8356936..00b173f3f85a3d7356bb337633c1c6a4b0d7a5d2 100644 (file)
@@ -3258,7 +3258,7 @@ static int wpa_driver_nl80211_set_acl(void *priv,
        struct i802_bss *bss = priv;
        struct wpa_driver_nl80211_data *drv = bss->drv;
        struct nl_msg *msg;
-       struct nlattr *acl;
+       struct nl_msg *acl;
        unsigned int i;
        int ret;
 
@@ -3271,23 +3271,26 @@ static int wpa_driver_nl80211_set_acl(void *priv,
        wpa_printf(MSG_DEBUG, "nl80211: Set %s ACL (num_mac_acl=%u)",
                   params->acl_policy ? "Accept" : "Deny", params->num_mac_acl);
 
+       acl = nlmsg_alloc();
+       if (!acl)
+               return -ENOMEM;
+       for (i = 0; i < params->num_mac_acl; i++) {
+               if (nla_put(acl, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
+                       nlmsg_free(acl);
+                       return -ENOMEM;
+               }
+       }
+
        if (!(msg = nl80211_drv_msg(drv, 0, NL80211_CMD_SET_MAC_ACL)) ||
            nla_put_u32(msg, NL80211_ATTR_ACL_POLICY, params->acl_policy ?
                        NL80211_ACL_POLICY_DENY_UNLESS_LISTED :
                        NL80211_ACL_POLICY_ACCEPT_UNLESS_LISTED) ||
-           (acl = nla_nest_start(msg, NL80211_ATTR_MAC_ADDRS)) == NULL) {
+           nla_put_nested(msg, NL80211_ATTR_MAC_ADDRS, acl)) {
                nlmsg_free(msg);
+               nlmsg_free(acl);
                return -ENOMEM;
        }
-
-       for (i = 0; i < params->num_mac_acl; i++) {
-               if (nla_put(msg, i + 1, ETH_ALEN, params->mac_acl[i].addr)) {
-                       nlmsg_free(msg);
-                       return -ENOMEM;
-               }
-       }
-
-       nla_nest_end(msg, acl);
+       nlmsg_free(acl);
 
        ret = send_and_recv_msgs(drv, msg, NULL, NULL);
        if (ret) {