aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEric Dumazet <edumazet@google.com>2015-02-17 06:19:24 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-20 15:24:04 -0500
commit959d10f6bbf6ab5b8813c4e37540a2e43ca2ae96 (patch)
treee6175dbec05d9cbc0cdcb4c7c6fa10030d25877f
parent64bea46e3ff28701aa34be48b93c7907ebbdb31e (diff)
igmp: add __ip_mc_{join|leave}_group()
There is a need to perform igmp join/leave operations while RTNL is held. Make ip_mc_{join|leave}_group() wrappers around __ip_mc_{join|leave}_group() to avoid the proliferation of work queues. For example, vxlan_igmp_join() could possibly be removed. Signed-off-by: Eric Dumazet <edumazet@google.com> Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r--include/linux/igmp.h2
-rw-r--r--net/ipv4/igmp.c52
2 files changed, 36 insertions, 18 deletions
diff --git a/include/linux/igmp.h b/include/linux/igmp.h
index 2c677afeea47..b5a6470e686c 100644
--- a/include/linux/igmp.h
+++ b/include/linux/igmp.h
@@ -111,7 +111,9 @@ struct ip_mc_list {
111 111
112extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u16 proto); 112extern int ip_check_mc_rcu(struct in_device *dev, __be32 mc_addr, __be32 src_addr, u16 proto);
113extern int igmp_rcv(struct sk_buff *); 113extern int igmp_rcv(struct sk_buff *);
114extern int __ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
114extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr); 115extern int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr);
116extern int __ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
115extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr); 117extern int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr);
116extern void ip_mc_drop_socket(struct sock *sk); 118extern void ip_mc_drop_socket(struct sock *sk);
117extern int ip_mc_source(int add, int omode, struct sock *sk, 119extern int ip_mc_source(int add, int omode, struct sock *sk,
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 666cf364df86..4b1172d73e03 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -1849,30 +1849,25 @@ static void ip_mc_clear_src(struct ip_mc_list *pmc)
1849 pmc->sfcount[MCAST_EXCLUDE] = 1; 1849 pmc->sfcount[MCAST_EXCLUDE] = 1;
1850} 1850}
1851 1851
1852 1852int __ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr)
1853/*
1854 * Join a multicast group
1855 */
1856int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1857{ 1853{
1858 int err;
1859 __be32 addr = imr->imr_multiaddr.s_addr; 1854 __be32 addr = imr->imr_multiaddr.s_addr;
1860 struct ip_mc_socklist *iml = NULL, *i; 1855 struct ip_mc_socklist *iml, *i;
1861 struct in_device *in_dev; 1856 struct in_device *in_dev;
1862 struct inet_sock *inet = inet_sk(sk); 1857 struct inet_sock *inet = inet_sk(sk);
1863 struct net *net = sock_net(sk); 1858 struct net *net = sock_net(sk);
1864 int ifindex; 1859 int ifindex;
1865 int count = 0; 1860 int count = 0;
1861 int err;
1862
1863 ASSERT_RTNL();
1866 1864
1867 if (!ipv4_is_multicast(addr)) 1865 if (!ipv4_is_multicast(addr))
1868 return -EINVAL; 1866 return -EINVAL;
1869 1867
1870 rtnl_lock();
1871
1872 in_dev = ip_mc_find_dev(net, imr); 1868 in_dev = ip_mc_find_dev(net, imr);
1873 1869
1874 if (!in_dev) { 1870 if (!in_dev) {
1875 iml = NULL;
1876 err = -ENODEV; 1871 err = -ENODEV;
1877 goto done; 1872 goto done;
1878 } 1873 }
@@ -1900,9 +1895,22 @@ int ip_mc_join_group(struct sock *sk , struct ip_mreqn *imr)
1900 ip_mc_inc_group(in_dev, addr); 1895 ip_mc_inc_group(in_dev, addr);
1901 err = 0; 1896 err = 0;
1902done: 1897done:
1903 rtnl_unlock();
1904 return err; 1898 return err;
1905} 1899}
1900EXPORT_SYMBOL(__ip_mc_join_group);
1901
1902/* Join a multicast group
1903 */
1904int ip_mc_join_group(struct sock *sk, struct ip_mreqn *imr)
1905{
1906 int ret;
1907
1908 rtnl_lock();
1909 ret = __ip_mc_join_group(sk, imr);
1910 rtnl_unlock();
1911
1912 return ret;
1913}
1906EXPORT_SYMBOL(ip_mc_join_group); 1914EXPORT_SYMBOL(ip_mc_join_group);
1907 1915
1908static int ip_mc_leave_src(struct sock *sk, struct ip_mc_socklist *iml, 1916static int ip_mc_leave_src(struct sock *sk, struct ip_mc_socklist *iml,
@@ -1925,11 +1933,7 @@ static int ip_mc_leave_src(struct sock *sk, struct ip_mc_socklist *iml,
1925 return err; 1933 return err;
1926} 1934}
1927 1935
1928/* 1936int __ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1929 * Ask a socket to leave a group.
1930 */
1931
1932int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1933{ 1937{
1934 struct inet_sock *inet = inet_sk(sk); 1938 struct inet_sock *inet = inet_sk(sk);
1935 struct ip_mc_socklist *iml; 1939 struct ip_mc_socklist *iml;
@@ -1940,7 +1944,8 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1940 u32 ifindex; 1944 u32 ifindex;
1941 int ret = -EADDRNOTAVAIL; 1945 int ret = -EADDRNOTAVAIL;
1942 1946
1943 rtnl_lock(); 1947 ASSERT_RTNL();
1948
1944 in_dev = ip_mc_find_dev(net, imr); 1949 in_dev = ip_mc_find_dev(net, imr);
1945 if (!in_dev) { 1950 if (!in_dev) {
1946 ret = -ENODEV; 1951 ret = -ENODEV;
@@ -1964,14 +1969,25 @@ int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1964 *imlp = iml->next_rcu; 1969 *imlp = iml->next_rcu;
1965 1970
1966 ip_mc_dec_group(in_dev, group); 1971 ip_mc_dec_group(in_dev, group);
1967 rtnl_unlock(); 1972
1968 /* decrease mem now to avoid the memleak warning */ 1973 /* decrease mem now to avoid the memleak warning */
1969 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc); 1974 atomic_sub(sizeof(*iml), &sk->sk_omem_alloc);
1970 kfree_rcu(iml, rcu); 1975 kfree_rcu(iml, rcu);
1971 return 0; 1976 return 0;
1972 } 1977 }
1973out: 1978out:
1979 return ret;
1980}
1981EXPORT_SYMBOL(__ip_mc_leave_group);
1982
1983int ip_mc_leave_group(struct sock *sk, struct ip_mreqn *imr)
1984{
1985 int ret;
1986
1987 rtnl_lock();
1988 ret = __ip_mc_leave_group(sk, imr);
1974 rtnl_unlock(); 1989 rtnl_unlock();
1990
1975 return ret; 1991 return ret;
1976} 1992}
1977EXPORT_SYMBOL(ip_mc_leave_group); 1993EXPORT_SYMBOL(ip_mc_leave_group);