summaryrefslogtreecommitdiffstats
path: root/babeld
diff options
context:
space:
mode:
authorDonald Sharp <sharpd@cumulusnetworks.com>2018-06-18 19:38:21 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-08-14 22:02:05 +0200
commitf135ba5272cfd892c1dfc88cf595a25da7c49fd9 (patch)
tree8018ebc1053defccb2bc31fbcc9968778fbb7269 /babeld
parentpimd: Add pim_errors and define some pim specific errors (diff)
downloadfrr-f135ba5272cfd892c1dfc88cf595a25da7c49fd9.tar.xz
frr-f135ba5272cfd892c1dfc88cf595a25da7c49fd9.zip
babeld: Add BABEL_ERR_XXX error messages.
Add some BABEL_ERR_XXX error messages and convert over to using zlog_ferr instead of zlog_err. Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
Diffstat (limited to 'babeld')
-rw-r--r--babeld/babel_errors.c42
-rw-r--r--babeld/babel_errors.h32
-rw-r--r--babeld/babel_interface.c32
-rw-r--r--babeld/babel_main.c25
-rw-r--r--babeld/babeld.c13
-rw-r--r--babeld/subdir.am2
6 files changed, 120 insertions, 26 deletions
diff --git a/babeld/babel_errors.c b/babeld/babel_errors.c
new file mode 100644
index 000000000..e83b81d8b
--- /dev/null
+++ b/babeld/babel_errors.c
@@ -0,0 +1,42 @@
+/*
+ * babel_errors - code for error messages that may occur in the
+ * babel process
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * FRR 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.
+ *
+ * FRR 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
+ */
+#include <zebra.h>
+
+#include "babel_errors.h"
+
+static struct ferr_ref ferr_babel_err[] = {
+ {
+ .code = BABEL_ERR_MEMORY,
+ .title = "BABEL Memory Errors",
+ .description = "Babel has failed to allocate memory, the system is about to run out of memory",
+ .suggestion = "Find the process that is causing memory shortages and remediate that process\nRestart FRR"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+
+void babel_error_init(void)
+{
+ ferr_ref_init();
+
+ ferr_ref_add(ferr_babel_err);
+}
diff --git a/babeld/babel_errors.h b/babeld/babel_errors.h
new file mode 100644
index 000000000..07a7863b0
--- /dev/null
+++ b/babeld/babel_errors.h
@@ -0,0 +1,32 @@
+/*
+ * babel_errors - header for error messages that may occur in the babel process
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * FRR 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.
+ *
+ * FRR 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
+ */
+#ifndef __BABEL_ERRORS_H__
+#define __BABEL_ERRORS_H__
+
+#include "ferr.h"
+#include "babel_errors.h"
+
+enum babel_ferr_refs {
+ BABEL_ERR_MEMORY = BABEL_FERR_START,
+};
+
+extern void babel_error_init(void);
+
+#endif
diff --git a/babeld/babel_interface.c b/babeld/babel_interface.c
index 453fd8e04..dc47ff002 100644
--- a/babeld/babel_interface.c
+++ b/babeld/babel_interface.c
@@ -27,6 +27,7 @@ THE SOFTWARE.
#include "prefix.h"
#include "vector.h"
#include "distribute.h"
+#include "lib_errors.h"
#include "babel_main.h"
#include "util.h"
@@ -39,6 +40,7 @@ THE SOFTWARE.
#include "route.h"
#include "xroute.h"
#include "babel_memory.h"
+#include "babel_errors.h"
#define IS_ENABLE(ifp) (babel_enable_if_lookup(ifp->name) >= 0)
@@ -167,7 +169,7 @@ babel_interface_address_add (int cmd, struct zclient *client,
if (babel_ifp->ipv4 == NULL) {
babel_ifp->ipv4 = malloc(4);
if (babel_ifp->ipv4 == NULL) {
- zlog_err("not einough memory");
+ zlog_ferr(BABEL_ERR_MEMORY, "not enough memory");
} else {
memcpy(babel_ifp->ipv4, &prefix->u.prefix4, 4);
}
@@ -707,7 +709,7 @@ interface_recalculate(struct interface *ifp)
tmp = babel_ifp->sendbuf;
babel_ifp->sendbuf = realloc(babel_ifp->sendbuf, babel_ifp->bufsize);
if(babel_ifp->sendbuf == NULL) {
- zlog_err("Couldn't reallocate sendbuf.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't reallocate sendbuf.");
free(tmp);
babel_ifp->bufsize = 0;
return -1;
@@ -727,8 +729,9 @@ interface_recalculate(struct interface *ifp)
rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
(char*)&mreq, sizeof(mreq));
if(rc < 0) {
- zlog_err("setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
- ifp->name, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SOCKET,
+ "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
+ ifp->name, safe_strerror(errno));
/* This is probably due to a missing link-local address,
so down this interface, and wait until the main loop
tries to up it again. */
@@ -790,8 +793,9 @@ interface_reset(struct interface *ifp)
rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
(char*)&mreq, sizeof(mreq));
if(rc < 0)
- zlog_err("setsockopt(IPV6_LEAVE_GROUP) on interface '%s': %s",
- ifp->name, safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SOCKET,
+ "setsockopt(IPV6_LEAVE_GROUP) on interface '%s': %s",
+ ifp->name, safe_strerror(errno));
}
update_interface_metric(ifp);
@@ -1056,7 +1060,7 @@ DEFUN (show_babel_route,
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
@@ -1068,7 +1072,7 @@ DEFUN (show_babel_route,
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
@@ -1103,7 +1107,7 @@ DEFUN (show_babel_route_prefix,
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
@@ -1115,7 +1119,7 @@ DEFUN (show_babel_route_prefix,
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
@@ -1161,7 +1165,7 @@ DEFUN (show_babel_route_addr,
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
@@ -1173,7 +1177,7 @@ DEFUN (show_babel_route_addr,
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
@@ -1220,7 +1224,7 @@ DEFUN (show_babel_route_addr6,
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
@@ -1232,7 +1236,7 @@ DEFUN (show_babel_route_addr6,
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ zlog_ferr(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
diff --git a/babeld/babel_main.c b/babeld/babel_main.c
index 2b87bed0f..2a40b4f89 100644
--- a/babeld/babel_main.c
+++ b/babeld/babel_main.c
@@ -33,6 +33,7 @@ THE SOFTWARE.
#include "vty.h"
#include "memory.h"
#include "libfrr.h"
+#include "lib_errors.h"
#include "babel_main.h"
#include "babeld.h"
@@ -45,6 +46,7 @@ THE SOFTWARE.
#include "message.h"
#include "resend.h"
#include "babel_zebra.h"
+#include "babel_errors.h"
static void babel_fail(void);
static void babel_init_random(void);
@@ -151,7 +153,7 @@ main(int argc, char **argv)
frr_preinit (&babeld_di, argc, argv);
frr_opt_add ("", longopts, "");
-
+
babel_init_random();
/* set the Babel's default link-local multicast address and Babel's port */
@@ -181,6 +183,7 @@ main(int argc, char **argv)
master = frr_init ();
/* Library inits. */
+ babel_error_init();
zprivs_init (&babeld_privs);
cmd_init (1);
vty_init (master);
@@ -225,7 +228,8 @@ babel_init_random(void)
rc = read_random_bytes(&seed, sizeof(seed));
if(rc < 0) {
- zlog_err("read(random): %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "read(random): %s",
+ safe_strerror(errno));
seed = 42;
}
@@ -245,13 +249,14 @@ babel_replace_by_null(int fd)
fd_null = open("/dev/null", O_RDONLY);
if(fd_null < 0) {
- zlog_err("open(null): %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "open(null): %s", safe_strerror(errno));
exit(1);
}
rc = dup2(fd_null, fd);
if(rc < 0) {
- zlog_err("dup2(null, 0): %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "dup2(null, 0): %s",
+ safe_strerror(errno));
exit(1);
}
@@ -270,10 +275,12 @@ babel_load_state_file(void)
fd = open(state_file, O_RDONLY);
if(fd < 0 && errno != ENOENT)
- zlog_err("open(babel-state: %s)", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "open(babel-state: %s)",
+ safe_strerror(errno));
rc = unlink(state_file);
if(fd >= 0 && rc < 0) {
- zlog_err("unlink(babel-state): %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "unlink(babel-state): %s",
+ safe_strerror(errno));
/* If we couldn't unlink it, it's probably stale. */
goto fini;
}
@@ -284,7 +291,8 @@ babel_load_state_file(void)
long t;
rc = read(fd, buf, 99);
if(rc < 0) {
- zlog_err("read(babel-state): %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "read(babel-state): %s",
+ safe_strerror(errno));
} else {
buf[rc] = '\0';
rc = sscanf(buf, "%99s %d %ld\n", buf2, &s, &t);
@@ -347,7 +355,8 @@ babel_save_state_file(void)
debugf(BABEL_DEBUG_COMMON, "Save state file.");
fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if(fd < 0) {
- zlog_err("creat(babel-state): %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SYSTEM_CALL, "creat(babel-state): %s",
+ safe_strerror(errno));
unlink(state_file);
} else {
struct timeval realnow;
diff --git a/babeld/babeld.c b/babeld/babeld.c
index 20dd098f3..91f54bfc8 100644
--- a/babeld/babeld.c
+++ b/babeld/babeld.c
@@ -29,6 +29,7 @@ THE SOFTWARE.
#include "prefix.h"
#include "filter.h"
#include "plist.h"
+#include "lib_errors.h"
#include "babel_main.h"
#include "babeld.h"
@@ -43,6 +44,7 @@ THE SOFTWARE.
#include "babel_filter.h"
#include "babel_zebra.h"
#include "babel_memory.h"
+#include "babel_errors.h"
static int babel_init_routing_process(struct thread *thread);
static void babel_get_myid(void);
@@ -143,7 +145,8 @@ babel_create_routing_process (void)
/* Make socket for Babel protocol. */
protocol_socket = babel_socket(protocol_port);
if (protocol_socket < 0) {
- zlog_err("Couldn't create link local socket: %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SOCKET, "Couldn't create link local socket: %s",
+ safe_strerror(errno));
goto fail;
}
@@ -176,7 +179,7 @@ babel_read_protocol (struct thread *thread)
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0) {
if(errno != EAGAIN && errno != EINTR) {
- zlog_err("recv: %s", safe_strerror(errno));
+ zlog_ferr(LIB_ERR_SOCKET, "recv: %s", safe_strerror(errno));
}
} else {
FOR_ALL_INTERFACES(vrf, ifp) {
@@ -514,7 +517,8 @@ resize_receive_buffer(int size)
if(receive_buffer == NULL) {
receive_buffer = malloc(size);
if(receive_buffer == NULL) {
- zlog_err("malloc(receive_buffer): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_MEMORY, "malloc(receive_buffer): %s",
+ safe_strerror(errno));
return -1;
}
receive_buffer_size = size;
@@ -522,7 +526,8 @@ resize_receive_buffer(int size)
unsigned char *new;
new = realloc(receive_buffer, size);
if(new == NULL) {
- zlog_err("realloc(receive_buffer): %s", safe_strerror(errno));
+ zlog_ferr(BABEL_ERR_MEMORY, "realloc(receive_buffer): %s",
+ safe_strerror(errno));
return -1;
}
receive_buffer = new;
diff --git a/babeld/subdir.am b/babeld/subdir.am
index c44cb275c..6f91f7393 100644
--- a/babeld/subdir.am
+++ b/babeld/subdir.am
@@ -9,6 +9,7 @@ dist_examples_DATA += babeld/babeld.conf.sample
endif
babeld_libbabel_a_SOURCES = \
+ babeld/babel_errors.c \
babeld/babel_filter.c \
babeld/babel_interface.c \
babeld/babel_memory.c \
@@ -26,6 +27,7 @@ babeld_libbabel_a_SOURCES = \
# end
noinst_HEADERS += \
+ babeld/babel_errors.h \
babeld/babel_filter.h \
babeld/babel_interface.h \
babeld/babel_main.h \