From 1c0b71699e1ed7c325a038cd69affba9b8b345b2 Mon Sep 17 00:00:00 2001 From: atg06 <106623568+atg06@users.noreply.github.com> Date: Sun, 25 Oct 2026 20:22:40 +0300 Subject: [PATCH] bgp: dissect every community in a COMMUNITIES attribute The COMMUNITIES path attribute (RFC 1997) holds a list of 4-byte values, but BGPPACommunity only dissected the first one and left the others as Raw. Chain the remaining communities as BGPPACommunity layers. Fixes #4071 AI-Assisted: yes (Claude Opus 5.5) Co-Authored-By: Claude Opus 5.5 --- scapy/contrib/bgp.py | 4 ++++ test/contrib/bgp.uts | 14 ++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/scapy/contrib/bgp.py b/scapy/contrib/bgp.py index a3846e6e1a1..6fb92c2ba91 100644 --- a/scapy/contrib/bgp.py +++ b/scapy/contrib/bgp.py @@ -1370,6 +1370,10 @@ class BGPPACommunity(Packet): name = "COMMUNITIES" fields_desc = [IntEnumField("community", 0, well_known_communities)] + def default_payload_class(self, payload): + # The attribute value is a list of 4-byte communities + return BGPPACommunity + # # ORIGINATOR_ID diff --git a/test/contrib/bgp.uts b/test/contrib/bgp.uts index f954760afee..b3608cec3f2 100644 --- a/test/contrib/bgp.uts +++ b/test/contrib/bgp.uts @@ -538,6 +538,20 @@ raw(BGPPACommunity(community = 0xFFFFFF01)) == b'\xff\xff\xff\x01' a = BGPPACommunity(b'\xff\xff\xff\x01') a.community == 0xFFFFFF01 += BGPPACommunity - Dissection of multiple communities (RFC 1997) +a = BGPPathAttr(b'\xc0\x08\x0c\xfc\x00\x00\x0b\xfc\x00\x00\x15\xff\xff\xff\x01') +a.attr_len == 12 +a.attribute.community == 0xFC00000B +a.attribute.payload.community == 0xFC000015 +a.attribute.payload.payload.community == 0xFFFFFF01 +not a.haslayer(Raw) + += BGPPACommunity - Build and dissect multiple communities +a = BGPPathAttr(type_flags=0xc0, type_code=8, attribute=BGPPACommunity(community=0xFC00000B) / BGPPACommunity(community=0xFFFFFF01)) +assert raw(a) == b'\xc0\x08\x08\xfc\x00\x00\x0b\xff\xff\xff\x01' +a = BGPPathAttr(raw(a)) +a.attribute.payload.community == 0xFFFFFF01 + ############################ BGPPAOriginatorID ############################### + BGPPAOriginatorID class tests