Linux kernel mirror (for testing)
git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel
os
linux
1// SPDX-License-Identifier: GPL-2.0-or-later
2/* Copyright Amazon.com Inc. or its affiliates. */
3
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>
10
11static int rtnl_net_debug_event(struct notifier_block *nb,
12 unsigned long event, void *ptr)
13{
14 struct net_device *dev = netdev_notifier_info_to_dev(ptr);
15 struct net *net = dev_net(dev);
16 enum netdev_cmd cmd = event;
17
18 /* Keep enum and don't add default to trigger -Werror=switch */
19 switch (cmd) {
20 case NETDEV_UP:
21 case NETDEV_DOWN:
22 case NETDEV_REBOOT:
23 case NETDEV_CHANGE:
24 case NETDEV_REGISTER:
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:
32 case NETDEV_PRE_UP:
33 case NETDEV_PRE_TYPE_CHANGE:
34 case NETDEV_POST_TYPE_CHANGE:
35 case NETDEV_POST_INIT:
36 case NETDEV_PRE_UNINIT:
37 case NETDEV_RELEASE:
38 case NETDEV_NOTIFY_PEERS:
39 case NETDEV_JOIN:
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:
59 ASSERT_RTNL();
60 break;
61
62 case NETDEV_CHANGENAME:
63 ASSERT_RTNL_NET(net);
64 break;
65 }
66
67 return NOTIFY_DONE;
68}
69
70static int rtnl_net_debug_net_id;
71
72static int __net_init rtnl_net_debug_net_init(struct net *net)
73{
74 struct notifier_block *nb;
75
76 nb = net_generic(net, rtnl_net_debug_net_id);
77 nb->notifier_call = rtnl_net_debug_event;
78
79 return register_netdevice_notifier_net(net, nb);
80}
81
82static void __net_exit rtnl_net_debug_net_exit(struct net *net)
83{
84 struct notifier_block *nb;
85
86 nb = net_generic(net, rtnl_net_debug_net_id);
87 unregister_netdevice_notifier_net(net, nb);
88}
89
90static 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),
95};
96
97static struct notifier_block rtnl_net_debug_block = {
98 .notifier_call = rtnl_net_debug_event,
99};
100
101static int __init rtnl_net_debug_init(void)
102{
103 int ret;
104
105 ret = register_pernet_device(&rtnl_net_debug_net_ops);
106 if (ret)
107 return ret;
108
109 ret = register_netdevice_notifier(&rtnl_net_debug_block);
110 if (ret)
111 unregister_pernet_subsys(&rtnl_net_debug_net_ops);
112
113 return ret;
114}
115
116subsys_initcall(rtnl_net_debug_init);