Commit 611da32f authored by Nikolay Aleksandrov's avatar Nikolay Aleksandrov Committed by Ben Hutchings

net: ip6mr: fix static mfc/dev leaks on table destruction

commit 4c698046 upstream.

Similar to ipv4, when destroying an mrt table the static mfc entries and
the static devices are kept, which leads to devices that can never be
destroyed (because of refcnt taken) and leaked memory. Make sure that
everything is cleaned up on netns destruction.

Fixes: 8229efda ("netns: ip6mr: enable namespace support in ipv6 multicast forwarding code")
CC: Benjamin Thery <benjamin.thery@bull.net>
Signed-off-by: default avatarNikolay Aleksandrov <nikolay@cumulusnetworks.com>
Reviewed-by: default avatarCong Wang <cwang@twopensource.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
Signed-off-by: default avatarBen Hutchings <ben@decadent.org.uk>
parent 64344727
...@@ -118,7 +118,7 @@ static int __ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb, ...@@ -118,7 +118,7 @@ static int __ip6mr_fill_mroute(struct mr6_table *mrt, struct sk_buff *skb,
struct mfc6_cache *c, struct rtmsg *rtm); struct mfc6_cache *c, struct rtmsg *rtm);
static int ip6mr_rtm_dumproute(struct sk_buff *skb, static int ip6mr_rtm_dumproute(struct sk_buff *skb,
struct netlink_callback *cb); struct netlink_callback *cb);
static void mroute_clean_tables(struct mr6_table *mrt); static void mroute_clean_tables(struct mr6_table *mrt, bool all);
static void ipmr_expire_process(unsigned long arg); static void ipmr_expire_process(unsigned long arg);
#ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES #ifdef CONFIG_IPV6_MROUTE_MULTIPLE_TABLES
...@@ -335,7 +335,7 @@ static struct mr6_table *ip6mr_new_table(struct net *net, u32 id) ...@@ -335,7 +335,7 @@ static struct mr6_table *ip6mr_new_table(struct net *net, u32 id)
static void ip6mr_free_table(struct mr6_table *mrt) static void ip6mr_free_table(struct mr6_table *mrt)
{ {
del_timer_sync(&mrt->ipmr_expire_timer); del_timer_sync(&mrt->ipmr_expire_timer);
mroute_clean_tables(mrt); mroute_clean_tables(mrt, true);
kfree(mrt); kfree(mrt);
} }
...@@ -1473,7 +1473,7 @@ static int ip6mr_mfc_add(struct net *net, struct mr6_table *mrt, ...@@ -1473,7 +1473,7 @@ static int ip6mr_mfc_add(struct net *net, struct mr6_table *mrt,
* Close the multicast socket, and clear the vif tables etc * Close the multicast socket, and clear the vif tables etc
*/ */
static void mroute_clean_tables(struct mr6_table *mrt) static void mroute_clean_tables(struct mr6_table *mrt, bool all)
{ {
int i; int i;
LIST_HEAD(list); LIST_HEAD(list);
...@@ -1483,7 +1483,8 @@ static void mroute_clean_tables(struct mr6_table *mrt) ...@@ -1483,7 +1483,8 @@ static void mroute_clean_tables(struct mr6_table *mrt)
* Shut down all active vif entries * Shut down all active vif entries
*/ */
for (i = 0; i < mrt->maxvif; i++) { for (i = 0; i < mrt->maxvif; i++) {
if (!(mrt->vif6_table[i].flags & VIFF_STATIC)) if (!all && (mrt->vif6_table[i].flags & VIFF_STATIC))
continue;
mif6_delete(mrt, i, &list); mif6_delete(mrt, i, &list);
} }
unregister_netdevice_many(&list); unregister_netdevice_many(&list);
...@@ -1493,7 +1494,7 @@ static void mroute_clean_tables(struct mr6_table *mrt) ...@@ -1493,7 +1494,7 @@ static void mroute_clean_tables(struct mr6_table *mrt)
*/ */
for (i = 0; i < MFC6_LINES; i++) { for (i = 0; i < MFC6_LINES; i++) {
list_for_each_entry_safe(c, next, &mrt->mfc6_cache_array[i], list) { list_for_each_entry_safe(c, next, &mrt->mfc6_cache_array[i], list) {
if (c->mfc_flags & MFC_STATIC) if (!all && (c->mfc_flags & MFC_STATIC))
continue; continue;
write_lock_bh(&mrt_lock); write_lock_bh(&mrt_lock);
list_del(&c->list); list_del(&c->list);
...@@ -1547,7 +1548,7 @@ int ip6mr_sk_done(struct sock *sk) ...@@ -1547,7 +1548,7 @@ int ip6mr_sk_done(struct sock *sk)
net->ipv6.devconf_all->mc_forwarding--; net->ipv6.devconf_all->mc_forwarding--;
write_unlock_bh(&mrt_lock); write_unlock_bh(&mrt_lock);
mroute_clean_tables(mrt); mroute_clean_tables(mrt, false);
err = 0; err = 0;
break; break;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment