blob: 62e17d1319ff7423dbcf176815f04cecfcdf3371 [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. */
Joe Perches4e77be42013-09-23 11:37:48 -070023unsigned int nf_conntrack_in(struct net *net, u_int8_t pf, unsigned int hooknum,
24 struct sk_buff *skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080025
Joe Perches4e77be42013-09-23 11:37:48 -070026int nf_conntrack_init_net(struct net *net);
27void nf_conntrack_cleanup_net(struct net *net);
28void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080029
Joe Perches4e77be42013-09-23 11:37:48 -070030int nf_conntrack_proto_pernet_init(struct net *net);
31void nf_conntrack_proto_pernet_fini(struct net *net);
Gao feng04d87002013-01-21 22:10:32 +000032
Joe Perches4e77be42013-09-23 11:37:48 -070033int nf_conntrack_proto_init(void);
34void nf_conntrack_proto_fini(void);
Patrick McHardyac5357e2007-03-14 16:38:25 -070035
Joe Perches4e77be42013-09-23 11:37:48 -070036int nf_conntrack_init_start(void);
37void nf_conntrack_cleanup_start(void);
Gao fengf94161c2013-01-21 22:10:24 +000038
Joe Perches4e77be42013-09-23 11:37:48 -070039void nf_conntrack_init_end(void);
40void nf_conntrack_cleanup_end(void);
Pablo Neira Ayuso1e47ee82013-01-10 16:12:01 +010041
Joe Perches4e77be42013-09-23 11:37:48 -070042bool 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. Biedermana31f1ad2015-09-18 14:33:04 -050044 struct net *net,
Joe Perches4e77be42013-09-23 11:37:48 -070045 struct nf_conntrack_tuple *tuple,
46 const struct nf_conntrack_l3proto *l3proto,
47 const struct nf_conntrack_l4proto *l4proto);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080048
Joe Perches4e77be42013-09-23 11:37:48 -070049bool 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 Kozakai9fb9cbb2005-11-09 16:38:16 -080053
54/* Find a connection corresponding to a tuple. */
Joe Perches4e77be42013-09-23 11:37:48 -070055struct nf_conntrack_tuple_hash *
Daniel Borkmann308ac912015-08-08 21:40:01 +020056nf_conntrack_find_get(struct net *net,
57 const struct nf_conntrack_zone *zone,
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010058 const struct nf_conntrack_tuple *tuple);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080059
Joe Perches4e77be42013-09-23 11:37:48 -070060int __nf_conntrack_confirm(struct sk_buff *skb);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080061
62/* Confirm a connection: returns NF_DROP if packet must be dropped. */
Herbert Xu3db05fe2007-10-15 00:53:15 -070063static inline int nf_conntrack_confirm(struct sk_buff *skb)
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080064{
Herbert Xu3db05fe2007-10-15 00:53:15 -070065 struct nf_conn *ct = (struct nf_conn *)skb->nfct;
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080066 int ret = NF_ACCEPT;
67
Eric Dumazet5bfddbd2010-06-08 16:09:52 +020068 if (ct && !nf_ct_is_untracked(ct)) {
Joerg Marxfc350772010-05-20 15:55:30 +020069 if (!nf_ct_is_confirmed(ct))
Herbert Xu3db05fe2007-10-15 00:53:15 -070070 ret = __nf_conntrack_confirm(skb);
Pablo Neira Ayusob1e93a62009-03-16 15:06:42 +010071 if (likely(ret == NF_ACCEPT))
72 nf_ct_deliver_cached_events(ct);
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080073 }
74 return ret;
75}
76
Joe Perches824f1fb2014-09-29 16:08:22 -070077void
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010078print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
Jan Engelhardt32948582008-01-31 04:53:24 -080079 const struct nf_conntrack_l3proto *l3proto,
80 const struct nf_conntrack_l4proto *proto);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010081
Sasha Levinb16c2912016-01-18 19:23:51 -050082#define CONNTRACK_LOCKS 1024
83
Jesper Dangaard Brouer93bb0ce2014-03-03 14:46:13 +010084extern spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];
Sasha Levinb16c2912016-01-18 19:23:51 -050085void nf_conntrack_lock(spinlock_t *lock);
Martin Josefsson7e5d03b2006-11-29 02:34:59 +010086
Jesper Dangaard Brouerca7433d2014-03-03 14:46:01 +010087extern spinlock_t nf_conntrack_expect_lock;
88
Yasuyuki Kozakai9fb9cbb2005-11-09 16:38:16 -080089#endif /* _NF_CONNTRACK_CORE_H */