2004-12-07 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* bgp_main.c: (main) The 2nd argument to openzlog has been removed.
* isis_main.c: (main) The 2nd argument to openzlog has been removed.
* ospf6_main.c: (main) The 2nd argument to openzlog has been removed.
Note that stdout logging will no longer be enabled by default when
not running as a daemon.
* ospf_main.c: (main) The 2nd argument to openzlog has been removed.
* rip_main.c: (main) The 2nd argument to openzlog has been removed.
* ripng_main.c: (main) The 2nd argument to openzlog has been removed.
* main.c: (main) The 2nd argument to openzlog has been removed.
So stdout logging will no longer be enabled by default.
* irdp_main.c: (irdp_finish) Reduce severity of shutdown message
from LOG_WARNING to LOG_INFO.
* vtysh.c: Make several functions static instead of global.
Added several commands to support destination-specific logging levels.
(vtysh_completion) This function is unused, so comment it out.
* basic.texi: Document new logging features. Separate basic config
commands from basic VTY commands.
* log.h: Replace struct zlog flags and maskpri fields with maxlvl
array to support individual logging levels for each destination.
Remove the 2nd argument to openzlog since the default logging config
should be standardized inside the library. Replaced the
zlog_set_flag and zlog_reset_flag functions with zlog_set_level.
And zlog_set_file now requires an additional log_level argument.
Declare zlog_proto_names for use inside command.c in the
"show logging" command. Added defines useful for command
construction.
* log.c: (vzlog) Decide where to send the message based on the
individual logging levels configured for each destination.
Remove support for ZLOG_STDERR since it was never actually used.
Support record-priority for terminal monitors.
(zlog_signal,zlog_backtrace_sigsafe) Support destination-specific
logging levels. Remove stderr support (was never used). Added
support for terminal monitor logging.
(_zlog_assert_failed) Increase message severity to LOG_EMERG.
(openzlog) Remove 2nd argument since default config should be
standardized in library. By default, terminal monitoring
is set to debug, and all other logging is disabled.
(zlog_set_flag,zlog_reset_flag) Removed.
(zlog_set_level) New function to replace zlog_set_flag and
zlog_reset_flag. Supports destination-specific logging levels.
(zlog_set_file,zlog_reset_file) Support file-specific logging level.
(zlog_rotate) Log an error message if fopen fails, and support
new file-specific logging level.
* command.h: Change DEFUN_CMD_FUNC_DECL and DEFUN_CMD_FUNC_TEXT so that
command functions will be static instead of global. Remove
declarations for config_exit and config_help. Define new macros
DEFUNSH_ATTR, DEFUNSH_HIDDEN, and DEFUNSH_DEPRECATED so we can
have deprecated commands in vtysh. Similarly, for completeness,
define macros ALIAS_SH, ALIAS_SH_HIDDEN, and ALIAS_SH_DEPRECATED.
Also, fix bug in ALIAS_ATTR macro (didn't matter because it
was never used).
* command.c: Make many functions static instead of global.
(facility_name,facility_match,level_match) New functions
to support enhanced destination-specific logging levels.
(config_write_host) Support new destination-specific logging levels.
(config_logmsg) Added new "logmsg" command to help test logging
system.
(show_logging) Added "show logging" command to show the current
configuration of the logging system.
(config_log_stdout_level) Support explicit stdout logging level.
(no_config_log_stdout) Now takes optional LEVEL arg.
(config_log_monitor,config_log_monitor_level,no_config_log_monitor)
New commands creating new "log monitor" commands to set terminal
monitoring log level.
(config_log_file_level) Support explicit file logging level.
(config_log_syslog_level) Support explicit syslog logging level.
(config_log_facility,no_config_log_facility) Implement new
"log facility" command.
(cmd_init) Add hooks for new commands: "show logging", "logmsg",
"log stdout <level>", "log monitor", "log monitor <level>",
"no log monitor", "log file <filename> <level>",
"no log file <filename> <level>", "log syslog <level>",
"log facility", and "no log facility".
* vty.h: Added a "level" argument to vty_log so it can support
"log record-priority". Declare new function vty_log_fixed for
use in signal handlers.
* vty.c: (vty_log,vty_log_out) Added a "level" argument to support
"log record-priority" for vty terminal monitors.
(vty_down_level) Use config_exit_cmd.func instead of calling
config_exit directly (since command functions will now be static
instead of global).
(vty_log_fixed) New function to send terminal monitor messages
from inside a signal handler.
2004-12-07 16:39:31 +01:00
|
|
|
/*
|
|
|
|
* Logging of zebra
|
2002-12-13 21:15:29 +01:00
|
|
|
* Copyright (C) 1997, 1998, 1999 Kunihiro Ishiguro
|
|
|
|
*
|
|
|
|
* This file is part of GNU Zebra.
|
|
|
|
*
|
|
|
|
* GNU Zebra is free software; you can redistribute it and/or modify it
|
|
|
|
* under the terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation; either version 2, or (at your option) any
|
|
|
|
* later version.
|
|
|
|
*
|
|
|
|
* GNU Zebra is distributed in the hope that it will be useful, but
|
|
|
|
* WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* General Public License for more details.
|
|
|
|
*
|
2017-05-13 10:25:29 +02:00
|
|
|
* You should have received a copy of the GNU General Public License along
|
|
|
|
* with this program; see the file COPYING; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2002-12-13 21:15:29 +01:00
|
|
|
*/
|
|
|
|
|
2016-12-20 18:31:42 +01:00
|
|
|
#define FRR_DEFINE_DESC_TABLE
|
2009-09-16 01:52:42 +02:00
|
|
|
|
2002-12-13 21:15:29 +01:00
|
|
|
#include <zebra.h>
|
|
|
|
|
2016-12-12 18:47:48 +01:00
|
|
|
#include "zclient.h"
|
2002-12-13 21:15:29 +01:00
|
|
|
#include "log.h"
|
|
|
|
#include "memory.h"
|
|
|
|
#include "command.h"
|
2018-06-14 15:13:18 +02:00
|
|
|
#include "lib_errors.h"
|
2019-01-25 14:40:27 +01:00
|
|
|
#include "lib/hook.h"
|
2019-05-14 16:27:30 +02:00
|
|
|
#include "printfrr.h"
|
2019-06-21 10:58:02 +02:00
|
|
|
#include "frr_pthread.h"
|
2018-06-14 15:13:18 +02:00
|
|
|
|
2017-08-24 16:09:48 +02:00
|
|
|
#ifdef HAVE_LIBUNWIND
|
|
|
|
#define UNW_LOCAL_ONLY
|
|
|
|
#include <libunwind.h>
|
|
|
|
#include <dlfcn.h>
|
|
|
|
#endif
|
|
|
|
|
2017-06-21 01:56:50 +02:00
|
|
|
/**
|
|
|
|
* Looks up a message in a message list by key.
|
|
|
|
*
|
|
|
|
* If the message is not found, returns the provided error message.
|
|
|
|
*
|
|
|
|
* Terminates when it hits a struct message that's all zeros.
|
|
|
|
*
|
|
|
|
* @param mz the message list
|
|
|
|
* @param kz the message key
|
|
|
|
* @param nf the message to return if not found
|
|
|
|
* @return the message
|
|
|
|
*/
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *lookup_msg(const struct message *mz, int kz, const char *nf)
|
2017-06-21 01:56:50 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
static struct message nt = {0};
|
|
|
|
const char *rz = nf ? nf : "(no message found)";
|
|
|
|
const struct message *pnt;
|
|
|
|
for (pnt = mz; memcmp(pnt, &nt, sizeof(struct message)); pnt++)
|
|
|
|
if (pnt->key == kz) {
|
|
|
|
rz = pnt->str ? pnt->str : rz;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return rz;
|
2017-06-21 01:56:50 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2017-06-21 01:56:50 +02:00
|
|
|
/* For time string format. */
|
2017-07-17 14:03:14 +02:00
|
|
|
size_t quagga_timestamp(int timestamp_precision, char *buf, size_t buflen)
|
2002-12-13 21:15:29 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
static struct {
|
|
|
|
time_t last;
|
|
|
|
size_t len;
|
|
|
|
char buf[28];
|
|
|
|
} cache;
|
|
|
|
struct timeval clock;
|
|
|
|
|
|
|
|
gettimeofday(&clock, NULL);
|
|
|
|
|
|
|
|
/* first, we update the cache if the time has changed */
|
|
|
|
if (cache.last != clock.tv_sec) {
|
2020-03-05 17:42:12 +01:00
|
|
|
struct tm tm;
|
2017-07-17 14:03:14 +02:00
|
|
|
cache.last = clock.tv_sec;
|
2020-03-05 17:42:12 +01:00
|
|
|
localtime_r(&cache.last, &tm);
|
2017-07-17 14:03:14 +02:00
|
|
|
cache.len = strftime(cache.buf, sizeof(cache.buf),
|
2020-03-05 17:42:12 +01:00
|
|
|
"%Y/%m/%d %H:%M:%S", &tm);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
/* note: it's not worth caching the subsecond part, because
|
|
|
|
chances are that back-to-back calls are not sufficiently close
|
|
|
|
together
|
|
|
|
for the clock not to have ticked forward */
|
|
|
|
|
|
|
|
if (buflen > cache.len) {
|
|
|
|
memcpy(buf, cache.buf, cache.len);
|
|
|
|
if ((timestamp_precision > 0)
|
|
|
|
&& (buflen > cache.len + 1 + timestamp_precision)) {
|
|
|
|
/* should we worry about locale issues? */
|
|
|
|
static const int divisor[] = {0, 100000, 10000, 1000,
|
|
|
|
100, 10, 1};
|
|
|
|
int prec;
|
|
|
|
char *p = buf + cache.len + 1
|
|
|
|
+ (prec = timestamp_precision);
|
|
|
|
*p-- = '\0';
|
|
|
|
while (prec > 6)
|
|
|
|
/* this is unlikely to happen, but protect anyway */
|
|
|
|
{
|
|
|
|
*p-- = '0';
|
|
|
|
prec--;
|
|
|
|
}
|
|
|
|
clock.tv_usec /= divisor[prec];
|
|
|
|
do {
|
|
|
|
*p-- = '0' + (clock.tv_usec % 10);
|
|
|
|
clock.tv_usec /= 10;
|
|
|
|
} while (--prec > 0);
|
|
|
|
*p = '.';
|
|
|
|
return cache.len + 1 + timestamp_precision;
|
|
|
|
}
|
|
|
|
buf[cache.len] = '\0';
|
|
|
|
return cache.len;
|
2007-04-29 00:14:10 +02:00
|
|
|
}
|
2017-07-17 14:03:14 +02:00
|
|
|
if (buflen > 0)
|
|
|
|
buf[0] = '\0';
|
|
|
|
return 0;
|
2007-04-29 00:14:10 +02:00
|
|
|
}
|
2002-12-13 21:15:29 +01:00
|
|
|
|
2019-06-03 18:04:32 +02:00
|
|
|
/*
|
|
|
|
* crash handling
|
|
|
|
*
|
|
|
|
* NB: only AS-Safe (async-signal) functions can be used here!
|
|
|
|
*/
|
2004-11-29 00:00:01 +01:00
|
|
|
|
2019-06-03 18:04:32 +02:00
|
|
|
/* Note: the goal here is to use only async-signal-safe functions. */
|
|
|
|
void zlog_signal(int signo, const char *action, void *siginfo_v,
|
|
|
|
void *program_counter)
|
|
|
|
{
|
|
|
|
siginfo_t *siginfo = siginfo_v;
|
|
|
|
time_t now;
|
|
|
|
char buf[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")
|
|
|
|
+ 100];
|
|
|
|
struct fbuf fb = { .buf = buf, .pos = buf, .len = sizeof(buf) };
|
|
|
|
|
|
|
|
time(&now);
|
|
|
|
|
|
|
|
bprintfrr(&fb, "Received signal %d at %lld", signo, (long long)now);
|
|
|
|
if (program_counter)
|
|
|
|
bprintfrr(&fb, " (si_addr 0x%tx, PC 0x%tx)",
|
|
|
|
(ptrdiff_t)siginfo->si_addr,
|
|
|
|
(ptrdiff_t)program_counter);
|
|
|
|
else
|
|
|
|
bprintfrr(&fb, " (si_addr 0x%tx)",
|
|
|
|
(ptrdiff_t)siginfo->si_addr);
|
|
|
|
bprintfrr(&fb, "; %s\n", action);
|
|
|
|
|
2017-05-06 06:40:17 +02:00
|
|
|
zlog_sigsafe(fb.buf, fb.pos - fb.buf);
|
2019-06-03 18:04:32 +02:00
|
|
|
|
2017-05-06 06:40:17 +02:00
|
|
|
zlog_backtrace_sigsafe(LOG_CRIT, program_counter);
|
2019-06-03 18:04:32 +02:00
|
|
|
|
|
|
|
fb.pos = buf;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
struct thread *tc;
|
|
|
|
tc = pthread_getspecific(thread_current);
|
2013-11-18 23:52:02 +01:00
|
|
|
|
2019-06-03 18:04:32 +02:00
|
|
|
if (!tc)
|
|
|
|
bprintfrr(&fb, "no thread information available\n");
|
|
|
|
else
|
|
|
|
bprintfrr(&fb, "in thread %s scheduled from %s:%d\n",
|
|
|
|
tc->funcname, tc->schedfrom, tc->schedfrom_line);
|
2013-11-18 23:52:02 +01:00
|
|
|
|
2017-05-06 06:40:17 +02:00
|
|
|
zlog_sigsafe(fb.buf, fb.pos - fb.buf);
|
2004-11-26 19:11:14 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
/* Log a backtrace using only async-signal-safe functions.
|
|
|
|
Needs to be enhanced to support syslog logging. */
|
2017-07-17 14:03:14 +02:00
|
|
|
void zlog_backtrace_sigsafe(int priority, void *program_counter)
|
2004-11-26 19:11:14 +01:00
|
|
|
{
|
2017-08-24 16:09:48 +02:00
|
|
|
#ifdef HAVE_LIBUNWIND
|
2019-06-03 18:04:32 +02:00
|
|
|
char buf[256];
|
|
|
|
struct fbuf fb = { .buf = buf, .len = sizeof(buf) };
|
2017-08-24 16:09:48 +02:00
|
|
|
unw_cursor_t cursor;
|
|
|
|
unw_context_t uc;
|
|
|
|
unw_word_t ip, off, sp;
|
|
|
|
Dl_info dlinfo;
|
|
|
|
|
|
|
|
unw_getcontext(&uc);
|
|
|
|
unw_init_local(&cursor, &uc);
|
|
|
|
while (unw_step(&cursor) > 0) {
|
|
|
|
char name[128] = "?";
|
|
|
|
|
|
|
|
unw_get_reg(&cursor, UNW_REG_IP, &ip);
|
|
|
|
unw_get_reg(&cursor, UNW_REG_SP, &sp);
|
|
|
|
|
2019-06-03 18:04:32 +02:00
|
|
|
if (!unw_get_proc_name(&cursor, buf, sizeof(buf), &off))
|
|
|
|
snprintfrr(name, sizeof(name), "%s+%#lx",
|
|
|
|
buf, (long)off);
|
2017-08-24 16:09:48 +02:00
|
|
|
|
2019-06-03 18:04:32 +02:00
|
|
|
fb.pos = buf;
|
|
|
|
if (unw_is_signal_frame(&cursor))
|
|
|
|
bprintfrr(&fb, " ---- signal ----\n");
|
|
|
|
bprintfrr(&fb, "%-30s %16lx %16lx", name, (long)ip, (long)sp);
|
|
|
|
if (dladdr((void *)ip, &dlinfo))
|
|
|
|
bprintfrr(&fb, " %s (mapped at %p)",
|
|
|
|
dlinfo.dli_fname, dlinfo.dli_fbase);
|
|
|
|
bprintfrr(&fb, "\n");
|
2017-05-06 06:40:17 +02:00
|
|
|
zlog_sigsafe(fb.buf, fb.pos - fb.buf);
|
2017-08-24 16:09:48 +02:00
|
|
|
}
|
2017-05-06 06:40:17 +02:00
|
|
|
#elif defined(HAVE_GLIBC_BACKTRACE)
|
2017-07-17 14:03:14 +02:00
|
|
|
void *array[64];
|
2017-05-06 06:40:17 +02:00
|
|
|
int size, i;
|
2019-06-03 18:04:32 +02:00
|
|
|
char buf[128];
|
|
|
|
struct fbuf fb = { .buf = buf, .pos = buf, .len = sizeof(buf) };
|
|
|
|
char **bt = NULL;
|
2004-11-23 19:19:14 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
size = backtrace(array, array_size(array));
|
|
|
|
if (size <= 0 || (size_t)size > array_size(array))
|
|
|
|
return;
|
|
|
|
|
2017-05-06 06:40:17 +02:00
|
|
|
bprintfrr(&fb, "Backtrace for %d stack frames:", size);
|
|
|
|
zlog_sigsafe(fb.pos, fb.buf - fb.pos);
|
|
|
|
|
|
|
|
bt = backtrace_symbols(array, size);
|
|
|
|
|
|
|
|
for (i = 0; i < size; i++) {
|
|
|
|
fb.pos = buf;
|
|
|
|
if (bt)
|
|
|
|
bprintfrr(&fb, "%s", bt[i]);
|
|
|
|
else
|
|
|
|
bprintfrr(&fb, "[bt %d] 0x%tx", i,
|
|
|
|
(ptrdiff_t)(array[i]));
|
|
|
|
zlog_sigsafe(fb.buf, fb.pos - fb.buf);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2017-05-06 06:40:17 +02:00
|
|
|
if (bt)
|
|
|
|
free(bt);
|
2006-05-28 10:26:15 +02:00
|
|
|
#endif /* HAVE_STRACK_TRACE */
|
2004-11-26 19:11:14 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void zlog_backtrace(int priority)
|
2004-11-26 19:11:14 +01:00
|
|
|
{
|
2017-08-24 16:09:48 +02:00
|
|
|
#ifdef HAVE_LIBUNWIND
|
|
|
|
char buf[100];
|
|
|
|
unw_cursor_t cursor;
|
|
|
|
unw_context_t uc;
|
|
|
|
unw_word_t ip, off, sp;
|
|
|
|
Dl_info dlinfo;
|
|
|
|
|
|
|
|
unw_getcontext(&uc);
|
|
|
|
unw_init_local(&cursor, &uc);
|
|
|
|
zlog(priority, "Backtrace:");
|
|
|
|
while (unw_step(&cursor) > 0) {
|
|
|
|
char name[128] = "?";
|
|
|
|
|
|
|
|
unw_get_reg(&cursor, UNW_REG_IP, &ip);
|
|
|
|
unw_get_reg(&cursor, UNW_REG_SP, &sp);
|
|
|
|
|
|
|
|
if (unw_is_signal_frame(&cursor))
|
|
|
|
zlog(priority, " ---- signal ----");
|
|
|
|
|
|
|
|
if (!unw_get_proc_name(&cursor, buf, sizeof(buf), &off))
|
|
|
|
snprintf(name, sizeof(name), "%s+%#lx",
|
|
|
|
buf, (long)off);
|
|
|
|
|
|
|
|
if (dladdr((void *)ip, &dlinfo))
|
|
|
|
zlog(priority, "%-30s %16lx %16lx %s (mapped at %p)",
|
|
|
|
name, (long)ip, (long)sp,
|
|
|
|
dlinfo.dli_fname, dlinfo.dli_fbase);
|
|
|
|
else
|
|
|
|
zlog(priority, "%-30s %16lx %16lx",
|
|
|
|
name, (long)ip, (long)sp);
|
|
|
|
}
|
|
|
|
#elif defined(HAVE_GLIBC_BACKTRACE)
|
2017-07-17 14:03:14 +02:00
|
|
|
void *array[20];
|
|
|
|
int size, i;
|
|
|
|
char **strings;
|
|
|
|
|
|
|
|
size = backtrace(array, array_size(array));
|
|
|
|
if (size <= 0 || (size_t)size > array_size(array)) {
|
2018-08-06 18:36:50 +02:00
|
|
|
flog_err_sys(
|
2018-09-13 21:34:28 +02:00
|
|
|
EC_LIB_SYSTEM_CALL,
|
2020-03-27 12:35:23 +01:00
|
|
|
"Cannot get backtrace, returned invalid # of frames %d (valid range is between 1 and %lu)",
|
2018-08-06 18:36:50 +02:00
|
|
|
size, (unsigned long)(array_size(array)));
|
2017-07-17 14:03:14 +02:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
zlog(priority, "Backtrace for %d stack frames:", size);
|
|
|
|
if (!(strings = backtrace_symbols(array, size))) {
|
2018-09-13 21:34:28 +02:00
|
|
|
flog_err_sys(EC_LIB_SYSTEM_CALL,
|
2018-08-06 18:36:50 +02:00
|
|
|
"Cannot get backtrace symbols (out of memory?)");
|
2017-07-17 14:03:14 +02:00
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
zlog(priority, "[bt %d] %p", i, array[i]);
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < size; i++)
|
|
|
|
zlog(priority, "[bt %d] %s", i, strings[i]);
|
|
|
|
free(strings);
|
|
|
|
}
|
2017-08-24 16:09:48 +02:00
|
|
|
#else /* !HAVE_GLIBC_BACKTRACE && !HAVE_LIBUNWIND */
|
|
|
|
zlog(priority, "No backtrace available on this platform.");
|
|
|
|
#endif
|
2004-11-23 19:19:14 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void zlog_thread_info(int log_level)
|
2013-11-18 23:52:02 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
struct thread *tc;
|
|
|
|
tc = pthread_getspecific(thread_current);
|
|
|
|
|
|
|
|
if (tc)
|
|
|
|
zlog(log_level,
|
2020-03-27 12:35:23 +01:00
|
|
|
"Current thread function %s, scheduled from file %s, line %u",
|
2017-07-17 14:03:14 +02:00
|
|
|
tc->funcname, tc->schedfrom, tc->schedfrom_line);
|
|
|
|
else
|
|
|
|
zlog(log_level, "Current thread not known/applicable");
|
2013-11-18 23:52:02 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void _zlog_assert_failed(const char *assertion, const char *file,
|
|
|
|
unsigned int line, const char *function)
|
2004-11-24 18:14:49 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
zlog(LOG_CRIT, "Assertion `%s' failed in file %s, line %u, function %s",
|
|
|
|
assertion, file, line, (function ? function : "?"));
|
|
|
|
zlog_backtrace(LOG_CRIT);
|
|
|
|
zlog_thread_info(LOG_CRIT);
|
2017-08-23 16:18:49 +02:00
|
|
|
log_memstats(stderr, "log");
|
2017-07-17 14:03:14 +02:00
|
|
|
abort();
|
2004-11-24 18:14:49 +01:00
|
|
|
}
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
void memory_oom(size_t size, const char *name)
|
2015-05-27 03:45:30 +02:00
|
|
|
{
|
2017-05-06 06:40:17 +02:00
|
|
|
zlog(LOG_CRIT,
|
|
|
|
"out of memory: failed to allocate %zu bytes for %s object",
|
|
|
|
size, name);
|
|
|
|
zlog_backtrace(LOG_CRIT);
|
|
|
|
log_memstats(stderr, "log");
|
2015-05-27 03:45:30 +02:00
|
|
|
abort();
|
|
|
|
}
|
2014-06-04 06:53:35 +02:00
|
|
|
|
2004-11-20 00:40:16 +01:00
|
|
|
/* Wrapper around strerror to handle case where it returns NULL. */
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *safe_strerror(int errnum)
|
2004-11-20 00:40:16 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *s = strerror(errnum);
|
|
|
|
return (s != NULL) ? s : "Unknown error";
|
2004-11-20 00:40:16 +01:00
|
|
|
}
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
|
2006-05-15 18:56:51 +02:00
|
|
|
#define DESC_ENTRY(T) [(T)] = { (T), (#T), '\0' }
|
|
|
|
static const struct zebra_desc_table command_types[] = {
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_ADDRESS_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_ADDRESS_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_UP),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_DOWN),
|
2017-06-13 14:59:32 +02:00
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_SET_MASTER),
|
2017-08-20 02:59:41 +02:00
|
|
|
DESC_ENTRY(ZEBRA_ROUTE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_ROUTE_DELETE),
|
2017-11-09 19:55:46 +01:00
|
|
|
DESC_ENTRY(ZEBRA_ROUTE_NOTIFY_OWNER),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_REDISTRIBUTE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_REDISTRIBUTE_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_REDISTRIBUTE_DEFAULT_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_REDISTRIBUTE_DEFAULT_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_ROUTER_ID_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_ROUTER_ID_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_ROUTER_ID_UPDATE),
|
|
|
|
DESC_ENTRY(ZEBRA_HELLO),
|
2019-03-25 14:04:28 +01:00
|
|
|
DESC_ENTRY(ZEBRA_CAPABILITIES),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_NEXTHOP_REGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_NEXTHOP_UNREGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_NEXTHOP_UPDATE),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_NBR_ADDRESS_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_NBR_ADDRESS_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_BFD_DEST_UPDATE),
|
|
|
|
DESC_ENTRY(ZEBRA_IMPORT_ROUTE_REGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_IMPORT_ROUTE_UNREGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_IMPORT_CHECK_UPDATE),
|
|
|
|
DESC_ENTRY(ZEBRA_BFD_DEST_REGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_BFD_DEST_DEREGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_BFD_DEST_UPDATE),
|
|
|
|
DESC_ENTRY(ZEBRA_BFD_DEST_REPLAY),
|
2017-08-21 03:10:50 +02:00
|
|
|
DESC_ENTRY(ZEBRA_REDISTRIBUTE_ROUTE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_REDISTRIBUTE_ROUTE_DEL),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_VRF_UNREGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_VRF_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_VRF_DELETE),
|
2018-01-30 19:30:36 +01:00
|
|
|
DESC_ENTRY(ZEBRA_VRF_LABEL),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_VRF_UPDATE),
|
|
|
|
DESC_ENTRY(ZEBRA_BFD_CLIENT_REGISTER),
|
2019-03-25 14:04:28 +01:00
|
|
|
DESC_ENTRY(ZEBRA_BFD_CLIENT_DEREGISTER),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_ENABLE_RADV),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_DISABLE_RADV),
|
|
|
|
DESC_ENTRY(ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB),
|
|
|
|
DESC_ENTRY(ZEBRA_INTERFACE_LINK_PARAMS),
|
|
|
|
DESC_ENTRY(ZEBRA_MPLS_LABELS_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_MPLS_LABELS_DELETE),
|
2019-08-08 20:57:13 +02:00
|
|
|
DESC_ENTRY(ZEBRA_MPLS_LABELS_REPLACE),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_IPMR_ROUTE_STATS),
|
|
|
|
DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT),
|
2018-06-07 15:28:12 +02:00
|
|
|
DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT_ASYNC),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_GET_LABEL_CHUNK),
|
|
|
|
DESC_ENTRY(ZEBRA_RELEASE_LABEL_CHUNK),
|
2019-03-25 14:04:28 +01:00
|
|
|
DESC_ENTRY(ZEBRA_FEC_REGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_FEC_UNREGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_FEC_UPDATE),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_ADVERTISE_ALL_VNI),
|
2017-06-28 10:51:10 +02:00
|
|
|
DESC_ENTRY(ZEBRA_ADVERTISE_DEFAULT_GW),
|
2019-02-04 02:24:59 +01:00
|
|
|
DESC_ENTRY(ZEBRA_ADVERTISE_SVI_MACIP),
|
2017-11-20 06:47:04 +01:00
|
|
|
DESC_ENTRY(ZEBRA_ADVERTISE_SUBNET),
|
2018-04-14 00:01:12 +02:00
|
|
|
DESC_ENTRY(ZEBRA_LOCAL_ES_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_LOCAL_ES_DEL),
|
2020-03-28 01:14:45 +01:00
|
|
|
DESC_ENTRY(ZEBRA_REMOTE_ES_VTEP_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_REMOTE_ES_VTEP_DEL),
|
|
|
|
DESC_ENTRY(ZEBRA_LOCAL_ES_EVI_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_LOCAL_ES_EVI_DEL),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_VNI_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_VNI_DEL),
|
2017-10-08 03:49:27 +02:00
|
|
|
DESC_ENTRY(ZEBRA_L3VNI_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_L3VNI_DEL),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_REMOTE_VTEP_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_REMOTE_VTEP_DEL),
|
|
|
|
DESC_ENTRY(ZEBRA_MACIP_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_MACIP_DEL),
|
2017-11-20 06:47:04 +01:00
|
|
|
DESC_ENTRY(ZEBRA_IP_PREFIX_ROUTE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_IP_PREFIX_ROUTE_DEL),
|
2017-07-17 14:03:14 +02:00
|
|
|
DESC_ENTRY(ZEBRA_REMOTE_MACIP_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_REMOTE_MACIP_DEL),
|
2018-11-02 01:55:07 +01:00
|
|
|
DESC_ENTRY(ZEBRA_DUPLICATE_ADDR_DETECTION),
|
2017-05-15 17:09:28 +02:00
|
|
|
DESC_ENTRY(ZEBRA_PW_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_PW_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_PW_SET),
|
|
|
|
DESC_ENTRY(ZEBRA_PW_UNSET),
|
|
|
|
DESC_ENTRY(ZEBRA_PW_STATUS_UPDATE),
|
2018-02-15 01:52:01 +01:00
|
|
|
DESC_ENTRY(ZEBRA_RULE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_RULE_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_RULE_NOTIFY_OWNER),
|
2018-03-05 17:57:29 +01:00
|
|
|
DESC_ENTRY(ZEBRA_TABLE_MANAGER_CONNECT),
|
|
|
|
DESC_ENTRY(ZEBRA_GET_TABLE_CHUNK),
|
|
|
|
DESC_ENTRY(ZEBRA_RELEASE_TABLE_CHUNK),
|
2018-03-07 13:21:14 +01:00
|
|
|
DESC_ENTRY(ZEBRA_IPSET_CREATE),
|
|
|
|
DESC_ENTRY(ZEBRA_IPSET_DESTROY),
|
|
|
|
DESC_ENTRY(ZEBRA_IPSET_ENTRY_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_IPSET_ENTRY_DELETE),
|
2019-03-25 14:04:28 +01:00
|
|
|
DESC_ENTRY(ZEBRA_IPSET_NOTIFY_OWNER),
|
|
|
|
DESC_ENTRY(ZEBRA_IPSET_ENTRY_NOTIFY_OWNER),
|
|
|
|
DESC_ENTRY(ZEBRA_IPTABLE_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_IPTABLE_DELETE),
|
|
|
|
DESC_ENTRY(ZEBRA_IPTABLE_NOTIFY_OWNER),
|
2018-10-05 00:42:57 +02:00
|
|
|
DESC_ENTRY(ZEBRA_VXLAN_FLOOD_CONTROL),
|
2019-03-19 21:56:46 +01:00
|
|
|
DESC_ENTRY(ZEBRA_VXLAN_SG_ADD),
|
|
|
|
DESC_ENTRY(ZEBRA_VXLAN_SG_DEL),
|
2019-07-02 20:20:34 +02:00
|
|
|
DESC_ENTRY(ZEBRA_VXLAN_SG_REPLAY),
|
2020-02-06 18:30:56 +01:00
|
|
|
DESC_ENTRY(ZEBRA_MLAG_PROCESS_UP),
|
|
|
|
DESC_ENTRY(ZEBRA_MLAG_PROCESS_DOWN),
|
|
|
|
DESC_ENTRY(ZEBRA_MLAG_CLIENT_REGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_MLAG_CLIENT_UNREGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_MLAG_FORWARD_MSG),
|
2019-12-17 23:00:52 +01:00
|
|
|
DESC_ENTRY(ZEBRA_ERROR),
|
2020-04-06 22:10:13 +02:00
|
|
|
DESC_ENTRY(ZEBRA_CLIENT_CAPABILITIES),
|
|
|
|
DESC_ENTRY(ZEBRA_OPAQUE_MESSAGE),
|
|
|
|
DESC_ENTRY(ZEBRA_OPAQUE_REGISTER),
|
|
|
|
DESC_ENTRY(ZEBRA_OPAQUE_UNREGISTER)};
|
2006-05-15 18:56:51 +02:00
|
|
|
#undef DESC_ENTRY
|
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
static const struct zebra_desc_table unknown = {0, "unknown", '?'};
|
2006-05-15 18:56:51 +02:00
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
static const struct zebra_desc_table *zroute_lookup(unsigned int zroute)
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
{
|
2018-03-27 21:13:34 +02:00
|
|
|
unsigned int i;
|
2017-07-17 14:03:14 +02:00
|
|
|
|
|
|
|
if (zroute >= array_size(route_types)) {
|
2018-09-13 21:34:28 +02:00
|
|
|
flog_err(EC_LIB_DEVELOPMENT, "unknown zebra route type: %u",
|
2018-09-13 21:38:57 +02:00
|
|
|
zroute);
|
2017-07-17 14:03:14 +02:00
|
|
|
return &unknown;
|
|
|
|
}
|
|
|
|
if (zroute == route_types[zroute].type)
|
|
|
|
return &route_types[zroute];
|
|
|
|
for (i = 0; i < array_size(route_types); i++) {
|
|
|
|
if (zroute == route_types[i].type) {
|
|
|
|
zlog_warn(
|
2020-03-27 12:35:23 +01:00
|
|
|
"internal error: route type table out of order while searching for %u, please notify developers",
|
2017-07-17 14:03:14 +02:00
|
|
|
zroute);
|
|
|
|
return &route_types[i];
|
|
|
|
}
|
|
|
|
}
|
2018-09-13 21:34:28 +02:00
|
|
|
flog_err(EC_LIB_DEVELOPMENT,
|
2018-09-13 21:38:57 +02:00
|
|
|
"internal error: cannot find route type %u in table!", zroute);
|
2017-07-17 14:03:14 +02:00
|
|
|
return &unknown;
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
}
|
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
const char *zebra_route_string(unsigned int zroute)
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return zroute_lookup(zroute)->string;
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
}
|
|
|
|
|
2018-03-27 21:13:34 +02:00
|
|
|
char zebra_route_char(unsigned int zroute)
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
return zroute_lookup(zroute)->chr;
|
2005-10-01 Andrew J. Schorr <ajschorr@alumni.princeton.edu>
* zebra.h: Declare new functions zebra_route_string() and
zebra_route_char().
* log.c: (zroute_lookup,zebra_route_string,zebra_route_char) New
functions to map zebra route numbers to strings.
* zebra_vty.c: (route_type_str) Remove obsolete function: use new
library function zebra_route_string() instead. Note that there
are a few differences: for IPv6 routes, we now get "ripng" and
"ospf6" instead of the old behavior ("rip" and "ospf").
(route_type_char) Remove obsolete function: ues new library function
zebra_route_char() instead. Note that there is one difference:
the old function returned 'S' for a ZEBRA_ROUTE_SYSTEM route,
whereas the new one returns 'X'.
(vty_show_ip_route_detail,vty_show_ipv6_route_detail) Replace
route_type_str() with zebra_route_string().
(vty_show_ip_route,vty_show_ipv6_route) Replace route_type_char()
with zebra_route_char().
* bgp_vty.c: (bgp_config_write_redistribute) Use new library function
zebra_route_string instead of a local hard-coded table.
* ospf6_asbr.c: Remove local hard-coded tables zroute_name and
zroute_abname. Change the ZROUTE_NAME macro to use new library
function zebra_route_string(). Remove the ZROUTE_ABNAME macro.
(ospf6_asbr_external_route_show): Replace ZROUTE_ABNAME() with
a call to zebra_route_char(), and be sure to fix the format string,
since we now have a char instead of a char *.
* ospf6_zebra.c: Remove local hard-coded tables zebra_route_name and
zebra_route_abname. Note that the zebra_route_name[] table
contained mixed-case strings, whereas the zebra_route_string()
function returns lower-case strings.
(ospf6_zebra_read_ipv6): Change debug message to use new library
function zebra_route_string() instead of zebra_route_name[].
(show_zebra): Use new library function zebra_route_string() instead
of zebra_route_name[].
* ospf_dump.c: Remove local hard-coded table ospf_redistributed_proto.
(ospf_redist_string) New function implemented using new library
function zebra_route_string(). Note that there are a few differences
in the output that will result: the new function returns strings
that are lower-case, whereas the old table was mixed case. Also,
the old table mapped ZEBRA_ROUTE_OSPF6 to "OSPFv3", whereas the
new function returns "ospf6".
* ospfd.h: Remove extern struct message ospf_redistributed_proto[],
and add extern const char *ospf_redist_string(u_int route_type)
instead.
* ospf_asbr.c: (ospf_external_info_add) In two messages, use
ospf_redist_string instead of LOOKUP(ospf_redistributed_proto).
* ospf_vty.c: Remove local hard-coded table distribute_str.
(config_write_ospf_redistribute,config_write_ospf_distribute): Use
new library function zebra_route_string() instead of distribute_str[].
* ospf_zebra.c: (ospf_redistribute_set,ospf_redistribute_unset,
ospf_redistribute_default_set,ospf_redistribute_check)
In debug messages, use ospf_redist_string() instead of
LOOKUP(ospf_redistributed_proto).
* rip_zebra.c: (config_write_rip_redistribute): Remove local hard-coded
table str[]. Replace str[] with calls to new library function
zebra_route_string().
* ripd.c: Remove local hard-coded table route_info[].
(show_ip_rip) Replace uses of str[] with calls to new library
functions zebra_route_char and zebra_route_string.
* ripng_zebra.c: (ripng_redistribute_write) Remove local hard-coded
table str[]. Replace str[i] with new library function
zebra_route_string(i).
* ripngd.c: Remove local hard-coded table route_info[].
(show_ipv6_ripng) Use new library function zebra_route_char() instead
of table route_info[].
2005-10-01 19:38:06 +02:00
|
|
|
}
|
2006-05-15 18:56:51 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *zserv_command_string(unsigned int command)
|
2006-05-15 18:56:51 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (command >= array_size(command_types)) {
|
2018-09-13 21:34:28 +02:00
|
|
|
flog_err(EC_LIB_DEVELOPMENT, "unknown zserv command type: %u",
|
2018-09-13 21:38:57 +02:00
|
|
|
command);
|
2017-07-17 14:03:14 +02:00
|
|
|
return unknown.string;
|
|
|
|
}
|
|
|
|
return command_types[command].string;
|
2006-05-15 18:56:51 +02:00
|
|
|
}
|
2007-05-02 18:05:35 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int proto_name2num(const char *s)
|
2007-05-02 18:05:35 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
unsigned i;
|
2007-05-02 18:05:35 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
for (i = 0; i < array_size(route_types); ++i)
|
|
|
|
if (strcasecmp(s, route_types[i].string) == 0)
|
|
|
|
return route_types[i].type;
|
|
|
|
return -1;
|
2007-05-02 18:05:35 +02:00
|
|
|
}
|
2009-09-16 01:52:42 +02:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
int proto_redistnum(int afi, const char *s)
|
2009-09-16 01:52:42 +02:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
if (!s)
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
if (afi == AFI_IP) {
|
|
|
|
if (strmatch(s, "kernel"))
|
|
|
|
return ZEBRA_ROUTE_KERNEL;
|
|
|
|
else if (strmatch(s, "connected"))
|
|
|
|
return ZEBRA_ROUTE_CONNECT;
|
|
|
|
else if (strmatch(s, "static"))
|
|
|
|
return ZEBRA_ROUTE_STATIC;
|
|
|
|
else if (strmatch(s, "rip"))
|
|
|
|
return ZEBRA_ROUTE_RIP;
|
|
|
|
else if (strmatch(s, "eigrp"))
|
|
|
|
return ZEBRA_ROUTE_EIGRP;
|
|
|
|
else if (strmatch(s, "ospf"))
|
|
|
|
return ZEBRA_ROUTE_OSPF;
|
|
|
|
else if (strmatch(s, "isis"))
|
|
|
|
return ZEBRA_ROUTE_ISIS;
|
|
|
|
else if (strmatch(s, "bgp"))
|
|
|
|
return ZEBRA_ROUTE_BGP;
|
|
|
|
else if (strmatch(s, "table"))
|
|
|
|
return ZEBRA_ROUTE_TABLE;
|
|
|
|
else if (strmatch(s, "vnc"))
|
|
|
|
return ZEBRA_ROUTE_VNC;
|
|
|
|
else if (strmatch(s, "vnc-direct"))
|
|
|
|
return ZEBRA_ROUTE_VNC_DIRECT;
|
|
|
|
else if (strmatch(s, "nhrp"))
|
|
|
|
return ZEBRA_ROUTE_NHRP;
|
|
|
|
else if (strmatch(s, "babel"))
|
|
|
|
return ZEBRA_ROUTE_BABEL;
|
2017-11-10 18:55:16 +01:00
|
|
|
else if (strmatch(s, "sharp"))
|
|
|
|
return ZEBRA_ROUTE_SHARP;
|
2018-03-22 15:01:08 +01:00
|
|
|
else if (strmatch(s, "openfabric"))
|
|
|
|
return ZEBRA_ROUTE_OPENFABRIC;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
if (afi == AFI_IP6) {
|
|
|
|
if (strmatch(s, "kernel"))
|
|
|
|
return ZEBRA_ROUTE_KERNEL;
|
|
|
|
else if (strmatch(s, "connected"))
|
|
|
|
return ZEBRA_ROUTE_CONNECT;
|
|
|
|
else if (strmatch(s, "static"))
|
|
|
|
return ZEBRA_ROUTE_STATIC;
|
|
|
|
else if (strmatch(s, "ripng"))
|
|
|
|
return ZEBRA_ROUTE_RIPNG;
|
|
|
|
else if (strmatch(s, "ospf6"))
|
|
|
|
return ZEBRA_ROUTE_OSPF6;
|
|
|
|
else if (strmatch(s, "isis"))
|
|
|
|
return ZEBRA_ROUTE_ISIS;
|
|
|
|
else if (strmatch(s, "bgp"))
|
|
|
|
return ZEBRA_ROUTE_BGP;
|
|
|
|
else if (strmatch(s, "table"))
|
|
|
|
return ZEBRA_ROUTE_TABLE;
|
|
|
|
else if (strmatch(s, "vnc"))
|
|
|
|
return ZEBRA_ROUTE_VNC;
|
|
|
|
else if (strmatch(s, "vnc-direct"))
|
|
|
|
return ZEBRA_ROUTE_VNC_DIRECT;
|
|
|
|
else if (strmatch(s, "nhrp"))
|
|
|
|
return ZEBRA_ROUTE_NHRP;
|
|
|
|
else if (strmatch(s, "babel"))
|
|
|
|
return ZEBRA_ROUTE_BABEL;
|
2017-11-10 18:55:16 +01:00
|
|
|
else if (strmatch(s, "sharp"))
|
|
|
|
return ZEBRA_ROUTE_SHARP;
|
2018-03-22 15:01:08 +01:00
|
|
|
else if (strmatch(s, "openfabric"))
|
|
|
|
return ZEBRA_ROUTE_OPENFABRIC;
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
|
|
|
return -1;
|
2009-09-16 01:52:42 +02:00
|
|
|
}
|
2015-10-21 03:46:55 +02:00
|
|
|
|
2020-03-24 19:37:58 +01:00
|
|
|
void zlog_hexdump(const void *mem, size_t len)
|
2017-07-17 14:03:14 +02:00
|
|
|
{
|
2020-03-24 19:37:58 +01:00
|
|
|
char line[64];
|
|
|
|
const uint8_t *src = mem;
|
|
|
|
const uint8_t *end = src + len;
|
|
|
|
|
|
|
|
if (len == 0) {
|
|
|
|
zlog_debug("%016lx: (zero length / no data)", (long)src);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
while (src < end) {
|
|
|
|
struct fbuf fb = {
|
|
|
|
.buf = line,
|
|
|
|
.pos = line,
|
|
|
|
.len = sizeof(line),
|
|
|
|
};
|
|
|
|
const uint8_t *lineend = src + 8;
|
|
|
|
unsigned line_bytes = 0;
|
|
|
|
|
|
|
|
bprintfrr(&fb, "%016lx: ", (long)src);
|
|
|
|
|
|
|
|
while (src < lineend && src < end) {
|
|
|
|
bprintfrr(&fb, "%02x ", *src++);
|
|
|
|
line_bytes++;
|
|
|
|
}
|
|
|
|
if (line_bytes < 8)
|
|
|
|
bprintfrr(&fb, "%*s", (8 - line_bytes) * 3, "");
|
|
|
|
|
|
|
|
src -= line_bytes;
|
|
|
|
while (src < lineend && src < end && fb.pos < fb.buf + fb.len) {
|
|
|
|
uint8_t byte = *src++;
|
|
|
|
|
|
|
|
if (isprint(byte))
|
|
|
|
*fb.pos++ = byte;
|
|
|
|
else
|
|
|
|
*fb.pos++ = '.';
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2020-03-24 19:37:58 +01:00
|
|
|
|
|
|
|
zlog_debug("%.*s", (int)(fb.pos - fb.buf), fb.buf);
|
2017-07-17 14:03:14 +02:00
|
|
|
}
|
2015-10-21 03:46:55 +02:00
|
|
|
}
|
2017-03-02 17:33:37 +01:00
|
|
|
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *zlog_sanitize(char *buf, size_t bufsz, const void *in, size_t inlen)
|
2017-03-02 17:33:37 +01:00
|
|
|
{
|
2017-07-17 14:03:14 +02:00
|
|
|
const char *inbuf = in;
|
|
|
|
char *pos = buf, *end = buf + bufsz;
|
|
|
|
const char *iend = inbuf + inlen;
|
|
|
|
|
|
|
|
memset(buf, 0, bufsz);
|
|
|
|
for (; inbuf < iend; inbuf++) {
|
|
|
|
/* don't write partial escape sequence */
|
|
|
|
if (end - pos < 5)
|
|
|
|
break;
|
|
|
|
|
|
|
|
if (*inbuf == '\n')
|
|
|
|
snprintf(pos, end - pos, "\\n");
|
|
|
|
else if (*inbuf == '\r')
|
|
|
|
snprintf(pos, end - pos, "\\r");
|
|
|
|
else if (*inbuf == '\t')
|
|
|
|
snprintf(pos, end - pos, "\\t");
|
|
|
|
else if (*inbuf < ' ' || *inbuf == '"' || *inbuf >= 127)
|
|
|
|
snprintf(pos, end - pos, "\\x%02hhx", *inbuf);
|
|
|
|
else
|
|
|
|
*pos = *inbuf;
|
|
|
|
|
|
|
|
pos += strlen(pos);
|
|
|
|
}
|
|
|
|
return buf;
|
2017-03-02 17:33:37 +01:00
|
|
|
}
|