summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/darr.c3
-rw-r--r--lib/darr.h24
-rw-r--r--lib/mgmt_msg_native.h16
-rw-r--r--lib/monotime.h16
-rw-r--r--lib/northbound_cli.c13
-rw-r--r--lib/northbound_cli.h3
-rw-r--r--lib/route_types.txt2
-rw-r--r--lib/vty.h1
8 files changed, 55 insertions, 23 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.
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/route_types.txt b/lib/route_types.txt
index 93cbc36e97..b5f8b6fdf3 100644
--- a/lib/route_types.txt
+++ b/lib/route_types.txt
@@ -88,7 +88,7 @@ ZEBRA_ROUTE_VRRP, vrrp, vrrpd, '-', 0, 0, 0, "VRRP", vr
ZEBRA_ROUTE_NHG, zebra, none, '-', 0, 0, 0, "Nexthop Group", none
ZEBRA_ROUTE_SRTE, srte, none, '-', 0, 0, 0, "SR-TE", none
ZEBRA_ROUTE_TABLE_DIRECT, table-direct, zebra, 't', 1, 1, 1, "Table-Direct", zebra
-ZEBRA_ROUTE_ALL, wildcard, none, '-', 0, 0, 0, "-", none
+ZEBRA_ROUTE_ALL, any, none, '-', 0, 0, 0, "-", none
## help strings
diff --git a/lib/vty.h b/lib/vty.h
index be54159aa9..c6f9f5a3a7 100644
--- a/lib/vty.h
+++ b/lib/vty.h
@@ -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;