From patchwork Thu Jan 25 21:20:11 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Tu X-Patchwork-Id: 866030 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming@ozlabs.org Delivered-To: patchwork-incoming@ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=vger.kernel.org (client-ip=209.132.180.67; helo=vger.kernel.org; envelope-from=netdev-owner@vger.kernel.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="AtxZhBIy"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 3zSFLk6TqLz9s7F for ; Fri, 26 Jan 2018 08:20:30 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751482AbeAYVU2 (ORCPT ); Thu, 25 Jan 2018 16:20:28 -0500 Received: from mail-pg0-f65.google.com ([74.125.83.65]:34350 "EHLO mail-pg0-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751462AbeAYVUZ (ORCPT ); Thu, 25 Jan 2018 16:20:25 -0500 Received: by mail-pg0-f65.google.com with SMTP id r19so5882203pgn.1 for ; Thu, 25 Jan 2018 13:20:25 -0800 (PST) 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=nsckgFSZVzg+L8w8abkYCL90xhxrkdJpq+8oQH0Mnug=; b=AtxZhBIy2DlDoaSD+t3WgFBUo17lrSdE9goe6jH7ZfZJaUckSqiqfDzFhfeYiSCBrN jw974XylQXR46THMj0uLtr58q5XYV62mGlMdJUmMtUPzA2oSIOB6LsubYBm5O6NuHfD8 t2EJk5K23f8EHmu9TIe3r3CXlMlaBBTqKBXF7rOXkZps530HRgDw6LJ+gUtMAf9I+TmH 0HfnH+wYHym9aN/YF/rHt5WCSS14TogfwKTJ2lHO0UCJA/i6YUcRi+luPznZInNg2jpt MmaqWlSlx7TRYwZb5T7aFibXgbfTQobs/YNBx7pCBG6xDPv29fmIR+khUrXnzAXcbf8A 4UQA== 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=nsckgFSZVzg+L8w8abkYCL90xhxrkdJpq+8oQH0Mnug=; b=sHrq7Xh0j8aMfw1ISktGI98iGhMNbD+JYyhKMfo/cvAU5rw9rtIe5QhaP2P5t+YrqQ GSgni/18HfhHpdbzt5oJc9VguZEaYux8ICdVvuSacUg8pAtLDCgVpTDwt519hRJLTfWl 14ou7Ef9CUqN7jzHAUWG1bbHcE88v57dgHsyjlxShGcMmOk/L8eFikgViNFaCXcz9N59 mCBRVbQwfwL0wjwlzoAYwbv7bIJImhImDCRCAqcmokdTIBeO98EvnuUjfnb1C/wF5Idh NYDEuDPtFgQjn3WWZZ05wsU5/q7nhnAhAuBHLeKmvu8q7G4p3FaWkmEbTsdhBU2+15iu EO5g== X-Gm-Message-State: AKwxytczw6mQTEX4arTBD52pjAk3bRfrjfFTRc8ixiElzlD2q0IgnjI5 kyAzg0H4KYI5WtnTxJB8r3DIXShc X-Google-Smtp-Source: AH8x224gebvic5/sjsPpw/xcL6vIUirbeE9Xr9s+/JIWQDMmtac4Iho1A2xlnIWHiTBhF3AWfqM6Ug== X-Received: by 10.98.211.21 with SMTP id q21mr16847729pfg.89.1516915225213; Thu, 25 Jan 2018 13:20:25 -0800 (PST) Received: from sc9-mailhost2.vmware.com ([24.5.191.4]) by smtp.gmail.com with ESMTPSA id t8sm5881980pgr.21.2018.01.25.13.20.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 25 Jan 2018 13:20:24 -0800 (PST) From: William Tu To: netdev@vger.kernel.org Cc: pshelar@ovn.org Subject: [PATCHv6 net-next 3/3] openvswitch: add erspan version I and II support Date: Thu, 25 Jan 2018 13:20:11 -0800 Message-Id: <1516915211-5869-4-git-send-email-u9012063@gmail.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1516915211-5869-1-git-send-email-u9012063@gmail.com> References: <1516915211-5869-1-git-send-email-u9012063@gmail.com> Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org The patch adds support for openvswitch to configure erspan v1 and v2. The OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS attr is added to uapi as a binary blob to support all ERSPAN v1 and v2's fields. Note that Previous commit "openvswitch: Add erspan tunnel support." was reverted since it does not design properly. Signed-off-by: William Tu Acked-by: Pravin B Shelar --- include/uapi/linux/openvswitch.h | 1 + net/openvswitch/flow_netlink.c | 52 +++++++++++++++++++++++++++++++++++++++- 2 files changed, 52 insertions(+), 1 deletion(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index dcfab5e3b55c..713e56ce681f 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -363,6 +363,7 @@ enum ovs_tunnel_key_attr { OVS_TUNNEL_KEY_ATTR_IPV6_SRC, /* struct in6_addr src IPv6 address. */ OVS_TUNNEL_KEY_ATTR_IPV6_DST, /* struct in6_addr dst IPv6 address. */ OVS_TUNNEL_KEY_ATTR_PAD, + OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS, /* struct erspan_metadata */ __OVS_TUNNEL_KEY_ATTR_MAX }; diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index eb55f1b3d047..7322aa1e382e 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -49,6 +49,7 @@ #include #include #include +#include #include "flow_netlink.h" @@ -329,7 +330,8 @@ size_t ovs_tun_key_attr_size(void) + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_CSUM */ + nla_total_size(0) /* OVS_TUNNEL_KEY_ATTR_OAM */ + nla_total_size(256) /* OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS */ - /* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS is mutually exclusive with + /* OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS and + * OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS is mutually exclusive with * OVS_TUNNEL_KEY_ATTR_GENEVE_OPTS and covered by it. */ + nla_total_size(2) /* OVS_TUNNEL_KEY_ATTR_TP_SRC */ @@ -400,6 +402,7 @@ static const struct ovs_len_tbl ovs_tunnel_key_lens[OVS_TUNNEL_KEY_ATTR_MAX + 1] .next = ovs_vxlan_ext_key_lens }, [OVS_TUNNEL_KEY_ATTR_IPV6_SRC] = { .len = sizeof(struct in6_addr) }, [OVS_TUNNEL_KEY_ATTR_IPV6_DST] = { .len = sizeof(struct in6_addr) }, + [OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS] = { .len = OVS_ATTR_VARIABLE }, }; static const struct ovs_len_tbl @@ -631,6 +634,33 @@ static int vxlan_tun_opt_from_nlattr(const struct nlattr *attr, return 0; } +static int erspan_tun_opt_from_nlattr(const struct nlattr *a, + struct sw_flow_match *match, bool is_mask, + bool log) +{ + unsigned long opt_key_offset; + + BUILD_BUG_ON(sizeof(struct erspan_metadata) > + sizeof(match->key->tun_opts)); + + if (nla_len(a) > sizeof(match->key->tun_opts)) { + OVS_NLERR(log, "ERSPAN option length err (len %d, max %zu).", + nla_len(a), sizeof(match->key->tun_opts)); + return -EINVAL; + } + + if (!is_mask) + SW_FLOW_KEY_PUT(match, tun_opts_len, + sizeof(struct erspan_metadata), false); + else + SW_FLOW_KEY_PUT(match, tun_opts_len, 0xff, true); + + opt_key_offset = TUN_METADATA_OFFSET(nla_len(a)); + SW_FLOW_KEY_MEMCPY_OFFSET(match, opt_key_offset, nla_data(a), + nla_len(a), is_mask); + return 0; +} + static int ip_tun_from_nlattr(const struct nlattr *attr, struct sw_flow_match *match, bool is_mask, bool log) @@ -738,6 +768,20 @@ static int ip_tun_from_nlattr(const struct nlattr *attr, break; case OVS_TUNNEL_KEY_ATTR_PAD: break; + case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS: + if (opts_type) { + OVS_NLERR(log, "Multiple metadata blocks provided"); + return -EINVAL; + } + + err = erspan_tun_opt_from_nlattr(a, match, is_mask, + log); + if (err) + return err; + + tun_flags |= TUNNEL_ERSPAN_OPT; + opts_type = type; + break; default: OVS_NLERR(log, "Unknown IP tunnel attribute %d", type); @@ -862,6 +906,10 @@ static int __ip_tun_to_nlattr(struct sk_buff *skb, else if (output->tun_flags & TUNNEL_VXLAN_OPT && vxlan_opt_to_nlattr(skb, tun_opts, swkey_tun_opts_len)) return -EMSGSIZE; + else if (output->tun_flags & TUNNEL_ERSPAN_OPT && + nla_put(skb, OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS, + swkey_tun_opts_len, tun_opts)) + return -EMSGSIZE; } return 0; @@ -2486,6 +2534,8 @@ static int validate_and_copy_set_tun(const struct nlattr *attr, break; case OVS_TUNNEL_KEY_ATTR_VXLAN_OPTS: break; + case OVS_TUNNEL_KEY_ATTR_ERSPAN_OPTS: + break; } }