]> git.proxmox.com Git - mirror_frr.git/commitdiff
lib: Add LIB_ERR_SYSTEM_CALL and convert VRF_SOCKET to SOCKET
authorDonald Sharp <sharpd@cumulusnetworks.com>
Thu, 14 Jun 2018 13:13:18 +0000 (09:13 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 14 Aug 2018 20:02:05 +0000 (20:02 +0000)
Add a new error code LIB_ERR_SYSTEM_CALL to the ferr subsystem.
Additionally convert LIB_ERR_VRF_SOCKET to a more generic
LIB_ERR_SOCKET.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
lib/buffer.c
lib/command.c
lib/lib_errors.c
lib/lib_errors.h
lib/log.c
lib/netns_linux.c
lib/pid_output.c
lib/sigevent.c
lib/sockopt.c
lib/vrf.c
lib/vty.c

index b573981c1b686d4bc692fe5b1768923abdf221e3..207f2320ff58558e946527d87b7acc34dae2c82b 100644 (file)
@@ -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));
index 7eda239ee4a19b08db0c366a19513b4ea75d3f47..ca916c6043364391cb70c6259401f100cb00edc3 100644 (file)
@@ -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;
                }
 
index c98534da034c7e40d3b02105a15a9587d6517768..f9bfa17b2eed1254b5aa0cbb0ab32b55e1e84d05 100644 (file)
@@ -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,
        }
 };
 
index 409b2f749c1332d8a5957fab5219a6afaba4196a..24521a6008c09c504dcf0fdeb51dabbed4af3d58 100644 (file)
 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);
index 1345ff2fd1868718b343675a57f54fb913f6fef1..afecbef19cd69624046824637a39f21958f125ea 100644 (file)
--- a/lib/log.c
+++ b/lib/log.c
@@ -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);
index a80b51fa007be00861dd032926ddb08b2e87034f..801264d1a86c6cca67488c49b500904ad9aa12d9 100644 (file)
 #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;
                }
 
index 023a166f27d37ca9a11940e2a037963d161bed9e..21687e48c4b2c8df56546c807cda4bf0853d739d 100644 (file)
@@ -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;
 }
index 59eaa8037075a754073cd40433c26fa3e9830fc6..c6a8fcbd1215c0f20bf7ea58fab07bb33d886ccc 100644 (file)
@@ -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 */
index e979bef17401159ffaaa09277ad4d06c329410f9..1e45f20aad6e91d78ebd0e3e8f956fb4765f436b 100644 (file)
@@ -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 */
index ca0bbe1db0d72939e82ef60c782bb47a20f9138b..17d389e6dfb5d0db6dd4f3351d6f248c30faa250 100644 (file)
--- a/lib/vrf.c
+++ b/lib/vrf.c
@@ -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;
index 9beb25442030473835cd10151d95631fb900c3c3..0b431a5c7f22a841ac7ecd641fc2c5ffe89ef4b3 100644 (file)
--- a/lib/vty.c
+++ b/lib/vty.c
@@ -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);
                }
        }