10 #include <linux/module.h>
11 #include <linux/kernel.h>
14 #include <linux/types.h>
18 #include <linux/errno.h>
19 #include <linux/netlink.h>
22 #include <linux/slab.h>
24 #include <linux/netfilter.h>
34 #include <linux/netfilter/nfnetlink.h>
39 MODULE_DESCRIPTION(
"cttimeout: Extended Netfilter Connection Tracking timeout tuning");
59 if (
likely(l4proto->ctnl_timeout.nlattr_to_obj)) {
60 struct nlattr *
tb[l4proto->ctnl_timeout.nlattr_max+1];
62 nla_parse_nested(tb, l4proto->ctnl_timeout.nlattr_max,
65 ret = l4proto->ctnl_timeout.nlattr_to_obj(tb, net,
80 struct net *net = sock_net(skb->
sk);
108 if (l4proto->
l4proto != l4num) {
118 if (matching->
l3num != l3num ||
119 matching->
l4proto->l4proto != l4num) {
124 ret = ctnl_timeout_parse_policy(matching, l4proto, net,
125 cda[CTA_TIMEOUT_DATA]);
134 if (timeout ==
NULL) {
139 ret = ctnl_timeout_parse_policy(timeout, l4proto, net,
140 cda[CTA_TIMEOUT_DATA]);
145 timeout->
l3num = l3num;
148 list_add_tail_rcu(&timeout->
head, &cttimeout_list);
168 nlh = nlmsg_put(skb, portid, seq, event,
sizeof(*nfmsg), flags);
172 nfmsg = nlmsg_data(nlh);
182 goto nla_put_failure;
184 if (
likely(l4proto->ctnl_timeout.obj_to_nlattr)) {
185 struct nlattr *nest_parms;
188 nest_parms = nla_nest_start(skb,
191 goto nla_put_failure;
193 ret = l4proto->ctnl_timeout.obj_to_nlattr(skb, &timeout->
data);
195 goto nla_put_failure;
197 nla_nest_end(skb, nest_parms);
205 nlmsg_cancel(skb, nlh);
222 list_for_each_entry_rcu(cur, &cttimeout_list,
head) {
223 if (last && cur != last)
241 cttimeout_get_timeout(
struct sock *ctnl,
struct sk_buff *skb,
243 const struct nlattr *
const cda[])
251 .dump = ctnl_timeout_dump,
253 return netlink_dump_start(ctnl, skb, nlh, &c);
258 name = nla_data(cda[CTA_TIMEOUT_NAME]);
272 ret = ctnl_timeout_fill_info(skb2,
NETLINK_CB(skb).portid,
292 static int ctnl_timeout_try_del(
struct ctnl_timeout *timeout)
299 list_del_rcu(&timeout->
head);
311 cttimeout_del_timeout(
struct sock *ctnl,
struct sk_buff *skb,
313 const struct nlattr *
const cda[])
319 if (!cda[CTA_TIMEOUT_NAME]) {
321 ctnl_timeout_try_del(cur);
325 name = nla_data(cda[CTA_TIMEOUT_NAME]);
331 ret = ctnl_timeout_try_del(cur);
340 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
341 static struct ctnl_timeout *ctnl_timeout_find_get(
const char *name)
346 list_for_each_entry_rcu(timeout, &cttimeout_list, head) {
365 static void ctnl_timeout_put(
struct ctnl_timeout *timeout)
375 .policy = cttimeout_nla_policy },
378 .policy = cttimeout_nla_policy },
381 .policy = cttimeout_nla_policy },
385 .name =
"conntrack_timeout",
393 static int __init cttimeout_init(
void)
399 pr_err(
"cttimeout_init: cannot register cttimeout with "
403 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
413 static void __exit cttimeout_exit(
void)
417 pr_info(
"cttimeout: unregistering from nfnetlink.\n");
421 list_del_rcu(&cur->
head);
428 #ifdef CONFIG_NF_CONNTRACK_TIMEOUT