diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/bfd.c | 12 | ||||
| -rw-r--r-- | lib/buffer.c | 3 | ||||
| -rw-r--r-- | lib/ferr.c | 4 | ||||
| -rw-r--r-- | lib/filter_nb.c | 3 | ||||
| -rw-r--r-- | lib/id_alloc.c | 11 | ||||
| -rw-r--r-- | lib/if.c | 3 | ||||
| -rw-r--r-- | lib/log.c | 9 | ||||
| -rw-r--r-- | lib/log.h | 6 | ||||
| -rw-r--r-- | lib/memory.c | 3 | ||||
| -rw-r--r-- | lib/privs.c | 3 | ||||
| -rw-r--r-- | lib/routemap.c | 12 | ||||
| -rw-r--r-- | lib/routing_nb.c | 40 | ||||
| -rw-r--r-- | lib/routing_nb.h | 24 | ||||
| -rw-r--r-- | lib/routing_nb_config.c | 74 | ||||
| -rw-r--r-- | lib/sockopt.c | 6 | ||||
| -rw-r--r-- | lib/sockunion.c | 3 | ||||
| -rw-r--r-- | lib/srcdest_table.c | 10 | ||||
| -rw-r--r-- | lib/srcdest_table.h | 2 | ||||
| -rw-r--r-- | lib/stream.c | 14 | ||||
| -rw-r--r-- | lib/subdir.am | 4 | ||||
| -rw-r--r-- | lib/thread.c | 6 | ||||
| -rw-r--r-- | lib/vrf.c | 3 | ||||
| -rw-r--r-- | lib/vty.c | 6 | ||||
| -rw-r--r-- | lib/yang.c | 144 | ||||
| -rw-r--r-- | lib/yang.h | 53 | ||||
| -rw-r--r-- | lib/yang_wrappers.c | 35 | ||||
| -rw-r--r-- | lib/yang_wrappers.h | 3 | ||||
| -rw-r--r-- | lib/zclient.c | 3 |
28 files changed, 431 insertions, 68 deletions
@@ -143,8 +143,7 @@ void bfd_peer_sendmsg(struct zclient *zclient, struct bfd_info *bfd_info, if (!zclient || zclient->sock < 0) { if (bfd_debug) zlog_debug( - "%s: Can't send BFD peer register, Zebra client not " - "established", + "%s: Can't send BFD peer register, Zebra client not established", __func__); return; } @@ -217,8 +216,7 @@ struct interface *bfd_get_peer_info(struct stream *s, struct prefix *dp, if (ifp == NULL) { if (bfd_debug) zlog_debug( - "zebra_interface_bfd_read: " - "Can't find interface by ifindex: %d ", + "zebra_interface_bfd_read: Can't find interface by ifindex: %d ", ifindex); return NULL; } @@ -320,8 +318,7 @@ void bfd_show_param(struct vty *vty, struct bfd_info *bfd_info, int bfd_tag, json_bfd); } else { vty_out(vty, - " %s%sDetect Multiplier: %d, Min Rx interval: %d," - " Min Tx interval: %d\n", + " %s%sDetect Multiplier: %d, Min Rx interval: %d, Min Tx interval: %d\n", (extra_space) ? " " : "", (bfd_tag) ? "BFD: " : " ", bfd_info->detect_mult, bfd_info->required_min_rx, bfd_info->desired_min_tx); @@ -397,8 +394,7 @@ void bfd_client_sendmsg(struct zclient *zclient, int command, if (!zclient || zclient->sock < 0) { if (bfd_debug) zlog_debug( - "%s: Can't send BFD client register, Zebra client not " - "established", + "%s: Can't send BFD client register, Zebra client not established", __func__); return; } diff --git a/lib/buffer.c b/lib/buffer.c index ff49bc83df..459d98e75d 100644 --- a/lib/buffer.c +++ b/lib/buffer.c @@ -327,8 +327,7 @@ buffer_status_t buffer_flush_window(struct buffer *b, int fd, int width, /* This should absolutely never occur. */ flog_err_sys( EC_LIB_SYSTEM_CALL, - "%s: corruption detected: iov_small overflowed; " - "head %p, tail %p, head->next %p", + "%s: corruption detected: iov_small overflowed; head %p, tail %p, head->next %p", __func__, (void *)b->head, (void *)b->tail, (void *)b->head->next); iov = XMALLOC(MTYPE_TMP, diff --git a/lib/ferr.c b/lib/ferr.c index ccf63dea17..7b923da177 100644 --- a/lib/ferr.c +++ b/lib/ferr.c @@ -130,7 +130,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json) if (json) { char key[11]; - snprintf(key, sizeof(key), "%"PRIu32, ref->code); + snprintf(key, sizeof(key), "%u", ref->code); obj = json_object_new_object(); json_object_string_add(obj, "title", ref->title); json_object_string_add(obj, "description", @@ -142,7 +142,7 @@ void log_ref_display(struct vty *vty, uint32_t code, bool json) char pbuf[256]; char ubuf[256]; - snprintf(pbuf, sizeof(pbuf), "\nError %"PRIu32" - %s", + snprintf(pbuf, sizeof(pbuf), "\nError %u - %s", ref->code, ref->title); memset(ubuf, '=', strlen(pbuf)); ubuf[strlen(pbuf)] = '\0'; diff --git a/lib/filter_nb.c b/lib/filter_nb.c index 83cf586ed3..d3d868b468 100644 --- a/lib/filter_nb.c +++ b/lib/filter_nb.c @@ -93,8 +93,7 @@ prefix_list_length_validate(const struct lyd_node *dnode) return NB_OK; log_and_fail: - zlog_info("prefix-list: invalid prefix range for %pFX: " - "Make sure that mask length < ge <= le", &p); + zlog_info("prefix-list: invalid prefix range for %pFX: Make sure that mask length < ge <= le", &p); return NB_ERR_VALIDATION; } diff --git a/lib/id_alloc.c b/lib/id_alloc.c index 7c7f2c4689..95096fa5f0 100644 --- a/lib/id_alloc.c +++ b/lib/id_alloc.c @@ -108,7 +108,7 @@ static struct id_alloc_page *find_or_create_page(struct id_alloc *alloc, } else if (page != NULL && create) { flog_err( EC_LIB_ID_CONSISTENCY, - "ID Allocator %s attempt to re-create page at %" PRIu32, + "ID Allocator %s attempt to re-create page at %u", alloc->name, id); } @@ -131,8 +131,7 @@ void idalloc_free(struct id_alloc *alloc, uint32_t id) page = find_or_create_page(alloc, id, 0); if (!page) { flog_err(EC_LIB_ID_CONSISTENCY, - "ID Allocator %s cannot free #%" PRIu32 - ". ID Block does not exist.", + "ID Allocator %s cannot free #%u. ID Block does not exist.", alloc->name, id); return; } @@ -142,8 +141,7 @@ void idalloc_free(struct id_alloc *alloc, uint32_t id) if ((page->allocated_mask[word] & (1 << offset)) == 0) { flog_err(EC_LIB_ID_CONSISTENCY, - "ID Allocator %s cannot free #%" PRIu32 - ". ID was not allocated at the time of free.", + "ID Allocator %s cannot free #%u. ID was not allocated at the time of free.", alloc->name, id); return; } @@ -285,8 +283,7 @@ uint32_t idalloc_reserve(struct id_alloc *alloc, uint32_t id) if (page->allocated_mask[word] & (((uint32_t)1) << offset)) { flog_err(EC_LIB_ID_CONSISTENCY, - "ID Allocator %s could not reserve %" PRIu32 - " because it is already allocated.", + "ID Allocator %s could not reserve %u because it is already allocated.", alloc->name, id); return IDALLOC_INVALID; } @@ -785,8 +785,7 @@ static void if_dump(const struct interface *ifp) struct vrf *vrf = vrf_lookup_by_id(ifp->vrf_id); zlog_info( - "Interface %s vrf %s(%u) index %d metric %d mtu %d " - "mtu6 %d %s", + "Interface %s vrf %s(%u) index %d metric %d mtu %d mtu6 %d %s", ifp->name, VRF_LOGNAME(vrf), ifp->vrf_id, ifp->ifindex, ifp->metric, ifp->mtu, ifp->mtu6, if_flag_dump(ifp->flags)); @@ -273,8 +273,7 @@ void zlog_backtrace(int priority) if (size <= 0 || (size_t)size > array_size(array)) { flog_err_sys( EC_LIB_SYSTEM_CALL, - "Cannot get backtrace, returned invalid # of frames %d " - "(valid range is between 1 and %lu)", + "Cannot get backtrace, returned invalid # of frames %d (valid range is between 1 and %lu)", size, (unsigned long)(array_size(array))); return; } @@ -301,8 +300,7 @@ void zlog_thread_info(int log_level) if (tc) zlog(log_level, - "Current thread function %s, scheduled from " - "file %s, line %u", + "Current thread function %s, scheduled from file %s, line %u", tc->funcname, tc->schedfrom, tc->schedfrom_line); else zlog(log_level, "Current thread not known/applicable"); @@ -465,8 +463,7 @@ static const struct zebra_desc_table *zroute_lookup(unsigned int zroute) for (i = 0; i < array_size(route_types); i++) { if (zroute == route_types[i].type) { zlog_warn( - "internal error: route type table out of order " - "while searching for %u, please notify developers", + "internal error: route type table out of order while searching for %u, please notify developers", zroute); return &route_types[i]; } @@ -64,13 +64,13 @@ struct message { /* For logs which have error codes associated with them */ #define flog_err(ferr_id, format, ...) \ - zlog_err("[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__) + zlog_err("[EC %u] " 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__) + zlog_warn("[EC %u] " format, ferr_id, ##__VA_ARGS__) #define flog(priority, ferr_id, format, ...) \ - zlog(priority, "[EC %" PRIu32 "] " format, ferr_id, ##__VA_ARGS__) + zlog(priority, "[EC %u] " format, ferr_id, ##__VA_ARGS__) extern void zlog_thread_info(int log_level); diff --git a/lib/memory.c b/lib/memory.c index 3a29404827..2c902d123b 100644 --- a/lib/memory.c +++ b/lib/memory.c @@ -157,8 +157,7 @@ static int qmem_exit_walker(void *arg, struct memgroup *mg, struct memtype *mt) if (!mt) { fprintf(eda->fp, - "%s: showing active allocations in " - "memory group %s\n", + "%s: showing active allocations in memory group %s\n", eda->prefix, mg->name); } else if (mt->n_alloc) { diff --git a/lib/privs.c b/lib/privs.c index eb0dbe0783..5c7e1240e2 100644 --- a/lib/privs.c +++ b/lib/privs.c @@ -558,8 +558,7 @@ static void zprivs_caps_init(struct zebra_privs_t *zprivs) /* nonsensical to have gotten here but not have capabilities */ if (!zprivs_state.syscaps_p) { fprintf(stderr, - "%s: capabilities enabled, " - "but no valid capabilities supplied\n", + "%s: capabilities enabled, but no valid capabilities supplied\n", __func__); } diff --git a/lib/routemap.c b/lib/routemap.c index 1415a9e2e9..22b4beb79d 100644 --- a/lib/routemap.c +++ b/lib/routemap.c @@ -353,8 +353,7 @@ int generic_match_add(struct vty *vty, struct route_map_index *index, "%% [%s] Argument form is unsupported or malformed.\n", frr_protonameinst); else - zlog_warn("Argument form is unsupported or malformed: " - "%s %s", command, arg); + zlog_warn("Argument form is unsupported or malformed: %s %s", command, arg); return CMD_WARNING_CONFIG_FAILED; case RMAP_COMPILE_SUCCESS: /* @@ -405,8 +404,7 @@ int generic_match_delete(struct vty *vty, struct route_map_index *index, "%% [%s] Argument form is unsupported or malformed.\n", frr_protonameinst); else - zlog_warn("Argument form is unsupported or malformed: " - "%s %s", command, arg); + zlog_warn("Argument form is unsupported or malformed: %s %s", command, arg); retval = CMD_WARNING_CONFIG_FAILED; break; case RMAP_COMPILE_SUCCESS: @@ -441,8 +439,7 @@ int generic_set_add(struct vty *vty, struct route_map_index *index, "%% [%s] Argument form is unsupported or malformed.\n", frr_protonameinst); else - zlog_warn("Argument form is unsupported or malformed: " - "%s %s", command, arg); + zlog_warn("Argument form is unsupported or malformed: %s %s", command, arg); return CMD_WARNING_CONFIG_FAILED; case RMAP_COMPILE_SUCCESS: break; @@ -470,8 +467,7 @@ int generic_set_delete(struct vty *vty, struct route_map_index *index, "%% [%s] Argument form is unsupported or malformed.\n", frr_protonameinst); else - zlog_warn("Argument form is unsupported or malformed: " - "%s %s", command, arg); + zlog_warn("Argument form is unsupported or malformed: %s %s", command, arg); return CMD_WARNING_CONFIG_FAILED; case RMAP_COMPILE_SUCCESS: break; diff --git a/lib/routing_nb.c b/lib/routing_nb.c new file mode 100644 index 0000000000..0160354a7e --- /dev/null +++ b/lib/routing_nb.c @@ -0,0 +1,40 @@ +/* + * Copyright (C) 2018 Vmware + * Vishal Dhingra + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ +#include "northbound.h" +#include "libfrr.h" +#include "routing_nb.h" + + + +/* clang-format off */ +const struct frr_yang_module_info frr_routing_info = { + .name = "frr-routing", + .nodes = { + { + .xpath = "/frr-routing:routing/control-plane-protocols/control-plane-protocol", + .cbs = { + .create = routing_control_plane_protocols_control_plane_protocol_create, + .destroy = routing_control_plane_protocols_control_plane_protocol_destroy, + } + }, + { + .xpath = NULL, + }, + } +}; diff --git a/lib/routing_nb.h b/lib/routing_nb.h new file mode 100644 index 0000000000..d1b59ea29e --- /dev/null +++ b/lib/routing_nb.h @@ -0,0 +1,24 @@ +#ifndef _FRR_ROUTING_NB_H_ +#define _FRR_ROUTING_NB_H_ + +extern const struct frr_yang_module_info frr_routing_info; + +/* Mandatory callbacks. */ +int routing_control_plane_protocols_control_plane_protocol_create( + struct nb_cb_create_args *args); +int routing_control_plane_protocols_control_plane_protocol_destroy( + struct nb_cb_destroy_args *args); + +#define FRR_ROUTING_XPATH \ + "/frr-routing:routing/control-plane-protocols/control-plane-protocol" + +#define FRR_ROUTING_KEY_XPATH \ + "/frr-routing:routing/control-plane-protocols/" \ + "control-plane-protocol[type='%s'][name='%s'][vrf='%s']" +/* + * callbacks for routing to handle configuration events + * based on the control plane protocol + */ +DECLARE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args)) + +#endif /* _FRR_ROUTING_NB_H_ */ diff --git a/lib/routing_nb_config.c b/lib/routing_nb_config.c new file mode 100644 index 0000000000..b789e8494e --- /dev/null +++ b/lib/routing_nb_config.c @@ -0,0 +1,74 @@ +/* + * Copyright (C) 2018 Vmware + * Vishal Dhingra + * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the Free + * Software Foundation; either version 2 of the License, or (at your option) + * any later version. + * + * This program is distributed in the hope that it will be useful, but WITHOUT + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for + * more details. + * + * You should have received a copy of the GNU General Public License along + * with this program; see the file COPYING; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + */ + +#include "northbound.h" +#include "libfrr.h" +#include "vrf.h" +#include "lib_errors.h" +#include "routing_nb.h" + + +DEFINE_HOOK(routing_conf_event, (struct nb_cb_create_args *args), (args)) + +/* + * XPath: /frr-routing:routing/control-plane-protocols/control-plane-protocol + */ + +int routing_control_plane_protocols_control_plane_protocol_create( + struct nb_cb_create_args *args) +{ + struct vrf *vrf; + const char *vrfname; + + switch (args->event) { + case NB_EV_VALIDATE: + if (hook_call(routing_conf_event, args)) + return NB_ERR_VALIDATION; + break; + case NB_EV_PREPARE: + case NB_EV_ABORT: + break; + case NB_EV_APPLY: + vrfname = yang_dnode_get_string(args->dnode, "./vrf"); + vrf = vrf_lookup_by_name(vrfname); + vrf = vrf ? vrf : vrf_get(VRF_UNKNOWN, vrfname); + if (!vrf) { + flog_warn(EC_LIB_NB_CB_CONFIG_APPLY, + "vrf creation %s failed", vrfname); + return NB_ERR; + } + nb_running_set_entry(args->dnode, vrf); + break; + }; + + return NB_OK; +} + +int routing_control_plane_protocols_control_plane_protocol_destroy( + struct nb_cb_destroy_args *args) +{ + struct vrf *vrf __attribute__((unused)); + + if (args->event != NB_EV_APPLY) + return NB_OK; + + vrf = nb_running_unset_entry(args->dnode); + + return NB_OK; +} diff --git a/lib/sockopt.c b/lib/sockopt.c index 45d9008796..21fddcd01d 100644 --- a/lib/sockopt.c +++ b/lib/sockopt.c @@ -264,8 +264,7 @@ int setsockopt_ipv4_multicast(int sock, int optname, struct in_addr if_addr, * up */ char buf[1][INET_ADDRSTRLEN]; zlog_info( - "setsockopt_ipv4_multicast attempting to drop and " - "re-add (fd %d, mcast %s, ifindex %u)", + "setsockopt_ipv4_multicast attempting to drop and re-add (fd %d, mcast %s, ifindex %u)", sock, inet_ntop(AF_INET, &mreqn.imr_multiaddr, buf[0], sizeof(buf[0])), ifindex); @@ -306,8 +305,7 @@ int setsockopt_ipv4_multicast(int sock, int optname, struct in_addr if_addr, * up */ char buf[1][INET_ADDRSTRLEN]; zlog_info( - "setsockopt_ipv4_multicast attempting to drop and " - "re-add (fd %d, mcast %s, ifindex %u)", + "setsockopt_ipv4_multicast attempting to drop and re-add (fd %d, mcast %s, ifindex %u)", sock, inet_ntop(AF_INET, &mreq.imr_multiaddr, buf[0], sizeof(buf[0])), ifindex); diff --git a/lib/sockunion.c b/lib/sockunion.c index 63d8a8c69b..0e7483bfbe 100644 --- a/lib/sockunion.c +++ b/lib/sockunion.c @@ -406,8 +406,7 @@ int sockopt_v6only(int family, int sock) sizeof(int)); if (ret < 0) { flog_err(EC_LIB_SOCKET, - "can't set sockopt IPV6_V6ONLY " - "to socket %d", + "can't set sockopt IPV6_V6ONLY to socket %d", sock); return -1; } diff --git a/lib/srcdest_table.c b/lib/srcdest_table.c index 66b735919b..8ffa0e9709 100644 --- a/lib/srcdest_table.c +++ b/lib/srcdest_table.c @@ -317,3 +317,13 @@ static ssize_t printfrr_rn(char *buf, size_t bsz, const char *fmt, srcdest2str(dst_p, (const struct prefix_ipv6 *)src_p, buf, bsz); return 2; } + +struct route_table *srcdest_srcnode_table(struct route_node *rn) +{ + if (rnode_is_dstnode(rn)) { + struct srcdest_rnode *srn = srcdest_rnode_from_rnode(rn); + + return srn->src_table; + } + return NULL; +} diff --git a/lib/srcdest_table.h b/lib/srcdest_table.h index 7982260777..79afef9bb0 100644 --- a/lib/srcdest_table.h +++ b/lib/srcdest_table.h @@ -100,6 +100,8 @@ static inline void *srcdest_rnode_table_info(struct route_node *rn) return route_table_get_info(srcdest_rnode_table(rn)); } +extern struct route_table *srcdest_srcnode_table(struct route_node *rn); + #ifdef __cplusplus } #endif diff --git a/lib/stream.c b/lib/stream.c index 17520f978e..d3afebbf13 100644 --- a/lib/stream.c +++ b/lib/stream.c @@ -55,15 +55,19 @@ DEFINE_MTYPE_STATIC(LIB, STREAM_FIFO, "Stream FIFO") * using stream_put..._at() functions. */ #define STREAM_WARN_OFFSETS(S) \ - 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) + do { \ + 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); \ + zlog_backtrace(LOG_WARNING); \ + } while (0) #define STREAM_VERIFY_SANE(S) \ do { \ - if (!(GETP_VALID(S, (S)->getp) && ENDP_VALID(S, (S)->endp))) \ + if (!(GETP_VALID(S, (S)->getp) && ENDP_VALID(S, (S)->endp))) { \ STREAM_WARN_OFFSETS(S); \ + } \ assert(GETP_VALID(S, (S)->getp)); \ assert(ENDP_VALID(S, (S)->endp)); \ } while (0) diff --git a/lib/subdir.am b/lib/subdir.am index 57b2cea832..f185841c76 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -108,6 +108,8 @@ lib_libfrr_la_SOURCES = \ lib/printf/printf-pos.c \ lib/printf/vfprintf.c \ lib/printf/glue.c \ + lib/routing_nb.c \ + lib/routing_nb_config.c \ # end nodist_lib_libfrr_la_SOURCES = \ @@ -117,6 +119,7 @@ nodist_lib_libfrr_la_SOURCES = \ yang/frr-route-types.yang.c \ yang/frr-vrf.yang.c \ yang/frr-routing.yang.c \ + yang/frr-nexthop.yang.c \ yang/ietf/ietf-routing-types.yang.c \ yang/ietf/ietf-interfaces.yang.c \ yang/frr-module-translator.yang.c \ @@ -266,6 +269,7 @@ pkginclude_HEADERS += \ lib/zlog.h \ lib/zlog_targets.h \ lib/pbr.h \ + lib/routing_nb.h \ # end diff --git a/lib/thread.c b/lib/thread.c index 9b2f5661ac..5c7c104842 100644 --- a/lib/thread.c +++ b/lib/thread.c @@ -305,8 +305,7 @@ DEFUN (show_thread_cpu, filter = parse_filter(argv[idx]->arg); if (!filter) { vty_out(vty, - "Invalid filter \"%s\" specified; must contain at least" - "one of 'RWTEXB'\n", + "Invalid filter \"%s\" specified; must contain at leastone of 'RWTEXB'\n", argv[idx]->arg); return CMD_WARNING; } @@ -393,8 +392,7 @@ DEFUN (clear_thread_cpu, filter = parse_filter(argv[idx]->arg); if (!filter) { vty_out(vty, - "Invalid filter \"%s\" specified; must contain at least" - "one of 'RWTEXB'\n", + "Invalid filter \"%s\" specified; must contain at leastone of 'RWTEXB'\n", argv[idx]->arg); return CMD_WARNING; } @@ -691,8 +691,7 @@ int vrf_netns_handler_create(struct vty *vty, struct vrf *vrf, char *pathname, return CMD_SUCCESS; if (vty) vty_out(vty, - "NS %s is already configured" - " with VRF %u(%s)\n", + "NS %s is already configured with VRF %u(%s)\n", ns->name, vrf2->vrf_id, vrf2->name); else zlog_info("NS %s is already configured with VRF %u(%s)", @@ -1244,8 +1244,7 @@ static int vty_telnet_option(struct vty *vty, unsigned char *buf, int nbytes) if (vty->sb_len != TELNET_NAWS_SB_LEN) flog_err( EC_LIB_SYSTEM_CALL, - "RFC 1073 violation detected: telnet NAWS option " - "should send %d characters, but we received %lu", + "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) @@ -1261,8 +1260,7 @@ static int vty_telnet_option(struct vty *vty, unsigned char *buf, int nbytes) | vty->sb_buf[4]); #ifdef TELNET_OPTION_DEBUG vty_out(vty, - "TELNET NAWS window size negotiation completed: " - "width %d, height %d\n", + "TELNET NAWS window size negotiation completed: width %d, height %d\n", vty->width, vty->height); #endif } diff --git a/lib/yang.c b/lib/yang.c index 0714ddf7bb..db99c0339e 100644 --- a/lib/yang.c +++ b/lib/yang.c @@ -749,3 +749,147 @@ void yang_terminate(void) ly_ctx_destroy(ly_native_ctx, NULL); } + +const struct lyd_node *yang_dnode_get_parent(const struct lyd_node *dnode, + const char *name) +{ + const struct lyd_node *orig_dnode = dnode; + + while (orig_dnode) { + switch (orig_dnode->schema->nodetype) { + case LYS_LIST: + case LYS_CONTAINER: + if (!strcmp(orig_dnode->schema->name, name)) + return orig_dnode; + break; + default: + break; + } + + orig_dnode = orig_dnode->parent; + } + + return NULL; +} + +/* API to check if the given node is last node in the list */ +static bool yang_is_last_list_dnode(const struct lyd_node *dnode) +{ + return (((dnode->next == NULL) + || (dnode->next + && (strcmp(dnode->next->schema->name, dnode->schema->name) + != 0))) + && dnode->prev + && ((dnode->prev == dnode) + || (strcmp(dnode->prev->schema->name, dnode->schema->name) + != 0))); +} + +/* API to check if the given node is last node in the data tree level */ +static bool yang_is_last_level_dnode(const struct lyd_node *dnode) +{ + const struct lyd_node *parent; + const struct lys_node_list *snode; + const struct lyd_node *key_leaf; + uint8_t keys_size; + + switch (dnode->schema->nodetype) { + case LYS_LIST: + assert(dnode->parent); + parent = dnode->parent; + snode = (struct lys_node_list *)parent->schema; + key_leaf = dnode->prev; + for (keys_size = 1; keys_size < snode->keys_size; keys_size++) + key_leaf = key_leaf->prev; + if (key_leaf->prev == dnode) + return true; + break; + case LYS_CONTAINER: + return true; + default: + break; + } + + return false; +} + + +const struct lyd_node * +yang_get_subtree_with_no_sibling(const struct lyd_node *dnode) +{ + bool parent = true; + const struct lyd_node *node; + const struct lys_node_container *snode; + + node = dnode; + if (node->schema->nodetype != LYS_LIST) + return node; + + while (parent) { + switch (node->schema->nodetype) { + case LYS_CONTAINER: + snode = (struct lys_node_container *)node->schema; + if ((!snode->presence) + && yang_is_last_level_dnode(node)) { + if (node->parent + && (node->parent->schema->module + == dnode->schema->module)) + node = node->parent; + else + parent = false; + } else + parent = false; + break; + case LYS_LIST: + if (yang_is_last_list_dnode(node) + && yang_is_last_level_dnode(node)) { + if (node->parent + && (node->parent->schema->module + == dnode->schema->module)) + node = node->parent; + else + parent = false; + } else + parent = false; + break; + default: + parent = false; + break; + } + } + return node; +} + +uint32_t yang_get_list_pos(const struct lyd_node *node) +{ + return lyd_list_pos(node); +} + +uint32_t yang_get_list_elements_count(const struct lyd_node *node) +{ + unsigned int count; + struct lys_node *schema; + + if (!node + || ((node->schema->nodetype != LYS_LIST) + && (node->schema->nodetype != LYS_LEAFLIST))) { + return 0; + } + + schema = node->schema; + count = 0; + do { + if (node->schema == schema) + ++count; + node = node->next; + } while (node); + return count; +} + + +const struct lyd_node *yang_dnode_get_child(const struct lyd_node *dnode) +{ + if (dnode) + return dnode->child; + return NULL; +} diff --git a/lib/yang.h b/lib/yang.h index 85ef0d758c..d526d2f5d6 100644 --- a/lib/yang.h +++ b/lib/yang.h @@ -34,7 +34,7 @@ extern "C" { #endif /* Maximum XPath length. */ -#define XPATH_MAXLEN 512 +#define XPATH_MAXLEN 1024 /* Maximum list key length. */ #define LIST_MAXKEYS 8 @@ -551,6 +551,57 @@ extern void yang_init(bool embedded_modules); */ extern void yang_terminate(void); +/* + * API to return the parent dnode having a given schema-node name + * Use case: One has to access the parent dnode's private pointer + * for a given child node. + * For that there is a need to find parent dnode first. + * + * dnode The starting node to work on + * + * name The name of container/list schema-node + * + * Returns The dnode matched with the given name + */ +extern const struct lyd_node * +yang_dnode_get_parent(const struct lyd_node *dnode, const char *name); + + +/* + * In some cases there is a need to auto delete the parent nodes + * if the given node is last in the list. + * It tries to delete all the parents in a given tree in a given module. + * The use case is with static routes and route maps + * example : ip route 1.1.1.1/32 ens33 + * ip route 1.1.1.1/32 ens34 + * After this no ip route 1.1.1.1/32 ens34 came, now staticd + * has to find out upto which level it has to delete the dnodes. + * For this case it has to send delete nexthop + * After this no ip route 1.1.1.1/32 ens33 came, now staticd has to + * clear nexthop, path and route nodes. + * The same scheme is required for routemaps also + * dnode The starting node to work on + * + * Returns The final parent node selected for deletion + */ +extern const struct lyd_node * +yang_get_subtree_with_no_sibling(const struct lyd_node *dnode); + +/* To get the relative position of a node in list */ +extern uint32_t yang_get_list_pos(const struct lyd_node *node); + +/* To get the number of elements in a list + * + * dnode : The head of list + * Returns : The number of dnodes present in the list + */ +extern uint32_t yang_get_list_elements_count(const struct lyd_node *node); + + +/* To get the immediate child of a dnode */ +const struct lyd_node *yang_dnode_get_child(const struct lyd_node *dnode); + + #ifdef __cplusplus } #endif diff --git a/lib/yang_wrappers.c b/lib/yang_wrappers.c index c31ba3fcc0..8b0e89d52e 100644 --- a/lib/yang_wrappers.c +++ b/lib/yang_wrappers.c @@ -1191,3 +1191,38 @@ const char *yang_nexthop_type2str(uint32_t ntype) break; } } + + +const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi) +{ + if (afi == AFI_IP && safi == SAFI_UNICAST) + return "frr-routing:ipv4-unicast"; + if (afi == AFI_IP6 && safi == SAFI_UNICAST) + return "frr-routing:ipv6-unicast"; + if (afi == AFI_IP && safi == SAFI_MULTICAST) + return "frr-routing:ipv4-multicast"; + if (afi == AFI_IP6 && safi == SAFI_MULTICAST) + return "frr-routing:ipv6-multicast"; + + return NULL; +} + +void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi) +{ + if (strmatch(key, "frr-routing:ipv4-unicast")) { + *afi = AFI_IP; + *safi = SAFI_UNICAST; + } else if (strmatch(key, "frr-routing:ipv6-unicast")) { + *afi = AFI_IP6; + *safi = SAFI_UNICAST; + } else if (strmatch(key, "frr-routing:ipv4-multicast")) { + *afi = AFI_IP; + *safi = SAFI_MULTICAST; + } else if (strmatch(key, "frr-routing:ipv6-multicast")) { + *afi = AFI_IP6; + *safi = SAFI_MULTICAST; + } else { + *afi = AFI_UNSPEC; + *safi = SAFI_UNSPEC; + } +} diff --git a/lib/yang_wrappers.h b/lib/yang_wrappers.h index ba2cf5139c..335ff319d5 100644 --- a/lib/yang_wrappers.h +++ b/lib/yang_wrappers.h @@ -191,6 +191,9 @@ extern struct yang_data *yang_data_new_date_and_time(const char *xpath, /* nexthop enum2str */ extern const char *yang_nexthop_type2str(uint32_t ntype); +const char *yang_afi_safi_value2identity(afi_t afi, safi_t safi); +void yang_afi_safi_identity2value(const char *key, afi_t *afi, safi_t *safi); + #ifdef __cplusplus } #endif diff --git a/lib/zclient.c b/lib/zclient.c index 793864243c..d8f311fcec 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1924,8 +1924,7 @@ static int link_params_set_value(struct stream *s, struct if_link_params *iflp) if (i < bwclassnum) flog_err( EC_LIB_ZAPI_MISSMATCH, - "%s: received %d > %d (MAX_CLASS_TYPE) bw entries" - " - outdated library?", + "%s: received %d > %d (MAX_CLASS_TYPE) bw entries - outdated library?", __func__, bwclassnum, MAX_CLASS_TYPE); } STREAM_GETL(s, iflp->admin_grp); |
