Skip to content

Commit bc897b3

Browse files
authored
Merge pull request #19306 from FRRouting/mergify/bp/stable/10.2/pr-19290
lib: compute link-state zapi message size (backport #19290)
2 parents 34eca8c + dad6a53 commit bc897b3

File tree

2 files changed

+19
-1
lines changed

2 files changed

+19
-1
lines changed

lib/link_state.c

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1678,6 +1678,20 @@ static int ls_format_msg(struct stream *s, struct ls_message *msg)
16781678
return -1;
16791679
}
16801680

1681+
/* Help to compute zapi message size based on the ls_xxx structs' data */
1682+
static size_t get_max_ls_msg_size(void)
1683+
{
1684+
size_t max = sizeof(struct ls_node);
1685+
1686+
if (max < sizeof(struct ls_attributes))
1687+
max = sizeof(struct ls_attributes);
1688+
1689+
if (max < sizeof(struct ls_prefix))
1690+
max = sizeof(struct ls_prefix);
1691+
1692+
return max;
1693+
}
1694+
16811695
int ls_send_msg(struct zclient *zclient, struct ls_message *msg,
16821696
struct zapi_opaque_reg_info *dst)
16831697
{
@@ -1690,7 +1704,7 @@ int ls_send_msg(struct zclient *zclient, struct ls_message *msg,
16901704

16911705
/* Check buffer size */
16921706
if (STREAM_SIZE(zclient->obuf) <
1693-
(ZEBRA_HEADER_SIZE + sizeof(uint32_t) + sizeof(msg)))
1707+
(ZEBRA_HEADER_SIZE + sizeof(uint32_t) + get_max_ls_msg_size()))
16941708
return -1;
16951709

16961710
/* Init the message, then encode the data inline. */

lib/link_state.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -877,6 +877,10 @@ struct ls_message {
877877
uint8_t event; /* Message Event: Sync, Add, Update, Delete */
878878
uint8_t type; /* Message Data Type: Node, Attribute, Prefix */
879879
struct ls_node_id remote_id; /* Remote Link State Node ID */
880+
881+
/* Please update the get_max_ls_msg_size() helper if you add a new
882+
* struct to this message container.
883+
*/
880884
union {
881885
struct ls_node *node; /* Link State Node */
882886
struct ls_attributes *attr; /* Link State Attributes */

0 commit comments

Comments
 (0)