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>
56 /* per conntrack: protocol private data */
57 union ip_conntrack_proto {
58 /* insert conntrack proto private data here */
60 struct ip_ct_icmp icmp;
63 union ip_conntrack_expect_proto {
64 /* insert expect proto private data here */
67 /* Add protocol helper include file here */
68 #include <linux/netfilter_ipv4/ip_conntrack_amanda.h>
69 #include <linux/netfilter_ipv4/ip_conntrack_ftp.h>
70 #include <linux/netfilter_ipv4/ip_conntrack_irc.h>
72 /* per expectation: application helper private data */
73 union ip_conntrack_expect_help {
74 /* insert conntrack helper private data (expect) here */
75 struct ip_ct_amanda_expect exp_amanda_info;
76 struct ip_ct_ftp_expect exp_ftp_info;
77 struct ip_ct_irc_expect exp_irc_info;
79 #ifdef CONFIG_IP_NF_NAT_NEEDED
81 /* insert nat helper private data (expect) here */
86 /* per conntrack: application helper private data */
87 union ip_conntrack_help {
88 /* insert conntrack helper private data (master) here */
89 struct ip_ct_ftp_master ct_ftp_info;
90 struct ip_ct_irc_master ct_irc_info;
93 #ifdef CONFIG_IP_NF_NAT_NEEDED
94 #include <linux/netfilter_ipv4/ip_nat.h>
96 /* per conntrack: nat application helper private data */
97 union ip_conntrack_nat_help {
98 /* insert nat helper private data here */
104 #include <linux/types.h>
105 #include <linux/skbuff.h>
107 #ifdef CONFIG_NETFILTER_DEBUG
108 #define IP_NF_ASSERT(x) \
111 /* Wooah! I'm tripping my conntrack in a frenzy of \
113 printk("NF_IP_ASSERT: %s:%i(%s)\n", \
114 __FILE__, __LINE__, __FUNCTION__); \
117 #define IP_NF_ASSERT(x)
120 struct ip_conntrack_expect
122 /* Internal linked list (global expectation list) */
123 struct list_head list;
125 /* reference count */
128 /* expectation list for this master */
129 struct list_head expected_list;
131 /* The conntrack of the master connection */
132 struct ip_conntrack *expectant;
134 /* The conntrack of the sibling connection, set after
135 * expectation arrived */
136 struct ip_conntrack *sibling;
138 /* Tuple saved for conntrack */
139 struct ip_conntrack_tuple ct_tuple;
141 /* Timer function; deletes the expectation. */
142 struct timer_list timeout;
144 /* Data filled out by the conntrack helpers follow: */
146 /* We expect this tuple, with the following mask */
147 struct ip_conntrack_tuple tuple, mask;
149 /* Function to call after setup and insertion */
150 int (*expectfn)(struct ip_conntrack *new);
152 /* At which sequence number did this expectation occur */
155 union ip_conntrack_expect_proto proto;
157 union ip_conntrack_expect_help help;
160 struct ip_conntrack_helper;
164 /* Usage count in here is 1 for hash table/destruct timer, 1 per skb,
165 plus 1 for any connection(s) we are `master' for */
166 struct nf_conntrack ct_general;
168 /* These are my tuples; original and reply */
169 struct ip_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX];
171 /* Have we seen traffic both ways yet? (bitset) */
172 unsigned long status;
174 /* Timer function; drops refcnt when it goes off. */
175 struct timer_list timeout;
177 /* If we're expecting another related connection, this will be
178 in expected linked list */
179 struct list_head sibling_list;
181 /* Current number of expected connections */
182 unsigned int expecting;
184 /* If we were expected by an expectation, this will be it */
185 struct ip_conntrack_expect *master;
187 /* Helper, if any. */
188 struct ip_conntrack_helper *helper;
190 /* Our various nf_ct_info structs specify *what* relation this
191 packet has to the conntrack */
192 struct nf_ct_info infos[IP_CT_NUMBER];
194 /* Storage reserved for other modules: */
196 union ip_conntrack_proto proto;
198 union ip_conntrack_help help;
200 #ifdef CONFIG_IP_NF_NAT_NEEDED
202 struct ip_nat_info info;
203 union ip_conntrack_nat_help help;
204 #if defined(CONFIG_IP_NF_TARGET_MASQUERADE) || \
205 defined(CONFIG_IP_NF_TARGET_MASQUERADE_MODULE)
209 #endif /* CONFIG_IP_NF_NAT_NEEDED */
211 /* VServer context id */
212 xid_t xid[IP_CT_DIR_MAX];
216 /* get master conntrack via master expectation */
217 #define master_ct(conntr) (conntr->master ? conntr->master->expectant : NULL)
219 /* Alter reply tuple (maybe alter helper). If it's already taken,
220 return 0 and don't do alteration. */
222 ip_conntrack_alter_reply(struct ip_conntrack *conntrack,
223 const struct ip_conntrack_tuple *newreply);
225 /* Is this tuple taken? (ignoring any belonging to the given
228 ip_conntrack_tuple_taken(const struct ip_conntrack_tuple *tuple,
229 const struct ip_conntrack *ignored_conntrack);
231 /* Return conntrack_info and tuple hash for given skb. */
232 extern struct ip_conntrack *
233 ip_conntrack_get(struct sk_buff *skb, enum ip_conntrack_info *ctinfo);
235 /* decrement reference count on a conntrack */
236 extern inline void ip_conntrack_put(struct ip_conntrack *ct);
238 /* find unconfirmed expectation based on tuple */
239 struct ip_conntrack_expect *
240 ip_conntrack_expect_find_get(const struct ip_conntrack_tuple *tuple);
242 /* decrement reference count on an expectation */
243 void ip_conntrack_expect_put(struct ip_conntrack_expect *exp);
245 /* call to create an explicit dependency on ip_conntrack. */
246 extern void need_ip_conntrack(void);
248 extern int invert_tuplepr(struct ip_conntrack_tuple *inverse,
249 const struct ip_conntrack_tuple *orig);
251 /* Refresh conntrack for this many jiffies */
252 extern void ip_ct_refresh(struct ip_conntrack *ct,
253 unsigned long extra_jiffies);
255 /* These are for NAT. Icky. */
256 /* Call me when a conntrack is destroyed. */
257 extern void (*ip_conntrack_destroyed)(struct ip_conntrack *conntrack);
259 /* Fake conntrack entry for untracked connections */
260 extern struct ip_conntrack ip_conntrack_untracked;
262 /* Returns new sk_buff, or NULL */
264 ip_ct_gather_frags(struct sk_buff *skb);
266 /* Delete all conntracks which match. */
268 ip_ct_selective_cleanup(int (*kill)(const struct ip_conntrack *i, void *data),
271 /* It's confirmed if it is, or has been in the hash table. */
272 static inline int is_confirmed(struct ip_conntrack *ct)
274 return test_bit(IPS_CONFIRMED_BIT, &ct->status);
277 extern unsigned int ip_conntrack_htable_size;
279 /* eg. PROVIDES_CONNTRACK(ftp); */
280 #define PROVIDES_CONNTRACK(name) \
281 int needs_ip_conntrack_##name; \
282 EXPORT_SYMBOL(needs_ip_conntrack_##name)
284 /*. eg. NEEDS_CONNTRACK(ftp); */
285 #define NEEDS_CONNTRACK(name) \
286 extern int needs_ip_conntrack_##name; \
287 static int *need_ip_conntrack_##name __attribute_used__ = &needs_ip_conntrack_##name
289 #endif /* __KERNEL__ */
290 #endif /* _IP_CONNTRACK_H */