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

Error reference cards #1

15 changes: 5 additions & 10 deletions bgpd/bgp_aspath.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,16 +214,11 @@ static struct assegment *assegment_append_asns(struct assegment *seg,
newas = XREALLOC(MTYPE_AS_SEG_DATA, seg->as,
ASSEGMENT_DATA_SIZE(seg->length + num, 1));

if (newas) {
seg->as = newas;
memcpy(seg->as + seg->length, asnos,
ASSEGMENT_DATA_SIZE(num, 1));
seg->length += num;
return seg;
}

assegment_free_all(seg);
return NULL;
seg->as = newas;
memcpy(seg->as + seg->length, asnos,
ASSEGMENT_DATA_SIZE(num, 1));
seg->length += num;
return seg;
}

static int int_cmp(const void *p1, const void *p2)
Expand Down
4 changes: 0 additions & 4 deletions bgpd/bgp_labelpool.c
Original file line number Diff line number Diff line change
Expand Up @@ -202,10 +202,6 @@ void bgp_lp_init(struct thread_master *master, struct labelpool *pool)
lp->requests = XCALLOC(MTYPE_BGP_LABEL_FIFO, sizeof(struct lp_fifo));
LABEL_FIFO_INIT(lp->requests);
lp->callback_q = work_queue_new(master, "label callbacks");
if (!lp->callback_q) {
zlog_err("%s: Failed to allocate work queue", __func__);
exit(1);
}

lp->callback_q->spec.workfunc = lp_cbq_docallback;
lp->callback_q->spec.del_item_data = lp_cbq_item_free;
Expand Down
27 changes: 27 additions & 0 deletions bgpd/bgp_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
#include "bfd.h"
#include "libfrr.h"
#include "ns.h"
#include "ferr.h"

#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"
Expand Down Expand Up @@ -85,6 +86,27 @@ void sigusr1(void);
static void bgp_exit(int);
static void bgp_vrf_terminate(void);

enum bgp_ferr_refs {
BGP_ERR_START = BGP_FERR_START,
BGP_EXAMPLE_ERR,
BGP_ERR_END = BGP_FERR_END,
};

static struct ferr_ref example_err[] = {
{
.code = BGP_EXAMPLE_ERR,
.title = "Example Error",
.description = "An example error made to be used as an example of the error reference system.",
.suggestion = "Ignore this error."
},
{
.code = END_FERR,
.title = "End of Errors",
.description = "This should not show up",
.suggestion = "Ignore this error."
},
};

static struct quagga_signal_t bgp_signals[] = {
{
.signal = SIGHUP,
Expand Down Expand Up @@ -416,6 +438,11 @@ int main(int argc, char **argv)
/* BGP related initialization. */
bgp_init();

ferr_ref_add(example_err);

zlog_ferr(BGP_EXAMPLE_ERR, "additional information %d", 42);


snprintf(bgpd_di.startinfo, sizeof(bgpd_di.startinfo), ", bgp@%s:%d",
(bm->address ? bm->address : "<all>"), bm->port);

Expand Down
13 changes: 7 additions & 6 deletions bgpd/bgp_network.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "hash.h"
#include "filter.h"
#include "ns.h"
#include "lib_errors.h"

#include "bgpd/bgpd.h"
#include "bgpd/bgp_open.h"
Expand Down Expand Up @@ -544,12 +545,12 @@ int bgp_connect(struct peer *peer)
return 0;
}
if (bgpd_privs.change(ZPRIVS_RAISE))
zlog_err("Can't raise privileges");
zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges");
/* Make socket for the peer. */
peer->fd = vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id,
bgp_get_bound_name(peer));
if (bgpd_privs.change(ZPRIVS_LOWER))
zlog_err("Can't lower privileges");
zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges");
if (peer->fd < 0)
return -1;

Expand Down Expand Up @@ -703,11 +704,11 @@ int bgp_socket(struct bgp *bgp, unsigned short port, const char *address)
port_str[sizeof(port_str) - 1] = '\0';

if (bgpd_privs.change(ZPRIVS_RAISE))
zlog_err("Can't raise privileges");
zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges");
ret = vrf_getaddrinfo(address, port_str, &req, &ainfo_save,
bgp->vrf_id);
if (bgpd_privs.change(ZPRIVS_LOWER))
zlog_err("Can't lower privileges");
zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges");
if (ret != 0) {
zlog_err("getaddrinfo: %s", gai_strerror(ret));
return -1;
Expand All @@ -721,13 +722,13 @@ int bgp_socket(struct bgp *bgp, unsigned short port, const char *address)
continue;

if (bgpd_privs.change(ZPRIVS_RAISE))
zlog_err("Can't raise privileges");
zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges");
sock = vrf_socket(ainfo->ai_family, ainfo->ai_socktype,
ainfo->ai_protocol, bgp->vrf_id,
(bgp->inst_type == BGP_INSTANCE_TYPE_VRF ?
bgp->name : NULL));
if (bgpd_privs.change(ZPRIVS_LOWER))
zlog_err("Can't lower privileges");
zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges");
if (sock < 0) {
zlog_err("socket: %s", safe_strerror(errno));
continue;
Expand Down
14 changes: 2 additions & 12 deletions bgpd/bgp_route.c
Original file line number Diff line number Diff line change
Expand Up @@ -2455,16 +2455,10 @@ static void bgp_processq_del(struct work_queue *wq, void *data)

void bgp_process_queue_init(void)
{
if (!bm->process_main_queue) {
if (!bm->process_main_queue)
bm->process_main_queue =
work_queue_new(bm->master, "process_main_queue");

if (!bm->process_main_queue) {
zlog_err("%s: Failed to allocate work queue", __func__);
exit(1);
}
}

bm->process_main_queue->spec.workfunc = &bgp_process_wq;
bm->process_main_queue->spec.del_item_data = &bgp_processq_del;
bm->process_main_queue->spec.max_retries = 0;
Expand Down Expand Up @@ -3836,11 +3830,7 @@ static void bgp_clear_node_queue_init(struct peer *peer)
snprintf(wname, sizeof(wname), "clear %s", peer->host);
#undef CLEAR_QUEUE_NAME_LEN

if ((peer->clear_node_queue = work_queue_new(bm->master, wname))
== NULL) {
zlog_err("%s: Failed to allocate work queue", __func__);
exit(1);
}
peer->clear_node_queue = work_queue_new(bm->master, wname);
peer->clear_node_queue->spec.hold = 10;
peer->clear_node_queue->spec.workfunc = &bgp_clear_route_node;
peer->clear_node_queue->spec.del_item_data = &bgp_clear_node_queue_del;
Expand Down
41 changes: 20 additions & 21 deletions isisd/dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -244,19 +244,18 @@ dict_t *dict_create(dictcount_t maxcount, dict_comp_t comp)
{
dict_t *new = XCALLOC(MTYPE_ISIS_DICT, sizeof(dict_t));

if (new) {
new->compare = comp;
new->allocnode = dnode_alloc;
new->freenode = dnode_free;
new->context = NULL;
new->nodecount = 0;
new->maxcount = maxcount;
new->nilnode.left = &new->nilnode;
new->nilnode.right = &new->nilnode;
new->nilnode.parent = &new->nilnode;
new->nilnode.color = dnode_black;
new->dupes = 0;
}
new->compare = comp;
new->allocnode = dnode_alloc;
new->freenode = dnode_free;
new->context = NULL;
new->nodecount = 0;
new->maxcount = maxcount;
new->nilnode.left = &new->nilnode;
new->nilnode.right = &new->nilnode;
new->nilnode.parent = &new->nilnode;
new->nilnode.color = dnode_black;
new->dupes = 0;

return new;
}

Expand Down Expand Up @@ -974,12 +973,12 @@ static void dnode_free(dnode_t *node, void *context)
dnode_t *dnode_create(void *data)
{
dnode_t *new = XCALLOC(MTYPE_ISIS_DICT_NODE, sizeof(dnode_t));
if (new) {
new->data = data;
new->parent = NULL;
new->left = NULL;
new->right = NULL;
}

new->data = data;
new->parent = NULL;
new->left = NULL;
new->right = NULL;

return new;
}

Expand Down Expand Up @@ -1250,8 +1249,8 @@ static char *dupstring(char *str)
{
int sz = strlen(str) + 1;
char *new = XCALLOC(MTYPE_ISIS_TMP, sz);
if (new)
memcpy(new, str, sz);

memcpy(new, str, sz);
return new;
}

Expand Down
4 changes: 0 additions & 4 deletions isisd/isis_circuit.c
Original file line number Diff line number Diff line change
Expand Up @@ -73,10 +73,6 @@ struct isis_circuit *isis_circuit_new()
int i;

circuit = XCALLOC(MTYPE_ISIS_CIRCUIT, sizeof(struct isis_circuit));
if (circuit == NULL) {
zlog_err("Can't malloc isis circuit");
return NULL;
}

/*
* Default values
Expand Down
4 changes: 0 additions & 4 deletions isisd/isis_spf.c
Original file line number Diff line number Diff line change
Expand Up @@ -466,10 +466,6 @@ struct isis_spftree *isis_spftree_new(struct isis_area *area)
struct isis_spftree *tree;

tree = XCALLOC(MTYPE_ISIS_SPFTREE, sizeof(struct isis_spftree));
if (tree == NULL) {
zlog_err("ISIS-Spf: isis_spftree_new Out of memory!");
return NULL;
}

isis_vertex_queue_init(&tree->tents, "IS-IS SPF tents", true);
isis_vertex_queue_init(&tree->paths, "IS-IS SPF paths", false);
Expand Down
3 changes: 0 additions & 3 deletions isisd/isis_te.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,9 +87,6 @@ struct mpls_te_circuit *mpls_te_circuit_new()

mtc = XCALLOC(MTYPE_ISIS_MPLS_TE, sizeof(struct mpls_te_circuit));

if (mtc == NULL)
return NULL;

mtc->status = disable;
mtc->type = STD_TE;
mtc->length = 0;
Expand Down
13 changes: 9 additions & 4 deletions lib/agentx.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include "memory.h"
#include "linklist.h"
#include "version.h"
#include "lib_errors.h"

static int agentx_enabled = 0;

Expand Down Expand Up @@ -141,16 +142,20 @@ static int agentx_log_callback(int major, int minor, void *serverarg,
msg[strlen(msg) - 1] = '\0';
switch (slm->priority) {
case LOG_EMERG:
zlog_err("snmp[emerg]: %s", msg ? msg : slm->msg);
zlog_ferr(LIB_ERR_SNMP,
"snmp[emerg]: %s", msg ? msg : slm->msg);
break;
case LOG_ALERT:
zlog_err("snmp[alert]: %s", msg ? msg : slm->msg);
zlog_ferr(LIB_ERR_SNMP,
"snmp[alert]: %s", msg ? msg : slm->msg);
break;
case LOG_CRIT:
zlog_err("snmp[crit]: %s", msg ? msg : slm->msg);
zlog_ferr(LIB_ERR_SNMP,
"snmp[crit]: %s", msg ? msg : slm->msg);
break;
case LOG_ERR:
zlog_err("snmp[err]: %s", msg ? msg : slm->msg);
zlog_ferr(LIB_ERR_SNMP,
"snmp[err]: %s", msg ? msg : slm->msg);
break;
case LOG_WARNING:
zlog_warn("snmp[warning]: %s", msg ? msg : slm->msg);
Expand Down
12 changes: 7 additions & 5 deletions lib/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -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));
Expand Down
10 changes: 4 additions & 6 deletions lib/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down Expand Up @@ -2409,15 +2410,12 @@ 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;
}

if ((p = XMALLOC(MTYPE_TMP, strlen(cwd) + strlen(fname) + 2))
== NULL) {
zlog_err("config_log_file: Unable to alloc mem!");
return CMD_WARNING_CONFIG_FAILED;
}
p = XMALLOC(MTYPE_TMP, strlen(cwd) + strlen(fname) + 2);
sprintf(p, "%s/%s", cwd, fname);
fullpath = p;
} else
Expand Down
Loading