[PATCH 6.1 06/15] genetlink: add netlink notifier support

Yana Bashlykova posted 15 patches 2 weeks, 5 days ago
[PATCH 6.1 06/15] genetlink: add netlink notifier support
Posted by Yana Bashlykova 2 weeks, 5 days ago
Add basic netlink notifier to monitor genetlink events:
- Simple ntf_genl_event() callback returning NOTIFY_OK
- Register/unregister in module init/exit
- Error handling for registration

Prepares infrastructure for tracking family registration events.

Signed-off-by: Yana Bashlykova <yana2bsh@gmail.com>
---
 .../net-pf-16-proto-16-family-PARALLEL_GENL.c | 19 +++++++++++++++++++
 1 file changed, 19 insertions(+)

diff --git a/drivers/net/genetlink/net-pf-16-proto-16-family-PARALLEL_GENL.c b/drivers/net/genetlink/net-pf-16-proto-16-family-PARALLEL_GENL.c
index 245f3b0f4fbb..cdedd77b2a1b 100644
--- a/drivers/net/genetlink/net-pf-16-proto-16-family-PARALLEL_GENL.c
+++ b/drivers/net/genetlink/net-pf-16-proto-16-family-PARALLEL_GENL.c
@@ -1116,6 +1116,16 @@ static struct genl_family incorrect_ops_genl_family = {
 	.policy = my_genl_policy, // random policy
 };
 
+static int ntf_genl_event(struct notifier_block *nb, unsigned long state,
+			  void *_notify)
+{
+	return NOTIFY_OK;
+}
+
+static struct notifier_block genl_notifier = {
+	.notifier_call = ntf_genl_event,
+};
+
 static int __init init_netlink(void)
 {
 	int rc;
@@ -1291,8 +1301,16 @@ static int __init module_netlink_init(void)
 	if (ret)
 		pr_err("%s: Incorrect Generic Netlink family wasn't registered\n", __func__);
 
+	ret = netlink_register_notifier(&genl_notifier);
+	if (ret)
+		goto err_family;
+
 	return 0;
 
+	// netlink_unregister_notifier(&genl_notifier);
+err_family:
+	genl_unregister_family(&my_genl_family);
+	genl_unregister_family(&my_genl_family_parallel);
 err_sysfs:
 	sysfs_remove_file(kobj_genl_test, &my_attr_u32_genl_test.attr);
 	sysfs_remove_file(kobj_genl_test, &my_attr_str_genl_test.attr);
@@ -1309,6 +1327,7 @@ static int __init module_netlink_init(void)
 
 static void __exit module_netlink_exit(void)
 {
+	netlink_unregister_notifier(&genl_notifier);
 	genl_unregister_family(&my_genl_family);
 	genl_unregister_family(&my_genl_family_parallel);
 
-- 
2.34.1