summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorFrancois Dumontet <francois.dumontet@6wind.com>2025-01-07 16:54:48 +0100
committerFrancois Dumontet <francois.dumontet@6wind.com>2025-02-27 16:51:05 +0100
commit8c9b007a0c7efb2e9afc2eac936ba9dd971c6707 (patch)
tree11d5048ac0976ece719f0df1a7e0c2a995f6e26c /lib
parent77b52da131293041c5074a3f9944a1709872e2f4 (diff)
zebra: reduce memory usage by streams when redistributing routes
required stream size is evaluated as a fix part and variable one. the variable one depend on the number of nexthops. Signed-off-by: Francois Dumontet <francois.dumontet@6wind.com>
Diffstat (limited to 'lib')
-rw-r--r--lib/zclient.c18
-rw-r--r--lib/zclient.h1
2 files changed, 19 insertions, 0 deletions
diff --git a/lib/zclient.c b/lib/zclient.c
index 5deea8f0cf..86bef38877 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -1326,6 +1326,24 @@ 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 afd84acce2..43521d6e2e 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -1158,6 +1158,7 @@ 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,