netfilter: Export nf_ct_{set,destroy}_timeout()
Subsystems (4)
PATCH v4 1/2 netfilter: Export nf_ct_{set,destroy}_timeout()
This patch exports nf_ct_set_timeout() and nf_ct_destroy_timeout(). The two functions are derived from xt_ct_destroy_timeout() and xt_ct_set_timeout() in xt_CT.c, and moved to nf_conntrack_timeout.c without any functional change.
It would be useful for other users (i.e. OVS) that utilizes the finer-grain conntrack timeout feature.
---
v1-> v2: Export nf_ct_set_timeout().
v2-> v3: Fix build issue when CONFIG_NF_CONNTRACK_TIMEOUT is not set. v3-> v4: Remove unnessary #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
--- include/net/netfilter/nf_conntrack_timeout.h | 15 +++++ net/netfilter/nf_conntrack_timeout.c | 89 ++++++++++++++++++++++++++ net/netfilter/xt_CT.c | 93 ++-------------------------- 3 files changed, 110 insertions(+), 87 deletions(-)
include/net/netfilter/nf_conntrack_timeout.h +15 -0
@@ -88,6 +88,9 @@ static inline unsigned int *nf_ct_timeout_lookup(const struct nf_conn *ct)int nf_conntrack_timeout_init (void );void nf_conntrack_timeout_fini (void );void nf_ct_untimeout (struct net *net,struct nf_ct_timeout *timeout); +int nf_ct_set_timeout (struct net *net,struct nf_conn *ct,u8 l3num,u8 l4num, +const char *timeout_name); +void nf_ct_destroy_timeout (struct nf_conn *ct);#else static inline int nf_conntrack_timeout_init (void ) {
@@ -98,6 +101,18 @@ static inline void nf_conntrack_timeout_fini(void) {return ; } + +static inline int nf_ct_set_timeout (struct net *net,struct nf_conn *ct, +u8 l3num,u8 l4num, +const char *timeout_name) +{ +return -EOPNOTSUPP ; +} + +static inline void nf_ct_destroy_timeout (struct nf_conn *ct) +{ +return ; +}#endif /* CONFIG_NF_CONNTRACK_TIMEOUT */ #ifdef CONFIG_NF_CONNTRACK_TIMEOUT
net/netfilter/nf_conntrack_timeout.c +89 -0
95 lines not on this page · raw message
net/netfilter/xt_CT.c +6 -87
124 lines not on this page · raw message
Signature · 1 line
2.7.4
PATCH v4 2/2 openvswitch: Add timeout support to ct action
Add support for fine-grain timeout support to conntrack action. The new OVS_CT_ATTR_TIMEOUT attribute of the conntrack action specifies a timeout to be associated with this connection. If no timeout is specified, it acts as is, that is the default timeout for the connection will be automatically applied.
Example usage:
$ nfct timeout add timeout_1 inet tcp syn_sent 100 established 200 $ ovs-ofctl add-flow br0 in_port=1,ip,tcp,action=ct(commit,timeout=timeout_1)
---
v1-> v2: Utilize nf_ct_set_timeout().
v2-> v4: No change in this patch, the build issue is resolved by patch 1.
--- include/uapi/linux/openvswitch.h | 3 +++ net/openvswitch/conntrack.c | 30 +++++++++++++++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-)
include/uapi/linux/openvswitch.h +3 -0
@@ -734,6 +734,7 @@ struct ovs_action_hash {* be received on NFNLGRP_CONNTRACK_NEW and NFNLGRP_CONNTRACK_DESTROY groups, * respectively. Remaining bits control the changes for which an event is * delivered on the NFNLGRP_CONNTRACK_UPDATE group. +* @OVS_CT_ATTR_TIMEOUT: Variable length string defining conntrack timeout. */ enum ovs_ct_attr {OVS_CT_ATTR_UNSPEC ,
@@ -746,6 +747,8 @@ enum ovs_ct_attr {OVS_CT_ATTR_NAT ,/* Nested OVS_NAT_ATTR_* */ OVS_CT_ATTR_FORCE_COMMIT ,/* No argument */ OVS_CT_ATTR_EVENTMASK ,/* u32 mask of IPCT_* events. */ +OVS_CT_ATTR_TIMEOUT ,/* Associate timeout with this connection for +* fine-grain timeout tuning. */ __OVS_CT_ATTR_MAX };
net/openvswitch/conntrack.c +29 -1
@@ -24,6 +24,7 @@#include <net/netfilter/nf_conntrack_helper.h> #include <net/netfilter/nf_conntrack_labels.h> #include <net/netfilter/nf_conntrack_seqadj.h> +#include <net/netfilter/nf_conntrack_timeout.h> #include <net/netfilter/nf_conntrack_zones.h> #include <net/netfilter/ipv6/nf_defrag_ipv6.h> #include <net/ipv6_frag.h>
@@ -73,6 +74,7 @@ struct ovs_conntrack_info {u32 eventmask;/* Mask of 1 << IPCT_*. */ struct md_mark mark;struct md_labels labels; +char timeout[CTNL_TIMEOUT_NAME_MAX ];#ifdef CONFIG_NF_NAT_NEEDED struct nf_nat_range2 range;/* Only present for SRC NAT and DST NAT. */ #endif
@@ -1465,6 +1467,8 @@ static const struct ovs_ct_len_tbl ovs_ct_attr_lens[OVS_CT_ATTR_MAX + 1] = { #endif [OVS_CT_ATTR_EVENTMASK ] = { .minlen =sizeof (u32), .maxlen = sizeof(u32) }, + [OVS_CT_ATTR_TIMEOUT ] = { .minlen =1 , + .maxlen = CTNL_TIMEOUT_NAME_MAX }, }; static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info,
@@ -1550,6 +1554,15 @@ static int parse_ct(const struct nlattr *attr, struct ovs_conntrack_info *info, info->have_eventmask = true; info->eventmask =nla_get_u32 (a);break ; +#ifdef CONFIG_NF_CONNTRACK_TIMEOUT +case OVS_CT_ATTR_TIMEOUT : +memcpy (info->timeout,nla_data (a),nla_len (a)); +if (!memchr (info->timeout,'\0' ,nla_len (a))) { +OVS_NLERR (log,"Invalid conntrack helper" ); +return -EINVAL ; + } +break ; +#endif default : OVS_NLERR(log, "Unknown conntrack attr (%d)",
@@ -1631,6 +1644,14 @@ int ovs_ct_copy_action(struct net *net, const struct nlattr *attr,OVS_NLERR (log,"Failed to allocate conntrack template" );return -ENOMEM ; } + +if (ct_info.timeout[0 ]) { +if (nf_ct_set_timeout (net, ct_info.ct, family, key->ip.proto, + ct_info.timeout)) +pr_info_ratelimited ("Failed to associated timeout " +"policy `%s'\n" , ct_info.timeout); + } +if (helper) { err =ovs_ct_add_helper (&ct_info, helper, key, log);if (err)
@@ -1751,6 +1772,10 @@ int ovs_ct_action_to_attr(const struct ovs_conntrack_info *ct_info,if (ct_info->have_eventmask &&nla_put_u32 (skb,OVS_CT_ATTR_EVENTMASK , ct_info->eventmask))return -EMSGSIZE ; +if (ct_info->timeout[0 ]) { +if (nla_put_string (skb,OVS_CT_ATTR_TIMEOUT , ct_info->timeout)) +return -EMSGSIZE ; + }#ifdef CONFIG_NF_NAT_NEEDED if (ct_info->nat && !ovs_ct_nat_to_attr (ct_info, skb))
@@ -1772,8 +1797,11 @@ static void __ovs_ct_free_action(struct ovs_conntrack_info *ct_info) {if (ct_info->helper)nf_conntrack_helper_put (ct_info->helper); -if (ct_info->ct) +if (ct_info->ct) {nf_ct_tmpl_free (ct_info->ct); +if (ct_info->timeout[0 ]) +nf_ct_destroy_timeout (ct_info->ct); + } }#if IS_ENABLED (CONFIG_NETFILTER_CONNCOUNT )
Signature · 1 line
2.7.4
Re: [PATCH net-next v4 2/2] openvswitch: Add timeout support to ct action
Quoted 11 lines · Yi-Hung Wei
Add support for fine-grain timeout support to conntrack action. The new
OVS_CT_ATTR_TIMEOUTattribute of the conntrack action specifies a timeout to be associated with this connection. If no timeout is specified, it acts as is, that is the default timeout for the connection will be automatically applied.Example usage:
$ nfct timeout add timeout_1 inet tcp syn_sent 100 established 200 $ ovs-ofctl add-flow br0 in_port=1,ip,tcp,action=ct(commit,timeout=timeout_1)
Quoted 7 lines
CC Pravin Shelar <[email protected]>CC Pablo Neira Ayuso <[email protected]>Signed-off-by Yi-Hung Wei <[email protected]>---
v1-> v2: Utilizenf_ct_set_timeout().
v2-> v4: No change in this patch, the build issue is resolved by patch 1.
---
Thanks,
Pravin.
Quoted 8 lines · Yi-Hung Wei
This patch exports
nf_ct_set_timeout()andnf_ct_destroy_timeout(). The two functions are derived fromxt_ct_destroy_timeout()andxt_ct_set_timeout()inxt_CT.c, and moved tonf_conntrack_timeout.cwithout any functional change.
It would be useful for other users (i.e. OVS) that utilizes the finer-grain conntrack timeout feature.
Quoted 7 lines
CC Pablo Neira Ayuso <[email protected]>CC Pravin Shelar <[email protected]>Signed-off-by Yi-Hung Wei <[email protected]>---
v1-> v2: Exportnf_ct_set_timeout().
v2-> v3: Fix build issue whenCONFIG_NF_CONNTRACK_TIMEOUTis not set. v3-> v4: Remove unnessary #ifdefCONFIG_NF_CONNTRACK_TIMEOUT
Looks good to me.
From: Yi-Hung Wei <[email protected]>
Date: Tue, 26 Mar 2019 11:31:13 -0700
Quoted 7 lines
This patch exports
nf_ct_set_timeout()andnf_ct_destroy_timeout(). The two functions are derived fromxt_ct_destroy_timeout()andxt_ct_set_timeout()inxt_CT.c, and moved tonf_conntrack_timeout.cwithout any functional change.
It would be useful for other users (i.e. OVS) that utilizes the finer-grain conntrack timeout feature.
Quoted 7 lines
CC Pablo Neira Ayuso <[email protected]>CC Pravin Shelar <[email protected]>Signed-off-by Yi-Hung Wei <[email protected]>---
v1-> v2: Exportnf_ct_set_timeout().
v2-> v3: Fix build issue whenCONFIG_NF_CONNTRACK_TIMEOUTis not set. v3-> v4: Remove unnessary #ifdefCONFIG_NF_CONNTRACK_TIMEOUT
Applied.
Re: [PATCH net-next v4 2/2] openvswitch: Add timeout support to ct action
In reply to Yi-Hung WeiFrom: Yi-Hung Wei <[email protected]>
Date: Tue, 26 Mar 2019 11:31:14 -0700
Quoted 10 lines
Add support for fine-grain timeout support to conntrack action. The new
OVS_CT_ATTR_TIMEOUTattribute of the conntrack action specifies a timeout to be associated with this connection. If no timeout is specified, it acts as is, that is the default timeout for the connection will be automatically applied.Example usage:
$ nfct timeout add timeout_1 inet tcp syn_sent 100 established 200 $ ovs-ofctl add-flow br0 in_port=1,ip,tcp,action=ct(commit,timeout=timeout_1)
Quoted 6 lines
CC Pravin Shelar <[email protected]>CC Pablo Neira Ayuso <[email protected]>Signed-off-by Yi-Hung Wei <[email protected]>---
v1-> v2: Utilizenf_ct_set_timeout().
v2-> v4: No change in this patch, the build issue is resolved by patch 1.
Applied.