netconsole.c 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130
  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. * This program is free software; you can redistribute it and/or modify
  21. * it under the terms of the GNU General Public License as published by
  22. * the Free Software Foundation; either version 2, or (at your option)
  23. * any later version.
  24. *
  25. * This program is distributed in the hope that it will be useful,
  26. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  27. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  28. * GNU General Public License for more details.
  29. *
  30. * You should have received a copy of the GNU General Public License
  31. * along with this program; if not, write to the Free Software
  32. * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  33. *
  34. ****************************************************************/
  35. #include <linux/mm.h>
  36. #include <linux/tty.h>
  37. #include <linux/init.h>
  38. #include <linux/module.h>
  39. #include <linux/console.h>
  40. #include <linux/tty_driver.h>
  41. #include <linux/moduleparam.h>
  42. #include <linux/string.h>
  43. #include <linux/sysrq.h>
  44. #include <linux/smp.h>
  45. #include <linux/netpoll.h>
  46. MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
  47. MODULE_DESCRIPTION("Console driver for network interfaces");
  48. MODULE_LICENSE("GPL");
  49. static char config[256];
  50. module_param_string(netconsole, config, 256, 0);
  51. MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]\n");
  52. static struct netpoll np = {
  53. .name = "netconsole",
  54. .dev_name = "eth0",
  55. .local_port = 6665,
  56. .remote_port = 6666,
  57. .remote_mac = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff},
  58. };
  59. static int configured = 0;
  60. #define MAX_PRINT_CHUNK 1000
  61. static void write_msg(struct console *con, const char *msg, unsigned int len)
  62. {
  63. int frag, left;
  64. unsigned long flags;
  65. if (!np.dev)
  66. return;
  67. local_irq_save(flags);
  68. for(left = len; left; ) {
  69. frag = min(left, MAX_PRINT_CHUNK);
  70. netpoll_send_udp(&np, msg, frag);
  71. msg += frag;
  72. left -= frag;
  73. }
  74. local_irq_restore(flags);
  75. }
  76. static struct console netconsole = {
  77. .name = "netcon",
  78. .flags = CON_ENABLED | CON_PRINTBUFFER,
  79. .write = write_msg
  80. };
  81. static int option_setup(char *opt)
  82. {
  83. configured = !netpoll_parse_options(&np, opt);
  84. return 1;
  85. }
  86. __setup("netconsole=", option_setup);
  87. static int init_netconsole(void)
  88. {
  89. int err;
  90. if(strlen(config))
  91. option_setup(config);
  92. if(!configured) {
  93. printk("netconsole: not configured, aborting\n");
  94. return 0;
  95. }
  96. err = netpoll_setup(&np);
  97. if (err)
  98. return err;
  99. register_console(&netconsole);
  100. printk(KERN_INFO "netconsole: network logging started\n");
  101. return 0;
  102. }
  103. static void cleanup_netconsole(void)
  104. {
  105. unregister_console(&netconsole);
  106. netpoll_cleanup(&np);
  107. }
  108. module_init(init_netconsole);
  109. module_exit(cleanup_netconsole);