From 94c608d636b9b8d8bedc23fec75454d8deff8e37 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 19 Jul 2017 18:20:02 +0000 Subject: [PATCH 01/75] zebra: "debug zebra packet" config display Signed-off-by: Daniel Walton --- zebra/debug.c | 12 +++++------- 1 file changed, 5 insertions(+), 7 deletions(-) diff --git a/zebra/debug.c b/zebra/debug.c index dfee6b74c0..fc2cd44e5f 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -145,17 +145,15 @@ DEFUN (debug_zebra_packet, if (argv_find(argv, argc, "send", &idx)) SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); - idx = 0; - if (argv_find(argv, argc, "recv", &idx)) + else if (argv_find(argv, argc, "recv", &idx)) SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); - idx = 0; - if (argv_find(argv, argc, "detail", &idx)) - SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL); - - if (!(zebra_debug_packet & ZEBRA_DEBUG_SEND & ZEBRA_DEBUG_RECV)) { + else { SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); } + + if (argv_find(argv, argc, "detail", &idx)) + SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL); return CMD_SUCCESS; } From a72730d34a8ca9ecd91b356c8e70914ccbccc8a7 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 20 Jul 2017 11:48:52 -0400 Subject: [PATCH 02/75] eigrpd, vtysh: add dummy route-map cli eigrpd will successfully accept `(conf)# route-map foo ...` because it is not sent to eigrpd from vtysh, but of course, this is the classic node sync syndrome. Since eigrpd apparently doesn't support proper routemaps yet just add the cli so we can suppress the vtysh errors. Signed-off-by: Quentin Young --- eigrpd/eigrp_main.c | 7 ++++++- vtysh/vtysh.h | 2 +- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/eigrpd/eigrp_main.c b/eigrpd/eigrp_main.c index d593f5ceea..e7532778a9 100644 --- a/eigrpd/eigrp_main.c +++ b/eigrpd/eigrp_main.c @@ -50,7 +50,7 @@ #include "keychain.h" #include "distribute.h" #include "libfrr.h" -//#include "routemap.h" +#include "routemap.h" //#include "if_rmap.h" #include "eigrpd/eigrp_structs.h" @@ -194,6 +194,11 @@ int main(int argc, char **argv, char **envp) prefix_list_add_hook(eigrp_distribute_update_all); prefix_list_delete_hook(eigrp_distribute_update_all); + /* + * XXX: This is just to get the CLI installed to suppress VTYSH errors. + * Routemaps in EIGRP are not yet functional. + */ + route_map_init(); /*eigrp_route_map_init(); route_map_add_hook (eigrp_rmap_update); route_map_delete_hook (eigrp_rmap_update);*/ diff --git a/vtysh/vtysh.h b/vtysh/vtysh.h index 67ee8898c9..bef4b82d3f 100644 --- a/vtysh/vtysh.h +++ b/vtysh/vtysh.h @@ -44,7 +44,7 @@ DECLARE_MGROUP(MVTYSH) * run on it (logging & co. should stay in a fixed/frozen config, and * things like prefix lists are not even initialised) */ #define VTYSH_ALL VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_LDPD|VTYSH_BGPD|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD -#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_PIMD +#define VTYSH_RMAP VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_BGPD|VTYSH_PIMD|VTYSH_EIGRPD #define VTYSH_INTERFACE VTYSH_ZEBRA|VTYSH_RIPD|VTYSH_RIPNGD|VTYSH_OSPFD|VTYSH_OSPF6D|VTYSH_ISISD|VTYSH_PIMD|VTYSH_NHRPD|VTYSH_EIGRPD|VTYSH_BABELD #define VTYSH_NS VTYSH_ZEBRA #define VTYSH_VRF VTYSH_ZEBRA From 874402831268edb872774f18b2d5701d604f3530 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Thu, 20 Jul 2017 17:11:43 +0000 Subject: [PATCH 03/75] lib: copy_nexthops() only copies the first nexthop Signed-off-by: Daniel Walton Before the fix NHT had each path resolving via swp1 cel-redxp-10# show ip route 20.0.11.253 Routing entry for 20.0.11.0/24 Known via "bgp", distance 20, metric 0, best Last update 00:00:20 ago * 169.254.0.1, via swp1 * 169.254.0.17, via swp2 cel-redxp-10# cel-redxp-10# show ip nht [snip] 20.0.11.253 resolved via bgp via 169.254.0.1, swp1 via 169.254.0.1, swp1 Client list: pim(fd 19) After the fix cel-redxp-10# show ip nht [snip] 20.0.11.253 resolved via bgp via 169.254.0.1, swp1 via 169.254.0.17, swp2 Client list: pim(fd 19) --- lib/nexthop.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/lib/nexthop.c b/lib/nexthop.c index 9b0c2d73f4..7180be33dd 100644 --- a/lib/nexthop.c +++ b/lib/nexthop.c @@ -133,17 +133,17 @@ void copy_nexthops(struct nexthop **tnh, struct nexthop *nh, for (nh1 = nh; nh1; nh1 = nh1->next) { nexthop = nexthop_new(); - nexthop->ifindex = nh->ifindex; - nexthop->type = nh->type; - nexthop->flags = nh->flags; - memcpy(&nexthop->gate, &nh->gate, sizeof(nh->gate)); - memcpy(&nexthop->src, &nh->src, sizeof(nh->src)); - memcpy(&nexthop->rmap_src, &nh->rmap_src, sizeof(nh->rmap_src)); + nexthop->ifindex = nh1->ifindex; + nexthop->type = nh1->type; + nexthop->flags = nh1->flags; + memcpy(&nexthop->gate, &nh1->gate, sizeof(nh1->gate)); + memcpy(&nexthop->src, &nh1->src, sizeof(nh1->src)); + memcpy(&nexthop->rmap_src, &nh1->rmap_src, sizeof(nh1->rmap_src)); nexthop->rparent = rparent; - if (nh->nh_label) - nexthop_add_labels(nexthop, nh->nh_label_type, - nh->nh_label->num_labels, - &nh->nh_label->label[0]); + if (nh1->nh_label) + nexthop_add_labels(nexthop, nh1->nh_label_type, + nh1->nh_label->num_labels, + &nh1->nh_label->label[0]); nexthop_add(tnh, nexthop); if (CHECK_FLAG(nh1->flags, NEXTHOP_FLAG_RECURSIVE)) From ead99d5f26abef2490c1ee89a0126bfd15181182 Mon Sep 17 00:00:00 2001 From: Olivier Dugeon Date: Thu, 20 Jul 2017 19:57:43 +0200 Subject: [PATCH 04/75] OSPF OPAQUE, TE and RI macro refactoring & cleanup * TLV macros where define itwice in ospf_te.h and in ospf_ri.h * Merge both definition in ospf_opaque.h and adjust accordingly RI and TE * Same for typedef status_t which is move in ospfd.h * Remove also all 'goto' statement in ospf_te.c and ospf_ri.c * Remove strange function lookup_oi_by_ifp() in ospf_te.c and replace it by a valid code in initialize_linkparams() function Signed-off-by: Olivier Dugeon --- ospfd/ospf_opaque.h | 41 +++++++ ospfd/ospf_ri.c | 269 ++++++++++++++++++++++---------------------- ospfd/ospf_ri.h | 42 +++---- ospfd/ospf_te.c | 242 +++++++++++++++++---------------------- ospfd/ospf_te.h | 134 +++++++++------------- ospfd/ospfd.h | 3 + 6 files changed, 344 insertions(+), 387 deletions(-) diff --git a/ospfd/ospf_opaque.h b/ospfd/ospf_opaque.h index 8bad51e65e..88a6854b84 100644 --- a/ospfd/ospf_opaque.h +++ b/ospfd/ospf_opaque.h @@ -77,6 +77,47 @@ ((ntohs((lsahdr)->length) >= sizeof(struct lsa_header)) \ && ((ntohs((lsahdr)->length) % sizeof(u_int32_t)) == 0)) +/* + * Following section defines generic TLV (type, length, value) macros, + * used for various LSA opaque usage e.g. Traffic Engineering. + */ +struct tlv_header +{ + u_int16_t type; /* Type of Value */ + u_int16_t length; /* Length of Value portion only, in bytes */ +}; + +#define TLV_HDR_SIZE \ + (sizeof (struct tlv_header)) + +#define TLV_BODY_SIZE(tlvh) \ + (ROUNDUP (ntohs ((tlvh)->length), sizeof (u_int32_t))) + +#define TLV_SIZE(tlvh) \ + (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh)) + +#define TLV_HDR_TOP(lsah) \ + (struct tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE) + +#define TLV_HDR_NEXT(tlvh) \ + (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh)) + +#define TLV_HDR_SUBTLV(tlvh) \ + (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE) + +#define TLV_DATA(tlvh) (void *)((char *)(tlvh) + TLV_HDR_SIZE) + +#define TLV_TYPE(tlvh) tlvh.header.type +#define TLV_LEN(tlvh) tlvh.header.length +#define TLV_HDR(tlvh) tlvh.header + +/* Following declaration concerns the Opaque LSA management */ +typedef enum _opcode_t { + REORIGINATE_THIS_LSA, + REFRESH_THIS_LSA, + FLUSH_THIS_LSA +} opcode_t; + /* Prototypes. */ extern void ospf_opaque_init(void); diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index 26d2ed7d13..2136f2eb64 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -58,9 +58,9 @@ #include "ospfd/ospf_ri.h" #include "ospfd/ospf_te.h" +/* Store Router Information PCE TLV and SubTLV in network byte order. */ struct ospf_pce_info { - - /* Store Router Information PCE TLV and SubTLV in network byte order. */ + status_t status; struct ri_tlv_pce pce_header; struct ri_pce_subtlv_address pce_address; struct ri_pce_subtlv_path_scope pce_scope; @@ -77,9 +77,8 @@ struct ospf_router_info { u_int8_t scope; /* Flags to manage this router information. */ -#define RIFLG_LOOKUP_DONE 0x1 -#define RIFLG_LSA_ENGAGED 0x2 -#define RIFLG_LSA_FORCED_REFRESH 0x4 +#define RIFLG_LSA_ENGAGED 0x1 +#define RIFLG_LSA_FORCED_REFRESH 0x2 u_int32_t flags; /* area pointer if flooding is Type 10 Null if flooding is AS scope */ @@ -120,12 +119,13 @@ int ospf_router_info_init(void) { memset(&OspfRI, 0, sizeof(struct ospf_router_info)); - OspfRI.status = disabled; + OspfRI.status = disable; OspfRI.registered = 0; OspfRI.scope = OSPF_OPAQUE_AS_LSA; OspfRI.flags = 0; /* Initialize pce domain and neighbor list */ + OspfRI.pce_info.status = disable; OspfRI.pce_info.pce_domain = list_new(); OspfRI.pce_info.pce_domain->del = del_pce_info; OspfRI.pce_info.pce_neighbor = list_new(); @@ -141,7 +141,7 @@ static int ospf_router_info_register(u_int8_t scope) int rc = 0; if (OspfRI.registered) - return 0; + return rc; zlog_info("Register Router Information with scope %s(%d)", scope == OSPF_OPAQUE_AREA_LSA ? "Area" : "AS", scope); @@ -165,7 +165,7 @@ static int ospf_router_info_register(u_int8_t scope) OspfRI.registered = 1; OspfRI.scope = scope; - return 0; + return rc; } static int ospf_router_info_unregister() @@ -193,7 +193,7 @@ void ospf_router_info_term(void) OspfRI.pce_info.pce_domain = NULL; OspfRI.pce_info.pce_neighbor = NULL; - OspfRI.status = disabled; + OspfRI.status = disable; ospf_router_info_unregister(); @@ -229,34 +229,36 @@ static int set_pce_header(struct ospf_pce_info *pce) /* PCE Address */ if (ntohs(pce->pce_address.header.type) != 0) - length += RI_TLV_SIZE(&pce->pce_address.header); + length += TLV_SIZE(&pce->pce_address.header); /* PCE Path Scope */ if (ntohs(pce->pce_scope.header.type) != 0) - length += RI_TLV_SIZE(&pce->pce_scope.header); + length += TLV_SIZE(&pce->pce_scope.header); /* PCE Domain */ for (ALL_LIST_ELEMENTS_RO(pce->pce_domain, node, domain)) { if (ntohs(domain->header.type) != 0) - length += RI_TLV_SIZE(&domain->header); + length += TLV_SIZE(&domain->header); } /* PCE Neighbor */ for (ALL_LIST_ELEMENTS_RO(pce->pce_neighbor, node, neighbor)) { if (ntohs(neighbor->header.type) != 0) - length += RI_TLV_SIZE(&neighbor->header); + length += TLV_SIZE(&neighbor->header); } /* PCE Capabilities */ if (ntohs(pce->pce_cap_flag.header.type) != 0) - length += RI_TLV_SIZE(&pce->pce_cap_flag.header); + length += TLV_SIZE(&pce->pce_cap_flag.header); if (length != 0) { pce->pce_header.header.type = htons(RI_TLV_PCE); pce->pce_header.header.length = htons(length); + pce->status = enable; } else { pce->pce_header.header.type = 0; pce->pce_header.header.length = 0; + pce->status = disable; } return length; @@ -279,8 +281,6 @@ static void set_pce_address(struct in_addr ipv4, struct ospf_pce_info *pce) static void set_pce_path_scope(u_int32_t scope, struct ospf_pce_info *pce) { - /* Enable PCE Info */ - pce->pce_header.header.type = htons(RI_TLV_PCE); /* Set PCE Scope */ pce->pce_scope.header.type = htons(RI_PCE_SUBTLV_PATH_SCOPE); pce->pce_scope.header.length = htons(RI_TLV_LENGTH); @@ -295,9 +295,6 @@ static void set_pce_domain(u_int16_t type, u_int32_t domain, struct ri_pce_subtlv_domain *new; - /* Enable PCE Info */ - pce->pce_header.header.type = htons(RI_TLV_PCE); - /* Create new domain info */ new = XCALLOC(MTYPE_OSPF_PCE_PARAMS, sizeof(struct ri_pce_subtlv_domain)); @@ -348,9 +345,6 @@ static void set_pce_neighbor(u_int16_t type, u_int32_t domain, struct ri_pce_subtlv_neighbor *new; - /* Enable PCE Info */ - pce->pce_header.header.type = htons(RI_TLV_PCE); - /* Create new neighbor info */ new = XCALLOC(MTYPE_OSPF_PCE_PARAMS, sizeof(struct ri_pce_subtlv_neighbor)); @@ -399,8 +393,6 @@ static void unset_pce_neighbor(u_int16_t type, u_int32_t domain, static void set_pce_cap_flag(u_int32_t cap, struct ospf_pce_info *pce) { - /* Enable PCE Info */ - pce->pce_header.header.type = htons(RI_TLV_PCE); /* Set PCE Capabilities flag */ pce->pce_cap_flag.header.type = htons(RI_PCE_SUBTLV_CAP_FLAG); pce->pce_cap_flag.header.length = htons(RI_TLV_LENGTH); @@ -410,12 +402,12 @@ static void set_pce_cap_flag(u_int32_t cap, struct ospf_pce_info *pce) } -static void unset_param(struct ri_tlv_header *tlv) +static void unset_param(struct tlv_header *tlv) { tlv->type = 0; /* Fill the Value to 0 */ - memset((tlv + RI_TLV_HDR_SIZE), 0, RI_TLV_BODY_SIZE(tlv)); + memset(TLV_DATA(tlv), 0, TLV_BODY_SIZE(tlv)); tlv->length = 0; return; @@ -423,14 +415,13 @@ static void unset_param(struct ri_tlv_header *tlv) static void initialize_params(struct ospf_router_info *ori) { - u_int32_t cap; + u_int32_t cap = 0; struct ospf *top; /* * Initialize default Router Information Capabilities. */ - cap = 0; - cap = cap | RI_TE_SUPPORT; + cap = RI_TE_SUPPORT; set_router_info_capabilities(&ori->router_cap, cap); @@ -462,9 +453,6 @@ static void initialize_params(struct ospf_router_info *ori) | PCE_CAP_ADDITIVE | PCE_CAP_MULTIPLE_REQ; set_pce_cap_flag(cap, &ori->pce_info); - /* Finally compute PCE header */ - set_pce_header(&ori->pce_info); - return; } @@ -473,16 +461,15 @@ static int is_mandated_params_set(struct ospf_router_info ori) int rc = 0; if (ntohs(ori.router_cap.header.type) == 0) - goto out; + return rc; if ((ntohs(ori.pce_info.pce_header.header.type) == RI_TLV_PCE) && (ntohs(ori.pce_info.pce_address.header.type) == 0) && (ntohs(ori.pce_info.pce_cap_flag.header.type) == 0)) - goto out; + return rc; rc = 1; -out: return rc; } @@ -499,7 +486,6 @@ static void ospf_router_info_ism_change(struct ospf_interface *oi, static void ospf_router_info_nsm_change(struct ospf_neighbor *nbr, int old_state) { - /* So far, nothing to do here. */ return; } @@ -508,19 +494,19 @@ static void ospf_router_info_nsm_change(struct ospf_neighbor *nbr, * Followings are OSPF protocol processing functions for ROUTER INFORMATION *------------------------------------------------------------------------*/ -static void build_tlv_header(struct stream *s, struct ri_tlv_header *tlvh) +static void build_tlv_header(struct stream *s, struct tlv_header *tlvh) { - stream_put(s, tlvh, sizeof(struct ri_tlv_header)); + stream_put(s, tlvh, sizeof(struct tlv_header)); return; } -static void build_tlv(struct stream *s, struct ri_tlv_header *tlvh) +static void build_tlv(struct stream *s, struct tlv_header *tlvh) { if (ntohs(tlvh->type) != 0) { build_tlv_header(s, tlvh); - stream_put(s, tlvh + 1, RI_TLV_BODY_SIZE(tlvh)); + stream_put(s, tlvh + 1, TLV_BODY_SIZE(tlvh)); } return; } @@ -535,9 +521,11 @@ static void ospf_router_info_lsa_body_set(struct stream *s) /* Build Router Information TLV */ build_tlv(s, &OspfRI.router_cap.header); - /* Add RI PCE TLV if it is set */ /* Compute PCE Info header first */ - if ((set_pce_header(&OspfRI.pce_info)) != 0) { + set_pce_header (&OspfRI.pce_info); + + /* Add RI PCE TLV if it is set */ + if (OspfRI.pce_info.status == enable) { /* Build PCE TLV */ build_tlv_header(s, &OspfRI.pce_info.pce_header.header); @@ -580,7 +568,7 @@ static struct ospf_lsa *ospf_router_info_lsa_new() /* Create a stream for LSA. */ if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { zlog_warn("ospf_router_info_lsa_new: stream_new() ?"); - goto out; + return NULL; } lsah = (struct lsa_header *)STREAM_DATA(s); @@ -614,14 +602,14 @@ static struct ospf_lsa *ospf_router_info_lsa_new() if ((new = ospf_lsa_new()) == NULL) { zlog_warn("ospf_router_info_lsa_new: ospf_lsa_new() ?"); stream_free(s); - goto out; + return NULL; } if ((new->data = ospf_lsa_data_new(length)) == NULL) { zlog_warn("ospf_router_info_lsa_new: ospf_lsa_data_new() ?"); ospf_lsa_unlock(&new); new = NULL; stream_free(s); - goto out; + return new; } new->area = OspfRI.area; /* Area must be null if the Opaque type is AS @@ -631,7 +619,6 @@ static struct ospf_lsa *ospf_router_info_lsa_new() memcpy(new->data, lsah, length); stream_free(s); -out: return new; } @@ -648,7 +635,7 @@ static int ospf_router_info_lsa_originate1(void *arg) if (area->area_id.s_addr != OspfRI.area_id.s_addr) { zlog_debug( "RI -> This is not the Router Information Area. Stop processing"); - goto out; + return rc; } OspfRI.area = area; } @@ -657,7 +644,7 @@ static int ospf_router_info_lsa_originate1(void *arg) if ((new = ospf_router_info_lsa_new()) == NULL) { zlog_warn( "ospf_router_info_lsa_originate1: ospf_router_info_lsa_new() ?"); - goto out; + return rc; } /* Get ospf info */ @@ -668,7 +655,7 @@ static int ospf_router_info_lsa_originate1(void *arg) zlog_warn( "ospf_router_info_lsa_originate1: ospf_lsa_install() ?"); ospf_lsa_unlock(&new); - goto out; + return rc; } /* Now this Router Info parameter entry has associated LSA. */ @@ -691,7 +678,6 @@ static int ospf_router_info_lsa_originate1(void *arg) } rc = 0; -out: return rc; } @@ -700,17 +686,17 @@ static int ospf_router_info_lsa_originate(void *arg) int rc = -1; - if (OspfRI.status == disabled) { + if (OspfRI.status == disable) { zlog_info( "ospf_router_info_lsa_originate: ROUTER INFORMATION is disabled now."); rc = 0; /* This is not an error case. */ - goto out; + return rc; } /* Check if Router Information LSA is already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) { - if (OspfRI.flags & RIFLG_LSA_FORCED_REFRESH) { - OspfRI.flags &= ~RIFLG_LSA_FORCED_REFRESH; + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) { + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_FORCED_REFRESH) { + UNSET_FLAG(OspfRI.flags, RIFLG_LSA_FORCED_REFRESH); ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } } else { @@ -720,11 +706,10 @@ static int ospf_router_info_lsa_originate(void *arg) /* Ok, let's try to originate an LSA */ if (ospf_router_info_lsa_originate1(arg) != 0) - goto out; + return rc; } rc = 0; -out: return rc; } @@ -733,7 +718,7 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa) struct ospf_lsa *new = NULL; struct ospf *top; - if (OspfRI.status == disabled) { + if (OspfRI.status == disable) { /* * This LSA must have flushed before due to ROUTER INFORMATION * status change. @@ -749,21 +734,21 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa) if (GET_OPAQUE_ID(ntohl(lsa->data->id.s_addr)) != 0) { zlog_warn( "ospf_router_info_lsa_refresh: Unsupported Router Information ID"); - goto out; + return NULL; } /* If the lsa's age reached to MaxAge, start flushing procedure. */ if (IS_LSA_MAXAGE(lsa)) { - OspfRI.flags &= ~RIFLG_LSA_ENGAGED; + UNSET_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED); ospf_opaque_lsa_flush_schedule(lsa); - goto out; + return NULL; } /* Create new Opaque-LSA/ROUTER INFORMATION instance. */ if ((new = ospf_router_info_lsa_new()) == NULL) { zlog_warn( "ospf_router_info_lsa_refresh: ospf_router_info_lsa_new() ?"); - goto out; + return NULL; } new->data->ls_seqnum = lsa_seqnum_increment(lsa); @@ -773,7 +758,7 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa) if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) { zlog_warn("ospf_router_info_lsa_refresh: ospf_lsa_install() ?"); ospf_lsa_unlock(&new); - goto out; + return new; } /* Flood updated LSA through AS or AREA depending of OspfRI.scope. */ @@ -790,7 +775,6 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa) ospf_lsa_header_dump(new->data); } -out: return new; } @@ -809,6 +793,13 @@ static void ospf_router_info_lsa_schedule(opcode_t opcode) opcode == REFRESH_THIS_LSA ? "Refresh" : "", opcode == FLUSH_THIS_LSA ? "Flush" : ""); + /* Check LSA flags state coherence */ + if (!CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) && (opcode != REORIGINATE_THIS_LSA)) + return; + + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) && (opcode == REORIGINATE_THIS_LSA)) + opcode = REFRESH_THIS_LSA; + top = ospf_lookup(); if ((OspfRI.scope == OSPF_OPAQUE_AREA_LSA) && (OspfRI.area == NULL)) { zlog_warn( @@ -838,7 +829,7 @@ static void ospf_router_info_lsa_schedule(opcode_t opcode) ospf_opaque_lsa_refresh_schedule(&lsa); break; case FLUSH_THIS_LSA: - OspfRI.flags &= ~RIFLG_LSA_ENGAGED; + UNSET_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED); ospf_opaque_lsa_flush_schedule(&lsa); break; default: @@ -855,7 +846,7 @@ static void ospf_router_info_lsa_schedule(opcode_t opcode) *------------------------------------------------------------------------*/ static u_int16_t show_vty_router_cap(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { struct ri_tlv_router_cap *top = (struct ri_tlv_router_cap *)tlvh; @@ -865,11 +856,11 @@ static u_int16_t show_vty_router_cap(struct vty *vty, else zlog_debug(" Router Capabilities: 0x%x", ntohl(top->value)); - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } static u_int16_t show_vty_pce_subtlv_address(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { struct ri_pce_subtlv_address *top = (struct ri_pce_subtlv_address *)tlvh; @@ -891,11 +882,11 @@ static u_int16_t show_vty_pce_subtlv_address(struct vty *vty, ntohl(top->address.value.s_addr)); } - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } static u_int16_t show_vty_pce_subtlv_path_scope(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { struct ri_pce_subtlv_path_scope *top = (struct ri_pce_subtlv_path_scope *)tlvh; @@ -905,11 +896,11 @@ static u_int16_t show_vty_pce_subtlv_path_scope(struct vty *vty, else zlog_debug(" PCE Path Scope: 0x%x", ntohl(top->value)); - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } static u_int16_t show_vty_pce_subtlv_domain(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { struct ri_pce_subtlv_domain *top = (struct ri_pce_subtlv_domain *)tlvh; struct in_addr tmp; @@ -927,11 +918,11 @@ static u_int16_t show_vty_pce_subtlv_domain(struct vty *vty, else zlog_debug(" PCE domain AS: %d", ntohl(top->value)); } - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } static u_int16_t show_vty_pce_subtlv_neighbor(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { struct ri_pce_subtlv_neighbor *top = @@ -953,11 +944,11 @@ static u_int16_t show_vty_pce_subtlv_neighbor(struct vty *vty, zlog_debug(" PCE neighbor AS: %d", ntohl(top->value)); } - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } static u_int16_t show_vty_pce_subtlv_cap_flag(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { struct ri_pce_subtlv_cap_flag *top = (struct ri_pce_subtlv_cap_flag *)tlvh; @@ -969,11 +960,11 @@ static u_int16_t show_vty_pce_subtlv_cap_flag(struct vty *vty, zlog_debug(" PCE Capabilities Flag: 0x%x", ntohl(top->value)); - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } static u_int16_t show_vty_unknown_tlv(struct vty *vty, - struct ri_tlv_header *tlvh) + struct tlv_header *tlvh) { if (vty != NULL) vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n", @@ -982,16 +973,16 @@ static u_int16_t show_vty_unknown_tlv(struct vty *vty, zlog_debug(" Unknown TLV: [type(0x%x), length(0x%x)]", ntohs(tlvh->type), ntohs(tlvh->length)); - return RI_TLV_SIZE(tlvh); + return TLV_SIZE(tlvh); } -static u_int16_t show_vty_pce_info(struct vty *vty, struct ri_tlv_header *ri, +static u_int16_t show_vty_pce_info(struct vty *vty, struct tlv_header *ri, uint32_t total) { - struct ri_tlv_header *tlvh; + struct tlv_header *tlvh; u_int16_t sum = 0; - for (tlvh = ri; sum < total; tlvh = RI_TLV_HDR_NEXT(tlvh)) { + for (tlvh = ri; sum < total; tlvh = TLV_HDR_NEXT(tlvh)) { switch (ntohs(tlvh->type)) { case RI_PCE_SUBTLV_ADDRESS: sum += show_vty_pce_subtlv_address(vty, tlvh); @@ -1019,21 +1010,21 @@ static u_int16_t show_vty_pce_info(struct vty *vty, struct ri_tlv_header *ri, static void ospf_router_info_show_info(struct vty *vty, struct ospf_lsa *lsa) { struct lsa_header *lsah = (struct lsa_header *)lsa->data; - struct ri_tlv_header *tlvh; + struct tlv_header *tlvh; u_int16_t length = 0, sum = 0; /* Initialize TLV browsing */ length = ntohs(lsah->length) - OSPF_LSA_HEADER_SIZE; - for (tlvh = RI_TLV_HDR_TOP(lsah); sum < length; - tlvh = RI_TLV_HDR_NEXT(tlvh)) { + for (tlvh = TLV_HDR_TOP(lsah); sum < length; + tlvh = TLV_HDR_NEXT(tlvh)) { switch (ntohs(tlvh->type)) { case RI_TLV_CAPABILITIES: sum += show_vty_router_cap(vty, tlvh); break; case RI_TLV_PCE: tlvh++; - sum += RI_TLV_HDR_SIZE; + sum += TLV_HDR_SIZE; sum += show_vty_pce_info(vty, tlvh, length - sum); break; default: @@ -1053,50 +1044,53 @@ static void ospf_router_info_config_write_router(struct vty *vty) struct ri_pce_subtlv_neighbor *neighbor; struct in_addr tmp; - if (OspfRI.status == enabled) { + if (OspfRI.status == enable) { if (OspfRI.scope == OSPF_OPAQUE_AS_LSA) vty_out(vty, " router-info as\n"); else vty_out(vty, " router-info area %s\n", inet_ntoa(OspfRI.area_id)); - if (pce->pce_address.header.type != 0) - vty_out(vty, " pce address %s\n", - inet_ntoa(pce->pce_address.address.value)); + if (OspfRI.pce_info.status == enable) { - if (pce->pce_cap_flag.header.type != 0) - vty_out(vty, " pce flag 0x%x\n", - ntohl(pce->pce_cap_flag.value)); + if (pce->pce_address.header.type != 0) + vty_out(vty, " pce address %s\n", + inet_ntoa(pce->pce_address.address.value)); - for (ALL_LIST_ELEMENTS_RO(pce->pce_domain, node, domain)) { - if (domain->header.type != 0) { - if (domain->type == PCE_DOMAIN_TYPE_AREA) { - tmp.s_addr = domain->value; - vty_out(vty, " pce domain area %s\n", - inet_ntoa(tmp)); - } else { - vty_out(vty, " pce domain as %d\n", - ntohl(domain->value)); + if (pce->pce_cap_flag.header.type != 0) + vty_out(vty, " pce flag 0x%x\n", + ntohl(pce->pce_cap_flag.value)); + + for (ALL_LIST_ELEMENTS_RO(pce->pce_domain, node, domain)) { + if (domain->header.type != 0) { + if (domain->type == PCE_DOMAIN_TYPE_AREA) { + tmp.s_addr = domain->value; + vty_out(vty, " pce domain area %s\n", + inet_ntoa(tmp)); + } else { + vty_out(vty, " pce domain as %d\n", + ntohl(domain->value)); + } } } - } - for (ALL_LIST_ELEMENTS_RO(pce->pce_neighbor, node, neighbor)) { - if (neighbor->header.type != 0) { - if (neighbor->type == PCE_DOMAIN_TYPE_AREA) { - tmp.s_addr = neighbor->value; - vty_out(vty, " pce neighbor area %s\n", - inet_ntoa(tmp)); - } else { - vty_out(vty, " pce neighbor as %d\n", - ntohl(neighbor->value)); + for (ALL_LIST_ELEMENTS_RO(pce->pce_neighbor, node, neighbor)) { + if (neighbor->header.type != 0) { + if (neighbor->type == PCE_DOMAIN_TYPE_AREA) { + tmp.s_addr = neighbor->value; + vty_out(vty, " pce neighbor area %s\n", + inet_ntoa(tmp)); + } else { + vty_out(vty, " pce neighbor as %d\n", + ntohl(neighbor->value)); + } } } - } - if (pce->pce_scope.header.type != 0) - vty_out(vty, " pce scope 0x%x\n", - ntohl(OspfRI.pce_info.pce_scope.value)); + if (pce->pce_scope.header.type != 0) + vty_out(vty, " pce scope 0x%x\n", + ntohl(OspfRI.pce_info.pce_scope.value)); + } } return; } @@ -1118,7 +1112,7 @@ DEFUN (router_info, u_int8_t scope; - if (OspfRI.status == enabled) + if (OspfRI.status == enable) return CMD_SUCCESS; /* Check and get Area value if present */ @@ -1137,11 +1131,11 @@ DEFUN (router_info, /* First start to register Router Information callbacks */ if ((ospf_router_info_register(scope)) != 0) { zlog_warn( - "Enable to register Router Information callbacks. Abort!"); + "Unable to register Router Information callbacks. Abort!"); return CMD_WARNING_CONFIG_FAILED; } - OspfRI.status = enabled; + OspfRI.status = enable; if (IS_DEBUG_OSPF_EVENT) zlog_debug("RI-> Router Information (%s flooding): OFF -> ON", @@ -1160,7 +1154,10 @@ DEFUN (router_info, initialize_params(&OspfRI); /* Refresh RI LSA if already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) { + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) { + zlog_debug ("RI-> Refresh LSA following configuration"); + ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); + } else { zlog_debug("RI-> Initial origination following configuration"); ospf_router_info_lsa_schedule(REORIGINATE_THIS_LSA); } @@ -1175,26 +1172,26 @@ DEFUN (no_router_info, "Disable the Router Information functionality\n") { - if (OspfRI.status == disabled) + if (OspfRI.status == disable) return CMD_SUCCESS; if (IS_DEBUG_OSPF_EVENT) zlog_debug("RI-> Router Information: ON -> OFF"); - if (OspfRI.flags & RIFLG_LSA_ENGAGED) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(FLUSH_THIS_LSA); /* Unregister the callbacks */ ospf_router_info_unregister(); - OspfRI.status = disabled; + OspfRI.status = disable; return CMD_SUCCESS; } static int ospf_ri_enabled(struct vty *vty) { - if (OspfRI.status == enabled) + if (OspfRI.status == enable) return 1; if (vty) @@ -1229,7 +1226,7 @@ DEFUN (pce_address, set_pce_address(value, pi); /* Refresh RI LSA if already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -1248,7 +1245,7 @@ DEFUN (no_pce_address, unset_param(&OspfRI.pce_info.pce_address.header); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1279,7 +1276,7 @@ DEFUN (pce_path_scope, set_pce_path_scope(scope, pi); /* Refresh RI LSA if already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -1298,7 +1295,7 @@ DEFUN (no_pce_path_scope, unset_param(&OspfRI.pce_info.pce_address.header); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1337,7 +1334,7 @@ DEFUN (pce_domain, set_pce_domain(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1367,7 +1364,7 @@ DEFUN (no_pce_domain, unset_pce_domain(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1407,7 +1404,7 @@ DEFUN (pce_neigbhor, set_pce_neighbor(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1437,7 +1434,7 @@ DEFUN (no_pce_neighbor, unset_pce_neighbor(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1469,7 +1466,7 @@ DEFUN (pce_cap_flag, set_pce_cap_flag(cap, pce); /* Refresh RI LSA if already engaged */ - if (OspfRI.flags & RIFLG_LSA_ENGAGED) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -1487,7 +1484,7 @@ DEFUN (no_pce_cap_flag, unset_param(&OspfRI.pce_info.pce_cap_flag.header); /* Refresh RI LSA if already engaged */ - if ((OspfRI.status == enabled) && (OspfRI.flags & RIFLG_LSA_ENGAGED)) + if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1502,7 +1499,7 @@ DEFUN (show_ip_ospf_router_info, "Router Information\n") { - if (OspfRI.status == enabled) { + if (OspfRI.status == enable) { vty_out(vty, "--- Router Information parameters ---\n"); show_vty_router_cap(vty, &OspfRI.router_cap.header); } else { @@ -1528,7 +1525,7 @@ DEFUN (show_ip_opsf_router_info_pce, struct ri_pce_subtlv_domain *domain; struct ri_pce_subtlv_neighbor *neighbor; - if (OspfRI.status == enabled) { + if (OspfRI.status == enable) { vty_out(vty, "--- PCE parameters ---\n"); if (pce->pce_address.header.type != 0) diff --git a/ospfd/ospf_ri.h b/ospfd/ospf_ri.h index 50221b25c5..2d90730d93 100644 --- a/ospfd/ospf_ri.h +++ b/ospfd/ospf_ri.h @@ -64,21 +64,6 @@ * +--------+--------+--------+--------+ --- */ -/* - * Following section defines TLV (tag, length, value) structures, - * used for Router Information. - */ -struct ri_tlv_header { - u_int16_t type; /* RI_TLV_XXX (see below) */ - u_int16_t length; /* Value portion only, in byte */ -}; - -#define RI_TLV_HDR_SIZE (sizeof (struct ri_tlv_header)) -#define RI_TLV_BODY_SIZE(tlvh) (ROUNDUP (ntohs ((tlvh)->length), sizeof (u_int32_t))) -#define RI_TLV_SIZE(tlvh) (RI_TLV_HDR_SIZE + RI_TLV_BODY_SIZE(tlvh)) -#define RI_TLV_HDR_TOP(lsah) (struct ri_tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE) -#define RI_TLV_HDR_NEXT(tlvh) (struct ri_tlv_header *)((char *)(tlvh) + RI_TLV_SIZE(tlvh)) - /* * Following section defines TLV body parts. */ @@ -91,7 +76,7 @@ struct ri_tlv_header { #define RI_TLV_CAPABILITIES 1 struct ri_tlv_router_cap { - struct ri_tlv_header header; /* Value length is 4 bytes. */ + struct tlv_header header; /* Value length is 4 bytes. */ u_int32_t value; }; @@ -109,23 +94,19 @@ struct ri_tlv_router_cap { #define RI_TLV_PCE 6 struct ri_tlv_pce { - struct ri_tlv_header header; + struct tlv_header header; /* A set of PCE-sub-TLVs will follow. */ }; /* PCE Address Sub-TLV */ /* Mandatory */ #define RI_PCE_SUBTLV_ADDRESS 1 struct ri_pce_subtlv_address { - struct ri_tlv_header - header; /* Type = 1; Length is 8 (IPv4) or 20 (IPv6) bytes. */ - /* $FRR indent$ */ - /* clang-format off */ + /* Type = 1; Length is 8 (IPv4) or 20 (IPv6) bytes. */ + struct tlv_header header; #define PCE_ADDRESS_LENGTH_IPV4 8 #define PCE_ADDRESS_LENGTH_IPV6 20 struct { u_int16_t type; /* Address type: 1 = IPv4, 2 = IPv6 */ - /* $FRR indent$ */ - /* clang-format off */ #define PCE_ADDRESS_TYPE_IPV4 1 #define PCE_ADDRESS_TYPE_IPV6 2 u_int16_t reserved; @@ -136,9 +117,12 @@ struct ri_pce_subtlv_address { /* PCE Path-Scope Sub-TLV */ /* Mandatory */ #define RI_PCE_SUBTLV_PATH_SCOPE 2 struct ri_pce_subtlv_path_scope { - struct ri_tlv_header header; /* Type = 2; Length = 4 bytes. */ - u_int32_t value; /* L, R, Rd, S, Sd, Y, PrefL, PrefR, PrefS and PrefY - bits see RFC5088 page 9 */ + struct tlv_header header; /* Type = 2; Length = 4 bytes. */ + /* + * L, R, Rd, S, Sd, Y, PrefL, PrefR, PrefS and PrefY bits: + * see RFC5088 page 9 + */ + u_int32_t value; }; /* PCE Domain Sub-TLV */ /* Optional */ @@ -148,7 +132,7 @@ struct ri_pce_subtlv_path_scope { #define PCE_DOMAIN_TYPE_AS 2 struct ri_pce_subtlv_domain { - struct ri_tlv_header header; /* Type = 3; Length = 8 bytes. */ + struct tlv_header header; /* Type = 3; Length = 8 bytes. */ u_int16_t type; /* Domain type: 1 = OSPF Area ID, 2 = AS Number */ u_int16_t reserved; u_int32_t value; @@ -157,7 +141,7 @@ struct ri_pce_subtlv_domain { /* PCE Neighbor Sub-TLV */ /* Mandatory if R or S bit is set */ #define RI_PCE_SUBTLV_NEIGHBOR 4 struct ri_pce_subtlv_neighbor { - struct ri_tlv_header header; /* Type = 4; Length = 8 bytes. */ + struct tlv_header header; /* Type = 4; Length = 8 bytes. */ u_int16_t type; /* Domain type: 1 = OSPF Area ID, 2 = AS Number */ u_int16_t reserved; u_int32_t value; @@ -177,7 +161,7 @@ struct ri_pce_subtlv_neighbor { #define PCE_CAP_MULTIPLE_REQ 0x0100 struct ri_pce_subtlv_cap_flag { - struct ri_tlv_header header; /* Type = 5; Length = n x 4 bytes. */ + struct tlv_header header; /* Type = 5; Length = n x 4 bytes. */ u_int32_t value; }; diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 4ca6578eae..66de46c5c9 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -68,9 +68,7 @@ */ struct ospf_mpls_te OspfMplsTE; -const char *mode2text[] = {"Disable", "AS", "Area", "Emulate"}; - -enum oifstate { OI_ANY, OI_DOWN, OI_UP }; +const char *mode2text[] = {"Off", "AS", "Area"}; /*------------------------------------------------------------------------* * Followings are initialize/terminate functions for MPLS-TE handling. @@ -106,29 +104,28 @@ int ospf_mpls_te_init(void) if (rc != 0) { zlog_warn( "ospf_mpls_te_init: Failed to register Traffic Engineering functions"); - goto out; + return rc; } memset(&OspfMplsTE, 0, sizeof(struct ospf_mpls_te)); - OspfMplsTE.status = disabled; - OspfMplsTE.inter_as = Disable; + OspfMplsTE.status = disable; + OspfMplsTE.inter_as = Off; OspfMplsTE.iflist = list_new(); OspfMplsTE.iflist->del = del_mpls_te_link; ospf_mpls_te_register_vty(); -out: return rc; } /* Additional register for RFC5392 support */ static int ospf_mpls_te_register(enum inter_as_mode mode) { - int rc; + int rc = 0; u_int8_t scope; - if (OspfMplsTE.inter_as != Disable) - return 0; + if (OspfMplsTE.inter_as != Off) + return rc; if (mode == AS) scope = OSPF_OPAQUE_AS_LSA; @@ -147,14 +144,14 @@ static int ospf_mpls_te_register(enum inter_as_mode mode) return rc; } - return 0; + return rc; } static int ospf_mpls_te_unregister() { u_int8_t scope; - if (OspfMplsTE.inter_as == Disable) + if (OspfMplsTE.inter_as == Off) return 0; if (OspfMplsTE.inter_as == AS) @@ -174,10 +171,10 @@ void ospf_mpls_te_term(void) ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA); - OspfMplsTE.status = disabled; + OspfMplsTE.status = disable; ospf_mpls_te_unregister(); - OspfMplsTE.inter_as = Disable; + OspfMplsTE.inter_as = Off; return; } @@ -192,7 +189,7 @@ static void del_mpls_te_link(void *val) return; } -u_int32_t get_mpls_te_instance_value(void) +static u_int32_t get_mpls_te_instance_value(void) { static u_int32_t seqno = 0; @@ -204,41 +201,6 @@ u_int32_t get_mpls_te_instance_value(void) return seqno; } -static struct ospf_interface *lookup_oi_by_ifp(struct interface *ifp, - struct ospf_area *area, - enum oifstate oifstate) -{ - struct ospf_interface *oi = NULL; - struct route_node *rn; - - for (rn = route_top(IF_OIFS(ifp)); rn; rn = route_next(rn)) { - if ((oi = rn->info) == NULL) - continue; - - switch (oifstate) { - case OI_ANY: - break; - case OI_DOWN: - if (ospf_if_is_enable(oi)) - continue; - break; - case OI_UP: - if (!ospf_if_is_enable(oi)) - continue; - break; - default: - zlog_warn("lookup_oi_by_ifp: Unknown oifstate: %x", - oifstate); - goto out; - } - - if (area == NULL || oi->area == area) - return oi; - } -out: - return NULL; -} - static struct mpls_te_link *lookup_linkparams_by_ifp(struct interface *ifp) { struct listnode *node, *nnode; @@ -793,14 +755,25 @@ static void update_linkparams(struct mpls_te_link *lp) static void initialize_linkparams(struct mpls_te_link *lp) { struct interface *ifp = lp->ifp; - struct ospf_interface *oi; + struct ospf_interface *oi = NULL; + struct route_node *rn; if (IS_DEBUG_OSPF_TE) zlog_debug( "MPLS-TE(initialize_linkparams) Initialize Link Parameters for interface %s", ifp->name); - if ((oi = lookup_oi_by_ifp(ifp, NULL, OI_ANY)) == NULL) { + /* Search OSPF Interface parameters for this interface */ + for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) { + + if ((oi = rn->info) == NULL) + continue; + + if (oi->ifp == ifp) + break; + } + + if ((oi == NULL) || (oi->ifp != ifp)) { if (IS_DEBUG_OSPF_TE) zlog_warn( "MPLS-TE(initialize_linkparams) Could not find corresponding OSPF Interface for %s", @@ -818,7 +791,7 @@ static void initialize_linkparams(struct mpls_te_link *lp) set_linkparams_lclif_ipaddr(lp, oi->address->u.prefix4); /* Set Remote IP addr if Point to Point Interface */ - if (oi->type == LINK_TYPE_SUBTLV_VALUE_PTP) { + if (oi->type == OSPF_IFTYPE_POINTOPOINT) { struct prefix *pref = CONNECTED_PREFIX(oi->connected); if (pref != NULL) set_linkparams_rmtif_ipaddr(lp, pref->u.prefix4); @@ -837,21 +810,20 @@ static int is_mandated_params_set(struct mpls_te_link *lp) if (ntohs(OspfMplsTE.router_addr.header.type) == 0) { zlog_warn( "MPLS-TE(is_mandated_params_set) Missing Router Address"); - goto out; + return rc; } if (ntohs(lp->link_type.header.type) == 0) { zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link Type"); - goto out; + return rc; } if (!IS_INTER_AS(lp->type) && (ntohs(lp->link_id.header.type) == 0)) { zlog_warn("MPLS-TE(is_mandated_params_set) Missing Link ID"); - goto out; + return rc; } rc = 1; -out: return rc; } @@ -873,14 +845,14 @@ static int ospf_mpls_te_new_if(struct interface *ifp) zlog_warn("ospf_mpls_te_new_if: ifp(%p) already in use?", (void *)ifp); rc = 0; /* Do nothing here. */ - goto out; + return rc; } new = XCALLOC(MTYPE_OSPF_MPLS_TE, sizeof(struct mpls_te_link)); if (new == NULL) { zlog_warn("ospf_mpls_te_new_if: XMALLOC: %s", safe_strerror(errno)); - goto out; + return rc; } new->instance = get_mpls_te_instance_value(); @@ -909,7 +881,6 @@ static int ospf_mpls_te_new_if(struct interface *ifp) /* Schedule Opaque-LSA refresh. */ /* XXX */ rc = 0; -out: return rc; } @@ -934,7 +905,6 @@ static int ospf_mpls_te_del_if(struct interface *ifp) /* Schedule Opaque-LSA refresh. */ /* XXX */ rc = 0; - /*out:*/ return rc; } @@ -952,10 +922,9 @@ void ospf_mpls_te_update_if(struct interface *ifp) /* Get Link context from interface */ if ((lp = lookup_linkparams_by_ifp(ifp)) == NULL) { - if (IS_DEBUG_OSPF_TE) - zlog_warn( - "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s", - ifp->name); + zlog_warn( + "OSPF MPLS-TE Update: Did not find Link Parameters context for interface %s", + ifp->name); return; } @@ -968,7 +937,7 @@ void ospf_mpls_te_update_if(struct interface *ifp) /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is * enabled */ - if (OspfMplsTE.status == enabled) + if (OspfMplsTE.status == enable) if (lp->area != NULL) { if CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) @@ -1000,14 +969,14 @@ static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_state) zlog_warn( "ospf_mpls_te_ism_change: Cannot get linkparams from OI(%s)?", IF_NAME(oi)); - goto out; + return; } if (oi->area == NULL || oi->area->ospf == NULL) { zlog_warn( "ospf_mpls_te_ism_change: Cannot refer to OSPF from OI(%s)?", IF_NAME(oi)); - goto out; + return; } #ifdef notyet if ((lp->area != NULL @@ -1076,7 +1045,6 @@ static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_state) break; } -out: return; } @@ -1090,15 +1058,15 @@ static void ospf_mpls_te_nsm_change(struct ospf_neighbor *nbr, int old_state) * Followings are OSPF protocol processing functions for MPLS-TE. *------------------------------------------------------------------------*/ -static void build_tlv_header(struct stream *s, struct te_tlv_header *tlvh) +static void build_tlv_header(struct stream *s, struct tlv_header *tlvh) { - stream_put(s, tlvh, sizeof(struct te_tlv_header)); + stream_put(s, tlvh, sizeof(struct tlv_header)); return; } static void build_router_tlv(struct stream *s) { - struct te_tlv_header *tlvh = &OspfMplsTE.router_addr.header; + struct tlv_header *tlvh = &OspfMplsTE.router_addr.header; if (ntohs(tlvh->type) != 0) { build_tlv_header(s, tlvh); stream_put(s, tlvh + 1, TLV_BODY_SIZE(tlvh)); @@ -1106,7 +1074,7 @@ static void build_router_tlv(struct stream *s) return; } -static void build_link_subtlv(struct stream *s, struct te_tlv_header *tlvh) +static void build_link_subtlv(struct stream *s, struct tlv_header *tlvh) { if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) { @@ -1177,7 +1145,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf_area *area, /* Create a stream for LSA. */ if ((s = stream_new(OSPF_MAX_LSA_SIZE)) == NULL) { zlog_warn("ospf_mpls_te_lsa_new: stream_new() ?"); - goto out; + return NULL; } lsah = (struct lsa_header *)STREAM_DATA(s); @@ -1233,14 +1201,14 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf_area *area, if ((new = ospf_lsa_new()) == NULL) { zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_new() ?"); stream_free(s); - goto out; + return NULL; } if ((new->data = ospf_lsa_data_new(length)) == NULL) { zlog_warn("ospf_mpls_te_lsa_new: ospf_lsa_data_new() ?"); ospf_lsa_unlock(&new); new = NULL; stream_free(s); - goto out; + return new; } new->area = area; @@ -1248,7 +1216,6 @@ static struct ospf_lsa *ospf_mpls_te_lsa_new(struct ospf_area *area, memcpy(new->data, lsah, length); stream_free(s); -out: return new; } @@ -1262,14 +1229,14 @@ static int ospf_mpls_te_lsa_originate1(struct ospf_area *area, if ((new = ospf_mpls_te_lsa_new(area, lp)) == NULL) { zlog_warn( "ospf_mpls_te_lsa_originate1: ospf_mpls_te_lsa_new() ?"); - goto out; + return rc; } /* Install this LSA into LSDB. */ if (ospf_lsa_install(area->ospf, NULL /*oi*/, new) == NULL) { zlog_warn("ospf_mpls_te_lsa_originate1: ospf_lsa_install() ?"); ospf_lsa_unlock(&new); - goto out; + return rc; } /* Now this link-parameter entry has associated LSA. */ @@ -1291,7 +1258,6 @@ static int ospf_mpls_te_lsa_originate1(struct ospf_area *area, } rc = 0; -out: return rc; } @@ -1302,11 +1268,11 @@ static int ospf_mpls_te_lsa_originate_area(void *arg) struct mpls_te_link *lp; int rc = -1; - if (OspfMplsTE.status == disabled) { + if (OspfMplsTE.status == disable) { zlog_info( "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now."); rc = 0; /* This is not an error case. */ - goto out; + return rc; } for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) { @@ -1352,11 +1318,10 @@ static int ospf_mpls_te_lsa_originate_area(void *arg) lp->instance, inet_ntoa(area->area_id), lp->ifp ? lp->ifp->name : "?"); if (ospf_mpls_te_lsa_originate1(area, lp) != 0) - goto out; + return rc; } rc = 0; -out: return rc; } @@ -1370,14 +1335,14 @@ static int ospf_mpls_te_lsa_originate2(struct ospf *top, if ((new = ospf_mpls_te_lsa_new(NULL, lp)) == NULL) { zlog_warn( "ospf_mpls_te_lsa_originate2: ospf_router_info_lsa_new() ?"); - goto out; + return rc; } /* Install this LSA into LSDB. */ if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) { zlog_warn("ospf_mpls_te_lsa_originate2: ospf_lsa_install() ?"); ospf_lsa_unlock(&new); - goto out; + return rc; } /* Now this Router Info parameter entry has associated LSA. */ @@ -1396,7 +1361,6 @@ static int ospf_mpls_te_lsa_originate2(struct ospf *top, } rc = 0; -out: return rc; } @@ -1408,12 +1372,12 @@ static int ospf_mpls_te_lsa_originate_as(void *arg) struct mpls_te_link *lp; int rc = -1; - if ((OspfMplsTE.status == disabled) - || (OspfMplsTE.inter_as == Disable)) { + if ((OspfMplsTE.status == disable) + || (OspfMplsTE.inter_as == Off)) { zlog_info( "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now."); rc = 0; /* This is not an error case. */ - goto out; + return rc; } for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) { @@ -1462,7 +1426,6 @@ static int ospf_mpls_te_lsa_originate_as(void *arg) } rc = 0; -out: return rc; } @@ -1473,7 +1436,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa) struct ospf *top; struct ospf_lsa *new = NULL; - if (OspfMplsTE.status == disabled) { + if (OspfMplsTE.status == disable) { /* * This LSA must have flushed before due to MPLS-TE status * change. @@ -1504,13 +1467,13 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa) if (lp) UNSET_FLAG(lp->flags, LPFLG_LSA_ENGAGED); ospf_opaque_lsa_flush_schedule(lsa); - goto out; + return NULL; } /* Create new Opaque-LSA/MPLS-TE instance. */ if ((new = ospf_mpls_te_lsa_new(area, lp)) == NULL) { zlog_warn("ospf_mpls_te_lsa_refresh: ospf_mpls_te_lsa_new() ?"); - goto out; + return NULL; } new->data->ls_seqnum = lsa_seqnum_increment(lsa); @@ -1526,7 +1489,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa) if (ospf_lsa_install(top, NULL /*oi */, new) == NULL) { zlog_warn("ospf_mpls_te_lsa_refresh: ospf_lsa_install() ?"); ospf_lsa_unlock(&new); - goto out; + return NULL; } /* Flood updated LSA through AS or Area depending of the RFC of the link @@ -1543,7 +1506,6 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa) ospf_lsa_header_dump(new->data); } -out: return new; } @@ -1636,7 +1598,7 @@ void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, opcode_t opcode) *------------------------------------------------------------------------*/ static u_int16_t show_vty_router_addr(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_tlv_router_addr *top = (struct te_tlv_router_addr *)tlvh; @@ -1649,7 +1611,7 @@ static u_int16_t show_vty_router_addr(struct vty *vty, } static u_int16_t show_vty_link_header(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_tlv_link *top = (struct te_tlv_link *)tlvh; @@ -1664,7 +1626,7 @@ static u_int16_t show_vty_link_header(struct vty *vty, } static u_int16_t show_vty_link_subtlv_link_type(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_link_type *top; const char *cp = "Unknown"; @@ -1691,7 +1653,7 @@ static u_int16_t show_vty_link_subtlv_link_type(struct vty *vty, } static u_int16_t show_vty_link_subtlv_link_id(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_link_id *top; @@ -1705,7 +1667,7 @@ static u_int16_t show_vty_link_subtlv_link_id(struct vty *vty, } static u_int16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_lclif_ipaddr *top; int i, n; @@ -1730,7 +1692,7 @@ static u_int16_t show_vty_link_subtlv_lclif_ipaddr(struct vty *vty, } static u_int16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_rmtif_ipaddr *top; int i, n; @@ -1754,7 +1716,7 @@ static u_int16_t show_vty_link_subtlv_rmtif_ipaddr(struct vty *vty, } static u_int16_t show_vty_link_subtlv_te_metric(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_te_metric *top; @@ -1770,7 +1732,7 @@ static u_int16_t show_vty_link_subtlv_te_metric(struct vty *vty, } static u_int16_t show_vty_link_subtlv_max_bw(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_max_bw *top; float fval; @@ -1787,7 +1749,7 @@ static u_int16_t show_vty_link_subtlv_max_bw(struct vty *vty, } static u_int16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_max_rsv_bw *top; float fval; @@ -1806,7 +1768,7 @@ static u_int16_t show_vty_link_subtlv_max_rsv_bw(struct vty *vty, } static u_int16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_unrsv_bw *top; float fval1, fval2; @@ -1837,7 +1799,7 @@ static u_int16_t show_vty_link_subtlv_unrsv_bw(struct vty *vty, } static u_int16_t show_vty_link_subtlv_rsc_clsclr(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_rsc_clsclr *top; @@ -1853,7 +1815,7 @@ static u_int16_t show_vty_link_subtlv_rsc_clsclr(struct vty *vty, } static u_int16_t show_vty_link_subtlv_lrrid(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_lrrid *top; @@ -1875,7 +1837,7 @@ static u_int16_t show_vty_link_subtlv_lrrid(struct vty *vty, } static u_int16_t show_vty_link_subtlv_llri(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_llri *top; @@ -1897,7 +1859,7 @@ static u_int16_t show_vty_link_subtlv_llri(struct vty *vty, } static u_int16_t show_vty_link_subtlv_rip(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_rip *top; @@ -1914,7 +1876,7 @@ static u_int16_t show_vty_link_subtlv_rip(struct vty *vty, } static u_int16_t show_vty_link_subtlv_ras(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_ras *top; @@ -1931,7 +1893,7 @@ static u_int16_t show_vty_link_subtlv_ras(struct vty *vty, } static u_int16_t show_vty_link_subtlv_av_delay(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_av_delay *top; u_int32_t delay; @@ -1952,7 +1914,7 @@ static u_int16_t show_vty_link_subtlv_av_delay(struct vty *vty, } static u_int16_t show_vty_link_subtlv_mm_delay(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_mm_delay *top; u_int32_t low, high; @@ -1974,7 +1936,7 @@ static u_int16_t show_vty_link_subtlv_mm_delay(struct vty *vty, } static u_int16_t show_vty_link_subtlv_delay_var(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_delay_var *top; u_int32_t jitter; @@ -1991,7 +1953,7 @@ static u_int16_t show_vty_link_subtlv_delay_var(struct vty *vty, } static u_int16_t show_vty_link_subtlv_pkt_loss(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_pkt_loss *top; u_int32_t loss; @@ -2014,7 +1976,7 @@ static u_int16_t show_vty_link_subtlv_pkt_loss(struct vty *vty, } static u_int16_t show_vty_link_subtlv_res_bw(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_res_bw *top; float fval; @@ -2035,7 +1997,7 @@ static u_int16_t show_vty_link_subtlv_res_bw(struct vty *vty, } static u_int16_t show_vty_link_subtlv_ava_bw(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_ava_bw *top; float fval; @@ -2056,7 +2018,7 @@ static u_int16_t show_vty_link_subtlv_ava_bw(struct vty *vty, } static u_int16_t show_vty_link_subtlv_use_bw(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { struct te_link_subtlv_use_bw *top; float fval; @@ -2077,7 +2039,7 @@ static u_int16_t show_vty_link_subtlv_use_bw(struct vty *vty, } static u_int16_t show_vty_unknown_tlv(struct vty *vty, - struct te_tlv_header *tlvh) + struct tlv_header *tlvh) { if (vty != NULL) vty_out(vty, " Unknown TLV: [type(0x%x), length(0x%x)]\n", @@ -2090,11 +2052,11 @@ static u_int16_t show_vty_unknown_tlv(struct vty *vty, } static u_int16_t ospf_mpls_te_show_link_subtlv(struct vty *vty, - struct te_tlv_header *tlvh0, + struct tlv_header *tlvh0, u_int16_t subtotal, u_int16_t total) { - struct te_tlv_header *tlvh, *next; + struct tlv_header *tlvh, *next; u_int16_t sum = subtotal; for (tlvh = tlvh0; sum < total; @@ -2172,9 +2134,9 @@ static u_int16_t ospf_mpls_te_show_link_subtlv(struct vty *vty, static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa) { struct lsa_header *lsah = (struct lsa_header *)lsa->data; - struct te_tlv_header *tlvh, *next; + struct tlv_header *tlvh, *next; u_int16_t sum, total; - u_int16_t (*subfunc)(struct vty * vty, struct te_tlv_header * tlvh, + u_int16_t (*subfunc)(struct vty * vty, struct tlv_header * tlvh, u_int16_t subtotal, u_int16_t total) = NULL; sum = 0; @@ -2184,7 +2146,7 @@ static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa) tlvh = (next ? next : TLV_HDR_NEXT(tlvh))) { if (subfunc != NULL) { sum = (*subfunc)(vty, tlvh, sum, total); - next = (struct te_tlv_header *)((char *)tlvh + sum); + next = (struct tlv_header *)((char *)tlvh + sum); subfunc = NULL; continue; } @@ -2210,7 +2172,7 @@ static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa) static void ospf_mpls_te_config_write_router(struct vty *vty) { - if (OspfMplsTE.status == enabled) { + if (OspfMplsTE.status == enable) { vty_out(vty, " mpls-te on\n"); vty_out(vty, " mpls-te router-address %s\n", inet_ntoa(OspfMplsTE.router_addr.value)); @@ -2239,20 +2201,20 @@ DEFUN (ospf_mpls_te_on, struct listnode *node; struct mpls_te_link *lp; - if (OspfMplsTE.status == enabled) + if (OspfMplsTE.status == enable) return CMD_SUCCESS; if (IS_DEBUG_OSPF_EVENT) zlog_debug("MPLS-TE: OFF -> ON"); - OspfMplsTE.status = enabled; + OspfMplsTE.status = enable; /* Reoriginate RFC3630 & RFC6827 Links */ ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule, REORIGINATE_THIS_LSA); /* Reoriginate LSA if INTER-AS is always on */ - if (OspfMplsTE.inter_as != Disable) { + if (OspfMplsTE.inter_as != Off) { for (ALL_LIST_ELEMENTS_RO(OspfMplsTE.iflist, node, lp)) { if (IS_INTER_AS(lp->type)) { ospf_mpls_te_lsa_schedule(lp, @@ -2275,13 +2237,13 @@ DEFUN (no_ospf_mpls_te, struct listnode *node, *nnode; struct mpls_te_link *lp; - if (OspfMplsTE.status == disabled) + if (OspfMplsTE.status == disable) return CMD_SUCCESS; if (IS_DEBUG_OSPF_EVENT) zlog_debug("MPLS-TE: ON -> OFF"); - OspfMplsTE.status = disabled; + OspfMplsTE.status = disable; for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) if @@ -2317,8 +2279,8 @@ DEFUN (ospf_mpls_te_router_addr, set_mpls_te_router_addr(value); - if (OspfMplsTE.status == disabled) - goto out; + if (OspfMplsTE.status == disable) + return CMD_SUCCESS; for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) { if ((lp->area == NULL) || IS_FLOOD_AS(lp->type)) @@ -2344,7 +2306,7 @@ DEFUN (ospf_mpls_te_router_addr, ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule, REORIGINATE_THIS_LSA); } -out: + return CMD_SUCCESS; } @@ -2356,7 +2318,7 @@ static int set_inter_as_mode(struct vty *vty, const char *mode_name, struct mpls_te_link *lp; int format; - if (OspfMplsTE.status == enabled) { + if (OspfMplsTE.status == enable) { /* Read and Check inter_as mode */ if (strcmp(mode_name, "as") == 0) @@ -2385,7 +2347,7 @@ static int set_inter_as_mode(struct vty *vty, const char *mode_name, } /* Enable mode and re-originate LSA if needed */ - if ((OspfMplsTE.inter_as == Disable) + if ((OspfMplsTE.inter_as == Off) && (mode != OspfMplsTE.inter_as)) { OspfMplsTE.inter_as = mode; /* Re-originate all InterAS-TEv2 LSA */ @@ -2451,9 +2413,9 @@ DEFUN (no_ospf_mpls_te_inter_as, if (IS_DEBUG_OSPF_EVENT) zlog_debug("MPLS-TE: Inter-AS support OFF"); - if ((OspfMplsTE.status == enabled) - && (OspfMplsTE.inter_as != Disable)) { - OspfMplsTE.inter_as = Disable; + if ((OspfMplsTE.status == enable) + && (OspfMplsTE.inter_as != Off)) { + OspfMplsTE.inter_as = Off; /* Flush all Inter-AS LSA */ for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) if (IS_INTER_AS(lp->type) @@ -2476,7 +2438,7 @@ DEFUN (show_ip_ospf_mpls_te_router, "MPLS-TE information\n" "MPLS-TE Router parameters\n") { - if (OspfMplsTE.status == enabled) { + if (OspfMplsTE.status == enable) { vty_out(vty, "--- MPLS-TE router parameters ---\n"); if (ntohs(OspfMplsTE.router_addr.header.type) != 0) @@ -2492,7 +2454,7 @@ static void show_mpls_te_link_sub(struct vty *vty, struct interface *ifp) { struct mpls_te_link *lp; - if ((OspfMplsTE.status == enabled) && HAS_LINK_PARAMS(ifp) + if ((OspfMplsTE.status == enable) && HAS_LINK_PARAMS(ifp) && !if_is_loopback(ifp) && if_is_up(ifp) && ((lp = lookup_linkparams_by_ifp(ifp)) != NULL)) { /* Continue only if interface is not passive or support Inter-AS diff --git a/ospfd/ospf_te.h b/ospfd/ospf_te.h index 4ee9139a3c..233350f830 100644 --- a/ospfd/ospf_te.h +++ b/ospfd/ospf_te.h @@ -78,7 +78,7 @@ #define FLOOD_AS 0x20 #define EMULATED 0x80 -#define IS_STD_TE(x) (x & STD_TE) +#define IS_STD_TE(x) (x & STD_TE) #define IS_PSEUDO_TE(x) (x & PSEUDO_TE) #define IS_INTER_AS(x) (x & INTER_AS) #define IS_EMULATED(x) (x & EMULATED) @@ -94,58 +94,32 @@ #define LPFLG_LOOKUP_DONE 0x4 #define LPFLG_LSA_FORCED_REFRESH 0x8 -/* - * Following section defines TLV (tag, length, value) structures, - * used for Traffic Engineering. - */ -struct te_tlv_header { - u_int16_t type; /* TE_TLV_XXX (see below) */ - u_int16_t length; /* Value portion only, in octets */ -}; - -#define TLV_HDR_SIZE (sizeof(struct te_tlv_header)) - -#define TLV_BODY_SIZE(tlvh) (ROUNDUP(ntohs((tlvh)->length), sizeof(u_int32_t))) - -#define TLV_SIZE(tlvh) (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh)) - -#define TLV_HDR_TOP(lsah) \ - (struct te_tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE) - -#define TLV_HDR_NEXT(tlvh) \ - (struct te_tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh)) - -#define TLV_HDR_SUBTLV(tlvh) \ - (struct te_tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE) - -#define TLV_TYPE(tlvh) tlvh.header.type -#define TLV_LEN(tlvh) tlvh.header.length -#define TLV_HDR(tlvh) tlvh.header - /* * Following section defines TLV body parts. */ + /* Router Address TLV */ /* Mandatory */ #define TE_TLV_ROUTER_ADDR 1 struct te_tlv_router_addr { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ struct in_addr value; }; /* Link TLV */ #define TE_TLV_LINK 2 struct te_tlv_link { - struct te_tlv_header header; + struct tlv_header header; /* A set of link-sub-TLVs will follow. */ }; +/* Default TE TLV size */ #define TE_LINK_SUBTLV_DEF_SIZE 4 /* Link Type Sub-TLV */ /* Mandatory */ #define TE_LINK_SUBTLV_LINK_TYPE 1 #define TE_LINK_SUBTLV_TYPE_SIZE 1 struct te_link_subtlv_link_type { - struct te_tlv_header header; /* Value length is 1 octet. */ + struct tlv_header header; /* Value length is 1 octet. */ struct { #define LINK_TYPE_SUBTLV_VALUE_PTP 1 #define LINK_TYPE_SUBTLV_VALUE_MA 2 @@ -157,42 +131,42 @@ struct te_link_subtlv_link_type { /* Link Sub-TLV: Link ID */ /* Mandatory */ #define TE_LINK_SUBTLV_LINK_ID 2 struct te_link_subtlv_link_id { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ struct in_addr value; /* Same as router-lsa's link-id. */ }; /* Link Sub-TLV: Local Interface IP Address */ /* Optional */ #define TE_LINK_SUBTLV_LCLIF_IPADDR 3 struct te_link_subtlv_lclif_ipaddr { - struct te_tlv_header header; /* Value length is 4 x N octets. */ + struct tlv_header header; /* Value length is 4 x N octets. */ struct in_addr value[1]; /* Local IP address(es). */ }; /* Link Sub-TLV: Remote Interface IP Address */ /* Optional */ #define TE_LINK_SUBTLV_RMTIF_IPADDR 4 struct te_link_subtlv_rmtif_ipaddr { - struct te_tlv_header header; /* Value length is 4 x N octets. */ + struct tlv_header header; /* Value length is 4 x N octets. */ struct in_addr value[1]; /* Neighbor's IP address(es). */ }; /* Link Sub-TLV: Traffic Engineering Metric */ /* Optional */ #define TE_LINK_SUBTLV_TE_METRIC 5 struct te_link_subtlv_te_metric { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ u_int32_t value; /* Link metric for TE purpose. */ }; /* Link Sub-TLV: Maximum Bandwidth */ /* Optional */ #define TE_LINK_SUBTLV_MAX_BW 6 struct te_link_subtlv_max_bw { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ float value; /* bytes/sec */ }; /* Link Sub-TLV: Maximum Reservable Bandwidth */ /* Optional */ #define TE_LINK_SUBTLV_MAX_RSV_BW 7 struct te_link_subtlv_max_rsv_bw { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ float value; /* bytes/sec */ }; @@ -200,14 +174,14 @@ struct te_link_subtlv_max_rsv_bw { #define TE_LINK_SUBTLV_UNRSV_BW 8 #define TE_LINK_SUBTLV_UNRSV_SIZE 32 struct te_link_subtlv_unrsv_bw { - struct te_tlv_header header; /* Value length is 32 octets. */ + struct tlv_header header; /* Value length is 32 octets. */ float value[MAX_CLASS_TYPE]; /* One for each priority level. */ }; /* Link Sub-TLV: Resource Class/Color */ /* Optional */ #define TE_LINK_SUBTLV_RSC_CLSCLR 9 struct te_link_subtlv_rsc_clsclr { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ u_int32_t value; /* Admin. group membership. */ }; @@ -216,7 +190,7 @@ struct te_link_subtlv_rsc_clsclr { #define TE_LINK_SUBTLV_LRRID 10 #define TE_LINK_SUBTLV_LRRID_SIZE 8 struct te_link_subtlv_lrrid { - struct te_tlv_header header; /* Value length is 8 octets. */ + struct tlv_header header; /* Value length is 8 octets. */ struct in_addr local; /* Local TE Router Identifier */ struct in_addr remote; /* Remote TE Router Identifier */ }; @@ -225,7 +199,7 @@ struct te_link_subtlv_lrrid { #define TE_LINK_SUBTLV_LLRI 11 #define TE_LINK_SUBTLV_LLRI_SIZE 8 struct te_link_subtlv_llri { - struct te_tlv_header header; /* Value length is 8 octets. */ + struct tlv_header header; /* Value length is 8 octets. */ u_int32_t local; /* Link Local Identifier */ u_int32_t remote; /* Link Remote Identifier */ }; @@ -240,14 +214,14 @@ struct te_link_subtlv_llri { /* Remote AS Number sub-TLV */ #define TE_LINK_SUBTLV_RAS 21 struct te_link_subtlv_ras { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ u_int32_t value; /* Remote AS number */ }; /* IPv4 Remote ASBR ID Sub-TLV */ #define TE_LINK_SUBTLV_RIP 22 struct te_link_subtlv_rip { - struct te_tlv_header header; /* Value length is 4 octets. */ + struct tlv_header header; /* Value length is 4 octets. */ struct in_addr value; /* Remote ASBR IP address */ }; @@ -261,63 +235,69 @@ struct te_link_subtlv_rip { /* Link Sub-TLV: Average Link Delay */ /* Optional */ #define TE_LINK_SUBTLV_AV_DELAY 27 struct te_link_subtlv_av_delay { - struct te_tlv_header header; /* Value length is 4 bytes. */ - u_int32_t - value; /* delay in micro-seconds only 24 bits => 0 ... 16777215 - with Anomalous Bit as Upper most bit */ + struct tlv_header header; /* Value length is 4 bytes. */ + /* + * delay in micro-seconds only 24 bits => 0 ... 16777215 + * with Anomalous Bit as Upper most bit + */ + u_int32_t value; }; /* Link Sub-TLV: Low/High Link Delay */ #define TE_LINK_SUBTLV_MM_DELAY 28 #define TE_LINK_SUBTLV_MM_DELAY_SIZE 8 struct te_link_subtlv_mm_delay { - struct te_tlv_header header; /* Value length is 8 bytes. */ - u_int32_t low; /* low delay in micro-seconds only 24 bits => 0 ... - 16777215 - with Anomalous Bit (A) as Upper most bit */ - u_int32_t high; /* high delay in micro-seconds only 24 bits => 0 ... - 16777215 */ + struct tlv_header header; /* Value length is 8 bytes. */ + /* + * low delay in micro-seconds only 24 bits => 0 ... 16777215 + * with Anomalous Bit (A) as Upper most bit + */ + u_int32_t low; + /* high delay in micro-seconds only 24 bits => 0 ... 16777215 */ + u_int32_t high; }; /* Link Sub-TLV: Link Delay Variation i.e. Jitter */ #define TE_LINK_SUBTLV_DELAY_VAR 29 struct te_link_subtlv_delay_var { - struct te_tlv_header header; /* Value length is 4 bytes. */ - u_int32_t value; /* interval in micro-seconds only 24 bits => 0 ... - 16777215 */ + struct tlv_header header; /* Value length is 4 bytes. */ + /* interval in micro-seconds only 24 bits => 0 ... 16777215 */ + u_int32_t value; }; /* Link Sub-TLV: Routine Unidirectional Link Packet Loss */ #define TE_LINK_SUBTLV_PKT_LOSS 30 struct te_link_subtlv_pkt_loss { - struct te_tlv_header header; /* Value length is 4 bytes. */ - u_int32_t - value; /* in percentage of total traffic only 24 bits (2^24 - 2) - with Anomalous Bit as Upper most bit */ + struct tlv_header header; /* Value length is 4 bytes. */ + /* + * in percentage of total traffic only 24 bits (2^24 - 2) + * with Anomalous Bit as Upper most bit + */ + u_int32_t value; }; /* Link Sub-TLV: Unidirectional Residual Bandwidth */ /* Optional */ #define TE_LINK_SUBTLV_RES_BW 31 struct te_link_subtlv_res_bw { - struct te_tlv_header header; /* Value length is 4 bytes. */ - float value; /* bandwidth in IEEE floating point format with units in - bytes per second */ + struct tlv_header header; /* Value length is 4 bytes. */ + /* bandwidth in IEEE floating point format with units in bytes/second */ + float value; }; /* Link Sub-TLV: Unidirectional Available Bandwidth */ /* Optional */ #define TE_LINK_SUBTLV_AVA_BW 32 struct te_link_subtlv_ava_bw { - struct te_tlv_header header; /* Value length is 4 octets. */ - float value; /* bandwidth in IEEE floating point format with units in - bytes per second */ + struct tlv_header header; /* Value length is 4 octets. */ + /* bandwidth in IEEE floating point format with units in bytes/second */ + float value; }; /* Link Sub-TLV: Unidirectional Utilized Bandwidth */ /* Optional */ #define TE_LINK_SUBTLV_USE_BW 33 struct te_link_subtlv_use_bw { - struct te_tlv_header header; /* Value length is 4 octets. */ - float value; /* bandwidth in IEEE floating point format with units in - bytes per second */ + struct tlv_header header; /* Value length is 4 octets. */ + /* bandwidth in IEEE floating point format with units in bytes/second */ + float value; }; #define TE_LINK_SUBTLV_MAX 34 /* Last SUBTLV + 1 */ @@ -325,20 +305,11 @@ struct te_link_subtlv_use_bw { /* Here are "non-official" architectural constants. */ #define MPLS_TE_MINIMUM_BANDWIDTH 1.0 /* Reasonable? *//* XXX */ -/* Following declaration concerns the MPLS-TE and LINk-TE management */ -typedef enum _opcode_t { - REORIGINATE_THIS_LSA, - REFRESH_THIS_LSA, - FLUSH_THIS_LSA -} opcode_t; - -typedef enum _status_t { disabled, enabled } status_t; - /* Mode for Inter-AS Opaque-LSA */ -enum inter_as_mode { Disable, AS, Area }; +enum inter_as_mode { Off, AS, Area }; struct te_link_subtlv { - struct te_tlv_header header; + struct tlv_header header; union { u_int32_t link_type; struct in_addr link_id; @@ -438,7 +409,6 @@ extern void ospf_mpls_te_term(void); extern struct ospf_mpls_te *get_ospf_mpls_te(void); extern void ospf_mpls_te_update_if(struct interface *); extern void ospf_mpls_te_lsa_schedule(struct mpls_te_link *, opcode_t); -extern u_int32_t get_mpls_te_instance_value(void); extern void set_linkparams_llri(struct mpls_te_link *, u_int32_t, u_int32_t); extern void set_linkparams_lrrid(struct mpls_te_link *, struct in_addr, struct in_addr); diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 4142f1a3e9..1876fad5fa 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -84,6 +84,9 @@ struct ospf_external { struct route_table *external_info; }; +/* Status of various sub function e.g. TE */ +typedef enum _status_t {disable, enable} status_t; + /* OSPF master for system wide configuration and variables. */ struct ospf_master { /* OSPF instance. */ From 2a39170c6bd4dddf803a8c4c241e8ab072d78cca Mon Sep 17 00:00:00 2001 From: Olivier Dugeon Date: Fri, 21 Jul 2017 16:34:33 +0200 Subject: [PATCH 05/75] Correct indentation and remove _opcode_t typedef * Correct struct tlh_header indentation in opaque.h * Change typedef enum _opcode_t by enum lsa_opcode * Propagate change in ospf_te.[c,h) and ospf_ri.c Signed-off-by: Olivier Dugeon --- ospfd/ospf_opaque.h | 7 +++---- ospfd/ospf_ri.c | 4 ++-- ospfd/ospf_te.c | 6 +++--- ospfd/ospf_te.h | 2 +- 4 files changed, 9 insertions(+), 10 deletions(-) diff --git a/ospfd/ospf_opaque.h b/ospfd/ospf_opaque.h index 88a6854b84..60435e502e 100644 --- a/ospfd/ospf_opaque.h +++ b/ospfd/ospf_opaque.h @@ -81,8 +81,7 @@ * Following section defines generic TLV (type, length, value) macros, * used for various LSA opaque usage e.g. Traffic Engineering. */ -struct tlv_header -{ +struct tlv_header { u_int16_t type; /* Type of Value */ u_int16_t length; /* Length of Value portion only, in bytes */ }; @@ -112,11 +111,11 @@ struct tlv_header #define TLV_HDR(tlvh) tlvh.header /* Following declaration concerns the Opaque LSA management */ -typedef enum _opcode_t { +enum lsa_opcode { REORIGINATE_THIS_LSA, REFRESH_THIS_LSA, FLUSH_THIS_LSA -} opcode_t; +}; /* Prototypes. */ diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index 2136f2eb64..e192a39e45 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -111,7 +111,7 @@ static void ospf_router_info_config_write_router(struct vty *vty); static void ospf_router_info_show_info(struct vty *vty, struct ospf_lsa *lsa); static int ospf_router_info_lsa_originate(void *arg); static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa); -static void ospf_router_info_lsa_schedule(opcode_t opcode); +static void ospf_router_info_lsa_schedule(enum lsa_opcode opcode); static void ospf_router_info_register_vty(void); static void del_pce_info(void *val); @@ -778,7 +778,7 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa) return new; } -static void ospf_router_info_lsa_schedule(opcode_t opcode) +static void ospf_router_info_lsa_schedule(enum lsa_opcode opcode) { struct ospf_lsa lsa; struct lsa_header lsah; diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 66de46c5c9..a982350e63 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -229,8 +229,8 @@ static struct mpls_te_link *lookup_linkparams_by_instance(struct ospf_lsa *lsa) } static void ospf_mpls_te_foreach_area(void (*func)(struct mpls_te_link *lp, - opcode_t sched_opcode), - opcode_t sched_opcode) + enum lsa_opcode sched_opcode), + enum lsa_opcode sched_opcode) { struct listnode *node, *nnode; struct listnode *node2; @@ -1509,7 +1509,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa) return new; } -void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, opcode_t opcode) +void ospf_mpls_te_lsa_schedule(struct mpls_te_link *lp, enum lsa_opcode opcode) { struct ospf_lsa lsa; struct lsa_header lsah; diff --git a/ospfd/ospf_te.h b/ospfd/ospf_te.h index 233350f830..e3a6114b4f 100644 --- a/ospfd/ospf_te.h +++ b/ospfd/ospf_te.h @@ -408,7 +408,7 @@ extern int ospf_mpls_te_init(void); extern void ospf_mpls_te_term(void); extern struct ospf_mpls_te *get_ospf_mpls_te(void); extern void ospf_mpls_te_update_if(struct interface *); -extern void ospf_mpls_te_lsa_schedule(struct mpls_te_link *, opcode_t); +extern void ospf_mpls_te_lsa_schedule(struct mpls_te_link *, enum lsa_opcode); extern void set_linkparams_llri(struct mpls_te_link *, u_int32_t, u_int32_t); extern void set_linkparams_lrrid(struct mpls_te_link *, struct in_addr, struct in_addr); From 40e344cc4bc4c6da92d213302231cce77edf596e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 24 Jul 2017 15:59:36 -0400 Subject: [PATCH 06/75] ripngd: Fix failure returned with some debug commands Signed-off-by: Donald Sharp --- ripngd/ripng_debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ripngd/ripng_debug.c b/ripngd/ripng_debug.c index 5d7a2cf9ff..d56161d39e 100644 --- a/ripngd/ripng_debug.c +++ b/ripngd/ripng_debug.c @@ -67,7 +67,7 @@ DEFUN (debug_ripng_events, "Debug option set for ripng events\n") { ripng_debug_event = RIPNG_DEBUG_EVENT; - return CMD_WARNING_CONFIG_FAILED; + return CMD_SUCCESS; } DEFUN (debug_ripng_packet, @@ -114,7 +114,7 @@ DEFUN (debug_ripng_zebra, "Debug option set for ripng and zebra communication\n") { ripng_debug_zebra = RIPNG_DEBUG_ZEBRA; - return CMD_WARNING_CONFIG_FAILED; + return CMD_SUCCESS; } DEFUN (no_debug_ripng_events, @@ -179,7 +179,7 @@ DEFUN (no_debug_ripng_zebra, "Debug option set for ripng and zebra communication\n") { ripng_debug_zebra = 0; - return CMD_WARNING_CONFIG_FAILED; + return CMD_SUCCESS; } /* Debug node. */ From 9c9d843baa9b8320f22f5976b2d0b79753dd202e Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 24 Jul 2017 16:00:20 -0400 Subject: [PATCH 07/75] ripd: Fix debug config failures Signed-off-by: Donald Sharp --- ripd/rip_debug.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/ripd/rip_debug.c b/ripd/rip_debug.c index b2c80817dd..492d036991 100644 --- a/ripd/rip_debug.c +++ b/ripd/rip_debug.c @@ -66,7 +66,7 @@ DEFUN (debug_rip_events, "RIP events\n") { rip_debug_event = RIP_DEBUG_EVENT; - return CMD_WARNING_CONFIG_FAILED; + return CMD_SUCCESS; } DEFUN (debug_rip_packet, @@ -112,7 +112,7 @@ DEFUN (debug_rip_zebra, "RIP and ZEBRA communication\n") { rip_debug_zebra = RIP_DEBUG_ZEBRA; - return CMD_WARNING_CONFIG_FAILED; + return CMD_SUCCESS; } DEFUN (no_debug_rip_events, @@ -177,7 +177,7 @@ DEFUN (no_debug_rip_zebra, "RIP and ZEBRA communication\n") { rip_debug_zebra = 0; - return CMD_WARNING_CONFIG_FAILED; + return CMD_SUCCESS; } /* Debug node. */ From 52535beec1fe85682094b625d3f2e19520a803a8 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 18:36:51 -0300 Subject: [PATCH 08/75] lib: revert reindent of files imported from OpenBSD We should preserve the original indentation to make it easier to keep these files in sync with the upstream. Signed-off-by: Renato Westphal --- lib/imsg-buffer.c | 105 +++--- lib/imsg.c | 117 ++++--- lib/imsg.h | 110 +++---- lib/openbsd-tree.c | 146 +++++---- lib/openbsd-tree.h | 793 ++++++++++++++++++++++----------------------- 5 files changed, 654 insertions(+), 617 deletions(-) diff --git a/lib/imsg-buffer.c b/lib/imsg-buffer.c index 4068e31c51..a486fc17c1 100644 --- a/lib/imsg-buffer.c +++ b/lib/imsg-buffer.c @@ -21,13 +21,14 @@ #include "openbsd-queue.h" #include "imsg.h" -int ibuf_realloc(struct ibuf *, size_t); -void ibuf_enqueue(struct msgbuf *, struct ibuf *); -void ibuf_dequeue(struct msgbuf *, struct ibuf *); +int ibuf_realloc(struct ibuf *, size_t); +void ibuf_enqueue(struct msgbuf *, struct ibuf *); +void ibuf_dequeue(struct msgbuf *, struct ibuf *); -struct ibuf *ibuf_open(size_t len) +struct ibuf * +ibuf_open(size_t len) { - struct ibuf *buf; + struct ibuf *buf; if ((buf = calloc(1, sizeof(struct ibuf))) == NULL) return (NULL); @@ -41,9 +42,10 @@ struct ibuf *ibuf_open(size_t len) return (buf); } -struct ibuf *ibuf_dynamic(size_t len, size_t max) +struct ibuf * +ibuf_dynamic(size_t len, size_t max) { - struct ibuf *buf; + struct ibuf *buf; if (max < len) return (NULL); @@ -57,9 +59,10 @@ struct ibuf *ibuf_dynamic(size_t len, size_t max) return (buf); } -int ibuf_realloc(struct ibuf *buf, size_t len) +int +ibuf_realloc(struct ibuf *buf, size_t len) { - u_char *b; + u_char *b; /* on static buffers max is eq size and so the following fails */ if (buf->wpos + len > buf->max) { @@ -76,7 +79,8 @@ int ibuf_realloc(struct ibuf *buf, size_t len) return (0); } -int ibuf_add(struct ibuf *buf, const void *data, size_t len) +int +ibuf_add(struct ibuf *buf, const void *data, size_t len) { if (buf->wpos + len > buf->size) if (ibuf_realloc(buf, len) == -1) @@ -87,9 +91,10 @@ int ibuf_add(struct ibuf *buf, const void *data, size_t len) return (0); } -void *ibuf_reserve(struct ibuf *buf, size_t len) +void * +ibuf_reserve(struct ibuf *buf, size_t len) { - void *b; + void *b; if (buf->wpos + len > buf->size) if (ibuf_realloc(buf, len) == -1) @@ -100,7 +105,8 @@ void *ibuf_reserve(struct ibuf *buf, size_t len) return (b); } -void *ibuf_seek(struct ibuf *buf, size_t pos, size_t len) +void * +ibuf_seek(struct ibuf *buf, size_t pos, size_t len) { /* only allowed to seek in already written parts */ if (pos + len > buf->wpos) @@ -109,31 +115,34 @@ void *ibuf_seek(struct ibuf *buf, size_t pos, size_t len) return (buf->buf + pos); } -size_t ibuf_size(struct ibuf *buf) +size_t +ibuf_size(struct ibuf *buf) { return (buf->wpos); } -size_t ibuf_left(struct ibuf *buf) +size_t +ibuf_left(struct ibuf *buf) { return (buf->max - buf->wpos); } -void ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) +void +ibuf_close(struct msgbuf *msgbuf, struct ibuf *buf) { ibuf_enqueue(msgbuf, buf); } -int ibuf_write(struct msgbuf *msgbuf) +int +ibuf_write(struct msgbuf *msgbuf) { - struct iovec iov[IOV_MAX]; - struct ibuf *buf; - unsigned int i = 0; - ssize_t n; + struct iovec iov[IOV_MAX]; + struct ibuf *buf; + unsigned int i = 0; + ssize_t n; memset(&iov, 0, sizeof(iov)); - TAILQ_FOREACH(buf, &msgbuf->bufs, entry) - { + TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { if (i >= IOV_MAX) break; iov[i].iov_base = buf->buf + buf->rpos; @@ -150,7 +159,7 @@ again: return (-1); } - if (n == 0) { /* connection closed */ + if (n == 0) { /* connection closed */ errno = 0; return (0); } @@ -160,7 +169,8 @@ again: return (1); } -void ibuf_free(struct ibuf *buf) +void +ibuf_free(struct ibuf *buf) { if (buf == NULL) return; @@ -168,19 +178,21 @@ void ibuf_free(struct ibuf *buf) free(buf); } -void msgbuf_init(struct msgbuf *msgbuf) +void +msgbuf_init(struct msgbuf *msgbuf) { msgbuf->queued = 0; msgbuf->fd = -1; TAILQ_INIT(&msgbuf->bufs); } -void msgbuf_drain(struct msgbuf *msgbuf, size_t n) +void +msgbuf_drain(struct msgbuf *msgbuf, size_t n) { - struct ibuf *buf, *next; + struct ibuf *buf, *next; for (buf = TAILQ_FIRST(&msgbuf->bufs); buf != NULL && n > 0; - buf = next) { + buf = next) { next = TAILQ_NEXT(buf, entry); if (buf->rpos + n >= buf->wpos) { n -= buf->wpos - buf->rpos; @@ -192,32 +204,33 @@ void msgbuf_drain(struct msgbuf *msgbuf, size_t n) } } -void msgbuf_clear(struct msgbuf *msgbuf) +void +msgbuf_clear(struct msgbuf *msgbuf) { - struct ibuf *buf; + struct ibuf *buf; while ((buf = TAILQ_FIRST(&msgbuf->bufs)) != NULL) ibuf_dequeue(msgbuf, buf); } -int msgbuf_write(struct msgbuf *msgbuf) +int +msgbuf_write(struct msgbuf *msgbuf) { - struct iovec iov[IOV_MAX]; - struct ibuf *buf; - unsigned int i = 0; - ssize_t n; - struct msghdr msg; - struct cmsghdr *cmsg; + struct iovec iov[IOV_MAX]; + struct ibuf *buf; + unsigned int i = 0; + ssize_t n; + struct msghdr msg; + struct cmsghdr *cmsg; union { - struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int))]; + struct cmsghdr hdr; + char buf[CMSG_SPACE(sizeof(int))]; } cmsgbuf; memset(&iov, 0, sizeof(iov)); memset(&msg, 0, sizeof(msg)); memset(&cmsgbuf, 0, sizeof(cmsgbuf)); - TAILQ_FOREACH(buf, &msgbuf->bufs, entry) - { + TAILQ_FOREACH(buf, &msgbuf->bufs, entry) { if (i >= IOV_MAX) break; iov[i].iov_base = buf->buf + buf->rpos; @@ -249,7 +262,7 @@ again: return (-1); } - if (n == 0) { /* connection closed */ + if (n == 0) { /* connection closed */ errno = 0; return (0); } @@ -268,13 +281,15 @@ again: return (1); } -void ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) +void +ibuf_enqueue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_INSERT_TAIL(&msgbuf->bufs, buf, entry); msgbuf->queued++; } -void ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) +void +ibuf_dequeue(struct msgbuf *msgbuf, struct ibuf *buf) { TAILQ_REMOVE(&msgbuf->bufs, buf, entry); diff --git a/lib/imsg.c b/lib/imsg.c index 10650f648a..fc62c13734 100644 --- a/lib/imsg.c +++ b/lib/imsg.c @@ -21,21 +21,22 @@ #include "openbsd-queue.h" #include "imsg.h" -int imsg_fd_overhead = 0; +int imsg_fd_overhead = 0; -int imsg_get_fd(struct imsgbuf *); +int imsg_get_fd(struct imsgbuf *); #ifndef __OpenBSD__ /* * The original code calls getdtablecount() which is OpenBSD specific. Use * available_fds() from OpenSMTPD instead. */ -static int available_fds(unsigned int n) +static int +available_fds(unsigned int n) { - unsigned int i; - int ret, fds[256]; + unsigned int i; + int ret, fds[256]; - if (n > (sizeof(fds) / sizeof(fds[0]))) + if (n > (sizeof(fds)/sizeof(fds[0]))) return (1); ret = 0; @@ -58,7 +59,8 @@ static int available_fds(unsigned int n) } #endif -void imsg_init(struct imsgbuf *ibuf, int fd) +void +imsg_init(struct imsgbuf *ibuf, int fd) { msgbuf_init(&ibuf->w); memset(&ibuf->r, 0, sizeof(ibuf->r)); @@ -68,18 +70,19 @@ void imsg_init(struct imsgbuf *ibuf, int fd) TAILQ_INIT(&ibuf->fds); } -ssize_t imsg_read(struct imsgbuf *ibuf) +ssize_t +imsg_read(struct imsgbuf *ibuf) { - struct msghdr msg; - struct cmsghdr *cmsg; + struct msghdr msg; + struct cmsghdr *cmsg; union { struct cmsghdr hdr; - char buf[CMSG_SPACE(sizeof(int) * 1)]; + char buf[CMSG_SPACE(sizeof(int) * 1)]; } cmsgbuf; - struct iovec iov; - ssize_t n = -1; - int fd; - struct imsg_fd *ifd; + struct iovec iov; + ssize_t n = -1; + int fd; + struct imsg_fd *ifd; memset(&msg, 0, sizeof(msg)); memset(&cmsgbuf, 0, sizeof(cmsgbuf)); @@ -96,14 +99,12 @@ ssize_t imsg_read(struct imsgbuf *ibuf) again: #ifdef __OpenBSD__ - if (getdtablecount() + imsg_fd_overhead - + (int)((CMSG_SPACE(sizeof(int)) - CMSG_SPACE(0)) - / sizeof(int)) + if (getdtablecount() + imsg_fd_overhead + + (int)((CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int)) >= getdtablesize()) { #else - if (available_fds(imsg_fd_overhead - + (CMSG_SPACE(sizeof(int)) - CMSG_SPACE(0)) - / sizeof(int))) { + if (available_fds(imsg_fd_overhead + + (CMSG_SPACE(sizeof(int))-CMSG_SPACE(0))/sizeof(int))) { #endif errno = EAGAIN; free(ifd); @@ -119,9 +120,9 @@ again: ibuf->r.wpos += n; for (cmsg = CMSG_FIRSTHDR(&msg); cmsg != NULL; - cmsg = CMSG_NXTHDR(&msg, cmsg)) { - if (cmsg->cmsg_level == SOL_SOCKET - && cmsg->cmsg_type == SCM_RIGHTS) { + cmsg = CMSG_NXTHDR(&msg, cmsg)) { + if (cmsg->cmsg_level == SOL_SOCKET && + cmsg->cmsg_type == SCM_RIGHTS) { int i; int j; @@ -130,15 +131,14 @@ again: * padding rules, our control buffer might contain * more than one fd, and we must close them. */ - j = ((char *)cmsg + cmsg->cmsg_len - - (char *)CMSG_DATA(cmsg)) - / sizeof(int); + j = ((char *)cmsg + cmsg->cmsg_len - + (char *)CMSG_DATA(cmsg)) / sizeof(int); for (i = 0; i < j; i++) { fd = ((int *)CMSG_DATA(cmsg))[i]; if (ifd != NULL) { ifd->fd = fd; TAILQ_INSERT_TAIL(&ibuf->fds, ifd, - entry); + entry); ifd = NULL; } else close(fd); @@ -152,9 +152,10 @@ fail: return (n); } -ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) +ssize_t +imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) { - size_t av, left, datalen; + size_t av, left, datalen; av = ibuf->r.wpos; @@ -162,7 +163,8 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) return (0); memcpy(&imsg->hdr, ibuf->r.buf, sizeof(imsg->hdr)); - if (imsg->hdr.len < IMSG_HEADER_SIZE || imsg->hdr.len > MAX_IMSGSIZE) { + if (imsg->hdr.len < IMSG_HEADER_SIZE || + imsg->hdr.len > MAX_IMSGSIZE) { errno = ERANGE; return (-1); } @@ -181,7 +183,7 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) imsg->fd = -1; if (imsg->data) - memcpy(imsg->data, ibuf->r.rptr, datalen); + memcpy(imsg->data, ibuf->r.rptr, datalen); if (imsg->hdr.len < av) { left = av - imsg->hdr.len; @@ -193,10 +195,11 @@ ssize_t imsg_get(struct imsgbuf *ibuf, struct imsg *imsg) return (datalen + IMSG_HEADER_SIZE); } -int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, int fd, const void *data, u_int16_t datalen) +int +imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, + pid_t pid, int fd, const void *data, u_int16_t datalen) { - struct ibuf *wbuf; + struct ibuf *wbuf; if ((wbuf = imsg_create(ibuf, type, peerid, pid, datalen)) == NULL) return (-1); @@ -211,11 +214,12 @@ int imsg_compose(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, return (1); } -int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, int fd, const struct iovec *iov, int iovcnt) +int +imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, + pid_t pid, int fd, const struct iovec *iov, int iovcnt) { - struct ibuf *wbuf; - int i, datalen = 0; + struct ibuf *wbuf; + int i, datalen = 0; for (i = 0; i < iovcnt; i++) datalen += iov[i].iov_len; @@ -235,11 +239,12 @@ int imsg_composev(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, } /* ARGSUSED */ -struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, - pid_t pid, u_int16_t datalen) +struct ibuf * +imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, + pid_t pid, u_int16_t datalen) { - struct ibuf *wbuf; - struct imsg_hdr hdr; + struct ibuf *wbuf; + struct imsg_hdr hdr; datalen += IMSG_HEADER_SIZE; if (datalen > MAX_IMSGSIZE) { @@ -261,7 +266,8 @@ struct ibuf *imsg_create(struct imsgbuf *ibuf, u_int32_t type, u_int32_t peerid, return (wbuf); } -int imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) +int +imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) { if (datalen) if (ibuf_add(msg, data, datalen) == -1) { @@ -271,9 +277,10 @@ int imsg_add(struct ibuf *msg, const void *data, u_int16_t datalen) return (datalen); } -void imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) +void +imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) { - struct imsg_hdr *hdr; + struct imsg_hdr *hdr; hdr = (struct imsg_hdr *)msg->buf; @@ -286,15 +293,17 @@ void imsg_close(struct imsgbuf *ibuf, struct ibuf *msg) ibuf_close(&ibuf->w, msg); } -void imsg_free(struct imsg *imsg) +void +imsg_free(struct imsg *imsg) { free(imsg->data); } -int imsg_get_fd(struct imsgbuf *ibuf) +int +imsg_get_fd(struct imsgbuf *ibuf) { - int fd; - struct imsg_fd *ifd; + int fd; + struct imsg_fd *ifd; if ((ifd = TAILQ_FIRST(&ibuf->fds)) == NULL) return (-1); @@ -306,7 +315,8 @@ int imsg_get_fd(struct imsgbuf *ibuf) return (fd); } -int imsg_flush(struct imsgbuf *ibuf) +int +imsg_flush(struct imsgbuf *ibuf) { while (ibuf->w.queued) if (msgbuf_write(&ibuf->w) <= 0) @@ -314,9 +324,10 @@ int imsg_flush(struct imsgbuf *ibuf) return (0); } -void imsg_clear(struct imsgbuf *ibuf) +void +imsg_clear(struct imsgbuf *ibuf) { - int fd; + int fd; msgbuf_clear(&ibuf->w); while ((fd = imsg_get_fd(ibuf)) != -1) diff --git a/lib/imsg.h b/lib/imsg.h index ddaf71344e..d053d01956 100644 --- a/lib/imsg.h +++ b/lib/imsg.h @@ -26,87 +26,87 @@ #define MAX_IMSGSIZE 16384 struct ibuf { - TAILQ_ENTRY(ibuf) entry; - u_char *buf; - size_t size; - size_t max; - size_t wpos; - size_t rpos; - int fd; + TAILQ_ENTRY(ibuf) entry; + u_char *buf; + size_t size; + size_t max; + size_t wpos; + size_t rpos; + int fd; }; struct msgbuf { - TAILQ_HEAD(, ibuf) bufs; - u_int32_t queued; - int fd; + TAILQ_HEAD(, ibuf) bufs; + u_int32_t queued; + int fd; }; struct ibuf_read { - u_char buf[IBUF_READ_SIZE]; - u_char *rptr; - size_t wpos; + u_char buf[IBUF_READ_SIZE]; + u_char *rptr; + size_t wpos; }; struct imsg_fd { - TAILQ_ENTRY(imsg_fd) entry; - int fd; + TAILQ_ENTRY(imsg_fd) entry; + int fd; }; struct imsgbuf { - TAILQ_HEAD(, imsg_fd) fds; - struct ibuf_read r; - struct msgbuf w; - int fd; - pid_t pid; + TAILQ_HEAD(, imsg_fd) fds; + struct ibuf_read r; + struct msgbuf w; + int fd; + pid_t pid; }; #define IMSGF_HASFD 1 struct imsg_hdr { - u_int32_t type; - u_int16_t len; - u_int16_t flags; - u_int32_t peerid; - u_int32_t pid; + u_int32_t type; + u_int16_t len; + u_int16_t flags; + u_int32_t peerid; + u_int32_t pid; }; struct imsg { - struct imsg_hdr hdr; - int fd; - void *data; + struct imsg_hdr hdr; + int fd; + void *data; }; /* buffer.c */ -struct ibuf *ibuf_open(size_t); -struct ibuf *ibuf_dynamic(size_t, size_t); -int ibuf_add(struct ibuf *, const void *, size_t); -void *ibuf_reserve(struct ibuf *, size_t); -void *ibuf_seek(struct ibuf *, size_t, size_t); -size_t ibuf_size(struct ibuf *); -size_t ibuf_left(struct ibuf *); -void ibuf_close(struct msgbuf *, struct ibuf *); -int ibuf_write(struct msgbuf *); -void ibuf_free(struct ibuf *); -void msgbuf_init(struct msgbuf *); -void msgbuf_clear(struct msgbuf *); -int msgbuf_write(struct msgbuf *); -void msgbuf_drain(struct msgbuf *, size_t); +struct ibuf *ibuf_open(size_t); +struct ibuf *ibuf_dynamic(size_t, size_t); +int ibuf_add(struct ibuf *, const void *, size_t); +void *ibuf_reserve(struct ibuf *, size_t); +void *ibuf_seek(struct ibuf *, size_t, size_t); +size_t ibuf_size(struct ibuf *); +size_t ibuf_left(struct ibuf *); +void ibuf_close(struct msgbuf *, struct ibuf *); +int ibuf_write(struct msgbuf *); +void ibuf_free(struct ibuf *); +void msgbuf_init(struct msgbuf *); +void msgbuf_clear(struct msgbuf *); +int msgbuf_write(struct msgbuf *); +void msgbuf_drain(struct msgbuf *, size_t); /* imsg.c */ -void imsg_init(struct imsgbuf *, int); -ssize_t imsg_read(struct imsgbuf *); -ssize_t imsg_get(struct imsgbuf *, struct imsg *); -int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, - const void *, u_int16_t); -int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, int, - const struct iovec *, int); +void imsg_init(struct imsgbuf *, int); +ssize_t imsg_read(struct imsgbuf *); +ssize_t imsg_get(struct imsgbuf *, struct imsg *); +int imsg_compose(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, + int, const void *, u_int16_t); +int imsg_composev(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, + int, const struct iovec *, int); struct ibuf *imsg_create(struct imsgbuf *, u_int32_t, u_int32_t, pid_t, - u_int16_t); -int imsg_add(struct ibuf *, const void *, u_int16_t); -void imsg_close(struct imsgbuf *, struct ibuf *); -void imsg_free(struct imsg *); -int imsg_flush(struct imsgbuf *); -void imsg_clear(struct imsgbuf *); + u_int16_t); +int imsg_add(struct ibuf *, const void *, u_int16_t); +void imsg_close(struct imsgbuf *, struct ibuf *); +void imsg_free(struct imsg *); +int imsg_flush(struct imsgbuf *); +void imsg_clear(struct imsgbuf *); #endif diff --git a/lib/openbsd-tree.c b/lib/openbsd-tree.c index 5d77ac2a47..7e753554c9 100644 --- a/lib/openbsd-tree.c +++ b/lib/openbsd-tree.c @@ -45,14 +45,16 @@ #include -static inline struct rb_entry *rb_n2e(const struct rb_type *t, void *node) +static inline struct rb_entry * +rb_n2e(const struct rb_type *t, void *node) { unsigned long addr = (unsigned long)node; return ((struct rb_entry *)(addr + t->t_offset)); } -static inline void *rb_e2n(const struct rb_type *t, struct rb_entry *rbe) +static inline void * +rb_e2n(const struct rb_type *t, struct rb_entry *rbe) { unsigned long addr = (unsigned long)rbe; @@ -66,33 +68,37 @@ static inline void *rb_e2n(const struct rb_type *t, struct rb_entry *rbe) #define RBH_ROOT(_rbt) (_rbt)->rbt_root -static inline void rbe_set(struct rb_entry *rbe, struct rb_entry *parent) +static inline void +rbe_set(struct rb_entry *rbe, struct rb_entry *parent) { RBE_PARENT(rbe) = parent; RBE_LEFT(rbe) = RBE_RIGHT(rbe) = NULL; RBE_COLOR(rbe) = RB_RED; } -static inline void rbe_set_blackred(struct rb_entry *black, - struct rb_entry *red) +static inline void +rbe_set_blackred(struct rb_entry *black, struct rb_entry *red) { RBE_COLOR(black) = RB_BLACK; RBE_COLOR(red) = RB_RED; } -static inline void rbe_augment(const struct rb_type *t, struct rb_entry *rbe) +static inline void +rbe_augment(const struct rb_type *t, struct rb_entry *rbe) { (*t->t_augment)(rb_e2n(t, rbe)); } -static inline void rbe_if_augment(const struct rb_type *t, struct rb_entry *rbe) +static inline void +rbe_if_augment(const struct rb_type *t, struct rb_entry *rbe) { if (t->t_augment != NULL) rbe_augment(t, rbe); } -static inline void rbe_rotate_left(const struct rb_type *t, - struct rbt_tree *rbt, struct rb_entry *rbe) +static inline void +rbe_rotate_left(const struct rb_type *t, struct rbt_tree *rbt, + struct rb_entry *rbe) { struct rb_entry *parent; struct rb_entry *tmp; @@ -124,8 +130,9 @@ static inline void rbe_rotate_left(const struct rb_type *t, } } -static inline void rbe_rotate_right(const struct rb_type *t, - struct rbt_tree *rbt, struct rb_entry *rbe) +static inline void +rbe_rotate_right(const struct rb_type *t, struct rbt_tree *rbt, + struct rb_entry *rbe) { struct rb_entry *parent; struct rb_entry *tmp; @@ -157,13 +164,14 @@ static inline void rbe_rotate_right(const struct rb_type *t, } } -static inline void rbe_insert_color(const struct rb_type *t, - struct rbt_tree *rbt, struct rb_entry *rbe) +static inline void +rbe_insert_color(const struct rb_type *t, struct rbt_tree *rbt, + struct rb_entry *rbe) { struct rb_entry *parent, *gparent, *tmp; - while ((parent = RBE_PARENT(rbe)) != NULL - && RBE_COLOR(parent) == RB_RED) { + while ((parent = RBE_PARENT(rbe)) != NULL && + RBE_COLOR(parent) == RB_RED) { gparent = RBE_PARENT(parent); if (parent == RBE_LEFT(gparent)) { @@ -208,10 +216,9 @@ static inline void rbe_insert_color(const struct rb_type *t, RBE_COLOR(RBH_ROOT(rbt)) = RB_BLACK; } -static inline void rbe_remove_color(const struct rb_type *t, - struct rbt_tree *rbt, - struct rb_entry *parent, - struct rb_entry *rbe) +static inline void +rbe_remove_color(const struct rb_type *t, struct rbt_tree *rbt, + struct rb_entry *parent, struct rb_entry *rbe) { struct rb_entry *tmp; @@ -219,8 +226,8 @@ static inline void rbe_remove_color(const struct rb_type *t, if (parent == NULL) return; - while ((rbe == NULL || RBE_COLOR(rbe) == RB_BLACK) - && rbe != RBH_ROOT(rbt)) { + while ((rbe == NULL || RBE_COLOR(rbe) == RB_BLACK) && + rbe != RBH_ROOT(rbt)) { if (RBE_LEFT(parent) == rbe) { tmp = RBE_RIGHT(parent); if (RBE_COLOR(tmp) == RB_RED) { @@ -228,16 +235,16 @@ static inline void rbe_remove_color(const struct rb_type *t, rbe_rotate_left(t, rbt, parent); tmp = RBE_RIGHT(parent); } - if ((RBE_LEFT(tmp) == NULL - || RBE_COLOR(RBE_LEFT(tmp)) == RB_BLACK) - && (RBE_RIGHT(tmp) == NULL - || RBE_COLOR(RBE_RIGHT(tmp)) == RB_BLACK)) { + if ((RBE_LEFT(tmp) == NULL || + RBE_COLOR(RBE_LEFT(tmp)) == RB_BLACK) && + (RBE_RIGHT(tmp) == NULL || + RBE_COLOR(RBE_RIGHT(tmp)) == RB_BLACK)) { RBE_COLOR(tmp) = RB_RED; rbe = parent; parent = RBE_PARENT(rbe); } else { - if (RBE_RIGHT(tmp) == NULL - || RBE_COLOR(RBE_RIGHT(tmp)) == RB_BLACK) { + if (RBE_RIGHT(tmp) == NULL || + RBE_COLOR(RBE_RIGHT(tmp)) == RB_BLACK) { struct rb_entry *oleft; oleft = RBE_LEFT(tmp); @@ -266,16 +273,16 @@ static inline void rbe_remove_color(const struct rb_type *t, tmp = RBE_LEFT(parent); } - if ((RBE_LEFT(tmp) == NULL - || RBE_COLOR(RBE_LEFT(tmp)) == RB_BLACK) - && (RBE_RIGHT(tmp) == NULL - || RBE_COLOR(RBE_RIGHT(tmp)) == RB_BLACK)) { + if ((RBE_LEFT(tmp) == NULL || + RBE_COLOR(RBE_LEFT(tmp)) == RB_BLACK) && + (RBE_RIGHT(tmp) == NULL || + RBE_COLOR(RBE_RIGHT(tmp)) == RB_BLACK)) { RBE_COLOR(tmp) = RB_RED; rbe = parent; parent = RBE_PARENT(rbe); } else { - if (RBE_LEFT(tmp) == NULL - || RBE_COLOR(RBE_LEFT(tmp)) == RB_BLACK) { + if (RBE_LEFT(tmp) == NULL || + RBE_COLOR(RBE_LEFT(tmp)) == RB_BLACK) { struct rb_entry *oright; oright = RBE_RIGHT(tmp); @@ -385,7 +392,8 @@ color: return (old); } -void *_rb_remove(const struct rb_type *t, struct rbt_tree *rbt, void *elm) +void * +_rb_remove(const struct rb_type *t, struct rbt_tree *rbt, void *elm) { struct rb_entry *rbe = rb_n2e(t, elm); struct rb_entry *old; @@ -395,7 +403,8 @@ void *_rb_remove(const struct rb_type *t, struct rbt_tree *rbt, void *elm) return (old == NULL ? NULL : rb_e2n(t, old)); } -void *_rb_insert(const struct rb_type *t, struct rbt_tree *rbt, void *elm) +void * +_rb_insert(const struct rb_type *t, struct rbt_tree *rbt, void *elm) { struct rb_entry *rbe = rb_n2e(t, elm); struct rb_entry *tmp; @@ -435,7 +444,8 @@ void *_rb_insert(const struct rb_type *t, struct rbt_tree *rbt, void *elm) } /* Finds the node with the same key as elm */ -void *_rb_find(const struct rb_type *t, struct rbt_tree *rbt, const void *key) +void * +_rb_find(const struct rb_type *t, struct rbt_tree *rbt, const void *key) { struct rb_entry *tmp = RBH_ROOT(rbt); void *node; @@ -456,7 +466,8 @@ void *_rb_find(const struct rb_type *t, struct rbt_tree *rbt, const void *key) } /* Finds the first node greater than or equal to the search key */ -void *_rb_nfind(const struct rb_type *t, struct rbt_tree *rbt, const void *key) +void * +_rb_nfind(const struct rb_type *t, struct rbt_tree *rbt, const void *key) { struct rb_entry *tmp = RBH_ROOT(rbt); void *node; @@ -478,7 +489,8 @@ void *_rb_nfind(const struct rb_type *t, struct rbt_tree *rbt, const void *key) return (res); } -void *_rb_next(const struct rb_type *t, void *elm) +void * +_rb_next(const struct rb_type *t, void *elm) { struct rb_entry *rbe = rb_n2e(t, elm); @@ -487,11 +499,12 @@ void *_rb_next(const struct rb_type *t, void *elm) while (RBE_LEFT(rbe) != NULL) rbe = RBE_LEFT(rbe); } else { - if (RBE_PARENT(rbe) && (rbe == RBE_LEFT(RBE_PARENT(rbe)))) + if (RBE_PARENT(rbe) && + (rbe == RBE_LEFT(RBE_PARENT(rbe)))) rbe = RBE_PARENT(rbe); else { - while (RBE_PARENT(rbe) - && (rbe == RBE_RIGHT(RBE_PARENT(rbe)))) + while (RBE_PARENT(rbe) && + (rbe == RBE_RIGHT(RBE_PARENT(rbe)))) rbe = RBE_PARENT(rbe); rbe = RBE_PARENT(rbe); } @@ -500,7 +513,8 @@ void *_rb_next(const struct rb_type *t, void *elm) return (rbe == NULL ? NULL : rb_e2n(t, rbe)); } -void *_rb_prev(const struct rb_type *t, void *elm) +void * +_rb_prev(const struct rb_type *t, void *elm) { struct rb_entry *rbe = rb_n2e(t, elm); @@ -509,11 +523,12 @@ void *_rb_prev(const struct rb_type *t, void *elm) while (RBE_RIGHT(rbe)) rbe = RBE_RIGHT(rbe); } else { - if (RBE_PARENT(rbe) && (rbe == RBE_RIGHT(RBE_PARENT(rbe)))) + if (RBE_PARENT(rbe) && + (rbe == RBE_RIGHT(RBE_PARENT(rbe)))) rbe = RBE_PARENT(rbe); else { - while (RBE_PARENT(rbe) - && (rbe == RBE_LEFT(RBE_PARENT(rbe)))) + while (RBE_PARENT(rbe) && + (rbe == RBE_LEFT(RBE_PARENT(rbe)))) rbe = RBE_PARENT(rbe); rbe = RBE_PARENT(rbe); } @@ -522,14 +537,16 @@ void *_rb_prev(const struct rb_type *t, void *elm) return (rbe == NULL ? NULL : rb_e2n(t, rbe)); } -void *_rb_root(const struct rb_type *t, struct rbt_tree *rbt) +void * +_rb_root(const struct rb_type *t, struct rbt_tree *rbt) { struct rb_entry *rbe = RBH_ROOT(rbt); return (rbe == NULL ? rbe : rb_e2n(t, rbe)); } -void *_rb_min(const struct rb_type *t, struct rbt_tree *rbt) +void * +_rb_min(const struct rb_type *t, struct rbt_tree *rbt) { struct rb_entry *rbe = RBH_ROOT(rbt); struct rb_entry *parent = NULL; @@ -542,7 +559,8 @@ void *_rb_min(const struct rb_type *t, struct rbt_tree *rbt) return (parent == NULL ? NULL : rb_e2n(t, parent)); } -void *_rb_max(const struct rb_type *t, struct rbt_tree *rbt) +void * +_rb_max(const struct rb_type *t, struct rbt_tree *rbt) { struct rb_entry *rbe = RBH_ROOT(rbt); struct rb_entry *parent = NULL; @@ -555,28 +573,32 @@ void *_rb_max(const struct rb_type *t, struct rbt_tree *rbt) return (parent == NULL ? NULL : rb_e2n(t, parent)); } -void *_rb_left(const struct rb_type *t, void *node) +void * +_rb_left(const struct rb_type *t, void *node) { struct rb_entry *rbe = rb_n2e(t, node); rbe = RBE_LEFT(rbe); return (rbe == NULL ? NULL : rb_e2n(t, rbe)); } -void *_rb_right(const struct rb_type *t, void *node) +void * +_rb_right(const struct rb_type *t, void *node) { struct rb_entry *rbe = rb_n2e(t, node); rbe = RBE_RIGHT(rbe); return (rbe == NULL ? NULL : rb_e2n(t, rbe)); } -void *_rb_parent(const struct rb_type *t, void *node) +void * +_rb_parent(const struct rb_type *t, void *node) { struct rb_entry *rbe = rb_n2e(t, node); rbe = RBE_PARENT(rbe); return (rbe == NULL ? NULL : rb_e2n(t, rbe)); } -void _rb_set_left(const struct rb_type *t, void *node, void *left) +void +_rb_set_left(const struct rb_type *t, void *node, void *left) { struct rb_entry *rbe = rb_n2e(t, node); struct rb_entry *rbl = (left == NULL) ? NULL : rb_n2e(t, left); @@ -584,7 +606,8 @@ void _rb_set_left(const struct rb_type *t, void *node, void *left) RBE_LEFT(rbe) = rbl; } -void _rb_set_right(const struct rb_type *t, void *node, void *right) +void +_rb_set_right(const struct rb_type *t, void *node, void *right) { struct rb_entry *rbe = rb_n2e(t, node); struct rb_entry *rbr = (right == NULL) ? NULL : rb_n2e(t, right); @@ -592,7 +615,8 @@ void _rb_set_right(const struct rb_type *t, void *node, void *right) RBE_RIGHT(rbe) = rbr; } -void _rb_set_parent(const struct rb_type *t, void *node, void *parent) +void +_rb_set_parent(const struct rb_type *t, void *node, void *parent) { struct rb_entry *rbe = rb_n2e(t, node); struct rb_entry *rbp = (parent == NULL) ? NULL : rb_n2e(t, parent); @@ -600,19 +624,21 @@ void _rb_set_parent(const struct rb_type *t, void *node, void *parent) RBE_PARENT(rbe) = rbp; } -void _rb_poison(const struct rb_type *t, void *node, unsigned long poison) +void +_rb_poison(const struct rb_type *t, void *node, unsigned long poison) { struct rb_entry *rbe = rb_n2e(t, node); RBE_PARENT(rbe) = RBE_LEFT(rbe) = RBE_RIGHT(rbe) = - (struct rb_entry *)poison; + (struct rb_entry *)poison; } -int _rb_check(const struct rb_type *t, void *node, unsigned long poison) +int +_rb_check(const struct rb_type *t, void *node, unsigned long poison) { struct rb_entry *rbe = rb_n2e(t, node); - return ((unsigned long)RBE_PARENT(rbe) == poison - && (unsigned long)RBE_LEFT(rbe) == poison - && (unsigned long)RBE_RIGHT(rbe) == poison); + return ((unsigned long)RBE_PARENT(rbe) == poison && + (unsigned long)RBE_LEFT(rbe) == poison && + (unsigned long)RBE_RIGHT(rbe) == poison); } diff --git a/lib/openbsd-tree.h b/lib/openbsd-tree.h index 859f751678..22cb9252f5 100644 --- a/lib/openbsd-tree.h +++ b/lib/openbsd-tree.h @@ -24,7 +24,7 @@ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. */ -#ifndef _SYS_TREE_H_ +#ifndef _SYS_TREE_H_ #define _SYS_TREE_H_ /* @@ -54,26 +54,23 @@ * The maximum height of a red-black tree is 2lg (n+1). */ -#define SPLAY_HEAD(name, type) \ - struct name { \ - struct type *sph_root; /* root of the tree */ \ - } +#define SPLAY_HEAD(name, type) \ +struct name { \ + struct type *sph_root; /* root of the tree */ \ +} -#define SPLAY_INITIALIZER(root) \ - { \ - NULL \ - } +#define SPLAY_INITIALIZER(root) \ + { NULL } -#define SPLAY_INIT(root) \ - do { \ - (root)->sph_root = NULL; \ - } while (0) +#define SPLAY_INIT(root) do { \ + (root)->sph_root = NULL; \ +} while (0) -#define SPLAY_ENTRY(type) \ - struct { \ - struct type *spe_left; /* left element */ \ - struct type *spe_right; /* right element */ \ - } +#define SPLAY_ENTRY(type) \ +struct { \ + struct type *spe_left; /* left element */ \ + struct type *spe_right; /* right element */ \ +} #define SPLAY_LEFT(elm, field) (elm)->field.spe_left #define SPLAY_RIGHT(elm, field) (elm)->field.spe_right @@ -81,220 +78,197 @@ #define SPLAY_EMPTY(head) (SPLAY_ROOT(head) == NULL) /* SPLAY_ROTATE_{LEFT,RIGHT} expect that tmp hold SPLAY_{RIGHT,LEFT} */ -#define SPLAY_ROTATE_RIGHT(head, tmp, field) \ - do { \ - SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ - SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ - (head)->sph_root = tmp; \ - } while (0) +#define SPLAY_ROTATE_RIGHT(head, tmp, field) do { \ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(tmp, field); \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) -#define SPLAY_ROTATE_LEFT(head, tmp, field) \ - do { \ - SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ - SPLAY_LEFT(tmp, field) = (head)->sph_root; \ - (head)->sph_root = tmp; \ - } while (0) +#define SPLAY_ROTATE_LEFT(head, tmp, field) do { \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(tmp, field); \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + (head)->sph_root = tmp; \ +} while (0) -#define SPLAY_LINKLEFT(head, tmp, field) \ - do { \ - SPLAY_LEFT(tmp, field) = (head)->sph_root; \ - tmp = (head)->sph_root; \ - (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ - } while (0) +#define SPLAY_LINKLEFT(head, tmp, field) do { \ + SPLAY_LEFT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field); \ +} while (0) -#define SPLAY_LINKRIGHT(head, tmp, field) \ - do { \ - SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ - tmp = (head)->sph_root; \ - (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ - } while (0) +#define SPLAY_LINKRIGHT(head, tmp, field) do { \ + SPLAY_RIGHT(tmp, field) = (head)->sph_root; \ + tmp = (head)->sph_root; \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field); \ +} while (0) -#define SPLAY_ASSEMBLE(head, node, left, right, field) \ - do { \ - SPLAY_RIGHT(left, field) = \ - SPLAY_LEFT((head)->sph_root, field); \ - SPLAY_LEFT(right, field) = \ - SPLAY_RIGHT((head)->sph_root, field); \ - SPLAY_LEFT((head)->sph_root, field) = \ - SPLAY_RIGHT(node, field); \ - SPLAY_RIGHT((head)->sph_root, field) = \ - SPLAY_LEFT(node, field); \ - } while (0) +#define SPLAY_ASSEMBLE(head, node, left, right, field) do { \ + SPLAY_RIGHT(left, field) = SPLAY_LEFT((head)->sph_root, field); \ + SPLAY_LEFT(right, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT((head)->sph_root, field) = SPLAY_RIGHT(node, field); \ + SPLAY_RIGHT((head)->sph_root, field) = SPLAY_LEFT(node, field); \ +} while (0) /* Generates prototypes and inline functions */ -#define SPLAY_PROTOTYPE(name, type, field, cmp) \ - void name##_SPLAY(struct name *, struct type *); \ - void name##_SPLAY_MINMAX(struct name *, int); \ - struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ - struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ - \ - /* Finds the node with the same key as elm */ \ - static __inline struct type *name##_SPLAY_FIND(struct name *head, \ - struct type *elm) \ - { \ - if (SPLAY_EMPTY(head)) \ - return (NULL); \ - name##_SPLAY(head, elm); \ - if ((cmp)(elm, (head)->sph_root) == 0) \ - return (head->sph_root); \ - return (NULL); \ - } \ - \ - static __inline struct type *name##_SPLAY_NEXT(struct name *head, \ - struct type *elm) \ - { \ - name##_SPLAY(head, elm); \ - if (SPLAY_RIGHT(elm, field) != NULL) { \ - elm = SPLAY_RIGHT(elm, field); \ - while (SPLAY_LEFT(elm, field) != NULL) { \ - elm = SPLAY_LEFT(elm, field); \ - } \ - } else \ - elm = NULL; \ - return (elm); \ - } \ - \ - static __inline struct type *name##_SPLAY_MIN_MAX(struct name *head, \ - int val) \ - { \ - name##_SPLAY_MINMAX(head, val); \ - return (SPLAY_ROOT(head)); \ - } +#define SPLAY_PROTOTYPE(name, type, field, cmp) \ +void name##_SPLAY(struct name *, struct type *); \ +void name##_SPLAY_MINMAX(struct name *, int); \ +struct type *name##_SPLAY_INSERT(struct name *, struct type *); \ +struct type *name##_SPLAY_REMOVE(struct name *, struct type *); \ + \ +/* Finds the node with the same key as elm */ \ +static __inline struct type * \ +name##_SPLAY_FIND(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) \ + return(NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) \ + return (head->sph_root); \ + return (NULL); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_NEXT(struct name *head, struct type *elm) \ +{ \ + name##_SPLAY(head, elm); \ + if (SPLAY_RIGHT(elm, field) != NULL) { \ + elm = SPLAY_RIGHT(elm, field); \ + while (SPLAY_LEFT(elm, field) != NULL) { \ + elm = SPLAY_LEFT(elm, field); \ + } \ + } else \ + elm = NULL; \ + return (elm); \ +} \ + \ +static __inline struct type * \ +name##_SPLAY_MIN_MAX(struct name *head, int val) \ +{ \ + name##_SPLAY_MINMAX(head, val); \ + return (SPLAY_ROOT(head)); \ +} /* Main splay operation. * Moves node close to the key of elm to top */ -#define SPLAY_GENERATE(name, type, field, cmp) \ - struct type *name##_SPLAY_INSERT(struct name *head, struct type *elm) \ - { \ - if (SPLAY_EMPTY(head)) { \ - SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = \ - NULL; \ - } else { \ - int __comp; \ - name##_SPLAY(head, elm); \ - __comp = (cmp)(elm, (head)->sph_root); \ - if (__comp < 0) { \ - SPLAY_LEFT(elm, field) = \ - SPLAY_LEFT((head)->sph_root, field); \ - SPLAY_RIGHT(elm, field) = (head)->sph_root; \ - SPLAY_LEFT((head)->sph_root, field) = NULL; \ - } else if (__comp > 0) { \ - SPLAY_RIGHT(elm, field) = \ - SPLAY_RIGHT((head)->sph_root, field); \ - SPLAY_LEFT(elm, field) = (head)->sph_root; \ - SPLAY_RIGHT((head)->sph_root, field) = NULL; \ - } else \ - return ((head)->sph_root); \ - } \ - (head)->sph_root = (elm); \ - return (NULL); \ - } \ - \ - struct type *name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ - { \ - struct type *__tmp; \ - if (SPLAY_EMPTY(head)) \ - return (NULL); \ - name##_SPLAY(head, elm); \ - if ((cmp)(elm, (head)->sph_root) == 0) { \ - if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ - (head)->sph_root = \ - SPLAY_RIGHT((head)->sph_root, field); \ - } else { \ - __tmp = SPLAY_RIGHT((head)->sph_root, field); \ - (head)->sph_root = \ - SPLAY_LEFT((head)->sph_root, field); \ - name##_SPLAY(head, elm); \ - SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ - } \ - return (elm); \ - } \ - return (NULL); \ - } \ - \ - void name##_SPLAY(struct name *head, struct type *elm) \ - { \ - struct type __node, *__left, *__right, *__tmp; \ - int __comp; \ - \ - SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = \ - NULL; \ - __left = __right = &__node; \ - \ - while ((__comp = (cmp)(elm, (head)->sph_root))) { \ - if (__comp < 0) { \ - __tmp = SPLAY_LEFT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if ((cmp)(elm, __tmp) < 0) { \ - SPLAY_ROTATE_RIGHT(head, __tmp, \ - field); \ - if (SPLAY_LEFT((head)->sph_root, \ - field) \ - == NULL) \ - break; \ - } \ - SPLAY_LINKLEFT(head, __right, field); \ - } else if (__comp > 0) { \ - __tmp = SPLAY_RIGHT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if ((cmp)(elm, __tmp) > 0) { \ - SPLAY_ROTATE_LEFT(head, __tmp, field); \ - if (SPLAY_RIGHT((head)->sph_root, \ - field) \ - == NULL) \ - break; \ - } \ - SPLAY_LINKRIGHT(head, __left, field); \ - } \ - } \ - SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ - } \ - \ - /* Splay with either the minimum or the maximum element \ - * Used to find minimum or maximum element in tree. \ - */ \ - void name##_SPLAY_MINMAX(struct name *head, int __comp) \ - { \ - struct type __node, *__left, *__right, *__tmp; \ - \ - SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = \ - NULL; \ - __left = __right = &__node; \ - \ - while (1) { \ - if (__comp < 0) { \ - __tmp = SPLAY_LEFT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if (__comp < 0) { \ - SPLAY_ROTATE_RIGHT(head, __tmp, \ - field); \ - if (SPLAY_LEFT((head)->sph_root, \ - field) \ - == NULL) \ - break; \ - } \ - SPLAY_LINKLEFT(head, __right, field); \ - } else if (__comp > 0) { \ - __tmp = SPLAY_RIGHT((head)->sph_root, field); \ - if (__tmp == NULL) \ - break; \ - if (__comp > 0) { \ - SPLAY_ROTATE_LEFT(head, __tmp, field); \ - if (SPLAY_RIGHT((head)->sph_root, \ - field) \ - == NULL) \ - break; \ - } \ - SPLAY_LINKRIGHT(head, __left, field); \ - } \ - } \ - SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ - } +#define SPLAY_GENERATE(name, type, field, cmp) \ +struct type * \ +name##_SPLAY_INSERT(struct name *head, struct type *elm) \ +{ \ + if (SPLAY_EMPTY(head)) { \ + SPLAY_LEFT(elm, field) = SPLAY_RIGHT(elm, field) = NULL; \ + } else { \ + int __comp; \ + name##_SPLAY(head, elm); \ + __comp = (cmp)(elm, (head)->sph_root); \ + if(__comp < 0) { \ + SPLAY_LEFT(elm, field) = SPLAY_LEFT((head)->sph_root, field);\ + SPLAY_RIGHT(elm, field) = (head)->sph_root; \ + SPLAY_LEFT((head)->sph_root, field) = NULL; \ + } else if (__comp > 0) { \ + SPLAY_RIGHT(elm, field) = SPLAY_RIGHT((head)->sph_root, field);\ + SPLAY_LEFT(elm, field) = (head)->sph_root; \ + SPLAY_RIGHT((head)->sph_root, field) = NULL; \ + } else \ + return ((head)->sph_root); \ + } \ + (head)->sph_root = (elm); \ + return (NULL); \ +} \ + \ +struct type * \ +name##_SPLAY_REMOVE(struct name *head, struct type *elm) \ +{ \ + struct type *__tmp; \ + if (SPLAY_EMPTY(head)) \ + return (NULL); \ + name##_SPLAY(head, elm); \ + if ((cmp)(elm, (head)->sph_root) == 0) { \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL) { \ + (head)->sph_root = SPLAY_RIGHT((head)->sph_root, field);\ + } else { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + (head)->sph_root = SPLAY_LEFT((head)->sph_root, field);\ + name##_SPLAY(head, elm); \ + SPLAY_RIGHT((head)->sph_root, field) = __tmp; \ + } \ + return (elm); \ + } \ + return (NULL); \ +} \ + \ +void \ +name##_SPLAY(struct name *head, struct type *elm) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ + int __comp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while ((__comp = (cmp)(elm, (head)->sph_root))) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if ((cmp)(elm, __tmp) > 0){ \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} \ + \ +/* Splay with either the minimum or the maximum element \ + * Used to find minimum or maximum element in tree. \ + */ \ +void name##_SPLAY_MINMAX(struct name *head, int __comp) \ +{ \ + struct type __node, *__left, *__right, *__tmp; \ +\ + SPLAY_LEFT(&__node, field) = SPLAY_RIGHT(&__node, field) = NULL;\ + __left = __right = &__node; \ +\ + while (1) { \ + if (__comp < 0) { \ + __tmp = SPLAY_LEFT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp < 0){ \ + SPLAY_ROTATE_RIGHT(head, __tmp, field); \ + if (SPLAY_LEFT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKLEFT(head, __right, field); \ + } else if (__comp > 0) { \ + __tmp = SPLAY_RIGHT((head)->sph_root, field); \ + if (__tmp == NULL) \ + break; \ + if (__comp > 0) { \ + SPLAY_ROTATE_LEFT(head, __tmp, field); \ + if (SPLAY_RIGHT((head)->sph_root, field) == NULL)\ + break; \ + } \ + SPLAY_LINKRIGHT(head, __left, field); \ + } \ + } \ + SPLAY_ASSEMBLE(head, &__node, __left, __right, field); \ +} #define SPLAY_NEGINF -1 #define SPLAY_INF 1 @@ -303,13 +277,14 @@ #define SPLAY_REMOVE(name, x, y) name##_SPLAY_REMOVE(x, y) #define SPLAY_FIND(name, x, y) name##_SPLAY_FIND(x, y) #define SPLAY_NEXT(name, x, y) name##_SPLAY_NEXT(x, y) -#define SPLAY_MIN(name, x) \ - (SPLAY_EMPTY(x) ? NULL : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) -#define SPLAY_MAX(name, x) \ - (SPLAY_EMPTY(x) ? NULL : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) +#define SPLAY_MIN(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_NEGINF)) +#define SPLAY_MAX(name, x) (SPLAY_EMPTY(x) ? NULL \ + : name##_SPLAY_MIN_MAX(x, SPLAY_INF)) -#define SPLAY_FOREACH(x, name, head) \ - for ((x) = SPLAY_MIN(name, head); (x) != NULL; \ +#define SPLAY_FOREACH(x, name, head) \ + for ((x) = SPLAY_MIN(name, head); \ + (x) != NULL; \ (x) = SPLAY_NEXT(name, head, x)) /* @@ -332,197 +307,203 @@ #define RB_RED 1 struct rb_type { - int (*t_compare)(const void *, const void *); - void (*t_augment)(void *); - unsigned int t_offset; /* offset of rb_entry in type */ + int (*t_compare)(const void *, const void *); + void (*t_augment)(void *); + unsigned int t_offset; /* offset of rb_entry in type */ }; struct rbt_tree { - struct rb_entry *rbt_root; + struct rb_entry *rbt_root; }; struct rb_entry { - struct rb_entry *rbt_parent; - struct rb_entry *rbt_left; - struct rb_entry *rbt_right; - unsigned int rbt_color; + struct rb_entry *rbt_parent; + struct rb_entry *rbt_left; + struct rb_entry *rbt_right; + unsigned int rbt_color; }; -#define RB_HEAD(_name, _type) \ - struct _name { \ - struct rbt_tree rbh_root; \ - } +#define RB_HEAD(_name, _type) \ +struct _name { \ + struct rbt_tree rbh_root; \ +} #define RB_ENTRY(_type) struct rb_entry -static inline void _rb_init(struct rbt_tree *rbt) +static inline void +_rb_init(struct rbt_tree *rbt) { rbt->rbt_root = NULL; } -static inline int _rb_empty(struct rbt_tree *rbt) +static inline int +_rb_empty(struct rbt_tree *rbt) { return (rbt->rbt_root == NULL); } -void *_rb_insert(const struct rb_type *, struct rbt_tree *, void *); -void *_rb_remove(const struct rb_type *, struct rbt_tree *, void *); -void *_rb_find(const struct rb_type *, struct rbt_tree *, const void *); -void *_rb_nfind(const struct rb_type *, struct rbt_tree *, const void *); -void *_rb_root(const struct rb_type *, struct rbt_tree *); -void *_rb_min(const struct rb_type *, struct rbt_tree *); -void *_rb_max(const struct rb_type *, struct rbt_tree *); -void *_rb_next(const struct rb_type *, void *); -void *_rb_prev(const struct rb_type *, void *); -void *_rb_left(const struct rb_type *, void *); -void *_rb_right(const struct rb_type *, void *); -void *_rb_parent(const struct rb_type *, void *); -void _rb_set_left(const struct rb_type *, void *, void *); -void _rb_set_right(const struct rb_type *, void *, void *); -void _rb_set_parent(const struct rb_type *, void *, void *); -void _rb_poison(const struct rb_type *, void *, unsigned long); -int _rb_check(const struct rb_type *, void *, unsigned long); +void *_rb_insert(const struct rb_type *, struct rbt_tree *, void *); +void *_rb_remove(const struct rb_type *, struct rbt_tree *, void *); +void *_rb_find(const struct rb_type *, struct rbt_tree *, const void *); +void *_rb_nfind(const struct rb_type *, struct rbt_tree *, const void *); +void *_rb_root(const struct rb_type *, struct rbt_tree *); +void *_rb_min(const struct rb_type *, struct rbt_tree *); +void *_rb_max(const struct rb_type *, struct rbt_tree *); +void *_rb_next(const struct rb_type *, void *); +void *_rb_prev(const struct rb_type *, void *); +void *_rb_left(const struct rb_type *, void *); +void *_rb_right(const struct rb_type *, void *); +void *_rb_parent(const struct rb_type *, void *); +void _rb_set_left(const struct rb_type *, void *, void *); +void _rb_set_right(const struct rb_type *, void *, void *); +void _rb_set_parent(const struct rb_type *, void *, void *); +void _rb_poison(const struct rb_type *, void *, unsigned long); +int _rb_check(const struct rb_type *, void *, unsigned long); #define RB_INITIALIZER(_head) { { NULL } } -#define RB_PROTOTYPE(_name, _type, _field, _cmp) \ - extern const struct rb_type *const _name##_RB_TYPE; \ - \ - __attribute__((__unused__)) static inline void _name##_RB_INIT( \ - struct _name *head) \ - { \ - _rb_init(&head->rbh_root); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_INSERT(struct _name *head, struct _type *elm) \ - { \ - return _rb_insert(_name##_RB_TYPE, &head->rbh_root, elm); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_REMOVE(struct _name *head, struct _type *elm) \ - { \ - return _rb_remove(_name##_RB_TYPE, &head->rbh_root, elm); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_FIND(struct _name *head, const struct _type *key) \ - { \ - return _rb_find(_name##_RB_TYPE, &head->rbh_root, key); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_NFIND(struct _name *head, const struct _type *key) \ - { \ - return _rb_nfind(_name##_RB_TYPE, &head->rbh_root, key); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_ROOT(struct _name *head) \ - { \ - return _rb_root(_name##_RB_TYPE, &head->rbh_root); \ - } \ - \ - __attribute__((__unused__)) static inline int _name##_RB_EMPTY( \ - struct _name *head) \ - { \ - return _rb_empty(&head->rbh_root); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_MIN(struct _name *head) \ - { \ - return _rb_min(_name##_RB_TYPE, &head->rbh_root); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_MAX(struct _name *head) \ - { \ - return _rb_max(_name##_RB_TYPE, &head->rbh_root); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_NEXT(struct _type *elm) \ - { \ - return _rb_next(_name##_RB_TYPE, elm); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_PREV(struct _type *elm) \ - { \ - return _rb_prev(_name##_RB_TYPE, elm); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_LEFT(struct _type *elm) \ - { \ - return _rb_left(_name##_RB_TYPE, elm); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_RIGHT(struct _type *elm) \ - { \ - return _rb_right(_name##_RB_TYPE, elm); \ - } \ - \ - __attribute__((__unused__)) static inline struct _type \ - *_name##_RB_PARENT(struct _type *elm) \ - { \ - return _rb_parent(_name##_RB_TYPE, elm); \ - } \ - \ - __attribute__((__unused__)) static inline void _name##_RB_SET_LEFT( \ - struct _type *elm, struct _type *left) \ - { \ - return _rb_set_left(_name##_RB_TYPE, elm, left); \ - } \ - \ - __attribute__((__unused__)) static inline void _name##_RB_SET_RIGHT( \ - struct _type *elm, struct _type *right) \ - { \ - return _rb_set_right(_name##_RB_TYPE, elm, right); \ - } \ - \ - __attribute__((__unused__)) static inline void _name##_RB_SET_PARENT( \ - struct _type *elm, struct _type *parent) \ - { \ - return _rb_set_parent(_name##_RB_TYPE, elm, parent); \ - } \ - \ - __attribute__((__unused__)) static inline void _name##_RB_POISON( \ - struct _type *elm, unsigned long poison) \ - { \ - return _rb_poison(_name##_RB_TYPE, elm, poison); \ - } \ - \ - __attribute__((__unused__)) static inline int _name##_RB_CHECK( \ - struct _type *elm, unsigned long poison) \ - { \ - return _rb_check(_name##_RB_TYPE, elm, poison); \ - } +#define RB_PROTOTYPE(_name, _type, _field, _cmp) \ +extern const struct rb_type *const _name##_RB_TYPE; \ + \ +__attribute__((__unused__)) static inline void \ +_name##_RB_INIT(struct _name *head) \ +{ \ + _rb_init(&head->rbh_root); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_INSERT(struct _name *head, struct _type *elm) \ +{ \ + return _rb_insert(_name##_RB_TYPE, &head->rbh_root, elm); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_REMOVE(struct _name *head, struct _type *elm) \ +{ \ + return _rb_remove(_name##_RB_TYPE, &head->rbh_root, elm); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_FIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_find(_name##_RB_TYPE, &head->rbh_root, key); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_NFIND(struct _name *head, const struct _type *key) \ +{ \ + return _rb_nfind(_name##_RB_TYPE, &head->rbh_root, key); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_ROOT(struct _name *head) \ +{ \ + return _rb_root(_name##_RB_TYPE, &head->rbh_root); \ +} \ + \ +__attribute__((__unused__)) static inline int \ +_name##_RB_EMPTY(struct _name *head) \ +{ \ + return _rb_empty(&head->rbh_root); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_MIN(struct _name *head) \ +{ \ + return _rb_min(_name##_RB_TYPE, &head->rbh_root); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_MAX(struct _name *head) \ +{ \ + return _rb_max(_name##_RB_TYPE, &head->rbh_root); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_NEXT(struct _type *elm) \ +{ \ + return _rb_next(_name##_RB_TYPE, elm); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_PREV(struct _type *elm) \ +{ \ + return _rb_prev(_name##_RB_TYPE, elm); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_LEFT(struct _type *elm) \ +{ \ + return _rb_left(_name##_RB_TYPE, elm); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_RIGHT(struct _type *elm) \ +{ \ + return _rb_right(_name##_RB_TYPE, elm); \ +} \ + \ +__attribute__((__unused__)) static inline struct _type * \ +_name##_RB_PARENT(struct _type *elm) \ +{ \ + return _rb_parent(_name##_RB_TYPE, elm); \ +} \ + \ +__attribute__((__unused__)) static inline void \ +_name##_RB_SET_LEFT(struct _type *elm, struct _type *left) \ +{ \ + return _rb_set_left(_name##_RB_TYPE, elm, left); \ +} \ + \ +__attribute__((__unused__)) static inline void \ +_name##_RB_SET_RIGHT(struct _type *elm, struct _type *right) \ +{ \ + return _rb_set_right(_name##_RB_TYPE, elm, right); \ +} \ + \ +__attribute__((__unused__)) static inline void \ +_name##_RB_SET_PARENT(struct _type *elm, struct _type *parent) \ +{ \ + return _rb_set_parent(_name##_RB_TYPE, elm, parent); \ +} \ + \ +__attribute__((__unused__)) static inline void \ +_name##_RB_POISON(struct _type *elm, unsigned long poison) \ +{ \ + return _rb_poison(_name##_RB_TYPE, elm, poison); \ +} \ + \ +__attribute__((__unused__)) static inline int \ +_name##_RB_CHECK(struct _type *elm, unsigned long poison) \ +{ \ + return _rb_check(_name##_RB_TYPE, elm, poison); \ +} -#define RB_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ - static int _name##_RB_COMPARE(const void *lptr, const void *rptr) \ - { \ - const struct _type *l = lptr, *r = rptr; \ - return _cmp(l, r); \ - } \ - static const struct rb_type _name##_RB_INFO = { \ - _name##_RB_COMPARE, _aug, offsetof(struct _type, _field), \ - }; \ - const struct rb_type *const _name##_RB_TYPE = &_name##_RB_INFO; +#define RB_GENERATE_INTERNAL(_name, _type, _field, _cmp, _aug) \ +static int \ +_name##_RB_COMPARE(const void *lptr, const void *rptr) \ +{ \ + const struct _type *l = lptr, *r = rptr; \ + return _cmp(l, r); \ +} \ +static const struct rb_type _name##_RB_INFO = { \ + _name##_RB_COMPARE, \ + _aug, \ + offsetof(struct _type, _field), \ +}; \ +const struct rb_type *const _name##_RB_TYPE = &_name##_RB_INFO; -#define RB_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ - static void _name##_RB_AUGMENT(void *ptr) \ - { \ - struct _type *p = ptr; \ - return _aug(p); \ - } \ - RB_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RB_AUGMENT) +#define RB_GENERATE_AUGMENT(_name, _type, _field, _cmp, _aug) \ +static void \ +_name##_RB_AUGMENT(void *ptr) \ +{ \ + struct _type *p = ptr; \ + return _aug(p); \ +} \ +RB_GENERATE_INTERNAL(_name, _type, _field, _cmp, _name##_RB_AUGMENT) -#define RB_GENERATE(_name, _type, _field, _cmp) \ - RB_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) +#define RB_GENERATE(_name, _type, _field, _cmp) \ + RB_GENERATE_INTERNAL(_name, _type, _field, _cmp, NULL) #define RB_INIT(_name, _head) _name##_RB_INIT(_head) #define RB_INSERT(_name, _head, _elm) _name##_RB_INSERT(_head, _elm) @@ -544,20 +525,24 @@ int _rb_check(const struct rb_type *, void *, unsigned long); #define RB_POISON(_name, _elm, _p) _name##_RB_POISON(_elm, _p) #define RB_CHECK(_name, _elm, _p) _name##_RB_CHECK(_elm, _p) -#define RB_FOREACH(_e, _name, _head) \ - for ((_e) = RB_MIN(_name, (_head)); (_e) != NULL; \ +#define RB_FOREACH(_e, _name, _head) \ + for ((_e) = RB_MIN(_name, (_head)); \ + (_e) != NULL; \ (_e) = RB_NEXT(_name, (_e))) -#define RB_FOREACH_SAFE(_e, _name, _head, _n) \ - for ((_e) = RB_MIN(_name, (_head)); \ - (_e) != NULL && ((_n) = RB_NEXT(_name, (_e)), 1); (_e) = (_n)) +#define RB_FOREACH_SAFE(_e, _name, _head, _n) \ + for ((_e) = RB_MIN(_name, (_head)); \ + (_e) != NULL && ((_n) = RB_NEXT(_name, (_e)), 1); \ + (_e) = (_n)) -#define RB_FOREACH_REVERSE(_e, _name, _head) \ - for ((_e) = RB_MAX(_name, (_head)); (_e) != NULL; \ +#define RB_FOREACH_REVERSE(_e, _name, _head) \ + for ((_e) = RB_MAX(_name, (_head)); \ + (_e) != NULL; \ (_e) = RB_PREV(_name, (_e))) -#define RB_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ - for ((_e) = RB_MAX(_name, (_head)); \ - (_e) != NULL && ((_n) = RB_PREV(_name, (_e)), 1); (_e) = (_n)) +#define RB_FOREACH_REVERSE_SAFE(_e, _name, _head, _n) \ + for ((_e) = RB_MAX(_name, (_head)); \ + (_e) != NULL && ((_n) = RB_PREV(_name, (_e)), 1); \ + (_e) = (_n)) -#endif /* _SYS_TREE_H_ */ +#endif /* _SYS_TREE_H_ */ From 145b205177ab47860a78b68329dd4b0ac0d19036 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 18:41:30 -0300 Subject: [PATCH 09/75] lib: fix corrupted RB trees Commit 8f942af90 introduced a bug while silencing a clang warning. Silence the warning in a different way to fix our red-black tree implementation. Fixes #841. Signed-off-by: Renato Westphal --- lib/openbsd-tree.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/lib/openbsd-tree.c b/lib/openbsd-tree.c index 7e753554c9..d171e14d25 100644 --- a/lib/openbsd-tree.c +++ b/lib/openbsd-tree.c @@ -222,12 +222,8 @@ rbe_remove_color(const struct rb_type *t, struct rbt_tree *rbt, { struct rb_entry *tmp; - /* Silence clang possible NULL deference warning. */ - if (parent == NULL) - return; - while ((rbe == NULL || RBE_COLOR(rbe) == RB_BLACK) && - rbe != RBH_ROOT(rbt)) { + rbe != RBH_ROOT(rbt) && parent) { if (RBE_LEFT(parent) == rbe) { tmp = RBE_RIGHT(parent); if (RBE_COLOR(tmp) == RB_RED) { From 9b86009a38e127c4797aa7818537d4577ed9bf6a Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 25 Jul 2017 13:55:48 -0300 Subject: [PATCH 10/75] bgpd/eigrpd: fix crashes found by the CLI fuzzer Fixes the following crashes: * bgpd aborted: vtysh -c "show ip bgp l2vpn evpn all 1.1.1.1 json" * bgpd aborted: vtysh -c "show ip bgp l2vpn evpn all 1.1.1.1" * bgpd aborted: vtysh -c "show ip bgp l2vpn evpn all 1.1.1.1/32 json" * bgpd aborted: vtysh -c "show ip bgp l2vpn evpn all 1.1.1.1/32" * bgpd aborted: vtysh -c "show bgp l2vpn evpn all 1.1.1.1 json" * bgpd aborted: vtysh -c "show bgp l2vpn evpn all 1.1.1.1" * bgpd aborted: vtysh -c "show bgp l2vpn evpn all 1.1.1.1/32 json" * bgpd aborted: vtysh -c "show bgp l2vpn evpn all 1.1.1.1/32" * bgpd aborted: vtysh -c "show bgp ipv4 vpn rd 1:1 1.1.1.1/32 json" * bgpd aborted: vtysh -c "show bgp ipv4 vpn rd 1:1 1.1.1.1/32" * bgpd aborted: vtysh -c "show bgp ipv4 vpn rd 1:1 2001:db8::1/128 json" * bgpd aborted: vtysh -c "show bgp ipv4 vpn rd 1:1 2001:db8::1/128" * bgpd aborted: vtysh -c "show bgp ipv6 vpn rd 1:1 1.1.1.1/32 json" * bgpd aborted: vtysh -c "show bgp ipv6 vpn rd 1:1 1.1.1.1/32" * bgpd aborted: vtysh -c "show bgp ipv6 vpn rd 1:1 2001:db8::1/128 json" * bgpd aborted: vtysh -c "show bgp ipv6 vpn rd 1:1 2001:db8::1/128" * bgpd aborted: vtysh -c "show vnc responses 1.1.1.1/32" * bgpd aborted: vtysh -c "show vnc responses 2001:db8::1/128" * bgpd aborted: vtysh -c "show vnc responses 11:11:11:11:11:11" * bgpd aborted: vtysh -c "show vnc responses" * eigrpd aborted: vtysh -c "configure terminal" -c "no router eigrp 65535" Signed-off-by: Renato Westphal --- bgpd/bgp_route.c | 8 +++++++- bgpd/rfapi/rfapi_rib.c | 10 +++++++++- eigrpd/eigrp_vty.c | 5 +++++ 3 files changed, 21 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 38ad7a6e0a..7cdc839618 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8617,8 +8617,14 @@ static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str, int prefix_check, enum bgp_path_type pathtype, u_char use_json) { - if (!bgp) + if (!bgp) { bgp = bgp_get_default(); + if (!bgp) { + if (!use_json) + vty_out(vty, "No BGP process is configured\n"); + return CMD_WARNING; + } + } /* labeled-unicast routes live in the unicast table */ if (safi == SAFI_LABELED_UNICAST) diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index a414df1ab4..791eb4c916 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -2236,9 +2236,12 @@ void rfapiRibShowResponsesSummary(void *stream) struct rfapi_descriptor *rfd; struct listnode *node; - if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; + if (!bgp) { + fp(out, "Unable to find default BGP instance\n"); + return; + } fp(out, "%-24s ", "Responses: (Prefixes)"); fp(out, "%-8s %-8u ", "Active:", bgp->rfapi->rib_prefix_count_total); @@ -2388,6 +2391,11 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match, if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; + if (!bgp) { + fp(out, "Unable to find default BGP instance\n"); + return; + } + /* * loop over NVEs */ diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index d416183f52..746db2abe9 100644 --- a/eigrpd/eigrp_vty.c +++ b/eigrpd/eigrp_vty.c @@ -237,6 +237,11 @@ DEFUN (no_router_eigrp, struct eigrp *eigrp; eigrp = eigrp_lookup(); + if (eigrp == NULL) { + vty_out(vty, " EIGRP Routing Process not enabled\n"); + return CMD_SUCCESS; + } + if (eigrp->AS != atoi(argv[3]->arg)) { vty_out(vty, "%% Attempting to deconfigure non-existent AS\n"); return CMD_WARNING_CONFIG_FAILED; From ba9d46ff14a53bb5494ceea6d2fce84ec7c32ce0 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Tue, 25 Jul 2017 12:07:07 -0700 Subject: [PATCH 11/75] zebra: debug cleanup Signed-off-by: Daniel Walton --- zebra/debug.c | 135 ++++++++++++++++++++++++-------------------------- 1 file changed, 64 insertions(+), 71 deletions(-) diff --git a/zebra/debug.c b/zebra/debug.c index dfee6b74c0..6aedea1e39 100644 --- a/zebra/debug.c +++ b/zebra/debug.c @@ -71,10 +71,10 @@ DEFUN (show_debugging_zebra, " Zebra kernel netlink message dumps (recv) are on\n"); /* Check here using flags as the 'macro' does an OR */ - if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) - vty_out(vty, " Zebra RIB debugging is on\n"); if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED)) vty_out(vty, " Zebra RIB detailed debugging is on\n"); + else if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) + vty_out(vty, " Zebra RIB debugging is on\n"); if (IS_ZEBRA_DEBUG_FPM) vty_out(vty, " Zebra FPM debugging is on\n"); @@ -145,17 +145,16 @@ DEFUN (debug_zebra_packet, if (argv_find(argv, argc, "send", &idx)) SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); - idx = 0; - if (argv_find(argv, argc, "recv", &idx)) + else if (argv_find(argv, argc, "recv", &idx)) SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); - idx = 0; - if (argv_find(argv, argc, "detail", &idx)) - SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL); - - if (!(zebra_debug_packet & ZEBRA_DEBUG_SEND & ZEBRA_DEBUG_RECV)) { + else { SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); } + + if (argv_find(argv, argc, "detail", &idx)) + SET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_DETAIL); + return CMD_SUCCESS; } @@ -167,6 +166,13 @@ DEFUN (debug_zebra_kernel, "Debug option set for zebra between kernel interface\n") { SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL); + + if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) + UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); + + if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) + UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); + return CMD_SUCCESS; } @@ -181,34 +187,41 @@ DEFUN (debug_zebra_kernel_msgdump, "Dump raw netlink messages sent\n") { int idx = 0; - if (argc == 4 || argv_find(argv, argc, "recv", &idx)) + + if (argv_find(argv, argc, "recv", &idx)) { SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); - if (argc == 4 || argv_find(argv, argc, "send", &idx)) + + if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) + UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); + + } else if (argv_find(argv, argc, "send", &idx)) { SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); + if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) + UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); + + } else { + SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); + SET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); + } + return CMD_SUCCESS; } DEFUN (debug_zebra_rib, debug_zebra_rib_cmd, - "debug zebra rib", - DEBUG_STR - "Zebra configuration\n" - "Debug RIB events\n") -{ - SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB); - return CMD_SUCCESS; -} - -DEFUN (debug_zebra_rib_detailed, - debug_zebra_rib_detailed_cmd, - "debug zebra rib detailed", + "debug zebra rib [detailed]", DEBUG_STR "Zebra configuration\n" "Debug RIB events\n" "Detailed debugs\n") { - SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED); + int idx = 0; + SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB); + + if (argv_find(argv, argc, "detailed", &idx)) + SET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED); + return CMD_SUCCESS; } @@ -273,19 +286,16 @@ DEFUN (no_debug_zebra_vxlan, DEFUN (no_debug_zebra_packet, no_debug_zebra_packet_cmd, - "no debug zebra packet []", + "no debug zebra packet [] [detail]", NO_STR DEBUG_STR "Zebra configuration\n" "Debug option set for zebra packet\n" "Debug option set for receive packet\n" - "Debug option set for send packet\n") + "Debug option set for send packet\n" + "Debug option set for detailed info\n") { - int idx = 0; - if (argc == 4 || argv_find(argv, argc, "send", &idx)) - UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_SEND); - if (argc == 4 || argv_find(argv, argc, "recv", &idx)) - UNSET_FLAG(zebra_debug_packet, ZEBRA_DEBUG_RECV); + zebra_debug_packet = 0; return CMD_SUCCESS; } @@ -297,7 +307,7 @@ DEFUN (no_debug_zebra_kernel, "Zebra configuration\n" "Debug option set for zebra between kernel interface\n") { - UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL); + zebra_debug_kernel = 0; return CMD_SUCCESS; } @@ -312,37 +322,20 @@ DEFUN (no_debug_zebra_kernel_msgdump, "Dump raw netlink messages received\n" "Dump raw netlink messages sent\n") { - int idx = 0; - if (argc == 5 || argv_find(argv, argc, "recv", &idx)) - UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV); - if (argc == 5 || argv_find(argv, argc, "send", &idx)) - UNSET_FLAG(zebra_debug_kernel, ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND); - + zebra_debug_kernel = 0; return CMD_SUCCESS; } DEFUN (no_debug_zebra_rib, no_debug_zebra_rib_cmd, - "no debug zebra rib", - NO_STR - DEBUG_STR - "Zebra configuration\n" - "Debug zebra RIB\n") -{ - zebra_debug_rib = 0; - return CMD_SUCCESS; -} - -DEFUN (no_debug_zebra_rib_detailed, - no_debug_zebra_rib_detailed_cmd, - "no debug zebra rib detailed", + "no debug zebra rib [detailed]", NO_STR DEBUG_STR "Zebra configuration\n" "Debug zebra RIB\n" "Detailed debugs\n") { - UNSET_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED); + zebra_debug_rib = 0; return CMD_SUCCESS; } @@ -385,27 +378,31 @@ static int config_write_debug(struct vty *vty) write++; } } + if (IS_ZEBRA_DEBUG_KERNEL) { - vty_out(vty, "debug zebra kernel\n"); - write++; - } - if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) { - vty_out(vty, "debug zebra kernel msgdump recv\n"); - write++; - } - if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) { - vty_out(vty, "debug zebra kernel msgdump send\n"); - write++; - } - /* Check here using flags as the 'macro' does an OR */ - if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) { - vty_out(vty, "debug zebra rib\n"); - write++; + if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND && IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) { + vty_out(vty, "debug zebra kernel msgdump\n"); + write++; + } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_RECV) { + vty_out(vty, "debug zebra kernel msgdump recv\n"); + write++; + } else if (IS_ZEBRA_DEBUG_KERNEL_MSGDUMP_SEND) { + vty_out(vty, "debug zebra kernel msgdump send\n"); + write++; + } else { + vty_out(vty, "debug zebra kernel\n"); + write++; + } } + if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB_DETAILED)) { vty_out(vty, "debug zebra rib detailed\n"); write++; + } else if (CHECK_FLAG(zebra_debug_rib, ZEBRA_DEBUG_RIB)) { + vty_out(vty, "debug zebra rib\n"); + write++; } + if (IS_ZEBRA_DEBUG_FPM) { vty_out(vty, "debug zebra fpm\n"); write++; @@ -447,7 +444,6 @@ void zebra_debug_init(void) install_element(ENABLE_NODE, &debug_zebra_kernel_cmd); install_element(ENABLE_NODE, &debug_zebra_kernel_msgdump_cmd); install_element(ENABLE_NODE, &debug_zebra_rib_cmd); - install_element(ENABLE_NODE, &debug_zebra_rib_detailed_cmd); install_element(ENABLE_NODE, &debug_zebra_fpm_cmd); install_element(ENABLE_NODE, &no_debug_zebra_events_cmd); install_element(ENABLE_NODE, &no_debug_zebra_nht_cmd); @@ -457,7 +453,6 @@ void zebra_debug_init(void) install_element(ENABLE_NODE, &no_debug_zebra_kernel_cmd); install_element(ENABLE_NODE, &no_debug_zebra_kernel_msgdump_cmd); install_element(ENABLE_NODE, &no_debug_zebra_rib_cmd); - install_element(ENABLE_NODE, &no_debug_zebra_rib_detailed_cmd); install_element(ENABLE_NODE, &no_debug_zebra_fpm_cmd); install_element(CONFIG_NODE, &debug_zebra_events_cmd); @@ -468,7 +463,6 @@ void zebra_debug_init(void) install_element(CONFIG_NODE, &debug_zebra_kernel_cmd); install_element(CONFIG_NODE, &debug_zebra_kernel_msgdump_cmd); install_element(CONFIG_NODE, &debug_zebra_rib_cmd); - install_element(CONFIG_NODE, &debug_zebra_rib_detailed_cmd); install_element(CONFIG_NODE, &debug_zebra_fpm_cmd); install_element(CONFIG_NODE, &no_debug_zebra_events_cmd); install_element(CONFIG_NODE, &no_debug_zebra_nht_cmd); @@ -478,6 +472,5 @@ void zebra_debug_init(void) install_element(CONFIG_NODE, &no_debug_zebra_kernel_cmd); install_element(CONFIG_NODE, &no_debug_zebra_kernel_msgdump_cmd); install_element(CONFIG_NODE, &no_debug_zebra_rib_cmd); - install_element(CONFIG_NODE, &no_debug_zebra_rib_detailed_cmd); install_element(CONFIG_NODE, &no_debug_zebra_fpm_cmd); } From 6058ea8cb16ee387585eea6cbb98119c6b7c0cef Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 21 Jul 2017 11:33:38 -0400 Subject: [PATCH 12/75] COMMUNITY.md: update style guide Signed-off-by: Quentin Young --- COMMUNITY.md | 98 ++++++++++++++++++++++++++-------------------------- 1 file changed, 49 insertions(+), 49 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index 8ab6a624ee..dfdcf89a17 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -264,10 +264,52 @@ Portions: Copyright (C) 2016 Your name [optional brief change description] ``` -### Code styling / format +### Code style / format -Coding style standards in FRR vary depending on location. Pre-existing -code uses GNU coding standards. New code may use Linux kernel coding style. +FRR uses Linux kernel style except where noted below. + +To help with compliance, in the project root there is a .clang-format +configuration file which can be used with the `clang-format` tool from the LLVM +project. In the `tools/` directory there is a Python script named `indent.py` +that wraps clang-format and handles some edge cases specific to FRR. If you are +submitting a new file, it is recommended to run that script over the new file +after ensuring that the latest stable release of `clang-format` is in your +PATH. + +**Whitespace changes in untouched parts of the code are not acceptable in +patches that change actual code.** To change/fix formatting issues, please +create a separate patch that only does formatting changes and nothing else. + +Kernel and BSD styles are documented externally: + +* [https://www.kernel.org/doc/html/latest/process/coding-style.html](https://www.kernel.org/doc/html/latest/process/coding-style.html) +* [http://man.openbsd.org/style](http://man.openbsd.org/style) + +For GNU coding style, use `indent` with the following invocation: + +``` +indent -nut -nfc1 file_for_submission.c +``` + +#### Exceptions + +FRR project code comes from a variety of sources, so there are some stylistic +exceptions in place. Here they are, by branch. + +**For `master`:** + +BSD coding style applies to: + +* ldpd/ + +`babeld` uses, approximately, the following style: + +* K&R style braces +* Indents are 4 spaces +* Function return types are on their own line + + +**For `stable/3.0` and `stable/2.0`:** GNU coding style apply to the following parts: @@ -281,57 +323,15 @@ GNU coding style apply to the following parts: * ripngd/ * vtysh/ -Linux kernel coding style applies to: - -* nhrpd/ -* watchfrr/ -* pimd/ -* lib/{checksum,hook,imsg-buffer,imsg,libfrr,md5,module,monotime,queue}.[ch] - BSD coding style applies to: * ldpd/ -**Whitespace changes in untouched parts of the code are not acceptable in -patches that change actual code.** To change/fix formatting issues, please -create a separate patch that only does formatting changes and nothing else. - -It is acceptable to rewrap entire files to Linux kernel style, but this -**MUST** come as a separate patch that does nothing other than this -reformatting. - - -#### GNU style - -For GNU coding style, Indentation follows the result of invoking GNU indent: - -``` -indent -nut -nfc1 file_for_submission.c -``` - -Originally, tabs were used instead of spaces, with tabs are every 8 columns. -However, tab interoperability issues mean space characters are now preferred for -new changes. We generally only clean up whitespace when code is unmaintainable -due to whitespace issues, to minimise merging conflicts. - - -#### Linux kernel & BSD style - -These styles are documented externally: - -* [https://www.kernel.org/doc/Documentation/CodingStyle](https://www.kernel.org/doc/Documentation/CodingStyle). -* [http://man.openbsd.org/style](http://man.openbsd.org/style) - -They are relatively similar but differ in details. - -pimd deviates from Linux kernel style in using 2 spaces for indentation, with -Tabs replacing 8 spaces, as well as adding a line break between `}` and `else`. -It is acceptable to convert indentation in pimd/ to Linux kernel style, but -please convert an entire file at a time. (Rationale: apart from 2-space -indentation, the styles are sufficiently close to not upset when mixed.) - -Unlike GNU style, these styles use tabs, not spaces. +#### Policy +The above standards relate to code formatting. For other stylistic choices e.g. +use of `typedef`, variable naming, etc. refer to the Linux kernel style +documentation. ### Compile-Time conditional code From c545559d4a9b4edbdc1bad12f7cbffd332e22a12 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 21 Jul 2017 12:12:52 -0400 Subject: [PATCH 13/75] COMMUNITY.md: s/PROJECT/FRRouting Also: * Make headers consistently capitalized * Some extra backticks where needed Signed-off-by: Quentin Young --- COMMUNITY.md | 105 ++++++++++++++++++++++++++------------------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index dfdcf89a17..6fd82c0541 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -1,4 +1,4 @@ -# Developing for PROJECT (DRAFT) +# Developing for FRRouting [TOC] @@ -14,8 +14,8 @@ it's the document that needs to be updated, not reality. ## Git Structure -The master Git for PROJECT resides on Github at -[https://github.com/PROJECT/XXX](https://github.com/PROJECT/XXX) +The master Git for FRRouting resides on Github at +[https://github.com/frrouting/frr](https://github.com/FRRouting/XXX) ![git branches continually merging to the left from 3 lanes; float-right](doc/git_branches.svg "git branch mechanics") @@ -38,23 +38,24 @@ is still here, this document obviously wasn't updated. ## Programming language, Tools and Libraries -The core of PROJECT is written in C (gcc or clang supported). A few -non-essential scripts are implemented in Perl and Python. PROJECT requires -the following tools to build distribution packages: automake, autoconf, -texinfo, libtool and gawk and various libraries (i.e. libpam and libjson-c). +The core of FRRouting is written in C (gcc or clang supported) and makes use of +GNU compiler extensions. A few non-essential scripts are implemented in Perl +and Python. FRRouting requires the following tools to build distribution +packages: automake, autoconf, texinfo, libtool and gawk and various libraries +(i.e. libpam and libjson-c). If your contribution requires a new library or other tool, then please -highlight this in your description of the change. Also make sure it’s -supported by all PROJECT platform OSes or provide a way to build without the -library (potentially without the new feature) on the other platforms. +highlight this in your description of the change. Also make sure it’s supported +by all FRRouting platform OSes or provide a way to build without the library +(potentially without the new feature) on the other platforms. Documentation should be written in Tex (.texi) or Markdown (.md) format with -preference on Markdown. +a preference for Markdown. ## Before Submitting your changes -* Format code (see [Code Styling requirements](#code-styling-requirements)) +* Format code (see [Code style requirements](#code-styling-requirements)) * Verify and acknowledge license (see [License for contributions](#license-for-contributions)) * Test building with various configurations: * `buildtest.sh` @@ -77,13 +78,13 @@ for the release notes. ### License for contributions -PROJECT is under a “GPLv2 or later” license. Any code submitted must be +FRRouting is under a “GPLv2 or later” license. Any code submitted must be released under the same license (preferred) or any license which allows redistribution under this GPLv2 license (eg MIT License). ### Signed-off required -Submissions to PROJECT require a “Signed-off” in the patch or git commit. +Submissions to FRRouting require a “Signed-off” in the patch or git commit. We follow the same standard as the Linux Kernel Development. > Developer's Certificate of Origin 1.1 @@ -143,7 +144,7 @@ the question of a maintainer. Preferred submission of code is by using a Github Pull Request against the Develop branch. Code submitted by Pull Request will have an email generated to -the PROJECT-devel mailing list for review and the submission will be +the FRRouting-devel mailing list for review and the submission will be automatically tested by one or more CI systems. Only after this test succeeds (and the submission is based on the head of the develop branch), then it will be automatically merged into the develop branch. In case of failed tests, it is @@ -154,9 +155,9 @@ Further (manual) code review and discussion happens after the merge into the develop branch. -### Code submission - Mailing Patch to PROJECT-Devel list +### Code submission - Mailing Patch to FRRouting-Devel list -As an alternative submission, a patch can be mailed to the PROJECT-Devel +As an alternative submission, a patch can be mailed to the FRRouting-Devel mailing list. Preferred way to send the patch is using git send-mail. Patches received on the mailing list will be picked up by Patchwork and tested against the latest develop branch. After a further ACK by someone on the mailing list, @@ -194,9 +195,9 @@ and will allow your changes to merge faster less than 2 hrs of the submission. If you don’t get the email, then check status on the github pull request (if submitted by pull request) or on Patchwork at - [https://patchwork.PROJECT.org](https://patchwork.PROJECT.org) (if + [https://patchwork.FRRouting.org](https://patchwork.PROJECT.org) (if submitted as patch to mailing list). - * Please notify PROJECT-Devel mailing list if you think something doesn’t + * Please notify FRRouting-Devel mailing list if you think something doesn’t work * If the tests failed: * In general, expect the community to ignore the submission until the tests @@ -206,23 +207,23 @@ and will allow your changes to merge faster changes broke or changed them. * It also includes fixing distribution packages for the failing platforms (ie if new libraries are required) - * Feel free to ask for help on PROJECT-Devel list + * Feel free to ask for help on FRRouting-Devel list * Go back to the submission process and repeat until the tests pass. * If the tests pass: * If the changes are done as a pull request, then they should be automatically merged to the develop branch. * Changes sent to mailing list require a manual ACK to be merged and should be merged within 2 weeks. If you don’t see the merge or any - reason/discussion on PROJECT-Devel, then please ask. + reason/discussion on FRRouting-Devel, then please ask. * Watch out for questions on the mailing list. At this time there will be a manual code review and further (longer) tests by various community members. * Your submission is done once it is merged to the master branch. (which should happen every few weeks from the develop branch) -## Code Styling requirements +## Code style requirements -### File header required for new files added +### Source file header New files need to have a Copyright header (see [License for contributions](#license-for-contributions) above) added to the file. Preferred @@ -251,7 +252,7 @@ form of the header is as follows: #include ``` -### Adding Copyright claims to already existing file +### Adding copyright claims to existing files When adding copyright claims for modifications to an existing file, please preface the claim with "Portions: " on a line before it and indent the @@ -264,7 +265,7 @@ Portions: Copyright (C) 2016 Your name [optional brief change description] ``` -### Code style / format +### Code formatting FRR uses Linux kernel style except where noted below. @@ -294,13 +295,13 @@ indent -nut -nfc1 file_for_submission.c #### Exceptions FRR project code comes from a variety of sources, so there are some stylistic -exceptions in place. Here they are, by branch. +exceptions in place. They are organized here by branch. **For `master`:** BSD coding style applies to: -* ldpd/ +* `ldpd/` `babeld` uses, approximately, the following style: @@ -313,46 +314,46 @@ BSD coding style applies to: GNU coding style apply to the following parts: -* lib/ -* zebra/ -* bgpd/ -* ospfd/ -* ospf6d/ -* isisd/ -* ripd/ -* ripngd/ -* vtysh/ +* `lib/` +* `zebra/` +* `bgpd/` +* `ospfd/` +* `ospf6d/` +* `isisd/` +* `ripd/` +* `ripngd/` +* `vtysh/` BSD coding style applies to: -* ldpd/ +* `ldpd/` #### Policy -The above standards relate to code formatting. For other stylistic choices e.g. -use of `typedef`, variable naming, etc. refer to the Linux kernel style +The above standards relate to code formatting. For other stylistic choices, +such as use of `typedef`, variable naming, etc. refer to the Linux kernel style documentation. -### Compile-Time conditional code +### Compile-time conditional code -Many users access PROJECT via binary packages from 3rd party sources; +Many users access FRR via binary packages from 3rd party sources; compile-time code puts inclusion/exclusion in the hands of the package maintainer. Please think very carefully before making code conditional at compile time, as it increases regression testing, maintenance burdens, and user -confusion. In particular, please avoid gratuitous --enable-… switches to the -configure script - typically code should be good enough to be in PROJECT, or it -shouldn’t be there at all. +confusion. In particular, please avoid gratuitous `--enable-…` switches to the +configure script - in general, code should be of high quality and in working +condition, or it shouldn’t be in FRR at all. When code must be compile-time conditional, try have the compiler make it -conditional rather than the C pre-processor - so that it will still be checked -by the compiler, even if disabled. I.e. this: +conditional rather than the C pre-processor so that it will still be checked by +the compiler, even if disabled. For example, ``` if (SOME_SYMBOL) frobnicate(); ``` -rather than +is preferred to ``` #ifdef SOME_SYMBOL @@ -363,18 +364,18 @@ frobnicate (); Note that the former approach requires ensuring that `SOME_SYMBOL` will be defined (watch your `AC_DEFINE`s). -### Debug-Guards in code +### Debug-guards in code -Debugs are an important methodology to allow developers to fix issues +Debugging statements are an important methodology to allow developers to fix issues found in the code after it has been released. The caveat here is that the developer must remember that people will be using the code at scale and in ways that can be unexpected for the original implementor. -As such debugs MUST be guarded in such a way that they can be turned off. -This PROJECT has the ability to turn on/off debugs from the CLI and it is +As such debugs **MUST** be guarded in such a way that they can be turned off. +FRR has the ability to turn on/off debugs from the CLI and it is expected that the developer will use this convention to allow control of their debugs. -### CLI-Changes +### CLI changes CLI's are a complicated ugly beast. Additions or changes to the CLI should use a DEFUN to encapsulate one setting as much as is possible. From b0ff7312a46570dd2d237fda78c76485bb895221 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Fri, 21 Jul 2017 12:50:59 -0400 Subject: [PATCH 14/75] COMMUNITY.md: miscellaneous documentation Also: - Add documentation on mailing list - Update mentions of unit tests - Update process description Signed-off-by: Quentin Young --- COMMUNITY.md | 163 +++++++++++++++++++++++++++------------------------ 1 file changed, 85 insertions(+), 78 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index 6fd82c0541..8a02d13cc6 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -1,4 +1,7 @@ -# Developing for FRRouting +Developing for FRRouting +========================= + +## Table of Contents [TOC] @@ -15,7 +18,7 @@ it's the document that needs to be updated, not reality. ## Git Structure The master Git for FRRouting resides on Github at -[https://github.com/frrouting/frr](https://github.com/FRRouting/XXX) +[https://github.com/frrouting/frr](https://github.com/FRRouting/frr) ![git branches continually merging to the left from 3 lanes; float-right](doc/git_branches.svg "git branch mechanics") @@ -53,17 +56,18 @@ Documentation should be written in Tex (.texi) or Markdown (.md) format with a preference for Markdown. -## Before Submitting your changes +## Mailing lists + +Italicized lists are private. + +| Topic | List | +|--------------------------------|------------------------------| +| Development | dev@lists.frrouting.org | +| Users & Operators | frog@lists.frrouting.org | +| Announcements | announce@lists.frrouting.org | +| _Security_ | security@lists.frrouting.org | +| _Technical Steering Committee_ | tsc@lists.frrouting.org | -* Format code (see [Code style requirements](#code-styling-requirements)) -* Verify and acknowledge license (see [License for contributions](#license-for-contributions)) -* Test building with various configurations: - * `buildtest.sh` -* Verify building source distribution: - * `make dist` (and try rebuilding from the resulting tar file) -* Run DejaGNU unit tests: - * `make test` -* Document Regression Runs and plans for continued maintenance of the feature ### Changelog @@ -76,16 +80,45 @@ for the release notes. ## Submitting Patches and Enhancements +### Pre-submission Checklist + +* Format code (see [Coding style requirements](#coding-style-requirements)) +* Verify and acknowledge license (see [License for contributions](#license-for-contributions)) +* Ensure you have properly signed off (see [Signing Off](#signing-off)) +* Test building with various configurations: + * `buildtest.sh` +* Verify building source distribution: + * `make dist` (and try rebuilding from the resulting tar file) +* Run unit tests: + * `make test` +* Document Regression Runs and plans for continued maintenance of the feature + ### License for contributions FRRouting is under a “GPLv2 or later” license. Any code submitted must be released under the same license (preferred) or any license which allows redistribution under this GPLv2 license (eg MIT License). -### Signed-off required +### Signing Off -Submissions to FRRouting require a “Signed-off” in the patch or git commit. -We follow the same standard as the Linux Kernel Development. +Code submitted to FRRouting must be signed off. We have the same requirements +for using the signed-off-by process as the Linux kernel. In short, you must +include a signed-off-by tag in every patch. + +`Signed-off-by:` this is a developer's certification that he or she has the +right to submit the patch for inclusion into the project. It is an agreement to +the Developer's Certificate of Origin (below). Code without a proper signoff +cannot and will not be merged. + +If you are unfamiliar with this process, you should read the [official policy +at kernel.org](http://www.kernel.org/doc/Documentation/SubmittingPatches) and +you might find this article about [participating in the Linux community on the +Linux Foundation +website](http://www.linuxfoundation.org/content/how-participate-linux-community-0) +to be a helpful resource. + +In short, when you sign off on a commit, you assert your agreement to all of +the following: > Developer's Certificate of Origin 1.1 > @@ -113,79 +146,52 @@ We follow the same standard as the Linux Kernel Development. > maintained indefinitely and may be redistributed consistent with > this project or the open source license(s) involved. -#### Using this Process - -We have the same requirements for using the signed-off-by process as the Linux -kernel. In short, you need to include a signed-off-by tag in every patch: - -* `Signed-off-by:` this is a developer's certification that he or she has the -right to submit the patch for inclusion into the project. It is an agreement to -the Developer's Certificate of Origin (above). Code without a proper signoff -cannot be merged into the mainline. - -Please make sure to have a `Signed-off-by:` in each commit/patch or the patches -will be rejected until this is added. - -If you are unfamiliar with this process, you should read the [official policy -at kernel.org](http://www.kernel.org/doc/Documentation/SubmittingPatches) and -you might find this article about [participating in the Linux community on the -Linux Foundation -website](http://www.linuxfoundation.org/content/how-participate-linux-community-0) -to be a helpful resource. - -### Code submission - What do I submit my changes against? +### What do I submit my changes against? We've documented where we would like to have the different fixes applied at https://github.com/FRRouting/frr/wiki/Where-Do-I-create-a-Pull-Request-against%3F If you are unsure where your submission goes, look at that document or ask -the question of a maintainer. +a project maintainer. -### Code submission - Github Pull Request (Strongly Preferred) +### Github pull requests -Preferred submission of code is by using a Github Pull Request against the -Develop branch. Code submitted by Pull Request will have an email generated to -the FRRouting-devel mailing list for review and the submission will be -automatically tested by one or more CI systems. Only after this test succeeds -(and the submission is based on the head of the develop branch), then it will -be automatically merged into the develop branch. In case of failed tests, it is -up to the submitter to either amend the request with further commits or close, -fix and create a new pull request. +The preferred method of submitting changes is a Github pull request. Code +submitted by pull request will have an email generated to the FRRouting-devel +mailing list for review and the submission will be automatically tested by one +or more CI systems. Only after this test succeeds it will be automatically merged into +the develop branch. In case of failed tests, it is up to the submitter to +either amend the request with further commits or close, fix and create a new +pull request. Further (manual) code review and discussion happens after the merge into the develop branch. -### Code submission - Mailing Patch to FRRouting-Devel list +### Patch submission via mailing list -As an alternative submission, a patch can be mailed to the FRRouting-Devel -mailing list. Preferred way to send the patch is using git send-mail. Patches -received on the mailing list will be picked up by Patchwork and tested against -the latest develop branch. After a further ACK by someone on the mailing list, -the patch is then merged into the develop branch. - -Further (manual) code review and discussion happens after the merge into the -develop branch. - -#### Sending patch to mailing list +As an alternative submission method, a patch can be mailed to the development +mailing list. Patches received on the mailing list will be picked up by +Patchwork and tested against the latest development branch. The recommended way to send the patch (or series of NN patches) to the list is -by using ‘git send-email’ as follows (assuming they are the most recent NN +by using `git send-email` as follows (assuming they are the N most recent commit(s) in your git history: ``` -git send-email -NN --annotate --to=XXX-Devel@XXX.org +git send-email -NN --annotate --to=dev@lists.frrouting.org ``` If your commits do not already contain a `Signed-off-by` line, then use the -following version to add it (after making sure to be able to agree to the -Developer Certificate of Origin as outlined above): +following command to add it (after making sure you agree to the Developer +Certificate of Origin as outlined above): ``` -git send-email -NN --annotate --signoff --to=XXX-Devel@XXX.org +git send-email -NN --annotate --signoff --to=dev@lists.frrouting.org ``` -Submitting multi-commit patches as a Github Pull Request is strongly encouraged -and will allow your changes to merge faster +Submitting multi-commit patches as a Github pull request is **strongly +encouraged** and increases the probability of your patch getting reviewed and +merged in a timely manner. ## After submitting your changes @@ -195,33 +201,32 @@ and will allow your changes to merge faster less than 2 hrs of the submission. If you don’t get the email, then check status on the github pull request (if submitted by pull request) or on Patchwork at - [https://patchwork.FRRouting.org](https://patchwork.PROJECT.org) (if + [https://patchwork.frrouting.org](https://patchwork.frrouting.org) (if submitted as patch to mailing list). - * Please notify FRRouting-Devel mailing list if you think something doesn’t + * Please notify development mailing list if you think something doesn’t work * If the tests failed: * In general, expect the community to ignore the submission until the tests pass. * It is up to you to fix and resubmit. - * This includes fixing existing dejagnu (“make test”) tests if your + * This includes fixing existing unit (“make test”) tests if your changes broke or changed them. * It also includes fixing distribution packages for the failing platforms (ie if new libraries are required) - * Feel free to ask for help on FRRouting-Devel list + * Feel free to ask for help on development list * Go back to the submission process and repeat until the tests pass. * If the tests pass: - * If the changes are done as a pull request, then they should be - automatically merged to the develop branch. - * Changes sent to mailing list require a manual ACK to be merged and should - be merged within 2 weeks. If you don’t see the merge or any - reason/discussion on FRRouting-Devel, then please ask. + * Wait for reviewers. Someone will review your code or be assigned to + review your code. + * Respond to any comments or concerns the reviewer has. + * After all comments and concerns are addressed, expect your patch to be + merged. * Watch out for questions on the mailing list. At this time there will be a manual code review and further (longer) tests by various community members. -* Your submission is done once it is merged to the master branch. (which should - happen every few weeks from the develop branch) +* Your submission is done once it is merged to the master branch. -## Code style requirements +## Coding style requirements ### Source file header @@ -267,9 +272,10 @@ Portions: ### Code formatting -FRR uses Linux kernel style except where noted below. +FRR uses Linux kernel style except where noted below. Code which does not +comply with these style guidelines will not be accepted. -To help with compliance, in the project root there is a .clang-format +To assist with compliance, in the project root there is a .clang-format configuration file which can be used with the `clang-format` tool from the LLVM project. In the `tools/` directory there is a Python script named `indent.py` that wraps clang-format and handles some edge cases specific to FRR. If you are @@ -281,6 +287,7 @@ PATH. patches that change actual code.** To change/fix formatting issues, please create a separate patch that only does formatting changes and nothing else. +#### Style documentation Kernel and BSD styles are documented externally: * [https://www.kernel.org/doc/html/latest/process/coding-style.html](https://www.kernel.org/doc/html/latest/process/coding-style.html) From a03e352668b36772ec0a3049fd17667f7266c397 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 25 Jul 2017 15:34:41 -0400 Subject: [PATCH 15/75] COMMUNITY.md: document documentation Add guidelines for documentation to COMMUNITY.md Signed-off-by: Quentin Young --- COMMUNITY.md | 65 ++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 60 insertions(+), 5 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index 8a02d13cc6..b9f152fa12 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -226,7 +226,7 @@ merged in a timely manner. * Your submission is done once it is merged to the master branch. -## Coding style requirements +## Developer's Guidelines ### Source file header @@ -335,11 +335,61 @@ BSD coding style applies to: * `ldpd/` -#### Policy -The above standards relate to code formatting. For other stylistic choices, -such as use of `typedef`, variable naming, etc. refer to the Linux kernel style -documentation. +### Documentation + +FRRouting is a large and complex software project developed by many different +people over a long period of time. Without adequate documentation, it can be +exceedingly difficult to understand code segments, APIs and other interfaces. +In the interest of keeping the project healthy and maintainable, you should +make every effort to document your code so that other people can understand +what it does without needing to closely read the code itself. + +Some specific guidelines that contributors should follow are: + +* Functions exposed in header files should have descriptive comments above + their signatures in the header file. At a minimum, a function comment should + contain information about the return value, parameters, and a general summary + of the function's purpose. Documentation on parameter values can be omitted + if it is (very) obvious what they are used for. + + Function comments must follow the style for multiline comments laid out in + the kernel style guide. + +Example: + +``` +/* + * Determines whether or not a string is cool. + * + * @param text - the string to check for coolness + * @param is_clccfc - whether capslock is cruise control for cool + * @return 7 if the text is cool, 0 otherwise + */ +int check_coolness(const char *text, bool is_clccfc); +``` + +The Javadoc-style annotations are not required, but you should still strive to +make it equally clear what parameters and return values are used for. + +* Static functions should have descriptive comments in the same form as above + if what they do is not immediately obvious. Use good engineering judgement + when deciding whether a comment is necessary. If you are unsure, document + your code. + +* Global variables, static or not, should have a comment describing their use. + +* **For new code in `lib/`, these guidelines are hard requirements.** + + +If you are contributing code that adds significant user-visible functionality +or introduces a new API, please document it in `doc/`. Markdown and LaTeX are +acceptable formats, although Markdown is currently preferred for new +documentation. This may change in the near future. + +Finally, if you come across some code that is undocumented and feel like going +above and beyond, document it! We absolutely appreciate and accept patches that +document previously undocumented code. ### Compile-time conditional code @@ -421,3 +471,8 @@ That said, compatibility measures can (and should) be removed when either: In all cases, compatibility pieces should be marked with compiler/preprocessor annotations to print warnings at compile time, pointing to the appropriate update path. A `-Werror` build should fail if compatibility bits are used. + +### Miscellaneous + +When in doubt, follow the guidelines in the Linux kernel style guide, or ask on +the development mailing list / public Slack instance. From 4b8ac525ff61438e02b7c50651cb0fd8c6f1978f Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 25 Jul 2017 15:39:05 -0400 Subject: [PATCH 16/75] COMMUNITY.md: minor grammatical fixes Signed-off-by: Quentin Young --- COMMUNITY.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index b9f152fa12..198d23b0b8 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -108,7 +108,7 @@ include a signed-off-by tag in every patch. `Signed-off-by:` this is a developer's certification that he or she has the right to submit the patch for inclusion into the project. It is an agreement to the Developer's Certificate of Origin (below). Code without a proper signoff -cannot and will not be merged. +can not and will not be merged. If you are unfamiliar with this process, you should read the [official policy at kernel.org](http://www.kernel.org/doc/Documentation/SubmittingPatches) and @@ -203,8 +203,8 @@ merged in a timely manner. Patchwork at [https://patchwork.frrouting.org](https://patchwork.frrouting.org) (if submitted as patch to mailing list). - * Please notify development mailing list if you think something doesn’t - work + * Please notify the development mailing list if you think something doesn’t + work. * If the tests failed: * In general, expect the community to ignore the submission until the tests pass. @@ -212,8 +212,8 @@ merged in a timely manner. * This includes fixing existing unit (“make test”) tests if your changes broke or changed them. * It also includes fixing distribution packages for the failing - platforms (ie if new libraries are required) - * Feel free to ask for help on development list + platforms (ie if new libraries are required). + * Feel free to ask for help on the development list. * Go back to the submission process and repeat until the tests pass. * If the tests pass: * Wait for reviewers. Someone will review your code or be assigned to From 651db60ff4f77dda2044cce3638ffbef44021ca0 Mon Sep 17 00:00:00 2001 From: Brian Rak Date: Tue, 25 Jul 2017 15:48:02 -0400 Subject: [PATCH 17/75] redhat: Make the init script flush routes for all associated protocols on stop --- redhat/frr.init | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/redhat/frr.init b/redhat/frr.init index cf01e4c6e3..a62647b258 100755 --- a/redhat/frr.init +++ b/redhat/frr.init @@ -515,6 +515,18 @@ case "$1" in if [ -z "$dmn" -o "$dmn" = "zebra" ]; then echo "Removing all routes made by zebra." ip route flush proto zebra + # At least in CentOS/RHEL 6, iproute2 doesn't know + # about the new protocol names, so we have to flush them + # by number (it also doesn't support rt_protos.d + ip route flush proto 186 + ip route flush proto 187 + ip route flush proto 188 + ip route flush proto 189 + ip route flush proto 190 + ip route flush proto 191 + ip route flush proto 192 + ip route flush proto 193 + ip route flush proto 194 else [ -n "$dmn" ] && eval "${dmn/-/_}=0" start_watchfrr From f1423462b1287177f05e5216eb3449ba0f450590 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 25 Jul 2017 15:53:05 -0400 Subject: [PATCH 18/75] COMMUNITY.md: rewrap paragraphs, update PR section * Wrap paragraphs at 80 lines * Update Github PR section to remove mention of develop branch Signed-off-by: Quentin Young --- COMMUNITY.md | 117 ++++++++++++++++++++++++--------------------------- 1 file changed, 54 insertions(+), 63 deletions(-) diff --git a/COMMUNITY.md b/COMMUNITY.md index 198d23b0b8..bbc5bb6d10 100644 --- a/COMMUNITY.md +++ b/COMMUNITY.md @@ -23,20 +23,20 @@ The master Git for FRRouting resides on Github at ![git branches continually merging to the left from 3 lanes; float-right](doc/git_branches.svg "git branch mechanics") -There is one main branch for development and a release branch for each -major release. +There is one main branch for development and a release branch for each major +release. New contributions are done against the head of the master branch. The CI -systems will pick up the Github Pull Requests or the new patch from -Patchwork, run some basic build and functional tests. +systems will pick up the Github Pull Requests or the new patch from Patchwork, +run some basic build and functional tests. -For each major release (1.0, 1.1 etc) a new release branch is created based -on the master. +For each major release (1.0, 1.1 etc) a new release branch is created based on +the master. -There was an attempt to use a "develop" branch automatically maintained by -the CI system. This is not currently in active use, though the system is -operational. If the "develop" branch is in active use and this paragraph -is still here, this document obviously wasn't updated. +There was an attempt to use a "develop" branch automatically maintained by the +CI system. This is not currently in active use, though the system is +operational. If the "develop" branch is in active use and this paragraph is +still here, this document obviously wasn't updated. ## Programming language, Tools and Libraries @@ -52,8 +52,8 @@ highlight this in your description of the change. Also make sure it’s supporte by all FRRouting platform OSes or provide a way to build without the library (potentially without the new feature) on the other platforms. -Documentation should be written in Tex (.texi) or Markdown (.md) format with -a preference for Markdown. +Documentation should be written in Tex (.texi) or Markdown (.md) format with a +preference for Markdown. ## Mailing lists @@ -150,22 +150,16 @@ the following: We've documented where we would like to have the different fixes applied at https://github.com/FRRouting/frr/wiki/Where-Do-I-create-a-Pull-Request-against%3F -If you are unsure where your submission goes, look at that document or ask -a project maintainer. +If you are unsure where your submission goes, look at that document or ask a +project maintainer. ### Github pull requests The preferred method of submitting changes is a Github pull request. Code -submitted by pull request will have an email generated to the FRRouting-devel -mailing list for review and the submission will be automatically tested by one -or more CI systems. Only after this test succeeds it will be automatically merged into -the develop branch. In case of failed tests, it is up to the submitter to -either amend the request with further commits or close, fix and create a new -pull request. - -Further (manual) code review and discussion happens after the merge into the -develop branch. - +submitted by pull request will be automatically tested by one or more CI +systems. Once the automated tests succeed, other developers will review your +code for quality and correctness. After any concerns are resolved, your code +will be merged into the branch it was submitted against. ### Patch submission via mailing list @@ -393,13 +387,13 @@ document previously undocumented code. ### Compile-time conditional code -Many users access FRR via binary packages from 3rd party sources; -compile-time code puts inclusion/exclusion in the hands of the package -maintainer. Please think very carefully before making code conditional at -compile time, as it increases regression testing, maintenance burdens, and user -confusion. In particular, please avoid gratuitous `--enable-…` switches to the -configure script - in general, code should be of high quality and in working -condition, or it shouldn’t be in FRR at all. +Many users access FRR via binary packages from 3rd party sources; compile-time +code puts inclusion/exclusion in the hands of the package maintainer. Please +think very carefully before making code conditional at compile time, as it +increases regression testing, maintenance burdens, and user confusion. In +particular, please avoid gratuitous `--enable-…` switches to the configure +script - in general, code should be of high quality and in working condition, +or it shouldn’t be in FRR at all. When code must be compile-time conditional, try have the compiler make it conditional rather than the C pre-processor so that it will still be checked by @@ -423,50 +417,47 @@ defined (watch your `AC_DEFINE`s). ### Debug-guards in code -Debugging statements are an important methodology to allow developers to fix issues -found in the code after it has been released. The caveat here is -that the developer must remember that people will be using the code -at scale and in ways that can be unexpected for the original implementor. -As such debugs **MUST** be guarded in such a way that they can be turned off. -FRR has the ability to turn on/off debugs from the CLI and it is -expected that the developer will use this convention to allow control -of their debugs. +Debugging statements are an important methodology to allow developers to fix +issues found in the code after it has been released. The caveat here is that +the developer must remember that people will be using the code at scale and in +ways that can be unexpected for the original implementor. As such debugs +**MUST** be guarded in such a way that they can be turned off. FRR has the +ability to turn on/off debugs from the CLI and it is expected that the +developer will use this convention to allow control of their debugs. ### CLI changes -CLI's are a complicated ugly beast. Additions or changes to the CLI -should use a DEFUN to encapsulate one setting as much as is possible. -Additionally as new DEFUN's are added to the system, documentation -should be provided for the new commands. +CLI's are a complicated ugly beast. Additions or changes to the CLI should use +a DEFUN to encapsulate one setting as much as is possible. Additionally as new +DEFUN's are added to the system, documentation should be provided for the new +commands. ### Backwards Compatibility -As a general principle, changes to CLI and code in the lib/ directory -should be made in a backwards compatible fashion. This means that -changes that are purely stylistic in nature should be avoided, e.g., -renaming an existing macro or library function name without any -functional change. When adding new parameters to common functions, it is -also good to consider if this too should be done in a backward -compatible fashion, e.g., by preserving the old form in addition to +As a general principle, changes to CLI and code in the lib/ directory should be +made in a backwards compatible fashion. This means that changes that are purely +stylistic in nature should be avoided, e.g., renaming an existing macro or +library function name without any functional change. When adding new parameters +to common functions, it is also good to consider if this too should be done in +a backward compatible fashion, e.g., by preserving the old form in addition to adding the new form. -This is not to say that minor or even major functional changes to CLI -and common code should be avoided, but rather that the benefit gained -from a change should be weighed against the added cost/complexity to -existing code. Also, that when making such changes, it is good to -preserve compatibility when possible to do so without introducing -maintenance overhead/cost. It is also important to keep in mind, -existing code includes code that may reside in private repositories (and -is yet to be submitted) or code that has yet to be migrated from Quagga -to FRR. +This is not to say that minor or even major functional changes to CLI and +common code should be avoided, but rather that the benefit gained from a change +should be weighed against the added cost/complexity to existing code. Also, +that when making such changes, it is good to preserve compatibility when +possible to do so without introducing maintenance overhead/cost. It is also +important to keep in mind, existing code includes code that may reside in +private repositories (and is yet to be submitted) or code that has yet to be +migrated from Quagga to FRR. That said, compatibility measures can (and should) be removed when either: -* they become a significant burden, e.g. when data structures change and - the compatibility measure would need a complex adaptation layer or becomes +* they become a significant burden, e.g. when data structures change and the + compatibility measure would need a complex adaptation layer or becomes flat-out impossible -* some measure of time (dependent on the specific case) has passed, so that - the compatibility grace period is considered expired. +* some measure of time (dependent on the specific case) has passed, so that the + compatibility grace period is considered expired. In all cases, compatibility pieces should be marked with compiler/preprocessor annotations to print warnings at compile time, pointing to the appropriate From 1ac79ce8df249480f8b963e64d0e3714b2c8e514 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Tue, 25 Jul 2017 13:24:45 -0700 Subject: [PATCH 19/75] zebra: static route cleanup Signed-off-by: Daniel Walton - The 'reject' keyword was being lost - Hide the "ip route A.B.C.D A.B.C.D" config options since these will be displayed as "ip route A.B.C.D/X" --- zebra/zebra_vty.c | 118 ++++++++++++++++++++++++---------------------- 1 file changed, 61 insertions(+), 57 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 3978664dbe..50fa69d224 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -444,20 +444,20 @@ DEFUN (ip_route_flags, } /* Mask as A.B.C.D format. */ -DEFUN (ip_route_mask, - ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) +DEFUN_HIDDEN (ip_route_mask, + ip_route_mask_cmd, + "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Null interface\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR) { int idx_ipv4 = 2; int idx_ipv4_2 = 3; @@ -475,19 +475,19 @@ DEFUN (ip_route_mask, distance, vrf, NULL); } -DEFUN (ip_route_mask_flags, - ip_route_mask_flags_cmd, - "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) +DEFUN_HIDDEN (ip_route_mask_flags, + ip_route_mask_flags_cmd, + "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "Emit an ICMP unreachable when matched\n" + "Silently discard pkts when matched\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR) { int idx_ipv4 = 2; int idx_ipv4_2 = 3; @@ -562,21 +562,21 @@ DEFUN (no_ip_route_flags, NULL, tag, distance, vrf, NULL); } -DEFUN (no_ip_route_mask, - no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) +DEFUN_HIDDEN (no_ip_route_mask, + no_ip_route_mask_cmd, + "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + NO_STR + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Null interface\n" + "Tag of this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR) { int idx_ipv4 = 3; int idx_ipv4_2 = 4; @@ -594,20 +594,20 @@ DEFUN (no_ip_route_mask, distance, vrf, NULL); } -DEFUN (no_ip_route_mask_flags, - no_ip_route_mask_flags_cmd, - "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) +DEFUN_HIDDEN (no_ip_route_mask_flags, + no_ip_route_mask_flags_cmd, + "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + NO_STR + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "Emit an ICMP unreachable when matched\n" + "Silently discard pkts when matched\n" + "Tag of this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR) { int idx_ipv4 = 3; int idx_ipv4_2 = 4; @@ -1937,8 +1937,12 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, case STATIC_IFINDEX: vty_out(vty, " %s", si->ifname); break; + /* blackhole and Null0 mean the same thing */ case STATIC_BLACKHOLE: - vty_out(vty, " Null0"); + if (CHECK_FLAG(si->flags, ZEBRA_FLAG_REJECT)) + vty_out(vty, " reject"); + else + vty_out(vty, " Null0"); break; case STATIC_IPV6_GATEWAY_IFINDEX: vty_out(vty, " %s %s", From 493c8ac787162d0a5a3ead3dbfa20b003aeb5823 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 26 Jul 2017 11:30:56 -0300 Subject: [PATCH 20/75] eigrpd: minor fix in the redistribute command Commands like "redistribute stati" and "redistribute osp" were being silently ignored. Signed-off-by: Renato Westphal --- eigrpd/eigrp_vty.c | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/eigrpd/eigrp_vty.c b/eigrpd/eigrp_vty.c index 746db2abe9..465007478d 100644 --- a/eigrpd/eigrp_vty.c +++ b/eigrpd/eigrp_vty.c @@ -1005,9 +1005,11 @@ DEFUN (eigrp_redistribute_source_metric, /* Get distribute source. */ argv_find(argv, argc, "redistribute", &idx); - source = proto_redistnum(AFI_IP, argv[idx + 1]->arg); - if (source < 0) + source = proto_redistnum(AFI_IP, argv[idx + 1]->text); + if (source < 0) { + vty_out(vty, "%% Invalid route type\n"); return CMD_WARNING_CONFIG_FAILED; + } /* Get metrics values */ @@ -1034,9 +1036,11 @@ DEFUN (no_eigrp_redistribute_source_metric, /* Get distribute source. */ argv_find(argv, argc, "redistribute", &idx); - source = proto_redistnum(AFI_IP, argv[idx + 1]->arg); - if (source < 0) + source = proto_redistnum(AFI_IP, argv[idx + 1]->text); + if (source < 0) { + vty_out(vty, "%% Invalid route type\n"); return CMD_WARNING_CONFIG_FAILED; + } /* Get metrics values */ From dd8765cad5ff747be42e2a70e1aadd56ef8f4021 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 26 Jul 2017 11:31:54 -0300 Subject: [PATCH 21/75] babel: fix crashes and improve the redistribute command Fixes the following crashes: babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "no redistribute pim" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "no redistribute eigrp" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "no redistribute nhrp" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "no redistribute table" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "no redistribute vnc" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "redistribute pim" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "redistribute eigrp" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "redistribute nhrp" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "redistribute table" babeld aborted: vtysh -c "configure terminal" -c "router babel" -c "redistribute vnc" While here, add an option to chose if we want to redistribute IPv4 or IPv6 routes (e.g. we might want static IPv4 routes only). Also, join the "no" version of the command in the same DEFUN (Yes We Can). Signed-off-by: Renato Westphal --- babeld/babel_zebra.c | 94 +++++++++++++------------------------------- babeld/babeld.c | 17 +++++--- 2 files changed, 38 insertions(+), 73 deletions(-) diff --git a/babeld/babel_zebra.c b/babeld/babel_zebra.c index 52d7eaee83..11b9c5956c 100644 --- a/babeld/babel_zebra.c +++ b/babeld/babel_zebra.c @@ -55,25 +55,6 @@ static struct { {0, 0, NULL} }; -static struct { - int str_min_len; - const char *str; -} proto_redistnum_type[ZEBRA_ROUTE_MAX] = { - [ZEBRA_ROUTE_BABEL] = {2, "babel"}, - [ZEBRA_ROUTE_BGP] = {2, "bgp"}, - [ZEBRA_ROUTE_CONNECT] = {1, "connected"}, - [ZEBRA_ROUTE_HSLS] = {1, "hsls"}, - [ZEBRA_ROUTE_ISIS] = {1, "isis"}, - [ZEBRA_ROUTE_KERNEL] = {1, "kernel"}, - [ZEBRA_ROUTE_OLSR] = {2, "olsr"}, - [ZEBRA_ROUTE_OSPF] = {2, "ospf"}, - [ZEBRA_ROUTE_OSPF6] = {5, "ospf6"}, - [ZEBRA_ROUTE_RIP] = {1, "rip"}, - [ZEBRA_ROUTE_RIPNG] = {4, "ripng"}, - [ZEBRA_ROUTE_STATIC] = {2, "static"}, - [ZEBRA_ROUTE_SYSTEM] = {2, "system"}, -}; - /* Zebra node structure. */ struct cmd_node zebra_node = { @@ -191,66 +172,46 @@ babel_zebra_read_ipv4 (int command, struct zclient *zclient, return 0; } -static int -babel_proto_redistnum(const char *s) -{ - int i; - if (! s) - return -1; - int len = strlen(s); - - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { - if (len <= (int)strlen(proto_redistnum_type[i].str) && - strncmp(proto_redistnum_type[i].str, s, - proto_redistnum_type[i].str_min_len) == 0) { - return i; - } - } - - return -1; -} - /* [Babel Command] */ DEFUN (babel_redistribute_type, babel_redistribute_type_cmd, - "redistribute " FRR_REDIST_STR_BABELD, - "Redistribute\n" - FRR_REDIST_HELP_STR_BABELD) -{ - int type; - - type = babel_proto_redistnum(argv[1]->arg); - - if (type < 0) { - vty_out (vty, "Invalid type %s\n", argv[1]->arg); - return CMD_WARNING_CONFIG_FAILED; - } - - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP, type, 0, VRF_DEFAULT); - zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, AFI_IP6, type, 0, VRF_DEFAULT); - return CMD_SUCCESS; -} - -/* [Babel Command] */ -DEFUN (no_babel_redistribute_type, - no_babel_redistribute_type_cmd, - "no redistribute " FRR_REDIST_STR_BABELD, + "[no] redistribute ", NO_STR "Redistribute\n" - FRR_REDIST_HELP_STR_BABELD) + "Redistribute IPv4 routes\n" + FRR_IP_REDIST_HELP_STR_BABELD + "Redistribute IPv6 routes\n" + FRR_IP6_REDIST_HELP_STR_BABELD) { + int negate = 0; + int family; + int afi; int type; + int idx = 0; - type = babel_proto_redistnum(argv[2]->arg); + if (argv_find(argv, argc, "no", &idx)) + negate = 1; + argv_find(argv, argc, "redistribute", &idx); + family = str2family(argv[idx + 1]->text); + if (family < 0) + return CMD_WARNING_CONFIG_FAILED; + afi = family2afi(family); + if (!afi) + return CMD_WARNING_CONFIG_FAILED; + + type = proto_redistnum(afi, argv[idx + 2]->text); if (type < 0) { - vty_out (vty, "Invalid type %s\n", argv[2]->arg); + vty_out (vty, "Invalid type %s\n", argv[idx + 2]->arg); return CMD_WARNING_CONFIG_FAILED; } - zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP, type, 0, VRF_DEFAULT); - zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, AFI_IP6, type, 0, VRF_DEFAULT); - /* perhaps should we remove xroutes having the same type... */ + if (!negate) + zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, 0, VRF_DEFAULT); + else { + zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, 0, VRF_DEFAULT); + /* perhaps should we remove xroutes having the same type... */ + } return CMD_SUCCESS; } @@ -374,7 +335,6 @@ void babelz_zebra_init(void) install_node (&zebra_node, zebra_config_write); install_element(BABEL_NODE, &babel_redistribute_type_cmd); - install_element(BABEL_NODE, &no_babel_redistribute_type_cmd); install_element(ENABLE_NODE, &debug_babel_cmd); install_element(ENABLE_NODE, &no_debug_babel_cmd); install_element(CONFIG_NODE, &debug_babel_cmd); diff --git a/babeld/babeld.c b/babeld/babeld.c index b2f8176aab..f995745e41 100644 --- a/babeld/babeld.c +++ b/babeld/babeld.c @@ -76,6 +76,7 @@ static int babel_config_write (struct vty *vty) { int lines = 0; + int afi; int i; /* list enabled debug modes */ @@ -108,13 +109,17 @@ babel_config_write (struct vty *vty) /* list enabled interfaces */ lines = 1 + babel_enable_if_config_write (vty); /* list redistributed protocols */ - for (i = 0; i < ZEBRA_ROUTE_MAX; i++) - if (i != zclient->redist_default && - vrf_bitmap_check (zclient->redist[AFI_IP][i], VRF_DEFAULT)) - { - vty_out (vty, " redistribute %s\n", zebra_route_string(i)); - lines++; + for (afi = AFI_IP; afi <= AFI_IP6; afi++) { + for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { + if (i != zclient->redist_default && + vrf_bitmap_check (zclient->redist[afi][i], VRF_DEFAULT)) { + vty_out (vty, " redistribute %s %s\n", + (afi == AFI_IP) ? "ipv4" : "ipv6", + zebra_route_string(i)); + lines++; + } } + } lines += config_write_distribute (vty); From 66a43eb221d8aed1194269f25157741a09083e10 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 26 Jul 2017 11:32:23 -0300 Subject: [PATCH 22/75] babeld: remove redundant startup message The frr_run() function already logs a startup message (and after reading the config so the "log" commands are honored). Signed-off-by: Renato Westphal --- babeld/babel_main.c | 2 -- babeld/babeld.h | 1 - 2 files changed, 3 deletions(-) diff --git a/babeld/babel_main.c b/babeld/babel_main.c index 517489f15f..54626a4aeb 100644 --- a/babeld/babel_main.c +++ b/babeld/babel_main.c @@ -207,8 +207,6 @@ main(int argc, char **argv) schedule_neighbours_check(5000, 1); - zlog_notice ("BABELd %s starting: vty@%d", BABEL_VERSION, babel_vty_port); - frr_config_fork(); frr_run(master); diff --git a/babeld/babeld.h b/babeld/babeld.h index d933f18805..899b4f175c 100644 --- a/babeld/babeld.h +++ b/babeld/babeld.h @@ -90,7 +90,6 @@ THE SOFTWARE. #define BABEL_VTY_PORT 2609 #define BABEL_DEFAULT_CONFIG "babeld.conf" -#define BABEL_VERSION "0.1 for quagga" /* Values in milliseconds */ #define BABEL_DEFAULT_HELLO_INTERVAL 4000 From 163076686edf41dfd77b889de1227334977ba070 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 26 Jul 2017 12:27:37 -0300 Subject: [PATCH 23/75] bgpd/ospfd: fix json leaks and blank output Signed-off-by: Renato Westphal --- bgpd/bgp_evpn_vty.c | 2 ++ bgpd/bgp_mplsvpn.c | 2 ++ bgpd/bgp_route.c | 4 ++++ bgpd/bgp_vpn.c | 2 ++ ospfd/ospf_vty.c | 8 ++++++++ 5 files changed, 18 insertions(+) diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 4b39ee8627..1225354c0a 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -347,6 +347,8 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, if (bgp == NULL) { if (!use_json) vty_out(vty, "No BGP process is configured\n"); + else + vty_out(vty, "{}\n"); return CMD_WARNING; } diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 5d2966d1ad..baf081c815 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -374,6 +374,8 @@ int bgp_show_mpls_vpn(struct vty *vty, afi_t afi, struct prefix_rd *prd, if (bgp == NULL) { if (!use_json) vty_out(vty, "No BGP process is configured\n"); + else + vty_out(vty, "{}\n"); return CMD_WARNING; } diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 7cdc839618..b554aeb32b 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -8257,6 +8257,8 @@ static int bgp_show(struct vty *vty, struct bgp *bgp, afi_t afi, safi_t safi, if (bgp == NULL) { if (!use_json) vty_out(vty, "No BGP process is configured\n"); + else + vty_out(vty, "{}\n"); return CMD_WARNING; } @@ -8622,6 +8624,8 @@ static int bgp_show_route(struct vty *vty, struct bgp *bgp, const char *ip_str, if (!bgp) { if (!use_json) vty_out(vty, "No BGP process is configured\n"); + else + vty_out(vty, "{}\n"); return CMD_WARNING; } } diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index ca98ff0668..4661e195a2 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -51,6 +51,8 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, if (bgp == NULL) { if (!use_json) vty_out(vty, "No BGP process is configured\n"); + else + vty_out(vty, "{}\n"); return CMD_WARNING; } diff --git a/ospfd/ospf_vty.c b/ospfd/ospf_vty.c index 55d6c27e8c..a8bfb669af 100644 --- a/ospfd/ospf_vty.c +++ b/ospfd/ospf_vty.c @@ -4402,6 +4402,10 @@ static int show_ip_ospf_neighbor_id_common(struct vty *vty, struct ospf *ospf, if (!ret) { if (!use_json) vty_out(vty, "Please specify Neighbor ID by A.B.C.D\n"); + else { + vty_out(vty, "{}\n"); + json_object_free(json); + } return CMD_WARNING; } @@ -4682,6 +4686,10 @@ static int show_ip_ospf_neighbor_int_detail_common(struct vty *vty, if (!ifp) { if (!use_json) vty_out(vty, "No such interface.\n"); + else { + vty_out(vty, "{}\n"); + json_object_free(json); + } return CMD_WARNING; } From bf0526b91925576387b47f5e78cc03aae797311a Mon Sep 17 00:00:00 2001 From: Brian Rak Date: Wed, 26 Jul 2017 11:47:07 -0400 Subject: [PATCH 24/75] redhat: Update documentation about frr-reload --- doc/Building_FRR_on_CentOS6.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/doc/Building_FRR_on_CentOS6.md b/doc/Building_FRR_on_CentOS6.md index 4139daf316..b25845c38a 100644 --- a/doc/Building_FRR_on_CentOS6.md +++ b/doc/Building_FRR_on_CentOS6.md @@ -17,6 +17,9 @@ CentOS 6 restrictions: - Zebra is unable to detect what bridge/vrf an interface is associcated with (IFLA_INFO_SLAVE_KIND does not exist in the kernel headers, you can use a newer kernel + headers to get this functionality) +- frr_reload.py will not work, as this requires Python 2.7, and CentOS 6 + only has 2.6. You can install Python 2.7 via IUS, but it won't work + properly unless you compile and install the ipaddr package for it. Install required packages ------------------------- From e386c1d575c12703913ed6d93b2a285b763812bc Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 26 Jul 2017 16:33:39 +0000 Subject: [PATCH 25/75] bgpd: UPDATE may be larger than 4096 if addpath is used Signed-off-by: Daniel Walton --- bgpd/bgp_updgrp_packet.c | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index d7a4a36986..1a23a36e91 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -700,6 +700,7 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) int send_attr_printed = 0; int num_pfx = 0; int addpath_encode = 0; + int addpath_overhead = 0; u_int32_t addpath_tx_id = 0; struct prefix_rd *prd = NULL; mpls_label_t label = MPLS_INVALID_LABEL; @@ -721,6 +722,7 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) bpacket_attr_vec_arr_reset(&vecarr); addpath_encode = bgp_addpath_encode_tx(peer, afi, safi); + addpath_overhead = addpath_encode ? BGP_ADDPATH_ID_LEN : 0; adv = BGP_ADV_FIFO_HEAD(&subgrp->sync->update); while (adv) { @@ -732,8 +734,8 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) space_remaining = STREAM_CONCAT_REMAIN(s, snlri, STREAM_SIZE(s)) - BGP_MAX_PACKET_SIZE_OVERFLOW; - space_needed = BGP_NLRI_LENGTH + bgp_packet_mpattr_prefix_size( - afi, safi, &rn->p); + space_needed = BGP_NLRI_LENGTH + addpath_overhead + + bgp_packet_mpattr_prefix_size(afi, safi, &rn->p); /* When remaining space can't include NLRI and it's length. */ if (space_remaining < space_needed) @@ -777,9 +779,9 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) space_remaining = STREAM_CONCAT_REMAIN(s, snlri, STREAM_SIZE(s)) - BGP_MAX_PACKET_SIZE_OVERFLOW; - space_needed = - BGP_NLRI_LENGTH + bgp_packet_mpattr_prefix_size( - afi, safi, &rn->p); + space_needed = BGP_NLRI_LENGTH + addpath_overhead + + bgp_packet_mpattr_prefix_size(afi, safi, + &rn->p); /* If the attributes alone do not leave any room for * NLRI then @@ -936,6 +938,7 @@ struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp) int space_needed = 0; int num_pfx = 0; int addpath_encode = 0; + int addpath_overhead = 0; u_int32_t addpath_tx_id = 0; struct prefix_rd *prd = NULL; @@ -952,6 +955,7 @@ struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp) s = subgrp->work; stream_reset(s); addpath_encode = bgp_addpath_encode_tx(peer, afi, safi); + addpath_overhead = addpath_encode ? BGP_ADDPATH_ID_LEN : 0; while ((adv = BGP_ADV_FIFO_HEAD(&subgrp->sync->withdraw)) != NULL) { assert(adv->rn); @@ -962,7 +966,7 @@ struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp) space_remaining = STREAM_REMAIN(s) - BGP_MAX_PACKET_SIZE_OVERFLOW; space_needed = - BGP_NLRI_LENGTH + BGP_TOTAL_ATTR_LEN + BGP_NLRI_LENGTH + addpath_overhead + BGP_TOTAL_ATTR_LEN + bgp_packet_mpattr_prefix_size(afi, safi, &rn->p); if (space_remaining < space_needed) From 8eeb033552d839da56b4d417006bfb1ec43a1bc3 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Wed, 26 Jul 2017 17:49:20 +0000 Subject: [PATCH 26/75] bgpd: attribute-unchanged issues with peer-groups Signed-off-by: Daniel Walton --- bgpd/bgp_vty.c | 37 ++++++++++++++++++++++++++++++++----- bgpd/bgpd.c | 34 ++++++++++++++++------------------ 2 files changed, 48 insertions(+), 23 deletions(-) diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 8ae015173f..65a1473f75 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -4201,8 +4201,15 @@ DEFUN (neighbor_attr_unchanged, "Med attribute\n") { int idx = 0; - char *peer = argv[1]->arg; + char *peer_str = argv[1]->arg; + struct peer *peer; u_int16_t flags = 0; + afi_t afi = bgp_node_afi(vty); + safi_t safi = bgp_node_safi(vty); + + peer = peer_and_group_lookup_vty(vty, peer_str); + if (!peer) + return CMD_WARNING_CONFIG_FAILED; if (argv_find(argv, argc, "as-path", &idx)) SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED); @@ -4213,15 +4220,35 @@ DEFUN (neighbor_attr_unchanged, if (argv_find(argv, argc, "med", &idx)) SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED); - if (!flags) // no flags means all of them! - { + /* no flags means all of them! */ + if (!flags) { SET_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED); SET_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED); SET_FLAG(flags, PEER_FLAG_MED_UNCHANGED); + } else { + if (!CHECK_FLAG(flags, PEER_FLAG_AS_PATH_UNCHANGED) && + peer_af_flag_check(peer, afi, safi, + PEER_FLAG_AS_PATH_UNCHANGED)) { + peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_AS_PATH_UNCHANGED); + } + + if (!CHECK_FLAG(flags, PEER_FLAG_NEXTHOP_UNCHANGED) && + peer_af_flag_check(peer, afi, safi, + PEER_FLAG_NEXTHOP_UNCHANGED)) { + peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_NEXTHOP_UNCHANGED); + } + + if (!CHECK_FLAG(flags, PEER_FLAG_MED_UNCHANGED) && + peer_af_flag_check(peer, afi, safi, + PEER_FLAG_MED_UNCHANGED)) { + peer_af_flag_unset_vty(vty, peer_str, afi, safi, + PEER_FLAG_MED_UNCHANGED); + } } - return peer_af_flag_set_vty(vty, peer, bgp_node_afi(vty), - bgp_node_safi(vty), flags); + return peer_af_flag_set_vty(vty, peer_str, afi, safi, flags); } ALIAS_HIDDEN( diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 3453da665a..a0e2d6749a 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -6926,36 +6926,34 @@ static void bgp_config_write_peer_af(struct vty *vty, struct bgp *bgp, bgp_config_write_filter(vty, peer, afi, safi, write); /* atribute-unchanged. */ - if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_AS_PATH_UNCHANGED) - || CHECK_FLAG(peer->af_flags[afi][safi], - PEER_FLAG_NEXTHOP_UNCHANGED) - || CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MED_UNCHANGED)) { - if (peergroup_af_flag_check(peer, afi, safi, - PEER_FLAG_AS_PATH_UNCHANGED) - && peergroup_af_flag_check(peer, afi, safi, - PEER_FLAG_NEXTHOP_UNCHANGED) - && peergroup_af_flag_check(peer, afi, safi, - PEER_FLAG_MED_UNCHANGED)) { - afi_header_vty_out( - vty, afi, safi, write, - " neighbor %s attribute-unchanged\n", addr); - } else { + if (peer_af_flag_check(peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED) || + peer_af_flag_check(peer, afi, safi, PEER_FLAG_NEXTHOP_UNCHANGED) || + peer_af_flag_check(peer, afi, safi, PEER_FLAG_MED_UNCHANGED)) { + + if (!peer_group_active(peer) || + peergroup_af_flag_check(peer, afi, safi, + PEER_FLAG_AS_PATH_UNCHANGED) || + peergroup_af_flag_check(peer, afi, safi, + PEER_FLAG_NEXTHOP_UNCHANGED) || + peergroup_af_flag_check(peer, afi, safi, + PEER_FLAG_MED_UNCHANGED)) { + afi_header_vty_out( vty, afi, safi, write, " neighbor %s attribute-unchanged%s%s%s\n", addr, - peergroup_af_flag_check( + peer_af_flag_check( peer, afi, safi, PEER_FLAG_AS_PATH_UNCHANGED) ? " as-path" : "", - peergroup_af_flag_check( + peer_af_flag_check( peer, afi, safi, PEER_FLAG_NEXTHOP_UNCHANGED) ? " next-hop" : "", - peergroup_af_flag_check(peer, afi, safi, - PEER_FLAG_MED_UNCHANGED) + peer_af_flag_check(peer, afi, safi, + PEER_FLAG_MED_UNCHANGED) ? " med" : ""); } From 647450524c42ba88c8b5acd60255e9018734c6b9 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 26 Jul 2017 09:57:35 -0400 Subject: [PATCH 27/75] bgpd: Set the ifindex to DELETED after we notify zebra The code path for a deleted interface was calling zebra with a IFINDEX_DELETED, which caused zebra to bitch and moan about the issue. Since the only thing this function does is call zebra to deregister the RA stuff, don't set the ifindex to DELETED till afterwords. Signed-off-by: Donald Sharp --- bgpd/bgp_zebra.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 8bf5477a61..4870e54aec 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -269,8 +269,6 @@ static int bgp_interface_delete(int command, struct zclient *zclient, if (!ifp) /* This may happen if we've just unregistered for a VRF. */ return 0; - ifp->ifindex = IFINDEX_DELETED; - if (BGP_DEBUG(zebra, ZEBRA)) zlog_debug("Rx Intf del VRF %u IF %s", vrf_id, ifp->name); @@ -279,6 +277,8 @@ static int bgp_interface_delete(int command, struct zclient *zclient, return 0; bgp_update_interface_nbrs(bgp, ifp, NULL); + + ifp->ifindex = IFINDEX_DELETED; return 0; } From 05a38c0c8b1887c58e0b916880aaf7e3004a3cc2 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 26 Jul 2017 09:41:36 -0400 Subject: [PATCH 28/75] bgpd: Fix nexthop comparison for v6 When we have both a LL and a Global address, use what the attribute wants for comparison instead of assuming Global than LL. This was causing BGP to install v6 routes that used the LL as the nexthop, where the global address was different and being used as the basis for comparison. Signed-off-by: Donald Sharp --- bgpd/bgp_mpath.c | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index 6dc6dc6769..d3ee140bb4 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -102,6 +102,7 @@ int bgp_maximum_paths_unset(struct bgp *bgp, afi_t afi, safi_t safi, int bgp_info_nexthop_cmp(struct bgp_info *bi1, struct bgp_info *bi2) { int compare; + struct in6_addr addr1, addr2; compare = IPV4_ADDR_CMP(&bi1->attr->nexthop, &bi2->attr->nexthop); if (!compare) { @@ -120,13 +121,18 @@ int bgp_info_nexthop_cmp(struct bgp_info *bi1, struct bgp_info *bi2) &bi2->attr->mp_nexthop_global); break; case BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL: - compare = IPV6_ADDR_CMP( - &bi1->attr->mp_nexthop_global, - &bi2->attr->mp_nexthop_global); + addr1 = (bi1->attr->mp_nexthop_prefer_global) ? + bi1->attr->mp_nexthop_global + : bi1->attr->mp_nexthop_local; + addr2 = (bi2->attr->mp_nexthop_prefer_global) ? + bi2->attr->mp_nexthop_global + : bi2->attr->mp_nexthop_local; + + if (!bi1->attr->mp_nexthop_prefer_global && + !bi2->attr->mp_nexthop_prefer_global) + compare = !(bi1->peer->ifindex == bi2->peer->ifindex); if (!compare) - compare = IPV6_ADDR_CMP( - &bi1->attr->mp_nexthop_local, - &bi2->attr->mp_nexthop_local); + compare = IPV6_ADDR_CMP(&addr1, &addr2); break; } } From a83a533139f64434b68ebc3ae9a65a013b04cc34 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 25 Jul 2017 17:28:19 -0400 Subject: [PATCH 29/75] lib: add CLI node names Adds an array of descriptive names for each CLI node, plus a runtime check to make sure folks don't forget to update it. Signed-off-by: Quentin Young --- lib/command.c | 109 +++++++++++++++++++++++++++++++++++++++++++++++--- lib/command.h | 5 ++- 2 files changed, 107 insertions(+), 7 deletions(-) diff --git a/lib/command.c b/lib/command.c index d97ad9db3c..2899a7c2ba 100644 --- a/lib/command.c +++ b/lib/command.c @@ -42,11 +42,80 @@ #include "command_graph.h" #include "qobj.h" #include "defaults.h" +#include "termtable.h" DEFINE_MTYPE(LIB, HOST, "Host config") DEFINE_MTYPE(LIB, STRVEC, "String vector") DEFINE_MTYPE(LIB, COMPLETION, "Completion item") +const char *node_names[] = { + "auth", // AUTH_NODE, + "view", // VIEW_NODE, + "auth enable", // AUTH_ENABLE_NODE, + "enable", // ENABLE_NODE, + "config", // CONFIG_NODE, + "service", // SERVICE_NODE, + "debug", // DEBUG_NODE, + "vrf debug", // VRF_DEBUG_NODE, + "vmc debug", // DEBUG_VNC_NODE, + "aaa", // AAA_NODE, + "keychain", // KEYCHAIN_NODE, + "leychain key", // KEYCHAIN_KEY_NODE, + "logical-router", // NS_NODE, + "vrf", // VRF_NODE, + "interface", // INTERFACE_NODE, + "zebra", // ZEBRA_NODE, + "table", // TABLE_NODE, + "rip", // RIP_NODE, + "ripng", // RIPNG_NODE, + "babel", // BABEL_NODE, + "eigrp", // EIGRP_NODE, + "bgp", // BGP_NODE, + "bgp vpnv4", // BGP_VPNV4_NODE, + "bgp vpnv56", // BGP_VPNV6_NODE, + "bgp ipv4 unicast", // BGP_IPV4_NODE, + "bgp ipv4 multicast", // BGP_IPV4M_NODE, + "bgp ipv4 labeled unicast", // BGP_IPV4L_NODE, + "bgp ipv6", // BGP_IPV6_NODE, + "bgp ipv6 multicast", // BGP_IPV6M_NODE, + "bgp ipv6 labeled unicast", // BGP_IPV6L_NODE, + "bgp vrf policy", // BGP_VRF_POLICY_NODE, + "bgp vnc defaults", // BGP_VNC_DEFAULTS_NODE, + "bgp vnc nve", // BGP_VNC_NVE_GROUP_NODE, + "bgp vnc l2", // BGP_VNC_L2_GROUP_NODE, + "rfp defaults", // RFP_DEFAULTS_NODE, + "bgp evpn", // BGP_EVPN_NODE, + "ospf", // OSPF_NODE, + "ospf6", // OSPF6_NODE, + "ldp", // LDP_NODE, + "ldp ipv4", // LDP_IPV4_NODE, + "ldp ipv6", // LDP_IPV6_NODE, + "ldp ipv4 interface", // LDP_IPV4_IFACE_NODE, + "ldp ipv6 interface", // LDP_IPV6_IFACE_NODE, + "ldp l2vpn", // LDP_L2VPN_NODE, + "ldp", // LDP_PSEUDOWIRE_NODE, + "isis", // ISIS_NODE, + "pim", // PIM_NODE, + "masc", // MASC_NODE, + "irdp", // IRDP_NODE, + "static ip", // IP_NODE, + "ipv4 access list", // ACCESS_NODE, + "ipv4 prefix list", // PREFIX_NODE, + "ipv6 access list", // ACCESS_IPV6_NODE, + "ipv6 prefix list", // PREFIX_IPV6_NODE, + "AS list", // AS_LIST_NODE, + "community list", // COMMUNITY_LIST_NODE, + "routemap", // RMAP_NODE, + "smux", // SMUX_NODE, + "dump", // DUMP_NODE, + "forwarding", // FORWARDING_NODE, + "protocol", // PROTOCOL_NODE, + "mpls", // MPLS_NODE, + "vty", // VTY_NODE, + "link-params", // LINK_PARAMS_NODE, + "bgp evpn vni", // BGP_EVPN_VNI_NODE, +}; + /* Command vector which includes some level of command lists. Normally each daemon maintains each own cmdvec. */ vector cmdvec = NULL; @@ -2355,6 +2424,32 @@ DEFUN (no_banner_motd, return CMD_SUCCESS; } +DEFUN(find, + find_cmd, + "find COMMAND...", + "Find CLI command containing text\n" + "Text to search for\n") +{ + char *text = argv_concat(argv, argc, 1); + + for (unsigned int i = 0; i < vector_active(cmdvec); i++) { + struct cmd_node *node = vector_slot(cmdvec, i); + if (!node) + continue; + vector clis = node->cmd_vector; + for (unsigned int j = 0; j < vector_active(clis); j++) { + struct cmd_element *cli = vector_slot(clis, j); + if (strcasestr(cli->string, text)) + vty_out(vty, "(%s) %s", + node_names[node->node], cli->string); + } + } + + XFREE(MTYPE_TMP, text); + + return CMD_SUCCESS; +} + /* Set config filename. Called from vty.c */ void host_config_set(const char *filename) { @@ -2375,6 +2470,7 @@ void install_default(enum node_type node) install_element(node, &config_end_cmd); install_element(node, &config_help_cmd); install_element(node, &config_list_cmd); + install_element(node, &find_cmd); install_element(node, &config_write_cmd); install_element(node, &show_running_config_cmd); @@ -2389,6 +2485,9 @@ void install_default(enum node_type node) * terminal = -1 -- watchfrr / no logging, but minimal config control */ void cmd_init(int terminal) { + if (array_size(node_names) != NODE_TYPE_MAX) + assert(!"Update the CLI node description array!"); + qobj_init(); varhandlers = list_new(); @@ -2416,6 +2515,8 @@ void cmd_init(int terminal) /* Each node's basic commands. */ install_element(VIEW_NODE, &show_version_cmd); + install_element(ENABLE_NODE, &show_startup_config_cmd); + if (terminal) { install_element(VIEW_NODE, &config_list_cmd); install_element(VIEW_NODE, &config_exit_cmd); @@ -2428,20 +2529,16 @@ void cmd_init(int terminal) install_element(VIEW_NODE, &show_commandtree_cmd); install_element(VIEW_NODE, &echo_cmd); install_element(VIEW_NODE, &autocomplete_cmd); - } + install_element(VIEW_NODE, &find_cmd); - if (terminal) { install_element(ENABLE_NODE, &config_end_cmd); install_element(ENABLE_NODE, &config_disable_cmd); install_element(ENABLE_NODE, &config_terminal_cmd); install_element(ENABLE_NODE, ©_runningconf_startupconf_cmd); install_element(ENABLE_NODE, &config_write_cmd); install_element(ENABLE_NODE, &show_running_config_cmd); - } - install_element(ENABLE_NODE, &show_startup_config_cmd); - - if (terminal) { install_element(ENABLE_NODE, &config_logmsg_cmd); + install_default(CONFIG_NODE); thread_cmd_init(); diff --git a/lib/command.h b/lib/command.h index 5d52fe3fc3..28aa1ac5dd 100644 --- a/lib/command.h +++ b/lib/command.h @@ -68,7 +68,7 @@ struct host { char *motdfile; }; -/* There are some command levels which called from command node. */ +/* List of CLI nodes. Please remember to update the names array below. */ enum node_type { AUTH_NODE, /* Authentication mode of vty interface. */ VIEW_NODE, /* View node. Default mode of vty interface. */ @@ -135,8 +135,11 @@ enum node_type { VTY_NODE, /* Vty node. */ LINK_PARAMS_NODE, /* Link-parameters node */ BGP_EVPN_VNI_NODE, /* BGP EVPN VNI */ + NODE_TYPE_MAX, /* maximum */ }; +extern const char *node_names[]; + /* Node which has some commands and prompt string and configuration function pointer . */ struct cmd_node { From 983bd6f71cb3184ee4f155fa1dd8d92fa3934282 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 26 Jul 2017 19:32:55 -0300 Subject: [PATCH 30/75] ldpd: add the exit-address-family command Signed-off-by: Renato Westphal --- ldpd/ldp_vty_cmds.c | 12 ++++++++++++ ldpd/ldp_vty_conf.c | 2 +- vtysh/vtysh.c | 14 +++++++++++++- 3 files changed, 26 insertions(+), 2 deletions(-) diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index d28424cbb7..871905aa8f 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -80,6 +80,16 @@ DEFUN_NOSH(ldp_address_family, return (ldp_vty_address_family(vty, negate, af)); } +DEFUN_NOSH(ldp_exit_address_family, + ldp_exit_address_family_cmd, + "exit-address-family", + "Exit from Address Family configuration mode\n") +{ + if (vty->node == LDP_IPV4_NODE || vty->node == LDP_IPV6_NODE) + vty->node = LDP_NODE; + return CMD_SUCCESS; +} + DEFUN (ldp_discovery_holdtime, ldp_discovery_holdtime_cmd, "[no] discovery holdtime (1-65535)", @@ -1082,6 +1092,7 @@ ldp_vty_init (void) install_element(LDP_IPV4_NODE, &ldp_interface_cmd); install_element(LDP_IPV4_NODE, &ldp_session_holdtime_cmd); install_element(LDP_IPV4_NODE, &ldp_neighbor_ipv4_targeted_cmd); + install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd); install_element(LDP_IPV6_NODE, &ldp_discovery_holdtime_cmd); install_element(LDP_IPV6_NODE, &ldp_discovery_interval_cmd); @@ -1095,6 +1106,7 @@ ldp_vty_init (void) install_element(LDP_IPV6_NODE, &ldp_interface_cmd); install_element(LDP_IPV6_NODE, &ldp_session_holdtime_cmd); install_element(LDP_IPV6_NODE, &ldp_neighbor_ipv6_targeted_cmd); + install_element(LDP_IPV6_NODE, &ldp_exit_address_family_cmd); install_element(LDP_IPV4_IFACE_NODE, &ldp_discovery_holdtime_cmd); install_element(LDP_IPV4_IFACE_NODE, &ldp_discovery_interval_cmd); diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 4e900ca93e..09eb6a7c55 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -233,7 +233,7 @@ ldp_af_config_write(struct vty *vty, int af, struct ldpd_conf *conf, ldp_af_iface_config_write(vty, af); - vty_out (vty, " !\n"); + vty_out(vty, " exit-address-family\n"); } int diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 666f3049d7..395982189c 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -303,7 +303,9 @@ static int vtysh_execute_func(const char *line, int pager) || saved_node == BGP_IPV4L_NODE || saved_node == BGP_IPV6L_NODE || saved_node == BGP_IPV6M_NODE - || saved_node == BGP_EVPN_NODE) + || saved_node == BGP_EVPN_NODE + || saved_node == LDP_IPV4_NODE + || saved_node == LDP_IPV6_NODE) && (tried == 1)) { vtysh_execute("exit-address-family"); } else if ((saved_node == BGP_EVPN_VNI_NODE) && (tried == 1)) { @@ -1268,6 +1270,14 @@ DEFUNSH(VTYSH_LDPD, ldp_address_family_ipv6, ldp_address_family_ipv6_cmd, return CMD_SUCCESS; } +DEFUNSH(VTYSH_LDPD, ldp_exit_address_family, ldp_exit_address_family_cmd, + "exit-address-family", "Exit from Address Family configuration mode\n") +{ + if (vty->node == LDP_IPV4_NODE || vty->node == LDP_IPV6_NODE) + vty->node = LDP_NODE; + return CMD_SUCCESS; +} + DEFUNSH(VTYSH_LDPD, ldp_interface_ifname, ldp_interface_ifname_cmd, "interface IFNAME", "Enable LDP on an interface and enter interface submode\n" @@ -2945,8 +2955,10 @@ void vtysh_init_vty(void) install_element(LDP_NODE, &vtysh_quit_ldpd_cmd); install_element(LDP_IPV4_NODE, &vtysh_exit_ldpd_cmd); install_element(LDP_IPV4_NODE, &vtysh_quit_ldpd_cmd); + install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd); install_element(LDP_IPV6_NODE, &vtysh_exit_ldpd_cmd); install_element(LDP_IPV6_NODE, &vtysh_quit_ldpd_cmd); + install_element(LDP_IPV6_NODE, &ldp_exit_address_family_cmd); install_element(LDP_IPV4_IFACE_NODE, &vtysh_exit_ldpd_cmd); install_element(LDP_IPV4_IFACE_NODE, &vtysh_quit_ldpd_cmd); install_element(LDP_IPV6_IFACE_NODE, &vtysh_exit_ldpd_cmd); From a701f7eaa27a6a816170997439a96f43082c9833 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Wed, 26 Jul 2017 19:37:49 -0300 Subject: [PATCH 31/75] vtysh: fix markfile output for ldpd Put the "end" marker in the right places. This should fix the frr-reload.py script because it depends on the output of vtysh -m. Signed-off-by: Renato Westphal --- vtysh/vtysh.c | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 395982189c..adf47ed57c 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -498,6 +498,29 @@ int vtysh_mark_file(const char *filename) strcpy(vty_buf_copy, vty->buf); vty_buf_trimmed = trim(vty_buf_copy); + switch (vty->node) { + case LDP_IPV4_IFACE_NODE: + if (strncmp(vty_buf_copy, " ", 3)) { + fprintf(stdout, " end\n"); + vty->node = LDP_IPV4_NODE; + } + break; + case LDP_IPV6_IFACE_NODE: + if (strncmp(vty_buf_copy, " ", 3)) { + fprintf(stdout, " end\n"); + vty->node = LDP_IPV6_NODE; + } + break; + case LDP_PSEUDOWIRE_NODE: + if (strncmp(vty_buf_copy, " ", 2)) { + fprintf(stdout, " end\n"); + vty->node = LDP_L2VPN_NODE; + } + break; + default: + break; + } + if (vty_buf_trimmed[0] == '!' || vty_buf_trimmed[0] == '#') { fprintf(stdout, "%s", vty->buf); continue; From cf6c83e712733f41a870a9c077803bc2e29ac69e Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Tue, 25 Jul 2017 14:20:55 -0400 Subject: [PATCH 32/75] lib, vtysh: add `find COMMAND` Substring search through all defined commands in all nodes. Signed-off-by: Quentin Young --- lib/command.c | 12 ++++---- lib/command.h | 3 +- vtysh/vtysh.c | 79 ++++++++++++++++++++++++--------------------------- 3 files changed, 46 insertions(+), 48 deletions(-) diff --git a/lib/command.c b/lib/command.c index 2899a7c2ba..4690a36be0 100644 --- a/lib/command.c +++ b/lib/command.c @@ -42,7 +42,6 @@ #include "command_graph.h" #include "qobj.h" #include "defaults.h" -#include "termtable.h" DEFINE_MTYPE(LIB, HOST, "Host config") DEFINE_MTYPE(LIB, STRVEC, "String vector") @@ -2431,16 +2430,19 @@ DEFUN(find, "Text to search for\n") { char *text = argv_concat(argv, argc, 1); + const struct cmd_node *node; + const struct cmd_element *cli; + vector clis; for (unsigned int i = 0; i < vector_active(cmdvec); i++) { - struct cmd_node *node = vector_slot(cmdvec, i); + node = vector_slot(cmdvec, i); if (!node) continue; - vector clis = node->cmd_vector; + clis = node->cmd_vector; for (unsigned int j = 0; j < vector_active(clis); j++) { - struct cmd_element *cli = vector_slot(clis, j); + cli = vector_slot(clis, j); if (strcasestr(cli->string, text)) - vty_out(vty, "(%s) %s", + vty_out(vty, " (%s) %s\n", node_names[node->node], cli->string); } } diff --git a/lib/command.h b/lib/command.h index 28aa1ac5dd..533b4b3289 100644 --- a/lib/command.h +++ b/lib/command.h @@ -68,7 +68,7 @@ struct host { char *motdfile; }; -/* List of CLI nodes. Please remember to update the names array below. */ +/* List of CLI nodes. Please remember to update the name array in command.c. */ enum node_type { AUTH_NODE, /* Authentication mode of vty interface. */ VIEW_NODE, /* View node. Default mode of vty interface. */ @@ -138,6 +138,7 @@ enum node_type { NODE_TYPE_MAX, /* maximum */ }; +extern vector cmdvec; extern const char *node_names[]; /* Node which has some commands and prompt string and configuration diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index 666f3049d7..92e522b695 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2582,9 +2582,39 @@ DEFUN (config_list, return cmd_list_cmds(vty, argc == 2); } +DEFUN(find, + find_cmd, + "find COMMAND...", + "Find CLI command containing text\n" + "Text to search for\n") +{ + char *text = argv_concat(argv, argc, 1); + const struct cmd_node *node; + const struct cmd_element *cli; + vector clis; + + for (unsigned int i = 0; i < vector_active(cmdvec); i++) { + node = vector_slot(cmdvec, i); + if (!node) + continue; + clis = node->cmd_vector; + for (unsigned int j = 0; j < vector_active(clis); j++) { + cli = vector_slot(clis, j); + if (strcasestr(cli->string, text)) + fprintf(stdout, " (%s) %s\n", + node_names[node->node], cli->string); + } + } + + XFREE(MTYPE_TMP, text); + + return CMD_SUCCESS; +} + static void vtysh_install_default(enum node_type node) { install_element(node, &config_list_cmd); + install_element(node, &find_cmd); } /* Making connection to protocol daemon. */ @@ -2876,48 +2906,13 @@ void vtysh_init_vty(void) install_node(&isis_node, NULL); install_node(&vty_node, NULL); - vtysh_install_default(VIEW_NODE); - vtysh_install_default(CONFIG_NODE); - vtysh_install_default(BGP_NODE); - vtysh_install_default(RIP_NODE); - vtysh_install_default(INTERFACE_NODE); - vtysh_install_default(LINK_PARAMS_NODE); - vtysh_install_default(NS_NODE); - vtysh_install_default(VRF_NODE); - vtysh_install_default(RMAP_NODE); - vtysh_install_default(ZEBRA_NODE); - vtysh_install_default(BGP_VPNV4_NODE); - vtysh_install_default(BGP_VPNV6_NODE); - vtysh_install_default(BGP_IPV4_NODE); - vtysh_install_default(BGP_IPV4M_NODE); - vtysh_install_default(BGP_IPV4L_NODE); - vtysh_install_default(BGP_IPV6_NODE); - vtysh_install_default(BGP_IPV6M_NODE); - vtysh_install_default(BGP_EVPN_NODE); - vtysh_install_default(BGP_EVPN_VNI_NODE); - vtysh_install_default(BGP_IPV6L_NODE); -#if ENABLE_BGP_VNC - vtysh_install_default(BGP_VRF_POLICY_NODE); - vtysh_install_default(BGP_VNC_DEFAULTS_NODE); - vtysh_install_default(BGP_VNC_NVE_GROUP_NODE); - vtysh_install_default(BGP_VNC_L2_GROUP_NODE); -#endif - vtysh_install_default(OSPF_NODE); - vtysh_install_default(EIGRP_NODE); - vtysh_install_default(BABEL_NODE); - vtysh_install_default(RIPNG_NODE); - vtysh_install_default(OSPF6_NODE); - vtysh_install_default(LDP_NODE); - vtysh_install_default(LDP_IPV4_NODE); - vtysh_install_default(LDP_IPV6_NODE); - vtysh_install_default(LDP_IPV4_IFACE_NODE); - vtysh_install_default(LDP_IPV6_IFACE_NODE); - vtysh_install_default(LDP_L2VPN_NODE); - vtysh_install_default(LDP_PSEUDOWIRE_NODE); - vtysh_install_default(ISIS_NODE); - vtysh_install_default(KEYCHAIN_NODE); - vtysh_install_default(KEYCHAIN_KEY_NODE); - vtysh_install_default(VTY_NODE); + struct cmd_node *node; + for (unsigned int i = 0; i < vector_active(cmdvec); i++) { + node = vector_slot(cmdvec, i); + if (!node || node->node == VIEW_NODE) + continue; + vtysh_install_default(node->node); + } install_element(VIEW_NODE, &vtysh_enable_cmd); install_element(ENABLE_NODE, &vtysh_config_terminal_cmd); From 32ab5cf4af84bc2acb4cf9fe48940397cd834797 Mon Sep 17 00:00:00 2001 From: Olivier Dugeon Date: Thu, 27 Jul 2017 16:09:00 +0200 Subject: [PATCH 33/75] Update PR #839 following review * Remove enum status_t opcode in ospfd.h * Replace enum status_t opcode by bool enabled in ospf_te.[c,h] and ospf_ri.c * Add missign parenthesis '()' around 'if CHECK_FLAG' in ospf_te.c and ospf_ri.c Signed-off-by: Olivier Dugeon --- ospfd/ospf_ri.c | 66 +++++++++++++-------------- ospfd/ospf_te.c | 115 ++++++++++++++++++++---------------------------- ospfd/ospf_te.h | 2 +- ospfd/ospfd.h | 5 +-- 4 files changed, 83 insertions(+), 105 deletions(-) diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index e192a39e45..e41b9c1524 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -60,7 +60,7 @@ /* Store Router Information PCE TLV and SubTLV in network byte order. */ struct ospf_pce_info { - status_t status; + bool enabled; struct ri_tlv_pce pce_header; struct ri_pce_subtlv_address pce_address; struct ri_pce_subtlv_path_scope pce_scope; @@ -71,7 +71,7 @@ struct ospf_pce_info { /* Following structure are internal use only. */ struct ospf_router_info { - status_t status; + bool enabled; u_int8_t registered; u_int8_t scope; @@ -119,13 +119,13 @@ int ospf_router_info_init(void) { memset(&OspfRI, 0, sizeof(struct ospf_router_info)); - OspfRI.status = disable; + OspfRI.enabled = false; OspfRI.registered = 0; OspfRI.scope = OSPF_OPAQUE_AS_LSA; OspfRI.flags = 0; /* Initialize pce domain and neighbor list */ - OspfRI.pce_info.status = disable; + OspfRI.pce_info.enabled = false; OspfRI.pce_info.pce_domain = list_new(); OspfRI.pce_info.pce_domain->del = del_pce_info; OspfRI.pce_info.pce_neighbor = list_new(); @@ -193,7 +193,7 @@ void ospf_router_info_term(void) OspfRI.pce_info.pce_domain = NULL; OspfRI.pce_info.pce_neighbor = NULL; - OspfRI.status = disable; + OspfRI.enabled = false; ospf_router_info_unregister(); @@ -254,11 +254,11 @@ static int set_pce_header(struct ospf_pce_info *pce) if (length != 0) { pce->pce_header.header.type = htons(RI_TLV_PCE); pce->pce_header.header.length = htons(length); - pce->status = enable; + pce->enabled = true; } else { pce->pce_header.header.type = 0; pce->pce_header.header.length = 0; - pce->status = disable; + pce->enabled = false; } return length; @@ -525,7 +525,7 @@ static void ospf_router_info_lsa_body_set(struct stream *s) set_pce_header (&OspfRI.pce_info); /* Add RI PCE TLV if it is set */ - if (OspfRI.pce_info.status == enable) { + if (OspfRI.pce_info.enabled) { /* Build PCE TLV */ build_tlv_header(s, &OspfRI.pce_info.pce_header.header); @@ -686,7 +686,7 @@ static int ospf_router_info_lsa_originate(void *arg) int rc = -1; - if (OspfRI.status == disable) { + if (!OspfRI.enabled) { zlog_info( "ospf_router_info_lsa_originate: ROUTER INFORMATION is disabled now."); rc = 0; /* This is not an error case. */ @@ -694,8 +694,8 @@ static int ospf_router_info_lsa_originate(void *arg) } /* Check if Router Information LSA is already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) { - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_FORCED_REFRESH) { + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) { + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_FORCED_REFRESH)) { UNSET_FLAG(OspfRI.flags, RIFLG_LSA_FORCED_REFRESH); ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -718,7 +718,7 @@ static struct ospf_lsa *ospf_router_info_lsa_refresh(struct ospf_lsa *lsa) struct ospf_lsa *new = NULL; struct ospf *top; - if (OspfRI.status == disable) { + if (!OspfRI.enabled) { /* * This LSA must have flushed before due to ROUTER INFORMATION * status change. @@ -1044,14 +1044,14 @@ static void ospf_router_info_config_write_router(struct vty *vty) struct ri_pce_subtlv_neighbor *neighbor; struct in_addr tmp; - if (OspfRI.status == enable) { + if (OspfRI.enabled) { if (OspfRI.scope == OSPF_OPAQUE_AS_LSA) vty_out(vty, " router-info as\n"); else vty_out(vty, " router-info area %s\n", inet_ntoa(OspfRI.area_id)); - if (OspfRI.pce_info.status == enable) { + if (OspfRI.pce_info.enabled) { if (pce->pce_address.header.type != 0) vty_out(vty, " pce address %s\n", @@ -1112,7 +1112,7 @@ DEFUN (router_info, u_int8_t scope; - if (OspfRI.status == enable) + if (OspfRI.enabled) return CMD_SUCCESS; /* Check and get Area value if present */ @@ -1135,7 +1135,7 @@ DEFUN (router_info, return CMD_WARNING_CONFIG_FAILED; } - OspfRI.status = enable; + OspfRI.enabled = true; if (IS_DEBUG_OSPF_EVENT) zlog_debug("RI-> Router Information (%s flooding): OFF -> ON", @@ -1154,7 +1154,7 @@ DEFUN (router_info, initialize_params(&OspfRI); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) { + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) { zlog_debug ("RI-> Refresh LSA following configuration"); ospf_router_info_lsa_schedule (REFRESH_THIS_LSA); } else { @@ -1172,26 +1172,26 @@ DEFUN (no_router_info, "Disable the Router Information functionality\n") { - if (OspfRI.status == disable) + if (!OspfRI.enabled) return CMD_SUCCESS; if (IS_DEBUG_OSPF_EVENT) zlog_debug("RI-> Router Information: ON -> OFF"); - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(FLUSH_THIS_LSA); /* Unregister the callbacks */ ospf_router_info_unregister(); - OspfRI.status = disable; + OspfRI.enabled = false; return CMD_SUCCESS; } static int ospf_ri_enabled(struct vty *vty) { - if (OspfRI.status == enable) + if (OspfRI.enabled) return 1; if (vty) @@ -1226,7 +1226,7 @@ DEFUN (pce_address, set_pce_address(value, pi); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -1245,7 +1245,7 @@ DEFUN (no_pce_address, unset_param(&OspfRI.pce_info.pce_address.header); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1276,7 +1276,7 @@ DEFUN (pce_path_scope, set_pce_path_scope(scope, pi); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -1295,7 +1295,7 @@ DEFUN (no_pce_path_scope, unset_param(&OspfRI.pce_info.pce_address.header); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1334,7 +1334,7 @@ DEFUN (pce_domain, set_pce_domain(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1364,7 +1364,7 @@ DEFUN (no_pce_domain, unset_pce_domain(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1404,7 +1404,7 @@ DEFUN (pce_neigbhor, set_pce_neighbor(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1434,7 +1434,7 @@ DEFUN (no_pce_neighbor, unset_pce_neighbor(PCE_DOMAIN_TYPE_AS, as, pce); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1466,7 +1466,7 @@ DEFUN (pce_cap_flag, set_pce_cap_flag(cap, pce); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); } @@ -1484,7 +1484,7 @@ DEFUN (no_pce_cap_flag, unset_param(&OspfRI.pce_info.pce_cap_flag.header); /* Refresh RI LSA if already engaged */ - if CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED) + if (CHECK_FLAG(OspfRI.flags, RIFLG_LSA_ENGAGED)) ospf_router_info_lsa_schedule(REFRESH_THIS_LSA); return CMD_SUCCESS; @@ -1499,7 +1499,7 @@ DEFUN (show_ip_ospf_router_info, "Router Information\n") { - if (OspfRI.status == enable) { + if (OspfRI.enabled) { vty_out(vty, "--- Router Information parameters ---\n"); show_vty_router_cap(vty, &OspfRI.router_cap.header); } else { @@ -1525,7 +1525,7 @@ DEFUN (show_ip_opsf_router_info_pce, struct ri_pce_subtlv_domain *domain; struct ri_pce_subtlv_neighbor *neighbor; - if (OspfRI.status == enable) { + if (OspfRI.enabled) { vty_out(vty, "--- PCE parameters ---\n"); if (pce->pce_address.header.type != 0) diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index a982350e63..521844b9ea 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -108,7 +108,7 @@ int ospf_mpls_te_init(void) } memset(&OspfMplsTE, 0, sizeof(struct ospf_mpls_te)); - OspfMplsTE.status = disable; + OspfMplsTE.enabled = false; OspfMplsTE.inter_as = Off; OspfMplsTE.iflist = list_new(); OspfMplsTE.iflist->del = del_mpls_te_link; @@ -171,7 +171,7 @@ void ospf_mpls_te_term(void) ospf_delete_opaque_functab(OSPF_OPAQUE_AREA_LSA, OPAQUE_TYPE_TRAFFIC_ENGINEERING_LSA); - OspfMplsTE.status = disable; + OspfMplsTE.enabled = false; ospf_mpls_te_unregister(); OspfMplsTE.inter_as = Off; @@ -243,8 +243,8 @@ static void ospf_mpls_te_foreach_area(void (*func)(struct mpls_te_link *lp, continue; if ((area = lp->area) == NULL) continue; - if - CHECK_FLAG(lp->flags, LPFLG_LOOKUP_DONE) continue; + if (CHECK_FLAG(lp->flags, LPFLG_LOOKUP_DONE)) + continue; if (func != NULL) (*func)(lp, sched_opcode); @@ -937,20 +937,18 @@ void ospf_mpls_te_update_if(struct interface *ifp) /* Finally Re-Originate or Refresh Opaque LSA if MPLS_TE is * enabled */ - if (OspfMplsTE.status == enable) + if (OspfMplsTE.enabled) if (lp->area != NULL) { - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA); - else ospf_mpls_te_lsa_schedule( - lp, REORIGINATE_THIS_LSA); + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) + ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA); + else + ospf_mpls_te_lsa_schedule(lp, REORIGINATE_THIS_LSA); } } else { /* If MPLS TE is disable on this interface, flush LSA if it is * already engaged */ - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) + ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); else /* Reset Activity flag */ lp->flags = LPFLG_LSA_INACTIVE; @@ -1028,20 +1026,18 @@ static void ospf_mpls_te_ism_change(struct ospf_interface *oi, int old_state) != ntohs(lp->link_id.header.type) || ntohl(old_id.value.s_addr) != ntohl(lp->link_id.value.s_addr))) { - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA); - else ospf_mpls_te_lsa_schedule(lp, - REORIGINATE_THIS_LSA); + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) + ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA); + else + ospf_mpls_te_lsa_schedule(lp, REORIGINATE_THIS_LSA); } break; default: lp->link_type.header.type = htons(0); lp->link_id.header.type = htons(0); - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) + ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); break; } @@ -1268,7 +1264,7 @@ static int ospf_mpls_te_lsa_originate_area(void *arg) struct mpls_te_link *lp; int rc = -1; - if (OspfMplsTE.status == disable) { + if (!OspfMplsTE.enabled) { zlog_info( "ospf_mpls_te_lsa_originate_area: MPLS-TE is disabled now."); rc = 0; /* This is not an error case. */ @@ -1287,23 +1283,16 @@ static int ospf_mpls_te_lsa_originate_area(void *arg) if (!IPV4_ADDR_SAME(&lp->area->area_id, &area->area_id)) continue; - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - { - if - CHECK_FLAG(lp->flags, - LPFLG_LSA_FORCED_REFRESH) - { - UNSET_FLAG( - lp->flags, - LPFLG_LSA_FORCED_REFRESH); - zlog_warn( - "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate"); - ospf_mpls_te_lsa_schedule( - lp, REFRESH_THIS_LSA); - } - continue; + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) { + if (CHECK_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH)) { + UNSET_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH); + zlog_warn( + "OSPF MPLS-TE (ospf_mpls_te_lsa_originate_area): Refresh instead of Originate"); + ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA); } + continue; + } + if (!is_mandated_params_set(lp)) { zlog_warn( "ospf_mpls_te_lsa_originate_area: Link(%s) lacks some mandated MPLS-TE parameters.", @@ -1372,7 +1361,7 @@ static int ospf_mpls_te_lsa_originate_as(void *arg) struct mpls_te_link *lp; int rc = -1; - if ((OspfMplsTE.status == disable) + if ((!OspfMplsTE.enabled) || (OspfMplsTE.inter_as == Off)) { zlog_info( "ospf_mpls_te_lsa_originate_as: MPLS-TE Inter-AS is disabled for now."); @@ -1386,21 +1375,14 @@ static int ospf_mpls_te_lsa_originate_as(void *arg) || !IS_INTER_AS(lp->type)) continue; - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - { - if - CHECK_FLAG(lp->flags, - LPFLG_LSA_FORCED_REFRESH) - { - UNSET_FLAG( - lp->flags, - LPFLG_LSA_FORCED_REFRESH); - ospf_mpls_te_lsa_schedule( - lp, REFRESH_THIS_LSA); - } - continue; + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) { + if (CHECK_FLAG(lp->flags, LPFLG_LSA_FORCED_REFRESH)) { + UNSET_FLAG(lp->flags,LPFLG_LSA_FORCED_REFRESH); + ospf_mpls_te_lsa_schedule(lp, REFRESH_THIS_LSA); } + continue; + } + if (!is_mandated_params_set(lp)) { zlog_warn( "ospf_mpls_te_lsa_originate_as: Link(%s) lacks some mandated MPLS-TE parameters.", @@ -1436,7 +1418,7 @@ static struct ospf_lsa *ospf_mpls_te_lsa_refresh(struct ospf_lsa *lsa) struct ospf *top; struct ospf_lsa *new = NULL; - if (OspfMplsTE.status == disable) { + if (!OspfMplsTE.enabled) { /* * This LSA must have flushed before due to MPLS-TE status * change. @@ -2172,7 +2154,7 @@ static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa) static void ospf_mpls_te_config_write_router(struct vty *vty) { - if (OspfMplsTE.status == enable) { + if (OspfMplsTE.enabled) { vty_out(vty, " mpls-te on\n"); vty_out(vty, " mpls-te router-address %s\n", inet_ntoa(OspfMplsTE.router_addr.value)); @@ -2201,13 +2183,13 @@ DEFUN (ospf_mpls_te_on, struct listnode *node; struct mpls_te_link *lp; - if (OspfMplsTE.status == enable) + if (OspfMplsTE.enabled) return CMD_SUCCESS; if (IS_DEBUG_OSPF_EVENT) zlog_debug("MPLS-TE: OFF -> ON"); - OspfMplsTE.status = enable; + OspfMplsTE.enabled = true; /* Reoriginate RFC3630 & RFC6827 Links */ ospf_mpls_te_foreach_area(ospf_mpls_te_lsa_schedule, @@ -2237,18 +2219,17 @@ DEFUN (no_ospf_mpls_te, struct listnode *node, *nnode; struct mpls_te_link *lp; - if (OspfMplsTE.status == disable) + if (!OspfMplsTE.enabled) return CMD_SUCCESS; if (IS_DEBUG_OSPF_EVENT) zlog_debug("MPLS-TE: ON -> OFF"); - OspfMplsTE.status = disable; + OspfMplsTE.enabled = false; for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) - if - CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED) - ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); + if (CHECK_FLAG(lp->flags, LPFLG_LSA_ENGAGED)) + ospf_mpls_te_lsa_schedule(lp, FLUSH_THIS_LSA); return CMD_SUCCESS; } @@ -2279,7 +2260,7 @@ DEFUN (ospf_mpls_te_router_addr, set_mpls_te_router_addr(value); - if (OspfMplsTE.status == disable) + if (!OspfMplsTE.enabled) return CMD_SUCCESS; for (ALL_LIST_ELEMENTS(OspfMplsTE.iflist, node, nnode, lp)) { @@ -2318,7 +2299,7 @@ static int set_inter_as_mode(struct vty *vty, const char *mode_name, struct mpls_te_link *lp; int format; - if (OspfMplsTE.status == enable) { + if (OspfMplsTE.enabled) { /* Read and Check inter_as mode */ if (strcmp(mode_name, "as") == 0) @@ -2413,7 +2394,7 @@ DEFUN (no_ospf_mpls_te_inter_as, if (IS_DEBUG_OSPF_EVENT) zlog_debug("MPLS-TE: Inter-AS support OFF"); - if ((OspfMplsTE.status == enable) + if ((OspfMplsTE.enabled) && (OspfMplsTE.inter_as != Off)) { OspfMplsTE.inter_as = Off; /* Flush all Inter-AS LSA */ @@ -2438,7 +2419,7 @@ DEFUN (show_ip_ospf_mpls_te_router, "MPLS-TE information\n" "MPLS-TE Router parameters\n") { - if (OspfMplsTE.status == enable) { + if (OspfMplsTE.enabled) { vty_out(vty, "--- MPLS-TE router parameters ---\n"); if (ntohs(OspfMplsTE.router_addr.header.type) != 0) @@ -2454,7 +2435,7 @@ static void show_mpls_te_link_sub(struct vty *vty, struct interface *ifp) { struct mpls_te_link *lp; - if ((OspfMplsTE.status == enable) && HAS_LINK_PARAMS(ifp) + if ((OspfMplsTE.enabled) && HAS_LINK_PARAMS(ifp) && !if_is_loopback(ifp) && if_is_up(ifp) && ((lp = lookup_linkparams_by_ifp(ifp)) != NULL)) { /* Continue only if interface is not passive or support Inter-AS diff --git a/ospfd/ospf_te.h b/ospfd/ospf_te.h index e3a6114b4f..0134214510 100644 --- a/ospfd/ospf_te.h +++ b/ospfd/ospf_te.h @@ -337,7 +337,7 @@ struct te_link_subtlv { /* Following structure are internal use only. */ struct ospf_mpls_te { /* Status of MPLS-TE: enable or disbale */ - status_t status; + bool enabled; /* RFC5392 */ enum inter_as_mode inter_as; diff --git a/ospfd/ospfd.h b/ospfd/ospfd.h index 1876fad5fa..b49bbdc17d 100644 --- a/ospfd/ospfd.h +++ b/ospfd/ospfd.h @@ -84,9 +84,6 @@ struct ospf_external { struct route_table *external_info; }; -/* Status of various sub function e.g. TE */ -typedef enum _status_t {disable, enable} status_t; - /* OSPF master for system wide configuration and variables. */ struct ospf_master { /* OSPF instance. */ @@ -104,7 +101,7 @@ struct ospf_master { /* Various OSPF global configuration. */ u_char options; -#define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */ +#define OSPF_MASTER_SHUTDOWN (1 << 0) /* deferred-shutdown */ }; struct ospf_redist { From 0ae6124f4807560736ba3ad3b8ce3cb8085e03ce Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 27 Jul 2017 10:05:48 -0400 Subject: [PATCH 34/75] bgp rfapi: use route_table_init and _finish (fixes crash due to recent lib change) Signed-off-by: Lou Berger --- bgpd/rfapi/bgp_rfapi_cfg.c | 26 +++++++++++++------------- bgpd/rfapi/bgp_rfapi_cfg.h | 4 ++-- bgpd/rfapi/rfapi.c | 4 ++-- bgpd/rfapi/rfapi_import.c | 11 ++++++++--- bgpd/rfapi/rfapi_private.h | 2 +- 5 files changed, 26 insertions(+), 21 deletions(-) diff --git a/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index 8a93d3984e..4b55c20c1c 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -135,10 +135,10 @@ struct rfapi_nve_group_cfg *bgp_rfapi_cfg_match_group(struct rfapi_cfg *hc, switch (vn->family) { case AF_INET: - rt_vn = &(hc->nve_groups_vn[AFI_IP]); + rt_vn = hc->nve_groups_vn[AFI_IP]; break; case AF_INET6: - rt_vn = &(hc->nve_groups_vn[AFI_IP6]); + rt_vn = hc->nve_groups_vn[AFI_IP6]; break; default: return NULL; @@ -146,10 +146,10 @@ struct rfapi_nve_group_cfg *bgp_rfapi_cfg_match_group(struct rfapi_cfg *hc, switch (un->family) { case AF_INET: - rt_un = &(hc->nve_groups_un[AFI_IP]); + rt_un = hc->nve_groups_un[AFI_IP]; break; case AF_INET6: - rt_un = &(hc->nve_groups_un[AFI_IP6]); + rt_un = hc->nve_groups_un[AFI_IP6]; break; default: return NULL; @@ -2527,10 +2527,10 @@ DEFUN (vnc_nve_group_prefix, } if (argv[1]->arg[0] == 'u') { - rt = &(bgp->rfapi_cfg->nve_groups_un[afi]); + rt = bgp->rfapi_cfg->nve_groups_un[afi]; is_un_prefix = 1; } else { - rt = &(bgp->rfapi_cfg->nve_groups_vn[afi]); + rt = bgp->rfapi_cfg->nve_groups_vn[afi]; } rn = route_node_get(rt, &p); /* NB locks node */ @@ -3838,14 +3838,9 @@ struct rfapi_cfg *bgp_rfapi_cfg_new(struct rfapi_rfp_cfg *cfg) h->nve_groups_sequential = list_new(); assert(h->nve_groups_sequential); - for (afi = AFI_IP; afi < AFI_MAX; afi++) { - /* ugly, to deal with addition of delegates, part of 0.99.24.1 - * merge */ - h->nve_groups_vn[afi].delegate = - route_table_get_default_delegate(); - h->nve_groups_un[afi].delegate = - route_table_get_default_delegate(); + h->nve_groups_vn[afi] = route_table_init(); + h->nve_groups_un[afi] = route_table_init(); } h->default_response_lifetime = BGP_VNC_DEFAULT_RESPONSE_LIFETIME_DEFAULT; @@ -3885,6 +3880,7 @@ struct rfapi_cfg *bgp_rfapi_cfg_new(struct rfapi_rfp_cfg *cfg) void bgp_rfapi_cfg_destroy(struct bgp *bgp, struct rfapi_cfg *h) { + int afi; if (h == NULL) return; @@ -3901,6 +3897,10 @@ void bgp_rfapi_cfg_destroy(struct bgp *bgp, struct rfapi_cfg *h) ecommunity_free(&h->default_rt_import_list); if (h->default_rfp_cfg) XFREE(MTYPE_RFAPI_RFP_GROUP_CFG, h->default_rfp_cfg); + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + route_table_finish(h->nve_groups_vn[afi]); + route_table_finish(h->nve_groups_un[afi]); + } XFREE(MTYPE_RFAPI_CFG, h); } diff --git a/bgpd/rfapi/bgp_rfapi_cfg.h b/bgpd/rfapi/bgp_rfapi_cfg.h index d99aefa60d..a11b0992fa 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.h +++ b/bgpd/rfapi/bgp_rfapi_cfg.h @@ -135,8 +135,8 @@ struct rfapi_cfg { struct list *l2_groups; /* rfapi_l2_group_cfg list */ /* three views into the same collection of rfapi_nve_group_cfg */ struct list *nve_groups_sequential; - struct route_table nve_groups_vn[AFI_MAX]; - struct route_table nve_groups_un[AFI_MAX]; + struct route_table *nve_groups_vn[AFI_MAX]; + struct route_table *nve_groups_un[AFI_MAX]; /* * For Single VRF export to ordinary routing protocols. This is diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 3a2a608a7c..29c114d994 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -224,7 +224,7 @@ static int rfapi_find_node(struct bgp *bgp, struct rfapi_ip_addr *vn_addr, if ((rc = rfapiRaddr2Qprefix(un_addr, &p))) return rc; - rn = route_node_lookup(&h->un[afi], &p); + rn = route_node_lookup(h->un[afi], &p); if (!rn) return ENOENT; @@ -1415,7 +1415,7 @@ int rfapi_init_and_open(struct bgp *bgp, struct rfapi_descriptor *rfd, assert(afi_vn && afi_un); assert(!rfapiRaddr2Qprefix(&rfd->un_addr, &pfx_un)); - rn = route_node_get(&(h->un[afi_un]), &pfx_un); + rn = route_node_get(h->un[afi_un], &pfx_un); assert(rn); rfd->next = rn->info; rn->info = rfd; diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index d0379e1ef8..f156161ef9 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -4257,9 +4257,7 @@ struct rfapi *bgp_rfapi_new(struct bgp *bgp) h = (struct rfapi *)XCALLOC(MTYPE_RFAPI, sizeof(struct rfapi)); for (afi = AFI_IP; afi < AFI_MAX; afi++) { - /* ugly, to deal with addition of delegates, part of 0.99.24.1 - * merge */ - h->un[afi].delegate = route_table_get_default_delegate(); + h->un[afi] = route_table_init(); } /* @@ -4292,6 +4290,8 @@ struct rfapi *bgp_rfapi_new(struct bgp *bgp) void bgp_rfapi_destroy(struct bgp *bgp, struct rfapi *h) { + int afi; + if (bgp == NULL || h == NULL) return; @@ -4327,6 +4327,11 @@ void bgp_rfapi_destroy(struct bgp *bgp, struct rfapi *h) if (h->rfp != NULL) rfp_stop(h->rfp); + + for (afi = AFI_IP; afi < AFI_MAX; afi++) { + route_table_finish(h->un[afi]); + } + XFREE(MTYPE_RFAPI_IMPORTTABLE, h->it_ce); XFREE(MTYPE_RFAPI, h); } diff --git a/bgpd/rfapi/rfapi_private.h b/bgpd/rfapi/rfapi_private.h index e7a3e5aae3..73c9312a64 100644 --- a/bgpd/rfapi/rfapi_private.h +++ b/bgpd/rfapi/rfapi_private.h @@ -171,7 +171,7 @@ struct rfapi_global_stats { * check vn address to get exact match. */ struct rfapi { - struct route_table un[AFI_MAX]; + struct route_table *un[AFI_MAX]; struct rfapi_import_table *imports; /* IPv4, IPv6 */ struct list descriptors; /* debug & resolve-nve imports */ From 8b2a6222e84c7f0aed5fd6c3e83ed4b33ec9db91 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Jul 2017 11:08:40 -0400 Subject: [PATCH 35/75] lib: Remove expansion of hash table The hash code has the idea of stopping expanding the hash table when certain criteria are set. With the recent addition of `show hashtable` we can now see that when we have a full internet feed we've stopped expanding the table at 1k buckets. This results in some serious performance issues at scale. Since we now have the ability to see the statistics on a hash table, let's allow it to expand. Doing so on a full feed showed this: before: Hash table | Buckets Entries Empty LF SD FLF SD ----------------------+---------------------------------------------------------------- route table hash | 1024 1187579 0% 1159.75 34.06 1159.75 35.08 route table hash | 32768 76208 10% 2.33 2.80 2.58 4.03 route table hash | 1024 1187572 0% 1159.74 34.06 1159.74 35.08 route table hash | 2048 76205 0% 37.21 6.13 37.21 7.29 Showing hash table statistics for BGP ------------------------------------- Hash table | Buckets Entries Empty LF SD FLF SD ---------------------+-------------------------------------------------------------- BGP Attributes | 131072 251229 15% 1.92 2.48 2.25 3.33 route table hash | 4096 1187572 0% 289.93 17.03 289.93 17.87 route table hash | 32768 76205 10% 2.33 2.90 2.58 4.21 After: Hash table | Buckets Entries Empty LF SD FLF SD ----------------------+-------------------------------------------------------- route table hash | 1048576 1187349 32% 1.13 2.57 1.67 3.16 route table hash | 32768 76195 10% 2.33 2.81 2.58 4.03 route table hash | 1048576 1187342 32% 1.13 2.58 1.67 3.16 route table hash | 32768 76192 10% 2.33 2.68 2.58 3.81 Showing hash table statistics for BGP ------------------------------------- Hash table | Buckets Entries Empty LF SD FLF SD ---------------------+-------------------------------------------------------- BGP Attributes | 131072 251222 15% 1.92 2.64 2.25 3.58 route table hash | 1048576 1187342 32% 1.13 2.52 1.67 3.07 route table hash | 32768 76192 10% 2.33 2.86 2.58 4.12 We should see some significant performance improvements across the board for full feeds. Signed-off-by: Donald Sharp --- lib/hash.c | 21 ++------------------- lib/hash.h | 3 --- 2 files changed, 2 insertions(+), 22 deletions(-) diff --git a/lib/hash.c b/lib/hash.c index 7adbd908d8..a7714f1569 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -49,7 +49,6 @@ struct hash *hash_create_size(unsigned int size, hash->index = XCALLOC(MTYPE_HASH_INDEX, sizeof(struct hash_backet *) * size); hash->size = size; - hash->no_expand = 0; hash->hash_key = hash_key; hash->hash_cmp = hash_cmp; hash->count = 0; @@ -91,7 +90,7 @@ void *hash_alloc_intern(void *arg) /* Expand hash if the chain length exceeds the threshold. */ static void hash_expand(struct hash *hash) { - unsigned int i, new_size, losers; + unsigned int i, new_size; struct hash_backet *hb, *hbnext, **new_index; new_size = hash->size * 2; @@ -128,22 +127,6 @@ static void hash_expand(struct hash *hash) XFREE(MTYPE_HASH_INDEX, hash->index); hash->size = new_size; hash->index = new_index; - - /* Ideally, new index should have chains half as long as the original. - * If expansion didn't help, then not worth expanding again, - * the problem is the hash function. */ - losers = 0; - for (i = 0; i < hash->size; i++) { - unsigned int len = hash->index[i] ? hash->index[i]->len : 0; - - if (len > HASH_THRESHOLD / 2) - ++losers; - if (len >= HASH_THRESHOLD) - hash->no_expand = 1; - } - - if (losers > hash->count / 2) - hash->no_expand = 1; } /* Lookup and return hash backet in hash. If there is no @@ -173,7 +156,7 @@ void *hash_get(struct hash *hash, void *data, void *(*alloc_func)(void *)) if (newdata == NULL) return NULL; - if (len > HASH_THRESHOLD && !hash->no_expand) { + if (len > HASH_THRESHOLD) { hash_expand(hash); index = key & (hash->size - 1); } diff --git a/lib/hash.h b/lib/hash.h index ec3766eaaa..6ce29f0426 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -64,9 +64,6 @@ struct hash { /* Hash table size. Must be power of 2 */ unsigned int size; - /* If expansion failed. */ - int no_expand; - /* Key make function. */ unsigned int (*hash_key)(void *); From 2f5078856eee87a6b9306e6298c1fbe15066fec0 Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 27 Jul 2017 11:01:36 -0400 Subject: [PATCH 36/75] bgpd rfapi: fix breakage introduced in refactoring Signed-off-by: Lou Berger --- bgpd/bgp_attr.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 79d215f1bd..ef32b9cf92 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -2039,7 +2039,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ } #endif } - stlv_last->next = tlv; + stlv_last = tlv; } if (BGP_ATTR_ENCAP == type) { From e7038ddec68ab012c2d7b7e8ed70cd99b46fc27d Mon Sep 17 00:00:00 2001 From: Lou Berger Date: Thu, 27 Jul 2017 13:06:49 -0400 Subject: [PATCH 37/75] bgpd rfapi: use afi_t Signed-off-by: Lou Berger --- bgpd/rfapi/bgp_rfapi_cfg.c | 9 +++++---- bgpd/rfapi/rfapi.c | 4 ++-- bgpd/rfapi/rfapi_import.c | 4 ++-- 3 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bgpd/rfapi/bgp_rfapi_cfg.c b/bgpd/rfapi/bgp_rfapi_cfg.c index 4b55c20c1c..c8e2dd9525 100644 --- a/bgpd/rfapi/bgp_rfapi_cfg.c +++ b/bgpd/rfapi/bgp_rfapi_cfg.c @@ -2503,7 +2503,7 @@ DEFUN (vnc_nve_group_prefix, VTY_DECLVAR_CONTEXT(bgp, bgp); VTY_DECLVAR_CONTEXT_SUB(rfapi_nve_group_cfg, rfg); struct prefix p; - int afi; + afi_t afi; struct route_table *rt; struct route_node *rn; int is_un_prefix = 0; @@ -3830,7 +3830,7 @@ void bgp_rfapi_cfg_init(void) struct rfapi_cfg *bgp_rfapi_cfg_new(struct rfapi_rfp_cfg *cfg) { struct rfapi_cfg *h; - int afi; + afi_t afi; h = (struct rfapi_cfg *)XCALLOC(MTYPE_RFAPI_CFG, sizeof(struct rfapi_cfg)); @@ -3880,7 +3880,7 @@ struct rfapi_cfg *bgp_rfapi_cfg_new(struct rfapi_rfp_cfg *cfg) void bgp_rfapi_cfg_destroy(struct bgp *bgp, struct rfapi_cfg *h) { - int afi; + afi_t afi; if (h == NULL) return; @@ -4571,7 +4571,8 @@ int bgp_rfapi_cfg_write(struct vty *vty, struct bgp *bgp) void bgp_rfapi_show_summary(struct bgp *bgp, struct vty *vty) { struct rfapi_cfg *hc = bgp->rfapi_cfg; - int afi, type, redist = 0; + afi_t afi; + int type, redist = 0; char tmp[40]; if (hc == NULL) return; diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 29c114d994..ab71eda126 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -205,7 +205,7 @@ static int rfapi_find_node(struct bgp *bgp, struct rfapi_ip_addr *vn_addr, struct prefix p; struct route_node *rn; int rc; - int afi; + afi_t afi; if (!bgp) { return ENXIO; @@ -2367,7 +2367,7 @@ int rfapi_register(void *handle, struct rfapi_ip_prefix *prefix, struct prefix p; struct prefix *pfx_ip = NULL; struct prefix_rd prd; - int afi; + afi_t afi; struct prefix pfx_mac_buf; struct prefix *pfx_mac = NULL; struct prefix pfx_vn_buf; diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index f156161ef9..0bbbe12cce 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -4248,7 +4248,7 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp, struct rfapi *bgp_rfapi_new(struct bgp *bgp) { struct rfapi *h; - int afi; + afi_t afi; struct rfapi_rfp_cfg *cfg = NULL; struct rfapi_rfp_cb_methods *cbm = NULL; @@ -4290,7 +4290,7 @@ struct rfapi *bgp_rfapi_new(struct bgp *bgp) void bgp_rfapi_destroy(struct bgp *bgp, struct rfapi *h) { - int afi; + afi_t afi; if (bgp == NULL || h == NULL) return; From c652f6f633c3c64acccf0438cdb6ab268afd0f0c Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Thu, 27 Jul 2017 15:03:31 -0400 Subject: [PATCH 38/75] lib: correct some node name typos Signed-off-by: Quentin Young --- lib/command.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/lib/command.c b/lib/command.c index 4690a36be0..7781fb02e6 100644 --- a/lib/command.c +++ b/lib/command.c @@ -56,7 +56,7 @@ const char *node_names[] = { "service", // SERVICE_NODE, "debug", // DEBUG_NODE, "vrf debug", // VRF_DEBUG_NODE, - "vmc debug", // DEBUG_VNC_NODE, + "vnc debug", // DEBUG_VNC_NODE, "aaa", // AAA_NODE, "keychain", // KEYCHAIN_NODE, "leychain key", // KEYCHAIN_KEY_NODE, @@ -71,7 +71,7 @@ const char *node_names[] = { "eigrp", // EIGRP_NODE, "bgp", // BGP_NODE, "bgp vpnv4", // BGP_VPNV4_NODE, - "bgp vpnv56", // BGP_VPNV6_NODE, + "bgp vpnv6", // BGP_VPNV6_NODE, "bgp ipv4 unicast", // BGP_IPV4_NODE, "bgp ipv4 multicast", // BGP_IPV4M_NODE, "bgp ipv4 labeled unicast", // BGP_IPV4L_NODE, @@ -102,7 +102,7 @@ const char *node_names[] = { "ipv4 prefix list", // PREFIX_NODE, "ipv6 access list", // ACCESS_IPV6_NODE, "ipv6 prefix list", // PREFIX_IPV6_NODE, - "AS list", // AS_LIST_NODE, + "as list", // AS_LIST_NODE, "community list", // COMMUNITY_LIST_NODE, "routemap", // RMAP_NODE, "smux", // SMUX_NODE, From 68bfcc05391eb4887c659cdd69fd878d565d9fa1 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Thu, 27 Jul 2017 18:19:31 -0400 Subject: [PATCH 39/75] ospf6d: New version of GCC with new warnings GCC 7.1.1 returned warnings about buffer sizes not being big enough to handle the full string that could be generated. Signed-off-by: Donald Sharp --- ospf6d/ospf6_intra.c | 2 +- ospf6d/ospf6_lsa.c | 2 +- ospf6d/ospf6_neighbor.c | 6 +++--- ospf6d/ospf6_route.c | 4 ++-- 4 files changed, 7 insertions(+), 7 deletions(-) diff --git a/ospf6d/ospf6_intra.c b/ospf6d/ospf6_intra.c index 7c5c44fca7..015776a174 100644 --- a/ospf6d/ospf6_intra.c +++ b/ospf6d/ospf6_intra.c @@ -1437,7 +1437,7 @@ static void ospf6_brouter_debug_print(struct ospf6_route *brouter) char brouter_name[16]; char area_name[16]; char destination[64]; - char installed[16], changed[16]; + char installed[64], changed[64]; struct timeval now, res; char id[16], adv_router[16]; char capa[16], options[16]; diff --git a/ospf6d/ospf6_lsa.c b/ospf6d/ospf6_lsa.c index 329060a16f..e1a431ea07 100644 --- a/ospf6d/ospf6_lsa.c +++ b/ospf6d/ospf6_lsa.c @@ -467,7 +467,7 @@ void ospf6_lsa_show(struct vty *vty, struct ospf6_lsa *lsa) char adv_router[64], id[64]; struct ospf6_lsa_handler *handler; struct timeval now, res; - char duration[16]; + char duration[64]; assert(lsa && lsa->header); diff --git a/ospf6d/ospf6_neighbor.c b/ospf6d/ospf6_neighbor.c index a21da07483..bde89f54a6 100644 --- a/ospf6d/ospf6_neighbor.c +++ b/ospf6d/ospf6_neighbor.c @@ -582,10 +582,10 @@ int inactivity_timer(struct thread *thread) static void ospf6_neighbor_show(struct vty *vty, struct ospf6_neighbor *on) { char router_id[16]; - char duration[16]; + char duration[64]; struct timeval res; char nstate[16]; - char deadtime[16]; + char deadtime[64]; long h, m, s; /* Router-ID (Name) */ @@ -640,7 +640,7 @@ static void ospf6_neighbor_show_drchoice(struct vty *vty, { char router_id[16]; char drouter[16], bdrouter[16]; - char duration[16]; + char duration[64]; struct timeval now, res; /* diff --git a/ospf6d/ospf6_route.c b/ospf6d/ospf6_route.c index 5e8fd0e15d..e0e9fc9449 100644 --- a/ospf6d/ospf6_route.c +++ b/ospf6d/ospf6_route.c @@ -945,7 +945,7 @@ void ospf6_route_show(struct vty *vty, struct ospf6_route *route) { int i; char destination[PREFIX2STR_BUFFER], nexthop[64]; - char duration[16]; + char duration[64]; const char *ifname; struct timeval now, res; struct listnode *node; @@ -991,7 +991,7 @@ void ospf6_route_show_detail(struct vty *vty, struct ospf6_route *route) char destination[PREFIX2STR_BUFFER], nexthop[64]; char area_id[16], id[16], adv_router[16], capa[16], options[16]; struct timeval now, res; - char duration[16]; + char duration[64]; struct listnode *node; struct ospf6_nexthop *nh; From 2f8aa457e0a30e20a1af84257892006e24490d85 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 10:44:55 -0300 Subject: [PATCH 40/75] zebra: use curly braces for optional arguments of static routes This way the optional arguments can be provided in any order. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 32 ++++++++++++++++---------------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 50fa69d224..5cbb55ebd2 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -389,7 +389,7 @@ static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], /* Static route configuration. */ DEFUN (ip_route, ip_route_cmd, - "ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" @@ -418,7 +418,7 @@ DEFUN (ip_route, DEFUN (ip_route_flags, ip_route_flags_cmd, - "ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" @@ -446,7 +446,7 @@ DEFUN (ip_route_flags, /* Mask as A.B.C.D format. */ DEFUN_HIDDEN (ip_route_mask, ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix\n" @@ -477,7 +477,7 @@ DEFUN_HIDDEN (ip_route_mask, DEFUN_HIDDEN (ip_route_mask_flags, ip_route_mask_flags_cmd, - "ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IP destination prefix\n" @@ -507,7 +507,7 @@ DEFUN_HIDDEN (ip_route_mask_flags, DEFUN (no_ip_route, no_ip_route_cmd, - "no ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -537,7 +537,7 @@ DEFUN (no_ip_route, DEFUN (no_ip_route_flags, no_ip_route_flags_cmd, - "no ip route A.B.C.D/M [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -564,7 +564,7 @@ DEFUN (no_ip_route_flags, DEFUN_HIDDEN (no_ip_route_mask, no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -596,7 +596,7 @@ DEFUN_HIDDEN (no_ip_route_mask, DEFUN_HIDDEN (no_ip_route_mask_flags, no_ip_route_mask_flags_cmd, - "no ip route A.B.C.D A.B.C.D [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2172,7 +2172,7 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, DEFUN (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2212,7 +2212,7 @@ DEFUN (ipv6_route, DEFUN (ipv6_route_flags, ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2257,7 +2257,7 @@ DEFUN (ipv6_route_flags, DEFUN (ipv6_route_ifname, ipv6_route_ifname_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2299,7 +2299,7 @@ DEFUN (ipv6_route_ifname, DEFUN (ipv6_route_ifname_flags, ipv6_route_ifname_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2347,7 +2347,7 @@ DEFUN (ipv6_route_ifname_flags, DEFUN (no_ipv6_route, no_ipv6_route_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2388,7 +2388,7 @@ DEFUN (no_ipv6_route, DEFUN (no_ipv6_route_flags, no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2434,7 +2434,7 @@ DEFUN (no_ipv6_route_flags, DEFUN (no_ipv6_route_ifname, no_ipv6_route_ifname_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" @@ -2477,7 +2477,7 @@ DEFUN (no_ipv6_route_ifname, DEFUN (no_ipv6_route_ifname_flags, no_ipv6_route_ifname_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [tag (1-4294967295)] [(1-255)] [vrf NAME]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" From 8bcbf3b0d705b532c17670ad508930414213e953 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 11:05:15 -0300 Subject: [PATCH 41/75] zebra: remove weird blackhole/reject ipv6 static routes This is the v6 counterpart of commit 74d263466b9. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 160 +++++++++------------------------------------- 1 file changed, 31 insertions(+), 129 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 5cbb55ebd2..7e492ad6b2 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -2045,10 +2045,6 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, if (tag_str) tag = strtoul(tag_str, NULL, 10); - /* When gateway is valid IPv6 addrees, then gate is treated as - nexthop address other case gate is treated as interface name. */ - ret = inet_pton(AF_INET6, gate_str, &gate_addr); - /* VRF id */ zvrf = zebra_vrf_lookup_by_name(vrf_id_str); @@ -2125,6 +2121,23 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, } } + if (gate_str == NULL) { + if (add_cmd) + static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, + NULL, ifindex, ifname, flag, tag, + distance, zvrf, &snh_label); + else + static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, + src_p, NULL, ifindex, tag, distance, + zvrf, &snh_label); + + return CMD_SUCCESS; + } + + /* When gateway is valid IPv6 addrees, then gate is treated as + nexthop address other case gate is treated as interface name. */ + ret = inet_pton(AF_INET6, gate_str, &gate_addr); + if (ifname) { /* When ifname is specified. It must be come with gateway address. */ @@ -2212,14 +2225,12 @@ DEFUN (ipv6_route, DEFUN (ipv6_route_flags, ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" @@ -2228,21 +2239,18 @@ DEFUN (ipv6_route_flags, VRF_CMD_HELP_STR) { int idx_ipv6_prefixlen = 2; - int idx_ipv6_ifname; int idx_reject_blackhole; int idx_curr; char *src, *tag, *distance, *vrf; if (strmatch(argv[3]->text, "from")) { src = argv[4]->arg; - idx_ipv6_ifname = 5; - idx_reject_blackhole = 6; - idx_curr = 7; + idx_reject_blackhole = 5; + idx_curr = 6; } else { src = NULL; - idx_ipv6_ifname = 3; - idx_reject_blackhole = 4; - idx_curr = 5; + idx_reject_blackhole = 3; + idx_curr = 4; } tag = distance = vrf = NULL; @@ -2250,9 +2258,8 @@ DEFUN (ipv6_route_flags, &vrf, NULL); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (ipv6_route_ifname, @@ -2297,54 +2304,6 @@ DEFUN (ipv6_route_ifname, NULL, tag, distance, vrf, NULL); } -DEFUN (ipv6_route_ifname_flags, - ipv6_route_ifname_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 2; - int idx_ipv6; - int idx_interface; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_ipv6 = 5; - idx_interface = 6; - idx_reject_blackhole = 7; - idx_curr = 8; - } else { - src = NULL; - idx_ipv6 = 3; - idx_interface = 4; - idx_reject_blackhole = 5; - idx_curr = 6; - } - - tag = distance = vrf = NULL; - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); -} - DEFUN (no_ipv6_route, no_ipv6_route_cmd, "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -2388,15 +2347,13 @@ DEFUN (no_ipv6_route, DEFUN (no_ipv6_route_flags, no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", NO_STR IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" @@ -2405,21 +2362,18 @@ DEFUN (no_ipv6_route_flags, VRF_CMD_HELP_STR) { int idx_ipv6_prefixlen = 3; - int idx_ipv6_ifname; int idx_reject_blackhole; int idx_curr; char *src, *tag, *distance, *vrf; if (strmatch(argv[4]->text, "from")) { src = argv[5]->arg; - idx_ipv6_ifname = 6; - idx_reject_blackhole = 7; - idx_curr = 8; + idx_reject_blackhole = 6; + idx_curr = 7; } else { src = NULL; - idx_ipv6_ifname = 4; - idx_reject_blackhole = 5; - idx_curr = 6; + idx_reject_blackhole = 4; + idx_curr = 5; } tag = distance = vrf = NULL; @@ -2427,9 +2381,8 @@ DEFUN (no_ipv6_route_flags, &vrf, NULL); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (no_ipv6_route_ifname, @@ -2475,55 +2428,6 @@ DEFUN (no_ipv6_route_ifname, NULL, tag, distance, vrf, NULL); } -DEFUN (no_ipv6_route_ifname_flags, - no_ipv6_route_ifname_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6; - int idx_interface; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_ipv6 = 6; - idx_interface = 7; - idx_reject_blackhole = 8; - idx_curr = 9; - } else { - src = NULL; - idx_ipv6 = 4; - idx_interface = 5; - idx_reject_blackhole = 6; - idx_curr = 7; - } - - tag = distance = vrf = NULL; - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); -} - DEFUN (show_ipv6_route, show_ipv6_route_cmd, "show ipv6 [vrf NAME] [tag (1-4294967295)|X:X::X:X/M longer-prefixes|" FRR_IP6_REDIST_STR_ZEBRA "] [json]", @@ -3413,11 +3317,9 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &ipv6_route_cmd); install_element(CONFIG_NODE, &ipv6_route_flags_cmd); install_element(CONFIG_NODE, &ipv6_route_ifname_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_flags_cmd); install_element(CONFIG_NODE, &no_ipv6_route_cmd); install_element(CONFIG_NODE, &no_ipv6_route_flags_cmd); install_element(CONFIG_NODE, &no_ipv6_route_ifname_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_flags_cmd); install_element(CONFIG_NODE, &ip_nht_default_route_cmd); install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd); install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd); From d97c792e9f525e360d3f39fd5c73e3ab4bd908c3 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 12:16:41 -0300 Subject: [PATCH 42/75] zebra: remove redundant DEFUNs for labeled static routes Signed-off-by: Renato Westphal --- zebra/zebra_mpls_vty.c | 599 +---------------------------------------- zebra/zebra_static.h | 12 - zebra/zebra_vty.c | 126 +++++---- 3 files changed, 63 insertions(+), 674 deletions(-) diff --git a/zebra/zebra_mpls_vty.c b/zebra/zebra_mpls_vty.c index ed34831f8f..9d100bb7d0 100644 --- a/zebra/zebra_mpls_vty.c +++ b/zebra/zebra_mpls_vty.c @@ -283,570 +283,6 @@ DEFUN (no_mpls_label_bind, return zebra_mpls_bind(vty, 0, argv[4]->arg, NULL); } -/* Static route configuration. */ -DEFUN (ip_route_label, - ip_route_label_cmd, - "ip route A.B.C.D/M label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, NULL, NULL, NULL, - argv[5]->arg); -} - -DEFUN (ip_route_tag_label, - ip_route_tag_label_cmd, - "ip route A.B.C.D/M tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, argv[5]->arg, NULL, NULL, - argv[7]->arg); -} - -/* Mask as A.B.C.D format. */ -DEFUN (ip_route_mask_label, - ip_route_mask_label_cmd, - "ip route A.B.C.D A.B.C.D label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, NULL, NULL, - NULL, argv[6]->arg); -} - -DEFUN (ip_route_mask_tag_label, - ip_route_mask_tag_label_cmd, - "ip route A.B.C.D A.B.C.D tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg, - NULL, NULL, argv[8]->arg); -} - -/* Distance option value. */ -DEFUN (ip_route_distance_label, - ip_route_distance_label_cmd, - "ip route A.B.C.D/M (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, NULL, argv[4]->arg, NULL, - argv[6]->arg); -} - -DEFUN (ip_route_tag_distance_label, - ip_route_tag_distance_label_cmd, - "ip route A.B.C.D/M tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, NULL, - argv[3]->arg, NULL, argv[5]->arg, argv[6]->arg, - NULL, argv[8]->arg); -} - -DEFUN (ip_route_mask_distance_label, - ip_route_mask_distance_label_cmd, - "ip route A.B.C.D A.B.C.D (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, NULL, - argv[5]->arg, NULL, argv[7]->arg); -} - -DEFUN (ip_route_mask_tag_distance_label, - ip_route_mask_tag_distance_label_cmd, - "ip route A.B.C.D A.B.C.D tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[2]->arg, - argv[3]->arg, argv[4]->arg, NULL, argv[6]->arg, - argv[7]->arg, NULL, argv[9]->arg); -} - -DEFUN (no_ip_route_label, - no_ip_route_label_cmd, - "no ip route A.B.C.D/M label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, NULL, NULL, NULL, - argv[6]->arg); -} - -DEFUN (no_ip_route_tag_label, - no_ip_route_tag_label_cmd, - "no ip route A.B.C.D/M tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, argv[6]->arg, NULL, NULL, - argv[8]->arg); -} - -DEFUN (no_ip_route_mask_label, - no_ip_route_mask_label_cmd, - "no ip route A.B.C.D A.B.C.D label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, NULL, NULL, - NULL, argv[7]->arg); -} - -DEFUN (no_ip_route_mask_tag_label, - no_ip_route_mask_tag_label_cmd, - "no ip route A.B.C.D A.B.C.D tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg, - NULL, NULL, argv[9]->arg); -} - -DEFUN (no_ip_route_distance_label, - no_ip_route_distance_label_cmd, - "no ip route A.B.C.D/M (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, NULL, argv[5]->arg, NULL, - argv[7]->arg); -} - -DEFUN (no_ip_route_tag_distance_label, - no_ip_route_tag_distance_label_cmd, - "no ip route A.B.C.D/M tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, NULL, - argv[4]->arg, NULL, argv[6]->arg, argv[7]->arg, - NULL, argv[9]->arg); -} - -DEFUN (no_ip_route_mask_distance_label, - no_ip_route_mask_distance_label_cmd, - "no ip route A.B.C.D A.B.C.D (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, NULL, - argv[6]->arg, NULL, argv[8]->arg); -} - -DEFUN (no_ip_route_mask_tag_distance_label, - no_ip_route_mask_tag_distance_label_cmd, - "no ip route A.B.C.D A.B.C.D tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - MPLS_LABEL_HELPSTR) -{ - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[3]->arg, - argv[4]->arg, argv[5]->arg, NULL, argv[7]->arg, - argv[8]->arg, NULL, argv[10]->arg); -} - -DEFUN (ipv6_route_label, - ipv6_route_label_cmd, - "ipv6 route X:X::X:X/M label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, NULL, NULL, NULL, argv[5]->arg); -} - -DEFUN (ipv6_route_tag_label, - ipv6_route_tag_label_cmd, - "ipv6 route X:X::X:X/M tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, argv[5]->arg, NULL, NULL, argv[7]->arg); -} - -DEFUN (ipv6_route_ifname_label, - ipv6_route_ifname_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, NULL, NULL, NULL, - argv[6]->arg); -} -DEFUN (ipv6_route_ifname_tag_label, - ipv6_route_ifname_tag_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, argv[6]->arg, NULL, NULL, - argv[8]->arg); -} - -DEFUN (ipv6_route_pref_label, - ipv6_route_pref_label_cmd, - "ipv6 route X:X::X:X/M (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, NULL, argv[4]->arg, NULL, argv[6]->arg); -} - -DEFUN (ipv6_route_pref_tag_label, - ipv6_route_pref_tag_label_cmd, - "ipv6 route X:X::X:X/M tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, NULL, - NULL, argv[5]->arg, argv[6]->arg, NULL, - argv[8]->arg); -} - -DEFUN (ipv6_route_ifname_pref_label, - ipv6_route_ifname_pref_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, NULL, argv[5]->arg, NULL, - argv[7]->arg); -} - -DEFUN (ipv6_route_ifname_pref_tag_label, - ipv6_route_ifname_pref_tag_label_cmd, - "ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 1, argv[2]->arg, NULL, argv[3]->arg, - argv[4]->arg, NULL, argv[6]->arg, argv[7]->arg, - NULL, argv[9]->arg); -} - -DEFUN (no_ipv6_route_label, - no_ipv6_route_label_cmd, - "no ipv6 route X:X::X:X/M label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, NULL, NULL, NULL, argv[6]->arg); -} - -DEFUN (no_ipv6_route_tag_label, - no_ipv6_route_tag_label_cmd, - "no ipv6 route X:X::X:X/M tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, argv[6]->arg, NULL, NULL, argv[8]->arg); -} - -DEFUN (no_ipv6_route_ifname_label, - no_ipv6_route_ifname_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, NULL, NULL, NULL, - argv[7]->arg); -} - -DEFUN (no_ipv6_route_ifname_tag_label, - no_ipv6_route_ifname_tag_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, argv[7]->arg, NULL, NULL, - argv[9]->arg); -} - -DEFUN (no_ipv6_route_pref_label, - no_ipv6_route_pref_label_cmd, - "no ipv6 route X:X::X:X/M (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, NULL, argv[5]->arg, NULL, argv[7]->arg); -} - -DEFUN (no_ipv6_route_pref_tag_label, - no_ipv6_route_pref_tag_label_cmd, - "no ipv6 route X:X::X:X/M tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, NULL, - NULL, argv[6]->arg, argv[7]->arg, NULL, - argv[9]->arg); -} - -DEFUN (no_ipv6_route_ifname_pref_label, - no_ipv6_route_ifname_pref_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, NULL, argv[6]->arg, NULL, - argv[8]->arg); -} - -DEFUN (no_ipv6_route_ifname_pref_tag_label, - no_ipv6_route_ifname_pref_tag_label_cmd, - "no ipv6 route X:X::X:X/M X:X::X:X INTERFACE tag (1-4294967295) (1-255) label WORD", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - MPLS_LABEL_HELPSTR) -{ - return static_ipv6_func(vty, 0, argv[3]->arg, NULL, argv[4]->arg, - argv[5]->arg, NULL, argv[7]->arg, argv[8]->arg, - NULL, argv[10]->arg); -} - /* MPLS LSP configuration write function. */ static int zebra_mpls_config(struct vty *vty) { @@ -1024,44 +460,11 @@ void zebra_mpls_vty_init(void) install_node(&mpls_node, zebra_mpls_config); - install_element(CONFIG_NODE, &ip_route_label_cmd); - install_element(CONFIG_NODE, &ip_route_tag_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_tag_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_tag_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_tag_label_cmd); - install_element(CONFIG_NODE, &ip_route_distance_label_cmd); - install_element(CONFIG_NODE, &ip_route_tag_distance_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_distance_label_cmd); - install_element(CONFIG_NODE, &ip_route_mask_tag_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_tag_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_distance_label_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_tag_distance_label_cmd); - - install_element(CONFIG_NODE, &ipv6_route_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_pref_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_pref_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_pref_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_pref_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_tag_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_tag_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_pref_tag_label_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_pref_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_pref_tag_label_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_pref_tag_label_cmd); - install_element(CONFIG_NODE, &mpls_transit_lsp_cmd); install_element(CONFIG_NODE, &no_mpls_transit_lsp_cmd); install_element(CONFIG_NODE, &no_mpls_transit_lsp_out_label_cmd); install_element(CONFIG_NODE, &no_mpls_transit_lsp_all_cmd); + install_element(CONFIG_NODE, &mpls_label_bind_cmd); install_element(CONFIG_NODE, &no_mpls_label_bind_cmd); diff --git a/zebra/zebra_static.h b/zebra/zebra_static.h index 91ac0a33c2..dff799a9aa 100644 --- a/zebra/zebra_static.h +++ b/zebra/zebra_static.h @@ -100,16 +100,4 @@ extern int static_delete_route(afi_t, safi_t safi, u_char type, struct zebra_vrf *zvrf, struct static_nh_label *snh_label); -int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, - const char *dest_str, const char *mask_str, - const char *gate_str, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str); - -int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, - const char *src_str, const char *gate_str, - const char *ifname, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str); - #endif diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 7e492ad6b2..941090171a 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -61,11 +61,11 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, #define CMD_VNI_RANGE "(1-16777215)" /* General function for static route. */ -int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, - const char *dest_str, const char *mask_str, - const char *gate_str, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) +static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, + const char *dest_str, const char *mask_str, + const char *gate_str, const char *flag_str, + const char *tag_str, const char *distance_str, + const char *vrf_id_str, const char *label_str) { int ret; u_char distance; @@ -362,7 +362,11 @@ static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], char **distance, char **vrf, char **labels) { + *tag = NULL; *distance = NULL; + *vrf = NULL; + if (labels) + *labels = NULL; while (idx_curr < argc) { if (strmatch(argv[idx_curr]->text, "tag")) { if (tag) @@ -389,7 +393,7 @@ static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], /* Static route configuration. */ DEFUN (ip_route, ip_route_cmd, - "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" @@ -399,21 +403,21 @@ DEFUN (ip_route, "Set tag for this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 2; int idx_ipv4_ifname_null = 3; int idx_curr = 4; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (ip_route_flags, @@ -434,7 +438,6 @@ DEFUN (ip_route_flags, int idx_curr = 4; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -446,7 +449,7 @@ DEFUN (ip_route_flags, /* Mask as A.B.C.D format. */ DEFUN_HIDDEN (ip_route_mask, ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IP destination prefix\n" @@ -457,22 +460,22 @@ DEFUN_HIDDEN (ip_route_mask, "Set tag for this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4 = 2; int idx_ipv4_2 = 3; int idx_ipv4_ifname_null = 4; int idx_curr = 5; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN_HIDDEN (ip_route_mask_flags, @@ -495,7 +498,6 @@ DEFUN_HIDDEN (ip_route_mask_flags, int idx_curr = 5; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -507,7 +509,7 @@ DEFUN_HIDDEN (ip_route_mask_flags, DEFUN (no_ip_route, no_ip_route_cmd, - "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -518,21 +520,21 @@ DEFUN (no_ip_route, "Tag of this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 3; int idx_ipv4_ifname_null = 4; int idx_curr = 5; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4_prefixlen]->arg, NULL, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (no_ip_route_flags, @@ -553,7 +555,6 @@ DEFUN (no_ip_route_flags, int idx_curr = 5; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -564,7 +565,7 @@ DEFUN (no_ip_route_flags, DEFUN_HIDDEN (no_ip_route_mask, no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -576,22 +577,22 @@ DEFUN_HIDDEN (no_ip_route_mask, "Tag of this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv4 = 3; int idx_ipv4_2 = 4; int idx_ipv4_ifname_null = 5; int idx_curr = 6; - char *tag, *distance, *vrf; + char *tag, *distance, *vrf, *label; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN_HIDDEN (no_ip_route_mask_flags, @@ -614,7 +615,6 @@ DEFUN_HIDDEN (no_ip_route_mask_flags, int idx_curr = 6; char *tag, *distance, *vrf; - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -1997,11 +1997,11 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, } /* General fucntion for IPv6 static route. */ -int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, - const char *src_str, const char *gate_str, - const char *ifname, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) +static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, + const char *src_str, const char *gate_str, + const char *ifname, const char *flag_str, + const char *tag_str, const char *distance_str, + const char *vrf_id_str, const char *label_str) { int ret; u_char distance; @@ -2185,7 +2185,7 @@ int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, DEFUN (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2197,12 +2197,13 @@ DEFUN (ipv6_route, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 2; int idx_ipv6_ifname; int idx_curr; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[3]->text, "from")) { src = argv[4]->arg; @@ -2214,13 +2215,12 @@ DEFUN (ipv6_route, idx_curr = 4; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (ipv6_route_flags, @@ -2253,7 +2253,6 @@ DEFUN (ipv6_route_flags, idx_curr = 4; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -2264,7 +2263,7 @@ DEFUN (ipv6_route_flags, DEFUN (ipv6_route_ifname, ipv6_route_ifname_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", IP_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" @@ -2275,13 +2274,14 @@ DEFUN (ipv6_route_ifname, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 2; int idx_ipv6 = 3; int idx_interface = 4; int idx_curr = 5; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[3]->text, "from")) { src = argv[4]->arg; @@ -2295,18 +2295,17 @@ DEFUN (ipv6_route_ifname, idx_curr = 5; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, NULL); + NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route, no_ipv6_route_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -2319,12 +2318,13 @@ DEFUN (no_ipv6_route, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 3; int idx_ipv6_ifname; int idx_curr; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[4]->text, "from")) { src = argv[5]->arg; @@ -2336,13 +2336,12 @@ DEFUN (no_ipv6_route, idx_curr = 5; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, NULL); + distance, vrf, label); } DEFUN (no_ipv6_route_flags, @@ -2376,7 +2375,6 @@ DEFUN (no_ipv6_route_flags, idx_curr = 5; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); @@ -2387,7 +2385,7 @@ DEFUN (no_ipv6_route_flags, DEFUN (no_ipv6_route_ifname, no_ipv6_route_ifname_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME}]", + "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", NO_STR IP_STR "Establish static routes\n" @@ -2399,13 +2397,14 @@ DEFUN (no_ipv6_route_ifname, "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) { int idx_ipv6_prefixlen = 3; int idx_ipv6; int idx_interface; int idx_curr; - char *src, *tag, *distance, *vrf; + char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[4]->text, "from")) { src = argv[5]->arg; @@ -2419,13 +2418,12 @@ DEFUN (no_ipv6_route_ifname, idx_curr = 6; } - tag = distance = vrf = NULL; zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); + &vrf, &label); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, NULL); + NULL, tag, distance, vrf, label); } DEFUN (show_ipv6_route, From 33df4bb219d6c5b972877434c57fa85543dc8a5e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 18:01:12 -0300 Subject: [PATCH 43/75] zebra: accept static v6 routes with non-existent nexthop interfaces We don't need to enforce that the interface exists because the route can be activated later once the interface becomes available. We already do this for IPv4 routes and IPv6 routes with both a nexthop address and a nexthop interface. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 941090171a..a79d8d71b4 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -2151,9 +2151,9 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, if (!ifp) { vty_out(vty, "%% Malformed Interface name %s\n", ifname); - return CMD_WARNING_CONFIG_FAILED; - } - ifindex = ifp->ifindex; + ifindex = IFINDEX_DELETED; + } else + ifindex = ifp->ifindex; } else { if (ret == 1) { type = STATIC_IPV6_GATEWAY; From c6cef20ba9d317792a9742c3efb728f4aa766dad Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 15:52:52 -0300 Subject: [PATCH 44/75] zebra: refactor zebra_static_ipv4() and static_ipv6_func() This is a preliminary step to join both functions into one later. The main idea here is to make these functions have separate arguments for the nexthop address and the nexthop interface, and adjust the call sites appropriately. Having an argument that could be a nexthop address OR a nexthop interface was making the code very hard to follow. With this simplification, a lot of code duplication was removed and now both functions look very similar. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 244 ++++++++++++++++++++++++---------------------- 1 file changed, 126 insertions(+), 118 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index a79d8d71b4..c5cdad890a 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -63,21 +63,22 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, /* General function for static route. */ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, const char *dest_str, const char *mask_str, - const char *gate_str, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) + const char *gate_str, const char *ifname, + const char *flag_str, const char *tag_str, + const char *distance_str, const char *vrf_id_str, + const char *label_str) { int ret; u_char distance; struct prefix p; struct in_addr gate; + struct in_addr *gatep = NULL; struct in_addr mask; u_char flag = 0; route_tag_t tag = 0; struct zebra_vrf *zvrf = NULL; unsigned int ifindex = 0; - const char *ifname = NULL; - u_char type = STATIC_BLACKHOLE; + u_char type; struct static_nh_label snh_label; memset(&snh_label, 0, sizeof(struct static_nh_label)); @@ -149,22 +150,15 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } /* Null0 static route. */ - if ((gate_str != NULL) - && (strncasecmp(gate_str, "Null0", strlen(gate_str)) == 0)) { + if ((ifname != NULL) + && (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) { if (flag_str) { vty_out(vty, "%% can not have flag %s with Null0\n", flag_str); return CMD_WARNING_CONFIG_FAILED; } - if (add_cmd) - static_add_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, ifname, ZEBRA_FLAG_BLACKHOLE, - tag, distance, zvrf, &snh_label); - else - static_delete_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, tag, distance, zvrf, - &snh_label); - return CMD_SUCCESS; + SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); + ifname = NULL; } /* Route flags */ @@ -184,44 +178,44 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } } - if (gate_str == NULL) { - if (add_cmd) - static_add_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, ifname, flag, tag, distance, - zvrf, &snh_label); - else - static_delete_route(AFI_IP, safi, type, &p, NULL, NULL, - ifindex, tag, distance, zvrf, - &snh_label); - - return CMD_SUCCESS; + if (gate_str) { + if (inet_pton(AF_INET, gate_str, &gate) != 1) { + vty_out(vty, "%% Malformed nexthop address %s\n", + gate_str); + return CMD_WARNING_CONFIG_FAILED; + } + gatep = &gate; } - /* When gateway is A.B.C.D format, gate is treated as nexthop - address other case gate is treated as interface name. */ - ret = inet_aton(gate_str, &gate); - if (!ret) { - struct interface *ifp = - if_lookup_by_name(gate_str, zvrf_id(zvrf)); + if (ifname) { + struct interface *ifp; + ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); if (!ifp) { - vty_out(vty, "%% Unknown interface: %s\n", gate_str); + vty_out(vty, "%% Malformed Interface name %s\n", + ifname); ifindex = IFINDEX_DELETED; } else ifindex = ifp->ifindex; - ifname = gate_str; + } + + if (gate_str == NULL && ifname == NULL) + type = STATIC_BLACKHOLE; + else if (gate_str && ifname) + /* TODO: not implemented yet */ + return CMD_WARNING_CONFIG_FAILED; + else if (ifname) type = STATIC_IFINDEX; - } else + else type = STATIC_IPV4_GATEWAY; if (add_cmd) static_add_route(AFI_IP, safi, type, &p, NULL, - ifindex ? NULL : (union g_addr *)&gate, - ifindex, ifname, flag, tag, distance, zvrf, - &snh_label); + (union g_addr *)gatep, ifindex, ifname, flag, + tag, distance, zvrf, &snh_label); else static_delete_route(AFI_IP, safi, type, &p, NULL, - ifindex ? NULL : (union g_addr *)&gate, - ifindex, tag, distance, zvrf, &snh_label); + (union g_addr *)gatep, ifindex, tag, + distance, zvrf, &snh_label); return CMD_SUCCESS; } @@ -238,11 +232,17 @@ DEFUN (ip_mroute_dist, "Distance\n") { char *destprefix = argv[2]->arg; - char *nexthop = argv[3]->arg; + char *gate = NULL; + char *ifname = NULL; char *distance = (argc == 5) ? argv[4]->arg : NULL; + if (argv[3]->type == IPV4_TKN) + gate = argv[3]->arg; + else + ifname = argv[3]->arg; + return zebra_static_ipv4(vty, SAFI_MULTICAST, 1, destprefix, NULL, - nexthop, NULL, NULL, distance, NULL, NULL); + gate, ifname, NULL, NULL, distance, NULL, NULL); } DEFUN (no_ip_mroute_dist, @@ -257,11 +257,17 @@ DEFUN (no_ip_mroute_dist, "Distance\n") { char *destprefix = argv[3]->arg; - char *nexthop = argv[4]->arg; + char *gate = NULL; + char *ifname = NULL; char *distance = (argc == 6) ? argv[5]->arg : NULL; + if (argv[4]->type == IPV4_TKN) + gate = argv[4]->arg; + else + ifname = argv[4]->arg; + return zebra_static_ipv4(vty, SAFI_MULTICAST, 0, destprefix, NULL, - nexthop, NULL, NULL, distance, NULL, NULL); + gate, ifname, NULL, NULL, distance, NULL, NULL); } DEFUN (ip_multicast_mode, @@ -407,17 +413,22 @@ DEFUN (ip_route, MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 2; - int idx_ipv4_ifname_null = 3; int idx_curr = 4; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[3]->type == IPV4_TKN) + gate = argv[3]->arg; + else + ifname = argv[3]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + argv[idx_ipv4_prefixlen]->arg, NULL, gate, + ifname, NULL, tag, distance, vrf, label); } DEFUN (ip_route_flags, @@ -443,7 +454,7 @@ DEFUN (ip_route_flags, return zebra_static_ipv4( vty, SAFI_UNICAST, 1, argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); + NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); } /* Mask as A.B.C.D format. */ @@ -465,17 +476,22 @@ DEFUN_HIDDEN (ip_route_mask, { int idx_ipv4 = 2; int idx_ipv4_2 = 3; - int idx_ipv4_ifname_null = 4; int idx_curr = 5; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[4]->type == IPV4_TKN) + gate = argv[4]->arg; + else + ifname = argv[4]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN_HIDDEN (ip_route_mask_flags, @@ -502,7 +518,7 @@ DEFUN_HIDDEN (ip_route_mask_flags, &vrf, NULL); return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, + argv[idx_ipv4_2]->arg, NULL, NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); } @@ -524,17 +540,22 @@ DEFUN (no_ip_route, MPLS_LABEL_HELPSTR) { int idx_ipv4_prefixlen = 3; - int idx_ipv4_ifname_null = 4; int idx_curr = 5; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[4]->type == IPV4_TKN) + gate = argv[4]->arg; + else + ifname = argv[4]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4_prefixlen]->arg, NULL, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (no_ip_route_flags, @@ -560,7 +581,7 @@ DEFUN (no_ip_route_flags, return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, tag, distance, vrf, NULL); + NULL, NULL, tag, distance, vrf, NULL); } DEFUN_HIDDEN (no_ip_route_mask, @@ -582,17 +603,22 @@ DEFUN_HIDDEN (no_ip_route_mask, { int idx_ipv4 = 3; int idx_ipv4_2 = 4; - int idx_ipv4_ifname_null = 5; int idx_curr = 6; + char *gate = NULL; + char *ifname = NULL; char *tag, *distance, *vrf, *label; + if (argv[5]->type == IPV4_TKN) + gate = argv[5]->arg; + else + ifname = argv[5]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - argv[idx_ipv4_ifname_null]->arg, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN_HIDDEN (no_ip_route_mask_flags, @@ -619,7 +645,7 @@ DEFUN_HIDDEN (no_ip_route_mask_flags, &vrf, NULL); return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, NULL, tag, + argv[idx_ipv4_2]->arg, NULL, NULL, NULL, tag, distance, vrf, NULL); } @@ -2009,11 +2035,10 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, struct prefix_ipv6 *src_p = NULL; struct in6_addr *gate = NULL; struct in6_addr gate_addr; - u_char type = STATIC_BLACKHOLE; + u_char type; u_char flag = 0; route_tag_t tag = 0; unsigned int ifindex = 0; - struct interface *ifp = NULL; struct zebra_vrf *zvrf; struct static_nh_label snh_label; @@ -2085,23 +2110,15 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, } /* Null0 static route. */ - if ((gate_str != NULL) - && (strncasecmp(gate_str, "Null0", strlen(gate_str)) == 0)) { + if ((ifname != NULL) + && (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) { if (flag_str) { vty_out(vty, "%% can not have flag %s with Null0\n", flag_str); return CMD_WARNING_CONFIG_FAILED; } - if (add_cmd) - static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - NULL, ifindex, ifname, - ZEBRA_FLAG_BLACKHOLE, tag, distance, - zvrf, &snh_label); - else - static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, - src_p, NULL, ifindex, tag, distance, - zvrf, &snh_label); - return CMD_SUCCESS; + SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); + ifname = NULL; } /* Route flags */ @@ -2121,32 +2138,17 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, } } - if (gate_str == NULL) { - if (add_cmd) - static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - NULL, ifindex, ifname, flag, tag, - distance, zvrf, &snh_label); - else - static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, - src_p, NULL, ifindex, tag, distance, - zvrf, &snh_label); - - return CMD_SUCCESS; - } - - /* When gateway is valid IPv6 addrees, then gate is treated as - nexthop address other case gate is treated as interface name. */ - ret = inet_pton(AF_INET6, gate_str, &gate_addr); - - if (ifname) { - /* When ifname is specified. It must be come with gateway - address. */ - if (ret != 1) { - vty_out(vty, "%% Malformed address\n"); + if (gate_str) { + if (inet_pton(AF_INET6, gate_str, &gate_addr) != 1) { + vty_out(vty, "%% Malformed nexthop address %s\n", + gate_str); return CMD_WARNING_CONFIG_FAILED; } - type = STATIC_IPV6_GATEWAY_IFINDEX; gate = &gate_addr; + } + + if (ifname) { + struct interface *ifp; ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); if (!ifp) { vty_out(vty, "%% Malformed Interface name %s\n", @@ -2154,23 +2156,17 @@ static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, ifindex = IFINDEX_DELETED; } else ifindex = ifp->ifindex; - } else { - if (ret == 1) { - type = STATIC_IPV6_GATEWAY; - gate = &gate_addr; - } else { - type = STATIC_IFINDEX; - ifp = if_lookup_by_name(gate_str, zvrf_id(zvrf)); - if (!ifp) { - vty_out(vty, "%% Malformed Interface name %s\n", - gate_str); - ifindex = IFINDEX_DELETED; - } else - ifindex = ifp->ifindex; - ifname = gate_str; - } } + if (gate_str == NULL && ifname == NULL) + type = STATIC_BLACKHOLE; + else if (gate_str && ifname) + type = STATIC_IPV6_GATEWAY_IFINDEX; + else if (ifname) + type = STATIC_IFINDEX; + else + type = STATIC_IPV6_GATEWAY; + if (add_cmd) static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, (union g_addr *)gate, ifindex, ifname, flag, @@ -2203,6 +2199,8 @@ DEFUN (ipv6_route, int idx_ipv6_prefixlen = 2; int idx_ipv6_ifname; int idx_curr; + char *gate = NULL; + char *ifname = NULL; char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[3]->text, "from")) { @@ -2215,12 +2213,16 @@ DEFUN (ipv6_route, idx_curr = 4; } + if (argv[idx_ipv6_ifname]->type == IPV6_TKN) + gate = argv[idx_ipv6_ifname]->arg; + else + ifname = argv[idx_ipv6_ifname]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (ipv6_route_flags, @@ -2324,6 +2326,8 @@ DEFUN (no_ipv6_route, int idx_ipv6_prefixlen = 3; int idx_ipv6_ifname; int idx_curr; + char *gate = NULL; + char *ifname = NULL; char *src, *tag, *distance, *vrf, *label; if (strmatch(argv[4]->text, "from")) { @@ -2336,12 +2340,16 @@ DEFUN (no_ipv6_route, idx_curr = 5; } + if (argv[idx_ipv6_ifname]->type == IPV6_TKN) + gate = argv[idx_ipv6_ifname]->arg; + else + ifname = argv[idx_ipv6_ifname]->arg; + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6_ifname]->arg, NULL, NULL, tag, - distance, vrf, label); + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route_flags, From 599186ad970b50d689f719dbb8cf527df0089d01 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 18:57:37 -0300 Subject: [PATCH 45/75] zebra: allow fully specified static ipv4 routes Fully specified routes are useful when you need to ensure that the nexthop address is reachable through the specified interface. Addresses Issue #641. Signed-off-by: Renato Westphal --- zebra/zebra_static.c | 27 +++++++-- zebra/zebra_static.h | 6 +- zebra/zebra_vty.c | 140 ++++++++++++++++++++++++++++++++++++++++--- 3 files changed, 156 insertions(+), 17 deletions(-) diff --git a/zebra/zebra_static.c b/zebra/zebra_static.c index ae32395161..6cebae997c 100644 --- a/zebra/zebra_static.c +++ b/zebra/zebra_static.c @@ -81,6 +81,10 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p, nh_p.u.prefix4 = si->addr.ipv4; zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; + case STATIC_IPV4_GATEWAY_IFINDEX: + nexthop = route_entry_nexthop_ipv4_ifindex_add( + re, &si->addr.ipv4, NULL, si->ifindex); + break; case STATIC_IFINDEX: nexthop = route_entry_nexthop_ifindex_add(re, si->ifindex); @@ -152,6 +156,10 @@ void static_install_route(afi_t afi, safi_t safi, struct prefix *p, nh_p.u.prefix4 = si->addr.ipv4; zebra_register_rnh_static_nh(si->vrf_id, &nh_p, rn); break; + case STATIC_IPV4_GATEWAY_IFINDEX: + nexthop = route_entry_nexthop_ipv4_ifindex_add( + re, &si->addr.ipv4, NULL, si->ifindex); + break; case STATIC_IFINDEX: nexthop = route_entry_nexthop_ifindex_add(re, si->ifindex); @@ -216,6 +224,11 @@ static int static_nexthop_same(struct nexthop *nexthop, struct static_route *si) && si->type == STATIC_IPV4_GATEWAY && IPV4_ADDR_SAME(&nexthop->gate.ipv4, &si->addr.ipv4)) return 1; + else if (nexthop->type == NEXTHOP_TYPE_IPV4_IFINDEX + && si->type == STATIC_IPV4_GATEWAY_IFINDEX + && IPV4_ADDR_SAME(&nexthop->gate.ipv4, &si->addr.ipv4) + && nexthop->ifindex == si->ifindex) + return 1; else if (nexthop->type == NEXTHOP_TYPE_IFINDEX && si->type == STATIC_IFINDEX && nexthop->ifindex == si->ifindex) @@ -361,12 +374,17 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, if (!stable) return -1; - if (!gate && (type == STATIC_IPV4_GATEWAY || type == STATIC_IPV6_GATEWAY - || type == STATIC_IPV6_GATEWAY_IFINDEX)) + if (!gate + && (type == STATIC_IPV4_GATEWAY + || type == STATIC_IPV4_GATEWAY_IFINDEX + || type == STATIC_IPV6_GATEWAY + || type == STATIC_IPV6_GATEWAY_IFINDEX)) return -1; if (!ifindex - && (type == STATIC_IFINDEX || type == STATIC_IPV6_GATEWAY_IFINDEX)) + && (type == STATIC_IFINDEX + || type == STATIC_IPV4_GATEWAY_IFINDEX + || type == STATIC_IPV6_GATEWAY_IFINDEX)) return -1; /* Lookup static route prefix. */ @@ -411,11 +429,10 @@ int static_add_route(afi_t afi, safi_t safi, u_char type, struct prefix *p, switch (type) { case STATIC_IPV4_GATEWAY: + case STATIC_IPV4_GATEWAY_IFINDEX: si->addr.ipv4 = gate->ipv4; break; case STATIC_IPV6_GATEWAY: - si->addr.ipv6 = gate->ipv6; - break; case STATIC_IPV6_GATEWAY_IFINDEX: si->addr.ipv6 = gate->ipv6; break; diff --git a/zebra/zebra_static.h b/zebra/zebra_static.h index dff799a9aa..885774895f 100644 --- a/zebra/zebra_static.h +++ b/zebra/zebra_static.h @@ -32,6 +32,7 @@ struct static_nh_label { typedef enum { STATIC_IFINDEX, STATIC_IPV4_GATEWAY, + STATIC_IPV4_GATEWAY_IFINDEX, STATIC_BLACKHOLE, STATIC_IPV6_GATEWAY, STATIC_IPV6_GATEWAY_IFINDEX, @@ -57,11 +58,6 @@ struct static_route { /* * Nexthop value. - * - * Under IPv4 addr and ifindex are - * used independentyly. - * STATIC_IPV4_GATEWAY uses addr - * STATIC_IFINDEX uses ifindex */ union g_addr addr; ifindex_t ifindex; diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index c5cdad890a..96f9221698 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -201,8 +201,7 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, if (gate_str == NULL && ifname == NULL) type = STATIC_BLACKHOLE; else if (gate_str && ifname) - /* TODO: not implemented yet */ - return CMD_WARNING_CONFIG_FAILED; + type = STATIC_IPV4_GATEWAY_IFINDEX; else if (ifname) type = STATIC_IFINDEX; else @@ -457,6 +456,34 @@ DEFUN (ip_route_flags, NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); } +DEFUN (ip_route_ifname, + ip_route_ifname_cmd, + "ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + IP_STR + "Establish static routes\n" + "IP destination prefix (e.g. 10.0.0.0/8)\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4_prefixlen = 2; + int idx_curr = 5; + char *gate = argv[3]->arg; + char *ifname = argv[4]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, gate, + ifname, NULL, tag, distance, vrf, label); +} + /* Mask as A.B.C.D format. */ DEFUN_HIDDEN (ip_route_mask, ip_route_mask_cmd, @@ -494,6 +521,36 @@ DEFUN_HIDDEN (ip_route_mask, gate, ifname, NULL, tag, distance, vrf, label); } +DEFUN_HIDDEN (ip_route_mask_ifname, + ip_route_mask_ifname_cmd, + "ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Set tag for this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4 = 2; + int idx_ipv4_2 = 3; + int idx_curr = 6; + char *gate = argv[4]->arg; + char *ifname = argv[5]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, + argv[idx_ipv4_2]->arg, + gate, ifname, NULL, tag, distance, vrf, label); +} + DEFUN_HIDDEN (ip_route_mask_flags, ip_route_mask_flags_cmd, "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -558,6 +615,35 @@ DEFUN (no_ip_route, gate, ifname, NULL, tag, distance, vrf, label); } +DEFUN (no_ip_route_ifname, + no_ip_route_ifname_cmd, + "no ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + NO_STR + IP_STR + "Establish static routes\n" + "IP destination prefix (e.g. 10.0.0.0/8)\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Tag of this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4_prefixlen = 3; + int idx_curr = 6; + char *gate = argv[4]->arg; + char *ifname = argv[5]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, + gate, ifname, NULL, tag, distance, vrf, label); +} + DEFUN (no_ip_route_flags, no_ip_route_flags_cmd, "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -621,6 +707,37 @@ DEFUN_HIDDEN (no_ip_route_mask, gate, ifname, NULL, tag, distance, vrf, label); } +DEFUN_HIDDEN (no_ip_route_mask_ifname, + no_ip_route_mask_ifname_cmd, + "no ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + NO_STR + IP_STR + "Establish static routes\n" + "IP destination prefix\n" + "IP destination prefix mask\n" + "IP gateway address\n" + "IP gateway interface name\n" + "Tag of this route\n" + "Tag value\n" + "Distance value for this route\n" + VRF_CMD_HELP_STR + MPLS_LABEL_HELPSTR) +{ + int idx_ipv4 = 3; + int idx_ipv4_2 = 4; + int idx_curr = 7; + char *gate = argv[5]->arg; + char *ifname = argv[6]->arg; + char *tag, *distance, *vrf, *label; + + zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, + &vrf, &label); + + return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, + argv[idx_ipv4_2]->arg, + gate, ifname, NULL, tag, distance, vrf, label); +} + DEFUN_HIDDEN (no_ip_route_mask_flags, no_ip_route_mask_flags_cmd, "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", @@ -1970,6 +2087,14 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, else vty_out(vty, " Null0"); break; + case STATIC_IPV4_GATEWAY_IFINDEX: + vty_out(vty, " %s %s", + inet_ntop(AF_INET, + &si->addr.ipv4, buf, + sizeof buf), + ifindex2ifname(si->ifindex, + si->vrf_id)); + break; case STATIC_IPV6_GATEWAY_IFINDEX: vty_out(vty, " %s %s", inet_ntop(AF_INET6, @@ -3288,11 +3413,17 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &ip_multicast_mode_cmd); install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd); install_element(CONFIG_NODE, &ip_route_cmd); + install_element(CONFIG_NODE, &ip_route_ifname_cmd); install_element(CONFIG_NODE, &ip_route_flags_cmd); install_element(CONFIG_NODE, &ip_route_mask_cmd); + install_element(CONFIG_NODE, &ip_route_mask_ifname_cmd); install_element(CONFIG_NODE, &ip_route_mask_flags_cmd); install_element(CONFIG_NODE, &no_ip_route_cmd); + install_element(CONFIG_NODE, &no_ip_route_flags_cmd); + install_element(CONFIG_NODE, &no_ip_route_ifname_cmd); install_element(CONFIG_NODE, &no_ip_route_mask_cmd); + install_element(CONFIG_NODE, &no_ip_route_mask_flags_cmd); + install_element(CONFIG_NODE, &no_ip_route_mask_ifname_cmd); install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd); install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); @@ -3310,11 +3441,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_ip_rpf_cmd); install_element(VIEW_NODE, &show_ip_rpf_addr_cmd); - /* Commands for VRF */ - - install_element(CONFIG_NODE, &no_ip_route_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_flags_cmd); - install_element(VIEW_NODE, &show_ip_route_vrf_all_addr_cmd); install_element(VIEW_NODE, &show_ip_route_vrf_all_prefix_cmd); install_element(VIEW_NODE, &show_ip_route_vrf_all_summary_cmd); From 1d3f0eff598c4798ecf2efd486596e2ade78f6b3 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 19:58:45 -0300 Subject: [PATCH 46/75] zebra: unify the ipv4/ipv6 static route functions Addresses Issue #655. Signed-off-by: Renato Westphal --- zebra/zebra_vty.c | 373 ++++++++++++++++------------------------------ 1 file changed, 129 insertions(+), 244 deletions(-) diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 96f9221698..446bcc49eb 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -61,41 +61,59 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, #define CMD_VNI_RANGE "(1-16777215)" /* General function for static route. */ -static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, - const char *dest_str, const char *mask_str, - const char *gate_str, const char *ifname, - const char *flag_str, const char *tag_str, - const char *distance_str, const char *vrf_id_str, - const char *label_str) +static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, + int add_cmd, const char *dest_str, + const char *mask_str, const char *src_str, + const char *gate_str, const char *ifname, + const char *flag_str, const char *tag_str, + const char *distance_str, const char *vrf_id_str, + const char *label_str) { int ret; u_char distance; - struct prefix p; - struct in_addr gate; - struct in_addr *gatep = NULL; + struct prefix p, src; + struct prefix_ipv6 *src_p = NULL; + union g_addr gate; + union g_addr *gatep = NULL; struct in_addr mask; u_char flag = 0; route_tag_t tag = 0; - struct zebra_vrf *zvrf = NULL; + struct zebra_vrf *zvrf; unsigned int ifindex = 0; u_char type; struct static_nh_label snh_label; - memset(&snh_label, 0, sizeof(struct static_nh_label)); ret = str2prefix(dest_str, &p); if (ret <= 0) { vty_out(vty, "%% Malformed address\n"); return CMD_WARNING_CONFIG_FAILED; } - /* Cisco like mask notation. */ - if (mask_str) { - ret = inet_aton(mask_str, &mask); - if (ret == 0) { - vty_out(vty, "%% Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; + switch (afi) { + case AFI_IP: + /* Cisco like mask notation. */ + if (mask_str) { + ret = inet_aton(mask_str, &mask); + if (ret == 0) { + vty_out(vty, "%% Malformed address\n"); + return CMD_WARNING_CONFIG_FAILED; + } + p.prefixlen = ip_masklen(mask); } - p.prefixlen = ip_masklen(mask); + break; + case AFI_IP6: + /* srcdest routing */ + if (src_str) { + ret = str2prefix(src_str, &src); + if (ret <= 0 || src.family != AF_INET6) { + vty_out(vty, "%% Malformed source address\n"); + return CMD_WARNING_CONFIG_FAILED; + } + src_p = (struct prefix_ipv6 *)&src; + } + break; + default: + break; } /* Apply mask for given prefix. */ @@ -120,6 +138,7 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } /* Labels */ + memset(&snh_label, 0, sizeof(struct static_nh_label)); if (label_str) { if (!mpls_enabled) { vty_out(vty, @@ -179,7 +198,7 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, } if (gate_str) { - if (inet_pton(AF_INET, gate_str, &gate) != 1) { + if (inet_pton(afi2family(afi), gate_str, &gate) != 1) { vty_out(vty, "%% Malformed nexthop address %s\n", gate_str); return CMD_WARNING_CONFIG_FAILED; @@ -200,21 +219,26 @@ static int zebra_static_ipv4(struct vty *vty, safi_t safi, int add_cmd, if (gate_str == NULL && ifname == NULL) type = STATIC_BLACKHOLE; - else if (gate_str && ifname) - type = STATIC_IPV4_GATEWAY_IFINDEX; - else if (ifname) + else if (gate_str && ifname) { + if (afi == AFI_IP) + type = STATIC_IPV4_GATEWAY_IFINDEX; + else + type = STATIC_IPV6_GATEWAY_IFINDEX; + } else if (ifname) type = STATIC_IFINDEX; - else - type = STATIC_IPV4_GATEWAY; + else { + if (afi == AFI_IP) + type = STATIC_IPV4_GATEWAY; + else + type = STATIC_IPV6_GATEWAY; + } if (add_cmd) - static_add_route(AFI_IP, safi, type, &p, NULL, - (union g_addr *)gatep, ifindex, ifname, flag, - tag, distance, zvrf, &snh_label); + static_add_route(afi, safi, type, &p, src_p, gatep, ifindex, + ifname, flag, tag, distance, zvrf, &snh_label); else - static_delete_route(AFI_IP, safi, type, &p, NULL, - (union g_addr *)gatep, ifindex, tag, - distance, zvrf, &snh_label); + static_delete_route(afi, safi, type, &p, src_p, gatep, ifindex, + tag, distance, zvrf, &snh_label); return CMD_SUCCESS; } @@ -240,8 +264,9 @@ DEFUN (ip_mroute_dist, else ifname = argv[3]->arg; - return zebra_static_ipv4(vty, SAFI_MULTICAST, 1, destprefix, NULL, - gate, ifname, NULL, NULL, distance, NULL, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 1, destprefix, + NULL, NULL, gate, ifname, NULL, NULL, distance, + NULL, NULL); } DEFUN (no_ip_mroute_dist, @@ -265,8 +290,9 @@ DEFUN (no_ip_mroute_dist, else ifname = argv[4]->arg; - return zebra_static_ipv4(vty, SAFI_MULTICAST, 0, destprefix, NULL, - gate, ifname, NULL, NULL, distance, NULL, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 0, destprefix, + NULL, NULL, gate, ifname, NULL, NULL, distance, + NULL, NULL); } DEFUN (ip_multicast_mode, @@ -425,9 +451,9 @@ DEFUN (ip_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, gate, - ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (ip_route_flags, @@ -451,9 +477,10 @@ DEFUN (ip_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4( - vty, SAFI_UNICAST, 1, argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, argv[idx_reject_blackhole]->arg, tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (ip_route_ifname, @@ -479,9 +506,9 @@ DEFUN (ip_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, gate, - ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, label); } /* Mask as A.B.C.D format. */ @@ -516,9 +543,10 @@ DEFUN_HIDDEN (ip_route_mask, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (ip_route_mask_ifname, @@ -546,9 +574,10 @@ DEFUN_HIDDEN (ip_route_mask_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (ip_route_mask_flags, @@ -574,10 +603,11 @@ DEFUN_HIDDEN (ip_route_mask_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4(vty, SAFI_UNICAST, 1, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, NULL, - argv[idx_reject_blackhole]->arg, tag, distance, - vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, NULL, NULL, + argv[idx_reject_blackhole]->arg, tag, + distance, vrf, NULL); } DEFUN (no_ip_route, @@ -610,9 +640,10 @@ DEFUN (no_ip_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN (no_ip_route_ifname, @@ -639,9 +670,10 @@ DEFUN (no_ip_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN (no_ip_route_flags, @@ -665,9 +697,9 @@ DEFUN (no_ip_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, NULL, tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4_prefixlen]->arg, NULL, NULL, + NULL, NULL, NULL, tag, distance, vrf, NULL); } DEFUN_HIDDEN (no_ip_route_mask, @@ -702,9 +734,10 @@ DEFUN_HIDDEN (no_ip_route_mask, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (no_ip_route_mask_ifname, @@ -733,9 +766,10 @@ DEFUN_HIDDEN (no_ip_route_mask_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN_HIDDEN (no_ip_route_mask_flags, @@ -761,9 +795,10 @@ DEFUN_HIDDEN (no_ip_route_mask_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return zebra_static_ipv4(vty, SAFI_UNICAST, 0, argv[idx_ipv4]->arg, - argv[idx_ipv4_2]->arg, NULL, NULL, NULL, tag, - distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, + argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, + NULL, NULL, NULL, NULL, tag, distance, vrf, + NULL); } /* New RIB. Detailed information for IPv4 route. */ @@ -2147,163 +2182,6 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, return write; } -/* General fucntion for IPv6 static route. */ -static int static_ipv6_func(struct vty *vty, int add_cmd, const char *dest_str, - const char *src_str, const char *gate_str, - const char *ifname, const char *flag_str, - const char *tag_str, const char *distance_str, - const char *vrf_id_str, const char *label_str) -{ - int ret; - u_char distance; - struct prefix p, src; - struct prefix_ipv6 *src_p = NULL; - struct in6_addr *gate = NULL; - struct in6_addr gate_addr; - u_char type; - u_char flag = 0; - route_tag_t tag = 0; - unsigned int ifindex = 0; - struct zebra_vrf *zvrf; - struct static_nh_label snh_label; - - ret = str2prefix(dest_str, &p); - if (ret <= 0) { - vty_out(vty, "%% Malformed address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - - if (src_str) { - ret = str2prefix(src_str, &src); - if (ret <= 0 || src.family != AF_INET6) { - vty_out(vty, "%% Malformed source address\n"); - return CMD_WARNING_CONFIG_FAILED; - } - src_p = (struct prefix_ipv6 *)&src; - } - - /* Apply mask for given prefix. */ - apply_mask(&p); - - /* Administrative distance. */ - if (distance_str) - distance = atoi(distance_str); - else - distance = ZEBRA_STATIC_DISTANCE_DEFAULT; - - /* tag */ - if (tag_str) - tag = strtoul(tag_str, NULL, 10); - - /* VRF id */ - zvrf = zebra_vrf_lookup_by_name(vrf_id_str); - - if (!zvrf) { - vty_out(vty, "%% vrf %s is not defined\n", vrf_id_str); - return CMD_WARNING_CONFIG_FAILED; - } - - /* Labels */ - memset(&snh_label, 0, sizeof(struct static_nh_label)); - if (label_str) { - if (!mpls_enabled) { - vty_out(vty, - "%% MPLS not turned on in kernel, ignoring command\n"); - return CMD_WARNING_CONFIG_FAILED; - } - int rc = mpls_str2label(label_str, &snh_label.num_labels, - snh_label.label); - if (rc < 0) { - switch (rc) { - case -1: - vty_out(vty, "%% Malformed label(s)\n"); - break; - case -2: - vty_out(vty, - "%% Cannot use reserved label(s) (%d-%d)\n", - MPLS_MIN_RESERVED_LABEL, - MPLS_MAX_RESERVED_LABEL); - break; - case -3: - vty_out(vty, - "%% Too many labels. Enter %d or fewer\n", - MPLS_MAX_LABELS); - break; - } - return CMD_WARNING_CONFIG_FAILED; - } - } - - /* Null0 static route. */ - if ((ifname != NULL) - && (strncasecmp(ifname, "Null0", strlen(ifname)) == 0)) { - if (flag_str) { - vty_out(vty, "%% can not have flag %s with Null0\n", - flag_str); - return CMD_WARNING_CONFIG_FAILED; - } - SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); - ifname = NULL; - } - - /* Route flags */ - if (flag_str) { - switch (flag_str[0]) { - case 'r': - case 'R': /* XXX */ - SET_FLAG(flag, ZEBRA_FLAG_REJECT); - break; - case 'b': - case 'B': /* XXX */ - SET_FLAG(flag, ZEBRA_FLAG_BLACKHOLE); - break; - default: - vty_out(vty, "%% Malformed flag %s \n", flag_str); - return CMD_WARNING_CONFIG_FAILED; - } - } - - if (gate_str) { - if (inet_pton(AF_INET6, gate_str, &gate_addr) != 1) { - vty_out(vty, "%% Malformed nexthop address %s\n", - gate_str); - return CMD_WARNING_CONFIG_FAILED; - } - gate = &gate_addr; - } - - if (ifname) { - struct interface *ifp; - ifp = if_lookup_by_name(ifname, zvrf_id(zvrf)); - if (!ifp) { - vty_out(vty, "%% Malformed Interface name %s\n", - ifname); - ifindex = IFINDEX_DELETED; - } else - ifindex = ifp->ifindex; - } - - if (gate_str == NULL && ifname == NULL) - type = STATIC_BLACKHOLE; - else if (gate_str && ifname) - type = STATIC_IPV6_GATEWAY_IFINDEX; - else if (ifname) - type = STATIC_IFINDEX; - else - type = STATIC_IPV6_GATEWAY; - - if (add_cmd) - static_add_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - (union g_addr *)gate, ifindex, ifname, flag, - tag, distance, zvrf, &snh_label); - else - static_delete_route(AFI_IP6, SAFI_UNICAST, type, &p, src_p, - (union g_addr *)gate, ifindex, tag, - distance, zvrf, &snh_label); - - return CMD_SUCCESS; -} - DEFUN (ipv6_route, ipv6_route_cmd, "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", @@ -2346,8 +2224,10 @@ DEFUN (ipv6_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + gate, ifname, NULL, tag, distance, vrf, + label); } DEFUN (ipv6_route_flags, @@ -2383,9 +2263,10 @@ DEFUN (ipv6_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (ipv6_route_ifname, @@ -2425,9 +2306,10 @@ DEFUN (ipv6_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 1, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + argv[idx_ipv6]->arg, argv[idx_interface]->arg, + NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route, @@ -2473,8 +2355,9 @@ DEFUN (no_ipv6_route, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - gate, ifname, NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + gate, ifname, NULL, tag, distance, vrf, label); } DEFUN (no_ipv6_route_flags, @@ -2511,9 +2394,10 @@ DEFUN (no_ipv6_route_flags, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, NULL); - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + NULL, NULL, argv[idx_reject_blackhole]->arg, + tag, distance, vrf, NULL); } DEFUN (no_ipv6_route_ifname, @@ -2554,9 +2438,10 @@ DEFUN (no_ipv6_route_ifname, zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, &vrf, &label); - return static_ipv6_func(vty, 0, argv[idx_ipv6_prefixlen]->arg, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, + argv[idx_ipv6_prefixlen]->arg, NULL, src, + argv[idx_ipv6]->arg, argv[idx_interface]->arg, + NULL, tag, distance, vrf, label); } DEFUN (show_ipv6_route, From 00685a85e25f3817b2a972019ac047914f019caa Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Thu, 27 Jul 2017 21:27:56 -0300 Subject: [PATCH 47/75] zebra: use DEFPY for static routes Now we have a single command for IPv4 static routes and another one for IPv6 static routes (+ one command for IPv4 multicast static routes). Signed-off-by: Renato Westphal --- zebra/.gitignore | 1 + zebra/Makefile.am | 2 + zebra/zebra_vty.c | 745 +++------------------------------------------- 3 files changed, 50 insertions(+), 698 deletions(-) diff --git a/zebra/.gitignore b/zebra/.gitignore index 145df05689..d0a7528539 100644 --- a/zebra/.gitignore +++ b/zebra/.gitignore @@ -13,3 +13,4 @@ TAGS .arch-ids *~ *.loT +zebra_vty_clippy.c diff --git a/zebra/Makefile.am b/zebra/Makefile.am index 46ecad5e4c..67031ea361 100644 --- a/zebra/Makefile.am +++ b/zebra/Makefile.am @@ -37,6 +37,8 @@ zebra_SOURCES = \ zebra_vxlan.c \ # end +zebra_vty.o: zebra_vty_clippy.c + noinst_HEADERS = \ zebra_memory.h \ connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \ diff --git a/zebra/zebra_vty.c b/zebra/zebra_vty.c index 446bcc49eb..e8b82ecf90 100644 --- a/zebra/zebra_vty.c +++ b/zebra/zebra_vty.c @@ -43,6 +43,7 @@ #include "zebra/zebra_static.h" #include "lib/json.h" #include "zebra/zebra_vxlan.h" +#include "zebra/zebra_vty_clippy.c" extern int allow_delete; @@ -62,7 +63,7 @@ static void vty_show_ip_route_detail(struct vty *vty, struct route_node *rn, /* General function for static route. */ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, - int add_cmd, const char *dest_str, + const char *negate, const char *dest_str, const char *mask_str, const char *src_str, const char *gate_str, const char *ifname, const char *flag_str, const char *tag_str, @@ -233,7 +234,7 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, type = STATIC_IPV6_GATEWAY; } - if (add_cmd) + if (!negate) static_add_route(afi, safi, type, &p, src_p, gatep, ifindex, ifname, flag, tag, distance, zvrf, &snh_label); else @@ -244,34 +245,9 @@ static int zebra_static_route(struct vty *vty, afi_t afi, safi_t safi, } /* Static unicast routes for multicast RPF lookup. */ -DEFUN (ip_mroute_dist, +DEFPY (ip_mroute_dist, ip_mroute_dist_cmd, - "ip mroute A.B.C.D/M [(1-255)]", - IP_STR - "Configure static unicast route into MRIB for multicast RPF lookup\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "Nexthop address\n" - "Nexthop interface name\n" - "Distance\n") -{ - char *destprefix = argv[2]->arg; - char *gate = NULL; - char *ifname = NULL; - char *distance = (argc == 5) ? argv[4]->arg : NULL; - - if (argv[3]->type == IPV4_TKN) - gate = argv[3]->arg; - else - ifname = argv[3]->arg; - - return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 1, destprefix, - NULL, NULL, gate, ifname, NULL, NULL, distance, - NULL, NULL); -} - -DEFUN (no_ip_mroute_dist, - no_ip_mroute_dist_cmd, - "no ip mroute A.B.C.D/M [(1-255)]", + "[no] ip mroute A.B.C.D/M$prefix [(1-255)$distance]", NO_STR IP_STR "Configure static unicast route into MRIB for multicast RPF lookup\n" @@ -280,19 +256,9 @@ DEFUN (no_ip_mroute_dist, "Nexthop interface name\n" "Distance\n") { - char *destprefix = argv[3]->arg; - char *gate = NULL; - char *ifname = NULL; - char *distance = (argc == 6) ? argv[5]->arg : NULL; - - if (argv[4]->type == IPV4_TKN) - gate = argv[4]->arg; - else - ifname = argv[4]->arg; - - return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, 0, destprefix, - NULL, NULL, gate, ifname, NULL, NULL, distance, - NULL, NULL); + return zebra_static_route(vty, AFI_IP, SAFI_MULTICAST, no, prefix_str, + NULL, NULL, gate_str, ifname, NULL, NULL, + distance_str, NULL, NULL); } DEFUN (ip_multicast_mode, @@ -388,417 +354,43 @@ DEFUN (show_ip_rpf_addr, return CMD_SUCCESS; } -static void zebra_vty_ip_route_tdv_helper(int argc, struct cmd_token *argv[], - int idx_curr, char **tag, - char **distance, char **vrf, - char **labels) -{ - *tag = NULL; - *distance = NULL; - *vrf = NULL; - if (labels) - *labels = NULL; - while (idx_curr < argc) { - if (strmatch(argv[idx_curr]->text, "tag")) { - if (tag) - *tag = argv[idx_curr + 1]->arg; - idx_curr += 2; - } else if (strmatch(argv[idx_curr]->text, "vrf")) { - if (vrf) - *vrf = argv[idx_curr + 1]->arg; - idx_curr += 2; - } else if (strmatch(argv[idx_curr]->text, "label")) { - if (labels) - *labels = argv[idx_curr + 1]->arg; - idx_curr += 2; - } else { - if (distance) - *distance = argv[idx_curr]->arg; - idx_curr++; - } - } - - return; -} - /* Static route configuration. */ -DEFUN (ip_route, +DEFPY (ip_route, ip_route_cmd, - "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", + "[no] ip route\ + \ + <\ + {A.B.C.D$gate|INTERFACE$ifname}\ + |null0$ifname\ + |$flag\ + >\ + [{\ + tag (1-4294967295)\ + |(1-255)$distance\ + |vrf NAME\ + |label WORD\ + }]", + NO_STR IP_STR "Establish static routes\n" "IP destination prefix (e.g. 10.0.0.0/8)\n" + "IP destination prefix\n" + "IP destination prefix mask\n" "IP gateway address\n" "IP gateway interface name\n" "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4_prefixlen = 2; - int idx_curr = 4; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[3]->type == IPV4_TKN) - gate = argv[3]->arg; - else - ifname = argv[3]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, label); -} - -DEFUN (ip_route_flags, - ip_route_flags_cmd, - "ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" "Tag value\n" "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4_prefixlen = 2; - int idx_reject_blackhole = 3; - int idx_curr = 4; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); -} - -DEFUN (ip_route_ifname, - ip_route_ifname_cmd, - "ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" VRF_CMD_HELP_STR MPLS_LABEL_HELPSTR) { - int idx_ipv4_prefixlen = 2; - int idx_curr = 5; - char *gate = argv[3]->arg; - char *ifname = argv[4]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, label); -} - -/* Mask as A.B.C.D format. */ -DEFUN_HIDDEN (ip_route_mask, - ip_route_mask_cmd, - "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_curr = 5; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[4]->type == IPV4_TKN) - gate = argv[4]->arg; - else - ifname = argv[4]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (ip_route_mask_ifname, - ip_route_mask_ifname_cmd, - "ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_curr = 6; - char *gate = argv[4]->arg; - char *ifname = argv[5]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (ip_route_mask_flags, - ip_route_mask_flags_cmd, - "ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4 = 2; - int idx_ipv4_2 = 3; - int idx_reject_blackhole = 4; - int idx_curr = 5; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 1, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, NULL, NULL, - argv[idx_reject_blackhole]->arg, tag, - distance, vrf, NULL); -} - -DEFUN (no_ip_route, - no_ip_route_cmd, - "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4_prefixlen = 3; - int idx_curr = 5; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[4]->type == IPV4_TKN) - gate = argv[4]->arg; - else - ifname = argv[4]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN (no_ip_route_ifname, - no_ip_route_ifname_cmd, - "no ip route A.B.C.D/M A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4_prefixlen = 3; - int idx_curr = 6; - char *gate = argv[4]->arg; - char *ifname = argv[5]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN (no_ip_route_flags, - no_ip_route_flags_cmd, - "no ip route A.B.C.D/M [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix (e.g. 10.0.0.0/8)\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4_prefixlen = 3; - int idx_curr = 5; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4_prefixlen]->arg, NULL, NULL, - NULL, NULL, NULL, tag, distance, vrf, NULL); -} - -DEFUN_HIDDEN (no_ip_route_mask, - no_ip_route_mask_cmd, - "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Null interface\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_curr = 6; - char *gate = NULL; - char *ifname = NULL; - char *tag, *distance, *vrf, *label; - - if (argv[5]->type == IPV4_TKN) - gate = argv[5]->arg; - else - ifname = argv[5]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (no_ip_route_mask_ifname, - no_ip_route_mask_ifname_cmd, - "no ip route A.B.C.D A.B.C.D A.B.C.D INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "IP gateway address\n" - "IP gateway interface name\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_curr = 7; - char *gate = argv[5]->arg; - char *ifname = argv[6]->arg; - char *tag, *distance, *vrf, *label; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN_HIDDEN (no_ip_route_mask_flags, - no_ip_route_mask_flags_cmd, - "no ip route A.B.C.D A.B.C.D [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IP destination prefix\n" - "IP destination prefix mask\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Tag of this route\n" - "Tag value\n" - "Distance value for this route\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv4 = 3; - int idx_ipv4_2 = 4; - int idx_curr = 6; - char *tag, *distance, *vrf; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, 0, - argv[idx_ipv4]->arg, argv[idx_ipv4_2]->arg, - NULL, NULL, NULL, NULL, tag, distance, vrf, - NULL); + return zebra_static_route(vty, AFI_IP, SAFI_UNICAST, no, prefix, + mask_str, NULL, gate_str, ifname, flag, + tag_str, distance_str, vrf, label); + return 0; } /* New RIB. Detailed information for IPv4 route. */ @@ -2182,10 +1774,22 @@ static int static_config(struct vty *vty, afi_t afi, safi_t safi, return write; } -DEFUN (ipv6_route, +DEFPY (ipv6_route, ipv6_route_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR + "[no] ipv6 route X:X::X:X/M$prefix [from X:X::X:X/M]\ + <\ + {X:X::X:X$gate|INTERFACE$ifname}\ + |null0$ifname\ + |$flag\ + >\ + [{\ + tag (1-4294967295)\ + |(1-255)$distance\ + |vrf NAME\ + |label WORD\ + }]", + NO_STR + IPV6_STR "Establish static routes\n" "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" "IPv6 source-dest route\n" @@ -2193,255 +1797,17 @@ DEFUN (ipv6_route, "IPv6 gateway address\n" "IPv6 gateway interface name\n" "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv6_prefixlen = 2; - int idx_ipv6_ifname; - int idx_curr; - char *gate = NULL; - char *ifname = NULL; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_ipv6_ifname = 5; - idx_curr = 6; - } else { - src = NULL; - idx_ipv6_ifname = 3; - idx_curr = 4; - } - - if (argv[idx_ipv6_ifname]->type == IPV6_TKN) - gate = argv[idx_ipv6_ifname]->arg; - else - ifname = argv[idx_ipv6_ifname]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - gate, ifname, NULL, tag, distance, vrf, - label); -} - -DEFUN (ipv6_route_flags, - ipv6_route_flags_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" "Emit an ICMP unreachable when matched\n" "Silently discard pkts when matched\n" "Set tag for this route\n" "Tag value\n" "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 2; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_reject_blackhole = 5; - idx_curr = 6; - } else { - src = NULL; - idx_reject_blackhole = 3; - idx_curr = 4; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); -} - -DEFUN (ipv6_route_ifname, - ipv6_route_ifname_cmd, - "ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" VRF_CMD_HELP_STR MPLS_LABEL_HELPSTR) { - int idx_ipv6_prefixlen = 2; - int idx_ipv6 = 3; - int idx_interface = 4; - int idx_curr = 5; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[3]->text, "from")) { - src = argv[4]->arg; - idx_ipv6 = 5; - idx_interface = 6; - idx_curr = 7; - } else { - src = NULL; - idx_ipv6 = 3; - idx_interface = 4; - idx_curr = 5; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 1, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); -} - -DEFUN (no_ipv6_route, - no_ipv6_route_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Null interface\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6_ifname; - int idx_curr; - char *gate = NULL; - char *ifname = NULL; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_ipv6_ifname = 6; - idx_curr = 7; - } else { - src = NULL; - idx_ipv6_ifname = 4; - idx_curr = 5; - } - - if (argv[idx_ipv6_ifname]->type == IPV6_TKN) - gate = argv[idx_ipv6_ifname]->arg; - else - ifname = argv[idx_ipv6_ifname]->arg; - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - gate, ifname, NULL, tag, distance, vrf, label); -} - -DEFUN (no_ipv6_route_flags, - no_ipv6_route_flags_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] [{tag (1-4294967295)|(1-255)|vrf NAME}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "Emit an ICMP unreachable when matched\n" - "Silently discard pkts when matched\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR) -{ - int idx_ipv6_prefixlen = 3; - int idx_reject_blackhole; - int idx_curr; - char *src, *tag, *distance, *vrf; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_reject_blackhole = 6; - idx_curr = 7; - } else { - src = NULL; - idx_reject_blackhole = 4; - idx_curr = 5; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, NULL); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - NULL, NULL, argv[idx_reject_blackhole]->arg, - tag, distance, vrf, NULL); -} - -DEFUN (no_ipv6_route_ifname, - no_ipv6_route_ifname_cmd, - "no ipv6 route X:X::X:X/M [from X:X::X:X/M] X:X::X:X INTERFACE [{tag (1-4294967295)|(1-255)|vrf NAME|label WORD}]", - NO_STR - IP_STR - "Establish static routes\n" - "IPv6 destination prefix (e.g. 3ffe:506::/32)\n" - "IPv6 source-dest route\n" - "IPv6 source prefix\n" - "IPv6 gateway address\n" - "IPv6 gateway interface name\n" - "Set tag for this route\n" - "Tag value\n" - "Distance value for this prefix\n" - VRF_CMD_HELP_STR - MPLS_LABEL_HELPSTR) -{ - int idx_ipv6_prefixlen = 3; - int idx_ipv6; - int idx_interface; - int idx_curr; - char *src, *tag, *distance, *vrf, *label; - - if (strmatch(argv[4]->text, "from")) { - src = argv[5]->arg; - idx_ipv6 = 6; - idx_interface = 7; - idx_curr = 8; - } else { - src = NULL; - idx_ipv6 = 4; - idx_interface = 5; - idx_curr = 6; - } - - zebra_vty_ip_route_tdv_helper(argc, argv, idx_curr, &tag, &distance, - &vrf, &label); - - return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, 0, - argv[idx_ipv6_prefixlen]->arg, NULL, src, - argv[idx_ipv6]->arg, argv[idx_interface]->arg, - NULL, tag, distance, vrf, label); + return zebra_static_route(vty, AFI_IP6, SAFI_UNICAST, no, prefix_str, + NULL, from_str, gate_str, ifname, flag, + tag_str, distance_str, vrf, label); } DEFUN (show_ipv6_route, @@ -3294,21 +2660,9 @@ void zebra_vty_init(void) install_element(CONFIG_NODE, &allow_external_route_update_cmd); install_element(CONFIG_NODE, &no_allow_external_route_update_cmd); install_element(CONFIG_NODE, &ip_mroute_dist_cmd); - install_element(CONFIG_NODE, &no_ip_mroute_dist_cmd); install_element(CONFIG_NODE, &ip_multicast_mode_cmd); install_element(CONFIG_NODE, &no_ip_multicast_mode_cmd); install_element(CONFIG_NODE, &ip_route_cmd); - install_element(CONFIG_NODE, &ip_route_ifname_cmd); - install_element(CONFIG_NODE, &ip_route_flags_cmd); - install_element(CONFIG_NODE, &ip_route_mask_cmd); - install_element(CONFIG_NODE, &ip_route_mask_ifname_cmd); - install_element(CONFIG_NODE, &ip_route_mask_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_cmd); - install_element(CONFIG_NODE, &no_ip_route_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_ifname_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_flags_cmd); - install_element(CONFIG_NODE, &no_ip_route_mask_ifname_cmd); install_element(CONFIG_NODE, &ip_zebra_import_table_distance_cmd); install_element(CONFIG_NODE, &no_ip_zebra_import_table_cmd); @@ -3332,11 +2686,6 @@ void zebra_vty_init(void) install_element(VIEW_NODE, &show_ip_route_vrf_all_summary_prefix_cmd); install_element(CONFIG_NODE, &ipv6_route_cmd); - install_element(CONFIG_NODE, &ipv6_route_flags_cmd); - install_element(CONFIG_NODE, &ipv6_route_ifname_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_flags_cmd); - install_element(CONFIG_NODE, &no_ipv6_route_ifname_cmd); install_element(CONFIG_NODE, &ip_nht_default_route_cmd); install_element(CONFIG_NODE, &no_ip_nht_default_route_cmd); install_element(CONFIG_NODE, &ipv6_nht_default_route_cmd); From dbaaa5396c554d08ad839b9ed41de3d9951b5add Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 19:48:08 -0300 Subject: [PATCH 48/75] ldpd: fix segfault in "clear mpls ldp neighbor [addr]" Bug introduced by the CLI refactoring (c740f7d3678). Signed-off-by: Renato Westphal --- ldpd/ldp_vty_cmds.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index 871905aa8f..8a8d903a61 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -759,8 +759,9 @@ DEFUN (ldp_clear_mpls_ldp_neighbor, int idx = 0; const char *address = NULL; - if (argv_find(argv, argc, "neighbor", &idx)) - address = argv[idx + 1]->arg; + if (argv_find(argv, argc, "A.B.C.D", &idx) || + argv_find(argv, argc, "X:X::X:X", &idx)) + address = argv[idx]->arg; return (ldp_vty_clear_nbr(vty, address)); } From fc4ea5c25e328fe9c4e807bc8d3669c0103ed1fe Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 20:22:17 -0300 Subject: [PATCH 49/75] ldpd: fix missing "no" commands in vtysh Split the "no" version of some commands into a different DEFUN so that DEFUN_NOSH doesn't apply to them. Signed-off-by: Renato Westphal --- ldpd/ldp_vty_cmds.c | 118 +++++++++++++++++++++++++++++++++----------- 1 file changed, 88 insertions(+), 30 deletions(-) diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index 8a8d903a61..052a93e2af 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -25,59 +25,88 @@ DEFUN_NOSH(ldp_mpls_ldp, ldp_mpls_ldp_cmd, - "[no] mpls ldp", + "mpls ldp", + "Global MPLS configuration subcommands\n" + "Label Distribution Protocol\n") +{ + return (ldp_vty_mpls_ldp(vty, 0)); +} + +DEFUN (no_ldp_mpls_ldp, + no_ldp_mpls_ldp_cmd, + "no mpls ldp", "Negate a command or set its defaults\n" "Global MPLS configuration subcommands\n" "Label Distribution Protocol\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_mpls_ldp(vty, negate)); + return (ldp_vty_mpls_ldp(vty, 1)); } DEFUN_NOSH(ldp_l2vpn, ldp_l2vpn_cmd, - "[no] l2vpn WORD type vpls", - "Negate a command or set its defaults\n" + "l2vpn WORD type vpls", "Configure l2vpn commands\n" "L2VPN name\n" "L2VPN type\n" "Virtual Private LAN Service\n") { int idx = 0; - int negate = 0; const char *name; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "WORD", &idx); name = argv[idx]->arg; - return (ldp_vty_l2vpn(vty, negate, name)); + return (ldp_vty_l2vpn(vty, 0, name)); +} + +DEFUN (no_ldp_l2vpn, + no_ldp_l2vpn_cmd, + "no l2vpn WORD type vpls", + "Configure l2vpn commands\n" + "L2VPN name\n" + "L2VPN type\n" + "Virtual Private LAN Service\n") +{ + int idx = 0; + const char *name; + + argv_find(argv, argc, "WORD", &idx); + name = argv[idx]->arg; + + return (ldp_vty_l2vpn(vty, 1, name)); } DEFUN_NOSH(ldp_address_family, ldp_address_family_cmd, - "[no] address-family ", + "address-family ", + "Configure Address Family and its parameters\n" + "IPv4\n" + "IPv6\n") +{ + int idx = 0; + const char *af; + + argv_find(argv, argc, "address-family", &idx); + af = argv[idx + 1]->text; + + return (ldp_vty_address_family(vty, 0, af)); +} + +DEFUN (no_ldp_address_family, + no_ldp_address_family_cmd, + "no address-family ", "Negate a command or set its defaults\n" "Configure Address Family and its parameters\n" "IPv4\n" "IPv6\n") { int idx = 0; - int negate = 0; const char *af; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "address-family", &idx); af = argv[idx + 1]->text; - return (ldp_vty_address_family(vty, negate, af)); + return (ldp_vty_address_family(vty, 1, af)); } DEFUN_NOSH(ldp_exit_address_family, @@ -494,21 +523,32 @@ DEFUN (ldp_session_holdtime, DEFUN_NOSH(ldp_interface, ldp_interface_cmd, - "[no] interface IFNAME", - "Negate a command or set its defaults\n" + "interface IFNAME", "Enable LDP on an interface and enter interface submode\n" "Interface's name\n") { int idx = 0; - int negate = 0; const char *ifname; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "IFNAME", &idx); ifname = argv[idx]->arg; - return (ldp_vty_interface(vty, negate, ifname)); + return (ldp_vty_interface(vty, 0, ifname)); +} + +DEFUN (no_ldp_interface, + no_ldp_interface_cmd, + "no interface IFNAME", + "Enable LDP on an interface and enter interface submode\n" + "Interface's name\n") +{ + int idx = 0; + const char *ifname; + + argv_find(argv, argc, "IFNAME", &idx); + ifname = argv[idx]->arg; + + return (ldp_vty_interface(vty, 1, ifname)); } DEFUN (ldp_neighbor_ipv4_targeted, @@ -611,22 +651,35 @@ DEFUN (ldp_member_interface, DEFUN_NOSH(ldp_member_pseudowire, ldp_member_pseudowire_cmd, - "[no] member pseudowire IFNAME", + "member pseudowire IFNAME", + "L2VPN member configuration\n" + "Pseudowire interface\n" + "Interface's name\n") +{ + int idx = 0; + const char *ifname; + + argv_find(argv, argc, "IFNAME", &idx); + ifname = argv[idx]->arg; + + return (ldp_vty_l2vpn_pseudowire(vty, 0, ifname)); +} + +DEFUN (no_ldp_member_pseudowire, + no_ldp_member_pseudowire_cmd, + "no member pseudowire IFNAME", "Negate a command or set its defaults\n" "L2VPN member configuration\n" "Pseudowire interface\n" "Interface's name\n") { int idx = 0; - int negate = 0; const char *ifname; - if (argv_find(argv, argc, "no", &idx)) - negate = 1; argv_find(argv, argc, "IFNAME", &idx); ifname = argv[idx]->arg; - return (ldp_vty_l2vpn_pseudowire(vty, negate, ifname)); + return (ldp_vty_l2vpn_pseudowire(vty, 1, ifname)); } DEFUN (ldp_vc_type, @@ -1065,13 +1118,16 @@ ldp_vty_init (void) install_default(LDP_PSEUDOWIRE_NODE); install_element(CONFIG_NODE, &ldp_mpls_ldp_cmd); + install_element(CONFIG_NODE, &no_ldp_mpls_ldp_cmd); install_element(CONFIG_NODE, &ldp_l2vpn_cmd); + install_element(CONFIG_NODE, &no_ldp_l2vpn_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_discovery_hello_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_type_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_messages_recv_cmd); install_element(CONFIG_NODE, &ldp_debug_mpls_ldp_messages_sent_cmd); install_element(LDP_NODE, &ldp_address_family_cmd); + install_element(LDP_NODE, &no_ldp_address_family_cmd); install_element(LDP_NODE, &ldp_discovery_holdtime_cmd); install_element(LDP_NODE, &ldp_discovery_interval_cmd); install_element(LDP_NODE, &ldp_dual_stack_transport_connection_prefer_ipv4_cmd); @@ -1091,6 +1147,7 @@ ldp_vty_init (void) install_element(LDP_IPV4_NODE, &ldp_label_remote_accept_cmd); install_element(LDP_IPV4_NODE, &ldp_ttl_security_disable_cmd); install_element(LDP_IPV4_NODE, &ldp_interface_cmd); + install_element(LDP_IPV4_NODE, &no_ldp_interface_cmd); install_element(LDP_IPV4_NODE, &ldp_session_holdtime_cmd); install_element(LDP_IPV4_NODE, &ldp_neighbor_ipv4_targeted_cmd); install_element(LDP_IPV4_NODE, &ldp_exit_address_family_cmd); @@ -1119,6 +1176,7 @@ ldp_vty_init (void) install_element(LDP_L2VPN_NODE, &ldp_mtu_cmd); install_element(LDP_L2VPN_NODE, &ldp_member_interface_cmd); install_element(LDP_L2VPN_NODE, &ldp_member_pseudowire_cmd); + install_element(LDP_L2VPN_NODE, &no_ldp_member_pseudowire_cmd); install_element(LDP_L2VPN_NODE, &ldp_vc_type_cmd); install_element(LDP_PSEUDOWIRE_NODE, &ldp_control_word_cmd); From cd49efdac87a4373c78adeb5170ca5298b6c8385 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 21:39:55 -0300 Subject: [PATCH 50/75] ldpd: restore correct defaults on "no discovery ... interval" Signed-off-by: Renato Westphal --- ldpd/ldp_vty_conf.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 09eb6a7c55..2dbc5757d3 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -582,11 +582,12 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, if (disable) { switch (hello_type) { case HELLO_LINK: - vty_conf->lhello_interval = LINK_DFLT_HOLDTIME; + vty_conf->lhello_interval = + DEFAULT_HELLO_INTERVAL; break; case HELLO_TARGETED: vty_conf->thello_interval = - TARGETED_DFLT_HOLDTIME; + DEFAULT_HELLO_INTERVAL; break; } } else { From 1224e5c4340723dc3b9073953bc67933b5fab552 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 24 Jul 2017 21:45:33 -0300 Subject: [PATCH 51/75] ldpd: convert CLI code to use DEFPY Yay :) Signed-off-by: Renato Westphal --- ldpd/Makefile.am | 4 + ldpd/ldp_debug.c | 18 +- ldpd/ldp_vty.h | 78 +++--- ldpd/ldp_vty_cmds.c | 668 +++++++++----------------------------------- ldpd/ldp_vty_conf.c | 210 +++++--------- ldpd/ldp_vty_exec.c | 34 +-- 6 files changed, 276 insertions(+), 736 deletions(-) diff --git a/ldpd/Makefile.am b/ldpd/Makefile.am index 6074b53a33..de9b07ed4c 100644 --- a/ldpd/Makefile.am +++ b/ldpd/Makefile.am @@ -1,5 +1,7 @@ ## Process this file with automake to produce Makefile.in. +include ../common.am + AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" INSTALL_SDATA=@INSTALL@ -m 600 @@ -16,6 +18,8 @@ libldp_a_SOURCES = \ socket.c util.c ldp_vty_cmds.c ldp_vty_conf.c ldp_vty_exec.c \ ldp_debug.c ldp_zebra.c +ldp_vty_cmds.o: ldp_vty_cmds_clippy.c + noinst_HEADERS = \ control.h lde.h ldpd.h ldpe.h ldp.h log.h ldp_debug.h ldp_vty.h diff --git a/ldpd/ldp_debug.c b/ldpd/ldp_debug.c index c9c7160aed..d80ec8dfbc 100644 --- a/ldpd/ldp_debug.c +++ b/ldpd/ldp_debug.c @@ -38,31 +38,31 @@ struct cmd_node ldp_debug_node = }; int -ldp_vty_debug(struct vty *vty, int disable, const char *type_str, - const char *dir_str, int all) +ldp_vty_debug(struct vty *vty, const char *negate, const char *type_str, + const char *dir_str, const char *all) { if (strcmp(type_str, "discovery") == 0) { if (dir_str == NULL) return (CMD_WARNING_CONFIG_FAILED); if (dir_str[0] == 'r') { - if (disable) + if (negate) DEBUG_OFF(hello, HELLO_RECV); else DEBUG_ON(hello, HELLO_RECV); } else { - if (disable) + if (negate) DEBUG_OFF(hello, HELLO_SEND); else DEBUG_ON(hello, HELLO_SEND); } } else if (strcmp(type_str, "errors") == 0) { - if (disable) + if (negate) DEBUG_OFF(errors, ERRORS); else DEBUG_ON(errors, ERRORS); } else if (strcmp(type_str, "event") == 0) { - if (disable) + if (negate) DEBUG_OFF(event, EVENT); else DEBUG_ON(event, EVENT); @@ -71,7 +71,7 @@ ldp_vty_debug(struct vty *vty, int disable, const char *type_str, return (CMD_WARNING_CONFIG_FAILED); if (dir_str[0] == 'r') { - if (disable) { + if (negate) { DEBUG_OFF(msg, MSG_RECV); DEBUG_OFF(msg, MSG_RECV_ALL); } else { @@ -80,7 +80,7 @@ ldp_vty_debug(struct vty *vty, int disable, const char *type_str, DEBUG_ON(msg, MSG_RECV_ALL); } } else { - if (disable) { + if (negate) { DEBUG_OFF(msg, MSG_SEND); DEBUG_OFF(msg, MSG_SEND_ALL); } else { @@ -90,7 +90,7 @@ ldp_vty_debug(struct vty *vty, int disable, const char *type_str, } } } else if (strcmp(type_str, "zebra") == 0) { - if (disable) + if (negate) DEBUG_OFF(zebra, ZEBRA); else DEBUG_ON(zebra, ZEBRA); diff --git a/ldpd/ldp_vty.h b/ldpd/ldp_vty.h index 93713166f4..3d2072f1e5 100644 --- a/ldpd/ldp_vty.h +++ b/ldpd/ldp_vty.h @@ -36,46 +36,46 @@ int ldp_get_address(const char *, int *, union ldpd_addr *); int ldp_config_write(struct vty *); int ldp_l2vpn_config_write(struct vty *); int ldp_debug_config_write(struct vty *); -int ldp_vty_mpls_ldp (struct vty *, int); -int ldp_vty_address_family (struct vty *, int, const char *); -int ldp_vty_disc_holdtime(struct vty *, int, const char *, const char *); -int ldp_vty_disc_interval(struct vty *, int, const char *, const char *); -int ldp_vty_targeted_hello_accept(struct vty *, int, const char *); -int ldp_vty_nbr_session_holdtime(struct vty *, int, const char *, const char *); -int ldp_vty_af_session_holdtime(struct vty *, int, const char *); -int ldp_vty_interface(struct vty *, int, const char *); -int ldp_vty_trans_addr(struct vty *, int, const char *); -int ldp_vty_neighbor_targeted(struct vty *, int, const char *); -int ldp_vty_label_advertise(struct vty *, int, const char *, const char *); -int ldp_vty_label_allocate(struct vty *, int, int, const char *); -int ldp_vty_label_expnull(struct vty *, int, const char *); -int ldp_vty_label_accept(struct vty *, int, const char *, const char *); -int ldp_vty_ttl_security(struct vty *, int); -int ldp_vty_router_id(struct vty *, int, const char *); -int ldp_vty_ds_cisco_interop(struct vty *, int); -int ldp_vty_trans_pref_ipv4(struct vty *, int); -int ldp_vty_neighbor_password(struct vty *, int, const char *, const char *); -int ldp_vty_neighbor_ttl_security(struct vty *, int, const char *, const char *); -int ldp_vty_l2vpn(struct vty *, int, const char *); -int ldp_vty_l2vpn_bridge(struct vty *, int, const char *); -int ldp_vty_l2vpn_mtu(struct vty *, int, const char *); -int ldp_vty_l2vpn_pwtype(struct vty *, int, const char *); -int ldp_vty_l2vpn_interface(struct vty *, int, const char *); -int ldp_vty_l2vpn_pseudowire(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_cword(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_nbr_addr(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_nbr_id(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_pwid(struct vty *, int, const char *); -int ldp_vty_l2vpn_pw_pwstatus(struct vty *, int); +int ldp_vty_mpls_ldp (struct vty *, const char *); +int ldp_vty_address_family (struct vty *, const char *, const char *); +int ldp_vty_disc_holdtime(struct vty *, const char *, const char *, long); +int ldp_vty_disc_interval(struct vty *, const char *, const char *, long); +int ldp_vty_targeted_hello_accept(struct vty *, const char *, const char *); +int ldp_vty_nbr_session_holdtime(struct vty *, const char *, struct in_addr, long); +int ldp_vty_af_session_holdtime(struct vty *, const char *, long); +int ldp_vty_interface(struct vty *, const char *, const char *); +int ldp_vty_trans_addr(struct vty *, const char *, const char *); +int ldp_vty_neighbor_targeted(struct vty *, const char *, const char *); +int ldp_vty_label_advertise(struct vty *, const char *, const char *, const char *); +int ldp_vty_label_allocate(struct vty *, const char *, const char *, const char *); +int ldp_vty_label_expnull(struct vty *, const char *, const char *); +int ldp_vty_label_accept(struct vty *, const char *, const char *, const char *); +int ldp_vty_ttl_security(struct vty *, const char *); +int ldp_vty_router_id(struct vty *, const char *, struct in_addr); +int ldp_vty_ds_cisco_interop(struct vty *, const char *); +int ldp_vty_trans_pref_ipv4(struct vty *, const char *); +int ldp_vty_neighbor_password(struct vty *, const char *, struct in_addr, const char *); +int ldp_vty_neighbor_ttl_security(struct vty *, const char *, struct in_addr, const char *); +int ldp_vty_l2vpn(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_bridge(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_mtu(struct vty *, const char *, long); +int ldp_vty_l2vpn_pwtype(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_interface(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pseudowire(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pw_cword(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pw_nbr_addr(struct vty *, const char *, const char *); +int ldp_vty_l2vpn_pw_nbr_id(struct vty *, const char *, struct in_addr); +int ldp_vty_l2vpn_pw_pwid(struct vty *, const char *, long); +int ldp_vty_l2vpn_pw_pwstatus(struct vty *, const char *); int ldp_vty_clear_nbr(struct vty *, const char *); -int ldp_vty_debug(struct vty *, int, const char *, const char *, int); -int ldp_vty_show_binding(struct vty *, const char *, int, int); -int ldp_vty_show_discovery(struct vty *, const char *, int, int); -int ldp_vty_show_interface(struct vty *, const char *, int); -int ldp_vty_show_capabilities(struct vty *, int); -int ldp_vty_show_neighbor(struct vty *, int, int, int); -int ldp_vty_show_atom_binding(struct vty *, int); -int ldp_vty_show_atom_vc(struct vty *, int); +int ldp_vty_debug(struct vty *, const char *, const char *, const char *, const char *); +int ldp_vty_show_binding(struct vty *, const char *, const char *, const char *); +int ldp_vty_show_discovery(struct vty *, const char *, const char *, const char *); +int ldp_vty_show_interface(struct vty *, const char *, const char *); +int ldp_vty_show_capabilities(struct vty *, const char *); +int ldp_vty_show_neighbor(struct vty *, int, const char *, const char *); +int ldp_vty_show_atom_binding(struct vty *, const char *); +int ldp_vty_show_atom_vc(struct vty *, const char *); int ldp_vty_show_debugging(struct vty *); void ldp_vty_init(void); diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index 052a93e2af..56a14581c3 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -22,6 +22,7 @@ #include "command.h" #include "vty.h" #include "ldpd/ldp_vty.h" +#include "ldpd/ldp_vty_cmds_clippy.c" DEFUN_NOSH(ldp_mpls_ldp, ldp_mpls_ldp_cmd, @@ -29,17 +30,17 @@ DEFUN_NOSH(ldp_mpls_ldp, "Global MPLS configuration subcommands\n" "Label Distribution Protocol\n") { - return (ldp_vty_mpls_ldp(vty, 0)); + return (ldp_vty_mpls_ldp(vty, NULL)); } -DEFUN (no_ldp_mpls_ldp, +DEFPY (no_ldp_mpls_ldp, no_ldp_mpls_ldp_cmd, "no mpls ldp", "Negate a command or set its defaults\n" "Global MPLS configuration subcommands\n" "Label Distribution Protocol\n") { - return (ldp_vty_mpls_ldp(vty, 1)); + return (ldp_vty_mpls_ldp(vty, "no")); } DEFUN_NOSH(ldp_l2vpn, @@ -59,21 +60,16 @@ DEFUN_NOSH(ldp_l2vpn, return (ldp_vty_l2vpn(vty, 0, name)); } -DEFUN (no_ldp_l2vpn, +DEFPY (no_ldp_l2vpn, no_ldp_l2vpn_cmd, - "no l2vpn WORD type vpls", + "no l2vpn WORD$name type vpls", + "Negate a command or set its defaults\n" "Configure l2vpn commands\n" "L2VPN name\n" "L2VPN type\n" "Virtual Private LAN Service\n") { - int idx = 0; - const char *name; - - argv_find(argv, argc, "WORD", &idx); - name = argv[idx]->arg; - - return (ldp_vty_l2vpn(vty, 1, name)); + return (ldp_vty_l2vpn(vty, "no", name)); } DEFUN_NOSH(ldp_address_family, @@ -92,21 +88,15 @@ DEFUN_NOSH(ldp_address_family, return (ldp_vty_address_family(vty, 0, af)); } -DEFUN (no_ldp_address_family, +DEFPY (no_ldp_address_family, no_ldp_address_family_cmd, - "no address-family ", + "no address-family $af", "Negate a command or set its defaults\n" "Configure Address Family and its parameters\n" "IPv4\n" "IPv6\n") { - int idx = 0; - const char *af; - - argv_find(argv, argc, "address-family", &idx); - af = argv[idx + 1]->text; - - return (ldp_vty_address_family(vty, 1, af)); + return (ldp_vty_address_family(vty, "no", af)); } DEFUN_NOSH(ldp_exit_address_family, @@ -119,9 +109,9 @@ DEFUN_NOSH(ldp_exit_address_family, return CMD_SUCCESS; } -DEFUN (ldp_discovery_holdtime, +DEFPY (ldp_discovery_holdtime, ldp_discovery_holdtime_cmd, - "[no] discovery holdtime (1-65535)", + "[no] discovery $hello_type holdtime (1-65535)$holdtime", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "LDP Link Hellos\n" @@ -129,24 +119,12 @@ DEFUN (ldp_discovery_holdtime, "Hello holdtime\n" "Time (seconds) - 65535 implies infinite\n") { - int idx = 0; - int negate = 0; - const char *hello_type; - const char *holdtime; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "discovery", &idx); - hello_type = argv[idx + 1]->text; - argv_find(argv, argc, "(1-65535)", &idx); - holdtime = argv[idx]->arg; - - return (ldp_vty_disc_holdtime(vty, negate, hello_type, holdtime)); + return (ldp_vty_disc_holdtime(vty, no, hello_type, holdtime)); } -DEFUN (ldp_discovery_interval, +DEFPY (ldp_discovery_interval, ldp_discovery_interval_cmd, - "[no] discovery interval (1-65535)", + "[no] discovery $hello_type interval (1-65535)$interval", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "LDP Link Hellos\n" @@ -154,22 +132,10 @@ DEFUN (ldp_discovery_interval, "Hello interval\n" "Time (seconds)\n") { - int idx = 0; - int negate = 0; - const char *hello_type; - const char *interval; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "discovery", &idx); - hello_type = argv[idx + 1]->text; - argv_find(argv, argc, "(1-65535)", &idx); - interval = argv[idx]->arg; - - return (ldp_vty_disc_interval(vty, negate, hello_type, interval)); + return (ldp_vty_disc_interval(vty, no, hello_type, interval)); } -DEFUN (ldp_dual_stack_transport_connection_prefer_ipv4, +DEFPY (ldp_dual_stack_transport_connection_prefer_ipv4, ldp_dual_stack_transport_connection_prefer_ipv4_cmd, "[no] dual-stack transport-connection prefer ipv4", "Negate a command or set its defaults\n" @@ -178,58 +144,34 @@ DEFUN (ldp_dual_stack_transport_connection_prefer_ipv4, "Configure prefered address family for TCP transport connection with neighbor\n" "IPv4\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_trans_pref_ipv4(vty, negate)); + return (ldp_vty_trans_pref_ipv4(vty, no)); } -DEFUN (ldp_dual_stack_cisco_interop, +DEFPY (ldp_dual_stack_cisco_interop, ldp_dual_stack_cisco_interop_cmd, "[no] dual-stack cisco-interop", "Negate a command or set its defaults\n" "Configure dual stack parameters\n" "Use Cisco non-compliant format to send and interpret the Dual-Stack capability TLV\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_ds_cisco_interop(vty, negate)); + return (ldp_vty_ds_cisco_interop(vty, no)); } -DEFUN (ldp_neighbor_password, +DEFPY (ldp_neighbor_password, ldp_neighbor_password_cmd, - "[no] neighbor A.B.C.D password WORD", + "[no] neighbor A.B.C.D$neighbor password WORD$password", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "LDP Id of neighbor\n" "Configure password for MD5 authentication\n" "The password\n") { - int idx = 0; - int negate = 0; - const char *neighbor; - const char *password; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - neighbor = argv[idx]->arg; - argv_find(argv, argc, "WORD", &idx); - password = argv[idx]->arg; - - return (ldp_vty_neighbor_password(vty, negate, neighbor, password)); + return (ldp_vty_neighbor_password(vty, no, neighbor, password)); } -DEFUN (ldp_neighbor_session_holdtime, +DEFPY (ldp_neighbor_session_holdtime, ldp_neighbor_session_holdtime_cmd, - "[no] neighbor A.B.C.D session holdtime (15-65535)", + "[no] neighbor A.B.C.D$neighbor session holdtime (15-65535)$holdtime", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "LDP Id of neighbor\n" @@ -237,24 +179,12 @@ DEFUN (ldp_neighbor_session_holdtime, "Configure session holdtime\n" "Time (seconds)\n") { - int idx = 0; - int negate = 0; - const char *neighbor; - const char *holdtime; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - neighbor = argv[idx]->arg; - argv_find(argv, argc, "(15-65535)", &idx); - holdtime = argv[idx]->arg; - - return (ldp_vty_nbr_session_holdtime(vty, negate, neighbor, holdtime)); + return (ldp_vty_nbr_session_holdtime(vty, no, neighbor, holdtime)); } -DEFUN (ldp_neighbor_ttl_security, +DEFPY (ldp_neighbor_ttl_security, ldp_neighbor_ttl_security_cmd, - "[no] neighbor A.B.C.D ttl-security ", + "[no] neighbor A.B.C.D$neighbor ttl-security ", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "LDP Id of neighbor\n" @@ -263,43 +193,22 @@ DEFUN (ldp_neighbor_ttl_security, "IP hops\n" "maximum number of hops\n") { - int idx = 0; - int negate = 0; - const char *neighbor; - const char *hops = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - neighbor = argv[idx]->arg; - if (argv_find(argv, argc, "(1-254)", &idx)) - hops = argv[idx]->arg; - - return (ldp_vty_neighbor_ttl_security(vty, negate, neighbor, hops)); + return (ldp_vty_neighbor_ttl_security(vty, no, neighbor, hops_str)); } -DEFUN (ldp_router_id, +DEFPY (ldp_router_id, ldp_router_id_cmd, - "[no] router-id A.B.C.D", + "[no] router-id A.B.C.D$address", "Negate a command or set its defaults\n" "Configure router Id\n" "LSR Id (in form of an IPv4 address)\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_router_id(vty, negate, address)); + return (ldp_vty_router_id(vty, no, address)); } -DEFUN (ldp_discovery_targeted_hello_accept, +DEFPY (ldp_discovery_targeted_hello_accept, ldp_discovery_targeted_hello_accept_cmd, - "[no] discovery targeted-hello accept [from <(1-199)|(1300-2699)|WORD>]", + "[no] discovery targeted-hello accept [from <(1-199)|(1300-2699)|WORD>$from_acl]", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "LDP Targeted Hellos\n" @@ -309,61 +218,34 @@ DEFUN (ldp_discovery_targeted_hello_accept, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *from_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "from", &idx)) - from_acl = argv[idx + 1]->arg; - - return (ldp_vty_targeted_hello_accept(vty, negate, from_acl)); + return (ldp_vty_targeted_hello_accept(vty, no, from_acl)); } -DEFUN (ldp_discovery_transport_address_ipv4, +DEFPY (ldp_discovery_transport_address_ipv4, ldp_discovery_transport_address_ipv4_cmd, - "[no] discovery transport-address A.B.C.D", + "[no] discovery transport-address A.B.C.D$address", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "Specify transport address for TCP connection\n" "IP address to be used as transport address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_trans_addr(vty, negate, address)); + return (ldp_vty_trans_addr(vty, no, address_str)); } -DEFUN (ldp_discovery_transport_address_ipv6, +DEFPY (ldp_discovery_transport_address_ipv6, ldp_discovery_transport_address_ipv6_cmd, - "[no] discovery transport-address X:X::X:X", + "[no] discovery transport-address X:X::X:X$address", "Negate a command or set its defaults\n" "Configure discovery parameters\n" "Specify transport address for TCP connection\n" "IPv6 address to be used as transport address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "X:X::X:X", &idx); - address = argv[idx]->arg; - - return (ldp_vty_trans_addr(vty, negate, address)); + return (ldp_vty_trans_addr(vty, no, address_str)); } -DEFUN (ldp_label_local_advertise, +DEFPY (ldp_label_local_advertise, ldp_label_local_advertise_cmd, - "[no] label local advertise [{to <(1-199)|(1300-2699)|WORD>|for <(1-199)|(1300-2699)|WORD>}]", + "[no] label local advertise [{to <(1-199)|(1300-2699)|WORD>$to_acl|for <(1-199)|(1300-2699)|WORD>$for_acl}]", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure local label control and policies\n" @@ -377,27 +259,12 @@ DEFUN (ldp_label_local_advertise, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *to_acl = NULL; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - /* arguments within curly braces may be provided in any order */ - if (argv_find(argv, argc, "to", &idx)) - to_acl = argv[idx + 1]->arg; - idx = 0; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_advertise(vty, negate, to_acl, for_acl)); + return (ldp_vty_label_advertise(vty, no, to_acl, for_acl)); } -DEFUN (ldp_label_local_advertise_explicit_null, +DEFPY (ldp_label_local_advertise_explicit_null, ldp_label_local_advertise_explicit_null_cmd, - "[no] label local advertise explicit-null [for <(1-199)|(1300-2699)|WORD>]", + "[no] label local advertise explicit-null [for <(1-199)|(1300-2699)|WORD>$for_acl]", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure local label control and policies\n" @@ -408,21 +275,12 @@ DEFUN (ldp_label_local_advertise_explicit_null, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_expnull(vty, negate, for_acl)); + return (ldp_vty_label_expnull(vty, no, for_acl)); } -DEFUN (ldp_label_local_allocate, +DEFPY (ldp_label_local_allocate, ldp_label_local_allocate_cmd, - "[no] label local allocate >", + "[no] label local allocate $for_acl>", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure local label control and policies\n" @@ -433,27 +291,12 @@ DEFUN (ldp_label_local_allocate, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - int host_routes = 0; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - /* arguments within curly braces may be provided in any order */ - if (argv_find(argv, argc, "host-routes", &idx)) - host_routes = 1; - idx = 0; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_allocate(vty, negate, host_routes, for_acl)); + return (ldp_vty_label_allocate(vty, no, host_routes, for_acl)); } -DEFUN (ldp_label_remote_accept, +DEFPY (ldp_label_remote_accept, ldp_label_remote_accept_cmd, - "[no] label remote accept {from <(1-199)|(1300-2699)|WORD>|for <(1-199)|(1300-2699)|WORD>}", + "[no] label remote accept {from <(1-199)|(1300-2699)|WORD>$from_acl|for <(1-199)|(1300-2699)|WORD>$for_acl}", "Negate a command or set its defaults\n" "Configure label control and policies\n" "Configure remote/peer label control and policies\n" @@ -467,58 +310,28 @@ DEFUN (ldp_label_remote_accept, "IP access-list number (expanded range)\n" "IP access-list name\n") { - int idx = 0; - int negate = 0; - const char *from_acl = NULL; - const char *for_acl = NULL; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - /* arguments within curly braces may be provided in any order */ - if (argv_find(argv, argc, "from", &idx)) - from_acl = argv[idx + 1]->arg; - idx = 0; - if (argv_find(argv, argc, "for", &idx)) - for_acl = argv[idx + 1]->arg; - - return (ldp_vty_label_accept(vty, negate, from_acl, for_acl)); + return (ldp_vty_label_accept(vty, no, from_acl, for_acl)); } -DEFUN (ldp_ttl_security_disable, +DEFPY (ldp_ttl_security_disable, ldp_ttl_security_disable_cmd, "[no] ttl-security disable", "Negate a command or set its defaults\n" "LDP ttl security check\n" "Disable ttl security\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_ttl_security(vty, negate)); + return (ldp_vty_ttl_security(vty, no)); } -DEFUN (ldp_session_holdtime, +DEFPY (ldp_session_holdtime, ldp_session_holdtime_cmd, - "[no] session holdtime (15-65535)", + "[no] session holdtime (15-65535)$holdtime", "Negate a command or set its defaults\n" "Configure session parameters\n" "Configure session holdtime\n" "Time (seconds)\n") { - int idx = 0; - int negate = 0; - const char *holdtime; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "(15-65535)", &idx); - holdtime = argv[idx]->arg; - - return (ldp_vty_af_session_holdtime(vty, negate, holdtime)); + return (ldp_vty_af_session_holdtime(vty, no, holdtime)); } DEFUN_NOSH(ldp_interface, @@ -536,117 +349,67 @@ DEFUN_NOSH(ldp_interface, return (ldp_vty_interface(vty, 0, ifname)); } -DEFUN (no_ldp_interface, +DEFPY (no_ldp_interface, no_ldp_interface_cmd, - "no interface IFNAME", + "no interface IFNAME$ifname", + "Negate a command or set its defaults\n" "Enable LDP on an interface and enter interface submode\n" "Interface's name\n") { - int idx = 0; - const char *ifname; - - argv_find(argv, argc, "IFNAME", &idx); - ifname = argv[idx]->arg; - - return (ldp_vty_interface(vty, 1, ifname)); + return (ldp_vty_interface(vty, "no", ifname)); } -DEFUN (ldp_neighbor_ipv4_targeted, +DEFPY (ldp_neighbor_ipv4_targeted, ldp_neighbor_ipv4_targeted_cmd, - "[no] neighbor A.B.C.D targeted", + "[no] neighbor A.B.C.D$address targeted", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "IP address of neighbor\n" "Establish targeted session\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_neighbor_targeted(vty, negate, address)); + return (ldp_vty_neighbor_targeted(vty, no, address_str)); } -DEFUN (ldp_neighbor_ipv6_targeted, +DEFPY (ldp_neighbor_ipv6_targeted, ldp_neighbor_ipv6_targeted_cmd, - "[no] neighbor X:X::X:X targeted", + "[no] neighbor X:X::X:X$address targeted", "Negate a command or set its defaults\n" "Configure neighbor parameters\n" "IPv6 address of neighbor\n" "Establish targeted session\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "X:X::X:X", &idx); - address = argv[idx]->arg; - - return (ldp_vty_neighbor_targeted(vty, negate, address)); + return (ldp_vty_neighbor_targeted(vty, no, address_str)); } -DEFUN (ldp_bridge, +DEFPY (ldp_bridge, ldp_bridge_cmd, - "[no] bridge IFNAME", + "[no] bridge IFNAME$ifname", "Negate a command or set its defaults\n" "Bridge interface\n" "Interface's name\n") { - int idx = 0; - int negate = 0; - const char *ifname; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "IFNAME", &idx); - ifname = argv[idx]->arg; - - return (ldp_vty_l2vpn_bridge(vty, negate, ifname)); + return (ldp_vty_l2vpn_bridge(vty, no, ifname)); } -DEFUN (ldp_mtu, +DEFPY (ldp_mtu, ldp_mtu_cmd, - "[no] mtu (1500-9180)", + "[no] mtu (1500-9180)$mtu", "Negate a command or set its defaults\n" "Set Maximum Transmission Unit\n" "Maximum Transmission Unit value\n") { - int idx = 0; - int negate = 0; - const char *mtu; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "(1500-9180)", &idx); - mtu = argv[idx]->arg; - - return (ldp_vty_l2vpn_mtu(vty, negate, mtu)); + return (ldp_vty_l2vpn_mtu(vty, no, mtu)); } -DEFUN (ldp_member_interface, +DEFPY (ldp_member_interface, ldp_member_interface_cmd, - "[no] member interface IFNAME", + "[no] member interface IFNAME$ifname", "Negate a command or set its defaults\n" "L2VPN member configuration\n" "Local interface\n" "Interface's name\n") { - int idx = 0; - int negate = 0; - const char *ifname; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "IFNAME", &idx); - ifname = argv[idx]->arg; - - return (ldp_vty_l2vpn_interface(vty, negate, ifname)); + return (ldp_vty_l2vpn_interface(vty, no, ifname)); } DEFUN_NOSH(ldp_member_pseudowire, @@ -665,143 +428,86 @@ DEFUN_NOSH(ldp_member_pseudowire, return (ldp_vty_l2vpn_pseudowire(vty, 0, ifname)); } -DEFUN (no_ldp_member_pseudowire, +DEFPY (no_ldp_member_pseudowire, no_ldp_member_pseudowire_cmd, - "no member pseudowire IFNAME", + "no member pseudowire IFNAME$ifname", "Negate a command or set its defaults\n" "L2VPN member configuration\n" "Pseudowire interface\n" "Interface's name\n") { - int idx = 0; - const char *ifname; - - argv_find(argv, argc, "IFNAME", &idx); - ifname = argv[idx]->arg; - - return (ldp_vty_l2vpn_pseudowire(vty, 1, ifname)); + return (ldp_vty_l2vpn_pseudowire(vty, "no", ifname)); } -DEFUN (ldp_vc_type, +DEFPY (ldp_vc_type, ldp_vc_type_cmd, - "[no] vc type ", + "[no] vc type $vc_type", "Negate a command or set its defaults\n" "Virtual Circuit options\n" "Virtual Circuit type to use\n" "Ethernet (type 5)\n" "Ethernet-tagged (type 4)\n") { - int idx = 0; - int negate = 0; - const char *vc_type; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "type", &idx); - vc_type = argv[idx + 1]->text; - - return (ldp_vty_l2vpn_pwtype(vty, negate, vc_type)); + return (ldp_vty_l2vpn_pwtype(vty, no, vc_type)); } -DEFUN (ldp_control_word, +DEFPY (ldp_control_word, ldp_control_word_cmd, - "[no] control-word ", + "[no] control-word $preference", "Negate a command or set its defaults\n" "Control-word options\n" "Exclude control-word in pseudowire packets\n" "Include control-word in pseudowire packets\n") { - int idx = 0; - int negate = 0; - const char *preference; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "control-word", &idx); - preference = argv[idx + 1]->text; - - return (ldp_vty_l2vpn_pw_cword(vty, negate, preference)); + return (ldp_vty_l2vpn_pw_cword(vty, no, preference)); } -DEFUN (ldp_neighbor_address, +DEFPY (ldp_neighbor_address, ldp_neighbor_address_cmd, - "[no] neighbor address ", + "[no] neighbor address $pw_address", "Negate a command or set its defaults\n" "Remote endpoint configuration\n" "Specify the IPv4 or IPv6 address of the remote endpoint\n" "IPv4 address\n" "IPv6 address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "address", &idx); - address = argv[idx + 1]->arg; - - return (ldp_vty_l2vpn_pw_nbr_addr(vty, negate, address)); + return (ldp_vty_l2vpn_pw_nbr_addr(vty, no, pw_address_str)); } -DEFUN (ldp_neighbor_lsr_id, +DEFPY (ldp_neighbor_lsr_id, ldp_neighbor_lsr_id_cmd, - "[no] neighbor lsr-id A.B.C.D", + "[no] neighbor lsr-id A.B.C.D$address", "Negate a command or set its defaults\n" "Remote endpoint configuration\n" "Specify the LSR-ID of the remote endpoint\n" "IPv4 address\n") { - int idx = 0; - int negate = 0; - const char *address; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "A.B.C.D", &idx); - address = argv[idx]->arg; - - return (ldp_vty_l2vpn_pw_nbr_id(vty, negate, address)); + return (ldp_vty_l2vpn_pw_nbr_id(vty, no, address)); } -DEFUN (ldp_pw_id, +DEFPY (ldp_pw_id, ldp_pw_id_cmd, - "[no] pw-id (1-4294967295)", + "[no] pw-id (1-4294967295)$pwid", "Negate a command or set its defaults\n" "Set the Virtual Circuit ID\n" "Virtual Circuit ID value\n") { - int idx = 0; - int negate = 0; - const char *pwid; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "(1-4294967295)", &idx); - pwid = argv[idx]->arg; - - return (ldp_vty_l2vpn_pw_pwid(vty, negate, pwid)); + return (ldp_vty_l2vpn_pw_pwid(vty, no, pwid)); } -DEFUN (ldp_pw_status_disable, +DEFPY (ldp_pw_status_disable, ldp_pw_status_disable_cmd, "[no] pw-status disable", "Negate a command or set its defaults\n" "Configure PW status\n" "Disable PW status\n") { - int idx = 0; - int negate = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - - return (ldp_vty_l2vpn_pw_pwstatus(vty, negate)); + return (ldp_vty_l2vpn_pw_pwstatus(vty, no)); } -DEFUN (ldp_clear_mpls_ldp_neighbor, +DEFPY (ldp_clear_mpls_ldp_neighbor, ldp_clear_mpls_ldp_neighbor_cmd, - "clear mpls ldp neighbor []", + "clear mpls ldp neighbor []$address", "Reset functions\n" "Reset MPLS statistical information\n" "Clear LDP state\n" @@ -809,19 +515,12 @@ DEFUN (ldp_clear_mpls_ldp_neighbor, "IPv4 address\n" "IPv6 address\n") { - int idx = 0; - const char *address = NULL; - - if (argv_find(argv, argc, "A.B.C.D", &idx) || - argv_find(argv, argc, "X:X::X:X", &idx)) - address = argv[idx]->arg; - - return (ldp_vty_clear_nbr(vty, address)); + return (ldp_vty_clear_nbr(vty, address_str)); } -DEFUN (ldp_debug_mpls_ldp_discovery_hello, +DEFPY (ldp_debug_mpls_ldp_discovery_hello, ldp_debug_mpls_ldp_discovery_hello_cmd, - "[no] debug mpls ldp discovery hello ", + "[no] debug mpls ldp discovery hello $dir", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -831,21 +530,12 @@ DEFUN (ldp_debug_mpls_ldp_discovery_hello, "Received messages\n" "Sent messages\n") { - int idx = 0; - int negate = 0; - const char *dir; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "hello", &idx); - dir = argv[idx + 1]->text; - - return (ldp_vty_debug(vty, negate, "discovery", dir, 0)); + return (ldp_vty_debug(vty, no, "discovery", dir, NULL)); } -DEFUN (ldp_debug_mpls_ldp_type, +DEFPY (ldp_debug_mpls_ldp_type, ldp_debug_mpls_ldp_type_cmd, - "[no] debug mpls ldp ", + "[no] debug mpls ldp $type", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -854,21 +544,12 @@ DEFUN (ldp_debug_mpls_ldp_type, "LDP event information\n" "LDP zebra information\n") { - int idx = 0; - int negate = 0; - const char *type; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - argv_find(argv, argc, "ldp", &idx); - type = argv[idx + 1]->text; - - return (ldp_vty_debug(vty, negate, type, NULL, 0)); + return (ldp_vty_debug(vty, no, type, NULL, NULL)); } -DEFUN (ldp_debug_mpls_ldp_messages_recv, +DEFPY (ldp_debug_mpls_ldp_messages_recv, ldp_debug_mpls_ldp_messages_recv_cmd, - "[no] debug mpls ldp messages recv [all]", + "[no] debug mpls ldp messages recv [all]$all", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -877,21 +558,12 @@ DEFUN (ldp_debug_mpls_ldp_messages_recv, "Received messages, excluding periodic Keep Alives\n" "Received messages, including periodic Keep Alives\n") { - int idx = 0; - int negate = 0; - int all = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "all", &idx)) - all = 1; - - return (ldp_vty_debug(vty, negate, "messages", "recv", all)); + return (ldp_vty_debug(vty, no, "messages", "recv", all)); } -DEFUN (ldp_debug_mpls_ldp_messages_sent, +DEFPY (ldp_debug_mpls_ldp_messages_sent, ldp_debug_mpls_ldp_messages_sent_cmd, - "[no] debug mpls ldp messages sent [all]", + "[no] debug mpls ldp messages sent [all]$all", "Negate a command or set its defaults\n" "Debugging functions\n" "MPLS information\n" @@ -900,21 +572,12 @@ DEFUN (ldp_debug_mpls_ldp_messages_sent, "Sent messages, excluding periodic Keep Alives\n" "Sent messages, including periodic Keep Alives\n") { - int idx = 0; - int negate = 0; - int all = 0; - - if (argv_find(argv, argc, "no", &idx)) - negate = 1; - if (argv_find(argv, argc, "all", &idx)) - all = 1; - - return (ldp_vty_debug(vty, negate, "messages", "sent", all)); + return (ldp_vty_debug(vty, no, "messages", "sent", all)); } -DEFUN (ldp_show_mpls_ldp_binding, +DEFPY (ldp_show_mpls_ldp_binding, ldp_show_mpls_ldp_binding_cmd, - "show mpls ldp [] binding [detail] [json]", + "show mpls ldp []$af binding [detail]$detail [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -924,25 +587,12 @@ DEFUN (ldp_show_mpls_ldp_binding, "Show detailed information\n" "JavaScript Object Notation\n") { - int idx = 0; - const char *af = NULL; - int detail = 0; - int json = 0; - - if (argv_find(argv, argc, "ipv4", &idx) || - argv_find(argv, argc, "ipv6", &idx)) - af = argv[idx]->text; - if (argv_find(argv, argc, "detail", &idx)) - detail = 1; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_binding(vty, af, detail, json)); } -DEFUN (ldp_show_mpls_ldp_discovery, +DEFPY (ldp_show_mpls_ldp_discovery, ldp_show_mpls_ldp_discovery_cmd, - "show mpls ldp [] discovery [detail] [json]", + "show mpls ldp []$af discovery [detail]$detail [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -952,25 +602,12 @@ DEFUN (ldp_show_mpls_ldp_discovery, "Show detailed information\n" "JavaScript Object Notation\n") { - int idx = 0; - const char *af = NULL; - int detail = 0; - int json = 0; - - if (argv_find(argv, argc, "ipv4", &idx) || - argv_find(argv, argc, "ipv6", &idx)) - af = argv[idx]->text; - if (argv_find(argv, argc, "detail", &idx)) - detail = 1; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_discovery(vty, af, detail, json)); } -DEFUN (ldp_show_mpls_ldp_interface, +DEFPY (ldp_show_mpls_ldp_interface, ldp_show_mpls_ldp_interface_cmd, - "show mpls ldp [] interface [json]", + "show mpls ldp []$af interface [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -979,40 +616,24 @@ DEFUN (ldp_show_mpls_ldp_interface, "interface information\n" "JavaScript Object Notation\n") { - int idx = 0; - const char *af = NULL; - int json = 0; - - if (argv_find(argv, argc, "ipv4", &idx) || - argv_find(argv, argc, "ipv6", &idx)) - af = argv[idx]->text; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_interface(vty, af, json)); } -DEFUN (ldp_show_mpls_ldp_capabilities, +DEFPY (ldp_show_mpls_ldp_capabilities, ldp_show_mpls_ldp_capabilities_cmd, - "show mpls ldp capabilities [json]", + "show mpls ldp capabilities [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" "Display LDP Capabilities information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_capabilities(vty, json)); } -DEFUN (ldp_show_mpls_ldp_neighbor, +DEFPY (ldp_show_mpls_ldp_neighbor, ldp_show_mpls_ldp_neighbor_cmd, - "show mpls ldp neighbor [detail] [json]", + "show mpls ldp neighbor [detail]$detail [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -1020,21 +641,12 @@ DEFUN (ldp_show_mpls_ldp_neighbor, "Show detailed information\n" "JavaScript Object Notation\n") { - int idx = 0; - int detail = 0; - int json = 0; - - if (argv_find(argv, argc, "detail", &idx)) - detail = 1; - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_neighbor(vty, 0, detail, json)); } -DEFUN (ldp_show_mpls_ldp_neighbor_capabilities, +DEFPY (ldp_show_mpls_ldp_neighbor_capabilities, ldp_show_mpls_ldp_neighbor_capabilities_cmd, - "show mpls ldp neighbor capabilities [json]", + "show mpls ldp neighbor capabilities [json]$json", "Show running system information\n" "MPLS information\n" "Label Distribution Protocol\n" @@ -1042,52 +654,34 @@ DEFUN (ldp_show_mpls_ldp_neighbor_capabilities, "Display neighbor capability information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - - return (ldp_vty_show_neighbor(vty, 1, 0, json)); + return (ldp_vty_show_neighbor(vty, 1, NULL, json)); } -DEFUN (ldp_show_l2vpn_atom_binding, +DEFPY (ldp_show_l2vpn_atom_binding, ldp_show_l2vpn_atom_binding_cmd, - "show l2vpn atom binding [json]", + "show l2vpn atom binding [json]$json", "Show running system information\n" "Show information about Layer2 VPN\n" "Show Any Transport over MPLS information\n" "Show AToM label binding information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_atom_binding(vty, json)); } -DEFUN (ldp_show_l2vpn_atom_vc, +DEFPY (ldp_show_l2vpn_atom_vc, ldp_show_l2vpn_atom_vc_cmd, - "show l2vpn atom vc [json]", + "show l2vpn atom vc [json]$json", "Show running system information\n" "Show information about Layer2 VPN\n" "Show Any Transport over MPLS information\n" "Show AToM virtual circuit information\n" "JavaScript Object Notation\n") { - int idx = 0; - int json = 0; - - if (argv_find(argv, argc, "json", &idx)) - json = 1; - return (ldp_vty_show_atom_vc(vty, json)); } -DEFUN (ldp_show_debugging_mpls_ldp, +DEFPY (ldp_show_debugging_mpls_ldp, ldp_show_debugging_mpls_ldp_cmd, "show debugging mpls ldp", "Show running system information\n" diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 2dbc5757d3..e938582d0d 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -407,9 +407,9 @@ ldp_iface_is_configured(struct ldpd_conf *xconf, const char *ifname) } int -ldp_vty_mpls_ldp(struct vty *vty, int disable) +ldp_vty_mpls_ldp(struct vty *vty, const char *negate) { - if (disable) + if (negate) vty_conf->flags &= ~F_LDPD_ENABLED; else { vty->node = LDP_NODE; @@ -422,7 +422,7 @@ ldp_vty_mpls_ldp(struct vty *vty, int disable) } int -ldp_vty_address_family(struct vty *vty, int disable, const char *af_str) +ldp_vty_address_family(struct vty *vty, const char *negate, const char *af_str) { struct ldpd_af_conf *af_conf; int af; @@ -436,7 +436,7 @@ ldp_vty_address_family(struct vty *vty, int disable, const char *af_str) } else return (CMD_WARNING_CONFIG_FAILED); - if (disable) { + if (negate) { af_conf->flags &= ~F_LDPD_AF_ENABLED; ldp_config_apply(vty, vty_conf); return (CMD_SUCCESS); @@ -460,23 +460,15 @@ ldp_vty_address_family(struct vty *vty, int disable, const char *af_str) } int -ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, - const char *seconds_str) +ldp_vty_disc_holdtime(struct vty *vty, const char *negate, + const char *hello_type_str, long secs) { struct ldpd_af_conf *af_conf; struct iface *iface; struct iface_af *ia; int af; - char *ep; - long int secs; enum hello_type hello_type; - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_HOLDTIME || secs > MAX_HOLDTIME) { - vty_out (vty, "%% Invalid holdtime\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - if (hello_type_str[0] == 'h') hello_type = HELLO_LINK; else @@ -484,7 +476,7 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, switch (vty->node) { case LDP_NODE: - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: vty_conf->lhello_holdtime = LINK_DFLT_HOLDTIME; @@ -511,7 +503,7 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: af_conf->lhello_holdtime = 0; @@ -539,7 +531,7 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, VTY_CHECK_CONTEXT(iface); ia = iface_af_get(iface, af); - if (disable) + if (negate) ia->hello_holdtime = 0; else ia->hello_holdtime = secs; @@ -554,24 +546,15 @@ ldp_vty_disc_holdtime(struct vty *vty, int disable, const char *hello_type_str, } int -ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, - const char *seconds_str) +ldp_vty_disc_interval(struct vty *vty, const char *negate, + const char *hello_type_str, long secs) { struct ldpd_af_conf *af_conf; struct iface *iface; struct iface_af *ia; int af; - char *ep; - long int secs; enum hello_type hello_type; - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_HELLO_INTERVAL || - secs > MAX_HELLO_INTERVAL) { - vty_out (vty, "%% Invalid interval\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - if (hello_type_str[0] == 'h') hello_type = HELLO_LINK; else @@ -579,7 +562,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, switch (vty->node) { case LDP_NODE: - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: vty_conf->lhello_interval = @@ -607,7 +590,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { switch (hello_type) { case HELLO_LINK: af_conf->lhello_interval = 0; @@ -635,7 +618,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, VTY_CHECK_CONTEXT(iface); ia = iface_af_get(iface, af); - if (disable) + if (negate) ia->hello_interval = 0; else ia->hello_interval = secs; @@ -650,7 +633,7 @@ ldp_vty_disc_interval(struct vty *vty, int disable, const char *hello_type_str, } int -ldp_vty_targeted_hello_accept(struct vty *vty, int disable, +ldp_vty_targeted_hello_accept(struct vty *vty, const char *negate, const char *acl_from_str) { struct ldpd_af_conf *af_conf; @@ -659,7 +642,7 @@ ldp_vty_targeted_hello_accept(struct vty *vty, int disable, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->flags &= ~F_LDPD_AF_THELLO_ACCEPT; af_conf->acl_thello_accept_from[0] = '\0'; } else { @@ -677,29 +660,19 @@ ldp_vty_targeted_hello_accept(struct vty *vty, int disable, } int -ldp_vty_nbr_session_holdtime(struct vty *vty, int disable, - const char *lsr_id_str, const char *seconds_str) +ldp_vty_nbr_session_holdtime(struct vty *vty, const char *negate, + struct in_addr lsr_id, long secs) { - char *ep; - long int secs; - struct in_addr lsr_id; struct nbr_params *nbrp; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_KEEPALIVE || secs > MAX_KEEPALIVE) { - vty_out (vty, "%% Invalid holdtime\n"); - return (CMD_SUCCESS); - } - nbrp = nbr_params_find(vty_conf, lsr_id); - if (disable) { + if (negate) { if (nbrp == NULL) return (CMD_SUCCESS); @@ -723,24 +696,15 @@ ldp_vty_nbr_session_holdtime(struct vty *vty, int disable, } int -ldp_vty_af_session_holdtime(struct vty *vty, int disable, - const char *seconds_str) +ldp_vty_af_session_holdtime(struct vty *vty, const char *negate, long secs) { struct ldpd_af_conf *af_conf; int af; - char *ep; - long int secs; - - secs = strtol(seconds_str, &ep, 10); - if (*ep != '\0' || secs < MIN_KEEPALIVE || secs > MAX_KEEPALIVE) { - vty_out (vty, "%% Invalid holdtime\n"); - return (CMD_SUCCESS); - } af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) + if (negate) af_conf->keepalive = DEFAULT_KEEPALIVE; else af_conf->keepalive = secs; @@ -751,7 +715,7 @@ ldp_vty_af_session_holdtime(struct vty *vty, int disable, } int -ldp_vty_interface(struct vty *vty, int disable, const char *ifname) +ldp_vty_interface(struct vty *vty, const char *negate, const char *ifname) { int af; struct iface *iface; @@ -760,7 +724,7 @@ ldp_vty_interface(struct vty *vty, int disable, const char *ifname) af = ldp_vty_get_af(vty); iface = if_lookup_name(vty_conf, ifname); - if (disable) { + if (negate) { if (iface == NULL) return (CMD_SUCCESS); @@ -813,7 +777,7 @@ ldp_vty_interface(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_trans_addr(struct vty *vty, int disable, const char *addr_str) +ldp_vty_trans_addr(struct vty *vty, const char *negate, const char *addr_str) { struct ldpd_af_conf *af_conf; int af; @@ -821,7 +785,7 @@ ldp_vty_trans_addr(struct vty *vty, int disable, const char *addr_str) af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) + if (negate) memset(&af_conf->trans_addr, 0, sizeof(af_conf->trans_addr)); else { if (inet_pton(af, addr_str, &af_conf->trans_addr) != 1 || @@ -837,7 +801,7 @@ ldp_vty_trans_addr(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_neighbor_targeted(struct vty *vty, int disable, const char *addr_str) +ldp_vty_neighbor_targeted(struct vty *vty, const char *negate, const char *addr_str) { int af; union ldpd_addr addr; @@ -857,7 +821,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, int disable, const char *addr_str) tnbr = tnbr_find(vty_conf, af, &addr); - if (disable) { + if (negate) { if (tnbr == NULL) return (CMD_SUCCESS); @@ -884,7 +848,7 @@ ldp_vty_neighbor_targeted(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_label_advertise(struct vty *vty, int disable, const char *acl_to_str, +ldp_vty_label_advertise(struct vty *vty, const char *negate, const char *acl_to_str, const char *acl_for_str) { struct ldpd_af_conf *af_conf; @@ -893,7 +857,7 @@ ldp_vty_label_advertise(struct vty *vty, int disable, const char *acl_to_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->acl_label_advertise_to[0] = '\0'; af_conf->acl_label_advertise_for[0] = '\0'; } else { @@ -915,7 +879,7 @@ ldp_vty_label_advertise(struct vty *vty, int disable, const char *acl_to_str, } int -ldp_vty_label_allocate(struct vty *vty, int disable, int host_routes, +ldp_vty_label_allocate(struct vty *vty, const char *negate, const char *host_routes, const char *acl_for_str) { struct ldpd_af_conf *af_conf; @@ -926,7 +890,7 @@ ldp_vty_label_allocate(struct vty *vty, int disable, int host_routes, af_conf->flags &= ~F_LDPD_AF_ALLOCHOSTONLY; af_conf->acl_label_allocate_for[0] = '\0'; - if (!disable) { + if (!negate) { if (host_routes) af_conf->flags |= F_LDPD_AF_ALLOCHOSTONLY; else @@ -940,7 +904,7 @@ ldp_vty_label_allocate(struct vty *vty, int disable, int host_routes, } int -ldp_vty_label_expnull(struct vty *vty, int disable, const char *acl_for_str) +ldp_vty_label_expnull(struct vty *vty, const char *negate, const char *acl_for_str) { struct ldpd_af_conf *af_conf; int af; @@ -948,7 +912,7 @@ ldp_vty_label_expnull(struct vty *vty, int disable, const char *acl_for_str) af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->flags &= ~F_LDPD_AF_EXPNULL; af_conf->acl_label_expnull_for[0] = '\0'; } else { @@ -966,7 +930,7 @@ ldp_vty_label_expnull(struct vty *vty, int disable, const char *acl_for_str) } int -ldp_vty_label_accept(struct vty *vty, int disable, const char *acl_from_str, +ldp_vty_label_accept(struct vty *vty, const char *negate, const char *acl_from_str, const char *acl_for_str) { struct ldpd_af_conf *af_conf; @@ -975,7 +939,7 @@ ldp_vty_label_accept(struct vty *vty, int disable, const char *acl_from_str, af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) { + if (negate) { af_conf->acl_label_accept_from[0] = '\0'; af_conf->acl_label_accept_for[0] = '\0'; } else { @@ -997,7 +961,7 @@ ldp_vty_label_accept(struct vty *vty, int disable, const char *acl_from_str, } int -ldp_vty_ttl_security(struct vty *vty, int disable) +ldp_vty_ttl_security(struct vty *vty, const char *negate) { struct ldpd_af_conf *af_conf; int af; @@ -1005,7 +969,7 @@ ldp_vty_ttl_security(struct vty *vty, int disable) af = ldp_vty_get_af(vty); af_conf = ldp_af_conf_get(vty_conf, af); - if (disable) + if (negate) af_conf->flags &= ~F_LDPD_AF_NO_GTSM; else af_conf->flags |= F_LDPD_AF_NO_GTSM; @@ -1016,16 +980,16 @@ ldp_vty_ttl_security(struct vty *vty, int disable) } int -ldp_vty_router_id(struct vty *vty, int disable, const char *addr_str) +ldp_vty_router_id(struct vty *vty, const char *negate, struct in_addr address) { - if (disable) + if (negate) vty_conf->rtr_id.s_addr = INADDR_ANY; else { - if (inet_pton(AF_INET, addr_str, &vty_conf->rtr_id) != 1 || - bad_addr_v4(vty_conf->rtr_id)) { + if (bad_addr_v4(address)) { vty_out (vty, "%% Malformed address\n"); return (CMD_SUCCESS); } + vty_conf->rtr_id = address; } ldp_config_apply(vty, vty_conf); @@ -1034,9 +998,9 @@ ldp_vty_router_id(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_ds_cisco_interop(struct vty *vty, int disable) +ldp_vty_ds_cisco_interop(struct vty *vty, const char * negate) { - if (disable) + if (negate) vty_conf->flags &= ~F_LDPD_DS_CISCO_INTEROP; else vty_conf->flags |= F_LDPD_DS_CISCO_INTEROP; @@ -1047,9 +1011,9 @@ ldp_vty_ds_cisco_interop(struct vty *vty, int disable) } int -ldp_vty_trans_pref_ipv4(struct vty *vty, int disable) +ldp_vty_trans_pref_ipv4(struct vty *vty, const char *negate) { - if (disable) + if (negate) vty_conf->trans_pref = DUAL_STACK_LDPOV6; else vty_conf->trans_pref = DUAL_STACK_LDPOV4; @@ -1060,22 +1024,20 @@ ldp_vty_trans_pref_ipv4(struct vty *vty, int disable) } int -ldp_vty_neighbor_password(struct vty *vty, int disable, const char *lsr_id_str, +ldp_vty_neighbor_password(struct vty *vty, const char *negate, struct in_addr lsr_id, const char *password_str) { - struct in_addr lsr_id; size_t password_len; struct nbr_params *nbrp; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } nbrp = nbr_params_find(vty_conf, lsr_id); - if (disable) { + if (negate) { if (nbrp == NULL) return (CMD_SUCCESS); @@ -1105,16 +1067,14 @@ ldp_vty_neighbor_password(struct vty *vty, int disable, const char *lsr_id_str, } int -ldp_vty_neighbor_ttl_security(struct vty *vty, int disable, - const char *lsr_id_str, const char *hops_str) +ldp_vty_neighbor_ttl_security(struct vty *vty, const char *negate, + struct in_addr lsr_id, const char *hops_str) { - struct in_addr lsr_id; struct nbr_params *nbrp; long int hops = 0; char *ep; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } @@ -1129,7 +1089,7 @@ ldp_vty_neighbor_ttl_security(struct vty *vty, int disable, nbrp = nbr_params_find(vty_conf, lsr_id); - if (disable) { + if (negate) { if (nbrp == NULL) return (CMD_SUCCESS); @@ -1159,7 +1119,7 @@ ldp_vty_neighbor_ttl_security(struct vty *vty, int disable, } int -ldp_vty_l2vpn(struct vty *vty, int disable, const char *name_str) +ldp_vty_l2vpn(struct vty *vty, const char *negate, const char *name_str) { struct l2vpn *l2vpn; struct l2vpn_if *lif; @@ -1167,7 +1127,7 @@ ldp_vty_l2vpn(struct vty *vty, int disable, const char *name_str) l2vpn = l2vpn_find(vty_conf, name_str); - if (disable) { + if (negate) { if (l2vpn == NULL) return (CMD_SUCCESS); @@ -1204,11 +1164,11 @@ ldp_vty_l2vpn(struct vty *vty, int disable, const char *name_str) } int -ldp_vty_l2vpn_bridge(struct vty *vty, int disable, const char *ifname) +ldp_vty_l2vpn_bridge(struct vty *vty, const char *negate, const char *ifname) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); - if (disable) + if (negate) memset(l2vpn->br_ifname, 0, sizeof(l2vpn->br_ifname)); else strlcpy(l2vpn->br_ifname, ifname, sizeof(l2vpn->br_ifname)); @@ -1219,19 +1179,11 @@ ldp_vty_l2vpn_bridge(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_l2vpn_mtu(struct vty *vty, int disable, const char *mtu_str) +ldp_vty_l2vpn_mtu(struct vty *vty, const char *negate, long mtu) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); - char *ep; - int mtu; - mtu = strtol(mtu_str, &ep, 10); - if (*ep != '\0' || mtu < MIN_L2VPN_MTU || mtu > MAX_L2VPN_MTU) { - vty_out (vty, "%% Invalid MTU\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - - if (disable) + if (negate) l2vpn->mtu = DEFAULT_L2VPN_MTU; else l2vpn->mtu = mtu; @@ -1242,7 +1194,7 @@ ldp_vty_l2vpn_mtu(struct vty *vty, int disable, const char *mtu_str) } int -ldp_vty_l2vpn_pwtype(struct vty *vty, int disable, const char *type_str) +ldp_vty_l2vpn_pwtype(struct vty *vty, const char *negate, const char *type_str) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); int pw_type; @@ -1252,7 +1204,7 @@ ldp_vty_l2vpn_pwtype(struct vty *vty, int disable, const char *type_str) else pw_type = PW_TYPE_ETHERNET_TAGGED; - if (disable) + if (negate) l2vpn->pw_type = DEFAULT_PW_TYPE; else l2vpn->pw_type = pw_type; @@ -1263,14 +1215,14 @@ ldp_vty_l2vpn_pwtype(struct vty *vty, int disable, const char *type_str) } int -ldp_vty_l2vpn_interface(struct vty *vty, int disable, const char *ifname) +ldp_vty_l2vpn_interface(struct vty *vty, const char *negate, const char *ifname) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); struct l2vpn_if *lif; lif = l2vpn_if_find(l2vpn, ifname); - if (disable) { + if (negate) { if (lif == NULL) return (CMD_SUCCESS); @@ -1301,14 +1253,14 @@ ldp_vty_l2vpn_interface(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_l2vpn_pseudowire(struct vty *vty, int disable, const char *ifname) +ldp_vty_l2vpn_pseudowire(struct vty *vty, const char *negate, const char *ifname) { VTY_DECLVAR_CONTEXT(l2vpn, l2vpn); struct l2vpn_pw *pw; pw = l2vpn_pw_find(l2vpn, ifname); - if (disable) { + if (negate) { if (pw == NULL) return (CMD_SUCCESS); @@ -1347,11 +1299,11 @@ ldp_vty_l2vpn_pseudowire(struct vty *vty, int disable, const char *ifname) } int -ldp_vty_l2vpn_pw_cword(struct vty *vty, int disable, const char *preference_str) +ldp_vty_l2vpn_pw_cword(struct vty *vty, const char *negate, const char *preference_str) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - if (disable) + if (negate) pw->flags |= F_PW_CWORD_CONF; else { if (preference_str[0] == 'e') @@ -1366,7 +1318,7 @@ ldp_vty_l2vpn_pw_cword(struct vty *vty, int disable, const char *preference_str) } int -ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, int disable, const char *addr_str) +ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, const char *negate, const char *addr_str) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); int af; @@ -1378,7 +1330,7 @@ ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, int disable, const char *addr_str) return (CMD_WARNING_CONFIG_FAILED); } - if (disable) { + if (negate) { pw->af = AF_UNSPEC; memset(&pw->addr, 0, sizeof(pw->addr)); pw->flags &= ~F_PW_STATIC_NBR_ADDR; @@ -1394,18 +1346,16 @@ ldp_vty_l2vpn_pw_nbr_addr(struct vty *vty, int disable, const char *addr_str) } int -ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, int disable, const char *lsr_id_str) +ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, const char *negate, struct in_addr lsr_id) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - struct in_addr lsr_id; - if (inet_pton(AF_INET, lsr_id_str, &lsr_id) != 1 || - bad_addr_v4(lsr_id)) { + if (bad_addr_v4(lsr_id)) { vty_out (vty, "%% Malformed address\n"); return (CMD_WARNING_CONFIG_FAILED); } - if (disable) + if (negate) pw->lsr_id.s_addr = INADDR_ANY; else pw->lsr_id = lsr_id; @@ -1416,19 +1366,11 @@ ldp_vty_l2vpn_pw_nbr_id(struct vty *vty, int disable, const char *lsr_id_str) } int -ldp_vty_l2vpn_pw_pwid(struct vty *vty, int disable, const char *pwid_str) +ldp_vty_l2vpn_pw_pwid(struct vty *vty, const char *negate, long pwid) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - char *ep; - uint32_t pwid; - pwid = strtol(pwid_str, &ep, 10); - if (*ep != '\0' || pwid < MIN_PWID_ID || pwid > MAX_PWID_ID) { - vty_out (vty, "%% Invalid pw-id\n"); - return (CMD_WARNING_CONFIG_FAILED); - } - - if (disable) + if (negate) pw->pwid = 0; else pw->pwid = pwid; @@ -1439,11 +1381,11 @@ ldp_vty_l2vpn_pw_pwid(struct vty *vty, int disable, const char *pwid_str) } int -ldp_vty_l2vpn_pw_pwstatus(struct vty *vty, int disable) +ldp_vty_l2vpn_pw_pwstatus(struct vty *vty, const char *negate) { VTY_DECLVAR_CONTEXT_SUB(l2vpn_pw, pw); - if (disable) + if (negate) pw->flags |= F_PW_STATUSTLV_CONF; else pw->flags &= ~F_PW_STATUSTLV_CONF; diff --git a/ldpd/ldp_vty_exec.c b/ldpd/ldp_vty_exec.c index bec1375bd2..ad5e79c721 100644 --- a/ldpd/ldp_vty_exec.c +++ b/ldpd/ldp_vty_exec.c @@ -1565,7 +1565,7 @@ ldp_vty_get_af(const char *str, int *af) } int -ldp_vty_show_binding(struct vty *vty, const char *af_str, int detail, int json) +ldp_vty_show_binding(struct vty *vty, const char *af_str, const char *detail, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1579,8 +1579,8 @@ ldp_vty_show_binding(struct vty *vty, const char *af_str, int detail, int json) memset(¶ms, 0, sizeof(params)); params.family = af; - params.detail = detail; - params.json = json; + params.detail = (detail) ? 1 : 0; + params.json = (json) ? 1 : 0; if (!params.detail && !params.json) vty_out (vty, "%-4s %-20s %-15s %-11s %-13s %6s\n", "AF", @@ -1592,8 +1592,8 @@ ldp_vty_show_binding(struct vty *vty, const char *af_str, int detail, int json) } int -ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail, - int json) +ldp_vty_show_discovery(struct vty *vty, const char *af_str, const char *detail, + const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1607,8 +1607,8 @@ ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail, memset(¶ms, 0, sizeof(params)); params.family = af; - params.detail = detail; - params.json = json; + params.detail = (detail) ? 1 : 0; + params.json = (json) ? 1 : 0; if (!params.detail && !params.json) vty_out (vty, "%-4s %-15s %-8s %-15s %9s\n", @@ -1623,7 +1623,7 @@ ldp_vty_show_discovery(struct vty *vty, const char *af_str, int detail, } int -ldp_vty_show_interface(struct vty *vty, const char *af_str, int json) +ldp_vty_show_interface(struct vty *vty, const char *af_str, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1638,7 +1638,7 @@ ldp_vty_show_interface(struct vty *vty, const char *af_str, int json) memset(¶ms, 0, sizeof(params)); params.family = af; - params.json = json; + params.json = (json) ? 1 : 0; /* header */ if (!params.json) { @@ -1652,7 +1652,7 @@ ldp_vty_show_interface(struct vty *vty, const char *af_str, int json) } int -ldp_vty_show_capabilities(struct vty *vty, int json) +ldp_vty_show_capabilities(struct vty *vty, const char *json) { if (json) { json_object *json; @@ -1703,7 +1703,7 @@ ldp_vty_show_capabilities(struct vty *vty, int json) } int -ldp_vty_show_neighbor(struct vty *vty, int capabilities, int detail, int json) +ldp_vty_show_neighbor(struct vty *vty, int capabilities, const char *detail, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1713,8 +1713,8 @@ ldp_vty_show_neighbor(struct vty *vty, int capabilities, int detail, int json) memset(¶ms, 0, sizeof(params)); params.capabilities = capabilities; - params.detail = detail; - params.json = json; + params.detail = (detail) ? 1 : 0; + params.json = (json) ? 1 : 0; if (params.capabilities) params.detail = 1; @@ -1728,7 +1728,7 @@ ldp_vty_show_neighbor(struct vty *vty, int capabilities, int detail, int json) } int -ldp_vty_show_atom_binding(struct vty *vty, int json) +ldp_vty_show_atom_binding(struct vty *vty, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1737,14 +1737,14 @@ ldp_vty_show_atom_binding(struct vty *vty, int json) return (CMD_WARNING); memset(¶ms, 0, sizeof(params)); - params.json = json; + params.json = (json) ? 1 : 0; imsg_compose(&ibuf, IMSG_CTL_SHOW_L2VPN_BINDING, 0, 0, -1, NULL, 0); return (ldp_vty_dispatch(vty, &ibuf, SHOW_L2VPN_BINDING, ¶ms)); } int -ldp_vty_show_atom_vc(struct vty *vty, int json) +ldp_vty_show_atom_vc(struct vty *vty, const char *json) { struct imsgbuf ibuf; struct show_params params; @@ -1753,7 +1753,7 @@ ldp_vty_show_atom_vc(struct vty *vty, int json) return (CMD_WARNING); memset(¶ms, 0, sizeof(params)); - params.json = json; + params.json = (json) ? 1 : 0; if (!params.json) { /* header */ From 935029cdd217b50a497513a9a084461ba40939bd Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 25 Jul 2017 00:20:56 -0300 Subject: [PATCH 52/75] ldpd: add auto-complete for l2vpns Signed-off-by: Renato Westphal --- ldpd/ldp_vty_cmds.c | 26 ++++++++++++++++++++++++-- 1 file changed, 24 insertions(+), 2 deletions(-) diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index 56a14581c3..7da76185c6 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -21,6 +21,7 @@ #include "command.h" #include "vty.h" +#include "ldpd/ldpd.h" #include "ldpd/ldp_vty.h" #include "ldpd/ldp_vty_cmds_clippy.c" @@ -62,14 +63,14 @@ DEFUN_NOSH(ldp_l2vpn, DEFPY (no_ldp_l2vpn, no_ldp_l2vpn_cmd, - "no l2vpn WORD$name type vpls", + "no l2vpn WORD$l2vpn_name type vpls", "Negate a command or set its defaults\n" "Configure l2vpn commands\n" "L2VPN name\n" "L2VPN type\n" "Virtual Private LAN Service\n") { - return (ldp_vty_l2vpn(vty, "no", name)); + return (ldp_vty_l2vpn(vty, "no", l2vpn_name)); } DEFUN_NOSH(ldp_address_family, @@ -692,9 +693,30 @@ DEFPY (ldp_show_debugging_mpls_ldp, return (ldp_vty_show_debugging(vty)); } +static void +l2vpn_autocomplete(vector comps, struct cmd_token *token) +{ + struct l2vpn *l2vpn; + + RB_FOREACH(l2vpn, l2vpn_head, &vty_conf->l2vpn_tree) + vector_set(comps, XSTRDUP(MTYPE_COMPLETION, l2vpn->name)); +} + +static const struct cmd_variable_handler l2vpn_var_handlers[] = { + { + .varname = "l2vpn_name", + .completions = l2vpn_autocomplete + }, + { + .completions = NULL + } +}; + void ldp_vty_init (void) { + cmd_variable_handler_register(l2vpn_var_handlers); + install_node(&ldp_node, ldp_config_write); install_node(&ldp_ipv4_node, NULL); install_node(&ldp_ipv6_node, NULL); From 1e4c86735790cb6c2ffde24fc64841de0541b723 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 25 Jul 2017 22:36:00 -0300 Subject: [PATCH 53/75] ldpd: silence coverity scan warning Signed-off-by: Renato Westphal --- ldpd/lde.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/ldpd/lde.c b/ldpd/lde.c index 602dc8805e..77643ff48b 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -1328,7 +1328,6 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) struct lde_map *me; RB_FOREACH(fec, fec_tree, &ln->recv_map) { - fn = (struct fec_node *)fec_find(&ft, fec); switch (fec->type) { case FEC_TYPE_IPV4: if (lde_addr->af != AF_INET) @@ -1342,6 +1341,11 @@ lde_nbr_addr_update(struct lde_nbr *ln, struct lde_addr *lde_addr, int removed) continue; } + fn = (struct fec_node *)fec_find(&ft, fec); + if (fn == NULL) + /* shouldn't happen */ + continue; + LIST_FOREACH(fnh, &fn->nexthops, entry) { if (ldp_addrcmp(fnh->af, &fnh->nexthop, &lde_addr->addr)) From b882ac4b51b8d412e3f8a4383e3f54c05695657e Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 25 Jul 2017 22:39:05 -0300 Subject: [PATCH 54/75] ldpd: update .gitignore Signed-off-by: Renato Westphal --- ldpd/.gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/ldpd/.gitignore b/ldpd/.gitignore index 35f7740d11..f52b227cb1 100644 --- a/ldpd/.gitignore +++ b/ldpd/.gitignore @@ -15,3 +15,4 @@ TAGS .arch-ids *~ *.loT +ldp_vty_cmds_clippy.c From 137a1684e0f0c95f0d2024206cd511379ee37edc Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 31 Jul 2017 08:52:10 -0400 Subject: [PATCH 55/75] vtysh: Fix shell executed commands Pretty much all shell executed commands from vtysh were not behaving correctly due to errors introduced in switching to the new cli. Signed-off-by: Donald Sharp --- vtysh/vtysh.c | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/vtysh/vtysh.c b/vtysh/vtysh.c index adf47ed57c..7476a2b897 100644 --- a/vtysh/vtysh.c +++ b/vtysh/vtysh.c @@ -2453,7 +2453,7 @@ DEFUN (vtysh_show_daemons, /* Execute command in child process. */ static void execute_command(const char *command, int argc, - struct cmd_token *arg1, const char *arg2) + const char *arg1, const char *arg2) { pid_t pid; int status; @@ -2498,7 +2498,10 @@ DEFUN (vtysh_ping, "Send echo messages\n" "Ping destination address or hostname\n") { - execute_command("ping", 1, argv[0], NULL); + int idx = 1; + + argv_find(argv, argc, "WORD", &idx); + execute_command("ping", 1, argv[idx]->arg, NULL); return CMD_SUCCESS; } @@ -2513,7 +2516,10 @@ DEFUN (vtysh_traceroute, "Trace route to destination\n" "Trace route to destination address or hostname\n") { - execute_command("traceroute", 1, argv[0], NULL); + int idx = 1; + + argv_find(argv, argc, "WORD", &idx); + execute_command("traceroute", 1, argv[idx]->arg, NULL); return CMD_SUCCESS; } @@ -2529,7 +2535,7 @@ DEFUN (vtysh_ping6, "IPv6 echo\n" "Ping destination address or hostname\n") { - execute_command("ping6", 1, argv[0], NULL); + execute_command("ping6", 1, argv[2]->arg, NULL); return CMD_SUCCESS; } @@ -2540,7 +2546,7 @@ DEFUN (vtysh_traceroute6, "IPv6 trace\n" "Trace route to destination address or hostname\n") { - execute_command("traceroute6", 1, argv[0], NULL); + execute_command("traceroute6", 1, argv[2]->arg, NULL); return CMD_SUCCESS; } @@ -2551,7 +2557,7 @@ DEFUN (vtysh_telnet, "Open a telnet connection\n" "IP address or hostname of a remote system\n") { - execute_command("telnet", 1, argv[0], NULL); + execute_command("telnet", 1, argv[1]->arg, NULL); return CMD_SUCCESS; } @@ -2562,7 +2568,7 @@ DEFUN (vtysh_telnet_port, "IP address or hostname of a remote system\n" "TCP Port number\n") { - execute_command("telnet", 2, argv[0], argv[1]); + execute_command("telnet", 2, argv[1]->arg, argv[2]->arg); return CMD_SUCCESS; } @@ -2572,7 +2578,7 @@ DEFUN (vtysh_ssh, "Open an ssh connection\n" "[user@]host\n") { - execute_command("ssh", 1, argv[0], NULL); + execute_command("ssh", 1, argv[1]->arg, NULL); return CMD_SUCCESS; } From a6df2b80d7f7f7f9b7329c15555bdd6f4bb4812d Mon Sep 17 00:00:00 2001 From: Olivier Dugeon Date: Mon, 31 Jul 2017 16:39:00 +0200 Subject: [PATCH 56/75] Correct code style as requested by review of PR839 * As per https://github.com/torvalds/linux/blob/master/scripts/checkpatch.pl script result, remove extra white space and add TAB when necessary Signed-off-by: Olivier Dugeon --- ospfd/ospf_opaque.h | 30 ++++++++++++++---------------- 1 file changed, 14 insertions(+), 16 deletions(-) diff --git a/ospfd/ospf_opaque.h b/ospfd/ospf_opaque.h index 60435e502e..2470cd2e2b 100644 --- a/ospfd/ospf_opaque.h +++ b/ospfd/ospf_opaque.h @@ -82,33 +82,31 @@ * used for various LSA opaque usage e.g. Traffic Engineering. */ struct tlv_header { - u_int16_t type; /* Type of Value */ - u_int16_t length; /* Length of Value portion only, in bytes */ + u_int16_t type; /* Type of Value */ + u_int16_t length; /* Length of Value portion only, in bytes */ }; -#define TLV_HDR_SIZE \ - (sizeof (struct tlv_header)) +#define TLV_HDR_SIZE (sizeof(struct tlv_header)) #define TLV_BODY_SIZE(tlvh) \ - (ROUNDUP (ntohs ((tlvh)->length), sizeof (u_int32_t))) + (ROUNDUP(ntohs((tlvh)->length), sizeof(u_int32_t))) -#define TLV_SIZE(tlvh) \ - (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh)) +#define TLV_SIZE(tlvh) (TLV_HDR_SIZE + TLV_BODY_SIZE(tlvh)) #define TLV_HDR_TOP(lsah) \ - (struct tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE) + (struct tlv_header *)((char *)(lsah) + OSPF_LSA_HEADER_SIZE) #define TLV_HDR_NEXT(tlvh) \ - (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh)) + (struct tlv_header *)((char *)(tlvh) + TLV_SIZE(tlvh)) #define TLV_HDR_SUBTLV(tlvh) \ - (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE) + (struct tlv_header *)((char *)(tlvh) + TLV_HDR_SIZE) -#define TLV_DATA(tlvh) (void *)((char *)(tlvh) + TLV_HDR_SIZE) +#define TLV_DATA(tlvh) (void *)((char *)(tlvh) + TLV_HDR_SIZE) -#define TLV_TYPE(tlvh) tlvh.header.type -#define TLV_LEN(tlvh) tlvh.header.length -#define TLV_HDR(tlvh) tlvh.header +#define TLV_TYPE(tlvh) tlvh.header.type +#define TLV_LEN(tlvh) tlvh.header.length +#define TLV_HDR(tlvh) tlvh.header /* Following declaration concerns the Opaque LSA management */ enum lsa_opcode { @@ -148,7 +146,7 @@ extern int ospf_opaque_new_if(struct interface *ifp); extern int ospf_opaque_del_if(struct interface *ifp); extern void ospf_opaque_ism_change(struct ospf_interface *oi, int old_status); extern void ospf_opaque_nsm_change(struct ospf_neighbor *nbr, int old_status); -extern void ospf_opaque_config_write_router(struct vty *vty, struct ospf *); +extern void ospf_opaque_config_write_router(struct vty *vty, struct ospf *ospf); extern void ospf_opaque_config_write_if(struct vty *vty, struct interface *ifp); extern void ospf_opaque_config_write_debug(struct vty *vty); extern void show_opaque_info_detail(struct vty *vty, struct ospf_lsa *lsa); @@ -156,7 +154,7 @@ extern void ospf_opaque_lsa_dump(struct stream *s, u_int16_t length); extern void ospf_opaque_lsa_originate_schedule(struct ospf_interface *oi, int *init_delay); -extern struct ospf_lsa *ospf_opaque_lsa_install(struct ospf_lsa *, +extern struct ospf_lsa *ospf_opaque_lsa_install(struct ospf_lsa *lsa, int rt_recalc); extern struct ospf_lsa *ospf_opaque_lsa_refresh(struct ospf_lsa *lsa); From 9d356c939f26f864a77f9bce007efd2b567a7466 Mon Sep 17 00:00:00 2001 From: Quentin Young Date: Mon, 31 Jul 2017 11:03:32 -0400 Subject: [PATCH 57/75] lib: s/leychain/keychain Signed-off-by: Quentin Young --- lib/command.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/command.c b/lib/command.c index 7781fb02e6..f28a55ec6d 100644 --- a/lib/command.c +++ b/lib/command.c @@ -59,7 +59,7 @@ const char *node_names[] = { "vnc debug", // DEBUG_VNC_NODE, "aaa", // AAA_NODE, "keychain", // KEYCHAIN_NODE, - "leychain key", // KEYCHAIN_KEY_NODE, + "keychain key", // KEYCHAIN_KEY_NODE, "logical-router", // NS_NODE, "vrf", // VRF_NODE, "interface", // INTERFACE_NODE, From 5d0df50febdd73cf29783efb60b6f4d2f36a3fc9 Mon Sep 17 00:00:00 2001 From: Olivier Dugeon Date: Mon, 31 Jul 2017 18:03:00 +0200 Subject: [PATCH 58/75] Correct build TLV functions * Functions that build TLVs in ospf_te.c and ospf_te.c use 'tlvh + 1' to move the pointer to the TLV payload ifor strem_put(). * Correct this by using TLV_DATA() macro which is saffer. Signed-off-by: Olivier Dugeon --- ospfd/ospf_ri.c | 2 +- ospfd/ospf_te.c | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ospfd/ospf_ri.c b/ospfd/ospf_ri.c index e41b9c1524..13013bf8ca 100644 --- a/ospfd/ospf_ri.c +++ b/ospfd/ospf_ri.c @@ -506,7 +506,7 @@ static void build_tlv(struct stream *s, struct tlv_header *tlvh) if (ntohs(tlvh->type) != 0) { build_tlv_header(s, tlvh); - stream_put(s, tlvh + 1, TLV_BODY_SIZE(tlvh)); + stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh)); } return; } diff --git a/ospfd/ospf_te.c b/ospfd/ospf_te.c index 521844b9ea..482d9d48c5 100644 --- a/ospfd/ospf_te.c +++ b/ospfd/ospf_te.c @@ -1065,7 +1065,7 @@ static void build_router_tlv(struct stream *s) struct tlv_header *tlvh = &OspfMplsTE.router_addr.header; if (ntohs(tlvh->type) != 0) { build_tlv_header(s, tlvh); - stream_put(s, tlvh + 1, TLV_BODY_SIZE(tlvh)); + stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh)); } return; } @@ -1075,7 +1075,7 @@ static void build_link_subtlv(struct stream *s, struct tlv_header *tlvh) if ((tlvh != NULL) && (ntohs(tlvh->type) != 0)) { build_tlv_header(s, tlvh); - stream_put(s, tlvh + 1, TLV_BODY_SIZE(tlvh)); + stream_put(s, TLV_DATA(tlvh), TLV_BODY_SIZE(tlvh)); } return; } @@ -2141,7 +2141,7 @@ static void ospf_mpls_te_show_info(struct vty *vty, struct ospf_lsa *lsa) case TE_TLV_LINK: sum += show_vty_link_header(vty, tlvh); subfunc = ospf_mpls_te_show_link_subtlv; - next = tlvh + 1; + next = TLV_DATA(tlvh); break; default: sum += show_vty_unknown_tlv(vty, tlvh); From 4a121f99f762258b4382b8a68f28094849fc3dfa Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 24 May 2017 17:48:12 +0200 Subject: [PATCH 59/75] build: convert lib/ to non-recursive build Signed-off-by: David Lamparter --- Makefile.am | 28 ++++- common.am | 11 +- configure.ac | 8 +- lib/.gitignore | 2 +- lib/Makefile | 10 ++ lib/Makefile.am | 155 --------------------------- lib/command_lex.l | 4 +- lib/command_parse.y | 4 +- lib/defun_lex.l | 2 +- lib/subdir.am | 253 ++++++++++++++++++++++++++++++++++++++++++++ 10 files changed, 306 insertions(+), 171 deletions(-) create mode 100644 lib/Makefile delete mode 100644 lib/Makefile.am create mode 100644 lib/subdir.am diff --git a/Makefile.am b/Makefile.am index 0092ba8c10..0ec8986b7b 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,18 +1,38 @@ ## Process this file with automake to produce Makefile.in. -SUBDIRS = lib qpb fpm @ZEBRA@ @LIBRFP@ @RFPTEST@ \ +AUTOMAKE_OPTIONS = subdir-objects 1.12 +include common.am + +AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib +AM_CFLAGS = $(WERROR) +DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" + +EXTRA_DIST = +BUILT_SOURCES = + +bin_PROGRAMS = +sbin_PROGRAMS = +noinst_PROGRAMS = +noinst_HEADERS = +noinst_LIBRARIES = +lib_LTLIBRARIES = +pkginclude_HEADERS = + +include lib/subdir.am + +SUBDIRS = . qpb fpm @ZEBRA@ @LIBRFP@ @RFPTEST@ \ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @LDPD@ \ @ISISD@ @PIMD@ @NHRPD@ @EIGRPD@ @BABELD@ \ @WATCHFRR@ @VTYSH@ @OSPFCLIENT@ @DOC@ m4 @pkgsrcdir@ \ redhat @SOLARIS@ tests tools snapcraft -DIST_SUBDIRS = lib qpb fpm zebra bgpd ripd ripngd ospfd ospf6d ldpd \ +DIST_SUBDIRS = . qpb fpm zebra bgpd ripd ripngd ospfd ospf6d ldpd \ isisd watchfrr vtysh ospfclient doc m4 pkgsrc redhat tests \ solaris pimd nhrpd eigrpd bgpd/rfp-example/librfp \ bgpd/rfp-example/rfptest tools snapcraft babeld python \ # end -EXTRA_DIST = aclocal.m4 SERVICES REPORTING-BUGS \ +EXTRA_DIST += aclocal.m4 SERVICES REPORTING-BUGS \ update-autotools \ vtysh/Makefile.in vtysh/Makefile.am \ tools/rrcheck.pl tools/rrlookup.pl tools/zc.pl \ @@ -20,4 +40,4 @@ EXTRA_DIST = aclocal.m4 SERVICES REPORTING-BUGS \ ACLOCAL_AMFLAGS = -I m4 -noinst_HEADERS = defaults.h +noinst_HEADERS += defaults.h diff --git a/common.am b/common.am index 0ccc4c9fd1..67e54d17d5 100644 --- a/common.am +++ b/common.am @@ -10,10 +10,17 @@ am__v_CLIPPY_1 = SUFFIXES = _clippy.c .c_clippy.c: - $(AM_V_at)$(MAKE) -C $(top_builddir)/$(CLIPPYDIR) clippy - $(AM_V_CLIPPY)$(top_builddir)/$(CLIPPYDIR)/clippy $(top_srcdir)/python/clidef.py $< > $@.tmp + $(AM_V_at)$(MAKE) -C $(top_builddir)/$(HOSTTOOLS) lib/clippy + $(AM_V_CLIPPY)$(top_builddir)/$(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py $< > $@.tmp @{ test -f $@ && diff $@.tmp $@ >/dev/null 2>/dev/null; } && rm $@.tmp || mv $@.tmp $@ +## automake's "ylwrap" is a great piece of GNU software... not. +.l.c: + $(AM_V_LEX)$(am__skiplex) $(LEXCOMPILE) $< +.y.c: + $(AM_V_YACC)$(am__skipyacc) $(YACCCOMPILE) $< + + if HAVE_PROTOBUF # Uncomment to use an non-system version of libprotobuf-c. diff --git a/configure.ac b/configure.ac index cbda2fc84f..291a08573c 100755 --- a/configure.ac +++ b/configure.ac @@ -46,12 +46,12 @@ AS_IF([test "$host" != "$build"], [ AC_MSG_NOTICE([...]) build_clippy="false" - CLIPPYDIR="hosttools/lib" + HOSTTOOLS="hosttools/" ], [ build_clippy="true" - CLIPPYDIR="lib" + HOSTTOOLS="" ]) -AC_SUBST(CLIPPYDIR) +AC_SUBST(HOSTTOOLS) AM_CONDITIONAL([BUILD_CLIPPY], [$build_clippy]) # Disable portability warnings -- our automake code (in particular @@ -1969,7 +1969,7 @@ AC_CACHE_VAL(ac_cv_htonl_works, ) AC_MSG_RESULT($ac_cv_htonl_works) -AC_CONFIG_FILES([Makefile lib/Makefile qpb/Makefile zebra/Makefile ripd/Makefile +AC_CONFIG_FILES([Makefile qpb/Makefile zebra/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile watchfrr/Makefile ospf6d/Makefile ldpd/Makefile isisd/Makefile vtysh/Makefile doc/Makefile ospfclient/Makefile tests/Makefile m4/Makefile diff --git a/lib/.gitignore b/lib/.gitignore index 60cde149f5..94f401ebe6 100644 --- a/lib/.gitignore +++ b/lib/.gitignore @@ -1,4 +1,4 @@ -Makefile +!Makefile Makefile.in *.o *.lo diff --git a/lib/Makefile b/lib/Makefile new file mode 100644 index 0000000000..62051ac4cc --- /dev/null +++ b/lib/Makefile @@ -0,0 +1,10 @@ +all: ALWAYS + @$(MAKE) -s -C .. lib/libfrr.la +%: ALWAYS + @$(MAKE) -s -C .. lib/$@ + +Makefile: + #nothing +ALWAYS: +.PHONY: ALWAYS makefiles +.SUFFIXES: diff --git a/lib/Makefile.am b/lib/Makefile.am deleted file mode 100644 index 5847ad4939..0000000000 --- a/lib/Makefile.am +++ /dev/null @@ -1,155 +0,0 @@ -## Process this file with automake to produce Makefile.in. - -include ../common.am - -AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib -AM_CFLAGS = $(WERROR) -DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -AM_YFLAGS = -d -Dapi.prefix=@BISON_OPENBRACE@cmd_yy@BISON_CLOSEBRACE@ @BISON_VERBOSE@ - -command_lex.h: command_lex.c - @if test ! -f $@; then rm -f command_lex.c; else :; fi - @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) command_lex.c; else :; fi -command_parse.lo: command_lex.h -clippy-command_parse.$(OBJEXT): command_lex.h - -lib_LTLIBRARIES = libfrr.la -libfrr_la_LDFLAGS = -version-info 0:0:0 - -libfrr_la_SOURCES = \ - network.c pid_output.c getopt.c getopt1.c \ - checksum.c vector.c linklist.c vty.c openbsd-tree.c \ - graph.c command_parse.y command_lex.l command_match.c \ - command_graph.c \ - command.c \ - sockunion.c prefix.c thread.c if.c buffer.c table.c hash.c \ - filter.c routemap.c distribute.c stream.c log.c plist.c \ - zclient.c sockopt.c md5.c if_rmap.c keychain.c privs.c \ - sigevent.c pqueue.c jhash.c workqueue.c nexthop.c json.c \ - ptm_lib.c csv.c bfd.c vrf.c systemd.c ns.c memory.c memory_vty.c \ - imsg-buffer.c imsg.c skiplist.c \ - qobj.c wheel.c \ - event_counter.c \ - grammar_sandbox.c \ - srcdest_table.c \ - spf_backoff.c \ - libfrr.c \ - strlcpy.c \ - strlcat.c \ - sha256.c \ - module.c \ - hook.c \ - frr_pthread.c \ - termtable.c \ - # end - -BUILT_SOURCES = route_types.h gitversion.h command_parse.h command_lex.h - -libfrr_la_LIBADD = @LIBCAP@ - -if SNMP -lib_LTLIBRARIES += libfrrsnmp.la -endif - -libfrrsnmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -libfrrsnmp_la_LDFLAGS = -version-info 0:0:0 -libfrrsnmp_la_LIBADD = libfrr.la $(SNMP_LIBS) -libfrrsnmp_la_SOURCES = \ - agentx.c \ - smux.c \ - snmp.c \ - #end - -pkginclude_HEADERS = \ - frratomic.h \ - buffer.h checksum.h filter.h getopt.h hash.h \ - if.h linklist.h log.h \ - graph.h command_match.h \ - command_graph.h \ - command.h \ - memory.h network.h prefix.h routemap.h distribute.h sockunion.h \ - stream.h table.h thread.h vector.h version.h vty.h zebra.h \ - plist.h zclient.h sockopt.h smux.h md5.h if_rmap.h keychain.h \ - privs.h sigevent.h pqueue.h jhash.h zassert.h \ - workqueue.h route_types.h libospf.h nexthop.h json.h \ - ptm_lib.h csv.h bfd.h vrf.h ns.h systemd.h bitfield.h \ - fifo.h memory_vty.h mpls.h imsg.h openbsd-queue.h openbsd-tree.h \ - skiplist.h qobj.h wheel.h \ - event_counter.h \ - monotime.h \ - spf_backoff.h \ - srcdest_table.h \ - module.h \ - hook.h \ - libfrr.h \ - sha256.h \ - frr_pthread.h \ - vrf_int.h \ - termtable.h \ - vlan.h \ - vxlan.h \ - ipaddr.h \ - # end - -noinst_HEADERS = \ - plist_int.h \ - log_int.h \ - clippy.h \ - # end - -noinst_PROGRAMS = grammar_sandbox -if BUILD_CLIPPY -noinst_PROGRAMS += clippy -endif - -grammar_sandbox_SOURCES = grammar_sandbox_main.c -grammar_sandbox_LDADD = libfrr.la - -clippy_SOURCES = \ - defun_lex.l \ - command_parse.y \ - command_lex.l \ - command_graph.c \ - command_py.c \ - memory.c \ - graph.c \ - vector.c \ - clippy.c \ - # end -clippy_CPPFLAGS = -D_GNU_SOURCE -clippy_CFLAGS = $(PYTHON_CFLAGS) -clippy_LDADD = $(PYTHON_LIBS) -clippy-command_graph.$(OBJEXT): route_types.h - -plist.lo: plist_clippy.c - -EXTRA_DIST = \ - queue.h \ - command_lex.h \ - route_types.pl route_types.txt \ - gitversion.pl - -route_types.h: $(srcdir)/route_types.txt $(srcdir)/route_types.pl - @PERL@ $(srcdir)/route_types.pl < $(srcdir)/route_types.txt > $@ - -if GIT_VERSION - -# bit of a trick here to always have up-to-date git stamps without triggering -# unneccessary rebuilds. .PHONY causes the .tmp file to be rebuilt always, -# but if we use that on gitversion.h it'll ripple through the .c file deps. -# (even if gitversion.h's file timestamp doesn't change, make will think it -# did, because of .PHONY...) - -.PHONY: gitversion.h.tmp -.SILENT: gitversion.h gitversion.h.tmp -GITH=gitversion.h -gitversion.h.tmp: $(srcdir)/../.git - @PERL@ $(srcdir)/gitversion.pl $(srcdir) > ${GITH}.tmp -gitversion.h: gitversion.h.tmp - { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp -v ${GITH}.tmp ${GITH} - -else -.PHONY: gitversion.h -gitversion.h: - true -endif diff --git a/lib/command_lex.l b/lib/command_lex.l index c020d193a1..fddbf7b287 100644 --- a/lib/command_lex.l +++ b/lib/command_lex.l @@ -49,8 +49,8 @@ RANGE \({NUMBER}[ ]?\-[ ]?{NUMBER}\) %option noyywrap %option nounput %option noinput -%option outfile="command_lex.c" -%option header-file="command_lex.h" +%option outfile="lib/command_lex.c" +%option header-file="lib/command_lex.h" %option prefix="cmd_yy" %option reentrant %option bison-bridge diff --git a/lib/command_parse.y b/lib/command_parse.y index ba042c33be..1bc8ea1a44 100644 --- a/lib/command_parse.y +++ b/lib/command_parse.y @@ -33,8 +33,8 @@ /* define api.prefix {cmd_yy} */ /* names for generated header and parser files */ -%defines "command_parse.h" -%output "command_parse.c" +%defines "lib/command_parse.h" +%output "lib/command_parse.c" /* note: code blocks are output in order, to both .c and .h: * 1. %code requires diff --git a/lib/defun_lex.l b/lib/defun_lex.l index 8aa37a62a2..024445be63 100644 --- a/lib/defun_lex.l +++ b/lib/defun_lex.l @@ -85,7 +85,7 @@ SPECIAL [(),] %option noyywrap %option noinput %option nounput -%option outfile="defun_lex.c" +%option outfile="lib/defun_lex.c" %option prefix="def_yy" %option 8bit diff --git a/lib/subdir.am b/lib/subdir.am new file mode 100644 index 0000000000..a49781e18c --- /dev/null +++ b/lib/subdir.am @@ -0,0 +1,253 @@ +# +# libfrr +# +lib_LTLIBRARIES += lib/libfrr.la +lib_libfrr_la_LDFLAGS = -version-info 0:0:0 +lib_libfrr_la_LIBADD = @LIBCAP@ + +lib_libfrr_la_SOURCES = \ + lib/bfd.c \ + lib/buffer.c \ + lib/checksum.c \ + lib/command.c \ + lib/command_graph.c \ + lib/command_lex.l \ + lib/command_match.c \ + lib/command_parse.y \ + lib/csv.c \ + lib/distribute.c \ + lib/event_counter.c \ + lib/filter.c \ + lib/frr_pthread.c \ + lib/getopt.c \ + lib/getopt1.c \ + lib/grammar_sandbox.c \ + lib/graph.c \ + lib/hash.c \ + lib/hook.c \ + lib/if.c \ + lib/if_rmap.c \ + lib/imsg-buffer.c \ + lib/imsg.c \ + lib/jhash.c \ + lib/json.c \ + lib/keychain.c \ + lib/libfrr.c \ + lib/linklist.c \ + lib/log.c \ + lib/md5.c \ + lib/memory.c \ + lib/memory_vty.c \ + lib/module.c \ + lib/network.c \ + lib/nexthop.c \ + lib/ns.c \ + lib/openbsd-tree.c \ + lib/pid_output.c \ + lib/plist.c \ + lib/pqueue.c \ + lib/prefix.c \ + lib/privs.c \ + lib/ptm_lib.c \ + lib/qobj.c \ + lib/routemap.c \ + lib/sha256.c \ + lib/sigevent.c \ + lib/skiplist.c \ + lib/sockopt.c \ + lib/sockunion.c \ + lib/spf_backoff.c \ + lib/srcdest_table.c \ + lib/stream.c \ + lib/strlcat.c \ + lib/strlcpy.c \ + lib/systemd.c \ + lib/table.c \ + lib/termtable.c \ + lib/thread.c \ + lib/vector.c \ + lib/vrf.c \ + lib/vty.c \ + lib/wheel.c \ + lib/workqueue.c \ + lib/zclient.c \ + # end + +lib/plist.lo: lib/plist_clippy.c + +pkginclude_HEADERS += \ + lib/bfd.h \ + lib/bitfield.h \ + lib/buffer.h \ + lib/checksum.h \ + lib/command.h \ + lib/command_graph.h \ + lib/command_match.h \ + lib/csv.h \ + lib/distribute.h \ + lib/event_counter.h \ + lib/fifo.h \ + lib/filter.h \ + lib/frr_pthread.h \ + lib/frratomic.h \ + lib/getopt.h \ + lib/graph.h \ + lib/hash.h \ + lib/hook.h \ + lib/if.h \ + lib/if_rmap.h \ + lib/imsg.h \ + lib/ipaddr.h \ + lib/jhash.h \ + lib/json.h \ + lib/keychain.h \ + lib/libfrr.h \ + lib/libospf.h \ + lib/linklist.h \ + lib/log.h \ + lib/md5.h \ + lib/memory.h \ + lib/memory_vty.h \ + lib/module.h \ + lib/monotime.h \ + lib/mpls.h \ + lib/network.h \ + lib/nexthop.h \ + lib/ns.h \ + lib/openbsd-queue.h \ + lib/openbsd-tree.h \ + lib/plist.h \ + lib/pqueue.h \ + lib/prefix.h \ + lib/privs.h \ + lib/ptm_lib.h \ + lib/qobj.h \ + lib/route_types.h \ + lib/routemap.h \ + lib/sha256.h \ + lib/sigevent.h \ + lib/skiplist.h \ + lib/smux.h \ + lib/sockopt.h \ + lib/sockunion.h \ + lib/spf_backoff.h \ + lib/srcdest_table.h \ + lib/stream.h \ + lib/systemd.h \ + lib/table.h \ + lib/termtable.h \ + lib/thread.h \ + lib/vector.h \ + lib/version.h \ + lib/vlan.h \ + lib/vrf.h \ + lib/vrf_int.h \ + lib/vty.h \ + lib/vxlan.h \ + lib/wheel.h \ + lib/workqueue.h \ + lib/zassert.h \ + lib/zclient.h \ + lib/zebra.h \ + # end + +noinst_HEADERS += \ + lib/clippy.h \ + lib/log_int.h \ + lib/plist_int.h \ + #end + +# +# SNMP support +# +if SNMP +lib_LTLIBRARIES += lib/libfrrsnmp.la +endif + +lib_libfrrsnmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) +lib_libfrrsnmp_la_LDFLAGS = -version-info 0:0:0 +lib_libfrrsnmp_la_LIBADD = lib/libfrr.la $(SNMP_LIBS) +lib_libfrrsnmp_la_SOURCES = \ + lib/agentx.c \ + lib/smux.c \ + lib/snmp.c \ + # end + +# +# CLI utilities +# +noinst_PROGRAMS += \ + lib/clippy \ + lib/grammar_sandbox \ + # end + +lib_grammar_sandbox_SOURCES = \ + lib/grammar_sandbox_main.c +lib_grammar_sandbox_LDADD = \ + lib/libfrr.la + +lib_clippy_CPPFLAGS = -D_GNU_SOURCE -I$(top_srcdir)/lib +lib_clippy_CFLAGS = $(PYTHON_CFLAGS) +lib_clippy_LDADD = $(PYTHON_LIBS) +lib_clippy_SOURCES = \ + lib/clippy.c \ + lib/command_graph.c \ + lib/command_lex.l \ + lib/command_parse.y \ + lib/command_py.c \ + lib/defun_lex.l \ + lib/graph.c \ + lib/memory.c \ + lib/vector.c \ + # end + + +# +# generated sources & extra foo +# +EXTRA_DIST += \ + lib/command_lex.h \ + lib/gitversion.pl \ + lib/queue.h \ + lib/route_types.pl \ + lib/route_types.txt \ + # end + +BUILT_SOURCES += \ + lib/command_lex.h \ + lib/command_parse.h \ + lib/gitversion.h \ + lib/route_types.h \ + # end + +AM_YFLAGS = -d -Dapi.prefix=@BISON_OPENBRACE@cmd_yy@BISON_CLOSEBRACE@ @BISON_VERBOSE@ + +lib/command_lex.h: lib/command_lex.c + @if test ! -f $@; then rm -f "lib/command_lex.c"; else :; fi + @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) "lib/command_lex.c"; else :; fi +lib/command_parse.lo: lib/command_lex.h +lib/lib_clippy-command_parse.$(OBJEXT): lib/command_lex.h + +lib/route_types.h: $(top_srcdir)/lib/route_types.txt $(top_srcdir)/lib/route_types.pl + @PERL@ $(top_srcdir)/lib/route_types.pl < $(top_srcdir)/lib/route_types.txt > $@ + +if GIT_VERSION +# bit of a trick here to always have up-to-date git stamps without triggering +# unneccessary rebuilds. .PHONY causes the .tmp file to be rebuilt always, +# but if we use that on gitversion.h it'll ripple through the .c file deps. +# (even if gitversion.h's file timestamp doesn't change, make will think it +# did, because of .PHONY...) + +.PHONY: lib/gitversion.h.tmp +.SILENT: lib/gitversion.h lib/gitversion.h.tmp +GITH=lib/gitversion.h +lib/gitversion.h.tmp: $(top_srcdir)/.git + @PERL@ $(top_srcdir)/lib/gitversion.pl $(top_srcdir) > ${GITH}.tmp +lib/gitversion.h: lib/gitversion.h.tmp + { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp -v ${GITH}.tmp ${GITH} + +else +.PHONY: lib/gitversion.h +lib/gitversion.h: + true +endif From 64d44794fe8f17c0da6d73329600d12b45d740e5 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Sat, 22 Jul 2017 19:01:46 +0200 Subject: [PATCH 60/75] build: convert zebra/ to non-recursive build Signed-off-by: David Lamparter --- Makefile.am | 12 +++- configure.ac | 10 +-- zebra/.gitignore | 2 +- zebra/Makefile | 10 +++ zebra/Makefile.am | 96 ----------------------------- zebra/subdir.am | 152 ++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 174 insertions(+), 108 deletions(-) create mode 100644 zebra/Makefile delete mode 100644 zebra/Makefile.am create mode 100644 zebra/subdir.am diff --git a/Makefile.am b/Makefile.am index 0ec8986b7b..415b80d516 100644 --- a/Makefile.am +++ b/Makefile.am @@ -3,30 +3,36 @@ AUTOMAKE_OPTIONS = subdir-objects 1.12 include common.am -AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib +AM_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir) -I$(top_builddir)/lib AM_CFLAGS = $(WERROR) DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" +LIBCAP = @LIBCAP@ EXTRA_DIST = BUILT_SOURCES = +examplesdir = $(exampledir) + bin_PROGRAMS = sbin_PROGRAMS = noinst_PROGRAMS = noinst_HEADERS = noinst_LIBRARIES = lib_LTLIBRARIES = +module_LTLIBRARIES = pkginclude_HEADERS = +dist_examples_DATA = include lib/subdir.am +include zebra/subdir.am -SUBDIRS = . qpb fpm @ZEBRA@ @LIBRFP@ @RFPTEST@ \ +SUBDIRS = . qpb fpm @LIBRFP@ @RFPTEST@ \ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @LDPD@ \ @ISISD@ @PIMD@ @NHRPD@ @EIGRPD@ @BABELD@ \ @WATCHFRR@ @VTYSH@ @OSPFCLIENT@ @DOC@ m4 @pkgsrcdir@ \ redhat @SOLARIS@ tests tools snapcraft -DIST_SUBDIRS = . qpb fpm zebra bgpd ripd ripngd ospfd ospf6d ldpd \ +DIST_SUBDIRS = . qpb fpm bgpd ripd ripngd ospfd ospf6d ldpd \ isisd watchfrr vtysh ospfclient doc m4 pkgsrc redhat tests \ solaris pimd nhrpd eigrpd bgpd/rfp-example/librfp \ bgpd/rfp-example/rfptest tools snapcraft babeld python \ diff --git a/configure.ac b/configure.ac index 291a08573c..0fa467ac0c 100755 --- a/configure.ac +++ b/configure.ac @@ -1375,12 +1375,7 @@ fi dnl -------------------- dnl Daemon disable check dnl -------------------- -if test "${enable_zebra}" = "no";then - ZEBRA="" -else - ZEBRA="zebra" -fi -AM_CONDITIONAL(ZEBRA, test "x$ZEBRA" = "xzebra") +AM_CONDITIONAL(ZEBRA, test "${enable_zebra}" != "no") if test "${enable_bgpd}" = "no";then BGPD="" @@ -1506,7 +1501,6 @@ fi AM_CONDITIONAL([ENABLE_BGP_VNC], [test x${enable_bgp_vnc} != xno]) AC_SUBST(DOC) -AC_SUBST(ZEBRA) AC_SUBST(RFPTEST) AC_SUBST(LIBRFP) AC_SUBST(RFPINC) @@ -1969,7 +1963,7 @@ AC_CACHE_VAL(ac_cv_htonl_works, ) AC_MSG_RESULT($ac_cv_htonl_works) -AC_CONFIG_FILES([Makefile qpb/Makefile zebra/Makefile ripd/Makefile +AC_CONFIG_FILES([Makefile qpb/Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile watchfrr/Makefile ospf6d/Makefile ldpd/Makefile isisd/Makefile vtysh/Makefile doc/Makefile ospfclient/Makefile tests/Makefile m4/Makefile diff --git a/zebra/.gitignore b/zebra/.gitignore index d0a7528539..7a1321e546 100644 --- a/zebra/.gitignore +++ b/zebra/.gitignore @@ -1,4 +1,4 @@ -Makefile +!Makefile Makefile.in *.o zebra diff --git a/zebra/Makefile b/zebra/Makefile new file mode 100644 index 0000000000..625a7168eb --- /dev/null +++ b/zebra/Makefile @@ -0,0 +1,10 @@ +all: ALWAYS + @$(MAKE) -s -C .. zebra/zebra +%: ALWAYS + @$(MAKE) -s -C .. zebra/$@ + +Makefile: + #nothing +ALWAYS: +.PHONY: ALWAYS makefiles +.SUFFIXES: diff --git a/zebra/Makefile.am b/zebra/Makefile.am deleted file mode 100644 index 67031ea361..0000000000 --- a/zebra/Makefile.am +++ /dev/null @@ -1,96 +0,0 @@ -include ../common.am - -## Process this file with automake to produce Makefile.in. - -AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib -DEFS = @DEFS@ -DSYSCONFDIR=\"$(sysconfdir)/\" -INSTALL_SDATA=@INSTALL@ -m 600 - -LIBCAP = @LIBCAP@ - -ipforward = @IPFORWARD@ -if_method = @IF_METHOD@ -rt_method = @RT_METHOD@ -rtread_method = @RTREAD_METHOD@ -kernel_method = @KERNEL_METHOD@ -ioctl_method = @IOCTL_METHOD@ -mpls_method = @MPLS_METHOD@ - -otherobj = $(ioctl_method) $(ipforward) $(if_method) \ - $(rt_method) $(rtread_method) $(kernel_method) $(mpls_method) - -AM_CFLAGS = $(WERROR) - -sbin_PROGRAMS = zebra -module_LTLIBRARIES = - -zebra_SOURCES = \ - zebra_memory.c \ - zserv.c main.c interface.c connected.c zebra_rib.c zebra_routemap.c \ - redistribute.c debug.c rtadv.c zebra_vty.c \ - irdp_main.c irdp_interface.c irdp_packet.c router-id.c \ - zebra_ptm.c zebra_rnh.c zebra_ptm_redistribute.c \ - zebra_ns.c zebra_vrf.c zebra_static.c zebra_mpls.c zebra_mpls_vty.c \ - zebra_mroute.c \ - label_manager.c \ - zebra_l2.c \ - zebra_vxlan.c \ - # end - -zebra_vty.o: zebra_vty_clippy.c - -noinst_HEADERS = \ - zebra_memory.h \ - connected.h ioctl.h rib.h rt.h zserv.h redistribute.h debug.h rtadv.h \ - interface.h ipforward.h irdp.h router-id.h kernel_socket.h \ - rt_netlink.h zebra_fpm_private.h zebra_rnh.h \ - zebra_ptm_redistribute.h zebra_ptm.h zebra_routemap.h \ - zebra_ns.h zebra_vrf.h ioctl_solaris.h zebra_static.h zebra_mpls.h \ - kernel_netlink.h if_netlink.h zebra_mroute.h label_manager.h \ - zebra_l2.h zebra_vxlan_private.h zebra_vxlan.h - -zebra_LDADD = $(otherobj) ../lib/libfrr.la $(LIBCAP) - -zebra_DEPENDENCIES = $(otherobj) - -if SNMP -module_LTLIBRARIES += zebra_snmp.la -endif -zebra_snmp_la_SOURCES = zebra_snmp.c -zebra_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) -zebra_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic -zebra_snmp_la_LIBADD = ../lib/libfrrsnmp.la - -if FPM -module_LTLIBRARIES += zebra_fpm.la -endif -zebra_fpm_la_LDFLAGS = -avoid-version -module -shared -export-dynamic -zebra_fpm_la_LIBADD = $(Q_FPM_PB_CLIENT_LDOPTS) -zebra_fpm_la_SOURCES = zebra_fpm.c -if HAVE_NETLINK -zebra_fpm_la_SOURCES += zebra_fpm_netlink.c -endif -if HAVE_PROTOBUF -zebra_fpm_la_SOURCES += zebra_fpm_protobuf.c -if DEV_BUILD -zebra_fpm_la_SOURCES += zebra_fpm_dt.c -endif -endif - - -EXTRA_DIST = if_ioctl.c if_ioctl_solaris.c if_netlink.c \ - if_sysctl.c ipforward_proc.c \ - ipforward_solaris.c ipforward_sysctl.c rt_netlink.c \ - rt_socket.c rtread_netlink.c rtread_sysctl.c \ - rtread_getmsg.c kernel_socket.c kernel_netlink.c \ - ioctl.c ioctl_solaris.c \ - zebra_mpls_netlink.c zebra_mpls_openbsd.c zebra_mpls_null.c \ - GNOME-SMI GNOME-PRODUCT-ZEBRA-MIB - -client : client_main.o ../lib/libfrr.la - $(CC) -g -o client client_main.o ../liblzebra.la $(LIBS) $(LIB_IPV6) - -frrconfdir = $(sysconfdir) - -examplesdir = $(exampledir) -dist_examples_DATA = zebra.conf.sample diff --git a/zebra/subdir.am b/zebra/subdir.am new file mode 100644 index 0000000000..e69aa6334c --- /dev/null +++ b/zebra/subdir.am @@ -0,0 +1,152 @@ +# +# zebra +# + +if ZEBRA +sbin_PROGRAMS += zebra/zebra +dist_examples_DATA += zebra/zebra.conf.sample + +if SNMP +module_LTLIBRARIES += zebra/zebra_snmp.la +endif +if FPM +module_LTLIBRARIES += zebra/zebra_fpm.la +endif + +## endif ZEBRA +endif + +ipforward = @IPFORWARD@ +if_method = @IF_METHOD@ +rt_method = @RT_METHOD@ +rtread_method = @RTREAD_METHOD@ +kernel_method = @KERNEL_METHOD@ +ioctl_method = @IOCTL_METHOD@ +mpls_method = @MPLS_METHOD@ + +otherobj = \ + zebra/$(ioctl_method) \ + zebra/$(ipforward) \ + zebra/$(if_method) \ + zebra/$(rt_method) \ + zebra/$(rtread_method) \ + zebra/$(kernel_method) \ + zebra/$(mpls_method) \ + # end + +zebra_zebra_LDADD = $(otherobj) lib/libfrr.la $(LIBCAP) +zebra_zebra_DEPENDENCIES = $(otherobj) lib/libfrr.la + +zebra_zebra_SOURCES = \ + zebra/connected.c \ + zebra/debug.c \ + zebra/interface.c \ + zebra/irdp_interface.c \ + zebra/irdp_main.c \ + zebra/irdp_packet.c \ + zebra/label_manager.c \ + zebra/main.c \ + zebra/redistribute.c \ + zebra/router-id.c \ + zebra/rtadv.c \ + zebra/zebra_l2.c \ + zebra/zebra_memory.c \ + zebra/zebra_mpls.c \ + zebra/zebra_mpls_vty.c \ + zebra/zebra_mroute.c \ + zebra/zebra_ns.c \ + zebra/zebra_ptm.c \ + zebra/zebra_ptm_redistribute.c \ + zebra/zebra_rib.c \ + zebra/zebra_rnh.c \ + zebra/zebra_routemap.c \ + zebra/zebra_static.c \ + zebra/zebra_vrf.c \ + zebra/zebra_vty.c \ + zebra/zebra_vxlan.c \ + zebra/zserv.c \ + # end + +zebra/zebra_vty.$(OBJEXT): zebra/zebra_vty_clippy.c + +noinst_HEADERS += \ + zebra/connected.h \ + zebra/debug.h \ + zebra/if_netlink.h \ + zebra/interface.h \ + zebra/ioctl.h \ + zebra/ioctl_solaris.h \ + zebra/ipforward.h \ + zebra/irdp.h \ + zebra/kernel_netlink.h \ + zebra/kernel_socket.h \ + zebra/label_manager.h \ + zebra/redistribute.h \ + zebra/rib.h \ + zebra/router-id.h \ + zebra/rt.h \ + zebra/rt_netlink.h \ + zebra/rtadv.h \ + zebra/zebra_fpm_private.h \ + zebra/zebra_l2.h \ + zebra/zebra_memory.h \ + zebra/zebra_mpls.h \ + zebra/zebra_mroute.h \ + zebra/zebra_ns.h \ + zebra/zebra_ptm.h \ + zebra/zebra_ptm_redistribute.h \ + zebra/zebra_rnh.h \ + zebra/zebra_routemap.h \ + zebra/zebra_static.h \ + zebra/zebra_vrf.h \ + zebra/zebra_vxlan.h \ + zebra/zebra_vxlan_private.h \ + zebra/zserv.h \ + # end + +zebra_zebra_snmp_la_SOURCES = zebra/zebra_snmp.c +zebra_zebra_snmp_la_CFLAGS = $(WERROR) $(SNMP_CFLAGS) +zebra_zebra_snmp_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_zebra_snmp_la_LIBADD = lib/libfrrsnmp.la + +zebra_zebra_fpm_la_LDFLAGS = -avoid-version -module -shared -export-dynamic +zebra_zebra_fpm_la_LIBADD = $(Q_FPM_PB_CLIENT_LDOPTS) +zebra_zebra_fpm_la_SOURCES = zebra/zebra_fpm.c +if HAVE_NETLINK +zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_netlink.c +endif +if HAVE_PROTOBUF +zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_protobuf.c +if DEV_BUILD +zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_dt.c +endif +endif + +EXTRA_DIST += \ + zebra/GNOME-SMI \ + zebra/GNOME-PRODUCT-ZEBRA-MIB \ + zebra/if_ioctl.c \ + zebra/if_ioctl_solaris.c \ + zebra/if_netlink.c \ + zebra/if_sysctl.c \ + zebra/ioctl.c \ + zebra/ioctl_solaris.c \ + zebra/ipforward_proc.c \ + zebra/ipforward_solaris.c \ + zebra/ipforward_sysctl.c \ + zebra/kernel_netlink.c \ + zebra/kernel_socket.c \ + zebra/rt_netlink.c \ + zebra/rt_socket.c \ + zebra/rtread_getmsg.c \ + zebra/rtread_netlink.c \ + zebra/rtread_sysctl.c \ + zebra/zebra_mpls_netlink.c \ + zebra/zebra_mpls_null.c \ + zebra/zebra_mpls_openbsd.c \ + # end + +# -- unmaintained -- +# noinst_PROGRAMS += zebra/client +# zebra_client_SOURCES = zebra/client_main.c +# zebra_client_LDADD = lib/libfrr.la From ddfeb48652f8318acc8b18c2c377515de2bf1b31 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Wed, 26 Jul 2017 19:49:15 +0200 Subject: [PATCH 61/75] build: zebra: remove *_method Makefile hacks replace with preprocessor checks in source files. Much simpler... Signed-off-by: David Lamparter --- configure.ac | 309 ++++++++++--------------------------- zebra/if_ioctl.c | 4 + zebra/if_ioctl_solaris.c | 4 + zebra/if_netlink.c | 4 + zebra/if_sysctl.c | 4 + zebra/ioctl.c | 4 + zebra/ioctl_solaris.c | 4 + zebra/ipforward_proc.c | 4 + zebra/ipforward_solaris.c | 5 + zebra/ipforward_sysctl.c | 5 + zebra/kernel_netlink.c | 4 + zebra/kernel_socket.c | 5 + zebra/rt_netlink.c | 5 + zebra/rt_socket.c | 5 + zebra/rtread_getmsg.c | 4 + zebra/rtread_netlink.c | 4 + zebra/rtread_sysctl.c | 4 + zebra/subdir.am | 62 +++----- zebra/zebra_fpm_netlink.c | 4 + zebra/zebra_mpls_netlink.c | 5 + zebra/zebra_mpls_null.c | 4 + zebra/zebra_mpls_openbsd.c | 5 + 22 files changed, 190 insertions(+), 268 deletions(-) diff --git a/configure.ac b/configure.ac index 0fa467ac0c..b22361d40b 100755 --- a/configure.ac +++ b/configure.ac @@ -415,26 +415,6 @@ if test "${enable_rr_semantics}" != "no" ; then AC_DEFINE(HAVE_V6_RR_SEMANTICS,, Compile in v6 Route Replacement Semantics) fi -dnl ---------- -dnl MPLS check -dnl ---------- -AC_MSG_CHECKING(whether this OS has MPLS stack) -case "$host" in - *-linux*) - MPLS_METHOD="zebra_mpls_netlink.o" - AC_MSG_RESULT(Linux MPLS) - ;; - *-openbsd*) - MPLS_METHOD="zebra_mpls_openbsd.o" - AC_MSG_RESULT(OpenBSD MPLS) - ;; - *) - MPLS_METHOD="zebra_mpls_null.o" - AC_MSG_RESULT(Unsupported kernel) - ;; -esac -AC_SUBST(MPLS_METHOD) - if test "${enable_datacenter}" = "yes" ; then AC_DEFINE(HAVE_DATACENTER,,Compile extensions for a DataCenter) DFLT_NAME="datacenter" @@ -850,50 +830,52 @@ FRR_INCLUDES dnl V6 headers are checked below, after we check for v6 -dnl Some systems (Solaris 2.x) require libnsl (Network Services Library) -case "$host" in - [*-sunos5.[6-7]*] | [*-solaris2.[6-7]*]) - opsys=sol2-6 - AC_DEFINE(SUNOS_56, 1, SunOS 5.6 to 5.7) - AC_DEFINE(SUNOS_5, 1, SunOS 5) - AC_CHECK_LIB(xnet, main) - CURSES=-lcurses - SOLARIS="solaris" - ;; - [*-sunos5.[8-9]] \ - | [*-sunos5.1[0-9]] \ - | [*-sunos5.1[0-9].[0-9]] \ - | [*-solaris2.[8-9]] \ - | [*-solaris2.1[0-9]] \ - | [*-solaris2.1[0-9].[0-9]]) - opsys=sol8 - AC_DEFINE(SUNOS_59, 1, [SunOS 5.8 up]) - AC_DEFINE(SUNOS_5, 1, [SunOS 5]) - AC_CHECK_LIB(socket, main) - AC_CHECK_LIB(nsl, main) - AC_CHECK_LIB(umem, main) - AC_CHECK_FUNCS([printstack], - [AC_DEFINE([HAVE_PRINTSTACK],1,[Solaris printstack]) - AC_DEFINE([HAVE_STACK_TRACE],1,[Stack symbols decode functionality]) - ]) - CURSES=-lcurses - SOLARIS="solaris" - ;; - *-sunos5* | *-solaris2*) - AC_DEFINE(SUNOS_5,,SunOS 5, Unknown SunOS) - AC_CHECK_LIB(socket, main) - AC_CHECK_LIB(nsl, main) - CURSES=-lcurses - SOLARIS="solaris" - ;; - *-linux*) - opsys=gnu-linux - AC_DEFINE(GNU_LINUX,,GNU Linux) - ;; - *-openbsd*) - opsys=openbsd - AC_DEFINE(OPEN_BSD,,OpenBSD) - ;; +AC_MSG_CHECKING([which operating system interface to use]) +case "$host_os" in + sunos* | solaris2*) + AC_MSG_RESULT([Solaris]) + + AC_DEFINE(SUNOS_5, 1, [SunOS 5]) + AC_DEFINE(SOLARIS_IPV6, 1, Solaris IPv6) + + AC_CHECK_LIB(socket, main) + AC_CHECK_LIB(nsl, main) + AC_CHECK_LIB(umem, main) + AC_CHECK_FUNCS([printstack], [ + AC_DEFINE([HAVE_PRINTSTACK],1,[Solaris printstack]) + AC_DEFINE([HAVE_STACK_TRACE],1,[Stack symbols decode functionality]) + ]) + CURSES=-lcurses + SOLARIS="solaris" + ;; + linux*) + AC_MSG_RESULT([Linux]) + + AC_DEFINE(GNU_LINUX,,GNU Linux) + AC_DEFINE(HAVE_NETLINK,,netlink) + AC_DEFINE(LINUX_IPV6,1,Linux IPv6 stack) + + dnl Linux has a compilation problem with mixing + dnl netinet/in.h and linux/in6.h they are not + dnl compatible. There has been discussion on + dnl how to fix it but no real progress on implementation + dnl when they fix it, remove this + AC_DEFINE(IPV6_MINHOPCOUNT, 73, Linux ipv6 Min Hop Count) + + AC_CHECK_DECLS([IFLA_INFO_SLAVE_KIND], [], [], [#include ]) + ;; + openbsd*) + AC_MSG_RESULT([OpenBSD]) + + AC_DEFINE(OPEN_BSD,,OpenBSD) + AC_DEFINE(KAME,1,KAME IPv6) + ;; + *) + AC_MSG_RESULT([BSD]) + + AC_DEFINE(HAVE_NET_RT_IFLIST,,NET_RT_IFLIST) + AC_DEFINE(KAME,1,KAME IPv6) + ;; esac AC_SYS_LARGEFILE @@ -1049,26 +1031,6 @@ AC_CHECK_HEADER([asm-generic/unistd.h], AC_CHECK_FUNCS(setns)] ) -dnl ------------------------------------ -dnl Determine routing get and set method -dnl ------------------------------------ -AC_MSG_CHECKING(zebra between kernel interface method) -if test x"$opsys" = x"gnu-linux"; then - AC_MSG_RESULT(netlink) - RT_METHOD=rt_netlink.o - KERNEL_METHOD=kernel_netlink.o - AC_DEFINE(HAVE_NETLINK,,netlink) - netlink=yes - AC_CHECK_DECLS([IFLA_INFO_SLAVE_KIND], [], [], [#include ]) -else - AC_MSG_RESULT(Route socket) - KERNEL_METHOD="kernel_socket.o" - RT_METHOD="rt_socket.o" -fi -AC_SUBST(RT_METHOD) -AC_SUBST(KERNEL_METHOD) -AM_CONDITIONAL([HAVE_NETLINK], [test "x$netlink" = "xyes"]) - dnl -------------------------- dnl Determine IS-IS I/O method dnl -------------------------- @@ -1078,27 +1040,32 @@ AC_DEFINE(ISIS_METHOD_BPF, 3, [ constant value for isis method bpf ]) AC_CHECK_HEADER(net/bpf.h) AC_CHECK_HEADER(sys/dlpi.h) AC_MSG_CHECKING(zebra IS-IS I/O method) -if test x"$opsys" = x"gnu-linux"; then - AC_MSG_RESULT(pfpacket) - ISIS_METHOD_MACRO="ISIS_METHOD_PFPACKET" -elif test x"$opsys" = x"sol2-6" -o x"$opsys" = x"sol8"; then - AC_MSG_RESULT(DLPI) - ISIS_METHOD_MACRO="ISIS_METHOD_DLPI" -else - if test $ac_cv_header_net_bpf_h = no; then - if test $ac_cv_header_sys_dlpi_h = no; then - AC_MSG_RESULT(none) - AC_MSG_WARN([*** IS-IS support will not be built ***]) - ISISD="" - else - AC_MSG_RESULT(DLPI) - fi + +case "$host_os" in + linux*) + AC_MSG_RESULT(pfpacket) + ISIS_METHOD_MACRO="ISIS_METHOD_PFPACKET" + ;; + solaris* | sunos*) + AC_MSG_RESULT(DLPI) ISIS_METHOD_MACRO="ISIS_METHOD_DLPI" - else - AC_MSG_RESULT(BPF) - ISIS_METHOD_MACRO="ISIS_METHOD_BPF" - fi -fi + ;; + *) + if test $ac_cv_header_net_bpf_h = no; then + if test $ac_cv_header_sys_dlpi_h = no; then + AC_MSG_RESULT(none) + AC_MSG_WARN([*** IS-IS support will not be built ***]) + ISISD="" + else + AC_MSG_RESULT(DLPI) + fi + ISIS_METHOD_MACRO="ISIS_METHOD_DLPI" + else + AC_MSG_RESULT(BPF) + ISIS_METHOD_MACRO="ISIS_METHOD_BPF" + fi + ;; +esac AC_DEFINE_UNQUOTED(ISIS_METHOD, $ISIS_METHOD_MACRO, [ selected method for isis, == one of the constants ]) dnl ------------------------------------ @@ -1128,59 +1095,6 @@ main() }]])],[AC_MSG_RESULT(yes - using workaround) AC_DEFINE(HAVE_BROKEN_CMSG_FIRSTHDR,,Broken CMSG_FIRSTHDR)], [AC_MSG_RESULT(no)],[AC_MSG_RESULT(no)]) -dnl ------------------------------ -dnl check kernel route read method -dnl ------------------------------ -AC_CACHE_CHECK([route read method], [frr_cv_rtread_method], -[if test "x$netlink" = xyes; then - frr_cv_rtread_method="netlink" -else -for frr_cv_rtread_method in /dev/ip /dev/null; -do - test x`ls $frr_cv_rtread_method 2>/dev/null` = x"$frr_cv_rtread_method" && break -done -case $frr_cv_rtread_method in - "/dev/ip") - case "$host" in - *-freebsd*) frr_cv_rtread_method="sysctl";; - *) frr_cv_rtread_method="getmsg";; - esac;; - *) - frr_cv_rtread_method="sysctl";; -esac -fi]) -RTREAD_METHOD=rtread_${frr_cv_rtread_method}.o -AC_SUBST(RTREAD_METHOD) - -dnl ----------------------------- -dnl check interface lookup method -dnl ----------------------------- -IOCTL_METHOD=ioctl.o -AC_MSG_CHECKING(interface looking up method) -if test "$netlink" = yes; then - AC_MSG_RESULT(netlink) - IF_METHOD=if_netlink.o -elif test "$opsys" = "sol2-6";then - AC_MSG_RESULT(Solaris GIF) - IF_METHOD=if_ioctl.o -elif test "$opsys" = "sol8";then - AC_MSG_RESULT(Solaris GLIF) - IF_METHOD=if_ioctl_solaris.o - IOCTL_METHOD=ioctl_solaris.o -elif test "$opsys" = "openbsd";then - AC_MSG_RESULT(openbsd) - IF_METHOD=if_ioctl.o -elif grep NET_RT_IFLIST /usr/include/sys/socket.h >/dev/null 2>&1; then - AC_MSG_RESULT(sysctl) - IF_METHOD=if_sysctl.o - AC_DEFINE(HAVE_NET_RT_IFLIST,,NET_RT_IFLIST) -else - AC_MSG_RESULT(ioctl) - IF_METHOD=if_ioctl.o -fi -AC_SUBST(IF_METHOD) -AC_SUBST(IOCTL_METHOD) - dnl --------------------------------------------------------------- dnl figure out how to specify an interface in multicast sockets API dnl --------------------------------------------------------------- @@ -1276,71 +1190,11 @@ if test $ac_cv_have_decl_TCP_MD5SIG = no; then AC_CHECK_DECLS([TCP_MD5SIG], [], [], MD5_INCLUDES)]) fi -dnl ----------------------------- -dnl check ipforward detect method -dnl ----------------------------- -AC_CACHE_CHECK([ipforward method], [frr_cv_ipforward_method], -[if test x$cross_compiling = xyes; then - if test x"$opsys" = x"gnu-linux"; then - frr_cv_ipforward_method=/proc/net/snmp - else - frr_cv_ipforward_method=/dev/ip - fi -else - for frr_cv_ipforward_method in /proc/net/snmp /dev/ip /dev/null; - do - test x`ls $frr_cv_ipforward_method 2>/dev/null` = x"$frr_cv_ipforward_method" && break - done -fi -case $frr_cv_ipforward_method in - "/proc/net/snmp") frr_cv_ipforward_method="proc";; - "/dev/ip") - case "$host" in - *-freebsd*) frr_cv_ipforward_method="sysctl";; - *) frr_cv_ipforward_method="solaris";; - esac;; - *) frr_cv_ipforward_method="sysctl";; -esac]) -IPFORWARD=ipforward_${frr_cv_ipforward_method}.o -AC_SUBST(IPFORWARD) - dnl ---------------------------------------------------------------------------- dnl figure out if domainname is available in the utsname struct (GNU extension). dnl ---------------------------------------------------------------------------- AC_CHECK_MEMBERS([struct utsname.domainname], [], [], [#include ]) -dnl ---------- -dnl IPv6 check -dnl ---------- -AC_MSG_CHECKING(whether does this OS have IPv6 stack) -dnl --------- -dnl KAME IPv6 -dnl --------- - if grep WIDE /usr/include/netinet6/in6.h >/dev/null 2>&1; then - AC_DEFINE(KAME,1,KAME IPv6) - AC_MSG_RESULT(KAME) -dnl ------------------------------------ -dnl Solaris 9, 10 and potentially higher -dnl ------------------------------------ - elif test x"$opsys" = x"sol8"; then - AC_DEFINE(SOLARIS_IPV6, 1, Solaris IPv6) - AC_MSG_RESULT(Solaris IPv6) -dnl ---------- -dnl Linux IPv6 -dnl ---------- - elif test x"$opsys" = x"gnu-linux"; then - AC_DEFINE(LINUX_IPV6,1,Linux IPv6 stack) - dnl Linux has a compilation problem with mixing - dnl netinet/in.h and linux/in6.h they are not - dnl compatible. There has been discussion on - dnl how to fix it but no real progress on implementation - dnl when they fix it, remove this - AC_DEFINE(IPV6_MINHOPCOUNT, 73, Linux ipv6 Min Hop Count) - AC_MSG_RESULT(Linux IPv6) - else - AC_MSG_ERROR([Failed to detect IPv6 stack]) - fi - dnl ------------------ dnl IPv6 header checks dnl ------------------ @@ -1407,15 +1261,18 @@ fi AM_CONDITIONAL(LDPD, test "x$LDPD" = "xldpd") NHRPD="" -if test "$opsys" = "gnu-linux"; then - if test "${enable_nhrpd}" != "no"; then - NHRPD="nhrpd" - fi -else - if test "${enable_nhrpd}" = "yes"; then - AC_MSG_ERROR([nhrpd requires kernel APIs that are only present on Linux.]) - fi -fi +case "$host_os" in + linux*) + if test "${enable_nhrpd}" != "no"; then + NHRPD="nhrpd" + fi + ;; + *) + if test "${enable_nhrpd}" = "yes"; then + AC_MSG_ERROR([nhrpd requires kernel APIs that are only present on Linux.]) + fi + ;; +esac AM_CONDITIONAL(NHRPD, test "x$NHRPD" = "xnhrpd") if test "${enable_eigrpd}" = "no";then diff --git a/zebra/if_ioctl.c b/zebra/if_ioctl.c index 2d5d604a8b..a65fcb2b8c 100644 --- a/zebra/if_ioctl.c +++ b/zebra/if_ioctl.c @@ -21,6 +21,8 @@ #include +#ifdef OPEN_BSD + #include "if.h" #include "sockunion.h" #include "prefix.h" @@ -328,3 +330,5 @@ void interface_list(struct zebra_ns *zns) ifaddr_proc_ipv6(); #endif /* HAVE_PROC_NET_IF_INET6 */ } + +#endif /* OPEN_BSD */ diff --git a/zebra/if_ioctl_solaris.c b/zebra/if_ioctl_solaris.c index fce36ebc1d..3d53194593 100644 --- a/zebra/if_ioctl_solaris.c +++ b/zebra/if_ioctl_solaris.c @@ -21,6 +21,8 @@ #include +#ifdef SUNOS_5 + #include "if.h" #include "sockunion.h" #include "prefix.h" @@ -358,3 +360,5 @@ struct connected *if_lookup_linklocal(struct interface *ifp) return NULL; } + +#endif /* SUNOS_5 */ diff --git a/zebra/if_netlink.c b/zebra/if_netlink.c index acec2db526..10db5067f9 100644 --- a/zebra/if_netlink.c +++ b/zebra/if_netlink.c @@ -21,6 +21,8 @@ #include +#ifdef GNU_LINUX + /* The following definition is to workaround an issue in the Linux kernel * header files with redefinition of 'struct in6_addr' in both * netinet/in.h and linux/in6.h. @@ -1218,3 +1220,5 @@ void interface_list(struct zebra_ns *zns) { interface_lookup_netlink(zns); } + +#endif /* GNU_LINUX */ diff --git a/zebra/if_sysctl.c b/zebra/if_sysctl.c index 99b0f9d942..39b7204e8e 100644 --- a/zebra/if_sysctl.c +++ b/zebra/if_sysctl.c @@ -21,6 +21,8 @@ #include +#if !defined(GNU_LINUX) && !defined(OPEN_BSD) && !defined(SUNOS_5) + #include "if.h" #include "sockunion.h" #include "prefix.h" @@ -134,3 +136,5 @@ void interface_list(struct zebra_ns *zns) /* Free sysctl buffer. */ XFREE(MTYPE_TMP, ref); } + +#endif /* !defined(GNU_LINUX) && !defined(OPEN_BSD) && !defined(SUNOS_5) */ diff --git a/zebra/ioctl.c b/zebra/ioctl.c index 72d98943ef..835f1f4934 100644 --- a/zebra/ioctl.c +++ b/zebra/ioctl.c @@ -33,6 +33,8 @@ #include "zebra/rt.h" #include "zebra/interface.h" +#ifndef SUNOS_5 + #ifdef HAVE_BSD_LINK_DETECT #include #endif /* HAVE_BSD_LINK_DETECT*/ @@ -563,3 +565,5 @@ int if_prefix_delete_ipv6(struct interface *ifp, struct connected *ifc) #endif /* HAVE_STRUCT_IN6_ALIASREQ */ #endif /* LINUX_IPV6 */ + +#endif /* !SUNOS_5 */ diff --git a/zebra/ioctl_solaris.c b/zebra/ioctl_solaris.c index df1554ae6f..e8b65925f8 100644 --- a/zebra/ioctl_solaris.c +++ b/zebra/ioctl_solaris.c @@ -21,6 +21,8 @@ #include +#ifdef SUNOS_5 + #include "linklist.h" #include "if.h" #include "prefix.h" @@ -398,3 +400,5 @@ int if_prefix_delete_ipv6(struct interface *ifp, struct connected *ifc) return 0; } + +#endif /* SUNOS_5 */ diff --git a/zebra/ipforward_proc.c b/zebra/ipforward_proc.c index c3dcdda55f..2834eeeb9c 100644 --- a/zebra/ipforward_proc.c +++ b/zebra/ipforward_proc.c @@ -21,6 +21,8 @@ #include +#ifdef GNU_LINUX + #include "log.h" #include "privs.h" @@ -193,3 +195,5 @@ int ipforward_ipv6_off(void) return ipforward_ipv6(); } + +#endif /* GNU_LINUX */ diff --git a/zebra/ipforward_solaris.c b/zebra/ipforward_solaris.c index 0d6b7dac03..123cf1bd08 100644 --- a/zebra/ipforward_solaris.c +++ b/zebra/ipforward_solaris.c @@ -20,6 +20,9 @@ */ #include + +#ifdef SUNOS_5 + #include "log.h" #include "prefix.h" @@ -153,3 +156,5 @@ int ipforward_ipv6_off(void) (void)solaris_nd_set("ip6_forwarding", 0); return ipforward_ipv6(); } + +#endif /* SUNOS_5 */ diff --git a/zebra/ipforward_sysctl.c b/zebra/ipforward_sysctl.c index 00be92bb6d..36212a0132 100644 --- a/zebra/ipforward_sysctl.c +++ b/zebra/ipforward_sysctl.c @@ -19,6 +19,9 @@ */ #include + +#if !defined(GNU_LINUX) && !defined(SUNOS_5) + #include "privs.h" #include "zebra/ipforward.h" @@ -147,3 +150,5 @@ int ipforward_ipv6_off(void) zlog_err("Can't lower privileges"); return ip6forwarding; } + +#endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */ diff --git a/zebra/kernel_netlink.c b/zebra/kernel_netlink.c index 7fc2d61332..dfc3f6211d 100644 --- a/zebra/kernel_netlink.c +++ b/zebra/kernel_netlink.c @@ -20,6 +20,8 @@ #include +#ifdef HAVE_NETLINK + #include "linklist.h" #include "if.h" #include "log.h" @@ -826,3 +828,5 @@ void kernel_terminate(struct zebra_ns *zns) zns->netlink_cmd.sock = -1; } } + +#endif /* HAVE_NETLINK */ diff --git a/zebra/kernel_socket.c b/zebra/kernel_socket.c index 4b63a3eb04..5df57b2530 100644 --- a/zebra/kernel_socket.c +++ b/zebra/kernel_socket.c @@ -19,6 +19,9 @@ */ #include + +#ifndef HAVE_NETLINK + #include #ifdef __OpenBSD__ #include @@ -1376,3 +1379,5 @@ void kernel_terminate(struct zebra_ns *zns) { return; } + +#endif /* !HAVE_NETLINK */ diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index c02774ca64..75118713d3 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -19,6 +19,9 @@ */ #include + +#ifdef HAVE_NETLINK + #include /* Hack for GNU libc version 2. */ @@ -2442,3 +2445,5 @@ void clear_nhlfe_installed(zebra_lsp_t *lsp) UNSET_FLAG(nexthop->flags, NEXTHOP_FLAG_FIB); } } + +#endif /* HAVE_NETLINK */ diff --git a/zebra/rt_socket.c b/zebra/rt_socket.c index 827d398704..0eae3c4f25 100644 --- a/zebra/rt_socket.c +++ b/zebra/rt_socket.c @@ -20,6 +20,9 @@ */ #include + +#ifndef HAVE_NETLINK + #ifdef __OpenBSD__ #include #endif @@ -443,3 +446,5 @@ int kernel_del_neigh(struct interface *ifp, struct ipaddr *ip) { return 0; } + +#endif /* !HAVE_NETLINK */ diff --git a/zebra/rtread_getmsg.c b/zebra/rtread_getmsg.c index 5384231f88..1bba003a0a 100644 --- a/zebra/rtread_getmsg.c +++ b/zebra/rtread_getmsg.c @@ -21,6 +21,8 @@ #include +#ifdef SUNOS_5 + #include "prefix.h" #include "log.h" #include "if.h" @@ -258,3 +260,5 @@ void neigh_read(struct zebra_ns *zns) void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) { } + +#endif /* SUNOS_5 */ diff --git a/zebra/rtread_netlink.c b/zebra/rtread_netlink.c index 304f441367..f38cba65e7 100644 --- a/zebra/rtread_netlink.c +++ b/zebra/rtread_netlink.c @@ -21,6 +21,8 @@ #include +#ifdef GNU_LINUX + #include "vty.h" #include "zebra/zserv.h" #include "zebra/rt_netlink.h" @@ -50,3 +52,5 @@ void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) { netlink_neigh_read_for_vlan(zns, vlan_if); } + +#endif /* GNU_LINUX */ diff --git a/zebra/rtread_sysctl.c b/zebra/rtread_sysctl.c index d3e2eb6fac..53ed0e7906 100644 --- a/zebra/rtread_sysctl.c +++ b/zebra/rtread_sysctl.c @@ -21,6 +21,8 @@ #include +#if !defined(GNU_LINUX) && !defined(SUNOS_5) + #include "memory.h" #include "zebra_memory.h" #include "log.h" @@ -90,3 +92,5 @@ void neigh_read(struct zebra_ns *zns) void neigh_read_for_vlan(struct zebra_ns *zns, struct interface *vlan_if) { } + +#endif /* !defined(GNU_LINUX) && !defined(SUNOS_5) */ diff --git a/zebra/subdir.am b/zebra/subdir.am index e69aa6334c..546da3cf25 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -16,42 +16,41 @@ endif ## endif ZEBRA endif -ipforward = @IPFORWARD@ -if_method = @IF_METHOD@ -rt_method = @RT_METHOD@ -rtread_method = @RTREAD_METHOD@ -kernel_method = @KERNEL_METHOD@ -ioctl_method = @IOCTL_METHOD@ -mpls_method = @MPLS_METHOD@ - -otherobj = \ - zebra/$(ioctl_method) \ - zebra/$(ipforward) \ - zebra/$(if_method) \ - zebra/$(rt_method) \ - zebra/$(rtread_method) \ - zebra/$(kernel_method) \ - zebra/$(mpls_method) \ - # end - -zebra_zebra_LDADD = $(otherobj) lib/libfrr.la $(LIBCAP) -zebra_zebra_DEPENDENCIES = $(otherobj) lib/libfrr.la - +zebra_zebra_LDADD = lib/libfrr.la $(LIBCAP) zebra_zebra_SOURCES = \ zebra/connected.c \ zebra/debug.c \ + zebra/if_ioctl.c \ + zebra/if_ioctl_solaris.c \ + zebra/if_netlink.c \ + zebra/if_sysctl.c \ zebra/interface.c \ + zebra/ioctl.c \ + zebra/ioctl_solaris.c \ + zebra/ipforward_proc.c \ + zebra/ipforward_solaris.c \ + zebra/ipforward_sysctl.c \ zebra/irdp_interface.c \ zebra/irdp_main.c \ zebra/irdp_packet.c \ + zebra/kernel_netlink.c \ + zebra/kernel_socket.c \ zebra/label_manager.c \ zebra/main.c \ zebra/redistribute.c \ zebra/router-id.c \ + zebra/rt_netlink.c \ + zebra/rt_socket.c \ zebra/rtadv.c \ + zebra/rtread_getmsg.c \ + zebra/rtread_netlink.c \ + zebra/rtread_sysctl.c \ zebra/zebra_l2.c \ zebra/zebra_memory.c \ zebra/zebra_mpls.c \ + zebra/zebra_mpls_netlink.c \ + zebra/zebra_mpls_openbsd.c \ + zebra/zebra_mpls_null.c \ zebra/zebra_mpls_vty.c \ zebra/zebra_mroute.c \ zebra/zebra_ns.c \ @@ -112,9 +111,7 @@ zebra_zebra_snmp_la_LIBADD = lib/libfrrsnmp.la zebra_zebra_fpm_la_LDFLAGS = -avoid-version -module -shared -export-dynamic zebra_zebra_fpm_la_LIBADD = $(Q_FPM_PB_CLIENT_LDOPTS) zebra_zebra_fpm_la_SOURCES = zebra/zebra_fpm.c -if HAVE_NETLINK zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_netlink.c -endif if HAVE_PROTOBUF zebra_zebra_fpm_la_SOURCES += zebra/zebra_fpm_protobuf.c if DEV_BUILD @@ -125,25 +122,6 @@ endif EXTRA_DIST += \ zebra/GNOME-SMI \ zebra/GNOME-PRODUCT-ZEBRA-MIB \ - zebra/if_ioctl.c \ - zebra/if_ioctl_solaris.c \ - zebra/if_netlink.c \ - zebra/if_sysctl.c \ - zebra/ioctl.c \ - zebra/ioctl_solaris.c \ - zebra/ipforward_proc.c \ - zebra/ipforward_solaris.c \ - zebra/ipforward_sysctl.c \ - zebra/kernel_netlink.c \ - zebra/kernel_socket.c \ - zebra/rt_netlink.c \ - zebra/rt_socket.c \ - zebra/rtread_getmsg.c \ - zebra/rtread_netlink.c \ - zebra/rtread_sysctl.c \ - zebra/zebra_mpls_netlink.c \ - zebra/zebra_mpls_null.c \ - zebra/zebra_mpls_openbsd.c \ # end # -- unmaintained -- diff --git a/zebra/zebra_fpm_netlink.c b/zebra/zebra_fpm_netlink.c index 862049cb85..28f7956639 100644 --- a/zebra/zebra_fpm_netlink.c +++ b/zebra/zebra_fpm_netlink.c @@ -24,6 +24,8 @@ #include +#ifdef HAVE_NETLINK + #include "log.h" #include "rib.h" #include "vty.h" @@ -457,3 +459,5 @@ int zfpm_netlink_encode_route(int cmd, rib_dest_t *dest, struct route_entry *re, return netlink_route_info_encode(ri, in_buf, in_buf_len); } + +#endif /* HAVE_NETLINK */ diff --git a/zebra/zebra_mpls_netlink.c b/zebra/zebra_mpls_netlink.c index c5053563b9..8b30783a9a 100644 --- a/zebra/zebra_mpls_netlink.c +++ b/zebra/zebra_mpls_netlink.c @@ -19,6 +19,9 @@ */ #include + +#ifdef HAVE_NETLINK + #include "zebra/rt.h" #include "zebra/rt_netlink.h" #include "zebra/zebra_mpls.h" @@ -105,3 +108,5 @@ int mpls_kernel_init(void) return 0; }; + +#endif /* HAVE_NETLINK */ diff --git a/zebra/zebra_mpls_null.c b/zebra/zebra_mpls_null.c index a9da5c29c6..e4dc570fd9 100644 --- a/zebra/zebra_mpls_null.c +++ b/zebra/zebra_mpls_null.c @@ -22,6 +22,8 @@ #include "zebra/rt.h" #include "zebra/zebra_mpls.h" +#if !defined(HAVE_NETLINK) && !defined(OPEN_BSD) + int kernel_add_lsp(zebra_lsp_t *lsp) { return 0; @@ -38,3 +40,5 @@ int mpls_kernel_init(void) { return -1; }; + +#endif /* !defined(HAVE_NETLINK) && !defined(OPEN_BSD) */ diff --git a/zebra/zebra_mpls_openbsd.c b/zebra/zebra_mpls_openbsd.c index fc1df9227f..c3d09aedbd 100644 --- a/zebra/zebra_mpls_openbsd.c +++ b/zebra/zebra_mpls_openbsd.c @@ -19,6 +19,9 @@ */ #include + +#ifdef OPEN_BSD + #include #include "zebra/rt.h" #include "zebra/zebra_mpls.h" @@ -358,3 +361,5 @@ int mpls_kernel_init(void) return 0; } + +#endif /* OPEN_BSD */ From 0f8b5fd5a05c1261061a94270218b701c1298719 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 28 Jul 2017 14:40:39 +0200 Subject: [PATCH 62/75] build: non-recursive qpb & fpm Signed-off-by: David Lamparter --- Makefile.am | 7 +++++-- common.am | 25 ++++++++++++------------- configure.ac | 3 +-- fpm/.gitignore | 2 +- fpm/Makefile | 10 ++++++++++ fpm/Makefile.am | 29 ----------------------------- fpm/subdir.am | 23 +++++++++++++++++++++++ qpb/.gitignore | 2 +- qpb/Makefile | 10 ++++++++++ qpb/Makefile.am | 30 ------------------------------ qpb/subdir.am | 26 ++++++++++++++++++++++++++ 11 files changed, 89 insertions(+), 78 deletions(-) create mode 100644 fpm/Makefile delete mode 100644 fpm/Makefile.am create mode 100644 fpm/subdir.am create mode 100644 qpb/Makefile delete mode 100644 qpb/Makefile.am create mode 100644 qpb/subdir.am diff --git a/Makefile.am b/Makefile.am index 415b80d516..53693ae4da 100644 --- a/Makefile.am +++ b/Makefile.am @@ -10,6 +10,7 @@ LIBCAP = @LIBCAP@ EXTRA_DIST = BUILT_SOURCES = +CLEANFILES = examplesdir = $(exampledir) @@ -25,14 +26,16 @@ dist_examples_DATA = include lib/subdir.am include zebra/subdir.am +include qpb/subdir.am +include fpm/subdir.am -SUBDIRS = . qpb fpm @LIBRFP@ @RFPTEST@ \ +SUBDIRS = . @LIBRFP@ @RFPTEST@ \ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @LDPD@ \ @ISISD@ @PIMD@ @NHRPD@ @EIGRPD@ @BABELD@ \ @WATCHFRR@ @VTYSH@ @OSPFCLIENT@ @DOC@ m4 @pkgsrcdir@ \ redhat @SOLARIS@ tests tools snapcraft -DIST_SUBDIRS = . qpb fpm bgpd ripd ripngd ospfd ospf6d ldpd \ +DIST_SUBDIRS = . bgpd ripd ripngd ospfd ospf6d ldpd \ isisd watchfrr vtysh ospfclient doc m4 pkgsrc redhat tests \ solaris pimd nhrpd eigrpd bgpd/rfp-example/librfp \ bgpd/rfp-example/rfptest tools snapcraft babeld python \ diff --git a/common.am b/common.am index 67e54d17d5..e252b74297 100644 --- a/common.am +++ b/common.am @@ -8,7 +8,7 @@ am__v_CLIPPY_ = $(am__v_CLIPPY_$(AM_DEFAULT_VERBOSITY)) am__v_CLIPPY_0 = @echo " CLIPPY " $@; am__v_CLIPPY_1 = -SUFFIXES = _clippy.c +SUFFIXES = _clippy.c .proto .pb-c.c .pb-c.h .pb.h .c_clippy.c: $(AM_V_at)$(MAKE) -C $(top_builddir)/$(HOSTTOOLS) lib/clippy $(AM_V_CLIPPY)$(top_builddir)/$(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py $< > $@.tmp @@ -34,16 +34,19 @@ Q_PROTOBUF_C_CLIENT_LDOPTS=-lprotobuf-c Q_PROTOC=protoc Q_PROTOC_C=protoc-c -Q_PROTOBUF_CFILES = $(filter %.pb-c.c,$(SOURCES)) - -Q_PROTOBUF_SRCS = $(Q_PROTOBUF_CFILES) $(Q_PROTOBUF_HFILES) - # Rules -%.pb.h: %.proto - $(Q_PROTOC) $(PROTOBUF_INCLUDES) --cpp_out=$(top_srcdir) $(top_srcdir)/$(PROTOBUF_PACKAGE)/$^ +.proto.pb.h: + $(Q_PROTOC) -I$(top_srcdir) --cpp_out=$(top_srcdir) $(top_srcdir)/$^ -%.pb-c.c %.pb-c.h: %.proto - $(Q_PROTOC_C) $(PROTOBUF_INCLUDES) --c_out=$(top_srcdir) $(top_srcdir)/$(PROTOBUF_PACKAGE)/$^ +AM_V_PROTOC_C = $(am__v_PROTOC_C_$(V)) +am__v_PROTOC_C_ = $(am__v_PROTOC_C_$(AM_DEFAULT_VERBOSITY)) +am__v_PROTOC_C_0 = @echo " PROTOC_C" $@; +am__v_PROTOC_C_1 = + +.proto.pb-c.c: + $(AM_V_PROTOC_C)$(Q_PROTOC_C) -I$(top_srcdir) --c_out=$(top_srcdir) $(top_srcdir)/$^ +.pb-c.c.pb-c.h: + @/bin/true # # Information about how to link to various libraries. @@ -53,7 +56,3 @@ Q_FRR_PB_CLIENT_LDOPTS = $(top_srcdir)/qpb/libfrr_pb.la $(Q_PROTOBUF_C_CLIENT_LD Q_FPM_PB_CLIENT_LDOPTS = $(top_srcdir)/fpm/libfrrfpm_pb.la $(Q_FRR_PB_CLIENT_LDOPTS) endif # HAVE_PROTOBUF - -Q_CLEANFILES = $(Q_PROTOBUF_SRCS) - -Q_BUILT_SRCS = $(Q_PROTOBUF_SRCS) diff --git a/configure.ac b/configure.ac index b22361d40b..1ba501ee40 100755 --- a/configure.ac +++ b/configure.ac @@ -1820,7 +1820,7 @@ AC_CACHE_VAL(ac_cv_htonl_works, ) AC_MSG_RESULT($ac_cv_htonl_works) -AC_CONFIG_FILES([Makefile qpb/Makefile ripd/Makefile +AC_CONFIG_FILES([Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile watchfrr/Makefile ospf6d/Makefile ldpd/Makefile isisd/Makefile vtysh/Makefile doc/Makefile ospfclient/Makefile tests/Makefile m4/Makefile @@ -1833,7 +1833,6 @@ AC_CONFIG_FILES([Makefile qpb/Makefile ripd/Makefile tools/Makefile pkgsrc/Makefile python/Makefile - fpm/Makefile redhat/frr.spec snapcraft/Makefile snapcraft/snapcraft.yaml diff --git a/fpm/.gitignore b/fpm/.gitignore index b133c52a42..17e90443e9 100644 --- a/fpm/.gitignore +++ b/fpm/.gitignore @@ -1,4 +1,4 @@ -Makefile +!Makefile Makefile.in *.o tags diff --git a/fpm/Makefile b/fpm/Makefile new file mode 100644 index 0000000000..1d280d176e --- /dev/null +++ b/fpm/Makefile @@ -0,0 +1,10 @@ +all: ALWAYS + @$(MAKE) -s -C .. fpm/libfrrfpm_pb.la +%: ALWAYS + @$(MAKE) -s -C .. fpm/$@ + +Makefile: + #nothing +ALWAYS: +.PHONY: ALWAYS makefiles +.SUFFIXES: diff --git a/fpm/Makefile.am b/fpm/Makefile.am deleted file mode 100644 index 1f46ac6db2..0000000000 --- a/fpm/Makefile.am +++ /dev/null @@ -1,29 +0,0 @@ -include ../common.am - -AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib $(Q_PROTOBUF_C_CLIENT_INCLUDES) - -PROTOBUF_INCLUDES=-I$(top_srcdir) -PROTOBUF_PACKAGE = fpm - -lib_LTLIBRARIES = libfrrfpm_pb.la -libfrrfpm_pb_la_LDFLAGS = -version-info 0:0:0 - -if HAVE_PROTOBUF -protobuf_srcs = - -protobuf_srcs_nodist = \ - fpm.pb-c.c -endif - -libfrrfpm_pb_la_SOURCES = \ - fpm.h \ - fpm_pb.h \ - fpm_pb.c \ - $(protobuf_srcs) - -nodist_libfrrfpm_pb_la_SOURCES = $(protobuf_srcs_nodist) - -CLEANFILES = $(Q_CLEANFILES) - -BUILT_SOURCES = $(Q_PROTOBUF_SRCS) -EXTRA_DIST = fpm.proto diff --git a/fpm/subdir.am b/fpm/subdir.am new file mode 100644 index 0000000000..f81a84222c --- /dev/null +++ b/fpm/subdir.am @@ -0,0 +1,23 @@ +if FPM +lib_LTLIBRARIES += fpm/libfrrfpm_pb.la +endif + +fpm_libfrrfpm_pb_la_LDFLAGS = -version-info 0:0:0 +fpm_libfrrfpm_pb_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir) -I$(top_builddir)/lib \ + $(Q_PROTOBUF_C_CLIENT_INCLUDES) +fpm_libfrrfpm_pb_la_SOURCES = \ + fpm/fpm.h \ + fpm/fpm_pb.h \ + fpm/fpm_pb.c \ + # end + +if HAVE_PROTOBUF +nodist_fpm_libfrrfpm_pb_la_SOURCES = fpm/fpm.pb-c.c +BUILT_SOURCES += fpm/fpm.pb-c.c +CLEANFILES += \ + fpm/fpm.pb-c.c \ + fpm/fpm.pb-c.h \ + # end +endif + +EXTRA_DIST += fpm/fpm.proto diff --git a/qpb/.gitignore b/qpb/.gitignore index b133c52a42..17e90443e9 100644 --- a/qpb/.gitignore +++ b/qpb/.gitignore @@ -1,4 +1,4 @@ -Makefile +!Makefile Makefile.in *.o tags diff --git a/qpb/Makefile b/qpb/Makefile new file mode 100644 index 0000000000..2237def02c --- /dev/null +++ b/qpb/Makefile @@ -0,0 +1,10 @@ +all: ALWAYS + @$(MAKE) -s -C .. fpm/libfrr_pb.la +%: ALWAYS + @$(MAKE) -s -C .. fpm/$@ + +Makefile: + #nothing +ALWAYS: +.PHONY: ALWAYS makefiles +.SUFFIXES: diff --git a/qpb/Makefile.am b/qpb/Makefile.am deleted file mode 100644 index e5951b2be9..0000000000 --- a/qpb/Makefile.am +++ /dev/null @@ -1,30 +0,0 @@ -include ../common.am - -AM_CPPFLAGS = -I.. -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir)/lib $(Q_PROTOBUF_C_CLIENT_INCLUDES) - -PROTOBUF_INCLUDES=-I$(top_srcdir) -PROTOBUF_PACKAGE = qpb - -lib_LTLIBRARIES = libfrr_pb.la -libfrr_pb_la_LDFLAGS = -version-info 0:0:0 - -if HAVE_PROTOBUF -protobuf_srcs = \ - qpb_allocator.c - -protobuf_srcs_nodist = \ - qpb.pb-c.c -endif - -libfrr_pb_la_SOURCES = \ - linear_allocator.h \ - qpb.h \ - qpb.c \ - qpb_allocator.h \ - $(protobuf_srcs) - -nodist_libfrr_pb_la_SOURCES = $(protobuf_srcs_nodist) - -CLEANFILES = $(Q_CLEANFILES) -BUILT_SOURCES = $(Q_PROTOBUF_SRCS) -EXTRA_DIST = qpb.proto diff --git a/qpb/subdir.am b/qpb/subdir.am new file mode 100644 index 0000000000..71e501b9c2 --- /dev/null +++ b/qpb/subdir.am @@ -0,0 +1,26 @@ +if HAVE_PROTOBUF +lib_LTLIBRARIES += qpb/libfrr_pb.la +endif + +qpb_libfrr_pb_la_CPPFLAGS = -I$(top_srcdir) -I$(top_srcdir)/lib -I$(top_builddir) -I$(top_builddir)/lib \ + $(Q_PROTOBUF_C_CLIENT_INCLUDES) +qpb_libfrr_pb_la_LDFLAGS = -version-info 0:0:0 + +qpb_libfrr_pb_la_SOURCES = \ + qpb/linear_allocator.h \ + qpb/qpb.h \ + qpb/qpb.c \ + qpb/qpb_allocator.h \ + # end + +if HAVE_PROTOBUF +qpb_libfrr_pb_la_SOURCES += qpb/qpb_allocator.c +nodist_qpb_libfrr_pb_la_SOURCES = qpb/qpb.pb-c.c +BUILT_SOURCES += qpb/qpb.pb-c.c +CLEANFILES += \ + qpb/qpb.pb-c.c \ + qpb/qpb.pb-c.h \ + # end +endif + +EXTRA_DIST += qpb/qpb.proto From a805d3bbb18f9cbaabf87850ba944b036e39240f Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Fri, 28 Jul 2017 14:42:13 +0200 Subject: [PATCH 63/75] protobuf: fix build Signed-off-by: David Lamparter --- fpm/fpm.proto | 2 ++ qpb/qpb.proto | 4 +++- qpb/qpb_allocator.c | 3 +-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/fpm/fpm.proto b/fpm/fpm.proto index 318e80a92e..4597c7f8eb 100644 --- a/fpm/fpm.proto +++ b/fpm/fpm.proto @@ -20,6 +20,8 @@ // CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. // +syntax = "proto2"; + // // Protobuf definitions pertaining to the Forwarding Plane Manager component. // diff --git a/qpb/qpb.proto b/qpb/qpb.proto index a1595a9abd..c06debb954 100644 --- a/qpb/qpb.proto +++ b/qpb/qpb.proto @@ -20,6 +20,8 @@ * CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +syntax = "proto2"; + /* * Protobuf definitions pertaining to the Quagga/FRR Protobuf component. */ @@ -87,4 +89,4 @@ enum Protocol { ISIS = 8; BGP = 9; OTHER = 10; -} \ No newline at end of file +} diff --git a/qpb/qpb_allocator.c b/qpb/qpb_allocator.c index 8b0ee941a5..7e5ba5b0ce 100644 --- a/qpb/qpb_allocator.c +++ b/qpb/qpb_allocator.c @@ -42,8 +42,7 @@ static void _qpb_free(void *allocator_data, void *ptr) linear_allocator_free(allocator_data, ptr); } -static ProtobufCAllocator allocator_template = {_qpb_alloc, _qpb_free, NULL, - 8192, NULL}; +static ProtobufCAllocator allocator_template = {_qpb_alloc, _qpb_free, NULL}; /* * qpb_allocator_init_linear From 53d93be147de81b6efbaff0eecfbff076e1f02ca Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 31 Jul 2017 22:05:56 +0200 Subject: [PATCH 64/75] build: non-recursive auxiliary directories Flatten {m4,pkgsrc,python,redhat,snapcraft}/Makefile.am into the main one. Signed-off-by: David Lamparter --- Makefile.am | 59 +++++++++++++++++++++++++++++++++++++------ configure.ac | 11 +++----- m4/Makefile.am | 1 - pkgsrc/Makefile.am | 3 --- python/Makefile.am | 3 --- redhat/Makefile.am | 5 ---- snapcraft/Makefile.am | 8 ------ 7 files changed, 54 insertions(+), 36 deletions(-) delete mode 100644 m4/Makefile.am delete mode 100644 pkgsrc/Makefile.am delete mode 100644 python/Makefile.am delete mode 100644 redhat/Makefile.am delete mode 100644 snapcraft/Makefile.am diff --git a/Makefile.am b/Makefile.am index 53693ae4da..7cfe4a97e3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -32,20 +32,63 @@ include fpm/subdir.am SUBDIRS = . @LIBRFP@ @RFPTEST@ \ @BGPD@ @RIPD@ @RIPNGD@ @OSPFD@ @OSPF6D@ @LDPD@ \ @ISISD@ @PIMD@ @NHRPD@ @EIGRPD@ @BABELD@ \ - @WATCHFRR@ @VTYSH@ @OSPFCLIENT@ @DOC@ m4 @pkgsrcdir@ \ - redhat @SOLARIS@ tests tools snapcraft + @WATCHFRR@ @VTYSH@ @OSPFCLIENT@ @DOC@ \ + @SOLARIS@ tests tools DIST_SUBDIRS = . bgpd ripd ripngd ospfd ospf6d ldpd \ - isisd watchfrr vtysh ospfclient doc m4 pkgsrc redhat tests \ + isisd watchfrr vtysh ospfclient doc tests \ solaris pimd nhrpd eigrpd bgpd/rfp-example/librfp \ - bgpd/rfp-example/rfptest tools snapcraft babeld python \ + bgpd/rfp-example/rfptest tools babeld \ # end -EXTRA_DIST += aclocal.m4 SERVICES REPORTING-BUGS \ +if PKGSRC +rcdir=@pkgsrcrcdir@ +rc_SCRIPTS = \ + pkgsrc/bgpd.sh \ + pkgsrc/ospf6d.sh \ + pkgsrc/ospfd.sh \ + pkgsrc/ripd.sh \ + pkgsrc/ripngd.sh \ + pkgsrc/zebra.sh \ + # end +endif + +EXTRA_DIST += \ + REPORTING-BUGS \ + SERVICES \ + aclocal.m4 \ update-autotools \ - vtysh/Makefile.in vtysh/Makefile.am \ - tools/rrcheck.pl tools/rrlookup.pl tools/zc.pl \ - tools/zebra.el tools/multiple-bgpd.sh + m4/README.txt \ + \ + python/clidef.py \ + python/clippy/__init__.py \ + \ + redhat/frr.init \ + redhat/frr.service \ + redhat/daemons \ + redhat/frr.logrotate \ + redhat/frr.pam \ + redhat/frr.spec \ + redhat/README.rpm_build.md \ + \ + snapcraft/snapcraft.yaml \ + snapcraft/README.snap_build.md \ + snapcraft/README.usage.md \ + snapcraft/extra_version_info.txt \ + snapcraft/scripts \ + snapcraft/defaults \ + snapcraft/helpers \ + snapcraft/snap \ + \ + tools/multiple-bgpd.sh \ + tools/rrcheck.pl \ + tools/rrlookup.pl \ + tools/zc.pl \ + tools/zebra.el \ + \ + vtysh/Makefile.am \ + vtysh/Makefile.in \ + # end ACLOCAL_AMFLAGS = -I m4 diff --git a/configure.ac b/configure.ac index 1ba501ee40..8cc70f8a99 100755 --- a/configure.ac +++ b/configure.ac @@ -75,14 +75,13 @@ AC_SUBST(exampledir) dnl default is to match previous behavior pkgsrcrcdir="" -pkgsrcdir="" AC_ARG_ENABLE([pkgsrcrcdir], AS_HELP_STRING([--enable-pkgsrcrcdir], [specify directory for rc.d scripts]), - pkgsrcrcdir="$enableval"; pkgsrcdir="pkgsrc",) + pkgsrcrcdir="$enableval",) dnl XXX add --pkgsrcrcdir to autoconf standard directory list somehow -AC_SUBST(pkgsrcdir) AC_SUBST(pkgsrcrcdir) +AM_CONDITIONAL([PKGSRC], [test "x$pkgsrcrcdir" != "x"]) AC_ARG_WITH([moduledir], [AS_HELP_STRING([--with-moduledir=DIR], [module directory (${libdir}/frr/modules)])], [ moduledir="$withval" @@ -1823,18 +1822,14 @@ AC_MSG_RESULT($ac_cv_htonl_works) AC_CONFIG_FILES([Makefile ripd/Makefile ripngd/Makefile bgpd/Makefile ospfd/Makefile watchfrr/Makefile ospf6d/Makefile ldpd/Makefile isisd/Makefile vtysh/Makefile - doc/Makefile ospfclient/Makefile tests/Makefile m4/Makefile + doc/Makefile ospfclient/Makefile tests/Makefile bgpd/rfp-example/rfptest/Makefile bgpd/rfp-example/librfp/Makefile babeld/Makefile pimd/Makefile eigrpd/Makefile nhrpd/Makefile - redhat/Makefile tools/Makefile - pkgsrc/Makefile - python/Makefile redhat/frr.spec - snapcraft/Makefile snapcraft/snapcraft.yaml lib/version.h tests/lib/cli/test_cli.refout diff --git a/m4/Makefile.am b/m4/Makefile.am deleted file mode 100644 index 49a29bdf1f..0000000000 --- a/m4/Makefile.am +++ /dev/null @@ -1 +0,0 @@ -EXTRA_DIST=Makefile.am README.txt diff --git a/pkgsrc/Makefile.am b/pkgsrc/Makefile.am deleted file mode 100644 index 622fbf0748..0000000000 --- a/pkgsrc/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -rcdir=@pkgsrcrcdir@ - -rc_SCRIPTS = bgpd.sh ospf6d.sh ospfd.sh ripd.sh ripngd.sh zebra.sh diff --git a/python/Makefile.am b/python/Makefile.am deleted file mode 100644 index 4ad1e36b59..0000000000 --- a/python/Makefile.am +++ /dev/null @@ -1,3 +0,0 @@ -EXTRA_DIST = \ - clidef.py \ - clippy/__init__.py diff --git a/redhat/Makefile.am b/redhat/Makefile.am deleted file mode 100644 index 74856cfd82..0000000000 --- a/redhat/Makefile.am +++ /dev/null @@ -1,5 +0,0 @@ - -EXTRA_DIST = frr.init frr.service daemons \ - frr.logrotate frr.pam frr.spec \ - README.rpm_build.md - diff --git a/snapcraft/Makefile.am b/snapcraft/Makefile.am deleted file mode 100644 index a8220670d1..0000000000 --- a/snapcraft/Makefile.am +++ /dev/null @@ -1,8 +0,0 @@ -EXTRA_DIST = snapcraft.yaml \ - README.snap_build.md \ - README.usage.md \ - extra_version_info.txt \ - scripts \ - defaults \ - helpers \ - snap From 40520c3649dc9d556b3a11f1d60e84130cebf487 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Mon, 31 Jul 2017 21:22:23 +0000 Subject: [PATCH 65/75] bgpd: peer hash expands until we are out of memory Signed-off-by: Daniel Walton swpX peers all start out with the same sockunion so initially they all go into the same hash bucket. Once IPv6 ND has worked its magic they will have different sockunions and will go in different buckets...life is good. Until then though, we are in a phase where all swpX peers have the same socknunion. Once we have HASH_THRESHOLD (10) swpX peers and call hash_get for a new swpX peer the hash code calls hash_expand(). This happens because there are more than HASH_THRESHOLD entries in a single bucket so the logic is "expand the hash to spread things out"...in our case expanding doesn't spread out the swpX peers because all of their sockunions are the same. I looked at having peer_hash_make and peer_hash_same consider the ifname of the swpX peer but that is a large change that we don't want to make at the moment. So the fix is to put a cap on how large we are willing to let the hash table get. By default there is no limit but if max_size is set we will not allow the hash to expand above that. --- bgpd/bgpd.c | 5 +++-- bgpd/bgpd.h | 1 + lib/hash.c | 4 ++++ lib/hash.h | 3 +++ 4 files changed, 11 insertions(+), 2 deletions(-) diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index a0e2d6749a..b4e000f8bb 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -746,7 +746,7 @@ static unsigned int peer_hash_key_make(void *p) return sockunion_hash(&peer->su); } -static int peer_hash_cmp(const void *p1, const void *p2) +static int peer_hash_same(const void *p1, const void *p2) { const struct peer *peer1 = p1; const struct peer *peer2 = p2; @@ -2757,7 +2757,8 @@ static struct bgp *bgp_create(as_t *as, const char *name, XSTRDUP(MTYPE_BGP_PEER_HOST, "Static announcement"); bgp->peer = list_new(); bgp->peer->cmp = (int (*)(void *, void *))peer_cmp; - bgp->peerhash = hash_create(peer_hash_key_make, peer_hash_cmp, NULL); + bgp->peerhash = hash_create(peer_hash_key_make, peer_hash_same, NULL); + bgp->peerhash->max_size = BGP_PEER_MAX_HASH_SIZE; bgp->group = list_new(); bgp->group->cmp = (int (*)(void *, void *))peer_group_cmp; diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 67b8289c70..ff5e709dae 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -36,6 +36,7 @@ #include "bitfield.h" #define BGP_MAX_HOSTNAME 64 /* Linux max, is larger than most other sys */ +#define BGP_PEER_MAX_HASH_SIZE 16384 /* Default interval for IPv6 RAs when triggered by BGP unnumbered neighbor. */ #define BGP_UNNUM_DEFAULT_RA_INTERVAL 10 diff --git a/lib/hash.c b/lib/hash.c index a7714f1569..e74e4355dc 100644 --- a/lib/hash.c +++ b/lib/hash.c @@ -94,6 +94,10 @@ static void hash_expand(struct hash *hash) struct hash_backet *hb, *hbnext, **new_index; new_size = hash->size * 2; + + if (hash->max_size && new_size > hash->max_size) + return; + new_index = XCALLOC(MTYPE_HASH_INDEX, sizeof(struct hash_backet *) * new_size); if (new_index == NULL) diff --git a/lib/hash.h b/lib/hash.h index 6ce29f0426..236abbbd6a 100644 --- a/lib/hash.h +++ b/lib/hash.h @@ -64,6 +64,9 @@ struct hash { /* Hash table size. Must be power of 2 */ unsigned int size; + /* If max_size is 0 there is no limit */ + unsigned int max_size; + /* Key make function. */ unsigned int (*hash_key)(void *); From a08ca0a7e101cbc44fc9300520bd0ab6a2c9b784 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 Jul 2017 21:09:01 -0300 Subject: [PATCH 66/75] lib: remove SAFI_RESERVED_4 and SAFI_RESERVED_5 SAFI values have been a major source of confusion over the last few years. That's because each SAFI needs to be represented in two different ways: * IANA's value used to send/receive packets over the network; * Internal value used for array indexing. In the second case, defining reserved values makes no sense because we don't want to index SAFIs that simply don't exist. The sole purpose of the internal SAFI values is to remove the gaps we have among the IANA values, which would represent wasted memory in C arrays. With that said, remove these reserved SAFIs to avoid further confusion in the future. Signed-off-by: Renato Westphal --- bgpd/bgp_fsm.c | 8 ++++---- bgpd/bgp_vty.c | 6 ------ bgpd/bgpd.c | 2 +- lib/zebra.h | 18 +++++------------- 4 files changed, 10 insertions(+), 24 deletions(-) diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index cf1cb18689..b609abac69 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -488,7 +488,7 @@ static int bgp_graceful_restart_timer_expire(struct thread *thread) /* NSF delete stale route */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++) + for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) if (peer->nsf[afi][safi]) bgp_clear_stale_route(peer, afi, safi); @@ -521,7 +521,7 @@ static int bgp_graceful_stale_timer_expire(struct thread *thread) /* NSF delete stale route */ for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++) + for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) if (peer->nsf[afi][safi]) bgp_clear_stale_route(peer, afi, safi); @@ -1022,7 +1022,7 @@ int bgp_stop(struct peer *peer) for (afi = AFI_IP; afi < AFI_MAX; afi++) for (safi = SAFI_UNICAST; - safi < SAFI_RESERVED_4; safi++) + safi <= SAFI_MPLS_VPN; safi++) peer->nsf[afi][safi] = 0; } @@ -1425,7 +1425,7 @@ static int bgp_establish(struct peer *peer) /* graceful restart */ UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT); for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++) { + for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) { if (peer->afc_nego[afi][safi] && CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV) && CHECK_FLAG(peer->af_cap[afi][safi], diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 65a1473f75..db503516d5 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -7079,12 +7079,6 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi, json); } safi++; - if (safi == SAFI_RESERVED_4 - || safi - == SAFI_RESERVED_5) /* handle special - cases to match - zebra.h */ - safi++; if (!safi_wildcard) safi = SAFI_MAX; } diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index a0e2d6749a..a078bdfd7e 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1842,7 +1842,7 @@ static void peer_nsf_stop(struct peer *peer) UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE); for (afi = AFI_IP; afi < AFI_MAX; afi++) - for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++) + for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) peer->nsf[afi][safi] = 0; if (peer->t_gr_restart) { diff --git a/lib/zebra.h b/lib/zebra.h index 8e1c4db804..7b705bb83f 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -419,19 +419,10 @@ typedef enum { AFI_IP = 1, AFI_IP6 = 2, AFI_L2VPN = 3, AFI_MAX = 4 } afi_t; #define SAFI_UNICAST 1 #define SAFI_MULTICAST 2 #define SAFI_MPLS_VPN 3 -#define SAFI_RESERVED_4 4 -#define SAFI_ENCAP 5 -#define SAFI_RESERVED_5 5 -#define SAFI_EVPN 6 -#define SAFI_LABELED_UNICAST 7 -#define SAFI_MAX 8 - -#define IANA_SAFI_RESERVED 0 -#define IANA_SAFI_UNICAST 1 -#define IANA_SAFI_MULTICAST 2 -#define IANA_SAFI_LABELED_UNICAST 4 -#define IANA_SAFI_ENCAP 7 -#define IANA_SAFI_MPLS_VPN 128 +#define SAFI_ENCAP 4 +#define SAFI_EVPN 5 +#define SAFI_LABELED_UNICAST 6 +#define SAFI_MAX 7 /* * The above AFI and SAFI definitions are for internal use. The protocol @@ -454,6 +445,7 @@ typedef enum { #define IANA_SAFI_RESERVED 0 #define IANA_SAFI_UNICAST 1 #define IANA_SAFI_MULTICAST 2 +#define IANA_SAFI_LABELED_UNICAST 4 #define IANA_SAFI_ENCAP 7 #define IANA_SAFI_EVPN 70 #define IANA_SAFI_MPLS_VPN 128 From 5c5255381e5b457e263081455a9677afa6b9e470 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 Jul 2017 21:06:40 -0300 Subject: [PATCH 67/75] lib/bgpd: introduce the iana_safi_t enum We had afi_t/iana_afi_t for AFIs but only safi_t for SAFIs. Fix this inconsistency. Signed-off-by: Renato Westphal --- bgpd/bgp_attr.c | 10 ++++++---- bgpd/bgp_open.c | 15 +++++++++------ bgpd/bgp_open.h | 2 +- bgpd/bgp_packet.c | 15 +++++++++------ bgpd/bgp_route.c | 2 +- bgpd/bgp_updgrp_packet.c | 4 ++-- bgpd/bgp_vty.c | 8 ++++++++ bgpd/bgpd.c | 6 +++--- bgpd/bgpd.h | 4 ++-- bgpd/rfapi/rfapi_import.c | 4 ++++ lib/prefix.c | 3 ++- lib/zebra.h | 38 ++++++++++++++++++++------------------ tests/bgpd/test_mp_attr.c | 2 +- 13 files changed, 68 insertions(+), 45 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index ef32b9cf92..ca9a50db55 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1677,7 +1677,8 @@ int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, { iana_afi_t pkt_afi; afi_t afi; - safi_t pkt_safi, safi; + iana_safi_t pkt_safi; + safi_t safi; bgp_size_t nlri_len; size_t start; struct stream *s; @@ -1826,7 +1827,8 @@ int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args, struct stream *s; iana_afi_t pkt_afi; afi_t afi; - safi_t pkt_safi, safi; + iana_safi_t pkt_safi; + safi_t safi; u_int16_t withdraw_len; struct peer *const peer = args->peer; struct attr *const attr = args->attr; @@ -2593,7 +2595,7 @@ size_t bgp_packet_mpattr_start(struct stream *s, struct peer *peer, afi_t afi, { size_t sizep; iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; afi_t nh_afi; /* Set extended bit always to encode the attribute length as 2 bytes */ @@ -3280,7 +3282,7 @@ size_t bgp_packet_mpunreach_start(struct stream *s, afi_t afi, safi_t safi) { unsigned long attrlen_pnt; iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; /* Set extended bit always to encode the attribute length as 2 bytes */ stream_putc(s, BGP_ATTR_FLAG_OPTIONAL | BGP_ATTR_FLAG_EXTLEN); diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index b18a4b7c46..2c988f86cc 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -298,7 +298,8 @@ static int bgp_capability_orf_entry(struct peer *peer, u_char num; iana_afi_t pkt_afi; afi_t afi; - safi_t pkt_safi, safi; + iana_safi_t pkt_safi; + safi_t safi; u_char type; u_char mode; u_int16_t sm_cap = 0; /* capability send-mode receive */ @@ -466,7 +467,7 @@ static int bgp_capability_restart(struct peer *peer, afi_t afi; safi_t safi; iana_afi_t pkt_afi = stream_getw(s); - safi_t pkt_safi = stream_getc(s); + iana_safi_t pkt_safi = stream_getc(s); u_char flag = stream_getc(s); /* Convert AFI, SAFI to internal values, check. */ @@ -543,7 +544,7 @@ static int bgp_capability_addpath(struct peer *peer, afi_t afi; safi_t safi; iana_afi_t pkt_afi = stream_getw(s); - safi_t pkt_safi = stream_getc(s); + iana_safi_t pkt_safi = stream_getc(s); u_char send_receive = stream_getc(s); if (bgp_debug_neighbor_events(peer)) @@ -600,7 +601,8 @@ static int bgp_capability_enhe(struct peer *peer, struct capability_header *hdr) while (stream_get_getp(s) + 6 <= end) { iana_afi_t pkt_afi = stream_getw(s); afi_t afi; - safi_t safi, pkt_safi = stream_getw(s); + iana_safi_t pkt_safi = stream_getw(s); + safi_t safi; iana_afi_t pkt_nh_afi = stream_getw(s); afi_t nh_afi; @@ -1199,7 +1201,7 @@ static void bgp_open_capability_orf(struct stream *s, struct peer *peer, unsigned long numberp; int number_of_orfs = 0; iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; /* Convert AFI, SAFI to values for packet. */ bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, &pkt_safi); @@ -1264,7 +1266,8 @@ void bgp_open_capability(struct stream *s, struct peer *peer) unsigned long cp, capp, rcapp; iana_afi_t pkt_afi; afi_t afi; - safi_t safi, pkt_safi; + safi_t safi; + iana_safi_t pkt_safi; as_t local_as; u_int32_t restart_time; u_char afi_safi_count = 0; diff --git a/bgpd/bgp_open.h b/bgpd/bgp_open.h index cbd32116b4..6b92e6e38c 100644 --- a/bgpd/bgp_open.h +++ b/bgpd/bgp_open.h @@ -31,7 +31,7 @@ struct capability_header { struct capability_mp_data { iana_afi_t afi; u_char reserved; - safi_t safi; + iana_safi_t safi; }; struct capability_as4 { diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index e92f2d6977..003fbaff63 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -142,7 +142,7 @@ static struct stream *bgp_update_packet_eor(struct peer *peer, afi_t afi, { struct stream *s; iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; if (DISABLE_BGP_ANNOUNCE) return NULL; @@ -671,7 +671,7 @@ void bgp_route_refresh_send(struct peer *peer, afi_t afi, safi_t safi, struct bgp_filter *filter; int orf_refresh = 0; iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; if (DISABLE_BGP_ANNOUNCE) return; @@ -761,7 +761,7 @@ void bgp_capability_send(struct peer *peer, afi_t afi, safi_t safi, { struct stream *s; iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; /* Convert AFI, SAFI to values for packet. */ bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi, &pkt_safi); @@ -1338,8 +1338,9 @@ int bgp_nlri_parse(struct peer *peer, struct attr *attr, packet); case SAFI_EVPN: return bgp_nlri_parse_evpn(peer, attr, packet, mp_withdraw); + default: + return -1; } - return -1; } /* Parse BGP Update packet and make attribute object. */ @@ -1697,7 +1698,8 @@ static void bgp_route_refresh_receive(struct peer *peer, bgp_size_t size) { iana_afi_t pkt_afi; afi_t afi; - safi_t pkt_safi, safi; + iana_safi_t pkt_safi; + safi_t safi; struct stream *s; struct peer_af *paf; struct update_group *updgrp; @@ -1965,7 +1967,8 @@ static int bgp_capability_msg_parse(struct peer *peer, u_char *pnt, u_char action; iana_afi_t pkt_afi; afi_t afi; - safi_t pkt_safi, safi; + iana_safi_t pkt_safi; + safi_t safi; end = pnt + length; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index b554aeb32b..8c2278339f 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2288,7 +2288,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, int always) { iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; if (!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) return 0; diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 1a23a36e91..692db32fa4 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -845,7 +845,7 @@ struct bpacket *subgroup_update_packet(struct update_subgroup *subgrp) send_attr_str); if (!stream_empty(snlri)) { iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; pkt_afi = afi_int2iana(afi); pkt_safi = safi_int2iana(safi); @@ -989,7 +989,7 @@ struct bpacket *subgroup_withdraw_packet(struct update_subgroup *subgrp) /* If first time, format the MP_UNREACH header */ if (first_time) { iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; pkt_afi = afi_int2iana(afi); pkt_safi = safi_int2iana(safi); diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index db503516d5..0220a7e55d 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -78,6 +78,10 @@ static enum node_type bgp_node_type(afi_t afi, safi_t safi) case SAFI_MPLS_VPN: return BGP_VPNV4_NODE; break; + default: + /* not expected */ + return BGP_IPV4_NODE; + break; } break; case AFI_IP6: @@ -94,6 +98,10 @@ static enum node_type bgp_node_type(afi_t afi, safi_t safi) case SAFI_MPLS_VPN: return BGP_VPNV6_NODE; break; + default: + /* not expected */ + return BGP_IPV4_NODE; + break; } break; case AFI_L2VPN: diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index a078bdfd7e..0729d0a1b3 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -611,8 +611,8 @@ int bgp_listen_limit_unset(struct bgp *bgp) return 0; } -int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi, safi_t pkt_safi, afi_t *afi, - safi_t *safi) +int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi, iana_safi_t pkt_safi, + afi_t *afi, safi_t *safi) { /* Map from IANA values to internal values, return error if * values are unrecognized. @@ -626,7 +626,7 @@ int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi, safi_t pkt_safi, afi_t *afi, } int bgp_map_afi_safi_int2iana(afi_t afi, safi_t safi, iana_afi_t *pkt_afi, - safi_t *pkt_safi) + iana_safi_t *pkt_safi) { /* Map from internal values to IANA values, return error if * internal values are bad (unexpected). diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 67b8289c70..ff15115e03 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -1381,10 +1381,10 @@ extern void bgp_route_map_terminate(void); extern int peer_cmp(struct peer *p1, struct peer *p2); -extern int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi, safi_t pkt_safi, +extern int bgp_map_afi_safi_iana2int(iana_afi_t pkt_afi, iana_safi_t pkt_safi, afi_t *afi, safi_t *safi); extern int bgp_map_afi_safi_int2iana(afi_t afi, safi_t safi, - iana_afi_t *pkt_afi, safi_t *pkt_safi); + iana_afi_t *pkt_afi, iana_safi_t *pkt_safi); extern struct peer_af *peer_af_create(struct peer *, afi_t, safi_t); extern struct peer_af *peer_af_find(struct peer *, afi_t, safi_t); diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 0bbbe12cce..61739d38ab 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -3872,6 +3872,10 @@ rfapiBgpInfoFilteredImportFunction(safi_t safi) case SAFI_ENCAP: return rfapiBgpInfoFilteredImportEncap; + + default: + /* not expected */ + return NULL; } zlog_err("%s: bad safi %d", __func__, safi); return NULL; diff --git a/lib/prefix.c b/lib/prefix.c index 88b13cd99f..0ba0025c68 100644 --- a/lib/prefix.c +++ b/lib/prefix.c @@ -507,8 +507,9 @@ const char *safi2str(safi_t safi) return "evpn"; case SAFI_LABELED_UNICAST: return "labeled-unicast"; + default: + return "unknown"; } - return NULL; } /* If n includes p prefix then return 1 else return 0. */ diff --git a/lib/zebra.h b/lib/zebra.h index 7b705bb83f..1924675a14 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -416,13 +416,15 @@ extern const char *zserv_command_string(unsigned int command); typedef enum { AFI_IP = 1, AFI_IP6 = 2, AFI_L2VPN = 3, AFI_MAX = 4 } afi_t; /* Subsequent Address Family Identifier. */ -#define SAFI_UNICAST 1 -#define SAFI_MULTICAST 2 -#define SAFI_MPLS_VPN 3 -#define SAFI_ENCAP 4 -#define SAFI_EVPN 5 -#define SAFI_LABELED_UNICAST 6 -#define SAFI_MAX 7 +typedef enum { + SAFI_UNICAST = 1, + SAFI_MULTICAST = 2, + SAFI_MPLS_VPN = 3, + SAFI_ENCAP = 4, + SAFI_EVPN = 5, + SAFI_LABELED_UNICAST = 6, + SAFI_MAX = 7 +} safi_t; /* * The above AFI and SAFI definitions are for internal use. The protocol @@ -442,13 +444,15 @@ typedef enum { IANA_AFI_IP6MR = 129 } iana_afi_t; -#define IANA_SAFI_RESERVED 0 -#define IANA_SAFI_UNICAST 1 -#define IANA_SAFI_MULTICAST 2 -#define IANA_SAFI_LABELED_UNICAST 4 -#define IANA_SAFI_ENCAP 7 -#define IANA_SAFI_EVPN 70 -#define IANA_SAFI_MPLS_VPN 128 +typedef enum { + IANA_SAFI_RESERVED = 0, + IANA_SAFI_UNICAST = 1, + IANA_SAFI_MULTICAST = 2, + IANA_SAFI_LABELED_UNICAST = 4, + IANA_SAFI_ENCAP = 7, + IANA_SAFI_EVPN = 70, + IANA_SAFI_MPLS_VPN = 128 +} iana_safi_t; /* Default Administrative Distance of each protocol. */ #define ZEBRA_KERNEL_DISTANCE_DEFAULT 0 @@ -469,8 +473,6 @@ typedef enum { #define UNSET_FLAG(V,F) (V) &= ~(F) #define RESET_FLAG(V) (V) = 0 -typedef u_int8_t safi_t; - /* Zebra types. Used in Zserv message header. */ typedef u_int16_t zebra_size_t; typedef u_int16_t zebra_command_t; @@ -504,7 +506,7 @@ static inline iana_afi_t afi_int2iana(afi_t afi) return IANA_AFI_RESERVED; } -static inline safi_t safi_iana2int(safi_t safi) +static inline safi_t safi_iana2int(iana_safi_t safi) { if (safi == IANA_SAFI_UNICAST) return SAFI_UNICAST; @@ -521,7 +523,7 @@ static inline safi_t safi_iana2int(safi_t safi) return SAFI_MAX; } -static inline safi_t safi_int2iana(safi_t safi) +static inline iana_safi_t safi_int2iana(safi_t safi) { if (safi == SAFI_UNICAST) return IANA_SAFI_UNICAST; diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index 7c0afa1b92..30d5fdd6cd 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -1059,7 +1059,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type) parse_ret = bgp_mp_unreach_parse(&attr_args, &nlri); if (!parse_ret) { iana_afi_t pkt_afi; - safi_t pkt_safi; + iana_safi_t pkt_safi; /* Convert AFI, SAFI to internal values, check. */ if (bgp_map_afi_safi_int2iana(nlri.afi, nlri.safi, &pkt_afi, From 085347cfadbca04a7dfee175971c23e266becc6b Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 Jul 2017 21:22:20 -0300 Subject: [PATCH 68/75] lib: use switch statements in the AFI/SAFI conversion functions Switch statements are more elegant (and potentially faster... but that's not the main motivation). Signed-off-by: Renato Westphal --- lib/zebra.h | 56 ++++++++++++++++++++++++++++++++--------------------- 1 file changed, 34 insertions(+), 22 deletions(-) diff --git a/lib/zebra.h b/lib/zebra.h index 1924675a14..c31fe0809c 100644 --- a/lib/zebra.h +++ b/lib/zebra.h @@ -486,58 +486,70 @@ typedef uint32_t route_tag_t; static inline afi_t afi_iana2int(iana_afi_t afi) { - if (afi == IANA_AFI_IPV4) + switch (afi) { + case IANA_AFI_IPV4: return AFI_IP; - if (afi == IANA_AFI_IPV6) + case IANA_AFI_IPV6: return AFI_IP6; - if (afi == IANA_AFI_L2VPN) + case IANA_AFI_L2VPN: return AFI_L2VPN; - return AFI_MAX; + default: + return AFI_MAX; + } } static inline iana_afi_t afi_int2iana(afi_t afi) { - if (afi == AFI_IP) + switch (afi) { + case AFI_IP: return IANA_AFI_IPV4; - if (afi == AFI_IP6) + case AFI_IP6: return IANA_AFI_IPV6; - if (afi == AFI_L2VPN) + case AFI_L2VPN: return IANA_AFI_L2VPN; - return IANA_AFI_RESERVED; + default: + return IANA_AFI_RESERVED; + } } static inline safi_t safi_iana2int(iana_safi_t safi) { - if (safi == IANA_SAFI_UNICAST) + switch (safi) { + case IANA_SAFI_UNICAST: return SAFI_UNICAST; - if (safi == IANA_SAFI_MULTICAST) + case IANA_SAFI_MULTICAST: return SAFI_MULTICAST; - if (safi == IANA_SAFI_MPLS_VPN) + case IANA_SAFI_MPLS_VPN: return SAFI_MPLS_VPN; - if (safi == IANA_SAFI_ENCAP) + case IANA_SAFI_ENCAP: return SAFI_ENCAP; - if (safi == IANA_SAFI_EVPN) + case IANA_SAFI_EVPN: return SAFI_EVPN; - if (safi == IANA_SAFI_LABELED_UNICAST) + case IANA_SAFI_LABELED_UNICAST: return SAFI_LABELED_UNICAST; - return SAFI_MAX; + default: + return SAFI_MAX; + } } static inline iana_safi_t safi_int2iana(safi_t safi) { - if (safi == SAFI_UNICAST) + switch (safi) { + case SAFI_UNICAST: return IANA_SAFI_UNICAST; - if (safi == SAFI_MULTICAST) + case SAFI_MULTICAST: return IANA_SAFI_MULTICAST; - if (safi == SAFI_MPLS_VPN) + case SAFI_MPLS_VPN: return IANA_SAFI_MPLS_VPN; - if (safi == SAFI_ENCAP) + case SAFI_ENCAP: return IANA_SAFI_ENCAP; - if (safi == SAFI_EVPN) + case SAFI_EVPN: return IANA_SAFI_EVPN; - if (safi == SAFI_LABELED_UNICAST) + case SAFI_LABELED_UNICAST: return IANA_SAFI_LABELED_UNICAST; - return IANA_SAFI_RESERVED; + default: + return IANA_SAFI_RESERVED; + } } #endif /* _ZEBRA_H */ From a46a2e9b4e8de782ac07e01429a80ed7ec167dcb Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 Jul 2017 21:37:46 -0300 Subject: [PATCH 69/75] bgpd: don't make any assumptions about the size of an enum The size of an enum is compiler dependent and thus we shouldn't use enums inside structures that represent fields of a packet. Problem detected by the 'test_capability' unit test. The problem was not apparent before because the 'iana_safi_t' enum didn't exist and 'safi_t' was a typedef to uint8_t. Now we have two different enums, 'iana_afi_t' and 'iana_safi_t', and both need to be encoded in different ways on the wire (2 bytes vs 1 byte). Signed-off-by: Renato Westphal --- bgpd/bgp_open.h | 4 ++-- bgpd/bgpd.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/bgpd/bgp_open.h b/bgpd/bgp_open.h index 6b92e6e38c..83b79a589a 100644 --- a/bgpd/bgp_open.h +++ b/bgpd/bgp_open.h @@ -29,9 +29,9 @@ struct capability_header { /* Generic MP capability data */ struct capability_mp_data { - iana_afi_t afi; + uint16_t afi; /* iana_afi_t */ u_char reserved; - iana_safi_t safi; + uint8_t safi; /* iana_safi_t */ }; struct capability_as4 { diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index ff15115e03..250ee5f4e8 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -922,10 +922,10 @@ DECLARE_QOBJ_TYPE(peer) stream. */ struct bgp_nlri { /* AFI. */ - afi_t afi; + uint16_t afi; /* iana_afi_t */ /* SAFI. */ - safi_t safi; + uint8_t safi; /* iana_safi_t */ /* Pointer to NLRI byte stream. */ u_char *nlri; From 399aedd6375f48ca5e99cc9391973566540b20a2 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Mon, 31 Jul 2017 21:01:34 -0300 Subject: [PATCH 70/75] tests: fix small typo Signed-off-by: Renato Westphal --- tests/bgpd/test_capability.c | 2 +- tests/bgpd/test_capability.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/bgpd/test_capability.c b/tests/bgpd/test_capability.c index 9ec2b5df19..e8700a8b4a 100644 --- a/tests/bgpd/test_capability.c +++ b/tests/bgpd/test_capability.c @@ -170,7 +170,7 @@ static struct test_segment mp_segments[] = { /* 8 */ { "MP6", - "MP IP4/MPLS-laveled VPN", + "MP IP4/MPLS-labeled VPN", {CAPABILITY_CODE_MP, 0x4, 0x0, 0x1, 0x0, 0x80}, 6, SHOULD_PARSE, diff --git a/tests/bgpd/test_capability.py b/tests/bgpd/test_capability.py index 4cb650092b..872fcb6d12 100644 --- a/tests/bgpd/test_capability.py +++ b/tests/bgpd/test_capability.py @@ -8,7 +8,7 @@ TestCapability.okfail("MPv6: MP IPv6/Uni") TestCapability.okfail("MP2: MP IP/Multicast") TestCapability.okfail("MP3: MP IP6/MPLS-labeled VPN") TestCapability.okfail("MP5: MP IP6/MPLS-VPN") -TestCapability.okfail("MP6: MP IP4/MPLS-laveled VPN") +TestCapability.okfail("MP6: MP IP4/MPLS-labeled VPN") TestCapability.okfail("MP8: MP unknown AFI/SAFI") TestCapability.okfail("MP-short: MP IP4/Unicast, length too short (< minimum)") TestCapability.okfail("MP-overflow: MP IP4/Unicast, length too long") From f1b32b2e5e6f0f00a290d4ba7d6529f1dd1b0a56 Mon Sep 17 00:00:00 2001 From: David Lamparter Date: Mon, 31 Jul 2017 22:38:48 +0200 Subject: [PATCH 71/75] build: fix/improve clippy dependencies Signed-off-by: David Lamparter --- common.am | 4 +++- lib/subdir.am | 7 +++++++ zebra/subdir.am | 1 + 3 files changed, 11 insertions(+), 1 deletion(-) diff --git a/common.am b/common.am index e252b74297..b115a871b9 100644 --- a/common.am +++ b/common.am @@ -8,9 +8,11 @@ am__v_CLIPPY_ = $(am__v_CLIPPY_$(AM_DEFAULT_VERBOSITY)) am__v_CLIPPY_0 = @echo " CLIPPY " $@; am__v_CLIPPY_1 = +CLIPPY_DEPS = $(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py + SUFFIXES = _clippy.c .proto .pb-c.c .pb-c.h .pb.h .c_clippy.c: - $(AM_V_at)$(MAKE) -C $(top_builddir)/$(HOSTTOOLS) lib/clippy + @{ test -x $(top_builddir)/$(HOSTTOOLS)lib/clippy || $(MAKE) -C $(top_builddir)/$(HOSTTOOLS) lib/clippy; } $(AM_V_CLIPPY)$(top_builddir)/$(HOSTTOOLS)lib/clippy $(top_srcdir)/python/clidef.py $< > $@.tmp @{ test -f $@ && diff $@.tmp $@ >/dev/null 2>/dev/null; } && rm $@.tmp || mv $@.tmp $@ diff --git a/lib/subdir.am b/lib/subdir.am index a49781e18c..cc082a8e85 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -73,6 +73,7 @@ lib_libfrr_la_SOURCES = \ lib/zclient.c \ # end +lib/plist_clippy.c: $(CLIPPY_DEPS) lib/plist.lo: lib/plist_clippy.c pkginclude_HEADERS += \ @@ -220,12 +221,18 @@ BUILT_SOURCES += \ lib/route_types.h \ # end +## force route_types.h +$(lib_clippy_OBJECTS): lib/route_types.h +$(lib_libfrr_la_OBJECTS): lib/route_types.h + AM_YFLAGS = -d -Dapi.prefix=@BISON_OPENBRACE@cmd_yy@BISON_CLOSEBRACE@ @BISON_VERBOSE@ lib/command_lex.h: lib/command_lex.c @if test ! -f $@; then rm -f "lib/command_lex.c"; else :; fi @if test ! -f $@; then $(MAKE) $(AM_MAKEFLAGS) "lib/command_lex.c"; else :; fi +lib/command_lex.lo: lib/command_parse.h lib/command_parse.lo: lib/command_lex.h +lib/lib_clippy-command_lex.$(OBJEXT): lib/command_parse.h lib/lib_clippy-command_parse.$(OBJEXT): lib/command_lex.h lib/route_types.h: $(top_srcdir)/lib/route_types.txt $(top_srcdir)/lib/route_types.pl diff --git a/zebra/subdir.am b/zebra/subdir.am index 546da3cf25..ceffa863e9 100644 --- a/zebra/subdir.am +++ b/zebra/subdir.am @@ -66,6 +66,7 @@ zebra_zebra_SOURCES = \ zebra/zserv.c \ # end +zebra/zebra_vty_clippy.c: $(CLIPPY_DEPS) zebra/zebra_vty.$(OBJEXT): zebra/zebra_vty_clippy.c noinst_HEADERS += \ From bb744275859b462161b1b97b4f45581454dade31 Mon Sep 17 00:00:00 2001 From: Daniel Walton Date: Tue, 1 Aug 2017 18:31:56 +0000 Subject: [PATCH 72/75] bgpd: multipath change for VRF route is not updated in zebra Signed-off-by: Daniel Walton If you are doing multipath in a VRF and bounce one of the multipaths for a prefix, bgp is not updating the zebra entry for that prefix with the new multipaths. We start with: cel-redxp-10# show bgp vrf RED ipv4 unicast 6.0.0.16/32 BGP routing table entry for 6.0.0.16/32 Paths: (4 available, best #4, table RED) Advertised to non peer-group peers: spine-1(swp1) spine-2(swp2) spine-3(swp3) spine-4(swp4) 104 65104 65002 fe80::202:ff:fe00:2d from spine-4(swp4) (6.0.0.12) (fe80::202:ff:fe00:2d) (used) Origin incomplete, localpref 100, valid, external, multipath, bestpath-from-AS 104 AddPath ID: RX 0, TX 21 Last update: Tue Aug 1 18:28:33 2017 102 65104 65002 fe80::202:ff:fe00:25 from spine-2(swp2) (6.0.0.10) (fe80::202:ff:fe00:25) (used) Origin incomplete, localpref 100, valid, external, multipath, bestpath-from-AS 102 AddPath ID: RX 0, TX 20 Last update: Tue Aug 1 18:28:33 2017 103 65104 65002 fe80::202:ff:fe00:29 from spine-3(swp3) (6.0.0.11) (fe80::202:ff:fe00:29) (used) Origin incomplete, localpref 100, valid, external, multipath, bestpath-from-AS 103 AddPath ID: RX 0, TX 17 Last update: Tue Aug 1 18:28:33 2017 101 65104 65002 fe80::202:ff:fe00:21 from spine-1(swp1) (6.0.0.9) (fe80::202:ff:fe00:21) (used) Origin incomplete, localpref 100, valid, external, multipath, bestpath-from-AS 101, best AddPath ID: RX 0, TX 8 Last update: Tue Aug 1 18:28:33 2017 cel-redxp-10# cel-redxp-10# show ip route vrf RED 6.0.0.16/32 Routing entry for 6.0.0.16/32 Known via "bgp", distance 20, metric 0, vrf RED, best Last update 00:00:25 ago * fe80::202:ff:fe00:21, via swp1 * fe80::202:ff:fe00:25, via swp2 * fe80::202:ff:fe00:29, via swp3 * fe80::202:ff:fe00:2d, via swp4 cel-redxp-10# And then on spine-1 we bounce all peers spine-1# clear ip bgp * spine-1# On the leaf (cel-redxp-10) we remove the route from spine-1 cel-redxp-10# show ip route vrf RED 6.0.0.16/32 Routing entry for 6.0.0.16/32 Known via "bgp", distance 20, metric 0, vrf RED, best Last update 00:00:01 ago * fe80::202:ff:fe00:25, via swp2 * fe80::202:ff:fe00:29, via swp3 * fe80::202:ff:fe00:2d, via swp4 cel-redxp-10# So far so good. The problem is when the session to spine-1 comes back up bgp will mark the flag from spine-1 as `multipath` but does not update zebra. We end up in a state where BGP has 4 paths flags as multipath but only 3 paths are in the RIB. --- bgpd/bgp_route.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 8c2278339f..1fb42f6182 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -2078,7 +2078,7 @@ static wq_item_status bgp_process_main(struct work_queue *wq, void *data) vnc_import_bgp_add_route(bgp, p, old_select); vnc_import_bgp_exterior_add_route(bgp, p, old_select); #endif - if (bgp_fibupd_safi(safi) && !bgp->name + if (bgp_fibupd_safi(safi) && !bgp_option_check(BGP_OPT_NO_FIB) && new_select->type == ZEBRA_ROUTE_BGP && new_select->sub_type == BGP_ROUTE_NORMAL) From 30c0daa4bae1f31429a584a630ab59ff64f67611 Mon Sep 17 00:00:00 2001 From: Jafar Al-Gharaibeh Date: Tue, 1 Aug 2017 13:47:02 -0500 Subject: [PATCH 73/75] ospfd: Fix, don't run network unset commands on virtual links Signed-off-by: Jafar Al-Gharaibeh --- ospfd/ospfd.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ospfd/ospfd.c b/ospfd/ospfd.c index cee2244dd9..381082fcda 100644 --- a/ospfd/ospfd.c +++ b/ospfd/ospfd.c @@ -976,9 +976,13 @@ int ospf_network_unset(struct ospf *ospf, struct prefix_ipv4 *p, rn->info = NULL; route_unlock_node(rn); /* initial reference */ - /* Find interfaces that not configured already. */ + /* Find interfaces that are not configured already. */ for (ALL_LIST_ELEMENTS(ospf->oiflist, node, nnode, oi)) { - ospf_network_run_subnet(ospf, oi->connected, NULL, NULL); + + if (oi->type == OSPF_IFTYPE_VIRTUALLINK) + continue; + + ospf_network_run_subnet(ospf, oi->connected, NULL, NULL); } /* Update connected redistribute. */ From bd402424a472178263228d94f314aa50a9687062 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 1 Aug 2017 22:12:24 -0300 Subject: [PATCH 74/75] lib: fix build from git repository on OpenBSD The OpenBSD's cp(1) command doesn't support the -v option. This will change in the next releases (starting from v6.2) but this patch fixes the problem for v6.1 and older releases. Fixes Issue #875. Signed-off-by: Renato Westphal --- lib/subdir.am | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/subdir.am b/lib/subdir.am index cc082a8e85..5a1971cba7 100644 --- a/lib/subdir.am +++ b/lib/subdir.am @@ -251,7 +251,7 @@ GITH=lib/gitversion.h lib/gitversion.h.tmp: $(top_srcdir)/.git @PERL@ $(top_srcdir)/lib/gitversion.pl $(top_srcdir) > ${GITH}.tmp lib/gitversion.h: lib/gitversion.h.tmp - { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp -v ${GITH}.tmp ${GITH} + { test -f ${GITH} && diff -s -q ${GITH}.tmp ${GITH}; } || cp ${GITH}.tmp ${GITH} else .PHONY: lib/gitversion.h From 2d3ed84004f926f9267955ef44a06349fe7de530 Mon Sep 17 00:00:00 2001 From: Renato Westphal Date: Tue, 1 Aug 2017 22:19:18 -0300 Subject: [PATCH 75/75] doc/babeld: small documentation update Fixes Issue #889. Signed-off-by: Renato Westphal --- babeld/babeld.conf.sample | 4 ++-- doc/babeld.texi | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/babeld/babeld.conf.sample b/babeld/babeld.conf.sample index a4924ec7b7..a77453a734 100644 --- a/babeld/babeld.conf.sample +++ b/babeld/babeld.conf.sample @@ -9,8 +9,8 @@ debug babel common router babel ! network wlan0 ! network eth0 -! redistribute kernel -! no redistribute static +! redistribute ipv4 kernel +! no redistribute ipv6 static ! The defaults are fine for a wireless interface diff --git a/doc/babeld.texi b/doc/babeld.texi index 2dfb5f8c0a..341f692869 100644 --- a/doc/babeld.texi +++ b/doc/babeld.texi @@ -179,8 +179,8 @@ The default is 4@dmn{s}. @node Babel redistribution, Show Babel information, Babel configuration, Babel @section Babel redistribution -@deffn {Babel command} {redistribute @var{kind}} -@deffnx {Babel command} {no redistribute @var{kind}} +@deffn {Babel command} {redistribute @var{} @var{kind}} +@deffnx {Babel command} {no redistribute @var{} @var{kind}} Specify which kind of routes should be redistributed into Babel. @end deffn