netfilter: cttimeout: decouple timeout policy from nfnetlink_cttimeout object
[linux-block.git] / net / netfilter / nf_conntrack_timeout.c
CommitLineData
dd705072
PNA
1/*
2 * (C) 2012 by Pablo Neira Ayuso <pablo@netfilter.org>
3 * (C) 2012 by Vyatta Inc. <http://www.vyatta.com>
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation (or any later at your option).
8 */
9
10#include <linux/types.h>
11#include <linux/netfilter.h>
12#include <linux/skbuff.h>
13#include <linux/vmalloc.h>
14#include <linux/stddef.h>
15#include <linux/err.h>
16#include <linux/percpu.h>
17#include <linux/kernel.h>
18#include <linux/netdevice.h>
19#include <linux/slab.h>
20#include <linux/export.h>
21
22#include <net/netfilter/nf_conntrack.h>
23#include <net/netfilter/nf_conntrack_core.h>
24#include <net/netfilter/nf_conntrack_extend.h>
25#include <net/netfilter/nf_conntrack_timeout.h>
26
6c1fd7dc 27struct nf_ct_timeout *
19576c94 28(*nf_ct_timeout_find_get_hook)(struct net *net, const char *name) __read_mostly;
dd705072
PNA
29EXPORT_SYMBOL_GPL(nf_ct_timeout_find_get_hook);
30
6c1fd7dc 31void (*nf_ct_timeout_put_hook)(struct nf_ct_timeout *timeout) __read_mostly;
dd705072
PNA
32EXPORT_SYMBOL_GPL(nf_ct_timeout_put_hook);
33
4e665afb
HS
34static int untimeout(struct nf_conn *ct, void *timeout)
35{
36 struct nf_conn_timeout *timeout_ext = nf_ct_timeout_find(ct);
37
38 if (timeout_ext && (!timeout || timeout_ext->timeout == timeout))
39 RCU_INIT_POINTER(timeout_ext->timeout, NULL);
40
41 /* We are not intended to delete this conntrack. */
42 return 0;
43}
44
6c1fd7dc 45void nf_ct_untimeout(struct net *net, struct nf_ct_timeout *timeout)
4e665afb
HS
46{
47 nf_ct_iterate_cleanup_net(net, untimeout, timeout, 0, 0);
48}
49EXPORT_SYMBOL_GPL(nf_ct_untimeout);
50
23f671a1 51static const struct nf_ct_ext_type timeout_extend = {
dd705072
PNA
52 .len = sizeof(struct nf_conn_timeout),
53 .align = __alignof__(struct nf_conn_timeout),
54 .id = NF_CT_EXT_TIMEOUT,
55};
56
8684094c 57int nf_conntrack_timeout_init(void)
dd705072 58{
8684094c
G
59 int ret = nf_ct_extend_register(&timeout_extend);
60 if (ret < 0)
61 pr_err("nf_ct_timeout: Unable to register timeout extension.\n");
62 return ret;
dd705072
PNA
63}
64
8684094c 65void nf_conntrack_timeout_fini(void)
dd705072 66{
8684094c 67 nf_ct_extend_unregister(&timeout_extend);
dd705072 68}