bgpd: changes for code maintainability

these changes are for improving the code maintainability and readability

Signed-off-by: sri-mohan1 <sri.mohan@samsung.com>
This commit is contained in:
sri-mohan1 2024-10-09 14:19:55 +05:30
parent 47cdfbda76
commit c853c8d13b
2 changed files with 34 additions and 46 deletions

View File

@ -528,14 +528,12 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
tmp_addr.p.prefixlen = p->prefixlen; tmp_addr.p.prefixlen = p->prefixlen;
} else { } else {
/* Here we need to find out which nexthop to be used*/ /* Here we need to find out which nexthop to be used*/
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) { if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) {
tmp_addr.p.u.prefix4 = attr->nexthop; tmp_addr.p.u.prefix4 = attr->nexthop;
tmp_addr.p.prefixlen = IPV4_MAX_BITLEN; tmp_addr.p.prefixlen = IPV4_MAX_BITLEN;
} else if ((attr->mp_nexthop_len) } else if ((attr->mp_nexthop_len) &&
&& ((attr->mp_nexthop_len ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ||
== BGP_ATTR_NHLEN_IPV4) (attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV4))) {
|| (attr->mp_nexthop_len
== BGP_ATTR_NHLEN_VPNV4))) {
tmp_addr.p.u.prefix4 = tmp_addr.p.u.prefix4 =
attr->mp_nexthop_global_in; attr->mp_nexthop_global_in;
tmp_addr.p.prefixlen = IPV4_MAX_BITLEN; tmp_addr.p.prefixlen = IPV4_MAX_BITLEN;
@ -564,11 +562,11 @@ bool bgp_nexthop_self(struct bgp *bgp, afi_t afi, uint8_t type,
memset(&tmp_tip, 0, sizeof(tmp_tip)); memset(&tmp_tip, 0, sizeof(tmp_tip));
tmp_tip.addr = attr->nexthop; tmp_tip.addr = attr->nexthop;
if (attr->flag & ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP)) { if (CHECK_FLAG(attr->flag, ATTR_FLAG_BIT(BGP_ATTR_NEXT_HOP))) {
tmp_tip.addr = attr->nexthop; tmp_tip.addr = attr->nexthop;
} else if ((attr->mp_nexthop_len) && } else if ((attr->mp_nexthop_len) &&
((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ((attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV4) ||
|| (attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV4))) { (attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV4))) {
tmp_tip.addr = attr->mp_nexthop_global_in; tmp_tip.addr = attr->mp_nexthop_global_in;
} }

View File

@ -2935,33 +2935,29 @@ static int bgp_route_refresh_receive(struct peer_connection *connection,
if (bgp_debug_neighbor_events(peer)) { if (bgp_debug_neighbor_events(peer)) {
char buf[INET6_BUFSIZ]; char buf[INET6_BUFSIZ];
zlog_debug( zlog_debug("%pBP rcvd %s %s seq %u %s/%d ge %d le %d%s",
"%pBP rcvd %s %s seq %u %s/%d ge %d le %d%s",
peer, peer,
(common & ORF_COMMON_PART_REMOVE (CHECK_FLAG(common, ORF_COMMON_PART_REMOVE)
? "Remove" ? "Remove"
: "Add"), : "Add"),
(common & ORF_COMMON_PART_DENY (CHECK_FLAG(common, ORF_COMMON_PART_DENY)
? "deny" ? "deny"
: "permit"), : "permit"),
orfp.seq, orfp.seq,
inet_ntop( inet_ntop(orfp.p.family, &orfp.p.u.prefix,
orfp.p.family, buf, INET6_BUFSIZ),
&orfp.p.u.prefix, orfp.p.prefixlen, orfp.ge, orfp.le,
buf,
INET6_BUFSIZ),
orfp.p.prefixlen,
orfp.ge, orfp.le,
ok ? "" : " MALFORMED"); ok ? "" : " MALFORMED");
} }
if (ok) if (ok)
ret = prefix_bgp_orf_set( ret = prefix_bgp_orf_set(name, afi, &orfp,
name, afi, &orfp, (CHECK_FLAG(common,
(common & ORF_COMMON_PART_DENY ORF_COMMON_PART_DENY)
? 0 ? 0
: 1), : 1),
(common & ORF_COMMON_PART_REMOVE (CHECK_FLAG(common,
ORF_COMMON_PART_REMOVE)
? 0 ? 0
: 1)); : 1));
@ -3190,16 +3186,10 @@ static void bgp_dynamic_capability_addpath(uint8_t *pnt, int action,
if (bgp_debug_neighbor_events(peer)) if (bgp_debug_neighbor_events(peer))
zlog_debug("%s OPEN has %s capability for afi/safi: %s/%s%s%s", zlog_debug("%s OPEN has %s capability for afi/safi: %s/%s%s%s",
peer->host, peer->host, lookup_msg(capcode_str, hdr->code, NULL),
lookup_msg(capcode_str, hdr->code, iana_afi2str(pkt_afi), iana_safi2str(pkt_safi),
NULL), CHECK_FLAG(bac.flags, BGP_ADDPATH_RX) ? ", receive" : "",
iana_afi2str(pkt_afi), CHECK_FLAG(bac.flags, BGP_ADDPATH_TX) ? ", transmit"
iana_safi2str(pkt_safi),
(bac.flags & BGP_ADDPATH_RX)
? ", receive"
: "",
(bac.flags & BGP_ADDPATH_TX)
? ", transmit"
: ""); : "");
if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi, if (bgp_map_afi_safi_iana2int(pkt_afi, pkt_safi, &afi,