From 339e36d258ad73701d7b9eccc0e56e48cdea1a2d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 8 Feb 2018 09:50:32 -0500 Subject: [PATCH] lib, sharpd, zebra: Add new enum for lsp type and pass it through. Add the ability to pass the lsp owner type through the zapi and in addition add a new label type for the sharp protocol for testing. Finally modify zebra_mpls.h to not have defaults specified for the enum. That way when we add a new LSP type the compile fails and the person doing the addition knows where he has to touch shit. Signed-off-by: Donald Sharp --- lib/mpls.h | 3 ++- lib/zclient.c | 3 ++- lib/zclient.h | 2 +- sharpd/sharp_zebra.c | 2 +- zebra/zebra_mpls.h | 37 ++++++++++++++++++++++++++++++++++--- zebra/zserv.c | 12 ++++++------ 6 files changed, 46 insertions(+), 13 deletions(-) diff --git a/lib/mpls.h b/lib/mpls.h index c6c0297ff0..b55d4875ae 100644 --- a/lib/mpls.h +++ b/lib/mpls.h @@ -115,7 +115,8 @@ enum lsp_types_t { ZEBRA_LSP_STATIC = 1, /* Static LSP. */ ZEBRA_LSP_LDP = 2, /* LDP LSP. */ ZEBRA_LSP_BGP = 3, /* BGP LSP. */ - ZEBRA_LSP_SR = 4 /* Segment Routing LSP. */ + ZEBRA_LSP_SR = 4, /* Segment Routing LSP. */ + ZEBRA_LSP_SHARP = 5, /* Identifier for test protocol */ }; /* Functions for basic label operations. */ diff --git a/lib/zclient.c b/lib/zclient.c index f8cdc61f7d..8e8b50b15e 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -364,7 +364,7 @@ static int zebra_hello_send(struct zclient *zclient) } void zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, - mpls_label_t label) + mpls_label_t label, enum lsp_types_t ltype) { struct stream *s; @@ -373,6 +373,7 @@ void zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, zclient_create_header(s, ZEBRA_VRF_LABEL, vrf_id); stream_putl(s, label); + stream_putc(s, ltype); stream_putw_at(s, 0, stream_get_endp(s)); zclient_send_message(zclient); } diff --git a/lib/zclient.h b/lib/zclient.h index 23cedf97bd..ff65838b53 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -392,7 +392,7 @@ extern void redist_del_instance(struct redist_proto *, u_short); * operation. */ extern void zclient_send_vrf_label(struct zclient *zclient, vrf_id_t vrf_id, - mpls_label_t label); + mpls_label_t label, enum lsp_types_t ltype); extern void zclient_send_reg_requests(struct zclient *, vrf_id_t); extern void zclient_send_dereg_requests(struct zclient *, vrf_id_t); diff --git a/sharpd/sharp_zebra.c b/sharpd/sharp_zebra.c index 5dffd4ab9b..f771e53f0c 100644 --- a/sharpd/sharp_zebra.c +++ b/sharpd/sharp_zebra.c @@ -154,7 +154,7 @@ static void zebra_connected(struct zclient *zclient) void vrf_label_add(vrf_id_t vrf_id, mpls_label_t label) { - zclient_send_vrf_label(zclient, vrf_id, label); + zclient_send_vrf_label(zclient, vrf_id, label, ZEBRA_LSP_SHARP); } void route_add(struct prefix *p, struct nexthop *nh) diff --git a/zebra/zebra_mpls.h b/zebra/zebra_mpls.h index 27a4971691..fd14b29ca9 100644 --- a/zebra/zebra_mpls.h +++ b/zebra/zebra_mpls.h @@ -428,9 +428,19 @@ static inline u_char lsp_distance(enum lsp_types_t type) return (route_distance(ZEBRA_ROUTE_LDP)); case ZEBRA_LSP_BGP: return (route_distance(ZEBRA_ROUTE_BGP)); - default: + case ZEBRA_LSP_NONE: + case ZEBRA_LSP_SHARP: + case ZEBRA_LSP_SR: return 150; } + + /* + * For some reason certain compilers do not believe + * that all the cases have been handled. And + * WTF does this work differently than when I removed + * the default case???? + */ + return 150; } /* @@ -444,6 +454,8 @@ static inline enum lsp_types_t lsp_type_from_re_type(int re_type) return ZEBRA_LSP_STATIC; case ZEBRA_ROUTE_BGP: return ZEBRA_LSP_BGP; + case ZEBRA_ROUTE_SHARP: + return ZEBRA_LSP_SHARP; default: return ZEBRA_LSP_NONE; } @@ -464,9 +476,18 @@ static inline int re_type_from_lsp_type(enum lsp_types_t lsp_type) case ZEBRA_LSP_SR: return ZEBRA_ROUTE_OSPF; case ZEBRA_LSP_NONE: - default: return ZEBRA_ROUTE_KERNEL; + case ZEBRA_LSP_SHARP: + return ZEBRA_ROUTE_SHARP; } + + /* + * For some reason certain compilers do not believe + * that all the cases have been handled. And + * WTF does this work differently than when I removed + * the default case???? + */ + return ZEBRA_ROUTE_KERNEL; } /* NHLFE type as printable string. */ @@ -481,9 +502,19 @@ static inline const char *nhlfe_type2str(enum lsp_types_t lsp_type) return "BGP"; case ZEBRA_LSP_SR: return "SR"; - default: + case ZEBRA_LSP_SHARP: + return "SHARP"; + case ZEBRA_LSP_NONE: return "Unknown"; } + + /* + * For some reason certain compilers do not believe + * that all the cases have been handled. And + * WTF does this work differently than when I removed + * the default case???? + */ + return "Unknown"; } static inline void mpls_mark_lsps_for_processing(struct zebra_vrf *zvrf) diff --git a/zebra/zserv.c b/zebra/zserv.c index bf8f66e20f..3d8be27f3b 100644 --- a/zebra/zserv.c +++ b/zebra/zserv.c @@ -2493,16 +2493,17 @@ static void zread_vrf_label(struct zserv *client, mpls_label_t nlabel; struct stream *s; struct zebra_vrf *def_zvrf; + enum lsp_types_t ltype; s = client->ibuf; STREAM_GETL(s, nlabel); - if (nlabel == zvrf->label) { /* * Nothing to do here move along */ return; } + STREAM_GETC(s, ltype); if (zvrf->vrf->vrf_id != VRF_DEFAULT) ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf->vrf_id); @@ -2518,13 +2519,12 @@ static void zread_vrf_label(struct zserv *client, def_zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT); if (zvrf->label != MPLS_LABEL_IPV4_EXPLICIT_NULL) - mpls_lsp_uninstall(def_zvrf, ZEBRA_LSP_STATIC, - zvrf->label, NEXTHOP_TYPE_IFINDEX, - NULL, ifp->ifindex); + mpls_lsp_uninstall(def_zvrf, ltype, zvrf->label, + NEXTHOP_TYPE_IFINDEX, NULL, ifp->ifindex); if (nlabel != MPLS_LABEL_IPV4_EXPLICIT_NULL) - mpls_lsp_install(def_zvrf, ZEBRA_LSP_STATIC, nlabel, - MPLS_LABEL_IMPLICIT_NULL, NEXTHOP_TYPE_IFINDEX, NULL, ifp->ifindex); + mpls_lsp_install(def_zvrf, ltype, nlabel, MPLS_LABEL_IMPLICIT_NULL, + NEXTHOP_TYPE_IFINDEX, NULL, ifp->ifindex); zvrf->label = nlabel; stream_failure: -- 2.39.5