162306a36Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
262306a36Sopenharmony_ci
362306a36Sopenharmony_ci==========
462306a36Sopenharmony_ciNetconsole
562306a36Sopenharmony_ci==========
662306a36Sopenharmony_ci
762306a36Sopenharmony_ci
862306a36Sopenharmony_cistarted by Ingo Molnar <mingo@redhat.com>, 2001.09.17
962306a36Sopenharmony_ci
1062306a36Sopenharmony_ci2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
1162306a36Sopenharmony_ci
1262306a36Sopenharmony_ciIPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013
1362306a36Sopenharmony_ci
1462306a36Sopenharmony_ciExtended console support by Tejun Heo <tj@kernel.org>, May 1 2015
1562306a36Sopenharmony_ci
1662306a36Sopenharmony_ciRelease prepend support by Breno Leitao <leitao@debian.org>, Jul 7 2023
1762306a36Sopenharmony_ci
1862306a36Sopenharmony_ciPlease send bug reports to Matt Mackall <mpm@selenic.com>
1962306a36Sopenharmony_ciSatyam Sharma <satyam.sharma@gmail.com>, and Cong Wang <xiyou.wangcong@gmail.com>
2062306a36Sopenharmony_ci
2162306a36Sopenharmony_ciIntroduction:
2262306a36Sopenharmony_ci=============
2362306a36Sopenharmony_ci
2462306a36Sopenharmony_ciThis module logs kernel printk messages over UDP allowing debugging of
2562306a36Sopenharmony_ciproblem where disk logging fails and serial consoles are impractical.
2662306a36Sopenharmony_ci
2762306a36Sopenharmony_ciIt can be used either built-in or as a module. As a built-in,
2862306a36Sopenharmony_cinetconsole initializes immediately after NIC cards and will bring up
2962306a36Sopenharmony_cithe specified interface as soon as possible. While this doesn't allow
3062306a36Sopenharmony_cicapture of early kernel panics, it does capture most of the boot
3162306a36Sopenharmony_ciprocess.
3262306a36Sopenharmony_ci
3362306a36Sopenharmony_ciSender and receiver configuration:
3462306a36Sopenharmony_ci==================================
3562306a36Sopenharmony_ci
3662306a36Sopenharmony_ciIt takes a string configuration parameter "netconsole" in the
3762306a36Sopenharmony_cifollowing format::
3862306a36Sopenharmony_ci
3962306a36Sopenharmony_ci netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
4062306a36Sopenharmony_ci
4162306a36Sopenharmony_ci   where
4262306a36Sopenharmony_ci	+             if present, enable extended console support
4362306a36Sopenharmony_ci	r             if present, prepend kernel version (release) to the message
4462306a36Sopenharmony_ci	src-port      source for UDP packets (defaults to 6665)
4562306a36Sopenharmony_ci	src-ip        source IP to use (interface address)
4662306a36Sopenharmony_ci	dev           network interface (eth0)
4762306a36Sopenharmony_ci	tgt-port      port for logging agent (6666)
4862306a36Sopenharmony_ci	tgt-ip        IP address for logging agent
4962306a36Sopenharmony_ci	tgt-macaddr   ethernet MAC address for logging agent (broadcast)
5062306a36Sopenharmony_ci
5162306a36Sopenharmony_ciExamples::
5262306a36Sopenharmony_ci
5362306a36Sopenharmony_ci linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
5462306a36Sopenharmony_ci
5562306a36Sopenharmony_cior::
5662306a36Sopenharmony_ci
5762306a36Sopenharmony_ci insmod netconsole netconsole=@/,@10.0.0.2/
5862306a36Sopenharmony_ci
5962306a36Sopenharmony_cior using IPv6::
6062306a36Sopenharmony_ci
6162306a36Sopenharmony_ci insmod netconsole netconsole=@/,@fd00:1:2:3::1/
6262306a36Sopenharmony_ci
6362306a36Sopenharmony_ciIt also supports logging to multiple remote agents by specifying
6462306a36Sopenharmony_ciparameters for the multiple agents separated by semicolons and the
6562306a36Sopenharmony_cicomplete string enclosed in "quotes", thusly::
6662306a36Sopenharmony_ci
6762306a36Sopenharmony_ci modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"
6862306a36Sopenharmony_ci
6962306a36Sopenharmony_ciBuilt-in netconsole starts immediately after the TCP stack is
7062306a36Sopenharmony_ciinitialized and attempts to bring up the supplied dev at the supplied
7162306a36Sopenharmony_ciaddress.
7262306a36Sopenharmony_ci
7362306a36Sopenharmony_ciThe remote host has several options to receive the kernel messages,
7462306a36Sopenharmony_cifor example:
7562306a36Sopenharmony_ci
7662306a36Sopenharmony_ci1) syslogd
7762306a36Sopenharmony_ci
7862306a36Sopenharmony_ci2) netcat
7962306a36Sopenharmony_ci
8062306a36Sopenharmony_ci   On distributions using a BSD-based netcat version (e.g. Fedora,
8162306a36Sopenharmony_ci   openSUSE and Ubuntu) the listening port must be specified without
8262306a36Sopenharmony_ci   the -p switch::
8362306a36Sopenharmony_ci
8462306a36Sopenharmony_ci	nc -u -l -p <port>' / 'nc -u -l <port>
8562306a36Sopenharmony_ci
8662306a36Sopenharmony_ci    or::
8762306a36Sopenharmony_ci
8862306a36Sopenharmony_ci	netcat -u -l -p <port>' / 'netcat -u -l <port>
8962306a36Sopenharmony_ci
9062306a36Sopenharmony_ci3) socat
9162306a36Sopenharmony_ci
9262306a36Sopenharmony_ci::
9362306a36Sopenharmony_ci
9462306a36Sopenharmony_ci   socat udp-recv:<port> -
9562306a36Sopenharmony_ci
9662306a36Sopenharmony_ciDynamic reconfiguration:
9762306a36Sopenharmony_ci========================
9862306a36Sopenharmony_ci
9962306a36Sopenharmony_ciDynamic reconfigurability is a useful addition to netconsole that enables
10062306a36Sopenharmony_ciremote logging targets to be dynamically added, removed, or have their
10162306a36Sopenharmony_ciparameters reconfigured at runtime from a configfs-based userspace interface.
10262306a36Sopenharmony_ci[ Note that the parameters of netconsole targets that were specified/created
10362306a36Sopenharmony_cifrom the boot/module option are not exposed via this interface, and hence
10462306a36Sopenharmony_cicannot be modified dynamically. ]
10562306a36Sopenharmony_ci
10662306a36Sopenharmony_ciTo include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
10762306a36Sopenharmony_cinetconsole module (or kernel, if netconsole is built-in).
10862306a36Sopenharmony_ci
10962306a36Sopenharmony_ciSome examples follow (where configfs is mounted at the /sys/kernel/config
11062306a36Sopenharmony_cimountpoint).
11162306a36Sopenharmony_ci
11262306a36Sopenharmony_ciTo add a remote logging target (target names can be arbitrary)::
11362306a36Sopenharmony_ci
11462306a36Sopenharmony_ci cd /sys/kernel/config/netconsole/
11562306a36Sopenharmony_ci mkdir target1
11662306a36Sopenharmony_ci
11762306a36Sopenharmony_ciNote that newly created targets have default parameter values (as mentioned
11862306a36Sopenharmony_ciabove) and are disabled by default -- they must first be enabled by writing
11962306a36Sopenharmony_ci"1" to the "enabled" attribute (usually after setting parameters accordingly)
12062306a36Sopenharmony_cias described below.
12162306a36Sopenharmony_ci
12262306a36Sopenharmony_ciTo remove a target::
12362306a36Sopenharmony_ci
12462306a36Sopenharmony_ci rmdir /sys/kernel/config/netconsole/othertarget/
12562306a36Sopenharmony_ci
12662306a36Sopenharmony_ciThe interface exposes these parameters of a netconsole target to userspace:
12762306a36Sopenharmony_ci
12862306a36Sopenharmony_ci	==============  =================================       ============
12962306a36Sopenharmony_ci	enabled		Is this target currently enabled?	(read-write)
13062306a36Sopenharmony_ci	extended	Extended mode enabled			(read-write)
13162306a36Sopenharmony_ci	release		Prepend kernel release to message	(read-write)
13262306a36Sopenharmony_ci	dev_name	Local network interface name		(read-write)
13362306a36Sopenharmony_ci	local_port	Source UDP port to use			(read-write)
13462306a36Sopenharmony_ci	remote_port	Remote agent's UDP port			(read-write)
13562306a36Sopenharmony_ci	local_ip	Source IP address to use		(read-write)
13662306a36Sopenharmony_ci	remote_ip	Remote agent's IP address		(read-write)
13762306a36Sopenharmony_ci	local_mac	Local interface's MAC address		(read-only)
13862306a36Sopenharmony_ci	remote_mac	Remote agent's MAC address		(read-write)
13962306a36Sopenharmony_ci	==============  =================================       ============
14062306a36Sopenharmony_ci
14162306a36Sopenharmony_ciThe "enabled" attribute is also used to control whether the parameters of
14262306a36Sopenharmony_cia target can be updated or not -- you can modify the parameters of only
14362306a36Sopenharmony_cidisabled targets (i.e. if "enabled" is 0).
14462306a36Sopenharmony_ci
14562306a36Sopenharmony_ciTo update a target's parameters::
14662306a36Sopenharmony_ci
14762306a36Sopenharmony_ci cat enabled				# check if enabled is 1
14862306a36Sopenharmony_ci echo 0 > enabled			# disable the target (if required)
14962306a36Sopenharmony_ci echo eth2 > dev_name			# set local interface
15062306a36Sopenharmony_ci echo 10.0.0.4 > remote_ip		# update some parameter
15162306a36Sopenharmony_ci echo cb:a9:87:65:43:21 > remote_mac	# update more parameters
15262306a36Sopenharmony_ci echo 1 > enabled			# enable target again
15362306a36Sopenharmony_ci
15462306a36Sopenharmony_ciYou can also update the local interface dynamically. This is especially
15562306a36Sopenharmony_ciuseful if you want to use interfaces that have newly come up (and may not
15662306a36Sopenharmony_cihave existed when netconsole was loaded / initialized).
15762306a36Sopenharmony_ci
15862306a36Sopenharmony_ciExtended console:
15962306a36Sopenharmony_ci=================
16062306a36Sopenharmony_ci
16162306a36Sopenharmony_ciIf '+' is prefixed to the configuration line or "extended" config file
16262306a36Sopenharmony_ciis set to 1, extended console support is enabled. An example boot
16362306a36Sopenharmony_ciparam follows::
16462306a36Sopenharmony_ci
16562306a36Sopenharmony_ci linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
16662306a36Sopenharmony_ci
16762306a36Sopenharmony_ciLog messages are transmitted with extended metadata header in the
16862306a36Sopenharmony_cifollowing format which is the same as /dev/kmsg::
16962306a36Sopenharmony_ci
17062306a36Sopenharmony_ci <level>,<sequnum>,<timestamp>,<contflag>;<message text>
17162306a36Sopenharmony_ci
17262306a36Sopenharmony_ciIf 'r' (release) feature is enabled, the kernel release version is
17362306a36Sopenharmony_ciprepended to the start of the message. Example::
17462306a36Sopenharmony_ci
17562306a36Sopenharmony_ci 6.4.0,6,444,501151268,-;netconsole: network logging started
17662306a36Sopenharmony_ci
17762306a36Sopenharmony_ciNon printable characters in <message text> are escaped using "\xff"
17862306a36Sopenharmony_cinotation. If the message contains optional dictionary, verbatim
17962306a36Sopenharmony_cinewline is used as the delimiter.
18062306a36Sopenharmony_ci
18162306a36Sopenharmony_ciIf a message doesn't fit in certain number of bytes (currently 1000),
18262306a36Sopenharmony_cithe message is split into multiple fragments by netconsole. These
18362306a36Sopenharmony_cifragments are transmitted with "ncfrag" header field added::
18462306a36Sopenharmony_ci
18562306a36Sopenharmony_ci ncfrag=<byte-offset>/<total-bytes>
18662306a36Sopenharmony_ci
18762306a36Sopenharmony_ciFor example, assuming a lot smaller chunk size, a message "the first
18862306a36Sopenharmony_cichunk, the 2nd chunk." may be split as follows::
18962306a36Sopenharmony_ci
19062306a36Sopenharmony_ci 6,416,1758426,-,ncfrag=0/31;the first chunk,
19162306a36Sopenharmony_ci 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.
19262306a36Sopenharmony_ci
19362306a36Sopenharmony_ciMiscellaneous notes:
19462306a36Sopenharmony_ci====================
19562306a36Sopenharmony_ci
19662306a36Sopenharmony_ci.. Warning::
19762306a36Sopenharmony_ci
19862306a36Sopenharmony_ci   the default target ethernet setting uses the broadcast
19962306a36Sopenharmony_ci   ethernet address to send packets, which can cause increased load on
20062306a36Sopenharmony_ci   other systems on the same ethernet segment.
20162306a36Sopenharmony_ci
20262306a36Sopenharmony_ci.. Tip::
20362306a36Sopenharmony_ci
20462306a36Sopenharmony_ci   some LAN switches may be configured to suppress ethernet broadcasts
20562306a36Sopenharmony_ci   so it is advised to explicitly specify the remote agents' MAC addresses
20662306a36Sopenharmony_ci   from the config parameters passed to netconsole.
20762306a36Sopenharmony_ci
20862306a36Sopenharmony_ci.. Tip::
20962306a36Sopenharmony_ci
21062306a36Sopenharmony_ci   to find out the MAC address of, say, 10.0.0.2, you may try using::
21162306a36Sopenharmony_ci
21262306a36Sopenharmony_ci	ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2
21362306a36Sopenharmony_ci
21462306a36Sopenharmony_ci.. Tip::
21562306a36Sopenharmony_ci
21662306a36Sopenharmony_ci   in case the remote logging agent is on a separate LAN subnet than
21762306a36Sopenharmony_ci   the sender, it is suggested to try specifying the MAC address of the
21862306a36Sopenharmony_ci   default gateway (you may use /sbin/route -n to find it out) as the
21962306a36Sopenharmony_ci   remote MAC address instead.
22062306a36Sopenharmony_ci
22162306a36Sopenharmony_ci.. note::
22262306a36Sopenharmony_ci
22362306a36Sopenharmony_ci   the network device (eth1 in the above case) can run any kind
22462306a36Sopenharmony_ci   of other network traffic, netconsole is not intrusive. Netconsole
22562306a36Sopenharmony_ci   might cause slight delays in other traffic if the volume of kernel
22662306a36Sopenharmony_ci   messages is high, but should have no other impact.
22762306a36Sopenharmony_ci
22862306a36Sopenharmony_ci.. note::
22962306a36Sopenharmony_ci
23062306a36Sopenharmony_ci   if you find that the remote logging agent is not receiving or
23162306a36Sopenharmony_ci   printing all messages from the sender, it is likely that you have set
23262306a36Sopenharmony_ci   the "console_loglevel" parameter (on the sender) to only send high
23362306a36Sopenharmony_ci   priority messages to the console. You can change this at runtime using::
23462306a36Sopenharmony_ci
23562306a36Sopenharmony_ci	dmesg -n 8
23662306a36Sopenharmony_ci
23762306a36Sopenharmony_ci   or by specifying "debug" on the kernel command line at boot, to send
23862306a36Sopenharmony_ci   all kernel messages to the console. A specific value for this parameter
23962306a36Sopenharmony_ci   can also be set using the "loglevel" kernel boot option. See the
24062306a36Sopenharmony_ci   dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
24162306a36Sopenharmony_ci   for details.
24262306a36Sopenharmony_ci
24362306a36Sopenharmony_ciNetconsole was designed to be as instantaneous as possible, to
24462306a36Sopenharmony_cienable the logging of even the most critical kernel bugs. It works
24562306a36Sopenharmony_cifrom IRQ contexts as well, and does not enable interrupts while
24662306a36Sopenharmony_cisending packets. Due to these unique needs, configuration cannot
24762306a36Sopenharmony_cibe more automatic, and some fundamental limitations will remain:
24862306a36Sopenharmony_cionly IP networks, UDP packets and ethernet devices are supported.
249