blob: 3f3aecbc8632e935e16e6517bc23eb8e07a9b16d [file] [log] [blame]
Martin Josefsson77ab9cf2006-11-29 02:34:58 +01001/*
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
Patrick McHardya71c0852007-07-07 22:33:47 -07009extern unsigned int nf_ct_expect_hsize;
Patrick McHardyf264a7d2007-07-07 22:36:24 -070010extern unsigned int nf_ct_expect_max;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010011
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000012struct nf_conntrack_expect {
Patrick McHardyb5605802007-07-07 22:35:56 -070013 /* Conntrack expectation list member */
14 struct hlist_node lnode;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010015
Patrick McHardya71c0852007-07-07 22:33:47 -070016 /* Hash member */
17 struct hlist_node hnode;
18
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010019 /* We expect this tuple, with the following mask */
Patrick McHardyd4156e82007-07-07 22:31:32 -070020 struct nf_conntrack_tuple tuple;
21 struct nf_conntrack_tuple_mask mask;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010022
23 /* Function to call after setup and insertion */
24 void (*expectfn)(struct nf_conn *new,
25 struct nf_conntrack_expect *this);
26
Patrick McHardy9457d852006-12-02 22:05:25 -080027 /* Helper to assign to new connection */
28 struct nf_conntrack_helper *helper;
29
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010030 /* 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
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010039 /* Flags */
40 unsigned int flags;
41
Patrick McHardy6002f2662008-03-25 20:09:15 -070042 /* Expectation class */
43 unsigned int class;
44
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010045#ifdef CONFIG_NF_NAT_NEEDED
Patrick McHardyc7232c92012-08-26 19:14:06 +020046 union nf_inet_addr saved_addr;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010047 /* This is the original per-proto part, used to map the
48 * expected connection the way the recipient expects. */
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080049 union nf_conntrack_man_proto saved_proto;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010050 /* Direction relative to the master connection. */
51 enum ip_conntrack_dir dir;
52#endif
Patrick McHardy7d0742d2008-01-31 04:38:19 -080053
54 struct rcu_head rcu;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010055};
56
Alexey Dobriyan9b03f382008-10-08 11:35:03 +020057static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)
58{
Alexey Dobriyan857b4092010-02-12 06:24:46 +010059 return nf_ct_net(exp->master);
Alexey Dobriyan9b03f382008-10-08 11:35:03 +020060}
61
Pablo Neira Ayuso3a8fc532012-01-15 16:34:08 +010062#define NF_CT_EXP_POLICY_NAME_LEN 16
63
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000064struct nf_conntrack_expect_policy {
Patrick McHardy6002f2662008-03-25 20:09:15 -070065 unsigned int max_expected;
66 unsigned int timeout;
Pablo Neira Ayuso3a8fc532012-01-15 16:34:08 +010067 char name[NF_CT_EXP_POLICY_NAME_LEN];
Patrick McHardy6002f2662008-03-25 20:09:15 -070068};
69
70#define NF_CT_EXPECT_CLASS_DEFAULT 0
71
Gao feng83b4dbe2013-01-21 22:10:25 +000072int nf_conntrack_expect_pernet_init(struct net *net);
73void nf_conntrack_expect_pernet_fini(struct net *net);
74
75int nf_conntrack_expect_init(void);
76void nf_conntrack_expect_fini(void);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010077
78struct nf_conntrack_expect *
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010079__nf_ct_expect_find(struct net *net, u16 zone,
80 const struct nf_conntrack_tuple *tuple);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010081
82struct nf_conntrack_expect *
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010083nf_ct_expect_find_get(struct net *net, u16 zone,
84 const struct nf_conntrack_tuple *tuple);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010085
86struct nf_conntrack_expect *
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010087nf_ct_find_expectation(struct net *net, u16 zone,
88 const struct nf_conntrack_tuple *tuple);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010089
Pablo Neira Ayusoebbf41d2010-10-19 10:19:06 +020090void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
Patrick McHardyec464e52013-04-17 06:47:08 +000091 u32 portid, int report);
Pablo Neira Ayusoebbf41d2010-10-19 10:19:06 +020092static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
93{
94 nf_ct_unlink_expect_report(exp, 0, 0);
95}
96
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010097void nf_ct_remove_expectations(struct nf_conn *ct);
Patrick McHardy68236452007-07-07 22:30:49 -070098void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010099
100/* Allocate space for an expectation: this is mandatory before calling
Patrick McHardy68236452007-07-07 22:30:49 -0700101 nf_ct_expect_related. You will have to call put afterwards. */
102struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200103void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
Patrick McHardy1d9d7522008-03-25 20:07:58 -0700104 const union nf_inet_addr *,
105 const union nf_inet_addr *,
106 u_int8_t, const __be16 *, const __be16 *);
Patrick McHardy68236452007-07-07 22:30:49 -0700107void nf_ct_expect_put(struct nf_conntrack_expect *exp);
Pablo Neira Ayuso19abb7b2008-11-18 11:56:20 +0100108int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
Patrick McHardyec464e52013-04-17 06:47:08 +0000109 u32 portid, int report);
Pablo Neira Ayuso83731672009-04-06 17:47:20 +0200110static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect)
111{
112 return nf_ct_expect_related_report(expect, 0, 0);
113}
Martin Josefsson77ab9cf2006-11-29 02:34:58 +0100114
115#endif /*_NF_CONNTRACK_EXPECT_H*/
116