scapy.contrib.bgp

BGP (Border Gateway Protocol).

class scapy.contrib.bgp.ASPathSegmentPacketListField(name: str, default: Optional[List[BasePacket]], pkt_cls: Optional[Union[Callable[[bytes], Packet], Type[Packet]]]  # noqa: E501 = None, count_from: Optional[Callable[[Packet], int]] = None, length_from: Optional[Callable[[Packet], int]] = None, next_cls_cb: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]]  # noqa: E501 = None, max_count: Optional[int] = None)[source]

Bases: PacketListField

PacketListField handling AS_PATH segments.

getfield(pkt, s)[source]
class scapy.contrib.bgp.BGP(_pkt, /)[source]

Bases: Packet

Every BGP message inherits from this class.

KEEPALIVE_TYPE = 4
NOTIFICATION_TYPE = 3
OPEN_TYPE = 1
ROUTEREFRESH_TYPE = 5
UPDATE_TYPE = 2
aliastypes = [<class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
classmethod dispatch_hook(_pkt=None, *args, **kargs)[source]

Returns the right class for the given data.

guess_payload_class(p)[source]
classmethod tcp_reassemble(data, *args, **kwargs)[source]
class scapy.contrib.bgp.BGPAuthenticationInformation(_pkt, /, *, authentication_code=0, authentication_data=None)[source]

Bases: Packet

Provides an implementation of the Authentication Information optional parameter, which is now obsolete. References: RFC 1771, RFC 1654, RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPAuthenticationInformation'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteField (BGPAuthenticationInformation).authentication_code>, <StrField (BGPAuthenticationInformation).authentication_data>]
class scapy.contrib.bgp.BGPCapFourBytesASN(_pkt, /, *, code=65, length=4, asn=0)[source]

Bases: BGPCapability

This class provides an implementation of the 4-octet AS number capability. References: RFC 4893

aliastypes = [<class 'scapy.contrib.bgp.BGPCapFourBytesASN'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPCapFourBytesASN).code>, <ByteField (BGPCapFourBytesASN).length>, <IntField (BGPCapFourBytesASN).asn>]
match_subclass = True
class scapy.contrib.bgp.BGPCapGeneric(_pkt, /, *, code=0, length=None, cap_data=b'')[source]

Bases: BGPCapability

This class provides an implementation of a generic capability.

aliastypes = [<class 'scapy.contrib.bgp.BGPCapGeneric'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPCapGeneric).code>, <FieldLenField (BGPCapGeneric).length>, <StrLenField (BGPCapGeneric).cap_data>]
match_subclass = True
class scapy.contrib.bgp.BGPCapGracefulRestart(_pkt, /, *, code=64, length=None, restart_flags=0, restart_time=0, entries=[])[source]

Bases: BGPCapability

This class provides an implementation of the Graceful Restart capability. References: RFC 4724

class GRTuple(_pkt, /, *, afi=0, safi=0, flags=0)[source]

Bases: Packet

Tuple <AFI, SAFI, Flags for address family>

aliastypes = [<class 'scapy.contrib.bgp.BGPCapGracefulRestart.GRTuple'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortEnumField (GRTuple).afi>, <ByteEnumField (GRTuple).safi>, <ByteEnumField (GRTuple).flags>]
aliastypes = [<class 'scapy.contrib.bgp.BGPCapGracefulRestart'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPCapGracefulRestart).code>, <ByteField (BGPCapGracefulRestart).length>, <BitField (BGPCapGracefulRestart).restart_flags>, <BitField (BGPCapGracefulRestart).restart_time>, <PacketListField (BGPCapGracefulRestart).entries>]
match_subclass = True
class scapy.contrib.bgp.BGPCapMultiprotocol(_pkt, /, *, code=1, length=4, afi=0, reserved=0, safi=0)[source]

Bases: BGPCapability

This class provides an implementation of the Multiprotocol capability. References: RFC 4760

aliastypes = [<class 'scapy.contrib.bgp.BGPCapMultiprotocol'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPCapMultiprotocol).code>, <ByteField (BGPCapMultiprotocol).length>, <ShortEnumField (BGPCapMultiprotocol).afi>, <ByteField (BGPCapMultiprotocol).reserved>, <ByteEnumField (BGPCapMultiprotocol).safi>]
match_subclass = True
class scapy.contrib.bgp.BGPCapORF(_pkt, /, *, code=3, length=None, orf=[])[source]

Bases: BGPCapability

This class provides an implementation of the Outbound Route Filtering capability. References: RFC 5291

aliastypes = [<class 'scapy.contrib.bgp.BGPCapORF'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPCapORF).code>, <ByteField (BGPCapORF).length>, <BGPCapORFBlockPacketListField (BGPCapORF).orf>]
match_subclass = True
class scapy.contrib.bgp.BGPCapORFBlock(_pkt, /, *, afi=0, reserved=0, safi=0, orf_number=None, entries=[])[source]

Bases: Packet

The “ORFBlock” is made of <AFI, rsvd, SAFI, Number of ORFs, and <ORF Type, Send/Receive> entries.

class ORFTuple(_pkt, /, *, orf_type=0, send_receive=0)[source]

Bases: Packet

Packet handling <ORF Types, Send/Receive> tuples.

aliastypes = [<class 'scapy.contrib.bgp.BGPCapORFBlock.ORFTuple'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (ORFTuple).orf_type>, <ByteEnumField (ORFTuple).send_receive>]
aliastypes = [<class 'scapy.contrib.bgp.BGPCapORFBlock'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortEnumField (BGPCapORFBlock).afi>, <ByteField (BGPCapORFBlock).reserved>, <ByteEnumField (BGPCapORFBlock).safi>, <FieldLenField (BGPCapORFBlock).orf_number>, <PacketListField (BGPCapORFBlock).entries>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPCapORFBlockPacketListField(name: str, default: Optional[List[BasePacket]], pkt_cls: Optional[Union[Callable[[bytes], Packet], Type[Packet]]]  # noqa: E501 = None, count_from: Optional[Callable[[Packet], int]] = None, length_from: Optional[Callable[[Packet], int]] = None, next_cls_cb: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]]  # noqa: E501 = None, max_count: Optional[int] = None)[source]

Bases: PacketListField

Handles lists of BGPCapORFBlocks.

getfield(pkt, s)[source]
class scapy.contrib.bgp.BGPCapability(_pkt, /)[source]

Bases: Packet

Generic BGP capability.

aliastypes = [<class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
classmethod dispatch_hook(_pkt=None, *args, **kargs)[source]

Returns the right class for the given data.

post_build(p, pay)[source]
pre_dissect(s)[source]

Check that the payload is long enough (at least 2 bytes).

class scapy.contrib.bgp.BGPConf[source]

Bases: ConfClass

BGP module configuration.

use_2_bytes_asn = True
class scapy.contrib.bgp.BGPFieldIPv4(name: str, default: Any, fmt: str = 'H')[source]

Bases: Field

IPv4 Field (CIDR)

addfield(pkt, s, val)[source]
getfield(pkt, s)[source]
h2i(pkt, h)[source]

x.x.x.x/y to “internal” representation.

i2h(pkt, i)[source]

“Internal” representation to “human” representation (x.x.x.x/y).

i2len(pkt, i)[source]
i2m(pkt, i)[source]

“Internal” (IP as bytes, mask as int) to “machine” representation.

i2repr(pkt, i)[source]
m2i(pkt, m)[source]
mask2iplen(mask)[source]

Get the IP field mask length (in bytes).

class scapy.contrib.bgp.BGPFieldIPv6(name: str, default: Any, fmt: str = 'H')[source]

Bases: Field

IPv6 Field (CIDR)

addfield(pkt, s, val)[source]
getfield(pkt, s)[source]
h2i(pkt, h)[source]

x.x.x.x/y to internal representation.

i2h(pkt, i)[source]

“Internal” representation to “human” representation.

i2len(pkt, i)[source]
i2m(pkt, i)[source]

“Internal” (IP as bytes, mask as int) to “machine” representation.

i2repr(pkt, i)[source]
m2i(pkt, m)[source]
mask2iplen(mask)[source]

Get the IP field mask length (in bytes).

class scapy.contrib.bgp.BGPHeader(_pkt, /, *, marker=340282366920938463463374607431768211455, len=None, type=4)[source]

Bases: Packet

The header of any BGP message. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPHeader'>, <class 'scapy.packet.Packet'>]
classmethod dispatch_hook(_pkt=None, *args, **kargs)[source]

Returns the right class for the given data.

fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<XBitField (BGPHeader,BGPKeepAlive).marker>, <ShortField (BGPHeader,BGPKeepAlive).len>, <ByteEnumField (BGPHeader,BGPKeepAlive).type>]
guess_payload_class(payload)[source]
payload_guess: List[Tuple[Dict[str, Any], Type[Packet]]] = [({'type': 1}, <class 'scapy.contrib.bgp.BGPOpen'>), ({'type': 2}, <class 'scapy.contrib.bgp.BGPUpdate'>), ({'type': 3}, <class 'scapy.contrib.bgp.BGPNotification'>), ({'type': 4}, <class 'scapy.contrib.bgp.BGPKeepAlive'>), ({'type': 5}, <class 'scapy.contrib.bgp.BGPRouteRefresh'>)]
post_build(p, pay)[source]
classmethod tcp_reassemble(data, *args, **kwargs)[source]
class scapy.contrib.bgp.BGPKeepAlive(_pkt, /, *, marker=340282366920938463463374607431768211455, len=None, type=4)[source]

Bases: BGP, BGPHeader

KEEPALIVE message.

aliastypes = [<class 'scapy.contrib.bgp.BGPKeepAlive'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
class scapy.contrib.bgp.BGPLargeCommunitySegment(_pkt, /, *, global_administrator=None, local_data_part1=None, local_data_part2=None)[source]

Bases: Packet

Provides an implementation for LARGE_COMMUNITY segments which holds 3*4 bytes integers.

aliastypes = [<class 'scapy.contrib.bgp.BGPLargeCommunitySegment'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPLargeCommunitySegment).global_administrator>, <IntField (BGPLargeCommunitySegment).local_data_part1>, <IntField (BGPLargeCommunitySegment).local_data_part2>]
class scapy.contrib.bgp.BGPNLRIPacketListField(name, default, ip_mode, **kwargs)[source]

Bases: PacketListField

PacketListField handling NLRI fields.

cls_group
getfield(pkt, s)[source]
max_bit_length
no_length
class scapy.contrib.bgp.BGPNLRI_IPv4(_pkt, /, *, prefix=(0, '0.0.0.0'))[source]

Bases: Packet

Packet handling IPv4 NLRI fields.

aliastypes = [<class 'scapy.contrib.bgp.BGPNLRI_IPv4'>, <class 'scapy.packet.Packet'>]
default_payload_class(payload)[source]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BGPFieldIPv4 (BGPNLRI_IPv4).prefix>]
class scapy.contrib.bgp.BGPNLRI_IPv4_AP(_pkt, /, *, nlri_path_id=0, prefix=(0, '0.0.0.0'))[source]

Bases: BGPNLRI_IPv4

Packet handling IPv4 NLRI fields WITH BGP ADDITIONAL PATH

aliastypes = [<class 'scapy.contrib.bgp.BGPNLRI_IPv4_AP'>, <class 'scapy.contrib.bgp.BGPNLRI_IPv4'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPNLRI_IPv4_AP).nlri_path_id>, <BGPFieldIPv4 (BGPNLRI_IPv4_AP).prefix>]
class scapy.contrib.bgp.BGPNLRI_IPv6(_pkt, /, *, prefix=(0, '::'))[source]

Bases: Packet

Packet handling IPv6 NLRI fields.

aliastypes = [<class 'scapy.contrib.bgp.BGPNLRI_IPv6'>, <class 'scapy.packet.Packet'>]
default_payload_class(payload)[source]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BGPFieldIPv6 (BGPNLRI_IPv6).prefix>]
class scapy.contrib.bgp.BGPNLRI_IPv6_AP(_pkt, /, *, nlri_path_id=0, prefix=(0, '::'))[source]

Bases: BGPNLRI_IPv6

Packet handling IPv6 NLRI fields WITH BGP ADDITIONAL PATH

aliastypes = [<class 'scapy.contrib.bgp.BGPNLRI_IPv6_AP'>, <class 'scapy.contrib.bgp.BGPNLRI_IPv6'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPNLRI_IPv6_AP).nlri_path_id>, <BGPFieldIPv6 (BGPNLRI_IPv6_AP).prefix>]
class scapy.contrib.bgp.BGPNotification(_pkt, /, *, error_code=0, error_subcode=0, data=None)[source]

Bases: BGP

NOTIFICATION messages end a BGP session. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPNotification'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPNotification).error_code>, <MultiEnumField (BGPNotification).error_subcode>, <StrField (BGPNotification).data>]
class scapy.contrib.bgp.BGPORF(_pkt, /, *, when_to_refresh=0, orf_type=0, orf_len=None, entries=[])[source]

Bases: Packet

Provides an implementation of ORFs carried in the RR message. References: RFC 5291

aliastypes = [<class 'scapy.contrib.bgp.BGPORF'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPORF).when_to_refresh>, <ByteEnumField (BGPORF).orf_type>, <FieldLenField (BGPORF).orf_len>, <BGPORFEntryPacketListField (BGPORF).entries>]
class scapy.contrib.bgp.BGPORFAddressPrefix(_pkt, /, *, action=0, match=0, reserved=0, sequence=0, min_len=0, max_len=0, prefix=b'')[source]

Bases: BGPORFEntry

Provides an implementation of the Address Prefix ORF (RFC 5292).

aliastypes = [<class 'scapy.contrib.bgp.BGPORFAddressPrefix'>, <class 'scapy.contrib.bgp.BGPORFEntry'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BitEnumField (BGPORFAddressPrefix).action>, <BitEnumField (BGPORFAddressPrefix).match>, <BitField (BGPORFAddressPrefix).reserved>, <IntField (BGPORFAddressPrefix).sequence>, <ByteField (BGPORFAddressPrefix).min_len>, <ByteField (BGPORFAddressPrefix).max_len>, <_ORFNLRIPacketField (BGPORFAddressPrefix).prefix>]
class scapy.contrib.bgp.BGPORFCoveringPrefix(_pkt, /, *, action=0, match=0, reserved=0, sequence=0, min_len=0, max_len=0, rt=0, import_rt=0, route_type=0, host_addr=None)[source]

Bases: BGPORFEntry

Provides an implementation of the CP-ORF (RFC 7543).

aliastypes = [<class 'scapy.contrib.bgp.BGPORFCoveringPrefix'>, <class 'scapy.contrib.bgp.BGPORFEntry'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BitEnumField (BGPORFCoveringPrefix).action>, <BitEnumField (BGPORFCoveringPrefix).match>, <BitField (BGPORFCoveringPrefix).reserved>, <IntField (BGPORFCoveringPrefix).sequence>, <ByteField (BGPORFCoveringPrefix).min_len>, <ByteField (BGPORFCoveringPrefix).max_len>, <LongField (BGPORFCoveringPrefix).rt>, <LongField (BGPORFCoveringPrefix).import_rt>, <ByteField (BGPORFCoveringPrefix).route_type>, <PacketField (BGPORFCoveringPrefix).host_addr>]
class scapy.contrib.bgp.BGPORFEntry(_pkt, /, *, action=0, match=0, reserved=0, value=b'')[source]

Bases: Packet

Provides an implementation of an ORF entry. References: RFC 5291

afi
aliastypes = [<class 'scapy.contrib.bgp.BGPORFEntry'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BitEnumField (BGPORFEntry).action>, <BitEnumField (BGPORFEntry).match>, <BitField (BGPORFEntry).reserved>, <StrField (BGPORFEntry).value>]
safi
class scapy.contrib.bgp.BGPORFEntryPacketListField(name: str, default: Optional[List[BasePacket]], pkt_cls: Optional[Union[Callable[[bytes], Packet], Type[Packet]]]  # noqa: E501 = None, count_from: Optional[Callable[[Packet], int]] = None, length_from: Optional[Callable[[Packet], int]] = None, next_cls_cb: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]]  # noqa: E501 = None, max_count: Optional[int] = None)[source]

Bases: PacketListField

PacketListField handling the ORF entries.

getfield(pkt, s)[source]
m2i(pkt, m)[source]
class scapy.contrib.bgp.BGPOpen(_pkt, /, *, version=4, my_as=0, hold_time=0, bgp_id='0.0.0.0', opt_param_len=None, opt_params=[])[source]

Bases: BGP

OPEN messages are exchanged in order to open a new BGP session. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPOpen'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteField (BGPOpen).version>, <ShortField (BGPOpen).my_as>, <ShortField (BGPOpen).hold_time>, <IPField (BGPOpen).bgp_id>, <FieldLenField (BGPOpen).opt_param_len>, <BGPOptParamPacketListField (BGPOpen).opt_params>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPOptParam(_pkt, /, *, param_type=2, param_length=None, param_value=None, authentication_data=None)[source]

Bases: Packet

Provides an implementation the OPEN message optional parameters. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPOptParam'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPOptParam).param_type>, <ByteField (BGPOptParam).param_length>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPOptParamPacketListField(name: str, default: Optional[List[BasePacket]], pkt_cls: Optional[Union[Callable[[bytes], Packet], Type[Packet]]]  # noqa: E501 = None, count_from: Optional[Callable[[Packet], int]] = None, length_from: Optional[Callable[[Packet], int]] = None, next_cls_cb: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]]  # noqa: E501 = None, max_count: Optional[int] = None)[source]

Bases: PacketListField

PacketListField handling the optional parameters (OPEN message).

getfield(pkt, s)[source]
class scapy.contrib.bgp.BGPPAAS4Aggregator(_pkt, /, *, aggregator_asn=0, speaker_address='0.0.0.0')[source]

Bases: Packet

Provides an implementation of the AS4_AGGREGATOR attribute “value part”. References: RFC 4893

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAS4Aggregator'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPAAS4Aggregator).aggregator_asn>, <IPField (BGPPAAS4Aggregator).speaker_address>]
class scapy.contrib.bgp.BGPPAAS4BytesPath(_pkt, /, *, segments=[])[source]

Bases: Packet

Packet handling the AS_PATH attribute value (4 bytes ASNs, for new speakers -> ASNs are encoded as IntFields). References: RFC 4893

class ASPathSegment(_pkt, /, *, segment_type=2, segment_length=None, segment_value=[])[source]

Bases: Packet

Provides an implementation for AS_PATH segments with 4 bytes ASNs.

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAS4BytesPath.ASPathSegment'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (ASPathSegment).segment_type>, <ByteField (ASPathSegment).segment_length>, <FieldListField (ASPathSegment).segment_value>]
post_build(p, pay)[source]
aliastypes = [<class 'scapy.contrib.bgp.BGPPAAS4BytesPath'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ASPathSegmentPacketListField (BGPPAAS4BytesPath).segments>]
class scapy.contrib.bgp.BGPPAAS4Path(_pkt, /, *, segment_type=2, segment_length=None, segment_value=[])[source]

Bases: Packet

Provides an implementation of the AS4_PATH attribute “value part”. References: RFC 4893

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAS4Path'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPPAAS4Path).segment_type>, <ByteField (BGPPAAS4Path).segment_length>, <FieldListField (BGPPAAS4Path).segment_value>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPPAASPath(_pkt, /, *, segments=[])[source]

Bases: Packet

Packet handling the AS_PATH attribute value (2 bytes ASNs, for old speakers). References: RFC 4271, RFC 5065

class ASPathSegment(_pkt, /, *, segment_type=2, segment_length=None, segment_value=[])[source]

Bases: Packet

Provides an implementation for AS_PATH segments with 2 bytes ASNs.

aliastypes = [<class 'scapy.contrib.bgp.BGPPAASPath.ASPathSegment'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (ASPathSegment).segment_type>, <ByteField (ASPathSegment).segment_length>, <FieldListField (ASPathSegment).segment_value>]
post_build(p, pay)[source]
AS_TRANS = 23456
aliastypes = [<class 'scapy.contrib.bgp.BGPPAASPath'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ASPathSegmentPacketListField (BGPPAASPath).segments>]
class scapy.contrib.bgp.BGPPAAggregator(_pkt, /, *, aggregator_asn=0, speaker_address='0.0.0.0')[source]

Bases: Packet

Packet handling the AGGREGATOR attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAggregator'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortField (BGPPAAggregator).aggregator_asn>, <IPField (BGPPAAggregator).speaker_address>]
class scapy.contrib.bgp.BGPPAAtomicAggregate(_pkt, /)[source]

Bases: Packet

Packet handling the ATOMIC_AGGREGATE attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAtomicAggregate'>, <class 'scapy.packet.Packet'>]
class scapy.contrib.bgp.BGPPAClusterList(_pkt, /, *, cluster_list=[])[source]

Bases: Packet

Packet handling the CLUSTER_LIST attribute value. References: RFC 4456

aliastypes = [<class 'scapy.contrib.bgp.BGPPAClusterList'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<FieldListField (BGPPAClusterList).cluster_list>]
class scapy.contrib.bgp.BGPPACommunity(_pkt, /, *, community=0)[source]

Bases: Packet

Packet handling the COMMUNITIES attribute value. References: RFC 1997

aliastypes = [<class 'scapy.contrib.bgp.BGPPACommunity'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntEnumField (BGPPACommunity).community>]
class scapy.contrib.bgp.BGPPAExtCommFourOctetASSpecific(_pkt, /, *, global_administrator=0, local_administrator=0)[source]

Bases: Packet

Packet handling the Four-Octet AS Specific Extended Community attribute value. References: RFC 5668

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommFourOctetASSpecific'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPAExtCommFourOctetASSpecific).global_administrator>, <ShortField (BGPPAExtCommFourOctetASSpecific).local_administrator>]
class scapy.contrib.bgp.BGPPAExtCommIPv4AddressSpecific(_pkt, /, *, global_administrator=0, local_administrator=0)[source]

Bases: Packet

Packet handling the IPv4 Address Specific Extended Community attribute value. References: RFC 4360

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommIPv4AddressSpecific'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPAExtCommIPv4AddressSpecific).global_administrator>, <ShortField (BGPPAExtCommIPv4AddressSpecific).local_administrator>]
class scapy.contrib.bgp.BGPPAExtCommOpaque(_pkt, /, *, value=b'')[source]

Bases: Packet

Packet handling the Opaque Extended Community attribute value. References: RFC 4360

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommOpaque'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<StrFixedLenField (BGPPAExtCommOpaque).value>]
class scapy.contrib.bgp.BGPPAExtCommRedirectAS2Byte(_pkt, /, *, asn=0, value=0)[source]

Bases: Packet

Packet handling the (FlowSpec) “redirect AS-2byte” extended community (RFC 7674). References: RFC 7674

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommRedirectAS2Byte'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortField (BGPPAExtCommRedirectAS2Byte).asn>, <IntField (BGPPAExtCommRedirectAS2Byte).value>]
class scapy.contrib.bgp.BGPPAExtCommRedirectAS4Byte(_pkt, /, *, asn=0, value=0)[source]

Bases: Packet

Packet handling the (FlowSpec) “redirect AS-4byte” extended community. (RFC 7674). References: RFC 7674

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommRedirectAS4Byte'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPAExtCommRedirectAS4Byte).asn>, <ShortField (BGPPAExtCommRedirectAS4Byte).value>]
class scapy.contrib.bgp.BGPPAExtCommRedirectIPv4(_pkt, /, *, ip_addr=0, value=0)[source]

Bases: Packet

Packet handling the (FlowSpec) “redirect IPv4” extended community. (RFC 7674). References: RFC 7674

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommRedirectIPv4'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPAExtCommRedirectIPv4).ip_addr>, <ShortField (BGPPAExtCommRedirectIPv4).value>]
class scapy.contrib.bgp.BGPPAExtCommTrafficAction(_pkt, /, *, reserved=0, sample=0, terminal_action=0)[source]

Bases: Packet

Packet handling the (FlowSpec) “traffic-action” extended community. References: RFC 5575

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTrafficAction'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BitField (BGPPAExtCommTrafficAction).reserved>, <BitField (BGPPAExtCommTrafficAction).sample>, <BitField (BGPPAExtCommTrafficAction).terminal_action>]
class scapy.contrib.bgp.BGPPAExtCommTrafficMarking(_pkt, /, *, dscp=48)[source]

Bases: Packet

Packet handling the (FlowSpec) “traffic-marking” extended community. References: RFC 5575

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTrafficMarking'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BitEnumField (BGPPAExtCommTrafficMarking).dscp>]
class scapy.contrib.bgp.BGPPAExtCommTrafficRate(_pkt, /, *, id=0, rate=0)[source]

Bases: Packet

Packet handling the (FlowSpec) “traffic-rate” extended community. References: RFC 5575

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTrafficRate'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortField (BGPPAExtCommTrafficRate).id>, <IEEEFloatField (BGPPAExtCommTrafficRate).rate>]
class scapy.contrib.bgp.BGPPAExtCommTwoOctetASSpecific(_pkt, /, *, global_administrator=0, local_administrator=0)[source]

Bases: Packet

Packet handling the Two-Octet AS Specific Extended Community attribute value. References: RFC 4360

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTwoOctetASSpecific'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortField (BGPPAExtCommTwoOctetASSpecific).global_administrator>, <IntField (BGPPAExtCommTwoOctetASSpecific).local_administrator>]
class scapy.contrib.bgp.BGPPAExtComms(_pkt, /, *, extended_communities=[])[source]

Bases: Packet

Packet handling the multiple extended communities.

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtComms'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<_ExtCommsPacketListField (BGPPAExtComms).extended_communities>]
class scapy.contrib.bgp.BGPPAExtCommunity(_pkt, /, *, type_high=0, type_low=None, value=None)[source]

Bases: Packet

Provides an implementation of the Extended Communities attribute. References: RFC 4360

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommunity'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPPAExtCommunity).type_high>, <_TypeLowField (BGPPAExtCommunity).type_low>, <_ExtCommValuePacketField (BGPPAExtCommunity).value>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPPAIPv6AddressSpecificExtComm(_pkt, /, *, global_administrator='::', local_administrator=0)[source]

Bases: Packet

Provides an implementation of the IPv6 Address Specific Extended Community attribute. This attribute is not defined using the existing BGP Extended Community attribute (see the RFC 5701 excerpt below). References: RFC 5701

aliastypes = [<class 'scapy.contrib.bgp.BGPPAIPv6AddressSpecificExtComm'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IP6Field (BGPPAIPv6AddressSpecificExtComm).global_administrator>, <ShortField (BGPPAIPv6AddressSpecificExtComm).local_administrator>]
class scapy.contrib.bgp.BGPPALargeCommunity(_pkt, /, *, segments=[])[source]

Bases: Packet

Provides an implementation of the LARGE_COMMUNITY attribute. References: RFC 8092, RFC 8195

aliastypes = [<class 'scapy.contrib.bgp.BGPPALargeCommunity'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<PacketListField (BGPPALargeCommunity).segments>]
class scapy.contrib.bgp.BGPPALocalPref(_pkt, /, *, local_pref=0)[source]

Bases: Packet

Packet handling the LOCAL_PREF attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPALocalPref'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPALocalPref).local_pref>]
class scapy.contrib.bgp.BGPPAMPReachNLRI(_pkt, /, *, afi=0, safi=0, nh_addr_len=0, nh_v4_addr='0.0.0.0', nh_v6_addr='::', nh_v6_global='::', nh_v6_link_local='::', reserved=0, nlri=[])[source]

Bases: Packet

Packet handling the MP_REACH_NLRI attribute value, for non IPv6 AFI. References: RFC 4760

aliastypes = [<class 'scapy.contrib.bgp.BGPPAMPReachNLRI'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortEnumField (BGPPAMPReachNLRI).afi>, <ByteEnumField (BGPPAMPReachNLRI).safi>, <ByteField (BGPPAMPReachNLRI).nh_addr_len>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <ByteField (BGPPAMPReachNLRI).reserved>, <MPReachNLRIPacketListField (BGPPAMPReachNLRI).nlri>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPPAMPUnreachNLRI(_pkt, /, *, afi=0, safi=0, afi_safi_specific=None)[source]

Bases: Packet

Packet handling the MP_UNREACH_NLRI attribute value, for non IPv6 AFI. References: RFC 4760

aliastypes = [<class 'scapy.contrib.bgp.BGPPAMPUnreachNLRI'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortEnumField (BGPPAMPUnreachNLRI).afi>, <ByteEnumField (BGPPAMPUnreachNLRI).safi>, <MPUnreachNLRIPacketField (BGPPAMPUnreachNLRI).afi_safi_specific>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPPAMPUnreachNLRI_IPv6(_pkt, /, *, withdrawn_routes=[])[source]

Bases: Packet

Packet handling the MP_UNREACH_NLRI attribute value, for IPv6 AFI.

aliastypes = [<class 'scapy.contrib.bgp.BGPPAMPUnreachNLRI_IPv6'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<BGPNLRIPacketListField (BGPPAMPUnreachNLRI_IPv6).withdrawn_routes>]
class scapy.contrib.bgp.BGPPAMultiExitDisc(_pkt, /, *, med=0)[source]

Bases: Packet

Packet handling the MULTI_EXIT_DISC attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAMultiExitDisc'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IntField (BGPPAMultiExitDisc).med>]
class scapy.contrib.bgp.BGPPANextHop(_pkt, /, *, next_hop='0.0.0.0')[source]

Bases: Packet

Packet handling the NEXT_HOP attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPANextHop'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IPField (BGPPANextHop).next_hop>]
class scapy.contrib.bgp.BGPPAOrigin(_pkt, /, *, origin=0)[source]

Bases: Packet

Packet handling the ORIGIN attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAOrigin'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ByteEnumField (BGPPAOrigin).origin>]
class scapy.contrib.bgp.BGPPAOriginatorID(_pkt, /, *, originator_id='0.0.0.0')[source]

Bases: Packet

Packet handling the ORIGINATOR_ID attribute value. References: RFC 4456

aliastypes = [<class 'scapy.contrib.bgp.BGPPAOriginatorID'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<IPField (BGPPAOriginatorID).originator_id>]
class scapy.contrib.bgp.BGPPathAttr(_pkt, /, *, type_flags=<Flag 128 (Optional)>, type_code=0, attr_ext_len=None, attr_len=None, attribute=None)[source]

Bases: Packet

Provides an implementation of the path attributes. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPathAttr'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<FlagsField (BGPPathAttr).type_flags>, <ByteEnumField (BGPPathAttr).type_code>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <_PathAttrPacketField (BGPPathAttr).attribute>]
post_build(p, pay)[source]
class scapy.contrib.bgp.BGPPathAttrPacketListField(name: str, default: Optional[List[BasePacket]], pkt_cls: Optional[Union[Callable[[bytes], Packet], Type[Packet]]]  # noqa: E501 = None, count_from: Optional[Callable[[Packet], int]] = None, length_from: Optional[Callable[[Packet], int]] = None, next_cls_cb: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]]  # noqa: E501 = None, max_count: Optional[int] = None)[source]

Bases: PacketListField

PacketListField handling the path attributes (UPDATE message).

getfield(pkt, s)[source]
class scapy.contrib.bgp.BGPRouteRefresh(_pkt, /, *, afi=1, subtype=0, safi=1, orf_data=b'')[source]

Bases: BGP

Provides an implementation of the ROUTE-REFRESH message. References: RFC 2918, RFC 7313

aliastypes = [<class 'scapy.contrib.bgp.BGPRouteRefresh'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<ShortEnumField (BGPRouteRefresh).afi>, <ByteEnumField (BGPRouteRefresh).subtype>, <ByteEnumField (BGPRouteRefresh).safi>, <scapy.fields.ConditionalField object>]
class scapy.contrib.bgp.BGPUpdate(_pkt, /, *, withdrawn_routes_len=None, withdrawn_routes=[], path_attr_len=None, path_attr=[], nlri=[])[source]

Bases: BGP

UPDATE messages allow peers to exchange routes. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPUpdate'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
fields_desc: ClassVar[List[Field[Any, Any] | _FieldContainer]] = [<FieldLenField (BGPUpdate).withdrawn_routes_len>, <BGPNLRIPacketListField (BGPUpdate).withdrawn_routes>, <FieldLenField (BGPUpdate).path_attr_len>, <BGPPathAttrPacketListField (BGPUpdate).path_attr>, <BGPNLRIPacketListField (BGPUpdate).nlri>]
post_build(p, pay)[source]
class scapy.contrib.bgp.MPReachNLRIPacketListField(name: str, default: Optional[List[BasePacket]], pkt_cls: Optional[Union[Callable[[bytes], Packet], Type[Packet]]]  # noqa: E501 = None, count_from: Optional[Callable[[Packet], int]] = None, length_from: Optional[Callable[[Packet], int]] = None, next_cls_cb: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]]  # noqa: E501 = None, max_count: Optional[int] = None)[source]

Bases: PacketListField

PacketListField handling the AFI specific part (except for the length of Next Hop Network Address field, which is not AFI specific) of the MP_REACH_NLRI attribute.

getfield(pkt, s)[source]
class scapy.contrib.bgp.MPUnreachNLRIPacketField(name: str, default: Optional[K], pkt_cls: Union[Callable[[bytes], Packet], Type[Packet]]  # noqa: E501)[source]

Bases: PacketField

PacketField handling the AFI specific part of the MP_UNREACH_NLRI attribute.

m2i(pkt, m)[source]
scapy.contrib.bgp.detect_add_path_prefix46(s, max_bit_length)[source]

Detect IPv4/IPv6 prefixes conform to BGP Additional Path but NOT conform to standard BGP..

This is an adapted version of wireshark’s detect_add_path_prefix46 https://github.com/wireshark/wireshark/blob/ed9e958a2ed506220fdab320738f1f96a3c2ffbb/epan/dissectors/packet-bgp.c#L2905 Kudos to them !

scapy.contrib.bgp.has_extended_length(flags)[source]

Used in BGPPathAttr to check if the extended-length flag is set.