From 794c4735f81289d9fc603b5fd5e4a5d39dbb5ca5 Mon Sep 17 00:00:00 2001 From: Nicolas Dichtel Date: Wed, 16 Sep 2015 09:42:36 +0200 Subject: bgpd/pimd: fix zAPI parsing Commit c99f3481a598 has changed the API. Now, the vrfid has been added in the header, thus we must read it before parsing the rest of the message. To ease code maintenance, let's add a new function to read a zAPI header. Fixes: c99f3481a598 ("*: add VRF ID in the API message header") Reported-by: Martin Winter Signed-off-by: Nicolas Dichtel Acked-by: Donald Sharp Tested-by: Martin Winter --- lib/zclient.c | 19 +++++++++++++++++++ lib/zclient.h | 3 +++ 2 files changed, 22 insertions(+) (limited to 'lib') diff --git a/lib/zclient.c b/lib/zclient.c index 8e443e28..a0956324 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -302,6 +302,25 @@ zclient_create_header (struct stream *s, uint16_t command, vrf_id_t vrf_id) stream_putw (s, command); } +int +zclient_read_header (struct stream *s, int sock, u_int16_t *size, u_char *marker, + u_char *version, u_int16_t *vrf_id, u_int16_t *cmd) +{ + if (stream_read (s, sock, ZEBRA_HEADER_SIZE) != ZEBRA_HEADER_SIZE) + return -1; + + *size = stream_getw (s) - ZEBRA_HEADER_SIZE; + *marker = stream_getc (s); + *version = stream_getc (s); + *vrf_id = stream_getw (s); + *cmd = stream_getw (s); + + if (*size && stream_read (s, sock, *size) != *size) + return -1; + + return 0; +} + /* Send simple Zebra message. */ static int zebra_message_send (struct zclient *zclient, int command, vrf_id_t vrf_id) diff --git a/lib/zclient.h b/lib/zclient.h index 19b4f0ea..3490b320 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -163,6 +163,9 @@ extern int zclient_send_message(struct zclient *); /* create header for command, length to be filled in by user later */ extern void zclient_create_header (struct stream *, uint16_t, vrf_id_t); +extern int zclient_read_header (struct stream *s, int sock, u_int16_t *size, + u_char *marker, u_char *version, + u_int16_t *vrf_id, u_int16_t *cmd); extern struct interface *zebra_interface_add_read (struct stream *, vrf_id_t); -- cgit v1.2.3