zebra: add struct zmsghdr

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>
This commit is contained in:
Quentin Young 2018-03-06 17:09:36 -05:00
parent 8068a649a7
commit 9bcbcae2e4
No known key found for this signature in database
GPG Key ID: DAF48E0F57E0834F
2 changed files with 30 additions and 0 deletions

View 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);

View 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 */