]> git.puffer.fish Git - matthieu/frr.git/commitdiff
bgpd, lib, sharpd: Add enum for zclient_send_message return
authorDonald Sharp <sharpd@nvidia.com>
Fri, 6 Nov 2020 23:21:50 +0000 (18:21 -0500)
committerDonald Sharp <sharpd@nvidia.com>
Sun, 15 Nov 2020 19:50:17 +0000 (14:50 -0500)
Add a `enum zclient_send_status` for appropriate handling
of return codes from zclient_send_message.  Touch all the places
where we handle this.

Signed-off-by: Donald Sharp <sharpd@nvidia.com>
bgpd/bgp_zebra.c
lib/bfd.c
lib/zclient.c
lib/zclient.h
ospf6d/ospf6_zebra.c
sharpd/sharp_zebra.c

index b2fec55eae5f031846c1a332903f7a4ddbafd34e..780780fd1ffdac44ead12e9fc21d8a42be38455c 100644 (file)
@@ -3050,7 +3050,8 @@ void bgp_send_pbr_rule_action(struct bgp_pbr_action *pbra,
        bgp_encode_pbr_rule_action(s, pbra, pbr);
 
        stream_putw_at(s, 0, stream_get_endp(s));
-       if ((zclient_send_message(zclient) != -1) && install) {
+       if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE)
+           && install) {
                if (!pbr)
                        pbra->install_in_progress = true;
                else
@@ -3081,7 +3082,7 @@ void bgp_send_pbr_ipset_match(struct bgp_pbr_match *pbrim, bool install)
        bgp_encode_pbr_ipset_match(s, pbrim);
 
        stream_putw_at(s, 0, stream_get_endp(s));
-       if ((zclient_send_message(zclient) != -1) && install)
+       if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE) && install)
                pbrim->install_in_progress = true;
 }
 
@@ -3109,7 +3110,7 @@ void bgp_send_pbr_ipset_entry_match(struct bgp_pbr_match_entry *pbrime,
        bgp_encode_pbr_ipset_entry_match(s, pbrime);
 
        stream_putw_at(s, 0, stream_get_endp(s));
-       if ((zclient_send_message(zclient) != -1) && install)
+       if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE) && install)
                pbrime->install_in_progress = true;
 }
 
@@ -3184,7 +3185,7 @@ void bgp_send_pbr_iptable(struct bgp_pbr_action *pba,
        stream_putw_at(s, 0, stream_get_endp(s));
        ret = zclient_send_message(zclient);
        if (install) {
-               if (ret != -1)
+               if (ret != ZCLIENT_SEND_FAILURE)
                        pba->refcnt++;
                else
                        pbm->install_iptable_in_progress = true;
index d1a0ec671e505c3e7fbf0616774fb16e1320a337..f8211a4d6ede346174ab6183f7ab96e8faa84282 100644 (file)
--- a/lib/bfd.c
+++ b/lib/bfd.c
@@ -402,7 +402,7 @@ void bfd_client_sendmsg(struct zclient *zclient, int command,
                        vrf_id_t vrf_id)
 {
        struct stream *s;
-       int ret;
+       enum zclient_send_status ret;
 
        /* Check socket. */
        if (!zclient || zclient->sock < 0) {
@@ -423,7 +423,7 @@ void bfd_client_sendmsg(struct zclient *zclient, int command,
 
        ret = zclient_send_message(zclient);
 
-       if (ret < 0) {
+       if (ret == ZCLIENT_SEND_FAILURE) {
                if (bfd_debug)
                        zlog_debug(
                                "bfd_client_sendmsg %ld: zclient_send_message() failed",
@@ -516,7 +516,7 @@ int zclient_bfd_command(struct zclient *zc, struct bfd_session_arg *args)
        stream_putw_at(s, 0, stream_get_endp(s));
 
        /* Send message to zebra. */
-       if (zclient_send_message(zc) == -1) {
+       if (zclient_send_message(zc) == ZCLIENT_SEND_FAILURE) {
                if (bfd_debug)
                        zlog_debug("%s: zclient_send_message failed", __func__);
                return -1;
index 980ecc5ed8d4e818e5563f164f68d256736c5ec5..56c131f7e3a60c68bcead6a1061d6dbad517ed87 100644 (file)
@@ -249,12 +249,12 @@ int zclient_socket_connect(struct zclient *zclient)
        return sock;
 }
 
-static int zclient_failed(struct zclient *zclient)
+static enum zclient_send_status zclient_failed(struct zclient *zclient)
 {
        zclient->fail++;
        zclient_stop(zclient);
        zclient_event(ZCLIENT_CONNECT, zclient);
-       return -1;
+       return ZCLIENT_SEND_FAILURE;
 }
 
 static int zclient_flush_data(struct thread *thread)
@@ -285,14 +285,15 @@ static int zclient_flush_data(struct thread *thread)
 }
 
 /*
- * -1 is a failure
- *  0 means we sent
- *  1 means we are buffering
+ * Returns:
+ * ZCLIENT_SEND_FAILED   - is a failure
+ * ZCLIENT_SEND_SUCCESS  - means we sent data to zebra
+ * ZCLIENT_SEND_BUFFERED - means we are buffering
  */
-int zclient_send_message(struct zclient *zclient)
+enum zclient_send_status zclient_send_message(struct zclient *zclient)
 {
        if (zclient->sock < 0)
-               return -1;
+               return ZCLIENT_SEND_FAILURE;
        switch (buffer_write(zclient->wb, zclient->sock,
                             STREAM_DATA(zclient->obuf),
                             stream_get_endp(zclient->obuf))) {
@@ -303,17 +304,15 @@ int zclient_send_message(struct zclient *zclient)
                return zclient_failed(zclient);
        case BUFFER_EMPTY:
                THREAD_OFF(zclient->t_write);
-               return 0;
-               break;
+               return ZCLIENT_SEND_SUCCESS;
        case BUFFER_PENDING:
                thread_add_write(zclient->master, zclient_flush_data, zclient,
                                 zclient->sock, &zclient->t_write);
-               return 1;
-               break;
+               return ZCLIENT_SEND_BUFFERED;
        }
 
        /* should not get here */
-       return 0;
+       return ZCLIENT_SEND_SUCCESS;
 }
 
 /*
@@ -771,11 +770,11 @@ int zclient_send_rnh(struct zclient *zclient, int command,
  *
  * XXX: No attention paid to alignment.
  */
-int zclient_route_send(uint8_t cmd, struct zclient *zclient,
-                      struct zapi_route *api)
+enum zclient_send_status
+zclient_route_send(uint8_t cmd, struct zclient *zclient, struct zapi_route *api)
 {
        if (zapi_route_encode(cmd, zclient->obuf, api) < 0)
-               return -1;
+               return ZCLIENT_SEND_FAILURE;
        return zclient_send_message(zclient);
 }
 
index e8629acbee2434ee64179fad229f49904a6d6d85..52fdfe202cf8a648751aa7b116a67d7709e35163 100644 (file)
@@ -669,6 +669,12 @@ enum zapi_iptable_notify_owner {
        ZAPI_IPTABLE_FAIL_REMOVE,
 };
 
+enum zclient_send_status {
+       ZCLIENT_SEND_FAILURE = -1,
+       ZCLIENT_SEND_SUCCESS = 0,
+       ZCLIENT_SEND_BUFFERED = 1
+};
+
 static inline const char *
 zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note)
 {
@@ -811,7 +817,7 @@ extern void zclient_redistribute_default(int command, struct zclient *,
  *  0 data was successfully sent
  *  1 data was buffered for future usage
  */
-extern int zclient_send_message(struct zclient *);
+extern enum zclient_send_status 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);
@@ -919,7 +925,8 @@ extern int zebra_send_pw(struct zclient *zclient, int command,
 extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS,
                                       struct zapi_pw_status *pw);
 
-extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *);
+extern enum zclient_send_status zclient_route_send(uint8_t, struct zclient *,
+                                                  struct zapi_route *);
 extern int zclient_send_rnh(struct zclient *zclient, int command,
                            const struct prefix *p, bool exact_match,
                            vrf_id_t vrf_id);
index b6c712176a5b4d8eea39d37c718233c56dee2c82..4f18eaa26b9a40db31fefd1f9f64b94f2e54aa18 100644 (file)
@@ -328,7 +328,7 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request,
        else
                ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
 
-       if (ret < 0)
+       if (ret == ZCLIENT_SEND_FAILURE)
                flog_err(EC_LIB_ZAPI_SOCKET,
                         "zclient_route_send() %s failed: %s",
                         (type == REM ? "delete" : "add"),
index 2ef9af897e4f761835ea4bf11354c083a8872624..e88904097aec622e88d30fca65636f89aef5984c 100644 (file)
@@ -289,7 +289,8 @@ static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance,
                api.backup_nexthop_num = i;
        }
 
-       if (zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api) == 1)
+       if (zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api)
+           == ZCLIENT_SEND_BUFFERED)
                return true;
        else
                return false;
@@ -312,7 +313,8 @@ static bool route_delete(struct prefix *p, vrf_id_t vrf_id, uint8_t instance)
        api.instance = instance;
        memcpy(&api.prefix, p, sizeof(*p));
 
-       if (zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api) == 1)
+       if (zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api)
+           == ZCLIENT_SEND_BUFFERED)
                return true;
        else
                return false;
@@ -356,8 +358,6 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count,
                        return;
                }
        }
-
-       return;
 }
 
 void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id,
@@ -409,8 +409,6 @@ static void sharp_remove_routes_restart(struct prefix *p, uint32_t count,
                        return;
                }
        }
-
-       return;
 }
 
 void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id,
@@ -454,12 +452,10 @@ static void sharp_zclient_buffer_ready(void)
                                             wb.instance, wb.nhgid, wb.nhg,
                                             wb.backup_nhg, wb.routes);
                return;
-               break;
        case SHARP_DELETE_ROUTES_RESTART:
                sharp_remove_routes_restart(&wb.p, wb.count, wb.vrf_id,
                                            wb.instance, wb.routes);
                return;
-               break;
        }
 }