]> git.proxmox.com Git - mirror_ubuntu-artful-kernel.git/blame - include/net/netfilter/nf_conntrack.h
[PATCH] severing skbuff.h -> poll.h
[mirror_ubuntu-artful-kernel.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>
23#include <linux/netfilter/nf_conntrack_sctp.h>
f09943fe 24#include <linux/netfilter/nf_conntrack_proto_gre.h>
9fb9cbb1
YK
25#include <net/netfilter/ipv4/nf_conntrack_icmp.h>
26#include <net/netfilter/ipv6/nf_conntrack_icmpv6.h>
27
28#include <net/netfilter/nf_conntrack_tuple.h>
29
30/* per conntrack: protocol private data */
31union nf_conntrack_proto {
32 /* insert conntrack proto private data here */
33 struct ip_ct_sctp sctp;
34 struct ip_ct_tcp tcp;
35 struct ip_ct_icmp icmp;
36 struct nf_ct_icmpv6 icmpv6;
f09943fe 37 struct nf_ct_gre gre;
9fb9cbb1
YK
38};
39
40union nf_conntrack_expect_proto {
41 /* insert expect proto private data here */
42};
43
44/* Add protocol helper include file here */
45#include <linux/netfilter/nf_conntrack_ftp.h>
f09943fe 46#include <linux/netfilter/nf_conntrack_pptp.h>
f587de0e 47#include <linux/netfilter/nf_conntrack_h323.h>
9fb9cbb1
YK
48
49/* per conntrack: application helper private data */
50union nf_conntrack_help {
51 /* insert conntrack helper private data (master) here */
55a73324 52 struct nf_ct_ftp_master ct_ftp_info;
f09943fe 53 struct nf_ct_pptp_master ct_pptp_info;
f587de0e 54 struct nf_ct_h323_master ct_h323_info;
9fb9cbb1
YK
55};
56
57#include <linux/types.h>
58#include <linux/skbuff.h>
59
60#ifdef CONFIG_NETFILTER_DEBUG
61#define NF_CT_ASSERT(x) \
62do { \
63 if (!(x)) \
64 /* Wooah! I'm tripping my conntrack in a frenzy of \
65 netplay... */ \
66 printk("NF_CT_ASSERT: %s:%i(%s)\n", \
67 __FILE__, __LINE__, __FUNCTION__); \
68} while(0)
69#else
70#define NF_CT_ASSERT(x)
71#endif
72
73struct nf_conntrack_helper;
74
dc808fe2
HW
75/* nf_conn feature for connections that have a helper */
76struct nf_conn_help {
77 /* Helper. if any */
78 struct nf_conntrack_helper *helper;
79
80 union nf_conntrack_help help;
81
82 /* Current number of expected connections */
83 unsigned int expecting;
84};
85
86
9fb9cbb1 87#include <net/netfilter/ipv4/nf_conntrack_ipv4.h>
f8eb24a8
PM
88#include <net/netfilter/ipv6/nf_conntrack_ipv6.h>
89
9fb9cbb1
YK
90struct nf_conn
91{
92 /* Usage count in here is 1 for hash table/destruct timer, 1 per skb,
93 plus 1 for any connection(s) we are `master' for */
94 struct nf_conntrack ct_general;
95
96 /* XXX should I move this to the tail ? - Y.K */
97 /* These are my tuples; original and reply */
98 struct nf_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];
99
100 /* Have we seen traffic both ways yet? (bitset) */
101 unsigned long status;
102
dc808fe2
HW
103 /* If we were expected by an expectation, this will be it */
104 struct nf_conn *master;
105
9fb9cbb1
YK
106 /* Timer function; drops refcnt when it goes off. */
107 struct timer_list timeout;
108
109#ifdef CONFIG_NF_CT_ACCT
110 /* Accounting Information (same cache line as other written members) */
111 struct ip_conntrack_counter counters[IP_CT_DIR_MAX];
112#endif
9fb9cbb1 113
c1d10adb
PNA
114 /* Unique ID that identifies this conntrack*/
115 unsigned int id;
116
9fb9cbb1
YK
117 /* features - nat, helper, ... used by allocating system */
118 u_int32_t features;
119
9fb9cbb1
YK
120#if defined(CONFIG_NF_CONNTRACK_MARK)
121 u_int32_t mark;
122#endif
123
7c9728c3
JM
124#ifdef CONFIG_NF_CONNTRACK_SECMARK
125 u_int32_t secmark;
126#endif
127
dc808fe2
HW
128 /* Storage reserved for other modules: */
129 union nf_conntrack_proto proto;
9fb9cbb1 130
dc808fe2
HW
131 /* features dynamically at the end: helper, nat (both optional) */
132 char data[0];
9fb9cbb1
YK
133};
134
9fb9cbb1
YK
135static inline struct nf_conn *
136nf_ct_tuplehash_to_ctrack(const struct nf_conntrack_tuple_hash *hash)
137{
138 return container_of(hash, struct nf_conn,
139 tuplehash[hash->tuple.dst.dir]);
140}
141
142/* get master conntrack via master expectation */
143#define master_ct(conntr) (conntr->master)
144
145/* Alter reply tuple (maybe alter helper). */
146extern void
147nf_conntrack_alter_reply(struct nf_conn *conntrack,
148 const struct nf_conntrack_tuple *newreply);
149
150/* Is this tuple taken? (ignoring any belonging to the given
151 conntrack). */
152extern int
153nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple,
154 const struct nf_conn *ignored_conntrack);
155
156/* Return conntrack_info and tuple hash for given skb. */
157static inline struct nf_conn *
158nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo)
159{
160 *ctinfo = skb->nfctinfo;
161 return (struct nf_conn *)skb->nfct;
162}
163
164/* decrement reference count on a conntrack */
165static inline void nf_ct_put(struct nf_conn *ct)
166{
167 NF_CT_ASSERT(ct);
168 nf_conntrack_put(&ct->ct_general);
169}
170
b9f78f9f
PNA
171/* Protocol module loading */
172extern int nf_ct_l3proto_try_module_get(unsigned short l3proto);
173extern void nf_ct_l3proto_module_put(unsigned short l3proto);
174
c1d10adb
PNA
175extern struct nf_conntrack_tuple_hash *
176__nf_conntrack_find(const struct nf_conntrack_tuple *tuple,
177 const struct nf_conn *ignored_conntrack);
178
179extern void nf_conntrack_hash_insert(struct nf_conn *ct);
180
c1d10adb
PNA
181extern void nf_conntrack_flush(void);
182
183extern struct nf_conntrack_helper *
184nf_ct_helper_find_get( const struct nf_conntrack_tuple *tuple);
185extern void nf_ct_helper_put(struct nf_conntrack_helper *helper);
186
187extern struct nf_conntrack_helper *
188__nf_conntrack_helper_find_byname(const char *name);
189
9fb9cbb1
YK
190extern int nf_ct_invert_tuplepr(struct nf_conntrack_tuple *inverse,
191 const struct nf_conntrack_tuple *orig);
192
193extern void __nf_ct_refresh_acct(struct nf_conn *ct,
194 enum ip_conntrack_info ctinfo,
195 const struct sk_buff *skb,
196 unsigned long extra_jiffies,
197 int do_acct);
198
199/* Refresh conntrack for this many jiffies and do accounting */
200static inline void nf_ct_refresh_acct(struct nf_conn *ct,
201 enum ip_conntrack_info ctinfo,
202 const struct sk_buff *skb,
203 unsigned long extra_jiffies)
204{
205 __nf_ct_refresh_acct(ct, ctinfo, skb, extra_jiffies, 1);
206}
207
208/* Refresh conntrack for this many jiffies */
209static inline void nf_ct_refresh(struct nf_conn *ct,
210 const struct sk_buff *skb,
211 unsigned long extra_jiffies)
212{
213 __nf_ct_refresh_acct(ct, 0, skb, extra_jiffies, 0);
214}
215
216/* These are for NAT. Icky. */
217/* Update TCP window tracking data when NAT mangles the packet */
218extern void nf_conntrack_tcp_update(struct sk_buff *skb,
219 unsigned int dataoff,
220 struct nf_conn *conntrack,
221 int dir);
222
223/* Call me when a conntrack is destroyed. */
224extern void (*nf_conntrack_destroyed)(struct nf_conn *conntrack);
225
226/* Fake conntrack entry for untracked connections */
227extern struct nf_conn nf_conntrack_untracked;
228
229extern int nf_ct_no_defrag;
230
231/* Iterate over all conntracks: if iter returns true, it's deleted. */
232extern void
233nf_ct_iterate_cleanup(int (*iter)(struct nf_conn *i, void *data), void *data);
234extern void nf_conntrack_free(struct nf_conn *ct);
235extern struct nf_conn *
236nf_conntrack_alloc(const struct nf_conntrack_tuple *orig,
237 const struct nf_conntrack_tuple *repl);
238
239/* It's confirmed if it is, or has been in the hash table. */
240static inline int nf_ct_is_confirmed(struct nf_conn *ct)
241{
242 return test_bit(IPS_CONFIRMED_BIT, &ct->status);
243}
244
245static inline int nf_ct_is_dying(struct nf_conn *ct)
246{
247 return test_bit(IPS_DYING_BIT, &ct->status);
248}
249
250extern unsigned int nf_conntrack_htable_size;
39a27a35 251extern int nf_conntrack_checksum;
f8eb24a8
PM
252extern atomic_t nf_conntrack_count;
253extern int nf_conntrack_max;
9fb9cbb1 254
f8eb24a8 255DECLARE_PER_CPU(struct ip_conntrack_stat, nf_conntrack_stat);
9fb9cbb1
YK
256#define NF_CT_STAT_INC(count) (__get_cpu_var(nf_conntrack_stat).count++)
257
9fb9cbb1
YK
258/* no helper, no nat */
259#define NF_CT_F_BASIC 0
260/* for helper */
261#define NF_CT_F_HELP 1
262/* for nat. */
263#define NF_CT_F_NAT 2
264#define NF_CT_F_NUM 4
265
266extern int
dc808fe2 267nf_conntrack_register_cache(u_int32_t features, const char *name, size_t size);
9fb9cbb1
YK
268extern void
269nf_conntrack_unregister_cache(u_int32_t features);
270
dc808fe2
HW
271/* valid combinations:
272 * basic: nf_conn, nf_conn .. nf_conn_help
5b1158e9 273 * nat: nf_conn .. nf_conn_nat, nf_conn .. nf_conn_nat .. nf_conn help
dc808fe2 274 */
5b1158e9
JK
275#ifdef CONFIG_NF_NAT_NEEDED
276static inline struct nf_conn_nat *nfct_nat(const struct nf_conn *ct)
277{
278 unsigned int offset = sizeof(struct nf_conn);
279
280 if (!(ct->features & NF_CT_F_NAT))
281 return NULL;
282
283 offset = ALIGN(offset, __alignof__(struct nf_conn_nat));
284 return (struct nf_conn_nat *) ((void *)ct + offset);
285}
286
dc808fe2
HW
287static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
288{
289 unsigned int offset = sizeof(struct nf_conn);
290
291 if (!(ct->features & NF_CT_F_HELP))
292 return NULL;
5b1158e9
JK
293 if (ct->features & NF_CT_F_NAT) {
294 offset = ALIGN(offset, __alignof__(struct nf_conn_nat));
295 offset += sizeof(struct nf_conn_nat);
296 }
dc808fe2 297
f9aae958 298 offset = ALIGN(offset, __alignof__(struct nf_conn_help));
dc808fe2
HW
299 return (struct nf_conn_help *) ((void *)ct + offset);
300}
5b1158e9
JK
301#else /* No NAT */
302static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
303{
304 unsigned int offset = sizeof(struct nf_conn);
305
306 if (!(ct->features & NF_CT_F_HELP))
307 return NULL;
dc808fe2 308
5b1158e9
JK
309 offset = ALIGN(offset, __alignof__(struct nf_conn_help));
310 return (struct nf_conn_help *) ((void *)ct + offset);
311}
312#endif /* CONFIG_NF_NAT_NEEDED */
9fb9cbb1
YK
313#endif /* __KERNEL__ */
314#endif /* _NF_CONNTRACK_H */