From 88cc0ce4e8f5eaabb4f9829c987d8a4675941096 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Tue, 29 Jun 2021 16:10:50 +0300 Subject: [PATCH] bgpd: Parse as withdrawal if AS-PATH contains 0 within the path Process this a bit later instead of bgp_attr_parse() which is causing the session to be shutdown upon receiving a prefix with AS number 0 inside. Signed-off-by: Donatas Abraitis --- bgpd/bgp_attr.c | 29 +++++++++-------------------- 1 file changed, 9 insertions(+), 20 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index 2f0751a5f0..3a2cb4c10b 100644 --- a/bgpd/bgp_attr.c +++ b/bgpd/bgp_attr.c @@ -1509,16 +1509,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 +1548,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 +1589,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); -- 2.39.5