Skip to content

Commit

Permalink
lib, zebra: use existing zapi header struct
Browse files Browse the repository at this point in the history
Nobody uses it, but it's got the same definition. Move the parser
function into zclient.c and use it.

Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
  • Loading branch information
qlyoung committed Mar 7, 2018
1 parent e3ed7cf commit 64ffa06
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 17 deletions.
12 changes: 12 additions & 0 deletions lib/zclient.c
Original file line number Diff line number Diff line change
Expand Up @@ -322,6 +322,18 @@ int zclient_read_header(struct stream *s, int sock, u_int16_t *size,
return 0;
}

bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr)
{
STREAM_GETW(zmsg, hdr->length);
STREAM_GETC(zmsg, hdr->marker);
STREAM_GETC(zmsg, hdr->version);
STREAM_GETC(zmsg, hdr->vrf_id);
STREAM_GETW(zmsg, hdr->command);
return true;
stream_failure:
return false;
}

/* Send simple Zebra message. */
static int zebra_message_send(struct zclient *zclient, int command,
vrf_id_t vrf_id)
Expand Down
62 changes: 55 additions & 7 deletions lib/zclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -226,14 +226,14 @@ struct zclient {
#define ZAPI_MESSAGE_SRCPFX 0x20
#define ZAPI_MESSAGE_LABEL 0x40

#define ZSERV_VERSION 5
/* Zserv protocol message header */
struct zserv_header {
struct zmsghdr {
uint16_t length;
uint8_t marker; /* corresponds to command field in old zserv
* always set to 255 in new zserv.
*/
/* corresponds to command field in old zserv
* always set to 255 in new zserv. */
uint8_t marker;
uint8_t version;
#define ZSERV_VERSION 5
vrf_id_t vrf_id;
uint16_t command;
};
Expand Down Expand Up @@ -428,9 +428,58 @@ 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);
/*
* Read sizeof(struct zmsghdr) bytes from the provided socket and parse the
* received data into the specified fields. If this is successful, read the
* rest of the packet into the provided stream.
*
* s
* The stream to read into
*
* sock
* The socket to read from
*
* size
* Parsed message size will be placed in the pointed-at integer
*
* marker
* Parsed marker will be placed in the pointed-at byte
*
* version
* Parsed version will be placed in the pointed-at byte
*
* vrf_id
* Parsed VRF ID will be placed in the pointed-at vrf_id_t
*
* cmd
* Parsed command number will be placed in the pointed-at integer
*
* Returns:
* -1 if:
* - insufficient data for header was read
* - a version mismatch was detected
* - a marker mismatch was detected
* - header size field specified more data than could be read
*/
extern int zclient_read_header(struct stream *s, int sock, u_int16_t *size,
u_char *marker, u_char *version,
vrf_id_t *vrf_id, u_int16_t *cmd);
/*
* Parse header from ZAPI message stream into struct zmsghdr.
* This function assumes the stream getp points at the first byte of the header.
* If the function is successful then the stream getp will point to the byte
* immediately after the last byte of the header.
*
* zmsg
* The stream containing the header
*
* hdr
* The header struct to parse into.
*
* Returns:
* true if parsing succeeded, false otherwise
*/
extern bool zapi_parse_header(struct stream *zmsg, struct zmsghdr *hdr);

extern void zclient_interface_set_master(struct zclient *client,
struct interface *master,
Expand All @@ -448,8 +497,7 @@ extern void zebra_interface_if_set_value(struct stream *, struct interface *);
extern void zebra_router_id_update_read(struct stream *s, struct prefix *rid);

#if CONFDATE > 20180823
CPP_NOTICE(
"zapi_ipv4_route, zapi_ipv6_route, zapi_ipv4_route_ipv6_nexthop as well as the zapi_ipv4 and zapi_ipv6 data structures should be removed now");
CPP_NOTICE("zapi_ipv4_route, zapi_ipv6_route, zapi_ipv4_route_ipv6_nexthop as well as the zapi_ipv4 and zapi_ipv6 data structures should be removed now");
#endif

extern int zapi_ipv4_route(u_char, struct zclient *, struct prefix_ipv4 *,
Expand Down
2 changes: 1 addition & 1 deletion zebra/zebra_vxlan.c
Original file line number Diff line number Diff line change
Expand Up @@ -6612,7 +6612,7 @@ void zebra_vxlan_advertise_gw_macip(ZAPI_HANDLER_ARGS)

zvni = zvni_lookup(vni);
if (!zvni)
return 0;
return;

if (IS_ZEBRA_DEBUG_VXLAN)
zlog_debug(
Expand Down
9 changes: 0 additions & 9 deletions zebra/zserv.h
Original file line number Diff line number Diff line change
Expand Up @@ -132,15 +132,6 @@ struct zserv {
int last_write_cmd;
};

/* ZAPI protocol structs */
struct zmsghdr {
uint16_t length;
uint8_t marker;
uint8_t version;
uint32_t vrf_id;
uint16_t command;
};

#define ZAPI_HANDLER_ARGS \
struct zserv *client, struct zmsghdr *hdr, struct stream *msg, \
struct zebra_vrf *zvrf
Expand Down

0 comments on commit 64ffa06

Please sign in to comment.