Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 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> |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 16 | #include <net/netfilter/nf_conntrack_l3proto.h> |
Martin Josefsson | 605dcad | 2006-11-29 02:35:06 +0100 | [diff] [blame] | 17 | #include <net/netfilter/nf_conntrack_l4proto.h> |
Martin Josefsson | f618012 | 2006-11-29 02:35:01 +0100 | [diff] [blame] | 18 | #include <net/netfilter/nf_conntrack_ecache.h> |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 19 | |
| 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. */ |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 23 | unsigned int nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum, |
| 24 | struct sk_buff *skb); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 25 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 26 | int nf_conntrack_init_net(struct net *net); |
| 27 | void nf_conntrack_cleanup_net(struct net *net); |
| 28 | void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 29 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 30 | int nf_conntrack_proto_pernet_init(struct net *net); |
| 31 | void nf_conntrack_proto_pernet_fini(struct net *net); |
Gao feng | 04d8700 | 2013-01-21 22:10:32 +0000 | [diff] [blame] | 32 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 33 | int nf_conntrack_proto_init(void); |
| 34 | void nf_conntrack_proto_fini(void); |
Patrick McHardy | ac5357e | 2007-03-14 16:38:25 -0700 | [diff] [blame] | 35 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 36 | int nf_conntrack_init_start(void); |
| 37 | void nf_conntrack_cleanup_start(void); |
Gao feng | f94161c | 2013-01-21 22:10:24 +0000 | [diff] [blame] | 38 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 39 | void nf_conntrack_init_end(void); |
| 40 | void nf_conntrack_cleanup_end(void); |
Pablo Neira Ayuso | 1e47ee8 | 2013-01-10 16:12:01 +0100 | [diff] [blame] | 41 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 42 | bool nf_ct_get_tuple(const struct sk_buff *skb, unsigned int nhoff, |
| 43 | unsigned int dataoff, u_int16_t l3num, u_int8_t protonum, |
Eric W. Biederman | a31f1ad | 2015-09-18 14:33:04 -0500 | [diff] [blame] | 44 | struct net *net, |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 45 | struct nf_conntrack_tuple *tuple, |
| 46 | const struct nf_conntrack_l3proto *l3proto, |
| 47 | const struct nf_conntrack_l4proto *l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 48 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 49 | bool nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse, |
| 50 | const struct nf_conntrack_tuple *orig, |
| 51 | const struct nf_conntrack_l3proto *l3proto, |
| 52 | const struct nf_conntrack_l4proto *l4proto); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 53 | |
| 54 | /* Find a connection corresponding to a tuple. */ |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 55 | struct nf_conntrack_tuple_hash * |
Daniel Borkmann | 308ac91 | 2015-08-08 21:40:01 +0200 | [diff] [blame] | 56 | nf_conntrack_find_get(struct net *net, |
| 57 | const struct nf_conntrack_zone *zone, |
Patrick McHardy | 5d0aa2c | 2010-02-15 18:13:33 +0100 | [diff] [blame] | 58 | const struct nf_conntrack_tuple *tuple); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 59 | |
Joe Perches | 4e77be4 | 2013-09-23 11:37:48 -0700 | [diff] [blame] | 60 | int __nf_conntrack_confirm(struct sk_buff *skb); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 61 | |
| 62 | /* Confirm a connection: returns NF_DROP if packet must be dropped. */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 63 | static inline int nf_conntrack_confirm(struct sk_buff *skb) |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 64 | { |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 65 | struct nf_conn *ct = (struct nf_conn *)skb->nfct; |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 66 | int ret = NF_ACCEPT; |
| 67 | |
Eric Dumazet | 5bfddbd | 2010-06-08 16:09:52 +0200 | [diff] [blame] | 68 | if (ct && !nf_ct_is_untracked(ct)) { |
Joerg Marx | fc35077 | 2010-05-20 15:55:30 +0200 | [diff] [blame] | 69 | if (!nf_ct_is_confirmed(ct)) |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 70 | ret = __nf_conntrack_confirm(skb); |
Pablo Neira Ayuso | b1e93a6 | 2009-03-16 15:06:42 +0100 | [diff] [blame] | 71 | if (likely(ret == NF_ACCEPT)) |
| 72 | nf_ct_deliver_cached_events(ct); |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 73 | } |
| 74 | return ret; |
| 75 | } |
| 76 | |
Joe Perches | 824f1fb | 2014-09-29 16:08:22 -0700 | [diff] [blame] | 77 | void |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 78 | print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple, |
Jan Engelhardt | 3294858 | 2008-01-31 04:53:24 -0800 | [diff] [blame] | 79 | const struct nf_conntrack_l3proto *l3proto, |
| 80 | const struct nf_conntrack_l4proto *proto); |
Martin Josefsson | 77ab9cf | 2006-11-29 02:34:58 +0100 | [diff] [blame] | 81 | |
Sasha Levin | b16c291 | 2016-01-18 19:23:51 -0500 | [diff] [blame] | 82 | #define CONNTRACK_LOCKS 1024 |
| 83 | |
Jesper Dangaard Brouer | 93bb0ce | 2014-03-03 14:46:13 +0100 | [diff] [blame] | 84 | extern spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS]; |
Sasha Levin | b16c291 | 2016-01-18 19:23:51 -0500 | [diff] [blame] | 85 | void nf_conntrack_lock(spinlock_t *lock); |
Martin Josefsson | 7e5d03b | 2006-11-29 02:34:59 +0100 | [diff] [blame] | 86 | |
Jesper Dangaard Brouer | ca7433d | 2014-03-03 14:46:01 +0100 | [diff] [blame] | 87 | extern spinlock_t nf_conntrack_expect_lock; |
| 88 | |
Yasuyuki Kozakai | 9fb9cbb | 2005-11-09 16:38:16 -0800 | [diff] [blame] | 89 | #endif /* _NF_CONNTRACK_CORE_H */ |