2 * connection tracking expectations.
5 #ifndef _NF_CONNTRACK_EXPECT_H
6 #define _NF_CONNTRACK_EXPECT_H
8 #include <linux/refcount.h>
10 #include <net/netfilter/nf_conntrack.h>
11 #include <net/netfilter/nf_conntrack_zones.h>
13 extern unsigned int nf_ct_expect_hsize;
14 extern unsigned int nf_ct_expect_max;
15 extern struct hlist_head *nf_ct_expect_hash;
17 struct nf_conntrack_expect {
18 /* Conntrack expectation list member */
19 struct hlist_node lnode;
22 struct hlist_node hnode;
24 /* We expect this tuple, with the following mask */
25 struct nf_conntrack_tuple tuple;
26 struct nf_conntrack_tuple_mask mask;
28 /* Function to call after setup and insertion */
29 void (*expectfn)(struct nf_conn *new,
30 struct nf_conntrack_expect *this);
32 /* Helper to assign to new connection */
33 struct nf_conntrack_helper *helper;
35 /* The conntrack of the master connection */
36 struct nf_conn *master;
38 /* Timer function; deletes the expectation. */
39 struct timer_list timeout;
47 /* Expectation class */
50 #ifdef CONFIG_NF_NAT_NEEDED
51 union nf_inet_addr saved_addr;
52 /* This is the original per-proto part, used to map the
53 * expected connection the way the recipient expects. */
54 union nf_conntrack_man_proto saved_proto;
55 /* Direction relative to the master connection. */
56 enum ip_conntrack_dir dir;
62 static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)
64 return nf_ct_net(exp->master);
67 #define NF_CT_EXP_POLICY_NAME_LEN 16
69 struct nf_conntrack_expect_policy {
70 unsigned int max_expected;
72 char name[NF_CT_EXP_POLICY_NAME_LEN];
75 #define NF_CT_EXPECT_CLASS_DEFAULT 0
76 #define NF_CT_EXPECT_MAX_CNT 255
78 int nf_conntrack_expect_pernet_init(struct net *net);
79 void nf_conntrack_expect_pernet_fini(struct net *net);
81 int nf_conntrack_expect_init(void);
82 void nf_conntrack_expect_fini(void);
84 struct nf_conntrack_expect *
85 __nf_ct_expect_find(struct net *net,
86 const struct nf_conntrack_zone *zone,
87 const struct nf_conntrack_tuple *tuple);
89 struct nf_conntrack_expect *
90 nf_ct_expect_find_get(struct net *net,
91 const struct nf_conntrack_zone *zone,
92 const struct nf_conntrack_tuple *tuple);
94 struct nf_conntrack_expect *
95 nf_ct_find_expectation(struct net *net,
96 const struct nf_conntrack_zone *zone,
97 const struct nf_conntrack_tuple *tuple);
99 void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
100 u32 portid, int report);
101 static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
103 nf_ct_unlink_expect_report(exp, 0, 0);
106 void nf_ct_remove_expectations(struct nf_conn *ct);
107 void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
108 bool nf_ct_remove_expect(struct nf_conntrack_expect *exp);
110 void nf_ct_expect_iterate_destroy(bool (*iter)(struct nf_conntrack_expect *e, void *data), void *data);
111 void nf_ct_expect_iterate_net(struct net *net,
112 bool (*iter)(struct nf_conntrack_expect *e, void *data),
113 void *data, u32 portid, int report);
115 /* Allocate space for an expectation: this is mandatory before calling
116 nf_ct_expect_related. You will have to call put afterwards. */
117 struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
118 void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
119 const union nf_inet_addr *,
120 const union nf_inet_addr *,
121 u_int8_t, const __be16 *, const __be16 *);
122 void nf_ct_expect_put(struct nf_conntrack_expect *exp);
123 int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
124 u32 portid, int report);
125 static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect)
127 return nf_ct_expect_related_report(expect, 0, 0);
130 #endif /*_NF_CONNTRACK_EXPECT_H*/