From patchwork Wed Dec 18 06:47:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Varghese X-Patchwork-Id: 1211995 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="WpiFi+P2"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47d5PD42gLz9sS9 for ; Wed, 18 Dec 2019 17:55:28 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726520AbfLRGz1 (ORCPT ); Wed, 18 Dec 2019 01:55:27 -0500 Received: from mail-pf1-f193.google.com ([209.85.210.193]:38943 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725797AbfLRGz1 (ORCPT ); Wed, 18 Dec 2019 01:55:27 -0500 Received: by mail-pf1-f193.google.com with SMTP id q10so674934pfs.6 for ; Tue, 17 Dec 2019 22:55:26 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=bzIfo5QToARCZWLeqG3x/wMqUmg7NXaLyDxKE0gqU2E=; b=WpiFi+P243pgZwyZZX1fE4hheEMWsNjMJ2xiHkNJvjgWmVYBWKCgtgcAO/AhFJXr1M CkgOe4ne7PWJKswPpIIrgUj2B7oNrejXMO3726H1CiDJ7uMbZsTrGrGf+/DNB4yX3mW5 eZbM35DyLAiYcqEqp5beVXIGjtRKHpkC82aqbXk2kY91vzyesmLNl4o9Z2iac/ahJUly Ds1to5xwBiQsy6WzaYHdufG5xh5Kw95Hew0uFmtGud0eZbMLgAQbIqhtdFZGuCnux6eH bFHgvUu0UQZVGsQGJiYNhxV52Ejk12Yi4HVlUbdP+/48yR/R3SeHosuwvzkPlQoYnOf+ GZXg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=bzIfo5QToARCZWLeqG3x/wMqUmg7NXaLyDxKE0gqU2E=; b=TJce1y3gqa4QoqhMRUplDNMfC3jXWw/KBkv46uIUDNWTC1j/KtTPopaTJOB5iUlFWe UXC+AcD2ouHE8RFS61CnKmAgpOLj4UZBz6JwzkJhKWoDLeZ/9yz6gaaPtza4gim8howt RAiMc6Y/e3vYzKs03hW/Sw9BIvFIzuWZ6JtDj2bpOt1InyV/3SFPejJqWXemasUMuK2L I6W03IwVwndx+0Hc3p46poj16YZQFbGhUd7HnXrvX/fVYJrn4WlqQ1fg0duKS4W+wDMB KeBig3AG7SsRSHFzCT6NmzJDtlo0s87IsmDe4knaHPpwNB2TEm8AqxJ16SeJxYqiqXhp T7Kg== X-Gm-Message-State: APjAAAVcEFR5o4VIXPQ3cPkXQaSQRCdOgO35LGKbfwsAJidmC+WIVzTv nXoLtv5DtvrvYU8M+Wt7geyOLlDq X-Google-Smtp-Source: APXvYqzjcUizAzcj4XiqmGBTd60EDhwTT5rN9brGZgQ8vXQSlVVsswIppMOe4PwC6PlfU0Ud73P2NQ== X-Received: by 2002:a62:4ec6:: with SMTP id c189mr1293397pfb.159.1576652126399; Tue, 17 Dec 2019 22:55:26 -0800 (PST) Received: from localhost.localdomain ([122.182.209.142]) by smtp.gmail.com with ESMTPSA id d24sm1555570pfq.75.2019.12.17.22.55.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Dec 2019 22:55:25 -0800 (PST) From: Martin Varghese To: netdev@vger.kernel.org, davem@davemloft.net, pshelar@ovn.org, scott.drennan@nokia.com, jbenc@redhat.com, martin.varghese@nokia.com Subject: [PATCH net-next v4 1/3] net: skb_mpls_push() modified to allow MPLS header push at start of packet. Date: Wed, 18 Dec 2019 12:17:50 +0530 Message-Id: <5dbc2dbc222ff778861ef08b4e0a68a49a7afeb1.1576648350.git.martin.varghese@nokia.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Martin Varghese The existing skb_mpls_push() implementation always inserts mpls header after the mac header. L2 VPN use cases requires MPLS header to be inserted before the ethernet header as the ethernet packet gets tunnelled inside MPLS header in those cases. Signed-off-by: Martin Varghese --- Changes in v2: - Fixed comments section of skb_mpls_push(). - Added skb_reset_mac_len() in skb_mpls_push(). The mac len changes when MPLS header in inserted at the start of the packet. net/core/skbuff.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index 973a71f..d90c827 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5472,12 +5472,15 @@ static void skb_mod_eth_type(struct sk_buff *skb, struct ethhdr *hdr, } /** - * skb_mpls_push() - push a new MPLS header after the mac header + * skb_mpls_push() - push a new MPLS header after mac_len bytes from start of + * the packet * * @skb: buffer * @mpls_lse: MPLS label stack entry to push * @mpls_proto: ethertype of the new MPLS header (expects 0x8847 or 0x8848) * @mac_len: length of the MAC header + * @ethernet: flag to indicate if the resulting packet after skb_mpls_push is + * ethernet * * Expects skb->data at mac header. * @@ -5501,7 +5504,7 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto, return err; if (!skb->inner_protocol) { - skb_set_inner_network_header(skb, mac_len); + skb_set_inner_network_header(skb, skb_network_offset(skb)); skb_set_inner_protocol(skb, skb->protocol); } @@ -5510,6 +5513,7 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto, mac_len); skb_reset_mac_header(skb); skb_set_network_header(skb, mac_len); + skb_reset_mac_len(skb); lse = mpls_hdr(skb); lse->label_stack_entry = mpls_lse; From patchwork Wed Dec 18 06:48:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Varghese X-Patchwork-Id: 1211996 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="tWNGVOmD"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47d5Pf0Ht5z9sR0 for ; Wed, 18 Dec 2019 17:55:50 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726641AbfLRGzs (ORCPT ); Wed, 18 Dec 2019 01:55:48 -0500 Received: from mail-pl1-f193.google.com ([209.85.214.193]:46956 "EHLO mail-pl1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725799AbfLRGzs (ORCPT ); Wed, 18 Dec 2019 01:55:48 -0500 Received: by mail-pl1-f193.google.com with SMTP id y8so527455pll.13 for ; Tue, 17 Dec 2019 22:55:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=b3hiJ3A3rMjBROFjEn7dlrVf4haGfG2YX4vYzJvUu0g=; b=tWNGVOmDpdCV/cL+mR1c3efXP7iMoERShzb18ZXMnuG9ssqfS1rNeUONB6dLWD7214 O48Zv+3ICcXno/HTXDSB3RbdY6QxoKwpysYobPFGMMXZka9jjMWTcn9kw/JnMBTU5CGN ybdzPnxv2quCH6x8w6bxn0fgXtVYNccel57cpY+ez0S7RyJcy5kJibf4wVrJi2EoHZii gm74kYjoHfjJ0I0H21hrlY3EmE/xsQBc+QjwoDmtanNUf5wUYLkmwMvdmg6NSoPHJBl2 qPjk34EDqaJ/5cjw63iPGnReFQ4ibFWDxh03Fbyp8ycbkRY03d6BcVIQN0i91Eq0dxI8 sYhw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=b3hiJ3A3rMjBROFjEn7dlrVf4haGfG2YX4vYzJvUu0g=; b=M37mj5mCZfd8XIHQ0XOr0G2MHvUQdL8YtNsMdGF9gOQJjypAN3kbhsncfPh1bqMS7q 4EbQvZ9+Q7+fDU0SZZ65GyTDgnaJ1/IAspdPxeotrAtugFF2gmRpy9es1hXYPY7WeBHL ycZNm8oEIj8hLwTM0WPlFKxnuJnadiKMtoSnBr8VYOqvW1K2xXL8rFWUA+lwY1nG9lnt Xy/JHJtyXy6oB9a8T6IpsrIrziHf68AGEjAJzPLyC8gQN3SkH79nMBTQVrKuQIpkGVLf TAQqEycNtD88HmUhilvU/0by6TlwAt/UoFJUoxaOgQun0MiGwN6If/7Ek5UQYBjue+Tn 0vUw== X-Gm-Message-State: APjAAAXSfNNXdY8qeSD4xro+9Zi/GXV+F1o3rGwgll5UHqAXDwlwvCh5 J7RlEU2MhpdQGzH8hDjmyr4WHoxf X-Google-Smtp-Source: APXvYqxZd3YkPfjPub8/Yw5LfDBNjKtVMtAwD2H9cYlfn/G9ggla/olwcUx0iZPX4MI9Vkkvqb20Gg== X-Received: by 2002:a17:902:12c:: with SMTP id 41mr1034836plb.160.1576652147732; Tue, 17 Dec 2019 22:55:47 -0800 (PST) Received: from localhost.localdomain ([122.182.209.142]) by smtp.gmail.com with ESMTPSA id y144sm1473739pfb.188.2019.12.17.22.55.45 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Dec 2019 22:55:47 -0800 (PST) From: Martin Varghese To: netdev@vger.kernel.org, davem@davemloft.net, pshelar@ovn.org, scott.drennan@nokia.com, jbenc@redhat.com, martin.varghese@nokia.com Subject: [PATCH net-next v4 2/3] net: Rephrased comments section of skb_mpls_pop() Date: Wed, 18 Dec 2019 12:18:11 +0530 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Martin Varghese Rephrased comments section of skb_mpls_pop() to align it with comments section of skb_mpls_push(). Signed-off-by: Martin Varghese --- net/core/skbuff.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/net/core/skbuff.c b/net/core/skbuff.c index d90c827..44b0894 100644 --- a/net/core/skbuff.c +++ b/net/core/skbuff.c @@ -5533,7 +5533,7 @@ int skb_mpls_push(struct sk_buff *skb, __be32 mpls_lse, __be16 mpls_proto, * @skb: buffer * @next_proto: ethertype of header after popped MPLS header * @mac_len: length of the MAC header - * @ethernet: flag to indicate if ethernet header is present in packet + * @ethernet: flag to indicate if the packet is ethernet * * Expects skb->data at mac header. * From patchwork Wed Dec 18 06:48:38 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Varghese X-Patchwork-Id: 1211997 X-Patchwork-Delegate: davem@davemloft.net Return-Path: X-Original-To: patchwork-incoming-netdev@ozlabs.org Delivered-To: patchwork-incoming-netdev@ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="H7rDdKM3"; dkim-atps=neutral Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id 47d5QC55z3z9sS9 for ; Wed, 18 Dec 2019 17:56:19 +1100 (AEDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726709AbfLRG4R (ORCPT ); Wed, 18 Dec 2019 01:56:17 -0500 Received: from mail-pg1-f195.google.com ([209.85.215.195]:40279 "EHLO mail-pg1-f195.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725991AbfLRG4Q (ORCPT ); Wed, 18 Dec 2019 01:56:16 -0500 Received: by mail-pg1-f195.google.com with SMTP id k25so735822pgt.7 for ; Tue, 17 Dec 2019 22:56:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=+E2tHh3PlsozlJKxVBujqed7OziRZZeh0g8FuYWyqIo=; b=H7rDdKM3HLNvyZoqDzHWbsNKeckod2jL/l9sHg5fngeSc1v1YGiy50gg2qmr07ZEsd +lwiQl9i2GPdRA0qfUKB4XrqGuiCLQ7YVq7ZYVAJ/9pzuH5qVGZURF/Sp5wk2fGo2th8 NA1WUdhdfM1NK6ATmaAVvI49bZR+LiNxZNuootr0icPANHE8Xtp6ZkLGCHCWIAQJEUbz mXv5fTgCmLEbNRRzy2vkMNQJeIJ6kHdVPMg8UDulm56R7heG+STuAgclc/4uGPsyrjc2 5bm3tbYFeljabdVWAC9jz5Z6LPxxV+d0DoMRXCLUsGO0Td+F6aQGOPGD3DjYkhTRYgPF uU0w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=+E2tHh3PlsozlJKxVBujqed7OziRZZeh0g8FuYWyqIo=; b=nQCsJrwfrujzcez1US6cn+7neVYJirw2rP0quvs0BvNcP03HPy1olazlhY6c8e9iZY rZ2kONjE3WEzKskXut0HcT4jDqTCZVd03ZMwPxcttIslPw5bS011yj8Z+LhPZc+32z4h jLR6SJ4lPxLu9btRZWkT9G8Qy5tSmUYRUe/PZDkcYeetgWbIKbRnzEqEZDc5Yax7/ZXo yW9Wrs/5WRrnN3kh8abJDosHQ7k57QNowE8bqxzYiZK0WUMqbItfWGGaUi0duX5lJVNs ByXUuTfk7/tfY2PPYXfRBCQgiUOtg+tIkE2qDO8hjxmxNFtyQliZuhcvUgEFHiy9r4I9 SVug== X-Gm-Message-State: APjAAAUQ4fxjmigj8SI3pg0jfW6vSp/8Lf5Ujy5Ldtoa4kOqcg9gQWk9 uPtc8AWavjCj3NTIf2+wZiveASOl X-Google-Smtp-Source: APXvYqz2XKQx9TQJSFGIxIyCnjii+tQ/3nUPCcYLZisbCX8CYNtVDcQ6woSXeiBGJgr7omMW++aWVQ== X-Received: by 2002:aa7:8f33:: with SMTP id y19mr1296121pfr.47.1576652175284; Tue, 17 Dec 2019 22:56:15 -0800 (PST) Received: from localhost.localdomain ([122.182.209.142]) by smtp.gmail.com with ESMTPSA id x21sm1464498pfn.164.2019.12.17.22.56.13 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 17 Dec 2019 22:56:14 -0800 (PST) From: Martin Varghese To: netdev@vger.kernel.org, davem@davemloft.net, pshelar@ovn.org, scott.drennan@nokia.com, jbenc@redhat.com, martin.varghese@nokia.com Subject: [PATCH net-next v4 3/3] openvswitch: New MPLS actions for layer 2 tunnelling Date: Wed, 18 Dec 2019 12:18:38 +0530 Message-Id: X-Mailer: git-send-email 1.9.1 In-Reply-To: References: Sender: netdev-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: netdev@vger.kernel.org From: Martin Varghese The existing PUSH MPLS action inserts MPLS header between ethernet header and the IP header. Though this behaviour is fine for L3 VPN where an IP packet is encapsulated inside a MPLS tunnel, it does not suffice the L2 VPN (l2 tunnelling) requirements. In L2 VPN the MPLS header should encapsulate the ethernet packet. The new mpls action PTAP_PUSH_MPLS inserts MPLS header at the start of the packet or at the start of the l3 header depending on the value of l2 tunnel flag in the PTAP_PUSH_MPLS arguments. POP_MPLS action is extended to support ethertype 0x6558. Signed-off-by: Martin Varghese --- Changes in v2: - PTAP_POP_MPLS action removed. - Special handling for ethertype 0 added in PUSH_MPLS. - Refactored push_mpls function to cater existing push_mpls and ptap_push_mpls actions. - mac len to specify the MPLS header location added in PTAP_PUSH_MPLS arguments. Changes in v3: - Special handling for ethertype 0 removed. - Added support for ether type 0x6558. - Removed mac len from PTAP_PUSH_MPLS argument list - used l2_tun flag to distinguish l2 and l3 tunnelling. - Extended PTAP_PUSH_MPLS handling to cater PUSH_MPLS action also. Changes in v4: - Removed extra blank lines. - Replaced bool l2_tun with u16 tun flags in struct ovs_action_ptap_push_mpls. include/uapi/linux/openvswitch.h | 31 +++++++++++++++++++++++++++++++ net/openvswitch/actions.c | 30 ++++++++++++++++++++++++------ net/openvswitch/flow_netlink.c | 34 ++++++++++++++++++++++++++++++++++ 3 files changed, 89 insertions(+), 6 deletions(-) diff --git a/include/uapi/linux/openvswitch.h b/include/uapi/linux/openvswitch.h index a87b44c..d9461ce 100644 --- a/include/uapi/linux/openvswitch.h +++ b/include/uapi/linux/openvswitch.h @@ -673,6 +673,32 @@ struct ovs_action_push_mpls { }; /** + * struct ovs_action_ptap_push_mpls - %OVS_ACTION_ATTR_PTAP_PUSH_MPLS action + * argument. + * @mpls_lse: MPLS label stack entry to push. + * @mpls_ethertype: Ethertype to set in the encapsulating ethernet frame. + * @tun_flags: MPLS tunnel attributes. + * + * The only values @mpls_ethertype should ever be given are %ETH_P_MPLS_UC and + * %ETH_P_MPLS_MC, indicating MPLS unicast or multicast. Other are rejected. + */ +struct ovs_action_ptap_push_mpls { + __be32 mpls_lse; + __be16 mpls_ethertype; /* Either %ETH_P_MPLS_UC or %ETH_P_MPLS_MC */ + __u16 tun_flags; +}; + +#define OVS_MPLS_L2_TUNNEL_FLAG_MASK (1 << 0) /* Flag to specify the place of + * insertion of MPLS header. + * When true, the MPLS header + * will be inserted at the start + * of the packet. + * When false, the MPLS header + * will be inserted at the start + * of the l3 header. + */ + +/** * struct ovs_action_push_vlan - %OVS_ACTION_ATTR_PUSH_VLAN action argument. * @vlan_tpid: Tag protocol identifier (TPID) to push. * @vlan_tci: Tag control identifier (TCI) to push. The CFI bit must be set @@ -892,6 +918,10 @@ struct check_pkt_len_arg { * @OVS_ACTION_ATTR_CHECK_PKT_LEN: Check the packet length and execute a set * of actions if greater than the specified packet length, else execute * another set of actions. + * @OVS_ACTION_ATTR_PTAP_PUSH_MPLS: Push a new MPLS label stack entry at the + * start of the packet or at the start of the l3 header depending on the value + * of l2 tunnel flag in the tun_flags field of OVS_ACTION_ATTR_PTAP_PUSH_MPLS + * argument. * * Only a single header can be set with a single %OVS_ACTION_ATTR_SET. Not all * fields within a header are modifiable, e.g. the IPv4 protocol and fragment @@ -927,6 +957,7 @@ enum ovs_action_attr { OVS_ACTION_ATTR_METER, /* u32 meter ID. */ OVS_ACTION_ATTR_CLONE, /* Nested OVS_CLONE_ATTR_*. */ OVS_ACTION_ATTR_CHECK_PKT_LEN, /* Nested OVS_CHECK_PKT_LEN_ATTR_*. */ + OVS_ACTION_ATTR_PTAP_PUSH_MPLS, /* struct ovs_action_ptap_push_mpls. */ __OVS_ACTION_ATTR_MAX, /* Nothing past this will be accepted * from userspace. */ diff --git a/net/openvswitch/actions.c b/net/openvswitch/actions.c index 4c83954..24c12ad 100644 --- a/net/openvswitch/actions.c +++ b/net/openvswitch/actions.c @@ -161,16 +161,17 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, const struct nlattr *attr, int len); static int push_mpls(struct sk_buff *skb, struct sw_flow_key *key, - const struct ovs_action_push_mpls *mpls) + __be32 mpls_lse, __be16 mpls_ethertype, __u16 mac_len) { int err; - err = skb_mpls_push(skb, mpls->mpls_lse, mpls->mpls_ethertype, - skb->mac_len, - ovs_key_mac_proto(key) == MAC_PROTO_ETHERNET); + err = skb_mpls_push(skb, mpls_lse, mpls_ethertype, mac_len, !!mac_len); if (err) return err; + if (!mac_len) + key->mac_proto = MAC_PROTO_NONE; + invalidate_flow_key(key); return 0; } @@ -185,6 +186,9 @@ static int pop_mpls(struct sk_buff *skb, struct sw_flow_key *key, if (err) return err; + if (ethertype == htons(ETH_P_TEB)) + key->mac_proto = MAC_PROTO_ETHERNET; + invalidate_flow_key(key); return 0; } @@ -1229,10 +1233,24 @@ static int do_execute_actions(struct datapath *dp, struct sk_buff *skb, execute_hash(skb, key, a); break; - case OVS_ACTION_ATTR_PUSH_MPLS: - err = push_mpls(skb, key, nla_data(a)); + case OVS_ACTION_ATTR_PUSH_MPLS: { + struct ovs_action_push_mpls *mpls = nla_data(a); + + err = push_mpls(skb, key, mpls->mpls_lse, + mpls->mpls_ethertype, skb->mac_len); break; + } + case OVS_ACTION_ATTR_PTAP_PUSH_MPLS: { + struct ovs_action_ptap_push_mpls *mpls = nla_data(a); + __u16 mac_len = 0; + + if (!(mpls->tun_flags & OVS_MPLS_L2_TUNNEL_FLAG_MASK)) + mac_len = skb->mac_len; + err = push_mpls(skb, key, mpls->mpls_lse, + mpls->mpls_ethertype, mac_len); + break; + } case OVS_ACTION_ATTR_POP_MPLS: err = pop_mpls(skb, key, nla_get_be16(a)); break; diff --git a/net/openvswitch/flow_netlink.c b/net/openvswitch/flow_netlink.c index 65c2e34..85fe7df 100644 --- a/net/openvswitch/flow_netlink.c +++ b/net/openvswitch/flow_netlink.c @@ -79,6 +79,7 @@ static bool actions_may_change_flow(const struct nlattr *actions) case OVS_ACTION_ATTR_SET_MASKED: case OVS_ACTION_ATTR_METER: case OVS_ACTION_ATTR_CHECK_PKT_LEN: + case OVS_ACTION_ATTR_PTAP_PUSH_MPLS: default: return true; } @@ -3005,6 +3006,7 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, [OVS_ACTION_ATTR_METER] = sizeof(u32), [OVS_ACTION_ATTR_CLONE] = (u32)-1, [OVS_ACTION_ATTR_CHECK_PKT_LEN] = (u32)-1, + [OVS_ACTION_ATTR_PTAP_PUSH_MPLS] = sizeof(struct ovs_action_ptap_push_mpls), }; const struct ovs_action_push_vlan *vlan; int type = nla_type(a); @@ -3072,6 +3074,33 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, case OVS_ACTION_ATTR_RECIRC: break; + case OVS_ACTION_ATTR_PTAP_PUSH_MPLS: { + const struct ovs_action_ptap_push_mpls *mpls = nla_data(a); + + if (!eth_p_mpls(mpls->mpls_ethertype)) + return -EINVAL; + + if (!(mpls->tun_flags & OVS_MPLS_L2_TUNNEL_FLAG_MASK)) { + if (vlan_tci & htons(VLAN_CFI_MASK) || + (eth_type != htons(ETH_P_IP) && + eth_type != htons(ETH_P_IPV6) && + eth_type != htons(ETH_P_ARP) && + eth_type != htons(ETH_P_RARP) && + !eth_p_mpls(eth_type))) + return -EINVAL; + mpls_label_count++; + } else { + if (mac_proto != MAC_PROTO_NONE) { + mpls_label_count = 1; + mac_proto = MAC_PROTO_NONE; + } else { + mpls_label_count++; + } + } + eth_type = mpls->mpls_ethertype; + break; + } + case OVS_ACTION_ATTR_PUSH_MPLS: { const struct ovs_action_push_mpls *mpls = nla_data(a); @@ -3109,6 +3138,11 @@ static int __ovs_nla_copy_actions(struct net *net, const struct nlattr *attr, * recirculation. */ proto = nla_get_be16(a); + + if (proto == htons(ETH_P_TEB) && + mac_proto != MAC_PROTO_NONE) + return -EINVAL; + mpls_label_count--; if (!eth_p_mpls(proto) || !mpls_label_count)