brintos

brintos / linux-shallow public Read only

0
0
Text · 10.7 KiB · d55c2a2 Raw
331 lines · plain
1.. SPDX-License-Identifier: GPL-2.02 3==========4Netconsole5==========6 7 8started by Ingo Molnar <mingo@redhat.com>, 2001.09.179 102.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 200311 12IPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 201313 14Extended console support by Tejun Heo <tj@kernel.org>, May 1 201515 16Release prepend support by Breno Leitao <leitao@debian.org>, Jul 7 202317 18Userdata append support by Matthew Wood <thepacketgeek@gmail.com>, Jan 22 202419 20Please send bug reports to Matt Mackall <mpm@selenic.com>21Satyam Sharma <satyam.sharma@gmail.com>, and Cong Wang <xiyou.wangcong@gmail.com>22 23Introduction:24=============25 26This module logs kernel printk messages over UDP allowing debugging of27problem where disk logging fails and serial consoles are impractical.28 29It can be used either built-in or as a module. As a built-in,30netconsole initializes immediately after NIC cards and will bring up31the specified interface as soon as possible. While this doesn't allow32capture of early kernel panics, it does capture most of the boot33process.34 35Sender and receiver configuration:36==================================37 38It takes a string configuration parameter "netconsole" in the39following format::40 41 netconsole=[+][r][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]42 43   where44	+             if present, enable extended console support45	r             if present, prepend kernel version (release) to the message46	src-port      source for UDP packets (defaults to 6665)47	src-ip        source IP to use (interface address)48	dev           network interface (eth0)49	tgt-port      port for logging agent (6666)50	tgt-ip        IP address for logging agent51	tgt-macaddr   ethernet MAC address for logging agent (broadcast)52 53Examples::54 55 linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc56 57or::58 59 insmod netconsole netconsole=@/,@10.0.0.2/60 61or using IPv6::62 63 insmod netconsole netconsole=@/,@fd00:1:2:3::1/64 65It also supports logging to multiple remote agents by specifying66parameters for the multiple agents separated by semicolons and the67complete string enclosed in "quotes", thusly::68 69 modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"70 71Built-in netconsole starts immediately after the TCP stack is72initialized and attempts to bring up the supplied dev at the supplied73address.74 75The remote host has several options to receive the kernel messages,76for example:77 781) syslogd79 802) netcat81 82   On distributions using a BSD-based netcat version (e.g. Fedora,83   openSUSE and Ubuntu) the listening port must be specified without84   the -p switch::85 86	nc -u -l -p <port>' / 'nc -u -l <port>87 88    or::89 90	netcat -u -l -p <port>' / 'netcat -u -l <port>91 923) socat93 94::95 96   socat udp-recv:<port> -97 98Dynamic reconfiguration:99========================100 101Dynamic reconfigurability is a useful addition to netconsole that enables102remote logging targets to be dynamically added, removed, or have their103parameters reconfigured at runtime from a configfs-based userspace interface.104 105To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the106netconsole module (or kernel, if netconsole is built-in).107 108Some examples follow (where configfs is mounted at the /sys/kernel/config109mountpoint).110 111To add a remote logging target (target names can be arbitrary)::112 113 cd /sys/kernel/config/netconsole/114 mkdir target1115 116Note that newly created targets have default parameter values (as mentioned117above) and are disabled by default -- they must first be enabled by writing118"1" to the "enabled" attribute (usually after setting parameters accordingly)119as described below.120 121To remove a target::122 123 rmdir /sys/kernel/config/netconsole/othertarget/124 125The interface exposes these parameters of a netconsole target to userspace:126 127	==============  =================================       ============128	enabled		Is this target currently enabled?	(read-write)129	extended	Extended mode enabled			(read-write)130	release		Prepend kernel release to message	(read-write)131	dev_name	Local network interface name		(read-write)132	local_port	Source UDP port to use			(read-write)133	remote_port	Remote agent's UDP port			(read-write)134	local_ip	Source IP address to use		(read-write)135	remote_ip	Remote agent's IP address		(read-write)136	local_mac	Local interface's MAC address		(read-only)137	remote_mac	Remote agent's MAC address		(read-write)138	==============  =================================       ============139 140The "enabled" attribute is also used to control whether the parameters of141a target can be updated or not -- you can modify the parameters of only142disabled targets (i.e. if "enabled" is 0).143 144To update a target's parameters::145 146 cat enabled				# check if enabled is 1147 echo 0 > enabled			# disable the target (if required)148 echo eth2 > dev_name			# set local interface149 echo 10.0.0.4 > remote_ip		# update some parameter150 echo cb:a9:87:65:43:21 > remote_mac	# update more parameters151 echo 1 > enabled			# enable target again152 153You can also update the local interface dynamically. This is especially154useful if you want to use interfaces that have newly come up (and may not155have existed when netconsole was loaded / initialized).156 157Netconsole targets defined at boot time (or module load time) with the158`netconsole=` param are assigned the name `cmdline<index>`.  For example, the159first target in the parameter is named `cmdline0`.  You can control and modify160these targets by creating configfs directories with the matching name.161 162Let's suppose you have two netconsole targets defined at boot time::163 164 netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc;4444@10.0.0.1/eth1,9353@10.0.0.3/12:34:56:78:9a:bc165 166You can modify these targets in runtime by creating the following targets::167 168 mkdir cmdline0169 cat cmdline0/remote_ip170 10.0.0.2171 172 mkdir cmdline1173 cat cmdline1/remote_ip174 10.0.0.3175 176Append User Data177----------------178 179Custom user data can be appended to the end of messages with netconsole180dynamic configuration enabled. User data entries can be modified without181changing the "enabled" attribute of a target.182 183Directories (keys) under `userdata` are limited to 53 character length, and184data in `userdata/<key>/value` are limited to 200 bytes::185 186 cd /sys/kernel/config/netconsole && mkdir cmdline0187 cd cmdline0188 mkdir userdata/foo189 echo bar > userdata/foo/value190 mkdir userdata/qux191 echo baz > userdata/qux/value192 193Messages will now include this additional user data::194 195 echo "This is a message" > /dev/kmsg196 197Sends::198 199 12,607,22085407756,-;This is a message200  foo=bar201  qux=baz202 203Preview the userdata that will be appended with::204 205 cd /sys/kernel/config/netconsole/cmdline0/userdata206 for f in `ls userdata`; do echo $f=$(cat userdata/$f/value); done207 208If a `userdata` entry is created but no data is written to the `value` file,209the entry will be omitted from netconsole messages::210 211 cd /sys/kernel/config/netconsole && mkdir cmdline0212 cd cmdline0213 mkdir userdata/foo214 echo bar > userdata/foo/value215 mkdir userdata/qux216 217The `qux` key is omitted since it has no value::218 219 echo "This is a message" > /dev/kmsg220 12,607,22085407756,-;This is a message221  foo=bar222 223Delete `userdata` entries with `rmdir`::224 225 rmdir /sys/kernel/config/netconsole/cmdline0/userdata/qux226 227.. warning::228   When writing strings to user data values, input is broken up per line in229   configfs store calls and this can cause confusing behavior::230 231     mkdir userdata/testing232     printf "val1\nval2" > userdata/testing/value233     # userdata store value is called twice, first with "val1\n" then "val2"234     # so "val2" is stored, being the last value stored235     cat userdata/testing/value236     val2237 238   It is recommended to not write user data values with newlines.239 240Extended console:241=================242 243If '+' is prefixed to the configuration line or "extended" config file244is set to 1, extended console support is enabled. An example boot245param follows::246 247 linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc248 249Log messages are transmitted with extended metadata header in the250following format which is the same as /dev/kmsg::251 252 <level>,<sequnum>,<timestamp>,<contflag>;<message text>253 254If 'r' (release) feature is enabled, the kernel release version is255prepended to the start of the message. Example::256 257 6.4.0,6,444,501151268,-;netconsole: network logging started258 259Non printable characters in <message text> are escaped using "\xff"260notation. If the message contains optional dictionary, verbatim261newline is used as the delimiter.262 263If a message doesn't fit in certain number of bytes (currently 1000),264the message is split into multiple fragments by netconsole. These265fragments are transmitted with "ncfrag" header field added::266 267 ncfrag=<byte-offset>/<total-bytes>268 269For example, assuming a lot smaller chunk size, a message "the first270chunk, the 2nd chunk." may be split as follows::271 272 6,416,1758426,-,ncfrag=0/31;the first chunk,273 6,416,1758426,-,ncfrag=16/31; the 2nd chunk.274 275Miscellaneous notes:276====================277 278.. Warning::279 280   the default target ethernet setting uses the broadcast281   ethernet address to send packets, which can cause increased load on282   other systems on the same ethernet segment.283 284.. Tip::285 286   some LAN switches may be configured to suppress ethernet broadcasts287   so it is advised to explicitly specify the remote agents' MAC addresses288   from the config parameters passed to netconsole.289 290.. Tip::291 292   to find out the MAC address of, say, 10.0.0.2, you may try using::293 294	ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2295 296.. Tip::297 298   in case the remote logging agent is on a separate LAN subnet than299   the sender, it is suggested to try specifying the MAC address of the300   default gateway (you may use /sbin/route -n to find it out) as the301   remote MAC address instead.302 303.. note::304 305   the network device (eth1 in the above case) can run any kind306   of other network traffic, netconsole is not intrusive. Netconsole307   might cause slight delays in other traffic if the volume of kernel308   messages is high, but should have no other impact.309 310.. note::311 312   if you find that the remote logging agent is not receiving or313   printing all messages from the sender, it is likely that you have set314   the "console_loglevel" parameter (on the sender) to only send high315   priority messages to the console. You can change this at runtime using::316 317	dmesg -n 8318 319   or by specifying "debug" on the kernel command line at boot, to send320   all kernel messages to the console. A specific value for this parameter321   can also be set using the "loglevel" kernel boot option. See the322   dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst323   for details.324 325Netconsole was designed to be as instantaneous as possible, to326enable the logging of even the most critical kernel bugs. It works327from IRQ contexts as well, and does not enable interrupts while328sending packets. Due to these unique needs, configuration cannot329be more automatic, and some fundamental limitations will remain:330only IP networks, UDP packets and ethernet devices are supported.331