netfilter: ctnetlink: rename tuple() by nf_ct_tuple() macro definition
[deliverable/linux.git] / include / net / netfilter / nf_conntrack.h
CommitLineData
9fb9cbb1
YK
1/*
2 * Connection state tracking for netfilter. This is separated from,
3 * but required by, the (future) NAT layer; it can also be used by an iptables
4 * extension.
5 *
6 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
7 * - generalize L3 protocol dependent part.
8 *
9 * Derived from include/linux/netfiter_ipv4/ip_conntrack.h
10 */
11
12#ifndef _NF_CONNTRACK_H
13#define _NF_CONNTRACK_H
14
15#include <linux/netfilter/nf_conntrack_common.h>
16
17#ifdef __KERNEL__
9fb9cbb1
YK
18#include <linux/bitops.h>
19#include <linux/compiler.h>
20#include <asm/atomic.h>
21
22#include <linux/netfilter/nf_conntrack_tcp.h>
2bc78049 23#include <linux/netfilter/nf_conntrack_dccp.h>
9fb9cbb1 24#include <linux/netfilter/nf_conntrack_sctp.h>
f09943fe 25#include <linux/netfilter/nf_conntrack_proto_gre.h>
9fb9cbb1
YK
26#include <net/netfilter/ipv4/nf_conntrack_icmp.h>
27#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
28
29#include <net/netfilter/nf_conntrack_tuple.h>
30
31/* per conntrack: protocol private data */
32union nf_conntrack_proto {
33 /* insert conntrack proto private data here */
2bc78049 34 struct nf_ct_dccp dccp;
9fb9cbb1
YK
35 struct ip_ct_sctp sctp;
36 struct ip_ct_tcp tcp;
37 struct ip_ct_icmp icmp;
38 struct nf_ct_icmpv6 icmpv6;
f09943fe 39 struct nf_ct_gre gre;
9fb9cbb1
YK
40};
41
42union nf_conntrack_expect_proto {
43 /* insert expect proto private data here */
44};
45
46/* Add protocol helper include file here */
47#include <linux/netfilter/nf_conntrack_ftp.h>
f09943fe 48#include <linux/netfilter/nf_conntrack_pptp.h>
f587de0e 49#include <linux/netfilter/nf_conntrack_h323.h>
6fecd198 50#include <linux/netfilter/nf_conntrack_sane.h>
0f32a40f 51#include <linux/netfilter/nf_conntrack_sip.h>
9fb9cbb1
YK
52
53/* per conntrack: application helper private data */
54union nf_conntrack_help {
55 /* insert conntrack helper private data (master) here */
55a73324 56 struct nf_ct_ftp_master ct_ftp_info;
f09943fe 57 struct nf_ct_pptp_master ct_pptp_info;
f587de0e 58 struct nf_ct_h323_master ct_h323_info;
6fecd198 59 struct nf_ct_sane_master ct_sane_info;
0f32a40f 60 struct nf_ct_sip_master ct_sip_info;
9fb9cbb1
YK
61};
62
63#include <linux/types.h>
64#include <linux/skbuff.h>
d7fe0f24 65#include <linux/timer.h>
9fb9cbb1
YK
66
67#ifdef CONFIG_NETFILTER_DEBUG
55871d04 68#define NF_CT_ASSERT(x) WARN_ON(!(x))
9fb9cbb1
YK
69#else
70#define NF_CT_ASSERT(x)
71#endif
72
73struct nf_conntrack_helper;
74
6002f266 75/* Must be kept in sync with the classes defined by helpers */
0d0ab037 76#define NF_CT_MAX_EXPECT_CLASSES 3
6002f266 77
dc808fe2
HW
78/* nf_conn feature for connections that have a helper */
79struct nf_conn_help {
80 /* Helper. if any */
81 struct nf_conntrack_helper *helper;
82
83 union nf_conntrack_help help;
84
b560580a
PM
85 struct hlist_head expectations;
86
dc808fe2 87 /* Current number of expected connections */
6002f266 88 u8 expecting[NF_CT_MAX_EXPECT_CLASSES];
dc808fe2
HW
89};
90
9fb9cbb1 91#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
f8eb24a8
PM
92#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
93
ea781f19 94struct nf_conn {
9fb9cbb1
YK
95 /* Usage count in here is 1 for hash table/destruct timer, 1 per skb,
96 plus 1 for any connection(s) we are `master' for */
97 struct nf_conntrack ct_general;
98
99 /* XXX should I move this to the tail ? - Y.K */
100 /* These are my tuples; original and reply */
101 struct nf_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];
102
103 /* Have we seen traffic both ways yet? (bitset) */
104 unsigned long status;
105
dc808fe2
HW
106 /* If we were expected by an expectation, this will be it */
107 struct nf_conn *master;
108
9fb9cbb1
YK
109 /* Timer function; drops refcnt when it goes off. */
110 struct timer_list timeout;
111
9fb9cbb1
YK
112#if defined(CONFIG_NF_CONNTRACK_MARK)
113 u_int32_t mark;
114#endif
115
7c9728c3
JM
116#ifdef CONFIG_NF_CONNTRACK_SECMARK
117 u_int32_t secmark;
118#endif
119
dc808fe2
HW
120 /* Storage reserved for other modules: */
121 union nf_conntrack_proto proto;
9fb9cbb1 122
ecfab2c9
YK
123 /* Extensions */
124 struct nf_ct_ext *ext;
5a1fb391
AD
125#ifdef CONFIG_NET_NS
126 struct net *ct_net;
127#endif
9fb9cbb1
YK
128};
129
9fb9cbb1
YK
130static inline struct nf_conn *
131nf_ct_tuplehash_to_ctrack(const struct nf_conntrack_tuple_hash *hash)
132{
133 return container_of(hash, struct nf_conn,
134 tuplehash[hash->tuple.dst.dir]);
135}
136
5e8fbe2a
PM
137static inline u_int16_t nf_ct_l3num(const struct nf_conn *ct)
138{
139 return ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.src.l3num;
140}
141
142static inline u_int8_t nf_ct_protonum(const struct nf_conn *ct)
143{
144 return ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
145}
146
f2f3e38c
PNA
147#define nf_ct_tuple(ct, dir) (&(ct)->tuplehash[dir].tuple)
148
9fb9cbb1
YK
149/* get master conntrack via master expectation */
150#define master_ct(conntr) (conntr->master)
151
5a1fb391
AD
152extern struct net init_net;
153
154static inline struct net *nf_ct_net(const struct nf_conn *ct)
155{
156#ifdef CONFIG_NET_NS
157 return ct->ct_net;
158#else
159 return &init_net;
160#endif
161}
162
9fb9cbb1
YK
163/* Alter reply tuple (maybe alter helper). */
164extern void
c88130bc 165nf_conntrack_alter_reply(struct nf_conn *ct,
9fb9cbb1
YK
166 const struct nf_conntrack_tuple *newreply);
167
168/* Is this tuple taken? (ignoring any belonging to the given
169 conntrack). */
170extern int
171nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
172 const struct nf_conn *ignored_conntrack);
173
174/* Return conntrack_info and tuple hash for given skb. */
175static inline struct nf_conn *
176nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo)
177{
178 *ctinfo = skb->nfctinfo;
179 return (struct nf_conn *)skb->nfct;
180}
181
182/* decrement reference count on a conntrack */
183static inline void nf_ct_put(struct nf_conn *ct)
184{
185 NF_CT_ASSERT(ct);
186 nf_conntrack_put(&ct->ct_general);
187}
188
b9f78f9f
PNA
189/* Protocol module loading */
190extern int nf_ct_l3proto_try_module_get(unsigned short l3proto);
191extern void nf_ct_l3proto_module_put(unsigned short l3proto);
192
ea781f19
ED
193/*
194 * Allocate a hashtable of hlist_head (if nulls == 0),
195 * or hlist_nulls_head (if nulls == 1)
196 */
197extern void *nf_ct_alloc_hashtable(unsigned int *sizep, int *vmalloced, int nulls);
198
199extern void nf_ct_free_hashtable(void *hash, int vmalloced, unsigned int size);
ac565e5f 200
c1d10adb 201extern struct nf_conntrack_tuple_hash *
400dad39 202__nf_conntrack_find(struct net *net, const struct nf_conntrack_tuple *tuple);
c1d10adb
PNA
203
204extern void nf_conntrack_hash_insert(struct nf_conn *ct);
205
19abb7b0 206extern void nf_conntrack_flush(struct net *net, u32 pid, int report);
c1d10adb 207
5f2b4c90
JE
208extern bool nf_ct_get_tuplepr(const struct sk_buff *skb,
209 unsigned int nhoff, u_int16_t l3num,
210 struct nf_conntrack_tuple *tuple);
211extern bool nf_ct_invert_tuplepr(struct nf_conntrack_tuple *inverse,
212 const struct nf_conntrack_tuple *orig);
9fb9cbb1
YK
213
214extern void __nf_ct_refresh_acct(struct nf_conn *ct,
215 enum ip_conntrack_info ctinfo,
216 const struct sk_buff *skb,
217 unsigned long extra_jiffies,
218 int do_acct);
219
220/* Refresh conntrack for this many jiffies and do accounting */
221static inline void nf_ct_refresh_acct(struct nf_conn *ct,
222 enum ip_conntrack_info ctinfo,
223 const struct sk_buff *skb,
224 unsigned long extra_jiffies)
225{
226 __nf_ct_refresh_acct(ct, ctinfo, skb, extra_jiffies, 1);
227}
228
229/* Refresh conntrack for this many jiffies */
230static inline void nf_ct_refresh(struct nf_conn *ct,
231 const struct sk_buff *skb,
232 unsigned long extra_jiffies)
233{
234 __nf_ct_refresh_acct(ct, 0, skb, extra_jiffies, 0);
235}
236
4c889498
DM
237extern bool __nf_ct_kill_acct(struct nf_conn *ct,
238 enum ip_conntrack_info ctinfo,
239 const struct sk_buff *skb,
240 int do_acct);
718d4ad9
FH
241
242/* kill conntrack and do accounting */
4c889498
DM
243static inline bool nf_ct_kill_acct(struct nf_conn *ct,
244 enum ip_conntrack_info ctinfo,
245 const struct sk_buff *skb)
718d4ad9 246{
4c889498 247 return __nf_ct_kill_acct(ct, ctinfo, skb, 1);
718d4ad9
FH
248}
249
250/* kill conntrack without accounting */
4c889498 251static inline bool nf_ct_kill(struct nf_conn *ct)
718d4ad9 252{
4c889498 253 return __nf_ct_kill_acct(ct, 0, NULL, 0);
718d4ad9 254}
51091764 255
9fb9cbb1
YK
256/* These are for NAT. Icky. */
257/* Update TCP window tracking data when NAT mangles the packet */
82f568fc 258extern void nf_conntrack_tcp_update(const struct sk_buff *skb,
9fb9cbb1 259 unsigned int dataoff,
c88130bc 260 struct nf_conn *ct,
9fb9cbb1
YK
261 int dir);
262
9fb9cbb1
YK
263/* Fake conntrack entry for untracked connections */
264extern struct nf_conn nf_conntrack_untracked;
265
9fb9cbb1
YK
266/* Iterate over all conntracks: if iter returns true, it's deleted. */
267extern void
400dad39 268nf_ct_iterate_cleanup(struct net *net, int (*iter)(struct nf_conn *i, void *data), void *data);
9fb9cbb1
YK
269extern void nf_conntrack_free(struct nf_conn *ct);
270extern struct nf_conn *
5a1fb391
AD
271nf_conntrack_alloc(struct net *net,
272 const struct nf_conntrack_tuple *orig,
b891c5a8
PNA
273 const struct nf_conntrack_tuple *repl,
274 gfp_t gfp);
9fb9cbb1
YK
275
276/* It's confirmed if it is, or has been in the hash table. */
277static inline int nf_ct_is_confirmed(struct nf_conn *ct)
278{
279 return test_bit(IPS_CONFIRMED_BIT, &ct->status);
280}
281
282static inline int nf_ct_is_dying(struct nf_conn *ct)
283{
284 return test_bit(IPS_DYING_BIT, &ct->status);
285}
286
587aa641
PM
287static inline int nf_ct_is_untracked(const struct sk_buff *skb)
288{
289 return (skb->nfct == &nf_conntrack_untracked.ct_general);
290}
291
fae718dd 292extern int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp);
9fb9cbb1 293extern unsigned int nf_conntrack_htable_size;
e478075c 294extern unsigned int nf_conntrack_max;
9fb9cbb1 295
0d55af87
AD
296#define NF_CT_STAT_INC(net, count) \
297 (per_cpu_ptr((net)->ct.stat, raw_smp_processor_id())->count++)
298#define NF_CT_STAT_INC_ATOMIC(net, count) \
c0e912d7
PM
299do { \
300 local_bh_disable(); \
0d55af87 301 per_cpu_ptr((net)->ct.stat, raw_smp_processor_id())->count++; \
c0e912d7
PM
302 local_bh_enable(); \
303} while (0)
9fb9cbb1 304
4dc06f96
PNA
305#define MODULE_ALIAS_NFCT_HELPER(helper) \
306 MODULE_ALIAS("nfct-helper-" helper)
307
9fb9cbb1
YK
308#endif /* __KERNEL__ */
309#endif /* _NF_CONNTRACK_H */
This page took 0.65569 seconds and 5 git commands to generate.