diff options
author | David L Stevens <dlstevens@us.ibm.com> | 2006-08-17 19:27:39 -0400 |
---|---|---|
committer | David S. Miller <davem@sunset.davemloft.net> | 2006-08-17 19:29:57 -0400 |
commit | acd6e00b8e4db542cb6bc9ddfbb4e18bbe29ce4d (patch) | |
tree | f644e1ee2a5d85b1d680897105ad8f38a562cfc1 /net | |
parent | c7fa9d189e93877a1fa08ab00f230e0689125e45 (diff) |
[MCAST]: Fix filter leak on device removal.
This fixes source filter leakage when a device is removed and a
process leaves the group thereafter.
This also includes corresponding fixes for IPv6 multicast source
filters on device removal.
Signed-off-by: David L Stevens <dlstevens@us.ibm.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/igmp.c | 32 | ||||
-rw-r--r-- | net/ipv6/mcast.c | 10 |
2 files changed, 25 insertions, 17 deletions
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c index e981369ebe13..8e8117c19e4d 100644 --- a/net/ipv4/igmp.c +++ b/net/ipv4/igmp.c | |||
@@ -1793,29 +1793,35 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr) | |||
1793 | struct in_device *in_dev; | 1793 | struct in_device *in_dev; |
1794 | u32 group = imr->imr_multiaddr.s_addr; | 1794 | u32 group = imr->imr_multiaddr.s_addr; |
1795 | u32 ifindex; | 1795 | u32 ifindex; |
1796 | int ret = -EADDRNOTAVAIL; | ||
1796 | 1797 | ||
1797 | rtnl_lock(); | 1798 | rtnl_lock(); |
1798 | in_dev = ip_mc_find_dev(imr); | 1799 | in_dev = ip_mc_find_dev(imr); |
1799 | if (!in_dev) { | ||
1800 | rtnl_unlock(); | ||
1801 | return -ENODEV; | ||
1802 | } | ||
1803 | ifindex = imr->imr_ifindex; | 1800 | ifindex = imr->imr_ifindex; |
1804 | for (imlp = &inet->mc_list; (iml = *imlp) != NULL; imlp = &iml->next) { | 1801 | for (imlp = &inet->mc_list; (iml = *imlp) != NULL; imlp = &iml->next) { |
1805 | if (iml->multi.imr_multiaddr.s_addr == group && | 1802 | if (iml->multi.imr_multiaddr.s_addr != group) |
1806 | iml->multi.imr_ifindex == ifindex) { | 1803 | continue; |
1807 | (void) ip_mc_leave_src(sk, iml, in_dev); | 1804 | if (ifindex) { |
1805 | if (iml->multi.imr_ifindex != ifindex) | ||
1806 | continue; | ||
1807 | } else if (imr->imr_address.s_addr && imr->imr_address.s_addr != | ||
1808 | iml->multi.imr_address.s_addr) | ||
1809 | continue; | ||
1808 | 1810 | ||
1809 | *imlp = iml->next; | 1811 | (void) ip_mc_leave_src(sk, iml, in_dev); |
1810 | 1812 | ||
1813 | *imlp = iml->next; | ||
1814 | |||
1815 | if (in_dev) | ||
1811 | ip_mc_dec_group(in_dev, group); | 1816 | ip_mc_dec_group(in_dev, group); |
1812 | rtnl_unlock(); | 1817 | rtnl_unlock(); |
1813 | sock_kfree_s(sk, iml, sizeof(*iml)); | 1818 | sock_kfree_s(sk, iml, sizeof(*iml)); |
1814 | return 0; | 1819 | return 0; |
1815 | } | ||
1816 | } | 1820 | } |
1821 | if (!in_dev) | ||
1822 | ret = -ENODEV; | ||
1817 | rtnl_unlock(); | 1823 | rtnl_unlock(); |
1818 | return -EADDRNOTAVAIL; | 1824 | return ret; |
1819 | } | 1825 | } |
1820 | 1826 | ||
1821 | int ip_mc_source(int add, int omode, struct sock *sk, struct | 1827 | int ip_mc_source(int add, int omode, struct sock *sk, struct |
diff --git a/net/ipv6/mcast.c b/net/ipv6/mcast.c index 9d697d4dcffc..639eb20c9f1f 100644 --- a/net/ipv6/mcast.c +++ b/net/ipv6/mcast.c | |||
@@ -268,13 +268,14 @@ int ipv6_sock_mc_drop(struct sock *sk, int ifindex, struct in6_addr *addr) | |||
268 | if ((dev = dev_get_by_index(mc_lst->ifindex)) != NULL) { | 268 | if ((dev = dev_get_by_index(mc_lst->ifindex)) != NULL) { |
269 | struct inet6_dev *idev = in6_dev_get(dev); | 269 | struct inet6_dev *idev = in6_dev_get(dev); |
270 | 270 | ||
271 | (void) ip6_mc_leave_src(sk, mc_lst, idev); | ||
271 | if (idev) { | 272 | if (idev) { |
272 | (void) ip6_mc_leave_src(sk,mc_lst,idev); | ||
273 | __ipv6_dev_mc_dec(idev, &mc_lst->addr); | 273 | __ipv6_dev_mc_dec(idev, &mc_lst->addr); |
274 | in6_dev_put(idev); | 274 | in6_dev_put(idev); |
275 | } | 275 | } |
276 | dev_put(dev); | 276 | dev_put(dev); |
277 | } | 277 | } else |
278 | (void) ip6_mc_leave_src(sk, mc_lst, NULL); | ||
278 | sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); | 279 | sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); |
279 | return 0; | 280 | return 0; |
280 | } | 281 | } |
@@ -334,13 +335,14 @@ void ipv6_sock_mc_close(struct sock *sk) | |||
334 | if (dev) { | 335 | if (dev) { |
335 | struct inet6_dev *idev = in6_dev_get(dev); | 336 | struct inet6_dev *idev = in6_dev_get(dev); |
336 | 337 | ||
338 | (void) ip6_mc_leave_src(sk, mc_lst, idev); | ||
337 | if (idev) { | 339 | if (idev) { |
338 | (void) ip6_mc_leave_src(sk, mc_lst, idev); | ||
339 | __ipv6_dev_mc_dec(idev, &mc_lst->addr); | 340 | __ipv6_dev_mc_dec(idev, &mc_lst->addr); |
340 | in6_dev_put(idev); | 341 | in6_dev_put(idev); |
341 | } | 342 | } |
342 | dev_put(dev); | 343 | dev_put(dev); |
343 | } | 344 | } else |
345 | (void) ip6_mc_leave_src(sk, mc_lst, NULL); | ||
344 | 346 | ||
345 | sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); | 347 | sock_kfree_s(sk, mc_lst, sizeof(*mc_lst)); |
346 | 348 | ||