diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/darr.c | 3 | ||||
| -rw-r--r-- | lib/darr.h | 24 | ||||
| -rw-r--r-- | lib/log.c | 2 | ||||
| -rw-r--r-- | lib/mgmt_msg_native.h | 16 | ||||
| -rw-r--r-- | lib/monotime.h | 16 | ||||
| -rw-r--r-- | lib/northbound_cli.c | 13 | ||||
| -rw-r--r-- | lib/northbound_cli.h | 3 | ||||
| -rw-r--r-- | lib/plist.c | 4 | ||||
| -rw-r--r-- | lib/vty.h | 1 | ||||
| -rw-r--r-- | lib/zclient.h | 2 |
10 files changed, 59 insertions, 25 deletions
diff --git a/lib/darr.c b/lib/darr.c index 7a01274104..0cffa64425 100644 --- a/lib/darr.c +++ b/lib/darr.c @@ -8,6 +8,7 @@ #include <zebra.h> #include "darr.h" #include "memory.h" +#include "printfrr.h" DEFINE_MTYPE(LIB, DARR, "Dynamic Array"); DEFINE_MTYPE(LIB, DARR_STR, "Dynamic Array String"); @@ -70,7 +71,7 @@ char *__darr_in_vsprintf(char **sp, bool concat, const char *fmt, va_list ap) *darr_append(*sp) = 0; again: va_copy(ap_copy, ap); - len = vsnprintf(darr_last(*sp), darr_avail(*sp) + 1, fmt, ap_copy); + len = vsnprintfrr(darr_last(*sp), darr_avail(*sp) + 1, fmt, ap_copy); va_end(ap_copy); if (len < 0) darr_in_strcat(*sp, fmt); diff --git a/lib/darr.h b/lib/darr.h index 2b9a0a0c02..121e3dd14e 100644 --- a/lib/darr.h +++ b/lib/darr.h @@ -272,10 +272,10 @@ void *__darr_resize(void *a, uint count, size_t esize, struct memtype *mt); */ #define darr_ensure_avail_mt(A, S, MT) \ ({ \ - ssize_t need = (ssize_t)(S) - \ - (ssize_t)(darr_cap(A) - darr_len(A)); \ - if (need > 0) \ - _darr_resize_mt((A), darr_cap(A) + need, MT); \ + ssize_t __dea_need = (ssize_t)(S) - \ + (ssize_t)(darr_cap(A) - darr_len(A)); \ + if (__dea_need > 0) \ + _darr_resize_mt((A), darr_cap(A) + __dea_need, MT); \ (A); \ }) #define darr_ensure_avail(A, S) darr_ensure_avail_mt(A, S, MTYPE_DARR) @@ -301,9 +301,9 @@ void *__darr_resize(void *a, uint count, size_t esize, struct memtype *mt); #define darr_ensure_cap_mt(A, C, MT) \ ({ \ /* Cast to avoid warning when C == 0 */ \ - uint _c = (C) > 0 ? (C) : 1; \ - if ((size_t)darr_cap(A) < _c) \ - _darr_resize_mt((A), _c, MT); \ + uint __dec_c = (C) > 0 ? (C) : 1; \ + if ((size_t)darr_cap(A) < __dec_c) \ + _darr_resize_mt((A), __dec_c, MT); \ (A); \ }) #define darr_ensure_cap(A, C) darr_ensure_cap_mt(A, C, MTYPE_DARR) @@ -428,12 +428,12 @@ void *__darr_resize(void *a, uint count, size_t esize, struct memtype *mt); #define _darr_append_n(A, N, Z, MT) \ ({ \ - uint __len = darr_len(A); \ - darr_ensure_cap_mt(A, __len + (N), MT); \ - _darr_len(A) = __len + (N); \ + uint __da_len = darr_len(A); \ + darr_ensure_cap_mt(A, __da_len + (N), MT); \ + _darr_len(A) = __da_len + (N); \ if (Z) \ - memset(&(A)[__len], 0, (N)*_darr_esize(A)); \ - &(A)[__len]; \ + memset(&(A)[__da_len], 0, (N)*_darr_esize(A)); \ + &(A)[__da_len]; \ }) /** * Extending the array's length by N. @@ -358,7 +358,7 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_BFD_CLIENT_DEREGISTER), DESC_ENTRY(ZEBRA_INTERFACE_ENABLE_RADV), DESC_ENTRY(ZEBRA_INTERFACE_DISABLE_RADV), - DESC_ENTRY(ZEBRA_NEXTHOP_LOOKUP_MRIB), + DESC_ENTRY(ZEBRA_NEXTHOP_LOOKUP), DESC_ENTRY(ZEBRA_INTERFACE_LINK_PARAMS), DESC_ENTRY(ZEBRA_MPLS_LABELS_ADD), DESC_ENTRY(ZEBRA_MPLS_LABELS_DELETE), diff --git a/lib/mgmt_msg_native.h b/lib/mgmt_msg_native.h index ef03b66edc..587a002801 100644 --- a/lib/mgmt_msg_native.h +++ b/lib/mgmt_msg_native.h @@ -554,8 +554,8 @@ extern int vmgmt_msg_native_send_error(struct msg_conn *conn, */ #define mgmt_msg_native_alloc_msg(msg_type, var_len, mem_type) \ ({ \ - uint8_t *buf = NULL; \ - (msg_type *)darr_append_nz_mt(buf, \ + uint8_t *__nam_buf = NULL; \ + (msg_type *)darr_append_nz_mt(__nam_buf, \ sizeof(msg_type) + (var_len), \ mem_type); \ }) @@ -590,10 +590,10 @@ extern int vmgmt_msg_native_send_error(struct msg_conn *conn, */ #define mgmt_msg_native_append(msg, data, len) \ ({ \ - uint8_t **darrp = mgmt_msg_native_get_darrp(msg); \ - uint8_t *p = darr_append_n(*darrp, len); \ - memcpy(p, data, len); \ - p; \ + uint8_t **__na_darrp = mgmt_msg_native_get_darrp(msg); \ + uint8_t *__na_p = darr_append_n(*__na_darrp, len); \ + memcpy(__na_p, data, len); \ + __na_p; \ }) /** @@ -611,8 +611,8 @@ extern int vmgmt_msg_native_send_error(struct msg_conn *conn, */ #define mgmt_msg_native_add_str(msg, s) \ do { \ - int __len = strlen(s) + 1; \ - mgmt_msg_native_append(msg, s, __len); \ + int __nas_len = strlen(s) + 1; \ + mgmt_msg_native_append(msg, s, __nas_len); \ } while (0) /** diff --git a/lib/monotime.h b/lib/monotime.h index f7ae1bbbe1..5e1bfe754e 100644 --- a/lib/monotime.h +++ b/lib/monotime.h @@ -129,6 +129,22 @@ static inline char *time_to_string(time_t ts, char *buf) return ctime_r(&tbuf, buf); } +/* A wrapper for time_to_string() which removes newline at the end. + * This is needed for JSON outputs, where newline is not expected. + */ +static inline char *time_to_string_json(time_t ts, char *buf) +{ + size_t len; + + time_to_string(ts, buf); + len = strlen(buf); + + if (len && buf[len - 1] == '\n') + buf[len - 1] = '\0'; + + return buf; +} + /* Convert interval to human-friendly string, used in cli output e.g. */ static inline const char *frrtime_to_interval(time_t t, char *buf, size_t buflen) diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index f9794bee3c..b199dd61f8 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -83,6 +83,7 @@ static int nb_cli_classic_commit(struct vty *vty) static void nb_cli_pending_commit_clear(struct vty *vty) { vty->pending_commit = 0; + vty->buffer_cmd_count = 0; XFREE(MTYPE_TMP, vty->pending_cmds_buf); vty->pending_cmds_buflen = 0; vty->pending_cmds_bufpos = 0; @@ -102,12 +103,19 @@ int nb_cli_pending_commit_check(struct vty *vty) static int nb_cli_schedule_command(struct vty *vty) { - /* Append command to dynamically sized buffer of scheduled commands. */ + /* Append command to dynamically sized buffer of scheduled commands. + * vty->buf -Incoming config + * vty->pending_cmds_buf - Pending buffer where incoming configs are + * accumulated for later processing + * vty->pending_cmds_bufpos - length of the pending buffer + * + */ if (!vty->pending_cmds_buf) { vty->pending_cmds_buflen = 4096; vty->pending_cmds_buf = XCALLOC(MTYPE_TMP, vty->pending_cmds_buflen); } + if ((strlen(vty->buf) + 3) > (vty->pending_cmds_buflen - vty->pending_cmds_bufpos)) { vty->pending_cmds_buflen *= 2; @@ -121,6 +129,9 @@ static int nb_cli_schedule_command(struct vty *vty) /* Schedule the commit operation. */ vty->pending_commit = 1; + vty->buffer_cmd_count++; + if (vty->buffer_cmd_count == NB_CMD_BATCH_SIZE) + nb_cli_pending_commit_check(vty); return CMD_SUCCESS; } diff --git a/lib/northbound_cli.h b/lib/northbound_cli.h index 4c8dc50bd2..43c40f49e1 100644 --- a/lib/northbound_cli.h +++ b/lib/northbound_cli.h @@ -20,6 +20,9 @@ enum nb_cfg_format { NB_CFG_FMT_XML, }; +/* Maximum config commands in a batch*/ +#define NB_CMD_BATCH_SIZE 5000 + extern struct nb_config *vty_shared_candidate_config; /* diff --git a/lib/plist.c b/lib/plist.c index 2cfaa7d81d..6950ab5761 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -1136,8 +1136,10 @@ static int vty_show_prefix_list_prefix(struct vty *vty, afi_t afi, match = 0; if (type == normal_display || type == first_match_display) - if (prefix_same(&p, &pentry->prefix)) + if (prefix_list_entry_match(pentry, &p, false)) { + pentry->hitcnt++; match = 1; + } if (type == longer_display) { if ((p.family == pentry->prefix.family) @@ -149,6 +149,7 @@ struct vty { struct nb_config *candidate_config_base; /* Dynamic transaction information. */ + size_t buffer_cmd_count; bool pending_allowed; bool pending_commit; char *pending_cmds_buf; diff --git a/lib/zclient.h b/lib/zclient.h index 6da9558aa5..2385a8a219 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -131,7 +131,7 @@ typedef enum { ZEBRA_BFD_CLIENT_DEREGISTER, ZEBRA_INTERFACE_ENABLE_RADV, ZEBRA_INTERFACE_DISABLE_RADV, - ZEBRA_NEXTHOP_LOOKUP_MRIB, + ZEBRA_NEXTHOP_LOOKUP, ZEBRA_INTERFACE_LINK_PARAMS, ZEBRA_MPLS_LABELS_ADD, ZEBRA_MPLS_LABELS_DELETE, |
