1 #include <linux/kernel.h> 2 #include <linux/module.h> 3 #include <linux/netdevice.h> 4 5 #include "notifier-error-inject.h" 6 7 static int priority; 8 module_param(priority, int, 0); 9 MODULE_PARM_DESC(priority, "specify netdevice notifier priority"); 10 11 static struct notifier_err_inject netdev_notifier_err_inject = { 12 .actions = { 13 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_REGISTER) }, 14 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEMTU) }, 15 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGENAME) }, 16 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRE_UP) }, 17 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRE_TYPE_CHANGE) }, 18 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_POST_INIT) }, 19 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRECHANGEMTU) }, 20 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_PRECHANGEUPPER) }, 21 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEUPPER) }, 22 {} 23 } 24 }; 25 26 static struct dentry *dir; 27 28 static int netdev_err_inject_init(void) 29 { 30 int err; 31 32 dir = notifier_err_inject_init("netdev", notifier_err_inject_dir, 33 &netdev_notifier_err_inject, priority); 34 if (IS_ERR(dir)) 35 return PTR_ERR(dir); 36 37 err = register_netdevice_notifier(&netdev_notifier_err_inject.nb); 38 if (err) 39 debugfs_remove_recursive(dir); 40 41 return err; 42 } 43 44 static void netdev_err_inject_exit(void) 45 { 46 unregister_netdevice_notifier(&netdev_notifier_err_inject.nb); 47 debugfs_remove_recursive(dir); 48 } 49 50 module_init(netdev_err_inject_init); 51 module_exit(netdev_err_inject_exit); 52 53 MODULE_DESCRIPTION("Netdevice notifier error injection module"); 54 MODULE_LICENSE("GPL"); 55 MODULE_AUTHOR("Nikolay Aleksandrov <razor@blackwall.org>"); 56