18c2ecf20Sopenharmony_ci.. SPDX-License-Identifier: GPL-2.0
28c2ecf20Sopenharmony_ci
38c2ecf20Sopenharmony_ci==========
48c2ecf20Sopenharmony_ciNetconsole
58c2ecf20Sopenharmony_ci==========
68c2ecf20Sopenharmony_ci
78c2ecf20Sopenharmony_ci
88c2ecf20Sopenharmony_cistarted by Ingo Molnar <mingo@redhat.com>, 2001.09.17
98c2ecf20Sopenharmony_ci
108c2ecf20Sopenharmony_ci2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
118c2ecf20Sopenharmony_ci
128c2ecf20Sopenharmony_ciIPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013
138c2ecf20Sopenharmony_ci
148c2ecf20Sopenharmony_ciExtended console support by Tejun Heo <tj@kernel.org>, May 1 2015
158c2ecf20Sopenharmony_ci
168c2ecf20Sopenharmony_ciPlease send bug reports to Matt Mackall <mpm@selenic.com>
178c2ecf20Sopenharmony_ciSatyam Sharma <satyam.sharma@gmail.com>, and Cong Wang <xiyou.wangcong@gmail.com>
188c2ecf20Sopenharmony_ci
198c2ecf20Sopenharmony_ciIntroduction:
208c2ecf20Sopenharmony_ci=============
218c2ecf20Sopenharmony_ci
228c2ecf20Sopenharmony_ciThis module logs kernel printk messages over UDP allowing debugging of
238c2ecf20Sopenharmony_ciproblem where disk logging fails and serial consoles are impractical.
248c2ecf20Sopenharmony_ci
258c2ecf20Sopenharmony_ciIt can be used either built-in or as a module. As a built-in,
268c2ecf20Sopenharmony_cinetconsole initializes immediately after NIC cards and will bring up
278c2ecf20Sopenharmony_cithe specified interface as soon as possible. While this doesn't allow
288c2ecf20Sopenharmony_cicapture of early kernel panics, it does capture most of the boot
298c2ecf20Sopenharmony_ciprocess.
308c2ecf20Sopenharmony_ci
318c2ecf20Sopenharmony_ciSender and receiver configuration:
328c2ecf20Sopenharmony_ci==================================
338c2ecf20Sopenharmony_ci
348c2ecf20Sopenharmony_ciIt takes a string configuration parameter "netconsole" in the
358c2ecf20Sopenharmony_cifollowing format::
368c2ecf20Sopenharmony_ci
378c2ecf20Sopenharmony_ci netconsole=[+][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
388c2ecf20Sopenharmony_ci
398c2ecf20Sopenharmony_ci   where
408c2ecf20Sopenharmony_ci	+             if present, enable extended console support
418c2ecf20Sopenharmony_ci	src-port      source for UDP packets (defaults to 6665)
428c2ecf20Sopenharmony_ci	src-ip        source IP to use (interface address)
438c2ecf20Sopenharmony_ci	dev           network interface (eth0)
448c2ecf20Sopenharmony_ci	tgt-port      port for logging agent (6666)
458c2ecf20Sopenharmony_ci	tgt-ip        IP address for logging agent
468c2ecf20Sopenharmony_ci	tgt-macaddr   ethernet MAC address for logging agent (broadcast)
478c2ecf20Sopenharmony_ci
488c2ecf20Sopenharmony_ciExamples::
498c2ecf20Sopenharmony_ci
508c2ecf20Sopenharmony_ci linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
518c2ecf20Sopenharmony_ci
528c2ecf20Sopenharmony_cior::
538c2ecf20Sopenharmony_ci
548c2ecf20Sopenharmony_ci insmod netconsole netconsole=@/,@10.0.0.2/
558c2ecf20Sopenharmony_ci
568c2ecf20Sopenharmony_cior using IPv6::
578c2ecf20Sopenharmony_ci
588c2ecf20Sopenharmony_ci insmod netconsole netconsole=@/,@fd00:1:2:3::1/
598c2ecf20Sopenharmony_ci
608c2ecf20Sopenharmony_ciIt also supports logging to multiple remote agents by specifying
618c2ecf20Sopenharmony_ciparameters for the multiple agents separated by semicolons and the
628c2ecf20Sopenharmony_cicomplete string enclosed in "quotes", thusly::
638c2ecf20Sopenharmony_ci
648c2ecf20Sopenharmony_ci modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"
658c2ecf20Sopenharmony_ci
668c2ecf20Sopenharmony_ciBuilt-in netconsole starts immediately after the TCP stack is
678c2ecf20Sopenharmony_ciinitialized and attempts to bring up the supplied dev at the supplied
688c2ecf20Sopenharmony_ciaddress.
698c2ecf20Sopenharmony_ci
708c2ecf20Sopenharmony_ciThe remote host has several options to receive the kernel messages,
718c2ecf20Sopenharmony_cifor example:
728c2ecf20Sopenharmony_ci
738c2ecf20Sopenharmony_ci1) syslogd
748c2ecf20Sopenharmony_ci
758c2ecf20Sopenharmony_ci2) netcat
768c2ecf20Sopenharmony_ci
778c2ecf20Sopenharmony_ci   On distributions using a BSD-based netcat version (e.g. Fedora,
788c2ecf20Sopenharmony_ci   openSUSE and Ubuntu) the listening port must be specified without
798c2ecf20Sopenharmony_ci   the -p switch::
808c2ecf20Sopenharmony_ci
818c2ecf20Sopenharmony_ci	nc -u -l -p <port>' / 'nc -u -l <port>
828c2ecf20Sopenharmony_ci
838c2ecf20Sopenharmony_ci    or::
848c2ecf20Sopenharmony_ci
858c2ecf20Sopenharmony_ci	netcat -u -l -p <port>' / 'netcat -u -l <port>
868c2ecf20Sopenharmony_ci
878c2ecf20Sopenharmony_ci3) socat
888c2ecf20Sopenharmony_ci
898c2ecf20Sopenharmony_ci::
908c2ecf20Sopenharmony_ci
918c2ecf20Sopenharmony_ci   socat udp-recv:<port> -
928c2ecf20Sopenharmony_ci
938c2ecf20Sopenharmony_ciDynamic reconfiguration:
948c2ecf20Sopenharmony_ci========================
958c2ecf20Sopenharmony_ci
968c2ecf20Sopenharmony_ciDynamic reconfigurability is a useful addition to netconsole that enables
978c2ecf20Sopenharmony_ciremote logging targets to be dynamically added, removed, or have their
988c2ecf20Sopenharmony_ciparameters reconfigured at runtime from a configfs-based userspace interface.
998c2ecf20Sopenharmony_ci[ Note that the parameters of netconsole targets that were specified/created
1008c2ecf20Sopenharmony_cifrom the boot/module option are not exposed via this interface, and hence
1018c2ecf20Sopenharmony_cicannot be modified dynamically. ]
1028c2ecf20Sopenharmony_ci
1038c2ecf20Sopenharmony_ciTo include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
1048c2ecf20Sopenharmony_cinetconsole module (or kernel, if netconsole is built-in).
1058c2ecf20Sopenharmony_ci
1068c2ecf20Sopenharmony_ciSome examples follow (where configfs is mounted at the /sys/kernel/config
1078c2ecf20Sopenharmony_cimountpoint).
1088c2ecf20Sopenharmony_ci
1098c2ecf20Sopenharmony_ciTo add a remote logging target (target names can be arbitrary)::
1108c2ecf20Sopenharmony_ci
1118c2ecf20Sopenharmony_ci cd /sys/kernel/config/netconsole/
1128c2ecf20Sopenharmony_ci mkdir target1
1138c2ecf20Sopenharmony_ci
1148c2ecf20Sopenharmony_ciNote that newly created targets have default parameter values (as mentioned
1158c2ecf20Sopenharmony_ciabove) and are disabled by default -- they must first be enabled by writing
1168c2ecf20Sopenharmony_ci"1" to the "enabled" attribute (usually after setting parameters accordingly)
1178c2ecf20Sopenharmony_cias described below.
1188c2ecf20Sopenharmony_ci
1198c2ecf20Sopenharmony_ciTo remove a target::
1208c2ecf20Sopenharmony_ci
1218c2ecf20Sopenharmony_ci rmdir /sys/kernel/config/netconsole/othertarget/
1228c2ecf20Sopenharmony_ci
1238c2ecf20Sopenharmony_ciThe interface exposes these parameters of a netconsole target to userspace:
1248c2ecf20Sopenharmony_ci
1258c2ecf20Sopenharmony_ci	==============  =================================       ============
1268c2ecf20Sopenharmony_ci	enabled		Is this target currently enabled?	(read-write)
1278c2ecf20Sopenharmony_ci	extended	Extended mode enabled			(read-write)
1288c2ecf20Sopenharmony_ci	dev_name	Local network interface name		(read-write)
1298c2ecf20Sopenharmony_ci	local_port	Source UDP port to use			(read-write)
1308c2ecf20Sopenharmony_ci	remote_port	Remote agent's UDP port			(read-write)
1318c2ecf20Sopenharmony_ci	local_ip	Source IP address to use		(read-write)
1328c2ecf20Sopenharmony_ci	remote_ip	Remote agent's IP address		(read-write)
1338c2ecf20Sopenharmony_ci	local_mac	Local interface's MAC address		(read-only)
1348c2ecf20Sopenharmony_ci	remote_mac	Remote agent's MAC address		(read-write)
1358c2ecf20Sopenharmony_ci	==============  =================================       ============
1368c2ecf20Sopenharmony_ci
1378c2ecf20Sopenharmony_ciThe "enabled" attribute is also used to control whether the parameters of
1388c2ecf20Sopenharmony_cia target can be updated or not -- you can modify the parameters of only
1398c2ecf20Sopenharmony_cidisabled targets (i.e. if "enabled" is 0).
1408c2ecf20Sopenharmony_ci
1418c2ecf20Sopenharmony_ciTo update a target's parameters::
1428c2ecf20Sopenharmony_ci
1438c2ecf20Sopenharmony_ci cat enabled				# check if enabled is 1
1448c2ecf20Sopenharmony_ci echo 0 > enabled			# disable the target (if required)
1458c2ecf20Sopenharmony_ci echo eth2 > dev_name			# set local interface
1468c2ecf20Sopenharmony_ci echo 10.0.0.4 > remote_ip		# update some parameter
1478c2ecf20Sopenharmony_ci echo cb:a9:87:65:43:21 > remote_mac	# update more parameters
1488c2ecf20Sopenharmony_ci echo 1 > enabled			# enable target again
1498c2ecf20Sopenharmony_ci
1508c2ecf20Sopenharmony_ciYou can also update the local interface dynamically. This is especially
1518c2ecf20Sopenharmony_ciuseful if you want to use interfaces that have newly come up (and may not
1528c2ecf20Sopenharmony_cihave existed when netconsole was loaded / initialized).
1538c2ecf20Sopenharmony_ci
1548c2ecf20Sopenharmony_ciExtended console:
1558c2ecf20Sopenharmony_ci=================
1568c2ecf20Sopenharmony_ci
1578c2ecf20Sopenharmony_ciIf '+' is prefixed to the configuration line or "extended" config file
1588c2ecf20Sopenharmony_ciis set to 1, extended console support is enabled. An example boot
1598c2ecf20Sopenharmony_ciparam follows::
1608c2ecf20Sopenharmony_ci
1618c2ecf20Sopenharmony_ci linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
1628c2ecf20Sopenharmony_ci
1638c2ecf20Sopenharmony_ciLog messages are transmitted with extended metadata header in the
1648c2ecf20Sopenharmony_cifollowing format which is the same as /dev/kmsg::
1658c2ecf20Sopenharmony_ci
1668c2ecf20Sopenharmony_ci <level>,<sequnum>,<timestamp>,<contflag>;<message text>
1678c2ecf20Sopenharmony_ci
1688c2ecf20Sopenharmony_ciNon printable characters in <message text> are escaped using "\xff"
1698c2ecf20Sopenharmony_cinotation. If the message contains optional dictionary, verbatim
1708c2ecf20Sopenharmony_cinewline is used as the delimeter.
1718c2ecf20Sopenharmony_ci
1728c2ecf20Sopenharmony_ciIf a message doesn't fit in certain number of bytes (currently 1000),
1738c2ecf20Sopenharmony_cithe message is split into multiple fragments by netconsole. These
1748c2ecf20Sopenharmony_cifragments are transmitted with "ncfrag" header field added::
1758c2ecf20Sopenharmony_ci
1768c2ecf20Sopenharmony_ci ncfrag=<byte-offset>/<total-bytes>
1778c2ecf20Sopenharmony_ci
1788c2ecf20Sopenharmony_ciFor example, assuming a lot smaller chunk size, a message "the first
1798c2ecf20Sopenharmony_cichunk, the 2nd chunk." may be split as follows::
1808c2ecf20Sopenharmony_ci
1818c2ecf20Sopenharmony_ci 6,416,1758426,-,ncfrag=0/31;the first chunk,
1828c2ecf20Sopenharmony_ci 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.
1838c2ecf20Sopenharmony_ci
1848c2ecf20Sopenharmony_ciMiscellaneous notes:
1858c2ecf20Sopenharmony_ci====================
1868c2ecf20Sopenharmony_ci
1878c2ecf20Sopenharmony_ci.. Warning::
1888c2ecf20Sopenharmony_ci
1898c2ecf20Sopenharmony_ci   the default target ethernet setting uses the broadcast
1908c2ecf20Sopenharmony_ci   ethernet address to send packets, which can cause increased load on
1918c2ecf20Sopenharmony_ci   other systems on the same ethernet segment.
1928c2ecf20Sopenharmony_ci
1938c2ecf20Sopenharmony_ci.. Tip::
1948c2ecf20Sopenharmony_ci
1958c2ecf20Sopenharmony_ci   some LAN switches may be configured to suppress ethernet broadcasts
1968c2ecf20Sopenharmony_ci   so it is advised to explicitly specify the remote agents' MAC addresses
1978c2ecf20Sopenharmony_ci   from the config parameters passed to netconsole.
1988c2ecf20Sopenharmony_ci
1998c2ecf20Sopenharmony_ci.. Tip::
2008c2ecf20Sopenharmony_ci
2018c2ecf20Sopenharmony_ci   to find out the MAC address of, say, 10.0.0.2, you may try using::
2028c2ecf20Sopenharmony_ci
2038c2ecf20Sopenharmony_ci	ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2
2048c2ecf20Sopenharmony_ci
2058c2ecf20Sopenharmony_ci.. Tip::
2068c2ecf20Sopenharmony_ci
2078c2ecf20Sopenharmony_ci   in case the remote logging agent is on a separate LAN subnet than
2088c2ecf20Sopenharmony_ci   the sender, it is suggested to try specifying the MAC address of the
2098c2ecf20Sopenharmony_ci   default gateway (you may use /sbin/route -n to find it out) as the
2108c2ecf20Sopenharmony_ci   remote MAC address instead.
2118c2ecf20Sopenharmony_ci
2128c2ecf20Sopenharmony_ci.. note::
2138c2ecf20Sopenharmony_ci
2148c2ecf20Sopenharmony_ci   the network device (eth1 in the above case) can run any kind
2158c2ecf20Sopenharmony_ci   of other network traffic, netconsole is not intrusive. Netconsole
2168c2ecf20Sopenharmony_ci   might cause slight delays in other traffic if the volume of kernel
2178c2ecf20Sopenharmony_ci   messages is high, but should have no other impact.
2188c2ecf20Sopenharmony_ci
2198c2ecf20Sopenharmony_ci.. note::
2208c2ecf20Sopenharmony_ci
2218c2ecf20Sopenharmony_ci   if you find that the remote logging agent is not receiving or
2228c2ecf20Sopenharmony_ci   printing all messages from the sender, it is likely that you have set
2238c2ecf20Sopenharmony_ci   the "console_loglevel" parameter (on the sender) to only send high
2248c2ecf20Sopenharmony_ci   priority messages to the console. You can change this at runtime using::
2258c2ecf20Sopenharmony_ci
2268c2ecf20Sopenharmony_ci	dmesg -n 8
2278c2ecf20Sopenharmony_ci
2288c2ecf20Sopenharmony_ci   or by specifying "debug" on the kernel command line at boot, to send
2298c2ecf20Sopenharmony_ci   all kernel messages to the console. A specific value for this parameter
2308c2ecf20Sopenharmony_ci   can also be set using the "loglevel" kernel boot option. See the
2318c2ecf20Sopenharmony_ci   dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
2328c2ecf20Sopenharmony_ci   for details.
2338c2ecf20Sopenharmony_ci
2348c2ecf20Sopenharmony_ciNetconsole was designed to be as instantaneous as possible, to
2358c2ecf20Sopenharmony_cienable the logging of even the most critical kernel bugs. It works
2368c2ecf20Sopenharmony_cifrom IRQ contexts as well, and does not enable interrupts while
2378c2ecf20Sopenharmony_cisending packets. Due to these unique needs, configuration cannot
2388c2ecf20Sopenharmony_cibe more automatic, and some fundamental limitations will remain:
2398c2ecf20Sopenharmony_cionly IP networks, UDP packets and ethernet devices are supported.
240