]> git.ipfire.org Git - thirdparty/hostap.git/commitdiff
nl80211: Move control port attribute adding into more accurate location
authorJouni Malinen <quic_jouni@quicinc.com>
Mon, 18 Dec 2023 22:20:16 +0000 (00:20 +0200)
committerJouni Malinen <j@w1.fi>
Mon, 18 Dec 2023 22:20:16 +0000 (00:20 +0200)
This is independent of the NL80211_ATTR_SOCKET_OWNER use, so add these
attributes from a separate helper function that is called only from
locations that actually start an operation that uses EAPOL frames.

Signed-off-by: Jouni Malinen <quic_jouni@quicinc.com>
src/drivers/driver_nl80211.c

index 0d5677cbc931df462a3c5527e50ea50f0955a1c1..f6a0db22d6e8b51fc34e6255377cfe8a4701b351 100644 (file)
@@ -626,12 +626,7 @@ static int send_and_recv_msgs_owner(struct wpa_driver_nl80211_data *drv,
         * attributes, but they have to be performed on the socket, which has
         * the connection owner property set in the kernel.
         */
-       if ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) &&
-           set_owner &&
-           (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) ||
-            nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER) ||
-            nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
-            nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH)))
+       if (set_owner && nla_put_flag(msg, NL80211_ATTR_SOCKET_OWNER))
                return -1;
 
        return send_and_recv(drv->global, handle,
@@ -651,6 +646,19 @@ send_and_recv_msgs_connect_handle(struct wpa_driver_nl80211_data *drv,
 }
 
 
+static int nl80211_put_control_port(struct wpa_driver_nl80211_data *drv,
+                                   struct nl_msg *msg)
+{
+       if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT) ||
+           nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
+           ((drv->capa.flags2 & WPA_DRIVER_FLAGS2_CONTROL_PORT_RX) &&
+            (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_OVER_NL80211) ||
+             nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_PREAUTH))))
+               return -1;
+       return 0;
+}
+
+
 struct family_data {
        const char *group;
        int id;
@@ -5200,11 +5208,13 @@ static int wpa_driver_nl80211_set_ap(void *priv,
                    os_strlen(params->sae_password), params->sae_password))
                goto fail;
 
+       if (nl80211_put_control_port(drv, msg) < 0)
+               goto fail;
+
        if (params->key_mgmt_suites & WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
            (!params->pairwise_ciphers ||
             params->pairwise_ciphers & (WPA_CIPHER_WEP104 | WPA_CIPHER_WEP40)) &&
-           (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
-            nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
+           nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
                goto fail;
 
        if (drv->device_ap_sme) {
@@ -6600,7 +6610,7 @@ retry:
            params->key_mgmt_suite == WPA_KEY_MGMT_PSK_SHA256 ||
            params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_SHA384) {
                wpa_printf(MSG_DEBUG, "  * control port");
-               if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
+               if (nl80211_put_control_port(drv, msg))
                        goto fail;
        }
 
@@ -7030,15 +7040,14 @@ static int nl80211_connect_common(struct wpa_driver_nl80211_data *drv,
                        return -1;
        }
 
-       if (nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT))
+       if (nl80211_put_control_port(drv, msg))
                return -1;
 
        if (params->key_mgmt_suite == WPA_KEY_MGMT_IEEE8021X_NO_WPA &&
            (params->pairwise_suite == WPA_CIPHER_NONE ||
             params->pairwise_suite == WPA_CIPHER_WEP104 ||
             params->pairwise_suite == WPA_CIPHER_WEP40) &&
-           (nla_put_u16(msg, NL80211_ATTR_CONTROL_PORT_ETHERTYPE, ETH_P_PAE) ||
-            nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT)))
+           nla_put_flag(msg, NL80211_ATTR_CONTROL_PORT_NO_ENCRYPT))
                return -1;
 
        if (params->rrm_used) {