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>
This commit is contained in:
Donald Sharp 2020-11-06 18:21:50 -05:00
parent 07414912cd
commit 8a3f8f2e4a
6 changed files with 36 additions and 33 deletions

View File

@ -3050,7 +3050,8 @@ void bgp_send_pbr_rule_action(struct bgp_pbr_action *pbra,
bgp_encode_pbr_rule_action(s, pbra, pbr); bgp_encode_pbr_rule_action(s, pbra, pbr);
stream_putw_at(s, 0, stream_get_endp(s)); 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) if (!pbr)
pbra->install_in_progress = true; pbra->install_in_progress = true;
else 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); bgp_encode_pbr_ipset_match(s, pbrim);
stream_putw_at(s, 0, stream_get_endp(s)); 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; 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); bgp_encode_pbr_ipset_entry_match(s, pbrime);
stream_putw_at(s, 0, stream_get_endp(s)); 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; 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)); stream_putw_at(s, 0, stream_get_endp(s));
ret = zclient_send_message(zclient); ret = zclient_send_message(zclient);
if (install) { if (install) {
if (ret != -1) if (ret != ZCLIENT_SEND_FAILURE)
pba->refcnt++; pba->refcnt++;
else else
pbm->install_iptable_in_progress = true; pbm->install_iptable_in_progress = true;

View File

@ -402,7 +402,7 @@ void bfd_client_sendmsg(struct zclient *zclient, int command,
vrf_id_t vrf_id) vrf_id_t vrf_id)
{ {
struct stream *s; struct stream *s;
int ret; enum zclient_send_status ret;
/* Check socket. */ /* Check socket. */
if (!zclient || zclient->sock < 0) { if (!zclient || zclient->sock < 0) {
@ -423,7 +423,7 @@ void bfd_client_sendmsg(struct zclient *zclient, int command,
ret = zclient_send_message(zclient); ret = zclient_send_message(zclient);
if (ret < 0) { if (ret == ZCLIENT_SEND_FAILURE) {
if (bfd_debug) if (bfd_debug)
zlog_debug( zlog_debug(
"bfd_client_sendmsg %ld: zclient_send_message() failed", "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)); stream_putw_at(s, 0, stream_get_endp(s));
/* Send message to zebra. */ /* Send message to zebra. */
if (zclient_send_message(zc) == -1) { if (zclient_send_message(zc) == ZCLIENT_SEND_FAILURE) {
if (bfd_debug) if (bfd_debug)
zlog_debug("%s: zclient_send_message failed", __func__); zlog_debug("%s: zclient_send_message failed", __func__);
return -1; return -1;

View File

@ -249,12 +249,12 @@ int zclient_socket_connect(struct zclient *zclient)
return sock; return sock;
} }
static int zclient_failed(struct zclient *zclient) static enum zclient_send_status zclient_failed(struct zclient *zclient)
{ {
zclient->fail++; zclient->fail++;
zclient_stop(zclient); zclient_stop(zclient);
zclient_event(ZCLIENT_CONNECT, zclient); zclient_event(ZCLIENT_CONNECT, zclient);
return -1; return ZCLIENT_SEND_FAILURE;
} }
static int zclient_flush_data(struct thread *thread) static int zclient_flush_data(struct thread *thread)
@ -285,14 +285,15 @@ static int zclient_flush_data(struct thread *thread)
} }
/* /*
* -1 is a failure * Returns:
* 0 means we sent * ZCLIENT_SEND_FAILED - is a failure
* 1 means we are buffering * 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) if (zclient->sock < 0)
return -1; return ZCLIENT_SEND_FAILURE;
switch (buffer_write(zclient->wb, zclient->sock, switch (buffer_write(zclient->wb, zclient->sock,
STREAM_DATA(zclient->obuf), STREAM_DATA(zclient->obuf),
stream_get_endp(zclient->obuf))) { stream_get_endp(zclient->obuf))) {
@ -303,17 +304,15 @@ int zclient_send_message(struct zclient *zclient)
return zclient_failed(zclient); return zclient_failed(zclient);
case BUFFER_EMPTY: case BUFFER_EMPTY:
THREAD_OFF(zclient->t_write); THREAD_OFF(zclient->t_write);
return 0; return ZCLIENT_SEND_SUCCESS;
break;
case BUFFER_PENDING: case BUFFER_PENDING:
thread_add_write(zclient->master, zclient_flush_data, zclient, thread_add_write(zclient->master, zclient_flush_data, zclient,
zclient->sock, &zclient->t_write); zclient->sock, &zclient->t_write);
return 1; return ZCLIENT_SEND_BUFFERED;
break;
} }
/* should not get here */ /* 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. * XXX: No attention paid to alignment.
*/ */
int zclient_route_send(uint8_t cmd, struct zclient *zclient, enum zclient_send_status
struct zapi_route *api) zclient_route_send(uint8_t cmd, struct zclient *zclient, struct zapi_route *api)
{ {
if (zapi_route_encode(cmd, zclient->obuf, api) < 0) if (zapi_route_encode(cmd, zclient->obuf, api) < 0)
return -1; return ZCLIENT_SEND_FAILURE;
return zclient_send_message(zclient); return zclient_send_message(zclient);
} }

View File

@ -669,6 +669,12 @@ enum zapi_iptable_notify_owner {
ZAPI_IPTABLE_FAIL_REMOVE, ZAPI_IPTABLE_FAIL_REMOVE,
}; };
enum zclient_send_status {
ZCLIENT_SEND_FAILURE = -1,
ZCLIENT_SEND_SUCCESS = 0,
ZCLIENT_SEND_BUFFERED = 1
};
static inline const char * static inline const char *
zapi_rule_notify_owner2str(enum zapi_rule_notify_owner note) 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 * 0 data was successfully sent
* 1 data was buffered for future usage * 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 */ /* 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 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, extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS,
struct zapi_pw_status *pw); 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, extern int zclient_send_rnh(struct zclient *zclient, int command,
const struct prefix *p, bool exact_match, const struct prefix *p, bool exact_match,
vrf_id_t vrf_id); vrf_id_t vrf_id);

View File

@ -328,7 +328,7 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request,
else else
ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api);
if (ret < 0) if (ret == ZCLIENT_SEND_FAILURE)
flog_err(EC_LIB_ZAPI_SOCKET, flog_err(EC_LIB_ZAPI_SOCKET,
"zclient_route_send() %s failed: %s", "zclient_route_send() %s failed: %s",
(type == REM ? "delete" : "add"), (type == REM ? "delete" : "add"),

View 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; 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; return true;
else else
return false; return false;
@ -312,7 +313,8 @@ static bool route_delete(struct prefix *p, vrf_id_t vrf_id, uint8_t instance)
api.instance = instance; api.instance = instance;
memcpy(&api.prefix, p, sizeof(*p)); 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; return true;
else else
return false; return false;
@ -356,8 +358,6 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count,
return; return;
} }
} }
return;
} }
void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id, 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;
} }
} }
return;
} }
void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id, 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.instance, wb.nhgid, wb.nhg,
wb.backup_nhg, wb.routes); wb.backup_nhg, wb.routes);
return; return;
break;
case SHARP_DELETE_ROUTES_RESTART: case SHARP_DELETE_ROUTES_RESTART:
sharp_remove_routes_restart(&wb.p, wb.count, wb.vrf_id, sharp_remove_routes_restart(&wb.p, wb.count, wb.vrf_id,
wb.instance, wb.routes); wb.instance, wb.routes);
return; return;
break;
} }
} }