diff mbox series

[2/6] unit: Use the new l_netlink_attr API

Message ID 20240823161553.479576-2-denkenz@gmail.com (mailing list archive)
State New
Headers show
Series [1/6] netlink: Add l_netlink_iter | expand

Checks

Context Check Description
tedd_an/pre-ci_am success Success

Commit Message

Denis Kenzior Aug. 23, 2024, 4:15 p.m. UTC
---
 unit/test-netlink.c | 29 ++++++++++++++++-------------
 1 file changed, 16 insertions(+), 13 deletions(-)
diff mbox series

Patch

diff --git a/unit/test-netlink.c b/unit/test-netlink.c
index da23ee5c9b0e..113d735adf40 100644
--- a/unit/test-netlink.c
+++ b/unit/test-netlink.c
@@ -27,31 +27,34 @@  static void getlink_callback(int error, uint16_t type, const void *data,
 						uint32_t len, void *user_data)
 {
 	const struct ifinfomsg *ifi = data;
-	struct rtattr *rta;
-	int bytes;
+	struct l_netlink_attr attr;
 	char ifname[IF_NAMESIZE];
 	uint32_t index, flags;
+	uint16_t rta_type;
+	uint16_t rta_len;
+	const void *rta_data;
 
 	if (error)
 		goto done;
 
-	bytes = len - NLMSG_ALIGN(sizeof(struct ifinfomsg));
+	if (l_netlink_attr_init(&attr, sizeof(struct ifinfomsg), data, len) < 0)
+		goto done;
 
 	memset(ifname, 0, sizeof(ifname));
 
-	index = ifi->ifi_index;
-	flags = ifi->ifi_flags;
+	while (!l_netlink_attr_next(&attr, &rta_type, &rta_len, &rta_data)) {
+		if (rta_type != IFLA_IFNAME)
+			continue;
+
+		if (rta_len <= IF_NAMESIZE)
+			strcpy(ifname, rta_data);
 
-	for (rta = IFLA_RTA(ifi); RTA_OK(rta, bytes);
-					rta = RTA_NEXT(rta, bytes)) {
-		switch (rta->rta_type) {
-		case IFLA_IFNAME:
-			if (RTA_PAYLOAD(rta) <= IF_NAMESIZE)
-				strcpy(ifname, RTA_DATA(rta));
-			break;
-		}
+		break;
 	}
 
+	index = ifi->ifi_index;
+	flags = ifi->ifi_flags;
+
 	l_info("index=%d flags=0x%08x name=%s", index, flags, ifname);
 
 done: