Skip to content

Commit

Permalink
net/ipv6: Pass net namespace to route functions
Browse files Browse the repository at this point in the history
Pass network namespace reference into route add, delete and get
functions.

Signed-off-by: David Ahern <dsahern@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
David Ahern authored and David S. Miller committed Apr 18, 2018
1 parent 7aef685 commit afb1d4b
Show file tree
Hide file tree
Showing 5 changed files with 66 additions and 55 deletions.
12 changes: 7 additions & 5 deletions include/net/ip6_route.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,8 +101,8 @@ void ip6_route_cleanup(void);
int ipv6_route_ioctl(struct net *net, unsigned int cmd, void __user *arg);

int ip6_route_add(struct fib6_config *cfg, struct netlink_ext_ack *extack);
int ip6_ins_rt(struct rt6_info *);
int ip6_del_rt(struct rt6_info *);
int ip6_ins_rt(struct net *net, struct rt6_info *rt);
int ip6_del_rt(struct net *net, struct rt6_info *rt);

void rt6_flush_exceptions(struct rt6_info *rt);
int rt6_remove_exception_rt(struct rt6_info *rt);
Expand Down Expand Up @@ -137,7 +137,7 @@ struct dst_entry *icmp6_dst_alloc(struct net_device *dev, struct flowi6 *fl6);

void fib6_force_start_gc(struct net *net);

struct rt6_info *addrconf_dst_alloc(struct inet6_dev *idev,
struct rt6_info *addrconf_dst_alloc(struct net *net, struct inet6_dev *idev,
const struct in6_addr *addr, bool anycast);

struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
Expand All @@ -147,9 +147,11 @@ struct rt6_info *ip6_dst_alloc(struct net *net, struct net_device *dev,
* support functions for ND
*
*/
struct rt6_info *rt6_get_dflt_router(const struct in6_addr *addr,
struct rt6_info *rt6_get_dflt_router(struct net *net,
const struct in6_addr *addr,
struct net_device *dev);
struct rt6_info *rt6_add_dflt_router(const struct in6_addr *gwaddr,
struct rt6_info *rt6_add_dflt_router(struct net *net,
const struct in6_addr *gwaddr,
struct net_device *dev, unsigned int pref);

void rt6_purge_dflt_routers(struct net *net);
Expand Down
33 changes: 18 additions & 15 deletions net/ipv6/addrconf.c
Original file line number Diff line number Diff line change
Expand Up @@ -1037,7 +1037,7 @@ ipv6_add_addr(struct inet6_dev *idev, const struct in6_addr *addr,
goto out;
}

rt = addrconf_dst_alloc(idev, addr, false);
rt = addrconf_dst_alloc(net, idev, addr, false);
if (IS_ERR(rt)) {
err = PTR_ERR(rt);
rt = NULL;
Expand Down Expand Up @@ -1187,7 +1187,7 @@ cleanup_prefix_route(struct inet6_ifaddr *ifp, unsigned long expires, bool del_r
0, RTF_GATEWAY | RTF_DEFAULT);
if (rt) {
if (del_rt)
ip6_del_rt(rt);
ip6_del_rt(dev_net(ifp->idev->dev), rt);
else {
if (!(rt->rt6i_flags & RTF_EXPIRES))
rt6_set_expires(rt, expires);
Expand Down Expand Up @@ -2666,7 +2666,7 @@ void addrconf_prefix_rcv(struct net_device *dev, u8 *opt, int len, bool sllao)
if (rt) {
/* Autoconf prefix route */
if (valid_lft == 0) {
ip6_del_rt(rt);
ip6_del_rt(net, rt);
rt = NULL;
} else if (addrconf_finite_timeout(rt_expires)) {
/* not infinity */
Expand Down Expand Up @@ -3333,7 +3333,8 @@ static void addrconf_gre_config(struct net_device *dev)
}
#endif

static int fixup_permanent_addr(struct inet6_dev *idev,
static int fixup_permanent_addr(struct net *net,
struct inet6_dev *idev,
struct inet6_ifaddr *ifp)
{
/* !rt6i_node means the host route was removed from the
Expand All @@ -3343,7 +3344,7 @@ static int fixup_permanent_addr(struct inet6_dev *idev,
if (!ifp->rt || !ifp->rt->rt6i_node) {
struct rt6_info *rt, *prev;

rt = addrconf_dst_alloc(idev, &ifp->addr, false);
rt = addrconf_dst_alloc(net, idev, &ifp->addr, false);
if (IS_ERR(rt))
return PTR_ERR(rt);

Expand All @@ -3367,7 +3368,7 @@ static int fixup_permanent_addr(struct inet6_dev *idev,
return 0;
}

static void addrconf_permanent_addr(struct net_device *dev)
static void addrconf_permanent_addr(struct net *net, struct net_device *dev)
{
struct inet6_ifaddr *ifp, *tmp;
struct inet6_dev *idev;
Expand All @@ -3380,7 +3381,7 @@ static void addrconf_permanent_addr(struct net_device *dev)

list_for_each_entry_safe(ifp, tmp, &idev->addr_list, if_list) {
if ((ifp->flags & IFA_F_PERMANENT) &&
fixup_permanent_addr(idev, ifp) < 0) {
fixup_permanent_addr(net, idev, ifp) < 0) {
write_unlock_bh(&idev->lock);
in6_ifa_hold(ifp);
ipv6_del_addr(ifp);
Expand Down Expand Up @@ -3449,7 +3450,7 @@ static int addrconf_notify(struct notifier_block *this, unsigned long event,

if (event == NETDEV_UP) {
/* restore routes for permanent addresses */
addrconf_permanent_addr(dev);
addrconf_permanent_addr(net, dev);

if (!addrconf_link_ready(dev)) {
/* device is not ready yet. */
Expand Down Expand Up @@ -3735,7 +3736,7 @@ static int addrconf_ifdown(struct net_device *dev, int how)
spin_unlock_bh(&ifa->lock);

if (rt)
ip6_del_rt(rt);
ip6_del_rt(net, rt);

if (state != INET6_IFADDR_STATE_DEAD) {
__ipv6_ifa_notify(RTM_DELADDR, ifa);
Expand Down Expand Up @@ -3853,6 +3854,7 @@ static void addrconf_dad_begin(struct inet6_ifaddr *ifp)
struct inet6_dev *idev = ifp->idev;
struct net_device *dev = idev->dev;
bool bump_id, notify = false;
struct net *net;

addrconf_join_solict(dev, &ifp->addr);

Expand All @@ -3863,8 +3865,9 @@ static void addrconf_dad_begin(struct inet6_ifaddr *ifp)
if (ifp->state == INET6_IFADDR_STATE_DEAD)
goto out;

net = dev_net(dev);
if (dev->flags&(IFF_NOARP|IFF_LOOPBACK) ||
(dev_net(dev)->ipv6.devconf_all->accept_dad < 1 &&
(net->ipv6.devconf_all->accept_dad < 1 &&
idev->cnf.accept_dad < 1) ||
!(ifp->flags&IFA_F_TENTATIVE) ||
ifp->flags & IFA_F_NODAD) {
Expand Down Expand Up @@ -3900,8 +3903,8 @@ static void addrconf_dad_begin(struct inet6_ifaddr *ifp)
* Frames right away
*/
if (ifp->flags & IFA_F_OPTIMISTIC) {
ip6_ins_rt(ifp->rt);
if (ipv6_use_optimistic_addr(dev_net(dev), idev)) {
ip6_ins_rt(net, ifp->rt);
if (ipv6_use_optimistic_addr(net, idev)) {
/* Because optimistic nodes can use this address,
* notify listeners. If DAD fails, RTM_DELADDR is sent.
*/
Expand Down Expand Up @@ -5604,7 +5607,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
* to do it again
*/
if (!rcu_access_pointer(ifp->rt->rt6i_node))
ip6_ins_rt(ifp->rt);
ip6_ins_rt(net, ifp->rt);
if (ifp->idev->cnf.forwarding)
addrconf_join_anycast(ifp);
if (!ipv6_addr_any(&ifp->peer_addr))
Expand All @@ -5621,11 +5624,11 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
rt = addrconf_get_prefix_route(&ifp->peer_addr, 128,
ifp->idev->dev, 0, 0);
if (rt)
ip6_del_rt(rt);
ip6_del_rt(net, rt);
}
if (ifp->rt) {
if (dst_hold_safe(&ifp->rt->dst))
ip6_del_rt(ifp->rt);
ip6_del_rt(net, ifp->rt);
}
rt_genid_bump_ipv6(net);
break;
Expand Down
10 changes: 6 additions & 4 deletions net/ipv6/anycast.c
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,7 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
{
struct ifacaddr6 *aca;
struct rt6_info *rt;
struct net *net;
int err;

ASSERT_RTNL();
Expand All @@ -265,7 +266,8 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
}
}

rt = addrconf_dst_alloc(idev, addr, true);
net = dev_net(idev->dev);
rt = addrconf_dst_alloc(net, idev, addr, true);
if (IS_ERR(rt)) {
err = PTR_ERR(rt);
goto out;
Expand All @@ -286,7 +288,7 @@ int __ipv6_dev_ac_inc(struct inet6_dev *idev, const struct in6_addr *addr)
aca_get(aca);
write_unlock_bh(&idev->lock);

ip6_ins_rt(rt);
ip6_ins_rt(net, rt);

addrconf_join_solict(idev->dev, &aca->aca_addr);

Expand Down Expand Up @@ -329,7 +331,7 @@ int __ipv6_dev_ac_dec(struct inet6_dev *idev, const struct in6_addr *addr)
addrconf_leave_solict(idev, &aca->aca_addr);

dst_hold(&aca->aca_rt->dst);
ip6_del_rt(aca->aca_rt);
ip6_del_rt(dev_net(idev->dev), aca->aca_rt);

aca_put(aca);
return 0;
Expand Down Expand Up @@ -357,7 +359,7 @@ void ipv6_ac_destroy_dev(struct inet6_dev *idev)
addrconf_leave_solict(idev, &aca->aca_addr);

dst_hold(&aca->aca_rt->dst);
ip6_del_rt(aca->aca_rt);
ip6_del_rt(dev_net(idev->dev), aca->aca_rt);

aca_put(aca);

Expand Down
12 changes: 7 additions & 5 deletions net/ipv6/ndisc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1156,6 +1156,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
struct neighbour *neigh = NULL;
struct inet6_dev *in6_dev;
struct rt6_info *rt = NULL;
struct net *net;
int lifetime;
struct ndisc_options ndopts;
int optlen;
Expand Down Expand Up @@ -1253,9 +1254,9 @@ static void ndisc_router_discovery(struct sk_buff *skb)
/* Do not accept RA with source-addr found on local machine unless
* accept_ra_from_local is set to true.
*/
net = dev_net(in6_dev->dev);
if (!in6_dev->cnf.accept_ra_from_local &&
ipv6_chk_addr(dev_net(in6_dev->dev), &ipv6_hdr(skb)->saddr,
in6_dev->dev, 0)) {
ipv6_chk_addr(net, &ipv6_hdr(skb)->saddr, in6_dev->dev, 0)) {
ND_PRINTK(2, info,
"RA from local address detected on dev: %s: default router ignored\n",
skb->dev->name);
Expand All @@ -1272,7 +1273,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
pref = ICMPV6_ROUTER_PREF_MEDIUM;
#endif

rt = rt6_get_dflt_router(&ipv6_hdr(skb)->saddr, skb->dev);
rt = rt6_get_dflt_router(net, &ipv6_hdr(skb)->saddr, skb->dev);

if (rt) {
neigh = dst_neigh_lookup(&rt->dst, &ipv6_hdr(skb)->saddr);
Expand All @@ -1285,7 +1286,7 @@ static void ndisc_router_discovery(struct sk_buff *skb)
}
}
if (rt && lifetime == 0) {
ip6_del_rt(rt);
ip6_del_rt(net, rt);
rt = NULL;
}

Expand All @@ -1294,7 +1295,8 @@ static void ndisc_router_discovery(struct sk_buff *skb)
if (!rt && lifetime) {
ND_PRINTK(3, info, "RA: adding default router\n");

rt = rt6_add_dflt_router(&ipv6_hdr(skb)->saddr, skb->dev, pref);
rt = rt6_add_dflt_router(net, &ipv6_hdr(skb)->saddr,
skb->dev, pref);
if (!rt) {
ND_PRINTK(0, err,
"RA: %s failed to add default route\n",
Expand Down
Loading

0 comments on commit afb1d4b

Please sign in to comment.