aboutsummaryrefslogtreecommitdiffstats
path: root/net
diff options
context:
space:
mode:
Diffstat (limited to 'net')
-rw-r--r--net/netfilter/nf_conntrack_expect.c68
1 files changed, 68 insertions, 0 deletions
diff --git a/net/netfilter/nf_conntrack_expect.c b/net/netfilter/nf_conntrack_expect.c
index aa5903e4da11..68623ae778c8 100644
--- a/net/netfilter/nf_conntrack_expect.c
+++ b/net/netfilter/nf_conntrack_expect.c
@@ -196,6 +196,74 @@ struct nf_conntrack_expect *nf_conntrack_expect_alloc(struct nf_conn *me)
196 return new; 196 return new;
197} 197}
198 198
199void nf_conntrack_expect_init(struct nf_conntrack_expect *exp, int family,
200 union nf_conntrack_address *saddr,
201 union nf_conntrack_address *daddr,
202 u_int8_t proto, __be16 *src, __be16 *dst)
203{
204 int len;
205
206 if (family == AF_INET)
207 len = 4;
208 else
209 len = 16;
210
211 exp->flags = 0;
212 exp->expectfn = NULL;
213 exp->helper = NULL;
214 exp->tuple.src.l3num = family;
215 exp->tuple.dst.protonum = proto;
216 exp->mask.src.l3num = 0xFFFF;
217 exp->mask.dst.protonum = 0xFF;
218
219 if (saddr) {
220 memcpy(&exp->tuple.src.u3, saddr, len);
221 if (sizeof(exp->tuple.src.u3) > len)
222 /* address needs to be cleared for nf_ct_tuple_equal */
223 memset((void *)&exp->tuple.src.u3 + len, 0x00,
224 sizeof(exp->tuple.src.u3) - len);
225 memset(&exp->mask.src.u3, 0xFF, len);
226 if (sizeof(exp->mask.src.u3) > len)
227 memset((void *)&exp->mask.src.u3 + len, 0x00,
228 sizeof(exp->mask.src.u3) - len);
229 } else {
230 memset(&exp->tuple.src.u3, 0x00, sizeof(exp->tuple.src.u3));
231 memset(&exp->mask.src.u3, 0x00, sizeof(exp->mask.src.u3));
232 }
233
234 if (daddr) {
235 memcpy(&exp->tuple.dst.u3, daddr, len);
236 if (sizeof(exp->tuple.dst.u3) > len)
237 /* address needs to be cleared for nf_ct_tuple_equal */
238 memset((void *)&exp->tuple.dst.u3 + len, 0x00,
239 sizeof(exp->tuple.dst.u3) - len);
240 memset(&exp->mask.dst.u3, 0xFF, len);
241 if (sizeof(exp->mask.dst.u3) > len)
242 memset((void *)&exp->mask.dst.u3 + len, 0x00,
243 sizeof(exp->mask.dst.u3) - len);
244 } else {
245 memset(&exp->tuple.dst.u3, 0x00, sizeof(exp->tuple.dst.u3));
246 memset(&exp->mask.dst.u3, 0x00, sizeof(exp->mask.dst.u3));
247 }
248
249 if (src) {
250 exp->tuple.src.u.all = (__force u16)*src;
251 exp->mask.src.u.all = 0xFFFF;
252 } else {
253 exp->tuple.src.u.all = 0;
254 exp->mask.src.u.all = 0;
255 }
256
257 if (dst) {
258 exp->tuple.dst.u.all = (__force u16)*dst;
259 exp->mask.dst.u.all = 0xFFFF;
260 } else {
261 exp->tuple.dst.u.all = 0;
262 exp->mask.dst.u.all = 0;
263 }
264}
265EXPORT_SYMBOL_GPL(nf_conntrack_expect_init);
266
199void nf_conntrack_expect_put(struct nf_conntrack_expect *exp) 267void nf_conntrack_expect_put(struct nf_conntrack_expect *exp)
200{ 268{
201 if (atomic_dec_and_test(&exp->use)) 269 if (atomic_dec_and_test(&exp->use))