rhashtable: fix for resize events during table walk
[linux/fpc-iii.git] / security / smack / smack_netfilter.c
bloba455cfc9ec1f614851aba10693800a6acd476049
1 /*
2 * Simplified MAC Kernel (smack) security module
4 * This file contains the Smack netfilter implementation
6 * Author:
7 * Casey Schaufler <casey@schaufler-ca.com>
9 * Copyright (C) 2014 Casey Schaufler <casey@schaufler-ca.com>
10 * Copyright (C) 2014 Intel Corporation.
12 * This program is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU General Public License version 2,
14 * as published by the Free Software Foundation.
17 #include <linux/netfilter_ipv4.h>
18 #include <linux/netfilter_ipv6.h>
19 #include <linux/netdevice.h>
20 #include "smack.h"
22 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
24 static unsigned int smack_ipv6_output(const struct nf_hook_ops *ops,
25 struct sk_buff *skb,
26 const struct nf_hook_state *state)
28 struct socket_smack *ssp;
29 struct smack_known *skp;
31 if (skb && skb->sk && skb->sk->sk_security) {
32 ssp = skb->sk->sk_security;
33 skp = ssp->smk_out;
34 skb->secmark = skp->smk_secid;
37 return NF_ACCEPT;
39 #endif /* IPV6 */
41 static unsigned int smack_ipv4_output(const struct nf_hook_ops *ops,
42 struct sk_buff *skb,
43 const struct nf_hook_state *state)
45 struct socket_smack *ssp;
46 struct smack_known *skp;
48 if (skb && skb->sk && skb->sk->sk_security) {
49 ssp = skb->sk->sk_security;
50 skp = ssp->smk_out;
51 skb->secmark = skp->smk_secid;
54 return NF_ACCEPT;
57 static struct nf_hook_ops smack_nf_ops[] = {
59 .hook = smack_ipv4_output,
60 .owner = THIS_MODULE,
61 .pf = NFPROTO_IPV4,
62 .hooknum = NF_INET_LOCAL_OUT,
63 .priority = NF_IP_PRI_SELINUX_FIRST,
65 #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE)
67 .hook = smack_ipv6_output,
68 .owner = THIS_MODULE,
69 .pf = NFPROTO_IPV6,
70 .hooknum = NF_INET_LOCAL_OUT,
71 .priority = NF_IP6_PRI_SELINUX_FIRST,
73 #endif /* IPV6 */
76 static int __init smack_nf_ip_init(void)
78 int err;
80 if (smack_enabled == 0)
81 return 0;
83 printk(KERN_DEBUG "Smack: Registering netfilter hooks\n");
85 err = nf_register_hooks(smack_nf_ops, ARRAY_SIZE(smack_nf_ops));
86 if (err)
87 pr_info("Smack: nf_register_hooks: error %d\n", err);
89 return 0;
92 __initcall(smack_nf_ip_init);