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)) { From patchwork Thu Dec 14 13:13:35 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 848528 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="QSqdMkhI"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="F/RbgJ1o"; 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 3yyDZj2VNHz9s7B for ; Fri, 15 Dec 2017 00:15:41 +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:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hena2fJR9Knt7H/E4k36rSdIJZiKU21fWqEfqIuxsh8=; b=QSqdMkhIKbEJCi D8/JNUwJ3/qaWa8U1znY/aoNUypQoIyw/8/m7mUI7bQL7cxQ2b88M4R76tuy+Y3TUPlfO5/xlz8F2 z7qvEMRZnFB3qPg86RbIdtj22dqdkD5q25cAZH1kgc/CcDzF8/Vm0GhaycgV3e4WWgki4s4obysw+ +Pa0nN6asHZYrqqC8pp9haQpdyCOrRlBHwlik91wEREqcHsoZQ+c+1lw4yissh+FUhbPrU9bevw/I Md2Kd/H37MYru+9DjeFnzcEfcIzkxfy3ukFDoFeZZ4b1ea2dEJvogOuVbJS0ZH94pt/S1g7vjIEdN gK3CLhUlwKeMOy9ZhWeg==; 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 1ePTMG-0005I1-QS; Thu, 14 Dec 2017 13:15:28 +0000 Received: from mail-wr0-x241.google.com ([2a00:1450:400c:c0c::241]) by bombadil.infradead.org with esmtps (Exim 4.87 #1 (Red Hat Linux)) id 1ePTKx-0002Mi-W3 for lede-dev@lists.infradead.org; Thu, 14 Dec 2017 13:14:28 +0000 Received: by mail-wr0-x241.google.com with SMTP id h1so5089120wre.12 for ; Thu, 14 Dec 2017 05:13:44 -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:in-reply-to:references; bh=jVP1BLK6tkYZOam9rHENIBdXARntKoHdJeT8ai/AvNw=; b=F/RbgJ1owhUD52h0taomboEjGbtuky4dwivOHgsnmblH3hqgq1sGVyJGALAu4rrnee dUJWxN46KPyaWnMoRVtOC0TFmDNFTfcosukGXmN7E4TnSXgRMJMEjX3sgGNtfQRdaxtS dztadjnK8WtzuCBbU8qgoIup+XtzhXJfSy3rfdwAt8jr3GKlTomqcReq9O8RzHwnccs3 YlAZhpWdFZJWS2re438cc1Pid5hScfA6m7dnlAM+6yJ3SnqJxWq+sUyNjWYWzj+DmvsF 2qshHPxEA2k91XlGVIQuslWE0KPQhCXsl9GKE4GZRjlc0LOehpMMcekB8Pchm05U4QEA cLrA== 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=jVP1BLK6tkYZOam9rHENIBdXARntKoHdJeT8ai/AvNw=; b=rvYfvge+r3rwCBXIDsKD/K2eVjp/EQM/vAVXY+H+dp5IxkbFKW8JCKZWtVe0loOp3E jlrALno/RrdpLfy4QcUAb+Zj3PYCQFoU3nwk2/lJQnqFc9cOXZhEkDs40aK3TD/4O6MI /MynDG1bD30hBHdiDXOOqnM+ewkI1v1NaY47jWLgUxX3/ar6Tn0l1va4LOEobPajGMQ0 6QzE2h0N0ZkMj08L2JKdVqLBWGFSBpO5UrG5rPnlEe0XqZpqYeCpz0Ssm7imT5kQ9Dfq Y8nksQAla4BwBfvMB86e97rnD15boAXVNGckGDoIuoPR75zvMZgAaLZvyIsXYKC1d0OD 8kuw== X-Gm-Message-State: AKGB3mKXCOpZRYtOUnwQHrIaQyxkcxyaRKHc+RUD0oiXDeChPr2Q/795 XaEPKKJFtEzSDa/tH/cW56KqDA== X-Google-Smtp-Source: ACJfBotiJ7D3I6PTWxgDUiChjr5FSOjangyFnNKnbnQaDK8+kzHHKvIK33a3HHz60oKAA02GkOnFcA== X-Received: by 10.223.141.134 with SMTP id o6mr5766533wrb.95.1513257222724; Thu, 14 Dec 2017 05:13:42 -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.41 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Thu, 14 Dec 2017 05:13:41 -0800 (PST) From: Hans Dedecker To: nbd@nbd.name, john@phrozen.org, lede-dev@lists.infradead.org Date: Thu, 14 Dec 2017 14:13:35 +0100 Message-Id: <1513257215-26220-2-git-send-email-dedeckeh@gmail.com> X-Mailer: git-send-email 1.9.1 In-Reply-To: <1513257215-26220-1-git-send-email-dedeckeh@gmail.com> References: <1513257215-26220-1-git-send-email-dedeckeh@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20171214_051408_953833_F46D3224 X-CRM114-Status: GOOD ( 13.78 ) 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:c0c:0:0:0:241 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 2/2 netifd] interface-ip: harden eui64 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 Check if a mac address is actually present when generating an eui64 based IPv6 address; in case of failure bail out. At the same time make sure the active mac address is used as input for the eui64 based IPv6 address and guarantee IPv6 prefix address generation is based on the actual config by resetting the IPv6 prefix address in the assignment structure when it gets deleted. Signed-off-by: Hans Dedecker --- device.c | 2 +- device.h | 1 + interface-ip.c | 26 ++++++++++++++++++++++---- 3 files changed, 24 insertions(+), 5 deletions(-) diff --git a/device.c b/device.c index 0424658..a851037 100644 --- a/device.c +++ b/device.c @@ -193,7 +193,7 @@ struct device_type simple_device_type = { .free = simple_device_free, }; -static void +void device_merge_settings(struct device *dev, struct device_settings *n) { struct device_settings *os = &dev->orig_settings; diff --git a/device.h b/device.h index f398dbc..07f1dbd 100644 --- a/device.h +++ b/device.h @@ -244,6 +244,7 @@ int device_type_add(struct device_type *devtype); struct device_type *device_type_get(const char *tname); struct device *device_create(const char *name, struct device_type *type, struct blob_attr *config); +void device_merge_settings(struct device *dev, struct device_settings *n); void device_init_settings(struct device *dev, struct blob_attr **tb); void device_init_pending(void); diff --git a/interface-ip.c b/interface-ip.c index 716a093..dcf3390 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -712,9 +712,16 @@ random_ifaceid(struct in6_addr *addr) addr->s6_addr32[3] = (uint32_t)mrand48(); } -static void +static bool eui64_ifaceid(struct interface *iface, struct in6_addr *addr) { + struct device_settings st; + + device_merge_settings(iface->l3_dev.dev, &st); + + if (!(st.flags & DEV_OPT_MACADDR)) + return false; + /* get mac address */ uint8_t *macaddr = iface->l3_dev.dev->settings.macaddr; uint8_t *ifaceid = addr->s6_addr + 8; @@ -723,11 +730,15 @@ eui64_ifaceid(struct interface *iface, struct in6_addr *addr) ifaceid[3] = 0xff; ifaceid[4] = 0xfe; ifaceid[0] ^= 0x02; + + return true; } -static void +static bool generate_ifaceid(struct interface *iface, struct in6_addr *addr) { + bool ret = true; + /* generate new iface id */ switch (iface->assignment_iface_id_selection) { case IFID_FIXED: @@ -741,9 +752,13 @@ generate_ifaceid(struct interface *iface, struct in6_addr *addr) break; case IFID_EUI64: /* eui64 */ - eui64_ifaceid(iface, addr); + ret = eui64_ifaceid(iface, addr); + break; + default: + ret = false; break; } + return ret; } static void @@ -797,12 +812,15 @@ interface_set_prefix_address(struct device_prefix_assignment *assignment, system_del_route(l3_downlink, &route); system_add_address(l3_downlink, &addr); + assignment->addr = in6addr_any; assignment->enabled = false; } 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); + if (!generate_ifaceid(iface, &addr.addr.in6)) + return; + assignment->addr = addr.addr.in6; route.addr = addr.addr; }