sharpd: Add code to allow nexthops to be watched from non-default vrf

Add a bit of code to the sharp cli to allow it to specify a non-default
vrf.

Signed-off-by: Donald Sharp <sharpd@cumulusnetworks.com>
This commit is contained in:
Donald Sharp 2019-02-28 08:24:20 -05:00
parent 91529dc88d
commit a3b6aa82db

View File

@ -39,17 +39,28 @@
#endif #endif
DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd, DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
"sharp watch <nexthop$n|import$import> X:X::X:X$nhop [connected$connected]", "sharp watch [vrf NAME$name] <nexthop$n|import$import> X:X::X:X$nhop [connected$connected]",
"Sharp routing Protocol\n" "Sharp routing Protocol\n"
"Watch for changes\n" "Watch for changes\n"
"The vrf we would like to watch if non-default\n"
"The NAME of the vrf\n"
"Watch for nexthop changes\n" "Watch for nexthop changes\n"
"Watch for import check changes\n" "Watch for import check changes\n"
"The v6 nexthop to signal for watching\n" "The v6 nexthop to signal for watching\n"
"Should the route be connected\n") "Should the route be connected\n")
{ {
struct vrf *vrf;
struct prefix p; struct prefix p;
bool type_import; bool type_import;
if (!name)
name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
name);
return CMD_WARNING;
}
if (n) if (n)
type_import = false; type_import = false;
@ -63,24 +74,36 @@ DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd,
p.family = AF_INET6; p.family = AF_INET6;
sharp_nh_tracker_get(&p); sharp_nh_tracker_get(&p);
sharp_zebra_nexthop_watch(&p, VRF_DEFAULT, type_import, sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import,
true, !!connected); true, !!connected);
return CMD_SUCCESS; return CMD_SUCCESS;
} }
DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
"sharp watch <nexthop$n|import$import> A.B.C.D$nhop [connected$connected]", "sharp watch [vrf NAME$name] <nexthop$n|import$import> A.B.C.D$nhop [connected$connected]",
"Sharp routing Protocol\n" "Sharp routing Protocol\n"
"Watch for changes\n" "Watch for changes\n"
"The vrf we would like to watch if non-default\n"
"The NAME of the vrf\n"
"Watch for nexthop changes\n" "Watch for nexthop changes\n"
"Watch for import check changes\n" "Watch for import check changes\n"
"The v4 nexthop to signal for watching\n" "The v4 nexthop to signal for watching\n"
"Should the route be connected\n") "Should the route be connected\n")
{ {
struct vrf *vrf;
struct prefix p; struct prefix p;
bool type_import; bool type_import;
if (!name)
name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(name);
if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n",
name);
return CMD_WARNING;
}
memset(&p, 0, sizeof(p)); memset(&p, 0, sizeof(p));
if (n) if (n)
@ -93,7 +116,7 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd,
p.family = AF_INET; p.family = AF_INET;
sharp_nh_tracker_get(&p); sharp_nh_tracker_get(&p);
sharp_zebra_nexthop_watch(&p, VRF_DEFAULT, type_import, sharp_zebra_nexthop_watch(&p, vrf->vrf_id, type_import,
true, !!connected); true, !!connected);
return CMD_SUCCESS; return CMD_SUCCESS;
@ -181,10 +204,13 @@ DEFPY (install_routes,
} }
sg.r.orig_prefix = prefix; sg.r.orig_prefix = prefix;
vrf = vrf_lookup_by_name(name ? name : VRF_DEFAULT_NAME); if (!name)
name = VRF_DEFAULT_NAME;
vrf = vrf_lookup_by_name(name);
if (!vrf) { if (!vrf) {
vty_out(vty, "The vrf NAME specified: %s does not exist\n", vty_out(vty, "The vrf NAME specified: %s does not exist\n",
name ? name : VRF_DEFAULT_NAME); name);
return CMD_WARNING; return CMD_WARNING;
} }