From 67a9eda9ee82f23ab5713b60c2911a7c0bf8c2f8 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 2 Oct 2019 09:27:04 -0400 Subject: [PATCH] sharpd: Start infrastructure to allow for redistribution testing Start the work in sharpd to allow the testing of redistribution of routes. Namely telling zebra to tell us about redistribution events via the callback. Future work here will allow sharpd to specify the redistribution events it wants and to allow us to track that via counters. Signed-off-by: Donald Sharp --- sharpd/sharp_zebra.c | 74 ++++++++++++++++++++++++++++++++------------ 1 file changed, 55 insertions(+), 19 deletions(-) diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 14220830c2..da2aa2f539 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -205,6 +205,15 @@ static int route_notify_owner(ZAPI_CALLBACK_ARGS) static void zebra_connected(struct zclient *zclient) { zclient_send_reg_requests(zclient, VRF_DEFAULT); + + /* + * Do not actually turn this on yet + * This is just the start of the infrastructure needed here + * This can be fixed at a later time. + * + * zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, + * ZEBRA_ROUTE_ALL, 0, VRF_DEFAULT); + */ } void vrf_label_add(vrf_id_t vrf_id, afi_t afi, mpls_label_t label) @@ -300,28 +309,13 @@ void sharp_zebra_nexthop_watch(struct prefix *p, vrf_id_t vrf_id, bool import, __PRETTY_FUNCTION__); } -static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS) +static int sharp_debug_nexthops(struct zapi_route *api) { - struct sharp_nh_tracker *nht; - struct zapi_route nhr; - char buf[PREFIX_STRLEN]; int i; + char buf[PREFIX_STRLEN]; - 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))); - - nht = sharp_nh_tracker_get(&nhr.prefix); - nht->nhop_num = nhr.nexthop_num; - nht->updates++; - - for (i = 0; i < nhr.nexthop_num; i++) { - struct zapi_nexthop *znh = &nhr.nexthops[i]; + for (i = 0; i < api->nexthop_num; i++) { + struct zapi_nexthop *znh = &api->nexthops[i]; switch (znh->type) { case NEXTHOP_TYPE_IPV4_IFINDEX: @@ -351,6 +345,45 @@ static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS) break; } } + + return i; +} +static int sharp_nexthop_update(ZAPI_CALLBACK_ARGS) +{ + struct sharp_nh_tracker *nht; + struct zapi_route nhr; + + if (!zapi_nexthop_update_decode(zclient->ibuf, &nhr)) { + zlog_warn("%s: Decode of update failed", __PRETTY_FUNCTION__); + + return 0; + } + + zlog_debug("Received update for %pFX", &nhr.prefix); + + nht = sharp_nh_tracker_get(&nhr.prefix); + nht->nhop_num = nhr.nexthop_num; + nht->updates++; + + sharp_debug_nexthops(&nhr); + + return 0; +} + +static int sharp_redistribute_route(ZAPI_CALLBACK_ARGS) +{ + struct zapi_route api; + + if (zapi_route_decode(zclient->ibuf, &api) < 0) + zlog_warn("%s: Decode of redistribute failed: %d", + __PRETTY_FUNCTION__, + ZEBRA_REDISTRIBUTE_ROUTE_ADD); + + zlog_debug("%s: %pFX (%s)", zserv_command_string(cmd), + &api.prefix, zebra_route_string(api.type)); + + sharp_debug_nexthops(&api); + return 0; } @@ -372,4 +405,7 @@ void sharp_zebra_init(void) zclient->route_notify_owner = route_notify_owner; zclient->nexthop_update = sharp_nexthop_update; zclient->import_check_update = sharp_nexthop_update; + + zclient->redistribute_route_add = sharp_redistribute_route; + zclient->redistribute_route_del = sharp_redistribute_route; }