]> git.ipfire.org Git - thirdparty/linux.git/commitdiff
ipv6: Convert tunnel devices' ->exit_batch_rtnl() to ->exit_rtnl().
authorKuniyuki Iwashima <kuniyu@amazon.com>
Fri, 11 Apr 2025 20:52:36 +0000 (13:52 -0700)
committerJakub Kicinski <kuba@kernel.org>
Tue, 15 Apr 2025 00:08:42 +0000 (17:08 -0700)
The following functions iterates the dying netns list and performs
the same operations for each netns.

  * ip6gre_exit_batch_rtnl()
  * ip6_tnl_exit_batch_rtnl()
  * vti6_exit_batch_rtnl()
  * sit_exit_batch_rtnl()

Let's use ->exit_rtnl().

Signed-off-by: Kuniyuki Iwashima <kuniyu@amazon.com>
Reviewed-by: David Ahern <dsahern@kernel.org>
Reviewed-by: Sabrina Dubroca <sd@queasysnail.net>
Link: https://patch.msgid.link/20250411205258.63164-8-kuniyu@amazon.com
Signed-off-by: Jakub Kicinski <kuba@kernel.org>
net/ipv6/ip6_gre.c
net/ipv6/ip6_tunnel.c
net/ipv6/ip6_vti.c
net/ipv6/sit.c

index 957ca98fa70f98f46cfbe88aecb594301e3f084c..2dc9dcffe2cab48e3f58947b8577e2a30615c04c 100644 (file)
@@ -1570,7 +1570,7 @@ static struct inet6_protocol ip6gre_protocol __read_mostly = {
        .flags       = INET6_PROTO_FINAL,
 };
 
-static void ip6gre_destroy_tunnels(struct net *net, struct list_head *head)
+static void __net_exit ip6gre_exit_rtnl_net(struct net *net, struct list_head *head)
 {
        struct ip6gre_net *ign = net_generic(net, ip6gre_net_id);
        struct net_device *dev, *aux;
@@ -1587,16 +1587,16 @@ static void ip6gre_destroy_tunnels(struct net *net, struct list_head *head)
                for (h = 0; h < IP6_GRE_HASH_SIZE; h++) {
                        struct ip6_tnl *t;
 
-                       t = rtnl_dereference(ign->tunnels[prio][h]);
+                       t = rtnl_net_dereference(net, ign->tunnels[prio][h]);
 
                        while (t) {
                                /* If dev is in the same netns, it has already
                                 * been added to the list by the previous loop.
                                 */
                                if (!net_eq(dev_net(t->dev), net))
-                                       unregister_netdevice_queue(t->dev,
-                                                                  head);
-                               t = rtnl_dereference(t->next);
+                                       unregister_netdevice_queue(t->dev, head);
+
+                               t = rtnl_net_dereference(net, t->next);
                        }
                }
        }
@@ -1640,19 +1640,9 @@ err_alloc_dev:
        return err;
 }
 
-static void __net_exit ip6gre_exit_batch_rtnl(struct list_head *net_list,
-                                             struct list_head *dev_to_kill)
-{
-       struct net *net;
-
-       ASSERT_RTNL();
-       list_for_each_entry(net, net_list, exit_list)
-               ip6gre_destroy_tunnels(net, dev_to_kill);
-}
-
 static struct pernet_operations ip6gre_net_ops = {
        .init = ip6gre_init_net,
-       .exit_batch_rtnl = ip6gre_exit_batch_rtnl,
+       .exit_rtnl = ip6gre_exit_rtnl_net,
        .id   = &ip6gre_net_id,
        .size = sizeof(struct ip6gre_net),
 };
index a04dd1bb4b195327845ec49253fd649edae869ef..894d3158a6f05d898d5cde68c0e019f1a8be6ac4 100644 (file)
@@ -2210,7 +2210,7 @@ static struct xfrm6_tunnel mplsip6_handler __read_mostly = {
        .priority       =       1,
 };
 
-static void __net_exit ip6_tnl_destroy_tunnels(struct net *net, struct list_head *list)
+static void __net_exit ip6_tnl_exit_rtnl_net(struct net *net, struct list_head *list)
 {
        struct ip6_tnl_net *ip6n = net_generic(net, ip6_tnl_net_id);
        struct net_device *dev, *aux;
@@ -2222,25 +2222,27 @@ static void __net_exit ip6_tnl_destroy_tunnels(struct net *net, struct list_head
                        unregister_netdevice_queue(dev, list);
 
        for (h = 0; h < IP6_TUNNEL_HASH_SIZE; h++) {
-               t = rtnl_dereference(ip6n->tnls_r_l[h]);
+               t = rtnl_net_dereference(net, ip6n->tnls_r_l[h]);
                while (t) {
                        /* If dev is in the same netns, it has already
                         * been added to the list by the previous loop.
                         */
                        if (!net_eq(dev_net(t->dev), net))
                                unregister_netdevice_queue(t->dev, list);
-                       t = rtnl_dereference(t->next);
+
+                       t = rtnl_net_dereference(net, t->next);
                }
        }
 
-       t = rtnl_dereference(ip6n->tnls_wc[0]);
+       t = rtnl_net_dereference(net, ip6n->tnls_wc[0]);
        while (t) {
                /* If dev is in the same netns, it has already
                 * been added to the list by the previous loop.
                 */
                if (!net_eq(dev_net(t->dev), net))
                        unregister_netdevice_queue(t->dev, list);
-               t = rtnl_dereference(t->next);
+
+               t = rtnl_net_dereference(net, t->next);
        }
 }
 
@@ -2287,19 +2289,9 @@ err_alloc_dev:
        return err;
 }
 
-static void __net_exit ip6_tnl_exit_batch_rtnl(struct list_head *net_list,
-                                              struct list_head *dev_to_kill)
-{
-       struct net *net;
-
-       ASSERT_RTNL();
-       list_for_each_entry(net, net_list, exit_list)
-               ip6_tnl_destroy_tunnels(net, dev_to_kill);
-}
-
 static struct pernet_operations ip6_tnl_net_ops = {
        .init = ip6_tnl_init_net,
-       .exit_batch_rtnl = ip6_tnl_exit_batch_rtnl,
+       .exit_rtnl = ip6_tnl_exit_rtnl_net,
        .id   = &ip6_tnl_net_id,
        .size = sizeof(struct ip6_tnl_net),
 };
index 09ec4b0ad7dc669053f3cdbd2ae78937abba3df8..40464a88bca6512cef30f8939eedfae1966fb203 100644 (file)
@@ -1112,21 +1112,21 @@ static struct rtnl_link_ops vti6_link_ops __read_mostly = {
        .get_link_net   = ip6_tnl_get_link_net,
 };
 
-static void __net_exit vti6_destroy_tunnels(struct vti6_net *ip6n,
-                                           struct list_head *list)
+static void __net_exit vti6_exit_rtnl_net(struct net *net, struct list_head *list)
 {
-       int h;
+       struct vti6_net *ip6n = net_generic(net, vti6_net_id);
        struct ip6_tnl *t;
+       int h;
 
        for (h = 0; h < IP6_VTI_HASH_SIZE; h++) {
-               t = rtnl_dereference(ip6n->tnls_r_l[h]);
+               t = rtnl_net_dereference(net, ip6n->tnls_r_l[h]);
                while (t) {
                        unregister_netdevice_queue(t->dev, list);
-                       t = rtnl_dereference(t->next);
+                       t = rtnl_net_dereference(net, t->next);
                }
        }
 
-       t = rtnl_dereference(ip6n->tnls_wc[0]);
+       t = rtnl_net_dereference(net, ip6n->tnls_wc[0]);
        if (t)
                unregister_netdevice_queue(t->dev, list);
 }
@@ -1170,22 +1170,9 @@ err_alloc_dev:
        return err;
 }
 
-static void __net_exit vti6_exit_batch_rtnl(struct list_head *net_list,
-                                           struct list_head *dev_to_kill)
-{
-       struct vti6_net *ip6n;
-       struct net *net;
-
-       ASSERT_RTNL();
-       list_for_each_entry(net, net_list, exit_list) {
-               ip6n = net_generic(net, vti6_net_id);
-               vti6_destroy_tunnels(ip6n, dev_to_kill);
-       }
-}
-
 static struct pernet_operations vti6_net_ops = {
        .init = vti6_init_net,
-       .exit_batch_rtnl = vti6_exit_batch_rtnl,
+       .exit_rtnl = vti6_exit_rtnl_net,
        .id   = &vti6_net_id,
        .size = sizeof(struct vti6_net),
 };
index 9a0f32acb75009dcb914041ff8d9b8cf43c1b96f..a72dbca9e8fcabdfba15d8b81aee3ea95a874265 100644 (file)
@@ -1804,8 +1804,7 @@ static struct xfrm_tunnel mplsip_handler __read_mostly = {
 };
 #endif
 
-static void __net_exit sit_destroy_tunnels(struct net *net,
-                                          struct list_head *head)
+static void __net_exit sit_exit_rtnl_net(struct net *net, struct list_head *head)
 {
        struct sit_net *sitn = net_generic(net, sit_net_id);
        struct net_device *dev, *aux;
@@ -1820,15 +1819,15 @@ static void __net_exit sit_destroy_tunnels(struct net *net,
                for (h = 0; h < (prio ? IP6_SIT_HASH_SIZE : 1); h++) {
                        struct ip_tunnel *t;
 
-                       t = rtnl_dereference(sitn->tunnels[prio][h]);
+                       t = rtnl_net_dereference(net, sitn->tunnels[prio][h]);
                        while (t) {
                                /* If dev is in the same netns, it has already
                                 * been added to the list by the previous loop.
                                 */
                                if (!net_eq(dev_net(t->dev), net))
-                                       unregister_netdevice_queue(t->dev,
-                                                                  head);
-                               t = rtnl_dereference(t->next);
+                                       unregister_netdevice_queue(t->dev, head);
+
+                               t = rtnl_net_dereference(net, t->next);
                        }
                }
        }
@@ -1881,19 +1880,9 @@ err_alloc_dev:
        return err;
 }
 
-static void __net_exit sit_exit_batch_rtnl(struct list_head *net_list,
-                                          struct list_head *dev_to_kill)
-{
-       struct net *net;
-
-       ASSERT_RTNL();
-       list_for_each_entry(net, net_list, exit_list)
-               sit_destroy_tunnels(net, dev_to_kill);
-}
-
 static struct pernet_operations sit_net_ops = {
        .init = sit_init_net,
-       .exit_batch_rtnl = sit_exit_batch_rtnl,
+       .exit_rtnl = sit_exit_rtnl_net,
        .id   = &sit_net_id,
        .size = sizeof(struct sit_net),
 };