2 * (C) 2010 Pablo Neira Ayuso <pablo@netfilter.org>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation (or any later at your option).
9 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
11 #include <linux/netfilter.h>
12 #include <linux/slab.h>
13 #include <linux/kernel.h>
14 #include <linux/moduleparam.h>
16 #include <net/netfilter/nf_conntrack.h>
17 #include <net/netfilter/nf_conntrack_extend.h>
18 #include <net/netfilter/nf_conntrack_timestamp.h>
20 static bool nf_ct_tstamp __read_mostly;
22 module_param_named(tstamp, nf_ct_tstamp, bool, 0644);
23 MODULE_PARM_DESC(tstamp, "Enable connection tracking flow timestamping.");
26 static struct ctl_table tstamp_sysctl_table[] = {
28 .procname = "nf_conntrack_timestamp",
29 .data = &init_net.ct.sysctl_tstamp,
30 .maxlen = sizeof(unsigned int),
32 .proc_handler = proc_dointvec,
36 #endif /* CONFIG_SYSCTL */
38 static const struct nf_ct_ext_type tstamp_extend = {
39 .len = sizeof(struct nf_conn_tstamp),
40 .align = __alignof__(struct nf_conn_tstamp),
41 .id = NF_CT_EXT_TSTAMP,
45 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
47 struct ctl_table *table;
49 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
54 table[0].data = &net->ct.sysctl_tstamp;
56 /* Don't export sysctls to unprivileged users */
57 if (net->user_ns != &init_user_ns)
58 table[0].procname = NULL;
60 net->ct.tstamp_sysctl_header = register_net_sysctl(net, "net/netfilter",
62 if (!net->ct.tstamp_sysctl_header) {
63 pr_err("can't register to sysctl\n");
74 static void nf_conntrack_tstamp_fini_sysctl(struct net *net)
76 struct ctl_table *table;
78 table = net->ct.tstamp_sysctl_header->ctl_table_arg;
79 unregister_net_sysctl_table(net->ct.tstamp_sysctl_header);
83 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
88 static void nf_conntrack_tstamp_fini_sysctl(struct net *net)
93 int nf_conntrack_tstamp_pernet_init(struct net *net)
95 net->ct.sysctl_tstamp = nf_ct_tstamp;
96 return nf_conntrack_tstamp_init_sysctl(net);
99 void nf_conntrack_tstamp_pernet_fini(struct net *net)
101 nf_conntrack_tstamp_fini_sysctl(net);
104 int nf_conntrack_tstamp_init(void)
107 ret = nf_ct_extend_register(&tstamp_extend);
109 pr_err("Unable to register extension\n");
113 void nf_conntrack_tstamp_fini(void)
115 nf_ct_extend_unregister(&tstamp_extend);