1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /* Copyright Amazon.com Inc. or its affiliates. */
4 #include <linux/init.h>
5 #include <linux/netdevice.h>
6 #include <linux/notifier.h>
7 #include <linux/rtnetlink.h>
8 #include <net/net_namespace.h>
9 #include <net/netns/generic.h>
11 static int rtnl_net_debug_event(struct notifier_block *nb,
12 unsigned long event, void *ptr)
14 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
15 struct net *net = dev_net(dev);
16 enum netdev_cmd cmd = event;
18 /* Keep enum and don't add default to trigger -Werror=switch */
25 case NETDEV_UNREGISTER:
26 case NETDEV_CHANGEMTU:
27 case NETDEV_CHANGEADDR:
28 case NETDEV_PRE_CHANGEADDR:
29 case NETDEV_GOING_DOWN:
30 case NETDEV_FEAT_CHANGE:
31 case NETDEV_BONDING_FAILOVER:
33 case NETDEV_PRE_TYPE_CHANGE:
34 case NETDEV_POST_TYPE_CHANGE:
35 case NETDEV_POST_INIT:
36 case NETDEV_PRE_UNINIT:
38 case NETDEV_NOTIFY_PEERS:
40 case NETDEV_CHANGEUPPER:
41 case NETDEV_RESEND_IGMP:
42 case NETDEV_PRECHANGEMTU:
43 case NETDEV_CHANGEINFODATA:
44 case NETDEV_BONDING_INFO:
45 case NETDEV_PRECHANGEUPPER:
46 case NETDEV_CHANGELOWERSTATE:
47 case NETDEV_UDP_TUNNEL_PUSH_INFO:
48 case NETDEV_UDP_TUNNEL_DROP_INFO:
49 case NETDEV_CHANGE_TX_QUEUE_LEN:
50 case NETDEV_CVLAN_FILTER_PUSH_INFO:
51 case NETDEV_CVLAN_FILTER_DROP_INFO:
52 case NETDEV_SVLAN_FILTER_PUSH_INFO:
53 case NETDEV_SVLAN_FILTER_DROP_INFO:
54 case NETDEV_OFFLOAD_XSTATS_ENABLE:
55 case NETDEV_OFFLOAD_XSTATS_DISABLE:
56 case NETDEV_OFFLOAD_XSTATS_REPORT_USED:
57 case NETDEV_OFFLOAD_XSTATS_REPORT_DELTA:
58 case NETDEV_XDP_FEAT_CHANGE:
62 case NETDEV_CHANGENAME:
70 static int rtnl_net_debug_net_id;
72 static int __net_init rtnl_net_debug_net_init(struct net *net)
74 struct notifier_block *nb;
76 nb = net_generic(net, rtnl_net_debug_net_id);
77 nb->notifier_call = rtnl_net_debug_event;
79 return register_netdevice_notifier_net(net, nb);
82 static void __net_exit rtnl_net_debug_net_exit(struct net *net)
84 struct notifier_block *nb;
86 nb = net_generic(net, rtnl_net_debug_net_id);
87 unregister_netdevice_notifier_net(net, nb);
90 static struct pernet_operations rtnl_net_debug_net_ops __net_initdata = {
91 .init = rtnl_net_debug_net_init,
92 .exit = rtnl_net_debug_net_exit,
93 .id = &rtnl_net_debug_net_id,
94 .size = sizeof(struct notifier_block),
97 static struct notifier_block rtnl_net_debug_block = {
98 .notifier_call = rtnl_net_debug_event,
101 static int __init rtnl_net_debug_init(void)
105 ret = register_pernet_device(&rtnl_net_debug_net_ops);
109 ret = register_netdevice_notifier(&rtnl_net_debug_block);
111 unregister_pernet_subsys(&rtnl_net_debug_net_ops);
116 subsys_initcall(rtnl_net_debug_init);