1 // SPDX-License-Identifier: GPL-2.0-or-later
3 * linux/drivers/net/netconsole.c
5 * Copyright (C) 2001 Ingo Molnar <mingo@redhat.com>
7 * This file contains the implementation of an IRQ-safe, crash-safe
8 * kernel console implementation that outputs kernel messages to the
11 * Modification history:
13 * 2001-09-17 started by Ingo Molnar.
14 * 2003-08-11 2.6 port by Matt Mackall
18 * 2003-09-07 rewritten with netpoll api
21 /****************************************************************
23 ****************************************************************/
25 #define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
28 #include <linux/init.h>
29 #include <linux/module.h>
30 #include <linux/slab.h>
31 #include <linux/console.h>
32 #include <linux/moduleparam.h>
33 #include <linux/kernel.h>
34 #include <linux/string.h>
35 #include <linux/netpoll.h>
36 #include <linux/inet.h>
37 #include <linux/configfs.h>
38 #include <linux/etherdevice.h>
39 #include <linux/utsname.h>
41 MODULE_AUTHOR("Maintainer: Matt Mackall <mpm@selenic.com>");
42 MODULE_DESCRIPTION("Console driver for network interfaces");
43 MODULE_LICENSE("GPL");
45 #define MAX_PARAM_LENGTH 256
46 #define MAX_PRINT_CHUNK 1000
48 static char config[MAX_PARAM_LENGTH];
49 module_param_string(netconsole, config, MAX_PARAM_LENGTH, 0);
50 MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macaddr]");
52 static bool oops_only = false;
53 module_param(oops_only, bool, 0600);
54 MODULE_PARM_DESC(oops_only, "Only log oops messages");
56 #define NETCONSOLE_PARAM_TARGET_PREFIX "cmdline"
59 static int __init option_setup(char *opt)
61 strscpy(config, opt, MAX_PARAM_LENGTH);
64 __setup("netconsole=", option_setup);
67 /* Linked list of all configured targets */
68 static LIST_HEAD(target_list);
70 /* This needs to be a spinlock because write_msg() cannot sleep */
71 static DEFINE_SPINLOCK(target_list_lock);
74 * Console driver for extended netconsoles. Registered on the first use to
75 * avoid unnecessarily enabling ext message formatting.
77 static struct console netconsole_ext;
80 * struct netconsole_target - Represents a configured netconsole target.
81 * @list: Links this target into the target_list.
82 * @item: Links us into the configfs subsystem hierarchy.
83 * @enabled: On / off knob to enable / disable target.
84 * Visible from userspace (read-write).
85 * We maintain a strict 1:1 correspondence between this and
86 * whether the corresponding netpoll is active or inactive.
87 * Also, other parameters of a target may be modified at
88 * runtime only when it is disabled (enabled == 0).
89 * @extended: Denotes whether console is extended or not.
90 * @release: Denotes whether kernel release version should be prepended
91 * to the message. Depends on extended console.
92 * @np: The netpoll structure for this target.
93 * Contains the other userspace visible parameters:
94 * dev_name (read-write)
95 * local_port (read-write)
96 * remote_port (read-write)
97 * local_ip (read-write)
98 * remote_ip (read-write)
99 * local_mac (read-only)
100 * remote_mac (read-write)
102 struct netconsole_target {
103 struct list_head list;
104 #ifdef CONFIG_NETCONSOLE_DYNAMIC
105 struct config_item item;
113 #ifdef CONFIG_NETCONSOLE_DYNAMIC
115 static struct configfs_subsystem netconsole_subsys;
116 static DEFINE_MUTEX(dynamic_netconsole_mutex);
118 static int __init dynamic_netconsole_init(void)
120 config_group_init(&netconsole_subsys.su_group);
121 mutex_init(&netconsole_subsys.su_mutex);
122 return configfs_register_subsystem(&netconsole_subsys);
125 static void __exit dynamic_netconsole_exit(void)
127 configfs_unregister_subsystem(&netconsole_subsys);
131 * Targets that were created by parsing the boot/module option string
132 * do not exist in the configfs hierarchy (and have NULL names) and will
133 * never go away, so make these a no-op for them.
135 static void netconsole_target_get(struct netconsole_target *nt)
137 if (config_item_name(&nt->item))
138 config_item_get(&nt->item);
141 static void netconsole_target_put(struct netconsole_target *nt)
143 if (config_item_name(&nt->item))
144 config_item_put(&nt->item);
147 #else /* !CONFIG_NETCONSOLE_DYNAMIC */
149 static int __init dynamic_netconsole_init(void)
154 static void __exit dynamic_netconsole_exit(void)
159 * No danger of targets going away from under us when dynamic
160 * reconfigurability is off.
162 static void netconsole_target_get(struct netconsole_target *nt)
166 static void netconsole_target_put(struct netconsole_target *nt)
170 static void populate_configfs_item(struct netconsole_target *nt,
174 #endif /* CONFIG_NETCONSOLE_DYNAMIC */
176 /* Allocate and initialize with defaults.
177 * Note that these targets get their config_item fields zeroed-out.
179 static struct netconsole_target *alloc_and_init(void)
181 struct netconsole_target *nt;
183 nt = kzalloc(sizeof(*nt), GFP_KERNEL);
187 if (IS_ENABLED(CONFIG_NETCONSOLE_EXTENDED_LOG))
189 if (IS_ENABLED(CONFIG_NETCONSOLE_PREPEND_RELEASE))
192 nt->np.name = "netconsole";
193 strscpy(nt->np.dev_name, "eth0", IFNAMSIZ);
194 nt->np.local_port = 6665;
195 nt->np.remote_port = 6666;
196 eth_broadcast_addr(nt->np.remote_mac);
201 #ifdef CONFIG_NETCONSOLE_DYNAMIC
204 * Our subsystem hierarchy is:
206 * /sys/kernel/config/netconsole/
222 static struct netconsole_target *to_target(struct config_item *item)
225 container_of(item, struct netconsole_target, item) :
230 * Attribute operations for netconsole_target.
233 static ssize_t enabled_show(struct config_item *item, char *buf)
235 return sysfs_emit(buf, "%d\n", to_target(item)->enabled);
238 static ssize_t extended_show(struct config_item *item, char *buf)
240 return sysfs_emit(buf, "%d\n", to_target(item)->extended);
243 static ssize_t release_show(struct config_item *item, char *buf)
245 return sysfs_emit(buf, "%d\n", to_target(item)->release);
248 static ssize_t dev_name_show(struct config_item *item, char *buf)
250 return sysfs_emit(buf, "%s\n", to_target(item)->np.dev_name);
253 static ssize_t local_port_show(struct config_item *item, char *buf)
255 return sysfs_emit(buf, "%d\n", to_target(item)->np.local_port);
258 static ssize_t remote_port_show(struct config_item *item, char *buf)
260 return sysfs_emit(buf, "%d\n", to_target(item)->np.remote_port);
263 static ssize_t local_ip_show(struct config_item *item, char *buf)
265 struct netconsole_target *nt = to_target(item);
268 return sysfs_emit(buf, "%pI6c\n", &nt->np.local_ip.in6);
270 return sysfs_emit(buf, "%pI4\n", &nt->np.local_ip);
273 static ssize_t remote_ip_show(struct config_item *item, char *buf)
275 struct netconsole_target *nt = to_target(item);
278 return sysfs_emit(buf, "%pI6c\n", &nt->np.remote_ip.in6);
280 return sysfs_emit(buf, "%pI4\n", &nt->np.remote_ip);
283 static ssize_t local_mac_show(struct config_item *item, char *buf)
285 struct net_device *dev = to_target(item)->np.dev;
286 static const u8 bcast[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
288 return sysfs_emit(buf, "%pM\n", dev ? dev->dev_addr : bcast);
291 static ssize_t remote_mac_show(struct config_item *item, char *buf)
293 return sysfs_emit(buf, "%pM\n", to_target(item)->np.remote_mac);
297 * This one is special -- targets created through the configfs interface
298 * are not enabled (and the corresponding netpoll activated) by default.
299 * The user is expected to set the desired parameters first (which
300 * would enable him to dynamically add new netpoll targets for new
301 * network interfaces as and when they come up).
303 static ssize_t enabled_store(struct config_item *item,
304 const char *buf, size_t count)
306 struct netconsole_target *nt = to_target(item);
311 mutex_lock(&dynamic_netconsole_mutex);
312 err = kstrtobool(buf, &enabled);
317 if ((bool)enabled == nt->enabled) {
318 pr_info("network logging has already %s\n",
319 nt->enabled ? "started" : "stopped");
323 if (enabled) { /* true */
324 if (nt->release && !nt->extended) {
325 pr_err("Not enabling netconsole. Release feature requires extended log message");
329 if (nt->extended && !console_is_registered(&netconsole_ext))
330 register_console(&netconsole_ext);
333 * Skip netpoll_parse_options() -- all the attributes are
334 * already configured via configfs. Just print them out.
336 netpoll_print_options(&nt->np);
338 err = netpoll_setup(&nt->np);
342 pr_info("network logging started\n");
344 /* We need to disable the netconsole before cleaning it up
345 * otherwise we might end up in write_msg() with
346 * nt->np.dev == NULL and nt->enabled == true
348 spin_lock_irqsave(&target_list_lock, flags);
350 spin_unlock_irqrestore(&target_list_lock, flags);
351 netpoll_cleanup(&nt->np);
354 nt->enabled = enabled;
356 mutex_unlock(&dynamic_netconsole_mutex);
357 return strnlen(buf, count);
359 mutex_unlock(&dynamic_netconsole_mutex);
363 static ssize_t release_store(struct config_item *item, const char *buf,
366 struct netconsole_target *nt = to_target(item);
370 mutex_lock(&dynamic_netconsole_mutex);
372 pr_err("target (%s) is enabled, disable to update parameters\n",
373 config_item_name(&nt->item));
378 err = kstrtobool(buf, &release);
382 nt->release = release;
384 mutex_unlock(&dynamic_netconsole_mutex);
385 return strnlen(buf, count);
387 mutex_unlock(&dynamic_netconsole_mutex);
391 static ssize_t extended_store(struct config_item *item, const char *buf,
394 struct netconsole_target *nt = to_target(item);
398 mutex_lock(&dynamic_netconsole_mutex);
400 pr_err("target (%s) is enabled, disable to update parameters\n",
401 config_item_name(&nt->item));
406 err = kstrtobool(buf, &extended);
410 nt->extended = extended;
412 mutex_unlock(&dynamic_netconsole_mutex);
413 return strnlen(buf, count);
415 mutex_unlock(&dynamic_netconsole_mutex);
419 static ssize_t dev_name_store(struct config_item *item, const char *buf,
422 struct netconsole_target *nt = to_target(item);
425 mutex_lock(&dynamic_netconsole_mutex);
427 pr_err("target (%s) is enabled, disable to update parameters\n",
428 config_item_name(&nt->item));
429 mutex_unlock(&dynamic_netconsole_mutex);
433 strscpy(nt->np.dev_name, buf, IFNAMSIZ);
435 /* Get rid of possible trailing newline from echo(1) */
436 len = strnlen(nt->np.dev_name, IFNAMSIZ);
437 if (nt->np.dev_name[len - 1] == '\n')
438 nt->np.dev_name[len - 1] = '\0';
440 mutex_unlock(&dynamic_netconsole_mutex);
441 return strnlen(buf, count);
444 static ssize_t local_port_store(struct config_item *item, const char *buf,
447 struct netconsole_target *nt = to_target(item);
450 mutex_lock(&dynamic_netconsole_mutex);
452 pr_err("target (%s) is enabled, disable to update parameters\n",
453 config_item_name(&nt->item));
457 rv = kstrtou16(buf, 10, &nt->np.local_port);
460 mutex_unlock(&dynamic_netconsole_mutex);
461 return strnlen(buf, count);
463 mutex_unlock(&dynamic_netconsole_mutex);
467 static ssize_t remote_port_store(struct config_item *item,
468 const char *buf, size_t count)
470 struct netconsole_target *nt = to_target(item);
473 mutex_lock(&dynamic_netconsole_mutex);
475 pr_err("target (%s) is enabled, disable to update parameters\n",
476 config_item_name(&nt->item));
480 rv = kstrtou16(buf, 10, &nt->np.remote_port);
483 mutex_unlock(&dynamic_netconsole_mutex);
484 return strnlen(buf, count);
486 mutex_unlock(&dynamic_netconsole_mutex);
490 static ssize_t local_ip_store(struct config_item *item, const char *buf,
493 struct netconsole_target *nt = to_target(item);
495 mutex_lock(&dynamic_netconsole_mutex);
497 pr_err("target (%s) is enabled, disable to update parameters\n",
498 config_item_name(&nt->item));
502 if (strnchr(buf, count, ':')) {
504 if (in6_pton(buf, count, nt->np.local_ip.in6.s6_addr, -1, &end) > 0) {
505 if (*end && *end != '\n') {
506 pr_err("invalid IPv6 address at: <%c>\n", *end);
514 nt->np.local_ip.ip = in_aton(buf);
519 mutex_unlock(&dynamic_netconsole_mutex);
520 return strnlen(buf, count);
522 mutex_unlock(&dynamic_netconsole_mutex);
526 static ssize_t remote_ip_store(struct config_item *item, const char *buf,
529 struct netconsole_target *nt = to_target(item);
531 mutex_lock(&dynamic_netconsole_mutex);
533 pr_err("target (%s) is enabled, disable to update parameters\n",
534 config_item_name(&nt->item));
538 if (strnchr(buf, count, ':')) {
540 if (in6_pton(buf, count, nt->np.remote_ip.in6.s6_addr, -1, &end) > 0) {
541 if (*end && *end != '\n') {
542 pr_err("invalid IPv6 address at: <%c>\n", *end);
550 nt->np.remote_ip.ip = in_aton(buf);
555 mutex_unlock(&dynamic_netconsole_mutex);
556 return strnlen(buf, count);
558 mutex_unlock(&dynamic_netconsole_mutex);
562 static ssize_t remote_mac_store(struct config_item *item, const char *buf,
565 struct netconsole_target *nt = to_target(item);
566 u8 remote_mac[ETH_ALEN];
568 mutex_lock(&dynamic_netconsole_mutex);
570 pr_err("target (%s) is enabled, disable to update parameters\n",
571 config_item_name(&nt->item));
575 if (!mac_pton(buf, remote_mac))
577 if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n')
579 memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN);
581 mutex_unlock(&dynamic_netconsole_mutex);
582 return strnlen(buf, count);
584 mutex_unlock(&dynamic_netconsole_mutex);
588 CONFIGFS_ATTR(, enabled);
589 CONFIGFS_ATTR(, extended);
590 CONFIGFS_ATTR(, dev_name);
591 CONFIGFS_ATTR(, local_port);
592 CONFIGFS_ATTR(, remote_port);
593 CONFIGFS_ATTR(, local_ip);
594 CONFIGFS_ATTR(, remote_ip);
595 CONFIGFS_ATTR_RO(, local_mac);
596 CONFIGFS_ATTR(, remote_mac);
597 CONFIGFS_ATTR(, release);
599 static struct configfs_attribute *netconsole_target_attrs[] = {
614 * Item operations and type for netconsole_target.
617 static void netconsole_target_release(struct config_item *item)
619 kfree(to_target(item));
622 static struct configfs_item_operations netconsole_target_item_ops = {
623 .release = netconsole_target_release,
626 static const struct config_item_type netconsole_target_type = {
627 .ct_attrs = netconsole_target_attrs,
628 .ct_item_ops = &netconsole_target_item_ops,
629 .ct_owner = THIS_MODULE,
632 static struct netconsole_target *find_cmdline_target(const char *name)
634 struct netconsole_target *nt, *ret = NULL;
637 spin_lock_irqsave(&target_list_lock, flags);
638 list_for_each_entry(nt, &target_list, list) {
639 if (!strcmp(nt->item.ci_name, name)) {
644 spin_unlock_irqrestore(&target_list_lock, flags);
650 * Group operations and type for netconsole_subsys.
653 static struct config_item *make_netconsole_target(struct config_group *group,
656 struct netconsole_target *nt;
659 /* Checking if a target by this name was created at boot time. If so,
660 * attach a configfs entry to that target. This enables dynamic
663 if (!strncmp(name, NETCONSOLE_PARAM_TARGET_PREFIX,
664 strlen(NETCONSOLE_PARAM_TARGET_PREFIX))) {
665 nt = find_cmdline_target(name);
670 nt = alloc_and_init();
672 return ERR_PTR(-ENOMEM);
674 /* Initialize the config_item member */
675 config_item_init_type_name(&nt->item, name, &netconsole_target_type);
677 /* Adding, but it is disabled */
678 spin_lock_irqsave(&target_list_lock, flags);
679 list_add(&nt->list, &target_list);
680 spin_unlock_irqrestore(&target_list_lock, flags);
685 static void drop_netconsole_target(struct config_group *group,
686 struct config_item *item)
689 struct netconsole_target *nt = to_target(item);
691 spin_lock_irqsave(&target_list_lock, flags);
693 spin_unlock_irqrestore(&target_list_lock, flags);
696 * The target may have never been enabled, or was manually disabled
697 * before being removed so netpoll may have already been cleaned up.
700 netpoll_cleanup(&nt->np);
702 config_item_put(&nt->item);
705 static struct configfs_group_operations netconsole_subsys_group_ops = {
706 .make_item = make_netconsole_target,
707 .drop_item = drop_netconsole_target,
710 static const struct config_item_type netconsole_subsys_type = {
711 .ct_group_ops = &netconsole_subsys_group_ops,
712 .ct_owner = THIS_MODULE,
715 /* The netconsole configfs subsystem */
716 static struct configfs_subsystem netconsole_subsys = {
719 .ci_namebuf = "netconsole",
720 .ci_type = &netconsole_subsys_type,
725 static void populate_configfs_item(struct netconsole_target *nt,
728 char target_name[16];
730 snprintf(target_name, sizeof(target_name), "%s%d",
731 NETCONSOLE_PARAM_TARGET_PREFIX, cmdline_count);
732 config_item_init_type_name(&nt->item, target_name,
733 &netconsole_target_type);
736 #endif /* CONFIG_NETCONSOLE_DYNAMIC */
738 /* Handle network interface device notifications */
739 static int netconsole_netdev_event(struct notifier_block *this,
740 unsigned long event, void *ptr)
743 struct netconsole_target *nt;
744 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
745 bool stopped = false;
747 if (!(event == NETDEV_CHANGENAME || event == NETDEV_UNREGISTER ||
748 event == NETDEV_RELEASE || event == NETDEV_JOIN))
751 spin_lock_irqsave(&target_list_lock, flags);
753 list_for_each_entry(nt, &target_list, list) {
754 netconsole_target_get(nt);
755 if (nt->np.dev == dev) {
757 case NETDEV_CHANGENAME:
758 strscpy(nt->np.dev_name, dev->name, IFNAMSIZ);
762 case NETDEV_UNREGISTER:
763 /* rtnl_lock already held
764 * we might sleep in __netpoll_cleanup()
766 spin_unlock_irqrestore(&target_list_lock, flags);
768 __netpoll_cleanup(&nt->np);
770 spin_lock_irqsave(&target_list_lock, flags);
771 netdev_put(nt->np.dev, &nt->np.dev_tracker);
775 netconsole_target_put(nt);
779 netconsole_target_put(nt);
781 spin_unlock_irqrestore(&target_list_lock, flags);
783 const char *msg = "had an event";
785 case NETDEV_UNREGISTER:
786 msg = "unregistered";
789 msg = "released slaves";
792 msg = "is joining a master device";
795 pr_info("network logging stopped on interface %s as it %s\n",
803 static struct notifier_block netconsole_netdev_notifier = {
804 .notifier_call = netconsole_netdev_event,
808 * send_ext_msg_udp - send extended log message to target
809 * @nt: target to send message to
810 * @msg: extended log message to send
811 * @msg_len: length of message
813 * Transfer extended log @msg to @nt. If @msg is longer than
814 * MAX_PRINT_CHUNK, it'll be split and transmitted in multiple chunks with
815 * ncfrag header field added to identify them.
817 static void send_ext_msg_udp(struct netconsole_target *nt, const char *msg,
820 static char buf[MAX_PRINT_CHUNK]; /* protected by target_list_lock */
821 const char *header, *body;
823 int header_len, body_len;
824 const char *msg_ready = msg;
829 release = init_utsname()->release;
830 release_len = strlen(release) + 1;
833 if (msg_len + release_len <= MAX_PRINT_CHUNK) {
834 /* No fragmentation needed */
836 scnprintf(buf, MAX_PRINT_CHUNK, "%s,%s", release, msg);
837 msg_len += release_len;
840 netpoll_send_udp(&nt->np, msg_ready, msg_len);
844 /* need to insert extra header fields, detect header and body */
846 body = memchr(msg, ';', msg_len);
847 if (WARN_ON_ONCE(!body))
850 header_len = body - header;
851 body_len = msg_len - header_len - 1;
855 * Transfer multiple chunks with the following extra header.
856 * "ncfrag=<byte-offset>/<total-bytes>"
859 scnprintf(buf, MAX_PRINT_CHUNK, "%s,", release);
860 memcpy(buf + release_len, header, header_len);
861 header_len += release_len;
863 while (offset < body_len) {
864 int this_header = header_len;
867 this_header += scnprintf(buf + this_header,
868 sizeof(buf) - this_header,
869 ",ncfrag=%d/%d;", offset, body_len);
871 this_chunk = min(body_len - offset,
872 MAX_PRINT_CHUNK - this_header);
873 if (WARN_ON_ONCE(this_chunk <= 0))
876 memcpy(buf + this_header, body + offset, this_chunk);
878 netpoll_send_udp(&nt->np, buf, this_header + this_chunk);
880 offset += this_chunk;
884 static void write_ext_msg(struct console *con, const char *msg,
887 struct netconsole_target *nt;
890 if ((oops_only && !oops_in_progress) || list_empty(&target_list))
893 spin_lock_irqsave(&target_list_lock, flags);
894 list_for_each_entry(nt, &target_list, list)
895 if (nt->extended && nt->enabled && netif_running(nt->np.dev))
896 send_ext_msg_udp(nt, msg, len);
897 spin_unlock_irqrestore(&target_list_lock, flags);
900 static void write_msg(struct console *con, const char *msg, unsigned int len)
904 struct netconsole_target *nt;
907 if (oops_only && !oops_in_progress)
909 /* Avoid taking lock and disabling interrupts unnecessarily */
910 if (list_empty(&target_list))
913 spin_lock_irqsave(&target_list_lock, flags);
914 list_for_each_entry(nt, &target_list, list) {
915 if (!nt->extended && nt->enabled && netif_running(nt->np.dev)) {
917 * We nest this inside the for-each-target loop above
918 * so that we're able to get as much logging out to
919 * at least one target if we die inside here, instead
920 * of unnecessarily keeping all targets in lock-step.
923 for (left = len; left;) {
924 frag = min(left, MAX_PRINT_CHUNK);
925 netpoll_send_udp(&nt->np, tmp, frag);
931 spin_unlock_irqrestore(&target_list_lock, flags);
934 /* Allocate new target (from boot/module param) and setup netpoll for it */
935 static struct netconsole_target *alloc_param_target(char *target_config,
938 struct netconsole_target *nt;
941 nt = alloc_and_init();
947 if (*target_config == '+') {
952 if (*target_config == 'r') {
954 pr_err("Netconsole configuration error. Release feature requires extended log message");
962 /* Parse parameters and setup netpoll */
963 err = netpoll_parse_options(&nt->np, target_config);
967 err = netpoll_setup(&nt->np);
971 populate_configfs_item(nt, cmdline_count);
981 /* Cleanup netpoll for given target (from boot/module param) and free it */
982 static void free_param_target(struct netconsole_target *nt)
984 netpoll_cleanup(&nt->np);
988 static struct console netconsole_ext = {
989 .name = "netcon_ext",
990 .flags = CON_ENABLED | CON_EXTENDED,
991 .write = write_ext_msg,
994 static struct console netconsole = {
996 .flags = CON_ENABLED,
1000 static int __init init_netconsole(void)
1003 struct netconsole_target *nt, *tmp;
1004 unsigned int count = 0;
1005 bool extended = false;
1006 unsigned long flags;
1007 char *target_config;
1008 char *input = config;
1010 if (strnlen(input, MAX_PARAM_LENGTH)) {
1011 while ((target_config = strsep(&input, ";"))) {
1012 nt = alloc_param_target(target_config, count);
1017 /* Dump existing printks when we register */
1020 netconsole_ext.flags |= CON_PRINTBUFFER;
1022 netconsole.flags |= CON_PRINTBUFFER;
1025 spin_lock_irqsave(&target_list_lock, flags);
1026 list_add(&nt->list, &target_list);
1027 spin_unlock_irqrestore(&target_list_lock, flags);
1032 err = register_netdevice_notifier(&netconsole_netdev_notifier);
1036 err = dynamic_netconsole_init();
1041 register_console(&netconsole_ext);
1042 register_console(&netconsole);
1043 pr_info("network logging started\n");
1048 unregister_netdevice_notifier(&netconsole_netdev_notifier);
1051 pr_err("cleaning up\n");
1054 * Remove all targets and destroy them (only targets created
1055 * from the boot/module option exist here). Skipping the list
1056 * lock is safe here, and netpoll_cleanup() will sleep.
1058 list_for_each_entry_safe(nt, tmp, &target_list, list) {
1059 list_del(&nt->list);
1060 free_param_target(nt);
1066 static void __exit cleanup_netconsole(void)
1068 struct netconsole_target *nt, *tmp;
1070 if (console_is_registered(&netconsole_ext))
1071 unregister_console(&netconsole_ext);
1072 unregister_console(&netconsole);
1073 dynamic_netconsole_exit();
1074 unregister_netdevice_notifier(&netconsole_netdev_notifier);
1077 * Targets created via configfs pin references on our module
1078 * and would first be rmdir(2)'ed from userspace. We reach
1079 * here only when they are already destroyed, and only those
1080 * created from the boot/module option are left, so remove and
1081 * destroy them. Skipping the list lock is safe here, and
1082 * netpoll_cleanup() will sleep.
1084 list_for_each_entry_safe(nt, tmp, &target_list, list) {
1085 list_del(&nt->list);
1086 free_param_target(nt);
1091 * Use late_initcall to ensure netconsole is
1092 * initialized after network device driver if built-in.
1094 * late_initcall() and module_init() are identical if built as module.
1096 late_initcall(init_netconsole);
1097 module_exit(cleanup_netconsole);