Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ospfd: zlog_ferr facility #6

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
acf7cd5
lib: add error reference system
qlyoung Jun 13, 2018
bcbb21c
lib: Allow adding arrays of ferr's
donaldsharp Jun 14, 2018
752d1b9
lib, bgpd: Add code to make lib auto create the ferr infrastructure
donaldsharp Jun 14, 2018
22de4e6
lib: Convert to zlog_ferr for zclient.c
donaldsharp Jun 14, 2018
a71dd8d
*: ALLOC calls cannot fail
donaldsharp Jun 14, 2018
b663b3c
lib: When logging commands do not use zlog_err
donaldsharp Jun 14, 2018
a827b03
lib: Add LIB_ERR_SYSTEM_CALL and convert VRF_SOCKET to SOCKET
donaldsharp Jun 14, 2018
55c636b
lib: Add LIB_ERR_VTY
donaldsharp Jun 14, 2018
faa0857
lib: Add LIB_ERR_SNMP
donaldsharp Jun 14, 2018
43afe00
bgpd, lib, zebra: Convert LIB_ERR_PRIVILEGES
donaldsharp Jun 14, 2018
8cc9a11
bgpd: implement zlog_ferr facility for enhance error messages in bgp
dslicenc Jun 15, 2018
5c77713
lib, zebra: Add LIB_ERR_INTERFACE
donaldsharp Jun 18, 2018
9d36bf3
lib: Add LIB_ERR_NS to error subsystem
donaldsharp Jun 18, 2018
d5f2c45
lib: Add LIB_ERR_DEVELOPMENT
donaldsharp Jun 18, 2018
815d5a4
lib: Remove memory check test
donaldsharp Jun 18, 2018
61b59c0
lib: Add LIB_ERR_ZMQ
donaldsharp Jun 18, 2018
e9550d0
lib: Cleanup some missed LIB_ERR_SYSTEM_CALL
donaldsharp Jun 18, 2018
546f4db
ospf6d: Update OSPFv3 to use new zlog_ferr
donaldsharp Jun 18, 2018
3527a27
ripd: Convert zlog_err to zlog_ferr for LIB_ERR_XXX
donaldsharp Jun 18, 2018
8d0f19c
ripngd: Convert over to using LIB_ERR_XXXX for zlog_ferr
donaldsharp Jun 18, 2018
128bbc2
pimd: Convert over to use LIB_ERR_XXX for zlog_err
donaldsharp Jun 18, 2018
1151a3d
lib: Update error ranges to include all daemons
donaldsharp Jun 18, 2018
a02ec79
eigrpd: Convert to use LIB_ERR_XXX for zlog_err
donaldsharp Jun 18, 2018
c3c755b
ldpd: Convert to using LIB_ERR_XXX and zlog_ferr
donaldsharp Jun 18, 2018
9014283
ospfd: Memory asserts on failure to create no need to check
donaldsharp Jun 18, 2018
e5beeb8
Merge pull request #3 from donaldsharp/more_error_stuff
qlyoung Jun 18, 2018
e00493d
Merge pull request #2 from dslicenc/bgp-error-reference
qlyoung Jun 18, 2018
607ecb0
bgpd: Cleanup initialization of bgp_errors.c
donaldsharp Jun 18, 2018
77dae04
pimd: Add pim_errors and define some pim specific errors
donaldsharp Jun 18, 2018
0bef3e0
babeld: Add BABEL_ERR_XXX error messages.
donaldsharp Jun 18, 2018
d7ef705
babeld: Use enum instead of #defines for kernel route type information
donaldsharp Jun 18, 2018
23f3240
babeld: Convert all zlog_err to zlog_ferr and add appropriate info
donaldsharp Jun 18, 2018
6b29bfa
isisd: Convert to use LIB_ERR_XXX
donaldsharp Jun 18, 2018
8578990
isisd: Add isis_errors and generate custom Error Codes
donaldsharp Jun 18, 2018
741faf9
Merge pull request #4 from donaldsharp/more_error_stuff
qlyoung Jun 19, 2018
17f5548
isisd: Cleanup compile issue
donaldsharp Jun 19, 2018
48157ee
Merge pull request #5 from donaldsharp/error-reference-cards
qlyoung Jun 19, 2018
2dd67ae
ospfd: zlog_ferr facility
chiragshah6 Jun 18, 2018
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 60 additions & 0 deletions babeld/babel_errors.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
/*
* 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 = BABEL_ERR_PACKET,
.title = "BABEL Packet Error",
.description = "Babel has detected a packet encode/decode problem",
.suggestion = "Collect relevant log files and file an Issue"
},
{
.code = BABEL_ERR_CONFIG,
.title = "BABEL Configuration Error",
.description = "Babel has detected a configuration error of some sort",
.suggestion = "Ensure that the configuration is correct"
},
{
.code = BABEL_ERR_ROUTE,
.title = "BABEL Route Error",
.description = "Babel has detected a routing error and has an inconsistent state",
.suggestion = "Gather data for filing an Issue and then restart FRR"
},
{
.code = END_FERR,
}
};

void babel_error_init(void)
{
ferr_ref_init();

ferr_ref_add(ferr_babel_err);
}
35 changes: 35 additions & 0 deletions babeld/babel_errors.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
/*
* 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,
BABEL_ERR_PACKET,
BABEL_ERR_CONFIG,
BABEL_ERR_ROUTE,
};

extern void babel_error_init(void);

#endif
32 changes: 18 additions & 14 deletions babeld/babel_interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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)

Expand Down Expand Up @@ -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);
}
Expand Down Expand Up @@ -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;
Expand All @@ -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. */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
}
Expand Down
37 changes: 24 additions & 13 deletions babeld/babel_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand All @@ -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);
Expand Down Expand Up @@ -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 */
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -228,7 +231,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;
}

Expand All @@ -248,13 +252,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);
}

Expand All @@ -273,10 +278,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;
}
Expand All @@ -287,15 +294,16 @@ 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);
if(rc == 3 && s >= 0 && s <= 0xFFFF) {
unsigned char sid[8];
rc = parse_eui64(buf2, sid);
if(rc < 0) {
zlog_err("Couldn't parse babel-state.");
zlog_ferr(BABEL_ERR_CONFIG, "Couldn't parse babel-state.");
} else {
struct timeval realnow;
debugf(BABEL_DEBUG_COMMON,
Expand All @@ -305,12 +313,13 @@ babel_load_state_file(void)
if(memcmp(sid, myid, 8) == 0)
myseqno = seqno_plus(s, 1);
else
zlog_err("ID mismatch in babel-state. id=%s; old=%s",
zlog_ferr(BABEL_ERR_CONFIG,
"ID mismatch in babel-state. id=%s; old=%s",
format_eui64(myid),
format_eui64(sid));
}
} else {
zlog_err("Couldn't parse babel-state.");
zlog_ferr(BABEL_ERR_CONFIG, "Couldn't parse babel-state.");
}
}
goto fini;
Expand Down Expand Up @@ -350,7 +359,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;
Expand All @@ -360,12 +370,13 @@ babel_save_state_file(void)
format_eui64(myid), (int)myseqno,
(long)realnow.tv_sec);
if(rc < 0 || rc >= 100) {
zlog_err("write(babel-state): overflow.");
zlog_ferr(BABEL_ERR_CONFIG, "write(babel-state): overflow.");
unlink(state_file);
} else {
rc = write(fd, buf, rc);
if(rc < 0) {
zlog_err("write(babel-state): %s", safe_strerror(errno));
zlog_ferr(BABEL_ERR_CONFIG, "write(babel-state): %s",
safe_strerror(errno));
unlink(state_file);
}
fsync(fd);
Expand Down
Loading