From patchwork Thu Aug 29 17:55:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 1155448 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="Qlz0e/dy"; 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 46K9ND5wl3z9sMr for ; Fri, 30 Aug 2019 03:59:08 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 426C84BF4; Thu, 29 Aug 2019 17:56:41 +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 542E94BAD for ; Thu, 29 Aug 2019 17:55:40 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f195.google.com (mail-pl1-f195.google.com [209.85.214.195]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id B75F5EC for ; Thu, 29 Aug 2019 17:55:39 +0000 (UTC) Received: by mail-pl1-f195.google.com with SMTP id go14so1931634plb.0 for ; Thu, 29 Aug 2019 10:55:39 -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; bh=IaeIpQGpWaG4215qFjVkk7r3SiLd2LOkUCs6Yj/Z2FI=; b=Qlz0e/dywpvN58tr8TgLTahk7eg9wI1M7DKponaE6WTplOv/AhuQsirrFqkj8A/Y5S Cza5wD0aG25iSl4+z5XsMNR3Hi1yBJ2KbLBRV73MPBtKhcE5NsANHndOkcFpzY7qICtT iNIGbPhjgeyrCi3/9jToeLWuTUn3y9+xBCrFlVGhofoZC35IKX3IB8U9vj6nx6svE5a+ XRPPkLnBbGgmD97+QITVKIzrzZUSi0cWvNZ2/OIgVJHMFWGtGGFc1flBe4gQDLTtNmZo FWeqVwvL/trS/PLUxDOKfuhJ31tJqi4j95hr0+gz/JfYwBttXlYzog7S6YNmSMcR4u8R 60AQ== 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; bh=IaeIpQGpWaG4215qFjVkk7r3SiLd2LOkUCs6Yj/Z2FI=; b=tVOhNbGSTIbo94bk1oDq9ZVCxuI9DqUuonS0lr2a82BDatqd/qUuOqwgfV+mI5Mgj9 aSBobQK6MYWbVb6AOo6/HC0HgBmmeslWsZp/A7sR9YgGBDULl81Jb4oNisswBKwbNJPt j59gxuEkO+S4oN1vfHh3R5869nfXT8JXs9UJDXYT2VKFYej7SkHOxjpJoM1qLApWcsI3 Ck8Z3ZpVYHKmIk+dP+z2iXEjfNzTu6zgtlhYsZ9Bq+o3rGdOt/VGdEYuPzFPA/PkEqF7 SHnmiZILInoe/pEVwsP3wSkaEE38UCppnj4hRhO4dpLhQwSmTdUtz6YlqdV1ZkYAWSuY yMsw== X-Gm-Message-State: APjAAAVX/U0Gb6axG1vTa13PguLkdm9XYZfwj8j9jG183T/TsSDyWFXL 6Hfncwh3Xf1i0Y9VNp5nJ4zErTy4 X-Google-Smtp-Source: APXvYqxIpvBUWp+S0fZN2CkQAowo842yNZ/DXzKYkqr5uq2PzlA/nRTfQRagg6pwb51Q+HixCr5aaA== X-Received: by 2002:a17:902:1e8:: with SMTP id b95mr11359310plb.28.1567101338927; Thu, 29 Aug 2019 10:55:38 -0700 (PDT) Received: from gizo.domain (97-115-90-227.ptld.qwest.net. [97.115.90.227]) by smtp.gmail.com with ESMTPSA id s3sm5857429pgq.17.2019.08.29.10.55.37 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 10:55:38 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org, jpettit@ovn.org Date: Thu, 29 Aug 2019 10:55:33 -0700 Message-Id: <1567101334-27785-1-git-send-email-gvrose8192@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH branch-2.5 1/2] datapath: Properly set L4 keys on "later" IP fragments 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 Upstream commit: commit ad06a566e118e57b852cab5933dbbbaebb141de3 Author: Greg Rose Date: Tue Aug 27 07:58:09 2019 -0700 openvswitch: Properly set L4 keys on "later" IP fragments When IP fragments are reassembled before being sent to conntrack, the key from the last fragment is used. Unless there are reordering issues, the last fragment received will not contain the L4 ports, so the key for the reassembled datagram won't contain them. This patch updates the key once we have a reassembled datagram. The handle_fragments() function works on L3 headers so we pull the L3/L4 flow key update code from key_extract into a new function 'key_extract_l3l4'. Then we add a another new function ovs_flow_key_update_l3l4() and export it so that it is accessible by handle_fragments() for conntrack packet reassembly. Co-authored-by: Justin Pettit Signed-off-by: Greg Rose Acked-by: Pravin B Shelar Signed-off-by: David S. Miller Signed-off-by: Greg Rose Signed-off-by: Justin Pettit --- datapath/conntrack.c | 5 ++ datapath/flow.c | 141 ++++++++++++++++++++++++++++++++------------------- datapath/flow.h | 1 + 3 files changed, 95 insertions(+), 52 deletions(-) diff --git a/datapath/conntrack.c b/datapath/conntrack.c index 875e26a..87540ec 100644 --- a/datapath/conntrack.c +++ b/datapath/conntrack.c @@ -360,6 +360,11 @@ static int handle_fragments(struct net *net, struct sw_flow_key *key, return -EPFNOSUPPORT; } + /* The key extracted from the fragment that completed this datagram + * likely didn't have an L4 header, so regenerate it. + */ + ovs_flow_key_update_l3l4(skb, key); + key->ip.frag = OVS_FRAG_TYPE_NONE; skb_clear_hash(skb); skb->ignore_df = 1; diff --git a/datapath/flow.c b/datapath/flow.c index 057dde1..00618dd 100644 --- a/datapath/flow.c +++ b/datapath/flow.c @@ -432,63 +432,14 @@ invalid: } /** - * key_extract - extracts a flow key from an Ethernet frame. + * key_extract_l3l4 - extracts L3/L4 header information. * @skb: sk_buff that contains the frame, with skb->data pointing to the - * Ethernet header + * L3 header * @key: output flow key - * - * The caller must ensure that skb->len >= ETH_HLEN. - * - * Returns 0 if successful, otherwise a negative errno value. - * - * Initializes @skb header pointers as follows: - * - * - skb->mac_header: the Ethernet header. - * - * - skb->network_header: just past the Ethernet header, or just past the - * VLAN header, to the first byte of the Ethernet payload. - * - * - skb->transport_header: If key->eth.type is ETH_P_IP or ETH_P_IPV6 - * on output, then just past the IP header, if one is present and - * of a correct length, otherwise the same as skb->network_header. - * For other key->eth.type values it is left untouched. */ -static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) +static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key) { int error; - struct ethhdr *eth; - - /* Flags are always used as part of stats */ - key->tp.flags = 0; - - skb_reset_mac_header(skb); - - /* Link layer. We are guaranteed to have at least the 14 byte Ethernet - * header in the linear data area. - */ - eth = eth_hdr(skb); - ether_addr_copy(key->eth.src, eth->h_source); - ether_addr_copy(key->eth.dst, eth->h_dest); - - __skb_pull(skb, 2 * ETH_ALEN); - /* We are going to push all headers that we pull, so no need to - * update skb->csum here. - */ - - key->eth.tci = 0; - if (skb_vlan_tag_present(skb)) - key->eth.tci = htons(vlan_get_tci(skb)); - else if (eth->h_proto == htons(ETH_P_8021Q)) - if (unlikely(parse_vlan(skb, key))) - return -ENOMEM; - - key->eth.type = parse_ethertype(skb); - if (unlikely(key->eth.type == htons(0))) - return -ENOMEM; - - skb_reset_network_header(skb); - skb_reset_mac_len(skb); - __skb_push(skb, skb->data - skb_mac_header(skb)); /* Network layer. */ if (key->eth.type == htons(ETH_P_IP)) { @@ -680,6 +631,92 @@ static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) return 0; } +/** + * key_extract - extracts a flow key from an Ethernet frame. + * @skb: sk_buff that contains the frame, with skb->data pointing to the + * Ethernet header + * @key: output flow key + * + * The caller must ensure that skb->len >= ETH_HLEN. + * + * Returns 0 if successful, otherwise a negative errno value. + * + * Initializes @skb header fields as follows: + * + * - skb->mac_header: the L2 header. + * + * - skb->network_header: just past the L2 header, or just past the + * VLAN header, to the first byte of the L2 payload. + * + * - skb->transport_header: If key->eth.type is ETH_P_IP or ETH_P_IPV6 + * on output, then just past the IP header, if one is present and + * of a correct length, otherwise the same as skb->network_header. + * For other key->eth.type values it is left untouched. + * + * - skb->protocol: the type of the data starting at skb->network_header. + * Equals to key->eth.type. + */ +static int key_extract(struct sk_buff *skb, struct sw_flow_key *key) +{ + struct ethhdr *eth; + + /* Flags are always used as part of stats */ + key->tp.flags = 0; + + skb_reset_mac_header(skb); + + /* Link layer. */ + clear_vlan(key); + if (ovs_key_mac_proto(key) == MAC_PROTO_NONE) { + if (unlikely(eth_type_vlan(skb->protocol))) + return -EINVAL; + + skb_reset_network_header(skb); + key->eth.type = skb->protocol; + } else { + eth = eth_hdr(skb); + ether_addr_copy(key->eth.src, eth->h_source); + ether_addr_copy(key->eth.dst, eth->h_dest); + + __skb_pull(skb, 2 * ETH_ALEN); + /* We are going to push all headers that we pull, so no need to + * update skb->csum here. + */ + + if (unlikely(parse_vlan(skb, key))) + return -ENOMEM; + + key->eth.type = parse_ethertype(skb); + if (unlikely(key->eth.type == htons(0))) + return -ENOMEM; + + /* Multiple tagged packets need to retain TPID to satisfy + * skb_vlan_pop(), which will later shift the ethertype into + * skb->protocol. + */ + if (key->eth.cvlan.tci & htons(VLAN_CFI_MASK)) + skb->protocol = key->eth.cvlan.tpid; + else + skb->protocol = key->eth.type; + + skb_reset_network_header(skb); + __skb_push(skb, skb->data - skb_mac_header(skb)); + } + + skb_reset_mac_len(skb); + + /* Fill out L3/L4 key info, if any */ + return key_extract_l3l4(skb, key); +} + +/* In the case of conntrack fragment handling it expects L3 headers, + * add a helper. + */ +int ovs_flow_key_update_l3l4(struct sk_buff *skb, struct sw_flow_key *key) +{ + return key_extract_l3l4(skb, key); +} + int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key) { return key_extract(skb, key); diff --git a/datapath/flow.h b/datapath/flow.h index c0b628a..02b0cbb 100644 --- a/datapath/flow.h +++ b/datapath/flow.h @@ -217,6 +217,7 @@ u64 ovs_flow_used_time(unsigned long flow_jiffies); /* Update the non-metadata part of the flow key using skb. */ int ovs_flow_key_update(struct sk_buff *skb, struct sw_flow_key *key); +int ovs_flow_key_update_l3l4(struct sk_buff *skb, struct sw_flow_key *key); int ovs_flow_key_extract(const struct ip_tunnel_info *tun_info, struct sk_buff *skb, struct sw_flow_key *key); From patchwork Thu Aug 29 17:55:34 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gregory Rose X-Patchwork-Id: 1155449 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="W4KO3U+z"; 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 46K9Np518Xz9sML for ; Fri, 30 Aug 2019 03:59:38 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id DD1D24BFB; Thu, 29 Aug 2019 17:56:41 +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 2A8BB4BAD for ; Thu, 29 Aug 2019 17:55:41 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pg1-f194.google.com (mail-pg1-f194.google.com [209.85.215.194]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id D7D64EC for ; Thu, 29 Aug 2019 17:55:40 +0000 (UTC) Received: by mail-pg1-f194.google.com with SMTP id x15so1973694pgg.8 for ; Thu, 29 Aug 2019 10:55:40 -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=am1m4QTFLoArSofqyR/y0IZCLgtvGCza+knuAsABI74=; b=W4KO3U+zcd+mSo2+/qRA9dvNDqRzuTCziP53UDOf7oHI7XCpASocypGJV208BoaufA Qezqu0dv7/CanNVCknU+0O8f0pjrVRze+BEvkt4iY3ON7SvdGNjfjEpMmH+UWOttuMH/ wW0KFEDBpIBh0DPhOKdvIHQ5ISf+3RmRJFodt5FrZaw4UiAW/gkpO5KszqMS8xMLL+7s iugeSg2c2qN8XkbXIre0BWjRbB4vZtPxt93d4CwsPN4YTq0RPnZWcboTEDtgZRIQ4fth zjGNWFtI4rhm0VXVIvWH5JNB/aLfbUskJkNMbswrow7d6k3hA/JC8+ngg26vbqypeqTD eL9g== 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=am1m4QTFLoArSofqyR/y0IZCLgtvGCza+knuAsABI74=; b=fN1mCjUz5Oin1zvvZ0yxwkKJ1tpJAgYOqI/lQXM69IgsG0aHfxKVQo8sCOcUzeq/6h zGoHZ8CUeEYDSFJA3gI86aKmKJtXd0yBXyFNdokRErQ2QyqlNDSeoqQxrPFqOULnnsBQ r4WUKK4DjALdJy9x2pGfKOfyqGRjCuP2lWTVhfWUdEOUGWBkpapggT5BCeOZyG4V9bkx Reh/pWcByKMX0geUGVm1qztb75wiEcmXIH2Q1KmId99NvLNhJRpfUAPPYaA3EZIuowH+ 6wVvIm8UA7kW9p9E0fVRcVEKdBpgDnvHUgrwc6mbMjMXuTlkbbwpSe0N06lI92CZDsmE 2usQ== X-Gm-Message-State: APjAAAWGQQhn3puWmbqD1aX6tpS7uGDNNATUB3N4nwShAkQ9JEOy/poK 8RRFc7C947Wak8g0jL7pn/fdwymZ X-Google-Smtp-Source: APXvYqyZQtuQTkU2H41mNdH4/wYS/zYmEIPQ5GCvoj5ENZCt59aJxUAd84SPo2b8fjJQHmWQfhCYSg== X-Received: by 2002:a65:4489:: with SMTP id l9mr9723055pgq.207.1567101340041; Thu, 29 Aug 2019 10:55:40 -0700 (PDT) Received: from gizo.domain (97-115-90-227.ptld.qwest.net. [97.115.90.227]) by smtp.gmail.com with ESMTPSA id s3sm5857429pgq.17.2019.08.29.10.55.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 29 Aug 2019 10:55:39 -0700 (PDT) From: Greg Rose To: dev@openvswitch.org, jpettit@ovn.org Date: Thu, 29 Aug 2019 10:55:34 -0700 Message-Id: <1567101334-27785-2-git-send-email-gvrose8192@gmail.com> X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1567101334-27785-1-git-send-email-gvrose8192@gmail.com> References: <1567101334-27785-1-git-send-email-gvrose8192@gmail.com> X-Spam-Status: No, score=-1.7 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_ENVFROM_END_DIGIT,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=no version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH branch-2.5 2/2] datapath: Clear the L4 portion of the key for "later" fragments 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: Justin Pettit Upstream commit: commit 0754b4e8cdf3eec6e4122e79af26ed9bab20f8f8 Author: Justin Pettit Date: Tue Aug 27 07:58:10 2019 -0700 openvswitch: Clear the L4 portion of the key for "later" fragments. Only the first fragment in a datagram contains the L4 headers. When the Open vSwitch module parses a packet, it always sets the IP protocol field in the key, but can only set the L4 fields on the first fragment. The original behavior would not clear the L4 portion of the key, so garbage values would be sent in the key for "later" fragments. This patch clears the L4 fields in that circumstance to prevent sending those garbage values as part of the upcall. Signed-off-by: Justin Pettit Acked-by: Pravin B Shelar Signed-off-by: David S. Miller Signed-off-by: Greg Rose Signed-off-by: Justin Pettit --- datapath/flow.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/datapath/flow.c b/datapath/flow.c index 00618dd..c23ad9e 100644 --- a/datapath/flow.c +++ b/datapath/flow.c @@ -468,6 +468,7 @@ static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key) offset = nh->frag_off & htons(IP_OFFSET); if (offset) { key->ip.frag = OVS_FRAG_TYPE_LATER; + memset(&key->tp, 0, sizeof(key->tp)); return 0; } if (nh->frag_off & htons(IP_MF) || @@ -587,8 +588,11 @@ static int key_extract_l3l4(struct sk_buff *skb, struct sw_flow_key *key) return error; } - if (key->ip.frag == OVS_FRAG_TYPE_LATER) + if (key->ip.frag == OVS_FRAG_TYPE_LATER) { + memset(&key->tp, 0, sizeof(key->tp)); return 0; + } +#ifdef HAVE_SKB_GSO_UDP if (skb_shinfo(skb)->gso_type & SKB_GSO_UDP) key->ip.frag = OVS_FRAG_TYPE_FIRST;