Commit | Line | Data |
---|---|---|
17e6e59f JM |
1 | /* |
2 | * "security" table for IPv6 | |
3 | * | |
4 | * This is for use by Mandatory Access Control (MAC) security models, | |
5 | * which need to be able to manage security policy in separate context | |
6 | * to DAC. | |
7 | * | |
8 | * Based on iptable_mangle.c | |
9 | * | |
10 | * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling | |
11 | * Copyright (C) 2000-2004 Netfilter Core Team <coreteam <at> netfilter.org> | |
12 | * Copyright (C) 2008 Red Hat, Inc., James Morris <jmorris <at> redhat.com> | |
13 | * | |
14 | * This program is free software; you can redistribute it and/or modify | |
15 | * it under the terms of the GNU General Public License version 2 as | |
16 | * published by the Free Software Foundation. | |
17 | */ | |
18 | #include <linux/module.h> | |
19 | #include <linux/netfilter_ipv6/ip6_tables.h> | |
20 | ||
21 | MODULE_LICENSE("GPL"); | |
22 | MODULE_AUTHOR("James Morris <jmorris <at> redhat.com>"); | |
23 | MODULE_DESCRIPTION("ip6tables security table, for MAC rules"); | |
24 | ||
25 | #define SECURITY_VALID_HOOKS (1 << NF_INET_LOCAL_IN) | \ | |
26 | (1 << NF_INET_FORWARD) | \ | |
27 | (1 << NF_INET_LOCAL_OUT) | |
28 | ||
35aad0ff | 29 | static const struct |
17e6e59f JM |
30 | { |
31 | struct ip6t_replace repl; | |
32 | struct ip6t_standard entries[3]; | |
33 | struct ip6t_error term; | |
f858b486 | 34 | } initial_table __net_initdata = { |
17e6e59f JM |
35 | .repl = { |
36 | .name = "security", | |
37 | .valid_hooks = SECURITY_VALID_HOOKS, | |
38 | .num_entries = 4, | |
39 | .size = sizeof(struct ip6t_standard) * 3 + sizeof(struct ip6t_error), | |
40 | .hook_entry = { | |
41 | [NF_INET_LOCAL_IN] = 0, | |
42 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard), | |
43 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2, | |
44 | }, | |
45 | .underflow = { | |
46 | [NF_INET_LOCAL_IN] = 0, | |
47 | [NF_INET_FORWARD] = sizeof(struct ip6t_standard), | |
48 | [NF_INET_LOCAL_OUT] = sizeof(struct ip6t_standard) * 2, | |
49 | }, | |
50 | }, | |
51 | .entries = { | |
52 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_IN */ | |
53 | IP6T_STANDARD_INIT(NF_ACCEPT), /* FORWARD */ | |
54 | IP6T_STANDARD_INIT(NF_ACCEPT), /* LOCAL_OUT */ | |
55 | }, | |
56 | .term = IP6T_ERROR_INIT, /* ERROR */ | |
57 | }; | |
58 | ||
35aad0ff | 59 | static const struct xt_table security_table = { |
17e6e59f JM |
60 | .name = "security", |
61 | .valid_hooks = SECURITY_VALID_HOOKS, | |
17e6e59f | 62 | .me = THIS_MODULE, |
f88e6a8a | 63 | .af = NFPROTO_IPV6, |
17e6e59f JM |
64 | }; |
65 | ||
66 | static unsigned int | |
737535c5 JE |
67 | ip6table_security_hook(unsigned int hook, struct sk_buff *skb, |
68 | const struct net_device *in, | |
69 | const struct net_device *out, | |
70 | int (*okfn)(struct sk_buff *)) | |
17e6e59f | 71 | { |
2b21e051 | 72 | const struct net *net = dev_net((in != NULL) ? in : out); |
17e6e59f | 73 | |
2b21e051 | 74 | return ip6t_do_table(skb, hook, in, out, net->ipv6.ip6table_security); |
17e6e59f JM |
75 | } |
76 | ||
17e6e59f JM |
77 | static struct nf_hook_ops ip6t_ops[] __read_mostly = { |
78 | { | |
737535c5 | 79 | .hook = ip6table_security_hook, |
17e6e59f | 80 | .owner = THIS_MODULE, |
24c232d8 | 81 | .pf = NFPROTO_IPV6, |
17e6e59f JM |
82 | .hooknum = NF_INET_LOCAL_IN, |
83 | .priority = NF_IP6_PRI_SECURITY, | |
84 | }, | |
85 | { | |
737535c5 | 86 | .hook = ip6table_security_hook, |
17e6e59f | 87 | .owner = THIS_MODULE, |
24c232d8 | 88 | .pf = NFPROTO_IPV6, |
17e6e59f JM |
89 | .hooknum = NF_INET_FORWARD, |
90 | .priority = NF_IP6_PRI_SECURITY, | |
91 | }, | |
92 | { | |
737535c5 | 93 | .hook = ip6table_security_hook, |
17e6e59f | 94 | .owner = THIS_MODULE, |
24c232d8 | 95 | .pf = NFPROTO_IPV6, |
17e6e59f JM |
96 | .hooknum = NF_INET_LOCAL_OUT, |
97 | .priority = NF_IP6_PRI_SECURITY, | |
98 | }, | |
99 | }; | |
100 | ||
101 | static int __net_init ip6table_security_net_init(struct net *net) | |
102 | { | |
103 | net->ipv6.ip6table_security = | |
104 | ip6t_register_table(net, &security_table, &initial_table.repl); | |
105 | ||
106 | if (IS_ERR(net->ipv6.ip6table_security)) | |
107 | return PTR_ERR(net->ipv6.ip6table_security); | |
108 | ||
109 | return 0; | |
110 | } | |
111 | ||
112 | static void __net_exit ip6table_security_net_exit(struct net *net) | |
113 | { | |
f54e9367 | 114 | ip6t_unregister_table(net, net->ipv6.ip6table_security); |
17e6e59f JM |
115 | } |
116 | ||
117 | static struct pernet_operations ip6table_security_net_ops = { | |
118 | .init = ip6table_security_net_init, | |
119 | .exit = ip6table_security_net_exit, | |
120 | }; | |
121 | ||
122 | static int __init ip6table_security_init(void) | |
123 | { | |
124 | int ret; | |
125 | ||
126 | ret = register_pernet_subsys(&ip6table_security_net_ops); | |
127 | if (ret < 0) | |
128 | return ret; | |
129 | ||
130 | ret = nf_register_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); | |
131 | if (ret < 0) | |
132 | goto cleanup_table; | |
133 | ||
134 | return ret; | |
135 | ||
136 | cleanup_table: | |
137 | unregister_pernet_subsys(&ip6table_security_net_ops); | |
138 | return ret; | |
139 | } | |
140 | ||
141 | static void __exit ip6table_security_fini(void) | |
142 | { | |
143 | nf_unregister_hooks(ip6t_ops, ARRAY_SIZE(ip6t_ops)); | |
144 | unregister_pernet_subsys(&ip6table_security_net_ops); | |
145 | } | |
146 | ||
147 | module_init(ip6table_security_init); | |
148 | module_exit(ip6table_security_fini); |