From patchwork Mon Apr 29 18:33:58 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Edmond X-Patchwork-Id: 1929132 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 4VSsTZ1cRvz23jG for ; Tue, 30 Apr 2024 04:35:46 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 88C748898E; Mon, 29 Apr 2024 20:35:22 +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 0985A88966; Mon, 29 Apr 2024 20:35:20 +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 120F88886D for ; Mon, 29 Apr 2024 20:35:16 +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 351B3210FBBF; Mon, 29 Apr 2024 11:35:15 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 351B3210FBBF From: Sean Edmond To: u-boot@lists.denx.de Cc: trini@konsulko.com, Sean Edmond , AKASHI Takahiro , Charles Hardin , Francis Laniel , Heinrich Schuchardt , Joe Hershberger , Mattijs Korpershoek , Michal Simek , Peter Robinson , Ramon Fried , Sean Anderson , Simon Glass Subject: [PATCH v6 3/3] net: bootp: add config option BOOTP_RANDOM_XID Date: Mon, 29 Apr 2024 11:33:58 -0700 Message-ID: <20240429183449.2284935-4-seanedmond@microsoft.com> X-Mailer: git-send-email 2.42.0 In-Reply-To: <20240429183449.2284935-1-seanedmond@microsoft.com> References: <20240429183449.2284935-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 0109446dd6f..e336282cb8f 100644 --- a/net/bootp.c +++ b/net/bootp.c @@ -837,22 +837,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