x86: merge APIC_init_uniprocessor
[deliverable/linux.git] / net / netfilter / nf_conntrack_ecache.c
CommitLineData
f6180121
MJ
1/* Event cache for netfilter. */
2
3/* (C) 1999-2001 Paul `Rusty' Russell
4 * (C) 2002-2006 Netfilter Core Team <coreteam@netfilter.org>
5 * (C) 2003,2004 USAGI/WIDE Project <http://www.linux-ipv6.org>
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License version 2 as
9 * published by the Free Software Foundation.
10 */
11
12#include <linux/types.h>
13#include <linux/netfilter.h>
14#include <linux/skbuff.h>
15#include <linux/vmalloc.h>
16#include <linux/stddef.h>
17#include <linux/err.h>
18#include <linux/percpu.h>
19#include <linux/notifier.h>
20#include <linux/kernel.h>
21#include <linux/netdevice.h>
22
23#include <net/netfilter/nf_conntrack.h>
f6180121
MJ
24#include <net/netfilter/nf_conntrack_core.h>
25
26ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);
13b18339
PM
27EXPORT_SYMBOL_GPL(nf_conntrack_chain);
28
6823645d
PM
29ATOMIC_NOTIFIER_HEAD(nf_ct_expect_chain);
30EXPORT_SYMBOL_GPL(nf_ct_expect_chain);
f6180121 31
f6180121
MJ
32/* deliver cached events and clear cache entry - must be called with locally
33 * disabled softirqs */
34static inline void
35__nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
36{
37 if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct)
38 && ecache->events)
39 atomic_notifier_call_chain(&nf_conntrack_chain, ecache->events,
40 ecache->ct);
41
42 ecache->events = 0;
43 nf_ct_put(ecache->ct);
44 ecache->ct = NULL;
45}
46
47/* Deliver all cached events for a particular conntrack. This is called
48 * by code prior to async packet handling for freeing the skb */
49void nf_ct_deliver_cached_events(const struct nf_conn *ct)
50{
6058fa6b 51 struct net *net = nf_ct_net(ct);
f6180121
MJ
52 struct nf_conntrack_ecache *ecache;
53
54 local_bh_disable();
6058fa6b 55 ecache = per_cpu_ptr(net->ct.ecache, raw_smp_processor_id());
f6180121
MJ
56 if (ecache->ct == ct)
57 __nf_ct_deliver_cached_events(ecache);
58 local_bh_enable();
59}
13b18339 60EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
f6180121
MJ
61
62/* Deliver cached events for old pending events, if current conntrack != old */
63void __nf_ct_event_cache_init(struct nf_conn *ct)
64{
6058fa6b 65 struct net *net = nf_ct_net(ct);
f6180121
MJ
66 struct nf_conntrack_ecache *ecache;
67
68 /* take care of delivering potentially old events */
6058fa6b 69 ecache = per_cpu_ptr(net->ct.ecache, raw_smp_processor_id());
f6180121
MJ
70 BUG_ON(ecache->ct == ct);
71 if (ecache->ct)
72 __nf_ct_deliver_cached_events(ecache);
73 /* initialize for this conntrack/packet */
74 ecache->ct = ct;
75 nf_conntrack_get(&ct->ct_general);
76}
13b18339 77EXPORT_SYMBOL_GPL(__nf_ct_event_cache_init);
f6180121
MJ
78
79/* flush the event cache - touches other CPU's data and must not be called
80 * while packets are still passing through the code */
6058fa6b 81void nf_ct_event_cache_flush(struct net *net)
f6180121
MJ
82{
83 struct nf_conntrack_ecache *ecache;
84 int cpu;
85
86 for_each_possible_cpu(cpu) {
6058fa6b 87 ecache = per_cpu_ptr(net->ct.ecache, cpu);
f6180121
MJ
88 if (ecache->ct)
89 nf_ct_put(ecache->ct);
90 }
91}
92
6058fa6b
AD
93int nf_conntrack_ecache_init(struct net *net)
94{
95 net->ct.ecache = alloc_percpu(struct nf_conntrack_ecache);
96 if (!net->ct.ecache)
97 return -ENOMEM;
98 return 0;
99}
100
101void nf_conntrack_ecache_fini(struct net *net)
102{
103 free_percpu(net->ct.ecache);
104}
105
010c7d6f
PM
106int nf_conntrack_register_notifier(struct notifier_block *nb)
107{
108 return atomic_notifier_chain_register(&nf_conntrack_chain, nb);
109}
110EXPORT_SYMBOL_GPL(nf_conntrack_register_notifier);
111
112int nf_conntrack_unregister_notifier(struct notifier_block *nb)
113{
114 return atomic_notifier_chain_unregister(&nf_conntrack_chain, nb);
115}
116EXPORT_SYMBOL_GPL(nf_conntrack_unregister_notifier);
117
6823645d 118int nf_ct_expect_register_notifier(struct notifier_block *nb)
010c7d6f 119{
6823645d 120 return atomic_notifier_chain_register(&nf_ct_expect_chain, nb);
010c7d6f 121}
6823645d 122EXPORT_SYMBOL_GPL(nf_ct_expect_register_notifier);
010c7d6f 123
6823645d 124int nf_ct_expect_unregister_notifier(struct notifier_block *nb)
010c7d6f 125{
6823645d 126 return atomic_notifier_chain_unregister(&nf_ct_expect_chain, nb);
010c7d6f 127}
6823645d 128EXPORT_SYMBOL_GPL(nf_ct_expect_unregister_notifier);
This page took 0.294613 seconds and 5 git commands to generate.