[PATCH net] net: vlan: allow vlan device MTU change follow real device from smaller to bigger

From: Ziyang Xuan
Date: Mon Feb 21 2022 - 07:29:00 EST


vlan device MTU can only follow real device change from bigger to smaller
but from smaller to bigger under the premise of vlan device MTU not exceed
the real device MTU.

This issue can be seen using the following commands:

ip link add link eth1 dev eth1.100 type vlan id 100
ip link set eth1 mtu 256
ip link set eth1 mtu 1500
ip link show

Modify to allow vlan device follow real device MTU change from smaller
to bigger when user has not configured vlan device MTU which is not
equal to real device MTU. That also ensure user configuration has higher
priority.

Fixes: 2e477c9bd2bb ("vlan: Propagate physical MTU changes")
Signed-off-by: Ziyang Xuan <william.xuanziyang@xxxxxxxxxx>
---
net/8021q/vlan.c | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
index 788076b002b3..7de4f462525a 100644
--- a/net/8021q/vlan.c
+++ b/net/8021q/vlan.c
@@ -361,6 +361,7 @@ static int __vlan_device_event(struct net_device *dev, unsigned long event)
static int vlan_device_event(struct notifier_block *unused, unsigned long event,
void *ptr)
{
+ unsigned int orig_mtu = ((struct netdev_notifier_info_ext *)ptr)->ext.mtu;
struct netlink_ext_ack *extack = netdev_notifier_info_to_extack(ptr);
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
struct vlan_group *grp;
@@ -419,7 +420,7 @@ static int vlan_device_event(struct notifier_block *unused, unsigned long event,

case NETDEV_CHANGEMTU:
vlan_group_for_each_dev(grp, i, vlandev) {
- if (vlandev->mtu <= dev->mtu)
+ if (vlandev->mtu <= dev->mtu && vlandev->mtu != orig_mtu)
continue;

dev_set_mtu(vlandev, dev->mtu);
--
2.25.1