From patchwork Mon Jul 10 19:39:52 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Eric Garver X-Patchwork-Id: 786339 X-Patchwork-Delegate: joestringer@nicira.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.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 3x5wZ55Sncz9s7m for ; Tue, 11 Jul 2017 05:41:17 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id A1FCDB62; Mon, 10 Jul 2017 19:40:05 +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 AB9B9A86 for ; Mon, 10 Jul 2017 19:40:02 +0000 (UTC) X-Greylist: from auto-whitelisted by SQLgrey-1.7.6 Received: from mx1.redhat.com (mx1.redhat.com [209.132.183.28]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 44E9F1F5 for ; Mon, 10 Jul 2017 19:40:02 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 767DD4E4C3; Mon, 10 Jul 2017 19:40:01 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 767DD4E4C3 Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=erig.me Authentication-Results: ext-mx09.extmail.prod.ext.phx2.redhat.com; spf=none smtp.mailfrom=e@erig.me DKIM-Filter: OpenDKIM Filter v2.11.0 mx1.redhat.com 767DD4E4C3 Received: from dev-rhel7.localdomain (wsfd-netdev-vmhost.ntdv.lab.eng.bos.redhat.com [10.19.17.17]) by smtp.corp.redhat.com (Postfix) with ESMTP id E33A117276; Mon, 10 Jul 2017 19:40:00 +0000 (UTC) From: Eric Garver To: dev@openvswitch.org Date: Mon, 10 Jul 2017 15:39:52 -0400 Message-Id: <20170710194000.21627-3-e@erig.me> In-Reply-To: <20170710194000.21627-1-e@erig.me> References: <20170710194000.21627-1-e@erig.me> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.38]); Mon, 10 Jul 2017 19:40:01 +0000 (UTC) X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00,RCVD_IN_DNSWL_HI 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 02/10] dpif-netlink: For non-Ethernet, use Ethertype from packet_type 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 For non-Ethernet flows, when fixing up the netlink message we need make sure to pass down a valid Ethertype. The kernel does not understand packet_type so it's implicitly encoded by the absence of _ETHERNET and exact match of _ETHERTYPE. Without this change match_validate in the kernel complains when trying to match packets from L3 tunnels. e.g. openvswitch: netlink: Unexpected mask (mask=110088, allowed=3d9804c) The mask use to always be set in xlate_wc_init() and xlate_wc_finish(), but that changed for non-Ethernet frames with the commit listed in Fixes. Fixes: 3d4b2e6eb74e ("userspace: Add OXM field MFF_PACKET_TYPE") Signed-off-by: Eric Garver --- lib/dpif-netlink.c | 48 ++++++++++++++++++++++++++++++++---------------- 1 file changed, 32 insertions(+), 16 deletions(-) diff --git a/lib/dpif-netlink.c b/lib/dpif-netlink.c index 562f6134c3a5..e7201233380f 100644 --- a/lib/dpif-netlink.c +++ b/lib/dpif-netlink.c @@ -3434,31 +3434,47 @@ dpif_netlink_flow_from_ofpbuf(struct dpif_netlink_flow *flow, /* - * If PACKET_TYPE attribute is present in 'data', it filters PACKET_TYPE out, - * then puts 'data' to 'buf'. + * If PACKET_TYPE attribute is present in 'data', it filters PACKET_TYPE out. + * If the flow is not Ethernet, packet_type is converted to ETHERTYPE. + * Puts 'data' to 'buf'. */ static void put_exclude_packet_type(struct ofpbuf *buf, uint16_t type, - const struct nlattr *data, uint16_t data_len) + const struct nlattr *data, size_t data_len) { const struct nlattr *packet_type; packet_type = nl_attr_find__(data, data_len, OVS_KEY_ATTR_PACKET_TYPE); if (packet_type) { - /* exclude PACKET_TYPE Netlink attribute. */ - ovs_assert(NLA_ALIGN(packet_type->nla_len) == NL_A_U32_SIZE); - size_t packet_type_len = NL_A_U32_SIZE; - size_t first_chunk_size = (uint8_t *)packet_type - (uint8_t *)data; - size_t second_chunk_size = data_len - first_chunk_size - - packet_type_len; - uint8_t *first_attr = NULL; - struct nlattr *next_attr = nl_attr_next(packet_type); - - first_attr = nl_msg_put_unspec_uninit(buf, type, - data_len - packet_type_len); - memcpy(first_attr, data, first_chunk_size); - memcpy(first_attr + first_chunk_size, next_attr, second_chunk_size); + struct odputil_keybuf new_attrs_buf; + const struct nlattr *ethernet; + struct nlattr *new_attrs; + size_t new_attrs_len; + + new_attrs = (struct nlattr *) &new_attrs_buf; + memcpy(new_attrs, data, data_len); + new_attrs_len = data_len; + + nl_attr_filter(new_attrs, &new_attrs_len, OVS_KEY_ATTR_PACKET_TYPE); + + /* If it's not Ethernet, then we need to override or add the Ethertype + * with the one from the packet_type. */ + ethernet = nl_attr_find__(data, data_len, OVS_KEY_ATTR_ETHERNET); + if (!ethernet) { + ovs_be32 packet_type_value = nl_attr_get_be32(packet_type); + struct ofpbuf new_buf; + + nl_attr_filter(new_attrs, &new_attrs_len, OVS_KEY_ATTR_ETHERTYPE); + + ofpbuf_use_stack(&new_buf, new_attrs, sizeof new_attrs_buf); + nl_msg_put_uninit(&new_buf, new_attrs_len); + nl_msg_put_be16(&new_buf, OVS_KEY_ATTR_ETHERTYPE, + pt_ns_type_be(packet_type_value)); + new_attrs_len = new_buf.size; + } + + nl_msg_put_unspec(buf, type, new_attrs, new_attrs_len); } else { nl_msg_put_unspec(buf, type, data, data_len); }