From: Donald Sharp Date: Thu, 28 Feb 2019 13:24:20 +0000 (-0500) Subject: sharpd: Add code to allow nexthops to be watched from non-default vrf X-Git-Tag: 7.1_pulled~189^2~1 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=a3b6aa82db8f0caf9e04d93e0c74849db1cc63b6;p=matthieu%2Ffrr.git 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 --- diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 74550d82d4..fbcbbe3fdc 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -39,17 +39,28 @@ #endif DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd, - "sharp watch X:X::X:X$nhop [connected$connected]", + "sharp watch [vrf NAME$name] X:X::X:X$nhop [connected$connected]", "Sharp routing Protocol\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 import check changes\n" "The v6 nexthop to signal for watching\n" "Should the route be connected\n") { + struct vrf *vrf; struct prefix p; 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) type_import = false; @@ -63,24 +74,36 @@ DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd, p.family = AF_INET6; 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); return CMD_SUCCESS; } DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, - "sharp watch A.B.C.D$nhop [connected$connected]", + "sharp watch [vrf NAME$name] A.B.C.D$nhop [connected$connected]", "Sharp routing Protocol\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 import check changes\n" "The v4 nexthop to signal for watching\n" "Should the route be connected\n") { + struct vrf *vrf; struct prefix p; 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)); if (n) @@ -93,7 +116,7 @@ DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, p.family = AF_INET; 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); return CMD_SUCCESS; @@ -181,10 +204,13 @@ DEFPY (install_routes, } 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) { vty_out(vty, "The vrf NAME specified: %s does not exist\n", - name ? name : VRF_DEFAULT_NAME); + name); return CMD_WARNING; }