diff mbox series

[3/8] rmnet: Track link notifications

Message ID 20241115220053.49613-3-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 link notifications that arrive via RTM_NEWLINK and RTM_DELLINK.
This will be used in the future to try to de-conflict use of RMNet
mux_ids that might have been (unlikely) created by other processes.
---
 src/rmnet.c | 22 ++++++++++++++++++++++
 1 file changed, 22 insertions(+)
diff mbox series

Patch

diff --git a/src/rmnet.c b/src/rmnet.c
index 52f47a03b27c..920525006e0a 100644
--- a/src/rmnet.c
+++ b/src/rmnet.c
@@ -27,6 +27,7 @@ 
 
 static struct l_netlink *rtnl;
 static uint32_t dump_id;
+static uint32_t link_notify_id;
 
 int rmnet_get_interfaces(uint32_t parent_ifindex, unsigned int n_interfaces,
 				rmnet_new_interfaces_func_t cb,
@@ -193,6 +194,23 @@  static int rmnet_link_dump()
 	return -EIO;
 }
 
+static void rmnet_link_notification(uint16_t type, const void *data,
+					uint32_t len, void *user_data)
+{
+	char ifname[IF_NAMESIZE];
+	uint16_t mux_id;
+	uint32_t ifindex;
+
+	if (type != RTM_NEWLINK && type != RTM_DELLINK)
+		return;
+
+	if (rmnet_parse_link(data, len, ifname, &ifindex, &mux_id) < 0)
+		return;
+
+	DBG("link_notification: %s(%u) with mux_id: %u",
+			ifname, ifindex, mux_id);
+}
+
 static int rmnet_init(void)
 {
 	int r;
@@ -207,6 +225,9 @@  static int rmnet_init(void)
 	if (r < 0)
 		goto dump_failed;
 
+	link_notify_id = l_netlink_register(rtnl, RTNLGRP_LINK,
+					rmnet_link_notification, NULL, NULL);
+
 	return 0;
 dump_failed:
 	l_netlink_destroy(rtnl);
@@ -215,6 +236,7 @@  dump_failed:
 
 static void rmnet_exit(void)
 {
+	l_netlink_unregister(rtnl, link_notify_id);
 	l_netlink_destroy(rtnl);
 }