diff options
| author | Stephen Worley <sworley@cumulusnetworks.com> | 2020-09-22 15:27:35 -0400 |
|---|---|---|
| committer | Stephen Worley <sworley@cumulusnetworks.com> | 2020-09-28 12:41:00 -0400 |
| commit | c6ce9334b5387f482af4112ed1ffe6a49debe352 (patch) | |
| tree | f9e2a98bce9af2b94ed49d8a407d96a30428fde5 /lib/zclient.c | |
| parent | aaa42e056fe2e52c74c8e9241948cc76b61e2ee2 (diff) | |
lib,sharpd: align zapi NHG apis a bit
Align the zapi NHG apis to be more consistent with the zapi_route
apis. Add a struct zapi_nhg to use for encodings as well.
Signed-off-by: Stephen Worley <sworley@cumulusnetworks.com>
Diffstat (limited to 'lib/zclient.c')
| -rw-r--r-- | lib/zclient.c | 53 |
1 files changed, 24 insertions, 29 deletions
diff --git a/lib/zclient.c b/lib/zclient.c index dfb409426d..13eba4c790 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1017,49 +1017,44 @@ done: return ret; } -extern void zclient_nhg_del(struct zclient *zclient, uint32_t id) +static int zapi_nhg_encode(struct stream *s, uint16_t proto, int cmd, + struct zapi_nhg *api_nhg) { - struct stream *s = zclient->obuf; + if (cmd != ZEBRA_NHG_DEL && cmd != ZEBRA_NHG_ADD) { + flog_err(EC_LIB_ZAPI_ENCODE, + "%s: Specified zapi NHG command (%d) doesn't exist\n", + __func__, cmd); + return -1; + } stream_reset(s); - zclient_create_header(s, ZEBRA_NHG_DEL, VRF_DEFAULT); - - stream_putw(s, zclient->redist_default); - stream_putl(s, id); - - stream_putw_at(s, 0, stream_get_endp(s)); -} - -static void zclient_nhg_writer(struct stream *s, uint16_t proto, int cmd, - uint32_t id, size_t nhops, - struct zapi_nexthop *znh) -{ - size_t i; + zclient_create_header(s, cmd, VRF_DEFAULT); - stream_reset(s); + stream_putw(s, proto); + stream_putl(s, api_nhg->id); - zapi_nexthop_group_sort(znh, nhops); + if (cmd == ZEBRA_NHG_ADD) { + zapi_nexthop_group_sort(api_nhg->nexthops, + api_nhg->nexthop_num); - zclient_create_header(s, cmd, VRF_DEFAULT); + stream_putw(s, api_nhg->nexthop_num); - stream_putw(s, proto); - stream_putl(s, id); - stream_putw(s, nhops); - for (i = 0; i < nhops; i++) { - zapi_nexthop_encode(s, znh, 0, 0); - znh++; + for (int i = 0; i < api_nhg->nexthop_num; i++) + zapi_nexthop_encode(s, &api_nhg->nexthops[i], 0, 0); } stream_putw_at(s, 0, stream_get_endp(s)); + + return 0; } -extern void zclient_nhg_add(struct zclient *zclient, uint32_t id, size_t nhops, - struct zapi_nexthop *znh) +int zclient_nhg_send(struct zclient *zclient, int cmd, struct zapi_nhg *api_nhg) { - struct stream *s = zclient->obuf; + if (zapi_nhg_encode(zclient->obuf, zclient->redist_default, cmd, + api_nhg)) + return -1; - zclient_nhg_writer(s, zclient->redist_default, ZEBRA_NHG_ADD, id, nhops, - znh); + return zclient_send_message(zclient); } int zapi_route_encode(uint8_t cmd, struct stream *s, struct zapi_route *api) |
