net: ipv4: fixes for PMTU when link MTU changes
Subsystems (3)
v2 cover net: ipv4: fixes for PMTU when link MTU changes
The first patch adapts the changes that commit e9fa1495d738 ("ipv6:
Reflect MTU changes on PMTU of exceptions for MTU-less routes") did in IPv6 to IPv4: lower PMTU when the first hop's MTU drops below it, and raise PMTU when the first hop was limiting PMTU discovery and its MTU is increased.
The second patch fixes bugs introduced in commit d52e5a7e7ca4 ("ipv4:
lock mtu in fnhe when received PMTU < net.ipv4.route.min_pmtu") that only appear once the first patch is applied.
Selftests for these cases were introduced in net-next commit e44e428f59e4 ("selftests: pmtu: add basic IPv4 and IPv6 PMTU tests")
v2: add cover letter, and fix a few small things in patch 1
Sabrina Dubroca (2):
net: ipv4: update fnhe_pmtu when first hop's MTU changes
net: ipv4: don't let PMTU updates increase route MTU
include/linux/netdevice.h | 7 ++++++ include/net/ip_fib.h | 1 + net/core/dev.c | 28 ++++++++++++++++++++-- net/ipv4/fib_frontend.c | 12 ++++++---- net/ipv4/fib_semantics.c | 50 +++++++++++++++++++++++++++++++++++++++ net/ipv4/route.c | 7 +++--- 6 files changed, 96 insertions(+), 9 deletions(-)
Signature · 1 line
2.19.0
PATCH v2 1/2 net: ipv4: update fnhe_pmtu when first hop's MTU changes
Since commit 5aad1de5ea2c ("ipv4: use separate genid for next hop exceptions"), exceptions get deprecated separately from cached routes. In particular, administrative changes don't clear PMTU anymore.
As Stefano described in commit e9fa1495d738 ("ipv6: Reflect MTU changes on PMTU of exceptions for MTU-less routes"), the PMTU discovered before the local MTU change can become stale:
- if the local MTU is now lower than the PMTU, that PMTU is now incorrect
- if the local MTU was the lowest value in the path, and is increased, we might discover a higher PMTU
Similarly to what commit e9fa1495d738 did for IPv6, update PMTU in those cases.
If the exception was locked, the discovered PMTU was smaller than the minimal accepted PMTU. In that case, if the new local MTU is smaller than the current PMTU, let PMTU discovery figure out if locking of the exception is still needed.
To do this, we need to know the old link MTU in the NETDEV_CHANGEMTU notifier. By the time the notifier is called, dev->mtu has been changed. This patch adds the old MTU as additional information in the notifier structure, and a new call_netdevice_notifiers_u32() function.
---
v2:
- s/u32/mtu/ in netdev_notifier_info_ext and call_netdevice_notifiers_ helper, suggested by David Ahern
- don't EXPORT_SYMBOL the helper, it's only used in net/core/dev.c
- fix typo in commit message
- fix kerneldoc comment, spotted by kbuild bot
include/linux/netdevice.h | 7 ++++++ include/net/ip_fib.h | 1 + net/core/dev.c | 28 ++++++++++++++++++++-- net/ipv4/fib_frontend.c | 12 ++++++---- net/ipv4/fib_semantics.c | 50 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 6 deletions(-)
include/linux/netdevice.h +7 -0
@@ -2458,6 +2458,13 @@ struct netdev_notifier_info {struct netlink_ext_ack *extack; }; +struct netdev_notifier_info_ext { +struct netdev_notifier_info info;/* must be first */ +union { +u32 mtu; + } ext; +}; +struct netdev_notifier_change_info {struct netdev_notifier_info info;/* must be first */ unsigned int flags_changed;
include/net/ip_fib.h +1 -0
@@ -394,6 +394,7 @@ int ip_fib_check_default(__be32 gw, struct net_device *dev);int fib_sync_down_dev (struct net_device *dev,unsigned long event,bool force);int fib_sync_down_addr (struct net_device *dev,__be32 local);int fib_sync_up (struct net_device *dev,unsigned int nh_flags); +void fib_sync_mtu (struct net_device *dev,u32 orig_mtu);#ifdef CONFIG_IP_ROUTE_MULTIPATH int fib_multipath_hash(const struct net *net, const struct flowi4 *fl4,
net/core/dev.c +26 -2
@@ -1752,6 +1752,28 @@ int call_netdevice_notifiers(unsigned long val, struct net_device *dev) }EXPORT_SYMBOL (call_netdevice_notifiers); +/** +* call_netdevice_notifiers_mtu - call all network notifier blocks +* @val: value passed unmodified to notifier function +* @dev: net_device pointer passed unmodified to notifier function +* @arg: additional u32 argument passed to the notifier function +* +* Call all network notifier blocks. Parameters and return value +* are as for raw_notifier_call_chain(). +*/ +static int call_netdevice_notifiers_mtu (unsigned long val, +struct net_device *dev,u32 arg) +{ +struct netdev_notifier_info_ext info = { + .info.dev = dev, + .ext.mtu = arg, + }; + +BUILD_BUG_ON (offsetof(struct netdev_notifier_info_ext , info) !=0 ); + +return call_netdevice_notifiers_info (val, &info.info); +} +#ifdef CONFIG_NET_INGRESS static DEFINE_STATIC_KEY_FALSE (ingress_needed_key);
@@ -7574,14 +7596,16 @@ int dev_set_mtu_ext(struct net_device *dev, int new_mtu, err =__dev_set_mtu (dev, new_mtu);if (!err) { - err =call_netdevice_notifiers (NETDEV_CHANGEMTU , dev); + err =call_netdevice_notifiers_mtu (NETDEV_CHANGEMTU , dev, + orig_mtu); 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); +call_netdevice_notifiers_mtu (NETDEV_CHANGEMTU , dev, + new_mtu); } }return err;
net/ipv4/fib_frontend.c +8 -4
@@ -1243,7 +1243,8 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,static int fib_netdev_event (struct notifier_block *this,unsigned long event,void *ptr) {struct net_device *dev =netdev_notifier_info_to_dev (ptr); -struct netdev_notifier_changeupper_info *info; +struct netdev_notifier_changeupper_info *upper_info = ptr; +struct netdev_notifier_info_ext *info_ext = ptr;struct in_device *in_dev;struct net *net =dev_net (dev);unsigned int flags;
@@ -1278,16 +1279,19 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vofib_sync_up (dev,RTNH_F_LINKDOWN ); elsefib_sync_down_dev (dev ,event ,false ); -/* fall through */ +rt_cache_flush (net); +break ;case NETDEV_CHANGEMTU : +fib_sync_mtu (dev, info_ext->ext.mtu);rt_cache_flush (net);break ;case NETDEV_CHANGEUPPER : - info = ptr; + upper_info = ptr;/* flush all routes if dev is linked to or unlinked from * an L3 master device (e.g., VRF) */ -if (info->upper_dev &&netif_is_l3_master (info->upper_dev)) +if (upper_info->upper_dev && +netif_is_l3_master (upper_info->upper_dev))fib_disable_ip (dev,NETDEV_DOWN , true);break ; }
net/ipv4/fib_semantics.c +50 -0
56 lines not on this page · raw message
Signature · 1 line
2.19.0
Re: [PATCH net v2 1/2] net: ipv4: update fnhe_pmtu when first hop's MTU changes
Quoted 36 lines · Sabrina Dubroca
Since commit
5aad1de5ea2c("ipv4: use separate genid for next hop exceptions"), exceptions get deprecated separately from cached routes. In particular, administrative changes don't clear PMTU anymore.As Stefano described in commit
e9fa1495d738("ipv6: Reflect MTU changes on PMTU of exceptions for MTU-less routes"), the PMTU discovered before the local MTU change can become stale:
- if the local MTU is now lower than the PMTU, that PMTU is now incorrect
- if the local MTU was the lowest value in the path, and is increased, we might discover a higher PMTUSimilarly to what commit
e9fa1495d738did for IPv6, update PMTU in those cases.If the exception was locked, the discovered PMTU was smaller than the minimal accepted PMTU. In that case, if the new local MTU is smaller than the current PMTU, let PMTU discovery figure out if locking of the exception is still needed.
To do this, we need to know the old link MTU in the
NETDEV_CHANGEMTUnotifier. By the time the notifier is called,dev->mtuhas been changed. This patch adds the old MTU as additional information in the notifier structure, and a newcall_netdevice_notifiers_u32()function.Fixes 5aad1de5ea2c ("ipv4: use separate genid for next hop exceptions")Signed-off-by Sabrina Dubroca <[email protected]>Reviewed-by Stefano Brivio <[email protected]>---
v2:
- s/u32/mtu/ innetdev_notifier_info_extandcall_netdevice_notifiers_helper, suggested by David Ahern
- don'tEXPORT_SYMBOLthe helper, it's only used innet/core/dev.c
- fix typo in commit message
- fix kerneldoc comment, spotted by kbuild bot
Quoted 6 lines
include/linux/netdevice.h | 7 ++++++ include/net/ip_fib.h | 1 + net/core/dev.c | 28 ++++++++++++++++++++-- net/ipv4/fib_frontend.c | 12 ++++++---- net/ipv4/fib_semantics.c | 50 +++++++++++++++++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 6 deletions(-)
PATCH v2 2/2 net: ipv4: don't let PMTU updates increase route MTU
In reply to Sabrina DubrocaWhen an MTU update with PMTU smaller than net.ipv4.route.min_pmtu is received, we must clamp its value. However, we can receive a PMTU exception with PMTU < old_mtu < ip_rt_min_pmtu, which would lead to an increase in PMTU.
To fix this, take the smallest of the old MTU and ip_rt_min_pmtu.
Before this patch, in case of an update, the exception's MTU would always change. Now, an exception can have only its lock flag updated, but not the MTU, so we need to add a check on locking to the following "is this exception getting updated, or close to expiring?" test.
---
v2: unchanged
net/ipv4/route.c | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-)
net/ipv4/route.c +4 -3
@@ -1001,21 +1001,22 @@ out: kfree_skb(skb);static void __ip_rt_update_pmtu (struct rtable *rt,struct flowi4 *fl4,u32 mtu) {struct dst_entry *dst = &rt->dst; +u32 old_mtu =ipv4_mtu (dst);struct fib_result res;bool lock = false;if (ip_mtu_locked (dst))return ; -if (ipv4_mtu (dst) < mtu) +if (old_mtu < mtu)return ;if (mtu < ip_rt_min_pmtu) { lock = true; - mtu = ip_rt_min_pmtu; + mtu =min (old_mtu, ip_rt_min_pmtu); } -if (rt->rt_pmtu == mtu && +if (rt->rt_pmtu == mtu && !lock &&time_before (jiffies, dst->expires - ip_rt_mtu_expires /2 ))return ;
Signature · 1 line
2.19.0
David Miller
maintainerFrom: Sabrina Dubroca <[email protected]>
Date: Tue, 9 Oct 2018 17:48:13 +0200
Quoted 6 lines
The first patch adapts the changes that commit
e9fa1495d738("ipv6:
Reflect MTU changes on PMTU of exceptions for MTU-less routes") did in IPv6 to IPv4: lower PMTU when the first hop's MTU drops below it, and raise PMTU when the first hop was limiting PMTU discovery and its MTU is increased.
Quoted 8 lines
The second patch fixes bugs introduced in commit
d52e5a7e7ca4("ipv4:
lock mtu in fnhe when received PMTU < net.ipv4.route.min_pmtu") that only appear once the first patch is applied.Selftests for these cases were introduced in net-next commit
e44e428f59e4("selftests: pmtu: add basic IPv4 and IPv6 PMTU tests")v2: add cover letter, and fix a few small things in patch 1
Series applied and queued up for -stable.