Merge pull request #16008 from mjstapp/show_routemap_source

zebra: include route source set by route-map in show output
This commit is contained in:
Russ White 2024-05-15 06:18:41 -04:00 committed by GitHub
commit db1e2a094d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 119 additions and 50 deletions

View file

@ -2381,6 +2381,14 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx
break; break;
setsrc = nexthop_set_src(nexthop, p->family, &src); setsrc = nexthop_set_src(nexthop, p->family, &src);
if (setsrc && IS_ZEBRA_DEBUG_KERNEL) {
if (p->family == AF_INET)
zlog_debug("%s: %pFX set src %pI4",
__func__, p, &src.ipv4);
else if (p->family == AF_INET6)
zlog_debug("%s: %pFX set src %pI6",
__func__, p, &src.ipv6);
}
} }
if (setsrc) { if (setsrc) {
@ -2423,6 +2431,16 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx
setsrc = nexthop_set_src(nexthop, p->family, setsrc = nexthop_set_src(nexthop, p->family,
&src); &src);
if (setsrc && IS_ZEBRA_DEBUG_KERNEL) {
if (p->family == AF_INET)
zlog_debug("%s: %pFX set src %pI4",
__func__, p,
&src.ipv4);
else if (p->family == AF_INET6)
zlog_debug("%s: %pFX set src %pI6",
__func__, p,
&src.ipv6);
}
continue; continue;
} }
@ -2482,6 +2500,16 @@ ssize_t netlink_route_multipath_msg_encode(int cmd, struct zebra_dplane_ctx *ctx
setsrc = nexthop_set_src(nexthop, p->family, setsrc = nexthop_set_src(nexthop, p->family,
&src); &src);
if (setsrc && IS_ZEBRA_DEBUG_KERNEL) {
if (p->family == AF_INET)
zlog_debug("%s: %pFX set src %pI4",
__func__, p,
&src.ipv4);
else if (p->family == AF_INET6)
zlog_debug("%s: %pFX set src %pI6",
__func__, p,
&src.ipv6);
}
continue; continue;
} }

View file

@ -1266,6 +1266,7 @@ failure:
*/ */
void show_nexthop_json_helper(json_object *json_nexthop, void show_nexthop_json_helper(json_object *json_nexthop,
const struct nexthop *nexthop, const struct nexthop *nexthop,
const struct route_node *rn,
const struct route_entry *re) const struct route_entry *re)
{ {
json_object *json_labels = NULL; json_object *json_labels = NULL;
@ -1381,13 +1382,24 @@ void show_nexthop_json_helper(json_object *json_nexthop,
switch (nexthop->type) { switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
if (nexthop->src.ipv4.s_addr) if (nexthop->rmap_src.ipv4.s_addr)
json_object_string_addf(json_nexthop, "rmapSource",
"%pI4", &nexthop->rmap_src.ipv4);
else if (nexthop->src.ipv4.s_addr)
json_object_string_addf(json_nexthop, "source", "%pI4", json_object_string_addf(json_nexthop, "source", "%pI4",
&nexthop->src.ipv4); &nexthop->src.ipv4);
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) /* Allow for 5549 ipv4 prefix with ipv6 nexthop */
if (rn && rn->p.family == AF_INET &&
nexthop->rmap_src.ipv4.s_addr)
json_object_string_addf(json_nexthop, "rmapSource",
"%pI4", &nexthop->rmap_src.ipv4);
else if (!IPV6_ADDR_SAME(&nexthop->rmap_src.ipv6, &in6addr_any))
json_object_string_addf(json_nexthop, "rmapSource",
"%pI6", &nexthop->rmap_src.ipv6);
else if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
json_object_string_addf(json_nexthop, "source", "%pI6", json_object_string_addf(json_nexthop, "source", "%pI6",
&nexthop->src.ipv6); &nexthop->src.ipv6);
break; break;
@ -1461,13 +1473,15 @@ void show_nexthop_json_helper(json_object *json_nexthop,
/* /*
* Helper for nexthop output, used in the 'show ip route' path * Helper for nexthop output, used in the 'show ip route' path
*/ */
void show_route_nexthop_helper(struct vty *vty, const struct route_entry *re, void show_route_nexthop_helper(struct vty *vty, const struct route_node *rn,
const struct route_entry *re,
const struct nexthop *nexthop) const struct nexthop *nexthop)
{ {
char buf[MPLS_LABEL_STRLEN]; char buf[MPLS_LABEL_STRLEN];
char seg_buf[SRV6_SEG_STRLEN]; char seg_buf[SRV6_SEG_STRLEN];
struct seg6_segs segs; struct seg6_segs segs;
uint8_t i; uint8_t i;
bool src_p = false;
switch (nexthop->type) { switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
@ -1529,8 +1543,14 @@ void show_route_nexthop_helper(struct vty *vty, const struct route_entry *re,
switch (nexthop->type) { switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
if (nexthop->src.ipv4.s_addr) { if (nexthop->rmap_src.ipv4.s_addr) {
vty_out(vty, ", rmapsrc %pI4", &nexthop->rmap_src.ipv4);
src_p = true;
} else if (nexthop->src.ipv4.s_addr) {
vty_out(vty, ", src %pI4", &nexthop->src.ipv4); vty_out(vty, ", src %pI4", &nexthop->src.ipv4);
src_p = true;
}
if (src_p) {
/* SR-TE information */ /* SR-TE information */
if (nexthop->srte_color) if (nexthop->srte_color)
vty_out(vty, ", SR-TE color %u", vty_out(vty, ", SR-TE color %u",
@ -1539,7 +1559,13 @@ void show_route_nexthop_helper(struct vty *vty, const struct route_entry *re,
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) /* Allow for 5549 ipv4 prefix with ipv6 nexthop */
if (rn && rn->p.family == AF_INET &&
nexthop->rmap_src.ipv4.s_addr)
vty_out(vty, ", rmapsrc %pI4", &nexthop->rmap_src.ipv4);
else if (!IPV6_ADDR_SAME(&nexthop->rmap_src.ipv6, &in6addr_any))
vty_out(vty, ", rmapsrc %pI6", &nexthop->rmap_src.ipv6);
else if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
vty_out(vty, ", src %pI6", &nexthop->src.ipv6); vty_out(vty, ", src %pI6", &nexthop->src.ipv6);
break; break;
case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFINDEX:
@ -1644,9 +1670,10 @@ static void print_rnh(struct route_node *rn, struct vty *vty, json_object *json)
json_object_array_add(json_nexthop_array, json_object_array_add(json_nexthop_array,
json_nexthop); json_nexthop);
show_nexthop_json_helper(json_nexthop, nexthop, show_nexthop_json_helper(json_nexthop, nexthop,
NULL); rn, NULL);
} else { } else {
show_route_nexthop_helper(vty, NULL, nexthop); show_route_nexthop_helper(vty, rn, NULL,
nexthop);
vty_out(vty, "\n"); vty_out(vty, "\n");
} }
} }

View file

@ -45,8 +45,10 @@ bool rnh_get_hide_backups(void);
void show_nexthop_json_helper(json_object *json_nexthop, void show_nexthop_json_helper(json_object *json_nexthop,
const struct nexthop *nexthop, const struct nexthop *nexthop,
const struct route_node *rn,
const struct route_entry *re); const struct route_entry *re);
void show_route_nexthop_helper(struct vty *vty, const struct route_entry *re, void show_route_nexthop_helper(struct vty *vty, const struct route_node *rn,
const struct route_entry *re,
const struct nexthop *nexthop); const struct nexthop *nexthop);
#ifdef __cplusplus #ifdef __cplusplus

View file

@ -76,13 +76,17 @@ static void vty_show_ip_route_summary_prefix(struct vty *vty,
bool use_json); bool use_json);
/* Helper api to format a nexthop in the 'detailed' output path. */ /* Helper api to format a nexthop in the 'detailed' output path. */
static void show_nexthop_detail_helper(struct vty *vty, static void show_nexthop_detail_helper(struct vty *vty,
const struct route_node *rn,
const struct route_entry *re, const struct route_entry *re,
const struct nexthop *nexthop, const struct nexthop *nexthop,
bool is_backup); bool is_backup);
static void show_ip_route_dump_vty(struct vty *vty, struct route_table *table); static void show_ip_route_dump_vty(struct vty *vty, struct route_table *table);
static void show_ip_route_nht_dump(struct vty *vty, struct nexthop *nexthop, static void show_ip_route_nht_dump(struct vty *vty,
struct route_entry *re, unsigned int num); const struct nexthop *nexthop,
const struct route_node *rn,
const struct route_entry *re,
unsigned int num);
DEFUN (ip_multicast_mode, DEFUN (ip_multicast_mode,
ip_multicast_mode_cmd, ip_multicast_mode_cmd,
@ -252,7 +256,7 @@ static char re_status_output_char(const struct route_entry *re,
/* /*
* Show backup nexthop info, in the 'detailed' output path * Show backup nexthop info, in the 'detailed' output path
*/ */
static void show_nh_backup_helper(struct vty *vty, static void show_nh_backup_helper(struct vty *vty, const struct route_node *rn,
const struct route_entry *re, const struct route_entry *re,
const struct nexthop *nexthop) const struct nexthop *nexthop)
{ {
@ -282,7 +286,7 @@ static void show_nh_backup_helper(struct vty *vty,
temp = backup; temp = backup;
while (backup) { while (backup) {
vty_out(vty, " "); vty_out(vty, " ");
show_nexthop_detail_helper(vty, re, backup, show_nexthop_detail_helper(vty, rn, re, backup,
true /*backup*/); true /*backup*/);
vty_out(vty, "\n"); vty_out(vty, "\n");
@ -303,11 +307,11 @@ static void show_nh_backup_helper(struct vty *vty,
* output path. * output path.
*/ */
static void show_nexthop_detail_helper(struct vty *vty, static void show_nexthop_detail_helper(struct vty *vty,
const struct route_node *rn,
const struct route_entry *re, const struct route_entry *re,
const struct nexthop *nexthop, const struct nexthop *nexthop,
bool is_backup) bool is_backup)
{ {
char addrstr[32];
char buf[MPLS_LABEL_STRLEN]; char buf[MPLS_LABEL_STRLEN];
int i; int i;
@ -391,23 +395,21 @@ static void show_nexthop_detail_helper(struct vty *vty,
switch (nexthop->type) { switch (nexthop->type) {
case NEXTHOP_TYPE_IPV4: case NEXTHOP_TYPE_IPV4:
case NEXTHOP_TYPE_IPV4_IFINDEX: case NEXTHOP_TYPE_IPV4_IFINDEX:
if (nexthop->src.ipv4.s_addr) { if (nexthop->rmap_src.ipv4.s_addr)
if (inet_ntop(AF_INET, &nexthop->src.ipv4, vty_out(vty, ", rmapsrc %pI4", &nexthop->rmap_src.ipv4);
addrstr, sizeof(addrstr))) else if (nexthop->src.ipv4.s_addr)
vty_out(vty, ", src %s", vty_out(vty, ", src %pI4", &nexthop->src.ipv4);
addrstr);
}
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, /* Allow for 5549 ipv4 prefix with ipv6 nexthop */
&in6addr_any)) { if (rn->p.family == AF_INET && nexthop->rmap_src.ipv4.s_addr)
if (inet_ntop(AF_INET6, &nexthop->src.ipv6, vty_out(vty, ", rmapsrc %pI4", &nexthop->rmap_src.ipv4);
addrstr, sizeof(addrstr))) else if (!IPV6_ADDR_SAME(&nexthop->rmap_src.ipv6, &in6addr_any))
vty_out(vty, ", src %s", vty_out(vty, ", rmapsrc %pI6", &nexthop->rmap_src.ipv6);
addrstr); else if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
} vty_out(vty, ", src %pI6", &nexthop->src.ipv6);
break; break;
case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFINDEX:
@ -591,13 +593,13 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn,
for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) { for (ALL_NEXTHOPS(re->nhe->nhg, nexthop)) {
/* Use helper to format each nexthop */ /* Use helper to format each nexthop */
show_nexthop_detail_helper(vty, re, nexthop, show_nexthop_detail_helper(vty, rn, re, nexthop,
false /*not backup*/); false /*not backup*/);
vty_out(vty, "\n"); vty_out(vty, "\n");
/* Include backup(s), if present */ /* Include backup(s), if present */
if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP)) if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_HAS_BACKUP))
show_nh_backup_helper(vty, re, nexthop); show_nh_backup_helper(vty, rn, re, nexthop);
} }
zebra_show_ip_route_opaque(vty, re, NULL); zebra_show_ip_route_opaque(vty, re, NULL);
@ -704,8 +706,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
for (ALL_NEXTHOPS_PTR(nhg, nexthop)) { for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
json_nexthop = json_object_new_object(); json_nexthop = json_object_new_object();
show_nexthop_json_helper(json_nexthop, show_nexthop_json_helper(json_nexthop, nexthop, rn, re);
nexthop, re);
json_object_array_add(json_nexthops, json_object_array_add(json_nexthops,
json_nexthop); json_nexthop);
@ -725,8 +726,8 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
for (ALL_NEXTHOPS_PTR(nhg, nexthop)) { for (ALL_NEXTHOPS_PTR(nhg, nexthop)) {
json_nexthop = json_object_new_object(); json_nexthop = json_object_new_object();
show_nexthop_json_helper(json_nexthop, show_nexthop_json_helper(json_nexthop, nexthop,
nexthop, re); rn, re);
json_object_array_add(json_nexthops, json_object_array_add(json_nexthops,
json_nexthop); json_nexthop);
} }
@ -791,7 +792,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
len - 3 + (2 * nexthop_level(nexthop)), ' '); len - 3 + (2 * nexthop_level(nexthop)), ' ');
} }
show_route_nexthop_helper(vty, re, nexthop); show_route_nexthop_helper(vty, rn, re, nexthop);
vty_out(vty, ", %s\n", up_str); vty_out(vty, ", %s\n", up_str);
} }
@ -822,7 +823,7 @@ static void vty_show_ip_route(struct vty *vty, struct route_node *rn,
vty_out(vty, " b%c %*c", vty_out(vty, " b%c %*c",
(star_p ? '*' : ' '), (star_p ? '*' : ' '),
len - 3 + (2 * nexthop_level(nexthop)), ' '); len - 3 + (2 * nexthop_level(nexthop)), ' ');
show_route_nexthop_helper(vty, re, nexthop); show_route_nexthop_helper(vty, rn, re, nexthop);
vty_out(vty, "\n"); vty_out(vty, "\n");
} }
@ -1278,14 +1279,15 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
for (ALL_NEXTHOPS(nhe->nhg, nexthop)) { for (ALL_NEXTHOPS(nhe->nhg, nexthop)) {
if (json_nexthop_array) { if (json_nexthop_array) {
json_nexthops = json_object_new_object(); json_nexthops = json_object_new_object();
show_nexthop_json_helper(json_nexthops, nexthop, NULL); show_nexthop_json_helper(json_nexthops, nexthop, NULL,
NULL);
} else { } else {
if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE)) if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_RECURSIVE))
vty_out(vty, " "); vty_out(vty, " ");
else else
/* Make recursive nexthops a bit more clear */ /* Make recursive nexthops a bit more clear */
vty_out(vty, " "); vty_out(vty, " ");
show_route_nexthop_helper(vty, NULL, nexthop); show_route_nexthop_helper(vty, NULL, NULL, nexthop);
} }
if (nhe->backup_info == NULL || nhe->backup_info->nhe == NULL) { if (nhe->backup_info == NULL || nhe->backup_info->nhe == NULL) {
@ -1343,7 +1345,7 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
if (json_backup_nexthop_array) { if (json_backup_nexthop_array) {
json_backup_nexthops = json_object_new_object(); json_backup_nexthops = json_object_new_object();
show_nexthop_json_helper(json_backup_nexthops, show_nexthop_json_helper(json_backup_nexthops,
nexthop, NULL); nexthop, NULL, NULL);
json_object_array_add(json_backup_nexthop_array, json_object_array_add(json_backup_nexthop_array,
json_backup_nexthops); json_backup_nexthops);
} else { } else {
@ -1356,7 +1358,8 @@ static void show_nexthop_group_out(struct vty *vty, struct nhg_hash_entry *nhe,
* clear * clear
*/ */
vty_out(vty, " "); vty_out(vty, " ");
show_route_nexthop_helper(vty, NULL, nexthop); show_route_nexthop_helper(vty, NULL, NULL,
nexthop);
vty_out(vty, "\n"); vty_out(vty, "\n");
} }
} }
@ -2104,8 +2107,11 @@ DEFUN_HIDDEN (show_route_zebra_dump,
return CMD_SUCCESS; return CMD_SUCCESS;
} }
static void show_ip_route_nht_dump(struct vty *vty, struct nexthop *nexthop, static void show_ip_route_nht_dump(struct vty *vty,
struct route_entry *re, unsigned int num) const struct nexthop *nexthop,
const struct route_node *rn,
const struct route_entry *re,
unsigned int num)
{ {
char buf[SRCDEST2STR_BUFFER]; char buf[SRCDEST2STR_BUFFER];
@ -2129,10 +2135,12 @@ static void show_ip_route_nht_dump(struct vty *vty, struct nexthop *nexthop,
nexthop->vrf_id)); nexthop->vrf_id));
} }
if (nexthop->src.ipv4.s_addr if (nexthop->rmap_src.ipv4.s_addr)
&& (inet_ntop(AF_INET, &nexthop->src.ipv4, buf, vty_out(vty, " rmapsrc: %pI4\n",
sizeof(buf)))) &nexthop->rmap_src.ipv4);
vty_out(vty, " source: %s\n", buf); else if (nexthop->src.ipv4.s_addr)
vty_out(vty, " source: %pI4\n",
&nexthop->src.ipv4.s_addr);
break; break;
case NEXTHOP_TYPE_IPV6: case NEXTHOP_TYPE_IPV6:
case NEXTHOP_TYPE_IPV6_IFINDEX: case NEXTHOP_TYPE_IPV6_IFINDEX:
@ -2149,11 +2157,15 @@ static void show_ip_route_nht_dump(struct vty *vty, struct nexthop *nexthop,
nexthop->vrf_id)); nexthop->vrf_id));
} }
if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any)) { /* Allow for 5549 ipv4 prefix with ipv6 nexthop */
if (inet_ntop(AF_INET6, &nexthop->src.ipv6, buf, if (rn->p.family == AF_INET && nexthop->rmap_src.ipv4.s_addr)
sizeof(buf))) vty_out(vty, " rmapsrc: %pI4\n",
vty_out(vty, " source: %s\n", buf); &nexthop->rmap_src.ipv4);
} else if (!IPV6_ADDR_SAME(&nexthop->rmap_src.ipv6, &in6addr_any))
vty_out(vty, " rmapsrc: %pI6\n",
&nexthop->rmap_src.ipv6);
else if (!IPV6_ADDR_SAME(&nexthop->src.ipv6, &in6addr_any))
vty_out(vty, " source: %pI6\n", &nexthop->src.ipv6);
break; break;
case NEXTHOP_TYPE_IFINDEX: case NEXTHOP_TYPE_IFINDEX:
vty_out(vty, vty_out(vty,
@ -2245,7 +2257,7 @@ static void show_ip_route_dump_vty(struct vty *vty, struct route_table *table)
for (ALL_NEXTHOPS_PTR(&(re->nhe->nhg), nexthop)) { for (ALL_NEXTHOPS_PTR(&(re->nhe->nhg), nexthop)) {
nexthop_num++; nexthop_num++;
show_ip_route_nht_dump(vty, nexthop, re, show_ip_route_nht_dump(vty, nexthop, rn, re,
nexthop_num); nexthop_num);
} }