diff options
Diffstat (limited to 'lib')
60 files changed, 774 insertions, 480 deletions
diff --git a/lib/.gitignore b/lib/.gitignore index 072146dbd5..6176b30f8d 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -1,26 +1,13 @@ -!Makefile -Makefile.in -*.o -*.lo -*.la -version.c -version.h -gitversion.h -gitversion.h.tmp -.deps -.nfs* -.libs -.arch-inventory -.arch-ids -*~ -*.loT -route_types.h -memtypes.h -command_lex.c -command_lex.h -command_parse.c -command_parse.h -refix -grammar_sandbox -clippy -defun_lex.c +/version.c +/version.h +/gitversion.h +/gitversion.h.tmp +/route_types.h +/memtypes.h +/command_lex.c +/command_lex.h +/command_parse.c +/command_parse.h +/grammar_sandbox +/clippy +/defun_lex.c diff --git a/lib/agentx.c b/lib/agentx.c index 8e6493d4d3..55bb9e99ec 100644 --- a/lib/agentx.c +++ b/lib/agentx.c @@ -142,23 +142,20 @@ static int agentx_log_callback(int major, int minor, void *serverarg, msg[strlen(msg) - 1] = '\0'; switch (slm->priority) { case LOG_EMERG: - flog_err(LIB_ERR_SNMP, - "snmp[emerg]: %s", msg ? msg : slm->msg); + flog_err(EC_LIB_SNMP, "snmp[emerg]: %s", msg ? msg : slm->msg); break; case LOG_ALERT: - flog_err(LIB_ERR_SNMP, - "snmp[alert]: %s", msg ? msg : slm->msg); + flog_err(EC_LIB_SNMP, "snmp[alert]: %s", msg ? msg : slm->msg); break; case LOG_CRIT: - flog_err(LIB_ERR_SNMP, - "snmp[crit]: %s", msg ? msg : slm->msg); + flog_err(EC_LIB_SNMP, "snmp[crit]: %s", msg ? msg : slm->msg); break; case LOG_ERR: - flog_err(LIB_ERR_SNMP, - "snmp[err]: %s", msg ? msg : slm->msg); + flog_err(EC_LIB_SNMP, "snmp[err]: %s", msg ? msg : slm->msg); break; case LOG_WARNING: - zlog_warn("snmp[warning]: %s", msg ? msg : slm->msg); + flog_warn(EC_LIB_SNMP, "snmp[warning]: %s", + msg ? msg : slm->msg); break; case LOG_NOTICE: zlog_notice("snmp[notice]: %s", msg ? msg : slm->msg); diff --git a/lib/buffer.c b/lib/buffer.c index 1799c6b94f..bb2cdb7e54 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -332,7 +332,7 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, } else { /* This should absolutely never occur. */ flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_SYSTEM_CALL, "%s: corruption detected: iov_small overflowed; " "head %p, tail %p, head->next %p", __func__, (void *)b->head, @@ -365,8 +365,9 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, iov_size = ((iov_index > IOV_MAX) ? IOV_MAX : iov_index); if ((nbytes = writev(fd, c_iov, iov_size)) < 0) { - zlog_warn("%s: writev to fd %d failed: %s", - __func__, fd, safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "%s: writev to fd %d failed: %s", + __func__, fd, safe_strerror(errno)); break; } @@ -377,8 +378,8 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, } #else /* IOV_MAX */ if ((nbytes = writev(fd, iov, iov_index)) < 0) - zlog_warn("%s: writev to fd %d failed: %s", __func__, fd, - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "%s: writev to fd %d failed: %s", + __func__, fd, safe_strerror(errno)); #endif /* IOV_MAX */ /* Free printed buffer data. */ @@ -438,17 +439,16 @@ in one shot. */ if (ERRNO_IO_RETRY(errno)) /* Calling code should try again later. */ return BUFFER_PENDING; - zlog_warn("%s: write error on fd %d: %s", __func__, fd, - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "%s: write error on fd %d: %s", + __func__, fd, safe_strerror(errno)); return BUFFER_ERROR; } /* Free printed buffer data. */ while (written > 0) { - struct buffer_data *d; if (!(d = b->head)) { flog_err( - LIB_ERR_DEVELOPMENT, + EC_LIB_DEVELOPMENT, "%s: corruption detected: buffer queue empty, but written is %lu", __func__, (unsigned long)written); break; @@ -493,8 +493,8 @@ buffer_status_t buffer_write(struct buffer *b, int fd, const void *p, if (ERRNO_IO_RETRY(errno)) nbytes = 0; else { - zlog_warn("%s: write error on fd %d: %s", __func__, fd, - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "%s: write error on fd %d: %s", + __func__, fd, safe_strerror(errno)); return BUFFER_ERROR; } } diff --git a/lib/command.c b/lib/command.c index 1df6442107..e4e3d786ac 100644 --- a/lib/command.c +++ b/lib/command.c @@ -146,6 +146,7 @@ const char *node_names[] = { */ "bfd", /* BFD_NODE */ "bfd peer", /* BFD_PEER_NODE */ + "openfabric", // OPENFABRIC_NODE }; /* clang-format on */ @@ -617,8 +618,8 @@ static int cmd_try_do_shortcut(enum node_type node, char *first_word) */ static int compare_completions(const void *fst, const void *snd) { - struct cmd_token *first = *(struct cmd_token **)fst, - *secnd = *(struct cmd_token **)snd; + const struct cmd_token *first = *(const struct cmd_token * const *)fst, + *secnd = *(const struct cmd_token * const *)snd; return strcmp(first->text, secnd->text); } @@ -1197,6 +1198,7 @@ static int handle_pipe_action(struct vty *vty, const char *cmd_in, /* retrieve action */ token = strsep(&working, " "); + assert(token); /* match result to known actions */ if (strmatch(token, "include")) { @@ -1435,6 +1437,7 @@ void cmd_exit(struct vty *vty) case LDP_NODE: case LDP_L2VPN_NODE: case ISIS_NODE: + case OPENFABRIC_NODE: case KEYCHAIN_NODE: case RMAP_NODE: case PBRMAP_NODE: @@ -1550,6 +1553,7 @@ DEFUN (config_end, case LDP_L2VPN_NODE: case LDP_PSEUDOWIRE_NODE: case ISIS_NODE: + case OPENFABRIC_NODE: case KEYCHAIN_NODE: case KEYCHAIN_KEY_NODE: case VTY_NODE: @@ -2417,7 +2421,7 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) cwd[MAXPATHLEN] = '\0'; if (getcwd(cwd, MAXPATHLEN) == NULL) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "config_log_file: Unable to alloc mem!"); return CMD_WARNING_CONFIG_FAILED; } diff --git a/lib/command.h b/lib/command.h index 75b69507ec..8e51641b88 100644 --- a/lib/command.h +++ b/lib/command.h @@ -141,6 +141,7 @@ enum node_type { BGP_FLOWSPECV6_NODE, /* BGP IPv6 FLOWSPEC Address-Family */ BFD_NODE, /* BFD protocol mode. */ BFD_PEER_NODE, /* BFD peer configuration mode. */ + OPENFABRIC_NODE, /* OpenFabric router configuration node */ NODE_TYPE_MAX, /* maximum */ }; @@ -364,7 +365,6 @@ struct cmd_node { #define PREFIX_LIST_STR "Build a prefix list\n" #define OSPF6_DUMP_TYPE_LIST \ "<neighbor|interface|area|lsa|zebra|config|dbex|spf|route|lsdb|redistribute|hook|asbr|prefix|abr>" -#define ISIS_STR "IS-IS information\n" #define AREA_TAG_STR "[area tag]\n" #define COMMUNITY_AANN_STR "Community number where AA and NN are (0-65535)\n" #define COMMUNITY_VAL_STR "Community number in AA:NN format (where AA and NN are (0-65535)) or local-AS|no-advertise|no-export|internet or additive\n" diff --git a/lib/command_lex.l b/lib/command_lex.l index 0d6e6ee7e5..3b18b58a2e 100644 --- a/lib/command_lex.l +++ b/lib/command_lex.l @@ -22,6 +22,11 @@ * 02111-1307, USA. */ +%top{ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +} %{ /* ignore flex generated code in static analyzer */ #ifndef __clang_analyzer__ diff --git a/lib/command_match.c b/lib/command_match.c index c165305d78..a1ae3ac6b9 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -195,7 +195,7 @@ static enum matcher_rv command_match_r(struct graph_node *start, vector vline, enum matcher_rv status = MATCHER_NO_MATCH; // get the minimum match level that can count as a full match - struct cmd_token *token = start->data; + struct cmd_token *copy, *token = start->data; enum match_type minmatch = min_match_level(token->type); /* check history/stack of tokens @@ -326,8 +326,8 @@ static enum matcher_rv command_match_r(struct graph_node *start, vector vline, } if (*currbest) { // copy token, set arg and prepend to currbest - struct cmd_token *token = start->data; - struct cmd_token *copy = cmd_token_dup(token); + token = start->data; + copy = cmd_token_dup(token); copy->arg = XSTRDUP(MTYPE_CMD_ARG, input_token); listnode_add_before(*currbest, (*currbest)->head, copy); } else if (n + 1 == vector_active(vline) && status == MATCHER_NO_MATCH) @@ -17,6 +17,11 @@ * 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 */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdio.h> #include <stdlib.h> #include <string.h> @@ -563,6 +568,8 @@ void csv_decode(csv_t *csv, char *inbuf) csv_record_t *rec; buf = (inbuf) ? inbuf : csv->buf; + assert(buf); + pos = strpbrk(buf, "\n"); while (pos != NULL) { rec = calloc(1, sizeof(csv_record_t)); diff --git a/lib/defun_lex.l b/lib/defun_lex.l index d901c26a2e..6c0805a4fa 100644 --- a/lib/defun_lex.l +++ b/lib/defun_lex.l @@ -1,4 +1,3 @@ -%{ /* * clippy (CLI preparator in python) C pseudo-lexer * Copyright (C) 2016-2017 David Lamparter for NetDEF, Inc. @@ -34,6 +33,12 @@ * code documentation in it. */ +%top{ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif +} +%{ /* ignore harmless bugs in old versions of flex */ #pragma GCC diagnostic ignored "-Wsign-compare" #pragma GCC diagnostic ignored "-Wunused-value" diff --git a/lib/ferr.c b/lib/ferr.c index 35d0fe4ff4..afef196cec 100644 --- a/lib/ferr.c +++ b/lib/ferr.c @@ -14,6 +14,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdlib.h> #include <stdarg.h> #include <string.h> @@ -148,7 +152,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json) snprintf(pbuf, sizeof(pbuf), "\nError %"PRIu32" - %s", ref->code, ref->title); memset(ubuf, '=', strlen(pbuf)); - ubuf[strlen(pbuf) - 1] = '\0'; + ubuf[strlen(pbuf)] = '\0'; vty_out(vty, "%s\n%s\n", pbuf, ubuf); vty_out(vty, "Description:\n%s\n\n", ref->description); diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index c0aae5e52e..d48b23f38a 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -19,6 +19,9 @@ #include <zebra.h> #include <pthread.h> +#ifdef HAVE_PTHREAD_NP_H +#include <pthread_np.h> +#endif #include <sched.h> #include "frr_pthread.h" @@ -163,10 +166,14 @@ int frr_pthread_set_name(struct frr_pthread *fpt, const char *name, pthread_mutex_lock(&fpt->mtx); snprintf(fpt->os_name, OS_THREAD_NAMELEN, "%s", os_name); pthread_mutex_unlock(&fpt->mtx); -#ifdef GNU_LINUX +#ifdef HAVE_PTHREAD_SETNAME_NP +# ifdef GNU_LINUX ret = pthread_setname_np(fpt->thread, fpt->os_name); -#elif defined(OPEN_BSD) - ret = pthread_set_name_np(fpt->thread, fpt->os_name); +# else /* NetBSD */ + ret = pthread_setname_np(fpt->thread, fpt->os_name, NULL); +# endif +#elif defined(HAVE_PTHREAD_SET_NAME_NP) + pthread_set_name_np(fpt->thread, fpt->os_name); #endif } diff --git a/lib/frr_pthread.h b/lib/frr_pthread.h index cc4fc74337..732e2925fe 100644 --- a/lib/frr_pthread.h +++ b/lib/frr_pthread.h @@ -234,4 +234,8 @@ void frr_pthread_yield(void); */ uint32_t frr_pthread_get_id(void); +#ifndef HAVE_PTHREAD_CONDATTR_SETCLOCK +#define pthread_condattr_setclock(A, B) +#endif + #endif /* _FRR_PTHREAD_H */ diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index 02d9b68bc1..cfea238d95 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -141,8 +141,8 @@ static int frrzmq_read_msg(struct thread *t) return 0; out_err: - flog_err(LIB_ERR_ZMQ, "ZeroMQ read error: %s(%d)", strerror(errno), - errno); + flog_err(EC_LIB_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; @@ -255,8 +255,8 @@ static int frrzmq_write_msg(struct thread *t) return 0; out_err: - flog_err(LIB_ERR_ZMQ, "ZeroMQ write error: %s(%d)", strerror(errno), - errno); + flog_err(EC_LIB_ZMQ, "ZeroMQ write error: %s(%d)", strerror(errno), + errno); if (cb->write.cb_error) cb->write.cb_error(cb->write.arg, cb->zmqsock); return 1; diff --git a/lib/frrstr.c b/lib/frrstr.c index 715e67b868..85d968182b 100644 --- a/lib/frrstr.c +++ b/lib/frrstr.c @@ -18,6 +18,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <string.h> #include <ctype.h> #include <sys/types.h> diff --git a/lib/grammar_sandbox.c b/lib/grammar_sandbox.c index 51e7a3987e..0d6200b006 100644 --- a/lib/grammar_sandbox.c +++ b/lib/grammar_sandbox.c @@ -23,6 +23,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "command.h" #include "memory_vty.h" #include "graph.h" @@ -311,7 +315,7 @@ static void cmd_graph_permute(struct list *out, struct graph_node **stack, struct graph_node *gn = stack[stackpos]; struct cmd_token *tok = gn->data; char *appendp = cmd + strlen(cmd); - size_t i, j; + size_t j; if (tok->type < SPECIAL_TKN) { sprintf(appendp, "%s ", tok->text); @@ -328,7 +332,7 @@ static void cmd_graph_permute(struct list *out, struct graph_node **stack, if (++stackpos == CMD_ARGC_MAX) return; - for (i = 0; i < vector_active(gn->to); i++) { + for (size_t i = 0; i < vector_active(gn->to); i++) { struct graph_node *gnext = vector_slot(gn->to, i); for (j = 0; j < stackpos; j++) if (stack[j] == gnext) diff --git a/lib/grammar_sandbox_main.c b/lib/grammar_sandbox_main.c index 264c7c48f0..c9c942f9bf 100644 --- a/lib/grammar_sandbox_main.c +++ b/lib/grammar_sandbox_main.c @@ -23,6 +23,10 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "command.h" #include "memory_vty.h" diff --git a/lib/hook.c b/lib/hook.c index 935064f4d2..4fe305f282 100644 --- a/lib/hook.c +++ b/lib/hook.c @@ -20,6 +20,10 @@ * DEALINGS IN THE SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "memory.h" #include "hook.h" @@ -63,7 +63,7 @@ int ptm_enable = 0; * before all numbers. Examples: de0 < de1, de100 < fxp0 < xl0, devpty < * devpty0, de0 < del0 */ -int if_cmp_name_func(char *p1, char *p2) +int if_cmp_name_func(const char *p1, const char *p2) { unsigned int l1, l2; long int x1, x2; @@ -99,8 +99,8 @@ int if_cmp_name_func(char *p1, char *p2) if (!*p2) return 1; - x1 = strtol(p1, &p1, 10); - x2 = strtol(p2, &p2, 10); + x1 = strtol(p1, (char **)&p1, 10); + x2 = strtol(p2, (char **)&p2, 10); /* let's compare numbers now */ if (x1 < x2) @@ -121,7 +121,7 @@ int if_cmp_name_func(char *p1, char *p2) static int if_cmp_func(const struct interface *ifp1, const struct interface *ifp2) { - return if_cmp_name_func((char *)ifp1->name, (char *)ifp2->name); + return if_cmp_name_func(ifp1->name, ifp2->name); } static int if_cmp_index_func(const struct interface *ifp1, @@ -371,37 +371,47 @@ struct interface *if_lookup_prefix(struct prefix *prefix, vrf_id_t vrf_id) one. */ struct interface *if_get_by_name(const char *name, vrf_id_t vrf_id, int vty) { - struct interface *ifp; + struct interface *ifp = NULL; - ifp = if_lookup_by_name(name, vrf_id); - if (ifp) - return ifp; - /* Not Found on same VRF. If the interface command - * was entered in vty without a VRF (passed as VRF_DEFAULT), - * accept the ifp we found. If a vrf was entered and there is - * a mismatch, reject it if from vty. - */ - ifp = if_lookup_by_name_all_vrf(name); - if (!ifp) + if (vrf_is_mapped_on_netns(vrf_lookup_by_id(vrf_id))) { + ifp = if_lookup_by_name(name, vrf_id); + if (ifp) + return ifp; + if (vty) { + /* If the interface command was entered in vty without a + * VRF (passed as VRF_DEFAULT), search an interface with + * this name in all VRs + */ + if (vrf_id == VRF_DEFAULT) + return if_lookup_by_name_all_vrf(name); + return NULL; + } return if_create(name, vrf_id); - if (vty) { - if (vrf_id == VRF_DEFAULT) + } + /* vrf is based on vrf-lite */ + ifp = if_lookup_by_name_all_vrf(name); + if (ifp) { + if (ifp->vrf_id == vrf_id) return ifp; - return NULL; + /* Found a match on a different VRF. If the interface command + * was entered in vty without a VRF (passed as VRF_DEFAULT), + * accept the ifp we found. If a vrf was entered and there is a + * mismatch, reject it if from vty. If it came from the kernel + * or by way of zclient, believe it and update the ifp + * accordingly. + */ + if (vty) { + if (vrf_id == VRF_DEFAULT) + return ifp; + return NULL; + } + /* If it came from the kernel or by way of zclient, believe it + * and update the ifp accordingly. + */ + if_update_to_new_vrf(ifp, vrf_id); + return ifp; } - /* if vrf backend uses NETNS, then - * this should not be considered as an update - * then create the new interface - */ - if (ifp->vrf_id != vrf_id && vrf_is_mapped_on_netns( - vrf_lookup_by_id(vrf_id))) - return if_create(name, vrf_id); - /* If it came from the kernel - * or by way of zclient, believe it and update - * the ifp accordingly. - */ - if_update_to_new_vrf(ifp, vrf_id); - return ifp; + return if_create(name, vrf_id); } void if_set_index(struct interface *ifp, ifindex_t ifindex) @@ -619,7 +629,7 @@ DEFUN (no_interface_desc, * if not: * - no idea, just get the name in its entirety. */ -static struct interface *if_sunwzebra_get(char *name, vrf_id_t vrf_id) +static struct interface *if_sunwzebra_get(const char *name, vrf_id_t vrf_id) { struct interface *ifp; char *cp; @@ -1149,7 +1159,7 @@ const char *if_link_type_str(enum zebra_link_type llt) llts(ZEBRA_LLT_IEEE802154, "IEEE 802.15.4"); llts(ZEBRA_LLT_IEEE802154_PHY, "IEEE 802.15.4 Phy"); default: - flog_err(LIB_ERR_DEVELOPMENT, "Unknown value %d", llt); + flog_err(EC_LIB_DEVELOPMENT, "Unknown value %d", llt); return "Unknown type!"; #undef llts } @@ -297,35 +297,31 @@ DECLARE_QOBJ_TYPE(interface) #define IFNAME_RB_INSERT(vrf, ifp) \ if (RB_INSERT(if_name_head, &vrf->ifaces_by_name, (ifp))) \ - flog_err( \ - LIB_ERR_INTERFACE, \ - "%s(%s): corruption detected -- interface with this " \ - "name exists already in VRF %u!", \ - __func__, (ifp)->name, (ifp)->vrf_id); + flog_err(EC_LIB_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) \ - 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); + flog_err(EC_LIB_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))) \ - flog_err( \ - LIB_ERR_INTERFACE, \ - "%s(%u): corruption detected -- interface with this " \ - "ifindex exists already in VRF %u!", \ - __func__, (ifp)->ifindex, (ifp)->vrf_id); + flog_err(EC_LIB_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) \ - 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); + flog_err(EC_LIB_INTERFACE, \ + "%s(%u): corruption detected -- interface with this " \ + "ifindex doesn't exist in VRF %u!", \ + __func__, (ifp)->ifindex, (ifp)->vrf_id); #define FOR_ALL_INTERFACES(vrf, ifp) \ if (vrf) \ @@ -455,7 +451,7 @@ struct nbr_connected { #endif /* IFF_VIRTUAL */ /* Prototypes. */ -extern int if_cmp_name_func(char *, char *); +extern int if_cmp_name_func(const char *p1, const char *p2); /* * Passing in VRF_UNKNOWN is a valid thing to do, unless we diff --git a/lib/imsg-buffer.c b/lib/imsg-buffer.c index b83f1f76f2..c2f4052b8f 100644 --- a/lib/imsg-buffer.c +++ b/lib/imsg-buffer.c @@ -21,9 +21,9 @@ #include "queue.h" #include "imsg.h" -int ibuf_realloc(struct ibuf *, size_t); -void ibuf_enqueue(struct msgbuf *, struct ibuf *); -void ibuf_dequeue(struct msgbuf *, struct ibuf *); +static int ibuf_realloc(struct ibuf *, size_t); +static void ibuf_enqueue(struct msgbuf *, struct ibuf *); +static void ibuf_dequeue(struct msgbuf *, struct ibuf *); struct ibuf *ibuf_open(size_t len) { @@ -57,7 +57,7 @@ struct ibuf *ibuf_dynamic(size_t len, size_t max) return (buf); } -int ibuf_realloc(struct ibuf *buf, size_t len) +static int ibuf_realloc(struct ibuf *buf, size_t len) { uint8_t *b; @@ -183,6 +183,8 @@ void msgbuf_drain(struct msgbuf *msgbuf, size_t n) next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; + + TAILQ_REMOVE(&msgbuf->bufs, buf, entry); ibuf_dequeue(msgbuf, buf); } else { buf->rpos += n; @@ -195,7 +197,7 @@ void msgbuf_clear(struct msgbuf *msgbuf) { struct ibuf *buf; - while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) + while ((buf = TAILQ_POP_FIRST(&msgbuf->bufs, entry)) != NULL) ibuf_dequeue(msgbuf, buf); } @@ -266,16 +268,15 @@ again: return (1); } -void ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) +static void ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } -void ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) +static void ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { - TAILQ_REMOVE(&msgbuf->bufs, buf, entry); - + /* TAILQ_REMOVE done by caller */ if (buf->fd != -1) close(buf->fd); diff --git a/lib/imsg.c b/lib/imsg.c index 5424140720..935d137727 100644 --- a/lib/imsg.c +++ b/lib/imsg.c @@ -299,11 +299,10 @@ int imsg_get_fd(struct imsgbuf *ibuf) int fd; struct imsg_fd *ifd; - if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL) + if ((ifd = TAILQ_POP_FIRST(&ibuf->fds, entry)) == NULL) return (-1); fd = ifd->fd; - TAILQ_REMOVE(&ibuf->fds, ifd, entry); free(ifd); return (fd); diff --git a/lib/lib_errors.c b/lib/lib_errors.c index 332a5b1d45..03ad974da6 100644 --- a/lib/lib_errors.c +++ b/lib/lib_errors.c @@ -18,90 +18,136 @@ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include "lib_errors.h" /* clang-format off */ +static struct log_ref ferr_lib_warn[] = { + { + .code = EC_LIB_SNMP, + .title = "SNMP has discovered a warning", + .description = "The SNMP AgentX library has returned a warning that we should report to the end user", + .suggestion = "Gather Log data and open an Issue.", + }, + { + .code = EC_LIB_STREAM, + .title = "The stream subsystem has encountered an error", + .description = "During sanity checking stream.c has detected an error in the data associated with a particular stream", + .suggestion = "Gather log data and open an Issue, restart FRR", + }, + { + .code = EC_LIB_LINUX_NS, + .title = "The Linux namespace subsystem has encountered a parsing error", + .description = "During system startup an invalid parameter for the namesapce was give to FRR", + .suggestion = "Gather log data and open an Issue. restart FRR", + }, + { + .code = EC_LIB_SLOW_THREAD, + .title = "The Event subsystem has detected a slow process", + .description = "The Event subsystem has detected a slow process, this typically indicates that FRR is having trouble completing work in a timely manner. This can be either a misconfiguration, bug, or some combination therof.", + .suggestion = "Gather log data and open an Issue", + }, + { + .code = EC_LIB_RMAP_RECURSION_LIMIT, + .title = "Reached the Route-Map Recursion Limit", + .description = "The Route-Map subsystem has detected a route-map depth of RMAP_RECURSION_LIMIT and has stopped processing", + .suggestion = "Re-work the Route-Map in question to not have so many route-map statements, or recompile FRR with a higher limit", + }, + { + .code = EC_LIB_BACKUP_CONFIG, + .title = "Unable to open configuration file", + .description = "The config subsystem attempted to read in it's configuration file which failed, so we are falling back to the backup config file to see if it is available", + .suggestion = "Create configuration file", + }, + { + .code = EC_LIB_VRF_LENGTH, + .title = "The VRF subsystem has encountered a parsing error", + .description = "The VRF subsystem, during initialization, has found a parsing error with input it has received", + .suggestion = "Check the length of the vrf name and adjust accordingly", + }, + { + .code = END_FERR, + }, +}; + static struct log_ref ferr_lib_err[] = { { - .code = LIB_ERR_PRIVILEGES, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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", + .suggestion = "Ensure that there are sufficient system resources available and ensure that the frr user has sufficient permisions to work. If necessary open an Issue", }, { - .code = LIB_ERR_ZAPI_MISSMATCH, + .code = EC_LIB_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, + .code = EC_LIB_ZAPI_ENCODE, .title = "ZAPI Error", .description = "The ZAPI subsystem has detected an encoding issue, between zebra and a client protocol", - .suggestion = "Restart FRR" + .suggestion = "Gather data and open an Issue, also Restart FRR" }, { - .code = LIB_ERR_ZAPI_SOCKET, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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, + .code = EC_LIB_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" @@ -114,5 +160,6 @@ static struct log_ref ferr_lib_err[] = { void lib_error_init(void) { + log_ref_add(ferr_lib_warn); log_ref_add(ferr_lib_err); } diff --git a/lib/lib_errors.h b/lib/lib_errors.h index 84f5b8dc10..e0f698a07d 100644 --- a/lib/lib_errors.h +++ b/lib/lib_errors.h @@ -24,20 +24,26 @@ #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, + EC_LIB_PRIVILEGES = LIB_FERR_START, + EC_LIB_VRF_START, + EC_LIB_SOCKET, + EC_LIB_ZAPI_MISSMATCH, + EC_LIB_ZAPI_ENCODE, + EC_LIB_ZAPI_SOCKET, + EC_LIB_SYSTEM_CALL, + EC_LIB_VTY, + EC_LIB_INTERFACE, + EC_LIB_NS, + EC_LIB_DEVELOPMENT, + EC_LIB_ZMQ, + EC_LIB_UNAVAILABLE, + EC_LIB_SNMP, + EC_LIB_STREAM, + EC_LIB_LINUX_NS, + EC_LIB_SLOW_THREAD, + EC_LIB_RMAP_RECURSION_LIMIT, + EC_LIB_BACKUP_CONFIG, + EC_LIB_VRF_LENGTH, }; extern void lib_error_init(void); diff --git a/lib/libfrr.c b/lib/libfrr.c index 821c57f37b..69e6882617 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -262,6 +262,34 @@ bool frr_zclient_addr(struct sockaddr_storage *sa, socklen_t *sa_len, static struct frr_daemon_info *di = NULL; +static void frr_guard_daemon(void) +{ + int fd; + struct flock lock; + const char *path = di->pid_file; + + fd = open(path, O_RDWR); + if (fd != -1) { + memset(&lock, 0, sizeof(lock)); + lock.l_type = F_WRLCK; + lock.l_whence = SEEK_SET; + if (fcntl(fd, F_GETLK, &lock) < 0) { + flog_err_sys( + EC_LIB_SYSTEM_CALL, + "Could not do F_GETLK pid_file %s (%s), exiting", + path, safe_strerror(errno)); + exit(1); + } else if (lock.l_type == F_WRLCK) { + flog_err_sys( + EC_LIB_SYSTEM_CALL, + "Process %d has a write lock on file %s already! Error: (%s)", + lock.l_pid, path, safe_strerror(errno)); + exit(1); + } + close(fd); + } +} + void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv) { di = daemon; @@ -517,13 +545,15 @@ static void frr_mkdir(const char *path, bool strip) if (errno == EEXIST) return; - zlog_warn("failed to mkdir \"%s\": %s", path, strerror(errno)); + flog_err(EC_LIB_SYSTEM_CALL, "failed to mkdir \"%s\": %s", path, + strerror(errno)); return; } zprivs_get_ids(&ids); if (chown(path, ids.uid_normal, ids.gid_normal)) - zlog_warn("failed to chown \"%s\": %s", path, strerror(errno)); + flog_err(EC_LIB_SYSTEM_CALL, "failed to chown \"%s\": %s", path, + strerror(errno)); } static struct thread_master *master; @@ -589,6 +619,9 @@ struct thread_master *frr_init(void) zprivs_init(di->privs); + /* Guard to prevent a second instance of this daemon */ + frr_guard_daemon(); + master = thread_master_create(NULL); signal_init(master, di->n_signals, di->signals); @@ -829,7 +862,7 @@ static void frr_terminal_close(int isexit) nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); if (nullfd == -1) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "%s: failed to open /dev/null: %s", __func__, safe_strerror(errno)); } else { @@ -902,7 +935,7 @@ void frr_run(struct thread_master *master) } else if (di->daemon_mode) { int nullfd = open("/dev/null", O_RDONLY | O_NOCTTY); if (nullfd == -1) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "%s: failed to open /dev/null: %s", __func__, safe_strerror(errno)); } else { diff --git a/lib/linklist.c b/lib/linklist.c index effd384e46..bee9d05a2c 100644 --- a/lib/linklist.c +++ b/lib/linklist.c @@ -318,8 +318,8 @@ void list_sort(struct list *list, int (*cmp)(const void **, const void **)) qsort(items, n, sizeof(void *), realcmp); - for (unsigned int i = 0; i < n; ++i) - listnode_add(list, items[i]); + for (unsigned int j = 0; j < n; ++j) + listnode_add(list, items[j]); XFREE(MTYPE_TMP, items); } @@ -634,7 +634,7 @@ void zlog_backtrace(int priority) size = backtrace(array, array_size(array)); if (size <= 0 || (size_t)size > array_size(array)) { flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_SYSTEM_CALL, "Cannot get backtrace, returned invalid # of frames %d " "(valid range is between 1 and %lu)", size, (unsigned long)(array_size(array))); @@ -642,7 +642,7 @@ void zlog_backtrace(int priority) } zlog(priority, "Backtrace for %d stack frames:", size); if (!(strings = backtrace_symbols(array, size))) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "Cannot get backtrace symbols (out of memory?)"); for (i = 0; i < size; i++) zlog(priority, "[bt %d] %p", i, array[i]); @@ -716,7 +716,7 @@ void _zlog_assert_failed(const char *assertion, const char *file, void memory_oom(size_t size, const char *name) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "out of memory: failed to allocate %zu bytes for %s" "object", size, name); @@ -872,7 +872,7 @@ int zlog_rotate(void) pthread_mutex_unlock(&loglock); flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_SYSTEM_CALL, "Log rotate failed: cannot open file %s for append: %s", zl->filename, safe_strerror(save_errno)); ret = -1; @@ -925,7 +925,6 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_IMPORT_ROUTE_REGISTER), DESC_ENTRY(ZEBRA_IMPORT_ROUTE_UNREGISTER), DESC_ENTRY(ZEBRA_IMPORT_CHECK_UPDATE), - DESC_ENTRY(ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD), DESC_ENTRY(ZEBRA_BFD_DEST_REGISTER), DESC_ENTRY(ZEBRA_BFD_DEST_DEREGISTER), DESC_ENTRY(ZEBRA_BFD_DEST_UPDATE), @@ -946,6 +945,7 @@ static const struct zebra_desc_table command_types[] = { DESC_ENTRY(ZEBRA_MPLS_LABELS_DELETE), DESC_ENTRY(ZEBRA_IPMR_ROUTE_STATS), DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT), + DESC_ENTRY(ZEBRA_LABEL_MANAGER_CONNECT_ASYNC), DESC_ENTRY(ZEBRA_GET_LABEL_CHUNK), DESC_ENTRY(ZEBRA_RELEASE_LABEL_CHUNK), DESC_ENTRY(ZEBRA_ADVERTISE_ALL_VNI), @@ -990,8 +990,8 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute) unsigned int i; if (zroute >= array_size(route_types)) { - flog_err(LIB_ERR_DEVELOPMENT, "unknown zebra route type: %u", - zroute); + flog_err(EC_LIB_DEVELOPMENT, "unknown zebra route type: %u", + zroute); return &unknown; } if (zroute == route_types[zroute].type) @@ -1005,9 +1005,8 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute) return &route_types[i]; } } - flog_err(LIB_ERR_DEVELOPMENT, - "internal error: cannot find route type %u in table!", - zroute); + flog_err(EC_LIB_DEVELOPMENT, + "internal error: cannot find route type %u in table!", zroute); return &unknown; } @@ -1024,8 +1023,8 @@ char zebra_route_char(unsigned int zroute) const char *zserv_command_string(unsigned int command) { if (command >= array_size(command_types)) { - flog_err(LIB_ERR_DEVELOPMENT, "unknown zserv command type: %u", - command); + flog_err(EC_LIB_DEVELOPMENT, "unknown zserv command type: %u", + command); return unknown.string; } return command_types[command].string; @@ -1075,6 +1074,8 @@ int proto_redistnum(int afi, const char *s) return ZEBRA_ROUTE_BABEL; else if (strmatch(s, "sharp")) return ZEBRA_ROUTE_SHARP; + else if (strmatch(s, "openfabric")) + return ZEBRA_ROUTE_OPENFABRIC; } if (afi == AFI_IP6) { if (strmatch(s, "kernel")) @@ -1103,6 +1104,8 @@ int proto_redistnum(int afi, const char *s) return ZEBRA_ROUTE_BABEL; else if (strmatch(s, "sharp")) return ZEBRA_ROUTE_SHARP; + else if (strmatch(s, "openfabric")) + return ZEBRA_ROUTE_OPENFABRIC; } return -1; } @@ -90,6 +90,8 @@ extern void zlog_debug(const char *format, ...) PRINTF_ATTRIBUTE(1, 2); zlog_err("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__) #define flog_err_sys(ferr_id, format, ...) \ flog_err(ferr_id, format, ##__VA_ARGS__) +#define flog_warn(ferr_id, format, ...) \ + zlog_warn("[EC %"PRIu32"] " format, ferr_id, ##__VA_ARGS__) extern void zlog_thread_info(int log_level); diff --git a/lib/memory.c b/lib/memory.c index 695bbfe115..fee23a75ac 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -20,6 +20,9 @@ #ifdef HAVE_MALLOC_H #include <malloc.h> #endif +#ifdef HAVE_MALLOC_NP_H +#include <malloc_np.h> +#endif #ifdef HAVE_MALLOC_MALLOC_H #include <malloc/malloc.h> #endif diff --git a/lib/memory_vty.c b/lib/memory_vty.c index 73a18529a2..5fd9c3b900 100644 --- a/lib/memory_vty.c +++ b/lib/memory_vty.c @@ -28,7 +28,9 @@ #include <malloc/malloc.h> #endif #include <dlfcn.h> +#ifdef HAVE_LINK_H #include <link.h> +#endif #include "log.h" #include "memory.h" diff --git a/lib/netns_linux.c b/lib/netns_linux.c index 33338ac89c..ef2f5dc953 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -219,7 +219,7 @@ static int ns_enable_internal(struct ns *ns, void (*func)(ns_id_t, void *)) } if (!ns_is_enabled(ns)) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "Can not enable NS %u: %s!", ns->ns_id, safe_strerror(errno)); return 0; @@ -227,9 +227,9 @@ static int ns_enable_internal(struct ns *ns, void (*func)(ns_id_t, void *)) /* Non default NS. leave */ if (ns->ns_id == NS_UNKNOWN) { - flog_err(LIB_ERR_NS, - "Can not enable NS %s %u: Invalid NSID", - ns->name, ns->ns_id); + flog_err(EC_LIB_NS, + "Can not enable NS %s %u: Invalid NSID", + ns->name, ns->ns_id); return 0; } if (func) @@ -441,8 +441,8 @@ char *ns_netns_pathname(struct vty *vty, const char *name) pathname, safe_strerror(errno)); else - zlog_warn("Invalid pathname for %s: %s", - pathname, + flog_warn(EC_LIB_LINUX_NS, + "Invalid pathname for %s: %s", pathname, safe_strerror(errno)); return NULL; } @@ -452,7 +452,8 @@ char *ns_netns_pathname(struct vty *vty, const char *name) vty_out(vty, "NS name (%s) invalid: too long (>%d)\n", check_base, NS_NAMSIZ - 1); else - zlog_warn("NS name (%s) invalid: too long (>%d)", + flog_warn(EC_LIB_LINUX_NS, + "NS name (%s) invalid: too long (>%d)", check_base, NS_NAMSIZ - 1); return NULL; } @@ -486,8 +487,8 @@ void ns_init_management(ns_id_t default_ns_id, ns_id_t internal_ns) ns_init(); default_ns = ns_get_created_internal(NULL, NULL, default_ns_id); if (!default_ns) { - flog_err(LIB_ERR_NS, "%s: failed to create the default NS!", - __func__); + flog_err(EC_LIB_NS, "%s: failed to create the default NS!", + __func__); exit(1); } if (have_netns()) { @@ -504,8 +505,8 @@ void ns_init_management(ns_id_t default_ns_id, ns_id_t internal_ns) /* Enable the default NS. */ if (!ns_enable(default_ns, NULL)) { - flog_err(LIB_ERR_NS, "%s: failed to enable the default NS!", - __func__); + flog_err(EC_LIB_NS, "%s: failed to enable the default NS!", + __func__); exit(1); } } diff --git a/lib/network.c b/lib/network.c index 6d3350ad49..411661a5e1 100644 --- a/lib/network.c +++ b/lib/network.c @@ -22,6 +22,7 @@ #include <zebra.h> #include "log.h" #include "network.h" +#include "lib_errors.h" /* Read nbytes from fd and store into ptr. */ int readn(int fd, uint8_t *ptr, int nbytes) @@ -78,13 +79,15 @@ int set_nonblocking(int fd) should never be negative. */ if ((flags = fcntl(fd, F_GETFL)) < 0) { - zlog_warn("fcntl(F_GETFL) failed for fd %d: %s", fd, - safe_strerror(errno)); + flog_err(EC_LIB_SYSTEM_CALL, + "fcntl(F_GETFL) failed for fd %d: %s", fd, + safe_strerror(errno)); return -1; } if (fcntl(fd, F_SETFL, (flags | O_NONBLOCK)) < 0) { - zlog_warn("fcntl failed setting fd %d non-blocking: %s", fd, - safe_strerror(errno)); + flog_err(EC_LIB_SYSTEM_CALL, + "fcntl failed setting fd %d non-blocking: %s", fd, + safe_strerror(errno)); return -1; } return 0; diff --git a/lib/openbsd-tree.c b/lib/openbsd-tree.c index 35bfce3a89..e8d13339b6 100644 --- a/lib/openbsd-tree.c +++ b/lib/openbsd-tree.c @@ -41,6 +41,10 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdlib.h> #include <lib/openbsd-tree.h> diff --git a/lib/pid_output.c b/lib/pid_output.c index c6120de861..b0643c4fe2 100644 --- a/lib/pid_output.c +++ b/lib/pid_output.c @@ -42,7 +42,7 @@ pid_t pid_output(const char *path) oldumask = umask(0777 & ~PIDFILE_MASK); fd = open(path, O_RDWR | O_CREAT, PIDFILE_MASK); if (fd < 0) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "Can't create pid lock file %s (%s), exiting", path, safe_strerror(errno)); umask(oldumask); @@ -59,7 +59,7 @@ pid_t pid_output(const char *path) lock.l_whence = SEEK_SET; if (fcntl(fd, F_SETLK, &lock) < 0) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "Could not lock pid_file %s (%s), exiting", path, safe_strerror(errno)); exit(1); @@ -69,12 +69,12 @@ pid_t pid_output(const char *path) pidsize = strlen(buf); if ((tmp = write(fd, buf, pidsize)) != (int)pidsize) flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_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) flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_SYSTEM_CALL, "Could not truncate pid_file %s to %u bytes: %s", path, (unsigned int)pidsize, safe_strerror(errno)); diff --git a/lib/plist.c b/lib/plist.c index 5746080127..ee68fbc0f1 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -930,7 +930,10 @@ static int vty_prefix_list_install(struct vty *vty, afi_t afi, const char *name, char buf_tmp[PREFIX2STR_BUFFER]; prefix2str(&p, buf, sizeof(buf)); prefix2str(&p_tmp, buf_tmp, sizeof(buf_tmp)); - zlog_warn( + vty_out(vty, + "%% Prefix-list %s prefix changed from %s to %s to match length\n", + name, buf, buf_tmp); + zlog_info( "Prefix-list %s prefix changed from %s to %s to match length", name, buf, buf_tmp); p = p_tmp; @@ -1249,13 +1252,13 @@ static int vty_show_prefix_list_prefix(struct vty *vty, afi_t afi, if (pentry->any) vty_out(vty, "any"); else { - struct prefix *p = &pentry->prefix; + struct prefix *pf = &pentry->prefix; char buf[BUFSIZ]; vty_out(vty, "%s/%d", - inet_ntop(p->family, p->u.val, buf, + inet_ntop(pf->family, pf->u.val, buf, BUFSIZ), - p->prefixlen); + pf->prefixlen); if (pentry->ge) vty_out(vty, " ge %d", pentry->ge); diff --git a/lib/prefix.c b/lib/prefix.c index a7f4fda1b2..21c3af7d49 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -657,9 +657,9 @@ void prefix_copy(struct prefix *dest, const struct prefix *src) memcpy((void *)dest->u.prefix_flowspec.ptr, (void *)src->u.prefix_flowspec.ptr, len); } else { - flog_err(LIB_ERR_DEVELOPMENT, - "prefix_copy(): Unknown address family %d", - src->family); + flog_err(EC_LIB_DEVELOPMENT, + "prefix_copy(): Unknown address family %d", + src->family); assert(0); } } diff --git a/lib/privs.c b/lib/privs.c index 34905ca480..838ff8fc92 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -24,6 +24,7 @@ #include "log.h" #include "privs.h" #include "memory.h" +#include "lib_errors.h" #ifdef HAVE_CAPABILITIES @@ -288,7 +289,8 @@ zebra_privs_current_t zprivs_state_caps(void) if (cap_get_flag(zprivs_state.caps, zprivs_state.syscaps_p->caps[i], CAP_EFFECTIVE, &val)) { - zlog_warn( + flog_err( + EC_LIB_SYSTEM_CALL, "zprivs_state_caps: could not cap_get_flag, %s", safe_strerror(errno)); return ZPRIVS_UNKNOWN; diff --git a/lib/ptm_lib.c b/lib/ptm_lib.c index 69fd61e2a0..7f868beda4 100644 --- a/lib/ptm_lib.c +++ b/lib/ptm_lib.c @@ -17,6 +17,11 @@ * 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 */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdio.h> #include <stdlib.h> #include <stdbool.h> diff --git a/lib/queue.h b/lib/queue.h index 04fbeee700..11e28b4c91 100644 --- a/lib/queue.h +++ b/lib/queue.h @@ -72,4 +72,17 @@ #include "freebsd-queue.h" #endif /* defined(__OpenBSD__) && !defined(STAILQ_HEAD) */ +#ifndef TAILQ_POP_FIRST +#define TAILQ_POP_FIRST(head, field) \ + ({ typeof((head)->tqh_first) _elm = TAILQ_FIRST(head); \ + if (_elm) { \ + if ((TAILQ_NEXT((_elm), field)) != NULL) \ + TAILQ_NEXT((_elm), field)->field.tqe_prev = \ + &TAILQ_FIRST(head); \ + else \ + (head)->tqh_last = &TAILQ_FIRST(head); \ + TAILQ_FIRST(head) = TAILQ_NEXT((_elm), field); \ + }; _elm; }) +#endif + #endif /* _FRR_QUEUE_H */ diff --git a/lib/route_types.txt b/lib/route_types.txt index 72f59a1b78..c5eff44ca7 100644 --- a/lib/route_types.txt +++ b/lib/route_types.txt @@ -82,6 +82,7 @@ ZEBRA_ROUTE_BABEL, babel, babeld, 'A', 1, 1, 1, "Babel" ZEBRA_ROUTE_SHARP, sharp, sharpd, 'D', 1, 1, 1, "SHARP" ZEBRA_ROUTE_PBR, pbr, pbrd, 'F', 1, 1, 0, "PBR" ZEBRA_ROUTE_BFD, bfd, bfdd, '-', 0, 0, 0, "BFD" +ZEBRA_ROUTE_OPENFABRIC, openfabric, fabricd, 'f', 1, 1, 1, "OpenFabric" ZEBRA_ROUTE_ALL, wildcard, none, '-', 0, 0, 0, "-" @@ -109,3 +110,4 @@ ZEBRA_ROUTE_BABEL, "Babel routing protocol (Babel)" ZEBRA_ROUTE_SHARP, "Super Happy Advanced Routing Protocol (sharpd)" ZEBRA_ROUTE_PBR, "Policy Based Routing (PBR)" ZEBRA_ROUTE_BFD, "Bidirectional Fowarding Detection (BFD)" +ZEBRA_ROUTE_OPENFABRIC, "OpenFabric Routing Protocol" diff --git a/lib/routemap.c b/lib/routemap.c index e5613c2081..66c15b9f2b 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -30,6 +30,7 @@ #include "log.h" #include "hash.h" #include "libfrr.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, ROUTE_MAP, "Route map") DEFINE_MTYPE(LIB, ROUTE_MAP_NAME, "Route map name") @@ -1445,7 +1446,8 @@ route_map_result_t route_map_apply(struct route_map *map, struct route_map_rule *set; if (recursion > RMAP_RECURSION_LIMIT) { - zlog_warn( + flog_warn( + EC_LIB_RMAP_RECURSION_LIMIT, "route-map recursion limit (%d) reached, discarding route", RMAP_RECURSION_LIMIT); recursion = 0; diff --git a/lib/sigevent.c b/lib/sigevent.c index 0346027935..57b41503e1 100644 --- a/lib/sigevent.c +++ b/lib/sigevent.c @@ -84,7 +84,7 @@ int quagga_sigevent_process(void) sigdelset(&newmask, SIGKILL); if ((sigprocmask(SIG_BLOCK, &newmask, &oldmask)) < 0) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "quagga_signal_timer: couldnt block signals!"); return -1; } @@ -329,7 +329,8 @@ static void trap_default_signals(void) } if (sigaction(sigmap[i].sigs[j], &act, NULL) < 0) - zlog_warn( + flog_err( + EC_LIB_SYSTEM_CALL, "Unable to set signal handler for signal %d: %s", sigmap[i].sigs[j], safe_strerror(errno)); diff --git a/lib/skiplist.c b/lib/skiplist.c index a36bf47139..3933429c3b 100644 --- a/lib/skiplist.c +++ b/lib/skiplist.c @@ -183,8 +183,8 @@ int skiplist_insert(register struct skiplist *l, register void *key, /* DEBUG */ if (!key) { - flog_err(LIB_ERR_DEVELOPMENT, "%s: key is 0, value is %p", - __func__, value); + flog_err(EC_LIB_DEVELOPMENT, "%s: key is 0, value is %p", + __func__, value); } p = l->header; @@ -202,6 +202,7 @@ int skiplist_insert(register struct skiplist *l, register void *key, } k = randomLevel(); + assert(k >= 0); if (k > l->level) { k = ++l->level; update[k] = l->header; diff --git a/lib/sockopt.c b/lib/sockopt.c index 3febcb714d..ea04f2a43e 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -38,8 +38,9 @@ void setsockopt_so_recvbuf(int sock, int size) size /= 2; if (size != orig_req) - zlog_warn("%s: fd %d: SO_RCVBUF set to %d (requested %d)", - __func__, sock, size, orig_req); + flog_err(EC_LIB_SOCKET, + "%s: fd %d: SO_RCVBUF set to %d (requested %d)", + __func__, sock, size, orig_req); } void setsockopt_so_sendbuf(const int sock, int size) @@ -51,8 +52,9 @@ void setsockopt_so_sendbuf(const int sock, int size) size /= 2; if (size != orig_req) - zlog_warn("%s: fd %d: SO_SNDBUF set to %d (requested %d)", - __func__, sock, size, orig_req); + flog_err(EC_LIB_SOCKET, + "%s: fd %d: SO_SNDBUF set to %d (requested %d)", + __func__, sock, size, orig_req); } int getsockopt_so_sendbuf(const int sock) @@ -62,7 +64,7 @@ int getsockopt_so_sendbuf(const int sock) int ret = getsockopt(sock, SOL_SOCKET, SO_SNDBUF, (char *)&optval, &optlen); if (ret < 0) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "fd %d: can't getsockopt SO_SNDBUF: %d (%s)", sock, errno, safe_strerror(errno)); return ret; @@ -92,13 +94,14 @@ int setsockopt_ipv6_pktinfo(int sock, int val) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVPKTINFO, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_RECVPKTINFO : %s", - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "can't setsockopt IPV6_RECVPKTINFO : %s", + safe_strerror(errno)); #else /*RFC2292*/ ret = setsockopt(sock, IPPROTO_IPV6, IPV6_PKTINFO, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_PKTINFO : %s", - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_PKTINFO : %s", + safe_strerror(errno)); #endif /* INIA_IPV6 */ return ret; } @@ -114,7 +117,7 @@ int setsockopt_ipv6_checksum(int sock, int val) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_CHECKSUM, &val, sizeof(val)); #endif /* GNU_LINUX */ if (ret < 0) - zlog_warn("can't setsockopt IPV6_CHECKSUM"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_CHECKSUM"); return ret; } @@ -126,7 +129,7 @@ int setsockopt_ipv6_multicast_hops(int sock, int val) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_HOPS, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_MULTICAST_HOPS"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_MULTICAST_HOPS"); return ret; } @@ -138,7 +141,7 @@ int setsockopt_ipv6_unicast_hops(int sock, int val) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_UNICAST_HOPS"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_UNICAST_HOPS"); return ret; } @@ -150,11 +153,11 @@ int setsockopt_ipv6_hoplimit(int sock, int val) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_RECVHOPLIMIT, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_RECVHOPLIMIT"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_RECVHOPLIMIT"); #else /*RFC2292*/ ret = setsockopt(sock, IPPROTO_IPV6, IPV6_HOPLIMIT, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_HOPLIMIT"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_HOPLIMIT"); #endif return ret; } @@ -167,7 +170,7 @@ int setsockopt_ipv6_multicast_loop(int sock, int val) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MULTICAST_LOOP, &val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IPV6_MULTICAST_LOOP"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IPV6_MULTICAST_LOOP"); return ret; } @@ -188,8 +191,9 @@ int setsockopt_ipv6_tclass(int sock, int tclass) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_TCLASS, &tclass, sizeof(tclass)); if (ret < 0) - zlog_warn("Can't set IPV6_TCLASS option for fd %d to %#x: %s", - sock, tclass, safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "Can't set IPV6_TCLASS option for fd %d to %#x: %s", + sock, tclass, safe_strerror(errno)); #endif return ret; } @@ -391,7 +395,7 @@ int setsockopt_ipv4_multicast_loop(int sock, uint8_t val) ret = setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP, (void *)&val, sizeof(val)); if (ret < 0) - zlog_warn("can't setsockopt IP_MULTICAST_LOOP"); + flog_err(EC_LIB_SOCKET, "can't setsockopt IP_MULTICAST_LOOP"); return ret; } @@ -403,13 +407,15 @@ static int setsockopt_ipv4_ifindex(int sock, ifindex_t val) #if defined(IP_PKTINFO) if ((ret = setsockopt(sock, IPPROTO_IP, IP_PKTINFO, &val, sizeof(val))) < 0) - zlog_warn("Can't set IP_PKTINFO option for fd %d to %d: %s", - sock, val, safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "Can't set IP_PKTINFO option for fd %d to %d: %s", + sock, val, safe_strerror(errno)); #elif defined(IP_RECVIF) if ((ret = setsockopt(sock, IPPROTO_IP, IP_RECVIF, &val, sizeof(val))) < 0) - zlog_warn("Can't set IP_RECVIF option for fd %d to %d: %s", - sock, val, safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "Can't set IP_RECVIF option for fd %d to %d: %s", sock, + val, safe_strerror(errno)); #else #warning "Neither IP_PKTINFO nor IP_RECVIF is available." #warning "Will not be able to receive link info." @@ -427,8 +433,9 @@ int setsockopt_ipv4_tos(int sock, int tos) ret = setsockopt(sock, IPPROTO_IP, IP_TOS, &tos, sizeof(tos)); if (ret < 0) - zlog_warn("Can't set IP_TOS option for fd %d to %#x: %s", sock, - tos, safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "Can't set IP_TOS option for fd %d to %#x: %s", sock, + tos, safe_strerror(errno)); return ret; } @@ -445,7 +452,8 @@ int setsockopt_ifindex(int af, int sock, ifindex_t val) ret = setsockopt_ipv6_pktinfo(sock, val); break; default: - zlog_warn("setsockopt_ifindex: unknown address family %d", af); + flog_err(EC_LIB_DEVELOPMENT, + "setsockopt_ifindex: unknown address family %d", af); } return ret; } @@ -534,7 +542,8 @@ ifindex_t getsockopt_ifindex(int af, struct msghdr *msgh) return (getsockopt_ipv6_ifindex(msgh)); break; default: - zlog_warn("getsockopt_ifindex: unknown address family %d", af); + flog_err(EC_LIB_DEVELOPMENT, + "getsockopt_ifindex: unknown address family %d", af); return 0; } } @@ -649,7 +658,7 @@ int sockopt_tcp_signature(int sock, union sockunion *su, const char *password) ret = 0; else flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_SYSTEM_CALL, "sockopt_tcp_signature: setsockopt(%d): %s", sock, safe_strerror(errno)); } diff --git a/lib/sockunion.c b/lib/sockunion.c index bbbfbfc424..bee82a067e 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -140,9 +140,9 @@ int sockunion_socket(const union sockunion *su) sock = socket(su->sa.sa_family, SOCK_STREAM, 0); if (sock < 0) { char buf[SU_ADDRSTRLEN]; - zlog_warn("Can't make socket for %s : %s", - sockunion_log(su, buf, SU_ADDRSTRLEN), - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "Can't make socket for %s : %s", + sockunion_log(su, buf, SU_ADDRSTRLEN), + safe_strerror(errno)); return -1; } @@ -235,7 +235,8 @@ int sockunion_stream_socket(union sockunion *su) sock = socket(su->sa.sa_family, SOCK_STREAM, 0); if (sock < 0) - zlog_warn("can't make socket sockunion_stream_socket"); + flog_err(EC_LIB_SOCKET, + "can't make socket sockunion_stream_socket"); return sock; } @@ -273,9 +274,9 @@ int sockunion_bind(int sock, union sockunion *su, unsigned short port, ret = bind(sock, (struct sockaddr *)su, size); if (ret < 0) { char buf[SU_ADDRSTRLEN]; - zlog_warn("can't bind socket for %s : %s", - sockunion_log(su, buf, SU_ADDRSTRLEN), - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "can't bind socket for %s : %s", + sockunion_log(su, buf, SU_ADDRSTRLEN), + safe_strerror(errno)); } return ret; @@ -289,7 +290,8 @@ int sockopt_reuseaddr(int sock) ret = setsockopt(sock, SOL_SOCKET, SO_REUSEADDR, (void *)&on, sizeof(on)); if (ret < 0) { - zlog_warn("can't set sockopt SO_REUSEADDR to socket %d", sock); + flog_err(EC_LIB_SOCKET, + "can't set sockopt SO_REUSEADDR to socket %d", sock); return -1; } return 0; @@ -304,7 +306,8 @@ int sockopt_reuseport(int sock) ret = setsockopt(sock, SOL_SOCKET, SO_REUSEPORT, (void *)&on, sizeof(on)); if (ret < 0) { - zlog_warn("can't set sockopt SO_REUSEPORT to socket %d", sock); + flog_err(EC_LIB_SOCKET, + "can't set sockopt SO_REUSEPORT to socket %d", sock); return -1; } return 0; @@ -325,8 +328,9 @@ int sockopt_ttl(int family, int sock, int ttl) ret = setsockopt(sock, IPPROTO_IP, IP_TTL, (void *)&ttl, sizeof(int)); if (ret < 0) { - zlog_warn("can't set sockopt IP_TTL %d to socket %d", - ttl, sock); + flog_err(EC_LIB_SOCKET, + "can't set sockopt IP_TTL %d to socket %d", + ttl, sock); return -1; } return 0; @@ -336,7 +340,8 @@ int sockopt_ttl(int family, int sock, int ttl) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_UNICAST_HOPS, (void *)&ttl, sizeof(int)); if (ret < 0) { - zlog_warn( + flog_err( + EC_LIB_SOCKET, "can't set sockopt IPV6_UNICAST_HOPS %d to socket %d", ttl, sock); return -1; @@ -383,7 +388,8 @@ int sockopt_minttl(int family, int sock, int minttl) int ret = setsockopt(sock, IPPROTO_IP, IP_MINTTL, &minttl, sizeof(minttl)); if (ret < 0) - zlog_warn( + flog_err( + EC_LIB_SOCKET, "can't set sockopt IP_MINTTL to %d on socket %d: %s", minttl, sock, safe_strerror(errno)); return ret; @@ -394,7 +400,8 @@ int sockopt_minttl(int family, int sock, int minttl) int ret = setsockopt(sock, IPPROTO_IPV6, IPV6_MINHOPCOUNT, &minttl, sizeof(minttl)); if (ret < 0) - zlog_warn( + flog_err( + EC_LIB_SOCKET, "can't set sockopt IPV6_MINHOPCOUNT to %d on socket %d: %s", minttl, sock, safe_strerror(errno)); return ret; @@ -414,10 +421,10 @@ int sockopt_v6only(int family, int sock) ret = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, (void *)&on, sizeof(int)); if (ret < 0) { - zlog_warn( - "can't set sockopt IPV6_V6ONLY " - "to socket %d", - sock); + flog_err(EC_LIB_SOCKET, + "can't set sockopt IPV6_V6ONLY " + "to socket %d", + sock); return -1; } return 0; @@ -532,8 +539,9 @@ union sockunion *sockunion_getsockname(int fd) ret = getsockname(fd, (struct sockaddr *)&name, &len); if (ret < 0) { - zlog_warn("Can't get local address and port by getsockname: %s", - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "Can't get local address and port by getsockname: %s", + safe_strerror(errno)); return NULL; } @@ -568,8 +576,8 @@ union sockunion *sockunion_getpeername(int fd) len = sizeof name; ret = getpeername(fd, (struct sockaddr *)&name, &len); if (ret < 0) { - zlog_warn("Can't get remote address and port: %s", - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "Can't get remote address and port: %s", + safe_strerror(errno)); return NULL; } diff --git a/lib/srcdest_table.c b/lib/srcdest_table.c index 4497faf6fc..e49735192d 100644 --- a/lib/srcdest_table.c +++ b/lib/srcdest_table.c @@ -301,5 +301,5 @@ const char *srcdest_rnode2str(struct route_node *rn, char *str, int size) const struct prefix *dst_p, *src_p; srcdest_rnode_prefixes(rn, &dst_p, &src_p); - return srcdest2str(dst_p, (struct prefix_ipv6*)src_p, str, size); + return srcdest2str(dst_p, (const struct prefix_ipv6 *)src_p, str, size); } diff --git a/lib/stream.c b/lib/stream.c index 55e7f64358..6c187bd359 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -54,7 +54,8 @@ DEFINE_MTYPE_STATIC(LIB, STREAM_FIFO, "Stream FIFO") * using stream_put..._at() functions. */ #define STREAM_WARN_OFFSETS(S) \ - zlog_warn("&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \ + flog_warn(EC_LIB_STREAM, \ + "&(struct stream): %p, size: %lu, getp: %lu, endp: %lu\n", \ (void *)(S), (unsigned long)(S)->size, \ (unsigned long)(S)->getp, (unsigned long)(S)->endp) @@ -68,16 +69,16 @@ DEFINE_MTYPE_STATIC(LIB, STREAM_FIFO, "Stream FIFO") #define STREAM_BOUND_WARN(S, WHAT) \ do { \ - zlog_warn("%s: Attempt to %s out of bounds", __func__, \ - (WHAT)); \ + flog_warn(EC_LIB_STREAM, "%s: Attempt to %s out of bounds", \ + __func__, (WHAT)); \ STREAM_WARN_OFFSETS(S); \ assert(0); \ } while (0) #define STREAM_BOUND_WARN2(S, WHAT) \ do { \ - zlog_warn("%s: Attempt to %s out of bounds", __func__, \ - (WHAT)); \ + flog_warn(EC_LIB_STREAM, "%s: Attempt to %s out of bounds", \ + __func__, (WHAT)); \ STREAM_WARN_OFFSETS(S); \ } while (0) @@ -85,7 +86,8 @@ DEFINE_MTYPE_STATIC(LIB, STREAM_FIFO, "Stream FIFO") #define CHECK_SIZE(S, Z) \ do { \ if (((S)->endp + (Z)) > (S)->size) { \ - zlog_warn( \ + flog_warn( \ + EC_LIB_STREAM, \ "CHECK_SIZE: truncating requested size %lu\n", \ (unsigned long)(Z)); \ STREAM_WARN_OFFSETS(S); \ @@ -270,7 +272,7 @@ void stream_forward_endp(struct stream *s, size_t size) } /* Copy from stream to destination. */ -inline bool stream_get2(void *dst, struct stream *s, size_t size) +bool stream_get2(void *dst, struct stream *s, size_t size) { STREAM_VERIFY_SANE(s); @@ -299,7 +301,7 @@ void stream_get(void *dst, struct stream *s, size_t size) } /* Get next character from the stream. */ -inline bool stream_getc2(struct stream *s, uint8_t *byte) +bool stream_getc2(struct stream *s, uint8_t *byte) { STREAM_VERIFY_SANE(s); @@ -344,7 +346,7 @@ uint8_t stream_getc_from(struct stream *s, size_t from) return c; } -inline bool stream_getw2(struct stream *s, uint16_t *word) +bool stream_getw2(struct stream *s, uint16_t *word) { STREAM_VERIFY_SANE(s); @@ -465,7 +467,7 @@ void stream_get_from(void *dst, struct stream *s, size_t from, size_t size) memcpy(dst, s->data + from, size); } -inline bool stream_getl2(struct stream *s, uint32_t *l) +bool stream_getl2(struct stream *s, uint32_t *l) { STREAM_VERIFY_SANE(s); @@ -966,8 +968,8 @@ ssize_t stream_read_try(struct stream *s, int fd, size_t size) /* Error: was it transient (return -2) or fatal (return -1)? */ if (ERRNO_IO_RETRY(errno)) return -2; - zlog_warn("%s: read failed on fd %d: %s", __func__, fd, - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "%s: read failed on fd %d: %s", __func__, fd, + safe_strerror(errno)); return -1; } @@ -997,8 +999,8 @@ ssize_t stream_recvfrom(struct stream *s, int fd, size_t size, int flags, /* Error: was it transient (return -2) or fatal (return -1)? */ if (ERRNO_IO_RETRY(errno)) return -2; - zlog_warn("%s: read failed on fd %d: %s", __func__, fd, - safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "%s: read failed on fd %d: %s", __func__, fd, + safe_strerror(errno)); return -1; } diff --git a/lib/strlcat.c b/lib/strlcat.c index be211f82a8..39773d9ac8 100644 --- a/lib/strlcat.c +++ b/lib/strlcat.c @@ -20,11 +20,13 @@ /* adapted for Quagga from glibc patch submission originally from * Florian Weimer <fweimer@redhat.com>, 2016-05-18 */ +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + #include <stdint.h> #include <string.h> -#include "config.h" - #ifndef HAVE_STRLCAT #undef strlcat diff --git a/lib/strlcpy.c b/lib/strlcpy.c index b0c33ca7f4..71ee9f1a54 100644 --- a/lib/strlcpy.c +++ b/lib/strlcpy.c @@ -20,9 +20,11 @@ /* adapted for Quagga from glibc patch submission originally from * Florian Weimer <fweimer@redhat.com>, 2016-05-18 */ -#include <string.h> - +#ifdef HAVE_CONFIG_H #include "config.h" +#endif + +#include <string.h> #ifndef HAVE_STRLCPY #undef strlcpy diff --git a/lib/subdir.am b/lib/subdir.am index ef6c8f8e55..499bb94920 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -84,6 +84,22 @@ lib_libfrr_la_SOURCES = \ lib/logicalrouter.c \ # end +vtysh_scan += \ + $(top_srcdir)/lib/distribute.c \ + $(top_srcdir)/lib/filter.c \ + $(top_srcdir)/lib/if.c \ + $(top_srcdir)/lib/if_rmap.c \ + $(top_srcdir)/lib/keychain.c \ + $(top_srcdir)/lib/logicalrouter.c \ + $(top_srcdir)/lib/nexthop_group.c \ + $(top_srcdir)/lib/plist.c \ + $(top_srcdir)/lib/routemap.c \ + $(top_srcdir)/lib/vrf.c \ + $(top_srcdir)/lib/vty.c \ + # end +# can be loaded as DSO - always include for vtysh +vtysh_scan += $(top_srcdir)/lib/agentx.c + lib/plist_clippy.c: $(CLIPPY_DEPS) lib/plist.lo: lib/plist_clippy.c lib/nexthop_group_clippy.c: $(CLIPPY_DEPS) @@ -152,6 +168,7 @@ pkginclude_HEADERS += \ lib/sha256.h \ lib/sigevent.h \ lib/skiplist.h \ + lib/smux.h \ lib/sockopt.h \ lib/sockunion.h \ lib/spf_backoff.h \ @@ -237,9 +254,10 @@ lib_grammar_sandbox_SOURCES = \ lib_grammar_sandbox_LDADD = \ lib/libfrr.la -lib_clippy_CPPFLAGS = $(AM_CPPFLAGS) -D_GNU_SOURCE -DBUILDING_CLIPPY @SAN_CLIPPY_FLAGS@ -lib_clippy_CFLAGS = $(PYTHON_CFLAGS) @SAN_CLIPPY_FLAGS@ +lib_clippy_CPPFLAGS = $(AM_CPPFLAGS) -D_GNU_SOURCE -DBUILDING_CLIPPY +lib_clippy_CFLAGS = $(PYTHON_CFLAGS) lib_clippy_LDADD = $(PYTHON_LIBS) +lib_clippy_LDFLAGS = -export-dynamic lib_clippy_SOURCES = \ lib/clippy.c \ lib/command_graph.c \ @@ -252,6 +270,26 @@ lib_clippy_SOURCES = \ lib/vector.c \ # end +# (global) clippy rules for all directories + +AM_V_CLIPPY = $(am__v_CLIPPY_$(V)) +am__v_CLIPPY_ = $(am__v_CLIPPY_$(AM_DEFAULT_VERBOSITY)) +am__v_CLIPPY_0 = @echo " CLIPPY " $@; +am__v_CLIPPY_1 = + +CLIPPY_DEPS = $(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py + +SUFFIXES = _clippy.c .proto .pb-c.c .pb-c.h .pb.h +.c_clippy.c: + @{ test -x $(top_builddir)/$(HOSTTOOLS)lib/clippy || \ + $(MAKE) -C $(top_builddir)/$(HOSTTOOLS) lib/clippy; } + $(AM_V_CLIPPY) $(top_builddir)/$(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py -o $@ $< + +## automake's "ylwrap" is a great piece of GNU software... not. +.l.c: + $(AM_V_LEX)$(am__skiplex) $(LEXCOMPILE) $< +.y.c: + $(AM_V_YACC)$(am__skipyacc) $(YACCCOMPILE) $< # # generated sources & extra foo diff --git a/lib/termtable.c b/lib/termtable.c index ba85962cc9..4f5f9ff218 100644 --- a/lib/termtable.c +++ b/lib/termtable.c @@ -140,8 +140,8 @@ static struct ttable_cell *ttable_insert_row_va(struct ttable *tt, int i, int ncols = 0; /* count how many columns we have */ - for (int i = 0; format[i]; i++) - ncols += !!(format[i] == '|'); + for (int j = 0; format[j]; j++) + ncols += !!(format[j] == '|'); ncols++; if (tt->ncols == 0) @@ -395,7 +395,7 @@ char *ttable_dump(struct ttable *tt, const char *newline) memcpy(&buf[pos], left, lsize); pos += lsize; - for (size_t i = 0; i < width - lsize - rsize; i++) + for (size_t l = 0; l < width - lsize - rsize; l++) buf[pos++] = row[0].style.border.top; pos -= width - lsize - rsize; @@ -421,7 +421,7 @@ char *ttable_dump(struct ttable *tt, const char *newline) buf[pos++] = row[j].style.border.left; /* print left padding */ - for (int i = 0; i < row[j].style.lpad; i++) + for (int k = 0; k < row[j].style.lpad; k++) buf[pos++] = ' '; /* calculate padding for sprintf */ @@ -443,7 +443,7 @@ char *ttable_dump(struct ttable *tt, const char *newline) pos += sprintf(&buf[pos], fmt, abspad, row[j].text); /* print right padding */ - for (int i = 0; i < row[j].style.rpad; i++) + for (int k = 0; k < row[j].style.rpad; k++) buf[pos++] = ' '; /* if right border && not last col print right border */ @@ -459,7 +459,7 @@ char *ttable_dump(struct ttable *tt, const char *newline) memcpy(&buf[pos], left, lsize); pos += lsize; - for (size_t i = 0; i < width - lsize - rsize; i++) + for (size_t l = 0; l < width - lsize - rsize; l++) buf[pos++] = row[0].style.border.bottom; pos -= width - lsize - rsize; @@ -483,7 +483,7 @@ char *ttable_dump(struct ttable *tt, const char *newline) memcpy(&buf[pos], left, lsize); pos += lsize; - for (size_t i = 0; i < width - lsize - rsize; i++) + for (size_t l = 0; l < width - lsize - rsize; l++) buf[pos++] = tt->style.border.bottom; memcpy(&buf[pos], right, rsize); diff --git a/lib/thread.c b/lib/thread.c index 52bc79ffe6..2c3db27c7b 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -33,6 +33,7 @@ #include "network.h" #include "jhash.h" #include "frratomic.h" +#include "lib_errors.h" DEFINE_MTYPE_STATIC(LIB, THREAD, "Thread") DEFINE_MTYPE_STATIC(LIB, THREAD_MASTER, "Thread master") @@ -1480,7 +1481,8 @@ struct thread *thread_fetch(struct thread_master *m, struct thread *fetch) } /* else die */ - zlog_warn("poll() error: %s", safe_strerror(errno)); + flog_err(EC_LIB_SYSTEM_CALL, "poll() error: %s", + safe_strerror(errno)); pthread_mutex_unlock(&m->mtx); fetch = NULL; break; @@ -1617,7 +1619,8 @@ void thread_call(struct thread *thread) * Whinge about it now, so we're aware this is yet another task * to fix. */ - zlog_warn( + flog_warn( + EC_LIB_SLOW_THREAD, "SLOW THREAD: task %s (%lx) ran for %lums (cpu time %lums)", thread->funcname, (unsigned long)thread->func, realtime / 1000, cputime / 1000); diff --git a/lib/thread.h b/lib/thread.h index 01ff4daf42..70090cf784 100644 --- a/lib/thread.h +++ b/lib/thread.h @@ -170,6 +170,8 @@ struct cpu_thread_history { #define thread_add_timer_tv(m,f,a,v,t) funcname_thread_add_timer_tv(m,f,a,v,t,#f,__FILE__,__LINE__) #define thread_add_event(m,f,a,v,t) funcname_thread_add_event(m,f,a,v,t,#f,__FILE__,__LINE__) #define thread_execute(m,f,a,v) funcname_thread_execute(m,f,a,v,#f,__FILE__,__LINE__) +#define thread_execute_name(m, f, a, v, n) \ + funcname_thread_execute(m, f, a, v, n, __FILE__, __LINE__) /* Prototypes. */ extern struct thread_master *thread_master_create(const char *); @@ -489,18 +489,24 @@ void vrf_init(int (*create)(struct vrf *), int (*enable)(struct vrf *), /* The default VRF always exists. */ default_vrf = vrf_get(VRF_DEFAULT, VRF_DEFAULT_NAME); if (!default_vrf) { - flog_err(LIB_ERR_VRF_START, - "vrf_init: failed to create the default VRF!"); + flog_err(EC_LIB_VRF_START, + "vrf_init: failed to create the default VRF!"); exit(1); } - if (vrf_is_backend_netns()) + if (vrf_is_backend_netns()) { + struct ns *ns; + strlcpy(default_vrf->data.l.netns_name, VRF_DEFAULT_NAME, NS_NAMSIZ); + ns = ns_lookup(ns_get_default_id()); + ns->vrf_ctxt = default_vrf; + default_vrf->ns_ctxt = ns; + } /* Enable the default VRF. */ if (!vrf_enable(default_vrf)) { - flog_err(LIB_ERR_VRF_START, - "vrf_init: failed to enable the default VRF!"); + flog_err(EC_LIB_VRF_START, + "vrf_init: failed to enable the default VRF!"); exit(1); } @@ -570,7 +576,7 @@ int vrf_socket(int domain, int type, int protocol, vrf_id_t vrf_id, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", + flog_err_sys(EC_LIB_SOCKET, "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); if (ret > 0 && interfacename && vrf_default_accepts_vrf(type)) { @@ -584,7 +590,7 @@ int vrf_socket(int domain, int type, int protocol, vrf_id_t vrf_id, save_errno = errno; ret2 = vrf_switchback_to_initial(); if (ret2 < 0) - flog_err_sys(LIB_ERR_SOCKET, + flog_err_sys(EC_LIB_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = save_errno; @@ -624,7 +630,8 @@ int vrf_handler_create(struct vty *vty, const char *vrfname, "%% VRF name %s invalid: length exceeds %d bytes\n", vrfname, VRF_NAMSIZ); else - zlog_warn( + flog_warn( + EC_LIB_VRF_LENGTH, "%% VRF name %s invalid: length exceeds %d bytes\n", vrfname, VRF_NAMSIZ); return CMD_WARNING_CONFIG_FAILED; @@ -653,7 +660,7 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, "VRF %u is already configured with VRF %s\n", vrf->vrf_id, vrf->name); else - zlog_warn("VRF %u is already configured with VRF %s\n", + zlog_info("VRF %u is already configured with VRF %s\n", vrf->vrf_id, vrf->name); return CMD_WARNING_CONFIG_FAILED; } @@ -665,7 +672,7 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, "VRF %u already configured with NETNS %s\n", vrf->vrf_id, ns->name); else - zlog_warn( + zlog_info( "VRF %u already configured with NETNS %s", vrf->vrf_id, ns->name); return CMD_WARNING_CONFIG_FAILED; @@ -683,7 +690,7 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, " with VRF %u(%s)\n", ns->name, vrf2->vrf_id, vrf2->name); else - zlog_warn("NS %s is already configured with VRF %u(%s)", + zlog_info("NS %s is already configured with VRF %u(%s)", ns->name, vrf2->vrf_id, vrf2->name); return CMD_WARNING_CONFIG_FAILED; } @@ -699,7 +706,7 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, vty_out(vty, "Can not associate NS %u with NETNS %s\n", ns->ns_id, ns->name); else - zlog_warn("Can not associate NS %u with NETNS %s", + zlog_info("Can not associate NS %u with NETNS %s", ns->ns_id, ns->name); return CMD_WARNING_CONFIG_FAILED; } @@ -711,8 +718,6 @@ int vrf_is_mapped_on_netns(struct vrf *vrf) { if (!vrf || vrf->data.l.netns_name[0] == '\0') return 0; - if (vrf->vrf_id == VRF_DEFAULT) - return 0; return 1; } @@ -956,13 +961,13 @@ int vrf_getaddrinfo(const char *node, const char *service, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", + flog_err_sys(EC_LIB_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) - flog_err_sys(LIB_ERR_SOCKET, + flog_err_sys(EC_LIB_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = save_errno; @@ -975,7 +980,7 @@ int vrf_ioctl(vrf_id_t vrf_id, int d, unsigned long request, char *params) ret = vrf_switch_to_netns(vrf_id); if (ret < 0) { - flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", + flog_err_sys(EC_LIB_SOCKET, "%s: Can't switch to VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); return 0; } @@ -983,7 +988,7 @@ int vrf_ioctl(vrf_id_t vrf_id, int d, unsigned long request, char *params) saved_errno = errno; ret = vrf_switchback_to_initial(); if (ret < 0) - flog_err_sys(LIB_ERR_SOCKET, + flog_err_sys(EC_LIB_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = saved_errno; @@ -997,13 +1002,13 @@ int vrf_sockunion_socket(const union sockunion *su, vrf_id_t vrf_id, ret = vrf_switch_to_netns(vrf_id); if (ret < 0) - flog_err_sys(LIB_ERR_SOCKET, "%s: Can't switch to VRF %u (%s)", + flog_err_sys(EC_LIB_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) - flog_err_sys(LIB_ERR_SOCKET, + flog_err_sys(EC_LIB_SOCKET, "%s: Can't switchback from VRF %u (%s)", __func__, vrf_id, safe_strerror(errno)); errno = save_errno; @@ -111,8 +111,8 @@ extern vrf_id_t vrf_name_to_id(const char *); #define VRF_GET_ID(V, NAME, USE_JSON) \ do { \ - struct vrf *vrf; \ - if (!(vrf = vrf_lookup_by_name(NAME))) { \ + struct vrf *_vrf; \ + if (!(_vrf = vrf_lookup_by_name(NAME))) { \ if (USE_JSON) { \ vty_out(vty, "{}\n"); \ } else { \ @@ -120,7 +120,7 @@ extern vrf_id_t vrf_name_to_id(const char *); } \ return CMD_WARNING; \ } \ - if (vrf->vrf_id == VRF_UNKNOWN) { \ + if (_vrf->vrf_id == VRF_UNKNOWN) { \ if (USE_JSON) { \ vty_out(vty, "{}\n"); \ } else { \ @@ -128,7 +128,7 @@ extern vrf_id_t vrf_name_to_id(const char *); } \ return CMD_WARNING; \ } \ - (V) = vrf->vrf_id; \ + (V) = _vrf->vrf_id; \ } while (0) /* @@ -201,7 +201,7 @@ extern int vrf_bitmap_check(vrf_bitmap_t, vrf_id_t); */ extern void vrf_init(int (*create)(struct vrf *vrf), int (*enable)(struct vrf *vrf), int (*disable)(struct vrf *vrf), int (*delete)(struct vrf *vrf), - int ((*update)(struct vrf *vrf))); + int (*update)(struct vrf *vrf)); /* * Call vrf_terminate when the protocol is being shutdown @@ -314,8 +314,9 @@ static int vty_log_out(struct vty *vty, const char *level, /* Fatal I/O error. */ vty->monitor = 0; /* disable monitoring to avoid infinite recursion */ - zlog_warn("%s: write failed to vty client fd %d, closing: %s", - __func__, vty->fd, safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, + "%s: write failed to vty client fd %d, closing: %s", + __func__, vty->fd, safe_strerror(errno)); buffer_reset(vty->obuf); buffer_reset(vty->lbuf); /* cannot call vty_close, because a parent routine may still try @@ -534,7 +535,8 @@ static int vty_command(struct vty *vty, char *buf) if ((realtime = thread_consumed_time(&after, &before, &cputime)) > CONSUMED_TIME_CHECK) /* Warn about CPU hog that must be fixed. */ - zlog_warn( + flog_warn( + EC_LIB_SLOW_THREAD, "SLOW COMMAND: command took %lums (cpu time %lums): %s", realtime / 1000, cputime / 1000, buf); } @@ -811,6 +813,7 @@ static void vty_end_config(struct vty *vty) case LDP_L2VPN_NODE: case LDP_PSEUDOWIRE_NODE: case ISIS_NODE: + case OPENFABRIC_NODE: case KEYCHAIN_NODE: case KEYCHAIN_KEY_NODE: case VTY_NODE: @@ -1210,6 +1213,7 @@ static void vty_stop_input(struct vty *vty) case LDP_L2VPN_NODE: case LDP_PSEUDOWIRE_NODE: case ISIS_NODE: + case OPENFABRIC_NODE: case KEYCHAIN_NODE: case KEYCHAIN_KEY_NODE: case VTY_NODE: @@ -1324,14 +1328,15 @@ static int vty_telnet_option(struct vty *vty, unsigned char *buf, int nbytes) switch (vty->sb_buf[0]) { case TELOPT_NAWS: if (vty->sb_len != TELNET_NAWS_SB_LEN) - zlog_warn( + flog_err( + EC_LIB_SYSTEM_CALL, "RFC 1073 violation detected: telnet NAWS option " "should send %d characters, but we received %lu", TELNET_NAWS_SB_LEN, (unsigned long)vty->sb_len); else if (sizeof(vty->sb_buf) < TELNET_NAWS_SB_LEN) flog_err( - LIB_ERR_DEVELOPMENT, + EC_LIB_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); @@ -1446,7 +1451,8 @@ static int vty_read(struct thread *thread) } vty->monitor = 0; /* disable monitoring to avoid infinite recursion */ - zlog_warn( + flog_err( + EC_LIB_SOCKET, "%s: read error on vty client fd %d, closing: %s", __func__, vty->fd, safe_strerror(errno)); buffer_reset(vty->obuf); @@ -1653,7 +1659,7 @@ static int vty_flush(struct thread *thread) case BUFFER_ERROR: vty->monitor = 0; /* disable monitoring to avoid infinite recursion */ - zlog_warn("buffer_flush failed on vty client fd %d, closing", + zlog_info("buffer_flush failed on vty client fd %d, closing", vty->fd); buffer_reset(vty->lbuf); buffer_reset(vty->obuf); @@ -1900,7 +1906,8 @@ static int vty_accept(struct thread *thread) /* We can handle IPv4 or IPv6 socket. */ vty_sock = sockunion_accept(accept_sock, &su); if (vty_sock < 0) { - zlog_warn("can't accept vty socket : %s", safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "can't accept vty socket : %s", + safe_strerror(errno)); return -1; } set_nonblocking(vty_sock); @@ -1973,7 +1980,7 @@ static void vty_serv_sock_addrinfo(const char *hostname, unsigned short port) ret = getaddrinfo(hostname, port_str, &req, &ainfo); if (ret != 0) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, "getaddrinfo failed: %s", + flog_err_sys(EC_LIB_SYSTEM_CALL, "getaddrinfo failed: %s", gai_strerror(ret)); exit(1); } @@ -2034,7 +2041,7 @@ static void vty_serv_un(const char *path) /* Make UNIX domain socket. */ sock = socket(AF_UNIX, SOCK_STREAM, 0); if (sock < 0) { - flog_err_sys(LIB_ERR_SOCKET, + flog_err_sys(EC_LIB_SOCKET, "Cannot create unix stream socket: %s", safe_strerror(errno)); return; @@ -2054,7 +2061,7 @@ static void vty_serv_un(const char *path) ret = bind(sock, (struct sockaddr *)&serv, len); if (ret < 0) { - flog_err_sys(LIB_ERR_SOCKET, "Cannot bind path %s: %s", path, + flog_err_sys(EC_LIB_SOCKET, "Cannot bind path %s: %s", path, safe_strerror(errno)); close(sock); /* Avoid sd leak. */ return; @@ -2062,7 +2069,7 @@ static void vty_serv_un(const char *path) ret = listen(sock, 5); if (ret < 0) { - flog_err_sys(LIB_ERR_SOCKET, "listen(fd %d) failed: %s", sock, + flog_err_sys(EC_LIB_SOCKET, "listen(fd %d) failed: %s", sock, safe_strerror(errno)); close(sock); /* Avoid sd leak. */ return; @@ -2078,7 +2085,7 @@ static void vty_serv_un(const char *path) if ((int)ids.gid_vty > 0) { /* set group of socket */ if (chown(path, -1, ids.gid_vty)) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "vty_serv_un: could chown socket, %s", safe_strerror(errno)); } @@ -2108,14 +2115,15 @@ static int vtysh_accept(struct thread *thread) (socklen_t *)&client_len); if (sock < 0) { - zlog_warn("can't accept vty socket : %s", safe_strerror(errno)); + flog_err(EC_LIB_SOCKET, "can't accept vty socket : %s", + safe_strerror(errno)); return -1; } if (set_nonblocking(sock) < 0) { - zlog_warn( - "vtysh_accept: could not set vty socket %d to non-blocking," - " %s, closing", + flog_err( + EC_LIB_SOCKET, + "vtysh_accept: could not set vty socket %d to non-blocking, %s, closing", sock, safe_strerror(errno)); close(sock); return -1; @@ -2146,8 +2154,8 @@ static int vtysh_flush(struct vty *vty) case BUFFER_ERROR: vty->monitor = 0; /* disable monitoring to avoid infinite recursion */ - zlog_warn("%s: write error to fd %d, closing", __func__, - vty->fd); + flog_err(EC_LIB_SOCKET, "%s: write error to fd %d, closing", + __func__, vty->fd); buffer_reset(vty->lbuf); buffer_reset(vty->obuf); vty_close(vty); @@ -2181,7 +2189,8 @@ static int vtysh_read(struct thread *thread) } vty->monitor = 0; /* disable monitoring to avoid infinite recursion */ - zlog_warn( + flog_err( + EC_LIB_SOCKET, "%s: read failed on vtysh client fd %d, closing: %s", __func__, sock, safe_strerror(errno)); } @@ -2411,9 +2420,8 @@ static void vty_read_file(FILE *confp) nl = strchr(vty->error_buf, '\n'); if (nl) *nl = '\0'; - flog_err(LIB_ERR_VTY, - "ERROR: %s on config line %u: %s", message, line_num, - vty->error_buf); + flog_err(EC_LIB_VTY, "ERROR: %s on config line %u: %s", message, + line_num, vty->error_buf); } vty_close(vty); @@ -2487,7 +2495,7 @@ bool vty_read_config(const char *config_file, char *config_default_dir) if (!IS_DIRECTORY_SEP(config_file[0])) { if (getcwd(cwd, MAXPATHLEN) == NULL) { flog_err_sys( - LIB_ERR_SYSTEM_CALL, + EC_LIB_SYSTEM_CALL, "Failure to determine Current Working Directory %d!", errno); exit(1); @@ -2502,17 +2510,20 @@ bool vty_read_config(const char *config_file, char *config_default_dir) confp = fopen(fullpath, "r"); if (confp == NULL) { - zlog_warn("%s: failed to open configuration file %s: %s, checking backup", - __func__, fullpath, safe_strerror(errno)); + flog_warn( + EC_LIB_BACKUP_CONFIG, + "%s: failed to open configuration file %s: %s, checking backup", + __func__, fullpath, safe_strerror(errno)); confp = vty_use_backup_config(fullpath); if (confp) - zlog_warn( + flog_warn( + EC_LIB_BACKUP_CONFIG, "WARNING: using backup configuration file!"); else { - flog_err(LIB_ERR_VTY, - "can't open configuration file [%s]", - config_file); + flog_err(EC_LIB_VTY, + "can't open configuration file [%s]", + config_file); exit(1); } } @@ -2548,19 +2559,22 @@ bool vty_read_config(const char *config_file, char *config_default_dir) #endif /* VTYSH */ confp = fopen(config_default_dir, "r"); if (confp == NULL) { - zlog_warn("%s: failed to open configuration file %s: %s, checking backup", - __func__, config_default_dir, - safe_strerror(errno)); + flog_err( + EC_LIB_SYSTEM_CALL, + "%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) { - zlog_warn( + flog_warn( + EC_LIB_BACKUP_CONFIG, "WARNING: using backup configuration file!"); fullpath = config_default_dir; } else { - flog_err(LIB_ERR_VTY, - "can't open configuration file [%s]", - config_default_dir); + flog_err(EC_LIB_VTY, + "can't open configuration file [%s]", + config_default_dir); goto tmp_free_and_out; } } else @@ -3073,13 +3087,13 @@ static void vty_save_cwd(void) * Hence not worrying about it too much. */ if (!chdir(SYSCONFDIR)) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "Failure to chdir to %s, errno: %d", SYSCONFDIR, errno); exit(-1); } if (getcwd(cwd, MAXPATHLEN) == NULL) { - flog_err_sys(LIB_ERR_SYSTEM_CALL, + flog_err_sys(EC_LIB_SYSTEM_CALL, "Failure to getcwd, errno: %d", errno); exit(-1); } diff --git a/lib/wheel.c b/lib/wheel.c index b1a3e89fc7..722b02424a 100644 --- a/lib/wheel.c +++ b/lib/wheel.c @@ -29,7 +29,9 @@ DEFINE_MTYPE_STATIC(LIB, TIMER_WHEEL_LIST, "Timer Wheel Slot List") static int debug_timer_wheel = 0; -static int wheel_timer_thread(struct thread *t) +static int wheel_timer_thread(struct thread *t); + +static int wheel_timer_thread_helper(struct thread *t) { struct listnode *node, *nextnode; unsigned long long curr_slot; @@ -65,15 +67,29 @@ static int wheel_timer_thread(struct thread *t) return 0; } +static int wheel_timer_thread(struct thread *t) +{ + struct timer_wheel *wheel; + + wheel = THREAD_ARG(t); + + thread_execute_name(wheel->master, wheel_timer_thread_helper, + wheel, 0, wheel->name); + + return 0; +} + struct timer_wheel *wheel_init(struct thread_master *master, int period, size_t slots, unsigned int (*slot_key)(void *), - void (*slot_run)(void *)) + void (*slot_run)(void *), + const char *run_name) { struct timer_wheel *wheel; size_t i; wheel = XCALLOC(MTYPE_TIMER_WHEEL, sizeof(struct timer_wheel)); + wheel->name = XSTRDUP(MTYPE_TIMER_WHEEL, run_name); wheel->slot_key = slot_key; wheel->slot_run = slot_run; @@ -104,6 +120,7 @@ void wheel_delete(struct timer_wheel *wheel) THREAD_OFF(wheel->timer); XFREE(MTYPE_TIMER_WHEEL_LIST, wheel->wheel_slot_lists); + XFREE(MTYPE_TIMER_WHEEL, wheel->name); XFREE(MTYPE_TIMER_WHEEL, wheel); } diff --git a/lib/wheel.h b/lib/wheel.h index 1f9f95ed31..c8e83fafcb 100644 --- a/lib/wheel.h +++ b/lib/wheel.h @@ -21,6 +21,7 @@ #define __WHEEL_H__ struct timer_wheel { + char *name; struct thread_master *master; int slots; long long curr_slot; @@ -76,7 +77,8 @@ struct timer_wheel { */ struct timer_wheel *wheel_init(struct thread_master *master, int period, size_t slots, unsigned int (*slot_key)(void *), - void (*slot_run)(void *)); + void (*slot_run)(void *), + const char *run_name); /* * Delete the specified timer wheel created diff --git a/lib/zclient.c b/lib/zclient.c index c5a48c178a..e6626a178b 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -221,9 +221,9 @@ int zclient_socket_connect(struct zclient *zclient) ret = connect(sock, (struct sockaddr *)&zclient_addr, zclient_addr_len); if (ret < 0) { if (zclient_debug) - zlog_warn("%s connect failure: %d(%s)", - __PRETTY_FUNCTION__, errno, - safe_strerror(errno)); + zlog_debug("%s connect failure: %d(%s)", + __PRETTY_FUNCTION__, errno, + safe_strerror(errno)); close(sock); return -1; } @@ -249,7 +249,8 @@ static int zclient_flush_data(struct thread *thread) return -1; switch (buffer_flush_available(zclient->wb, zclient->sock)) { case BUFFER_ERROR: - zlog_warn( + flog_err( + EC_LIB_ZAPI_SOCKET, "%s: buffer_flush_available failed on zclient fd %d, closing", __func__, zclient->sock); return zclient_failed(zclient); @@ -273,8 +274,9 @@ int zclient_send_message(struct zclient *zclient) STREAM_DATA(zclient->obuf), stream_get_endp(zclient->obuf))) { case BUFFER_ERROR: - zlog_warn("%s: buffer_write failed to zclient fd %d, closing", - __func__, zclient->sock); + flog_err(EC_LIB_ZAPI_SOCKET, + "%s: buffer_write failed to zclient fd %d, closing", + __func__, zclient->sock); return zclient_failed(zclient); break; case BUFFER_EMPTY: @@ -313,9 +315,10 @@ int zclient_read_header(struct stream *s, int sock, uint16_t *size, STREAM_GETW(s, *cmd); if (*version != ZSERV_VERSION || *marker != ZEBRA_HEADER_MARKER) { - flog_err(LIB_ERR_ZAPI_MISSMATCH, - "%s: socket %d version mismatch, marker %d, version %d", - __func__, sock, *marker, *version); + flog_err( + EC_LIB_ZAPI_MISSMATCH, + "%s: socket %d version mismatch, marker %d, version %d", + __func__, sock, *marker, *version); return -1; } @@ -575,8 +578,8 @@ int zclient_start(struct zclient *zclient) } if (set_nonblocking(zclient->sock) < 0) - zlog_warn("%s: set_nonblocking(%d) failed", __func__, - zclient->sock); + flog_err(EC_LIB_ZAPI_SOCKET, "%s: set_nonblocking(%d) failed", + __func__, zclient->sock); /* Clear fail count. */ zclient->fail = 0; @@ -771,9 +774,9 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) char buf[PREFIX2STR_BUFFER]; prefix2str(&api->prefix, buf, sizeof(buf)); - zlog_warn( - "%s: prefix %s: can't encode %u nexthops " - "(maximum is %u)", + flog_err( + EC_LIB_ZAPI_ENCODE, + "%s: prefix %s: can't encode %u nexthops (maximum is %u)", __func__, buf, api->nexthop_num, MULTIPATH_NUM); return -1; } @@ -808,11 +811,6 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) 16); stream_putl(s, api_nh->ifindex); break; - default: - zlog_warn( - "%s: Specified Nexthop type %d does not exist", - __PRETTY_FUNCTION__, api_nh->type); - return -1; } /* MPLS labels for BGP-LU or Segment Routing */ @@ -821,12 +819,12 @@ int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) char buf[PREFIX2STR_BUFFER]; prefix2str(&api->prefix, buf, sizeof(buf)); - 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); + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: prefix %s: can't encode " + "%u labels (maximum is %u)", + __func__, buf, + api_nh->label_num, + MPLS_MAX_LABELS); return -1; } @@ -871,8 +869,9 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) /* Type, flags, message. */ STREAM_GETC(s, api->type); if (api->type > ZEBRA_ROUTE_MAX) { - zlog_warn("%s: Specified route type: %d is not a legal value\n", - __PRETTY_FUNCTION__, api->type); + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: Specified route type: %d is not a legal value\n", + __PRETTY_FUNCTION__, api->type); return -1; } @@ -887,7 +886,8 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) switch (api->prefix.family) { case AF_INET: if (api->prefix.prefixlen > IPV4_MAX_PREFIXLEN) { - zlog_warn( + flog_err( + EC_LIB_ZAPI_ENCODE, "%s: V4 prefixlen is %d which should not be more than 32", __PRETTY_FUNCTION__, api->prefix.prefixlen); return -1; @@ -895,15 +895,17 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) break; case AF_INET6: if (api->prefix.prefixlen > IPV6_MAX_PREFIXLEN) { - zlog_warn( + flog_err( + EC_LIB_ZAPI_ENCODE, "%s: v6 prefixlen is %d which should not be more than 128", __PRETTY_FUNCTION__, api->prefix.prefixlen); return -1; } break; default: - zlog_warn("%s: Specified family %d is not v4 or v6", - __PRETTY_FUNCTION__, api->prefix.family); + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: Specified family %d is not v4 or v6", + __PRETTY_FUNCTION__, api->prefix.family); return -1; } STREAM_GET(&api->prefix.u.prefix, s, PSIZE(api->prefix.prefixlen)); @@ -912,7 +914,8 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) api->src_prefix.family = AF_INET6; STREAM_GETC(s, api->src_prefix.prefixlen); if (api->src_prefix.prefixlen > IPV6_MAX_PREFIXLEN) { - zlog_warn( + flog_err( + EC_LIB_ZAPI_ENCODE, "%s: SRC Prefix prefixlen received: %d is too large", __PRETTY_FUNCTION__, api->src_prefix.prefixlen); return -1; @@ -922,7 +925,8 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) if (api->prefix.family != AF_INET6 || api->src_prefix.prefixlen == 0) { - zlog_warn( + flog_err( + EC_LIB_ZAPI_ENCODE, "%s: SRC prefix specified in some manner that makes no sense", __PRETTY_FUNCTION__); return -1; @@ -933,8 +937,9 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) if (CHECK_FLAG(api->message, ZAPI_MESSAGE_NEXTHOP)) { STREAM_GETW(s, api->nexthop_num); if (api->nexthop_num > MULTIPATH_NUM) { - zlog_warn("%s: invalid number of nexthops (%u)", - __func__, api->nexthop_num); + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: invalid number of nexthops (%u)", + __func__, api->nexthop_num); return -1; } @@ -966,11 +971,6 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) STREAM_GET(&api_nh->gate.ipv6, s, 16); STREAM_GETL(s, api_nh->ifindex); break; - default: - zlog_warn( - "%s: Specified nexthop type %d does not exist", - __PRETTY_FUNCTION__, api_nh->type); - return -1; } /* MPLS labels for BGP-LU or Segment Routing */ @@ -978,9 +978,9 @@ int zapi_route_decode(struct stream *s, struct zapi_route *api) STREAM_GETC(s, api_nh->label_num); if (api_nh->label_num > MPLS_MAX_LABELS) { - zlog_warn( - "%s: invalid number of MPLS " - "labels (%u)", + flog_err( + EC_LIB_ZAPI_ENCODE, + "%s: invalid number of MPLS labels (%u)", __func__, api_nh->label_num); return -1; } @@ -1239,8 +1239,9 @@ bool zapi_nexthop_update_decode(struct stream *s, struct zapi_route *nhr) } STREAM_GETC(s, nhr->nexthops[i].label_num); if (nhr->nexthops[i].label_num > MPLS_MAX_LABELS) { - zlog_warn("%s: invalid number of MPLS labels (%u)", - __func__, nhr->nexthops[i].label_num); + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: invalid number of MPLS labels (%u)", + __func__, nhr->nexthops[i].label_num); return false; } if (nhr->nexthops[i].label_num) @@ -1424,8 +1425,9 @@ struct interface *zebra_interface_state_read(struct stream *s, vrf_id_t vrf_id) /* Lookup this by interface index. */ ifp = if_lookup_by_name(ifname_tmp, vrf_id); if (ifp == NULL) { - zlog_warn("INTERFACE_STATE: Cannot find IF %s in VRF %d", - ifname_tmp, vrf_id); + flog_err(EC_LIB_ZAPI_ENCODE, + "INTERFACE_STATE: Cannot find IF %s in VRF %d", + ifname_tmp, vrf_id); return NULL; } @@ -1450,10 +1452,11 @@ static void link_params_set_value(struct stream *s, struct if_link_params *iflp) for (i = 0; i < bwclassnum && i < MAX_CLASS_TYPE; i++) iflp->unrsv_bw[i] = stream_getf(s); if (i < bwclassnum) - flog_err(LIB_ERR_ZAPI_MISSMATCH, - "%s: received %d > %d (MAX_CLASS_TYPE) bw entries" - " - outdated library?", - __func__, bwclassnum, MAX_CLASS_TYPE); + flog_err( + EC_LIB_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); @@ -1482,9 +1485,9 @@ struct interface *zebra_interface_link_params_read(struct stream *s) struct interface *ifp = if_lookup_by_index(ifindex, VRF_DEFAULT); if (ifp == NULL) { - flog_err(LIB_ERR_ZAPI_ENCODE, - "%s: unknown ifindex %u, shouldn't happen", __func__, - ifindex); + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: unknown ifindex %u, shouldn't happen", __func__, + ifindex); return NULL; } @@ -1633,9 +1636,10 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, /* Lookup index. */ ifp = if_lookup_by_index(ifindex, vrf_id); if (ifp == NULL) { - zlog_warn("INTERFACE_ADDRESS_%s: Cannot find IF %u in VRF %d", - (type == ZEBRA_INTERFACE_ADDRESS_ADD) ? "ADD" : "DEL", - ifindex, vrf_id); + flog_err(EC_LIB_ZAPI_ENCODE, + "INTERFACE_ADDRESS_%s: Cannot find IF %u in VRF %d", + (type == ZEBRA_INTERFACE_ADDRESS_ADD) ? "ADD" : "DEL", + ifindex, vrf_id); return NULL; } @@ -1670,9 +1674,9 @@ struct connected *zebra_interface_address_read(int type, struct stream *s, /* carp interfaces on OpenBSD with 0.0.0.0/0 as * "peer" */ char buf[PREFIX_STRLEN]; - zlog_warn( - "warning: interface %s address %s " - "with peer flag set, but no peer address!", + flog_err( + EC_LIB_ZAPI_ENCODE, + "warning: interface %s address %s with peer flag set, but no peer address!", ifp->name, prefix2str(ifc->address, buf, sizeof buf)); @@ -1725,10 +1729,11 @@ zebra_interface_nbr_address_read(int type, struct stream *s, vrf_id_t vrf_id) /* Lookup index. */ ifp = if_lookup_by_index(ifindex, vrf_id); if (ifp == NULL) { - zlog_warn("INTERFACE_NBR_%s: Cannot find IF %u in VRF %d", - (type == ZEBRA_INTERFACE_NBR_ADDRESS_ADD) ? "ADD" - : "DELETE", - ifindex, vrf_id); + flog_err(EC_LIB_ZAPI_ENCODE, + "INTERFACE_NBR_%s: Cannot find IF %u in VRF %d", + (type == ZEBRA_INTERFACE_NBR_ADDRESS_ADD) ? "ADD" + : "DELETE", + ifindex, vrf_id); return NULL; } @@ -1774,8 +1779,9 @@ struct interface *zebra_interface_vrf_update_read(struct stream *s, /* Lookup interface. */ ifp = if_lookup_by_index(ifindex, vrf_id); if (ifp == NULL) { - zlog_warn("INTERFACE_VRF_UPDATE: Cannot find IF %u in VRF %d", - ifindex, vrf_id); + flog_err(EC_LIB_ZAPI_ENCODE, + "INTERFACE_VRF_UPDATE: Cannot find IF %u in VRF %d", + ifindex, vrf_id); return NULL; } @@ -1819,8 +1825,8 @@ static int zclient_read_sync_response(struct zclient *zclient, size); } if (ret != 0) { - flog_err(LIB_ERR_ZAPI_ENCODE, - "%s: Invalid Sync Message Reply", __func__); + flog_err(EC_LIB_ZAPI_ENCODE, "%s: Invalid Sync Message Reply", + __func__); return -1; } @@ -1833,24 +1839,29 @@ static int zclient_read_sync_response(struct zclient *zclient, * immediately reads the answer from the input buffer. * * @param zclient Zclient used to connect to label manager (zebra) + * @param async Synchronous (0) or asynchronous (1) operation * @result Result of response */ -int lm_label_manager_connect(struct zclient *zclient) +int lm_label_manager_connect(struct zclient *zclient, int async) { int ret; struct stream *s; uint8_t result; + uint16_t cmd = async ? ZEBRA_LABEL_MANAGER_CONNECT_ASYNC : + ZEBRA_LABEL_MANAGER_CONNECT; if (zclient_debug) zlog_debug("Connecting to Label Manager (LM)"); - if (zclient->sock < 0) + if (zclient->sock < 0) { + zlog_debug("%s: invalid zclient socket", __func__); return -1; + } /* send request */ s = zclient->obuf; stream_reset(s); - zclient_create_header(s, ZEBRA_LABEL_MANAGER_CONNECT, VRF_DEFAULT); + zclient_create_header(s, cmd, VRF_DEFAULT); /* proto */ stream_putc(s, zclient->redist_default); @@ -1862,13 +1873,13 @@ int lm_label_manager_connect(struct zclient *zclient) ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, "Can't write to zclient sock"); + flog_err(EC_LIB_ZAPI_SOCKET, "Can't write to zclient sock"); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, "Zclient sock closed"); + flog_err(EC_LIB_ZAPI_SOCKET, "Zclient sock closed"); close(zclient->sock); zclient->sock = -1; return -1; @@ -1876,8 +1887,11 @@ int lm_label_manager_connect(struct zclient *zclient) if (zclient_debug) zlog_debug("LM connect request sent (%d bytes)", ret); + if (async) + return 0; + /* read response */ - if (zclient_read_sync_response(zclient, ZEBRA_LABEL_MANAGER_CONNECT) + if (zclient_read_sync_response(zclient, cmd) != 0) return -1; @@ -1889,13 +1903,15 @@ int lm_label_manager_connect(struct zclient *zclient) /* sanity */ if (proto != zclient->redist_default) - flog_err(LIB_ERR_ZAPI_ENCODE, - "Wrong proto (%u) in LM connect response. Should be %u", - proto, zclient->redist_default); + flog_err( + EC_LIB_ZAPI_ENCODE, + "Wrong proto (%u) in LM connect response. Should be %u", + proto, zclient->redist_default); if (instance != zclient->instance) - flog_err(LIB_ERR_ZAPI_ENCODE, - "Wrong instId (%u) in LM connect response. Should be %u", - instance, zclient->instance); + flog_err( + EC_LIB_ZAPI_ENCODE, + "Wrong instId (%u) in LM connect response. Should be %u", + instance, zclient->instance); /* result code */ result = stream_getc(s); @@ -1984,15 +2000,13 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, - "Can't write to zclient sock"); + flog_err(EC_LIB_ZAPI_SOCKET, "Can't write to zclient sock"); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, - "Zclient sock closed"); + flog_err(EC_LIB_ZAPI_SOCKET, "Zclient sock closed"); close(zclient->sock); zclient->sock = -1; return -1; @@ -2013,13 +2027,13 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, /* sanities */ if (proto != zclient->redist_default) - flog_err(LIB_ERR_ZAPI_ENCODE, - "Wrong proto (%u) in get chunk response. Should be %u", - proto, zclient->redist_default); + flog_err(EC_LIB_ZAPI_ENCODE, + "Wrong proto (%u) in get chunk response. Should be %u", + proto, zclient->redist_default); if (instance != zclient->instance) - flog_err(LIB_ERR_ZAPI_ENCODE, - "Wrong instId (%u) in get chunk response Should be %u", - instance, zclient->instance); + flog_err(EC_LIB_ZAPI_ENCODE, + "Wrong instId (%u) in get chunk response Should be %u", + instance, zclient->instance); /* keep */ response_keep = stream_getc(s); @@ -2029,15 +2043,16 @@ int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, /* not owning this response */ if (keep != response_keep) { - flog_err(LIB_ERR_ZAPI_ENCODE, - "Invalid Label chunk: %u - %u, keeps mismatch %u != %u", - *start, *end, keep, response_keep); + flog_err( + EC_LIB_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) { - flog_err(LIB_ERR_ZAPI_ENCODE, - "Invalid Label chunk: %u - %u", *start, *end); + flog_err(EC_LIB_ZAPI_ENCODE, "Invalid Label chunk: %u - %u", + *start, *end); return -1; } @@ -2087,14 +2102,13 @@ int lm_release_label_chunk(struct zclient *zclient, uint32_t start, ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, "Can't write to zclient sock"); + flog_err(EC_LIB_ZAPI_SOCKET, "Can't write to zclient sock"); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, - "Zclient sock connection closed"); + flog_err(EC_LIB_ZAPI_SOCKET, "Zclient sock connection closed"); close(zclient->sock); zclient->sock = -1; return -1; @@ -2197,15 +2211,15 @@ int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, ret = writen(zclient->sock, s->data, stream_get_endp(s)); if (ret < 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, - "%s: can't write to zclient->sock", __func__); + flog_err(EC_LIB_ZAPI_SOCKET, "%s: can't write to zclient->sock", + __func__); close(zclient->sock); zclient->sock = -1; return -1; } if (ret == 0) { - flog_err(LIB_ERR_ZAPI_SOCKET, - "%s: zclient->sock connection closed", __func__); + flog_err(EC_LIB_ZAPI_SOCKET, + "%s: zclient->sock connection closed", __func__); close(zclient->sock); zclient->sock = -1; return -1; @@ -2291,8 +2305,7 @@ int zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw) stream_write(s, (uint8_t *)&pw->nexthop.ipv6, 16); break; default: - flog_err(LIB_ERR_ZAPI_ENCODE, - "%s: unknown af", __func__); + flog_err(EC_LIB_ZAPI_ENCODE, "%s: unknown af", __func__); return -1; } @@ -2394,23 +2407,25 @@ static int zclient_read(struct thread *thread) command = stream_getw(zclient->ibuf); if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION) { - flog_err(LIB_ERR_ZAPI_MISSMATCH, - "%s: socket %d version mismatch, marker %d, version %d", - __func__, zclient->sock, marker, version); + flog_err( + EC_LIB_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) { - flog_err(LIB_ERR_ZAPI_MISSMATCH, - "%s: socket %d message length %u is less than %d ", - __func__, zclient->sock, length, ZEBRA_HEADER_SIZE); + flog_err(EC_LIB_ZAPI_MISSMATCH, + "%s: socket %d message length %u is less than %d ", + __func__, zclient->sock, length, ZEBRA_HEADER_SIZE); return zclient_failed(zclient); } /* Length check. */ if (length > STREAM_SIZE(zclient->ibuf)) { struct stream *ns; - zlog_warn( + flog_err( + EC_LIB_ZAPI_ENCODE, "%s: message size %u exceeds buffer size %lu, expanding...", __func__, length, (unsigned long)STREAM_SIZE(zclient->ibuf)); diff --git a/lib/zclient.h b/lib/zclient.h index b8ff85e80f..54f3635901 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -91,7 +91,6 @@ typedef enum { ZEBRA_IMPORT_ROUTE_REGISTER, ZEBRA_IMPORT_ROUTE_UNREGISTER, ZEBRA_IMPORT_CHECK_UPDATE, - ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD, ZEBRA_BFD_DEST_REGISTER, ZEBRA_BFD_DEST_DEREGISTER, ZEBRA_BFD_DEST_UPDATE, @@ -113,6 +112,7 @@ typedef enum { ZEBRA_MPLS_LABELS_DELETE, ZEBRA_IPMR_ROUTE_STATS, ZEBRA_LABEL_MANAGER_CONNECT, + ZEBRA_LABEL_MANAGER_CONNECT_ASYNC, ZEBRA_GET_LABEL_CHUNK, ZEBRA_RELEASE_LABEL_CHUNK, ZEBRA_FEC_REGISTER, @@ -573,7 +573,7 @@ extern int zclient_send_get_label_chunk( uint8_t keep, uint32_t chunk_size); -extern int lm_label_manager_connect(struct zclient *zclient); +extern int lm_label_manager_connect(struct zclient *zclient, int async); extern int lm_get_label_chunk(struct zclient *zclient, uint8_t keep, uint32_t chunk_size, uint32_t *start, uint32_t *end); diff --git a/lib/zebra.h b/lib/zebra.h index b12f6616ba..4e0e408ea6 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -28,7 +28,6 @@ #include "compiler.h" #ifdef SUNOS_5 -#define _XPG4_2 typedef unsigned int uint32_t; typedef unsigned short uint16_t; typedef unsigned char uint8_t; @@ -334,18 +333,18 @@ struct in_pktinfo { #endif #define MAX(a, b) \ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a > _b ? _a : _b; \ + typeof(a) _max_a = (a); \ + typeof(b) _max_b = (b); \ + _max_a > _max_b ? _max_a : _max_b; \ }) #ifdef MIN #undef MIN #endif #define MIN(a, b) \ ({ \ - typeof(a) _a = (a); \ - typeof(b) _b = (b); \ - _a < _b ? _a : _b; \ + typeof(a) _min_a = (a); \ + typeof(b) _min_b = (b); \ + _min_a < _min_b ? _min_a : _min_b; \ }) #ifndef offsetof @@ -414,6 +413,7 @@ extern const char *zserv_command_string(unsigned int command); #define ZEBRA_FLAG_FIB_OVERRIDE 0x200 #define ZEBRA_FLAG_EVPN_ROUTE 0x400 #define ZEBRA_FLAG_RR_USE_DISTANCE 0x800 +#define ZEBRA_FLAG_ONLINK 0x1000 /* ZEBRA_FLAG_BLACKHOLE was 0x04 */ /* ZEBRA_FLAG_REJECT was 0x80 */ |
