diff options
218 files changed, 6075 insertions, 1472 deletions
diff --git a/bgpd/bgp_addpath.c b/bgpd/bgp_addpath.c index aaa77b04d..75fdb0bb4 100644 --- a/bgpd/bgp_addpath.c +++ b/bgpd/bgp_addpath.c @@ -65,8 +65,8 @@ bgp_addpath_names(enum bgp_addpath_strat strat) /* * Returns if any peer is transmitting addpaths for a given afi/safi. */ -int bgp_addpath_is_addpath_used(struct bgp_addpath_bgp_data *d, afi_t afi, - safi_t safi) +bool bgp_addpath_is_addpath_used(struct bgp_addpath_bgp_data *d, afi_t afi, + safi_t safi) { return d->total_peercount[afi][safi] > 0; } @@ -123,15 +123,15 @@ uint32_t bgp_addpath_id_for_peer(struct peer *peer, afi_t afi, safi_t safi, * Returns true if the path has an assigned addpath ID for any of the addpath * strategies. */ -int bgp_addpath_info_has_ids(struct bgp_addpath_info_data *d) +bool bgp_addpath_info_has_ids(struct bgp_addpath_info_data *d) { int i; for (i = 0; i < BGP_ADDPATH_MAX; i++) if (d->addpath_tx_id[i] != 0) - return 1; + return true; - return 0; + return false; } /* @@ -152,7 +152,7 @@ void bgp_addpath_free_node_data(struct bgp_addpath_bgp_data *bd, /* * Check to see if the addpath strategy requires DMED to be configured to work. */ -int bgp_addpath_dmed_required(int strategy) +bool bgp_addpath_dmed_required(int strategy) { return strategy == BGP_ADDPATH_BEST_PER_AS; } @@ -161,21 +161,20 @@ int bgp_addpath_dmed_required(int strategy) * Return true if this is a path we should advertise due to a * configured addpath-tx knob */ -int bgp_addpath_tx_path(enum bgp_addpath_strat strat, - struct bgp_path_info *pi) +bool bgp_addpath_tx_path(enum bgp_addpath_strat strat, struct bgp_path_info *pi) { switch (strat) { case BGP_ADDPATH_NONE: - return 0; + return false; case BGP_ADDPATH_ALL: - return 1; + return true; case BGP_ADDPATH_BEST_PER_AS: if (CHECK_FLAG(pi->flags, BGP_PATH_DMED_SELECTED)) - return 1; + return true; else - return 0; + return false; default: - return 0; + return false; } } diff --git a/bgpd/bgp_addpath.h b/bgpd/bgp_addpath.h index 786873a00..f61d68e18 100644 --- a/bgpd/bgp_addpath.h +++ b/bgpd/bgp_addpath.h @@ -32,8 +32,8 @@ void bgp_addpath_init_bgp_data(struct bgp_addpath_bgp_data *d); -int bgp_addpath_is_addpath_used(struct bgp_addpath_bgp_data *d, afi_t afi, - safi_t safi); +bool bgp_addpath_is_addpath_used(struct bgp_addpath_bgp_data *d, afi_t afi, + safi_t safi); void bgp_addpath_free_node_data(struct bgp_addpath_bgp_data *bd, struct bgp_addpath_node_data *nd, @@ -43,7 +43,7 @@ void bgp_addpath_free_info_data(struct bgp_addpath_info_data *d, struct bgp_addpath_node_data *nd); -int bgp_addpath_info_has_ids(struct bgp_addpath_info_data *d); +bool bgp_addpath_info_has_ids(struct bgp_addpath_info_data *d); uint32_t bgp_addpath_id_for_peer(struct peer *peer, afi_t afi, safi_t safi, struct bgp_addpath_info_data *d); @@ -51,14 +51,14 @@ uint32_t bgp_addpath_id_for_peer(struct peer *peer, afi_t afi, safi_t safi, const struct bgp_addpath_strategy_names * bgp_addpath_names(enum bgp_addpath_strat strat); -int bgp_addpath_dmed_required(int strategy); +bool bgp_addpath_dmed_required(int strategy); /* * Return true if this is a path we should advertise due to a configured * addpath-tx knob */ -int bgp_addpath_tx_path(enum bgp_addpath_strat strat, - struct bgp_path_info *pi); +bool bgp_addpath_tx_path(enum bgp_addpath_strat strat, + struct bgp_path_info *pi); /* * Change the type of addpath used for a peer. */ diff --git a/bgpd/bgp_advertise.c b/bgpd/bgp_advertise.c index 8d1c83cf5..9ee6a24bc 100644 --- a/bgpd/bgp_advertise.c +++ b/bgpd/bgp_advertise.c @@ -144,8 +144,8 @@ void bgp_advertise_unintern(struct hash *hash, struct bgp_advertise_attr *baa) } } -int bgp_adj_out_lookup(struct peer *peer, struct bgp_node *rn, - uint32_t addpath_tx_id) +bool bgp_adj_out_lookup(struct peer *peer, struct bgp_node *rn, + uint32_t addpath_tx_id) { struct bgp_adj_out *adj; struct peer_af *paf; @@ -169,11 +169,12 @@ int bgp_adj_out_lookup(struct peer *peer, struct bgp_node *rn, && adj->addpath_tx_id != addpath_tx_id) continue; - return (adj->adv ? (adj->adv->baa ? 1 : 0) - : (adj->attr ? 1 : 0)); + return (adj->adv + ? (adj->adv->baa ? true : false) + : (adj->attr ? true : false)); } - return 0; + return false; } @@ -208,8 +209,8 @@ void bgp_adj_in_remove(struct bgp_node *rn, struct bgp_adj_in *bai) XFREE(MTYPE_BGP_ADJ_IN, bai); } -int bgp_adj_in_unset(struct bgp_node *rn, struct peer *peer, - uint32_t addpath_id) +bool bgp_adj_in_unset(struct bgp_node *rn, struct peer *peer, + uint32_t addpath_id) { struct bgp_adj_in *adj; struct bgp_adj_in *adj_next; @@ -217,7 +218,7 @@ int bgp_adj_in_unset(struct bgp_node *rn, struct peer *peer, adj = rn->adj_in; if (!adj) - return 0; + return false; while (adj) { adj_next = adj->next; @@ -230,7 +231,7 @@ int bgp_adj_in_unset(struct bgp_node *rn, struct peer *peer, adj = adj_next; } - return 1; + return true; } void bgp_sync_init(struct peer *peer) diff --git a/bgpd/bgp_advertise.h b/bgpd/bgp_advertise.h index c98359875..6223dc94a 100644 --- a/bgpd/bgp_advertise.h +++ b/bgpd/bgp_advertise.h @@ -139,10 +139,10 @@ struct bgp_synchronize { #define BGP_ADJ_IN_DEL(N, A) BGP_PATH_INFO_DEL(N, A, adj_in) /* Prototypes. */ -extern int bgp_adj_out_lookup(struct peer *, struct bgp_node *, uint32_t); +extern bool bgp_adj_out_lookup(struct peer *, struct bgp_node *, uint32_t); extern void bgp_adj_in_set(struct bgp_node *, struct peer *, struct attr *, uint32_t); -extern int bgp_adj_in_unset(struct bgp_node *, struct peer *, uint32_t); +extern bool bgp_adj_in_unset(struct bgp_node *, struct peer *, uint32_t); extern void bgp_adj_in_remove(struct bgp_node *, struct bgp_adj_in *); extern void bgp_sync_init(struct peer *); diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 7c15fd371..0bdd079e0 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -130,14 +130,14 @@ static struct cluster_list *cluster_parse(struct in_addr *pnt, int length) return cluster; } -int cluster_loop_check(struct cluster_list *cluster, struct in_addr originator) +bool cluster_loop_check(struct cluster_list *cluster, struct in_addr originator) { int i; for (i = 0; i < cluster->length / 4; i++) if (cluster->list[i].s_addr == originator.s_addr) - return 1; - return 0; + return true; + return false; } static unsigned int cluster_hash_key_make(const void *p) @@ -263,16 +263,16 @@ void bgp_attr_flush_encap(struct attr *attr) * * This algorithm could be made faster if needed */ -static int encap_same(const struct bgp_attr_encap_subtlv *h1, - const struct bgp_attr_encap_subtlv *h2) +static bool encap_same(const struct bgp_attr_encap_subtlv *h1, + const struct bgp_attr_encap_subtlv *h2) { const struct bgp_attr_encap_subtlv *p; const struct bgp_attr_encap_subtlv *q; if (h1 == h2) - return 1; + return true; if (h1 == NULL || h2 == NULL) - return 0; + return false; for (p = h1; p; p = p->next) { for (q = h2; q; q = q->next) { @@ -283,7 +283,7 @@ static int encap_same(const struct bgp_attr_encap_subtlv *h1, } } if (!q) - return 0; + return false; } for (p = h2; p; p = p->next) { @@ -295,10 +295,10 @@ static int encap_same(const struct bgp_attr_encap_subtlv *h1, } } if (!q) - return 0; + return false; } - return 1; + return true; } static void *encap_hash_alloc(void *p) @@ -1274,7 +1274,7 @@ const uint8_t attr_flags_values[] = { }; static const size_t attr_flags_values_max = array_size(attr_flags_values) - 1; -static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) +static bool bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) { uint8_t mask = BGP_ATTR_FLAG_EXTLEN; const uint8_t flags = args->flags; @@ -1282,9 +1282,9 @@ static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) /* there may be attributes we don't know about */ if (attr_code > attr_flags_values_max) - return 0; + return false; if (attr_flags_values[attr_code] == 0) - return 0; + return false; /* RFC4271, "For well-known attributes, the Transitive bit MUST be set * to @@ -1296,7 +1296,7 @@ static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) EC_BGP_ATTR_FLAG, "%s well-known attributes must have transitive flag set (%x)", lookup_msg(attr_str, attr_code, NULL), flags); - return 1; + return true; } /* "For well-known attributes and for optional non-transitive @@ -1309,7 +1309,7 @@ static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) "%s well-known attribute " "must NOT have the partial flag set (%x)", lookup_msg(attr_str, attr_code, NULL), flags); - return 1; + return true; } if (CHECK_FLAG(flags, BGP_ATTR_FLAG_OPTIONAL) && !CHECK_FLAG(flags, BGP_ATTR_FLAG_TRANS)) { @@ -1317,7 +1317,7 @@ static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) "%s optional + transitive attribute " "must NOT have the partial flag set (%x)", lookup_msg(attr_str, attr_code, NULL), flags); - return 1; + return true; } } @@ -1329,10 +1329,10 @@ static int bgp_attr_flag_invalid(struct bgp_attr_parser_args *args) SET_FLAG(mask, BGP_ATTR_FLAG_PARTIAL); if ((flags & ~mask) == attr_flags_values[attr_code]) - return 0; + return false; bgp_attr_flags_diagnose(args, attr_flags_values[attr_code]); - return 1; + return true; } /* Get origin attribute of the update message. */ @@ -2382,8 +2382,7 @@ static int bgp_attr_encap(uint8_t type, struct peer *peer, /* IN */ * Returns 0 if there was an error that needs to be passed up the stack */ static bgp_attr_parse_ret_t bgp_attr_psid_sub(uint8_t type, uint16_t length, - struct bgp_attr_parser_args *args, - struct bgp_nlri *mp_update) + struct bgp_attr_parser_args *args) { struct peer *const peer = args->peer; struct attr *const attr = args->attr; @@ -2421,15 +2420,6 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(uint8_t type, uint16_t length, /* Store label index; subsequently, we'll check on * address-family */ attr->label_index = label_index; - - /* - * Ignore the Label index attribute unless received for - * labeled-unicast - * SAFI. - */ - if (!mp_update->length - || mp_update->safi != SAFI_LABELED_UNICAST) - attr->label_index = BGP_INVALID_LABEL_INDEX; } /* Placeholder code for the IPv6 SID type */ @@ -2628,8 +2618,7 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(uint8_t type, uint16_t length, /* Prefix SID attribute * draft-ietf-idr-bgp-prefix-sid-05 */ -bgp_attr_parse_ret_t bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, - struct bgp_nlri *mp_update) +bgp_attr_parse_ret_t bgp_attr_prefix_sid(struct bgp_attr_parser_args *args) { struct peer *const peer = args->peer; struct attr *const attr = args->attr; @@ -2640,8 +2629,10 @@ bgp_attr_parse_ret_t bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, uint8_t type; uint16_t length; size_t headersz = sizeof(type) + sizeof(length); + size_t psid_parsed_length = 0; - while (STREAM_READABLE(peer->curr) > 0) { + while (STREAM_READABLE(peer->curr) > 0 + && psid_parsed_length < args->length) { if (STREAM_READABLE(peer->curr) < headersz) { flog_err( @@ -2659,7 +2650,7 @@ bgp_attr_parse_ret_t bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, if (STREAM_READABLE(peer->curr) < length) { flog_err( EC_BGP_ATTR_LEN, - "Malformed Prefix SID attribute - insufficient data (need %" PRIu8 + "Malformed Prefix SID attribute - insufficient data (need %" PRIu16 " for attribute body, have %zu remaining in UPDATE)", length, STREAM_READABLE(peer->curr)); return bgp_attr_malformed(args, @@ -2667,10 +2658,23 @@ bgp_attr_parse_ret_t bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, args->total); } - ret = bgp_attr_psid_sub(type, length, args, mp_update); + ret = bgp_attr_psid_sub(type, length, args); if (ret != BGP_ATTR_PARSE_PROCEED) return ret; + + psid_parsed_length += length + headersz; + + if (psid_parsed_length > args->length) { + flog_err( + EC_BGP_ATTR_LEN, + "Malformed Prefix SID attribute - TLV overflow by attribute (need %zu" + " for TLV length, have %zu overflowed in UPDATE)", + length + headersz, psid_parsed_length - (length + headersz)); + return bgp_attr_malformed( + args, BGP_NOTIFY_UPDATE_ATTR_LENG_ERR, + args->total); + } } return BGP_ATTR_PARSE_PROCEED; @@ -3066,7 +3070,7 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, startp); break; case BGP_ATTR_PREFIX_SID: - ret = bgp_attr_prefix_sid(&attr_args, mp_update); + ret = bgp_attr_prefix_sid(&attr_args); break; case BGP_ATTR_PMSI_TUNNEL: ret = bgp_attr_pmsi_tunnel(&attr_args); @@ -3113,6 +3117,17 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, } } + /* + * draft-ietf-idr-bgp-prefix-sid-27#section-3: + * About Prefix-SID path attribute, + * Label-Index TLV(type1) and The Originator SRGB TLV(type-3) + * may only appear in a BGP Prefix-SID attribute attached to + * IPv4/IPv6 Labeled Unicast prefixes ([RFC8277]). + * It MUST be ignored when received for other BGP AFI/SAFI combinations. + */ + if (!attr->mp_nexthop_len || mp_update->safi != SAFI_LABELED_UNICAST) + attr->label_index = BGP_INVALID_LABEL_INDEX; + /* Check final read pointer is same as end pointer. */ if (BGP_INPUT_PNT(peer) != endp) { flog_warn(EC_BGP_ATTRIBUTES_MISMATCH, @@ -3547,7 +3562,7 @@ void bgp_packet_mpattr_end(struct stream *s, size_t sizep) stream_putw_at(s, sizep, (stream_get_endp(s) - sizep) - 2); } -static int bgp_append_local_as(struct peer *peer, afi_t afi, safi_t safi) +static bool bgp_append_local_as(struct peer *peer, afi_t afi, safi_t safi) { if (!BGP_AS_IS_PRIVATE(peer->local_as) || (BGP_AS_IS_PRIVATE(peer->local_as) @@ -3559,8 +3574,8 @@ static int bgp_append_local_as(struct peer *peer, afi_t afi, safi_t safi) PEER_FLAG_REMOVE_PRIVATE_AS_REPLACE) && !CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REMOVE_PRIVATE_AS_ALL_REPLACE))) - return 1; - return 0; + return true; + return false; } /* Make attribute packet. */ @@ -4115,7 +4130,7 @@ void bgp_attr_finish(void) /* Make attribute packet. */ void bgp_dump_routes_attr(struct stream *s, struct attr *attr, - struct prefix *prefix) + const struct prefix *prefix) { unsigned long cp; unsigned long len; diff --git a/bgpd/bgp_attr.h b/bgpd/bgp_attr.h index 2e91f56df..04b3a20d6 100644 --- a/bgpd/bgp_attr.h +++ b/bgpd/bgp_attr.h @@ -324,8 +324,8 @@ extern bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *, struct prefix *, afi_t, safi_t, struct peer *, struct prefix_rd *, mpls_label_t *, uint32_t, int, uint32_t); -extern void bgp_dump_routes_attr(struct stream *, struct attr *, - struct prefix *); +extern void bgp_dump_routes_attr(struct stream *s, struct attr *attr, + const struct prefix *p); extern bool attrhash_cmp(const void *arg1, const void *arg2); extern unsigned int attrhash_key_make(const void *); extern void attr_show_all(struct vty *); @@ -333,7 +333,7 @@ extern unsigned long int attr_count(void); extern unsigned long int attr_unknown_count(void); /* Cluster list prototypes. */ -extern int cluster_loop_check(struct cluster_list *, struct in_addr); +extern bool cluster_loop_check(struct cluster_list *, struct in_addr); extern void cluster_unintern(struct cluster_list *); /* Below exported for unit-test purposes only */ @@ -351,8 +351,7 @@ extern int bgp_mp_reach_parse(struct bgp_attr_parser_args *args, extern int bgp_mp_unreach_parse(struct bgp_attr_parser_args *args, struct bgp_nlri *); extern bgp_attr_parse_ret_t -bgp_attr_prefix_sid(struct bgp_attr_parser_args *args, - struct bgp_nlri *mp_update); +bgp_attr_prefix_sid(struct bgp_attr_parser_args *args); extern struct bgp_attr_encap_subtlv * encap_tlv_dup(struct bgp_attr_encap_subtlv *orig); diff --git a/bgpd/bgp_attr_evpn.c b/bgpd/bgp_attr_evpn.c index ec9656a98..7239ddef9 100644 --- a/bgpd/bgp_attr_evpn.c +++ b/bgpd/bgp_attr_evpn.c @@ -54,25 +54,25 @@ void bgp_add_routermac_ecom(struct attr *attr, struct ethaddr *routermac) * format accepted: AA:BB:CC:DD:EE:FF:GG:HH:II:JJ * if id is null, check only is done */ -int str2esi(const char *str, struct eth_segment_id *id) +bool str2esi(const char *str, struct eth_segment_id *id) { unsigned int a[ESI_LEN]; int i; if (!str) - return 0; + return false; if (sscanf(str, "%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x:%2x", a + 0, a + 1, a + 2, a + 3, a + 4, a + 5, a + 6, a + 7, a + 8, a + 9) != ESI_LEN) { /* error in incoming str length */ - return 0; + return false; } /* valid mac address */ if (!id) - return 1; + return true; for (i = 0; i < ESI_LEN; ++i) id->val[i] = a[i] & 0xff; - return 1; + return true; } char *esi2str(struct eth_segment_id *id) @@ -186,7 +186,7 @@ uint32_t bgp_attr_mac_mobility_seqnum(struct attr *attr, uint8_t *sticky) * one. */ for (i = 0; i < ecom->size; i++) { - uint8_t *pnt; + const uint8_t *pnt; uint8_t type, sub_type; uint32_t seq_num; diff --git a/bgpd/bgp_attr_evpn.h b/bgpd/bgp_attr_evpn.h index 25654ba70..c1bfd8376 100644 --- a/bgpd/bgp_attr_evpn.h +++ b/bgpd/bgp_attr_evpn.h @@ -51,7 +51,7 @@ struct bgp_route_evpn { union gw_addr gw_ip; }; -extern int str2esi(const char *str, struct eth_segment_id *id); +extern bool str2esi(const char *str, struct eth_segment_id *id); extern char *esi2str(struct eth_segment_id *id); extern char *ecom_mac2str(char *ecom_mac); diff --git a/bgpd/bgp_bfd.c b/bgpd/bgp_bfd.c index 5f4db3dfa..a200589bd 100644 --- a/bgpd/bgp_bfd.c +++ b/bgpd/bgp_bfd.c @@ -72,21 +72,21 @@ void bgp_bfd_peer_group2peer_copy(struct peer *conf, struct peer *peer) * bgp_bfd_is_peer_multihop - returns whether BFD peer is multi-hop or single * hop. */ -int bgp_bfd_is_peer_multihop(struct peer *peer) +bool bgp_bfd_is_peer_multihop(struct peer *peer) { struct bfd_info *bfd_info; bfd_info = (struct bfd_info *)peer->bfd_info; if (!bfd_info) - return 0; + return false; if ((bfd_info->type == BFD_TYPE_MULTIHOP) || ((peer->sort == BGP_PEER_IBGP) && !peer->shared_network) || is_ebgp_multihop_configured(peer)) - return 1; + return true; else - return 0; + return false; } /* diff --git a/bgpd/bgp_bfd.h b/bgpd/bgp_bfd.h index b96ebb6c9..f2fa959b4 100644 --- a/bgpd/bgp_bfd.h +++ b/bgpd/bgp_bfd.h @@ -39,6 +39,6 @@ extern void bgp_bfd_peer_config_write(struct vty *vty, struct peer *peer, extern void bgp_bfd_show_info(struct vty *vty, struct peer *peer, bool use_json, json_object *json_neigh); -extern int bgp_bfd_is_peer_multihop(struct peer *peer); +extern bool bgp_bfd_is_peer_multihop(struct peer *peer); #endif /* _QUAGGA_BGP_BFD_H */ diff --git a/bgpd/bgp_bmp.c b/bgpd/bgp_bmp.c index 24a9cab5d..32865da37 100644 --- a/bgpd/bgp_bmp.c +++ b/bgpd/bgp_bmp.c @@ -664,8 +664,7 @@ static int bmp_peer_established(struct peer *peer) return 0; /* Check if this peer just went to Established */ - if ((peer->last_major_event != OpenConfirm) || - !(peer_established(peer))) + if ((peer->ostatus != OpenConfirm) || !(peer_established(peer))) return 0; if (peer->doppelganger && (peer->doppelganger->status != Deleted)) { diff --git a/bgpd/bgp_btoa.c b/bgpd/bgp_btoa.c index cc37e352e..cbe18e23c 100644 --- a/bgpd/bgp_btoa.c +++ b/bgpd/bgp_btoa.c @@ -68,7 +68,7 @@ enum MRT_MSG_TYPES { MSG_TABLE_DUMP /* routing table dump */ }; -static int attr_parse(struct stream *s, uint16_t len) +static void attr_parse(struct stream *s, uint16_t len) { unsigned int flag; unsigned int type; @@ -115,8 +115,6 @@ static int attr_parse(struct stream *s, uint16_t len) break; } } - - return 0; } int main(int argc, char **argv) diff --git a/bgpd/bgp_clist.c b/bgpd/bgp_clist.c index 5c461dbe7..cf4d44ea2 100644 --- a/bgpd/bgp_clist.c +++ b/bgpd/bgp_clist.c @@ -311,9 +311,9 @@ static void community_list_delete(struct community_list_master *cm, community_list_free(list); } -static int community_list_empty_p(struct community_list *list) +static bool community_list_empty_p(struct community_list *list) { - return (list->head == NULL && list->tail == NULL) ? 1 : 0; + return list->head == NULL && list->tail == NULL; } /* Delete community-list entry from the list. */ @@ -497,7 +497,7 @@ static char *community_str_get(struct community *com, int i) /* Internal function to perform regular expression match for * a single community. */ -static int community_regexp_include(regex_t *reg, struct community *com, int i) +static bool community_regexp_include(regex_t *reg, struct community *com, int i) { char *str; int rv; @@ -514,16 +514,12 @@ static int community_regexp_include(regex_t *reg, struct community *com, int i) XFREE(MTYPE_COMMUNITY_STR, str); - if (rv == 0) - return 1; - - /* No match. */ - return 0; + return rv == 0; } /* Internal function to perform regular expression match for community attribute. */ -static int community_regexp_match(struct community *com, regex_t *reg) +static bool community_regexp_match(struct community *com, regex_t *reg) { const char *str; @@ -536,10 +532,10 @@ static int community_regexp_match(struct community *com, regex_t *reg) /* Regular expression match. */ if (regexec(reg, str, 0, NULL, 0) == 0) - return 1; + return true; /* No match. */ - return 0; + return false; } static char *lcommunity_str_get(struct lcommunity *lcom, int i) @@ -549,7 +545,7 @@ static char *lcommunity_str_get(struct lcommunity *lcom, int i) uint32_t localdata1; uint32_t localdata2; char *str; - uint8_t *ptr; + const uint8_t *ptr; char *pnt; ptr = lcom->val + (i * LCOMMUNITY_SIZE); @@ -574,8 +570,8 @@ static char *lcommunity_str_get(struct lcommunity *lcom, int i) /* Internal function to perform regular expression match for * a single community. */ -static int lcommunity_regexp_include(regex_t *reg, struct lcommunity *lcom, - int i) +static bool lcommunity_regexp_include(regex_t *reg, struct lcommunity *lcom, + int i) { char *str; @@ -589,15 +585,15 @@ static int lcommunity_regexp_include(regex_t *reg, struct lcommunity *lcom, /* Regular expression match. */ if (regexec(reg, str, 0, NULL, 0) == 0) { XFREE(MTYPE_LCOMMUNITY_STR, str); - return 1; + return true; } XFREE(MTYPE_LCOMMUNITY_STR, str); /* No match. */ - return 0; + return false; } -static int lcommunity_regexp_match(struct lcommunity *com, regex_t *reg) +static bool lcommunity_regexp_match(struct lcommunity *com, regex_t *reg) { const char *str; @@ -610,14 +606,14 @@ static int lcommunity_regexp_match(struct lcommunity *com, regex_t *reg) /* Regular expression match. */ if (regexec(reg, str, 0, NULL, 0) == 0) - return 1; + return true; /* No match. */ - return 0; + return false; } -static int ecommunity_regexp_match(struct ecommunity *ecom, regex_t *reg) +static bool ecommunity_regexp_match(struct ecommunity *ecom, regex_t *reg) { const char *str; @@ -630,10 +626,10 @@ static int ecommunity_regexp_match(struct ecommunity *ecom, regex_t *reg) /* Regular expression match. */ if (regexec(reg, str, 0, NULL, 0) == 0) - return 1; + return true; /* No match. */ - return 0; + return false; } #if 0 @@ -718,125 +714,113 @@ community_regexp_delete (struct community *com, regex_t * reg) /* When given community attribute matches to the community-list return 1 else return 0. */ -int community_list_match(struct community *com, struct community_list *list) +bool community_list_match(struct community *com, struct community_list *list) { struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { if (entry->any) - return entry->direct == COMMUNITY_PERMIT ? 1 : 0; + return entry->direct == COMMUNITY_PERMIT; if (entry->style == COMMUNITY_LIST_STANDARD) { if (community_include(entry->u.com, COMMUNITY_INTERNET)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; if (community_match(com, entry->u.com)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == COMMUNITY_LIST_EXPANDED) { if (community_regexp_match(com, entry->reg)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } } - return 0; + return false; } -int lcommunity_list_match(struct lcommunity *lcom, struct community_list *list) +bool lcommunity_list_match(struct lcommunity *lcom, struct community_list *list) { struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { if (entry->any) - return entry->direct == COMMUNITY_PERMIT ? 1 : 0; + return entry->direct == COMMUNITY_PERMIT; if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) { if (lcommunity_match(lcom, entry->u.lcom)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == LARGE_COMMUNITY_LIST_EXPANDED) { if (lcommunity_regexp_match(lcom, entry->reg)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } } - return 0; + return false; } /* Perform exact matching. In case of expanded large-community-list, do * same thing as lcommunity_list_match(). */ -int lcommunity_list_exact_match(struct lcommunity *lcom, - struct community_list *list) +bool lcommunity_list_exact_match(struct lcommunity *lcom, + struct community_list *list) { struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { if (entry->any) - return entry->direct == COMMUNITY_PERMIT ? 1 : 0; + return entry->direct == COMMUNITY_PERMIT; if (entry->style == LARGE_COMMUNITY_LIST_STANDARD) { if (lcommunity_cmp(lcom, entry->u.com)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == LARGE_COMMUNITY_LIST_EXPANDED) { if (lcommunity_regexp_match(lcom, entry->reg)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } } - return 0; + return false; } -int ecommunity_list_match(struct ecommunity *ecom, struct community_list *list) +bool ecommunity_list_match(struct ecommunity *ecom, struct community_list *list) { struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { if (entry->any) - return entry->direct == COMMUNITY_PERMIT ? 1 : 0; + return entry->direct == COMMUNITY_PERMIT; if (entry->style == EXTCOMMUNITY_LIST_STANDARD) { if (ecommunity_match(ecom, entry->u.ecom)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == EXTCOMMUNITY_LIST_EXPANDED) { if (ecommunity_regexp_match(ecom, entry->reg)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } } - return 0; + return false; } /* Perform exact matching. In case of expanded community-list, do same thing as community_list_match(). */ -int community_list_exact_match(struct community *com, - struct community_list *list) +bool community_list_exact_match(struct community *com, + struct community_list *list) { struct community_entry *entry; for (entry = list->head; entry; entry = entry->next) { if (entry->any) - return entry->direct == COMMUNITY_PERMIT ? 1 : 0; + return entry->direct == COMMUNITY_PERMIT; if (entry->style == COMMUNITY_LIST_STANDARD) { if (community_include(entry->u.com, COMMUNITY_INTERNET)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; if (community_cmp(com, entry->u.com)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } else if (entry->style == COMMUNITY_LIST_EXPANDED) { if (community_regexp_match(com, entry->reg)) - return entry->direct == COMMUNITY_PERMIT ? 1 - : 0; + return entry->direct == COMMUNITY_PERMIT; } } - return 0; + return false; } /* Delete all permitted communities in the list from com. */ @@ -900,8 +884,8 @@ struct community *community_list_match_delete(struct community *com, /* To avoid duplicated entry in the community-list, this function compares specified entry to existing entry. */ -static int community_list_dup_check(struct community_list *list, - struct community_entry *new) +static bool community_list_dup_check(struct community_list *list, + struct community_entry *new) { struct community_entry *entry; @@ -916,32 +900,32 @@ static int community_list_dup_check(struct community_list *list, continue; if (entry->any) - return 1; + return true; switch (entry->style) { case COMMUNITY_LIST_STANDARD: if (community_cmp(entry->u.com, new->u.com)) - return 1; + return true; break; case LARGE_COMMUNITY_LIST_STANDARD: if (lcommunity_cmp(entry->u.lcom, new->u.lcom)) - return 1; + return true; break; case EXTCOMMUNITY_LIST_STANDARD: if (ecommunity_cmp(entry->u.ecom, new->u.ecom)) - return 1; + return true; break; case COMMUNITY_LIST_EXPANDED: case EXTCOMMUNITY_LIST_EXPANDED: case LARGE_COMMUNITY_LIST_EXPANDED: if (strcmp(entry->config, new->config) == 0) - return 1; + return true; break; default: break; } } - return 0; + return false; } /* Set community-list. */ @@ -1104,7 +1088,7 @@ struct lcommunity *lcommunity_list_match_delete(struct lcommunity *lcom, } /* Helper to check if every octet do not exceed UINT_MAX */ -static int lcommunity_list_valid(const char *community) +static bool lcommunity_list_valid(const char *community) { int octets = 0; char **splits; @@ -1114,10 +1098,10 @@ static int lcommunity_list_valid(const char *community) for (int i = 0; i < num; i++) { if (strtoul(splits[i], NULL, 10) > UINT_MAX) - return 0; + return false; if (strlen(splits[i]) == 0) - return 0; + return false; octets++; XFREE(MTYPE_TMP, splits[i]); @@ -1125,9 +1109,9 @@ static int lcommunity_list_valid(const char *community) XFREE(MTYPE_TMP, splits); if (octets < 3) - return 0; + return false; - return 1; + return true; } /* Set lcommunity-list. */ diff --git a/bgpd/bgp_clist.h b/bgpd/bgp_clist.h index c5718aeca..4cb5d7c59 100644 --- a/bgpd/bgp_clist.h +++ b/bgpd/bgp_clist.h @@ -165,13 +165,13 @@ extern struct community_list * community_list_lookup(struct community_list_handler *c, const char *name, uint32_t name_hash, int master); -extern int community_list_match(struct community *, struct community_list *); -extern int ecommunity_list_match(struct ecommunity *, struct community_list *); -extern int lcommunity_list_match(struct lcommunity *, struct community_list *); -extern int community_list_exact_match(struct community *, - struct community_list *); -extern int lcommunity_list_exact_match(struct lcommunity *lcom, - struct community_list *list); +extern bool community_list_match(struct community *, struct community_list *); +extern bool ecommunity_list_match(struct ecommunity *, struct community_list *); +extern bool lcommunity_list_match(struct lcommunity *, struct community_list *); +extern bool community_list_exact_match(struct community *, + struct community_list *); +extern bool lcommunity_list_exact_match(struct lcommunity *lcom, + struct community_list *list); extern struct community *community_list_match_delete(struct community *, struct community_list *); extern struct lcommunity * diff --git a/bgpd/bgp_community.c b/bgpd/bgp_community.c index c145c47d0..195c0f394 100644 --- a/bgpd/bgp_community.c +++ b/bgpd/bgp_community.c @@ -128,7 +128,7 @@ static int community_compare(const void *a1, const void *a2) return 0; } -int community_include(struct community *com, uint32_t val) +bool community_include(struct community *com, uint32_t val) { int i; @@ -136,9 +136,8 @@ int community_include(struct community *com, uint32_t val) for (i = 0; i < com->size; i++) if (memcmp(&val, com_nthval(com, i), sizeof(uint32_t)) == 0) - return 1; - - return 0; + return true; + return false; } uint32_t community_val_get(struct community *com, int i) @@ -564,19 +563,19 @@ unsigned int community_hash_make(const struct community *com) return jhash2(pnt, com->size, 0x43ea96c1); } -int community_match(const struct community *com1, const struct community *com2) +bool community_match(const struct community *com1, const struct community *com2) { int i = 0; int j = 0; if (com1 == NULL && com2 == NULL) - return 1; + return true; if (com1 == NULL || com2 == NULL) - return 0; + return false; if (com1->size < com2->size) - return 0; + return false; /* Every community on com2 needs to be on com1 for this to match */ while (i < com1->size && j < com2->size) { @@ -586,9 +585,9 @@ int community_match(const struct community *com1, const struct community *com2) } if (j == com2->size) - return 1; + return true; else - return 0; + return false; } /* If two aspath have same value then return 1 else return 0. This diff --git a/bgpd/bgp_community.h b/bgpd/bgp_community.h index 74a3a6b50..31a061370 100644 --- a/bgpd/bgp_community.h +++ b/bgpd/bgp_community.h @@ -77,7 +77,7 @@ extern void community_unintern(struct community **); extern char *community_str(struct community *, bool make_json); extern unsigned int community_hash_make(const struct community *); extern struct community *community_str2com(const char *); -extern int community_match(const struct community *, const struct community *); +extern bool community_match(const struct community *, const struct community *); extern bool community_cmp(const struct community *c1, const struct community *c2); extern struct community *community_merge(struct community *, @@ -85,7 +85,7 @@ extern struct community *community_merge(struct community *, extern struct community *community_delete(struct community *, struct community *); extern struct community *community_dup(struct community *); -extern int community_include(struct community *, uint32_t); +extern bool community_include(struct community *, uint32_t); extern void community_del_val(struct community *, uint32_t *); extern unsigned long community_count(void); extern struct hash *community_hash(void); diff --git a/bgpd/bgp_debug.c b/bgpd/bgp_debug.c index 2e21c7222..ee5f75a07 100644 --- a/bgpd/bgp_debug.c +++ b/bgpd/bgp_debug.c @@ -184,8 +184,8 @@ static const struct message bgp_notify_fsm_msg[] = { const char *const bgp_origin_str[] = {"i", "e", "?"}; const char *const bgp_origin_long_str[] = {"IGP", "EGP", "incomplete"}; -static int bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, - struct prefix *p); +static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, + struct prefix *p); /* Given a string return a pointer the corresponding peer structure */ static struct peer *bgp_find_peer(struct vty *vty, const char *peer_str) { @@ -315,8 +315,8 @@ static void bgp_debug_list_add_entry(struct list *list, const char *host, listnode_add(list, filter); } -static int bgp_debug_list_remove_entry(struct list *list, const char *host, - struct prefix *p) +static bool bgp_debug_list_remove_entry(struct list *list, const char *host, + struct prefix *p) { struct bgp_debug_filter *filter; struct listnode *node, *nnode; @@ -326,21 +326,21 @@ static int bgp_debug_list_remove_entry(struct list *list, const char *host, listnode_delete(list, filter); XFREE(MTYPE_BGP_DEBUG_STR, filter->host); XFREE(MTYPE_BGP_DEBUG_FILTER, filter); - return 1; + return true; } else if (p && filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p)) { listnode_delete(list, filter); prefix_free(&filter->p); XFREE(MTYPE_BGP_DEBUG_FILTER, filter); - return 1; + return true; } } - return 0; + return false; } -static int bgp_debug_list_has_entry(struct list *list, const char *host, - const struct prefix *p) +static bool bgp_debug_list_has_entry(struct list *list, const char *host, + const struct prefix *p) { struct bgp_debug_filter *filter; struct listnode *node, *nnode; @@ -348,32 +348,32 @@ static int bgp_debug_list_has_entry(struct list *list, const char *host, for (ALL_LIST_ELEMENTS(list, node, nnode, filter)) { if (host) { if (strcmp(filter->host, host) == 0) { - return 1; + return true; } } else if (p) { if (filter->p->prefixlen == p->prefixlen && prefix_match(filter->p, p)) { - return 1; + return true; } } } - return 0; + return false; } -int bgp_debug_peer_updout_enabled(char *host) +bool bgp_debug_peer_updout_enabled(char *host) { return (bgp_debug_list_has_entry(bgp_debug_update_out_peers, host, NULL)); } /* Dump attribute. */ -int bgp_dump_attr(struct attr *attr, char *buf, size_t size) +bool bgp_dump_attr(struct attr *attr, char *buf, size_t size) { char addrbuf[BUFSIZ]; if (!attr) - return 0; + return false; buf[0] = '\0'; @@ -455,9 +455,9 @@ int bgp_dump_attr(struct attr *attr, char *buf, size_t size) } if (strlen(buf) > 1) - return 1; + return true; else - return 0; + return false; } const char *bgp_notify_code_str(char code) @@ -561,8 +561,8 @@ static void bgp_debug_clear_updgrp_update_dbg(struct bgp *bgp) update_group_walk(bgp, update_group_clear_update_dbg, NULL); } -static int bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, - struct prefix *p) +static void bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, + struct prefix *p) { char evpn_desc[PREFIX2STR_BUFFER + INET_ADDRSTRLEN]; char buf[PREFIX2STR_BUFFER]; @@ -601,8 +601,6 @@ static int bgp_debug_print_evpn_prefix(struct vty *vty, const char *desc, } vty_out(vty, "%s %s\n", desc, evpn_desc); - - return 0; } static int bgp_debug_parse_evpn_prefix(struct vty *vty, struct cmd_token **argv, @@ -2406,7 +2404,7 @@ void bgp_debug_init(void) /* Return true if this prefix is on the per_prefix_list of prefixes to debug * for BGP_DEBUG_TYPE */ -static int bgp_debug_per_prefix(struct prefix *p, +static int bgp_debug_per_prefix(const struct prefix *p, unsigned long term_bgp_debug_type, unsigned int BGP_DEBUG_TYPE, struct list *per_prefix_list) @@ -2491,8 +2489,8 @@ int bgp_debug_keepalive(struct peer *peer) bgp_debug_keepalive_peers); } -int bgp_debug_update(struct peer *peer, struct prefix *p, - struct update_group *updgrp, unsigned int inbound) +bool bgp_debug_update(struct peer *peer, const struct prefix *p, + struct update_group *updgrp, unsigned int inbound) { char *host = NULL; @@ -2503,7 +2501,7 @@ int bgp_debug_update(struct peer *peer, struct prefix *p, if (bgp_debug_per_peer(host, term_bgp_debug_update, BGP_DEBUG_UPDATE_IN, bgp_debug_update_in_peers)) - return 1; + return true; } /* outbound */ @@ -2511,12 +2509,12 @@ int bgp_debug_update(struct peer *peer, struct prefix *p, if (bgp_debug_per_peer(host, term_bgp_debug_update, BGP_DEBUG_UPDATE_OUT, bgp_debug_update_out_peers)) - return 1; + return true; /* Check if update debugging implicitly enabled for the group. */ if (updgrp && UPDGRP_DBG_ON(updgrp)) - return 1; + return true; } @@ -2524,34 +2522,34 @@ int bgp_debug_update(struct peer *peer, struct prefix *p, if (bgp_debug_per_prefix(p, term_bgp_debug_update, BGP_DEBUG_UPDATE_PREFIX, bgp_debug_update_prefixes)) - return 1; + return true; } - return 0; + return false; } -int bgp_debug_bestpath(struct prefix *p) +bool bgp_debug_bestpath(struct bgp_node *rn) { if (BGP_DEBUG(bestpath, BESTPATH)) { - if (bgp_debug_per_prefix(p, term_bgp_debug_bestpath, - BGP_DEBUG_BESTPATH, - bgp_debug_bestpath_prefixes)) - return 1; + if (bgp_debug_per_prefix( + &rn->p, term_bgp_debug_bestpath, + BGP_DEBUG_BESTPATH, bgp_debug_bestpath_prefixes)) + return true; } - return 0; + return false; } -int bgp_debug_zebra(struct prefix *p) +bool bgp_debug_zebra(const struct prefix *p) { if (BGP_DEBUG(zebra, ZEBRA)) { if (bgp_debug_per_prefix(p, term_bgp_debug_zebra, BGP_DEBUG_ZEBRA, bgp_debug_zebra_prefixes)) - return 1; + return true; } - return 0; + return false; } const char *bgp_debug_rdpfxpath2str(afi_t afi, safi_t safi, diff --git a/bgpd/bgp_debug.h b/bgpd/bgp_debug.h index 1e6482e96..4ce1e1dce 100644 --- a/bgpd/bgp_debug.h +++ b/bgpd/bgp_debug.h @@ -157,8 +157,8 @@ struct bgp_debug_filter { extern const char *const bgp_type_str[]; -extern int bgp_dump_attr(struct attr *, char *, size_t); -extern int bgp_debug_peer_updout_enabled(char *host); +extern bool bgp_dump_attr(struct attr *, char *, size_t); +extern bool bgp_debug_peer_updout_enabled(char *host); extern const char *bgp_notify_code_str(char); extern const char *bgp_notify_subcode_str(char, char); extern void bgp_notify_print(struct peer *, struct bgp_notify *, const char *); @@ -166,10 +166,10 @@ extern void bgp_notify_print(struct peer *, struct bgp_notify *, const char *); extern const struct message bgp_status_msg[]; extern int bgp_debug_neighbor_events(struct peer *peer); extern int bgp_debug_keepalive(struct peer *peer); -extern int bgp_debug_update(struct peer *peer, struct prefix *p, - struct update_group *updgrp, unsigned int inbound); -extern int bgp_debug_bestpath(struct prefix *p); -extern int bgp_debug_zebra(struct prefix *p); +extern bool bgp_debug_update(struct peer *peer, const struct prefix *p, + struct update_group *updgrp, unsigned int inbound); +extern bool bgp_debug_bestpath(struct bgp_node *rn); +extern bool bgp_debug_zebra(const struct prefix *p); extern const char *bgp_debug_rdpfxpath2str(afi_t, safi_t, struct prefix_rd *, union prefixconstptr, mpls_label_t *, diff --git a/bgpd/bgp_ecommunity.c b/bgpd/bgp_ecommunity.c index 2711cf7a6..fc6649474 100644 --- a/bgpd/bgp_ecommunity.c +++ b/bgpd/bgp_ecommunity.c @@ -75,7 +75,7 @@ static void ecommunity_hash_free(struct ecommunity *ecom) structure, we don't add the value. Newly added value is sorted by numerical order. When the value is added to the structure return 1 else return 0. */ -int ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval) +bool ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval) { int c; @@ -84,7 +84,7 @@ int ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval) ecom->size = 1; ecom->val = XCALLOC(MTYPE_ECOMMUNITY_VAL, ECOMMUNITY_SIZE); memcpy(ecom->val, eval->val, ECOMMUNITY_SIZE); - return 1; + return true; } /* If the value already exists in the structure return 0. */ @@ -93,7 +93,7 @@ int ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval) p += ECOMMUNITY_SIZE, c++) { int ret = memcmp(p, eval->val, ECOMMUNITY_SIZE); if (ret == 0) - return 0; + return false; else if (ret > 0) break; } @@ -108,7 +108,7 @@ int ecommunity_add_val(struct ecommunity *ecom, struct ecommunity_val *eval) (ecom->size - 1 - c) * ECOMMUNITY_SIZE); memcpy(ecom->val + (c * ECOMMUNITY_SIZE), eval->val, ECOMMUNITY_SIZE); - return 1; + return true; } /* This function takes pointer to Extended Communites strucutre then @@ -555,7 +555,7 @@ struct ecommunity *ecommunity_str2com(const char *str, int type, return ecom; } -static int ecommunity_rt_soo_str(char *buf, size_t bufsz, uint8_t *pnt, +static int ecommunity_rt_soo_str(char *buf, size_t bufsz, const uint8_t *pnt, int type, int sub_type, int format) { int len = 0; @@ -837,20 +837,20 @@ char *ecommunity_ecom2str(struct ecommunity *ecom, int format, int filter) return str_buf; } -int ecommunity_match(const struct ecommunity *ecom1, - const struct ecommunity *ecom2) +bool ecommunity_match(const struct ecommunity *ecom1, + const struct ecommunity *ecom2) { int i = 0; int j = 0; if (ecom1 == NULL && ecom2 == NULL) - return 1; + return true; if (ecom1 == NULL || ecom2 == NULL) - return 0; + return false; if (ecom1->size < ecom2->size) - return 0; + return false; /* Every community on com2 needs to be on com1 for this to match */ while (i < ecom1->size && j < ecom2->size) { @@ -862,9 +862,9 @@ int ecommunity_match(const struct ecommunity *ecom1, } if (j == ecom2->size) - return 1; + return true; else - return 0; + return false; } /* return first occurence of type */ @@ -889,54 +889,63 @@ extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *ecom, /* remove ext. community matching type and subtype * return 1 on success ( removed ), 0 otherwise (not present) */ -extern int ecommunity_strip(struct ecommunity *ecom, uint8_t type, - uint8_t subtype) +extern bool ecommunity_strip(struct ecommunity *ecom, uint8_t type, + uint8_t subtype) { - uint8_t *p; + uint8_t *p, *q, *new; int c, found = 0; /* When this is fist value, just add it. */ - if (ecom == NULL || ecom->val == NULL) { - return 0; - } + if (ecom == NULL || ecom->val == NULL) + return false; - /* If the value already exists in the structure return 0. */ + /* Check if any existing ext community matches. */ + /* Certain extended communities like the Route Target can be present + * multiple times, handle that. + */ c = 0; for (p = ecom->val; c < ecom->size; p += ECOMMUNITY_SIZE, c++) { - if (p[0] == type && p[1] == subtype) { - found = 1; - break; - } + if (p[0] == type && p[1] == subtype) + found++; } + /* If no matching ext community exists, return. */ if (found == 0) - return 0; - /* Strip The selected value */ - ecom->size--; - /* size is reduced. no memmove to do */ - p = XMALLOC(MTYPE_ECOMMUNITY_VAL, ecom->size * ECOMMUNITY_SIZE); - if (c != 0) - memcpy(p, ecom->val, c * ECOMMUNITY_SIZE); - if ((ecom->size - c) != 0) - memcpy(p + (c)*ECOMMUNITY_SIZE, - ecom->val + (c + 1) * ECOMMUNITY_SIZE, - (ecom->size - c) * ECOMMUNITY_SIZE); - /* shift last ecommunities */ - XFREE(MTYPE_ECOMMUNITY, ecom->val); - ecom->val = p; - return 1; + return false; + + /* Handle the case where everything needs to be stripped. */ + if (found == ecom->size) { + XFREE(MTYPE_ECOMMUNITY_VAL, ecom->val); + ecom->size = 0; + return true; + } + + /* Strip matching ext community(ies). */ + new = XMALLOC(MTYPE_ECOMMUNITY_VAL, + (ecom->size - found) * ECOMMUNITY_SIZE); + q = new; + for (c = 0, p = ecom->val; c < ecom->size; c++, p += ECOMMUNITY_SIZE) { + if (!(p[0] == type && p[1] == subtype)) { + memcpy(q, p, ECOMMUNITY_SIZE); + q += ECOMMUNITY_SIZE; + } + } + XFREE(MTYPE_ECOMMUNITY_VAL, ecom->val); + ecom->val = new; + ecom->size -= found; + return true; } /* * Remove specified extended community value from extended community. * Returns 1 if value was present (and hence, removed), 0 otherwise. */ -int ecommunity_del_val(struct ecommunity *ecom, struct ecommunity_val *eval) +bool ecommunity_del_val(struct ecommunity *ecom, struct ecommunity_val *eval) { uint8_t *p; int c, found = 0; /* Make sure specified value exists. */ if (ecom == NULL || ecom->val == NULL) - return 0; + return false; c = 0; for (p = ecom->val; c < ecom->size; p += ECOMMUNITY_SIZE, c++) { if (!memcmp(p, eval->val, ECOMMUNITY_SIZE)) { @@ -945,7 +954,7 @@ int ecommunity_del_val(struct ecommunity *ecom, struct ecommunity_val *eval) } } if (found == 0) - return 0; + return false; /* Delete the selected value */ ecom->size--; @@ -958,7 +967,7 @@ int ecommunity_del_val(struct ecommunity *ecom, struct ecommunity_val *eval) (ecom->size - c) * ECOMMUNITY_SIZE); XFREE(MTYPE_ECOMMUNITY_VAL, ecom->val); ecom->val = p; - return 1; + return true; } int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval, diff --git a/bgpd/bgp_ecommunity.h b/bgpd/bgp_ecommunity.h index ae64f41ca..df0da091d 100644 --- a/bgpd/bgp_ecommunity.h +++ b/bgpd/bgp_ecommunity.h @@ -165,22 +165,22 @@ extern unsigned int ecommunity_hash_make(const void *); extern struct ecommunity *ecommunity_str2com(const char *, int, int); extern char *ecommunity_ecom2str(struct ecommunity *, int, int); extern void ecommunity_strfree(char **s); -extern int ecommunity_match(const struct ecommunity *, - const struct ecommunity *); +extern bool ecommunity_match(const struct ecommunity *, + const struct ecommunity *); extern char *ecommunity_str(struct ecommunity *); extern struct ecommunity_val *ecommunity_lookup(const struct ecommunity *, uint8_t, uint8_t); -extern int ecommunity_add_val(struct ecommunity *ecom, - struct ecommunity_val *eval); +extern bool ecommunity_add_val(struct ecommunity *ecom, + struct ecommunity_val *eval); /* for vpn */ extern struct ecommunity *ecommunity_new(void); -extern int ecommunity_add_val(struct ecommunity *, struct ecommunity_val *); -extern int ecommunity_strip(struct ecommunity *ecom, uint8_t type, - uint8_t subtype); +extern bool ecommunity_add_val(struct ecommunity *, struct ecommunity_val *); +extern bool ecommunity_strip(struct ecommunity *ecom, uint8_t type, + uint8_t subtype); extern struct ecommunity *ecommunity_new(void); -extern int ecommunity_del_val(struct ecommunity *ecom, - struct ecommunity_val *eval); +extern bool ecommunity_del_val(struct ecommunity *ecom, + struct ecommunity_val *eval); struct bgp_pbr_entry_action; extern int ecommunity_fill_pbr_action(struct ecommunity_val *ecom_eval, struct bgp_pbr_entry_action *api); @@ -202,4 +202,13 @@ extern void bgp_remove_ecomm_from_aggregate_hash( struct ecommunity *ecommunity); extern void bgp_aggr_ecommunity_remove(void *arg); + +static inline void ecommunity_strip_rts(struct ecommunity *ecom) +{ + uint8_t subtype = ECOMMUNITY_ROUTE_TARGET; + + ecommunity_strip(ecom, ECOMMUNITY_ENCODE_AS, subtype); + ecommunity_strip(ecom, ECOMMUNITY_ENCODE_IP, subtype); + ecommunity_strip(ecom, ECOMMUNITY_ENCODE_AS4, subtype); +} #endif /* _QUAGGA_BGP_ECOMMUNITY_H */ diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 664d62fd1..5202f6801 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -496,7 +496,7 @@ static void unmap_vni_from_rt(struct bgp *bgp, struct bgpevpn *vpn, } static void bgp_evpn_get_rmac_nexthop(struct bgpevpn *vpn, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct attr *attr, uint8_t flags) { struct bgp *bgp_vrf = vpn->bgp_vrf; @@ -583,7 +583,7 @@ static void evpn_convert_nexthop_to_ipv6(struct attr *attr) * Add (update) or delete MACIP from zebra. */ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct in_addr remote_vtep_ip, int add, uint8_t flags, uint32_t seq) { @@ -651,8 +651,8 @@ static int bgp_zebra_send_remote_macip(struct bgp *bgp, struct bgpevpn *vpn, * Add (update) or delete remote VTEP from zebra. */ static int bgp_zebra_send_remote_vtep(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, - int flood_control, int add) + const struct prefix_evpn *p, + int flood_control, int add) { struct stream *s; @@ -930,7 +930,8 @@ static void add_mac_mobility_to_attr(uint32_t seq_num, struct attr *attr) /* Install EVPN route into zebra. */ static int evpn_zebra_install(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, struct bgp_path_info *pi) + const struct prefix_evpn *p, + struct bgp_path_info *pi) { int ret; uint8_t flags; @@ -970,7 +971,7 @@ static int evpn_zebra_install(struct bgp *bgp, struct bgpevpn *vpn, /* Uninstall EVPN route from zebra. */ static int evpn_zebra_uninstall(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct in_addr remote_vtep_ip) { int ret; @@ -1054,9 +1055,8 @@ static int is_vtep_present_in_list(struct list *list, * Best path for ES route was changed, * update the list of VTEPs for this ES */ -static int evpn_es_install_vtep(struct bgp *bgp, - struct evpnes *es, - struct prefix_evpn *p, +static int evpn_es_install_vtep(struct bgp *bgp, struct evpnes *es, + const struct prefix_evpn *p, struct in_addr rvtep) { struct in_addr *vtep_ip; @@ -1157,7 +1157,7 @@ static int evpn_es_route_select_install(struct bgp *bgp, if (new_select && new_select->type == ZEBRA_ROUTE_BGP && new_select->sub_type == BGP_ROUTE_IMPORTED) { ret = evpn_es_install_vtep(bgp, es, - (struct prefix_evpn *)&rn->p, + (const struct prefix_evpn *)&rn->p, new_select->attr->nexthop); } else { if (old_select && old_select->type == ZEBRA_ROUTE_BGP @@ -2555,7 +2555,7 @@ bgp_create_evpn_bgp_path_info(struct bgp_path_info *parent_pi, /* Install EVPN route entry in ES */ static int install_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct bgp_path_info *parent_pi) { int ret = 0; @@ -2619,7 +2619,7 @@ static int install_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es, * Install route entry into the VRF routing table and invoke route selection. */ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, - struct prefix_evpn *evp, + const struct prefix_evpn *evp, struct bgp_path_info *parent_pi) { struct bgp_node *rn; @@ -2726,7 +2726,7 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, * Install route entry into the VNI routing table and invoke route selection. */ static int install_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct bgp_path_info *parent_pi) { struct bgp_node *rn; @@ -2782,7 +2782,7 @@ static int install_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, /* Uninstall EVPN route entry from ES route table */ static int uninstall_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct bgp_path_info *parent_pi) { int ret; @@ -2825,7 +2825,7 @@ static int uninstall_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es, * to zebra, if appropriate. */ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, - struct prefix_evpn *evp, + const struct prefix_evpn *evp, struct bgp_path_info *parent_pi) { struct bgp_node *rn; @@ -2895,7 +2895,7 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, * to zebra, if appropriate. */ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, - struct prefix_evpn *p, + const struct prefix_evpn *p, struct bgp_path_info *parent_pi) { struct bgp_node *rn; @@ -2932,7 +2932,7 @@ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, /* * Given a prefix, see if it belongs to ES. */ -static int is_prefix_matching_for_es(struct prefix_evpn *p, +static int is_prefix_matching_for_es(const struct prefix_evpn *p, struct evpnes *es) { /* if not an ES route return false */ @@ -3153,7 +3153,7 @@ static int install_uninstall_routes_for_es(struct bgp *bgp, * route into bgp vrf table and remote rmac in bridge table. */ static int bgp_evpn_route_rmac_self_check(struct bgp *bgp_vrf, - struct prefix_evpn *evp, + const struct prefix_evpn *evp, struct bgp_path_info *pi) { /* evpn route could have learnt prior to L3vni has come up, @@ -3524,7 +3524,7 @@ static int install_uninstall_route_in_vnis(struct bgp *bgp, afi_t afi, * Install or uninstall route for appropriate VNIs/ESIs. */ static int install_uninstall_evpn_route(struct bgp *bgp, afi_t afi, safi_t safi, - struct prefix *p, + const struct prefix *p, struct bgp_path_info *pi, int import) { struct prefix_evpn *evp = (struct prefix_evpn *)p; @@ -4465,7 +4465,7 @@ static void update_autort_vni(struct hash_bucket *bucket, struct bgp *bgp) */ /* withdraw type-5 route corresponding to ip prefix */ -void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p, +void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, const struct prefix *p, afi_t afi, safi_t safi) { int ret = 0; @@ -4535,7 +4535,7 @@ void bgp_evpn_install_uninstall_default_route(struct bgp *bgp_vrf, afi_t afi, * path in the case of the attr. In the case of a local prefix (when we * are advertising local subnets), the src_attr will be NULL. */ -void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, struct prefix *p, +void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, const struct prefix *p, struct attr *src_attr, afi_t afi, safi_t safi) { @@ -4576,16 +4576,34 @@ void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi, /* apply the route-map */ if (bgp_vrf->adv_cmd_rmap[afi][safi].map) { route_map_result_t ret; + struct bgp_path_info tmp_pi; + struct bgp_path_info_extra tmp_pie; + struct attr tmp_attr; + + tmp_attr = *pi->attr; + + /* Fill temp path_info */ + prep_for_rmap_apply( + &tmp_pi, &tmp_pie, rn, pi, + pi->peer, &tmp_attr); + + RESET_FLAG(tmp_attr.rmap_change_flags); ret = route_map_apply( bgp_vrf->adv_cmd_rmap[afi][safi] .map, - &rn->p, RMAP_BGP, pi); - if (ret == RMAP_DENYMATCH) + &rn->p, RMAP_BGP, &tmp_pi); + if (ret == RMAP_DENYMATCH) { + bgp_attr_flush(&tmp_attr); continue; - } - bgp_evpn_advertise_type5_route( - bgp_vrf, &rn->p, pi->attr, afi, safi); + } + bgp_evpn_advertise_type5_route( + bgp_vrf, &rn->p, &tmp_attr, + afi, safi); + } else + bgp_evpn_advertise_type5_route( + bgp_vrf, &rn->p, pi->attr, + afi, safi); break; } } @@ -4882,7 +4900,7 @@ char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels, char *buf, * Function to convert evpn route to json format. * NOTE: We don't use prefix2str as the output here is a bit different. */ -void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json) +void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json) { char buf1[ETHER_ADDR_STRLEN]; char buf2[PREFIX2STR_BUFFER]; @@ -4947,7 +4965,7 @@ void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json) * Function to convert evpn route to string. * NOTE: We don't use prefix2str as the output here is a bit different. */ -char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len) +char *bgp_evpn_route2str(const struct prefix_evpn *p, char *buf, int len) { char buf1[ETHER_ADDR_STRLEN]; char buf2[PREFIX2STR_BUFFER]; @@ -5532,7 +5550,7 @@ void bgp_evpn_es_free(struct bgp *bgp, struct evpnes *es) * Import evpn route from global table to VNI/VRF/ESI. */ int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi, - struct prefix *p, struct bgp_path_info *pi) + const struct prefix *p, struct bgp_path_info *pi) { return install_uninstall_evpn_route(bgp, afi, safi, p, pi, 1); } @@ -5541,7 +5559,7 @@ int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi, * Unimport evpn route from VNI/VRF/ESI. */ int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi, - struct prefix *p, struct bgp_path_info *pi) + const struct prefix *p, struct bgp_path_info *pi) { return install_uninstall_evpn_route(bgp, afi, safi, p, pi, 0); } @@ -6262,7 +6280,7 @@ int bgp_evpn_get_type5_prefixlen(struct prefix *pfx) /* * Should we register nexthop for this EVPN prefix for nexthop tracking? */ -bool bgp_evpn_is_prefix_nht_supported(struct prefix *pfx) +bool bgp_evpn_is_prefix_nht_supported(const struct prefix *pfx) { struct prefix_evpn *evp = (struct prefix_evpn *)pfx; diff --git a/bgpd/bgp_evpn.h b/bgpd/bgp_evpn.h index b030f0a33..219321fc6 100644 --- a/bgpd/bgp_evpn.h +++ b/bgpd/bgp_evpn.h @@ -140,11 +140,12 @@ static inline bool is_route_injectable_into_evpn(struct bgp_path_info *pi) } extern void bgp_evpn_advertise_type5_route(struct bgp *bgp_vrf, - struct prefix *p, + const struct prefix *p, struct attr *src_attr, afi_t afi, safi_t safi); -extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, struct prefix *p, - afi_t afi, safi_t safi); +extern void bgp_evpn_withdraw_type5_route(struct bgp *bgp_vrf, + const struct prefix *p, afi_t afi, + safi_t safi); extern void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi, safi_t safi); extern void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi, @@ -153,8 +154,9 @@ extern void bgp_evpn_vrf_delete(struct bgp *bgp_vrf); extern void bgp_evpn_handle_router_id_update(struct bgp *bgp, int withdraw); extern char *bgp_evpn_label2str(mpls_label_t *label, uint32_t num_labels, char *buf, int len); -extern char *bgp_evpn_route2str(struct prefix_evpn *p, char *buf, int len); -extern void bgp_evpn_route2json(struct prefix_evpn *p, json_object *json); +extern char *bgp_evpn_route2str(const struct prefix_evpn *p, char *buf, + int len); +extern void bgp_evpn_route2json(const struct prefix_evpn *p, json_object *json); extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p, struct prefix_rd *prd, mpls_label_t *label, uint32_t num_labels, struct attr *attr, @@ -162,9 +164,11 @@ extern void bgp_evpn_encode_prefix(struct stream *s, struct prefix *p, extern int bgp_nlri_parse_evpn(struct peer *peer, struct attr *attr, struct bgp_nlri *packet, int withdraw); extern int bgp_evpn_import_route(struct bgp *bgp, afi_t afi, safi_t safi, - struct prefix *p, struct bgp_path_info *ri); + const struct prefix *p, + struct bgp_path_info *ri); extern int bgp_evpn_unimport_route(struct bgp *bgp, afi_t afi, safi_t safi, - struct prefix *p, struct bgp_path_info *ri); + const struct prefix *p, + struct bgp_path_info *ri); extern int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp); extern int bgp_evpn_local_macip_del(struct bgp *bgp, vni_t vni, struct ethaddr *mac, struct ipaddr *ip, @@ -192,7 +196,7 @@ extern void bgp_evpn_cleanup_on_disable(struct bgp *bgp); extern void bgp_evpn_cleanup(struct bgp *bgp); extern void bgp_evpn_init(struct bgp *bgp); extern int bgp_evpn_get_type5_prefixlen(struct prefix *pfx); -extern bool bgp_evpn_is_prefix_nht_supported(struct prefix *pfx); +extern bool bgp_evpn_is_prefix_nht_supported(const struct prefix *pfx); extern void update_advertise_vrf_routes(struct bgp *bgp_vrf); #endif /* _QUAGGA_BGP_EVPN_H */ diff --git a/bgpd/bgp_evpn_private.h b/bgpd/bgp_evpn_private.h index 76cf8b2cd..ea1ae087f 100644 --- a/bgpd/bgp_evpn_private.h +++ b/bgpd/bgp_evpn_private.h @@ -366,7 +366,7 @@ static inline void encode_na_flag_extcomm(struct ecommunity_val *eval, eval->val[2] |= ECOMMUNITY_EVPN_SUBTYPE_ND_ROUTER_FLAG; } -static inline void ip_prefix_from_type5_prefix(struct prefix_evpn *evp, +static inline void ip_prefix_from_type5_prefix(const struct prefix_evpn *evp, struct prefix *ip) { memset(ip, 0, sizeof(struct prefix)); @@ -392,7 +392,7 @@ static inline int is_evpn_prefix_default(const struct prefix *evp) 1 : 0); } -static inline void ip_prefix_from_type2_prefix(struct prefix_evpn *evp, +static inline void ip_prefix_from_type2_prefix(const struct prefix_evpn *evp, struct prefix *ip) { memset(ip, 0, sizeof(struct prefix)); @@ -409,7 +409,7 @@ static inline void ip_prefix_from_type2_prefix(struct prefix_evpn *evp, } } -static inline void ip_prefix_from_evpn_prefix(struct prefix_evpn *evp, +static inline void ip_prefix_from_evpn_prefix(const struct prefix_evpn *evp, struct prefix *ip) { if (evp->prefix.route_type == BGP_EVPN_MAC_IP_ROUTE) @@ -432,8 +432,9 @@ static inline void build_evpn_type2_prefix(struct prefix_evpn *p, memcpy(&p->prefix.macip_addr.ip, ip, sizeof(*ip)); } -static inline void build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp, - struct prefix *ip_prefix) +static inline void +build_type5_prefix_from_ip_prefix(struct prefix_evpn *evp, + const struct prefix *ip_prefix) { struct ipaddr ip; diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index 7ed37319b..70bd7b219 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -59,7 +59,7 @@ struct vni_walk_ctx { static void display_vrf_import_rt(struct vty *vty, struct vrf_irt_node *irt, json_object *json) { - uint8_t *pnt; + const uint8_t *pnt; uint8_t type, sub_type; struct ecommunity_as eas; struct ecommunity_ip eip; @@ -167,7 +167,7 @@ static void show_vrf_import_rt_entry(struct hash_bucket *bucket, void *args[]) static void display_import_rt(struct vty *vty, struct irt_node *irt, json_object *json) { - uint8_t *pnt; + const uint8_t *pnt; uint8_t type, sub_type; struct ecommunity_as eas; struct ecommunity_ip eip; @@ -2210,13 +2210,13 @@ static struct bgpevpn *evpn_create_update_vni(struct bgp *bgp, vni_t vni) * appropriate action) and the VNI marked as unconfigured; the * VNI will continue to exist, purely as a "learnt" entity. */ -static int evpn_delete_vni(struct bgp *bgp, struct bgpevpn *vpn) +static void evpn_delete_vni(struct bgp *bgp, struct bgpevpn *vpn) { assert(bgp->vnihash); if (!is_vni_live(vpn)) { bgp_evpn_free(bgp, vpn); - return 0; + return; } /* We need to take the unconfigure action for each parameter of this VNI @@ -2234,8 +2234,6 @@ static int evpn_delete_vni(struct bgp *bgp, struct bgpevpn *vpn) /* Next, deal with the import side. */ if (is_import_rt_configured(vpn)) evpn_unconfigure_import_rt(bgp, vpn, NULL); - - return 0; } /* diff --git a/bgpd/bgp_filter.c b/bgpd/bgp_filter.c index a03551e79..7de8dc2c8 100644 --- a/bgpd/bgp_filter.c +++ b/bgpd/bgp_filter.c @@ -302,12 +302,9 @@ static void as_list_delete(struct as_list *aslist) as_list_free(aslist); } -static int as_list_empty(struct as_list *aslist) +static bool as_list_empty(struct as_list *aslist) { - if (aslist->head == NULL && aslist->tail == NULL) - return 1; - else - return 0; + return aslist->head == NULL && aslist->tail == NULL; } static void as_list_filter_delete(struct as_list *aslist, @@ -337,11 +334,9 @@ static void as_list_filter_delete(struct as_list *aslist, XFREE(MTYPE_AS_STR, name); } -static int as_filter_match(struct as_filter *asfilter, struct aspath *aspath) +static bool as_filter_match(struct as_filter *asfilter, struct aspath *aspath) { - if (bgp_regexec(asfilter->reg, aspath) != REG_NOMATCH) - return 1; - return 0; + return bgp_regexec(asfilter->reg, aspath) != REG_NOMATCH; } /* Apply AS path filter to AS. */ @@ -374,26 +369,25 @@ void as_list_delete_hook(void (*func)(const char *)) as_list_master.delete_hook = func; } -static int as_list_dup_check(struct as_list *aslist, struct as_filter *new) +static bool as_list_dup_check(struct as_list *aslist, struct as_filter *new) { struct as_filter *asfilter; for (asfilter = aslist->head; asfilter; asfilter = asfilter->next) { if (asfilter->type == new->type && strcmp(asfilter->reg_str, new->reg_str) == 0) - return 1; + return true; } - return 0; + return false; } -int config_bgp_aspath_validate(const char *regstr) +bool config_bgp_aspath_validate(const char *regstr) { char valid_chars[] = "1234567890_^|[,{}() ]$*+.?-\\"; if (strspn(regstr, valid_chars) == strlen(regstr)) - return 1; - - return 0; + return true; + return false; } DEFUN(as_path, bgp_as_path_cmd, diff --git a/bgpd/bgp_filter.h b/bgpd/bgp_filter.h index 3c49e357f..9357a2d38 100644 --- a/bgpd/bgp_filter.h +++ b/bgpd/bgp_filter.h @@ -31,6 +31,6 @@ extern enum as_filter_type as_list_apply(struct as_list *, void *); extern struct as_list *as_list_lookup(const char *); extern void as_list_add_hook(void (*func)(char *)); extern void as_list_delete_hook(void (*func)(const char *)); -extern int config_bgp_aspath_validate(const char *regstr); +extern bool config_bgp_aspath_validate(const char *regstr); #endif /* _QUAGGA_BGP_FILTER_H */ diff --git a/bgpd/bgp_flowspec.h b/bgpd/bgp_flowspec.h index bc201b739..94c571f2f 100644 --- a/bgpd/bgp_flowspec.h +++ b/bgpd/bgp_flowspec.h @@ -43,7 +43,7 @@ extern void bgp_fs_nlri_get_string(unsigned char *nlri_content, size_t len, char *return_string, int format, json_object *json_path); -extern void route_vty_out_flowspec(struct vty *vty, struct prefix *p, +extern void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, json_object *json_paths); extern int bgp_fs_config_write_pbr(struct vty *vty, struct bgp *bgp, diff --git a/bgpd/bgp_flowspec_util.c b/bgpd/bgp_flowspec_util.c index 002aae561..79d5268c7 100644 --- a/bgpd/bgp_flowspec_util.c +++ b/bgpd/bgp_flowspec_util.c @@ -76,9 +76,8 @@ static int bgp_flowspec_call_non_opaque_decode(uint8_t *nlri_content, int len, return ret; } -bool bgp_flowspec_contains_prefix(struct prefix *pfs, - struct prefix *input, - int prefix_check) +bool bgp_flowspec_contains_prefix(const struct prefix *pfs, + struct prefix *input, int prefix_check) { uint32_t offset = 0; int type; @@ -599,8 +598,8 @@ int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len, } /* return 1 if FS entry invalid or no NH IP */ -int bgp_flowspec_get_first_nh(struct bgp *bgp, struct bgp_path_info *pi, - struct prefix *p) +bool bgp_flowspec_get_first_nh(struct bgp *bgp, struct bgp_path_info *pi, + struct prefix *p) { struct bgp_pbr_entry_main api; int i; @@ -609,7 +608,7 @@ int bgp_flowspec_get_first_nh(struct bgp *bgp, struct bgp_path_info *pi, memset(&api, 0, sizeof(struct bgp_pbr_entry_main)); if (bgp_pbr_build_and_validate_entry(&rn->p, pi, &api) < 0) - return 1; + return true; for (i = 0; i < api.action_num; i++) { api_action = &api.actions[i]; if (api_action->action != ACTION_REDIRECT_IP) @@ -617,7 +616,7 @@ int bgp_flowspec_get_first_nh(struct bgp *bgp, struct bgp_path_info *pi, p->family = AF_INET; p->prefixlen = IPV4_MAX_BITLEN; p->u.prefix4 = api_action->u.zr.redirect_ip_v4; - return 0; + return false; } - return 1; + return true; } diff --git a/bgpd/bgp_flowspec_util.h b/bgpd/bgp_flowspec_util.h index 2ce911da4..0e78c7a53 100644 --- a/bgpd/bgp_flowspec_util.h +++ b/bgpd/bgp_flowspec_util.h @@ -50,12 +50,11 @@ struct bgp_pbr_entry_main; extern int bgp_flowspec_match_rules_fill(uint8_t *nlri_content, int len, struct bgp_pbr_entry_main *bpem); -extern bool bgp_flowspec_contains_prefix(struct prefix *pfs, +extern bool bgp_flowspec_contains_prefix(const struct prefix *pfs, struct prefix *input, int prefix_check); -extern int bgp_flowspec_get_first_nh(struct bgp *bgp, - struct bgp_path_info *pi, - struct prefix *nh); +extern bool bgp_flowspec_get_first_nh(struct bgp *bgp, struct bgp_path_info *pi, + struct prefix *nh); #endif /* _FRR_BGP_FLOWSPEC_UTIL_H */ diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c index 80384c12c..c453c4e81 100644 --- a/bgpd/bgp_flowspec_vty.c +++ b/bgpd/bgp_flowspec_vty.c @@ -252,7 +252,7 @@ void bgp_fs_nlri_get_string(unsigned char *nlri_content, size_t len, } } -void route_vty_out_flowspec(struct vty *vty, struct prefix *p, +void route_vty_out_flowspec(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, json_object *json_paths) { diff --git a/bgpd/bgp_fsm.c b/bgpd/bgp_fsm.c index f4fbfe4c6..fdffe374c 100644 --- a/bgpd/bgp_fsm.c +++ b/bgpd/bgp_fsm.c @@ -130,8 +130,8 @@ static struct peer *peer_xfer_conn(struct peer *from_peer) afi_t afi; safi_t safi; int fd; - int status, pstatus; - unsigned char last_evt, last_maj_evt; + enum bgp_fsm_status status, pstatus; + enum bgp_fsm_events last_evt, last_maj_evt; assert(from_peer != NULL); @@ -456,6 +456,10 @@ void bgp_timer_set(struct peer *peer) bgp_keepalives_off(peer); BGP_TIMER_OFF(peer->t_routeadv); break; + case BGP_STATUS_MAX: + flog_err(EC_LIB_DEVELOPMENT, + "BGP_STATUS_MAX while a legal state is not valid state for the FSM"); + break; } } @@ -660,32 +664,29 @@ static int bgp_graceful_deferral_timer_expire(struct thread *thread) return bgp_best_path_select_defer(bgp, afi, safi); } -static int bgp_update_delay_applicable(struct bgp *bgp) +static bool bgp_update_delay_applicable(struct bgp *bgp) { /* update_delay_over flag should be reset (set to 0) for any new applicability of the update-delay during BGP process lifetime. And it should be set after an occurence of the update-delay is over)*/ if (!bgp->update_delay_over) - return 1; - - return 0; + return true; + return false; } -int bgp_update_delay_active(struct bgp *bgp) +bool bgp_update_delay_active(struct bgp *bgp) { if (bgp->t_update_delay) - return 1; - - return 0; + return true; + return false; } -int bgp_update_delay_configured(struct bgp *bgp) +bool bgp_update_delay_configured(struct bgp *bgp) { if (bgp->v_update_delay) - return 1; - - return 0; + return true; + return false; } /* Do the post-processing needed when bgp comes out of the read-only mode @@ -836,28 +837,25 @@ void bgp_adjust_routeadv(struct peer *peer) } } -static int bgp_maxmed_onstartup_applicable(struct bgp *bgp) +static bool bgp_maxmed_onstartup_applicable(struct bgp *bgp) { if (!bgp->maxmed_onstartup_over) - return 1; - - return 0; + return true; + return false; } -int bgp_maxmed_onstartup_configured(struct bgp *bgp) +bool bgp_maxmed_onstartup_configured(struct bgp *bgp) { if (bgp->v_maxmed_onstartup != BGP_MAXMED_ONSTARTUP_UNCONFIGURED) - return 1; - - return 0; + return true; + return false; } -int bgp_maxmed_onstartup_active(struct bgp *bgp) +bool bgp_maxmed_onstartup_active(struct bgp *bgp) { if (bgp->t_maxmed_onstartup) - return 1; - - return 0; + return true; + return false; } void bgp_maxmed_update(struct bgp *bgp) @@ -2037,7 +2035,7 @@ void bgp_fsm_event_update(struct peer *peer, int valid) /* Finite State Machine structure */ static const struct { int (*func)(struct peer *); - int next_state; + enum bgp_fsm_status next_state; } FSM[BGP_STATUS_MAX - 1][BGP_EVENTS_MAX - 1] = { { /* Idle state: In Idle state, all events other than BGP_Start is @@ -2184,7 +2182,7 @@ static const struct { /* Execute event process. */ int bgp_event(struct thread *thread) { - int event; + enum bgp_fsm_events event; struct peer *peer; int ret; @@ -2196,9 +2194,9 @@ int bgp_event(struct thread *thread) return (ret); } -int bgp_event_update(struct peer *peer, int event) +int bgp_event_update(struct peer *peer, enum bgp_fsm_events event) { - int next; + enum bgp_fsm_status next; int ret = 0; struct peer *other; int passive_conn = 0; diff --git a/bgpd/bgp_fsm.h b/bgpd/bgp_fsm.h index 4b8db161d..2fd5f6fc4 100644 --- a/bgpd/bgp_fsm.h +++ b/bgpd/bgp_fsm.h @@ -111,7 +111,7 @@ /* Prototypes. */ extern void bgp_fsm_event_update(struct peer *peer, int valid); extern int bgp_event(struct thread *); -extern int bgp_event_update(struct peer *, int event); +extern int bgp_event_update(struct peer *, enum bgp_fsm_events event); extern int bgp_stop(struct peer *peer); extern void bgp_timer_set(struct peer *); extern int bgp_routeadv_timer(struct thread *); @@ -119,8 +119,8 @@ extern void bgp_fsm_change_status(struct peer *peer, int status); extern const char *const peer_down_str[]; extern void bgp_update_delay_end(struct bgp *); extern void bgp_maxmed_update(struct bgp *); -extern int bgp_maxmed_onstartup_configured(struct bgp *); -extern int bgp_maxmed_onstartup_active(struct bgp *); +extern bool bgp_maxmed_onstartup_configured(struct bgp *); +extern bool bgp_maxmed_onstartup_active(struct bgp *); extern int bgp_fsm_error_subcode(int status); /** diff --git a/bgpd/bgp_lcommunity.c b/bgpd/bgp_lcommunity.c index 7a4435f6f..c21056f30 100644 --- a/bgpd/bgp_lcommunity.c +++ b/bgpd/bgp_lcommunity.c @@ -59,8 +59,8 @@ static void lcommunity_hash_free(struct lcommunity *lcom) structure, we don't add the value. Newly added value is sorted by numerical order. When the value is added to the structure return 1 else return 0. */ -static int lcommunity_add_val(struct lcommunity *lcom, - struct lcommunity_val *lval) +static bool lcommunity_add_val(struct lcommunity *lcom, + struct lcommunity_val *lval) { uint8_t *p; int ret; @@ -71,7 +71,7 @@ static int lcommunity_add_val(struct lcommunity *lcom, lcom->size++; lcom->val = XMALLOC(MTYPE_LCOMMUNITY_VAL, lcom_length(lcom)); memcpy(lcom->val, lval->val, LCOMMUNITY_SIZE); - return 1; + return true; } /* If the value already exists in the structure return 0. */ @@ -79,7 +79,7 @@ static int lcommunity_add_val(struct lcommunity *lcom, for (p = lcom->val; c < lcom->size; p += LCOMMUNITY_SIZE, c++) { ret = memcmp(p, lval->val, LCOMMUNITY_SIZE); if (ret == 0) - return 0; + return false; if (ret > 0) break; } @@ -94,7 +94,7 @@ static int lcommunity_add_val(struct lcommunity *lcom, (lcom->size - 1 - c) * LCOMMUNITY_SIZE); memcpy(lcom->val + c * LCOMMUNITY_SIZE, lval->val, LCOMMUNITY_SIZE); - return 1; + return true; } /* This function takes pointer to Large Communites strucutre then @@ -178,7 +178,7 @@ static void set_lcommunity_string(struct lcommunity *lcom, bool make_json) int i; int len; char *str_buf; - uint8_t *pnt; + const uint8_t *pnt; uint32_t global, local1, local2; json_object *json_lcommunity_list = NULL; json_object *json_string = NULL; @@ -456,7 +456,7 @@ struct lcommunity *lcommunity_str2com(const char *str) return lcom; } -int lcommunity_include(struct lcommunity *lcom, uint8_t *ptr) +bool lcommunity_include(struct lcommunity *lcom, uint8_t *ptr) { int i; uint8_t *lcom_ptr; @@ -464,25 +464,25 @@ int lcommunity_include(struct lcommunity *lcom, uint8_t *ptr) for (i = 0; i < lcom->size; i++) { lcom_ptr = lcom->val + (i * LCOMMUNITY_SIZE); if (memcmp(ptr, lcom_ptr, LCOMMUNITY_SIZE) == 0) - return 1; + return true; } - return 0; + return false; } -int lcommunity_match(const struct lcommunity *lcom1, - const struct lcommunity *lcom2) +bool lcommunity_match(const struct lcommunity *lcom1, + const struct lcommunity *lcom2) { int i = 0; int j = 0; if (lcom1 == NULL && lcom2 == NULL) - return 1; + return true; if (lcom1 == NULL || lcom2 == NULL) - return 0; + return false; if (lcom1->size < lcom2->size) - return 0; + return false; /* Every community on com2 needs to be on com1 for this to match */ while (i < lcom1->size && j < lcom2->size) { @@ -494,9 +494,9 @@ int lcommunity_match(const struct lcommunity *lcom1, } if (j == lcom2->size) - return 1; + return true; else - return 0; + return false; } /* Delete one lcommunity. */ diff --git a/bgpd/bgp_lcommunity.h b/bgpd/bgp_lcommunity.h index 7d63f4d26..e10ab0eef 100644 --- a/bgpd/bgp_lcommunity.h +++ b/bgpd/bgp_lcommunity.h @@ -66,10 +66,10 @@ extern void lcommunity_unintern(struct lcommunity **); extern unsigned int lcommunity_hash_make(const void *); extern struct hash *lcommunity_hash(void); extern struct lcommunity *lcommunity_str2com(const char *); -extern int lcommunity_match(const struct lcommunity *, - const struct lcommunity *); +extern bool lcommunity_match(const struct lcommunity *, + const struct lcommunity *); extern char *lcommunity_str(struct lcommunity *, bool make_json); -extern int lcommunity_include(struct lcommunity *lcom, uint8_t *ptr); +extern bool lcommunity_include(struct lcommunity *lcom, uint8_t *ptr); extern void lcommunity_del_val(struct lcommunity *lcom, uint8_t *ptr); extern void bgp_compute_aggregate_lcommunity( diff --git a/bgpd/bgp_mac.c b/bgpd/bgp_mac.c index 537bb4545..fed88fd50 100644 --- a/bgpd/bgp_mac.c +++ b/bgpd/bgp_mac.c @@ -358,7 +358,7 @@ void bgp_mac_del_mac_entry(struct interface *ifp) * An example: router-mac attribute in any of evpn update * requires to compare against local mac. */ -bool bgp_mac_exist(struct ethaddr *mac) +bool bgp_mac_exist(const struct ethaddr *mac) { struct bgp_self_mac lookup; struct bgp_self_mac *bsm; @@ -379,9 +379,9 @@ bool bgp_mac_exist(struct ethaddr *mac) * mac against any of local assigned (SVIs) MAC * address. */ -bool bgp_mac_entry_exists(struct prefix *p) +bool bgp_mac_entry_exists(const struct prefix *p) { - struct prefix_evpn *pevpn = (struct prefix_evpn *)p; + const struct prefix_evpn *pevpn = (const struct prefix_evpn *)p; if (pevpn->family != AF_EVPN) return false; diff --git a/bgpd/bgp_mac.h b/bgpd/bgp_mac.h index 68449b574..4b94d80d1 100644 --- a/bgpd/bgp_mac.h +++ b/bgpd/bgp_mac.h @@ -36,7 +36,7 @@ void bgp_mac_dump_table(struct vty *vty); /* * Function to lookup the prefix and see if we have a matching mac */ -bool bgp_mac_entry_exists(struct prefix *p); -bool bgp_mac_exist(struct ethaddr *mac); +bool bgp_mac_entry_exists(const struct prefix *p); +bool bgp_mac_exist(const struct ethaddr *mac); #endif diff --git a/bgpd/bgp_mpath.c b/bgpd/bgp_mpath.c index 9e73acdc0..7ec33556c 100644 --- a/bgpd/bgp_mpath.c +++ b/bgpd/bgp_mpath.c @@ -457,7 +457,7 @@ void bgp_path_info_mpath_update(struct bgp_node *rn, old_mpath_count = 0; prev_mpath = new_best; mp_node = listhead(mp_list); - debug = bgp_debug_bestpath(&rn->p); + debug = bgp_debug_bestpath(rn); if (debug) prefix2str(&rn->p, pfx_buf, sizeof(pfx_buf)); diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 8758d0ca7..3e2ba9802 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -385,13 +385,13 @@ int vpn_leak_label_callback( return 0; } -static int ecom_intersect(struct ecommunity *e1, struct ecommunity *e2) +static bool ecom_intersect(struct ecommunity *e1, struct ecommunity *e2) { int i; int j; if (!e1 || !e2) - return 0; + return false; for (i = 0; i < e1->size; ++i) { for (j = 0; j < e2->size; ++j) { @@ -399,11 +399,11 @@ static int ecom_intersect(struct ecommunity *e1, struct ecommunity *e2) e2->val + (j * ECOMMUNITY_SIZE), ECOMMUNITY_SIZE)) { - return 1; + return true; } } } - return 0; + return false; } static bool labels_same(struct bgp_path_info *bpi, mpls_label_t *label, @@ -744,10 +744,15 @@ void vpn_leak_from_vrf_update(struct bgp *bgp_vpn, /* to */ struct ecommunity *old_ecom; struct ecommunity *new_ecom; + /* Export with the 'from' instance's export RTs. */ + /* If doing VRF-to-VRF leaking, strip existing RTs first. */ old_ecom = static_attr.ecommunity; if (old_ecom) { - new_ecom = ecommunity_merge( - ecommunity_dup(old_ecom), + new_ecom = ecommunity_dup(old_ecom); + if (CHECK_FLAG(bgp_vrf->af_flags[afi][SAFI_UNICAST], + BGP_CONFIG_VRF_TO_VRF_EXPORT)) + ecommunity_strip_rts(new_ecom); + new_ecom = ecommunity_merge(new_ecom, bgp_vrf->vpn_policy[afi] .rtlist[BGP_VPN_POLICY_DIR_TOVPN]); if (!old_ecom->refcnt) @@ -1087,6 +1092,20 @@ vpn_leak_to_vrf_update_onevrf(struct bgp *bgp_vrf, /* to */ /* shallow copy */ static_attr = *path_vpn->attr; + struct ecommunity *old_ecom; + struct ecommunity *new_ecom; + + /* If doing VRF-to-VRF leaking, strip RTs. */ + old_ecom = static_attr.ecommunity; + if (old_ecom && CHECK_FLAG(bgp_vrf->af_flags[afi][safi], + BGP_CONFIG_VRF_TO_VRF_IMPORT)) { + new_ecom = ecommunity_dup(old_ecom); + ecommunity_strip_rts(new_ecom); + static_attr.ecommunity = new_ecom; + if (!old_ecom->refcnt) + ecommunity_free(&old_ecom); + } + /* * Nexthop: stash and clear * diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 8e43801d2..23c5adbf2 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -470,8 +470,8 @@ static void bgp_connected_cleanup(struct route_table *table, } } -int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, uint8_t sub_type, - struct attr *attr, struct bgp_node *rn) +bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, + uint8_t sub_type, struct attr *attr, struct bgp_node *rn) { uint8_t new_afi = afi == AFI_IP ? AF_INET : AF_INET6; struct bgp_addr tmp_addr = {{0}}, *addr = NULL; @@ -505,7 +505,7 @@ int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, uint8_t sub_type, attr->mp_nexthop_global_in; tmp_addr.p.prefixlen = IPV4_MAX_BITLEN; } else - return 0; + return false; } break; case AF_INET6: @@ -523,7 +523,7 @@ int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, uint8_t sub_type, addr = hash_lookup(bgp->address_hash, &tmp_addr); if (addr) - return 1; + return true; if (new_afi == AF_INET) { memset(&tmp_tip, 0, sizeof(struct tip_addr)); @@ -539,13 +539,13 @@ int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, uint8_t sub_type, tip = hash_lookup(bgp->tip_hash, &tmp_tip); if (tip) - return 1; + return true; } - return 0; + return false; } -int bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer) +bool bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer) { struct bgp_node *rn1; struct bgp_node *rn2; @@ -558,7 +558,7 @@ int bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer) rn1 = bgp_node_match(peer->bgp->connected_table[AFI_IP], &p); if (!rn1) - return 0; + return false; p.family = AF_INET; p.prefixlen = IPV4_MAX_BITLEN; @@ -567,18 +567,18 @@ int bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer) rn2 = bgp_node_match(peer->bgp->connected_table[AFI_IP], &p); if (!rn2) { bgp_unlock_node(rn1); - return 0; + return false; } - ret = (rn1 == rn2) ? 1 : 0; + ret = (rn1 == rn2); bgp_unlock_node(rn1); bgp_unlock_node(rn2); - return (ret); + return ret; } -int bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) +bool bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) { struct bgp_node *rn1; struct bgp_node *rn2; @@ -591,7 +591,7 @@ int bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) rn1 = bgp_node_match(peer->bgp->connected_table[AFI_IP6], &p); if (!rn1) - return 0; + return false; p.family = AF_INET6; p.prefixlen = IPV6_MAX_BITLEN; @@ -600,10 +600,10 @@ int bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) rn2 = bgp_node_match(peer->bgp->connected_table[AFI_IP6], &p); if (!rn2) { bgp_unlock_node(rn1); - return 0; + return false; } - ret = (rn1 == rn2) ? 1 : 0; + ret = (rn1 == rn2); bgp_unlock_node(rn1); bgp_unlock_node(rn2); @@ -611,9 +611,9 @@ int bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer) return ret; } -int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, - struct update_subgroup *subgrp, - struct peer *exclude) +bool bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, + struct update_subgroup *subgrp, + struct peer *exclude) { struct bgp_node *rn1 = NULL, *rn2 = NULL; struct peer_af *paf = NULL; @@ -630,7 +630,7 @@ int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, bgp = SUBGRP_INST(subgrp); rn1 = bgp_node_match(bgp->connected_table[AFI_IP6], &np); if (!rn1) - return 0; + return false; SUBGRP_FOREACH_PEER (subgrp, paf) { /* Skip peer we're told to exclude - e.g., source of route. */ @@ -642,7 +642,7 @@ int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, if (rn1 == rn2) { bgp_unlock_node(rn1); bgp_unlock_node(rn2); - return 1; + return true; } if (rn2) @@ -650,12 +650,12 @@ int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, } bgp_unlock_node(rn1); - return 0; + return false; } -int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, - struct update_subgroup *subgrp, - struct peer *exclude) +bool bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, + struct update_subgroup *subgrp, + struct peer *exclude) { struct bgp_node *rn1, *rn2; struct peer_af *paf; @@ -672,7 +672,7 @@ int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, bgp = SUBGRP_INST(subgrp); rn1 = bgp_node_match(bgp->connected_table[AFI_IP], &np); if (!rn1) - return 0; + return false; SUBGRP_FOREACH_PEER (subgrp, paf) { /* Skip peer we're told to exclude - e.g., source of route. */ @@ -685,7 +685,7 @@ int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, if (rn1 == rn2) { bgp_unlock_node(rn1); bgp_unlock_node(rn2); - return 1; + return true; } if (rn2) @@ -693,7 +693,7 @@ int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, } bgp_unlock_node(rn1); - return 0; + return false; } static void bgp_show_nexthops_detail(struct vty *vty, struct bgp *bgp, diff --git a/bgpd/bgp_nexthop.h b/bgpd/bgp_nexthop.h index 4a25c83cd..461e77211 100644 --- a/bgpd/bgp_nexthop.h +++ b/bgpd/bgp_nexthop.h @@ -81,18 +81,19 @@ struct bgp_addrv6 { extern void bgp_connected_add(struct bgp *bgp, struct connected *c); extern void bgp_connected_delete(struct bgp *bgp, struct connected *c); -extern int bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, - struct update_subgroup *subgrp, - struct peer *exclude); -extern int bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, - struct update_subgroup *subgrp, - struct peer *exclude); -extern int bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer); -extern int bgp_multiaccess_check_v6(struct in6_addr nexthop, struct peer *peer); +extern bool bgp_subgrp_multiaccess_check_v4(struct in_addr nexthop, + struct update_subgroup *subgrp, + struct peer *exclude); +extern bool bgp_subgrp_multiaccess_check_v6(struct in6_addr nexthop, + struct update_subgroup *subgrp, + struct peer *exclude); +extern bool bgp_multiaccess_check_v4(struct in_addr nexthop, struct peer *peer); +extern bool bgp_multiaccess_check_v6(struct in6_addr nexthop, + struct peer *peer); extern int bgp_config_write_scan_time(struct vty *); -extern int bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, - uint8_t sub_type, struct attr *attr, - struct bgp_node *rn); +extern bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type, + uint8_t sub_type, struct attr *attr, + struct bgp_node *rn); extern struct bgp_nexthop_cache *bnc_new(void); extern void bnc_free(struct bgp_nexthop_cache *bnc); extern void bnc_nexthop_free(struct bgp_nexthop_cache *bnc); diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c index 81bb45aa7..4a2f7d588 100644 --- a/bgpd/bgp_open.c +++ b/bgpd/bgp_open.c @@ -1013,15 +1013,15 @@ static int bgp_auth_parse(struct peer *peer, size_t length) return -1; } -static int strict_capability_same(struct peer *peer) +static bool strict_capability_same(struct peer *peer) { int i, j; for (i = AFI_IP; i < AFI_MAX; i++) for (j = SAFI_UNICAST; j < SAFI_MAX; j++) if (peer->afc[i][j] != peer->afc_nego[i][j]) - return 0; - return 1; + return false; + return true; } /* peek into option, stores ASN to *as4 if the AS4 capability was found. diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c index 9649de464..10e96497f 100644 --- a/bgpd/bgp_packet.c +++ b/bgpd/bgp_packet.c @@ -587,7 +587,7 @@ void bgp_open_send(struct peer *peer) * @param peer * @return 0 */ -static int bgp_write_notify(struct peer *peer) +static void bgp_write_notify(struct peer *peer) { int ret, val; uint8_t type; @@ -597,7 +597,7 @@ static int bgp_write_notify(struct peer *peer) s = stream_fifo_pop(peer->obuf); if (!s) - return 0; + return; assert(stream_get_endp(s) >= BGP_HEADER_SIZE); @@ -617,7 +617,7 @@ static int bgp_write_notify(struct peer *peer) if (ret <= 0) { stream_free(s); BGP_EVENT_ADD(peer, TCP_fatal_error); - return 0; + return; } /* Disable Nagle, make NOTIFY packet go out right away */ @@ -649,8 +649,6 @@ static int bgp_write_notify(struct peer *peer) BGP_EVENT_ADD(peer, BGP_Stop); stream_free(s); - - return 0; } /* @@ -2337,7 +2335,7 @@ int bgp_process_packet(struct thread *thread) flog_err( EC_BGP_PKT_OPEN, "%s: BGP OPEN receipt failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); break; case BGP_MSG_UPDATE: atomic_fetch_add_explicit(&peer->update_in, 1, @@ -2348,7 +2346,7 @@ int bgp_process_packet(struct thread *thread) flog_err( EC_BGP_UPDATE_RCV, "%s: BGP UPDATE receipt failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); break; case BGP_MSG_NOTIFY: atomic_fetch_add_explicit(&peer->notify_in, 1, @@ -2358,7 +2356,7 @@ int bgp_process_packet(struct thread *thread) flog_err( EC_BGP_NOTIFY_RCV, "%s: BGP NOTIFY receipt failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); break; case BGP_MSG_KEEPALIVE: peer->readtime = monotime(NULL); @@ -2369,7 +2367,7 @@ int bgp_process_packet(struct thread *thread) flog_err( EC_BGP_KEEP_RCV, "%s: BGP KEEPALIVE receipt failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); break; case BGP_MSG_ROUTE_REFRESH_NEW: case BGP_MSG_ROUTE_REFRESH_OLD: @@ -2380,7 +2378,7 @@ int bgp_process_packet(struct thread *thread) flog_err( EC_BGP_RFSH_RCV, "%s: BGP ROUTEREFRESH receipt failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); break; case BGP_MSG_CAPABILITY: atomic_fetch_add_explicit(&peer->dynamic_cap_in, 1, @@ -2390,7 +2388,7 @@ int bgp_process_packet(struct thread *thread) flog_err( EC_BGP_CAP_RCV, "%s: BGP CAPABILITY receipt failed for peer: %s", - __FUNCTION__, peer->host); + __func__, peer->host); break; default: /* Suppress uninitialized variable warning */ diff --git a/bgpd/bgp_pbr.c b/bgpd/bgp_pbr.c index 172ec8b42..fd3fad63f 100644 --- a/bgpd/bgp_pbr.c +++ b/bgpd/bgp_pbr.c @@ -685,9 +685,9 @@ static int bgp_pbr_validate_policy_route(struct bgp_pbr_entry_main *api) } /* return -1 if build or validation failed */ -int bgp_pbr_build_and_validate_entry(struct prefix *p, - struct bgp_path_info *path, - struct bgp_pbr_entry_main *api) +int bgp_pbr_build_and_validate_entry(const struct prefix *p, + struct bgp_path_info *path, + struct bgp_pbr_entry_main *api) { int ret; int i, action_count = 0; @@ -2610,7 +2610,7 @@ static void bgp_pbr_handle_entry(struct bgp *bgp, struct bgp_path_info *path, } } -void bgp_pbr_update_entry(struct bgp *bgp, struct prefix *p, +void bgp_pbr_update_entry(struct bgp *bgp, const struct prefix *p, struct bgp_path_info *info, afi_t afi, safi_t safi, bool nlri_update) { diff --git a/bgpd/bgp_pbr.h b/bgpd/bgp_pbr.h index 393b08da4..47d5e2169 100644 --- a/bgpd/bgp_pbr.h +++ b/bgpd/bgp_pbr.h @@ -291,7 +291,7 @@ void bgp_pbr_print_policy_route(struct bgp_pbr_entry_main *api); struct bgp_node; struct bgp_path_info; -extern void bgp_pbr_update_entry(struct bgp *bgp, struct prefix *p, +extern void bgp_pbr_update_entry(struct bgp *bgp, const struct prefix *p, struct bgp_path_info *new_select, afi_t afi, safi_t safi, bool nlri_update); @@ -301,7 +301,7 @@ extern void bgp_pbr_reset(struct bgp *bgp, afi_t afi); extern struct bgp_pbr_interface *bgp_pbr_interface_lookup(const char *name, struct bgp_pbr_interface_head *head); -extern int bgp_pbr_build_and_validate_entry(struct prefix *p, +extern int bgp_pbr_build_and_validate_entry(const struct prefix *p, struct bgp_path_info *path, struct bgp_pbr_entry_main *api); #endif /* __BGP_PBR_H__ */ diff --git a/bgpd/bgp_rd.c b/bgpd/bgp_rd.c index be950dfa5..5facf3269 100644 --- a/bgpd/bgp_rd.c +++ b/bgpd/bgp_rd.c @@ -37,7 +37,7 @@ #include "bgpd/rfapi/rfapi_backend.h" #endif -uint16_t decode_rd_type(uint8_t *pnt) +uint16_t decode_rd_type(const uint8_t *pnt) { uint16_t v; @@ -60,7 +60,7 @@ void encode_rd_type(uint16_t v, uint8_t *pnt) } /* type == RD_TYPE_AS */ -void decode_rd_as(uint8_t *pnt, struct rd_as *rd_as) +void decode_rd_as(const uint8_t *pnt, struct rd_as *rd_as) { rd_as->as = (uint16_t)*pnt++ << 8; rd_as->as |= (uint16_t)*pnt++; @@ -68,7 +68,7 @@ void decode_rd_as(uint8_t *pnt, struct rd_as *rd_as) } /* type == RD_TYPE_AS4 */ -void decode_rd_as4(uint8_t *pnt, struct rd_as *rd_as) +void decode_rd_as4(const uint8_t *pnt, struct rd_as *rd_as) { pnt = ptr_get_be32(pnt, &rd_as->as); rd_as->val = ((uint16_t)*pnt++ << 8); @@ -76,7 +76,7 @@ void decode_rd_as4(uint8_t *pnt, struct rd_as *rd_as) } /* type == RD_TYPE_IP */ -void decode_rd_ip(uint8_t *pnt, struct rd_ip *rd_ip) +void decode_rd_ip(const uint8_t *pnt, struct rd_ip *rd_ip) { memcpy(&rd_ip->ip, pnt, 4); pnt += 4; diff --git a/bgpd/bgp_rd.h b/bgpd/bgp_rd.h index c5ea34103..439dfd4a3 100644 --- a/bgpd/bgp_rd.h +++ b/bgpd/bgp_rd.h @@ -54,12 +54,12 @@ struct rd_vnc_eth { }; #endif -extern uint16_t decode_rd_type(uint8_t *pnt); +extern uint16_t decode_rd_type(const uint8_t *pnt); extern void encode_rd_type(uint16_t, uint8_t *); -extern void decode_rd_as(uint8_t *pnt, struct rd_as *rd_as); -extern void decode_rd_as4(uint8_t *pnt, struct rd_as *rd_as); -extern void decode_rd_ip(uint8_t *pnt, struct rd_ip *rd_ip); +extern void decode_rd_as(const uint8_t *pnt, struct rd_as *rd_as); +extern void decode_rd_as4(const uint8_t *pnt, struct rd_as *rd_as); +extern void decode_rd_ip(const uint8_t *pnt, struct rd_ip *rd_ip); #if ENABLE_BGP_VNC extern void decode_rd_vnc_eth(uint8_t *pnt, struct rd_vnc_eth *rd_vnc_eth); #endif diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 0fdf2d3a8..c958e330c 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -116,7 +116,7 @@ DEFINE_HOOK(bgp_process, struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi, - safi_t safi, struct prefix *p, + safi_t safi, const struct prefix *p, struct prefix_rd *prd) { struct bgp_node *rn; @@ -146,7 +146,7 @@ struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi, } struct bgp_node *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi, - safi_t safi, struct prefix *p, + safi_t safi, const struct prefix *p, struct prefix_rd *prd) { struct bgp_node *rn; @@ -1202,7 +1202,8 @@ int bgp_path_info_cmp_compatible(struct bgp *bgp, struct bgp_path_info *new, return ret; } -static enum filter_type bgp_input_filter(struct peer *peer, struct prefix *p, +static enum filter_type bgp_input_filter(struct peer *peer, + const struct prefix *p, struct attr *attr, afi_t afi, safi_t safi) { @@ -1241,7 +1242,8 @@ static enum filter_type bgp_input_filter(struct peer *peer, struct prefix *p, #undef FILTER_EXIST_WARN } -static enum filter_type bgp_output_filter(struct peer *peer, struct prefix *p, +static enum filter_type bgp_output_filter(struct peer *peer, + const struct prefix *p, struct attr *attr, afi_t afi, safi_t safi) { @@ -1282,30 +1284,30 @@ static enum filter_type bgp_output_filter(struct peer *peer, struct prefix *p, } /* If community attribute includes no_export then return 1. */ -static int bgp_community_filter(struct peer *peer, struct attr *attr) +static bool bgp_community_filter(struct peer *peer, struct attr *attr) { if (attr->community) { /* NO_ADVERTISE check. */ if (community_include(attr->community, COMMUNITY_NO_ADVERTISE)) - return 1; + return true; /* NO_EXPORT check. */ if (peer->sort == BGP_PEER_EBGP && community_include(attr->community, COMMUNITY_NO_EXPORT)) - return 1; + return true; /* NO_EXPORT_SUBCONFED check. */ if (peer->sort == BGP_PEER_EBGP || peer->sort == BGP_PEER_CONFED) if (community_include(attr->community, COMMUNITY_NO_EXPORT_SUBCONFED)) - return 1; + return true; } - return 0; + return false; } /* Route reflection loop check. */ -static int bgp_cluster_filter(struct peer *peer, struct attr *attr) +static bool bgp_cluster_filter(struct peer *peer, struct attr *attr) { struct in_addr cluster_id; @@ -1316,12 +1318,12 @@ static int bgp_cluster_filter(struct peer *peer, struct attr *attr) cluster_id = peer->bgp->router_id; if (cluster_loop_check(attr->cluster, cluster_id)) - return 1; + return true; } - return 0; + return false; } -static int bgp_input_modifier(struct peer *peer, struct prefix *p, +static int bgp_input_modifier(struct peer *peer, const struct prefix *p, struct attr *attr, afi_t afi, safi_t safi, const char *rmap_name, mpls_label_t *label, uint32_t num_labels, struct bgp_node *rn) @@ -1543,9 +1545,9 @@ static void subgroup_announce_reset_nhop(uint8_t family, struct attr *attr) memset(&attr->mp_nexthop_global_in, 0, BGP_ATTR_NHLEN_IPV4); } -int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, - struct update_subgroup *subgrp, struct prefix *p, - struct attr *attr) +bool subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, + struct update_subgroup *subgrp, + const struct prefix *p, struct attr *attr) { struct bgp_filter *filter; struct peer *from; @@ -1562,7 +1564,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, int samepeer_safe = 0; /* for synthetic mplsvpns routes */ if (DISABLE_BGP_ANNOUNCE) - return 0; + return false; afi = SUBGRP_AFI(subgrp); safi = SUBGRP_SAFI(subgrp); @@ -1609,7 +1611,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID) || CHECK_FLAG(pi->flags, BGP_PATH_HISTORY) || CHECK_FLAG(pi->flags, BGP_PATH_REMOVED)) { - return 0; + return false; } /* If this is not the bestpath then check to see if there is an enabled @@ -1617,14 +1619,14 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, * feature that requires us to advertise it */ if (!CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) { if (!bgp_addpath_tx_path(peer->addpath_type[afi][safi], pi)) { - return 0; + return false; } } /* Aggregate-address suppress check. */ if (pi->extra && pi->extra->suppress) if (!UNSUPPRESS_MAP_NAME(filter)) { - return 0; + return false; } /* @@ -1635,7 +1637,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, */ if (safi == SAFI_MPLS_VPN && pi->extra && pi->extra->num_labels && pi->extra->label[0] == BGP_PREVENT_VRF_2_VRF_LEAK) - return 0; + return false; /* If it's labeled safi, make sure the route has a valid label. */ if (safi == SAFI_LABELED_UNICAST) { @@ -1648,13 +1650,13 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN), p->prefixlen, &label); - return 0; + return false; } } /* Do not send back route to sender. */ if (onlypeer && from == onlypeer) { - return 0; + return false; } /* Do not send the default route in the BGP table if the neighbor is @@ -1662,9 +1664,9 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE)) { if (p->family == AF_INET && p->u.prefix4.s_addr == INADDR_ANY) - return 0; + return false; else if (p->family == AF_INET6 && p->prefixlen == 0) - return 0; + return false; } /* Transparency check. */ @@ -1679,7 +1681,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) zlog_debug( "subgrpannouncecheck: community filter check fail"); - return 0; + return false; } /* If the attribute has originator-id and it is same as remote @@ -1692,7 +1694,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, "remote router-id", onlypeer->host, prefix2str(p, buf, sizeof(buf))); - return 0; + return false; } /* ORF prefix-list filter check */ @@ -1710,7 +1712,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, peer->host, prefix2str(p, buf, sizeof(buf))); - return 0; + return false; } } @@ -1719,7 +1721,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, if (bgp_debug_update(NULL, p, subgrp->update_group, 0)) zlog_debug("%s [Update:SEND] %s is filtered", peer->host, prefix2str(p, buf, sizeof(buf))); - return 0; + return false; } /* AS path loop check. */ @@ -1730,7 +1732,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, "%s [Update:SEND] suppress announcement to peer AS %u " "that is part of AS path.", onlypeer->host, onlypeer->as); - return 0; + return false; } /* If we're a CONFED we need to loop check the CONFED ID too */ @@ -1741,7 +1743,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, "%s [Update:SEND] suppress announcement to peer AS %u" " is AS path.", peer->host, bgp->confed_id); - return 0; + return false; } } @@ -1765,13 +1767,13 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, BGP_FLAG_NO_CLIENT_TO_CLIENT)) if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) - return 0; + return false; } else { /* A route from a Non-client peer. Reflect to all other clients. */ if (!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_REFLECTOR_CLIENT)) - return 0; + return false; } } @@ -1875,16 +1877,9 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, struct bgp_path_info_extra dummy_rmap_path_extra = {0}; struct attr dummy_attr = {0}; - memset(&rmap_path, 0, sizeof(struct bgp_path_info)); - rmap_path.peer = peer; - rmap_path.attr = attr; - rmap_path.net = rn; - - if (pi->extra) { - memcpy(&dummy_rmap_path_extra, pi->extra, - sizeof(struct bgp_path_info_extra)); - rmap_path.extra = &dummy_rmap_path_extra; - } + /* Fill temp path_info */ + prep_for_rmap_apply(&rmap_path, &dummy_rmap_path_extra, + rn, pi, peer, attr); /* don't confuse inbound and outbound setting */ RESET_FLAG(attr->rmap_change_flags); @@ -1917,7 +1912,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, peer->host, prefix2str(p, buf, sizeof(buf))); bgp_attr_flush(attr); - return 0; + return false; } } @@ -1933,7 +1928,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, if (peer->bgp->ebgp_requires_policy == DEFAULT_EBGP_POLICY_ENABLED) if (!bgp_outbound_policy_exists(peer, filter)) - return 0; + return false; /* draft-ietf-idr-deprecate-as-set-confed-set * Filter routes having AS_SET or AS_CONFED_SET in the path. @@ -1943,7 +1938,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, */ if (peer->bgp->reject_as_sets == BGP_REJECT_AS_SETS_ENABLED) if (aspath_check_as_sets(attr->aspath)) - return 0; + return false; /* Codification of AS 0 Processing */ if (aspath_check_as_zero(attr->aspath)) @@ -2055,7 +2050,7 @@ int subgroup_announce_check(struct bgp_node *rn, struct bgp_path_info *pi, subgroup_announce_reset_nhop(AF_INET6, attr); } - return 1; + return true; } static int bgp_route_select_timer_expire(struct thread *thread) @@ -2102,7 +2097,7 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, do_mpath = (mpath_cfg->maxpaths_ebgp > 1 || mpath_cfg->maxpaths_ibgp > 1); - debug = bgp_debug_bestpath(&rn->p); + debug = bgp_debug_bestpath(rn); if (debug) prefix2str(&rn->p, pfx_buf, sizeof(pfx_buf)); @@ -2320,10 +2315,10 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, * A new route/change in bestpath of an existing route. Evaluate the path * for advertisement to the subgroup. */ -int subgroup_process_announce_selected(struct update_subgroup *subgrp, - struct bgp_path_info *selected, - struct bgp_node *rn, - uint32_t addpath_tx_id) +void subgroup_process_announce_selected(struct update_subgroup *subgrp, + struct bgp_path_info *selected, + struct bgp_node *rn, + uint32_t addpath_tx_id) { struct prefix *p; struct peer *onlypeer; @@ -2347,7 +2342,7 @@ int subgroup_process_announce_selected(struct update_subgroup *subgrp, /* First update is deferred until ORF or ROUTE-REFRESH is received */ if (onlypeer && CHECK_FLAG(onlypeer->af_sflags[afi][safi], PEER_STATUS_ORF_WAIT_REFRESH)) - return 0; + return; memset(&attr, 0, sizeof(struct attr)); /* It's initialized in bgp_announce_check() */ @@ -2366,8 +2361,6 @@ int subgroup_process_announce_selected(struct update_subgroup *subgrp, else { bgp_adj_out_unset_subgroup(rn, subgrp, 1, addpath_tx_id); } - - return 0; } /* @@ -2391,8 +2384,8 @@ void bgp_zebra_clear_route_change_flags(struct bgp_node *rn) * if the route selection returns the same best route as earlier - to * determine if we need to update zebra or not. */ -int bgp_zebra_has_route_changed(struct bgp_node *rn, - struct bgp_path_info *selected) +bool bgp_zebra_has_route_changed(struct bgp_node *rn, + struct bgp_path_info *selected) { struct bgp_path_info *mpinfo; @@ -2404,7 +2397,7 @@ int bgp_zebra_has_route_changed(struct bgp_node *rn, */ if (CHECK_FLAG(selected->flags, BGP_PATH_IGP_CHANGED) || CHECK_FLAG(selected->flags, BGP_PATH_MULTIPATH_CHG)) - return 1; + return true; /* * If this is multipath, check all selected paths for any nexthop change @@ -2413,11 +2406,11 @@ int bgp_zebra_has_route_changed(struct bgp_node *rn, mpinfo = bgp_path_info_mpath_next(mpinfo)) { if (CHECK_FLAG(mpinfo->flags, BGP_PATH_IGP_CHANGED) || CHECK_FLAG(mpinfo->flags, BGP_PATH_ATTR_CHANGED)) - return 1; + return true; } /* Nothing has changed from the RIB's perspective. */ - return 0; + return false; } struct bgp_process_queue { @@ -2458,7 +2451,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn, if (CHECK_FLAG(bgp->flags, BGP_FLAG_DELETE_IN_PROGRESS)) { if (rn) - debug = bgp_debug_bestpath(&rn->p); + debug = bgp_debug_bestpath(rn); if (debug) { prefix2str(&rn->p, pfx_buf, sizeof(pfx_buf)); zlog_debug( @@ -2485,7 +2478,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn, struct prefix *p = &rn->p; - debug = bgp_debug_bestpath(&rn->p); + debug = bgp_debug_bestpath(rn); if (debug) { prefix2str(&rn->p, pfx_buf, sizeof(pfx_buf)); zlog_debug("%s: p=%s afi=%s, safi=%s start", __func__, pfx_buf, @@ -2693,17 +2686,31 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_node *rn, /* apply the route-map */ if (bgp->adv_cmd_rmap[afi][safi].map) { route_map_result_t ret; + struct bgp_path_info rmap_path; + struct bgp_path_info_extra rmap_path_extra; + struct attr dummy_attr; + + dummy_attr = *new_select->attr; + + /* Fill temp path_info */ + prep_for_rmap_apply( + &rmap_path, &rmap_path_extra, + rn, new_select, new_select->peer, + &dummy_attr); + + RESET_FLAG(dummy_attr.rmap_change_flags); ret = route_map_apply( bgp->adv_cmd_rmap[afi][safi].map, - &rn->p, RMAP_BGP, new_select); - if (ret == RMAP_PERMITMATCH) - bgp_evpn_advertise_type5_route( - bgp, &rn->p, new_select->attr, - afi, safi); - else + &rn->p, RMAP_BGP, &rmap_path); + if (ret == RMAP_DENYMATCH) { + bgp_attr_flush(&dummy_attr); bgp_evpn_withdraw_type5_route( bgp, &rn->p, afi, safi); + } else + bgp_evpn_advertise_type5_route( + bgp, &rn->p, &dummy_attr, + afi, safi); } else { bgp_evpn_advertise_type5_route(bgp, &rn->p, @@ -2941,20 +2948,20 @@ static int bgp_maximum_prefix_restart_timer(struct thread *thread) return 0; } -int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, - int always) +bool bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, + int always) { iana_afi_t pkt_afi; iana_safi_t pkt_safi; if (!CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX)) - return 0; + return false; if (peer->pcount[afi][safi] > peer->pmax[afi][safi]) { if (CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT) && !always) - return 0; + return false; zlog_info( "%%MAXPFXEXCEED: No. of %s prefix received from %s %" PRIu32 @@ -2965,7 +2972,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, if (CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_MAX_PREFIX_WARNING)) - return 0; + return false; /* Convert AFI, SAFI to values for packet. */ pkt_afi = afi_int2iana(afi); @@ -2989,7 +2996,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, /* Dynamic peers will just close their connection. */ if (peer_dynamic_neighbor(peer)) - return 1; + return true; /* restart timer start */ if (peer->pmax_restart[afi][safi]) { @@ -3006,7 +3013,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, peer->v_pmax_restart); } - return 1; + return true; } else UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_LIMIT); @@ -3016,7 +3023,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, if (CHECK_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD) && !always) - return 0; + return false; zlog_info( "%%MAXPFX: No. of %s prefix received from %s reaches %" PRIu32 @@ -3028,7 +3035,7 @@ int bgp_maximum_prefix_overflow(struct peer *peer, afi_t afi, safi_t safi, } else UNSET_FLAG(peer->af_sflags[afi][safi], PEER_STATUS_PREFIX_THRESHOLD); - return 0; + return false; } /* Unconditionally remove the route from the RIB, without taking @@ -3197,23 +3204,23 @@ static bool overlay_index_equal(afi_t afi, struct bgp_path_info *path, } /* Check if received nexthop is valid or not. */ -static int bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, - uint8_t type, uint8_t stype, - struct attr *attr, struct bgp_node *rn) +static bool bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, + uint8_t type, uint8_t stype, + struct attr *attr, struct bgp_node *rn) { - int ret = 0; + bool ret = 0; /* Only validated for unicast and multicast currently. */ /* Also valid for EVPN where the nexthop is an IP address. */ if (safi != SAFI_UNICAST && safi != SAFI_MULTICAST && safi != SAFI_EVPN) - return 0; + return false; /* If NEXT_HOP is present, validate it. */ if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) { if (attr->nexthop.s_addr == INADDR_ANY || IPV4_CLASS_DE(ntohl(attr->nexthop.s_addr)) || bgp_nexthop_self(bgp, afi, type, stype, attr, rn)) - return 1; + return true; } /* If MP_NEXTHOP is present, validate it. */ @@ -3244,7 +3251,7 @@ static int bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, break; default: - ret = 1; + ret = true; break; } } @@ -3252,7 +3259,7 @@ static int bgp_update_martian_nexthop(struct bgp *bgp, afi_t afi, safi_t safi, return ret; } -int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, +int bgp_update(struct peer *peer, const struct prefix *p, uint32_t addpath_id, struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, uint32_t num_labels, int soft_reconfig, @@ -4021,7 +4028,7 @@ filtered: return 0; } -int bgp_withdraw(struct peer *peer, struct prefix *p, uint32_t addpath_id, +int bgp_withdraw(struct peer *peer, const struct prefix *p, uint32_t addpath_id, struct attr *attr, afi_t afi, safi_t safi, int type, int sub_type, struct prefix_rd *prd, mpls_label_t *label, uint32_t num_labels, struct bgp_route_evpn *evpn) @@ -4603,30 +4610,30 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) } } -int bgp_outbound_policy_exists(struct peer *peer, struct bgp_filter *filter) +bool bgp_outbound_policy_exists(struct peer *peer, struct bgp_filter *filter) { if (peer->sort == BGP_PEER_IBGP) - return 1; + return true; if (peer->sort == BGP_PEER_EBGP && (ROUTE_MAP_OUT_NAME(filter) || PREFIX_LIST_OUT_NAME(filter) || FILTER_LIST_OUT_NAME(filter) || DISTRIBUTE_OUT_NAME(filter))) - return 1; - return 0; + return true; + return false; } -int bgp_inbound_policy_exists(struct peer *peer, struct bgp_filter *filter) +bool bgp_inbound_policy_exists(struct peer *peer, struct bgp_filter *filter) { if (peer->sort == BGP_PEER_IBGP) - return 1; + return true; if (peer->sort == BGP_PEER_EBGP && (ROUTE_MAP_IN_NAME(filter) || PREFIX_LIST_IN_NAME(filter) || FILTER_LIST_IN_NAME(filter) || DISTRIBUTE_IN_NAME(filter))) - return 1; - return 0; + return true; + return false; } static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table, @@ -6016,11 +6023,11 @@ static void bgp_aggregate_free(struct bgp_aggregate *aggregate) XFREE(MTYPE_BGP_AGGREGATE, aggregate); } -static int bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin, - struct aspath *aspath, - struct community *comm, - struct ecommunity *ecomm, - struct lcommunity *lcomm) +static bool bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin, + struct aspath *aspath, + struct community *comm, + struct ecommunity *ecomm, + struct lcommunity *lcomm) { static struct aspath *ae = NULL; @@ -6028,27 +6035,27 @@ static int bgp_aggregate_info_same(struct bgp_path_info *pi, uint8_t origin, ae = aspath_empty(); if (!pi) - return 0; + return false; if (origin != pi->attr->origin) - return 0; + return false; if (!aspath_cmp(pi->attr->aspath, (aspath) ? aspath : ae)) - return 0; + return false; if (!community_cmp(pi->attr->community, comm)) - return 0; + return false; if (!ecommunity_cmp(pi->attr->ecommunity, ecomm)) - return 0; + return false; if (!lcommunity_cmp(pi->attr->lcommunity, lcomm)) - return 0; + return false; if (!CHECK_FLAG(pi->flags, BGP_PATH_VALID)) - return 0; + return false; - return 1; + return true; } static void bgp_aggregate_install(struct bgp *bgp, afi_t afi, safi_t safi, @@ -6608,7 +6615,7 @@ static void bgp_remove_route_from_aggregate(struct bgp *bgp, afi_t afi, lcommunity, atomic_aggregate, aggregate); } -void bgp_aggregate_increment(struct bgp *bgp, struct prefix *p, +void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p, struct bgp_path_info *pi, afi_t afi, safi_t safi) { struct bgp_node *child; @@ -6641,7 +6648,7 @@ void bgp_aggregate_increment(struct bgp *bgp, struct prefix *p, bgp_unlock_node(child); } -void bgp_aggregate_decrement(struct bgp *bgp, struct prefix *p, +void bgp_aggregate_decrement(struct bgp *bgp, const struct prefix *p, struct bgp_path_info *del, afi_t afi, safi_t safi) { struct bgp_node *child; @@ -7337,7 +7344,7 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type, } /* Static function to display route. */ -static void route_vty_out_route(struct prefix *p, struct vty *vty, +static void route_vty_out_route(const struct prefix *p, struct vty *vty, json_object *json) { int len = 0; @@ -7494,7 +7501,7 @@ static char *bgp_nexthop_hostname(struct peer *peer, struct attr *attr) } /* called from terminal list command */ -void route_vty_out(struct vty *vty, struct prefix *p, +void route_vty_out(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, safi_t safi, json_object *json_paths) { @@ -8090,7 +8097,7 @@ void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr, vty_out(vty, "\n"); } -void route_vty_out_tag(struct vty *vty, struct prefix *p, +void route_vty_out_tag(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, safi_t safi, json_object *json) { @@ -8183,7 +8190,7 @@ void route_vty_out_tag(struct vty *vty, struct prefix *p, } } -void route_vty_out_overlay(struct vty *vty, struct prefix *p, +void route_vty_out_overlay(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, json_object *json_paths) { @@ -12291,7 +12298,7 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, } /* Apply BGP information to distance method. */ -uint8_t bgp_distance_apply(struct prefix *p, struct bgp_path_info *pinfo, +uint8_t bgp_distance_apply(const struct prefix *p, struct bgp_path_info *pinfo, afi_t afi, safi_t safi, struct bgp *bgp) { struct bgp_node *rn; diff --git a/bgpd/bgp_route.h b/bgpd/bgp_route.h index 0ad656d13..5f6a15891 100644 --- a/bgpd/bgp_route.h +++ b/bgpd/bgp_route.h @@ -467,6 +467,23 @@ static inline bool is_pi_family_matching(struct bgp_path_info *pi, return false; } +static inline void prep_for_rmap_apply(struct bgp_path_info *dst_pi, + struct bgp_path_info_extra *dst_pie, + struct bgp_node *rn, + struct bgp_path_info *src_pi, + struct peer *peer, struct attr *attr) +{ + memset(dst_pi, 0, sizeof(struct bgp_path_info)); + dst_pi->peer = peer; + dst_pi->attr = attr; + dst_pi->net = rn; + if (src_pi->extra) { + memcpy(dst_pie, src_pi->extra, + sizeof(struct bgp_path_info_extra)); + dst_pi->extra = dst_pie; + } +} + /* called before bgp_process() */ DECLARE_HOOK(bgp_process, (struct bgp *bgp, afi_t afi, safi_t safi, @@ -489,11 +506,11 @@ extern void bgp_clear_route(struct peer *, afi_t, safi_t); extern void bgp_clear_route_all(struct peer *); extern void bgp_clear_adj_in(struct peer *, afi_t, safi_t); extern void bgp_clear_stale_route(struct peer *, afi_t, safi_t); -extern int bgp_outbound_policy_exists(struct peer *, struct bgp_filter *); -extern int bgp_inbound_policy_exists(struct peer *, struct bgp_filter *); +extern bool bgp_outbound_policy_exists(struct peer *, struct bgp_filter *); +extern bool bgp_inbound_policy_exists(struct peer *, struct bgp_filter *); extern struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi, - safi_t safi, struct prefix *p, + safi_t safi, const struct prefix *p, struct prefix_rd *prd); extern struct bgp_path_info *bgp_path_info_lock(struct bgp_path_info *path); extern struct bgp_path_info *bgp_path_info_unlock(struct bgp_path_info *path); @@ -512,7 +529,7 @@ extern void bgp_path_info_path_with_addpath_rx_str(struct bgp_path_info *pi, extern int bgp_nlri_parse_ip(struct peer *, struct attr *, struct bgp_nlri *); -extern int bgp_maximum_prefix_overflow(struct peer *, afi_t, safi_t, int); +extern bool bgp_maximum_prefix_overflow(struct peer *, afi_t, safi_t, int); extern void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, const union g_addr *nexthop, ifindex_t ifindex, @@ -541,12 +558,17 @@ extern int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *, const char *, const char *, const char *); /* this is primarily for MPLS-VPN */ -extern int bgp_update(struct peer *, struct prefix *, uint32_t, struct attr *, - afi_t, safi_t, int, int, struct prefix_rd *, - mpls_label_t *, uint32_t, int, struct bgp_route_evpn *); -extern int bgp_withdraw(struct peer *, struct prefix *, uint32_t, struct attr *, - afi_t, safi_t, int, int, struct prefix_rd *, - mpls_label_t *, uint32_t, struct bgp_route_evpn *); +extern int bgp_update(struct peer *peer, const struct prefix *p, + uint32_t addpath_id, struct attr *attr, + afi_t afi, safi_t safi, int type, int sub_type, + struct prefix_rd *prd, mpls_label_t *label, + uint32_t num_labels, int soft_reconfig, + struct bgp_route_evpn *evpn); +extern int bgp_withdraw(struct peer *peer, const struct prefix *p, + uint32_t addpath_id, struct attr *attr, afi_t afi, + safi_t safi, int type, int sub_type, + struct prefix_rd *prd, mpls_label_t *label, + uint32_t num_labels, struct bgp_route_evpn *evpn); /* for bgp_nexthop and bgp_damp */ extern void bgp_process(struct bgp *, struct bgp_node *, afi_t, safi_t); @@ -566,15 +588,16 @@ extern void bgp_aggregate_delete(struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi, struct bgp_aggregate *aggregate); extern void bgp_aggregate_route(struct bgp *bgp, struct prefix *p, afi_t afi, safi_t safi, struct bgp_aggregate *aggregate); -extern void bgp_aggregate_increment(struct bgp *bgp, struct prefix *p, +extern void bgp_aggregate_increment(struct bgp *bgp, const struct prefix *p, struct bgp_path_info *path, afi_t afi, safi_t safi); -extern void bgp_aggregate_decrement(struct bgp *bgp, struct prefix *p, +extern void bgp_aggregate_decrement(struct bgp *bgp, const struct prefix *p, struct bgp_path_info *path, afi_t afi, safi_t safi); -extern uint8_t bgp_distance_apply(struct prefix *p, struct bgp_path_info *path, - afi_t afi, safi_t safi, struct bgp *bgp); +extern uint8_t bgp_distance_apply(const struct prefix *p, + struct bgp_path_info *path, afi_t afi, + safi_t safi, struct bgp *bgp); extern afi_t bgp_node_afi(struct vty *); extern safi_t bgp_node_safi(struct vty *); @@ -584,35 +607,35 @@ extern struct bgp_path_info *info_make(int type, int sub_type, struct peer *peer, struct attr *attr, struct bgp_node *rn); -extern void route_vty_out(struct vty *vty, struct prefix *p, +extern void route_vty_out(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, safi_t safi, json_object *json_paths); -extern void route_vty_out_tag(struct vty *vty, struct prefix *p, +extern void route_vty_out_tag(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, safi_t safi, json_object *json); extern void route_vty_out_tmp(struct vty *vty, struct prefix *p, struct attr *attr, safi_t safi, bool use_json, json_object *json_ar); -extern void route_vty_out_overlay(struct vty *vty, struct prefix *p, +extern void route_vty_out_overlay(struct vty *vty, const struct prefix *p, struct bgp_path_info *path, int display, json_object *json); -extern int subgroup_process_announce_selected(struct update_subgroup *subgrp, - struct bgp_path_info *selected, - struct bgp_node *rn, - uint32_t addpath_tx_id); +extern void subgroup_process_announce_selected(struct update_subgroup *subgrp, + struct bgp_path_info *selected, + struct bgp_node *rn, + uint32_t addpath_tx_id); -extern int subgroup_announce_check(struct bgp_node *rn, - struct bgp_path_info *pi, - struct update_subgroup *subgrp, - struct prefix *p, struct attr *attr); +extern bool subgroup_announce_check(struct bgp_node *rn, + struct bgp_path_info *pi, + struct update_subgroup *subgrp, + const struct prefix *p, struct attr *attr); extern void bgp_peer_clear_node_queue_drain_immediate(struct peer *peer); extern void bgp_process_queues_drain_immediate(void); /* for encap/vpn */ extern struct bgp_node *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi, - safi_t safi, struct prefix *p, + safi_t safi, const struct prefix *p, struct prefix_rd *prd); extern void bgp_path_info_restore(struct bgp_node *rn, struct bgp_path_info *path); @@ -629,8 +652,8 @@ extern void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, struct bgp_path_info_pair *result, afi_t afi, safi_t safi); extern void bgp_zebra_clear_route_change_flags(struct bgp_node *rn); -extern int bgp_zebra_has_route_changed(struct bgp_node *rn, - struct bgp_path_info *selected); +extern bool bgp_zebra_has_route_changed(struct bgp_node *rn, + struct bgp_path_info *selected); extern void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp, struct bgp_node *rn, diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index d50716105..5cf0b7398 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -858,7 +858,7 @@ static int bgpTrapEstablished(struct peer *peer) oid index[sizeof(oid) * IN_ADDR_SIZE]; /* Check if this peer just went to Established */ - if ((peer->last_major_event != OpenConfirm) || !(peer_established(peer))) + if ((peer->ostatus != OpenConfirm) || !(peer_established(peer))) return 0; ret = inet_aton(peer->host, &addr); diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c index 04181d38b..3d74128da 100644 --- a/bgpd/bgp_table.c +++ b/bgpd/bgp_table.c @@ -187,7 +187,8 @@ bgp_route_next_until_maxlen(struct bgp_node *node, const struct bgp_node *limit, return NULL; } -void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, +void bgp_table_range_lookup(const struct bgp_table *table, + const struct prefix *p, uint8_t maxlen, struct list *matches) { struct bgp_node *node = bgp_node_from_rnode(table->route_table->top); diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 69cca9eee..7b468cc03 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -217,7 +217,7 @@ static inline struct bgp_node *bgp_route_next_until(struct bgp_node *node, * bgp_node_get */ static inline struct bgp_node *bgp_node_get(struct bgp_table *const table, - struct prefix *p) + const struct prefix *p) { return bgp_node_from_rnode(route_node_get(table->route_table, p)); } @@ -226,7 +226,7 @@ static inline struct bgp_node *bgp_node_get(struct bgp_table *const table, * bgp_node_lookup */ static inline struct bgp_node * -bgp_node_lookup(const struct bgp_table *const table, struct prefix *p) +bgp_node_lookup(const struct bgp_table *const table, const struct prefix *p) { return bgp_node_from_rnode(route_node_lookup(table->route_table, p)); } @@ -243,7 +243,7 @@ static inline struct bgp_node *bgp_lock_node(struct bgp_node *node) * bgp_node_match */ static inline struct bgp_node *bgp_node_match(const struct bgp_table *table, - struct prefix *p) + const struct prefix *p) { return bgp_node_from_rnode(route_node_match(table->route_table, p)); } @@ -277,7 +277,7 @@ static inline unsigned long bgp_table_count(const struct bgp_table *const table) * bgp_table_get_next */ static inline struct bgp_node *bgp_table_get_next(const struct bgp_table *table, - struct prefix *p) + const struct prefix *p) { return bgp_node_from_rnode(route_table_get_next(table->route_table, p)); } @@ -347,7 +347,8 @@ static inline uint64_t bgp_table_version(struct bgp_table *table) return table->version; } -void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, +void bgp_table_range_lookup(const struct bgp_table *table, + const struct prefix *p, uint8_t maxlen, struct list *matches); diff --git a/bgpd/bgp_updgrp.c b/bgpd/bgp_updgrp.c index 50824cd6d..a29721988 100644 --- a/bgpd/bgp_updgrp.c +++ b/bgpd/bgp_updgrp.c @@ -831,17 +831,17 @@ void update_subgroup_inherit_info(struct update_subgroup *to, * * Returns true if the subgroup was deleted. */ -static int update_subgroup_check_delete(struct update_subgroup *subgrp) +static bool update_subgroup_check_delete(struct update_subgroup *subgrp) { if (!subgrp) - return 0; + return false; if (!LIST_EMPTY(&(subgrp->peers))) - return 0; + return false; update_subgroup_delete(subgrp); - return 1; + return true; } /* @@ -982,7 +982,7 @@ static struct update_subgroup *update_subgroup_find(struct update_group *updgrp, * Returns true if this subgroup is in a state that allows it to be * merged into another subgroup. */ -static int update_subgroup_ready_for_merge(struct update_subgroup *subgrp) +static bool update_subgroup_ready_for_merge(struct update_subgroup *subgrp) { /* @@ -990,13 +990,13 @@ static int update_subgroup_ready_for_merge(struct update_subgroup *subgrp) * out to peers. */ if (!bpacket_queue_is_empty(SUBGRP_PKTQ(subgrp))) - return 0; + return false; /* * Not ready if there enqueued updates waiting to be encoded. */ if (!advertise_list_is_empty(subgrp)) - return 0; + return false; /* * Don't attempt to merge a subgroup that needs a refresh. For one, @@ -1004,9 +1004,9 @@ static int update_subgroup_ready_for_merge(struct update_subgroup *subgrp) * another group. */ if (update_subgroup_needs_refresh(subgrp)) - return 0; + return false; - return 1; + return true; } /* @@ -1095,13 +1095,13 @@ static void update_subgroup_merge(struct update_subgroup *subgrp, * Returns true if the subgroup has been merged. The subgroup pointer * should not be accessed in this case. */ -int update_subgroup_check_merge(struct update_subgroup *subgrp, - const char *reason) +bool update_subgroup_check_merge(struct update_subgroup *subgrp, + const char *reason) { struct update_subgroup *target; if (!update_subgroup_ready_for_merge(subgrp)) - return 0; + return false; /* * Look for a subgroup to merge into. @@ -1112,10 +1112,10 @@ int update_subgroup_check_merge(struct update_subgroup *subgrp, } if (!target) - return 0; + return false; update_subgroup_merge(subgrp, target, reason); - return 1; + return true; } /* @@ -1143,14 +1143,14 @@ static int update_subgroup_merge_check_thread_cb(struct thread *thread) * * Returns true if a merge check will be performed shortly. */ -int update_subgroup_trigger_merge_check(struct update_subgroup *subgrp, - int force) +bool update_subgroup_trigger_merge_check(struct update_subgroup *subgrp, + int force) { if (subgrp->t_merge_check) - return 1; + return true; if (!force && !update_subgroup_ready_for_merge(subgrp)) - return 0; + return false; subgrp->t_merge_check = NULL; thread_add_timer_msec(bm->master, update_subgroup_merge_check_thread_cb, @@ -1158,7 +1158,7 @@ int update_subgroup_trigger_merge_check(struct update_subgroup *subgrp, SUBGRP_INCR_STAT(subgrp, merge_checks_triggered); - return 1; + return true; } /* @@ -1212,8 +1212,8 @@ static int update_subgroup_copy_packets(struct update_subgroup *dest, return count; } -static int updgrp_prefix_list_update(struct update_group *updgrp, - const char *name) +static bool updgrp_prefix_list_update(struct update_group *updgrp, + const char *name) { struct peer *peer; struct bgp_filter *filter; @@ -1225,13 +1225,13 @@ static int updgrp_prefix_list_update(struct update_group *updgrp, && (strcmp(name, PREFIX_LIST_OUT_NAME(filter)) == 0)) { PREFIX_LIST_OUT(filter) = prefix_list_lookup( UPDGRP_AFI(updgrp), PREFIX_LIST_OUT_NAME(filter)); - return 1; + return true; } - return 0; + return false; } -static int updgrp_filter_list_update(struct update_group *updgrp, - const char *name) +static bool updgrp_filter_list_update(struct update_group *updgrp, + const char *name) { struct peer *peer; struct bgp_filter *filter; @@ -1243,13 +1243,13 @@ static int updgrp_filter_list_update(struct update_group *updgrp, && (strcmp(name, FILTER_LIST_OUT_NAME(filter)) == 0)) { FILTER_LIST_OUT(filter) = as_list_lookup(FILTER_LIST_OUT_NAME(filter)); - return 1; + return true; } - return 0; + return false; } -static int updgrp_distribute_list_update(struct update_group *updgrp, - const char *name) +static bool updgrp_distribute_list_update(struct update_group *updgrp, + const char *name) { struct peer *peer; struct bgp_filter *filter; @@ -1261,9 +1261,9 @@ static int updgrp_distribute_list_update(struct update_group *updgrp, && (strcmp(name, DISTRIBUTE_OUT_NAME(filter)) == 0)) { DISTRIBUTE_OUT(filter) = access_list_lookup( UPDGRP_AFI(updgrp), DISTRIBUTE_OUT_NAME(filter)); - return 1; + return true; } - return 0; + return false; } static int updgrp_route_map_update(struct update_group *updgrp, diff --git a/bgpd/bgp_updgrp.h b/bgpd/bgp_updgrp.h index fe654bb3e..403ca139f 100644 --- a/bgpd/bgp_updgrp.h +++ b/bgpd/bgp_updgrp.h @@ -373,9 +373,9 @@ extern void update_subgroup_remove_peer(struct update_subgroup *, struct peer_af *); extern struct bgp_table *update_subgroup_rib(struct update_subgroup *); extern void update_subgroup_split_peer(struct peer_af *, struct update_group *); -extern int update_subgroup_check_merge(struct update_subgroup *, const char *); -extern int update_subgroup_trigger_merge_check(struct update_subgroup *, - int force); +extern bool update_subgroup_check_merge(struct update_subgroup *, const char *); +extern bool update_subgroup_trigger_merge_check(struct update_subgroup *, + int force); extern void update_group_policy_update(struct bgp *bgp, bgp_policy_type_e ptype, const char *pname, int route_update, int start_event); @@ -404,13 +404,13 @@ extern struct bpacket *bpacket_queue_first(struct bpacket_queue *q); struct bpacket *bpacket_queue_last(struct bpacket_queue *q); unsigned int bpacket_queue_length(struct bpacket_queue *q); unsigned int bpacket_queue_hwm_length(struct bpacket_queue *q); -int bpacket_queue_is_full(struct bgp *bgp, struct bpacket_queue *q); +bool bpacket_queue_is_full(struct bgp *bgp, struct bpacket_queue *q); extern void bpacket_queue_advance_peer(struct peer_af *paf); extern void bpacket_queue_remove_peer(struct peer_af *paf); extern void bpacket_add_peer(struct bpacket *pkt, struct peer_af *paf); unsigned int bpacket_queue_virtual_length(struct peer_af *paf); extern void bpacket_queue_show_vty(struct bpacket_queue *q, struct vty *vty); -int subgroup_packets_to_build(struct update_subgroup *subgrp); +bool subgroup_packets_to_build(struct update_subgroup *subgrp); extern struct bpacket *subgroup_update_packet(struct update_subgroup *s); extern struct bpacket *subgroup_withdraw_packet(struct update_subgroup *s); extern struct stream *bpacket_reformat_for_peer(struct bpacket *pkt, diff --git a/bgpd/bgp_updgrp_packet.c b/bgpd/bgp_updgrp_packet.c index 4dc9dfa39..6553211b0 100644 --- a/bgpd/bgp_updgrp_packet.c +++ b/bgpd/bgp_updgrp_packet.c @@ -226,11 +226,11 @@ unsigned int bpacket_queue_hwm_length(struct bpacket_queue *q) return q->hwm_count - 1; } -int bpacket_queue_is_full(struct bgp *bgp, struct bpacket_queue *q) +bool bpacket_queue_is_full(struct bgp *bgp, struct bpacket_queue *q) { if (q->curr_count >= bgp->default_subgroup_pkt_queue_max) - return 1; - return 0; + return true; + return false; } void bpacket_add_peer(struct bpacket *pkt, struct peer_af *paf) @@ -656,22 +656,22 @@ static void bpacket_attr_vec_arr_update(struct bpacket_attr_vec_arr *vecarr, /* * Return if there are packets to build for this subgroup. */ -int subgroup_packets_to_build(struct update_subgroup *subgrp) +bool subgroup_packets_to_build(struct update_subgroup *subgrp) { struct bgp_advertise *adv; if (!subgrp) - return 0; + return false; adv = bgp_adv_fifo_first(&subgrp->sync->withdraw); if (adv) - return 1; + return true; adv = bgp_adv_fifo_first(&subgrp->sync->update); if (adv) - return 1; + return true; - return 0; + return false; } /* Make BGP update packet. */ diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 8c751e4f1..3db9866a9 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -533,7 +533,7 @@ int bgp_vty_find_and_parse_afi_safi_bgp(struct vty *vty, return *idx; } -static int peer_address_self_check(struct bgp *bgp, union sockunion *su) +static bool peer_address_self_check(struct bgp *bgp, union sockunion *su) { struct interface *ifp = NULL; @@ -545,9 +545,9 @@ static int peer_address_self_check(struct bgp *bgp, union sockunion *su) bgp->vrf_id); if (ifp) - return 1; + return true; - return 0; + return false; } /* Utility function for looking up peer from VTY. */ @@ -14086,7 +14086,8 @@ static bool peergroup_filter_check(struct peer *peer, afi_t afi, safi_t safi, /* Return true if the addpath type is set for peer and different from * peer-group. */ -static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi) +static bool peergroup_af_addpath_check(struct peer *peer, afi_t afi, + safi_t safi) { enum bgp_addpath_strat type, g_type; @@ -14097,15 +14098,15 @@ static int peergroup_af_addpath_check(struct peer *peer, afi_t afi, safi_t safi) g_type = peer->group->conf->addpath_type[afi][safi]; if (type != g_type) - return 1; + return true; else - return 0; + return false; } - return 1; + return true; } - return 0; + return false; } /* This is part of the address-family block (unicast only) */ diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index f3ab60849..95b6548c7 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -66,19 +66,19 @@ struct zclient *zclient = NULL; /* Can we install into zebra? */ -static inline int bgp_install_info_to_zebra(struct bgp *bgp) +static inline bool bgp_install_info_to_zebra(struct bgp *bgp) { if (zclient->sock <= 0) - return 0; + return false; if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { zlog_debug( "%s: No zebra instance to talk to, not installing information", __func__); - return 0; + return false; } - return 1; + return true; } int zclient_num_connects; @@ -928,8 +928,8 @@ bgp_path_info_to_ipv6_nexthop(struct bgp_path_info *path, ifindex_t *ifindex) return nexthop; } -static int bgp_table_map_apply(struct route_map *map, struct prefix *p, - struct bgp_path_info *path) +static bool bgp_table_map_apply(struct route_map *map, const struct prefix *p, + struct bgp_path_info *path) { route_map_result_t ret; @@ -937,7 +937,7 @@ static int bgp_table_map_apply(struct route_map *map, struct prefix *p, bgp_attr_flush(path->attr); if (ret != RMAP_DENYMATCH) - return 1; + return true; if (bgp_debug_zebra(p)) { if (p->family == AF_INET) { @@ -965,7 +965,7 @@ static int bgp_table_map_apply(struct route_map *map, struct prefix *p, buf[1], sizeof(buf[1]))); } } - return 0; + return false; } static struct thread *bgp_tm_thread_connect; @@ -1058,12 +1058,10 @@ int bgp_zebra_get_table_range(uint32_t chunk_size, return 0; } -static int update_ipv4nh_for_route_install(int nh_othervrf, - struct bgp *nh_bgp, - struct in_addr *nexthop, - struct attr *attr, - bool is_evpn, - struct zapi_nexthop *api_nh) +static bool update_ipv4nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, + struct in_addr *nexthop, + struct attr *attr, bool is_evpn, + struct zapi_nexthop *api_nh) { api_nh->gate.ipv4 = *nexthop; api_nh->vrf_id = nh_bgp->vrf_id; @@ -1083,15 +1081,16 @@ static int update_ipv4nh_for_route_install(int nh_othervrf, } else api_nh->type = NEXTHOP_TYPE_IPV4; - return 1; + return true; } -static int -update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, - struct in6_addr *nexthop, - ifindex_t ifindex, struct bgp_path_info *pi, - struct bgp_path_info *best_pi, bool is_evpn, - struct zapi_nexthop *api_nh) +static bool update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, + struct in6_addr *nexthop, + ifindex_t ifindex, + struct bgp_path_info *pi, + struct bgp_path_info *best_pi, + bool is_evpn, + struct zapi_nexthop *api_nh) { struct attr *attr; @@ -1108,7 +1107,7 @@ update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, api_nh->ifindex = attr->nh_ifindex; } else if (IN6_IS_ADDR_LINKLOCAL(nexthop)) { if (ifindex == 0) - return 0; + return false; api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; api_nh->ifindex = ifindex; } else { @@ -1136,7 +1135,7 @@ update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, } if (ifindex == 0) - return 0; + return false; api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; api_nh->ifindex = ifindex; } else { @@ -1146,10 +1145,10 @@ update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, } api_nh->gate.ipv6 = *nexthop; - return 1; + return true; } -void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, +void bgp_zebra_announce(struct bgp_node *rn, const struct prefix *p, struct bgp_path_info *info, struct bgp *bgp, afi_t afi, safi_t safi) { @@ -1485,7 +1484,7 @@ void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi) safi); } -void bgp_zebra_withdraw(struct prefix *p, struct bgp_path_info *info, +void bgp_zebra_withdraw(const struct prefix *p, struct bgp_path_info *info, struct bgp *bgp, safi_t safi) { struct zapi_route api; @@ -1660,11 +1659,11 @@ int bgp_redistribute_resend(struct bgp *bgp, afi_t afi, int type, } /* Redistribute with route-map specification. */ -int bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, - struct route_map *route_map) +bool bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, + struct route_map *route_map) { if (red->rmap.name && (strcmp(red->rmap.name, name) == 0)) - return 0; + return false; XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name); /* Decrement the count for existing routemap and @@ -1675,18 +1674,18 @@ int bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, red->rmap.map = route_map; route_map_counter_increment(red->rmap.map); - return 1; + return true; } /* Redistribute with metric specification. */ -int bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, - afi_t afi, int type, uint32_t metric) +bool bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, + afi_t afi, int type, uint32_t metric) { struct bgp_node *rn; struct bgp_path_info *pi; if (red->redist_metric_flag && red->redist_metric == metric) - return 0; + return false; red->redist_metric_flag = 1; red->redist_metric = metric; @@ -1713,7 +1712,7 @@ int bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, } } - return 1; + return true; } /* Unset redistribution. */ diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 5a02e2fbf..e546cd5da 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -32,12 +32,13 @@ extern void bgp_zebra_destroy(void); extern int bgp_zebra_get_table_range(uint32_t chunk_size, uint32_t *start, uint32_t *end); extern int bgp_if_update_all(void); -extern void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, +extern void bgp_zebra_announce(struct bgp_node *rn, const struct prefix *p, struct bgp_path_info *path, struct bgp *bgp, afi_t afi, safi_t safi); extern void bgp_zebra_announce_table(struct bgp *, afi_t, safi_t); -extern void bgp_zebra_withdraw(struct prefix *p, struct bgp_path_info *path, - struct bgp *bgp, safi_t safi); +extern void bgp_zebra_withdraw(const struct prefix *p, + struct bgp_path_info *path, struct bgp *bgp, + safi_t safi); extern void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer); extern void bgp_zebra_terminate_radv(struct bgp *bgp, struct peer *peer); @@ -53,10 +54,10 @@ extern struct bgp_redist *bgp_redist_add(struct bgp *, afi_t, uint8_t, extern int bgp_redistribute_set(struct bgp *, afi_t, int, unsigned short, bool changed); extern int bgp_redistribute_resend(struct bgp *, afi_t, int, unsigned short); -extern int bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, - struct route_map *route_map); -extern int bgp_redistribute_metric_set(struct bgp *, struct bgp_redist *, afi_t, - int, uint32_t); +extern bool bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, + struct route_map *route_map); +extern bool bgp_redistribute_metric_set(struct bgp *, struct bgp_redist *, + afi_t, int, uint32_t); extern int bgp_redistribute_unset(struct bgp *, afi_t, int, unsigned short); extern int bgp_redistribute_unreg(struct bgp *, afi_t, int, unsigned short); diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index 267d67e46..945277010 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -320,13 +320,12 @@ void bgp_router_id_zebra_bump(vrf_id_t vrf_id, const struct prefix *router_id) } } -int bgp_router_id_static_set(struct bgp *bgp, struct in_addr id) +void bgp_router_id_static_set(struct bgp *bgp, struct in_addr id) { bgp->router_id_static = id; bgp_router_id_set(bgp, id.s_addr != INADDR_ANY ? &id : &bgp->router_id_zebra, true /* is config */); - return 0; } /* BGP's cluster-id control. */ @@ -393,25 +392,21 @@ time_t bgp_clock(void) } /* BGP timer configuration. */ -int bgp_timers_set(struct bgp *bgp, uint32_t keepalive, uint32_t holdtime, - uint32_t connect_retry) +void bgp_timers_set(struct bgp *bgp, uint32_t keepalive, uint32_t holdtime, + uint32_t connect_retry) { bgp->default_keepalive = (keepalive < holdtime / 3 ? keepalive : holdtime / 3); bgp->default_holdtime = holdtime; bgp->default_connect_retry = connect_retry; - - return 0; } /* mostly for completeness - CLI uses its own defaults */ -int bgp_timers_unset(struct bgp *bgp) +void bgp_timers_unset(struct bgp *bgp) { bgp->default_keepalive = BGP_DEFAULT_KEEPALIVE; bgp->default_holdtime = BGP_DEFAULT_HOLDTIME; bgp->default_connect_retry = BGP_DEFAULT_CONNECT_RETRY; - - return 0; } /* BGP confederation configuration. */ @@ -499,18 +494,18 @@ int bgp_confederation_id_unset(struct bgp *bgp) } /* Is an AS part of the confed or not? */ -int bgp_confederation_peers_check(struct bgp *bgp, as_t as) +bool bgp_confederation_peers_check(struct bgp *bgp, as_t as) { int i; if (!bgp) - return 0; + return false; for (i = 0; i < bgp->confed_peers_cnt; i++) if (bgp->confed_peers[i] == as) - return 1; + return true; - return 0; + return false; } /* Add an AS to the confederation set. */ @@ -1415,8 +1410,8 @@ static int bgp_peer_conf_if_to_su_update_v4(struct peer *peer, return 0; } -static int bgp_peer_conf_if_to_su_update_v6(struct peer *peer, - struct interface *ifp) +static bool bgp_peer_conf_if_to_su_update_v6(struct peer *peer, + struct interface *ifp) { struct nbr_connected *ifc_nbr; @@ -1430,10 +1425,10 @@ static int bgp_peer_conf_if_to_su_update_v6(struct peer *peer, peer->su.sin6.sin6_len = sizeof(struct sockaddr_in6); #endif peer->su.sin6.sin6_scope_id = ifp->ifindex; - return 1; + return true; } - return 0; + return false; } /* @@ -2084,18 +2079,18 @@ int peer_activate(struct peer *peer, afi_t afi, safi_t safi) return ret; } -static int non_peergroup_deactivate_af(struct peer *peer, afi_t afi, - safi_t safi) +static bool non_peergroup_deactivate_af(struct peer *peer, afi_t afi, + safi_t safi) { if (CHECK_FLAG(peer->sflags, PEER_STATUS_GROUP)) { flog_err(EC_BGP_PEER_GROUP, "%s was called for peer-group %s", __func__, peer->host); - return 1; + return true; } /* Nothing to do if we've already deactivated this peer */ if (!peer->afc[afi][safi]) - return 0; + return false; /* De-activate the address family configuration. */ peer->afc[afi][safi] = 0; @@ -2104,7 +2099,7 @@ static int non_peergroup_deactivate_af(struct peer *peer, afi_t afi, flog_err(EC_BGP_PEER_DELETE, "couldn't delete af structure for peer %s(%s, %s)", peer->host, afi2str(afi), safi2str(safi)); - return 1; + return true; } if (peer->status == Established) { @@ -2130,7 +2125,7 @@ static int non_peergroup_deactivate_af(struct peer *peer, afi_t afi, } } - return 0; + return false; } int peer_deactivate(struct peer *peer, afi_t afi, safi_t safi) @@ -2547,15 +2542,14 @@ int peer_group_remote_as(struct bgp *bgp, const char *group_name, as_t *as, return 0; } -int peer_notify_unconfig(struct peer *peer) +void peer_notify_unconfig(struct peer *peer) { if (BGP_IS_VALID_STATE_FOR_NOTIF(peer->status)) bgp_notify_send(peer, BGP_NOTIFY_CEASE, BGP_NOTIFY_CEASE_PEER_UNCONFIG); - return 0; } -int peer_group_notify_unconfig(struct peer_group *group) +void peer_group_notify_unconfig(struct peer_group *group) { struct peer *peer, *other; struct listnode *node, *nnode; @@ -2568,7 +2562,6 @@ int peer_group_notify_unconfig(struct peer_group *group) } else peer_notify_unconfig(peer); } - return 0; } int peer_group_delete(struct peer_group *group) @@ -3771,10 +3764,10 @@ static void peer_drop_dynamic_neighbor(struct peer *peer) } /* If peer is configured at least one address family return 1. */ -int peer_active(struct peer *peer) +bool peer_active(struct peer *peer) { if (BGP_PEER_SU_UNSPEC(peer)) - return 0; + return false; if (peer->afc[AFI_IP][SAFI_UNICAST] || peer->afc[AFI_IP][SAFI_MULTICAST] || peer->afc[AFI_IP][SAFI_LABELED_UNICAST] || peer->afc[AFI_IP][SAFI_MPLS_VPN] || peer->afc[AFI_IP][SAFI_ENCAP] @@ -3786,12 +3779,12 @@ int peer_active(struct peer *peer) || peer->afc[AFI_IP6][SAFI_ENCAP] || peer->afc[AFI_IP6][SAFI_FLOWSPEC] || peer->afc[AFI_L2VPN][SAFI_EVPN]) - return 1; - return 0; + return true; + return false; } /* If peer is negotiated at least one address family return 1. */ -int peer_active_nego(struct peer *peer) +bool peer_active_nego(struct peer *peer) { if (peer->afc_nego[AFI_IP][SAFI_UNICAST] || peer->afc_nego[AFI_IP][SAFI_MULTICAST] @@ -3806,8 +3799,8 @@ int peer_active_nego(struct peer *peer) || peer->afc_nego[AFI_IP6][SAFI_ENCAP] || peer->afc_nego[AFI_IP6][SAFI_FLOWSPEC] || peer->afc_nego[AFI_L2VPN][SAFI_EVPN]) - return 1; - return 0; + return true; + return false; } void peer_change_action(struct peer *peer, afi_t afi, safi_t safi, @@ -4308,18 +4301,16 @@ int peer_af_flag_unset(struct peer *peer, afi_t afi, safi_t safi, uint32_t flag) } -int peer_tx_shutdown_message_set(struct peer *peer, const char *msg) +void peer_tx_shutdown_message_set(struct peer *peer, const char *msg) { XFREE(MTYPE_PEER_TX_SHUTDOWN_MSG, peer->tx_shutdown_message); peer->tx_shutdown_message = msg ? XSTRDUP(MTYPE_PEER_TX_SHUTDOWN_MSG, msg) : NULL; - return 0; } -int peer_tx_shutdown_message_unset(struct peer *peer) +void peer_tx_shutdown_message_unset(struct peer *peer) { XFREE(MTYPE_PEER_TX_SHUTDOWN_MSG, peer->tx_shutdown_message); - return 0; } @@ -4426,20 +4417,16 @@ int peer_ebgp_multihop_unset(struct peer *peer) } /* Neighbor description. */ -int peer_description_set(struct peer *peer, const char *desc) +void peer_description_set(struct peer *peer, const char *desc) { XFREE(MTYPE_PEER_DESC, peer->desc); peer->desc = XSTRDUP(MTYPE_PEER_DESC, desc); - - return 0; } -int peer_description_unset(struct peer *peer) +void peer_description_unset(struct peer *peer) { XFREE(MTYPE_PEER_DESC, peer->desc); - - return 0; } /* Neighbor update-source. */ @@ -4789,16 +4776,14 @@ int peer_default_originate_unset(struct peer *peer, afi_t afi, safi_t safi) return 0; } -int peer_port_set(struct peer *peer, uint16_t port) +void peer_port_set(struct peer *peer, uint16_t port) { peer->port = port; - return 0; } -int peer_port_unset(struct peer *peer) +void peer_port_unset(struct peer *peer) { peer->port = BGP_PORT_DEFAULT; - return 0; } /* diff --git a/bgpd/bgpd.h b/bgpd/bgpd.h index 769ac3265..2b67a39ef 100644 --- a/bgpd/bgpd.h +++ b/bgpd/bgpd.h @@ -838,6 +838,37 @@ struct bgp_peer_gr { bgp_peer_gr_action_ptr action_fun; }; +/* BGP finite state machine events. */ +enum bgp_fsm_events { + BGP_Start = 1, + BGP_Stop, + TCP_connection_open, + TCP_connection_closed, + TCP_connection_open_failed, + TCP_fatal_error, + ConnectRetry_timer_expired, + Hold_Timer_expired, + KeepAlive_timer_expired, + Receive_OPEN_message, + Receive_KEEPALIVE_message, + Receive_UPDATE_message, + Receive_NOTIFICATION_message, + Clearing_Completed, + BGP_EVENTS_MAX, +}; + +/* BGP finite state machine status. */ +enum bgp_fsm_status { + Idle = 1, + Connect, + Active, + OpenSent, + OpenConfirm, + Established, + Clearing, + Deleted, + BGP_STATUS_MAX, +}; /* BGP neighbor structure. */ struct peer { @@ -896,15 +927,15 @@ struct peer { struct peer *doppelganger; /* Status of the peer. */ - int status; - int ostatus; + enum bgp_fsm_status status; + enum bgp_fsm_status ostatus; /* FSM events, stored for debug purposes. * Note: uchar used for reduced memory usage. */ - unsigned char cur_event; - unsigned char last_event; - unsigned char last_major_event; + enum bgp_fsm_events cur_event; + enum bgp_fsm_events last_event; + enum bgp_fsm_events last_major_event; /* Peer index, used for dumping TABLE_DUMP_V2 format */ uint16_t table_dump_index; @@ -1550,34 +1581,6 @@ struct bgp_nlri { #define BGP_NOTIFY_CAPABILITY_INVALID_LENGTH 2 #define BGP_NOTIFY_CAPABILITY_MALFORMED_CODE 3 -/* BGP finite state machine status. */ -#define Idle 1 -#define Connect 2 -#define Active 3 -#define OpenSent 4 -#define OpenConfirm 5 -#define Established 6 -#define Clearing 7 -#define Deleted 8 -#define BGP_STATUS_MAX 9 - -/* BGP finite state machine events. */ -#define BGP_Start 1 -#define BGP_Stop 2 -#define TCP_connection_open 3 -#define TCP_connection_closed 4 -#define TCP_connection_open_failed 5 -#define TCP_fatal_error 6 -#define ConnectRetry_timer_expired 7 -#define Hold_Timer_expired 8 -#define KeepAlive_timer_expired 9 -#define Receive_OPEN_message 10 -#define Receive_KEEPALIVE_message 11 -#define Receive_UPDATE_message 12 -#define Receive_NOTIFICATION_message 13 -#define Clearing_Completed 14 -#define BGP_EVENTS_MAX 15 - /* BGP timers default value. */ #define BGP_INIT_START_TIMER 1 /* The following 3 are RFC defaults that are overridden in bgp_vty.c with @@ -1739,8 +1742,8 @@ extern struct peer *peer_unlock_with_caller(const char *, struct peer *); extern bgp_peer_sort_t peer_sort(struct peer *peer); extern bgp_peer_sort_t peer_sort_lookup(struct peer *peer); -extern int peer_active(struct peer *); -extern int peer_active_nego(struct peer *); +extern bool peer_active(struct peer *); +extern bool peer_active_nego(struct peer *); extern void bgp_recalculate_all_bestpaths(struct bgp *bgp); extern struct peer *peer_create(union sockunion *, const char *, struct bgp *, as_t, as_t, int, afi_t, safi_t, @@ -1774,21 +1777,21 @@ extern int bgp_handle_socket(struct bgp *bgp, struct vrf *vrf, vrf_id_t old_vrf_id, bool create); extern void bgp_router_id_zebra_bump(vrf_id_t, const struct prefix *); -extern int bgp_router_id_static_set(struct bgp *, struct in_addr); +extern void bgp_router_id_static_set(struct bgp *, struct in_addr); extern int bgp_cluster_id_set(struct bgp *, struct in_addr *); extern int bgp_cluster_id_unset(struct bgp *); extern int bgp_confederation_id_set(struct bgp *, as_t); extern int bgp_confederation_id_unset(struct bgp *); -extern int bgp_confederation_peers_check(struct bgp *, as_t); +extern bool bgp_confederation_peers_check(struct bgp *, as_t); extern int bgp_confederation_peers_add(struct bgp *, as_t); extern int bgp_confederation_peers_remove(struct bgp *, as_t); -extern int bgp_timers_set(struct bgp *, uint32_t keepalive, uint32_t holdtime, - uint32_t connect_retry); -extern int bgp_timers_unset(struct bgp *); +extern void bgp_timers_set(struct bgp *, uint32_t keepalive, uint32_t holdtime, + uint32_t connect_retry); +extern void bgp_timers_unset(struct bgp *); extern int bgp_default_local_preference_set(struct bgp *, uint32_t); extern int bgp_default_local_preference_unset(struct bgp *); @@ -1799,19 +1802,19 @@ extern int bgp_default_subgroup_pkt_queue_max_unset(struct bgp *bgp); extern int bgp_listen_limit_set(struct bgp *, int); extern int bgp_listen_limit_unset(struct bgp *); -extern int bgp_update_delay_active(struct bgp *); -extern int bgp_update_delay_configured(struct bgp *); +extern bool bgp_update_delay_active(struct bgp *); +extern bool bgp_update_delay_configured(struct bgp *); extern int bgp_afi_safi_peer_exists(struct bgp *bgp, afi_t afi, safi_t safi); extern void peer_as_change(struct peer *, as_t, int); extern int peer_remote_as(struct bgp *, union sockunion *, const char *, as_t *, int, afi_t, safi_t); extern int peer_group_remote_as(struct bgp *, const char *, as_t *, int); extern int peer_delete(struct peer *peer); -extern int peer_notify_unconfig(struct peer *peer); +extern void peer_notify_unconfig(struct peer *peer); extern int peer_group_delete(struct peer_group *); extern int peer_group_remote_as_delete(struct peer_group *); extern int peer_group_listen_range_add(struct peer_group *, struct prefix *); -extern int peer_group_notify_unconfig(struct peer_group *group); +extern void peer_group_notify_unconfig(struct peer_group *group); extern int peer_activate(struct peer *, afi_t, safi_t); extern int peer_deactivate(struct peer *, afi_t, safi_t); @@ -1836,8 +1839,8 @@ extern int peer_ebgp_multihop_set(struct peer *, int); extern int peer_ebgp_multihop_unset(struct peer *); extern int is_ebgp_multihop_configured(struct peer *peer); -extern int peer_description_set(struct peer *, const char *); -extern int peer_description_unset(struct peer *); +extern void peer_description_set(struct peer *, const char *); +extern void peer_description_unset(struct peer *); extern int peer_update_source_if_set(struct peer *, const char *); extern int peer_update_source_addr_set(struct peer *, const union sockunion *); @@ -1848,8 +1851,8 @@ extern int peer_default_originate_set(struct peer *peer, afi_t afi, safi_t safi, struct route_map *route_map); extern int peer_default_originate_unset(struct peer *, afi_t, safi_t); -extern int peer_port_set(struct peer *, uint16_t); -extern int peer_port_unset(struct peer *); +extern void peer_port_set(struct peer *, uint16_t); +extern void peer_port_unset(struct peer *); extern int peer_weight_set(struct peer *, afi_t, safi_t, uint16_t); extern int peer_weight_unset(struct peer *, afi_t, safi_t); @@ -1906,8 +1909,8 @@ extern int peer_clear_soft(struct peer *, afi_t, safi_t, enum bgp_clear_type); extern int peer_ttl_security_hops_set(struct peer *, int); extern int peer_ttl_security_hops_unset(struct peer *); -extern int peer_tx_shutdown_message_set(struct peer *, const char *msg); -extern int peer_tx_shutdown_message_unset(struct peer *); +extern void peer_tx_shutdown_message_set(struct peer *, const char *msg); +extern void peer_tx_shutdown_message_unset(struct peer *); extern int bgp_route_map_update_timer(struct thread *thread); extern void bgp_route_map_terminate(void); diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index d87292f65..435b61edf 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -355,7 +355,7 @@ int rfapi_check(void *handle) void del_vnc_route(struct rfapi_descriptor *rfd, struct peer *peer, /* rfd->peer for RFP regs */ - struct bgp *bgp, safi_t safi, struct prefix *p, + struct bgp *bgp, safi_t safi, const struct prefix *p, struct prefix_rd *prd, uint8_t type, uint8_t sub_type, struct rfapi_nexthop *lnh, int kill) { @@ -557,7 +557,7 @@ void rfapi_vn_options_free(struct rfapi_vn_option *p) /* Based on bgp_redistribute_add() */ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ - struct bgp *bgp, int safi, struct prefix *p, + struct bgp *bgp, int safi, const struct prefix *p, struct prefix_rd *prd, struct rfapi_ip_addr *nexthop, uint32_t *local_pref, uint32_t *lifetime, /* NULL => dont send lifetime */ diff --git a/bgpd/rfapi/rfapi_ap.c b/bgpd/rfapi/rfapi_ap.c index c5fda15d3..abb18aeb2 100644 --- a/bgpd/rfapi/rfapi_ap.c +++ b/bgpd/rfapi/rfapi_ap.c @@ -81,10 +81,10 @@ * is used to spread out the sort for adbs with the same lifetime * and thereby make the skip list operations more efficient. */ -static int sl_adb_lifetime_cmp(void *adb1, void *adb2) +static int sl_adb_lifetime_cmp(const void *adb1, const void *adb2) { - struct rfapi_adb *a1 = adb1; - struct rfapi_adb *a2 = adb2; + const struct rfapi_adb *a1 = adb1; + const struct rfapi_adb *a2 = adb2; if (a1->lifetime < a2->lifetime) return -1; diff --git a/bgpd/rfapi/rfapi_backend.h b/bgpd/rfapi/rfapi_backend.h index 96e464d2a..4facc31c6 100644 --- a/bgpd/rfapi/rfapi_backend.h +++ b/bgpd/rfapi/rfapi_backend.h @@ -35,16 +35,16 @@ extern void rfapi_delete(struct bgp *); struct rfapi *bgp_rfapi_new(struct bgp *bgp); void bgp_rfapi_destroy(struct bgp *bgp, struct rfapi *h); -extern void rfapiProcessUpdate(struct peer *peer, void *rfd, struct prefix *p, - struct prefix_rd *prd, struct attr *attr, - afi_t afi, safi_t safi, uint8_t type, - uint8_t sub_type, uint32_t *label); +extern void rfapiProcessUpdate(struct peer *peer, void *rfd, + const struct prefix *p, struct prefix_rd *prd, + struct attr *attr, afi_t afi, safi_t safi, + uint8_t type, uint8_t sub_type, uint32_t *label); -extern void rfapiProcessWithdraw(struct peer *peer, void *rfd, struct prefix *p, - struct prefix_rd *prd, struct attr *attr, - afi_t afi, safi_t safi, uint8_t type, - int kill); +extern void rfapiProcessWithdraw(struct peer *peer, void *rfd, + const struct prefix *p, struct prefix_rd *prd, + struct attr *attr, afi_t afi, safi_t safi, + uint8_t type, int kill); extern void rfapiProcessPeerDown(struct peer *peer); @@ -56,7 +56,7 @@ extern void vnc_zebra_withdraw(struct prefix *p, struct bgp_path_info *old_select); -extern void rfapi_vty_out_vncinfo(struct vty *vty, struct prefix *p, +extern void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p, struct bgp_path_info *bpi, safi_t safi); diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 2f274015f..4d7fccbe9 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -663,14 +663,17 @@ rfapiMonitorMoveShorter(struct agg_node *original_vpn_node, int lockoffset) * If no less-specific routes, try to use the 0/0 node */ if (!par) { + const struct prefix *p; /* this isn't necessarily 0/0 */ par = agg_route_table_top(original_vpn_node); + if (par) + p = agg_node_get_prefix(par); /* * If we got the top node but it wasn't 0/0, * ignore it */ - if (par && par->p.prefixlen) { + if (par && p->prefixlen) { agg_unlock_node(par); /* maybe free */ par = NULL; } @@ -685,9 +688,10 @@ rfapiMonitorMoveShorter(struct agg_node *original_vpn_node, int lockoffset) */ if (!par) { struct prefix pfx_default; + const struct prefix *p = agg_node_get_prefix(original_vpn_node); memset(&pfx_default, 0, sizeof(pfx_default)); - pfx_default.family = original_vpn_node->p.family; + pfx_default.family = p->family; /* creates default node if none exists */ par = agg_node_get(agg_get_table(original_vpn_node), @@ -768,6 +772,7 @@ static void rfapiMonitorMoveLonger(struct agg_node *new_vpn_node) struct rfapi_monitor_vpn *mlast; struct bgp_path_info *bpi; struct agg_node *par; + const struct prefix *new_vpn_node_p = agg_node_get_prefix(new_vpn_node); RFAPI_CHECK_REFCOUNT(new_vpn_node, SAFI_MPLS_VPN, 0); @@ -808,12 +813,11 @@ static void rfapiMonitorMoveLonger(struct agg_node *new_vpn_node) * specific updated node */ for (mlast = NULL, monitor = RFAPI_MONITOR_VPN(par); monitor;) { - /* * If new longest match for monitor prefix is the new * route's prefix, move monitor to new route's prefix */ - if (prefix_match(&new_vpn_node->p, &monitor->p)) { + if (prefix_match(new_vpn_node_p, &monitor->p)) { /* detach */ if (mlast) { mlast->next = monitor->next; @@ -1040,7 +1044,7 @@ int rfapiEcommunityGetEthernetTag(struct ecommunity *ecom, uint16_t *tag_id) for (i = 0; i < ecom->size; ++i) { as_t as = 0; int encode = 0; - uint8_t *p = ecom->val + (i * ECOMMUNITY_SIZE); + const uint8_t *p = ecom->val + (i * ECOMMUNITY_SIZE); /* High-order octet of type. */ encode = *p++; @@ -1266,6 +1270,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, { struct rfapi_next_hop_entry *new; int have_vnc_tunnel_un = 0; + const struct prefix *p = agg_node_get_prefix(rn); #ifdef DEBUG_ENCAP_MONITOR vnc_zlog_debug_verbose("%s: entry, bpi %p, rn %p", __func__, bpi, rn); @@ -1289,8 +1294,7 @@ rfapiRouteInfo2NextHopEntry(struct rfapi_ip_prefix *rprefix, vo->type = RFAPI_VN_OPTION_TYPE_L2ADDR; - memcpy(&vo->v.l2addr.macaddr, &rn->p.u.prefix_eth.octet, - ETH_ALEN); + memcpy(&vo->v.l2addr.macaddr, &p->u.prefix_eth.octet, ETH_ALEN); /* only low 3 bytes of this are significant */ (void)rfapiEcommunityGetLNI(bpi->attr->ecommunity, &vo->v.l2addr.logical_net_id); @@ -1493,7 +1497,8 @@ static int rfapiNhlAddNodeRoutes( struct prefix pfx_un; struct skiplist *seen_nexthops; int count = 0; - int is_l2 = (rn->p.family == AF_ETHERNET); + const struct prefix *p = agg_node_get_prefix(rn); + int is_l2 = (p->family == AF_ETHERNET); if (rfd_rib_node) { struct agg_table *atable = agg_get_table(rfd_rib_node); @@ -1626,14 +1631,14 @@ static int rfapiNhlAddSubtree( * hands in node->link */ if (agg_node_left(rn) && agg_node_left(rn) != omit_node) { if (agg_node_left(rn)->info) { + const struct prefix *p = + agg_node_get_prefix(agg_node_left(rn)); int count = 0; struct agg_node *rib_rn = NULL; - rfapiQprefix2Rprefix(&agg_node_left(rn)->p, &rprefix); - if (rfd_rib_table) { - rib_rn = agg_node_get(rfd_rib_table, - &agg_node_left(rn)->p); - } + rfapiQprefix2Rprefix(p, &rprefix); + if (rfd_rib_table) + rib_rn = agg_node_get(rfd_rib_table, p); count = rfapiNhlAddNodeRoutes( agg_node_left(rn), &rprefix, lifetime, 0, head, @@ -1653,14 +1658,15 @@ static int rfapiNhlAddSubtree( if (agg_node_right(rn) && agg_node_right(rn) != omit_node) { if (agg_node_right(rn)->info) { + const struct prefix *p = + agg_node_get_prefix(agg_node_right(rn)); int count = 0; struct agg_node *rib_rn = NULL; - rfapiQprefix2Rprefix(&agg_node_right(rn)->p, &rprefix); - if (rfd_rib_table) { - rib_rn = agg_node_get(rfd_rib_table, - &agg_node_right(rn)->p); - } + rfapiQprefix2Rprefix(p, &rprefix); + if (rfd_rib_table) + rib_rn = agg_node_get(rfd_rib_table, p); + count = rfapiNhlAddNodeRoutes( agg_node_right(rn), &rprefix, lifetime, 0, head, tail, exclude_vnaddr, rib_rn, @@ -1712,23 +1718,18 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( struct rfapi_next_hop_entry *answer = NULL; struct rfapi_next_hop_entry *last = NULL; struct agg_node *parent; + const struct prefix *p = agg_node_get_prefix(rn); int count = 0; struct agg_node *rib_rn; #ifdef DEBUG_RETURNED_NHL - { - char buf[PREFIX_STRLEN]; - - prefix2str(&rn->p, buf, sizeof(buf)); - vnc_zlog_debug_verbose("%s: called with node pfx=%s", __func__, - buf); - } + vnc_zlog_debug_verbose("%s: called with node pfx=%rRN", __func__, rn); rfapiDebugBacktrace(); #endif - rfapiQprefix2Rprefix(&rn->p, &rprefix); + rfapiQprefix2Rprefix(p, &rprefix); - rib_rn = rfd_rib_table ? agg_node_get(rfd_rib_table, &rn->p) : NULL; + rib_rn = rfd_rib_table ? agg_node_get(rfd_rib_table, p) : NULL; /* * Add non-withdrawn routes at this node @@ -1780,9 +1781,10 @@ struct rfapi_next_hop_entry *rfapiRouteNode2NextHopList( * Add non-withdrawn routes from less-specific prefix */ if (parent) { - rib_rn = rfd_rib_table ? agg_node_get(rfd_rib_table, &parent->p) - : NULL; - rfapiQprefix2Rprefix(&parent->p, &rprefix); + const struct prefix *p = agg_node_get_prefix(parent); + + rib_rn = rfd_rib_table ? agg_node_get(rfd_rib_table, p) : NULL; + rfapiQprefix2Rprefix(p, &rprefix); count += rfapiNhlAddNodeRoutes(parent, &rprefix, lifetime, 0, &answer, &last, exclude_vnaddr, rib_rn, pfx_target_original); @@ -1863,7 +1865,9 @@ struct rfapi_next_hop_entry *rfapiEthRouteNode2NextHopList( struct rfapi_next_hop_entry *last = NULL; struct agg_node *rib_rn; - rib_rn = rfd_rib_table ? agg_node_get(rfd_rib_table, &rn->p) : NULL; + rib_rn = rfd_rib_table + ? agg_node_get(rfd_rib_table, agg_node_get_prefix(rn)) + : NULL; count = rfapiNhlAddNodeRoutes(rn, rprefix, lifetime, 0, &answer, &last, NULL, rib_rn, pfx_target_original); @@ -2006,10 +2010,10 @@ static void rfapiBgpInfoDetach(struct agg_node *rn, struct bgp_path_info *bpi) /* * For L3-indexed import tables */ -static int rfapi_bi_peer_rd_cmp(void *b1, void *b2) +static int rfapi_bi_peer_rd_cmp(const void *b1, const void *b2) { - struct bgp_path_info *bpi1 = b1; - struct bgp_path_info *bpi2 = b2; + const struct bgp_path_info *bpi1 = b1; + const struct bgp_path_info *bpi2 = b2; /* * Compare peers @@ -2022,8 +2026,9 @@ static int rfapi_bi_peer_rd_cmp(void *b1, void *b2) /* * compare RDs */ - return vnc_prefix_cmp((struct prefix *)&bpi1->extra->vnc.import.rd, - (struct prefix *)&bpi2->extra->vnc.import.rd); + return vnc_prefix_cmp( + (const struct prefix *)&bpi1->extra->vnc.import.rd, + (const struct prefix *)&bpi2->extra->vnc.import.rd); } /* @@ -2031,10 +2036,10 @@ static int rfapi_bi_peer_rd_cmp(void *b1, void *b2) * The BPIs in these tables should ALWAYS have an aux_prefix set because * they arrive via IPv4 or IPv6 advertisements. */ -static int rfapi_bi_peer_rd_aux_cmp(void *b1, void *b2) +static int rfapi_bi_peer_rd_aux_cmp(const void *b1, const void *b2) { - struct bgp_path_info *bpi1 = b1; - struct bgp_path_info *bpi2 = b2; + const struct bgp_path_info *bpi1 = b1; + const struct bgp_path_info *bpi2 = b2; int rc; /* @@ -2089,6 +2094,7 @@ static void rfapiItBiIndexAdd(struct agg_node *rn, /* Import table VPN node */ struct bgp_path_info *bpi) /* new BPI */ { struct skiplist *sl; + const struct prefix *p; assert(rn); assert(bpi); @@ -2105,7 +2111,8 @@ static void rfapiItBiIndexAdd(struct agg_node *rn, /* Import table VPN node */ sl = RFAPI_RDINDEX_W_ALLOC(rn); if (!sl) { - if (AF_ETHERNET == rn->p.family) { + p = agg_node_get_prefix(rn); + if (AF_ETHERNET == p->family) { sl = skiplist_new(0, rfapi_bi_peer_rd_aux_cmp, NULL); } else { sl = skiplist_new(0, rfapi_bi_peer_rd_cmp, NULL); @@ -2152,7 +2159,7 @@ static void rfapiItBiIndexDump(struct agg_node *rn) static struct bgp_path_info *rfapiItBiIndexSearch( struct agg_node *rn, /* Import table VPN node */ struct prefix_rd *prd, struct peer *peer, - struct prefix *aux_prefix) /* optional L3 addr for L2 ITs */ + const struct prefix *aux_prefix) /* optional L3 addr for L2 ITs */ { struct skiplist *sl; int rc; @@ -2375,7 +2382,7 @@ static int rfapiWithdrawTimerVPN(struct thread *t) struct rfapi_withdraw *wcb = t->arg; struct bgp_path_info *bpi = wcb->info; struct bgp *bgp = bgp_get_default(); - + const struct prefix *p; struct rfapi_monitor_vpn *moved; afi_t afi; @@ -2398,15 +2405,8 @@ static int rfapiWithdrawTimerVPN(struct thread *t) RFAPI_CHECK_REFCOUNT(wcb->node, SAFI_MPLS_VPN, wcb->lockoffset); - { - char buf[BUFSIZ]; - - vnc_zlog_debug_verbose( - "%s: removing bpi %p at prefix %s/%d", __func__, bpi, - rfapi_ntop(wcb->node->p.family, &wcb->node->p.u.prefix, - buf, BUFSIZ), - wcb->node->p.prefixlen); - } + vnc_zlog_debug_verbose("%s: removing bpi %p at prefix %pRN", __func__, + bpi, wcb->node); /* * Remove the route (doubly-linked) @@ -2415,7 +2415,8 @@ static int rfapiWithdrawTimerVPN(struct thread *t) && VALID_INTERIOR_TYPE(bpi->type)) RFAPI_MONITOR_EXTERIOR(wcb->node)->valid_interior_count--; - afi = family2afi(wcb->node->p.family); + p = agg_node_get_prefix(wcb->node); + afi = family2afi(p->family); wcb->import_table->holddown_count[afi] -= 1; /* keep count consistent */ rfapiItBiIndexDel(wcb->node, bpi); rfapiBgpInfoDetach(wcb->node, bpi); /* with removed bpi */ @@ -2846,11 +2847,13 @@ rfapiBiStartWithdrawTimer(struct rfapi_import_table *import_table, } -typedef void(rfapi_bi_filtered_import_f)(struct rfapi_import_table *, int, - struct peer *, void *, struct prefix *, - struct prefix *, afi_t, - struct prefix_rd *, struct attr *, - uint8_t, uint8_t, uint32_t *); +typedef void(rfapi_bi_filtered_import_f)(struct rfapi_import_table *table, + int action, struct peer *peer, + void *rfd, const struct prefix *prefix, + const struct prefix *aux_prefix, + afi_t afi, struct prefix_rd *prd, + struct attr *attr, uint8_t type, + uint8_t sub_type, uint32_t *label); static void rfapiExpireEncapNow(struct rfapi_import_table *it, @@ -2899,11 +2902,11 @@ static int rfapiGetNexthop(struct attr *attr, struct prefix *prefix) static void rfapiBgpInfoFilteredImportEncap( struct rfapi_import_table *import_table, int action, struct peer *peer, void *rfd, /* set for looped back routes */ - struct prefix *p, - struct prefix *aux_prefix, /* Unused for encap routes */ + const struct prefix *p, + const struct prefix *aux_prefix, /* Unused for encap routes */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_path_info */ - uint8_t type, /* part of bgp_path_info */ + uint8_t type, /* part of bgp_path_info */ uint8_t sub_type, /* part of bgp_path_info */ uint32_t *label) /* part of bgp_path_info */ { @@ -3074,11 +3077,8 @@ static void rfapiBgpInfoFilteredImportEncap( if (action == FIF_ACTION_WITHDRAW) { vnc_zlog_debug_verbose( - "%s: withdrawing at prefix %s/%d", - __func__, - inet_ntop(rn->p.family, &rn->p.u.prefix, - buf, BUFSIZ), - rn->p.prefixlen); + "%s: withdrawing at prefix %pRN", + __func__, rn); rfapiBiStartWithdrawTimer( import_table, rn, bpi, afi, SAFI_ENCAP, @@ -3086,13 +3086,11 @@ static void rfapiBgpInfoFilteredImportEncap( } else { vnc_zlog_debug_verbose( - "%s: %s at prefix %s/%d", __func__, + "%s: %s at prefix %pRN", __func__, ((action == FIF_ACTION_KILL) ? "killing" : "replacing"), - inet_ntop(rn->p.family, &rn->p.u.prefix, - buf, BUFSIZ), - rn->p.prefixlen); + rn); /* * If this route is waiting to be deleted @@ -3160,10 +3158,8 @@ static void rfapiBgpInfoFilteredImportEncap( rn = agg_node_get(rt, p); } - vnc_zlog_debug_verbose( - "%s: (afi=%d, rn=%p) inserting at prefix %s/%d", __func__, afi, - rn, inet_ntop(rn->p.family, &rn->p.u.prefix, buf, BUFSIZ), - rn->p.prefixlen); + vnc_zlog_debug_verbose("%s: (afi=%d, rn=%p) inserting at prefix %pRN", + __func__, afi, rn, rn); rfapiBgpInfoAttachSorted(rn, info_new, afi, SAFI_ENCAP); @@ -3246,6 +3242,7 @@ static void rfapiBgpInfoFilteredImportEncap( __func__, rn); #endif for (m = RFAPI_MONITOR_ENCAP(rn); m; m = m->next) { + const struct prefix *p; /* * For each referenced bpi/route, copy the ENCAP route's @@ -3273,9 +3270,9 @@ static void rfapiBgpInfoFilteredImportEncap( * list * per prefix. */ - + p = agg_node_get_prefix(m->node); referenced_vpn_prefix = - agg_node_get(referenced_vpn_table, &m->node->p); + agg_node_get(referenced_vpn_table, p); assert(referenced_vpn_prefix); for (mnext = referenced_vpn_prefix->info; mnext; mnext = mnext->next) { @@ -3360,11 +3357,11 @@ static void rfapiExpireVpnNow(struct rfapi_import_table *it, void rfapiBgpInfoFilteredImportVPN( struct rfapi_import_table *import_table, int action, struct peer *peer, void *rfd, /* set for looped back routes */ - struct prefix *p, - struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ + const struct prefix *p, + const struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_path_info */ - uint8_t type, /* part of bgp_path_info */ + uint8_t type, /* part of bgp_path_info */ uint8_t sub_type, /* part of bgp_path_info */ uint32_t *label) /* part of bgp_path_info */ { @@ -3525,11 +3522,8 @@ void rfapiBgpInfoFilteredImportVPN( BGP_PATH_REMOVED); vnc_zlog_debug_verbose( - "%s: withdrawing at prefix %s/%d%s", - __func__, rfapi_ntop(rn->p.family, - &rn->p.u.prefix, - buf, BUFSIZ), - rn->p.prefixlen, + "%s: withdrawing at prefix %pRN%s", + __func__, rn, (washolddown ? " (already being withdrawn)" : "")); @@ -3548,14 +3542,11 @@ void rfapiBgpInfoFilteredImportVPN( VNC_ITRCCK; } else { vnc_zlog_debug_verbose( - "%s: %s at prefix %s/%d", __func__, + "%s: %s at prefix %pRN", __func__, ((action == FIF_ACTION_KILL) ? "killing" : "replacing"), - rfapi_ntop(rn->p.family, - &rn->p.u.prefix, buf, - BUFSIZ), - rn->p.prefixlen); + rn); /* * If this route is waiting to be deleted @@ -3673,10 +3664,8 @@ void rfapiBgpInfoFilteredImportVPN( info_new->extra->vnc.import.aux_prefix = *aux_prefix; } - vnc_zlog_debug_verbose( - "%s: inserting bpi %p at prefix %s/%d #%d", __func__, info_new, - rfapi_ntop(rn->p.family, &rn->p.u.prefix, buf, BUFSIZ), - rn->p.prefixlen, rn->lock); + vnc_zlog_debug_verbose("%s: inserting bpi %p at prefix %pRN #%d", + __func__, info_new, rn, rn->lock); rfapiBgpInfoAttachSorted(rn, info_new, afi, SAFI_MPLS_VPN); rfapiItBiIndexAdd(rn, info_new); @@ -3839,11 +3828,11 @@ void rfapiBgpInfoFilteredImportVPN( static void rfapiBgpInfoFilteredImportBadSafi( struct rfapi_import_table *import_table, int action, struct peer *peer, void *rfd, /* set for looped back routes */ - struct prefix *p, - struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ + const struct prefix *p, + const struct prefix *aux_prefix, /* AFI_L2VPN: optional IP */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_path_info */ - uint8_t type, /* part of bgp_path_info */ + uint8_t type, /* part of bgp_path_info */ uint8_t sub_type, /* part of bgp_path_info */ uint32_t *label) /* part of bgp_path_info */ { @@ -3869,7 +3858,7 @@ rfapiBgpInfoFilteredImportFunction(safi_t safi) void rfapiProcessUpdate(struct peer *peer, void *rfd, /* set when looped from RFP/RFAPI */ - struct prefix *p, struct prefix_rd *prd, + const struct prefix *p, struct prefix_rd *prd, struct attr *attr, afi_t afi, safi_t safi, uint8_t type, uint8_t sub_type, uint32_t *label) { @@ -3953,7 +3942,7 @@ void rfapiProcessUpdate(struct peer *peer, } -void rfapiProcessWithdraw(struct peer *peer, void *rfd, struct prefix *p, +void rfapiProcessWithdraw(struct peer *peer, void *rfd, const struct prefix *p, struct prefix_rd *prd, struct attr *attr, afi_t afi, safi_t safi, uint8_t type, int kill) { @@ -4444,27 +4433,20 @@ static void rfapiDeleteRemotePrefixesIt( for (rn = agg_route_top(rt); rn; rn = agg_route_next(rn)) { struct bgp_path_info *bpi; struct bgp_path_info *next; + const struct prefix *rn_p = agg_node_get_prefix(rn); if (p && VNC_DEBUG(IMPORT_DEL_REMOTE)) { char p1line[PREFIX_STRLEN]; - char p2line[PREFIX_STRLEN]; prefix2str(p, p1line, sizeof(p1line)); - prefix2str(&rn->p, p2line, sizeof(p2line)); - vnc_zlog_debug_any("%s: want %s, have %s", - __func__, p1line, p2line); + vnc_zlog_debug_any("%s: want %s, have %pRN", + __func__, p1line, rn); } - if (p && prefix_cmp(p, &rn->p)) + if (p && prefix_cmp(p, rn_p)) continue; - { - char buf_pfx[PREFIX_STRLEN]; - - prefix2str(&rn->p, buf_pfx, sizeof(buf_pfx)); - vnc_zlog_debug_verbose("%s: rn pfx=%s", - __func__, buf_pfx); - } + vnc_zlog_debug_verbose("%s: rn pfx=%pRN", __func__, rn); /* TBD is this valid for afi == AFI_L2VPN? */ RFAPI_CHECK_REFCOUNT(rn, SAFI_MPLS_VPN, 1); @@ -4596,7 +4578,7 @@ static void rfapiDeleteRemotePrefixesIt( } } - vnc_direct_bgp_rh_del_route(bgp, afi, &rn->p, + vnc_direct_bgp_rh_del_route(bgp, afi, rn_p, bpi->peer); RFAPI_UPDATE_ITABLE_COUNT(bpi, it, afi, -1); diff --git a/bgpd/rfapi/rfapi_import.h b/bgpd/rfapi/rfapi_import.h index 1ab9cc519..50093111c 100644 --- a/bgpd/rfapi/rfapi_import.h +++ b/bgpd/rfapi/rfapi_import.h @@ -143,11 +143,11 @@ extern void rfapiUnicastNexthop2Prefix(afi_t afi, struct attr *attr, extern void rfapiBgpInfoFilteredImportVPN( struct rfapi_import_table *import_table, int action, struct peer *peer, void *rfd, /* set for looped back routes */ - struct prefix *p, - struct prefix *aux_prefix, /* AFI_ETHER: optional IP */ + const struct prefix *p, + const struct prefix *aux_prefix, /* AFI_ETHER: optional IP */ afi_t afi, struct prefix_rd *prd, struct attr *attr, /* part of bgp_path_info */ - uint8_t type, /* part of bgp_path_info */ + uint8_t type, /* part of bgp_path_info */ uint8_t sub_type, /* part of bgp_path_info */ uint32_t *label); /* part of bgp_path_info */ diff --git a/bgpd/rfapi/rfapi_monitor.c b/bgpd/rfapi/rfapi_monitor.c index dc1f7e0fb..6aea18e0b 100644 --- a/bgpd/rfapi/rfapi_monitor.c +++ b/bgpd/rfapi/rfapi_monitor.c @@ -789,7 +789,8 @@ static void rfapiMonitorTimerRestart(struct rfapi_monitor_vpn *m) * been responsible for the response, i.e., any monitors for * the exact prefix or a parent of it. */ -void rfapiMonitorTimersRestart(struct rfapi_descriptor *rfd, struct prefix *p) +void rfapiMonitorTimersRestart(struct rfapi_descriptor *rfd, + const struct prefix *p) { struct agg_node *rn; @@ -818,12 +819,14 @@ void rfapiMonitorTimersRestart(struct rfapi_descriptor *rfd, struct prefix *p) for (rn = agg_route_top(rfd->mon); rn; rn = agg_route_next(rn)) { struct rfapi_monitor_vpn *m; + const struct prefix *p_node; if (!((m = rn->info))) continue; + p_node = agg_node_get_prefix(m->node); /* NB order of test is significant ! */ - if (!m->node || prefix_match(&m->node->p, p)) { + if (!m->node || prefix_match(p_node, p)) { rfapiMonitorTimerRestart(m); } } @@ -841,7 +844,8 @@ void rfapiMonitorItNodeChanged( struct skiplist *nves_seen; struct agg_node *rn = it_node; struct bgp *bgp = bgp_get_default(); - afi_t afi = family2afi(rn->p.family); + const struct prefix *p = agg_node_get_prefix(rn); + afi_t afi = family2afi(p->family); #if DEBUG_L2_EXTRA char buf_prefix[PREFIX_STRLEN]; #endif @@ -931,17 +935,14 @@ void rfapiMonitorItNodeChanged( assert(!skiplist_insert(nves_seen, m->rfd, NULL)); - char buf_attach_pfx[PREFIX_STRLEN]; char buf_target_pfx[PREFIX_STRLEN]; - prefix2str(&m->node->p, buf_attach_pfx, - sizeof(buf_attach_pfx)); prefix2str(&m->p, buf_target_pfx, sizeof(buf_target_pfx)); vnc_zlog_debug_verbose( - "%s: update rfd %p attached to pfx %s (targ=%s)", - __func__, m->rfd, - buf_attach_pfx, buf_target_pfx); + "%s: update rfd %p attached to pfx %pRN (targ=%s)", + __func__, m->rfd, m->node, + buf_target_pfx); /* * update its RIB @@ -1103,10 +1104,10 @@ static void rfapiMonitorEthTimerRestart(struct rfapi_monitor_eth *m) m->rfd->response_lifetime, &m->timer); } -static int mon_eth_cmp(void *a, void *b) +static int mon_eth_cmp(const void *a, const void *b) { - struct rfapi_monitor_eth *m1; - struct rfapi_monitor_eth *m2; + const struct rfapi_monitor_eth *m1; + const struct rfapi_monitor_eth *m2; int i; diff --git a/bgpd/rfapi/rfapi_monitor.h b/bgpd/rfapi/rfapi_monitor.h index b8eec5647..3a2248aa6 100644 --- a/bgpd/rfapi/rfapi_monitor.h +++ b/bgpd/rfapi/rfapi_monitor.h @@ -167,7 +167,7 @@ extern void rfapiMonitorResponseRemovalOn(struct bgp *bgp); extern void rfapiMonitorExtraPrune(safi_t safi, struct agg_node *rn); extern void rfapiMonitorTimersRestart(struct rfapi_descriptor *rfd, - struct prefix *p); + const struct prefix *p); extern void rfapiMonitorItNodeChanged(struct rfapi_import_table *import_table, struct agg_node *it_node, diff --git a/bgpd/rfapi/rfapi_nve_addr.c b/bgpd/rfapi/rfapi_nve_addr.c index ee54d88c3..b8193f143 100644 --- a/bgpd/rfapi/rfapi_nve_addr.c +++ b/bgpd/rfapi/rfapi_nve_addr.c @@ -58,10 +58,10 @@ static void logdifferent(const char *tag, struct rfapi_nve_addr *a, #endif -int rfapi_nve_addr_cmp(void *k1, void *k2) +int rfapi_nve_addr_cmp(const void *k1, const void *k2) { - struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1; - struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2; + const struct rfapi_nve_addr *a = (struct rfapi_nve_addr *)k1; + const struct rfapi_nve_addr *b = (struct rfapi_nve_addr *)k2; int ret = 0; if (!a || !b) { diff --git a/bgpd/rfapi/rfapi_nve_addr.h b/bgpd/rfapi/rfapi_nve_addr.h index 2d54d4a3c..7bcb3cab6 100644 --- a/bgpd/rfapi/rfapi_nve_addr.h +++ b/bgpd/rfapi/rfapi_nve_addr.h @@ -30,7 +30,7 @@ struct rfapi_nve_addr { }; -extern int rfapi_nve_addr_cmp(void *k1, void *k2); +extern int rfapi_nve_addr_cmp(const void *k1, const void *k2); extern void rfapiNveAddr2Str(struct rfapi_nve_addr *na, char *buf, int bufsize); diff --git a/bgpd/rfapi/rfapi_private.h b/bgpd/rfapi/rfapi_private.h index ff1cf7ef4..68caba600 100644 --- a/bgpd/rfapi/rfapi_private.h +++ b/bgpd/rfapi/rfapi_private.h @@ -272,16 +272,13 @@ struct rfapi { ? ((prefix)->prefixlen == 128) \ : 0)) -extern void rfapiQprefix2Rprefix(struct prefix *qprefix, - struct rfapi_ip_prefix *rprefix); - extern int rfapi_find_rfd(struct bgp *bgp, struct rfapi_ip_addr *vn_addr, struct rfapi_ip_addr *un_addr, struct rfapi_descriptor **rfd); extern void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie + UN addr for VPN */ - struct bgp *bgp, int safi, struct prefix *p, + struct bgp *bgp, int safi, const struct prefix *p, struct prefix_rd *prd, struct rfapi_ip_addr *nexthop, uint32_t *local_pref, /* host byte order */ uint32_t *lifetime, /* host byte order */ @@ -297,7 +294,7 @@ add_vnc_route(struct rfapi_descriptor *rfd, /* cookie + UN addr for VPN */ #endif extern void del_vnc_route(struct rfapi_descriptor *rfd, struct peer *peer, - struct bgp *bgp, safi_t safi, struct prefix *p, + struct bgp *bgp, safi_t safi, const struct prefix *p, struct prefix_rd *prd, uint8_t type, uint8_t sub_type, struct rfapi_nexthop *lnh, int kill); diff --git a/bgpd/rfapi/rfapi_rib.c b/bgpd/rfapi/rfapi_rib.c index 3d4bdef75..c64658181 100644 --- a/bgpd/rfapi/rfapi_rib.c +++ b/bgpd/rfapi/rfapi_rib.c @@ -340,7 +340,6 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd, { struct thread *t = ri->timer; struct rfapi_rib_tcb *tcb = NULL; - char buf_prefix[PREFIX_STRLEN]; if (t) { tcb = t->arg; @@ -361,9 +360,8 @@ static void rfapiRibStartTimer(struct rfapi_descriptor *rfd, UNSET_FLAG(tcb->flags, RFAPI_RIB_TCB_FLAG_DELETED); } - prefix2str(&rn->p, buf_prefix, sizeof(buf_prefix)); - vnc_zlog_debug_verbose("%s: rfd %p pfx %s life %u", __func__, rfd, - buf_prefix, ri->lifetime); + vnc_zlog_debug_verbose("%s: rfd %p pfx %pRN life %u", __func__, rfd, rn, + ri->lifetime); ri->timer = NULL; thread_add_timer(bm->master, rfapiRibExpireTimer, tcb, ri->lifetime, &ri->timer); @@ -388,10 +386,10 @@ extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */ /* * Compares two <struct rfapi_rib_key>s */ -int rfapi_rib_key_cmp(void *k1, void *k2) +int rfapi_rib_key_cmp(const void *k1, const void *k2) { - struct rfapi_rib_key *a = (struct rfapi_rib_key *)k1; - struct rfapi_rib_key *b = (struct rfapi_rib_key *)k2; + const struct rfapi_rib_key *a = (struct rfapi_rib_key *)k1; + const struct rfapi_rib_key *b = (struct rfapi_rib_key *)k2; int ret; if (!a || !b) @@ -741,11 +739,12 @@ int rfapiRibPreloadBi( struct rfapi_rib_key rk; struct agg_node *trn; afi_t afi; + const struct prefix *p = agg_node_get_prefix(rfd_rib_node); if (!rfd_rib_node) return 0; - afi = family2afi(rfd_rib_node->p.family); + afi = family2afi(p->family); rfd = agg_get_table_info(agg_get_table(rfd_rib_node)); @@ -803,8 +802,7 @@ int rfapiRibPreloadBi( /* * Update last sent time for prefix */ - trn = agg_node_get(rfd->rsp_times[afi], - &rfd_rib_node->p); /* locks trn */ + trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ trn->info = (void *)(uintptr_t)bgp_clock(); if (trn->lock > 1) agg_unlock_node(trn); @@ -852,10 +850,9 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd, struct list *lPendCost = NULL; struct list *delete_list = NULL; int printedprefix = 0; - char buf_prefix[PREFIX_STRLEN]; int rib_node_started_nonempty = 0; int sendingsomeroutes = 0; - + const struct prefix *p; #if DEBUG_PROCESS_PENDING_NODE unsigned int count_rib_initial = 0; unsigned int count_pend_vn_initial = 0; @@ -863,12 +860,12 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd, #endif assert(pn); - prefix2str(&pn->p, buf_prefix, sizeof(buf_prefix)); - vnc_zlog_debug_verbose("%s: afi=%d, %s pn->info=%p", __func__, afi, - buf_prefix, pn->info); + p = agg_node_get_prefix(pn); + vnc_zlog_debug_verbose("%s: afi=%d, %pRN pn->info=%p", __func__, afi, + pn, pn->info); if (AFI_L2VPN != afi) { - rfapiQprefix2Rprefix(&pn->p, &hp); + rfapiQprefix2Rprefix(p, &hp); } RFAPI_RIB_CHECK_COUNTS(1, 0); @@ -876,7 +873,7 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd, /* * Find corresponding RIB node */ - rn = agg_node_get(rfd->rib[afi], &pn->p); /* locks rn */ + rn = agg_node_get(rfd->rib[afi], p); /* locks rn */ /* * RIB skiplist has key=rfapi_addr={vn,un}, val = rfapi_info, @@ -935,9 +932,9 @@ static void process_pending_node(struct bgp *bgp, struct rfapi_descriptor *rfd, prefix2str(&ri->rk.vn, buf, sizeof(buf)); prefix2str(&ri->un, buf2, sizeof(buf2)); vnc_zlog_debug_verbose( - "%s: put dl pfx=%s vn=%s un=%s cost=%d life=%d vn_options=%p", - __func__, buf_prefix, buf, buf2, - ri->cost, ri->lifetime, ri->vn_options); + "%s: put dl pfx=%pRN vn=%s un=%s cost=%d life=%d vn_options=%p", + __func__, pn, buf, buf2, ri->cost, + ri->lifetime, ri->vn_options); skiplist_delete_first(slRibPt); } @@ -1186,8 +1183,7 @@ callback: vnc_zlog_debug_verbose("%s: lPendCost->count now %d", __func__, lPendCost->count); - vnc_zlog_debug_verbose("%s: For prefix %s (a)", __func__, - buf_prefix); + vnc_zlog_debug_verbose("%s: For prefix %pRN (a)", __func__, pn); printedprefix = 1; for (ALL_LIST_ELEMENTS(lPendCost, node, nnode, ri)) { @@ -1246,7 +1242,7 @@ callback: * update this NVE's timestamp for this prefix */ trn = agg_node_get(rfd->rsp_times[afi], - &pn->p); /* locks trn */ + p); /* locks trn */ trn->info = (void *)(uintptr_t)bgp_clock(); if (trn->lock > 1) agg_unlock_node(trn); @@ -1268,8 +1264,8 @@ callback: char buf2[BUFSIZ]; if (!printedprefix) { - vnc_zlog_debug_verbose("%s: For prefix %s (d)", - __func__, buf_prefix); + vnc_zlog_debug_verbose("%s: For prefix %pRN (d)", + __func__, pn); } vnc_zlog_debug_verbose("%s: delete_list has %d elements", __func__, delete_list->count); @@ -1465,7 +1461,7 @@ callback: } if (sendingsomeroutes) - rfapiMonitorTimersRestart(rfd, &pn->p); + rfapiMonitorTimersRestart(rfd, p); agg_unlock_node(rn); /* agg_node_get() */ @@ -1589,7 +1585,7 @@ void rfapiRibUpdatePendingNode( struct rfapi_import_table *it, /* needed for L2 */ struct agg_node *it_node, uint32_t lifetime) { - struct prefix *prefix; + const struct prefix *prefix; struct bgp_path_info *bpi; struct agg_node *pn; afi_t afi; @@ -1606,7 +1602,7 @@ void rfapiRibUpdatePendingNode( RFAPI_RIB_CHECK_COUNTS(1, 0); - prefix = &it_node->p; + prefix = agg_node_get_prefix(it_node); afi = family2afi(prefix->family); prefix2str(prefix, buf, sizeof(buf)); vnc_zlog_debug_verbose("%s: prefix=%s", __func__, buf); @@ -1794,7 +1790,8 @@ int rfapiRibFTDFilterRecentPrefix( struct prefix *pfx_target_original) /* query target */ { struct bgp *bgp = rfd->bgp; - afi_t afi = family2afi(it_rn->p.family); + const struct prefix *p = agg_node_get_prefix(it_rn); + afi_t afi = family2afi(p->family); time_t prefix_time; struct agg_node *trn; @@ -1809,7 +1806,7 @@ int rfapiRibFTDFilterRecentPrefix( * This matches behavior of now-obsolete rfapiRibFTDFilterRecent(), * but we need to decide if that is correct. */ - if (it_rn->p.family == AF_ETHERNET) + if (p->family == AF_ETHERNET) return 0; #ifdef DEBUG_FTD_FILTER_RECENT @@ -1824,7 +1821,7 @@ int rfapiRibFTDFilterRecentPrefix( /* * prefix covers target address, so allow prefix */ - if (prefix_match(&it_rn->p, pfx_target_original)) { + if (prefix_match(p, pfx_target_original)) { #ifdef DEBUG_FTD_FILTER_RECENT vnc_zlog_debug_verbose("%s: prefix covers target, allowed", __func__); @@ -1835,7 +1832,7 @@ int rfapiRibFTDFilterRecentPrefix( /* * check this NVE's timestamp for this prefix */ - trn = agg_node_get(rfd->rsp_times[afi], &it_rn->p); /* locks trn */ + trn = agg_node_get(rfd->rsp_times[afi], p); /* locks trn */ prefix_time = (time_t)trn->info; if (trn->lock > 1) agg_unlock_node(trn); @@ -2114,11 +2111,10 @@ void rfapiRibPendingDeleteRoute(struct bgp *bgp, struct rfapi_import_table *it, { struct rfapi_descriptor *rfd; struct listnode *node; - char buf[PREFIX_STRLEN]; + const struct prefix *p = agg_node_get_prefix(it_node); - prefix2str(&it_node->p, buf, sizeof(buf)); - vnc_zlog_debug_verbose("%s: entry, it=%p, afi=%d, it_node=%p, pfx=%s", - __func__, it, afi, it_node, buf); + vnc_zlog_debug_verbose("%s: entry, it=%p, afi=%d, it_node=%p, pfx=%pRN", + __func__, it, afi, it_node, it_node); if (AFI_L2VPN == afi) { /* @@ -2157,7 +2153,7 @@ void rfapiRibPendingDeleteRoute(struct bgp *bgp, struct rfapi_import_table *it, * delete */ if ((rn = agg_node_lookup(m->rfd->rib[afi], - &it_node->p))) { + p))) { rfapiRibUpdatePendingNode( bgp, m->rfd, it, it_node, m->rfd->response_lifetime); @@ -2179,8 +2175,7 @@ void rfapiRibPendingDeleteRoute(struct bgp *bgp, struct rfapi_import_table *it, * this * NVE, it's OK to send an update with the delete */ - if ((rn = agg_node_lookup(m->rfd->rib[afi], - &it_node->p))) { + if ((rn = agg_node_lookup(m->rfd->rib[afi], p))) { rfapiRibUpdatePendingNode( bgp, m->rfd, it, it_node, m->rfd->response_lifetime); @@ -2212,8 +2207,7 @@ void rfapiRibPendingDeleteRoute(struct bgp *bgp, struct rfapi_import_table *it, * prefix * previously, we should send an updated response. */ - if ((rn = agg_node_lookup(rfd->rib[afi], - &it_node->p))) { + if ((rn = agg_node_lookup(rfd->rib[afi], p))) { rfapiRibUpdatePendingNode( bgp, rfd, it, it_node, rfd->response_lifetime); @@ -2416,7 +2410,8 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match, for (rn = agg_route_top(rfd->rib[afi]); rn; rn = agg_route_next(rn)) { - + const struct prefix *p = + agg_node_get_prefix(rn); struct skiplist *sl; char str_pfx[PREFIX_STRLEN]; int printedprefix = 0; @@ -2433,9 +2428,8 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match, nhs_total += skiplist_count(sl); ++prefixes_total; - if (pfx_match - && !prefix_match(pfx_match, &rn->p) - && !prefix_match(&rn->p, pfx_match)) + if (pfx_match && !prefix_match(pfx_match, p) + && !prefix_match(p, pfx_match)) continue; ++prefixes_displayed; @@ -2472,7 +2466,7 @@ void rfapiRibShowResponses(void *stream, struct prefix *pfx_match, str_un, BUFSIZ)); } - prefix2str(&rn->p, str_pfx, sizeof(str_pfx)); + prefix2str(p, str_pfx, sizeof(str_pfx)); // fp(out, " %s\n", buf); /* prefix */ routes_displayed++; diff --git a/bgpd/rfapi/rfapi_rib.h b/bgpd/rfapi/rfapi_rib.h index 38a6df9fb..3ad021b4f 100644 --- a/bgpd/rfapi/rfapi_rib.h +++ b/bgpd/rfapi/rfapi_rib.h @@ -147,7 +147,7 @@ extern void rfapi_rib_key_init(struct prefix *prefix, /* may be NULL */ struct prefix *aux, /* may be NULL */ struct rfapi_rib_key *rk); -extern int rfapi_rib_key_cmp(void *k1, void *k2); +extern int rfapi_rib_key_cmp(const void *k1, const void *k2); extern void rfapiAdbFree(struct rfapi_adb *adb); diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 58fdc7c13..5a84d14bd 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -194,7 +194,7 @@ int rfapiQprefix2Raddr(struct prefix *qprefix, struct rfapi_ip_addr *raddr) * Translate Quagga prefix to RFAPI prefix */ /* rprefix->cost set to 0 */ -void rfapiQprefix2Rprefix(struct prefix *qprefix, +void rfapiQprefix2Rprefix(const struct prefix *qprefix, struct rfapi_ip_prefix *rprefix) { memset(rprefix, 0, sizeof(struct rfapi_ip_prefix)); @@ -393,7 +393,7 @@ int rfapiStream2Vty(void *stream, /* input */ } /* called from bgpd/bgp_vty.c'route_vty_out() */ -void rfapi_vty_out_vncinfo(struct vty *vty, struct prefix *p, +void rfapi_vty_out_vncinfo(struct vty *vty, const struct prefix *p, struct bgp_path_info *bpi, safi_t safi) { char *s; @@ -743,7 +743,6 @@ static void rfapiDebugPrintMonitorEncap(void *stream, void rfapiShowItNode(void *stream, struct agg_node *rn) { struct bgp_path_info *bpi; - char buf[BUFSIZ]; int (*fp)(void *, const char *, ...); struct vty *vty; @@ -753,9 +752,7 @@ void rfapiShowItNode(void *stream, struct agg_node *rn) if (rfapiStream2Vty(stream, &fp, &vty, &out, &vty_newline) == 0) return; - fp(out, "%s/%d @%p #%d%s", - rfapi_ntop(rn->p.family, &rn->p.u.prefix, buf, BUFSIZ), - rn->p.prefixlen, rn, rn->lock, HVTYNL); + fp(out, "%pRN @%p #%d%s", rn, rn, rn->lock, HVTYNL); for (bpi = rn->info; bpi; bpi = bpi->next) { rfapiPrintBi(stream, bpi); @@ -782,14 +779,15 @@ void rfapiShowImportTable(void *stream, const char *label, struct agg_table *rt, for (rn = agg_route_top(rt); rn; rn = agg_route_next(rn)) { struct bgp_path_info *bpi; + const struct prefix *p = agg_node_get_prefix(rn); - if (rn->p.family == AF_ETHERNET) { - rfapiEthAddr2Str(&rn->p.u.prefix_eth, buf, BUFSIZ); + if (p->family == AF_ETHERNET) { + rfapiEthAddr2Str(&p->u.prefix_eth, buf, BUFSIZ); } else { - inet_ntop(rn->p.family, &rn->p.u.prefix, buf, BUFSIZ); + inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ); } - fp(out, "%s/%d @%p #%d%s", buf, rn->p.prefixlen, rn, + fp(out, "%s/%d @%p #%d%s", buf, p->prefixlen, rn, rn->lock - 1, /* account for loop iterator locking */ HVTYNL); @@ -868,6 +866,8 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match) if (rfd->mon) { for (rn = agg_route_top(rfd->mon); rn; rn = agg_route_next(rn)) { + const struct prefix *p = + agg_node_get_prefix(rn); struct rfapi_monitor_vpn *m; char buf_remain[BUFSIZ]; char buf_pfx[BUFSIZ]; @@ -879,9 +879,8 @@ int rfapiShowVncQueries(void *stream, struct prefix *pfx_match) ++queries_total; - if (pfx_match - && !prefix_match(pfx_match, &rn->p) - && !prefix_match(&rn->p, pfx_match)) + if (pfx_match && !prefix_match(pfx_match, p) + && !prefix_match(p, pfx_match)) continue; ++queries_displayed; @@ -1028,6 +1027,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream, char buf_vn[BUFSIZ]; char buf_lifetime[BUFSIZ]; int nlines = 0; + const struct prefix *p = agg_node_get_prefix(rn); if (!stream) return 0; /* for debug log, print into buf & call output once */ @@ -1040,8 +1040,8 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream, */ buf_pfx[0] = 0; snprintf(buf_pfx, BUFSIZ, "%s/%d", - rfapi_ntop(rn->p.family, &rn->p.u.prefix, buf_ntop, BUFSIZ), - rn->p.prefixlen); + rfapi_ntop(p->family, &p->u.prefix, buf_ntop, BUFSIZ), + p->prefixlen); buf_pfx[BUFSIZ - 1] = 0; nlines++; @@ -1155,7 +1155,7 @@ static int rfapiPrintRemoteRegBi(struct bgp *bgp, void *stream, } fp(out, "%s", HVTYNL); - if (rn->p.family == AF_ETHERNET) { + if (p->family == AF_ETHERNET) { /* * If there is a corresponding IP address && != VN address, * print that on the next line @@ -1221,13 +1221,13 @@ static int rfapiShowRemoteRegistrationsIt(struct bgp *bgp, void *stream, for (rn = agg_route_top(it->imported_vpn[afi]); rn; rn = agg_route_next(rn)) { - + const struct prefix *p = agg_node_get_prefix(rn); struct bgp_path_info *bpi; int count_only; /* allow for wider or more narrow mask from user */ - if (prefix_only && !prefix_match(prefix_only, &rn->p) - && !prefix_match(&rn->p, prefix_only)) + if (prefix_only && !prefix_match(prefix_only, p) + && !prefix_match(p, prefix_only)) count_only = 1; else count_only = 0; @@ -2754,10 +2754,10 @@ static void nve_addr_free(void *hap) XFREE(MTYPE_RFAPI_NVE_ADDR, hap); } -static int nve_addr_cmp(void *k1, void *k2) +static int nve_addr_cmp(const void *k1, const void *k2) { - struct nve_addr *a = (struct nve_addr *)k1; - struct nve_addr *b = (struct nve_addr *)k2; + const struct nve_addr *a = (struct nve_addr *)k1; + const struct nve_addr *b = (struct nve_addr *)k2; int ret = 0; if (!a || !b) { diff --git a/bgpd/rfapi/rfapi_vty.h b/bgpd/rfapi/rfapi_vty.h index 8b881292a..b5e1c38b0 100644 --- a/bgpd/rfapi/rfapi_vty.h +++ b/bgpd/rfapi/rfapi_vty.h @@ -43,7 +43,7 @@ extern void rfapiRprefixApplyMask(struct rfapi_ip_prefix *rprefix); extern int rfapiQprefix2Raddr(struct prefix *qprefix, struct rfapi_ip_addr *raddr); -extern void rfapiQprefix2Rprefix(struct prefix *qprefix, +extern void rfapiQprefix2Rprefix(const struct prefix *qprefix, struct rfapi_ip_prefix *rprefix); extern int rfapiRprefix2Qprefix(struct rfapi_ip_prefix *rprefix, diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 3d34d696b..6e928c2a4 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -177,7 +177,7 @@ void vnc_direct_bgp_add_route_ce(struct bgp *bgp, struct agg_node *rn, { struct attr *attr = bpi->attr; struct peer *peer = bpi->peer; - struct prefix *prefix = &rn->p; + const struct prefix *prefix = agg_node_get_prefix(rn); afi_t afi = family2afi(prefix->family); struct bgp_node *urn; struct bgp_path_info *ubpi; @@ -330,7 +330,8 @@ void vnc_direct_bgp_add_route_ce(struct bgp *bgp, struct agg_node *rn, void vnc_direct_bgp_del_route_ce(struct bgp *bgp, struct agg_node *rn, struct bgp_path_info *bpi) { - afi_t afi = family2afi(rn->p.family); + const struct prefix *p = agg_node_get_prefix(rn); + afi_t afi = family2afi(p->family); struct bgp_path_info *vbpi; struct prefix ce_nexthop; @@ -395,8 +396,8 @@ void vnc_direct_bgp_del_route_ce(struct bgp *bgp, struct agg_node *rn, /* * withdraw the route */ - bgp_withdraw(bpi->peer, &rn->p, 0, /* addpath_id */ - NULL, /* attr, ignored */ + bgp_withdraw(bpi->peer, p, 0, /* addpath_id */ + NULL, /* attr, ignored */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, NULL, /* RD not used for unicast */ NULL, 0, NULL); /* tag not used for unicast */ @@ -432,17 +433,11 @@ static void vnc_direct_bgp_vpn_enable_ce(struct bgp *bgp, afi_t afi) */ for (rn = agg_route_top(bgp->rfapi->it_ce->imported_vpn[afi]); rn; rn = agg_route_next(rn)) { - if (!rn->info) continue; - { - char prefixstr[PREFIX_STRLEN]; - - prefix2str(&rn->p, prefixstr, sizeof(prefixstr)); - vnc_zlog_debug_verbose("%s: checking prefix %s", - __func__, prefixstr); - } + vnc_zlog_debug_verbose("%s: checking prefix %pRN", __func__, + rn); for (ri = rn->info; ri; ri = ri->next) { @@ -698,7 +693,8 @@ void vnc_direct_bgp_add_prefix(struct bgp *bgp, struct attr attr = {0}; struct listnode *node, *nnode; struct rfapi_rfg_name *rfgn; - afi_t afi = family2afi(rn->p.family); + const struct prefix *p = agg_node_get_prefix(rn); + afi_t afi = family2afi(p->family); if (!afi) { flog_err(EC_LIB_DEVELOPMENT, "%s: can't get afi of route node", @@ -769,7 +765,7 @@ void vnc_direct_bgp_add_prefix(struct bgp *bgp, */ if (rfgn->rfg->plist_export_bgp[afi]) { if (prefix_list_apply(rfgn->rfg->plist_export_bgp[afi], - &rn->p) + p) == PREFIX_DENY) continue; @@ -808,7 +804,8 @@ void vnc_direct_bgp_del_prefix(struct bgp *bgp, { struct listnode *node, *nnode; struct rfapi_rfg_name *rfgn; - afi_t afi = family2afi(rn->p.family); + const struct prefix *p = agg_node_get_prefix(rn); + afi_t afi = family2afi(p->family); if (!afi) { flog_err(EC_LIB_DEVELOPMENT, "%s: can't get afi route node", @@ -877,9 +874,9 @@ void vnc_direct_bgp_del_prefix(struct bgp *bgp, if (rfapiRaddr2Qprefix(&irfd->vn_addr, &nhp)) continue; - bgp_withdraw(irfd->peer, &rn->p, /* prefix */ - 0, /* addpath_id */ - NULL, /* attr, ignored */ + bgp_withdraw(irfd->peer, p, /* prefix */ + 0, /* addpath_id */ + NULL, /* attr, ignored */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, NULL, /* RD not used for unicast */ @@ -907,9 +904,9 @@ void vnc_direct_bgp_del_prefix(struct bgp *bgp, if (rfapiRaddr2Qprefix(&irfd->vn_addr, &nhp)) continue; - bgp_withdraw(irfd->peer, &rn->p, /* prefix */ - 0, /* addpath_id */ - NULL, /* attr, ignored */ + bgp_withdraw(irfd->peer, p, /* prefix */ + 0, /* addpath_id */ + NULL, /* attr, ignored */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, NULL, /* RD not used for unicast */ @@ -998,6 +995,8 @@ void vnc_direct_bgp_add_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) struct attr hattr; struct attr *iattr; struct bgp_path_info info; + const struct prefix *p = + agg_node_get_prefix(rn); if (rfapiRaddr2Qprefix(&irfd->vn_addr, &nhp)) @@ -1010,7 +1009,7 @@ void vnc_direct_bgp_add_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) if (prefix_list_apply( rfgn->rfg->plist_export_bgp [afi], - &rn->p) + p) == PREFIX_DENY) continue; @@ -1033,8 +1032,7 @@ void vnc_direct_bgp_add_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) ret = route_map_apply( rfgn->rfg ->routemap_export_bgp, - &rn->p, RMAP_BGP, - &info); + p, RMAP_BGP, &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); continue; @@ -1044,8 +1042,8 @@ void vnc_direct_bgp_add_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) iattr = bgp_attr_intern(&hattr); bgp_attr_flush(&hattr); bgp_update( - irfd->peer, &rn->p, /* prefix */ - 0, /* addpath_id */ + irfd->peer, p, /* prefix */ + 0, /* addpath_id */ iattr, /* bgp_update copies it */ afi, SAFI_UNICAST, @@ -1134,7 +1132,8 @@ void vnc_direct_bgp_del_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) rn = agg_route_next(rn)) { if (rn->info) { - + const struct prefix *p = + agg_node_get_prefix(rn); struct prefix nhp; struct rfapi_descriptor *irfd = rfd; @@ -1142,10 +1141,9 @@ void vnc_direct_bgp_del_nve(struct bgp *bgp, struct rfapi_descriptor *rfd) &nhp)) continue; - bgp_withdraw(irfd->peer, - &rn->p, /* prefix */ - 0, /* addpath_id */ - NULL, /* attr, ignored */ + bgp_withdraw(irfd->peer, p, /* prefix */ + 0, /* addpath_id */ + NULL, /* attr, ignored */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, @@ -1169,6 +1167,7 @@ static void vnc_direct_add_rn_group_rd(struct bgp *bgp, struct bgp_path_info info; struct attr hattr; struct attr *iattr; + const struct prefix *p = agg_node_get_prefix(rn); if (irfd == NULL && rfg->type != RFAPI_GROUP_CFG_VRF) { /* need new rfapi_handle, for peer strcture @@ -1242,8 +1241,8 @@ static void vnc_direct_add_rn_group_rd(struct bgp *bgp, info.peer = irfd->peer; info.attr = &hattr; - ret = route_map_apply(rfg->routemap_export_bgp, &rn->p, - RMAP_BGP, &info); + ret = route_map_apply(rfg->routemap_export_bgp, p, RMAP_BGP, + &info); if (ret == RMAP_DENYMATCH) { bgp_attr_flush(&hattr); vnc_zlog_debug_verbose( @@ -1261,9 +1260,9 @@ static void vnc_direct_add_rn_group_rd(struct bgp *bgp, iattr = bgp_attr_intern(&hattr); bgp_attr_flush(&hattr); - bgp_update(irfd->peer, &rn->p, /* prefix */ - 0, /* addpath_id */ - iattr, /* bgp_update copies it */ + bgp_update(irfd->peer, p, /* prefix */ + 0, /* addpath_id */ + iattr, /* bgp_update copies it */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, NULL, /* RD not used for unicast */ NULL, /* tag not used for unicast */ @@ -1317,7 +1316,7 @@ static void vnc_direct_bgp_add_group_afi(struct bgp *bgp, for (rn = agg_route_top(rt); rn; rn = agg_route_next(rn)) { if (rn->info) { - + const struct prefix *p = agg_node_get_prefix(rn); struct listnode *ln; /* @@ -1325,7 +1324,7 @@ static void vnc_direct_bgp_add_group_afi(struct bgp *bgp, */ if (rfg->plist_export_bgp[afi]) { if (prefix_list_apply( - rfg->plist_export_bgp[afi], &rn->p) + rfg->plist_export_bgp[afi], p) == PREFIX_DENY) continue; @@ -1374,9 +1373,10 @@ static void vnc_direct_del_rn_group_rd(struct bgp *bgp, { if (irfd == NULL) return; - bgp_withdraw(irfd->peer, &rn->p, /* prefix */ - 0, /* addpath_id */ - NULL, /* attr, ignored */ + + bgp_withdraw(irfd->peer, agg_node_get_prefix(rn), /* prefix */ + 0, /* addpath_id */ + NULL, /* attr, ignored */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, NULL, /* RD not used for unicast */ NULL, 0, NULL); /* tag not used for unicast */ @@ -1493,9 +1493,9 @@ static void vnc_direct_bgp_unexport_table(afi_t afi, struct agg_table *rt, irfd)) { bgp_withdraw(irfd->peer, - &rn->p, /* prefix */ - 0, /* addpath_id */ - NULL, /* attr, ignored */ + agg_node_get_prefix(rn), + 0, /* addpath_id */ + NULL, /* attr, ignored */ afi, SAFI_UNICAST, ZEBRA_ROUTE_VNC_DIRECT, BGP_ROUTE_REDISTRIBUTE, @@ -1633,7 +1633,7 @@ void vnc_direct_bgp_vpn_disable(struct bgp *bgp, afi_t afi) * caller do it? */ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi, - struct prefix *prefix, struct peer *peer, + const struct prefix *prefix, struct peer *peer, struct attr *attr) { struct vnc_export_info *eti; @@ -1732,13 +1732,14 @@ void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi, static int vncExportWithdrawTimer(struct thread *t) { struct vnc_export_info *eti = t->arg; + const struct prefix *p = agg_node_get_prefix(eti->node); /* * withdraw the route */ - bgp_withdraw(eti->peer, &eti->node->p, 0, /* addpath_id */ - NULL, /* attr, ignored */ - family2afi(eti->node->p.family), SAFI_UNICAST, eti->type, + bgp_withdraw(eti->peer, p, 0, /* addpath_id */ + NULL, /* attr, ignored */ + family2afi(p->family), SAFI_UNICAST, eti->type, eti->subtype, NULL, /* RD not used for unicast */ NULL, 0, NULL); /* tag not used for unicast, EVPN neither */ @@ -1757,7 +1758,7 @@ static int vncExportWithdrawTimer(struct thread *t) * caller do it? */ void vnc_direct_bgp_rh_del_route(struct bgp *bgp, afi_t afi, - struct prefix *prefix, struct peer *peer) + const struct prefix *prefix, struct peer *peer) { struct vnc_export_info *eti; diff --git a/bgpd/rfapi/vnc_export_bgp_p.h b/bgpd/rfapi/vnc_export_bgp_p.h index a1cb97274..bf292abb0 100644 --- a/bgpd/rfapi/vnc_export_bgp_p.h +++ b/bgpd/rfapi/vnc_export_bgp_p.h @@ -61,12 +61,12 @@ extern void vnc_direct_bgp_reexport_group_afi(struct bgp *bgp, extern void vnc_direct_bgp_rh_add_route(struct bgp *bgp, afi_t afi, - struct prefix *prefix, + const struct prefix *prefix, struct peer *peer, struct attr *attr); extern void vnc_direct_bgp_rh_del_route(struct bgp *bgp, afi_t afi, - struct prefix *prefix, + const struct prefix *prefix, struct peer *peer); extern void vnc_direct_bgp_reexport(struct bgp *bgp, afi_t afi); diff --git a/bgpd/rfapi/vnc_export_table.c b/bgpd/rfapi/vnc_export_table.c index 5e00a1017..8bf1479a2 100644 --- a/bgpd/rfapi/vnc_export_table.c +++ b/bgpd/rfapi/vnc_export_table.c @@ -34,7 +34,7 @@ #include "bgpd/rfapi/vnc_debug.h" struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type, - struct prefix *p) + const struct prefix *p) { struct agg_table *t = NULL; struct agg_node *rn = NULL; @@ -66,7 +66,7 @@ struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type, } struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type, - struct prefix *p) + const struct prefix *p) { struct agg_table *t = NULL; struct agg_node *rn = NULL; @@ -98,7 +98,7 @@ struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type, } struct vnc_export_info *vnc_eti_get(struct bgp *bgp, vnc_export_type_t etype, - struct prefix *p, struct peer *peer, + const struct prefix *p, struct peer *peer, uint8_t type, uint8_t subtype) { struct agg_node *etn; diff --git a/bgpd/rfapi/vnc_export_table.h b/bgpd/rfapi/vnc_export_table.h index fdb35e81e..5dcf4e6c1 100644 --- a/bgpd/rfapi/vnc_export_table.h +++ b/bgpd/rfapi/vnc_export_table.h @@ -46,15 +46,14 @@ struct vnc_export_info { }; extern struct agg_node *vnc_etn_get(struct bgp *bgp, vnc_export_type_t type, - struct prefix *p); + const struct prefix *p); extern struct agg_node *vnc_etn_lookup(struct bgp *bgp, vnc_export_type_t type, - struct prefix *p); + const struct prefix *p); -extern struct vnc_export_info *vnc_eti_get(struct bgp *bgp, - vnc_export_type_t etype, - struct prefix *p, struct peer *peer, - uint8_t type, uint8_t subtype); +extern struct vnc_export_info * +vnc_eti_get(struct bgp *bgp, vnc_export_type_t etype, const struct prefix *p, + struct peer *peer, uint8_t type, uint8_t subtype); extern void vnc_eti_delete(struct vnc_export_info *goner); diff --git a/bgpd/rfapi/vnc_import_bgp.c b/bgpd/rfapi/vnc_import_bgp.c index ba6ef1425..50256d994 100644 --- a/bgpd/rfapi/vnc_import_bgp.c +++ b/bgpd/rfapi/vnc_import_bgp.c @@ -104,7 +104,7 @@ uint32_t calc_local_pref(struct attr *attr, struct peer *peer) return local_pref; } -static int is_host_prefix(struct prefix *p) +static int is_host_prefix(const struct prefix *p) { switch (p->family) { case AF_INET: @@ -128,14 +128,14 @@ struct prefix_bag { static const uint8_t maskbit[] = {0x00, 0x80, 0xc0, 0xe0, 0xf0, 0xf8, 0xfc, 0xfe, 0xff}; -int vnc_prefix_cmp(void *pfx1, void *pfx2) +int vnc_prefix_cmp(const void *pfx1, const void *pfx2) { int offset; int shift; uint8_t mask; - struct prefix *p1 = pfx1; - struct prefix *p2 = pfx2; + const struct prefix *p1 = pfx1; + const struct prefix *p2 = pfx2; if (p1->family < p2->family) return -1; @@ -299,9 +299,9 @@ static void vnc_rhnck(char *tag) */ static int process_unicast_route(struct bgp *bgp, /* in */ afi_t afi, /* in */ - struct prefix *prefix, /* in */ - struct bgp_path_info *info, /* in */ - struct ecommunity **ecom, /* OUT */ + const struct prefix *prefix, /* in */ + struct bgp_path_info *info, /* in */ + struct ecommunity **ecom, /* OUT */ struct prefix *unicast_nexthop) /* OUT */ { struct rfapi_cfg *hc = bgp->rfapi_cfg; @@ -425,10 +425,10 @@ static int process_unicast_route(struct bgp *bgp, /* in */ static void vnc_import_bgp_add_route_mode_resolve_nve_one_bi( struct bgp *bgp, afi_t afi, struct bgp_path_info *bpi, /* VPN bpi */ struct prefix_rd *prd, /* RD */ - struct prefix *prefix, /* unicast route prefix */ - uint32_t *local_pref, /* NULL = no local_pref */ - uint32_t *med, /* NULL = no med */ - struct ecommunity *ecom) /* generated ecoms */ + const struct prefix *prefix, /* unicast route prefix */ + uint32_t *local_pref, /* NULL = no local_pref */ + uint32_t *med, /* NULL = no med */ + struct ecommunity *ecom) /* generated ecoms */ { struct prefix un; struct prefix nexthop; @@ -509,11 +509,12 @@ static void vnc_import_bgp_add_route_mode_resolve_nve_one_bi( } static void vnc_import_bgp_add_route_mode_resolve_nve_one_rd( - struct prefix_rd *prd, /* RD */ + struct prefix_rd *prd, /* RD */ struct bgp_table *table_rd, /* per-rd VPN route table */ - afi_t afi, struct bgp *bgp, struct prefix *prefix, /* unicast prefix */ - struct ecommunity *ecom, /* generated ecoms */ - uint32_t *local_pref, /* NULL = no local_pref */ + afi_t afi, struct bgp *bgp, + const struct prefix *prefix, /* unicast prefix */ + struct ecommunity *ecom, /* generated ecoms */ + uint32_t *local_pref, /* NULL = no local_pref */ uint32_t *med, /* NULL = no med */ struct prefix *ubpi_nexthop) /* unicast nexthop */ { @@ -552,8 +553,8 @@ static void vnc_import_bgp_add_route_mode_resolve_nve_one_rd( } static void vnc_import_bgp_add_route_mode_resolve_nve( - struct bgp *bgp, struct prefix *prefix, /* unicast prefix */ - struct bgp_path_info *info) /* unicast info */ + struct bgp *bgp, const struct prefix *prefix, /* unicast prefix */ + struct bgp_path_info *info) /* unicast info */ { afi_t afi = family2afi(prefix->family); @@ -686,7 +687,7 @@ static void vnc_import_bgp_add_route_mode_resolve_nve( static void vnc_import_bgp_add_route_mode_plain(struct bgp *bgp, - struct prefix *prefix, + const struct prefix *prefix, struct bgp_path_info *info) { afi_t afi = family2afi(prefix->family); @@ -874,10 +875,9 @@ static void vnc_import_bgp_add_route_mode_plain(struct bgp *bgp, ecommunity_free(&ecom); } -static void -vnc_import_bgp_add_route_mode_nvegroup(struct bgp *bgp, struct prefix *prefix, - struct bgp_path_info *info, - struct rfapi_nve_group_cfg *rfg) +static void vnc_import_bgp_add_route_mode_nvegroup( + struct bgp *bgp, const struct prefix *prefix, + struct bgp_path_info *info, struct rfapi_nve_group_cfg *rfg) { afi_t afi = family2afi(prefix->family); struct peer *peer = info->peer; @@ -1080,7 +1080,7 @@ vnc_import_bgp_add_route_mode_nvegroup(struct bgp *bgp, struct prefix *prefix, } static void vnc_import_bgp_del_route_mode_plain(struct bgp *bgp, - struct prefix *prefix, + const struct prefix *prefix, struct bgp_path_info *info) { struct prefix_rd prd; @@ -1153,7 +1153,7 @@ static void vnc_import_bgp_del_route_mode_plain(struct bgp *bgp, } static void vnc_import_bgp_del_route_mode_nvegroup(struct bgp *bgp, - struct prefix *prefix, + const struct prefix *prefix, struct bgp_path_info *info) { struct prefix_rd prd; @@ -1236,7 +1236,7 @@ static void vnc_import_bgp_del_route_mode_nvegroup(struct bgp *bgp, static void vnc_import_bgp_del_route_mode_resolve_nve_one_bi( struct bgp *bgp, afi_t afi, struct bgp_path_info *bpi, /* VPN bpi */ struct prefix_rd *prd, /* RD */ - struct prefix *prefix) /* unicast route prefix */ + const struct prefix *prefix) /* unicast route prefix */ { struct prefix un; @@ -1272,8 +1272,9 @@ static void vnc_import_bgp_del_route_mode_resolve_nve_one_bi( static void vnc_import_bgp_del_route_mode_resolve_nve_one_rd( struct prefix_rd *prd, struct bgp_table *table_rd, /* per-rd VPN route table */ - afi_t afi, struct bgp *bgp, struct prefix *prefix, /* unicast prefix */ - struct prefix *ubpi_nexthop) /* unicast bpi's nexthop */ + afi_t afi, struct bgp *bgp, + const struct prefix *prefix, /* unicast prefix */ + const struct prefix *ubpi_nexthop) /* unicast bpi's nexthop */ { struct bgp_node *bn; struct bgp_path_info *bpi; @@ -1312,7 +1313,7 @@ static void vnc_import_bgp_del_route_mode_resolve_nve_one_rd( static void vnc_import_bgp_del_route_mode_resolve_nve(struct bgp *bgp, afi_t afi, - struct prefix *prefix, + const struct prefix *prefix, struct bgp_path_info *info) { struct ecommunity *ecom = NULL; @@ -1396,7 +1397,7 @@ vnc_import_bgp_del_route_mode_resolve_nve(struct bgp *bgp, afi_t afi, void vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( struct bgp *bgp, struct prefix_rd *prd, /* RD */ struct bgp_table *table_rd, /* per-rd VPN route table */ - struct prefix *prefix, /* VPN prefix */ + const struct prefix *prefix, /* VPN prefix */ struct bgp_path_info *bpi) /* new VPN host route */ { afi_t afi = family2afi(prefix->family); @@ -1533,7 +1534,7 @@ void vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( void vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( struct bgp *bgp, struct prefix_rd *prd, /* RD */ struct bgp_table *table_rd, /* per-rd VPN route table */ - struct prefix *prefix, /* VPN prefix */ + const struct prefix *prefix, /* VPN prefix */ struct bgp_path_info *bpi) /* old VPN host route */ { afi_t afi = family2afi(prefix->family); @@ -1675,8 +1676,8 @@ static int is_usable_interior_route(struct bgp_path_info *bpi_interior) */ static void vnc_import_bgp_exterior_add_route_it( struct bgp *bgp, /* exterior instance, we hope */ - struct prefix *prefix, /* unicast prefix */ - struct bgp_path_info *info, /* unicast info */ + const struct prefix *prefix, /* unicast prefix */ + struct bgp_path_info *info, /* unicast info */ struct rfapi_import_table *it_only) /* NULL, or limit to this IT */ { struct rfapi *h; @@ -1844,9 +1845,9 @@ static void vnc_import_bgp_exterior_add_route_it( } void vnc_import_bgp_exterior_add_route( - struct bgp *bgp, /* exterior instance, we hope */ - struct prefix *prefix, /* unicast prefix */ - struct bgp_path_info *info) /* unicast info */ + struct bgp *bgp, /* exterior instance, we hope */ + const struct prefix *prefix, /* unicast prefix */ + struct bgp_path_info *info) /* unicast info */ { vnc_import_bgp_exterior_add_route_it(bgp, prefix, info, NULL); } @@ -1861,8 +1862,8 @@ void vnc_import_bgp_exterior_add_route( * right routes. */ void vnc_import_bgp_exterior_del_route( - struct bgp *bgp, struct prefix *prefix, /* unicast prefix */ - struct bgp_path_info *info) /* unicast info */ + struct bgp *bgp, const struct prefix *prefix, /* unicast prefix */ + struct bgp_path_info *info) /* unicast info */ { struct rfapi *h; struct rfapi_cfg *hc; @@ -2027,7 +2028,8 @@ void vnc_import_bgp_exterior_add_route_interior( struct agg_node *rn_interior, /* VPN IT node */ struct bgp_path_info *bpi_interior) /* VPN IT route */ { - afi_t afi = family2afi(rn_interior->p.family); + const struct prefix *p = agg_node_get_prefix(rn_interior); + afi_t afi = family2afi(p->family); struct agg_node *par; struct bgp_path_info *bpi_exterior; struct prefix *pfx_exterior; /* exterior pfx */ @@ -2057,13 +2059,8 @@ void vnc_import_bgp_exterior_add_route_interior( } /*debugging */ - { - char str_pfx[PREFIX_STRLEN]; - - prefix2str(&rn_interior->p, str_pfx, sizeof(str_pfx)); - vnc_zlog_debug_verbose("%s: interior prefix=%s, bpi type=%d", - __func__, str_pfx, bpi_interior->type); - } + vnc_zlog_debug_verbose("%s: interior prefix=%pRN, bpi type=%d", + __func__, rn_interior, bpi_interior->type); if (RFAPI_HAS_MONITOR_EXTERIOR(rn_interior)) { @@ -2178,7 +2175,7 @@ void vnc_import_bgp_exterior_add_route_interior( rfapiUnicastNexthop2Prefix(afi, bpi_exterior->attr, &pfx_nexthop); - if (prefix_match(&rn_interior->p, &pfx_nexthop)) { + if (prefix_match(p, &pfx_nexthop)) { struct bgp_path_info *bpi; struct prefix_rd *prd; @@ -2321,7 +2318,7 @@ void vnc_import_bgp_exterior_add_route_interior( rfapiUnicastNexthop2Prefix(afi, bpi_exterior->attr, &pfx_nexthop); - if (prefix_match(&rn_interior->p, &pfx_nexthop)) { + if (prefix_match(p, &pfx_nexthop)) { struct prefix_rd *prd; struct attr new_attr; @@ -2409,7 +2406,8 @@ void vnc_import_bgp_exterior_del_route_interior( struct agg_node *rn_interior, /* VPN IT node */ struct bgp_path_info *bpi_interior) /* VPN IT route */ { - afi_t afi = family2afi(rn_interior->p.family); + const struct prefix *p = agg_node_get_prefix(rn_interior); + afi_t afi = family2afi(p->family); struct agg_node *par; struct bgp_path_info *bpi_exterior; struct prefix *pfx_exterior; /* exterior pfx */ @@ -2443,14 +2441,8 @@ void vnc_import_bgp_exterior_del_route_interior( } /*debugging */ - { - char str_pfx[PREFIX_STRLEN]; - - prefix2str(&rn_interior->p, str_pfx, sizeof(str_pfx)); - - vnc_zlog_debug_verbose("%s: interior prefix=%s, bpi type=%d", - __func__, str_pfx, bpi_interior->type); - } + vnc_zlog_debug_verbose("%s: interior prefix=%pRN, bpi type=%d", + __func__, rn_interior, bpi_interior->type); /* * Remove constructed routes based on the deleted interior route @@ -2597,7 +2589,7 @@ void vnc_import_bgp_exterior_del_route_interior( * Generic add/delete unicast routes ***********************************************************************/ -void vnc_import_bgp_add_route(struct bgp *bgp, struct prefix *prefix, +void vnc_import_bgp_add_route(struct bgp *bgp, const struct prefix *prefix, struct bgp_path_info *info) { afi_t afi = family2afi(prefix->family); @@ -2666,7 +2658,7 @@ void vnc_import_bgp_add_route(struct bgp *bgp, struct prefix *prefix, /* * "Withdrawing a Route" import process */ -void vnc_import_bgp_del_route(struct bgp *bgp, struct prefix *prefix, +void vnc_import_bgp_del_route(struct bgp *bgp, const struct prefix *prefix, struct bgp_path_info *info) /* unicast info */ { afi_t afi = family2afi(prefix->family); diff --git a/bgpd/rfapi/vnc_import_bgp.h b/bgpd/rfapi/vnc_import_bgp.h index 3db6f4010..ab2ec1a74 100644 --- a/bgpd/rfapi/vnc_import_bgp.h +++ b/bgpd/rfapi/vnc_import_bgp.h @@ -32,12 +32,14 @@ extern uint32_t calc_local_pref(struct attr *attr, struct peer *peer); -extern int vnc_prefix_cmp(void *pfx1, void *pfx2); +extern int vnc_prefix_cmp(const void *pfx1, const void *pfx2); -extern void vnc_import_bgp_add_route(struct bgp *bgp, struct prefix *prefix, +extern void vnc_import_bgp_add_route(struct bgp *bgp, + const struct prefix *prefix, struct bgp_path_info *info); -extern void vnc_import_bgp_del_route(struct bgp *bgp, struct prefix *prefix, +extern void vnc_import_bgp_del_route(struct bgp *bgp, + const struct prefix *prefix, struct bgp_path_info *info); extern void vnc_import_bgp_redist_enable(struct bgp *bgp, afi_t afi); @@ -51,23 +53,23 @@ extern void vnc_import_bgp_exterior_redist_disable(struct bgp *bgp, afi_t afi); extern void vnc_import_bgp_exterior_add_route( struct bgp *bgp, /* exterior instance, we hope */ - struct prefix *prefix, /* unicast prefix */ + const struct prefix *prefix, /* unicast prefix */ struct bgp_path_info *info); /* unicast info */ extern void vnc_import_bgp_exterior_del_route( - struct bgp *bgp, struct prefix *prefix, /* unicast prefix */ - struct bgp_path_info *info); /* unicast info */ + struct bgp *bgp, const struct prefix *prefix, /* unicast prefix */ + struct bgp_path_info *info); /* unicast info */ extern void vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( struct bgp *bgp, struct prefix_rd *prd, /* RD */ struct bgp_table *table_rd, /* per-rd VPN route table */ - struct prefix *prefix, /* VPN prefix */ + const struct prefix *prefix, /* VPN prefix */ struct bgp_path_info *bpi); /* new VPN host route */ extern void vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( struct bgp *bgp, struct prefix_rd *prd, /* RD */ struct bgp_table *table_rd, /* per-rd VPN route table */ - struct prefix *prefix, /* VPN prefix */ + const struct prefix *prefix, /* VPN prefix */ struct bgp_path_info *bpi); /* old VPN host route */ #endif /* _QUAGGA_RFAPI_VNC_IMPORT_BGP_H_ */ diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c index 80a590f56..ca4a32822 100644 --- a/bgpd/rfapi/vnc_zebra.c +++ b/bgpd/rfapi/vnc_zebra.c @@ -380,7 +380,7 @@ static int vnc_zebra_read_route(ZAPI_CALLBACK_ARGS) /* * low-level message builder */ -static void vnc_zebra_route_msg(struct prefix *p, unsigned int nhp_count, +static void vnc_zebra_route_msg(const struct prefix *p, unsigned int nhp_count, void *nhp_ary, int add) /* 1 = add, 0 = del */ { struct zapi_route api; @@ -560,7 +560,7 @@ static void vnc_zebra_add_del_prefix(struct bgp *bgp, int add) /* !0 = add, 0 = del */ { struct list *nves; - + const struct prefix *p = agg_node_get_prefix(rn); unsigned int nexthop_count = 0; void *nh_ary = NULL; void *nhp_ary = NULL; @@ -570,15 +570,15 @@ static void vnc_zebra_add_del_prefix(struct bgp *bgp, if (zclient_vnc->sock < 0) return; - if (rn->p.family != AF_INET && rn->p.family != AF_INET6) { + if (p->family != AF_INET && p->family != AF_INET6) { flog_err(EC_LIB_DEVELOPMENT, "%s: invalid route node addr family", __func__); return; } - if (!vrf_bitmap_check(zclient_vnc->redist[family2afi(rn->p.family)] - [ZEBRA_ROUTE_VNC], - VRF_DEFAULT)) + if (!vrf_bitmap_check( + zclient_vnc->redist[family2afi(p->family)][ZEBRA_ROUTE_VNC], + VRF_DEFAULT)) return; if (!bgp->rfapi_cfg) { @@ -592,17 +592,16 @@ static void vnc_zebra_add_del_prefix(struct bgp *bgp, return; } - import_table_to_nve_list_zebra(bgp, import_table, &nves, rn->p.family); + import_table_to_nve_list_zebra(bgp, import_table, &nves, p->family); if (nves) { - nve_list_to_nh_array(rn->p.family, nves, &nexthop_count, - &nh_ary, &nhp_ary); + nve_list_to_nh_array(p->family, nves, &nexthop_count, &nh_ary, + &nhp_ary); list_delete(&nves); if (nexthop_count) - vnc_zebra_route_msg(&rn->p, nexthop_count, nhp_ary, - add); + vnc_zebra_route_msg(p, nexthop_count, nhp_ary, add); } XFREE(MTYPE_TMP, nhp_ary); @@ -695,15 +694,14 @@ static void vnc_zebra_add_del_nve(struct bgp *bgp, struct rfapi_descriptor *rfd, */ for (rn = agg_route_top(rt); rn; rn = agg_route_next(rn)) { - - if (rn->info) { - - vnc_zlog_debug_verbose( - "%s: sending %s", __func__, - (add ? "add" : "del")); - vnc_zebra_route_msg(&rn->p, 1, &pAddr, - add); - } + if (!rn->info) + continue; + + vnc_zlog_debug_verbose("%s: sending %s", + __func__, + (add ? "add" : "del")); + vnc_zebra_route_msg(agg_node_get_prefix(rn), 1, + &pAddr, add); } } } @@ -778,9 +776,9 @@ static void vnc_zebra_add_del_group_afi(struct bgp *bgp, for (rn = agg_route_top(rt); rn; rn = agg_route_next(rn)) { if (rn->info) { - vnc_zebra_route_msg(&rn->p, - nexthop_count, - nhp_ary, add); + vnc_zebra_route_msg( + agg_node_get_prefix(rn), + nexthop_count, nhp_ary, add); } } } diff --git a/configure.ac b/configure.ac index 0d56b60e7..41d1911c3 100755 --- a/configure.ac +++ b/configure.ac @@ -1122,16 +1122,6 @@ case "$host_os" in AC_DEFINE([OPEN_BSD], [1], [OpenBSD]) AC_DEFINE([KAME], [1], [KAME IPv6]) AC_DEFINE([BSD_V6_SYSCTL], [1], [BSD v6 sysctl to turn on and off forwarding]) - - if test "$enable_pimd" != "no"; then - case "$host_os" in - openbsd6.0) - ;; - openbsd[6-9]*) - AC_MSG_FAILURE([pimd cannot be enabled as PIM support has been removed from OpenBSD 6.1]) - ;; - esac - fi ;; *) AC_MSG_RESULT([BSD]) @@ -1791,6 +1781,42 @@ if test "$enable_rpki" = "yes"; then ) fi +dnl ------------------------------------ +dnl pimd is not supported on OpenBSD and MacOS +dnl ------------------------------------ +if test "$enable_pimd" != "no"; then +AC_MSG_CHECKING([for pimd OS support]) +case "$host_os" in + darwin*) + AC_MSG_RESULT([no]) + enable_pimd="no" + ;; + openbsd*) + AC_MSG_RESULT([no]) + enable_pimd="no" + ;; + *) + AC_MSG_RESULT([yes]) + ;; +esac +fi + +dnl ------------------------------------- +dnl VRRP is only supported on linux +dnl ------------------------------------- +if test "$enable_vrrpd" != "no"; then +AC_MSG_CHECKING([for VRRP OS support]) +case "$host_os" in + linux*) + AC_MSG_RESULT([yes]) + ;; + *) + AC_MSG_RESULT([no]) + enable_vrrpd="no" + ;; +esac +fi + dnl ------------------------------------------ dnl Check whether rtrlib was build with ssh support dnl ------------------------------------------ diff --git a/doc/developer/building-frr-for-archlinux.rst b/doc/developer/building-frr-for-archlinux.rst new file mode 100644 index 000000000..7ede35ad9 --- /dev/null +++ b/doc/developer/building-frr-for-archlinux.rst @@ -0,0 +1,129 @@ +Arch Linux +================ + +Installing Dependencies +----------------------- + +.. code-block:: console + + sudo pacman -Syu + sudo pacman -S \ + git autoconf automake libtool make cmake pcre readline texinfo \ + pkg-config pam json-c bison flex python-pytest \ + c-ares python systemd python2-ipaddress python-sphinx \ + systemd-libs net-snmp perl libcap + +.. include:: building-libyang.rst + +Protobuf +^^^^^^^^ + +.. code-block:: console + + sudo pacman -S protobuf-c + +ZeroMQ +^^^^^^ + +.. code-block:: console + + sudo pacman -S zeromq + +Building & Installing FRR +------------------------- + +Add FRR user and groups +^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: console + + sudo groupadd -r -g 92 frr + sudo groupadd -r -g 85 frrvty + sudo useradd --system -g frr --home-dir /var/run/frr/ \ + -c "FRR suite" --shell /sbin/nologin frr + sudo usermod -a -G frrvty frr + +Compile +^^^^^^^ + +.. include:: include-compile.rst + +Install FRR configuration files +^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: console + + sudo install -m 775 -o frr -g frr -d /var/log/frr + sudo install -m 775 -o frr -g frrvty -d /etc/frr + sudo install -m 640 -o frr -g frrvty tools/etc/frr/vtysh.conf /etc/frr/vtysh.conf + sudo install -m 640 -o frr -g frr tools/etc/frr/frr.conf /etc/frr/frr.conf + sudo install -m 640 -o frr -g frr tools/etc/frr/daemons.conf /etc/frr/daemons.conf + sudo install -m 640 -o frr -g frr tools/etc/frr/daemons /etc/frr/daemons + +Tweak sysctls +^^^^^^^^^^^^^ + +Some sysctls need to be changed in order to enable IPv4/IPv6 forwarding and +MPLS (if supported by your platform). If your platform does not support MPLS, +skip the MPLS related configuration in this section. + +Edit :file:`/etc/sysctl.conf`[*Create the file if it doesn't exist*] and +append the following values (ignore the other settings): + +:: + + # Enable packet forwarding for IPv4 + net.ipv4.ip_forward=1 + + # Enable packet forwarding for IPv6 + net.ipv6.conf.all.forwarding=1 + +Reboot or use ``sysctl -p`` to apply the same config to the running system. + +Add MPLS kernel modules +""""""""""""""""""""""" + +To +enable, add the following lines to :file:`/etc/modules-load.d/modules.conf`: + +:: + + # Load MPLS Kernel Modules + mpls_router + mpls_iptunnel + + +And load the kernel modules on the running system: + +.. code-block:: console + + sudo modprobe mpls-router mpls-iptunnel + +Enable MPLS Forwarding +"""""""""""""""""""""" + +Edit :file:`/etc/sysctl.conf` and the following lines. Make sure to add a line +equal to :file:`net.mpls.conf.eth0.input` for each interface used with MPLS. + +:: + + # Enable MPLS Label processing on all interfaces + net.mpls.conf.eth0.input=1 + net.mpls.conf.eth1.input=1 + net.mpls.conf.eth2.input=1 + net.mpls.platform_labels=100000 + +Install service files +^^^^^^^^^^^^^^^^^^^^^ + +.. code-block:: console + + sudo install -m 644 tools/frr.service /etc/systemd/system/frr.service + sudo systemctl enable frr + +Start FRR +^^^^^^^^^ + +.. code-block:: shell + + systemctl start frr diff --git a/doc/developer/building-frr-for-centos6.rst b/doc/developer/building-frr-for-centos6.rst index 04c6b922c..b730a5ee3 100644 --- a/doc/developer/building-frr-for-centos6.rst +++ b/doc/developer/building-frr-for-centos6.rst @@ -116,7 +116,19 @@ Update rpm database & Install newer sphinx sudo yum update sudo yum install python27-sphinx -.. include:: building-libyang.rst +Install libyang and its dependencies: + +.. code-block:: shell + + sudo yum install pcre-devel doxygen cmake + git clone https://github.com/CESNET/libyang.git + cd libyang + git checkout 090926a89d59a3c4000719505d563aaf6ac60f2 + mkdir build ; cd build + cmake -DENABLE_LYD_PRIV=ON -DCMAKE_INSTALL_PREFIX:PATH=/usr -D CMAKE_BUILD_TYPE:String="Release" .. + make build-rpm + sudo yum install ./rpms/RPMS/x86_64/libyang-0.16.111-0.x86_64.rpm ./rpms/RPMS/x86_64/libyang-devel-0.16.111-0.x86_64.rpm + cd ../.. Get FRR, compile it and install it (from Git) --------------------------------------------- diff --git a/doc/developer/building.rst b/doc/developer/building.rst index 859f61231..ef55954ac 100644 --- a/doc/developer/building.rst +++ b/doc/developer/building.rst @@ -26,3 +26,4 @@ Building FRR building-frr-for-ubuntu1404 building-frr-for-ubuntu1604 building-frr-for-ubuntu1804 + building-frr-for-archlinux diff --git a/doc/user/ldpd.rst b/doc/user/ldpd.rst index 977195d6a..2df4ba300 100644 --- a/doc/user/ldpd.rst +++ b/doc/user/ldpd.rst @@ -108,6 +108,11 @@ LDP Configuration The following command located under MPLS router node configures the MPLS router-id of the local device. +.. index:: [no] ordered-control +.. clicmd:: [no] ordered-control + + Configure LDP Ordered Label Distribution Control. + .. index:: [no] address-family [ipv4 | ipv6] .. clicmd:: [no] address-family [ipv4 | ipv6] diff --git a/doc/user/nhrpd.rst b/doc/user/nhrpd.rst index 95ef9cb7e..8d3bea7c9 100644 --- a/doc/user/nhrpd.rst +++ b/doc/user/nhrpd.rst @@ -199,6 +199,31 @@ NHRP Events Configure the Unix path for the event socket. +.. _show-nhrp: + +Show NHRP +========== + +.. index:: show [ip|ipv6] nhrp cache [json] +.. clicmd:: show [ip|ipv6] nhrp cache [json] + + Dump the cache entries. + +.. index:: show [ip|ipv6] nhrp opennhrp [json] +.. clicmd:: show [ip|ipv6] nhrp opennhrp [json] + + Dump the cache entries with opennhrp format. + +.. index:: show [ip|ipv6] nhrp nhs [json] +.. clicmd:: show [ip|ipv6] nhrp nhs [json] + + Dump the hub context. + +.. index:: show dmvpn [json] +.. clicmd:: show dmvpn [json] + + Dump the security contexts. + Configuration Example ===================== diff --git a/doc/user/overview.rst b/doc/user/overview.rst index e31799c1e..c9934d1c6 100644 --- a/doc/user/overview.rst +++ b/doc/user/overview.rst @@ -306,6 +306,8 @@ BGP :t:`The Resource Public Key Infrastructure (RPKI) to Router Protocol. R. Bush, R. Austein. January 2013.` - :rfc:`6811` :t:`BGP Prefix Origin Validation. P. Mohapatra, J. Scudder, D. Ward, R. Bush, R. Austein. January 2013.` +- :rfc:`7606` + :t:`Revised Error Handling for BGP UPDATE Messages. E. Chen, J. Scudder, P. Mohapatra, K. Patel. August 2015.` - :rfc:`7607` :t:`Codification of AS 0 Processing. W. Kumari, R. Bush, H. Schiller, K. Patel. August 2015.` - :rfc:`7611` diff --git a/isisd/fabricd.c b/isisd/fabricd.c index b9c27d51b..28cc65380 100644 --- a/isisd/fabricd.c +++ b/isisd/fabricd.c @@ -122,9 +122,9 @@ static bool neighbor_entry_hash_cmp(const void *a, const void *b) return memcmp(na->id, nb->id, sizeof(na->id)) == 0; } -static int neighbor_entry_list_cmp(void *a, void *b) +static int neighbor_entry_list_cmp(const void *a, const void *b) { - struct neighbor_entry *na = a, *nb = b; + const struct neighbor_entry *na = a, *nb = b; return -memcmp(na->id, nb->id, sizeof(na->id)); } diff --git a/isisd/isis_bpf.c b/isisd/isis_bpf.c index e916a5088..19695e7ab 100644 --- a/isisd/isis_bpf.c +++ b/isisd/isis_bpf.c @@ -73,7 +73,7 @@ static const uint8_t ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; static const uint8_t ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; #endif -static char sock_buff[8192]; +static char sock_buff[16384]; static int open_bpf_dev(struct isis_circuit *circuit) { diff --git a/isisd/isis_cli.c b/isisd/isis_cli.c index 3144b3c28..fc70a344c 100644 --- a/isisd/isis_cli.c +++ b/isisd/isis_cli.c @@ -1398,8 +1398,8 @@ void cli_show_ip_isis_metric(struct vty *vty, struct lyd_node *dnode, if (strmatch(l1, l2)) vty_out(vty, " isis metric %s\n", l1); else { - vty_out(vty, " isis metric %s level-1\n", l1); - vty_out(vty, " isis metric %s level-2\n", l2); + vty_out(vty, " isis metric level-1 %s\n", l1); + vty_out(vty, " isis metric level-2 %s\n", l2); } } diff --git a/isisd/isis_dlpi.c b/isisd/isis_dlpi.c index ea16f4af7..5c15d1d29 100644 --- a/isisd/isis_dlpi.c +++ b/isisd/isis_dlpi.c @@ -62,7 +62,7 @@ static const uint8_t ALL_ISS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x05}; static const uint8_t ALL_ESS[6] = {0x09, 0x00, 0x2B, 0x00, 0x00, 0x04}; #endif -static uint8_t sock_buff[8192]; +static uint8_t sock_buff[16384]; static unsigned short pf_filter[] = { ENF_PUSHWORD + 0, /* Get the SSAP/DSAP values */ diff --git a/isisd/isis_spf_private.h b/isisd/isis_spf_private.h index a8185a8be..05aae14b9 100644 --- a/isisd/isis_spf_private.h +++ b/isisd/isis_spf_private.h @@ -117,11 +117,11 @@ static bool isis_vertex_queue_hash_cmp(const void *a, const void *b) * Compares vertizes for sorting in the TENT list. Returns true * if candidate should be considered before current, false otherwise. */ -__attribute__((__unused__)) -static int isis_vertex_queue_tent_cmp(void *a, void *b) +__attribute__((__unused__)) static int isis_vertex_queue_tent_cmp(const void *a, + const void *b) { - struct isis_vertex *va = a; - struct isis_vertex *vb = b; + const struct isis_vertex *va = a; + const struct isis_vertex *vb = b; if (va->d_N < vb->d_N) return -1; diff --git a/ldpd/lde.c b/ldpd/lde.c index 5f9403132..64c12e0df 100644 --- a/ldpd/lde.c +++ b/ldpd/lde.c @@ -61,6 +61,8 @@ static void lde_label_list_init(void); static int lde_get_label_chunk(void); static void on_get_label_chunk_response(uint32_t start, uint32_t end); static uint32_t lde_get_next_label(void); +static bool lde_fec_connected(const struct fec_node *); +static bool lde_fec_outside_mpls_network(const struct fec_node *); RB_GENERATE(nbr_tree, lde_nbr, entry, lde_nbr_compare) RB_GENERATE(lde_map_head, lde_map, entry, lde_map_compare) @@ -658,18 +660,31 @@ lde_acl_check(char *acl_name, int af, union ldpd_addr *addr, uint8_t prefixlen) return ldp_acl_request(iev_main_sync, acl_name, af, addr, prefixlen); } +static bool lde_fec_connected(const struct fec_node *fn) +{ + struct fec_nh *fnh; + + LIST_FOREACH(fnh, &fn->nexthops, entry) + if (fnh->flags & F_FEC_NH_CONNECTED) + return true; + + return false; +} + +static bool lde_fec_outside_mpls_network(const struct fec_node *fn) +{ + struct fec_nh *fnh; + + LIST_FOREACH(fnh, &fn->nexthops, entry) + if (!(fnh->flags & F_FEC_NH_NO_LDP)) + return false; + + return true; +} + uint32_t lde_update_label(struct fec_node *fn) { - struct fec_nh *fnh; - int connected = 0; - - LIST_FOREACH(fnh, &fn->nexthops, entry) { - if (fnh->flags & F_FEC_NH_CONNECTED) { - connected = 1; - break; - } - } /* should we allocate a label for this fec? */ switch (fn->fec.type) { @@ -695,7 +710,14 @@ lde_update_label(struct fec_node *fn) break; } - if (connected) { + /* + * If connected interface act as egress for fec. + * If LDP is not configured on an interface but there + * are other NHs with interfaces configured with LDP + * then don't act as an egress for the fec, otherwise + * act as an egress for the fec + */ + if (lde_fec_connected(fn) || lde_fec_outside_mpls_network(fn)) { /* choose implicit or explicit-null depending on configuration */ switch (fn->fec.type) { case FEC_TYPE_IPV4: @@ -735,6 +757,13 @@ lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh) struct zapi_pw zpw; struct l2vpn_pw *pw; + /* + * Ordered Control: don't program label into HW until a + * labelmap msg has been received from upstream router + */ + if (fnh->flags & F_FEC_NH_DEFER) + return; + switch (fn->fec.type) { case FEC_TYPE_IPV4: memset(&kr, 0, sizeof(kr)); @@ -901,6 +930,27 @@ lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn, int single) struct lde_req *lre; struct map map; struct l2vpn_pw *pw; + struct fec_nh *fnh; + bool allow = false; + + /* + * Ordered Control: do not send a labelmap msg until + * a labelmap message is received from downstream router + * and don't send labelmap back to downstream router + */ + if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + LIST_FOREACH(fnh, &fn->nexthops, entry) { + if (fnh->flags & F_FEC_NH_DEFER) + continue; + + if (lde_address_find(ln, fnh->af, &fnh->nexthop)) + return; + allow = true; + break; + } + if (!allow) + return; + } /* * We shouldn't send a new label mapping if we have a pending @@ -1241,6 +1291,7 @@ lde_nbr_del(struct lde_nbr *ln) struct fec_node *fn; struct fec_nh *fnh; struct l2vpn_pw *pw; + struct lde_nbr *lnbr; if (ln == NULL) return; @@ -1256,6 +1307,25 @@ lde_nbr_del(struct lde_nbr *ln) if (!lde_address_find(ln, fnh->af, &fnh->nexthop)) continue; + + /* + * Ordered Control: must mark any non-connected + * NH to wait until we receive a labelmap msg + * before installing in kernel and sending to + * peer, must do this as NHs are not removed + * when lsps go down. Also send label withdraw + * to other neighbors for all fecs from neighbor + * going down + */ + if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + fnh->flags |= F_FEC_NH_DEFER; + + RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) { + if (ln->peerid == lnbr->peerid) + continue; + lde_send_labelwithdraw(lnbr, fn, NULL, NULL); + } + } break; case FEC_TYPE_PWID: if (f->u.pwid.lsr_id.s_addr != ln->id.s_addr) diff --git a/ldpd/lde.h b/ldpd/lde.h index ce466c16b..a099f8d28 100644 --- a/ldpd/lde.h +++ b/ldpd/lde.h @@ -114,6 +114,8 @@ struct fec_nh { }; #define F_FEC_NH_NEW 0x01 #define F_FEC_NH_CONNECTED 0x02 +#define F_FEC_NH_DEFER 0x04 /* running ordered control */ +#define F_FEC_NH_NO_LDP 0x08 /* no ldp on this interface */ struct fec_node { struct fec fec; diff --git a/ldpd/lde_lib.c b/ldpd/lde_lib.c index eb1a6d943..8f524e0aa 100644 --- a/ldpd/lde_lib.c +++ b/ldpd/lde_lib.c @@ -20,6 +20,7 @@ #include <zebra.h> #include "ldpd.h" +#include "ldpe.h" #include "lde.h" #include "log.h" @@ -325,6 +326,7 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop, { struct fec_node *fn; struct fec_nh *fnh; + struct iface *iface; fn = (struct fec_node *)fec_find(&ft, fec); if (fn == NULL) @@ -333,9 +335,21 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop, fn->data = data; fnh = fec_nh_find(fn, af, nexthop, ifindex, route_type, route_instance); - if (fnh == NULL) + if (fnh == NULL) { fnh = fec_nh_add(fn, af, nexthop, ifindex, route_type, route_instance); + /* + * Ordered Control: if not a connected route and not a route + * learned over an interface not running LDP and not a PW + * then mark to wait until we receive labelmap msg before + * installing in kernel and sending to peer + */ + iface = if_lookup(ldeconf, ifindex); + if ((ldeconf->flags & F_LDPD_ORDERED_CONTROL) && + !connected && iface != NULL && fec->type != FEC_TYPE_PWID) + fnh->flags |= F_FEC_NH_DEFER; + } + fnh->flags |= F_FEC_NH_NEW; if (connected) fnh->flags |= F_FEC_NH_CONNECTED; @@ -374,15 +388,25 @@ lde_kernel_update(struct fec *fec) struct fec_nh *fnh, *safe; struct lde_nbr *ln; struct lde_map *me; + struct iface *iface; fn = (struct fec_node *)fec_find(&ft, fec); if (fn == NULL) return; LIST_FOREACH_SAFE(fnh, &fn->nexthops, entry, safe) { - if (fnh->flags & F_FEC_NH_NEW) + if (fnh->flags & F_FEC_NH_NEW) { fnh->flags &= ~F_FEC_NH_NEW; - else { + /* + * if LDP configured on interface or a static route + * clear flag else treat fec as a connected route + */ + iface = if_lookup(ldeconf,fnh->ifindex); + if (iface || fnh->route_type == ZEBRA_ROUTE_STATIC) + fnh->flags &=~F_FEC_NH_NO_LDP; + else + fnh->flags |= F_FEC_NH_NO_LDP; + } else { lde_send_delete_klabel(fn, fnh); fec_nh_del(fnh); } @@ -445,6 +469,7 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln) struct lde_req *lre; struct lde_map *me; struct l2vpn_pw *pw; + bool send_map = false; lde_map2fec(map, ln->id, &fec); @@ -525,6 +550,15 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln) if (!lde_address_find(ln, fnh->af, &fnh->nexthop)) continue; + /* + * Ordered Control: labelmap msg received from + * NH so clear flag and send labelmap msg to + * peer + */ + if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + send_map = true; + fnh->flags &= ~F_FEC_NH_DEFER; + } fnh->remote_label = map->label; lde_send_change_klabel(fn, fnh); break; @@ -558,6 +592,15 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln) * loop detection. LMp.28 - LMp.30 are unnecessary because we are * merging capable. */ + + /* + * Ordered Control: just received a labelmap for this fec from NH so + * need to send labelmap to all peers + * LMp.20 - LMp21 Execute procedure to send Label Mapping + */ + if (send_map && fn->local_label != NO_LABEL) + RB_FOREACH(ln, nbr_tree, &lde_nbrs) + lde_send_labelmapping(ln, fn, 1); } void @@ -757,6 +800,7 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln) struct fec_nh *fnh; struct lde_map *me; struct l2vpn_pw *pw; + struct lde_nbr *lnbr; /* wildcard label withdraw */ if (map->type == MAP_TYPE_WILDCARD || @@ -803,6 +847,26 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln) if (me && (map->label == NO_LABEL || map->label == me->map.label)) /* LWd.4: remove record of previously received lbl mapping */ lde_map_del(ln, me, 0); + + /* Ordered Control: additional withdraw steps */ + if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + /* LWd.8: for each neighbor other that src of withdraw msg */ + RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) { + if (ln->peerid == lnbr->peerid) + continue; + + /* LWd.9: check if previously sent a label mapping */ + me = (struct lde_map *)fec_find(&lnbr->sent_map, + &fn->fec); + /* + * LWd.10: does label sent to peer "map" to withdraw + * label + */ + if (me) + /* LWd.11: send label withdraw */ + lde_send_labelwithdraw(lnbr, fn, NULL, NULL); + } + } } void @@ -813,6 +877,7 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) struct fec_nh *fnh; struct lde_map *me; struct l2vpn_pw *pw; + struct lde_nbr *lnbr; /* LWd.2: send label release */ lde_send_labelrelease(ln, NULL, map, map->label); @@ -859,6 +924,26 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) * label mapping */ lde_map_del(ln, me, 0); + + /* Ordered Control: additional withdraw steps */ + if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) { + /* LWd.8: for each neighbor other that src of withdraw msg */ + RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) { + if (ln->peerid == lnbr->peerid) + continue; + + /* LWd.9: check if previously sent a label mapping */ + me = (struct lde_map *)fec_find(&lnbr->sent_map, + &fn->fec); + /* + * LWd.10: does label sent to peer "map" to withdraw + * label + */ + if (me) + /* LWd.11: send label withdraw */ + lde_send_labelwithdraw(lnbr, fn, NULL, NULL); + } + } } } diff --git a/ldpd/ldp_vty.h b/ldpd/ldp_vty.h index 5e9df4aaf..af5f1d561 100644 --- a/ldpd/ldp_vty.h +++ b/ldpd/ldp_vty.h @@ -52,6 +52,7 @@ 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_ordered_control(struct vty *, const char *); 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 *); diff --git a/ldpd/ldp_vty_cmds.c b/ldpd/ldp_vty_cmds.c index c24e1917c..c10c6ae35 100644 --- a/ldpd/ldp_vty_cmds.c +++ b/ldpd/ldp_vty_cmds.c @@ -221,6 +221,15 @@ DEFPY (ldp_router_id, return (ldp_vty_router_id(vty, no, address)); } +DEFPY (ldp_ordered_control, + ldp_ordered_control_cmd, + "[no] ordered-control", + NO_STR + "Configure LDP ordered label distribution control mode\n") +{ + return (ldp_vty_ordered_control(vty, no)); +} + DEFPY (ldp_discovery_targeted_hello_accept, ldp_discovery_targeted_hello_accept_cmd, "[no] discovery targeted-hello accept [from <(1-199)|(1300-2699)|WORD>$from_acl]", @@ -807,6 +816,7 @@ ldp_vty_init (void) install_element(LDP_NODE, &ldp_neighbor_session_holdtime_cmd); install_element(LDP_NODE, &ldp_neighbor_ttl_security_cmd); install_element(LDP_NODE, &ldp_router_id_cmd); + install_element(LDP_NODE, &ldp_ordered_control_cmd); install_element(LDP_IPV4_NODE, &ldp_discovery_link_holdtime_cmd); install_element(LDP_IPV4_NODE, &ldp_discovery_targeted_holdtime_cmd); diff --git a/ldpd/ldp_vty_conf.c b/ldpd/ldp_vty_conf.c index 816fcc64b..05b896256 100644 --- a/ldpd/ldp_vty_conf.c +++ b/ldpd/ldp_vty_conf.c @@ -278,6 +278,9 @@ ldp_config_write(struct vty *vty) if (ldpd_conf->flags & F_LDPD_DS_CISCO_INTEROP) vty_out (vty, " dual-stack cisco-interop\n"); + if (ldpd_conf->flags & F_LDPD_ORDERED_CONTROL) + vty_out (vty, " ordered-control\n"); + RB_FOREACH(nbrp, nbrp_head, &ldpd_conf->nbrp_tree) { if (nbrp->flags & F_NBRP_KEEPALIVE) vty_out (vty, " neighbor %s session holdtime %u\n", @@ -997,6 +1000,19 @@ ldp_vty_router_id(struct vty *vty, const char *negate, struct in_addr address) } int +ldp_vty_ordered_control(struct vty *vty, const char *negate) +{ + if (negate) + vty_conf->flags &= ~F_LDPD_ORDERED_CONTROL; + else + vty_conf->flags |= F_LDPD_ORDERED_CONTROL; + + ldp_config_apply(vty, vty_conf); + + return (CMD_SUCCESS); +} + +int ldp_vty_ds_cisco_interop(struct vty *vty, const char * negate) { if (negate) diff --git a/ldpd/ldpd.c b/ldpd/ldpd.c index 78b1c3e54..0f9f055d0 100644 --- a/ldpd/ldpd.c +++ b/ldpd/ldpd.c @@ -1285,6 +1285,14 @@ merge_global(struct ldpd_conf *conf, struct ldpd_conf *xconf) conf->rtr_id = xconf->rtr_id; } + /* + * Configuration of ordered-control or independent-control + * requires resetting all neighborships. + */ + if ((conf->flags & F_LDPD_ORDERED_CONTROL) != + (xconf->flags & F_LDPD_ORDERED_CONTROL)) + ldpe_reset_nbrs(AF_UNSPEC); + conf->lhello_holdtime = xconf->lhello_holdtime; conf->lhello_interval = xconf->lhello_interval; conf->thello_holdtime = xconf->thello_holdtime; diff --git a/ldpd/ldpd.h b/ldpd/ldpd.h index 006780f03..a736b4ca3 100644 --- a/ldpd/ldpd.h +++ b/ldpd/ldpd.h @@ -511,6 +511,8 @@ DECLARE_QOBJ_TYPE(ldpd_conf) #define F_LDPD_NO_FIB_UPDATE 0x0001 #define F_LDPD_DS_CISCO_INTEROP 0x0002 #define F_LDPD_ENABLED 0x0004 +#define F_LDPD_ORDERED_CONTROL 0x0008 + struct ldpd_af_global { struct thread *disc_ev; diff --git a/lib/agg_table.h b/lib/agg_table.h index 40ffe8c75..9fddc975e 100644 --- a/lib/agg_table.h +++ b/lib/agg_table.h @@ -86,13 +86,13 @@ static inline struct agg_node *agg_route_next(struct agg_node *node) } static inline struct agg_node *agg_node_get(struct agg_table *table, - struct prefix *p) + const struct prefix *p) { return agg_node_from_rnode(route_node_get(table->route_table, p)); } static inline struct agg_node * -agg_node_lookup(const struct agg_table *const table, struct prefix *p) +agg_node_lookup(const struct agg_table *const table, const struct prefix *p) { return agg_node_from_rnode(route_node_lookup(table->route_table, p)); } @@ -109,7 +109,7 @@ static inline struct agg_node *agg_route_next_until(struct agg_node *node, } static inline struct agg_node *agg_node_match(struct agg_table *table, - struct prefix *p) + const struct prefix *p) { return agg_node_from_rnode(route_node_match(table->route_table, p)); } @@ -155,6 +155,12 @@ static inline struct agg_table *agg_get_table(struct agg_node *node) return (struct agg_table *)route_table_get_info(node->table); } +static inline const struct prefix * +agg_node_get_prefix(const struct agg_node *node) +{ + return &node->p; +} + #ifdef __cplusplus } #endif diff --git a/lib/lib_vty.c b/lib/lib_vty.c index 787da08e2..9c927ca4a 100644 --- a/lib/lib_vty.c +++ b/lib/lib_vty.c @@ -93,7 +93,7 @@ static int qmem_walker(void *arg, struct memgroup *mg, struct memtype *mt) #endif ); } else { - if (mt->n_alloc != 0) { + if (mt->n_max != 0) { char size[32]; snprintf(size, sizeof(size), "%6zu", mt->size); #ifdef HAVE_MALLOC_USABLE_SIZE diff --git a/lib/libfrr.h b/lib/libfrr.h index f964c9e2a..9d91ea915 100644 --- a/lib/libfrr.h +++ b/lib/libfrr.h @@ -128,7 +128,8 @@ extern void frr_preinit(struct frr_daemon_info *daemon, int argc, char **argv); extern void frr_opt_add(const char *optstr, const struct option *longopts, const char *helpstr); extern int frr_getopt(int argc, char *const argv[], int *longindex); -extern void frr_help_exit(int status); + +extern __attribute__((__noreturn__)) void frr_help_exit(int status); extern struct thread_master *frr_init(void); extern const char *frr_get_progname(void); diff --git a/lib/memory.h b/lib/memory.h index 44ea19b55..e4e05faa4 100644 --- a/lib/memory.h +++ b/lib/memory.h @@ -179,7 +179,8 @@ extern int qmem_walk(qmem_walk_fn *func, void *arg); extern int log_memstats(FILE *fp, const char *); #define log_memstats_stderr(prefix) log_memstats(stderr, prefix) -extern void memory_oom(size_t size, const char *name); +extern __attribute__((__noreturn__)) void memory_oom(size_t size, + const char *name); #ifdef __cplusplus } diff --git a/lib/mlag.c b/lib/mlag.c index 733dd41ea..653fbe8fe 100644 --- a/lib/mlag.c +++ b/lib/mlag.c @@ -85,9 +85,12 @@ int mlag_lib_decode_mlag_hdr(struct stream *s, struct mlag_msg *msg, size_t *length) { #define LIB_MLAG_HDR_LENGTH 8 + if (s == NULL || msg == NULL) + return -1; + *length = stream_get_endp(s); - if (s == NULL || msg == NULL || *length < LIB_MLAG_HDR_LENGTH) + if (*length < LIB_MLAG_HDR_LENGTH) return -1; *length -= LIB_MLAG_HDR_LENGTH; diff --git a/lib/ntop.c b/lib/ntop.c index 066e10e3e..ccbf8793d 100644 --- a/lib/ntop.c +++ b/lib/ntop.c @@ -165,7 +165,7 @@ inet4: return dst; } -#ifndef INET_NTOP_NO_OVERRIDE +#if !defined(INET_NTOP_NO_OVERRIDE) && !defined(__APPLE__) /* we want to override libc inet_ntop, but make sure it shows up in backtraces * as frr_inet_ntop (to avoid confusion while debugging) */ diff --git a/lib/prefix.h b/lib/prefix.h index b01f7d1fd..51b3dacb8 100644 --- a/lib/prefix.h +++ b/lib/prefix.h @@ -531,7 +531,7 @@ static inline int is_host_route(struct prefix *p) return 0; } -static inline int is_default_host_route(struct prefix *p) +static inline int is_default_host_route(const struct prefix *p) { if (p->family == AF_INET) { return (p->u.prefix4.s_addr == INADDR_ANY && diff --git a/lib/skiplist.c b/lib/skiplist.c index d955c6eb9..fa25770ef 100644 --- a/lib/skiplist.c +++ b/lib/skiplist.c @@ -112,7 +112,7 @@ static int randomLevel(void) return level; } -static int default_cmp(void *key1, void *key2) +static int default_cmp(const void *key1, const void *key2) { if (key1 < key2) return -1; @@ -126,7 +126,8 @@ unsigned int skiplist_count(struct skiplist *l) return l->count; } -struct skiplist *skiplist_new(int flags, int (*cmp)(void *key1, void *key2), +struct skiplist *skiplist_new(int flags, + int (*cmp)(const void *key1, const void *key2), void (*del)(void *val)) { struct skiplist *new; @@ -329,8 +330,8 @@ int skiplist_delete(register struct skiplist *l, register void *key, * Also set a cursor for use with skiplist_next_value. */ int skiplist_first_value(register struct skiplist *l, /* in */ - register void *key, /* in */ - void **valuePointer, /* out */ + register const void *key, /* in */ + void **valuePointer, /* out */ void **cursor) /* out */ { register int k; @@ -374,7 +375,7 @@ int skiplist_search(register struct skiplist *l, register void *key, * last element with the given key, -1 is returned. */ int skiplist_next_value(register struct skiplist *l, /* in */ - register void *key, /* in */ + register const void *key, /* in */ void **valuePointer, /* in/out */ void **cursor) /* in/out */ { diff --git a/lib/skiplist.h b/lib/skiplist.h index 2ab37331c..a106a455d 100644 --- a/lib/skiplist.h +++ b/lib/skiplist.h @@ -68,7 +68,7 @@ struct skiplist { * Returns -1 if val1 < val2, 0 if equal?, 1 if val1 > val2. * Used as definition of sorted for listnode_add_sort */ - int (*cmp)(void *val1, void *val2); + int (*cmp)(const void *val1, const void *val2); /* callback to free user-owned data when listnode is deleted. supplying * this callback is very much encouraged! @@ -81,8 +81,9 @@ struct skiplist { extern struct skiplist * skiplist_new(/* encouraged: set list.del callback on new lists */ int flags, - int (*cmp)(void *key1, void *key2), /* NULL => default cmp */ - void (*del)(void *val)); /* NULL => no auto val free */ + int (*cmp)(const void *key1, + const void *key2), /* NULL => default cmp */ + void (*del)(void *val)); /* NULL => no auto val free */ extern void skiplist_free(struct skiplist *); @@ -96,12 +97,12 @@ extern int skiplist_search(register struct skiplist *l, register void *key, void **valuePointer); extern int skiplist_first_value(register struct skiplist *l, /* in */ - register void *key, /* in */ - void **valuePointer, /* in/out */ + register const void *key, /* in */ + void **valuePointer, /* in/out */ void **cursor); /* out */ extern int skiplist_next_value(register struct skiplist *l, /* in */ - register void *key, /* in */ + register const void *key, /* in */ void **valuePointer, /* in/out */ void **cursor); /* in/out */ diff --git a/lib/stream.h b/lib/stream.h index 36c65afa3..425f0c5ed 100644 --- a/lib/stream.h +++ b/lib/stream.h @@ -354,9 +354,10 @@ extern void stream_fifo_free(struct stream_fifo *fifo); * bit), for 64-bit values (you need to cast them anyway), and neither for * encoding (because it's downcasted.) */ -static inline uint8_t *ptr_get_be32(uint8_t *ptr, uint32_t *out) +static inline const uint8_t *ptr_get_be32(const uint8_t *ptr, uint32_t *out) { uint32_t tmp; + memcpy(&tmp, ptr, sizeof(tmp)); *out = ntohl(tmp); return ptr + 4; diff --git a/lib/zclient.c b/lib/zclient.c index eac6c7081..93c5fe39a 100644 --- a/lib/zclient.c +++ b/lib/zclient.c @@ -690,8 +690,9 @@ static int zclient_connect(struct thread *t) return zclient_start(zclient); } -int zclient_send_rnh(struct zclient *zclient, int command, struct prefix *p, - bool exact_match, vrf_id_t vrf_id) +int zclient_send_rnh(struct zclient *zclient, int command, + const struct prefix *p, bool exact_match, + vrf_id_t vrf_id) { struct stream *s; diff --git a/lib/zclient.h b/lib/zclient.h index e6f4c747e..f18511dc8 100644 --- a/lib/zclient.h +++ b/lib/zclient.h @@ -738,7 +738,7 @@ extern void zebra_read_pw_status_update(ZAPI_CALLBACK_ARGS, struct zapi_pw_statu extern int zclient_route_send(uint8_t, struct zclient *, struct zapi_route *); extern int zclient_send_rnh(struct zclient *zclient, int command, - struct prefix *p, bool exact_match, + const struct prefix *p, bool exact_match, vrf_id_t vrf_id); int zapi_nexthop_encode(struct stream *s, const struct zapi_nexthop *api_nh, uint32_t api_flags); diff --git a/libyang b/libyang deleted file mode 160000 -Subproject 4241fbbe72216ae2b84f10d25acb1bc84eb967e diff --git a/nhrpd/nhrp_vty.c b/nhrpd/nhrp_vty.c index f6d18fb77..a3066f917 100644 --- a/nhrpd/nhrp_vty.c +++ b/nhrpd/nhrp_vty.c @@ -12,6 +12,7 @@ #include "zclient.h" #include "stream.h" #include "filter.h" +#include "json.h" #include "nhrpd.h" #include "netlink.h" @@ -594,6 +595,7 @@ struct info_ctx { struct vty *vty; afi_t afi; int count; + struct json_object *json; }; static void show_ip_nhrp_cache(struct nhrp_cache *c, void *pctx) @@ -601,22 +603,60 @@ static void show_ip_nhrp_cache(struct nhrp_cache *c, void *pctx) struct info_ctx *ctx = pctx; struct vty *vty = ctx->vty; char buf[2][SU_ADDRSTRLEN]; + struct json_object *json = NULL; if (ctx->afi != family2afi(sockunion_family(&c->remote_addr))) return; - if (!ctx->count) { + + if (!ctx->count && !ctx->json) { vty_out(vty, "%-8s %-8s %-24s %-24s %-6s %s\n", "Iface", "Type", "Protocol", "NBMA", "Flags", "Identity"); } ctx->count++; + sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])); + if (c->cur.peer) + sockunion2str(&c->cur.peer->vc->remote.nbma, + buf[1], sizeof(buf[1])); + else + snprintf(buf[1], sizeof(buf[1]), "-"); + + if (json) { + json = json_object_new_object(); + json_object_string_add(json, "interface", c->ifp->name); + json_object_string_add(json, "type", + nhrp_cache_type_str[c->cur.type]); + json_object_string_add(json, "protocol", buf[0]); + json_object_string_add(json, "nbma", buf[1]); + + if (c->used) + json_object_boolean_true_add(json, "used"); + else + json_object_boolean_false_add(json, "used"); + + if (c->t_timeout) + json_object_boolean_true_add(json, "timeout"); + else + json_object_boolean_false_add(json, "timeout"); + + if (c->t_auth) + json_object_boolean_true_add(json, "auth"); + else + json_object_boolean_false_add(json, "auth"); + + if (c->cur.peer) + json_object_string_add(json, "identity", + c->cur.peer->vc->remote.id); + else + json_object_string_add(json, "identity", "-"); + + json_object_array_add(ctx->json, json); + return; + } vty_out(ctx->vty, "%-8s %-8s %-24s %-24s %c%c%c %s\n", c->ifp->name, nhrp_cache_type_str[c->cur.type], - sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])), - c->cur.peer ? sockunion2str(&c->cur.peer->vc->remote.nbma, - buf[1], sizeof(buf[1])) - : "-", + buf[0], buf[1], c->used ? 'U' : ' ', c->t_timeout ? 'T' : ' ', c->t_auth ? 'A' : ' ', c->cur.peer ? c->cur.peer->vc->remote.id : "-"); @@ -628,19 +668,35 @@ static void show_ip_nhrp_nhs(struct nhrp_nhs *n, struct nhrp_registration *reg, struct info_ctx *ctx = pctx; struct vty *vty = ctx->vty; char buf[2][SU_ADDRSTRLEN]; + struct json_object *json = NULL; - if (!ctx->count) { + if (!ctx->count && !ctx->json) { vty_out(vty, "%-8s %-24s %-16s %-16s\n", "Iface", "FQDN", "NBMA", "Protocol"); } ctx->count++; + if (reg && reg->peer) + sockunion2str(®->peer->vc->remote.nbma, + buf[0], sizeof(buf[0])); + else + snprintf(buf[0], sizeof(buf[0]), "-"); + sockunion2str(reg ? ®->proto_addr : &n->proto_addr, buf[1], + sizeof(buf[1])); + + if (ctx->json) { + json = json_object_new_object(); + json_object_string_add(json, "interface", n->ifp->name); + json_object_string_add(json, "fqdn", n->nbma_fqdn); + json_object_string_add(json, "nbma", buf[0]); + json_object_string_add(json, "protocol", buf[1]); + + json_object_array_add(ctx->json, json); + return; + } + vty_out(vty, "%-8s %-24s %-16s %-16s\n", n->ifp->name, n->nbma_fqdn, - (reg && reg->peer) ? sockunion2str(®->peer->vc->remote.nbma, - buf[0], sizeof(buf[0])) - : "-", - sockunion2str(reg ? ®->proto_addr : &n->proto_addr, buf[1], - sizeof(buf[1]))); + buf[0], buf[1]); } static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx) @@ -649,6 +705,7 @@ static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx) struct nhrp_cache *c; struct vty *vty = ctx->vty; char buf1[PREFIX_STRLEN], buf2[SU_ADDRSTRLEN]; + struct json_object *json = NULL; if (!ctx->count) { vty_out(vty, "%-8s %-24s %-24s %s\n", "Type", "Prefix", "Via", @@ -657,20 +714,82 @@ static void show_ip_nhrp_shortcut(struct nhrp_shortcut *s, void *pctx) ctx->count++; c = s->cache; - vty_out(ctx->vty, "%-8s %-24s %-24s %s\n", nhrp_cache_type_str[s->type], - prefix2str(s->p, buf1, sizeof(buf1)), - c ? sockunion2str(&c->remote_addr, buf2, sizeof(buf2)) : "", + if (c) + sockunion2str(&c->remote_addr, buf2, sizeof(buf2)); + prefix2str(s->p, buf1, sizeof(buf1)); + + if (ctx->json) { + json = json_object_new_object(); + json_object_string_add(json, "type", + nhrp_cache_type_str[s->type]); + json_object_string_add(json, "prefix", buf1); + + if (c) + json_object_string_add(json, "via", buf2); + + if (c && c->cur.peer) + json_object_string_add(json, "identity", + c->cur.peer->vc->remote.id); + else + json_object_string_add(json, "identity", ""); + + json_object_array_add(ctx->json, json); + return; + } + + vty_out(ctx->vty, "%-8s %-24s %-24s %s\n", + nhrp_cache_type_str[s->type], + buf1, buf2, (c && c->cur.peer) ? c->cur.peer->vc->remote.id : ""); } static void show_ip_opennhrp_cache(struct nhrp_cache *c, void *pctx) { struct info_ctx *ctx = pctx; - char buf[SU_ADDRSTRLEN]; + char buf[3][SU_ADDRSTRLEN]; + struct json_object *json = NULL; + if (ctx->afi != family2afi(sockunion_family(&c->remote_addr))) return; + sockunion2str(&c->remote_addr, buf[0], sizeof(buf[0])); + if (c->cur.peer) + sockunion2str(&c->cur.peer->vc->remote.nbma, buf[1], + sizeof(buf[1])); + if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) + sockunion2str(&c->cur.remote_nbma_natoa, buf[2], + sizeof(buf[2])); + if (ctx->json) { + json = json_object_new_object(); + json_object_string_add(json, "type", + nhrp_cache_type_str[c->cur.type]); + + if (c->cur.peer && c->cur.peer->online) + json_object_boolean_true_add(json, "up"); + else + json_object_boolean_false_add(json, "up"); + + if (c->used) + json_object_boolean_true_add(json, "used"); + else + json_object_boolean_false_add(json, "used"); + + json_object_string_add(json, "protocolAddress", buf[0]); + json_object_int_add(json, "protocolAddressSize", + 8 * family2addrsize(sockunion_family + (&c->remote_addr))); + + if (c->cur.peer) + json_object_string_add(json, "nbmaAddress", buf[1]); + + if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) + json_object_string_add(json, "nbmaNatOaAddress", + buf[2]); + + json_object_array_add(ctx->json, json); + return; + } vty_out(ctx->vty, "Type: %s\n" "Flags:%s%s\n" @@ -678,40 +797,45 @@ static void show_ip_opennhrp_cache(struct nhrp_cache *c, void *pctx) nhrp_cache_type_str[c->cur.type], (c->cur.peer && c->cur.peer->online) ? " up" : "", c->used ? " used" : "", - sockunion2str(&c->remote_addr, buf, sizeof(buf)), + buf[0], 8 * family2addrsize(sockunion_family(&c->remote_addr))); - if (c->cur.peer) { - vty_out(ctx->vty, "NBMA-Address: %s\n", - sockunion2str(&c->cur.peer->vc->remote.nbma, buf, - sizeof(buf))); - } + if (c->cur.peer) + vty_out(ctx->vty, "NBMA-Address: %s\n", buf[1]); - if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) { - vty_out(ctx->vty, "NBMA-NAT-OA-Address: %s\n", - sockunion2str(&c->cur.remote_nbma_natoa, buf, - sizeof(buf))); - } + if (sockunion_family(&c->cur.remote_nbma_natoa) != AF_UNSPEC) + vty_out(ctx->vty, "NBMA-NAT-OA-Address: %s\n", buf[2]); vty_out(ctx->vty, "\n\n"); } DEFUN(show_ip_nhrp, show_ip_nhrp_cmd, - "show " AFI_CMD " nhrp [cache|nhs|shortcut|opennhrp]", + "show " AFI_CMD " nhrp [cache|nhs|shortcut|opennhrp] [json]", SHOW_STR AFI_STR "NHRP information\n" "Forwarding cache information\n" "Next hop server information\n" "Shortcut information\n" - "opennhrpctl style cache dump\n") + "opennhrpctl style cache dump\n" + JSON_STR) { struct vrf *vrf = vrf_lookup_by_id(VRF_DEFAULT); struct interface *ifp; struct info_ctx ctx = { - .vty = vty, .afi = cmd_to_afi(argv[1]), + .vty = vty, .afi = cmd_to_afi(argv[1]), .json = NULL }; - + bool uj = use_json(argc, argv); + struct json_object *json_path = NULL; + struct json_object *json_vrf = NULL, *json_vrf_path = NULL; + int ret = CMD_SUCCESS; + + if (uj) { + json_vrf = json_object_new_object(); + json_vrf_path = json_object_new_object(); + json_path = json_object_new_array(); + ctx.json = json_path; + } if (argc <= 3 || argv[3]->text[0] == 'c') { FOR_ALL_INTERFACES (vrf, ifp) nhrp_cache_foreach(ifp, show_ip_nhrp_cache, &ctx); @@ -721,49 +845,104 @@ DEFUN(show_ip_nhrp, show_ip_nhrp_cmd, } else if (argv[3]->text[0] == 's') { nhrp_shortcut_foreach(ctx.afi, show_ip_nhrp_shortcut, &ctx); } else { - vty_out(vty, "Status: ok\n\n"); + if (!ctx.json) + vty_out(vty, "Status: ok\n\n"); + else + json_object_string_add(json_vrf, "status", "ok"); + ctx.count++; FOR_ALL_INTERFACES (vrf, ifp) nhrp_cache_foreach(ifp, show_ip_opennhrp_cache, &ctx); } + if (uj) + json_object_int_add(json_vrf, "entriesCount", ctx.count); if (!ctx.count) { - vty_out(vty, "%% No entries\n"); - return CMD_WARNING; + if (!ctx.json) + vty_out(vty, "%% No entries\n"); + ret = CMD_WARNING; } - - return CMD_SUCCESS; + if (uj) { + json_object_object_add(json_vrf_path, "attr", json_vrf); + json_object_object_add(json_vrf_path, "table", ctx.json); + vty_out(vty, "%s", + json_object_to_json_string_ext( + json_vrf_path, JSON_C_TO_STRING_PRETTY)); + json_object_free(json_vrf_path); + } + return ret; } +struct dmvpn_cfg { + struct vty *vty; + struct json_object *json; +}; + static void show_dmvpn_entry(struct nhrp_vc *vc, void *ctx) { - struct vty *vty = ctx; + struct dmvpn_cfg *ctxt = ctx; + struct vty *vty; char buf[2][SU_ADDRSTRLEN]; + struct json_object *json = NULL; + + if (!ctxt || !ctxt->vty) + return; + vty = ctxt->vty; + sockunion2str(&vc->local.nbma, buf[0], sizeof(buf[0])); + sockunion2str(&vc->remote.nbma, buf[1], sizeof(buf[1])); + if (ctxt->json) { + json = json_object_new_object(); + json_object_string_add(json, "src", buf[0]); + json_object_string_add(json, "dst", buf[1]); + + if (notifier_active(&vc->notifier_list)) + json_object_boolean_true_add(json, "notifierActive"); + else + json_object_boolean_false_add(json, "notifierActive"); - vty_out(vty, "%-24s %-24s %c %-4d %-24s\n", - sockunion2str(&vc->local.nbma, buf[0], sizeof(buf[0])), - sockunion2str(&vc->remote.nbma, buf[1], sizeof(buf[1])), - notifier_active(&vc->notifier_list) ? 'n' : ' ', vc->ipsec, - vc->remote.id); + json_object_int_add(json, "sas", vc->ipsec); + json_object_string_add(json, "identity", vc->remote.id); + json_object_array_add(ctxt->json, json); + } else { + vty_out(vty, "%-24s %-24s %c %-4d %-24s\n", + buf[0], buf[1], notifier_active(&vc->notifier_list) ? + 'n' : ' ', vc->ipsec, vc->remote.id); + } } DEFUN(show_dmvpn, show_dmvpn_cmd, - "show dmvpn", + "show dmvpn [json]", SHOW_STR - "DMVPN information\n") + "DMVPN information\n" + JSON_STR) { - vty_out(vty, "%-24s %-24s %-6s %-4s %-24s\n", "Src", "Dst", "Flags", - "SAs", "Identity"); - - nhrp_vc_foreach(show_dmvpn_entry, vty); - + bool uj = use_json(argc, argv); + struct dmvpn_cfg ctxt; + struct json_object *json_path = NULL; + + ctxt.vty = vty; + if (!uj) { + ctxt.json = NULL; + vty_out(vty, "%-24s %-24s %-6s %-4s %-24s\n", + "Src", "Dst", "Flags", "SAs", "Identity"); + } else { + json_path = json_object_new_array(); + ctxt.json = json_path; + } + nhrp_vc_foreach(show_dmvpn_entry, &ctxt); + if (uj) { + vty_out(vty, "%s", + json_object_to_json_string_ext( + json_path, JSON_C_TO_STRING_PRETTY)); + json_object_free(json_path); + } return CMD_SUCCESS; } static void clear_nhrp_cache(struct nhrp_cache *c, void *data) { struct info_ctx *ctx = data; - if (c->cur.type <= NHRP_CACHE_CACHED) { + if (c->cur.type <= NHRP_CACHE_DYNAMIC) { nhrp_cache_update_binding(c, c->cur.type, -1, NULL, 0, NULL); ctx->count++; } diff --git a/ospfd/ospf_packet.c b/ospfd/ospf_packet.c index d87f02627..0808f245e 100644 --- a/ospfd/ospf_packet.c +++ b/ospfd/ospf_packet.c @@ -2335,7 +2335,7 @@ static struct stream *ospf_recv_packet(struct ospf *ospf, int fd, ip_len = iph->ip_len; -#if !defined(GNU_LINUX) && (OpenBSD < 200311) && (__FreeBSD_version < 1000000) +#if defined(__FreeBSD__) && (__FreeBSD_version < 1000000) /* * Kernel network code touches incoming IP header parameters, * before protocol specific processing. diff --git a/pbrd/pbr_vty.c b/pbrd/pbr_vty.c index e395b7831..dfc8bec1b 100644 --- a/pbrd/pbr_vty.c +++ b/pbrd/pbr_vty.c @@ -423,7 +423,6 @@ DEFPY(pbr_map_vrf, pbr_map_vrf_cmd, "Use the interface's VRF for lookup\n") { struct pbr_map_sequence *pbrms = VTY_GET_CONTEXT(pbr_map_sequence); - int ret = CMD_SUCCESS; if (no) { pbr_map_delete_vrf(pbrms); @@ -434,28 +433,51 @@ DEFPY(pbr_map_vrf, pbr_map_vrf_cmd, pbrms->vrf_lookup = false; pbrms->vrf_unchanged = false; - goto done; + return CMD_SUCCESS; } if (pbrms->nhgrp_name || pbrms->nhg) { vty_out(vty, "A `set nexthop/nexthop-group XX` command already exits, please remove that first\n"); - ret = CMD_WARNING_CONFIG_FAILED; - goto done; + return CMD_WARNING_CONFIG_FAILED; } - if (pbrms->vrf_lookup || pbrms->vrf_unchanged) { - vty_out(vty, SET_VRF_EXISTS_STR); - ret = CMD_WARNING_CONFIG_FAILED; - goto done; + /* + * Determine if a set vrf * command already exists. + * + * If its equivalent, just return success. + * + * Else, return failure, we don't allow atomic swaps yet. + */ + if (vrf_name && pbrms->vrf_lookup) { + /* New vrf specified and one already exists */ + + /* Is this vrf different from one already configured? */ + if (strncmp(pbrms->vrf_name, vrf_name, sizeof(pbrms->vrf_name)) + != 0) + goto vrf_exists; + + return CMD_SUCCESS; + + } else if (!vrf_name && pbrms->vrf_unchanged) { + /* Unchanged specified and unchanged already exists */ + return CMD_SUCCESS; + + } else if (vrf_name && pbrms->vrf_unchanged) { + /* New vrf specified and unchanged is already set */ + goto vrf_exists; + + } else if (!vrf_name && pbrms->vrf_lookup) { + /* Unchanged specified and vrf to lookup already exists */ + goto vrf_exists; } + /* Create new lookup VRF or Unchanged */ if (vrf_name) { if (!pbr_vrf_lookup_by_name(vrf_name)) { vty_out(vty, "Specified: %s is non-existent\n", vrf_name); - ret = CMD_WARNING_CONFIG_FAILED; - goto done; + return CMD_WARNING_CONFIG_FAILED; } pbrms->vrf_lookup = true; @@ -465,8 +487,11 @@ DEFPY(pbr_map_vrf, pbr_map_vrf_cmd, pbr_map_check(pbrms); -done: - return ret; + return CMD_SUCCESS; + +vrf_exists: + vty_out(vty, SET_VRF_EXISTS_STR); + return CMD_WARNING_CONFIG_FAILED; } DEFPY (pbr_policy, diff --git a/pimd/pim_bsm.c b/pimd/pim_bsm.c index bcf11aedb..f55934909 100644 --- a/pimd/pim_bsm.c +++ b/pimd/pim_bsm.c @@ -601,7 +601,8 @@ static bool is_preferred_bsr(struct pim_instance *pim, struct in_addr bsr, return true; else if (bsr_prio == pim->global_scope.current_bsr_prio) { - if (bsr.s_addr >= pim->global_scope.current_bsr.s_addr) + if (ntohl(bsr.s_addr) + >= ntohl(pim->global_scope.current_bsr.s_addr)) return true; else return false; @@ -874,6 +875,17 @@ static void pim_bsm_fwd_whole_sz(struct pim_instance *pim, uint8_t *buf, pim_ifp = ifp->info; if ((!pim_ifp) || (!pim_ifp->bsm_enable)) continue; + + /* + * RFC 5059 Sec 3.4: + * When a Bootstrap message is forwarded, it is forwarded out + * of every multicast-capable interface that has PIM neighbors. + * + * So skipping pim interfaces with no neighbors. + */ + if (listcount(pim_ifp->pim_neighbor_list) == 0) + continue; + pim_hello_require(ifp); pim_mtu = ifp->mtu - MAX_IP_HDR_LEN; if (pim_mtu < len) { diff --git a/pimd/pim_cmd.c b/pimd/pim_cmd.c index 8bfad8ee2..92de99f33 100644 --- a/pimd/pim_cmd.c +++ b/pimd/pim_cmd.c @@ -5807,7 +5807,7 @@ static void show_mroute(struct pim_instance *pim, struct vty *vty, vty_out(vty, " R - RP-bit set, F - Register flag, T - SPT-bit set\n"); vty_out(vty, - "\nSource Group Flags Proto Input Output TTL Uptime\n"); + "\nSource Group Flags Proto Input Output TTL Uptime\n"); } now = pim_time_monotonic_sec(); @@ -7289,11 +7289,20 @@ DEFUN (no_ip_pim_ecmp_rebalance, static int pim_cmd_igmp_start(struct vty *vty, struct interface *ifp) { struct pim_interface *pim_ifp; + struct pim_instance *pim; uint8_t need_startup = 0; pim_ifp = ifp->info; if (!pim_ifp) { + pim = pim_get_pim_instance(ifp->vrf_id); + /* Limit mcast interfaces to number of vifs available */ + if (pim->mcast_if_count == MAXVIFS) { + vty_out(vty, + "Max multicast interfaces(%d) Reached. Could not enable IGMP on interface %s\n", + MAXVIFS, ifp->name); + return CMD_WARNING_CONFIG_FAILED; + } (void)pim_if_new(ifp, true, false, false, false); need_startup = 1; } else { @@ -8043,13 +8052,21 @@ DEFPY_HIDDEN (interface_ip_igmp_query_generate, return CMD_SUCCESS; } -static int pim_cmd_interface_add(struct interface *ifp) +static int pim_cmd_interface_add(struct vty *vty, struct interface *ifp) { struct pim_interface *pim_ifp = ifp->info; + struct pim_instance *pim; - if (!pim_ifp) + if (!pim_ifp) { + pim = pim_get_pim_instance(ifp->vrf_id); + /* Limiting mcast interfaces to number of VIFs */ + if (pim->mcast_if_count == MAXVIFS) { + vty_out(vty, "Max multicast interfaces(%d) reached.", + MAXVIFS); + return 0; + } pim_ifp = pim_if_new(ifp, false, true, false, false); - else + } else PIM_IF_DO_PIM(pim_ifp->options); pim_if_addr_add_all(ifp); @@ -8120,15 +8137,17 @@ DEFPY (interface_ip_pim_activeactive, VTY_DECLVAR_CONTEXT(interface, ifp); struct pim_interface *pim_ifp; - if (!no && !pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM active-active on interface\n"); + if (!no && !pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, + "Could not enable PIM SM active-active on interface %s\n", + ifp->name); return CMD_WARNING_CONFIG_FAILED; } - if (PIM_DEBUG_MLAG) - zlog_debug("%sConfiguring PIM active-active on Interface: %s", - no ? "Un-":" ", ifp->name); + if (PIM_DEBUG_MLAG) + zlog_debug("%sConfiguring PIM active-active on Interface: %s", + no ? "Un-" : " ", ifp->name); pim_ifp = ifp->info; if (no) @@ -8148,8 +8167,9 @@ DEFUN_HIDDEN (interface_ip_pim_ssm, { VTY_DECLVAR_CONTEXT(interface, ifp); - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING_CONFIG_FAILED; } @@ -8165,8 +8185,9 @@ static int interface_ip_pim_helper(struct vty *vty) VTY_DECLVAR_CONTEXT(interface, ifp); - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING_CONFIG_FAILED; } @@ -8454,8 +8475,10 @@ DEFUN (interface_ip_pim_hello, struct pim_interface *pim_ifp = ifp->info; if (!pim_ifp) { - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, + "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING_CONFIG_FAILED; } } @@ -9197,8 +9220,10 @@ DEFUN (ip_pim_bfd, struct bfd_info *bfd_info = NULL; if (!pim_ifp) { - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, + "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING; } } @@ -9248,8 +9273,10 @@ DEFUN (ip_pim_bsm, struct pim_interface *pim_ifp = ifp->info; if (!pim_ifp) { - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, + "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING; } } @@ -9292,8 +9319,10 @@ DEFUN (ip_pim_ucast_bsm, struct pim_interface *pim_ifp = ifp->info; if (!pim_ifp) { - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, + "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING; } } @@ -9360,8 +9389,10 @@ DEFUN( struct pim_interface *pim_ifp = ifp->info; if (!pim_ifp) { - if (!pim_cmd_interface_add(ifp)) { - vty_out(vty, "Could not enable PIM SM on interface\n"); + if (!pim_cmd_interface_add(vty, ifp)) { + vty_out(vty, + "Could not enable PIM SM on interface %s\n", + ifp->name); return CMD_WARNING; } } diff --git a/pimd/pim_iface.c b/pimd/pim_iface.c index cb31878e0..07c4172f2 100644 --- a/pimd/pim_iface.c +++ b/pimd/pim_iface.c @@ -186,6 +186,7 @@ struct pim_interface *pim_if_new(struct interface *ifp, bool igmp, bool pim, pim_sock_reset(ifp); pim_if_add_vif(ifp, ispimreg, is_vxlan_term); + pim_ifp->pim->mcast_if_count++; return pim_ifp; } @@ -209,6 +210,7 @@ void pim_if_delete(struct interface *ifp) pim_neighbor_delete_all(ifp, "Interface removed from configuration"); pim_if_del_vif(ifp); + pim_ifp->pim->mcast_if_count--; list_delete(&pim_ifp->igmp_socket_list); list_delete(&pim_ifp->pim_neighbor_list); @@ -275,7 +277,7 @@ static void pim_addr_change(struct interface *ifp) 1) Before an interface goes down or changes primary IP address, a Hello message with a zero HoldTime should be sent immediately (with the old IP address if the IP address changed). - -- FIXME See CAVEAT C13 + -- Done at the caller of the function as new ip already updated here 2) After an interface has changed its IP address, it MUST send a Hello message with its new IP address. @@ -320,6 +322,10 @@ static int detect_primary_address_change(struct interface *ifp, } if (changed) { + /* Before updating pim_ifp send Hello time with 0 hold time */ + if (PIM_IF_TEST_PIM(pim_ifp->options)) { + pim_hello_send(ifp, 0 /* zero-sec holdtime */); + } pim_ifp->primary_address = new_prim_addr; } @@ -1583,8 +1589,14 @@ int pim_ifp_create(struct interface *ifp) } if (!strncmp(ifp->name, PIM_VXLAN_TERM_DEV_NAME, - sizeof(PIM_VXLAN_TERM_DEV_NAME))) - pim_vxlan_add_term_dev(pim, ifp); + sizeof(PIM_VXLAN_TERM_DEV_NAME))) { + if (pim->mcast_if_count < MAXVIFS) + pim_vxlan_add_term_dev(pim, ifp); + else + zlog_warn( + "%s: Cannot enable pim on %s. MAXVIFS(%d) reached. Deleting and readding the vxlan termimation device after unconfiguring pim from other interfaces may succeed.", + __func__, ifp->name, MAXVIFS); + } return 0; } diff --git a/pimd/pim_instance.c b/pimd/pim_instance.c index 2cda628a9..b4c2dd28c 100644 --- a/pimd/pim_instance.c +++ b/pimd/pim_instance.c @@ -83,6 +83,7 @@ static struct pim_instance *pim_instance_init(struct vrf *vrf) pim_if_init(pim); + pim->mcast_if_count = 0; pim->keep_alive_time = PIM_KEEPALIVE_PERIOD; pim->rp_keep_alive_time = PIM_RP_KEEPALIVE_PERIOD; diff --git a/pimd/pim_instance.h b/pimd/pim_instance.h index 48dc2d953..71bd7c108 100644 --- a/pimd/pim_instance.h +++ b/pimd/pim_instance.h @@ -168,6 +168,7 @@ struct pim_instance { struct route_table *rp_table; int iface_vif_index[MAXVIFS]; + int mcast_if_count; struct rb_pim_oil_head channel_oil_head; diff --git a/pimd/pim_join.c b/pimd/pim_join.c index 62bd2360c..3a88de207 100644 --- a/pimd/pim_join.c +++ b/pimd/pim_join.c @@ -140,18 +140,19 @@ static void recv_prune(struct interface *ifp, struct pim_neighbor *neigh, if ((source_flags & PIM_RPT_BIT_MASK) && (source_flags & PIM_WILDCARD_BIT_MASK)) { - struct pim_rpf *rp = RP(pim_ifp->pim, sg->grp); + /* + * RFC 4601 Section 4.5.2: + * Received Prune(*,G) messages are processed even if the + * RP in the message does not match RP(G). + */ + if (PIM_DEBUG_PIM_TRACE) { + char received_rp[INET_ADDRSTRLEN]; - if (!rp) { - if (PIM_DEBUG_PIM_TRACE) - zlog_debug( - "%s: RP for %pSG4 completely failed lookup", - __func__, sg); - return; + pim_inet4_dump("<received?>", sg->src, received_rp, + sizeof(received_rp)); + zlog_debug("%s: Prune received with RP(%s) for %pSG4", + __func__, received_rp, sg); } - // Ignoring Prune *,G's at the moment. - if (sg->src.s_addr != rp->rpf_addr.u.prefix4.s_addr) - return; sg->src.s_addr = INADDR_ANY; } diff --git a/pimd/pim_mroute.c b/pimd/pim_mroute.c index 5ce786361..f75bd2c1b 100644 --- a/pimd/pim_mroute.c +++ b/pimd/pim_mroute.c @@ -232,6 +232,8 @@ static int pim_mroute_msg_nocache(int fd, struct interface *ifp, pim_upstream_mroute_iif_update(up->channel_oil, __func__); } pim_register_join(up); + /* if we have receiver, inherit from parent */ + pim_upstream_inherited_olist_decide(pim_ifp->pim, up); return 0; } @@ -961,7 +963,7 @@ static inline void pim_mroute_copy(struct mfcctl *oil, static int pim_mroute_add(struct channel_oil *c_oil, const char *name) { struct pim_instance *pim = c_oil->pim; - struct mfcctl tmp_oil; + struct mfcctl tmp_oil = { {0} }; int err; pim->mroute_add_last = pim_time_monotonic_sec(); diff --git a/pimd/pim_neighbor.c b/pimd/pim_neighbor.c index ca7ca1140..d8a797f98 100644 --- a/pimd/pim_neighbor.c +++ b/pimd/pim_neighbor.c @@ -779,6 +779,7 @@ void pim_neighbor_update(struct pim_neighbor *neigh, uint32_t dr_priority, struct list *addr_list) { struct pim_interface *pim_ifp = neigh->interface->info; + uint32_t old, new; /* Received holdtime ? */ if (PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_HOLDTIME)) { @@ -818,6 +819,16 @@ void pim_neighbor_update(struct pim_neighbor *neigh, neigh->prefix_list = addr_list; update_dr_priority(neigh, hello_options, dr_priority); + new = PIM_OPTION_IS_SET(hello_options, PIM_OPTION_MASK_LAN_PRUNE_DELAY); + old = PIM_OPTION_IS_SET(neigh->hello_options, + PIM_OPTION_MASK_LAN_PRUNE_DELAY); + + if (old != new) { + if (old) + ++pim_ifp->pim_number_of_nonlandelay_neighbors; + else + --pim_ifp->pim_number_of_nonlandelay_neighbors; + } /* Copy flags */ diff --git a/pimd/pim_pim.c b/pimd/pim_pim.c index 8d7a921cf..f37c140bf 100644 --- a/pimd/pim_pim.c +++ b/pimd/pim_pim.c @@ -42,7 +42,6 @@ #include "pim_bsm.h" static int on_pim_hello_send(struct thread *t); -static int pim_hello_send(struct interface *ifp, uint16_t holdtime); static const char *pim_pim_msgtype2str(enum pim_msg_type type) { @@ -137,6 +136,18 @@ void pim_sock_delete(struct interface *ifp, const char *delete_message) sock_close(ifp); } +/* For now check dst address for hello, assrt and join/prune is all pim rtr */ +static bool pim_pkt_dst_addr_ok(enum pim_msg_type type, in_addr_t addr) +{ + if ((type == PIM_MSG_TYPE_HELLO) || (type == PIM_MSG_TYPE_ASSERT) + || (type == PIM_MSG_TYPE_JOIN_PRUNE)) { + if (addr != qpim_all_pim_routers_addr.s_addr) + return false; + } + + return true; +} + int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) { struct ip *ip_hdr; @@ -237,6 +248,21 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len) } } + if (!pim_pkt_dst_addr_ok(header->type, ip_hdr->ip_dst.s_addr)) { + char dst_str[INET_ADDRSTRLEN]; + char src_str[INET_ADDRSTRLEN]; + + pim_inet4_dump("<dst?>", ip_hdr->ip_dst, dst_str, + sizeof(dst_str)); + pim_inet4_dump("<src?>", ip_hdr->ip_src, src_str, + sizeof(src_str)); + zlog_warn( + "%s: Ignoring Pkt. Unexpected IP destination %s for %s (Expected: all_pim_routers_addr) from %s", + __func__, dst_str, pim_pim_msgtype2str(header->type), + src_str); + return -1; + } + switch (header->type) { case PIM_MSG_TYPE_HELLO: return pim_hello_recv(ifp, ip_hdr->ip_src, @@ -662,7 +688,7 @@ static int hello_send(struct interface *ifp, uint16_t holdtime) return 0; } -static int pim_hello_send(struct interface *ifp, uint16_t holdtime) +int pim_hello_send(struct interface *ifp, uint16_t holdtime) { struct pim_interface *pim_ifp = ifp->info; diff --git a/pimd/pim_pim.h b/pimd/pim_pim.h index e930ab7c2..b9fdb14dc 100644 --- a/pimd/pim_pim.h +++ b/pimd/pim_pim.h @@ -59,4 +59,5 @@ int pim_pim_packet(struct interface *ifp, uint8_t *buf, size_t len); int pim_msg_send(int fd, struct in_addr src, struct in_addr dst, uint8_t *pim_msg, int pim_msg_size, const char *ifname); +int pim_hello_send(struct interface *ifp, uint16_t holdtime); #endif /* PIM_PIM_H */ diff --git a/pimd/pim_vxlan.c b/pimd/pim_vxlan.c index 569b04d27..380c97a97 100644 --- a/pimd/pim_vxlan.c +++ b/pimd/pim_vxlan.c @@ -253,8 +253,17 @@ static void pim_vxlan_orig_mr_up_del(struct pim_vxlan_sg *vxlan_sg) /* if there are other references register the source * for nht */ - if (up) - pim_rpf_update(vxlan_sg->pim, up, NULL, __func__); + if (up) { + enum pim_rpf_result r; + + r = pim_rpf_update(vxlan_sg->pim, up, NULL, __func__); + if (r == PIM_RPF_FAILURE) { + if (PIM_DEBUG_VXLAN) + zlog_debug( + "vxlan SG %s rpf_update failure", + vxlan_sg->sg_str); + } + } } } @@ -788,8 +797,8 @@ void pim_vxlan_sg_del(struct pim_instance *pim, struct prefix_sg *sg) if (!vxlan_sg) return; - pim_vxlan_sg_del_item(vxlan_sg); hash_release(pim->vxlan.sg_hash, vxlan_sg); + pim_vxlan_sg_del_item(vxlan_sg); } /******************************* MLAG handling *******************************/ diff --git a/ripngd/ripng_interface.c b/ripngd/ripng_interface.c index 6a30c07d9..25d9ed2b9 100644 --- a/ripngd/ripng_interface.c +++ b/ripngd/ripng_interface.c @@ -867,17 +867,12 @@ int ripng_network_write(struct vty *vty, struct ripng *ripng) unsigned int i; const char *ifname; struct agg_node *node; - char buf[BUFSIZ]; /* Write enable network. */ for (node = agg_route_top(ripng->enable_network); node; node = agg_route_next(node)) - if (node->info) { - struct prefix *p = &node->p; - vty_out(vty, " %s/%d\n", - inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ), - p->prefixlen); - } + if (node->info) + vty_out(vty, " %pRN\n", node); /* Write enable interface. */ for (i = 0; i < vector_active(ripng->enable_if); i++) diff --git a/ripngd/ripng_nb_state.c b/ripngd/ripng_nb_state.c index 167077ea2..75dec3cb3 100644 --- a/ripngd/ripng_nb_state.c +++ b/ripngd/ripng_nb_state.c @@ -158,7 +158,8 @@ int ripngd_instance_state_routes_route_get_keys(const void *list_entry, const struct agg_node *rn = list_entry; keys->num = 1; - (void)prefix2str(&rn->p, keys->key[0], sizeof(keys->key[0])); + (void)prefix2str(agg_node_get_prefix(rn), keys->key[0], + sizeof(keys->key[0])); return NB_OK; } @@ -191,7 +192,7 @@ ripngd_instance_state_routes_route_prefix_get_elem(const char *xpath, const struct agg_node *rn = list_entry; const struct ripng_info *rinfo = listnode_head(rn->info); - return yang_data_new_ipv6p(xpath, &rinfo->rp->p); + return yang_data_new_ipv6p(xpath, agg_node_get_prefix(rinfo->rp)); } /* diff --git a/ripngd/ripng_zebra.c b/ripngd/ripng_zebra.c index f9bd56d1d..baf7f0096 100644 --- a/ripngd/ripng_zebra.c +++ b/ripngd/ripng_zebra.c @@ -46,12 +46,13 @@ static void ripng_zebra_ipv6_send(struct ripng *ripng, struct agg_node *rp, struct listnode *listnode = NULL; struct ripng_info *rinfo = NULL; int count = 0; + const struct prefix *p = agg_node_get_prefix(rp); memset(&api, 0, sizeof(api)); api.vrf_id = ripng->vrf->vrf_id; api.type = ZEBRA_ROUTE_RIPNG; api.safi = SAFI_UNICAST; - api.prefix = rp->p; + api.prefix = *p; SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { @@ -85,18 +86,17 @@ static void ripng_zebra_ipv6_send(struct ripng *ripng, struct agg_node *rp, if (IS_RIPNG_DEBUG_ZEBRA) { if (ripng->ecmp) - zlog_debug("%s: %s/%d nexthops %d", + zlog_debug("%s: %pRN nexthops %d", (cmd == ZEBRA_ROUTE_ADD) ? "Install into zebra" : "Delete from zebra", - inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen, - count); + rp, count); else - zlog_debug( - "%s: %s/%d", - (cmd == ZEBRA_ROUTE_ADD) ? "Install into zebra" - : "Delete from zebra", - inet6_ntoa(rp->p.u.prefix6), rp->p.prefixlen); + zlog_debug("%s: %pRN", + (cmd == ZEBRA_ROUTE_ADD) + ? "Install into zebra" + : "Delete from zebra", + rp); } } diff --git a/ripngd/ripngd.c b/ripngd/ripngd.c index bb33abdb2..1ea006abd 100644 --- a/ripngd/ripngd.c +++ b/ripngd/ripngd.c @@ -1087,7 +1087,8 @@ void ripng_redistribute_withdraw(struct ripng *ripng, int type) if (IS_RIPNG_DEBUG_EVENT) { struct prefix_ipv6 *p = - (struct prefix_ipv6 *)&rp->p; + (struct prefix_ipv6 *) + agg_node_get_prefix(rp); zlog_debug( "Poisone %s/%d on the interface %s [withdraw]", @@ -1619,7 +1620,7 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, * following * information. */ - p = (struct prefix_ipv6 *)&rp->p; + p = (struct prefix_ipv6 *)agg_node_get_prefix(rp); rinfo->metric_out = rinfo->metric; rinfo->tag_out = rinfo->tag; memset(&rinfo->nexthop_out, 0, @@ -1761,7 +1762,7 @@ void ripng_output_process(struct interface *ifp, struct sockaddr_in6 *to, * following * information. */ - p = (struct prefix_ipv6 *)&rp->p; + p = (struct prefix_ipv6 *)agg_node_get_prefix(rp); aggregate->metric_set = 0; aggregate->metric_out = aggregate->metric; aggregate->tag_out = aggregate->tag; @@ -2053,7 +2054,6 @@ DEFUN (show_ipv6_ripng, struct agg_node *rp; struct ripng_info *rinfo; struct ripng_aggregate *aggregate; - struct prefix_ipv6 *p; struct list *list = NULL; struct listnode *listnode = NULL; int len; @@ -2085,15 +2085,11 @@ DEFUN (show_ipv6_ripng, for (rp = agg_route_top(ripng->table); rp; rp = agg_route_next(rp)) { if ((aggregate = rp->aggregate) != NULL) { - p = (struct prefix_ipv6 *)&rp->p; - #ifdef DEBUG - vty_out(vty, "R(a) %d/%d %s/%d ", aggregate->count, - aggregate->suppress, inet6_ntoa(p->prefix), - p->prefixlen); + vty_out(vty, "R(a) %d/%d %pRN ", aggregate->count, + aggregate->suppress, rp); #else - vty_out(vty, "R(a) %s/%d ", inet6_ntoa(p->prefix), - p->prefixlen); + vty_out(vty, "R(a) %pRN ", rp); #endif /* DEBUG */ vty_out(vty, "\n"); vty_out(vty, "%*s", 18, " "); @@ -2105,19 +2101,15 @@ DEFUN (show_ipv6_ripng, if ((list = rp->info) != NULL) for (ALL_LIST_ELEMENTS_RO(list, listnode, rinfo)) { - p = (struct prefix_ipv6 *)&rp->p; - #ifdef DEBUG - vty_out(vty, "%c(%s) 0/%d %s/%d ", + vty_out(vty, "%c(%s) 0/%d %pRN ", zebra_route_char(rinfo->type), ripng_route_subtype_print(rinfo), - rinfo->suppress, inet6_ntoa(p->prefix), - p->prefixlen); + rinfo->suppress, rp); #else - vty_out(vty, "%c(%s) %s/%d ", + vty_out(vty, "%c(%s) %pRN ", zebra_route_char(rinfo->type), - ripng_route_subtype_print(rinfo), - inet6_ntoa(p->prefix), p->prefixlen); + ripng_route_subtype_print(rinfo), rp); #endif /* DEBUG */ vty_out(vty, "\n"); vty_out(vty, "%*s", 18, " "); diff --git a/staticd/static_vty.c b/staticd/static_vty.c index 40bcf2b5d..a950b0473 100644 --- a/staticd/static_vty.c +++ b/staticd/static_vty.c @@ -867,7 +867,7 @@ DEFPY(ip_route_address_interface, "Table to configure\n" "The table number to configure\n" VRF_CMD_HELP_STR - "Treat the nexthop as directly attached to the interface") + "Treat the nexthop as directly attached to the interface\n") { struct static_vrf *svrf; struct static_vrf *nh_svrf; @@ -935,7 +935,7 @@ DEFPY(ip_route_address_interface_vrf, "Table to configure\n" "The table number to configure\n" VRF_CMD_HELP_STR - "Treat the nexthop as directly attached to the interface") + "Treat the nexthop as directly attached to the interface\n") { VTY_DECLVAR_CONTEXT(vrf, vrf); const char *flag = NULL; @@ -1211,7 +1211,7 @@ DEFPY(ipv6_route_address_interface, "Table to configure\n" "The table number to configure\n" VRF_CMD_HELP_STR - "Treat the nexthop as directly attached to the interface") + "Treat the nexthop as directly attached to the interface\n") { struct static_vrf *svrf; struct static_vrf *nh_svrf; @@ -1279,7 +1279,7 @@ DEFPY(ipv6_route_address_interface_vrf, "Table to configure\n" "The table number to configure\n" VRF_CMD_HELP_STR - "Treat the nexthop as directly attached to the interface") + "Treat the nexthop as directly attached to the interface\n") { VTY_DECLVAR_CONTEXT(vrf, vrf); struct static_vrf *svrf = vrf->info; diff --git a/tests/bgpd/test_mp_attr.c b/tests/bgpd/test_mp_attr.c index c97ea5715..7fabaad7f 100644 --- a/tests/bgpd/test_mp_attr.c +++ b/tests/bgpd/test_mp_attr.c @@ -951,12 +951,19 @@ static struct test_segment mp_prefix_sid[] = { "PREFIX-SID", "PREFIX-SID Test 1", { - 0x01, 0x00, 0x07, - 0x00, 0x00, 0x00, 0x00, - 0x00, 0x00, 0x02, - 0x03, 0x00, 0x08, 0x00, - 0x00, 0x0a, 0x1b, 0xfe, - 0x00, 0x00, 0x0a + /* TLV[0] Latel-Index TLV */ + 0x01, /* Type 0x01:Label-Index */ + 0x00, 0x07, /* Length */ + 0x00, /* RESERVED */ + 0x00, 0x00, /* Flags */ + 0x00, 0x00, 0x00, 0x02, /* Label Index */ + + /* TLV[1] SRGB TLV */ + 0x03, /* Type 0x03:SRGB */ + 0x00, 0x08, /* Length */ + 0x00, 0x00, /* Flags */ + 0x0a, 0x1b, 0xfe, /* SRGB[0] first label */ + 0x00, 0x00, 0x0a /* SRBG[0] nb-labels in range */ }, .len = 21, .parses = SHOULD_PARSE, @@ -1027,7 +1034,7 @@ static void parse_test(struct peer *peer, struct test_segment *t, int type) parse_ret = bgp_mp_unreach_parse(&attr_args, &nlri); break; case BGP_ATTR_PREFIX_SID: - parse_ret = bgp_attr_prefix_sid(&attr_args, &nlri); + parse_ret = bgp_attr_prefix_sid(&attr_args); break; default: printf("unknown type"); diff --git a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py index 16609221c..a671e14e0 100755 --- a/tests/topotests/all-protocol-startup/test_all_protocol_startup.py +++ b/tests/topotests/all-protocol-startup/test_all_protocol_startup.py @@ -307,7 +307,7 @@ def test_converge_protocols(): expected = open(v4_routesFile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) - actual = net['r%s' %i].cmd('vtysh -c "show ip route" | /usr/bin/tail -n +7 | sort 2> /dev/null').rstrip() + actual = net['r%s' %i].cmd('vtysh -c "show ip route" | /usr/bin/tail -n +7 | env LC_ALL=en_US.UTF-8 sort 2> /dev/null').rstrip() # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) @@ -329,7 +329,7 @@ def test_converge_protocols(): expected = open(v6_routesFile).read().rstrip() expected = ('\n'.join(expected.splitlines()) + '\n').splitlines(1) - actual = net['r%s' %i].cmd('vtysh -c "show ipv6 route" | /usr/bin/tail -n +7 | sort 2> /dev/null').rstrip() + actual = net['r%s' %i].cmd('vtysh -c "show ipv6 route" | /usr/bin/tail -n +7 | env LC_ALL=en_US.UTF-8 sort 2> /dev/null').rstrip() # Drop time in last update actual = re.sub(r" [0-2][0-9]:[0-5][0-9]:[0-5][0-9]", " XX:XX:XX", actual) actual = ('\n'.join(actual.splitlines()) + '\n').splitlines(1) diff --git a/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py b/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py index 59858d6fd..e2bd80daa 100755 --- a/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py +++ b/tests/topotests/bfd-bgp-cbit-topo3/test_bfd_bgp_cbit_topo3.py @@ -142,7 +142,7 @@ def test_bfd_connection(): test_func = partial(topotest.router_json_cmp, router, 'show bfd peers json', expected) - _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5) + _, result = topotest.run_and_expect(test_func, None, count=16, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -173,7 +173,7 @@ def test_bfd_loss_intermediate(): test_func = partial(topotest.router_json_cmp, router, 'show bfd peers json', expected) - _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5) + _, result = topotest.run_and_expect(test_func, None, count=16, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg @@ -229,7 +229,7 @@ def test_bfd_comes_back_again(): test_func = partial(topotest.router_json_cmp, router, 'show bfd peers json', expected) - _, result = topotest.run_and_expect(test_func, None, count=8, wait=0.5) + _, result = topotest.run_and_expect(test_func, None, count=16, wait=0.5) assertmsg = '"{}" JSON output mismatches'.format(router.name) assert result is None, assertmsg diff --git a/tests/topotests/bgp_prefix_sid/__init__.py b/tests/topotests/bgp_prefix_sid/__init__.py new file mode 100644 index 000000000..e69de29bb --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/__init__.py diff --git a/tests/topotests/bgp_prefix_sid/exabgp.env b/tests/topotests/bgp_prefix_sid/exabgp.env new file mode 100644 index 000000000..6c554f5fa --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/exabgp.env @@ -0,0 +1,53 @@ + +[exabgp.api] +encoder = text +highres = false +respawn = false +socket = '' + +[exabgp.bgp] +openwait = 60 + +[exabgp.cache] +attributes = true +nexthops = true + +[exabgp.daemon] +daemonize = true +pid = '/var/run/exabgp/exabgp.pid' +user = 'exabgp' + +[exabgp.log] +all = false +configuration = true +daemon = true +destination = '/var/log/exabgp.log' +enable = true +level = INFO +message = false +network = true +packets = false +parser = false +processes = true +reactor = true +rib = false +routes = false +short = false +timers = false + +[exabgp.pdb] +enable = false + +[exabgp.profile] +enable = false +file = '' + +[exabgp.reactor] +speed = 1.0 + +[exabgp.tcp] +acl = false +bind = '' +delay = 0 +once = false +port = 179 diff --git a/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg b/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg new file mode 100644 index 000000000..5b55366a0 --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/peer1/exabgp.cfg @@ -0,0 +1,103 @@ +group controller { + neighbor 10.0.0.1 { + router-id 10.0.0.101; + local-address 10.0.0.101; + local-as 2; + peer-as 1; + + family { + ipv4 nlri-mpls; + } + + static { + # ref: draft-ietf-idr-bgp-prefix-sid-27 + # + # IANA temporarily assigned the following: + # attribute code type (suggested value: 40) to + # the BGP Prefix-SID attribute + # + # 0 1 2 3 + # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Type | Length | RESERVED | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Flags | Label Index | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Label Index | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # Figure. Label-Index TLV (Prefix-SID type-1) + # + # 0 1 2 3 + # 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Type | Length | Flags | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | Flags | + # +-+-+-+-+-+-+-+-+ + # + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | SRGB 1 (6 octets) | + # | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | SRGB n (6 octets) | + # | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ + # | | + # +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+<Paste> + # Figure. Originator SRGB TLV (Prefix-SID type-3) + + # ExaBGP generic-attribute binary pattern: + # Attribute-type: 0x28 (40:BGP_PREFIX_SID) + # Attribute-flag: 0xc0 (Option, Transitive) + # Attribute-body: Label-Index TLV and Originator SRGB TLV + # Label-Index TLV: 0x01000700000000000001 + # Type (08bit): 0x01 + # Length (16bit): 0x0007 + # RESERVED (08bit): 0x00 + # Flags (16bit): 0x0000 + # Label Index (32bit): 0x00000001 + # Originator SRGB TLV: 0x03000800000c350000000a + # Type (08bit): 0x03 + # Length (16bit): 0x0008 (nb-SRGB is 1) + # Flags (16bit): 0x0000 + # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) + route 3.0.0.1/32 next-hop 10.0.0.101 label [800001] attribute [0x28 0xc0 0x0100070000000000000103000800000c350000000a]; + + # ExaBGP generic-attribute binary pattern: + # Attribute-type: 0x28 (40:BGP_PREFIX_SID) + # Attribute-flag: 0xc0 (Option, Transitive) + # Attribute-body: Label-Index TLV and Originator SRGB TLV + # Label-Index TLV: 0x01000700000000000001 + # Type (08bit): 0x01 + # Length (16bit): 0x0007 + # RESERVED (08bit): 0x00 + # Flags (16bit): 0x0000 + # Label Index (32bit): 0x00000002 + # Originator SRGB TLV: 0x03000800000c350000000a + # Type (08bit): 0x03 + # Length (16bit): 0x0008 (nb-SRGB is 1) + # Flags (16bit): 0x0000 + # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) + route 3.0.0.2/32 next-hop 10.0.0.101 label [800002] attribute [0x28 0xc0 0x0100070000000000000203000800000c350000000a]; + + # ExaBGP generic-attribute binary pattern: + # Attribute-type: 0x28 (40:BGP_PREFIX_SID) + # Attribute-flag: 0xc0 (Option, Transitive) + # Attribute-body: Label-Index TLV and Originator SRGB TLV + # Label-Index TLV: 0x01000700000000000001 + # Type (08bit): 0x01 + # Length (16bit): 0x0007 + # RESERVED (08bit): 0x00 + # Flags (16bit): 0x0000 + # Label Index (32bit): 0x00000003 + # Originator SRGB TLV: 0x03000800000c350000000a + # Type (08bit): 0x03 + # Length (16bit): 0x0008 (nb-SRGB is 1) + # Flags (16bit): 0x0000 + # SRGB1 (48bit): 0x0c3500:0x00000a (800000-800010 is SRGB1) + route 3.0.0.3/32 next-hop 10.0.0.101 label [800003] attribute [0x28 0xc0 0x0100070000000000000303000800000c350000000a]; + } + } +} diff --git a/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py b/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py new file mode 100755 index 000000000..eaa6a6787 --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/peer2/exa-receive.py @@ -0,0 +1,37 @@ +#!/usr/bin/env python + +""" +exa-receive.py: Save received routes form ExaBGP into file +""" + +from sys import stdin,argv +from datetime import datetime + +# 1st arg is peer number +peer = int(argv[1]) + +# When the parent dies we are seeing continual newlines, so we only access so many before stopping +counter = 0 + +routesavefile = open('/tmp/peer%s-received.log' % peer, 'w') + +while True: + try: + line = stdin.readline() + routesavefile.write(line) + routesavefile.flush() + + if line == "": + counter += 1 + if counter > 100: + break + continue + + counter = 0 + except KeyboardInterrupt: + pass + except IOError: + # most likely a signal during readline + pass + +routesavefile.close() diff --git a/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg b/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg new file mode 100644 index 000000000..dabd88e03 --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/peer2/exabgp.cfg @@ -0,0 +1,19 @@ +group controller { + + process receive-routes { + run "/etc/exabgp/exa-receive.py 2"; + receive-routes; + encoder json; + } + + neighbor 10.0.0.1 { + router-id 10.0.0.102; + local-address 10.0.0.102; + local-as 3; + peer-as 1; + + family { + ipv4 nlri-mpls; + } + } +} diff --git a/tests/topotests/bgp_prefix_sid/r1/bgpd.conf b/tests/topotests/bgp_prefix_sid/r1/bgpd.conf new file mode 100644 index 000000000..7a38cc307 --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/r1/bgpd.conf @@ -0,0 +1,15 @@ +log stdout notifications +log monitor notifications +log commands +! +router bgp 1 + bgp router-id 10.0.0.1 + no bgp default ipv4-unicast + neighbor 10.0.0.101 remote-as 2 + neighbor 10.0.0.102 remote-as 3 + ! + address-family ipv4 labeled-unicast + neighbor 10.0.0.101 activate + neighbor 10.0.0.102 activate + exit-address-family +! diff --git a/tests/topotests/bgp_prefix_sid/r1/zebra.conf b/tests/topotests/bgp_prefix_sid/r1/zebra.conf new file mode 100644 index 000000000..0cd26052f --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/r1/zebra.conf @@ -0,0 +1,7 @@ +hostname r1 +! +interface r1-eth0 + ip address 10.0.0.1/24 + no shutdown +! +line vty diff --git a/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py new file mode 100755 index 000000000..dc203cabc --- /dev/null +++ b/tests/topotests/bgp_prefix_sid/test_bgp_prefix_sid.py @@ -0,0 +1,173 @@ +#!/usr/bin/env python + +# +# test_bgp_prefix_sid.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2020 by LINE Corporation +# Copyright (c) 2020 by Hiroki Shirokura <slank.dev@gmail.com> +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +test_bgp_prefix_sid.py: Test BGP topology with EBGP on prefix-sid +""" + +import json +import os +import sys +import functools +import pytest + +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, '../')) + +# pylint: disable=C0413 +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger +from mininet.topo import Topo + + +class TemplateTopo(Topo): + def build(self, **_opts): + tgen = get_topogen(self) + router = tgen.add_router('r1') + switch = tgen.add_switch('s1') + switch.add_link(router) + + switch = tgen.gears['s1'] + peer1 = tgen.add_exabgp_peer('peer1', ip='10.0.0.101', defaultRoute='via 10.0.0.1') + peer2 = tgen.add_exabgp_peer('peer2', ip='10.0.0.102', defaultRoute='via 10.0.0.1') + switch.add_link(peer1) + switch.add_link(peer2) + + +def setup_module(module): + tgen = Topogen(TemplateTopo, module.__name__) + tgen.start_topology() + + router = tgen.gears['r1'] + router.load_config(TopoRouter.RD_ZEBRA, os.path.join(CWD, '{}/zebra.conf'.format('r1'))) + router.load_config(TopoRouter.RD_BGP, os.path.join(CWD, '{}/bgpd.conf'.format('r1'))) + router.start() + + logger.info('starting exaBGP on peer1') + peer_list = tgen.exabgp_peers() + for pname, peer in peer_list.iteritems(): + peer_dir = os.path.join(CWD, pname) + env_file = os.path.join(CWD, 'exabgp.env') + logger.info('Running ExaBGP peer') + peer.start(peer_dir, env_file) + logger.info(pname) + + +def teardown_module(module): + tgen = get_topogen() + tgen.stop_topology() + + +def test_r1_receive_and_advertise_prefix_sid_type1(): + tgen = get_topogen() + router = tgen.gears['r1'] + + def _check_type1_r1(router, prefix, remoteLabel, labelIndex): + output = router.vtysh_cmd('show bgp ipv4 labeled-unicast {} json'.format(prefix)) + output = json.loads(output) + expected = { + 'prefix': prefix, + 'advertisedTo': { '10.0.0.101':{}, '10.0.0.102':{} }, + 'paths': [{ + 'valid':True, + 'remoteLabel': remoteLabel, + 'labelIndex': labelIndex, + }] + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_check_type1_r1, router, '3.0.0.1/32', 800001, 1) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, 'Failed _check_type1_r1 in "{}"'.format(router) + + test_func = functools.partial(_check_type1_r1, router, '3.0.0.2/32', 800002, 2) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, 'Failed _check_type1_r1 in "{}"'.format(router) + + +def exabgp_get_update_prefix(filename, afi, nexthop, prefix): + with open('/tmp/peer2-received.log') as f: + for line in f.readlines(): + output = json.loads(line) + ret = output.get('neighbor') + if ret is None: + continue + ret = ret.get('message') + if ret is None: + continue + ret = ret.get('update') + if ret is None: + continue + ret = ret.get('announce') + if ret is None: + continue + ret = ret.get(afi) + if ret is None: + continue + ret = ret.get(nexthop) + if ret is None: + continue + ret = ret.get(prefix) + if ret is None: + continue + return output + return "Not found" + + +def test_peer2_receive_prefix_sid_type1(): + tgen = get_topogen() + peer2 = tgen.gears['peer2'] + + def _check_type1_peer2(prefix, labelindex): + output = exabgp_get_update_prefix('/tmp/peer2-received.log', 'ipv4 nlri-mpls', '10.0.0.101', prefix) + expected = { + 'type': 'update', + 'neighbor': { + 'ip': '10.0.0.1', + 'message': { + 'update': { + 'attribute': { + 'attribute-0x28-0xE0': '0x010007000000{:08x}'.format(labelindex) + }, + 'announce': { 'ipv4 nlri-mpls': { '10.0.0.101': {} } } + } + } + } + } + return topotest.json_cmp(output, expected) + + test_func = functools.partial(_check_type1_peer2, '3.0.0.1/32', labelindex=1) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, 'Failed _check_type1_peer2 in "{}"'.format('peer2') + + test_func = functools.partial(_check_type1_peer2, '3.0.0.2/32', labelindex=2) + success, result = topotest.run_and_expect(test_func, None, count=10, wait=0.5) + assert result is None, 'Failed _check_type1_peer2 in "{}"'.format('peer2') + + +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + ret = pytest.main(args) + sys.exit(ret) diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/ldpd.conf b/tests/topotests/ldp-oc-acl-topo1/r1/ldpd.conf new file mode 100644 index 000000000..85bb970fd --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/ldpd.conf @@ -0,0 +1,25 @@ +hostname r1 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 1.1.1.1 + ordered-control + ! + address-family ipv4 + discovery transport-address 1.1.1.1 + label local allocate host-routes + ! + interface r1-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/ospfd.conf b/tests/topotests/ldp-oc-acl-topo1/r1/ospfd.conf new file mode 100644 index 000000000..6daf034d1 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/ospfd.conf @@ -0,0 +1,7 @@ +hostname r1 +log file ospfd.log +! +router ospf + router-id 1.1.1.1 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-acl-topo1/r1/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..2c493173f --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/show_ip_ospf_neighbor.json @@ -0,0 +1,12 @@ +{ + "neighbors":{ + "2.2.2.2":[ + { + "priority":1, + "state":"Full\/DR", + "address":"10.0.1.2", + "ifaceName":"r1-eth0:10.0.1.1" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/show_ip_route.ref b/tests/topotests/ldp-oc-acl-topo1/r1/show_ip_route.ref new file mode 100644 index 000000000..d75b8f21d --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/show_ip_route.ref @@ -0,0 +1,171 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"1.1.1.1/32", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.1.0/24":[ + { + "prefix":"10.0.1.0/24", + "protocol":"ospf", + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.1.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.2.0/24":[ + { + "prefix":"10.0.2.0/24", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.3.0/24":[ + { + "prefix":"10.0.3.0/24", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "123.0.1.0/24":[ + { + "prefix":"123.0.1.0/24", + "protocol":"ospf", + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + }, + { + "prefix":"123.0.1.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_binding.ref b/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_binding.ref new file mode 100644 index 000000000..ccc841364 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_binding.ref @@ -0,0 +1,55 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"2.2.2.2", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"2.2.2.2", + "localLabel":"-", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"2.2.2.2", + "localLabel":"-", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"2.2.2.2", + "localLabel":"-", + "inUse":1 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_discovery.ref b/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_discovery.ref new file mode 100644 index 000000000..b349f4418 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_discovery.ref @@ -0,0 +1,11 @@ +{ + "adjacencies":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "type":"link", + "interface":"r1-eth0", + "helloHoldtime":15 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_neighbor.ref new file mode 100644 index 000000000..4bff444a4 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/show_ldp_neighbor.ref @@ -0,0 +1,10 @@ +{ + "neighbors":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "state":"OPERATIONAL", + "transportAddress":"2.2.2.2" + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r1/zebra.conf b/tests/topotests/ldp-oc-acl-topo1/r1/zebra.conf new file mode 100644 index 000000000..83aea46e6 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r1/zebra.conf @@ -0,0 +1,17 @@ +log file zebra.log +! +hostname r1 +! +interface lo + ip address 1.1.1.1/32 +! +interface r1-eth0 + description to sw0 + ip address 10.0.1.1/24 + ip address 123.0.1.1/24 +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/ldpd.conf b/tests/topotests/ldp-oc-acl-topo1/r2/ldpd.conf new file mode 100644 index 000000000..e1a552c70 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/ldpd.conf @@ -0,0 +1,28 @@ +hostname r2 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 2.2.2.2 + ordered-control + ! + address-family ipv4 + discovery transport-address 2.2.2.2 + ! + interface r2-eth0 + ! + interface r2-eth1 + ! + interface r2-eth2 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/ospfd.conf b/tests/topotests/ldp-oc-acl-topo1/r2/ospfd.conf new file mode 100644 index 000000000..867881366 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/ospfd.conf @@ -0,0 +1,7 @@ +hostname r2 +log file ospfd.log +! +router ospf + router-id 2.2.2.2 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-acl-topo1/r2/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..55f12359e --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/show_ip_ospf_neighbor.json @@ -0,0 +1,31 @@ +{ + "neighbors":{ + "1.1.1.1":[ + { + "priority":1, + "state":"Full\/Backup", + "address":"10.0.1.1", + "ifaceName":"r2-eth0:10.0.1.2", + "retransmitCounter":0, + "requestCounter":0, + "dbSummaryCounter":0 + } + ], + "3.3.3.3":[ + { + "priority":1, + "state":"Full\/Backup", + "address":"10.0.2.3", + "ifaceName":"r2-eth1:10.0.2.2" + } + ], + "4.4.4.4":[ + { + "priority":1, + "state":"Full\/DR", + "address":"10.0.2.4", + "ifaceName":"r2-eth1:10.0.2.2" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/show_ip_route.ref b/tests/topotests/ldp-oc-acl-topo1/r2/show_ip_route.ref new file mode 100644 index 000000000..060c0b429 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/show_ip_route.ref @@ -0,0 +1,209 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "distance":110, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"2.2.2.2/32", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.1.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + }, + { + "prefix":"10.0.2.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "123.0.1.0\/24":[ + { + "prefix":"123.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_binding.ref b/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_binding.ref new file mode 100644 index 000000000..ea32de3ed --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_binding.ref @@ -0,0 +1,63 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"1.1.1.1", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"3.3.3.3", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"3.3.3.3", + "localLabel":"imp-null", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"3.3.3.3", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_discovery.ref b/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_discovery.ref new file mode 100644 index 000000000..812957008 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_discovery.ref @@ -0,0 +1,18 @@ +{ + "adjacencies":[ + { + "addressFamily":"ipv4", + "neighborId":"1.1.1.1", + "type":"link", + "interface":"r2-eth0", + "helloHoldtime":15 + }, + { + "addressFamily":"ipv4", + "neighborId":"3.3.3.3", + "type":"link", + "interface":"r2-eth1", + "helloHoldtime":15 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_neighbor.ref new file mode 100644 index 000000000..eed35289e --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/show_ldp_neighbor.ref @@ -0,0 +1,16 @@ +{ + "neighbors":[ + { + "addressFamily":"ipv4", + "neighborId":"1.1.1.1", + "state":"OPERATIONAL", + "transportAddress":"1.1.1.1" + }, + { + "addressFamily":"ipv4", + "neighborId":"3.3.3.3", + "state":"OPERATIONAL", + "transportAddress":"3.3.3.3" + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r2/zebra.conf b/tests/topotests/ldp-oc-acl-topo1/r2/zebra.conf new file mode 100644 index 000000000..1f1e3e391 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r2/zebra.conf @@ -0,0 +1,27 @@ +log file zebra.log +! +hostname r2 +! +interface lo + ip address 2.2.2.2/32 +! +interface r2-eth0 + description to sw0 + ip address 10.0.1.2/24 +! no link-detect +! +interface r2-eth1 + description to sw1 + ip address 10.0.2.2/24 +! no link-detect +! +interface r2-eths2 + description to sw2 + ip address 10.0.3.2/24 +! no link-detect +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/ldpd.conf b/tests/topotests/ldp-oc-acl-topo1/r3/ldpd.conf new file mode 100644 index 000000000..4e66b140a --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/ldpd.conf @@ -0,0 +1,24 @@ +hostname r3 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 3.3.3.3 + ordered-control + ! + address-family ipv4 + discovery transport-address 3.3.3.3 + ! + interface r3-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/ospfd.conf b/tests/topotests/ldp-oc-acl-topo1/r3/ospfd.conf new file mode 100644 index 000000000..202be238e --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/ospfd.conf @@ -0,0 +1,8 @@ +hostname r3 +password 1 +log file ospfd.log +! +router ospf + router-id 3.3.3.3 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-acl-topo1/r3/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..24502ed81 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/show_ip_ospf_neighbor.json @@ -0,0 +1,20 @@ +{ + "neighbors":{ + "2.2.2.2":[ + { + "priority":1, + "state":"Full\/DROther", + "address":"10.0.2.2", + "ifaceName":"r3-eth0:10.0.2.3" + } + ], + "4.4.4.4":[ + { + "priority":1, + "state":"Full\/DR", + "address":"10.0.2.4", + "ifaceName":"r3-eth0:10.0.2.3" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/show_ip_route.ref b/tests/topotests/ldp-oc-acl-topo1/r3/show_ip_route.ref new file mode 100644 index 000000000..40800762b --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/show_ip_route.ref @@ -0,0 +1,209 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "distance":110, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"3.3.3.3/32", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.2.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r3-eth1", + "active":true + } + ] + }, + { + "prefix":"10.0.3.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r3-eth1", + "active":true + } + ] + } + ], + "123.0.1.0\/24":[ + { + "prefix":"123.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_binding.ref b/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_binding.ref new file mode 100644 index 000000000..bb1b2b302 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_binding.ref @@ -0,0 +1,62 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"2.2.2.2", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"2.2.2.2", + "localLabel":"imp-null", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_discovery.ref b/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_discovery.ref new file mode 100644 index 000000000..c3a07e7e3 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_discovery.ref @@ -0,0 +1,11 @@ +{ + "adjacencies":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "type":"link", + "interface":"r3-eth0", + "helloHoldtime":15 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_neighbor.ref new file mode 100644 index 000000000..4bff444a4 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/show_ldp_neighbor.ref @@ -0,0 +1,10 @@ +{ + "neighbors":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "state":"OPERATIONAL", + "transportAddress":"2.2.2.2" + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r3/zebra.conf b/tests/topotests/ldp-oc-acl-topo1/r3/zebra.conf new file mode 100644 index 000000000..234c215dd --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r3/zebra.conf @@ -0,0 +1,22 @@ +log file zebra.log +! +hostname r3 +! +interface lo + ip address 3.3.3.3/32 +! +interface r3-eth0 + description to sw1 + ip address 10.0.2.3/24 +! no link-detect +! +interface r3-eth1 + description to sw2 + ip address 10.0.3.3/24 +! no link-detect +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/ldpd.conf b/tests/topotests/ldp-oc-acl-topo1/r4/ldpd.conf new file mode 100644 index 000000000..6b7d28f98 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/ldpd.conf @@ -0,0 +1,24 @@ +hostname r4 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 4.4.4.4 + ordered-control + ! + address-family ipv4 + discovery transport-address 4.4.4.4 + ! + !interface r4-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/ospfd.conf b/tests/topotests/ldp-oc-acl-topo1/r4/ospfd.conf new file mode 100644 index 000000000..569dbc54e --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/ospfd.conf @@ -0,0 +1,7 @@ +hostname r4 +log file ospfd.log +! +router ospf + router-id 4.4.4.4 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-acl-topo1/r4/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..794410522 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/show_ip_ospf_neighbor.json @@ -0,0 +1,21 @@ + +{ + "neighbors":{ + "2.2.2.2":[ + { + "priority":1, + "state":"Full\/DROther", + "address":"10.0.2.2", + "ifaceName":"r4-eth0:10.0.2.4" + } + ], + "3.3.3.3":[ + { + "priority":1, + "state":"Full\/Backup", + "address":"10.0.2.3", + "ifaceName":"r4-eth0:10.0.2.4" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/show_ip_route.ref b/tests/topotests/ldp-oc-acl-topo1/r4/show_ip_route.ref new file mode 100644 index 000000000..c9b83a1c7 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/show_ip_route.ref @@ -0,0 +1,196 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "distance":110, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"4.4.4.4/32", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.2.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "123.0.1.0\/24":[ + { + "prefix":"123.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_binding.ref b/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_binding.ref new file mode 100644 index 000000000..2a46c4034 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_binding.ref @@ -0,0 +1,68 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + } + ] +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_discovery.ref b/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_discovery.ref new file mode 100644 index 000000000..2c63c0851 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_discovery.ref @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_neighbor.ref new file mode 100644 index 000000000..2c63c0851 --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/show_ldp_neighbor.ref @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/ldp-oc-acl-topo1/r4/zebra.conf b/tests/topotests/ldp-oc-acl-topo1/r4/zebra.conf new file mode 100644 index 000000000..7e291053e --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/r4/zebra.conf @@ -0,0 +1,17 @@ +log file zebra.log +! +hostname r4 +! +interface lo + ip address 4.4.4.4/32 +! +interface r4-eth0 + description to sw1 + ip address 10.0.2.4/24 +! no link-detect +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.dot b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.dot new file mode 100644 index 000000000..62058e3cb --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.dot @@ -0,0 +1,76 @@ +## Color coding: +######################### +## Main FRR: #f08080 red +## Switches: #d0e0d0 gray +## RIP: #19e3d9 Cyan +## RIPng: #fcb314 dark yellow +## OSPFv2: #32b835 Green +## OSPFv3: #19e3d9 Cyan +## ISIS IPv4 #fcb314 dark yellow +## ISIS IPv6 #9a81ec purple +## BGP IPv4 #eee3d3 beige +## BGP IPv6 #fdff00 yellow +##### Colors (see http://www.color-hex.com/) + +graph template { + label="Test Topology - LDP-OC 1"; + + # Routers + r1 [ + shape=doubleoctagon, + label="r1", + fillcolor="#f08080", + style=filled, + ]; + r2 [ + shape=doubleoctagon + label="r2", + fillcolor="#f08080", + style=filled, + ]; + r3 [ + shape=doubleoctagon + label="r3", + fillcolor="#f08080", + style=filled, + ]; + r4 [ + shape=doubleoctagon + label="r4", + fillcolor="#f08080", + style=filled, + ]; + + + # Switches + s0 [ + shape=oval, + label="10.0.1.0/24", + fillcolor="#d0e0d0", + style=filled, + ]; + s1 [ + shape=oval, + label="10.0.2.0/24", + fillcolor="#d0e0d0", + style=filled, + ]; + s2 [ + shape=oval, + label="10.0.3.0/24", + fillcolor="#d0e0d0", + style=filled, + ]; + + # Connections + + r1 -- s0 [label="eth0"]; + r2 -- s0 [label="eth0"]; + + r2 -- s1 [label="eth1"]; + r3 -- s1 [label="eth0"]; + r4 -- s1 [label="eth0"]; + + r2 -- s2 [label="eth2"]; + r3 -- s2 [label="eth1"]; +} diff --git a/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py new file mode 100755 index 000000000..47b32a16e --- /dev/null +++ b/tests/topotests/ldp-oc-acl-topo1/test_ldp_oc_acl_topo1.py @@ -0,0 +1,227 @@ +#!/usr/bin/env python + +# +# test_ldp_oc_acl_topo1.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2020 by Volta Networks +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +test_ldp_oc_acl_topo1.py: Simple FRR/Quagga LDP Test + + +---------+ + | r1 | + | 1.1.1.1 | + +----+----+ + | .1 r1-eth0 + | + ~~~~~~~~~~~~~ + ~~ sw0 ~~ + ~~ 10.0.1.0/24 ~~ + ~~~~~~~~~~~~~ + |10.0.1.0/24 + | + | .2 r2-eth0 + +----+----+ + | r2 | + | 2.2.2.2 | + +--+---+--+ + r2-eth2 .2 | | .2 r2-eth1 + ______/ \______ + / \ + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ +~~ sw2 ~~ ~~ sw1 ~~ +~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~ + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + | / | + \ _________/ | + \ / \ +r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 + +----+--+---+ +----+----+ + | r3 | | r4 | + | 3.3.3.3 | | 4.4.4.4 | + +-----------+ +---------+ +""" + +import os +import sys +import pytest +import json +from time import sleep +from functools import partial + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, '../')) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +# Required to instantiate the topology builder class. +from mininet.topo import Topo + +class TemplateTopo(Topo): + "Test topology builder" + def build(self, *_args, **_opts): + "Build function" + tgen = get_topogen(self) + + # + # Define FRR Routers + # + for router in ['r1', 'r2', 'r3', 'r4']: + tgen.add_router(router) + + # + # Define connections + # + switch = tgen.add_switch('s0') + switch.add_link(tgen.gears['r1']) + switch.add_link(tgen.gears['r2']) + + switch = tgen.add_switch('s1') + switch.add_link(tgen.gears['r2']) + switch.add_link(tgen.gears['r3']) + switch.add_link(tgen.gears['r4']) + + switch = tgen.add_switch('s2') + switch.add_link(tgen.gears['r2']) + switch.add_link(tgen.gears['r3']) + +def setup_module(mod): + "Sets up the pytest environment" + tgen = Topogen(TemplateTopo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + # For all registered routers, load the zebra configuration file + for rname, router in router_list.iteritems(): + router.load_config( + TopoRouter.RD_ZEBRA, + os.path.join(CWD, '{}/zebra.conf'.format(rname)) + ) + # Don't start ospfd and ldpd in the CE nodes + if router.name[0] == 'r': + router.load_config( + TopoRouter.RD_OSPF, + os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + ) + router.load_config( + TopoRouter.RD_LDP, + os.path.join(CWD, '{}/ldpd.conf'.format(rname)) + ) + + tgen.start_router() + +def teardown_module(mod): + "Teardown the pytest environment" + tgen = get_topogen() + + # This function tears down the whole topology. + tgen.stop_topology() + + +def router_compare_json_output(rname, command, reference): + "Compare router JSON output" + + logger.info('Comparing router "%s" "%s" output', rname, command) + + tgen = get_topogen() + filename = '{}/{}/{}'.format(CWD, rname, reference) + expected = json.loads(open(filename).read()) + + # Run test function until we get an result. Wait at most 80 seconds. + test_func = partial(topotest.router_json_cmp, + tgen.gears[rname], command, expected) + _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) + + assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) + assert diff is None, assertmsg + +def test_ospf_convergence(): + logger.info("Test: check OSPF adjacencies") + + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json") + +def test_rib(): + logger.info("Test: verify RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show ip route json", "show_ip_route.ref") + +def test_ldp_adjacencies(): + logger.info("Test: verify LDP adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show mpls ldp discovery json", "show_ldp_discovery.ref") + +def test_ldp_neighbors(): + logger.info("Test: verify LDP neighbors") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref") + +def test_ldp_bindings(): + logger.info("Test: verify LDP bindings") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_binding.ref") + +# Memory leak test template +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip('Memory leak test/report is disabled') + + tgen.report_memory_leaks() + +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/ldp-oc-topo1/r1/ldpd.conf b/tests/topotests/ldp-oc-topo1/r1/ldpd.conf new file mode 100644 index 000000000..2a8e02383 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/ldpd.conf @@ -0,0 +1,24 @@ +hostname r1 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 1.1.1.1 + ordered-control + ! + address-family ipv4 + discovery transport-address 1.1.1.1 + ! + interface r1-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r1/ospfd.conf b/tests/topotests/ldp-oc-topo1/r1/ospfd.conf new file mode 100644 index 000000000..6daf034d1 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/ospfd.conf @@ -0,0 +1,7 @@ +hostname r1 +log file ospfd.log +! +router ospf + router-id 1.1.1.1 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-topo1/r1/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-topo1/r1/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..2c493173f --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/show_ip_ospf_neighbor.json @@ -0,0 +1,12 @@ +{ + "neighbors":{ + "2.2.2.2":[ + { + "priority":1, + "state":"Full\/DR", + "address":"10.0.1.2", + "ifaceName":"r1-eth0:10.0.1.1" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-topo1/r1/show_ip_route.ref b/tests/topotests/ldp-oc-topo1/r1/show_ip_route.ref new file mode 100644 index 000000000..d75b8f21d --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/show_ip_route.ref @@ -0,0 +1,171 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"1.1.1.1/32", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.1.0/24":[ + { + "prefix":"10.0.1.0/24", + "protocol":"ospf", + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.1.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.2.0/24":[ + { + "prefix":"10.0.2.0/24", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "10.0.3.0/24":[ + { + "prefix":"10.0.3.0/24", + "protocol":"ospf", + "selected":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ], + "123.0.1.0/24":[ + { + "prefix":"123.0.1.0/24", + "protocol":"ospf", + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + }, + { + "prefix":"123.0.1.0/24", + "protocol":"connected", + "selected":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r1-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r1/show_ldp_binding.ref b/tests/topotests/ldp-oc-topo1/r1/show_ldp_binding.ref new file mode 100644 index 000000000..99a59668f --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/show_ldp_binding.ref @@ -0,0 +1,61 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"2.2.2.2", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"2.2.2.2", + "localLabel":"imp-null", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"2.2.2.2", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r1/show_ldp_discovery.ref b/tests/topotests/ldp-oc-topo1/r1/show_ldp_discovery.ref new file mode 100644 index 000000000..b349f4418 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/show_ldp_discovery.ref @@ -0,0 +1,11 @@ +{ + "adjacencies":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "type":"link", + "interface":"r1-eth0", + "helloHoldtime":15 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r1/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-topo1/r1/show_ldp_neighbor.ref new file mode 100644 index 000000000..4bff444a4 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/show_ldp_neighbor.ref @@ -0,0 +1,10 @@ +{ + "neighbors":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "state":"OPERATIONAL", + "transportAddress":"2.2.2.2" + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r1/zebra.conf b/tests/topotests/ldp-oc-topo1/r1/zebra.conf new file mode 100644 index 000000000..83aea46e6 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r1/zebra.conf @@ -0,0 +1,17 @@ +log file zebra.log +! +hostname r1 +! +interface lo + ip address 1.1.1.1/32 +! +interface r1-eth0 + description to sw0 + ip address 10.0.1.1/24 + ip address 123.0.1.1/24 +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r2/ldpd.conf b/tests/topotests/ldp-oc-topo1/r2/ldpd.conf new file mode 100644 index 000000000..e1a552c70 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/ldpd.conf @@ -0,0 +1,28 @@ +hostname r2 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 2.2.2.2 + ordered-control + ! + address-family ipv4 + discovery transport-address 2.2.2.2 + ! + interface r2-eth0 + ! + interface r2-eth1 + ! + interface r2-eth2 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r2/ospfd.conf b/tests/topotests/ldp-oc-topo1/r2/ospfd.conf new file mode 100644 index 000000000..867881366 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/ospfd.conf @@ -0,0 +1,7 @@ +hostname r2 +log file ospfd.log +! +router ospf + router-id 2.2.2.2 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-topo1/r2/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-topo1/r2/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..55f12359e --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/show_ip_ospf_neighbor.json @@ -0,0 +1,31 @@ +{ + "neighbors":{ + "1.1.1.1":[ + { + "priority":1, + "state":"Full\/Backup", + "address":"10.0.1.1", + "ifaceName":"r2-eth0:10.0.1.2", + "retransmitCounter":0, + "requestCounter":0, + "dbSummaryCounter":0 + } + ], + "3.3.3.3":[ + { + "priority":1, + "state":"Full\/Backup", + "address":"10.0.2.3", + "ifaceName":"r2-eth1:10.0.2.2" + } + ], + "4.4.4.4":[ + { + "priority":1, + "state":"Full\/DR", + "address":"10.0.2.4", + "ifaceName":"r2-eth1:10.0.2.2" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-topo1/r2/show_ip_route.ref b/tests/topotests/ldp-oc-topo1/r2/show_ip_route.ref new file mode 100644 index 000000000..060c0b429 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/show_ip_route.ref @@ -0,0 +1,209 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "distance":110, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"2.2.2.2/32", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.1.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + }, + { + "prefix":"10.0.2.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":3, + "interfaceName":"r2-eth1", + "active":true + } + ] + } + ], + "123.0.1.0\/24":[ + { + "prefix":"123.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.1.1", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r2-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r2/show_ldp_binding.ref b/tests/topotests/ldp-oc-topo1/r2/show_ldp_binding.ref new file mode 100644 index 000000000..95fb847c1 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/show_ldp_binding.ref @@ -0,0 +1,63 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"1.1.1.1", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"3.3.3.3", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"1.1.1.1", + "localLabel":"imp-null", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"3.3.3.3", + "localLabel":"imp-null", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"3.3.3.3", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"1.1.1.1", + "remoteLabel":"imp-null", + "inUse":1 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r2/show_ldp_discovery.ref b/tests/topotests/ldp-oc-topo1/r2/show_ldp_discovery.ref new file mode 100644 index 000000000..812957008 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/show_ldp_discovery.ref @@ -0,0 +1,18 @@ +{ + "adjacencies":[ + { + "addressFamily":"ipv4", + "neighborId":"1.1.1.1", + "type":"link", + "interface":"r2-eth0", + "helloHoldtime":15 + }, + { + "addressFamily":"ipv4", + "neighborId":"3.3.3.3", + "type":"link", + "interface":"r2-eth1", + "helloHoldtime":15 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r2/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-topo1/r2/show_ldp_neighbor.ref new file mode 100644 index 000000000..eed35289e --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/show_ldp_neighbor.ref @@ -0,0 +1,16 @@ +{ + "neighbors":[ + { + "addressFamily":"ipv4", + "neighborId":"1.1.1.1", + "state":"OPERATIONAL", + "transportAddress":"1.1.1.1" + }, + { + "addressFamily":"ipv4", + "neighborId":"3.3.3.3", + "state":"OPERATIONAL", + "transportAddress":"3.3.3.3" + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r2/zebra.conf b/tests/topotests/ldp-oc-topo1/r2/zebra.conf new file mode 100644 index 000000000..1f1e3e391 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r2/zebra.conf @@ -0,0 +1,27 @@ +log file zebra.log +! +hostname r2 +! +interface lo + ip address 2.2.2.2/32 +! +interface r2-eth0 + description to sw0 + ip address 10.0.1.2/24 +! no link-detect +! +interface r2-eth1 + description to sw1 + ip address 10.0.2.2/24 +! no link-detect +! +interface r2-eths2 + description to sw2 + ip address 10.0.3.2/24 +! no link-detect +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r3/ldpd.conf b/tests/topotests/ldp-oc-topo1/r3/ldpd.conf new file mode 100644 index 000000000..4e66b140a --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/ldpd.conf @@ -0,0 +1,24 @@ +hostname r3 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 3.3.3.3 + ordered-control + ! + address-family ipv4 + discovery transport-address 3.3.3.3 + ! + interface r3-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r3/ospfd.conf b/tests/topotests/ldp-oc-topo1/r3/ospfd.conf new file mode 100644 index 000000000..202be238e --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/ospfd.conf @@ -0,0 +1,8 @@ +hostname r3 +password 1 +log file ospfd.log +! +router ospf + router-id 3.3.3.3 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-topo1/r3/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-topo1/r3/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..24502ed81 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/show_ip_ospf_neighbor.json @@ -0,0 +1,20 @@ +{ + "neighbors":{ + "2.2.2.2":[ + { + "priority":1, + "state":"Full\/DROther", + "address":"10.0.2.2", + "ifaceName":"r3-eth0:10.0.2.3" + } + ], + "4.4.4.4":[ + { + "priority":1, + "state":"Full\/DR", + "address":"10.0.2.4", + "ifaceName":"r3-eth0:10.0.2.3" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-topo1/r3/show_ip_route.ref b/tests/topotests/ldp-oc-topo1/r3/show_ip_route.ref new file mode 100644 index 000000000..40800762b --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/show_ip_route.ref @@ -0,0 +1,209 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "distance":110, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"3.3.3.3/32", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.4", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.2.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r3-eth1", + "active":true + } + ] + }, + { + "prefix":"10.0.3.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":3, + "interfaceName":"r3-eth1", + "active":true + } + ] + } + ], + "123.0.1.0\/24":[ + { + "prefix":"123.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r3-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r3/show_ldp_binding.ref b/tests/topotests/ldp-oc-topo1/r3/show_ldp_binding.ref new file mode 100644 index 000000000..100dd307e --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/show_ldp_binding.ref @@ -0,0 +1,61 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"2.2.2.2", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"2.2.2.2", + "remoteLabel":"imp-null", + "inUse":1 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"2.2.2.2", + "localLabel":"imp-null", + "remoteLabel":"imp-null", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"2.2.2.2", + "inUse":1 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r3/show_ldp_discovery.ref b/tests/topotests/ldp-oc-topo1/r3/show_ldp_discovery.ref new file mode 100644 index 000000000..c3a07e7e3 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/show_ldp_discovery.ref @@ -0,0 +1,11 @@ +{ + "adjacencies":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "type":"link", + "interface":"r3-eth0", + "helloHoldtime":15 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r3/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-topo1/r3/show_ldp_neighbor.ref new file mode 100644 index 000000000..4bff444a4 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/show_ldp_neighbor.ref @@ -0,0 +1,10 @@ +{ + "neighbors":[ + { + "addressFamily":"ipv4", + "neighborId":"2.2.2.2", + "state":"OPERATIONAL", + "transportAddress":"2.2.2.2" + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r3/zebra.conf b/tests/topotests/ldp-oc-topo1/r3/zebra.conf new file mode 100644 index 000000000..234c215dd --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r3/zebra.conf @@ -0,0 +1,22 @@ +log file zebra.log +! +hostname r3 +! +interface lo + ip address 3.3.3.3/32 +! +interface r3-eth0 + description to sw1 + ip address 10.0.2.3/24 +! no link-detect +! +interface r3-eth1 + description to sw2 + ip address 10.0.3.3/24 +! no link-detect +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r4/ldpd.conf b/tests/topotests/ldp-oc-topo1/r4/ldpd.conf new file mode 100644 index 000000000..6b7d28f98 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/ldpd.conf @@ -0,0 +1,24 @@ +hostname r4 +log file ldpd.log +! +debug mpls ldp zebra +debug mpls ldp event +debug mpls ldp errors +debug mpls ldp messages recv +debug mpls ldp messages sent +debug mpls ldp discovery hello recv +debug mpls ldp discovery hello sent +! +mpls ldp + router-id 4.4.4.4 + ordered-control + ! + address-family ipv4 + discovery transport-address 4.4.4.4 + ! + !interface r4-eth0 + ! + ! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/r4/ospfd.conf b/tests/topotests/ldp-oc-topo1/r4/ospfd.conf new file mode 100644 index 000000000..569dbc54e --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/ospfd.conf @@ -0,0 +1,7 @@ +hostname r4 +log file ospfd.log +! +router ospf + router-id 4.4.4.4 + network 0.0.0.0/0 area 0 +! diff --git a/tests/topotests/ldp-oc-topo1/r4/show_ip_ospf_neighbor.json b/tests/topotests/ldp-oc-topo1/r4/show_ip_ospf_neighbor.json new file mode 100644 index 000000000..794410522 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/show_ip_ospf_neighbor.json @@ -0,0 +1,21 @@ + +{ + "neighbors":{ + "2.2.2.2":[ + { + "priority":1, + "state":"Full\/DROther", + "address":"10.0.2.2", + "ifaceName":"r4-eth0:10.0.2.4" + } + ], + "3.3.3.3":[ + { + "priority":1, + "state":"Full\/Backup", + "address":"10.0.2.3", + "ifaceName":"r4-eth0:10.0.2.4" + } + ] + } +} diff --git a/tests/topotests/ldp-oc-topo1/r4/show_ip_route.ref b/tests/topotests/ldp-oc-topo1/r4/show_ip_route.ref new file mode 100644 index 000000000..c9b83a1c7 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/show_ip_route.ref @@ -0,0 +1,196 @@ +{ + "1.1.1.1/32":[ + { + "prefix":"1.1.1.1/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "2.2.2.2/32":[ + { + "prefix":"2.2.2.2/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "3.3.3.3/32":[ + { + "prefix":"3.3.3.3/32", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":10, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "4.4.4.4/32":[ + { + "prefix":"4.4.4.4/32", + "protocol":"ospf", + "distance":110, + "metric":0, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + }, + { + "prefix":"4.4.4.4/32", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":1, + "interfaceName":"lo", + "active":true + } + ] + } + ], + "10.0.1.0\/24":[ + { + "prefix":"10.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "10.0.2.0\/24":[ + { + "prefix":"10.0.2.0\/24", + "protocol":"ospf", + "distance":110, + "metric":10, + "nexthops":[ + { + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + }, + { + "prefix":"10.0.2.0\/24", + "protocol":"connected", + "selected":true, + "destSelected":true, + "distance":0, + "metric":0, + "installed":true, + "nexthops":[ + { + "fib":true, + "directlyConnected":true, + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "10.0.3.0\/24":[ + { + "prefix":"10.0.3.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":20, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.3", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ], + "123.0.1.0\/24":[ + { + "prefix":"123.0.1.0\/24", + "protocol":"ospf", + "selected":true, + "destSelected":true, + "distance":110, + "metric":30, + "installed":true, + "nexthops":[ + { + "fib":true, + "ip":"10.0.2.2", + "afi":"ipv4", + "interfaceIndex":2, + "interfaceName":"r4-eth0", + "active":true + } + ] + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r4/show_ldp_binding.ref b/tests/topotests/ldp-oc-topo1/r4/show_ldp_binding.ref new file mode 100644 index 000000000..2a46c4034 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/show_ldp_binding.ref @@ -0,0 +1,68 @@ +{ + "bindings":[ + { + "addressFamily":"ipv4", + "prefix":"1.1.1.1/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"2.2.2.2/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"3.3.3.3/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"4.4.4.4/32", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.1.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.2.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"10.0.3.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + }, + { + "addressFamily":"ipv4", + "prefix":"123.0.1.0/24", + "neighborId":"0.0.0.0", + "localLabel":"imp-null", + "remoteLabel":"-", + "inUse":0 + } + ] +} diff --git a/tests/topotests/ldp-oc-topo1/r4/show_ldp_discovery.ref b/tests/topotests/ldp-oc-topo1/r4/show_ldp_discovery.ref new file mode 100644 index 000000000..2c63c0851 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/show_ldp_discovery.ref @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/ldp-oc-topo1/r4/show_ldp_neighbor.ref b/tests/topotests/ldp-oc-topo1/r4/show_ldp_neighbor.ref new file mode 100644 index 000000000..2c63c0851 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/show_ldp_neighbor.ref @@ -0,0 +1,2 @@ +{ +} diff --git a/tests/topotests/ldp-oc-topo1/r4/zebra.conf b/tests/topotests/ldp-oc-topo1/r4/zebra.conf new file mode 100644 index 000000000..7e291053e --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/r4/zebra.conf @@ -0,0 +1,17 @@ +log file zebra.log +! +hostname r4 +! +interface lo + ip address 4.4.4.4/32 +! +interface r4-eth0 + description to sw1 + ip address 10.0.2.4/24 +! no link-detect +! +ip forwarding +! +! +line vty +! diff --git a/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.dot b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.dot new file mode 100644 index 000000000..62058e3cb --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.dot @@ -0,0 +1,76 @@ +## Color coding: +######################### +## Main FRR: #f08080 red +## Switches: #d0e0d0 gray +## RIP: #19e3d9 Cyan +## RIPng: #fcb314 dark yellow +## OSPFv2: #32b835 Green +## OSPFv3: #19e3d9 Cyan +## ISIS IPv4 #fcb314 dark yellow +## ISIS IPv6 #9a81ec purple +## BGP IPv4 #eee3d3 beige +## BGP IPv6 #fdff00 yellow +##### Colors (see http://www.color-hex.com/) + +graph template { + label="Test Topology - LDP-OC 1"; + + # Routers + r1 [ + shape=doubleoctagon, + label="r1", + fillcolor="#f08080", + style=filled, + ]; + r2 [ + shape=doubleoctagon + label="r2", + fillcolor="#f08080", + style=filled, + ]; + r3 [ + shape=doubleoctagon + label="r3", + fillcolor="#f08080", + style=filled, + ]; + r4 [ + shape=doubleoctagon + label="r4", + fillcolor="#f08080", + style=filled, + ]; + + + # Switches + s0 [ + shape=oval, + label="10.0.1.0/24", + fillcolor="#d0e0d0", + style=filled, + ]; + s1 [ + shape=oval, + label="10.0.2.0/24", + fillcolor="#d0e0d0", + style=filled, + ]; + s2 [ + shape=oval, + label="10.0.3.0/24", + fillcolor="#d0e0d0", + style=filled, + ]; + + # Connections + + r1 -- s0 [label="eth0"]; + r2 -- s0 [label="eth0"]; + + r2 -- s1 [label="eth1"]; + r3 -- s1 [label="eth0"]; + r4 -- s1 [label="eth0"]; + + r2 -- s2 [label="eth2"]; + r3 -- s2 [label="eth1"]; +} diff --git a/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py new file mode 100755 index 000000000..eda1b37e5 --- /dev/null +++ b/tests/topotests/ldp-oc-topo1/test_ldp_oc_topo1.py @@ -0,0 +1,227 @@ +#!/usr/bin/env python + +# +# test_ldp_oc_topo1.py +# Part of NetDEF Topology Tests +# +# Copyright (c) 2020 by by Volta Networks +# +# Permission to use, copy, modify, and/or distribute this software +# for any purpose with or without fee is hereby granted, provided +# that the above copyright notice and this permission notice appear +# in all copies. +# +# THE SOFTWARE IS PROVIDED "AS IS" AND NETDEF DISCLAIMS ALL WARRANTIES +# WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF +# MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL NETDEF BE LIABLE FOR +# ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY +# DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, +# WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS +# ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE +# OF THIS SOFTWARE. +# + +""" +test_ldp_oc_topo1.py: Simple FRR/Quagga LDP Test + + +---------+ + | r1 | + | 1.1.1.1 | + +----+----+ + | .1 r1-eth0 + | + ~~~~~~~~~~~~~ + ~~ sw0 ~~ + ~~ 10.0.1.0/24 ~~ + ~~~~~~~~~~~~~ + |10.0.1.0/24 + | + | .2 r2-eth0 + +----+----+ + | r2 | + | 2.2.2.2 | + +--+---+--+ + r2-eth2 .2 | | .2 r2-eth1 + ______/ \______ + / \ + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ +~~ sw2 ~~ ~~ sw1 ~~ +~~ 10.0.3.0/24 ~~ ~~ 10.0.2.0/24 ~~ + ~~~~~~~~~~~~~ ~~~~~~~~~~~~~ + | / | + \ _________/ | + \ / \ +r3-eth1 .3 | | .3 r3-eth0 | .4 r4-eth0 + +----+--+---+ +----+----+ + | r3 | | r4 | + | 3.3.3.3 | | 4.4.4.4 | + +-----------+ +---------+ +""" + +import os +import sys +import pytest +import json +from time import sleep +from functools import partial + +# Save the Current Working Directory to find configuration files. +CWD = os.path.dirname(os.path.realpath(__file__)) +sys.path.append(os.path.join(CWD, '../')) + +# pylint: disable=C0413 +# Import topogen and topotest helpers +from lib import topotest +from lib.topogen import Topogen, TopoRouter, get_topogen +from lib.topolog import logger + +# Required to instantiate the topology builder class. +from mininet.topo import Topo + +class TemplateTopo(Topo): + "Test topology builder" + def build(self, *_args, **_opts): + "Build function" + tgen = get_topogen(self) + + # + # Define FRR Routers + # + for router in ['r1', 'r2', 'r3', 'r4']: + tgen.add_router(router) + + # + # Define connections + # + switch = tgen.add_switch('s0') + switch.add_link(tgen.gears['r1']) + switch.add_link(tgen.gears['r2']) + + switch = tgen.add_switch('s1') + switch.add_link(tgen.gears['r2']) + switch.add_link(tgen.gears['r3']) + switch.add_link(tgen.gears['r4']) + + switch = tgen.add_switch('s2') + switch.add_link(tgen.gears['r2']) + switch.add_link(tgen.gears['r3']) + +def setup_module(mod): + "Sets up the pytest environment" + tgen = Topogen(TemplateTopo, mod.__name__) + tgen.start_topology() + + router_list = tgen.routers() + + # For all registered routers, load the zebra configuration file + for rname, router in router_list.iteritems(): + router.load_config( + TopoRouter.RD_ZEBRA, + os.path.join(CWD, '{}/zebra.conf'.format(rname)) + ) + # Don't start ospfd and ldpd in the CE nodes + if router.name[0] == 'r': + router.load_config( + TopoRouter.RD_OSPF, + os.path.join(CWD, '{}/ospfd.conf'.format(rname)) + ) + router.load_config( + TopoRouter.RD_LDP, + os.path.join(CWD, '{}/ldpd.conf'.format(rname)) + ) + + tgen.start_router() + +def teardown_module(mod): + "Teardown the pytest environment" + tgen = get_topogen() + + # This function tears down the whole topology. + tgen.stop_topology() + + +def router_compare_json_output(rname, command, reference): + "Compare router JSON output" + + logger.info('Comparing router "%s" "%s" output', rname, command) + + tgen = get_topogen() + filename = '{}/{}/{}'.format(CWD, rname, reference) + expected = json.loads(open(filename).read()) + + # Run test function until we get an result. Wait at most 80 seconds. + test_func = partial(topotest.router_json_cmp, + tgen.gears[rname], command, expected) + _, diff = topotest.run_and_expect(test_func, None, count=160, wait=0.5) + + assertmsg = '"{}" JSON output mismatches the expected result'.format(rname) + assert diff is None, assertmsg + +def test_ospf_convergence(): + logger.info("Test: check OSPF adjacencies") + + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show ip ospf neighbor json", "show_ip_ospf_neighbor.json") + +def test_rib(): + logger.info("Test: verify RIB") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show ip route json", "show_ip_route.ref") + +def test_ldp_adjacencies(): + logger.info("Test: verify LDP adjacencies") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show mpls ldp discovery json", "show_ldp_discovery.ref") + +def test_ldp_neighbors(): + logger.info("Test: verify LDP neighbors") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show mpls ldp neighbor json", "show_ldp_neighbor.ref") + +def test_ldp_bindings(): + logger.info("Test: verify LDP bindings") + tgen = get_topogen() + + # Skip if previous fatal error condition is raised + if tgen.routers_have_failure(): + pytest.skip(tgen.errors) + + for rname in ['r1', 'r2', 'r3', 'r4']: + router_compare_json_output(rname, "show mpls ldp binding json", "show_ldp_binding.ref") + +# Memory leak test template +def test_memory_leak(): + "Run the memory leak test and report results." + tgen = get_topogen() + if not tgen.is_memleak_enabled(): + pytest.skip('Memory leak test/report is disabled') + + tgen.report_memory_leaks() + +if __name__ == '__main__': + args = ["-s"] + sys.argv[1:] + sys.exit(pytest.main(args)) diff --git a/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref b/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref index f244122f1..a13c1d459 100644 --- a/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref +++ b/tests/topotests/ldp-topo1/r1/ip_mpls_route.ref @@ -3,3 +3,4 @@ xx as to xx via inet 10.0.1.2 dev r1-eth0 proto xx xx via inet 10.0.1.2 dev r1-eth0 proto xx xx via inet 10.0.1.2 dev r1-eth0 proto xx xx via inet 10.0.1.2 dev r1-eth0 proto xx + diff --git a/tests/topotests/ospf6-topo1/test_ospf6_topo1.py b/tests/topotests/ospf6-topo1/test_ospf6_topo1.py index cb0c4af22..2f7a4ce4e 100755 --- a/tests/topotests/ospf6-topo1/test_ospf6_topo1.py +++ b/tests/topotests/ospf6-topo1/test_ospf6_topo1.py @@ -319,18 +319,18 @@ def test_linux_ipv6_kernel_routingTable(): # Now compare the routing tables (after substituting link-local addresses) for i in range(1, 5): - if topotest.version_cmp(platform.release(), '5.3') < 0: + # Actual output from router + actual = tgen.gears['r{}'.format(i)].run('ip -6 route').rstrip() + if "nhid" in actual: + refTableFile = os.path.join(CWD, 'r{}/ip_6_address.nhg.ref'.format(i)) + else: refTableFile = os.path.join(CWD, 'r{}/ip_6_address.ref'.format(i)) - else: - refTableFile = os.path.join(CWD, 'r{}/ip_6_address.nhg.ref'.format(i)) - if os.path.isfile(refTableFile): + if os.path.isfile(refTableFile): expected = open(refTableFile).read().rstrip() # Fix newlines (make them all the same) expected = ('\n'.join(expected.splitlines())).splitlines(1) - # Actual output from router - actual = tgen.gears['r{}'.format(i)].run('ip -6 route').rstrip() # Mask out Link-Local mac addresses for ll in linklocals: actual = actual.replace(ll[1], "fe80::__(%s)__" % ll[0]) diff --git a/tools/coccinelle/int_to_bool_function.cocci b/tools/coccinelle/int_to_bool_function.cocci new file mode 100644 index 000000000..f86fe70be --- /dev/null +++ b/tools/coccinelle/int_to_bool_function.cocci @@ -0,0 +1,24 @@ +@@ +identifier fn; +typedef bool; +symbol false; +symbol true; +identifier I; +struct thread *thread; +@@ + +- int ++ bool +fn (...) +{ +... when strict + when != I = THREAD_ARG(thread); +( +- return 0; ++ return false; +| +- return 1; ++ return true; +) +?... +} diff --git a/zebra/redistribute.c b/zebra/redistribute.c index d1148061b..80cc18a57 100644 --- a/zebra/redistribute.c +++ b/zebra/redistribute.c @@ -173,8 +173,7 @@ void redistribute_update(const struct prefix *p, const struct prefix *src_p, afi = family2afi(p->family); if (!afi) { flog_warn(EC_ZEBRA_REDISTRIBUTE_UNKNOWN_AF, - "%s: Unknown AFI/SAFI prefix received\n", - __FUNCTION__); + "%s: Unknown AFI/SAFI prefix received\n", __func__); return; } if (!zebra_check_addr(p)) { diff --git a/zebra/rt_netlink.c b/zebra/rt_netlink.c index e40bf45f5..2f675e2d5 100644 --- a/zebra/rt_netlink.c +++ b/zebra/rt_netlink.c @@ -1111,7 +1111,8 @@ static int build_label_stack(struct mpls_label_stack *nh_label, * @param nlmsg: nlmsghdr structure to fill in. * @param req_size: The size allocated for the message. */ -static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, +static void _netlink_route_build_singlepath(const struct prefix *p, + const char *routedesc, int bytelen, const struct nexthop *nexthop, struct nlmsghdr *nlmsg, struct rtmsg *rtmsg, @@ -1176,9 +1177,8 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - " 5549: _netlink_route_build_singlepath() (%s): " - "nexthop via %s %s if %u(%u)", - routedesc, ipv4_ll_buf, label_buf, + " 5549: _netlink_route_build_singlepath() (%s): %pFX nexthop via %s %s if %u(%u)", + routedesc, p, ipv4_ll_buf, label_buf, nexthop->ifindex, nexthop->vrf_id); return; } @@ -1202,9 +1202,8 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): " - "nexthop via %s %s if %u(%u)", - routedesc, inet_ntoa(nexthop->gate.ipv4), + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u(%u)", + routedesc, p, inet_ntoa(nexthop->gate.ipv4), label_buf, nexthop->ifindex, nexthop->vrf_id); } @@ -1225,9 +1224,8 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): " - "nexthop via %s %s if %u(%u)", - routedesc, inet6_ntoa(nexthop->gate.ipv6), + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u(%u)", + routedesc, p, inet6_ntoa(nexthop->gate.ipv6), label_buf, nexthop->ifindex, nexthop->vrf_id); } @@ -1251,9 +1249,9 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): " - "nexthop via if %u(%u)", - routedesc, nexthop->ifindex, nexthop->vrf_id); + "netlink_route_multipath() (%s): %pFX nexthop via if %u(%u)", + routedesc, p, nexthop->ifindex, + nexthop->vrf_id); } } @@ -1273,12 +1271,11 @@ static void _netlink_route_build_singlepath(const char *routedesc, int bytelen, * @param src: pointer pointing to a location where * the prefsrc should be stored. */ -static void _netlink_route_build_multipath(const char *routedesc, int bytelen, - const struct nexthop *nexthop, - struct rtattr *rta, - struct rtnexthop *rtnh, - struct rtmsg *rtmsg, - const union g_addr **src) +static void +_netlink_route_build_multipath(const struct prefix *p, const char *routedesc, + int bytelen, const struct nexthop *nexthop, + struct rtattr *rta, struct rtnexthop *rtnh, + struct rtmsg *rtmsg, const union g_addr **src) { mpls_lse_t out_lse[MPLS_MAX_LABELS]; char label_buf[256]; @@ -1340,6 +1337,8 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, bytelen); rtnh->rtnh_len += sizeof(struct rtattr) + bytelen; rtnh->rtnh_ifindex = nexthop->ifindex; + if (nexthop->weight) + rtnh->rtnh_hops = nexthop->weight - 1; if (nexthop->rmap_src.ipv4.s_addr != INADDR_ANY) *src = &nexthop->rmap_src; @@ -1348,9 +1347,8 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - " 5549: netlink_route_build_multipath() (%s): " - "nexthop via %s %s if %u", - routedesc, ipv4_ll_buf, label_buf, + " 5549: netlink_route_build_multipath() (%s): %pFX nexthop via %s %s if %u", + routedesc, p, ipv4_ll_buf, label_buf, nexthop->ifindex); return; } @@ -1367,9 +1365,8 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): " - "nexthop via %s %s if %u", - routedesc, inet_ntoa(nexthop->gate.ipv4), + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u", + routedesc, p, inet_ntoa(nexthop->gate.ipv4), label_buf, nexthop->ifindex); } if (nexthop->type == NEXTHOP_TYPE_IPV6 @@ -1385,9 +1382,8 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): " - "nexthop via %s %s if %u", - routedesc, inet6_ntoa(nexthop->gate.ipv6), + "netlink_route_multipath() (%s): %pFX nexthop via %s %s if %u", + routedesc, p, inet6_ntoa(nexthop->gate.ipv6), label_buf, nexthop->ifindex); } @@ -1408,16 +1404,16 @@ static void _netlink_route_build_multipath(const char *routedesc, int bytelen, if (IS_ZEBRA_DEBUG_KERNEL) zlog_debug( - "netlink_route_multipath() (%s): " - "nexthop via if %u", - routedesc, nexthop->ifindex); + "netlink_route_multipath() (%s): %pFX nexthop via if %u", + routedesc, p, nexthop->ifindex); } if (nexthop->weight) rtnh->rtnh_hops = nexthop->weight - 1; } -static inline void _netlink_mpls_build_singlepath(const char *routedesc, +static inline void _netlink_mpls_build_singlepath(const struct prefix *p, + const char *routedesc, const zebra_nhlfe_t *nhlfe, struct nlmsghdr *nlmsg, struct rtmsg *rtmsg, @@ -1428,23 +1424,24 @@ static inline void _netlink_mpls_build_singlepath(const char *routedesc, family = NHLFE_FAMILY(nhlfe); bytelen = (family == AF_INET ? 4 : 16); - _netlink_route_build_singlepath(routedesc, bytelen, nhlfe->nexthop, + _netlink_route_build_singlepath(p, routedesc, bytelen, nhlfe->nexthop, nlmsg, rtmsg, req_size, cmd); } static inline void -_netlink_mpls_build_multipath(const char *routedesc, const zebra_nhlfe_t *nhlfe, - struct rtattr *rta, struct rtnexthop *rtnh, - struct rtmsg *rtmsg, const union g_addr **src) +_netlink_mpls_build_multipath(const struct prefix *p, const char *routedesc, + const zebra_nhlfe_t *nhlfe, struct rtattr *rta, + struct rtnexthop *rtnh, struct rtmsg *rtmsg, + const union g_addr **src) { int bytelen; uint8_t family; family = NHLFE_FAMILY(nhlfe); bytelen = (family == AF_INET ? 4 : 16); - _netlink_route_build_multipath(routedesc, bytelen, nhlfe->nexthop, rta, - rtnh, rtmsg, src); + _netlink_route_build_multipath(p, routedesc, bytelen, nhlfe->nexthop, + rta, rtnh, rtmsg, src); } @@ -1644,6 +1641,10 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx) } if (kernel_nexthops_supported()) { + if (IS_ZEBRA_DEBUG_KERNEL) + zlog_debug( + "netlink_route_multipath(): %pFX nhg_id is %u", + p, dplane_ctx_get_nhe_id(ctx)); /* Kernel supports nexthop objects */ addattr32(&req.n, sizeof(req), RTA_NH_ID, dplane_ctx_get_nhe_id(ctx)); @@ -1730,7 +1731,7 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx) : "single-path"; _netlink_route_build_singlepath( - routedesc, bytelen, nexthop, &req.n, + p, routedesc, bytelen, nexthop, &req.n, &req.r, sizeof(req), cmd); nexthop_num++; break; @@ -1800,8 +1801,8 @@ static int netlink_route_multipath(int cmd, struct zebra_dplane_ctx *ctx) nexthop_num++; _netlink_route_build_multipath( - routedesc, bytelen, nexthop, rta, rtnh, - &req.r, &src1); + p, routedesc, bytelen, nexthop, rta, + rtnh, &req.r, &src1); rtnh = RTNH_NEXT(rtnh); if (!setsrc && src1) { @@ -3464,6 +3465,7 @@ int netlink_mpls_multipath(int cmd, struct zebra_dplane_ctx *ctx) unsigned int nexthop_num; const char *routedesc; int route_type; + struct prefix p = {0}; struct { struct nlmsghdr n; @@ -3550,8 +3552,7 @@ int netlink_mpls_multipath(int cmd, struct zebra_dplane_ctx *ctx) NEXTHOP_FLAG_FIB)))) { /* Add the gateway */ _netlink_mpls_build_singlepath( - routedesc, nhlfe, - &req.n, &req.r, + &p, routedesc, nhlfe, &req.n, &req.r, sizeof(req), cmd); nexthop_num++; @@ -3591,9 +3592,9 @@ int netlink_mpls_multipath(int cmd, struct zebra_dplane_ctx *ctx) nexthop_num++; /* Build the multipath */ - _netlink_mpls_build_multipath(routedesc, nhlfe, - rta, rtnh, &req.r, - &src1); + _netlink_mpls_build_multipath(&p, routedesc, + nhlfe, rta, rtnh, + &req.r, &src1); rtnh = RTNH_NEXT(rtnh); } } diff --git a/zebra/zebra_rnh.c b/zebra/zebra_rnh.c index 6cfc68eb7..c758e2583 100644 --- a/zebra/zebra_rnh.c +++ b/zebra/zebra_rnh.c @@ -1030,7 +1030,7 @@ static int send_client(struct rnh *rnh, struct zserv *client, rnh_type_t type, default: flog_err(EC_ZEBRA_RNH_UNKNOWN_FAMILY, "%s: Unknown family (%d) notification attempted\n", - __FUNCTION__, rn->p.family); + __func__, rn->p.family); break; } if (re) { diff --git a/zebra/zserv.h b/zebra/zserv.h index 6a075cc9a..6ab7fbd91 100644 --- a/zebra/zserv.h +++ b/zebra/zserv.h @@ -314,7 +314,7 @@ extern void zserv_read_file(char *input); #endif /* TODO */ -int zebra_finalize(struct thread *event); +__attribute__((__noreturn__)) int zebra_finalize(struct thread *event); /* * Graceful restart functions. |