[PATCH v2 3/8] rmnet: Track link notifications

Denis Kenzior <[email protected]>
Newsgroups dev.linux.lists.ofono
Message-ID <[email protected]>
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 --git a/src/rmnet.c b/src/rmnet.c
index 325f1c503ca9..5f40fcabcfb7 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(void)
 	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);
 }
 
-- 
2.47.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.