netfilter: don't setup nat info for confirmed ct
[linux-block.git] / include / net / netfilter / nf_conntrack_helper.h
CommitLineData
9fb9cbb1
YK
1/*
2 * connection tracking helpers.
3 *
4 * 16 Dec 2003: Yasuyuki Kozakai @USAGI <yasuyuki.kozakai@toshiba.co.jp>
5 * - generalize L3 protocol dependent part.
6 *
7 * Derived from include/linux/netfiter_ipv4/ip_conntrack_helper.h
8 */
9
10#ifndef _NF_CONNTRACK_HELPER_H
11#define _NF_CONNTRACK_HELPER_H
12#include <net/netfilter/nf_conntrack.h>
ceceae1b 13#include <net/netfilter/nf_conntrack_extend.h>
1afc5679 14#include <net/netfilter/nf_conntrack_expect.h>
9fb9cbb1
YK
15
16struct module;
17
12f7a505
PNA
18enum nf_ct_helper_flags {
19 NF_CT_HELPER_F_USERSPACE = (1 << 0),
20 NF_CT_HELPER_F_CONFIGURED = (1 << 1),
21};
22
af9d32ad
HE
23#define NF_CT_HELPER_NAME_LEN 16
24
fd2c3ef7 25struct nf_conntrack_helper {
b8a7fe6c 26 struct hlist_node hnode; /* Internal use. */
9fb9cbb1 27
3a8fc53a 28 char name[NF_CT_HELPER_NAME_LEN]; /* name of the module */
9fb9cbb1 29 struct module *me; /* pointer to self */
6002f266 30 const struct nf_conntrack_expect_policy *expect_policy;
9fb9cbb1 31
d4156e8c 32 /* Tuple of things we will help (compared against server response) */
9fb9cbb1 33 struct nf_conntrack_tuple tuple;
d4156e8c 34
9fb9cbb1
YK
35 /* Function to call when data passes; return verdict, or -1 to
36 invalidate. */
3db05fea 37 int (*help)(struct sk_buff *skb,
9fb9cbb1
YK
38 unsigned int protoff,
39 struct nf_conn *ct,
40 enum ip_conntrack_info conntrackinfo);
c1d10adb 41
f09943fe
PM
42 void (*destroy)(struct nf_conn *ct);
43
ae243bee 44 int (*from_nlattr)(struct nlattr *attr, struct nf_conn *ct);
fdf70832 45 int (*to_nlattr)(struct sk_buff *skb, const struct nf_conn *ct);
6002f266 46 unsigned int expect_class_max;
12f7a505
PNA
47
48 unsigned int flags;
9f0f3ebe
FW
49
50 /* For user-space helpers: */
51 unsigned int queue_num;
52 /* length of userspace private data stored in nf_conn_help->data */
53 u16 data_len;
9fb9cbb1
YK
54};
55
906535b0
FW
56/* Must be kept in sync with the classes defined by helpers */
57#define NF_CT_MAX_EXPECT_CLASSES 4
58
59/* nf_conn feature for connections that have a helper */
60struct nf_conn_help {
61 /* Helper. if any */
62 struct nf_conntrack_helper __rcu *helper;
63
64 struct hlist_head expectations;
65
66 /* Current number of expected connections */
67 u8 expecting[NF_CT_MAX_EXPECT_CLASSES];
68
69 /* private helper information. */
dcf67740 70 char data[32] __aligned(8);
906535b0
FW
71};
72
dcf67740
FW
73#define NF_CT_HELPER_BUILD_BUG_ON(structsize) \
74 BUILD_BUG_ON((structsize) > FIELD_SIZEOF(struct nf_conn_help, data))
75
4e77be46
JP
76struct nf_conntrack_helper *__nf_conntrack_helper_find(const char *name,
77 u16 l3num, u8 protonum);
7e5d03bb 78
4e77be46
JP
79struct nf_conntrack_helper *nf_conntrack_helper_try_module_get(const char *name,
80 u16 l3num,
81 u8 protonum);
82de0be6
GF
82void nf_ct_helper_init(struct nf_conntrack_helper *helper,
83 u16 l3num, u16 protonum, const char *name,
84 u16 default_port, u16 spec_port, u32 id,
85 const struct nf_conntrack_expect_policy *exp_pol,
9f0f3ebe 86 u32 expect_class_max,
82de0be6
GF
87 int (*help)(struct sk_buff *skb, unsigned int protoff,
88 struct nf_conn *ct,
89 enum ip_conntrack_info ctinfo),
90 int (*from_nlattr)(struct nlattr *attr,
91 struct nf_conn *ct),
92 struct module *module);
84f3bb9a 93
4e77be46
JP
94int nf_conntrack_helper_register(struct nf_conntrack_helper *);
95void nf_conntrack_helper_unregister(struct nf_conntrack_helper *);
9fb9cbb1 96
82de0be6
GF
97int nf_conntrack_helpers_register(struct nf_conntrack_helper *, unsigned int);
98void nf_conntrack_helpers_unregister(struct nf_conntrack_helper *,
99 unsigned int);
100
4e77be46
JP
101struct nf_conn_help *nf_ct_helper_ext_add(struct nf_conn *ct,
102 struct nf_conntrack_helper *helper,
103 gfp_t gfp);
b560580a 104
4e77be46
JP
105int __nf_ct_try_assign_helper(struct nf_conn *ct, struct nf_conn *tmpl,
106 gfp_t flags);
226c0c0e 107
4e77be46 108void nf_ct_helper_destroy(struct nf_conn *ct);
9858a3ae 109
ceceae1b
YK
110static inline struct nf_conn_help *nfct_help(const struct nf_conn *ct)
111{
112 return nf_ct_ext_find(ct, NF_CT_EXT_HELPER);
113}
b334aadc 114
1afc5679
PNA
115static inline void *nfct_help_data(const struct nf_conn *ct)
116{
117 struct nf_conn_help *help;
118
119 help = nf_ct_ext_find(ct, NF_CT_EXT_HELPER);
120
121 return (void *)help->data;
122}
123
4e77be46
JP
124int nf_conntrack_helper_pernet_init(struct net *net);
125void nf_conntrack_helper_pernet_fini(struct net *net);
5e615b22 126
4e77be46
JP
127int nf_conntrack_helper_init(void);
128void nf_conntrack_helper_fini(void);
b334aadc 129
4e77be46
JP
130int nf_conntrack_broadcast_help(struct sk_buff *skb, unsigned int protoff,
131 struct nf_conn *ct,
132 enum ip_conntrack_info ctinfo,
133 unsigned int timeout);
93557f53 134
544d5c7d
PNA
135struct nf_ct_helper_expectfn {
136 struct list_head head;
137 const char *name;
138 void (*expectfn)(struct nf_conn *ct, struct nf_conntrack_expect *exp);
139};
140
b20ab9cc
PNA
141__printf(3,4)
142void nf_ct_helper_log(struct sk_buff *skb, const struct nf_conn *ct,
143 const char *fmt, ...);
144
544d5c7d
PNA
145void nf_ct_helper_expectfn_register(struct nf_ct_helper_expectfn *n);
146void nf_ct_helper_expectfn_unregister(struct nf_ct_helper_expectfn *n);
147struct nf_ct_helper_expectfn *
148nf_ct_helper_expectfn_find_by_name(const char *name);
149struct nf_ct_helper_expectfn *
150nf_ct_helper_expectfn_find_by_symbol(const void *symbol);
151
12f7a505
PNA
152extern struct hlist_head *nf_ct_helper_hash;
153extern unsigned int nf_ct_helper_hsize;
154
9fb9cbb1 155#endif /*_NF_CONNTRACK_HELPER_H*/