blob: aced085132e7e52591f05ba1f1529dbba420465b [file] [log] [blame]
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -08001/*
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>
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010016#include <net/netfilter/nf_conntrack_l3proto.h>
Martin Josefsson605dcad2006-11-29 02:35:06 +010017#include <net/netfilter/nf_conntrack_l4proto.h>
Martin Josefssonf6180122006-11-29 02:35:01 +010018#include <net/netfilter/nf_conntrack_ecache.h>
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080019
20/* This header is used to share core functionality between the
21 standalone connection tracking module, and the compatibility layer's use
22 of connection tracking. */
Alexey Dobriyana702a652008-10-08 11:35:04 +020023extern unsigned int nf_conntrack_in(struct net *net,
24 u_int8_t pf,
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080025 unsigned int hooknum,
Herbert Xu3db05fe2007-10-15 00:53:15 -070026 struct sk_buff *skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080027
Alexey Dobriyandfdb8d72008-10-08 11:35:02 +020028extern int nf_conntrack_init(struct net *net);
29extern void nf_conntrack_cleanup(struct net *net);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080030
Patrick McHardyac5357e2007-03-14 16:38:25 -070031extern int nf_conntrack_proto_init(void);
32extern void nf_conntrack_proto_fini(void);
33
Jan Engelhardt5f2b4c92008-04-14 11:15:53 +020034extern bool
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080035nf_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,
Martin Josefsson605dcad2006-11-29 02:35:06 +010042 const struct nf_conntrack_l4proto *l4proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080043
Jan Engelhardt5f2b4c92008-04-14 11:15:53 +020044extern bool
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080045nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
46 const struct nf_conntrack_tuple *orig,
47 const struct nf_conntrack_l3proto *l3proto,
Martin Josefsson605dcad2006-11-29 02:35:06 +010048 const struct nf_conntrack_l4proto *l4proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080049
50/* Find a connection corresponding to a tuple. */
51extern struct nf_conntrack_tuple_hash *
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010052nf_conntrack_find_get(struct net *net, u16 zone,
53 const struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080054
Herbert Xu3db05fe2007-10-15 00:53:15 -070055extern int __nf_conntrack_confirm(struct sk_buff *skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080056
57/* Confirm a connection: returns NF_DROP if packet must be dropped. */
Herbert Xu3db05fe2007-10-15 00:53:15 -070058static inline int nf_conntrack_confirm(struct sk_buff *skb)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080059{
Herbert Xu3db05fe2007-10-15 00:53:15 -070060 struct nf_conn *ct = (struct nf_conn *)skb->nfct;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080061 int ret = NF_ACCEPT;
62
Eric Dumazet5bfddbd2010-06-08 16:09:52 +020063 if (ct && !nf_ct_is_untracked(ct)) {
Joerg Marxfc350772010-05-20 15:55:30 +020064 if (!nf_ct_is_confirmed(ct))
Herbert Xu3db05fe2007-10-15 00:53:15 -070065 ret = __nf_conntrack_confirm(skb);
Pablo Neira Ayusob1e93a62009-03-16 15:06:42 +010066 if (likely(ret == NF_ACCEPT))
67 nf_ct_deliver_cached_events(ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080068 }
69 return ret;
70}
71
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010072int
73print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
Jan Engelhardt32948582008-01-31 04:53:24 -080074 const struct nf_conntrack_l3proto *l3proto,
75 const struct nf_conntrack_l4proto *proto);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010076
Patrick McHardyf8ba1af2008-01-31 04:38:58 -080077extern spinlock_t nf_conntrack_lock ;
Martin Josefsson7e5d03b2006-11-29 02:34:59 +010078
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080079#endif /* _NF_CONNTRACK_CORE_H */