1 /* SPDX-License-Identifier: GPL-2.0 */
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.
7 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
8 * - generalize L3 protocol dependent part.
10 * Derived from include/linux/netfiter_ipv4/ip_conntrack_core.h
13 #ifndef _NF_CONNTRACK_CORE_H
14 #define _NF_CONNTRACK_CORE_H
16 #include <linux/netfilter.h>
17 #include <net/netfilter/nf_conntrack.h>
18 #include <net/netfilter/nf_conntrack_ecache.h>
19 #include <net/netfilter/nf_conntrack_l4proto.h>
21 /* This header is used to share core functionality between the
22 standalone connection tracking module, and the compatibility layer's use
23 of connection tracking. */
25 unsigned int nf_conntrack_in(struct sk_buff *skb,
26 const struct nf_hook_state *state);
28 int nf_conntrack_init_net(struct net *net);
29 void nf_conntrack_cleanup_net(struct net *net);
30 void nf_conntrack_cleanup_net_list(struct list_head *net_exit_list);
32 void nf_conntrack_proto_pernet_init(struct net *net);
34 int nf_conntrack_proto_init(void);
35 void nf_conntrack_proto_fini(void);
37 int nf_conntrack_init_start(void);
38 void nf_conntrack_cleanup_start(void);
40 void nf_conntrack_init_end(void);
41 void nf_conntrack_cleanup_end(void);
43 bool nf_ct_invert_tuple(struct nf_conntrack_tuple *inverse,
44 const struct nf_conntrack_tuple *orig);
46 /* Find a connection corresponding to a tuple. */
47 struct nf_conntrack_tuple_hash *
48 nf_conntrack_find_get(struct net *net,
49 const struct nf_conntrack_zone *zone,
50 const struct nf_conntrack_tuple *tuple);
52 int __nf_conntrack_confirm(struct sk_buff *skb);
54 /* Confirm a connection: returns NF_DROP if packet must be dropped. */
55 static inline int nf_conntrack_confirm(struct sk_buff *skb)
57 struct nf_conn *ct = (struct nf_conn *)skb_nfct(skb);
61 if (!nf_ct_is_confirmed(ct)) {
62 ret = __nf_conntrack_confirm(skb);
65 ct = (struct nf_conn *)skb_nfct(skb);
68 if (ret == NF_ACCEPT && nf_ct_ecache_exist(ct))
69 nf_ct_deliver_cached_events(ct);
74 unsigned int nf_confirm(struct sk_buff *skb, unsigned int protoff,
75 struct nf_conn *ct, enum ip_conntrack_info ctinfo);
77 void print_tuple(struct seq_file *s, const struct nf_conntrack_tuple *tuple,
78 const struct nf_conntrack_l4proto *proto);
80 #define CONNTRACK_LOCKS 1024
82 extern spinlock_t nf_conntrack_locks[CONNTRACK_LOCKS];
83 void nf_conntrack_lock(spinlock_t *lock);
85 extern spinlock_t nf_conntrack_expect_lock;
87 /* ctnetlink code shared by both ctnetlink and nf_conntrack_bpf */
89 #if (IS_BUILTIN(CONFIG_NF_CONNTRACK) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF)) || \
90 (IS_MODULE(CONFIG_NF_CONNTRACK) && IS_ENABLED(CONFIG_DEBUG_INFO_BTF_MODULES) || \
91 IS_ENABLED(CONFIG_NF_CT_NETLINK))
93 static inline void __nf_ct_set_timeout(struct nf_conn *ct, u64 timeout)
95 if (timeout > INT_MAX)
97 WRITE_ONCE(ct->timeout, nfct_time_stamp + (u32)timeout);
100 int __nf_ct_change_timeout(struct nf_conn *ct, u64 cta_timeout);
101 void __nf_ct_change_status(struct nf_conn *ct, unsigned long on, unsigned long off);
102 int nf_ct_change_status_common(struct nf_conn *ct, unsigned int status);
106 #endif /* _NF_CONNTRACK_CORE_H */