1 Documentation/networking/netconsole.txt | 57 ++++++++
2 arch/i386/kernel/i386_ksyms.c | 8 +
3 arch/i386/kernel/irq.c | 12 +
4 drivers/net/Kconfig | 7 +
5 drivers/net/Makefile | 1
6 drivers/net/netconsole.c | 217 ++++++++++++++++++++++++++++++++
7 include/asm-i386/netconsole.h | 6
10 9 files changed, 311 insertions(+), 2 deletions(-)
12 --- linux-2.6.0-test6/arch/i386/kernel/i386_ksyms.c~netconsole-over-netpoll 2003-10-14 17:44:04.000000000 +0400
13 +++ linux-2.6.0-test6-alexey/arch/i386/kernel/i386_ksyms.c 2003-10-14 17:45:08.000000000 +0400
19 +#include <asm/netconsole.h>
20 extern void dump_thread(struct pt_regs *, struct user *);
21 extern spinlock_t rtc_lock;
23 @@ -211,6 +211,12 @@ EXPORT_SYMBOL(edd);
27 +#ifdef CONFIG_NETCONSOLE
28 +EXPORT_SYMBOL(netconsole_sysrq_req);
29 +EXPORT_SYMBOL(netconsole_do_sysrq);
30 +EXPORT_SYMBOL(netif_in_poll);
33 #if defined(CONFIG_X86_SPEEDSTEP_SMI) || defined(CONFIG_X86_SPEEDSTEP_SMI_MODULE)
34 EXPORT_SYMBOL(ist_info);
36 --- linux-2.6.0-test6/arch/i386/kernel/irq.c~netconsole-over-netpoll 2003-10-14 17:45:03.000000000 +0400
37 +++ linux-2.6.0-test6-alexey/arch/i386/kernel/irq.c 2003-10-14 17:45:08.000000000 +0400
42 +#include <asm/netconsole.h>
45 * Linux has a controller-independent x86 interrupt architecture.
46 @@ -510,6 +511,17 @@ out:
50 +#ifdef CONFIG_NETCONSOLE
52 + * We need to do this after clearing out of all the interrupt
53 + * machinery because kgdb will reenter the NIC driver and the IRQ
54 + * system. synchronize_irq() (at least) will deadlock.
56 + if (netconsole_sysrq_req && !netif_in_poll) {
57 + netconsole_sysrq_req = 0;
64 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
65 +++ linux-2.6.0-test6-alexey/Documentation/networking/netconsole.txt 2003-10-14 17:45:08.000000000 +0400
68 +started by Ingo Molnar <mingo@redhat.com>, 2001.09.17
69 +2.6 port and netpoll api by Matt Mackall <mpm@selenic.com>, Sep 9 2003
71 +Please send bug reports to Matt Mackall <mpm@selenic.com>
73 +This module logs kernel printk messages over UDP allowing debugging of
74 +problem where disk logging fails and serial consoles are impractical.
76 +It can be used either built-in or as a module. As a built-in,
77 +netconsole initializes immediately after NIC cards and will bring up
78 +the specified interface as soon as possible. While this doesn't allow
79 +capture of early kernel panics, it does capture most of the boot
82 +It takes a string configuration parameter "netconsole" in the
85 + netconsole=[src-port]@[src-ip]/[<dev>],[tgt-port]@<tgt-ip>/[tgt-macaddr]
88 + src-port source for UDP packets (defaults to 6666)
89 + src-ip source IP to use (interface address)
90 + dev network interface (eth0)
91 + tgt-port port for logging agent (514)
92 + tgt-ip IP address for logging agent
93 + tgt-macaddr ethernet MAC address for logging agent (broadcast)
97 + linux netconsole=4444@10.0.0.1/eth1,9353@10.0.0.2/12:34:56:78:9a:bc
101 + insmod netconsole netconsole=@/,@10.0.0.2/
103 +Built-in netconsole starts immediately after the TCP stack is
104 +initialized and attempts to bring up the supplied dev at the supplied
107 +The remote host can run either 'netcat -u -l -p <port>' or syslogd.
109 +WARNING: the default target ethernet setting uses the broadcast
110 +ethernet address to send packets, which can cause increased load on
111 +other systems on the same ethernet segment.
113 +NOTE: the network device (eth1 in the above case) can run any kind
114 +of other network traffic, netconsole is not intrusive. Netconsole
115 +might cause slight delays in other traffic if the volume of kernel
116 +messages is high, but should have no other impact.
118 +Netconsole was designed to be as instantaneous as possible, to
119 +enable the logging of even the most critical kernel bugs. It works
120 +from IRQ contexts as well, and does not enable interrupts while
121 +sending packets. Due to these unique needs, configuration can not
122 +be more automatic, and some fundamental limitations will remain:
123 +only IP networks, UDP packets and ethernet devices are supported.
124 --- linux-2.6.0-test6/drivers/net/Kconfig~netconsole-over-netpoll 2003-10-14 17:44:05.000000000 +0400
125 +++ linux-2.6.0-test6-alexey/drivers/net/Kconfig 2003-10-14 17:45:08.000000000 +0400
126 @@ -2444,6 +2444,13 @@ config SHAPER
127 config NET_POLL_CONTROLLER
131 + tristate "Network console logging support"
132 + depends on NETDEVICES
134 + If you want to log kernel messages over the network, enable this.
135 + See Documentation/networking/netconsole.txt for details.
137 source "drivers/net/wan/Kconfig"
139 source "drivers/net/pcmcia/Kconfig"
140 --- linux-2.6.0-test6/drivers/net/Makefile~netconsole-over-netpoll 2003-10-14 17:45:04.000000000 +0400
141 +++ linux-2.6.0-test6-alexey/drivers/net/Makefile 2003-10-14 17:45:08.000000000 +0400
142 @@ -109,6 +109,7 @@ ifeq ($(CONFIG_SLIP_COMPRESSED),y)
144 # Must come after all NICs it might use
145 obj-$(CONFIG_KGDB) += kgdb_eth.o
146 +obj-$(CONFIG_NETCONSOLE) += netconsole.o
148 obj-$(CONFIG_DUMMY) += dummy.o
149 obj-$(CONFIG_DE600) += de600.o
150 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
151 +++ linux-2.6.0-test6-alexey/drivers/net/netconsole.c 2003-10-14 17:45:56.000000000 +0400
154 + * linux/drivers/net/netconsole.c
156 + * Copyright (C) 2001 Ingo Molnar <mingo@redhat.com>
158 + * This file contains the implementation of an IRQ-safe, crash-safe
159 + * kernel console implementation that outputs kernel messages to the
162 + * Modification history:
164 + * 2001-09-17 started by Ingo Molnar.
165 + * 2003-08-11 2.6 port by Matt Mackall
166 + * simplified options
167 + * generic card hooks
168 + * works non-modular
169 + * 2003-09-07 rewritten with netpoll api
170 + * 2003-09-27 updated by wangdi <wangdi@clusterfs.com>
173 +/****************************************************************
174 + * This program is free software; you can redistribute it and/or modify
175 + * it under the terms of the GNU General Public License as published by
176 + * the Free Software Foundation; either version 2, or (at your option)
177 + * any later version.
179 + * This program is distributed in the hope that it will be useful,
180 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
181 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
182 + * GNU General Public License for more details.
184 + * You should have received a copy of the GNU General Public License
185 + * along with this program; if not, write to the Free Software
186 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
188 + ****************************************************************/
190 +#include <linux/mm.h>
191 +#include <linux/tty.h>
192 +#include <linux/init.h>
193 +#include <linux/module.h>
194 +#include <linux/console.h>
195 +#include <linux/tty_driver.h>
196 +#include <linux/module.h>
197 +#include <linux/moduleparam.h>
198 +#include <linux/string.h>
199 +#include <linux/sysrq.h>
200 +#include <linux/smp.h>
201 +#include <linux/netpoll.h>
202 +#include <linux/dump.h>
203 +#include <linux/dump_netdev.h>
204 +#include <asm/unaligned.h>
205 +#include <asm/dump.h>
206 +#include <asm/netconsole.h>
208 +MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
209 +MODULE_DESCRIPTION("Console driver for network interfaces");
210 +MODULE_LICENSE("GPL");
212 +static char config[256];
213 +module_param_string(netconsole, config, 256, 0);
214 +MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n");
216 +static void rx_hook(struct netpoll *np, int port, char *msg, int len);
218 +static int sysrq_mode = 0;
221 +unsigned int netconsole_sysrq_req = 0;
222 +unsigned int netif_in_poll = 0;
223 +static unsigned int handle_sysrq_progress = 0;
224 +#define Set_Sysrq_mode() (sysrq_mode = 1)
225 +#define Clear_Sysrq_mode() (sysrq_mode = 0)
227 +static struct netpoll np = {
228 + .name = "netconsole",
229 + .dev_name = "eth0",
230 + .rx_hook = rx_hook,
231 + .local_port = 6666,
232 + .remote_port = 6666,
233 + .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
236 +#define MAX_PRINT_CHUNK 1000
237 +#define MAX_SEND_BUFFER_LEN (MAX_PRINT_CHUNK + 200)
239 +static char send_buf[MAX_SEND_BUFFER_LEN];
240 +static char send_cache[MAX_PRINT_CHUNK];
241 +static unsigned int send_cache_pos = 0;
243 +static void send_msg_buffer(struct netpoll *np, const char *msg, int len)
247 + send_buf[0] = NETCONSOLE_VERSION;
248 + reply.code = REPLY_LOG;
252 + put_unaligned(htonl(reply.nr), (u32 *) (send_buf + 1));
253 + put_unaligned(htonl(reply.code), (u32 *) (send_buf + 5));
254 + put_unaligned(htonl(reply.info), (u32 *) (send_buf+ 9));
256 + memcpy(send_buf + 1 + sizeof(reply_t), msg, len);
257 + netpoll_send_udp(np, send_buf, len + 1 + sizeof(reply_t));
260 +static void write_msg(struct console *con, const char *msg, unsigned int len)
262 + unsigned long total_len = send_cache_pos + len;
263 + unsigned long left_len = len;
264 + unsigned long flags;
270 + while (total_len >= MAX_PRINT_CHUNK){
271 + unsigned long send_len = MAX_PRINT_CHUNK - send_cache_pos;
272 + memcpy(send_cache + send_cache_pos, msg, send_len);
273 + local_irq_save(flags);
275 + for(left = send_len; left; ) {
276 + frag = min(left, MAX_PRINT_CHUNK);
277 + send_msg_buffer(&np, send_buffer, frag);
282 + send_msg_buffer(&np, send_cache, MAX_PRINT_CHUNK);
283 + send_cache_pos = 0;
284 + local_irq_restore(flags);
285 + total_len -= MAX_PRINT_CHUNK;
286 + left_len -= send_len;
289 + memcpy(send_cache + send_cache_pos, msg + (len -left_len), left_len);
290 + send_cache_pos += left_len;
293 +void netconsole_do_sysrq()
295 + struct pt_regs regs;
296 + unsigned long flags;
298 + handle_sysrq_progress = 1;
300 + get_current_regs(®s);
301 + handle_sysrq((int)req.from, ®s, NULL);
303 + if (send_cache_pos != 0){
304 + local_irq_save(flags);
305 + send_msg_buffer(&np, send_cache, send_cache_pos);
306 + send_cache_pos = 0;
307 + local_irq_restore(flags);
310 + handle_sysrq_progress = 0;
311 + Clear_Sysrq_mode();
313 +static void rx_hook(struct netpoll *np, int port, char *msg, int len)
315 + /* add sysrq support */
318 + if (handle_sysrq_progress)
320 + __req = (req_t *)(msg);
321 + if(len < (sizeof(req_t)))
324 + if ((ntohl(__req->command) != COMM_SYSRQ))
326 + /*FIXME should check magic, but did not have good ways*/
328 + req.magic = ntohl(__req->magic);
329 + req.command = ntohl(__req->command);
330 + req.from = ntohl(__req->from);
331 + req.to = ntohl(__req->to);
332 + req.nr = ntohl(__req->nr);
333 + netconsole_sysrq_req = 1;
338 +static struct console netconsole = {
339 + .flags = CON_ENABLED | CON_PRINTBUFFER,
343 +static int option_setup(char *opt)
345 + return netpoll_parse_options(&np, opt);
348 +__setup("netconsole=", option_setup);
350 +static int init_netconsole(void)
352 + if(strlen(config) && option_setup(config))
355 + if(!np.remote_ip || netpoll_setup(&np))
357 + register_console(&netconsole);
358 + printk(KERN_INFO "netconsole: network logging started\n");
362 +static void cleanup_netconsole(void)
364 + unregister_console(&netconsole);
365 + netpoll_cleanup(&np);
368 +module_init(init_netconsole);
369 +module_exit(cleanup_netconsole);
370 --- /dev/null 2003-01-30 13:24:37.000000000 +0300
371 +++ linux-2.6.0-test6-alexey/include/asm-i386/netconsole.h 2003-10-14 17:45:08.000000000 +0400
373 +extern unsigned int netconsole_sysrq_req;
374 +extern void netconsole_do_sysrq(void);
375 +extern unsigned int netif_in_poll;
376 +#ifndef HANDLE_NETCONSOLE
377 +#define HANDLE_NETCONSOLE netconsole_do_sysrq()
379 --- linux-2.6.0-test6/net/core/dev.c~netconsole-over-netpoll 2003-10-14 17:45:03.000000000 +0400
380 +++ linux-2.6.0-test6-alexey/net/core/dev.c 2003-10-14 17:45:08.000000000 +0400
382 #include <linux/wireless.h> /* Note : will define WIRELESS_EXT */
383 #include <net/iw_handler.h>
384 #endif /* CONFIG_NET_RADIO */
385 +#include <asm/netconsole.h>
386 #include <asm/current.h>
389 @@ -1687,6 +1688,7 @@ static void net_rx_action(struct softirq
394 while (!list_empty(&queue->poll_list)) {
395 struct net_device *dev;
397 @@ -1711,6 +1713,7 @@ static void net_rx_action(struct softirq
405 --- linux-2.6.0-test6/net/Kconfig~netconsole-over-netpoll 2003-10-14 17:45:03.000000000 +0400
406 +++ linux-2.6.0-test6-alexey/net/Kconfig 2003-10-14 17:45:08.000000000 +0400
407 @@ -671,6 +671,6 @@ source "net/irda/Kconfig"
408 source "net/bluetooth/Kconfig"
412 + def_bool KGDB || NETCONSOLE