All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH v2 net-next] net: make dev_set_mtu() honor notification return code
@ 2014-01-10 15:56 Veaceslav Falico
  2014-01-10 16:21 ` Jiri Pirko
  0 siblings, 1 reply; 2+ messages in thread
From: Veaceslav Falico @ 2014-01-10 15:56 UTC (permalink / raw)
  To: netdev
  Cc: Veaceslav Falico, Jiri Pirko, David S. Miller, Eric Dumazet,
	Alexander Duyck, Nicolas Dichtel

Currently, after changing the MTU for a device, dev_set_mtu() calls
NETDEV_CHANGEMTU notification, however doesn't verify it's return code -
which can be NOTIFY_BAD - i.e. some of the net notifier blocks refused this
change, and continues nevertheless.

To fix this, verify the return code, and if it's an error - then revert the
MTU to the original one, notify again and pass the error code.

CC: Jiri Pirko <jiri@resnulli.us>
CC: "David S. Miller" <davem@davemloft.net>
CC: Eric Dumazet <edumazet@google.com>
CC: Alexander Duyck <alexander.h.duyck@intel.com>
CC: Nicolas Dichtel <nicolas.dichtel@6wind.com>
Signed-off-by: Veaceslav Falico <vfalico@redhat.com>
---

Notes:
    v1 -> v2:
    Notify again after we've reverted the MTU back to the original, so that
    everyone has a chance to change its MTU back.

 net/core/dev.c | 34 +++++++++++++++++++++++++---------
 1 file changed, 25 insertions(+), 9 deletions(-)

diff --git a/net/core/dev.c b/net/core/dev.c
index ce01847..0991d94 100644
--- a/net/core/dev.c
+++ b/net/core/dev.c
@@ -5287,6 +5287,17 @@ int dev_change_flags(struct net_device *dev, unsigned int flags)
 }
 EXPORT_SYMBOL(dev_change_flags);
 
+static int __dev_set_mtu(struct net_device *dev, int new_mtu)
+{
+	const struct net_device_ops *ops = dev->netdev_ops;
+
+	if (ops->ndo_change_mtu)
+		return ops->ndo_change_mtu(dev, new_mtu);
+
+	dev->mtu = new_mtu;
+	return 0;
+}
+
 /**
  *	dev_set_mtu - Change maximum transfer unit
  *	@dev: device
@@ -5296,8 +5307,7 @@ EXPORT_SYMBOL(dev_change_flags);
  */
 int dev_set_mtu(struct net_device *dev, int new_mtu)
 {
-	const struct net_device_ops *ops = dev->netdev_ops;
-	int err;
+	int err, orig_mtu;
 
 	if (new_mtu == dev->mtu)
 		return 0;
@@ -5309,14 +5319,20 @@ int dev_set_mtu(struct net_device *dev, int new_mtu)
 	if (!netif_device_present(dev))
 		return -ENODEV;
 
-	err = 0;
-	if (ops->ndo_change_mtu)
-		err = ops->ndo_change_mtu(dev, new_mtu);
-	else
-		dev->mtu = new_mtu;
+	orig_mtu = dev->mtu;
+	err = __dev_set_mtu(dev, new_mtu);
 
-	if (!err)
-		call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
+	if (!err) {
+		err = call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
+		err = notifier_to_errno(err);
+		if (err) {
+			/* setting mtu back and notifying everyone again,
+			 * so that they have a chance to revert changes.
+			 */
+			__dev_set_mtu(dev, orig_mtu);
+			call_netdevice_notifiers(NETDEV_CHANGEMTU, dev);
+		}
+	}
 	return err;
 }
 EXPORT_SYMBOL(dev_set_mtu);
-- 
1.8.4

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH v2 net-next] net: make dev_set_mtu() honor notification return code
  2014-01-10 15:56 [PATCH v2 net-next] net: make dev_set_mtu() honor notification return code Veaceslav Falico
@ 2014-01-10 16:21 ` Jiri Pirko
  0 siblings, 0 replies; 2+ messages in thread
From: Jiri Pirko @ 2014-01-10 16:21 UTC (permalink / raw)
  To: Veaceslav Falico
  Cc: netdev, David S. Miller, Eric Dumazet, Alexander Duyck, Nicolas Dichtel

Fri, Jan 10, 2014 at 04:56:25PM CET, vfalico@redhat.com wrote:
>Currently, after changing the MTU for a device, dev_set_mtu() calls
>NETDEV_CHANGEMTU notification, however doesn't verify it's return code -
>which can be NOTIFY_BAD - i.e. some of the net notifier blocks refused this
>change, and continues nevertheless.
>
>To fix this, verify the return code, and if it's an error - then revert the
>MTU to the original one, notify again and pass the error code.
>
>CC: Jiri Pirko <jiri@resnulli.us>
>CC: "David S. Miller" <davem@davemloft.net>
>CC: Eric Dumazet <edumazet@google.com>
>CC: Alexander Duyck <alexander.h.duyck@intel.com>
>CC: Nicolas Dichtel <nicolas.dichtel@6wind.com>
>Signed-off-by: Veaceslav Falico <vfalico@redhat.com>

Reviewed-by: Jiri Pirko <jiri@resnulli.us>

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2014-01-10 16:21 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-01-10 15:56 [PATCH v2 net-next] net: make dev_set_mtu() honor notification return code Veaceslav Falico
2014-01-10 16:21 ` Jiri Pirko

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.