]> bbs.cooldavid.org Git - net-next-2.6.git/blame - net/netfilter/nf_conntrack_ecache.c
[NETFILTER]: Mark old IPv4-only connection tracking scheduled for removal
[net-next-2.6.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>
24#include <net/netfilter/nf_conntrack_l3proto.h>
605dcad6 25#include <net/netfilter/nf_conntrack_l4proto.h>
f6180121
MJ
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
30ATOMIC_NOTIFIER_HEAD(nf_conntrack_chain);
31ATOMIC_NOTIFIER_HEAD(nf_conntrack_expect_chain);
32
33DEFINE_PER_CPU(struct nf_conntrack_ecache, nf_conntrack_ecache);
34
35/* deliver cached events and clear cache entry - must be called with locally
36 * disabled softirqs */
37static inline void
38__nf_ct_deliver_cached_events(struct nf_conntrack_ecache *ecache)
39{
40 if (nf_ct_is_confirmed(ecache->ct) && !nf_ct_is_dying(ecache->ct)
41 && ecache->events)
42 atomic_notifier_call_chain(&nf_conntrack_chain, ecache->events,
43 ecache->ct);
44
45 ecache->events = 0;
46 nf_ct_put(ecache->ct);
47 ecache->ct = NULL;
48}
49
50/* Deliver all cached events for a particular conntrack. This is called
51 * by code prior to async packet handling for freeing the skb */
52void nf_ct_deliver_cached_events(const struct nf_conn *ct)
53{
54 struct nf_conntrack_ecache *ecache;
55
56 local_bh_disable();
57 ecache = &__get_cpu_var(nf_conntrack_ecache);
58 if (ecache->ct == ct)
59 __nf_ct_deliver_cached_events(ecache);
60 local_bh_enable();
61}
62
63/* Deliver cached events for old pending events, if current conntrack != old */
64void __nf_ct_event_cache_init(struct nf_conn *ct)
65{
66 struct nf_conntrack_ecache *ecache;
67
68 /* take care of delivering potentially old events */
69 ecache = &__get_cpu_var(nf_conntrack_ecache);
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}
77
78/* flush the event cache - touches other CPU's data and must not be called
79 * while packets are still passing through the code */
80void nf_ct_event_cache_flush(void)
81{
82 struct nf_conntrack_ecache *ecache;
83 int cpu;
84
85 for_each_possible_cpu(cpu) {
86 ecache = &per_cpu(nf_conntrack_ecache, cpu);
87 if (ecache->ct)
88 nf_ct_put(ecache->ct);
89 }
90}
91