diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/buffer.c | 12 | ||||
-rw-r--r-- | lib/command.c | 4 | ||||
-rw-r--r-- | lib/lib_errors.c | 14 | ||||
-rw-r--r-- | lib/lib_errors.h | 3 | ||||
-rw-r--r-- | lib/log.c | 27 | ||||
-rw-r--r-- | lib/netns_linux.c | 7 | ||||
-rw-r--r-- | lib/pid_output.c | 25 | ||||
-rw-r--r-- | lib/sigevent.c | 4 | ||||
-rw-r--r-- | lib/sockopt.c | 11 | ||||
-rw-r--r-- | lib/vrf.c | 16 | ||||
-rw-r--r-- | lib/vty.c | 42 |
11 files changed, 98 insertions, 67 deletions
diff --git a/lib/buffer.c b/lib/buffer.c index b573981c1..207f2320f 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -25,6 +25,8 @@ #include "buffer.h" #include "log.h" #include "network.h" +#include "lib_errors.h" + #include <stddef.h> DEFINE_MTYPE_STATIC(LIB, BUFFER, "Buffer") @@ -341,11 +343,11 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, iov_alloc * sizeof(*iov)); } else { /* This should absolutely never occur. */ - zlog_err( - "%s: corruption detected: iov_small overflowed; " - "head %p, tail %p, head->next %p", - __func__, (void *)b->head, - (void *)b->tail, (void *)b->head->next); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: corruption detected: iov_small overflowed; " + "head %p, tail %p, head->next %p", + __func__, (void *)b->head, + (void *)b->tail, (void *)b->head->next); iov = XMALLOC(MTYPE_TMP, iov_alloc * sizeof(*iov)); memcpy(iov, small_iov, sizeof(small_iov)); diff --git a/lib/command.c b/lib/command.c index 7eda239ee..ca916c604 100644 --- a/lib/command.c +++ b/lib/command.c @@ -45,6 +45,7 @@ #include "libfrr.h" #include "jhash.h" #include "hook.h" +#include "lib_errors.h" DEFINE_MTYPE(LIB, HOST, "Host config") DEFINE_MTYPE(LIB, COMPLETION, "Completion item") @@ -2416,7 +2417,8 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) cwd[MAXPATHLEN] = '\0'; if (getcwd(cwd, MAXPATHLEN) == NULL) { - zlog_err("config_log_file: Unable to alloc mem!"); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "config_log_file: Unable to alloc mem!"); return CMD_WARNING_CONFIG_FAILED; } diff --git a/lib/lib_errors.c b/lib/lib_errors.c index c98534da0..f9bfa17b2 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -35,9 +35,9 @@ static struct ferr_ref ferr_lib_err[] = { .suggestion = "Ensure that there is sufficient memory to start processes and restart FRR", }, { - .code = LIB_ERR_VRF_SOCKET, - .title = "VRF Socket Error", - .description = "When attempting to access a socket for the VRF specified, we\nwere unable to properly complete the request", + .code = LIB_ERR_SOCKET, + .title = "Socket Error", + .description = "When attempting to access a socket a system error has occured\nand we were unable to properly complete the request", .suggestion = "Ensure that there is sufficient system resources available and\nensure that the frr user has sufficient permisions to work", }, { @@ -59,7 +59,13 @@ static struct ferr_ref ferr_lib_err[] = { .suggestion = "Restart FRR" }, { - .code = END_FERR + .code = LIB_ERR_SYSTEM_CALL, + .title = "System Call Error", + .description = "FRR has detected a error from using a vital system call and has probably\nalready exited", + .suggestion = "Ensure permissions are correct for FRR and FRR user and groups are correct\nAdditionally check that system resources are still available" + }, + { + .code = END_FERR, } }; diff --git a/lib/lib_errors.h b/lib/lib_errors.h index 409b2f749..24521a600 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -26,10 +26,11 @@ enum lib_ferr_refs { LIB_ERR_PRIVILEGES = LIB_FERR_START, LIB_ERR_VRF_START, - LIB_ERR_VRF_SOCKET, + LIB_ERR_SOCKET, LIB_ERR_ZAPI_MISSMATCH, LIB_ERR_ZAPI_ENCODE, LIB_ERR_ZAPI_SOCKET, + LIB_ERR_SYSTEM_CALL, }; extern void lib_error_init(void); @@ -28,6 +28,8 @@ #include "log_int.h" #include "memory.h" #include "command.h" +#include "lib_errors.h" + #ifndef SUNOS_5 #include <sys/un.h> #endif @@ -631,15 +633,16 @@ void zlog_backtrace(int priority) size = backtrace(array, array_size(array)); if (size <= 0 || (size_t)size > array_size(array)) { - zlog_err( - "Cannot get backtrace, returned invalid # of frames %d " - "(valid range is between 1 and %lu)", - size, (unsigned long)(array_size(array))); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Cannot get backtrace, returned invalid # of frames %d " + "(valid range is between 1 and %lu)", + size, (unsigned long)(array_size(array))); return; } zlog(priority, "Backtrace for %d stack frames:", size); if (!(strings = backtrace_symbols(array, size))) { - zlog_err("Cannot get backtrace symbols (out of memory?)"); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Cannot get backtrace symbols (out of memory?)"); for (i = 0; i < size; i++) zlog(priority, "[bt %d] %p", i, array[i]); } else { @@ -712,10 +715,10 @@ void _zlog_assert_failed(const char *assertion, const char *file, void memory_oom(size_t size, const char *name) { - zlog_err( - "out of memory: failed to allocate %zu bytes for %s" - "object", - size, name); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "out of memory: failed to allocate %zu bytes for %s" + "object", + size, name); zlog_backtrace(LOG_ERR); abort(); } @@ -864,9 +867,9 @@ int zlog_rotate(void) save_errno = errno; umask(oldumask); if (zl->fp == NULL) { - zlog_err( - "Log rotate failed: cannot open file %s for append: %s", - zl->filename, safe_strerror(save_errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Log rotate failed: cannot open file %s for append: %s", + zl->filename, safe_strerror(save_errno)); ret = -1; } else { logfile_fd = fileno(zl->fp); diff --git a/lib/netns_linux.c b/lib/netns_linux.c index a80b51fa0..801264d1a 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -35,10 +35,10 @@ #include "ns.h" #include "log.h" #include "memory.h" - #include "command.h" #include "vty.h" #include "vrf.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, NS, "NetNS Context") DEFINE_MTYPE_STATIC(LIB, NS_NAME, "NetNS Name") @@ -219,8 +219,9 @@ static int ns_enable_internal(struct ns *ns, void (*func)(ns_id_t, void *)) } if (!ns_is_enabled(ns)) { - zlog_err("Can not enable NS %u: %s!", ns->ns_id, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Can not enable NS %u: %s!", ns->ns_id, + safe_strerror(errno)); return 0; } diff --git a/lib/pid_output.c b/lib/pid_output.c index 023a166f2..21687e48c 100644 --- a/lib/pid_output.c +++ b/lib/pid_output.c @@ -24,6 +24,7 @@ #include <log.h> #include "version.h" #include "network.h" +#include "lib_errors.h" #define PIDFILE_MASK 0644 @@ -41,8 +42,9 @@ pid_t pid_output(const char *path) oldumask = umask(0777 & ~PIDFILE_MASK); fd = open(path, O_RDWR | O_CREAT, PIDFILE_MASK); if (fd < 0) { - zlog_err("Can't create pid lock file %s (%s), exiting", path, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Can't create pid lock file %s (%s), exiting", path, + safe_strerror(errno)); umask(oldumask); exit(1); } else { @@ -57,22 +59,23 @@ pid_t pid_output(const char *path) lock.l_whence = SEEK_SET; if (fcntl(fd, F_SETLK, &lock) < 0) { - zlog_err("Could not lock pid_file %s (%s), exiting", - path, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Could not lock pid_file %s (%s), exiting", + path, safe_strerror(errno)); exit(1); } sprintf(buf, "%d\n", (int)pid); pidsize = strlen(buf); if ((tmp = write(fd, buf, pidsize)) != (int)pidsize) - zlog_err( - "Could not write pid %d to pid_file %s, rc was %d: %s", - (int)pid, path, tmp, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Could not write pid %d to pid_file %s, rc was %d: %s", + (int)pid, path, tmp, safe_strerror(errno)); else if (ftruncate(fd, pidsize) < 0) - zlog_err( - "Could not truncate pid_file %s to %u bytes: %s", - path, (unsigned int)pidsize, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Could not truncate pid_file %s to %u bytes: %s", + path, (unsigned int)pidsize, + safe_strerror(errno)); } return pid; } diff --git a/lib/sigevent.c b/lib/sigevent.c index 59eaa8037..c6a8fcbd1 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -22,6 +22,7 @@ #include <sigevent.h> #include <log.h> #include <memory.h> +#include <lib_errors.h> #ifdef SA_SIGINFO #ifdef HAVE_UCONTEXT_H @@ -83,7 +84,8 @@ int quagga_sigevent_process(void) sigdelset(&newmask, SIGKILL); if ((sigprocmask(SIG_BLOCK, &newmask, &oldmask)) < 0) { - zlog_err("quagga_signal_timer: couldnt block signals!"); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "quagga_signal_timer: couldnt block signals!"); return -1; } #endif /* SIGEVENT_BLOCK_SIGNALS */ diff --git a/lib/sockopt.c b/lib/sockopt.c index e979bef17..1e45f20aa 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -27,6 +27,7 @@ #include "log.h" #include "sockopt.h" #include "sockunion.h" +#include "lib_errors.h" void setsockopt_so_recvbuf(int sock, int size) { @@ -61,8 +62,9 @@ int getsockopt_so_sendbuf(const int sock) int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&optval, &optlen); if (ret < 0) { - zlog_err("fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock, - errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock, + errno, safe_strerror(errno)); return ret; } return optval; @@ -670,8 +672,9 @@ int sockopt_tcp_signature(int sock, union sockunion *su, const char *password) if (ENOENT == errno) ret = 0; else - zlog_err("sockopt_tcp_signature: setsockopt(%d): %s", - sock, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "sockopt_tcp_signature: setsockopt(%d): %s", + sock, safe_strerror(errno)); } return ret; #else /* HAVE_TCP_MD5SIG */ @@ -545,7 +545,7 @@ int vrf_socket(int domain, int type, int protocol, vrf_id_t vrf_id, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); @@ -560,7 +560,7 @@ int vrf_socket(int domain, int type, int protocol, vrf_id_t vrf_id, save_errno = errno; ret2 = vrf_switchback_to_initial(); if (ret2 < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = save_errno; @@ -914,14 +914,14 @@ int vrf_getaddrinfo(const char *node, const char *service, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); ret = getaddrinfo(node, service, hints, res); save_errno = errno; ret2 = vrf_switchback_to_initial(); if (ret2 < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = save_errno; @@ -934,7 +934,7 @@ int vrf_ioctl(vrf_id_t vrf_id, int d, unsigned long request, char *params) ret = vrf_switch_to_netns(vrf_id); if (ret < 0) { - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); return 0; @@ -943,7 +943,7 @@ int vrf_ioctl(vrf_id_t vrf_id, int d, unsigned long request, char *params) saved_errno = errno; ret = vrf_switchback_to_initial(); if (ret < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = saved_errno; @@ -957,14 +957,14 @@ int vrf_sockunion_socket(const union sockunion *su, vrf_id_t vrf_id, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); ret = sockunion_socket(su); save_errno = errno; ret2 = vrf_switchback_to_initial(); if (ret2 < 0) - zlog_ferr(LIB_ERR_VRF_SOCKET, + zlog_ferr(LIB_ERR_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = save_errno; @@ -1972,7 +1972,8 @@ static void vty_serv_sock_addrinfo(const char *hostname, unsigned short port) ret = getaddrinfo(hostname, port_str, &req, &ainfo); if (ret != 0) { - zlog_err("getaddrinfo failed: %s", gai_strerror(ret)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "getaddrinfo failed: %s", gai_strerror(ret)); exit(1); } @@ -2032,7 +2033,8 @@ static void vty_serv_un(const char *path) /* Make UNIX domain socket. */ sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { - zlog_err("Cannot create unix stream socket: %s", + zlog_ferr(LIB_ERR_SOCKET, + "Cannot create unix stream socket: %s", safe_strerror(errno)); return; } @@ -2051,15 +2053,18 @@ static void vty_serv_un(const char *path) ret = bind(sock, (struct sockaddr *)&serv, len); if (ret < 0) { - zlog_err("Cannot bind path %s: %s", path, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "Cannot bind path %s: %s", + path, safe_strerror(errno)); close(sock); /* Avoid sd leak. */ return; } ret = listen(sock, 5); if (ret < 0) { - zlog_err("listen(fd %d) failed: %s", sock, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "listen(fd %d) failed: %s", sock, + safe_strerror(errno)); close(sock); /* Avoid sd leak. */ return; } @@ -2074,8 +2079,9 @@ static void vty_serv_un(const char *path) if ((int)ids.gid_vty > 0) { /* set group of socket */ if (chown(path, -1, ids.gid_vty)) { - zlog_err("vty_serv_un: could chown socket, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "vty_serv_un: could chown socket, %s", + safe_strerror(errno)); } } @@ -2480,9 +2486,9 @@ bool vty_read_config(const char *config_file, char *config_default_dir) if (config_file != NULL) { if (!IS_DIRECTORY_SEP(config_file[0])) { if (getcwd(cwd, MAXPATHLEN) == NULL) { - zlog_err( - "Failure to determine Current Working Directory %d!", - errno); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Failure to determine Current Working Directory %d!", + errno); exit(1); } tmp = XMALLOC(MTYPE_TMP, @@ -2495,7 +2501,7 @@ bool vty_read_config(const char *config_file, char *config_default_dir) confp = fopen(fullpath, "r"); if (confp == NULL) { - zlog_err("%s: failed to open configuration file %s: %s", + zlog_warn("%s: failed to open configuration file %s: %s, checking backup", __func__, fullpath, safe_strerror(errno)); confp = vty_use_backup_config(fullpath); @@ -2540,9 +2546,9 @@ bool vty_read_config(const char *config_file, char *config_default_dir) #endif /* VTYSH */ confp = fopen(config_default_dir, "r"); if (confp == NULL) { - zlog_err("%s: failed to open configuration file %s: %s", - __func__, config_default_dir, - safe_strerror(errno)); + zlog_warn("%s: failed to open configuration file %s: %s, checking backup", + __func__, config_default_dir, + safe_strerror(errno)); confp = vty_use_backup_config(config_default_dir); if (confp) { @@ -3064,12 +3070,14 @@ static void vty_save_cwd(void) * Hence not worrying about it too much. */ if (!chdir(SYSCONFDIR)) { - zlog_err("Failure to chdir to %s, errno: %d", - SYSCONFDIR, errno); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Failure to chdir to %s, errno: %d", + SYSCONFDIR, errno); exit(-1); } if (getcwd(cwd, MAXPATHLEN) == NULL) { - zlog_err("Failure to getcwd, errno: %d", errno); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "Failure to getcwd, errno: %d", errno); exit(-1); } } |