From 8cff42add5fe8f2b7f5d606c455859568a37e9d9 Mon Sep 17 00:00:00 2001 From: Donatas Abraitis Date: Sun, 1 Aug 2021 09:29:31 +0300 Subject: [PATCH] bgpd: Use strict AS4 capability when processing parsing/generating pkts PeerA sets `dont-capability-negotiate` for PeerB. It does not send any capabilities to PeerB. This leads to situation when PeerA received AS4 cap, while it doesn't send AS4 to PeerB and tries parsing AS_PATH using 32bits. [GTTPK-RX2GP][EC 33554436] Malformed AS path from 192.168.0.2, length is 4 [SM0KX-WXMGK] bgp_attr_malformed: attributes: , origin ? [P7TRR-4J6XT][EC 33554487] 192.168.0.2: Attribute AS_PATH, parse error - treating as withdrawal [WX70K-6XXVF][EC 33554454] 192.168.0.2 rcvd UPDATE with errors in attr(s)!! Withdrawing route. [Z2KFR-ZGJC8] 192.168.0.2 rcvd UPDATE w/ attr: , origin ? [P9VY3-5B6NX] 192.168.0.2 rcvd UPDATE wlen 0 attrlen 80 alen 73 [QMZ79-K2DH7][EC 33554454] 192.168.0.2 [Error] Update packet error (wrong prefix length 64 for afi 1) [P9SYB-54XRZ][EC 33554454] 192.168.0.2 [Error] Error parsing NLRI [V1CHF-JSGRR] %NOTIFICATION: sent to neighbor 192.168.0.2 3/10 (UPDATE Message Error/Invalid Network Field) 0 bytes [HTHRX-GQYGJ][EC 33554454] bgp_process_packet: BGP UPDATE receipt failed for peer: 192.168.0.2 Signed-off-by: Donatas Abraitis --- bgpd/bgp_attr.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/bgpd/bgp_attr.c b/bgpd/bgp_attr.c index adf408220e..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) { @@ -3745,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; -- 2.39.5