Skip to content

Commit 5c333f8

Browse files
congwanggregkh
authored andcommitted
ipv6: reorder ip6_route_dev_notifier after ipv6_dev_notf
[ Upstream commit 242d3a49a2a1a71d8eb9f953db1bcaa9d698ce00 ] For each netns (except init_net), we initialize its null entry in 3 places: 1) The template itself, as we use kmemdup() 2) Code around dst_init_metrics() in ip6_route_net_init() 3) ip6_route_dev_notify(), which is supposed to initialize it after loopback registers Unfortunately the last one still happens in a wrong order because we expect to initialize net->ipv6.ip6_null_entry->rt6i_idev to net->loopback_dev's idev, thus we have to do that after we add idev to loopback. However, this notifier has priority == 0 same as ipv6_dev_notf, and ipv6_dev_notf is registered after ip6_route_dev_notifier so it is called actually after ip6_route_dev_notifier. This is similar to commit 2f460933f58e ("ipv6: initialize route null entry in addrconf_init()") which fixes init_net. Fix it by picking a smaller priority for ip6_route_dev_notifier. Also, we have to release the refcnt accordingly when unregistering loopback_dev because device exit functions are called before subsys exit functions. Acked-by: David Ahern <dsahern@gmail.com> Tested-by: David Ahern <dsahern@gmail.com> Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com> Signed-off-by: David S. Miller <davem@davemloft.net> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
1 parent 5117f03 commit 5c333f8

3 files changed

Lines changed: 14 additions & 2 deletions

File tree

include/net/addrconf.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#define ADDRCONF_TIMER_FUZZ (HZ / 4)
2020
#define ADDRCONF_TIMER_FUZZ_MAX (HZ)
2121

22+
#define ADDRCONF_NOTIFY_PRIORITY 0
23+
2224
#include <linux/in.h>
2325
#include <linux/in6.h>
2426

net/ipv6/addrconf.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3306,6 +3306,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,
33063306
*/
33073307
static struct notifier_block ipv6_dev_notf = {
33083308
.notifier_call = addrconf_notify,
3309+
.priority = ADDRCONF_NOTIFY_PRIORITY,
33093310
};
33103311

33113312
static void addrconf_type_change(struct net_device *dev, unsigned long event)

net/ipv6/route.c

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3363,14 +3363,23 @@ static int ip6_route_dev_notify(struct notifier_block *this,
33633363
struct net_device *dev = netdev_notifier_info_to_dev(ptr);
33643364
struct net *net = dev_net(dev);
33653365

3366-
if (event == NETDEV_REGISTER && (dev->flags & IFF_LOOPBACK)) {
3366+
if (!(dev->flags & IFF_LOOPBACK))
3367+
return NOTIFY_OK;
3368+
3369+
if (event == NETDEV_REGISTER) {
33673370
net->ipv6.ip6_null_entry->dst.dev = dev;
33683371
net->ipv6.ip6_null_entry->rt6i_idev = in6_dev_get(dev);
33693372
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
33703373
net->ipv6.ip6_prohibit_entry->dst.dev = dev;
33713374
net->ipv6.ip6_prohibit_entry->rt6i_idev = in6_dev_get(dev);
33723375
net->ipv6.ip6_blk_hole_entry->dst.dev = dev;
33733376
net->ipv6.ip6_blk_hole_entry->rt6i_idev = in6_dev_get(dev);
3377+
#endif
3378+
} else if (event == NETDEV_UNREGISTER) {
3379+
in6_dev_put(net->ipv6.ip6_null_entry->rt6i_idev);
3380+
#ifdef CONFIG_IPV6_MULTIPLE_TABLES
3381+
in6_dev_put(net->ipv6.ip6_prohibit_entry->rt6i_idev);
3382+
in6_dev_put(net->ipv6.ip6_blk_hole_entry->rt6i_idev);
33743383
#endif
33753384
}
33763385

@@ -3678,7 +3687,7 @@ static struct pernet_operations ip6_route_net_late_ops = {
36783687

36793688
static struct notifier_block ip6_route_dev_notifier = {
36803689
.notifier_call = ip6_route_dev_notify,
3681-
.priority = 0,
3690+
.priority = ADDRCONF_NOTIFY_PRIORITY - 10,
36823691
};
36833692

36843693
void __init ip6_route_init_special_entries(void)

0 commit comments

Comments
 (0)