From patchwork Fri Nov 15 19:50:12 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hurukawa2121 X-Patchwork-Id: 3945 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1ee:b0:5d9:9f4c:3bc7 with SMTP id 14csp1232673map; Fri, 15 Nov 2024 11:51:16 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCUC9BdYDvCb0Wm/I3MEcbG4t5H3sCX6ePPNdULJ/nrQEcSejGRrtamrXwmqIef9wQSbMwOiyeYji7g=@openvpn.net X-Google-Smtp-Source: AGHT+IEttO9YrfOGJNVZigvK97NMxHVpQldM+5pxzR8tG1dXp1be1PWaRK8EY9muJPUUARq5Wg7K X-Received: by 2002:a05:6870:56a5:b0:277:fdce:6759 with SMTP id 586e51a60fabf-2962e01d417mr3967818fac.31.1731700276059; Fri, 15 Nov 2024 11:51:16 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731700276; cv=none; d=google.com; s=arc-20240605; b=OQklMDjaId6Sp3bpA8K6ZvQwG4000XBugqXy9pm0RCYWDE0MLEYxBy0ydpeoLiWWzG VrGeDbm04evBStKPTvtlro9l52PfDac1gZcBv0MCvjSGEy4soMdonBpz/c73YVB0MDv+ GNwza7dCuVGBF+kfmG02jAqE//M3O/QbL/5CaRRUfzeVALScu6V2yjS2F+H6CL2ePNyy rx8WgFezGRKWz66A2G1cMmPw9b49PtwuR+WzE6hD4hVZxRX4sSul2T6FcpXaFjiNtuk+ 2PfPRdaVm7V9aeGQQfann/XpGYKBVSTEy1Ghrp7wbiheuhWG779aUgYZfzYdI2E8rhA9 yuVg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=errors-to:content-transfer-encoding:cc:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :mime-version:message-id:date:to:from:dkim-signature:dkim-signature :dkim-signature; bh=6BG5iY6GDOmipEJltr3t2UPLtZlxlAEfBhBTgccSqbY=; fh=PL8Gaq/CUo2LaXltYwxkcFfwVlvPtEN/PzCeiK+ADDw=; b=aFKI3gUA7HJQ/R7nQPD3IQgzKkSm+rfstuNGJ1XGiGWSGAyWsR1FLhUu4pnMs0Pqmi o3nAY6j+iUz4MkeWTTmhc18yvhHnkwtFPJT0aArKi7WSa2znBqIPp6wK3EzP59dzX7BL WFp+/wkvDKHefUPbbzjwuQBayJqBPidgqTMJVHfCOvzkeQaNBYqEqlI+V+35xhQzLPBP WlR7+Nu0I2OkO4k2irsF//1nrSDchJ3jWfVxiFz5mwC7I7x/5ikovy6DyGyGKkNbhS9d pUFduJgR4FrxlMdvUg5sot9P1aHYw6Z9cAj2puPJfyXez1bFTjLEnWwMJrGfpaP2hUDw d97w==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="OsD/HfvQ"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=B2Azkgf3; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="heSLpOX/"; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@openvpn.net Received: from lists.sourceforge.net (lists.sourceforge.net. [216.105.38.7]) by mx.google.com with ESMTPS id 46e09a7af769-71a780e6145si1238085a34.58.2024.11.15.11.51.15 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Nov 2024 11:51:16 -0800 (PST) Received-SPF: pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) client-ip=216.105.38.7; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@sourceforge.net header.s=x header.b="OsD/HfvQ"; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b=B2Azkgf3; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b="heSLpOX/"; spf=pass (google.com: domain of openvpn-devel-bounces@lists.sourceforge.net designates 216.105.38.7 as permitted sender) smtp.mailfrom=openvpn-devel-bounces@lists.sourceforge.net; dmarc=fail (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com; dara=fail header.i=@openvpn.net Received: from [127.0.0.1] (helo=sfs-ml-3.v29.lw.sourceforge.com) by sfs-ml-3.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tC2LV-0005Wk-7j; Fri, 15 Nov 2024 19:51:08 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-3.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tC2LU-0005Wc-8t for openvpn-devel@lists.sourceforge.net; Fri, 15 Nov 2024 19:51:07 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=yI5g9zvt7XvZ3ire08iD1vpVblTtegpw5Zpf3GFpFmU=; b=OsD/HfvQtpmJL+A07i0XeyOwvm KTD/dSxQQy3TRAXTzph8YDgSMT8bVyQsiB1yog1RFClkJnnyWVlSlgC5ayngqFUwAOLXNPQmAvmHA 9tg5Rnl7AqQyl61WwWSuqHul/Zgc8FQYc0QJNxjkicEAqmBGIV+UMOwTQO+Xm4JuLDw8=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=yI5g9zvt7XvZ3ire08iD1vpVblTtegpw5Zpf3GFpFmU=; b=B 2Azkgf39D84ycDCMOVBvm5mUG4OIvMRffTsF5xxRcwhrf2D9d2W3j5fmFbXMLBcUWp37qp3jcnQ6b XgHPuXVOWMDs/xso475SL5H0KofNqK3O7s60UJXM0iUhEATcKWHANeKILDmmS6TdrCMsQNWvPr2dO 2tRjliG/9DKoCXbw=; Received: from mail-pl1-f180.google.com ([209.85.214.180]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tC2LS-00018l-V5 for openvpn-devel@lists.sourceforge.net; Fri, 15 Nov 2024 19:51:07 +0000 Received: by mail-pl1-f180.google.com with SMTP id d9443c01a7336-20c767a9c50so25057415ad.1 for ; Fri, 15 Nov 2024 11:51:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731700261; x=1732305061; darn=lists.sourceforge.net; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:from:to:cc:subject:date:message-id:reply-to; bh=yI5g9zvt7XvZ3ire08iD1vpVblTtegpw5Zpf3GFpFmU=; b=heSLpOX/tmNiqCIvOUkD3PwdHFf9O77eIdxnS72mT1w/0PkG2c31JcRiCfneoYZWlB u2wfg7LCQDPVNCb3lxJyc2ksU2K1+u9QxQ8J/+dtxuUEL9K8L1pZmcP1zn51Qfc3Lxoq TPaJ8x6q9B26C1Ys2ATULihH6CnGc+bUOMKNVbciEHaHgGShW34FxPeFkX4+8x1gOa6d 8a+F7FmWbbo/r76tpGDnhLbdErTZvj8vDztc+CWNz13dsToruRW+V9ux8gyb3BIXRHC8 +r9stungP3xB1W8wSsxFiGsafmcDLlY3KTiJH5eA0hYntienLpeXmNWxXWQp8dqi7LVZ ZTag== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731700261; x=1732305061; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=yI5g9zvt7XvZ3ire08iD1vpVblTtegpw5Zpf3GFpFmU=; b=Ph2zqZCDLIl8Jieh9Y8U+0NAQ5DVTDFiEPnRZz+Sh1J0s8Q4dH6eJ3s3e6Il186EPv 8SliN2FJQmZheVkLj2ASPfAp1l+8T2lVJDAyJax5VIXCyQQwJ5IhrpBEjdjjhAp6Zk9H 2xkTl/WoOV3/iFWFxJnwDuvt95ftukkPyiw1hngVFfBMLlxmfoFulG9gocNCpMtjTaJ5 yhWNtJYK7q+tn5tRfImLV5NwNSXr0GAokKcIt+g4uKD2uS7d4rX2OV3flbCVnpkyxg+f ewy1HZmNFAqnVgsLYjq/0IZ/l1qJn8BgSfjnIzj9fvUaQ19DmOS6VxjCp2QYhl5eb/3m qiBQ== X-Gm-Message-State: AOJu0YzEGTeijQqs2AaOVSACXzX0i7Dg8pAEa6nsUGlmJXyZziMd+3Uo 72N/1C9Clem6h8yHkRFnWYzQl12cbnVHpFM0A6XbqyibZIOqaBQ1zV/1pHJ4 X-Received: by 2002:a17:902:f705:b0:20c:ca83:31c7 with SMTP id d9443c01a7336-211d0edc8a7mr57191905ad.54.1731700261165; Fri, 15 Nov 2024 11:51:01 -0800 (PST) Received: from localhost.localdomain ([2001:268:98c3:808:6023:9c0:455:8a35]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0f61372sm15994905ad.278.2024.11.15.11.50.59 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 15 Nov 2024 11:51:00 -0800 (PST) From: Hurukawa2121 To: openvpn-devel@lists.sourceforge.net Date: Sat, 16 Nov 2024 04:50:12 +0900 Message-Id: <20241115195011.44764-1-shujifurukawa1213@gmail.com> X-Mailer: git-send-email 2.39.3 (Apple Git-146) MIME-Version: 1.0 X-Spam-Score: 0.1 (/) X-Spam-Report: Spam detection software, running on the system "util-spamd-2.v13.lw.sourceforge.com", 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: Hurukawa2121 --- Improve shuffling algorithm of connection list This patch implements the Fisher-Yates shuffle algorithm to ensure that all permutations of the connection target list are generated with equal probability, eliminating biases present in the previous [...] Content analysis details: (0.1 points, 6.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- 0.0 RCVD_IN_VALIDITY_SAFE_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.214.180 listed in sa-trusted.bondedsender.org] 0.0 RCVD_IN_VALIDITY_RPBL_BLOCKED RBL: ADMINISTRATOR NOTICE: The query to Validity was blocked. See https://knowledge.validity.com/hc/en-us/articles/20961730681243 for more information. [209.85.214.180 listed in bl.score.senderscore.com] 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 [shujifurukawa1213[at]gmail.com] 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [shujifurukawa1213[at]gmail.com] -0.0 SPF_PASS SPF: sender matches SPF record -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 -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.0 RCVD_IN_MSPIKE_H3 RBL: Good reputation (+3) [209.85.214.180 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.214.180 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-Headers-End: 1tC2LS-00018l-V5 Subject: [Openvpn-devel] [PATCH] Improve shuffling algorithm of connection list X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hurukawa2121 Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox X-GMAIL-THRID: =?utf-8?q?1815818427618448736?= X-GMAIL-MSGID: =?utf-8?q?1815819348405920008?= From: Hurukawa2121 --- Improve shuffling algorithm of connection list This patch implements the Fisher-Yates shuffle algorithm to ensure that all permutations of the connection target list are generated with equal probability, eliminating biases present in the previous shuffling method. In the Fisher-Yates algorithm, there's only one way to obtain each permutation through these swaps, so all permutations occur with equal probability in theory. Signed-off-by: Hurukawa2121 src/openvpn/init.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/openvpn/init.c b/src/openvpn/init.c index 9371024e..3b00b49d 100644 --- a/src/openvpn/init.c +++ b/src/openvpn/init.c @@ -478,9 +478,9 @@ init_connection_list(struct context *c) if (c->options.remote_random) { int i; - for (i = 0; i < l->len; ++i) + for (i = l->len - 1; i > 0; --i) { - const int j = get_random() % l->len; + const int j = get_random() % (i + 1); if (i != j) { struct connection_entry *tmp;