From patchwork Thu Dec 14 13:13:34 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 848529 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (mailfrom) smtp.mailfrom=lists.infradead.org (client-ip=65.50.211.133; helo=bombadil.infradead.org; envelope-from=lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="ptVo7z76"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="SSuT5wnx"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [65.50.211.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3yyDZm4xYgz9s7B for ; Fri, 15 Dec 2017 00:15:44 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:Message-Id: Date:To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=0/5WxwZpt557wTU10AkwA799nLeFAcpuXtjzbpMD3PQ=; b=ptVo7z76kpZCm3 r6/no+4Xog3X9LWHgdIv9vabXhWbGjMZt3GO+I8m/rCwPugn1pqqbwsjXgUgk9qsYrC0nIYhKKGyP gXGVkCQRiMM3c5ebUYljHuZdchfIEpZ63qTjJ1xnINhA9FRasuUAzArQW03hrah56tlFwmyXaPDci 5ddb77oaQUiqcp95dU6S/4gnT/ZjF6Mfvu7mo7WSqPHJJNZdOYxL7ReUKGiAYf5/JMWmvTrTnlWqq mVvNdYn/frqbrAC3Qjh4qFqI8nKcIqmsiHAzOENSE7wDUr8vsRUxh9hOGIokon5kH4LncNU56mVJy igLX7PMflYQAXMFzeMLA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.87 #1 (Red Hat Linux)) id 1ePTMU-0005SE-DU; Thu, 14 Dec 2017 13:15:42 +0000 Received: from mail-wm0-x242.google.com ([2a00:1450:400c:c09::242]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePTKx-0002Mx-LY for lede-dev@lists.infradead.org; Thu, 14 Dec 2017 13:14:40 +0000 Received: by mail-wm0-x242.google.com with SMTP id t8so11199389wmc.3 for ; Thu, 14 Dec 2017 05:13:45 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=oqaUEc4tT8vOInIxvRJzwSb33Bc2mbe1iAp3d+eZqdo=; b=SSuT5wnx49O99zD3AT7vzvipWkBtUYLty0XcaZYC0RapzCaNypJKdekV8TYkWcsA4S a5HPn8S+RkXsHueKvM2wt1vE5r6DLAjmnnFDfP7thfnlX7gEymHAwh7l+ZWXeaateJC9 u3b7ZH+6+JQ6E/mmW8PyWLjbK0n5cESFwJJcjY3ruEDocpM/8Y1xYdgRizYv3nvmZI9j uyzs7is63ajcwr5JLouAax7VmozPFDrLTiBEcz0C9K7nCw14oK/7M3YFmjqPa0KZcCGf I9TnHUD7rMRv8/YrwZMx0YT0HJQwQYLpFau1zPHzISlZ44mIw04ksfiTGs1nfaTDksPQ cYRA== 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=oqaUEc4tT8vOInIxvRJzwSb33Bc2mbe1iAp3d+eZqdo=; b=FzmyV+Rijnh7ozaEGa5J2Ai5kP4u5idTk7+zgg1SQsIZr4pFrnj3xT2IbEX5yLHI10 amxOLQ+wtTTgjy6n1hEd7nsFvE+QdnVdcHdbVmmo8i4vBypY0i5BeEuqJjP4qDqctjEe vXSxdSzjEKFUCzfvqK21DAfm2msQx8nPZFLu66LOD1/Swl9fqhUqO3DIjn71gyqZ2xEw X494jX8Qf2GeGXKb6WyzgGS+MFwiov3BKyEPXNuH5z0WWuM2zA14XQHs6wvkQtBodJIg CnSDzeIKzUocXXnCmpITUBuqZRpVbgj4HN0fa0BOdvSz4+sJz28t55LL6YpjCQXNHmDg 43ew== X-Gm-Message-State: AKGB3mLu2Wajqkf+G6CXkDGJn9CXNU+K8xdotsk/vWWtT+g0a7yNnFeK dwmmkxq318ACnnt9VfL37zE= X-Google-Smtp-Source: ACJfBotTGIVSSoWcOYm2NIEJCEbKsRCM9pOnrYkBZ98RGw3F8zf+t0Obi209wBLDSAouQ5WaKYTjvg== X-Received: by 10.28.178.85 with SMTP id b82mr2088138wmf.47.1513257220127; Thu, 14 Dec 2017 05:13:40 -0800 (PST) Received: from cplx43.eu.thmulti.com ([141.11.62.7]) by smtp.gmail.com with ESMTPSA id u194sm2991934wmd.6.2017.12.14.05.13.39 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Dec 2017 05:13:39 -0800 (PST) From: Hans Dedecker To: nbd@nbd.name, john@phrozen.org, lede-dev@lists.infradead.org Date: Thu, 14 Dec 2017 14:13:34 +0100 Message-Id: <1513257215-26220-1-git-send-email-dedeckeh@gmail.com> X-Mailer: git-send-email 1.9.1 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171214_051409_023493_EC32B49D X-CRM114-Status: GOOD ( 10.53 ) X-Spam-Score: -2.0 (--) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-2.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [2a00:1450:400c:c09:0:0:0:242 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedeckeh[at]gmail.com) -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [LEDE-DEV] [PATCH 1/2 netifd] interface-ip: fix race condition in IPv6 prefix address generation X-BeenThere: lede-dev@lists.infradead.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Dedecker MIME-Version: 1.0 Sender: "Lede-dev" Errors-To: lede-dev-bounces+incoming=patchwork.ozlabs.org@lists.infradead.org Don't generate an IPv6 prefix address without taking into account the interface state. In case eui64 is configured to generate the ifaceid this could fail as the layer3 device mac address could not yet be available if the interface is not yet in setup or up state. While at it remove the interface metric assignment as this is already done by the function interface_set_route_info. Signed-off-by: Hans Dedecker --- interface-ip.c | 33 +++++++++++++++++++-------------- 1 file changed, 19 insertions(+), 14 deletions(-) diff --git a/interface-ip.c b/interface-ip.c index 1490ca4..716a093 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -761,15 +761,7 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, memset(&addr, 0, sizeof(addr)); memset(&route, 0, sizeof(route)); - if (IN6_IS_ADDR_UNSPECIFIED(&assignment->addr)) { - addr.addr.in6 = prefix->addr; - addr.addr.in6.s6_addr32[1] |= htonl(assignment->assigned); - generate_ifaceid(iface, &addr.addr.in6); - assignment->addr = addr.addr.in6; - } - else - addr.addr.in6 = assignment->addr; - + addr.addr.in6 = assignment->addr; addr.mask = assignment->length; addr.flags = DEVADDR_INET6 | DEVADDR_OFFLINK; addr.preferred_until = prefix->preferred_until; @@ -778,11 +770,10 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, route.flags = DEVADDR_INET6; route.mask = addr.mask < 64 ? 64 : addr.mask; route.addr = addr.addr; - clear_if_addr(&route.addr, route.mask); - interface_set_route_info(iface, &route); if (!add && assignment->enabled) { time_t now = system_get_rtime(); + addr.preferred_until = now; if (!addr.valid_until || addr.valid_until - now > 7200) addr.valid_until = now + 7200; @@ -800,12 +791,24 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, addr.mask, 0, iface, "unreachable", true); } + clear_if_addr(&route.addr, route.mask); + interface_set_route_info(iface, &route); + system_del_route(l3_downlink, &route); system_add_address(l3_downlink, &addr); assignment->enabled = false; - } else if (add && (iface->state == IFS_UP || iface->state == IFS_SETUP) && - !system_add_address(l3_downlink, &addr)) { + } else if (add && (iface->state == IFS_UP || iface->state == IFS_SETUP)) { + if (IN6_IS_ADDR_UNSPECIFIED(&addr.addr.in6)) { + addr.addr.in6 = prefix->addr; + addr.addr.in6.s6_addr32[1] |= htonl(assignment->assigned); + generate_ifaceid(iface, &addr.addr.in6); + assignment->addr = addr.addr.in6; + route.addr = addr.addr; + } + + if (system_add_address(l3_downlink, &addr)) + return; if (!assignment->enabled) { if (iface->ip6table) @@ -822,7 +825,9 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, } } - route.metric = iface->metric; + clear_if_addr(&route.addr, route.mask); + interface_set_route_info(iface, &route); + system_add_route(l3_downlink, &route); if (uplink && uplink->l3_dev.dev && !(l3_downlink->settings.flags & DEV_OPT_MTU6)) {