1 #ifndef _IP_CONNTRACK_H
2 #define _IP_CONNTRACK_H
3 /* Connection state tracking for netfilter. This is separated from,
4 but required by, the NAT layer; it can also be used by an iptables
7 #include <linux/config.h>
8 #include <linux/netfilter_ipv4/ip_conntrack_tuple.h>
9 #include <linux/bitops.h>
10 #include <linux/compiler.h>
11 #include <linux/vserver/context.h>
12 #include <asm/atomic.h>
14 enum ip_conntrack_info
16 /* Part of an established connection (either direction). */
19 /* Like NEW, but related to an existing connection, or ICMP error
20 (in either direction). */
23 /* Started a new connection to track (only
24 IP_CT_DIR_ORIGINAL); may be a retransmission. */
27 /* >= this indicates reply direction */
30 /* Number of distinct IP_CT types (no NEW in reply dirn). */
31 IP_CT_NUMBER = IP_CT_IS_REPLY * 2 - 1
34 /* Bitset representing status of connection. */
35 enum ip_conntrack_status {
36 /* It's an expected connection: bit 0 set. This bit never changed */
38 IPS_EXPECTED = (1 << IPS_EXPECTED_BIT),
40 /* We've seen packets both ways: bit 1 set. Can be set, not unset. */
41 IPS_SEEN_REPLY_BIT = 1,
42 IPS_SEEN_REPLY = (1 << IPS_SEEN_REPLY_BIT),
44 /* Conntrack should never be early-expired. */
46 IPS_ASSURED = (1 << IPS_ASSURED_BIT),
48 /* Connection is confirmed: originating packet has left box */
49 IPS_CONFIRMED_BIT = 3,
50 IPS_CONFIRMED = (1 << IPS_CONFIRMED_BIT),
53 #include <linux/netfilter_ipv4/ip_conntrack_tcp.h>
54 #include <linux/netfilter_ipv4/ip_conntrack_icmp.h>
55 #include <linux/netfilter_ipv4/ip_conntrack_proto_gre.h>
57 /* per conntrack: protocol private data */
58 union ip_conntrack_proto {
59 /* insert conntrack proto private data here */
62 struct ip_ct_icmp icmp;
65 union ip_conntrack_expect_proto {
66 /* insert expect proto private data here */
67 struct ip_ct_gre_expect gre;
70 /* Add protocol helper include file here */
71 #include <linux/netfilter_ipv4/ip_conntrack_pptp.h>
72 #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
73 #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
74 #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
76 /* per expectation: application helper private data */
77 union ip_conntrack_expect_help {
78 /* insert conntrack helper private data (expect) here */
79 struct ip_ct_pptp_expect exp_pptp_info;
80 struct ip_ct_amanda_expect exp_amanda_info;
81 struct ip_ct_ftp_expect exp_ftp_info;
82 struct ip_ct_irc_expect exp_irc_info;
84 #ifdef CONFIG_IP_NF_NAT_NEEDED
86 /* insert nat helper private data (expect) here */
91 /* per conntrack: application helper private data */
92 union ip_conntrack_help {
93 /* insert conntrack helper private data (master) here */
94 struct ip_ct_pptp_master ct_pptp_info;
95 struct ip_ct_ftp_master ct_ftp_info;
96 struct ip_ct_irc_master ct_irc_info;
99 #ifdef CONFIG_IP_NF_NAT_NEEDED
100 #include <linux/netfilter_ipv4/ip_nat.h>
101 #include <linux/netfilter_ipv4/ip_nat_pptp.h>
103 /* per conntrack: nat application helper private data */
104 union ip_conntrack_nat_help {
105 /* insert nat helper private data here */
106 struct ip_nat_pptp nat_pptp_info;
112 #include <linux/types.h>
113 #include <linux/skbuff.h>
115 #ifdef CONFIG_NETFILTER_DEBUG
116 #define IP_NF_ASSERT(x) \
119 /* Wooah! I'm tripping my conntrack in a frenzy of \
121 printk("NF_IP_ASSERT: %s:%i(%s)\n", \
122 __FILE__, __LINE__, __FUNCTION__); \
125 #define IP_NF_ASSERT(x)
128 struct ip_conntrack_expect
130 /* Internal linked list (global expectation list) */
131 struct list_head list;
133 /* reference count */
136 /* expectation list for this master */
137 struct list_head expected_list;
139 /* The conntrack of the master connection */
140 struct ip_conntrack *expectant;
142 /* The conntrack of the sibling connection, set after
143 * expectation arrived */
144 struct ip_conntrack *sibling;
146 /* Tuple saved for conntrack */
147 struct ip_conntrack_tuple ct_tuple;
149 /* Timer function; deletes the expectation. */
150 struct timer_list timeout;
152 /* Data filled out by the conntrack helpers follow: */
154 /* We expect this tuple, with the following mask */
155 struct ip_conntrack_tuple tuple, mask;
157 /* Function to call after setup and insertion */
158 int (*expectfn)(struct ip_conntrack *new);
160 /* At which sequence number did this expectation occur */
163 union ip_conntrack_expect_proto proto;
165 union ip_conntrack_expect_help help;
168 struct ip_conntrack_counter
174 struct ip_conntrack_helper;
178 /* Usage count in here is 1 for hash table/destruct timer, 1 per skb,
179 plus 1 for any connection(s) we are `master' for */
180 struct nf_conntrack ct_general;
182 /* These are my tuples; original and reply */
183 struct ip_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];
185 /* Have we seen traffic both ways yet? (bitset) */
186 unsigned long status;
188 /* Timer function; drops refcnt when it goes off. */
189 struct timer_list timeout;
191 #ifdef CONFIG_IP_NF_CT_ACCT
192 /* Accounting Information (same cache line as other written members) */
193 struct ip_conntrack_counter counters[IP_CT_DIR_MAX];
196 /* If we're expecting another related connection, this will be
197 in expected linked list */
198 struct list_head sibling_list;
200 /* Current number of expected connections */
201 unsigned int expecting;
203 /* If we were expected by an expectation, this will be it */
204 struct ip_conntrack_expect *master;
206 /* Helper, if any. */
207 struct ip_conntrack_helper *helper;
209 /* Our various nf_ct_info structs specify *what* relation this
210 packet has to the conntrack */
211 struct nf_ct_info infos[IP_CT_NUMBER];
213 /* Storage reserved for other modules: */
215 union ip_conntrack_proto proto;
217 union ip_conntrack_help help;
219 #ifdef CONFIG_IP_NF_NAT_NEEDED
221 struct ip_nat_info info;
222 union ip_conntrack_nat_help help;
223 #if defined(CONFIG_IP_NF_TARGET_MASQUERADE) || \
224 defined(CONFIG_IP_NF_TARGET_MASQUERADE_MODULE)
228 #endif /* CONFIG_IP_NF_NAT_NEEDED */
230 /* VServer context id */
231 xid_t xid[IP_CT_DIR_MAX];
235 /* get master conntrack via master expectation */
236 #define master_ct(conntr) (conntr->master ? conntr->master->expectant : NULL)
238 /* Alter reply tuple (maybe alter helper). If it's already taken,
239 return 0 and don't do alteration. */
241 ip_conntrack_alter_reply(struct ip_conntrack *conntrack,
242 const struct ip_conntrack_tuple *newreply);
244 /* Is this tuple taken? (ignoring any belonging to the given
247 ip_conntrack_tuple_taken(const struct ip_conntrack_tuple *tuple,
248 const struct ip_conntrack *ignored_conntrack);
250 /* Return conntrack_info and tuple hash for given skb. */
251 extern struct ip_conntrack *
252 ip_conntrack_get(struct sk_buff *skb, enum ip_conntrack_info *ctinfo);
254 /* decrement reference count on a conntrack */
255 extern inline void ip_conntrack_put(struct ip_conntrack *ct);
257 /* find unconfirmed expectation based on tuple */
258 struct ip_conntrack_expect *
259 ip_conntrack_expect_find_get(const struct ip_conntrack_tuple *tuple);
261 /* decrement reference count on an expectation */
262 void ip_conntrack_expect_put(struct ip_conntrack_expect *exp);
264 /* call to create an explicit dependency on ip_conntrack. */
265 extern void need_ip_conntrack(void);
267 extern int invert_tuplepr(struct ip_conntrack_tuple *inverse,
268 const struct ip_conntrack_tuple *orig);
270 /* Refresh conntrack for this many jiffies */
271 extern void ip_ct_refresh_acct(struct ip_conntrack *ct,
272 enum ip_conntrack_info ctinfo,
273 const struct sk_buff *skb,
274 unsigned long extra_jiffies);
276 /* These are for NAT. Icky. */
277 /* Call me when a conntrack is destroyed. */
278 extern void (*ip_conntrack_destroyed)(struct ip_conntrack *conntrack);
280 /* Fake conntrack entry for untracked connections */
281 extern struct ip_conntrack ip_conntrack_untracked;
283 /* Returns new sk_buff, or NULL */
285 ip_ct_gather_frags(struct sk_buff *skb);
287 /* Delete all conntracks which match. */
289 ip_ct_selective_cleanup(int (*kill)(const struct ip_conntrack *i, void *data),
292 /* It's confirmed if it is, or has been in the hash table. */
293 static inline int is_confirmed(struct ip_conntrack *ct)
295 return test_bit(IPS_CONFIRMED_BIT, &ct->status);
298 extern unsigned int ip_conntrack_htable_size;
300 /* eg. PROVIDES_CONNTRACK(ftp); */
301 #define PROVIDES_CONNTRACK(name) \
302 int needs_ip_conntrack_##name; \
303 EXPORT_SYMBOL(needs_ip_conntrack_##name)
305 /*. eg. NEEDS_CONNTRACK(ftp); */
306 #define NEEDS_CONNTRACK(name) \
307 extern int needs_ip_conntrack_##name; \
308 static int *need_ip_conntrack_##name __attribute_used__ = &needs_ip_conntrack_##name
310 #endif /* __KERNEL__ */
311 #endif /* _IP_CONNTRACK_H */