Lines Matching +full:target +full:- +full:module
1 // SPDX-License-Identifier: GPL-2.0-or-later
7 * This file contains the implementation of an IRQ-safe, crash-safe
13 * 2001-09-17 started by Ingo Molnar.
14 * 2003-08-11 2.6 port by Matt Mackall
17 * works non-modular
18 * 2003-09-07 rewritten with netpoll api
29 #include <linux/module.h>
49 MODULE_PARM_DESC(netconsole, " netconsole=[src-port]@[src-ip]/[dev],[tgt-port]@<tgt-ip>/[tgt-macadd…
55 #ifndef MODULE
62 #endif /* MODULE */
77 * struct netconsole_target - Represents a configured netconsole target.
78 * @list: Links this target into the target_list.
80 * @enabled: On / off knob to enable / disable target.
81 * Visible from userspace (read-write).
84 * Also, other parameters of a target may be modified at
86 * @np: The netpoll structure for this target.
88 * dev_name (read-write)
89 * local_port (read-write)
90 * remote_port (read-write)
91 * local_ip (read-write)
92 * remote_ip (read-write)
93 * local_mac (read-only)
94 * remote_mac (read-write)
124 * Targets that were created by parsing the boot/module option string
126 * never go away, so make these a no-op for them.
130 if (config_item_name(&nt->item)) in netconsole_target_get()
131 config_item_get(&nt->item); in netconsole_target_get()
136 if (config_item_name(&nt->item)) in netconsole_target_put()
137 config_item_put(&nt->item); in netconsole_target_put()
165 /* Allocate new target (from boot/module param) and setup netpoll for it */
168 int err = -ENOMEM; in alloc_param_target()
173 * Note that these targets get their config_item fields zeroed-out. in alloc_param_target()
179 nt->np.name = "netconsole"; in alloc_param_target()
180 strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ); in alloc_param_target()
181 nt->np.local_port = 6665; in alloc_param_target()
182 nt->np.remote_port = 6666; in alloc_param_target()
183 eth_broadcast_addr(nt->np.remote_mac); in alloc_param_target()
186 nt->extended = true; in alloc_param_target()
191 err = netpoll_parse_options(&nt->np, target_config); in alloc_param_target()
195 err = netpoll_setup(&nt->np); in alloc_param_target()
199 nt->enabled = true; in alloc_param_target()
208 /* Cleanup netpoll for given target (from boot/module param) and free it */
211 netpoll_cleanup(&nt->np); in free_param_target()
222 * <target>/
232 * <target>/...
248 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->enabled); in enabled_show()
253 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->extended); in extended_show()
258 return snprintf(buf, PAGE_SIZE, "%s\n", to_target(item)->np.dev_name); in dev_name_show()
263 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->np.local_port); in local_port_show()
268 return snprintf(buf, PAGE_SIZE, "%d\n", to_target(item)->np.remote_port); in remote_port_show()
275 if (nt->np.ipv6) in local_ip_show()
276 return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.local_ip.in6); in local_ip_show()
278 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.local_ip); in local_ip_show()
285 if (nt->np.ipv6) in remote_ip_show()
286 return snprintf(buf, PAGE_SIZE, "%pI6c\n", &nt->np.remote_ip.in6); in remote_ip_show()
288 return snprintf(buf, PAGE_SIZE, "%pI4\n", &nt->np.remote_ip); in remote_ip_show()
293 struct net_device *dev = to_target(item)->np.dev; in local_mac_show()
296 return snprintf(buf, PAGE_SIZE, "%pM\n", dev ? dev->dev_addr : bcast); in local_mac_show()
301 return snprintf(buf, PAGE_SIZE, "%pM\n", to_target(item)->np.remote_mac); in remote_mac_show()
305 * This one is special -- targets created through the configfs interface
324 err = -EINVAL; in enabled_store()
327 if ((bool)enabled == nt->enabled) { in enabled_store()
329 nt->enabled ? "started" : "stopped"); in enabled_store()
334 if (nt->extended && !(netconsole_ext.flags & CON_ENABLED)) { in enabled_store()
340 * Skip netpoll_parse_options() -- all the attributes are in enabled_store()
343 netpoll_print_options(&nt->np); in enabled_store()
345 err = netpoll_setup(&nt->np); in enabled_store()
353 * nt->np.dev == NULL and nt->enabled == true in enabled_store()
356 nt->enabled = false; in enabled_store()
358 netpoll_cleanup(&nt->np); in enabled_store()
361 nt->enabled = enabled; in enabled_store()
378 if (nt->enabled) { in extended_store()
379 pr_err("target (%s) is enabled, disable to update parameters\n", in extended_store()
380 config_item_name(&nt->item)); in extended_store()
381 err = -EINVAL; in extended_store()
389 err = -EINVAL; in extended_store()
393 nt->extended = extended; in extended_store()
409 if (nt->enabled) { in dev_name_store()
410 pr_err("target (%s) is enabled, disable to update parameters\n", in dev_name_store()
411 config_item_name(&nt->item)); in dev_name_store()
413 return -EINVAL; in dev_name_store()
416 strlcpy(nt->np.dev_name, buf, IFNAMSIZ); in dev_name_store()
419 len = strnlen(nt->np.dev_name, IFNAMSIZ); in dev_name_store()
420 if (nt->np.dev_name[len - 1] == '\n') in dev_name_store()
421 nt->np.dev_name[len - 1] = '\0'; in dev_name_store()
431 int rv = -EINVAL; in local_port_store()
434 if (nt->enabled) { in local_port_store()
435 pr_err("target (%s) is enabled, disable to update parameters\n", in local_port_store()
436 config_item_name(&nt->item)); in local_port_store()
440 rv = kstrtou16(buf, 10, &nt->np.local_port); in local_port_store()
454 int rv = -EINVAL; in remote_port_store()
457 if (nt->enabled) { in remote_port_store()
458 pr_err("target (%s) is enabled, disable to update parameters\n", in remote_port_store()
459 config_item_name(&nt->item)); in remote_port_store()
463 rv = kstrtou16(buf, 10, &nt->np.remote_port); in remote_port_store()
479 if (nt->enabled) { in local_ip_store()
480 pr_err("target (%s) is enabled, disable to update parameters\n", in local_ip_store()
481 config_item_name(&nt->item)); in local_ip_store()
487 if (in6_pton(buf, count, nt->np.local_ip.in6.s6_addr, -1, &end) > 0) { in local_ip_store()
492 nt->np.ipv6 = true; in local_ip_store()
496 if (!nt->np.ipv6) { in local_ip_store()
497 nt->np.local_ip.ip = in_aton(buf); in local_ip_store()
506 return -EINVAL; in local_ip_store()
515 if (nt->enabled) { in remote_ip_store()
516 pr_err("target (%s) is enabled, disable to update parameters\n", in remote_ip_store()
517 config_item_name(&nt->item)); in remote_ip_store()
523 if (in6_pton(buf, count, nt->np.remote_ip.in6.s6_addr, -1, &end) > 0) { in remote_ip_store()
528 nt->np.ipv6 = true; in remote_ip_store()
532 if (!nt->np.ipv6) { in remote_ip_store()
533 nt->np.remote_ip.ip = in_aton(buf); in remote_ip_store()
542 return -EINVAL; in remote_ip_store()
552 if (nt->enabled) { in remote_mac_store()
553 pr_err("target (%s) is enabled, disable to update parameters\n", in remote_mac_store()
554 config_item_name(&nt->item)); in remote_mac_store()
560 if (buf[3 * ETH_ALEN - 1] && buf[3 * ETH_ALEN - 1] != '\n') in remote_mac_store()
562 memcpy(nt->np.remote_mac, remote_mac, ETH_ALEN); in remote_mac_store()
568 return -EINVAL; in remote_mac_store()
625 * Target is disabled at creation (!enabled). in make_netconsole_target()
629 return ERR_PTR(-ENOMEM); in make_netconsole_target()
631 nt->np.name = "netconsole"; in make_netconsole_target()
632 strlcpy(nt->np.dev_name, "eth0", IFNAMSIZ); in make_netconsole_target()
633 nt->np.local_port = 6665; in make_netconsole_target()
634 nt->np.remote_port = 6666; in make_netconsole_target()
635 eth_broadcast_addr(nt->np.remote_mac); in make_netconsole_target()
638 config_item_init_type_name(&nt->item, name, &netconsole_target_type); in make_netconsole_target()
642 list_add(&nt->list, &target_list); in make_netconsole_target()
645 return &nt->item; in make_netconsole_target()
655 list_del(&nt->list); in drop_netconsole_target()
659 * The target may have never been enabled, or was manually disabled in drop_netconsole_target()
662 if (nt->enabled) in drop_netconsole_target()
663 netpoll_cleanup(&nt->np); in drop_netconsole_target()
665 config_item_put(&nt->item); in drop_netconsole_target()
707 if (nt->np.dev == dev) { in netconsole_netdev_event()
710 strlcpy(nt->np.dev_name, dev->name, IFNAMSIZ); in netconsole_netdev_event()
720 __netpoll_cleanup(&nt->np); in netconsole_netdev_event()
723 dev_put(nt->np.dev); in netconsole_netdev_event()
724 nt->np.dev = NULL; in netconsole_netdev_event()
725 nt->enabled = false; in netconsole_netdev_event()
748 dev->name, msg); in netconsole_netdev_event()
760 * send_ext_msg_udp - send extended log message to target
761 * @nt: target to send message to
778 netpoll_send_udp(&nt->np, msg, msg_len); in send_ext_msg_udp()
788 header_len = body - header; in send_ext_msg_udp()
789 body_len = msg_len - header_len - 1; in send_ext_msg_udp()
794 * "ncfrag=<byte-offset>/<total-bytes>" in send_ext_msg_udp()
803 sizeof(buf) - this_header, in send_ext_msg_udp()
806 this_chunk = min(body_len - offset, in send_ext_msg_udp()
807 MAX_PRINT_CHUNK - this_header); in send_ext_msg_udp()
813 netpoll_send_udp(&nt->np, buf, this_header + this_chunk); in send_ext_msg_udp()
830 if (nt->extended && nt->enabled && netif_running(nt->np.dev)) in write_ext_msg()
850 if (!nt->extended && nt->enabled && netif_running(nt->np.dev)) { in write_msg()
852 * We nest this inside the for-each-target loop above in write_msg()
854 * at least one target if we die inside here, instead in write_msg()
855 * of unnecessarily keeping all targets in lock-step. in write_msg()
860 netpoll_send_udp(&nt->np, tmp, frag); in write_msg()
862 left -= frag; in write_msg()
897 if (nt->extended) in init_netconsole()
904 list_add(&nt->list, &target_list); in init_netconsole()
932 * from the boot/module option exist here). Skipping the list in init_netconsole()
936 list_del(&nt->list); in init_netconsole()
953 * Targets created via configfs pin references on our module in cleanup_netconsole()
956 * created from the boot/module option are left, so remove and in cleanup_netconsole()
961 list_del(&nt->list); in cleanup_netconsole()
968 * initialized after network device driver if built-in.
970 * late_initcall() and module_init() are identical if built as module.