ipv4: bump rt_genid when a relevant devconf value changes through netlink
Subsystems (3)
PATCH v3 1/1 ipv4: bump rt_genid when a relevant devconf value changes through netlink
When modifying IPv4 devconf values using netlink for some relevant fields the rt_cache_flush() call was missing. In addition, if forwarding is enabled on the interface then disable LRO.
This is needed to avoid possible connectivity issues and ease the responsabilities of user space tools.
---
v2: use netif_disable_lro() as we already hold netdev_need_ops_lock() and use net_device struct passed as argument instead of using in_dev->dev
v3: separate it from the series and sent it to net tree instead
--- net/ipv4/devinet.c | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-)
net/ipv4/devinet.c +22 -1
@@ -2098,6 +2098,8 @@ static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, {struct in_device *in_dev =__in_dev_get_rtnl (dev);struct nlattr *a, *tb[IFLA_INET_MAX +1 ]; +struct net *net =dev_net (dev); +bool flush_cache = false;int rem;if (!in_dev)
@@ -2107,8 +2109,27 @@ static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla,return -EINVAL ;if (tb[IFLA_INET_CONF ]) { -nla_for_each_nested (a, tb[IFLA_INET_CONF ], rem) +nla_for_each_nested (a, tb[IFLA_INET_CONF ], rem) {ipv4_devconf_set (in_dev,nla_type (a),nla_get_u32 (a)); + +switch (nla_type (a)) { +case IPV4_DEVCONF_FORWARDING : +if (nla_get_u32 (a)) +netif_disable_lro (dev); + fallthrough; +case IPV4_DEVCONF_NOXFRM : +case IPV4_DEVCONF_NOPOLICY : +case IPV4_DEVCONF_PROMOTE_SECONDARIES : +case IPV4_DEVCONF_ROUTE_LOCALNET : +case IPV4_DEVCONF_DROP_UNICAST_IN_L2_MULTICAST : + flush_cache = true; +break ; +default : +break ; + } + } +if (flush_cache) +rt_cache_flush (net); }return 0 ;
Signature · 1 line
2.53.0
Jakub Kicinski
maintainernet/ipv4/devinet.c static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, · line 2118
Quoted 4 lines · On Mon, 2 Mar 2026 14:08:57 +0100 Fernando Fernandez Mancera wrote:
net/ipv4/devinet.c +4
-0+switch (nla_type (a)) { +case IPV4_DEVCONF_FORWARDING : +if (nla_get_u32 (a)) +netif_disable_lro (dev);
why not dev_disable_lro()??
Quoted 5 lines
net/ipv4/devinet.c +5
-0+ fallthrough; +case IPV4_DEVCONF_NOXFRM : +case IPV4_DEVCONF_NOPOLICY : +case IPV4_DEVCONF_PROMOTE_SECONDARIES : +case IPV4_DEVCONF_ROUTE_LOCALNET :
net/ipv4/devinet.c static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, · line 2133
Quoted 10 lines
net/ipv4/devinet.c +9
-0+case IPV4_DEVCONF_DROP_UNICAST_IN_L2_MULTICAST : + flush_cache = true; +break ; +default : +break ; + } + } +if (flush_cache) +rt_cache_flush (net); }
Looking closer at this I'm struggling to connect this to devinet_conf_proc(). The attrs you're snooping here are completely different!? Logic for when rt_cache_flush() happens is different.
inet_netconf_notify_devconf() is missing even after the patch.
Signature · 1 line
pw-bot: cr
Quoted 7 lines · Jakub Kicinski
net/ipv4/devinet.c static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, · line 2118
Quoted 4 lines · On Mon, 2 Mar 2026 14:08:57 +0100 Fernando Fernandez Mancera wrote:
net/ipv4/devinet.c +4
-0+switch (nla_type (a)) { +case IPV4_DEVCONF_FORWARDING : +if (nla_get_u32 (a)) +netif_disable_lro (dev);why not
dev_disable_lro()??
dev_disable_lro() takes netdev_lock_ops() but when handling IFLA_AF_SPEC at net/core/rtnetlink.c:3320 we are already holding netdev lock ops. So we need to call netif_disable_lro() instead.
Quoted 12 lines
Quoted 12 lines
net/ipv4/devinet.c +11
-0+ fallthrough; +case IPV4_DEVCONF_NOXFRM : +case IPV4_DEVCONF_NOPOLICY : +case IPV4_DEVCONF_PROMOTE_SECONDARIES : +case IPV4_DEVCONF_ROUTE_LOCALNET : +case IPV4_DEVCONF_DROP_UNICAST_IN_L2_MULTICAST : + flush_cache = true; +break ; +default : +break ; + }
Quoted 9 lines
net/ipv4/devinet.c static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, · line 2133
Quoted 4 lines
net/ipv4/devinet.c +3
-0+ } +if (flush_cache) +rt_cache_flush (net); }Looking closer at this I'm struggling to connect this to
devinet_conf_proc(). The attrs you're snooping here are completely different!? Logic for whenrt_cache_flush()happens is different.
So I was planning to to handle inet_netconf_notify_devconf() calls in a follow-up patch to net-next because it might require some more changes and also the missing notification shouldn't be net tree material IMHO.
This is handling ipv4_doint_and_flush() which is used by DEVINET_SYSCTL_FLUSHING_ENTRY() macro. But now that you mention it, BC_FORWARDING and ACCEPT_LOCAL are part of devinet_conf_proc() while they probably could go to ipv4_doint_and_flush().
In addition, I guess we should flush the cache only if the value changed. I will add that bit too.
P.S: there is also dead code in devinet_conf_proc() as i == IPV4_DEVCONF_ROUTE_LOCALNET - 1 won't never evaluate as true.
Thanks,
Fernando.
Quoted 1 line
inet_netconf_notify_devconf()is missing even after the patch.
Jakub Kicinski
maintainerQuoted 9 lines · On Wed, 4 Mar 2026 10:03:37 +0100 Fernando Fernandez Mancera wrote:
Quoted 7 lines · Jakub Kicinski
net/ipv4/devinet.c static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, · line 2118
Quoted 4 lines · On Mon, 2 Mar 2026 14:08:57 +0100 Fernando Fernandez Mancera wrote:
net/ipv4/devinet.c +4
-0+switch (nla_type (a)) { +case IPV4_DEVCONF_FORWARDING : +if (nla_get_u32 (a)) +netif_disable_lro (dev);why not
dev_disable_lro()??
Quoted 3 lines
dev_disable_lro()takesnetdev_lock_ops()but when handlingIFLA_AF_SPECatnet/core/rtnetlink.c:3320we are already holding netdev lock ops. So we need to callnetif_disable_lro()instead.
Makes sense
Quoted 20 lines
Quoted 11 lines
Quoted 11 lines
net/ipv4/devinet.c +11
-0+ fallthrough; +case IPV4_DEVCONF_NOXFRM : +case IPV4_DEVCONF_NOPOLICY : +case IPV4_DEVCONF_PROMOTE_SECONDARIES : +case IPV4_DEVCONF_ROUTE_LOCALNET : +case IPV4_DEVCONF_DROP_UNICAST_IN_L2_MULTICAST : + flush_cache = true; +break ; +default : +break ; + }Quoted 8 lines
net/ipv4/devinet.c static int inet_set_link_af(struct net_device *dev, const struct nlattr *nla, · line 2133
Quoted 4 lines
net/ipv4/devinet.c +3
-0+ } +if (flush_cache) +rt_cache_flush (net); }Looking closer at this I'm struggling to connect this to
devinet_conf_proc(). The attrs you're snooping here are completely different!? Logic for whenrt_cache_flush()happens is different.
Quoted 3 lines
So I was planning to to handle
inet_netconf_notify_devconf()calls in a follow-up patch to net-next because it might require some more changes and also the missing notification shouldn't be net tree material IMHO.
Fair, let's call it out in the commit message, tho
Quoted 7 lines
This is handling
ipv4_doint_and_flush()which is used byDEVINET_SYSCTL_FLUSHING_ENTRY()macro. But now that you mention it,BC_FORWARDINGandACCEPT_LOCALare part ofdevinet_conf_proc()while they probably could go toipv4_doint_and_flush().In addition, I guess we should flush the cache only if the value changed. I will add that bit too.
Thanks!