Skip to content

Commit af28493

Browse files
Daniel Lezcanodavem330
authored andcommitted
[NETNS][IPV6] addrconf - Pass the proper network namespace parameters to addrconf
This patch propagates the network namespace pointer to the address configuration routines which need it, which means adding a new parameter to these functions, and make them use it instead of using the initial network namespace. Signed-off-by: Daniel Lezcano <dlezcano@fr.ibm.com> Signed-off-by: Benjamin Thery <benjamin.thery@bull.net> Signed-off-by: David S. Miller <davem@davemloft.net>
1 parent 300bf59 commit af28493

File tree

3 files changed

+57
-24
lines changed

3 files changed

+57
-24
lines changed

include/net/addrconf.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -55,9 +55,12 @@ struct prefix_info {
5555
extern int addrconf_init(void);
5656
extern void addrconf_cleanup(void);
5757

58-
extern int addrconf_add_ifaddr(void __user *arg);
59-
extern int addrconf_del_ifaddr(void __user *arg);
60-
extern int addrconf_set_dstaddr(void __user *arg);
58+
extern int addrconf_add_ifaddr(struct net *net,
59+
void __user *arg);
60+
extern int addrconf_del_ifaddr(struct net *net,
61+
void __user *arg);
62+
extern int addrconf_set_dstaddr(struct net *net,
63+
void __user *arg);
6164

6265
extern int ipv6_chk_addr(struct net *net,
6366
struct in6_addr *addr,

net/ipv6/addrconf.c

Lines changed: 48 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -1866,7 +1866,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len)
18661866
* Special case for SIT interfaces where we create a new "virtual"
18671867
* device.
18681868
*/
1869-
int addrconf_set_dstaddr(void __user *arg)
1869+
int addrconf_set_dstaddr(struct net *net, void __user *arg)
18701870
{
18711871
struct in6_ifreq ireq;
18721872
struct net_device *dev;
@@ -1878,7 +1878,7 @@ int addrconf_set_dstaddr(void __user *arg)
18781878
if (copy_from_user(&ireq, arg, sizeof(struct in6_ifreq)))
18791879
goto err_exit;
18801880

1881-
dev = __dev_get_by_index(&init_net, ireq.ifr6_ifindex);
1881+
dev = __dev_get_by_index(net, ireq.ifr6_ifindex);
18821882

18831883
err = -ENODEV;
18841884
if (dev == NULL)
@@ -1909,7 +1909,8 @@ int addrconf_set_dstaddr(void __user *arg)
19091909

19101910
if (err == 0) {
19111911
err = -ENOBUFS;
1912-
if ((dev = __dev_get_by_name(&init_net, p.name)) == NULL)
1912+
dev = __dev_get_by_name(net, p.name);
1913+
if (!dev)
19131914
goto err_exit;
19141915
err = dev_open(dev);
19151916
}
@@ -1924,8 +1925,9 @@ int addrconf_set_dstaddr(void __user *arg)
19241925
/*
19251926
* Manual configuration of address on an interface
19261927
*/
1927-
static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
1928-
__u8 ifa_flags, __u32 prefered_lft, __u32 valid_lft)
1928+
static int inet6_addr_add(struct net *net, int ifindex, struct in6_addr *pfx,
1929+
int plen, __u8 ifa_flags, __u32 prefered_lft,
1930+
__u32 valid_lft)
19291931
{
19301932
struct inet6_ifaddr *ifp;
19311933
struct inet6_dev *idev;
@@ -1939,7 +1941,8 @@ static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
19391941
if (!valid_lft || prefered_lft > valid_lft)
19401942
return -EINVAL;
19411943

1942-
if ((dev = __dev_get_by_index(&init_net, ifindex)) == NULL)
1944+
dev = __dev_get_by_index(net, ifindex);
1945+
if (!dev)
19431946
return -ENODEV;
19441947

19451948
if ((idev = addrconf_add_dev(dev)) == NULL)
@@ -1984,13 +1987,15 @@ static int inet6_addr_add(int ifindex, struct in6_addr *pfx, int plen,
19841987
return PTR_ERR(ifp);
19851988
}
19861989

1987-
static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
1990+
static int inet6_addr_del(struct net *net, int ifindex, struct in6_addr *pfx,
1991+
int plen)
19881992
{
19891993
struct inet6_ifaddr *ifp;
19901994
struct inet6_dev *idev;
19911995
struct net_device *dev;
19921996

1993-
if ((dev = __dev_get_by_index(&init_net, ifindex)) == NULL)
1997+
dev = __dev_get_by_index(net, ifindex);
1998+
if (!dev)
19941999
return -ENODEV;
19952000

19962001
if ((idev = __in6_dev_get(dev)) == NULL)
@@ -2018,7 +2023,7 @@ static int inet6_addr_del(int ifindex, struct in6_addr *pfx, int plen)
20182023
}
20192024

20202025

2021-
int addrconf_add_ifaddr(void __user *arg)
2026+
int addrconf_add_ifaddr(struct net *net, void __user *arg)
20222027
{
20232028
struct in6_ifreq ireq;
20242029
int err;
@@ -2030,13 +2035,14 @@ int addrconf_add_ifaddr(void __user *arg)
20302035
return -EFAULT;
20312036

20322037
rtnl_lock();
2033-
err = inet6_addr_add(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen,
2034-
IFA_F_PERMANENT, INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
2038+
err = inet6_addr_add(net, ireq.ifr6_ifindex, &ireq.ifr6_addr,
2039+
ireq.ifr6_prefixlen, IFA_F_PERMANENT,
2040+
INFINITY_LIFE_TIME, INFINITY_LIFE_TIME);
20352041
rtnl_unlock();
20362042
return err;
20372043
}
20382044

2039-
int addrconf_del_ifaddr(void __user *arg)
2045+
int addrconf_del_ifaddr(struct net *net, void __user *arg)
20402046
{
20412047
struct in6_ifreq ireq;
20422048
int err;
@@ -2048,7 +2054,8 @@ int addrconf_del_ifaddr(void __user *arg)
20482054
return -EFAULT;
20492055

20502056
rtnl_lock();
2051-
err = inet6_addr_del(ireq.ifr6_ifindex, &ireq.ifr6_addr, ireq.ifr6_prefixlen);
2057+
err = inet6_addr_del(net, ireq.ifr6_ifindex, &ireq.ifr6_addr,
2058+
ireq.ifr6_prefixlen);
20522059
rtnl_unlock();
20532060
return err;
20542061
}
@@ -3061,7 +3068,7 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
30613068
if (pfx == NULL)
30623069
return -EINVAL;
30633070

3064-
return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
3071+
return inet6_addr_del(net, ifm->ifa_index, pfx, ifm->ifa_prefixlen);
30653072
}
30663073

30673074
static int inet6_addr_modify(struct inet6_ifaddr *ifp, u8 ifa_flags,
@@ -3137,7 +3144,7 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
31373144
valid_lft = INFINITY_LIFE_TIME;
31383145
}
31393146

3140-
dev = __dev_get_by_index(&init_net, ifm->ifa_index);
3147+
dev = __dev_get_by_index(net, ifm->ifa_index);
31413148
if (dev == NULL)
31423149
return -ENODEV;
31433150

@@ -3150,8 +3157,9 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
31503157
* It would be best to check for !NLM_F_CREATE here but
31513158
* userspace alreay relies on not having to provide this.
31523159
*/
3153-
return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
3154-
ifa_flags, preferred_lft, valid_lft);
3160+
return inet6_addr_add(net, ifm->ifa_index, pfx,
3161+
ifm->ifa_prefixlen, ifa_flags,
3162+
preferred_lft, valid_lft);
31553163
}
31563164

31573165
if (nlh->nlmsg_flags & NLM_F_EXCL ||
@@ -4260,6 +4268,22 @@ int unregister_inet6addr_notifier(struct notifier_block *nb)
42604268

42614269
EXPORT_SYMBOL(unregister_inet6addr_notifier);
42624270

4271+
4272+
static int addrconf_net_init(struct net *net)
4273+
{
4274+
return 0;
4275+
}
4276+
4277+
static void addrconf_net_exit(struct net *net)
4278+
{
4279+
;
4280+
}
4281+
4282+
static struct pernet_operations addrconf_net_ops = {
4283+
.init = addrconf_net_init,
4284+
.exit = addrconf_net_exit,
4285+
};
4286+
42634287
/*
42644288
* Init / cleanup code
42654289
*/
@@ -4301,6 +4325,10 @@ int __init addrconf_init(void)
43014325
if (err)
43024326
goto errlo;
43034327

4328+
err = register_pernet_device(&addrconf_net_ops);
4329+
if (err)
4330+
return err;
4331+
43044332
register_netdevice_notifier(&ipv6_dev_notf);
43054333

43064334
addrconf_verify(0);
@@ -4334,6 +4362,7 @@ void addrconf_cleanup(void)
43344362
int i;
43354363

43364364
unregister_netdevice_notifier(&ipv6_dev_notf);
4365+
unregister_pernet_device(&addrconf_net_ops);
43374366

43384367
unregister_pernet_subsys(&addrconf_ops);
43394368

@@ -4370,6 +4399,7 @@ void addrconf_cleanup(void)
43704399
write_unlock_bh(&addrconf_hash_lock);
43714400

43724401
del_timer(&addr_chk_timer);
4373-
43744402
rtnl_unlock();
4403+
4404+
unregister_pernet_subsys(&addrconf_net_ops);
43754405
}

net/ipv6/af_inet6.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -454,11 +454,11 @@ int inet6_ioctl(struct socket *sock, unsigned int cmd, unsigned long arg)
454454
return(ipv6_route_ioctl(net, cmd, (void __user *)arg));
455455

456456
case SIOCSIFADDR:
457-
return addrconf_add_ifaddr((void __user *) arg);
457+
return addrconf_add_ifaddr(net, (void __user *) arg);
458458
case SIOCDIFADDR:
459-
return addrconf_del_ifaddr((void __user *) arg);
459+
return addrconf_del_ifaddr(net, (void __user *) arg);
460460
case SIOCSIFDSTADDR:
461-
return addrconf_set_dstaddr((void __user *) arg);
461+
return addrconf_set_dstaddr(net, (void __user *) arg);
462462
default:
463463
if (!sk->sk_prot->ioctl)
464464
return -ENOIOCTLCMD;

0 commit comments

Comments
 (0)