]> git.proxmox.com Git - mirror_frr.git/commitdiff
ospfd: zlog_ferr facility
authorChirag Shah <chirag@cumulusnetworks.com>
Tue, 19 Jun 2018 20:41:28 +0000 (16:41 -0400)
committerQuentin Young <qlyoung@cumulusnetworks.com>
Tue, 14 Aug 2018 20:02:05 +0000 (20:02 +0000)
Ticket:CM-21333

Signed-off-by: Chirag Shah <chirag@cumulusnetworks.com>
Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
ospf6d/ospf6_network.c
ospfd/ospf_errors.c [new file with mode: 0644]
ospfd/ospf_errors.h [new file with mode: 0644]
ospfd/ospf_main.c
ospfd/ospf_network.c
ospfd/ospf_packet.c
ospfd/ospf_sr.c
ospfd/ospfd.c
ospfd/subdir.am

index 86481e46c6cfe4653840ca021d98a5638228eb3a..57414a2d063c5c1d64a88f6949a1091e05a8eaf1 100644 (file)
@@ -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 (file)
index 0000000..7f94080
--- /dev/null
@@ -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 (file)
index 0000000..a981364
--- /dev/null
@@ -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
index 5bf7ec14698ed5d6fe65ec57a0c38c822967d871..1a25e27d7a5f23fffa2befd7a0f02c365d0babeb 100644 (file)
@@ -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);
        }
 
index d7cca0f1332fe30d78eeaf0b6305fc350d6744eb..c51533865d22330d66c548fc4fac8e52013ac2e8 100644 (file)
@@ -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;
 }
index 486ef3335d473077284252b3a3ef75666723a5a7..074e385fa332f0b91dd27f73bff08f4f00ff6ef3 100644 (file)
@@ -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);
index 25983ddc57c142efe49cfe5049c7f4d65a6b93c4..629edbf370641fbf6225aa3f8bef5a7c7765a2bd 100644 (file)
@@ -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;
        }
 
index 2298c2261a9af283c587dd5e29da86598cdb24e0..c4bb1ca55234c20c34823f2c981544705f53ab93 100644 (file)
@@ -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,
index f2e292e186b5e438bd7366377a5e34c6f4deb8ca..cd659a9bc92592448beb1de28040a1b992df6d9b 100644 (file)
@@ -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 \