]> git.proxmox.com Git - mirror_frr.git/commitdiff
zebra: add struct zmsghdr
authorQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 6 Mar 2018 22:09:36 +0000 (17:09 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 12 Mar 2018 18:57:05 +0000 (14:57 -0400)
Formalize the ZAPI header by documenting it in code and providing it to
message handlers free of charge to reduce complexity.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
zebra/zserv.c
zebra/zserv.h

index f3ee38fef121822c8b4e248bdb97d7e9fffb5990..3ecc82be4252cc7a746634b68ce199115aeb9ead 100644 (file)
@@ -2681,10 +2681,31 @@ stream_failure:
        return;
 }
 
+/*
+ * Reads header from zmsg stream.
+ *
+ * Note this advances the stream getp by the size of the header.
+ */
+static bool zserv_read_header(struct stream *msg, struct zmsghdr *hdr)
+{
+       STREAM_GETW(msg, hdr->length);
+       STREAM_GETC(msg, hdr->marker);
+       STREAM_GETC(msg, hdr->version);
+       STREAM_GETL(msg, hdr->vrf_id);
+       STREAM_GETW(msg, hdr->command);
+       return true;
+stream_failure:
+       return false;
+}
+
 static inline void zserv_handle_commands(struct zserv *client, uint16_t command,
                                         uint16_t length,
                                         struct zebra_vrf *zvrf)
 {
+       struct zmsghdr hdr;
+       stream_set_getp(client->ibuf, 0);
+       zserv_read_header(client->ibuf, &hdr);
+
        switch (command) {
        case ZEBRA_ROUTER_ID_ADD:
                zread_router_id_add(client, length, zvrf);
index 8519693726e3bd95f92125cc8fb457a0c8eaf105..a09baeff7a3e1a75877bb3622b699f57b446e081 100644 (file)
@@ -129,6 +129,15 @@ struct zserv {
        int last_write_cmd;
 };
 
+/* ZAPI protocol message header */
+struct zmsghdr {
+       uint16_t length;
+       uint8_t marker;
+       uint8_t version;
+       uint32_t vrf_id;
+       uint16_t command;
+};
+
 /* Zebra instance */
 struct zebra_t {
        /* Thread master */