Received: by 2002:a05:7412:3290:b0:fa:6e18:a558 with SMTP id ev16csp913280rdb; Fri, 26 Jan 2024 15:16:40 -0800 (PST) X-Google-Smtp-Source: AGHT+IE/ImLLar1scHo3CK5v8c9YEAgN+VfmnTpIcBkVhJR5/hSmigw/iLvAinoHuNLvM279yHF3 X-Received: by 2002:a17:906:451:b0:a27:c4d2:c649 with SMTP id e17-20020a170906045100b00a27c4d2c649mr268512eja.59.1706310999905; Fri, 26 Jan 2024 15:16:39 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706310999; cv=pass; d=google.com; s=arc-20160816; b=K4P3375KdSoBQy93Q7jDI8WIGocNfXfpMv/Fet1wxH1LUn7a7WsfMMIq5PplkI4i5S XnZ87LplIR8as/fui5bk7+RtaC+yMAyAzAEcGzovEMSh+Lt5csFs+dq7Fm3P6NR7d+AU 4YGB+RgisKoaIAn+cVh3jeoyMJCgWpsfpCmgQpGPj++RmfNW6rjgh+sgdSeg50pl3F2z onlpiX+mtw1aAHNAAozmtdlOT+BqEnog/ciX2VZb717D3/Xr2kijWBOzVhk7cdHsk0dF oej0OA7Q+LAParWLpuPuRZBq7B0+Hanqv7XxTRxgxkqPbtQphiOXFVCIcsea+TJBKuW6 Fqyg== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=HGFbx+2eRIKYYfw924Gczlw/lLoyAbfAHs5r+gBC2OQ=; fh=+EB6oBnXtBrxaPMIm1rb1kOyvjkddCLSgL4/UeSWQvM=; b=vq2YY6l4JJJ/+wR+2SCHLM9GwCFo1JMYh7n40Sm3fKPb/z+V1EfHrquDot7F2lqSf2 LzhOHEga927WTDC3lAifbRbEWnTzGx5IkFS3S6b/00QykncZNjmg/UrAPtTMfS/nRn0/ 9xBwP8ZnY+NXHXer877HWR6ARLakdx4J4y+MpcsWhbi2YWyx52zBZEFmQjHlxUCmZU4X EiTP3KG73D9OD1o+1hRXHJxdm1GYs4uYUm4yHypYcwSbO0tMm9OGfLFXYBz9Oku1zmIB aU72KBHZpHAyn0MxNONCOVK54ITLPAmoj12ff4SKY4lnNtXVoVmIIKfGnj4Uk08Niikk MKuQ== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lyL9QUuj; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-40815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40815-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id u20-20020a1709064ad400b00a26d99e7f44si918801ejt.1040.2024.01.26.15.16.39 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 15:16:39 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-40815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=lyL9QUuj; arc=pass (i=1 spf=pass spfdomain=gmail.com dkim=pass dkdomain=gmail.com dmarc=pass fromdomain=gmail.com); spf=pass (google.com: domain of linux-kernel+bounces-40815-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-40815-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 649CE1F21D6A for ; Fri, 26 Jan 2024 23:16:38 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id E713D5EE7C; Fri, 26 Jan 2024 23:14:12 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="lyL9QUuj" Received: from mail-pl1-f177.google.com (mail-pl1-f177.google.com [209.85.214.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id A47915EE62; Fri, 26 Jan 2024 23:14:10 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.177 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706310852; cv=none; b=h+WIWPkyKNIh8F4Sl0nleBlIHLmxhlZkQ/0B0y5UZm4lV64a2WN0zAdS3V9X294AYxCzh+VLn81dTtgK8Nt7PNuN8XACo3XtaEHheyWvivc1vOH7JsOpTvKiaRk2lNMEMqmeMgBtPOPMFAiJvZr7BfvQj7aEMKO+QIeW6QKNtpk= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706310852; c=relaxed/simple; bh=gcaCmv31jC9+dLD+970bShIol4o9Uq98lPUTwZv23Io=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=QCVEcRdao61FouO2YflVBkvhs7Qv+Pk1s0zVO9yG37C53iTkBoohgLG6COT+dgKRED9QkFJa9/gVSJ64Uabp0puyg7SpMydQF8AnTWsp7pk0HpICDRC+RvES5PonIJCq0jU8xIrKpAPEEx80Klm8RPfgGnlzy0f8fHvTXkUdVP8= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=lyL9QUuj; arc=none smtp.client-ip=209.85.214.177 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Received: by mail-pl1-f177.google.com with SMTP id d9443c01a7336-1d711d7a940so8358445ad.1; Fri, 26 Jan 2024 15:14:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706310850; x=1706915650; darn=vger.kernel.org; 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=HGFbx+2eRIKYYfw924Gczlw/lLoyAbfAHs5r+gBC2OQ=; b=lyL9QUujNxrLi9UaunMf2pKmy8U+0UUvFUa5ln/NBtl7X+3CGsdlmFn0itJdggZZZY cGAGL8ptlySTZhABfHwtQ3DsaQeR2o+109KivhV/PMhpO6dRztNWjACB/RDNHLrQ/gqI ruA0PNX6aSN7uZTREClqwBYwh0e2VxQp/ZF23JVJ8J1QO5k2mE+3Yc+XjHRPEavSn7zA /Jubir2MHSP0RvmHiIUvbuHxFFzR7IJYNpwPH6kvJDZJ160nHej69Gb+zLSqpO7B/cr6 o49w18gU0v7eQnXTjqo+opPncKHLyPqxiHggyoS+QRznfKiFb+GaNcXIOHDM0K7Yu6gF 42pg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706310850; x=1706915650; 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=HGFbx+2eRIKYYfw924Gczlw/lLoyAbfAHs5r+gBC2OQ=; b=fdt1OclPrUsNBP6VTBVOSqC86YA9wmq/Mk2YUVt+cCJmUxX1PDKzabhziIYlDABZBo eYg3FZducMNrmBfOdvOg6Dpcyx+tDjmlEt5Q8qyxIDwHSmBlb4jteKiUCLF3tmpn3X0u 4oHYzV98lnVBk5LxuvYVfo2k+OblqTmlRODtK65ykCWodmsLVTLSkMXkJHUaRTbn9ZMX LK2f8zi6NkhYv8i5UdAus8d/E+U0GHXsaQJaSJd6vl1MNQ1oSoLGGICESVtqVX0n9xct 0+jD3YolJupN9N5+XozP6cdvqjKVJ0D7B4Bd5CmjuIVAvSMQ8g1oJNglexmKXZOhF/2D veSQ== X-Gm-Message-State: AOJu0YxF7PR/oxS5itdtt4xg3CvBmsPQnBTp4MJ0PWaEC+SOTGbioecz IURv3MWbyDy1YploNmhRr9l7Wsr5BVp9EJAm3RAchotnMwC0dI5k X-Received: by 2002:a17:902:ce83:b0:1d6:f87f:7627 with SMTP id f3-20020a170902ce8300b001d6f87f7627mr672487plg.130.1706310850069; Fri, 26 Jan 2024 15:14:10 -0800 (PST) Received: from localhost ([2601:644:9380:8cd0::7fb4]) by smtp.gmail.com with ESMTPSA id md8-20020a17090b23c800b002933c85eb64sm1659421pjb.53.2024.01.26.15.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 26 Jan 2024 15:14:09 -0800 (PST) From: Matthew Wood To: "David S. Miller" , Eric Dumazet , Jakub Kicinski , Paolo Abeni Cc: leitao@debian.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org Subject: [PATCH net-next v2 8/8] net: netconsole: append userdata to fragmented netconsole messages Date: Fri, 26 Jan 2024 15:13:43 -0800 Message-ID: <20240126231348.281600-9-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240126231348.281600-1-thepacketgeek@gmail.com> References: <20240126231348.281600-1-thepacketgeek@gmail.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Regardless of whether the original message body or formatted userdata exceeds the MAX_PRINT_CHUNK, append userdata to the netconsole message starting with the first chunk that has available space after writing the body. Co-developed-by: Breno Leitao Signed-off-by: Breno Leitao Signed-off-by: Matthew Wood --- drivers/net/netconsole.c | 50 +++++++++++++++++++++++++++++----------- 1 file changed, 37 insertions(+), 13 deletions(-) diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c index de668a0794b1..b33ceb110434 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1086,24 +1086,48 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg, memcpy(buf + release_len, header, header_len); header_len += release_len; - while (offset < body_len) { + while (offset < body_len + userdata_len) { int this_header = header_len; - int this_chunk; + int this_offset = 0; + int this_chunk = 0; this_header += scnprintf(buf + this_header, sizeof(buf) - this_header, - ",ncfrag=%d/%d;", offset, body_len); - - this_chunk = min(body_len - offset, - MAX_PRINT_CHUNK - this_header); - if (WARN_ON_ONCE(this_chunk <= 0)) - return; - - memcpy(buf + this_header, body + offset, this_chunk); - - netpoll_send_udp(&nt->np, buf, this_header + this_chunk); + ",ncfrag=%d/%d;", offset, + body_len + userdata_len); + + /* Not all body data has been written yet */ + if (offset < body_len) { + this_chunk = min(body_len - offset, + MAX_PRINT_CHUNK - this_header); + if (WARN_ON_ONCE(this_chunk <= 0)) + return; + memcpy(buf + this_header, body + offset, this_chunk); + this_offset += this_chunk; + } + /* Body is fully written and there is pending userdata to write, + * append userdata in this chunk + */ + if (offset + this_offset >= body_len && + offset + this_offset < userdata_len + body_len) { + int sent_userdata = (offset + this_offset) - body_len; + int preceding_bytes = this_chunk + this_header; + + if (WARN_ON_ONCE(sent_userdata < 0)) + return; + + this_chunk = min(userdata_len - sent_userdata, + MAX_PRINT_CHUNK - preceding_bytes); + if (WARN_ON_ONCE(this_chunk <= 0)) + return; + memcpy(buf + this_header + this_offset, + userdata + sent_userdata, + this_chunk); + this_offset += this_chunk; + } - offset += this_chunk; + netpoll_send_udp(&nt->np, buf, this_header + this_offset); + offset += this_offset; } } -- 2.43.0