Skip to content

Commit

Permalink
staticd: Add new command show static ip/ipv6 route
Browse files Browse the repository at this point in the history
Signed-off-by: guozhongfeng.gzf <[email protected]>
  • Loading branch information
guoguojia2021 committed Dec 28, 2024
1 parent ee5a345 commit 7b20b86
Show file tree
Hide file tree
Showing 3 changed files with 157 additions and 0 deletions.
103 changes: 103 additions & 0 deletions staticd/static_routes.c
Original file line number Diff line number Diff line change
Expand Up @@ -691,3 +691,106 @@ void static_get_nh_str(struct static_nexthop *nh, char *nexthop, size_t size)
break;
};
}

void static_route_show_nexthop(struct vty *vty,
const struct static_nexthop *sn)
{

switch (sn->type) {
case STATIC_IFNAME:
vty_out(vty, " ifname(%d):%s", sn->ifindex, sn->ifname);
break;
case STATIC_IPV4_GATEWAY:
vty_out(vty, " ip4:%pI4", &sn->addr.ipv4);
break;
case STATIC_IPV4_GATEWAY_IFNAME:
vty_out(vty, " ip4-ifindex(%d):%pI4 :%s", sn->ifindex,
&sn->addr.ipv4, sn->ifname);
break;
case STATIC_BLACKHOLE:
vty_out(vty, " blackhole:%d", sn->bh_type);
break;
case STATIC_IPV6_GATEWAY:
vty_out(vty, " ip6:%pI6", &sn->addr.ipv6);
break;
case STATIC_IPV6_GATEWAY_IFNAME:
vty_out(vty, " ip6-ifindex(%d):%pI6 :%s", sn->ifindex,
&sn->addr.ipv6, sn->ifname);
break;
};

vty_out(vty, " %s, registered:%s, state:%d\n",
sn->nh_valid ? "valid" : "invalid",
sn->nh_registered ? "yes" : "no", sn->state);
}

void static_route_show_path(struct vty *vty, struct route_table *stable)
{
struct route_node *rn;
bool first = true;
int len_rn = 0;

for (rn = route_top(stable); rn; rn = srcdest_route_next(rn)) {
struct static_route_info *si = static_route_info_from_rnode(rn);
struct static_path *sp;

if (si == NULL)
continue;

frr_each (static_path_list, &si->path_list, sp) {
struct static_nexthop *sn;

len_rn = vty_out(vty, " %pRN", sp->rn);
frr_each (static_nexthop_list, &sp->nexthop_list, sn) {
if (first)
first = false;
else
vty_out(vty, "%*c", len_rn, ' ');
static_route_show_nexthop(vty, sn);
}
}
first = true;
}
}

void static_route_show(struct vty *vty, afi_t afi, char *vrf_name, bool vrf_all)
{
struct route_table *stable;
struct static_vrf *svrf;

vty_out(vty, "Staticd routes:\n");
if (vrf_all) {
RB_FOREACH (svrf, svrf_name_head, &svrfs) {
stable = static_vrf_static_table(afi, SAFI_UNICAST, svrf);
if (stable) {
vty_out(vty, " VRF %s %s Unicast:\n", svrf->name, afi2str(afi));
static_route_show_path(vty, stable);
}

stable = static_vrf_static_table(afi, SAFI_MULTICAST, svrf);
if (stable) {
vty_out(vty, " VRF %s %s Municast:\n", svrf->name, afi2str(afi));
static_route_show_path(vty, stable);
}
}
} else {
RB_FOREACH (svrf, svrf_name_head, &svrfs) {
if (strcmp(vrf_name, svrf->name) != 0)
continue;

stable = static_vrf_static_table(afi, SAFI_UNICAST, svrf);
if (stable) {
vty_out(vty, " VRF %s %s Unicast:\n", svrf->name, afi2str(afi));
static_route_show_path(vty, stable);
}

stable = static_vrf_static_table(afi, SAFI_MULTICAST, svrf);
if (stable) {
vty_out(vty, " VRF %s %s Municast:\n", svrf->name, afi2str(afi));
static_route_show_path(vty, stable);
}
}
}

vty_out(vty, "\n");
}
1 change: 1 addition & 0 deletions staticd/static_routes.h
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,7 @@ extern void static_bfd_initialize(struct zclient *zc, struct event_loop *tm);

extern void static_bfd_show(struct vty *vty, bool isjson);

extern void static_route_show(struct vty *vty, afi_t afi, char *vrf_name, bool vrf_all);
#ifdef __cplusplus
}
#endif
Expand Down
53 changes: 53 additions & 0 deletions staticd/static_vty.c
Original file line number Diff line number Diff line change
Expand Up @@ -1630,6 +1630,57 @@ DEFPY(staticd_show_bfd_routes, staticd_show_bfd_routes_cmd,
return CMD_SUCCESS;
}

DEFPY(show_static_ip_route, show_static_route_ip_cmd,
"show static ip route [vrf <NAME|all>]",
"Show running system information\n"
STATICD_STR
"ip address\n"
"BGP route table\n"
VRF_FULL_CMD_HELP_STR)
{
const char *vrf_name = VRF_DEFAULT_NAME;
bool all_vrf = false;
int idx = 0;

if (argv_find(argv, argc, "vrf", &idx)) {
vrf_name = argv[idx + 1]->arg;
all_vrf = strmatch(vrf_name, "all");
}

if (all_vrf)
static_route_show(vty, AFI_IP, NULL, true);
else
static_route_show(vty, AFI_IP, vrf_name, false);

return CMD_SUCCESS;
}

DEFPY(show_static_ipv6_route, show_static_route_ipv6_cmd,
"show static ipv6 route [vrf <NAME|all>]",
"Show running system information\n"
STATICD_STR
"ipv6 address\n"
"BGP route table\n"
VRF_FULL_CMD_HELP_STR)
{
const char *vrf_name = VRF_DEFAULT_NAME;
bool all_vrf = false;
int idx = 0;

if (argv_find(argv, argc, "vrf", &idx)) {
vrf_name = argv[idx + 1]->arg;
all_vrf = strmatch(vrf_name, "all");
}

if (all_vrf)
static_route_show(vty, AFI_IP6, NULL, true);
else

static_route_show(vty, AFI_IP6, vrf_name, false);

return CMD_SUCCESS;
}

DEFUN_NOSH (show_debugging_static,
show_debugging_static_cmd,
"show debugging [static]",
Expand All @@ -1653,6 +1704,8 @@ void static_vty_init(void)
install_element(CONFIG_NODE, &debug_staticd_cmd);
install_element(ENABLE_NODE, &show_debugging_static_cmd);
install_element(ENABLE_NODE, &staticd_show_bfd_routes_cmd);
install_element(ENABLE_NODE, &show_static_route_ip_cmd);
install_element(ENABLE_NODE, &show_static_route_ipv6_cmd);
#else /* else INCLUDE_MGMTD_CMDDEFS_ONLY */
install_element(CONFIG_NODE, &ip_mroute_dist_cmd);

Expand Down

0 comments on commit 7b20b86

Please sign in to comment.