lib: remove SAFI_RESERVED_4 and SAFI_RESERVED_5

SAFI values have been a major source of confusion over the last few
years. That's because each SAFI needs to be represented in two different
ways:
* IANA's value used to send/receive packets over the network;
* Internal value used for array indexing.

In the second case, defining reserved values makes no sense because we
don't want to index SAFIs that simply don't exist. The sole purpose of
the internal SAFI values is to remove the gaps we have among the IANA
values, which would represent wasted memory in C arrays. With that said,
remove these reserved SAFIs to avoid further confusion in the future.

Signed-off-by: Renato Westphal <renato@opensourcerouting.org>
This commit is contained in:
Renato Westphal 2017-07-31 21:09:01 -03:00
parent 84d5286a9f
commit a08ca0a7e1
4 changed files with 10 additions and 24 deletions

View File

@ -488,7 +488,7 @@ static int bgp_graceful_restart_timer_expire(struct thread *thread)
/* NSF delete stale route */
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
if (peer->nsf[afi][safi])
bgp_clear_stale_route(peer, afi, safi);
@ -521,7 +521,7 @@ static int bgp_graceful_stale_timer_expire(struct thread *thread)
/* NSF delete stale route */
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
if (peer->nsf[afi][safi])
bgp_clear_stale_route(peer, afi, safi);
@ -1022,7 +1022,7 @@ int bgp_stop(struct peer *peer)
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST;
safi < SAFI_RESERVED_4; safi++)
safi <= SAFI_MPLS_VPN; safi++)
peer->nsf[afi][safi] = 0;
}
@ -1425,7 +1425,7 @@ static int bgp_establish(struct peer *peer)
/* graceful restart */
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_WAIT);
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++) {
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++) {
if (peer->afc_nego[afi][safi]
&& CHECK_FLAG(peer->cap, PEER_CAP_RESTART_ADV)
&& CHECK_FLAG(peer->af_cap[afi][safi],

View File

@ -7079,12 +7079,6 @@ static void bgp_show_summary_afi_safi(struct vty *vty, struct bgp *bgp, int afi,
json);
}
safi++;
if (safi == SAFI_RESERVED_4
|| safi
== SAFI_RESERVED_5) /* handle special
cases to match
zebra.h */
safi++;
if (!safi_wildcard)
safi = SAFI_MAX;
}

View File

@ -1842,7 +1842,7 @@ static void peer_nsf_stop(struct peer *peer)
UNSET_FLAG(peer->sflags, PEER_STATUS_NSF_MODE);
for (afi = AFI_IP; afi < AFI_MAX; afi++)
for (safi = SAFI_UNICAST; safi < SAFI_RESERVED_4; safi++)
for (safi = SAFI_UNICAST; safi <= SAFI_MPLS_VPN; safi++)
peer->nsf[afi][safi] = 0;
if (peer->t_gr_restart) {

View File

@ -419,19 +419,10 @@ typedef enum { AFI_IP = 1, AFI_IP6 = 2, AFI_L2VPN = 3, AFI_MAX = 4 } afi_t;
#define SAFI_UNICAST 1
#define SAFI_MULTICAST 2
#define SAFI_MPLS_VPN 3
#define SAFI_RESERVED_4 4
#define SAFI_ENCAP 5
#define SAFI_RESERVED_5 5
#define SAFI_EVPN 6
#define SAFI_LABELED_UNICAST 7
#define SAFI_MAX 8
#define IANA_SAFI_RESERVED 0
#define IANA_SAFI_UNICAST 1
#define IANA_SAFI_MULTICAST 2
#define IANA_SAFI_LABELED_UNICAST 4
#define IANA_SAFI_ENCAP 7
#define IANA_SAFI_MPLS_VPN 128
#define SAFI_ENCAP 4
#define SAFI_EVPN 5
#define SAFI_LABELED_UNICAST 6
#define SAFI_MAX 7
/*
* The above AFI and SAFI definitions are for internal use. The protocol
@ -454,6 +445,7 @@ typedef enum {
#define IANA_SAFI_RESERVED 0
#define IANA_SAFI_UNICAST 1
#define IANA_SAFI_MULTICAST 2
#define IANA_SAFI_LABELED_UNICAST 4
#define IANA_SAFI_ENCAP 7
#define IANA_SAFI_EVPN 70
#define IANA_SAFI_MPLS_VPN 128