917e170fa75269e25908b81aff9a0af6d69ec96c
[safe/jmp/linux-2.6] / 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 #include <net/netfilter/nf_conntrack.h>
8
9 extern unsigned int nf_ct_expect_hsize;
10 extern unsigned int nf_ct_expect_max;
11
12 struct nf_conntrack_expect {
13         /* Conntrack expectation list member */
14         struct hlist_node lnode;
15
16         /* Hash member */
17         struct hlist_node hnode;
18
19         /* We expect this tuple, with the following mask */
20         struct nf_conntrack_tuple tuple;
21         struct nf_conntrack_tuple_mask mask;
22
23         /* Function to call after setup and insertion */
24         void (*expectfn)(struct nf_conn *new,
25                          struct nf_conntrack_expect *this);
26
27         /* Helper to assign to new connection */
28         struct nf_conntrack_helper *helper;
29
30         /* The conntrack of the master connection */
31         struct nf_conn *master;
32
33         /* Timer function; deletes the expectation. */
34         struct timer_list timeout;
35
36         /* Usage count. */
37         atomic_t use;
38
39         /* Flags */
40         unsigned int flags;
41
42         /* Expectation class */
43         unsigned int class;
44
45 #ifdef CONFIG_NF_NAT_NEEDED
46         __be32 saved_ip;
47         /* This is the original per-proto part, used to map the
48          * expected connection the way the recipient expects. */
49         union nf_conntrack_man_proto saved_proto;
50         /* Direction relative to the master connection. */
51         enum ip_conntrack_dir dir;
52 #endif
53
54         struct rcu_head rcu;
55 };
56
57 static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)
58 {
59 #ifdef CONFIG_NET_NS
60         return exp->master->ct_net;     /* by definition */
61 #else
62         return &init_net;
63 #endif
64 }
65
66 struct nf_conntrack_expect_policy {
67         unsigned int    max_expected;
68         unsigned int    timeout;
69         const char      *name;
70 };
71
72 #define NF_CT_EXPECT_CLASS_DEFAULT      0
73
74 #define NF_CT_EXPECT_PERMANENT  0x1
75 #define NF_CT_EXPECT_INACTIVE   0x2
76
77 int nf_conntrack_expect_init(struct net *net);
78 void nf_conntrack_expect_fini(struct net *net);
79
80 struct nf_conntrack_expect *
81 __nf_ct_expect_find(struct net *net, const struct nf_conntrack_tuple *tuple);
82
83 struct nf_conntrack_expect *
84 nf_ct_expect_find_get(struct net *net, const struct nf_conntrack_tuple *tuple);
85
86 struct nf_conntrack_expect *
87 nf_ct_find_expectation(struct net *net, const struct nf_conntrack_tuple *tuple);
88
89 void nf_ct_unlink_expect(struct nf_conntrack_expect *exp);
90 void nf_ct_remove_expectations(struct nf_conn *ct);
91 void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
92
93 /* Allocate space for an expectation: this is mandatory before calling
94    nf_ct_expect_related.  You will have to call put afterwards. */
95 struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
96 void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
97                        const union nf_inet_addr *,
98                        const union nf_inet_addr *,
99                        u_int8_t, const __be16 *, const __be16 *);
100 void nf_ct_expect_put(struct nf_conntrack_expect *exp);
101 int nf_ct_expect_related_report(struct nf_conntrack_expect *expect, 
102                                 u32 pid, int report);
103 static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect)
104 {
105         return nf_ct_expect_related_report(expect, 0, 0);
106 }
107
108 #endif /*_NF_CONNTRACK_EXPECT_H*/
109