diff mbox series

wiphy: non-LAA mac randomization

Message ID 20250310225418.198643-4-rushiimachine@proton.me (mailing list archive)
State New
Headers show
Series wiphy: non-LAA mac randomization | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success
prestwoj/iwd-alpine-ci-fetch success Fetch PR
prestwoj/iwd-ci-gitlint success GitLint
prestwoj/iwd-ci-fetch success Fetch PR
prestwoj/iwd-alpine-ci-setupell success Prep - Setup ELL
prestwoj/iwd-ci-setupell success Prep - Setup ELL
prestwoj/iwd-ci-makedistcheck success Make Distcheck
prestwoj/iwd-ci-incremental_build success Incremental build not run PASS
prestwoj/iwd-alpine-ci-makedistcheck success Make Distcheck
prestwoj/iwd-alpine-ci-incremental_build success Incremental build not run PASS
prestwoj/iwd-ci-build success Build - Configure
prestwoj/iwd-alpine-ci-build success Build - Configure
prestwoj/iwd-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-ci-clang success clang PASS
prestwoj/iwd-ci-makecheck success Make Check
prestwoj/iwd-alpine-ci-makecheckvalgrind success Make Check w/Valgrind
prestwoj/iwd-alpine-ci-makecheck success Make Check
prestwoj/iwd-ci-testrunner success test-runner PASS

Commit Message

rushiimachine@proton.me March 10, 2025, 10:55 p.m. UTC
From: rushiiMachine <rushiimachine@proton.me>

Add a secondary option to `AddressRandomizationRange` to not set the
locally-administered bit of `full` randomized MAC addresses. This
allows randomizing MAC addresses to not appear as Locally
Administered Addresses (LAA). Currently, there is no way to avoid
having this bit set other than setting `AddressRandomizationRange`
to `nic`, which undesirably copies the entire OUI and only randomizes
the last 3 octets.
---
 src/iwd.config.rst |  8 ++++++--
 src/wiphy.c        | 17 +++++++++++++----
 2 files changed, 19 insertions(+), 6 deletions(-)

Comments

Denis Kenzior March 11, 2025, 6:39 p.m. UTC | #1
Hi

On 3/10/25 5:55 PM, rushiimachine@proton.me wrote:
> From: rushiiMachine <rushiimachine@proton.me>
> 

I need a real name / author information in order to accept patches.

> Add a secondary option to `AddressRandomizationRange` to not set the
> locally-administered bit of `full` randomized MAC addresses. This
> allows randomizing MAC addresses to not appear as Locally
> Administered Addresses (LAA). Currently, there is no way to avoid
> having this bit set other than setting `AddressRandomizationRange`
> to `nic`, which undesirably copies the entire OUI and only randomizes
> the last 3 octets.
> ---
>   src/iwd.config.rst |  8 ++++++--
>   src/wiphy.c        | 17 +++++++++++++----
>   2 files changed, 19 insertions(+), 6 deletions(-)
> 
> diff --git a/src/iwd.config.rst b/src/iwd.config.rst
> index 895a1012..55b95db9 100644
> --- a/src/iwd.config.rst
> +++ b/src/iwd.config.rst
> @@ -107,7 +107,7 @@ The group ``[General]`` contains general settings.
>          the permanent address.
>   
>      * - AddressRandomizationRange
> -     - Values: **full**, nic
> +     - Values: **full**, full-uaa, nic

What does uaa mean here? user-administered-address?

>   
>          One can control which part of the address is randomized using this
>          setting.
> @@ -119,7 +119,11 @@ The group ``[General]`` contains general settings.
>   
>          When using ``AddressRandomizationRange`` set to ``full``, all 6 octets
>          of the address are randomized.  The locally-administered bit will be
> -       set.
> +       set, and multicast bit will be cleared.
> +
> +       When using ``AddressRandomizationRange`` set to ``full-uaa``, all 6
> +       octets of the address are randomized. The locally-administered and
> +       multicast bits will be cleared.
>   
>      * - RoamThreshold
>        - Value: rssi dBm value, from -100 to 1, default: **-70**
> diff --git a/src/wiphy.c b/src/wiphy.c
> index fb544fe6..ccdc7645 100644
> --- a/src/wiphy.c
> +++ b/src/wiphy.c
> @@ -64,6 +64,7 @@ static struct l_hwdb *hwdb;
>   static char **whitelist_filter;
>   static char **blacklist_filter;
>   static int mac_randomize_bytes = 6;
> +static bool mac_set_laa = true;
>   static char regdom_country[2];
>   static uint32_t work_ids;
>   static unsigned int wiphy_dump_id;
> @@ -778,8 +779,11 @@ static void wiphy_address_constrain(struct wiphy *wiphy, uint8_t addr[static 6])
>   {
>   	switch (mac_randomize_bytes) {
>   	case 6:
> -		/* Set the locally administered bit */
> -		addr[0] |= 0x2;
> +		/* Set or clear the locally administered bit */
> +		if (mac_set_laa)
> +			addr[0] |= 0x2;
> +		else
> +			addr[0] &= 0xfd;

Nit: Prefer L_BIT_SET / L_BIT_CLEAR

>   
>   		/* Reset multicast bit */
>   		addr[0] &= 0xfe;
> @@ -2854,9 +2858,13 @@ static int wiphy_init(void)
>   	if (s) {
>   		if (!strcmp(s, "nic"))
>   			mac_randomize_bytes = 3;
> -		else if (!strcmp(s, "full"))
> +		else if (!strcmp(s, "full")) {
>   			mac_randomize_bytes = 6;
> -		else
> +			mac_set_laa = true;
> +		} else if (!strcmp(s, "full-uaa")) {
> +			mac_randomize_bytes = 6;
> +			mac_set_laa = false;
> +		} else
>   			l_warn("Invalid [General].AddressRandomizationRange"
>   				" value: %s", s);
>   	}
> @@ -2884,6 +2892,7 @@ static void wiphy_exit(void)
>   	l_genl_family_free(nl80211);
>   	nl80211 = NULL;
>   	mac_randomize_bytes = 6;
> +	mac_set_laa = true;
>   
>   	l_dbus_unregister_interface(dbus_get_bus(), IWD_WIPHY_INTERFACE);
>   

Looks good otherwise.

Regards,
-Denis
diff mbox series

Patch

diff --git a/src/iwd.config.rst b/src/iwd.config.rst
index 895a1012..55b95db9 100644
--- a/src/iwd.config.rst
+++ b/src/iwd.config.rst
@@ -107,7 +107,7 @@  The group ``[General]`` contains general settings.
        the permanent address.
 
    * - AddressRandomizationRange
-     - Values: **full**, nic
+     - Values: **full**, full-uaa, nic
 
        One can control which part of the address is randomized using this
        setting.
@@ -119,7 +119,11 @@  The group ``[General]`` contains general settings.
 
        When using ``AddressRandomizationRange`` set to ``full``, all 6 octets
        of the address are randomized.  The locally-administered bit will be
-       set.
+       set, and multicast bit will be cleared.
+
+       When using ``AddressRandomizationRange`` set to ``full-uaa``, all 6
+       octets of the address are randomized. The locally-administered and
+       multicast bits will be cleared.
 
    * - RoamThreshold
      - Value: rssi dBm value, from -100 to 1, default: **-70**
diff --git a/src/wiphy.c b/src/wiphy.c
index fb544fe6..ccdc7645 100644
--- a/src/wiphy.c
+++ b/src/wiphy.c
@@ -64,6 +64,7 @@  static struct l_hwdb *hwdb;
 static char **whitelist_filter;
 static char **blacklist_filter;
 static int mac_randomize_bytes = 6;
+static bool mac_set_laa = true;
 static char regdom_country[2];
 static uint32_t work_ids;
 static unsigned int wiphy_dump_id;
@@ -778,8 +779,11 @@  static void wiphy_address_constrain(struct wiphy *wiphy, uint8_t addr[static 6])
 {
 	switch (mac_randomize_bytes) {
 	case 6:
-		/* Set the locally administered bit */
-		addr[0] |= 0x2;
+		/* Set or clear the locally administered bit */
+		if (mac_set_laa)
+			addr[0] |= 0x2;
+		else
+			addr[0] &= 0xfd;
 
 		/* Reset multicast bit */
 		addr[0] &= 0xfe;
@@ -2854,9 +2858,13 @@  static int wiphy_init(void)
 	if (s) {
 		if (!strcmp(s, "nic"))
 			mac_randomize_bytes = 3;
-		else if (!strcmp(s, "full"))
+		else if (!strcmp(s, "full")) {
 			mac_randomize_bytes = 6;
-		else
+			mac_set_laa = true;
+		} else if (!strcmp(s, "full-uaa")) {
+			mac_randomize_bytes = 6;
+			mac_set_laa = false;
+		} else
 			l_warn("Invalid [General].AddressRandomizationRange"
 				" value: %s", s);
 	}
@@ -2884,6 +2892,7 @@  static void wiphy_exit(void)
 	l_genl_family_free(nl80211);
 	nl80211 = NULL;
 	mac_randomize_bytes = 6;
+	mac_set_laa = true;
 
 	l_dbus_unregister_interface(dbus_get_bus(), IWD_WIPHY_INTERFACE);