Skip to contentSkip to conversation

rtnl: add 'power_up' flag to l_rtnl_set_mac

PATCH Applied James Prestwood 2 participants 2 messages Mar 11, 2020 – Mar 12, 2020

lore
Share & tools
lore
#0 lore raw

PATCH 1/1 rtnl: add 'power_up' flag to l_rtnl_set_mac

The use of l_rtnl_set_mac in IWD is always followed by powering up the device. Bringing the device back up requires calling l_rtnl_set_powered which makes another async call into the kernel. In order to reduce complexity we can include the IFF_UP flag to the MAC change message which will both change the MAC and bring the interface up all in one go.

The existing behavior is maintained by passing false to 'power_up'.

---
 ell/rtnl.c | 5 +++++
 ell/rtnl.h | 1 +
 2 files changed, 6 insertions(+)
ell/rtnl.c +5 -0
index 4600a7e..bf84cbd 100644
@@ -167,6 +167,7 @@ uint32_t l_rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
 
 uint32_t l_rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
 					const uint8_t addr[static 6],
+					bool power_up,
 					l_netlink_command_func_t cb,
 					void *user_data,
 					l_netlink_destroy_func_t destroy)
@@ -183,6 +184,10 @@ uint32_t l_rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
 
 	rtmmsg->ifi_family = AF_UNSPEC;
 	rtmmsg->ifi_index = ifindex;
+	if (power_up) {
+		rtmmsg->ifi_change = IFF_UP;
+		rtmmsg->ifi_flags = IFF_UP;
+	}
 
 	rta_buf = (void *) rtmmsg + NLMSG_ALIGN(sizeof(struct ifinfomsg));
 
ell/rtnl.h +1 -0
index ea283c1..60b8db4 100644
@@ -38,6 +38,7 @@ uint32_t l_rtnl_set_linkmode_and_operstate(struct l_netlink *rtnl, int ifindex,
 
 uint32_t l_rtnl_set_mac(struct l_netlink *rtnl, int ifindex,
 					const uint8_t addr[static 6],
+					bool power_up,
 					l_netlink_command_func_t cb,
 					void *user_data,
 					l_netlink_destroy_func_t destroy);
Signature · 1 line
2.24.1
#1 lore raw

Hi James,

Quoted 6 lines · James Prestwood

The use of l_rtnl_set_mac in IWD is always followed by powering up the device. Bringing the device back up requires calling l_rtnl_set_powered which makes another async call into the kernel. In order to reduce complexity we can include the IFF_UP flag to the MAC change message which will both change the MAC and bring the interface up all in one go.

Quoted 6 lines

The existing behavior is maintained by passing false to 'power_up'.

---
  ell/rtnl.c | 5 +++++
  ell/rtnl.h | 1 +
  2 files changed, 6 insertions(+)

Applied, thanks.

Regards,
-Denis