Back to home page

LXR

 
 

    


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