diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command.c | 45 | ||||
| -rw-r--r-- | lib/command_graph.c | 2 | ||||
| -rw-r--r-- | lib/distribute.c | 27 | ||||
| -rw-r--r-- | lib/event_counter.c | 2 | ||||
| -rw-r--r-- | lib/filter.c | 12 | ||||
| -rw-r--r-- | lib/frr_pthread.c | 3 | ||||
| -rw-r--r-- | lib/frr_zmq.c | 4 | ||||
| -rw-r--r-- | lib/frrstr.c | 4 | ||||
| -rw-r--r-- | lib/hash.c | 5 | ||||
| -rw-r--r-- | lib/if.c | 12 | ||||
| -rw-r--r-- | lib/if_rmap.c | 118 | ||||
| -rw-r--r-- | lib/if_rmap.h | 33 | ||||
| -rw-r--r-- | lib/imsg.c | 3 | ||||
| -rw-r--r-- | lib/jhash.c | 4 | ||||
| -rw-r--r-- | lib/keychain.c | 6 | ||||
| -rw-r--r-- | lib/libfrr.c | 2 | ||||
| -rw-r--r-- | lib/log.c | 6 | ||||
| -rw-r--r-- | lib/module.c | 3 | ||||
| -rw-r--r-- | lib/netns_linux.c | 3 | ||||
| -rw-r--r-- | lib/nexthop.h | 1 | ||||
| -rw-r--r-- | lib/nexthop_group.c | 6 | ||||
| -rw-r--r-- | lib/northbound.c | 94 | ||||
| -rw-r--r-- | lib/northbound_confd.c | 2 | ||||
| -rw-r--r-- | lib/plist.c | 6 | ||||
| -rw-r--r-- | lib/pqueue.c | 2 | ||||
| -rw-r--r-- | lib/prefix.c | 15 | ||||
| -rw-r--r-- | lib/privs.c | 19 | ||||
| -rw-r--r-- | lib/privs.h | 10 | ||||
| -rw-r--r-- | lib/routemap.c | 15 | ||||
| -rw-r--r-- | lib/thread.c | 8 | ||||
| -rw-r--r-- | lib/vty.c | 21 | ||||
| -rw-r--r-- | lib/workqueue.c | 2 | ||||
| -rw-r--r-- | lib/yang_translator.c | 2 | ||||
| -rw-r--r-- | lib/yang_wrappers.c | 2 |
34 files changed, 258 insertions, 241 deletions
diff --git a/lib/command.c b/lib/command.c index b46241ac87..559457c119 100644 --- a/lib/command.c +++ b/lib/command.c @@ -1277,8 +1277,7 @@ int cmd_execute(struct vty *vty, const char *cmd, hook_call(cmd_execute_done, vty, cmd_exec); - if (cmd_out) - XFREE(MTYPE_TMP, cmd_out); + XFREE(MTYPE_TMP, cmd_out); return ret; } @@ -2408,8 +2407,7 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) ret = zlog_set_file(fullpath, loglevel); - if (p) - XFREE(MTYPE_TMP, p); + XFREE(MTYPE_TMP, p); if (!ret) { if (vty) @@ -2417,8 +2415,7 @@ static int set_log_file(struct vty *vty, const char *fname, int loglevel) return CMD_WARNING_CONFIG_FAILED; } - if (host.logfile) - XFREE(MTYPE_HOST, host.logfile); + XFREE(MTYPE_HOST, host.logfile); host.logfile = XSTRDUP(MTYPE_HOST, fname); @@ -2487,8 +2484,7 @@ static void disable_log_file(void) { zlog_reset_file(); - if (host.logfile) - XFREE(MTYPE_HOST, host.logfile); + XFREE(MTYPE_HOST, host.logfile); host.logfile = NULL; } @@ -2637,8 +2633,7 @@ int cmd_banner_motd_file(const char *file) return CMD_ERR_NO_FILE; in = strstr(rpath, SYSCONFDIR); if (in == rpath) { - if (host.motdfile) - XFREE(MTYPE_HOST, host.motdfile); + XFREE(MTYPE_HOST, host.motdfile); host.motdfile = XSTRDUP(MTYPE_HOST, file); } else success = CMD_WARNING_CONFIG_FAILED; @@ -2723,8 +2718,7 @@ DEFUN(find, /* Set config filename. Called from vty.c */ void host_config_set(const char *filename) { - if (host.config) - XFREE(MTYPE_HOST, host.config); + XFREE(MTYPE_HOST, host.config); host.config = XSTRDUP(MTYPE_HOST, filename); } @@ -2904,24 +2898,15 @@ void cmd_terminate(void) cmdvec = NULL; } - if (host.name) - XFREE(MTYPE_HOST, host.name); - if (host.domainname) - XFREE(MTYPE_HOST, host.domainname); - if (host.password) - XFREE(MTYPE_HOST, host.password); - if (host.password_encrypt) - XFREE(MTYPE_HOST, host.password_encrypt); - if (host.enable) - XFREE(MTYPE_HOST, host.enable); - if (host.enable_encrypt) - XFREE(MTYPE_HOST, host.enable_encrypt); - if (host.logfile) - XFREE(MTYPE_HOST, host.logfile); - if (host.motdfile) - XFREE(MTYPE_HOST, host.motdfile); - if (host.config) - XFREE(MTYPE_HOST, host.config); + XFREE(MTYPE_HOST, host.name); + XFREE(MTYPE_HOST, host.domainname); + XFREE(MTYPE_HOST, host.password); + XFREE(MTYPE_HOST, host.password_encrypt); + XFREE(MTYPE_HOST, host.enable); + XFREE(MTYPE_HOST, host.enable_encrypt); + XFREE(MTYPE_HOST, host.logfile); + XFREE(MTYPE_HOST, host.motdfile); + XFREE(MTYPE_HOST, host.config); list_delete(&varhandlers); qobj_finish(); diff --git a/lib/command_graph.c b/lib/command_graph.c index 0e8669c4b5..4757fd951f 100644 --- a/lib/command_graph.c +++ b/lib/command_graph.c @@ -471,7 +471,7 @@ void cmd_graph_node_print_cb(struct graph_node *gn, struct buffer *buf) struct cmd_token *tok = gn->data; const char *color; - if (wasend == true) { + if (wasend) { wasend = false; return; } diff --git a/lib/distribute.c b/lib/distribute.c index 7cc10a230d..fa8ac5242e 100644 --- a/lib/distribute.c +++ b/lib/distribute.c @@ -44,16 +44,15 @@ static void distribute_free(struct distribute *dist) { int i = 0; - if (dist->ifname) - XFREE(MTYPE_DISTRIBUTE_IFNAME, dist->ifname); + XFREE(MTYPE_DISTRIBUTE_IFNAME, dist->ifname); - for (i = 0; i < DISTRIBUTE_MAX; i++) - if (dist->list[i]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[i]); + for (i = 0; i < DISTRIBUTE_MAX; i++) { + XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[i]); + } - for (i = 0; i < DISTRIBUTE_MAX; i++) - if (dist->prefix[i]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[i]); + for (i = 0; i < DISTRIBUTE_MAX; i++) { + XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[i]); + } XFREE(MTYPE_DISTRIBUTE, dist); } @@ -83,8 +82,7 @@ struct distribute *distribute_lookup(struct distribute_ctx *ctx, dist = hash_lookup(ctx->disthash, &key); - if (key.ifname) - XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); return dist; } @@ -128,8 +126,7 @@ static struct distribute *distribute_get(struct distribute_ctx *ctx, ret = hash_get(ctx->disthash, &key, (void *(*)(void *))distribute_hash_alloc); - if (key.ifname) - XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); + XFREE(MTYPE_DISTRIBUTE_IFNAME, key.ifname); return ret; } @@ -163,8 +160,7 @@ static void distribute_list_set(struct distribute_ctx *ctx, dist = distribute_get(ctx, ifname); - if (dist->list[type]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]); + XFREE(MTYPE_DISTRIBUTE_NAME, dist->list[type]); dist->list[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, alist_name); /* Apply this distribute-list to the interface. */ @@ -210,8 +206,7 @@ static void distribute_list_prefix_set(struct distribute_ctx *ctx, dist = distribute_get(ctx, ifname); - if (dist->prefix[type]) - XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]); + XFREE(MTYPE_DISTRIBUTE_NAME, dist->prefix[type]); dist->prefix[type] = XSTRDUP(MTYPE_DISTRIBUTE_NAME, plist_name); /* Apply this distribute-list to the interface. */ diff --git a/lib/event_counter.c b/lib/event_counter.c index c520937a38..57dbfb5fd1 100644 --- a/lib/event_counter.c +++ b/lib/event_counter.c @@ -62,7 +62,7 @@ const char *event_counter_format(const struct event_counter *counter) || strftime(timebuf, sizeof(timebuf), "%a, %d %b %Y %T %z", last_change) == 0) { - strncpy(timebuf, "???", sizeof(timebuf)); + strlcpy(timebuf, "???", sizeof(timebuf)); } snprintf(rv, sizeof(rv), "%5llu last: %s", counter->count, diff --git a/lib/filter.c b/lib/filter.c index 317c1b68b7..276df4b4d7 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -128,8 +128,7 @@ static struct access_master *access_master_get(afi_t afi) /* Allocate new filter structure. */ static struct filter *filter_new(void) { - return (struct filter *)XCALLOC(MTYPE_ACCESS_FILTER, - sizeof(struct filter)); + return XCALLOC(MTYPE_ACCESS_FILTER, sizeof(struct filter)); } static void filter_free(struct filter *filter) @@ -202,8 +201,7 @@ static int filter_match_zebra(struct filter *mfilter, const struct prefix *p) /* Allocate new access list structure. */ static struct access_list *access_list_new(void) { - return (struct access_list *)XCALLOC(MTYPE_ACCESS_LIST, - sizeof(struct access_list)); + return XCALLOC(MTYPE_ACCESS_LIST, sizeof(struct access_list)); } /* Free allocated access_list. */ @@ -242,11 +240,9 @@ static void access_list_delete(struct access_list *access) else list->head = access->next; - if (access->name) - XFREE(MTYPE_ACCESS_LIST_STR, access->name); + XFREE(MTYPE_ACCESS_LIST_STR, access->name); - if (access->remark) - XFREE(MTYPE_TMP, access->remark); + XFREE(MTYPE_TMP, access->remark); access_list_free(access); } diff --git a/lib/frr_pthread.c b/lib/frr_pthread.c index d7f655271b..2a18e5cfc6 100644 --- a/lib/frr_pthread.c +++ b/lib/frr_pthread.c @@ -110,8 +110,7 @@ void frr_pthread_destroy(struct frr_pthread *fpt) pthread_mutex_destroy(&fpt->mtx); pthread_mutex_destroy(fpt->running_cond_mtx); pthread_cond_destroy(fpt->running_cond); - if (fpt->name) - XFREE(MTYPE_FRR_PTHREAD, fpt->name); + XFREE(MTYPE_FRR_PTHREAD, fpt->name); XFREE(MTYPE_PTHREAD_PRIM, fpt->running_cond_mtx); XFREE(MTYPE_PTHREAD_PRIM, fpt->running_cond); XFREE(MTYPE_FRR_PTHREAD, fpt); diff --git a/lib/frr_zmq.c b/lib/frr_zmq.c index cfea238d95..7781beae5e 100644 --- a/lib/frr_zmq.c +++ b/lib/frr_zmq.c @@ -176,8 +176,6 @@ int funcname_frrzmq_thread_add_read(struct thread_master *master, cb = *cbp; else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - if (!cb) - return -1; cb->write.cancelled = 1; *cbp = cb; @@ -286,8 +284,6 @@ int funcname_frrzmq_thread_add_write(struct thread_master *master, cb = *cbp; else { cb = XCALLOC(MTYPE_ZEROMQ_CB, sizeof(struct frrzmq_cb)); - if (!cb) - return -1; cb->read.cancelled = 1; *cbp = cb; diff --git a/lib/frrstr.c b/lib/frrstr.c index 85d968182b..fd337073f8 100644 --- a/lib/frrstr.c +++ b/lib/frrstr.c @@ -155,13 +155,13 @@ void frrstr_strvec_free(vector v) bool begins_with(const char *str, const char *prefix) { if (!str || !prefix) - return 0; + return false; size_t lenstr = strlen(str); size_t lenprefix = strlen(prefix); if (lenprefix > lenstr) - return 0; + return false; return strncmp(str, prefix, lenprefix) == 0; } diff --git a/lib/hash.c b/lib/hash.c index 9f9fc31d37..c02b81814c 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -95,8 +95,6 @@ static void hash_expand(struct hash *hash) new_index = XCALLOC(MTYPE_HASH_INDEX, sizeof(struct hash_bucket *) * new_size); - if (new_index == NULL) - return; hash->stats.empty = new_size; @@ -324,8 +322,7 @@ void hash_free(struct hash *hash) } pthread_mutex_unlock(&_hashes_mtx); - if (hash->name) - XFREE(MTYPE_HASH, hash->name); + XFREE(MTYPE_HASH, hash->name); XFREE(MTYPE_HASH_INDEX, hash->index); XFREE(MTYPE_HASH, hash); @@ -234,8 +234,7 @@ void if_delete(struct interface *ifp) if_link_params_free(ifp); - if (ifp->desc) - XFREE(MTYPE_TMP, ifp->desc); + XFREE(MTYPE_TMP, ifp->desc); XFREE(MTYPE_IF, ifp); } @@ -708,8 +707,7 @@ void connected_free(struct connected *connected) if (connected->destination) prefix_free(connected->destination); - if (connected->label) - XFREE(MTYPE_CONNECTED_LABEL, connected->label); + XFREE(MTYPE_CONNECTED_LABEL, connected->label); XFREE(MTYPE_CONNECTED, connected); } @@ -1349,8 +1347,7 @@ static int lib_interface_description_modify(enum nb_event event, return NB_OK; ifp = yang_dnode_get_entry(dnode, true); - if (ifp->desc) - XFREE(MTYPE_TMP, ifp->desc); + XFREE(MTYPE_TMP, ifp->desc); description = yang_dnode_get_string(dnode, NULL); ifp->desc = XSTRDUP(MTYPE_TMP, description); @@ -1366,8 +1363,7 @@ static int lib_interface_description_delete(enum nb_event event, return NB_OK; ifp = yang_dnode_get_entry(dnode, true); - if (ifp->desc) - XFREE(MTYPE_TMP, ifp->desc); + XFREE(MTYPE_TMP, ifp->desc); return NB_OK; } diff --git a/lib/if_rmap.c b/lib/if_rmap.c index 7ac5368171..955c1417c4 100644 --- a/lib/if_rmap.c +++ b/lib/if_rmap.c @@ -26,14 +26,12 @@ #include "if.h" #include "if_rmap.h" +DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX, "Interface route map container") +DEFINE_MTYPE_STATIC(LIB, IF_RMAP_CTX_NAME, "Interface route map container name") DEFINE_MTYPE_STATIC(LIB, IF_RMAP, "Interface route map") DEFINE_MTYPE_STATIC(LIB, IF_RMAP_NAME, "I.f. route map name") -struct hash *ifrmaphash; - -/* Hook functions. */ -static void (*if_rmap_add_hook)(struct if_rmap *) = NULL; -static void (*if_rmap_delete_hook)(struct if_rmap *) = NULL; +struct list *if_rmap_ctx_list; static struct if_rmap *if_rmap_new(void) { @@ -46,18 +44,15 @@ static struct if_rmap *if_rmap_new(void) static void if_rmap_free(struct if_rmap *if_rmap) { - if (if_rmap->ifname) - XFREE(MTYPE_IF_RMAP_NAME, if_rmap->ifname); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->ifname); - if (if_rmap->routemap[IF_RMAP_IN]) - XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]); - if (if_rmap->routemap[IF_RMAP_OUT]) - XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]); XFREE(MTYPE_IF_RMAP, if_rmap); } -struct if_rmap *if_rmap_lookup(const char *ifname) +struct if_rmap *if_rmap_lookup(struct if_rmap_ctx *ctx, const char *ifname) { struct if_rmap key; struct if_rmap *if_rmap; @@ -65,22 +60,25 @@ struct if_rmap *if_rmap_lookup(const char *ifname) /* temporary copy */ key.ifname = (ifname) ? XSTRDUP(MTYPE_IF_RMAP_NAME, ifname) : NULL; - if_rmap = hash_lookup(ifrmaphash, &key); + if_rmap = hash_lookup(ctx->ifrmaphash, &key); - if (key.ifname) - XFREE(MTYPE_IF_RMAP_NAME, key.ifname); + XFREE(MTYPE_IF_RMAP_NAME, key.ifname); return if_rmap; } -void if_rmap_hook_add(void (*func)(struct if_rmap *)) +void if_rmap_hook_add(struct if_rmap_ctx *ctx, + void (*func)(struct if_rmap_ctx *ctx, + struct if_rmap *)) { - if_rmap_add_hook = func; + ctx->if_rmap_add_hook = func; } -void if_rmap_hook_delete(void (*func)(struct if_rmap *)) +void if_rmap_hook_delete(struct if_rmap_ctx *ctx, + void (*func)(struct if_rmap_ctx *ctx, + struct if_rmap *)) { - if_rmap_delete_hook = func; + ctx->if_rmap_delete_hook = func; } static void *if_rmap_hash_alloc(void *arg) @@ -94,7 +92,7 @@ static void *if_rmap_hash_alloc(void *arg) return if_rmap; } -static struct if_rmap *if_rmap_get(const char *ifname) +static struct if_rmap *if_rmap_get(struct if_rmap_ctx *ctx, const char *ifname) { struct if_rmap key; struct if_rmap *ret; @@ -102,10 +100,9 @@ static struct if_rmap *if_rmap_get(const char *ifname) /* temporary copy */ key.ifname = (ifname) ? XSTRDUP(MTYPE_IF_RMAP_NAME, ifname) : NULL; - ret = hash_get(ifrmaphash, &key, if_rmap_hash_alloc); + ret = hash_get(ctx->ifrmaphash, &key, if_rmap_hash_alloc); - if (key.ifname) - XFREE(MTYPE_IF_RMAP_NAME, key.ifname); + XFREE(MTYPE_IF_RMAP_NAME, key.ifname); return ret; } @@ -125,40 +122,38 @@ static bool if_rmap_hash_cmp(const void *arg1, const void *arg2) return strcmp(if_rmap1->ifname, if_rmap2->ifname) == 0; } -static struct if_rmap *if_rmap_set(const char *ifname, enum if_rmap_type type, +static struct if_rmap *if_rmap_set(struct if_rmap_ctx *ctx, + const char *ifname, enum if_rmap_type type, const char *routemap_name) { struct if_rmap *if_rmap; - if_rmap = if_rmap_get(ifname); + if_rmap = if_rmap_get(ctx, ifname); if (type == IF_RMAP_IN) { - if (if_rmap->routemap[IF_RMAP_IN]) - XFREE(MTYPE_IF_RMAP_NAME, - if_rmap->routemap[IF_RMAP_IN]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_IN]); if_rmap->routemap[IF_RMAP_IN] = XSTRDUP(MTYPE_IF_RMAP_NAME, routemap_name); } if (type == IF_RMAP_OUT) { - if (if_rmap->routemap[IF_RMAP_OUT]) - XFREE(MTYPE_IF_RMAP_NAME, - if_rmap->routemap[IF_RMAP_OUT]); + XFREE(MTYPE_IF_RMAP_NAME, if_rmap->routemap[IF_RMAP_OUT]); if_rmap->routemap[IF_RMAP_OUT] = XSTRDUP(MTYPE_IF_RMAP_NAME, routemap_name); } - if (if_rmap_add_hook) - (*if_rmap_add_hook)(if_rmap); + if (ctx->if_rmap_add_hook) + (ctx->if_rmap_add_hook)(ctx, if_rmap); return if_rmap; } -static int if_rmap_unset(const char *ifname, enum if_rmap_type type, +static int if_rmap_unset(struct if_rmap_ctx *ctx, + const char *ifname, enum if_rmap_type type, const char *routemap_name) { struct if_rmap *if_rmap; - if_rmap = if_rmap_lookup(ifname); + if_rmap = if_rmap_lookup(ctx, ifname); if (!if_rmap) return 0; @@ -182,12 +177,12 @@ static int if_rmap_unset(const char *ifname, enum if_rmap_type type, if_rmap->routemap[IF_RMAP_OUT] = NULL; } - if (if_rmap_delete_hook) - (*if_rmap_delete_hook)(if_rmap); + if (ctx->if_rmap_delete_hook) + ctx->if_rmap_delete_hook(ctx, if_rmap); if (if_rmap->routemap[IF_RMAP_IN] == NULL && if_rmap->routemap[IF_RMAP_OUT] == NULL) { - hash_release(ifrmaphash, if_rmap); + hash_release(ctx->ifrmaphash, if_rmap); if_rmap_free(if_rmap); } @@ -207,6 +202,8 @@ DEFUN (if_rmap, int idx_in_out = 2; int idx_ifname = 3; enum if_rmap_type type; + struct if_rmap_ctx *ctx = + (struct if_rmap_ctx *)listnode_head(if_rmap_ctx_list); if (strncmp(argv[idx_in_out]->text, "in", 1) == 0) type = IF_RMAP_IN; @@ -217,7 +214,8 @@ DEFUN (if_rmap, return CMD_WARNING_CONFIG_FAILED; } - if_rmap_set(argv[idx_ifname]->arg, type, argv[idx_rmap_name]->arg); + if_rmap_set(ctx, argv[idx_ifname]->arg, + type, argv[idx_rmap_name]->arg); return CMD_SUCCESS; } @@ -237,6 +235,8 @@ DEFUN (no_if_rmap, int idx_ifname = 4; int ret; enum if_rmap_type type; + struct if_rmap_ctx *ctx = + (struct if_rmap_ctx *)listnode_head(if_rmap_ctx_list); if (strncmp(argv[idx_in_out]->arg, "i", 1) == 0) type = IF_RMAP_IN; @@ -247,7 +247,7 @@ DEFUN (no_if_rmap, return CMD_WARNING_CONFIG_FAILED; } - ret = if_rmap_unset(argv[idx_ifname]->arg, type, + ret = if_rmap_unset(ctx, argv[idx_ifname]->arg, type, argv[idx_routemap_name]->arg); if (!ret) { vty_out(vty, "route-map doesn't exist\n"); @@ -258,11 +258,13 @@ DEFUN (no_if_rmap, /* Configuration write function. */ -int config_write_if_rmap(struct vty *vty) +int config_write_if_rmap(struct vty *vty, + struct if_rmap_ctx *ctx) { unsigned int i; struct hash_bucket *mp; int write = 0; + struct hash *ifrmaphash = ctx->ifrmaphash; for (i = 0; i < ifrmaphash->size; i++) for (mp = ifrmaphash->index[i]; mp; mp = mp->next) { @@ -287,18 +289,44 @@ int config_write_if_rmap(struct vty *vty) return write; } -void if_rmap_reset(void) +void if_rmap_ctx_delete(struct if_rmap_ctx *ctx) { - hash_clean(ifrmaphash, (void (*)(void *))if_rmap_free); + hash_clean(ctx->ifrmaphash, (void (*)(void *))if_rmap_free); + if (ctx->name) + XFREE(MTYPE_IF_RMAP_CTX_NAME, ctx); + XFREE(MTYPE_IF_RMAP_CTX, ctx); +} + +/* name is optional: either vrf name, or other */ +struct if_rmap_ctx *if_rmap_ctx_create(const char *name) +{ + struct if_rmap_ctx *ctx; + + ctx = XCALLOC(MTYPE_IF_RMAP_CTX, sizeof(struct if_rmap_ctx)); + + if (ctx->name) + ctx->name = XSTRDUP(MTYPE_IF_RMAP_CTX_NAME, name); + ctx->ifrmaphash = hash_create_size(4, if_rmap_hash_make, if_rmap_hash_cmp, + "Interface Route-Map Hash"); + if (!if_rmap_ctx_list) + if_rmap_ctx_list = list_new(); + listnode_add(if_rmap_ctx_list, ctx); + return ctx; } void if_rmap_init(int node) { - ifrmaphash = hash_create_size(4, if_rmap_hash_make, if_rmap_hash_cmp, - "Interface Route-Map Hash"); if (node == RIPNG_NODE) { } else if (node == RIP_NODE) { install_element(RIP_NODE, &if_rmap_cmd); install_element(RIP_NODE, &no_if_rmap_cmd); } + if_rmap_ctx_list = list_new(); +} + +void if_rmap_terminate(void) +{ + if (!if_rmap_ctx_list) + return; + list_delete(&if_rmap_ctx_list); } diff --git a/lib/if_rmap.h b/lib/if_rmap.h index 8dded2cb48..dfc7298823 100644 --- a/lib/if_rmap.h +++ b/lib/if_rmap.h @@ -34,12 +34,33 @@ struct if_rmap { char *routemap[IF_RMAP_MAX]; }; -extern void if_rmap_init(int); -extern void if_rmap_reset(void); -extern void if_rmap_hook_add(void (*)(struct if_rmap *)); -extern void if_rmap_hook_delete(void (*)(struct if_rmap *)); -extern struct if_rmap *if_rmap_lookup(const char *); -extern int config_write_if_rmap(struct vty *); +struct if_rmap_ctx { + /* if_rmap */ + struct hash *ifrmaphash; + + /* Hook functions. */ + void (*if_rmap_add_hook)(struct if_rmap_ctx *ctx, + struct if_rmap *ifrmap); + void (*if_rmap_delete_hook)(struct if_rmap_ctx *ctx, + struct if_rmap *ifrmap); + + /* naming information */ + char *name; +}; + +extern struct if_rmap_ctx *if_rmap_ctx_create(const char *name); +extern void if_rmap_ctx_delete(struct if_rmap_ctx *ctx); +extern void if_rmap_init(int node); +extern void if_rmap_terminate(void); +void if_rmap_hook_add(struct if_rmap_ctx *ctx, + void (*func)(struct if_rmap_ctx *ctx, + struct if_rmap *)); +void if_rmap_hook_delete(struct if_rmap_ctx *ctx, + void (*func)(struct if_rmap_ctx *ctx, + struct if_rmap *)); +extern struct if_rmap *if_rmap_lookup(struct if_rmap_ctx *ctx, + const char *ifname); +extern int config_write_if_rmap(struct vty *, struct if_rmap_ctx *ctx); #ifdef __cplusplus } diff --git a/lib/imsg.c b/lib/imsg.c index 935d137727..57e70617d2 100644 --- a/lib/imsg.c +++ b/lib/imsg.c @@ -18,6 +18,7 @@ #include <zebra.h> +#include "memory.h" #include "queue.h" #include "imsg.h" @@ -35,7 +36,7 @@ static int available_fds(unsigned int n) unsigned int i; int ret, fds[256]; - if (n > (sizeof(fds) / sizeof(fds[0]))) + if (n > (unsigned int)array_size(fds)) return (1); ret = 0; diff --git a/lib/jhash.c b/lib/jhash.c index cb6946f37e..0d561ef3a4 100644 --- a/lib/jhash.c +++ b/lib/jhash.c @@ -116,7 +116,7 @@ uint32_t jhash(const void *key, uint32_t length, uint32_t initval) /* fallthru */ case 1: a += k[0]; - }; + } __jhash_mix(a, b, c); @@ -151,7 +151,7 @@ uint32_t jhash2(const uint32_t *k, uint32_t length, uint32_t initval) /* fallthru */ case 1: a += k[0]; - }; + } __jhash_mix(a, b, c); diff --git a/lib/keychain.c b/lib/keychain.c index 9aa3ef695f..0a96c4cf0e 100644 --- a/lib/keychain.c +++ b/lib/keychain.c @@ -116,8 +116,7 @@ static struct keychain *keychain_get(const char *name) static void keychain_delete(struct keychain *keychain) { - if (keychain->name) - XFREE(MTYPE_KEYCHAIN, keychain->name); + XFREE(MTYPE_KEYCHAIN, keychain->name); list_delete(&keychain->key); listnode_delete(keychain_list, keychain); @@ -217,8 +216,7 @@ static void key_delete(struct keychain *keychain, struct key *key) { listnode_delete(keychain->key, key); - if (key->string) - XFREE(MTYPE_KEY, key->string); + XFREE(MTYPE_KEY, key->string); key_free(key); } diff --git a/lib/libfrr.c b/lib/libfrr.c index 9119b04992..1afe30d618 100644 --- a/lib/libfrr.c +++ b/lib/libfrr.c @@ -61,7 +61,7 @@ static char dbfile_default[512]; #endif static char vtypath_default[256]; -bool debug_memstats_at_exit = 0; +bool debug_memstats_at_exit = false; static bool nodetach_term, nodetach_daemon; static char comb_optstr[256]; @@ -851,8 +851,7 @@ void closezlog(void) if (zl->fp != NULL) fclose(zl->fp); - if (zl->filename != NULL) - XFREE(MTYPE_ZLOG, zl->filename); + XFREE(MTYPE_ZLOG, zl->filename); XFREE(MTYPE_ZLOG, zl); zlog_default = NULL; @@ -911,8 +910,7 @@ int zlog_reset_file(void) logfile_fd = -1; zl->maxlvl[ZLOG_DEST_FILE] = ZLOG_DISABLED; - if (zl->filename) - XFREE(MTYPE_ZLOG, zl->filename); + XFREE(MTYPE_ZLOG, zl->filename); zl->filename = NULL; pthread_mutex_unlock(&loglock); diff --git a/lib/module.c b/lib/module.c index 6754b94579..098c550684 100644 --- a/lib/module.c +++ b/lib/module.c @@ -141,8 +141,7 @@ struct frrmod_runtime *frrmod_load(const char *spec, const char *dir, char *err, return rtinfo; out_fail: - if (rtinfo->load_args) - XFREE(MTYPE_MODULE_LOADARGS, rtinfo->load_args); + XFREE(MTYPE_MODULE_LOADARGS, rtinfo->load_args); XFREE(MTYPE_MODULE_LOADNAME, rtinfo->load_name); return NULL; } diff --git a/lib/netns_linux.c b/lib/netns_linux.c index ef2f5dc953..55c66fdc3d 100644 --- a/lib/netns_linux.c +++ b/lib/netns_linux.c @@ -344,8 +344,7 @@ void ns_delete(struct ns *ns) // if_terminate (&ns->iflist); RB_REMOVE(ns_head, &ns_tree, ns); - if (ns->name) - XFREE(MTYPE_NS_NAME, ns->name); + XFREE(MTYPE_NS_NAME, ns->name); XFREE(MTYPE_NS, ns); } diff --git a/lib/nexthop.h b/lib/nexthop.h index c79ec590a8..fd27ca207b 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -83,7 +83,6 @@ struct nexthop { #define NEXTHOP_FLAG_MATCHED (1 << 4) /* Already matched vs a nexthop */ #define NEXTHOP_FLAG_FILTERED (1 << 5) /* rmap filtered, used by static only */ #define NEXTHOP_FLAG_DUPLICATE (1 << 6) /* nexthop duplicates another active one */ -#define NEXTHOP_FLAG_EVPN_RVTEP (1 << 7) /* EVPN remote vtep nexthop */ #define NEXTHOP_IS_ACTIVE(flags) \ (CHECK_FLAG(flags, NEXTHOP_FLAG_ACTIVE) \ && !CHECK_FLAG(flags, NEXTHOP_FLAG_DUPLICATE)) diff --git a/lib/nexthop_group.c b/lib/nexthop_group.c index 23ea96f75c..f940418d83 100644 --- a/lib/nexthop_group.c +++ b/lib/nexthop_group.c @@ -205,11 +205,9 @@ static int nhgl_cmp(struct nexthop_hold *nh1, struct nexthop_hold *nh2) static void nhgl_delete(struct nexthop_hold *nh) { - if (nh->intf) - XFREE(MTYPE_TMP, nh->intf); + XFREE(MTYPE_TMP, nh->intf); - if (nh->nhvrf_name) - XFREE(MTYPE_TMP, nh->nhvrf_name); + XFREE(MTYPE_TMP, nh->nhvrf_name); XFREE(MTYPE_TMP, nh); } diff --git a/lib/northbound.c b/lib/northbound.c index 15139aa8d0..edf7e0eca6 100644 --- a/lib/northbound.c +++ b/lib/northbound.c @@ -348,39 +348,58 @@ static void nb_config_diff_del_changes(struct nb_config_cbs *changes) * configurations. Given a new subtree, calculate all new YANG data nodes, * excluding default leafs and leaf-lists. This is a recursive function. */ -static void nb_config_diff_new_subtree(const struct lyd_node *dnode, - struct nb_config_cbs *changes) +static void nb_config_diff_created(const struct lyd_node *dnode, + struct nb_config_cbs *changes) { + enum nb_operation operation; struct lyd_node *child; - LY_TREE_FOR (dnode->child, child) { - enum nb_operation operation; + switch (dnode->schema->nodetype) { + case LYS_LEAF: + case LYS_LEAFLIST: + if (lyd_wd_default((struct lyd_node_leaf_list *)dnode)) + break; - switch (child->schema->nodetype) { - case LYS_LEAF: - case LYS_LEAFLIST: - if (lyd_wd_default((struct lyd_node_leaf_list *)child)) - break; + if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema)) + operation = NB_OP_CREATE; + else if (nb_operation_is_valid(NB_OP_MODIFY, dnode->schema)) + operation = NB_OP_MODIFY; + else + return; - if (nb_operation_is_valid(NB_OP_CREATE, child->schema)) - operation = NB_OP_CREATE; - else if (nb_operation_is_valid(NB_OP_MODIFY, - child->schema)) - operation = NB_OP_MODIFY; - else - continue; + nb_config_diff_add_change(changes, operation, dnode); + break; + case LYS_CONTAINER: + case LYS_LIST: + if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema)) + nb_config_diff_add_change(changes, NB_OP_CREATE, dnode); - nb_config_diff_add_change(changes, operation, child); - break; - case LYS_CONTAINER: - case LYS_LIST: - if (nb_operation_is_valid(NB_OP_CREATE, child->schema)) - nb_config_diff_add_change(changes, NB_OP_CREATE, - child); - nb_config_diff_new_subtree(child, changes); - break; - default: - break; + /* Process child nodes recursively. */ + LY_TREE_FOR (dnode->child, child) { + nb_config_diff_created(child, changes); + } + break; + default: + break; + } +} + +static void nb_config_diff_deleted(const struct lyd_node *dnode, + struct nb_config_cbs *changes) +{ + if (nb_operation_is_valid(NB_OP_DESTROY, dnode->schema)) + nb_config_diff_add_change(changes, NB_OP_DESTROY, dnode); + else if (CHECK_FLAG(dnode->schema->nodetype, LYS_CONTAINER)) { + struct lyd_node *child; + + /* + * Non-presence containers need special handling since they + * don't have "destroy" callbacks. In this case, what we need to + * do is to call the "destroy" callbacks of their child nodes + * when applicable (i.e. optional nodes). + */ + LY_TREE_FOR (dnode->child, child) { + nb_config_diff_deleted(child, changes); } } } @@ -399,42 +418,27 @@ static void nb_config_diff(const struct nb_config *config1, for (int i = 0; diff->type[i] != LYD_DIFF_END; i++) { LYD_DIFFTYPE type; struct lyd_node *dnode; - enum nb_operation operation; type = diff->type[i]; switch (type) { case LYD_DIFF_CREATED: dnode = diff->second[i]; - - if (nb_operation_is_valid(NB_OP_CREATE, dnode->schema)) - operation = NB_OP_CREATE; - else if (nb_operation_is_valid(NB_OP_MODIFY, - dnode->schema)) - operation = NB_OP_MODIFY; - else - continue; + nb_config_diff_created(dnode, changes); break; case LYD_DIFF_DELETED: dnode = diff->first[i]; - operation = NB_OP_DESTROY; + nb_config_diff_deleted(dnode, changes); break; case LYD_DIFF_CHANGED: dnode = diff->second[i]; - operation = NB_OP_MODIFY; + nb_config_diff_add_change(changes, NB_OP_MODIFY, dnode); break; case LYD_DIFF_MOVEDAFTER1: case LYD_DIFF_MOVEDAFTER2: default: continue; } - - nb_config_diff_add_change(changes, operation, dnode); - - if (type == LYD_DIFF_CREATED - && CHECK_FLAG(dnode->schema->nodetype, - LYS_CONTAINER | LYS_LIST)) - nb_config_diff_new_subtree(dnode, changes); } lyd_free_diff(diff); diff --git a/lib/northbound_confd.c b/lib/northbound_confd.c index a8e0017819..a499d48c12 100644 --- a/lib/northbound_confd.c +++ b/lib/northbound_confd.c @@ -1383,7 +1383,7 @@ error: static int frr_confd_finish(void) { - if (confd_connected == false) + if (!confd_connected) return 0; frr_confd_finish_cdb(); diff --git a/lib/plist.c b/lib/plist.c index 41c8e4f8c0..2a97e1e5b2 100644 --- a/lib/plist.c +++ b/lib/plist.c @@ -326,8 +326,7 @@ static void prefix_list_delete(struct prefix_list *plist) else list->head = plist->next; - if (plist->desc) - XFREE(MTYPE_TMP, plist->desc); + XFREE(MTYPE_TMP, plist->desc); /* Make sure master's recent changed prefix-list information is cleared. */ @@ -338,8 +337,7 @@ static void prefix_list_delete(struct prefix_list *plist) if (master->delete_hook) (*master->delete_hook)(plist); - if (plist->name) - XFREE(MTYPE_MPREFIX_LIST_STR, plist->name); + XFREE(MTYPE_MPREFIX_LIST_STR, plist->name); XFREE(MTYPE_PREFIX_LIST_TRIE, plist->trie); diff --git a/lib/pqueue.c b/lib/pqueue.c index 1565de216e..87b54a681a 100644 --- a/lib/pqueue.c +++ b/lib/pqueue.c @@ -133,8 +133,6 @@ static int pqueue_expand(struct pqueue *queue) newarray = XCALLOC(MTYPE_PQUEUE_DATA, queue->array_size * DATA_SIZE * 2); - if (newarray == NULL) - return 0; memcpy(newarray, queue->array, queue->array_size * DATA_SIZE); diff --git a/lib/prefix.c b/lib/prefix.c index babd4304d1..52bb266f11 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -866,7 +866,7 @@ int str2prefix_ipv4(const char *str, struct prefix_ipv4 *p) return ret; } else { cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1); - strncpy(cp, str, pnt - str); + memcpy(cp, str, pnt - str); *(cp + (pnt - str)) = '\0'; ret = inet_aton(cp, &p->prefix); XFREE(MTYPE_TMP, cp); @@ -913,7 +913,7 @@ int str2prefix_eth(const char *str, struct prefix_eth *p) } cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1); - strncpy(cp, str, pnt - str); + memcpy(cp, str, pnt - str); *(cp + (pnt - str)) = '\0'; str_addr = cp; @@ -944,8 +944,7 @@ int str2prefix_eth(const char *str, struct prefix_eth *p) ret = 1; done: - if (cp) - XFREE(MTYPE_TMP, cp); + XFREE(MTYPE_TMP, cp); return ret; } @@ -1030,7 +1029,7 @@ int str2prefix_ipv6(const char *str, struct prefix_ipv6 *p) int plen; cp = XMALLOC(MTYPE_TMP, (pnt - str) + 1); - strncpy(cp, str, pnt - str); + memcpy(cp, str, pnt - str); *(cp + (pnt - str)) = '\0'; ret = inet_pton(AF_INET6, cp, &p->prefix); XFREE(MTYPE_TMP, cp); @@ -1503,8 +1502,7 @@ char *prefix_mac2str(const struct ethaddr *mac, char *buf, int size) if (!mac) return NULL; if (!buf) - ptr = (char *)XMALLOC(MTYPE_TMP, - ETHER_ADDR_STRLEN * sizeof(char)); + ptr = XMALLOC(MTYPE_TMP, ETHER_ADDR_STRLEN * sizeof(char)); else { assert(size >= ETHER_ADDR_STRLEN); ptr = buf; @@ -1585,8 +1583,7 @@ char *esi_to_str(const esi_t *esi, char *buf, int size) if (!esi) return NULL; if (!buf) - ptr = (char *)XMALLOC(MTYPE_TMP, - ESI_STR_LEN * sizeof(char)); + ptr = XMALLOC(MTYPE_TMP, ESI_STR_LEN * sizeof(char)); else { assert(size >= ESI_STR_LEN); ptr = buf; diff --git a/lib/privs.c b/lib/privs.c index 2932800070..3ce8e0d57a 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -706,6 +706,14 @@ struct zebra_privs_t *_zprivs_raise(struct zebra_privs_t *privs, if (!privs) return NULL; + /* If we're already elevated, just return */ + pthread_mutex_lock(&(privs->mutex)); + if (++privs->refcount > 1) { + pthread_mutex_unlock(&(privs->mutex)); + return privs; + } + pthread_mutex_unlock(&(privs->mutex)); + errno = 0; if (privs->change(ZPRIVS_RAISE)) { zlog_err("%s: Failed to raise privileges (%s)", @@ -723,6 +731,14 @@ void _zprivs_lower(struct zebra_privs_t **privs) if (!*privs) return; + /* Don't lower privs if there's another caller */ + pthread_mutex_lock(&(*privs)->mutex); + if (--((*privs)->refcount) > 0) { + pthread_mutex_unlock(&(*privs)->mutex); + return; + } + pthread_mutex_unlock(&(*privs)->mutex); + errno = 0; if ((*privs)->change(ZPRIVS_LOWER)) { zlog_err("%s: Failed to lower privileges (%s)", @@ -743,6 +759,9 @@ void zprivs_preinit(struct zebra_privs_t *zprivs) exit(1); } + pthread_mutex_init(&(zprivs->mutex), NULL); + zprivs->refcount = 0; + if (zprivs->vty_group) { /* in a "NULL" setup, this is allowed to fail too, but still * try. */ diff --git a/lib/privs.h b/lib/privs.h index 1fee423a95..01ddba4622 100644 --- a/lib/privs.h +++ b/lib/privs.h @@ -23,6 +23,8 @@ #ifndef _ZEBRA_PRIVS_H #define _ZEBRA_PRIVS_H +#include <pthread.h> + #ifdef __cplusplus extern "C" { #endif @@ -59,6 +61,14 @@ struct zebra_privs_t { zebra_capabilities_t *caps_i; /* caps to allow inheritance of */ int cap_num_p; /* number of caps in arrays */ int cap_num_i; + + /* Mutex and counter used to avoid race conditions in multi-threaded + * processes. The privs elevation is process-wide, so we need to + * avoid changing the privilege status across threads. + */ + pthread_mutex_t mutex; + uint32_t refcount; + const char *user; /* user and group to run as */ const char *group; const char *vty_group; /* group to chown vty socket to */ diff --git a/lib/routemap.c b/lib/routemap.c index 7c1ee2353c..4898a8d0fa 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -538,10 +538,8 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index, break; } - if (dep_name) - XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); - if (rmap_name) - XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); + XFREE(MTYPE_ROUTE_MAP_RULE, dep_name); + XFREE(MTYPE_ROUTE_MAP_NAME, rmap_name); return retval; } @@ -1075,8 +1073,7 @@ static void route_map_index_delete(struct route_map_index *index, int notify) index->map->head = index->next; /* Free 'char *nextrm' if not NULL */ - if (index->nextrm) - XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm); + XFREE(MTYPE_ROUTE_MAP_NAME, index->nextrm); /* Execute event hook. */ if (route_map_master.event_hook && notify) { @@ -1231,8 +1228,7 @@ static void route_map_rule_delete(struct route_map_rule_list *list, if (rule->cmd->func_free) (*rule->cmd->func_free)(rule->value); - if (rule->rule_str) - XFREE(MTYPE_ROUTE_MAP_RULE_STR, rule->rule_str); + XFREE(MTYPE_ROUTE_MAP_RULE_STR, rule->rule_str); if (rule->next) rule->next->prev = rule->prev; @@ -1779,8 +1775,7 @@ static int route_map_dep_update(struct hash *dephash, const char *dep_name, } ret_map_name = (char *)hash_release(dep->dep_rmap_hash, rname); - if (ret_map_name) - XFREE(MTYPE_ROUTE_MAP_NAME, ret_map_name); + XFREE(MTYPE_ROUTE_MAP_NAME, ret_map_name); if (!dep->dep_rmap_hash->count) { dep = hash_release(dephash, dname); diff --git a/lib/thread.c b/lib/thread.c index 055587434c..19ab409439 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -414,8 +414,6 @@ struct thread_master *thread_master_create(const char *name) pthread_once(&init_once, &initializer); rv = XCALLOC(MTYPE_THREAD_MASTER, sizeof(struct thread_master)); - if (rv == NULL) - return NULL; /* Initialize master mutex */ pthread_mutex_init(&rv->mtx, NULL); @@ -484,8 +482,7 @@ void thread_master_set_name(struct thread_master *master, const char *name) { pthread_mutex_lock(&master->mtx); { - if (master->name) - XFREE(MTYPE_THREAD_MASTER, master->name); + XFREE(MTYPE_THREAD_MASTER, master->name); master->name = XSTRDUP(MTYPE_THREAD_MASTER, name); } pthread_mutex_unlock(&master->mtx); @@ -649,8 +646,7 @@ void thread_master_free(struct thread_master *m) hash_free(m->cpu_record); m->cpu_record = NULL; - if (m->name) - XFREE(MTYPE_THREAD_MASTER, m->name); + XFREE(MTYPE_THREAD_MASTER, m->name); XFREE(MTYPE_THREAD_MASTER, m->handler.pfds); XFREE(MTYPE_THREAD_MASTER, m->handler.copy); XFREE(MTYPE_THREAD_MASTER, m); @@ -974,8 +974,7 @@ static void vty_complete_command(struct vty *vty) default: break; } - if (matched) - XFREE(MTYPE_TMP, matched); + XFREE(MTYPE_TMP, matched); } static void vty_describe_fold(struct vty *vty, int cmd_width, @@ -1169,8 +1168,7 @@ static void vty_hist_add(struct vty *vty) } /* Insert history entry. */ - if (vty->hist[vty->hindex]) - XFREE(MTYPE_VTY_HIST, vty->hist[vty->hindex]); + XFREE(MTYPE_VTY_HIST, vty->hist[vty->hindex]); vty->hist[vty->hindex] = XSTRDUP(MTYPE_VTY_HIST, vty->buf); /* History index rotation. */ @@ -2232,9 +2230,9 @@ void vty_close(struct vty *vty) buffer_free(vty->lbuf); /* Free command history. */ - for (i = 0; i < VTY_MAXHIST; i++) - if (vty->hist[i]) - XFREE(MTYPE_VTY_HIST, vty->hist[i]); + for (i = 0; i < VTY_MAXHIST; i++) { + XFREE(MTYPE_VTY_HIST, vty->hist[i]); + } /* Unset vector. */ if (vty->fd != -1) @@ -2255,8 +2253,7 @@ void vty_close(struct vty *vty) if (vty->fd == STDIN_FILENO) was_stdio = true; - if (vty->buf) - XFREE(MTYPE_VTY, vty->buf); + XFREE(MTYPE_VTY, vty->buf); if (vty->error) { vty->error->del = vty_error_delete; @@ -2546,8 +2543,7 @@ bool vty_read_config(struct nb_config *config, const char *config_file, host_config_set(fullpath); tmp_free_and_out: - if (tmp) - XFREE(MTYPE_TMP, tmp); + XFREE(MTYPE_TMP, tmp); return read_success; } @@ -3163,8 +3159,7 @@ void vty_init(struct thread_master *master_thread) void vty_terminate(void) { - if (vty_cwd) - XFREE(MTYPE_TMP, vty_cwd); + XFREE(MTYPE_TMP, vty_cwd); if (vtyvec && Vvty_serv_thread) { vty_reset(); diff --git a/lib/workqueue.c b/lib/workqueue.c index fa69ec600e..066d81f350 100644 --- a/lib/workqueue.c +++ b/lib/workqueue.c @@ -274,7 +274,7 @@ int work_queue_run(struct thread *thread) wq->cycles.granularity = WORK_QUEUE_MIN_GRANULARITY; STAILQ_FOREACH_SAFE (item, &wq->items, wq, titem) { - assert(item && item->data); + assert(item->data); /* dont run items which are past their allowed retries */ if (item->ran > wq->spec.max_retries) { diff --git a/lib/yang_translator.c b/lib/yang_translator.c index 6d6f92836f..76a6cc5fd1 100644 --- a/lib/yang_translator.c +++ b/lib/yang_translator.c @@ -511,7 +511,7 @@ static void str_replace(char *o_string, const char *s_string, if (!ch) return; - strncpy(buffer, o_string, ch - o_string); + memcpy(buffer, o_string, ch - o_string); buffer[ch - o_string] = 0; sprintf(buffer + (ch - o_string), "%s%s", r_string, diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c index 6273dff3ce..7ecea5f445 100644 --- a/lib/yang_wrappers.c +++ b/lib/yang_wrappers.c @@ -62,7 +62,7 @@ bool yang_str2bool(const char *value) struct yang_data *yang_data_new_bool(const char *xpath, bool value) { - return yang_data_new(xpath, (value == true) ? "true" : "false"); + return yang_data_new(xpath, (value) ? "true" : "false"); } bool yang_dnode_get_bool(const struct lyd_node *dnode, const char *xpath_fmt, |
