From: Donald Sharp Date: Fri, 16 Mar 2018 16:26:26 +0000 (-0400) Subject: sharpd: Add ability to register for nht X-Git-Tag: frr-5.0-dev~144^2 X-Git-Url: https://git.puffer.fish/?a=commitdiff_plain;h=refs%2Fpull%2F1911%2Fhead;p=mirror%2Ffrr.git sharpd: Add ability to register for nht Add code to sharpd to allow it to register for nexthop tracking and then to display when it receives information about the nexthop it is watching. Signed-off-by: Donald Sharp --- diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 3065ad19c3..4d19484a64 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -39,6 +39,46 @@ extern uint32_t total_routes; extern uint32_t installed_routes; extern uint32_t removed_routes; +DEFPY(watch_nexthop_v6, watch_nexthop_v6_cmd, + "sharp watch nexthop X:X::X:X$nhop", + "Sharp routing Protocol\n" + "Watch for changes\n" + "Watch for nexthop changes\n" + "The v6 nexthop to signal for watching\n") +{ + struct prefix p; + + memset(&p, 0, sizeof(p)); + + p.prefixlen = 128; + memcpy(&p.u.prefix6, &nhop, 16); + p.family = AF_INET6; + + sharp_zebra_nexthop_watch(&p, true); + + return CMD_SUCCESS; +} + +DEFPY(watch_nexthop_v4, watch_nexthop_v4_cmd, + "sharp watch nexthop A.B.C.D$nhop", + "Sharp routing Protocol\n" + "Watch for changes\n" + "Watch for nexthop changes\n" + "The v4 nexthop to signal for watching\n") +{ + struct prefix p; + + memset(&p, 0, sizeof(p)); + + p.prefixlen = 32; + p.u.prefix4 = nhop; + p.family = AF_INET; + + sharp_zebra_nexthop_watch(&p, true); + + return CMD_SUCCESS; +} + DEFPY (install_routes, install_routes_cmd, "sharp install routes A.B.C.D$start nexthop A.B.C.D$nexthop (1-1000000)$routes", @@ -147,5 +187,7 @@ void sharp_vty_init(void) install_element(ENABLE_NODE, &install_routes_cmd); install_element(ENABLE_NODE, &remove_routes_cmd); install_element(ENABLE_NODE, &vrf_label_cmd); + install_element(ENABLE_NODE, &watch_nexthop_v6_cmd); + install_element(ENABLE_NODE, &watch_nexthop_v4_cmd); return; } diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 8915397c7e..999255e925 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -214,6 +214,65 @@ void route_delete(struct prefix *p) return; } +void sharp_zebra_nexthop_watch(struct prefix *p, bool watch) +{ + int command = ZEBRA_NEXTHOP_REGISTER; + + if (!watch) + command = ZEBRA_NEXTHOP_UNREGISTER; + + zclient_send_rnh(zclient, command, p, true, VRF_DEFAULT); +} + +static int sharp_nexthop_update(int command, struct zclient *zclient, + zebra_size_t length, vrf_id_t vrf_id) +{ + struct zapi_route nhr; + char buf[PREFIX_STRLEN]; + int i; + + if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) { + zlog_warn("%s: Decode of update failed", __PRETTY_FUNCTION__); + + return 0; + } + + zlog_debug("Received update for %s", + prefix2str(&nhr.prefix, buf, sizeof(buf))); + for (i = 0; i < nhr.nexthop_num; i++) { + struct zapi_nexthop *znh = &nhr.nexthops[i]; + + switch (znh->type) { + case NEXTHOP_TYPE_IPV4_IFINDEX: + case NEXTHOP_TYPE_IPV4: + zlog_debug( + "\tNexthop %s, type: %d, ifindex: %d, vrf: %d, label_num: %d", + inet_ntop(AF_INET, &znh->gate.ipv4.s_addr, buf, + sizeof(buf)), + znh->type, znh->ifindex, znh->vrf_id, + znh->label_num); + break; + case NEXTHOP_TYPE_IPV6_IFINDEX: + case NEXTHOP_TYPE_IPV6: + zlog_debug( + "\tNexthop %s, type: %d, ifindex: %d, vrf: %d, label_num: %d", + inet_ntop(AF_INET6, &znh->gate.ipv6, buf, + sizeof(buf)), + znh->type, znh->ifindex, znh->vrf_id, + znh->label_num); + break; + case NEXTHOP_TYPE_IFINDEX: + zlog_debug("\tNexthop IFINDEX: %d, ifindex: %d", + znh->type, znh->ifindex); + break; + case NEXTHOP_TYPE_BLACKHOLE: + zlog_debug("\tNexthop blackhole"); + break; + } + } + return 0; +} + extern struct zebra_privs_t sharp_privs; void sharp_zebra_init(void) @@ -231,4 +290,5 @@ void sharp_zebra_init(void) zclient->interface_address_add = interface_address_add; zclient->interface_address_delete = interface_address_delete; zclient->route_notify_owner = route_notify_owner; + zclient->nexthop_update = sharp_nexthop_update; } diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index 0bba443bd4..0c906fc4ff 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -27,4 +27,5 @@ extern void sharp_zebra_init(void); extern void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label); extern void route_add(struct prefix *p, struct nexthop *nh); extern void route_delete(struct prefix *p); +extern void sharp_zebra_nexthop_watch(struct prefix *p, bool watch); #endif