ipv6: order addresses by scope
Subsystems (3)
PATCH 1/1 ipv6: order addresses by scope
If IPv6 addresses are ordered by scope, then ipv6_dev_get_saddr() can break-out of the device addr_list for() loop when the candidate source address scope is less than the destination address scope.
net/ipv6/addrconf.c +21 -3
@@ -509,6 +509,25 @@ void inet6_ifa_finish_destroy(struct inekfree (ifp); } +static void +ipv6_link_dev_addr (struct inet6_dev *idev,struct inet6_ifaddr *ifp) +{ +struct inet6_ifaddr *ifa, **ifap; + +/* +* Each device address list is sorted in order of scope - +* global before linklocal. +*/ +for (ifap = &idev->addr_list; (ifa = *ifap) !=NULL ; + ifap = &ifa->if_next) { +if (ifp->scope > ifa->scope) +break ; + } + + ifp->if_next = *ifap; + *ifap = ifp; +} +/* On success it returns ifp with increased reference count */ static struct inet6_ifaddr *
@@ -574,8 +593,7 @@ ipv6_add_addr(struct inet6_dev *idev, cowrite_lock (&idev->lock);/* Add to inet6_dev unicast addr list. */ - ifa->if_next = idev->addr_list; - idev->addr_list = ifa; +ipv6_link_dev_addr (idev, ifa);#ifdef CONFIG_IPV6_PRIVACY if (ifa->flags&IFA_F_TEMPORARY ) {
@@ -982,7 +1000,7 @@ int ipv6_dev_get_saddr(struct net_devicecontinue ; }else if (score.scope < hiscore.scope) {if (score.scope < daddr_scope) -continue ; +break ;/* addresses sorted by scope */ else { score.rule =2 ; goto record_it;
David Miller
maintainerFrom: Brian Haley <[email protected]>
Date: Fri, 09 Jun 2006 14:14:50 -0400
Quoted 5 lines
If IPv6 addresses are ordered by scope, then
ipv6_dev_get_saddr()can break-out of the deviceaddr_listfor()loop when the candidate source address scope is less than the destination address scope.Signed-off-by Brian Haley <[email protected]>
This patch looks fine to me, it's an optimization and not a correctness issue.
But I'd like an ACK from an ipv6 developer, such as Yoshifuji, before adding this patch.
Thanks.
YOSHIFUJI Hideaki / 吉藤英明
Acked-byIn article <[email protected]> (at Mon, 10 Jul 2006 15:00:45 -0700 (PDT)), David Miller <[email protected]> says:
Quoted 11 lines
Quoted 5 lines
If IPv6 addresses are ordered by scope, then
ipv6_dev_get_saddr()can break-out of the deviceaddr_listfor()loop when the candidate source address scope is less than the destination address scope.Signed-off-by Brian Haley <[email protected]>This patch looks fine to me, it's an optimization and not a correctness issue.
But I'd like an ACK from an ipv6 developer, such as Yoshifuji, before adding this patch.
I agree, too.
Note: People should not depend on the order of addresses.
--yoshfuji
David Miller
maintainerFrom: YOSHIFUJI Hideaki <[email protected]>
Date: Mon, 10 Jul 2006 18:18:16 -0400 (EDT)
Quoted 11 lines
In article <[email protected]> (at Mon, 10 Jul 2006 15:00:45 -0700 (PDT)), David Miller <[email protected]> says:
Quoted 9 lines
Quoted 5 lines
If IPv6 addresses are ordered by scope, then
ipv6_dev_get_saddr()can break-out of the deviceaddr_listfor()loop when the candidate source address scope is less than the destination address scope.Signed-off-by Brian Haley <[email protected]>This patch looks fine to me, it's an optimization and not a correctness issue.
Quoted 7 lines
Quoted 2 lines
But I'd like an ACK from an ipv6 developer, such as Yoshifuji, before adding this patch.
I agree, too.
Note: People should not depend on the order of addresses.
Thank you for reviewing, patch applied.