summaryrefslogtreecommitdiffstats
path: root/bgpd/bgp_packet.c
diff options
context:
space:
mode:
Diffstat (limited to 'bgpd/bgp_packet.c')
-rw-r--r--bgpd/bgp_packet.c101
1 files changed, 40 insertions, 61 deletions
diff --git a/bgpd/bgp_packet.c b/bgpd/bgp_packet.c
index dffca37dd..38470a3c7 100644
--- a/bgpd/bgp_packet.c
+++ b/bgpd/bgp_packet.c
@@ -147,6 +147,8 @@ static struct stream *
bgp_update_packet_eor (struct peer *peer, afi_t afi, safi_t safi)
{
struct stream *s;
+ afi_t pkt_afi;
+ safi_t pkt_safi;
if (DISABLE_BGP_ANNOUNCE)
return NULL;
@@ -169,13 +171,16 @@ bgp_update_packet_eor (struct peer *peer, afi_t afi, safi_t safi)
}
else
{
+ /* Convert AFI, SAFI to values for packet. */
+ bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi);
+
/* Total Path Attribute Length */
stream_putw (s, 6);
stream_putc (s, BGP_ATTR_FLAG_OPTIONAL);
stream_putc (s, BGP_ATTR_MP_UNREACH_NLRI);
stream_putc (s, 3);
- stream_putw (s, afi);
- stream_putc (s, (safi == SAFI_MPLS_VPN) ? SAFI_MPLS_LABELED_VPN : safi);
+ stream_putw (s, pkt_afi);
+ stream_putc (s, pkt_safi);
}
bgp_packet_set_size (s);
@@ -690,15 +695,16 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
struct stream *s;
struct bgp_filter *filter;
int orf_refresh = 0;
+ afi_t pkt_afi;
+ safi_t pkt_safi;
if (DISABLE_BGP_ANNOUNCE)
return;
filter = &peer->filter[afi][safi];
- /* Adjust safi code. */
- if (safi == SAFI_MPLS_VPN)
- safi = SAFI_MPLS_LABELED_VPN;
+ /* Convert AFI, SAFI to values for packet. */
+ bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi);
s = stream_new (BGP_MAX_PACKET_SIZE);
@@ -709,9 +715,9 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
bgp_packet_set_marker (s, BGP_MSG_ROUTE_REFRESH_OLD);
/* Encode Route Refresh message. */
- stream_putw (s, afi);
+ stream_putw (s, pkt_afi);
stream_putc (s, 0);
- stream_putc (s, safi);
+ stream_putc (s, pkt_safi);
if (orf_type == ORF_TYPE_PREFIX
|| orf_type == ORF_TYPE_PREFIX_OLD)
@@ -734,7 +740,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
zlog_debug ("%s sending REFRESH_REQ to remove ORF(%d) (%s) for afi/safi: %d/%d",
peer->host, orf_type,
(when_to_refresh == REFRESH_DEFER ? "defer" : "immediate"),
- afi, safi);
+ pkt_afi, pkt_safi);
}
else
{
@@ -746,7 +752,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
zlog_debug ("%s sending REFRESH_REQ with pfxlist ORF(%d) (%s) for afi/safi: %d/%d",
peer->host, orf_type,
(when_to_refresh == REFRESH_DEFER ? "defer" : "immediate"),
- afi, safi);
+ pkt_afi, pkt_safi);
}
/* Total ORF Entry Len. */
@@ -761,7 +767,7 @@ bgp_route_refresh_send (struct peer *peer, afi_t afi, safi_t safi,
{
if (! orf_refresh)
zlog_debug ("%s sending REFRESH_REQ for afi/safi: %d/%d",
- peer->host, afi, safi);
+ peer->host, pkt_afi, pkt_safi);
}
/* Add packet to the peer. */
@@ -776,10 +782,11 @@ bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi,
int capability_code, int action)
{
struct stream *s;
+ afi_t pkt_afi;
+ safi_t pkt_safi;
- /* Adjust safi code. */
- if (safi == SAFI_MPLS_VPN)
- safi = SAFI_MPLS_LABELED_VPN;
+ /* Convert AFI, SAFI to values for packet. */
+ bgp_map_afi_safi_int2iana (afi, safi, &pkt_afi, &pkt_safi);
s = stream_new (BGP_MAX_PACKET_SIZE);
@@ -792,14 +799,14 @@ bgp_capability_send (struct peer *peer, afi_t afi, safi_t safi,
stream_putc (s, action);
stream_putc (s, CAPABILITY_CODE_MP);
stream_putc (s, CAPABILITY_CODE_MP_LEN);
- stream_putw (s, afi);
+ stream_putw (s, pkt_afi);
stream_putc (s, 0);
- stream_putc (s, safi);
+ stream_putc (s, pkt_safi);
if (bgp_debug_neighbor_events(peer))
zlog_debug ("%s sending CAPABILITY has %s MP_EXT CAP for afi/safi: %d/%d",
peer->host, action == CAPABILITY_ACTION_SET ?
- "Advertising" : "Removing", afi, safi);
+ "Advertising" : "Removing", pkt_afi, pkt_safi);
}
/* Set packet size. */
@@ -1329,7 +1336,6 @@ bgp_nlri_parse (struct peer *peer, struct attr *attr, struct bgp_nlri *packet)
case SAFI_MULTICAST:
return bgp_nlri_parse_ip (peer, attr, packet);
case SAFI_MPLS_VPN:
- case SAFI_MPLS_LABELED_VPN:
return bgp_nlri_parse_vpn (peer, attr, packet);
case SAFI_ENCAP:
return bgp_nlri_parse_encap (peer, attr, packet);
@@ -1508,26 +1514,6 @@ bgp_update_receive (struct peer *peer, bgp_size_t size)
if (!nlris[i].nlri)
continue;
- /* We use afi and safi as indices into tables and what not. It would
- * be impossible, at this time, to support unknown afi/safis. And
- * anyway, the peer needs to be configured to enable the afi/safi
- * explicitly which requires UI support.
- *
- * Ignore unknown afi/safi NLRIs.
- *
- * Note: This means nlri[x].afi/safi still can not be trusted for
- * indexing later in this function!
- *
- * Note2: This will also remap the wire code-point for VPN safi to the
- * internal safi_t point, as needs be.
- */
- if(!bgp_afi_safi_valid_indices (nlris[i].afi, &nlris[i].safi))
- {
- zlog_info ("%s [Info] UPDATE with unsupported AFI/SAFI %u/%u",
- peer->host, nlris[i].afi, nlris[i].safi);
- continue;
- }
-
/* NLRI is processed iff the peer if configured for the specific afi/safi */
if (!peer->afc[nlris[i].afi][nlris[i].safi])
{
@@ -1586,9 +1572,7 @@ bgp_update_receive (struct peer *peer, bgp_size_t size)
safi = SAFI_UNICAST;
}
else if (attr.flag & ATTR_FLAG_BIT (BGP_ATTR_MP_UNREACH_NLRI)
- && nlris[NLRI_MP_WITHDRAW].length == 0
- && bgp_afi_safi_valid_indices (nlris[NLRI_MP_WITHDRAW].afi,
- &nlris[NLRI_MP_WITHDRAW].safi))
+ && nlris[NLRI_MP_WITHDRAW].length == 0)
{
afi = nlris[NLRI_MP_WITHDRAW].afi;
safi = nlris[NLRI_MP_WITHDRAW].safi;
@@ -1727,8 +1711,8 @@ bgp_keepalive_receive (struct peer *peer, bgp_size_t size)
static void
bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
{
- afi_t afi;
- safi_t safi;
+ afi_t pkt_afi, afi;
+ safi_t pkt_safi, safi;
struct stream *s;
struct peer_af *paf;
struct update_group *updgrp;
@@ -1757,28 +1741,22 @@ bgp_route_refresh_receive (struct peer *peer, bgp_size_t size)
s = peer->ibuf;
/* Parse packet. */
- afi = stream_getw (s);
+ pkt_afi = stream_getw (s);
(void)stream_getc (s);
- safi = stream_getc (s);
+ pkt_safi = stream_getc (s);
if (bgp_debug_update(peer, NULL, NULL, 0))
zlog_debug ("%s rcvd REFRESH_REQ for afi/safi: %d/%d",
- peer->host, afi, safi);
+ peer->host, pkt_afi, pkt_safi);
- /* Check AFI and SAFI. */
- if ((afi != AFI_IP && afi != AFI_IP6)
- || (safi != SAFI_UNICAST && safi != SAFI_MULTICAST
- && safi != SAFI_MPLS_LABELED_VPN))
+ /* Convert AFI, SAFI to internal values and check. */
+ if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi))
{
zlog_info ("%s REFRESH_REQ for unrecognized afi/safi: %d/%d - ignored",
- peer->host, afi, safi);
+ peer->host, pkt_afi, pkt_safi);
return;
}
- /* Adjust safi code. */
- if (safi == SAFI_MPLS_LABELED_VPN)
- safi = SAFI_MPLS_VPN;
-
if (size != BGP_MSG_ROUTE_REFRESH_MIN_SIZE - BGP_HEADER_SIZE)
{
u_char *end;
@@ -1954,8 +1932,8 @@ bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length)
struct capability_mp_data mpc;
struct capability_header *hdr;
u_char action;
- afi_t afi;
- safi_t safi;
+ afi_t pkt_afi, afi;
+ safi_t pkt_safi, safi;
end = pnt + length;
@@ -1999,18 +1977,19 @@ bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length)
/* We know MP Capability Code. */
if (hdr->code == CAPABILITY_CODE_MP)
{
- afi = ntohs (mpc.afi);
- safi = mpc.safi;
+ pkt_afi = ntohs (mpc.afi);
+ pkt_safi = mpc.safi;
/* Ignore capability when override-capability is set. */
if (CHECK_FLAG (peer->flags, PEER_FLAG_OVERRIDE_CAPABILITY))
continue;
- if (!bgp_afi_safi_valid_indices (afi, &safi))
+ /* Convert AFI, SAFI to internal values. */
+ if (bgp_map_afi_safi_iana2int (pkt_afi, pkt_safi, &afi, &safi))
{
if (bgp_debug_neighbor_events(peer))
zlog_debug ("%s Dynamic Capability MP_EXT afi/safi invalid "
- "(%u/%u)", peer->host, afi, safi);
+ "(%u/%u)", peer->host, pkt_afi, pkt_safi);
continue;
}
@@ -2020,7 +1999,7 @@ bgp_capability_msg_parse (struct peer *peer, u_char *pnt, bgp_size_t length)
peer->host,
action == CAPABILITY_ACTION_SET
? "Advertising" : "Removing",
- ntohs(mpc.afi) , mpc.safi);
+ pkt_afi, pkt_safi);
if (action == CAPABILITY_ACTION_SET)
{