Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 #include <linux/kernel.h>
0003 #include <linux/module.h>
0004 #include <linux/netdevice.h>
0005 
0006 #include "notifier-error-inject.h"
0007 
0008 static int priority;
0009 module_param(priority, int, 0);
0010 MODULE_PARM_DESC(priority, "specify netdevice notifier priority");
0011 
0012 static struct notifier_err_inject netdev_notifier_err_inject = {
0013     .actions = {
0014         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_REGISTER) },
0015         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEMTU) },
0016         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGENAME) },
0017         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRE_UP) },
0018         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRE_TYPE_CHANGE) },
0019         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_POST_INIT) },
0020         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRECHANGEMTU) },
0021         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRECHANGEUPPER) },
0022         { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEUPPER) },
0023         {}
0024     }
0025 };
0026 
0027 static struct dentry *dir;
0028 
0029 static int netdev_err_inject_init(void)
0030 {
0031     int err;
0032 
0033     dir = notifier_err_inject_init("netdev", notifier_err_inject_dir,
0034                        &netdev_notifier_err_inject, priority);
0035     if (IS_ERR(dir))
0036         return PTR_ERR(dir);
0037 
0038     err = register_netdevice_notifier(&netdev_notifier_err_inject.nb);
0039     if (err)
0040         debugfs_remove_recursive(dir);
0041 
0042     return err;
0043 }
0044 
0045 static void netdev_err_inject_exit(void)
0046 {
0047     unregister_netdevice_notifier(&netdev_notifier_err_inject.nb);
0048     debugfs_remove_recursive(dir);
0049 }
0050 
0051 module_init(netdev_err_inject_init);
0052 module_exit(netdev_err_inject_exit);
0053 
0054 MODULE_DESCRIPTION("Netdevice notifier error injection module");
0055 MODULE_LICENSE("GPL");
0056 MODULE_AUTHOR("Nikolay Aleksandrov <razor@blackwall.org>");