diff options
Diffstat (limited to 'bgpd/bgp_attr.c')
| -rw-r--r-- | bgpd/bgp_attr.c | 48 |
1 files changed, 19 insertions, 29 deletions
diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 2f0751a5f0..0870748f7e 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1497,8 +1497,10 @@ static int bgp_attr_aspath(struct bgp_attr_parser_args *args) * peer with AS4 => will get 4Byte ASnums * otherwise, will get 16 Bit */ - attr->aspath = aspath_parse(peer->curr, length, - CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV)); + attr->aspath = aspath_parse( + peer->curr, length, + CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV) + && CHECK_FLAG(peer->cap, PEER_CAP_AS4_ADV)); /* In case of IBGP, length will be zero. */ if (!attr->aspath) { @@ -1509,16 +1511,6 @@ static int bgp_attr_aspath(struct bgp_attr_parser_args *args) 0); } - /* Codification of AS 0 Processing */ - if (aspath_check_as_zero(attr->aspath)) { - flog_err( - EC_BGP_ATTR_MAL_AS_PATH, - "Malformed AS path, AS number is 0 in the path from %s", - peer->host); - return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, - 0); - } - /* Set aspath attribute flag. */ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS_PATH); @@ -1558,6 +1550,15 @@ static bgp_attr_parse_ret_t bgp_attr_aspath_check(struct peer *const peer, } } + /* Codification of AS 0 Processing */ + if (peer->sort == BGP_PEER_EBGP && aspath_check_as_zero(attr->aspath)) { + flog_err( + EC_BGP_ATTR_MAL_AS_PATH, + "Malformed AS path, AS number is 0 in the path from %s", + peer->host); + return BGP_ATTR_PARSE_WITHDRAW; + } + /* local-as prepend */ if (peer->change_local_as && !CHECK_FLAG(peer->flags, PEER_FLAG_LOCAL_AS_NO_PREPEND)) { @@ -1590,16 +1591,6 @@ static int bgp_attr_as4_path(struct bgp_attr_parser_args *args, 0); } - /* Codification of AS 0 Processing */ - if (aspath_check_as_zero(*as4_path)) { - flog_err( - EC_BGP_ATTR_MAL_AS_PATH, - "Malformed AS path, AS number is 0 in the path from %s", - peer->host); - return bgp_attr_malformed(args, BGP_NOTIFY_UPDATE_MAL_AS_PATH, - 0); - } - /* Set aspath attribute flag. */ attr->flag |= ATTR_FLAG_BIT(BGP_ATTR_AS4_PATH); @@ -2926,11 +2917,8 @@ static bgp_attr_parse_ret_t bgp_attr_unknown(struct bgp_attr_parser_args *args) if (!transit) transit = XCALLOC(MTYPE_TRANSIT, sizeof(struct transit)); - if (transit->val) - transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val, - transit->length + total); - else - transit->val = XMALLOC(MTYPE_TRANSIT_VAL, total); + transit->val = XREALLOC(MTYPE_TRANSIT_VAL, transit->val, + transit->length + total); memcpy(transit->val + transit->length, startp, total); transit->length += total; @@ -3317,7 +3305,8 @@ bgp_attr_parse_ret_t bgp_attr_parse(struct peer *peer, struct attr *attr, } /* Check all mandatory well-known attributes are present */ - if ((ret = bgp_attr_check(peer, attr)) < 0) + ret = bgp_attr_check(peer, attr); + if (ret < 0) goto done; /* @@ -3758,7 +3747,8 @@ bgp_size_t bgp_packet_attribute(struct bgp *bgp, struct peer *peer, struct aspath *aspath; int send_as4_path = 0; int send_as4_aggregator = 0; - bool use32bit = CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV); + bool use32bit = CHECK_FLAG(peer->cap, PEER_CAP_AS4_RCV) + && CHECK_FLAG(peer->cap, PEER_CAP_AS4_ADV); if (!bgp) bgp = peer->bgp; |
