From patchwork Tue Jan 7 16:50:06 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Lorenzo Bianconi X-Patchwork-Id: 1218910 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.b="alNfw3bP"; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47sdgD5LQbz9sRf for ; Wed, 8 Jan 2020 03:51:04 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 5CBCA86005; Tue, 7 Jan 2020 16:51:02 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id RNZYtb53ZCch; Tue, 7 Jan 2020 16:51:00 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 9C9EA85FC4; Tue, 7 Jan 2020 16:51:00 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 9361DC1D82; Tue, 7 Jan 2020 16:51:00 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from fraxinus.osuosl.org (smtp4.osuosl.org [140.211.166.137]) by lists.linuxfoundation.org (Postfix) with ESMTP id C219BC0881 for ; Tue, 7 Jan 2020 16:50:59 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by fraxinus.osuosl.org (Postfix) with ESMTP id AE25985569 for ; Tue, 7 Jan 2020 16:50:59 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from fraxinus.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id sXvKwLCzDKDm for ; Tue, 7 Jan 2020 16:50:58 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by fraxinus.osuosl.org (Postfix) with ESMTPS id 377C585495 for ; Tue, 7 Jan 2020 16:50:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1578415826; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=+6Rw2S6Jn4dYXXaxmGIoyXHtzSVsLQE29QO0XF3P7OY=; b=alNfw3bPWywzM5gkXZIa66SauU30QHEcgYTqVAnNIDG5FasrKHewKWJHLWVFVymiiFVrf/ HBaYC4sRHpmHvEnZsVQWkduP5ql+BqZXQcM3YH3445Jl/HUTJkz36WOQjPJsyZoAuB/X5d zP6SBw9MRCCdqTfRomY4cTx7bL81jWM= Received: from mail-wr1-f70.google.com (mail-wr1-f70.google.com [209.85.221.70]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-241-mmCyQV-7PFSRXb2zraUepw-1; Tue, 07 Jan 2020 11:50:20 -0500 Received: by mail-wr1-f70.google.com with SMTP id l20so183883wrc.13 for ; Tue, 07 Jan 2020 08:50:20 -0800 (PST) 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:mime-version:content-transfer-encoding; bh=qFwmHvL5JD5CbR17BpsK+vcM39ls4LvO2Q9VzS0VKYY=; b=hLIF4UCe6QrhlAYdiEJm6WBeIfbkvq+dtK+l1KLaXBfNkOgDa+B6K36j33xTZdukwt 5jeouExV++ie7cfZbT+l6/EO8F7KhWKJS11hLFZbTzz8SNGQoeivDusorHVyTmIHpc4G u8gKfPGzqllGR2yMqVSackQtaYXrLbvp/SlA6sbriAwVu1VsgUB++JebqFi++OujJZEQ vJBdlJpZhINY7u1bI7TUOvyo3dhMyCdlt3ynklLzEeIEOAd6mPlo0vgAgD8ldKkrSOLv vWBMq0M3hpsKn9PBPiDbjMD3w9uU6osLvswWFw+9B36gU57FmQeeUVkjj40pfflKkdo0 aifg== X-Gm-Message-State: APjAAAXd8vd69XM2pjmSfW5lo+JXR2+mLLaSHXskyzfrCAz8ACFyP0x2 AqomfgEqYnUltobqiU3onwnwF3ybc7uIV5/4giEDMElTvcguwYVYgeK8gwbnqchZPPpc6VjBEUg y1Sr9yv7b0lpw X-Received: by 2002:adf:bc87:: with SMTP id g7mr1990572wrh.121.1578415819529; Tue, 07 Jan 2020 08:50:19 -0800 (PST) X-Google-Smtp-Source: APXvYqz8M4WWY4dAEry6mzVqxzT8723WPPFBhfB4alCUevtLxhhTs4TaEpa11rp58FKASpD1fJeGMA== X-Received: by 2002:adf:bc87:: with SMTP id g7mr1990553wrh.121.1578415819252; Tue, 07 Jan 2020 08:50:19 -0800 (PST) Received: from new-host-3.redhat.com (net-2-42-61-77.cust.vodafonedsl.it. [2.42.61.77]) by smtp.gmail.com with ESMTPSA id n1sm487436wrw.52.2020.01.07.08.50.18 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 07 Jan 2020 08:50:18 -0800 (PST) From: Lorenzo Bianconi To: dev@openvswitch.org Date: Tue, 7 Jan 2020 17:50:06 +0100 Message-Id: <8bc6b374e3a80fcac7a8a92951ae629ad6879d49.1578414443.git.lorenzo.bianconi@redhat.com> X-Mailer: git-send-email 2.21.1 In-Reply-To: References: MIME-Version: 1.0 X-MC-Unique: mmCyQV-7PFSRXb2zraUepw-1 X-Mimecast-Spam-Score: 0 Subject: [ovs-dev] [PATCH v2 ovn 2/2] RA Route Info Option: copy route info string in order to avoid truncated value X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" ipv6_ra_send can run 2 times in a row before prepare_ipv6_ras updates the route info. Copy route info string in packet_put_ra_route_info_opt in order to avoid sending truncated route info on the wire. Moreover move ip6_hdr definition just before accessing it because the packet can be reallocated if the data area is not big enough for packet content Fixes: 9f7f466af ("Add support for Route Info Option in RA - RFC 4191") Signed-off-by: Lorenzo Bianconi --- controller/pinctrl.c | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/controller/pinctrl.c b/controller/pinctrl.c index 1a577f62a..c4752c673 100644 --- a/controller/pinctrl.c +++ b/controller/pinctrl.c @@ -2469,13 +2469,14 @@ out: static void packet_put_ra_route_info_opt(struct dp_packet *b, ovs_be32 lifetime, - char *route_list) + char *route_data) { size_t prev_l4_size = dp_packet_l4_size(b); - struct ip6_hdr *nh = dp_packet_l3(b); - char *t0, *r0 = NULL; + char *route_list, *t0, *r0 = NULL; size_t size = 0; + route_list = xstrdup(route_data); + for (t0 = strtok_r(route_list, ",", &r0); t0; t0 = strtok_r(NULL, ",", &r0)) { struct ovs_nd_route_info nd_rinfo; @@ -2503,11 +2504,11 @@ packet_put_ra_route_info_opt(struct dp_packet *b, ovs_be32 lifetime, uint8_t plen; if (!extract_ip_addresses(t1, &route)) { - return; + goto out; } if (!route.n_ipv6_addrs) { destroy_lport_addresses(&route); - return; + goto out; } nd_rinfo.prefix_len = route.ipv6_addrs->plen; @@ -2522,17 +2523,20 @@ packet_put_ra_route_info_opt(struct dp_packet *b, ovs_be32 lifetime, break; } default: - return; + goto out; } } } + struct ip6_hdr *nh = dp_packet_l3(b); nh->ip6_plen = htons(prev_l4_size + size); struct ovs_ra_msg *ra = dp_packet_l4(b); ra->icmph.icmp6_cksum = 0; uint32_t icmp_csum = packet_csum_pseudoheader6(dp_packet_l3(b)); ra->icmph.icmp6_cksum = csum_finish(csum_continue(icmp_csum, ra, prev_l4_size + size)); +out: + free(route_list); } /* Called with in the pinctrl_handler thread context. */ @@ -2576,7 +2580,7 @@ ipv6_ra_send(struct rconn *swconn, struct ipv6_ra_state *ra) } if (ra->config->route_info.length) { packet_put_ra_route_info_opt(&packet, htonl(0xffffffff), - ra->config->route_info.string); + ds_cstr(&ra->config->route_info)); } uint64_t ofpacts_stub[4096 / 8];