summaryrefslogtreecommitdiff
path: root/sharpd/sharp_zebra.c
diff options
context:
space:
mode:
Diffstat (limited to 'sharpd/sharp_zebra.c')
-rw-r--r--sharpd/sharp_zebra.c78
1 files changed, 78 insertions, 0 deletions
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index 0795096440..34cc1a4b5a 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -480,6 +480,83 @@ static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS)
return 0;
}
+/* Handler for opaque messages */
+static int sharp_opaque_handler(ZAPI_CALLBACK_ARGS)
+{
+ uint32_t type;
+ struct stream *s;
+
+ s = zclient->ibuf;
+
+ STREAM_GETL(s, type);
+
+ zlog_debug("%s: received opaque type %u", __func__, type);
+
+stream_failure:
+
+ return 0;
+}
+
+/*
+ * Send OPAQUE messages, using subtype 'type'.
+ */
+void sharp_opaque_send(uint32_t type, uint32_t count)
+{
+ uint8_t buf[32];
+ int ret;
+ uint32_t i;
+
+ /* Prepare a small payload */
+ for (i = 0; i < sizeof(buf); i++) {
+ if (type < 255)
+ buf[i] = type;
+ else
+ buf[i] = 255;
+ }
+
+ /* Send some messages */
+ for (i = 0; i < count; i++) {
+ ret = zclient_send_opaque(zclient, type, buf, sizeof(buf));
+ if (ret < 0) {
+ zlog_debug("%s: send_opaque() failed => %d",
+ __func__, ret);
+ break;
+ }
+ }
+
+}
+
+/*
+ * Send OPAQUE registration messages, using subtype 'type'.
+ */
+void sharp_opaque_reg_send(bool is_reg, uint32_t proto, uint32_t instance,
+ uint32_t session_id, uint32_t type)
+{
+ struct stream *s;
+
+ s = zclient->obuf;
+ stream_reset(s);
+
+ if (is_reg)
+ zclient_create_header(s, ZEBRA_OPAQUE_REGISTER, VRF_DEFAULT);
+ else
+ zclient_create_header(s, ZEBRA_OPAQUE_UNREGISTER, VRF_DEFAULT);
+
+ /* Send sub-type */
+ stream_putl(s, type);
+
+ /* Add zclient info */
+ stream_putc(s, proto);
+ stream_putw(s, instance);
+ stream_putl(s, session_id);
+
+ /* Put length at the first point of the stream. */
+ stream_putw_at(s, 0, stream_get_endp(s));
+
+ (void)zclient_send_message(zclient);
+
+}
+
extern struct zebra_privs_t sharp_privs;
void sharp_zebra_init(void)
@@ -501,4 +578,5 @@ void sharp_zebra_init(void)
zclient->redistribute_route_add = sharp_redistribute_route;
zclient->redistribute_route_del = sharp_redistribute_route;
+ zclient->opaque_msg_handler = sharp_opaque_handler;
}