xref: /openbmc/linux/Documentation/networking/netconsole.rst (revision c900529f3d9161bfde5cca0754f83b4d3c3e0220)
1d9d6ef25SMauro Carvalho Chehab.. SPDX-License-Identifier: GPL-2.0
2d9d6ef25SMauro Carvalho Chehab
3d9d6ef25SMauro Carvalho Chehab==========
4d9d6ef25SMauro Carvalho ChehabNetconsole
5d9d6ef25SMauro Carvalho Chehab==========
6d9d6ef25SMauro Carvalho Chehab
7d9d6ef25SMauro Carvalho Chehab
8d9d6ef25SMauro Carvalho Chehabstarted by Ingo Molnar <mingo@redhat.com>, 2001.09.17
9d9d6ef25SMauro Carvalho Chehab
10d9d6ef25SMauro Carvalho Chehab2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
11d9d6ef25SMauro Carvalho Chehab
12d9d6ef25SMauro Carvalho ChehabIPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013
13d9d6ef25SMauro Carvalho Chehab
14d9d6ef25SMauro Carvalho ChehabExtended console support by Tejun Heo <tj@kernel.org>, May 1 2015
15d9d6ef25SMauro Carvalho Chehab
16*c62c0a17SBreno LeitaoRelease prepend support by Breno Leitao <leitao@debian.org>, Jul 7 2023
17*c62c0a17SBreno Leitao
18d9d6ef25SMauro Carvalho ChehabPlease send bug reports to Matt Mackall <mpm@selenic.com>
19d9d6ef25SMauro Carvalho ChehabSatyam Sharma <satyam.sharma@gmail.com>, and Cong Wang <xiyou.wangcong@gmail.com>
20d9d6ef25SMauro Carvalho Chehab
21d9d6ef25SMauro Carvalho ChehabIntroduction:
22d9d6ef25SMauro Carvalho Chehab=============
23d9d6ef25SMauro Carvalho Chehab
24d9d6ef25SMauro Carvalho ChehabThis module logs kernel printk messages over UDP allowing debugging of
25d9d6ef25SMauro Carvalho Chehabproblem where disk logging fails and serial consoles are impractical.
26d9d6ef25SMauro Carvalho Chehab
27d9d6ef25SMauro Carvalho ChehabIt can be used either built-in or as a module. As a built-in,
28d9d6ef25SMauro Carvalho Chehabnetconsole initializes immediately after NIC cards and will bring up
29d9d6ef25SMauro Carvalho Chehabthe specified interface as soon as possible. While this doesn't allow
30d9d6ef25SMauro Carvalho Chehabcapture of early kernel panics, it does capture most of the boot
31d9d6ef25SMauro Carvalho Chehabprocess.
32d9d6ef25SMauro Carvalho Chehab
33d9d6ef25SMauro Carvalho ChehabSender and receiver configuration:
34d9d6ef25SMauro Carvalho Chehab==================================
35d9d6ef25SMauro Carvalho Chehab
36d9d6ef25SMauro Carvalho ChehabIt takes a string configuration parameter "netconsole" in the
37d9d6ef25SMauro Carvalho Chehabfollowing format::
38d9d6ef25SMauro Carvalho Chehab
39*c62c0a17SBreno Leitao netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
40d9d6ef25SMauro Carvalho Chehab
41d9d6ef25SMauro Carvalho Chehab   where
42d9d6ef25SMauro Carvalho Chehab	+             if present, enable extended console support
43*c62c0a17SBreno Leitao	r             if present, prepend kernel version (release) to the message
44d9d6ef25SMauro Carvalho Chehab	src-port      source for UDP packets (defaults to 6665)
45d9d6ef25SMauro Carvalho Chehab	src-ip        source IP to use (interface address)
46d9d6ef25SMauro Carvalho Chehab	dev           network interface (eth0)
47d9d6ef25SMauro Carvalho Chehab	tgt-port      port for logging agent (6666)
48d9d6ef25SMauro Carvalho Chehab	tgt-ip        IP address for logging agent
49d9d6ef25SMauro Carvalho Chehab	tgt-macaddr   ethernet MAC address for logging agent (broadcast)
50d9d6ef25SMauro Carvalho Chehab
51d9d6ef25SMauro Carvalho ChehabExamples::
52d9d6ef25SMauro Carvalho Chehab
53d9d6ef25SMauro Carvalho Chehab linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
54d9d6ef25SMauro Carvalho Chehab
55d9d6ef25SMauro Carvalho Chehabor::
56d9d6ef25SMauro Carvalho Chehab
57d9d6ef25SMauro Carvalho Chehab insmod netconsole netconsole=@/,@10.0.0.2/
58d9d6ef25SMauro Carvalho Chehab
59d9d6ef25SMauro Carvalho Chehabor using IPv6::
60d9d6ef25SMauro Carvalho Chehab
61d9d6ef25SMauro Carvalho Chehab insmod netconsole netconsole=@/,@fd00:1:2:3::1/
62d9d6ef25SMauro Carvalho Chehab
63d9d6ef25SMauro Carvalho ChehabIt also supports logging to multiple remote agents by specifying
64d9d6ef25SMauro Carvalho Chehabparameters for the multiple agents separated by semicolons and the
65d9d6ef25SMauro Carvalho Chehabcomplete string enclosed in "quotes", thusly::
66d9d6ef25SMauro Carvalho Chehab
67d9d6ef25SMauro Carvalho Chehab modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"
68d9d6ef25SMauro Carvalho Chehab
69d9d6ef25SMauro Carvalho ChehabBuilt-in netconsole starts immediately after the TCP stack is
70d9d6ef25SMauro Carvalho Chehabinitialized and attempts to bring up the supplied dev at the supplied
71d9d6ef25SMauro Carvalho Chehabaddress.
72d9d6ef25SMauro Carvalho Chehab
73d9d6ef25SMauro Carvalho ChehabThe remote host has several options to receive the kernel messages,
74d9d6ef25SMauro Carvalho Chehabfor example:
75d9d6ef25SMauro Carvalho Chehab
76d9d6ef25SMauro Carvalho Chehab1) syslogd
77d9d6ef25SMauro Carvalho Chehab
78d9d6ef25SMauro Carvalho Chehab2) netcat
79d9d6ef25SMauro Carvalho Chehab
80d9d6ef25SMauro Carvalho Chehab   On distributions using a BSD-based netcat version (e.g. Fedora,
81d9d6ef25SMauro Carvalho Chehab   openSUSE and Ubuntu) the listening port must be specified without
82d9d6ef25SMauro Carvalho Chehab   the -p switch::
83d9d6ef25SMauro Carvalho Chehab
84d9d6ef25SMauro Carvalho Chehab	nc -u -l -p <port>' / 'nc -u -l <port>
85d9d6ef25SMauro Carvalho Chehab
86d9d6ef25SMauro Carvalho Chehab    or::
87d9d6ef25SMauro Carvalho Chehab
88d9d6ef25SMauro Carvalho Chehab	netcat -u -l -p <port>' / 'netcat -u -l <port>
89d9d6ef25SMauro Carvalho Chehab
90d9d6ef25SMauro Carvalho Chehab3) socat
91d9d6ef25SMauro Carvalho Chehab
92d9d6ef25SMauro Carvalho Chehab::
93d9d6ef25SMauro Carvalho Chehab
94d9d6ef25SMauro Carvalho Chehab   socat udp-recv:<port> -
95d9d6ef25SMauro Carvalho Chehab
96d9d6ef25SMauro Carvalho ChehabDynamic reconfiguration:
97d9d6ef25SMauro Carvalho Chehab========================
98d9d6ef25SMauro Carvalho Chehab
99d9d6ef25SMauro Carvalho ChehabDynamic reconfigurability is a useful addition to netconsole that enables
100d9d6ef25SMauro Carvalho Chehabremote logging targets to be dynamically added, removed, or have their
101d9d6ef25SMauro Carvalho Chehabparameters reconfigured at runtime from a configfs-based userspace interface.
102d9d6ef25SMauro Carvalho Chehab[ Note that the parameters of netconsole targets that were specified/created
103d9d6ef25SMauro Carvalho Chehabfrom the boot/module option are not exposed via this interface, and hence
104d9d6ef25SMauro Carvalho Chehabcannot be modified dynamically. ]
105d9d6ef25SMauro Carvalho Chehab
106d9d6ef25SMauro Carvalho ChehabTo include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
107d9d6ef25SMauro Carvalho Chehabnetconsole module (or kernel, if netconsole is built-in).
108d9d6ef25SMauro Carvalho Chehab
109d9d6ef25SMauro Carvalho ChehabSome examples follow (where configfs is mounted at the /sys/kernel/config
110d9d6ef25SMauro Carvalho Chehabmountpoint).
111d9d6ef25SMauro Carvalho Chehab
112d9d6ef25SMauro Carvalho ChehabTo add a remote logging target (target names can be arbitrary)::
113d9d6ef25SMauro Carvalho Chehab
114d9d6ef25SMauro Carvalho Chehab cd /sys/kernel/config/netconsole/
115d9d6ef25SMauro Carvalho Chehab mkdir target1
116d9d6ef25SMauro Carvalho Chehab
117d9d6ef25SMauro Carvalho ChehabNote that newly created targets have default parameter values (as mentioned
118d9d6ef25SMauro Carvalho Chehababove) and are disabled by default -- they must first be enabled by writing
119d9d6ef25SMauro Carvalho Chehab"1" to the "enabled" attribute (usually after setting parameters accordingly)
120d9d6ef25SMauro Carvalho Chehabas described below.
121d9d6ef25SMauro Carvalho Chehab
122d9d6ef25SMauro Carvalho ChehabTo remove a target::
123d9d6ef25SMauro Carvalho Chehab
124d9d6ef25SMauro Carvalho Chehab rmdir /sys/kernel/config/netconsole/othertarget/
125d9d6ef25SMauro Carvalho Chehab
126d9d6ef25SMauro Carvalho ChehabThe interface exposes these parameters of a netconsole target to userspace:
127d9d6ef25SMauro Carvalho Chehab
128d9d6ef25SMauro Carvalho Chehab	==============  =================================       ============
129d9d6ef25SMauro Carvalho Chehab	enabled		Is this target currently enabled?	(read-write)
130d9d6ef25SMauro Carvalho Chehab	extended	Extended mode enabled			(read-write)
131*c62c0a17SBreno Leitao	release		Prepend kernel release to message	(read-write)
132d9d6ef25SMauro Carvalho Chehab	dev_name	Local network interface name		(read-write)
133d9d6ef25SMauro Carvalho Chehab	local_port	Source UDP port to use			(read-write)
134d9d6ef25SMauro Carvalho Chehab	remote_port	Remote agent's UDP port			(read-write)
135d9d6ef25SMauro Carvalho Chehab	local_ip	Source IP address to use		(read-write)
136d9d6ef25SMauro Carvalho Chehab	remote_ip	Remote agent's IP address		(read-write)
137d9d6ef25SMauro Carvalho Chehab	local_mac	Local interface's MAC address		(read-only)
138d9d6ef25SMauro Carvalho Chehab	remote_mac	Remote agent's MAC address		(read-write)
139d9d6ef25SMauro Carvalho Chehab	==============  =================================       ============
140d9d6ef25SMauro Carvalho Chehab
141d9d6ef25SMauro Carvalho ChehabThe "enabled" attribute is also used to control whether the parameters of
142d9d6ef25SMauro Carvalho Chehaba target can be updated or not -- you can modify the parameters of only
143d9d6ef25SMauro Carvalho Chehabdisabled targets (i.e. if "enabled" is 0).
144d9d6ef25SMauro Carvalho Chehab
145d9d6ef25SMauro Carvalho ChehabTo update a target's parameters::
146d9d6ef25SMauro Carvalho Chehab
147d9d6ef25SMauro Carvalho Chehab cat enabled				# check if enabled is 1
148d9d6ef25SMauro Carvalho Chehab echo 0 > enabled			# disable the target (if required)
149d9d6ef25SMauro Carvalho Chehab echo eth2 > dev_name			# set local interface
150d9d6ef25SMauro Carvalho Chehab echo 10.0.0.4 > remote_ip		# update some parameter
151d9d6ef25SMauro Carvalho Chehab echo cb:a9:87:65:43:21 > remote_mac	# update more parameters
152d9d6ef25SMauro Carvalho Chehab echo 1 > enabled			# enable target again
153d9d6ef25SMauro Carvalho Chehab
154d9d6ef25SMauro Carvalho ChehabYou can also update the local interface dynamically. This is especially
155d9d6ef25SMauro Carvalho Chehabuseful if you want to use interfaces that have newly come up (and may not
156d9d6ef25SMauro Carvalho Chehabhave existed when netconsole was loaded / initialized).
157d9d6ef25SMauro Carvalho Chehab
158d9d6ef25SMauro Carvalho ChehabExtended console:
159d9d6ef25SMauro Carvalho Chehab=================
160d9d6ef25SMauro Carvalho Chehab
161d9d6ef25SMauro Carvalho ChehabIf '+' is prefixed to the configuration line or "extended" config file
162d9d6ef25SMauro Carvalho Chehabis set to 1, extended console support is enabled. An example boot
163d9d6ef25SMauro Carvalho Chehabparam follows::
164d9d6ef25SMauro Carvalho Chehab
165d9d6ef25SMauro Carvalho Chehab linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
166d9d6ef25SMauro Carvalho Chehab
167d9d6ef25SMauro Carvalho ChehabLog messages are transmitted with extended metadata header in the
168d9d6ef25SMauro Carvalho Chehabfollowing format which is the same as /dev/kmsg::
169d9d6ef25SMauro Carvalho Chehab
170d9d6ef25SMauro Carvalho Chehab <level>,<sequnum>,<timestamp>,<contflag>;<message text>
171d9d6ef25SMauro Carvalho Chehab
172*c62c0a17SBreno LeitaoIf 'r' (release) feature is enabled, the kernel release version is
173*c62c0a17SBreno Leitaoprepended to the start of the message. Example::
174*c62c0a17SBreno Leitao
175*c62c0a17SBreno Leitao 6.4.0,6,444,501151268,-;netconsole: network logging started
176*c62c0a17SBreno Leitao
177d9d6ef25SMauro Carvalho ChehabNon printable characters in <message text> are escaped using "\xff"
178d9d6ef25SMauro Carvalho Chehabnotation. If the message contains optional dictionary, verbatim
179a266ef69SRandy Dunlapnewline is used as the delimiter.
180d9d6ef25SMauro Carvalho Chehab
181d9d6ef25SMauro Carvalho ChehabIf a message doesn't fit in certain number of bytes (currently 1000),
182d9d6ef25SMauro Carvalho Chehabthe message is split into multiple fragments by netconsole. These
183d9d6ef25SMauro Carvalho Chehabfragments are transmitted with "ncfrag" header field added::
184d9d6ef25SMauro Carvalho Chehab
185d9d6ef25SMauro Carvalho Chehab ncfrag=<byte-offset>/<total-bytes>
186d9d6ef25SMauro Carvalho Chehab
187d9d6ef25SMauro Carvalho ChehabFor example, assuming a lot smaller chunk size, a message "the first
188d9d6ef25SMauro Carvalho Chehabchunk, the 2nd chunk." may be split as follows::
189d9d6ef25SMauro Carvalho Chehab
190d9d6ef25SMauro Carvalho Chehab 6,416,1758426,-,ncfrag=0/31;the first chunk,
191d9d6ef25SMauro Carvalho Chehab 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.
192d9d6ef25SMauro Carvalho Chehab
193d9d6ef25SMauro Carvalho ChehabMiscellaneous notes:
194d9d6ef25SMauro Carvalho Chehab====================
195d9d6ef25SMauro Carvalho Chehab
196d9d6ef25SMauro Carvalho Chehab.. Warning::
197d9d6ef25SMauro Carvalho Chehab
198d9d6ef25SMauro Carvalho Chehab   the default target ethernet setting uses the broadcast
199d9d6ef25SMauro Carvalho Chehab   ethernet address to send packets, which can cause increased load on
200d9d6ef25SMauro Carvalho Chehab   other systems on the same ethernet segment.
201d9d6ef25SMauro Carvalho Chehab
202d9d6ef25SMauro Carvalho Chehab.. Tip::
203d9d6ef25SMauro Carvalho Chehab
204d9d6ef25SMauro Carvalho Chehab   some LAN switches may be configured to suppress ethernet broadcasts
205d9d6ef25SMauro Carvalho Chehab   so it is advised to explicitly specify the remote agents' MAC addresses
206d9d6ef25SMauro Carvalho Chehab   from the config parameters passed to netconsole.
207d9d6ef25SMauro Carvalho Chehab
208d9d6ef25SMauro Carvalho Chehab.. Tip::
209d9d6ef25SMauro Carvalho Chehab
210d9d6ef25SMauro Carvalho Chehab   to find out the MAC address of, say, 10.0.0.2, you may try using::
211d9d6ef25SMauro Carvalho Chehab
212d9d6ef25SMauro Carvalho Chehab	ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2
213d9d6ef25SMauro Carvalho Chehab
214d9d6ef25SMauro Carvalho Chehab.. Tip::
215d9d6ef25SMauro Carvalho Chehab
216d9d6ef25SMauro Carvalho Chehab   in case the remote logging agent is on a separate LAN subnet than
217d9d6ef25SMauro Carvalho Chehab   the sender, it is suggested to try specifying the MAC address of the
218d9d6ef25SMauro Carvalho Chehab   default gateway (you may use /sbin/route -n to find it out) as the
219d9d6ef25SMauro Carvalho Chehab   remote MAC address instead.
220d9d6ef25SMauro Carvalho Chehab
221d9d6ef25SMauro Carvalho Chehab.. note::
222d9d6ef25SMauro Carvalho Chehab
223d9d6ef25SMauro Carvalho Chehab   the network device (eth1 in the above case) can run any kind
224d9d6ef25SMauro Carvalho Chehab   of other network traffic, netconsole is not intrusive. Netconsole
225d9d6ef25SMauro Carvalho Chehab   might cause slight delays in other traffic if the volume of kernel
226d9d6ef25SMauro Carvalho Chehab   messages is high, but should have no other impact.
227d9d6ef25SMauro Carvalho Chehab
228d9d6ef25SMauro Carvalho Chehab.. note::
229d9d6ef25SMauro Carvalho Chehab
230d9d6ef25SMauro Carvalho Chehab   if you find that the remote logging agent is not receiving or
231d9d6ef25SMauro Carvalho Chehab   printing all messages from the sender, it is likely that you have set
232d9d6ef25SMauro Carvalho Chehab   the "console_loglevel" parameter (on the sender) to only send high
233d9d6ef25SMauro Carvalho Chehab   priority messages to the console. You can change this at runtime using::
234d9d6ef25SMauro Carvalho Chehab
235d9d6ef25SMauro Carvalho Chehab	dmesg -n 8
236d9d6ef25SMauro Carvalho Chehab
237d9d6ef25SMauro Carvalho Chehab   or by specifying "debug" on the kernel command line at boot, to send
238d9d6ef25SMauro Carvalho Chehab   all kernel messages to the console. A specific value for this parameter
239d9d6ef25SMauro Carvalho Chehab   can also be set using the "loglevel" kernel boot option. See the
240d9d6ef25SMauro Carvalho Chehab   dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
241d9d6ef25SMauro Carvalho Chehab   for details.
242d9d6ef25SMauro Carvalho Chehab
243d9d6ef25SMauro Carvalho ChehabNetconsole was designed to be as instantaneous as possible, to
244d9d6ef25SMauro Carvalho Chehabenable the logging of even the most critical kernel bugs. It works
245d9d6ef25SMauro Carvalho Chehabfrom IRQ contexts as well, and does not enable interrupts while
246d9d6ef25SMauro Carvalho Chehabsending packets. Due to these unique needs, configuration cannot
247d9d6ef25SMauro Carvalho Chehabbe more automatic, and some fundamental limitations will remain:
248d9d6ef25SMauro Carvalho Chehabonly IP networks, UDP packets and ethernet devices are supported.
249