From patchwork Fri Jul 27 21:19:12 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 950368 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=none (p=none dis=none) header.from=ovn.org 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 41chg23MdQz9ryn for ; Sat, 28 Jul 2018 07:19:25 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 323D8FB6; Fri, 27 Jul 2018 21:19:23 +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 31C37F0C for ; Fri, 27 Jul 2018 21:19:22 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 205F371D for ; Fri, 27 Jul 2018 21:19:19 +0000 (UTC) X-Originating-IP: 76.21.1.228 Received: from localhost.localdomain (unknown [76.21.1.228]) (Authenticated sender: jpettit@ovn.org) by relay4-d.mail.gandi.net (Postfix) with ESMTPSA id 457ABE0007 for ; Fri, 27 Jul 2018 21:19:16 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Fri, 27 Jul 2018 14:19:12 -0700 Message-Id: <20180727211913.18268-1-jpettit@ovn.org> X-Mailer: git-send-email 2.17.1 X-Spam-Level: X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW 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] [PATCHv2 1/2] dpif: Move common meter checks into the dpif layer. 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 Another dpif provider will soon add support for meters, so move some of the common sanity checks up into the dpif layer so that each provider doesn't need to re-implement them. Signed-off-by: Justin Pettit Acked-by: Ben Pfaff --- v2: This patch is new to the series. --- lib/dpif-netdev.c | 15 +++------------ lib/dpif.c | 22 +++++++++++++++++++--- 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/lib/dpif-netdev.c b/lib/dpif-netdev.c index 13a20f023554..26d07b39c9af 100644 --- a/lib/dpif-netdev.c +++ b/lib/dpif-netdev.c @@ -5172,21 +5172,12 @@ dpif_netdev_meter_set(struct dpif *dpif, ofproto_meter_id *meter_id, return EFBIG; /* Meter_id out of range. */ } - if (config->flags & ~DP_SUPPORTED_METER_FLAGS_MASK || - !(config->flags & (OFPMF13_KBPS | OFPMF13_PKTPS))) { + if (config->flags & ~DP_SUPPORTED_METER_FLAGS_MASK) { return EBADF; /* Unsupported flags set */ } - /* Validate bands */ - if (config->n_bands == 0 || config->n_bands > MAX_BANDS) { - return EINVAL; /* Too many bands */ - } - - /* Validate rates */ - for (i = 0; i < config->n_bands; i++) { - if (config->bands[i].rate == 0) { - return EDOM; /* rate must be non-zero */ - } + if (config->n_bands > MAX_BANDS) { + return EINVAL; } for (i = 0; i < config->n_bands; ++i) { diff --git a/lib/dpif.c b/lib/dpif.c index d78330bef3b8..c267bcfb0c55 100644 --- a/lib/dpif.c +++ b/lib/dpif.c @@ -1895,11 +1895,27 @@ int dpif_meter_set(struct dpif *dpif, ofproto_meter_id *meter_id, struct ofputil_meter_config *config) { - int error; - COVERAGE_INC(dpif_meter_set); - error = dpif->dpif_class->meter_set(dpif, meter_id, config); + if (!(config->flags & (OFPMF13_KBPS | OFPMF13_PKTPS))) { + return EBADF; /* Rate unit type not set. */ + } + + if ((config->flags & OFPMF13_KBPS) && (config->flags & OFPMF13_PKTPS)) { + return EBADF; /* Both rate units may not be set. */ + } + + if (config->n_bands == 0) { + return EINVAL; + } + + for (size_t i = 0; i < config->n_bands; i++) { + if (config->bands[i].rate == 0) { + return EDOM; /* Rate must be non-zero */ + } + } + + int error = dpif->dpif_class->meter_set(dpif, meter_id, config); if (!error) { VLOG_DBG_RL(&dpmsg_rl, "%s: DPIF meter %"PRIu32" set", dpif_name(dpif), meter_id->uint32);