netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Matthew Wood <thepacketgeek@gmail.com>
To: "David S. Miller" <davem@davemloft.net>,
	Eric Dumazet <edumazet@google.com>,
	Jakub Kicinski <kuba@kernel.org>, Paolo Abeni <pabeni@redhat.com>
Cc: leitao@debian.org, netdev@vger.kernel.org, linux-kernel@vger.kernel.org
Subject: [PATCH net-next v2 7/8] net: netconsole: append userdata to netconsole messages
Date: Fri, 26 Jan 2024 15:13:42 -0800	[thread overview]
Message-ID: <20240126231348.281600-8-thepacketgeek@gmail.com> (raw)
In-Reply-To: <20240126231348.281600-1-thepacketgeek@gmail.com>

Append userdata to outgoing unfragmented (<1000 bytes) netconsole messages.
When sending messages the userdata string is already formatted and stored
in netconsole_target->userdata_complete.

Always write the outgoing message to buf, so userdata can be appended in
a standard fashion. This is a change from only using buf when the
release needs to be prepended to the message.

Co-developed-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Breno Leitao <leitao@debian.org>
Signed-off-by: Matthew Wood <thepacketgeek@gmail.com>
---
 drivers/net/netconsole.c | 19 +++++++++++++++++--
 1 file changed, 17 insertions(+), 2 deletions(-)

diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 73feba0b3c93..de668a0794b1 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -1035,19 +1035,34 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
 	const char *msg_ready = msg;
 	const char *release;
 	int release_len = 0;
+	int userdata_len = 0;
+	char *userdata = NULL;
+
+#ifdef CONFIG_NETCONSOLE_DYNAMIC
+	userdata = nt->userdata_complete;
+	userdata_len = nt->userdata_length;
+#endif
 
 	if (nt->release) {
 		release = init_utsname()->release;
 		release_len = strlen(release) + 1;
 	}
 
-	if (msg_len + release_len <= MAX_PRINT_CHUNK) {
+	if (msg_len + release_len + userdata_len <= MAX_PRINT_CHUNK) {
 		/* No fragmentation needed */
 		if (nt->release) {
 			scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg);
 			msg_len += release_len;
-			msg_ready = buf;
+		} else {
+			memcpy(buf, msg, msg_len);
 		}
+
+		if (userdata)
+			msg_len += scnprintf(&buf[msg_len],
+					     MAX_PRINT_CHUNK - msg_len,
+					     "%s", userdata);
+
+		msg_ready = buf;
 		netpoll_send_udp(&nt->np, msg_ready, msg_len);
 		return;
 	}
-- 
2.43.0


  parent reply	other threads:[~2024-01-26 23:14 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2024-01-26 23:13 [PATCH net-next v2 0/8] netconsole: Add userdata append support Matthew Wood
2024-01-26 23:13 ` [PATCH net-next v2 1/8] net: netconsole: cleanup formatting lints Matthew Wood
2024-01-30  9:23   ` Breno Leitao
2024-01-26 23:13 ` [PATCH net-next v2 2/8] net: netconsole: move netconsole_target config_item to config_group Matthew Wood
2024-01-30  9:22   ` Breno Leitao
2024-02-02 11:54   ` Simon Horman
2024-01-26 23:13 ` [PATCH net-next v2 3/8] net: netconsole: move newline trimming to function Matthew Wood
2024-01-30  9:16   ` Breno Leitao
2024-02-01  4:45     ` Packet Geek
2024-02-01  5:31       ` Matthew Wood
2024-01-26 23:13 ` [PATCH net-next v2 4/8] net: netconsole: add docs for appending netconsole user data Matthew Wood
2024-01-26 23:13 ` [PATCH net-next v2 5/8] net: netconsole: add a userdata config_group member to netconsole_target Matthew Wood
2024-02-02 11:51   ` Simon Horman
2024-02-02 16:05     ` Matthew Wood
2024-02-06 13:51       ` Simon Horman
2024-01-26 23:13 ` [PATCH net-next v2 6/8] net: netconsole: cache userdata formatted string in netconsole_target Matthew Wood
2024-01-27 13:15   ` kernel test robot
2024-02-02 11:53   ` Simon Horman
2024-01-26 23:13 ` Matthew Wood [this message]
2024-01-26 23:13 ` [PATCH net-next v2 8/8] net: netconsole: append userdata to fragmented netconsole messages Matthew Wood

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20240126231348.281600-8-thepacketgeek@gmail.com \
    --to=thepacketgeek@gmail.com \
    --cc=davem@davemloft.net \
    --cc=edumazet@google.com \
    --cc=kuba@kernel.org \
    --cc=leitao@debian.org \
    --cc=linux-kernel@vger.kernel.org \
    --cc=netdev@vger.kernel.org \
    --cc=pabeni@redhat.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).