netdev-notifier-error-inject.c 1.5 KB

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