From e5d4cda0a7bcc0c0ccbd7d6c11dfa63dfa43ff1c Mon Sep 17 00:00:00 2001 From: Hiroki Shirokura Date: Tue, 4 Feb 2020 00:11:29 +0000 Subject: [PATCH] bgpd: fix Prefix-SID parsing failure case Prefix-SID path attribute Label-index TLV (type-1) is used by SR-MPLS. And Label-index TLV MUST ignored if that path attribute is append on non-Labeled-unicast UPDATE message described on [ref1]. There is a problem case exist arround this implementation. This commit fix that. Before this commit, unfortunally, setting Label-Index value is skipped at somecases. because, Label-Index TLV implementation check the AFI/SAFI pair. by mp_update variable that is set by bgp_mp_reach_parse function. if MP_REACH_NLRI is present after PREFIX_SID, bgp_attr_psid_sub function can't understand AFI/SAFI pair. and the order of each path attributes is never no-deterministic thing for receiver.[ref2] In this commit, I re-located checking code of AFI/SAFI pair after path-attr loop. [ref1](https://tools.ietf.org/html/draft-ietf-idr-bgp-prefix-sid-27#section-3.2) > The Originator SRGB TLV may only appear in a BGP Prefix-SID attribute > attached to IPv4/IPv6 Labeled Unicast prefixes ([RFC8277]). It MUST > be ignored when received for other BGP AFI/SAFI combinations. [ref2](https://tools.ietf.org/html/rfc4271#section-5) > The sender of an UPDATE message SHOULD order path attributes within > the UPDATE message in ascending order of attribute type. The > receiver of an UPDATE message MUST be prepared to handle path > attributes within UPDATE messages that are out of order. Signed-off-by: Hiroki Shirokura --- bgpd/bgp_attr.c | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 2bbcade8e8..316cc957c9 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -2382,15 +2382,6 @@ static bgp_attr_parse_ret_t bgp_attr_psid_sub(uint8_t type, uint16_t length, /* Store label index; subsequently, we'll check on * address-family */ attr->label_index = label_index; - - /* - * Ignore the Label index attribute unless received for - * labeled-unicast - * SAFI. - */ - if (!mp_update->length - || mp_update->safi != SAFI_LABELED_UNICAST) - attr->label_index = BGP_INVALID_LABEL_INDEX; } /* Placeholder code for the IPv6 SID type */ @@ -3078,6 +3069,17 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, } } + /* + * draft-ietf-idr-bgp-prefix-sid-27#section-3: + * About Prefix-SID path attribute, + * Label-Index TLV(type1) and The Originator SRGB TLV(type-3) + * may only appear in a BGP Prefix-SID attribute attached to + * IPv4/IPv6 Labeled Unicast prefixes ([RFC8277]). + * It MUST be ignored when received for other BGP AFI/SAFI combinations. + */ + if (!attr->mp_nexthop_len || mp_update->safi != SAFI_LABELED_UNICAST) + attr->label_index = BGP_INVALID_LABEL_INDEX; + /* Check final read pointer is same as end pointer. */ if (BGP_INPUT_PNT(peer) != endp) { flog_warn(EC_BGP_ATTRIBUTES_MISMATCH,