]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib, zebra: use existing zapi header struct
authorQuentin Young <qlyoung@cumulusnetworks.com>
Wed, 7 Mar 2018 16:23:58 +0000 (11:23 -0500)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Mon, 12 Mar 2018 18:57:06 +0000 (14:57 -0400)
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>
lib/zclient.c
lib/zclient.h
zebra/zebra_vxlan.c
zebra/zserv.h

index fa3a5f6691270da15f0266d013582e2ecce65203..20aaaca161c3314c980acc9eda9017693113675c 100644 (file)
@@ -322,6 +322,18 @@ stream_failure:
        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)
index 1aa94b641c8654c39be714999d36215b2ac10af2..c8574946d01fb0f5405374905ce68ae942745400 100644 (file)
@@ -237,14 +237,14 @@ struct zclient {
  */
 #define ZAPI_MESSAGE_TABLEID  0x80
 
+#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;
 };
@@ -449,9 +449,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,
@@ -469,8 +518,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 *,
index a8d184872357f5fc67faa52a743acc31e9931198..256fa9e4b71009a7b8a65b8496e855c1b5c44d27 100644 (file)
@@ -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(
index a055a28c0100addf4f59dfa99456916124934d65..62707510c2ef79547d87fbcaeee7cab4f9174faf 100644 (file)
@@ -133,15 +133,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