From patchwork Thu Apr 17 13:26:57 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881862 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp315005wrs; Thu, 17 Apr 2025 06:27:42 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCWq6HIXsSTqXVRpHFMRjeftTq4MWScsnWf7WicNKCWIQriMNz9+j10jbtP8h3UDNQ/fpkXgqw==@linaro.org X-Google-Smtp-Source: AGHT+IHlYamBh2ahqKFKeDi5yGEDWL+tjyYBG09cpA2/1dKROxRlAGsfSNJsynIHFTArfR/jBv7+ X-Received: by 2002:a05:6000:22ca:b0:391:39fb:59c8 with SMTP id ffacd0b85a97d-39ee5b2f5camr5350285f8f.25.1744896461878; Thu, 17 Apr 2025 06:27:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744896461; cv=none; d=google.com; s=arc-20240605; b=jmlFoC8cAQtIFraOoTHrBG7EH4i5zuDZdSezUcQkVwwqm9CICrP8IfNhuv/cSz+q3/ 38hZTQtVeaNckMILe/g8Vvmysez5Cj6dEKmPJ7H7elyQMTgRnV8WhKNdpmGeBXEhw9Vl Y5lvPY2jr3BoxLPVOCKXOBWrAzq0zXoJ3MTQuoT6A1SkPX15NWfPLXixrDiX/hqBOMI3 T1uQM7RVUjKmT0lXRfEVG7ooWMDNC7dLpVgUUVlW5ophwaHMDa4Svaf6h+UZdXlZeuuq 0oqGcby8imUPn+7Q1gRFqrK4nPx3FZEdOEBs3voH9Ki+7dcLL5VGTiRaFQzSlli0wDfi lY+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=D11ec35keRrC0Yq7WtMF0PySDIUXFOaHDLO+c2svLyM=; fh=vZMGN31IDYvBGpSoI/uxqw824em/ddbq/o428IGX5FI=; b=IbQmqKq/36c5w5fHHi8XtsMK2u4usLAIDHkbTy5vqH5D/qM988MxNvBOx6iPdyqjTk KWdeugOSknUgcnG0oQQ4WQk10gZTusvgPnEOKuM4bbbZvHBrbEBYm6Gxp5kpiNLAt7K5 sjDcpsvjZV0j8IgW2eyX2EQziWWbpqhCCR4xXuO764Mtk6LZLIxHuDC3h0YSdaIvUpfe HligqbnHaXk90HATy9XWycxV+vDo3CZ1olCQ2eTlyMeDrpWTHhpKyub43JLoCNd9Aa+a jK6DPGhblEb5QbcuvKntPFgBJbXJ4kWzFzMVNAvopmWDYSOyxq7gPr0fJllLuc1kiYqw OzFA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x2WlhfGe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id ffacd0b85a97d-39eaf4278efsi9379585f8f.424.2025.04.17.06.27.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:41 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=x2WlhfGe; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 277BC82CBC; Thu, 17 Apr 2025 15:27:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="x2WlhfGe"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A31BE8303B; Thu, 17 Apr 2025 15:27:32 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 9E28182D21 for ; Thu, 17 Apr 2025 15:27:30 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x434.google.com with SMTP id ffacd0b85a97d-39c0dfad22aso537324f8f.2 for ; Thu, 17 Apr 2025 06:27:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744896450; x=1745501250; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=D11ec35keRrC0Yq7WtMF0PySDIUXFOaHDLO+c2svLyM=; b=x2WlhfGeXbLdqWpinIms+o2fOHf+zp/l6mnLwo1uRGuzXlv57lYF0Ziehr01PMnWkW LbkUnXozZHPnlCFVSgq/lcQ7xMFkySspqvVe7VGXRqx3UN2HBY2bUU05b+mheTWbCrcn 0e9aEgM09Uz4IuF51n83H01JwoTJ3CevXl5ZDkPV4J/qLv/Ub7QzZVXqZXcwHJZCDt9A g1kj3nQ1XHrSBob7W3NWg1An0Srlsd+16KWmPFcRKVM0DEv1zUKqYVv02jVJ3dFU5+pw u9zStZis2YJY/T/znGIOk0Lcf3xtCEM4xudKtXt9S6FwG/Xrca+TYSfsgJlC43xcl/kt fHaQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744896450; x=1745501250; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=D11ec35keRrC0Yq7WtMF0PySDIUXFOaHDLO+c2svLyM=; b=Pt/JyNB73zdyBw3pCbSiNd05oZuwBmTX3XwjRpNDZitDQWzUD+ZFlsmzn6O2dUT6JC JSWWyM4tvFtvu3XsLi3aIm0gYrnWHlGrm8l3kfiPevJIiREJSw+fIU8Vjn1QzxVf1tTV AnekPPC5F6fRBewnM3g5WpnVkC5QwXvEf8x5Elpz0lZZuNyjln/Px8+j5SSV3e/3+4ws 8jXFZzFaPSwocJpq5UhfgtXLL8PVUfSfaUxVKTrPU1IdONSCjNfdCjjwUYBJ8i27r8mM nY9Ezr/fDk0LJyqnBXSjV46aKn25gfo5N1Shrl93lO7bvBeysk+rQz4sz5swh+xTg68p BWvQ== X-Gm-Message-State: AOJu0YzgAHEUV+nPpmvlCSyE9JqYkKtrSu5CF5XOSkzMnKqc2yCZ+TJp vTTZS6VIxT7HsHl46pnRiAJZhZqit/RPY5vK2kh/K9djlPrdtflQk2OL2J8vv7CanXSPwx+J0Do EPF8= X-Gm-Gg: ASbGncsjROv1lJUWCOYlu2VEk8SAyNSJY2yu/94V/xz7SStZCPqa9CFrPNywgUro0ye Wtnxio6cBlWDDYSKHxSOFKrAujdrM8wDkfyzODRGbtsc6lSRGY8tYuFO0rPvw60YgYwEzlJm/6t m9V0bW5cLcgyyNVR5HdHg4A4m8pGQNeMycwvKlMS8weQDQHvKfSpur5om3TBi0FPbBjzzewygHf hl4mIGma8aEax7T0p/RPxUomb9RFHdjC3k/BJkiRNXN9JAb4ft88TffkfJz/drwa4/goNogTuER TmD0h7/d+bD1ouI+v24zx8IgPKtUTTCoWuSyb9dPS1di0fXm2w== X-Received: by 2002:a5d:64ae:0:b0:39c:11c0:eb98 with SMTP id ffacd0b85a97d-39ee5b9f651mr5443973f8f.39.1744896449800; Thu, 17 Apr 2025 06:27:29 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:a07e:3f08:7eef:b036]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm19951605f8f.42.2025.04.17.06.27.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:29 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Adriano Cordova , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Tom Rini Subject: [PATCH v5 1/4] net-lwip: change static function wget_loop() to be wget_do_request() Date: Thu, 17 Apr 2025 15:26:57 +0200 Message-ID: <20250417132718.2023555-2-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250417132718.2023555-1-jerome.forissier@linaro.org> References: <20250417132718.2023555-1-jerome.forissier@linaro.org> 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 wget_do_request() currently does so little before calling the static function wget_loop() that we may as well rename wget_loop() to wget_do_request() and put everything in one function. Signed-off-by: Jerome Forissier Acked-by: Sughosh Ganu --- (no changes since v4) Changes in v4: - New patch net/lwip/wget.c | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index ec098148835..2b512a1bc84 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -372,13 +372,14 @@ static int set_cacert(char * const saddr, char * const ssz) #endif #endif /* CONFIG_WGET_CACERT || CONFIG_WGET_BUILTIN_CACERT */ -static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) +int wget_do_request(ulong dst_addr, char *uri) { #if CONFIG_IS_ENABLED(WGET_HTTPS) altcp_allocator_t tls_allocator; #endif httpc_connection_t conn; httpc_state_t *state; + struct udevice *udev; struct netif *netif; struct wget_ctx ctx; char *path; @@ -394,6 +395,13 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) if (parse_url(uri, ctx.server_name, &ctx.port, &path, &is_https)) return CMD_RET_USAGE; + net_lwip_set_current(); + + if (!wget_info) + wget_info = &default_wget_info; + + udev = eth_get_dev(); + netif = net_lwip_new_netif(udev); if (!netif) return -1; @@ -469,16 +477,6 @@ static int wget_loop(struct udevice *udev, ulong dst_addr, char *uri) return -1; } -int wget_do_request(ulong dst_addr, char *uri) -{ - net_lwip_set_current(); - - if (!wget_info) - wget_info = &default_wget_info; - - return wget_loop(eth_get_dev(), dst_addr, uri); -} - int do_wget(struct cmd_tbl *cmdtp, int flag, int argc, char * const argv[]) { char *end; From patchwork Thu Apr 17 13:26:58 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881864 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp315136wrs; Thu, 17 Apr 2025 06:27:57 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCVjQSSir0P71+ZR4myZvLA0oXHxKzqpZskhFZxMW2c0ZSkZ1QfO/MKY20Zy/Mzo5In/Lo4vag==@linaro.org X-Google-Smtp-Source: AGHT+IHqkRQi9EPIfpEi/gugVux3zaIb99Nnl15RGVOziPhBib4UnNg6W5tnuxXi3PWB5NlZ8YUQ X-Received: by 2002:a05:600c:a181:b0:440:6760:d06a with SMTP id 5b1f17b1804b1-4406760d527mr11179325e9.5.1744896477606; Thu, 17 Apr 2025 06:27:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744896477; cv=none; d=google.com; s=arc-20240605; b=RrubV7gL/cUQ7eR9pp+czctp8euI/fQL9AW5sw1jDSK+ZZMzPDNQSXuXSrDkuSRqip 0HPP4LdLHsxUyIbIELjU89UCNw7pK4JYa2fDfxY3+Nn6nfUVrluZ3rD1q7prfpuiwjG+ DeHEVZ31jeLnJVg6qu2+i0BSG6RoloIGCi8q2oJ9Q9iVulFO4DgsHD8/+D1FwXiKVNUK X9WLNReIUohIO+NfSYZCPLAur7P9TRf/DXtOQi7iTRk9jlxqSCF8aQCNC8U7mKrPU7nU 4HqmuMgZhCPNkyIgD7gXnqUwY+WwoUsbtB1bYso8bgW4ymPuQuAIv/7VTU1ed+w5I1Xj UQxQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=eZOQjJFalRgpPeuxaB4yi+NuMS9a1y2RFiAI5YGeXrE=; fh=Qd7nANw/SoY8xScQE9Ppz5yy7BXhLnlMA6RPvGzTONs=; b=Xcu6AG3tN7zmf52gjNj8HUlfyyhoUsjdfQNgC7bMZu4osOOWplrWtYLNTCzqiM2Obr 0hXvFBXvv2Ow5hzMyICRQnK++Lychp5r4T5U8uioq8i+zslLB53oMDEJWLwQw8cB+C4J 7n6bzPb8zzMEB4Jrxicla24w2LdiLi9sGYwj2+O/qFBdKtHq8DjyGEMBYF/5pVhQUGy4 cMfe7/vRkjWnO2j2Cq30U0vBUWSmDJDRAokzfbzrYkGh04Yw1Ckv6jp5x/moj7DFdOth UXIj1sZuCri158dpWxXlDPOvlUpfaVo6e9ZskODVyL8vmCzwO/J+uu6xNpovaS/B9JIa zZPQ==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dOSrk6fb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id ffacd0b85a97d-39eaf427e62si9250274f8f.307.2025.04.17.06.27.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:57 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=dOSrk6fb; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id B51F583061; Thu, 17 Apr 2025 15:27:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="dOSrk6fb"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 76F6482CA8; Thu, 17 Apr 2025 15:27:34 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42f.google.com (mail-wr1-x42f.google.com [IPv6:2a00:1450:4864:20::42f]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 74AB283013 for ; Thu, 17 Apr 2025 15:27:31 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42f.google.com with SMTP id ffacd0b85a97d-39149bccb69so781530f8f.2 for ; Thu, 17 Apr 2025 06:27:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744896451; x=1745501251; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=eZOQjJFalRgpPeuxaB4yi+NuMS9a1y2RFiAI5YGeXrE=; b=dOSrk6fb2soE3N0ie1NrTFpLGhpW7RJNm5ecRF6MjwEPVOaDzlSvI1GF9BrGZ9gDPU iuRn3oKuL8kqJ2cKMvuWP51xdzSqYlMQE2B2r+gBM0uiVxfWiUVO/SbAm9HKVS8cSpsI ic7Jm1G/jo+2lfqoU3KKcZ6AZwYRKd1l6+JK2p83kN7+qYoHYGYcAQJRgVxRchTH8wMx KTHdkUjm8vocYh0SFt9ekCqcM0YBGjq8J6YEmeLIqFoA4/6oy1rL/Zxt2tKQ4wVh2em3 t4hWkpoWfX4xO8EDjnGt1nwvdwF5k7yTctdAb7EZJuXxusjRbiMXvNS1ju6RI8dKcDpc PMNw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744896451; x=1745501251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=eZOQjJFalRgpPeuxaB4yi+NuMS9a1y2RFiAI5YGeXrE=; b=iTUtQW7yCuvxpAmv+QOS68i+ar6LnmJLZuqT89FpWYlESt7CKip+x9Q208icI7gQ6X IUhh14lG1Y+NdtJe95vho5DCrP0SGCF74bcOW5KcGZFsxk2KwOFUqodHQLPFH+b6IeJI I82XCcGh7zNqhGld59QtVwYgQ++bYMQy/xW8tVLSbDFq94ytK8ZAiMxrT9nvBn01DfJe qR/u5qqWz/8GPKRaHtZ3GCSwiLBQORRPENUTvBwA674g0z1MYSEI8l3ZxF8c736M0JBj ESmF7wlSBSK2xoGevxVWtffAA4vdXBagErJNMucBWJnzMK+XuW3w7gOJ4Y/rloCKXy4M 0uhQ== X-Gm-Message-State: AOJu0Yxkb+LdXNYGd1Y8OG0gbUYLp/SRnUcaCl13PhrnChI0hczxsD7p /hXe0XJDOUr3rMXj3kHWPneDSUTg/2YDrvVMwb+ZhMggn9pIWhMKbxkXISe3WITDi8cungdWpnd JP4w= X-Gm-Gg: ASbGncuuSEjHCzmYovdYygHqD56KCPeLK/kBluWEP7GfmI/9KL4H1rtXFj8tj28kX3l r/ge+q97f/fezf8ZZo7nAqLyRbQXJTGSXm1xklCxyt+ibYIEtShmKtu+esxxiBKUE8O23g6Lnaa r3erfp0vCgROE1oBhwfLsgaOVo2gdx61S/DyQjmRAr9e2Zm1kClM5mnzfZBwCWzzl0qDZroy28Y Qi05iMKBDNN+eO78RBOyQdsWizyM1UZrnyEk+4rqmfkudb4DnAh/6HCcltvhb2IHJavasf1Z51v zMK0yypqMB70G23Irugc34ypkwa1NMAvxAzmuNcl0yKMxhdHJA== X-Received: by 2002:a5d:5f82:0:b0:39c:1404:3748 with SMTP id ffacd0b85a97d-39ee5b14a71mr5222860f8f.16.1744896450652; Thu, 17 Apr 2025 06:27:30 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:a07e:3f08:7eef:b036]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm19951605f8f.42.2025.04.17.06.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:30 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Heinrich Schuchardt , Adriano Cordova , Ilias Apalodimas , Javier Tia , Joe Hershberger , Mikhail Kshevetskiy , Ramon Fried , Simon Glass , Sughosh Ganu , Tom Rini Subject: [PATCH v5 2/4] net, net-lwip: wget: suppress console output when called by EFI Date: Thu, 17 Apr 2025 15:26:58 +0200 Message-ID: <20250417132718.2023555-3-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250417132718.2023555-1-jerome.forissier@linaro.org> References: <20250417132718.2023555-1-jerome.forissier@linaro.org> 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 Functions called from EFI applications should not do console output. Refactor the wget code to implement this requirement. The wget_http_info struct is used to hold the boolean that signifies whether the output is allowed or not. Signed-off-by: Jerome Forissier Reported-by: Heinrich Schuchardt --- Changes in v5: - Remove extra hunk in wget_do_request() already added by "net-lwip: change static function wget_loop() to be wget_do_request(): - Do not forget to silence the printf's that were added inside lwIP by commit 7a15ccb66217 ("lwip: tls: warn when no CA exists amd log certificate validation errors"). The "no CA certificates" and "verification failed" messages are moved outside of lwIP into wget.c, with the help of errno for the certificate verification case. Changes in v4: - Patch renamed, deals with NET in addition to NET_LWIP Changes in v3: - New patch doc/usage/cmd/wget.rst | 2 +- include/net-common.h | 2 + lib/efi_loader/efi_net.c | 2 +- .../src/apps/altcp_tls/altcp_tls_mbedtls.c | 8 ++-- net/lwip/wget.c | 37 ++++++++++++++----- net/wget.c | 23 +++++++++--- 6 files changed, 52 insertions(+), 22 deletions(-) diff --git a/doc/usage/cmd/wget.rst b/doc/usage/cmd/wget.rst index cc82e495a29..44033aaff39 100644 --- a/doc/usage/cmd/wget.rst +++ b/doc/usage/cmd/wget.rst @@ -141,9 +141,9 @@ https://cacerts.digicert.com/DigiCertTLSRSA4096RootG5.crt. Bytes transferred = 1864 (748 hex) # Another server not signed against Digicert will fail => wget https://www.google.com/ - Certificate verification failed HTTP client error 4 + Certificate verification failed # Disable authentication to allow the command to proceed anyways => wget cacert none => wget https://www.google.com/ diff --git a/include/net-common.h b/include/net-common.h index 30860f5975a..1043b24d0b9 100644 --- a/include/net-common.h +++ b/include/net-common.h @@ -555,6 +555,7 @@ enum wget_http_method { * Filled by client. * @hdr_cont_len: content length according to headers. Filled by wget * @headers: buffer for headers. Filled by wget. + * @silent: do not print anything to the console. Filled by client. */ struct wget_http_info { enum wget_http_method method; @@ -565,6 +566,7 @@ struct wget_http_info { bool check_buffer_size; u32 hdr_cont_len; char *headers; + bool silent; }; extern struct wget_http_info default_wget_info; diff --git a/lib/efi_loader/efi_net.c b/lib/efi_loader/efi_net.c index b3291b4f1d5..9ff0b691ee1 100644 --- a/lib/efi_loader/efi_net.c +++ b/lib/efi_loader/efi_net.c @@ -51,7 +51,7 @@ static int next_dp_entry; static struct wget_http_info efi_wget_info = { .set_bootdev = false, .check_buffer_size = true, - + .silent = true, }; #endif diff --git a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c index ef51a5ac168..7459bfa468f 100644 --- a/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c +++ b/lib/lwip/lwip/src/apps/altcp_tls/altcp_tls_mbedtls.c @@ -60,6 +60,8 @@ #if LWIP_ALTCP_TLS && LWIP_ALTCP_TLS_MBEDTLS +#include "lwip/errno.h" + #include "lwip/altcp.h" #include "lwip/altcp_tls.h" #include "lwip/priv/altcp_priv.h" @@ -299,7 +301,8 @@ altcp_mbedtls_lower_recv_process(struct altcp_pcb *conn, altcp_mbedtls_state_t * LWIP_DEBUGF(ALTCP_MBEDTLS_DEBUG, ("mbedtls_ssl_handshake failed: %d\n", ret)); /* handshake failed, connection has to be closed */ if (ret == MBEDTLS_ERR_X509_CERT_VERIFY_FAILED) { - printf("Certificate verification failed\n"); + /* provide a cause for why the connection is closed to the called */ + errno = EPERM; } if (conn->err) { conn->err(conn->arg, ERR_CLSD); @@ -844,9 +847,6 @@ altcp_tls_create_config(int is_server, u8_t cert_count, u8_t pkey_count, int hav altcp_mbedtls_free_config(conf); return NULL; } - if (authmode == MBEDTLS_SSL_VERIFY_NONE) { - printf("WARNING: no CA certificates, HTTPS connections not authenticated\n"); - } mbedtls_ssl_conf_authmode(&conf->conf, authmode); mbedtls_ssl_conf_rng(&conf->conf, mbedtls_ctr_drbg_random, &altcp_tls_entropy_rng->ctr_drbg); diff --git a/net/lwip/wget.c b/net/lwip/wget.c index 2b512a1bc84..63583e4c6e7 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -8,6 +8,7 @@ #include #include #include "lwip/altcp_tls.h" +#include #include #include #include @@ -217,7 +218,8 @@ static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, memcpy((void *)ctx->daddr, buf->payload, buf->len); ctx->daddr += buf->len; ctx->size += buf->len; - if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + if (!wget_info->silent && + ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { printf("#"); ctx->prevsize = ctx->size; } @@ -255,11 +257,15 @@ static void httpc_result_cb(void *arg, httpc_result_t httpc_result, elapsed = get_timer(ctx->start_time); if (!elapsed) elapsed = 1; - if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) - printf("\n"); - printf("%u bytes transferred in %lu ms (", rx_content_len, elapsed); - print_size(rx_content_len / elapsed * 1000, "/s)\n"); - printf("Bytes transferred = %lu (%lx hex)\n", ctx->size, ctx->size); + if (!wget_info->silent) { + if (rx_content_len > PROGRESS_PRINT_STEP_BYTES) + printf("\n"); + printf("%u bytes transferred in %lu ms (", rx_content_len, + elapsed); + print_size(rx_content_len / elapsed * 1000, "/s)\n"); + printf("Bytes transferred = %lu (%lx hex)\n", ctx->size, + ctx->size); + } if (wget_info->set_bootdev) efi_set_bootdev("Http", ctx->server_name, ctx->path, map_sysmem(ctx->saved_daddr, 0), rx_content_len); @@ -339,7 +345,8 @@ static int _set_cacert(const void *addr, size_t sz) mbedtls_x509_crt_init(&crt); ret = mbedtls_x509_crt_parse(&crt, cacert, cacert_size); if (ret) { - printf("Could not parse certificates (%d)\n", ret); + if (!wget_info->silent) + printf("Could not parse certificates (%d)\n", ret); free(cacert); cacert = NULL; cacert_size = 0; @@ -421,9 +428,10 @@ int wget_do_request(ulong dst_addr, char *uri) if (cacert_auth_mode == AUTH_REQUIRED) { if (!ca || !ca_sz) { - printf("Error: cacert authentication mode is " - "'required' but no CA certificates " - "given\n"); + if (!wget_info->silent) + printf("Error: cacert authentication " + "mode is 'required' but no CA " + "certificates given\n"); return CMD_RET_FAILURE; } } else if (cacert_auth_mode == AUTH_NONE) { @@ -438,6 +446,10 @@ int wget_do_request(ulong dst_addr, char *uri) */ } + if (!ca && !wget_info->silent) { + printf("WARNING: no CA certificates, "); + printf("HTTPS connections not authenticated\n"); + } tls_allocator.alloc = &altcp_tls_alloc; tls_allocator.arg = altcp_tls_create_config_client(ca, ca_sz, @@ -462,6 +474,8 @@ int wget_do_request(ulong dst_addr, char *uri) return CMD_RET_FAILURE; } + errno = 0; + while (!ctx.done) { net_lwip_rx(udev, netif); sys_check_timeouts(); @@ -474,6 +488,9 @@ int wget_do_request(ulong dst_addr, char *uri) if (ctx.done == SUCCESS) return 0; + if (errno == EPERM && !wget_info->silent) + printf("Certificate verification failed\n"); + return -1; } diff --git a/net/wget.c b/net/wget.c index c73836cbc9d..3c0fff488eb 100644 --- a/net/wget.c +++ b/net/wget.c @@ -59,8 +59,10 @@ static inline int store_block(uchar *src, unsigned int offset, unsigned int len) if (CONFIG_IS_ENABLED(LMB) && wget_info->set_bootdev) { if (store_addr < image_load_addr || lmb_read_check(store_addr, len)) { - printf("\nwget error: "); - printf("trying to overwrite reserved memory...\n"); + if (!wget_info->silent) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory\n"); + } return -1; } } @@ -76,6 +78,9 @@ static void show_block_marker(u32 packets) { int cnt; + if (wget_info->silent) + return; + if (content_length != -1) { if (net_boot_file_size > content_length) content_length = net_boot_file_size; @@ -101,11 +106,15 @@ static void tcp_stream_on_closed(struct tcp_stream *tcp) net_set_state(wget_loop_state); if (wget_loop_state != NETLOOP_SUCCESS) { net_boot_file_size = 0; - printf("\nwget: Transfer Fail, TCP status - %d\n", tcp->status); + if (!wget_info->silent) + printf("\nwget: Transfer Fail, TCP status - %d\n", + tcp->status); return; } - printf("\nPackets received %d, Transfer Successful\n", tcp->rx_packets); + if (!wget_info->silent) + printf("\nPackets received %d, Transfer Successful\n", + tcp->rx_packets); wget_info->file_size = net_boot_file_size; if (wget_info->method == WGET_HTTP_METHOD_GET && wget_info->set_bootdev) { efi_set_bootdev("Http", NULL, image_url, @@ -139,7 +148,8 @@ static void tcp_stream_on_rcv_nxt_update(struct tcp_stream *tcp, u32 rx_bytes) tcp->state == TCP_ESTABLISHED) goto end; - printf("ERROR: misssed HTTP header\n"); + if (!wget_info->silent) + printf("ERROR: misssed HTTP header\n"); tcp_stream_close(tcp); goto end; } @@ -346,7 +356,8 @@ void wget_start(void) tcp_stream_set_on_create_handler(tcp_stream_on_create); tcp = tcp_stream_connect(web_server_ip, server_port); if (!tcp) { - printf("No free tcp streams\n"); + if (!wget_info->silent) + printf("No free tcp streams\n"); net_set_state(NETLOOP_FAIL); return; } From patchwork Thu Apr 17 13:26:59 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881863 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp315082wrs; Thu, 17 Apr 2025 06:27:49 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUqyWym1ubaav6lBM2cJFDVOzfTa1CzbyNuO7kfPOzf4O67Y+We1CzmQ9zvO9ooukb3KbXNaA==@linaro.org X-Google-Smtp-Source: AGHT+IEMET6W/hpSb/vS+uURjWzj/KKRrZq+6wl2lR3NXu9Vmp26Iw9Q+85Ct2+4G7xHNbnyR1/n X-Received: by 2002:a05:600c:3b07:b0:43c:f75a:eb54 with SMTP id 5b1f17b1804b1-4405d61c938mr60888925e9.13.1744896469494; Thu, 17 Apr 2025 06:27:49 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744896469; cv=none; d=google.com; s=arc-20240605; b=ObuNGhPr27jbH1HgZDb3rOoXBa9TCZATZTQ+vwy4B2exy4id1WEAJpF1tKFcL8R5mh OHMqQmVDhNXK0TMIacKkeZqg6Nd61PaaMdssSpzhrELCcEVFd4mW1h5ANdWaVH/FMDT7 geIoIxf/r1n2emI6NDawBKM2JIqAJF6HUmmpxZJABtTJSvQvZX6Kgq6Oyiu63WvzVZYQ ZSHy5YSI5hEIol2UT0LJgUuL79JRxsXpLA93inVZyVgmocbPmdaTioJfos84RjasXtbz EJ5UDswlV11bbwwIQh9Ye7q7VopYBd5e/uT9ibxhyk+WpihJ44ci51n7ekzNSawHRQ/w 1aDw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=NH2Pl2IO51nijsyi+Ru2HA3FymfKngVtLYLV5gURHcg=; fh=vZMGN31IDYvBGpSoI/uxqw824em/ddbq/o428IGX5FI=; b=PVQg0bL2mpFyl148C4POHhldlOC+nCTPwofCHaVzL6ed0g4rtus+FEG68upMppoHUz TAdiWmRpIqdn165ZkOu9MJV8ZUGDP+7u2N3AQCk58VO6TFA3H+H14R26Mz+ny8hbPmbc EC1+LCH6Zyv7JUz6RfeCJJHxg9sx3YHFuOiAeVPHopboy3/XdurJJ4Nk31tj+U/v/ZtL Chbb13vzUo0mGg4E+La8LQzhOnDaD2HEJIkc5RzMdq3Mm3oPIRrp90esHvgee0UvJ9eL gcScOmno81BJLUt9xnS7m5X6ZW7hD7UlrTzi4IcjCqOYP2oHrjeZib+fi6k5TIViKnnt ss4A==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w+l+8lxm; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 5b1f17b1804b1-4405b5a505bsi30086945e9.152.2025.04.17.06.27.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:49 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=w+l+8lxm; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 6CFBA83045; Thu, 17 Apr 2025 15:27:35 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="w+l+8lxm"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 3D5118304A; Thu, 17 Apr 2025 15:27:34 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id 2A3AB82CA8 for ; Thu, 17 Apr 2025 15:27:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42e.google.com with SMTP id ffacd0b85a97d-39ac56756f6so797111f8f.2 for ; Thu, 17 Apr 2025 06:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744896451; x=1745501251; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=NH2Pl2IO51nijsyi+Ru2HA3FymfKngVtLYLV5gURHcg=; b=w+l+8lxmuwbgDX9PjM+xgrpUWc/yqxLVQKFznMWNWXxpuhHYXNpRv1L5AVpYCLI/nv OE+EwL9eMmBYP3gM+89/tUUJCIHeS1bTDqH7O/cbiqpwutGWwaQ/+9DF6VKQyQw8C/pB BElP4A4lrPuitJojKcOa0tOgdk0cn6yJxzUXqGAW5Br1ZI2mTDlK6QMwTAKyCwXJFcOR pJ4y128NLIpofs+ER5VStOgEIi14AxWJZBgWFd/w/R4eDiYs+8tN/wPTN1tg6pJXrKcA 8YmshZGsjZtfqrXNxmq7hAH2kLUvPfDLXtdhvhIBAsUPKjY/tVVEHxG852t3oWU2kk5b y/Qw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744896451; x=1745501251; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=NH2Pl2IO51nijsyi+Ru2HA3FymfKngVtLYLV5gURHcg=; b=a8+rHDmYGI4ZcR2eeu9R/f3a/3CYg71pPW2yaT2IXVAO6jmOxwKED18NVHHyUW6H82 wx2Eu87lifw1yluCXCrR+oPhPW+KQuGMBUVfjswPYrDWAU/D5lsJHGm05N8BwrDgkwOF u6r5VZ9Cgrp7nZDNpu6b6By8IY36C2qEOHh3tVK7FfQJpRv5dpSMcJEwTjn/7Cl6JkB4 H5tJ6zwfzIzRgBDmvBSFQYif+wOwzmbXQcH2m5UAQS6Dzpmql2iwtf6CJGLGzDbexQ2l WizljagaECOQQvSpFp5i0dkzcrH6k0nhBHdlqyNxXNKPnpZ97OsQehBhoEcwPd67epP/ hpZw== X-Gm-Message-State: AOJu0Yw4s7SJMT4YmWBc5+AYe5yHq3luW80UoH83JfJ5zobrJ4mHftUZ dIGHMxGB3QZxRSi0LhyCWBMu0uhQpuP3G2MZ17U/5jPyVO5lWhbz2PSru+DBCj2bndadk3ZxH79 8kx0= X-Gm-Gg: ASbGnct6Pi3DSFCh9qCerNDF7kbjX1DhzNQL2EVajaJORIY5zUFSbf6OfUeEHbhYa48 a2p4wiWN8n7jVGO/wP4jS7ZjFtjTk4Tts8IDVNtGraBZPj5bdfIHOOSPZXZsyjje9LTdYwlfrtn Az/V/MgNTbgWuBgMO+PfsLXnHkAjuSEB2ok04tj0r1++eTKuIly8X+aeaYNPeMip6VN4zwEn0Ml fLCDcjxD5dDgPFgZ8i6Qyyi25uUn0mE2frnCxPxo7vDjDtnQ+mL9KaEGXE6Io0HMmo1xbkx+rQK FFy0q2CfaaPgl4BJAm/QHY/5urPVQAJAJi0H+gQGFFgntpEkaw== X-Received: by 2002:a05:6000:18ab:b0:39c:1f02:44ae with SMTP id ffacd0b85a97d-39ee5b35dbemr5924491f8f.27.1744896451434; Thu, 17 Apr 2025 06:27:31 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:a07e:3f08:7eef:b036]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm19951605f8f.42.2025.04.17.06.27.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:31 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Adriano Cordova , Heinrich Schuchardt , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Tom Rini Subject: [PATCH v5 3/4] net-lwip: wget: add LMB and buffer checks Date: Thu, 17 Apr 2025 15:26:59 +0200 Message-ID: <20250417132718.2023555-4-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250417132718.2023555-1-jerome.forissier@linaro.org> References: <20250417132718.2023555-1-jerome.forissier@linaro.org> 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 Legacy NET wget invokes a store_block() function which performs buffer validation (LMB, address wrapping). Do the same with NET_LWIP. Signed-off-by: Jerome Forissier Suggested-by: Sughosh Ganu Acked-by: Sughosh Ganu --- (no changes since v4) Changes in v4: - The 'silent' boolean in stored in struct wget_http_info (same as NET) Changes in v3: - store_block(): add Sphinx-like documentation - store_block(): do not print to the console if ctx->silent Changes in v2: - httpc_recv_cb(): add a call to altcp_abort(). Otherwise the transfer continues and we try to write later blocks which makes no sense if one has been rejected already. Thanks Sughosh G. for testing and reporting. net/lwip/wget.c | 64 ++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 55 insertions(+), 9 deletions(-) diff --git a/net/lwip/wget.c b/net/lwip/wget.c index 63583e4c6e7..4ec00de96b2 100644 --- a/net/lwip/wget.c +++ b/net/lwip/wget.c @@ -6,6 +6,7 @@ #include #include #include +#include #include #include "lwip/altcp_tls.h" #include @@ -202,11 +203,58 @@ static int parse_legacy_arg(char *arg, char *nurl, size_t rem) return 0; } +/** + * store_block() - copy received data + * + * This function is called by the receive callback to copy a block of data + * into its final location (ctx->daddr). Before doing so, it checks if the copy + * is allowed. + * + * @ctx: the context for the current transfer + * @src: the data received from the TCP stack + * @len: the length of the data + */ +static int store_block(struct wget_ctx *ctx, void *src, u16_t len) +{ + ulong store_addr = ctx->daddr; + uchar *ptr; + + /* Avoid overflow */ + if (wget_info->buffer_size && wget_info->buffer_size < ctx->size + len) + return -1; + + if (CONFIG_IS_ENABLED(LMB) && wget_info->set_bootdev) { + if (store_addr + len < store_addr || + lmb_read_check(store_addr, len)) { + if (!wget_info->silent) { + printf("\nwget error: "); + printf("trying to overwrite reserved memory\n"); + } + return -1; + } + } + + ptr = map_sysmem(store_addr, len); + memcpy(ptr, src, len); + unmap_sysmem(ptr); + + ctx->daddr += len; + ctx->size += len; + if (ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { + if (!wget_info->silent) + printf("#"); + ctx->prevsize = ctx->size; + } + + return 0; +} + static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, err_t err) { struct wget_ctx *ctx = arg; struct pbuf *buf; + err_t ret; if (!pbuf) return ERR_BUF; @@ -215,19 +263,17 @@ static err_t httpc_recv_cb(void *arg, struct altcp_pcb *pcb, struct pbuf *pbuf, ctx->start_time = get_timer(0); for (buf = pbuf; buf; buf = buf->next) { - memcpy((void *)ctx->daddr, buf->payload, buf->len); - ctx->daddr += buf->len; - ctx->size += buf->len; - if (!wget_info->silent && - ctx->size - ctx->prevsize > PROGRESS_PRINT_STEP_BYTES) { - printf("#"); - ctx->prevsize = ctx->size; + if (store_block(ctx, buf->payload, buf->len) < 0) { + altcp_abort(pcb); + ret = ERR_BUF; + goto out; } } - altcp_recved(pcb, pbuf->tot_len); + ret = ERR_OK; +out: pbuf_free(pbuf); - return ERR_OK; + return ret; } static void httpc_result_cb(void *arg, httpc_result_t httpc_result, From patchwork Thu Apr 17 13:27:00 2025 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jerome Forissier X-Patchwork-Id: 881865 Delivered-To: patch@linaro.org Received: by 2002:a5d:474d:0:b0:38f:210b:807b with SMTP id o13csp315217wrs; Thu, 17 Apr 2025 06:28:06 -0700 (PDT) X-Forwarded-Encrypted: i=2; AJvYcCUeGV+9FbPSaaiWMwxIOM4sp/I9RHhstOROJ/fCwYxSRm58PgPu2EI3qdcVEo4onaiALCWyXw==@linaro.org X-Google-Smtp-Source: AGHT+IEbed+Aex3Kucr2GucL/RJ1BT39z775AJ1khdDfobzCqME/HTQ2NyPHyTv6yQDhNrXRQlwV X-Received: by 2002:a05:600c:3eca:b0:43d:585f:ebf5 with SMTP id 5b1f17b1804b1-4405d5fae0cmr56773025e9.1.1744896486325; Thu, 17 Apr 2025 06:28:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1744896486; cv=none; d=google.com; s=arc-20240605; b=CdYnQtR3AvZJqEQVBHNRA8Vbb/LzOf/c6dlodNGa1+i0QaAEAZittR8R0bQsMs08zQ TeWcXmteBOnn2VJ7z8bZhtEXlK7JSQtVvlScPgjlP1b62kJUOpKAoWkBMEd4TQs6qoy6 Pxw+3XaLjAQjE9JvUTIcTk4uPdUiUy1Q7AmXcb8B8ZdyFeGSsMw3xy2dYxYrDJ3LZpJ3 r8MuRB/YZ4MlZMo+bWCX1q3fCnpr/yAWiVvomI+xcUc66N1OzcJQWv/bZeiWhTKjcFwM KLLX6hnxOIwiM6ozgTBfTeaVyThx8eOpvUk4t2nSpBhey+qNE4oKkAMnKKkh6+A05hDw pNrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20240605; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=fAuMqpH5iZGzS2bdQo+tUVHECNwVltITZ8VKenT7qZw=; fh=PQg1uaxoFkVPH7GvYt2sPX/rmqpadkXu1gxBQgKczic=; b=BTZLC4OwlhBgr5wLEQ45rem4YTUIxDibX67hBxgIRn3JggBeTjdEnGexaMeK1+olda n8Oi7Xd+bsTaYhNh9X4qVt9pw/SrrrYEvgn66+PjLww5r6JvtLGjUB74zb+l2AS13UDM /NX+BQX8WQ4fSU6fTAKCWb2CCRbf9F2+s6eavVTyYStomIykJ8d4dMcETq9n96q5hBqp eQGAxGrmV9jJFWajFJT0GJYULF9155nMoHhyEav77RMtOx5vUEUnNaFipGY5v+O5l4Ed WWHNGl01wwUQW7kAnTCntbselKrolCdmJBwgJNjsejx3QtE3mop1HJh1kIMOiqSSBqRB mZbA==; dara=google.com ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YJbfr9GX; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id 5b1f17b1804b1-4405b53df94si30445325e9.166.2025.04.17.06.28.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:28:06 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=YJbfr9GX; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org; dara=neutral header.i=@linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 07C608303B; Thu, 17 Apr 2025 15:27:38 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="YJbfr9GX"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D9C3782CA8; Thu, 17 Apr 2025 15:27:34 +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=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_BLOCKED, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id D3EE28303B for ; Thu, 17 Apr 2025 15:27:32 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=jerome.forissier@linaro.org Received: by mail-wr1-x42d.google.com with SMTP id ffacd0b85a97d-39c266c1389so565665f8f.1 for ; Thu, 17 Apr 2025 06:27:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; t=1744896452; x=1745501252; darn=lists.denx.de; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=fAuMqpH5iZGzS2bdQo+tUVHECNwVltITZ8VKenT7qZw=; b=YJbfr9GXkDBW0Fsew3UADo7Nit6C3suY27wip4ahULWM+8ZrqB7WAXUH/IgEVYEYqj S02IaDZDDMHkjxGX+40d5XGLAqXT19nhScLjYr8EsTBXRolwerY5Vg6lQIT+GaLSCRDR IHm9JCk/W2hhXlr+kA5d2f4IE3/dXNhtEUJK0XmphbbfR4xX20nqy/zA1tilpyivuLB1 Q2e9SduOUcwJ4egVPiVeb78CaA9dL/SsJRinmGo4eUuld6RqUeuTgp86Yl41P4dKnxCB OxnbLZ+nalQ525JhgWMOYAKNOnlAHlyNqTf9BrutxuMQmVKF3+qpcF4GfClP4muBAeXb 7tCA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1744896452; x=1745501252; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=fAuMqpH5iZGzS2bdQo+tUVHECNwVltITZ8VKenT7qZw=; b=cSGWS692N30SeWd/Ld8qy65JC04CO660xdFqdbG/c/ekq4J4gmzVqj7X83eN2W9eXZ yGID/eaCKcGBA7D2sFKu2IBOBbpfQ4PEyDfpcRCrQYSa9LxYQ3JxIObQebiySQK4QmHY bJvLmbV1tGObjrpqkMNo37rLMa0XOMUvf0VaLXFTYVx9nTyhZR7Cr7Rbon953nnV6/0V 0NBL2gvGNWhw/84UN3omOG6/Yyx6tdc4c4z90aM+V63GD9y3cBXxnD7gqqKr9qPXcGki vBmqus7b6SCiODp+bjVpsRt5XFinYz94WlPT1OE6dnp32cACIUbxLSnDJkFQueMqtroT t0Rg== X-Gm-Message-State: AOJu0Yz8lHjxK7VsBWtEw+cno+F0/vUaazceL0VIombHNn+m8GGRPtkH 2QmNpGFj1y1OmC8FxadT/UIy8e8P2a20LN8CdiZCjsm9DPTf0yW8KuljaZfiRN9mOJYjuhiQl2M gX3Q= X-Gm-Gg: ASbGnctvtUo1T1SLMtngAuvVP7QLILQSPwy/shfJu0kVpPfBLJdUfBxIAnQEdPq8Z3d Ydk6gwLj9+qzICMzCrsWFria/o7bMXVoWhQpCV2Ir8Lun6mQ0SZ17pLUISrA2gQHDBgsdmUx/Hw ciaSCX+JqVAjKYTwrIHqNlwOHqaGYovqydgXYLztev9jfTaLZnSGZHvldrbOBC+j8d24+NbFmn/ oA8z0DE6Udj/wRRSPpjv4CvbuHQ7vUO/SRngfvKGYfqOy03fk5mIkTo0kqZmhUBhf0yEIwP8kni k3uj7YJHVrTXDN7toY5JR3o1a1xEvjFfVO8oKBlHbOIc6CNrYXd9RpRSJ6Fx X-Received: by 2002:a05:6000:2209:b0:391:39bd:a361 with SMTP id ffacd0b85a97d-39ee5b19f89mr4975308f8f.18.1744896452156; Thu, 17 Apr 2025 06:27:32 -0700 (PDT) Received: from builder.. ([2a01:e0a:3cb:7bb0:a07e:3f08:7eef:b036]) by smtp.gmail.com with ESMTPSA id ffacd0b85a97d-39eae977513sm19951605f8f.42.2025.04.17.06.27.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 17 Apr 2025 06:27:31 -0700 (PDT) From: Jerome Forissier To: U-Boot mailing list Cc: Jerome Forissier , Sughosh Ganu , Ilias Apalodimas , Joe Hershberger , Ramon Fried , Tom Rini Subject: [PATCH v5 4/4] net-lwip: tftp: add LMB and buffer checks Date: Thu, 17 Apr 2025 15:27:00 +0200 Message-ID: <20250417132718.2023555-5-jerome.forissier@linaro.org> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20250417132718.2023555-1-jerome.forissier@linaro.org> References: <20250417132718.2023555-1-jerome.forissier@linaro.org> 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 Legacy NET tftp invokes a store_block() function which performs buffer validation (LMB, address wrapping). Do the same with NET_LWIP. Signed-off-by: Jerome Forissier Suggested-by: Sughosh Ganu Acked-by: Sughosh Ganu --- (no changes since v3) Changes in v3: - store_block(): add Sphinx-like documentation net/lwip/tftp.c | 56 +++++++++++++++++++++++++++++++++++++++---------- 1 file changed, 45 insertions(+), 11 deletions(-) diff --git a/net/lwip/tftp.c b/net/lwip/tftp.c index 123d66b5dba..c7f1420ca0f 100644 --- a/net/lwip/tftp.c +++ b/net/lwip/tftp.c @@ -8,6 +8,7 @@ #include #include #include +#include #include #include #include @@ -31,6 +32,47 @@ struct tftp_ctx { enum done_state done; }; +/** + * store_block() - copy received data + * + * This function is called by the receive callback to copy a block of data + * into its final location (ctx->daddr). Before doing so, it checks if the copy + * is allowed. + * + * @ctx: the context for the current transfer + * @src: the data received from the TCP stack + * @len: the length of the data + */ +static int store_block(struct tftp_ctx *ctx, void *src, u16_t len) +{ + ulong store_addr = ctx->daddr; + void *ptr; + + if (CONFIG_IS_ENABLED(LMB)) { + if (store_addr + len < store_addr || + lmb_read_check(store_addr, len)) { + puts("\nTFTP error: "); + puts("trying to overwrite reserved memory...\n"); + return -1; + } + } + + ptr = map_sysmem(store_addr, len); + memcpy(ptr, src, len); + unmap_sysmem(ptr); + + ctx->daddr += len; + ctx->size += len; + ctx->block_count++; + if (ctx->block_count % 10 == 0) { + putc('#'); + if (ctx->block_count % (65 * 10) == 0) + puts("\n\t "); + } + + return 0; +} + static void *tftp_open(const char *fname, const char *mode, u8_t is_write) { return NULL; @@ -71,17 +113,9 @@ static int tftp_write(void *handle, struct pbuf *p) struct tftp_ctx *ctx = handle; struct pbuf *q; - for (q = p; q; q = q->next) { - memcpy((void *)ctx->daddr, q->payload, q->len); - ctx->daddr += q->len; - ctx->size += q->len; - ctx->block_count++; - if (ctx->block_count % 10 == 0) { - putc('#'); - if (ctx->block_count % (65 * 10) == 0) - puts("\n\t "); - } - } + for (q = p; q; q = q->next) + if (store_block(ctx, q->payload, q->len) < 0) + return -1; return 0; }