]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/route-nexthop: store ifindex of the assigned interface in Route.nexthop.ifindex
authorYu Watanabe <watanabe.yu+github@gmail.com>
Sat, 13 Jan 2024 02:18:53 +0000 (11:18 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Mon, 15 Jan 2024 01:28:25 +0000 (10:28 +0900)
And use it if set on building netlink message.

src/network/networkd-route-nexthop.c

index 028504537c225334203237e9e6752228e019c123..43ff790f04a9b220851514b28d1c3d8b625181d2 100644 (file)
@@ -365,8 +365,7 @@ int route_nexthops_set_netlink_message(Link *link, const Route *route, sd_netlin
                                 return r;
                 }
 
-                assert(link);
-                return sd_netlink_message_append_u32(message, RTA_OIF, link->ifindex);
+                return sd_netlink_message_append_u32(message, RTA_OIF, route->nexthop.ifindex > 0 ? route->nexthop.ifindex : ASSERT_PTR(link)->ifindex);
         }
 
         return netlink_message_append_multipath_route(link, route, message);
@@ -474,12 +473,14 @@ int route_nexthops_read_netlink_message(Route *route, sd_netlink_message *messag
                  * routes. Hence, skip reading of RTA_OIF. */
                 return 0;
 
-        uint32_t ifindex = 0;
+        uint32_t ifindex;
         r = sd_netlink_message_read_u32(message, RTA_OIF, &ifindex);
-        if (r < 0 && r != -ENODATA)
+        if (r >= 0)
+                route->nexthop.ifindex = (int) ifindex;
+        else if (r != -ENODATA)
                 return log_warning_errno(r, "rtnl: could not get ifindex from route message, ignoring: %m");
 
-        if (ifindex > 0) {
+        if (route->nexthop.ifindex > 0) {
                 r = netlink_message_read_in_addr_union(message, RTA_GATEWAY, route->family, &route->nexthop.gw);
                 if (r >= 0) {
                         route->nexthop.family = route->family;