public inbox for iwd@lists.linux.dev
 help / color / mirror / Atom feed
* [PATCH 1/3] wired: Update to the new l_netlink_send API
@ 2024-07-26 22:37 Denis Kenzior
  2024-07-26 22:37 ` [PATCH 2/3] netdev: " Denis Kenzior
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Denis Kenzior @ 2024-07-26 22:37 UTC (permalink / raw)
  To: iwd; +Cc: Denis Kenzior

---
 wired/ethdev.c | 10 ++++++----
 1 file changed, 6 insertions(+), 4 deletions(-)

diff --git a/wired/ethdev.c b/wired/ethdev.c
index e5353582494e..a933cc18e343 100644
--- a/wired/ethdev.c
+++ b/wired/ethdev.c
@@ -723,7 +723,8 @@ static void setup_adapter_interface(struct l_dbus_interface *interface)
 
 bool ethdev_init(const char *whitelist, const char *blacklist)
 {
-	struct ifinfomsg msg;
+	struct ifinfomsg ifi;
+	struct l_netlink_message *nlm;
 
 	if (rtnl)
 		return false;
@@ -760,10 +761,11 @@ bool ethdev_init(const char *whitelist, const char *blacklist)
 	if (blacklist)
 		blacklist_filter = l_strsplit(blacklist, ',');
 
-	memset(&msg, 0, sizeof(msg));
+	memset(&ifi, 0, sizeof(ifi));
+	nlm = l_netlink_message_new_sized(RTM_GETLINK, NLM_F_DUMP, sizeof(ifi));
+	l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
 
-	l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, &msg, sizeof(msg),
-						getlink_callback, NULL, NULL);
+	l_netlink_send(rtnl, nlm, getlink_callback, NULL, NULL);
 
 	return true;
 }
-- 
2.45.2


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

* [PATCH 2/3] netdev: Update to the new l_netlink_send API
  2024-07-26 22:37 [PATCH 1/3] wired: Update to the new l_netlink_send API Denis Kenzior
@ 2024-07-26 22:37 ` Denis Kenzior
  2024-07-26 22:37 ` [PATCH 3/3] monitor: Update to the new ell " Denis Kenzior
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2024-07-26 22:37 UTC (permalink / raw)
  To: iwd; +Cc: Denis Kenzior

---
 src/netdev.c | 20 ++++++++------------
 1 file changed, 8 insertions(+), 12 deletions(-)

diff --git a/src/netdev.c b/src/netdev.c
index 2d70fc38eea9..e27a0019b7ea 100644
--- a/src/netdev.c
+++ b/src/netdev.c
@@ -6093,23 +6093,19 @@ error:
 
 static void netdev_get_link(struct netdev *netdev)
 {
-	struct ifinfomsg *rtmmsg;
-	size_t bufsize;
+	struct ifinfomsg ifi;
+	struct l_netlink_message *nlm =
+		l_netlink_message_new_sized(RTM_GETLINK, 0, sizeof(ifi));
 
-	/* Query interface flags */
-	bufsize = NLMSG_ALIGN(sizeof(struct ifinfomsg));
-	rtmmsg = l_malloc(bufsize);
-	memset(rtmmsg, 0, bufsize);
+	memset(&ifi, 0, sizeof(ifi));
+	ifi.ifi_family = AF_UNSPEC;
+	ifi.ifi_index = netdev->index;
 
-	rtmmsg->ifi_family = AF_UNSPEC;
-	rtmmsg->ifi_index = netdev->index;
+	l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
 
-	netdev->get_link_cmd_id = l_netlink_send(rtnl, RTM_GETLINK, 0, rtmmsg,
-						bufsize, netdev_getlink_cb,
+	netdev->get_link_cmd_id = l_netlink_send(rtnl, nlm, netdev_getlink_cb,
 						netdev, NULL);
 	L_WARN_ON(netdev->get_link_cmd_id == 0);
-
-	l_free(rtmmsg);
 }
 
 struct netdev *netdev_create_from_genl(struct l_genl_msg *msg,
-- 
2.45.2


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

* [PATCH 3/3] monitor: Update to the new ell l_netlink_send API
  2024-07-26 22:37 [PATCH 1/3] wired: Update to the new l_netlink_send API Denis Kenzior
  2024-07-26 22:37 ` [PATCH 2/3] netdev: " Denis Kenzior
@ 2024-07-26 22:37 ` Denis Kenzior
  2024-07-29 11:41 ` [PATCH 1/3] wired: Update to the new " James Prestwood
  2024-07-30 15:53 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2024-07-26 22:37 UTC (permalink / raw)
  To: iwd; +Cc: Denis Kenzior

---
 monitor/main.c | 88 ++++++++++++++------------------------------------
 1 file changed, 24 insertions(+), 64 deletions(-)

diff --git a/monitor/main.c b/monitor/main.c
index 32f5ec4fc7f3..c560db775caa 100644
--- a/monitor/main.c
+++ b/monitor/main.c
@@ -260,22 +260,6 @@ static struct l_genl *genl_lookup(const char *ifname)
 	return genl;
 }
 
-static size_t rta_add(void *rta_buf, unsigned short type, uint16_t len,
-			const void *data)
-{
-	unsigned short rta_len = RTA_LENGTH(len);
-	struct rtattr *rta = rta_buf;
-
-	memset(RTA_DATA(rta), 0, RTA_SPACE(len));
-
-	rta->rta_len = rta_len;
-	rta->rta_type = type;
-	if (len)
-		memcpy(RTA_DATA(rta), data, len);
-
-	return RTA_SPACE(len);
-}
-
 static bool rta_linkinfo_kind(struct rtattr *rta, unsigned short len,
 			const char* kind)
 {
@@ -304,10 +288,9 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl,
 {
 	size_t nlmon_type_len = strlen(NLMON_TYPE);
 	unsigned short ifname_len = 0;
-	size_t bufsize;
-	struct ifinfomsg *rtmmsg;
-	void *rta_buf;
-	struct rtattr *linkinfo_rta;
+	struct l_netlink_message *nlm;
+	struct ifinfomsg ifi;
+	uint16_t flags = 0;
 
 	if (ifname) {
 		ifname_len = strlen(ifname) + 1;
@@ -316,64 +299,41 @@ static struct l_netlink *rtm_interface_send_message(struct l_netlink *rtnl,
 			return NULL;
 	}
 
+	if (!L_IN_SET(rtm_msg_type, RTM_NEWLINK, RTM_DELLINK, RTM_GETLINK))
+		return NULL;
+
 	if (!rtnl)
 		rtnl = l_netlink_new(NETLINK_ROUTE);
 
 	if (!rtnl)
 		return NULL;
 
-	bufsize = NLMSG_LENGTH(sizeof(struct ifinfomsg)) +
-		RTA_SPACE(ifname_len) + RTA_SPACE(0) +
-		RTA_SPACE(nlmon_type_len);
-
-	rtmmsg = l_malloc(bufsize);
-	memset(rtmmsg, 0, bufsize);
-
-	rtmmsg->ifi_family = AF_UNSPEC;
-	rtmmsg->ifi_change = ~0;
-
-	rta_buf = rtmmsg + 1;
-
-	if (ifname)
-		rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname);
-
-	linkinfo_rta = rta_buf;
-
-	rta_buf += rta_add(rta_buf, IFLA_LINKINFO, 0, NULL);
-	rta_buf += rta_add(rta_buf, IFLA_INFO_KIND, nlmon_type_len, NLMON_TYPE);
-
-	linkinfo_rta->rta_len = rta_buf - (void *) linkinfo_rta;
+	memset(&ifi, 0, sizeof(ifi));
+	ifi.ifi_family = AF_UNSPEC;
+	ifi.ifi_change = ~0;
 
 	switch (rtm_msg_type) {
 	case RTM_NEWLINK:
-		rtmmsg->ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP;
-
-		l_netlink_send(rtnl, RTM_NEWLINK, NLM_F_CREATE|NLM_F_EXCL,
-				rtmmsg, rta_buf - (void *) rtmmsg, callback,
-				user_data, destroy);
+		ifi.ifi_flags = IFF_UP | IFF_ALLMULTI | IFF_NOARP;
+		flags = NLM_F_CREATE | NLM_F_EXCL;
 		break;
-
-	case RTM_DELLINK:
-		rta_buf += rta_add(rta_buf, IFLA_IFNAME, ifname_len, ifname);
-
-		l_netlink_send(rtnl, RTM_DELLINK, 0, rtmmsg,
-				rta_buf - (void *)rtmmsg, callback, user_data,
-				destroy);
-		break;
-
 	case RTM_GETLINK:
-		l_netlink_send(rtnl, RTM_GETLINK, NLM_F_DUMP, rtmmsg,
-				rta_buf - (void *)rtmmsg, callback, user_data,
-				destroy);
-		break;
-
-	default:
-		l_netlink_destroy(rtnl);
-		rtnl = NULL;
+		flags = NLM_F_DUMP;
 		break;
 	}
 
-	l_free(rtmmsg);
+	nlm = l_netlink_message_new(rtm_msg_type, flags);;
+	l_netlink_message_add_header(nlm, &ifi, sizeof(ifi));
+
+	if (ifname)
+		l_netlink_message_append(nlm, IFLA_IFNAME, ifname, ifname_len);
+
+	l_netlink_message_enter_nested(nlm, IFLA_LINKINFO);
+	l_netlink_message_append(nlm, IFLA_INFO_KIND,
+						NLMON_TYPE, nlmon_type_len);
+	l_netlink_message_leave_nested(nlm);
+
+	l_netlink_send(rtnl, nlm, callback, user_data, destroy);
 
 	return rtnl;
 }
-- 
2.45.2


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

* Re: [PATCH 1/3] wired: Update to the new l_netlink_send API
  2024-07-26 22:37 [PATCH 1/3] wired: Update to the new l_netlink_send API Denis Kenzior
  2024-07-26 22:37 ` [PATCH 2/3] netdev: " Denis Kenzior
  2024-07-26 22:37 ` [PATCH 3/3] monitor: Update to the new ell " Denis Kenzior
@ 2024-07-29 11:41 ` James Prestwood
  2024-07-30 15:53 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: James Prestwood @ 2024-07-29 11:41 UTC (permalink / raw)
  To: Denis Kenzior, iwd

On 7/26/24 3:37 PM, Denis Kenzior wrote:
> ---
>   wired/ethdev.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
>
All look good to me

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

* Re: [PATCH 1/3] wired: Update to the new l_netlink_send API
  2024-07-26 22:37 [PATCH 1/3] wired: Update to the new l_netlink_send API Denis Kenzior
                   ` (2 preceding siblings ...)
  2024-07-29 11:41 ` [PATCH 1/3] wired: Update to the new " James Prestwood
@ 2024-07-30 15:53 ` Denis Kenzior
  3 siblings, 0 replies; 5+ messages in thread
From: Denis Kenzior @ 2024-07-30 15:53 UTC (permalink / raw)
  To: iwd

On 7/26/24 5:37 PM, Denis Kenzior wrote:
> ---
>   wired/ethdev.c | 10 ++++++----
>   1 file changed, 6 insertions(+), 4 deletions(-)
> 

All applied


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

end of thread, other threads:[~2024-07-30 15:53 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2024-07-26 22:37 [PATCH 1/3] wired: Update to the new l_netlink_send API Denis Kenzior
2024-07-26 22:37 ` [PATCH 2/3] netdev: " Denis Kenzior
2024-07-26 22:37 ` [PATCH 3/3] monitor: Update to the new ell " Denis Kenzior
2024-07-29 11:41 ` [PATCH 1/3] wired: Update to the new " James Prestwood
2024-07-30 15:53 ` Denis Kenzior

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox