blob: 69233f6aa05ca2d115f77ed3c71d00954c5c0204 [file] [log] [blame]
Linus Torvalds1da177e2005-04-16 15:20:36 -07001/*
2 * linux/drivers/net/netconsole.c
3 *
4 * Copyright (C) 2001 Ingo Molnar <mingo@redhat.com>
5 *
6 * This file contains the implementation of an IRQ-safe, crash-safe
7 * kernel console implementation that outputs kernel messages to the
8 * network.
9 *
10 * Modification history:
11 *
12 * 2001-09-17 started by Ingo Molnar.
13 * 2003-08-11 2.6 port by Matt Mackall
14 * simplified options
15 * generic card hooks
16 * works non-modular
17 * 2003-09-07 rewritten with netpoll api
18 */
19
20/****************************************************************
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2, or (at your option)
24 * any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 *
35 ****************************************************************/
36
37#include <linux/mm.h>
38#include <linux/tty.h>
39#include <linux/init.h>
40#include <linux/module.h>
41#include <linux/console.h>
42#include <linux/tty_driver.h>
43#include <linux/moduleparam.h>
44#include <linux/string.h>
45#include <linux/sysrq.h>
46#include <linux/smp.h>
47#include <linux/netpoll.h>
48
49MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
50MODULE_DESCRIPTION("Console driver for network interfaces");
51MODULE_LICENSE("GPL");
52
53static char config[256];
54module_param_string(netconsole, config, 256, 0);
55MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n");
56
57static struct netpoll np = {
58 .name = "netconsole",
59 .dev_name = "eth0",
60 .local_port = 6665,
61 .remote_port = 6666,
62 .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
Linus Torvalds1da177e2005-04-16 15:20:36 -070063};
64static int configured = 0;
65
66#define MAX_PRINT_CHUNK 1000
67
68static void write_msg(struct console *con, const char *msg, unsigned int len)
69{
70 int frag, left;
71 unsigned long flags;
72
73 if (!np.dev)
74 return;
75
76 local_irq_save(flags);
77
78 for(left = len; left; ) {
79 frag = min(left, MAX_PRINT_CHUNK);
80 netpoll_send_udp(&np, msg, frag);
81 msg += frag;
82 left -= frag;
83 }
84
85 local_irq_restore(flags);
86}
87
88static struct console netconsole = {
Randy Dunlapd938ab42006-04-04 20:11:56 -070089 .name = "netcon",
Linus Torvalds1da177e2005-04-16 15:20:36 -070090 .flags = CON_ENABLED | CON_PRINTBUFFER,
91 .write = write_msg
92};
93
94static int option_setup(char *opt)
95{
96 configured = !netpoll_parse_options(&np, opt);
OGAWA Hirofumi9b410462006-03-31 02:30:33 -080097 return 1;
Linus Torvalds1da177e2005-04-16 15:20:36 -070098}
99
100__setup("netconsole=", option_setup);
101
102static int init_netconsole(void)
103{
Stephen Hemmingerb41848b2006-10-26 15:46:52 -0700104 int err;
105
Linus Torvalds1da177e2005-04-16 15:20:36 -0700106 if(strlen(config))
107 option_setup(config);
108
109 if(!configured) {
110 printk("netconsole: not configured, aborting\n");
Matt Mackall92cd6ee2006-06-05 15:04:37 -0700111 return 0;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700112 }
113
Stephen Hemmingerb41848b2006-10-26 15:46:52 -0700114 err = netpoll_setup(&np);
115 if (err)
116 return err;
Linus Torvalds1da177e2005-04-16 15:20:36 -0700117
118 register_console(&netconsole);
119 printk(KERN_INFO "netconsole: network logging started\n");
120 return 0;
121}
122
123static void cleanup_netconsole(void)
124{
125 unregister_console(&netconsole);
126 netpoll_cleanup(&np);
127}
128
129module_init(init_netconsole);
130module_exit(cleanup_netconsole);