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