From eb9125b3a21bec6331ae6ebce407120d22b17e2f Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 16 Nov 2018 09:14:13 -0500 Subject: [PATCH 01/13] bgpd: Cleanup weird includes of zebra headers There is no reason that bgp should be including zebra headers into it's code base, it is a violation of their respective name spaces. Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 2 -- 1 file changed, 2 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 1cb7e4c5e1..9d76a41075 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -44,8 +44,6 @@ #include "bgpd/bgp_damp.h" #include "bgpd/bgp_fsm.h" #include "bgpd/bgp_vty.h" -#include "zebra/rib.h" -#include "zebra/zserv.h" /* For ZEBRA_SERV_PATH. */ DEFINE_MTYPE_STATIC(BGPD, MARTIAN_STRING, "BGP Martian Address Intf String"); From aaafc3216727276a6daf5f2fc5a050b5601e1eb3 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Sep 2018 18:39:37 -0400 Subject: [PATCH 02/13] bgpd: Reduce size of 'struct bgp_node' by 8 bytes The ordering of data within the `struct bgp_node` was causing extra padding of data. Moving the version to a bit different spot allows for more efficient packing of data. Pre-change: (gdb) p sizeof(struct bgp_node) $1 = 152 (gdb) Post-change: (gdb) p sizeof(struct bgp_node) $1 = 144 (gdb) Signed-off-by: Donald Sharp --- bgpd/bgp_table.h | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index c267b4fe8a..f306a05da1 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -60,9 +60,10 @@ struct bgp_node { STAILQ_ENTRY(bgp_node) pq; + uint64_t version; + mpls_label_t local_label; - uint64_t version; uint8_t flags; #define BGP_NODE_PROCESS_SCHEDULED (1 << 0) #define BGP_NODE_USER_CLEAR (1 << 1) From 6f94b685d0480f7ea427ddfd1c603399dd047aa3 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 30 Jul 2018 11:40:02 -0400 Subject: [PATCH 03/13] bgpd: Abstract bgp_info retrieving/setting from info pointer The bgp_info data is stored as a void pointer in `struct bgp_node`. Abstract retrieval of this data and setting of this data into functions so that in the future we can move around what is stored in bgp_node. Signed-off-by: Donald Sharp --- bgpd/bgp_addpath.c | 8 +-- bgpd/bgp_dump.c | 2 +- bgpd/bgp_evpn.c | 68 +++++++++++++---------- bgpd/bgp_evpn_vty.c | 29 +++++----- bgpd/bgp_flowspec_vty.c | 15 +++--- bgpd/bgp_mplsvpn.c | 24 ++++++--- bgpd/bgp_route.c | 104 ++++++++++++++++++++---------------- bgpd/bgp_rpki.c | 2 +- bgpd/bgp_snmp.c | 6 ++- bgpd/bgp_table.c | 7 +-- bgpd/bgp_table.h | 17 ++++++ bgpd/bgp_updgrp_adv.c | 11 ++-- bgpd/bgp_vpn.c | 7 +-- bgpd/bgp_zebra.c | 4 +- bgpd/rfapi/rfapi.c | 20 ++++--- bgpd/rfapi/rfapi_import.c | 6 ++- bgpd/rfapi/rfapi_vty.c | 2 +- bgpd/rfapi/vnc_export_bgp.c | 12 +++-- bgpd/rfapi/vnc_import_bgp.c | 26 +++++---- bgpd/rfapi/vnc_zebra.c | 3 +- 20 files changed, 224 insertions(+), 149 deletions(-) diff --git a/bgpd/bgp_addpath.c b/bgpd/bgp_addpath.c index 22401f0017..55a86f99fc 100644 --- a/bgpd/bgp_addpath.c +++ b/bgpd/bgp_addpath.c @@ -193,7 +193,7 @@ static void bgp_addpath_flush_type(struct bgp *bgp, afi_t afi, safi_t safi, idalloc_drain_pool( bgp->tx_addpath.id_allocators[afi][safi][addpath_type], &(rn->tx_addpath.free_ids[addpath_type])); - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (pi->tx_addpath.addpath_tx_id[addpath_type] != IDALLOC_INVALID) { idalloc_free( @@ -256,7 +256,7 @@ static void bgp_addpath_populate_type(struct bgp *bgp, afi_t afi, safi_t safi, for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) - for (bi = rn->info; bi; bi = bi->next) + for (bi = bgp_node_get_bgp_path_info(rn); bi; bi = bi->next) bgp_addpath_populate_path(allocator, bi, addpath_type); } @@ -396,7 +396,7 @@ void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_node *bn, afi_t afi, continue; /* Free Unused IDs back to the pool.*/ - for (pi = bn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(bn); pi; pi = pi->next) { if (pi->tx_addpath.addpath_tx_id[i] != IDALLOC_INVALID && !bgp_addpath_tx_path(i, pi)) { idalloc_free_to_pool(pool_ptr, @@ -407,7 +407,7 @@ void bgp_addpath_update_ids(struct bgp *bgp, struct bgp_node *bn, afi_t afi, } /* Give IDs to paths that need them (pulling from the pool) */ - for (pi = bn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(bn); pi; pi = pi->next) { if (pi->tx_addpath.addpath_tx_id[i] == IDALLOC_INVALID && bgp_addpath_tx_path(i, pi)) { pi->tx_addpath.addpath_tx_id[i] = diff --git a/bgpd/bgp_dump.c b/bgpd/bgp_dump.c index 3d1880ca48..751140850a 100644 --- a/bgpd/bgp_dump.c +++ b/bgpd/bgp_dump.c @@ -410,7 +410,7 @@ static unsigned int bgp_dump_routes_func(int afi, int first_run, table = bgp->rib[afi][SAFI_UNICAST]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - path = rn->info; + path = bgp_node_get_bgp_path_info(rn); while (path) { path = bgp_dump_route_node_record(afi, rn, path, seq); seq++; diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index fc3ac28723..729e61a56f 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -1232,7 +1232,8 @@ static int evpn_route_is_def_gw(struct bgp *bgp, struct bgp_node *rn) struct bgp_path_info *local_pi = NULL; local_pi = NULL; - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) { if (tmp_pi->peer == bgp->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -1255,7 +1256,8 @@ static int evpn_route_is_sticky(struct bgp *bgp, struct bgp_node *rn) struct bgp_path_info *local_pi; local_pi = NULL; - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) { if (tmp_pi->peer == bgp->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -1292,7 +1294,8 @@ static int update_evpn_type4_route_entry(struct bgp *bgp, struct evpnes *es, evp = (struct prefix_evpn *)&rn->p; /* locate the local and remote entries if any */ - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) { if (tmp_pi->peer == bgp->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -1303,7 +1306,7 @@ static int update_evpn_type4_route_entry(struct bgp *bgp, struct evpnes *es, remote_pi = tmp_pi; } - /* we don't expect to see a remote_pi at this point. + /* we don't expect to see a remote_ri at this point. * An ES route has esi + vtep_ip as the key, * We shouldn't see the same route from any other vtep. */ @@ -1449,7 +1452,8 @@ static int update_evpn_type5_route_entry(struct bgp *bgp_def, *route_changed = 0; /* locate the local route entry if any */ - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) { if (tmp_pi->peer == bgp_def->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -1587,7 +1591,8 @@ static int update_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, /* See if this is an update of an existing route, or a new add. */ local_pi = NULL; - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) { if (tmp_pi->peer == bgp->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -1726,7 +1731,8 @@ static void evpn_cleanup_local_non_best_route(struct bgp *bgp, bgp_path_info_reap(rn, local_pi); /* tell zebra to re-add the best remote path */ - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); + tmp_pi; tmp_pi = tmp_pi->next) { if (CHECK_FLAG(tmp_pi->flags, BGP_PATH_SELECTED)) { curr_select = tmp_pi; break; @@ -1863,7 +1869,8 @@ static void delete_evpn_route_entry(struct bgp *bgp, afi_t afi, safi_t safi, *pi = NULL; /* Now, find matching route. */ - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) if (tmp_pi->peer == bgp->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -2034,7 +2041,8 @@ static int update_all_type2_routes(struct bgp *bgp, struct bgpevpn *vpn) continue; /* Identify local route. */ - for (tmp_pi = rn->info; tmp_pi; tmp_pi = tmp_pi->next) { + for (tmp_pi = bgp_node_get_bgp_path_info(rn); tmp_pi; + tmp_pi = tmp_pi->next) { if (tmp_pi->peer == bgp->peer_self && tmp_pi->type == ZEBRA_ROUTE_BGP && tmp_pi->sub_type == BGP_ROUTE_STATIC) @@ -2125,7 +2133,7 @@ static int delete_global_type2_routes(struct bgp *bgp, struct bgpevpn *vpn) safi = SAFI_EVPN; rdrn = bgp_node_lookup(bgp->rib[afi][safi], (struct prefix *)&vpn->prd); - if (rdrn && rdrn->info) { + if (rdrn && bgp_node_has_bgp_path_info_data(rdrn)) { table = (struct bgp_table *)rdrn->info; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p; @@ -2195,8 +2203,8 @@ static int delete_all_es_routes(struct bgp *bgp, struct evpnes *es) /* Walk this ES's route table and delete all routes. */ for (rn = bgp_table_top(es->route_table); rn; rn = bgp_route_next(rn)) { - for (pi = rn->info; (pi != NULL) && (nextpi = pi->next, 1); - pi = nextpi) { + for (pi = bgp_node_get_bgp_path_info(rn); + (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { bgp_path_info_delete(rn, pi); bgp_path_info_reap(rn, pi); } @@ -2216,8 +2224,8 @@ static int delete_all_vni_routes(struct bgp *bgp, struct bgpevpn *vpn) /* Walk this VNI's route table and delete all routes. */ for (rn = bgp_table_top(vpn->route_table); rn; rn = bgp_route_next(rn)) { - for (pi = rn->info; (pi != NULL) && (nextpi = pi->next, 1); - pi = nextpi) { + for (pi = bgp_node_get_bgp_path_info(rn); + (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { bgp_path_info_delete(rn, pi); bgp_path_info_reap(rn, pi); } @@ -2353,7 +2361,7 @@ static int install_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es, rn = bgp_node_get(es->route_table, (struct prefix *)p); /* Check if route entry is already present. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->extra && (struct bgp_path_info *)pi->extra->parent == parent_pi) break; @@ -2454,7 +2462,7 @@ static int install_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, attr.flag |= ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP); /* Check if route entry is already present. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->extra && (struct bgp_path_info *)pi->extra->parent == parent_pi) break; @@ -2529,7 +2537,7 @@ static int install_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, rn = bgp_node_get(vpn->route_table, (struct prefix *)p); /* Check if route entry is already present. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->extra && (struct bgp_path_info *)pi->extra->parent == parent_pi) break; @@ -2601,7 +2609,7 @@ static int uninstall_evpn_route_entry_in_es(struct bgp *bgp, struct evpnes *es, return 0; /* Find matching route entry. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->extra && (struct bgp_path_info *)pi->extra->parent == parent_pi) break; @@ -2666,7 +2674,7 @@ static int uninstall_evpn_route_entry_in_vrf(struct bgp *bgp_vrf, return 0; /* Find matching route entry. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->extra && (struct bgp_path_info *)pi->extra->parent == parent_pi) break; @@ -2707,7 +2715,7 @@ static int uninstall_evpn_route_entry(struct bgp *bgp, struct bgpevpn *vpn, return 0; /* Find matching route entry. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->extra && (struct bgp_path_info *)pi->extra->parent == parent_pi) break; @@ -2907,7 +2915,8 @@ static int install_uninstall_routes_for_es(struct bgp *bgp, for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; + pi = pi->next) { /* * Consider "valid" remote routes applicable for * this ES. @@ -2990,7 +2999,8 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf, int install) || is_evpn_prefix_ipaddr_v6(evp))) continue; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; + pi = pi->next) { /* Consider "valid" remote routes applicable for * this VRF. */ @@ -3065,7 +3075,8 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp, if (evp->prefix.route_type != rtype) continue; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; + pi = pi->next) { /* Consider "valid" remote routes applicable for * this VNI. */ if (!(CHECK_FLAG(pi->flags, BGP_PATH_VALID) @@ -3479,7 +3490,7 @@ static int update_advertise_vni_routes(struct bgp *bgp, struct bgpevpn *vpn) rn = bgp_node_lookup(vpn->route_table, (struct prefix *)&p); if (!rn) /* unexpected */ return 0; - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) @@ -3509,7 +3520,7 @@ static int update_advertise_vni_routes(struct bgp *bgp, struct bgpevpn *vpn) if (evp->prefix.route_type != BGP_EVPN_MAC_IP_ROUTE) continue; - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) @@ -4207,7 +4218,7 @@ void bgp_evpn_withdraw_type5_routes(struct bgp *bgp_vrf, afi_t afi, safi_t safi) for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { /* Only care about "selected" routes - non-imported. */ /* TODO: Support for AddPath for EVPN. */ - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && (!pi->extra || !pi->extra->parent)) { bgp_evpn_withdraw_type5_route(bgp_vrf, &rn->p, @@ -4257,7 +4268,7 @@ void bgp_evpn_advertise_type5_routes(struct bgp *bgp_vrf, afi_t afi, * attribute. Also, we only consider "non-imported" routes. * TODO: Support for AddPath for EVPN. */ - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && (!pi->extra || !pi->extra->parent)) { @@ -5225,7 +5236,8 @@ int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp) for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; + pi = pi->next) { /* Consider "valid" remote routes applicable for * this VNI. */ diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index aa5eabeade..d26a2e98e6 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -556,7 +556,8 @@ static void show_esi_routes(struct bgp *bgp, if (json) json_prefix = json_object_new_object(); - if (rn->info) { + pi = bgp_node_get_bgp_path_info(rn); + if (pi) { /* Overall header/legend displayed once. */ if (header) { bgp_evpn_show_route_header(vty, bgp, @@ -573,7 +574,7 @@ static void show_esi_routes(struct bgp *bgp, /* For EVPN, the prefix is displayed for each path (to fit in * with code that already exists). */ - for (pi = rn->info; pi; pi = pi->next) { + for (; pi; pi = pi->next) { json_object *json_path = NULL; if (json) @@ -643,7 +644,8 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type, if (json) json_prefix = json_object_new_object(); - if (rn->info) { + pi = bgp_node_get_bgp_path_info(rn); + if (pi) { /* Overall header/legend displayed once. */ if (header) { bgp_evpn_show_route_header(vty, bgp, @@ -660,7 +662,7 @@ static void show_vni_routes(struct bgp *bgp, struct bgpevpn *vpn, int type, /* For EVPN, the prefix is displayed for each path (to fit in * with code that already exists). */ - for (pi = rn->info; pi; pi = pi->next) { + for (; pi; pi = pi->next) { json_object *json_path = NULL; if (vtep_ip.s_addr @@ -1046,7 +1048,8 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, tbl_ver = table->version; for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) - for (pi = rm->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rm); pi; + pi = pi->next) { total_count++; if (type == bgp_show_type_neighbor) { union sockunion *su = output_arg; @@ -2049,7 +2052,7 @@ static void evpn_show_route_vni_multicast(struct vty *vty, struct bgp *bgp, route_vty_out_detail_header(vty, bgp, rn, NULL, afi, safi, json); /* Display each path for this prefix. */ - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { json_object *json_path = NULL; if (json) @@ -2119,7 +2122,7 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp, route_vty_out_detail_header(vty, bgp, rn, NULL, afi, safi, json); /* Display each path for this prefix. */ - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { json_object *json_path = NULL; if (json) @@ -2226,7 +2229,7 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp, json_paths = json_object_new_array(); /* Display each path for this prefix. */ - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { json_object *json_path = NULL; if (json) @@ -2307,7 +2310,8 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp, if (json) json_prefix = json_object_new_object(); - if (rn->info) { + pi = bgp_node_get_bgp_path_info(rn); + if (pi) { /* RD header and legend - once overall. */ if (rd_header && !json) { vty_out(vty, @@ -2330,7 +2334,7 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp, json_paths = json_object_new_array(); /* Display each path for this prefix. */ - for (pi = rn->info; pi; pi = pi->next) { + for (; pi; pi = pi->next) { json_object *json_path = NULL; if (json) @@ -2435,7 +2439,8 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, if (type && evp->prefix.route_type != type) continue; - if (rn->info) { + pi = bgp_node_get_bgp_path_info(rn); + if (pi) { /* Overall header/legend displayed once. */ if (header) { bgp_evpn_show_route_header(vty, bgp, @@ -2467,7 +2472,7 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, * fit in * with code that already exists). */ - for (pi = rn->info; pi; pi = pi->next) { + for (; pi; pi = pi->next) { json_object *json_path = NULL; path_cnt++; add_prefix_to_json = 1; diff --git a/bgpd/bgp_flowspec_vty.c b/bgpd/bgp_flowspec_vty.c index 4fb055bcc3..1fce2d0608 100644 --- a/bgpd/bgp_flowspec_vty.c +++ b/bgpd/bgp_flowspec_vty.c @@ -379,13 +379,14 @@ int bgp_show_table_flowspec(struct vty *vty, struct bgp *bgp, afi_t afi, return CMD_SUCCESS; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - if (rn->info == NULL) + pi = bgp_node_get_bgp_path_info(rn); + if (pi == NULL) continue; if (use_json) { json_paths = json_object_new_array(); display = NLRI_STRING_FORMAT_JSON; } - for (pi = rn->info; pi; pi = pi->next) { + for (; pi; pi = pi->next) { total_count++; route_vty_out_flowspec(vty, &rn->p, pi, display, json_paths); @@ -542,11 +543,11 @@ extern int bgp_flowspec_display_match_per_ip(afi_t afi, struct bgp_table *rib, continue; if (bgp_flowspec_contains_prefix(prefix, match, prefix_check)) { - route_vty_out_flowspec(vty, &rn->p, - rn->info, use_json ? - NLRI_STRING_FORMAT_JSON : - NLRI_STRING_FORMAT_LARGE, - json_paths); + route_vty_out_flowspec( + vty, &rn->p, bgp_node_get_bgp_path_info(rn), + use_json ? NLRI_STRING_FORMAT_JSON + : NLRI_STRING_FORMAT_LARGE, + json_paths); display++; } } diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 6668823d64..24ac4ca078 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -500,7 +500,7 @@ leak_update(struct bgp *bgp, /* destination bgp instance */ /* * match parent */ - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; bpi = bpi->next) { if (bpi->extra && bpi->extra->parent == parent) break; } @@ -919,11 +919,13 @@ void vpn_leak_from_vrf_withdraw(struct bgp *bgp_vpn, /* to */ bn = bgp_afi_node_get(bgp_vpn->rib[afi][safi], afi, safi, p, &(bgp_vrf->vpn_policy[afi].tovpn_rd)); + if (!bn) + return; /* * vrf -> vpn * match original bpi imported from */ - for (bpi = (bn ? bn->info : NULL); bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; bpi = bpi->next) { if (bpi->extra && bpi->extra->parent == path_vrf) { break; } @@ -968,13 +970,14 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn, /* to */ char buf[PREFIX2STR_BUFFER]; - if (debug && bn->info) { + bpi = bgp_node_get_bgp_path_info(bn); + if (debug && bpi) { zlog_debug( "%s: looking at prefix %s", __func__, prefix2str(&bn->p, buf, sizeof(buf))); } - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (; bpi; bpi = bpi->next) { if (debug) zlog_debug("%s: type %d, sub_type %d", __func__, bpi->type, @@ -1017,7 +1020,8 @@ void vpn_leak_from_vrf_update_all(struct bgp *bgp_vpn, /* to */ if (debug) zlog_debug("%s: node=%p", __func__, bn); - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; + bpi = bpi->next) { if (debug) zlog_debug( "%s: calling vpn_leak_from_vrf_update", @@ -1299,7 +1303,9 @@ void vpn_leak_to_vrf_withdraw(struct bgp *bgp_vpn, /* from */ bgp->name_pretty); bn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL); - for (bpi = (bn ? bn->info : NULL); bpi; bpi = bpi->next) { + + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; + bpi = bpi->next) { if (bpi->extra && (struct bgp_path_info *)bpi->extra->parent == path_vpn) { @@ -1335,7 +1341,8 @@ void vpn_leak_to_vrf_withdraw_all(struct bgp *bgp_vrf, /* to */ for (bn = bgp_table_top(bgp_vrf->rib[afi][safi]); bn; bn = bgp_route_next(bn)) { - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; + bpi = bpi->next) { if (bpi->extra && bpi->extra->bgp_orig != bgp_vrf) { /* delete route */ @@ -1381,7 +1388,8 @@ void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, /* to */ for (bn = bgp_table_top(table); bn; bn = bgp_route_next(bn)) { - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; + bpi = bpi->next) { if (bpi->extra && bpi->extra->bgp_orig == bgp_vrf) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index bb8c5d8f6e..b59a59e6a7 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -152,7 +152,7 @@ struct bgp_node *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi, if (!prn) return NULL; - if (prn->info == NULL) { + if (!bgp_node_has_bgp_path_info_data(prn)) { bgp_unlock_node(prn); return NULL; } @@ -291,13 +291,13 @@ void bgp_path_info_add(struct bgp_node *rn, struct bgp_path_info *pi) { struct bgp_path_info *top; - top = rn->info; + top = bgp_node_get_bgp_path_info(rn); - pi->next = rn->info; + pi->next = top; pi->prev = NULL; if (top) top->prev = pi; - rn->info = pi; + bgp_node_set_bgp_path_info(rn, pi); bgp_path_info_lock(pi); bgp_lock_node(rn); @@ -313,7 +313,7 @@ void bgp_path_info_reap(struct bgp_node *rn, struct bgp_path_info *pi) if (pi->prev) pi->prev->next = pi->next; else - rn->info = pi->next; + bgp_node_set_bgp_path_info(rn, pi->next); bgp_path_info_mpath_dequeue(pi); bgp_path_info_unlock(pi); @@ -1895,11 +1895,13 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, if (bgp_flag_check(bgp, BGP_FLAG_DETERMINISTIC_MED)) { /* Clear BGP_PATH_DMED_SELECTED for all paths */ - for (pi1 = rn->info; pi1; pi1 = pi1->next) + for (pi1 = bgp_node_get_bgp_path_info(rn); pi1; + pi1 = pi1->next) bgp_path_info_unset_flag(rn, pi1, BGP_PATH_DMED_SELECTED); - for (pi1 = rn->info; pi1; pi1 = pi1->next) { + for (pi1 = bgp_node_get_bgp_path_info(rn); pi1; + pi1 = pi1->next) { if (CHECK_FLAG(pi1->flags, BGP_PATH_DMED_CHECK)) continue; if (BGP_PATH_HOLDDOWN(pi1)) @@ -1965,8 +1967,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, /* Check old selected route and new selected route. */ old_select = NULL; new_select = NULL; - for (pi = rn->info; (pi != NULL) && (nextpi = pi->next, 1); - pi = nextpi) { + for (pi = bgp_node_get_bgp_path_info(rn); + (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) old_select = pi; @@ -2030,8 +2032,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_node *rn, } if (do_mpath && new_select) { - for (pi = rn->info; (pi != NULL) && (nextpi = pi->next, 1); - pi = nextpi) { + for (pi = bgp_node_get_bgp_path_info(rn); + (pi != NULL) && (nextpi = pi->next, 1); pi = nextpi) { if (debug) bgp_path_info_path_with_addpath_rx_str( @@ -2151,7 +2153,7 @@ void bgp_zebra_clear_route_change_flags(struct bgp_node *rn) { struct bgp_path_info *pi; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (BGP_PATH_HOLDDOWN(pi)) continue; UNSET_FLAG(pi->flags, BGP_PATH_IGP_CHANGED); @@ -2948,7 +2950,7 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, bgp_adj_in_set(rn, peer, attr, addpath_id); /* Check previously received route. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == peer && pi->type == type && pi->sub_type == sub_type && pi->addpath_rx_id == addpath_id) @@ -3611,7 +3613,7 @@ int bgp_withdraw(struct peer *peer, struct prefix *p, uint32_t addpath_id, } /* Lookup withdrawn route. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == peer && pi->type == type && pi->sub_type == sub_type && pi->addpath_rx_id == addpath_id) @@ -3765,7 +3767,8 @@ static void bgp_soft_reconfig_table(struct peer *peer, afi_t afi, safi_t safi, if (ain->peer != peer) continue; - struct bgp_path_info *pi = rn->info; + struct bgp_path_info *pi = + bgp_node_get_bgp_path_info(rn); uint32_t num_labels = 0; mpls_label_t *label_pnt = NULL; @@ -3832,7 +3835,7 @@ static wq_item_status bgp_clear_route_node(struct work_queue *wq, void *data) /* It is possible that we have multiple paths for a prefix from a peer * if that peer is using AddPath. */ - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (pi->peer != peer) continue; @@ -3971,7 +3974,7 @@ static void bgp_clear_route_table(struct peer *peer, afi_t afi, safi_t safi, ain = ain_next; } - for (pi = rn->info; pi; pi = next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = next) { next = pi->next; if (pi->peer != peer) continue; @@ -4095,7 +4098,8 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) - for (pi = rm->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rm); pi; + pi = pi->next) { if (pi->peer != peer) continue; if (!CHECK_FLAG(pi->flags, @@ -4109,7 +4113,8 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) } else { for (rn = bgp_table_top(peer->bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; + pi = pi->next) { if (pi->peer != peer) continue; if (!CHECK_FLAG(pi->flags, BGP_PATH_STALE)) @@ -4128,7 +4133,7 @@ static void bgp_cleanup_table(struct bgp *bgp, struct bgp_table *table, struct bgp_path_info *next; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) - for (pi = rn->info; pi; pi = next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = next) { next = pi->next; if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && pi->type == ZEBRA_ROUTE_BGP @@ -4458,7 +4463,7 @@ void bgp_static_update(struct bgp *bgp, struct prefix *p, attr_new = bgp_attr_intern(&attr); } - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) break; @@ -4626,7 +4631,7 @@ void bgp_static_withdraw(struct bgp *bgp, struct prefix *p, afi_t afi, rn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, NULL); /* Check selected route and self inserted route. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) break; @@ -4661,7 +4666,7 @@ static void bgp_static_withdraw_safi(struct bgp *bgp, struct prefix *p, rn = bgp_afi_node_get(bgp->rib[afi][safi], afi, safi, p, prd); /* Check selected route and self inserted route. */ - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) break; @@ -4771,7 +4776,7 @@ static void bgp_static_update_safi(struct bgp *bgp, struct prefix *p, attr_new = bgp_attr_intern(&attr); } - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) break; @@ -5115,7 +5120,7 @@ static void bgp_purge_af_static_redist_routes(struct bgp *bgp, afi_t afi, table = bgp->rib[afi][safi]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (pi->peer == bgp->peer_self && ((pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_STATIC) @@ -5553,13 +5558,13 @@ static void bgp_aggregate_install(struct bgp *bgp, afi_t afi, safi_t safi, { struct bgp_node *rn; struct bgp_table *table; - struct bgp_path_info *pi, *new; + struct bgp_path_info *pi, *orig, *new; table = bgp->rib[afi][safi]; rn = bgp_node_get(table, p); - for (pi = rn->info; pi; pi = pi->next) + for (orig = pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_AGGREGATE) break; @@ -5569,7 +5574,7 @@ static void bgp_aggregate_install(struct bgp *bgp, afi_t afi, safi_t safi, * If the aggregate information has not changed * no need to re-install it again. */ - if (bgp_aggregate_info_same(rn->info, origin, aspath, community, + if (bgp_aggregate_info_same(orig, origin, aspath, community, ecommunity, lcommunity)) { bgp_unlock_node(rn); @@ -5604,7 +5609,7 @@ static void bgp_aggregate_install(struct bgp *bgp, afi_t afi, safi_t safi, bgp_path_info_add(rn, new); bgp_process(bgp, rn, afi, safi); } else { - for (pi = rn->info; pi; pi = pi->next) + for (pi = orig; pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == ZEBRA_ROUTE_BGP && pi->sub_type == BGP_ROUTE_AGGREGATE) @@ -5662,7 +5667,7 @@ static void bgp_aggregate_route(struct bgp *bgp, struct prefix *p, match = 0; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (BGP_PATH_HOLDDOWN(pi)) continue; @@ -5854,7 +5859,7 @@ static void bgp_aggregate_delete(struct bgp *bgp, struct prefix *p, afi_t afi, continue; match = 0; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (BGP_PATH_HOLDDOWN(pi)) continue; @@ -6269,7 +6274,8 @@ void bgp_redistribute_add(struct bgp *bgp, struct prefix *p, new_attr = bgp_attr_intern(&attr_new); - for (bpi = bn->info; bpi; bpi = bpi->next) + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; + bpi = bpi->next) if (bpi->peer == bgp->peer_self && bpi->sub_type == BGP_ROUTE_REDISTRIBUTE) break; @@ -6351,7 +6357,7 @@ void bgp_redistribute_delete(struct bgp *bgp, struct prefix *p, uint8_t type, rn = bgp_afi_node_get(bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, p, NULL); - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == type) break; @@ -6381,7 +6387,7 @@ void bgp_redistribute_withdraw(struct bgp *bgp, afi_t afi, int type, table = bgp->rib[afi][SAFI_UNICAST]; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (pi->peer == bgp->peer_self && pi->type == type && pi->instance == instance) break; @@ -8446,7 +8452,8 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, /* Start processing of routes. */ for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - if (rn->info == NULL) + pi = bgp_node_get_bgp_path_info(rn); + if (pi == NULL) continue; display = 0; @@ -8455,7 +8462,7 @@ static int bgp_show_table(struct vty *vty, struct bgp *bgp, safi_t safi, else json_paths = NULL; - for (pi = rn->info; pi; pi = pi->next) { + for (; pi; pi = pi->next) { total_count++; if (type == bgp_show_type_flap_statistics || type == bgp_show_type_flap_neighbor @@ -8897,7 +8904,7 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp, vty_out(vty, "not allocated\n"); } - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { count++; if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED)) { best = count; @@ -9076,7 +9083,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, continue; } - for (pi = rm->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rm); pi; + pi = pi->next) { if (header) { route_vty_out_detail_header( vty, bgp, rm, @@ -9114,7 +9122,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, if ((rn = bgp_node_match(rib, &match)) != NULL) { if (!prefix_check || rn->p.prefixlen == match.prefixlen) { - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; + pi = pi->next) { if (header) { route_vty_out_detail_header( vty, bgp, rn, NULL, afi, @@ -9923,7 +9932,7 @@ static int bgp_table_stats_walker(struct thread *t) if (rn == top) continue; - if (!rn->info) + if (!bgp_node_has_bgp_path_info_data(rn)) continue; ts->counts[BGP_STATS_PREFIXES]++; @@ -9937,7 +9946,7 @@ static int bgp_table_stats_walker(struct thread *t) #endif /* check if the prefix is included by any other announcements */ - while (prn && !prn->info) + while (prn && !bgp_node_has_bgp_path_info_data(prn)) prn = bgp_node_parent_nolock(prn); if (prn == NULL || prn == top) { @@ -9946,10 +9955,10 @@ static int bgp_table_stats_walker(struct thread *t) if (space) ts->total_space += pow(2.0, space - rn->p.prefixlen); - } else if (prn->info) + } else if (bgp_node_has_bgp_path_info_data(prn)) ts->counts[BGP_STATS_MAX_AGGREGATEABLE]++; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { pinum++; ts->counts[BGP_STATS_RIB]++; @@ -10132,7 +10141,8 @@ static int bgp_peer_count_walker(struct thread *t) if (ain->peer == peer) pc->count[PCOUNT_ADJ_IN]++; - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { + if (pi->peer != peer) continue; @@ -11095,7 +11105,7 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, XFREE(MTYPE_AS_LIST, bdistance->access_list); bgp_distance_free(bdistance); - rn->info = NULL; + bgp_node_set_bgp_path_info(rn, NULL); bgp_unlock_node(rn); bgp_unlock_node(rn); @@ -11425,7 +11435,7 @@ static int bgp_clear_damp_route(struct vty *vty, const char *view_name, if (!prefix_check || rm->p.prefixlen == match.prefixlen) { - pi = rm->info; + pi = bgp_node_get_bgp_path_info(rm); while (pi) { if (pi->extra && pi->extra->damp_info) { pi_temp = pi->next; @@ -11445,7 +11455,7 @@ static int bgp_clear_damp_route(struct vty *vty, const char *view_name, != NULL) { if (!prefix_check || rn->p.prefixlen == match.prefixlen) { - pi = rn->info; + pi = bgp_node_get_bgp_path_info(rn); while (pi) { if (pi->extra && pi->extra->damp_info) { pi_temp = pi->next; diff --git a/bgpd/bgp_rpki.c b/bgpd/bgp_rpki.c index 77bd2eaefa..e80080fedd 100644 --- a/bgpd/bgp_rpki.c +++ b/bgpd/bgp_rpki.c @@ -418,7 +418,7 @@ static void revalidate_bgp_node(struct bgp_node *bgp_node, afi_t afi, for (ain = bgp_node->adj_in; ain; ain = ain->next) { int ret; - struct bgp_path_info *path = bgp_node->info; + struct bgp_path_info *path = bgp_info_from_node(bgp_node); mpls_label_t *label = NULL; uint32_t num_labels = 0; diff --git a/bgpd/bgp_snmp.c b/bgpd/bgp_snmp.c index d539fad510..e9ba93bbd4 100644 --- a/bgpd/bgp_snmp.c +++ b/bgpd/bgp_snmp.c @@ -715,7 +715,8 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], if (rn) { bgp_unlock_node(rn); - for (path = rn->info; path; path = path->next) + for (path = bgp_info_from_node(rn); path; + path = path->next) if (sockunion_same(&path->peer->su, &su)) return path; } @@ -762,7 +763,8 @@ static struct bgp_path_info *bgp4PathAttrLookup(struct variable *v, oid name[], do { min = NULL; - for (path = rn->info; path; path = path->next) { + for (path = bgp_info_from_node(rn); path; + path = path->next) { if (path->peer->su.sin.sin_family == AF_INET && ntohl(paddr.s_addr) < ntohl(path->peer->su.sin diff --git a/bgpd/bgp_table.c b/bgpd/bgp_table.c index 728eeaa3a9..0329995224 100644 --- a/bgpd/bgp_table.c +++ b/bgpd/bgp_table.c @@ -156,7 +156,8 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, while (node && node->p.prefixlen <= p->prefixlen && prefix_match(&node->p, p)) { - if (node->info && node->p.prefixlen == p->prefixlen) { + if (bgp_node_has_bgp_path_info_data(node) + && node->p.prefixlen == p->prefixlen) { matched = node; break; } @@ -172,14 +173,14 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, else if (matched == NULL) matched = node = bgp_node_from_rnode(node->parent); - if (matched->info) { + if (bgp_node_has_bgp_path_info_data(matched)) { bgp_lock_node(matched); listnode_add(matches, matched); } while ((node = bgp_route_next_until_maxlen(node, matched, maxlen))) { if (prefix_match(p, &node->p)) { - if (node->info) { + if (bgp_node_has_bgp_path_info_data(node)) { bgp_lock_node(node); listnode_add(matches, node); } diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index f306a05da1..87fbc39f43 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -376,4 +376,21 @@ static inline void bgp_nexthop_set_node_info(struct bgp_node *node, node->info = bnc; } +static inline struct bgp_path_info * +bgp_node_get_bgp_path_info(struct bgp_node *node) +{ + return node->info; +} + +static inline void bgp_node_set_bgp_path_info(struct bgp_node *node, + struct bgp_path_info *bi) +{ + node->info = bi; +} + +static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node *node) +{ + return !!node->info; +} + #endif /* _QUAGGA_BGP_TABLE_H */ diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index 7196bbbf12..ff7d18761c 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -114,7 +114,8 @@ static void subgrp_withdraw_stale_addpath(struct updwalk_context *ctx, adj_next = adj->next; if (adj->subgroup == subgrp) { - for (pi = ctx->rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(ctx->rn); + pi; pi = pi->next) { id = bgp_addpath_id_for_peer(peer, afi, safi, &pi->tx_addpath); @@ -168,7 +169,8 @@ static int group_announce_route_walkcb(struct update_group *updgrp, void *arg) if (addpath_capable) { subgrp_withdraw_stale_addpath(ctx, subgrp); - for (pi = ctx->rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(ctx->rn); + pi; pi = pi->next) { /* Skip the bestpath for now */ if (pi == ctx->pi) continue; @@ -622,7 +624,7 @@ void subgroup_announce_table(struct update_subgroup *subgrp, subgroup_default_originate(subgrp, 0); for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) - for (ri = rn->info; ri; ri = ri->next) + for (ri = bgp_node_get_bgp_path_info(rn); ri; ri = ri->next) if (CHECK_FLAG(ri->flags, BGP_PATH_SELECTED) || (addpath_capable @@ -745,7 +747,8 @@ void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) SET_FLAG(bgp->peer_self->rmap_type, PEER_RMAP_TYPE_DEFAULT); for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) { - for (ri = rn->info; ri; ri = ri->next) { + for (ri = bgp_node_get_bgp_path_info(rn); + ri; ri = ri->next) { struct attr dummy_attr; /* Provide dummy so the route-map can't modify diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index 2b4477ddde..99bcefe70c 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -38,7 +38,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, struct bgp_table *table; struct bgp_node *rn; struct bgp_node *rm; - struct attr *attr; + struct bgp_path_info *path; int rd_header; int header = 1; json_object *json = NULL; @@ -89,7 +89,8 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { - if ((attr = rm->info) != NULL) { + path = bgp_node_get_bgp_path_info(rm); + if (path != NULL) { if (header) { if (use_json) { json_object_int_add( @@ -238,7 +239,7 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, json_array); } else { route_vty_out_tmp( - vty, &rm->p, attr, + vty, &rm->p, path->attr, SAFI_MPLS_VPN, use_json, json_array); } diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index 62f977eee1..9a4a639fef 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1480,7 +1480,7 @@ void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi) return; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) - for (pi = rn->info; pi; pi = pi->next) + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && (pi->type == ZEBRA_ROUTE_BGP @@ -1692,7 +1692,7 @@ int bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, for (rn = bgp_table_top(bgp->rib[afi][SAFI_UNICAST]); rn; rn = bgp_route_next(rn)) { - for (pi = rn->info; pi; pi = pi->next) { + for (pi = bgp_node_get_bgp_path_info(rn); pi; pi = pi->next) { if (pi->sub_type == BGP_ROUTE_REDISTRIBUTE && pi->type == type && pi->instance == red->instance) { diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 6978dd145d..4fffe94a83 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -382,9 +382,10 @@ void del_vnc_route(struct rfapi_descriptor *rfd, vnc_zlog_debug_verbose( "%s: peer=%p, prefix=%s, prd=%s afi=%d, safi=%d bn=%p, bn->info=%p", __func__, peer, buf, prefix_rd2str(prd, buf2, sizeof(buf2)), - afi, safi, bn, (bn ? bn->info : NULL)); + afi, safi, bn, (bn ? bgp_node_get_bgp_path_info(bn) : NULL)); - for (bpi = (bn ? bn->info : NULL); bpi; bpi = bpi->next) { + for (bpi = (bn ? bgp_node_get_bgp_path_info(bn) : NULL); bpi; + bpi = bpi->next) { vnc_zlog_debug_verbose( "%s: trying bpi=%p, bpi->peer=%p, bpi->type=%d, bpi->sub_type=%d, bpi->extra->vnc.export.rfapi_handle=%p, local_pref=%u", @@ -945,7 +946,7 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ * ecommunity: POINTS TO interned/refcounted dynamic 2-part AS attr * aspath: POINTS TO interned/refcounted hashed block */ - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; bpi = bpi->next) { /* probably only need to check * bpi->extra->vnc.export.rfapi_handle */ if (bpi->peer == rfd->peer && bpi->type == type @@ -1081,7 +1082,7 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ /* debug */ if (VNC_DEBUG(VERBOSE)) { - vnc_zlog_debug_verbose("%s: printing BI", __func__); + vnc_zlog_debug_verbose("%s: printing BPI", __func__); rfapiPrintBi(NULL, new); } @@ -3701,10 +3702,12 @@ static void rfapi_print_exported(struct bgp *bgp) fprintf(stderr, "%s: vpn rdn=%p\n", __func__, rdn); for (rn = bgp_table_top(rdn->info); rn; rn = bgp_route_next(rn)) { - if (!rn->info) + bpi = bgp_node_get_bgp_path_info(rn); + + if (!bpi) continue; fprintf(stderr, "%s: rn=%p\n", __func__, rn); - for (bpi = rn->info; bpi; bpi = bpi->next) { + for (; bpi; bpi = bpi->next) { rfapiPrintBi((void *)2, bpi); /* 2 => stderr */ } } @@ -3716,10 +3719,11 @@ static void rfapi_print_exported(struct bgp *bgp) fprintf(stderr, "%s: encap rdn=%p\n", __func__, rdn); for (rn = bgp_table_top(rdn->info); rn; rn = bgp_route_next(rn)) { - if (!rn->info) + bpi = bgp_node_get_bgp_path_info(rn); + if (!bpi) continue; fprintf(stderr, "%s: rn=%p\n", __func__, rn); - for (bpi = rn->info; bpi; bpi = bpi->next) { + for (; bpi; bpi = bpi->next) { rfapiPrintBi((void *)2, bpi); /* 2 => stderr */ } } diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index 6f5af5182a..aa20a9d36c 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -4244,13 +4244,15 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp, for (rn1 = bgp_table_top(bgp->rib[afi][safi]); rn1; rn1 = bgp_route_next(rn1)) { - if (rn1->info) { + if (bgp_node_has_bgp_path_info_data(rn1)) { + for (rn2 = bgp_table_top(rn1->info); rn2; rn2 = bgp_route_next(rn2)) { struct bgp_path_info *bpi; - for (bpi = rn2->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(rn2); + bpi; bpi = bpi->next) { uint32_t label = 0; if (CHECK_FLAG(bpi->flags, diff --git a/bgpd/rfapi/rfapi_vty.c b/bgpd/rfapi/rfapi_vty.c index 1844839f25..04ddff934d 100644 --- a/bgpd/rfapi/rfapi_vty.c +++ b/bgpd/rfapi/rfapi_vty.c @@ -1570,7 +1570,7 @@ void rfapiPrintAdvertisedInfo(struct vty *vty, struct rfapi_descriptor *rfd, vty_out(vty, " bn=%p%s", bn, HVTYNL); - for (bpi = bn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; bpi = bpi->next) { if (bpi->peer == rfd->peer && bpi->type == type && bpi->sub_type == BGP_ROUTE_RFP && bpi->extra && bpi->extra->vnc.export.rfapi_handle == (void *)rfd) { diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 212d394fdc..9f55634aac 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -256,7 +256,7 @@ void vnc_direct_bgp_add_route_ce(struct bgp *bgp, struct agg_node *rn, */ urn = bgp_afi_node_get(bgp->rib[afi][SAFI_UNICAST], afi, SAFI_UNICAST, prefix, NULL); - for (ubpi = urn->info; ubpi; ubpi = ubpi->next) { + for (ubpi = bgp_node_get_bgp_path_info(urn); ubpi; ubpi = ubpi->next) { struct prefix unicast_nexthop; if (CHECK_FLAG(ubpi->flags, BGP_PATH_REMOVED)) @@ -483,7 +483,8 @@ static void vnc_direct_bgp_vpn_disable_ce(struct bgp *bgp, afi_t afi) struct bgp_path_info *ri; struct bgp_path_info *next; - for (ri = rn->info, next = NULL; ri; ri = next) { + for (ri = bgp_node_get_bgp_path_info(rn), next = NULL; + ri; ri = next) { next = ri->next; @@ -1856,7 +1857,7 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi) /* * skip prefix list check if no routes here */ - if (!rn->info) + if (!bgp_node_has_bgp_path_info_data(rn)) continue; { @@ -1883,7 +1884,8 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi) } } - for (ri = rn->info; ri; ri = ri->next) { + for (ri = bgp_node_get_bgp_path_info(rn); + ri; ri = ri->next) { vnc_zlog_debug_verbose("%s: ri->sub_type: %d", __func__, ri->sub_type); @@ -2003,7 +2005,7 @@ void vnc_direct_bgp_rh_vpn_disable(struct bgp *bgp, afi_t afi) struct bgp_path_info *ri; struct bgp_path_info *next; - for (ri = rn->info, next = NULL; ri; ri = next) { + for (ri = bgp_node_get_bgp_path_info(rn), next = NULL; ri; ri = next) { next = ri->next; diff --git a/bgpd/rfapi/vnc_import_bgp.c b/bgpd/rfapi/vnc_import_bgp.c index 2f634f6f40..e54e3b6151 100644 --- a/bgpd/rfapi/vnc_import_bgp.c +++ b/bgpd/rfapi/vnc_import_bgp.c @@ -545,8 +545,8 @@ static void vnc_import_bgp_add_route_mode_resolve_nve_one_rd( return; } - /* Iterate over bgp_path_info items at this node */ - for (bpi = bn->info; bpi; bpi = bpi->next) { + /* Iterate over bgp_info items at this node */ + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; bpi = bpi->next) { vnc_import_bgp_add_route_mode_resolve_nve_one_bi( bgp, afi, bpi, /* VPN bpi */ @@ -1305,8 +1305,8 @@ static void vnc_import_bgp_del_route_mode_resolve_nve_one_rd( return; } - /* Iterate over bgp_path_info items at this node */ - for (bpi = bn->info; bpi; bpi = bpi->next) { + /* Iterate over bgp_info items at this node */ + for (bpi = bgp_node_get_bgp_path_info(bn); bpi; bpi = bpi->next) { vnc_import_bgp_del_route_mode_resolve_nve_one_bi( bgp, afi, bpi, /* VPN bpi */ @@ -2780,7 +2780,8 @@ void vnc_import_bgp_redist_enable(struct bgp *bgp, afi_t afi) struct bgp_path_info *bpi; - for (bpi = rn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(rn); bpi; + bpi = bpi->next) { if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) continue; @@ -2820,7 +2821,8 @@ void vnc_import_bgp_exterior_redist_enable(struct bgp *bgp, afi_t afi) struct bgp_path_info *bpi; - for (bpi = rn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(rn); bpi; + bpi = bpi->next) { if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) continue; @@ -2865,7 +2867,8 @@ void vnc_import_bgp_exterior_redist_enable_it( struct bgp_path_info *bpi; - for (bpi = rn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(rn); bpi; + bpi = bpi->next) { if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) continue; @@ -2902,14 +2905,16 @@ void vnc_import_bgp_redist_disable(struct bgp *bgp, afi_t afi) for (rn1 = bgp_table_top(bgp->rib[afi][SAFI_MPLS_VPN]); rn1; rn1 = bgp_route_next(rn1)) { - if (rn1->info) { + if (bgp_node_has_bgp_path_info_data(rn1)) { + for (rn2 = bgp_table_top(rn1->info); rn2; rn2 = bgp_route_next(rn2)) { struct bgp_path_info *bpi; struct bgp_path_info *nextbpi; - for (bpi = rn2->info; bpi; bpi = nextbpi) { + for (bpi = bgp_node_get_bgp_path_info(rn2); bpi; + bpi = nextbpi) { nextbpi = bpi->next; @@ -2999,7 +3004,8 @@ void vnc_import_bgp_exterior_redist_disable(struct bgp *bgp, afi_t afi) struct bgp_path_info *bpi; - for (bpi = rn->info; bpi; bpi = bpi->next) { + for (bpi = bgp_node_get_bgp_path_info(rn); bpi; + bpi = bpi->next) { if (CHECK_FLAG(bpi->flags, BGP_PATH_REMOVED)) continue; diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c index a43cf1f6a9..77bec4842a 100644 --- a/bgpd/rfapi/vnc_zebra.c +++ b/bgpd/rfapi/vnc_zebra.c @@ -320,7 +320,8 @@ static void vnc_redistribute_withdraw(struct bgp *bgp, afi_t afi, uint8_t type) struct bgp_path_info *ri; - for (ri = rn->info; ri; ri = ri->next) { + for (ri = bgp_node_get_bgp_path_info(rn); ri; + ri = ri->next) { if (ri->type == type) { /* has matching redist type */ break; From 67009e2200b70563b5b2eb1ca5752d7fafe6902c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Tue, 25 Sep 2018 20:37:16 -0400 Subject: [PATCH 04/13] bgpd: Abstract bgp_table retrieving/setting from info pointer Convert the set/get of bgp_table's from the info pointer. Signed-off-by: Donald Sharp --- bgpd/bgp_evpn.c | 10 +-- bgpd/bgp_evpn_vty.c | 13 ++-- bgpd/bgp_mplsvpn.c | 4 +- bgpd/bgp_route.c | 136 ++++++++++++++++++++---------------- bgpd/bgp_table.h | 12 ++++ bgpd/bgp_updgrp_adv.c | 9 ++- bgpd/bgp_vpn.c | 3 +- bgpd/bgp_vty.c | 4 +- bgpd/bgpd.c | 9 +-- bgpd/rfapi/rfapi.c | 38 +++++----- bgpd/rfapi/rfapi_import.c | 2 +- bgpd/rfapi/vnc_export_bgp.c | 2 +- bgpd/rfapi/vnc_import_bgp.c | 9 +-- bgpd/rfapi/vnc_zebra.c | 2 +- 14 files changed, 142 insertions(+), 111 deletions(-) diff --git a/bgpd/bgp_evpn.c b/bgpd/bgp_evpn.c index 729e61a56f..7d11cb71d1 100644 --- a/bgpd/bgp_evpn.c +++ b/bgpd/bgp_evpn.c @@ -2134,7 +2134,7 @@ static int delete_global_type2_routes(struct bgp *bgp, struct bgpevpn *vpn) rdrn = bgp_node_lookup(bgp->rib[afi][safi], (struct prefix *)&vpn->prd); if (rdrn && bgp_node_has_bgp_path_info_data(rdrn)) { - table = (struct bgp_table *)rdrn->info; + table = bgp_node_get_bgp_table_info(rdrn); for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { struct prefix_evpn *evp = (struct prefix_evpn *)&rn->p; @@ -2908,7 +2908,7 @@ static int install_uninstall_routes_for_es(struct bgp *bgp, */ for (rd_rn = bgp_table_top(bgp->rib[afi][safi]); rd_rn; rd_rn = bgp_route_next(rd_rn)) { - table = (struct bgp_table *)(rd_rn->info); + table = bgp_node_get_bgp_table_info(rd_rn); if (!table) continue; @@ -2981,7 +2981,7 @@ static int install_uninstall_routes_for_vrf(struct bgp *bgp_vrf, int install) */ for (rd_rn = bgp_table_top(bgp_def->rib[afi][safi]); rd_rn; rd_rn = bgp_route_next(rd_rn)) { - table = (struct bgp_table *)(rd_rn->info); + table = bgp_node_get_bgp_table_info(rd_rn); if (!table) continue; @@ -3065,7 +3065,7 @@ static int install_uninstall_routes_for_vni(struct bgp *bgp, /* EVPN routes are a 2-level table. */ for (rd_rn = bgp_table_top(bgp->rib[afi][safi]); rd_rn; rd_rn = bgp_route_next(rd_rn)) { - table = (struct bgp_table *)(rd_rn->info); + table = bgp_node_get_bgp_table_info(rd_rn); if (!table) continue; @@ -5230,7 +5230,7 @@ int bgp_filter_evpn_routes_upon_martian_nh_change(struct bgp *bgp) /* EVPN routes are a 2-level table. */ for (rd_rn = bgp_table_top(bgp->rib[afi][safi]); rd_rn; rd_rn = bgp_route_next(rd_rn)) { - table = (struct bgp_table *)(rd_rn->info); + table = bgp_node_get_bgp_table_info(rd_rn); if (!table) continue; diff --git a/bgpd/bgp_evpn_vty.c b/bgpd/bgp_evpn_vty.c index d26a2e98e6..f37c4f651a 100644 --- a/bgpd/bgp_evpn_vty.c +++ b/bgpd/bgp_evpn_vty.c @@ -1041,7 +1041,8 @@ static int bgp_show_ethernet_vpn(struct vty *vty, struct prefix_rd *prd, if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0) continue; - if ((table = rn->info) == NULL) + table = bgp_node_get_bgp_table_info(rn); + if (!table) continue; rd_header = 1; @@ -2039,7 +2040,7 @@ static void evpn_show_route_vni_multicast(struct vty *vty, struct bgp *bgp, /* See if route exists. */ build_evpn_type3_prefix(&p, orig_ip); rn = bgp_node_lookup(vpn->route_table, (struct prefix *)&p); - if (!rn || !rn->info) { + if (!rn || !bgp_node_has_bgp_path_info_data(rn)) { if (!json) vty_out(vty, "%% Network not in table\n"); return; @@ -2109,7 +2110,7 @@ static void evpn_show_route_vni_macip(struct vty *vty, struct bgp *bgp, /* See if route exists. Look for both non-sticky and sticky. */ build_evpn_type2_prefix(&p, mac, ip); rn = bgp_node_lookup(vpn->route_table, (struct prefix *)&p); - if (!rn || !rn->info) { + if (!rn || !bgp_node_has_bgp_path_info_data(rn)) { if (!json) vty_out(vty, "%% Network not in table\n"); return; @@ -2213,7 +2214,7 @@ static void evpn_show_route_rd_macip(struct vty *vty, struct bgp *bgp, build_evpn_type2_prefix(&p, mac, ip); rn = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi, (struct prefix *)&p, prd); - if (!rn || !rn->info) { + if (!rn || !bgp_node_has_bgp_path_info_data(rn)) { if (!json) vty_out(vty, "%% Network not in table\n"); return; @@ -2284,7 +2285,7 @@ static void evpn_show_route_rd(struct vty *vty, struct bgp *bgp, if (!rd_rn) return; - table = (struct bgp_table *)rd_rn->info; + table = bgp_node_get_bgp_table_info(rd_rn); if (table == NULL) return; @@ -2408,7 +2409,7 @@ static void evpn_show_all_routes(struct vty *vty, struct bgp *bgp, int type, int add_rd_to_json = 0; uint64_t tbl_ver; - table = (struct bgp_table *)rd_rn->info; + table = bgp_node_get_bgp_table_info(rd_rn); if (table == NULL) continue; diff --git a/bgpd/bgp_mplsvpn.c b/bgpd/bgp_mplsvpn.c index 24ac4ca078..c763d9fc72 100644 --- a/bgpd/bgp_mplsvpn.c +++ b/bgpd/bgp_mplsvpn.c @@ -961,7 +961,7 @@ void vpn_leak_from_vrf_withdraw_all(struct bgp *bgp_vpn, /* to */ struct bgp_path_info *bpi; /* This is the per-RD table of prefixes */ - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); if (!table) continue; @@ -1381,7 +1381,7 @@ void vpn_leak_to_vrf_update_all(struct bgp *bgp_vrf, /* to */ memcpy(prd.val, prn->p.u.val, 8); /* This is the per-RD table of prefixes */ - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); if (!table) continue; diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index b59a59e6a7..8cb65262cd 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -120,11 +120,12 @@ struct bgp_node *bgp_afi_node_get(struct bgp_table *table, afi_t afi, || (safi == SAFI_EVPN)) { prn = bgp_node_get(table, (struct prefix *)prd); - if (prn->info == NULL) - prn->info = bgp_table_init(table->bgp, afi, safi); + if (!bgp_node_has_bgp_path_info_data(prn)) + bgp_node_set_bgp_table_info( + prn, bgp_table_init(table->bgp, afi, safi)); else bgp_unlock_node(prn); - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); } rn = bgp_node_get(table, p); @@ -157,7 +158,7 @@ struct bgp_node *bgp_afi_node_lookup(struct bgp_table *table, afi_t afi, return NULL; } - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); } rn = bgp_node_lookup(table, p); @@ -2743,8 +2744,8 @@ static void bgp_rib_withdraw(struct bgp_node *rn, struct bgp_path_info *pi, prn = bgp_node_get(peer->bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); + if (bgp_node_has_bgp_path_info_data(prn)) { + table = bgp_node_get_bgp_table_info(prn); vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( peer->bgp, prd, table, &rn->p, pi); @@ -3174,8 +3175,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); + if (bgp_node_has_bgp_path_info_data(prn)) { + table = bgp_node_get_bgp_table_info(prn); vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, pi); @@ -3324,8 +3325,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); + if (bgp_node_has_bgp_path_info_data(prn)) { + table = bgp_node_get_bgp_table_info(prn); vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, pi); @@ -3461,8 +3462,8 @@ int bgp_update(struct peer *peer, struct prefix *p, uint32_t addpath_id, struct bgp_table *table = NULL; prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); + if (bgp_node_has_bgp_path_info_data(prn)) { + table = bgp_node_get_bgp_table_info(prn); vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, new); @@ -3802,9 +3803,11 @@ void bgp_soft_reconfig_in(struct peer *peer, afi_t afi, safi_t safi) bgp_soft_reconfig_table(peer, afi, safi, NULL, NULL); else for (rn = bgp_table_top(peer->bgp->rib[afi][safi]); rn; - rn = bgp_route_next(rn)) - if ((table = rn->info) != NULL) { + rn = bgp_route_next(rn)) { + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { struct prefix_rd prd; + prd.family = AF_UNSPEC; prd.prefixlen = 64; memcpy(&prd.val, rn->p.u.val, 8); @@ -3812,6 +3815,7 @@ void bgp_soft_reconfig_in(struct peer *peer, afi_t afi, safi_t safi) bgp_soft_reconfig_table(peer, afi, safi, table, &prd); } + } } @@ -4031,9 +4035,13 @@ void bgp_clear_route(struct peer *peer, afi_t afi, safi_t safi) bgp_clear_route_table(peer, afi, safi, NULL); else for (rn = bgp_table_top(peer->bgp->rib[afi][safi]); rn; - rn = bgp_route_next(rn)) - if ((table = rn->info) != NULL) - bgp_clear_route_table(peer, afi, safi, table); + rn = bgp_route_next(rn)) { + table = bgp_node_get_bgp_table_info(rn); + if (!table) + continue; + + bgp_clear_route_table(peer, afi, safi, table); + } /* unlock if no nodes got added to the clear-node-queue. */ if (!peer->clear_node_queue->thread) @@ -4093,7 +4101,8 @@ void bgp_clear_stale_route(struct peer *peer, afi_t afi, safi_t safi) struct bgp_node *rm; /* look for neighbor in tables */ - if ((table = rn->info) == NULL) + table = bgp_node_get_bgp_table_info(rn); + if (!table) continue; for (rm = bgp_table_top(table); rm; @@ -4154,6 +4163,7 @@ void bgp_cleanup_routes(struct bgp *bgp) { afi_t afi; struct bgp_node *rn; + struct bgp_table *table; for (afi = AFI_IP; afi < AFI_MAX; ++afi) { if (afi == AFI_L2VPN) @@ -4168,26 +4178,22 @@ void bgp_cleanup_routes(struct bgp *bgp) safi = SAFI_MPLS_VPN; for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) { - if (rn->info) { - bgp_cleanup_table(bgp, - (struct bgp_table *)(rn->info), - safi); - bgp_table_finish((struct bgp_table **)&( - rn->info)); - rn->info = NULL; + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { + bgp_cleanup_table(bgp, table, safi); + bgp_table_finish(&table); + bgp_node_set_bgp_table_info(rn, NULL); bgp_unlock_node(rn); } } safi = SAFI_ENCAP; for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) { - if (rn->info) { - bgp_cleanup_table(bgp, - (struct bgp_table *)(rn->info), - safi); - bgp_table_finish((struct bgp_table **)&( - rn->info)); - rn->info = NULL; + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { + bgp_cleanup_table(bgp, table, safi); + bgp_table_finish(&table); + bgp_node_set_bgp_table_info(rn, NULL); bgp_unlock_node(rn); } } @@ -4195,12 +4201,11 @@ void bgp_cleanup_routes(struct bgp *bgp) } for (rn = bgp_table_top(bgp->rib[AFI_L2VPN][SAFI_EVPN]); rn; rn = bgp_route_next(rn)) { - if (rn->info) { - bgp_cleanup_table(bgp, - (struct bgp_table *)(rn->info), - SAFI_EVPN); - bgp_table_finish((struct bgp_table **)&(rn->info)); - rn->info = NULL; + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { + bgp_cleanup_table(bgp, table, SAFI_EVPN); + bgp_table_finish(&table); + bgp_node_set_bgp_table_info(rn, NULL); bgp_unlock_node(rn); } } @@ -5007,12 +5012,12 @@ void bgp_static_add(struct bgp *bgp) FOREACH_AFI_SAFI (afi, safi) for (rn = bgp_table_top(bgp->route[afi][safi]); rn; rn = bgp_route_next(rn)) { - if (rn->info == NULL) + if (!bgp_node_has_bgp_path_info_data(rn)) continue; if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN)) { - table = rn->info; + table = bgp_node_get_bgp_table_info(rn); for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { @@ -5044,12 +5049,12 @@ void bgp_static_delete(struct bgp *bgp) FOREACH_AFI_SAFI (afi, safi) for (rn = bgp_table_top(bgp->route[afi][safi]); rn; rn = bgp_route_next(rn)) { - if (rn->info == NULL) + if (!bgp_node_has_bgp_path_info_data(rn)) continue; if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN)) { - table = rn->info; + table = bgp_node_get_bgp_table_info(rn); for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { @@ -5086,12 +5091,12 @@ void bgp_static_redo_import_check(struct bgp *bgp) FOREACH_AFI_SAFI (afi, safi) { for (rn = bgp_table_top(bgp->route[afi][safi]); rn; rn = bgp_route_next(rn)) { - if (rn->info == NULL) + if (!bgp_node_has_bgp_path_info_data(rn)) continue; if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP) || (safi == SAFI_EVPN)) { - table = rn->info; + table = bgp_node_get_bgp_table_info(rn); for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { @@ -5227,15 +5232,16 @@ int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty, } } prn = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd); - if (prn->info == NULL) - prn->info = bgp_table_init(bgp, afi, safi); + if (!bgp_node_has_bgp_path_info_data(prn)) + bgp_node_set_bgp_table_info(prn, + bgp_table_init(bgp, afi, safi)); else bgp_unlock_node(prn); - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); rn = bgp_node_get(table, &p); - if (rn->info) { + if (bgp_node_has_bgp_path_info_data(rn)) { vty_out(vty, "%% Same network configuration exists\n"); bgp_unlock_node(rn); } else { @@ -5325,11 +5331,12 @@ int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *vty, } prn = bgp_node_get(bgp->route[afi][safi], (struct prefix *)&prd); - if (prn->info == NULL) - prn->info = bgp_table_init(bgp, afi, safi); + if (!bgp_node_has_bgp_path_info_data(prn)) + bgp_node_set_bgp_table_info(prn, + bgp_table_init(bgp, afi, safi)); else bgp_unlock_node(prn); - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); rn = bgp_node_lookup(table, &p); @@ -6020,7 +6027,7 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, /* Old configuration check. */ rn = bgp_node_get(bgp->aggregate[afi][safi], &p); - if (rn->info) { + if (bgp_node_has_bgp_path_info_data(rn)) { vty_out(vty, "There is already same aggregate network.\n"); /* try to remove the old entry */ ret = bgp_aggregate_unset(vty, prefix_str, afi, safi); @@ -8722,6 +8729,7 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, unsigned long output_cum = 0; unsigned long total_cum = 0; unsigned long json_header_depth = 0; + struct bgp_table *itable; bool show_msg; show_msg = (!use_json && type == bgp_show_type_normal); @@ -8730,16 +8738,17 @@ int bgp_show_table_rd(struct vty *vty, struct bgp *bgp, safi_t safi, next = bgp_route_next(rn); if (prd_match && memcmp(rn->p.u.val, prd_match->val, 8) != 0) continue; - if (rn->info != NULL) { + + itable = bgp_node_get_bgp_table_info(rn); + if (itable != NULL) { struct prefix_rd prd; char rd[RD_ADDRSTRLEN]; memcpy(&prd, &(rn->p), sizeof(struct prefix_rd)); prefix_rd2str(&prd, rd, sizeof(rd)); - bgp_show_table(vty, bgp, safi, rn->info, type, - output_arg, use_json, rd, next == NULL, - &output_cum, &total_cum, - &json_header_depth); + bgp_show_table(vty, bgp, safi, itable, type, output_arg, + use_json, rd, next == NULL, &output_cum, + &total_cum, &json_header_depth); if (next == NULL) show_msg = false; } @@ -9068,8 +9077,8 @@ static int bgp_show_route_in_table(struct vty *vty, struct bgp *bgp, for (rn = bgp_table_top(rib); rn; rn = bgp_route_next(rn)) { if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0) continue; - - if ((table = rn->info) == NULL) + table = bgp_node_get_bgp_table_info(rn); + if (!table) continue; header = 1; @@ -11428,7 +11437,8 @@ static int bgp_clear_damp_route(struct vty *vty, const char *view_name, rn = bgp_route_next(rn)) { if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0) continue; - if ((table = rn->info) == NULL) + table = bgp_node_get_bgp_table_info(rn); + if (!table) continue; if ((rm = bgp_node_match(table, &match)) == NULL) continue; @@ -11588,7 +11598,8 @@ static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp, /* Network configuration. */ for (prn = bgp_table_top(bgp->route[afi][safi]); prn; prn = bgp_route_next(prn)) { - if ((table = prn->info) == NULL) + table = bgp_node_get_bgp_table_info(prn); + if (!table) continue; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { @@ -11638,7 +11649,8 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp, /* Network configuration. */ for (prn = bgp_table_top(bgp->route[afi][safi]); prn; prn = bgp_route_next(prn)) { - if ((table = prn->info) == NULL) + table = bgp_node_get_bgp_table_info(prn); + if (!table) continue; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 87fbc39f43..ee21e74a15 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -388,6 +388,18 @@ static inline void bgp_node_set_bgp_path_info(struct bgp_node *node, node->info = bi; } +static inline struct bgp_table * +bgp_node_get_bgp_table_info(struct bgp_node *node) +{ + return node->info; +} + +static inline void bgp_node_set_bgp_table_info(struct bgp_node *node, + struct bgp_table *table) +{ + node->info = table; +} + static inline bool bgp_node_has_bgp_path_info_data(struct bgp_node *node) { return !!node->info; diff --git a/bgpd/bgp_updgrp_adv.c b/bgpd/bgp_updgrp_adv.c index ff7d18761c..a6542f48a0 100644 --- a/bgpd/bgp_updgrp_adv.c +++ b/bgpd/bgp_updgrp_adv.c @@ -690,9 +690,12 @@ void subgroup_announce_route(struct update_subgroup *subgrp) subgroup_announce_table(subgrp, NULL); else for (rn = bgp_table_top(update_subgroup_rib(subgrp)); rn; - rn = bgp_route_next(rn)) - if ((table = (rn->info)) != NULL) - subgroup_announce_table(subgrp, table); + rn = bgp_route_next(rn)) { + table = bgp_node_get_bgp_table_info(rn); + if (!table) + continue; + subgroup_announce_table(subgrp, table); + } } void subgroup_default_originate(struct update_subgroup *subgrp, int withdraw) diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index 99bcefe70c..21f289fb9f 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -79,7 +79,8 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0) continue; - if ((table = rn->info) != NULL) { + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { if (use_json) json_array = json_object_new_array(); else diff --git a/bgpd/bgp_vty.c b/bgpd/bgp_vty.c index 4dd148bb41..da28fdb193 100644 --- a/bgpd/bgp_vty.c +++ b/bgpd/bgp_vty.c @@ -7209,7 +7209,9 @@ static int bgp_clear_prefix(struct vty *vty, const char *view_name, if (prd && memcmp(rn->p.u.val, prd->val, 8) != 0) continue; - if ((table = rn->info) != NULL) { + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { + if ((rm = bgp_node_match(table, &match)) != NULL) { if (rm->p.prefixlen diff --git a/bgpd/bgpd.c b/bgpd/bgpd.c index a078c4f587..e2229afa05 100644 --- a/bgpd/bgpd.c +++ b/bgpd/bgpd.c @@ -1432,16 +1432,17 @@ static void bgp_recalculate_afi_safi_bestpaths(struct bgp *bgp, afi_t afi, safi_t safi) { struct bgp_node *rn, *nrn; + struct bgp_table *table; for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) { - if (rn->info != NULL) { + table = bgp_node_get_bgp_table_info(rn); + if (table != NULL) { /* Special handling for 2-level routing * tables. */ if (safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP || safi == SAFI_EVPN) { - for (nrn = bgp_table_top( - (struct bgp_table *)(rn->info)); + for (nrn = bgp_table_top(table); nrn; nrn = bgp_route_next(nrn)) bgp_process(bgp, nrn, afi, safi); } else @@ -3319,7 +3320,7 @@ void bgp_free(struct bgp *bgp) || safi == SAFI_EVPN) { for (rn = bgp_table_top(bgp->rib[afi][safi]); rn; rn = bgp_route_next(rn)) { - table = (struct bgp_table *)rn->info; + table = bgp_node_get_bgp_table_info(rn); bgp_table_finish(&table); } } diff --git a/bgpd/rfapi/rfapi.c b/bgpd/rfapi/rfapi.c index 4fffe94a83..a41473fa4f 100644 --- a/bgpd/rfapi/rfapi.c +++ b/bgpd/rfapi/rfapi.c @@ -472,12 +472,10 @@ void del_vnc_route(struct rfapi_descriptor *rfd, prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); - + table = bgp_node_get_bgp_table_info(prn); + if (table) vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, bpi); - } bgp_unlock_node(prn); } @@ -1018,12 +1016,10 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); - + table = bgp_node_get_bgp_table_info(prn); + if (table) vnc_import_bgp_del_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, bpi); - } bgp_unlock_node(prn); } @@ -1043,12 +1039,10 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); - + table = bgp_node_get_bgp_table_info(prn); + if (table) vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, bpi); - } bgp_unlock_node(prn); } @@ -1094,12 +1088,10 @@ void add_vnc_route(struct rfapi_descriptor *rfd, /* cookie, VPN UN addr, peer */ struct bgp_table *table = NULL; prn = bgp_node_get(bgp->rib[afi][safi], (struct prefix *)prd); - if (prn->info) { - table = (struct bgp_table *)(prn->info); - + table = bgp_node_get_bgp_table_info(prn); + if (table) vnc_import_bgp_add_vnc_host_route_mode_resolve_nve( bgp, prd, table, p, new); - } bgp_unlock_node(prn); encode_label(label_val, &bn->local_label); } @@ -3697,10 +3689,13 @@ static void rfapi_print_exported(struct bgp *bgp) for (rdn = bgp_table_top(bgp->rib[AFI_IP][SAFI_MPLS_VPN]); rdn; rdn = bgp_route_next(rdn)) { - if (!rdn->info) + struct bgp_table *table; + + table = bgp_node_get_bgp_table_info(rdn); + if (!table) continue; fprintf(stderr, "%s: vpn rdn=%p\n", __func__, rdn); - for (rn = bgp_table_top(rdn->info); rn; + for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { bpi = bgp_node_get_bgp_path_info(rn); @@ -3714,10 +3709,13 @@ static void rfapi_print_exported(struct bgp *bgp) } for (rdn = bgp_table_top(bgp->rib[AFI_IP][SAFI_ENCAP]); rdn; rdn = bgp_route_next(rdn)) { - if (!rdn->info) + struct bgp_table *table; + + table = bgp_node_get_bgp_table_info(rdn); + if (!table) continue; fprintf(stderr, "%s: encap rdn=%p\n", __func__, rdn); - for (rn = bgp_table_top(rdn->info); rn; + for (rn = bgp_table_top(table)); rn; rn = bgp_route_next(rn)) { bpi = bgp_node_get_bgp_path_info(rn); if (!bpi) diff --git a/bgpd/rfapi/rfapi_import.c b/bgpd/rfapi/rfapi_import.c index aa20a9d36c..c49b6e354d 100644 --- a/bgpd/rfapi/rfapi_import.c +++ b/bgpd/rfapi/rfapi_import.c @@ -4246,7 +4246,7 @@ static void rfapiBgpTableFilteredImport(struct bgp *bgp, if (bgp_node_has_bgp_path_info_data(rn1)) { - for (rn2 = bgp_table_top(rn1->info); rn2; + for (rn2 = bgp_table_top(bgp_node_get_bgp_table_info(rn1)); rn2; rn2 = bgp_route_next(rn2)) { struct bgp_path_info *bpi; diff --git a/bgpd/rfapi/vnc_export_bgp.c b/bgpd/rfapi/vnc_export_bgp.c index 9f55634aac..3d8d5bccb0 100644 --- a/bgpd/rfapi/vnc_export_bgp.c +++ b/bgpd/rfapi/vnc_export_bgp.c @@ -1847,7 +1847,7 @@ void vnc_direct_bgp_rh_vpn_enable(struct bgp *bgp, afi_t afi) memcpy(prd.val, prn->p.u.val, 8); /* This is the per-RD table of prefixes */ - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); if (!table) continue; diff --git a/bgpd/rfapi/vnc_import_bgp.c b/bgpd/rfapi/vnc_import_bgp.c index e54e3b6151..eb2d0fd889 100644 --- a/bgpd/rfapi/vnc_import_bgp.c +++ b/bgpd/rfapi/vnc_import_bgp.c @@ -676,7 +676,7 @@ static void vnc_import_bgp_add_route_mode_resolve_nve( struct bgp_table *table; - table = (struct bgp_table *)(bnp->info); + table = bgp_node_get_bgp_table_info(bnp); if (!table) continue; @@ -1377,7 +1377,7 @@ vnc_import_bgp_del_route_mode_resolve_nve(struct bgp *bgp, afi_t afi, struct bgp_table *table; - table = (struct bgp_table *)(bnp->info); + table = bgp_node_get_bgp_table_info(bnp); if (!table) continue; @@ -2907,8 +2907,9 @@ void vnc_import_bgp_redist_disable(struct bgp *bgp, afi_t afi) if (bgp_node_has_bgp_path_info_data(rn1)) { - for (rn2 = bgp_table_top(rn1->info); rn2; - rn2 = bgp_route_next(rn2)) { + for (rn2 = bgp_table_top( + bgp_node_get_bgp_table_info(rn1)); + rn2; rn2 = bgp_route_next(rn2)) { struct bgp_path_info *bpi; struct bgp_path_info *nextbpi; diff --git a/bgpd/rfapi/vnc_zebra.c b/bgpd/rfapi/vnc_zebra.c index 77bec4842a..98f719969c 100644 --- a/bgpd/rfapi/vnc_zebra.c +++ b/bgpd/rfapi/vnc_zebra.c @@ -312,7 +312,7 @@ static void vnc_redistribute_withdraw(struct bgp *bgp, afi_t afi, uint8_t type) memcpy(prd.val, prn->p.u.val, 8); /* This is the per-RD table of prefixes */ - table = prn->info; + table = bgp_node_get_bgp_table_info(prn); if (!table) continue; From 96f10e1edc439b1aeae39c2cd722bdb995ad7647 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Wed, 26 Sep 2018 07:51:49 -0400 Subject: [PATCH 05/13] bgpd: Fix missed usage of bgp_static_get_node_info() Fix the missed usage of bgp_static_get_node_info and also cleanup the function around it that was using it to make it a bit more readable. Signed-off-by: Donald Sharp --- bgpd/bgp_routemap.c | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index f7c4175383..8093ffe49f 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -3226,11 +3226,13 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, /* For network route-map updates. */ for (bn = bgp_table_top(bgp->route[afi][safi]); bn; - bn = bgp_route_next(bn)) - if ((bgp_static = bn->info) != NULL) { + bn = bgp_route_next(bn)) { + bgp_static = bgp_static_get_node_info(bn); + if (bgp_static != NULL) { if (bgp_static->rmap.name && (strcmp(rmap_name, bgp_static->rmap.name) == 0)) { + bgp_static->rmap.map = map; if (route_update) @@ -3253,6 +3255,7 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, } } } + } } /* For redistribute route-map updates. */ From c983710570ea69a086588ac83265b6b30695a39c Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 12 Oct 2018 08:44:15 -0400 Subject: [PATCH 06/13] bgpd: Cleanup bgp_route_map_process_update to be readable Cleanup the bgp_route_map_process_update code to be a bit easier to read as that it approached the right side of the 80 column limit a whole bunch and became hard to read. Signed-off-by: Donald Sharp --- bgpd/bgp_routemap.c | 89 +++++++++++++++++++++------------------------ 1 file changed, 41 insertions(+), 48 deletions(-) diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 8093ffe49f..73b01b6b2d 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -3228,32 +3228,25 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, for (bn = bgp_table_top(bgp->route[afi][safi]); bn; bn = bgp_route_next(bn)) { bgp_static = bgp_static_get_node_info(bn); - if (bgp_static != NULL) { - if (bgp_static->rmap.name - && (strcmp(rmap_name, bgp_static->rmap.name) - == 0)) { + if (!bgp_static) + continue; - bgp_static->rmap.map = map; + if (!bgp_static->rmap.name + || (strcmp(rmap_name, bgp_static->rmap.name) != 0)) + continue; - if (route_update) - if (!bgp_static->backdoor) { - if (bgp_debug_zebra( - &bn->p)) - zlog_debug( - "Processing route_map %s update on " - "static route %s", - rmap_name, - inet_ntop( - bn->p.family, - &bn->p.u.prefix, - buf, - INET6_ADDRSTRLEN)); - bgp_static_update( - bgp, &bn->p, - bgp_static, afi, - safi); - } - } + bgp_static->rmap.map = map; + + if (route_update && !bgp_static->backdoor) { + if (bgp_debug_zebra(&bn->p)) + zlog_debug( + "Processing route_map %s update on static route %s", + rmap_name, + inet_ntop(bn->p.family, + &bn->p.u.prefix, buf, + INET6_ADDRSTRLEN)); + bgp_static_update(bgp, &bn->p, bgp_static, afi, + safi); } } } @@ -3269,38 +3262,38 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, continue; for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { - if (red->rmap.name - && (strcmp(rmap_name, red->rmap.name) - == 0)) { - red->rmap.map = map; + if (!red->rmap.name + || (strcmp(rmap_name, red->rmap.name) != 0)) + continue; - if (route_update) { - if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug( - "Processing route_map %s update on " - "redistributed routes", - rmap_name); + red->rmap.map = map; - bgp_redistribute_resend( - bgp, afi, i, + if (!route_update) + continue; + + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug( + "Processing route_map %s update on redistributed routes", + rmap_name); + + bgp_redistribute_resend(bgp, afi, i, red->instance); - } - } } } /* for type5 command route-maps */ FOREACH_AFI_SAFI (afi, safi) { - if (bgp->adv_cmd_rmap[afi][safi].name - && strcmp(rmap_name, bgp->adv_cmd_rmap[afi][safi].name) - == 0) { - if (BGP_DEBUG(zebra, ZEBRA)) - zlog_debug( - "Processing route_map %s update on advertise type5 route command", - rmap_name); - bgp_evpn_withdraw_type5_routes(bgp, afi, safi); - bgp_evpn_advertise_type5_routes(bgp, afi, safi); - } + if (!bgp->adv_cmd_rmap[afi][safi].name + || strcmp(rmap_name, bgp->adv_cmd_rmap[afi][safi].name) + != 0) + continue; + + if (BGP_DEBUG(zebra, ZEBRA)) + zlog_debug( + "Processing route_map %s update on advertise type5 route command", + rmap_name); + bgp_evpn_withdraw_type5_routes(bgp, afi, safi); + bgp_evpn_advertise_type5_routes(bgp, afi, safi); } } From c4936a1acec9b920d118dc5f6e58a175b1acfe17 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 13 Oct 2018 11:17:12 -0400 Subject: [PATCH 07/13] bgpd: Cleanup show_adj_route_vpn to be easier to read The show_adj_route_vpn function was incredibly hard to read because of the incredibly deep indentation. fix this up some. Signed-off-by: Donald Sharp --- bgpd/bgp_vpn.c | 281 +++++++++++++++++++++---------------------------- 1 file changed, 121 insertions(+), 160 deletions(-) diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index 21f289fb9f..b310057176 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -80,171 +80,132 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, continue; table = bgp_node_get_bgp_table_info(rn); - if (table != NULL) { - if (use_json) - json_array = json_object_new_array(); - else - json_array = NULL; + if (table == NULL) + continue; - rd_header = 1; + if (use_json) + json_array = json_object_new_array(); + else + json_array = NULL; - for (rm = bgp_table_top(table); rm; - rm = bgp_route_next(rm)) { - path = bgp_node_get_bgp_path_info(rm); - if (path != NULL) { - if (header) { - if (use_json) { - json_object_int_add( - json, - "bgpTableVersion", - 0); - json_object_string_add( - json, - "bgpLocalRouterId", - inet_ntoa( - bgp->router_id)); - json_object_object_add( - json, - "bgpStatusCodes", - json_scode); - json_object_object_add( - json, - "bgpOriginCodes", - json_ocode); - } else { - vty_out(vty, - "BGP table version is 0, local router ID is %s\n", - inet_ntoa( - bgp->router_id)); - vty_out(vty, - "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n"); - vty_out(vty, - "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n"); - vty_out(vty, V4_HEADER); - } - header = 0; - } + rd_header = 1; - if (rd_header) { - uint16_t type; - struct rd_as rd_as = {0}; - struct rd_ip rd_ip = {0}; -#if ENABLE_BGP_VNC - struct rd_vnc_eth rd_vnc_eth = { - 0}; -#endif - uint8_t *pnt; + for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { + path = bgp_node_get_bgp_path_info(rm); + if (path == NULL) + continue; - pnt = rn->p.u.val; - - /* Decode RD type. */ - type = decode_rd_type(pnt); - /* Decode RD value. */ - if (type == RD_TYPE_AS) - decode_rd_as(pnt + 2, - &rd_as); - else if (type == RD_TYPE_AS4) - decode_rd_as4(pnt + 2, - &rd_as); - else if (type == RD_TYPE_IP) - decode_rd_ip(pnt + 2, - &rd_ip); -#if ENABLE_BGP_VNC - else if (type - == RD_TYPE_VNC_ETH) - decode_rd_vnc_eth( - pnt, - &rd_vnc_eth); -#endif - - if (use_json) { - char buffer[BUFSIZ]; - if (type == RD_TYPE_AS - || type == RD_TYPE_AS4) - sprintf(buffer, - "%u:%d", - rd_as.as, - rd_as.val); - else if (type - == RD_TYPE_IP) - sprintf(buffer, - "%s:%d", - inet_ntoa( - rd_ip.ip), - rd_ip.val); - json_object_string_add( - json_routes, - "routeDistinguisher", - buffer); - } else { - vty_out(vty, - "Route Distinguisher: "); - - if (type == RD_TYPE_AS - || type == RD_TYPE_AS4) - vty_out(vty, - "%u:%d", - rd_as.as, - rd_as.val); - else if (type - == RD_TYPE_IP) - vty_out(vty, - "%s:%d", - inet_ntoa( - rd_ip.ip), - rd_ip.val); -#if ENABLE_BGP_VNC - else if ( - type - == RD_TYPE_VNC_ETH) - vty_out(vty, - "%u:%02x:%02x:%02x:%02x:%02x:%02x", - rd_vnc_eth - .local_nve_id, - rd_vnc_eth - .macaddr - .octet[0], - rd_vnc_eth - .macaddr - .octet[1], - rd_vnc_eth - .macaddr - .octet[2], - rd_vnc_eth - .macaddr - .octet[3], - rd_vnc_eth - .macaddr - .octet[4], - rd_vnc_eth - .macaddr - .octet[5]); -#endif - - vty_out(vty, "\n"); - } - rd_header = 0; - } - if (use_json) { - char buf_a[BUFSIZ]; - char buf_b[BUFSIZ]; - - sprintf(buf_a, "%s/%d", - inet_ntop(rm->p.family, - rm->p.u.val, - buf_b, - BUFSIZ), - rm->p.prefixlen); - json_object_object_add( - json_routes, buf_a, - json_array); - } else { - route_vty_out_tmp( - vty, &rm->p, path->attr, - SAFI_MPLS_VPN, use_json, - json_array); - } + if (header) { + if (use_json) { + json_object_int_add( + json, "bgpTableVersion", 0); + json_object_string_add( + json, "bgpLocalRouterId", + inet_ntoa(bgp->router_id)); + json_object_object_add(json, + "bgpStatusCodes", + json_scode); + json_object_object_add(json, + "bgpOriginCodes", + json_ocode); + } else { + vty_out(vty, + "BGP table version is 0, local router ID is %s\n", + inet_ntoa(bgp->router_id)); + vty_out(vty, + "Status codes: s suppressed, d damped, h history, * valid, > best, i - internal\n"); + vty_out(vty, + "Origin codes: i - IGP, e - EGP, ? - incomplete\n\n"); + vty_out(vty, V4_HEADER); } + header = 0; + } + + if (rd_header) { + uint16_t type; + struct rd_as rd_as = {0}; + struct rd_ip rd_ip = {0}; +#if ENABLE_BGP_VNC + struct rd_vnc_eth rd_vnc_eth = {0}; +#endif + uint8_t *pnt; + + pnt = rn->p.u.val; + + /* Decode RD type. */ + type = decode_rd_type(pnt); + /* Decode RD value. */ + if (type == RD_TYPE_AS) + decode_rd_as(pnt + 2, &rd_as); + else if (type == RD_TYPE_AS4) + decode_rd_as4(pnt + 2, &rd_as); + else if (type == RD_TYPE_IP) + decode_rd_ip(pnt + 2, &rd_ip); +#if ENABLE_BGP_VNC + else if (type == RD_TYPE_VNC_ETH) + decode_rd_vnc_eth(pnt, &rd_vnc_eth); +#endif + if (use_json) { + char buffer[BUFSIZ]; + if (type == RD_TYPE_AS + || type == RD_TYPE_AS4) + sprintf(buffer, "%u:%d", + rd_as.as, rd_as.val); + else if (type == RD_TYPE_IP) + sprintf(buffer, "%s:%d", + inet_ntoa(rd_ip.ip), + rd_ip.val); + json_object_string_add( + json_routes, + "routeDistinguisher", buffer); + } else { + vty_out(vty, "Route Distinguisher: "); + + if (type == RD_TYPE_AS + || type == RD_TYPE_AS4) + vty_out(vty, "%u:%d", rd_as.as, + rd_as.val); + else if (type == RD_TYPE_IP) + vty_out(vty, "%s:%d", + inet_ntoa(rd_ip.ip), + rd_ip.val); +#if ENABLE_BGP_VNC + else if (type == RD_TYPE_VNC_ETH) + vty_out(vty, + "%u:%02x:%02x:%02x:%02x:%02x:%02x", + rd_vnc_eth.local_nve_id, + rd_vnc_eth.macaddr + .octet[0], + rd_vnc_eth.macaddr + .octet[1], + rd_vnc_eth.macaddr + .octet[2], + rd_vnc_eth.macaddr + .octet[3], + rd_vnc_eth.macaddr + .octet[4], + rd_vnc_eth.macaddr + .octet[5]); +#endif + + vty_out(vty, "\n"); + } + rd_header = 0; + } + if (use_json) { + char buf_a[BUFSIZ]; + char buf_b[BUFSIZ]; + + sprintf(buf_a, "%s/%d", + inet_ntop(rm->p.family, rm->p.u.val, + buf_b, BUFSIZ), + rm->p.prefixlen); + json_object_object_add(json_routes, buf_a, + json_array); + } else { + route_vty_out_tmp(vty, &rm->p, path->attr, + SAFI_MPLS_VPN, use_json, + json_array); } } } From e13cc805783440571d8c80a45fad2db1fdcca787 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Sat, 13 Oct 2018 11:20:51 -0400 Subject: [PATCH 08/13] bgpd: Cleanup non-usage of prefix2str in bgp_vpn.c We were printing out a prefix by not using the prefix2str function. Let's use that. Signed-off-by: Donald Sharp --- bgpd/bgp_vpn.c | 10 +++------- 1 file changed, 3 insertions(+), 7 deletions(-) diff --git a/bgpd/bgp_vpn.c b/bgpd/bgp_vpn.c index b310057176..54ca980cad 100644 --- a/bgpd/bgp_vpn.c +++ b/bgpd/bgp_vpn.c @@ -193,14 +193,10 @@ int show_adj_route_vpn(struct vty *vty, struct peer *peer, rd_header = 0; } if (use_json) { - char buf_a[BUFSIZ]; - char buf_b[BUFSIZ]; + char buf[BUFSIZ]; - sprintf(buf_a, "%s/%d", - inet_ntop(rm->p.family, rm->p.u.val, - buf_b, BUFSIZ), - rm->p.prefixlen); - json_object_object_add(json_routes, buf_a, + prefix2str(&rm->p, buf, sizeof(buf)); + json_object_object_add(json_routes, buf, json_array); } else { route_vty_out_tmp(vty, &rm->p, path->attr, From 5b8d32bd583c180c15e9dba07feb24c68501176d Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Mon, 15 Oct 2018 08:33:58 -0400 Subject: [PATCH 09/13] bgpd: Cleanup bgp_nexthop_set|get function names The bgp_nexthop_set_node_info and bgp_nexthop_get_node_info function names were slightly backwards, rename to bgp_node_set and get Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 6 +++--- bgpd/bgp_nht.c | 20 ++++++++++---------- bgpd/bgp_table.h | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 9d76a41075..1877077602 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -81,7 +81,7 @@ static void bgp_nexthop_cache_reset(struct bgp_table *table) struct bgp_nexthop_cache *bnc; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) continue; @@ -92,7 +92,7 @@ static void bgp_nexthop_cache_reset(struct bgp_table *table) } bnc_free(bnc); - bgp_nexthop_set_node_info(rn, NULL); + bgp_node_set_bgp_nexthop_info(rn, NULL); bgp_unlock_node(rn); } } @@ -601,7 +601,7 @@ static void bgp_show_nexthops(struct vty *vty, struct bgp *bgp, int detail) for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn; rn = bgp_route_next(rn)) { - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) continue; diff --git a/bgpd/bgp_nht.c b/bgpd/bgp_nht.c index 0dce96f432..221bfea93d 100644 --- a/bgpd/bgp_nht.c +++ b/bgpd/bgp_nht.c @@ -95,7 +95,7 @@ static void bgp_unlink_nexthop_check(struct bgp_nexthop_cache *bnc) } unregister_zebra_rnh(bnc, CHECK_FLAG(bnc->flags, BGP_STATIC_ROUTE)); - bgp_nexthop_set_node_info(bnc->node, NULL); + bgp_node_set_bgp_nexthop_info(bnc->node, NULL); bgp_unlock_node(bnc->node); bnc->node = NULL; bnc_free(bnc); @@ -126,7 +126,7 @@ void bgp_unlink_nexthop_by_peer(struct peer *peer) rn = bgp_node_get(peer->bgp->nexthop_cache_table[afi], &p); - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) return; @@ -183,10 +183,10 @@ int bgp_find_or_add_nexthop(struct bgp *bgp_route, struct bgp *bgp_nexthop, else rn = bgp_node_get(bgp_nexthop->nexthop_cache_table[afi], &p); - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) { bnc = bnc_new(); - bgp_nexthop_set_node_info(rn, bnc); + bgp_node_set_bgp_nexthop_info(rn, bnc); bnc->node = rn; bnc->bgp = bgp_nexthop; bgp_lock_node(rn); @@ -293,7 +293,7 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer) return; } - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) { if (BGP_DEBUG(nht, NHT)) zlog_debug("Cannot find connected NHT node for peer %s on route_node as expected", @@ -318,7 +318,7 @@ void bgp_delete_connected_nexthop(afi_t afi, struct peer *peer) zlog_debug("Freeing connected NHT node %p for peer %s", bnc, peer->host); unregister_zebra_rnh(bnc, 0); - bgp_nexthop_set_node_info(bnc->node, NULL); + bgp_node_set_bgp_nexthop_info(bnc->node, NULL); bgp_unlock_node(bnc->node); bnc_free(bnc); } @@ -371,7 +371,7 @@ void bgp_parse_nexthop_update(int command, vrf_id_t vrf_id) return; } - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) { if (BGP_DEBUG(nht, NHT)) { char buf[PREFIX2STR_BUFFER]; @@ -510,7 +510,7 @@ void bgp_cleanup_nexthops(struct bgp *bgp) for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn; rn = bgp_route_next(rn)) { - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) continue; @@ -829,7 +829,7 @@ void bgp_nht_register_nexthops(struct bgp *bgp) for (rn = bgp_table_top(bgp->nexthop_cache_table[afi]); rn; rn = bgp_route_next(rn)) { - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) continue; @@ -867,7 +867,7 @@ void bgp_nht_register_enhe_capability_interfaces(struct peer *peer) return; rn = bgp_node_lookup(bgp->nexthop_cache_table[AFI_IP6], &p); - bnc = bgp_nexthop_get_node_info(rn); + bnc = bgp_node_get_bgp_nexthop_info(rn); if (!bnc) return; diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index ee21e74a15..77722e515b 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -365,12 +365,12 @@ static inline void bgp_connected_set_node_info(struct bgp_node *node, } static inline struct bgp_nexthop_cache * -bgp_nexthop_get_node_info(struct bgp_node *node) +bgp_node_get_bgp_nexthop_info(struct bgp_node *node) { return node->info; } -static inline void bgp_nexthop_set_node_info(struct bgp_node *node, +static inline void bgp_node_set_bgp_nexthop_info(struct bgp_node *node, struct bgp_nexthop_cache *bnc) { node->info = bnc; From b613a9183fb8d6a75aab73084983b94a866a4c41 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 2 Nov 2018 08:31:22 -0400 Subject: [PATCH 10/13] bgpd: Cleanup bgp_aggregate_set|get function names The bgp_aggregate_set_node_info and bgp_aggregate_get_node_info functions names were slightly backwards, rename to bgp_node_get_bgp_aggregate_info and bgp_node_set_bgp_aggregate_info Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 12 ++++++------ bgpd/bgp_table.h | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 8cb65262cd..1822c60322 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -5916,7 +5916,7 @@ void bgp_aggregate_increment(struct bgp *bgp, struct prefix *p, /* Aggregate address configuration check. */ for (rn = child; rn; rn = bgp_node_parent_nolock(rn)) { - aggregate = bgp_aggregate_get_node_info(rn); + aggregate = bgp_node_get_bgp_aggregate_info(rn); if (aggregate != NULL && rn->p.prefixlen < p->prefixlen) { bgp_aggregate_delete(bgp, &rn->p, afi, safi, aggregate); bgp_aggregate_route(bgp, &rn->p, pi, afi, safi, NULL, @@ -5947,7 +5947,7 @@ void bgp_aggregate_decrement(struct bgp *bgp, struct prefix *p, /* Aggregate address configuration check. */ for (rn = child; rn; rn = bgp_node_parent_nolock(rn)) { - aggregate = bgp_aggregate_get_node_info(rn); + aggregate = bgp_node_get_bgp_aggregate_info(rn); if (aggregate != NULL && rn->p.prefixlen < p->prefixlen) { bgp_aggregate_delete(bgp, &rn->p, afi, safi, aggregate); bgp_aggregate_route(bgp, &rn->p, NULL, afi, safi, del, @@ -5986,13 +5986,13 @@ static int bgp_aggregate_unset(struct vty *vty, const char *prefix_str, return CMD_WARNING_CONFIG_FAILED; } - aggregate = bgp_aggregate_get_node_info(rn); + aggregate = bgp_node_get_bgp_aggregate_info(rn); bgp_aggregate_delete(bgp, &p, afi, safi, aggregate); bgp_aggregate_install(bgp, afi, safi, &p, 0, NULL, NULL, NULL, NULL, 0, aggregate); /* Unlock aggregate address configuration. */ - bgp_aggregate_set_node_info(rn, NULL); + bgp_node_set_bgp_aggregate_info(rn, NULL); bgp_aggregate_free(aggregate); bgp_unlock_node(rn); bgp_unlock_node(rn); @@ -6043,7 +6043,7 @@ static int bgp_aggregate_set(struct vty *vty, const char *prefix_str, afi_t afi, aggregate->summary_only = summary_only; aggregate->as_set = as_set; aggregate->safi = safi; - bgp_aggregate_set_node_info(rn, aggregate); + bgp_node_set_bgp_aggregate_info(rn, aggregate); /* Aggregate address insert into BGP routing table. */ bgp_aggregate_route(bgp, &p, NULL, afi, safi, NULL, aggregate); @@ -11777,7 +11777,7 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi, /* Aggregate-address configuration. */ for (rn = bgp_table_top(bgp->aggregate[afi][safi]); rn; rn = bgp_route_next(rn)) { - bgp_aggregate = bgp_aggregate_get_node_info(rn); + bgp_aggregate = bgp_node_get_bgp_aggregate_info(rn); if (bgp_aggregate == NULL) continue; diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 77722e515b..1ad5e5e8b2 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -319,13 +319,14 @@ void bgp_table_range_lookup(const struct bgp_table *table, struct prefix *p, static inline struct bgp_aggregate * -bgp_aggregate_get_node_info(struct bgp_node *node) +bgp_node_get_bgp_aggregate_info(struct bgp_node *node) { return node->info; } -static inline void bgp_aggregate_set_node_info(struct bgp_node *node, - struct bgp_aggregate *aggregate) +static inline void +bgp_node_set_bgp_aggregate_info(struct bgp_node *node, + struct bgp_aggregate *aggregate) { node->info = aggregate; } From 5a8ba9fc0ad9f0d6d3ca3075bf229a2319eb5cc0 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 16 Nov 2018 08:46:19 -0500 Subject: [PATCH 11/13] bgpd: Cleanup bgp_static_set|get function names The bgp_static_set_node_info and bgp_static_get_node_info function names were slightly backwards rename to bgp_node_get_bgp_static_info and bgp_node_set_bgp_static_info Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 46 ++++++++++++++++++++++++--------------------- bgpd/bgp_routemap.c | 2 +- bgpd/bgp_table.h | 7 ++++--- 3 files changed, 30 insertions(+), 25 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index 1822c60322..c582c46c8e 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -4905,7 +4905,7 @@ static int bgp_static_set(struct vty *vty, const char *negate, return CMD_WARNING_CONFIG_FAILED; } - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); if ((label_index != BGP_INVALID_LABEL_INDEX) && (label_index != bgp_static->label_index)) { @@ -4927,7 +4927,7 @@ static int bgp_static_set(struct vty *vty, const char *negate, /* Clear configuration. */ bgp_static_free(bgp_static); - bgp_static_set_node_info(rn, NULL); + bgp_node_set_bgp_static_info(rn, NULL); bgp_unlock_node(rn); bgp_unlock_node(rn); } else { @@ -4935,7 +4935,7 @@ static int bgp_static_set(struct vty *vty, const char *negate, /* Set BGP static route configuration. */ rn = bgp_node_get(bgp->route[afi][safi], &p); - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); if (bgp_static) { /* Configuration change. */ /* Label index cannot be changed. */ @@ -4986,7 +4986,7 @@ static int bgp_static_set(struct vty *vty, const char *negate, bgp_static->rmap.map = route_map_lookup_by_name(rmap); } - bgp_static_set_node_info(rn, bgp_static); + bgp_node_set_bgp_static_info(rn, bgp_static); } bgp_static->valid = 1; @@ -5022,15 +5022,17 @@ void bgp_static_add(struct bgp *bgp) for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { bgp_static = - bgp_static_get_node_info(rm); + bgp_node_get_bgp_static_info( + rm); bgp_static_update_safi(bgp, &rm->p, bgp_static, afi, safi); } } else { - bgp_static_update(bgp, &rn->p, - bgp_static_get_node_info(rn), - afi, safi); + bgp_static_update( + bgp, &rn->p, + bgp_node_get_bgp_static_info(rn), afi, + safi); } } } @@ -5059,19 +5061,20 @@ void bgp_static_delete(struct bgp *bgp) for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { bgp_static = - bgp_static_get_node_info(rm); + bgp_node_get_bgp_static_info( + rm); bgp_static_withdraw_safi( bgp, &rm->p, AFI_IP, safi, (struct prefix_rd *)&rn->p); bgp_static_free(bgp_static); - bgp_static_set_node_info(rn, NULL); + bgp_node_set_bgp_static_info(rn, NULL); bgp_unlock_node(rn); } } else { - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); bgp_static_withdraw(bgp, &rn->p, afi, safi); bgp_static_free(bgp_static); - bgp_static_set_node_info(rn, NULL); + bgp_node_set_bgp_static_info(rn, NULL); bgp_unlock_node(rn); } } @@ -5101,13 +5104,14 @@ void bgp_static_redo_import_check(struct bgp *bgp) for (rm = bgp_table_top(table); rm; rm = bgp_route_next(rm)) { bgp_static = - bgp_static_get_node_info(rm); + bgp_node_get_bgp_static_info( + rm); bgp_static_update_safi(bgp, &rm->p, bgp_static, afi, safi); } } else { - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); bgp_static_update(bgp, &rn->p, bgp_static, afi, safi); } @@ -5280,7 +5284,7 @@ int bgp_static_set_safi(afi_t afi, safi_t safi, struct vty *vty, if (gwip) prefix_copy(&bgp_static->gatewayIp, &gw_ip); } - bgp_static_set_node_info(rn, bgp_static); + bgp_node_set_bgp_static_info(rn, bgp_static); bgp_static->valid = 1; bgp_static_update_safi(bgp, &p, bgp_static, afi, safi); @@ -5343,9 +5347,9 @@ int bgp_static_unset_safi(afi_t afi, safi_t safi, struct vty *vty, if (rn) { bgp_static_withdraw_safi(bgp, &p, afi, safi, &prd); - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); bgp_static_free(bgp_static); - bgp_static_set_node_info(rn, NULL); + bgp_node_set_bgp_static_info(rn, NULL); bgp_unlock_node(rn); bgp_unlock_node(rn); } else @@ -11156,7 +11160,7 @@ uint8_t bgp_distance_apply(struct prefix *p, struct bgp_path_info *pinfo, /* Backdoor check. */ rn = bgp_node_lookup(bgp->route[afi][safi], p); if (rn) { - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); bgp_unlock_node(rn); if (bgp_static->backdoor) { @@ -11603,7 +11607,7 @@ static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp, continue; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); if (bgp_static == NULL) continue; @@ -11654,7 +11658,7 @@ static void bgp_config_write_network_evpn(struct vty *vty, struct bgp *bgp, continue; for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) { - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); if (bgp_static == NULL) continue; @@ -11730,7 +11734,7 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi, /* Network configuration. */ for (rn = bgp_table_top(bgp->route[afi][safi]); rn; rn = bgp_route_next(rn)) { - bgp_static = bgp_static_get_node_info(rn); + bgp_static = bgp_node_get_bgp_static_info(rn); if (bgp_static == NULL) continue; diff --git a/bgpd/bgp_routemap.c b/bgpd/bgp_routemap.c index 73b01b6b2d..1a0532fbb8 100644 --- a/bgpd/bgp_routemap.c +++ b/bgpd/bgp_routemap.c @@ -3227,7 +3227,7 @@ static void bgp_route_map_process_update(struct bgp *bgp, const char *rmap_name, /* For network route-map updates. */ for (bn = bgp_table_top(bgp->route[afi][safi]); bn; bn = bgp_route_next(bn)) { - bgp_static = bgp_static_get_node_info(bn); + bgp_static = bgp_node_get_bgp_static_info(bn); if (!bgp_static) continue; diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 1ad5e5e8b2..9fcf5c1c79 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -342,13 +342,14 @@ static inline void bgp_distance_set_node_info(struct bgp_node *node, node->info = distance; } -static inline struct bgp_static *bgp_static_get_node_info(struct bgp_node *node) +static inline struct bgp_static * +bgp_node_get_bgp_static_info(struct bgp_node *node) { return node->info; } -static inline void bgp_static_set_node_info(struct bgp_node *node, - struct bgp_static *bgp_static) +static inline void bgp_node_set_bgp_static_info(struct bgp_node *node, + struct bgp_static *bgp_static) { node->info = bgp_static; } From 5b00b40eec095ed2d4d667d496783153deb457e2 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 16 Nov 2018 08:50:26 -0500 Subject: [PATCH 12/13] bgpd: Cleanup bgp_distance_set|get function names The bgp_distance_set_node_info and bgp_distance_get_node_info function names were slightly backwards lets fix them up to bgp_node_get_bgp_distance_info and bgp_node_set_bgp_distance_info Signed-off-by: Donald Sharp --- bgpd/bgp_route.c | 10 +++++----- bgpd/bgp_table.h | 7 ++++--- 2 files changed, 9 insertions(+), 8 deletions(-) diff --git a/bgpd/bgp_route.c b/bgpd/bgp_route.c index c582c46c8e..3f3cda1960 100644 --- a/bgpd/bgp_route.c +++ b/bgpd/bgp_route.c @@ -11056,12 +11056,12 @@ static int bgp_distance_set(struct vty *vty, const char *distance_str, /* Get BGP distance node. */ rn = bgp_node_get(bgp_distance_table[afi][safi], (struct prefix *)&p); - bdistance = bgp_distance_get_node(rn); + bdistance = bgp_node_get_bgp_distance_info(rn); if (bdistance) bgp_unlock_node(rn); else { bdistance = bgp_distance_new(); - bgp_distance_set_node_info(rn, bdistance); + bgp_node_set_bgp_distance_info(rn, bdistance); } /* Set distance value. */ @@ -11106,7 +11106,7 @@ static int bgp_distance_unset(struct vty *vty, const char *distance_str, return CMD_WARNING_CONFIG_FAILED; } - bdistance = bgp_distance_get_node(rn); + bdistance = bgp_node_get_bgp_distance_info(rn); distance = atoi(distance_str); if (bdistance->distance != distance) { @@ -11145,7 +11145,7 @@ uint8_t bgp_distance_apply(struct prefix *p, struct bgp_path_info *pinfo, sockunion2hostprefix(&peer->su, &q); rn = bgp_node_match(bgp_distance_table[afi][safi], &q); if (rn) { - bdistance = bgp_distance_get_node(rn); + bdistance = bgp_node_get_bgp_distance_info(rn); bgp_unlock_node(rn); if (bdistance->access_list) { @@ -11833,7 +11833,7 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi, for (rn = bgp_table_top(bgp_distance_table[afi][safi]); rn; rn = bgp_route_next(rn)) { - bdistance = bgp_distance_get_node(rn); + bdistance = bgp_node_get_bgp_distance_info(rn); if (bdistance != NULL) { char buf[PREFIX_STRLEN]; diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 9fcf5c1c79..936d72ff19 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -331,13 +331,14 @@ bgp_node_set_bgp_aggregate_info(struct bgp_node *node, node->info = aggregate; } -static inline struct bgp_distance *bgp_distance_get_node(struct bgp_node *node) +static inline struct bgp_distance * +bgp_node_get_bgp_distance_info(struct bgp_node *node) { return node->info; } -static inline void bgp_distance_set_node_info(struct bgp_node *node, - struct bgp_distance *distance) +static inline void bgp_node_set_bgp_distance_info(struct bgp_node *node, + struct bgp_distance *distance) { node->info = distance; } From cb8c85abd3f0721c0480e7245f6e783105be7289 Mon Sep 17 00:00:00 2001 From: Donald Sharp Date: Fri, 16 Nov 2018 08:55:29 -0500 Subject: [PATCH 13/13] bgpd: Cleanup bgp_connected_set|get function names The bgp_connected_set_node_info and bgp_connected_get_node_info function names were slightly backwards lets fix them up to bgp_node_set_bgp_connected_ref_info and bgp_node_get_bgp_connected_ref_info Signed-off-by: Donald Sharp --- bgpd/bgp_nexthop.c | 16 ++++++++-------- bgpd/bgp_table.h | 7 ++++--- 2 files changed, 12 insertions(+), 11 deletions(-) diff --git a/bgpd/bgp_nexthop.c b/bgpd/bgp_nexthop.c index 1877077602..30d786fcda 100644 --- a/bgpd/bgp_nexthop.c +++ b/bgpd/bgp_nexthop.c @@ -349,14 +349,14 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc) rn = bgp_node_get(bgp->connected_table[AFI_IP], (struct prefix *)&p); - bc = bgp_connected_get_node_info(rn); + bc = bgp_node_get_bgp_connected_ref_info(rn); if (bc) bc->refcnt++; else { bc = XCALLOC(MTYPE_BGP_CONN, sizeof(struct bgp_connected_ref)); bc->refcnt = 1; - bgp_connected_set_node_info(rn, bc); + bgp_node_set_bgp_connected_ref_info(rn, bc); } for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { @@ -382,14 +382,14 @@ void bgp_connected_add(struct bgp *bgp, struct connected *ifc) rn = bgp_node_get(bgp->connected_table[AFI_IP6], (struct prefix *)&p); - bc = bgp_connected_get_node_info(rn); + bc = bgp_node_get_bgp_connected_ref_info(rn); if (bc) bc->refcnt++; else { bc = XCALLOC(MTYPE_BGP_CONN, sizeof(struct bgp_connected_ref)); bc->refcnt = 1; - bgp_connected_set_node_info(rn, bc); + bgp_node_set_bgp_connected_ref_info(rn, bc); } } } @@ -426,11 +426,11 @@ void bgp_connected_delete(struct bgp *bgp, struct connected *ifc) if (!rn) return; - bc = bgp_connected_get_node_info(rn); + bc = bgp_node_get_bgp_connected_ref_info(rn); bc->refcnt--; if (bc->refcnt == 0) { XFREE(MTYPE_BGP_CONN, bc); - bgp_connected_set_node_info(rn, NULL); + bgp_node_set_bgp_connected_ref_info(rn, NULL); } bgp_unlock_node(rn); bgp_unlock_node(rn); @@ -442,14 +442,14 @@ static void bgp_connected_cleanup(struct route_table *table, struct bgp_connected_ref *bc; struct bgp_node *bn = bgp_node_from_rnode(rn); - bc = bgp_connected_get_node_info(bn); + bc = bgp_node_get_bgp_connected_ref_info(bn); if (!bc) return; bc->refcnt--; if (bc->refcnt == 0) { XFREE(MTYPE_BGP_CONN, bc); - bgp_connected_set_node_info(bn, NULL); + bgp_node_set_bgp_connected_ref_info(bn, NULL); } } diff --git a/bgpd/bgp_table.h b/bgpd/bgp_table.h index 936d72ff19..a76af0ef28 100644 --- a/bgpd/bgp_table.h +++ b/bgpd/bgp_table.h @@ -356,13 +356,14 @@ static inline void bgp_node_set_bgp_static_info(struct bgp_node *node, } static inline struct bgp_connected_ref * -bgp_connected_get_node_info(struct bgp_node *node) +bgp_node_get_bgp_connected_ref_info(struct bgp_node *node) { return node->info; } -static inline void bgp_connected_set_node_info(struct bgp_node *node, - struct bgp_connected_ref *bc) +static inline void +bgp_node_set_bgp_connected_ref_info(struct bgp_node *node, + struct bgp_connected_ref *bc) { node->info = bc; }