From: Yu Watanabe Date: Mon, 15 Jan 2024 03:35:47 +0000 (+0900) Subject: network/nexthop: read netlink message in nexthop_update_group() X-Git-Tag: v256-rc1~1146^2~3 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=4e9795ebfa3a7bb27f34153c858dba39b3018c4b;p=thirdparty%2Fsystemd.git network/nexthop: read netlink message in nexthop_update_group() No functional change, preparation for later commits. --- diff --git a/src/network/networkd-nexthop.c b/src/network/networkd-nexthop.c index 4de1e09999b..f440187c310 100644 --- a/src/network/networkd-nexthop.c +++ b/src/network/networkd-nexthop.c @@ -861,15 +861,20 @@ void link_foreignize_nexthops(Link *link) { } } -static int nexthop_update_group(NextHop *nexthop, const struct nexthop_grp *group, size_t size) { +static int nexthop_update_group(NextHop *nexthop, sd_netlink_message *message) { _cleanup_hashmap_free_free_ Hashmap *h = NULL; - size_t n_group; + _cleanup_free_ struct nexthop_grp *group = NULL; + size_t size = 0, n_group; int r; assert(nexthop); - assert(group || size == 0); + assert(message); + + r = sd_netlink_message_read_data(message, NHA_GROUP, &size, (void**) &group); + if (r < 0 && r != -ENODATA) + return log_debug_errno(r, "rtnl: could not get NHA_GROUP attribute, ignoring: %m"); - if (size == 0 || size % sizeof(struct nexthop_grp) != 0) + if (size % sizeof(struct nexthop_grp) != 0) return log_debug_errno(SYNTHETIC_ERRNO(EINVAL), "rtnl: received nexthop message with invalid nexthop group size, ignoring."); @@ -912,8 +917,6 @@ static int nexthop_update_group(NextHop *nexthop, const struct nexthop_grp *grou } int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, Manager *m) { - _cleanup_free_ void *raw_group = NULL; - size_t raw_group_size; uint16_t type; uint32_t id, ifindex; NextHop *nexthop = NULL; @@ -1001,13 +1004,7 @@ int manager_rtnl_process_nexthop(sd_netlink *rtnl, sd_netlink_message *message, if (r < 0) log_debug_errno(r, "rtnl: could not get nexthop flags, ignoring: %m"); - r = sd_netlink_message_read_data(message, NHA_GROUP, &raw_group_size, &raw_group); - if (r == -ENODATA) - nexthop->group = hashmap_free_free(nexthop->group); - else if (r < 0) - log_debug_errno(r, "rtnl: could not get NHA_GROUP attribute, ignoring: %m"); - else - (void) nexthop_update_group(nexthop, raw_group, raw_group_size); + (void) nexthop_update_group(nexthop, message); if (nexthop->family != AF_UNSPEC) { r = netlink_message_read_in_addr_union(message, NHA_GATEWAY, nexthop->family, &nexthop->gw);