[NETFILTER]: nf_conntrack: EXPORT_SYMBOL cleanup
[safe/jmp/linux-2.6] / net / netfilter / nf_conntrack_ecache.c
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>
24 #include <net/netfilter/nf_conntrack_l3proto.h>
25 #include <net/netfilter/nf_conntrack_l4proto.h>
26 #include <net/netfilter/nf_conntrack_expect.h>
27 #include <net/netfilter/nf_conntrack_helper.h>
28 #include <net/netfilter/nf_conntrack_core.h>
29
30 ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);
31 EXPORT_SYMBOL_GPL(nf_conntrack_chain);
32
33 ATOMIC_NOTIFIER_HEAD(nf_conntrack_expect_chain);
34 EXPORT_SYMBOL_GPL(nf_conntrack_expect_chain);
35
36 DEFINE_PER_CPU(struct nf_conntrack_ecache, nf_conntrack_ecache);
37 EXPORT_PER_CPU_SYMBOL_GPL(nf_conntrack_ecache);
38
39 /* deliver cached events and clear cache entry - must be called with locally
40  * disabled softirqs */
41 static inline void
42 __nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
43 {
44         if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct)
45             && ecache->events)
46                 atomic_notifier_call_chain(&nf_conntrack_chain, ecache->events,
47                                     ecache->ct);
48
49         ecache->events = 0;
50         nf_ct_put(ecache->ct);
51         ecache->ct = NULL;
52 }
53
54 /* Deliver all cached events for a particular conntrack. This is called
55  * by code prior to async packet handling for freeing the skb */
56 void nf_ct_deliver_cached_events(const struct nf_conn *ct)
57 {
58         struct nf_conntrack_ecache *ecache;
59
60         local_bh_disable();
61         ecache = &__get_cpu_var(nf_conntrack_ecache);
62         if (ecache->ct == ct)
63                 __nf_ct_deliver_cached_events(ecache);
64         local_bh_enable();
65 }
66 EXPORT_SYMBOL_GPL(nf_ct_deliver_cached_events);
67
68 /* Deliver cached events for old pending events, if current conntrack != old */
69 void __nf_ct_event_cache_init(struct nf_conn *ct)
70 {
71         struct nf_conntrack_ecache *ecache;
72
73         /* take care of delivering potentially old events */
74         ecache = &__get_cpu_var(nf_conntrack_ecache);
75         BUG_ON(ecache->ct == ct);
76         if (ecache->ct)
77                 __nf_ct_deliver_cached_events(ecache);
78         /* initialize for this conntrack/packet */
79         ecache->ct = ct;
80         nf_conntrack_get(&ct->ct_general);
81 }
82 EXPORT_SYMBOL_GPL(__nf_ct_event_cache_init);
83
84 /* flush the event cache - touches other CPU's data and must not be called
85  * while packets are still passing through the code */
86 void nf_ct_event_cache_flush(void)
87 {
88         struct nf_conntrack_ecache *ecache;
89         int cpu;
90
91         for_each_possible_cpu(cpu) {
92                 ecache = &per_cpu(nf_conntrack_ecache, cpu);
93                 if (ecache->ct)
94                         nf_ct_put(ecache->ct);
95         }
96 }
97