diff options
author | Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp> | 2005-11-09 19:38:16 -0500 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2005-11-09 19:38:16 -0500 |
commit | 9fb9cbb1082d6b31fb45aa1a14432449a0df6cf1 (patch) | |
tree | c964a62bdd766eca436c30f51a9e33e2b798b0a6 /include/net | |
parent | 6730c3c14421b7c924d06e31bb66e0adad225547 (diff) |
[NETFILTER]: Add nf_conntrack subsystem.
The existing connection tracking subsystem in netfilter can only
handle ipv4. There were basically two choices present to add
connection tracking support for ipv6. We could either duplicate all
of the ipv4 connection tracking code into an ipv6 counterpart, or (the
choice taken by these patches) we could design a generic layer that
could handle both ipv4 and ipv6 and thus requiring only one sub-protocol
(TCP, UDP, etc.) connection tracking helper module to be written.
In fact nf_conntrack is capable of working with any layer 3
protocol.
The existing ipv4 specific conntrack code could also not deal
with the pecularities of doing connection tracking on ipv6,
which is also cured here. For example, these issues include:
1) ICMPv6 handling, which is used for neighbour discovery in
ipv6 thus some messages such as these should not participate
in connection tracking since effectively they are like ARP
messages
2) fragmentation must be handled differently in ipv6, because
the simplistic "defrag, connection track and NAT, refrag"
(which the existing ipv4 connection tracking does) approach simply
isn't feasible in ipv6
3) ipv6 extension header parsing must occur at the correct spots
before and after connection tracking decisions, and there were
no provisions for this in the existing connection tracking
design
4) ipv6 has no need for stateful NAT
The ipv4 specific conntrack layer is kept around, until all of
the ipv4 specific conntrack helpers are ported over to nf_conntrack
and it is feature complete. Once that occurs, the old conntrack
stuff will get placed into the feature-removal-schedule and we will
fully kill it off 6 months later.
Signed-off-by: Yasuyuki Kozakai <yasuyuki.kozakai@toshiba.co.jp>
Signed-off-by: Harald Welte <laforge@netfilter.org>
Signed-off-by: Arnaldo Carvalho de Melo <acme@mandriva.com>
Diffstat (limited to 'include/net')
-rw-r--r-- | include/net/netfilter/ipv4/nf_conntrack_icmp.h | 11 | ||||
-rw-r--r-- | include/net/netfilter/ipv4/nf_conntrack_ipv4.h | 43 | ||||
-rw-r--r-- | include/net/netfilter/ipv6/nf_conntrack_icmpv6.h | 27 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack.h | 354 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack_compat.h | 108 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack_core.h | 76 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack_helper.h | 51 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack_l3proto.h | 93 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack_protocol.h | 105 | ||||
-rw-r--r-- | include/net/netfilter/nf_conntrack_tuple.h | 190 |
10 files changed, 1058 insertions, 0 deletions
diff --git a/include/net/netfilter/ipv4/nf_conntrack_icmp.h b/include/net/netfilter/ipv4/nf_conntrack_icmp.h new file mode 100644 index 000000000000..3dd22cff23ec --- /dev/null +++ b/include/net/netfilter/ipv4/nf_conntrack_icmp.h | |||
@@ -0,0 +1,11 @@ | |||
1 | #ifndef _NF_CONNTRACK_ICMP_H | ||
2 | #define _NF_CONNTRACK_ICMP_H | ||
3 | /* ICMP tracking. */ | ||
4 | #include <asm/atomic.h> | ||
5 | |||
6 | struct ip_ct_icmp | ||
7 | { | ||
8 | /* Optimization: when number in == number out, forget immediately. */ | ||
9 | atomic_t count; | ||
10 | }; | ||
11 | #endif /* _NF_CONNTRACK_ICMP_H */ | ||
diff --git a/include/net/netfilter/ipv4/nf_conntrack_ipv4.h b/include/net/netfilter/ipv4/nf_conntrack_ipv4.h new file mode 100644 index 000000000000..25b081a730e6 --- /dev/null +++ b/include/net/netfilter/ipv4/nf_conntrack_ipv4.h | |||
@@ -0,0 +1,43 @@ | |||
1 | /* | ||
2 | * IPv4 support for nf_conntrack. | ||
3 | * | ||
4 | * 23 Mar 2004: Yasuyuki Kozakai @ USAGI <yasuyuki.kozakai@toshiba.co.jp> | ||
5 | * - move L3 protocol dependent part from include/linux/netfilter_ipv4/ | ||
6 | * ip_conntarck.h | ||
7 | */ | ||
8 | |||
9 | #ifndef _NF_CONNTRACK_IPV4_H | ||
10 | #define _NF_CONNTRACK_IPV4_H | ||
11 | |||
12 | #ifdef CONFIG_IP_NF_NAT_NEEDED | ||
13 | #include <linux/netfilter_ipv4/ip_nat.h> | ||
14 | |||
15 | /* per conntrack: nat application helper private data */ | ||
16 | union ip_conntrack_nat_help { | ||
17 | /* insert nat helper private data here */ | ||
18 | }; | ||
19 | |||
20 | struct nf_conntrack_ipv4_nat { | ||
21 | struct ip_nat_info info; | ||
22 | union ip_conntrack_nat_help help; | ||
23 | #if defined(CONFIG_IP_NF_TARGET_MASQUERADE) || \ | ||
24 | defined(CONFIG_IP_NF_TARGET_MASQUERADE_MODULE) | ||
25 | int masq_index; | ||
26 | #endif | ||
27 | }; | ||
28 | #endif /* CONFIG_IP_NF_NAT_NEEDED */ | ||
29 | |||
30 | struct nf_conntrack_ipv4 { | ||
31 | #ifdef CONFIG_IP_NF_NAT_NEEDED | ||
32 | struct nf_conntrack_ipv4_nat *nat; | ||
33 | #endif | ||
34 | }; | ||
35 | |||
36 | /* Returns new sk_buff, or NULL */ | ||
37 | struct sk_buff * | ||
38 | nf_ct_ipv4_ct_gather_frags(struct sk_buff *skb); | ||
39 | |||
40 | /* call to create an explicit dependency on nf_conntrack_l3proto_ipv4. */ | ||
41 | extern void need_ip_conntrack(void); | ||
42 | |||
43 | #endif /*_NF_CONNTRACK_IPV4_H*/ | ||
diff --git a/include/net/netfilter/ipv6/nf_conntrack_icmpv6.h b/include/net/netfilter/ipv6/nf_conntrack_icmpv6.h new file mode 100644 index 000000000000..86591afda29c --- /dev/null +++ b/include/net/netfilter/ipv6/nf_conntrack_icmpv6.h | |||
@@ -0,0 +1,27 @@ | |||
1 | /* | ||
2 | * ICMPv6 tracking. | ||
3 | * | ||
4 | * 21 Apl 2004: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | ||
5 | * - separated from nf_conntrack_icmp.h | ||
6 | * | ||
7 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_icmp.h | ||
8 | */ | ||
9 | |||
10 | #ifndef _NF_CONNTRACK_ICMPV6_H | ||
11 | #define _NF_CONNTRACK_ICMPV6_H | ||
12 | #include <asm/atomic.h> | ||
13 | |||
14 | #ifndef ICMPV6_NI_QUERY | ||
15 | #define ICMPV6_NI_QUERY 139 | ||
16 | #endif | ||
17 | #ifndef ICMPV6_NI_REPLY | ||
18 | #define ICMPV6_NI_REPLY 140 | ||
19 | #endif | ||
20 | |||
21 | struct nf_ct_icmpv6 | ||
22 | { | ||
23 | /* Optimization: when number in == number out, forget immediately. */ | ||
24 | atomic_t count; | ||
25 | }; | ||
26 | |||
27 | #endif /* _NF_CONNTRACK_ICMPV6_H */ | ||
diff --git a/include/net/netfilter/nf_conntrack.h b/include/net/netfilter/nf_conntrack.h new file mode 100644 index 000000000000..cc4825610795 --- /dev/null +++ b/include/net/netfilter/nf_conntrack.h | |||
@@ -0,0 +1,354 @@ | |||
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__ | ||
18 | #include <linux/config.h> | ||
19 | #include <linux/bitops.h> | ||
20 | #include <linux/compiler.h> | ||
21 | #include <asm/atomic.h> | ||
22 | |||
23 | #include <linux/netfilter/nf_conntrack_tcp.h> | ||
24 | #include <linux/netfilter/nf_conntrack_sctp.h> | ||
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 */ | ||
31 | union 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; | ||
37 | }; | ||
38 | |||
39 | union nf_conntrack_expect_proto { | ||
40 | /* insert expect proto private data here */ | ||
41 | }; | ||
42 | |||
43 | /* Add protocol helper include file here */ | ||
44 | #include <linux/netfilter/nf_conntrack_ftp.h> | ||
45 | |||
46 | /* per conntrack: application helper private data */ | ||
47 | union nf_conntrack_help { | ||
48 | /* insert conntrack helper private data (master) here */ | ||
49 | struct ip_ct_ftp_master ct_ftp_info; | ||
50 | }; | ||
51 | |||
52 | #include <linux/types.h> | ||
53 | #include <linux/skbuff.h> | ||
54 | |||
55 | #ifdef CONFIG_NETFILTER_DEBUG | ||
56 | #define NF_CT_ASSERT(x) \ | ||
57 | do { \ | ||
58 | if (!(x)) \ | ||
59 | /* Wooah! I'm tripping my conntrack in a frenzy of \ | ||
60 | netplay... */ \ | ||
61 | printk("NF_CT_ASSERT: %s:%i(%s)\n", \ | ||
62 | __FILE__, __LINE__, __FUNCTION__); \ | ||
63 | } while(0) | ||
64 | #else | ||
65 | #define NF_CT_ASSERT(x) | ||
66 | #endif | ||
67 | |||
68 | struct nf_conntrack_helper; | ||
69 | |||
70 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> | ||
71 | struct nf_conn | ||
72 | { | ||
73 | /* Usage count in here is 1 for hash table/destruct timer, 1 per skb, | ||
74 | plus 1 for any connection(s) we are `master' for */ | ||
75 | struct nf_conntrack ct_general; | ||
76 | |||
77 | /* XXX should I move this to the tail ? - Y.K */ | ||
78 | /* These are my tuples; original and reply */ | ||
79 | struct nf_conntrack_tuple_hash tuplehash[IP_CT_DIR_MAX]; | ||
80 | |||
81 | /* Have we seen traffic both ways yet? (bitset) */ | ||
82 | unsigned long status; | ||
83 | |||
84 | /* Timer function; drops refcnt when it goes off. */ | ||
85 | struct timer_list timeout; | ||
86 | |||
87 | #ifdef CONFIG_NF_CT_ACCT | ||
88 | /* Accounting Information (same cache line as other written members) */ | ||
89 | struct ip_conntrack_counter counters[IP_CT_DIR_MAX]; | ||
90 | #endif | ||
91 | /* If we were expected by an expectation, this will be it */ | ||
92 | struct nf_conn *master; | ||
93 | |||
94 | /* Current number of expected connections */ | ||
95 | unsigned int expecting; | ||
96 | |||
97 | /* Helper. if any */ | ||
98 | struct nf_conntrack_helper *helper; | ||
99 | |||
100 | /* features - nat, helper, ... used by allocating system */ | ||
101 | u_int32_t features; | ||
102 | |||
103 | /* Storage reserved for other modules: */ | ||
104 | |||
105 | union nf_conntrack_proto proto; | ||
106 | |||
107 | #if defined(CONFIG_NF_CONNTRACK_MARK) | ||
108 | u_int32_t mark; | ||
109 | #endif | ||
110 | |||
111 | /* These members are dynamically allocated. */ | ||
112 | |||
113 | union nf_conntrack_help *help; | ||
114 | |||
115 | /* Layer 3 dependent members. (ex: NAT) */ | ||
116 | union { | ||
117 | struct nf_conntrack_ipv4 *ipv4; | ||
118 | } l3proto; | ||
119 | void *data[0]; | ||
120 | }; | ||
121 | |||
122 | struct nf_conntrack_expect | ||
123 | { | ||
124 | /* Internal linked list (global expectation list) */ | ||
125 | struct list_head list; | ||
126 | |||
127 | /* We expect this tuple, with the following mask */ | ||
128 | struct nf_conntrack_tuple tuple, mask; | ||
129 | |||
130 | /* Function to call after setup and insertion */ | ||
131 | void (*expectfn)(struct nf_conn *new, | ||
132 | struct nf_conntrack_expect *this); | ||
133 | |||
134 | /* The conntrack of the master connection */ | ||
135 | struct nf_conn *master; | ||
136 | |||
137 | /* Timer function; deletes the expectation. */ | ||
138 | struct timer_list timeout; | ||
139 | |||
140 | /* Usage count. */ | ||
141 | atomic_t use; | ||
142 | |||
143 | /* Flags */ | ||
144 | unsigned int flags; | ||
145 | |||
146 | #ifdef CONFIG_NF_NAT_NEEDED | ||
147 | /* This is the original per-proto part, used to map the | ||
148 | * expected connection the way the recipient expects. */ | ||
149 | union nf_conntrack_manip_proto saved_proto; | ||
150 | /* Direction relative to the master connection. */ | ||
151 | enum ip_conntrack_dir dir; | ||
152 | #endif | ||
153 | }; | ||
154 | |||
155 | #define NF_CT_EXPECT_PERMANENT 0x1 | ||
156 | |||
157 | static inline struct nf_conn * | ||
158 | nf_ct_tuplehash_to_ctrack(const struct nf_conntrack_tuple_hash *hash) | ||
159 | { | ||
160 | return container_of(hash, struct nf_conn, | ||
161 | tuplehash[hash->tuple.dst.dir]); | ||
162 | } | ||
163 | |||
164 | /* get master conntrack via master expectation */ | ||
165 | #define master_ct(conntr) (conntr->master) | ||
166 | |||
167 | /* Alter reply tuple (maybe alter helper). */ | ||
168 | extern void | ||
169 | nf_conntrack_alter_reply(struct nf_conn *conntrack, | ||
170 | const struct nf_conntrack_tuple *newreply); | ||
171 | |||
172 | /* Is this tuple taken? (ignoring any belonging to the given | ||
173 | conntrack). */ | ||
174 | extern int | ||
175 | nf_conntrack_tuple_taken(const struct nf_conntrack_tuple *tuple, | ||
176 | const struct nf_conn *ignored_conntrack); | ||
177 | |||
178 | /* Return conntrack_info and tuple hash for given skb. */ | ||
179 | static inline struct nf_conn * | ||
180 | nf_ct_get(const struct sk_buff *skb, enum ip_conntrack_info *ctinfo) | ||
181 | { | ||
182 | *ctinfo = skb->nfctinfo; | ||
183 | return (struct nf_conn *)skb->nfct; | ||
184 | } | ||
185 | |||
186 | /* decrement reference count on a conntrack */ | ||
187 | static inline void nf_ct_put(struct nf_conn *ct) | ||
188 | { | ||
189 | NF_CT_ASSERT(ct); | ||
190 | nf_conntrack_put(&ct->ct_general); | ||
191 | } | ||
192 | |||
193 | /* call to create an explicit dependency on nf_conntrack. */ | ||
194 | extern void need_nf_conntrack(void); | ||
195 | |||
196 | extern int nf_ct_invert_tuplepr(struct nf_conntrack_tuple *inverse, | ||
197 | const struct nf_conntrack_tuple *orig); | ||
198 | |||
199 | extern void __nf_ct_refresh_acct(struct nf_conn *ct, | ||
200 | enum ip_conntrack_info ctinfo, | ||
201 | const struct sk_buff *skb, | ||
202 | unsigned long extra_jiffies, | ||
203 | int do_acct); | ||
204 | |||
205 | /* Refresh conntrack for this many jiffies and do accounting */ | ||
206 | static inline void nf_ct_refresh_acct(struct nf_conn *ct, | ||
207 | enum ip_conntrack_info ctinfo, | ||
208 | const struct sk_buff *skb, | ||
209 | unsigned long extra_jiffies) | ||
210 | { | ||
211 | __nf_ct_refresh_acct(ct, ctinfo, skb, extra_jiffies, 1); | ||
212 | } | ||
213 | |||
214 | /* Refresh conntrack for this many jiffies */ | ||
215 | static inline void nf_ct_refresh(struct nf_conn *ct, | ||
216 | const struct sk_buff *skb, | ||
217 | unsigned long extra_jiffies) | ||
218 | { | ||
219 | __nf_ct_refresh_acct(ct, 0, skb, extra_jiffies, 0); | ||
220 | } | ||
221 | |||
222 | /* These are for NAT. Icky. */ | ||
223 | /* Update TCP window tracking data when NAT mangles the packet */ | ||
224 | extern void nf_conntrack_tcp_update(struct sk_buff *skb, | ||
225 | unsigned int dataoff, | ||
226 | struct nf_conn *conntrack, | ||
227 | int dir); | ||
228 | |||
229 | /* Call me when a conntrack is destroyed. */ | ||
230 | extern void (*nf_conntrack_destroyed)(struct nf_conn *conntrack); | ||
231 | |||
232 | /* Fake conntrack entry for untracked connections */ | ||
233 | extern struct nf_conn nf_conntrack_untracked; | ||
234 | |||
235 | extern int nf_ct_no_defrag; | ||
236 | |||
237 | /* Iterate over all conntracks: if iter returns true, it's deleted. */ | ||
238 | extern void | ||
239 | nf_ct_iterate_cleanup(int (*iter)(struct nf_conn *i, void *data), void *data); | ||
240 | extern void nf_conntrack_free(struct nf_conn *ct); | ||
241 | extern struct nf_conn * | ||
242 | nf_conntrack_alloc(const struct nf_conntrack_tuple *orig, | ||
243 | const struct nf_conntrack_tuple *repl); | ||
244 | |||
245 | /* It's confirmed if it is, or has been in the hash table. */ | ||
246 | static inline int nf_ct_is_confirmed(struct nf_conn *ct) | ||
247 | { | ||
248 | return test_bit(IPS_CONFIRMED_BIT, &ct->status); | ||
249 | } | ||
250 | |||
251 | static inline int nf_ct_is_dying(struct nf_conn *ct) | ||
252 | { | ||
253 | return test_bit(IPS_DYING_BIT, &ct->status); | ||
254 | } | ||
255 | |||
256 | extern unsigned int nf_conntrack_htable_size; | ||
257 | |||
258 | #define NF_CT_STAT_INC(count) (__get_cpu_var(nf_conntrack_stat).count++) | ||
259 | |||
260 | #ifdef CONFIG_NF_CONNTRACK_EVENTS | ||
261 | #include <linux/notifier.h> | ||
262 | #include <linux/interrupt.h> | ||
263 | |||
264 | struct nf_conntrack_ecache { | ||
265 | struct nf_conn *ct; | ||
266 | unsigned int events; | ||
267 | }; | ||
268 | DECLARE_PER_CPU(struct nf_conntrack_ecache, nf_conntrack_ecache); | ||
269 | |||
270 | #define CONNTRACK_ECACHE(x) (__get_cpu_var(nf_conntrack_ecache).x) | ||
271 | |||
272 | extern struct notifier_block *nf_conntrack_chain; | ||
273 | extern struct notifier_block *nf_conntrack_expect_chain; | ||
274 | |||
275 | static inline int nf_conntrack_register_notifier(struct notifier_block *nb) | ||
276 | { | ||
277 | return notifier_chain_register(&nf_conntrack_chain, nb); | ||
278 | } | ||
279 | |||
280 | static inline int nf_conntrack_unregister_notifier(struct notifier_block *nb) | ||
281 | { | ||
282 | return notifier_chain_unregister(&nf_conntrack_chain, nb); | ||
283 | } | ||
284 | |||
285 | static inline int | ||
286 | nf_conntrack_expect_register_notifier(struct notifier_block *nb) | ||
287 | { | ||
288 | return notifier_chain_register(&nf_conntrack_expect_chain, nb); | ||
289 | } | ||
290 | |||
291 | static inline int | ||
292 | nf_conntrack_expect_unregister_notifier(struct notifier_block *nb) | ||
293 | { | ||
294 | return notifier_chain_unregister(&nf_conntrack_expect_chain, nb); | ||
295 | } | ||
296 | |||
297 | extern void nf_ct_deliver_cached_events(const struct nf_conn *ct); | ||
298 | extern void __nf_ct_event_cache_init(struct nf_conn *ct); | ||
299 | |||
300 | static inline void | ||
301 | nf_conntrack_event_cache(enum ip_conntrack_events event, | ||
302 | const struct sk_buff *skb) | ||
303 | { | ||
304 | struct nf_conn *ct = (struct nf_conn *)skb->nfct; | ||
305 | struct nf_conntrack_ecache *ecache; | ||
306 | |||
307 | local_bh_disable(); | ||
308 | ecache = &__get_cpu_var(nf_conntrack_ecache); | ||
309 | if (ct != ecache->ct) | ||
310 | __nf_ct_event_cache_init(ct); | ||
311 | ecache->events |= event; | ||
312 | local_bh_enable(); | ||
313 | } | ||
314 | |||
315 | static inline void nf_conntrack_event(enum ip_conntrack_events event, | ||
316 | struct nf_conn *ct) | ||
317 | { | ||
318 | if (nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct)) | ||
319 | notifier_call_chain(&nf_conntrack_chain, event, ct); | ||
320 | } | ||
321 | |||
322 | static inline void | ||
323 | nf_conntrack_expect_event(enum ip_conntrack_expect_events event, | ||
324 | struct nf_conntrack_expect *exp) | ||
325 | { | ||
326 | notifier_call_chain(&nf_conntrack_expect_chain, event, exp); | ||
327 | } | ||
328 | #else /* CONFIG_NF_CONNTRACK_EVENTS */ | ||
329 | static inline void nf_conntrack_event_cache(enum ip_conntrack_events event, | ||
330 | const struct sk_buff *skb) {} | ||
331 | static inline void nf_conntrack_event(enum ip_conntrack_events event, | ||
332 | struct nf_conn *ct) {} | ||
333 | static inline void nf_ct_deliver_cached_events(const struct nf_conn *ct) {} | ||
334 | static inline void | ||
335 | nf_conntrack_expect_event(enum ip_conntrack_expect_events event, | ||
336 | struct nf_conntrack_expect *exp) {} | ||
337 | #endif /* CONFIG_NF_CONNTRACK_EVENTS */ | ||
338 | |||
339 | /* no helper, no nat */ | ||
340 | #define NF_CT_F_BASIC 0 | ||
341 | /* for helper */ | ||
342 | #define NF_CT_F_HELP 1 | ||
343 | /* for nat. */ | ||
344 | #define NF_CT_F_NAT 2 | ||
345 | #define NF_CT_F_NUM 4 | ||
346 | |||
347 | extern int | ||
348 | nf_conntrack_register_cache(u_int32_t features, const char *name, size_t size, | ||
349 | int (*init_conntrack)(struct nf_conn *, u_int32_t)); | ||
350 | extern void | ||
351 | nf_conntrack_unregister_cache(u_int32_t features); | ||
352 | |||
353 | #endif /* __KERNEL__ */ | ||
354 | #endif /* _NF_CONNTRACK_H */ | ||
diff --git a/include/net/netfilter/nf_conntrack_compat.h b/include/net/netfilter/nf_conntrack_compat.h new file mode 100644 index 000000000000..3cac19fb3648 --- /dev/null +++ b/include/net/netfilter/nf_conntrack_compat.h | |||
@@ -0,0 +1,108 @@ | |||
1 | #ifndef _NF_CONNTRACK_COMPAT_H | ||
2 | #define _NF_CONNTRACK_COMPAT_H | ||
3 | |||
4 | #ifdef __KERNEL__ | ||
5 | |||
6 | #if defined(CONFIG_IP_NF_CONNTRACK) || defined(CONFIG_IP_NF_CONNTRACK_MODULE) | ||
7 | |||
8 | #include <linux/netfilter_ipv4/ip_conntrack.h> | ||
9 | |||
10 | #ifdef CONFIG_IP_NF_CONNTRACK_MARK | ||
11 | static inline u_int32_t *nf_ct_get_mark(const struct sk_buff *skb, | ||
12 | u_int32_t *ctinfo) | ||
13 | { | ||
14 | struct ip_conntrack *ct = ip_conntrack_get(skb, ctinfo); | ||
15 | |||
16 | if (ct) | ||
17 | return &ct->mark; | ||
18 | else | ||
19 | return NULL; | ||
20 | } | ||
21 | #endif /* CONFIG_IP_NF_CONNTRACK_MARK */ | ||
22 | |||
23 | #ifdef CONFIG_IP_NF_CT_ACCT | ||
24 | static inline struct ip_conntrack_counter * | ||
25 | nf_ct_get_counters(const struct sk_buff *skb) | ||
26 | { | ||
27 | enum ip_conntrack_info ctinfo; | ||
28 | struct ip_conntrack *ct = ip_conntrack_get(skb, &ctinfo); | ||
29 | |||
30 | if (ct) | ||
31 | return ct->counters; | ||
32 | else | ||
33 | return NULL; | ||
34 | } | ||
35 | #endif /* CONFIG_IP_NF_CT_ACCT */ | ||
36 | |||
37 | static inline int nf_ct_is_untracked(const struct sk_buff *skb) | ||
38 | { | ||
39 | return (skb->nfct == &ip_conntrack_untracked.ct_general); | ||
40 | } | ||
41 | |||
42 | static inline void nf_ct_untrack(struct sk_buff *skb) | ||
43 | { | ||
44 | skb->nfct = &ip_conntrack_untracked.ct_general; | ||
45 | } | ||
46 | |||
47 | static inline int nf_ct_get_ctinfo(const struct sk_buff *skb, | ||
48 | enum ip_conntrack_info *ctinfo) | ||
49 | { | ||
50 | struct ip_conntrack *ct = ip_conntrack_get(skb, ctinfo); | ||
51 | return (ct != NULL); | ||
52 | } | ||
53 | |||
54 | #else /* CONFIG_IP_NF_CONNTRACK */ | ||
55 | |||
56 | #include <net/netfilter/ipv4/nf_conntrack_ipv4.h> | ||
57 | #include <net/netfilter/nf_conntrack.h> | ||
58 | |||
59 | #ifdef CONFIG_NF_CONNTRACK_MARK | ||
60 | |||
61 | static inline u_int32_t *nf_ct_get_mark(const struct sk_buff *skb, | ||
62 | u_int32_t *ctinfo) | ||
63 | { | ||
64 | struct nf_conn *ct = nf_ct_get(skb, ctinfo); | ||
65 | |||
66 | if (ct) | ||
67 | return &ct->mark; | ||
68 | else | ||
69 | return NULL; | ||
70 | } | ||
71 | #endif /* CONFIG_NF_CONNTRACK_MARK */ | ||
72 | |||
73 | #ifdef CONFIG_NF_CT_ACCT | ||
74 | static inline struct ip_conntrack_counter * | ||
75 | nf_ct_get_counters(const struct sk_buff *skb) | ||
76 | { | ||
77 | enum ip_conntrack_info ctinfo; | ||
78 | struct nf_conn *ct = nf_ct_get(skb, &ctinfo); | ||
79 | |||
80 | if (ct) | ||
81 | return ct->counters; | ||
82 | else | ||
83 | return NULL; | ||
84 | } | ||
85 | #endif /* CONFIG_NF_CT_ACCT */ | ||
86 | |||
87 | static inline int nf_ct_is_untracked(const struct sk_buff *skb) | ||
88 | { | ||
89 | return (skb->nfct == &nf_conntrack_untracked.ct_general); | ||
90 | } | ||
91 | |||
92 | static inline void nf_ct_untrack(struct sk_buff *skb) | ||
93 | { | ||
94 | skb->nfct = &nf_conntrack_untracked.ct_general; | ||
95 | } | ||
96 | |||
97 | static inline int nf_ct_get_ctinfo(const struct sk_buff *skb, | ||
98 | enum ip_conntrack_info *ctinfo) | ||
99 | { | ||
100 | struct nf_conn *ct = nf_ct_get(skb, ctinfo); | ||
101 | return (ct != NULL); | ||
102 | } | ||
103 | |||
104 | #endif /* CONFIG_IP_NF_CONNTRACK */ | ||
105 | |||
106 | #endif /* __KERNEL__ */ | ||
107 | |||
108 | #endif /* _NF_CONNTRACK_COMPAT_H */ | ||
diff --git a/include/net/netfilter/nf_conntrack_core.h b/include/net/netfilter/nf_conntrack_core.h new file mode 100644 index 000000000000..da254525a4ce --- /dev/null +++ b/include/net/netfilter/nf_conntrack_core.h | |||
@@ -0,0 +1,76 @@ | |||
1 | /* | ||
2 | * This header is used to share core functionality between the | ||
3 | * standalone connection tracking module, and the compatibility layer's use | ||
4 | * of connection tracking. | ||
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_core.h | ||
10 | */ | ||
11 | |||
12 | #ifndef _NF_CONNTRACK_CORE_H | ||
13 | #define _NF_CONNTRACK_CORE_H | ||
14 | |||
15 | #include <linux/netfilter.h> | ||
16 | |||
17 | /* This header is used to share core functionality between the | ||
18 | standalone connection tracking module, and the compatibility layer's use | ||
19 | of connection tracking. */ | ||
20 | extern unsigned int nf_conntrack_in(int pf, | ||
21 | unsigned int hooknum, | ||
22 | struct sk_buff **pskb); | ||
23 | |||
24 | extern int nf_conntrack_init(void); | ||
25 | extern void nf_conntrack_cleanup(void); | ||
26 | |||
27 | struct nf_conntrack_l3proto; | ||
28 | extern struct nf_conntrack_l3proto *nf_ct_find_l3proto(u_int16_t pf); | ||
29 | /* Like above, but you already have conntrack read lock. */ | ||
30 | extern struct nf_conntrack_l3proto *__nf_ct_find_l3proto(u_int16_t l3proto); | ||
31 | |||
32 | struct nf_conntrack_protocol; | ||
33 | |||
34 | extern int | ||
35 | nf_ct_get_tuple(const struct sk_buff *skb, | ||
36 | unsigned int nhoff, | ||
37 | unsigned int dataoff, | ||
38 | u_int16_t l3num, | ||
39 | u_int8_t protonum, | ||
40 | struct nf_conntrack_tuple *tuple, | ||
41 | const struct nf_conntrack_l3proto *l3proto, | ||
42 | const struct nf_conntrack_protocol *protocol); | ||
43 | |||
44 | extern int | ||
45 | nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse, | ||
46 | const struct nf_conntrack_tuple *orig, | ||
47 | const struct nf_conntrack_l3proto *l3proto, | ||
48 | const struct nf_conntrack_protocol *protocol); | ||
49 | |||
50 | /* Find a connection corresponding to a tuple. */ | ||
51 | extern struct nf_conntrack_tuple_hash * | ||
52 | nf_conntrack_find_get(const struct nf_conntrack_tuple *tuple, | ||
53 | const struct nf_conn *ignored_conntrack); | ||
54 | |||
55 | extern int __nf_conntrack_confirm(struct sk_buff **pskb); | ||
56 | |||
57 | /* Confirm a connection: returns NF_DROP if packet must be dropped. */ | ||
58 | static inline int nf_conntrack_confirm(struct sk_buff **pskb) | ||
59 | { | ||
60 | struct nf_conn *ct = (struct nf_conn *)(*pskb)->nfct; | ||
61 | int ret = NF_ACCEPT; | ||
62 | |||
63 | if (ct) { | ||
64 | if (!nf_ct_is_confirmed(ct)) | ||
65 | ret = __nf_conntrack_confirm(pskb); | ||
66 | nf_ct_deliver_cached_events(ct); | ||
67 | } | ||
68 | return ret; | ||
69 | } | ||
70 | |||
71 | extern void __nf_conntrack_attach(struct sk_buff *nskb, struct sk_buff *skb); | ||
72 | |||
73 | extern struct list_head *nf_conntrack_hash; | ||
74 | extern struct list_head nf_conntrack_expect_list; | ||
75 | extern rwlock_t nf_conntrack_lock ; | ||
76 | #endif /* _NF_CONNTRACK_CORE_H */ | ||
diff --git a/include/net/netfilter/nf_conntrack_helper.h b/include/net/netfilter/nf_conntrack_helper.h new file mode 100644 index 000000000000..5a66b2a3a623 --- /dev/null +++ b/include/net/netfilter/nf_conntrack_helper.h | |||
@@ -0,0 +1,51 @@ | |||
1 | /* | ||
2 | * connection tracking helpers. | ||
3 | * | ||
4 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | ||
5 | * - generalize L3 protocol dependent part. | ||
6 | * | ||
7 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_helper.h | ||
8 | */ | ||
9 | |||
10 | #ifndef _NF_CONNTRACK_HELPER_H | ||
11 | #define _NF_CONNTRACK_HELPER_H | ||
12 | #include <net/netfilter/nf_conntrack.h> | ||
13 | |||
14 | struct module; | ||
15 | |||
16 | struct nf_conntrack_helper | ||
17 | { | ||
18 | struct list_head list; /* Internal use. */ | ||
19 | |||
20 | const char *name; /* name of the module */ | ||
21 | struct module *me; /* pointer to self */ | ||
22 | unsigned int max_expected; /* Maximum number of concurrent | ||
23 | * expected connections */ | ||
24 | unsigned int timeout; /* timeout for expecteds */ | ||
25 | |||
26 | /* Mask of things we will help (compared against server response) */ | ||
27 | struct nf_conntrack_tuple tuple; | ||
28 | struct nf_conntrack_tuple mask; | ||
29 | |||
30 | /* Function to call when data passes; return verdict, or -1 to | ||
31 | invalidate. */ | ||
32 | int (*help)(struct sk_buff **pskb, | ||
33 | unsigned int protoff, | ||
34 | struct nf_conn *ct, | ||
35 | enum ip_conntrack_info conntrackinfo); | ||
36 | }; | ||
37 | |||
38 | extern int nf_conntrack_helper_register(struct nf_conntrack_helper *); | ||
39 | extern void nf_conntrack_helper_unregister(struct nf_conntrack_helper *); | ||
40 | |||
41 | /* Allocate space for an expectation: this is mandatory before calling | ||
42 | nf_conntrack_expect_related. You will have to call put afterwards. */ | ||
43 | extern struct nf_conntrack_expect * | ||
44 | nf_conntrack_expect_alloc(struct nf_conn *master); | ||
45 | extern void nf_conntrack_expect_put(struct nf_conntrack_expect *exp); | ||
46 | |||
47 | /* Add an expected connection: can have more than one per connection */ | ||
48 | extern int nf_conntrack_expect_related(struct nf_conntrack_expect *exp); | ||
49 | extern void nf_conntrack_unexpect_related(struct nf_conntrack_expect *exp); | ||
50 | |||
51 | #endif /*_NF_CONNTRACK_HELPER_H*/ | ||
diff --git a/include/net/netfilter/nf_conntrack_l3proto.h b/include/net/netfilter/nf_conntrack_l3proto.h new file mode 100644 index 000000000000..01663e5b33df --- /dev/null +++ b/include/net/netfilter/nf_conntrack_l3proto.h | |||
@@ -0,0 +1,93 @@ | |||
1 | /* | ||
2 | * Copyright (C)2003,2004 USAGI/WIDE Project | ||
3 | * | ||
4 | * Header for use in defining a given L3 protocol for connection tracking. | ||
5 | * | ||
6 | * Author: | ||
7 | * Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | ||
8 | * | ||
9 | * Derived from include/netfilter_ipv4/ip_conntrack_protocol.h | ||
10 | */ | ||
11 | |||
12 | #ifndef _NF_CONNTRACK_L3PROTO_H | ||
13 | #define _NF_CONNTRACK_L3PROTO_H | ||
14 | #include <linux/seq_file.h> | ||
15 | #include <net/netfilter/nf_conntrack.h> | ||
16 | |||
17 | struct nf_conntrack_l3proto | ||
18 | { | ||
19 | /* Next pointer. */ | ||
20 | struct list_head list; | ||
21 | |||
22 | /* L3 Protocol Family number. ex) PF_INET */ | ||
23 | u_int16_t l3proto; | ||
24 | |||
25 | /* Protocol name */ | ||
26 | const char *name; | ||
27 | |||
28 | /* | ||
29 | * Try to fill in the third arg: nhoff is offset of l3 proto | ||
30 | * hdr. Return true if possible. | ||
31 | */ | ||
32 | int (*pkt_to_tuple)(const struct sk_buff *skb, unsigned int nhoff, | ||
33 | struct nf_conntrack_tuple *tuple); | ||
34 | |||
35 | /* | ||
36 | * Invert the per-proto part of the tuple: ie. turn xmit into reply. | ||
37 | * Some packets can't be inverted: return 0 in that case. | ||
38 | */ | ||
39 | int (*invert_tuple)(struct nf_conntrack_tuple *inverse, | ||
40 | const struct nf_conntrack_tuple *orig); | ||
41 | |||
42 | /* Print out the per-protocol part of the tuple. */ | ||
43 | int (*print_tuple)(struct seq_file *s, | ||
44 | const struct nf_conntrack_tuple *); | ||
45 | |||
46 | /* Print out the private part of the conntrack. */ | ||
47 | int (*print_conntrack)(struct seq_file *s, const struct nf_conn *); | ||
48 | |||
49 | /* Returns verdict for packet, or -1 for invalid. */ | ||
50 | int (*packet)(struct nf_conn *conntrack, | ||
51 | const struct sk_buff *skb, | ||
52 | enum ip_conntrack_info ctinfo); | ||
53 | |||
54 | /* | ||
55 | * Called when a new connection for this protocol found; | ||
56 | * returns TRUE if it's OK. If so, packet() called next. | ||
57 | */ | ||
58 | int (*new)(struct nf_conn *conntrack, const struct sk_buff *skb); | ||
59 | |||
60 | /* Called when a conntrack entry is destroyed */ | ||
61 | void (*destroy)(struct nf_conn *conntrack); | ||
62 | |||
63 | /* | ||
64 | * Called before tracking. | ||
65 | * *dataoff: offset of protocol header (TCP, UDP,...) in *pskb | ||
66 | * *protonum: protocol number | ||
67 | */ | ||
68 | int (*prepare)(struct sk_buff **pskb, unsigned int hooknum, | ||
69 | unsigned int *dataoff, u_int8_t *protonum); | ||
70 | |||
71 | u_int32_t (*get_features)(const struct nf_conntrack_tuple *tuple); | ||
72 | |||
73 | /* Module (if any) which this is connected to. */ | ||
74 | struct module *me; | ||
75 | }; | ||
76 | |||
77 | extern struct nf_conntrack_l3proto *nf_ct_l3protos[AF_MAX]; | ||
78 | |||
79 | /* Protocol registration. */ | ||
80 | extern int nf_conntrack_l3proto_register(struct nf_conntrack_l3proto *proto); | ||
81 | extern void nf_conntrack_l3proto_unregister(struct nf_conntrack_l3proto *proto); | ||
82 | |||
83 | static inline struct nf_conntrack_l3proto * | ||
84 | nf_ct_find_l3proto(u_int16_t l3proto) | ||
85 | { | ||
86 | return nf_ct_l3protos[l3proto]; | ||
87 | } | ||
88 | |||
89 | /* Existing built-in protocols */ | ||
90 | extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv4; | ||
91 | extern struct nf_conntrack_l3proto nf_conntrack_l3proto_ipv6; | ||
92 | extern struct nf_conntrack_l3proto nf_conntrack_generic_l3proto; | ||
93 | #endif /*_NF_CONNTRACK_L3PROTO_H*/ | ||
diff --git a/include/net/netfilter/nf_conntrack_protocol.h b/include/net/netfilter/nf_conntrack_protocol.h new file mode 100644 index 000000000000..b3afda35397a --- /dev/null +++ b/include/net/netfilter/nf_conntrack_protocol.h | |||
@@ -0,0 +1,105 @@ | |||
1 | /* | ||
2 | * Header for use in defining a given protocol for connection tracking. | ||
3 | * | ||
4 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | ||
5 | * - generalized L3 protocol dependent part. | ||
6 | * | ||
7 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_protcol.h | ||
8 | */ | ||
9 | |||
10 | #ifndef _NF_CONNTRACK_PROTOCOL_H | ||
11 | #define _NF_CONNTRACK_PROTOCOL_H | ||
12 | #include <net/netfilter/nf_conntrack.h> | ||
13 | |||
14 | struct seq_file; | ||
15 | |||
16 | struct nf_conntrack_protocol | ||
17 | { | ||
18 | /* Next pointer. */ | ||
19 | struct list_head list; | ||
20 | |||
21 | /* L3 Protocol number. */ | ||
22 | u_int16_t l3proto; | ||
23 | |||
24 | /* Protocol number. */ | ||
25 | u_int8_t proto; | ||
26 | |||
27 | /* Protocol name */ | ||
28 | const char *name; | ||
29 | |||
30 | /* Try to fill in the third arg: dataoff is offset past network protocol | ||
31 | hdr. Return true if possible. */ | ||
32 | int (*pkt_to_tuple)(const struct sk_buff *skb, | ||
33 | unsigned int dataoff, | ||
34 | struct nf_conntrack_tuple *tuple); | ||
35 | |||
36 | /* Invert the per-proto part of the tuple: ie. turn xmit into reply. | ||
37 | * Some packets can't be inverted: return 0 in that case. | ||
38 | */ | ||
39 | int (*invert_tuple)(struct nf_conntrack_tuple *inverse, | ||
40 | const struct nf_conntrack_tuple *orig); | ||
41 | |||
42 | /* Print out the per-protocol part of the tuple. Return like seq_* */ | ||
43 | int (*print_tuple)(struct seq_file *s, | ||
44 | const struct nf_conntrack_tuple *); | ||
45 | |||
46 | /* Print out the private part of the conntrack. */ | ||
47 | int (*print_conntrack)(struct seq_file *s, const struct nf_conn *); | ||
48 | |||
49 | /* Returns verdict for packet, or -1 for invalid. */ | ||
50 | int (*packet)(struct nf_conn *conntrack, | ||
51 | const struct sk_buff *skb, | ||
52 | unsigned int dataoff, | ||
53 | enum ip_conntrack_info ctinfo, | ||
54 | int pf, | ||
55 | unsigned int hooknum); | ||
56 | |||
57 | /* Called when a new connection for this protocol found; | ||
58 | * returns TRUE if it's OK. If so, packet() called next. */ | ||
59 | int (*new)(struct nf_conn *conntrack, const struct sk_buff *skb, | ||
60 | unsigned int dataoff); | ||
61 | |||
62 | /* Called when a conntrack entry is destroyed */ | ||
63 | void (*destroy)(struct nf_conn *conntrack); | ||
64 | |||
65 | int (*error)(struct sk_buff *skb, unsigned int dataoff, | ||
66 | enum ip_conntrack_info *ctinfo, | ||
67 | int pf, unsigned int hooknum); | ||
68 | |||
69 | /* Module (if any) which this is connected to. */ | ||
70 | struct module *me; | ||
71 | }; | ||
72 | |||
73 | /* Existing built-in protocols */ | ||
74 | extern struct nf_conntrack_protocol nf_conntrack_protocol_tcp6; | ||
75 | extern struct nf_conntrack_protocol nf_conntrack_protocol_udp4; | ||
76 | extern struct nf_conntrack_protocol nf_conntrack_protocol_udp6; | ||
77 | extern struct nf_conntrack_protocol nf_conntrack_generic_protocol; | ||
78 | |||
79 | #define MAX_NF_CT_PROTO 256 | ||
80 | extern struct nf_conntrack_protocol **nf_ct_protos[PF_MAX]; | ||
81 | |||
82 | extern struct nf_conntrack_protocol * | ||
83 | nf_ct_find_proto(u_int16_t l3proto, u_int8_t protocol); | ||
84 | |||
85 | /* Protocol registration. */ | ||
86 | extern int nf_conntrack_protocol_register(struct nf_conntrack_protocol *proto); | ||
87 | extern void nf_conntrack_protocol_unregister(struct nf_conntrack_protocol *proto); | ||
88 | |||
89 | /* Log invalid packets */ | ||
90 | extern unsigned int nf_ct_log_invalid; | ||
91 | |||
92 | #ifdef CONFIG_SYSCTL | ||
93 | #ifdef DEBUG_INVALID_PACKETS | ||
94 | #define LOG_INVALID(proto) \ | ||
95 | (nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW) | ||
96 | #else | ||
97 | #define LOG_INVALID(proto) \ | ||
98 | ((nf_ct_log_invalid == (proto) || nf_ct_log_invalid == IPPROTO_RAW) \ | ||
99 | && net_ratelimit()) | ||
100 | #endif | ||
101 | #else | ||
102 | #define LOG_INVALID(proto) 0 | ||
103 | #endif /* CONFIG_SYSCTL */ | ||
104 | |||
105 | #endif /*_NF_CONNTRACK_PROTOCOL_H*/ | ||
diff --git a/include/net/netfilter/nf_conntrack_tuple.h b/include/net/netfilter/nf_conntrack_tuple.h new file mode 100644 index 000000000000..14ce790e5c65 --- /dev/null +++ b/include/net/netfilter/nf_conntrack_tuple.h | |||
@@ -0,0 +1,190 @@ | |||
1 | /* | ||
2 | * Definitions and Declarations for tuple. | ||
3 | * | ||
4 | * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp> | ||
5 | * - generalize L3 protocol dependent part. | ||
6 | * | ||
7 | * Derived from include/linux/netfiter_ipv4/ip_conntrack_tuple.h | ||
8 | */ | ||
9 | |||
10 | #ifndef _NF_CONNTRACK_TUPLE_H | ||
11 | #define _NF_CONNTRACK_TUPLE_H | ||
12 | |||
13 | #include <linux/netfilter/nf_conntrack_tuple_common.h> | ||
14 | |||
15 | /* A `tuple' is a structure containing the information to uniquely | ||
16 | identify a connection. ie. if two packets have the same tuple, they | ||
17 | are in the same connection; if not, they are not. | ||
18 | |||
19 | We divide the structure along "manipulatable" and | ||
20 | "non-manipulatable" lines, for the benefit of the NAT code. | ||
21 | */ | ||
22 | |||
23 | #define NF_CT_TUPLE_L3SIZE 4 | ||
24 | |||
25 | /* The l3 protocol-specific manipulable parts of the tuple: always in | ||
26 | network order! */ | ||
27 | union nf_conntrack_man_l3proto { | ||
28 | u_int32_t all[NF_CT_TUPLE_L3SIZE]; | ||
29 | u_int32_t ip; | ||
30 | u_int32_t ip6[4]; | ||
31 | }; | ||
32 | |||
33 | /* The protocol-specific manipulable parts of the tuple: always in | ||
34 | network order! */ | ||
35 | union nf_conntrack_man_proto | ||
36 | { | ||
37 | /* Add other protocols here. */ | ||
38 | u_int16_t all; | ||
39 | |||
40 | struct { | ||
41 | u_int16_t port; | ||
42 | } tcp; | ||
43 | struct { | ||
44 | u_int16_t port; | ||
45 | } udp; | ||
46 | struct { | ||
47 | u_int16_t id; | ||
48 | } icmp; | ||
49 | struct { | ||
50 | u_int16_t port; | ||
51 | } sctp; | ||
52 | }; | ||
53 | |||
54 | /* The manipulable part of the tuple. */ | ||
55 | struct nf_conntrack_man | ||
56 | { | ||
57 | union nf_conntrack_man_l3proto u3; | ||
58 | union nf_conntrack_man_proto u; | ||
59 | /* Layer 3 protocol */ | ||
60 | u_int16_t l3num; | ||
61 | }; | ||
62 | |||
63 | /* This contains the information to distinguish a connection. */ | ||
64 | struct nf_conntrack_tuple | ||
65 | { | ||
66 | struct nf_conntrack_man src; | ||
67 | |||
68 | /* These are the parts of the tuple which are fixed. */ | ||
69 | struct { | ||
70 | union { | ||
71 | u_int32_t all[NF_CT_TUPLE_L3SIZE]; | ||
72 | u_int32_t ip; | ||
73 | u_int32_t ip6[4]; | ||
74 | } u3; | ||
75 | union { | ||
76 | /* Add other protocols here. */ | ||
77 | u_int16_t all; | ||
78 | |||
79 | struct { | ||
80 | u_int16_t port; | ||
81 | } tcp; | ||
82 | struct { | ||
83 | u_int16_t port; | ||
84 | } udp; | ||
85 | struct { | ||
86 | u_int8_t type, code; | ||
87 | } icmp; | ||
88 | struct { | ||
89 | u_int16_t port; | ||
90 | } sctp; | ||
91 | } u; | ||
92 | |||
93 | /* The protocol. */ | ||
94 | u_int8_t protonum; | ||
95 | |||
96 | /* The direction (for tuplehash) */ | ||
97 | u_int8_t dir; | ||
98 | } dst; | ||
99 | }; | ||
100 | |||
101 | /* This is optimized opposed to a memset of the whole structure. Everything we | ||
102 | * really care about is the source/destination unions */ | ||
103 | #define NF_CT_TUPLE_U_BLANK(tuple) \ | ||
104 | do { \ | ||
105 | (tuple)->src.u.all = 0; \ | ||
106 | (tuple)->dst.u.all = 0; \ | ||
107 | memset(&(tuple)->src.u3, 0, sizeof((tuple)->src.u3)); \ | ||
108 | memset(&(tuple)->dst.u3, 0, sizeof((tuple)->dst.u3)); \ | ||
109 | } while (0) | ||
110 | |||
111 | #ifdef __KERNEL__ | ||
112 | |||
113 | #define NF_CT_DUMP_TUPLE(tp) \ | ||
114 | DEBUGP("tuple %p: %u %u %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x %hu -> %04x:%04x:%04x:%04x:%04x:%04x:%04x:%04x %hu\n", \ | ||
115 | (tp), (tp)->src.l3num, (tp)->dst.protonum, \ | ||
116 | NIP6(*(struct in6_addr *)(tp)->src.u3.all), ntohs((tp)->src.u.all), \ | ||
117 | NIP6(*(struct in6_addr *)(tp)->dst.u3.all), ntohs((tp)->dst.u.all)) | ||
118 | |||
119 | /* If we're the first tuple, it's the original dir. */ | ||
120 | #define NF_CT_DIRECTION(h) \ | ||
121 | ((enum ip_conntrack_dir)(h)->tuple.dst.dir) | ||
122 | |||
123 | /* Connections have two entries in the hash table: one for each way */ | ||
124 | struct nf_conntrack_tuple_hash | ||
125 | { | ||
126 | struct list_head list; | ||
127 | |||
128 | struct nf_conntrack_tuple tuple; | ||
129 | }; | ||
130 | |||
131 | #endif /* __KERNEL__ */ | ||
132 | |||
133 | static inline int nf_ct_tuple_src_equal(const struct nf_conntrack_tuple *t1, | ||
134 | const struct nf_conntrack_tuple *t2) | ||
135 | { | ||
136 | return (t1->src.u3.all[0] == t2->src.u3.all[0] && | ||
137 | t1->src.u3.all[1] == t2->src.u3.all[1] && | ||
138 | t1->src.u3.all[2] == t2->src.u3.all[2] && | ||
139 | t1->src.u3.all[3] == t2->src.u3.all[3] && | ||
140 | t1->src.u.all == t2->src.u.all && | ||
141 | t1->src.l3num == t2->src.l3num && | ||
142 | t1->dst.protonum == t2->dst.protonum); | ||
143 | } | ||
144 | |||
145 | static inline int nf_ct_tuple_dst_equal(const struct nf_conntrack_tuple *t1, | ||
146 | const struct nf_conntrack_tuple *t2) | ||
147 | { | ||
148 | return (t1->dst.u3.all[0] == t2->dst.u3.all[0] && | ||
149 | t1->dst.u3.all[1] == t2->dst.u3.all[1] && | ||
150 | t1->dst.u3.all[2] == t2->dst.u3.all[2] && | ||
151 | t1->dst.u3.all[3] == t2->dst.u3.all[3] && | ||
152 | t1->dst.u.all == t2->dst.u.all && | ||
153 | t1->src.l3num == t2->src.l3num && | ||
154 | t1->dst.protonum == t2->dst.protonum); | ||
155 | } | ||
156 | |||
157 | static inline int nf_ct_tuple_equal(const struct nf_conntrack_tuple *t1, | ||
158 | const struct nf_conntrack_tuple *t2) | ||
159 | { | ||
160 | return nf_ct_tuple_src_equal(t1, t2) && nf_ct_tuple_dst_equal(t1, t2); | ||
161 | } | ||
162 | |||
163 | static inline int nf_ct_tuple_mask_cmp(const struct nf_conntrack_tuple *t, | ||
164 | const struct nf_conntrack_tuple *tuple, | ||
165 | const struct nf_conntrack_tuple *mask) | ||
166 | { | ||
167 | int count = 0; | ||
168 | |||
169 | for (count = 0; count < NF_CT_TUPLE_L3SIZE; count++){ | ||
170 | if ((t->src.u3.all[count] ^ tuple->src.u3.all[count]) & | ||
171 | mask->src.u3.all[count]) | ||
172 | return 0; | ||
173 | } | ||
174 | |||
175 | for (count = 0; count < NF_CT_TUPLE_L3SIZE; count++){ | ||
176 | if ((t->dst.u3.all[count] ^ tuple->dst.u3.all[count]) & | ||
177 | mask->dst.u3.all[count]) | ||
178 | return 0; | ||
179 | } | ||
180 | |||
181 | if ((t->src.u.all ^ tuple->src.u.all) & mask->src.u.all || | ||
182 | (t->dst.u.all ^ tuple->dst.u.all) & mask->dst.u.all || | ||
183 | (t->src.l3num ^ tuple->src.l3num) & mask->src.l3num || | ||
184 | (t->dst.protonum ^ tuple->dst.protonum) & mask->dst.protonum) | ||
185 | return 0; | ||
186 | |||
187 | return 1; | ||
188 | } | ||
189 | |||
190 | #endif /* _NF_CONNTRACK_TUPLE_H */ | ||