]> git.proxmox.com Git - mirror_frr.git/blobdiff - bgpd/bgp_route.c
*: Create/Use accessor functions for lock count
[mirror_frr.git] / bgpd / bgp_route.c
index 8977b1651a6a121c936340a6645e25a30a99c5aa..f998a4d3509a45d2081a2752a8ec797dc6b619db 100644 (file)
@@ -216,7 +216,7 @@ void bgp_path_info_extra_free(struct bgp_path_info_extra **extra)
                        unsigned refcount;
 
                        bpi = bgp_path_info_lock(bpi);
-                       refcount = bpi->net->lock - 1;
+                       refcount = bgp_dest_get_lock_count(bpi->net) - 1;
                        bgp_dest_unlock_node((struct bgp_dest *)bpi->net);
                        if (!refcount)
                                bpi->net = NULL;
@@ -314,8 +314,8 @@ static int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete)
        if (CHECK_FLAG(dest->flags, BGP_NODE_PROCESS_SCHEDULED)) {
                if (BGP_DEBUG(update, UPDATE_OUT))
                        zlog_debug(
-                               "Route %pRN is in workqueue and being processed, not deferred.",
-                               bgp_dest_to_rnode(dest));
+                               "Route %pBD is in workqueue and being processed, not deferred.",
+                               dest);
 
                return 0;
        }
@@ -365,7 +365,7 @@ static int bgp_dest_set_defer_flag(struct bgp_dest *dest, bool delete)
                                        bgp->gr_info[afi][safi].route_list,
                                        dest);
                        if (BGP_DEBUG(update, UPDATE_OUT))
-                               zlog_debug("DEFER route %pRN, dest %p, node %p",
+                               zlog_debug("DEFER route %pBD, dest %p, node %p",
                                           dest, dest, dest->rt_node);
                        return 0;
                }
@@ -1635,7 +1635,6 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
        struct peer *onlypeer;
        struct bgp *bgp;
        struct attr *piattr;
-       char buf[PREFIX_STRLEN];
        route_map_result_t ret;
        int transparent;
        int reflect;
@@ -1671,9 +1670,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
                 * though they can have peer pointers that reference other
                 * systems
                 */
-               prefix2str(p, buf, PREFIX_STRLEN);
-               zlog_debug("%s: pfx %s bgp_direct->vpn route peer safe",
-                          __func__, buf);
+               zlog_debug("%s: pfx %pFX bgp_direct->vpn route peer safe",
+                          __func__, p);
                samepeer_safe = 1;
        }
 #endif
@@ -1726,11 +1724,10 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
                mpls_label_t label = bgp_adv_label(dest, pi, peer, afi, safi);
                if (!bgp_is_valid_label(&label)) {
                        if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
-                               zlog_debug("u%" PRIu64 ":s%" PRIu64" %s/%d is filtered - no label (%p)",
+                               zlog_debug("u%" PRIu64 ":s%" PRIu64
+                                          " %pFX is filtered - no label (%p)",
                                           subgrp->update_group->id, subgrp->id,
-                                          inet_ntop(p->family, &p->u.prefix,
-                                                    buf, SU_ADDRSTRLEN),
-                                          p->prefixlen, &label);
+                                          p, &label);
                        return false;
                }
        }
@@ -1771,9 +1768,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
            && (IPV4_ADDR_SAME(&onlypeer->remote_id, &piattr->originator_id))) {
                if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
                        zlog_debug(
-                               "%s [Update:SEND] %s originator-id is same as remote router-id",
-                               onlypeer->host,
-                               prefix2str(p, buf, sizeof(buf)));
+                               "%s [Update:SEND] %pFX originator-id is same as remote router-id",
+                               onlypeer->host, p);
                return false;
        }
 
@@ -1788,10 +1784,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
                                if (bgp_debug_update(NULL, p,
                                                     subgrp->update_group, 0))
                                        zlog_debug(
-                                               "%s [Update:SEND] %s is filtered via ORF",
-                                               peer->host,
-                                               prefix2str(p, buf,
-                                                          sizeof(buf)));
+                                               "%s [Update:SEND] %pFX is filtered via ORF",
+                                               peer->host, p);
                                return false;
                        }
                }
@@ -1799,8 +1793,8 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
        /* Output filter check. */
        if (bgp_output_filter(peer, p, piattr, afi, safi) == FILTER_DENY) {
                if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
-                       zlog_debug("%s [Update:SEND] %s is filtered",
-                                  peer->host, prefix2str(p, buf, sizeof(buf)));
+                       zlog_debug("%s [Update:SEND] %pFX is filtered",
+                                  peer->host, p);
                return false;
        }
 
@@ -1986,8 +1980,9 @@ bool subgroup_announce_check(struct bgp_dest *dest, struct bgp_path_info *pi,
 
                if (ret == RMAP_DENYMATCH) {
                        if (bgp_debug_update(NULL, p, subgrp->update_group, 0))
-                               zlog_debug("%s [Update:SEND] %s is filtered by route-map",
-                               peer->host, prefix2str(p, buf, sizeof(buf)));
+                               zlog_debug(
+                                       "%s [Update:SEND] %pFX is filtered by route-map",
+                                       peer->host, p);
 
                        bgp_attr_flush(attr);
                        return false;
@@ -2268,10 +2263,11 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
                        if (debug) {
                                bgp_path_info_path_with_addpath_rx_str(
                                        new_select, path_buf);
-                               zlog_debug("%s: %s is the bestpath from AS %u",
-                                          pfx_buf, path_buf,
-                                          aspath_get_first_as(
-                                                  new_select->attr->aspath));
+                               zlog_debug(
+                                       "%pBD: %s is the bestpath from AS %u",
+                                       dest, path_buf,
+                                       aspath_get_first_as(
+                                               new_select->attr->aspath));
                        }
                }
        }
@@ -2345,8 +2341,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
                else
                        snprintf(path_buf, sizeof(path_buf), "NONE");
                zlog_debug(
-                       "%s: After path selection, newbest is %s oldbest was %s",
-                       pfx_buf, path_buf,
+                       "%pBD: After path selection, newbest is %s oldbest was %s",
+                       dest, path_buf,
                        old_select ? old_select->peer->host : "NONE");
        }
 
@@ -2361,8 +2357,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
                        if (pi == new_select) {
                                if (debug)
                                        zlog_debug(
-                                               "%s: %s is the bestpath, add to the multipath list",
-                                               pfx_buf, path_buf);
+                                               "%pBD: %s is the bestpath, add to the multipath list",
+                                               dest, path_buf);
                                bgp_mp_list_add(&mp_list, pi);
                                continue;
                        }
@@ -2379,8 +2375,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
                        if (!bgp_path_info_nexthop_cmp(pi, new_select)) {
                                if (debug)
                                        zlog_debug(
-                                               "%s: %s has the same nexthop as the bestpath, skip it",
-                                               pfx_buf, path_buf);
+                                               "%pBD: %s has the same nexthop as the bestpath, skip it",
+                                               dest, path_buf);
                                continue;
                        }
 
@@ -2391,8 +2387,8 @@ void bgp_best_selection(struct bgp *bgp, struct bgp_dest *dest,
                        if (paths_eq) {
                                if (debug)
                                        zlog_debug(
-                                               "%s: %s is equivalent to the bestpath, add to the multipath list",
-                                               pfx_buf, path_buf);
+                                               "%pBD: %s is equivalent to the bestpath, add to the multipath list",
+                                               dest, path_buf);
                                bgp_mp_list_add(&mp_list, pi);
                        }
                }
@@ -2601,7 +2597,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
                        debug = bgp_debug_bestpath(dest);
                if (debug)
                        zlog_debug(
-                               "%s: bgp delete in progress, ignoring event, p=%pRN",
+                               "%s: bgp delete in progress, ignoring event, p=%pBD",
                                __func__, dest);
                return;
        }
@@ -2625,7 +2621,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
 
        debug = bgp_debug_bestpath(dest);
        if (debug)
-               zlog_debug("%s: p=%pRN afi=%s, safi=%s start", __func__, dest,
+               zlog_debug("%s: p=%pBD afi=%s, safi=%s start", __func__, dest,
                           afi2str(afi), safi2str(safi));
 
        /* The best path calculation for the route is deferred if
@@ -2686,7 +2682,7 @@ static void bgp_process_main_one(struct bgp *bgp, struct bgp_dest *dest,
 
        if (debug)
                zlog_debug(
-                       "%s: p=%pRN afi=%s, safi=%s, old_select=%p, new_select=%p",
+                       "%s: p=%pBD afi=%s, safi=%s, old_select=%p, new_select=%p",
                        __func__, dest, afi2str(afi), safi2str(safi),
                        old_select, new_select);
 
@@ -7610,10 +7606,7 @@ static void route_vty_out_route(const struct prefix *p, struct vty *vty,
 
        if (p->family == AF_INET) {
                if (!json) {
-                       len = vty_out(
-                               vty, "%s/%d",
-                               inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
-                               p->prefixlen);
+                       len = vty_out(vty, "%pFX", p);
                } else {
                        json_object_string_add(json, "prefix",
                                               inet_ntop(p->family,
@@ -7625,13 +7618,12 @@ static void route_vty_out_route(const struct prefix *p, struct vty *vty,
                }
        } else if (p->family == AF_ETHERNET) {
                prefix2str(p, buf, PREFIX_STRLEN);
-               len = vty_out(vty, "%s", buf);
+               len = vty_out(vty, "%pFX", p);
        } else if (p->family == AF_EVPN) {
                if (!json)
-                       len = vty_out(
-                               vty, "%s",
-                               bgp_evpn_route2str((struct prefix_evpn *)p, buf,
-                                                  BUFSIZ));
+                       len = vty_out(vty, "%s",
+                                     prefix2str((struct prefix_evpn *)p, buf,
+                                                BUFSIZ));
                else
                        bgp_evpn_route2json((struct prefix_evpn *)p, json);
        } else if (p->family == AF_FLOWSPEC) {
@@ -7641,10 +7633,7 @@ static void route_vty_out_route(const struct prefix *p, struct vty *vty,
                               NLRI_STRING_FORMAT_MIN, json);
        } else {
                if (!json)
-                       len = vty_out(
-                               vty, "%s/%d",
-                               inet_ntop(p->family, &p->u.prefix, buf, BUFSIZ),
-                               p->prefixlen);
+                       len = vty_out(vty, "%pFX", p);
                else {
                        json_object_string_add(json, "prefix",
                                                inet_ntop(p->family,
@@ -8985,10 +8974,9 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
                }
                if (safi == SAFI_EVPN) {
                        if (!json_paths) {
-                               bgp_evpn_route2str(
-                                       (struct prefix_evpn *)
-                                               bgp_dest_get_prefix(bn),
-                                       buf2, sizeof(buf2));
+                               prefix2str((struct prefix_evpn *)
+                                                  bgp_dest_get_prefix(bn),
+                                          buf2, sizeof(buf2));
                                vty_out(vty, "  Route %s", buf2);
                                if (tag_buf[0] != '\0')
                                        vty_out(vty, " VNI %s", tag_buf);
@@ -9013,11 +9001,10 @@ void route_vty_out_detail(struct vty *vty, struct bgp *bgp,
                                                pdest),
                                        buf1, sizeof(buf1));
                                if (is_pi_family_evpn(parent_ri)) {
-                                       bgp_evpn_route2str(
-                                               (struct prefix_evpn *)
-                                                       bgp_dest_get_prefix(
-                                                               dest),
-                                               buf2, sizeof(buf2));
+                                       prefix2str((struct prefix_evpn *)
+                                                          bgp_dest_get_prefix(
+                                                                  dest),
+                                                  buf2, sizeof(buf2));
                                        vty_out(vty, "  Imported from %s:%s, VNI %s\n", buf1, buf2, tag_buf);
                                } else
                                        vty_out(vty, "  Imported from %s:%s\n", buf1, buf2);
@@ -10334,7 +10321,6 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
        struct peer *peer;
        struct listnode *node, *nnode;
        char buf1[RD_ADDRSTRLEN];
-       char buf2[INET6_ADDRSTRLEN];
        char buf3[EVPN_ROUTE_STRLEN];
        char prefix_str[BUFSIZ];
        int count = 0;
@@ -10369,9 +10355,10 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
                if (!json) {
                        vty_out(vty, "BGP routing table entry for %s%s%s\n",
                                prd ? prefix_rd2str(prd, buf1, sizeof(buf1))
-                               : "", prd ? ":" : "",
-                               bgp_evpn_route2str((struct prefix_evpn *)p,
-                               buf3, sizeof(buf3)));
+                                   : "",
+                               prd ? ":" : "",
+                               prefix2str((struct prefix_evpn *)p, buf3,
+                                          sizeof(buf3)));
                } else {
                        json_object_string_add(json, "rd",
                                prd ? prefix_rd2str(prd, buf1, sizeof(buf1)) :
@@ -10380,15 +10367,12 @@ void route_vty_out_detail_header(struct vty *vty, struct bgp *bgp,
                }
        } else {
                if (!json) {
-                       vty_out(vty, "BGP routing table entry for %s%s%s/%d\n",
+                       vty_out(vty, "BGP routing table entry for %s%s%pFX\n",
                                ((safi == SAFI_MPLS_VPN || safi == SAFI_ENCAP)
-                                ? prefix_rd2str(prd, buf1,
-                                        sizeof(buf1))
-                                : ""),
-                               safi == SAFI_MPLS_VPN ? ":" : "",
-                               inet_ntop(p->family, &p->u.prefix, buf2,
-                                       INET6_ADDRSTRLEN),
-                               p->prefixlen);
+                                        ? prefix_rd2str(prd, buf1,
+                                                        sizeof(buf1))
+                                        : ""),
+                               safi == SAFI_MPLS_VPN ? ":" : "", p);
 
                } else
                        json_object_string_add(json, "prefix",
@@ -13782,7 +13766,6 @@ static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp,
        const struct prefix_rd *prd;
        struct bgp_static *bgp_static;
        mpls_label_t label;
-       char buf[SU_ADDRSTRLEN];
        char rdbuf[RD_ADDRSTRLEN];
 
        /* Network configuration. */
@@ -13806,10 +13789,7 @@ static void bgp_config_write_network_vpn(struct vty *vty, struct bgp *bgp,
                        prefix_rd2str(prd, rdbuf, sizeof(rdbuf));
                        label = decode_label(&bgp_static->label);
 
-                       vty_out(vty, "  network %s/%d rd %s",
-                               inet_ntop(p->family, &p->u.prefix, buf,
-                                         SU_ADDRSTRLEN),
-                               p->prefixlen, rdbuf);
+                       vty_out(vty, "  network %pFX rd %s", p, rdbuf);
                        if (safi == SAFI_MPLS_VPN)
                                vty_out(vty, " label %u", label);
 
@@ -13907,7 +13887,6 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi,
        const struct prefix *p;
        struct bgp_static *bgp_static;
        struct bgp_aggregate *bgp_aggregate;
-       char buf[SU_ADDRSTRLEN];
 
        if ((safi == SAFI_MPLS_VPN) || (safi == SAFI_ENCAP)) {
                bgp_config_write_network_vpn(vty, bgp, afi, safi);
@@ -13928,9 +13907,7 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi,
 
                p = bgp_dest_get_prefix(dest);
 
-               vty_out(vty, "  network %s/%d",
-                       inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
-                       p->prefixlen);
+               vty_out(vty, "  network %pFX", p);
 
                if (bgp_static->label_index != BGP_INVALID_LABEL_INDEX)
                        vty_out(vty, " label-index %u",
@@ -13954,9 +13931,7 @@ void bgp_config_write_network(struct vty *vty, struct bgp *bgp, afi_t afi,
 
                p = bgp_dest_get_prefix(dest);
 
-               vty_out(vty, "  aggregate-address %s/%d",
-                       inet_ntop(p->family, &p->u.prefix, buf, SU_ADDRSTRLEN),
-                       p->prefixlen);
+               vty_out(vty, "  aggregate-address %pFX", p);
 
                if (bgp_aggregate->as_set)
                        vty_out(vty, " as-set");
@@ -14001,7 +13976,7 @@ void bgp_config_write_distance(struct vty *vty, struct bgp *bgp, afi_t afi,
             dest = bgp_route_next(dest)) {
                bdistance = bgp_dest_get_bgp_distance_info(dest);
                if (bdistance != NULL)
-                       vty_out(vty, "  distance %d %pRN %s\n",
+                       vty_out(vty, "  distance %d %pBD %s\n",
                                bdistance->distance, dest,
                                bdistance->access_list ? bdistance->access_list
                                                       : "");