summaryrefslogtreecommitdiffstats
path: root/net/ipv4
diff options
context:
space:
mode:
authorDavid S. Miller <davem@davemloft.net>2015-02-27 16:25:30 -0500
committerDavid S. Miller <davem@davemloft.net>2015-02-27 16:25:30 -0500
commit7705f730372d65f73599f0b49e3249433bba55e8 (patch)
tree3cc79521cb6dbcd600384507329ecef93ae618ab /net/ipv4
parent723b8e460d87e957f251dc5764f4ab86af6ab44e (diff)
parent93a714d6b53d87872e552dbb273544bdeaaf6e12 (diff)
downloadlinux-stable-7705f730372d65f73599f0b49e3249433bba55e8.tar.gz
linux-stable-7705f730372d65f73599f0b49e3249433bba55e8.tar.bz2
linux-stable-7705f730372d65f73599f0b49e3249433bba55e8.zip
Merge branch 'ip_level_multicast_join_leave'
Madhu Challa says: ==================== Multicast group join/leave at ip level This series enables configuring multicast group join/leave at ip level by extending the "ip address" command. It adds a new control socket mc_autojoin_sock and ifa_flag IFA_F_MCAUTOJOIN to invoke the corresponding igmp group join/leave api. Since the igmp group join/leave api takes the rtnl_lock the code had to be refactored by adding a shim layer prefixed by __ that can be invoked by code that already has the rtnl_lock. This way we avoid proliferation of work queues. The first patch in this series does the refactoring for igmp v6. Its based on igmp v4 changes that were added by Eric Dumazet. The second patch in this series does the group join/leave based on the setting of the IFA_F_MCAUTOJOIN flag. v5: - addressed comments from Daniel Borkmann. - removed blank line in patch 1/2 - removed unused variable, const arg in patch 2/2 v4: - addressed comments from Yoshifuji Hideaki. - Remove WARN_ON not needed because we return a value from v2. - addressed comments from Daniel Borkmann. - rename sock to mc_autojoin_sk - ip_mc_config() pass ifa so it needs one less argument. - igmp_net_{init|destroy}() use inet_ctl_sock_{create|destroy} - inet_rtm_newaddr() change scope of ret. - igmp_net_init() no need to initialize sock to NULL. v3: - addressed comments from David Miller. - fixed indentation and local variable order. v2: - addressed comments from Eric Dumazet. - removed workqueue and call __ip_mc_{join|leave}_group or __ipv6_sock_mc_{join|drop} ==================== Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv4')
-rw-r--r--net/ipv4/devinet.c31
-rw-r--r--net/ipv4/igmp.c13
2 files changed, 44 insertions, 0 deletions
diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
index 3a8985c94581..5105759e4e00 100644
--- a/net/ipv4/devinet.c
+++ b/net/ipv4/devinet.c
@@ -548,6 +548,26 @@ struct in_ifaddr *inet_ifa_byprefix(struct in_device *in_dev, __be32 prefix,
return NULL;
}
+static int ip_mc_config(struct sock *sk, bool join, const struct in_ifaddr *ifa)
+{
+ struct ip_mreqn mreq = {
+ .imr_multiaddr.s_addr = ifa->ifa_address,
+ .imr_ifindex = ifa->ifa_dev->dev->ifindex,
+ };
+ int ret;
+
+ ASSERT_RTNL();
+
+ lock_sock(sk);
+ if (join)
+ ret = __ip_mc_join_group(sk, &mreq);
+ else
+ ret = __ip_mc_leave_group(sk, &mreq);
+ release_sock(sk);
+
+ return ret;
+}
+
static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
{
struct net *net = sock_net(skb->sk);
@@ -584,6 +604,8 @@ static int inet_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh)
!inet_ifa_match(nla_get_be32(tb[IFA_ADDRESS]), ifa)))
continue;
+ if (ipv4_is_multicast(ifa->ifa_address))
+ ip_mc_config(net->ipv4.mc_autojoin_sk, false, ifa);
__inet_del_ifa(in_dev, ifap, 1, nlh, NETLINK_CB(skb).portid);
return 0;
}
@@ -838,6 +860,15 @@ static int inet_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh)
* userspace already relies on not having to provide this.
*/
set_ifa_lifetime(ifa, valid_lft, prefered_lft);
+ if (ifa->ifa_flags & IFA_F_MCAUTOJOIN) {
+ int ret = ip_mc_config(net->ipv4.mc_autojoin_sk,
+ true, ifa);
+
+ if (ret < 0) {
+ inet_free_ifa(ifa);
+ return ret;
+ }
+ }
return __inet_insert_ifa(ifa, nlh, NETLINK_CB(skb).portid);
} else {
inet_free_ifa(ifa);
diff --git a/net/ipv4/igmp.c b/net/ipv4/igmp.c
index 4b1172d73e03..5cb1ef4ce292 100644
--- a/net/ipv4/igmp.c
+++ b/net/ipv4/igmp.c
@@ -97,6 +97,7 @@
#include <net/route.h>
#include <net/sock.h>
#include <net/checksum.h>
+#include <net/inet_common.h>
#include <linux/netfilter_ipv4.h>
#ifdef CONFIG_IP_MROUTE
#include <linux/mroute.h>
@@ -2740,6 +2741,7 @@ static const struct file_operations igmp_mcf_seq_fops = {
static int __net_init igmp_net_init(struct net *net)
{
struct proc_dir_entry *pde;
+ int err;
pde = proc_create("igmp", S_IRUGO, net->proc_net, &igmp_mc_seq_fops);
if (!pde)
@@ -2748,8 +2750,18 @@ static int __net_init igmp_net_init(struct net *net)
&igmp_mcf_seq_fops);
if (!pde)
goto out_mcfilter;
+ err = inet_ctl_sock_create(&net->ipv4.mc_autojoin_sk, AF_INET,
+ SOCK_DGRAM, 0, net);
+ if (err < 0) {
+ pr_err("Failed to initialize the IGMP autojoin socket (err %d)\n",
+ err);
+ goto out_sock;
+ }
+
return 0;
+out_sock:
+ remove_proc_entry("mcfilter", net->proc_net);
out_mcfilter:
remove_proc_entry("igmp", net->proc_net);
out_igmp:
@@ -2760,6 +2772,7 @@ static void __net_exit igmp_net_exit(struct net *net)
{
remove_proc_entry("mcfilter", net->proc_net);
remove_proc_entry("igmp", net->proc_net);
+ inet_ctl_sock_destroy(net->ipv4.mc_autojoin_sk);
}
static struct pernet_operations igmp_net_ops = {