[NET] netconsole: Simplify boot/module option setup logic
[deliverable/linux.git] / drivers / net / netconsole.c
CommitLineData
1da177e4
LT
1/*
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>
1da177e4
LT
38#include <linux/init.h>
39#include <linux/module.h>
40#include <linux/console.h>
1da177e4
LT
41#include <linux/moduleparam.h>
42#include <linux/string.h>
1da177e4
LT
43#include <linux/netpoll.h>
44
45MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
46MODULE_DESCRIPTION("Console driver for network interfaces");
47MODULE_LICENSE("GPL");
48
d39badf0
SS
49#define MAX_PARAM_LENGTH 256
50#define MAX_PRINT_CHUNK 1000
51
52static char config[MAX_PARAM_LENGTH];
53module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0);
1da177e4
LT
54MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n");
55
d2b60881
SS
56#ifndef MODULE
57static int __init option_setup(char *opt)
58{
59 strlcpy(config, opt, MAX_PARAM_LENGTH);
60 return 1;
61}
62__setup("netconsole=", option_setup);
63#endif /* MODULE */
64
1da177e4 65static struct netpoll np = {
d39badf0
SS
66 .name = "netconsole",
67 .dev_name = "eth0",
68 .local_port = 6665,
69 .remote_port = 6666,
70 .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
1da177e4 71};
1da177e4
LT
72
73static void write_msg(struct console *con, const char *msg, unsigned int len)
74{
75 int frag, left;
76 unsigned long flags;
77
1da177e4
LT
78 local_irq_save(flags);
79
d39badf0 80 for (left = len; left;) {
1da177e4
LT
81 frag = min(left, MAX_PRINT_CHUNK);
82 netpoll_send_udp(&np, msg, frag);
83 msg += frag;
84 left -= frag;
85 }
86
87 local_irq_restore(flags);
88}
89
90static struct console netconsole = {
d39badf0
SS
91 .name = "netcon",
92 .flags = CON_ENABLED | CON_PRINTBUFFER,
93 .write = write_msg,
1da177e4
LT
94};
95
d39badf0 96static int __init init_netconsole(void)
1da177e4 97{
d39badf0 98 int err = 0;
b41848b6 99
d2b60881 100 if (!strnlen(config, MAX_PARAM_LENGTH)) {
d39badf0
SS
101 printk(KERN_INFO "netconsole: not configured, aborting\n");
102 goto out;
1da177e4
LT
103 }
104
d2b60881
SS
105 err = netpoll_parse_options(&np, config);
106 if (err)
107 goto out;
108
b41848b6
SH
109 err = netpoll_setup(&np);
110 if (err)
d39badf0 111 goto out;
1da177e4
LT
112
113 register_console(&netconsole);
114 printk(KERN_INFO "netconsole: network logging started\n");
d39badf0
SS
115
116out:
117 return err;
1da177e4
LT
118}
119
d39badf0 120static void __exit cleanup_netconsole(void)
1da177e4
LT
121{
122 unregister_console(&netconsole);
123 netpoll_cleanup(&np);
124}
125
126module_init(init_netconsole);
127module_exit(cleanup_netconsole);
This page took 0.28507 seconds and 5 git commands to generate.