From 054859269166720f36fe34096c904a7390f85f9e Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 09:07:18 +0000 Subject: [PATCH] *: eliminate redundant info from srv6 locator zapi Signed-off-by: Hiroki Shirokura --- bgpd/bgp_zebra.c | 11 --------- lib/zclient.c | 6 ++--- sharpd/sharp_zebra.c | 53 ++++++++++++++------------------------------ 3 files changed, 19 insertions(+), 51 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index a10c6fd245..d4a4ed2305 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -3009,17 +3009,6 @@ static void bgp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) s = zclient->ibuf; zapi_srv6_locator_chunk_decode(s, &s6c); - if (zclient->redist_default != s6c.proto) { - zlog_err("%s: Got SRv6 Manager msg with wrong proto %u", - __func__, s6c.proto); - return; - } - if (zclient->instance != s6c.instance) { - zlog_err("%s: Got SRv6 Manager msg with wrong instance %u", - __func__, s6c.instance); - return; - } - if (strcmp(bgp->srv6_locator_name, s6c.locator_name) != 0) { zlog_err("%s: Locator name unmatch %s:%s", __func__, bgp->srv6_locator_name, s6c.locator_name); diff --git a/lib/zclient.c b/lib/zclient.c index 4d8fbdf157..5395d4799d 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1070,8 +1070,6 @@ done: int zapi_srv6_locator_chunk_encode(struct stream *s, const struct srv6_locator_chunk *c) { - stream_putc(s, c->proto); - stream_putw(s, c->instance); stream_putw(s, strlen(c->locator_name)); stream_put(s, c->locator_name, strlen(c->locator_name)); stream_putw(s, c->prefix.prefixlen); @@ -1088,8 +1086,8 @@ int zapi_srv6_locator_chunk_decode(struct stream *s, { uint16_t len = 0; - STREAM_GETC(s, c->proto); - STREAM_GETW(s, c->instance); + c->prefix.family = AF_INET6; + STREAM_GETW(s, len); if (len > SRV6_LOCNAME_SIZE) goto stream_failure; diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index ae4add6a60..2575475dd2 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -938,52 +938,33 @@ int sharp_zebra_srv6_manager_release_locator_chunk(const char *locator_name) static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) { struct stream *s = NULL; - uint8_t proto; - uint16_t instance; - uint16_t len; - char name[256] = {0}; - struct prefix_ipv6 *chunk = NULL; - - chunk = prefix_ipv6_new(); - - s = zclient->ibuf; - STREAM_GETC(s, proto); - STREAM_GETW(s, instance); - - STREAM_GETW(s, len); - STREAM_GET(name, s, len); - - STREAM_GETW(s, chunk->prefixlen); - STREAM_GET(&chunk->prefix, s, 16); - - if (zclient->redist_default != proto) { - zlog_err("Got SRv6 Manager msg with wrong proto %u", proto); - return; - } - if (zclient->instance != instance) { - zlog_err("Got SRv6 Manager msg with wrong instance %u", proto); - return; - } - - struct listnode *loc_node; + struct srv6_locator_chunk s6c = {}; + struct listnode *node, *nnode; struct sharp_srv6_locator *loc; - for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) { + s = zclient->ibuf; + zapi_srv6_locator_chunk_decode(s, &s6c); + + for (ALL_LIST_ELEMENTS(sg.srv6_locators, node, nnode, loc)) { + struct prefix_ipv6 *chunk = NULL; struct listnode *chunk_node; struct prefix_ipv6 *c; - if (strcmp(loc->name, name)) + if (strcmp(loc->name, s6c.locator_name) != 0) { + zlog_err("%s: Locator name unmatch %s:%s", __func__, + loc->name, s6c.locator_name); continue; + } for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c)) - if (!prefix_cmp(c, chunk)) + if (!prefix_cmp(c, &s6c.prefix)) return; - listnode_add(loc->chunks, chunk); - } - return; -stream_failure: - free(chunk); + chunk = prefix_ipv6_new(); + *chunk = s6c.prefix; + listnode_add(loc->chunks, chunk); + return; + } zlog_err("%s: can't get locator_chunk!!", __func__); }