From: Soumya Roy Date: Fri, 14 Mar 2025 22:01:51 +0000 (+0000) Subject: zebra: reduce memory usage by streams when redistributing routes X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=860c1e445043c6e380a9fb08cc0c21c6339625ad;p=matthieu%2Ffrr.git zebra: reduce memory usage by streams when redistributing routes This commit undo 8c9b007a0c7efb2e9afc2eac936ba9dd971c6707 stream lib has been modified to expand the stream if needed Now for zapi route encode, we use expandable stream Signed-off-by: Soumya Roy --- diff --git a/lib/zclient.c b/lib/zclient.c index f0476867be..532771cb93 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1326,24 +1326,6 @@ enum zclient_send_status zclient_nhg_send(struct zclient *zclient, int cmd, return zclient_send_message(zclient); } -/* size needed by a stream for redistributing a route */ -int zapi_redistribute_stream_size(struct zapi_route *api) -{ - size_t msg_size = 0; - size_t nh_size = sizeof(struct zapi_nexthop); - - msg_size = sizeof(struct zapi_route); - /* remove unused nexthop structures */ - msg_size -= (MULTIPATH_NUM - api->nexthop_num) * nh_size; - /* remove unused backup nexthop structures */ - msg_size -= (MULTIPATH_NUM - api->backup_nexthop_num) * nh_size; - /* remove unused opaque values */ - msg_size -= ZAPI_MESSAGE_OPAQUE_LENGTH - api->opaque.length; - - return msg_size; -} - - int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) { struct zapi_nexthop *api_nh; diff --git a/lib/zclient.h b/lib/zclient.h index 43521d6e2e..afd84acce2 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -1158,7 +1158,6 @@ zclient_send_rnh(struct zclient *zclient, int command, const struct prefix *p, vrf_id_t vrf_id); int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, uint32_t api_flags, uint32_t api_message); -extern int zapi_redistribute_stream_size(struct zapi_route *api); extern int zapi_route_encode(uint8_t, struct stream *, struct zapi_route *); extern int zapi_route_decode(struct stream *s, struct zapi_route *api); extern int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh, diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 066859d380..9c8ef19a9d 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -518,7 +518,6 @@ int zsend_redistribute_route(int cmd, struct zserv *client, const struct route_n const struct prefix *p, *src_p; uint16_t count = 0; afi_t afi; - size_t stream_size = 0; srcdest_rnode_prefixes(rn, &p, &src_p); memset(&api, 0, sizeof(api)); @@ -610,8 +609,7 @@ int zsend_redistribute_route(int cmd, struct zserv *client, const struct route_n SET_FLAG(api.message, ZAPI_MESSAGE_MTU); api.mtu = re->mtu; - stream_size = zapi_redistribute_stream_size(&api); - struct stream *s = stream_new(stream_size); + struct stream *s = stream_new_expandable(ZEBRA_MAX_PACKET_SIZ); /* Encode route and send. */ if (zapi_route_encode(cmd, s, &api) < 0) {