summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@nvidia.com>2020-11-07 00:21:50 +0100
committerDonald Sharp <sharpd@nvidia.com>2020-11-15 20:50:17 +0100
commit8a3f8f2e4ae1e8aaa3666fd8d38780e753bc09e7 (patch)
tree6d39449fbe173f576de0c4309dc284d837a6edb1
parentsharpd: Add buffering support (diff)
downloadfrr-8a3f8f2e4ae1e8aaa3666fd8d38780e753bc09e7.tar.xz
frr-8a3f8f2e4ae1e8aaa3666fd8d38780e753bc09e7.zip
bgpd, lib, sharpd: Add enum for zclient_send_message return
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>
-rw-r--r--bgpd/bgp_zebra.c9
-rw-r--r--lib/bfd.c6
-rw-r--r--lib/zclient.c29
-rw-r--r--lib/zclient.h11
-rw-r--r--ospf6d/ospf6_zebra.c2
-rw-r--r--sharpd/sharp_zebra.c12
6 files changed, 36 insertions, 33 deletions
diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c
index b2fec55ea..780780fd1 100644
--- a/bgpd/bgp_zebra.c
+++ b/bgpd/bgp_zebra.c
@@ -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;
diff --git a/lib/bfd.c b/lib/bfd.c
index d1a0ec671..f8211a4d6 100644
--- 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;
diff --git a/lib/zclient.c b/lib/zclient.c
index 980ecc5ed..56c131f7e 100644
--- a/lib/zclient.c
+++ b/lib/zclient.c
@@ -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);
}
diff --git a/lib/zclient.h b/lib/zclient.h
index e8629acbe..52fdfe202 100644
--- a/lib/zclient.h
+++ b/lib/zclient.h
@@ -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);
diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c
index b6c712176..4f18eaa26 100644
--- a/ospf6d/ospf6_zebra.c
+++ b/ospf6d/ospf6_zebra.c
@@ -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"),
diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c
index 2ef9af897..e88904097 100644
--- a/sharpd/sharp_zebra.c
+++ b/sharpd/sharp_zebra.c
@@ -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;
}
}