1 // SPDX-License-Identifier: GPL-2.0-only
2 /* (C) 1999-2001 Paul `Rusty' Russell
3 * (C) 2002-2004 Netfilter Core Team <coreteam@netfilter.org>
6 #include <linux/types.h>
7 #include <linux/jiffies.h>
8 #include <linux/timer.h>
9 #include <linux/netfilter.h>
10 #include <net/netfilter/nf_conntrack_l4proto.h>
11 #include <net/netfilter/nf_conntrack_timeout.h>
13 static const unsigned int nf_ct_generic_timeout
= 600*HZ
;
15 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
17 #include <linux/netfilter/nfnetlink.h>
18 #include <linux/netfilter/nfnetlink_cttimeout.h>
20 static int generic_timeout_nlattr_to_obj(struct nlattr
*tb
[],
21 struct net
*net
, void *data
)
23 struct nf_generic_net
*gn
= nf_generic_pernet(net
);
24 unsigned int *timeout
= data
;
27 timeout
= &gn
->timeout
;
29 if (tb
[CTA_TIMEOUT_GENERIC_TIMEOUT
])
31 ntohl(nla_get_be32(tb
[CTA_TIMEOUT_GENERIC_TIMEOUT
])) * HZ
;
33 /* Set default generic timeout. */
34 *timeout
= gn
->timeout
;
41 generic_timeout_obj_to_nlattr(struct sk_buff
*skb
, const void *data
)
43 const unsigned int *timeout
= data
;
45 if (nla_put_be32(skb
, CTA_TIMEOUT_GENERIC_TIMEOUT
, htonl(*timeout
/ HZ
)))
54 static const struct nla_policy
55 generic_timeout_nla_policy
[CTA_TIMEOUT_GENERIC_MAX
+1] = {
56 [CTA_TIMEOUT_GENERIC_TIMEOUT
] = { .type
= NLA_U32
},
58 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */
60 void nf_conntrack_generic_init_net(struct net
*net
)
62 struct nf_generic_net
*gn
= nf_generic_pernet(net
);
64 gn
->timeout
= nf_ct_generic_timeout
;
67 const struct nf_conntrack_l4proto nf_conntrack_l4proto_generic
=
70 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
72 .nlattr_to_obj
= generic_timeout_nlattr_to_obj
,
73 .obj_to_nlattr
= generic_timeout_obj_to_nlattr
,
74 .nlattr_max
= CTA_TIMEOUT_GENERIC_MAX
,
75 .obj_size
= sizeof(unsigned int),
76 .nla_policy
= generic_timeout_nla_policy
,
78 #endif /* CONFIG_NF_CONNTRACK_TIMEOUT */