From patchwork Fri Nov 15 19:35:04 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hurukawa2121 X-Patchwork-Id: 3941 Return-Path: Delivered-To: patchwork@openvpn.net Received: by 2002:a05:7000:1ee:b0:5d9:9f4c:3bc7 with SMTP id 14csp1225919map; Fri, 15 Nov 2024 11:36:38 -0800 (PST) X-Forwarded-Encrypted: i=2; AJvYcCWPu1CCp3VtyO+BaNE/gIB8BSC2lzKQ0Yk4hq1wSWdHZcl3npa5sQtShMokQMGCJjIgzCGYR/JncSg=@openvpn.net X-Google-Smtp-Source: AGHT+IFOUwvYteqOfXwUTuOn6kCuWrOwEhZCeyn4cJFyFsFEMxHLB7YM4+4uviP+QVuMuGYeAYYh X-Received: by 2002:a05:6808:2223:b0:3e6:f6e:984b with SMTP id 5614622812f47-3e7bc86cd22mr3947357b6e.38.1731699397779; Fri, 15 Nov 2024 11:36:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1731699397; cv=none; d=google.com; s=arc-20240605; b=ekPdcQ3RPeg8I1L9uBDMCuAco2vcRw66xQW8LA2OqJCPWCsuh+uwA+dnpU2ocYiMvE SkeFcUtrqeJDveBRV+WVNS14Noy37qWz10c4Y3T6NZCyFLDGat6aZ6CEZQLWRXQ/Qbtp kVGSfzoZ/Q5Pzh+70OP38VGU2sC8TliXi6zekAnx+Cb5pYn6FmwKrK267ORaX3s48+bW Gw/V+6sA6Qyfou6li8ugCFpRn6aJWAntVolrhlnEQytMST8uiF1SWARWYunKT1BkVIMC spc09iyUrX+DH3v1fJJJQdnZJYjWEgEt6kcDwWTdi8S00n3H7oxIekYWctH2T8C21Ti+ 6mYQ== 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=aKmCnCnLZS43c+7X9nSSv52M9AX6mSuxeC2OjHIPXrE=; fh=PL8Gaq/CUo2LaXltYwxkcFfwVlvPtEN/PzCeiK+ADDw=; b=DMOqX8gnHSdc4FkYFyJclpBlFgJ8NsLAEna2trTxO3/W7MjkMH6zOM561oPJmqvRyq L2643d8WaZtLJag4QGTEg+6KodfwEJwcD3OmaBJEtIcLBW5xfLwcZtl2gtmTeKuAWVpS ng3YgM7elqIqxM/hdJKlR6YnJp9cCvteW8NAkqhxv55aHRxbcMIhQyRU3Zz44+VkJNHJ 43asrS44tAi5VjV9HUzS5G795GIG0PYwdUntmlng1rvaDeLtuJKRlKUdpDE/sN0ZYYvQ xeMCMKBkkjRZRz+6hM8BWjk9G0ulN5SOawev81E6KaVBlVdPH+6dfdNp3wc3mCiLNbb1 Ih9g==; 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=dXDTdqf2; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Da/bfnF3"; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ktRSNFUR; 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 5614622812f47-3e7bccefc26si1458056b6e.31.2024.11.15.11.36.37 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Fri, 15 Nov 2024 11:36:37 -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=dXDTdqf2; dkim=neutral (body hash did not verify) header.i=@sf.net header.s=x header.b="Da/bfnF3"; dkim=neutral (body hash did not verify) header.i=@gmail.com header.s=20230601 header.b=ktRSNFUR; 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-2.v29.lw.sourceforge.com) by sfs-ml-2.v29.lw.sourceforge.com with esmtp (Exim 4.95) (envelope-from ) id 1tC27H-0001Sp-E0; Fri, 15 Nov 2024 19:36:27 +0000 Received: from [172.30.29.66] (helo=mx.sourceforge.net) by sfs-ml-2.v29.lw.sourceforge.com with esmtps (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384 (Exim 4.95) (envelope-from ) id 1tC27G-0001SZ-0B for openvpn-devel@lists.sourceforge.net; Fri, 15 Nov 2024 19:36:26 +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=Vuov/8AKPq0vWw7fhpW6BJWD6UEWWCBPOWqOQglKUFQ=; b=dXDTdqf26l6KJgEwV+QW5jhObh /pZBexkvQ4ntQcrGyssKYejqlbxVg5HJ2/GYBUUDVOY7jEc4AZPJK+9JjLD1Zn9XXs+fem7S8wVw1 q1Tf2bM++JLEePxR0GRzo7/mWOVJfo9YSBpvjjcg3fPuBbI5v4SKUTJqPFRIvbkoIDSc=; 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=Vuov/8AKPq0vWw7fhpW6BJWD6UEWWCBPOWqOQglKUFQ=; b=D a/bfnF3u1Bu0IXUtp2hSNEmr6s/vUOLI1G6x97goEeHZW9FaqhyK0MiJxPNJwaNTPXUq9ixvVVrwA 4ttTYA49EmNcs9LVZ3nBqXoXWTiMo7MKmQtkIaTJD/TEnG5FgYEatT7w0ARgQ7twCDSRb7ez6QNNN xE/srxMfDnBptoU0=; Received: from mail-pj1-f45.google.com ([209.85.216.45]) by sfi-mx-2.v28.lw.sourceforge.com with esmtps (TLS1.2:ECDHE-RSA-AES128-GCM-SHA256:128) (Exim 4.95) id 1tC27F-0007zr-BT for openvpn-devel@lists.sourceforge.net; Fri, 15 Nov 2024 19:36:25 +0000 Received: by mail-pj1-f45.google.com with SMTP id 98e67ed59e1d1-2e9b4a5862fso1748132a91.1 for ; Fri, 15 Nov 2024 11:36:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1731699375; x=1732304175; 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=Vuov/8AKPq0vWw7fhpW6BJWD6UEWWCBPOWqOQglKUFQ=; b=ktRSNFURZEikJbbZpcU8QQ3w9nkiqN9KaHn1boUT8zftrqu9H+BRtTUMYBS8iUvSeX cDa8puLnOkwnVbVoSV37fNetXs8I2RU8y90LG+DSj57iPP9+gaObUe0d+S49IQnt1CFU z2gMOugsjlThTVVpB43Lu/5IfLt0EPlpW1CET//wjU8yZOvrFIa8xMHhr2InDDBZ3uv1 GZBjBv5j2r9juPlvDBM5p3ERUjhytCdGyPuMolXm6EnNdOVPCuHTV0TIdDGm1rLeC3fG j3LjZDKWURl7UC3rofaNYBkoUdaK7Ia3H0MY0DDuglhhWVb/ezoJmFnu6i8OQGXwP7Dx 4ZhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1731699375; x=1732304175; 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=Vuov/8AKPq0vWw7fhpW6BJWD6UEWWCBPOWqOQglKUFQ=; b=udDg7QCDtyOC3S7OjuspS0u2wTSHxJx2kml0W1gQGqDl9NtQP8U14PGhceZULUtsG3 3JjW0ZS/shOLe/NhstHJF99U515TRWL2vfKMV+l6T6Sh9vQlS2yuTJ0PufzTooE3/rex 1nWtbm3smUmY6UDuGr3gcWtYKqVwpH1Zm+cwwh/RPCgRjXI4PB86Namq72l5+P3xhNmF JkDMoEzio4NE8vWXPVHlbejPUKtEI3XgSec75YcAmIMie5X61AJ8tf1L5XqegnDA7YNG rXTyjiPzefOfTfnmL9D+oHNlvuNEUvEKVpbJCuRoHXdJsIU7Pmmkk+5ecgN+nvzfJP5F zIkA== X-Gm-Message-State: AOJu0YwZ/NWn9YbDili7Su3fvu3Ao/uFBrFwM3XQOhhexL4rPEh3fakJ 3WUBq7AZTUlpnG7DcZc3oRo+gbdlIfYRst/smcPtOxSO9UGrerz+uw7YLQ== X-Received: by 2002:a17:90a:d2cc:b0:2ea:338e:3358 with SMTP id 98e67ed59e1d1-2ea338e453amr260000a91.14.1731699374631; Fri, 15 Nov 2024 11:36:14 -0800 (PST) Received: from localhost.localdomain ([2001:268:98c3:808:6023:9c0:455:8a35]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-211d0ecafebsm15946395ad.105.2024.11.15.11.36.13 (version=TLS1_3 cipher=TLS_CHACHA20_POLY1305_SHA256 bits=256/256); Fri, 15 Nov 2024 11:36:14 -0800 (PST) From: Hurukawa2121 X-Google-Original-From: Hurukawa2121 To: openvpn-devel@lists.sourceforge.net Date: Sat, 16 Nov 2024 04:35:04 +0900 Message-Id: <20241115193503.35016-1-shujifurukawa1213@gamil.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: --- 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.216.45 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.216.45 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.216.45 listed in wl.mailspike.net] -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [209.85.216.45 listed in list.dnswl.org] 0.0 RCVD_IN_MSPIKE_WL Mailspike good senders X-Headers-End: 1tC27F-0007zr-BT 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?1815818427618448736?= --- 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;