Commit 7198f8ce authored by Thomas Graf's avatar Thomas Graf Committed by David S. Miller

[IPV6] address: Support NLM_F_EXCL when adding addresses

iproute2 doesn't provide the NLM_F_CREATE flag when adding addresses,
it is assumed to be implied. The existing code issues a check on
said flag when the modify operation fails (likely due to ENOENT)
before continueing to create it, this leads to a hard to predict
result, therefore the NLM_F_CREATE check is removed.
Signed-off-by: default avatarThomas Graf <tgraf@suug.ch>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent 680a27a2
...@@ -2908,24 +2908,14 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -2908,24 +2908,14 @@ inet6_rtm_deladdr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen); return inet6_addr_del(ifm->ifa_index, pfx, ifm->ifa_prefixlen);
} }
static int static int inet6_addr_modify(struct inet6_ifaddr *ifp, u32 prefered_lft,
inet6_addr_modify(int ifindex, struct in6_addr *pfx, u32 valid_lft)
__u32 prefered_lft, __u32 valid_lft)
{ {
struct inet6_ifaddr *ifp = NULL;
struct net_device *dev;
int ifa_flags = 0; int ifa_flags = 0;
if ((dev = __dev_get_by_index(ifindex)) == NULL)
return -ENODEV;
if (!valid_lft || (prefered_lft > valid_lft)) if (!valid_lft || (prefered_lft > valid_lft))
return -EINVAL; return -EINVAL;
ifp = ipv6_get_ifaddr(pfx, dev, 1);
if (ifp == NULL)
return -ENOENT;
if (valid_lft == INFINITY_LIFE_TIME) if (valid_lft == INFINITY_LIFE_TIME)
ifa_flags = IFA_F_PERMANENT; ifa_flags = IFA_F_PERMANENT;
else if (valid_lft >= 0x7FFFFFFF/HZ) else if (valid_lft >= 0x7FFFFFFF/HZ)
...@@ -2947,7 +2937,6 @@ inet6_addr_modify(int ifindex, struct in6_addr *pfx, ...@@ -2947,7 +2937,6 @@ inet6_addr_modify(int ifindex, struct in6_addr *pfx,
spin_unlock_bh(&ifp->lock); spin_unlock_bh(&ifp->lock);
if (!(ifp->flags&IFA_F_TENTATIVE)) if (!(ifp->flags&IFA_F_TENTATIVE))
ipv6_ifa_notify(0, ifp); ipv6_ifa_notify(0, ifp);
in6_ifa_put(ifp);
addrconf_verify(0); addrconf_verify(0);
...@@ -2960,6 +2949,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -2960,6 +2949,8 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
struct ifaddrmsg *ifm; struct ifaddrmsg *ifm;
struct nlattr *tb[IFA_MAX+1]; struct nlattr *tb[IFA_MAX+1];
struct in6_addr *pfx; struct in6_addr *pfx;
struct inet6_ifaddr *ifa;
struct net_device *dev;
u32 valid_lft, preferred_lft; u32 valid_lft, preferred_lft;
int err; int err;
...@@ -2983,15 +2974,29 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg) ...@@ -2983,15 +2974,29 @@ inet6_rtm_newaddr(struct sk_buff *skb, struct nlmsghdr *nlh, void *arg)
valid_lft = INFINITY_LIFE_TIME; valid_lft = INFINITY_LIFE_TIME;
} }
if (nlh->nlmsg_flags & NLM_F_REPLACE) { dev = __dev_get_by_index(ifm->ifa_index);
err = inet6_addr_modify(ifm->ifa_index, pfx, if (dev == NULL)
preferred_lft, valid_lft); return -ENODEV;
if (err == 0 || !(nlh->nlmsg_flags & NLM_F_CREATE))
return err;
}
ifa = ipv6_get_ifaddr(pfx, dev, 1);
if (ifa == NULL) {
/*
* It would be best to check for !NLM_F_CREATE here but
* userspace alreay relies on not having to provide this.
*/
return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen, return inet6_addr_add(ifm->ifa_index, pfx, ifm->ifa_prefixlen,
preferred_lft, valid_lft); preferred_lft, valid_lft);
}
if (nlh->nlmsg_flags & NLM_F_EXCL ||
!(nlh->nlmsg_flags & NLM_F_REPLACE))
err = -EEXIST;
else
err = inet6_addr_modify(ifa, preferred_lft, valid_lft);
in6_ifa_put(ifa);
return err;
} }
static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags, static void put_ifaddrmsg(struct nlmsghdr *nlh, u8 prefixlen, u8 flags,
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment