From ad1844f7bd580e73f7088e79493481a20b5f872d Mon Sep 17 00:00:00 2001 From: Iqra Siddiqui Date: Fri, 17 Sep 2021 08:50:03 -0700 Subject: [PATCH] bgpd: Few code optimisations Description: Added a macro which optimises some part of the code. Co-authored-by: Santosh P K Co-authored-by: Kantesh Mundaragi Signed-off-by: Iqra Siddiqui --- bgpd/bgp_zebra.c | 22 +++++++++------------- bgpd/bgp_zebra.h | 7 +++++++ 2 files changed, 16 insertions(+), 13 deletions(-) diff --git a/bgpd/bgp_zebra.c b/bgpd/bgp_zebra.c index a98168d46..5b4f31f66 100644 --- a/bgpd/bgp_zebra.c +++ b/bgpd/bgp_zebra.c @@ -1249,6 +1249,7 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, uint8_t distance; struct peer *peer; struct bgp_path_info *mpinfo; + struct bgp *bgp_orig; uint32_t metric; struct attr local_attr; struct bgp_path_info local_info; @@ -1412,13 +1413,13 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, } } + BGP_ORIGINAL_UPDATE(bgp_orig, mpinfo, bgp); + if (nh_family == AF_INET) { nh_updated = update_ipv4nh_for_route_install( - nh_othervrf, - nh_othervrf ? - info->extra->bgp_orig : bgp, - &mpinfo_cp->attr->nexthop, - mpinfo_cp->attr, is_evpn, api_nh); + nh_othervrf, bgp_orig, + &mpinfo_cp->attr->nexthop, mpinfo_cp->attr, + is_evpn, api_nh); } else { ifindex_t ifindex = IFINDEX_INTERNAL; struct in6_addr *nexthop; @@ -1428,18 +1429,13 @@ void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, if (!nexthop) nh_updated = update_ipv4nh_for_route_install( - nh_othervrf, - nh_othervrf ? info->extra->bgp_orig - : bgp, + nh_othervrf, bgp_orig, &mpinfo_cp->attr->nexthop, mpinfo_cp->attr, is_evpn, api_nh); else nh_updated = update_ipv6nh_for_route_install( - nh_othervrf, - nh_othervrf ? info->extra->bgp_orig - : bgp, - nexthop, ifindex, mpinfo, info, is_evpn, - api_nh); + nh_othervrf, bgp_orig, nexthop, ifindex, + mpinfo, info, is_evpn, api_nh); } /* Did we get proper nexthop info to update zebra? */ diff --git a/bgpd/bgp_zebra.h b/bgpd/bgp_zebra.h index 9c0a1d8f1..eee3d3693 100644 --- a/bgpd/bgp_zebra.h +++ b/bgpd/bgp_zebra.h @@ -23,6 +23,13 @@ #include "vxlan.h" +/* Macro to update bgp_original based on bpg_path_info */ +#define BGP_ORIGINAL_UPDATE(_bgp_orig, _mpinfo, _bgp) \ + ((_mpinfo->extra && _mpinfo->extra->bgp_orig \ + && _mpinfo->sub_type == BGP_ROUTE_IMPORTED) \ + ? (_bgp_orig = _mpinfo->extra->bgp_orig) \ + : (_bgp_orig = _bgp)) + /* Default weight for next hop, if doing weighted ECMP. */ #define BGP_ZEBRA_DEFAULT_NHOP_WEIGHT 1 -- 2.39.5