Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.8 required=3.0 tests=DKIM_SIGNED,DKIM_VALID, DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id A1B13C43381 for ; Tue, 26 Mar 2019 18:39:24 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 67B17206DF for ; Tue, 26 Mar 2019 18:39:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ctgg42xd" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1732489AbfCZSjX (ORCPT ); Tue, 26 Mar 2019 14:39:23 -0400 Received: from mail-pl1-f196.google.com ([209.85.214.196]:39998 "EHLO mail-pl1-f196.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731755AbfCZSjW (ORCPT ); Tue, 26 Mar 2019 14:39:22 -0400 Received: by mail-pl1-f196.google.com with SMTP id b11so2034952plr.7 for ; Tue, 26 Mar 2019 11:39:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=v2N8Jhm6EXqa+Hg28kdcUmHNEae+pqpsCl7REZIwkWY=; b=ctgg42xdAuh49ofV0SHvWKgwsdUJnf0Rko3/yw1iH3rymbYCG32kXfJ0cxD0TpWCuf j+7t3jb7baN9Vv2kv3xiSD5WIvcNrIDxKh37yk0j/ru7uvcxE8M7j7u+tRoqJ+fFBipQ vNpkO6Bb5tSS/rd41zhJDbytNezb7OIlfIJnObPt1EZfMeXROsM3XCO3jr5cknn6k5nv zGEDNGr8Mr1RnST5JVEG3jHjXuxotO6vCe9ERRLbbhDJrOM4h91SFYZVIyhALwhYIB09 MqTufOI7byQ5av0olZqTLdSqrk+R50hgExM9T/QycgvyCrMUCpGlOPt1wtgIL6+PY8sG 2Tew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=v2N8Jhm6EXqa+Hg28kdcUmHNEae+pqpsCl7REZIwkWY=; b=jDlYa0acEERx5Kl+ERJIlV+mI0EfHgcapLFkU0IUsxKKxf0Ffu5gfQC/YbXFjL/4It nIDDzkvDh8CjjkB8xSFiQjvh6Z4hMrSrFo+r84UF++P9Zi0o6t4AAQg4bEbpF0JLvNMJ fYwh5m/jM7YkeQkX/7nEr3XADVQyp2OZizUKtOJIC5Mebr8dGY0FhIFwJXctlyNrpcnS LlIvzajGcTVoH+A1rS/IPxYeYGBCsAcHmaeY/24wV39YERQjx9+jIHLFvD2JXwJVRLBO PTsT1/dBN29hye5JXr+TB7fn562yc0HxRV9/Cj46c+eG2/wp1HPEI+LwcBXFjTR9TIXY 2lrQ== X-Gm-Message-State: APjAAAV/AxcrrT5DARxfD5bcZljqFsVTF4z6GPacj58IusF1wN1cKPpd MlvCXLsAyJRao4YNJOCRGq2xY3qg X-Google-Smtp-Source: APXvYqyvPDaSEuFmC0xfRxrtEMajGy+oSjVP7ux0u5GoDsRORGT3rtQcObuo16uS0bfP+2l+Skgw0g== X-Received: by 2002:a17:902:26f:: with SMTP id 102mr32080580plc.175.1553625561367; Tue, 26 Mar 2019 11:39:21 -0700 (PDT) Received: from Husky.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id q86sm57945230pfi.171.2019.03.26.11.39.19 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Mar 2019 11:39:20 -0700 (PDT) From: Yi-Hung Wei To: netdev@vger.kernel.org Cc: Yi-Hung Wei , Pravin Shelar , Pablo Neira Ayuso Subject: [PATCH net-next v4 2/2] openvswitch: Add timeout support to ct action Date: Tue, 26 Mar 2019 11:31:14 -0700 Message-Id: <1553625074-20756-2-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1553625074-20756-1-git-send-email-yihung.wei@gmail.com> References: <1553625074-20756-1-git-send-email-yihung.wei@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org 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) CC: Pravin Shelar CC: Pablo Neira Ayuso Signed-off-by: Yi-Hung Wei --- 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(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index dbe0cbe4f1b7..00ec98836cf3 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -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 }; diff --git a/net/openvswitch/conntrack.c b/net/openvswitch/conntrack.c index 51080004677e..c4adbaeadda4 100644 --- a/net/openvswitch/conntrack.c +++ b/net/openvswitch/conntrack.c @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -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) -- 2.7.4