]>
Commit | Line | Data |
---|---|---|
601e68e1 | 1 | /* netfilter.c: look after the filters for various protocols. |
f6ebe77f HW |
2 | * Heavily influenced by the old firewall.c by David Bonn and Alan Cox. |
3 | * | |
4 | * Thanks to Rob `CmdrTaco' Malda for not influencing this code in any | |
5 | * way. | |
6 | * | |
7 | * Rusty Russell (C)2000 -- This code is GPL. | |
f229f6ce | 8 | * Patrick McHardy (c) 2006-2012 |
f6ebe77f | 9 | */ |
f6ebe77f HW |
10 | #include <linux/kernel.h> |
11 | #include <linux/netfilter.h> | |
12 | #include <net/protocol.h> | |
13 | #include <linux/init.h> | |
14 | #include <linux/skbuff.h> | |
15 | #include <linux/wait.h> | |
16 | #include <linux/module.h> | |
17 | #include <linux/interrupt.h> | |
18 | #include <linux/if.h> | |
19 | #include <linux/netdevice.h> | |
56768644 | 20 | #include <linux/netfilter_ipv6.h> |
f6ebe77f HW |
21 | #include <linux/inetdevice.h> |
22 | #include <linux/proc_fs.h> | |
d486dd1f | 23 | #include <linux/mutex.h> |
5a0e3ad6 | 24 | #include <linux/slab.h> |
e3b37f11 | 25 | #include <linux/rcupdate.h> |
457c4cbc | 26 | #include <net/net_namespace.h> |
f6ebe77f HW |
27 | #include <net/sock.h> |
28 | ||
29 | #include "nf_internals.h" | |
30 | ||
d486dd1f | 31 | static DEFINE_MUTEX(afinfo_mutex); |
bce8032e | 32 | |
0906a372 | 33 | const struct nf_afinfo __rcu *nf_afinfo[NFPROTO_NUMPROTO] __read_mostly; |
bce8032e | 34 | EXPORT_SYMBOL(nf_afinfo); |
2a7851bf FW |
35 | const struct nf_ipv6_ops __rcu *nf_ipv6_ops __read_mostly; |
36 | EXPORT_SYMBOL_GPL(nf_ipv6_ops); | |
bce8032e | 37 | |
e7c8899f FW |
38 | DEFINE_PER_CPU(bool, nf_skb_duplicated); |
39 | EXPORT_SYMBOL_GPL(nf_skb_duplicated); | |
40 | ||
1e796fda | 41 | int nf_register_afinfo(const struct nf_afinfo *afinfo) |
bce8032e | 42 | { |
7926dbfa | 43 | mutex_lock(&afinfo_mutex); |
a9b3cd7f | 44 | RCU_INIT_POINTER(nf_afinfo[afinfo->family], afinfo); |
d486dd1f | 45 | mutex_unlock(&afinfo_mutex); |
bce8032e PM |
46 | return 0; |
47 | } | |
48 | EXPORT_SYMBOL_GPL(nf_register_afinfo); | |
49 | ||
1e796fda | 50 | void nf_unregister_afinfo(const struct nf_afinfo *afinfo) |
bce8032e | 51 | { |
d486dd1f | 52 | mutex_lock(&afinfo_mutex); |
a9b3cd7f | 53 | RCU_INIT_POINTER(nf_afinfo[afinfo->family], NULL); |
d486dd1f | 54 | mutex_unlock(&afinfo_mutex); |
bce8032e PM |
55 | synchronize_rcu(); |
56 | } | |
57 | EXPORT_SYMBOL_GPL(nf_unregister_afinfo); | |
58 | ||
d1c85c2e | 59 | #ifdef HAVE_JUMP_LABEL |
c5905afb | 60 | struct static_key nf_hooks_needed[NFPROTO_NUMPROTO][NF_MAX_HOOKS]; |
a2d7ec58 ED |
61 | EXPORT_SYMBOL(nf_hooks_needed); |
62 | #endif | |
63 | ||
fd706d69 | 64 | static DEFINE_MUTEX(nf_hook_mutex); |
e3b37f11 AC |
65 | #define nf_entry_dereference(e) \ |
66 | rcu_dereference_protected(e, lockdep_is_held(&nf_hook_mutex)) | |
f6ebe77f | 67 | |
bd3769bf | 68 | static struct nf_hook_entry __rcu **nf_hook_entry_head(struct net *net, const struct nf_hook_ops *reg) |
f6ebe77f | 69 | { |
0edcf282 | 70 | if (reg->pf != NFPROTO_NETDEV) |
bd3769bf LT |
71 | return net->nf.hooks[reg->pf]+reg->hooknum; |
72 | ||
e687ad60 | 73 | #ifdef CONFIG_NETFILTER_INGRESS |
bd3769bf | 74 | if (reg->hooknum == NF_NETDEV_INGRESS) { |
085db2c0 | 75 | if (reg->dev && dev_net(reg->dev) == net) |
bd3769bf | 76 | return ®->dev->nf_hooks_ingress; |
e687ad60 | 77 | } |
7816ec56 | 78 | #endif |
bd3769bf | 79 | return NULL; |
e3b37f11 | 80 | } |
7181ebaf | 81 | |
085db2c0 | 82 | int nf_register_net_hook(struct net *net, const struct nf_hook_ops *reg) |
0edcf282 | 83 | { |
bd3769bf LT |
84 | struct nf_hook_entry __rcu **pp; |
85 | struct nf_hook_entry *entry, *p; | |
085db2c0 | 86 | |
7816ec56 AC |
87 | if (reg->pf == NFPROTO_NETDEV) { |
88 | #ifndef CONFIG_NETFILTER_INGRESS | |
89 | if (reg->hooknum == NF_NETDEV_INGRESS) | |
90 | return -EOPNOTSUPP; | |
91 | #endif | |
92 | if (reg->hooknum != NF_NETDEV_INGRESS || | |
93 | !reg->dev || dev_net(reg->dev) != net) | |
94 | return -EINVAL; | |
95 | } | |
d4bb5caa | 96 | |
bd3769bf LT |
97 | pp = nf_hook_entry_head(net, reg); |
98 | if (!pp) | |
99 | return -EINVAL; | |
100 | ||
7181ebaf PNA |
101 | entry = kmalloc(sizeof(*entry), GFP_KERNEL); |
102 | if (!entry) | |
085db2c0 | 103 | return -ENOMEM; |
0edcf282 | 104 | |
0aa8c57a | 105 | nf_hook_entry_init(entry, reg); |
e3b37f11 AC |
106 | |
107 | mutex_lock(&nf_hook_mutex); | |
085db2c0 | 108 | |
bd3769bf | 109 | /* Find the spot in the list */ |
679972f3 | 110 | for (; (p = nf_entry_dereference(*pp)) != NULL; pp = &p->next) { |
0aa8c57a | 111 | if (reg->priority < nf_hook_entry_priority(p)) |
bd3769bf | 112 | break; |
f6ebe77f | 113 | } |
bd3769bf LT |
114 | rcu_assign_pointer(entry->next, p); |
115 | rcu_assign_pointer(*pp, entry); | |
e3b37f11 | 116 | |
fd706d69 | 117 | mutex_unlock(&nf_hook_mutex); |
4c091156 EB |
118 | #ifdef CONFIG_NETFILTER_INGRESS |
119 | if (reg->pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS) | |
120 | net_inc_ingress_queue(); | |
121 | #endif | |
d1c85c2e | 122 | #ifdef HAVE_JUMP_LABEL |
c5905afb | 123 | static_key_slow_inc(&nf_hooks_needed[reg->pf][reg->hooknum]); |
a2d7ec58 | 124 | #endif |
f6ebe77f HW |
125 | return 0; |
126 | } | |
085db2c0 | 127 | EXPORT_SYMBOL(nf_register_net_hook); |
f6ebe77f | 128 | |
933bd83e FW |
129 | static struct nf_hook_entry * |
130 | __nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg) | |
f6ebe77f | 131 | { |
bd3769bf LT |
132 | struct nf_hook_entry __rcu **pp; |
133 | struct nf_hook_entry *p; | |
134 | ||
135 | pp = nf_hook_entry_head(net, reg); | |
136 | if (WARN_ON_ONCE(!pp)) | |
933bd83e | 137 | return NULL; |
085db2c0 | 138 | |
fd706d69 | 139 | mutex_lock(&nf_hook_mutex); |
679972f3 | 140 | for (; (p = nf_entry_dereference(*pp)) != NULL; pp = &p->next) { |
0aa8c57a | 141 | if (nf_hook_entry_ops(p) == reg) { |
bd3769bf LT |
142 | rcu_assign_pointer(*pp, p->next); |
143 | break; | |
085db2c0 EB |
144 | } |
145 | } | |
fd706d69 | 146 | mutex_unlock(&nf_hook_mutex); |
bd3769bf | 147 | if (!p) { |
085db2c0 | 148 | WARN(1, "nf_unregister_net_hook: hook not found!\n"); |
933bd83e | 149 | return NULL; |
085db2c0 | 150 | } |
e687ad60 | 151 | #ifdef CONFIG_NETFILTER_INGRESS |
4c091156 EB |
152 | if (reg->pf == NFPROTO_NETDEV && reg->hooknum == NF_NETDEV_INGRESS) |
153 | net_dec_ingress_queue(); | |
e687ad60 | 154 | #endif |
d1c85c2e | 155 | #ifdef HAVE_JUMP_LABEL |
c5905afb | 156 | static_key_slow_dec(&nf_hooks_needed[reg->pf][reg->hooknum]); |
a2d7ec58 | 157 | #endif |
933bd83e FW |
158 | |
159 | return p; | |
160 | } | |
161 | ||
162 | void nf_unregister_net_hook(struct net *net, const struct nf_hook_ops *reg) | |
163 | { | |
164 | struct nf_hook_entry *p = __nf_unregister_net_hook(net, reg); | |
039b40ee | 165 | unsigned int nfq; |
933bd83e FW |
166 | |
167 | if (!p) | |
168 | return; | |
169 | ||
f6ebe77f | 170 | synchronize_net(); |
039b40ee | 171 | |
514ed62e | 172 | /* other cpu might still process nfqueue verdict that used reg */ |
039b40ee FW |
173 | nfq = nf_queue_nf_hook_drop(net); |
174 | if (nfq) | |
175 | synchronize_net(); | |
bd3769bf | 176 | kfree(p); |
085db2c0 EB |
177 | } |
178 | EXPORT_SYMBOL(nf_unregister_net_hook); | |
179 | ||
180 | int nf_register_net_hooks(struct net *net, const struct nf_hook_ops *reg, | |
181 | unsigned int n) | |
182 | { | |
183 | unsigned int i; | |
184 | int err = 0; | |
185 | ||
186 | for (i = 0; i < n; i++) { | |
187 | err = nf_register_net_hook(net, ®[i]); | |
188 | if (err) | |
189 | goto err; | |
190 | } | |
191 | return err; | |
192 | ||
193 | err: | |
194 | if (i > 0) | |
195 | nf_unregister_net_hooks(net, reg, i); | |
196 | return err; | |
197 | } | |
198 | EXPORT_SYMBOL(nf_register_net_hooks); | |
199 | ||
200 | void nf_unregister_net_hooks(struct net *net, const struct nf_hook_ops *reg, | |
933bd83e | 201 | unsigned int hookcount) |
085db2c0 | 202 | { |
933bd83e | 203 | struct nf_hook_entry *to_free[16]; |
039b40ee | 204 | unsigned int i, n, nfq; |
933bd83e FW |
205 | |
206 | do { | |
207 | n = min_t(unsigned int, hookcount, ARRAY_SIZE(to_free)); | |
208 | ||
209 | for (i = 0; i < n; i++) | |
210 | to_free[i] = __nf_unregister_net_hook(net, ®[i]); | |
211 | ||
212 | synchronize_net(); | |
213 | ||
039b40ee FW |
214 | /* need 2nd synchronize_net() if nfqueue is used, skb |
215 | * can get reinjected right before nf_queue_hook_drop() | |
216 | */ | |
217 | nfq = nf_queue_nf_hook_drop(net); | |
218 | if (nfq) | |
219 | synchronize_net(); | |
933bd83e FW |
220 | |
221 | for (i = 0; i < n; i++) | |
222 | kfree(to_free[i]); | |
223 | ||
224 | reg += n; | |
225 | hookcount -= n; | |
226 | } while (hookcount > 0); | |
085db2c0 EB |
227 | } |
228 | EXPORT_SYMBOL(nf_unregister_net_hooks); | |
229 | ||
230 | static LIST_HEAD(nf_hook_list); | |
231 | ||
e8bffe0c | 232 | static int _nf_register_hook(struct nf_hook_ops *reg) |
085db2c0 EB |
233 | { |
234 | struct net *net, *last; | |
235 | int ret; | |
236 | ||
085db2c0 EB |
237 | for_each_net(net) { |
238 | ret = nf_register_net_hook(net, reg); | |
239 | if (ret && ret != -ENOENT) | |
240 | goto rollback; | |
241 | } | |
242 | list_add_tail(®->list, &nf_hook_list); | |
085db2c0 EB |
243 | |
244 | return 0; | |
245 | rollback: | |
246 | last = net; | |
247 | for_each_net(net) { | |
248 | if (net == last) | |
249 | break; | |
250 | nf_unregister_net_hook(net, reg); | |
251 | } | |
e8bffe0c MB |
252 | return ret; |
253 | } | |
254 | ||
255 | int nf_register_hook(struct nf_hook_ops *reg) | |
256 | { | |
257 | int ret; | |
258 | ||
259 | rtnl_lock(); | |
260 | ret = _nf_register_hook(reg); | |
085db2c0 | 261 | rtnl_unlock(); |
e8bffe0c | 262 | |
085db2c0 EB |
263 | return ret; |
264 | } | |
265 | EXPORT_SYMBOL(nf_register_hook); | |
266 | ||
e8bffe0c | 267 | static void _nf_unregister_hook(struct nf_hook_ops *reg) |
085db2c0 EB |
268 | { |
269 | struct net *net; | |
270 | ||
085db2c0 EB |
271 | list_del(®->list); |
272 | for_each_net(net) | |
273 | nf_unregister_net_hook(net, reg); | |
e8bffe0c MB |
274 | } |
275 | ||
276 | void nf_unregister_hook(struct nf_hook_ops *reg) | |
277 | { | |
278 | rtnl_lock(); | |
279 | _nf_unregister_hook(reg); | |
085db2c0 | 280 | rtnl_unlock(); |
f6ebe77f HW |
281 | } |
282 | EXPORT_SYMBOL(nf_unregister_hook); | |
283 | ||
972d1cb1 PM |
284 | int nf_register_hooks(struct nf_hook_ops *reg, unsigned int n) |
285 | { | |
286 | unsigned int i; | |
287 | int err = 0; | |
288 | ||
289 | for (i = 0; i < n; i++) { | |
290 | err = nf_register_hook(®[i]); | |
291 | if (err) | |
292 | goto err; | |
293 | } | |
294 | return err; | |
295 | ||
296 | err: | |
297 | if (i > 0) | |
298 | nf_unregister_hooks(reg, i); | |
299 | return err; | |
300 | } | |
301 | EXPORT_SYMBOL(nf_register_hooks); | |
302 | ||
e8bffe0c MB |
303 | /* Caller MUST take rtnl_lock() */ |
304 | int _nf_register_hooks(struct nf_hook_ops *reg, unsigned int n) | |
305 | { | |
306 | unsigned int i; | |
307 | int err = 0; | |
308 | ||
309 | for (i = 0; i < n; i++) { | |
310 | err = _nf_register_hook(®[i]); | |
311 | if (err) | |
312 | goto err; | |
313 | } | |
314 | return err; | |
315 | ||
316 | err: | |
317 | if (i > 0) | |
318 | _nf_unregister_hooks(reg, i); | |
319 | return err; | |
320 | } | |
321 | EXPORT_SYMBOL(_nf_register_hooks); | |
322 | ||
972d1cb1 PM |
323 | void nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n) |
324 | { | |
f68c5301 CG |
325 | while (n-- > 0) |
326 | nf_unregister_hook(®[n]); | |
972d1cb1 PM |
327 | } |
328 | EXPORT_SYMBOL(nf_unregister_hooks); | |
329 | ||
e8bffe0c MB |
330 | /* Caller MUST take rtnl_lock */ |
331 | void _nf_unregister_hooks(struct nf_hook_ops *reg, unsigned int n) | |
332 | { | |
333 | while (n-- > 0) | |
334 | _nf_unregister_hook(®[n]); | |
335 | } | |
336 | EXPORT_SYMBOL(_nf_unregister_hooks); | |
337 | ||
f6ebe77f | 338 | /* Returns 1 if okfn() needs to be executed by the caller, |
e2361cb9 | 339 | * -EPERM for NF_DROP, 0 otherwise. Caller must hold rcu_read_lock. */ |
01886bd9 PNA |
340 | int nf_hook_slow(struct sk_buff *skb, struct nf_hook_state *state, |
341 | struct nf_hook_entry *entry) | |
f6ebe77f | 342 | { |
f6ebe77f | 343 | unsigned int verdict; |
c63cbc46 | 344 | int ret; |
f6ebe77f | 345 | |
26dfab72 | 346 | do { |
0aa8c57a | 347 | verdict = nf_hook_entry_hookfn(entry, skb, state); |
26dfab72 PNA |
348 | switch (verdict & NF_VERDICT_MASK) { |
349 | case NF_ACCEPT: | |
350 | entry = rcu_dereference(entry->next); | |
351 | break; | |
352 | case NF_DROP: | |
353 | kfree_skb(skb); | |
354 | ret = NF_DROP_GETERR(verdict); | |
355 | if (ret == 0) | |
356 | ret = -EPERM; | |
357 | return ret; | |
26dfab72 PNA |
358 | case NF_QUEUE: |
359 | ret = nf_queue(skb, state, &entry, verdict); | |
360 | if (ret == 1 && entry) | |
361 | continue; | |
362 | return ret; | |
363 | default: | |
364 | /* Implicit handling for NF_STOLEN, as well as any other | |
365 | * non conventional verdicts. | |
366 | */ | |
367 | return 0; | |
368 | } | |
369 | } while (entry); | |
370 | ||
371 | return 1; | |
f6ebe77f HW |
372 | } |
373 | EXPORT_SYMBOL(nf_hook_slow); | |
374 | ||
375 | ||
37d41879 | 376 | int skb_make_writable(struct sk_buff *skb, unsigned int writable_len) |
f6ebe77f | 377 | { |
37d41879 | 378 | if (writable_len > skb->len) |
f6ebe77f HW |
379 | return 0; |
380 | ||
381 | /* Not exclusive use of packet? Must copy. */ | |
37d41879 HX |
382 | if (!skb_cloned(skb)) { |
383 | if (writable_len <= skb_headlen(skb)) | |
384 | return 1; | |
385 | } else if (skb_clone_writable(skb, writable_len)) | |
386 | return 1; | |
387 | ||
388 | if (writable_len <= skb_headlen(skb)) | |
389 | writable_len = 0; | |
390 | else | |
391 | writable_len -= skb_headlen(skb); | |
392 | ||
393 | return !!__pskb_pull_tail(skb, writable_len); | |
f6ebe77f HW |
394 | } |
395 | EXPORT_SYMBOL(skb_make_writable); | |
396 | ||
b7bd1809 PNA |
397 | /* This needs to be compiled in any case to avoid dependencies between the |
398 | * nfnetlink_queue code and nf_conntrack. | |
399 | */ | |
a4b4766c KM |
400 | struct nfnl_ct_hook __rcu *nfnl_ct_hook __read_mostly; |
401 | EXPORT_SYMBOL_GPL(nfnl_ct_hook); | |
b7bd1809 | 402 | |
c0cd1156 | 403 | #if IS_ENABLED(CONFIG_NF_CONNTRACK) |
f6ebe77f HW |
404 | /* This does not belong here, but locally generated errors need it if connection |
405 | tracking in use: without this, connection may not be in hash table, and hence | |
406 | manufactured ICMP or RST packets will not be associated with it. */ | |
312a0c16 PM |
407 | void (*ip_ct_attach)(struct sk_buff *, const struct sk_buff *) |
408 | __rcu __read_mostly; | |
f6ebe77f HW |
409 | EXPORT_SYMBOL(ip_ct_attach); |
410 | ||
312a0c16 | 411 | void nf_ct_attach(struct sk_buff *new, const struct sk_buff *skb) |
f6ebe77f | 412 | { |
312a0c16 | 413 | void (*attach)(struct sk_buff *, const struct sk_buff *); |
f6ebe77f | 414 | |
a9e419dc | 415 | if (skb->_nfct) { |
c3a47ab3 PM |
416 | rcu_read_lock(); |
417 | attach = rcu_dereference(ip_ct_attach); | |
418 | if (attach) | |
419 | attach(new, skb); | |
420 | rcu_read_unlock(); | |
f6ebe77f HW |
421 | } |
422 | } | |
423 | EXPORT_SYMBOL(nf_ct_attach); | |
de6e05c4 | 424 | |
0e60ebe0 | 425 | void (*nf_ct_destroy)(struct nf_conntrack *) __rcu __read_mostly; |
de6e05c4 YK |
426 | EXPORT_SYMBOL(nf_ct_destroy); |
427 | ||
428 | void nf_conntrack_destroy(struct nf_conntrack *nfct) | |
429 | { | |
430 | void (*destroy)(struct nf_conntrack *); | |
431 | ||
432 | rcu_read_lock(); | |
433 | destroy = rcu_dereference(nf_ct_destroy); | |
434 | BUG_ON(destroy == NULL); | |
435 | destroy(nfct); | |
436 | rcu_read_unlock(); | |
437 | } | |
438 | EXPORT_SYMBOL(nf_conntrack_destroy); | |
9cb01766 | 439 | |
62da9865 DB |
440 | /* Built-in default zone used e.g. by modules. */ |
441 | const struct nf_conntrack_zone nf_ct_zone_dflt = { | |
442 | .id = NF_CT_DEFAULT_ZONE_ID, | |
443 | .dir = NF_CT_DEFAULT_ZONE_DIR, | |
444 | }; | |
445 | EXPORT_SYMBOL_GPL(nf_ct_zone_dflt); | |
de6e05c4 | 446 | #endif /* CONFIG_NF_CONNTRACK */ |
f6ebe77f | 447 | |
c7232c99 PM |
448 | #ifdef CONFIG_NF_NAT_NEEDED |
449 | void (*nf_nat_decode_session_hook)(struct sk_buff *, struct flowi *); | |
450 | EXPORT_SYMBOL(nf_nat_decode_session_hook); | |
451 | #endif | |
452 | ||
085db2c0 EB |
453 | static int nf_register_hook_list(struct net *net) |
454 | { | |
455 | struct nf_hook_ops *elem; | |
456 | int ret; | |
457 | ||
458 | rtnl_lock(); | |
459 | list_for_each_entry(elem, &nf_hook_list, list) { | |
460 | ret = nf_register_net_hook(net, elem); | |
461 | if (ret && ret != -ENOENT) | |
462 | goto out_undo; | |
463 | } | |
464 | rtnl_unlock(); | |
465 | return 0; | |
466 | ||
467 | out_undo: | |
468 | list_for_each_entry_continue_reverse(elem, &nf_hook_list, list) | |
469 | nf_unregister_net_hook(net, elem); | |
470 | rtnl_unlock(); | |
471 | return ret; | |
472 | } | |
473 | ||
474 | static void nf_unregister_hook_list(struct net *net) | |
475 | { | |
476 | struct nf_hook_ops *elem; | |
477 | ||
478 | rtnl_lock(); | |
479 | list_for_each_entry(elem, &nf_hook_list, list) | |
480 | nf_unregister_net_hook(net, elem); | |
481 | rtnl_unlock(); | |
482 | } | |
483 | ||
f3c1a44a G |
484 | static int __net_init netfilter_net_init(struct net *net) |
485 | { | |
085db2c0 EB |
486 | int i, h, ret; |
487 | ||
488 | for (i = 0; i < ARRAY_SIZE(net->nf.hooks); i++) { | |
489 | for (h = 0; h < NF_MAX_HOOKS; h++) | |
e3b37f11 | 490 | RCU_INIT_POINTER(net->nf.hooks[i][h], NULL); |
085db2c0 EB |
491 | } |
492 | ||
f3c1a44a G |
493 | #ifdef CONFIG_PROC_FS |
494 | net->nf.proc_netfilter = proc_net_mkdir(net, "netfilter", | |
495 | net->proc_net); | |
12202fa7 PNA |
496 | if (!net->nf.proc_netfilter) { |
497 | if (!net_eq(net, &init_net)) | |
498 | pr_err("cannot create netfilter proc entry"); | |
499 | ||
f3c1a44a G |
500 | return -ENOMEM; |
501 | } | |
502 | #endif | |
085db2c0 EB |
503 | ret = nf_register_hook_list(net); |
504 | if (ret) | |
505 | remove_proc_entry("netfilter", net->proc_net); | |
506 | ||
507 | return ret; | |
f3c1a44a G |
508 | } |
509 | ||
510 | static void __net_exit netfilter_net_exit(struct net *net) | |
511 | { | |
085db2c0 | 512 | nf_unregister_hook_list(net); |
f3c1a44a G |
513 | remove_proc_entry("netfilter", net->proc_net); |
514 | } | |
515 | ||
516 | static struct pernet_operations netfilter_net_ops = { | |
517 | .init = netfilter_net_init, | |
518 | .exit = netfilter_net_exit, | |
519 | }; | |
520 | ||
6d11cfdb | 521 | int __init netfilter_init(void) |
f6ebe77f | 522 | { |
085db2c0 | 523 | int ret; |
f6ebe77f | 524 | |
6d11cfdb PNA |
525 | ret = register_pernet_subsys(&netfilter_net_ops); |
526 | if (ret < 0) | |
527 | goto err; | |
528 | ||
529 | ret = netfilter_log_init(); | |
530 | if (ret < 0) | |
531 | goto err_pernet; | |
f6ebe77f | 532 | |
6d11cfdb PNA |
533 | return 0; |
534 | err_pernet: | |
535 | unregister_pernet_subsys(&netfilter_net_ops); | |
536 | err: | |
537 | return ret; | |
f6ebe77f | 538 | } |