@@ -750,6 +750,8 @@ static bool prefix_route_address_is_reachable(const Address *a, int family, cons
750750
751751 if (a -> family != family )
752752 return false;
753+ if (!address_is_ready (a ))
754+ return false;
753755 if (FLAGS_SET (a -> flags , IFA_F_NOPREFIXROUTE ))
754756 return false;
755757 if (in_addr_is_set (a -> family , & a -> in_addr_peer ))
@@ -763,37 +765,34 @@ static bool prefix_route_address_is_reachable(const Address *a, int family, cons
763765 FAMILY_ADDRESS_SIZE (family ) * 8 ) > 0 ;
764766}
765767
766- bool manager_address_is_reachable ( Manager * manager , int family , const union in_addr_union * address ) {
767- Link * link ;
768+ static bool link_address_is_reachable ( Link * link , int family , const union in_addr_union * address ) {
769+ Route * route ;
768770
769- assert (manager );
771+ assert (link );
772+ assert (link -> manager );
770773 assert (IN_SET (family , AF_INET , AF_INET6 ));
771774 assert (address );
772775
773- HASHMAP_FOREACH (link , manager -> links_by_index ) {
774- Route * route ;
775776
776- SET_FOREACH (route , link -> routes )
777- if (route_address_is_reachable (route , family , address ))
778- return true;
779- SET_FOREACH (route , link -> routes_foreign )
780- if (route_address_is_reachable (route , family , address ))
781- return true;
782- }
777+ SET_FOREACH (route , link -> routes )
778+ if (route_address_is_reachable (route , family , address ))
779+ return true;
780+ SET_FOREACH (route , link -> routes_foreign )
781+ if (route_address_is_reachable (route , family , address ))
782+ return true;
783783
784784 /* If we do not manage foreign routes, then there may exist a prefix route we do not know,
785785 * which was created on configuring an address. Hence, also check the addresses. */
786- if (!manager -> manage_foreign_routes )
787- HASHMAP_FOREACH (link , manager -> links_by_index ) {
788- Address * a ;
789-
790- SET_FOREACH (a , link -> addresses )
791- if (prefix_route_address_is_reachable (a , family , address ))
792- return true;
793- SET_FOREACH (a , link -> addresses_foreign )
794- if (prefix_route_address_is_reachable (a , family , address ))
795- return true;
796- }
786+ if (!link -> manager -> manage_foreign_routes ) {
787+ Address * a ;
788+
789+ SET_FOREACH (a , link -> addresses )
790+ if (prefix_route_address_is_reachable (a , family , address ))
791+ return true;
792+ SET_FOREACH (a , link -> addresses_foreign )
793+ if (prefix_route_address_is_reachable (a , family , address ))
794+ return true;
795+ }
797796
798797 return false;
799798}
@@ -1689,6 +1688,22 @@ int link_request_static_routes(Link *link, bool only_ipv4) {
16891688 return 0 ;
16901689}
16911690
1691+ bool gateway_is_ready (Link * link , int onlink , int family , const union in_addr_union * gw ) {
1692+ assert (link );
1693+ assert (gw );
1694+
1695+ if (onlink > 0 )
1696+ return true;
1697+
1698+ if (!in_addr_is_set (family , gw ))
1699+ return true;
1700+
1701+ if (family == AF_INET6 && in6_addr_is_link_local (& gw -> in6 ))
1702+ return true;
1703+
1704+ return link_address_is_reachable (link , family , gw );
1705+ }
1706+
16921707static int route_is_ready_to_configure (const Route * route , Link * link ) {
16931708 MultipathRoute * m ;
16941709 NextHop * nh = NULL ;
@@ -1732,19 +1747,13 @@ static int route_is_ready_to_configure(const Route *route, Link *link) {
17321747 return r ;
17331748 }
17341749
1735- if (route -> gateway_onlink <= 0 &&
1736- in_addr_is_set (route -> gw_family , & route -> gw ) > 0 &&
1737- !manager_address_is_reachable (link -> manager , route -> gw_family , & route -> gw ))
1750+ if (!gateway_is_ready (link , route -> gateway_onlink , route -> gw_family , & route -> gw ))
17381751 return false;
17391752
17401753 ORDERED_SET_FOREACH (m , route -> multipath_routes ) {
17411754 union in_addr_union a = m -> gateway .address ;
17421755 Link * l = NULL ;
17431756
1744- if (route -> gateway_onlink <= 0 &&
1745- !manager_address_is_reachable (link -> manager , m -> gateway .family , & a ))
1746- return false;
1747-
17481757 if (m -> ifname ) {
17491758 if (link_get_by_name (link -> manager , m -> ifname , & l ) < 0 )
17501759 return false;
@@ -1756,6 +1765,9 @@ static int route_is_ready_to_configure(const Route *route, Link *link) {
17561765 }
17571766 if (l && !link_is_ready_to_configure (l , true))
17581767 return false;
1768+
1769+ if (!gateway_is_ready (l ?: link , route -> gateway_onlink , m -> gateway .family , & a ))
1770+ return false;
17591771 }
17601772
17611773 return true;
0 commit comments