blob: 5ed33ea4718ef5a101689432825ebb1a48fcc0d9 [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
Daniel Borkmann308ac912015-08-08 21:40:01 +02007
Martin Josefsson77ab9cf2006-11-29 02:34:58 +01008#include <net/netfilter/nf_conntrack.h>
Daniel Borkmann308ac912015-08-08 21:40:01 +02009#include <net/netfilter/nf_conntrack_zones.h>
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010010
Patrick McHardya71c0852007-07-07 22:33:47 -070011extern unsigned int nf_ct_expect_hsize;
Patrick McHardyf264a7d2007-07-07 22:36:24 -070012extern unsigned int nf_ct_expect_max;
Florian Westphal0a93aae2016-05-06 00:51:49 +020013extern struct hlist_head *nf_ct_expect_hash;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010014
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000015struct nf_conntrack_expect {
Patrick McHardyb5605802007-07-07 22:35:56 -070016 /* Conntrack expectation list member */
17 struct hlist_node lnode;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010018
Patrick McHardya71c0852007-07-07 22:33:47 -070019 /* Hash member */
20 struct hlist_node hnode;
21
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010022 /* We expect this tuple, with the following mask */
Patrick McHardyd4156e82007-07-07 22:31:32 -070023 struct nf_conntrack_tuple tuple;
24 struct nf_conntrack_tuple_mask mask;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010025
26 /* Function to call after setup and insertion */
27 void (*expectfn)(struct nf_conn *new,
28 struct nf_conntrack_expect *this);
29
Patrick McHardy9457d852006-12-02 22:05:25 -080030 /* Helper to assign to new connection */
31 struct nf_conntrack_helper *helper;
32
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010033 /* 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
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010042 /* Flags */
43 unsigned int flags;
44
Patrick McHardy6002f2662008-03-25 20:09:15 -070045 /* Expectation class */
46 unsigned int class;
47
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010048#ifdef CONFIG_NF_NAT_NEEDED
Patrick McHardyc7232c92012-08-26 19:14:06 +020049 union nf_inet_addr saved_addr;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010050 /* This is the original per-proto part, used to map the
51 * expected connection the way the recipient expects. */
Jozsef Kadlecsik5b1158e2006-12-02 22:07:13 -080052 union nf_conntrack_man_proto saved_proto;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010053 /* Direction relative to the master connection. */
54 enum ip_conntrack_dir dir;
55#endif
Patrick McHardy7d0742d2008-01-31 04:38:19 -080056
57 struct rcu_head rcu;
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010058};
59
Alexey Dobriyan9b03f382008-10-08 11:35:03 +020060static inline struct net *nf_ct_exp_net(struct nf_conntrack_expect *exp)
61{
Alexey Dobriyan857b4092010-02-12 06:24:46 +010062 return nf_ct_net(exp->master);
Alexey Dobriyan9b03f382008-10-08 11:35:03 +020063}
64
Pablo Neira Ayuso3a8fc532012-01-15 16:34:08 +010065#define NF_CT_EXP_POLICY_NAME_LEN 16
66
Eric Dumazetfd2c3ef2009-11-03 03:26:03 +000067struct nf_conntrack_expect_policy {
Patrick McHardy6002f2662008-03-25 20:09:15 -070068 unsigned int max_expected;
69 unsigned int timeout;
Pablo Neira Ayuso3a8fc532012-01-15 16:34:08 +010070 char name[NF_CT_EXP_POLICY_NAME_LEN];
Patrick McHardy6002f2662008-03-25 20:09:15 -070071};
72
73#define NF_CT_EXPECT_CLASS_DEFAULT 0
74
Gao feng83b4dbe2013-01-21 22:10:25 +000075int nf_conntrack_expect_pernet_init(struct net *net);
76void nf_conntrack_expect_pernet_fini(struct net *net);
77
78int nf_conntrack_expect_init(void);
79void nf_conntrack_expect_fini(void);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010080
81struct nf_conntrack_expect *
Daniel Borkmann308ac912015-08-08 21:40:01 +020082__nf_ct_expect_find(struct net *net,
83 const struct nf_conntrack_zone *zone,
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010084 const struct nf_conntrack_tuple *tuple);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010085
86struct nf_conntrack_expect *
Daniel Borkmann308ac912015-08-08 21:40:01 +020087nf_ct_expect_find_get(struct net *net,
88 const struct nf_conntrack_zone *zone,
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010089 const struct nf_conntrack_tuple *tuple);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010090
91struct nf_conntrack_expect *
Daniel Borkmann308ac912015-08-08 21:40:01 +020092nf_ct_find_expectation(struct net *net,
93 const struct nf_conntrack_zone *zone,
Patrick McHardy5d0aa2c2010-02-15 18:13:33 +010094 const struct nf_conntrack_tuple *tuple);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +010095
Pablo Neira Ayusoebbf41d2010-10-19 10:19:06 +020096void nf_ct_unlink_expect_report(struct nf_conntrack_expect *exp,
Patrick McHardyec464e52013-04-17 06:47:08 +000097 u32 portid, int report);
Pablo Neira Ayusoebbf41d2010-10-19 10:19:06 +020098static inline void nf_ct_unlink_expect(struct nf_conntrack_expect *exp)
99{
100 nf_ct_unlink_expect_report(exp, 0, 0);
101}
102
Martin Josefsson77ab9cf2006-11-29 02:34:58 +0100103void nf_ct_remove_expectations(struct nf_conn *ct);
Patrick McHardy68236452007-07-07 22:30:49 -0700104void nf_ct_unexpect_related(struct nf_conntrack_expect *exp);
Martin Josefsson77ab9cf2006-11-29 02:34:58 +0100105
106/* Allocate space for an expectation: this is mandatory before calling
Patrick McHardy68236452007-07-07 22:30:49 -0700107 nf_ct_expect_related. You will have to call put afterwards. */
108struct nf_conntrack_expect *nf_ct_expect_alloc(struct nf_conn *me);
Jan Engelhardt76108ce2008-10-08 11:35:00 +0200109void nf_ct_expect_init(struct nf_conntrack_expect *, unsigned int, u_int8_t,
Patrick McHardy1d9d7522008-03-25 20:07:58 -0700110 const union nf_inet_addr *,
111 const union nf_inet_addr *,
112 u_int8_t, const __be16 *, const __be16 *);
Patrick McHardy68236452007-07-07 22:30:49 -0700113void nf_ct_expect_put(struct nf_conntrack_expect *exp);
Pablo Neira Ayuso19abb7b2008-11-18 11:56:20 +0100114int nf_ct_expect_related_report(struct nf_conntrack_expect *expect,
Patrick McHardyec464e52013-04-17 06:47:08 +0000115 u32 portid, int report);
Pablo Neira Ayuso83731672009-04-06 17:47:20 +0200116static inline int nf_ct_expect_related(struct nf_conntrack_expect *expect)
117{
118 return nf_ct_expect_related_report(expect, 0, 0);
119}
Martin Josefsson77ab9cf2006-11-29 02:34:58 +0100120
121#endif /*_NF_CONNTRACK_EXPECT_H*/
122