c15604717be06cd42e9d1707455165c4bb898a14
[openwrt/staging/svanheule.git] /
1 From: Andy Ren <andy.ren@getcruise.com>
2 Date: Mon, 7 Nov 2022 09:42:42 -0800
3 Subject: [PATCH] net/core: Allow live renaming when an interface is up
4
5 Allow a network interface to be renamed when the interface
6 is up.
7
8 As described in the netconsole documentation [1], when netconsole is
9 used as a built-in, it will bring up the specified interface as soon as
10 possible. As a result, user space will not be able to rename the
11 interface since the kernel disallows renaming of interfaces that are
12 administratively up unless the 'IFF_LIVE_RENAME_OK' private flag was set
13 by the kernel.
14
15 The original solution [2] to this problem was to add a new parameter to
16 the netconsole configuration parameters that allows renaming of
17 the interface used by netconsole while it is administratively up.
18 However, during the discussion that followed, it became apparent that we
19 have no reason to keep the current restriction and instead we should
20 allow user space to rename interfaces regardless of their administrative
21 state:
22
23 1. The restriction was put in place over 20 years ago when renaming was
24 only possible via IOCTL and before rtnetlink started notifying user
25 space about such changes like it does today.
26
27 2. The 'IFF_LIVE_RENAME_OK' flag was added over 3 years ago in version
28 5.2 and no regressions were reported.
29
30 3. In-kernel listeners to 'NETDEV_CHANGENAME' do not seem to care about
31 the administrative state of interface.
32
33 Therefore, allow user space to rename running interfaces by removing the
34 restriction and the associated 'IFF_LIVE_RENAME_OK' flag. Help in
35 possible triage by emitting a message to the kernel log that an
36 interface was renamed while UP.
37
38 [1] https://www.kernel.org/doc/Documentation/networking/netconsole.rst
39 [2] https://lore.kernel.org/netdev/20221102002420.2613004-1-andy.ren@getcruise.com/
40
41 Signed-off-by: Andy Ren <andy.ren@getcruise.com>
42 Reviewed-by: Ido Schimmel <idosch@nvidia.com>
43 Reviewed-by: David Ahern <dsahern@kernel.org>
44 Signed-off-by: David S. Miller <davem@davemloft.net>
45 ---
46
47 --- a/include/linux/netdevice.h
48 +++ b/include/linux/netdevice.h
49 @@ -1667,7 +1667,6 @@ struct net_device_ops {
50 * @IFF_FAILOVER: device is a failover master device
51 * @IFF_FAILOVER_SLAVE: device is lower dev of a failover master device
52 * @IFF_L3MDEV_RX_HANDLER: only invoke the rx handler of L3 master device
53 - * @IFF_LIVE_RENAME_OK: rename is allowed while device is up and running
54 * @IFF_TX_SKB_NO_LINEAR: device/driver is capable of xmitting frames with
55 * skb_headlen(skb) == 0 (data starts from frag0)
56 * @IFF_CHANGE_PROTO_DOWN: device supports setting carrier via IFLA_PROTO_DOWN
57 @@ -1703,7 +1702,7 @@ enum netdev_priv_flags {
58 IFF_FAILOVER = 1<<27,
59 IFF_FAILOVER_SLAVE = 1<<28,
60 IFF_L3MDEV_RX_HANDLER = 1<<29,
61 - IFF_LIVE_RENAME_OK = 1<<30,
62 + /* was IFF_LIVE_RENAME_OK */
63 IFF_TX_SKB_NO_LINEAR = BIT_ULL(31),
64 IFF_CHANGE_PROTO_DOWN = BIT_ULL(32),
65 };
66 @@ -1738,7 +1737,6 @@ enum netdev_priv_flags {
67 #define IFF_FAILOVER IFF_FAILOVER
68 #define IFF_FAILOVER_SLAVE IFF_FAILOVER_SLAVE
69 #define IFF_L3MDEV_RX_HANDLER IFF_L3MDEV_RX_HANDLER
70 -#define IFF_LIVE_RENAME_OK IFF_LIVE_RENAME_OK
71 #define IFF_TX_SKB_NO_LINEAR IFF_TX_SKB_NO_LINEAR
72
73 /* Specifies the type of the struct net_device::ml_priv pointer */
74 --- a/net/core/dev.c
75 +++ b/net/core/dev.c
76 @@ -1188,22 +1188,6 @@ int dev_change_name(struct net_device *d
77
78 net = dev_net(dev);
79
80 - /* Some auto-enslaved devices e.g. failover slaves are
81 - * special, as userspace might rename the device after
82 - * the interface had been brought up and running since
83 - * the point kernel initiated auto-enslavement. Allow
84 - * live name change even when these slave devices are
85 - * up and running.
86 - *
87 - * Typically, users of these auto-enslaving devices
88 - * don't actually care about slave name change, as
89 - * they are supposed to operate on master interface
90 - * directly.
91 - */
92 - if (dev->flags & IFF_UP &&
93 - likely(!(dev->priv_flags & IFF_LIVE_RENAME_OK)))
94 - return -EBUSY;
95 -
96 down_write(&devnet_rename_sem);
97
98 if (strncmp(newname, dev->name, IFNAMSIZ) == 0) {
99 @@ -1220,7 +1204,8 @@ int dev_change_name(struct net_device *d
100 }
101
102 if (oldname[0] && !strchr(oldname, '%'))
103 - netdev_info(dev, "renamed from %s\n", oldname);
104 + netdev_info(dev, "renamed from %s%s\n", oldname,
105 + dev->flags & IFF_UP ? " (while UP)" : "");
106
107 old_assign_type = dev->name_assign_type;
108 dev->name_assign_type = NET_NAME_RENAMED;
109 --- a/net/core/failover.c
110 +++ b/net/core/failover.c
111 @@ -80,14 +80,14 @@ static int failover_slave_register(struc
112 goto err_upper_link;
113 }
114
115 - slave_dev->priv_flags |= (IFF_FAILOVER_SLAVE | IFF_LIVE_RENAME_OK);
116 + slave_dev->priv_flags |= IFF_FAILOVER_SLAVE;
117
118 if (fops && fops->slave_register &&
119 !fops->slave_register(slave_dev, failover_dev))
120 return NOTIFY_OK;
121
122 netdev_upper_dev_unlink(slave_dev, failover_dev);
123 - slave_dev->priv_flags &= ~(IFF_FAILOVER_SLAVE | IFF_LIVE_RENAME_OK);
124 + slave_dev->priv_flags &= ~IFF_FAILOVER_SLAVE;
125 err_upper_link:
126 netdev_rx_handler_unregister(slave_dev);
127 done:
128 @@ -121,7 +121,7 @@ int failover_slave_unregister(struct net
129
130 netdev_rx_handler_unregister(slave_dev);
131 netdev_upper_dev_unlink(slave_dev, failover_dev);
132 - slave_dev->priv_flags &= ~(IFF_FAILOVER_SLAVE | IFF_LIVE_RENAME_OK);
133 + slave_dev->priv_flags &= ~IFF_FAILOVER_SLAVE;
134
135 if (fops && fops->slave_unregister &&
136 !fops->slave_unregister(slave_dev, failover_dev))