]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
wifi: cfg80211: make cluster id an array
authorMiri Korenblit <miriam.rachel.korenblit@intel.com>
Mon, 2 Mar 2026 07:11:46 +0000 (09:11 +0200)
committerJohannes Berg <johannes.berg@intel.com>
Mon, 2 Mar 2026 10:01:02 +0000 (11:01 +0100)
cfg80211_nan_conf::cluster_id is currently a pointer, but there is no real
reason to not have it an array. It makes things easier as there is no
need to check the pointer validity each time.
If a cluster ID wasn't provided by user space it will be randomized.

Signed-off-by: Miri Korenblit <miriam.rachel.korenblit@intel.com>
Link: https://patch.msgid.link/20260302091108.2b12e4ccf5bb.Ib16bf5cca55463d4c89e18099cf1dfe4de95d405@changeid
Signed-off-by: Johannes Berg <johannes.berg@intel.com>
drivers/net/wireless/intel/iwlwifi/mld/nan.c
drivers/net/wireless/virtual/mac80211_hwsim.c
include/net/cfg80211.h
net/mac80211/cfg.c
net/wireless/nl80211.c

index 2dbd3d58b0c6200af8b18835e03cc00a411f0e0e..4d8e85f2bd7c23d9c08522157d29660b85333427 100644 (file)
@@ -54,9 +54,8 @@ static int iwl_mld_nan_config(struct iwl_mld *mld,
        ether_addr_copy(cmd.nmi_addr, vif->addr);
        cmd.master_pref = conf->master_pref;
 
-       if (conf->cluster_id)
-               memcpy(cmd.cluster_id, conf->cluster_id + 4,
-                      sizeof(cmd.cluster_id));
+       memcpy(cmd.cluster_id, conf->cluster_id + 4,
+              sizeof(cmd.cluster_id));
 
        cmd.scan_period = conf->scan_period < 255 ? conf->scan_period : 255;
        cmd.dwell_time =
index c6871c6c771a0d8e84ddc37832d2f5f16c30fc74..475918ee8132f5df9a99a148f6f5a7fe44052379 100644 (file)
@@ -4151,7 +4151,7 @@ static int mac80211_hwsim_start_nan(struct ieee80211_hw *hw,
                      ns_to_ktime(until_dw * NSEC_PER_USEC),
                      HRTIMER_MODE_REL_SOFT);
 
-       if (conf->cluster_id && !is_zero_ether_addr(conf->cluster_id) &&
+       if (!is_zero_ether_addr(conf->cluster_id) &&
            is_zero_ether_addr(hwsim_nan_cluster_id)) {
                memcpy(hwsim_nan_cluster_id, conf->cluster_id, ETH_ALEN);
        } else if (is_zero_ether_addr(hwsim_nan_cluster_id)) {
index c21354647da01723b4dd0edabdfedda9a43929cb..8a63dea500adf531a5677460f24a97e3595a9237 100644 (file)
@@ -4023,7 +4023,6 @@ struct cfg80211_nan_band_config {
  *     (i.e. BIT(NL80211_BAND_2GHZ)).
  * @cluster_id: cluster ID used for NAN synchronization. This is a MAC address
  *     that can take a value from 50-6F-9A-01-00-00 to 50-6F-9A-01-FF-FF.
- *     If NULL, the device will pick a random Cluster ID.
  * @scan_period: period (in seconds) between NAN scans.
  * @scan_dwell_time: dwell time (in milliseconds) for NAN scans.
  * @discovery_beacon_interval: interval (in TUs) for discovery beacons.
@@ -4039,7 +4038,7 @@ struct cfg80211_nan_band_config {
 struct cfg80211_nan_conf {
        u8 master_pref;
        u8 bands;
-       const u8 *cluster_id;
+       u8 cluster_id[ETH_ALEN] __aligned(2);
        u16 scan_period;
        u16 scan_dwell_time;
        u8 discovery_beacon_interval;
index aa3b86644e8f8f719544e856a9777f9405802c9e..0c4979526c9103664344a90281ea37ffa5d9e606 100644 (file)
@@ -330,7 +330,6 @@ static void ieee80211_stop_p2p_device(struct wiphy *wiphy,
 
 static void ieee80211_nan_conf_free(struct cfg80211_nan_conf *conf)
 {
-       kfree(conf->cluster_id);
        kfree(conf->extra_nan_attrs);
        kfree(conf->vendor_elems);
        memset(conf, 0, sizeof(*conf));
@@ -372,9 +371,6 @@ static int ieee80211_nan_conf_copy(struct cfg80211_nan_conf *dst,
                memcpy(&dst->band_cfgs, &src->band_cfgs,
                       sizeof(dst->band_cfgs));
 
-               kfree(dst->cluster_id);
-               dst->cluster_id = NULL;
-
                kfree(dst->extra_nan_attrs);
                dst->extra_nan_attrs = NULL;
                dst->extra_nan_attrs_len = 0;
@@ -383,12 +379,8 @@ static int ieee80211_nan_conf_copy(struct cfg80211_nan_conf *dst,
                dst->vendor_elems = NULL;
                dst->vendor_elems_len = 0;
 
-               if (src->cluster_id) {
-                       dst->cluster_id = kmemdup(src->cluster_id, ETH_ALEN,
-                                                 GFP_KERNEL);
-                       if (!dst->cluster_id)
-                               goto no_mem;
-               }
+               if (is_zero_ether_addr(dst->cluster_id))
+                       ether_addr_copy(dst->cluster_id, src->cluster_id);
 
                if (src->extra_nan_attrs && src->extra_nan_attrs_len) {
                        dst->extra_nan_attrs = kmemdup(src->extra_nan_attrs,
index de7956dbe0a0089734797c3581cf5130e0a3a807..26cf29c8867b9bc01af7d1dfb94fa0b09490cc33 100644 (file)
@@ -21,6 +21,7 @@
 #include <linux/nospec.h>
 #include <linux/etherdevice.h>
 #include <linux/if_vlan.h>
+#include <linux/random.h>
 #include <net/net_namespace.h>
 #include <net/genetlink.h>
 #include <net/cfg80211.h>
@@ -15767,9 +15768,16 @@ static int nl80211_parse_nan_conf(struct wiphy *wiphy,
                return err;
 
        changed |= CFG80211_NAN_CONF_CHANGED_CONFIG;
-       if (attrs[NL80211_NAN_CONF_CLUSTER_ID] && start)
-               conf->cluster_id =
-                       nla_data(attrs[NL80211_NAN_CONF_CLUSTER_ID]);
+       if (attrs[NL80211_NAN_CONF_CLUSTER_ID] && start) {
+               ether_addr_copy(conf->cluster_id,
+                               nla_data(attrs[NL80211_NAN_CONF_CLUSTER_ID]));
+       } else if (start) {
+               conf->cluster_id[0] = 0x50;
+               conf->cluster_id[1] = 0x6f;
+               conf->cluster_id[2] = 0x9a;
+               conf->cluster_id[3] = 0x01;
+               get_random_bytes(&conf->cluster_id[4], 2);
+       }
 
        if (attrs[NL80211_NAN_CONF_EXTRA_ATTRS]) {
                conf->extra_nan_attrs =