From patchwork Thu May 9 02:39:03 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Edmond X-Patchwork-Id: 1933313 X-Patchwork-Delegate: rfried.dev@gmail.com Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=patchwork.ozlabs.org) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature ECDSA (secp384r1)) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4VZbpJ57bZz20fh for ; Thu, 9 May 2024 12:40:08 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 2DE618846D; Thu, 9 May 2024 04:39:37 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=reject dis=none) header.from=microsoft.com Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Received: by phobos.denx.de (Postfix, from userid 109) id 0CDDE8847F; Thu, 9 May 2024 04:39:35 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_FAIL, SPF_HELO_PASS autolearn=no autolearn_force=no version=3.4.2 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by phobos.denx.de (Postfix) with ESMTP id 0C50088441 for ; Thu, 9 May 2024 04:39:33 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=fail (p=reject dis=none) header.from=microsoft.com Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=seanedmond@microsoft.com Received: from ovlvm106.redmond.corp.microsoft.com (unknown [131.107.147.185]) by linux.microsoft.com (Postfix) with ESMTPSA id 3AFE720B2C86; Wed, 8 May 2024 19:39:32 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3AFE720B2C86 From: Sean Edmond To: u-boot@lists.denx.de Cc: trini@konsulko.com, Sean Edmond , AKASHI Takahiro , Abdellatif El Khlifi , Bin Meng , Charles Hardin , Francis Laniel , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Mattijs Korpershoek , Peter Robinson , Ramon Fried , Sean Anderson , Simon Glass Subject: [PATCH v8 3/3] net: bootp: add config option BOOTP_RANDOM_XID Date: Wed, 8 May 2024 19:39:03 -0700 Message-ID: <20240509023918.2504185-4-seanedmond@microsoft.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240509023918.2504185-1-seanedmond@microsoft.com> References: <20240509023918.2504185-1-seanedmond@microsoft.com> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.8 at phobos.denx.de X-Virus-Status: Clean The new config option BOOTP_RANDOM_XID will randomize the transaction ID for each new BOOT/DHCPv4 exchange. Signed-off-by: Sean Edmond Reviewed-by: Tom Rini --- (no changes since v5) Changes in v5: - fix depends for BOOTP_RANDOM_XID: "depends on CMD_BOOTP && (LIB_RAND || LIB_HW_RAND)" Changes in v3: - Add depends for BOOTP_RANDOM_XID cmd/Kconfig | 7 +++++++ net/bootp.c | 31 +++++++++++++++++-------------- 2 files changed, 24 insertions(+), 14 deletions(-) diff --git a/cmd/Kconfig b/cmd/Kconfig index 54c4ab8570c..82f6a089586 100644 --- a/cmd/Kconfig +++ b/cmd/Kconfig @@ -1909,6 +1909,13 @@ config BOOTP_VCI_STRING default "U-Boot.arm" if ARM default "U-Boot" +config BOOTP_RANDOM_XID + bool "Send random transaction ID to BOOTP/DHCP server" + depends on CMD_BOOTP && (LIB_RAND || LIB_HW_RAND) + help + Selecting this will allow for a random transaction ID to get + selected for each BOOTP/DHCPv4 exchange. + if CMD_DHCP6 config DHCP6_PXE_CLIENTARCH diff --git a/net/bootp.c b/net/bootp.c index c34ffe27854..285fcba7348 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -834,22 +834,25 @@ void bootp_request(void) /* Only generate a new transaction ID for each new BOOTP request */ if (bootp_try == 1) { - /* - * Bootp ID is the lower 4 bytes of our ethernet address - * plus the current time in ms. - */ - bootp_id = ((u32)net_ethaddr[2] << 24) - | ((u32)net_ethaddr[3] << 16) - | ((u32)net_ethaddr[4] << 8) - | (u32)net_ethaddr[5]; - bootp_id += get_timer(0); - bootp_id = htonl(bootp_id); - bootp_add_id(bootp_id); - net_copy_u32(&bp->bp_id, &bootp_id); - } else { - net_copy_u32(&bp->bp_id, &bootp_id); + if (IS_ENABLED(CONFIG_BOOTP_RANDOM_XID)) { + srand(get_ticks() + rand()); + bootp_id = rand(); + } else { + /* + * Bootp ID is the lower 4 bytes of our ethernet address + * plus the current time in ms. + */ + bootp_id = ((u32)net_ethaddr[2] << 24) + | ((u32)net_ethaddr[3] << 16) + | ((u32)net_ethaddr[4] << 8) + | (u32)net_ethaddr[5]; + bootp_id += get_timer(0); + bootp_id = htonl(bootp_id); + } } + bootp_add_id(bootp_id); + net_copy_u32(&bp->bp_id, &bootp_id); /* * Calculate proper packet lengths taking into account the * variable size of the options field