network/nexthop: NextHop.id is always positive when nexthop_configure() is called

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.
This commit is contained in:
Yu Watanabe 2023-12-12 18:40:43 +09:00
parent c624143b59
commit a533473a48

View 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;