]> git.ipfire.org Git - thirdparty/systemd.git/commitdiff
network/nexthop: NextHop.id is always positive when nexthop_configure() is called
authorYu Watanabe <watanabe.yu+github@gmail.com>
Tue, 12 Dec 2023 09:40:43 +0000 (18:40 +0900)
committerYu Watanabe <watanabe.yu+github@gmail.com>
Thu, 14 Dec 2023 09:57:43 +0000 (18:57 +0900)
If a nexthop is requested without a valid ID, then nexthop_acquire_id()
assigns an unused ID. So, at the time nexthop_configure() is called, the
ID is always valid.

src/network/networkd-nexthop.c

index b10ddc46b8c66f6bfb5458871017e4bbfd8eb3eb..367759f373eb66475d6d2fd1b288c2288a3a6e8d 100644 (file)
@@ -435,6 +435,7 @@ static int nexthop_configure(NextHop *nexthop, Link *link, Request *req) {
         int r;
 
         assert(nexthop);
+        assert(nexthop->id > 0);
         assert(IN_SET(nexthop->family, AF_UNSPEC, AF_INET, AF_INET6));
         assert(link);
         assert(link->manager);
@@ -448,11 +449,9 @@ static int nexthop_configure(NextHop *nexthop, Link *link, Request *req) {
         if (r < 0)
                 return r;
 
-        if (nexthop->id > 0) {
-                r = sd_netlink_message_append_u32(m, NHA_ID, nexthop->id);
-                if (r < 0)
-                        return r;
-        }
+        r = sd_netlink_message_append_u32(m, NHA_ID, nexthop->id);
+        if (r < 0)
+                return r;
 
         if (!hashmap_isempty(nexthop->group)) {
                 _cleanup_free_ struct nexthop_grp *group = NULL;