Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions scapy/contrib/bgp.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you use a bind_layers instead? Thanks



#
# ORIGINATOR_ID
Expand Down
14 changes: 14 additions & 0 deletions test/contrib/bgp.uts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down