From patchwork Wed Jun 20 00:22:40 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Justin Pettit X-Patchwork-Id: 931879 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 419QY40lrhz9s2L for ; Wed, 20 Jun 2018 10:23:35 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 24A35E62; Wed, 20 Jun 2018 00:23:33 +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 6230DD83 for ; Wed, 20 Jun 2018 00:23:31 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 5FB7E8A for ; Wed, 20 Jun 2018 00:23:30 +0000 (UTC) Received: from localhost.localdomain (unknown [76.21.1.228]) (Authenticated sender: jpettit@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 74E33100004; Wed, 20 Jun 2018 00:23:27 +0000 (UTC) From: Justin Pettit To: dev@openvswitch.org Date: Tue, 19 Jun 2018 17:22:40 -0700 Message-Id: <1529454160-88413-1-git-send-email-jpettit@ovn.org> X-Mailer: git-send-email 2.7.4 X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 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] datapath: Add meter action support. 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 From: Andy Zhou Upstream commit: commit cd8a6c33693c1b89d2737ffdbf9611564e9ac907 Author: Andy Zhou Date: Fri Nov 10 12:09:43 2017 -0800 openvswitch: Add meter action support Implements OVS kernel meter action support. Signed-off-by: Andy Zhou Signed-off-by: David S. Miller Signed-off-by: Justin Pettit Reviewed-by: Greg Rose Tested-by: Greg Rose --- NEWS | 5 +++-- datapath/actions.c | 6 ++++++ datapath/datapath.h | 1 + datapath/flow_netlink.c | 6 ++++++ datapath/linux/compat/include/linux/openvswitch.h | 2 +- 5 files changed, 17 insertions(+), 3 deletions(-) diff --git a/NEWS b/NEWS index 7f6589a46878..cd15a332c47e 100644 --- a/NEWS +++ b/NEWS @@ -19,8 +19,9 @@ Post-v2.9.0 * New OpenFlow 1.0 extensions for group support. * Default selection method for select groups is now dp_hash with improved accuracy. - - Linux kernel 4.14 - * Add support for compiling OVS with the latest Linux 4.14 kernel + - Linux datapath + * Add support for compiling OVS with the latest Linux 4.14 kernel. + * Added support for meters. - ovn: * implemented icmp4/icmp6/tcp_reset actions in order to drop the packet and reply with a RST for TCP or ICMPv4/ICMPv6 unreachable message for diff --git a/datapath/actions.c b/datapath/actions.c index eab147617c8b..56b013601393 100644 --- a/datapath/actions.c +++ b/datapath/actions.c @@ -1341,6 +1341,12 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, case OVS_ACTION_ATTR_POP_NSH: err = pop_nsh(skb, key); break; + + case OVS_ACTION_ATTR_METER: + if (ovs_meter_execute(dp, skb, key, nla_get_u32(a))) { + consume_skb(skb); + return 0; + } } if (unlikely(err)) { diff --git a/datapath/datapath.h b/datapath/datapath.h index 93c9ed505448..c38286df75c7 100644 --- a/datapath/datapath.h +++ b/datapath/datapath.h @@ -31,6 +31,7 @@ #include "compat.h" #include "flow.h" #include "flow_table.h" +#include "meter.h" #include "vport-internal_dev.h" #define DP_MAX_PORTS USHRT_MAX diff --git a/datapath/flow_netlink.c b/datapath/flow_netlink.c index 1b7bad8fe2ab..bea525a5dfcb 100644 --- a/datapath/flow_netlink.c +++ b/datapath/flow_netlink.c @@ -92,6 +92,7 @@ static bool actions_may_change_flow(const struct nlattr *actions) case OVS_ACTION_ATTR_SAMPLE: case OVS_ACTION_ATTR_SET: case OVS_ACTION_ATTR_SET_MASKED: + case OVS_ACTION_ATTR_METER: default: return true; } @@ -2853,6 +2854,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, [OVS_ACTION_ATTR_POP_ETH] = 0, [OVS_ACTION_ATTR_PUSH_NSH] = (u32)-1, [OVS_ACTION_ATTR_POP_NSH] = 0, + [OVS_ACTION_ATTR_METER] = sizeof(u32), }; const struct ovs_action_push_vlan *vlan; int type = nla_type(a); @@ -3038,6 +3040,10 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, break; } + case OVS_ACTION_ATTR_METER: + /* Non-existent meters are simply ignored. */ + break; + default: OVS_NLERR(log, "Unknown Action type %d", type); return -EINVAL; diff --git a/datapath/linux/compat/include/linux/openvswitch.h b/datapath/linux/compat/include/linux/openvswitch.h index 5c1e2383f4f9..8e5f3b6fbfb1 100644 --- a/datapath/linux/compat/include/linux/openvswitch.h +++ b/datapath/linux/compat/include/linux/openvswitch.h @@ -934,12 +934,12 @@ enum ovs_action_attr { OVS_ACTION_ATTR_CT_CLEAR, /* No argument. */ OVS_ACTION_ATTR_PUSH_NSH, /* Nested OVS_NSH_KEY_ATTR_*. */ OVS_ACTION_ATTR_POP_NSH, /* No argument. */ + OVS_ACTION_ATTR_METER, /* u32 meter number. */ #ifndef __KERNEL__ OVS_ACTION_ATTR_TUNNEL_PUSH, /* struct ovs_action_push_tnl*/ OVS_ACTION_ATTR_TUNNEL_POP, /* u32 port number. */ OVS_ACTION_ATTR_CLONE, /* Nested OVS_CLONE_ATTR_*. */ - OVS_ACTION_ATTR_METER, /* u32 meter number. */ #endif __OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted * from userspace. */