| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 38 | #include <linux/init.h> |
| 39 | #include <linux/module.h> |
| 40 | #include <linux/console.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 41 | #include <linux/moduleparam.h> |
| 42 | #include <linux/string.h> |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 43 | #include <linux/netpoll.h> |
| 44 | |
| 45 | MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>"); |
| 46 | MODULE_DESCRIPTION("Console driver for network interfaces"); |
| 47 | MODULE_LICENSE("GPL"); |
| 48 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 49 | #define MAX_PARAM_LENGTH 256 |
| 50 | #define MAX_PRINT_CHUNK 1000 |
| 51 | |
| 52 | static char config[MAX_PARAM_LENGTH]; |
| 53 | module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0); |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 54 | MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n"); |
| 55 | |
| 56 | static struct netpoll np = { |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 57 | .name = "netconsole", |
| 58 | .dev_name = "eth0", |
| 59 | .local_port = 6665, |
| 60 | .remote_port = 6666, |
| 61 | .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 62 | }; |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 63 | static int configured; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 64 | |
| 65 | static void write_msg(struct console *con, const char *msg, unsigned int len) |
| 66 | { |
| 67 | int frag, left; |
| 68 | unsigned long flags; |
| 69 | |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | local_irq_save(flags); |
| 71 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 72 | for (left = len; left;) { |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 73 | frag = min(left, MAX_PRINT_CHUNK); |
| 74 | netpoll_send_udp(&np, msg, frag); |
| 75 | msg += frag; |
| 76 | left -= frag; |
| 77 | } |
| 78 | |
| 79 | local_irq_restore(flags); |
| 80 | } |
| 81 | |
| 82 | static struct console netconsole = { |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 83 | .name = "netcon", |
| 84 | .flags = CON_ENABLED | CON_PRINTBUFFER, |
| 85 | .write = write_msg, |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 86 | }; |
| 87 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 88 | static int __init option_setup(char *opt) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 89 | { |
| 90 | configured = !netpoll_parse_options(&np, opt); |
| OGAWA Hirofumi | 9b41046 | 2006-03-31 02:30:33 -0800 | [diff] [blame] | 91 | return 1; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 92 | } |
| 93 | |
| 94 | __setup("netconsole=", option_setup); |
| 95 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 96 | static int __init init_netconsole(void) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 97 | { |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 98 | int err = 0; |
| Stephen Hemminger | b41848b | 2006-10-26 15:46:52 -0700 | [diff] [blame] | 99 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 100 | if (strnlen(config, MAX_PARAM_LENGTH)) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 101 | option_setup(config); |
| 102 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 103 | if (!configured) { |
| 104 | printk(KERN_INFO "netconsole: not configured, aborting\n"); |
| 105 | goto out; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 106 | } |
| 107 | |
| Stephen Hemminger | b41848b | 2006-10-26 15:46:52 -0700 | [diff] [blame] | 108 | err = netpoll_setup(&np); |
| 109 | if (err) |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 110 | goto out; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 111 | |
| 112 | register_console(&netconsole); |
| 113 | printk(KERN_INFO "netconsole: network logging started\n"); |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 114 | |
| 115 | out: |
| 116 | return err; |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | } |
| 118 | |
| Satyam Sharma | d39badf | 2007-08-10 15:27:24 -0700 | [diff] [blame] | 119 | static void __exit cleanup_netconsole(void) |
| Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 120 | { |
| 121 | unregister_console(&netconsole); |
| 122 | netpoll_cleanup(&np); |
| 123 | } |
| 124 | |
| 125 | module_init(init_netconsole); |
| 126 | module_exit(cleanup_netconsole); |