All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 1/6] anqp: Only register for frames on station interfaces
@ 2019-11-20 22:23 Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 2/6] device: Move device creation from netdev.c to event watch Andrew Zaborowski
                   ` (5 more replies)
  0 siblings, 6 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-20 22:23 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 837 bytes --]

Check the iftype before registering ANQP on new interface.

Not that the check here and in rrm.c (which already checks the iftype)
may need to be extended to run on NETDEV_WATCH_EVENT_UP because a device
could be created with a different iftype and then have the iftype changed
before powering up.
---
 src/anqp.c | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/src/anqp.c b/src/anqp.c
index f3171456..6627bd81 100644
--- a/src/anqp.c
+++ b/src/anqp.c
@@ -374,7 +374,9 @@ static void anqp_netdev_watch(struct netdev *netdev,
 {
 	switch (event) {
 	case NETDEV_WATCH_EVENT_NEW:
-		anqp_register_frame(netdev_get_ifindex(netdev));
+		if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_STATION)
+			anqp_register_frame(netdev_get_ifindex(netdev));
+
 		return;
 	default:
 		break;
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 2/6] device: Move device creation from netdev.c to event watch
  2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
@ 2019-11-20 22:23 ` Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 3/6] device: Make functions static, drop device.h Andrew Zaborowski
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-20 22:23 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 6020 bytes --]

Create and destroy the device state struct and the DBus interfaces in a
way more similar to the Station, AdHoc and AP interfaces.  Drop
netdev_get_device() and the device specific code in netdev that as far
as I can tell wasn't needed.
---
 src/device.c | 42 +++++++++++++++++++++++++++++++-----------
 src/netdev.c | 16 ++++------------
 src/netdev.h |  2 --
 3 files changed, 35 insertions(+), 25 deletions(-)

diff --git a/src/device.c b/src/device.c
index e0e42c4d..4c963bc2 100644
--- a/src/device.c
+++ b/src/device.c
@@ -289,31 +289,48 @@ static void device_netdev_notify(struct netdev *netdev,
 					enum netdev_watch_event event,
 					void *user_data)
 {
-	struct device *device = netdev_get_device(netdev);
+	struct device *device;
 	struct l_dbus *dbus = dbus_get_bus();
+	const char *path = netdev_get_path(netdev);
+
+	device = l_dbus_object_get_data(dbus, path, IWD_DEVICE_INTERFACE);
 
-	if (!device)
+	if (!device && event != NETDEV_WATCH_EVENT_NEW)
 		return;
 
 	switch (event) {
+	case NETDEV_WATCH_EVENT_NEW:
+		if (L_WARN_ON(device))
+			break;
+
+		if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_P2P_CLIENT ||
+				netdev_get_iftype(netdev) ==
+				NETDEV_IFTYPE_P2P_GO)
+			return;
+
+		device_create(netdev_get_wiphy(netdev), netdev);
+		break;
+	case NETDEV_WATCH_EVENT_DEL:
+		l_dbus_unregister_object(dbus, path);
+		break;
 	case NETDEV_WATCH_EVENT_UP:
 		device->powered = true;
 
-		l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
+		l_dbus_property_changed(dbus, path,
 					IWD_DEVICE_INTERFACE, "Powered");
 		break;
 	case NETDEV_WATCH_EVENT_DOWN:
 		device->powered = false;
 
-		l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
+		l_dbus_property_changed(dbus, path,
 					IWD_DEVICE_INTERFACE, "Powered");
 		break;
 	case NETDEV_WATCH_EVENT_NAME_CHANGE:
-		l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
+		l_dbus_property_changed(dbus, path,
 					IWD_DEVICE_INTERFACE, "Name");
 		break;
 	case NETDEV_WATCH_EVENT_ADDRESS_CHANGE:
-		l_dbus_property_changed(dbus, netdev_get_path(device->netdev),
+		l_dbus_property_changed(dbus, path,
 					IWD_DEVICE_INTERFACE, "Address");
 		break;
 	default:
@@ -380,12 +397,8 @@ struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
 
 void device_remove(struct device *device)
 {
-	struct l_dbus *dbus = dbus_get_bus();
-
 	l_debug("");
 
-	l_dbus_unregister_object(dbus, netdev_get_path(device->netdev));
-
 	scan_wdev_remove(netdev_get_wdev_id(device->netdev));
 
 	netdev_frame_watch_remove(device->netdev, device->ap_roam_watch);
@@ -394,12 +407,19 @@ void device_remove(struct device *device)
 	l_free(device);
 }
 
+static void destroy_device_interface(void *user_data)
+{
+	struct device *device = user_data;
+
+	device_remove(device);
+}
+
 static int device_init(void)
 {
 	if (!l_dbus_register_interface(dbus_get_bus(),
 					IWD_DEVICE_INTERFACE,
 					setup_device_interface,
-					NULL, false))
+					destroy_device_interface, false))
 		return false;
 
 	netdev_watch = netdev_watch_add(device_netdev_notify, NULL, NULL);
diff --git a/src/netdev.c b/src/netdev.c
index e3fcbc1b..3c1510b9 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -50,7 +50,6 @@
 #include "src/eapol.h"
 #include "src/handshake.h"
 #include "src/crypto.h"
-#include "src/device.h"
 #include "src/scan.h"
 #include "src/netdev.h"
 #include "src/ft.h"
@@ -89,7 +88,6 @@ struct netdev {
 	char name[IFNAMSIZ];
 	uint32_t type;
 	uint8_t addr[ETH_ALEN];
-	struct device *device;
 	struct wiphy *wiphy;
 	unsigned int ifi_flags;
 	uint32_t frequency;
@@ -150,6 +148,7 @@ struct netdev {
 	bool expect_connect_failure : 1;
 	bool aborting : 1;
 	bool mac_randomize_once : 1;
+	bool events_ready : 1;
 };
 
 struct netdev_preauth_state {
@@ -306,11 +305,6 @@ struct handshake_state *netdev_get_handshake(struct netdev *netdev)
 	return netdev->handshake;
 }
 
-struct device *netdev_get_device(struct netdev *netdev)
-{
-	return netdev->device;
-}
-
 const char *netdev_get_path(struct netdev *netdev)
 {
 	static char path[256];
@@ -656,11 +650,9 @@ static void netdev_free(void *data)
 		netdev->qos_map_cmd_id = 0;
 	}
 
-	if (netdev->device) {
+	if (netdev->events_ready)
 		WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
 					netdev, NETDEV_WATCH_EVENT_DEL);
-		device_remove(netdev->device);
-	}
 
 	watchlist_destroy(&netdev->frame_watches);
 	watchlist_destroy(&netdev->station_watches);
@@ -4203,7 +4195,7 @@ static void netdev_newlink_notify(const struct ifinfomsg *ifi, int bytes)
 		}
 	}
 
-	if (!netdev->device) /* Did we send NETDEV_WATCH_EVENT_NEW yet? */
+	if (!netdev->events_ready) /* Did we send NETDEV_WATCH_EVENT_NEW yet? */
 		return;
 
 	new_up = netdev_get_is_up(netdev);
@@ -4269,9 +4261,9 @@ static void netdev_initial_up_cb(int error, uint16_t type, const void *data,
 
 	l_debug("Interface %i initialized", netdev->index);
 
-	netdev->device = device_create(netdev->wiphy, netdev);
 	WATCHLIST_NOTIFY(&netdev_watches, netdev_watch_func_t,
 				netdev, NETDEV_WATCH_EVENT_NEW);
+	netdev->events_ready = true;
 }
 
 static void netdev_set_mac_cb(int error, uint16_t type, const void *data,
diff --git a/src/netdev.h b/src/netdev.h
index 8028167d..032265f9 100644
--- a/src/netdev.h
+++ b/src/netdev.h
@@ -23,7 +23,6 @@
 #include <stdbool.h>
 
 struct netdev;
-struct device;
 struct scan_bss;
 struct handshake_state;
 struct eapol_sm;
@@ -135,7 +134,6 @@ int netdev_set_4addr(struct netdev *netdev, bool use_4addr,
 bool netdev_get_4addr(struct netdev *netdev);
 const char *netdev_get_name(struct netdev *netdev);
 bool netdev_get_is_up(struct netdev *netdev);
-struct device *netdev_get_device(struct netdev *netdev);
 const char *netdev_get_path(struct netdev *netdev);
 
 struct handshake_state *netdev_handshake_state_new(struct netdev *netdev);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 3/6] device: Make functions static, drop device.h
  2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 2/6] device: Move device creation from netdev.c to event watch Andrew Zaborowski
@ 2019-11-20 22:23 ` Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 4/6] rtnlutil: Move rtnl_set_powered from netdev to rtnlutil Andrew Zaborowski
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-20 22:23 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 7069 bytes --]

---
 Makefile.am   |   2 +-
 src/adhoc.c   |   1 -
 src/ap.c      |   1 -
 src/device.c  | 113 +++++++++++++++++++++++++-------------------------
 src/device.h  |  30 --------------
 src/station.c |   1 -
 6 files changed, 57 insertions(+), 91 deletions(-)
 delete mode 100644 src/device.h

diff --git a/Makefile.am b/Makefile.am
index f58006e7..8c69d9f4 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -189,7 +189,7 @@ src_iwd_SOURCES = src/main.c linux/nl80211.h src/iwd.h src/missing.h \
 					src/plugin.h src/plugin.c \
 					src/netdev.h src/netdev.c \
 					src/wiphy.h src/wiphy.c \
-					src/device.h src/device.c \
+					src/device.c \
 					src/station.h src/station.c \
 					src/ie.h src/ie.c \
 					src/dbus.h src/dbus.c \
diff --git a/src/adhoc.c b/src/adhoc.c
index a63c4669..52164a0a 100644
--- a/src/adhoc.c
+++ b/src/adhoc.c
@@ -30,7 +30,6 @@
 
 #include "src/iwd.h"
 #include "src/module.h"
-#include "src/device.h"
 #include "src/netdev.h"
 #include "src/wiphy.h"
 #include "src/crypto.h"
diff --git a/src/ap.c b/src/ap.c
index 2fca6ce2..c79fe9b5 100644
--- a/src/ap.c
+++ b/src/ap.c
@@ -34,7 +34,6 @@
 #include "src/iwd.h"
 #include "src/module.h"
 #include "src/scan.h"
-#include "src/device.h"
 #include "src/netdev.h"
 #include "src/wiphy.h"
 #include "src/crypto.h"
diff --git a/src/device.c b/src/device.c
index 4c963bc2..20224e8f 100644
--- a/src/device.c
+++ b/src/device.c
@@ -38,7 +38,6 @@
 #include "src/netdev.h"
 #include "src/dbus.h"
 #include "src/station.h"
-#include "src/device.h"
 
 struct device {
 	uint32_t index;
@@ -285,59 +284,6 @@ static void setup_device_interface(struct l_dbus_interface *interface)
 					device_property_set_mode);
 }
 
-static void device_netdev_notify(struct netdev *netdev,
-					enum netdev_watch_event event,
-					void *user_data)
-{
-	struct device *device;
-	struct l_dbus *dbus = dbus_get_bus();
-	const char *path = netdev_get_path(netdev);
-
-	device = l_dbus_object_get_data(dbus, path, IWD_DEVICE_INTERFACE);
-
-	if (!device && event != NETDEV_WATCH_EVENT_NEW)
-		return;
-
-	switch (event) {
-	case NETDEV_WATCH_EVENT_NEW:
-		if (L_WARN_ON(device))
-			break;
-
-		if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_P2P_CLIENT ||
-				netdev_get_iftype(netdev) ==
-				NETDEV_IFTYPE_P2P_GO)
-			return;
-
-		device_create(netdev_get_wiphy(netdev), netdev);
-		break;
-	case NETDEV_WATCH_EVENT_DEL:
-		l_dbus_unregister_object(dbus, path);
-		break;
-	case NETDEV_WATCH_EVENT_UP:
-		device->powered = true;
-
-		l_dbus_property_changed(dbus, path,
-					IWD_DEVICE_INTERFACE, "Powered");
-		break;
-	case NETDEV_WATCH_EVENT_DOWN:
-		device->powered = false;
-
-		l_dbus_property_changed(dbus, path,
-					IWD_DEVICE_INTERFACE, "Powered");
-		break;
-	case NETDEV_WATCH_EVENT_NAME_CHANGE:
-		l_dbus_property_changed(dbus, path,
-					IWD_DEVICE_INTERFACE, "Name");
-		break;
-	case NETDEV_WATCH_EVENT_ADDRESS_CHANGE:
-		l_dbus_property_changed(dbus, path,
-					IWD_DEVICE_INTERFACE, "Address");
-		break;
-	default:
-		break;
-	}
-}
-
 static void device_wiphy_state_changed_event(struct wiphy *wiphy,
 					enum wiphy_state_watch_event event,
 					void *user_data)
@@ -355,7 +301,7 @@ static void device_wiphy_state_changed_event(struct wiphy *wiphy,
 	}
 }
 
-struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
+static struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
 {
 	struct device *device;
 	struct l_dbus *dbus = dbus_get_bus();
@@ -395,7 +341,7 @@ struct device *device_create(struct wiphy *wiphy, struct netdev *netdev)
 	return device;
 }
 
-void device_remove(struct device *device)
+static void device_free(struct device *device)
 {
 	l_debug("");
 
@@ -407,11 +353,64 @@ void device_remove(struct device *device)
 	l_free(device);
 }
 
+static void device_netdev_notify(struct netdev *netdev,
+					enum netdev_watch_event event,
+					void *user_data)
+{
+	struct device *device;
+	struct l_dbus *dbus = dbus_get_bus();
+	const char *path = netdev_get_path(netdev);
+
+	device = l_dbus_object_get_data(dbus, path, IWD_DEVICE_INTERFACE);
+
+	if (!device && event != NETDEV_WATCH_EVENT_NEW)
+		return;
+
+	switch (event) {
+	case NETDEV_WATCH_EVENT_NEW:
+		if (L_WARN_ON(device))
+			break;
+
+		if (netdev_get_iftype(netdev) == NETDEV_IFTYPE_P2P_CLIENT ||
+				netdev_get_iftype(netdev) ==
+				NETDEV_IFTYPE_P2P_GO)
+			return;
+
+		device_create(netdev_get_wiphy(netdev), netdev);
+		break;
+	case NETDEV_WATCH_EVENT_DEL:
+		l_dbus_unregister_object(dbus, path);
+		break;
+	case NETDEV_WATCH_EVENT_UP:
+		device->powered = true;
+
+		l_dbus_property_changed(dbus, path,
+					IWD_DEVICE_INTERFACE, "Powered");
+		break;
+	case NETDEV_WATCH_EVENT_DOWN:
+		device->powered = false;
+
+		l_dbus_property_changed(dbus, path,
+					IWD_DEVICE_INTERFACE, "Powered");
+		break;
+	case NETDEV_WATCH_EVENT_NAME_CHANGE:
+		l_dbus_property_changed(dbus, path,
+					IWD_DEVICE_INTERFACE, "Name");
+		break;
+	case NETDEV_WATCH_EVENT_ADDRESS_CHANGE:
+		l_dbus_property_changed(dbus, path,
+					IWD_DEVICE_INTERFACE, "Address");
+		break;
+	default:
+		break;
+	}
+}
+
 static void destroy_device_interface(void *user_data)
 {
 	struct device *device = user_data;
 
-	device_remove(device);
+	device_free(device);
 }
 
 static int device_init(void)
diff --git a/src/device.h b/src/device.h
deleted file mode 100644
index 31e472be..00000000
--- a/src/device.h
+++ /dev/null
@@ -1,30 +0,0 @@
-/*
- *
- *  Wireless daemon for Linux
- *
- *  Copyright (C) 2013-2019  Intel Corporation. All rights reserved.
- *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
- *
- */
-
-#include <stdbool.h>
-
-struct wiphy;
-struct netdev;
-struct device;
-
-struct device *device_create(struct wiphy *wiphy, struct netdev *netdev);
-void device_remove(struct device *device);
diff --git a/src/station.c b/src/station.c
index 76cf20a1..b98aeb63 100644
--- a/src/station.c
+++ b/src/station.c
@@ -37,7 +37,6 @@
 #include "src/iwd.h"
 #include "src/module.h"
 #include "src/common.h"
-#include "src/device.h"
 #include "src/watchlist.h"
 #include "src/scan.h"
 #include "src/netdev.h"
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 4/6] rtnlutil: Move rtnl_set_powered from netdev to rtnlutil
  2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 2/6] device: Move device creation from netdev.c to event watch Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 3/6] device: Make functions static, drop device.h Andrew Zaborowski
@ 2019-11-20 22:23 ` Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 5/6] netdev: Power P2P interfaces up like other interfaces Andrew Zaborowski
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-20 22:23 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 6058 bytes --]

This function fits with the other utilities in rtnlutil and netdev.c
can slim down.
---
 src/netdev.c   | 46 ++++++++++++----------------------------------
 src/rtnlutil.c | 26 ++++++++++++++++++++++++++
 src/rtnlutil.h |  4 ++++
 3 files changed, 42 insertions(+), 34 deletions(-)

diff --git a/src/netdev.c b/src/netdev.c
index 3c1510b9..bdd9dc77 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -343,31 +343,6 @@ static void netdev_set_powered_destroy(void *user_data)
 	netdev->set_powered_user_data = NULL;
 }
 
-static uint32_t rtnl_set_powered(int ifindex, bool powered,
-				l_netlink_command_func_t cb, void *user_data,
-				l_netlink_destroy_func_t destroy)
-{
-	struct ifinfomsg *rtmmsg;
-	size_t bufsize;
-	uint32_t id;
-
-	bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-
-	rtmmsg = l_malloc(bufsize);
-	memset(rtmmsg, 0, bufsize);
-
-	rtmmsg->ifi_family = AF_UNSPEC;
-	rtmmsg->ifi_index = ifindex;
-	rtmmsg->ifi_change = IFF_UP;
-	rtmmsg->ifi_flags = powered ? IFF_UP : 0;
-
-	id = l_netlink_send(rtnl, RTM_SETLINK, 0, rtmmsg, bufsize,
-					cb, user_data, destroy);
-
-	l_free(rtmmsg);
-	return id;
-}
-
 int netdev_set_powered(struct netdev *netdev, bool powered,
 			netdev_command_cb_t callback, void *user_data,
 			netdev_destroy_func_t destroy)
@@ -377,7 +352,7 @@ int netdev_set_powered(struct netdev *netdev, bool powered,
 		return -EBUSY;
 
 	netdev->set_powered_cmd_id =
-		rtnl_set_powered(netdev->index, powered,
+		rtnl_set_powered(rtnl, netdev->index, powered,
 					netdev_set_powered_result, netdev,
 					netdev_set_powered_destroy);
 	if (!netdev->set_powered_cmd_id)
@@ -667,7 +642,7 @@ static void netdev_shutdown_one(void *data, void *user_data)
 	struct netdev *netdev = data;
 
 	if (netdev_get_is_up(netdev))
-		rtnl_set_powered(netdev->index, false, NULL, NULL, NULL);
+		rtnl_set_powered(rtnl, netdev->index, false, NULL, NULL, NULL);
 }
 
 static bool netdev_match(const void *a, const void *b)
@@ -3949,7 +3924,7 @@ static void netdev_set_iftype_cb(struct l_genl_msg *msg, void *user_data)
 		goto done;
 
 	netdev->set_powered_cmd_id =
-			rtnl_set_powered(netdev->index, true,
+			rtnl_set_powered(rtnl, netdev->index, true,
 					netdev_set_iftype_up_cb, req,
 					netdev_set_iftype_request_destroy);
 	if (!netdev->set_powered_cmd_id) {
@@ -4045,7 +4020,7 @@ int netdev_set_iftype(struct netdev *netdev, enum netdev_iftype type,
 		l_genl_msg_unref(msg);
 	} else {
 		netdev->set_powered_cmd_id =
-			rtnl_set_powered(netdev->index, false,
+			rtnl_set_powered(rtnl, netdev->index, false,
 					netdev_set_iftype_down_cb, req,
 					netdev_set_iftype_request_destroy);
 		if (netdev->set_powered_cmd_id)
@@ -4276,8 +4251,8 @@ static void netdev_set_mac_cb(int error, uint16_t type, const void *data,
 			strerror(-error));
 
 	netdev->set_powered_cmd_id =
-		rtnl_set_powered(netdev->index, true, netdev_initial_up_cb,
-					netdev, NULL);
+		rtnl_set_powered(rtnl, netdev->index, true,
+					netdev_initial_up_cb, netdev, NULL);
 }
 
 static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
@@ -4308,8 +4283,8 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
 	}
 
 	netdev->set_powered_cmd_id =
-		rtnl_set_powered(netdev->index, true, netdev_initial_up_cb,
-					netdev, NULL);
+		rtnl_set_powered(rtnl, netdev->index, true,
+					netdev_initial_up_cb, netdev, NULL);
 }
 
 static void netdev_getlink_cb(int error, uint16_t type, const void *data,
@@ -4367,7 +4342,8 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
 	cb = powered ? netdev_initial_down_cb : netdev_initial_up_cb;
 
 	netdev->set_powered_cmd_id =
-		rtnl_set_powered(ifi->ifi_index, !powered, cb, netdev, NULL);
+		rtnl_set_powered(rtnl, ifi->ifi_index, !powered, cb, netdev,
+					NULL);
 }
 
 static void netdev_frame_watch_free(struct watchlist_item *item)
@@ -4729,6 +4705,8 @@ static void netdev_link_notify(uint16_t type, const void *data, uint32_t len,
 	if (ifi->ifi_type != ARPHRD_ETHER)
 		return;
 
+	l_debug("event %u on ifindex %u", type, ifi->ifi_index);
+
 	bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
 
 	switch (type) {
diff --git a/src/rtnlutil.c b/src/rtnlutil.c
index 833f7103..cd5c11a0 100644
--- a/src/rtnlutil.c
+++ b/src/rtnlutil.c
@@ -25,6 +25,7 @@
 #endif
 
 #include <sys/socket.h>
+#include <linux/if.h>
 #include <linux/rtnetlink.h>
 #include <arpa/inet.h>
 
@@ -130,6 +131,31 @@ uint32_t rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
 	return id;
 }
 
+uint32_t rtnl_set_powered(struct l_netlink *rtnl, int ifindex, bool powered,
+				l_netlink_command_func_t cb, void *user_data,
+				l_netlink_destroy_func_t destroy)
+{
+	struct ifinfomsg *rtmmsg;
+	size_t bufsize;
+	uint32_t id;
+
+	bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
+
+	rtmmsg = l_malloc(bufsize);
+	memset(rtmmsg, 0, bufsize);
+
+	rtmmsg->ifi_family = AF_UNSPEC;
+	rtmmsg->ifi_index = ifindex;
+	rtmmsg->ifi_change = IFF_UP;
+	rtmmsg->ifi_flags = powered ? IFF_UP : 0;
+
+	id = l_netlink_send(rtnl, RTM_SETLINK, 0, rtmmsg, bufsize,
+					cb, user_data, destroy);
+	l_free(rtmmsg);
+
+	return id;
+}
+
 void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
 				char **label, char **ip, char **broadcast)
 {
diff --git a/src/rtnlutil.h b/src/rtnlutil.h
index 383d562f..dc053783 100644
--- a/src/rtnlutil.h
+++ b/src/rtnlutil.h
@@ -32,6 +32,10 @@ uint32_t rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
 
+uint32_t rtnl_set_powered(struct l_netlink *rtnl, int ifindex, bool powered,
+				l_netlink_command_func_t cb, void *user_data,
+				l_netlink_destroy_func_t destroy);
+
 void rtnl_ifaddr_extract(const struct ifaddrmsg *ifa, int bytes,
 				char **label, char **ip, char **broadcast);
 uint32_t rtnl_ifaddr_get(struct l_netlink *rtnl, l_netlink_command_func_t cb,
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 5/6] netdev: Power P2P interfaces up like other interfaces
  2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
                   ` (2 preceding siblings ...)
  2019-11-20 22:23 ` [PATCH 4/6] rtnlutil: Move rtnl_set_powered from netdev to rtnlutil Andrew Zaborowski
@ 2019-11-20 22:23 ` Andrew Zaborowski
  2019-11-20 22:23 ` [PATCH 6/6] netdev: Replace bool randomize_mac with specific address Andrew Zaborowski
  2019-11-21  2:33 ` [PATCH 1/6] anqp: Only register for frames on station interfaces Denis Kenzior
  5 siblings, 0 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-20 22:23 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 729 bytes --]

After all we will want to power these iftypes up on init just like
station, etc.
---
 src/netdev.c | 5 -----
 1 file changed, 5 deletions(-)

diff --git a/src/netdev.c b/src/netdev.c
index bdd9dc77..eb8a7ce8 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -4315,11 +4315,6 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
 
 	netdev_newlink_notify(ifi, bytes);
 
-	/* Don't do anything automatically for P2P interfaces */
-	if (netdev->type == NL80211_IFTYPE_P2P_CLIENT ||
-			netdev->type == NL80211_IFTYPE_P2P_GO)
-		return;
-
 	/*
 	 * If the interface is UP, reset it to ensure a clean state.
 	 * Otherwise, if we need to set a random mac, do so.  If not, just
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [PATCH 6/6] netdev: Replace bool randomize_mac with specific address
  2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
                   ` (3 preceding siblings ...)
  2019-11-20 22:23 ` [PATCH 5/6] netdev: Power P2P interfaces up like other interfaces Andrew Zaborowski
@ 2019-11-20 22:23 ` Andrew Zaborowski
  2019-11-21  2:42   ` Denis Kenzior
  2019-11-21  2:33 ` [PATCH 1/6] anqp: Only register for frames on station interfaces Denis Kenzior
  5 siblings, 1 reply; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-20 22:23 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 5799 bytes --]

Allow netdev_create_from_genl callers to draw a random or non-random MAC
and pass it in the parameter instead of a bool to tell us to generating
the MAC locally.  In P2P we are generating the MAC some time before
creating the netdev to pass it to the peer during negotiation.
---
 src/manager.c | 22 ++++++++++++++++++----
 src/netdev.c  | 44 +++++++++++++++++++++-----------------------
 src/netdev.h  |  3 ++-
 3 files changed, 41 insertions(+), 28 deletions(-)

diff --git a/src/manager.c b/src/manager.c
index 47874e11..4ad0f03c 100644
--- a/src/manager.c
+++ b/src/manager.c
@@ -102,6 +102,9 @@ static void wiphy_setup_state_destroy(struct wiphy_setup_state *state)
 
 static bool manager_use_default(struct wiphy_setup_state *state)
 {
+	uint8_t addr_buf[6];
+	uint8_t *addr = NULL;
+
 	l_debug("");
 
 	if (!state->default_if_msg) {
@@ -110,13 +113,20 @@ static bool manager_use_default(struct wiphy_setup_state *state)
 		return false;
 	}
 
-	netdev_create_from_genl(state->default_if_msg, randomize);
+	if (randomize) {
+		wiphy_generate_random_address(state->wiphy, addr_buf);
+		addr = addr_buf;
+	}
+
+	netdev_create_from_genl(state->default_if_msg, addr);
 	return true;
 }
 
 static void manager_new_interface_cb(struct l_genl_msg *msg, void *user_data)
 {
 	struct wiphy_setup_state *state = user_data;
+	uint8_t addr_buf[6];
+	uint8_t *addr = NULL;
 
 	l_debug("");
 
@@ -134,9 +144,13 @@ static void manager_new_interface_cb(struct l_genl_msg *msg, void *user_data)
 		return;
 	}
 
-	netdev_create_from_genl(msg, randomize &&
-					!wiphy_has_feature(state->wiphy,
-						NL80211_FEATURE_MAC_ON_CREATE));
+	if (randomize && !wiphy_has_feature(state->wiphy,
+					NL80211_FEATURE_MAC_ON_CREATE)) {
+		wiphy_generate_random_address(state->wiphy, addr_buf);
+		addr = addr_buf;
+	}
+
+	netdev_create_from_genl(msg, addr);
 }
 
 static void manager_new_interface_done(void *user_data)
diff --git a/src/netdev.c b/src/netdev.c
index eb8a7ce8..eea7267d 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -125,6 +125,7 @@ struct netdev {
 	int8_t cur_rssi;
 	struct l_timeout *rssi_poll_timeout;
 	uint32_t rssi_poll_cmd_id;
+	uint8_t *set_mac_once;
 
 	uint32_t set_powered_cmd_id;
 	netdev_command_cb_t set_powered_cb;
@@ -147,7 +148,6 @@ struct netdev {
 	bool ignore_connect_event : 1;
 	bool expect_connect_failure : 1;
 	bool aborting : 1;
-	bool mac_randomize_once : 1;
 	bool events_ready : 1;
 };
 
@@ -634,6 +634,7 @@ static void netdev_free(void *data)
 
 	l_io_destroy(netdev->pae_io);
 
+	l_free(netdev->set_mac_once);
 	l_free(netdev);
 }
 
@@ -4255,6 +4256,21 @@ static void netdev_set_mac_cb(int error, uint16_t type, const void *data,
 					netdev_initial_up_cb, netdev, NULL);
 }
 
+static bool netdev_check_set_mac(struct netdev *netdev)
+{
+	if (!netdev->set_mac_once)
+		return false;
+
+	l_debug("Setting initial address on ifindex: %d to: " MAC,
+		netdev->index, MAC_STR(netdev->set_mac_once));
+	netdev->set_powered_cmd_id =
+		rtnl_set_mac(rtnl, netdev->index, netdev->set_mac_once,
+				netdev_set_mac_cb, netdev, NULL);
+	l_free(netdev->set_mac_once);
+	netdev->set_mac_once = NULL;
+	return true;
+}
+
 static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
 					uint32_t len, void *user_data)
 {
@@ -4270,17 +4286,8 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
 		return;
 	}
 
-	if (netdev->mac_randomize_once) {
-		uint8_t addr[ETH_ALEN];
-
-		wiphy_generate_random_address(netdev->wiphy, addr);
-		l_debug("Setting initial random address on "
-			"ifindex: %d to: "MAC, netdev->index, MAC_STR(addr));
-		netdev->set_powered_cmd_id =
-			rtnl_set_mac(rtnl, netdev->index, addr,
-					netdev_set_mac_cb, netdev, NULL);
+	if (netdev_check_set_mac(netdev))
 		return;
-	}
 
 	netdev->set_powered_cmd_id =
 		rtnl_set_powered(rtnl, netdev->index, true,
@@ -4322,17 +4329,8 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
 	 */
 	powered = netdev_get_is_up(netdev);
 
-	if (!powered && netdev->mac_randomize_once) {
-		uint8_t addr[ETH_ALEN];
-
-		wiphy_generate_random_address(netdev->wiphy, addr);
-		l_debug("Setting initial random address on "
-			"ifindex: %d to: "MAC, netdev->index, MAC_STR(addr));
-		netdev->set_powered_cmd_id =
-			rtnl_set_mac(rtnl, netdev->index, addr,
-					netdev_set_mac_cb, netdev, NULL);
+	if (!powered && netdev_check_set_mac(netdev))
 		return;
-	}
 
 	cb = powered ? netdev_initial_down_cb : netdev_initial_up_cb;
 
@@ -4507,7 +4505,7 @@ error:
 	return NULL;
 }
 
-struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
+struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, const uint8_t set_mac[6])
 {
 	struct l_genl_attr attr;
 	uint16_t type, len;
@@ -4624,7 +4622,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
 	memcpy(netdev->name, ifname, ifname_len);
 	netdev->wiphy = wiphy;
 	netdev->pae_over_nl80211 = pae_io == NULL;
-	netdev->mac_randomize_once = random_mac;
+	netdev->set_mac_once = set_mac ? l_memdup(set_mac, 6) : NULL;
 
 	if (pae_io) {
 		netdev->pae_io = pae_io;
diff --git a/src/netdev.h b/src/netdev.h
index 032265f9..c5b6f139 100644
--- a/src/netdev.h
+++ b/src/netdev.h
@@ -205,5 +205,6 @@ uint32_t netdev_station_watch_add(struct netdev *netdev,
 
 bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id);
 
-struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac);
+struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
+					const uint8_t addr[6]);
 bool netdev_destroy(struct netdev *netdev);
-- 
2.20.1

^ permalink raw reply related	[flat|nested] 9+ messages in thread

* Re: [PATCH 1/6] anqp: Only register for frames on station interfaces
  2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
                   ` (4 preceding siblings ...)
  2019-11-20 22:23 ` [PATCH 6/6] netdev: Replace bool randomize_mac with specific address Andrew Zaborowski
@ 2019-11-21  2:33 ` Denis Kenzior
  5 siblings, 0 replies; 9+ messages in thread
From: Denis Kenzior @ 2019-11-21  2:33 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 517 bytes --]

Hi Andrew,

On 11/20/19 4:23 PM, Andrew Zaborowski wrote:
> Check the iftype before registering ANQP on new interface.
> 
> Not that the check here and in rrm.c (which already checks the iftype)
> may need to be extended to run on NETDEV_WATCH_EVENT_UP because a device
> could be created with a different iftype and then have the iftype changed
> before powering up.
> ---
>   src/anqp.c | 4 +++-
>   1 file changed, 3 insertions(+), 1 deletion(-)
> 

Patches 1-5 applied, thanks.

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 6/6] netdev: Replace bool randomize_mac with specific address
  2019-11-20 22:23 ` [PATCH 6/6] netdev: Replace bool randomize_mac with specific address Andrew Zaborowski
@ 2019-11-21  2:42   ` Denis Kenzior
  2019-11-21  3:24     ` Andrew Zaborowski
  0 siblings, 1 reply; 9+ messages in thread
From: Denis Kenzior @ 2019-11-21  2:42 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 5155 bytes --]

Hi Andrew,

On 11/20/19 4:23 PM, Andrew Zaborowski wrote:
> Allow netdev_create_from_genl callers to draw a random or non-random MAC
> and pass it in the parameter instead of a bool to tell us to generating
> the MAC locally.  In P2P we are generating the MAC some time before
> creating the netdev to pass it to the peer during negotiation.
> ---
>   src/manager.c | 22 ++++++++++++++++++----
>   src/netdev.c  | 44 +++++++++++++++++++++-----------------------
>   src/netdev.h  |  3 ++-
>   3 files changed, 41 insertions(+), 28 deletions(-)
>

<snip>

> diff --git a/src/netdev.c b/src/netdev.c
> index eb8a7ce8..eea7267d 100644
> --- a/src/netdev.c
> +++ b/src/netdev.c
> @@ -125,6 +125,7 @@ struct netdev {
>   	int8_t cur_rssi;
>   	struct l_timeout *rssi_poll_timeout;
>   	uint32_t rssi_poll_cmd_id;
> +	uint8_t *set_mac_once;

So just nit-picking, but using uint8_t set_mac_once[6] would still use 
less space (at least on 64-bit) and also skip mallocing/freeing 6 byte 
array...

Set it to all zeros or something to act as a NULL value

>   
>   	uint32_t set_powered_cmd_id;
>   	netdev_command_cb_t set_powered_cb;
> @@ -147,7 +148,6 @@ struct netdev {
>   	bool ignore_connect_event : 1;
>   	bool expect_connect_failure : 1;
>   	bool aborting : 1;
> -	bool mac_randomize_once : 1;
>   	bool events_ready : 1;
>   };
>   
> @@ -634,6 +634,7 @@ static void netdev_free(void *data)
>   
>   	l_io_destroy(netdev->pae_io);
>   
> +	l_free(netdev->set_mac_once);
>   	l_free(netdev);
>   }
>   
> @@ -4255,6 +4256,21 @@ static void netdev_set_mac_cb(int error, uint16_t type, const void *data,
>   					netdev_initial_up_cb, netdev, NULL);
>   }
>   
> +static bool netdev_check_set_mac(struct netdev *netdev)
> +{
> +	if (!netdev->set_mac_once)
> +		return false;
> +
> +	l_debug("Setting initial address on ifindex: %d to: " MAC,
> +		netdev->index, MAC_STR(netdev->set_mac_once));
> +	netdev->set_powered_cmd_id =
> +		rtnl_set_mac(rtnl, netdev->index, netdev->set_mac_once,
> +				netdev_set_mac_cb, netdev, NULL);
> +	l_free(netdev->set_mac_once);
> +	netdev->set_mac_once = NULL;
> +	return true;
> +}
> +
>   static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
>   					uint32_t len, void *user_data)
>   {
> @@ -4270,17 +4286,8 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
>   		return;
>   	}
>   
> -	if (netdev->mac_randomize_once) {
> -		uint8_t addr[ETH_ALEN];
> -
> -		wiphy_generate_random_address(netdev->wiphy, addr);
> -		l_debug("Setting initial random address on "
> -			"ifindex: %d to: "MAC, netdev->index, MAC_STR(addr));
> -		netdev->set_powered_cmd_id =
> -			rtnl_set_mac(rtnl, netdev->index, addr,
> -					netdev_set_mac_cb, netdev, NULL);
> +	if (netdev_check_set_mac(netdev))
>   		return;
> -	}
>   
>   	netdev->set_powered_cmd_id =
>   		rtnl_set_powered(rtnl, netdev->index, true,
> @@ -4322,17 +4329,8 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
>   	 */
>   	powered = netdev_get_is_up(netdev);
>   
> -	if (!powered && netdev->mac_randomize_once) {
> -		uint8_t addr[ETH_ALEN];
> -
> -		wiphy_generate_random_address(netdev->wiphy, addr);
> -		l_debug("Setting initial random address on "
> -			"ifindex: %d to: "MAC, netdev->index, MAC_STR(addr));
> -		netdev->set_powered_cmd_id =
> -			rtnl_set_mac(rtnl, netdev->index, addr,
> -					netdev_set_mac_cb, netdev, NULL);
> +	if (!powered && netdev_check_set_mac(netdev))
>   		return;
> -	}
>   
>   	cb = powered ? netdev_initial_down_cb : netdev_initial_up_cb;
>   
> @@ -4507,7 +4505,7 @@ error:
>   	return NULL;
>   }
>   
> -struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
> +struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, const uint8_t set_mac[6])
>   {
>   	struct l_genl_attr attr;
>   	uint16_t type, len;
> @@ -4624,7 +4622,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
>   	memcpy(netdev->name, ifname, ifname_len);
>   	netdev->wiphy = wiphy;
>   	netdev->pae_over_nl80211 = pae_io == NULL;
> -	netdev->mac_randomize_once = random_mac;
> +	netdev->set_mac_once = set_mac ? l_memdup(set_mac, 6) : NULL;
>   
>   	if (pae_io) {
>   		netdev->pae_io = pae_io;
> diff --git a/src/netdev.h b/src/netdev.h
> index 032265f9..c5b6f139 100644
> --- a/src/netdev.h
> +++ b/src/netdev.h
> @@ -205,5 +205,6 @@ uint32_t netdev_station_watch_add(struct netdev *netdev,
>   
>   bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id);
>   
> -struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac);
> +struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
> +					const uint8_t addr[6]);

Nitpicking again.  This syntax is pretty useless since addr is treated 
like a const uint8_t *.  It only serves to confuse the reader.  We 
should not be using this form at all.

Use const uint8_t addr[static 6] instead.

>   bool netdev_destroy(struct netdev *netdev);
> 

Regards,
-Denis

^ permalink raw reply	[flat|nested] 9+ messages in thread

* Re: [PATCH 6/6] netdev: Replace bool randomize_mac with specific address
  2019-11-21  2:42   ` Denis Kenzior
@ 2019-11-21  3:24     ` Andrew Zaborowski
  0 siblings, 0 replies; 9+ messages in thread
From: Andrew Zaborowski @ 2019-11-21  3:24 UTC (permalink / raw)
  To: iwd

[-- Attachment #1: Type: text/plain, Size: 6124 bytes --]

Hi Denis,

On Thu, 21 Nov 2019 at 03:43, Denis Kenzior <denkenz@gmail.com> wrote:
> On 11/20/19 4:23 PM, Andrew Zaborowski wrote:
> > Allow netdev_create_from_genl callers to draw a random or non-random MAC
> > and pass it in the parameter instead of a bool to tell us to generating
> > the MAC locally.  In P2P we are generating the MAC some time before
> > creating the netdev to pass it to the peer during negotiation.
> > ---
> >   src/manager.c | 22 ++++++++++++++++++----
> >   src/netdev.c  | 44 +++++++++++++++++++++-----------------------
> >   src/netdev.h  |  3 ++-
> >   3 files changed, 41 insertions(+), 28 deletions(-)
> >
>
> <snip>
>
> > diff --git a/src/netdev.c b/src/netdev.c
> > index eb8a7ce8..eea7267d 100644
> > --- a/src/netdev.c
> > +++ b/src/netdev.c
> > @@ -125,6 +125,7 @@ struct netdev {
> >       int8_t cur_rssi;
> >       struct l_timeout *rssi_poll_timeout;
> >       uint32_t rssi_poll_cmd_id;
> > +     uint8_t *set_mac_once;
>
> So just nit-picking, but using uint8_t set_mac_once[6] would still use
> less space (at least on 64-bit) and also skip mallocing/freeing 6 byte
> array...
>
> Set it to all zeros or something to act as a NULL value

Ok.

>
> >
> >       uint32_t set_powered_cmd_id;
> >       netdev_command_cb_t set_powered_cb;
> > @@ -147,7 +148,6 @@ struct netdev {
> >       bool ignore_connect_event : 1;
> >       bool expect_connect_failure : 1;
> >       bool aborting : 1;
> > -     bool mac_randomize_once : 1;
> >       bool events_ready : 1;
> >   };
> >
> > @@ -634,6 +634,7 @@ static void netdev_free(void *data)
> >
> >       l_io_destroy(netdev->pae_io);
> >
> > +     l_free(netdev->set_mac_once);
> >       l_free(netdev);
> >   }
> >
> > @@ -4255,6 +4256,21 @@ static void netdev_set_mac_cb(int error, uint16_t type, const void *data,
> >                                       netdev_initial_up_cb, netdev, NULL);
> >   }
> >
> > +static bool netdev_check_set_mac(struct netdev *netdev)
> > +{
> > +     if (!netdev->set_mac_once)
> > +             return false;
> > +
> > +     l_debug("Setting initial address on ifindex: %d to: " MAC,
> > +             netdev->index, MAC_STR(netdev->set_mac_once));
> > +     netdev->set_powered_cmd_id =
> > +             rtnl_set_mac(rtnl, netdev->index, netdev->set_mac_once,
> > +                             netdev_set_mac_cb, netdev, NULL);
> > +     l_free(netdev->set_mac_once);
> > +     netdev->set_mac_once = NULL;
> > +     return true;
> > +}
> > +
> >   static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
> >                                       uint32_t len, void *user_data)
> >   {
> > @@ -4270,17 +4286,8 @@ static void netdev_initial_down_cb(int error, uint16_t type, const void *data,
> >               return;
> >       }
> >
> > -     if (netdev->mac_randomize_once) {
> > -             uint8_t addr[ETH_ALEN];
> > -
> > -             wiphy_generate_random_address(netdev->wiphy, addr);
> > -             l_debug("Setting initial random address on "
> > -                     "ifindex: %d to: "MAC, netdev->index, MAC_STR(addr));
> > -             netdev->set_powered_cmd_id =
> > -                     rtnl_set_mac(rtnl, netdev->index, addr,
> > -                                     netdev_set_mac_cb, netdev, NULL);
> > +     if (netdev_check_set_mac(netdev))
> >               return;
> > -     }
> >
> >       netdev->set_powered_cmd_id =
> >               rtnl_set_powered(rtnl, netdev->index, true,
> > @@ -4322,17 +4329,8 @@ static void netdev_getlink_cb(int error, uint16_t type, const void *data,
> >        */
> >       powered = netdev_get_is_up(netdev);
> >
> > -     if (!powered && netdev->mac_randomize_once) {
> > -             uint8_t addr[ETH_ALEN];
> > -
> > -             wiphy_generate_random_address(netdev->wiphy, addr);
> > -             l_debug("Setting initial random address on "
> > -                     "ifindex: %d to: "MAC, netdev->index, MAC_STR(addr));
> > -             netdev->set_powered_cmd_id =
> > -                     rtnl_set_mac(rtnl, netdev->index, addr,
> > -                                     netdev_set_mac_cb, netdev, NULL);
> > +     if (!powered && netdev_check_set_mac(netdev))
> >               return;
> > -     }
> >
> >       cb = powered ? netdev_initial_down_cb : netdev_initial_up_cb;
> >
> > @@ -4507,7 +4505,7 @@ error:
> >       return NULL;
> >   }
> >
> > -struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
> > +struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, const uint8_t set_mac[6])
> >   {
> >       struct l_genl_attr attr;
> >       uint16_t type, len;
> > @@ -4624,7 +4622,7 @@ struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac)
> >       memcpy(netdev->name, ifname, ifname_len);
> >       netdev->wiphy = wiphy;
> >       netdev->pae_over_nl80211 = pae_io == NULL;
> > -     netdev->mac_randomize_once = random_mac;
> > +     netdev->set_mac_once = set_mac ? l_memdup(set_mac, 6) : NULL;
> >
> >       if (pae_io) {
> >               netdev->pae_io = pae_io;
> > diff --git a/src/netdev.h b/src/netdev.h
> > index 032265f9..c5b6f139 100644
> > --- a/src/netdev.h
> > +++ b/src/netdev.h
> > @@ -205,5 +205,6 @@ uint32_t netdev_station_watch_add(struct netdev *netdev,
> >
> >   bool netdev_station_watch_remove(struct netdev *netdev, uint32_t id);
> >
> > -struct netdev *netdev_create_from_genl(struct l_genl_msg *msg, bool random_mac);
> > +struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
> > +                                     const uint8_t addr[6]);
>
> Nitpicking again.  This syntax is pretty useless since addr is treated
> like a const uint8_t *.  It only serves to confuse the reader.  We
> should not be using this form at all.
>
> Use const uint8_t addr[static 6] instead.

This seems to prohibit passing a NULL, so we'd also need to pass
all-zero arrays from the caller.  I think I'd rather use const uint8_t
*addr then.

Best regards

^ permalink raw reply	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2019-11-21  3:24 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-11-20 22:23 [PATCH 1/6] anqp: Only register for frames on station interfaces Andrew Zaborowski
2019-11-20 22:23 ` [PATCH 2/6] device: Move device creation from netdev.c to event watch Andrew Zaborowski
2019-11-20 22:23 ` [PATCH 3/6] device: Make functions static, drop device.h Andrew Zaborowski
2019-11-20 22:23 ` [PATCH 4/6] rtnlutil: Move rtnl_set_powered from netdev to rtnlutil Andrew Zaborowski
2019-11-20 22:23 ` [PATCH 5/6] netdev: Power P2P interfaces up like other interfaces Andrew Zaborowski
2019-11-20 22:23 ` [PATCH 6/6] netdev: Replace bool randomize_mac with specific address Andrew Zaborowski
2019-11-21  2:42   ` Denis Kenzior
2019-11-21  3:24     ` Andrew Zaborowski
2019-11-21  2:33 ` [PATCH 1/6] anqp: Only register for frames on station interfaces Denis Kenzior

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.