Received: by 2002:a05:7412:5112:b0:fa:6e18:a558 with SMTP id fm18csp1274364rdb; Wed, 24 Jan 2024 09:51:37 -0800 (PST) X-Google-Smtp-Source: AGHT+IENTNZMoKFnFkWpQTwknFRqV4TYFiWjHjN8JKrL0r3uoDLkHWQ/KrzrNXCy+SF2g+MpvXqh X-Received: by 2002:a17:90a:ce95:b0:28e:82b9:5df with SMTP id g21-20020a17090ace9500b0028e82b905dfmr3970052pju.49.1706118696550; Wed, 24 Jan 2024 09:51:36 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1706118696; cv=pass; d=google.com; s=arc-20160816; b=X6cdRi0rSzHxm/Q+AJajH9hLXRpgbV3lzFDUiCfiwpq8edM36go8ZnYT4fa4H3K1AA vqWUB15eaLPFVTDHeVF0S+VZrW5WizXcvzT+/S3qGQysm3EI2rOP7Yx0es1EiA/J1X1v yHq9xq/SOIAISgScKRoHITJ6ovPkiP6fEGIC1T1gbBcWKSSGy8j1cHMFluE9ZTlTJzD6 KtPOvtFk2l3bne+cGK3CI1bsO+rHsAj2ek5i8p2h8zx4hvoD833bC+xkNOFtqjfVkxzu wLNKdN4Zwdwa0y7J75XE3O1rLlFzg4Qr5G40z1KU3CHKJSK+vXrdYd2jX3keQlYJ44xR z+DQ== 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=Vzf+RsvLyT/r4LQQ0hA+PIZWqxzvX6yBhcSuFj8O/bI=; fh=+EB6oBnXtBrxaPMIm1rb1kOyvjkddCLSgL4/UeSWQvM=; b=WBJmSKOr0r+C/XKDzYyKSGCdr9MskNCDm2o/GVhPvwVLJyDjCkMTMwhWJELd4iD62w mgnBRAnj5L3kbTEBq0BoeOjIXc/SWrfLHxzh0Iv86OK0Y97m2MmbFmVMIS8UxYAsWwhr LL39VzuC//ZSPJmwYT86goPsSMLlY9nnGAIOaaBtKDFCwiRr9DHpKk1vh+09vNnN4dlL Jx5WUyCXRNY6BAro5w5+EdRUyj3avAy+R0VXpfAzbS6CAXF3hN9/fxV2U3OzJq3+uZCu r8Rj+GQWz8rXienUpzsXkJCIhcplRsrWB5yzmmt2KQrV69i/L9DwDzubfXZaaWWUrw9W 4crg== ARC-Authentication-Results: i=2; mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PhiUpWfX; 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-37464-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37464-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=QUARANTINE dis=NONE) header.from=gmail.com Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id k60-20020a17090a4cc200b0028cbf77f0cesi11887799pjh.102.2024.01.24.09.51.36 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:51:36 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-37464-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; dkim=pass header.i=@gmail.com header.s=20230601 header.b=PhiUpWfX; 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-37464-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-37464-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 sv.mirrors.kernel.org (Postfix) with ESMTPS id 36776281BC3 for ; Wed, 24 Jan 2024 17:51:36 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 83E7812CD88; Wed, 24 Jan 2024 17:47:33 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="PhiUpWfX" Received: from mail-pl1-f182.google.com (mail-pl1-f182.google.com [209.85.214.182]) (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 380C412C523; Wed, 24 Jan 2024 17:47:31 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.214.182 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118452; cv=none; b=JuSQwneRS3h0H3IwhMHSL7LdFARrraz3JvqrWpE8OIvtADXHc+m4IMABMptFLjS4ETvTSlC+p9Isra66YQ2LbrgHqR8C3cS6ZSefJaktCJ88vW84e5x2YFny6tiyei2YCiSVLTpwrwM2Owj4+w0fkzdHCsBXMopEBHVu69thWbM= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1706118452; c=relaxed/simple; bh=1guLW5LaVQcL2JOWOYaToB2yKWIxIxlvgTjPbw8dAoQ=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=l/5QJEnW3RcWOcX/9ssbgUTarolyKCz9jr3tTm5tQVe5n7wwakvPCaPsLwe/d8g4M2ZtB0BCbP6LK9eKI5AB3Z6lYQ7LVOgY8caaylT1WLLcrCHCYxgd7zeMGkabAVK20Ikw0X8UjI/+j3EW/o2diz6oAhtRZuJYP2TVd0+a6Vw= 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=PhiUpWfX; arc=none smtp.client-ip=209.85.214.182 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-f182.google.com with SMTP id d9443c01a7336-1d7431e702dso27044695ad.1; Wed, 24 Jan 2024 09:47:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1706118450; x=1706723250; 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=Vzf+RsvLyT/r4LQQ0hA+PIZWqxzvX6yBhcSuFj8O/bI=; b=PhiUpWfXkft2sJMCaID8IER2iup0P4tfa1wGwH9G/gB5NSI//l2HavJjHduKx4qKb2 ARVAlIJnEswJ64KszivPJfIrE8N/hl6ZPGeCpZbDbqHP0LZ2KhwlbfAG07vxYxq35j+k GaJh0f5J6JE1oL7wcyFeWo12FuvGR5yV5avKVlhnh1nuE7OI5cVMhZ6AnQa3NXtajL6k XfS/iiPQUNTRhbgbMUEYpW7Cz3EcXjmHXUjL0NySijSasr61Px6mAuo0+V/Fcq3C6r1j ysM4MqxXiLTS2buKiZcEGqhSwH4tMdGhWeyevn6lgfa08VkrXwXhEwTkilBkRROCiUJO e5ow== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1706118450; x=1706723250; 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=Vzf+RsvLyT/r4LQQ0hA+PIZWqxzvX6yBhcSuFj8O/bI=; b=k+LZb48NmmkyDNFuH05qGLfINODw8VyysAVvJ454d2siK/zftA8oVcgUHA8rwLo5P0 s1+41CIr/ctl8EYrryJdLhC/xBgBzZdnirnLVnr3yG+HfSvE5t/5ZkP9dhRDMOXREB7p 4Zm93ZkPDSfygES01aOSwI3AbrXoHPqsyY1KXAkME/7niS7jujqP6aCgkvzrX3uA9cjc /aPAzCtJZl3ZRZTMCDcHzGw/ZIufL0ZqG24EARC8esaaAL4C4SEpZ6IMLCeYZ9LXEG+w FqmUF8w6eaNBs1/9UqzmV2cVgZSR9YADShzVvuOSYAo/VbAKN00FR2PoQ6hNn8n3BkPp UREg== X-Gm-Message-State: AOJu0YzJ87Zlr8pvpwgevNr0DpBhwNr88/zqbShGfEZAaOvPsI2xXZam gq8W/ajVGNB7tgWZ4MEfKf9JRvTpVoolmtAi0ccl84uOCpghHXKM X-Received: by 2002:a17:902:cec2:b0:1d7:72b9:b114 with SMTP id d2-20020a170902cec200b001d772b9b114mr1268561plg.60.1706118450630; Wed, 24 Jan 2024 09:47:30 -0800 (PST) Received: from localhost ([2601:644:9380:8cd0::7fb4]) by smtp.gmail.com with ESMTPSA id d5-20020a170902b70500b001d74c285b55sm5565938pls.67.2024.01.24.09.47.29 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 24 Jan 2024 09:47:30 -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 v1 8/8] net: netconsole: append userdata to fragmented netconsole messages Date: Wed, 24 Jan 2024 09:47:06 -0800 Message-ID: <20240124174711.1906102-9-thepacketgeek@gmail.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240124174711.1906102-1-thepacketgeek@gmail.com> References: <20240124174711.1906102-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 8df3932ef4fc..95e563e474af 100644 --- a/drivers/net/netconsole.c +++ b/drivers/net/netconsole.c @@ -1083,24 +1083,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