GNU Linux-libre 4.9.309-gnu1
[releases.git] / include / net / netfilter / nf_conntrack_expect.h
1 /*
2  * connection tracking expectations.
3  */
4
5 #ifndef _NF_CONNTRACK_EXPECT_H
6 #define _NF_CONNTRACK_EXPECT_H
7
8 #include <net/netfilter/nf_conntrack.h>
9 #include <net/netfilter/nf_conntrack_zones.h>
10
11 extern unsigned int nf_ct_expect_hsize;
12 extern unsigned int nf_ct_expect_max;
13 extern struct hlist_head *nf_ct_expect_hash;
14
15 struct nf_conntrack_expect {
16         /* Conntrack expectation list member */
17         struct hlist_node lnode;
18
19         /* Hash member */
20         struct hlist_node hnode;
21
22         /* We expect this tuple, with the following mask */
23         struct nf_conntrack_tuple tuple;
24         struct nf_conntrack_tuple_mask mask;
25
26         /* Function to call after setup and insertion */
27         void (*expectfn)(struct nf_conn *new,
28                          struct nf_conntrack_expect *this);
29
30         /* Helper to assign to new connection */
31         struct nf_conntrack_helper *helper;
32
33         /* The conntrack of the master connection */
34         struct nf_conn *master;
35
36         /* Timer function; deletes the expectation. */
37         struct timer_list timeout;
38
39         /* Usage count. */
40         atomic_t use;
41
42         /* Flags */
43         unsigned int flags;
44
45         /* Expectation class */
46         unsigned int class;
47
48 #ifdef CONFIG_NF_NAT_NEEDED
49         union nf_inet_addr saved_addr;
50         /* This is the original per-proto part, used to map the
51          * expected connection the way the recipient expects. */
52         union nf_conntrack_man_proto saved_proto;
53         /* Direction relative to the master connection. */
54         enum ip_conntrack_dir dir;
55 #endif
56
57         struct rcu_head rcu;
58 };
59
60 static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)
61 {
62         return nf_ct_net(exp->master);
63 }
64
65 #define NF_CT_EXP_POLICY_NAME_LEN       16
66
67 struct nf_conntrack_expect_policy {
68         unsigned int    max_expected;
69         unsigned int    timeout;
70         char            name[NF_CT_EXP_POLICY_NAME_LEN];
71 };
72
73 #define NF_CT_EXPECT_CLASS_DEFAULT      0
74
75 int nf_conntrack_expect_pernet_init(struct net *net);
76 void nf_conntrack_expect_pernet_fini(struct net *net);
77
78 int nf_conntrack_expect_init(void);
79 void nf_conntrack_expect_fini(void);
80
81 struct nf_conntrack_expect *
82 __nf_ct_expect_find(struct net *net,
83                     const struct nf_conntrack_zone *zone,
84                     const struct nf_conntrack_tuple *tuple);
85
86 struct nf_conntrack_expect *
87 nf_ct_expect_find_get(struct net *net,
88                       const struct nf_conntrack_zone *zone,
89                       const struct nf_conntrack_tuple *tuple);
90
91 struct nf_conntrack_expect *
92 nf_ct_find_expectation(struct net *net,
93                        const struct nf_conntrack_zone *zone,
94                        const struct nf_conntrack_tuple *tuple);
95
96 void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
97                                 u32 portid, int report);
98 static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
99 {
100         nf_ct_unlink_expect_report(exp, 0, 0);
101 }
102
103 void nf_ct_remove_expectations(struct nf_conn *ct);
104 void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
105
106 /* Allocate space for an expectation: this is mandatory before calling
107    nf_ct_expect_related.  You will have to call put afterwards. */
108 struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
109 void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
110                        const union nf_inet_addr *,
111                        const union nf_inet_addr *,
112                        u_int8_t, const __be16 *, const __be16 *);
113 void nf_ct_expect_put(struct nf_conntrack_expect *exp);
114 int nf_ct_expect_related_report(struct nf_conntrack_expect *expect, 
115                                 u32 portid, int report);
116 static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect)
117 {
118         return nf_ct_expect_related_report(expect, 0, 0);
119 }
120
121 #endif /*_NF_CONNTRACK_EXPECT_H*/
122