Skip to content

Commit 403dbb9

Browse files
Tom Goffdavem330
authored andcommitted
PIM-SM: namespace changes
IPv4: - make PIM register vifs netns local - set the netns when a PIM register vif is created - make PIM available in all network namespaces (if CONFIG_IP_PIMSM_V2) by adding the protocol handler when multicast routing is initialized IPv6: - make PIM register vifs netns local - make PIM available in all network namespaces (if CONFIG_IPV6_PIMSM_V2) by adding the protocol handler when multicast routing is initialized Signed-off-by: Tom Goff <thomas.goff@boeing.com> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent e61a4b6 commit 403dbb9

2 files changed

Lines changed: 29 additions & 20 deletions

File tree

‎net/ipv4/ipmr.c‎

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,10 @@ static void reg_vif_setup(struct net_device *dev)
226226
dev->flags = IFF_NOARP;
227227
dev->netdev_ops = &reg_vif_netdev_ops,
228228
dev->destructor = free_netdev;
229+
dev->features |= NETIF_F_NETNS_LOCAL;
229230
}
230231

231-
static struct net_device *ipmr_reg_vif(void)
232+
static struct net_device *ipmr_reg_vif(struct net *net)
232233
{
233234
struct net_device *dev;
234235
struct in_device *in_dev;
@@ -238,6 +239,8 @@ static struct net_device *ipmr_reg_vif(void)
238239
if (dev == NULL)
239240
return NULL;
240241

242+
dev_net_set(dev, net);
243+
241244
if (register_netdevice(dev)) {
242245
free_netdev(dev);
243246
return NULL;
@@ -448,7 +451,7 @@ static int vif_add(struct net *net, struct vifctl *vifc, int mrtsock)
448451
*/
449452
if (net->ipv4.mroute_reg_vif_num >= 0)
450453
return -EADDRINUSE;
451-
dev = ipmr_reg_vif();
454+
dev = ipmr_reg_vif(net);
452455
if (!dev)
453456
return -ENOBUFS;
454457
err = dev_set_allmulti(dev, 1);
@@ -1031,16 +1034,6 @@ int ip_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
10311034
if (v != net->ipv4.mroute_do_pim) {
10321035
net->ipv4.mroute_do_pim = v;
10331036
net->ipv4.mroute_do_assert = v;
1034-
#ifdef CONFIG_IP_PIMSM_V2
1035-
if (net->ipv4.mroute_do_pim)
1036-
ret = inet_add_protocol(&pim_protocol,
1037-
IPPROTO_PIM);
1038-
else
1039-
ret = inet_del_protocol(&pim_protocol,
1040-
IPPROTO_PIM);
1041-
if (ret < 0)
1042-
ret = -EAGAIN;
1043-
#endif
10441037
}
10451038
rtnl_unlock();
10461039
return ret;
@@ -1954,6 +1947,7 @@ static const struct file_operations ipmr_mfc_fops = {
19541947
#ifdef CONFIG_IP_PIMSM_V2
19551948
static struct net_protocol pim_protocol = {
19561949
.handler = pim_rcv,
1950+
.netns_ok = 1,
19571951
};
19581952
#endif
19591953

@@ -2040,8 +2034,19 @@ int __init ip_mr_init(void)
20402034
err = register_netdevice_notifier(&ip_mr_notifier);
20412035
if (err)
20422036
goto reg_notif_fail;
2037+
#ifdef CONFIG_IP_PIMSM_V2
2038+
if (inet_add_protocol(&pim_protocol, IPPROTO_PIM) < 0) {
2039+
printk(KERN_ERR "ip_mr_init: can't add PIM protocol\n");
2040+
err = -EAGAIN;
2041+
goto add_proto_fail;
2042+
}
2043+
#endif
20432044
return 0;
20442045

2046+
#ifdef CONFIG_IP_PIMSM_V2
2047+
add_proto_fail:
2048+
unregister_netdevice_notifier(&ip_mr_notifier);
2049+
#endif
20452050
reg_notif_fail:
20462051
del_timer(&ipmr_expire_timer);
20472052
unregister_pernet_subsys(&ipmr_net_ops);

‎net/ipv6/ip6mr.c‎

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -441,6 +441,7 @@ static void reg_vif_setup(struct net_device *dev)
441441
dev->flags = IFF_NOARP;
442442
dev->netdev_ops = &reg_vif_netdev_ops;
443443
dev->destructor = free_netdev;
444+
dev->features |= NETIF_F_NETNS_LOCAL;
444445
}
445446

446447
static struct net_device *ip6mr_reg_vif(struct net *net)
@@ -1077,7 +1078,18 @@ int __init ip6_mr_init(void)
10771078
err = register_netdevice_notifier(&ip6_mr_notifier);
10781079
if (err)
10791080
goto reg_notif_fail;
1081+
#ifdef CONFIG_IPV6_PIMSM_V2
1082+
if (inet6_add_protocol(&pim6_protocol, IPPROTO_PIM) < 0) {
1083+
printk(KERN_ERR "ip6_mr_init: can't add PIM protocol\n");
1084+
err = -EAGAIN;
1085+
goto add_proto_fail;
1086+
}
1087+
#endif
10801088
return 0;
1089+
#ifdef CONFIG_IPV6_PIMSM_V2
1090+
add_proto_fail:
1091+
unregister_netdevice_notifier(&ip6_mr_notifier);
1092+
#endif
10811093
reg_notif_fail:
10821094
del_timer(&ipmr_expire_timer);
10831095
unregister_pernet_subsys(&ip6mr_net_ops);
@@ -1363,14 +1375,6 @@ int ip6_mroute_setsockopt(struct sock *sk, int optname, char __user *optval, int
13631375
if (v != net->ipv6.mroute_do_pim) {
13641376
net->ipv6.mroute_do_pim = v;
13651377
net->ipv6.mroute_do_assert = v;
1366-
if (net->ipv6.mroute_do_pim)
1367-
ret = inet6_add_protocol(&pim6_protocol,
1368-
IPPROTO_PIM);
1369-
else
1370-
ret = inet6_del_protocol(&pim6_protocol,
1371-
IPPROTO_PIM);
1372-
if (ret < 0)
1373-
ret = -EAGAIN;
13741378
}
13751379
rtnl_unlock();
13761380
return ret;

0 commit comments

Comments
 (0)