mirror of
https://git.kernel.org/pub/scm/linux/kernel/git/stable/linux.git
synced 2024-09-12 21:57:43 +00:00
b884fa4617
Due to historical reasons, all l4 trackers register their own sysctls. This leads to copy&pasted boilerplate code, that does exactly same thing, just with different data structure. Place all of this in a single file. This allows to remove the various ctl_table pointers from the ct_netns structure and reduces overall code size. Signed-off-by: Florian Westphal <fw@strlen.de> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
91 lines
2.3 KiB
C
91 lines
2.3 KiB
C
/* (C) 1999-2001 Paul `Rusty' Russell
|
|
* (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
|
|
*
|
|
* This program is free software; you can redistribute it and/or modify
|
|
* it under the terms of the GNU General Public License version 2 as
|
|
* published by the Free Software Foundation.
|
|
*/
|
|
|
|
#include <linux/types.h>
|
|
#include <linux/jiffies.h>
|
|
#include <linux/timer.h>
|
|
#include <linux/netfilter.h>
|
|
#include <net/netfilter/nf_conntrack_l4proto.h>
|
|
#include <net/netfilter/nf_conntrack_timeout.h>
|
|
|
|
static const unsigned int nf_ct_generic_timeout = 600*HZ;
|
|
|
|
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
|
|
|
|
#include <linux/netfilter/nfnetlink.h>
|
|
#include <linux/netfilter/nfnetlink_cttimeout.h>
|
|
|
|
static int generic_timeout_nlattr_to_obj(struct nlattr *tb[],
|
|
struct net *net, void *data)
|
|
{
|
|
struct nf_generic_net *gn = nf_generic_pernet(net);
|
|
unsigned int *timeout = data;
|
|
|
|
if (!timeout)
|
|
timeout = &gn->timeout;
|
|
|
|
if (tb[CTA_TIMEOUT_GENERIC_TIMEOUT])
|
|
*timeout =
|
|
ntohl(nla_get_be32(tb[CTA_TIMEOUT_GENERIC_TIMEOUT])) * HZ;
|
|
else {
|
|
/* Set default generic timeout. */
|
|
*timeout = gn->timeout;
|
|
}
|
|
|
|
return 0;
|
|
}
|
|
|
|
static int
|
|
generic_timeout_obj_to_nlattr(struct sk_buff *skb, const void *data)
|
|
{
|
|
const unsigned int *timeout = data;
|
|
|
|
if (nla_put_be32(skb, CTA_TIMEOUT_GENERIC_TIMEOUT, htonl(*timeout / HZ)))
|
|
goto nla_put_failure;
|
|
|
|
return 0;
|
|
|
|
nla_put_failure:
|
|
return -ENOSPC;
|
|
}
|
|
|
|
static const struct nla_policy
|
|
generic_timeout_nla_policy[CTA_TIMEOUT_GENERIC_MAX+1] = {
|
|
[CTA_TIMEOUT_GENERIC_TIMEOUT] = { .type = NLA_U32 },
|
|
};
|
|
#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
|
|
|
|
static int generic_init_net(struct net *net)
|
|
{
|
|
struct nf_generic_net *gn = nf_generic_pernet(net);
|
|
|
|
gn->timeout = nf_ct_generic_timeout;
|
|
|
|
return 0;
|
|
}
|
|
|
|
static struct nf_proto_net *generic_get_net_proto(struct net *net)
|
|
{
|
|
return &net->ct.nf_ct_proto.generic.pn;
|
|
}
|
|
|
|
const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic =
|
|
{
|
|
.l4proto = 255,
|
|
#ifdef CONFIG_NF_CONNTRACK_TIMEOUT
|
|
.ctnl_timeout = {
|
|
.nlattr_to_obj = generic_timeout_nlattr_to_obj,
|
|
.obj_to_nlattr = generic_timeout_obj_to_nlattr,
|
|
.nlattr_max = CTA_TIMEOUT_GENERIC_MAX,
|
|
.obj_size = sizeof(unsigned int),
|
|
.nla_policy = generic_timeout_nla_policy,
|
|
},
|
|
#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
|
|
.init_net = generic_init_net,
|
|
.get_net_proto = generic_get_net_proto,
|
|
};
|