From 34f86754a20ad1a796430ee9483fce93bc30dfa2 Mon Sep 17 00:00:00 2001 From: Mark Stapp Date: Thu, 2 Apr 2020 09:29:36 -0400 Subject: [PATCH] lib: add backup nexthop/nhlfe to zapi label messages Add backup nexthops/nhlfes to the zapi messages used to convey LSPs to zebra. Signed-off-by: Mark Stapp --- lib/zclient.c | 43 +++++++++++++++++++++++++++++++++++++++++++ lib/zclient.h | 7 ++++++- 2 files changed, 49 insertions(+), 1 deletion(-) diff --git a/lib/zclient.c b/lib/zclient.c index be2c4e54a0..fe0cd3ce27 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -2811,6 +2811,27 @@ int zapi_labels_encode(struct stream *s, int cmd, struct zapi_labels *zl) return -1; } + if (CHECK_FLAG(zl->message, ZAPI_LABELS_HAS_BACKUPS)) { + + if (zl->backup_nexthop_num > MULTIPATH_NUM) { + flog_err( + EC_LIB_ZAPI_ENCODE, + "%s: label %u: can't encode %u nexthops (maximum is %u)", + __func__, zl->local_label, zl->nexthop_num, + MULTIPATH_NUM); + return -1; + } + stream_putw(s, zl->backup_nexthop_num); + + for (int i = 0; i < zl->backup_nexthop_num; i++) { + znh = &zl->backup_nexthops[i]; + + if (zapi_nexthop_encode(s, znh, 0) < 0) + return -1; + } + + } + /* Put length at the first point of the stream. */ stream_putw_at(s, 0, stream_get_endp(s)); @@ -2885,6 +2906,28 @@ int zapi_labels_decode(struct stream *s, struct zapi_labels *zl) return -1; } + if (CHECK_FLAG(zl->message, ZAPI_LABELS_HAS_BACKUPS)) { + STREAM_GETW(s, zl->backup_nexthop_num); + + if (zl->backup_nexthop_num > MULTIPATH_NUM) { + flog_warn( + EC_LIB_ZAPI_ENCODE, + "%s: Prefix %pFX has %d backup nexthops, but we can only use the first %d", + __func__, &zl->route.prefix, + zl->backup_nexthop_num, MULTIPATH_NUM); + } + + zl->backup_nexthop_num = MIN(MULTIPATH_NUM, + zl->backup_nexthop_num); + + for (int i = 0; i < zl->backup_nexthop_num; i++) { + znh = &zl->backup_nexthops[i]; + + if (zapi_nexthop_decode(s, znh, 0) < 0) + return -1; + } + } + return 0; stream_failure: return -1; diff --git a/lib/zclient.h b/lib/zclient.h index 4ada064623..92ac017e80 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -484,7 +484,8 @@ struct zapi_route { struct zapi_labels { uint8_t message; -#define ZAPI_LABELS_FTN 0x01 +#define ZAPI_LABELS_FTN 0x01 +#define ZAPI_LABELS_HAS_BACKUPS 0x02 enum lsp_types_t type; mpls_label_t local_label; struct { @@ -495,6 +496,10 @@ struct zapi_labels { uint16_t nexthop_num; struct zapi_nexthop nexthops[MULTIPATH_NUM]; + + /* Backup nexthops, if present */ + uint16_t backup_nexthop_num; + struct zapi_nexthop backup_nexthops[MULTIPATH_NUM]; }; struct zapi_pw {