From patchwork Thu Jul 25 23:24:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Yi-Hung Wei X-Patchwork-Id: 1137165 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="l0B4kbG0"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 45vpKz4Prqz9s4Y for ; Fri, 26 Jul 2019 09:28:07 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 4D425D30; Thu, 25 Jul 2019 23:24:37 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id 70AE3D1A for ; Thu, 25 Jul 2019 23:24:35 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pf1-f196.google.com (mail-pf1-f196.google.com [209.85.210.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 19A8C224 for ; Thu, 25 Jul 2019 23:24:35 +0000 (UTC) Received: by mail-pf1-f196.google.com with SMTP id y15so23506484pfn.5 for ; Thu, 25 Jul 2019 16:24:35 -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=w+2MckYxoqq2iiw9mp+nUczzZDSaFunEJa2qVE3KX3g=; b=l0B4kbG0eCVEV7IJyjrx6yQn6JQ5WRSzH4qNRsBfWB2qghmfdmXzDF2ufypvX8Tegz IXH1Q2eVrGNpxP174LD/0ie07KHjsUhYm5sgEghxYxh+Ue8/25MpNm2GiaEMy6U21g+h EpcMh8ct947mvzqdt2bYrDa91JC/hBPmNGf1LMrIwk7q1sazNAIKIpAFnm61dto11j6f 8vzfgmSxNPKDDYuhr9NlAjK99QoW4f26Iq6/fAXhQmSwo7OXdM5uv7K4rxquJGlhQvXR fGnFyKDJl0gdzS0m2cxvJatWa0Jg+nI6jGkDFhVVgBPiEHUOh7XokC1ZyCI3DwgihjJh 2nhw== 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=w+2MckYxoqq2iiw9mp+nUczzZDSaFunEJa2qVE3KX3g=; b=ukijzMbwF8sCZE/is89+h4aY++VUwB9J5/eF0Gr4PT6u0pXl7SA7HI5LcLROa4mgEv ylv1PrCwkQmgWMtM949m0QFCoX++Rb6WEzUX+XZO/p29y6r+gBGHMo9FYOOXWh8bRBWc pWXUpiV74CtelPWN6AzLN0QkeOLXsEP8WCmgnaSzn6tvlGwsadwckXqa5UAZWVxNdSc/ 5e8F9QtK9/T1BEI1TnOFcxhy90QwPqrzbnoi/sSX8OjUQYoDyOjo++OMl5qzFXkipkL0 HraoZ58A2PW4YglFWRrmPJvEsiCof7mZOlKTVYKZ58P3tbmBgSYrprVJOFzOiSZY5HlG 4GKQ== X-Gm-Message-State: APjAAAVYv3He/aj+W+At2P5q4Nq6rndYde+SXJQhPk+WwMhscRG6JUm4 GpCso//sKhq8eyR28Xpi170GP64u X-Google-Smtp-Source: APXvYqw4pnpXTUBr0sXmhix+XQHwcQaO+iTdeBad+1ZHnUbQTGatwqGem3pA+6xok7kUgCzZb2fRoA== X-Received: by 2002:a63:5811:: with SMTP id m17mr17939716pgb.237.1564097074089; Thu, 25 Jul 2019 16:24:34 -0700 (PDT) Received: from vm-main.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id x9sm28189940pgp.75.2019.07.25.16.24.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jul 2019 16:24:32 -0700 (PDT) From: Yi-Hung Wei To: dev@openvswitch.org, blp@ovn.org Date: Thu, 25 Jul 2019 16:24:08 -0700 Message-Id: <1564097054-72663-7-git-send-email-yihung.wei@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1564097054-72663-1-git-send-email-yihung.wei@gmail.com> References: <1564097054-72663-1-git-send-email-yihung.wei@gmail.com> X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH 06/12] ct-dpif: Add timeout policy related utility functions. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org These functions will be useful in the following patches. Signed-off-by: Yi-Hung Wei Acked-by: William Tu --- lib/ct-dpif.c | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/ct-dpif.h | 3 +++ 2 files changed, 56 insertions(+) diff --git a/lib/ct-dpif.c b/lib/ct-dpif.c index ae347a9bb46d..1625754e2441 100644 --- a/lib/ct-dpif.c +++ b/lib/ct-dpif.c @@ -761,6 +761,59 @@ ct_dpif_format_zone_limits(uint32_t default_limit, } } +static const char *const ct_dpif_tp_attr_string[] = { +#define CT_DPIF_TP_TCP_ATTR(ATTR) \ + [CT_DPIF_TP_ATTR_TCP_##ATTR] = "TCP_"#ATTR, + CT_DPIF_TP_TCP_ATTRS +#undef CT_DPIF_TP_TCP_ATTR +#define CT_DPIF_TP_UDP_ATTR(ATTR) \ + [CT_DPIF_TP_ATTR_UDP_##ATTR] = "UDP_"#ATTR, + CT_DPIF_TP_UDP_ATTRS +#undef CT_DPIF_TP_UDP_ATTR +#define CT_DPIF_TP_ICMP_ATTR(ATTR) \ + [CT_DPIF_TP_ATTR_ICMP_##ATTR] = "ICMP_"#ATTR, + CT_DPIF_TP_ICMP_ATTRS +#undef CT_DPIF_TP_ICMP_ATTR +}; + +static bool +ct_dpif_set_timeout_policy_attr(struct ct_dpif_timeout_policy *tp, + uint32_t attr, uint32_t value) +{ + if (tp->present & (1 << attr) && tp->attrs[attr] == value) { + return false; + } + tp->attrs[attr] = value; + tp->present |= 1 << attr; + return true; +} + +/* Sets a timeout value identified by '*name' to 'value'. + * Returns true if the attribute is changed */ +bool +ct_dpif_set_timeout_policy_attr_by_name(struct ct_dpif_timeout_policy *tp, + const char *name, uint32_t value) +{ + uint32_t i; + + for (i = 0; i < CT_DPIF_TP_ATTR_MAX; ++i) { + if (!strcasecmp(name, ct_dpif_tp_attr_string[i])) { + return ct_dpif_set_timeout_policy_attr(tp, i, value); + } + } + return false; +} + +bool +ct_dpif_timeout_policy_support_ipproto(uint8_t ipproto) +{ + if (ipproto == IPPROTO_TCP || ipproto == IPPROTO_UDP || + ipproto == IPPROTO_ICMP || ipproto == IPPROTO_ICMPV6) { + return true; + } + return false; +} + int ct_dpif_add_timeout_policy(struct dpif *dpif, bool is_default, const struct ct_dpif_timeout_policy *tp) diff --git a/lib/ct-dpif.h b/lib/ct-dpif.h index 9dc33bede527..de032cc416ce 100644 --- a/lib/ct-dpif.h +++ b/lib/ct-dpif.h @@ -305,6 +305,9 @@ bool ct_dpif_parse_zone_limit_tuple(const char *s, uint16_t *pzone, uint32_t *plimit, struct ds *); void ct_dpif_format_zone_limits(uint32_t default_limit, const struct ovs_list *, struct ds *); +bool ct_dpif_set_timeout_policy_attr_by_name(struct ct_dpif_timeout_policy *tp, + const char *key, uint32_t value); +bool ct_dpif_timeout_policy_support_ipproto(uint8_t ipproto); int ct_dpif_add_timeout_policy(struct dpif *dpif, bool is_default, const struct ct_dpif_timeout_policy *tp); int ct_dpif_get_timeout_policy(struct dpif *dpif, bool is_default,