lib: add label_type as field in zapi_nexthop

Add the ability to specify the label type along with the labels
you are passing to zebra in zapi_nexthop. This is needed as we
abstract the label code to be re-used by evpn as well as mpls.

Protocols need to be able to set the type of label they have attached.

Signed-off-by: Stephen Worley <sworley@nvidia.com>
This commit is contained in:
Stephen Worley 2021-04-05 17:12:01 -04:00
parent 4645cb6bc2
commit d5ea1185d5
3 changed files with 7 additions and 2 deletions

View File

@ -1035,6 +1035,7 @@ int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh,
*/
if (api_nh->label_num > 0) {
stream_putc(s, api_nh->label_num);
stream_putc(s, api_nh->label_type);
stream_put(s, &api_nh->labels[0],
api_nh->label_num * sizeof(mpls_label_t));
}
@ -1397,6 +1398,7 @@ int zapi_nexthop_decode(struct stream *s, struct zapi_nexthop *api_nh,
/* MPLS labels for BGP-LU or Segment Routing */
if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL)) {
STREAM_GETC(s, api_nh->label_num);
STREAM_GETC(s, api_nh->label_type);
if (api_nh->label_num > MPLS_MAX_LABELS) {
flog_err(
EC_LIB_ZAPI_ENCODE,
@ -1948,6 +1950,7 @@ int zapi_nexthop_from_nexthop(struct zapi_nexthop *znh,
znh->labels[i] = nh->nh_label->label[i];
znh->label_num = i;
znh->label_type = nh->nh_label_type;
SET_FLAG(znh->flags, ZAPI_NEXTHOP_FLAG_LABEL);
}

View File

@ -427,6 +427,7 @@ struct zapi_nexthop {
/* MPLS labels for BGP-LU or Segment Routing */
uint8_t label_num;
enum lsp_types_t label_type;
mpls_label_t labels[MPLS_MAX_LABELS];
struct ethaddr rmac;

View File

@ -1785,8 +1785,9 @@ static bool zapi_read_nexthops(struct zserv *client, struct prefix *p,
&& api_nh->type != NEXTHOP_TYPE_BLACKHOLE
&& api_nh->label_num > 0) {
if (CHECK_FLAG(flags, ZEBRA_FLAG_EVPN_ROUTE))
label_type = ZEBRA_LSP_EVPN;
/* If label type was passed, use it */
if (api_nh->label_type)
label_type = api_nh->label_type;
else
label_type =
lsp_type_from_re_type(client->proto);