* Called upon system init or kld load. Initializes the netdump parameters to * sane defaults (locates the first available NIC and uses the first IPv4 IP on * that card as the client IP). Leaves the server IP unconfigured. * * Parameters: * mod, Unused. * what, The module event type. * priv, Unused. * * Returns: * int, An errno value if an error occured, 0 otherwise. */
| 671 | * int, An errno value if an error occured, 0 otherwise. |
| 672 | */ |
| 673 | static int |
| 674 | netdump_modevent(module_t mod __unused, int what, void *priv __unused) |
| 675 | { |
| 676 | struct diocskerneldump_arg conf; |
| 677 | char *arg; |
| 678 | int error; |
| 679 | |
| 680 | error = 0; |
| 681 | switch (what) { |
| 682 | case MOD_LOAD: |
| 683 | error = make_dev_p(MAKEDEV_WAITOK, &netdump_cdev, |
| 684 | &netdump_cdevsw, 0, UID_ROOT, GID_WHEEL, 0600, "netdump"); |
| 685 | if (error != 0) |
| 686 | return (error); |
| 687 | |
| 688 | nd_detach_cookie = EVENTHANDLER_REGISTER(ifnet_departure_event, |
| 689 | netdump_ifdetach, NULL, EVENTHANDLER_PRI_ANY); |
| 690 | |
| 691 | if ((arg = kern_getenv("net.dump.iface")) != NULL) { |
| 692 | strlcpy(conf.kda_iface, arg, sizeof(conf.kda_iface)); |
| 693 | freeenv(arg); |
| 694 | |
| 695 | if ((arg = kern_getenv("net.dump.server")) != NULL) { |
| 696 | inet_aton(arg, &conf.kda_server.in4); |
| 697 | freeenv(arg); |
| 698 | } |
| 699 | if ((arg = kern_getenv("net.dump.client")) != NULL) { |
| 700 | inet_aton(arg, &conf.kda_client.in4); |
| 701 | freeenv(arg); |
| 702 | } |
| 703 | if ((arg = kern_getenv("net.dump.gateway")) != NULL) { |
| 704 | inet_aton(arg, &conf.kda_gateway.in4); |
| 705 | freeenv(arg); |
| 706 | } |
| 707 | conf.kda_af = AF_INET; |
| 708 | |
| 709 | /* Ignore errors; we print a message to the console. */ |
| 710 | NETDUMP_WLOCK(); |
| 711 | (void)netdump_configure(&conf, NULL); |
| 712 | NETDUMP_WUNLOCK(); |
| 713 | } |
| 714 | break; |
| 715 | case MOD_UNLOAD: |
| 716 | NETDUMP_WLOCK(); |
| 717 | if (netdump_enabled()) { |
| 718 | printf("netdump: disabling dump device for unload\n"); |
| 719 | netdump_unconfigure(); |
| 720 | } |
| 721 | NETDUMP_WUNLOCK(); |
| 722 | destroy_dev(netdump_cdev); |
| 723 | EVENTHANDLER_DEREGISTER(ifnet_departure_event, |
| 724 | nd_detach_cookie); |
| 725 | break; |
| 726 | default: |
| 727 | error = EOPNOTSUPP; |
| 728 | break; |
| 729 | } |
| 730 | return (error); |
nothing calls this directly
no test coverage detected