From 5c777139a0e81dc9cd541e4c77facc244b5b1f1b Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 08:49:36 -0400 Subject: [PATCH 01/14] lib, zebra: Add LIB_ERR_INTERFACE Add a error type that allows us to track bad interface states. Signed-off-by: Donald Sharp --- lib/if.c | 1 + lib/if.h | 12 ++++++++---- lib/lib_errors.c | 6 ++++++ lib/lib_errors.h | 1 + zebra/if_ioctl.c | 8 +++++--- zebra/if_netlink.c | 24 +++++++++++++----------- zebra/interface.c | 4 +++- 7 files changed, 37 insertions(+), 19 deletions(-) diff --git a/lib/if.c b/lib/if.c index 2541e6e45aff..c93ddaeb35c0 100644 --- a/lib/if.c +++ b/lib/if.c @@ -23,6 +23,7 @@ #include "linklist.h" #include "vector.h" +#include "lib_errors.h" #include "vty.h" #include "command.h" #include "vrf.h" diff --git a/lib/if.h b/lib/if.h index 7b65bbd2e55a..4379e1ad8c35 100644 --- a/lib/if.h +++ b/lib/if.h @@ -297,28 +297,32 @@ DECLARE_QOBJ_TYPE(interface) #define IFNAME_RB_INSERT(vrf, ifp) \ if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp))) \ - zlog_err( \ + zlog_ferr( \ + LIB_ERR_INTERFACE, \ "%s(%s): corruption detected -- interface with this " \ "name exists already in VRF %u!", \ __func__, (ifp)->name, (ifp)->vrf_id); #define IFNAME_RB_REMOVE(vrf, ifp) \ if (RB_REMOVE(if_name_head, &vrf->ifaces_by_name, (ifp)) == NULL) \ - zlog_err( \ + zlog_ferr( \ + LIB_ERR_INTERFACE, \ "%s(%s): corruption detected -- interface with this " \ "name doesn't exist in VRF %u!", \ __func__, (ifp)->name, (ifp)->vrf_id); #define IFINDEX_RB_INSERT(vrf, ifp) \ if (RB_INSERT(if_index_head, &vrf->ifaces_by_index, (ifp))) \ - zlog_err( \ + zlog_ferr( \ + LIB_ERR_INTERFACE, \ "%s(%u): corruption detected -- interface with this " \ "ifindex exists already in VRF %u!", \ __func__, (ifp)->ifindex, (ifp)->vrf_id); #define IFINDEX_RB_REMOVE(vrf, ifp) \ if (RB_REMOVE(if_index_head, &vrf->ifaces_by_index, (ifp)) == NULL) \ - zlog_err( \ + zlog_ferr( \ + LIB_ERR_INTERFACE, \ "%s(%u): corruption detected -- interface with this " \ "ifindex doesn't exist in VRF %u!", \ __func__, (ifp)->ifindex, (ifp)->vrf_id); diff --git a/lib/lib_errors.c b/lib/lib_errors.c index 44d9ecd0337f..d1db7b777a2d 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -76,6 +76,12 @@ static struct ferr_ref ferr_lib_err[] = { .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 = LIB_ERR_INTERFACE, + .title = "Interface Subsystem Error", + .description = "FRR has detected a problem with interface data from the kernel as it deviates\nfrom what we would expect to happen via normal netlink messaging", + .suggestion = "Open an Issue with all relevant log files and restart FRR" + }, { .code = END_FERR, } diff --git a/lib/lib_errors.h b/lib/lib_errors.h index 671c768eb900..67feb68827c9 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -33,6 +33,7 @@ enum lib_ferr_refs { LIB_ERR_SYSTEM_CALL, LIB_ERR_VTY, LIB_ERR_SNMP, + LIB_ERR_INTERFACE, }; extern void lib_error_init(void); diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index f5ed9455279c..8e2e64edc60f 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -181,7 +181,8 @@ static int if_getaddrs(void) for (ifapfree = ifap; ifap; ifap = ifap->ifa_next) { if (ifap->ifa_addr == NULL) { - zlog_err( + zlog_ferr( + LIB_ERR_INTERFACE, "%s: nonsensical ifaddr with NULL ifa_addr, ifname %s", __func__, (ifap->ifa_name ? ifap->ifa_name : "(null)")); @@ -190,8 +191,9 @@ static int if_getaddrs(void) ifp = if_lookup_by_name(ifap->ifa_name, VRF_DEFAULT); if (ifp == NULL) { - zlog_err("if_getaddrs(): Can't lookup interface %s\n", - ifap->ifa_name); + zlog_ferr(LIB_ERR_INTERFACE, + "if_getaddrs(): Can't lookup interface %s\n", + ifap->ifa_name); continue; } diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index 1667b8f9b55b..7154903cff2e 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -80,9 +80,9 @@ static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, if (((oifp = if_lookup_by_index_per_ns(zns, ifi_index)) != NULL) && (oifp != ifp)) { if (ifi_index == IFINDEX_INTERNAL) - zlog_err( - "Netlink is setting interface %s ifindex to reserved " - "internal value %u", + zlog_ferr( + LIB_ERR_INTERFACE, + "Netlink is setting interface %s ifindex to reserved internal value %u", ifp->name, ifi_index); else { if (IS_ZEBRA_DEBUG_KERNEL) @@ -90,9 +90,9 @@ static void set_ifindex(struct interface *ifp, ifindex_t ifi_index, "interface index %d was renamed from %s to %s", ifi_index, oifp->name, ifp->name); if (if_is_up(oifp)) - zlog_err( - "interface rename detected on up interface: index %d " - "was renamed from %s to %s, results are uncertain!", + zlog_ferr( + LIB_ERR_INTERFACE, + "interface rename detected on up interface: index %d was renamed from %s to %s, results are uncertain!", ifi_index, oifp->name, ifp->name); if_delete_update(oifp); } @@ -310,8 +310,8 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, vrf = vrf_get((vrf_id_t)ifi->ifi_index, name); // It would create vrf if (!vrf) { - zlog_err("VRF %s id %u not created", name, - ifi->ifi_index); + zlog_ferr(LIB_ERR_INTERFACE, "VRF %s id %u not created", + name, ifi->ifi_index); return; } @@ -332,8 +332,9 @@ static void netlink_vrf_change(struct nlmsghdr *h, struct rtattr *tb, /* Enable the created VRF. */ if (!vrf_enable(vrf)) { - zlog_err("Failed to enable VRF %s id %u", name, - ifi->ifi_index); + zlog_ferr(LIB_ERR_INTERFACE, + "Failed to enable VRF %s id %u", name, + ifi->ifi_index); return; } @@ -902,7 +903,8 @@ int netlink_interface_addr(struct nlmsghdr *h, ns_id_t ns_id, int startup) ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index); if (ifp == NULL) { - zlog_err( + zlog_ferr( + LIB_ERR_INTERFACE, "netlink_interface_addr can't find interface by index %d", ifa->ifa_index); return -1; diff --git a/zebra/interface.c b/zebra/interface.c index 7de18d683c1b..dbf9add9f2e9 100644 --- a/zebra/interface.c +++ b/zebra/interface.c @@ -22,6 +22,7 @@ #include #include "if.h" +#include "lib_errors.h" #include "vty.h" #include "sockunion.h" #include "prefix.h" @@ -720,7 +721,8 @@ void if_delete_update(struct interface *ifp) struct zebra_if *zif; if (if_is_up(ifp)) { - zlog_err( + zlog_ferr( + LIB_ERR_INTERFACE, "interface %s vrf %u index %d is still up while being deleted.", ifp->name, ifp->vrf_id, ifp->ifindex); return; From 9d36bf3d9321132f7440e62a61a2301f9f80cbc5 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 08:55:06 -0400 Subject: [PATCH 02/14] lib: Add LIB_ERR_NS to error subsystem Add additional information about NameSpace errors that may happen. Signed-off-by: Donald Sharp --- lib/lib_errors.c | 6 ++++++ lib/lib_errors.h | 1 + lib/netns_linux.c | 16 ++++++++++------ 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/lib/lib_errors.c b/lib/lib_errors.c index d1db7b777a2d..71ff53053eee 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -82,6 +82,12 @@ static struct ferr_ref ferr_lib_err[] = { .description = "FRR has detected a problem with interface data from the kernel as it deviates\nfrom what we would expect to happen via normal netlink messaging", .suggestion = "Open an Issue with all relevant log files and restart FRR" }, + { + .code = LIB_ERR_NS, + .title = "NameSpace Subsystem Error", + .description = "FRR has detected a problem with NameSpace data from the kernel as it deviates\nfrom what we would expect to happen via normal kernel messaging", + .suggestion = "Open an Issue with all relevant log files and restart FRR" + }, { .code = END_FERR, } diff --git a/lib/lib_errors.h b/lib/lib_errors.h index 67feb68827c9..e4ab88e994e5 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -34,6 +34,7 @@ enum lib_ferr_refs { LIB_ERR_VTY, LIB_ERR_SNMP, LIB_ERR_INTERFACE, + LIB_ERR_NS, }; extern void lib_error_init(void); diff --git a/lib/netns_linux.c b/lib/netns_linux.c index e9a619893e1a..460bb20460bb 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -227,8 +227,9 @@ static int ns_enable_internal(struct ns *ns, void (*func)(ns_id_t, void *)) /* Non default NS. leave */ if (ns->ns_id == NS_UNKNOWN) { - zlog_err("Can not enable NS %s %u: Invalid NSID", - ns->name, ns->ns_id); + zlog_ferr(LIB_ERR_NS, + "Can not enable NS %s %u: Invalid NSID", + ns->name, ns->ns_id); return 0; } if (func) @@ -468,8 +469,9 @@ void ns_init(void) if (have_netns_enabled < 0) { ns_default_ns_fd = open(NS_DEFAULT_NAME, O_RDONLY); if (ns_default_ns_fd == -1) - zlog_err("NS initialization failure %d(%s)", - errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_NS, + "NS initialization failure %d(%s)", errno, + safe_strerror(errno)); } else { ns_default_ns_fd = -1; default_ns = NULL; @@ -490,7 +492,8 @@ void ns_init_management(ns_id_t default_ns_id, ns_id_t internal_ns) ns_init(); default_ns = ns_get_created_internal(NULL, NULL, default_ns_id); if (!default_ns) { - zlog_err("%s: failed to create the default NS!", __func__); + zlog_ferr(LIB_ERR_NS, "%s: failed to create the default NS!", + __func__); exit(1); } if (have_netns()) { @@ -507,7 +510,8 @@ void ns_init_management(ns_id_t default_ns_id, ns_id_t internal_ns) /* Enable the default NS. */ if (!ns_enable(default_ns, NULL)) { - zlog_err("%s: failed to enable the default NS!", __func__); + zlog_ferr(LIB_ERR_NS, "%s: failed to enable the default NS!", + __func__); exit(1); } } From d5f2c4598928af6e252fc26e671b77bf483763fa Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 09:13:37 -0400 Subject: [PATCH 03/14] lib: Add LIB_ERR_DEVELOPMENT Sometimes a error state is detected when we have added new code to FRR, but not updated all the places that we should have. Consider this a developmental escape that needs to be fixed. Signed-off-by: Donald Sharp --- lib/buffer.c | 6 +++--- lib/lib_errors.c | 6 ++++++ lib/lib_errors.h | 2 +- lib/log.c | 10 +++++++--- lib/prefix.c | 6 ++++-- lib/skiplist.c | 4 +++- lib/vty.c | 6 +++--- 7 files changed, 27 insertions(+), 13 deletions(-) diff --git a/lib/buffer.c b/lib/buffer.c index 207f2320ff58..acdaf07bbc1a 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -458,9 +458,9 @@ in one shot. */ while (written > 0) { struct buffer_data *d; if (!(d = b->head)) { - zlog_err( - "%s: corruption detected: buffer queue empty, " - "but written is %lu", + zlog_ferr( + LIB_ERR_DEVELOPMENT, + "%s: corruption detected: buffer queue empty, but written is %lu", __func__, (unsigned long)written); break; } diff --git a/lib/lib_errors.c b/lib/lib_errors.c index 71ff53053eee..ae4635673f26 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -88,6 +88,12 @@ static struct ferr_ref ferr_lib_err[] = { .description = "FRR has detected a problem with NameSpace data from the kernel as it deviates\nfrom what we would expect to happen via normal kernel messaging", .suggestion = "Open an Issue with all relevant log files and restart FRR" }, + { + .code = LIB_ERR_DEVELOPMENT, + .title = "Developmental Escape Error", + .description = "FRR has detected an issue where new development has not properly\nupdated all code paths.", + .suggestion = "Open an Issue with all relevant log files" + }, { .code = END_FERR, } diff --git a/lib/lib_errors.h b/lib/lib_errors.h index e4ab88e994e5..bb83c45e67d7 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -21,7 +21,6 @@ #define __LIB_ERRORS_H__ #include "ferr.h" -#include "lib_errors.h" enum lib_ferr_refs { LIB_ERR_PRIVILEGES = LIB_FERR_START, @@ -35,6 +34,7 @@ enum lib_ferr_refs { LIB_ERR_SNMP, LIB_ERR_INTERFACE, LIB_ERR_NS, + LIB_ERR_DEVELOPMENT, }; extern void lib_error_init(void); diff --git a/lib/log.c b/lib/log.c index afecbef19cd6..6aa718c953a5 100644 --- a/lib/log.c +++ b/lib/log.c @@ -987,7 +987,8 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute) unsigned int i; if (zroute >= array_size(route_types)) { - zlog_err("unknown zebra route type: %u", zroute); + zlog_ferr(LIB_ERR_DEVELOPMENT, "unknown zebra route type: %u", + zroute); return &unknown; } if (zroute == route_types[zroute].type) @@ -1001,7 +1002,9 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute) return &route_types[i]; } } - zlog_err("internal error: cannot find route type %u in table!", zroute); + zlog_ferr(LIB_ERR_DEVELOPMENT, + "internal error: cannot find route type %u in table!", + zroute); return &unknown; } @@ -1018,7 +1021,8 @@ char zebra_route_char(unsigned int zroute) const char *zserv_command_string(unsigned int command) { if (command >= array_size(command_types)) { - zlog_err("unknown zserv command type: %u", command); + zlog_ferr(LIB_ERR_DEVELOPMENT, "unknown zserv command type: %u", + command); return unknown.string; } return command_types[command].string; diff --git a/lib/prefix.c b/lib/prefix.c index ed0774e77495..4b4890a80c86 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -27,6 +27,7 @@ #include "memory.h" #include "log.h" #include "jhash.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, PREFIX, "Prefix") @@ -656,8 +657,9 @@ void prefix_copy(struct prefix *dest, const struct prefix *src) memcpy((void *)dest->u.prefix_flowspec.ptr, (void *)src->u.prefix_flowspec.ptr, len); } else { - zlog_err("prefix_copy(): Unknown address family %d", - src->family); + zlog_ferr(LIB_ERR_DEVELOPMENT, + "prefix_copy(): Unknown address family %d", + src->family); assert(0); } } diff --git a/lib/skiplist.c b/lib/skiplist.c index a546bb44c025..d2b3acc971e3 100644 --- a/lib/skiplist.c +++ b/lib/skiplist.c @@ -60,6 +60,7 @@ #include "log.h" #include "vty.h" #include "skiplist.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, SKIP_LIST, "Skip List") DEFINE_MTYPE_STATIC(LIB, SKIP_LIST_NODE, "Skip Node") @@ -182,7 +183,8 @@ int skiplist_insert(register struct skiplist *l, register void *key, /* DEBUG */ if (!key) { - zlog_err("%s: key is 0, value is %p", __func__, value); + zlog_ferr(LIB_ERR_DEVELOPMENT, "%s: key is 0, value is %p", + __func__, value); } p = l->header; diff --git a/lib/vty.c b/lib/vty.c index b5e4aed8262b..4b4363f59ab7 100644 --- a/lib/vty.c +++ b/lib/vty.c @@ -1324,9 +1324,9 @@ static int vty_telnet_option(struct vty *vty, unsigned char *buf, int nbytes) TELNET_NAWS_SB_LEN, (unsigned long)vty->sb_len); else if (sizeof(vty->sb_buf) < TELNET_NAWS_SB_LEN) - zlog_err( - "Bug detected: sizeof(vty->sb_buf) %lu < %d, " - "too small to handle the telnet NAWS option", + zlog_ferr( + LIB_ERR_DEVELOPMENT, + "Bug detected: sizeof(vty->sb_buf) %lu < %d, too small to handle the telnet NAWS option", (unsigned long)sizeof(vty->sb_buf), TELNET_NAWS_SB_LEN); else { From 815d5a4839066f16ed1c8d2214ba9b75b0ef9168 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 09:18:10 -0400 Subject: [PATCH 04/14] lib: Remove memory check test Found a missed memory check test that can just be removed. Signed-off-by: Donald Sharp --- lib/ferr.c | 7 ------- 1 file changed, 7 deletions(-) diff --git a/lib/ferr.c b/lib/ferr.c index 26b8c87f6a99..6625749c3f44 100644 --- a/lib/ferr.c +++ b/lib/ferr.c @@ -175,13 +175,6 @@ static ferr_r ferr_set_va(const char *file, int line, const char *func, if (!error) { error = XCALLOC(MTYPE_ERRINFO, sizeof(*error)); - if (!error) { - /* we're screwed */ - zlog_err("out of memory while allocating error info"); - raise(SIGSEGV); - abort(); /* raise() can return, but raise(SIGSEGV) shall - not */ - } pthread_setspecific(errkey, error); } From 61b59c0098193146672dfdfc2f72c93208cda3ae Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 09:25:03 -0400 Subject: [PATCH 05/14] lib: Add LIB_ERR_ZMQ Add new error event for when we detect an issue within the ZMQ subsystem. Signed-off-by: Donald Sharp --- lib/frr_zmq.c | 7 +++++-- lib/lib_errors.c | 6 ++++++ lib/lib_errors.h | 1 + 3 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index 8f190a3a09c7..81a664d648fb 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -24,6 +24,7 @@ #include "memory.h" #include "frr_zmq.h" #include "log.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, ZEROMQ_CB, "ZeroMQ callback") @@ -140,7 +141,8 @@ static int frrzmq_read_msg(struct thread *t) return 0; out_err: - zlog_err("ZeroMQ read error: %s(%d)", strerror(errno), errno); + zlog_ferr(LIB_ERR_ZMQ, "ZeroMQ read error: %s(%d)", strerror(errno), + errno); if (cb->read.cb_error) cb->read.cb_error(cb->read.arg, cb->zmqsock); return 1; @@ -252,7 +254,8 @@ static int frrzmq_write_msg(struct thread *t) return 0; out_err: - zlog_err("ZeroMQ write error: %s(%d)", strerror(errno), errno); + zlog_ferr(LIB_ERR_ZMQ, "ZeroMQ write error: %s(%d)", strerror(errno), + errno); if (cb->write.cb_error) cb->write.cb_error(cb->write.arg, cb->zmqsock); return 1; diff --git a/lib/lib_errors.c b/lib/lib_errors.c index ae4635673f26..d45e21ddc8b2 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -94,6 +94,12 @@ static struct ferr_ref ferr_lib_err[] = { .description = "FRR has detected an issue where new development has not properly\nupdated all code paths.", .suggestion = "Open an Issue with all relevant log files" }, + { + .code = LIB_ERR_ZMQ, + .title = "ZMQ Subsystem Error", + .description = "FRR has detected an issue with the Zero MQ subsystem and ZeroMQ\nis not working properly now", + .suggestion = "Open an Issue with all relevant log files and restart FRR" + }, { .code = END_FERR, } diff --git a/lib/lib_errors.h b/lib/lib_errors.h index bb83c45e67d7..5a68efb30c76 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -35,6 +35,7 @@ enum lib_ferr_refs { LIB_ERR_INTERFACE, LIB_ERR_NS, LIB_ERR_DEVELOPMENT, + LIB_ERR_ZMQ, }; extern void lib_error_init(void); From e9550d02c88aa76dd60dd39f6423e89976dfba0e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 09:29:27 -0400 Subject: [PATCH 06/14] lib: Cleanup some missed LIB_ERR_SYSTEM_CALL libfrr.c had some detection for system call issues. Signed-off-by: Donald Sharp --- lib/libfrr.c | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/lib/libfrr.c b/lib/libfrr.c index b51c871554fa..6cb0d2ef1f11 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -790,8 +790,9 @@ static void frr_terminal_close(int isexit) nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); if (nullfd == -1) { - zlog_err("%s: failed to open /dev/null: %s", __func__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: failed to open /dev/null: %s", __func__, + safe_strerror(errno)); } else { dup2(nullfd, 0); dup2(nullfd, 1); @@ -860,8 +861,9 @@ void frr_run(struct thread_master *master) } else if (di->daemon_mode) { int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); if (nullfd == -1) { - zlog_err("%s: failed to open /dev/null: %s", __func__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: failed to open /dev/null: %s", __func__, + safe_strerror(errno)); } else { dup2(nullfd, 0); dup2(nullfd, 1); From 546f4db8da2ae08bf0b56a96dc4866bc24c23d2f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 09:46:19 -0400 Subject: [PATCH 07/14] ospf6d: Update OSPFv3 to use new zlog_ferr Update OSPFv3 to use the new zlog_ferr messages Signed-off-by: Donald Sharp --- ospf6d/ospf6_message.c | 6 ++++-- ospf6d/ospf6_network.c | 15 ++++++++++----- ospf6d/ospf6_route.c | 4 ++-- ospf6d/ospf6_spf.c | 4 +++- ospf6d/ospf6_zebra.c | 8 +++++--- 5 files changed, 24 insertions(+), 13 deletions(-) diff --git a/ospf6d/ospf6_message.c b/ospf6d/ospf6_message.c index c7cd94bd327b..bed2d021077e 100644 --- a/ospf6d/ospf6_message.c +++ b/ospf6d/ospf6_message.c @@ -26,6 +26,7 @@ #include "command.h" #include "thread.h" #include "linklist.h" +#include "lib_errors.h" #include "ospf6_proto.h" #include "ospf6_lsa.h" @@ -1558,7 +1559,8 @@ int ospf6_receive(struct thread *thread) /* receive message */ len = ospf6_recvmsg(&src, &dst, &ifindex, iovector); if (len > iobuflen) { - zlog_err("Excess message read"); + zlog_ferr(LIB_ERR_DEVELOPMENT, + "Excess message read"); return 0; } @@ -1706,7 +1708,7 @@ static void ospf6_send(struct in6_addr *src, struct in6_addr *dst, /* send message */ len = ospf6_sendmsg(src, dst, &oi->interface->ifindex, iovector); if (len != ntohs(oh->length)) - zlog_err("Could not send entire message"); + zlog_ferr(LIB_ERR_DEVELOPMENT, "Could not send entire message"); } static uint32_t ospf6_packet_max(struct ospf6_interface *oi) diff --git a/ospf6d/ospf6_network.c b/ospf6d/ospf6_network.c index 4790d8f01ef5..86481e46c6cf 100644 --- a/ospf6d/ospf6_network.c +++ b/ospf6d/ospf6_network.c @@ -25,6 +25,7 @@ #include "sockunion.h" #include "sockopt.h" #include "privs.h" +#include "lib_errors.h" #include "libospf.h" #include "ospf6_proto.h" @@ -76,17 +77,20 @@ static void ospf6_set_checksum(void) int ospf6_serv_sock(void) { if (ospf6d_privs.change(ZPRIVS_RAISE)) - zlog_err("ospf6_serv_sock: could not raise privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "ospf6_serv_sock: could not raise privs"); ospf6_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_OSPFIGP); if (ospf6_sock < 0) { zlog_warn("Network: can't create OSPF6 socket."); if (ospf6d_privs.change(ZPRIVS_LOWER)) - zlog_err("ospf_sock_init: could not lower privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "ospf_sock_init: could not lower privs"); return -1; } if (ospf6d_privs.change(ZPRIVS_LOWER)) - zlog_err("ospf_sock_init: could not lower privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "ospf_sock_init: could not lower privs"); /* set socket options */ #if 1 @@ -120,8 +124,9 @@ int ospf6_sso(ifindex_t ifindex, struct in6_addr *group, int option) ret = setsockopt(ospf6_sock, IPPROTO_IPV6, option, &mreq6, sizeof(mreq6)); if (ret < 0) { - zlog_err("Network: setsockopt (%d) on ifindex %d failed: %s", - option, ifindex, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "Network: setsockopt (%d) on ifindex %d failed: %s", + option, ifindex, safe_strerror(errno)); return ret; } diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 15d8eb6cf258..b1ac67ae7dc3 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -574,8 +574,8 @@ static void route_table_assert(struct ospf6_route_table *table) if (link_error == 0 && num == table->count) return; - zlog_err("PANIC !!"); - zlog_err("Something has gone wrong with ospf6_route_table[%p]", table); + zlog_ferr(LIB_ERR_DEVELOPMENT, "PANIC !!"); + zlog_ferr(LIB_ERR_DEVELOPMENT, "Something has gone wrong with ospf6_route_table[%p]", table); zlog_debug("table count = %d, real number = %d", table->count, num); zlog_debug("DUMP START"); for (r = ospf6_route_head(table); r; r = ospf6_route_next(r)) { diff --git a/ospf6d/ospf6_spf.c b/ospf6d/ospf6_spf.c index 0b94b930c5e0..30ad48cd56fa 100644 --- a/ospf6d/ospf6_spf.c +++ b/ospf6d/ospf6_spf.c @@ -30,6 +30,7 @@ #include "pqueue.h" #include "linklist.h" #include "thread.h" +#include "lib_errors.h" #include "ospf6_lsa.h" #include "ospf6_lsdb.h" @@ -272,7 +273,8 @@ static void ospf6_nexthop_calc(struct ospf6_vertex *w, struct ospf6_vertex *v, ifindex = (VERTEX_IS_TYPE(NETWORK, v) ? ospf6_spf_get_ifindex_from_nh(v) : ROUTER_LSDESC_GET_IFID(lsdesc)); if (ifindex == 0) { - zlog_err("No nexthop ifindex at vertex %s", v->name); + zlog_ferr(LIB_ERR_DEVELOPMENT, + "No nexthop ifindex at vertex %s", v->name); return; } diff --git a/ospf6d/ospf6_zebra.c b/ospf6d/ospf6_zebra.c index 8458d19952e0..8f1b009cc0b6 100644 --- a/ospf6d/ospf6_zebra.c +++ b/ospf6d/ospf6_zebra.c @@ -28,6 +28,7 @@ #include "zclient.h" #include "memory.h" #include "lib/bfd.h" +#include "lib_errors.h" #include "ospf6_proto.h" #include "ospf6_top.h" @@ -362,9 +363,10 @@ static void ospf6_zebra_route_update(int type, struct ospf6_route *request) ret = zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); if (ret < 0) - zlog_err("zclient_route_send() %s failed: %s", - (type == REM ? "delete" : "add"), - safe_strerror(errno)); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, + "zclient_route_send() %s failed: %s", + (type == REM ? "delete" : "add"), + safe_strerror(errno)); return; } From 3527a27eb80d000cbe141627645626675ec87e19 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 09:50:29 -0400 Subject: [PATCH 08/14] ripd: Convert zlog_err to zlog_ferr for LIB_ERR_XXX For those errors that can be traced to LIB_ERR_XXX convert to using those in ripd. Signed-off-by: Donald Sharp --- ripd/rip_interface.c | 6 ++++-- ripd/ripd.c | 20 +++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ripd/rip_interface.c b/ripd/rip_interface.c index 5a3f3412054d..3fe0583b29b4 100644 --- a/ripd/rip_interface.c +++ b/ripd/rip_interface.c @@ -34,6 +34,7 @@ #include "filter.h" #include "sockopt.h" #include "privs.h" +#include "lib_errors.h" #include "zebra/connected.h" @@ -865,8 +866,9 @@ static int rip_interface_wakeup(struct thread *t) /* Join to multicast group. */ if (rip_multicast_join(ifp, rip->sock) < 0) { - zlog_err("multicast join failed, interface %s not running", - ifp->name); + zlog_ferr(LIB_ERR_SOCKET, + "multicast join failed, interface %s not running", + ifp->name); return 0; } diff --git a/ripd/ripd.c b/ripd/ripd.c index ec9b04edff6f..bbe2a0c04ff3 100644 --- a/ripd/ripd.c +++ b/ripd/ripd.c @@ -40,6 +40,7 @@ #include "md5.h" #include "keychain.h" #include "privs.h" +#include "lib_errors.h" #include "ripd/ripd.h" #include "ripd/rip_debug.h" @@ -1339,7 +1340,8 @@ static int rip_create_socket(void) /* Make datagram socket. */ sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (sock < 0) { - zlog_err("Cannot create UDP socket: %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "Cannot create UDP socket: %s", + safe_strerror(errno)); exit(1); } @@ -1355,25 +1357,29 @@ static int rip_create_socket(void) #endif if (ripd_privs.change(ZPRIVS_RAISE)) - zlog_err("rip_create_socket: could not raise privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "rip_create_socket: could not raise privs"); setsockopt_so_recvbuf(sock, RIP_UDP_RCV_BUF); if ((ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr))) < 0) { int save_errno = errno; if (ripd_privs.change(ZPRIVS_LOWER)) - zlog_err("rip_create_socket: could not lower privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "rip_create_socket: could not lower privs"); - zlog_err("%s: Can't bind socket %d to %s port %d: %s", __func__, - sock, inet_ntoa(addr.sin_addr), - (int)ntohs(addr.sin_port), safe_strerror(save_errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Can't bind socket %d to %s port %d: %s", + __func__, sock, inet_ntoa(addr.sin_addr), + (int)ntohs(addr.sin_port), safe_strerror(save_errno)); close(sock); return ret; } if (ripd_privs.change(ZPRIVS_LOWER)) - zlog_err("rip_create_socket: could not lower privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "rip_create_socket: could not lower privs"); return sock; } From 8d0f19cee8dd39836055d03034fcd3e9f0a9403e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 10:05:16 -0400 Subject: [PATCH 09/14] ripngd: Convert over to using LIB_ERR_XXXX for zlog_ferr Convert over those zlog_err functions to zlog_ferr that are appropriate for the LIB_ERR_XXX. Signed-off-by: Donald Sharp --- ripngd/ripng_interface.c | 14 ++++++++++---- ripngd/ripngd.c | 26 ++++++++++++++++---------- 2 files changed, 26 insertions(+), 14 deletions(-) diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index d1057bf53e21..c780c26989d9 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -35,6 +35,7 @@ #include "thread.h" #include "privs.h" #include "vrf.h" +#include "lib_errors.h" #include "ripngd/ripngd.h" #include "ripngd/ripng_debug.h" @@ -72,14 +73,18 @@ static int ripng_multicast_join(struct interface *ifp) * for this call as a workaround. */ if (ripngd_privs.change(ZPRIVS_RAISE)) - zlog_err("ripng_multicast_join: could not raise privs"); + zlog_ferr( + LIB_ERR_PRIVILEGES, + "ripng_multicast_join: could not raise privs"); ret = setsockopt(ripng->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, (char *)&mreq, sizeof(mreq)); save_errno = errno; if (ripngd_privs.change(ZPRIVS_LOWER)) - zlog_err("ripng_multicast_join: could not lower privs"); + zlog_ferr( + LIB_ERR_PRIVILEGES, + "ripng_multicast_join: could not lower privs"); if (ret < 0 && save_errno == EADDRINUSE) { /* @@ -642,8 +647,9 @@ static int ripng_interface_wakeup(struct thread *t) /* Join to multicast group. */ if (ripng_multicast_join(ifp) < 0) { - zlog_err("multicast join failed, interface %s not running", - ifp->name); + zlog_ferr(LIB_ERR_SOCKET, + "multicast join failed, interface %s not running", + ifp->name); return 0; } diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index 840157516fb6..5eef13136c8d 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -35,6 +35,7 @@ #include "routemap.h" #include "if_rmap.h" #include "privs.h" +#include "lib_errors.h" #include "ripngd/ripngd.h" #include "ripngd/ripng_route.h" @@ -94,7 +95,7 @@ static int ripng_make_socket(void) sock = socket(AF_INET6, SOCK_DGRAM, 0); if (sock < 0) { - zlog_err("Can't make ripng socket"); + zlog_ferr(LIB_ERR_SOCKET, "Can't make ripng socket"); return sock; } @@ -125,17 +126,21 @@ static int ripng_make_socket(void) ripaddr.sin6_port = htons(RIPNG_PORT_DEFAULT); if (ripngd_privs.change(ZPRIVS_RAISE)) - zlog_err("ripng_make_socket: could not raise privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "ripng_make_socket: could not raise privs"); ret = bind(sock, (struct sockaddr *)&ripaddr, sizeof(ripaddr)); if (ret < 0) { - zlog_err("Can't bind ripng socket: %s.", safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "Can't bind ripng socket: %s.", + safe_strerror(errno)); if (ripngd_privs.change(ZPRIVS_LOWER)) - zlog_err("ripng_make_socket: could not lower privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "ripng_make_socket: could not lower privs"); goto error; } if (ripngd_privs.change(ZPRIVS_LOWER)) - zlog_err("ripng_make_socket: could not lower privs"); + zlog_ferr(LIB_ERR_PRIVILEGES, + "ripng_make_socket: could not lower privs"); return sock; error: @@ -202,12 +207,13 @@ int ripng_send_packet(caddr_t buf, int bufsize, struct sockaddr_in6 *to, if (ret < 0) { if (to) - zlog_err("RIPng send fail on %s to %s: %s", ifp->name, - inet6_ntoa(to->sin6_addr), - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "RIPng send fail on %s to %s: %s", ifp->name, + inet6_ntoa(to->sin6_addr), + safe_strerror(errno)); else - zlog_err("RIPng send fail on %s: %s", ifp->name, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "RIPng send fail on %s: %s", + ifp->name, safe_strerror(errno)); } return ret; From 128bbc2b020cfad3f876789c3ab8ed4326d38073 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 10:17:36 -0400 Subject: [PATCH 10/14] pimd: Convert over to use LIB_ERR_XXX for zlog_err Convert, where appropriate, the zlog_err functions to zlog_ferr for the LIB_ERR_XXX enums Signed-off-by: Donald Sharp --- pimd/pim_br.c | 5 --- pimd/pim_iface.c | 50 ------------------------------ pimd/pim_ifchannel.c | 20 ------------ pimd/pim_igmp.c | 16 ++++------ pimd/pim_igmpv3.c | 4 ++- pimd/pim_instance.c | 19 +----------- pimd/pim_mroute.c | 17 +++++++---- pimd/pim_msdp.c | 4 ++- pimd/pim_msdp_packet.c | 4 ++- pimd/pim_msdp_socket.c | 69 ++++++++++++++++++++++++------------------ pimd/pim_neighbor.c | 4 ++- pimd/pim_oil.c | 5 --- pimd/pim_rp.c | 8 +++-- pimd/pim_sock.c | 38 +++++++++++++---------- pimd/pim_ssmpingd.c | 15 ++++----- pimd/pim_time.c | 21 ++++++++----- pimd/pim_tlv.c | 12 -------- pimd/pim_zlookup.c | 28 +++++++++++------ pimd/pimd.c | 4 ++- 19 files changed, 138 insertions(+), 205 deletions(-) diff --git a/pimd/pim_br.c b/pimd/pim_br.c index a4ecab1e3af9..fc6a02ec9316 100644 --- a/pimd/pim_br.c +++ b/pimd/pim_br.c @@ -95,9 +95,4 @@ void pim_br_clear_pmbr(struct prefix_sg *sg) void pim_br_init(void) { pim_br_list = list_new(); - if (!pim_br_list) { - zlog_err("%s: Failure to create pim_br_list", - __PRETTY_FUNCTION__); - return; - } } diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index 5b11ae90b22d..b998f5a1feca 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -75,36 +75,6 @@ void pim_if_terminate(struct pim_instance *pim) return; } -static void *if_list_clean(struct pim_interface *pim_ifp) -{ - struct pim_ifchannel *ch; - - if (pim_ifp->igmp_join_list) - list_delete_and_null(&pim_ifp->igmp_join_list); - - if (pim_ifp->igmp_socket_list) - list_delete_and_null(&pim_ifp->igmp_socket_list); - - if (pim_ifp->pim_neighbor_list) - list_delete_and_null(&pim_ifp->pim_neighbor_list); - - if (pim_ifp->upstream_switch_list) - list_delete_and_null(&pim_ifp->upstream_switch_list); - - if (pim_ifp->sec_addr_list) - list_delete_and_null(&pim_ifp->sec_addr_list); - - while (!RB_EMPTY(pim_ifchannel_rb, &pim_ifp->ifchannel_rb)) { - ch = RB_ROOT(pim_ifchannel_rb, &pim_ifp->ifchannel_rb); - - pim_ifchannel_delete(ch); - } - - XFREE(MTYPE_PIM_INTERFACE, pim_ifp); - - return 0; -} - static void pim_sec_addr_free(struct pim_secondary_addr *sec_addr) { XFREE(MTYPE_PIM_SEC_ADDR, sec_addr); @@ -182,38 +152,18 @@ struct pim_interface *pim_if_new(struct interface *ifp, int igmp, int pim) /* list of struct igmp_sock */ pim_ifp->igmp_socket_list = list_new(); - if (!pim_ifp->igmp_socket_list) { - zlog_err("%s: failure: igmp_socket_list=list_new()", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->igmp_socket_list->del = (void (*)(void *))igmp_sock_free; /* list of struct pim_neighbor */ pim_ifp->pim_neighbor_list = list_new(); - if (!pim_ifp->pim_neighbor_list) { - zlog_err("%s: failure: pim_neighbor_list=list_new()", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->pim_neighbor_list->del = (void (*)(void *))pim_neighbor_free; pim_ifp->upstream_switch_list = list_new(); - if (!pim_ifp->upstream_switch_list) { - zlog_err("%s: failure: upstream_switch_list=list_new()", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->upstream_switch_list->del = (void (*)(void *))pim_jp_agg_group_list_free; pim_ifp->upstream_switch_list->cmp = pim_jp_agg_group_list_cmp; pim_ifp->sec_addr_list = list_new(); - if (!pim_ifp->sec_addr_list) { - zlog_err("%s: failure: secondary addresslist", - __PRETTY_FUNCTION__); - return if_list_clean(pim_ifp); - } pim_ifp->sec_addr_list->del = (void (*)(void *))pim_sec_addr_free; pim_ifp->sec_addr_list->cmp = (int (*)(void *, void *))pim_sec_addr_comp; diff --git a/pimd/pim_ifchannel.c b/pimd/pim_ifchannel.c index e82a7589b719..a2a3e88e3c70 100644 --- a/pimd/pim_ifchannel.c +++ b/pimd/pim_ifchannel.c @@ -550,26 +550,6 @@ struct pim_ifchannel *pim_ifchannel_add(struct interface *ifp, up = pim_upstream_add(pim_ifp->pim, sg, NULL, up_flags, __PRETTY_FUNCTION__, ch); - if (!up) { - zlog_err( - "%s: could not attach upstream (S,G)=%s on interface %s", - __PRETTY_FUNCTION__, pim_str_sg_dump(sg), ifp->name); - - if (ch->parent) - listnode_delete(ch->parent->sources, ch); - - pim_ifchannel_remove_children(ch); - if (ch->sources) - list_delete_and_null(&ch->sources); - - THREAD_OFF(ch->t_ifjoin_expiry_timer); - THREAD_OFF(ch->t_ifjoin_prune_pending_timer); - THREAD_OFF(ch->t_ifassert_timer); - - RB_REMOVE(pim_ifchannel_rb, &pim_ifp->ifchannel_rb, ch); - XFREE(MTYPE_PIM_IFCHANNEL, ch); - return NULL; - } ch->upstream = up; listnode_add_sort(up->ifchannels, ch); diff --git a/pimd/pim_igmp.c b/pimd/pim_igmp.c index 8bfc59116a82..fa7a1824012f 100644 --- a/pimd/pim_igmp.c +++ b/pimd/pim_igmp.c @@ -24,6 +24,7 @@ #include "if.h" #include "hash.h" #include "jhash.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_igmp.h" @@ -96,9 +97,9 @@ static int igmp_sock_open(struct in_addr ifaddr, struct interface *ifp, } if (!join) { - zlog_err( - "IGMP socket fd=%d could not join any group on interface address %s", - fd, inet_ntoa(ifaddr)); + zlog_ferr(LIB_ERR_SOCKET, + "IGMP socket fd=%d could not join any group on interface address %s", + fd, inet_ntoa(ifaddr)); close(fd); fd = -1; } @@ -697,7 +698,8 @@ static void sock_close(struct igmp_sock *igmp) THREAD_OFF(igmp->t_igmp_read); if (close(igmp->fd)) { - zlog_err( + zlog_ferr( + LIB_ERR_SOCKET, "Failure closing IGMP socket %s fd=%d on interface %s: errno=%d: %s", inet_ntoa(igmp->ifaddr), igmp->fd, igmp->interface->name, errno, safe_strerror(errno)); @@ -961,12 +963,6 @@ struct igmp_sock *pim_igmp_sock_add(struct list *igmp_sock_list, } igmp = igmp_sock_new(fd, ifaddr, ifp, mtrace_only); - if (!igmp) { - zlog_err("%s %s: igmp_sock_new() failure", __FILE__, - __PRETTY_FUNCTION__); - close(fd); - return 0; - } igmp_read_on(igmp); diff --git a/pimd/pim_igmpv3.c b/pimd/pim_igmpv3.c index 132fe4d56424..38f26f7ae85e 100644 --- a/pimd/pim_igmpv3.c +++ b/pimd/pim_igmpv3.c @@ -21,6 +21,7 @@ #include "log.h" #include "memory.h" #include "if.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_iface.h" @@ -1583,7 +1584,8 @@ void igmp_v3_send_query(struct igmp_group *group, int fd, const char *ifname, msg_size = IGMP_V3_SOURCES_OFFSET + (num_sources << 2); if (msg_size > query_buf_size) { - zlog_err( + zlog_ferr( + LIB_ERR_DEVELOPMENT, "%s %s: unable to send: msg_size=%zd larger than query_buf_size=%d", __FILE__, __PRETTY_FUNCTION__, msg_size, query_buf_size); diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index 5bdfbab49a3d..c4461776d777 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -22,6 +22,7 @@ #include "hash.h" #include "vrf.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_ssm.h" @@ -94,18 +95,8 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) zlog_debug("%s: NHT rpf hash init ", __PRETTY_FUNCTION__); pim->ssm_info = pim_ssm_init(); - if (!pim->ssm_info) { - pim_instance_terminate(pim); - return NULL; - } pim->static_routes = list_new(); - if (!pim->static_routes) { - zlog_err("%s %s: failure: static_routes=list_new()", __FILE__, - __PRETTY_FUNCTION__); - pim_instance_terminate(pim); - return NULL; - } pim->static_routes->del = (void (*)(void *))pim_static_route_free; pim->send_v6_secondary = 1; @@ -138,14 +129,6 @@ static int pim_vrf_new(struct vrf *vrf) struct pim_instance *pim = pim_instance_init(vrf); zlog_debug("VRF Created: %s(%u)", vrf->name, vrf->vrf_id); - if (pim == NULL) { - zlog_err("%s %s: pim class init failure ", __FILE__, - __PRETTY_FUNCTION__); - /* - * We will crash and burn otherwise - */ - exit(1); - } vrf->info = (void *)pim; diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 8462a4fdf8d6..b7745e3bbb8e 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -25,6 +25,7 @@ #include "vty.h" #include "plist.h" #include "sockopt.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_rpf.h" @@ -56,7 +57,8 @@ static int pim_mroute_set(struct pim_instance *pim, int enable) */ if (pim->vrf_id != VRF_DEFAULT) { if (pimd_privs.change(ZPRIVS_RAISE)) - zlog_err( + zlog_ferr( + LIB_ERR_PRIVILEGES, "pim_mroute_socket_enable: could not raise privs, %s", safe_strerror(errno)); @@ -73,7 +75,8 @@ static int pim_mroute_set(struct pim_instance *pim, int enable) } if (pimd_privs.change(ZPRIVS_LOWER)) - zlog_err( + zlog_ferr( + LIB_ERR_PRIVILEGES, "pim_mroute_socket_enable: could not lower privs, %s", safe_strerror(errno)); } @@ -709,8 +712,9 @@ int pim_mroute_socket_enable(struct pim_instance *pim) int fd; if (pimd_privs.change(ZPRIVS_RAISE)) - zlog_err("pim_mroute_socket_enable: could not raise privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "pim_mroute_socket_enable: could not raise privs, %s", + safe_strerror(errno)); fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP); @@ -732,8 +736,9 @@ int pim_mroute_socket_enable(struct pim_instance *pim) #endif if (pimd_privs.change(ZPRIVS_LOWER)) - zlog_err("pim_mroute_socket_enable: could not lower privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "pim_mroute_socket_enable: could not lower privs, %s", + safe_strerror(errno)); pim->mroute_socket = fd; if (pim_mroute_set(pim, 1)) { diff --git a/pimd/pim_msdp.c b/pimd/pim_msdp.c index cfa523821aeb..41d4771abaed 100644 --- a/pimd/pim_msdp.c +++ b/pimd/pim_msdp.c @@ -28,6 +28,7 @@ #include #include #include +#include #include "pimd.h" #include "pim_cmd.h" @@ -517,7 +518,8 @@ static void pim_msdp_sa_local_del_on_up_del(struct pim_instance *pim, * the flow. Accounting for such cases requires lot of * changes; perhaps * address this in the next release? - XXX */ - zlog_err( + zlog_ferr( + LIB_ERR_DEVELOPMENT, "MSDP sa %s SPT teardown is causing the local entry to be removed", sa->sg_str); return; diff --git a/pimd/pim_msdp_packet.c b/pimd/pim_msdp_packet.c index 978d979245bc..7aa9357b8535 100644 --- a/pimd/pim_msdp_packet.c +++ b/pimd/pim_msdp_packet.c @@ -23,6 +23,7 @@ #include #include #include +#include #include "pimd.h" #include "pim_str.h" @@ -145,7 +146,8 @@ static void pim_msdp_connect_check(struct pim_msdp_peer *mp) /* If getsockopt is fail, this is fatal error. */ if (ret < 0) { - zlog_err("can't get sockopt for nonblocking connect"); + zlog_ferr(LIB_ERR_SOCKET, + "can't get sockopt for nonblocking connect"); pim_msdp_peer_reset_tcp_conn(mp, "connect-failed"); return; } diff --git a/pimd/pim_msdp_socket.c b/pimd/pim_msdp_socket.c index f245a043534a..5b1afb774b66 100644 --- a/pimd/pim_msdp_socket.c +++ b/pimd/pim_msdp_socket.c @@ -26,6 +26,7 @@ #include #include #include +#include #include "pimd.h" #include "pim_sock.h" @@ -41,16 +42,17 @@ static void pim_msdp_update_sock_send_buffer_size(int fd) socklen_t optlen = sizeof(optval); if (getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &optval, &optlen) < 0) { - zlog_err("getsockopt of SO_SNDBUF failed %s\n", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "getsockopt of SO_SNDBUF failed %s\n", + safe_strerror(errno)); return; } if (optval < size) { if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &size, sizeof(size)) < 0) { - zlog_err("Couldn't increase send buffer: %s\n", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "Couldn't increase send buffer: %s\n", + safe_strerror(errno)); } } } @@ -70,7 +72,8 @@ static int pim_msdp_sock_accept(struct thread *thread) /* re-register accept thread */ accept_sock = THREAD_FD(thread); if (accept_sock < 0) { - zlog_err("accept_sock is negative value %d", accept_sock); + zlog_ferr(LIB_ERR_DEVELOPMENT, + "accept_sock is negative value %d", accept_sock); return -1; } pim->msdp.listener.thread = NULL; @@ -80,8 +83,8 @@ static int pim_msdp_sock_accept(struct thread *thread) /* accept client connection. */ msdp_sock = sockunion_accept(accept_sock, &su); if (msdp_sock < 0) { - zlog_err("pim_msdp_sock_accept failed (%s)", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "pim_msdp_sock_accept failed (%s)", + safe_strerror(errno)); return -1; } @@ -106,7 +109,7 @@ static int pim_msdp_sock_accept(struct thread *thread) * with this one */ if (mp->fd >= 0) { if (PIM_DEBUG_MSDP_EVENTS) { - zlog_err( + zlog_notice( "msdp peer new connection from %s stop old connection", sockunion2str(&su, buf, SU_ADDRSTRLEN)); } @@ -135,7 +138,7 @@ int pim_msdp_sock_listen(struct pim_instance *pim) sock = socket(AF_INET, SOCK_STREAM, 0); if (sock < 0) { - zlog_err("socket: %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "socket: %s", safe_strerror(errno)); return sock; } @@ -154,42 +157,47 @@ int pim_msdp_sock_listen(struct pim_instance *pim) struct interface *ifp = if_lookup_by_name(pim->vrf->name, pim->vrf_id); if (!ifp) { - zlog_err("%s: Unable to lookup vrf interface: %s", - __PRETTY_FUNCTION__, pim->vrf->name); + zlog_ferr(LIB_ERR_INTERFACE, + "%s: Unable to lookup vrf interface: %s", + __PRETTY_FUNCTION__, pim->vrf->name); close(sock); return -1; } if (pim_socket_bind(sock, ifp)) { - zlog_err("%s: Unable to bind to socket: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Unable to bind to socket: %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); close(sock); return -1; } } if (pimd_privs.change(ZPRIVS_RAISE)) { - zlog_err("pim_msdp_socket: could not raise privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "pim_msdp_socket: could not raise privs, %s", + safe_strerror(errno)); } /* bind to well known TCP port */ rc = bind(sock, (struct sockaddr *)&sin, socklen); if (pimd_privs.change(ZPRIVS_LOWER)) { - zlog_err("pim_msdp_socket: could not lower privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "pim_msdp_socket: could not lower privs, %s", + safe_strerror(errno)); } if (rc < 0) { - zlog_err("pim_msdp_socket bind to port %d: %s", - ntohs(sin.sin_port), safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "pim_msdp_socket bind to port %d: %s", + ntohs(sin.sin_port), safe_strerror(errno)); close(sock); return rc; } rc = listen(sock, 3 /* backlog */); if (rc < 0) { - zlog_err("pim_msdp_socket listen: %s", safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "pim_msdp_socket listen: %s", + safe_strerror(errno)); close(sock); return rc; } @@ -219,7 +227,7 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) * with this one */ if (mp->fd >= 0) { if (PIM_DEBUG_MSDP_EVENTS) { - zlog_err( + zlog_notice( "msdp duplicate connect to %s nuke old connection", mp->key_str); } @@ -229,8 +237,8 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) /* Make socket for the peer. */ mp->fd = sockunion_socket(&mp->su_peer); if (mp->fd < 0) { - zlog_err("pim_msdp_socket socket failure: %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, "pim_msdp_socket socket failure: %s", + safe_strerror(errno)); return -1; } @@ -238,13 +246,15 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) struct interface *ifp = if_lookup_by_name(mp->pim->vrf->name, mp->pim->vrf_id); if (!ifp) { - zlog_err("%s: Unable to lookup vrf interface: %s", - __PRETTY_FUNCTION__, mp->pim->vrf->name); + zlog_ferr(LIB_ERR_INTERFACE, + "%s: Unable to lookup vrf interface: %s", + __PRETTY_FUNCTION__, mp->pim->vrf->name); return -1; } if (pim_socket_bind(mp->fd, ifp)) { - zlog_err("%s: Unable to bind to socket: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Unable to bind to socket: %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); close(mp->fd); mp->fd = -1; return -1; @@ -261,8 +271,9 @@ int pim_msdp_sock_connect(struct pim_msdp_peer *mp) /* source bind */ rc = sockunion_bind(mp->fd, &mp->su_local, 0, &mp->su_local); if (rc < 0) { - zlog_err("pim_msdp_socket connect bind failure: %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "pim_msdp_socket connect bind failure: %s", + safe_strerror(errno)); close(mp->fd); mp->fd = -1; return rc; diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index 2730f5e7aa36..6e1f74b1d1c1 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -25,6 +25,7 @@ #include "if.h" #include "vty.h" #include "plist.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_neighbor.h" @@ -796,7 +797,8 @@ void pim_neighbor_update(struct pim_neighbor *neigh, if (neigh->prefix_list == addr_list) { if (addr_list) { - zlog_err( + zlog_ferr( + LIB_ERR_DEVELOPMENT, "%s: internal error: trying to replace same prefix list=%p", __PRETTY_FUNCTION__, (void *)addr_list); } diff --git a/pimd/pim_oil.c b/pimd/pim_oil.c index 209bc73cee6b..d980c4e8af51 100644 --- a/pimd/pim_oil.c +++ b/pimd/pim_oil.c @@ -108,11 +108,6 @@ void pim_oil_init(struct pim_instance *pim) pim_oil_equal, hash_name); pim->channel_oil_list = list_new(); - if (!pim->channel_oil_list) { - zlog_err("%s %s: failure: channel_oil_list=list_new()", - __FILE__, __PRETTY_FUNCTION__); - return; - } pim->channel_oil_list->del = (void (*)(void *))pim_channel_oil_free; pim->channel_oil_list->cmp = (int (*)(void *, void *))pim_channel_oil_compare; diff --git a/pimd/pim_rp.c b/pimd/pim_rp.c index 79b176def376..86278747a345 100644 --- a/pimd/pim_rp.c +++ b/pimd/pim_rp.c @@ -31,6 +31,7 @@ #include "plist.h" #include "nexthop.h" #include "table.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_vty.h" @@ -228,7 +229,8 @@ static struct rp_info *pim_rp_find_match_group(struct pim_instance *pim, rn = route_node_match(pim->rp_table, group); if (!rn) { - zlog_err( + zlog_ferr( + LIB_ERR_DEVELOPMENT, "%s: BUG We should have found default group information\n", __PRETTY_FUNCTION__); return best; @@ -619,7 +621,9 @@ int pim_rp_del(struct pim_instance *pim, const char *rp, rn = route_node_get(pim->rp_table, &rp_info->group); if (rn) { if (rn->info != rp_info) - zlog_err("WTF matey"); + zlog_ferr( + LIB_ERR_DEVELOPMENT, + "Expected rn->info to be equal to rp_info"); if (PIM_DEBUG_TRACE) { char buf[PREFIX_STRLEN]; diff --git a/pimd/pim_sock.c b/pimd/pim_sock.c index 8f311391e11d..1da38295fe8c 100644 --- a/pimd/pim_sock.c +++ b/pimd/pim_sock.c @@ -33,6 +33,7 @@ #include "if.h" #include "vrf.h" #include "sockopt.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_mroute.h" @@ -47,14 +48,16 @@ int pim_socket_raw(int protocol) int fd; if (pimd_privs.change(ZPRIVS_RAISE)) - zlog_err("pim_sockek_raw: could not raise privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "pim_sockek_raw: could not raise privs, %s", + safe_strerror(errno)); fd = socket(AF_INET, SOCK_RAW, protocol); if (pimd_privs.change(ZPRIVS_LOWER)) - zlog_err("pim_socket_raw: could not lower privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "pim_socket_raw: could not lower privs, %s", + safe_strerror(errno)); if (fd < 0) { zlog_warn("Could not create raw socket: errno=%d: %s", errno, @@ -70,16 +73,17 @@ void pim_socket_ip_hdr(int fd) const int on = 1; if (pimd_privs.change(ZPRIVS_RAISE)) - zlog_err("%s: could not raise privs, %s", __PRETTY_FUNCTION__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: could not raise privs, %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); if (setsockopt(fd, IPPROTO_IP, IP_HDRINCL, &on, sizeof(on))) - zlog_err("%s: Could not turn on IP_HDRINCL option: %s", - __PRETTY_FUNCTION__, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: Could not turn on IP_HDRINCL option: %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); if (pimd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs, %s", __PRETTY_FUNCTION__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: could not lower privs, %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); } /* @@ -92,15 +96,15 @@ int pim_socket_bind(int fd, struct interface *ifp) #ifdef SO_BINDTODEVICE if (pimd_privs.change(ZPRIVS_RAISE)) - zlog_err("%s: could not raise privs, %s", __PRETTY_FUNCTION__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: could not raise privs, %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifp->name, strlen(ifp->name)); if (pimd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs, %s", __PRETTY_FUNCTION__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: could not lower privs, %s", + __PRETTY_FUNCTION__, safe_strerror(errno)); #endif return ret; @@ -162,7 +166,8 @@ int pim_socket_mcast(int protocol, struct in_addr ifaddr, struct interface *ifp, fd, errno, safe_strerror(errno)); } #else - zlog_err( + zlog_ferr( + LIB_ERR_DEVELOPMENT, "%s %s: Missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()", __FILE__, __PRETTY_FUNCTION__); close(fd); @@ -299,7 +304,8 @@ int pim_socket_join(int fd, struct in_addr group, struct in_addr ifaddr, sizeof(ifaddr_str))) sprintf(ifaddr_str, ""); - zlog_err( + zlog_ferr( + LIB_ERR_SOCKET, "Failure socket joining fd=%d group %s on interface address %s: errno=%d: %s", fd, group_str, ifaddr_str, errno, safe_strerror(errno)); return ret; diff --git a/pimd/pim_ssmpingd.c b/pimd/pim_ssmpingd.c index f811707c3bff..3cb49079b48a 100644 --- a/pimd/pim_ssmpingd.c +++ b/pimd/pim_ssmpingd.c @@ -24,6 +24,7 @@ #include "memory.h" #include "sockopt.h" #include "vrf.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_ssmpingd.h" @@ -82,8 +83,9 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) fd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) { - zlog_err("%s: could not create socket: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SOCKET, + "%s: could not create socket: errno=%d: %s", + __PRETTY_FUNCTION__, errno, safe_strerror(errno)); return -1; } @@ -124,7 +126,8 @@ static int ssmpingd_socket(struct in_addr addr, int port, int mttl) safe_strerror(errno)); } #else - zlog_err( + zlog_ferr( + LIB_ERR_DEVELOPMENT, "%s %s: missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()", __FILE__, __PRETTY_FUNCTION__); close(fd); @@ -348,12 +351,6 @@ static struct ssmpingd_sock *ssmpingd_new(struct pim_instance *pim, if (!pim->ssmpingd_list) { pim->ssmpingd_list = list_new(); - if (!pim->ssmpingd_list) { - zlog_err( - "%s %s: failure: qpim_ssmpingd_list=list_new()", - __FILE__, __PRETTY_FUNCTION__); - return 0; - } pim->ssmpingd_list->del = (void (*)(void *))ssmpingd_free; } diff --git a/pimd/pim_time.c b/pimd/pim_time.c index 6f011da43e75..ed2942d5946c 100644 --- a/pimd/pim_time.c +++ b/pimd/pim_time.c @@ -25,6 +25,7 @@ #include "log.h" #include "thread.h" +#include "lib_errors.h" #include "pim_time.h" @@ -34,8 +35,9 @@ static int gettime_monotonic(struct timeval *tv) result = gettimeofday(tv, 0); if (result) { - zlog_err("%s: gettimeofday() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: gettimeofday() failure: errno=%d: %s", + __PRETTY_FUNCTION__, errno, safe_strerror(errno)); } return result; @@ -50,8 +52,9 @@ int64_t pim_time_monotonic_sec() struct timeval now_tv; if (gettime_monotonic(&now_tv)) { - zlog_err("%s: gettime_monotonic() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: gettime_monotonic() failure: errno=%d: %s", + __PRETTY_FUNCTION__, errno, safe_strerror(errno)); return -1; } @@ -68,8 +71,9 @@ int64_t pim_time_monotonic_dsec() int64_t now_dsec; if (gettime_monotonic(&now_tv)) { - zlog_err("%s: gettime_monotonic() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: gettime_monotonic() failure: errno=%d: %s", + __PRETTY_FUNCTION__, errno, safe_strerror(errno)); return -1; } @@ -85,8 +89,9 @@ int64_t pim_time_monotonic_usec(void) int64_t now_dsec; if (gettime_monotonic(&now_tv)) { - zlog_err("%s: gettime_monotonic() failure: errno=%d: %s", - __PRETTY_FUNCTION__, errno, safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: gettime_monotonic() failure: errno=%d: %s", + __PRETTY_FUNCTION__, errno, safe_strerror(errno)); return -1; } diff --git a/pimd/pim_tlv.c b/pimd/pim_tlv.c index eddec3c29e81..70700dd508d1 100644 --- a/pimd/pim_tlv.c +++ b/pimd/pim_tlv.c @@ -757,12 +757,6 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, */ if (!*hello_option_addr_list) { *hello_option_addr_list = list_new(); - if (!*hello_option_addr_list) { - zlog_err( - "%s %s: failure: hello_option_addr_list=list_new()", - __FILE__, __PRETTY_FUNCTION__); - return -2; - } (*hello_option_addr_list)->del = (void (*)(void *))prefix_free; } @@ -773,12 +767,6 @@ int pim_tlv_parse_addr_list(const char *ifname, struct in_addr src_addr, { struct prefix *p; p = prefix_new(); - if (!p) { - zlog_err("%s %s: failure: prefix_new()", - __FILE__, __PRETTY_FUNCTION__); - FREE_ADDR_LIST(*hello_option_addr_list); - return -3; - } prefix_copy(p, &tmp); listnode_add(*hello_option_addr_list, p); } diff --git a/pimd/pim_zlookup.c b/pimd/pim_zlookup.c index fb616e1b0dda..12958b0390a9 100644 --- a/pimd/pim_zlookup.c +++ b/pimd/pim_zlookup.c @@ -28,6 +28,7 @@ #include "thread.h" #include "prefix.h" #include "vty.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_iface.h" @@ -122,7 +123,8 @@ void zclient_lookup_new(void) { zlookup = zclient_new_notify(master, &zclient_options_default); if (!zlookup) { - zlog_err("%s: zclient_new() failure", __PRETTY_FUNCTION__); + zlog_ferr(LIB_ERR_ZAPI_SOCKET, "%s: zclient_new() failure", + __PRETTY_FUNCTION__); return; } @@ -168,8 +170,9 @@ static int zclient_read_nexthop(struct pim_instance *pim, err = zclient_read_header(s, zlookup->sock, &length, &marker, &version, &vrf_id, &command); if (err < 0) { - zlog_err("%s: zclient_read_header() failed", - __PRETTY_FUNCTION__); + zlog_ferr(LIB_ERR_ZAPI_MISSMATCH, + "%s: zclient_read_header() failed", + __PRETTY_FUNCTION__); zclient_lookup_failed(zlookup); return -1; } @@ -333,15 +336,17 @@ static int zclient_lookup_nexthop_once(struct pim_instance *pim, ret = writen(zlookup->sock, s->data, stream_get_endp(s)); if (ret < 0) { - zlog_err( + zlog_ferr( + LIB_ERR_SOCKET, "%s: writen() failure: %d writing to zclient lookup socket", __PRETTY_FUNCTION__, errno); zclient_lookup_failed(zlookup); return -2; } if (ret == 0) { - zlog_err("%s: connection closed on zclient lookup socket", - __PRETTY_FUNCTION__); + zlog_ferr(LIB_ERR_SOCKET, + "%s: connection closed on zclient lookup socket", + __PRETTY_FUNCTION__); zclient_lookup_failed(zlookup); return -3; } @@ -509,7 +514,8 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) count = stream_get_endp(s); ret = writen(zlookup->sock, s->data, count); if (ret <= 0) { - zlog_err( + zlog_ferr( + LIB_ERR_SOCKET, "%s: writen() failure: %d writing to zclient lookup socket", __PRETTY_FUNCTION__, errno); return -1; @@ -528,8 +534,9 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) err = zclient_read_header(s, zlookup->sock, &length, &marker, &version, &vrf_id, &command); if (err < 0) { - zlog_err("%s: zclient_read_header() failed", - __PRETTY_FUNCTION__); + zlog_ferr(LIB_ERR_ZAPI_MISSMATCH, + "%s: zclient_read_header() failed", + __PRETTY_FUNCTION__); zclient_lookup_failed(zlookup); return -1; } @@ -544,7 +551,8 @@ int pim_zlookup_sg_statistics(struct channel_oil *c_oil) more.src = c_oil->oil.mfcc_origin; more.grp = c_oil->oil.mfcc_mcastgrp; - zlog_err( + zlog_ferr( + LIB_ERR_ZAPI_MISSMATCH, "%s: Received wrong %s(%s) information requested", __PRETTY_FUNCTION__, pim_str_sg_dump(&more), c_oil->pim->vrf->name); diff --git a/pimd/pimd.c b/pimd/pimd.c index 5f871026266a..a22baeff84c5 100644 --- a/pimd/pimd.c +++ b/pimd/pimd.c @@ -28,6 +28,7 @@ #include "hash.h" #include "jhash.h" #include "vrf.h" +#include "lib_errors.h" #include "pimd.h" #include "pim_cmd.h" @@ -86,7 +87,8 @@ static void pim_free() void pim_init() { if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) { - zlog_err( + zlog_ferr( + LIB_ERR_SOCKET, "%s %s: could not solve %s to group address: errno=%d: %s", __FILE__, __PRETTY_FUNCTION__, PIM_ALL_PIM_ROUTERS, errno, safe_strerror(errno)); From 1151a3dccd24bf9fd72eb8316f9261be50082a75 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 10:45:27 -0400 Subject: [PATCH 11/14] lib: Update error ranges to include all daemons Signed-off-by: Donald Sharp --- lib/ferr.h | 44 +++++++++++++++++++++++++++++++++++--------- 1 file changed, 35 insertions(+), 9 deletions(-) diff --git a/lib/ferr.h b/lib/ferr.h index 011925b854fa..1ce0429107b6 100644 --- a/lib/ferr.h +++ b/lib/ferr.h @@ -96,15 +96,41 @@ struct ferr { }; /* 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 +#define BABEL_FERR_START 0x01000001 +#define BABEL_FRRR_END 0x01FFFFFF +#define BGP_FERR_START 0x02000001 +#define BGP_FERR_END 0x02FFFFFF +#define EIGRP_FERR_START 0x03000001 +#define EIGRP_FERR_END 0x03FFFFFF +#define ISIS_FERR_START 0x04000001 +#define ISIS_FERR_END 0x04FFFFFF +#define LDP_FERR_START 0x05000001 +#define LDP_FERR_END 0x05FFFFFF +#define LIB_FERR_START 0x06000001 +#define LIB_FERR_END 0x06FFFFFF +#define NHRP_FERR_START 0x07000001 +#define NHRP_FERR_END 0x07FFFFFF +#define OSPF_FERR_START 0x08000001 +#define OSPF_FERR_END 0x08FFFFFF +#define OSPFV3_FERR_START 0x09000001 +#define OSPFV3_FERR_END 0x09FFFFFF +#define PBR_FERR_START 0x0A000001 +#define PBR_FERR_END 0x0AFFFFFF +#define PIM_FERR_START 0x0B000001 +#define PIM_FERR_STOP 0x0BFFFFFF +#define RIP_FERR_START 0x0C000001 +#define RIP_FERR_STOP 0x0CFFFFFF +#define RIPNG_FERR_START 0x0D000001 +#define RIPNG_FERR_STOP 0x0DFFFFFF +#define SHARP_FERR_START 0x0E000001 +#define SHARP_FERR_END 0x0EFFFFFF +#define VTYSH_FERR_START 0x0F000001 +#define VTYSH_FRR_END 0x0FFFFFFF +#define WATCHFRR_FRR_START 0x10000001 +#define WATCHFRR_FRR_END 0x10FFFFFF +#define ZEBRA_FERR_START 0xF1000001 +#define ZEBRA_FERR_END 0xF1FFFFFF +#define END_FERR 0xFFFFFFFF struct ferr_ref { /* Unique error code displayed to end user as a reference. -1 means From a02ec79d1876a16a4d06542c88bfb1361a29d468 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 10:58:43 -0400 Subject: [PATCH 12/14] eigrpd: Convert to use LIB_ERR_XXX for zlog_err Convert, where appropriate, to using LIB_ERR_XXX for zlog_ferr Signed-off-by: Donald Sharp --- eigrpd/eigrp_network.c | 33 +++++++++++++++++++-------------- eigrpd/eigrp_packet.c | 6 ++++-- eigrpd/eigrp_topology.c | 4 +++- eigrpd/eigrpd.c | 7 +------ 4 files changed, 27 insertions(+), 23 deletions(-) diff --git a/eigrpd/eigrp_network.c b/eigrpd/eigrp_network.c index 2578fecb35cc..0f8b135d8893 100644 --- a/eigrpd/eigrp_network.c +++ b/eigrpd/eigrp_network.c @@ -37,6 +37,7 @@ #include "privs.h" #include "table.h" #include "vty.h" +#include "lib_errors.h" #include "eigrpd/eigrp_structs.h" #include "eigrpd/eigrpd.h" @@ -58,8 +59,9 @@ int eigrp_sock_init(void) int ret, hincl = 1; if (eigrpd_privs.change(ZPRIVS_RAISE)) - zlog_err("eigrp_sock_init: could not raise privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "eigrp_sock_init: could not raise privs, %s", + safe_strerror(errno)); eigrp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_EIGRPIGP); if (eigrp_sock < 0) { @@ -67,8 +69,8 @@ int eigrp_sock_init(void) if (eigrpd_privs.change(ZPRIVS_LOWER)) zlog_err("eigrp_sock_init: could not lower privs, %s", safe_strerror(errno)); - zlog_err("eigrp_read_sock_init: socket: %s", - safe_strerror(save_errno)); + zlog_ferr(LIB_ERR_SOCKET, "eigrp_read_sock_init: socket: %s", + safe_strerror(save_errno)); exit(1); } @@ -79,8 +81,9 @@ int eigrp_sock_init(void) if (ret < 0) { int save_errno = errno; if (eigrpd_privs.change(ZPRIVS_LOWER)) - zlog_err("eigrp_sock_init: could not lower privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "eigrp_sock_init: could not lower privs, %s", + safe_strerror(errno)); zlog_warn("Can't set IP_HDRINCL option for fd %d: %s", eigrp_sock, safe_strerror(save_errno)); } @@ -91,8 +94,9 @@ int eigrp_sock_init(void) if (ret < 0) { int save_errno = errno; if (eigrpd_privs.change(ZPRIVS_LOWER)) - zlog_err("eigrpd_sock_init: could not lower privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "eigrpd_sock_init: could not lower privs, %s", + safe_strerror(errno)); zlog_warn("can't set sockopt IP_TOS %d to socket %d: %s", tos, eigrp_sock, safe_strerror(save_errno)); close(eigrp_sock); /* Prevent sd leak. */ @@ -109,8 +113,9 @@ int eigrp_sock_init(void) zlog_warn("Can't set pktinfo option for fd %d", eigrp_sock); if (eigrpd_privs.change(ZPRIVS_LOWER)) { - zlog_err("eigrp_sock_init: could not lower privs, %s", - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, + "eigrp_sock_init: could not lower privs, %s", + safe_strerror(errno)); } return eigrp_sock; @@ -123,8 +128,8 @@ void eigrp_adjust_sndbuflen(struct eigrp *eigrp, unsigned int buflen) if (eigrp->maxsndbuflen >= buflen) return; if (eigrpd_privs.change(ZPRIVS_RAISE)) - zlog_err("%s: could not raise privs, %s", __func__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: could not raise privs, %s", + __func__, safe_strerror(errno)); /* Now we try to set SO_SNDBUF to what our caller has requested * (the MTU of a newly added interface). However, if the OS has @@ -143,8 +148,8 @@ void eigrp_adjust_sndbuflen(struct eigrp *eigrp, unsigned int buflen) else zlog_warn("%s: failed to get SO_SNDBUF", __func__); if (eigrpd_privs.change(ZPRIVS_LOWER)) - zlog_err("%s: could not lower privs, %s", __func__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_PRIVILEGES, "%s: could not lower privs, %s", + __func__, safe_strerror(errno)); } int eigrp_if_ipmulticast(struct eigrp *top, struct prefix *p, diff --git a/eigrpd/eigrp_packet.c b/eigrpd/eigrp_packet.c index 59864532cf9f..330631a71619 100644 --- a/eigrpd/eigrp_packet.c +++ b/eigrpd/eigrp_packet.c @@ -42,6 +42,7 @@ #include "checksum.h" #include "md5.h" #include "sha256.h" +#include "lib_errors.h" #include "eigrpd/eigrp_structs.h" #include "eigrpd/eigrpd.h" @@ -1212,8 +1213,9 @@ uint16_t eigrp_add_internalTLV_to_stream(struct stream *s, stream_putw(s, length); break; default: - zlog_err("%s: Unexpected prefix length: %d", - __PRETTY_FUNCTION__, pe->destination->prefixlen); + zlog_ferr(LIB_ERR_DEVELOPMENT, + "%s: Unexpected prefix length: %d", + __PRETTY_FUNCTION__, pe->destination->prefixlen); return 0; } stream_putl(s, 0x00000000); diff --git a/eigrpd/eigrp_topology.c b/eigrpd/eigrp_topology.c index becb29a95faa..525d98632747 100644 --- a/eigrpd/eigrp_topology.c +++ b/eigrpd/eigrp_topology.c @@ -37,6 +37,7 @@ #include "log.h" #include "linklist.h" #include "vty.h" +#include "lib_errors.h" #include "eigrpd/eigrp_structs.h" #include "eigrpd/eigrpd.h" @@ -408,7 +409,8 @@ eigrp_topology_update_distance(struct eigrp_fsm_action_message *msg) } break; default: - zlog_err("%s: Please implement handler", __PRETTY_FUNCTION__); + zlog_ferr(LIB_ERR_DEVELOPMENT, "%s: Please implement handler", + __PRETTY_FUNCTION__); break; } distance_done: diff --git a/eigrpd/eigrpd.c b/eigrpd/eigrpd.c index 24d1253cb9bb..a60d1a1b8da8 100644 --- a/eigrpd/eigrpd.c +++ b/eigrpd/eigrpd.c @@ -170,12 +170,7 @@ static struct eigrp *eigrp_new(const char *AS) eigrp->fd = eigrp_socket; eigrp->maxsndbuflen = getsockopt_so_sendbuf(eigrp->fd); - if ((eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN + 1)) == NULL) { - zlog_err( - "eigrp_new: fatal error: stream_new (%u) failed allocating ibuf", - EIGRP_PACKET_MAX_LEN + 1); - exit(1); - } + eigrp->ibuf = stream_new(EIGRP_PACKET_MAX_LEN + 1); eigrp->t_read = NULL; thread_add_read(master, eigrp_read, eigrp, eigrp->fd, &eigrp->t_read); From c3c755b5cde9d314b4208a0c4a850c4ee8e624c9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 10:59:27 -0400 Subject: [PATCH 13/14] ldpd: Convert to using LIB_ERR_XXX and zlog_ferr convert ldpd over to using zlog_ferr and LIB_ERR_XXX where appropriate. Signed-off-by: Donald Sharp --- ldpd/ldpd.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 255febeb6034..6754e5309820 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -42,6 +42,7 @@ #include "filter.h" #include "qobj.h" #include "libfrr.h" +#include "lib_errors.h" static void ldpd_shutdown(void); static pid_t start_child(enum ldpd_process, char *, int, int); @@ -450,8 +451,9 @@ start_child(enum ldpd_process p, char *argv0, int fd_async, int fd_sync) nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); if (nullfd == -1) { - zlog_err("%s: failed to open /dev/null: %s", __func__, - safe_strerror(errno)); + zlog_ferr(LIB_ERR_SYSTEM_CALL, + "%s: failed to open /dev/null: %s", __func__, + safe_strerror(errno)); } else { dup2(nullfd, 0); dup2(nullfd, 1); From 9014283a41ab037243bbb7e891773758fe2b2b60 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 18 Jun 2018 11:29:50 -0400 Subject: [PATCH 14/14] ospfd: Memory asserts on failure to create no need to check Memory Asserts on failure to allocate new memory, no need to check for success failure in these cases. Signed-off-by: Donald Sharp --- ospfd/ospf_apiserver.c | 20 +++----------------- ospfd/ospf_ext.c | 32 -------------------------------- ospfd/ospf_lsa.c | 30 +++++------------------------- ospfd/ospf_ri.c | 19 +++---------------- ospfd/ospf_te.c | 19 +++---------------- ospfd/ospfd.c | 7 +------ 6 files changed, 15 insertions(+), 112 deletions(-) diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c index d19b04682a79..39660d525cf9 100644 --- a/ospfd/ospf_apiserver.c +++ b/ospfd/ospf_apiserver.c @@ -1390,10 +1390,7 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, assert(ospf); /* Create a stream for internal opaque LSA */ - if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { - zlog_warn("ospf_apiserver_opaque_lsa_new: stream_new failed"); - return NULL; - } + s = stream_new(OSPF_MAX_LSA_SIZE); newlsa = (struct lsa_header *)STREAM_DATA(s); @@ -1425,19 +1422,8 @@ struct ospf_lsa *ospf_apiserver_opaque_lsa_new(struct ospf_area *area, newlsa->length = htons(length); /* Create OSPF LSA. */ - if ((new = ospf_lsa_new()) == NULL) { - zlog_warn("ospf_apiserver_opaque_lsa_new: ospf_lsa_new() ?"); - stream_free(s); - return NULL; - } - - if ((new->data = ospf_lsa_data_new(length)) == NULL) { - zlog_warn( - "ospf_apiserver_opaque_lsa_new: ospf_lsa_data_new() ?"); - ospf_lsa_unlock(&new); - stream_free(s); - return NULL; - } + new = ospf_lsa_new(); + new->data = ospf_lsa_data_new(length); new->area = area; new->oi = oi; diff --git a/ospfd/ospf_ext.c b/ospfd/ospf_ext.c index 47ae9adb7ef0..97610701a60c 100644 --- a/ospfd/ospf_ext.c +++ b/ospfd/ospf_ext.c @@ -929,10 +929,6 @@ static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area, /* Create a stream for LSA. */ s = stream_new(OSPF_MAX_LSA_SIZE); - if (s == NULL) { - zlog_warn("EXT (%s): stream_new() error", __func__); - return NULL; - } /* Prepare LSA Header */ lsah = (struct lsa_header *)STREAM_DATA(s); @@ -978,19 +974,7 @@ static struct ospf_lsa *ospf_ext_pref_lsa_new(struct ospf_area *area, /* Now, create an OSPF LSA instance. */ new = ospf_lsa_new(); - if (new == NULL) { - zlog_warn("EXT (%s): ospf_lsa_new() error", __func__); - stream_free(s); - return NULL; - } new->data = ospf_lsa_data_new(length); - if (new->data == NULL) { - zlog_warn("EXT (%s): ospf_lsa_data_new() error", __func__); - ospf_lsa_unlock(&new); - new = NULL; - stream_free(s); - return NULL; - } /* Segment Routing belongs only to default VRF */ new->vrf_id = VRF_DEFAULT; @@ -1020,10 +1004,6 @@ static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area, /* Create a stream for LSA. */ s = stream_new(OSPF_MAX_LSA_SIZE); - if (s == NULL) { - zlog_warn("EXT (%s): stream_new() error", __func__); - return NULL; - } lsah = (struct lsa_header *)STREAM_DATA(s); options = OSPF_OPTION_O; /* Don't forget this :-) */ @@ -1057,19 +1037,7 @@ static struct ospf_lsa *ospf_ext_link_lsa_new(struct ospf_area *area, /* Now, create an OSPF LSA instance. */ new = ospf_lsa_new(); - if (new == NULL) { - zlog_warn("EXT (%s): ospf_lsa_new() error", __func__); - stream_free(s); - return NULL; - } new->data = ospf_lsa_data_new(length); - if (new->data == NULL) { - zlog_warn("EXT (%s): ospf_lsa_data_new() error", __func__); - ospf_lsa_unlock(&new); - new = NULL; - stream_free(s); - return NULL; - } /* Segment Routing belongs only to default VRF */ new->vrf_id = VRF_DEFAULT; diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c index e6b513cf9749..1b5ce1d562d8 100644 --- a/ospfd/ospf_lsa.c +++ b/ospfd/ospf_lsa.c @@ -781,10 +781,7 @@ static struct ospf_lsa *ospf_router_lsa_new(struct ospf_area *area) lsah->length = htons(length); /* Now, create OSPF LSA instance. */ - if ((new = ospf_lsa_new()) == NULL) { - zlog_err("%s: Unable to create new lsa", __func__); - return NULL; - } + new = ospf_lsa_new(); new->area = area; SET_FLAG(new->flags, OSPF_LSA_SELF | OSPF_LSA_SELF_CHECKED); @@ -804,10 +801,7 @@ static struct ospf_lsa *ospf_router_lsa_originate(struct ospf_area *area) struct ospf_lsa *new; /* Create new router-LSA instance. */ - if ((new = ospf_router_lsa_new(area)) == NULL) { - zlog_err("%s: ospf_router_lsa_new returned NULL", __func__); - return NULL; - } + new = ospf_router_lsa_new(area); /* Sanity check. */ if (new->data->adv_router.s_addr == 0) { @@ -852,10 +846,7 @@ static struct ospf_lsa *ospf_router_lsa_refresh(struct ospf_lsa *lsa) ospf_refresher_unregister_lsa(area->ospf, lsa); /* Create new router-LSA instance. */ - if ((new = ospf_router_lsa_new(area)) == NULL) { - zlog_err("%s: ospf_router_lsa_new returned NULL", __func__); - return NULL; - } + new = ospf_router_lsa_new(area); new->data->ls_seqnum = lsa_seqnum_increment(lsa); @@ -997,10 +988,7 @@ static struct ospf_lsa *ospf_network_lsa_new(struct ospf_interface *oi) lsah->length = htons(length); /* Create OSPF LSA instance. */ - if ((new = ospf_lsa_new()) == NULL) { - zlog_err("%s: ospf_lsa_new returned NULL", __func__); - return NULL; - } + new = ospf_lsa_new(); new->area = oi->area; SET_FLAG(new->flags, OSPF_LSA_SELF | OSPF_LSA_SELF_CHECKED); @@ -1040,8 +1028,6 @@ void ospf_network_lsa_update(struct ospf_interface *oi) /* Create new network-LSA instance. */ new = ospf_network_lsa_new(oi); - if (new == NULL) - return; /* Install LSA to LSDB. */ new = ospf_lsa_install(oi->ospf, oi, new); @@ -1091,8 +1077,6 @@ static struct ospf_lsa *ospf_network_lsa_refresh(struct ospf_lsa *lsa) /* Create new network-LSA instance. */ new = ospf_network_lsa_new(oi); - if (new == NULL) - return NULL; oip = ospf_lookup_if_params(oi->ifp, oi->address->u.prefix4); assert(oip != NULL); @@ -1214,8 +1198,7 @@ struct ospf_lsa *ospf_summary_lsa_originate(struct prefix_ipv4 *p, } /* Create new summary-LSA instance. */ - if (!(new = ospf_summary_lsa_new(area, (struct prefix *)p, metric, id))) - return NULL; + new = ospf_summary_lsa_new(area, (struct prefix *)p, metric, id); /* Instlal LSA to LSDB. */ new = ospf_lsa_install(area->ospf, NULL, new); @@ -1251,9 +1234,6 @@ static struct ospf_lsa *ospf_summary_lsa_refresh(struct ospf *ospf, new = ospf_summary_lsa_new(lsa->area, &p, GET_METRIC(sl->metric), sl->header.id); - if (!new) - return NULL; - new->data->ls_seqnum = lsa_seqnum_increment(lsa); ospf_lsa_install(ospf, NULL, new); diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index 786b1990290c..975af01c76fa 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -741,10 +741,7 @@ static struct ospf_lsa *ospf_router_info_lsa_new() uint16_t length; /* Create a stream for LSA. */ - if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { - zlog_warn("ospf_router_info_lsa_new: stream_new() ?"); - return NULL; - } + s = stream_new(OSPF_MAX_LSA_SIZE); lsah = (struct lsa_header *)STREAM_DATA(s); options = OSPF_OPTION_E; /* Enable AS external as we flood RI with @@ -774,18 +771,8 @@ static struct ospf_lsa *ospf_router_info_lsa_new() lsah->length = htons(length); /* Now, create an OSPF LSA instance. */ - if ((new = ospf_lsa_new()) == NULL) { - zlog_warn("ospf_router_info_lsa_new: ospf_lsa_new() ?"); - stream_free(s); - return NULL; - } - if ((new->data = ospf_lsa_data_new(length)) == NULL) { - zlog_warn("ospf_router_info_lsa_new: ospf_lsa_data_new() ?"); - ospf_lsa_unlock(&new); - new = NULL; - stream_free(s); - return new; - } + new = ospf_lsa_new(); + new->data = ospf_lsa_data_new(length); new->area = OspfRI.area; /* Area must be null if the Opaque type is AS scope, fulfill otherwise */ diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index dabdf286dc30..00f5dc94eac9 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -1146,10 +1146,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf, uint16_t length; /* Create a stream for LSA. */ - if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { - zlog_warn("ospf_mpls_te_lsa_new: stream_new() ?"); - return NULL; - } + s = stream_new(OSPF_MAX_LSA_SIZE); lsah = (struct lsa_header *)STREAM_DATA(s); options = OSPF_OPTION_O; /* Don't forget this :-) */ @@ -1201,18 +1198,8 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf *ospf, lsah->length = htons(length); /* Now, create an OSPF LSA instance. */ - if ((new = ospf_lsa_new()) == NULL) { - zlog_warn("%s: ospf_lsa_new() ?", __func__); - stream_free(s); - return NULL; - } - if ((new->data = ospf_lsa_data_new(length)) == NULL) { - zlog_warn("%s: ospf_lsa_data_new() ?", __func__); - ospf_lsa_unlock(&new); - new = NULL; - stream_free(s); - return new; - } + new = ospf_lsa_new(); + new->data = ospf_lsa_data_new(length); new->vrf_id = ospf->vrf_id; if (area && area->ospf) diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index 4cf38439c658..e712a5c21a10 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -308,12 +308,7 @@ static struct ospf *ospf_new(unsigned short instance, const char *name) new->lsa_refresh_interval, &new->t_lsa_refresher); new->lsa_refresher_started = monotime(NULL); - if ((new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1)) == NULL) { - zlog_err( - "ospf_new: fatal error: stream_new(%u) failed allocating ibuf", - OSPF_MAX_PACKET_SIZE + 1); - exit(1); - } + new->ibuf = stream_new(OSPF_MAX_PACKET_SIZE + 1); new->t_read = NULL; new->oi_write_q = list_new(); new->write_oi_count = OSPF_WRITE_INTERFACE_COUNT_DEFAULT;