All of lore.kernel.org
 help / color / mirror / Atom feed
From: fw@strlen.de (Florian Westphal)
To: linux-security-module@vger.kernel.org
Subject: [PATCH security-next 1/2] smack: use pernet operations for hook registration
Date: Fri, 21 Apr 2017 11:49:08 +0200	[thread overview]
Message-ID: <20170421094909.28961-2-fw@strlen.de> (raw)
In-Reply-To: <20170421094909.28961-1-fw@strlen.de>

It will allow us to remove the old netfilter hook api in the near future.

Signed-off-by: Florian Westphal <fw@strlen.de>
---
 security/smack/smack_netfilter.c | 26 ++++++++++++++++++--------
 1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/security/smack/smack_netfilter.c b/security/smack/smack_netfilter.c
index 205b785fb400..cdeb0f3243dd 100644
--- a/security/smack/smack_netfilter.c
+++ b/security/smack/smack_netfilter.c
@@ -18,6 +18,7 @@
 #include <linux/netfilter_ipv6.h>
 #include <linux/netdevice.h>
 #include <net/inet_sock.h>
+#include <net/net_namespace.h>
 #include "smack.h"
 
 #if IS_ENABLED(CONFIG_IPV6)
@@ -74,20 +75,29 @@ static struct nf_hook_ops smack_nf_ops[] = {
 #endif	/* IPV6 */
 };
 
-static int __init smack_nf_ip_init(void)
+static int __net_init smack_nf_register(struct net *net)
+{
+	return nf_register_net_hooks(net, smack_nf_ops,
+				     ARRAY_SIZE(smack_nf_ops));
+}
+
+static void __net_exit smack_nf_unregister(struct net *net)
 {
-	int err;
+	nf_unregister_net_hooks(net, smack_nf_ops, ARRAY_SIZE(smack_nf_ops));
+}
 
+static struct pernet_operations smack_net_ops = {
+	.init = smack_nf_register,
+	.exit = smack_nf_unregister,
+};
+
+static int __init smack_nf_ip_init(void)
+{
 	if (smack_enabled == 0)
 		return 0;
 
 	printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");
-
-	err = nf_register_hooks(smack_nf_ops, ARRAY_SIZE(smack_nf_ops));
-	if (err)
-		pr_info("Smack: nf_register_hooks: error %d\n", err);
-
-	return 0;
+	return register_pernet_subsys(&smack_net_ops);
 }
 
 __initcall(smack_nf_ip_init);
-- 
2.10.2

--
To unsubscribe from this list: send the line "unsubscribe linux-security-module" in
the body of a message to majordomo at vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html

  reply	other threads:[~2017-04-21  9:49 UTC|newest]

Thread overview: 15+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-04-21  9:49 [PATCH security-next 0/2]: switch selinux and smack to pernet ops Florian Westphal
2017-04-21  9:49 ` Florian Westphal [this message]
2017-04-21 16:42   ` [PATCH security-next 1/2] smack: use pernet operations for hook registration Casey Schaufler
2017-04-21 17:57   ` Casey Schaufler
2017-06-01 16:44   ` Casey Schaufler
2017-06-02  8:33     ` Pablo Neira Ayuso
2017-06-02  8:48       ` Florian Westphal
2017-06-02  9:07         ` Pablo Neira Ayuso
2017-06-02 14:36         ` Paul Moore
2017-04-21  9:49 ` [PATCH security-next 2/2] selinux: " Florian Westphal
2017-04-26 20:46   ` Paul Moore
2017-04-26 20:47     ` Paul Moore
2017-04-26 20:47       ` Paul Moore
2017-06-02 14:33       ` Paul Moore
2017-06-02 14:33         ` Paul Moore

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20170421094909.28961-2-fw@strlen.de \
    --to=fw@strlen.de \
    --cc=linux-security-module@vger.kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.