blob: 13e9c62e216ff010bcace555da96daabb708fe67 [file] [log] [blame]
Nikolay Aleksandrov02fff962015-11-28 13:45:28 +01001#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/netdevice.h>
4
5#include "notifier-error-inject.h"
6
7static int priority;
8module_param(priority, int, 0);
9MODULE_PARM_DESC(priority, "specify netdevice notifier priority");
10
11static 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) },
Ido Schimmelc39d0452015-12-03 12:12:04 +010021 { NOTIFIER_ERR_INJECT_ACTION(NETDEV_CHANGEUPPER) },
Nikolay Aleksandrov02fff962015-11-28 13:45:28 +010022 {}
23 }
24};
25
26static struct dentry *dir;
27
28static 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
44static void netdev_err_inject_exit(void)
45{
46 unregister_netdevice_notifier(&netdev_notifier_err_inject.nb);
47 debugfs_remove_recursive(dir);
48}
49
50module_init(netdev_err_inject_init);
51module_exit(netdev_err_inject_exit);
52
53MODULE_DESCRIPTION("Netdevice notifier error injection module");
54MODULE_LICENSE("GPL");
55MODULE_AUTHOR("Nikolay Aleksandrov <razor@blackwall.org>");