Back to home page

OSCL-LXR

 
 

    


0001 .. SPDX-License-Identifier: GPL-2.0
0002 
0003 ==========
0004 Netconsole
0005 ==========
0006 
0007 
0008 started by Ingo Molnar <mingo@redhat.com>, 2001.09.17
0009 
0010 2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
0011 
0012 IPv6 support by Cong Wang <xiyou.wangcong@gmail.com>, Jan 1 2013
0013 
0014 Extended console support by Tejun Heo <tj@kernel.org>, May 1 2015
0015 
0016 Please send bug reports to Matt Mackall <mpm@selenic.com>
0017 Satyam Sharma <satyam.sharma@gmail.com>, and Cong Wang <xiyou.wangcong@gmail.com>
0018 
0019 Introduction:
0020 =============
0021 
0022 This module logs kernel printk messages over UDP allowing debugging of
0023 problem where disk logging fails and serial consoles are impractical.
0024 
0025 It can be used either built-in or as a module. As a built-in,
0026 netconsole initializes immediately after NIC cards and will bring up
0027 the specified interface as soon as possible. While this doesn't allow
0028 capture of early kernel panics, it does capture most of the boot
0029 process.
0030 
0031 Sender and receiver configuration:
0032 ==================================
0033 
0034 It takes a string configuration parameter "netconsole" in the
0035 following format::
0036 
0037  netconsole=[+][src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
0038 
0039    where
0040         +             if present, enable extended console support
0041         src-port      source for UDP packets (defaults to 6665)
0042         src-ip        source IP to use (interface address)
0043         dev           network interface (eth0)
0044         tgt-port      port for logging agent (6666)
0045         tgt-ip        IP address for logging agent
0046         tgt-macaddr   ethernet MAC address for logging agent (broadcast)
0047 
0048 Examples::
0049 
0050  linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
0051 
0052 or::
0053 
0054  insmod netconsole netconsole=@/,@10.0.0.2/
0055 
0056 or using IPv6::
0057 
0058  insmod netconsole netconsole=@/,@fd00:1:2:3::1/
0059 
0060 It also supports logging to multiple remote agents by specifying
0061 parameters for the multiple agents separated by semicolons and the
0062 complete string enclosed in "quotes", thusly::
0063 
0064  modprobe netconsole netconsole="@/,@10.0.0.2/;@/eth1,6892@10.0.0.3/"
0065 
0066 Built-in netconsole starts immediately after the TCP stack is
0067 initialized and attempts to bring up the supplied dev at the supplied
0068 address.
0069 
0070 The remote host has several options to receive the kernel messages,
0071 for example:
0072 
0073 1) syslogd
0074 
0075 2) netcat
0076 
0077    On distributions using a BSD-based netcat version (e.g. Fedora,
0078    openSUSE and Ubuntu) the listening port must be specified without
0079    the -p switch::
0080 
0081         nc -u -l -p <port>' / 'nc -u -l <port>
0082 
0083     or::
0084 
0085         netcat -u -l -p <port>' / 'netcat -u -l <port>
0086 
0087 3) socat
0088 
0089 ::
0090 
0091    socat udp-recv:<port> -
0092 
0093 Dynamic reconfiguration:
0094 ========================
0095 
0096 Dynamic reconfigurability is a useful addition to netconsole that enables
0097 remote logging targets to be dynamically added, removed, or have their
0098 parameters reconfigured at runtime from a configfs-based userspace interface.
0099 [ Note that the parameters of netconsole targets that were specified/created
0100 from the boot/module option are not exposed via this interface, and hence
0101 cannot be modified dynamically. ]
0102 
0103 To include this feature, select CONFIG_NETCONSOLE_DYNAMIC when building the
0104 netconsole module (or kernel, if netconsole is built-in).
0105 
0106 Some examples follow (where configfs is mounted at the /sys/kernel/config
0107 mountpoint).
0108 
0109 To add a remote logging target (target names can be arbitrary)::
0110 
0111  cd /sys/kernel/config/netconsole/
0112  mkdir target1
0113 
0114 Note that newly created targets have default parameter values (as mentioned
0115 above) and are disabled by default -- they must first be enabled by writing
0116 "1" to the "enabled" attribute (usually after setting parameters accordingly)
0117 as described below.
0118 
0119 To remove a target::
0120 
0121  rmdir /sys/kernel/config/netconsole/othertarget/
0122 
0123 The interface exposes these parameters of a netconsole target to userspace:
0124 
0125         ==============  =================================       ============
0126         enabled         Is this target currently enabled?       (read-write)
0127         extended        Extended mode enabled                   (read-write)
0128         dev_name        Local network interface name            (read-write)
0129         local_port      Source UDP port to use                  (read-write)
0130         remote_port     Remote agent's UDP port                 (read-write)
0131         local_ip        Source IP address to use                (read-write)
0132         remote_ip       Remote agent's IP address               (read-write)
0133         local_mac       Local interface's MAC address           (read-only)
0134         remote_mac      Remote agent's MAC address              (read-write)
0135         ==============  =================================       ============
0136 
0137 The "enabled" attribute is also used to control whether the parameters of
0138 a target can be updated or not -- you can modify the parameters of only
0139 disabled targets (i.e. if "enabled" is 0).
0140 
0141 To update a target's parameters::
0142 
0143  cat enabled                            # check if enabled is 1
0144  echo 0 > enabled                       # disable the target (if required)
0145  echo eth2 > dev_name                   # set local interface
0146  echo 10.0.0.4 > remote_ip              # update some parameter
0147  echo cb:a9:87:65:43:21 > remote_mac    # update more parameters
0148  echo 1 > enabled                       # enable target again
0149 
0150 You can also update the local interface dynamically. This is especially
0151 useful if you want to use interfaces that have newly come up (and may not
0152 have existed when netconsole was loaded / initialized).
0153 
0154 Extended console:
0155 =================
0156 
0157 If '+' is prefixed to the configuration line or "extended" config file
0158 is set to 1, extended console support is enabled. An example boot
0159 param follows::
0160 
0161  linux netconsole=+4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
0162 
0163 Log messages are transmitted with extended metadata header in the
0164 following format which is the same as /dev/kmsg::
0165 
0166  <level>,<sequnum>,<timestamp>,<contflag>;<message text>
0167 
0168 Non printable characters in <message text> are escaped using "\xff"
0169 notation. If the message contains optional dictionary, verbatim
0170 newline is used as the delimeter.
0171 
0172 If a message doesn't fit in certain number of bytes (currently 1000),
0173 the message is split into multiple fragments by netconsole. These
0174 fragments are transmitted with "ncfrag" header field added::
0175 
0176  ncfrag=<byte-offset>/<total-bytes>
0177 
0178 For example, assuming a lot smaller chunk size, a message "the first
0179 chunk, the 2nd chunk." may be split as follows::
0180 
0181  6,416,1758426,-,ncfrag=0/31;the first chunk,
0182  6,416,1758426,-,ncfrag=16/31; the 2nd chunk.
0183 
0184 Miscellaneous notes:
0185 ====================
0186 
0187 .. Warning::
0188 
0189    the default target ethernet setting uses the broadcast
0190    ethernet address to send packets, which can cause increased load on
0191    other systems on the same ethernet segment.
0192 
0193 .. Tip::
0194 
0195    some LAN switches may be configured to suppress ethernet broadcasts
0196    so it is advised to explicitly specify the remote agents' MAC addresses
0197    from the config parameters passed to netconsole.
0198 
0199 .. Tip::
0200 
0201    to find out the MAC address of, say, 10.0.0.2, you may try using::
0202 
0203         ping -c 1 10.0.0.2 ; /sbin/arp -n | grep 10.0.0.2
0204 
0205 .. Tip::
0206 
0207    in case the remote logging agent is on a separate LAN subnet than
0208    the sender, it is suggested to try specifying the MAC address of the
0209    default gateway (you may use /sbin/route -n to find it out) as the
0210    remote MAC address instead.
0211 
0212 .. note::
0213 
0214    the network device (eth1 in the above case) can run any kind
0215    of other network traffic, netconsole is not intrusive. Netconsole
0216    might cause slight delays in other traffic if the volume of kernel
0217    messages is high, but should have no other impact.
0218 
0219 .. note::
0220 
0221    if you find that the remote logging agent is not receiving or
0222    printing all messages from the sender, it is likely that you have set
0223    the "console_loglevel" parameter (on the sender) to only send high
0224    priority messages to the console. You can change this at runtime using::
0225 
0226         dmesg -n 8
0227 
0228    or by specifying "debug" on the kernel command line at boot, to send
0229    all kernel messages to the console. A specific value for this parameter
0230    can also be set using the "loglevel" kernel boot option. See the
0231    dmesg(8) man page and Documentation/admin-guide/kernel-parameters.rst
0232    for details.
0233 
0234 Netconsole was designed to be as instantaneous as possible, to
0235 enable the logging of even the most critical kernel bugs. It works
0236 from IRQ contexts as well, and does not enable interrupts while
0237 sending packets. Due to these unique needs, configuration cannot
0238 be more automatic, and some fundamental limitations will remain:
0239 only IP networks, UDP packets and ethernet devices are supported.