diff options
author | Donald Sharp <sharpd@nvidia.com> | 2020-12-05 20:51:21 +0100 |
---|---|---|
committer | Donald Sharp <sharpd@nvidia.com> | 2020-12-08 15:06:09 +0100 |
commit | cfa2a35d8d0abc746d0d557e22556bacac1431c0 (patch) | |
tree | 62bebe1b1eed11d7dd473b513bf1574560c9d56c /sharpd | |
parent | zebra: Setup structure for opaque data to be displayed (diff) | |
download | frr-cfa2a35d8d0abc746d0d557e22556bacac1431c0.tar.xz frr-cfa2a35d8d0abc746d0d557e22556bacac1431c0.zip |
sharpd, zebra: Pass and display opaque data as PoC
Pass data from sharpd to zebra as opaque data and display
it as part of the detailed route data.
Signed-off-by: Donald Sharp <sharpd@nvidia.com>
Diffstat (limited to 'sharpd')
-rw-r--r-- | sharpd/sharp_globals.h | 2 | ||||
-rw-r--r-- | sharpd/sharp_vty.c | 13 | ||||
-rw-r--r-- | sharpd/sharp_zebra.c | 27 | ||||
-rw-r--r-- | sharpd/sharp_zebra.h | 2 |
4 files changed, 31 insertions, 13 deletions
diff --git a/sharpd/sharp_globals.h b/sharpd/sharp_globals.h index 0bd47454a..52561fd45 100644 --- a/sharpd/sharp_globals.h +++ b/sharpd/sharp_globals.h @@ -45,6 +45,8 @@ struct sharp_routes { struct timeval t_start; struct timeval t_end; + + char opaque[ZAPI_MESSAGE_OPAQUE_LENGTH]; }; struct sharp_global { diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 45c0799fa..a1215835c 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -163,7 +163,7 @@ DEFPY (install_routes, <nexthop <A.B.C.D$nexthop4|X:X::X:X$nexthop6>|\ nexthop-group NHGNAME$nexthop_group>\ [backup$backup <A.B.C.D$backup_nexthop4|X:X::X:X$backup_nexthop6>] \ - (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt]", + (1-1000000)$routes [instance (0-255)$instance] [repeat (2-1000)$rpt] [opaque WORD]", "Sharp routing Protocol\n" "install some routes\n" "Routes to install\n" @@ -183,7 +183,9 @@ DEFPY (install_routes, "Instance to use\n" "Instance\n" "Should we repeat this command\n" - "How many times to repeat this command\n") + "How many times to repeat this command\n" + "What opaque data to send down\n" + "The opaque data\n") { struct vrf *vrf; struct prefix prefix; @@ -292,12 +294,17 @@ DEFPY (install_routes, sg.r.backup_nhop_group.nexthop = &sg.r.backup_nhop; } + if (opaque) + strlcpy(sg.r.opaque, opaque, ZAPI_MESSAGE_OPAQUE_LENGTH); + else + sg.r.opaque[0] = '\0'; + sg.r.inst = instance; sg.r.vrf_id = vrf->vrf_id; rts = routes; sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, nhgid, &sg.r.nhop_group, &sg.r.backup_nhop_group, - rts); + rts, sg.r.opaque); return CMD_SUCCESS; } diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 627caea37..4445bc013 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -232,6 +232,7 @@ struct buffer_delay { const struct nexthop_group *nhg; const struct nexthop_group *backup_nhg; enum where_to_restart restart; + char *opaque; } wb; /* @@ -242,7 +243,7 @@ struct buffer_delay { */ static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance, uint32_t nhgid, const struct nexthop_group *nhg, - const struct nexthop_group *backup_nhg) + const struct nexthop_group *backup_nhg, char *opaque) { struct zapi_route api; struct zapi_nexthop *api_nh; @@ -290,6 +291,13 @@ static bool route_add(const struct prefix *p, vrf_id_t vrf_id, uint8_t instance, api.backup_nexthop_num = i; } + if (strlen(opaque)) { + SET_FLAG(api.message, ZAPI_MESSAGE_OPAQUE); + api.opaque.length = strlen(opaque) + 1; + assert(api.opaque.length <= ZAPI_MESSAGE_OPAQUE_LENGTH); + memcpy(api.opaque.data, opaque, api.opaque.length); + } + if (zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api) == ZCLIENT_SEND_BUFFERED) return true; @@ -326,7 +334,7 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count, uint32_t nhgid, const struct nexthop_group *nhg, const struct nexthop_group *backup_nhg, - uint32_t routes) + uint32_t routes, char *opaque) { uint32_t temp, i; bool v4 = false; @@ -339,7 +347,7 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count, for (i = count; i < routes; i++) { bool buffered = route_add(p, vrf_id, (uint8_t)instance, nhgid, - nhg, backup_nhg); + nhg, backup_nhg, opaque); if (v4) p->u.prefix4.s_addr = htonl(++temp); else @@ -354,6 +362,7 @@ static void sharp_install_routes_restart(struct prefix *p, uint32_t count, wb.nhgid = nhgid; wb.nhg = nhg; wb.backup_nhg = backup_nhg; + wb.opaque = opaque; wb.restart = SHARP_INSTALL_ROUTES_RESTART; return; @@ -365,7 +374,7 @@ void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id, uint8_t instance, uint32_t nhgid, const struct nexthop_group *nhg, const struct nexthop_group *backup_nhg, - uint32_t routes) + uint32_t routes, char *opaque) { zlog_debug("Inserting %u routes", routes); @@ -375,7 +384,7 @@ void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id, monotime(&sg.r.t_start); sharp_install_routes_restart(p, 0, vrf_id, instance, nhgid, nhg, - backup_nhg, routes); + backup_nhg, routes, opaque); } static void sharp_remove_routes_restart(struct prefix *p, uint32_t count, @@ -441,7 +450,7 @@ static void handle_repeated(bool installed) sharp_install_routes_helper(&p, sg.r.vrf_id, sg.r.inst, sg.r.nhgid, &sg.r.nhop_group, &sg.r.backup_nhop_group, - sg.r.total_routes); + sg.r.total_routes, sg.r.opaque); } } @@ -449,9 +458,9 @@ static void sharp_zclient_buffer_ready(void) { switch (wb.restart) { case SHARP_INSTALL_ROUTES_RESTART: - sharp_install_routes_restart(&wb.p, wb.count, wb.vrf_id, - wb.instance, wb.nhgid, wb.nhg, - wb.backup_nhg, wb.routes); + sharp_install_routes_restart( + &wb.p, wb.count, wb.vrf_id, wb.instance, wb.nhgid, + wb.nhg, wb.backup_nhg, wb.routes, wb.opaque); return; case SHARP_DELETE_ROUTES_RESTART: sharp_remove_routes_restart(&wb.p, wb.count, wb.vrf_id, diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index 8c5fa5e15..e7247f537 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -39,7 +39,7 @@ extern void sharp_install_routes_helper(struct prefix *p, vrf_id_t vrf_id, uint8_t instance, uint32_t nhgid, const struct nexthop_group *nhg, const struct nexthop_group *backup_nhg, - uint32_t routes); + uint32_t routes, char *opaque); extern void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id, uint8_t instance, uint32_t routes); |