From patchwork Tue Oct 26 21:59:52 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 1546636 X-Patchwork-Delegate: nbd@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=3pOhzIUF; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=mMUrWJMg; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hf5Vj3G3yz9sX3 for ; Wed, 27 Oct 2021 09:05:48 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=XAAToPx+blsSkgjNSUuMCL5eWSNX4zEP4u4XmcVoxpo=; b=3pOhzIUF+FtZWD 6jWrkRpiX8FMMzHzQRQM0nFDvoyyMDdnz6cb+RKjUn9mViOHMRV9CnGMLxk30o4bd0+PhJxlN+RoP hip6ox2otWPbTdiIktl29OyB7nDEnJnkjfVngH1adzc/Gj//99DWNJFcgsiLfpZPPnQSk5INN6U1m ea4GHvEPUSC9c4HqPWNPMuA1EoL2p+9xNwhGuHuxNKTr9uN68pDDK7DyxiMDJ4VMj0HDG0nrgY2HX l3IYgegACJMkIe4YtSA2aVWOML8yVvRYeo+r2T0S3rF6XP95PU6Ptxp7dFJKTsXiK0a05gflBE2ca 6hjj5F5QRKbCTTvdY0Bw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfUUY-003B7l-Tn; Tue, 26 Oct 2021 22:00:23 +0000 Received: from mail-qt1-x834.google.com ([2607:f8b0:4864:20::834]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfUUT-003B7U-QX for openwrt-devel@lists.openwrt.org; Tue, 26 Oct 2021 22:00:19 +0000 Received: by mail-qt1-x834.google.com with SMTP id w2so729186qtn.0 for ; Tue, 26 Oct 2021 15:00:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LjCXSBV2NcGetCbamgc7fbY8iGW49jdHI9M7U6UAYZE=; b=mMUrWJMgBF9h/9hkAJC82TjhMXtasMDAkdVVRu93yg9eLdWK2gD3zgJP6ftkaJuXd2 wfvMNwajX9HTmntb0p9503FruWBu5Ia8CwaLwYuKATPnLddw/F2UwZLCx6k5xs5jdurq FeL6NFsW0rOsGuEAMm6sR1LLXlOo85N7R2x5GEFrqQojDiTCJtYWYk1Upx4Xkup1OJik 6fKs7fRvZuma5274DChkdmFlHTiFSLd/h5BxLWA3T48dGUIrrnFIOcsaBJJ9Yq+w29Zy liQzfPmvBw4fgutEWqOuFRFxIsNdVuJmUPGYBrpS1uNY62RNZxqPcBFlLZkhj9cn21BJ jR4g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=LjCXSBV2NcGetCbamgc7fbY8iGW49jdHI9M7U6UAYZE=; b=tMqmBst6HWSBPiKS8MZIfOtamHlFUyI/DX+CEXQUunmSQaNek2EBqUK9O59st1sM/b a5MDjEgdAfn6n3I2ha7vw4V4VIeZRnJ9+jG3gftJ/qw8WqrfAVoU0Bt3nLMNpzrDEe8p fR5pHj5slzBvAtHclnpB1aXJAZfcSjNMFz0BK6jdDQoptq6cTooVZoH5EIYxsG2/gMCw dIJ2UBTlXDiKW8PMJzDh8MJucAvw9kJ9vQI39KKqg/G9A2TQ4frk2njWa4RzvtZn7H2a pUAZnsLm81zRYx4HQSrbASup4xdsqAtogodI5+3UdRDsl2L/gspKADyAd1u0cKWc7X53 dj/Q== X-Gm-Message-State: AOAM532uoHCKtZrffqHeQ1KcXU+Sa4ucVOziF8Au3wdLlEvgBNHRRaAm zvV7Ja2M2tJ0RNabcpShy3s51kNONqTuqSe9 X-Google-Smtp-Source: ABdhPJx3xGbKFLFo7QdffJVkmsRHlpLKdS/H/k5v6jI+byItv4Dm9fGbFPyTzEw60l858nqCZbEy1g== X-Received: by 2002:a05:622a:55:: with SMTP id y21mr28350578qtw.39.1635285616071; Tue, 26 Oct 2021 15:00:16 -0700 (PDT) Received: from tresc043793.tre-sc.gov.br ([187.94.103.218]) by smtp.gmail.com with ESMTPSA id t22sm6182903qtw.21.2021.10.26.15.00.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 15:00:14 -0700 (PDT) From: luizluca@gmail.com To: openwrt-devel@lists.openwrt.org Cc: nbd@nbd.name, Luiz Angelo Daros de Luca Subject: [PATCH 1/2] interface-ip: copy more info for target host route Date: Tue, 26 Oct 2021 18:59:52 -0300 Message-Id: <20211026215953.8951-1-luizluca@gmail.com> X-Mailer: git-send-email 2.33.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_150017_926568_3033384D X-CRM114-Status: UNSURE ( 8.14 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Luiz Angelo Daros de Luca interface_ip_add_target_route was adding a host route without copying other confs like type, source, online). The result was that this: unreachable 192.168.0.9 metric 123 Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:834 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [luizluca[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Luiz Angelo Daros de Luca interface_ip_add_target_route was adding a host route without copying other confs like type, source, online). The result was that this: unreachable 192.168.0.9 metric 123 was being converted to: 192.168.0.9 dev lo scope link metric 123 Signed-off-by: Luiz Angelo Daros de Luca --- interface-ip.c | 23 ++++++++++++++++++++--- 1 file changed, 20 insertions(+), 3 deletions(-) diff --git a/interface-ip.c b/interface-ip.c index 648f521..7c60fec 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -301,9 +301,26 @@ interface_ip_add_target_route(union if_addr *addr, bool v6, struct interface *if route->mask = v6 ? 128 : 32; memcpy(&route->addr, addr, addrsize); memcpy(&route->nexthop, &r_next->nexthop, sizeof(route->nexthop)); - route->mtu = r_next->mtu; - route->metric = r_next->metric; - route->table = r_next->table; + if (r_next->flags & DEVROUTE_MTU) { + route->mtu = r_next->mtu; + route->flags |= DEVROUTE_MTU; + } + if (r_next->flags & DEVROUTE_METRIC) { + route->metric = r_next->metric; + route->flags |= DEVROUTE_METRIC; + } + if (r_next->flags & DEVROUTE_TABLE) { + route->table = r_next->table; + route->flags |= DEVROUTE_TABLE; + } + if (r_next->flags & DEVROUTE_TYPE) { + route->type = r_next->type; + route->flags |= DEVROUTE_TYPE; + } + if (r_next->flags & DEVROUTE_ONLINK) + route->flags |= DEVROUTE_ONLINK; + memcpy(&route->source, &r_next->source, addrsize); + route->sourcemask = r_next->sourcemask; route->iface = iface; vlist_add(&iface->host_routes, &route->node, route); From patchwork Tue Oct 26 21:59:53 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luiz Angelo Daros de Luca X-Patchwork-Id: 1546635 X-Patchwork-Delegate: nbd@openwrt.org Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=sU4zimkp; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20210112 header.b=QtkUkaW/; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=none (no SPF record) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Hf5Vj2sfcz9sRN for ; Wed, 27 Oct 2021 09:05:48 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5nJPH32wyNkZ+wJ8G3CGSRSrUOmW1CnnSOtqcLGxiQ8=; b=sU4zimkpfv2PDJ V1pBA4QGH4jE34aQs7RDsnHYiOg0frYF5BfyWoMiPSV3mmdvkITCPJBZVzva1WdLZ+fDYsnhgeU0v q86eUDUalwIPEbWUa7tMIg4qTE8JDERlIoQy79aZbQngqTEiPWiYI/LklXC1aIIQtYtxDEPe98txL VgSttxXZeRj5ee9x3BBpGl6GLtvvRi/2MXgduzegNbrGrQvS/T7G5TzPgNTrXZTIhJPwSL031zDYR +wb9wIqAtCHMtBhU8CLbDeDFU1kSi5cal9kfPrRjZ6FsIFLypS7FxDdvFe+Q0AJ3DH8MN1jRiLKwz C3ysVgEuFk8jLqAjREFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfUUl-003B8l-7X; Tue, 26 Oct 2021 22:00:35 +0000 Received: from mail-qt1-x831.google.com ([2607:f8b0:4864:20::831]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfUUZ-003B7p-MB for openwrt-devel@lists.openwrt.org; Tue, 26 Oct 2021 22:00:24 +0000 Received: by mail-qt1-x831.google.com with SMTP id w2so729419qtn.0 for ; Tue, 26 Oct 2021 15:00:23 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=zUC1CF2ZldCvcUpVH6/RbtGmlaABLd9ONsbmWTU5Wrw=; b=QtkUkaW/aSbZsC6p8iXIGmZzm+2eJlbD9c2Z6tOxl9Am5uOzEzO/bkEVP2W3xRfdcU +IMRNQTY7w+ZKiyHniDn23zgjPWX8ZNEKK1yXXXNOAXoIjX0ODa2RhES8Q6dx5Etp6Gb sLWOJaqb/LzODR9JQkfMpWhQmnXu2sQrBWjXlylAFW/p3JAexLn4gd5mA1OqbowfBFGH I+2+b+V+pSqra2hKdoaS07dveQitYgIvdwSYRes5pW/94mhnT6LuOMOyMCtIh4BP22b5 QCAvCXZE5MF4OyrUEvumUWAOIBlaxR+PrFmO1gZm+3D+NvLxVx13Mg6HXOiKTbULj799 CpEA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zUC1CF2ZldCvcUpVH6/RbtGmlaABLd9ONsbmWTU5Wrw=; b=LZKPBol3J0mN3yIuRoRb7HCW9BrZfUTdQFsFNrpHYHdCrb45qBqggK3otmvY0Sok6Z PCF1sGYbQ1AXHhIR9n6tYtMbzQwBle4WHojT/NltLNRiY1MyoASQ7VeOTFy46mygVpew 4tf9fsqJCQGNaz8Dw1pMGROInk27eH7Ubeo5XUsKMYJk8M22d7ZF3JbkhzgJN+2oJEr9 D93mMFYBfLWF+7RBsgemckBDwLZCw3sRo+bMyFLt4aVaFc6NCjWqxzVJszR51HIzYEHk VnDGQnSEMI6Zgl4cYUF/BAjyvSHUNJV86SKNjbre9Ubrgyf4FQnj2PeDjaxHwnONI1cD OePw== X-Gm-Message-State: AOAM530ZU1yaHsvG3pkkHxxfO3hEstooiiufdsTWhQMLkJNMx481sytu 0IfEnRM1ubHpEMBNfFSgpFv8V1qmX50tmgPk X-Google-Smtp-Source: ABdhPJyB3rwRGzeUis3RuzJ/kfcM5MZ4eHKbksW5sSodr5iJ/s07rOcTEtitsCnj4iVDZA3hAUnyAA== X-Received: by 2002:a05:622a:1453:: with SMTP id v19mr28717223qtx.125.1635285622452; Tue, 26 Oct 2021 15:00:22 -0700 (PDT) Received: from tresc043793.tre-sc.gov.br ([187.94.103.218]) by smtp.gmail.com with ESMTPSA id t22sm6182903qtw.21.2021.10.26.15.00.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 26 Oct 2021 15:00:22 -0700 (PDT) From: luizluca@gmail.com To: openwrt-devel@lists.openwrt.org Cc: nbd@nbd.name, Luiz Angelo Daros de Luca Subject: [PATCH 2/2] interface-ip: use metric when looking for a route Date: Tue, 26 Oct 2021 18:59:53 -0300 Message-Id: <20211026215953.8951-2-luizluca@gmail.com> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211026215953.8951-1-luizluca@gmail.com> References: <20211026215953.8951-1-luizluca@gmail.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_150023_768203_4896F74C X-CRM114-Status: GOOD ( 11.02 ) X-Spam-Score: -0.2 (/) X-Spam-Report: Spam detection software, running on the system "bombadil.infradead.org", has NOT identified this incoming email as spam. The original message has been attached to this so you can view it or label similar future email. If you have any questions, see the administrator of that system for details. Content preview: From: Luiz Angelo Daros de Luca When there were multiple routes with the same target but different metrics, __find_ip_route_target was returning the first one, independently of the metric. Signed-off-by: Luiz Angelo Daros de Luca --- interface-ip.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) Content analysis details: (-0.2 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:831 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [luizluca[at]gmail.com] -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -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_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org From: Luiz Angelo Daros de Luca When there were multiple routes with the same target but different metrics, __find_ip_route_target was returning the first one, independently of the metric. Signed-off-by: Luiz Angelo Daros de Luca --- interface-ip.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/interface-ip.c b/interface-ip.c index 7c60fec..cecfb6d 100644 --- a/interface-ip.c +++ b/interface-ip.c @@ -234,7 +234,9 @@ __find_ip_route_target(struct interface_ip_settings *ip, union if_addr *a, if (route->flags & DEVROUTE_TABLE) continue; - if (!*res || route->mask > (*res)->mask) + if (!*res || route->mask > (*res)->mask || + ((route->mask == (*res)->mask) && (route->flags & DEVROUTE_METRIC) + && (route->metric < (*res)->metric))) *res = route; } }