892b8cdf7f6227dcaed056b2ab5f8d9432207e50
[safe/jmp/linux-2.6] / include / net / netfilter / nf_conntrack_ecache.h
1 /*
2  * connection tracking event cache.
3  */
4
5 #ifndef _NF_CONNTRACK_ECACHE_H
6 #define _NF_CONNTRACK_ECACHE_H
7 #include <net/netfilter/nf_conntrack.h>
8
9 #include <linux/notifier.h>
10 #include <linux/interrupt.h>
11 #include <net/net_namespace.h>
12 #include <net/netfilter/nf_conntrack_expect.h>
13
14 /* Connection tracking event bits */
15 enum ip_conntrack_events
16 {
17         /* New conntrack */
18         IPCT_NEW_BIT = 0,
19         IPCT_NEW = (1 << IPCT_NEW_BIT),
20
21         /* Expected connection */
22         IPCT_RELATED_BIT = 1,
23         IPCT_RELATED = (1 << IPCT_RELATED_BIT),
24
25         /* Destroyed conntrack */
26         IPCT_DESTROY_BIT = 2,
27         IPCT_DESTROY = (1 << IPCT_DESTROY_BIT),
28
29         /* Timer has been refreshed */
30         IPCT_REFRESH_BIT = 3,
31         IPCT_REFRESH = (1 << IPCT_REFRESH_BIT),
32
33         /* Status has changed */
34         IPCT_STATUS_BIT = 4,
35         IPCT_STATUS = (1 << IPCT_STATUS_BIT),
36
37         /* Update of protocol info */
38         IPCT_PROTOINFO_BIT = 5,
39         IPCT_PROTOINFO = (1 << IPCT_PROTOINFO_BIT),
40
41         /* Volatile protocol info */
42         IPCT_PROTOINFO_VOLATILE_BIT = 6,
43         IPCT_PROTOINFO_VOLATILE = (1 << IPCT_PROTOINFO_VOLATILE_BIT),
44
45         /* New helper for conntrack */
46         IPCT_HELPER_BIT = 7,
47         IPCT_HELPER = (1 << IPCT_HELPER_BIT),
48
49         /* Update of helper info */
50         IPCT_HELPINFO_BIT = 8,
51         IPCT_HELPINFO = (1 << IPCT_HELPINFO_BIT),
52
53         /* Volatile helper info */
54         IPCT_HELPINFO_VOLATILE_BIT = 9,
55         IPCT_HELPINFO_VOLATILE = (1 << IPCT_HELPINFO_VOLATILE_BIT),
56
57         /* NAT info */
58         IPCT_NATINFO_BIT = 10,
59         IPCT_NATINFO = (1 << IPCT_NATINFO_BIT),
60
61         /* Counter highest bit has been set, unused */
62         IPCT_COUNTER_FILLING_BIT = 11,
63         IPCT_COUNTER_FILLING = (1 << IPCT_COUNTER_FILLING_BIT),
64
65         /* Mark is set */
66         IPCT_MARK_BIT = 12,
67         IPCT_MARK = (1 << IPCT_MARK_BIT),
68
69         /* NAT sequence adjustment */
70         IPCT_NATSEQADJ_BIT = 13,
71         IPCT_NATSEQADJ = (1 << IPCT_NATSEQADJ_BIT),
72
73         /* Secmark is set */
74         IPCT_SECMARK_BIT = 14,
75         IPCT_SECMARK = (1 << IPCT_SECMARK_BIT),
76 };
77
78 enum ip_conntrack_expect_events {
79         IPEXP_NEW_BIT = 0,
80         IPEXP_NEW = (1 << IPEXP_NEW_BIT),
81 };
82
83 #ifdef CONFIG_NF_CONNTRACK_EVENTS
84 struct nf_conntrack_ecache {
85         struct nf_conn *ct;
86         unsigned int events;
87 };
88
89 /* This structure is passed to event handler */
90 struct nf_ct_event {
91         struct nf_conn *ct;
92         u32 pid;
93         int report;
94 };
95
96 extern struct atomic_notifier_head nf_conntrack_chain;
97 extern int nf_conntrack_register_notifier(struct notifier_block *nb);
98 extern int nf_conntrack_unregister_notifier(struct notifier_block *nb);
99
100 extern void nf_ct_deliver_cached_events(const struct nf_conn *ct);
101 extern void __nf_ct_event_cache_init(struct nf_conn *ct);
102 extern void nf_ct_event_cache_flush(struct net *net);
103
104 static inline void
105 nf_conntrack_event_cache(enum ip_conntrack_events event, struct nf_conn *ct)
106 {
107         struct net *net = nf_ct_net(ct);
108         struct nf_conntrack_ecache *ecache;
109
110         local_bh_disable();
111         ecache = per_cpu_ptr(net->ct.ecache, raw_smp_processor_id());
112         if (ct != ecache->ct)
113                 __nf_ct_event_cache_init(ct);
114         ecache->events |= event;
115         local_bh_enable();
116 }
117
118 static inline void
119 nf_conntrack_event_report(enum ip_conntrack_events event,
120                           struct nf_conn *ct,
121                           u32 pid,
122                           int report)
123 {
124         struct nf_ct_event item = {
125                 .ct     = ct,
126                 .pid    = pid,
127                 .report = report
128         };
129         if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
130                 atomic_notifier_call_chain(&nf_conntrack_chain, event, &item);
131 }
132
133 static inline void
134 nf_conntrack_event(enum ip_conntrack_events event, struct nf_conn *ct)
135 {
136         nf_conntrack_event_report(event, ct, 0, 0);
137 }
138
139 struct nf_exp_event {
140         struct nf_conntrack_expect *exp;
141         u32 pid;
142         int report;
143 };
144
145 extern struct atomic_notifier_head nf_ct_expect_chain;
146 extern int nf_ct_expect_register_notifier(struct notifier_block *nb);
147 extern int nf_ct_expect_unregister_notifier(struct notifier_block *nb);
148
149 static inline void
150 nf_ct_expect_event_report(enum ip_conntrack_expect_events event,
151                           struct nf_conntrack_expect *exp,
152                           u32 pid,
153                           int report)
154 {
155         struct nf_exp_event item = {
156                 .exp    = exp,
157                 .pid    = pid,
158                 .report = report
159         };
160         atomic_notifier_call_chain(&nf_ct_expect_chain, event, &item);
161 }
162
163 static inline void
164 nf_ct_expect_event(enum ip_conntrack_expect_events event,
165                    struct nf_conntrack_expect *exp)
166 {
167         nf_ct_expect_event_report(event, exp, 0, 0);
168 }
169
170 extern int nf_conntrack_ecache_init(struct net *net);
171 extern void nf_conntrack_ecache_fini(struct net *net);
172
173 #else /* CONFIG_NF_CONNTRACK_EVENTS */
174
175 static inline void nf_conntrack_event_cache(enum ip_conntrack_events event,
176                                             struct nf_conn *ct) {}
177 static inline void nf_conntrack_event(enum ip_conntrack_events event,
178                                       struct nf_conn *ct) {}
179 static inline void nf_conntrack_event_report(enum ip_conntrack_events event,
180                                              struct nf_conn *ct,
181                                              u32 pid,
182                                              int report) {}
183 static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct) {}
184 static inline void nf_ct_expect_event(enum ip_conntrack_expect_events event,
185                                       struct nf_conntrack_expect *exp) {}
186 static inline void nf_ct_expect_event_report(enum ip_conntrack_expect_events e,
187                                              struct nf_conntrack_expect *exp,
188                                              u32 pid,
189                                              int report) {}
190 static inline void nf_ct_event_cache_flush(struct net *net) {}
191
192 static inline int nf_conntrack_ecache_init(struct net *net)
193 {
194         return 0;
195 }
196
197 static inline void nf_conntrack_ecache_fini(struct net *net)
198 {
199 }
200 #endif /* CONFIG_NF_CONNTRACK_EVENTS */
201
202 #endif /*_NF_CONNTRACK_ECACHE_H*/
203