#include "lib_errors.h"
#include "lib/hook.h"
#include "printfrr.h"
+#include "frr_pthread.h"
#ifndef SUNOS_5
#include <sys/un.h>
void zlog_filter_clear(void)
{
- pthread_mutex_lock(&loglock);
- zlog_filter_count = 0;
- pthread_mutex_unlock(&loglock);
+ frr_with_mutex(&loglock) {
+ zlog_filter_count = 0;
+ }
}
int zlog_filter_add(const char *filter)
{
- pthread_mutex_lock(&loglock);
+ frr_with_mutex(&loglock) {
+ if (zlog_filter_count >= ZLOG_FILTERS_MAX)
+ return 1;
- int ret = 0;
+ if (zlog_filter_lookup(filter) != -1)
+ /* Filter already present */
+ return -1;
- if (zlog_filter_count >= ZLOG_FILTERS_MAX) {
- ret = 1;
- goto done;
- }
+ strlcpy(zlog_filters[zlog_filter_count], filter,
+ sizeof(zlog_filters[0]));
- if (zlog_filter_lookup(filter) != -1) {
- /* Filter already present */
- ret = -1;
- goto done;
- }
+ if (zlog_filters[zlog_filter_count][0] == '\0')
+ /* Filter was either empty or didn't get copied
+ * correctly
+ */
+ return -1;
- strlcpy(zlog_filters[zlog_filter_count], filter,
- sizeof(zlog_filters[0]));
-
- if (zlog_filters[zlog_filter_count][0] == '\0') {
- /* Filter was either empty or didn't get copied correctly */
- ret = -1;
- goto done;
+ zlog_filter_count++;
}
-
- zlog_filter_count++;
-
-done:
- pthread_mutex_unlock(&loglock);
- return ret;
+ return 0;
}
int zlog_filter_del(const char *filter)
{
- pthread_mutex_lock(&loglock);
-
- int found_idx = zlog_filter_lookup(filter);
- int last_idx = zlog_filter_count - 1;
- int ret = 0;
+ frr_with_mutex(&loglock) {
+ int found_idx = zlog_filter_lookup(filter);
+ int last_idx = zlog_filter_count - 1;
- if (found_idx == -1) {
- /* Didn't find the filter to delete */
- ret = -1;
- goto done;
- }
+ if (found_idx == -1)
+ /* Didn't find the filter to delete */
+ return -1;
- /* Adjust the filter array */
- memmove(zlog_filters[found_idx], zlog_filters[found_idx + 1],
- (last_idx - found_idx) * sizeof(zlog_filters[0]));
+ /* Adjust the filter array */
+ memmove(zlog_filters[found_idx], zlog_filters[found_idx + 1],
+ (last_idx - found_idx) * sizeof(zlog_filters[0]));
- zlog_filter_count--;
-
-done:
- pthread_mutex_unlock(&loglock);
- return ret;
+ zlog_filter_count--;
+ }
+ return 0;
}
/* Dump all filters to buffer, delimited by new line */
int zlog_filter_dump(char *buf, size_t max_size)
{
- pthread_mutex_lock(&loglock);
-
- int ret = 0;
int len = 0;
- for (int i = 0; i < zlog_filter_count; i++) {
- ret = snprintf(buf + len, max_size - len, " %s\n",
- zlog_filters[i]);
- len += ret;
- if ((ret < 0) || ((size_t)len >= max_size)) {
- len = -1;
- goto done;
+ frr_with_mutex(&loglock) {
+ for (int i = 0; i < zlog_filter_count; i++) {
+ int ret;
+ ret = snprintf(buf + len, max_size - len, " %s\n",
+ zlog_filters[i]);
+ len += ret;
+ if ((ret < 0) || ((size_t)len >= max_size))
+ return -1;
}
}
-done:
- pthread_mutex_unlock(&loglock);
return len;
}
/* va_list version of zlog. */
void vzlog(int priority, const char *format, va_list args)
{
- pthread_mutex_lock(&loglock);
+ frr_mutex_lock_autounlock(&loglock);
char proto_str[32] = "";
int original_errno = errno;
/* If it doesn't match on a filter, do nothing with the debug log */
if ((priority == LOG_DEBUG) && zlog_filter_count
- && vzlog_filter(zl, &tsctl, proto_str, priority, msg)) {
- pthread_mutex_unlock(&loglock);
+ && vzlog_filter(zl, &tsctl, proto_str, priority, msg))
goto out;
- }
/* call external hook */
hook_call(zebra_ext_log, priority, format, args);
if (msg != buf)
XFREE(MTYPE_TMP, msg);
errno = original_errno;
- pthread_mutex_unlock(&loglock);
}
int vzlog_test(int priority)
{
- pthread_mutex_lock(&loglock);
-
- int ret = 0;
+ frr_mutex_lock_autounlock(&loglock);
struct zlog *zl = zlog_default;
/* When zlog_default is also NULL, use stderr for logging. */
if (zl == NULL)
- ret = 1;
+ return 1;
/* Syslog output */
else if (priority <= zl->maxlvl[ZLOG_DEST_SYSLOG])
- ret = 1;
+ return 1;
/* File output. */
else if ((priority <= zl->maxlvl[ZLOG_DEST_FILE]) && zl->fp)
- ret = 1;
+ return 1;
/* stdout output. */
else if (priority <= zl->maxlvl[ZLOG_DEST_STDOUT])
- ret = 1;
+ return 1;
/* Terminal monitor. */
else if (priority <= zl->maxlvl[ZLOG_DEST_MONITOR])
- ret = 1;
+ return 1;
- pthread_mutex_unlock(&loglock);
-
- return ret;
+ return 0;
}
/*
void zlog_signal(int signo, const char *action, void *siginfo_v,
void *program_counter)
{
-#ifdef SA_SIGINFO
siginfo_t *siginfo = siginfo_v;
-#endif
time_t now;
char buf[sizeof("DEFAULT: Received signal S at T (si_addr 0xP, PC 0xP); aborting...")
+ 100];
msgstart = fb.pos;
bprintfrr(&fb, "Received signal %d at %lld", signo, (long long)now);
-#ifdef SA_SIGINFO
if (program_counter)
bprintfrr(&fb, " (si_addr 0x%tx, PC 0x%tx)",
(ptrdiff_t)siginfo->si_addr,
else
bprintfrr(&fb, " (si_addr 0x%tx)",
(ptrdiff_t)siginfo->si_addr);
-#endif /* SA_SIGINFO */
bprintfrr(&fb, "; %s\n", action);
crash_write(&fb, msgstart);
openlog(progname, syslog_flags, zl->facility);
- pthread_mutex_lock(&loglock);
- zlog_default = zl;
- pthread_mutex_unlock(&loglock);
+ frr_with_mutex(&loglock) {
+ zlog_default = zl;
+ }
#ifdef HAVE_GLIBC_BACKTRACE
/* work around backtrace() using lazily resolved dynamically linked
void closezlog(void)
{
- pthread_mutex_lock(&loglock);
+ frr_mutex_lock_autounlock(&loglock);
+
struct zlog *zl = zlog_default;
closelog();
XFREE(MTYPE_ZLOG, zl);
zlog_default = NULL;
- pthread_mutex_unlock(&loglock);
}
/* Called from command.c. */
void zlog_set_level(zlog_dest_t dest, int log_level)
{
- pthread_mutex_lock(&loglock);
- zlog_default->maxlvl[dest] = log_level;
- pthread_mutex_unlock(&loglock);
+ frr_with_mutex(&loglock) {
+ zlog_default->maxlvl[dest] = log_level;
+ }
}
int zlog_set_file(const char *filename, int log_level)
if (fp == NULL) {
ret = 0;
} else {
- pthread_mutex_lock(&loglock);
- zl = zlog_default;
-
- /* Set flags. */
- zl->filename = XSTRDUP(MTYPE_ZLOG, filename);
- zl->maxlvl[ZLOG_DEST_FILE] = log_level;
- zl->fp = fp;
- logfile_fd = fileno(fp);
- pthread_mutex_unlock(&loglock);
+ frr_with_mutex(&loglock) {
+ zl = zlog_default;
+
+ /* Set flags. */
+ zl->filename = XSTRDUP(MTYPE_ZLOG, filename);
+ zl->maxlvl[ZLOG_DEST_FILE] = log_level;
+ zl->fp = fp;
+ logfile_fd = fileno(fp);
+ }
}
return ret;
/* Reset opend file. */
int zlog_reset_file(void)
{
- pthread_mutex_lock(&loglock);
+ frr_mutex_lock_autounlock(&loglock);
struct zlog *zl = zlog_default;
zl->maxlvl[ZLOG_DEST_FILE] = ZLOG_DISABLED;
XFREE(MTYPE_ZLOG, zl->filename);
- zl->filename = NULL;
-
- pthread_mutex_unlock(&loglock);
return 1;
}
DESC_ENTRY(ZEBRA_INTERFACE_LINK_PARAMS),
DESC_ENTRY(ZEBRA_MPLS_LABELS_ADD),
DESC_ENTRY(ZEBRA_MPLS_LABELS_DELETE),
+ DESC_ENTRY(ZEBRA_MPLS_LABELS_REPLACE),
DESC_ENTRY(ZEBRA_IPMR_ROUTE_STATS),
DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT),
DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT_ASYNC),
DESC_ENTRY(ZEBRA_VXLAN_SG_ADD),
DESC_ENTRY(ZEBRA_VXLAN_SG_DEL),
DESC_ENTRY(ZEBRA_VXLAN_SG_REPLAY),
-};
+ DESC_ENTRY(ZEBRA_ERROR),
+ DESC_ENTRY(ZEBRA_CLIENT_CAPABILITIES)};
#undef DESC_ENTRY
static const struct zebra_desc_table unknown = {0, "unknown", '?'};
size_t bs = ((len / 8) + 1) * 53 + 1;
char buf[bs];
char *s = buf;
+ const unsigned char *memch = mem;
memset(buf, 0, sizeof(buf));
/* print offset */
if (i % columns == 0)
s += snprintf(s, bs - (s - buf),
- "0x%016lx: ", (unsigned long)mem + i);
+ "0x%016lx: ", (unsigned long)memch + i);
/* print hex data */
if (i < len)
- s += snprintf(s, bs - (s - buf), "%02x ",
- 0xFF & ((const char *)mem)[i]);
+ s += snprintf(s, bs - (s - buf), "%02x ", memch[i]);
/* end of block, just aligning for ASCII dump */
else
/* end of block not really printing */
if (j >= len)
s += snprintf(s, bs - (s - buf), " ");
- else if (isprint((int)((const char *)mem)[j]))
- s += snprintf(
- s, bs - (s - buf), "%c",
- 0xFF & ((const char *)mem)[j]);
+ else if (isprint(memch[j]))
+ s += snprintf(s, bs - (s - buf), "%c",
+ memch[j]);
else /* other char */
s += snprintf(s, bs - (s - buf), ".");
}