summaryrefslogtreecommitdiff
path: root/lib/link_state.c
diff options
context:
space:
mode:
authorMark Stapp <mjs@labn.net>2023-05-29 13:04:24 -0400
committerMark Stapp <mjs@labn.net>2023-06-23 08:27:42 -0400
commitef8e3ac02c4482bd6ef255578e325a98ec9c8e86 (patch)
tree9f1ffc6088e53a52085e503566c6ebb8d935891e /lib/link_state.c
parent3cbc7150bb2d7b9a192bd047ee258986b8eb2c44 (diff)
lib, zebra: include source client zapi info in opaque messages
Include the sending zapi client info (proto, instance, and session id) in each opaque zapi message. Add opaque 'init' apis for clients who want to encode their opaque data inline, into the zclient's internal stream buffer. Use these init apis in the TE/link-state lib code, instead of hand-coding the zapi opaque header info. Signed-off-by: Mark Stapp <mjs@labn.net>
Diffstat (limited to 'lib/link_state.c')
-rw-r--r--lib/link_state.c46
1 files changed, 10 insertions, 36 deletions
diff --git a/lib/link_state.c b/lib/link_state.c
index 58727a568b..6537f881ce 100644
--- a/lib/link_state.c
+++ b/lib/link_state.c
@@ -1138,31 +1138,13 @@ int ls_unregister(struct zclient *zclient, bool server)
int ls_request_sync(struct zclient *zclient)
{
- struct stream *s;
- uint16_t flags = 0;
-
/* Check buffer size */
if (STREAM_SIZE(zclient->obuf)
< (ZEBRA_HEADER_SIZE + 3 * sizeof(uint32_t)))
return -1;
- s = zclient->obuf;
- stream_reset(s);
-
- zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT);
-
- /* Set type and flags */
- stream_putl(s, LINK_STATE_SYNC);
- stream_putw(s, flags);
- /* Send destination client info */
- stream_putc(s, zclient->redist_default);
- stream_putw(s, zclient->instance);
- stream_putl(s, zclient->session_id);
-
- /* Put length into the header at the start of the stream. */
- stream_putw_at(s, 0, stream_get_endp(s));
-
- return zclient_send_message(zclient);
+ /* No data with this message */
+ return zclient_send_opaque(zclient, LINK_STATE_SYNC, NULL, 0);
}
static struct ls_node *ls_parse_node(struct stream *s)
@@ -1623,23 +1605,15 @@ int ls_send_msg(struct zclient *zclient, struct ls_message *msg,
(ZEBRA_HEADER_SIZE + sizeof(uint32_t) + sizeof(msg)))
return -1;
+ /* Init the message, then encode the data inline. */
+ if (dst == NULL)
+ zapi_opaque_init(zclient, LINK_STATE_UPDATE, flags);
+ else
+ zapi_opaque_unicast_init(zclient, LINK_STATE_UPDATE, flags,
+ dst->proto, dst->instance,
+ dst->session_id);
+
s = zclient->obuf;
- stream_reset(s);
-
- zclient_create_header(s, ZEBRA_OPAQUE_MESSAGE, VRF_DEFAULT);
-
- /* Set sub-type, flags and destination for unicast message */
- stream_putl(s, LINK_STATE_UPDATE);
- if (dst != NULL) {
- SET_FLAG(flags, ZAPI_OPAQUE_FLAG_UNICAST);
- stream_putw(s, flags);
- /* Send destination client info */
- stream_putc(s, dst->proto);
- stream_putw(s, dst->instance);
- stream_putl(s, dst->session_id);
- } else {
- stream_putw(s, flags);
- }
/* Format Link State message */
if (ls_format_msg(s, msg) < 0) {