mirror of
https://git.proxmox.com/git/mirror_frr
synced 2025-08-16 00:25:01 +00:00
Merge pull request #5716 from opensourcerouting/bfdd-log
bfdd: remove logging shim & fix warnings
This commit is contained in:
commit
6fe6a8b544
31
bfdd/bfd.h
31
bfdd/bfd.h
@ -427,27 +427,20 @@ void pl_free(struct peer_label *pl);
|
|||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* log.c
|
* logging - alias to zebra log
|
||||||
*
|
|
||||||
* Contains code that does the logging procedures. Might implement multiple
|
|
||||||
* backends (e.g. zebra log, syslog or other logging lib).
|
|
||||||
*/
|
*/
|
||||||
enum blog_level {
|
|
||||||
/* level vs syslog equivalent */
|
|
||||||
BLOG_DEBUG = 0, /* LOG_DEBUG */
|
|
||||||
BLOG_INFO = 1, /* LOG_INFO */
|
|
||||||
BLOG_WARNING = 2, /* LOG_WARNING */
|
|
||||||
BLOG_ERROR = 3, /* LOG_ERR */
|
|
||||||
BLOG_FATAL = 4, /* LOG_CRIT */
|
|
||||||
};
|
|
||||||
|
|
||||||
void log_init(int foreground, enum blog_level level,
|
#define log_debug zlog_debug
|
||||||
struct frr_daemon_info *fdi);
|
#define log_info zlog_info
|
||||||
void log_info(const char *fmt, ...);
|
#define log_warning zlog_warn
|
||||||
void log_debug(const char *fmt, ...);
|
#define log_error zlog_err
|
||||||
void log_warning(const char *fmt, ...);
|
|
||||||
void log_error(const char *fmt, ...);
|
#define log_fatal(msg, ...) \
|
||||||
void log_fatal(const char *fmt, ...);
|
do { \
|
||||||
|
zlog_err(msg, ## __VA_ARGS__); \
|
||||||
|
assert(!msg); \
|
||||||
|
abort(); \
|
||||||
|
} while (0)
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -116,7 +116,7 @@ int _ptm_bfd_send(struct bfd_session *bs, uint16_t *port, const void *data,
|
|||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
if (rv < (ssize_t)datalen)
|
if (rv < (ssize_t)datalen)
|
||||||
log_debug("packet-send: send partial", strerror(errno));
|
log_debug("packet-send: send partial: %s", strerror(errno));
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -799,7 +799,7 @@ int bp_udp_send(int sd, uint8_t ttl, uint8_t *data, size_t datalen,
|
|||||||
log_debug("udp-send: loopback failure: (%d) %s", errno, strerror(errno));
|
log_debug("udp-send: loopback failure: (%d) %s", errno, strerror(errno));
|
||||||
return -1;
|
return -1;
|
||||||
} else if (wlen < (ssize_t)datalen) {
|
} else if (wlen < (ssize_t)datalen) {
|
||||||
log_debug("udp-send: partial send: %ld expected %ld", wlen,
|
log_debug("udp-send: partial send: %zd expected %zu", wlen,
|
||||||
datalen);
|
datalen);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
@ -216,15 +216,12 @@ int main(int argc, char *argv[])
|
|||||||
parse_config(conf);
|
parse_config(conf);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* Initialize logging API. */
|
/* Initialize FRR infrastructure. */
|
||||||
log_init(1, BLOG_DEBUG, &bfdd_di);
|
master = frr_init();
|
||||||
|
|
||||||
/* Initialize control socket. */
|
/* Initialize control socket. */
|
||||||
control_init(ctl_path);
|
control_init(ctl_path);
|
||||||
|
|
||||||
/* Initialize FRR infrastructure. */
|
|
||||||
master = frr_init();
|
|
||||||
|
|
||||||
/* Initialize BFD data structures. */
|
/* Initialize BFD data structures. */
|
||||||
bfd_initialize();
|
bfd_initialize();
|
||||||
|
|
||||||
|
@ -215,7 +215,8 @@ static int parse_peer_config(struct json_object *jo, struct bfd_peer_cfg *bpc)
|
|||||||
if (strlcpy(bpc->bpc_localif, sval,
|
if (strlcpy(bpc->bpc_localif, sval,
|
||||||
sizeof(bpc->bpc_localif))
|
sizeof(bpc->bpc_localif))
|
||||||
> sizeof(bpc->bpc_localif)) {
|
> sizeof(bpc->bpc_localif)) {
|
||||||
log_debug("\tlocal-interface: %s (truncated)");
|
log_debug("\tlocal-interface: %s (truncated)",
|
||||||
|
sval);
|
||||||
error++;
|
error++;
|
||||||
} else {
|
} else {
|
||||||
log_debug("\tlocal-interface: %s", sval);
|
log_debug("\tlocal-interface: %s", sval);
|
||||||
@ -235,7 +236,7 @@ static int parse_peer_config(struct json_object *jo, struct bfd_peer_cfg *bpc)
|
|||||||
bpc->bpc_detectmultiplier =
|
bpc->bpc_detectmultiplier =
|
||||||
json_object_get_int64(jo_val);
|
json_object_get_int64(jo_val);
|
||||||
bpc->bpc_has_detectmultiplier = true;
|
bpc->bpc_has_detectmultiplier = true;
|
||||||
log_debug("\tdetect-multiplier: %llu",
|
log_debug("\tdetect-multiplier: %u",
|
||||||
bpc->bpc_detectmultiplier);
|
bpc->bpc_detectmultiplier);
|
||||||
} else if (strcmp(key, "receive-interval") == 0) {
|
} else if (strcmp(key, "receive-interval") == 0) {
|
||||||
bpc->bpc_recvinterval = json_object_get_int64(jo_val);
|
bpc->bpc_recvinterval = json_object_get_int64(jo_val);
|
||||||
|
@ -471,7 +471,7 @@ static int control_read(struct thread *t)
|
|||||||
bcb->bcb_buf = XMALLOC(MTYPE_BFDD_NOTIFICATION,
|
bcb->bcb_buf = XMALLOC(MTYPE_BFDD_NOTIFICATION,
|
||||||
sizeof(bcm) + bcb->bcb_left + 1);
|
sizeof(bcm) + bcb->bcb_left + 1);
|
||||||
if (bcb->bcb_buf == NULL) {
|
if (bcb->bcb_buf == NULL) {
|
||||||
log_warning("%s: not enough memory for message size: %u",
|
log_warning("%s: not enough memory for message size: %zu",
|
||||||
__func__, bcb->bcb_left);
|
__func__, bcb->bcb_left);
|
||||||
control_free(bcs);
|
control_free(bcs);
|
||||||
return 0;
|
return 0;
|
||||||
|
125
bfdd/log.c
125
bfdd/log.c
@ -1,125 +0,0 @@
|
|||||||
/*********************************************************************
|
|
||||||
* Copyright 2017-2018 Network Device Education Foundation, Inc. ("NetDEF")
|
|
||||||
*
|
|
||||||
* This program 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 of the License, or (at your option)
|
|
||||||
* any later version.
|
|
||||||
*
|
|
||||||
* This program 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.
|
|
||||||
*
|
|
||||||
* 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
|
|
||||||
*
|
|
||||||
* log.c: implements an abstraction between loggers interface. Implement all
|
|
||||||
* log backends in this file.
|
|
||||||
*
|
|
||||||
* Authors
|
|
||||||
* -------
|
|
||||||
* Rafael Zalamena <rzalamena@opensourcerouting.org>
|
|
||||||
*/
|
|
||||||
|
|
||||||
#include <zebra.h>
|
|
||||||
|
|
||||||
#include "bfd.h"
|
|
||||||
|
|
||||||
#include "lib/log_int.h"
|
|
||||||
|
|
||||||
void log_msg(int level, const char *fmt, va_list vl);
|
|
||||||
|
|
||||||
|
|
||||||
static int log_fg;
|
|
||||||
static int log_level = BLOG_DEBUG;
|
|
||||||
|
|
||||||
void log_init(int foreground, enum blog_level level,
|
|
||||||
struct frr_daemon_info *fdi)
|
|
||||||
{
|
|
||||||
log_fg = foreground;
|
|
||||||
log_level = level;
|
|
||||||
|
|
||||||
openzlog(fdi->progname, fdi->logname, 0,
|
|
||||||
LOG_CONS | LOG_NDELAY | LOG_PID, LOG_DAEMON);
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_msg(int level, const char *fmt, va_list vl)
|
|
||||||
{
|
|
||||||
if (level < log_level)
|
|
||||||
return;
|
|
||||||
|
|
||||||
switch (level) {
|
|
||||||
case BLOG_DEBUG:
|
|
||||||
vzlog(LOG_DEBUG, fmt, vl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BLOG_INFO:
|
|
||||||
vzlog(LOG_INFO, fmt, vl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BLOG_WARNING:
|
|
||||||
vzlog(LOG_WARNING, fmt, vl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BLOG_ERROR:
|
|
||||||
vzlog(LOG_ERR, fmt, vl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
case BLOG_FATAL:
|
|
||||||
vzlog(LOG_EMERG, fmt, vl);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
vfprintf(stderr, fmt, vl);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_info(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list vl;
|
|
||||||
|
|
||||||
va_start(vl, fmt);
|
|
||||||
log_msg(BLOG_INFO, fmt, vl);
|
|
||||||
va_end(vl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_debug(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list vl;
|
|
||||||
|
|
||||||
va_start(vl, fmt);
|
|
||||||
log_msg(BLOG_DEBUG, fmt, vl);
|
|
||||||
va_end(vl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_error(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list vl;
|
|
||||||
|
|
||||||
va_start(vl, fmt);
|
|
||||||
log_msg(BLOG_ERROR, fmt, vl);
|
|
||||||
va_end(vl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_warning(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list vl;
|
|
||||||
|
|
||||||
va_start(vl, fmt);
|
|
||||||
log_msg(BLOG_WARNING, fmt, vl);
|
|
||||||
va_end(vl);
|
|
||||||
}
|
|
||||||
|
|
||||||
void log_fatal(const char *fmt, ...)
|
|
||||||
{
|
|
||||||
va_list vl;
|
|
||||||
|
|
||||||
va_start(vl, fmt);
|
|
||||||
log_msg(BLOG_FATAL, fmt, vl);
|
|
||||||
va_end(vl);
|
|
||||||
|
|
||||||
exit(1);
|
|
||||||
}
|
|
@ -22,7 +22,6 @@ bfdd_libbfd_a_SOURCES = \
|
|||||||
bfdd/config.c \
|
bfdd/config.c \
|
||||||
bfdd/control.c \
|
bfdd/control.c \
|
||||||
bfdd/event.c \
|
bfdd/event.c \
|
||||||
bfdd/log.c \
|
|
||||||
bfdd/ptm_adapter.c \
|
bfdd/ptm_adapter.c \
|
||||||
# end
|
# end
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user