summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChirag Shah <chirag@cumulusnetworks.com>2018-06-19 22:41:28 +0200
committerQuentin Young <qlyoung@cumulusnetworks.com>2018-08-14 22:02:05 +0200
commit313d7993a35571dabf8c2b2ecdf538b0686aae74 (patch)
treefed04413cd7b3b49cf8ce678162891bc37266de3
parentlib: Convert zlog_err for clippy build (diff)
downloadfrr-313d7993a35571dabf8c2b2ecdf538b0686aae74.tar.xz
frr-313d7993a35571dabf8c2b2ecdf538b0686aae74.zip
ospfd: zlog_ferr facility
Ticket:CM-21333 Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com> Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
-rw-r--r--ospf6d/ospf6_network.c4
-rw-r--r--ospfd/ospf_errors.c84
-rw-r--r--ospfd/ospf_errors.h38
-rw-r--r--ospfd/ospf_main.c4
-rw-r--r--ospfd/ospf_network.c26
-rw-r--r--ospfd/ospf_packet.c30
-rw-r--r--ospfd/ospf_sr.c62
-rw-r--r--ospfd/ospfd.c20
-rw-r--r--ospfd/subdir.am2
9 files changed, 208 insertions, 62 deletions
diff --git a/ospf6d/ospf6_network.c b/ospf6d/ospf6_network.c
index 86481e46c..57414a2d0 100644
--- a/ospf6d/ospf6_network.c
+++ b/ospf6d/ospf6_network.c
@@ -85,12 +85,12 @@ int ospf6_serv_sock(void)
zlog_warn("Network: can't create OSPF6 socket.");
if (ospf6d_privs.change(ZPRIVS_LOWER))
zlog_ferr(LIB_ERR_PRIVILEGES,
- "ospf_sock_init: could not lower privs");
+ "ospf6_sock_init: could not lower privs");
return -1;
}
if (ospf6d_privs.change(ZPRIVS_LOWER))
zlog_ferr(LIB_ERR_PRIVILEGES,
- "ospf_sock_init: could not lower privs");
+ "ospf6_sock_init: could not lower privs");
/* set socket options */
#if 1
diff --git a/ospfd/ospf_errors.c b/ospfd/ospf_errors.c
new file mode 100644
index 000000000..7f94080ce
--- /dev/null
+++ b/ospfd/ospf_errors.c
@@ -0,0 +1,84 @@
+/*
+ * ospf_errors - code for error messages that may occur in the
+ * ospf process
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Chirag Shah
+ *
+ * FRR is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2, or (at your option) any
+ * later version.
+ *
+ * FRR is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+#include <zebra.h>
+#include "ospf_errors.h"
+
+static struct ferr_ref ferr_ospf_err[] = {
+ {
+ .code = OSPF_ERR_PKT_PROCESS,
+ .title = "Failure to process a packet",
+ .description = "OSPF attempted to process a received packet but could not",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_ROUTER_LSA_MISMATCH,
+ .title = "Failure to process Router LSA",
+ .description = "OSPF attempted to process a Router LSA but Advertising ID mismtach with link id",
+ .suggestion = "Check OSPF network config for any config issue, If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_DOMAIN_CORRUPT,
+ .title = "OSPF Domain Corruption",
+ .description = "OSPF attempted to process a Router LSA but Advertising ID mismtach with link id",
+ .suggestion = "Check OSPF network Database for corrupted LSA, If the problem persists, shutdown ospf domain and report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_INIT_FAIL,
+ .title = "OSPF Initialization failure",
+ .description = "OSPF failed to initialized ospf default insance",
+ .suggestion = "Ensure there is adequate memory on the device. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_SR_INVALID_DB,
+ .title = "OSPF SR Invalid DB",
+ .description = "OSPF Segment Routing Database is invalid",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_SR_NODE_CREATE,
+ .title = "OSPF SR hash node creation failed",
+ .description = "OSPF Segment Routing node creation failed",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_SR_INVALID_LSA_ID,
+ .title = "OSPF SR Invalid lsa id",
+ .description = "OSPF Segment Routing invalid lsa id",
+ .suggestion = "Restart ospf instance, If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = OSPF_ERR_SR_INVALID_ALGORITHM,
+ .title = "OSPF SR Invalid Algorithm",
+ .description = "OSPF Segment Routing invalid Algorithm",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+
+ {
+ .code = END_FERR,
+ }
+};
+
+void ospf_error_init(void)
+{
+ ferr_ref_init();
+
+ ferr_ref_add(ferr_ospf_err);
+}
diff --git a/ospfd/ospf_errors.h b/ospfd/ospf_errors.h
new file mode 100644
index 000000000..a9813640f
--- /dev/null
+++ b/ospfd/ospf_errors.h
@@ -0,0 +1,38 @@
+/*
+ * ospf_errors - header for error messages that may occur in the ospf process
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Chirag Shah
+ *
+ * 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 __OSPF_ERRORS_H__
+#define __OSPF_ERRORS_H__
+
+#include "ferr.h"
+
+enum ospf_ferr_refs {
+ OSPF_ERR_PKT_PROCESS = OSPF_FERR_START,
+ OSPF_ERR_ROUTER_LSA_MISMATCH,
+ OSPF_ERR_DOMAIN_CORRUPT,
+ OSPF_ERR_INIT_FAIL,
+ OSPF_ERR_SR_INVALID_DB,
+ OSPF_ERR_SR_NODE_CREATE,
+ OSPF_ERR_SR_INVALID_LSA_ID,
+ OSPF_ERR_SR_INVALID_ALGORITHM,
+};
+
+extern void ospf_error_init(void);
+
+#endif
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 5bf7ec146..1a25e27d7 100644
--- a/ospfd/ospf_main.c
+++ b/ospfd/ospf_main.c
@@ -52,6 +52,7 @@
#include "ospfd/ospf_zebra.h"
#include "ospfd/ospf_vty.h"
#include "ospfd/ospf_bfd.h"
+#include "ospfd/ospf_errors.h"
/* ospfd privileges */
zebra_capabilities_t _caps_p[] = {ZCAP_NET_RAW, ZCAP_BIND, ZCAP_NET_ADMIN,
@@ -211,7 +212,8 @@ int main(int argc, char **argv)
ospf',
when quagga(ospfd) is restarted */
if (!ospf_get_instance(instance)) {
- zlog_err("OSPF instance init failed: %s", strerror(errno));
+ zlog_ferr(OSPF_ERR_INIT_FAIL, "OSPF instance init failed: %s",
+ strerror(errno));
exit(1);
}
diff --git a/ospfd/ospf_network.c b/ospfd/ospf_network.c
index d7cca0f13..c51533865 100644
--- a/ospfd/ospf_network.c
+++ b/ospfd/ospf_network.c
@@ -29,6 +29,7 @@
#include "log.h"
#include "sockopt.h"
#include "privs.h"
+#include "lib_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
@@ -185,10 +186,10 @@ int ospf_sock_init(struct ospf *ospf)
/* silently return since VRF is not ready */
return -1;
}
- if (ospfd_privs.change(ZPRIVS_RAISE)) {
- zlog_err("ospf_sock_init: could not raise privs, %s",
- safe_strerror(errno));
- }
+ if (ospfd_privs.change(ZPRIVS_RAISE))
+ zlog_ferr(LIB_ERR_PRIVILEGES,
+ "ospf_sock_init: could not raise privs, %s",
+ safe_strerror(errno));
ospf_sock = vrf_socket(AF_INET, SOCK_RAW, IPPROTO_OSPFIGP, ospf->vrf_id,
ospf->name);
@@ -196,10 +197,10 @@ int ospf_sock_init(struct ospf *ospf)
int save_errno = errno;
if (ospfd_privs.change(ZPRIVS_LOWER))
- zlog_err("ospf_sock_init: could not lower privs, %s",
- safe_strerror(errno));
- zlog_err("ospf_read_sock_init: socket: %s",
- safe_strerror(save_errno));
+ zlog_ferr(LIB_ERR_PRIVILEGES,
+ "ospf_sock_init: could not lower privs, %s",
+ safe_strerror(save_errno));
+
exit(1);
}
@@ -242,9 +243,10 @@ int ospf_sock_init(struct ospf *ospf)
ospf->fd = ospf_sock;
out:
- if (ospfd_privs.change(ZPRIVS_LOWER)) {
- zlog_err("ospf_sock_init: could not lower privs, %s",
- safe_strerror(errno));
- }
+ if (ospfd_privs.change(ZPRIVS_LOWER))
+ zlog_ferr(LIB_ERR_PRIVILEGES,
+ "ospf_sock_init: could not lower privs, %s",
+ safe_strerror(errno));
+
return ret;
}
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 486ef3335..074e385fa 100644
--- a/ospfd/ospf_packet.c
+++ b/ospfd/ospf_packet.c
@@ -35,6 +35,7 @@
#include "checksum.h"
#include "md5.h"
#include "vrf.h"
+#include "ospf_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
@@ -230,7 +231,8 @@ void ospf_fifo_free(struct ospf_fifo *fifo)
void ospf_packet_add(struct ospf_interface *oi, struct ospf_packet *op)
{
if (!oi->obuf) {
- zlog_err(
+ zlog_ferr(
+ OSPF_ERR_PKT_PROCESS,
"ospf_packet_add(interface %s in state %d [%s], packet type %s, "
"destination %s) called with NULL obuf, ignoring "
"(please report this bug)!\n",
@@ -253,7 +255,8 @@ static void ospf_packet_add_top(struct ospf_interface *oi,
struct ospf_packet *op)
{
if (!oi->obuf) {
- zlog_err(
+ zlog_ferr(
+ OSPF_ERR_PKT_PROCESS,
"ospf_packet_add(interface %s in state %d [%s], packet type %s, "
"destination %s) called with NULL obuf, ignoring "
"(please report this bug)!\n",
@@ -1915,17 +1918,18 @@ static void ospf_ls_upd(struct ospf *ospf, struct ip *iph,
char buf2[INET_ADDRSTRLEN];
char buf3[INET_ADDRSTRLEN];
- zlog_err(
- "Incoming Router-LSA from %s with "
- "Adv-ID[%s] != LS-ID[%s]",
- inet_ntop(AF_INET, &ospfh->router_id,
- buf1, INET_ADDRSTRLEN),
- inet_ntop(AF_INET, &lsa->data->id, buf2,
- INET_ADDRSTRLEN),
- inet_ntop(AF_INET,
- &lsa->data->adv_router, buf3,
- INET_ADDRSTRLEN));
- zlog_err(
+ zlog_ferr(OSPF_ERR_ROUTER_LSA_MISMATCH,
+ "Incoming Router-LSA from %s with "
+ "Adv-ID[%s] != LS-ID[%s]",
+ inet_ntop(AF_INET, &ospfh->router_id,
+ buf1, INET_ADDRSTRLEN),
+ inet_ntop(AF_INET, &lsa->data->id,
+ buf2, INET_ADDRSTRLEN),
+ inet_ntop(AF_INET,
+ &lsa->data->adv_router,
+ buf3, INET_ADDRSTRLEN));
+ zlog_ferr(
+ OSPF_ERR_DOMAIN_CORRUPT,
"OSPF domain compromised by attack or corruption. "
"Verify correct operation of -ALL- OSPF routers.");
DISCARD_LSA(lsa, 0);
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index 25983ddc5..629edbf37 100644
--- a/ospfd/ospf_sr.c
+++ b/ospfd/ospf_sr.c
@@ -48,6 +48,7 @@
#include "vty.h"
#include "zclient.h"
#include <lib/json.h>
+#include "ospf_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
@@ -820,8 +821,9 @@ static struct sr_prefix *get_ext_prefix_sid(struct tlv_header *tlvh)
case EXT_SUBTLV_PREFIX_SID:
psid = (struct ext_subtlv_prefix_sid *)sub_tlvh;
if (psid->algorithm != SR_ALGORITHM_SPF) {
- zlog_err("SR (%s): Unsupported Algorithm",
- __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_ALGORITHM,
+ "SR (%s): Unsupported Algorithm",
+ __func__);
XFREE(MTYPE_OSPF_SR_PARAMS, srp);
return NULL;
}
@@ -1100,7 +1102,8 @@ void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa)
return;
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1110,17 +1113,18 @@ void ospf_sr_ri_lsa_update(struct ospf_lsa *lsa)
/* Sanity check */
if (srn == NULL) {
- zlog_err("SR (%s): Abort! can't create SR node in hash table",
- __func__);
+ zlog_ferr(OSPF_ERR_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
if ((srn->instance != 0) && (srn->instance != ntohl(lsah->id.s_addr))) {
- zlog_err(
- "SR (%s): Abort! Wrong "
- "LSA ID 4.0.0.%u for SR node %s/%u",
- __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
- inet_ntoa(lsah->adv_router), srn->instance);
+ zlog_ferr(OSPF_ERR_SR_INVALID_LSA_ID,
+ "SR (%s): Abort! Wrong "
+ "LSA ID 4.0.0.%u for SR node %s/%u",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ inet_ntoa(lsah->adv_router), srn->instance);
return;
}
@@ -1209,7 +1213,8 @@ void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa)
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR Data Base", __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR Data Base", __func__);
return;
}
@@ -1218,15 +1223,18 @@ void ospf_sr_ri_lsa_delete(struct ospf_lsa *lsa)
/* Sanity check */
if (srn == NULL) {
- zlog_err("SR (%s): Abort! no entry in SRDB for SR Node %s",
- __func__, inet_ntoa(lsah->adv_router));
+ zlog_ferr(OSPF_ERR_SR_NODE_CREATE,
+ "SR (%s): Abort! no entry in SRDB for SR Node %s",
+ __func__, inet_ntoa(lsah->adv_router));
return;
}
if ((srn->instance != 0) && (srn->instance != ntohl(lsah->id.s_addr))) {
- zlog_err("SR (%s): Abort! Wrong LSA ID 4.0.0.%u for SR node %s",
- __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
- inet_ntoa(lsah->adv_router));
+ zlog_ferr(
+ OSPF_ERR_SR_INVALID_LSA_ID,
+ "SR (%s): Abort! Wrong LSA ID 4.0.0.%u for SR node %s",
+ __func__, GET_OPAQUE_ID(ntohl(lsah->id.s_addr)),
+ inet_ntoa(lsah->adv_router));
return;
}
@@ -1252,7 +1260,8 @@ void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa)
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1263,8 +1272,9 @@ void ospf_sr_ext_link_lsa_update(struct ospf_lsa *lsa)
/* Sanity check */
if (srn == NULL) {
- zlog_err("SR (%s): Abort! can't create SR node in hash table",
- __func__);
+ zlog_ferr(OSPF_ERR_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
@@ -1302,7 +1312,8 @@ void ospf_sr_ext_link_lsa_delete(struct ospf_lsa *lsa)
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1359,7 +1370,8 @@ void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa)
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1370,8 +1382,9 @@ void ospf_sr_ext_prefix_lsa_update(struct ospf_lsa *lsa)
/* Sanity check */
if (srn == NULL) {
- zlog_err("SR (%s): Abort! can't create SR node in hash table",
- __func__);
+ zlog_ferr(OSPF_ERR_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
@@ -1410,7 +1423,8 @@ void ospf_sr_ext_prefix_lsa_delete(struct ospf_lsa *lsa)
/* Sanity check */
if (OspfSR.neighbors == NULL) {
- zlog_err("SR (%s): Abort! no valid SR DataBase", __func__);
+ zlog_ferr(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 2298c2261..c4bb1ca55 100644
--- a/ospfd/ospfd.c
+++ b/ospfd/ospfd.c
@@ -38,6 +38,7 @@
#include "bfd.h"
#include "libfrr.h"
#include "defaults.h"
+#include "lib_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
@@ -2087,11 +2088,10 @@ static int ospf_vrf_enable(struct vrf *vrf)
old_vrf_id);
if (old_vrf_id != ospf->vrf_id) {
- if (ospfd_privs.change(ZPRIVS_RAISE)) {
- zlog_err(
- "ospf_sock_init: could not raise privs, %s",
- safe_strerror(errno));
- }
+ if (ospfd_privs.change(ZPRIVS_RAISE))
+ zlog_ferr(
+ LIB_ERR_PRIVILEGES,
+ "ospf_vrf_link: could not raise privs");
/* stop zebra redist to us for old vrf */
zclient_send_dereg_requests(zclient, old_vrf_id);
@@ -2102,11 +2102,11 @@ static int ospf_vrf_enable(struct vrf *vrf)
ospf_zebra_vrf_register(ospf);
ret = ospf_sock_init(ospf);
- if (ospfd_privs.change(ZPRIVS_LOWER)) {
- zlog_err(
- "ospf_sock_init: could not lower privs, %s",
- safe_strerror(errno));
- }
+ if (ospfd_privs.change(ZPRIVS_LOWER))
+ zlog_ferr(
+ LIB_ERR_PRIVILEGES,
+ "ospf_sock_init: could not lower privs");
+
if (ret < 0 || ospf->fd <= 0)
return 0;
thread_add_read(master, ospf_read, ospf, ospf->fd,
diff --git a/ospfd/subdir.am b/ospfd/subdir.am
index f2e292e18..cd659a9bc 100644
--- a/ospfd/subdir.am
+++ b/ospfd/subdir.am
@@ -20,6 +20,7 @@ ospfd_libfrrospf_a_SOURCES = \
ospfd/ospf_bfd.c \
ospfd/ospf_dump.c \
ospfd/ospf_dump_api.c \
+ ospfd/ospf_errors.c \
ospfd/ospf_ext.c \
ospfd/ospf_flood.c \
ospfd/ospf_ia.c \
@@ -68,6 +69,7 @@ noinst_HEADERS += \
ospfd/ospf_apiserver.h \
ospfd/ospf_ase.h \
ospfd/ospf_bfd.h \
+ ospfd/ospf_errors.h \
ospfd/ospf_ext.h \
ospfd/ospf_flood.h \
ospfd/ospf_ia.h \