From mboxrd@z Thu Jan 1 00:00:00 1970 Authentication-Results: passt.top; dmarc=pass (p=none dis=none) header.from=mur.at Authentication-Results: passt.top; dkim=pass (3072-bit key; unprotected) header.d=mur.at header.i=@mur.at header.a=rsa-sha256 header.s=dkim2 header.b=g42xozW7; dkim-atps=neutral Received: from efeu.mur.at (efeu.mur.at [89.106.208.42]) by passt.top (Postfix) with ESMTPS id D29CF5A0275 for ; Tue, 08 Sep 2026 20:16:57 +0200 (CEST) Received: from raspi4 (lan1.raspi.ma39.ffgraz.net [10.12.1.243]) by efeu.mur.at (Postfix) with ESMTPSA id 4A2E546F2F; Tue, 8 Sep 2026 20:16:57 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=mur.at; s=dkim2; t=1788891417; bh=Ejig9xQOshqh3qdtTg/VVBpVVSyBM6PC0nYRVYT8yf8=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=g42xozW7ewz7X8XZHVUztxkMhmSU6IUYPBQgJiYK2blmARcGcWU3OZcrQFtWUoWo/ /UzW0bdIMG1OWTrIITxgrTCwYN2IHMQ0td9K7bhAwcdLP1CQ7Q7VpiCusgSgdKau+m RjO6d1seoeeFJZqWfSbY6DQQTV3P5rUv6l6xcLdlL4yQ918xVrvKfDLr7iqB06YhK2 1guQYJQWXPz3GqSNF+k9JumDPYw1+T3dyN6hGv6mV26S7Uo/Pyzsofqia/20J9Q33y XVDe3tplpq96FuifhjqKYfZoXdvVxcjOujuLAavDs5ZYVo8CZhhudi0paSK1zeVV0l DVQhAEn4hywvcfI82VZnVKQ9+b1Vt0bs35KgCyTBDWajg+dQvlLUp+iUVRKQkwUs6S WgPzc7ZAfeOwiAci8dyZZ49BAN/EaDrJbMAreXqeNTGmBmehxt9FlXXmIWfNqrKx/d QF9FWR6YTLs1qlv4K1nfyqP3O8Q/P0sbEVkreZsjxwcfL6VWadF From: Martin Schitter To: passt-dev@passt.top Subject: [PATCH v2 3/3] Optimize route dependency solver. Date: Tue, 8 Sep 2026 18:13:14 +0000 Message-ID: <20260908181631.537802-4-ms+git@mur.at> X-Mailer: git-send-email 2.53.0 In-Reply-To: <20260908181631.537802-1-ms+git@mur.at> References: <20260908181631.537802-1-ms+git@mur.at> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-MailFrom: ms+git@mur.at X-Mailman-Rule-Hits: nonmember-moderation X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation Message-ID-Hash: PTFRN5Q2ZUQ4MQHROXUZTPQFFVMBHTNR X-Message-ID-Hash: PTFRN5Q2ZUQ4MQHROXUZTPQFFVMBHTNR X-Mailman-Approved-At: Tue, 08 Sep 2026 22:39:37 +0200 CC: Martin Schitter X-Mailman-Version: 3.3.8 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Avoid retransmitting routes that explicitly got reported as already existing. Never make more resolution attempts than there are still unresolved dependency errors. In the context of my current mesh network with ~700 route entries these changes reduce the required processing time from 5.5s to 15ms. --- netlink.c | 26 +++++++++++++++++++------- 1 file changed, 19 insertions(+), 7 deletions(-) diff --git a/netlink.c b/netlink.c index 65cc5d7..0e1c82a 100644 --- a/netlink.c +++ b/netlink.c @@ -703,13 +703,12 @@ int nl_route_dup(int s_src, unsigned int ifi_src, /* Routes might have dependencies between each other, and the kernel * processes RTM_NEWROUTE messages sequentially. For n routes, we might - * need to send the requests up to n times to get all of them inserted. - * Routes that have been already inserted will return -EEXIST, but we - * can safely ignore that and repeat the requests. This avoids the need - * to calculate dependencies: let the kernel do that. + * need to send the requests up to n times in the worst case to get all + * of them inserted. */ clock_gettime(CLOCK_MONOTONIC, &start); - for (i = 0; i < dup_routes; i++) { + for (i = dup_routes; i > 0; i--) { + unsigned int dep_errors = 0; for (nh = (struct nlmsghdr *)buf, left = nlmsgs_size; NLMSG_OK(nh, left); nh = NLMSG_NEXT(nh, left)) { @@ -722,10 +721,23 @@ int nl_route_dup(int s_src, unsigned int ifi_src, rc = nl_do(s_dst, nh, RTM_NEWROUTE, (flags & ~NLM_F_DUMP_FILTERED) | NLM_F_CREATE, nh->nlmsg_len); - if (rc < 0 && rc != -EEXIST && - rc != -ENETUNREACH && rc != -EHOSTUNREACH) + + if ( rc == -EEXIST) { + /* Exclude existing routes from further retry attempts */ + nh->nlmsg_type = NLMSG_NOOP; + continue; + } + if ( rc == -ENETUNREACH || rc == -EHOSTUNREACH){ + dep_errors++; + continue; + } + if (rc < 0) return rc; } + debug("route dependency errors: %d", dep_errors); + /* Avoid having much more resolution attempts than + * there are still unresolved dependency errors */ + i = MIN(i, dep_errors++); } clock_gettime(CLOCK_MONOTONIC, &now); debug("route dependency handling time: %f s", -- 2.53.0