summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRenato Westphal <renato@opensourcerouting.org>2020-10-07 11:50:52 -0300
committerGitHub <noreply@github.com>2020-10-07 11:50:52 -0300
commit9cfb2747adc875a7aaa7f99a45a65f65234a2004 (patch)
tree2f1528432631a32fb22d98826a2ebb5ffd23246d
parent0ed866fd217079d7d7739b6f78fb01f3fd6533fd (diff)
parent9bee02322f69e34c54510f8dff245e52794fdfc8 (diff)
Merge pull request #7241 from chiragshah6/evpn_dev1
lib: add errmsg to nb rpc
-rw-r--r--lib/northbound.c5
-rw-r--r--lib/northbound.h9
-rw-r--r--lib/northbound_cli.c9
-rw-r--r--lib/northbound_cli.h5
-rw-r--r--lib/northbound_confd.c5
-rw-r--r--lib/northbound_grpc.cpp3
-rw-r--r--lib/northbound_sysrepo.c5
-rw-r--r--ripd/rip_cli.c2
-rw-r--r--ripngd/ripng_cli.c2
-rw-r--r--zebra/zebra_nb_rpcs.c11
-rw-r--r--zebra/zebra_vty.c3
-rw-r--r--zebra/zebra_vxlan.c28
-rw-r--r--zebra/zebra_vxlan.h7
13 files changed, 67 insertions, 27 deletions
diff --git a/lib/northbound.c b/lib/northbound.c
index 5816c162d8..c99f993ea5 100644
--- a/lib/northbound.c
+++ b/lib/northbound.c
@@ -1142,7 +1142,8 @@ const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
}
int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
- const struct list *input, struct list *output)
+ const struct list *input, struct list *output, char *errmsg,
+ size_t errmsg_len)
{
struct nb_cb_rpc_args args = {};
@@ -1151,6 +1152,8 @@ int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
args.xpath = xpath;
args.input = input;
args.output = output;
+ args.errmsg = errmsg;
+ args.errmsg_len = errmsg_len;
return nb_node->cbs.rpc(&args);
}
diff --git a/lib/northbound.h b/lib/northbound.h
index 01dc528aa4..16f19b3d5b 100644
--- a/lib/northbound.h
+++ b/lib/northbound.h
@@ -258,6 +258,12 @@ struct nb_cb_rpc_args {
/* List of output parameters to be populated by the callback. */
struct list *output;
+
+ /* Buffer to store human-readable error message in case of error. */
+ char *errmsg;
+
+ /* Size of errmsg. */
+ size_t errmsg_len;
};
/*
@@ -689,7 +695,8 @@ extern const void *nb_callback_lookup_entry(const struct nb_node *nb_node,
const void *parent_list_entry,
const struct yang_list_keys *keys);
extern int nb_callback_rpc(const struct nb_node *nb_node, const char *xpath,
- const struct list *input, struct list *output);
+ const struct list *input, struct list *output,
+ char *errmsg, size_t errmsg_len);
/*
* Create a northbound node for all YANG schema nodes.
diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c
index 6ce520149a..a7f3a1b305 100644
--- a/lib/northbound_cli.c
+++ b/lib/northbound_cli.c
@@ -284,10 +284,12 @@ int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt, ...)
return CMD_SUCCESS;
}
-int nb_cli_rpc(const char *xpath, struct list *input, struct list *output)
+int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
+ struct list *output)
{
struct nb_node *nb_node;
int ret;
+ char errmsg[BUFSIZ] = {0};
nb_node = nb_node_find(xpath);
if (!nb_node) {
@@ -296,11 +298,14 @@ int nb_cli_rpc(const char *xpath, struct list *input, struct list *output)
return CMD_WARNING;
}
- ret = nb_callback_rpc(nb_node, xpath, input, output);
+ ret = nb_callback_rpc(nb_node, xpath, input, output, errmsg,
+ sizeof(errmsg));
switch (ret) {
case NB_OK:
return CMD_SUCCESS;
default:
+ if (strlen(errmsg))
+ vty_show_nb_errors(vty, ret, errmsg);
return CMD_WARNING;
}
}
diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h
index 112d62efda..2290a76b8d 100644
--- a/lib/northbound_cli.h
+++ b/lib/northbound_cli.h
@@ -75,6 +75,9 @@ extern int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt,
/*
* Execute a YANG RPC or Action.
*
+ * vty
+ * The vty terminal to dump any error.
+ *
* xpath
* XPath of the YANG RPC or Action node.
*
@@ -90,7 +93,7 @@ extern int nb_cli_apply_changes(struct vty *vty, const char *xpath_base_fmt,
* Returns:
* CMD_SUCCESS on success, CMD_WARNING otherwise.
*/
-extern int nb_cli_rpc(const char *xpath, struct list *input,
+extern int nb_cli_rpc(struct vty *vty, const char *xpath, struct list *input,
struct list *output);
/*
diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c
index 1f480f3d02..c1cb0fc11d 100644
--- a/lib/northbound_confd.c
+++ b/lib/northbound_confd.c
@@ -1068,6 +1068,7 @@ static int frr_confd_action_execute(struct confd_user_info *uinfo,
struct yang_data *data;
confd_tag_value_t *reply;
int ret = CONFD_OK;
+ char errmsg[BUFSIZ] = {0};
/* Getting the XPath is tricky. */
if (kp) {
@@ -1115,7 +1116,9 @@ static int frr_confd_action_execute(struct confd_user_info *uinfo,
}
/* Execute callback registered for this XPath. */
- if (nb_callback_rpc(nb_node, xpath, input, output) != NB_OK) {
+ if (nb_callback_rpc(nb_node, xpath, input, output, errmsg,
+ sizeof(errmsg))
+ != NB_OK) {
flog_warn(EC_LIB_NB_CB_RPC, "%s: rpc callback failed: %s",
__func__, xpath);
ret = CONFD_ERR;
diff --git a/lib/northbound_grpc.cpp b/lib/northbound_grpc.cpp
index f35b4bb31b..abdae993b1 100644
--- a/lib/northbound_grpc.cpp
+++ b/lib/northbound_grpc.cpp
@@ -962,6 +962,7 @@ class NorthboundImpl
struct listnode *node;
struct yang_data *data;
const char *xpath;
+ char errmsg[BUFSIZ] = {0};
switch (tag->state) {
case CREATE:
@@ -1012,7 +1013,7 @@ class NorthboundImpl
// Execute callback registered for this XPath.
if (nb_callback_rpc(nb_node, xpath, input_list,
- output_list)
+ output_list, errmsg, sizeof(errmsg))
!= NB_OK) {
flog_warn(EC_LIB_NB_CB_RPC,
"%s: rpc callback failed: %s",
diff --git a/lib/northbound_sysrepo.c b/lib/northbound_sysrepo.c
index b5ef040a3f..3cd310c5a7 100644
--- a/lib/northbound_sysrepo.c
+++ b/lib/northbound_sysrepo.c
@@ -414,6 +414,7 @@ static int frr_sr_config_rpc_cb(sr_session_ctx_t *session, const char *xpath,
struct yang_data *data;
size_t cb_output_cnt;
int ret = SR_ERR_OK;
+ char errmsg[BUFSIZ] = {0};
nb_node = nb_node_find(xpath);
if (!nb_node) {
@@ -436,7 +437,9 @@ static int frr_sr_config_rpc_cb(sr_session_ctx_t *session, const char *xpath,
}
/* Execute callback registered for this XPath. */
- if (nb_callback_rpc(nb_node, xpath, input, output) != NB_OK) {
+ if (nb_callback_rpc(nb_node, xpath, input, output, errmsg,
+ sizeof(errmsg))
+ != NB_OK) {
flog_warn(EC_LIB_NB_CB_RPC, "%s: rpc callback failed: %s",
__func__, xpath);
ret = SR_ERR_OPERATION_FAILED;
diff --git a/ripd/rip_cli.c b/ripd/rip_cli.c
index 5e64b7afdb..87098ece64 100644
--- a/ripd/rip_cli.c
+++ b/ripd/rip_cli.c
@@ -1012,7 +1012,7 @@ DEFPY_YANG (clear_ip_rip,
listnode_add(input, yang_vrf);
}
- ret = nb_cli_rpc("/frr-ripd:clear-rip-route", input, NULL);
+ ret = nb_cli_rpc(vty, "/frr-ripd:clear-rip-route", input, NULL);
list_delete(&input);
diff --git a/ripngd/ripng_cli.c b/ripngd/ripng_cli.c
index f66de175fa..365082f806 100644
--- a/ripngd/ripng_cli.c
+++ b/ripngd/ripng_cli.c
@@ -496,7 +496,7 @@ DEFPY_YANG (clear_ipv6_rip,
listnode_add(input, yang_vrf);
}
- ret = nb_cli_rpc("/frr-ripngd:clear-ripng-route", input, NULL);
+ ret = nb_cli_rpc(vty, "/frr-ripngd:clear-ripng-route", input, NULL);
list_delete(&input);
diff --git a/zebra/zebra_nb_rpcs.c b/zebra/zebra_nb_rpcs.c
index 204cc5da6d..e7d438b1af 100644
--- a/zebra/zebra_nb_rpcs.c
+++ b/zebra/zebra_nb_rpcs.c
@@ -65,19 +65,22 @@ int clear_evpn_dup_addr_rpc(struct nb_cb_rpc_args *args)
if (yang_dup_mac) {
yang_str2mac(yang_dup_mac->value, &mac);
ret = zebra_vxlan_clear_dup_detect_vni_mac(
- zvrf, vni, &mac);
+ zvrf, vni, &mac, args->errmsg,
+ args->errmsg_len);
} else if (yang_dup_ip) {
yang_str2ip(yang_dup_ip->value, &host_ip);
ret = zebra_vxlan_clear_dup_detect_vni_ip(
- zvrf, vni, &host_ip);
+ zvrf, vni, &host_ip, args->errmsg,
+ args->errmsg_len);
} else
ret = zebra_vxlan_clear_dup_detect_vni(zvrf,
vni);
}
}
- ret = (ret != CMD_SUCCESS) ? NB_ERR : NB_OK;
+ if (ret < 0)
+ return NB_ERR;
- return ret;
+ return NB_OK;
}
/*
diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c
index 6785151705..920fdd6baa 100644
--- a/zebra/zebra_vty.c
+++ b/zebra/zebra_vty.c
@@ -3264,7 +3264,8 @@ DEFPY (clear_evpn_dup_addr,
if (yang_dup) {
listnode_add(input, yang_dup);
- ret = nb_cli_rpc("/frr-zebra:clear-evpn-dup-addr", input, NULL);
+ ret = nb_cli_rpc(vty, "/frr-zebra:clear-evpn-dup-addr", input,
+ NULL);
}
list_delete(&input);
diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c
index d8ed58edef..82e871801a 100644
--- a/zebra/zebra_vxlan.c
+++ b/zebra/zebra_vxlan.c
@@ -36,6 +36,7 @@
#ifdef GNU_LINUX
#include <linux/neighbour.h>
#endif
+#include "lib/printfrr.h"
#include "zebra/zebra_router.h"
#include "zebra/debug.h"
@@ -2994,7 +2995,8 @@ void zebra_vxlan_print_macs_vni_dad(struct vty *vty,
}
int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni,
- struct ethaddr *macaddr)
+ struct ethaddr *macaddr, char *errmsg,
+ size_t errmsg_len)
{
zebra_evpn_t *zevpn;
zebra_mac_t *mac;
@@ -3006,18 +3008,20 @@ int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni,
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
- zlog_warn("VNI %u does not exist\n", vni);
+ snprintfrr(errmsg, errmsg_len, "VNI %u does not exist", vni);
return -1;
}
mac = zebra_evpn_mac_lookup(zevpn, macaddr);
if (!mac) {
- zlog_warn("Requested MAC does not exist in VNI %u\n", vni);
+ snprintf(errmsg, errmsg_len,
+ "Requested MAC does not exist in VNI %u\n", vni);
return -1;
}
if (!CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) {
- zlog_warn("Requested MAC is not duplicate detected\n");
+ snprintfrr(errmsg, errmsg_len,
+ "Requested MAC is not duplicate detected\n");
return -1;
}
@@ -3079,7 +3083,8 @@ int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf, vni_t vni,
}
int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf *zvrf, vni_t vni,
- struct ipaddr *ip)
+ struct ipaddr *ip, char *errmsg,
+ size_t errmsg_len)
{
zebra_evpn_t *zevpn;
zebra_neigh_t *nbr;
@@ -3092,28 +3097,31 @@ int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf *zvrf, vni_t vni,
zevpn = zebra_evpn_lookup(vni);
if (!zevpn) {
- zlog_debug("VNI %u does not exist\n", vni);
+ snprintfrr(errmsg, errmsg_len, "VNI %u does not exist\n", vni);
return -1;
}
nbr = zebra_evpn_neigh_lookup(zevpn, ip);
if (!nbr) {
- zlog_warn("Requested host IP does not exist in VNI %u\n", vni);
+ snprintfrr(errmsg, errmsg_len,
+ "Requested host IP does not exist in VNI %u\n", vni);
return -1;
}
ipaddr2str(&nbr->ip, buf, sizeof(buf));
if (!CHECK_FLAG(nbr->flags, ZEBRA_NEIGH_DUPLICATE)) {
- zlog_warn("Requested host IP %s is not duplicate detected\n",
- buf);
+ snprintfrr(errmsg, errmsg_len,
+ "Requested host IP %s is not duplicate detected\n",
+ buf);
return -1;
}
mac = zebra_evpn_mac_lookup(zevpn, &nbr->emac);
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_DUPLICATE)) {
- zlog_warn(
+ snprintfrr(
+ errmsg, errmsg_len,
"Requested IP's associated MAC %s is still in duplicate state\n",
prefix_mac2str(&nbr->emac, buf2, sizeof(buf2)));
return -1;
diff --git a/zebra/zebra_vxlan.h b/zebra/zebra_vxlan.h
index 9c8af9d1fc..534e29936d 100644
--- a/zebra/zebra_vxlan.h
+++ b/zebra/zebra_vxlan.h
@@ -208,9 +208,12 @@ extern void zebra_vxlan_evpn_vrf_route_del(vrf_id_t vrf_id,
struct prefix *host_prefix);
extern int zebra_vxlan_clear_dup_detect_vni_mac(struct zebra_vrf *zvrf,
vni_t vni,
- struct ethaddr *macaddr);
+ struct ethaddr *macaddr,
+ char *errmsg,
+ size_t errmsg_len);
extern int zebra_vxlan_clear_dup_detect_vni_ip(struct zebra_vrf *zvrf,
- vni_t vni, struct ipaddr *ip);
+ vni_t vni, struct ipaddr *ip,
+ char *errmsg, size_t errmsg_len);
extern int zebra_vxlan_clear_dup_detect_vni_all(struct zebra_vrf *zvrf);
extern int zebra_vxlan_clear_dup_detect_vni(struct zebra_vrf *zvrf, vni_t vni);
extern void zebra_vxlan_handle_result(struct zebra_dplane_ctx *ctx);