From patchwork Tue May 23 23:02:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Joe Stringer X-Patchwork-Id: 766258 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 3wXWKm4gD5z9sNp for ; Wed, 24 May 2017 09:03:40 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 9FF84BD8; Tue, 23 May 2017 23:02:30 +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 25F79B5F for ; Tue, 23 May 2017 23:02:28 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay5-d.mail.gandi.net (relay5-d.mail.gandi.net [217.70.183.197]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 9D9CB1B4 for ; Tue, 23 May 2017 23:02:26 +0000 (UTC) Received: from mfilter19-d.gandi.net (mfilter19-d.gandi.net [217.70.178.147]) by relay5-d.mail.gandi.net (Postfix) with ESMTP id 9BD4B41C084 for ; Wed, 24 May 2017 01:02:25 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at mfilter19-d.gandi.net Received: from relay5-d.mail.gandi.net ([IPv6:::ffff:217.70.183.197]) by mfilter19-d.gandi.net (mfilter19-d.gandi.net [::ffff:10.0.15.180]) (amavisd-new, port 10024) with ESMTP id J4WvDiQ8ij-p for ; Wed, 24 May 2017 01:02:24 +0200 (CEST) X-Originating-IP: 64.134.227.17 Received: from archer.hil-sfofhhh02.sfo.wayport.net (ip-64-134-227-17.public.wayport.net [64.134.227.17]) (Authenticated sender: joe@ovn.org) by relay5-d.mail.gandi.net (Postfix) with ESMTPSA id B020D41C086 for ; Wed, 24 May 2017 01:02:23 +0200 (CEST) From: Joe Stringer To: dev@openvswitch.org Date: Tue, 23 May 2017 16:02:13 -0700 Message-Id: <20170523230216.29696-3-joe@ovn.org> X-Mailer: git-send-email 2.12.2 In-Reply-To: <20170523230216.29696-1-joe@ovn.org> References: <20170523230216.29696-1-joe@ovn.org> X-Spam-Status: No, score=-2.6 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_LOW 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 2/5] ofproto-dpif: Fix unaligned eth_addr pointers. 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 Clang 4.0 complains: ../ofproto/ofproto-dpif.c:2291:46: error: taking address of packed member 'eth_src' of class or structure 'eth_header' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member] netdev_get_etheraddr(ofport->up.netdev, ð->eth_src); ^~~~~~~~~~~~ ../ofproto/ofproto-dpif.c:2316:50: error: taking address of packed member 'eth_src' of class or structure 'eth_header' may result in an unaligned pointer value [-Werror,-Waddress-of-packed-member] netdev_get_etheraddr(ofport->up.netdev, ð->eth_src); Ethernet source addresses are 48 bits offset into the Ethernet header, so taking a pointer for this is not guaranteed to be valid on all architectures. Fix this by retrieving the mac address to the local stack and copying it into the header. Signed-off-by: Joe Stringer --- ofproto/ofproto-dpif.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c index dc5f004cd92d..5b866427f406 100644 --- a/ofproto/ofproto-dpif.c +++ b/ofproto/ofproto-dpif.c @@ -2287,13 +2287,15 @@ rstp_send_bpdu_cb(struct dp_packet *pkt, void *ofport_, void *ofproto_) struct ofproto_dpif *ofproto = ofproto_; struct ofport_dpif *ofport = ofport_; struct eth_header *eth = dp_packet_eth(pkt); + struct eth_addr mac; - netdev_get_etheraddr(ofport->up.netdev, ð->eth_src); - if (eth_addr_is_zero(eth->eth_src)) { + netdev_get_etheraddr(ofport->up.netdev, &mac); + if (eth_addr_is_zero(mac)) { VLOG_WARN_RL(&rl, "%s port %d: cannot send RSTP BPDU on a port which " "does not have a configured source MAC address.", ofproto->up.name, ofp_to_u16(ofport->up.ofp_port)); } else { + eth->eth_src = mac; ofproto_dpif_send_packet(ofport, false, pkt); } dp_packet_delete(pkt); @@ -2312,12 +2314,14 @@ send_bpdu_cb(struct dp_packet *pkt, int port_num, void *ofproto_) ofproto->up.name, port_num); } else { struct eth_header *eth = dp_packet_eth(pkt); + struct eth_addr mac; - netdev_get_etheraddr(ofport->up.netdev, ð->eth_src); - if (eth_addr_is_zero(eth->eth_src)) { + netdev_get_etheraddr(ofport->up.netdev, &mac); + if (eth_addr_is_zero(mac)) { VLOG_WARN_RL(&rl, "%s: cannot send BPDU on port %d " "with unknown MAC", ofproto->up.name, port_num); } else { + eth->eth_src = mac; ofproto_dpif_send_packet(ofport, false, pkt); } }