1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  * This header is used to share core functionality between the
4  * standalone connection tracking module, and the compatibility layer's use
5  * of connection tracking.
6  *
7  * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
8  *	- generalize L3 protocol dependent part.
9  *
10  * Derived from include/linux/netfiter_ipv4/ip_conntrack_core.h
11  */
12 
13 #ifndef _NF_CONNTRACK_CORE_H
14 #define _NF_CONNTRACK_CORE_H
15 
16 #include <linux/netfilter.h>
17 #include <net/netfilter/nf_conntrack_l4proto.h>
18 #include <net/netfilter/nf_conntrack_ecache.h>
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. */
23 unsigned int nf_conntrack_in(struct sk_buff *skb, const struct nf_hook_state *state);
24 
25 int nf_conntrack_init_net(struct net *net);
26 void nf_conntrack_cleanup_net(struct net *net);
27 void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list);
28 
29 int nf_conntrack_proto_pernet_init(struct net *net);
30 void nf_conntrack_proto_pernet_fini(struct net *net);
31 
32 int nf_conntrack_proto_init(void);
33 void nf_conntrack_proto_fini(void);
34 
35 int nf_conntrack_init_start(void);
36 void nf_conntrack_cleanup_start(void);
37 
38 void nf_conntrack_init_end(void);
39 void nf_conntrack_cleanup_end(void);
40 
41 bool nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
42 			const struct nf_conntrack_tuple *orig);
43 
44 /* Find a connection corresponding to a tuple. */
45 struct nf_conntrack_tuple_hash *
46 nf_conntrack_find_get(struct net *net,
47 		      const struct nf_conntrack_zone *zone,
48 		      const struct nf_conntrack_tuple *tuple);
49 
50 int __nf_conntrack_confirm(struct sk_buff *skb);
51 
52 /* Confirm a connection: returns NF_DROP if packet must be dropped. */
53 static inline int nf_conntrack_confirm(struct sk_buff *skb)
54 {
55 	struct nf_conn *ct = (struct nf_conn *)skb_nfct(skb);
56 	int ret = NF_ACCEPT;
57 
58 	if (ct) {
59 		if (!nf_ct_is_confirmed(ct))
60 			ret = __nf_conntrack_confirm(skb);
61 		if (likely(ret == NF_ACCEPT))
62 			nf_ct_deliver_cached_events(ct);
63 	}
64 	return ret;
65 }
66 
67 void print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
68 		 const struct nf_conntrack_l4proto *proto);
69 
70 #define CONNTRACK_LOCKS 1024
71 
72 extern spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];
73 void nf_conntrack_lock(spinlock_t *lock);
74 
75 extern spinlock_t nf_conntrack_expect_lock;
76 
77 #endif /* _NF_CONNTRACK_CORE_H */
78