diff mbox series

[4/8] rmnet: Track used mux ids

Message ID 20241115220053.49613-4-denkenz@gmail.com (mailing list archive)
State Superseded
Headers show
Series [1/8] rmnet: Add skeleton | expand

Commit Message

Denis Kenzior Nov. 15, 2024, 10 p.m. UTC
Track used mux identifiers.  This uintset can later be used to allocate
unused mux identifiers.
---
 src/rmnet.c | 9 +++++++++
 1 file changed, 9 insertions(+)
diff mbox series

Patch

diff --git a/src/rmnet.c b/src/rmnet.c
index 920525006e0a..f784e5cc4bb2 100644
--- a/src/rmnet.c
+++ b/src/rmnet.c
@@ -28,6 +28,7 @@ 
 static struct l_netlink *rtnl;
 static uint32_t dump_id;
 static uint32_t link_notify_id;
+static struct l_uintset *mux_ids;
 
 int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces,
 				rmnet_new_interfaces_func_t cb,
@@ -169,6 +170,7 @@  static void rmnet_link_dump_cb(int error,
 
 	DBG("Existing rmnet link: %s(%u) mux_id: %u",
 			info.ifname, info.ifindex, info.mux_id);
+	l_uintset_put(mux_ids, info.mux_id);
 }
 
 static int rmnet_link_dump()
@@ -207,6 +209,11 @@  static void rmnet_link_notification(uint16_t type, const void *data,
 	if (rmnet_parse_link(data, len, ifname, &ifindex, &mux_id) < 0)
 		return;
 
+	if (type == RTM_NEWLINK)
+		l_uintset_put(mux_ids, mux_id);
+	else
+		l_uintset_take(mux_ids, mux_id);
+
 	DBG("link_notification: %s(%u) with mux_id: %u",
 			ifname, ifindex, mux_id);
 }
@@ -227,6 +234,7 @@  static int rmnet_init(void)
 
 	link_notify_id = l_netlink_register(rtnl, RTNLGRP_LINK,
 					rmnet_link_notification, NULL, NULL);
+	mux_ids = l_uintset_new_from_range(1, MAX_MUX_IDS);
 
 	return 0;
 dump_failed:
@@ -236,6 +244,7 @@  dump_failed:
 
 static void rmnet_exit(void)
 {
+	l_uintset_free(mux_ids);
 	l_netlink_unregister(rtnl, link_notify_id);
 	l_netlink_destroy(rtnl);
 }