--- /dev/null
+/*
+ * Babel-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "babel_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_babel_err[] = {
+ {
+ .code = BABEL_ERR_MEMORY,
+ .title = "BABEL Memory Errors",
+ .description = "Babel has failed to allocate memory, the system is about to run out of memory",
+ .suggestion = "Find the process that is causing memory shortages, remediate that process and restart FRR"
+ },
+ {
+ .code = BABEL_ERR_PACKET,
+ .title = "BABEL Packet Error",
+ .description = "Babel has detected a packet encode/decode problem",
+ .suggestion = "Collect relevant log files and file an Issue"
+ },
+ {
+ .code = BABEL_ERR_CONFIG,
+ .title = "BABEL Configuration Error",
+ .description = "Babel has detected a configuration error of some sort",
+ .suggestion = "Ensure that the configuration is correct"
+ },
+ {
+ .code = BABEL_ERR_ROUTE,
+ .title = "BABEL Route Error",
+ .description = "Babel has detected a routing error and has an inconsistent state",
+ .suggestion = "Gather data for filing an Issue and then restart FRR"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void babel_error_init(void)
+{
+ log_ref_add(ferr_babel_err);
+}
--- /dev/null
+/*
+ * Babel-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __BABEL_ERRORS_H__
+#define __BABEL_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum babel_log_refs {
+ BABEL_ERR_MEMORY = BABEL_FERR_START,
+ BABEL_ERR_PACKET,
+ BABEL_ERR_CONFIG,
+ BABEL_ERR_ROUTE,
+};
+
+extern void babel_error_init(void);
+
+#endif
#include "prefix.h"
#include "vector.h"
#include "distribute.h"
+#include "lib_errors.h"
#include "babel_main.h"
#include "util.h"
#include "route.h"
#include "xroute.h"
#include "babel_memory.h"
+#include "babel_errors.h"
#define IS_ENABLE(ifp) (babel_enable_if_lookup(ifp->name) >= 0)
if (babel_ifp->ipv4 == NULL) {
babel_ifp->ipv4 = malloc(4);
if (babel_ifp->ipv4 == NULL) {
- zlog_err("not einough memory");
+ flog_err(BABEL_ERR_MEMORY, "not enough memory");
} else {
memcpy(babel_ifp->ipv4, &prefix->u.prefix4, 4);
}
tmp = babel_ifp->sendbuf;
babel_ifp->sendbuf = realloc(babel_ifp->sendbuf, babel_ifp->bufsize);
if(babel_ifp->sendbuf == NULL) {
- zlog_err("Couldn't reallocate sendbuf.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't reallocate sendbuf.");
free(tmp);
babel_ifp->bufsize = 0;
return -1;
rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_JOIN_GROUP,
(char*)&mreq, sizeof(mreq));
if(rc < 0) {
- zlog_err("setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
- ifp->name, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "setsockopt(IPV6_JOIN_GROUP) on interface '%s': %s",
+ ifp->name, safe_strerror(errno));
/* This is probably due to a missing link-local address,
so down this interface, and wait until the main loop
tries to up it again. */
rc = setsockopt(protocol_socket, IPPROTO_IPV6, IPV6_LEAVE_GROUP,
(char*)&mreq, sizeof(mreq));
if(rc < 0)
- zlog_err("setsockopt(IPV6_LEAVE_GROUP) on interface '%s': %s",
- ifp->name, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "setsockopt(IPV6_LEAVE_GROUP) on interface '%s': %s",
+ ifp->name, safe_strerror(errno));
}
update_interface_metric(ifp);
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
xroutes = xroute_stream();
if(xroutes) {
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
return CMD_SUCCESS;
}
#include "vty.h"
#include "memory.h"
#include "libfrr.h"
+#include "lib_errors.h"
#include "babel_main.h"
#include "babeld.h"
#include "message.h"
#include "resend.h"
#include "babel_zebra.h"
+#include "babel_errors.h"
static void babel_fail(void);
static void babel_init_random(void);
frr_preinit (&babeld_di, argc, argv);
frr_opt_add ("", longopts, "");
-
+
babel_init_random();
/* set the Babel's default link-local multicast address and Babel's port */
master = frr_init ();
/* Library inits. */
- zprivs_init (&babeld_privs);
- cmd_init (1);
- vty_init (master);
+ babel_error_init();
resend_delay = BABEL_DEFAULT_RESEND_DELAY;
change_smoothing_half_life(BABEL_DEFAULT_SMOOTHING_HALF_LIFE);
rc = read_random_bytes(&seed, sizeof(seed));
if(rc < 0) {
- zlog_err("read(random): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "read(random): %s",
+ safe_strerror(errno));
seed = 42;
}
fd_null = open("/dev/null", O_RDONLY);
if(fd_null < 0) {
- zlog_err("open(null): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "open(null): %s", safe_strerror(errno));
exit(1);
}
rc = dup2(fd_null, fd);
if(rc < 0) {
- zlog_err("dup2(null, 0): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "dup2(null, 0): %s",
+ safe_strerror(errno));
exit(1);
}
fd = open(state_file, O_RDONLY);
if(fd < 0 && errno != ENOENT)
- zlog_err("open(babel-state: %s)", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "open(babel-state: %s)",
+ safe_strerror(errno));
rc = unlink(state_file);
if(fd >= 0 && rc < 0) {
- zlog_err("unlink(babel-state): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "unlink(babel-state): %s",
+ safe_strerror(errno));
/* If we couldn't unlink it, it's probably stale. */
goto fini;
}
long t;
rc = read(fd, buf, 99);
if(rc < 0) {
- zlog_err("read(babel-state): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "read(babel-state): %s",
+ safe_strerror(errno));
} else {
buf[rc] = '\0';
rc = sscanf(buf, "%99s %d %ld\n", buf2, &s, &t);
unsigned char sid[8];
rc = parse_eui64(buf2, sid);
if(rc < 0) {
- zlog_err("Couldn't parse babel-state.");
+ flog_err(BABEL_ERR_CONFIG, "Couldn't parse babel-state.");
} else {
struct timeval realnow;
debugf(BABEL_DEBUG_COMMON,
if(memcmp(sid, myid, 8) == 0)
myseqno = seqno_plus(s, 1);
else
- zlog_err("ID mismatch in babel-state. id=%s; old=%s",
+ flog_err(BABEL_ERR_CONFIG,
+ "ID mismatch in babel-state. id=%s; old=%s",
format_eui64(myid),
format_eui64(sid));
}
} else {
- zlog_err("Couldn't parse babel-state.");
+ flog_err(BABEL_ERR_CONFIG, "Couldn't parse babel-state.");
}
}
goto fini;
debugf(BABEL_DEBUG_COMMON, "Save state file.");
fd = open(state_file, O_WRONLY | O_TRUNC | O_CREAT, 0644);
if(fd < 0) {
- zlog_err("creat(babel-state): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "creat(babel-state): %s",
+ safe_strerror(errno));
unlink(state_file);
} else {
struct timeval realnow;
format_eui64(myid), (int)myseqno,
(long)realnow.tv_sec);
if(rc < 0 || rc >= 100) {
- zlog_err("write(babel-state): overflow.");
+ flog_err(BABEL_ERR_CONFIG, "write(babel-state): overflow.");
unlink(state_file);
} else {
rc = write(fd, buf, rc);
if(rc < 0) {
- zlog_err("write(babel-state): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_CONFIG, "write(babel-state): %s",
+ safe_strerror(errno));
unlink(state_file);
}
fsync(fd);
#include "prefix.h"
#include "filter.h"
#include "plist.h"
+#include "lib_errors.h"
#include "babel_main.h"
#include "babeld.h"
#include "babel_filter.h"
#include "babel_zebra.h"
#include "babel_memory.h"
+#include "babel_errors.h"
static int babel_init_routing_process(struct thread *thread);
static void babel_get_myid(void);
/* Make socket for Babel protocol. */
protocol_socket = babel_socket(protocol_port);
if (protocol_socket < 0) {
- zlog_err("Couldn't create link local socket: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "Couldn't create link local socket: %s",
+ safe_strerror(errno));
goto fail;
}
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0) {
if(errno != EAGAIN && errno != EINTR) {
- zlog_err("recv: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "recv: %s", safe_strerror(errno));
}
} else {
FOR_ALL_INTERFACES(vrf, ifp) {
return;
}
- zlog_err("Warning: couldn't find router id -- using random value.");
+ flog_err(BABEL_ERR_CONFIG,
+ "Warning: couldn't find router id -- using random value.");
rc = read_random_bytes(myid, 8);
if(rc < 0) {
- zlog_err("read(random): %s (cannot assign an ID)",safe_strerror(errno));
+ flog_err(BABEL_ERR_CONFIG, "read(random): %s (cannot assign an ID)",
+ safe_strerror(errno));
exit(1);
}
/* Clear group and global bits */
if(receive_buffer == NULL) {
receive_buffer = malloc(size);
if(receive_buffer == NULL) {
- zlog_err("malloc(receive_buffer): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_MEMORY, "malloc(receive_buffer): %s",
+ safe_strerror(errno));
return -1;
}
receive_buffer_size = size;
unsigned char *new;
new = realloc(receive_buffer, size);
if(new == NULL) {
- zlog_err("realloc(receive_buffer): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_MEMORY, "realloc(receive_buffer): %s",
+ safe_strerror(errno));
return -1;
}
receive_buffer = new;
#include "message.h"
#include "kernel.h"
#include "babel_main.h"
+#include "babel_errors.h"
static unsigned char packet_header[4] = {42, 2};
}
if(i + 1 > alen) {
- zlog_err("Received truncated attributes.");
+ flog_err(BABEL_ERR_PACKET, "Received truncated attributes.");
return;
}
len = a[i + 1];
if(i + len > alen) {
- zlog_err("Received truncated attributes.");
+ flog_err(BABEL_ERR_PACKET, "Received truncated attributes.");
return;
}
/* Nothing. */
} else if(type == SUBTLV_DIVERSITY) {
if(len > DIVERSITY_HOPS) {
- zlog_err("Received overlong channel information (%d > %d).n",
- len, DIVERSITY_HOPS);
+ flog_err(BABEL_ERR_PACKET,
+ "Received overlong channel information (%d > %d).n",
+ len, DIVERSITY_HOPS);
len = DIVERSITY_HOPS;
}
if(memchr(a + i + 2, 0, len) != NULL) {
/* 0 is reserved. */
- zlog_err("Channel information contains 0!");
+ flog_err(BABEL_ERR_PACKET, "Channel information contains 0!");
return;
}
memset(channels, 0, DIVERSITY_HOPS);
}
if(i + 1 > alen) {
- zlog_err("Received truncated sub-TLV on Hello message.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on Hello message.");
return -1;
}
len = a[i + 1];
if(i + len > alen) {
- zlog_err("Received truncated sub-TLV on Hello message.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on Hello message.");
return -1;
}
DO_NTOHL(*hello_send_us, a + i + 2);
ret = 1;
} else {
- zlog_err("Received incorrect RTT sub-TLV on Hello message.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received incorrect RTT sub-TLV on Hello message.");
}
} else {
debugf(BABEL_DEBUG_COMMON,
}
if(i + 1 > alen) {
- zlog_err("Received truncated sub-TLV on IHU message.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on IHU message.");
return -1;
}
len = a[i + 1];
if(i + len > alen) {
- zlog_err("Received truncated sub-TLV on IHU message.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received truncated sub-TLV on IHU message.");
return -1;
}
ret = 1;
}
else {
- zlog_err("Received incorrect RTT sub-TLV on IHU message.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received incorrect RTT sub-TLV on IHU message.");
}
} else {
debugf(BABEL_DEBUG_COMMON,
}
if(!linklocal(from)) {
- zlog_err("Received packet from non-local address %s.",
- format_address(from));
+ flog_err(BABEL_ERR_PACKET,
+ "Received packet from non-local address %s.",
+ format_address(from));
return;
}
if (babel_packet_examin (packet, packetlen)) {
- zlog_err("Received malformed packet on %s from %s.",
- ifp->name, format_address(from));
+ flog_err(BABEL_ERR_PACKET,
+ "Received malformed packet on %s from %s.",
+ ifp->name, format_address(from));
return;
}
neigh = find_neighbour(from, ifp);
if(neigh == NULL) {
- zlog_err("Couldn't allocate neighbour.");
+ flog_err(BABEL_ERR_PACKET, "Couldn't allocate neighbour.");
return;
}
DO_NTOHS(bodylen, packet + 2);
if(bodylen + 4 > packetlen) {
- zlog_err("Received truncated packet (%d + 4 > %d).",
+ flog_err(BABEL_ERR_PACKET, "Received truncated packet (%d + 4 > %d).",
bodylen, packetlen);
bodylen = packetlen - 4;
}
have_router_id = 1;
}
if(!have_router_id && message[2] != 0) {
- zlog_err("Received prefix with no router id.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received prefix with no router id.");
goto fail;
}
debugf(BABEL_DEBUG_COMMON,"Received update%s%s for %s from %s on %s.",
if(message[2] == 0) {
if(metric < 0xFFFF) {
- zlog_err("Received wildcard update with finite metric.");
+ flog_err(BABEL_ERR_PACKET,
+ "Received wildcard update with finite metric.");
goto done;
}
retract_neighbour_routes(neigh);
continue;
fail:
- zlog_err("Couldn't parse packet (%d, %d) from %s on %s.",
- message[0], message[1], format_address(from), ifp->name);
+ flog_err(BABEL_ERR_PACKET,
+ "Couldn't parse packet (%d, %d) from %s on %s.",
+ message[0], message[1], format_address(from), ifp->name);
goto done;
}
DO_HTONL(babel_ifp->sendbuf + babel_ifp->buffered_hello + 10, time);
return 1;
} else {
- zlog_err("No space left for timestamp sub-TLV "
+ flog_err(BABEL_ERR_PACKET, "No space left for timestamp sub-TLV "
"(this shouldn't happen)");
return -1;
}
babel_ifp->sendbuf, babel_ifp->buffered,
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0)
- zlog_err("send: %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_PACKET, "send: %s", safe_strerror(errno));
} else {
- zlog_err("Warning: bucket full, dropping packet to %s.",
- ifp->name);
+ flog_err(BABEL_ERR_PACKET,
+ "Warning: bucket full, dropping packet to %s.",
+ ifp->name);
}
}
VALGRIND_MAKE_MEM_UNDEFINED(babel_ifp->sendbuf, babel_ifp->bufsize);
if(!unicast_buffer)
unicast_buffer = malloc(UNICAST_BUFSIZE);
if(!unicast_buffer) {
- zlog_err("malloc(unicast_buffer): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_MEMORY, "malloc(unicast_buffer): %s",
+ safe_strerror(errno));
return -1;
}
unicast_buffer, unicast_buffered,
(struct sockaddr*)&sin6, sizeof(sin6));
if(rc < 0)
- zlog_err("send(unicast): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_PACKET, "send(unicast): %s",
+ safe_strerror(errno));
} else {
- zlog_err("Warning: bucket full, dropping unicast packet to %s if %s.",
- format_address(unicast_neighbour->address),
- unicast_neighbour->ifp->name);
+ flog_err(BABEL_ERR_PACKET,
+ "Warning: bucket full, dropping unicast packet to %s if %s.",
+ format_address(unicast_neighbour->address),
+ unicast_neighbour->ifp->name);
}
done:
again:
babel_ifp->buffered_updates = malloc(n *sizeof(struct buffered_update));
if(babel_ifp->buffered_updates == NULL) {
- zlog_err("malloc(buffered_updates): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_MEMORY, "malloc(buffered_updates): %s",
+ safe_strerror(errno));
if(n > 4) {
/* Try again with a tiny buffer. */
n = 4;
}
route_stream_done(routes);
} else {
- zlog_err("Couldn't allocate route stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate route stream.");
}
set_timeout(&babel_ifp->update_timeout, babel_ifp->update_interval);
babel_ifp->last_update_time = babel_now.tv_sec;
}
xroute_stream_done(xroutes);
} else {
- zlog_err("Couldn't allocate xroute stream.");
+ flog_err(BABEL_ERR_MEMORY, "Couldn't allocate xroute stream.");
}
}
#include "route.h"
#include "message.h"
#include "resend.h"
+#include "babel_errors.h"
struct neighbour *neighs = NULL;
neigh = malloc(sizeof(struct neighbour));
if(neigh == NULL) {
- zlog_err("malloc(neighbour): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_MEMORY, "malloc(neighbour): %s",
+ safe_strerror(errno));
return NULL;
}
#include "xroute.h"
#include "message.h"
#include "resend.h"
+#include "babel_errors.h"
static void consider_route(struct babel_route *route);
struct babel_route **routes = NULL;
static int route_slots = 0, max_route_slots = 0;
int kernel_metric = 0;
-int diversity_kind = DIVERSITY_NONE;
+enum babel_diversity diversity_kind = DIVERSITY_NONE;
int diversity_factor = BABEL_DEFAULT_DIVERSITY_FACTOR;
int keep_unfeasible = 0;
return;
if(!route_feasible(route))
- zlog_err("WARNING: installing unfeasible route "
- "(this shouldn't happen).");
+ flog_err(BABEL_ERR_ROUTE, "WARNING: installing unfeasible route "
+ "(this shouldn't happen).");
i = find_route_slot(route->src->prefix, route->src->plen, NULL);
assert(i >= 0 && i < route_slots);
if(routes[i] != route && routes[i]->installed) {
- zlog_err("WARNING: attempting to install duplicate route "
- "(this shouldn't happen).");
+ flog_err(BABEL_ERR_ROUTE,
+ "WARNING: attempting to install duplicate route "
+ "(this shouldn't happen).");
return;
}
metric_to_kernel(route_metric(route)), NULL, 0, 0);
if(rc < 0) {
int save = errno;
- zlog_err("kernel_route(ADD): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_ROUTE, "kernel_route(ADD): %s",
+ safe_strerror(errno));
if(save != EEXIST)
return;
}
route->neigh->ifp->ifindex,
metric_to_kernel(route_metric(route)), NULL, 0, 0);
if(rc < 0)
- zlog_err("kernel_route(FLUSH): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_ROUTE, "kernel_route(FLUSH): %s",
+ safe_strerror(errno));
route->installed = 0;
}
return;
if(!route_feasible(new))
- zlog_err("WARNING: switching to unfeasible route "
- "(this shouldn't happen).");
+ flog_err(BABEL_ERR_ROUTE, "WARNING: switching to unfeasible route "
+ "(this shouldn't happen).");
rc = kernel_route(ROUTE_MODIFY, old->src->prefix, old->src->plen,
old->nexthop, old->neigh->ifp->ifindex,
new->nexthop, new->neigh->ifp->ifindex,
metric_to_kernel(route_metric(new)));
if(rc < 0) {
- zlog_err("kernel_route(MODIFY): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_ROUTE, "kernel_route(MODIFY): %s",
+ safe_strerror(errno));
return;
}
route->nexthop, route->neigh->ifp->ifindex,
new);
if(rc < 0) {
- zlog_err("kernel_route(MODIFY metric): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_ROUTE, "kernel_route(MODIFY metric): %s",
+ safe_strerror(errno));
return;
}
}
}
}
return 0;
- default:
- zlog_err("Unknown kind of diversity.");
- return 1;
}
+
+ return 1;
}
int
return NULL;
if(martian_prefix(prefix, plen)) {
- zlog_err("Rejecting martian route to %s through %s.",
+ flog_err(BABEL_ERR_ROUTE, "Rejecting martian route to %s through %s.",
format_prefix(prefix, plen), format_address(nexthop));
return NULL;
}
route->next = NULL;
new_route = insert_route(route);
if(new_route == NULL) {
- zlog_err("Couldn't insert route.");
+ flog_err(BABEL_ERR_ROUTE, "Couldn't insert route.");
free(route);
return NULL;
}
#include "babel_interface.h"
#include "source.h"
-#define DIVERSITY_NONE 0
-#define DIVERSITY_INTERFACE_1 1
-#define DIVERSITY_CHANNEL_1 2
-#define DIVERSITY_CHANNEL 3
+enum babel_diversity {
+ DIVERSITY_NONE,
+ DIVERSITY_INTERFACE_1,
+ DIVERSITY_CHANNEL_1,
+ DIVERSITY_CHANNEL,
+};
#define DIVERSITY_HOPS 8
extern struct babel_route **routes;
extern int kernel_metric;
-extern int diversity_kind, diversity_factor;
+extern enum babel_diversity diversity_kind;
+extern int diversity_factor;
extern int keep_unfeasible;
extern int smoothing_half_life;
#include "source.h"
#include "babel_interface.h"
#include "route.h"
+#include "babel_errors.h"
struct source *srcs = NULL;
src = malloc(sizeof(struct source));
if(src == NULL) {
- zlog_err("malloc(source): %s", safe_strerror(errno));
+ flog_err(BABEL_ERR_MEMORY, "malloc(source): %s", safe_strerror(errno));
return NULL;
}
endif
babeld_libbabel_a_SOURCES = \
+ babeld/babel_errors.c \
babeld/babel_filter.c \
babeld/babel_interface.c \
babeld/babel_memory.c \
# end
noinst_HEADERS += \
+ babeld/babel_errors.h \
babeld/babel_filter.h \
babeld/babel_interface.h \
babeld/babel_main.h \
bgp_encap_tlv.c $(BGP_VNC_RFAPI_SRC) bgp_attr_evpn.c \
bgp_evpn.c bgp_evpn_vty.c bgp_vpn.c bgp_label.c bgp_rd.c \
bgp_keepalives.c bgp_io.c bgp_flowspec.c bgp_flowspec_util.c \
- bgp_flowspec_vty.c bgp_labelpool.c bgp_pbr.c
+ bgp_flowspec_vty.c bgp_labelpool.c bgp_pbr.c bgp_errors.c
noinst_HEADERS = \
bgp_memory.h \
$(BGP_VNC_RFAPI_HD) bgp_attr_evpn.h bgp_evpn.h bgp_evpn_vty.h \
bgp_vpn.h bgp_label.h bgp_rd.h bgp_evpn_private.h bgp_keepalives.h \
bgp_io.h bgp_flowspec.h bgp_flowspec_private.h bgp_flowspec_util.h \
- bgp_labelpool.h bgp_pbr.h
+ bgp_labelpool.h bgp_pbr.h bgp_errors.h
bgpd_SOURCES = bgp_main.c
bgpd_LDADD = libbgp.a $(BGP_VNC_RFP_LIB) ../lib/libfrr.la @LIBCAP@ @LIBM@
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_community.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_label.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_ecommunity.h"
for (i = 0; i <= 2; i++) /* O,T,P, but not E */
if (CHECK_FLAG(desired_flags, attr_flag_str[i].key)
!= CHECK_FLAG(real_flags, attr_flag_str[i].key)) {
- zlog_err("%s attribute must%s be flagged as \"%s\"",
- lookup_msg(attr_str, attr_code, NULL),
- CHECK_FLAG(desired_flags, attr_flag_str[i].key)
- ? ""
- : " not",
- attr_flag_str[i].str);
+ flog_err(
+ BGP_ERR_ATTR_FLAG,
+ "%s attribute must%s be flagged as \"%s\"",
+ lookup_msg(attr_str, attr_code, NULL),
+ CHECK_FLAG(desired_flags, attr_flag_str[i].key)
+ ? ""
+ : " not",
+ attr_flag_str[i].str);
seen = 1;
}
if (!seen) {
*/
if (!CHECK_FLAG(BGP_ATTR_FLAG_OPTIONAL, flags)
&& !CHECK_FLAG(BGP_ATTR_FLAG_TRANS, flags)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_ATTR_FLAG,
"%s well-known attributes must have transitive flag set (%x)",
lookup_msg(attr_str, attr_code, NULL), flags);
return 1;
*/
if (CHECK_FLAG(flags, BGP_ATTR_FLAG_PARTIAL)) {
if (!CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL)) {
- zlog_err(
- "%s well-known attribute "
- "must NOT have the partial flag set (%x)",
- lookup_msg(attr_str, attr_code, NULL), flags);
+ flog_err(BGP_ERR_ATTR_FLAG,
+ "%s well-known attribute "
+ "must NOT have the partial flag set (%x)",
+ lookup_msg(attr_str, attr_code, NULL), flags);
return 1;
}
if (CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL)
&& !CHECK_FLAG(flags, BGP_ATTR_FLAG_TRANS)) {
- zlog_err(
- "%s optional + transitive attribute "
- "must NOT have the partial flag set (%x)",
- lookup_msg(attr_str, attr_code, NULL), flags);
+ flog_err(BGP_ERR_ATTR_FLAG,
+ "%s optional + transitive attribute "
+ "must NOT have the partial flag set (%x)",
+ lookup_msg(attr_str, attr_code, NULL), flags);
return 1;
}
}
field contains the erroneous attribute (type, length and
value). */
if (length != 1) {
- zlog_err("Origin attribute length is not one %d", length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "Origin attribute length is not one %d", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
contains the unrecognized attribute (type, length and value). */
if ((attr->origin != BGP_ORIGIN_IGP) && (attr->origin != BGP_ORIGIN_EGP)
&& (attr->origin != BGP_ORIGIN_INCOMPLETE)) {
- zlog_err("Origin attribute value is invalid %d", attr->origin);
+ flog_err(BGP_ERR_ATTR_ORIGIN,
+ "Origin attribute value is invalid %d", attr->origin);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_INVAL_ORIGIN,
args->total);
}
/* In case of IBGP, length will be zero. */
if (!attr->aspath) {
- zlog_err("Malformed AS path from %s, length is %d", peer->host,
- length);
+ flog_err(BGP_ERR_ATTR_MAL_AS_PATH,
+ "Malformed AS path from %s, length is %d", peer->host,
+ length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH,
0);
}
&& !aspath_left_confed_check(attr->aspath))
|| (peer->sort == BGP_PEER_EBGP
&& aspath_confed_check(attr->aspath))) {
- zlog_err("Malformed AS path from %s", peer->host);
+ flog_err(BGP_ERR_ATTR_MAL_AS_PATH, "Malformed AS path from %s",
+ peer->host);
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
return BGP_ATTR_PARSE_ERROR;
if (CHECK_FLAG(peer->flags, PEER_FLAG_ENFORCE_FIRST_AS)) {
if (peer->sort == BGP_PEER_EBGP
&& !aspath_firstas_check(attr->aspath, peer->as)) {
- zlog_err("%s incorrect first AS (must be %u)",
- peer->host, peer->as);
+ flog_err(BGP_ERR_ATTR_FIRST_AS,
+ "%s incorrect first AS (must be %u)",
+ peer->host, peer->as);
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_AS_PATH);
return BGP_ATTR_PARSE_ERROR;
/* In case of IBGP, length will be zero. */
if (!*as4_path) {
- zlog_err("Malformed AS4 path from %s, length is %d", peer->host,
- length);
+ flog_err(BGP_ERR_ATTR_MAL_AS_PATH,
+ "Malformed AS4 path from %s, length is %d",
+ peer->host, length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH,
0);
}
/* Check nexthop attribute length. */
if (length != 4) {
- zlog_err("Nexthop attribute length isn't four [%d]", length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "Nexthop attribute length isn't four [%d]", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
{
char buf[INET_ADDRSTRLEN];
inet_ntop(AF_INET, &nexthop_n, buf, INET_ADDRSTRLEN);
- zlog_err("Martian nexthop %s", buf);
+ flog_err(BGP_ERR_ATTR_MARTIAN_NH, "Martian nexthop %s", buf);
return bgp_attr_malformed(
args, BGP_NOTIFY_UPDATE_INVAL_NEXT_HOP, args->total);
}
/* Length check. */
if (length != 4) {
- zlog_err("MED attribute length isn't four [%d]", length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "MED attribute length isn't four [%d]", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
/* Length check. */
if (length != 4) {
- zlog_err("LOCAL_PREF attribute length isn't 4 [%u]", length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "LOCAL_PREF attribute length isn't 4 [%u]", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
/* Length check. */
if (length != 0) {
- zlog_err("ATOMIC_AGGREGATE attribute length isn't 0 [%u]",
- length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "ATOMIC_AGGREGATE attribute length isn't 0 [%u]",
+ length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
wantedlen = 8;
if (length != wantedlen) {
- zlog_err("AGGREGATOR attribute length isn't %u [%u]", wantedlen,
- length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "AGGREGATOR attribute length isn't %u [%u]",
+ wantedlen, length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
const bgp_size_t length = args->length;
if (length != 8) {
- zlog_err("New Aggregator length is not 8 [%d]", length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "New Aggregator length is not 8 [%d]", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
0);
}
/* Length check. */
if (length != 4) {
- zlog_err("Bad originator ID length %d", length);
+ flog_err(BGP_ERR_ATTR_LEN, "Bad originator ID length %d",
+ length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
/* Check length. */
if (length % 4) {
- zlog_err("Bad cluster list length %d", length);
+ flog_err(BGP_ERR_ATTR_LEN, "Bad cluster list length %d",
+ length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
if (type == BGP_PREFIX_SID_LABEL_INDEX) {
if (length != BGP_PREFIX_SID_LABEL_INDEX_LENGTH) {
- zlog_err(
- "Prefix SID label index length is %d instead of %d",
- length,
- BGP_PREFIX_SID_LABEL_INDEX_LENGTH);
+ flog_err(
+ BGP_ERR_ATTR_LEN,
+ "Prefix SID label index length is %d instead of %d",
+ length, BGP_PREFIX_SID_LABEL_INDEX_LENGTH);
return bgp_attr_malformed(args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
/* Placeholder code for the IPv6 SID type */
else if (type == BGP_PREFIX_SID_IPV6) {
if (length != BGP_PREFIX_SID_IPV6_LENGTH) {
- zlog_err("Prefix SID IPv6 length is %d instead of %d",
- length, BGP_PREFIX_SID_IPV6_LENGTH);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "Prefix SID IPv6 length is %d instead of %d",
+ length, BGP_PREFIX_SID_IPV6_LENGTH);
return bgp_attr_malformed(args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
length -= 2;
if (length % BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH) {
- zlog_err(
+ flog_err(
+ BGP_ERR_ATTR_LEN,
"Prefix SID Originator SRGB length is %d, it must be a multiple of %d ",
length, BGP_PREFIX_SID_ORIGINATOR_SRGB_LENGTH);
return bgp_attr_malformed(
tlength -= length + 3;
if (tlength < 0) {
- zlog_err("Prefix SID internal length %d causes us to read beyond the total Prefix SID length",
- length);
+ flog_err(
+ BGP_ERR_ATTR_LEN,
+ "Prefix SID internal length %d causes us to read beyond the total Prefix SID length",
+ length);
return bgp_attr_malformed(args,
BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
* can only support that.
*/
if (length < 2) {
- zlog_err("Bad PMSI tunnel attribute length %d", length);
+ flog_err(BGP_ERR_ATTR_LEN,
+ "Bad PMSI tunnel attribute length %d", length);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
}
stream_getc(peer->curr); /* Flags */
tnl_type = stream_getc(peer->curr);
if (tnl_type > PMSI_TNLTYPE_MAX) {
- zlog_err("Invalid PMSI tunnel attribute type %d", tnl_type);
+ flog_err(BGP_ERR_ATTR_PMSI_TYPE,
+ "Invalid PMSI tunnel attribute type %d", tnl_type);
return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_OPT_ATTR_ERR,
args->total);
}
if (tnl_type == PMSI_TNLTYPE_INGR_REPL) {
if (length != 9) {
- zlog_err("Bad PMSI tunnel attribute length %d for IR",
- length);
+ flog_err(BGP_ERR_ATTR_PMSI_LEN,
+ "Bad PMSI tunnel attribute length %d for IR",
+ length);
return bgp_attr_malformed(
args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR,
args->total);
break;
default:
if (safi != SAFI_FLOWSPEC)
- zlog_err(
- "Bad nexthop when sending to %s, AFI %u SAFI %u nhlen %d",
- peer->host, afi, safi, attr->mp_nexthop_len);
+ flog_err(
+ BGP_ERR_ATTR_NH_SEND_LEN,
+ "Bad nexthop when sending to %s, AFI %u SAFI %u nhlen %d",
+ peer->host, afi, safi, attr->mp_nexthop_len);
break;
}
else
len = sprintf(str_buf + str_pnt,
"MM:%u", seqnum);
+ } else if (*pnt == ECOMMUNITY_EVPN_SUBTYPE_ND) {
+ uint8_t flags = *++pnt;
+
+ if (flags
+ & ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG)
+ len = sprintf(str_buf + str_pnt,
+ "ND:Router Flag");
} else
unk_ecom = 1;
} else if (type == ECOMMUNITY_ENCODE_REDIRECT_IP_NH) {
--- /dev/null
+/*
+ * BGP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Don Slice
+ *
+ * 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 "bgp_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_bgp_err[] = {
+ {
+ .code = BGP_ERR_ATTR_FLAG,
+ .title = "BGP attribute flag is incorrect",
+ .description = "BGP attribute flag is set to the wrong value (Optional/Transitive/Partial)",
+ .suggestion = "Determine the soure of the attribute and determine why the attribute flag has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_ATTR_LEN,
+ .title = "BGP attribute length is incorrect",
+ .description = "BGP attribute length is incorrect",
+ .suggestion = "Determine the soure of the attribute and determine why the attribute length has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_ATTR_ORIGIN,
+ .title = "BGP attribute origin value invalid",
+ .description = "BGP attribute origin value is invalid",
+ .suggestion = "Determine the soure of the attribute and determine why the origin attribute has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_ATTR_MAL_AS_PATH,
+ .title = "BGP as path is invalid",
+ .description = "BGP as path has been malformed",
+ .suggestion = "Determine the soure of the update and determine why the as path has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_ATTR_FIRST_AS,
+ .title = "BGP as path first as is invalid",
+ .description = "BGP update has invalid first as in as path",
+ .suggestion = "Determine the soure of the update and determine why the as path first as value has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_ATTR_PMSI_TYPE,
+ .title = "BGP PMSI tunnel attribute type is invalid",
+ .description = "BGP update has invalid type for PMSI tunnel",
+ .suggestion = "Determine the soure of the update and determine why the PMSI tunnel attribute type has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_ATTR_PMSI_LEN,
+ .title = "BGP PMSI tunnel attribute length is invalid",
+ .description = "BGP update has invalid length for PMSI tunnel",
+ .suggestion = "Determine the soure of the update and determine why the PMSI tunnel attribute length has been set incorrectly"
+ },
+ {
+ .code = BGP_ERR_PEER_GROUP,
+ .title = "BGP peergroup operated on in error",
+ .description = "BGP operating on peer-group instead of peers included",
+ .suggestion = "Ensure the config doesn't contain peergroups contained within peergroups"
+ },
+ {
+ .code = BGP_ERR_PEER_DELETE,
+ .title = "BGP failed to delete peer structure",
+ .description = "BGP was unable to delete peer structure when address-family removed",
+ .suggestion = "Determine if all expected peers are removed and restart FRR if not. Most likely a bug"
+ },
+ {
+ .code = BGP_ERR_TABLE_CHUNK,
+ .title = "BGP failed to get table chunk memory",
+ .description = "BGP unable to get chunk memory for table manager",
+ .suggestion = "Ensure there is adequate memory on the device to support the table requirements"
+ },
+ {
+ .code = BGP_ERR_MACIP_LEN,
+ .title = "BGP received MACIP with invalid IP addr len",
+ .description = "BGP received MACIP with invalid IP addr len from Zebra",
+ .suggestion = "Verify MACIP entries inserted in Zebra are correct. Most likely a bug"
+ },
+ {
+ .code = BGP_ERR_LM_ERROR,
+ .title = "BGP received invalid label manager message",
+ .description = "BGP received invalid label manager message from label manager",
+ .suggestion = "Label manager sent invalid essage to BGP for wrong protocol, instance, etc. Most likely a bug"
+ },
+ {
+ .code = BGP_ERR_JSON_MEM_ERROR,
+ .title = "BGP unable to allocate memory for JSON output",
+ .description = "BGP attempted to generate JSON output and was unable to allocate the memory required",
+ .suggestion = "Ensure that the device has adequate memory to suport the required functions"
+ },
+ {
+ .code = BGP_ERR_UPDGRP_ATTR_LEN,
+ .title = "BGP update had attributes too long to send",
+ .description = "BGP attempted to send an update but the attributes were too long to fit",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_UPDGRP_CREATE,
+ .title = "BGP update group creation failed",
+ .description = "BGP attempted to create an update group but was unable to",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_UPDATE_SND,
+ .title = "BGP error creating update packet",
+ .description = "BGP attempted to create an update packet but was unable to",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_PKT_OPEN,
+ .title = "BGP error receiving open packet",
+ .description = "BGP received an open from a peer that was invalid",
+ .suggestion = "Determine the sending peer and correct his invalid open packet"
+ },
+ {
+ .code = BGP_ERR_SND_FAIL,
+ .title = "BGP error sending to peer",
+ .description = "BGP attempted to respond to open from a peer and failed",
+ .suggestion = "BGP attempted to respond to an open and could not sene the packet. Check local IP address for source"
+ },
+ {
+ .code = BGP_ERR_INVALID_STATUS,
+ .title = "BGP error receiving from peer",
+ .description = "BGP received an update from a peer but status was incorrect",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_UPDATE_RCV,
+ .title = "BGP error receiving update packet",
+ .description = "BGP received an invalid update packet",
+ .suggestion = "Determine the source of the update and resolve the invalid update being sent"
+ },
+ {
+ .code = BGP_ERR_NO_CAP,
+ .title = "BGP error due to capability not enabled",
+ .description = "BGP attempted a function that did not have the capability enabled",
+ .suggestion = "Enable the capability if this functionality is desired"
+ },
+ {
+ .code = BGP_ERR_NOTIFY_RCV,
+ .title = "BGP error receiving notify message",
+ .description = "BGP unable to process notification message",
+ .suggestion = "BGP notify received while in stopped state. If the problem persists, report for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_KEEP_RCV,
+ .title = "BGP error receiving keepalive packet",
+ .description = "BGP unable to process keepalive packet",
+ .suggestion = "BGP keepalive received while in stopped state. If the problem persists, report for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_RFSH_RCV,
+ .title = "BGP error receiving route refresh message",
+ .description = "BGP unable to process route refresh message",
+ .suggestion = "BGP route refresh received while in stopped state. If the problem persists, report for troubleshooting"},
+ {
+ .code = BGP_ERR_CAP_RCV,
+ .title = "BGP error capability message",
+ .description = "BGP unable to process received capability",
+ .suggestion = "BGP capability message received while in stopped state. If the problem persists, report for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_NH_UPD,
+ .title = "BGP error with nexthopo update",
+ .description = "BGP unable to process nexthop update",
+ .suggestion = "BGP received nexthop update but nexthop is not reachable in this bgp instance. Report for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_LABEL,
+ .title = "Failure to apply label",
+ .description = "BGP attempted to attempted to apply a label but could not",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_MULTIPATH,
+ .title = "Multipath specified is invalid",
+ .description = "BGP was started with an invalid ecmp/multipath value",
+ .suggestion = "Correct the ecmp/multipath value supplied when starting the BGP daemon"
+ },
+ {
+ .code = BGP_ERR_PKT_PROCESS,
+ .title = "Failure to process a packet",
+ .description = "BGP attempted to process a received packet but could not",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_CONNECT,
+ .title = "Failure to connect to peer",
+ .description = "BGP attempted to send open to peer but couldn't connect",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_FSM,
+ .title = "BGP FSM issue",
+ .description = "BGP neighbor transition problem",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_VNI,
+ .title = "BGP VNI creation issue",
+ .description = "BGP could not create a new VNI",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_NO_DFLT,
+ .title = "BGP default instance missing",
+ .description = "BGP could not find default instance",
+ .suggestion = "Define a default instance of BGP since some feature requires it's existence"
+ },
+ {
+ .code = BGP_ERR_VTEP_INVALID,
+ .title = "BGP remote VTEP invalid",
+ .description = "BGP remote VTEP is invalid and cannot be used",
+ .suggestion = "Correct remote VTEP configuration or resolve the source of the problem"
+ },
+ {
+ .code = BGP_ERR_ES_INVALID,
+ .title = "BGP ES route error",
+ .description = "BGP ES route incorrect, learned both local and remote",
+ .suggestion = "Correct configuration or addressing so that same not learned both local and remote"
+ },
+ {
+ .code = BGP_ERR_EVPN_ROUTE_DELETE,
+ .title = "BGP EVPN route delete error",
+ .description = "BGP attempted to delete an EVPN route and failed",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_EVPN_FAIL,
+ .title = "BGP EVPN install/uninstall error",
+ .description = "BGP attempted to install or uninstall an EVPN prefix and failed",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_EVPN_ROUTE_INVALID,
+ .title = "BGP EVPN route received with invalid contents",
+ .description = "BGP received an EVPN route with invalid contents",
+ .suggestion = "Determine the source of the EVPN route and resolve whatever is causing invalid contents"
+ },
+ {
+ .code = BGP_ERR_EVPN_ROUTE_CREATE,
+ .title = "BGP EVPN route create error",
+ .description = "BGP attempted to create an EVPN route and failed",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_ES_CREATE,
+ .title = "BGP EVPN ES entry create error",
+ .description = "BGP attempted to create an EVPN ES entry and failed",
+ .suggestion = "Most likely a bug. If the problem persists, report the problem for troubleshooting"
+ },
+ {
+ .code = BGP_ERR_MULTI_INSTANCE,
+ .title = "BGP config multi-instance issue",
+ .description = "BGP configuration attempting multiple instances without enabling the feature",
+ .suggestion = "Correct the configuration so that bgp multiple-instance is enabled if desired"
+ },
+ {
+ .code = BGP_ERR_EVPN_AS_MISMATCH,
+ .title = "BGP AS configuration issue",
+ .description = "BGP configuration attempted for a different AS than currently configured",
+ .suggestion = "Correct the configuration so that the correct BGP AS number is used"
+ },
+ {
+ .code = BGP_ERR_EVPN_INSTANCE_MISMATCH,
+ .title = "BGP EVPN AS and process name mismatch",
+ .description = "BGP configuration has AS and process name mismatch",
+ .suggestion = "Correct the configuration so that the BGP AS number and instance name are consistent"
+ },
+ {
+ .code = BGP_ERR_FLOWSPEC_PACKET,
+ .title = "BGP Flowspec packet processing error",
+ .description = "The BGP flowspec subsystem has detected a error in the send or receive of a packet",
+ .suggestion = "Gather log files from both sides of the peering relationship and open an issue"
+ },
+ {
+ .code = BGP_ERR_FLOWSPEC_INSTALLATION,
+ .title = "BGP Flowspec Installation/removal Error",
+ .description = "The BGP flowspec subsystem has detected that there was a failure for installation/removal/modification of Flowspec from the dataplane",
+ .suggestion = "Gather log files from the router and open an issue, Restart FRR"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void bgp_error_init(void)
+{
+ log_ref_add(ferr_bgp_err);
+}
--- /dev/null
+/*
+ * BGP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Don Slice
+ *
+ * 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 __BGP_ERRORS_H__
+#define __BGP_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum bgp_log_refs {
+
+ BGP_ERR_ATTR_FLAG = BGP_FERR_START,
+ BGP_ERR_ATTR_LEN,
+ BGP_ERR_ATTR_ORIGIN,
+ BGP_ERR_ATTR_MAL_AS_PATH,
+ BGP_ERR_ATTR_FIRST_AS,
+ BGP_ERR_ATTR_MARTIAN_NH,
+ BGP_ERR_ATTR_PMSI_TYPE,
+ BGP_ERR_ATTR_PMSI_LEN,
+ BGP_ERR_ATTR_NH_SEND_LEN,
+ BGP_ERR_PEER_GROUP,
+ BGP_ERR_PEER_DELETE,
+ BGP_ERR_TABLE_CHUNK,
+ BGP_ERR_MACIP_LEN,
+ BGP_ERR_LM_ERROR,
+ BGP_ERR_JSON_MEM_ERROR,
+ BGP_ERR_UPDGRP_ATTR_LEN,
+ BGP_ERR_UPDGRP_CREATE,
+ BGP_ERR_UPDATE_SND,
+ BGP_ERR_PKT_OPEN,
+ BGP_ERR_SND_FAIL,
+ BGP_ERR_INVALID_STATUS,
+ BGP_ERR_UPDATE_RCV,
+ BGP_ERR_NO_CAP,
+ BGP_ERR_NOTIFY_RCV,
+ BGP_ERR_KEEP_RCV,
+ BGP_ERR_RFSH_RCV,
+ BGP_ERR_CAP_RCV,
+ BGP_ERR_NH_UPD,
+ BGP_ERR_LABEL,
+ BGP_ERR_MULTIPATH,
+ BGP_ERR_PKT_PROCESS,
+ BGP_ERR_CONNECT,
+ BGP_ERR_FSM,
+ BGP_ERR_VNI,
+ BGP_ERR_NO_DFLT,
+ BGP_ERR_VTEP_INVALID,
+ BGP_ERR_ES_INVALID,
+ BGP_ERR_EVPN_ROUTE_DELETE,
+ BGP_ERR_EVPN_FAIL,
+ BGP_ERR_EVPN_ROUTE_INVALID,
+ BGP_ERR_EVPN_ROUTE_CREATE,
+ BGP_ERR_ES_CREATE,
+ BGP_ERR_MULTI_INSTANCE,
+ BGP_ERR_EVPN_AS_MISMATCH,
+ BGP_ERR_EVPN_INSTANCE_MISMATCH,
+ BGP_ERR_FLOWSPEC_PACKET,
+ BGP_ERR_FLOWSPEC_INSTALLATION,
+};
+
+extern void bgp_error_init(void);
+
+#endif
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_encap_types.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_nexthop.h"
bgp_def = bgp_get_default();
if (!bgp_def) {
- zlog_err("vrf import rt new - def instance not created yet");
+ flog_err(BGP_ERR_NO_DFLT,
+ "vrf import rt new - def instance not created yet");
return NULL;
}
bgp_def = bgp_get_default();
if (!bgp_def) {
- zlog_err("vrf import rt free - def instance not created yet");
+ flog_err(BGP_ERR_NO_DFLT,
+ "vrf import rt free - def instance not created yet");
return;
}
bgp_def = bgp_get_default();
if (!bgp_def) {
- zlog_err("vrf import rt lookup - def instance not created yet");
+ flog_err(
+ BGP_ERR_NO_DFLT,
+ "vrf import rt lookup - def instance not created yet");
return NULL;
}
if (is_evpn_prefix_ipaddr_v4(p))
stream_put_in_addr(s, &p->prefix.imet_addr.ip.ipaddr_v4);
else if (is_evpn_prefix_ipaddr_v6(p)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_VTEP_INVALID,
"Bad remote IP when trying to %s remote VTEP for VNI %u",
add ? "ADD" : "DEL", vpn->vni);
return -1;
* We shouldn't see the same route from any other vtep.
*/
if (remote_ri) {
- zlog_err(
- "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
- bgp->vrf_id,
- esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)),
- ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
+ flog_err(
+ BGP_ERR_ES_INVALID,
+ "%u ERROR: local es route for ESI: %s Vtep %s also learnt from remote",
+ bgp->vrf_id,
+ esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)),
+ ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
return -1;
}
&attr, 1, &ri,
&route_changed);
if (ret != 0) {
- zlog_err("%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
- bgp->vrf_id,
- esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)),
- ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
+ flog_err(
+ BGP_ERR_ES_INVALID,
+ "%u ERROR: Failed to updated ES route ESI: %s VTEP %s",
+ bgp->vrf_id,
+ esi_to_str(&p->prefix.es_addr.esi, buf, sizeof(buf)),
+ ipaddr2str(&es->originator_ip, buf1, sizeof(buf1)));
}
assert(ri);
build_evpn_type4_prefix(&p, &es->esi, es->originator_ip.ipaddr_v4);
ret = delete_evpn_type4_route(bgp, es, &p);
if (ret) {
- zlog_err(
- "%u failed to delete type-4 route for ESI %s",
- bgp->vrf_id,
- esi_to_str(&es->esi, buf, sizeof(buf)));
+ flog_err(BGP_ERR_EVPN_ROUTE_DELETE,
+ "%u failed to delete type-4 route for ESI %s",
+ bgp->vrf_id, esi_to_str(&es->esi, buf, sizeof(buf)));
}
/* Delete all routes from per ES table */
bgp, es, evp, ri);
if (ret) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_FAIL,
"Failed to %s EVPN %s route in ESI %s",
install ? "install"
: "uninstall",
bgp_vrf, evp, ri);
if (ret) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_FAIL,
"Failed to %s EVPN %s route in VRF %s",
install ? "install"
: "uninstall",
bgp, vpn, evp, ri);
if (ret) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_FAIL,
"%u: Failed to %s EVPN %s route in VNI %u",
bgp->vrf_id,
install ? "install"
ret = uninstall_evpn_route_entry_in_es(bgp, es, evp, ri);
if (ret) {
- zlog_err("%u: Failed to %s EVPN %s route in ESI %s",
- bgp->vrf_id, install ? "install" : "uninstall",
- "ES",
- esi_to_str(&evp->prefix.es_addr.esi, buf,
- sizeof(buf)));
+ flog_err(
+ BGP_ERR_EVPN_FAIL,
+ "%u: Failed to %s EVPN %s route in ESI %s", bgp->vrf_id,
+ install ? "install" : "uninstall", "ES",
+ esi_to_str(&evp->prefix.es_addr.esi, buf, sizeof(buf)));
return ret;
}
return 0;
ri);
if (ret) {
- zlog_err("%u: Failed to %s prefix %s in VRF %s",
- bgp_def->vrf_id,
- install ? "install" : "uninstall",
- prefix2str(evp, buf, sizeof(buf)),
- vrf_id_to_name(bgp_vrf->vrf_id));
+ flog_err(BGP_ERR_EVPN_FAIL,
+ "%u: Failed to %s prefix %s in VRF %s",
+ bgp_def->vrf_id,
+ install ? "install" : "uninstall",
+ prefix2str(evp, buf, sizeof(buf)),
+ vrf_id_to_name(bgp_vrf->vrf_id));
return ret;
}
}
ret = uninstall_evpn_route_entry(bgp, vpn, evp, ri);
if (ret) {
- zlog_err("%u: Failed to %s EVPN %s route in VNI %u",
- bgp->vrf_id, install ? "install" : "uninstall",
- evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE
- ? "MACIP"
- : "IMET",
- vpn->vni);
+ flog_err(
+ BGP_ERR_EVPN_FAIL,
+ "%u: Failed to %s EVPN %s route in VNI %u",
+ bgp->vrf_id, install ? "install" : "uninstall",
+ evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE
+ ? "MACIP"
+ : "IMET",
+ vpn->vni);
return ret;
}
}
*/
static void update_router_id_vni(struct hash_backet *backet, struct bgp *bgp)
{
- struct bgpevpn *vpn;
-
- vpn = (struct bgpevpn *)backet->data;
-
- if (!vpn) {
- zlog_warn("%s: VNI hash entry for VNI not found", __FUNCTION__);
- return;
- }
+ struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
/* Skip VNIs with configured RD. */
if (is_rd_configured(vpn))
*/
static void withdraw_router_id_vni(struct hash_backet *backet, struct bgp *bgp)
{
- struct bgpevpn *vpn;
-
- vpn = (struct bgpevpn *)backet->data;
-
- if (!vpn) {
- zlog_warn("%s: VNI hash entry for VNI not found", __FUNCTION__);
- return;
- }
+ struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
/* Skip VNIs with configured RD. */
if (is_rd_configured(vpn))
*/
if (psize != 33 && psize != 37 && psize != 49 && psize != 36
&& psize != 40 && psize != 52) {
- zlog_err("%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
- peer->bgp->vrf_id, peer->host, psize);
+ flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-2 NLRI with invalid length %d",
+ peer->bgp->vrf_id, peer->host, psize);
return -1;
}
memcpy(&p.prefix.macip_addr.mac.octet, pfx, ETH_ALEN);
pfx += ETH_ALEN;
} else {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-2 NLRI with unsupported MAC address length %d",
peer->bgp->vrf_id, peer->host, macaddr_len);
return -1;
ipaddr_len = *pfx++;
if (ipaddr_len != 0 && ipaddr_len != IPV4_MAX_BITLEN
&& ipaddr_len != IPV6_MAX_BITLEN) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-2 NLRI with unsupported IP address length %d",
peer->bgp->vrf_id, peer->host, ipaddr_len);
return -1;
* IP len (1) and IP (4 or 16).
*/
if (psize != 17 && psize != 29) {
- zlog_err("%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
- peer->bgp->vrf_id, peer->host, psize);
+ flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-3 NLRI with invalid length %d",
+ peer->bgp->vrf_id, peer->host, psize);
return -1;
}
p.prefix.imet_addr.ip.ipa_type = IPADDR_V4;
memcpy(&p.prefix.imet_addr.ip.ip.addr, pfx, IPV4_MAX_BYTELEN);
} else {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-3 NLRI with unsupported IP address length %d",
peer->bgp->vrf_id, peer->host, ipaddr_len);
return -1;
* RD (8), ESI (10), ip-len (1), ip (4 or 16)
*/
if (psize != 23 && psize != 35) {
- zlog_err("%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
- peer->bgp->vrf_id, peer->host, psize);
+ flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-4 NLRI with invalid length %d",
+ peer->bgp->vrf_id, peer->host, psize);
return -1;
}
if (ipaddr_len == IPV4_MAX_BITLEN) {
memcpy(&vtep_ip, pfx, IPV4_MAX_BYTELEN);
} else {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-4 NLRI with unsupported IP address length %d",
peer->bgp->vrf_id, peer->host, ipaddr_len);
return -1;
* Note that the IP and GW should both be IPv4 or both IPv6.
*/
if (psize != 34 && psize != 58) {
- zlog_err("%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
- peer->bgp->vrf_id, peer->host, psize);
+ flog_err(BGP_ERR_EVPN_ROUTE_INVALID,
+ "%u:%s - Rx EVPN Type-5 NLRI with invalid length %d",
+ peer->bgp->vrf_id, peer->host, psize);
return -1;
}
/* Fetch IP prefix length. */
ippfx_len = *pfx++;
if (ippfx_len > IPV6_MAX_BITLEN) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_INVALID,
"%u:%s - Rx EVPN Type-5 NLRI with invalid IP Prefix length %d",
peer->bgp->vrf_id, peer->host, ippfx_len);
return -1;
*/
static void free_vni_entry(struct hash_backet *backet, struct bgp *bgp)
{
- struct bgpevpn *vpn;
+ struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
- vpn = (struct bgpevpn *)backet->data;
delete_all_vni_routes(bgp, vpn);
bgp_evpn_free(bgp, vpn);
}
{
struct bgpevpn *vpn = backet->data;
- if (!vpn) {
- zlog_warn("%s: VNI hash entry for VNI not found", __PRETTY_FUNCTION__);
- return;
- }
-
if (!is_import_rt_configured(vpn)) {
if (is_vni_live(vpn))
bgp_evpn_uninstall_routes(bgp, vpn);
build_type5_prefix_from_ip_prefix(&evp, p);
ret = delete_evpn_type5_route(bgp_vrf, &evp);
if (ret) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_DELETE,
"%u failed to delete type-5 route for prefix %s in vrf %s",
bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)),
vrf_id_to_name(bgp_vrf->vrf_id));
build_type5_prefix_from_ip_prefix(&evp, p);
ret = update_evpn_type5_route(bgp_vrf, &evp, src_attr);
if (ret)
- zlog_err("%u: Failed to create type-5 route for prefix %s",
- bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)));
+ flog_err(BGP_ERR_EVPN_ROUTE_CREATE,
+ "%u: Failed to create type-5 route for prefix %s",
+ bgp_vrf->vrf_id, prefix2str(p, buf, sizeof(buf)));
}
/* Inject all prefixes of a particular address-family (currently, IPv4 or
if (process_type2_route(peer, afi, safi,
withdraw ? NULL : attr, pnt,
psize, addpath_id)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_FAIL,
"%u:%s - Error in processing EVPN type-2 NLRI size %d",
peer->bgp->vrf_id, peer->host, psize);
return -1;
if (process_type3_route(peer, afi, safi,
withdraw ? NULL : attr, pnt,
psize, addpath_id)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_PROCESS,
"%u:%s - Error in processing EVPN type-3 NLRI size %d",
peer->bgp->vrf_id, peer->host, psize);
return -1;
if (process_type4_route(peer, afi, safi,
withdraw ? NULL : attr, pnt,
psize, addpath_id)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_PROCESS,
"%u:%s - Error in processing EVPN type-4 NLRI size %d",
peer->bgp->vrf_id, peer->host, psize);
return -1;
case BGP_EVPN_IP_PREFIX_ROUTE:
if (process_type5_route(peer, afi, safi, attr, pnt,
psize, addpath_id, withdraw)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_PROCESS,
"%u:%s - Error in processing EVPN type-5 NLRI size %d",
peer->bgp->vrf_id, peer->host, psize);
return -1;
char buf[ETHER_ADDR_STRLEN];
char buf2[INET6_ADDRSTRLEN];
- zlog_err(
+ flog_err(
+ BGP_ERR_EVPN_ROUTE_CREATE,
"%u:Failed to create Type-2 route, VNI %u %s MAC %s IP %s (flags: 0x%x)",
bgp->vrf_id, vpn->vni,
CHECK_FLAG(flags, ZEBRA_MACIP_TYPE_STICKY)
static void link_l2vni_hash_to_l3vni(struct hash_backet *backet,
struct bgp *bgp_vrf)
{
- struct bgpevpn *vpn = NULL;
+ struct bgpevpn *vpn = (struct bgpevpn *)backet->data;
struct bgp *bgp_def = NULL;
bgp_def = bgp_get_default();
assert(bgp_def);
- vpn = (struct bgpevpn *)backet->data;
if (vpn->tenant_vrf_id == bgp_vrf->vrf_id)
bgpevpn_link_to_l3vni(vpn);
}
*/
bgp_def = bgp_get_default();
if (!bgp_def) {
- zlog_err(
+ flog_err(
+ BGP_ERR_NO_DFLT,
"Cannot process L3VNI %u ADD - default BGP instance not yet created",
l3vni);
return -1;
BGP_INSTANCE_TYPE_VRF);
switch (ret) {
case BGP_ERR_MULTIPLE_INSTANCE_NOT_SET:
- zlog_err("'bgp multiple-instance' not present\n");
+ flog_err(BGP_ERR_MULTI_INSTANCE,
+ "'bgp multiple-instance' not present\n");
return -1;
case BGP_ERR_AS_MISMATCH:
- zlog_err("BGP is already running; AS is %u\n", as);
+ flog_err(BGP_ERR_EVPN_AS_MISMATCH,
+ "BGP is already running; AS is %u\n", as);
return -1;
case BGP_ERR_INSTANCE_MISMATCH:
- zlog_err("BGP instance name and AS number mismatch\n");
+ flog_err(BGP_ERR_EVPN_INSTANCE_MISMATCH,
+ "BGP instance name and AS number mismatch\n");
return -1;
}
bgp_vrf = bgp_lookup_by_vrf_id(vrf_id);
if (!bgp_vrf) {
- zlog_err(
+ flog_err(
+ BGP_ERR_NO_DFLT,
"Cannot process L3VNI %u Del - Could not find BGP instance",
l3vni);
return -1;
bgp_def = bgp_get_default();
if (!bgp_def) {
- zlog_err(
+ flog_err(
+ BGP_ERR_NO_DFLT,
"Cannot process L3VNI %u Del - Could not find default BGP instance",
l3vni);
return -1;
if (!vpn) {
vpn = bgp_evpn_new(bgp, vni, originator_ip, tenant_vrf_id);
if (!vpn) {
- zlog_err(
+ flog_err(
+ BGP_ERR_VNI,
"%u: Failed to allocate VNI entry for VNI %u - at Add",
bgp->vrf_id, vni);
return -1;
/* Create EVPN type-3 route and schedule for processing. */
build_evpn_type3_prefix(&p, vpn->originator_ip);
if (update_evpn_route(bgp, vpn, &p, 0)) {
- zlog_err("%u: Type3 route creation failure for VNI %u",
- bgp->vrf_id, vni);
+ flog_err(BGP_ERR_EVPN_ROUTE_CREATE,
+ "%u: Type3 route creation failure for VNI %u",
+ bgp->vrf_id, vni);
return -1;
}
struct evpnes *es = NULL;
if (!bgp->esihash) {
- zlog_err("%u: ESI hash not yet created", bgp->vrf_id);
+ flog_err(BGP_ERR_ES_CREATE, "%u: ESI hash not yet created",
+ bgp->vrf_id);
return -1;
}
struct prefix_evpn p;
if (!bgp->esihash) {
- zlog_err("%u: ESI hash not yet created", bgp->vrf_id);
+ flog_err(BGP_ERR_ES_CREATE, "%u: ESI hash not yet created",
+ bgp->vrf_id);
return -1;
}
if (!es) {
es = bgp_evpn_es_new(bgp, esi, originator_ip);
if (!es) {
- zlog_err(
+ flog_err(
+ BGP_ERR_ES_CREATE,
"%u: Failed to allocate ES entry for ESI %s - at Local ES Add",
bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
return -1;
build_evpn_type4_prefix(&p, esi, originator_ip->ipaddr_v4);
if (update_evpn_type4_route(bgp, es, &p)) {
- zlog_err("%u: Type4 route creation failure for ESI %s",
- bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
+ flog_err(BGP_ERR_EVPN_ROUTE_CREATE,
+ "%u: Type4 route creation failure for ESI %s",
+ bgp->vrf_id, esi_to_str(esi, buf, sizeof(buf)));
return -1;
}
#include "bgpd/bgp_evpn_private.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_vty.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_ecommunity.h"
#define SHOW_DISPLAY_STANDARD 0
*/
vpn = bgp_evpn_new(bgp, vni, bgp->router_id, 0);
if (!vpn) {
- zlog_err(
+ flog_err(
+ BGP_ERR_VNI,
"%u: Failed to allocate VNI entry for VNI %u - at Config",
bgp->vrf_id, vni);
return NULL;
#include <zebra.h>
#include "prefix.h"
+#include "lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_flowspec_private.h"
#include "bgpd/bgp_ecommunity.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
static int bgp_fs_nlri_validate(uint8_t *nlri_content, uint32_t len)
{
safi = packet->safi;
if (afi == AFI_IP6) {
- zlog_err("BGP flowspec IPv6 not supported");
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "BGP flowspec IPv6 not supported");
return -1;
}
if (packet->length >= FLOWSPEC_NLRI_SIZELIMIT) {
- zlog_err("BGP flowspec nlri length maximum reached (%u)",
- packet->length);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "BGP flowspec nlri length maximum reached (%u)",
+ packet->length);
return -1;
}
/* When packet overflow occur return immediately. */
if (pnt + psize > lim) {
- zlog_err("Flowspec NLRI length inconsistent ( size %u seen)",
- psize);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "Flowspec NLRI length inconsistent ( size %u seen)",
+ psize);
return -1;
}
if (bgp_fs_nlri_validate(pnt, psize) < 0) {
- zlog_err("Bad flowspec format or NLRI options not supported");
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "Bad flowspec format or NLRI options not supported");
return -1;
}
p.family = AF_FLOWSPEC;
ZEBRA_ROUTE_BGP, BGP_ROUTE_NORMAL,
NULL, NULL, 0, NULL);
if (ret) {
- zlog_err("Flowspec NLRI failed to be %s.",
- attr ? "added" : "withdrawn");
+ flog_err(BGP_ERR_FLOWSPEC_INSTALLATION,
+ "Flowspec NLRI failed to be %s.",
+ attr ? "added" : "withdrawn");
return -1;
}
}
#include "zebra.h"
#include "prefix.h"
+#include "lib_errors.h"
#include "bgp_table.h"
#include "bgp_flowspec_util.h"
#include "bgp_flowspec_private.h"
#include "bgp_pbr.h"
+#include "bgp_errors.h"
static void hex2bin(uint8_t *hex, int *bin)
{
len,
mval, error);
if (*error < 0)
- zlog_err("%s: flowspec_op_decode error %d",
- __func__, *error);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "%s: flowspec_op_decode error %d",
+ __func__, *error);
else
*match_num = *error;
return ret;
len - offset,
prefix, &error);
if (error < 0)
- zlog_err("%s: flowspec_ip_address error %d",
- __func__, error);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "%s: flowspec_ip_address error %d",
+ __func__, error);
else
bpem->match_bitmask |= bitmask;
offset += ret;
len - offset,
&bpem->tcpflags, &error);
if (error < 0)
- zlog_err("%s: flowspec_tcpflags_decode error %d",
- __func__, error);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "%s: flowspec_tcpflags_decode error %d",
+ __func__, error);
else
bpem->match_tcpflags_num = error;
/* contains the number of slots used */
len - offset, &bpem->fragment,
&error);
if (error < 0)
- zlog_err("%s: flowspec_fragment_type_decode error %d",
- __func__, error);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "%s: flowspec_fragment_type_decode error %d",
+ __func__, error);
else
bpem->match_fragment_num = error;
offset += ret;
break;
default:
- zlog_err("%s: unknown type %d\n", __func__, type);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: unknown type %d\n",
+ __func__, type);
}
}
return error;
#include "queue.h"
#include "filter.h"
#include "command.h"
+#include "lib_errors.h"
#include "lib/json.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_network.h"
* runs in our pthread.
*/
if (peer->curr) {
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_PROCESS,
"[%s] Dropping pending packet on connection transfer:",
peer->host);
uint16_t type = stream_getc_from(peer->curr,
}
if (bgp_getsockname(peer) < 0) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%%bgp_getsockname() failed for %s peer %s fd %d (from_peer fd %d)",
(CHECK_FLAG(peer->sflags, PEER_STATUS_ACCEPT_PEER)
? "accept"
}
if (from_peer->status > Active) {
if (bgp_getsockname(from_peer) < 0) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%%bgp_getsockname() failed for %s from_peer %s fd %d (peer fd %d)",
+
(CHECK_FLAG(from_peer->sflags,
PEER_STATUS_ACCEPT_PEER)
? "accept"
static int bgp_connect_success(struct peer *peer)
{
if (peer->fd < 0) {
- zlog_err("bgp_connect_success peer's fd is negative value %d",
- peer->fd);
+ flog_err(BGP_ERR_CONNECT,
+ "bgp_connect_success peer's fd is negative value %d",
+ peer->fd);
bgp_stop(peer);
return -1;
}
if (bgp_getsockname(peer) < 0) {
- zlog_err("%s: bgp_getsockname(): failed for peer %s, fd %d",
- __FUNCTION__, peer->host, peer->fd);
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: bgp_getsockname(): failed for peer %s, fd %d",
+ __FUNCTION__, peer->host, peer->fd);
bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR,
0); /* internal error */
bgp_writes_on(peer);
if (BGP_PEER_START_SUPPRESSED(peer)) {
if (bgp_debug_neighbor_events(peer))
- zlog_err(
- "%s [FSM] Trying to start suppressed peer"
- " - this is never supposed to happen!",
- peer->host);
+ flog_err(BGP_ERR_FSM,
+ "%s [FSM] Trying to start suppressed peer"
+ " - this is never supposed to happen!",
+ peer->host);
return -1;
}
if (peer->bgp->vrf_id == VRF_UNKNOWN) {
if (bgp_debug_neighbor_events(peer))
- zlog_err(
+ flog_err(
+ BGP_ERR_FSM,
"%s [FSM] In a VRF that is not initialised yet",
peer->host);
return -1;
"%s [FSM] Non blocking connect waiting result, fd %d",
peer->host, peer->fd);
if (peer->fd < 0) {
- zlog_err("bgp_start peer's fd is negative value %d",
- peer->fd);
+ flog_err(BGP_ERR_FSM,
+ "bgp_start peer's fd is negative value %d",
+ peer->fd);
return -1;
}
/*
peer and change to Idle status. */
static int bgp_fsm_event_error(struct peer *peer)
{
- zlog_err("%s [FSM] unexpected packet received in state %s", peer->host,
- lookup_msg(bgp_status_msg, peer->status, NULL));
+ flog_err(BGP_ERR_FSM,
+ "%s [FSM] unexpected packet received in state %s", peer->host,
+ lookup_msg(bgp_status_msg, peer->status, NULL));
return bgp_stop_with_notify(peer, BGP_NOTIFY_FSM_ERR, 0);
}
other = peer->doppelganger;
peer = peer_xfer_conn(peer);
if (!peer) {
- zlog_err("%%Neighbor failed in xfer_conn");
+ flog_err(BGP_ERR_CONNECT, "%%Neighbor failed in xfer_conn");
return -1;
}
/* This is empty event. */
static int bgp_ignore(struct peer *peer)
{
- zlog_err(
+ flog_err(
+ BGP_ERR_FSM,
"%s [FSM] Ignoring event %s in state %s, prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event],
lookup_msg(bgp_status_msg, peer->status, NULL),
/* This is to handle unexpected events.. */
static int bgp_fsm_exeption(struct peer *peer)
{
- zlog_err(
+ flog_err(
+ BGP_ERR_FSM,
"%s [FSM] Unexpected event %s in state %s, prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event],
lookup_msg(bgp_status_msg, peer->status, NULL),
* code.
*/
if (!dyn_nbr && !passive_conn && peer->bgp) {
- zlog_err(
+ flog_err(
+ BGP_ERR_FSM,
"%s [FSM] Failure handling event %s in state %s, "
"prior events %s, %s, fd %d",
peer->host, bgp_event_str[peer->cur_event],
#include "bgpd/bgp_io.h"
#include "bgpd/bgp_debug.h" // for bgp_debug_neighbor_events, bgp_type_str
+#include "bgpd/bgp_errors.h" // for expanded error reference information
#include "bgpd/bgp_fsm.h" // for BGP_EVENT_ADD, bgp_event
#include "bgpd/bgp_packet.h" // for bgp_notify_send_with_data, bgp_notify...
#include "bgpd/bgpd.h" // for peer, BGP_MARKER_SIZE, bgp_master, bm
SET_FLAG(status, BGP_IO_TRANS_ERR);
/* Fatal error; tear down session */
} else if (nbytes < 0) {
- zlog_err("%s [Error] bgp_read_packet error: %s", peer->host,
- safe_strerror(errno));
+ flog_err(BGP_ERR_UPDATE_RCV,
+ "%s [Error] bgp_read_packet error: %s", peer->host,
+ safe_strerror(errno));
if (peer->status == Established) {
if (CHECK_FLAG(peer->sflags, PEER_STATUS_NSF_MODE)) {
/* placeholder bucket data to use for fast key lookups */
static struct pkat holder = {0};
- if (!peerhash_mtx) {
- zlog_warn("%s: call bgp_keepalives_init() first", __func__);
- return;
- }
+ /*
+ * We need to ensure that bgp_keepalives_init was called first
+ */
+ assert(peerhash_mtx);
pthread_mutex_lock(peerhash_mtx);
{
/* placeholder bucket data to use for fast key lookups */
static struct pkat holder = {0};
- if (!peerhash_mtx) {
- zlog_warn("%s: call bgp_keepalives_init() first", __func__);
- return;
- }
+ /*
+ * We need to ensure that bgp_keepalives_init was called first
+ */
+ assert(peerhash_mtx);
pthread_mutex_lock(peerhash_mtx);
{
#include "bgpd/bgp_label.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
extern struct zclient *zclient;
/* sanity check against packet data */
if ((pnt + psize) > lim) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / L-U (prefix length %d exceeds packet size %u)",
peer->host, prefixlen, (uint)(lim - pnt));
return -1;
/* There needs to be at least one label */
if (prefixlen < 24) {
- zlog_err(
- "%s [Error] Update packet error"
- " (wrong label length %d)",
- peer->host, prefixlen);
+ flog_err(BGP_ERR_UPDATE_RCV,
+ "%s [Error] Update packet error"
+ " (wrong label length %d)",
+ peer->host, prefixlen);
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_INVAL_NETWORK);
return -1;
* be logged locally, and the prefix SHOULD be
* ignored.
*/
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: IPv4 labeled-unicast NLRI is multicast address %s, ignoring",
peer->host, inet_ntoa(p.u.prefix4));
continue;
if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) {
char buf[BUFSIZ];
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: IPv6 labeled-unicast NLRI is link-local address %s, ignoring",
peer->host,
inet_ntop(AF_INET6, &p.u.prefix6, buf,
if (IN6_IS_ADDR_MULTICAST(&p.u.prefix6)) {
char buf[BUFSIZ];
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: IPv6 unicast NLRI is multicast address %s, ignoring",
peer->host,
inet_ntop(AF_INET6, &p.u.prefix6, buf,
/* Packet length consistency check. */
if (pnt != lim) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / L-U (%zu data remaining after parsing)",
peer->host, lim - pnt);
return -1;
#include "bgpd/bgpd.h"
#include "bgpd/bgp_labelpool.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
/*
* Definitions and external declarations.
if (lcbq->label == MPLS_LABEL_NONE) {
/* shouldn't happen */
- zlog_err("%s: error: label==MPLS_LABEL_NONE", __func__);
+ flog_err(BGP_ERR_LABEL, "%s: error: label==MPLS_LABEL_NONE",
+ __func__);
return WQ_SUCCESS;
}
if (rc) {
/* shouldn't happen */
- zlog_err("%s: can't insert new LCB into ledger list",
- __func__);
+ flog_err(BGP_ERR_LABEL,
+ "%s: can't insert new LCB into ledger list",
+ __func__);
XFREE(MTYPE_BGP_LABEL_CB, lcb);
return;
}
struct lp_fifo *lf;
if (last < first) {
- zlog_err("%s: zebra label chunk invalid: first=%u, last=%u",
- __func__, first, last);
+ flog_err(BGP_ERR_LABEL,
+ "%s: zebra label chunk invalid: first=%u, last=%u",
+ __func__, first, last);
return;
}
#include "bgpd/bgp_regex.h"
#include "bgpd/bgp_clist.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_filter.h"
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_keepalives.h"
#include "bgpd/bgp_network.h"
+#include "bgpd/bgp_errors.h"
#ifdef ENABLE_BGP_VNC
#include "bgpd/rfapi/rfapi_backend.h"
multipath_num = atoi(optarg);
if (multipath_num > MULTIPATH_NUM
|| multipath_num <= 0) {
- zlog_err(
+ flog_err(
+ BGP_ERR_MULTIPATH,
"Multipath Number specified must be less than %d and greater than 0",
MULTIPATH_NUM);
return 1;
if (no_fib_flag)
bgp_option_set(BGP_OPT_NO_FIB);
+ bgp_error_init();
/* Initializations. */
bgp_vrf_init();
#include "bgpd/bgpd.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h"
psize = PSIZE(prefixlen);
if (prefixlen < VPN_PREFIXLEN_MIN_BYTES * 8) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / VPN (prefix length %d less than VPN min length)",
peer->host, prefixlen);
return -1;
/* sanity check against packet data */
if ((pnt + psize) > lim) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / VPN (prefix length %d exceeds packet size %u)",
peer->host, prefixlen, (uint)(lim - pnt));
return -1;
/* sanity check against storage for the IP address portion */
if ((psize - VPN_PREFIXLEN_MIN_BYTES) > (ssize_t)sizeof(p.u)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / VPN (psize %d exceeds storage size %zu)",
peer->host,
prefixlen - VPN_PREFIXLEN_MIN_BYTES * 8,
/* Sanity check against max bitlen of the address family */
if ((psize - VPN_PREFIXLEN_MIN_BYTES) > prefix_blen(&p)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / VPN (psize %d exceeds family (%u) max byte len %u)",
peer->host,
prefixlen - VPN_PREFIXLEN_MIN_BYTES * 8,
#endif
default:
- zlog_err("Unknown RD type %d", type);
+ flog_err(BGP_ERR_UPDATE_RCV, "Unknown RD type %d",
+ type);
break; /* just report */
}
}
/* Packet length consistency check. */
if (pnt != lim) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error / VPN (%zu data remaining after parsing)",
peer->host, lim - pnt);
return -1;
return 0;
}
/* Shouldn't happen: different label allocation */
- zlog_err("%s: %s had label %u but got new assignment %u",
- __func__, vp->bgp->name_pretty, vp->tovpn_label, label);
+ flog_err(BGP_ERR_LABEL,
+ "%s: %s had label %u but got new assignment %u",
+ __func__, vp->bgp->name_pretty, vp->tovpn_label,
+ label);
/* use new one */
}
#include "hash.h"
#include "filter.h"
#include "ns.h"
+#include "lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_open.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_network.h"
extern struct zebra_privs_t bgpd_privs;
int ret = -1;
#if HAVE_DECL_TCP_MD5SIG
- if (bgpd_privs.change(ZPRIVS_RAISE)) {
- zlog_err("%s: could not raise privs", __func__);
- return ret;
+ frr_elevate_privs(&bgpd_privs) {
+ ret = bgp_md5_set_socket(socket, su, password);
}
-
- ret = bgp_md5_set_socket(socket, su, password);
-
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs", __func__);
#endif /* HAVE_TCP_MD5SIG */
return ret;
int ret = 0;
struct bgp_listener *listener;
- if (bgpd_privs.change(ZPRIVS_RAISE)) {
- zlog_err("%s: could not raise privs", __func__);
- return -1;
- }
-
+ frr_elevate_privs(&bgpd_privs) {
/* Set or unset the password on the listen socket(s). Outbound
- * connections
- * are taken care of in bgp_connect() below.
+ * connections are taken care of in bgp_connect() below.
*/
- for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener))
- if (listener->su.sa.sa_family == peer->su.sa.sa_family) {
- ret = bgp_md5_set_socket(listener->fd, &peer->su,
- password);
- break;
- }
-
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs", __func__);
-
+ for (ALL_LIST_ELEMENTS_RO(bm->listen_sockets, node, listener))
+ if (listener->su.sa.sa_family
+ == peer->su.sa.sa_family) {
+ ret = bgp_md5_set_socket(listener->fd,
+ &peer->su, password);
+ break;
+ }
+ }
return ret;
}
if (!peer->gtsm_hops && (peer_sort(peer) == BGP_PEER_EBGP)) {
ret = sockopt_ttl(peer->su.sa.sa_family, bgp_sock, peer->ttl);
if (ret) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%s: Can't set TxTTL on peer (rtrid %s) socket, err = %d",
- __func__, inet_ntop(AF_INET, &peer->remote_id,
- buf, sizeof(buf)),
+ __func__,
+ inet_ntop(AF_INET, &peer->remote_id, buf,
+ sizeof(buf)),
errno);
return ret;
}
*/
ret = sockopt_ttl(peer->su.sa.sa_family, bgp_sock, MAXTTL);
if (ret) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%s: Can't set TxTTL on peer (rtrid %s) socket, err = %d",
- __func__, inet_ntop(AF_INET, &peer->remote_id,
- buf, sizeof(buf)),
+ __func__,
+ inet_ntop(AF_INET, &peer->remote_id, buf,
+ sizeof(buf)),
errno);
return ret;
}
ret = sockopt_minttl(peer->su.sa.sa_family, bgp_sock,
MAXTTL + 1 - peer->gtsm_hops);
if (ret) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%s: Can't set MinTTL on peer (rtrid %s) socket, err = %d",
- __func__, inet_ntop(AF_INET, &peer->remote_id,
- buf, sizeof(buf)),
+ __func__,
+ inet_ntop(AF_INET, &peer->remote_id, buf,
+ sizeof(buf)),
errno);
return ret;
}
rc = getsockopt(sock, SOL_SOCKET, SO_BINDTODEVICE, name, &name_len);
if (rc != 0) {
#if defined(HAVE_CUMULUS)
- zlog_err("[Error] BGP SO_BINDTODEVICE get failed (%s), sock %d",
- safe_strerror(errno), sock);
+ flog_err(
+ LIB_ERR_SOCKET,
+ "[Error] BGP SO_BINDTODEVICE get failed (%s), sock %d",
+ safe_strerror(errno), sock);
return -1;
#endif
}
/* Register accept thread. */
accept_sock = THREAD_FD(thread);
if (accept_sock < 0) {
- zlog_err("accept_sock is nevative value %d", accept_sock);
+ flog_err_sys(LIB_ERR_SOCKET, "accept_sock is nevative value %d",
+ accept_sock);
return -1;
}
listener->thread = NULL;
/* Accept client connection. */
bgp_sock = sockunion_accept(accept_sock, &su);
if (bgp_sock < 0) {
- zlog_err("[Error] BGP socket accept failed (%s)",
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "[Error] BGP socket accept failed (%s)",
+ safe_strerror(errno));
return -1;
}
set_nonblocking(bgp_sock);
zlog_debug("Peer address not learnt: Returning from connect");
return 0;
}
- if (bgpd_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
+ frr_elevate_privs(&bgpd_privs) {
/* Make socket for the peer. */
- peer->fd = vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id,
- bgp_get_bound_name(peer));
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ peer->fd = vrf_sockunion_socket(&peer->su, peer->bgp->vrf_id,
+ bgp_get_bound_name(peer));
+ }
if (peer->fd < 0)
return -1;
peer->host, safe_strerror(errno));
#ifdef IPTOS_PREC_INTERNETCONTROL
- if (bgpd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs", __func__);
- if (sockunion_family(&peer->su) == AF_INET)
- setsockopt_ipv4_tos(peer->fd, IPTOS_PREC_INTERNETCONTROL);
- else if (sockunion_family(&peer->su) == AF_INET6)
- setsockopt_ipv6_tclass(peer->fd, IPTOS_PREC_INTERNETCONTROL);
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs", __func__);
+ frr_elevate_privs(&bgpd_privs) {
+ if (sockunion_family(&peer->su) == AF_INET)
+ setsockopt_ipv4_tos(peer->fd,
+ IPTOS_PREC_INTERNETCONTROL);
+ else if (sockunion_family(&peer->su) == AF_INET6)
+ setsockopt_ipv6_tclass(peer->fd,
+ IPTOS_PREC_INTERNETCONTROL);
+ }
#endif
if (peer->password)
if (bgp_nexthop_set(peer->su_local, peer->su_remote, &peer->nexthop,
peer)) {
#if defined(HAVE_CUMULUS)
- zlog_err(
+ flog_err(
+ BGP_ERR_NH_UPD,
"%s: nexthop_set failed, resetting connection - intf %p",
peer->host, peer->nexthop.ifp);
return -1;
sockopt_reuseaddr(sock);
sockopt_reuseport(sock);
- if (bgpd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs", __func__);
+ frr_elevate_privs(&bgpd_privs) {
#ifdef IPTOS_PREC_INTERNETCONTROL
- if (sa->sa_family == AF_INET)
- setsockopt_ipv4_tos(sock, IPTOS_PREC_INTERNETCONTROL);
- else if (sa->sa_family == AF_INET6)
- setsockopt_ipv6_tclass(sock, IPTOS_PREC_INTERNETCONTROL);
+ if (sa->sa_family == AF_INET)
+ setsockopt_ipv4_tos(sock, IPTOS_PREC_INTERNETCONTROL);
+ else if (sa->sa_family == AF_INET6)
+ setsockopt_ipv6_tclass(sock,
+ IPTOS_PREC_INTERNETCONTROL);
#endif
- sockopt_v6only(sa->sa_family, sock);
+ sockopt_v6only(sa->sa_family, sock);
- ret = bind(sock, sa, salen);
- en = errno;
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs", __func__);
+ ret = bind(sock, sa, salen);
+ en = errno;
+ }
if (ret < 0) {
- zlog_err("bind: %s", safe_strerror(en));
+ flog_err_sys(LIB_ERR_SOCKET, "bind: %s", safe_strerror(en));
return ret;
}
ret = listen(sock, SOMAXCONN);
if (ret < 0) {
- zlog_err("listen: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "listen: %s",
+ safe_strerror(errno));
return ret;
}
snprintf(port_str, sizeof(port_str), "%d", port);
port_str[sizeof(port_str) - 1] = '\0';
- if (bgpd_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- ret = vrf_getaddrinfo(address, port_str, &req, &ainfo_save,
- bgp->vrf_id);
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&bgpd_privs) {
+ ret = vrf_getaddrinfo(address, port_str, &req, &ainfo_save,
+ bgp->vrf_id);
+ }
if (ret != 0) {
- zlog_err("getaddrinfo: %s", gai_strerror(ret));
+ flog_err_sys(LIB_ERR_SOCKET, "getaddrinfo: %s",
+ gai_strerror(ret));
return -1;
}
if (ainfo->ai_family != AF_INET && ainfo->ai_family != AF_INET6)
continue;
- if (bgpd_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- sock = vrf_socket(ainfo->ai_family, ainfo->ai_socktype,
- ainfo->ai_protocol, bgp->vrf_id,
- (bgp->inst_type == BGP_INSTANCE_TYPE_VRF ?
- bgp->name : NULL));
- if (bgpd_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&bgpd_privs) {
+ sock = vrf_socket(ainfo->ai_family,
+ ainfo->ai_socktype,
+ ainfo->ai_protocol, bgp->vrf_id,
+ (bgp->inst_type
+ == BGP_INSTANCE_TYPE_VRF
+ ? bgp->name : NULL));
+ }
if (sock < 0) {
- zlog_err("socket: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "socket: %s",
+ safe_strerror(errno));
continue;
}
}
freeaddrinfo(ainfo_save);
if (count == 0 && bgp->inst_type != BGP_INSTANCE_TYPE_VRF) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%s: no usable addresses please check other programs usage of specified port %d",
__func__, port);
- zlog_err("%s: Program cannot continue", __func__);
+ flog_err_sys(LIB_ERR_SOCKET, "%s: Program cannot continue",
+ __func__);
exit(-1);
}
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_nexthop.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_nht.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_zebra.h"
bgp = bgp_lookup_by_vrf_id(vrf_id);
if (!bgp) {
- zlog_err(
+ flog_err(
+ BGP_ERR_NH_UPD,
"parse nexthop update: instance not found for vrf_id %u",
vrf_id);
return;
#include "bgpd/bgpd.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_packet.h"
#include "bgpd/bgp_open.h"
SET_FLAG(peer->cap, PEER_CAP_AS4_RCV);
if (hdr->length != CAPABILITY_CODE_AS4_LEN) {
- zlog_err("%s AS4 capability has incorrect data length %d",
- peer->host, hdr->length);
+ flog_err(BGP_ERR_PKT_OPEN,
+ "%s AS4 capability has incorrect data length %d",
+ peer->host, hdr->length);
return 0;
}
&& !peer->afc_nego[AFI_IP6][SAFI_ENCAP]
&& !peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC]
&& !peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) {
- zlog_err(
- "%s [Error] Configured AFI/SAFIs do not "
- "overlap with received MP capabilities",
- peer->host);
+ flog_err(BGP_ERR_PKT_OPEN,
+ "%s [Error] Configured AFI/SAFIs do not "
+ "overlap with received MP capabilities",
+ peer->host);
if (error != error_data)
bgp_notify_send_with_data(
#include "plist.h"
#include "queue.h"
#include "filter.h"
+#include "lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_dump.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_packet.h"
/* Just in case we have a silly peer who sends AS4 capability set to 0
*/
if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV) && !as4) {
- zlog_err("%s bad OPEN, got AS4 capability, but AS4 set to 0",
- peer->host);
+ flog_err(BGP_ERR_PKT_OPEN,
+ "%s bad OPEN, got AS4 capability, but AS4 set to 0",
+ peer->host);
bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR,
BGP_NOTIFY_OPEN_BAD_PEER_AS,
notify_data_remote_as4, 4);
* BGP_AS_TRANS, for some unknown reason.
*/
if (as4 == BGP_AS_TRANS) {
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_OPEN,
"%s [AS4] NEW speaker using AS_TRANS for AS4, not allowed",
peer->host);
bgp_notify_send_with_data(peer, BGP_NOTIFY_OPEN_ERR,
if (CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)
&& as4 != remote_as) {
/* raise error, log this, close session */
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_OPEN,
"%s bad OPEN, got AS4 capability, but remote_as %u"
" mismatch with 16bit 'myasn' %u in open",
peer->host, as4, remote_as);
/* Get sockname. */
if ((ret = bgp_getsockname(peer)) < 0) {
- zlog_err("%s: bgp_getsockname() failed for peer: %s",
- __FUNCTION__, peer->host);
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: bgp_getsockname() failed for peer: %s",
+ __FUNCTION__, peer->host);
return BGP_Stop;
}
|| peer->afc_nego[AFI_IP][SAFI_ENCAP]) {
if (!peer->nexthop.v4.s_addr) {
#if defined(HAVE_CUMULUS)
- zlog_err(
+ flog_err(
+ BGP_ERR_SND_FAIL,
"%s: No local IPv4 addr resetting connection, fd %d",
peer->host, peer->fd);
bgp_notify_send(peer, BGP_NOTIFY_CEASE,
|| peer->afc_nego[AFI_IP6][SAFI_ENCAP]) {
if (IN6_IS_ADDR_UNSPECIFIED(&peer->nexthop.v6_global)) {
#if defined(HAVE_CUMULUS)
- zlog_err(
+ flog_err(
+ BGP_ERR_SND_FAIL,
"%s: No local IPv6 addr resetting connection, fd %d",
peer->host, peer->fd);
bgp_notify_send(peer, BGP_NOTIFY_CEASE,
/* Status must be Established. */
if (peer->status != Established) {
- zlog_err("%s [FSM] Update packet received under status %s",
- peer->host,
- lookup_msg(bgp_status_msg, peer->status, NULL));
+ flog_err(BGP_ERR_INVALID_STATUS,
+ "%s [FSM] Update packet received under status %s",
+ peer->host,
+ lookup_msg(bgp_status_msg, peer->status, NULL));
bgp_notify_send(peer, BGP_NOTIFY_FSM_ERR, 0);
return BGP_Stop;
}
Attribute Length + 23 exceeds the message Length), then the Error
Subcode is set to Malformed Attribute List. */
if (stream_pnt(s) + 2 > end) {
- zlog_err(
- "%s [Error] Update packet error"
- " (packet length is short for unfeasible length)",
- peer->host);
+ flog_err(BGP_ERR_UPDATE_RCV,
+ "%s [Error] Update packet error"
+ " (packet length is short for unfeasible length)",
+ peer->host);
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_ATTR);
return BGP_Stop;
/* Unfeasible Route Length check. */
if (stream_pnt(s) + withdraw_len > end) {
- zlog_err(
- "%s [Error] Update packet error"
- " (packet unfeasible length overflow %d)",
- peer->host, withdraw_len);
+ flog_err(BGP_ERR_UPDATE_RCV,
+ "%s [Error] Update packet error"
+ " (packet unfeasible length overflow %d)",
+ peer->host, withdraw_len);
bgp_notify_send(peer, BGP_NOTIFY_UPDATE_ERR,
BGP_NOTIFY_UPDATE_MAL_ATTR);
return BGP_Stop;
ret = bgp_dump_attr(&attr, peer->rcvd_attr_str, BUFSIZ);
if (attr_parse_ret == BGP_ATTR_PARSE_WITHDRAW)
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s rcvd UPDATE with errors in attr(s)!! Withdrawing route.",
peer->host);
}
if (nlri_ret < 0) {
- zlog_err("%s [Error] Error parsing NLRI", peer->host);
+ flog_err(BGP_ERR_UPDATE_RCV,
+ "%s [Error] Error parsing NLRI", peer->host);
if (peer->status == Established)
bgp_notify_send(
peer, BGP_NOTIFY_UPDATE_ERR,
/* If peer does not have the capability, send notification. */
if (!CHECK_FLAG(peer->cap, PEER_CAP_REFRESH_ADV)) {
- zlog_err("%s [Error] BGP route refresh is not enabled",
- peer->host);
+ flog_err(BGP_ERR_NO_CAP,
+ "%s [Error] BGP route refresh is not enabled",
+ peer->host);
bgp_notify_send(peer, BGP_NOTIFY_HEADER_ERR,
BGP_NOTIFY_HEADER_BAD_MESTYPE);
return BGP_Stop;
/* Status must be Established. */
if (peer->status != Established) {
- zlog_err(
+ flog_err(
+ BGP_ERR_INVALID_STATUS,
"%s [Error] Route refresh packet received under status %s",
peer->host,
lookup_msg(bgp_status_msg, peer->status, NULL));
/* If peer does not have the capability, send notification. */
if (!CHECK_FLAG(peer->cap, PEER_CAP_DYNAMIC_ADV)) {
- zlog_err("%s [Error] BGP dynamic capability is not enabled",
- peer->host);
+ flog_err(BGP_ERR_NO_CAP,
+ "%s [Error] BGP dynamic capability is not enabled",
+ peer->host);
bgp_notify_send(peer, BGP_NOTIFY_HEADER_ERR,
BGP_NOTIFY_HEADER_BAD_MESTYPE);
return BGP_Stop;
/* Status must be Established. */
if (peer->status != Established) {
- zlog_err(
+ flog_err(
+ BGP_ERR_NO_CAP,
"%s [Error] Dynamic capability packet received under status %s",
peer->host,
lookup_msg(bgp_status_msg, peer->status, NULL));
memory_order_relaxed);
mprc = bgp_open_receive(peer, size);
if (mprc == BGP_Stop)
- zlog_err(
+ flog_err(
+ BGP_ERR_PKT_OPEN,
"%s: BGP OPEN receipt failed for peer: %s",
__FUNCTION__, peer->host);
break;
peer->readtime = monotime(NULL);
mprc = bgp_update_receive(peer, size);
if (mprc == BGP_Stop)
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: BGP UPDATE receipt failed for peer: %s",
__FUNCTION__, peer->host);
break;
memory_order_relaxed);
mprc = bgp_notify_receive(peer, size);
if (mprc == BGP_Stop)
- zlog_err(
+ flog_err(
+ BGP_ERR_NOTIFY_RCV,
"%s: BGP NOTIFY receipt failed for peer: %s",
__FUNCTION__, peer->host);
break;
memory_order_relaxed);
mprc = bgp_keepalive_receive(peer, size);
if (mprc == BGP_Stop)
- zlog_err(
+ flog_err(
+ BGP_ERR_KEEP_RCV,
"%s: BGP KEEPALIVE receipt failed for peer: %s",
__FUNCTION__, peer->host);
break;
memory_order_relaxed);
mprc = bgp_route_refresh_receive(peer, size);
if (mprc == BGP_Stop)
- zlog_err(
+ flog_err(
+ BGP_ERR_RFSH_RCV,
"%s: BGP ROUTEREFRESH receipt failed for peer: %s",
__FUNCTION__, peer->host);
break;
memory_order_relaxed);
mprc = bgp_capability_receive(peer, size);
if (mprc == BGP_Stop)
- zlog_err(
+ flog_err(
+ BGP_ERR_CAP_RCV,
"%s: BGP CAPABILITY receipt failed for peer: %s",
__FUNCTION__, peer->host);
break;
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_mplsvpn.h"
#include "bgpd/bgp_flowspec_private.h"
+#include "bgpd/bgp_errors.h"
DEFINE_MTYPE_STATIC(BGPD, PBR_MATCH_ENTRY, "PBR match entry")
DEFINE_MTYPE_STATIC(BGPD, PBR_MATCH, "PBR match")
action_count++;
if (action_count > ACTIONS_MAX_NUM) {
if (BGP_DEBUG(pbr, PBR_ERROR))
- zlog_err("%s: flowspec actions exceeds limit (max %u)",
- __func__, action_count);
+ flog_err(BGP_ERR_FLOWSPEC_PACKET,
+ "%s: flowspec actions exceeds limit (max %u)",
+ __func__, action_count);
break;
}
api_action = &api->actions[action_count - 1];
if (!bgp_zebra_tm_chunk_obtained()) {
if (BGP_DEBUG(pbr, PBR_ERROR))
- zlog_err("%s: table chunk not obtained yet",
- __func__);
+ flog_err(BGP_ERR_TABLE_CHUNK,
+ "%s: table chunk not obtained yet",
+ __func__);
return;
}
if (bgp_pbr_build_and_validate_entry(p, info, &api) < 0) {
if (BGP_DEBUG(pbr, PBR_ERROR))
- zlog_err("%s: cancel updating entry %p in bgp pbr",
- __func__, info);
+ flog_err(BGP_ERR_FLOWSPEC_INSTALLATION,
+ "%s: cancel updating entry %p in bgp pbr",
+ __func__, info);
return;
}
bgp_pbr_handle_entry(bgp, info, &api, nlri_update);
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_aspath.h"
#include "bgpd/bgp_regex.h"
#include "bgpd/bgp_community.h"
}
if (newattr->sticky && !existattr->sticky) {
- zlog_warn(
- "%s: %s wins over %s due to sticky MAC flag",
- pfx_buf, new_buf, exist_buf);
+ if (debug)
+ zlog_debug(
+ "%s: %s wins over %s due to sticky MAC flag",
+ pfx_buf, new_buf, exist_buf);
return 1;
}
if (!newattr->sticky && existattr->sticky) {
- zlog_warn(
- "%s: %s loses to %s due to sticky MAC flag",
- pfx_buf, new_buf, exist_buf);
+ if (debug)
+ zlog_debug(
+ "%s: %s loses to %s due to sticky MAC flag",
+ pfx_buf, new_buf, exist_buf);
return 0;
}
}
/* Prefix length check. */
if (p.prefixlen > prefix_blen(&p) * 8) {
- zlog_err(
- "%s [Error] Update packet error (wrong perfix length %d for afi %u)",
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
+ "%s [Error] Update packet error (wrong prefix length %d for afi %u)",
peer->host, p.prefixlen, packet->afi);
return -1;
}
/* When packet overflow occur return immediately. */
if (pnt + psize > lim) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error (prefix length %d overflows packet)",
peer->host, p.prefixlen);
return -1;
/* Defensive coding, double-check the psize fits in a struct
* prefix */
if (psize > (ssize_t)sizeof(p.u)) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error (prefix length %d too large for prefix storage %zu)",
peer->host, p.prefixlen, sizeof(p.u));
return -1;
* be logged locally, and the prefix SHOULD be
* ignored.
*/
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: IPv4 unicast NLRI is multicast address %s, ignoring",
peer->host, inet_ntoa(p.u.prefix4));
continue;
if (IN6_IS_ADDR_LINKLOCAL(&p.u.prefix6)) {
char buf[BUFSIZ];
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: IPv6 unicast NLRI is link-local address %s, ignoring",
peer->host,
inet_ntop(AF_INET6, &p.u.prefix6, buf,
if (IN6_IS_ADDR_MULTICAST(&p.u.prefix6)) {
char buf[BUFSIZ];
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s: IPv6 unicast NLRI is multicast address %s, ignoring",
peer->host,
inet_ntop(AF_INET6, &p.u.prefix6, buf,
/* Packet length consistency check. */
if (pnt != lim) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDATE_RCV,
"%s [Error] Update packet error (prefix length mismatch with total length)",
peer->host);
return -1;
#include "bgpd/bgpd.h"
#include "bgpd/bgp_table.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_advertise.h"
#include "bgpd/bgp_packet.h"
if (!updgrp) {
updgrp = update_group_create(paf);
if (!updgrp) {
- zlog_err("couldn't create update group for peer %s",
- paf->peer->host);
+ flog_err(BGP_ERR_UPDGRP_CREATE,
+ "couldn't create update group for peer %s",
+ paf->peer->host);
return;
}
}
#include "bgpd/bgpd.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_packet.h"
* NLRI then
* return */
if (space_remaining < space_needed) {
- zlog_err(
+ flog_err(
+ BGP_ERR_UPDGRP_ATTR_LEN,
"u%" PRIu64 ":s%" PRIu64
" attributes too long, cannot send UPDATE",
subgrp->update_group->id, subgrp->id);
#include "bgpd/bgp_lcommunity.h"
#include "bgpd/bgp_damp.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_nexthop.h"
#include "bgpd/bgp_open.h"
vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
vty_out(vty, "if you are using this please let the developers know\n");
- zlog_warn("Deprecated option: `bgp multiple-instance` being used");
+ zlog_info("Deprecated option: `bgp multiple-instance` being used");
ret = bgp_option_unset(BGP_OPT_MULTIPLE_INSTANCE);
if (ret < 0) {
vty_out(vty, "%% There are more than two BGP instances\n");
if (argv_find(argv, argc, "cisco", &idx)) {
vty_out(vty, "This config option is deprecated, and is scheduled for removal.\n");
vty_out(vty, "if you are using this please let the developers know!\n");
- zlog_warn("Deprecated option: `bgp config-type cisco` being used");
+ zlog_info("Deprecated option: `bgp config-type cisco` being used");
bgp_option_set(BGP_OPT_CONFIG_CISCO);
} else
bgp_option_unset(BGP_OPT_CONFIG_CISCO);
for (ALL_LIST_ELEMENTS(bm->bgp, node, nnode, bgp)) {
if (use_json) {
if (!(json = json_object_new_object())) {
- zlog_err(
+ flog_err(
+ BGP_ERR_JSON_MEM_ERROR,
"Unable to allocate memory for JSON object");
vty_out(vty,
"{\"error\": {\"message:\": \"Unable to allocate memory for JSON object\"}}}\n");
#include "bgpd/bgp_zebra.h"
#include "bgpd/bgp_fsm.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_mpath.h"
#include "bgpd/bgp_nexthop.h"
#include "bgpd/bgp_nht.h"
ret = tm_table_manager_connect(zclient);
}
if (ret < 0) {
- zlog_warn("Error connecting to table manager!");
+ zlog_info("Error connecting to table manager!");
bgp_tm_status_connected = false;
} else {
if (!bgp_tm_status_connected)
return -1;
ret = tm_get_table_chunk(zclient, chunk_size, start, end);
if (ret < 0) {
- zlog_err("BGP: Error getting table chunk %u", chunk_size);
+ flog_err(BGP_ERR_TABLE_CHUNK,
+ "BGP: Error getting table chunk %u", chunk_size);
return -1;
}
zlog_info("BGP: Table Manager returns range from chunk %u is [%u %u]",
ipa_len = stream_getl(s);
if (ipa_len != 0 && ipa_len != IPV4_MAX_BYTELEN
&& ipa_len != IPV6_MAX_BYTELEN) {
- zlog_err("%u:Recv MACIP %s with invalid IP addr length %d",
- vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del",
- ipa_len);
+ flog_err(BGP_ERR_MACIP_LEN,
+ "%u:Recv MACIP %s with invalid IP addr length %d",
+ vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del",
+ ipa_len);
return -1;
}
STREAM_GETL(s, last);
if (zclient->redist_default != proto) {
- zlog_err("Got LM msg with wrong proto %u", proto);
+ flog_err(BGP_ERR_LM_ERROR, "Got LM msg with wrong proto %u",
+ proto);
return;
}
if (zclient->instance != instance) {
- zlog_err("Got LM msg with wrong instance %u", proto);
+ flog_err(BGP_ERR_LM_ERROR, "Got LM msg with wrong instance %u",
+ proto);
return;
}
first < MPLS_LABEL_UNRESERVED_MIN ||
last > MPLS_LABEL_UNRESERVED_MAX) {
- zlog_err("%s: Invalid Label chunk: %u - %u",
- __func__, first, last);
+ flog_err(BGP_ERR_LM_ERROR, "%s: Invalid Label chunk: %u - %u",
+ __func__, first, last);
return;
}
if (BGP_DEBUG(zebra, ZEBRA)) {
#include "bgpd/bgp_route.h"
#include "bgpd/bgp_dump.h"
#include "bgpd/bgp_debug.h"
+#include "bgpd/bgp_errors.h"
#include "bgpd/bgp_community.h"
#include "bgpd/bgp_attr.h"
#include "bgpd/bgp_regex.h"
/* Allocate new peer af */
af = XCALLOC(MTYPE_BGP_PEER_AF, sizeof(struct peer_af));
- if (af == NULL) {
- zlog_err("Could not create af structure for peer %s",
- peer->host);
- return NULL;
- }
-
peer->peer_af_array[afid] = af;
af->afi = afi;
af->safi = safi;
int active;
if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
- zlog_err("%s was called for peer-group %s", __func__,
- peer->host);
+ flog_err(BGP_ERR_PEER_GROUP, "%s was called for peer-group %s",
+ __func__, peer->host);
return 1;
}
safi_t safi)
{
if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) {
- zlog_err("%s was called for peer-group %s", __func__,
- peer->host);
+ flog_err(BGP_ERR_PEER_GROUP, "%s was called for peer-group %s",
+ __func__, peer->host);
return 1;
}
peer->afc[afi][safi] = 0;
if (peer_af_delete(peer, afi, safi) != 0) {
- zlog_err("couldn't delete af structure for peer %s",
- peer->host);
+ flog_err(BGP_ERR_PEER_DELETE,
+ "couldn't delete af structure for peer %s",
+ peer->host);
return 1;
}
group = peer->group;
if (peer_af_delete(peer, afi, safi) != 0) {
- zlog_err("couldn't delete af structure for peer %s",
- peer->host);
+ flog_err(BGP_ERR_PEER_DELETE,
+ "couldn't delete af structure for peer %s",
+ peer->host);
}
for (ALL_LIST_ELEMENTS(group->peer, node, nnode, tmp_peer)) {
if (flag & PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS) {
if (!bgp_flag_check(
bgp, BGP_FLAG_DETERMINISTIC_MED)) {
- zlog_warn(
+ zlog_info(
"%s: enabling bgp deterministic-med, this is required"
" for addpath-tx-bestpath-per-AS",
peer->host);
#include "lib/command.h"
#include "lib/stream.h"
#include "lib/ringbuf.h"
+#include "lib/lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
size);
break;
default:
- zlog_err("%s: Unknown group type=%d", __func__, type);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: Unknown group type=%d",
+ __func__, type);
/* should never happen */
assert("Unknown type" == NULL);
break;
criteria, search_cb);
break;
default:
- zlog_err("%s: Unknown group type=%d", __func__, type);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: Unknown group type=%d",
+ __func__, type);
/* should never happen */
assert("Unknown type" == NULL);
break;
#include "lib/skiplist.h"
#include "lib/thread.h"
#include "lib/stream.h"
+#include "lib/lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
break;
default:
- zlog_err("%s: bad afi %d", __func__, afi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi %d", __func__, afi);
return;
}
break;
default:
- zlog_err("%s: bad afi %d", __func__, afi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi %d", __func__, afi);
return;
}
default:
/* not expected */
- zlog_err("%s: bad safi %d", __func__, safi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad safi %d", __func__,
+ safi);
return rfapiBgpInfoFilteredImportBadSafi;
}
}
#include "lib/linklist.h"
#include "lib/plist.h"
#include "lib/routemap.h"
+#include "lib/lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
if (!afi) {
- zlog_err("%s: can't get afi of route node", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: can't get afi of route node", __func__);
return;
}
struct prefix ce_nexthop;
if (!afi) {
- zlog_err("%s: bad afi", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi", __func__);
return;
}
afi_t afi = family2afi(rn->p.family);
if (!afi) {
- zlog_err("%s: can't get afi of route node", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: can't get afi of route node", __func__);
return;
}
afi_t afi = family2afi(rn->p.family);
if (!afi) {
- zlog_err("%s: can't get afi route node", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: can't get afi route node",
+ __func__);
return;
}
afi_t afi = family2afi(rfd->vn_addr.addr_family);
if (!afi) {
- zlog_err("%s: can't get afi of nve vn addr", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: can't get afi of nve vn addr", __func__);
return;
}
if (afi == AFI_IP || afi == AFI_IP6) {
rt = import_table->imported_vpn[afi];
} else {
- zlog_err("%s: bad afi %d", __func__, afi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi %d",
+ __func__, afi);
return;
}
afi_t afi = family2afi(rfd->vn_addr.addr_family);
if (!afi) {
- zlog_err("%s: can't get afi of nve vn addr", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: can't get afi of nve vn addr", __func__);
return;
}
if (afi == AFI_IP || afi == AFI_IP6) {
rt = import_table->imported_vpn[afi];
} else {
- zlog_err("%s: bad afi %d", __func__, afi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi %d",
+ __func__, afi);
return;
}
if (afi == AFI_IP || afi == AFI_IP6) {
rt = import_table->imported_vpn[afi];
} else {
- zlog_err("%s: bad afi %d", __func__, afi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi %d", __func__, afi);
return;
}
struct attr *iattr;
if (!afi) {
- zlog_err("%s: can't get afi of route node", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: can't get afi of route node", __func__);
return;
}
struct vnc_export_info *eti;
if (!afi) {
- zlog_err("%s: can't get afi route node", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: can't get afi route node",
+ __func__);
return;
}
#include "lib/linklist.h"
#include "lib/plist.h"
#include "lib/routemap.h"
+#include "lib/lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
*/
if (!afi) {
- zlog_err("%s: can't get afi of prefix", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: can't get afi of prefix",
+ __func__);
return;
}
}
if (!afi) {
- zlog_err("%s: can't get afi of prefix", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: can't get afi of prefix",
+ __func__);
return;
}
assert(rfg);
if (!afi) {
- zlog_err("%s: can't get afi of prefix", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: can't get afi of prefix",
+ __func__);
return;
}
VNC_RHNCK(enter);
if (!afi) {
- zlog_err("%s: can't get afi of prefix", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: can't get afi of prefix",
+ __func__);
return;
}
#include "lib/stream.h"
#include "lib/ringbuf.h"
#include "lib/memory.h"
+#include "lib/lib_errors.h"
#include "bgpd/bgpd.h"
#include "bgpd/bgp_ecommunity.h"
return;
if (rn->p.family != AF_INET && rn->p.family != AF_INET6) {
- zlog_err("%s: invalid route node addr family", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: invalid route node addr family", __func__);
return;
}
return;
if (afi != AFI_IP && afi != AFI_IP6) {
- zlog_err("%s: invalid vn addr family", __func__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: invalid vn addr family",
+ __func__);
return;
}
if (afi == AFI_IP || afi == AFI_IP6) {
rt = import_table->imported_vpn[afi];
} else {
- zlog_err("%s: bad afi %d", __func__, afi);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: bad afi %d", __func__, afi);
return;
}
if (!family) {
- zlog_err("%s: computed bad family: %d", __func__, family);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: computed bad family: %d",
+ __func__, family);
return;
}
user/vtysh.rst \
user/zebra.rst \
user/bfd.rst \
- user/flowspec.rst \
+ user/flowspec.rst \
mpls/ChangeLog.opaque.txt \
mpls/ospfd.conf \
mpls/cli_summary.txt \
--- /dev/null
+/*
+ * EIGRP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "eigrp_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_eigrp_err[] = {
+ {
+ .code = EIGRP_ERR_PACKET,
+ .title = "EIGRP Packet Error",
+ .description = "EIGRP has a packet that does not correctly decode or encode",
+ .suggestion = "Gather log files from both sides of the neighbor relationship and open an issue"
+ },
+ {
+ .code = EIGRP_ERR_CONFIG,
+ .title = "EIGRP Configuration Error",
+ .description = "EIGRP has detected a configuration error",
+ .suggestion = "Correct the configuration issue, if it still persists open an Issue"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void eigrp_error_init(void)
+{
+ log_ref_add(ferr_eigrp_err);
+}
--- /dev/null
+/*
+ * EIGRP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __EIGRP_ERRORS_H__
+#define __EIGRP_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum eigrp_log_refs {
+ EIGRP_ERR_PACKET = EIGRP_FERR_START,
+ EIGRP_ERR_CONFIG,
+};
+
+extern void eigrp_error_init(void);
+
+#endif
#include "eigrpd/eigrp_vty.h"
#include "eigrpd/eigrp_dump.h"
#include "eigrpd/eigrp_macros.h"
+#include "eigrpd/eigrp_errors.h"
/* Packet Type String. */
static const struct message eigrp_general_tlv_type_str[] = {
ret = sscanf(ver_string, "%" SCNu32 ".%" SCNu32, &FRR_MAJOR,
&FRR_MINOR);
if (ret != 2)
- zlog_err("Did not Properly parse %s, please fix VERSION string",
- VERSION);
+ flog_err(EIGRP_ERR_PACKET,
+ "Did not Properly parse %s, please fix VERSION string",
+ VERSION);
}
/**
#include "eigrpd/eigrp_network.h"
#include "eigrpd/eigrp_snmp.h"
#include "eigrpd/eigrp_filter.h"
+#include "eigrpd/eigrp_errors.h"
//#include "eigrpd/eigrp_routemap.h"
/* eigprd privileges */
eigrp_om->master = frr_init();
master = eigrp_om->master;
+ eigrp_error_init();
vrf_init(NULL, NULL, NULL, NULL);
/*EIGRPd init*/
#include "eigrpd/eigrp_network.h"
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_memory.h"
+#include "eigrpd/eigrp_errors.h"
struct eigrp_neighbor *eigrp_nbr_new(struct eigrp_interface *ei)
{
void eigrp_nbr_hard_restart(struct eigrp_neighbor *nbr, struct vty *vty)
{
if (nbr == NULL) {
- zlog_err("Nbr Hard restart: Neighbor not specified.");
+ flog_err(EIGRP_ERR_CONFIG,
+ "Nbr Hard restart: Neighbor not specified.");
return;
}
#include "privs.h"
#include "table.h"
#include "vty.h"
+#include "lib_errors.h"
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrpd.h"
int hincl = 1;
#endif
- if (eigrpd_privs.change(ZPRIVS_RAISE))
- zlog_err("eigrp_sock_init: could not raise privs, %s",
- safe_strerror(errno));
-
- eigrp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_EIGRPIGP);
- if (eigrp_sock < 0) {
- int save_errno = errno;
- if (eigrpd_privs.change(ZPRIVS_LOWER))
- zlog_err("eigrp_sock_init: could not lower privs, %s",
+ frr_elevate_privs(&eigrpd_privs) {
+ eigrp_sock = socket(AF_INET, SOCK_RAW, IPPROTO_EIGRPIGP);
+ if (eigrp_sock < 0) {
+ zlog_err("eigrp_read_sock_init: socket: %s",
safe_strerror(errno));
- zlog_err("eigrp_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(eigrp_sock, IPPROTO_IP, IP_HDRINCL, &hincl,
- sizeof(hincl));
- 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_warn("Can't set IP_HDRINCL option for fd %d: %s",
- eigrp_sock, safe_strerror(save_errno));
- }
+ /* we will include IP header with packet */
+ ret = setsockopt(eigrp_sock, IPPROTO_IP, IP_HDRINCL, &hincl,
+ sizeof(hincl));
+ if (ret < 0) {
+ zlog_warn("Can't set IP_HDRINCL option for fd %d: %s",
+ eigrp_sock, safe_strerror(errno));
+ }
#elif defined(IPTOS_PREC_INTERNETCONTROL)
#warning "IP_HDRINCL not available on this system"
#warning "using IPTOS_PREC_INTERNETCONTROL"
- ret = setsockopt_ipv4_tos(eigrp_sock, IPTOS_PREC_INTERNETCONTROL);
- 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_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. */
- return ret;
- }
+ ret = setsockopt_ipv4_tos(eigrp_sock,
+ IPTOS_PREC_INTERNETCONTROL);
+ if (ret < 0) {
+ zlog_warn("can't set sockopt IP_TOS %d to socket %d: %s",
+ tos, eigrp_sock, safe_strerror(errno));
+ close(eigrp_sock); /* Prevent sd leak. */
+ return ret;
+ }
#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, eigrp_sock, 1);
-
- if (ret < 0)
- 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));
+ ret = setsockopt_ifindex(AF_INET, eigrp_sock, 1);
+ if (ret < 0)
+ zlog_warn("Can't set pktinfo option for fd %d",
+ eigrp_sock);
}
return eigrp_sock;
/* Check if any work has to be done at all. */
if (eigrp->maxsndbuflen >= buflen)
return;
- if (eigrpd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs, %s", __func__,
- safe_strerror(errno));
+ frr_elevate_privs(&eigrpd_privs) {
/* 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
* may allocate more buffer space, than requested, this isn't
* a error.
*/
- setsockopt_so_sendbuf(eigrp->fd, buflen);
- newbuflen = getsockopt_so_sendbuf(eigrp->fd);
- if (newbuflen < 0 || newbuflen < (int)buflen)
- zlog_warn("%s: tried to set SO_SNDBUF to %u, but got %d",
- __func__, buflen, newbuflen);
- if (newbuflen >= 0)
- eigrp->maxsndbuflen = (unsigned int)newbuflen;
- 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));
+ setsockopt_so_sendbuf(eigrp->fd, buflen);
+ newbuflen = getsockopt_so_sendbuf(eigrp->fd);
+ if (newbuflen < 0 || newbuflen < (int)buflen)
+ zlog_warn("%s: tried to set SO_SNDBUF to %u, but got %d",
+ __func__, buflen, newbuflen);
+ if (newbuflen >= 0)
+ eigrp->maxsndbuflen = (unsigned int)newbuflen;
+ else
+ zlog_warn("%s: failed to get SO_SNDBUF", __func__);
+ }
}
int eigrp_if_ipmulticast(struct eigrp *top, struct prefix *p,
#include "checksum.h"
#include "md5.h"
#include "sha256.h"
+#include "lib_errors.h"
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrpd.h"
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_fsm.h"
#include "eigrpd/eigrp_memory.h"
+#include "eigrpd/eigrp_errors.h"
/* Packet Type String. */
const struct message eigrp_packet_type_str[] = {
/* Get one packet from queue. */
ep = eigrp_fifo_next(ei->obuf);
if (!ep) {
- zlog_err("%s: Interface %s no packet on queue?",
- __PRETTY_FUNCTION__, ei->ifp->name);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: Interface %s no packet on queue?",
+ __PRETTY_FUNCTION__, ei->ifp->name);
goto out;
}
if (ep->length < EIGRP_HEADER_LEN) {
- zlog_err("%s: Packet just has a header?", __PRETTY_FUNCTION__);
+ flog_err(EIGRP_ERR_PACKET,
+ "%s: Packet just has a header?", __PRETTY_FUNCTION__);
eigrp_header_dump((struct eigrp_header *)ep->s->data);
eigrp_packet_delete(ei);
goto out;
stream_putw(s, length);
break;
default:
- zlog_err("%s: Unexpected prefix length: %d",
- __PRETTY_FUNCTION__, pe->destination->prefixlen);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: Unexpected prefix length: %d",
+ __PRETTY_FUNCTION__, pe->destination->prefixlen);
return 0;
}
stream_putl(s, 0x00000000);
#include "eigrpd/eigrp_topology.h"
#include "eigrpd/eigrp_fsm.h"
#include "eigrpd/eigrp_memory.h"
+#include "eigrpd/eigrp_errors.h"
void eigrp_send_reply(struct eigrp_neighbor *nbr, struct eigrp_prefix_entry *pe)
{
if (!dest) {
char buf[PREFIX_STRLEN];
- zlog_err(
- "%s: Received prefix %s which we do not know about",
- __PRETTY_FUNCTION__,
- prefix2str(&dest_addr, buf, sizeof(buf)));
+ flog_err(EIGRP_ERR_PACKET,
+ "%s: Received prefix %s which we do not know about",
+ __PRETTY_FUNCTION__,
+ prefix2str(&dest_addr, buf, sizeof(buf)));
eigrp_IPv4_InternalTLV_free(tlv);
continue;
}
#include "log.h"
#include "linklist.h"
#include "vty.h"
+#include "lib_errors.h"
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrpd.h"
}
break;
default:
- zlog_err("%s: Please implement handler", __PRETTY_FUNCTION__);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: Please implement handler",
+ __PRETTY_FUNCTION__);
break;
}
distance_done:
#include "sockopt.h"
#include "keychain.h"
#include "libfrr.h"
+#include "lib_errors.h"
#include "eigrpd/eigrp_structs.h"
#include "eigrpd/eigrpd.h"
eigrp->networks = eigrp_topology_new();
if ((eigrp_socket = eigrp_sock_init()) < 0) {
- zlog_err(
- "eigrp_new: fatal error: eigrp_sock_init was unable to open "
- "a socket");
+ flog_err_sys(
+ LIB_ERR_SOCKET,
+ "eigrp_new: fatal error: eigrp_sock_init was unable to open a socket");
exit(1);
}
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);
eigrpd_libeigrp_a_SOURCES = \
eigrpd/eigrp_dump.c \
+ eigrpd/eigrp_errors.c \
eigrpd/eigrp_filter.c \
eigrpd/eigrp_fsm.c \
eigrpd/eigrp_hello.c \
noinst_HEADERS += \
eigrpd/eigrp_const.h \
+ eigrpd/eigrp_errors.h \
eigrpd/eigrp_filter.h \
eigrpd/eigrp_fsm.h \
eigrpd/eigrp_interface.h \
#include "network.h"
#include "stream.h"
#include "if.h"
+#include "lib_errors.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
{
int retval = ISIS_OK;
- if (isisd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs, %s", __func__,
- safe_strerror(errno));
+ frr_elevate_privs(&isisd_privs) {
- retval = open_bpf_dev(circuit);
+ retval = open_bpf_dev(circuit);
- if (retval != ISIS_OK) {
- zlog_warn("%s: could not initialize the socket", __func__);
- goto end;
- }
+ if (retval != ISIS_OK) {
+ zlog_warn("%s: could not initialize the socket",
+ __func__);
+ break;
+ }
- if (if_is_broadcast(circuit->interface)) {
- circuit->tx = isis_send_pdu_bcast;
- circuit->rx = isis_recv_pdu_bcast;
- } else {
- zlog_warn("isis_sock_init(): unknown circuit type");
- retval = ISIS_WARNING;
- goto end;
+ if (if_is_broadcast(circuit->interface)) {
+ circuit->tx = isis_send_pdu_bcast;
+ circuit->rx = isis_recv_pdu_bcast;
+ } else {
+ zlog_warn("isis_sock_init(): unknown circuit type");
+ retval = ISIS_WARNING;
+ break;
+ }
}
-end:
- if (isisd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs, %s", __func__,
- safe_strerror(errno));
-
return retval;
}
#include "isisd/isis_events.h"
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
+#include "isisd/isis_errors.h"
DEFINE_QOBJ_TYPE(isis_circuit)
return ISIS_OK;
if (circuit->area->lsp_mtu > isis_circuit_pdu_size(circuit)) {
- zlog_err(
+ flog_err(
+ ISIS_ERR_CONFIG,
"Interface MTU %zu on %s is too low to support area lsp mtu %u!",
isis_circuit_pdu_size(circuit),
circuit->interface->name, circuit->area->lsp_mtu);
if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
circuit->circuit_id = isis_circuit_id_gen(isis, circuit->interface);
if (!circuit->circuit_id) {
- zlog_err("There are already 255 broadcast circuits active!");
+ flog_err(
+ ISIS_ERR_CONFIG,
+ "There are already 255 broadcast circuits active!");
return ISIS_ERROR;
}
#include "isisd/isisd.h"
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
+#include "isisd/isis_errors.h"
extern struct isis *isis;
case IF_UP_FROM_Z:
isis_circuit_if_add(circuit, (struct interface *)arg);
if (isis_circuit_up(circuit) != ISIS_OK) {
- zlog_err(
+ flog_err(
+ ISIS_ERR_CONFIG,
"Could not bring up %s because of invalid config.",
circuit->interface->name);
- zlog_err(
+ flog_err(
+ ISIS_ERR_CONFIG,
"Clearing config for %s. Please re-examine it.",
circuit->interface->name);
if (circuit->ip_router) {
#include "network.h"
#include "stream.h"
#include "if.h"
+#include "lib_errors.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
{
int retval = ISIS_OK;
- if (isisd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs, %s", __func__,
- safe_strerror(errno));
+ frr_elevate_privs(&isisd_privs) {
- retval = open_dlpi_dev(circuit);
+ retval = open_dlpi_dev(circuit);
- if (retval != ISIS_OK) {
- zlog_warn("%s: could not initialize the socket", __func__);
- goto end;
- }
+ if (retval != ISIS_OK) {
+ zlog_warn("%s: could not initialize the socket",
+ __func__);
+ break;
+ }
- if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
- circuit->tx = isis_send_pdu_bcast;
- circuit->rx = isis_recv_pdu_bcast;
- } else {
- zlog_warn("isis_sock_init(): unknown circuit type");
- retval = ISIS_WARNING;
- goto end;
+ if (circuit->circ_type == CIRCUIT_T_BROADCAST) {
+ circuit->tx = isis_send_pdu_bcast;
+ circuit->rx = isis_recv_pdu_bcast;
+ } else {
+ zlog_warn("isis_sock_init(): unknown circuit type");
+ retval = ISIS_WARNING;
+ break;
+ }
}
-end:
- if (isisd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs, %s", __func__,
- safe_strerror(errno));
-
return retval;
}
--- /dev/null
+/*
+ * ISIS-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "isis_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_isis_err[] = {
+ {
+ .code = ISIS_ERR_PACKET,
+ .title = "ISIS Packet Error",
+ .description = "Isis has detected an error with a packet from a peer",
+ .suggestion = "Gather log information and open an issue then restart FRR"
+ },
+ {
+ .code = ISIS_ERR_CONFIG,
+ .title = "ISIS Configuration Error",
+ .description = "Isis has detected an error within configuration for the router",
+ .suggestion = "Ensure configuration is correct"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void isis_error_init(void)
+{
+ log_ref_add(ferr_isis_err);
+}
--- /dev/null
+/*
+ * ISIS-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __ISIS_ERRORS_H__
+#define __ISIS_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum isis_log_refs {
+ ISIS_ERR_PACKET = ISIS_FERR_START,
+ ISIS_ERR_CONFIG,
+};
+
+extern void isis_error_init(void);
+
+#endif
#include "isisd/isis_csm.h"
#include "isisd/isis_events.h"
#include "isisd/isis_spf.h"
+#include "isisd/isis_errors.h"
/* debug isis-spf spf-events
4w4d: ISIS-Spf (tlt): L2 SPF needed, new adjacency, from 0x609229F4
return; /* No change */
if (!(newtype & circuit->area->is_type)) {
- zlog_err(
- "ISIS-Evt (%s) circuit type change - invalid level %s because"
- " area is %s",
+ flog_err(
+ ISIS_ERR_CONFIG,
+ "ISIS-Evt (%s) circuit type change - invalid level %s because area is %s",
circuit->area->area_tag, circuit_t2string(newtype),
circuit_t2string(circuit->area->is_type));
return;
#include "md5.h"
#include "table.h"
#include "srcdest_table.h"
+#include "lib_errors.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
struct isis_area *area, int level, bool confusion)
{
if (lsp->own_lsp) {
- zlog_err(
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
"ISIS-Upd (%s): BUG updating LSP %s still marked as own LSP",
area->area_tag, rawlspid_print(lsp->hdr.lsp_id));
lsp_clear_data(lsp);
lsp = lsp_search(lspid, lspdb);
if (!lsp) {
- zlog_err("ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
- area->area_tag, level);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "ISIS-Upd (%s): lsp_regenerate: no L%d LSP found!",
+ area->area_tag, level);
return ISIS_ERROR;
}
lsp = lsp_search(lsp_id, lspdb);
if (!lsp) {
- zlog_err("lsp_regenerate_pseudo: no l%d LSP %s found!", level,
- rawlspid_print(lsp_id));
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "lsp_regenerate_pseudo: no l%d LSP %s found!", level,
+ rawlspid_print(lsp_id));
return ISIS_ERROR;
}
#include "isisd/isis_routemap.h"
#include "isisd/isis_zebra.h"
#include "isisd/isis_te.h"
+#include "isisd/isis_errors.h"
/* Default configuration file name */
#define ISISD_DEFAULT_CONFIG "isisd.conf"
void sighup(void)
{
- zlog_err("SIGHUP/reload is not implemented for isisd");
+ zlog_notice("SIGHUP/reload is not implemented for isisd");
return;
}
/*
* initializations
*/
+ isis_error_init();
access_list_init();
vrf_init(NULL, NULL, NULL, NULL);
prefix_list_init();
#include "if.h"
#include "checksum.h"
#include "md5.h"
+#include "lib_errors.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
#include "isisd/isis_te.h"
#include "isisd/isis_mt.h"
#include "isisd/isis_tlvs.h"
+#include "isisd/isis_errors.h"
static int ack_lsp(struct isis_lsp_hdr *hdr, struct isis_circuit *circuit,
int level)
retval = circuit->tx(circuit, level);
if (retval != ISIS_OK)
- zlog_err("ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
- circuit->area->area_tag, level,
- circuit->interface->name);
+ flog_err(ISIS_ERR_PACKET,
+ "ISIS-Upd (%s): Send L%d LSP PSNP on %s failed",
+ circuit->area->area_tag, level,
+ circuit->interface->name);
return retval;
}
}
if (!p2p_hello && !(level & iih.circ_type)) {
- zlog_err("Level %d LAN Hello with Circuit Type %d", level,
- iih.circ_type);
+ flog_err(ISIS_ERR_PACKET,
+ "Level %d LAN Hello with Circuit Type %d", level,
+ iih.circ_type);
return ISIS_ERROR;
}
/* Verify that at least the 8 bytes fixed header have been received */
if (stream_get_endp(circuit->rcv_stream) < ISIS_FIXED_HDR_LEN) {
- zlog_err("PDU is too short to be IS-IS.");
+ flog_err(ISIS_ERR_PACKET, "PDU is too short to be IS-IS.");
return ISIS_ERROR;
}
uint8_t max_area_addrs = stream_getc(circuit->rcv_stream);
if (idrp == ISO9542_ESIS) {
- zlog_err("No support for ES-IS packet IDRP=%" PRIx8, idrp);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "No support for ES-IS packet IDRP=%" PRIx8, idrp);
return ISIS_ERROR;
}
if (idrp != ISO10589_ISIS) {
- zlog_err("Not an IS-IS packet IDRP=%" PRIx8, idrp);
+ flog_err(ISIS_ERR_PACKET, "Not an IS-IS packet IDRP=%" PRIx8,
+ idrp);
return ISIS_ERROR;
}
}
if (id_len != 0 && id_len != ISIS_SYS_ID_LEN) {
- zlog_err(
+ flog_err(
+ ISIS_ERR_PACKET,
"IDFieldLengthMismatch: ID Length field in a received PDU %" PRIu8
", while the parameter for this IS is %u",
id_len, ISIS_SYS_ID_LEN);
}
if (length != expected_length) {
- zlog_err("Exepected fixed header length = %" PRIu8
- " but got %" PRIu8,
- expected_length, length);
+ flog_err(ISIS_ERR_PACKET,
+ "Exepected fixed header length = %" PRIu8
+ " but got %" PRIu8,
+ expected_length, length);
return ISIS_ERROR;
}
if (stream_get_endp(circuit->rcv_stream) < length) {
- zlog_err(
+ flog_err(
+ ISIS_ERR_PACKET,
"PDU is too short to contain fixed header of given PDU type.");
return ISIS_ERROR;
}
/* either 3 or 0 */
if (max_area_addrs != 0 && max_area_addrs != isis->max_area_addrs) {
- zlog_err(
+ flog_err(
+ ISIS_ERR_PACKET,
"maximumAreaAddressesMismatch: maximumAreaAdresses in a received PDU %" PRIu8
" while the parameter for this IS is %u",
max_area_addrs, isis->max_area_addrs);
retval = circuit->tx(circuit, level);
if (retval != ISIS_OK)
- zlog_err("ISIS-Adj (%s): Send L%d IIH on %s failed",
- circuit->area->area_tag, level,
- circuit->interface->name);
+ flog_err(ISIS_ERR_PACKET,
+ "ISIS-Adj (%s): Send L%d IIH on %s failed",
+ circuit->area->area_tag, level,
+ circuit->interface->name);
return retval;
}
int retval = circuit->tx(circuit, level);
if (retval != ISIS_OK) {
- zlog_err("ISIS-Snp (%s): Send L%d CSNP on %s failed",
- circuit->area->area_tag, level,
- circuit->interface->name);
+ flog_err(ISIS_ERR_PACKET,
+ "ISIS-Snp (%s): Send L%d CSNP on %s failed",
+ circuit->area->area_tag, level,
+ circuit->interface->name);
isis_free_tlvs(tlvs);
return retval;
}
int retval = circuit->tx(circuit, level);
if (retval != ISIS_OK) {
- zlog_err("ISIS-Snp (%s): Send L%d PSNP on %s failed",
- circuit->area->area_tag, level,
- circuit->interface->name);
+ flog_err(ISIS_ERR_PACKET,
+ "ISIS-Snp (%s): Send L%d PSNP on %s failed",
+ circuit->area->area_tag, level,
+ circuit->interface->name);
isis_free_tlvs(tlvs);
return retval;
}
* than
* the circuit's MTU. So handle and log this case here. */
if (stream_get_endp(lsp->pdu) > stream_get_size(circuit->snd_stream)) {
- zlog_err(
+ flog_err(
+ ISIS_ERR_PACKET,
"ISIS-Upd (%s): Can't send L%d LSP %s, seq 0x%08" PRIx32
", cksum 0x%04" PRIx16 ", lifetime %" PRIu16
"s on %s. LSP Size is %zu while interface stream size is %zu.",
clear_srm = 0;
retval = circuit->tx(circuit, lsp->level);
if (retval != ISIS_OK) {
- zlog_err("ISIS-Upd (%s): Send L%d LSP on %s failed %s",
- circuit->area->area_tag, lsp->level,
- circuit->interface->name,
- (retval == ISIS_WARNING) ? "temporarily"
- : "permanently");
+ flog_err(ISIS_ERR_PACKET,
+ "ISIS-Upd (%s): Send L%d LSP on %s failed %s",
+ circuit->area->area_tag, lsp->level,
+ circuit->interface->name,
+ (retval == ISIS_WARNING) ? "temporarily"
+ : "permanently");
}
out:
#include "network.h"
#include "stream.h"
#include "if.h"
+#include "lib_errors.h"
#include "isisd/dict.h"
#include "isisd/isis_constants.h"
{
int retval = ISIS_OK;
- if (isisd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs, %s", __func__,
- safe_strerror(errno));
+ frr_elevate_privs(&isisd_privs) {
- retval = open_packet_socket(circuit);
+ retval = open_packet_socket(circuit);
- if (retval != ISIS_OK) {
- zlog_warn("%s: could not initialize the socket", __func__);
- goto end;
- }
+ if (retval != ISIS_OK) {
+ zlog_warn("%s: could not initialize the socket",
+ __func__);
+ break;
+ }
/* Assign Rx and Tx callbacks are based on real if type */
- if (if_is_broadcast(circuit->interface)) {
- circuit->tx = isis_send_pdu_bcast;
- circuit->rx = isis_recv_pdu_bcast;
- } else if (if_is_pointopoint(circuit->interface)) {
- circuit->tx = isis_send_pdu_p2p;
- circuit->rx = isis_recv_pdu_p2p;
- } else {
- zlog_warn("isis_sock_init(): unknown circuit type");
- retval = ISIS_WARNING;
- goto end;
+ if (if_is_broadcast(circuit->interface)) {
+ circuit->tx = isis_send_pdu_bcast;
+ circuit->rx = isis_recv_pdu_bcast;
+ } else if (if_is_pointopoint(circuit->interface)) {
+ circuit->tx = isis_send_pdu_p2p;
+ circuit->rx = isis_recv_pdu_p2p;
+ } else {
+ zlog_warn("isis_sock_init(): unknown circuit type");
+ retval = ISIS_WARNING;
+ break;
+ }
}
-end:
- if (isisd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs, %s", __func__,
- safe_strerror(errno));
-
return retval;
}
#include "jhash.h"
#include "skiplist.h"
#include "srcdest_table.h"
+#include "lib_errors.h"
#include "isis_constants.h"
#include "isis_common.h"
} else if (VTYPE_IP(vtype)) {
memcpy(&vertex->N.ip, &n->ip, sizeof(n->ip));
} else {
- zlog_err("WTF!");
+ flog_err(LIB_ERR_DEVELOPMENT, "Unknown Vertex Type");
}
}
isisd/isis_csm.c \
isisd/isis_dr.c \
isisd/isis_dynhn.c \
+ isisd/isis_errors.c \
isisd/isis_events.c \
isisd/isis_flags.c \
isisd/isis_lsp.c \
isisd/isis_csm.h \
isisd/isis_dr.h \
isisd/isis_dynhn.h \
+ isisd/isis_errors.h \
isisd/isis_events.h \
isisd/isis_flags.h \
isisd/isis_lsp.h \
#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);
nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
if (nullfd == -1) {
- zlog_err("%s: failed to open /dev/null: %s", __func__,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: failed to open /dev/null: %s", __func__,
+ safe_strerror(errno));
} else {
dup2(nullfd, 0);
dup2(nullfd, 1);
#ifdef __OpenBSD__
int opt;
#endif
- int save_errno;
/* create socket */
switch (type) {
sock_set_bindany(fd, 1);
break;
}
- if (ldpd_privs.change(ZPRIVS_RAISE))
- log_warn("%s: could not raise privs", __func__);
- if (sock_set_reuse(fd, 1) == -1) {
- if (ldpd_privs.change(ZPRIVS_LOWER))
- log_warn("%s: could not lower privs", __func__);
- close(fd);
- return (-1);
- }
- if (bind(fd, &local_su.sa, sockaddr_len(&local_su.sa)) == -1) {
- save_errno = errno;
- if (ldpd_privs.change(ZPRIVS_LOWER))
- log_warn("%s: could not lower privs", __func__);
- log_warnx("%s: error binding socket: %s", __func__,
- safe_strerror(save_errno));
- close(fd);
- return (-1);
+ frr_elevate_privs(&ldpd_privs) {
+ if (sock_set_reuse(fd, 1) == -1) {
+ close(fd);
+ return (-1);
+ }
+ if (bind(fd, &local_su.sa, sockaddr_len(&local_su.sa)) == -1) {
+ log_warnx("%s: error binding socket: %s", __func__,
+ safe_strerror(errno));
+ close(fd);
+ return (-1);
+ }
}
- if (ldpd_privs.change(ZPRIVS_LOWER))
- log_warn("%s: could not lower privs", __func__);
/* set options */
switch (af) {
sock_set_bindany(int fd, int enable)
{
#ifdef HAVE_SO_BINDANY
- if (ldpd_privs.change(ZPRIVS_RAISE))
- log_warn("%s: could not raise privs", __func__);
- if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable,
- sizeof(int)) < 0) {
- if (ldpd_privs.change(ZPRIVS_LOWER))
- log_warn("%s: could not lower privs", __func__);
- log_warn("%s: error setting SO_BINDANY", __func__);
- return (-1);
+ frr_elevate_privs(&ldpd_privs) {
+ if (setsockopt(fd, SOL_SOCKET, SO_BINDANY, &enable,
+ sizeof(int)) < 0) {
+ log_warn("%s: error setting SO_BINDANY", __func__);
+ return (-1);
+ }
}
- if (ldpd_privs.change(ZPRIVS_LOWER))
- log_warn("%s: could not lower privs", __func__);
return (0);
#elif defined(HAVE_IP_FREEBIND)
if (setsockopt(fd, IPPROTO_IP, IP_FREEBIND, &enable, sizeof(int)) < 0) {
#if HAVE_DECL_TCP_MD5SIG
addr2sa(af, addr, 0, &su);
- if (ldpe_privs.change(ZPRIVS_RAISE)) {
- log_warn("%s: could not raise privs", __func__);
- return (-1);
+ frr_elevate_privs(&ldpe_privs) {
+ ret = sockopt_tcp_signature(fd, &su, password);
+ save_errno = errno;
}
- ret = sockopt_tcp_signature(fd, &su, password);
- save_errno = errno;
- if (ldpe_privs.change(ZPRIVS_LOWER))
- log_warn("%s: could not lower privs", __func__);
#endif /* HAVE_TCP_MD5SIG */
if (ret < 0)
log_warnx("%s: can't set TCP_MD5SIG option on fd %d: %s",
#include "memory.h"
#include "linklist.h"
#include "version.h"
+#include "lib_errors.h"
static int agentx_enabled = 0;
msg[strlen(msg) - 1] = '\0';
switch (slm->priority) {
case LOG_EMERG:
- zlog_err("snmp[emerg]: %s", msg ? msg : slm->msg);
+ flog_err(LIB_ERR_SNMP,
+ "snmp[emerg]: %s", msg ? msg : slm->msg);
break;
case LOG_ALERT:
- zlog_err("snmp[alert]: %s", msg ? msg : slm->msg);
+ flog_err(LIB_ERR_SNMP,
+ "snmp[alert]: %s", msg ? msg : slm->msg);
break;
case LOG_CRIT:
- zlog_err("snmp[crit]: %s", msg ? msg : slm->msg);
+ flog_err(LIB_ERR_SNMP,
+ "snmp[crit]: %s", msg ? msg : slm->msg);
break;
case LOG_ERR:
- zlog_err("snmp[err]: %s", msg ? msg : slm->msg);
+ flog_err(LIB_ERR_SNMP,
+ "snmp[err]: %s", msg ? msg : slm->msg);
break;
case LOG_WARNING:
zlog_warn("snmp[warning]: %s", msg ? msg : slm->msg);
#define _ZEBRA_BFD_H
#include "lib/json.h"
+#include "lib/zclient.h"
#define BFD_DEF_MIN_RX 300
#define BFD_MIN_MIN_RX 50
#include "buffer.h"
#include "log.h"
#include "network.h"
+#include "lib_errors.h"
+
#include <stddef.h>
DEFINE_MTYPE_STATIC(LIB, BUFFER, "Buffer")
iov_alloc * sizeof(*iov));
} else {
/* This should absolutely never occur. */
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"%s: corruption detected: iov_small overflowed; "
"head %p, tail %p, head->next %p",
__func__, (void *)b->head,
while (written > 0) {
struct buffer_data *d;
if (!(d = b->head)) {
- zlog_err(
- "%s: corruption detected: buffer queue empty, "
- "but written is %lu",
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
+ "%s: corruption detected: buffer queue empty, but written is %lu",
__func__, (unsigned long)written);
break;
}
#include "libfrr.h"
#include "jhash.h"
#include "hook.h"
+#include "lib_errors.h"
DEFINE_MTYPE(LIB, HOST, "Host config")
DEFINE_MTYPE(LIB, COMPLETION, "Completion item")
cwd[MAXPATHLEN] = '\0';
if (getcwd(cwd, MAXPATHLEN) == NULL) {
- zlog_err("config_log_file: Unable to alloc mem!");
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "config_log_file: Unable to alloc mem!");
return CMD_WARNING_CONFIG_FAILED;
}
char spacing[256];
int lineno = 0;
- zlog_err ("%s: FATAL parse error: %s", __func__, msg);
- zlog_err ("%s: %d:%d-%d of this command definition:", __func__, loc->first_line, loc->first_column, loc->last_column);
+ zlog_notice ("%s: FATAL parse error: %s", __func__, msg);
+ zlog_notice ("%s: %d:%d-%d of this command definition:", __func__, loc->first_line, loc->first_column, loc->last_column);
line = tmpstr;
do {
if (eol)
*eol++ = '\0';
- zlog_err ("%s: | %s", __func__, line);
+ zlog_notice ("%s: | %s", __func__, line);
if (lineno == loc->first_line && lineno == loc->last_line
&& loc->first_column < (int)sizeof(spacing) - 1
&& loc->last_column < (int)sizeof(spacing) - 1) {
memset(spacing, ' ', loc->first_column - 1);
memset(spacing + loc->first_column - 1, '^', len);
spacing[loc->first_column - 1 + len] = '\0';
- zlog_err ("%s: | %s", __func__, spacing);
+ zlog_notice ("%s: | %s", __func__, spacing);
}
} while ((line = eol));
free(tmpstr);
#include <string.h>
#include <pthread.h>
#include <signal.h>
+#include <inttypes.h>
#include "ferr.h"
#include "vty.h"
#include "jhash.h"
#include "memory.h"
+#include "hash.h"
+#include "command.h"
+#include "json.h"
+#include "linklist.h"
DEFINE_MTYPE_STATIC(LIB, ERRINFO, "error information")
+/*
+ * Thread-specific key for temporary storage of allocated ferr.
+ */
static pthread_key_t errkey;
static void ferr_free(void *arg)
pthread_key_delete(errkey);
}
+/*
+ * Global shared hash table holding reference text for all defined errors.
+ */
+pthread_mutex_t refs_mtx = PTHREAD_MUTEX_INITIALIZER;
+struct hash *refs;
+
+static int ferr_hash_cmp(const void *a, const void *b)
+{
+ const struct log_ref *f_a = a;
+ const struct log_ref *f_b = b;
+
+ return f_a->code == f_b->code;
+}
+
+static inline unsigned int ferr_hash_key(void *a)
+{
+ struct log_ref *f = a;
+
+ return f->code;
+}
+
+void log_ref_add(struct log_ref *ref)
+{
+ uint32_t i = 0;
+
+ pthread_mutex_lock(&refs_mtx);
+ {
+ while (ref[i].code != END_FERR) {
+ hash_get(refs, &ref[i], hash_alloc_intern);
+ i++;
+ }
+ }
+ pthread_mutex_unlock(&refs_mtx);
+}
+
+struct log_ref *log_ref_get(uint32_t code)
+{
+ struct log_ref holder;
+ struct log_ref *ref;
+
+ holder.code = code;
+ pthread_mutex_lock(&refs_mtx);
+ {
+ ref = hash_lookup(refs, &holder);
+ }
+ pthread_mutex_unlock(&refs_mtx);
+
+ return ref;
+}
+
+void log_ref_display(struct vty *vty, uint32_t code, bool json)
+{
+ struct log_ref *ref;
+ struct json_object *top, *obj;
+ struct list *errlist;
+ struct listnode *ln;
+
+ if (json)
+ top = json_object_new_object();
+
+ pthread_mutex_lock(&refs_mtx);
+ {
+ errlist = code ? list_new() : hash_to_list(refs);
+ }
+ pthread_mutex_unlock(&refs_mtx);
+
+ if (code) {
+ ref = log_ref_get(code);
+ if (!ref) {
+ vty_out(vty, "Code %"PRIu32" - Unknown\n", code);
+ return;
+ }
+ listnode_add(errlist, ref);
+ }
+
+ for (ALL_LIST_ELEMENTS_RO(errlist, ln, ref)) {
+ if (json) {
+ char key[11];
+
+ snprintf(key, sizeof(key), "%"PRIu32, ref->code);
+ obj = json_object_new_object();
+ json_object_string_add(obj, "title", ref->title);
+ json_object_string_add(obj, "description",
+ ref->description);
+ json_object_string_add(obj, "suggestion",
+ ref->suggestion);
+ json_object_object_add(top, key, obj);
+ } else {
+ char pbuf[256];
+ char ubuf[256];
+
+ snprintf(pbuf, sizeof(pbuf), "\nError %"PRIu32" - %s",
+ code, ref->title);
+ memset(ubuf, '=', strlen(pbuf));
+ ubuf[sizeof(ubuf) - 1] = '\0';
+
+ vty_out(vty, "%s\n%s\n", pbuf, ubuf);
+ vty_out(vty, "Description:\n%s\n\n", ref->description);
+ vty_out(vty, "Recommendation:\n%s\n", ref->suggestion);
+ }
+ }
+
+ if (json) {
+ const char *str = json_object_to_json_string_ext(
+ top, JSON_C_TO_STRING_PRETTY);
+ vty_out(vty, "%s\n", str);
+ json_object_free(top);
+ }
+
+ list_delete_and_null(&errlist);
+}
+
+DEFUN_NOSH(show_error_code,
+ show_error_code_cmd,
+ "show error <(1-4294967296)|all> [json]",
+ SHOW_STR
+ "Information on errors\n"
+ "Error code to get info about\n"
+ "Information on all errors\n"
+ JSON_STR)
+{
+ bool json = strmatch(argv[argc-1]->text, "json");
+ uint32_t arg = 0;
+
+ if (!strmatch(argv[2]->text, "all"))
+ arg = strtoul(argv[2]->arg, NULL, 10);
+
+ log_ref_display(vty, arg, json);
+ return CMD_SUCCESS;
+}
+
+void log_ref_init(void)
+{
+ pthread_mutex_lock(&refs_mtx);
+ {
+ refs = hash_create(ferr_hash_key, ferr_hash_cmp,
+ "Error Reference Texts");
+ }
+ pthread_mutex_unlock(&refs_mtx);
+
+ install_element(VIEW_NODE, &show_error_code_cmd);
+}
+
+void log_ref_fini(void)
+{
+ pthread_mutex_lock(&refs_mtx);
+ {
+ hash_clean(refs, NULL);
+ hash_free(refs);
+ refs = NULL;
+ }
+ pthread_mutex_unlock(&refs_mtx);
+}
+
const struct ferr *ferr_get_last(ferr_r errval)
{
struct ferr *last_error = pthread_getspecific(errkey);
#include <limits.h>
#include <errno.h>
+#include "vty.h"
+
/* return type when this error indication stuff is used.
*
* guaranteed to have boolean evaluation to "false" when OK, "true" when error
char pathname[PATH_MAX];
};
+/* Numeric ranges assigned to daemons for use as error codes. */
+#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_FERR_START 0x10000001
+#define WATCHFRR_FERR_END 0x10FFFFFF
+#define ZEBRA_FERR_START 0xF1000001
+#define ZEBRA_FERR_END 0xF1FFFFFF
+#define END_FERR 0xFFFFFFFF
+
+struct log_ref {
+ /* Unique error code displayed to end user as a reference. -1 means
+ * this is an uncoded error that does not have reference material. */
+ uint32_t code;
+ /* Ultra brief title */
+ const char *title;
+ /* Brief description of error */
+ const char *description;
+ /* Remedial suggestion */
+ const char *suggestion;
+};
+
+void log_ref_add(struct log_ref *ref);
+struct log_ref *log_ref_get(uint32_t code);
+void log_ref_display(struct vty *vty, uint32_t code, bool json);
+
+/*
+ * This function should be called by the
+ * code in libfrr.c
+ */
+void log_ref_init(void);
+void log_ref_fini(void);
+
/* get error details.
*
* NB: errval/ferr_r does NOT carry the full error information. It's only
*/
const struct ferr *ferr_get_last(ferr_r errval);
-/* can optionally be called at strategic locations.
- * always returns 0. */
+/*
+ * Can optionally be called at strategic locations.
+ * Always returns 0.
+ */
ferr_r ferr_clear(void);
/* do NOT call these functions directly. only for macro use! */
#include "memory.h"
#include "frr_zmq.h"
#include "log.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, ZEROMQ_CB, "ZeroMQ callback")
return 0;
out_err:
- zlog_err("ZeroMQ read error: %s(%d)", strerror(errno), errno);
+ flog_err(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;
return 0;
out_err:
- zlog_err("ZeroMQ write error: %s(%d)", strerror(errno), errno);
+ flog_err(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;
* hash table to operate on
*
* data
- * data to insert or retrieve
+ * data to insert or retrieve - A hash backet will not be created if
+ * the alloc_func returns a NULL pointer and nothing will be added to
+ * the hash. As such backet->data will always be non-NULL.
*
* alloc_func
* function to call if the item is not found in the hash table. This
* during the walk will cause undefined behavior in that some new entries
* will be walked and some will not. So do not do this.
*
+ * The backet passed to func will have a non-NULL data pointer.
+ *
* hash
* hash table to operate on
*
* during the walk will cause undefined behavior in that some new entries
* will be walked and some will not. So do not do this.
*
+ * The backet passed to func will have a non-NULL data pointer.
+ *
* hash
* hash table to operate on
*
#include "linklist.h"
#include "vector.h"
+#include "lib_errors.h"
#include "vty.h"
#include "command.h"
#include "vrf.h"
#define IFNAME_RB_INSERT(vrf, ifp) \
if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp))) \
- zlog_err( \
+ flog_err( \
+ 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( \
+ flog_err( \
+ 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( \
+ flog_err( \
+ 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( \
+ flog_err( \
+ LIB_ERR_INTERFACE, \
"%s(%u): corruption detected -- interface with this " \
"ifindex doesn't exist in VRF %u!", \
__func__, (ifp)->ifindex, (ifp)->vrf_id);
--- /dev/null
+/*
+ * Library-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "lib_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_lib_err[] = {
+ {
+ .code = LIB_ERR_PRIVILEGES,
+ .title = "Failure to raise or lower privileges",
+ .description = "FRR attempted to raise or lower its privileges and was unable to do so",
+ .suggestion = "Ensure that you are running FRR as the frr user and that the user has sufficient privileges to properly access root privileges"
+ },
+ {
+ .code = LIB_ERR_VRF_START,
+ .title = "VRF Failure on Start",
+ .description = "Upon startup FRR failed to properly initialize and startup the VRF subsystem",
+ .suggestion = "Ensure that there is sufficient memory to start processes and restart FRR",
+ },
+ {
+ .code = LIB_ERR_SOCKET,
+ .title = "Socket Error",
+ .description = "When attempting to access a socket a system error has occured and we were unable to properly complete the request",
+ .suggestion = "Ensure that there are sufficient system resources available and ensure that the frr user has sufficient permisions to work",
+ },
+ {
+ .code = LIB_ERR_ZAPI_MISSMATCH,
+ .title = "ZAPI Error",
+ .description = "A version miss-match has been detected between zebra and client protocol",
+ .suggestion = "Two different versions of FRR have been installed and the install is not properly setup. Completely stop FRR, remove it from the system and reinstall. Typically only developers should see this issue."
+ },
+ {
+ .code = LIB_ERR_ZAPI_ENCODE,
+ .title = "ZAPI Error",
+ .description = "The ZAPI subsystem has detected an encoding issue, between zebra and a client protocol",
+ .suggestion = "Restart FRR"
+ },
+ {
+ .code = LIB_ERR_ZAPI_SOCKET,
+ .title = "ZAPI Error",
+ .description = "The ZAPI subsystem has detected a socket error between zebra and a client",
+ .suggestion = "Restart FRR"
+ },
+ {
+ .code = LIB_ERR_SYSTEM_CALL,
+ .title = "System Call Error",
+ .description = "FRR has detected a error from using a vital system call and has probably already exited",
+ .suggestion = "Ensure permissions are correct for FRR files, users and groups are correct. Additionally check that sufficient system resources are available."
+ },
+ {
+ .code = LIB_ERR_VTY,
+ .title = "VTY Subsystem Error",
+ .description = "FRR has detected a problem with the specified configuration file",
+ .suggestion = "Ensure configuration file exists and has correct permissions for operations Additionally ensure that all config lines are correct as well",
+ },
+ {
+ .code = LIB_ERR_SNMP,
+ .title = "SNMP Subsystem Error",
+ .description = "FRR has detected a problem with the snmp library it uses A 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 from 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 from 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 updated 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 is not working properly now",
+ .suggestion = "Open an Issue with all relevant log files and restart FRR"
+ },
+ {
+ .code = LIB_ERR_UNAVAILABLE,
+ .title = "Feature or system unavailable",
+ .description = "FRR was not compiled with support for a particular feature, or it is not available on the current platform",
+ .suggestion = "Recompile FRR with the feature enabled, or find out what platforms support the feature"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void lib_error_init(void)
+{
+ log_ref_add(ferr_lib_err);
+}
--- /dev/null
+/*
+ * Library-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __LIB_ERRORS_H__
+#define __LIB_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum lib_log_refs {
+ LIB_ERR_PRIVILEGES = LIB_FERR_START,
+ LIB_ERR_VRF_START,
+ LIB_ERR_SOCKET,
+ LIB_ERR_ZAPI_MISSMATCH,
+ LIB_ERR_ZAPI_ENCODE,
+ LIB_ERR_ZAPI_SOCKET,
+ LIB_ERR_SYSTEM_CALL,
+ LIB_ERR_VTY,
+ LIB_ERR_SNMP,
+ LIB_ERR_INTERFACE,
+ LIB_ERR_NS,
+ LIB_ERR_DEVELOPMENT,
+ LIB_ERR_ZMQ,
+ LIB_ERR_UNAVAILABLE,
+};
+
+extern void lib_error_init(void);
+
+#endif
#include "log_int.h"
#include "module.h"
#include "network.h"
+#include "lib_errors.h"
DEFINE_HOOK(frr_late_init, (struct thread_master * tm), (tm))
DEFINE_KOOH(frr_early_fini, (), ())
vty_init(master);
memory_init();
+ log_ref_init();
+ lib_error_init();
+
return master;
}
nullfd = open("/dev/null", O_RDONLY | O_NOCTTY);
if (nullfd == -1) {
- zlog_err("%s: failed to open /dev/null: %s", __func__,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: failed to open /dev/null: %s", __func__,
+ safe_strerror(errno));
} else {
dup2(nullfd, 0);
dup2(nullfd, 1);
} 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));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: failed to open /dev/null: %s",
+ __func__, safe_strerror(errno));
} else {
dup2(nullfd, 0);
dup2(nullfd, 1);
/* memory_init -> nothing needed */
vty_terminate();
cmd_terminate();
+ log_ref_fini();
zprivs_terminate(di->privs);
/* signal_init -> nothing needed */
thread_master_free(master);
#include "log_int.h"
#include "memory.h"
#include "command.h"
+#include "lib_errors.h"
+
#ifndef SUNOS_5
#include <sys/un.h>
#endif
size = backtrace(array, array_size(array));
if (size <= 0 || (size_t)size > array_size(array)) {
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"Cannot get backtrace, returned invalid # of frames %d "
"(valid range is between 1 and %lu)",
size, (unsigned long)(array_size(array)));
}
zlog(priority, "Backtrace for %d stack frames:", size);
if (!(strings = backtrace_symbols(array, size))) {
- zlog_err("Cannot get backtrace symbols (out of memory?)");
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Cannot get backtrace symbols (out of memory?)");
for (i = 0; i < size; i++)
zlog(priority, "[bt %d] %p", i, array[i]);
} else {
void memory_oom(size_t size, const char *name)
{
- zlog_err(
- "out of memory: failed to allocate %zu bytes for %s"
- "object",
- size, name);
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "out of memory: failed to allocate %zu bytes for %s"
+ "object",
+ size, name);
zlog_backtrace(LOG_ERR);
abort();
}
save_errno = errno;
umask(oldumask);
if (zl->fp == NULL) {
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"Log rotate failed: cannot open file %s for append: %s",
zl->filename, safe_strerror(save_errno));
ret = -1;
unsigned int i;
if (zroute >= array_size(route_types)) {
- zlog_err("unknown zebra route type: %u", zroute);
+ flog_err(LIB_ERR_DEVELOPMENT, "unknown zebra route type: %u",
+ zroute);
return &unknown;
}
if (zroute == route_types[zroute].type)
return &route_types[i];
}
}
- zlog_err("internal error: cannot find route type %u in table!", zroute);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "internal error: cannot find route type %u in table!",
+ zroute);
return &unknown;
}
const char *zserv_command_string(unsigned int command)
{
if (command >= array_size(command_types)) {
- zlog_err("unknown zserv command type: %u", command);
+ flog_err(LIB_ERR_DEVELOPMENT, "unknown zserv command type: %u",
+ command);
return unknown.string;
}
return command_types[command].string;
extern void zlog_notice(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2);
+/* For logs which have error codes associated with them */
+#define flog_err(ferr_id, format, ...) \
+ zlog_err("[EC %d] " format, ferr_id, ##__VA_ARGS__)
+#define flog_err_sys(ferr_id, format, ...) \
+ flog_err(ferr_id, format, ##__VA_ARGS__)
+
+
extern void zlog_thread_info(int log_level);
/* Set logging level for the given destination. If the log_level
#ifndef _QUAGGA_MPLS_H
#define _QUAGGA_MPLS_H
+#include <zebra.h>
#include <arpa/inet.h>
#ifdef MPLS_LABEL_MAX
#include "ns.h"
#include "log.h"
#include "memory.h"
-
#include "command.h"
#include "vty.h"
#include "vrf.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, NS, "NetNS Context")
DEFINE_MTYPE_STATIC(LIB, NS_NAME, "NetNS Name")
}
if (!ns_is_enabled(ns)) {
- zlog_err("Can not enable NS %u: %s!", ns->ns_id,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Can not enable NS %u: %s!", ns->ns_id,
+ safe_strerror(errno));
return 0;
}
/* 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);
+ flog_err(LIB_ERR_NS,
+ "Can not enable NS %s %u: Invalid NSID",
+ ns->name, ns->ns_id);
return 0;
}
if (func)
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));
+ flog_err(LIB_ERR_NS,
+ "NS initialization failure %d(%s)", errno,
+ safe_strerror(errno));
} else {
ns_default_ns_fd = -1;
default_ns = NULL;
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__);
+ flog_err(LIB_ERR_NS, "%s: failed to create the default NS!",
+ __func__);
exit(1);
}
if (have_netns()) {
/* Enable the default NS. */
if (!ns_enable(default_ns, NULL)) {
- zlog_err("%s: failed to enable the default NS!", __func__);
+ flog_err(LIB_ERR_NS, "%s: failed to enable the default NS!",
+ __func__);
exit(1);
}
}
#include <log.h>
#include "version.h"
#include "network.h"
+#include "lib_errors.h"
#define PIDFILE_MASK 0644
oldumask = umask(0777 & ~PIDFILE_MASK);
fd = open(path, O_RDWR | O_CREAT, PIDFILE_MASK);
if (fd < 0) {
- zlog_err("Can't create pid lock file %s (%s), exiting", path,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Can't create pid lock file %s (%s), exiting",
+ path, safe_strerror(errno));
umask(oldumask);
exit(1);
} else {
lock.l_whence = SEEK_SET;
if (fcntl(fd, F_SETLK, &lock) < 0) {
- zlog_err("Could not lock pid_file %s (%s), exiting",
- path, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Could not lock pid_file %s (%s), exiting",
+ path, safe_strerror(errno));
exit(1);
}
sprintf(buf, "%d\n", (int)pid);
pidsize = strlen(buf);
if ((tmp = write(fd, buf, pidsize)) != (int)pidsize)
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"Could not write pid %d to pid_file %s, rc was %d: %s",
(int)pid, path, tmp, safe_strerror(errno));
else if (ftruncate(fd, pidsize) < 0)
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"Could not truncate pid_file %s to %u bytes: %s",
path, (unsigned int)pidsize,
safe_strerror(errno));
#include "memory.h"
#include "log.h"
#include "jhash.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, PREFIX, "Prefix")
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);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "prefix_copy(): Unknown address family %d",
+ src->family);
assert(0);
}
}
}
#endif /* HAVE_GETGROUPLIST */
+struct zebra_privs_t *_zprivs_raise(struct zebra_privs_t *privs,
+ const char *funcname)
+{
+ int save_errno = errno;
+
+ if (!privs)
+ return NULL;
+
+ errno = 0;
+ if (privs->change(ZPRIVS_RAISE)) {
+ zlog_err("%s: Failed to raise privileges (%s)",
+ funcname, safe_strerror(errno));
+ }
+ errno = save_errno;
+ privs->raised_in_funcname = funcname;
+ return privs;
+}
+
+void _zprivs_lower(struct zebra_privs_t **privs)
+{
+ int save_errno = errno;
+
+ if (!*privs)
+ return;
+
+ errno = 0;
+ if ((*privs)->change(ZPRIVS_LOWER)) {
+ zlog_err("%s: Failed to lower privileges (%s)",
+ (*privs)->raised_in_funcname, safe_strerror(errno));
+ }
+ errno = save_errno;
+ (*privs)->raised_in_funcname = NULL;
+ *privs = NULL;
+}
+
void zprivs_preinit(struct zebra_privs_t *zprivs)
{
struct passwd *pwentry = NULL;
int (*change)(zebra_privs_ops_t); /* change privileges, 0 on success */
zebra_privs_current_t (*current_state)(
void); /* current privilege state */
+ const char *raised_in_funcname;
};
struct zprivs_ids_t {
/* query for runtime uid's and gid's, eg vty needs this */
extern void zprivs_get_ids(struct zprivs_ids_t *);
+/*
+ * Wrapper around zprivs, to be used as:
+ * frr_elevate_privs(&privs) {
+ * ... code ...
+ * if (error)
+ * break; -- break can be used to get out of the block
+ * ... code ...
+ * }
+ *
+ * The argument to frr_elevate_privs() can be NULL to leave privileges as-is
+ * (mostly useful for conditional privilege-raising, i.e.:)
+ * frr_elevate_privs(cond ? &privs : NULL) {}
+ *
+ * NB: The code block is always executed, regardless of whether privileges
+ * could be raised or not, or whether NULL was given or not. This is fully
+ * intentional; the user may have configured some RBAC or similar that we
+ * are not aware of, but that allows our code to proceed without privileges.
+ *
+ * The point of this wrapper is to prevent accidental bugs where privileges
+ * are elevated but then not dropped. This can happen when, for example, a
+ * "return", "goto" or "break" in the middle of the elevated-privilege code
+ * skips past the privilege dropping call.
+ *
+ * The macro below uses variable cleanup to drop privileges as soon as the
+ * code block is left in any way (and thus the _privs variable goes out of
+ * scope.) _once is just a trick to run the loop exactly once.
+ */
+extern struct zebra_privs_t *_zprivs_raise(struct zebra_privs_t *privs,
+ const char *funcname);
+extern void _zprivs_lower(struct zebra_privs_t **privs);
+
+#define frr_elevate_privs(privs) \
+ for (struct zebra_privs_t *_once = NULL, \
+ *_privs __attribute__( \
+ (unused, cleanup(_zprivs_lower))) = \
+ _zprivs_raise(privs, __func__); \
+ _once == NULL; _once = (void *)1)
+
#endif /* _ZEBRA_PRIVS_H */
struct route_map_dep *dep = (struct route_map_dep *)backet->data;
char *rmap_name;
- if (dep && arg) {
+ if (arg) {
rmap_name =
(char *)hash_release(dep->dep_rmap_hash, (void *)arg);
if (rmap_name) {
char *rmap_name = (char *)backet->data;
char *dep_name = (char *)data;
- if (rmap_name)
- zlog_debug("%s: Dependency for %s: %s", __FUNCTION__, dep_name,
- rmap_name);
+ zlog_debug("%s: Dependency for %s: %s", __FUNCTION__, dep_name,
+ rmap_name);
}
static int route_map_dep_update(struct hash *dephash, const char *dep_name,
static void route_map_process_dependency(struct hash_backet *backet, void *data)
{
- char *rmap_name;
+ char *rmap_name = (char *)backet->data;
route_map_event_t type = (route_map_event_t)(ptrdiff_t)data;
- rmap_name = (char *)backet->data;
-
- if (rmap_name) {
- if (rmap_debug)
- zlog_debug("%s: Notifying %s of dependency",
- __FUNCTION__, rmap_name);
- if (route_map_master.event_hook)
- (*route_map_master.event_hook)(type, rmap_name);
- }
+ if (rmap_debug)
+ zlog_debug("%s: Notifying %s of dependency",
+ __FUNCTION__, rmap_name);
+ if (route_map_master.event_hook)
+ (*route_map_master.event_hook)(type, rmap_name);
}
void route_map_upd8_dependency(route_map_event_t type, const char *arg,
#include <sigevent.h>
#include <log.h>
#include <memory.h>
+#include <lib_errors.h>
#ifdef SA_SIGINFO
#ifdef HAVE_UCONTEXT_H
sigdelset(&newmask, SIGKILL);
if ((sigprocmask(SIG_BLOCK, &newmask, &oldmask)) < 0) {
- zlog_err("quagga_signal_timer: couldnt block signals!");
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "quagga_signal_timer: couldnt block signals!");
return -1;
}
#endif /* SIGEVENT_BLOCK_SIGNALS */
#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")
/* DEBUG */
if (!key) {
- zlog_err("%s: key is 0, value is %p", __func__, value);
+ flog_err(LIB_ERR_DEVELOPMENT, "%s: key is 0, value is %p",
+ __func__, value);
}
p = l->header;
#include "log.h"
#include "sockopt.h"
#include "sockunion.h"
+#include "lib_errors.h"
void setsockopt_so_recvbuf(int sock, int size)
{
int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&optval,
&optlen);
if (ret < 0) {
- zlog_err("fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock,
- errno, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock,
+ errno, safe_strerror(errno));
return ret;
}
return optval;
if (ENOENT == errno)
ret = 0;
else
- zlog_err("sockopt_tcp_signature: setsockopt(%d): %s",
- sock, safe_strerror(errno));
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
+ "sockopt_tcp_signature: setsockopt(%d): %s",
+ sock, safe_strerror(errno));
}
return ret;
#else /* HAVE_TCP_MD5SIG */
#include "memory.h"
#include "log.h"
#include "jhash.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, SOCKUNION, "Socket union")
#ifdef SO_MARK
int ret;
- if (cap->change(ZPRIVS_RAISE))
- zlog_err("routing_socket: Can't raise privileges");
-
- ret = setsockopt(sock, SOL_SOCKET, SO_MARK, &mark, sizeof(mark));
-
- if (cap->change(ZPRIVS_LOWER))
- zlog_err("routing_socket: Can't lower privileges");
-
+ frr_elevate_privs(cap) {
+ ret = setsockopt(sock, SOL_SOCKET, SO_MARK, &mark,
+ sizeof(mark));
+ }
return ret;
#else
return 0;
lib/jhash.c \
lib/json.c \
lib/keychain.c \
+ lib/lib_errors.c \
lib/libfrr.c \
lib/linklist.c \
lib/log.c \
lib/jhash.h \
lib/json.h \
lib/keychain.h \
+ lib/lib_errors.h \
lib/libfrr.h \
lib/libospf.h \
lib/linklist.h \
#include "ns.h"
#include "privs.h"
#include "nexthop_group.h"
+#include "lib_errors.h"
/* default VRF ID value used when VRF backend is not NETNS */
#define VRF_DEFAULT_INTERNAL 0
/* The default VRF always exists. */
default_vrf = vrf_get(VRF_DEFAULT, VRF_DEFAULT_NAME);
if (!default_vrf) {
- zlog_err("vrf_init: failed to create the default VRF!");
+ flog_err(LIB_ERR_VRF_START,
+ "vrf_init: failed to create the default VRF!");
exit(1);
}
/* Enable the default VRF. */
if (!vrf_enable(default_vrf)) {
- zlog_err("vrf_init: failed to enable the default VRF!");
+ flog_err(LIB_ERR_VRF_START,
+ "vrf_init: failed to enable the default VRF!");
exit(1);
}
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0)
- zlog_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
+
if (ret > 0 && interfacename && vrf_default_accepts_vrf(type)) {
zlog_err("VRF socket not used since net.ipv4.%s_l3mdev_accept != 0",
(type == SOCK_STREAM ? "tcp" : "udp"));
errno = EEXIST; /* not sure if this is the best error... */
return -2;
}
+
ret = socket(domain, type, protocol);
save_errno = errno;
ret2 = vrf_switchback_to_initial();
if (ret2 < 0)
- zlog_err("%s: Can't switchback from VRF %u (%s)", __func__,
- vrf_id, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: Can't switchback from VRF %u (%s)", __func__,
+ vrf_id, safe_strerror(errno));
errno = save_errno;
if (ret <= 0)
return ret;
if (!pathname)
return CMD_WARNING_CONFIG_FAILED;
- if (vrf_daemon_privs &&
- vrf_daemon_privs->change(ZPRIVS_RAISE))
- zlog_err("%s: Can't raise privileges", __func__);
-
- ret = vrf_netns_handler_create(vty, vrf, pathname,
- NS_UNKNOWN, NS_UNKNOWN);
-
- if (vrf_daemon_privs &&
- vrf_daemon_privs->change(ZPRIVS_LOWER))
- zlog_err("%s: Can't lower privileges", __func__);
+ frr_elevate_privs(vrf_daemon_privs) {
+ ret = vrf_netns_handler_create(vty, vrf, pathname,
+ NS_UNKNOWN, NS_UNKNOWN);
+ }
return ret;
}
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0)
- zlog_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
ret = getaddrinfo(node, service, hints, res);
save_errno = errno;
ret2 = vrf_switchback_to_initial();
if (ret2 < 0)
- zlog_err("%s: Can't switchback from VRF %u (%s)", __func__,
- vrf_id, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: Can't switchback from VRF %u (%s)", __func__,
+ vrf_id, safe_strerror(errno));
errno = save_errno;
return ret;
}
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0) {
- zlog_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
return 0;
}
rc = ioctl(d, request, params);
saved_errno = errno;
ret = vrf_switchback_to_initial();
if (ret < 0)
- zlog_err("%s: Can't switchback from VRF %u (%s)", __func__,
- vrf_id, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: Can't switchback from VRF %u (%s)", __func__,
+ vrf_id, safe_strerror(errno));
errno = saved_errno;
return rc;
}
ret = vrf_switch_to_netns(vrf_id);
if (ret < 0)
- zlog_err("%s: Can't switch to VRF %u (%s)", __func__, vrf_id,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)",
+ __func__, vrf_id, safe_strerror(errno));
ret = sockunion_socket(su);
save_errno = errno;
ret2 = vrf_switchback_to_initial();
if (ret2 < 0)
- zlog_err("%s: Can't switchback from VRF %u (%s)", __func__,
- vrf_id, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: Can't switchback from VRF %u (%s)", __func__,
+ vrf_id, safe_strerror(errno));
errno = save_errno;
if (ret <= 0)
#include "network.h"
#include "libfrr.h"
#include "frrstr.h"
+#include "lib_errors.h"
#include <arpa/telnet.h>
#include <termios.h>
vty_str);
/* now log the command */
- zlog_err("%s%s", prompt_str, buf);
+ zlog_notice("%s%s", prompt_str, buf);
}
#ifdef CONSUMED_TIME_CHECK
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",
+ flog_err(
+ 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 {
ret = getaddrinfo(hostname, port_str, &req, &ainfo);
if (ret != 0) {
- zlog_err("getaddrinfo failed: %s", gai_strerror(ret));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "getaddrinfo failed: %s",
+ gai_strerror(ret));
exit(1);
}
/* Make UNIX domain socket. */
sock = socket(AF_UNIX, SOCK_STREAM, 0);
if (sock < 0) {
- zlog_err("Cannot create unix stream socket: %s",
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "Cannot create unix stream socket: %s",
+ safe_strerror(errno));
return;
}
ret = bind(sock, (struct sockaddr *)&serv, len);
if (ret < 0) {
- zlog_err("Cannot bind path %s: %s", path, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "Cannot bind path %s: %s", path,
+ safe_strerror(errno));
close(sock); /* Avoid sd leak. */
return;
}
ret = listen(sock, 5);
if (ret < 0) {
- zlog_err("listen(fd %d) failed: %s", sock,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "listen(fd %d) failed: %s", sock,
+ safe_strerror(errno));
close(sock); /* Avoid sd leak. */
return;
}
if ((int)ids.gid_vty > 0) {
/* set group of socket */
if (chown(path, -1, ids.gid_vty)) {
- zlog_err("vty_serv_un: could chown socket, %s",
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "vty_serv_un: could chown socket, %s",
+ safe_strerror(errno));
}
}
nl = strchr(vty->error_buf, '\n');
if (nl)
*nl = '\0';
- zlog_err("ERROR: %s on config line %u: %s", message, line_num,
- vty->error_buf);
+ flog_err(LIB_ERR_VTY,
+ "ERROR: %s on config line %u: %s", message, line_num,
+ vty->error_buf);
}
vty_close(vty);
if (config_file != NULL) {
if (!IS_DIRECTORY_SEP(config_file[0])) {
if (getcwd(cwd, MAXPATHLEN) == NULL) {
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"Failure to determine Current Working Directory %d!",
errno);
exit(1);
confp = fopen(fullpath, "r");
if (confp == NULL) {
- zlog_err("%s: failed to open configuration file %s: %s",
+ zlog_warn("%s: failed to open configuration file %s: %s, checking backup",
__func__, fullpath, safe_strerror(errno));
confp = vty_use_backup_config(fullpath);
zlog_warn(
"WARNING: using backup configuration file!");
else {
- zlog_err("can't open configuration file [%s]",
- config_file);
+ flog_err(LIB_ERR_VTY,
+ "can't open configuration file [%s]",
+ config_file);
exit(1);
}
}
#endif /* VTYSH */
confp = fopen(config_default_dir, "r");
if (confp == NULL) {
- zlog_err("%s: failed to open configuration file %s: %s",
- __func__, config_default_dir,
- safe_strerror(errno));
+ zlog_warn("%s: failed to open configuration file %s: %s, checking backup",
+ __func__, config_default_dir,
+ safe_strerror(errno));
confp = vty_use_backup_config(config_default_dir);
if (confp) {
"WARNING: using backup configuration file!");
fullpath = config_default_dir;
} else {
- zlog_err("can't open configuration file [%s]",
- config_default_dir);
+ flog_err(LIB_ERR_VTY,
+ "can't open configuration file [%s]",
+ config_default_dir);
goto tmp_free_and_out;
}
} else
* Hence not worrying about it too much.
*/
if (!chdir(SYSCONFDIR)) {
- zlog_err("Failure to chdir to %s, errno: %d",
- SYSCONFDIR, errno);
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Failure to chdir to %s, errno: %d",
+ SYSCONFDIR, errno);
exit(-1);
}
if (getcwd(cwd, MAXPATHLEN) == NULL) {
- zlog_err("Failure to getcwd, errno: %d", errno);
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Failure to getcwd, errno: %d", errno);
exit(-1);
}
}
#include "sockopt.h"
#include "pbr.h"
#include "nexthop_group.h"
+#include "lib_errors.h"
DEFINE_MTYPE_STATIC(LIB, ZCLIENT, "Zclient")
DEFINE_MTYPE_STATIC(LIB, REDIST_INST, "Redistribution instance IDs")
set_cloexec(sock);
- zclient->privs->change(ZPRIVS_RAISE);
- setsockopt_so_sendbuf(sock, 1048576);
- zclient->privs->change(ZPRIVS_LOWER);
+ frr_elevate_privs(zclient->privs) {
+ setsockopt_so_sendbuf(sock, 1048576);
+ }
/* Connect to zebra. */
ret = connect(sock, (struct sockaddr *)&zclient_addr, zclient_addr_len);
STREAM_GETW(s, *cmd);
if (*version != ZSERV_VERSION || *marker != ZEBRA_HEADER_MARKER) {
- zlog_err(
- "%s: socket %d version mismatch, marker %d, version %d",
- __func__, sock, *marker, *version);
+ flog_err(LIB_ERR_ZAPI_MISSMATCH,
+ "%s: socket %d version mismatch, marker %d, version %d",
+ __func__, sock, *marker, *version);
return -1;
}
char buf[PREFIX2STR_BUFFER];
prefix2str(&api->prefix, buf,
sizeof(buf));
- zlog_err(
- "%s: prefix %s: can't encode "
- "%u labels (maximum is %u)",
- __func__, buf,
- api_nh->label_num,
- MPLS_MAX_LABELS);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "%s: prefix %s: can't encode "
+ "%u labels (maximum is %u)",
+ __func__, buf,
+ api_nh->label_num,
+ MPLS_MAX_LABELS);
return -1;
}
for (i = 0; i < bwclassnum && i < MAX_CLASS_TYPE; i++)
iflp->unrsv_bw[i] = stream_getf(s);
if (i < bwclassnum)
- zlog_err(
- "%s: received %d > %d (MAX_CLASS_TYPE) bw entries"
- " - outdated library?",
- __func__, bwclassnum, MAX_CLASS_TYPE);
+ flog_err(LIB_ERR_ZAPI_MISSMATCH,
+ "%s: received %d > %d (MAX_CLASS_TYPE) bw entries"
+ " - outdated library?",
+ __func__, bwclassnum, MAX_CLASS_TYPE);
}
iflp->admin_grp = stream_getl(s);
iflp->rmt_as = stream_getl(s);
struct interface *ifp = if_lookup_by_index(ifindex, VRF_DEFAULT);
if (ifp == NULL) {
- zlog_err("%s: unknown ifindex %u, shouldn't happen", __func__,
- ifindex);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "%s: unknown ifindex %u, shouldn't happen", __func__,
+ ifindex);
return NULL;
}
size);
}
if (ret != 0) {
- zlog_err("%s: Invalid Sync Message Reply", __func__);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "%s: Invalid Sync Message Reply", __func__);
return -1;
}
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("Can't write to zclient sock");
+ flog_err(LIB_ERR_ZAPI_SOCKET, "Can't write to zclient sock");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("Zclient sock closed");
+ flog_err(LIB_ERR_ZAPI_SOCKET, "Zclient sock closed");
close(zclient->sock);
zclient->sock = -1;
return -1;
/* sanity */
if (proto != zclient->redist_default)
- zlog_err(
- "Wrong proto (%u) in LM connect response. Should be %u",
- proto, zclient->redist_default);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "Wrong proto (%u) in LM connect response. Should be %u",
+ proto, zclient->redist_default);
if (instance != zclient->instance)
- zlog_err(
- "Wrong instId (%u) in LM connect response. Should be %u",
- instance, zclient->instance);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "Wrong instId (%u) in LM connect response. Should be %u",
+ instance, zclient->instance);
/* result code */
result = stream_getc(s);
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("Can't write to zclient sock");
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "Can't write to zclient sock");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("Zclient sock closed");
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "Zclient sock closed");
close(zclient->sock);
zclient->sock = -1;
return -1;
/* sanities */
if (proto != zclient->redist_default)
- zlog_err("Wrong proto (%u) in get chunk response. Should be %u",
- proto, zclient->redist_default);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "Wrong proto (%u) in get chunk response. Should be %u",
+ proto, zclient->redist_default);
if (instance != zclient->instance)
- zlog_err("Wrong instId (%u) in get chunk response Should be %u",
- instance, zclient->instance);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "Wrong instId (%u) in get chunk response Should be %u",
+ instance, zclient->instance);
/* keep */
response_keep = stream_getc(s);
/* not owning this response */
if (keep != response_keep) {
- zlog_err(
- "Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
- *start, *end, keep, response_keep);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "Invalid Label chunk: %u - %u, keeps mismatch %u != %u",
+ *start, *end, keep, response_keep);
}
/* sanity */
if (*start > *end || *start < MPLS_LABEL_UNRESERVED_MIN
|| *end > MPLS_LABEL_UNRESERVED_MAX) {
- zlog_err("Invalid Label chunk: %u - %u", *start, *end);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "Invalid Label chunk: %u - %u", *start, *end);
return -1;
}
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("Can't write to zclient sock");
+ flog_err(LIB_ERR_ZAPI_SOCKET, "Can't write to zclient sock");
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("Zclient sock connection closed");
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "Zclient sock connection closed");
close(zclient->sock);
zclient->sock = -1;
return -1;
ret = writen(zclient->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err("%s: can't write to zclient->sock", __func__);
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "%s: can't write to zclient->sock", __func__);
close(zclient->sock);
zclient->sock = -1;
return -1;
}
if (ret == 0) {
- zlog_err("%s: zclient->sock connection closed", __func__);
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "%s: zclient->sock connection closed", __func__);
close(zclient->sock);
zclient->sock = -1;
return -1;
stream_write(s, (uint8_t *)&pw->nexthop.ipv6, 16);
break;
default:
- zlog_err("%s: unknown af", __func__);
+ flog_err(LIB_ERR_ZAPI_ENCODE,
+ "%s: unknown af", __func__);
return -1;
}
command = stream_getw(zclient->ibuf);
if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) {
- zlog_err(
- "%s: socket %d version mismatch, marker %d, version %d",
- __func__, zclient->sock, marker, version);
+ flog_err(LIB_ERR_ZAPI_MISSMATCH,
+ "%s: socket %d version mismatch, marker %d, version %d",
+ __func__, zclient->sock, marker, version);
return zclient_failed(zclient);
}
if (length < ZEBRA_HEADER_SIZE) {
- zlog_err("%s: socket %d message length %u is less than %d ",
- __func__, zclient->sock, length, ZEBRA_HEADER_SIZE);
+ flog_err(LIB_ERR_ZAPI_MISSMATCH,
+ "%s: socket %d message length %u is less than %d ",
+ __func__, zclient->sock, length, ZEBRA_HEADER_SIZE);
return zclient_failed(zclient);
}
--- /dev/null
+/*
+ * NHRP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "nhrp_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_nhrp_err[] = {
+ {
+ .code = NHRP_ERR_SWAN,
+ .title = "NHRP Strong Swan Error",
+ .description = "NHRP has detected a error with the Strongswan code",
+ .suggestion = "Ensure that StrongSwan is configured correctly. Restart StrongSwan and FRR"
+ },
+ {
+ .code = NHRP_ERR_RESOLVER,
+ .title = "NHRP DNS Resolution",
+ .description = "NHRP has detected an error in an attempt to resolve a hostname",
+ .suggestion = "Ensure that DNS is working properly and the hostname is configured in dns. If you are still seeing this error, open an issue"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void nhrp_error_init(void)
+{
+ log_ref_add(ferr_nhrp_err);
+}
--- /dev/null
+/*
+ * NHRP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __NHRP_ERRORS_H__
+#define __NHRP_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum nhrp_log_refs {
+ NHRP_ERR_SWAN = NHRP_FERR_START,
+ NHRP_ERR_RESOLVER,
+};
+
+extern void nhrp_error_init(void);
+
+#endif
#include "nhrpd.h"
#include "netlink.h"
+#include "nhrp_errors.h"
DEFINE_MGROUP(NHRPD, "NHRP")
/* Library inits. */
master = frr_init();
+ nhrp_error_init();
vrf_init(NULL, NULL, NULL, NULL);
nhrp_interface_init();
resolver_init();
#include "vector.h"
#include "thread.h"
+#include "lib_errors.h"
+
#include "nhrpd.h"
+#include "nhrp_errors.h"
struct resolver_state {
ares_channel channel;
union sockunion *))
{
if (query->callback != NULL) {
- zlog_err(
- "Trying to resolve '%s', but previous query was not finished yet",
- hostname);
+ flog_err(NHRP_ERR_RESOLVER,
+ "Trying to resolve '%s', but previous query was not finished yet",
+ hostname);
return;
}
nhrpd/netlink_arp.c \
nhrpd/netlink_gre.c \
nhrpd/nhrp_cache.c \
+ nhrpd/nhrp_errors.c \
nhrpd/nhrp_event.c \
nhrpd/nhrp_interface.c \
nhrpd/nhrp_main.c \
nhrpd/debug.h \
nhrpd/list.h \
nhrpd/netlink.h \
+ nhrpd/nhrp_errors.h \
nhrpd/nhrp_protocol.h \
nhrpd/nhrpd.h \
nhrpd/os.h \
#include "thread.h"
#include "zbuf.h"
#include "log.h"
-#include "nhrpd.h"
+#include "lib_errors.h"
+#include "nhrpd.h"
#include "vici.h"
+#include "nhrp_errors.h"
#define ERRNO_IO_RETRY(EN) (((EN) == EAGAIN) || ((EN) == EWOULDBLOCK) || ((EN) == EINTR))
if (str2sockunion(buf,
&sactx->local.host)
< 0)
- zlog_err(
- "VICI: bad strongSwan local-host: %s",
- buf);
+ flog_err(NHRP_ERR_SWAN,
+ "VICI: bad strongSwan local-host: %s",
+ buf);
} else if (blob_equal(key, "local-id")
&& ctx->nsections == 1) {
sactx->local.id = *val;
if (str2sockunion(buf,
&sactx->remote.host)
< 0)
- zlog_err(
- "VICI: bad strongSwan remote-host: %s",
- buf);
+ flog_err(NHRP_ERR_SWAN,
+ "VICI: bad strongSwan remote-host: %s",
+ buf);
} else if (blob_equal(key, "remote-id")
&& ctx->nsections == 1) {
sactx->remote.id = *val;
case VICI_KEY_VALUE:
if (blob_equal(key, "errmsg")
&& blob2buf(val, buf, sizeof(buf)))
- zlog_err("VICI: strongSwan: %s", buf);
+ flog_err(NHRP_ERR_SWAN, "VICI: strongSwan: %s", buf);
break;
default:
break;
break;
case VICI_EVENT_UNKNOWN:
case VICI_CMD_UNKNOWN:
- zlog_err(
+ flog_err(NHRP_ERR_SWAN,
"VICI: StrongSwan does not support mandatory events (unpatched?)");
break;
case VICI_EVENT_CONFIRM:
#include "command.h"
#include "thread.h"
#include "linklist.h"
+#include "lib_errors.h"
#include "ospf6_proto.h"
#include "ospf6_lsa.h"
/* receive message */
len = ospf6_recvmsg(&src, &dst, &ifindex, iovector);
if (len > iobuflen) {
- zlog_err("Excess message read");
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "Excess message read");
return 0;
}
/* send message */
len = ospf6_sendmsg(src, dst, &oi->interface->ifindex, iovector);
if (len != ntohs(oh->length))
- zlog_err("Could not send entire message");
+ flog_err(LIB_ERR_DEVELOPMENT, "Could not send entire message");
}
static uint32_t ospf6_packet_max(struct ospf6_interface *oi)
#include "sockunion.h"
#include "sockopt.h"
#include "privs.h"
+#include "lib_errors.h"
#include "libospf.h"
#include "ospf6_proto.h"
/* Make ospf6d's server socket. */
int ospf6_serv_sock(void)
{
- if (ospf6d_privs.change(ZPRIVS_RAISE))
- zlog_err("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");
- return -1;
+ frr_elevate_privs(&ospf6d_privs) {
+
+ ospf6_sock = socket(AF_INET6, SOCK_RAW, IPPROTO_OSPFIGP);
+ if (ospf6_sock < 0) {
+ zlog_warn("Network: can't create OSPF6 socket.");
+ return -1;
+ }
}
- if (ospf6d_privs.change(ZPRIVS_LOWER))
- zlog_err("ospf_sock_init: could not lower privs");
/* set socket options */
#if 1
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));
+ flog_err_sys(
+ LIB_ERR_SOCKET,
+ "Network: setsockopt (%d) on ifindex %d failed: %s",
+ option, ifindex, safe_strerror(errno));
return ret;
}
if (link_error == 0 && num == table->count)
return;
- zlog_err("PANIC !!");
- zlog_err("Something has gone wrong with ospf6_route_table[%p]", table);
+ flog_err(LIB_ERR_DEVELOPMENT, "PANIC !!");
+ flog_err(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)) {
#include "pqueue.h"
#include "linklist.h"
#include "thread.h"
+#include "lib_errors.h"
#include "ospf6_lsa.h"
#include "ospf6_lsdb.h"
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);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "No nexthop ifindex at vertex %s", v->name);
return;
}
#include "zclient.h"
#include "memory.h"
#include "lib/bfd.h"
+#include "lib_errors.h"
#include "ospf6_proto.h"
#include "ospf6_top.h"
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));
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "zclient_route_send() %s failed: %s",
+ (type == REM ? "delete" : "add"),
+ safe_strerror(errno));
return;
}
--- /dev/null
+/*
+ * 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);
+}
--- /dev/null
+/*
+ * 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
#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,
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);
}
#include "log.h"
#include "sockopt.h"
#include "privs.h"
+#include "lib_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
/* 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;
}
#include "checksum.h"
#include "md5.h"
#include "vrf.h"
+#include "ospf_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
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",
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",
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);
#include "vty.h"
#include "zclient.h"
#include <lib/json.h>
+#include "ospf_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_interface.h"
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;
}
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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
/* 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;
}
struct sr_nhlfe old;
int rc;
- /* Sanity Check */
- if (srn == NULL)
- return;
-
if (IS_DEBUG_OSPF_SR)
zlog_debug(" |- Update Prefix for SR Node %s",
inet_ntoa(srn->adv_router));
#include "bfd.h"
#include "libfrr.h"
#include "defaults.h"
+#include "lib_errors.h"
#include "ospfd/ospfd.h"
#include "ospfd/ospf_network.h"
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;
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 \
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 \
ifindex_t first_ifindex;
struct interface *ifp = NULL;
- if (!pnc)
- return CMD_SUCCESS;
-
for (nh_node = pnc->nexthop; nh_node; nh_node = nh_node->next) {
first_ifindex = nh_node->ifindex;
ifp = if_lookup_by_index(first_ifindex, pim->vrf_id);
--- /dev/null
+/*
+ * PIM-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "pim_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_pim_err[] = {
+ {
+ .code = PIM_ERR_MSDP_PACKET,
+ .title = "PIM MSDP Packet Error",
+ .description = "PIM has received a packet from a peer that does not correctly decode",
+ .suggestion = "Check MSDP peer and ensure it is correctly working"
+ },
+ {
+ .code = PIM_ERR_CONFIG,
+ .title = "PIM Configuration Error",
+ .description = "PIM has detected a configuration error",
+ .suggestion = "Ensure the configuration is correct and apply correct configuration"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void pim_error_init(void)
+{
+ log_ref_add(ferr_pim_err);
+}
--- /dev/null
+/*
+ * PIM-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __PIM_ERRORS_H__
+#define __PIM_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum pim_log_refs {
+ PIM_ERR_MSDP_PACKET = PIM_FERR_START,
+ PIM_ERR_CONFIG,
+};
+
+extern void pim_error_init(void);
+
+#endif
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);
#include "if.h"
#include "hash.h"
#include "jhash.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_igmp.h"
}
if (!join) {
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SOCKET,
"IGMP socket fd=%d could not join any group on interface address %s",
fd, inet_ntoa(ifaddr));
close(fd);
THREAD_OFF(igmp->t_igmp_read);
if (close(igmp->fd)) {
- zlog_err(
+ flog_err(
+ 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));
}
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);
#include "log.h"
#include "memory.h"
#include "if.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_iface.h"
msg_size = IGMP_V3_SOURCES_OFFSET + (num_sources << 2);
if (msg_size > query_buf_size) {
- zlog_err(
+ flog_err(
+ 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);
#include "hash.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_ssm.h"
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();
pim->static_routes->del = (void (*)(void *))pim_static_route_free;
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;
#include "pim_msdp.h"
#include "pim_iface.h"
#include "pim_bfd.h"
+#include "pim_errors.h"
extern struct host host;
/*
* Initializations
*/
+ pim_error_init();
pim_vrf_init();
access_list_init();
prefix_list_init();
#include "vty.h"
#include "plist.h"
#include "sockopt.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_rpf.h"
* We need to create the VRF table for the pim mroute_socket
*/
if (pim->vrf_id != VRF_DEFAULT) {
- if (pimd_privs.change(ZPRIVS_RAISE))
- zlog_err(
- "pim_mroute_socket_enable: could not raise privs, %s",
- safe_strerror(errno));
+ frr_elevate_privs(&pimd_privs) {
- opt = pim->vrf->data.l.table_id;
- err = setsockopt(pim->mroute_socket, IPPROTO_IP, MRT_TABLE,
- &opt, opt_len);
- if (err) {
- zlog_warn(
- "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s",
- __FILE__, __PRETTY_FUNCTION__,
- pim->mroute_socket, opt, errno,
- safe_strerror(errno));
- return -1;
- }
+ opt = pim->vrf->data.l.table_id;
+ err = setsockopt(pim->mroute_socket, IPPROTO_IP,
+ MRT_TABLE,
+ &opt, opt_len);
+ if (err) {
+ zlog_warn(
+ "%s %s: failure: setsockopt(fd=%d,IPPROTO_IP, MRT_TABLE=%d): errno=%d: %s",
+ __FILE__, __PRETTY_FUNCTION__,
+ pim->mroute_socket, opt, errno,
+ safe_strerror(errno));
+ return -1;
+ }
- if (pimd_privs.change(ZPRIVS_LOWER))
- zlog_err(
- "pim_mroute_socket_enable: could not lower privs, %s",
- safe_strerror(errno));
+ }
}
opt = enable ? MRT_INIT : MRT_DONE;
{
int fd;
- if (pimd_privs.change(ZPRIVS_RAISE))
- zlog_err("pim_mroute_socket_enable: could not raise privs, %s",
- safe_strerror(errno));
+ frr_elevate_privs(&pimd_privs) {
- fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
+ fd = socket(AF_INET, SOCK_RAW, IPPROTO_IGMP);
- if (fd < 0) {
- zlog_warn("Could not create mroute socket: errno=%d: %s", errno,
- safe_strerror(errno));
- return -2;
- }
+ if (fd < 0) {
+ zlog_warn("Could not create mroute socket: errno=%d: %s",
+ errno,
+ safe_strerror(errno));
+ return -2;
+ }
#ifdef SO_BINDTODEVICE
- if (pim->vrf->vrf_id != VRF_DEFAULT
- && setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, pim->vrf->name,
- strlen(pim->vrf->name))) {
- zlog_warn("Could not setsockopt SO_BINDTODEVICE: %s",
- safe_strerror(errno));
- close(fd);
- return -3;
- }
+ if (pim->vrf->vrf_id != VRF_DEFAULT
+ && setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE,
+ pim->vrf->name, strlen(pim->vrf->name))) {
+ zlog_warn("Could not setsockopt SO_BINDTODEVICE: %s",
+ safe_strerror(errno));
+ close(fd);
+ return -3;
+ }
#endif
- if (pimd_privs.change(ZPRIVS_LOWER))
- zlog_err("pim_mroute_socket_enable: could not lower privs, %s",
- safe_strerror(errno));
+ }
pim->mroute_socket = fd;
if (pim_mroute_set(pim, 1)) {
#include <lib/thread.h>
#include <lib/vty.h>
#include <lib/plist.h>
+#include <lib/lib_errors.h>
#include "pimd.h"
#include "pim_cmd.h"
* the flow. Accounting for such cases requires lot of
* changes; perhaps
* address this in the next release? - XXX */
- zlog_err(
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
"MSDP sa %s SPT teardown is causing the local entry to be removed",
sa->sg_str);
return;
#include <lib/stream.h>
#include <lib/thread.h>
#include <lib/vty.h>
+#include <lib/lib_errors.h>
#include "pimd.h"
#include "pim_str.h"
+#include "pim_errors.h"
#include "pim_msdp.h"
#include "pim_msdp_packet.h"
/* If getsockopt is fail, this is fatal error. */
if (ret < 0) {
- zlog_err("can't get sockopt for nonblocking connect");
+ flog_err_sys(LIB_ERR_SOCKET,
+ "can't get sockopt for nonblocking connect");
pim_msdp_peer_reset_tcp_conn(mp, "connect-failed");
return;
}
if (prefix_len != 32) {
/* ignore SA update if the prefix length is not 32 */
- zlog_err("rxed sa update with invalid prefix length %d",
- prefix_len);
+ flog_err(PIM_ERR_MSDP_PACKET,
+ "rxed sa update with invalid prefix length %d",
+ prefix_len);
return;
}
if (PIM_DEBUG_MSDP_PACKETS) {
#include <lib/vty.h>
#include <lib/if.h>
#include <lib/vrf.h>
+#include <lib/lib_errors.h>
#include "pimd.h"
#include "pim_sock.h"
+#include "pim_errors.h"
#include "pim_msdp.h"
#include "pim_msdp_socket.h"
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));
+ flog_err_sys(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));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "Couldn't increase send buffer: %s\n",
+ safe_strerror(errno));
}
}
}
/* re-register accept thread */
accept_sock = THREAD_FD(thread);
if (accept_sock < 0) {
- zlog_err("accept_sock is negative value %d", accept_sock);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "accept_sock is negative value %d", accept_sock);
return -1;
}
pim->msdp.listener.thread = NULL;
/* 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));
+ flog_err_sys(LIB_ERR_SOCKET, "pim_msdp_sock_accept failed (%s)",
+ safe_strerror(errno));
return -1;
}
if (!mp || !PIM_MSDP_PEER_IS_LISTENER(mp)) {
++pim->msdp.rejected_accepts;
if (PIM_DEBUG_MSDP_EVENTS) {
- zlog_err("msdp peer connection refused from %s",
- sockunion2str(&su, buf, SU_ADDRSTRLEN));
+ flog_err(PIM_ERR_MSDP_PACKET,
+ "msdp peer connection refused from %s",
+ sockunion2str(&su, buf, SU_ADDRSTRLEN));
}
close(msdp_sock);
return -1;
* 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));
}
sock = socket(AF_INET, SOCK_STREAM, 0);
if (sock < 0) {
- zlog_err("socket: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "socket: %s",
+ safe_strerror(errno));
return sock;
}
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);
+ flog_err(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));
+ flog_err_sys(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));
- }
-
- /* 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));
+ frr_elevate_privs(&pimd_privs) {
+ /* bind to well known TCP port */
+ rc = bind(sock, (struct sockaddr *)&sin, socklen);
}
if (rc < 0) {
- zlog_err("pim_msdp_socket bind to port %d: %s",
- ntohs(sin.sin_port), safe_strerror(errno));
+ flog_err_sys(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));
+ flog_err_sys(LIB_ERR_SOCKET, "pim_msdp_socket listen: %s",
+ safe_strerror(errno));
close(sock);
return rc;
}
* 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);
}
/* 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));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "pim_msdp_socket socket failure: %s",
+ safe_strerror(errno));
return -1;
}
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);
+ flog_err(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));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: Unable to bind to socket: %s",
+ __PRETTY_FUNCTION__, safe_strerror(errno));
close(mp->fd);
mp->fd = -1;
return -1;
/* 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));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "pim_msdp_socket connect bind failure: %s",
+ safe_strerror(errno));
close(mp->fd);
mp->fd = -1;
return rc;
#include "if.h"
#include "vty.h"
#include "plist.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_neighbor.h"
if (neigh->prefix_list == addr_list) {
if (addr_list) {
- zlog_err(
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
"%s: internal error: trying to replace same prefix list=%p",
__PRETTY_FUNCTION__, (void *)addr_list);
}
#include "pim_assert.h"
#include "pim_msg.h"
#include "pim_register.h"
+#include "pim_errors.h"
static int on_pim_hello_send(struct thread *t);
static int pim_hello_send(struct interface *ifp, uint16_t holdtime);
delete_message);
if (!ifp->info) {
- zlog_err("%s: %s: but PIM not enabled on interface %s (!)",
- __PRETTY_FUNCTION__, delete_message, ifp->name);
+ flog_err(PIM_ERR_CONFIG,
+ "%s: %s: but PIM not enabled on interface %s (!)",
+ __PRETTY_FUNCTION__, delete_message, ifp->name);
return;
}
#include "plist.h"
#include "nexthop.h"
#include "table.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_vty.h"
hash_clean(pnc->upstream_hash, NULL);
hash_free(pnc->upstream_hash);
pnc->upstream_hash = NULL;
+ if (pnc->nexthop)
+ nexthops_free(pnc->nexthop);
XFREE(MTYPE_PIM_NEXTHOP_CACHE, pnc);
}
rp_info = XCALLOC(MTYPE_PIM_RP, sizeof(*rp_info));
if (!str2prefix("224.0.0.0/4", &rp_info->group)) {
- zlog_err("Unable to convert 224.0.0.0/4 to prefix");
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "Unable to convert 224.0.0.0/4 to prefix");
list_delete_and_null(&pim->rp_list);
route_table_finish(pim->rp_table);
XFREE(MTYPE_PIM_RP, rp_info);
rn = route_node_match(pim->rp_table, group);
if (!rn) {
- zlog_err(
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
"%s: BUG We should have found default group information\n",
__PRETTY_FUNCTION__);
return best;
rn = route_node_get(pim->rp_table, &rp_info->group);
if (rn) {
if (rn->info != rp_info)
- zlog_err("WTF matey");
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
+ "Expected rn->info to be equal to rp_info");
if (PIM_DEBUG_TRACE) {
char buf[PREFIX_STRLEN];
#include "if.h"
#include "vrf.h"
#include "sockopt.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_mroute.h"
{
int fd;
- if (pimd_privs.change(ZPRIVS_RAISE))
- zlog_err("pim_sockek_raw: could not raise privs, %s",
- safe_strerror(errno));
+ frr_elevate_privs(&pimd_privs) {
- fd = socket(AF_INET, SOCK_RAW, protocol);
+ 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));
+ }
if (fd < 0) {
zlog_warn("Could not create raw socket: errno=%d: %s", errno,
{
const int on = 1;
- if (pimd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs, %s", __PRETTY_FUNCTION__,
- safe_strerror(errno));
+ frr_elevate_privs(&pimd_privs) {
- 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));
+ 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));
- if (pimd_privs.change(ZPRIVS_LOWER))
- zlog_err("%s: could not lower privs, %s", __PRETTY_FUNCTION__,
- safe_strerror(errno));
+ }
}
/*
int ret = 0;
#ifdef SO_BINDTODEVICE
- if (pimd_privs.change(ZPRIVS_RAISE))
- zlog_err("%s: could not raise privs, %s", __PRETTY_FUNCTION__,
- safe_strerror(errno));
+ frr_elevate_privs(&pimd_privs) {
- ret = setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, ifp->name,
- strlen(ifp->name));
+ 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));
+ }
#endif
return ret;
fd, errno, safe_strerror(errno));
}
#else
- zlog_err(
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
"%s %s: Missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()",
__FILE__, __PRETTY_FUNCTION__);
close(fd);
sizeof(ifaddr_str)))
sprintf(ifaddr_str, "<ifaddr?>");
- zlog_err(
+ flog_err(
+ 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;
#include <lib/vty.h>
#include <lib/vrf.h>
#include <lib/plist.h>
+#include <lib/lib_errors.h>
#include "pimd.h"
#include "pim_ssm.h"
if (first) {
if (!str2prefix(PIM_SSM_STANDARD_RANGE, &group_ssm))
- zlog_err("%s: Failure to Read Group Address: %s",
- __PRETTY_FUNCTION__, PIM_SSM_STANDARD_RANGE);
+ flog_err(LIB_ERR_DEVELOPMENT,
+ "%s: Failure to Read Group Address: %s",
+ __PRETTY_FUNCTION__, PIM_SSM_STANDARD_RANGE);
first = 0;
}
#include "memory.h"
#include "sockopt.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_ssmpingd.h"
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));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: could not create socket: errno=%d: %s",
+ __PRETTY_FUNCTION__, errno, safe_strerror(errno));
return -1;
}
safe_strerror(errno));
}
#else
- zlog_err(
+ flog_err(
+ LIB_ERR_DEVELOPMENT,
"%s %s: missing IP_PKTINFO and IP_RECVDSTADDR: unable to get dst addr from recvmsg()",
__FILE__, __PRETTY_FUNCTION__);
close(fd);
#include "log.h"
#include "thread.h"
+#include "lib_errors.h"
#include "pim_time.h"
result = gettimeofday(tv, 0);
if (result) {
- zlog_err("%s: gettimeofday() failure: errno=%d: %s",
- __PRETTY_FUNCTION__, errno, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: gettimeofday() failure: errno=%d: %s",
+ __PRETTY_FUNCTION__, errno, safe_strerror(errno));
}
return result;
struct timeval now_tv;
if (gettime_monotonic(&now_tv)) {
- zlog_err("%s: gettime_monotonic() failure: errno=%d: %s",
- __PRETTY_FUNCTION__, errno, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: gettime_monotonic() failure: errno=%d: %s",
+ __PRETTY_FUNCTION__, errno, safe_strerror(errno));
return -1;
}
int64_t now_dsec;
if (gettime_monotonic(&now_tv)) {
- zlog_err("%s: gettime_monotonic() failure: errno=%d: %s",
- __PRETTY_FUNCTION__, errno, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: gettime_monotonic() failure: errno=%d: %s",
+ __PRETTY_FUNCTION__, errno, safe_strerror(errno));
return -1;
}
int64_t now_dsec;
if (gettime_monotonic(&now_tv)) {
- zlog_err("%s: gettime_monotonic() failure: errno=%d: %s",
- __PRETTY_FUNCTION__, errno, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: gettime_monotonic() failure: errno=%d: %s",
+ __PRETTY_FUNCTION__, errno, safe_strerror(errno));
return -1;
}
{
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);
}
#include "thread.h"
#include "prefix.h"
#include "vty.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_iface.h"
{
zlookup = zclient_new_notify(master, &zclient_options_default);
if (!zlookup) {
- zlog_err("%s: zclient_new() failure", __PRETTY_FUNCTION__);
+ flog_err(LIB_ERR_ZAPI_SOCKET, "%s: zclient_new() failure",
+ __PRETTY_FUNCTION__);
return;
}
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__);
+ flog_err(LIB_ERR_ZAPI_MISSMATCH,
+ "%s: zclient_read_header() failed",
+ __PRETTY_FUNCTION__);
zclient_lookup_failed(zlookup);
return -1;
}
/* Check socket. */
if (zlookup->sock < 0) {
- zlog_err("%s: zclient lookup socket is not connected",
- __PRETTY_FUNCTION__);
+ flog_err(LIB_ERR_ZAPI_SOCKET,
+ "%s: zclient lookup socket is not connected",
+ __PRETTY_FUNCTION__);
zclient_lookup_failed(zlookup);
return -1;
}
if (pim->vrf->vrf_id == VRF_UNKNOWN) {
- zlog_err(
+ zlog_notice(
"%s: VRF: %s does not fully exist yet, delaying lookup",
__PRETTY_FUNCTION__, pim->vrf->name);
return -1;
ret = writen(zlookup->sock, s->data, stream_get_endp(s));
if (ret < 0) {
- zlog_err(
+ flog_err(
+ 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__);
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s: connection closed on zclient lookup socket",
+ __PRETTY_FUNCTION__);
zclient_lookup_failed(zlookup);
return -3;
}
count = stream_get_endp(s);
ret = writen(zlookup->sock, s->data, count);
if (ret <= 0) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"%s: writen() failure: %d writing to zclient lookup socket",
__PRETTY_FUNCTION__, errno);
return -1;
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__);
+ flog_err(LIB_ERR_ZAPI_MISSMATCH,
+ "%s: zclient_read_header() failed",
+ __PRETTY_FUNCTION__);
zclient_lookup_failed(zlookup);
return -1;
}
more.src = c_oil->oil.mfcc_origin;
more.grp = c_oil->oil.mfcc_mcastgrp;
- zlog_err(
+ flog_err(
+ LIB_ERR_ZAPI_MISSMATCH,
"%s: Received wrong %s(%s) information requested",
__PRETTY_FUNCTION__, pim_str_sg_dump(&more),
c_oil->pim->vrf->name);
#include "hash.h"
#include "jhash.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "pimd.h"
#include "pim_cmd.h"
void pim_init()
{
if (!inet_aton(PIM_ALL_PIM_ROUTERS, &qpim_all_pim_routers_addr)) {
- zlog_err(
+ flog_err(
+ 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));
pimd/pim_bfd.c \
pimd/pim_br.c \
pimd/pim_cmd.c \
+ pimd/pim_errors.c \
pimd/pim_hello.c \
pimd/pim_iface.c \
pimd/pim_ifchannel.c \
pimd/pim_bfd.h \
pimd/pim_br.h \
pimd/pim_cmd.h \
+ pimd/pim_errors.h \
pimd/pim_hello.h \
pimd/pim_iface.h \
pimd/pim_ifchannel.h \
--- /dev/null
+/*
+ * RIP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "rip_errors.h"
+
+static struct log_ref ferr_rip_err[] = {
+ {
+ .code = RIP_ERR_PACKET,
+ .title = "RIP Packet Error",
+ .description = "RIP has detected a packet encode/decode issue",
+ .suggestion = "Gather log files from both sides and open a Issue"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+
+void rip_error_init(void)
+{
+ log_ref_add(ferr_rip_err);
+}
--- /dev/null
+/*
+ * RIP-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __RIP_ERRORS_H__
+#define __RIP_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum rip_log_refs {
+ RIP_ERR_PACKET = RIP_FERR_START,
+ RIP_ERR_CONFIG,
+};
+
+extern void rip_error_init(void);
+
+#endif
#include "filter.h"
#include "sockopt.h"
#include "privs.h"
+#include "lib_errors.h"
#include "zebra/connected.h"
/* Join to multicast group. */
if (rip_multicast_join(ifp, rip->sock) < 0) {
- zlog_err("multicast join failed, interface %s not running",
- ifp->name);
+ flog_err_sys(LIB_ERR_SOCKET,
+ "multicast join failed, interface %s not running",
+ ifp->name);
return 0;
}
#include "libfrr.h"
#include "ripd/ripd.h"
+#include "ripd/rip_errors.h"
/* ripd options. */
#if CONFDATE > 20190521
master = frr_init();
/* Library initialization. */
+ rip_error_init();
keychain_init();
vrf_init(NULL, NULL, NULL, NULL);
#include "md5.h"
#include "keychain.h"
#include "privs.h"
+#include "lib_errors.h"
#include "ripd/ripd.h"
#include "ripd/rip_debug.h"
+#include "ripd/rip_errors.h"
DEFINE_QOBJ_TYPE(rip)
/* Check packet length. */
if (len < (RIP_HEADER_SIZE + RIP_RTE_SIZE)) {
- zlog_err(
- "rip_auth_md5_set(): packet length %ld is less than minimum length.",
- len);
+ flog_err(RIP_ERR_PACKET,
+ "rip_auth_md5_set(): packet length %ld is less than minimum length.",
+ len);
return;
}
/* Make datagram socket. */
sock = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP);
if (sock < 0) {
- zlog_err("Cannot create UDP socket: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "Cannot create UDP socket: %s",
+ safe_strerror(errno));
exit(1);
}
setsockopt_ipv4_tos(sock, IPTOS_PREC_INTERNETCONTROL);
#endif
- if (ripd_privs.change(ZPRIVS_RAISE))
- zlog_err("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_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));
-
- close(sock);
- return ret;
+ frr_elevate_privs(&ripd_privs) {
+ setsockopt_so_recvbuf(sock, RIP_UDP_RCV_BUF);
+ if ((ret = bind(sock, (struct sockaddr *)&addr, sizeof(addr)))
+ < 0) {
+ 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(errno));
+
+ close(sock);
+ return ret;
+ }
}
- if (ripd_privs.change(ZPRIVS_LOWER))
- zlog_err("rip_create_socket: could not lower privs");
-
return sock;
}
ripd_librip_a_SOURCES = \
ripd/rip_debug.c \
+ ripd/rip_errors.c \
ripd/rip_interface.c \
ripd/rip_memory.c \
ripd/rip_offset.c \
noinst_HEADERS += \
ripd/rip_debug.h \
+ ripd/rip_errors.h \
ripd/rip_interface.h \
ripd/rip_memory.h \
ripd/ripd.h \
#include "thread.h"
#include "privs.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "ripngd/ripngd.h"
#include "ripngd/ripng_debug.h"
* While this is bogus, privs are available and easy to use
* for this call as a workaround.
*/
- if (ripngd_privs.change(ZPRIVS_RAISE))
- zlog_err("ripng_multicast_join: could not raise privs");
+ frr_elevate_privs(&ripngd_privs) {
- ret = setsockopt(ripng->sock, IPPROTO_IPV6, IPV6_JOIN_GROUP,
- (char *)&mreq, sizeof(mreq));
- save_errno = errno;
+ 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");
+ }
if (ret < 0 && save_errno == EADDRINUSE) {
/*
/* Join to multicast group. */
if (ripng_multicast_join(ifp) < 0) {
- zlog_err("multicast join failed, interface %s not running",
- ifp->name);
+ flog_err_sys(LIB_ERR_SOCKET,
+ "multicast join failed, interface %s not running",
+ ifp->name);
return 0;
}
#include "routemap.h"
#include "if_rmap.h"
#include "privs.h"
+#include "lib_errors.h"
#include "ripngd/ripngd.h"
#include "ripngd/ripng_route.h"
sock = socket(AF_INET6, SOCK_DGRAM, 0);
if (sock < 0) {
- zlog_err("Can't make ripng socket");
+ flog_err_sys(LIB_ERR_SOCKET, "Can't make ripng socket");
return sock;
}
#endif /* SIN6_LEN */
ripaddr.sin6_port = htons(RIPNG_PORT_DEFAULT);
- if (ripngd_privs.change(ZPRIVS_RAISE))
- zlog_err("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));
- if (ripngd_privs.change(ZPRIVS_LOWER))
- zlog_err("ripng_make_socket: could not lower privs");
- goto error;
+ frr_elevate_privs(&ripngd_privs) {
+ ret = bind(sock, (struct sockaddr *)&ripaddr, sizeof(ripaddr));
+ if (ret < 0) {
+ zlog_err("Can't bind ripng socket: %s.",
+ safe_strerror(errno));
+ goto error;
+ }
}
- if (ripngd_privs.change(ZPRIVS_LOWER))
- zlog_err("ripng_make_socket: could not lower privs");
return sock;
error:
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));
+ flog_err_sys(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));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "RIPng send fail on %s: %s", ifp->name,
+ safe_strerror(errno));
}
return ret;
((test_privs.current_state() == ZPRIVS_RAISED) ? "Raised" : "Lowered")
printf("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_RAISE);
-
- printf("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_LOWER);
+ frr_elevate_privs(&test_privs) {
+ printf("%s\n", PRIV_STATE());
+ }
printf("%s\n", PRIV_STATE());
zprivs_get_ids(&ids);
/* but these should continue to work... */
printf("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_RAISE);
-
- printf("%s\n", PRIV_STATE());
- test_privs.change(ZPRIVS_LOWER);
+ frr_elevate_privs(&test_privs) {
+ printf("%s\n", PRIV_STATE());
+ }
printf("%s\n", PRIV_STATE());
zprivs_get_ids(&ids);
--- /dev/null
+@@
+identifier change;
+identifier end;
+expression E, f, g;
+iterator name frr_elevate_privs;
+@@
+
+- if (E.change(ZPRIVS_RAISE))
+- f;
++ frr_elevate_privs(&E) {
+ <+...
+- goto end;
++ break;
+ ...+>
+- end:
+- if (E.change(ZPRIVS_LOWER))
+- g;
++ }
+
+@@
+identifier change, errno, safe_strerror, exit;
+expression E, f1, f2, f3, ret, fn;
+iterator name frr_elevate_privs;
+@@
+
+ if (E.change(ZPRIVS_RAISE))
+ f1;
+ ...
+ if (...) {
+- int save_errno = errno;
+ ...
+- if (E.change(ZPRIVS_LOWER))
+- f2;
+ ...
+- safe_strerror(save_errno)
++ safe_strerror(errno)
+ ...
+ \( return ret; \| exit(ret); \)
+ }
+ ...
+ if (E.change(ZPRIVS_LOWER))
+ f3;
+
+@@
+identifier change;
+expression E, f1, f2, f3, ret;
+iterator name frr_elevate_privs;
+@@
+
+ if (E.change(ZPRIVS_RAISE))
+ f1;
+ ...
+ if (...) {
+ ...
+- if (E.change(ZPRIVS_LOWER))
+- f2;
+ ...
+ return ret;
+ }
+ ...
+ if (E.change(ZPRIVS_LOWER))
+ f3;
+
+@@
+identifier change;
+expression E, f, g;
+iterator name frr_elevate_privs;
+@@
+
+- if (E.change(ZPRIVS_RAISE))
+- f;
++ frr_elevate_privs(&E) {
+ ...
+- if (E.change(ZPRIVS_LOWER))
+- g;
++ }
#include "libfrr.h"
#include "command_graph.h"
#include "frrstr.h"
+#include "json.h"
DEFINE_MTYPE_STATIC(MVTYSH, VTYSH_CMD, "Vtysh cmd copy")
"Hashtable statistics for %s:\n");
}
+DEFUN (vtysh_show_error_code,
+ vtysh_show_error_code_cmd,
+ "show error <(1-4294967296)|all> [json]",
+ SHOW_STR
+ "Information on errors\n"
+ "Error code to get info about\n"
+ "Information on all errors\n"
+ JSON_STR)
+{
+ char *fcmd = argv_concat(argv, argc, 0);
+ char cmd[256];
+ int rv;
+
+ snprintf(cmd, sizeof(cmd), "do %s", fcmd);
+
+ /* FIXME: Needs to determine which daemon to send to via code ranges */
+ rv = show_per_daemon(cmd, "");
+
+ XFREE(MTYPE_TMP, fcmd);
+ return rv;
+}
+
/* Memory */
DEFUN (vtysh_show_memory,
vtysh_show_memory_cmd,
/* debugging */
install_element(VIEW_NODE, &vtysh_show_debugging_cmd);
+ install_element(VIEW_NODE, &vtysh_show_error_code_cmd);
install_element(VIEW_NODE, &vtysh_show_debugging_hashtable_cmd);
install_element(ENABLE_NODE, &vtysh_debug_all_cmd);
install_element(CONFIG_NODE, &vtysh_debug_all_cmd);
noinst_HEADERS += \
watchfrr/watchfrr.h \
+ watchfrr/watchfrr_errors.h \
# end
watchfrr_watchfrr_LDADD = lib/libfrr.la @LIBCAP@
watchfrr_watchfrr_SOURCES = \
watchfrr/watchfrr.c \
+ watchfrr/watchfrr_errors.c \
watchfrr/watchfrr_vty.c \
# end
#include "command.h"
#include "memory_vty.h"
#include "libfrr.h"
+#include "lib_errors.h"
#include <getopt.h>
#include <sys/un.h>
#include <systemd.h>
#include "watchfrr.h"
+#include "watchfrr_errors.h"
#ifndef MIN
#define MIN(X,Y) (((X) <= (Y)) ? (X) : (Y))
switch (child = fork()) {
case -1:
- zlog_err("fork failed, cannot run command [%s]: %s", shell_cmd,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "fork failed, cannot run command [%s]: %s",
+ shell_cmd, safe_strerror(errno));
return -1;
case 0:
/* Child process. */
char dashc[] = "-c";
char *const argv[4] = {shell, dashc, shell_cmd, NULL};
execv("/bin/sh", argv);
- zlog_err("execv(/bin/sh -c '%s') failed: %s", shell_cmd,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "execv(/bin/sh -c '%s') failed: %s",
+ shell_cmd, safe_strerror(errno));
_exit(127);
}
default:
/* Parent process: we will reap the child later. */
- zlog_err("Forked background command [pid %d]: %s", (int)child,
- shell_cmd);
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "Forked background command [pid %d]: %s",
+ (int)child, shell_cmd);
return child;
}
}
switch (child = waitpid(-1, &status, WNOHANG)) {
case -1:
- zlog_err("waitpid failed: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "waitpid failed: %s",
+ safe_strerror(errno));
return;
case 0:
zlog_warn("SIGCHLD received, but waitpid did not reap a child");
* completed. */
gettimeofday(&restart->time, NULL);
} else {
- zlog_err(
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
"waitpid returned status for an unknown child process %d",
(int)child);
name = "(unknown)";
zlog_debug("%s %s process %d exited normally", what,
name, (int)child);
} else
- zlog_err("cannot interpret %s %s process %d wait status 0x%x",
- what, name, (int)child, status);
+ flog_err_sys(
+ LIB_ERR_SYSTEM_CALL,
+ "cannot interpret %s %s process %d wait status 0x%x",
+ what, name, (int)child, status);
phase_check();
}
dmn->t_wakeup = NULL;
if (try_connect(dmn) < 0) {
SET_WAKEUP_DOWN(dmn);
- zlog_err("%s state -> down : initial connection attempt failed",
- dmn->name);
+ flog_err(WATCHFRR_ERR_CONNECTION,
+ "%s state -> down : initial connection attempt failed",
+ dmn->name);
dmn->state = DAEMON_DOWN;
}
return 0;
static void daemon_down(struct daemon *dmn, const char *why)
{
if (IS_UP(dmn) || (dmn->state == DAEMON_INIT))
- zlog_err("%s state -> down : %s", dmn->name, why);
+ flog_err(WATCHFRR_ERR_CONNECTION,
+ "%s state -> down : %s", dmn->name, why);
else if (gs.loglevel > LOG_DEBUG)
zlog_debug("%s still down : %s", dmn->name, why);
if (IS_UP(dmn))
of creating a socket. */
if (access(addr.sun_path, W_OK) < 0) {
if (errno != ENOENT)
- zlog_err("%s: access to socket %s denied: %s",
- dmn->name, addr.sun_path,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s: access to socket %s denied: %s",
+ dmn->name, addr.sun_path,
+ safe_strerror(errno));
return -1;
}
if ((sock = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) {
- zlog_err("%s(%s): cannot make socket: %s", __func__,
- addr.sun_path, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s(%s): cannot make socket: %s",
+ __func__, addr.sun_path, safe_strerror(errno));
return -1;
}
if (set_nonblocking(sock) < 0 || set_cloexec(sock) < 0) {
- zlog_err("%s(%s): set_nonblocking/cloexec(%d) failed", __func__,
- addr.sun_path, sock);
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "%s(%s): set_nonblocking/cloexec(%d) failed",
+ __func__, addr.sun_path, sock);
close(sock);
return -1;
}
static int phase_hanging(struct thread *t_hanging)
{
gs.t_phase_hanging = NULL;
- zlog_err("Phase [%s] hanging for %ld seconds, aborting phased restart",
- phase_str[gs.phase], PHASE_TIMEOUT);
+ flog_err(WATCHFRR_ERR_CONNECTION,
+ "Phase [%s] hanging for %ld seconds, aborting phased restart",
+ phase_str[gs.phase], PHASE_TIMEOUT);
gs.phase = PHASE_NONE;
return 0;
}
dmn->t_wakeup = NULL;
if (dmn->state != DAEMON_UNRESPONSIVE)
- zlog_err(
- "%s: no longer unresponsive (now %s), "
- "wakeup should have been cancelled!",
- dmn->name, state_str[dmn->state]);
+ flog_err(WATCHFRR_ERR_CONNECTION,
+ "%s: no longer unresponsive (now %s), "
+ "wakeup should have been cancelled!",
+ dmn->name, state_str[dmn->state]);
else {
SET_WAKEUP_UNRESPONSIVE(dmn);
try_restart(dmn);
dmn->t_wakeup = NULL;
dmn->state = DAEMON_UNRESPONSIVE;
- zlog_err(
- "%s state -> unresponsive : no response yet to ping "
- "sent %ld seconds ago",
- dmn->name, gs.timeout);
+ flog_err(WATCHFRR_ERR_CONNECTION,
+ "%s state -> unresponsive : no response yet to ping "
+ "sent %ld seconds ago",
+ dmn->name, gs.timeout);
SET_WAKEUP_UNRESPONSIVE(dmn);
try_restart(dmn);
return 0;
gs.restart.interval = gs.min_restart_interval;
master = frr_init();
+ watchfrr_error_init();
zlog_set_level(ZLOG_DEST_MONITOR, ZLOG_DISABLED);
if (watchfrr_di.daemon_mode) {
--- /dev/null
+/*
+ * Watchfrr-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 "watchfrr_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_watchfrr_err[] = {
+ {
+ .code = WATCHFRR_ERR_CONNECTION,
+ .title = "WATCHFRR Connection Error",
+ .description = "WATCHFRR has detected a connectivity issue with one of the FRR daemons",
+ .suggestion = "Ensure that FRR is still running and if not please open an Issue"
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+void watchfrr_error_init(void)
+{
+ log_ref_add(ferr_watchfrr_err);
+}
--- /dev/null
+/*
+ * Watchfrr-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Donald Sharp
+ *
+ * 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 __WATCHFRR_ERRORS_H__
+#define __WATCHFRR_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum watchfrr_log_refs {
+ WATCHFRR_ERR_CONNECTION = WATCHFRR_FERR_START,
+};
+
+extern void watchfrr_error_init(void);
+
+#endif
#ifndef _ZEBRA_CONNECTED_H
#define _ZEBRA_CONNECTED_H
+#include <zebra.h>
+#include <stdint.h>
+
+#include "lib/if.h"
+#include "lib/prefix.h"
+
extern struct connected *connected_check(struct interface *ifp,
union prefixconstptr p);
extern struct connected *connected_check_ptp(struct interface *ifp,
#ifndef _ZEBRA_DEBUG_H
#define _ZEBRA_DEBUG_H
+#include "lib/vty.h"
+
/* Debug flags. */
#define ZEBRA_DEBUG_EVENT 0x01
#include "log.h"
#include "vrf.h"
#include "vty.h"
+#include "lib_errors.h"
#include "zebra/interface.h"
#include "zebra/rib.h"
ret = getifaddrs(&ifap);
if (ret != 0) {
- zlog_err("getifaddrs(): %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "getifaddrs(): %s",
+ safe_strerror(errno));
return -1;
}
for (ifapfree = ifap; ifap; ifap = ifap->ifa_next) {
if (ifap->ifa_addr == NULL) {
- zlog_err(
+ flog_err(
+ LIB_ERR_INTERFACE,
"%s: nonsensical ifaddr with NULL ifa_addr, ifname %s",
__func__,
(ifap->ifa_name ? ifap->ifa_name : "(null)"));
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);
+ flog_err(LIB_ERR_INTERFACE,
+ "if_getaddrs(): Can't lookup interface %s\n",
+ ifap->ifa_name);
continue;
}
#include "privs.h"
#include "vrf.h"
#include "vty.h"
+#include "lib_errors.h"
#include "zebra/interface.h"
#include "zebra/ioctl_solaris.h"
size_t needed, lastneeded = 0;
char *buf = NULL;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
+ frr_elevate_privs(&zserv_privs) {
+ sock = socket(af, SOCK_DGRAM, 0);
+ }
- sock = socket(af, SOCK_DGRAM, 0);
if (sock < 0) {
zlog_warn("Can't make %s socket stream: %s",
(af == AF_INET ? "AF_INET" : "AF_INET6"),
safe_strerror(errno));
-
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
-
return -1;
}
-calculate_lifc_len: /* must hold privileges to enter here */
- lifn.lifn_family = af;
- lifn.lifn_flags = LIFC_NOXMIT; /* we want NOXMIT interfaces too */
- ret = ioctl(sock, SIOCGLIFNUM, &lifn);
- save_errno = errno;
+calculate_lifc_len:
+ frr_elevate_privs(&zserv_privs) {
+ lifn.lifn_family = af;
+ lifn.lifn_flags = LIFC_NOXMIT;
+ /* we want NOXMIT interfaces too */
+ ret = ioctl(sock, SIOCGLIFNUM, &lifn);
+ save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ }
if (ret < 0) {
zlog_warn("interface_list_ioctl: SIOCGLIFNUM failed %s",
lifconf.lifc_len = needed;
lifconf.lifc_buf = buf;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
-
- ret = ioctl(sock, SIOCGLIFCONF, &lifconf);
+ frr_elevate_privs(&zserv_privs) {
+ ret = ioctl(sock, SIOCGLIFCONF, &lifconf);
+ }
if (ret < 0) {
if (errno == EINVAL)
- goto calculate_lifc_len; /* deliberately hold privileges
- */
+ goto calculate_lifc_len;
zlog_warn("SIOCGLIFCONF: %s", safe_strerror(errno));
-
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
-
goto end;
}
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
-
/* Allocate interface. */
lifreq = lifconf.lifc_req;
#include "vrf.h"
#include "vrf_int.h"
#include "mpls.h"
+#include "lib_errors.h"
#include "vty.h"
#include "zebra/zserv.h"
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",
+ flog_err(
+ LIB_ERR_INTERFACE,
+ "Netlink is setting interface %s ifindex to reserved internal value %u",
ifp->name, ifi_index);
else {
if (IS_ZEBRA_DEBUG_KERNEL)
"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!",
+ flog_err(
+ 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);
}
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);
+ flog_err(LIB_ERR_INTERFACE, "VRF %s id %u not created",
+ name, ifi->ifi_index);
return;
}
/* Enable the created VRF. */
if (!vrf_enable(vrf)) {
- zlog_err("Failed to enable VRF %s id %u", name,
- ifi->ifi_index);
+ flog_err(LIB_ERR_INTERFACE,
+ "Failed to enable VRF %s id %u", name,
+ ifi->ifi_index);
return;
}
ifdata.ifr_data = (caddr_t)&ecmd;
/* use ioctl to get IP address of an interface */
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP, interface->vrf_id,
- NULL);
- if (sd < 0) {
- if (IS_ZEBRA_DEBUG_KERNEL)
- zlog_debug("Failure to read interface %s speed: %d %s",
- ifname, errno, safe_strerror(errno));
- return 0;
- }
+ frr_elevate_privs(&zserv_privs) {
+ sd = vrf_socket(PF_INET, SOCK_DGRAM, IPPROTO_IP,
+ interface->vrf_id,
+ NULL);
+ if (sd < 0) {
+ if (IS_ZEBRA_DEBUG_KERNEL)
+ zlog_debug("Failure to read interface %s speed: %d %s",
+ ifname, errno, safe_strerror(errno));
+ return 0;
+ }
/* Get the current link state for the interface */
- rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL, (char *)&ifdata);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ rc = vrf_ioctl(interface->vrf_id, sd, SIOCETHTOOL,
+ (char *)&ifdata);
+ }
if (rc < 0) {
if (IS_ZEBRA_DEBUG_KERNEL)
zlog_debug(
ifp = if_lookup_by_index_per_ns(zns, ifa->ifa_index);
if (ifp == NULL) {
- zlog_err(
+ flog_err(
+ LIB_ERR_INTERFACE,
"netlink_interface_addr can't find interface by index %d",
ifa->ifa_index);
return -1;
#include <zebra.h>
#include "if.h"
+#include "lib_errors.h"
#include "vty.h"
#include "sockunion.h"
#include "prefix.h"
struct zebra_if *zif;
if (if_is_up(ifp)) {
- zlog_err(
+ flog_err(
+ LIB_ERR_INTERFACE,
"interface %s vrf %u index %d is still up while being deleted.",
ifp->name, ifp->vrf_id, ifp->ifindex);
return;
#include "ioctl.h"
#include "log.h"
#include "privs.h"
+#include "lib_errors.h"
#include "vty.h"
#include "zebra/rib.h"
int ret;
int err = 0;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- int save_errno = errno;
-
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_err("Cannot create UDP socket: %s",
- safe_strerror(save_errno));
- exit(1);
+ frr_elevate_privs(&zserv_privs) {
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0) {
+ zlog_err("Cannot create UDP socket: %s",
+ safe_strerror(errno));
+ exit(1);
+ }
+ if ((ret = ioctl(sock, request, buffer)) < 0)
+ err = errno;
}
- if ((ret = ioctl(sock, request, buffer)) < 0)
- err = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
close(sock);
if (ret < 0) {
int ret;
int err = 0;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- sock = vrf_socket(AF_INET, SOCK_DGRAM, 0, vrf_id, NULL);
- if (sock < 0) {
- int save_errno = errno;
-
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_err("Cannot create UDP socket: %s",
- safe_strerror(save_errno));
- exit(1);
+ frr_elevate_privs(&zserv_privs) {
+ sock = vrf_socket(AF_INET, SOCK_DGRAM, 0, vrf_id, NULL);
+ if (sock < 0) {
+ zlog_err("Cannot create UDP socket: %s",
+ safe_strerror(errno));
+ exit(1);
+ }
+ ret = vrf_ioctl(vrf_id, sock, request, buffer);
+ if (ret < 0)
+ err = errno;
}
- ret = vrf_ioctl(vrf_id, sock, request, buffer);
- if (ret < 0)
- err = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
close(sock);
if (ret < 0) {
int ret;
int err = 0;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- sock = socket(AF_INET6, SOCK_DGRAM, 0);
- if (sock < 0) {
- int save_errno = errno;
-
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_err("Cannot create IPv6 datagram socket: %s",
- safe_strerror(save_errno));
- exit(1);
- }
+ frr_elevate_privs(&zserv_privs) {
+ sock = socket(AF_INET6, SOCK_DGRAM, 0);
+ if (sock < 0) {
+ zlog_err("Cannot create IPv6 datagram socket: %s",
+ safe_strerror(errno));
+ exit(1);
+ }
- if ((ret = ioctl(sock, request, buffer)) < 0)
- err = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ if ((ret = ioctl(sock, request, buffer)) < 0)
+ err = errno;
+ }
close(sock);
if (ret < 0) {
ret = vrf_if_ioctl(SIOCGIFFLAGS, (caddr_t)&ifreq, ifp->vrf_id);
if (ret < 0) {
- zlog_err("vrf_if_ioctl(SIOCGIFFLAGS) failed: %s",
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "vrf_if_ioctl(SIOCGIFFLAGS) failed: %s",
+ safe_strerror(errno));
return;
}
#ifdef HAVE_BSD_LINK_DETECT /* Detect BSD link-state at start-up */
/* Seems not all interfaces implement this ioctl */
if (if_ioctl(SIOCGIFMEDIA, (caddr_t)&ifmr) < 0)
- zlog_err("if_ioctl(SIOCGIFMEDIA) failed: %s",
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "if_ioctl(SIOCGIFMEDIA) failed: %s",
+ safe_strerror(errno));
else if (ifmr.ifm_status & IFM_AVALID) /* Link state is valid */
{
if (ifmr.ifm_status & IFM_ACTIVE)
#include "privs.h"
#include "vty.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "zebra/rib.h"
#include "zebra/rt.h"
int ret;
int err;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
-
- sock = socket(AF_INET, SOCK_DGRAM, 0);
- if (sock < 0) {
- int save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_err("Cannot create UDP socket: %s",
- safe_strerror(save_errno));
- exit(1);
- }
+ frr_elevate_privs(&zserv_privs) {
+
+ sock = socket(AF_INET, SOCK_DGRAM, 0);
+ if (sock < 0) {
+ zlog_err("Cannot create UDP socket: %s",
+ safe_strerror(errno));
+ exit(1);
+ }
- if ((ret = ioctl(sock, request, buffer)) < 0)
- err = errno;
+ if ((ret = ioctl(sock, request, buffer)) < 0)
+ err = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ }
close(sock);
int ret;
int err;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
-
- sock = socket(AF_INET6, SOCK_DGRAM, 0);
- if (sock < 0) {
- int save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_err("Cannot create IPv6 datagram socket: %s",
- safe_strerror(save_errno));
- exit(1);
- }
+ frr_elevate_privs(&zserv_privs) {
+
+ sock = socket(AF_INET6, SOCK_DGRAM, 0);
+ if (sock < 0) {
+ zlog_err("Cannot create IPv6 datagram socket: %s",
+ safe_strerror(errno));
+ exit(1);
+ }
- if ((ret = ioctl(sock, request, buffer)) < 0)
- err = errno;
+ if ((ret = ioctl(sock, request, buffer)) < 0)
+ err = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ }
close(sock);
#include "log.h"
#include "privs.h"
+#include "lib_errors.h"
#include "zebra/ipforward.h"
{
FILE *fp;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges, %s", safe_strerror(errno));
+ frr_elevate_privs(&zserv_privs) {
- fp = fopen(proc_ipv4_forwarding, "w");
+ fp = fopen(proc_ipv4_forwarding, "w");
- if (fp == NULL) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s",
- safe_strerror(errno));
- return -1;
- }
+ if (fp == NULL) {
+ return -1;
+ }
- fprintf(fp, "1\n");
+ fprintf(fp, "1\n");
- fclose(fp);
+ fclose(fp);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s", safe_strerror(errno));
+ }
return ipforward();
}
{
FILE *fp;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges, %s", safe_strerror(errno));
+ frr_elevate_privs(&zserv_privs) {
- fp = fopen(proc_ipv4_forwarding, "w");
+ fp = fopen(proc_ipv4_forwarding, "w");
- if (fp == NULL) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s",
- safe_strerror(errno));
- return -1;
- }
+ if (fp == NULL) {
+ return -1;
+ }
- fprintf(fp, "0\n");
+ fprintf(fp, "0\n");
- fclose(fp);
+ fclose(fp);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s", safe_strerror(errno));
+ }
return ipforward();
}
{
FILE *fp;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges, %s", safe_strerror(errno));
+ frr_elevate_privs(&zserv_privs) {
- fp = fopen(proc_ipv6_forwarding, "w");
+ fp = fopen(proc_ipv6_forwarding, "w");
- if (fp == NULL) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s",
- safe_strerror(errno));
- return -1;
- }
+ if (fp == NULL) {
+ return -1;
+ }
- fprintf(fp, "1\n");
+ fprintf(fp, "1\n");
- fclose(fp);
+ fclose(fp);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s", safe_strerror(errno));
+ }
return ipforward_ipv6();
}
{
FILE *fp;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges, %s", safe_strerror(errno));
+ frr_elevate_privs(&zserv_privs) {
- fp = fopen(proc_ipv6_forwarding, "w");
+ fp = fopen(proc_ipv6_forwarding, "w");
- if (fp == NULL) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s",
- safe_strerror(errno));
- return -1;
- }
+ if (fp == NULL) {
+ return -1;
+ }
- fprintf(fp, "0\n");
+ fprintf(fp, "0\n");
- fclose(fp);
+ fclose(fp);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges, %s", safe_strerror(errno));
+ }
return ipforward_ipv6();
}
#include "log.h"
#include "prefix.h"
+#include "lib_errors.h"
#include "privs.h"
#include "zebra/ipforward.h"
else if (cmd == ND_GET)
snprintf(nd_buf, ND_BUFFER_SIZE, "%s", parameter);
else {
- zlog_err(
- "internal error - inappropriate command given to "
- "solaris_nd()%s:%d",
- __FILE__, __LINE__);
+ flog_err_sys(LIB_ERR_SYSTEM_CALL,
+ "internal error - inappropriate command given to "
+ "solaris_nd()%s:%d",
+ __FILE__, __LINE__);
return -1;
}
strioctl.ic_len = ND_BUFFER_SIZE;
strioctl.ic_dp = nd_buf;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("solaris_nd: Can't raise privileges");
- if ((fd = open(device, O_RDWR)) < 0) {
- zlog_warn("failed to open device %s - %s", device,
- safe_strerror(errno));
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("solaris_nd: Can't lower privileges");
- return -1;
- }
- if (ioctl(fd, I_STR, &strioctl) < 0) {
- int save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("solaris_nd: Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ if ((fd = open(device, O_RDWR)) < 0) {
+ zlog_warn("failed to open device %s - %s", device,
+ safe_strerror(errno));
+ return -1;
+ }
+ if (ioctl(fd, I_STR, &strioctl) < 0) {
+ close(fd);
+ zlog_warn("ioctl I_STR failed on device %s - %s",
+ device,
+ safe_strerror(errno));
+ return -1;
+ }
close(fd);
- zlog_warn("ioctl I_STR failed on device %s - %s", device,
- safe_strerror(save_errno));
- return -1;
}
- close(fd);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("solaris_nd: Can't lower privileges");
if (cmd == ND_GET) {
errno = 0;
#include "zebra/ipforward.h"
#include "log.h"
+#include "lib_errors.h"
#define MIB_SIZ 4
int ipforwarding = 1;
len = sizeof ipforwarding;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_warn("Can't set ipforwarding on");
- return -1;
+ frr_elevate_privs(&zserv_privs) {
+ if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) {
+ zlog_warn("Can't set ipforwarding on");
+ return -1;
+ }
}
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
return ipforwarding;
}
int ipforwarding = 0;
len = sizeof ipforwarding;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_warn("Can't set ipforwarding on");
- return -1;
+ frr_elevate_privs(&zserv_privs) {
+ if (sysctl(mib, MIB_SIZ, NULL, NULL, &ipforwarding, len) < 0) {
+ zlog_warn("Can't set ipforwarding on");
+ return -1;
+ }
}
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
return ipforwarding;
}
int ip6forwarding = 0;
len = sizeof ip6forwarding;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- if (sysctl(mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_warn("can't get ip6forwarding value");
- return -1;
+ frr_elevate_privs(&zserv_privs) {
+ if (sysctl(mib_ipv6, MIB_SIZ, &ip6forwarding, &len, 0, 0) < 0) {
+ zlog_warn("can't get ip6forwarding value");
+ return -1;
+ }
}
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
return ip6forwarding;
}
int ip6forwarding = 1;
len = sizeof ip6forwarding;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_warn("can't get ip6forwarding value");
- return -1;
+ frr_elevate_privs(&zserv_privs) {
+ if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len)
+ < 0) {
+ zlog_warn("can't get ip6forwarding value");
+ return -1;
+ }
}
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
return ip6forwarding;
}
int ip6forwarding = 0;
len = sizeof ip6forwarding;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len) < 0) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
- zlog_warn("can't get ip6forwarding value");
- return -1;
+ frr_elevate_privs(&zserv_privs) {
+ if (sysctl(mib_ipv6, MIB_SIZ, NULL, NULL, &ip6forwarding, len)
+ < 0) {
+ zlog_warn("can't get ip6forwarding value");
+ return -1;
+ }
}
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
return ip6forwarding;
}
/*
*
- * Copyright (C) 2000 Robert Olsson.
- * Swedish University of Agricultural Sciences
+ * Copyright (C) 1997, 2000
+ * Portions:
+ * Swedish University of Agricultural Sciences
+ * Robert Olsson
+ * Kunihiro Ishiguro
+ *
+ * Thanks to Jens Laas at Swedish University of Agricultural Sciences
+ * for reviewing and tests.
*
* This file is part of GNU Zebra.
*
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
-/*
- * This work includes work with the following copywrite:
- *
- * Copyright (C) 1997, 2000 Kunihiro Ishiguro
- *
- */
-
-/*
- * Thanks to Jens Låås at Swedish University of Agricultural Sciences
- * for reviewing and tests.
- */
-
-
#include <zebra.h>
#include "if.h"
*/
/*
- * Thanks to Jens Låås at Swedish University of Agricultural Sciences
+ * Thanks to Jens Laas at Swedish University of Agricultural Sciences
* for reviewing and tests.
*/
#include "thread.h"
#include "privs.h"
#include "libfrr.h"
+#include "lib_errors.h"
#include "version.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
int save_errno;
int sock;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("irdp_sock_init: could not raise privs, %s",
- safe_strerror(errno));
+ frr_elevate_privs(&zserv_privs) {
- sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
- save_errno = errno;
+ sock = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);
+ save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("irdp_sock_init: could not lower privs, %s",
- safe_strerror(errno));
+ }
if (sock < 0) {
zlog_warn("IRDP: can't create irdp socket %s",
*/
/*
- * Thanks to Jens Låås at Swedish University of Agricultural Sciences
+ * Thanks to Jens Laas at Swedish University of Agricultural Sciences
* for reviewing and tests.
*/
#include <zebra.h>
+#include <netinet/ip_icmp.h>
-
-#include "if.h"
-#include "vty.h"
-#include "sockunion.h"
-#include "prefix.h"
+#include "checksum.h"
#include "command.h"
-#include "memory.h"
-#include "zebra_memory.h"
-#include "stream.h"
-#include "ioctl.h"
#include "connected.h"
+#include "if.h"
+#include "ioctl.h"
#include "log.h"
-#include "zclient.h"
+#include "log.h"
+#include "memory.h"
+#include "prefix.h"
+#include "sockopt.h"
+#include "sockunion.h"
+#include "sockunion.h"
+#include "stream.h"
#include "thread.h"
+#include "vty.h"
+#include "zclient.h"
+
+#include "zebra_memory.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/redistribute.h"
#include "zebra/irdp.h"
-#include <netinet/ip_icmp.h>
-#include "if.h"
-#include "checksum.h"
-#include "sockunion.h"
-#include "log.h"
-#include "sockopt.h"
+#include "zebra/zebra_errors.h"
/* GLOBAL VARS */
src = ip->ip_src;
if (len != iplen) {
- zlog_err("IRDP: RX length doesnt match IP length");
+ flog_err(ZEBRA_ERR_IRDP_LEN_MISMATCH,
+ "IRDP: RX length doesnt match IP length");
return;
}
if (iplen < ICMP_MINLEN) {
- zlog_err("IRDP: RX ICMP packet too short from %s\n",
- inet_ntoa(src));
+ flog_err(ZEBRA_ERR_IRDP_LEN_MISMATCH,
+ "IRDP: RX ICMP packet too short from %s\n",
+ inet_ntoa(src));
return;
}
+
len of IP-header) 14+20 */
if (iplen > IRDP_RX_BUF - 34) {
- zlog_err("IRDP: RX ICMP packet too long from %s\n",
- inet_ntoa(src));
+ flog_err(ZEBRA_ERR_IRDP_LEN_MISMATCH,
+ "IRDP: RX ICMP packet too long from %s\n",
+ inet_ntoa(src));
return;
}
#include "nexthop.h"
#include "vrf.h"
#include "mpls.h"
+#include "lib_errors.h"
#include "zebra/zserv.h"
#include "zebra/zebra_ns.h"
#include "zebra/rt_netlink.h"
#include "zebra/if_netlink.h"
#include "zebra/rule_netlink.h"
+#include "zebra/zebra_errors.h"
#ifndef SO_RCVBUFFORCE
#define SO_RCVBUFFORCE (33)
* received some other message in an unexpected
* way.
*/
- zlog_err("%s: ignoring message type 0x%04x(%s) NS %u",
- __PRETTY_FUNCTION__, h->nlmsg_type,
- nl_msg_type_to_str(h->nlmsg_type), ns_id);
+ zlog_debug("%s: ignoring message type 0x%04x(%s) NS %u", __func__,
+ h->nlmsg_type, nl_msg_type_to_str(h->nlmsg_type), ns_id);
return 0;
}
ret = getsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &oldsize, &oldlen);
if (ret < 0) {
- zlog_err("Can't get %s receive buffer size: %s", nl->name,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "Can't get %s receive buffer size: %s", nl->name,
+ safe_strerror(errno));
return -1;
}
/* Try force option (linux >= 2.6.14) and fall back to normal set */
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("routing_socket: Can't raise privileges");
- ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUFFORCE, &nl_rcvbufsize,
- sizeof(nl_rcvbufsize));
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("routing_socket: Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUFFORCE,
+ &nl_rcvbufsize,
+ sizeof(nl_rcvbufsize));
+ }
if (ret < 0)
ret = setsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF,
&nl_rcvbufsize, sizeof(nl_rcvbufsize));
if (ret < 0) {
- zlog_err("Can't set %s receive buffer size: %s", nl->name,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "Can't set %s receive buffer size: %s", nl->name,
+ safe_strerror(errno));
return -1;
}
ret = getsockopt(nl->sock, SOL_SOCKET, SO_RCVBUF, &newsize, &newlen);
if (ret < 0) {
- zlog_err("Can't get %s receive buffer size: %s", nl->name,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "Can't get %s receive buffer size: %s", nl->name,
+ safe_strerror(errno));
return -1;
}
struct sockaddr_nl snl;
int sock;
int namelen;
- int save_errno;
- if (zserv_privs.change(ZPRIVS_RAISE)) {
- zlog_err("Can't raise privileges");
- return -1;
- }
-
- sock = ns_socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE, ns_id);
- if (sock < 0) {
- zlog_err("Can't open %s socket: %s", nl->name,
- safe_strerror(errno));
- return -1;
- }
+ frr_elevate_privs(&zserv_privs) {
+ sock = ns_socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE, ns_id);
+ if (sock < 0) {
+ zlog_err("Can't open %s socket: %s", nl->name,
+ safe_strerror(errno));
+ return -1;
+ }
- memset(&snl, 0, sizeof snl);
- snl.nl_family = AF_NETLINK;
- snl.nl_groups = groups;
+ memset(&snl, 0, sizeof snl);
+ snl.nl_family = AF_NETLINK;
+ snl.nl_groups = groups;
- /* Bind the socket to the netlink structure for anything. */
- ret = bind(sock, (struct sockaddr *)&snl, sizeof snl);
- save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ /* Bind the socket to the netlink structure for anything. */
+ ret = bind(sock, (struct sockaddr *)&snl, sizeof snl);
+ }
if (ret < 0) {
zlog_err("Can't bind %s socket to group 0x%x: %s", nl->name,
- snl.nl_groups, safe_strerror(save_errno));
+ snl.nl_groups, safe_strerror(errno));
close(sock);
return -1;
}
namelen = sizeof snl;
ret = getsockname(sock, (struct sockaddr *)&snl, (socklen_t *)&namelen);
if (ret < 0 || namelen != sizeof snl) {
- zlog_err("Can't get %s socket name: %s", nl->name,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "Can't get %s socket name: %s",
+ nl->name, safe_strerror(errno));
close(sock);
return -1;
}
* this message type or not ask for
* it to be sent up to us
*/
- zlog_err("Unknown netlink nlmsg_type %s(%d) vrf %u\n",
- nl_msg_type_to_str(h->nlmsg_type), h->nlmsg_type,
- ns_id);
+ flog_err(ZEBRA_ERR_UNKNOWN_NLMSG,
+ "Unknown netlink nlmsg_type %s(%d) vrf %u\n",
+ nl_msg_type_to_str(h->nlmsg_type), h->nlmsg_type,
+ ns_id);
break;
}
return 0;
char fname[MAXPATHLEN];
FILE *f;
- zserv_privs.change(ZPRIVS_RAISE);
snprintf(fname, MAXPATHLEN, "%s/%s_%u", DAEMON_VTY_DIR, "netlink",
counter);
- f = fopen(fname, "w");
+ frr_elevate_privs(&zserv_privs) {
+ f = fopen(fname, "w");
+ }
if (f) {
fwrite(buf, 1, size, f);
fclose(f);
}
- zserv_privs.change(ZPRIVS_LOWER);
}
/**
FILE *f;
long file_bytes = -1;
- zserv_privs.change(ZPRIVS_RAISE);
- f = fopen(fname, "r");
+ frr_elevate_privs(&zserv_privs) {
+ f = fopen(fname, "r");
+ }
if (f) {
fseek(f, 0, SEEK_END);
file_bytes = ftell(f);
fread(buf, NL_RCV_PKT_BUF_SIZE, 1, f);
fclose(f);
}
- zserv_privs.change(ZPRIVS_LOWER);
return file_bytes;
}
continue;
if (errno == EWOULDBLOCK || errno == EAGAIN)
break;
- zlog_err("%s recvmsg overrun: %s", nl->name,
- safe_strerror(errno));
+ flog_err(ZEBRA_ERR_RECVMSG_OVERRUN,
+ "%s recvmsg overrun: %s", nl->name,
+ safe_strerror(errno));
/*
* In this case we are screwed.
* There is no good way to
}
if (status == 0) {
- zlog_err("%s EOF", nl->name);
+ flog_err_sys(LIB_ERR_SOCKET, "%s EOF", nl->name);
return -1;
}
if (msg.msg_namelen != sizeof snl) {
- zlog_err("%s sender address length error: length %d",
- nl->name, msg.msg_namelen);
+ flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ "%s sender address length error: length %d",
+ nl->name, msg.msg_namelen);
return -1;
}
continue;
}
+ if (h->nlmsg_len
+ < NLMSG_LENGTH(sizeof(struct nlmsgerr))) {
+ flog_err(
+ ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ "%s error: message truncated",
+ nl->name);
+ return -1;
+ }
+
/* Deal with errors that occur because of races
* in link handling */
if (nl == &zns->netlink_cmd
err->msg.nlmsg_seq,
err->msg.nlmsg_pid);
} else
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_UNEXPECTED_MESSAGE,
"%s error: %s, type=%s(%u), seq=%u, pid=%u",
nl->name,
safe_strerror(-errnum),
* other actors besides the kernel
*/
if (snl.nl_pid != 0) {
- zlog_err("Ignoring message from pid %u",
- snl.nl_pid);
+ zlog_debug("Ignoring message from pid %u",
+ snl.nl_pid);
continue;
}
error = (*filter)(h, zns->ns_id, startup);
if (error < 0) {
- zlog_err("%s filter function error", nl->name);
- zlog_backtrace(LOG_ERR);
+ zlog_warn("%s filter function error", nl->name);
ret = error;
}
}
/* After error care. */
if (msg.msg_flags & MSG_TRUNC) {
- zlog_err("%s error: message truncated", nl->name);
+ flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ "%s error: message truncated", nl->name);
continue;
}
if (status) {
- zlog_err("%s error: data remnant size %d", nl->name,
- status);
+ flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ "%s error: data remnant size %d", nl->name,
+ status);
return -1;
}
}
struct nlmsghdr *n, struct nlsock *nl, struct zebra_ns *zns,
int startup)
{
- int status;
+ int status = 0;
struct sockaddr_nl snl;
struct iovec iov;
struct msghdr msg;
- int save_errno;
+ int save_errno = 0;
memset(&snl, 0, sizeof snl);
memset(&iov, 0, sizeof iov);
n->nlmsg_flags);
/* Send message to netlink interface. */
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- status = sendmsg(nl->sock, &msg, 0);
- save_errno = errno;
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ status = sendmsg(nl->sock, &msg, 0);
+ save_errno = errno;
+ }
if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) {
zlog_debug("%s: >> netlink message dump [sent]", __func__);
}
if (status < 0) {
- zlog_err("netlink_talk sendmsg() error: %s",
- safe_strerror(save_errno));
+ flog_err_sys(LIB_ERR_SOCKET, "netlink_talk sendmsg() error: %s",
+ safe_strerror(save_errno));
return -1;
}
{
int ret;
struct sockaddr_nl snl;
- int save_errno;
/* Check netlink socket. */
if (nl->sock < 0) {
- zlog_err("%s socket isn't active.", nl->name);
+ flog_err_sys(LIB_ERR_SOCKET, "%s socket isn't active.",
+ nl->name);
return -1;
}
snl.nl_family = AF_NETLINK;
/* Raise capabilities and send message, then lower capabilities. */
- if (zserv_privs.change(ZPRIVS_RAISE)) {
- zlog_err("Can't raise privileges");
- return -1;
+ frr_elevate_privs(&zserv_privs) {
+ ret = sendto(nl->sock, (void *)n, n->nlmsg_len, 0,
+ (struct sockaddr *)&snl, sizeof snl);
}
- ret = sendto(nl->sock, (void *)n, n->nlmsg_len, 0,
- (struct sockaddr *)&snl, sizeof snl);
- save_errno = errno;
-
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
-
if (ret < 0) {
zlog_err("%s sendto failed: %s", nl->name,
- safe_strerror(save_errno));
+ safe_strerror(errno));
return -1;
}
/* Register kernel socket. */
if (fcntl(zns->netlink.sock, F_SETFL, O_NONBLOCK) < 0)
- zlog_err("Can't set %s socket error: %s(%d)",
- zns->netlink.name, safe_strerror(errno), errno);
+ flog_err_sys(LIB_ERR_SOCKET, "Can't set %s socket flags: %s",
+ zns->netlink.name, safe_strerror(errno));
if (fcntl(zns->netlink_cmd.sock, F_SETFL, O_NONBLOCK) < 0)
zlog_err("Can't set %s socket error: %s(%d)",
#include "rib.h"
#include "privs.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "zebra/rt.h"
#include "zebra/interface.h"
#include "zebra/debug.h"
#include "zebra/kernel_socket.h"
#include "zebra/rib.h"
+#include "zebra/zebra_errors.h"
extern struct zebra_privs_t zserv_privs;
/* paranoia: sanity check structure */
if (ifm->ifm_msglen < sizeof(struct if_msghdr)) {
- zlog_err("ifm_read: ifm->ifm_msglen %d too short\n",
- ifm->ifm_msglen);
+ flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ "ifm_read: ifm->ifm_msglen %d too short\n",
+ ifm->ifm_msglen);
return -1;
}
/* Make routing socket. */
static void routing_socket(struct zebra_ns *zns)
{
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("routing_socket: Can't raise privileges");
-
- routing_sock =
- ns_socket(AF_ROUTE, SOCK_RAW, 0, zns->ns_id);
+ frr_elevate_privs(&zserv_privs) {
+ routing_sock = ns_socket(AF_ROUTE, SOCK_RAW, 0, zns->ns_id);
+ }
if (routing_sock < 0) {
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("routing_socket: Can't lower privileges");
zlog_warn("Can't init kernel routing socket");
return;
}
/*if (fcntl (routing_sock, F_SETFL, O_NONBLOCK) < 0)
zlog_warn ("Can't set O_NONBLOCK to routing socket");*/
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("routing_socket: Can't lower privileges");
-
/* kernel_read needs rewrite. */
thread_add_read(zebrad.master, kernel_read, NULL, routing_sock, NULL);
}
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
+#include <zebra.h>
#include <stdio.h>
#include <string.h>
#include <sys/types.h>
-#include "zebra.h"
-#include "zserv.h"
#include "lib/log.h"
#include "lib/memory.h"
#include "lib/mpls.h"
#include "lib/zclient.h"
#include "lib/libfrr.h"
-#include "label_manager.h"
+#include "zebra/zserv.h"
+#include "zebra/label_manager.h"
+#include "zebra/zebra_errors.h"
#define CONNECTION_DELAY 5
ret = zclient_read_header(src, zclient->sock, &size, &marker, &version,
&vrf_id, &resp_cmd);
if (ret < 0 && errno != EAGAIN) {
- zlog_err("Error reading Label Manager response: %s",
- strerror(errno));
+ flog_err(ZEBRA_ERR_LM_RESPONSE,
+ "Error reading Label Manager response: %s",
+ strerror(errno));
return -1;
}
zlog_debug("Label Manager response received, %d bytes", size);
/* lookup the client to relay the msg to */
zserv = zserv_find_client(proto, instance);
if (!zserv) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_LM_NO_SUCH_CLIENT,
"Error relaying LM response: can't find client %s, instance %u",
proto_str, instance);
return -1;
/* send response back */
ret = writen(zserv->sock, dst->data, stream_get_endp(dst));
if (ret <= 0) {
- zlog_err("Error relaying LM response to %s instance %u: %s",
- proto_str, instance, strerror(errno));
+ flog_err(ZEBRA_ERR_LM_RELAY_FAILED,
+ "Error relaying LM response to %s instance %u: %s",
+ proto_str, instance, strerror(errno));
return -1;
}
zlog_debug("Relayed LM response (%d bytes) to %s instance %u", ret,
unsigned short instance;
if (zclient->sock < 0) {
- zlog_err("Unable to relay LM request: no socket");
+ flog_err(ZEBRA_ERR_LM_NO_SOCKET,
+ "Unable to relay LM request: no socket");
reply_error(cmd, zserv, vrf_id);
return -1;
}
/* check & set client instance if unset */
if (zserv->instance && zserv->instance != instance) {
- zlog_err("Client instance(%u) != msg instance(%u)",
- zserv->instance, instance);
+ flog_err(ZEBRA_ERR_LM_BAD_INSTANCE,
+ "Client instance(%u) != msg instance(%u)",
+ zserv->instance, instance);
return -1;
}
/* Send request to external label manager */
ret = writen(zclient->sock, dst->data, stream_get_endp(dst));
if (ret <= 0) {
- zlog_err("Error relaying LM request from %s instance %u: %s",
- proto_str, instance, strerror(errno));
+ flog_err(ZEBRA_ERR_LM_RELAY_FAILED,
+ "Error relaying LM request from %s instance %u: %s",
+ proto_str, instance, strerror(errno));
reply_error(cmd, zserv, vrf_id);
return -1;
}
return 0;
if (zclient_socket_connect(zclient) < 0) {
- zlog_err("Error connecting synchronous zclient!");
+ flog_err(ZEBRA_ERR_LM_CLIENT_CONNECTION_FAILED,
+ "Error connecting synchronous zclient!");
thread_add_timer(zebrad.master, lm_zclient_connect, zclient,
CONNECTION_DELAY, &zclient->t_connect);
return -1;
->end
+ 1;
if (lmc->start > MPLS_LABEL_UNRESERVED_MAX - size + 1) {
- zlog_err("Reached max labels. Start: %u, size: %u", lmc->start,
- size);
+ flog_err(ZEBRA_ERR_LM_EXHAUSTED_LABELS,
+ "Reached max labels. Start: %u, size: %u", lmc->start,
+ size);
XFREE(MTYPE_LM_CHUNK, lmc);
return NULL;
}
if (lmc->end != end)
continue;
if (lmc->proto != proto || lmc->instance != instance) {
- zlog_err("%s: Daemon mismatch!!", __func__);
+ flog_err(ZEBRA_ERR_LM_DAEMON_MISMATCH,
+ "%s: Daemon mismatch!!", __func__);
continue;
}
lmc->proto = NO_PROTO;
break;
}
if (ret != 0)
- zlog_err("%s: Label chunk not released!!", __func__);
+ flog_err(ZEBRA_ERR_LM_UNRELEASED_CHUNK,
+ "%s: Label chunk not released!!", __func__);
return ret;
}
#include "routemap.h"
#include "frr_pthread.h"
+#include "zebra/zebra_errors.h"
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/debug.h"
multipath_num = atoi(optarg);
if (multipath_num > MULTIPATH_NUM
|| multipath_num <= 0) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_BAD_MULTIPATH_NUM,
"Multipath Number specified must be less than %d and greater than 0",
MULTIPATH_NUM);
return 1;
/* RNH init */
zebra_rnh_init();
+
+ /* Error init */
+ zebra_error_init();
#if defined(HANDLE_ZAPI_FUZZING)
if (zapi_fuzzing) {
#include "log.h"
#include "privs.h"
#include "vxlan.h"
+#include "lib_errors.h"
#include "zebra/debug.h"
#include "zebra/rib.h"
*/
case ZEBRA_ERR_RTEXIST:
if (cmd != RTM_ADD)
- zlog_err(
+ flog_err(
+ LIB_ERR_SYSTEM_CALL,
"%s: rtm_write() returned %d for command %d",
__func__, error, cmd);
continue;
case ZEBRA_ERR_RTNOEXIST:
case ZEBRA_ERR_RTUNREACH:
default:
- zlog_err(
+ flog_err(
+ LIB_ERR_SYSTEM_CALL,
"%s: %s: rtm_write() unexpectedly returned %d for command %s",
__func__,
prefix2str(p, prefix_buf,
int route = 0;
if (src_p && src_p->prefixlen) {
- zlog_err("route add: IPv6 sourcedest routes unsupported!");
+ zlog_warn("%s: IPv6 sourcedest routes unsupported!", __func__);
return DP_REQUEST_FAILURE;
}
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
+ frr_elevate_privs(&zserv_privs) {
- if (old)
- route |= kernel_rtm(RTM_DELETE, p, old);
+ if (old)
+ route |= kernel_rtm(RTM_DELETE, p, old);
- if (new)
- route |= kernel_rtm(RTM_ADD, p, new);
+ if (new)
+ route |= kernel_rtm(RTM_ADD, p, new);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ }
if (new) {
kernel_route_rib_pass_fail(
#include "privs.h"
#include "vrf.h"
#include "ns.h"
+#include "lib_errors.h"
#include "zebra/interface.h"
#include "zebra/rtadv.h"
adata = calloc(1, CMSG_SPACE(sizeof(struct in6_pktinfo)));
if (adata == NULL) {
- zlog_err(
+ zlog_warn(
"rtadv_send_packet: can't malloc control data");
exit(-1);
}
ret = sendmsg(sock, &msg, 0);
if (ret < 0) {
- zlog_err("%s(%u): Tx RA failed, socket %u error %d (%s)",
- ifp->name, ifp->ifindex, sock, errno,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "%s(%u): Tx RA failed, socket %u error %d (%s)",
+ ifp->name, ifp->ifindex, sock, errno,
+ safe_strerror(errno));
} else
zif->ra_sent++;
}
static int rtadv_make_socket(ns_id_t ns_id)
{
- int sock;
+ int sock = -1;
int ret = 0;
struct icmp6_filter filter;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("rtadv_make_socket: could not raise privs, %s",
- safe_strerror(errno));
+ frr_elevate_privs(&zserv_privs) {
- sock = ns_socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6, ns_id);
+ sock = ns_socket(AF_INET6, SOCK_RAW, IPPROTO_ICMPV6, ns_id);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("rtadv_make_socket: could not lower privs, %s",
- safe_strerror(errno));
+ }
if (sock < 0) {
return -1;
#include "if.h"
#include "prefix.h"
#include "vrf.h"
+#include "lib_errors.h"
#include "zebra/zserv.h"
#include "zebra/zebra_ns.h"
enum dp_req_result kernel_add_pbr_rule(struct zebra_pbr_rule *rule)
{
- zlog_err("%s not Implemented for this platform", __PRETTY_FUNCTION__);
+ flog_err(LIB_ERR_UNAVAILABLE, "%s not Implemented for this platform",
+ __PRETTY_FUNCTION__);
return DP_REQUEST_FAILURE;
}
enum dp_req_result kernel_del_pbr_rule(struct zebra_pbr_rule *rule)
{
- zlog_err("%s not Implemented for this platform", __PRETTY_FUNCTION__);
+ flog_err(LIB_ERR_UNAVAILABLE, "%s not Implemented for this platform",
+ __PRETTY_FUNCTION__);
return DP_REQUEST_FAILURE;
}
zebra/zebra_netns_notify.c \
zebra/table_manager.c \
zebra/zapi_msg.c \
+ zebra/zebra_errors.c \
# end
zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS)
zebra/zebra_netns_notify.h \
zebra/table_manager.h \
zebra/zapi_msg.h \
+ zebra/zebra_errors.h \
# end
zebra_zebra_irdp_la_SOURCES = \
#include "zebra/zebra_vrf.h"
#include "zebra/label_manager.h" /* for NO_PROTO */
#include "zebra/table_manager.h"
+#include "zebra/zebra_errors.h"
/* routing table identifiers
*
#endif /* SUNOS_5 */
tmc->start = start;
if (RT_TABLE_ID_UNRESERVED_MAX - size + 1 < start) {
- zlog_err("Reached max table id. Start/Size %u/%u",
- start, size);
+ flog_err(ZEBRA_ERR_TM_EXHAUSTED_IDS,
+ "Reached max table id. Start/Size %u/%u", start,
+ size);
XFREE(MTYPE_TM_CHUNK, tmc);
return NULL;
}
if (tmc->end != end)
continue;
if (tmc->proto != proto || tmc->instance != instance) {
- zlog_err("%s: Daemon mismatch!!", __func__);
+ flog_err(ZEBRA_ERR_TM_DAEMON_MISMATCH,
+ "%s: Daemon mismatch!!", __func__);
continue;
}
tmc->proto = NO_PROTO;
break;
}
if (ret != 0)
- zlog_err("%s: Table chunk not released!!", __func__);
+ flog_err(ZEBRA_ERR_TM_UNRELEASED_CHUNK,
+ "%s: Table chunk not released!!", __func__);
return ret;
}
STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN);
l += IPV6_MAX_BYTELEN;
} else {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_UNKNOWN_FAMILY,
"rnh_register: Received unknown family type %d\n",
p.family);
return;
STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN);
l += IPV6_MAX_BYTELEN;
} else {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_UNKNOWN_FAMILY,
"rnh_register: Received unknown family type %d\n",
p.family);
return;
* registration
*/
if (hdr->length < ZEBRA_MIN_FEC_LENGTH) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_IRDP_LEN_MISMATCH,
"fec_register: Received a fec register of hdr->length %d, it is of insufficient size to properly decode",
hdr->length);
return;
memset(&p, 0, sizeof(p));
STREAM_GETW(s, p.family);
if (p.family != AF_INET && p.family != AF_INET6) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_UNKNOWN_FAMILY,
"fec_register: Received unknown family type %d\n",
p.family);
return;
* fec unregistration
*/
if (hdr->length < ZEBRA_MIN_FEC_LENGTH) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_IRDP_LEN_MISMATCH,
"fec_unregister: Received a fec unregister of hdr->length %d, it is of insufficient size to properly decode",
hdr->length);
return;
memset(&p, 0, sizeof(p));
STREAM_GETW(s, p.family);
if (p.family != AF_INET && p.family != AF_INET6) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_UNKNOWN_FAMILY,
"fec_unregister: Received unknown family type %d\n",
p.family);
return;
/* accept only dynamic routing protocols */
if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) {
- zlog_err("client %d has wrong protocol %s", client->sock,
- zebra_route_string(proto));
+ flog_err(ZEBRA_ERR_TM_WRONG_PROTO,
+ "client %d has wrong protocol %s", client->sock,
+ zebra_route_string(proto));
zsend_table_manager_connect_response(client, vrf_id, 1);
return;
}
/* accept only dynamic routing protocols */
if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) {
- zlog_err("client %d has wrong protocol %s", client->sock,
- zebra_route_string(proto));
+ flog_err(ZEBRA_ERR_TM_WRONG_PROTO,
+ "client %d has wrong protocol %s", client->sock,
+ zebra_route_string(proto));
zsend_label_manager_connect_response(client, vrf_id, 1);
return;
}
uint8_t proto, unsigned int instance)
{
if (proto != client->proto) {
- zlog_err("%s: msg vs client proto mismatch, client=%u msg=%u",
- op, client->proto, proto);
+ flog_err(ZEBRA_ERR_PROTO_OR_INSTANCE_MISMATCH,
+ "%s: msg vs client proto mismatch, client=%u msg=%u",
+ op, client->proto, proto);
/* TODO: fail when BGP sets proto and instance */
/* return 1; */
}
if (instance != client->instance) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_PROTO_OR_INSTANCE_MISMATCH,
"%s: msg vs client instance mismatch, client=%u msg=%u",
op, client->instance, instance);
/* TODO: fail when BGP sets proto and instance */
lmc = assign_label_chunk(client->proto, client->instance, keep, size);
if (!lmc)
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_LM_CANNOT_ASSIGN_CHUNK,
"Unable to assign Label Chunk of size %u to %s instance %u",
size, zebra_route_string(client->proto),
client->instance);
else {
/* Sanity: don't allow 'unidentified' requests */
if (!client->proto) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_LM_ALIENS,
"Got label request from an unidentified client");
return;
}
tmc = assign_table_chunk(client->proto, client->instance, size);
if (!tmc)
- zlog_err("%s: Unable to assign Table Chunk of size %u",
- __func__, size);
+ flog_err(ZEBRA_ERR_TM_CANNOT_ASSIGN_CHUNK,
+ "%s: Unable to assign Table Chunk of size %u",
+ __func__, size);
else
zlog_debug("Assigned Table Chunk %u - %u", tmc->start,
tmc->end);
else {
/* Sanity: don't allow 'unidentified' requests */
if (!client->proto) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_TM_ALIENS,
"Got table request from an unidentified client");
return;
}
copy = stream_dup(orig);
stream_set_getp(copy, 0);
- zserv_privs.change(ZPRIVS_RAISE);
snprintf(fname, MAXPATHLEN, "%s/%u", DAEMON_VTY_DIR, command);
- fd = open(fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
+
+ frr_elevate_privs(&zserv_privs) {
+ fd = open(fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
+ }
stream_flush(copy, fd);
close(fd);
- zserv_privs.change(ZPRIVS_LOWER);
stream_free(copy);
}
#endif
#include "zebra/rib.h"
#include "zebra/zserv.h"
#include "zebra/zebra_pbr.h"
+#include "zebra/zebra_errors.h"
/*
* This is called to process inbound ZAPI messages.
--- /dev/null
+/*
+ * Zebra-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Quentin Young
+ *
+ * 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 "zebra_errors.h"
+
+/* clang-format off */
+static struct log_ref ferr_zebra_err[] = {
+ {
+ .code = ZEBRA_ERR_LM_RESPONSE,
+ .title = "Error reading response from label manager",
+ .description = "Zebra could not read the ZAPI header from the label manager",
+ .suggestion = "Wait for the error to resolve on its own. If it does not resolve, restart Zebra.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_NO_SUCH_CLIENT,
+ .title = "Label manager could not find ZAPI client",
+ .description = "Zebra was unable to find a ZAPI client matching the given protocol and instance number.",
+ .suggestion = "Ensure clients which use the label manager are properly configured and running.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_RELAY_FAILED,
+ .title = "Zebra could not relay label manager response",
+ .description = "Zebra found the client and instance to relay the label manager response or request to, but was not able to do so, possibly because the connection was closed.",
+ .suggestion = "Ensure clients which use the label manager are properly configured and running.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_BAD_INSTANCE,
+ .title = "Mismatch between ZAPI instance and encoded message instance",
+ .description = "While relaying a request to the external label manager, Zebra noticed that the instance number encoded in the message did not match the client instance number.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_EXHAUSTED_LABELS,
+ .title = "Zebra label manager used all available labels",
+ .description = "Zebra is unable to assign additional label chunks because it has exhausted its assigned label range.",
+ .suggestion = "Make the label range bigger and restart Zebra.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_DAEMON_MISMATCH,
+ .title = "Daemon mismatch when releasing label chunks",
+ .description = "Zebra noticed a mismatch between a label chunk and a protocol daemon number or instance when releasing unused label chunks.",
+ .suggestion = "Ignore this error.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_UNRELEASED_CHUNK,
+ .title = "Zebra did not free any label chunks",
+ .description = "Zebra's chunk cleanup procedure ran, but no label chunks were released.",
+ .suggestion = "Ignore this error.",
+ },
+ {
+ .code = ZEBRA_ERR_DP_INVALID_RC,
+ .title = "Dataplane returned invalid status code",
+ .description = "The underlying dataplane responded to a Zebra message or other interaction with an unrecognized, unknown or invalid status code.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_WQ_NONEXISTENT,
+ .title = "A necessary work queue does not exist.",
+ .description = "A necessary work queue does not exist.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_FEC_ADD_FAILED,
+ .title = "Failed to add FEC for MPLS client",
+ .description = "A client requested a label binding for a new FEC, but Zebra was unable to add the FEC to its internal table.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_FEC_RM_FAILED,
+ .title = "Failed to remove FEC for MPLS client",
+ .description = "Zebra was unable to find and remove a FEC in its internal table.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_IRDP_LEN_MISMATCH,
+ .title = "IRDP message length mismatch",
+ .description = "The length encoded in the IP TLV does not match the length of the packet received.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_RNH_UNKNOWN_FAMILY,
+ .title = "Attempted to perform nexthop update for unknown address family",
+ .description = "Zebra attempted to perform a nexthop update for unknown address family",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_DP_INSTALL_FAIL,
+ .title = "Dataplane installation failure",
+ .description = "Installation of routes to underlying dataplane failed.",
+ .suggestion = "Check all configuration parameters for correctness.",
+ },
+ {
+ .code = ZEBRA_ERR_TABLE_LOOKUP_FAILED,
+ .title = "Zebra table lookup failed",
+ .description = "Zebra attempted to look up a table for a particular address family and subsequent address family, but didn't find anything.",
+ .suggestion = "If you entered a command to trigger this error, make sure you entered the arguments correctly. Check your config file for any potential errors. If these look correct, seek help.",
+ },
+ {
+ .code = ZEBRA_ERR_NETLINK_NOT_AVAILABLE,
+ .title = "Netlink backend not available",
+ .description = "FRR was not compiled with support for Netlink. Any operations that require Netlink will fail.",
+ .suggestion = "Recompile FRR with Netlink, or install a package that supports this feature.",
+ },
+ {
+ .code = ZEBRA_ERR_PROTOBUF_NOT_AVAILABLE,
+ .title = "Protocol Buffers backend not available",
+ .description = "FRR was not compiled with support for Protocol Buffers. Any operations that require Protobuf will fail.",
+ .suggestion = "Recompile FRR with Protobuf support, or install a package that supports this feature.",
+ },
+ {
+ .code = ZEBRA_ERR_TM_EXHAUSTED_IDS,
+ .title = "Table manager used all available IDs",
+ .description = "Zebra's table manager used up all IDs available to it and can't assign any more.",
+ .suggestion = "Reconfigure Zebra with a larger range of table IDs.",
+ },
+ {
+ .code = ZEBRA_ERR_TM_DAEMON_MISMATCH,
+ .title = "Daemon mismatch when releasing table chunks",
+ .description = "Zebra noticed a mismatch between a table ID chunk and a protocol daemon number instance when releasing unused table chunks.",
+ .suggestion = "Ignore this error.",
+ },
+ {
+ .code = ZEBRA_ERR_TM_UNRELEASED_CHUNK,
+ .title = "Zebra did not free any table chunks",
+ .description = "Zebra's table chunk cleanup procedure ran, but no table chunks were released.",
+ .suggestion = "Ignore this error.",
+ },
+ {
+ .code = ZEBRA_ERR_UNKNOWN_FAMILY,
+ .title = "Address family specifier unrecognized",
+ .description = "Zebra attempted to process information from somewhere that included an address family specifier, but did not recognize the provided specifier.",
+ .suggestion = "Ensure that your configuration is correct. If it is, notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_TM_WRONG_PROTO,
+ .title = "Incorrect protocol for table manager client",
+ .description = "Zebra's table manager only accepts connections from daemons managing dynamic routing protocols, but received a connection attempt from a daemon that does not meet this criterion.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_PROTO_OR_INSTANCE_MISMATCH,
+ .title = "Mismatch between message and client protocol and/or instance",
+ .description = "Zebra detected a mismatch between a client's protocol and/or instance numbers versus those stored in a message transiting its socket.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_CANNOT_ASSIGN_CHUNK,
+ .title = "Label manager unable to assign label chunk",
+ .description = "Zebra's label manager was unable to assign a label chunk to client.",
+ .suggestion = "Ensure that Zebra has a sufficient label range available and that there is not a range collision.",
+ },
+ {
+ .code = ZEBRA_ERR_LM_ALIENS,
+ .title = "Label request from unidentified client",
+ .description = "Zebra's label manager received a label request from an unidentified client.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_TM_CANNOT_ASSIGN_CHUNK,
+ .title = "Table manager unable to assign table chunk",
+ .description = "Zebra's table manager was unable to assign a table chunk to a client.",
+ .suggestion = "Ensure that Zebra has sufficient table ID range available and that there is not a range collision.",
+ },
+ {
+ .code = ZEBRA_ERR_TM_ALIENS,
+ .title = "Table request from unidentified client",
+ .description = "Zebra's table manager received a table request from an unidentified client.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_RECVBUF,
+ .title = "Cannot set receive buffer size",
+ .description = "Socket receive buffer size could not be set in the kernel",
+ .suggestion = "Ignore this error.",
+ },
+ {
+ .code = ZEBRA_ERR_UNKNOWN_NLMSG,
+ .title = "Unknown Netlink message type",
+ .description = "Zebra received a Netlink message with an unrecognized type field.",
+ .suggestion = "Verify that you are running the latest version of FRR to ensure kernel compatibility. If the problem persists, notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_RECVMSG_OVERRUN,
+ .title = "Receive buffer overrun",
+ .description = "The kernel's buffer for a socket has been overrun, rendering the socket invalid.",
+ .suggestion = "Zebra will restart itself. Notify a developer if this issue shows up frequently.",
+ },
+ {
+ .code = ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ .title = "Netlink message length mismatch",
+ .description = "Zebra received a Netlink message with incorrect length fields.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ .title = "Netlink message length mismatch",
+ .description = "Zebra received a Netlink message with incorrect length fields.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_UNEXPECTED_MESSAGE,
+ .title = "Received unexpected response from kernel",
+ .description = "Received unexpected response from the kernel via Netlink.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_NETLINK_BAD_SEQUENCE,
+ .title = "Bad sequence number in Netlink message",
+ .description = "Zebra received a Netlink message with a bad sequence number.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_BAD_MULTIPATH_NUM,
+ .title = "Multipath number was out of valid range",
+ .description = "Multipath number specified to Zebra must be in the appropriate range",
+ .suggestion = "Provide a multipath number that is within its accepted range",
+ },
+ {
+ .code = ZEBRA_ERR_PREFIX_PARSE_ERROR,
+ .title = "String could not be parsed as IP prefix",
+ .description = "There was an attempt to parse a string as an IPv4 or IPv6 prefix, but the string could not be parsed and this operation failed.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_MAC_ADD_FAILED,
+ .title = "Failed to add MAC address to interface",
+ .description = "Zebra attempted to assign a MAC address to a vxlan interface but failed",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_VNI_DEL_FAILED,
+ .title = "Failed to delete VNI",
+ .description = "Zebra attempted to delete a VNI entry and failed",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_VTEP_ADD_FAILED,
+ .title = "Adding remote VTEP failed",
+ .description = "Zebra attempted to add a remote VTEP and failed.",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = ZEBRA_ERR_VNI_ADD_FAILED,
+ .title = "Adding VNI failed",
+ .description = "Zebra attempted to add a VNI hash to an interface and failed",
+ .suggestion = "Notify a developer.",
+ },
+ {
+ .code = END_FERR,
+ }
+};
+/* clang-format on */
+
+
+void zebra_error_init(void)
+{
+ log_ref_add(ferr_zebra_err);
+}
--- /dev/null
+/*
+ * Zebra-specific error messages.
+ * Copyright (C) 2018 Cumulus Networks, Inc.
+ * Quentin Young
+ *
+ * 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 __ZEBRA_ERRORS_H__
+#define __ZEBRA_ERRORS_H__
+
+#include "lib/ferr.h"
+
+enum zebra_log_refs {
+ ZEBRA_ERR_LM_RESPONSE = ZEBRA_FERR_START,
+ ZEBRA_ERR_LM_NO_SUCH_CLIENT,
+ ZEBRA_ERR_LM_RELAY_FAILED,
+ ZEBRA_ERR_LM_NO_SOCKET,
+ ZEBRA_ERR_LM_BAD_INSTANCE,
+ ZEBRA_ERR_LM_RELAY_REQUEST_FAILED,
+ ZEBRA_ERR_LM_CLIENT_CONNECTION_FAILED,
+ ZEBRA_ERR_LM_EXHAUSTED_LABELS,
+ ZEBRA_ERR_LM_DAEMON_MISMATCH,
+ ZEBRA_ERR_LM_UNRELEASED_CHUNK,
+ ZEBRA_ERR_DP_INVALID_RC,
+ ZEBRA_ERR_WQ_NONEXISTENT,
+ ZEBRA_ERR_FEC_ADD_FAILED,
+ ZEBRA_ERR_FEC_RM_FAILED,
+ ZEBRA_ERR_IRDP_LEN_MISMATCH,
+ ZEBRA_ERR_RNH_UNKNOWN_FAMILY,
+ ZEBRA_ERR_DP_INSTALL_FAIL,
+ ZEBRA_ERR_TABLE_LOOKUP_FAILED,
+ ZEBRA_ERR_NETLINK_NOT_AVAILABLE,
+ ZEBRA_ERR_PROTOBUF_NOT_AVAILABLE,
+ ZEBRA_ERR_TM_EXHAUSTED_IDS,
+ ZEBRA_ERR_TM_DAEMON_MISMATCH,
+ ZEBRA_ERR_TM_UNRELEASED_CHUNK,
+ ZEBRA_ERR_UNKNOWN_FAMILY,
+ ZEBRA_ERR_TM_WRONG_PROTO,
+ ZEBRA_ERR_PROTO_OR_INSTANCE_MISMATCH,
+ ZEBRA_ERR_LM_CANNOT_ASSIGN_CHUNK,
+ ZEBRA_ERR_LM_ALIENS,
+ ZEBRA_ERR_TM_CANNOT_ASSIGN_CHUNK,
+ ZEBRA_ERR_TM_ALIENS,
+ ZEBRA_ERR_RECVBUF,
+ ZEBRA_ERR_UNKNOWN_NLMSG,
+ ZEBRA_ERR_RECVMSG_OVERRUN,
+ ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ ZEBRA_ERR_UNEXPECTED_MESSAGE,
+ ZEBRA_ERR_NETLINK_BAD_SEQUENCE,
+ ZEBRA_ERR_BAD_MULTIPATH_NUM,
+ ZEBRA_ERR_PREFIX_PARSE_ERROR,
+ ZEBRA_ERR_MAC_ADD_FAILED,
+ ZEBRA_ERR_VNI_DEL_FAILED,
+ ZEBRA_ERR_VTEP_ADD_FAILED,
+ ZEBRA_ERR_VNI_ADD_FAILED,
+};
+
+void zebra_error_init(void);
+
+#endif /* __ZEBRA_ERRORS_H__ */
#include "zebra/zserv.h"
#include "zebra/zebra_ns.h"
#include "zebra/zebra_vrf.h"
+#include "zebra/zebra_errors.h"
#include "fpm/fpm.h"
#include "zebra_fpm_private.h"
if (!strcmp("netlink", format)) {
if (!have_netlink) {
- zlog_err("FPM netlink message format is not available");
+ flog_err(
+ ZEBRA_ERR_NETLINK_NOT_AVAILABLE,
+ "FPM netlink message format is not available");
return;
}
zfpm_g->message_format = ZFPM_MSG_FORMAT_NETLINK;
if (!strcmp("protobuf", format)) {
if (!have_protobuf) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_PROTOBUF_NOT_AVAILABLE,
"FPM protobuf message format is not available");
return;
}
#include "zebra/zebra_memory.h"
#include "zebra/zebra_vrf.h"
#include "zebra/zebra_mpls.h"
+#include "zebra/zebra_errors.h"
DEFINE_MTYPE_STATIC(ZEBRA, LSP, "MPLS LSP object")
DEFINE_MTYPE_STATIC(ZEBRA, FEC, "MPLS FEC object")
UNSET_FLAG(lsp->flags, LSP_FLAG_CHANGED);
switch (kernel_add_lsp(lsp)) {
case DP_REQUEST_QUEUED:
- zlog_err("No current DataPlane interfaces can return this, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INVALID_RC,
+ "No current DataPlane interfaces can return this, please fix");
break;
case DP_REQUEST_FAILURE:
break;
switch (kernel_del_lsp(lsp)) {
case DP_REQUEST_QUEUED:
- zlog_err("No current DataPlane interfaces can return this, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INVALID_RC,
+ "No current DataPlane interfaces can return this, please fix");
break;
case DP_REQUEST_FAILURE:
break;
switch (kernel_upd_lsp(lsp)) {
case DP_REQUEST_QUEUED:
- zlog_err("No current DataPlane interfaces can return this, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INVALID_RC,
+ "No current DataPlane interfaces can return this, please fix");
break;
case DP_REQUEST_FAILURE:
break;
return 0;
if (zebrad.lsp_process_q == NULL) {
- zlog_err("%s: work_queue does not exist!", __func__);
+ flog_err(ZEBRA_ERR_WQ_NONEXISTENT,
+ "%s: work_queue does not exist!", __func__);
return -1;
}
{
zebra->lsp_process_q = work_queue_new(zebra->master, "LSP processing");
if (!zebra->lsp_process_q) {
- zlog_err("%s: could not initialise work queue!", __func__);
+ flog_err(ZEBRA_ERR_WQ_NONEXISTENT,
+ "%s: could not initialise work queue!", __func__);
return -1;
}
fec = fec_add(table, p, MPLS_INVALID_LABEL, 0, label_index);
if (!fec) {
prefix2str(p, buf, BUFSIZ);
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_FEC_ADD_FAILED,
"Failed to add FEC %s upon register, client %s",
buf, zebra_route_string(client->proto));
return -1;
fec = fec_find(table, p);
if (!fec) {
prefix2str(p, buf, BUFSIZ);
- zlog_err("Failed to find FEC %s upon unregister, client %s",
- buf, zebra_route_string(client->proto));
+ flog_err(ZEBRA_ERR_FEC_RM_FAILED,
+ "Failed to find FEC %s upon unregister, client %s",
+ buf, zebra_route_string(client->proto));
return -1;
}
MPLS_INVALID_LABEL_INDEX);
if (!fec) {
prefix2str(p, buf, BUFSIZ);
- zlog_err("Failed to add FEC %s upon config", buf);
+ flog_err(ZEBRA_ERR_FEC_ADD_FAILED,
+ "Failed to add FEC %s upon config", buf);
return -1;
}
fec = fec_find(table, p);
if (!fec) {
prefix2str(p, buf, BUFSIZ);
- zlog_err("Failed to find FEC %s upon delete", buf);
+ flog_err(ZEBRA_ERR_FEC_RM_FAILED,
+ "Failed to find FEC %s upon delete", buf);
return -1;
}
struct hash *lsp_table;
lsp = (zebra_lsp_t *)backet->data;
- if (!lsp || !lsp->nhlfe_list)
+ if (!lsp->nhlfe_list)
return;
lsp_table = ctxt;
#include "prefix.h"
#include "interface.h"
#include "log.h"
+#include "lib_errors.h"
extern struct zebra_privs_t zserv_privs;
hdr.rtm_mpls = MPLS_OP_SWAP;
}
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- ret = writev(kr_state.fd, iov, iovcnt);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ ret = writev(kr_state.fd, iov, iovcnt);
+ }
if (ret == -1)
- zlog_err("%s: %s", __func__, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s: %s", __func__,
+ safe_strerror(errno));
return ret;
}
hdr.rtm_mpls = MPLS_OP_SWAP;
}
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- ret = writev(kr_state.fd, iov, iovcnt);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ ret = writev(kr_state.fd, iov, iovcnt);
+ }
if (ret == -1)
- zlog_err("%s: %s", __func__, safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "%s: %s", __func__,
+ safe_strerror(errno));
return ret;
}
imr.imr_type = IMR_TYPE_ETHERNET_TAGGED;
break;
default:
- zlog_err("%s: unhandled pseudowire type (%#X)", __func__,
- pw->type);
+ zlog_warn("%s: unhandled pseudowire type (%#X)", __func__,
+ pw->type);
return -1;
}
sa_in6->sin6_addr = pw->nexthop.ipv6;
break;
default:
- zlog_err("%s: unhandled pseudowire address-family (%u)",
- __func__, pw->af);
+ zlog_warn("%s: unhandled pseudowire address-family (%u)",
+ __func__, pw->af);
return -1;
}
memcpy(&imr.imr_nexthop, (struct sockaddr *)&ss,
strlcpy(ifr.ifr_name, pw->ifname, sizeof(ifr.ifr_name));
ifr.ifr_data = (caddr_t)&imr;
if (ioctl(kr_state.ioctl_fd, SIOCSETMPWCFG, &ifr) == -1) {
- zlog_err("ioctl SIOCSETMPWCFG: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "ioctl SIOCSETMPWCFG: %s",
+ safe_strerror(errno));
return -1;
}
strlcpy(ifr.ifr_name, pw->ifname, sizeof(ifr.ifr_name));
ifr.ifr_data = (caddr_t)&imr;
if (ioctl(kr_state.ioctl_fd, SIOCSETMPWCFG, &ifr) == -1) {
- zlog_err("ioctl SIOCSETMPWCFG: %s", safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SYSTEM_CALL, "ioctl SIOCSETMPWCFG: %s",
+ safe_strerror(errno));
return -1;
}
#include "ns.h"
#include "vrf.h"
#include "log.h"
+#include "lib_errors.h"
#if defined(HAVE_NETLINK)
#include "kernel_netlink.h"
#endif /* defined(HAVE_NETLINK) */
-#include "zebra_netns_id.h"
+#include "zebra/zebra_netns_id.h"
+#include "zebra/zebra_errors.h"
/* default NS ID value used when VRF backend is not NETNS */
#define NS_DEFAULT_INTERNAL 0
ret = sendto(sock, (const void *)nlh, (size_t)nlh->nlmsg_len, 0,
(struct sockaddr *)&snl, (socklen_t)sizeof(snl));
if (ret < 0) {
- zlog_err("netlink( %u) sendmsg() error: %s", sock,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "netlink( %u) sendmsg() error: %s",
+ sock, safe_strerror(errno));
return -1;
}
};
ret = recvmsg(sock, &msg, 0);
if (ret < 0) {
- zlog_err("netlink recvmsg: error %d (errno %u)", ret, errno);
+ flog_err_sys(LIB_ERR_SOCKET,
+ "netlink recvmsg: error %d (errno %u)", ret,
+ errno);
return -1;
}
if (msg.msg_flags & MSG_TRUNC) {
- zlog_err("netlink recvmsg : error message truncated");
+ flog_err(ZEBRA_ERR_NETLINK_LENGTH_ERROR,
+ "netlink recvmsg : error message truncated");
return -1;
}
/* nlh already points to buf */
if (nlh->nlmsg_seq != seq) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_NETLINK_BAD_SEQUENCE,
"netlink recvmsg: bad sequence number %x (expected %x)",
seq, nlh->nlmsg_seq);
return -1;
/* netlink socket */
sock = socket(AF_NETLINK, SOCK_RAW, NETLINK_ROUTE);
if (sock < 0) {
- zlog_err("netlink( %u) socket() error: %s", sock,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET, "netlink( %u) socket() error: %s",
+ sock, safe_strerror(errno));
close(fd);
return NS_UNKNOWN;
}
snl.nl_pid = 0; /* AUTO PID */
ret = bind(sock, (struct sockaddr *)&snl, sizeof(snl));
if (ret < 0) {
- zlog_err("netlink( %u) socket() bind error: %s", sock,
- safe_strerror(errno));
+ flog_err_sys(LIB_ERR_SOCKET,
+ "netlink( %u) socket() bind error: %s", sock,
+ safe_strerror(errno));
close(sock);
close(fd);
return NS_UNKNOWN;
if (ret <= 0) {
if (errno != EEXIST && ret != 0) {
- zlog_err(
+ flog_err(
+ LIB_ERR_SOCKET,
"netlink( %u) recvfrom() error 2 when reading: %s",
fd, safe_strerror(errno));
close(sock);
#include "ns.h"
#include "command.h"
#include "memory.h"
+#include "lib_errors.h"
#include "zserv.h"
#include "zebra_memory.h"
if (netnspath == NULL)
return;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- ns_id = zebra_ns_id_get(netnspath);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ ns_id = zebra_ns_id_get(netnspath);
+ }
if (ns_id == NS_UNKNOWN)
return;
ns_id_external = ns_map_nsid_with_external(ns_id, true);
ns_map_nsid_with_external(ns_id, false);
return;
}
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- ret = vrf_netns_handler_create(NULL, vrf, netnspath,
- ns_id_external, ns_id);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ ret = vrf_netns_handler_create(NULL, vrf, netnspath,
+ ns_id_external, ns_id);
+ }
if (ret != CMD_SUCCESS) {
zlog_warn("NS notify : failed to create NS %s", netnspath);
ns_map_nsid_with_external(ns_id, false);
netnspath = zns_info->netnspath;
if (--zns_info->retries == 0)
stop_retry = 1;
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- err = ns_switch_to_netns(netnspath);
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ err = ns_switch_to_netns(netnspath);
+ }
if (err < 0)
return zebra_ns_continue_read(zns_info, stop_retry);
/* go back to default ns */
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- err = ns_switchback_to_initial();
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ err = ns_switchback_to_initial();
+ }
if (err < 0)
return zebra_ns_continue_read(zns_info, stop_retry);
#include "lib/logicalrouter.h"
#include "lib/prefix.h"
#include "lib/memory.h"
+#include "lib/lib_errors.h"
#include "rtadv.h"
#include "zebra_ns.h"
dzns = zebra_ns_alloc();
- if (zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
- ns_id = zebra_ns_id_get_default();
- if (zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
+ frr_elevate_privs(&zserv_privs) {
+ ns_id = zebra_ns_id_get_default();
+ }
ns_id_external = ns_map_nsid_with_external(ns_id, true);
ns_init_management(ns_id_external, ns_id);
*/
#include <zebra.h>
+
#include <sys/un.h> /* for sockaddr_un */
#include <net/if.h>
+
+#include "bfd.h"
+#include "buffer.h"
+#include "command.h"
+#include "if.h"
+#include "network.h"
+#include "ptm_lib.h"
+#include "rib.h"
+#include "stream.h"
+#include "version.h"
+#include "vrf.h"
#include "vty.h"
-#include "zebra/zserv.h"
-#include "zebra/interface.h"
+
#include "zebra/debug.h"
+#include "zebra/interface.h"
+#include "zebra/zebra_errors.h"
#include "zebra/zebra_ptm.h"
-#include "if.h"
-#include "command.h"
-#include "stream.h"
-#include "ptm_lib.h"
-#include "network.h"
-#include "buffer.h"
#include "zebra/zebra_ptm_redistribute.h"
-#include "bfd.h"
-#include "vrf.h"
-#include "rib.h"
+#include "zebra/zserv.h"
#include "zebra_vrf.h"
-#include "version.h"
/*
* Choose the BFD implementation that we'll use.
dest_str, src_str);
if (str2prefix(dest_str, &dest_prefix) == 0) {
- zlog_err("%s: Peer addr %s not found", __func__, dest_str);
+ flog_err(ZEBRA_ERR_PREFIX_PARSE_ERROR,
+ "%s: Peer addr %s not found", __func__, dest_str);
return -1;
}
memset(&src_prefix, 0, sizeof(struct prefix));
if (strcmp(ZEBRA_PTM_INVALID_SRC_IP, src_str)) {
if (str2prefix(src_str, &src_prefix) == 0) {
- zlog_err("%s: Local addr %s not found", __func__,
- src_str);
+ flog_err(ZEBRA_ERR_PREFIX_PARSE_ERROR,
+ "%s: Local addr %s not found", __func__,
+ src_str);
return -1;
}
}
ifp = if_lookup_by_name_all_vrf(port_str);
if (!ifp) {
- zlog_err("%s: %s not found in interface list", __func__,
- port_str);
+ zlog_warn("%s: %s not found in interface list",
+ __func__, port_str);
return -1;
}
}
return 0;
if (IS_ZEBRA_DEBUG_EVENT)
- zlog_err("bfd_client_deregister msg for client %s",
- zebra_route_string(proto));
+ zlog_warn("bfd_client_deregister msg for client %s",
+ zebra_route_string(proto));
if (ptm_cb.ptm_sock == -1) {
ptm_cb.t_timer = NULL;
#include <zebra.h>
-#include "if.h"
-#include "prefix.h"
-#include "table.h"
-#include "memory.h"
-#include "zebra_memory.h"
#include "command.h"
+#include "if.h"
+#include "linklist.h"
#include "log.h"
#include "log_int.h"
-#include "sockunion.h"
-#include "linklist.h"
-#include "thread.h"
-#include "workqueue.h"
+#include "memory.h"
+#include "mpls.h"
+#include "nexthop.h"
+#include "prefix.h"
#include "prefix.h"
#include "routemap.h"
-#include "nexthop.h"
-#include "vrf.h"
-#include "mpls.h"
+#include "sockunion.h"
#include "srcdest_table.h"
+#include "table.h"
+#include "thread.h"
+#include "vrf.h"
+#include "workqueue.h"
+#include "zebra/connected.h"
+#include "zebra/debug.h"
+#include "zebra/interface.h"
+#include "zebra/redistribute.h"
#include "zebra/rib.h"
#include "zebra/rt.h"
+#include "zebra/zapi_msg.h"
+#include "zebra/zebra_errors.h"
+#include "zebra/zebra_memory.h"
#include "zebra/zebra_ns.h"
-#include "zebra/zebra_vrf.h"
-#include "zebra/redistribute.h"
-#include "zebra/zebra_routemap.h"
-#include "zebra/debug.h"
#include "zebra/zebra_rnh.h"
-#include "zebra/interface.h"
-#include "zebra/connected.h"
+#include "zebra/zebra_routemap.h"
+#include "zebra/zebra_vrf.h"
#include "zebra/zebra_vxlan.h"
-#include "zebra/zapi_msg.h"
DEFINE_HOOK(rib_update, (struct route_node * rn, const char *reason),
(rn, reason))
hook_call(rib_update, rn, "installing in kernel");
switch (kernel_route_rib(rn, p, src_p, old, re)) {
case DP_REQUEST_QUEUED:
- zlog_err("No current known DataPlane interfaces can return this, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INVALID_RC,
+ "No current known DataPlane interfaces can return this, please fix");
break;
case DP_REQUEST_FAILURE:
- zlog_err("No current known Rib Install Failure cases, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INSTALL_FAIL,
+ "No current known Rib Install Failure cases, please fix");
break;
case DP_REQUEST_SUCCESS:
zvrf->installs++;
hook_call(rib_update, rn, "uninstalling from kernel");
switch (kernel_route_rib(rn, p, src_p, re, NULL)) {
case DP_REQUEST_QUEUED:
- zlog_err("No current known DataPlane interfaces can return this, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INVALID_RC,
+ "No current known DataPlane interfaces can return this, please fix");
break;
case DP_REQUEST_FAILURE:
- zlog_err("No current known RIB Install Failure cases, please fix");
+ flog_err(
+ ZEBRA_ERR_DP_INSTALL_FAIL,
+ "No current known RIB Install Failure cases, please fix");
break;
case DP_REQUEST_SUCCESS:
if (zvrf)
}
if (zebrad.ribq == NULL) {
- zlog_err("%s: work_queue does not exist!", __func__);
+ flog_err(ZEBRA_ERR_WQ_NONEXISTENT,
+ "%s: work_queue does not exist!", __func__);
return;
}
if (!(zebra->ribq =
work_queue_new(zebra->master, "route_node processing"))) {
- zlog_err("%s: could not initialise work queue!", __func__);
+ flog_err(ZEBRA_ERR_WQ_NONEXISTENT,
+ "%s: could not initialise work queue!", __func__);
return;
}
zebra->ribq->spec.hold = ZEBRA_RIB_PROCESS_HOLD_TIME;
if (!(zebra->mq = meta_queue_new())) {
- zlog_err("%s: could not initialise meta queue!", __func__);
+ flog_err(ZEBRA_ERR_WQ_NONEXISTENT,
+ "%s: could not initialise meta queue!", __func__);
return;
}
return;
/* Lookup table. */
table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id);
if (!table) {
- zlog_err("%s:%u zebra_vrf_table() returned NULL",
- __func__, vrf_id);
+ flog_err(ZEBRA_ERR_TABLE_LOOKUP_FAILED,
+ "%s:%u zebra_vrf_table() returned NULL", __func__,
+ vrf_id);
return;
}
rib_dest_t *dest;
if (NULL == (table = zebra_vrf_table(AFI_IP, SAFI_UNICAST, vrf_id))) {
- zlog_err("%s:%u zebra_vrf_table() returned NULL",
- __func__, vrf_id);
+ flog_err(ZEBRA_ERR_TABLE_LOOKUP_FAILED,
+ "%s:%u zebra_vrf_table() returned NULL", __func__,
+ vrf_id);
return;
}
#include "zebra/zebra_routemap.h"
#include "zebra/interface.h"
#include "zebra/zebra_memory.h"
+#include "zebra/zebra_errors.h"
static void free_state(vrf_id_t vrf_id, struct route_entry *re,
struct route_node *rn);
stream_put(s, &rn->p.u.prefix6, IPV6_MAX_BYTELEN);
break;
default:
- zlog_err("%s: Unknown family (%d) notification attempted\n",
- __FUNCTION__, rn->p.family);
+ flog_err(ZEBRA_ERR_RNH_UNKNOWN_FAMILY,
+ "%s: Unknown family (%d) notification attempted\n",
+ __FUNCTION__, rn->p.family);
break;
}
if (re) {
#include <zebra.h>
+#include "hash.h"
#include "if.h"
-#include "prefix.h"
-#include "table.h"
-#include "memory.h"
-#include "log.h"
+#include "jhash.h"
#include "linklist.h"
+#include "log.h"
+#include "memory.h"
+#include "prefix.h"
#include "stream.h"
-#include "hash.h"
-#include "jhash.h"
+#include "table.h"
#include "vlan.h"
#include "vxlan.h"
#ifdef GNU_LINUX
#include <linux/neighbour.h>
#endif
+#include "zebra/debug.h"
+#include "zebra/interface.h"
#include "zebra/rib.h"
#include "zebra/rt.h"
+#include "zebra/rt_netlink.h"
+#include "zebra/zebra_errors.h"
+#include "zebra/zebra_l2.h"
+#include "zebra/zebra_memory.h"
#include "zebra/zebra_ns.h"
-#include "zebra/zserv.h"
-#include "zebra/debug.h"
-#include "zebra/interface.h"
#include "zebra/zebra_vrf.h"
-#include "zebra/rt_netlink.h"
-#include "zebra/zebra_vxlan_private.h"
#include "zebra/zebra_vxlan.h"
-#include "zebra/zebra_memory.h"
-#include "zebra/zebra_l2.h"
+#include "zebra/zebra_vxlan_private.h"
+#include "zebra/zserv.h"
DEFINE_MTYPE_STATIC(ZEBRA, HOST_PREFIX, "host prefix");
DEFINE_MTYPE_STATIC(ZEBRA, ZVNI, "VNI hash");
int width;
n = (zebra_neigh_t *)backet->data;
- if (!n)
- return;
ipaddr2str(&n->ip, buf, sizeof(buf)), width = strlen(buf);
if (width > wctx->addr_width)
vty = wctx->vty;
json_vni = wctx->json;
n = (zebra_neigh_t *)backet->data;
- if (!n)
- return;
if (json_vni)
json_row = json_object_new_object();
json = (json_object *)args[1];
zvni = (zebra_vni_t *)backet->data;
- if (!zvni) {
- if (json)
- vty_out(vty, "{}\n");
- return;
- }
+
num_neigh = hashcount(zvni->neigh_table);
if (json == NULL) {
vty_out(vty,
vty = wctx->vty;
json_mac_hdr = wctx->json;
mac = (zebra_mac_t *)backet->data;
- if (!mac)
- return;
prefix_mac2str(&mac->macaddr, buf1, sizeof(buf1));
json = (struct json_object *)wctx->json;
zvni = (zebra_vni_t *)backet->data;
- if (!zvni) {
- if (json)
- vty_out(vty, "{}\n");
- return;
- }
wctx->zvni = zvni;
/*We are iterating over a new VNI, set the count to 0*/
if (json_vni)
json_nh = json_object_new_object();
n = (zebra_neigh_t *)backet->data;
- if (!n)
- return;
if (!json_vni) {
vty_out(vty, "%-15s %-17s\n",
json = (struct json_object *)args[1];
zl3vni = (zebra_l3vni_t *)backet->data;
- if (!zl3vni) {
- if (json)
- vty_out(vty, "{}\n");
- return;
- }
num_nh = hashcount(zl3vni->nh_table);
if (!num_nh)
json = (struct json_object *)args[1];
zl3vni = (zebra_l3vni_t *)backet->data;
- if (!zl3vni) {
- if (json)
- vty_out(vty, "{}\n");
- return;
- }
num_rmacs = hashcount(zl3vni->rmac_table);
if (!num_rmacs)
if (json)
json_rmac = json_object_new_object();
zrmac = (zebra_mac_t *)backet->data;
- if (!zrmac)
- return;
if (!json) {
vty_out(vty, "%-17s %-21s\n",
json = (json_object *)ctx[1];
zl3vni = (zebra_l3vni_t *)backet->data;
- if (!zl3vni)
- return;
if (!json) {
vty_out(vty, "%-10u %-4s %-21s %-8lu %-8lu %-15s %-37s\n",
json = ctxt[1];
zvni = (zebra_vni_t *)backet->data;
- if (!zvni)
- return;
zvtep = zvni->vteps;
while (zvtep) {
zvni_neigh_send_del_to_client(zvni->vni, &n->ip,
&n->emac, 0);
}
- } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)) {
- if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_err(
- "local MAC %s getting deleted on VNI %u has remote neigh %s",
- prefix_mac2str(&n->emac, buf,
- sizeof(buf)),
- zvni->vni,
- ipaddr2str(&n->ip, buf2, sizeof(buf2)));
+ } else if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE)
+ && IS_ZEBRA_DEBUG_VXLAN) {
+ zlog_debug(
+ "local MAC %s getting deleted on VNI %u has remote neigh %s",
+ prefix_mac2str(&n->emac, buf, sizeof(buf)),
+ zvni->vni,
+ ipaddr2str(&n->ip, buf2, sizeof(buf2)));
}
}
}
char buf2[INET6_ADDRSTRLEN];
for (ALL_LIST_ELEMENTS_RO(zmac->neigh_list, node, n)) {
- if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)) {
- if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_err(
- "remote MAC %s getting deleted on VNI %u has local neigh %s",
- prefix_mac2str(&n->emac, buf,
- sizeof(buf)),
- zvni->vni,
- ipaddr2str(&n->ip, buf2, sizeof(buf2)));
+ if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_LOCAL)
+ && IS_ZEBRA_DEBUG_VXLAN) {
+ zlog_debug(
+ "remote MAC %s getting deleted on VNI %u has local neigh %s",
+ prefix_mac2str(&n->emac, buf, sizeof(buf)),
+ zvni->vni,
+ ipaddr2str(&n->ip, buf2, sizeof(buf2)));
}
}
}
return 0;
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
- zvni->vni, zvni);
+ zlog_warn("VNI %u hash %p couldn't be uninstalled - no intf",
+ zvni->vni, zvni);
return -1;
}
struct neigh_walk_ctx *wctx = ctxt;
n = (zebra_neigh_t *)backet->data;
- if (!n)
- return;
if (CHECK_FLAG(n->flags, ZEBRA_NEIGH_REMOTE))
zvni_neigh_install(wctx->zvni, n);
if (!mac) {
mac = zvni_mac_add(zvni, macaddr);
if (!mac) {
- zlog_err("Failed to add MAC %s intf %s(%u) VID %u",
- prefix_mac2str(macaddr, buf, sizeof(buf)),
- ifp->name, ifp->ifindex, vxl->access_vlan);
+ flog_err(ZEBRA_ERR_MAC_ADD_FAILED,
+ "Failed to add MAC %s intf %s(%u) VID %u",
+ prefix_mac2str(macaddr, buf, sizeof(buf)),
+ ifp->name, ifp->ifindex, vxl->access_vlan);
return -1;
}
}
if (!n) {
n = zvni_neigh_add(zvni, ip, macaddr);
if (!n) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_MAC_ADD_FAILED,
"Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
ipaddr2str(ip, buf2, sizeof(buf2)),
prefix_mac2str(macaddr, buf, sizeof(buf)),
/* mac entry should be present */
mac = zvni_mac_lookup(zvni, &n->emac);
if (!mac) {
- zlog_err("MAC %s doesnt exists for neigh %s on VNI %u",
- prefix_mac2str(&n->emac, buf1, sizeof(buf1)),
- ipaddr2str(ip, buf2, sizeof(buf2)), zvni->vni);
+ zlog_warn("MAC %s doesnt exists for neigh %s on VNI %u",
+ prefix_mac2str(&n->emac, buf1, sizeof(buf1)),
+ ipaddr2str(ip, buf2, sizeof(buf2)), zvni->vni);
return -1;
}
/* Add primary SVI MAC*/
zvni = (zebra_vni_t *)backet->data;
- if (!zvni)
- return;
ifp = zvni->vxlan_if;
if (!ifp)
struct interface *ifp = NULL;
zvni = (zebra_vni_t *)backet->data;
- if (!zvni)
- return;
ifp = zvni->vxlan_if;
if (!ifp)
/* New neighbor - create */
n = zvni_neigh_add(zvni, ip, macaddr);
if (!n) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_MAC_ADD_FAILED,
"Failed to add neighbor %s MAC %s intf %s(%u) -> VNI %u",
ipaddr2str(ip, buf2, sizeof(buf2)),
prefix_mac2str(macaddr, buf, sizeof(buf)),
*/
zmac = zvni_mac_lookup(zvni, macaddr);
if (!zmac || !CHECK_FLAG(zmac->flags, ZEBRA_MAC_REMOTE)) {
- zlog_err("Ignore remote neigh %s (MAC %s) on L2-VNI %u - MAC unknown or local",
- ipaddr2str(&n->ip, buf2, sizeof(buf2)),
- prefix_mac2str(macaddr, buf, sizeof(buf)),
- zvni->vni);
+ zlog_warn(
+ "Ignore remote neigh %s (MAC %s) on L2-VNI %u - MAC unknown or local",
+ ipaddr2str(&n->ip, buf2, sizeof(buf2)),
+ prefix_mac2str(macaddr, buf, sizeof(buf)),
+ zvni->vni);
return -1;
}
return 0;
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
- zvni->vni, zvni);
+ zlog_warn("VNI %u hash %p couldn't be uninstalled - no intf",
+ zvni->vni, zvni);
return -1;
}
struct mac_walk_ctx *wctx = ctxt;
mac = (zebra_mac_t *)backet->data;
- if (!mac)
- return;
if (CHECK_FLAG(mac->flags, ZEBRA_MAC_REMOTE))
zvni_mac_install(wctx->zvni, mac);
/* VNI hash entry is not expected to exist. */
zvni = zvni_lookup(vni);
if (zvni) {
- zlog_err(
+ zlog_warn(
"VNI hash already present for IF %s(%u) L2-VNI %u",
ifp->name, ifp->ifindex, vni);
continue;
zvni = zvni_add(vni);
if (!zvni) {
- zlog_err(
+ zlog_warn(
"Failed to add VNI hash, IF %s(%u) L2-VNI %u",
ifp->name, ifp->ifindex, vni);
return;
static int zvni_vtep_uninstall(zebra_vni_t *zvni, struct in_addr *vtep_ip)
{
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p couldn't be uninstalled - no intf",
- zvni->vni, zvni);
+ zlog_warn("VNI %u hash %p couldn't be uninstalled - no intf",
+ zvni->vni, zvni);
return -1;
}
struct zebra_vrf *zvrf = (struct zebra_vrf *)arg;
zvni = (zebra_vni_t *)backet->data;
- if (!zvni)
- return;
/* remove from l3-vni list */
if (zvrf->l3vni)
zebra_l3vni_t *zl3vni = NULL;
zl3vni = (zebra_l3vni_t *)backet->data;
- if (!zl3vni)
- return;
zebra_vxlan_process_l3vni_oper_down(zl3vni);
}
return 0;
if (!zl3vni->vxlan_if) {
- zlog_err(
+ zlog_warn(
"RMAC %s on L3-VNI %u hash %p couldn't be uninstalled - no vxlan_if",
prefix_mac2str(&zrmac->macaddr, buf, sizeof(buf)),
zl3vni->vni, zl3vni);
/* Delete the hash entry. */
if (zvni_del(zvni)) {
- zlog_err("Failed to del VNI hash %p, VNI %u", zvni,
- zvni->vni);
+ flog_err(ZEBRA_ERR_VNI_DEL_FAILED,
+ "Failed to del VNI hash %p, VNI %u", zvni,
+ zvni->vni);
return -1;
}
} else {
return 0;
if (!zvni->vxlan_if) {
- zlog_err(
+ zlog_warn(
"VNI %u hash %p doesn't have intf upon local neighbor DEL",
zvni->vni, zvni);
return -1;
zmac = zvni_mac_lookup(zvni, &n->emac);
if (!zmac) {
if (IS_ZEBRA_DEBUG_VXLAN)
- zlog_err(
+ zlog_warn(
"Trying to del a neigh %s without a mac %s on VNI %u",
ipaddr2str(ip, buf, sizeof(buf)),
prefix_mac2str(&n->emac, buf2, sizeof(buf2)),
}
ifp = zvni->vxlan_if;
if (!ifp) {
- zlog_err(
+ zlog_warn(
"VNI %u hash %p doesn't have intf upon remote MACIP DEL",
vni, zvni);
continue;
n = zvni_neigh_lookup(zvni, &ip);
if (n && !mac) {
- zlog_err("Failed to locate MAC %s for neigh %s VNI %u",
- prefix_mac2str(&macaddr, buf, sizeof(buf)),
- ipaddr2str(&ip, buf1, sizeof(buf1)), vni);
+ zlog_warn("Failed to locate MAC %s for neigh %s VNI %u",
+ prefix_mac2str(&macaddr, buf, sizeof(buf)),
+ ipaddr2str(&ip, buf1, sizeof(buf1)), vni);
continue;
}
/* Ignore the delete if this mac is a gateway mac-ip */
if (mac && CHECK_FLAG(mac->flags, ZEBRA_MAC_LOCAL)
&& CHECK_FLAG(mac->flags, ZEBRA_MAC_DEF_GW)) {
- zlog_err(
+ zlog_warn(
"%u: Ignore Del for MAC %s neigh %s on VNI %u as it is configured as a default gateway",
zvrf_id(zvrf),
prefix_mac2str(&macaddr, buf, sizeof(buf)),
/* Locate VNI hash entry - expected to exist. */
zvni = zvni_lookup(vni);
if (!zvni) {
- zlog_err(
+ zlog_warn(
"Failed to locate VNI hash upon remote MACIP ADD, VNI %u",
vni);
continue;
}
ifp = zvni->vxlan_if;
if (!ifp) {
- zlog_err(
+ zlog_warn(
"VNI %u hash %p doesn't have intf upon remote MACIP add",
vni, zvni);
continue;
zvtep = zvni_vtep_find(zvni, &vtep_ip);
if (!zvtep) {
if (zvni_vtep_add(zvni, &vtep_ip) == NULL) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_VTEP_ADD_FAILED,
"Failed to add remote VTEP, VNI %u zvni %p",
vni, zvni);
continue;
if (!zvni)
return 0;
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p doesn't have intf upon local MAC DEL",
- zvni->vni, zvni);
+ zlog_warn("VNI %u hash %p doesn't have intf upon local MAC DEL",
+ zvni->vni, zvni);
return -1;
}
}
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p doesn't have intf upon local MAC ADD",
- zvni->vni, zvni);
+ zlog_warn("VNI %u hash %p doesn't have intf upon local MAC ADD",
+ zvni->vni, zvni);
return -1;
}
if (!mac) {
mac = zvni_mac_add(zvni, macaddr);
if (!mac) {
- zlog_err("Failed to add MAC %s intf %s(%u) VID %u",
- prefix_mac2str(macaddr, buf, sizeof(buf)),
- ifp->name, ifp->ifindex, vid);
+ flog_err(ZEBRA_ERR_MAC_ADD_FAILED,
+ "Failed to add MAC %s intf %s(%u) VID %u",
+ prefix_mac2str(macaddr, buf, sizeof(buf)),
+ ifp->name, ifp->ifindex, vid);
return -1;
}
}
}
if (zvrf_id(zvrf) != VRF_DEFAULT) {
- zlog_err("Recv MACIP DEL for non-default VRF %u",
- zvrf_id(zvrf));
+ zlog_warn("Recv MACIP DEL for non-default VRF %u",
+ zvrf_id(zvrf));
return;
}
ifp = zvni->vxlan_if;
if (!ifp) {
- zlog_err(
+ zlog_warn(
"VNI %u hash %p doesn't have intf upon remote VTEP DEL",
zvni->vni, zvni);
continue;
}
if (zvrf_id(zvrf) != VRF_DEFAULT) {
- zlog_err("Recv MACIP ADD for non-default VRF %u",
- zvrf_id(zvrf));
+ zlog_warn("Recv MACIP ADD for non-default VRF %u",
+ zvrf_id(zvrf));
return;
}
/* Locate VNI hash entry - expected to exist. */
zvni = zvni_lookup(vni);
if (!zvni) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_VTEP_ADD_FAILED,
"Failed to locate VNI hash upon remote VTEP ADD, VNI %u",
vni);
continue;
ifp = zvni->vxlan_if;
if (!ifp) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_VTEP_ADD_FAILED,
"VNI %u hash %p doesn't have intf upon remote VTEP ADD",
zvni->vni, zvni);
continue;
continue;
if (zvni_vtep_add(zvni, &vtep_ip) == NULL) {
- zlog_err("Failed to add remote VTEP, VNI %u zvni %p",
- vni, zvni);
+ flog_err(ZEBRA_ERR_VTEP_ADD_FAILED,
+ "Failed to add remote VTEP, VNI %u zvni %p",
+ vni, zvni);
continue;
}
svi_if = if_lookup_by_index_per_ns(zebra_ns_lookup(NS_DEFAULT),
ifp_zif->link_ifindex);
if (!svi_if) {
- zlog_err("MACVLAN %s(%u) without link information",
- ifp->name, ifp->ifindex);
+ zlog_warn("MACVLAN %s(%u) without link information",
+ ifp->name, ifp->ifindex);
return -1;
}
return 0;
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p doesn't have intf upon MACVLAN up",
- zvni->vni, zvni);
+ zlog_warn("VNI %u hash %p doesn't have intf upon MACVLAN up",
+ zvni->vni, zvni);
return -1;
}
return 0;
if (!zvni->vxlan_if) {
- zlog_err("VNI %u hash %p doesn't have intf upon SVI up",
- zvni->vni, zvni);
+ zlog_warn(
+ "VNI %u hash %p doesn't have intf upon SVI up",
+ zvni->vni, zvni);
return -1;
}
/* Locate hash entry; it is expected to exist. */
zvni = zvni_lookup(vni);
if (!zvni) {
- zlog_err(
+ zlog_warn(
"Failed to locate VNI hash at DOWN, IF %s(%u) VNI %u",
ifp->name, ifp->ifindex, vni);
return -1;
/* Locate hash entry; it is expected to exist. */
zvni = zvni_lookup(vni);
if (!zvni) {
- zlog_err(
+ zlog_warn(
"Failed to locate VNI hash at UP, IF %s(%u) VNI %u",
ifp->name, ifp->ifindex, vni);
return -1;
/* Locate hash entry; it is expected to exist. */
zvni = zvni_lookup(vni);
if (!zvni) {
- zlog_err(
+ zlog_warn(
"Failed to locate VNI hash at del, IF %s(%u) VNI %u",
ifp->name, ifp->ifindex, vni);
return 0;
/* Delete the hash entry. */
if (zvni_del(zvni)) {
- zlog_err("Failed to del VNI hash %p, IF %s(%u) VNI %u",
- zvni, ifp->name, ifp->ifindex, zvni->vni);
+ flog_err(ZEBRA_ERR_VNI_DEL_FAILED,
+ "Failed to del VNI hash %p, IF %s(%u) VNI %u",
+ zvni, ifp->name, ifp->ifindex, zvni->vni);
return -1;
}
}
/* Update VNI hash. */
zvni = zvni_lookup(vni);
if (!zvni) {
- zlog_err(
+ zlog_warn(
"Failed to find L2-VNI hash on update, IF %s(%u) VNI %u",
ifp->name, ifp->ifindex, vni);
return -1;
if (!zvni) {
zvni = zvni_add(vni);
if (!zvni) {
- zlog_err(
+ flog_err(
+ ZEBRA_ERR_VNI_ADD_FAILED,
"Failed to add VNI hash, IF %s(%u) VNI %u",
ifp->name, ifp->ifindex, vni);
return -1;
struct interface *vlan_if = NULL;
if (zvrf_id(zvrf) != VRF_DEFAULT) {
- zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
- zvrf_id(zvrf));
+ zlog_warn("EVPN GW-MACIP Adv for non-default VRF %u",
+ zvrf_id(zvrf));
return;
}
struct interface *ifp = NULL;
if (zvrf_id(zvrf) != VRF_DEFAULT) {
- zlog_err("EVPN GW-MACIP Adv for non-default VRF %u",
- zvrf_id(zvrf));
+ zlog_warn("EVPN GW-MACIP Adv for non-default VRF %u",
+ zvrf_id(zvrf));
return;
}
struct zebra_ns *zns = NULL;
if (zvrf_id(zvrf) != VRF_DEFAULT) {
- zlog_err("EVPN VNI Adv for non-default VRF %u", zvrf_id(zvrf));
+ zlog_warn("EVPN VNI Adv for non-default VRF %u", zvrf_id(zvrf));
return;
}
#include "lib/zclient.h" /* for zmsghdr, ZEBRA_HEADER_SIZE, ZEBRA... */
#include "lib/frr_pthread.h" /* for frr_pthread_new, frr_pthread_stop... */
#include "lib/frratomic.h" /* for atomic_load_explicit, atomic_stor... */
+#include "lib/lib_errors.h" /* for generic ferr ids */
#include "zebra/debug.h" /* for various debugging macros */
#include "zebra/rib.h" /* for rib_score_proto */
unlink(suna->sun_path);
}
- zserv_privs.change(ZPRIVS_RAISE);
- setsockopt_so_recvbuf(zebrad.sock, 1048576);
- setsockopt_so_sendbuf(zebrad.sock, 1048576);
- zserv_privs.change(ZPRIVS_LOWER);
-
- if (sa.ss_family != AF_UNIX && zserv_privs.change(ZPRIVS_RAISE))
- zlog_err("Can't raise privileges");
+ frr_elevate_privs(&zserv_privs) {
+ setsockopt_so_recvbuf(zebrad.sock, 1048576);
+ setsockopt_so_sendbuf(zebrad.sock, 1048576);
+ }
- ret = bind(zebrad.sock, (struct sockaddr *)&sa, sa_len);
+ frr_elevate_privs((sa.ss_family != AF_UNIX) ? &zserv_privs : NULL) {
+ ret = bind(zebrad.sock, (struct sockaddr *)&sa, sa_len);
+ }
if (ret < 0) {
zlog_warn("Can't bind zserv socket on %s: %s", path,
safe_strerror(errno));
zebrad.sock = -1;
return;
}
- if (sa.ss_family != AF_UNIX && zserv_privs.change(ZPRIVS_LOWER))
- zlog_err("Can't lower privileges");
ret = listen(zebrad.sock, 5);
if (ret < 0) {