794-v6.2-net-core-Allow-live-renaming-when-an-interface-is-up.patch 5.2 KB

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