blob: 5a449b44ba33255f4acebc28879a37ae7e3ab3bd [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 *
Alexey Dobriyan400dad32008-10-08 11:35:03 +020052nf_conntrack_find_get(struct net *net, const struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080053
Herbert Xu3db05fe2007-10-15 00:53:15 -070054extern int __nf_conntrack_confirm(struct sk_buff *skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080055
56/* Confirm a connection: returns NF_DROP if packet must be dropped. */
Herbert Xu3db05fe2007-10-15 00:53:15 -070057static inline int nf_conntrack_confirm(struct sk_buff *skb)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080058{
Herbert Xu3db05fe2007-10-15 00:53:15 -070059 struct nf_conn *ct = (struct nf_conn *)skb->nfct;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080060 int ret = NF_ACCEPT;
61
Patrick McHardy5962fc62009-02-18 15:30:34 +010062 if (ct && ct != &nf_conntrack_untracked) {
Patrick McHardyec68e972007-03-04 15:57:01 -080063 if (!nf_ct_is_confirmed(ct) && !nf_ct_is_dying(ct))
Herbert Xu3db05fe2007-10-15 00:53:15 -070064 ret = __nf_conntrack_confirm(skb);
Pablo Neira Ayusob1e93a62009-03-16 15:06:42 +010065 if (likely(ret == NF_ACCEPT))
66 nf_ct_deliver_cached_events(ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080067 }
68 return ret;
69}
70
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010071int
72print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
Jan Engelhardt32948582008-01-31 04:53:24 -080073 const struct nf_conntrack_l3proto *l3proto,
74 const struct nf_conntrack_l4proto *proto);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010075
Patrick McHardyf8ba1af2008-01-31 04:38:58 -080076extern spinlock_t nf_conntrack_lock ;
Martin Josefsson7e5d03b2006-11-29 02:34:59 +010077
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080078#endif /* _NF_CONNTRACK_CORE_H */