summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_open.c
diff options
context:
space:
mode:
authorQuentin Young <qlyoung@cumulusnetworks.com>2017-11-21 19:02:06 +0100
committerQuentin Young <qlyoung@cumulusnetworks.com>2017-11-21 19:02:06 +0100
commit05c7a1cc93f81ad12424fc9744c60dc722ff459b (patch)
tree1128127dbad7eef96efd6cdc0443ea83f5edad29 /bgpd/bgp_open.c
parentMerge pull request #1451 from msablic/msablic_frr_cm00003 (diff)
downloadfrr-05c7a1cc93f81ad12424fc9744c60dc722ff459b.tar.xz
frr-05c7a1cc93f81ad12424fc9744c60dc722ff459b.zip
bgpd: use FOREACH_AFI_SAFI where possible
Improves consistency and readability. Signed-off-by: Quentin Young <qlyoung@cumulusnetworks.com>
Diffstat (limited to 'bgpd/bgp_open.c')
-rw-r--r--bgpd/bgp_open.c216
1 files changed, 102 insertions, 114 deletions
diff --git a/bgpd/bgp_open.c b/bgpd/bgp_open.c
index 5c9ba89a5..77fb61fbb 100644
--- a/bgpd/bgp_open.c
+++ b/bgpd/bgp_open.c
@@ -1285,59 +1285,52 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
return;
/* MP capability for configured AFI, SAFI */
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++) {
- if (peer->afc[afi][safi]) {
- /* Convert AFI, SAFI to values for packet. */
- bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi,
- &pkt_safi);
-
- peer->afc_adv[afi][safi] = 1;
+ FOREACH_AFI_SAFI (afi, safi) {
+ if (peer->afc[afi][safi]) {
+ /* Convert AFI, SAFI to values for packet. */
+ bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi,
+ &pkt_safi);
+
+ peer->afc_adv[afi][safi] = 1;
+ stream_putc(s, BGP_OPEN_OPT_CAP);
+ stream_putc(s, CAPABILITY_CODE_MP_LEN + 2);
+ stream_putc(s, CAPABILITY_CODE_MP);
+ stream_putc(s, CAPABILITY_CODE_MP_LEN);
+ stream_putw(s, pkt_afi);
+ stream_putc(s, 0);
+ stream_putc(s, pkt_safi);
+
+ /* Extended nexthop capability - currently
+ * supporting RFC-5549 for
+ * Link-Local peering only
+ */
+ if (CHECK_FLAG(peer->flags, PEER_FLAG_CAPABILITY_ENHE)
+ && peer->su.sa.sa_family == AF_INET6
+ && IN6_IS_ADDR_LINKLOCAL(&peer->su.sin6.sin6_addr)
+ && afi == AFI_IP
+ && (safi == SAFI_UNICAST
+ || safi == SAFI_LABELED_UNICAST)) {
+ /* RFC 5549 Extended Next Hop Encoding
+ */
+ SET_FLAG(peer->cap, PEER_CAP_ENHE_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s, CAPABILITY_CODE_MP_LEN + 2);
- stream_putc(s, CAPABILITY_CODE_MP);
- stream_putc(s, CAPABILITY_CODE_MP_LEN);
+ stream_putc(s, CAPABILITY_CODE_ENHE_LEN + 2);
+ stream_putc(s, CAPABILITY_CODE_ENHE);
+ stream_putc(s, CAPABILITY_CODE_ENHE_LEN);
+
+ SET_FLAG(peer->af_cap[AFI_IP][safi],
+ PEER_CAP_ENHE_AF_ADV);
stream_putw(s, pkt_afi);
- stream_putc(s, 0);
- stream_putc(s, pkt_safi);
+ stream_putw(s, pkt_safi);
+ stream_putw(s, afi_int2iana(AFI_IP6));
- /* Extended nexthop capability - currently
- * supporting RFC-5549 for
- * Link-Local peering only
- */
- if (CHECK_FLAG(peer->flags,
- PEER_FLAG_CAPABILITY_ENHE)
- && peer->su.sa.sa_family == AF_INET6
- && IN6_IS_ADDR_LINKLOCAL(
- &peer->su.sin6.sin6_addr)
- && afi == AFI_IP
- && (safi == SAFI_UNICAST
- || safi == SAFI_LABELED_UNICAST)) {
- /* RFC 5549 Extended Next Hop Encoding
- */
- SET_FLAG(peer->cap, PEER_CAP_ENHE_ADV);
- stream_putc(s, BGP_OPEN_OPT_CAP);
- stream_putc(s,
- CAPABILITY_CODE_ENHE_LEN
- + 2);
- stream_putc(s, CAPABILITY_CODE_ENHE);
- stream_putc(s,
- CAPABILITY_CODE_ENHE_LEN);
-
- SET_FLAG(peer->af_cap[AFI_IP][safi],
- PEER_CAP_ENHE_AF_ADV);
- stream_putw(s, pkt_afi);
- stream_putw(s, pkt_safi);
- stream_putw(s, afi_int2iana(AFI_IP6));
-
- if (CHECK_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ENHE_AF_RCV))
- SET_FLAG(
- peer->af_cap[afi][safi],
- PEER_CAP_ENHE_AF_NEGO);
- }
+ if (CHECK_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ENHE_AF_RCV))
+ SET_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ENHE_AF_NEGO);
}
}
+ }
/* Route refresh. */
SET_FLAG(peer->cap, PEER_CAP_REFRESH_ADV);
@@ -1363,21 +1356,20 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
stream_putl(s, local_as);
/* AddPath */
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
- if (peer->afc[afi][safi]) {
- afi_safi_count++;
-
- /* Only advertise addpath TX if a feature that
- * will use it is
- * configured */
- if (CHECK_FLAG(peer->af_flags[afi][safi],
- PEER_FLAG_ADDPATH_TX_ALL_PATHS)
- || CHECK_FLAG(
- peer->af_flags[afi][safi],
- PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
- adv_addpath_tx = 1;
- }
+ FOREACH_AFI_SAFI (afi, safi) {
+ if (peer->afc[afi][safi]) {
+ afi_safi_count++;
+
+ /* Only advertise addpath TX if a feature that
+ * will use it is
+ * configured */
+ if (CHECK_FLAG(peer->af_flags[afi][safi],
+ PEER_FLAG_ADDPATH_TX_ALL_PATHS)
+ || CHECK_FLAG(peer->af_flags[afi][safi],
+ PEER_FLAG_ADDPATH_TX_BESTPATH_PER_AS))
+ adv_addpath_tx = 1;
+ }
+ }
SET_FLAG(peer->cap, PEER_CAP_ADDPATH_ADV);
stream_putc(s, BGP_OPEN_OPT_CAP);
@@ -1385,46 +1377,43 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
stream_putc(s, CAPABILITY_CODE_ADDPATH);
stream_putc(s, CAPABILITY_CODE_ADDPATH_LEN * afi_safi_count);
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
- if (peer->afc[afi][safi]) {
- /* Convert AFI, SAFI to values for packet. */
- bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi,
- &pkt_safi);
+ FOREACH_AFI_SAFI (afi, safi) {
+ if (peer->afc[afi][safi]) {
+ /* Convert AFI, SAFI to values for packet. */
+ bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi,
+ &pkt_safi);
- stream_putw(s, pkt_afi);
- stream_putc(s, pkt_safi);
+ stream_putw(s, pkt_afi);
+ stream_putc(s, pkt_safi);
- if (adv_addpath_tx) {
- stream_putc(s,
- BGP_ADDPATH_RX
- | BGP_ADDPATH_TX);
- SET_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ADDPATH_AF_RX_ADV);
- SET_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ADDPATH_AF_TX_ADV);
- } else {
- stream_putc(s, BGP_ADDPATH_RX);
- SET_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ADDPATH_AF_RX_ADV);
- UNSET_FLAG(peer->af_cap[afi][safi],
- PEER_CAP_ADDPATH_AF_TX_ADV);
- }
+ if (adv_addpath_tx) {
+ stream_putc(s, BGP_ADDPATH_RX | BGP_ADDPATH_TX);
+ SET_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ADDPATH_AF_RX_ADV);
+ SET_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ADDPATH_AF_TX_ADV);
+ } else {
+ stream_putc(s, BGP_ADDPATH_RX);
+ SET_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ADDPATH_AF_RX_ADV);
+ UNSET_FLAG(peer->af_cap[afi][safi],
+ PEER_CAP_ADDPATH_AF_TX_ADV);
}
+ }
+ }
/* ORF capability. */
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
- if (CHECK_FLAG(peer->af_flags[afi][safi],
- PEER_FLAG_ORF_PREFIX_SM)
- || CHECK_FLAG(peer->af_flags[afi][safi],
- PEER_FLAG_ORF_PREFIX_RM)) {
- bgp_open_capability_orf(
- s, peer, afi, safi,
- CAPABILITY_CODE_ORF_OLD);
- bgp_open_capability_orf(s, peer, afi, safi,
- CAPABILITY_CODE_ORF);
- }
+ FOREACH_AFI_SAFI (afi, safi) {
+ if (CHECK_FLAG(peer->af_flags[afi][safi],
+ PEER_FLAG_ORF_PREFIX_SM)
+ || CHECK_FLAG(peer->af_flags[afi][safi],
+ PEER_FLAG_ORF_PREFIX_RM)) {
+ bgp_open_capability_orf(s, peer, afi, safi,
+ CAPABILITY_CODE_ORF_OLD);
+ bgp_open_capability_orf(s, peer, afi, safi,
+ CAPABILITY_CODE_ORF);
+ }
+ }
/* Dynamic capability. */
if (CHECK_FLAG(peer->flags, PEER_FLAG_DYNAMIC_CAPABILITY)) {
@@ -1497,22 +1486,21 @@ void bgp_open_capability(struct stream *s, struct peer *peer)
config
is present */
if (bgp_flag_check(peer->bgp, BGP_FLAG_GRACEFUL_RESTART)) {
- for (afi = AFI_IP; afi < AFI_MAX; afi++)
- for (safi = SAFI_UNICAST; safi < SAFI_MAX; safi++)
- if (peer->afc[afi][safi]) {
- /* Convert AFI, SAFI to values for
- * packet. */
- bgp_map_afi_safi_int2iana(
- afi, safi, &pkt_afi, &pkt_safi);
- stream_putw(s, pkt_afi);
- stream_putc(s, pkt_safi);
- if (bgp_flag_check(
- peer->bgp,
- BGP_FLAG_GR_PRESERVE_FWD))
- stream_putc(s, RESTART_F_BIT);
- else
- stream_putc(s, 0);
- }
+ FOREACH_AFI_SAFI (afi, safi) {
+ if (peer->afc[afi][safi]) {
+ /* Convert AFI, SAFI to values for
+ * packet. */
+ bgp_map_afi_safi_int2iana(afi, safi, &pkt_afi,
+ &pkt_safi);
+ stream_putw(s, pkt_afi);
+ stream_putc(s, pkt_safi);
+ if (bgp_flag_check(peer->bgp,
+ BGP_FLAG_GR_PRESERVE_FWD))
+ stream_putc(s, RESTART_F_BIT);
+ else
+ stream_putc(s, 0);
+ }
+ }
}
/* Total Graceful restart capability Len. */