From cb7775a9740d78ba81b5126fcb637102e4bad1d6 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Wed, 19 Aug 2020 09:46:33 +0900 Subject: lib: add new nexthop's attributes seg6local (step1) This commit is a part of #5853 works that add new nexthop's addional object for SRv6 routing about seg6local route. Before this commit, we can add MPLS info as additional object on nexthop. This commit make it add more support about seg6local routes. seg6local routes are ones of the LWT routing mechanism, so configuration of seg6local routes is performed by ZEBRA_ROUTE_SEND, it's same as MPLS configuration. Real configuration implementation isn't implemented at this commit. later commit add that. This commit add only nexthop additional object and some misc functions. Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 3ea1789441..bf67392cbe 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -796,6 +796,19 @@ static int zapi_nexthop_labels_cmp(const struct zapi_nexthop *next1, return memcmp(next1->labels, next2->labels, next1->label_num); } +static int zapi_nexthop_seg6local_cmp(const struct zapi_nexthop *next1, + const struct zapi_nexthop *next2) +{ + if (next1->seg6local_action > next2->seg6local_action) + return 1; + + if (next1->seg6local_action < next2->seg6local_action) + return -1; + + return memcmp(&next1->seg6local_ctx, &next2->seg6local_ctx, + sizeof(struct seg6local_context)); +} + static int zapi_nexthop_cmp_no_labels(const struct zapi_nexthop *next1, const struct zapi_nexthop *next2) { @@ -896,6 +909,10 @@ static int zapi_nexthop_cmp(const void *item1, const void *item2) return ret; ret = zapi_nexthop_labels_cmp(next1, next2); + if (ret != 0) + return ret; + + ret = zapi_nexthop_seg6local_cmp(next1, next2); return ret; } @@ -992,6 +1009,12 @@ int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, stream_putc(s, api_nh->backup_idx[i]); } + if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE)) { + stream_putl(s, api_nh->seg6local_action); + stream_write(s, &api_nh->seg6local_ctx, + sizeof(struct seg6local_context)); + } + done: return ret; } @@ -1273,6 +1296,12 @@ int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh, STREAM_GETC(s, api_nh->backup_idx[i]); } + if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE)) { + STREAM_GETL(s, api_nh->seg6local_action); + STREAM_GET(&api_nh->seg6local_ctx, s, + sizeof(struct seg6local_context)); + } + /* Success */ ret = 0; @@ -1637,6 +1666,10 @@ struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) memcpy(n->backup_idx, znh->backup_idx, n->backup_num); } + if (znh->seg6local_action != 0) + nexthop_add_seg6local(n, znh->seg6local_action, + &znh->seg6local_ctx); + return n; } @@ -1681,6 +1714,12 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, memcpy(znh->backup_idx, nh->backup_idx, znh->backup_num); } + if (nh->nh_seg6local_action != 0 && nh->nh_seg6local_ctx != NULL) { + znh->seg6local_action = nh->nh_seg6local_action; + memcpy(&znh->seg6local_ctx, nh->nh_seg6local_ctx, + sizeof(struct seg6local_context)); + } + return 0; } -- cgit v1.2.3 From f2867068e679900582aeb263d1723f8d7c3aa0ed Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Sun, 23 Feb 2020 11:27:15 +0000 Subject: lib: add new structures for srv6-locator (step2) This commit is a part of #5853 works that add new structures for SRv6-locator. This structure will be used by zebra and another routing daemon and its ZAPI messaging to manage SRv6-locator. Encoder/decoder for ZAPI stream is also added by this commit. Real configuration mechanism isn't implemented at this commit. later commit add real configure implementation. This commit add only SRv6-locator's structures and misc functions. Signed-off-by: Hiroki Shirokura --- lib/srv6.c | 85 +++++++++++++++++++++++++++ lib/srv6.h | 32 ++++++++++ lib/zclient.c | 184 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ lib/zclient.h | 16 +++++ 4 files changed, 317 insertions(+) (limited to 'lib/zclient.c') diff --git a/lib/srv6.c b/lib/srv6.c index 9b9f402987..d59d2d75b0 100644 --- a/lib/srv6.c +++ b/lib/srv6.c @@ -22,6 +22,10 @@ #include "srv6.h" #include "log.h" +DEFINE_QOBJ_TYPE(srv6_locator); +DEFINE_MTYPE_STATIC(LIB, SRV6_LOCATOR, "SRV6 locator"); +DEFINE_MTYPE_STATIC(LIB, SRV6_LOCATOR_CHUNK, "SRV6 locator chunk"); + const char *seg6local_action2str(uint32_t action) { switch (action) { @@ -117,3 +121,84 @@ const char *seg6local_context2str(char *str, size_t size, return str; } } + +struct srv6_locator *srv6_locator_alloc(const char *name) +{ + struct srv6_locator *locator = NULL; + + locator = XCALLOC(MTYPE_SRV6_LOCATOR, sizeof(struct srv6_locator)); + strlcpy(locator->name, name, sizeof(locator->name)); + locator->chunks = list_new(); + QOBJ_REG(locator, srv6_locator); + return locator; +} + +struct srv6_locator_chunk *srv6_locator_chunk_alloc(void) +{ + struct srv6_locator_chunk *chunk = NULL; + + chunk = XCALLOC(MTYPE_SRV6_LOCATOR_CHUNK, + sizeof(struct srv6_locator_chunk)); + return chunk; +} + +void srv6_locator_free(struct srv6_locator *locator) +{ + XFREE(MTYPE_SRV6_LOCATOR, locator); +} + +void srv6_locator_chunk_free(struct srv6_locator_chunk *chunk) +{ + XFREE(MTYPE_SRV6_LOCATOR_CHUNK, chunk); +} + +json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk) +{ + char str[256]; + json_object *jo_root = NULL; + + jo_root = json_object_new_object(); + prefix2str(&chunk->prefix, str, sizeof(str)); + json_object_string_add(jo_root, "prefix", str); + json_object_string_add(jo_root, "proto", + zebra_route_string(chunk->proto)); + + return jo_root; +} + +json_object *srv6_locator_json(const struct srv6_locator *loc) +{ + char str[256]; + struct listnode *node; + struct srv6_locator_chunk *chunk; + json_object *jo_root = NULL; + json_object *jo_chunk = NULL; + json_object *jo_chunks = NULL; + + jo_root = json_object_new_object(); + + /* set name */ + json_object_string_add(jo_root, "name", loc->name); + + /* set prefix */ + prefix2str(&loc->prefix, str, sizeof(str)); + json_object_string_add(jo_root, "prefix", str); + + /* set function_bits_length */ + json_object_int_add(jo_root, "function_bits_length", + loc->function_bits_length); + + /* set status_up */ + json_object_boolean_add(jo_root, "status_up", + loc->status_up); + + /* set chunks */ + jo_chunks = json_object_new_array(); + json_object_object_add(jo_root, "chunks", jo_chunks); + for (ALL_LIST_ELEMENTS_RO((struct list *)loc->chunks, node, chunk)) { + jo_chunk = srv6_locator_chunk_json(chunk); + json_object_array_add(jo_chunks, jo_chunk); + } + + return jo_root; +} diff --git a/lib/srv6.h b/lib/srv6.h index b72b098c78..46ff830e7f 100644 --- a/lib/srv6.h +++ b/lib/srv6.h @@ -21,10 +21,14 @@ #define _FRR_SRV6_H #include +#include "prefix.h" +#include "json.h" + #include #include #define SRV6_MAX_SIDS 16 +#define SRV6_LOCNAME_SIZE 256 #ifdef __cplusplus extern "C" { @@ -69,6 +73,27 @@ struct seg6local_context { uint32_t table; }; +struct srv6_locator { + char name[SRV6_LOCNAME_SIZE]; + struct prefix_ipv6 prefix; + uint8_t function_bits_length; + int algonum; + uint64_t current; + bool status_up; + struct list *chunks; + + QOBJ_FIELDS; +}; +DECLARE_QOBJ_TYPE(srv6_locator); + +struct srv6_locator_chunk { + uint8_t keep; + uint8_t proto; + uint16_t instance; + uint32_t session_id; + struct prefix_ipv6 prefix; +}; + static inline const char *seg6_mode2str(enum seg6_mode_t mode) { switch (mode) { @@ -126,6 +151,13 @@ const char *seg6local_context2str(char *str, size_t size, int snprintf_seg6_segs(char *str, size_t size, const struct seg6_segs *segs); +extern struct srv6_locator *srv6_locator_alloc(const char *name); +extern struct srv6_locator_chunk *srv6_locator_chunk_alloc(void); +extern void srv6_locator_free(struct srv6_locator *locator); +extern void srv6_locator_chunk_free(struct srv6_locator_chunk *chunk); +json_object *srv6_locator_chunk_json(const struct srv6_locator_chunk *chunk); +json_object *srv6_locator_json(const struct srv6_locator *loc); + #ifdef __cplusplus } #endif diff --git a/lib/zclient.c b/lib/zclient.c index bf67392cbe..c8bb720591 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -41,6 +41,7 @@ #include "lib_errors.h" #include "srte.h" #include "printfrr.h" +#include "srv6.h" DEFINE_MTYPE_STATIC(LIB, ZCLIENT, "Zclient"); DEFINE_MTYPE_STATIC(LIB, REDIST_INST, "Redistribution instance IDs"); @@ -2637,6 +2638,174 @@ stream_failure: return -1; } +/** + * Connect to srv6 manager in a syncronous way + * + * It first writes the request to zcient output buffer and then + * immediately reads the answer from the input buffer. + * + * @param zclient Zclient used to connect to srv6 manager (zebra) + * @result Result of response + */ +int srv6_manager_connect(struct zclient *zclient) +{ + struct stream *s; + int ret, result = 0; + uint16_t cmd = ZEBRA_SRV6_MANAGER_CONNECT; + + if (zclient_debug) + zlog_debug("Connecting to SRv6 Manager"); + + if (zclient->sock < 0) { + zlog_debug("%s: invalid zclient socket", __func__); + return -1; + } + + /* send request */ + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, cmd, VRF_DEFAULT); + + stream_putc(s, zclient->redist_default); /* proto */ + stream_putw(s, zclient->instance); /* instance */ + stream_putw_at(s, 0, stream_get_endp(s)); + ret = writen(zclient->sock, s->data, stream_get_endp(s)); + if (ret < 0) { + flog_err(EC_LIB_ZAPI_SOCKET, "Can't write to zclient sock"); + close(zclient->sock); + zclient->sock = -1; + return -1; + } + if (ret == 0) { + flog_err(EC_LIB_ZAPI_SOCKET, "Zclient sock closed"); + close(zclient->sock); + zclient->sock = -1; + return -1; + } + if (zclient_debug) + zlog_debug("SRv6 Manager connect request sent (%d bytes)", ret); + + /* read response */ + if (zclient_read_sync_response(zclient, cmd) + != 0) + return -1; + + s = zclient->ibuf; + + /* read instance and proto */ + uint8_t proto; + uint16_t instance; + + STREAM_GETC(s, proto); + STREAM_GETW(s, instance); + + /* sanity */ + if (proto != zclient->redist_default) + flog_err( + EC_LIB_ZAPI_ENCODE, + "Wrong proto (%u) in SRv6 Manager connect response. Should be %u", + proto, zclient->redist_default); + if (instance != zclient->instance) + flog_err( + EC_LIB_ZAPI_ENCODE, + "Wrong instId (%u) in SRv6 Manager connect response. Should be %u", + instance, zclient->instance); + + /* result code */ + STREAM_GETC(s, result); + if (zclient_debug) + zlog_debug("SRv6 Manager connect-response received, result %u", result); + + return (int)result; + +stream_failure: + return -1; +} + +/** + * Function to request a srv6-locator chunk in an Asyncronous way + * + * It first writes the request to zclient output buffer and then + * immediately reads the answer from the input buffer. + * + * @param zclient Zclient used to connect to table manager (zebra) + * @param locator_name Name of SRv6-locator + * @result 0 on success, -1 otherwise + */ +int srv6_manager_get_locator_chunk(struct zclient *zclient, + const char *locator_name) +{ + struct stream *s; + const size_t len = strlen(locator_name); + + if (zclient_debug) + zlog_debug("Getting SRv6-Locator Chunk %s", locator_name); + + if (zclient->sock < 0) + return -1; + + /* send request */ + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, VRF_DEFAULT); + + /* proto */ + stream_putc(s, zclient->redist_default); + + /* instance */ + stream_putw(s, zclient->instance); + + /* locator_name */ + stream_putw(s, len); + stream_put(s, locator_name, len); + + /* Put length at the first point of the stream. */ + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + +/** + * Function to release a srv6-locator chunk + * + * @param zclient Zclient used to connect to table manager (zebra) + * @param locator_name Name of SRv6-locator + * @result 0 on success, -1 otherwise + */ +int srv6_manager_release_locator_chunk(struct zclient *zclient, + const char *locator_name) +{ + struct stream *s; + const size_t len = strlen(locator_name); + + if (zclient_debug) + zlog_debug("Releasing SRv6-Locator Chunk %s", locator_name); + + if (zclient->sock < 0) + return -1; + + /* send request */ + s = zclient->obuf; + stream_reset(s); + zclient_create_header(s, ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK, + VRF_DEFAULT); + + /* proto */ + stream_putc(s, zclient->redist_default); + + /* instance */ + stream_putw(s, zclient->instance); + + /* locator_name */ + stream_putw(s, len); + stream_put(s, locator_name, len); + + /* Put length at the first point of the stream. */ + stream_putw_at(s, 0, stream_get_endp(s)); + + return zclient_send_message(zclient); +} + /* * Asynchronous label chunk request * @@ -3927,6 +4096,21 @@ static int zclient_read(struct thread *thread) case ZEBRA_MLAG_FORWARD_MSG: zclient_mlag_handle_msg(command, zclient, length, vrf_id); break; + case ZEBRA_SRV6_LOCATOR_ADD: + if (zclient->srv6_locator_add) + (*zclient->srv6_locator_add)(command, zclient, length, + vrf_id); + break; + case ZEBRA_SRV6_LOCATOR_DELETE: + if (zclient->srv6_locator_delete) + (*zclient->srv6_locator_delete)(command, zclient, + length, vrf_id); + break; + case ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK: + if (zclient->process_srv6_locator_chunk) + (*zclient->process_srv6_locator_chunk)(command, zclient, + length, vrf_id); + break; case ZEBRA_ERROR: zclient_handle_error(command, zclient, length, vrf_id); break; diff --git a/lib/zclient.h b/lib/zclient.h index 3f5225f097..6496e79c89 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -39,6 +39,7 @@ #include "mlag.h" #include "srte.h" +#include "srv6.h" #ifdef __cplusplus extern "C" { @@ -216,6 +217,11 @@ typedef enum { ZEBRA_NHG_NOTIFY_OWNER, ZEBRA_EVPN_REMOTE_NH_ADD, ZEBRA_EVPN_REMOTE_NH_DEL, + ZEBRA_SRV6_LOCATOR_ADD, + ZEBRA_SRV6_LOCATOR_DELETE, + ZEBRA_SRV6_MANAGER_CONNECT, + ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, + ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK, ZEBRA_ERROR, ZEBRA_CLIENT_CAPABILITIES, ZEBRA_OPAQUE_MESSAGE, @@ -387,6 +393,11 @@ struct zclient { int (*mlag_process_down)(void); int (*mlag_handle_msg)(struct stream *msg, int len); int (*nhg_notify_owner)(ZAPI_CALLBACK_ARGS); + int (*srv6_locator_add)(ZAPI_CALLBACK_ARGS); + int (*srv6_locator_delete)(ZAPI_CALLBACK_ARGS); + int (*srv6_function_add)(ZAPI_CALLBACK_ARGS); + int (*srv6_function_delete)(ZAPI_CALLBACK_ARGS); + void (*process_srv6_locator_chunk)(ZAPI_CALLBACK_ARGS); int (*handle_error)(enum zebra_error_types error); int (*opaque_msg_handler)(ZAPI_CALLBACK_ARGS); int (*opaque_register_handler)(ZAPI_CALLBACK_ARGS); @@ -1051,6 +1062,11 @@ extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, uint32_t *start, uint32_t *end); extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start, uint32_t end); +extern int srv6_manager_connect(struct zclient *zclient); +extern int srv6_manager_get_locator_chunk(struct zclient *zclient, + const char *locator_name); +extern int srv6_manager_release_locator_chunk(struct zclient *zclient, + const char *locator_name); extern enum zclient_send_status zebra_send_sr_policy(struct zclient *zclient, int cmd, -- cgit v1.2.3 From 2aa01034f3c437e076cf12f1ea4e4b7b5b6b9075 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Thu, 17 Dec 2020 22:45:58 +0900 Subject: lib: add new nexthop's attributes seg6 (step3) This commit add new nexthop's addional object for SRv6 routing about seg6 route. Before this commit, we can add MPLS info as additional object on nexthop. This commit make it add more support about seg6 routes. seg6 routes are ones of the LWT routing mechanism, so configuration of seg6local routes is performed by ZEBRA_ROUTE_SEND, it's same as MPLS configuration. Real configuration implementation isn't implemented at this commit. later commit add that. This commit add only nexthop additional object and some misc functions. Signed-off-by: Hiroki Shirokura --- lib/nexthop.c | 44 ++++++++++++++++++++++++++++++++++++++++++++ lib/nexthop.h | 5 +++++ lib/zclient.c | 27 +++++++++++++++++++++++++++ lib/zclient.h | 3 +++ 4 files changed, 79 insertions(+) (limited to 'lib/zclient.c') diff --git a/lib/nexthop.c b/lib/nexthop.c index 3c36dbf69a..d0cc5dc258 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -37,6 +37,7 @@ DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop"); DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label"); DEFINE_MTYPE_STATIC(LIB, NH_SEG6LOCAL, "Nexthop seg6local"); +DEFINE_MTYPE_STATIC(LIB, NH_SEG6, "Nexthop seg6"); static int _nexthop_labels_cmp(const struct nexthop *nh1, const struct nexthop *nh2) @@ -89,6 +90,22 @@ static int _nexthop_seg6local_cmp(const struct nexthop *nh1, sizeof(struct seg6local_context)); } +static int _nexthop_seg6_cmp(const struct nexthop *nh1, + const struct nexthop *nh2) +{ + if (!nh1->nh_seg6_segs && !nh2->nh_seg6_segs) + return 0; + + if (nh1->nh_seg6_segs && !nh2->nh_seg6_segs) + return 1; + + if (!nh1->nh_seg6_segs && nh2->nh_seg6_segs) + return -1; + + return memcmp(nh1->nh_seg6_segs, nh2->nh_seg6_segs, + sizeof(struct in6_addr)); +} + int nexthop_g_addr_cmp(enum nexthop_types_t type, const union g_addr *addr1, const union g_addr *addr2) { @@ -226,6 +243,10 @@ int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2) return ret; ret = _nexthop_seg6local_cmp(next1, next2); + if (ret != 0) + return ret; + + ret = _nexthop_seg6_cmp(next1, next2); return ret; } @@ -381,6 +402,7 @@ void nexthop_free(struct nexthop *nexthop) { nexthop_del_labels(nexthop); nexthop_del_seg6local(nexthop); + nexthop_del_seg6(nexthop); if (nexthop->resolved) nexthops_free(nexthop->resolved); XFREE(MTYPE_NEXTHOP, nexthop); @@ -572,6 +594,21 @@ void nexthop_del_seg6local(struct nexthop *nexthop) nexthop->nh_seg6local_action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; } +void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr *segs) +{ + struct in6_addr *nh_segs; + + nh_segs = XCALLOC(MTYPE_NH_SEG6, sizeof(struct in6_addr)); + if (segs) + *nh_segs = *segs; + nexthop->nh_seg6_segs = nh_segs; +} + +void nexthop_del_seg6(struct nexthop *nexthop) +{ + XFREE(MTYPE_NH_SEG6, nexthop->nh_seg6_segs); +} + const char *nexthop2str(const struct nexthop *nexthop, char *str, int size) { switch (nexthop->type) { @@ -723,6 +760,10 @@ uint32_t nexthop_hash_quick(const struct nexthop *nexthop) sizeof(nexthop->nh_seg6local_ctx), key); } + if (nexthop->nh_seg6_segs) + key = jhash(nexthop->nh_seg6_segs, + sizeof(nexthop->nh_seg6_segs), key); + return key; } @@ -779,6 +820,9 @@ void nexthop_copy_no_recurse(struct nexthop *copy, if (nexthop->nh_seg6local_ctx) nexthop_add_seg6local(copy, nexthop->nh_seg6local_action, nexthop->nh_seg6local_ctx); + + if (nexthop->nh_seg6_segs) + nexthop_add_seg6(copy, nexthop->nh_seg6_segs); } void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop, diff --git a/lib/nexthop.h b/lib/nexthop.h index 7bddee8713..8c52631af1 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -144,6 +144,9 @@ struct nexthop { /* SRv6 localsid info for Endpoint-behaviour */ enum seg6local_action_t nh_seg6local_action; struct seg6local_context *nh_seg6local_ctx; + + /* SRv6 Headend-behaviour */ + struct in6_addr *nh_seg6_segs; }; /* Utility to append one nexthop to another. */ @@ -165,6 +168,8 @@ void nexthop_del_labels(struct nexthop *); void nexthop_add_seg6local(struct nexthop *nexthop, uint32_t action, const struct seg6local_context *ctx); void nexthop_del_seg6local(struct nexthop *nexthop); +void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr* segs); +void nexthop_del_seg6(struct nexthop *nexthop); /* * Allocate a new nexthop object and initialize it from various args. diff --git a/lib/zclient.c b/lib/zclient.c index c8bb720591..8520fd769d 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -810,6 +810,13 @@ static int zapi_nexthop_seg6local_cmp(const struct zapi_nexthop *next1, sizeof(struct seg6local_context)); } +static int zapi_nexthop_seg6_cmp(const struct zapi_nexthop *next1, + const struct zapi_nexthop *next2) +{ + return memcmp(&next1->seg6_segs, &next2->seg6_segs, + sizeof(struct in6_addr)); +} + static int zapi_nexthop_cmp_no_labels(const struct zapi_nexthop *next1, const struct zapi_nexthop *next2) { @@ -914,6 +921,10 @@ static int zapi_nexthop_cmp(const void *item1, const void *item2) return ret; ret = zapi_nexthop_seg6local_cmp(next1, next2); + if (ret != 0) + return ret; + + ret = zapi_nexthop_seg6_cmp(next1, next2); return ret; } @@ -1016,6 +1027,10 @@ int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, sizeof(struct seg6local_context)); } + if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6_ROUTE)) + stream_write(s, &api_nh->seg6_segs, + sizeof(struct in6_addr)); + done: return ret; } @@ -1303,6 +1318,10 @@ int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh, sizeof(struct seg6local_context)); } + if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6_ROUTE)) + STREAM_GET(&api_nh->seg6_segs, s, + sizeof(struct in6_addr)); + /* Success */ ret = 0; @@ -1645,6 +1664,7 @@ stream_failure: struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) { + uint8_t zero[16] = {0}; struct nexthop *n = nexthop_new(); n->type = znh->type; @@ -1671,6 +1691,9 @@ struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) nexthop_add_seg6local(n, znh->seg6local_action, &znh->seg6local_ctx); + if (memcmp(&znh->seg6_segs, zero, sizeof(struct in6_addr)) != 0) + nexthop_add_seg6(n, &znh->seg6_segs); + return n; } @@ -1721,6 +1744,10 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, sizeof(struct seg6local_context)); } + if (nh->nh_seg6_segs != NULL) + memcpy(&znh->seg6_segs, nh->nh_seg6_segs, + sizeof(struct in6_addr)); + return 0; } diff --git a/lib/zclient.h b/lib/zclient.h index 6496e79c89..95f3775d5b 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -474,6 +474,9 @@ struct zapi_nexthop { /* SRv6 localsid info for Endpoint-behaviour */ uint32_t seg6local_action; struct seg6local_context seg6local_ctx; + + /* SRv6 Headend-behaviour */ + struct in6_addr seg6_segs; }; /* -- cgit v1.2.3 From 4df9d8592b1631e6cb50e291cab1ff7486467a3d Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Wed, 24 Feb 2021 10:47:05 +0000 Subject: *: fix code format accourding to checkpatch Signed-off-by: Hiroki Shirokura --- lib/nexthop.h | 2 +- lib/zclient.c | 6 ++++-- sharpd/sharp_vty.c | 4 +++- sharpd/sharp_zebra.c | 19 ++++++++++-------- sharpd/sharp_zebra.h | 6 +++++- zebra/rt_netlink.c | 13 ++++++------ zebra/zapi_msg.h | 3 +-- zebra/zebra_srv6.c | 7 ++++--- zebra/zebra_srv6.h | 3 ++- zebra/zebra_srv6_vty.c | 54 +++++++++++++++++++++++++++++--------------------- 10 files changed, 69 insertions(+), 48 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/nexthop.h b/lib/nexthop.h index 8c52631af1..c9af1ff478 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -168,7 +168,7 @@ void nexthop_del_labels(struct nexthop *); void nexthop_add_seg6local(struct nexthop *nexthop, uint32_t action, const struct seg6local_context *ctx); void nexthop_del_seg6local(struct nexthop *nexthop); -void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr* segs); +void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr *segs); void nexthop_del_seg6(struct nexthop *nexthop); /* diff --git a/lib/zclient.c b/lib/zclient.c index 8520fd769d..7eb365c305 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2774,7 +2774,8 @@ int srv6_manager_get_locator_chunk(struct zclient *zclient, /* send request */ s = zclient->obuf; stream_reset(s); - zclient_create_header(s, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, VRF_DEFAULT); + zclient_create_header(s, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, + VRF_DEFAULT); /* proto */ stream_putc(s, zclient->redist_default); @@ -3580,7 +3581,8 @@ enum zclient_send_status zclient_send_mlag_register(struct zclient *client, enum zclient_send_status zclient_send_mlag_deregister(struct zclient *client) { - return zebra_message_send(client, ZEBRA_MLAG_CLIENT_UNREGISTER, VRF_DEFAULT); + return zebra_message_send(client, ZEBRA_MLAG_CLIENT_UNREGISTER, + VRF_DEFAULT); } enum zclient_send_status zclient_send_mlag_data(struct zclient *client, diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 5997e5e312..58f6e3fe95 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -318,6 +318,7 @@ DEFPY (install_routes, } else if (seg6l_oif) { struct seg6local_context ctx; enum seg6local_action_t action; + memset(&ctx, 0, sizeof(struct seg6local_context)); if (seg6l_enddx4) { action = ZEBRA_SEG6_LOCAL_ACTION_END_DX4; @@ -1047,7 +1048,8 @@ void sharp_vty_init(void) install_element(ENABLE_NODE, &show_sharp_ted_cmd); install_element(ENABLE_NODE, &sharp_srv6_manager_get_locator_chunk_cmd); - install_element(ENABLE_NODE, &sharp_srv6_manager_release_locator_chunk_cmd); + install_element(ENABLE_NODE, + &sharp_srv6_manager_release_locator_chunk_cmd); install_element(ENABLE_NODE, &show_sharp_segment_routing_srv6_cmd); return; diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 7c24ae380f..ae4add6a60 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -338,7 +338,8 @@ 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 flags, char *opaque) + uint32_t routes, uint32_t flags, + char *opaque) { uint32_t temp, i; bool v4 = false; @@ -924,7 +925,7 @@ static int nhg_notify_owner(ZAPI_CALLBACK_ARGS) return 0; } -int sharp_zebra_srv6_manager_get_locator_chunk(const char* locator_name) +int sharp_zebra_srv6_manager_get_locator_chunk(const char *locator_name) { return srv6_manager_get_locator_chunk(zclient, locator_name); } @@ -942,6 +943,7 @@ static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) uint16_t len; char name[256] = {0}; struct prefix_ipv6 *chunk = NULL; + chunk = prefix_ipv6_new(); s = zclient->ibuf; @@ -965,16 +967,17 @@ static void sharp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) struct listnode *loc_node; struct sharp_srv6_locator *loc; + for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) { + struct listnode *chunk_node; + struct prefix_ipv6 *c; + if (strcmp(loc->name, name)) continue; - struct listnode *chunk_node; - struct prefix_ipv6 *c; - for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c)) { + for (ALL_LIST_ELEMENTS_RO(loc->chunks, chunk_node, c)) if (!prefix_cmp(c, chunk)) return; - } listnode_add(loc->chunks, chunk); } return; @@ -983,7 +986,6 @@ stream_failure: free(chunk); zlog_err("%s: can't get locator_chunk!!", __func__); - return; } void sharp_zebra_init(void) @@ -1007,5 +1009,6 @@ void sharp_zebra_init(void) zclient->redistribute_route_add = sharp_redistribute_route; zclient->redistribute_route_del = sharp_redistribute_route; zclient->opaque_msg_handler = sharp_opaque_handler; - zclient->process_srv6_locator_chunk = sharp_zebra_process_srv6_locator_chunk; + zclient->process_srv6_locator_chunk = + sharp_zebra_process_srv6_locator_chunk; } diff --git a/sharpd/sharp_zebra.h b/sharpd/sharp_zebra.h index 043a7405c2..45e26a9b3d 100644 --- a/sharpd/sharp_zebra.h +++ b/sharpd/sharp_zebra.h @@ -39,7 +39,8 @@ 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 flags, char *opaque); + uint32_t routes, uint32_t flags, + char *opaque); extern void sharp_remove_routes_helper(struct prefix *p, vrf_id_t vrf_id, uint8_t instance, uint32_t routes); @@ -67,6 +68,9 @@ extern void sharp_redistribute_vrf(struct vrf *vrf, int source); extern int sharp_zebra_srv6_manager_get_locator_chunk(const char* locator_name); extern int sharp_zebra_srv6_manager_release_locator_chunk(const char *locator_name); +extern int sharp_zebra_srv6_manager_get_locator_chunk(const char *locator_name); +extern int sharp_zebra_srv6_manager_release_locator_chunk( + const char *locator_name); extern void sharp_install_seg6local_route_helper(struct prefix *p, uint8_t instance, enum seg6local_action_t act, diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index 705a035de5..f5ce4e795b 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -474,7 +474,7 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, mpls_label_t labels[MPLS_MAX_LABELS] = {0}; int num_labels = 0; enum seg6local_action_t seg6l_act = SEG6_LOCAL_ACTION_UNSPEC; - struct seg6local_context seg6l_ctx = {{0}}; + struct seg6local_context seg6l_ctx = { {0} }; struct in6_addr seg6_segs = {0}; int num_segs = 0; @@ -556,7 +556,7 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, mpls_label_t labels[MPLS_MAX_LABELS] = {0}; int num_labels = 0; enum seg6local_action_t seg6l_act = SEG6_LOCAL_ACTION_UNSPEC; - struct seg6local_context seg6l_ctx = {{0}}; + struct seg6local_context seg6l_ctx = { {0} }; struct in6_addr seg6_segs = {0}; int num_segs = 0; struct rtattr *rtnh_tb[RTA_MAX + 1] = {}; @@ -1336,6 +1336,7 @@ static size_t fill_seg6ipt_encap(char *buffer, size_t buflen, struct seg6_iptunnel_encap *ipt; struct ipv6_sr_hdr *srh; const size_t srhlen = 24; + memset(buffer, 0, buflen); ipt = (struct seg6_iptunnel_encap *)buffer; @@ -2479,16 +2480,16 @@ ssize_t netlink_nexthop_msg_encode(uint16_t cmd, break; case SEG6_LOCAL_ACTION_END_DX4: nl_attr_put32(&req->n, buflen, - SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END_DX4); + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END_DX4); nl_attr_put(&req->n, buflen, SEG6_LOCAL_NH4, &ctx->nh4, sizeof(struct in_addr)); break; case SEG6_LOCAL_ACTION_END_DT6: nl_attr_put32(&req->n, buflen, - SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END_DT6); + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END_DT6); nl_attr_put32(&req->n, buflen, SEG6_LOCAL_TABLE, ctx->table); diff --git a/zebra/zapi_msg.h b/zebra/zapi_msg.h index 35bb554121..e991dca4f3 100644 --- a/zebra/zapi_msg.h +++ b/zebra/zapi_msg.h @@ -122,8 +122,7 @@ extern int zsend_zebra_srv6_locator_add(struct zserv *client, extern int zsend_zebra_srv6_locator_delete(struct zserv *client, struct srv6_locator *loc); extern int zsend_srv6_manager_get_locator_chunk_response(struct zserv *client, - vrf_id_t vrf_id, - struct srv6_locator *loc); + vrf_id_t vrf_id, struct srv6_locator *loc); #ifdef __cplusplus } diff --git a/zebra/zebra_srv6.c b/zebra/zebra_srv6.c index b4b691e8e0..1e12117ac4 100644 --- a/zebra/zebra_srv6.c +++ b/zebra/zebra_srv6.c @@ -115,6 +115,7 @@ void zebra_srv6_locator_add(struct srv6_locator *locator) void zebra_srv6_locator_delete(struct srv6_locator *locator) { struct zebra_srv6 *srv6 = zebra_srv6_get_default(); + listnode_delete(srv6->locators, locator); } @@ -206,6 +207,8 @@ static int zebra_srv6_manager_get_locator_chunk(struct srv6_locator **loc, const char *locator_name, vrf_id_t vrf_id) { + int ret = 0; + *loc = assign_srv6_locator_chunk(client->proto, client->instance, client->session_id, locator_name); @@ -217,7 +220,6 @@ static int zebra_srv6_manager_get_locator_chunk(struct srv6_locator **loc, (*loc)->name, zebra_route_string(client->proto), client->instance); - int ret = 0; if ((*loc)->status_up) ret = zsend_srv6_manager_get_locator_chunk_response(client, vrf_id, @@ -244,9 +246,8 @@ static int release_srv6_locator_chunk(uint8_t proto, uint16_t instance, struct srv6_locator *loc = NULL; loc = zebra_srv6_locator_lookup(locator_name); - if (!loc) { + if (!loc) return -1; - } if (IS_ZEBRA_DEBUG_PACKET) zlog_debug("%s: Releasing srv6-locator on %s", __func__, diff --git a/zebra/zebra_srv6.h b/zebra/zebra_srv6.h index 751cee6e70..84fcc305bc 100644 --- a/zebra/zebra_srv6.h +++ b/zebra/zebra_srv6.h @@ -65,7 +65,8 @@ extern void zebra_srv6_init(void); extern struct zebra_srv6 *zebra_srv6_get_default(void); extern bool zebra_srv6_is_enable(void); -extern void srv6_manager_client_connect_call(struct zserv *client, vrf_id_t vrf_id); +extern void srv6_manager_client_connect_call(struct zserv *client, + vrf_id_t vrf_id); extern void srv6_manager_get_locator_chunk_call(struct srv6_locator **loc, struct zserv *client, const char *locator_name, diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index 73038fad73..e2685141bb 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -147,30 +147,31 @@ DEFUN (show_srv6_locator_detail, if (uj) { vty_out(vty, "JSON format isn't supported\n"); return CMD_WARNING; - } else { - for (ALL_LIST_ELEMENTS_RO(srv6->locators, node, locator)) { - if (strcmp(locator->name, locator_name) != 0) { - continue; - } + } - prefix2str(&locator->prefix, str, sizeof(str)); - vty_out(vty, "Name: %s\n", locator->name); - vty_out(vty, "Prefix: %s\n", str); - vty_out(vty, "Function-Bit-Len: %u\n", - locator->function_bits_length); - - vty_out(vty, "Chunks:\n"); - struct listnode *node; - struct srv6_locator_chunk *chunk; - for (ALL_LIST_ELEMENTS_RO((struct list *)locator->chunks, node, chunk)) { - prefix2str(&chunk->prefix, str, sizeof(str)); - vty_out(vty, "- prefix: %s, owner: %s\n", str, - zebra_route_string(chunk->proto)); - } + for (ALL_LIST_ELEMENTS_RO(srv6->locators, node, locator)) { + struct listnode *node; + struct srv6_locator_chunk *chunk; + + if (strcmp(locator->name, locator_name) != 0) + continue; + + prefix2str(&locator->prefix, str, sizeof(str)); + vty_out(vty, "Name: %s\n", locator->name); + vty_out(vty, "Prefix: %s\n", str); + vty_out(vty, "Function-Bit-Len: %u\n", + locator->function_bits_length); + + vty_out(vty, "Chunks:\n"); + for (ALL_LIST_ELEMENTS_RO((struct list *)locator->chunks, node, + chunk)) { + prefix2str(&chunk->prefix, str, sizeof(str)); + vty_out(vty, "- prefix: %s, owner: %s\n", str, + zebra_route_string(chunk->proto)); } - } + return CMD_SUCCESS; } @@ -264,16 +265,23 @@ DEFUN (locator_prefix, } else { for (ALL_LIST_ELEMENTS_RO(locator->chunks, node, chunk)) { uint8_t zero[16] = {0}; + if (memcmp(&chunk->prefix.prefix, zero, 16) == 0) { struct zserv *client; struct listnode *client_node; + chunk->prefix = prefix; - for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, client_node, client)) { + for (ALL_LIST_ELEMENTS_RO(zrouter.client_list, + client_node, + client)) { + struct srv6_locator *tmp; + if (client->proto != chunk->proto) continue; - struct srv6_locator *tmp; srv6_manager_get_locator_chunk_call( - &tmp, client, locator->name, VRF_DEFAULT); + &tmp, client, + locator->name, + VRF_DEFAULT); } } } -- cgit v1.2.3 From 618538f8ab65eeee12323a460336dffb08cd36e8 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Sat, 19 Dec 2020 09:28:38 +0900 Subject: lib: add usual func to install SRv6 localsid (step4) This commit add usuful function to configure SRv6 localsid which is represented with seg6local lwt route. Now, it can support only NEXTHOP_TYPE_IFINDEX route. Actual configurationof SRv6 localsid is performed with ZEBRA_ROUTE_ADD. So this is just a wrapper function for route-install. Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 39 +++++++++++++++++++++++++++++++++++++++ lib/zclient.h | 5 +++++ 2 files changed, 44 insertions(+) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 7eb365c305..1acf7f20d5 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -436,6 +436,45 @@ enum zclient_send_status zclient_send_vrf_label(struct zclient *zclient, return zclient_send_message(zclient); } +enum zclient_send_status zclient_send_localsid(struct zclient *zclient, + const struct in6_addr *sid, ifindex_t oif, + enum seg6local_action_t action, + const struct seg6local_context *context) +{ + struct prefix_ipv6 p; + struct zapi_route api; + struct nexthop nh; + + memset(&p, 0, sizeof(p)); + p.family = AF_INET6; + p.prefixlen = 128; + p.prefix = *sid; + + memset(&api, 0, sizeof(api)); + api.vrf_id = VRF_DEFAULT; + api.type = ZEBRA_ROUTE_BGP; + api.instance = 0; + api.safi = SAFI_UNICAST; + memcpy(&api.prefix, &p, sizeof(p)); + + if (action == ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) + return zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); + + SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); + SET_FLAG(api.flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE); + SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); + + memset(&nh, 0, sizeof(nh)); + nh.type = NEXTHOP_TYPE_IFINDEX; + nh.ifindex = oif; + nexthop_add_seg6local(&nh, action, context); + + zapi_nexthop_from_nexthop(&api.nexthops[0], &nh); + api.nexthop_num = 1; + + return zclient_route_send(ZEBRA_ROUTE_ADD, zclient, &api); +} + /* Send register requests to zebra daemon for the information in a VRF. */ void zclient_send_reg_requests(struct zclient *zclient, vrf_id_t vrf_id) { diff --git a/lib/zclient.h b/lib/zclient.h index 95f3775d5b..e06079673a 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -933,6 +933,11 @@ extern enum zclient_send_status zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, afi_t afi, mpls_label_t label, enum lsp_types_t ltype); +extern enum zclient_send_status +zclient_send_localsid(struct zclient *zclient, const struct in6_addr *sid, + ifindex_t oif, enum seg6local_action_t action, + const struct seg6local_context *context); + extern void zclient_send_reg_requests(struct zclient *, vrf_id_t); extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t); extern enum zclient_send_status -- cgit v1.2.3 From ac6a9479af182fad4810fe6d21abc73f39c751f9 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Thu, 31 Dec 2020 11:56:32 +0000 Subject: zebra: add zapi_srv6_locator_chunk_{en,de}code Signed-off-by: Hiroki Shirokura --- lib/srv6.h | 25 ++++++++++++++++++++++++- lib/zclient.c | 40 ++++++++++++++++++++++++++++++++++++++++ lib/zclient.h | 5 +++++ zebra/zapi_msg.c | 29 +++++++++++++---------------- zebra/zebra_srv6_vty.c | 19 +++++++++++++++++++ 5 files changed, 101 insertions(+), 17 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/srv6.h b/lib/srv6.h index 46ff830e7f..9ac89125ce 100644 --- a/lib/srv6.h +++ b/lib/srv6.h @@ -76,7 +76,16 @@ struct seg6local_context { struct srv6_locator { char name[SRV6_LOCNAME_SIZE]; struct prefix_ipv6 prefix; + + /* + * Bit length of SRv6 locator described in + * draft-ietf-bess-srv6-services-05#section-3.2.1 + */ + uint8_t block_bits_length; + uint8_t node_bits_length; uint8_t function_bits_length; + uint8_t argument_bits_length; + int algonum; uint64_t current; bool status_up; @@ -87,11 +96,25 @@ struct srv6_locator { DECLARE_QOBJ_TYPE(srv6_locator); struct srv6_locator_chunk { + char locator_name[SRV6_LOCNAME_SIZE]; + struct prefix_ipv6 prefix; + + /* + * Bit length of SRv6 locator described in + * draft-ietf-bess-srv6-services-05#section-3.2.1 + */ + uint8_t block_bits_length; + uint8_t node_bits_length; + uint8_t function_bits_length; + uint8_t argument_bits_length; + + /* + * For Zclient communication values + */ uint8_t keep; uint8_t proto; uint16_t instance; uint32_t session_id; - struct prefix_ipv6 prefix; }; static inline const char *seg6_mode2str(enum seg6_mode_t mode) diff --git a/lib/zclient.c b/lib/zclient.c index 1acf7f20d5..f6b97a768f 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -1074,6 +1074,46 @@ done: return ret; } +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); + stream_put(s, &c->prefix.prefix, sizeof(c->prefix.prefix)); + stream_putc(s, c->block_bits_length); + stream_putc(s, c->node_bits_length); + stream_putc(s, c->function_bits_length); + stream_putc(s, c->argument_bits_length); + return 0; +} + +int zapi_srv6_locator_chunk_decode(struct stream *s, + struct srv6_locator_chunk *c) +{ + uint16_t len = 0; + + STREAM_GETC(s, c->proto); + STREAM_GETW(s, c->instance); + STREAM_GETW(s, len); + if (len > SRV6_LOCNAME_SIZE) + goto stream_failure; + + STREAM_GET(c->locator_name, s, len); + STREAM_GETW(s, c->prefix.prefixlen); + STREAM_GET(&c->prefix.prefix, s, sizeof(c->prefix.prefix)); + STREAM_GETC(s, c->block_bits_length); + STREAM_GETC(s, c->node_bits_length); + STREAM_GETC(s, c->function_bits_length); + STREAM_GETC(s, c->argument_bits_length); + return 0; + +stream_failure: + return -1; +} + static int zapi_nhg_encode(struct stream *s, int cmd, struct zapi_nhg *api_nhg) { int i; diff --git a/lib/zclient.h b/lib/zclient.h index e06079673a..d9ca6a859d 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -1092,6 +1092,11 @@ extern int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl); extern int zapi_labels_decode(struct stream *s, struct zapi_labels *zl); +extern int zapi_srv6_locator_chunk_encode(struct stream *s, + const struct srv6_locator_chunk *c); +extern int zapi_srv6_locator_chunk_decode(struct stream *s, + struct srv6_locator_chunk *c); + extern enum zclient_send_status zebra_send_pw(struct zclient *zclient, int command, struct zapi_pw *pw); extern int zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 25c51e2227..46bd9d9959 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2701,26 +2701,23 @@ int zsend_srv6_manager_get_locator_chunk_response(struct zserv *client, vrf_id_t vrf_id, struct srv6_locator *loc) { + struct srv6_locator_chunk chunk; struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - zclient_create_header(s, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, vrf_id); - - /* proto */ - stream_putc(s, client->proto); - - /* instance */ - stream_putw(s, client->instance); - - if (loc) { - stream_putw(s, strlen(loc->name)); - stream_put(s, loc->name, strlen(loc->name)); - stream_putw(s, loc->prefix.prefixlen); - stream_put(s, &loc->prefix.prefix, 16); - } + memset(&chunk, 0, sizeof(chunk)); + strlcpy(chunk.locator_name, loc->name, sizeof(chunk.locator_name)); + chunk.prefix = loc->prefix; + chunk.block_bits_length = loc->block_bits_length; + chunk.node_bits_length = loc->node_bits_length; + chunk.function_bits_length = loc->function_bits_length; + chunk.argument_bits_length = loc->argument_bits_length; + chunk.keep = 0; + chunk.proto = client->proto; + chunk.instance = client->instance; - /* Write packet size. */ + zclient_create_header(s, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, vrf_id); + zapi_srv6_locator_chunk_encode(s, &chunk); stream_putw_at(s, 0, stream_get_endp(s)); - return zserv_send_message(client, s); } diff --git a/zebra/zebra_srv6_vty.c b/zebra/zebra_srv6_vty.c index 0bc48f6339..803e9f1196 100644 --- a/zebra/zebra_srv6_vty.c +++ b/zebra/zebra_srv6_vty.c @@ -246,7 +246,26 @@ DEFPY (locator_prefix, struct listnode *node = NULL; locator->prefix = *prefix; + + /* + * TODO(slankdev): please support variable node-bit-length. + * In draft-ietf-bess-srv6-services-05#section-3.2.1. + * Locator block length and Locator node length are defined. + * Which are defined as "locator-len == block-len + node-len". + * In current implementation, node bits length is hardcoded as 24. + * It should be supported various val. + * + * Cisco IOS-XR support only following pattern. + * (1) Teh locator length should be 64-bits long. + * (2) The SID block portion (MSBs) cannot exceed 40 bits. + * If this value is less than 40 bits, + * user should use a pattern of zeros as a filler. + * (3) The Node Id portion (LSBs) cannot exceed 24 bits. + */ + locator->block_bits_length = prefix->prefixlen - 24; + locator->node_bits_length = 24; locator->function_bits_length = func_bit_len; + locator->argument_bits_length = 0; if (list_isempty(locator->chunks)) { chunk = srv6_locator_chunk_alloc(); -- cgit v1.2.3 From 1bda3e627de060ece571012041965faa389c33c5 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 00:31:56 +0000 Subject: *: use one line init instead of memset and format it Signed-off-by: Hiroki Shirokura --- bgpd/bgp_mplsvpn.c | 2 +- bgpd/bgp_zebra.c | 3 +-- lib/zclient.c | 9 +++------ sharpd/sharp_vty.c | 3 +-- zebra/rt_netlink.c | 12 ++++++------ zebra/zapi_msg.c | 3 +-- 6 files changed, 13 insertions(+), 19 deletions(-) (limited to 'lib/zclient.c') diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 6162ec42a6..f99d672c8a 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -366,7 +366,7 @@ void vpn_leak_zebra_vrf_sid_update(struct bgp *bgp, afi_t afi) { int debug = BGP_DEBUG(vpn, VPN_LEAK_LABEL); enum seg6local_action_t act; - struct seg6local_context ctx = { {0} }; + struct seg6local_context ctx = {}; struct in6_addr *tovpn_sid = NULL; struct in6_addr *tovpn_sid_ls = NULL; struct vrf *vrf; diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index df6f383fb7..a10c6fd245 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -3003,11 +3003,10 @@ static void bgp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) struct bgp *bgp = bgp_get_default(); struct listnode *node; struct prefix_ipv6 *c; - struct srv6_locator_chunk s6c; + struct srv6_locator_chunk s6c = {}; struct prefix_ipv6 *chunk = NULL; s = zclient->ibuf; - memset(&s6c, 0, sizeof(s6c)); zapi_srv6_locator_chunk_decode(s, &s6c); if (zclient->redist_default != s6c.proto) { diff --git a/lib/zclient.c b/lib/zclient.c index f6b97a768f..158a20eb58 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -441,16 +441,14 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient, enum seg6local_action_t action, const struct seg6local_context *context) { - struct prefix_ipv6 p; - struct zapi_route api; - struct nexthop nh; + struct prefix_ipv6 p = {}; + struct zapi_route api = {}; + struct nexthop nh = {}; - memset(&p, 0, sizeof(p)); p.family = AF_INET6; p.prefixlen = 128; p.prefix = *sid; - memset(&api, 0, sizeof(api)); api.vrf_id = VRF_DEFAULT; api.type = ZEBRA_ROUTE_BGP; api.instance = 0; @@ -464,7 +462,6 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient, SET_FLAG(api.flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE); SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); - memset(&nh, 0, sizeof(nh)); nh.type = NEXTHOP_TYPE_IFINDEX; nh.ifindex = oif; nexthop_add_seg6local(&nh, action, context); diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 58f6e3fe95..72bc7d16b9 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -316,10 +316,9 @@ DEFPY (install_routes, sg.r.backup_nhop_group.nexthop = bnhgc->nhg.nexthop; } } else if (seg6l_oif) { - struct seg6local_context ctx; + struct seg6local_context ctx = {}; enum seg6local_action_t action; - memset(&ctx, 0, sizeof(struct seg6local_context)); if (seg6l_enddx4) { action = ZEBRA_SEG6_LOCAL_ACTION_END_DX4; ctx.nh4 = seg6l_enddx4_nh4; diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index a84c3da6ad..70db6234bb 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -419,7 +419,7 @@ static enum seg6local_action_t parse_encap_seg6local(struct rtattr *tb, struct seg6local_context *ctx) { - struct rtattr *tb_encap[256] = {0}; + struct rtattr *tb_encap[256] = {}; enum seg6local_action_t act = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; netlink_parse_rtattr_nested(tb_encap, 256, tb); @@ -443,7 +443,7 @@ parse_encap_seg6local(struct rtattr *tb, static int parse_encap_seg6(struct rtattr *tb, struct in6_addr *segs) { - struct rtattr *tb_encap[256] = {0}; + struct rtattr *tb_encap[256] = {}; struct seg6_iptunnel_encap *ipt = NULL; struct in6_addr *segments = NULL; @@ -474,8 +474,8 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, mpls_label_t labels[MPLS_MAX_LABELS] = {0}; int num_labels = 0; enum seg6local_action_t seg6l_act = SEG6_LOCAL_ACTION_UNSPEC; - struct seg6local_context seg6l_ctx = { {0} }; - struct in6_addr seg6_segs = { .s6_addr = {0} }; + struct seg6local_context seg6l_ctx = {}; + struct in6_addr seg6_segs = {}; int num_segs = 0; vrf_id_t nh_vrf_id = vrf_id; @@ -556,8 +556,8 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, mpls_label_t labels[MPLS_MAX_LABELS] = {0}; int num_labels = 0; enum seg6local_action_t seg6l_act = SEG6_LOCAL_ACTION_UNSPEC; - struct seg6local_context seg6l_ctx = { {0} }; - struct in6_addr seg6_segs = { .s6_addr = {0} }; + struct seg6local_context seg6l_ctx = {}; + struct in6_addr seg6_segs = {}; int num_segs = 0; struct rtattr *rtnh_tb[RTA_MAX + 1] = {}; diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 235c06f177..4331487b8b 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2701,10 +2701,9 @@ int zsend_srv6_manager_get_locator_chunk_response(struct zserv *client, vrf_id_t vrf_id, struct srv6_locator *loc) { - struct srv6_locator_chunk chunk; + struct srv6_locator_chunk chunk = {}; struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - memset(&chunk, 0, sizeof(chunk)); strlcpy(chunk.locator_name, loc->name, sizeof(chunk.locator_name)); chunk.prefix = loc->prefix; chunk.block_bits_length = loc->block_bits_length; -- cgit v1.2.3 From fbaa42f744b8bcf30f50a5442ecbe8028ea47d2a Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 00:52:11 +0000 Subject: lib: integrate srv6-nexthop-cmp functions I agree with the PR review from mstap and merged the following two functions into one. - zapi_nexthop_seg6_cmp - zapi_nexthop_seg6local_cmp [note] If both of them have more complex extensions in the future, I think it will be less confusing to remove the integration of these functions and make them as separate functions as before. Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 158a20eb58..27cc095f12 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -833,9 +833,16 @@ static int zapi_nexthop_labels_cmp(const struct zapi_nexthop *next1, return memcmp(next1->labels, next2->labels, next1->label_num); } -static int zapi_nexthop_seg6local_cmp(const struct zapi_nexthop *next1, - const struct zapi_nexthop *next2) +static int zapi_nexthop_srv6_cmp(const struct zapi_nexthop *next1, + const struct zapi_nexthop *next2) { + int ret = 0; + + ret = memcmp(&next1->seg6_segs, &next2->seg6_segs, + sizeof(struct in6_addr)); + if (ret != 0) + return ret; + if (next1->seg6local_action > next2->seg6local_action) return 1; @@ -846,13 +853,6 @@ static int zapi_nexthop_seg6local_cmp(const struct zapi_nexthop *next1, sizeof(struct seg6local_context)); } -static int zapi_nexthop_seg6_cmp(const struct zapi_nexthop *next1, - const struct zapi_nexthop *next2) -{ - return memcmp(&next1->seg6_segs, &next2->seg6_segs, - sizeof(struct in6_addr)); -} - static int zapi_nexthop_cmp_no_labels(const struct zapi_nexthop *next1, const struct zapi_nexthop *next2) { @@ -956,11 +956,7 @@ static int zapi_nexthop_cmp(const void *item1, const void *item2) if (ret != 0) return ret; - ret = zapi_nexthop_seg6local_cmp(next1, next2); - if (ret != 0) - return ret; - - ret = zapi_nexthop_seg6_cmp(next1, next2); + ret = zapi_nexthop_srv6_cmp(next1, next2); return ret; } -- cgit v1.2.3 From 8dcb27e6d908dc6f95b6ce2b119102bb084563c5 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 00:57:03 +0000 Subject: lib: eliminate odd line-break Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 27cc095f12..32414f34d1 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2785,8 +2785,7 @@ int srv6_manager_connect(struct zclient *zclient) zlog_debug("SRv6 Manager connect request sent (%d bytes)", ret); /* read response */ - if (zclient_read_sync_response(zclient, cmd) - != 0) + if (zclient_read_sync_response(zclient, cmd) != 0) return -1; s = zclient->ibuf; -- cgit v1.2.3 From 4c6a567d724170e742730d56daf15a49db37d714 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 01:09:16 +0000 Subject: lib: erase wrong comments by copy-paste Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 3 --- 1 file changed, 3 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 32414f34d1..270f780ed0 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2823,9 +2823,6 @@ stream_failure: /** * Function to request a srv6-locator chunk in an Asyncronous way * - * It first writes the request to zclient output buffer and then - * immediately reads the answer from the input buffer. - * * @param zclient Zclient used to connect to table manager (zebra) * @param locator_name Name of SRv6-locator * @result 0 on success, -1 otherwise -- cgit v1.2.3 From a9510347aa9126fbbca09679a170b10c63ef851c Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 01:45:33 +0000 Subject: zebra: delete unneeded zebra_srv6_manager_connect Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 83 -------------------------------------------------------- lib/zclient.h | 2 -- zebra/zapi_msg.c | 68 ---------------------------------------------- 3 files changed, 153 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index 270f780ed0..de3aed46e9 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2737,89 +2737,6 @@ stream_failure: return -1; } -/** - * Connect to srv6 manager in a syncronous way - * - * It first writes the request to zcient output buffer and then - * immediately reads the answer from the input buffer. - * - * @param zclient Zclient used to connect to srv6 manager (zebra) - * @result Result of response - */ -int srv6_manager_connect(struct zclient *zclient) -{ - struct stream *s; - int ret, result = 0; - uint16_t cmd = ZEBRA_SRV6_MANAGER_CONNECT; - - if (zclient_debug) - zlog_debug("Connecting to SRv6 Manager"); - - if (zclient->sock < 0) { - zlog_debug("%s: invalid zclient socket", __func__); - return -1; - } - - /* send request */ - s = zclient->obuf; - stream_reset(s); - zclient_create_header(s, cmd, VRF_DEFAULT); - - stream_putc(s, zclient->redist_default); /* proto */ - stream_putw(s, zclient->instance); /* instance */ - stream_putw_at(s, 0, stream_get_endp(s)); - ret = writen(zclient->sock, s->data, stream_get_endp(s)); - if (ret < 0) { - flog_err(EC_LIB_ZAPI_SOCKET, "Can't write to zclient sock"); - close(zclient->sock); - zclient->sock = -1; - return -1; - } - if (ret == 0) { - flog_err(EC_LIB_ZAPI_SOCKET, "Zclient sock closed"); - close(zclient->sock); - zclient->sock = -1; - return -1; - } - if (zclient_debug) - zlog_debug("SRv6 Manager connect request sent (%d bytes)", ret); - - /* read response */ - if (zclient_read_sync_response(zclient, cmd) != 0) - return -1; - - s = zclient->ibuf; - - /* read instance and proto */ - uint8_t proto; - uint16_t instance; - - STREAM_GETC(s, proto); - STREAM_GETW(s, instance); - - /* sanity */ - if (proto != zclient->redist_default) - flog_err( - EC_LIB_ZAPI_ENCODE, - "Wrong proto (%u) in SRv6 Manager connect response. Should be %u", - proto, zclient->redist_default); - if (instance != zclient->instance) - flog_err( - EC_LIB_ZAPI_ENCODE, - "Wrong instId (%u) in SRv6 Manager connect response. Should be %u", - instance, zclient->instance); - - /* result code */ - STREAM_GETC(s, result); - if (zclient_debug) - zlog_debug("SRv6 Manager connect-response received, result %u", result); - - return (int)result; - -stream_failure: - return -1; -} - /** * Function to request a srv6-locator chunk in an Asyncronous way * diff --git a/lib/zclient.h b/lib/zclient.h index d9ca6a859d..c41d25133d 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -219,7 +219,6 @@ typedef enum { ZEBRA_EVPN_REMOTE_NH_DEL, ZEBRA_SRV6_LOCATOR_ADD, ZEBRA_SRV6_LOCATOR_DELETE, - ZEBRA_SRV6_MANAGER_CONNECT, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK, ZEBRA_ERROR, @@ -1070,7 +1069,6 @@ extern int tm_get_table_chunk(struct zclient *zclient, uint32_t chunk_size, uint32_t *start, uint32_t *end); extern int tm_release_table_chunk(struct zclient *zclient, uint32_t start, uint32_t end); -extern int srv6_manager_connect(struct zclient *zclient); extern int srv6_manager_get_locator_chunk(struct zclient *zclient, const char *locator_name); extern int srv6_manager_release_locator_chunk(struct zclient *zclient, diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 4331487b8b..4f6663fe2b 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1137,29 +1137,6 @@ static int zsend_table_manager_connect_response(struct zserv *client, return zserv_send_message(client, s); } -static int zsend_srv6_manager_connect_response(struct zserv *client, - vrf_id_t vrf_id, - uint16_t result) -{ - struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ); - - zclient_create_header(s, ZEBRA_SRV6_MANAGER_CONNECT, vrf_id); - - /* proto */ - stream_putc(s, client->proto); - - /* instance */ - stream_putw(s, client->instance); - - /* result */ - stream_putc(s, result); - - /* Write packet size. */ - stream_putw_at(s, 0, stream_get_endp(s)); - - return zserv_send_message(client, s); -} - /* Inbound message handling ------------------------------------------------ */ const int cmd2type[] = { @@ -2656,47 +2633,6 @@ int zsend_client_close_notify(struct zserv *client, struct zserv *closed_client) return zserv_send_message(client, s); } -/* Send response to a srv6 manager connect request to client */ -static void zread_srv6_manager_connect(struct zserv *client, - struct stream *msg, vrf_id_t vrf_id) -{ - struct stream *s; - uint8_t proto; - uint16_t instance; - struct vrf *vrf = vrf_lookup_by_id(vrf_id); - - s = msg; - - /* Get data. */ - STREAM_GETC(s, proto); - STREAM_GETW(s, instance); - - /* accept only dynamic routing protocols */ - if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) { - flog_err(EC_ZEBRA_TM_WRONG_PROTO, - "client %d has wrong protocol %s", client->sock, - zebra_route_string(proto)); - zsend_srv6_manager_connect_response(client, vrf_id, 1); - return; - } - zlog_notice("client %d with vrf %s(%u) instance %u connected as %s", - client->sock, VRF_LOGNAME(vrf), vrf_id, instance, - zebra_route_string(proto)); - client->proto = proto; - client->instance = instance; - - /* - * Release previous locators of same protocol and instance. - * This is done in case it restarted from an unexpected shutdown. - */ - release_daemon_srv6_locator_chunks(client); - - zsend_srv6_manager_connect_response(client, vrf_id, 0); - -stream_failure: - return; -} - int zsend_srv6_manager_get_locator_chunk_response(struct zserv *client, vrf_id_t vrf_id, struct srv6_locator *loc) @@ -2983,9 +2919,6 @@ stream_failure: static void zread_srv6_manager_request(ZAPI_HANDLER_ARGS) { switch (hdr->command) { - case ZEBRA_SRV6_MANAGER_CONNECT: - zread_srv6_manager_connect(client, msg, zvrf_id(zvrf)); - break; case ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK: zread_srv6_manager_get_locator_chunk(client, msg, zvrf_id(zvrf)); @@ -3759,7 +3692,6 @@ void (*const zserv_handlers[])(ZAPI_HANDLER_ARGS) = { [ZEBRA_MLAG_CLIENT_REGISTER] = zebra_mlag_client_register, [ZEBRA_MLAG_CLIENT_UNREGISTER] = zebra_mlag_client_unregister, [ZEBRA_MLAG_FORWARD_MSG] = zebra_mlag_forward_client_msg, - [ZEBRA_SRV6_MANAGER_CONNECT] = zread_srv6_manager_request, [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] = zread_srv6_manager_request, [ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK] = zread_srv6_manager_request, [ZEBRA_CLIENT_CAPABILITIES] = zread_client_capabilities, -- cgit v1.2.3 From 7b778857f8340df730b1b26844a11c09eb7dc451 Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 02:24:06 +0000 Subject: zebra: drop un-needed info in locator-zapi Signed-off-by: Hiroki Shirokura --- lib/zclient.c | 12 ------------ zebra/zapi_msg.c | 12 ------------ 2 files changed, 24 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/zclient.c b/lib/zclient.c index de3aed46e9..4d8fbdf157 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2762,12 +2762,6 @@ int srv6_manager_get_locator_chunk(struct zclient *zclient, zclient_create_header(s, ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK, VRF_DEFAULT); - /* proto */ - stream_putc(s, zclient->redist_default); - - /* instance */ - stream_putw(s, zclient->instance); - /* locator_name */ stream_putw(s, len); stream_put(s, locator_name, len); @@ -2803,12 +2797,6 @@ int srv6_manager_release_locator_chunk(struct zclient *zclient, zclient_create_header(s, ZEBRA_SRV6_MANAGER_RELEASE_LOCATOR_CHUNK, VRF_DEFAULT); - /* proto */ - stream_putc(s, zclient->redist_default); - - /* instance */ - stream_putw(s, zclient->instance); - /* locator_name */ stream_putw(s, len); stream_put(s, locator_name, len); diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index 4f6663fe2b..d97d876cf5 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -2870,19 +2870,13 @@ static void zread_srv6_manager_get_locator_chunk(struct zserv *client, vrf_id_t vrf_id) { struct stream *s = msg; - uint8_t proto; - uint16_t instance; uint16_t len; char locator_name[SRV6_LOCNAME_SIZE] = {0}; /* Get data. */ - STREAM_GETC(s, proto); - STREAM_GETW(s, instance); STREAM_GETW(s, len); STREAM_GET(locator_name, s, len); - assert(proto == client->proto && instance == client->instance); - /* call hook to get a chunk using wrapper */ struct srv6_locator *loc = NULL; srv6_manager_get_locator_chunk_call(&loc, client, locator_name, vrf_id); @@ -2896,19 +2890,13 @@ static void zread_srv6_manager_release_locator_chunk(struct zserv *client, vrf_id_t vrf_id) { struct stream *s = msg; - uint8_t proto; - uint16_t instance; uint16_t len; char locator_name[SRV6_LOCNAME_SIZE] = {0}; /* Get data. */ - STREAM_GETC(s, proto); - STREAM_GETW(s, instance); STREAM_GETW(s, len); STREAM_GET(locator_name, s, len); - assert(proto == client->proto && instance == client->instance); - /* call hook to release a chunk using wrapper */ srv6_manager_release_locator_chunk_call(client, locator_name, vrf_id); -- cgit v1.2.3 From 054859269166720f36fe34096c904a7390f85f9e Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 22 Mar 2021 09:07:18 +0000 Subject: *: 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 | 49 +++++++++++++++---------------------------------- 3 files changed, 17 insertions(+), 49 deletions(-) (limited to 'lib/zclient.c') 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(); + struct srv6_locator_chunk s6c = {}; + struct listnode *node, *nnode; + struct sharp_srv6_locator *loc; 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); + zapi_srv6_locator_chunk_decode(s, &s6c); - 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 sharp_srv6_locator *loc; - - for (ALL_LIST_ELEMENTS_RO(sg.srv6_locators, loc_node, loc)) { + 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; + + chunk = prefix_ipv6_new(); + *chunk = s6c.prefix; listnode_add(loc->chunks, chunk); + return; } - return; - -stream_failure: - free(chunk); zlog_err("%s: can't get locator_chunk!!", __func__); } -- cgit v1.2.3 From eab0f8f0a202201fcc9757c6097f5c913456ff4d Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Mon, 5 Apr 2021 13:29:12 +0000 Subject: lib,sharpd,zebra: update nexthop object with nh_srv6 Signed-off-by: Hiroki Shirokura --- lib/nexthop.c | 141 ++++++++++++----------- lib/nexthop.h | 19 ++-- lib/srv6.h | 9 ++ lib/zclient.c | 33 +++--- sharpd/sharp_vty.c | 4 +- zebra/rt_netlink.c | 326 +++++++++++++++++++++++++++++------------------------ zebra/zapi_msg.c | 7 +- zebra/zebra_nhg.c | 8 +- zebra/zebra_vty.c | 20 ++-- 9 files changed, 303 insertions(+), 264 deletions(-) (limited to 'lib/zclient.c') diff --git a/lib/nexthop.c b/lib/nexthop.c index d0cc5dc258..23e3a2b733 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -36,8 +36,7 @@ DEFINE_MTYPE_STATIC(LIB, NEXTHOP, "Nexthop"); DEFINE_MTYPE_STATIC(LIB, NH_LABEL, "Nexthop label"); -DEFINE_MTYPE_STATIC(LIB, NH_SEG6LOCAL, "Nexthop seg6local"); -DEFINE_MTYPE_STATIC(LIB, NH_SEG6, "Nexthop seg6"); +DEFINE_MTYPE_STATIC(LIB, NH_SRV6, "Nexthop srv6"); static int _nexthop_labels_cmp(const struct nexthop *nh1, const struct nexthop *nh2) @@ -68,42 +67,37 @@ static int _nexthop_labels_cmp(const struct nexthop *nh1, (nhl1->num_labels * sizeof(mpls_label_t))); } -static int _nexthop_seg6local_cmp(const struct nexthop *nh1, - const struct nexthop *nh2) +static int _nexthop_srv6_cmp(const struct nexthop *nh1, + const struct nexthop *nh2) { - if (nh1->nh_seg6local_action > nh2->nh_seg6local_action) - return 1; - - if (nh2->nh_seg6local_action < nh1->nh_seg6local_action) - return -1; + int ret = 0; - if (!nh1->nh_seg6local_ctx && !nh2->nh_seg6local_ctx) + if (!nh1->nh_srv6 && !nh2->nh_srv6) return 0; - if (nh1->nh_seg6local_ctx && !nh2->nh_seg6local_ctx) + if (nh1->nh_srv6 && !nh2->nh_srv6) return 1; - if (!nh1->nh_seg6local_ctx && nh2->nh_seg6local_ctx) + if (!nh1->nh_srv6 && nh2->nh_srv6) return -1; - return memcmp(nh1->nh_seg6local_ctx, nh2->nh_seg6local_ctx, - sizeof(struct seg6local_context)); -} - -static int _nexthop_seg6_cmp(const struct nexthop *nh1, - const struct nexthop *nh2) -{ - if (!nh1->nh_seg6_segs && !nh2->nh_seg6_segs) - return 0; - - if (nh1->nh_seg6_segs && !nh2->nh_seg6_segs) + if (nh1->nh_srv6->seg6local_action > nh2->nh_srv6->seg6local_action) return 1; - if (!nh1->nh_seg6_segs && nh2->nh_seg6_segs) + if (nh2->nh_srv6->seg6local_action < nh1->nh_srv6->seg6local_action) return -1; - return memcmp(nh1->nh_seg6_segs, nh2->nh_seg6_segs, - sizeof(struct in6_addr)); + ret = memcmp(&nh1->nh_srv6->seg6local_ctx, + &nh2->nh_srv6->seg6local_ctx, + sizeof(struct seg6local_context)); + if (ret != 0) + return ret; + + ret = memcmp(&nh1->nh_srv6->seg6_segs, + &nh2->nh_srv6->seg6_segs, + sizeof(struct in6_addr)); + + return ret; } int nexthop_g_addr_cmp(enum nexthop_types_t type, const union g_addr *addr1, @@ -242,11 +236,7 @@ int nexthop_cmp(const struct nexthop *next1, const struct nexthop *next2) if (ret != 0) return ret; - ret = _nexthop_seg6local_cmp(next1, next2); - if (ret != 0) - return ret; - - ret = _nexthop_seg6_cmp(next1, next2); + ret = _nexthop_srv6_cmp(next1, next2); return ret; } @@ -401,8 +391,8 @@ struct nexthop *nexthop_new(void) void nexthop_free(struct nexthop *nexthop) { nexthop_del_labels(nexthop); - nexthop_del_seg6local(nexthop); - nexthop_del_seg6(nexthop); + nexthop_del_srv6_seg6local(nexthop); + nexthop_del_srv6_seg6(nexthop); if (nexthop->resolved) nexthops_free(nexthop->resolved); XFREE(MTYPE_NEXTHOP, nexthop); @@ -573,40 +563,55 @@ void nexthop_del_labels(struct nexthop *nexthop) nexthop->nh_label_type = ZEBRA_LSP_NONE; } -void nexthop_add_seg6local(struct nexthop *nexthop, uint32_t action, - const struct seg6local_context *ctx) +void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action, + const struct seg6local_context *ctx) { - struct seg6local_context *nh_ctx; - if (action == ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) return; - nh_ctx = XCALLOC(MTYPE_NH_SEG6LOCAL, sizeof(struct seg6local_context)); - if (ctx) - *nh_ctx = *ctx; - nexthop->nh_seg6local_action = action; - nexthop->nh_seg6local_ctx = nh_ctx; + if (!nexthop->nh_srv6) + nexthop->nh_srv6 = XCALLOC(MTYPE_NH_SRV6, + sizeof(struct nexthop_srv6)); + + nexthop->nh_srv6->seg6local_action = action; + nexthop->nh_srv6->seg6local_ctx = *ctx; } -void nexthop_del_seg6local(struct nexthop *nexthop) +void nexthop_del_srv6_seg6local(struct nexthop *nexthop) { - XFREE(MTYPE_NH_SEG6LOCAL, nexthop->nh_seg6local_ctx); - nexthop->nh_seg6local_action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + if (!nexthop->nh_srv6) + return; + + nexthop->nh_srv6->seg6local_action = ZEBRA_SEG6_LOCAL_ACTION_UNSPEC; + + if (sid_zero(&nexthop->nh_srv6->seg6_segs)) + XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6); } -void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr *segs) +void nexthop_add_srv6_seg6(struct nexthop *nexthop, + const struct in6_addr *segs) { - struct in6_addr *nh_segs; + if (!segs) + return; + + if (!nexthop->nh_srv6) + nexthop->nh_srv6 = XCALLOC(MTYPE_NH_SRV6, + sizeof(struct nexthop_srv6)); - nh_segs = XCALLOC(MTYPE_NH_SEG6, sizeof(struct in6_addr)); - if (segs) - *nh_segs = *segs; - nexthop->nh_seg6_segs = nh_segs; + nexthop->nh_srv6->seg6_segs = *segs; } -void nexthop_del_seg6(struct nexthop *nexthop) +void nexthop_del_srv6_seg6(struct nexthop *nexthop) { - XFREE(MTYPE_NH_SEG6, nexthop->nh_seg6_segs); + if (!nexthop->nh_srv6) + return; + + memset(&nexthop->nh_srv6->seg6_segs, 0, + sizeof(nexthop->nh_srv6->seg6_segs)); + + if (nexthop->nh_srv6->seg6local_action == + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) + XFREE(MTYPE_NH_SRV6, nexthop->nh_srv6); } const char *nexthop2str(const struct nexthop *nexthop, char *str, int size) @@ -754,16 +759,14 @@ uint32_t nexthop_hash_quick(const struct nexthop *nexthop) key = jhash_1word(nexthop->backup_idx[i], key); } - if (nexthop->nh_seg6local_ctx) { - key = jhash_1word(nexthop->nh_seg6local_action, key); - key = jhash(nexthop->nh_seg6local_ctx, - sizeof(nexthop->nh_seg6local_ctx), key); + if (nexthop->nh_srv6) { + key = jhash_1word(nexthop->nh_srv6->seg6local_action, key); + key = jhash(&nexthop->nh_srv6->seg6local_ctx, + sizeof(nexthop->nh_srv6->seg6local_ctx), key); + key = jhash(&nexthop->nh_srv6->seg6_segs, + sizeof(nexthop->nh_srv6->seg6_segs), key); } - if (nexthop->nh_seg6_segs) - key = jhash(nexthop->nh_seg6_segs, - sizeof(nexthop->nh_seg6_segs), key); - return key; } @@ -817,12 +820,16 @@ void nexthop_copy_no_recurse(struct nexthop *copy, nexthop->nh_label->num_labels, &nexthop->nh_label->label[0]); - if (nexthop->nh_seg6local_ctx) - nexthop_add_seg6local(copy, nexthop->nh_seg6local_action, - nexthop->nh_seg6local_ctx); - - if (nexthop->nh_seg6_segs) - nexthop_add_seg6(copy, nexthop->nh_seg6_segs); + if (nexthop->nh_srv6) { + if (nexthop->nh_srv6->seg6local_action != + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) + nexthop_add_srv6_seg6local(copy, + nexthop->nh_srv6->seg6local_action, + &nexthop->nh_srv6->seg6local_ctx); + if (!sid_zero(&nexthop->nh_srv6->seg6_segs)) + nexthop_add_srv6_seg6(copy, + &nexthop->nh_srv6->seg6_segs); + } } void nexthop_copy(struct nexthop *copy, const struct nexthop *nexthop, diff --git a/lib/nexthop.h b/lib/nexthop.h index c9af1ff478..dd65509aec 100644 --- a/lib/nexthop.h +++ b/lib/nexthop.h @@ -141,12 +141,8 @@ struct nexthop { /* SR-TE color used for matching SR-TE policies */ uint32_t srte_color; - /* SRv6 localsid info for Endpoint-behaviour */ - enum seg6local_action_t nh_seg6local_action; - struct seg6local_context *nh_seg6local_ctx; - - /* SRv6 Headend-behaviour */ - struct in6_addr *nh_seg6_segs; + /* SRv6 information */ + struct nexthop_srv6 *nh_srv6; }; /* Utility to append one nexthop to another. */ @@ -165,11 +161,12 @@ void nexthops_free(struct nexthop *nexthop); void nexthop_add_labels(struct nexthop *nexthop, enum lsp_types_t ltype, uint8_t num_labels, const mpls_label_t *labels); void nexthop_del_labels(struct nexthop *); -void nexthop_add_seg6local(struct nexthop *nexthop, uint32_t action, - const struct seg6local_context *ctx); -void nexthop_del_seg6local(struct nexthop *nexthop); -void nexthop_add_seg6(struct nexthop *nexthop, const struct in6_addr *segs); -void nexthop_del_seg6(struct nexthop *nexthop); +void nexthop_add_srv6_seg6local(struct nexthop *nexthop, uint32_t action, + const struct seg6local_context *ctx); +void nexthop_del_srv6_seg6local(struct nexthop *nexthop); +void nexthop_add_srv6_seg6(struct nexthop *nexthop, + const struct in6_addr *segs); +void nexthop_del_srv6_seg6(struct nexthop *nexthop); /* * Allocate a new nexthop object and initialize it from various args. diff --git a/lib/srv6.h b/lib/srv6.h index 9ac89125ce..715fc3723b 100644 --- a/lib/srv6.h +++ b/lib/srv6.h @@ -117,6 +117,15 @@ struct srv6_locator_chunk { uint32_t session_id; }; +struct nexthop_srv6 { + /* SRv6 localsid info for Endpoint-behaviour */ + enum seg6local_action_t seg6local_action; + struct seg6local_context seg6local_ctx; + + /* SRv6 Headend-behaviour */ + struct in6_addr seg6_segs; +}; + static inline const char *seg6_mode2str(enum seg6_mode_t mode) { switch (mode) { diff --git a/lib/zclient.c b/lib/zclient.c index 5395d4799d..4eef55e469 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -464,7 +464,7 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient, nh.type = NEXTHOP_TYPE_IFINDEX; nh.ifindex = oif; - nexthop_add_seg6local(&nh, action, context); + nexthop_add_srv6_seg6local(&nh, action, context); zapi_nexthop_from_nexthop(&api.nexthops[0], &nh); api.nexthop_num = 1; @@ -1734,7 +1734,6 @@ stream_failure: struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) { - uint8_t zero[16] = {0}; struct nexthop *n = nexthop_new(); n->type = znh->type; @@ -1757,12 +1756,12 @@ struct nexthop *nexthop_from_zapi_nexthop(const struct zapi_nexthop *znh) memcpy(n->backup_idx, znh->backup_idx, n->backup_num); } - if (znh->seg6local_action != 0) - nexthop_add_seg6local(n, znh->seg6local_action, - &znh->seg6local_ctx); + if (znh->seg6local_action != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) + nexthop_add_srv6_seg6local(n, znh->seg6local_action, + &znh->seg6local_ctx); - if (memcmp(&znh->seg6_segs, zero, sizeof(struct in6_addr)) != 0) - nexthop_add_seg6(n, &znh->seg6_segs); + if (!sid_zero(&znh->seg6_segs)) + nexthop_add_srv6_seg6(n, &znh->seg6_segs); return n; } @@ -1808,15 +1807,19 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, memcpy(znh->backup_idx, nh->backup_idx, znh->backup_num); } - if (nh->nh_seg6local_action != 0 && nh->nh_seg6local_ctx != NULL) { - znh->seg6local_action = nh->nh_seg6local_action; - memcpy(&znh->seg6local_ctx, nh->nh_seg6local_ctx, - sizeof(struct seg6local_context)); - } + if (nh->nh_srv6) { + if (nh->nh_srv6->seg6local_action != + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) { + znh->seg6local_action = nh->nh_srv6->seg6local_action; + memcpy(&znh->seg6local_ctx, + &nh->nh_srv6->seg6local_ctx, + sizeof(struct seg6local_context)); + } - if (nh->nh_seg6_segs != NULL) - memcpy(&znh->seg6_segs, nh->nh_seg6_segs, - sizeof(struct in6_addr)); + if (!sid_zero(&nh->nh_srv6->seg6_segs)) + memcpy(&znh->seg6_segs, &nh->nh_srv6->seg6_segs, + sizeof(struct in6_addr)); + } return 0; } diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 7cd9b959f8..7482a6da68 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -407,7 +407,7 @@ DEFPY (install_seg6_routes, sg.r.nhop.vrf_id = vrf->vrf_id; sg.r.nhop_group.nexthop = &sg.r.nhop; - nexthop_add_seg6(&sg.r.nhop, &seg6_seg); + nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg); SET_FLAG(route_flags, ZEBRA_FLAG_SEG6_ROUTE); sg.r.vrf_id = vrf->vrf_id; @@ -504,7 +504,7 @@ DEFPY (install_seg6local_routes, sg.r.nhop.ifindex = ifname2ifindex(seg6l_oif, vrf->vrf_id); sg.r.nhop.vrf_id = vrf->vrf_id; sg.r.nhop_group.nexthop = &sg.r.nhop; - nexthop_add_seg6local(&sg.r.nhop, action, &ctx); + nexthop_add_srv6_seg6local(&sg.r.nhop, action, &ctx); SET_FLAG(route_flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE); sg.r.vrf_id = vrf->vrf_id; diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index d40c717018..4479c434eb 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -534,10 +534,10 @@ parse_nexthop_unicast(ns_id_t ns_id, struct rtmsg *rtm, struct rtattr **tb, nexthop_add_labels(&nh, ZEBRA_LSP_STATIC, num_labels, labels); if (seg6l_act != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) - nexthop_add_seg6local(&nh, seg6l_act, &seg6l_ctx); + nexthop_add_srv6_seg6local(&nh, seg6l_act, &seg6l_ctx); if (num_segs) - nexthop_add_seg6(&nh, &seg6_segs); + nexthop_add_srv6_seg6(&nh, &seg6_segs); return nh; } @@ -641,11 +641,11 @@ static uint8_t parse_multipath_nexthops_unicast(ns_id_t ns_id, num_labels, labels); if (seg6l_act != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) - nexthop_add_seg6local(nh, seg6l_act, - &seg6l_ctx); + nexthop_add_srv6_seg6local(nh, seg6l_act, + &seg6l_ctx); if (num_segs) - nexthop_add_seg6(nh, &seg6_segs); + nexthop_add_srv6_seg6(nh, &seg6_segs); if (rtnh->rtnh_flags & RTNH_F_ONLINK) SET_FLAG(nh->flags, NEXTHOP_FLAG_ONLINK); @@ -1399,84 +1399,97 @@ static bool _netlink_route_build_singlepath(const struct prefix *p, sizeof(label_buf))) return false; - if (nexthop->nh_seg6local_ctx) { - struct rtattr *nest; - const struct seg6local_context *ctx; - - ctx = nexthop->nh_seg6local_ctx; - if (!nl_attr_put16(nlmsg, req_size, RTA_ENCAP_TYPE, - LWTUNNEL_ENCAP_SEG6_LOCAL)) - return false; - - nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP); - if (!nest) - return false; + if (nexthop->nh_srv6) { + if (nexthop->nh_srv6->seg6local_action != + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) { + struct rtattr *nest; + const struct seg6local_context *ctx; - switch (nexthop->nh_seg6local_action) { - case ZEBRA_SEG6_LOCAL_ACTION_END: - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END)) - return false; - break; - case ZEBRA_SEG6_LOCAL_ACTION_END_X: - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END_X)) - return false; - if (!nl_attr_put(nlmsg, req_size, SEG6_LOCAL_NH6, - &ctx->nh6, sizeof(struct in6_addr))) - return false; - break; - case ZEBRA_SEG6_LOCAL_ACTION_END_T: - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END_T)) + ctx = &nexthop->nh_srv6->seg6local_ctx; + if (!nl_attr_put16(nlmsg, req_size, RTA_ENCAP_TYPE, + LWTUNNEL_ENCAP_SEG6_LOCAL)) return false; - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_TABLE, - ctx->table)) + + nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP); + if (!nest) return false; - break; - case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END_DX4)) + + switch (nexthop->nh_srv6->seg6local_action) { + case ZEBRA_SEG6_LOCAL_ACTION_END: + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END)) + return false; + break; + case ZEBRA_SEG6_LOCAL_ACTION_END_X: + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END_X)) + return false; + if (!nl_attr_put(nlmsg, req_size, + SEG6_LOCAL_NH6, &ctx->nh6, + sizeof(struct in6_addr))) + return false; + break; + case ZEBRA_SEG6_LOCAL_ACTION_END_T: + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END_T)) + return false; + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_TABLE, + ctx->table)) + return false; + break; + case ZEBRA_SEG6_LOCAL_ACTION_END_DX4: + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END_DX4)) + return false; + if (!nl_attr_put(nlmsg, req_size, + SEG6_LOCAL_NH4, &ctx->nh4, + sizeof(struct in_addr))) + return false; + break; + case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_ACTION, + SEG6_LOCAL_ACTION_END_DT6)) + return false; + if (!nl_attr_put32(nlmsg, req_size, + SEG6_LOCAL_TABLE, + ctx->table)) + return false; + break; + default: + zlog_err("%s: unsupport seg6local behaviour action=%u", + __func__, + nexthop->nh_srv6->seg6local_action); + break; + } + nl_attr_nest_end(nlmsg, nest); + } + + if (!sid_zero(&nexthop->nh_srv6->seg6_segs)) { + char tun_buf[4096]; + ssize_t tun_len; + struct rtattr *nest; + + if (!nl_attr_put16(nlmsg, req_size, RTA_ENCAP_TYPE, + LWTUNNEL_ENCAP_SEG6)) return false; - if (!nl_attr_put(nlmsg, req_size, SEG6_LOCAL_NH4, - &ctx->nh4, sizeof(struct in_addr))) + nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP); + if (!nest) return false; - break; - case ZEBRA_SEG6_LOCAL_ACTION_END_DT6: - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_ACTION, - SEG6_LOCAL_ACTION_END_DT6)) + tun_len = fill_seg6ipt_encap(tun_buf, sizeof(tun_buf), + &nexthop->nh_srv6->seg6_segs); + if (tun_len < 0) return false; - if (!nl_attr_put32(nlmsg, req_size, SEG6_LOCAL_TABLE, - ctx->table)) + if (!nl_attr_put(nlmsg, req_size, SEG6_IPTUNNEL_SRH, + tun_buf, tun_len)) return false; - break; - default: - zlog_err("%s: unsupport seg6local behaviour action=%u", - __func__, nexthop->nh_seg6local_action); - break; + nl_attr_nest_end(nlmsg, nest); } - nl_attr_nest_end(nlmsg, nest); - } - - if (nexthop->nh_seg6_segs) { - char tun_buf[4096]; - ssize_t tun_len; - struct rtattr *nest; - - if (!nl_attr_put16(nlmsg, req_size, RTA_ENCAP_TYPE, - LWTUNNEL_ENCAP_SEG6)) - return false; - nest = nl_attr_nest(nlmsg, req_size, RTA_ENCAP); - if (!nest) - return false; - tun_len = fill_seg6ipt_encap(tun_buf, sizeof(tun_buf), - nexthop->nh_seg6_segs); - if (tun_len < 0) - return false; - if (!nl_attr_put(nlmsg, req_size, SEG6_IPTUNNEL_SRH, tun_buf, - tun_len)) - return false; - nl_attr_nest_end(nlmsg, nest); } if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ONLINK)) @@ -2473,104 +2486,117 @@ ssize_t netlink_nexthop_msg_encode(uint16_t cmd, nl_attr_nest_end(&req->n, nest); } - if (nh->nh_seg6local_ctx) { - uint32_t action; - uint16_t encap; - struct rtattr *nest; - const struct seg6local_context *ctx; - - req->nhm.nh_family = AF_INET6; - action = nh->nh_seg6local_action; - ctx = nh->nh_seg6local_ctx; - encap = LWTUNNEL_ENCAP_SEG6_LOCAL; - if (!nl_attr_put(&req->n, buflen, - NHA_ENCAP_TYPE, &encap, - sizeof(uint16_t))) - return 0; + if (nh->nh_srv6) { + if (nh->nh_srv6->seg6local_action != + ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) { + uint32_t action; + uint16_t encap; + struct rtattr *nest; + const struct seg6local_context *ctx; + + req->nhm.nh_family = AF_INET6; + action = nh->nh_srv6->seg6local_action; + ctx = &nh->nh_srv6->seg6local_ctx; + encap = LWTUNNEL_ENCAP_SEG6_LOCAL; + if (!nl_attr_put(&req->n, buflen, + NHA_ENCAP_TYPE, + &encap, + sizeof(uint16_t))) + return 0; - nest = nl_attr_nest(&req->n, buflen, - NHA_ENCAP | NLA_F_NESTED); - if (!nest) - return 0; + nest = nl_attr_nest(&req->n, buflen, + NHA_ENCAP | NLA_F_NESTED); + if (!nest) + return 0; - switch (action) { - case SEG6_LOCAL_ACTION_END: - if (!nl_attr_put32(&req->n, buflen, + switch (action) { + case SEG6_LOCAL_ACTION_END: + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_ACTION, SEG6_LOCAL_ACTION_END)) - return 0; - break; - case SEG6_LOCAL_ACTION_END_X: - if (!nl_attr_put32(&req->n, buflen, + return 0; + break; + case SEG6_LOCAL_ACTION_END_X: + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_ACTION, SEG6_LOCAL_ACTION_END_X)) - return 0; - if (!nl_attr_put(&req->n, buflen, + return 0; + if (!nl_attr_put( + &req->n, buflen, SEG6_LOCAL_NH6, &ctx->nh6, sizeof(struct in6_addr))) - return 0; - break; - case SEG6_LOCAL_ACTION_END_T: - if (!nl_attr_put32(&req->n, buflen, + return 0; + break; + case SEG6_LOCAL_ACTION_END_T: + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_ACTION, SEG6_LOCAL_ACTION_END_T)) - return 0; - if (!nl_attr_put32(&req->n, buflen, + return 0; + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_TABLE, ctx->table)) - return 0; - break; - case SEG6_LOCAL_ACTION_END_DX4: - if (!nl_attr_put32(&req->n, buflen, + return 0; + break; + case SEG6_LOCAL_ACTION_END_DX4: + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_ACTION, SEG6_LOCAL_ACTION_END_DX4)) - return 0; - if (!nl_attr_put(&req->n, buflen, + return 0; + if (!nl_attr_put( + &req->n, buflen, SEG6_LOCAL_NH4, &ctx->nh4, sizeof(struct in_addr))) - return 0; - break; - case SEG6_LOCAL_ACTION_END_DT6: - if (!nl_attr_put32(&req->n, buflen, + return 0; + break; + case SEG6_LOCAL_ACTION_END_DT6: + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_ACTION, SEG6_LOCAL_ACTION_END_DT6)) - return 0; - if (!nl_attr_put32(&req->n, buflen, + return 0; + if (!nl_attr_put32( + &req->n, buflen, SEG6_LOCAL_TABLE, ctx->table)) - return 0; - break; - default: - zlog_err("%s: unsupport seg6local behaviour action=%u", - __func__, action); - break; + return 0; + break; + default: + zlog_err("%s: unsupport seg6local behaviour action=%u", + __func__, action); + break; + } + nl_attr_nest_end(&req->n, nest); } - nl_attr_nest_end(&req->n, nest); - } - if (nh->nh_seg6_segs) { - char tun_buf[4096]; - ssize_t tun_len; - struct rtattr *nest; + if (!sid_zero(&nh->nh_srv6->seg6_segs)) { + char tun_buf[4096]; + ssize_t tun_len; + struct rtattr *nest; - if (!nl_attr_put16(&req->n, buflen, - NHA_ENCAP_TYPE, - LWTUNNEL_ENCAP_SEG6)) - return 0; - nest = nl_attr_nest(&req->n, buflen, - NHA_ENCAP | NLA_F_NESTED); - if (!nest) - return 0; - tun_len = fill_seg6ipt_encap(tun_buf, - sizeof(tun_buf), - nh->nh_seg6_segs); - if (tun_len < 0) - return 0; - if (!nl_attr_put(&req->n, buflen, - SEG6_IPTUNNEL_SRH, - tun_buf, tun_len)) - return 0; - nl_attr_nest_end(&req->n, nest); + if (!nl_attr_put16(&req->n, buflen, + NHA_ENCAP_TYPE, + LWTUNNEL_ENCAP_SEG6)) + return 0; + nest = nl_attr_nest(&req->n, buflen, + NHA_ENCAP | NLA_F_NESTED); + if (!nest) + return 0; + tun_len = fill_seg6ipt_encap(tun_buf, + sizeof(tun_buf), + &nh->nh_srv6->seg6_segs); + if (tun_len < 0) + return 0; + if (!nl_attr_put(&req->n, buflen, + SEG6_IPTUNNEL_SRH, + tun_buf, tun_len)) + return 0; + nl_attr_nest_end(&req->n, nest); + } } nexthop_done: diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index d97d876cf5..f6151463ce 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1756,8 +1756,9 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, seg6local_action2str( api_nh->seg6local_action)); - nexthop_add_seg6local(nexthop, api_nh->seg6local_action, - &api_nh->seg6local_ctx); + nexthop_add_srv6_seg6local(nexthop, + api_nh->seg6local_action, + &api_nh->seg6local_ctx); } if (CHECK_FLAG(flags, ZEBRA_FLAG_SEG6_ROUTE) @@ -1765,7 +1766,7 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: adding seg6", __func__); - nexthop_add_seg6(nexthop, &api_nh->seg6_segs); + nexthop_add_srv6_seg6(nexthop, &api_nh->seg6_segs); } if (IS_ZEBRA_DEBUG_RECV) { diff --git a/zebra/zebra_nhg.c b/zebra/zebra_nhg.c index 84ce97b008..face0ef3bc 100644 --- a/zebra/zebra_nhg.c +++ b/zebra/zebra_nhg.c @@ -1007,8 +1007,8 @@ void nhg_ctx_free(struct nhg_ctx **ctx) nh = nhg_ctx_get_nh(*ctx); nexthop_del_labels(nh); - nexthop_del_seg6local(nh); - nexthop_del_seg6(nh); + nexthop_del_srv6_seg6local(nh); + nexthop_del_srv6_seg6(nh); done: XFREE(MTYPE_NHG_CTX, *ctx); @@ -1379,8 +1379,8 @@ static struct nhg_hash_entry *depends_find_singleton(const struct nexthop *nh, /* The copy may have allocated labels; free them if necessary. */ nexthop_del_labels(&lookup); - nexthop_del_seg6local(&lookup); - nexthop_del_seg6(&lookup); + nexthop_del_srv6_seg6local(&lookup); + nexthop_del_srv6_seg6(&lookup); if (IS_ZEBRA_DEBUG_NHG_DETAIL) zlog_debug("%s: nh %pNHv => %p (%u)", diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index fae443ca2e..2bc25f6f7d 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -653,17 +653,15 @@ static void show_route_nexthop_helper(struct vty *vty, sizeof(buf), 1)); } - if (nexthop->nh_seg6local_ctx) { + if (nexthop->nh_srv6) { seg6local_context2str(buf, sizeof(buf), - nexthop->nh_seg6local_ctx, - nexthop->nh_seg6local_action); + &nexthop->nh_srv6->seg6local_ctx, + nexthop->nh_srv6->seg6local_action); vty_out(vty, ", seg6local %s %s", - seg6local_action2str(nexthop->nh_seg6local_action), + seg6local_action2str(nexthop->nh_srv6->seg6local_action), buf); - } - if (nexthop->nh_seg6_segs) { - inet_ntop(AF_INET6, nexthop->nh_seg6_segs, buf, sizeof(buf)); + inet_ntop(AF_INET6, &nexthop->nh_srv6->seg6_segs, buf, sizeof(buf)); vty_out(vty, ", seg6 %s", buf); } @@ -869,18 +867,16 @@ static void show_nexthop_json_helper(json_object *json_nexthop, json_object_int_add(json_nexthop, "srteColor", nexthop->srte_color); - if (nexthop->nh_seg6local_ctx) { + if (nexthop->nh_srv6) { json_seg6local = json_object_new_object(); json_object_string_add( json_seg6local, "action", - seg6local_action2str(nexthop->nh_seg6local_action)); + seg6local_action2str(nexthop->nh_srv6->seg6local_action)); json_object_object_add(json_nexthop, "seg6local", json_seg6local); - } - if (nexthop->nh_seg6_segs) { json_seg6 = json_object_new_object(); - inet_ntop(AF_INET6, nexthop->nh_seg6_segs, buf, sizeof(buf)); + inet_ntop(AF_INET6, &nexthop->nh_srv6->seg6_segs, buf, sizeof(buf)); json_object_string_add(json_seg6, "segs", buf); json_object_object_add(json_nexthop, "seg6", json_seg6); } -- cgit v1.2.3 From c60c1ade86c1c999f5219c0ebc35374acddb661c Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Fri, 23 Apr 2021 12:46:07 +0000 Subject: *: delete ZEBRA_FLAG_SEG6*_ROUTE and add ZAPI_NEXTHOP_FLAG_SEG6* https://github.com/FRRouting/frr/pull/5865#discussion_r597670225 As this comment says. ZEBRA_FLAG_XXX should not have been used. To communicate SRv6 Route Information. A simple Nexthop Flag would have been sufficient for SRv6 information. And I fixed the whole thing that way. Signed-off-by: Hiroki Shirokura --- bgpd/bgp_zebra.c | 2 +- lib/zclient.c | 15 +++++++++------ lib/zclient.h | 12 ++---------- sharpd/sharp_vty.c | 3 --- .../topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf10_rib.json | 2 +- .../topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf20_rib.json | 4 ++-- .../topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf10_rib.json | 4 ++-- .../topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf20_rib.json | 2 +- zebra/zapi_msg.c | 4 ++-- 9 files changed, 20 insertions(+), 28 deletions(-) (limited to 'lib/zclient.c') diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index d4a4ed2305..e3a795c6f1 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1408,7 +1408,7 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, } if (has_valid_sid && !(CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE))) - SET_FLAG(api.flags, ZEBRA_FLAG_SEG6_ROUTE); + SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6); is_add = (valid_nh_count || nhg_id) ? true : false; diff --git a/lib/zclient.c b/lib/zclient.c index 4eef55e469..10dda5ba0e 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -459,11 +459,11 @@ enum zclient_send_status zclient_send_localsid(struct zclient *zclient, return zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); - SET_FLAG(api.flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE); SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); nh.type = NEXTHOP_TYPE_IFINDEX; nh.ifindex = oif; + SET_FLAG(nh.flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL); nexthop_add_srv6_seg6local(&nh, action, context); zapi_nexthop_from_nexthop(&api.nexthops[0], &nh); @@ -1053,13 +1053,13 @@ int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, stream_putc(s, api_nh->backup_idx[i]); } - if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE)) { + if (CHECK_FLAG(nh_flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL)) { stream_putl(s, api_nh->seg6local_action); stream_write(s, &api_nh->seg6local_ctx, sizeof(struct seg6local_context)); } - if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6_ROUTE)) + if (CHECK_FLAG(nh_flags, ZAPI_NEXTHOP_FLAG_SEG6)) stream_write(s, &api_nh->seg6_segs, sizeof(struct in6_addr)); @@ -1382,13 +1382,13 @@ int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh, STREAM_GETC(s, api_nh->backup_idx[i]); } - if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE)) { + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL)) { STREAM_GETL(s, api_nh->seg6local_action); STREAM_GET(&api_nh->seg6local_ctx, s, sizeof(struct seg6local_context)); } - if (CHECK_FLAG(api_flags, ZEBRA_FLAG_SEG6_ROUTE)) + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6)) STREAM_GET(&api_nh->seg6_segs, s, sizeof(struct in6_addr)); @@ -1810,15 +1810,18 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh, if (nh->nh_srv6) { if (nh->nh_srv6->seg6local_action != ZEBRA_SEG6_LOCAL_ACTION_UNSPEC) { + SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL); znh->seg6local_action = nh->nh_srv6->seg6local_action; memcpy(&znh->seg6local_ctx, &nh->nh_srv6->seg6local_ctx, sizeof(struct seg6local_context)); } - if (!sid_zero(&nh->nh_srv6->seg6_segs)) + if (!sid_zero(&nh->nh_srv6->seg6_segs)) { + SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_SEG6); memcpy(&znh->seg6_segs, &nh->nh_srv6->seg6_segs, sizeof(struct in6_addr)); + } } return 0; diff --git a/lib/zclient.h b/lib/zclient.h index c41d25133d..48de3425be 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -488,6 +488,8 @@ struct zapi_nexthop { #define ZAPI_NEXTHOP_FLAG_LABEL 0x02 #define ZAPI_NEXTHOP_FLAG_WEIGHT 0x04 #define ZAPI_NEXTHOP_FLAG_HAS_BACKUP 0x08 /* Nexthop has a backup */ +#define ZAPI_NEXTHOP_FLAG_SEG6 0x10 +#define ZAPI_NEXTHOP_FLAG_SEG6LOCAL 0x20 /* * ZAPI Nexthop Group. For use with protocol creation of nexthop groups. @@ -572,16 +574,6 @@ struct zapi_route { * offload situation. */ #define ZEBRA_FLAG_OFFLOAD_FAILED 0x200 -/* - * This flag tells Zebra that the route is a seg6 route and should - * be treated specially. - */ -#define ZEBRA_FLAG_SEG6_ROUTE 0x400 -/* - * This flag tells Zebra that the route is a seg6local route and - * should be treated specially. - */ -#define ZEBRA_FLAG_SEG6LOCAL_ROUTE 0x800 /* The older XXX_MESSAGE flags live here */ uint32_t message; diff --git a/sharpd/sharp_vty.c b/sharpd/sharp_vty.c index 7482a6da68..1a3c5f4502 100644 --- a/sharpd/sharp_vty.c +++ b/sharpd/sharp_vty.c @@ -406,9 +406,7 @@ DEFPY (install_seg6_routes, sg.r.nhop.gate.ipv6 = seg6_nh6; sg.r.nhop.vrf_id = vrf->vrf_id; sg.r.nhop_group.nexthop = &sg.r.nhop; - nexthop_add_srv6_seg6(&sg.r.nhop, &seg6_seg); - SET_FLAG(route_flags, ZEBRA_FLAG_SEG6_ROUTE); sg.r.vrf_id = vrf->vrf_id; sharp_install_routes_helper(&prefix, sg.r.vrf_id, sg.r.inst, 0, @@ -505,7 +503,6 @@ DEFPY (install_seg6local_routes, sg.r.nhop.vrf_id = vrf->vrf_id; sg.r.nhop_group.nexthop = &sg.r.nhop; nexthop_add_srv6_seg6local(&sg.r.nhop, action, &ctx); - SET_FLAG(route_flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE); sg.r.vrf_id = vrf->vrf_id; sharp_install_routes_helper(&sg.r.orig_prefix, sg.r.vrf_id, sg.r.inst, 0, diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf10_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf10_rib.json index 9219d9ad38..fa05972a35 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf10_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf10_rib.json @@ -37,7 +37,7 @@ "installed": true, "table": 10, "internalStatus": 16, - "internalFlags": 1032, + "internalFlags": 8, "internalNextHopNum": 1, "internalNextHopActiveNum": 1, "nexthops": [ diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf20_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf20_rib.json index cd4c7d5039..0155557242 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf20_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r1/vrf20_rib.json @@ -11,7 +11,7 @@ "installed": true, "table": 20, "internalStatus": 16, - "internalFlags": 1032, + "internalFlags": 8, "internalNextHopNum": 1, "internalNextHopActiveNum": 1, "nexthops": [ @@ -72,7 +72,7 @@ "installed": true, "table": 20, "internalStatus": 16, - "internalFlags": 1032, + "internalFlags": 8, "internalNextHopNum": 1, "internalNextHopActiveNum": 1, "nexthops": [ diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf10_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf10_rib.json index 5ae377c399..887eb24386 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf10_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf10_rib.json @@ -11,7 +11,7 @@ "installed": true, "table": 10, "internalStatus": 16, - "internalFlags": 1032, + "internalFlags": 8, "internalNextHopNum": 1, "internalNextHopActiveNum": 1, "nexthops": [ @@ -72,7 +72,7 @@ "installed": true, "table": 10, "internalStatus": 16, - "internalFlags": 1032, + "internalFlags": 8, "internalNextHopNum": 1, "internalNextHopActiveNum": 1, "nexthops": [ diff --git a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf20_rib.json b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf20_rib.json index ea1fe4c2a9..c118518423 100644 --- a/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf20_rib.json +++ b/tests/topotests/bgp_srv6l3vpn_to_bgp_vrf/r2/vrf20_rib.json @@ -37,7 +37,7 @@ "installed": true, "table": 20, "internalStatus": 16, - "internalFlags": 1032, + "internalFlags": 8, "internalNextHopNum": 1, "internalNextHopActiveNum": 1, "nexthops": [ diff --git a/zebra/zapi_msg.c b/zebra/zapi_msg.c index f6151463ce..06aaa706dc 100644 --- a/zebra/zapi_msg.c +++ b/zebra/zapi_msg.c @@ -1748,7 +1748,7 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, &api_nh->labels[0]); } - if (CHECK_FLAG(flags, ZEBRA_FLAG_SEG6LOCAL_ROUTE) + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6LOCAL) && api_nh->type != NEXTHOP_TYPE_BLACKHOLE) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: adding seg6local action %s", @@ -1761,7 +1761,7 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p, &api_nh->seg6local_ctx); } - if (CHECK_FLAG(flags, ZEBRA_FLAG_SEG6_ROUTE) + if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6) && api_nh->type != NEXTHOP_TYPE_BLACKHOLE) { if (IS_ZEBRA_DEBUG_RECV) zlog_debug("%s: adding seg6", __func__); -- cgit v1.2.3