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