From: Yu Watanabe Date: Fri, 12 Jan 2024 04:22:05 +0000 (+0900) Subject: network/route-nexthop: do not update MultipathRoute object X-Git-Tag: v256-rc1~1159^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=fad2f7235174fe1a47929443293b4deed94a12ce;p=thirdparty%2Fsystemd.git network/route-nexthop: do not update MultipathRoute object A MultipathRoute object is always owned by a Network object, and the interface matching with its name specified in a MultipathRoute= setting may be removed, and re-added later with a different ifindex. --- diff --git a/src/network/networkd-route-nexthop.c b/src/network/networkd-route-nexthop.c index e20c0eb72b5..4ffaf1aea0d 100644 --- a/src/network/networkd-route-nexthop.c +++ b/src/network/networkd-route-nexthop.c @@ -19,13 +19,13 @@ int multipath_route_get_link(Manager *manager, const MultipathRoute *m, Link **r assert(manager); assert(m); + if (m->ifindex > 0) { + r = link_get_by_index(manager, m->ifindex, ret); + return r < 0 ? r : 1; + } if (m->ifname) { r = link_get_by_name(manager, m->ifname, ret); return r < 0 ? r : 1; - - } else if (m->ifindex > 0) { /* Always ignore ifindex if ifname is set. */ - r = link_get_by_index(manager, m->ifindex, ret); - return r < 0 ? r : 1; } if (ret) @@ -33,7 +33,7 @@ int multipath_route_get_link(Manager *manager, const MultipathRoute *m, Link **r return 0; } -static bool multipath_route_is_ready_to_configure(MultipathRoute *m, Link *link, bool onlink) { +static bool multipath_route_is_ready_to_configure(const MultipathRoute *m, Link *link, bool onlink) { union in_addr_union a = m->gateway.address; Link *l = NULL; int r; @@ -55,7 +55,6 @@ static bool multipath_route_is_ready_to_configure(MultipathRoute *m, Link *link, if (!link->network && !link_has_carrier(link)) return false; - m->ifindex = link->ifindex; return gateway_is_ready(link, onlink, m->gateway.family, &a); } @@ -174,7 +173,18 @@ static int append_nexthop_one(Link *link, const Route *route, const MultipathRou assert(m); assert(rta); assert(*rta); - assert(m->ifindex > 0 || link); + + if (m->ifindex <= 0) { + assert(link); + assert(link->manager); + + Link *l; + r = multipath_route_get_link(link->manager, m, &l); + if (r < 0) + return r; + if (r > 0) + link = l; + } new_rta = realloc(*rta, RTA_ALIGN((*rta)->rta_len) + RTA_SPACE(sizeof(struct rtnexthop))); if (!new_rta)