diff --git a/bgpd/bgp_aspath.c b/bgpd/bgp_aspath.c index e02617691fa7..78c5bd521972 100644 --- a/bgpd/bgp_aspath.c +++ b/bgpd/bgp_aspath.c @@ -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) diff --git a/bgpd/bgp_labelpool.c b/bgpd/bgp_labelpool.c index 2c98cd9ef9fb..e052d6061ef4 100644 --- a/bgpd/bgp_labelpool.c +++ b/bgpd/bgp_labelpool.c @@ -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; diff --git a/bgpd/bgp_main.c b/bgpd/bgp_main.c index acb4272cd1ff..3048df8237b2 100644 --- a/bgpd/bgp_main.c +++ b/bgpd/bgp_main.c @@ -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" @@ -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, @@ -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 : ""), bm->port); diff --git a/bgpd/bgp_network.c b/bgpd/bgp_network.c index 84a959d0e8cb..3b844297123d 100644 --- a/bgpd/bgp_network.c +++ b/bgpd/bgp_network.c @@ -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" @@ -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; @@ -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; @@ -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; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index d3c03cb72213..7da15d40e3fd 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -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; @@ -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; diff --git a/isisd/dict.c b/isisd/dict.c index 20a4c0ff7383..5d3e61e6d6bf 100644 --- a/isisd/dict.c +++ b/isisd/dict.c @@ -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; } @@ -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; } @@ -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; } diff --git a/isisd/isis_circuit.c b/isisd/isis_circuit.c index 6f4d72cb1fe0..7a89d56bd053 100644 --- a/isisd/isis_circuit.c +++ b/isisd/isis_circuit.c @@ -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 diff --git a/isisd/isis_spf.c b/isisd/isis_spf.c index a55a0e190216..4350686b1a0b 100644 --- a/isisd/isis_spf.c +++ b/isisd/isis_spf.c @@ -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); diff --git a/isisd/isis_te.c b/isisd/isis_te.c index 6834f52a82a6..459494761212 100644 --- a/isisd/isis_te.c +++ b/isisd/isis_te.c @@ -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; diff --git a/lib/agentx.c b/lib/agentx.c index 302bbf0a4266..80422c480542 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -31,6 +31,7 @@ #include "memory.h" #include "linklist.h" #include "version.h" +#include "lib_errors.h" static int agentx_enabled = 0; @@ -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); diff --git a/lib/buffer.c b/lib/buffer.c index b573981c1b68..207f2320ff58 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 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 a8e61c6bb4f1..53c3568aac31 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") @@ -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 diff --git a/lib/ferr.c b/lib/ferr.c index d315cf843c82..26b8c87f6a99 100644 --- a/lib/ferr.c +++ b/lib/ferr.c @@ -24,9 +24,14 @@ #include "vty.h" #include "jhash.h" #include "memory.h" +#include "hash.h" +#include "command.h" DEFINE_MTYPE_STATIC(LIB, ERRINFO, "error information") +/* + * Thread-specific key for temporary storage of allocated ferr. + */ static pthread_key_t errkey; static void ferr_free(void *arg) @@ -46,6 +51,106 @@ static void err_key_fini(void) pthread_key_delete(errkey); } +/* + * Global shared hash table holding reference text for all defined errors. + */ +pthread_mutex_t refs_mtx = PTHREAD_MUTEX_INITIALIZER; +struct hash *refs; + +static int ferr_hash_cmp(const void *a, const void *b) +{ + const struct ferr_ref *f_a = a; + const struct ferr_ref *f_b = b; + + return f_a->code == f_b->code; +} + +static inline unsigned int ferr_hash_key(void *a) +{ + struct ferr_ref *f = a; + + return f->code; +} + +void ferr_ref_add(struct ferr_ref *ref) +{ + uint32_t i = 0; + + pthread_mutex_lock(&refs_mtx); + { + while (ref[i].code != END_FERR) { + hash_get(refs, &ref[i], hash_alloc_intern); + i++; + } + } + pthread_mutex_unlock(&refs_mtx); +} + +struct ferr_ref *ferr_ref_get(uint32_t code) +{ + struct ferr_ref holder; + struct ferr_ref *ref; + + holder.code = code; + pthread_mutex_lock(&refs_mtx); + { + ref = hash_lookup(refs, &holder); + } + pthread_mutex_unlock(&refs_mtx); + + return ref; +} + +void ferr_ref_display(struct vty *vty, uint32_t code) +{ + struct ferr_ref *ref = ferr_ref_get(code); + + if (!ref) { + vty_out(vty, "Code %d - Unknown\n", code); + return; + } + + vty_out(vty, "Error Code %d - %s\n", code, ref->title); + vty_out(vty, "--------------------------------------\n"); + vty_out(vty, "\nDescription:\n%s\n\nRecommendation:\n%s\n\n", + ref->description, ref->suggestion); +} + +DEFUN_NOSH(show_error_code, + show_error_code_cmd, + "show error (0-4294967296)", + SHOW_STR + "Information on errors\n" + "Error code to get info about\n") +{ + uint32_t arg = strtoul(argv[2]->arg, NULL, 10); + + ferr_ref_display(vty, arg); + return CMD_SUCCESS; +} + +void ferr_ref_init(void) +{ + pthread_mutex_lock(&refs_mtx); + { + refs = hash_create(ferr_hash_key, ferr_hash_cmp, + "Error Reference Texts"); + } + pthread_mutex_unlock(&refs_mtx); + + install_element(VIEW_NODE, &show_error_code_cmd); +} + +void ferr_ref_fini(void) +{ + pthread_mutex_lock(&refs_mtx); + { + hash_free(refs); + refs = NULL; + } + pthread_mutex_unlock(&refs_mtx); +} + const struct ferr *ferr_get_last(ferr_r errval) { struct ferr *last_error = pthread_getspecific(errkey); diff --git a/lib/ferr.h b/lib/ferr.h index 2f100c1b0121..011925b854fa 100644 --- a/lib/ferr.h +++ b/lib/ferr.h @@ -25,6 +25,8 @@ #include #include +#include "vty.h" + /* return type when this error indication stuff is used. * * guaranteed to have boolean evaluation to "false" when OK, "true" when error @@ -93,6 +95,40 @@ struct ferr { char pathname[PATH_MAX]; }; +/* Numeric ranges assigned to daemons for use as error codes. */ +#define LIB_FERR_START 0x01000001 +#define LIB_FERR_END 0x01FFFFFF +#define BGP_FERR_START 0x02000000 +#define BGP_FERR_END 0x02FFFFFF +#define OSPF_FERR_START 0x03000001 +#define OSPF_FERR_END 0x03FFFFFF +#define ZEBRA_FERR_START 0x04000001 +#define ZEBRA_FERR_END 0x04FFFFFF +#define END_FERR 0xFFFFFFFF + +struct ferr_ref { + /* Unique error code displayed to end user as a reference. -1 means + * this is an uncoded error that does not have reference material. */ + uint32_t code; + /* Ultra brief title */ + const char *title; + /* Brief description of error */ + const char *description; + /* Remedial suggestion */ + const char *suggestion; +}; + +void ferr_ref_add(struct ferr_ref *ref); +struct ferr_ref *ferr_ref_get(uint32_t code); +void ferr_ref_display(struct vty *, uint32_t code); + +/* + * This function should be called by the + * code in libfrr.c + */ +void ferr_ref_init(void); +void ferr_ref_fini(void); + /* get error details. * * NB: errval/ferr_r does NOT carry the full error information. It's only diff --git a/lib/lib_errors.c b/lib/lib_errors.c new file mode 100644 index 000000000000..f4ddcfc6161e --- /dev/null +++ b/lib/lib_errors.c @@ -0,0 +1,90 @@ +/* + * lib_errors - code for error messages that may occur in the + * libs + * 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 + +#include + +static struct ferr_ref ferr_lib_err[] = { + { + .code = LIB_ERR_PRIVILEGES, + .title = "Failure to raise or lower priviledges", + .description = "FRR attempted to raise or lower it's priviledges and was unable to do so", + .suggestion = "Ensure that you are running FRR as the frr user and that the user has\nSufficient priviledges to properly access root priviledges" + }, + { + .code = LIB_ERR_VRF_START, + .title = "VRF Failure on Start", + .description = "Upon startup FRR failed to properly initialize and startup the VRF subsystem", + .suggestion = "Ensure that there is sufficient memory to start processes and restart FRR", + }, + { + .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", + }, + { + .code = LIB_ERR_ZAPI_MISSMATCH, + .title = "Zapi Error", + .description = "A version miss-match has been detected between zebra and client protocol", + .suggestion = "Two different versions of FRR have been installed and the install is\nnot properly setup. Completely stop FRR, remove it from the system and\nreinstall. Typically only developers should see this issue" + }, + { + .code = LIB_ERR_ZAPI_ENCODE, + .title = "Zapi Error", + .description = "The Zapi subsystem has detected an encoding issue, between zebra and a client protocol", + .suggestion = "Restart FRR" + }, + { + .code = LIB_ERR_ZAPI_SOCKET, + .title = "Zapi Error", + .description = "The Zapi subsystem has detected a socket error between zebra and a client", + .suggestion = "Restart FRR" + }, + { + .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 = LIB_ERR_VTY, + .title = "VTY subsystem Error", + .description = "FRR has detected a problem with the specified configuration file", + .suggestion = "Ensure configuration file exists and has correct permissions for operations\nAdditionally ensure that all config lines are correct as well", + }, + { + .code = LIB_ERR_SNMP, + .title = "SNMP subsystem Error", + .description = "FRR has detected a problem with the snmp library it uses\nA callback from this subsystem has indicated some error", + .suggestion = "Examine callback message and ensure snmp is properly setup and working" + }, + { + .code = END_FERR, + } +}; + +void lib_error_init(void) +{ + ferr_ref_init(); + + ferr_ref_add(ferr_lib_err); +} diff --git a/lib/lib_errors.h b/lib/lib_errors.h new file mode 100644 index 000000000000..1723d45b57e2 --- /dev/null +++ b/lib/lib_errors.h @@ -0,0 +1,40 @@ +/* + * lib_errors - header for error messages that may occur in the libs + * 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 __LIB_ERRORS_H__ +#define __LIB_ERRORS_H__ + +#include "ferr.h" +#include "lib_errors.h" + +enum lib_ferr_refs { + LIB_ERR_PRIVILEGES = LIB_FERR_START, + LIB_ERR_VRF_START, + LIB_ERR_SOCKET, + LIB_ERR_ZAPI_MISSMATCH, + LIB_ERR_ZAPI_ENCODE, + LIB_ERR_ZAPI_SOCKET, + LIB_ERR_SYSTEM_CALL, + LIB_ERR_VTY, + LIB_ERR_SNMP, +}; + +extern void lib_error_init(void); + +#endif diff --git a/lib/libfrr.c b/lib/libfrr.c index 88203fbeb6bb..b51c871554fa 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -35,6 +35,7 @@ #include "log_int.h" #include "module.h" #include "network.h" +#include "lib_errors.h" DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm)) DEFINE_KOOH(frr_early_fini, (), ()) @@ -587,6 +588,8 @@ struct thread_master *frr_init(void) vty_init(master); memory_init(); + lib_error_init(); + return master; } diff --git a/lib/log.c b/lib/log.c index 1345ff2fd186..afecbef19cd6 100644 --- 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 #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/log.h b/lib/log.h index 07eb6d5bd560..a2546298a86b 100644 --- a/lib/log.h +++ b/lib/log.h @@ -85,6 +85,11 @@ extern void zlog_info(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); extern void zlog_notice(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); +/* For logs which have error codes associated with them */ +#define zlog_ferr(ferr_id, format, ...) \ + zlog_err("[EC %d] " format, ferr_id, ##__VA_ARGS__) + + extern void zlog_thread_info(int log_level); /* Set logging level for the given destination. If the log_level diff --git a/lib/netns_linux.c b/lib/netns_linux.c index a3fae8f39fab..e9a619893e1a 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 023a166f27d3..21687e48c4b2 100644 --- a/lib/pid_output.c +++ b/lib/pid_output.c @@ -24,6 +24,7 @@ #include #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 d299760fabe0..a58718706854 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -22,6 +22,7 @@ #include #include #include +#include #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 1d8d9990df5d..c24696288f8d 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; @@ -667,8 +669,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 */ diff --git a/lib/sockunion.c b/lib/sockunion.c index 28a7f647cba7..2ff8d8072607 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -26,6 +26,7 @@ #include "memory.h" #include "log.h" #include "jhash.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, SOCKUNION, "Socket union") @@ -363,12 +364,14 @@ int sockopt_mark_default(int sock, int mark, struct zebra_privs_t *cap) int ret; if (cap->change(ZPRIVS_RAISE)) - zlog_err("routing_socket: Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't raise privileges"); ret = setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark)); if (cap->change(ZPRIVS_LOWER)) - zlog_err("routing_socket: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't lower privileges"); return ret; #else diff --git a/lib/subdir.am b/lib/subdir.am index 9472fabe1d15..9660bb767082 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -35,6 +35,7 @@ lib_libfrr_la_SOURCES = \ lib/jhash.c \ lib/json.c \ lib/keychain.c \ + lib/lib_errors.c \ lib/libfrr.c \ lib/linklist.c \ lib/log.c \ @@ -118,6 +119,7 @@ pkginclude_HEADERS += \ lib/jhash.h \ lib/json.h \ lib/keychain.h \ + lib/lib_errors.h \ lib/libfrr.h \ lib/libospf.h \ lib/linklist.h \ diff --git a/lib/vrf.c b/lib/vrf.c index 797b25d01dcb..2ee9fc5e8074 100644 --- a/lib/vrf.c +++ b/lib/vrf.c @@ -35,6 +35,7 @@ #include "ns.h" #include "privs.h" #include "nexthop_group.h" +#include "lib_errors.h" /* default VRF ID value used when VRF backend is not NETNS */ #define VRF_DEFAULT_INTERNAL 0 @@ -466,13 +467,15 @@ void vrf_init(int (*create)(struct vrf *), int (*enable)(struct vrf *), /* The default VRF always exists. */ default_vrf = vrf_get(VRF_DEFAULT, VRF_DEFAULT_NAME); if (!default_vrf) { - zlog_err("vrf_init: failed to create the default VRF!"); + zlog_ferr(LIB_ERR_VRF_START, + "vrf_init: failed to create the default VRF!"); exit(1); } /* Enable the default VRF. */ if (!vrf_enable(default_vrf)) { - zlog_err("vrf_init: failed to enable the default VRF!"); + zlog_ferr(LIB_ERR_VRF_START, + "vrf_init: failed to enable the default VRF!"); exit(1); } @@ -513,14 +516,16 @@ 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_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, + safe_strerror(errno)); ret = socket(domain, type, protocol); save_errno = errno; ret2 = vrf_switchback_to_initial(); if (ret2 < 0) - zlog_err("%s: Can't switchback from VRF %u (%s)", __func__, - vrf_id, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't switchback from VRF %u (%s)", __func__, + vrf_id, safe_strerror(errno)); errno = save_errno; if (ret <= 0) return ret; @@ -726,14 +731,16 @@ DEFUN (vrf_netns, if (vrf_daemon_privs && vrf_daemon_privs->change(ZPRIVS_RAISE)) - zlog_err("%s: Can't raise privileges", __func__); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: Can't raise privileges", + __func__); ret = vrf_netns_handler_create(vty, vrf, pathname, NS_UNKNOWN, NS_UNKNOWN); if (vrf_daemon_privs && vrf_daemon_privs->change(ZPRIVS_LOWER)) - zlog_err("%s: Can't lower privileges", __func__); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: Can't lower privileges", + __func__); return ret; } @@ -871,14 +878,16 @@ int vrf_getaddrinfo(const char *node, const char *service, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - zlog_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id, - safe_strerror(errno)); + 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_err("%s: Can't switchback from VRF %u (%s)", __func__, - vrf_id, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't switchback from VRF %u (%s)", __func__, + vrf_id, safe_strerror(errno)); errno = save_errno; return ret; } @@ -889,16 +898,18 @@ 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_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, + safe_strerror(errno)); return 0; } rc = ioctl(d, request, params); saved_errno = errno; ret = vrf_switchback_to_initial(); if (ret < 0) - zlog_err("%s: Can't switchback from VRF %u (%s)", __func__, - vrf_id, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't switchback from VRF %u (%s)", __func__, + vrf_id, safe_strerror(errno)); errno = saved_errno; return rc; } @@ -910,14 +921,16 @@ int vrf_sockunion_socket(const union sockunion *su, vrf_id_t vrf_id, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - zlog_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id, - safe_strerror(errno)); + 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_err("%s: Can't switchback from VRF %u (%s)", __func__, - vrf_id, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't switchback from VRF %u (%s)", __func__, + vrf_id, safe_strerror(errno)); errno = save_errno; if (ret <= 0) diff --git a/lib/vty.c b/lib/vty.c index 280b2ace51a6..b5e4aed8262b 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -40,6 +40,7 @@ #include "network.h" #include "libfrr.h" #include "frrstr.h" +#include "lib_errors.h" #include #include @@ -509,7 +510,7 @@ static int vty_command(struct vty *vty, char *buf) vty_str); /* now log the command */ - zlog_err("%s%s", prompt_str, buf); + zlog_notice("%s%s", prompt_str, buf); } #ifdef CONSUMED_TIME_CHECK @@ -1966,7 +1967,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); } @@ -2026,7 +2028,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; } @@ -2045,15 +2048,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; } @@ -2068,8 +2074,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)); } } @@ -2400,8 +2407,9 @@ static void vty_read_file(FILE *confp) nl = strchr(vty->error_buf, '\n'); if (nl) *nl = '\0'; - zlog_err("ERROR: %s on config line %u: %s", message, line_num, - vty->error_buf); + zlog_ferr(LIB_ERR_VTY, + "ERROR: %s on config line %u: %s", message, line_num, + vty->error_buf); } vty_close(vty); @@ -2473,9 +2481,9 @@ void 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, @@ -2488,7 +2496,7 @@ void 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); @@ -2496,8 +2504,9 @@ void vty_read_config(const char *config_file, char *config_default_dir) zlog_warn( "WARNING: using backup configuration file!"); else { - zlog_err("can't open configuration file [%s]", - config_file); + zlog_ferr(LIB_ERR_VTY, + "can't open configuration file [%s]", + config_file); exit(1); } } @@ -2531,9 +2540,9 @@ void 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) { @@ -2541,8 +2550,9 @@ void vty_read_config(const char *config_file, char *config_default_dir) "WARNING: using backup configuration file!"); fullpath = config_default_dir; } else { - zlog_err("can't open configuration file [%s]", - config_default_dir); + zlog_ferr(LIB_ERR_VTY, + "can't open configuration file [%s]", + config_default_dir); goto tmp_free_and_out; } } else @@ -3052,12 +3062,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); } } diff --git a/lib/workqueue.c b/lib/workqueue.c index 1af51c06c130..3eb569d1f98d 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -81,9 +81,6 @@ struct work_queue *work_queue_new(struct thread_master *m, new = XCALLOC(MTYPE_WORK_QUEUE, sizeof(struct work_queue)); - if (new == NULL) - return new; - new->name = XSTRDUP(MTYPE_WORK_QUEUE_NAME, queue_name); new->master = m; SET_FLAG(new->flags, WQ_UNPLUGGED); @@ -152,10 +149,7 @@ void work_queue_add(struct work_queue *wq, void *data) assert(wq); - if (!(item = work_queue_item_new(wq))) { - zlog_err("%s: unable to get new queue item", __func__); - return; - } + item = work_queue_item_new(wq); item->data = data; work_queue_item_enqueue(wq, item); diff --git a/lib/zclient.c b/lib/zclient.c index 38a9e6c78eec..105435fb2e4f 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -38,6 +38,7 @@ #include "sockopt.h" #include "pbr.h" #include "nexthop_group.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, ZCLIENT, "Zclient") DEFINE_MTYPE_STATIC(LIB, REDIST_INST, "Redistribution instance IDs") @@ -312,9 +313,9 @@ int zclient_read_header(struct stream *s, int sock, uint16_t *size, STREAM_GETW(s, *cmd); if (*version != ZSERV_VERSION || *marker != ZEBRA_HEADER_MARKER) { - zlog_err( - "%s: socket %d version mismatch, marker %d, version %d", - __func__, sock, *marker, *version); + zlog_ferr(LIB_ERR_ZAPI_MISSMATCH, + "%s: socket %d version mismatch, marker %d, version %d", + __func__, sock, *marker, *version); return -1; } @@ -1045,12 +1046,12 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) char buf[PREFIX2STR_BUFFER]; prefix2str(&api->prefix, buf, sizeof(buf)); - zlog_err( - "%s: prefix %s: can't encode " - "%u labels (maximum is %u)", - __func__, buf, - api_nh->label_num, - MPLS_MAX_LABELS); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "%s: prefix %s: can't encode " + "%u labels (maximum is %u)", + __func__, buf, + api_nh->label_num, + MPLS_MAX_LABELS); return -1; } @@ -1671,10 +1672,10 @@ static void link_params_set_value(struct stream *s, struct if_link_params *iflp) for (i = 0; i < bwclassnum && i < MAX_CLASS_TYPE; i++) iflp->unrsv_bw[i] = stream_getf(s); if (i < bwclassnum) - zlog_err( - "%s: received %d > %d (MAX_CLASS_TYPE) bw entries" - " - outdated library?", - __func__, bwclassnum, MAX_CLASS_TYPE); + zlog_ferr(LIB_ERR_ZAPI_MISSMATCH, + "%s: received %d > %d (MAX_CLASS_TYPE) bw entries" + " - outdated library?", + __func__, bwclassnum, MAX_CLASS_TYPE); } iflp->admin_grp = stream_getl(s); iflp->rmt_as = stream_getl(s); @@ -1703,8 +1704,9 @@ struct interface *zebra_interface_link_params_read(struct stream *s) struct interface *ifp = if_lookup_by_index(ifindex, VRF_DEFAULT); if (ifp == NULL) { - zlog_err("%s: unknown ifindex %u, shouldn't happen", __func__, - ifindex); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "%s: unknown ifindex %u, shouldn't happen", __func__, + ifindex); return NULL; } @@ -2039,7 +2041,8 @@ static int zclient_read_sync_response(struct zclient *zclient, size); } if (ret != 0) { - zlog_err("%s: Invalid Sync Message Reply", __func__); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "%s: Invalid Sync Message Reply", __func__); return -1; } @@ -2081,13 +2084,13 @@ int lm_label_manager_connect(struct zclient *zclient) ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - zlog_err("Can't write to zclient sock"); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, "Can't write to zclient sock"); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - zlog_err("Zclient sock closed"); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, "Zclient sock closed"); close(zclient->sock); zclient->sock = -1; return -1; @@ -2108,13 +2111,13 @@ int lm_label_manager_connect(struct zclient *zclient) /* sanity */ if (proto != zclient->redist_default) - zlog_err( - "Wrong proto (%u) in LM connect response. Should be %u", - proto, zclient->redist_default); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "Wrong proto (%u) in LM connect response. Should be %u", + proto, zclient->redist_default); if (instance != zclient->instance) - zlog_err( - "Wrong instId (%u) in LM connect response. Should be %u", - instance, zclient->instance); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "Wrong instId (%u) in LM connect response. Should be %u", + instance, zclient->instance); /* result code */ result = stream_getc(s); @@ -2203,13 +2206,15 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - zlog_err("Can't write to zclient sock"); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, + "Can't write to zclient sock"); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - zlog_err("Zclient sock closed"); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, + "Zclient sock closed"); close(zclient->sock); zclient->sock = -1; return -1; @@ -2230,11 +2235,13 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, /* sanities */ if (proto != zclient->redist_default) - zlog_err("Wrong proto (%u) in get chunk response. Should be %u", - proto, zclient->redist_default); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "Wrong proto (%u) in get chunk response. Should be %u", + proto, zclient->redist_default); if (instance != zclient->instance) - zlog_err("Wrong instId (%u) in get chunk response Should be %u", - instance, zclient->instance); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "Wrong instId (%u) in get chunk response Should be %u", + instance, zclient->instance); /* keep */ response_keep = stream_getc(s); @@ -2244,14 +2251,15 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, /* not owning this response */ if (keep != response_keep) { - zlog_err( - "Invalid Label chunk: %u - %u, keeps mismatch %u != %u", - *start, *end, keep, response_keep); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "Invalid Label chunk: %u - %u, keeps mismatch %u != %u", + *start, *end, keep, response_keep); } /* sanity */ if (*start > *end || *start < MPLS_LABEL_UNRESERVED_MIN || *end > MPLS_LABEL_UNRESERVED_MAX) { - zlog_err("Invalid Label chunk: %u - %u", *start, *end); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "Invalid Label chunk: %u - %u", *start, *end); return -1; } @@ -2301,13 +2309,14 @@ int lm_release_label_chunk(struct zclient *zclient, uint32_t start, ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - zlog_err("Can't write to zclient sock"); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, "Can't write to zclient sock"); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - zlog_err("Zclient sock connection closed"); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, + "Zclient sock connection closed"); close(zclient->sock); zclient->sock = -1; return -1; @@ -2410,13 +2419,15 @@ int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - zlog_err("%s: can't write to zclient->sock", __func__); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, + "%s: can't write to zclient->sock", __func__); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - zlog_err("%s: zclient->sock connection closed", __func__); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, + "%s: zclient->sock connection closed", __func__); close(zclient->sock); zclient->sock = -1; return -1; @@ -2502,7 +2513,8 @@ int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw) stream_write(s, (uint8_t *)&pw->nexthop.ipv6, 16); break; default: - zlog_err("%s: unknown af", __func__); + zlog_ferr(LIB_ERR_ZAPI_ENCODE, + "%s: unknown af", __func__); return -1; } @@ -2604,15 +2616,16 @@ static int zclient_read(struct thread *thread) command = stream_getw(zclient->ibuf); if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) { - zlog_err( - "%s: socket %d version mismatch, marker %d, version %d", - __func__, zclient->sock, marker, version); + zlog_ferr(LIB_ERR_ZAPI_MISSMATCH, + "%s: socket %d version mismatch, marker %d, version %d", + __func__, zclient->sock, marker, version); return zclient_failed(zclient); } if (length < ZEBRA_HEADER_SIZE) { - zlog_err("%s: socket %d message length %u is less than %d ", - __func__, zclient->sock, length, ZEBRA_HEADER_SIZE); + zlog_ferr(LIB_ERR_ZAPI_MISSMATCH, + "%s: socket %d message length %u is less than %d ", + __func__, zclient->sock, length, ZEBRA_HEADER_SIZE); return zclient_failed(zclient); } diff --git a/nhrpd/nhrp_cache.c b/nhrpd/nhrp_cache.c index ffc8b5a9bf80..f3a33eb28f2c 100644 --- a/nhrpd/nhrp_cache.c +++ b/nhrpd/nhrp_cache.c @@ -48,17 +48,16 @@ static void *nhrp_cache_alloc(void *data) struct nhrp_cache *p, *key = data; p = XMALLOC(MTYPE_NHRP_CACHE, sizeof(struct nhrp_cache)); - if (p) { - *p = (struct nhrp_cache){ - .cur.type = NHRP_CACHE_INVALID, - .new.type = NHRP_CACHE_INVALID, - .remote_addr = key->remote_addr, - .ifp = key->ifp, - .notifier_list = - NOTIFIER_LIST_INITIALIZER(&p->notifier_list), - }; - nhrp_cache_counts[p->cur.type]++; - } + + *p = (struct nhrp_cache){ + .cur.type = NHRP_CACHE_INVALID, + .new.type = NHRP_CACHE_INVALID, + .remote_addr = key->remote_addr, + .ifp = key->ifp, + .notifier_list = + NOTIFIER_LIST_INITIALIZER(&p->notifier_list), + }; + nhrp_cache_counts[p->cur.type]++; return p; } diff --git a/nhrpd/nhrp_interface.c b/nhrpd/nhrp_interface.c index 054a375cb89a..3a42712748cd 100644 --- a/nhrpd/nhrp_interface.c +++ b/nhrpd/nhrp_interface.c @@ -25,8 +25,6 @@ static int nhrp_if_new_hook(struct interface *ifp) afi_t afi; nifp = XCALLOC(MTYPE_NHRP_IF, sizeof(struct nhrp_interface)); - if (!nifp) - return 0; ifp->info = nifp; nifp->ifp = ifp; diff --git a/nhrpd/nhrp_nhs.c b/nhrpd/nhrp_nhs.c index a7a8c2019154..360972c327f5 100644 --- a/nhrpd/nhrp_nhs.c +++ b/nhrpd/nhrp_nhs.c @@ -324,8 +324,6 @@ int nhrp_nhs_add(struct interface *ifp, afi_t afi, union sockunion *proto_addr, } nhs = XMALLOC(MTYPE_NHRP_NHS, sizeof(struct nhrp_nhs)); - if (!nhs) - return NHRP_ERR_NO_MEMORY; *nhs = (struct nhrp_nhs){ .afi = afi, diff --git a/nhrpd/nhrp_peer.c b/nhrpd/nhrp_peer.c index 8952a282e904..44271d68ac79 100644 --- a/nhrpd/nhrp_peer.c +++ b/nhrpd/nhrp_peer.c @@ -165,18 +165,18 @@ static void *nhrp_peer_create(void *data) struct nhrp_peer *p, *key = data; p = XMALLOC(MTYPE_NHRP_PEER, sizeof(*p)); - if (p) { - *p = (struct nhrp_peer){ - .ref = 0, - .ifp = key->ifp, - .vc = key->vc, - .notifier_list = - NOTIFIER_LIST_INITIALIZER(&p->notifier_list), - }; - nhrp_vc_notify_add(p->vc, &p->vc_notifier, nhrp_peer_vc_notify); - nhrp_interface_notify_add(p->ifp, &p->ifp_notifier, - nhrp_peer_ifp_notify); - } + + *p = (struct nhrp_peer){ + .ref = 0, + .ifp = key->ifp, + .vc = key->vc, + .notifier_list = + NOTIFIER_LIST_INITIALIZER(&p->notifier_list), + }; + nhrp_vc_notify_add(p->vc, &p->vc_notifier, nhrp_peer_vc_notify); + nhrp_interface_notify_add(p->ifp, &p->ifp_notifier, + nhrp_peer_ifp_notify); + return p; } diff --git a/nhrpd/nhrp_vc.c b/nhrpd/nhrp_vc.c index c373411d66d9..41a87d4adbc1 100644 --- a/nhrpd/nhrp_vc.c +++ b/nhrpd/nhrp_vc.c @@ -48,14 +48,13 @@ static void *nhrp_vc_alloc(void *data) struct nhrp_vc *vc, *key = data; vc = XMALLOC(MTYPE_NHRP_VC, sizeof(struct nhrp_vc)); - if (vc) { - *vc = (struct nhrp_vc){ - .local.nbma = key->local.nbma, - .remote.nbma = key->remote.nbma, - .notifier_list = - NOTIFIER_LIST_INITIALIZER(&vc->notifier_list), - }; - } + + *vc = (struct nhrp_vc){ + .local.nbma = key->local.nbma, + .remote.nbma = key->remote.nbma, + .notifier_list = + NOTIFIER_LIST_INITIALIZER(&vc->notifier_list), + }; return vc; } @@ -118,8 +117,6 @@ int nhrp_vc_ipsec_updown(uint32_t child_id, struct nhrp_vc *vc) return 0; sa = XMALLOC(MTYPE_NHRP_VC, sizeof(struct child_sa)); - if (!sa) - return 0; *sa = (struct child_sa){ .id = child_id, diff --git a/nhrpd/zbuf.c b/nhrpd/zbuf.c index 65232a309318..6e7cad8aec2c 100644 --- a/nhrpd/zbuf.c +++ b/nhrpd/zbuf.c @@ -25,8 +25,6 @@ struct zbuf *zbuf_alloc(size_t size) struct zbuf *zb; zb = XMALLOC(MTYPE_ZBUF_DATA, sizeof(*zb) + size); - if (!zb) - return NULL; zbuf_init(zb, zb + 1, size, 0); zb->allocated = 1; diff --git a/ospf6d/ospf6_interface.c b/ospf6d/ospf6_interface.c index cc8577b94e7a..2d939f7df04d 100644 --- a/ospf6d/ospf6_interface.c +++ b/ospf6d/ospf6_interface.c @@ -180,12 +180,6 @@ struct ospf6_interface *ospf6_interface_create(struct interface *ifp) oi = (struct ospf6_interface *)XCALLOC(MTYPE_OSPF6_IF, sizeof(struct ospf6_interface)); - if (!oi) { - zlog_err("Can't malloc ospf6_interface for ifindex %d", - ifp->ifindex); - return (struct ospf6_interface *)NULL; - } - oi->area = (struct ospf6_area *)NULL; oi->neighbor_list = list_new(); oi->neighbor_list->cmp = ospf6_neighbor_cmp; diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index c608a0110243..c7cd94bd327b 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -1503,14 +1503,6 @@ int ospf6_iobuf_size(unsigned int size) recvnew = XMALLOC(MTYPE_OSPF6_MESSAGE, size); sendnew = XMALLOC(MTYPE_OSPF6_MESSAGE, size); - if (recvnew == NULL || sendnew == NULL) { - if (recvnew) - XFREE(MTYPE_OSPF6_MESSAGE, recvnew); - if (sendnew) - XFREE(MTYPE_OSPF6_MESSAGE, sendnew); - zlog_debug("Could not allocate I/O buffer of size %d.", size); - return iobuflen; - } if (recvbuf) XFREE(MTYPE_OSPF6_MESSAGE, recvbuf); diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index b5a1812ffa82..0cc7294d6799 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -84,10 +84,6 @@ struct ospf6_neighbor *ospf6_neighbor_create(uint32_t router_id, on = (struct ospf6_neighbor *)XMALLOC(MTYPE_OSPF6_NEIGHBOR, sizeof(struct ospf6_neighbor)); - if (on == NULL) { - zlog_warn("neighbor: malloc failed"); - return NULL; - } memset(on, 0, sizeof(struct ospf6_neighbor)); inet_ntop(AF_INET, &router_id, buf, sizeof(buf)); diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 28c3459825e0..0b94b930c5e0 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -1012,16 +1012,10 @@ struct ospf6_lsa *ospf6_create_single_router_lsa(struct ospf6_area *area, /* Allocate memory for this LSA */ new_header = XMALLOC(MTYPE_OSPF6_LSA_HEADER, total_lsa_length); - if (!new_header) - return NULL; /* LSA information structure */ lsa = (struct ospf6_lsa *)XCALLOC(MTYPE_OSPF6_LSA, sizeof(struct ospf6_lsa)); - if (!lsa) { - free(new_header); - return NULL; - } lsa->header = (struct ospf6_lsa_header *)new_header; diff --git a/ospfclient/ospf_apiclient.c b/ospfclient/ospf_apiclient.c index 5b46059d7835..db624ae0741a 100644 --- a/ospfclient/ospf_apiclient.c +++ b/ospfclient/ospf_apiclient.c @@ -570,10 +570,7 @@ static void ospf_apiclient_handle_lsa_update(struct ospf_apiclient *oclient, /* Extract LSA from message */ lsalen = ntohs(cn->data.length); lsa = XMALLOC(MTYPE_OSPF_APICLIENT, lsalen); - if (!lsa) { - fprintf(stderr, "LSA update: Cannot allocate memory for LSA\n"); - return; - } + memcpy(lsa, &(cn->data), lsalen); /* Invoke registered update callback function */ @@ -598,10 +595,7 @@ static void ospf_apiclient_handle_lsa_delete(struct ospf_apiclient *oclient, /* Extract LSA from message */ lsalen = ntohs(cn->data.length); lsa = XMALLOC(MTYPE_OSPF_APICLIENT, lsalen); - if (!lsa) { - fprintf(stderr, "LSA delete: Cannot allocate memory for LSA\n"); - return; - } + memcpy(lsa, &(cn->data), lsalen); /* Invoke registered update callback function */ diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index 37735e36119e..d19b04682a79 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -1176,13 +1176,11 @@ int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv, apiserv->filter = XMALLOC(MTYPE_OSPF_APISERVER_MSGFILTER, ntohs(msg->hdr.msglen)); - if (apiserv->filter) { - /* copy it over. */ - memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen)); - rc = OSPF_API_OK; - } else { - rc = OSPF_API_NOMEMORY; - } + + /* copy it over. */ + memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen)); + rc = OSPF_API_OK; + /* Send a reply back to client with return code */ rc = ospf_apiserver_send_reply(apiserv, seqnum, rc); return rc; diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c index ac5df3eb4e2d..47ae9adb7ef0 100644 --- a/ospfd/ospf_ext.c +++ b/ospfd/ospf_ext.c @@ -545,11 +545,6 @@ static int ospf_ext_link_new_if(struct interface *ifp) } new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf)); - if (new == NULL) { - zlog_warn("EXT (%s): XCALLOC: %s", __func__, - safe_strerror(errno)); - return rc; - } /* initialize new information and link back the interface */ new->ifp = ifp; diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c index ea31d8c2ca2b..28f22c488636 100644 --- a/ospfd/ospf_interface.c +++ b/ospfd/ospf_interface.c @@ -523,9 +523,6 @@ static struct ospf_if_params *ospf_new_if_params(void) oip = XCALLOC(MTYPE_OSPF_IF_PARAMS, sizeof(struct ospf_if_params)); - if (!oip) - return NULL; - UNSET_IF_PARAM(oip, output_cost_cmd); UNSET_IF_PARAM(oip, transmit_delay); UNSET_IF_PARAM(oip, retransmit_interval); diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index 662379083703..c7d0c8f632a6 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -2911,24 +2911,17 @@ void ospf_lsa_maxage(struct ospf *ospf, struct ospf_lsa *lsa) lsa_prefix.prefixlen = sizeof(lsa_prefix.u.ptr) * CHAR_BIT; lsa_prefix.u.ptr = (uintptr_t)lsa; - if ((rn = route_node_get(ospf->maxage_lsa, - (struct prefix *)&lsa_prefix)) - != NULL) { - if (rn->info != NULL) { - if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) - zlog_debug( - "LSA[%s]: found LSA (%p) in table for LSA %p %d", - dump_lsa_key(lsa), rn->info, - (void *)lsa, lsa_prefix.prefixlen); - route_unlock_node(rn); - } else { - rn->info = ospf_lsa_lock(lsa); - SET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE); - } + rn = route_node_get(ospf->maxage_lsa, (struct prefix *)&lsa_prefix); + if (rn->info != NULL) { + if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) + zlog_debug( + "LSA[%s]: found LSA (%p) in table for LSA %p %d", + dump_lsa_key(lsa), rn->info, + (void *)lsa, lsa_prefix.prefixlen); + route_unlock_node(rn); } else { - zlog_err("Unable to allocate memory for maxage lsa %s\n", - dump_lsa_key(lsa)); - assert(0); + rn->info = ospf_lsa_lock(lsa); + SET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE); } if (IS_DEBUG_OSPF(lsa, LSA_FLOODING)) diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c index 1ae9a29a1b50..be62eb3906d0 100644 --- a/ospfd/ospf_opaque.c +++ b/ospfd/ospf_opaque.c @@ -399,13 +399,8 @@ int ospf_register_opaque_functab( } } - if ((new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB, - sizeof(struct ospf_opaque_functab))) - == NULL) { - zlog_warn("ospf_register_opaque_functab: XMALLOC: %s", - safe_strerror(errno)); - goto out; - } + new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB, + sizeof(struct ospf_opaque_functab)); new->opaque_type = opaque_type; new->oipt = NULL; @@ -554,13 +549,8 @@ register_opaque_info_per_type(struct ospf_opaque_functab *functab, struct ospf *top; struct opaque_info_per_type *oipt; - if ((oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE, - sizeof(struct opaque_info_per_type))) - == NULL) { - zlog_warn("register_opaque_info_per_type: XMALLOC: %s", - safe_strerror(errno)); - goto out; - } + oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE, + sizeof(struct opaque_info_per_type)); switch (new->data->type) { case OSPF_OPAQUE_LINK_LSA: @@ -711,13 +701,9 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt, { struct opaque_info_per_id *oipi; - if ((oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID, - sizeof(struct opaque_info_per_id))) - == NULL) { - zlog_warn("register_opaque_info_per_id: XMALLOC: %s", - safe_strerror(errno)); - goto out; - } + oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID, + sizeof(struct opaque_info_per_id)); + oipi->opaque_id = GET_OPAQUE_ID(ntohl(new->data->id.s_addr)); oipi->t_opaque_lsa_self = NULL; oipi->opqctl_type = oipt; @@ -725,7 +711,6 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt, listnode_add(oipt->id_list, oipi); -out: return oipi; } diff --git a/ospfd/ospf_spf.c b/ospfd/ospf_spf.c index c6c16e71693a..e3c729f65ee1 100644 --- a/ospfd/ospf_spf.c +++ b/ospfd/ospf_spf.c @@ -154,9 +154,6 @@ static struct vertex_parent *vertex_parent_new(struct vertex *v, int backlink, new = XMALLOC(MTYPE_OSPF_VERTEX_PARENT, sizeof(struct vertex_parent)); - if (new == NULL) - return NULL; - new->parent = v; new->backlink = backlink; new->nexthop = hop; diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c index e5fc3e29548e..25983ddc57c1 100644 --- a/ospfd/ospf_sr.c +++ b/ospfd/ospf_sr.c @@ -128,12 +128,6 @@ static struct sr_node *sr_node_new(struct in_addr *rid) /* Allocate Segment Routing node memory */ new = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_node)); - /* Sanity Check */ - if (new == NULL) { - zlog_err("SR (%s): Abort! can't create new SR node", __func__); - return NULL; - } - /* Default Algorithm, SRGB and MSD */ for (int i = 0; i < ALGORITHM_COUNT; i++) new->algo[i] = SR_ALGORITHM_UNSET; @@ -735,9 +729,6 @@ static struct sr_link *get_ext_link_sid(struct tlv_header *tlvh) srl = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_link)); - if (srl == NULL) - return NULL; - /* Initialize TLV browsing */ length = ntohs(tlvh->length) - EXT_TLV_LINK_SIZE; sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE @@ -820,9 +811,6 @@ static struct sr_prefix *get_ext_prefix_sid(struct tlv_header *tlvh) srp = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_prefix)); - if (srp == NULL) - return NULL; - /* Initialize TLV browsing */ length = ntohs(tlvh->length) - EXT_TLV_PREFIX_SIZE; sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 2b1b328617e3..dabdf286dc30 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -857,11 +857,6 @@ static int ospf_mpls_te_new_if(struct interface *ifp) } new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link)); - if (new == NULL) { - zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s", - safe_strerror(errno)); - return rc; - } new->instance = get_mpls_te_instance_value(); new->ifp = ifp; diff --git a/pbrd/pbr_zebra.c b/pbrd/pbr_zebra.c index 8d336c9d0d95..25d64238bfd3 100644 --- a/pbrd/pbr_zebra.c +++ b/pbrd/pbr_zebra.c @@ -54,12 +54,6 @@ struct pbr_interface *pbr_if_new(struct interface *ifp) pbr_ifp = XCALLOC(MTYPE_PBR_INTERFACE, sizeof(*pbr_ifp)); - if (!pbr_ifp) { - zlog_err("%s: PBR XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*pbr_ifp)); - return 0; - } - ifp->info = pbr_ifp; return pbr_ifp; } diff --git a/pimd/pim_br.c b/pimd/pim_br.c index f297b0591db7..a4ecab1e3af9 100644 --- a/pimd/pim_br.c +++ b/pimd/pim_br.c @@ -64,11 +64,6 @@ void pim_br_set_pmbr(struct prefix_sg *sg, struct in_addr br) if (!pim_br) { pim_br = XCALLOC(MTYPE_PIM_BR, sizeof(*pim_br)); - if (!pim_br) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*pim_br)); - return; - } - pim_br->sg = *sg; listnode_add(pim_br_list, pim_br); diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 55222ecddbd8..e6385ed90a98 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -5100,11 +5100,6 @@ static int pim_rp_cmd_worker(struct pim_instance *pim, struct vty *vty, result = pim_rp_new(pim, rp, group, plist); - if (result == PIM_MALLOC_FAIL) { - vty_out(vty, "%% Out of memory\n"); - return CMD_WARNING_CONFIG_FAILED; - } - if (result == PIM_GROUP_BAD_ADDRESS) { vty_out(vty, "%% Bad group address specified: %s\n", group); return CMD_WARNING_CONFIG_FAILED; diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 5c4d99ad4d00..5b11ae90b22d 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -145,10 +145,6 @@ struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim) zassert(!ifp->info); pim_ifp = XCALLOC(MTYPE_PIM_INTERFACE, sizeof(*pim_ifp)); - if (!pim_ifp) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*pim_ifp)); - return 0; - } pim_ifp->options = 0; pim_ifp->pim = pim_get_pim_instance(ifp->vrf_id); @@ -404,8 +400,6 @@ static int pim_sec_addr_add(struct pim_interface *pim_ifp, struct prefix *addr) } sec_addr = XCALLOC(MTYPE_PIM_SEC_ADDR, sizeof(*sec_addr)); - if (!sec_addr) - return changed; changed = 1; sec_addr->addr = *addr; @@ -1286,20 +1280,6 @@ static struct igmp_join *igmp_join_new(struct interface *ifp, } ij = XCALLOC(MTYPE_PIM_IGMP_JOIN, sizeof(*ij)); - if (!ij) { - char group_str[INET_ADDRSTRLEN]; - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", group_addr, group_str, - sizeof(group_str)); - pim_inet4_dump("", source_addr, source_str, - sizeof(source_str)); - zlog_err( - "%s: XCALLOC(%zu) failure for IGMP group %s source %s on interface %s", - __PRETTY_FUNCTION__, sizeof(*ij), group_str, source_str, - ifp->name); - close(join_fd); - return 0; - } ij->sock_fd = join_fd; ij->group_addr = group_addr; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index 5e6b0f10cf5e..e82a7589b719 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -520,12 +520,6 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, pim_ifp = ifp->info; ch = XCALLOC(MTYPE_PIM_IFCHANNEL, sizeof(*ch)); - if (!ch) { - zlog_warn( - "%s: pim_ifchannel_new() failure for (S,G)=%s on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(sg), ifp->name); - return NULL; - } ch->flags = 0; if ((source_flags & PIM_ENCODE_RPT_BIT) diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index c980f5fcbaa7..8bfc59116a82 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -860,18 +860,8 @@ static struct igmp_sock *igmp_sock_new(int fd, struct in_addr ifaddr, } igmp = XCALLOC(MTYPE_PIM_IGMP_SOCKET, sizeof(*igmp)); - if (!igmp) { - zlog_warn("%s %s: XCALLOC() failure", __FILE__, - __PRETTY_FUNCTION__); - return 0; - } igmp->igmp_group_list = list_new(); - if (!igmp->igmp_group_list) { - zlog_err("%s %s: failure: igmp_group_list = list_new()", - __FILE__, __PRETTY_FUNCTION__); - return 0; - } igmp->igmp_group_list->del = (void (*)(void *))igmp_group_free; snprintf(hash_name, 64, "IGMP %s hash", ifp->name); @@ -1130,11 +1120,6 @@ struct igmp_group *igmp_add_group_by_addr(struct igmp_sock *igmp, */ group = XCALLOC(MTYPE_PIM_IGMP_GROUP, sizeof(*group)); - if (!group) { - zlog_warn("%s %s: XCALLOC() failure", __FILE__, - __PRETTY_FUNCTION__); - return NULL; /* error, not found, could not create */ - } group->group_source_list = list_new(); if (!group->group_source_list) { diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 5ccad39b3356..132fe4d56424 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -457,11 +457,6 @@ struct igmp_source *source_new(struct igmp_group *group, } src = XCALLOC(MTYPE_PIM_IGMP_GROUP_SOURCE, sizeof(*src)); - if (!src) { - zlog_warn("%s %s: XCALLOC() failure", __FILE__, - __PRETTY_FUNCTION__); - return 0; /* error, not found, could not create */ - } src->t_source_timer = NULL; src->source_group = group; /* back pointer */ @@ -491,9 +486,6 @@ static struct igmp_source *add_source_by_addr(struct igmp_sock *igmp, } src = source_new(group, src_addr); - if (!src) { - return 0; - } return src; } @@ -584,10 +576,6 @@ static void isex_excl(struct igmp_group *group, int num_sources, /* E.4: if not found, create source with timer=GMI: * (A-X-Y) */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* timer == 0 */ igmp_source_reset_gmi(group->group_igmp_sock, group, source); @@ -642,10 +630,6 @@ static void isex_incl(struct igmp_group *group, int num_sources, /* I.4: if not found, create source with timer=0 (B-A) */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* (B-A) timer=0 */ } @@ -725,10 +709,6 @@ static void toin_incl(struct igmp_group *group, int num_sources, } else { /* If not found, create new source */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } } /* (B)=GMI */ @@ -770,10 +750,6 @@ static void toin_excl(struct igmp_group *group, int num_sources, } else { /* If not found, create new source */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } } /* (A)=GMI */ @@ -859,10 +835,6 @@ static void toex_incl(struct igmp_group *group, int num_sources, /* If source not found, create source with timer=0: * (B-A)=0 */ source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* (B-A) timer=0 */ } @@ -922,10 +894,6 @@ static void toex_excl(struct igmp_group *group, int num_sources, * (A-X-Y)=Group Timer */ long group_timer_msec; source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* timer == 0 */ group_timer_msec = igmp_group_timer_remain_msec(group); @@ -1436,10 +1404,6 @@ static void block_excl(struct igmp_group *group, int num_sources, * (A-X-Y)=Group Timer */ long group_timer_msec; source = source_new(group, *src_addr); - if (!source) { - /* ugh, internal malloc failure, skip source */ - continue; - } zassert(!source->t_source_timer); /* timer == 0 */ group_timer_msec = igmp_group_timer_remain_msec(group); diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index cb70ee79046f..5bdfbab49a3d 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -69,8 +69,6 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) char hash_name[64]; pim = XCALLOC(MTYPE_PIM_PIM_INSTANCE, sizeof(struct pim_instance)); - if (!pim) - return NULL; pim_if_init(pim); diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index e798d70a5112..cfa523821aeb 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -240,11 +240,6 @@ static struct pim_msdp_sa *pim_msdp_sa_new(struct pim_instance *pim, struct pim_msdp_sa *sa; sa = XCALLOC(MTYPE_PIM_MSDP_SA, sizeof(*sa)); - if (!sa) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*sa)); - return NULL; - } sa->pim = pim; sa->sg = *sg; @@ -1069,11 +1064,6 @@ static enum pim_msdp_err pim_msdp_peer_new(struct pim_instance *pim, pim_msdp_enable(pim); mp = XCALLOC(MTYPE_PIM_MSDP_PEER, sizeof(*mp)); - if (!mp) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*mp)); - return PIM_MSDP_ERR_OOM; - } mp->pim = pim; mp->peer = peer_addr; @@ -1277,11 +1267,6 @@ static struct pim_msdp_mg *pim_msdp_mg_new(const char *mesh_group_name) struct pim_msdp_mg *mg; mg = XCALLOC(MTYPE_PIM_MSDP_MG, sizeof(*mg)); - if (!mg) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*mg)); - return NULL; - } mg->mesh_group_name = XSTRDUP(MTYPE_PIM_MSDP_MG_NAME, mesh_group_name); mg->mbr_list = list_new(); @@ -1395,13 +1380,7 @@ enum pim_msdp_err pim_msdp_mg_mbr_add(struct pim_instance *pim, } mbr = XCALLOC(MTYPE_PIM_MSDP_MG_MBR, sizeof(*mbr)); - if (!mbr) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*mbr)); - /* if there are no references to the mg free it */ - pim_msdp_mg_free(pim, mg); - return PIM_MSDP_ERR_OOM; - } + mbr->mbr_ip = mbr_ip; listnode_add_sort(mg->mbr_list, mbr); diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 20a942b4fdfd..2730f5e7aa36 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -305,11 +305,6 @@ pim_neighbor_new(struct interface *ifp, struct in_addr source_addr, zassert(pim_ifp); neigh = XCALLOC(MTYPE_PIM_NEIGHBOR, sizeof(*neigh)); - if (!neigh) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*neigh)); - return 0; - } neigh->creation = pim_time_monotonic_sec(); neigh->source_addr = source_addr; diff --git a/pimd/pim_nht.c b/pimd/pim_nht.c index fa6486a83e76..c3a02177c991 100644 --- a/pimd/pim_nht.c +++ b/pimd/pim_nht.c @@ -92,10 +92,6 @@ static struct pim_nexthop_cache *pim_nexthop_cache_add(struct pim_instance *pim, pnc = XCALLOC(MTYPE_PIM_NEXTHOP_CACHE, sizeof(struct pim_nexthop_cache)); - if (!pnc) { - zlog_err("%s: NHT PIM XCALLOC failure ", __PRETTY_FUNCTION__); - return NULL; - } pnc->rpf.rpf_addr.family = rpf_addr->rpf_addr.family; pnc->rpf.rpf_addr.prefixlen = rpf_addr->rpf_addr.prefixlen; pnc->rpf.rpf_addr.u.prefix4.s_addr = diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index fd3c04e8ca3d..209bc73cee6b 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -183,10 +183,6 @@ struct channel_oil *pim_channel_oil_add(struct pim_instance *pim, } c_oil = XCALLOC(MTYPE_PIM_CHANNEL_OIL, sizeof(*c_oil)); - if (!c_oil) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*c_oil)); - return NULL; - } c_oil->oil.mfcc_mcastgrp = sg->grp; c_oil->oil.mfcc_origin = sg->src; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index a8cf58cd363d..79b176def376 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -99,29 +99,13 @@ void pim_rp_init(struct pim_instance *pim) struct route_node *rn; pim->rp_list = list_new(); - if (!pim->rp_list) { - zlog_err("Unable to alloc rp_list"); - return; - } pim->rp_list->del = (void (*)(void *))pim_rp_info_free; pim->rp_list->cmp = pim_rp_list_cmp; pim->rp_table = route_table_init(); - if (!pim->rp_table) { - zlog_err("Unable to alloc rp_table"); - list_delete_and_null(&pim->rp_list); - return; - } rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info)); - if (!rp_info) { - zlog_err("Unable to alloc rp_info"); - route_table_finish(pim->rp_table); - list_delete_and_null(&pim->rp_list); - return; - } - if (!str2prefix("224.0.0.0/4", &rp_info->group)) { zlog_err("Unable to convert 224.0.0.0/4 to prefix"); list_delete_and_null(&pim->rp_list); @@ -137,14 +121,6 @@ void pim_rp_init(struct pim_instance *pim) listnode_add(pim->rp_list, rp_info); rn = route_node_get(pim->rp_table, &rp_info->group); - if (!rn) { - zlog_err("Failure to get route node for pim->rp_table"); - list_delete_and_null(&pim->rp_list); - route_table_finish(pim->rp_table); - XFREE(MTYPE_PIM_RP, rp_info); - return; - } - rn->info = rp_info; if (PIM_DEBUG_TRACE) zlog_debug( @@ -365,8 +341,6 @@ int pim_rp_new(struct pim_instance *pim, const char *rp, struct route_node *rn; rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info)); - if (!rp_info) - return PIM_MALLOC_FAIL; if (group_range == NULL) result = str2prefix("224.0.0.0/4", &rp_info->group); @@ -534,12 +508,6 @@ int pim_rp_new(struct pim_instance *pim, const char *rp, listnode_add_sort(pim->rp_list, rp_info); rn = route_node_get(pim->rp_table, &rp_info->group); - if (!rn) { - char buf[PREFIX_STRLEN]; - zlog_err("Failure to get route node for pim->rp_table: %s", - prefix2str(&rp_info->group, buf, sizeof(buf))); - return PIM_MALLOC_FAIL; - } rn->info = rp_info; if (PIM_DEBUG_TRACE) { diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index 8e7da0f121e8..f811707c3bff 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -369,15 +369,6 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, } ss = XCALLOC(MTYPE_PIM_SSMPINGD, sizeof(*ss)); - if (!ss) { - char source_str[INET_ADDRSTRLEN]; - pim_inet4_dump("", source_addr, source_str, - sizeof(source_str)); - zlog_err("%s: XCALLOC(%zu) failure for ssmpingd source %s", - __PRETTY_FUNCTION__, sizeof(*ss), source_str); - close(sock_fd); - return 0; - } ss->pim = pim; ss->sock_fd = sock_fd; diff --git a/pimd/pim_static.c b/pimd/pim_static.c index 3d44a01c7880..ac5ae7e497b6 100644 --- a/pimd/pim_static.c +++ b/pimd/pim_static.c @@ -42,10 +42,7 @@ static struct static_route *static_route_alloc() struct static_route *s_route; s_route = XCALLOC(MTYPE_PIM_STATIC_ROUTE, sizeof(*s_route)); - if (!s_route) { - zlog_err("PIM XCALLOC(%zu) failure", sizeof(*s_route)); - return 0; - } + return s_route; } diff --git a/pimd/pim_upstream.c b/pimd/pim_upstream.c index 9329d72ce055..e3488b6a66d7 100644 --- a/pimd/pim_upstream.c +++ b/pimd/pim_upstream.c @@ -603,11 +603,6 @@ static struct pim_upstream *pim_upstream_new(struct pim_instance *pim, struct pim_upstream *up; up = XCALLOC(MTYPE_PIM_UPSTREAM, sizeof(*up)); - if (!up) { - zlog_err("%s: PIM XCALLOC(%zu) failure", __PRETTY_FUNCTION__, - sizeof(*up)); - return NULL; - } up->sg = *sg; pim_str_sg_set(sg, up->sg_str); diff --git a/pimd/pimd.h b/pimd/pimd.h index 840e0d7e348b..1b11dc3f7390 100644 --- a/pimd/pimd.h +++ b/pimd/pimd.h @@ -117,7 +117,6 @@ /* PIM error codes */ #define PIM_SUCCESS 0 -#define PIM_MALLOC_FAIL -1 #define PIM_GROUP_BAD_ADDRESS -2 #define PIM_GROUP_OVERLAP -3 #define PIM_GROUP_PFXLIST_OVERLAP -4 diff --git a/ripd/ripd.c b/ripd/ripd.c index 92c27106d583..ec9b04edff6f 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -2800,15 +2800,9 @@ DEFUN_NOSH (router_rip, "Enable a routing process\n" "Routing Information Protocol (RIP)\n") { - int ret; - /* If rip is not enabled before. */ if (!rip) { - ret = rip_create(); - if (ret < 0) { - zlog_info("Can't create RIP"); - return CMD_WARNING_CONFIG_FAILED; - } + rip_create(); } VTY_PUSH_CONTEXT(RIP_NODE, rip); diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 63553469ddf5..bea1592a9919 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2285,6 +2285,21 @@ DEFUN (vtysh_show_debugging_hashtable, "Hashtable statistics for %s:\n"); } +DEFUN (vtysh_show_error_code, + vtysh_show_error_code_cmd, + "show error (0-4294967296)", + SHOW_STR + "Information on errors\n" + "Error code to get info about\n") +{ + char cmd[256]; + + snprintf(cmd, sizeof(cmd), "do show error %s", argv[2]->arg); + + /* FIXME: Needs to determine which daemon to send to via code ranges */ + return show_per_daemon(cmd, ""); +} + /* Memory */ DEFUN (vtysh_show_memory, vtysh_show_memory_cmd, @@ -3707,6 +3722,7 @@ void vtysh_init_vty(void) /* debugging */ install_element(VIEW_NODE, &vtysh_show_debugging_cmd); + install_element(VIEW_NODE, &vtysh_show_error_code_cmd); install_element(VIEW_NODE, &vtysh_show_debugging_hashtable_cmd); install_element(ENABLE_NODE, &vtysh_debug_all_cmd); install_element(CONFIG_NODE, &vtysh_debug_all_cmd); diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c index 6cf98e85f58d..64412fba9262 100644 --- a/zebra/if_ioctl_solaris.c +++ b/zebra/if_ioctl_solaris.c @@ -34,6 +34,7 @@ #include "privs.h" #include "vrf.h" #include "vty.h" +#include "lib_errors.h" #include "zebra/interface.h" #include "zebra/ioctl_solaris.h" @@ -59,7 +60,7 @@ static int interface_list_ioctl(int af) char *buf = NULL; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sock = socket(af, SOCK_DGRAM, 0); if (sock < 0) { @@ -68,7 +69,7 @@ static int interface_list_ioctl(int af) safe_strerror(errno)); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); return -1; } @@ -80,7 +81,7 @@ static int interface_list_ioctl(int af) save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret < 0) { zlog_warn("interface_list_ioctl: SIOCGLIFNUM failed %s", @@ -100,11 +101,7 @@ static int interface_list_ioctl(int af) if (needed > lastneeded || needed < lastneeded / 2) { if (buf != NULL) XFREE(MTYPE_TMP, buf); - if ((buf = XMALLOC(MTYPE_TMP, needed)) == NULL) { - zlog_warn("interface_list_ioctl: malloc failed"); - close(sock); - return -1; - } + buf = XMALLOC(MTYPE_TMP, needed); } lastneeded = needed; @@ -114,7 +111,7 @@ static int interface_list_ioctl(int af) lifconf.lifc_buf = buf; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ret = ioctl(sock, SIOCGLIFCONF, &lifconf); @@ -126,13 +123,13 @@ static int interface_list_ioctl(int af) zlog_warn("SIOCGLIFCONF: %s", safe_strerror(errno)); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); goto end; } if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); /* Allocate interface. */ lifreq = lifconf.lifc_req; diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index e6d324ab6a64..1667b8f9b55b 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -52,6 +52,7 @@ #include "vrf.h" #include "vrf_int.h" #include "mpls.h" +#include "lib_errors.h" #include "vty.h" #include "zebra/zserv.h" @@ -374,7 +375,7 @@ static int get_iflink_speed(struct interface *interface) /* use ioctl to get IP address of an interface */ if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP, interface->vrf_id, NULL); if (sd < 0) { @@ -386,7 +387,7 @@ static int get_iflink_speed(struct interface *interface) /* Get the current link state for the interface */ rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL, (char *)&ifdata); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (rc < 0) { if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( diff --git a/zebra/ioctl.c b/zebra/ioctl.c index a577b008d5b4..981393965f36 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -27,6 +27,7 @@ #include "ioctl.h" #include "log.h" #include "privs.h" +#include "lib_errors.h" #include "vty.h" #include "zebra/rib.h" @@ -55,13 +56,13 @@ int if_ioctl(unsigned long request, caddr_t buffer) int err = 0; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { int save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_err("Cannot create UDP socket: %s", safe_strerror(save_errno)); exit(1); @@ -69,7 +70,7 @@ int if_ioctl(unsigned long request, caddr_t buffer) if ((ret = ioctl(sock, request, buffer)) < 0) err = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); close(sock); if (ret < 0) { @@ -87,13 +88,13 @@ int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id) int err = 0; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sock = vrf_socket(AF_INET, SOCK_DGRAM, 0, vrf_id, NULL); if (sock < 0) { int save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_err("Cannot create UDP socket: %s", safe_strerror(save_errno)); exit(1); @@ -102,7 +103,7 @@ int vrf_if_ioctl(unsigned long request, caddr_t buffer, vrf_id_t vrf_id) if (ret < 0) err = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); close(sock); if (ret < 0) { @@ -120,13 +121,13 @@ static int if_ioctl_ipv6(unsigned long request, caddr_t buffer) int err = 0; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) { int save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_err("Cannot create IPv6 datagram socket: %s", safe_strerror(save_errno)); exit(1); @@ -135,7 +136,7 @@ static int if_ioctl_ipv6(unsigned long request, caddr_t buffer) if ((ret = ioctl(sock, request, buffer)) < 0) err = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); close(sock); if (ret < 0) { diff --git a/zebra/ioctl_solaris.c b/zebra/ioctl_solaris.c index eb68451f7ca3..24f5fde7943f 100644 --- a/zebra/ioctl_solaris.c +++ b/zebra/ioctl_solaris.c @@ -31,6 +31,7 @@ #include "privs.h" #include "vty.h" #include "vrf.h" +#include "lib_errors.h" #include "zebra/rib.h" #include "zebra/rt.h" @@ -58,13 +59,13 @@ int if_ioctl(unsigned long request, caddr_t buffer) int err; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sock = socket(AF_INET, SOCK_DGRAM, 0); if (sock < 0) { int save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_err("Cannot create UDP socket: %s", safe_strerror(save_errno)); exit(1); @@ -74,7 +75,7 @@ int if_ioctl(unsigned long request, caddr_t buffer) err = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); close(sock); @@ -93,13 +94,13 @@ int if_ioctl_ipv6(unsigned long request, caddr_t buffer) int err; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) { int save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_err("Cannot create IPv6 datagram socket: %s", safe_strerror(save_errno)); exit(1); @@ -109,7 +110,7 @@ int if_ioctl_ipv6(unsigned long request, caddr_t buffer) err = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); close(sock); diff --git a/zebra/ipforward_proc.c b/zebra/ipforward_proc.c index f823ec4384c9..feafbb27cfcd 100644 --- a/zebra/ipforward_proc.c +++ b/zebra/ipforward_proc.c @@ -25,6 +25,7 @@ #include "log.h" #include "privs.h" +#include "lib_errors.h" #include "zebra/ipforward.h" @@ -77,14 +78,16 @@ int ipforward_on(void) FILE *fp; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges, %s", + safe_strerror(errno)); fp = fopen(proc_ipv4_forwarding, "w"); if (fp == NULL) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "Can't lower privileges, %s", + safe_strerror(errno)); return -1; } @@ -93,7 +96,8 @@ int ipforward_on(void) fclose(fp); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges, %s", + safe_strerror(errno)); return ipforward(); } @@ -103,14 +107,16 @@ int ipforward_off(void) FILE *fp; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges, %s", + safe_strerror(errno)); fp = fopen(proc_ipv4_forwarding, "w"); if (fp == NULL) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "Can't lower privileges, %s", + safe_strerror(errno)); return -1; } @@ -119,7 +125,8 @@ int ipforward_off(void) fclose(fp); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges, %s", + safe_strerror(errno)); return ipforward(); } @@ -154,14 +161,16 @@ int ipforward_ipv6_on(void) FILE *fp; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges, %s", + safe_strerror(errno)); fp = fopen(proc_ipv6_forwarding, "w"); if (fp == NULL) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "Can't lower privileges, %s", + safe_strerror(errno)); return -1; } @@ -170,7 +179,8 @@ int ipforward_ipv6_on(void) fclose(fp); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges, %s", + safe_strerror(errno)); return ipforward_ipv6(); } @@ -181,14 +191,16 @@ int ipforward_ipv6_off(void) FILE *fp; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges, %s", + safe_strerror(errno)); fp = fopen(proc_ipv6_forwarding, "w"); if (fp == NULL) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "Can't lower privileges, %s", + safe_strerror(errno)); return -1; } @@ -197,7 +209,8 @@ int ipforward_ipv6_off(void) fclose(fp); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges, %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges, %s", + safe_strerror(errno)); return ipforward_ipv6(); } diff --git a/zebra/ipforward_solaris.c b/zebra/ipforward_solaris.c index 123cf1bd081b..36e2211dae1f 100644 --- a/zebra/ipforward_solaris.c +++ b/zebra/ipforward_solaris.c @@ -25,6 +25,7 @@ #include "log.h" #include "prefix.h" +#include "lib_errors.h" #include "privs.h" #include "zebra/ipforward.h" @@ -82,18 +83,21 @@ static int solaris_nd(const int cmd, const char *parameter, const int value) strioctl.ic_dp = nd_buf; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("solaris_nd: Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "solaris_nd: Can't raise privileges"); if ((fd = open(device, O_RDWR)) < 0) { zlog_warn("failed to open device %s - %s", device, safe_strerror(errno)); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("solaris_nd: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "solaris_nd: Can't lower privileges"); return -1; } if (ioctl(fd, I_STR, &strioctl) < 0) { int save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("solaris_nd: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "solaris_nd: Can't lower privileges"); close(fd); zlog_warn("ioctl I_STR failed on device %s - %s", device, safe_strerror(save_errno)); @@ -101,7 +105,8 @@ static int solaris_nd(const int cmd, const char *parameter, const int value) } close(fd); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("solaris_nd: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "solaris_nd: Can't lower privileges"); if (cmd == ND_GET) { errno = 0; diff --git a/zebra/ipforward_sysctl.c b/zebra/ipforward_sysctl.c index cdf426b9b8ff..8e34ed73bc36 100644 --- a/zebra/ipforward_sysctl.c +++ b/zebra/ipforward_sysctl.c @@ -26,6 +26,7 @@ #include "zebra/ipforward.h" #include "log.h" +#include "lib_errors.h" #define MIB_SIZ 4 @@ -54,15 +55,15 @@ int ipforward_on(void) len = sizeof ipforwarding; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_warn("Can't set ipforwarding on"); return -1; } if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); return ipforwarding; } @@ -73,15 +74,15 @@ int ipforward_off(void) len = sizeof ipforwarding; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_warn("Can't set ipforwarding on"); return -1; } if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); return ipforwarding; } @@ -101,15 +102,15 @@ int ipforward_ipv6(void) len = sizeof ip6forwarding; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); if (sysctl(mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_warn("can't get ip6forwarding value"); return -1; } if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); return ip6forwarding; } @@ -120,15 +121,15 @@ int ipforward_ipv6_on(void) len = sizeof ip6forwarding; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_warn("can't get ip6forwarding value"); return -1; } if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); return ip6forwarding; } @@ -139,15 +140,15 @@ int ipforward_ipv6_off(void) len = sizeof ip6forwarding; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); zlog_warn("can't get ip6forwarding value"); return -1; } if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); return ip6forwarding; } diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 0e79b8253319..316eadabd38f 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -36,6 +36,7 @@ #include "nexthop.h" #include "vrf.h" #include "mpls.h" +#include "lib_errors.h" #include "zebra/zserv.h" #include "zebra/zebra_ns.h" @@ -164,11 +165,13 @@ static int netlink_recvbuf(struct nlsock *nl, uint32_t newsize) /* Try force option (linux >= 2.6.14) and fall back to normal set */ if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("routing_socket: Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't raise privileges"); ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUFFORCE, &nl_rcvbufsize, sizeof(nl_rcvbufsize)); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("routing_socket: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't lower privileges"); if (ret < 0) ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &nl_rcvbufsize, sizeof(nl_rcvbufsize)); @@ -201,7 +204,7 @@ static int netlink_socket(struct nlsock *nl, unsigned long groups, int save_errno; if (zserv_privs.change(ZPRIVS_RAISE)) { - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); return -1; } @@ -220,7 +223,7 @@ static int netlink_socket(struct nlsock *nl, unsigned long groups, ret = bind(sock, (struct sockaddr *)&snl, sizeof snl); save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret < 0) { zlog_err("Can't bind %s socket to group 0x%x: %s", nl->name, @@ -761,11 +764,11 @@ int netlink_talk(int (*filter)(struct nlmsghdr *, ns_id_t, int startup), /* Send message to netlink interface. */ if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); status = sendmsg(nl->sock, &msg, 0); save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) { zlog_debug("%s: >> netlink message dump [sent]", __func__); @@ -811,7 +814,7 @@ int netlink_request(struct nlsock *nl, struct nlmsghdr *n) /* Raise capabilities and send message, then lower capabilities. */ if (zserv_privs.change(ZPRIVS_RAISE)) { - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); return -1; } @@ -820,7 +823,7 @@ int netlink_request(struct nlsock *nl, struct nlmsghdr *n) save_errno = errno; if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret < 0) { zlog_err("%s sendto failed: %s", nl->name, diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index b85c4748c4c1..2b18bdc34806 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -39,6 +39,7 @@ #include "rib.h" #include "privs.h" #include "vrf.h" +#include "lib_errors.h" #include "zebra/rt.h" #include "zebra/interface.h" @@ -1383,14 +1384,16 @@ static int kernel_read(struct thread *thread) static void routing_socket(struct zebra_ns *zns) { if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("routing_socket: Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't raise privileges"); routing_sock = ns_socket(AF_ROUTE, SOCK_RAW, 0, zns->ns_id); if (routing_sock < 0) { if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("routing_socket: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't lower privileges"); zlog_warn("Can't init kernel routing socket"); return; } @@ -1403,7 +1406,8 @@ static void routing_socket(struct zebra_ns *zns) zlog_warn ("Can't set O_NONBLOCK to routing socket");*/ if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("routing_socket: Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "routing_socket: Can't lower privileges"); /* kernel_read needs rewrite. */ thread_add_read(zebrad.master, kernel_read, NULL, routing_sock, NULL); diff --git a/zebra/label_manager.c b/zebra/label_manager.c index b24a4b68dc0d..f2f89fdebe6a 100644 --- a/zebra/label_manager.c +++ b/zebra/label_manager.c @@ -384,8 +384,6 @@ struct label_manager_chunk *assign_label_chunk(uint8_t proto, } /* otherwise create a new one */ lmc = XCALLOC(MTYPE_LM_CHUNK, sizeof(struct label_manager_chunk)); - if (!lmc) - return NULL; if (list_isempty(lbl_mgr.lc_list)) lmc->start = MPLS_LABEL_UNRESERVED_MIN; diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index 3380f225c0a3..3a7228e55ffc 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -33,6 +33,7 @@ #include "log.h" #include "privs.h" #include "vxlan.h" +#include "lib_errors.h" #include "zebra/debug.h" #include "zebra/rib.h" @@ -399,7 +400,7 @@ enum dp_req_result kernel_route_rib(struct route_node *rn, } if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); if (old) route |= kernel_rtm(RTM_DELETE, p, old); @@ -408,7 +409,7 @@ enum dp_req_result kernel_route_rib(struct route_node *rn, route |= kernel_rtm(RTM_ADD, p, new); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (new) { kernel_route_rib_pass_fail( diff --git a/zebra/zebra_mpls.c b/zebra/zebra_mpls.c index fe0837a63a75..a02e61991072 100644 --- a/zebra/zebra_mpls.c +++ b/zebra/zebra_mpls.c @@ -549,8 +549,6 @@ static zebra_fec_t *fec_add(struct route_table *table, struct prefix *p, if (!fec) { fec = XCALLOC(MTYPE_FEC, sizeof(zebra_fec_t)); - if (!fec) - return NULL; rn->info = fec; fec->rn = rn; @@ -1178,8 +1176,6 @@ static zebra_nhlfe_t *nhlfe_add(zebra_lsp_t *lsp, enum lsp_types_t lsp_type, return NULL; nhlfe = XCALLOC(MTYPE_NHLFE, sizeof(zebra_nhlfe_t)); - if (!nhlfe) - return NULL; nhlfe->lsp = lsp; nhlfe->type = lsp_type; diff --git a/zebra/zebra_mpls_openbsd.c b/zebra/zebra_mpls_openbsd.c index 412fe7d3dd3f..c684167e386a 100644 --- a/zebra/zebra_mpls_openbsd.c +++ b/zebra/zebra_mpls_openbsd.c @@ -31,6 +31,7 @@ #include "prefix.h" #include "interface.h" #include "log.h" +#include "lib_errors.h" extern struct zebra_privs_t zserv_privs; @@ -117,10 +118,10 @@ static int kernel_send_rtmsg_v4(int action, mpls_label_t in_label, } if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ret = writev(kr_state.fd, iov, iovcnt); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret == -1) zlog_err("%s: %s", __func__, safe_strerror(errno)); @@ -225,10 +226,10 @@ static int kernel_send_rtmsg_v6(int action, mpls_label_t in_label, } if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ret = writev(kr_state.fd, iov, iovcnt); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret == -1) zlog_err("%s: %s", __func__, safe_strerror(errno)); diff --git a/zebra/zebra_netns_notify.c b/zebra/zebra_netns_notify.c index 30f850597c65..4c60d844e273 100644 --- a/zebra/zebra_netns_notify.c +++ b/zebra/zebra_netns_notify.c @@ -34,6 +34,7 @@ #include "ns.h" #include "command.h" #include "memory.h" +#include "lib_errors.h" #include "zserv.h" #include "zebra_memory.h" @@ -76,10 +77,10 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name) return; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ns_id = zebra_ns_id_get(netnspath); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); ns_id_external = ns_map_nsid_with_external(ns_id, true); /* if VRF with NS ID already present */ vrf = vrf_lookup_by_id((vrf_id_t)ns_id_external); @@ -95,11 +96,11 @@ static void zebra_ns_notify_create_context_from_entry_name(const char *name) return; } if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ret = vrf_netns_handler_create(NULL, vrf, netnspath, ns_id_external, ns_id); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (ret != CMD_SUCCESS) { zlog_warn("NS notify : failed to create NS %s", netnspath); ns_map_nsid_with_external(ns_id, false); @@ -166,19 +167,19 @@ static int zebra_ns_ready_read(struct thread *t) if (--zns_info->retries == 0) stop_retry = 1; if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); err = ns_switch_to_netns(netnspath); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (err < 0) return zebra_ns_continue_read(zns_info, stop_retry); /* go back to default ns */ if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); err = ns_switchback_to_initial(); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); if (err < 0) return zebra_ns_continue_read(zns_info, stop_retry); diff --git a/zebra/zebra_ns.c b/zebra/zebra_ns.c index 25e68cc081a8..8676d3aec800 100644 --- a/zebra/zebra_ns.c +++ b/zebra/zebra_ns.c @@ -26,6 +26,7 @@ #include "lib/logicalrouter.h" #include "lib/prefix.h" #include "lib/memory.h" +#include "lib/lib_errors.h" #include "rtadv.h" #include "zebra_ns.h" @@ -315,10 +316,10 @@ int zebra_ns_init(void) dzns = zebra_ns_alloc(); if (zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ns_id = zebra_ns_id_get_default(); if (zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); ns_id_external = ns_map_nsid_with_external(ns_id, true); ns_init_management(ns_id_external, ns_id); diff --git a/zebra/zebra_rib.c b/zebra/zebra_rib.c index 879e7e831769..075cf2b8a10a 100644 --- a/zebra/zebra_rib.c +++ b/zebra/zebra_rib.c @@ -1967,7 +1967,6 @@ static struct meta_queue *meta_queue_new(void) unsigned i; new = XCALLOC(MTYPE_WORK_QUEUE, sizeof(struct meta_queue)); - assert(new); for (i = 0; i < MQ_SIZE; i++) { new->subq[i] = list_new(); diff --git a/zebra/zebra_routemap.c b/zebra/zebra_routemap.c index 10ba88880a89..b9edc84f2614 100644 --- a/zebra/zebra_routemap.c +++ b/zebra/zebra_routemap.c @@ -1096,9 +1096,6 @@ static void *route_match_address_prefix_len_compile(const char *arg) prefix_len = XMALLOC(MTYPE_ROUTE_MAP_COMPILED, sizeof(uint32_t)); - if (!prefix_len) - return prefix_len; - *prefix_len = tmpval; return prefix_len; } diff --git a/zebra/zebra_vxlan.c b/zebra/zebra_vxlan.c index 59f0cf52f0a1..7e9fd74de287 100644 --- a/zebra/zebra_vxlan.c +++ b/zebra/zebra_vxlan.c @@ -2953,10 +2953,6 @@ static zebra_vtep_t *zvni_vtep_add(zebra_vni_t *zvni, struct in_addr *vtep_ip) zebra_vtep_t *zvtep; zvtep = XCALLOC(MTYPE_ZVNI_VTEP, sizeof(zebra_vtep_t)); - if (!zvtep) { - zlog_err("Failed to alloc VTEP entry, VNI %u", zvni->vni); - return NULL; - } zvtep->vtep_ip = *vtep_ip; diff --git a/zebra/zserv.c b/zebra/zserv.c index a099cfc057dd..1f3eb13796f0 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -54,6 +54,7 @@ #include "lib/zclient.h" /* for zmsghdr, ZEBRA_HEADER_SIZE, ZEBRA... */ #include "lib/frr_pthread.h" /* for frr_pthread_new, frr_pthread_stop... */ #include "lib/frratomic.h" /* for atomic_load_explicit, atomic_stor... */ +#include "lib/lib_errors.h" /* for generic ferr ids */ #include "zebra/debug.h" /* for various debugging macros */ #include "zebra/rib.h" /* for rib_score_proto */ @@ -776,7 +777,7 @@ void zserv_start(char *path) zserv_privs.change(ZPRIVS_LOWER); if (sa.ss_family != AF_UNIX && zserv_privs.change(ZPRIVS_RAISE)) - zlog_err("Can't raise privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't raise privileges"); ret = bind(zebrad.sock, (struct sockaddr *)&sa, sa_len); if (ret < 0) { @@ -789,7 +790,7 @@ void zserv_start(char *path) return; } if (sa.ss_family != AF_UNIX && zserv_privs.change(ZPRIVS_LOWER)) - zlog_err("Can't lower privileges"); + zlog_ferr(LIB_ERR_PRIVILEGES, "Can't lower privileges"); ret = listen(zebrad.sock, 5); if (ret < 0) {