aboutsummaryrefslogtreecommitdiffstats
path: root/net/ipv6/addrconf.c
diff options
context:
space:
mode:
authorHannes Frederic Sowa <hannes@stressinduktion.org>2014-01-16 14:13:04 -0500
committerDavid S. Miller <davem@davemloft.net>2014-01-17 21:10:01 -0500
commit11ffff752c6a5adc86f7dd397b2f75af8f917c51 (patch)
tree857e74e69def8f491d7d3eca9ee84497122cd81f /net/ipv6/addrconf.c
parent77f99ad16a07aa062c2d30fae57b1fee456f6ef6 (diff)
ipv6: simplify detection of first operational link-local address on interface
In commit 1ec047eb4751e3 ("ipv6: introduce per-interface counter for dad-completed ipv6 addresses") I build the detection of the first operational link-local address much to complex. Additionally this code now has a race condition. Replace it with a much simpler variant, which just scans the address list when duplicate address detection completes, to check if this is the first valid link local address and send RS and MLD reports then. Fixes: 1ec047eb4751e3 ("ipv6: introduce per-interface counter for dad-completed ipv6 addresses") Reported-by: Jiri Pirko <jiri@resnulli.us> Cc: Flavio Leitner <fbl@redhat.com> Signed-off-by: Hannes Frederic Sowa <hannes@stressinduktion.org> Acked-by: Flavio Leitner <fbl@redhat.com> Acked-by: Jiri Pirko <jiri@resnulli.us> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net/ipv6/addrconf.c')
-rw-r--r--net/ipv6/addrconf.c38
1 files changed, 17 insertions, 21 deletions
diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
index abe46a4228ce..4b6b720971b9 100644
--- a/net/ipv6/addrconf.c
+++ b/net/ipv6/addrconf.c
@@ -3189,6 +3189,22 @@ out:
3189 in6_ifa_put(ifp); 3189 in6_ifa_put(ifp);
3190} 3190}
3191 3191
3192/* ifp->idev must be at least read locked */
3193static bool ipv6_lonely_lladdr(struct inet6_ifaddr *ifp)
3194{
3195 struct inet6_ifaddr *ifpiter;
3196 struct inet6_dev *idev = ifp->idev;
3197
3198 list_for_each_entry(ifpiter, &idev->addr_list, if_list) {
3199 if (ifp != ifpiter && ifpiter->scope == IFA_LINK &&
3200 (ifpiter->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE|
3201 IFA_F_OPTIMISTIC|IFA_F_DADFAILED)) ==
3202 IFA_F_PERMANENT)
3203 return false;
3204 }
3205 return true;
3206}
3207
3192static void addrconf_dad_completed(struct inet6_ifaddr *ifp) 3208static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
3193{ 3209{
3194 struct net_device *dev = ifp->idev->dev; 3210 struct net_device *dev = ifp->idev->dev;
@@ -3208,14 +3224,11 @@ static void addrconf_dad_completed(struct inet6_ifaddr *ifp)
3208 */ 3224 */
3209 3225
3210 read_lock_bh(&ifp->idev->lock); 3226 read_lock_bh(&ifp->idev->lock);
3211 spin_lock(&ifp->lock); 3227 send_mld = ifp->scope == IFA_LINK && ipv6_lonely_lladdr(ifp);
3212 send_mld = ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL &&
3213 ifp->idev->valid_ll_addr_cnt == 1;
3214 send_rs = send_mld && 3228 send_rs = send_mld &&
3215 ipv6_accept_ra(ifp->idev) && 3229 ipv6_accept_ra(ifp->idev) &&
3216 ifp->idev->cnf.rtr_solicits > 0 && 3230 ifp->idev->cnf.rtr_solicits > 0 &&
3217 (dev->flags&IFF_LOOPBACK) == 0; 3231 (dev->flags&IFF_LOOPBACK) == 0;
3218 spin_unlock(&ifp->lock);
3219 read_unlock_bh(&ifp->idev->lock); 3232 read_unlock_bh(&ifp->idev->lock);
3220 3233
3221 /* While dad is in progress mld report's source address is in6_addrany. 3234 /* While dad is in progress mld report's source address is in6_addrany.
@@ -4512,19 +4525,6 @@ errout:
4512 rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err); 4525 rtnl_set_sk_err(net, RTNLGRP_IPV6_PREFIX, err);
4513} 4526}
4514 4527
4515static void update_valid_ll_addr_cnt(struct inet6_ifaddr *ifp, int count)
4516{
4517 write_lock_bh(&ifp->idev->lock);
4518 spin_lock(&ifp->lock);
4519 if (((ifp->flags & (IFA_F_PERMANENT|IFA_F_TENTATIVE|IFA_F_OPTIMISTIC|
4520 IFA_F_DADFAILED)) == IFA_F_PERMANENT) &&
4521 (ipv6_addr_type(&ifp->addr) & IPV6_ADDR_LINKLOCAL))
4522 ifp->idev->valid_ll_addr_cnt += count;
4523 WARN_ON(ifp->idev->valid_ll_addr_cnt < 0);
4524 spin_unlock(&ifp->lock);
4525 write_unlock_bh(&ifp->idev->lock);
4526}
4527
4528static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp) 4528static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
4529{ 4529{
4530 struct net *net = dev_net(ifp->idev->dev); 4530 struct net *net = dev_net(ifp->idev->dev);
@@ -4533,8 +4533,6 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
4533 4533
4534 switch (event) { 4534 switch (event) {
4535 case RTM_NEWADDR: 4535 case RTM_NEWADDR:
4536 update_valid_ll_addr_cnt(ifp, 1);
4537
4538 /* 4536 /*
4539 * If the address was optimistic 4537 * If the address was optimistic
4540 * we inserted the route at the start of 4538 * we inserted the route at the start of
@@ -4550,8 +4548,6 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
4550 ifp->idev->dev, 0, 0); 4548 ifp->idev->dev, 0, 0);
4551 break; 4549 break;
4552 case RTM_DELADDR: 4550 case RTM_DELADDR:
4553 update_valid_ll_addr_cnt(ifp, -1);
4554
4555 if (ifp->idev->cnf.forwarding) 4551 if (ifp->idev->cnf.forwarding)
4556 addrconf_leave_anycast(ifp); 4552 addrconf_leave_anycast(ifp);
4557 addrconf_leave_solict(ifp->idev, &ifp->addr); 4553 addrconf_leave_solict(ifp->idev, &ifp->addr);