netdev.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] netconsole: Append kernel version to message
@ 2023-07-03 15:41 leitao
  2023-07-03 16:46 ` Andrew Lunn
                   ` (2 more replies)
  0 siblings, 3 replies; 12+ messages in thread
From: leitao @ 2023-07-03 15:41 UTC (permalink / raw)
  To: David S. Miller, Eric Dumazet, Jakub Kicinski, Paolo Abeni
  Cc: sergey.senozhatsky, pmladek, tj, Breno Leitao, Dave Jones,
	open list:NETWORKING DRIVERS, open list

From: Breno Leitao <leitao@debian.org>

Create a new netconsole Kconfig option that prepends the kernel version in
the netconsole message. This is useful to map kernel messages to kernel
version in a simple way, i.e., without checking somewhere which kernel
version the host that sent the message is using.

If this option is selected, then the "<uname>;" is prepended before the
netconsole message. This is an example of a netcons output, with this
feature enabled:

	6.4.0-01762-ga1ba2ffe946e;12,426,112883998,-;this is a test

Calvin Owens send a RFC about this problem in 2016[1], but his
approach was a bit more intrusive, changing the printk subsystem. This
approach is lighter, and just append the information in the last mile,
just before netconsole push the message to netpoll.

[1] Link: https://lore.kernel.org/all/51047c0f6e86abcb9ee13f60653b6946f8fcfc99.1463172791.git.calvinowens@fb.com/

Signed-off-by: Breno Leitao <leitao@debian.org>
Cc: Dave Jones <davej@codemonkey.org.uk>
---
 drivers/net/Kconfig      | 10 ++++++++++
 drivers/net/netconsole.c | 35 ++++++++++++++++++++++++++++++++++-
 2 files changed, 44 insertions(+), 1 deletion(-)

diff --git a/drivers/net/Kconfig b/drivers/net/Kconfig
index d0a1ed216d15..df50fdb6c794 100644
--- a/drivers/net/Kconfig
+++ b/drivers/net/Kconfig
@@ -332,6 +332,16 @@ config NETCONSOLE_DYNAMIC
 	  at runtime through a userspace interface exported using configfs.
 	  See <file:Documentation/networking/netconsole.rst> for details.
 
+config NETCONSOLE_UNAME
+	bool "Add the kernel version to netconsole lines"
+	depends on NETCONSOLE
+	default n
+	help
+	  This option causes extended netcons messages to be prepended with
+	  kernel uname version. This can be useful for monitoring a large
+	  deployment of servers, so, you can easily map outputs to kernel
+	  versions.
+
 config NETPOLL
 	def_bool NETCONSOLE
 
diff --git a/drivers/net/netconsole.c b/drivers/net/netconsole.c
index 4f4f79532c6c..7edc5b033e14 100644
--- a/drivers/net/netconsole.c
+++ b/drivers/net/netconsole.c
@@ -36,6 +36,7 @@
 #include <linux/inet.h>
 #include <linux/configfs.h>
 #include <linux/etherdevice.h>
+#include <linux/utsname.h>
 
 MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
 MODULE_DESCRIPTION("Console driver for network interfaces");
@@ -815,6 +816,38 @@ static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
 	}
 }
 
+#ifdef CONFIG_NETCONSOLE_UNAME
+static void send_ext_msg_udp_uname(struct netconsole_target *nt,
+				   const char *msg, unsigned int len)
+{
+	unsigned int newlen;
+	char *newmsg;
+	char *uname;
+
+	uname = init_utsname()->release;
+
+	newmsg = kasprintf(GFP_KERNEL, "%s;%s", uname, msg);
+	if (!newmsg)
+		/* In case of ENOMEM, just ignore this entry */
+		return;
+	newlen = strlen(uname) + len + 1;
+
+	send_ext_msg_udp(nt, newmsg, newlen);
+
+	kfree(newmsg);
+}
+#endif
+
+static inline void send_msg_udp(struct netconsole_target *nt,
+				const char *msg, unsigned int len)
+{
+#ifdef CONFIG_NETCONSOLE_UNAME
+	send_ext_msg_udp_uname(nt, msg, len);
+#else
+	send_ext_msg_udp(nt, msg, len);
+#endif
+}
+
 static void write_ext_msg(struct console *con, const char *msg,
 			  unsigned int len)
 {
@@ -827,7 +860,7 @@ static void write_ext_msg(struct console *con, const char *msg,
 	spin_lock_irqsave(&target_list_lock, flags);
 	list_for_each_entry(nt, &target_list, list)
 		if (nt->extended && nt->enabled && netif_running(nt->np.dev))
-			send_ext_msg_udp(nt, msg, len);
+			send_msg_udp(nt, msg, len);
 	spin_unlock_irqrestore(&target_list_lock, flags);
 }
 
-- 
2.34.1


^ permalink raw reply related	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-07-05 15:56 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-07-03 15:41 [PATCH] netconsole: Append kernel version to message leitao
2023-07-03 16:46 ` Andrew Lunn
2023-07-04 15:53   ` Breno Leitao
2023-07-03 18:34 ` Stephen Hemminger
2023-07-04 15:15   ` Breno Leitao
2023-07-04 15:58     ` Stephen Hemminger
2023-07-05  9:18       ` Breno Leitao
2023-07-05 15:26         ` Stephen Hemminger
2023-07-05 15:49           ` Jakub Kicinski
2023-07-03 19:44 ` Jakub Kicinski
2023-07-04 15:47   ` Breno Leitao
2023-07-05 15:56     ` Jakub Kicinski

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).