]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - include/net/netfilter/nf_conntrack_expect.h
Merge branch 'kvm-insert-lfence' into kvm-master
[mirror_ubuntu-bionic-kernel.git] / include / net / netfilter / nf_conntrack_expect.h
CommitLineData
b2441318 1/* SPDX-License-Identifier: GPL-2.0 */
77ab9cff
MJ
2/*
3 * connection tracking expectations.
4 */
5
6#ifndef _NF_CONNTRACK_EXPECT_H
7#define _NF_CONNTRACK_EXPECT_H
308ac914 8
b54ab92b
RE
9#include <linux/refcount.h>
10
77ab9cff 11#include <net/netfilter/nf_conntrack.h>
308ac914 12#include <net/netfilter/nf_conntrack_zones.h>
77ab9cff 13
a71c0855 14extern unsigned int nf_ct_expect_hsize;
f264a7df 15extern unsigned int nf_ct_expect_max;
0a93aaed 16extern struct hlist_head *nf_ct_expect_hash;
77ab9cff 17
fd2c3ef7 18struct nf_conntrack_expect {
b560580a
PM
19 /* Conntrack expectation list member */
20 struct hlist_node lnode;
77ab9cff 21
a71c0855
PM
22 /* Hash member */
23 struct hlist_node hnode;
24
77ab9cff 25 /* We expect this tuple, with the following mask */
d4156e8c
PM
26 struct nf_conntrack_tuple tuple;
27 struct nf_conntrack_tuple_mask mask;
77ab9cff
MJ
28
29 /* Function to call after setup and insertion */
30 void (*expectfn)(struct nf_conn *new,
31 struct nf_conntrack_expect *this);
32
9457d851
PM
33 /* Helper to assign to new connection */
34 struct nf_conntrack_helper *helper;
35
77ab9cff
MJ
36 /* The conntrack of the master connection */
37 struct nf_conn *master;
38
39 /* Timer function; deletes the expectation. */
40 struct timer_list timeout;
41
42 /* Usage count. */
b54ab92b 43 refcount_t use;
77ab9cff 44
77ab9cff
MJ
45 /* Flags */
46 unsigned int flags;
47
6002f266
PM
48 /* Expectation class */
49 unsigned int class;
50
77ab9cff 51#ifdef CONFIG_NF_NAT_NEEDED
c7232c99 52 union nf_inet_addr saved_addr;
77ab9cff
MJ
53 /* This is the original per-proto part, used to map the
54 * expected connection the way the recipient expects. */
5b1158e9 55 union nf_conntrack_man_proto saved_proto;
77ab9cff
MJ
56 /* Direction relative to the master connection. */
57 enum ip_conntrack_dir dir;
58#endif
7d0742da
PM
59
60 struct rcu_head rcu;
77ab9cff
MJ
61};
62
9b03f38d
AD
63static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)
64{
857b409a 65 return nf_ct_net(exp->master);
9b03f38d
AD
66}
67
3a8fc53a
PNA
68#define NF_CT_EXP_POLICY_NAME_LEN 16
69
fd2c3ef7 70struct nf_conntrack_expect_policy {
6002f266
PM
71 unsigned int max_expected;
72 unsigned int timeout;
3a8fc53a 73 char name[NF_CT_EXP_POLICY_NAME_LEN];
6002f266
PM
74};
75
76#define NF_CT_EXPECT_CLASS_DEFAULT 0
92f73221 77#define NF_CT_EXPECT_MAX_CNT 255
6002f266 78
83b4dbe1
G
79int nf_conntrack_expect_pernet_init(struct net *net);
80void nf_conntrack_expect_pernet_fini(struct net *net);
81
82int nf_conntrack_expect_init(void);
83void nf_conntrack_expect_fini(void);
77ab9cff
MJ
84
85struct nf_conntrack_expect *
308ac914
DB
86__nf_ct_expect_find(struct net *net,
87 const struct nf_conntrack_zone *zone,
5d0aa2cc 88 const struct nf_conntrack_tuple *tuple);
77ab9cff
MJ
89
90struct nf_conntrack_expect *
308ac914
DB
91nf_ct_expect_find_get(struct net *net,
92 const struct nf_conntrack_zone *zone,
5d0aa2cc 93 const struct nf_conntrack_tuple *tuple);
77ab9cff
MJ
94
95struct nf_conntrack_expect *
308ac914
DB
96nf_ct_find_expectation(struct net *net,
97 const struct nf_conntrack_zone *zone,
5d0aa2cc 98 const struct nf_conntrack_tuple *tuple);
77ab9cff 99
ebbf41df 100void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
ec464e5d 101 u32 portid, int report);
ebbf41df
PNA
102static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
103{
104 nf_ct_unlink_expect_report(exp, 0, 0);
105}
106
77ab9cff 107void nf_ct_remove_expectations(struct nf_conn *ct);
6823645d 108void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
ec0e3f01 109bool nf_ct_remove_expect(struct nf_conntrack_expect *exp);
77ab9cff 110
ac7b8483
FW
111void nf_ct_expect_iterate_destroy(bool (*iter)(struct nf_conntrack_expect *e, void *data), void *data);
112void nf_ct_expect_iterate_net(struct net *net,
113 bool (*iter)(struct nf_conntrack_expect *e, void *data),
114 void *data, u32 portid, int report);
115
77ab9cff 116/* Allocate space for an expectation: this is mandatory before calling
6823645d
PM
117 nf_ct_expect_related. You will have to call put afterwards. */
118struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
76108cea 119void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
1d9d7522
PM
120 const union nf_inet_addr *,
121 const union nf_inet_addr *,
122 u_int8_t, const __be16 *, const __be16 *);
6823645d 123void nf_ct_expect_put(struct nf_conntrack_expect *exp);
19abb7b0 124int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
ec464e5d 125 u32 portid, int report);
83731671
PNA
126static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect)
127{
128 return nf_ct_expect_related_report(expect, 0, 0);
129}
77ab9cff
MJ
130
131#endif /*_NF_CONNTRACK_EXPECT_H*/
132