summaryrefslogtreecommitdiff
path: root/ospfd
diff options
context:
space:
mode:
Diffstat (limited to 'ospfd')
-rw-r--r--ospfd/ospf_apiserver.c12
-rw-r--r--ospfd/ospf_bfd.c20
-rw-r--r--ospfd/ospf_errors.c84
-rw-r--r--ospfd/ospf_errors.h39
-rw-r--r--ospfd/ospf_ext.c5
-rw-r--r--ospfd/ospf_interface.c3
-rw-r--r--ospfd/ospf_lsa.c27
-rw-r--r--ospfd/ospf_main.c7
-rw-r--r--ospfd/ospf_network.c80
-rw-r--r--ospfd/ospf_opaque.c29
-rw-r--r--ospfd/ospf_packet.c30
-rw-r--r--ospfd/ospf_spf.c3
-rw-r--r--ospfd/ospf_sr.c74
-rw-r--r--ospfd/ospf_te.c5
-rw-r--r--ospfd/ospfd.c25
-rw-r--r--ospfd/subdir.am2
16 files changed, 268 insertions, 177 deletions
diff --git a/ospfd/ospf_apiserver.c b/ospfd/ospf_apiserver.c
index 8f8900e147..c0ce971f0c 100644
--- a/ospfd/ospf_apiserver.c
+++ b/ospfd/ospf_apiserver.c
@@ -1176,13 +1176,11 @@ int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv,
apiserv->filter =
XMALLOC(MTYPE_OSPF_APISERVER_MSGFILTER, ntohs(msg->hdr.msglen));
- if (apiserv->filter) {
- /* copy it over. */
- memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen));
- rc = OSPF_API_OK;
- } else {
- rc = OSPF_API_NOMEMORY;
- }
+
+ /* copy it over. */
+ memcpy(apiserv->filter, &rmsg->filter, ntohs(msg->hdr.msglen));
+ rc = OSPF_API_OK;
+
/* Send a reply back to client with return code */
rc = ospf_apiserver_send_reply(apiserv, seqnum, rc);
return rc;
diff --git a/ospfd/ospf_bfd.c b/ospfd/ospf_bfd.c
index 0f7fb50778..df41897660 100644
--- a/ospfd/ospf_bfd.c
+++ b/ospfd/ospf_bfd.c
@@ -290,17 +290,21 @@ void ospf_bfd_info_nbr_create(struct ospf_interface *oi,
void ospf_bfd_write_config(struct vty *vty, struct ospf_if_params *params)
{
+#if HAVE_BFDD == 0
struct bfd_info *bfd_info;
+#endif /* ! HAVE_BFDD */
if (!params->bfd_info)
return;
+#if HAVE_BFDD == 0
bfd_info = (struct bfd_info *)params->bfd_info;
if (CHECK_FLAG(bfd_info->flags, BFD_FLAG_PARAM_CFG))
vty_out(vty, " ip ospf bfd %d %d %d\n", bfd_info->detect_mult,
bfd_info->required_min_rx, bfd_info->desired_min_tx);
else
+#endif /* ! HAVE_BFDD */
vty_out(vty, " ip ospf bfd\n");
}
@@ -373,7 +377,12 @@ DEFUN (ip_ospf_bfd,
return CMD_SUCCESS;
}
-DEFUN (ip_ospf_bfd_param,
+#if HAVE_BFDD > 0
+DEFUN_HIDDEN(
+#else
+DEFUN(
+#endif /* HAVE_BFDD */
+ ip_ospf_bfd_param,
ip_ospf_bfd_param_cmd,
"ip ospf bfd (2-255) (50-60000) (50-60000)",
"IP Information\n"
@@ -407,14 +416,21 @@ DEFUN (ip_ospf_bfd_param,
DEFUN (no_ip_ospf_bfd,
no_ip_ospf_bfd_cmd,
+#if HAVE_BFDD > 0
+ "no ip ospf bfd",
+#else
"no ip ospf bfd [(2-255) (50-60000) (50-60000)]",
+#endif /* HAVE_BFDD */
NO_STR
"IP Information\n"
"OSPF interface commands\n"
"Disables BFD support\n"
+#if HAVE_BFDD == 0
"Detect Multiplier\n"
"Required min receive interval\n"
- "Desired min transmit interval\n")
+ "Desired min transmit interval\n"
+#endif /* !HAVE_BFDD */
+)
{
VTY_DECLVAR_CONTEXT(interface, ifp);
struct ospf_if_params *params;
diff --git a/ospfd/ospf_errors.c b/ospfd/ospf_errors.c
new file mode 100644
index 0000000000..2927f7cb14
--- /dev/null
+++ b/ospfd/ospf_errors.c
@@ -0,0 +1,84 @@
+/*
+ * OSPF-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Chirag Shah
+ *
+ * This program 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 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 "lib/ferr.h"
+#include "ospf_errors.h"
+
+static struct log_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 mismatch 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 mismatch 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)
+{
+ log_ref_add(ferr_ospf_err);
+}
diff --git a/ospfd/ospf_errors.h b/ospfd/ospf_errors.h
new file mode 100644
index 0000000000..c3f1018550
--- /dev/null
+++ b/ospfd/ospf_errors.h
@@ -0,0 +1,39 @@
+/*
+ * OSPF-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Chirag Shah
+ *
+ * This program 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 of the License, or (at your option)
+ * any later version.
+ *
+ * This program 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 "lib/ferr.h"
+
+enum ospf_log_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_ext.c b/ospfd/ospf_ext.c
index 331cba44a8..b8d14c351e 100644
--- a/ospfd/ospf_ext.c
+++ b/ospfd/ospf_ext.c
@@ -545,11 +545,6 @@ static int ospf_ext_link_new_if(struct interface *ifp)
}
new = XCALLOC(MTYPE_OSPF_EXT_PARAMS, sizeof(struct ext_itf));
- if (new == NULL) {
- zlog_warn("EXT (%s): XCALLOC: %s", __func__,
- safe_strerror(errno));
- return rc;
- }
/* initialize new information and link back the interface */
new->ifp = ifp;
diff --git a/ospfd/ospf_interface.c b/ospfd/ospf_interface.c
index 23353b3c30..24584f6713 100644
--- a/ospfd/ospf_interface.c
+++ b/ospfd/ospf_interface.c
@@ -523,9 +523,6 @@ static struct ospf_if_params *ospf_new_if_params(void)
oip = XCALLOC(MTYPE_OSPF_IF_PARAMS, sizeof(struct ospf_if_params));
- if (!oip)
- return NULL;
-
UNSET_IF_PARAM(oip, output_cost_cmd);
UNSET_IF_PARAM(oip, transmit_delay);
UNSET_IF_PARAM(oip, retransmit_interval);
diff --git a/ospfd/ospf_lsa.c b/ospfd/ospf_lsa.c
index 4165338834..2651cf717b 100644
--- a/ospfd/ospf_lsa.c
+++ b/ospfd/ospf_lsa.c
@@ -2912,24 +2912,17 @@ void ospf_lsa_maxage(struct ospf *ospf, struct ospf_lsa *lsa)
lsa_prefix.prefixlen = sizeof(lsa_prefix.u.ptr) * CHAR_BIT;
lsa_prefix.u.ptr = (uintptr_t)lsa;
- if ((rn = route_node_get(ospf->maxage_lsa,
- (struct prefix *)&lsa_prefix))
- != NULL) {
- if (rn->info != NULL) {
- if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
- zlog_debug(
- "LSA[%s]: found LSA (%p) in table for LSA %p %d",
- dump_lsa_key(lsa), rn->info,
- (void *)lsa, lsa_prefix.prefixlen);
- route_unlock_node(rn);
- } else {
- rn->info = ospf_lsa_lock(lsa);
- SET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE);
- }
+ rn = route_node_get(ospf->maxage_lsa, (struct prefix *)&lsa_prefix);
+ if (rn->info != NULL) {
+ if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
+ zlog_debug(
+ "LSA[%s]: found LSA (%p) in table for LSA %p %d",
+ dump_lsa_key(lsa), rn->info,
+ (void *)lsa, lsa_prefix.prefixlen);
+ route_unlock_node(rn);
} else {
- zlog_err("Unable to allocate memory for maxage lsa %s\n",
- dump_lsa_key(lsa));
- assert(0);
+ rn->info = ospf_lsa_lock(lsa);
+ SET_FLAG(lsa->flags, OSPF_LSA_IN_MAXAGE);
}
if (IS_DEBUG_OSPF(lsa, LSA_FLOODING))
diff --git a/ospfd/ospf_main.c b/ospfd/ospf_main.c
index 5bf7ec1469..6dadc05bba 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,
@@ -206,12 +207,16 @@ int main(int argc, char **argv)
ospf_route_map_init();
ospf_opaque_init();
+ /* OSPF errors init */
+ ospf_error_init();
+
/* Need to initialize the default ospf structure, so the interface mode
commands can be duly processed if they are received before 'router
ospf',
when quagga(ospfd) is restarted */
if (!ospf_get_instance(instance)) {
- zlog_err("OSPF instance init failed: %s", strerror(errno));
+ flog_err(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 d7cca0f133..1fb930659e 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,66 +186,51 @@ 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));
- }
-
- ospf_sock = vrf_socket(AF_INET, SOCK_RAW, IPPROTO_OSPFIGP, ospf->vrf_id,
- ospf->name);
- if (ospf_sock < 0) {
- int save_errno = errno;
-
- if (ospfd_privs.change(ZPRIVS_LOWER))
- zlog_err("ospf_sock_init: could not lower privs, %s",
+ frr_elevate_privs(&ospfd_privs) {
+ ospf_sock = vrf_socket(AF_INET, SOCK_RAW, IPPROTO_OSPFIGP,
+ ospf->vrf_id, ospf->name);
+ if (ospf_sock < 0) {
+ zlog_err("ospf_read_sock_init: socket: %s",
safe_strerror(errno));
- zlog_err("ospf_read_sock_init: socket: %s",
- safe_strerror(save_errno));
- exit(1);
- }
+ exit(1);
+ }
#ifdef IP_HDRINCL
- /* we will include IP header with packet */
- ret = setsockopt(ospf_sock, IPPROTO_IP, IP_HDRINCL, &hincl,
- sizeof(hincl));
- if (ret < 0) {
- int save_errno = errno;
-
- zlog_warn("Can't set IP_HDRINCL option for fd %d: %s",
- ospf_sock, safe_strerror(save_errno));
- close(ospf_sock);
- goto out;
- }
+ /* we will include IP header with packet */
+ ret = setsockopt(ospf_sock, IPPROTO_IP, IP_HDRINCL, &hincl,
+ sizeof(hincl));
+ if (ret < 0) {
+ zlog_warn("Can't set IP_HDRINCL option for fd %d: %s",
+ ospf_sock, safe_strerror(errno));
+ close(ospf_sock);
+ break;
+ }
#elif defined(IPTOS_PREC_INTERNETCONTROL)
#warning "IP_HDRINCL not available on this system"
#warning "using IPTOS_PREC_INTERNETCONTROL"
- ret = setsockopt_ipv4_tos(ospf_sock, IPTOS_PREC_INTERNETCONTROL);
- if (ret < 0) {
- int save_errno = errno;
-
- zlog_warn("can't set sockopt IP_TOS %d to socket %d: %s", tos,
- ospf_sock, safe_strerror(save_errno));
- close(ospf_sock); /* Prevent sd leak. */
- goto out;
- }
+ ret = setsockopt_ipv4_tos(ospf_sock,
+ IPTOS_PREC_INTERNETCONTROL);
+ if (ret < 0) {
+ zlog_warn("can't set sockopt IP_TOS %d to socket %d: %s",
+ tos, ospf_sock, safe_strerror(errno));
+ close(ospf_sock); /* Prevent sd leak. */
+ break;
+ }
#else /* !IPTOS_PREC_INTERNETCONTROL */
#warning "IP_HDRINCL not available, nor is IPTOS_PREC_INTERNETCONTROL"
- zlog_warn("IP_HDRINCL option not available");
+ zlog_warn("IP_HDRINCL option not available");
#endif /* IP_HDRINCL */
- ret = setsockopt_ifindex(AF_INET, ospf_sock, 1);
+ ret = setsockopt_ifindex(AF_INET, ospf_sock, 1);
- if (ret < 0)
- zlog_warn("Can't set pktinfo option for fd %d", ospf_sock);
+ if (ret < 0)
+ zlog_warn("Can't set pktinfo option for fd %d",
+ ospf_sock);
- setsockopt_so_sendbuf(ospf_sock, bufsize);
- setsockopt_so_recvbuf(ospf_sock, bufsize);
+ setsockopt_so_sendbuf(ospf_sock, bufsize);
+ setsockopt_so_recvbuf(ospf_sock, bufsize);
+ }
ospf->fd = ospf_sock;
-out:
- if (ospfd_privs.change(ZPRIVS_LOWER)) {
- zlog_err("ospf_sock_init: could not lower privs, %s",
- safe_strerror(errno));
- }
return ret;
}
diff --git a/ospfd/ospf_opaque.c b/ospfd/ospf_opaque.c
index 1ae9a29a1b..be62eb3906 100644
--- a/ospfd/ospf_opaque.c
+++ b/ospfd/ospf_opaque.c
@@ -399,13 +399,8 @@ int ospf_register_opaque_functab(
}
}
- if ((new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB,
- sizeof(struct ospf_opaque_functab)))
- == NULL) {
- zlog_warn("ospf_register_opaque_functab: XMALLOC: %s",
- safe_strerror(errno));
- goto out;
- }
+ new = XCALLOC(MTYPE_OSPF_OPAQUE_FUNCTAB,
+ sizeof(struct ospf_opaque_functab));
new->opaque_type = opaque_type;
new->oipt = NULL;
@@ -554,13 +549,8 @@ register_opaque_info_per_type(struct ospf_opaque_functab *functab,
struct ospf *top;
struct opaque_info_per_type *oipt;
- if ((oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE,
- sizeof(struct opaque_info_per_type)))
- == NULL) {
- zlog_warn("register_opaque_info_per_type: XMALLOC: %s",
- safe_strerror(errno));
- goto out;
- }
+ oipt = XCALLOC(MTYPE_OPAQUE_INFO_PER_TYPE,
+ sizeof(struct opaque_info_per_type));
switch (new->data->type) {
case OSPF_OPAQUE_LINK_LSA:
@@ -711,13 +701,9 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt,
{
struct opaque_info_per_id *oipi;
- if ((oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID,
- sizeof(struct opaque_info_per_id)))
- == NULL) {
- zlog_warn("register_opaque_info_per_id: XMALLOC: %s",
- safe_strerror(errno));
- goto out;
- }
+ oipi = XCALLOC(MTYPE_OPAQUE_INFO_PER_ID,
+ sizeof(struct opaque_info_per_id));
+
oipi->opaque_id = GET_OPAQUE_ID(ntohl(new->data->id.s_addr));
oipi->t_opaque_lsa_self = NULL;
oipi->opqctl_type = oipt;
@@ -725,7 +711,6 @@ register_opaque_info_per_id(struct opaque_info_per_type *oipt,
listnode_add(oipt->id_list, oipi);
-out:
return oipi;
}
diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c
index 486ef3335d..f1d4a39dba 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(
+ flog_err(
+ 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(
+ flog_err(
+ 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(
+ flog_err(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));
+ flog_err(
+ 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_spf.c b/ospfd/ospf_spf.c
index c6c16e7169..e3c729f65e 100644
--- a/ospfd/ospf_spf.c
+++ b/ospfd/ospf_spf.c
@@ -154,9 +154,6 @@ static struct vertex_parent *vertex_parent_new(struct vertex *v, int backlink,
new = XMALLOC(MTYPE_OSPF_VERTEX_PARENT, sizeof(struct vertex_parent));
- if (new == NULL)
- return NULL;
-
new->parent = v;
new->backlink = backlink;
new->nexthop = hop;
diff --git a/ospfd/ospf_sr.c b/ospfd/ospf_sr.c
index e5fc3e2954..6cb697f3ab 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"
@@ -128,12 +129,6 @@ static struct sr_node *sr_node_new(struct in_addr *rid)
/* Allocate Segment Routing node memory */
new = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_node));
- /* Sanity Check */
- if (new == NULL) {
- zlog_err("SR (%s): Abort! can't create new SR node", __func__);
- return NULL;
- }
-
/* Default Algorithm, SRGB and MSD */
for (int i = 0; i < ALGORITHM_COUNT; i++)
new->algo[i] = SR_ALGORITHM_UNSET;
@@ -735,9 +730,6 @@ static struct sr_link *get_ext_link_sid(struct tlv_header *tlvh)
srl = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_link));
- if (srl == NULL)
- return NULL;
-
/* Initialize TLV browsing */
length = ntohs(tlvh->length) - EXT_TLV_LINK_SIZE;
sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE
@@ -820,9 +812,6 @@ static struct sr_prefix *get_ext_prefix_sid(struct tlv_header *tlvh)
srp = XCALLOC(MTYPE_OSPF_SR_PARAMS, sizeof(struct sr_prefix));
- if (srp == NULL)
- return NULL;
-
/* Initialize TLV browsing */
length = ntohs(tlvh->length) - EXT_TLV_PREFIX_SIZE;
sub_tlvh = (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE
@@ -832,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__);
+ flog_err(OSPF_ERR_SR_INVALID_ALGORITHM,
+ "SR (%s): Unsupported Algorithm",
+ __func__);
XFREE(MTYPE_OSPF_SR_PARAMS, srp);
return NULL;
}
@@ -1112,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__);
+ flog_err(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1122,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__);
+ flog_err(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);
+ flog_err(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;
}
@@ -1221,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__);
+ flog_err(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR Data Base", __func__);
return;
}
@@ -1230,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));
+ flog_err(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));
+ flog_err(
+ 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;
}
@@ -1264,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__);
+ flog_err(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1275,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__);
+ flog_err(OSPF_ERR_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
@@ -1314,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__);
+ flog_err(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1371,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__);
+ flog_err(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
@@ -1382,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__);
+ flog_err(OSPF_ERR_SR_NODE_CREATE,
+ "SR (%s): Abort! can't create SR node in hash table",
+ __func__);
return;
}
@@ -1422,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__);
+ flog_err(OSPF_ERR_SR_INVALID_DB,
+ "SR (%s): Abort! no valid SR DataBase", __func__);
return;
}
diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c
index 86125d0c76..cc2d9282fe 100644
--- a/ospfd/ospf_te.c
+++ b/ospfd/ospf_te.c
@@ -857,11 +857,6 @@ static int ospf_mpls_te_new_if(struct interface *ifp)
}
new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link));
- if (new == NULL) {
- zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s",
- safe_strerror(errno));
- return rc;
- }
new->instance = get_mpls_te_instance_value();
new->ifp = ifp;
diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c
index 2298c2261a..ac8f0d92c3 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,25 +2088,17 @@ 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));
- }
-
- /* stop zebra redist to us for old vrf */
- zclient_send_dereg_requests(zclient, old_vrf_id);
+ frr_elevate_privs(&ospfd_privs) {
+ /* stop zebra redist to us for old vrf */
+ zclient_send_dereg_requests(zclient,
+ old_vrf_id);
- ospf_set_redist_vrf_bitmaps(ospf);
+ ospf_set_redist_vrf_bitmaps(ospf);
- /* start zebra redist to us for new vrf */
- ospf_zebra_vrf_register(ospf);
+ /* start zebra redist to us for new 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));
+ ret = ospf_sock_init(ospf);
}
if (ret < 0 || ospf->fd <= 0)
return 0;
diff --git a/ospfd/subdir.am b/ospfd/subdir.am
index f2e292e186..cd659a9bc9 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 \