Skip to content

Commit cd03498

Browse files
authored
Merge pull request #19307 from FRRouting/mergify/bp/stable/10.1/pr-19290
lib: compute link-state zapi message size (backport #19290)
2 parents 3c5f189 + 8807ea5 commit cd03498

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
@@ -1661,6 +1661,20 @@ static int ls_format_msg(struct stream *s, struct ls_message *msg)
16611661
return -1;
16621662
}
16631663

1664+
/* Help to compute zapi message size based on the ls_xxx structs' data */
1665+
static size_t get_max_ls_msg_size(void)
1666+
{
1667+
size_t max = sizeof(struct ls_node);
1668+
1669+
if (max < sizeof(struct ls_attributes))
1670+
max = sizeof(struct ls_attributes);
1671+
1672+
if (max < sizeof(struct ls_prefix))
1673+
max = sizeof(struct ls_prefix);
1674+
1675+
return max;
1676+
}
1677+
16641678
int ls_send_msg(struct zclient *zclient, struct ls_message *msg,
16651679
struct zapi_opaque_reg_info *dst)
16661680
{
@@ -1673,7 +1687,7 @@ int ls_send_msg(struct zclient *zclient, struct ls_message *msg,
16731687

16741688
/* Check buffer size */
16751689
if (STREAM_SIZE(zclient->obuf) <
1676-
(ZEBRA_HEADER_SIZE + sizeof(uint32_t) + sizeof(msg)))
1690+
(ZEBRA_HEADER_SIZE + sizeof(uint32_t) + get_max_ls_msg_size()))
16771691
return -1;
16781692

16791693
/* 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
@@ -871,6 +871,10 @@ struct ls_message {
871871
uint8_t event; /* Message Event: Sync, Add, Update, Delete */
872872
uint8_t type; /* Message Data Type: Node, Attribute, Prefix */
873873
struct ls_node_id remote_id; /* Remote Link State Node ID */
874+
875+
/* Please update the get_max_ls_msg_size() helper if you add a new
876+
* struct to this message container.
877+
*/
874878
union {
875879
struct ls_node *node; /* Link State Node */
876880
struct ls_attributes *attr; /* Link State Attributes */

0 commit comments

Comments
 (0)