diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/command_match.c | 2 | ||||
| -rw-r--r-- | lib/nexthop.c | 64 | ||||
| -rw-r--r-- | lib/northbound_cli.c | 18 | ||||
| -rw-r--r-- | lib/zclient.c | 27 | ||||
| -rw-r--r-- | lib/zclient.h | 3 |
5 files changed, 101 insertions, 13 deletions
diff --git a/lib/command_match.c b/lib/command_match.c index 56a7ae422b..f221e0a02c 100644 --- a/lib/command_match.c +++ b/lib/command_match.c @@ -81,7 +81,7 @@ static enum match_type match_mac(const char *, bool); static bool is_neg(vector vline, size_t idx) { - if (idx >= vector_active(vline)) + if (idx >= vector_active(vline) || !vector_slot(vline, idx)) return false; return !strcmp(vector_slot(vline, idx), "no"); } diff --git a/lib/nexthop.c b/lib/nexthop.c index 98409c76c5..2e09cb4bcc 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -634,9 +634,6 @@ const char *nexthop2str(const struct nexthop *nexthop, char *str, int size) case NEXTHOP_TYPE_BLACKHOLE: snprintf(str, size, "blackhole"); break; - default: - snprintf(str, size, "unknown"); - break; } return str; @@ -939,6 +936,12 @@ int nexthop_str2backups(const char *str, int *num_backups, * unreachable (blackhole) * %pNHs * nexthop2str() + * %pNHcg + * 1.2.3.4 + * (0-length if no IP address present) + * %pNHci + * eth0 + * (0-length if no interface present) */ printfrr_ext_autoreg_p("NH", printfrr_nh) static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea, @@ -993,12 +996,10 @@ static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea, case BLACKHOLE_NULL: ret += bputs(buf, " (blackhole)"); break; - default: + case BLACKHOLE_UNSPEC: break; } break; - default: - break; } if (do_ifi && nexthop->ifindex) ret += bprintfrr(buf, ", %s%s", v_viaif, @@ -1029,9 +1030,54 @@ static ssize_t printfrr_nh(struct fbuf *buf, struct printfrr_eargs *ea, case NEXTHOP_TYPE_BLACKHOLE: ret += bputs(buf, "blackhole"); break; - default: - ret += bputs(buf, "unknown"); - break; + } + return ret; + case 'c': + ea->fmt++; + if (*ea->fmt == 'g') { + ea->fmt++; + if (!nexthop) + return bputs(buf, "(null)"); + switch (nexthop->type) { + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + ret += bprintfrr(buf, "%pI4", + &nexthop->gate.ipv4); + break; + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + ret += bprintfrr(buf, "%pI6", + &nexthop->gate.ipv6); + break; + case NEXTHOP_TYPE_IFINDEX: + case NEXTHOP_TYPE_BLACKHOLE: + break; + } + } else if (*ea->fmt == 'i') { + ea->fmt++; + if (!nexthop) + return bputs(buf, "(null)"); + switch (nexthop->type) { + case NEXTHOP_TYPE_IFINDEX: + ret += bprintfrr( + buf, "%s", + ifindex2ifname(nexthop->ifindex, + nexthop->vrf_id)); + break; + case NEXTHOP_TYPE_IPV4: + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV6: + case NEXTHOP_TYPE_IPV6_IFINDEX: + if (nexthop->ifindex) + ret += bprintfrr( + buf, "%s", + ifindex2ifname( + nexthop->ifindex, + nexthop->vrf_id)); + break; + case NEXTHOP_TYPE_BLACKHOLE: + break; + } } return ret; } diff --git a/lib/northbound_cli.c b/lib/northbound_cli.c index b74a0e6c23..6676c0b072 100644 --- a/lib/northbound_cli.c +++ b/lib/northbound_cli.c @@ -550,6 +550,13 @@ void nb_cli_show_config_prepare(struct nb_config *config, bool with_defaults) LYD_VALIDATE_NO_STATE, NULL); } +static int lyd_node_cmp(struct lyd_node **dnode1, struct lyd_node **dnode2) +{ + struct nb_node *nb_node = (*dnode1)->schema->priv; + + return nb_node->cbs.cli_cmp(*dnode1, *dnode2); +} + static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root, bool with_defaults) { @@ -567,6 +574,10 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root, * it's time to print the config. */ if (sort_node && nb_node != sort_node) { + list_sort(sort_list, + (int (*)(const void **, + const void **))lyd_node_cmp); + for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data)) nb_cli_show_dnode_cmds(vty, data, with_defaults); @@ -584,11 +595,9 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root, if (!sort_node) { sort_node = nb_node; sort_list = list_new(); - sort_list->cmp = (int (*)(void *, void *)) - nb_node->cbs.cli_cmp; } - listnode_add_sort(sort_list, child); + listnode_add(sort_list, child); continue; } @@ -596,6 +605,9 @@ static void show_dnode_children_cmds(struct vty *vty, struct lyd_node *root, } if (sort_node) { + list_sort(sort_list, + (int (*)(const void **, const void **))lyd_node_cmp); + for (ALL_LIST_ELEMENTS_RO(sort_list, listnode, data)) nb_cli_show_dnode_cmds(vty, data, with_defaults); diff --git a/lib/zclient.c b/lib/zclient.c index a1e7194890..dde60a6c90 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1105,6 +1105,33 @@ stream_failure: return -1; } +int zapi_srv6_locator_encode(struct stream *s, const struct srv6_locator *l) +{ + stream_putw(s, strlen(l->name)); + stream_put(s, l->name, strlen(l->name)); + stream_putw(s, l->prefix.prefixlen); + stream_put(s, &l->prefix.prefix, sizeof(l->prefix.prefix)); + return 0; +} + +int zapi_srv6_locator_decode(struct stream *s, struct srv6_locator *l) +{ + uint16_t len = 0; + + STREAM_GETW(s, len); + if (len > SRV6_LOCNAME_SIZE) + goto stream_failure; + + STREAM_GET(l->name, s, len); + STREAM_GETW(s, l->prefix.prefixlen); + STREAM_GET(&l->prefix.prefix, s, sizeof(l->prefix.prefix)); + l->prefix.family = AF_INET6; + return 0; + +stream_failure: + return -1; +} + static int zapi_nhg_encode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) { int i; diff --git a/lib/zclient.h b/lib/zclient.h index 71187ccae7..f9438d5db7 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -1090,6 +1090,9 @@ extern int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl); extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl); +extern int zapi_srv6_locator_encode(struct stream *s, + const struct srv6_locator *l); +extern int zapi_srv6_locator_decode(struct stream *s, struct srv6_locator *l); extern int zapi_srv6_locator_chunk_encode(struct stream *s, const struct srv6_locator_chunk *c); extern int zapi_srv6_locator_chunk_decode(struct stream *s, |
