scapy.contrib.bgp

BGP (Border Gateway Protocol).

class scapy.contrib.bgp.ASPathSegmentPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField handling AS_PATH segments.

getfield(pkt, s)
class scapy.contrib.bgp.BGP

Bases: scapy.packet.Packet

Every BGP message inherits from this class.

KEEPALIVE_TYPE = 4
NOTIFICATION_TYPE = 3
OPEN_TYPE = 1
ROUTEREFRESH_TYPE = 5
UPDATE_TYPE = 2
aliastypes
classmethod dispatch_hook(_pkt=None, *args, **kargs)

Returns the right class for the given data.

guess_payload_class(p)
class scapy.contrib.bgp.BGPAuthenticationInformation

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPAuthenticationInformation fields

authentication_code

ByteField

0

authentication_data

StrField

None

class scapy.contrib.bgp.BGPCapFourBytesASN

Bases: scapy.contrib.bgp.BGPCapability

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

aliastypes
fields_desc
BGPCapFourBytesASN fields

code

ByteEnumField

65

length

ByteField

4

asn

IntField

0

class scapy.contrib.bgp.BGPCapGeneric

Bases: scapy.contrib.bgp.BGPCapability

This class provides an implementation of a generic capability.

aliastypes
fields_desc
BGPCapGeneric fields

code

ByteEnumField

0

length

FieldLenField

None

cap_data

StrLenField

b''

class scapy.contrib.bgp.BGPCapGracefulRestart

Bases: scapy.contrib.bgp.BGPCapability

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

class GRTuple

Bases: scapy.packet.Packet

Tuple <AFI, SAFI, Flags for address family>

aliastypes
fields_desc
GRTuple fields

afi

ShortEnumField

0

safi

ByteEnumField

0

flags

ByteEnumField

0

aliastypes
fields_desc
BGPCapGracefulRestart fields

code

ByteEnumField

64

length

ByteField

None

restart_flags

BitField (4 bits)

0

restart_time

BitField (12 bits)

0

entries

PacketListField

[]

class scapy.contrib.bgp.BGPCapMultiprotocol

Bases: scapy.contrib.bgp.BGPCapability

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

aliastypes
fields_desc
BGPCapMultiprotocol fields

code

ByteEnumField

1

length

ByteField

4

afi

ShortEnumField

0

reserved

ByteField

0

safi

ByteEnumField

0

class scapy.contrib.bgp.BGPCapORF

Bases: scapy.contrib.bgp.BGPCapability

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

aliastypes
fields_desc
BGPCapORF fields

code

ByteEnumField

3

length

ByteField

None

orf

BGPCapORFBlockPacketListField

[]

class scapy.contrib.bgp.BGPCapORFBlock

Bases: scapy.packet.Packet

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

class ORFTuple

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
ORFTuple fields

orf_type

ByteEnumField

0

send_receive

ByteEnumField

0

aliastypes
fields_desc
BGPCapORFBlock fields

afi

ShortEnumField

0

reserved

ByteField

0

safi

ByteEnumField

0

orf_number

FieldLenField

None

entries

PacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPCapORFBlockPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

Handles lists of BGPCapORFBlocks.

getfield(pkt, s)
class scapy.contrib.bgp.BGPCapability

Bases: scapy.packet.Packet

Generic BGP capability.

aliastypes
classmethod dispatch_hook(_pkt=None, *args, **kargs)

Returns the right class for the given data.

getlayer(cls, nb=1, _track=None, _subclass=True, **flt)
haslayer(cls)
post_build(p, pay)
pre_dissect(s)

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

class scapy.contrib.bgp.BGPConf

Bases: scapy.config.ConfClass

BGP module configuration.

use_2_bytes_asn = True
class scapy.contrib.bgp.BGPFieldIPv4(name, default, fmt='H')

Bases: scapy.fields.Field

IPv4 Field (CIDR)

addfield(pkt, s, val)
getfield(pkt, s)
h2i(pkt, h)

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

i2h(pkt, i)

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

i2len(pkt, i)
i2m(pkt, i)

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

i2repr(pkt, i)
m2i(pkt, m)
mask2iplen(mask)

Get the IP field mask length (in bytes).

class scapy.contrib.bgp.BGPFieldIPv6(name, default, fmt='H')

Bases: scapy.fields.Field

IPv6 Field (CIDR)

addfield(pkt, s, val)
getfield(pkt, s)
h2i(pkt, h)

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

i2h(pkt, i)

“Internal” representation to “human” representation.

i2len(pkt, i)
i2m(pkt, i)

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

i2repr(pkt, i)
m2i(pkt, m)
mask2iplen(mask)

Get the IP field mask length (in bytes).

class scapy.contrib.bgp.BGPHeader

Bases: scapy.packet.Packet

The header of any BGP message. References: RFC 4271

aliastypes
classmethod dispatch_hook(_pkt=None, *args, **kargs)

Returns the right class for the given data.

fields_desc
BGPHeader fields

marker

XBitField (128 bits)

340282366920938463463374607431768211455

len

ShortField

None

type

ByteEnumField

4

guess_payload_class(payload)
payload_guess

Possible sublayers: BGPKeepAlive, BGPNotification, BGPOpen, BGPRouteRefresh, BGPUpdate

post_build(p, pay)
class scapy.contrib.bgp.BGPKeepAlive

Bases: scapy.contrib.bgp.BGP, scapy.contrib.bgp.BGPHeader

KEEPALIVE message.

aliastypes
class scapy.contrib.bgp.BGPNLRIPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField handling NLRI fields.

getfield(pkt, s)
class scapy.contrib.bgp.BGPNLRI_IPv4

Bases: scapy.packet.Packet

Packet handling IPv4 NLRI fields.

aliastypes
fields_desc
BGPNLRI_IPv4 fields

prefix

BGPFieldIPv4

(0, '0.0.0.0')

class scapy.contrib.bgp.BGPNLRI_IPv6

Bases: scapy.packet.Packet

Packet handling IPv6 NLRI fields.

aliastypes
fields_desc
BGPNLRI_IPv6 fields

prefix

BGPFieldIPv6

(0, '::')

class scapy.contrib.bgp.BGPNotification

Bases: scapy.contrib.bgp.BGP

NOTIFICATION messages end a BGP session. References: RFC 4271

aliastypes
fields_desc
BGPNotification fields

error_code

ByteEnumField

0

error_subcode

MultiEnumField (Depends on error_code)

0

data

StrField

None

class scapy.contrib.bgp.BGPORF

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPORF fields

when_to_refresh

ByteEnumField

0

orf_type

ByteEnumField

0

orf_len

FieldLenField

None

entries

BGPORFEntryPacketListField

[]

class scapy.contrib.bgp.BGPORFAddressPrefix

Bases: scapy.contrib.bgp.BGPORFEntry

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

aliastypes
fields_desc
BGPORFAddressPrefix fields

action

BitEnumField (2 bits)

0

match

BitEnumField (1 bit)

0

reserved

BitField (5 bits)

0

sequence

IntField

0

min_len

ByteField

0

max_len

ByteField

0

prefix

_ORFNLRIPacketField

b''

class scapy.contrib.bgp.BGPORFCoveringPrefix

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPORFCoveringPrefix fields

action

BitEnumField (2 bits)

0

match

BitEnumField (1 bit)

0

reserved

BitField (5 bits)

0

sequence

IntField

0

min_len

ByteField

0

max_len

ByteField

0

rt

LongField

0

import_rt

LongField

0

route_type

ByteField

0

host_addr

PacketField

None

class scapy.contrib.bgp.BGPORFEntry

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPORFEntry fields

action

BitEnumField (2 bits)

0

match

BitEnumField (1 bit)

0

reserved

BitField (5 bits)

0

value

StrField

b''

class scapy.contrib.bgp.BGPORFEntryPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField handling the ORF entries.

getfield(pkt, s)
m2i(pkt, m)
class scapy.contrib.bgp.BGPOpen

Bases: scapy.contrib.bgp.BGP

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

aliastypes
fields_desc
BGPOpen fields

version

ByteField

4

my_as

ShortField

0

hold_time

ShortField

0

bgp_id

IPField

'0.0.0.0'

opt_param_len

FieldLenField

None

opt_params

BGPOptParamPacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPOptParam

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPOptParam fields

param_type

ByteEnumField

2

param_length

ByteField

None

param_value

PacketField (Cond)

None

authentication_data

PacketField (Cond)

None

post_build(p, pay)
class scapy.contrib.bgp.BGPOptParamPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField handling the optional parameters (OPEN message).

getfield(pkt, s)
class scapy.contrib.bgp.BGPPAAS4Aggregator

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAAS4Aggregator fields

aggregator_asn

IntField

0

speaker_address

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPAAS4BytesPath

Bases: scapy.packet.Packet

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

class ASPathSegment

Bases: scapy.packet.Packet

Provides an implementation for AS_PATH segments with 4 bytes ASNs.

aliastypes
fields_desc
ASPathSegment fields

segment_type

ByteEnumField

2

segment_length

ByteField

None

segment_value

FieldListField

[]

post_build(p, pay)
aliastypes
fields_desc
BGPPAAS4BytesPath fields

segments

ASPathSegmentPacketListField

[]

class scapy.contrib.bgp.BGPPAAS4Path

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAAS4Path fields

segment_type

ByteEnumField

2

segment_length

ByteField

None

segment_value

FieldListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPPAASPath

Bases: scapy.packet.Packet

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

class ASPathSegment

Bases: scapy.packet.Packet

Provides an implementation for AS_PATH segments with 2 bytes ASNs.

aliastypes
fields_desc
ASPathSegment fields

segment_type

ByteEnumField

2

segment_length

ByteField

None

segment_value

FieldListField

[]

post_build(p, pay)
AS_TRANS = 23456
aliastypes
fields_desc
BGPPAASPath fields

segments

ASPathSegmentPacketListField

[]

class scapy.contrib.bgp.BGPPAAggregator

Bases: scapy.packet.Packet

Packet handling the AGGREGATOR attribute value. References: RFC 4271

aliastypes
fields_desc
BGPPAAggregator fields

aggregator_asn

ShortField

0

speaker_address

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPAAtomicAggregate

Bases: scapy.packet.Packet

Packet handling the ATOMIC_AGGREGATE attribute value. References: RFC 4271

aliastypes
class scapy.contrib.bgp.BGPPAClusterList

Bases: scapy.packet.Packet

Packet handling the CLUSTER_LIST attribute value. References: RFC 4456

aliastypes
fields_desc
BGPPAClusterList fields

cluster_list

FieldListField

[]

class scapy.contrib.bgp.BGPPACommunity

Bases: scapy.packet.Packet

Packet handling the COMMUNITIES attribute value. References: RFC 1997

aliastypes
fields_desc
BGPPACommunity fields

community

IntEnumField

0

class scapy.contrib.bgp.BGPPAExtCommFourOctetASSpecific

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommFourOctetASSpecific fields

global_administrator

IntField

0

local_administrator

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommIPv4AddressSpecific

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommIPv4AddressSpecific fields

global_administrator

IntField

0

local_administrator

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommOpaque

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommOpaque fields

value

StrFixedLenField

b''

class scapy.contrib.bgp.BGPPAExtCommRedirectAS2Byte

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommRedirectAS2Byte fields

asn

ShortField

0

value

IntField

0

class scapy.contrib.bgp.BGPPAExtCommRedirectAS4Byte

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommRedirectAS4Byte fields

asn

IntField

0

value

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommRedirectIPv4

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommRedirectIPv4 fields

ip_addr

IntField

0

value

ShortField

0

class scapy.contrib.bgp.BGPPAExtCommTrafficAction

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommTrafficAction fields

reserved

BitField (46 bits)

0

sample

BitField (1 bit)

0

terminal_action

BitField (1 bit)

0

class scapy.contrib.bgp.BGPPAExtCommTrafficMarking

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommTrafficMarking fields

dscp

BitEnumField (48 bits)

48

class scapy.contrib.bgp.BGPPAExtCommTrafficRate

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommTrafficRate fields

id

ShortField

0

rate

IEEEFloatField

0

class scapy.contrib.bgp.BGPPAExtCommTwoOctetASSpecific

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommTwoOctetASSpecific fields

global_administrator

ShortField

0

local_administrator

IntField

0

class scapy.contrib.bgp.BGPPAExtComms

Bases: scapy.packet.Packet

Packet handling the multiple extended communities.

aliastypes
fields_desc
BGPPAExtComms fields

extended_communities

_ExtCommsPacketListField

[]

class scapy.contrib.bgp.BGPPAExtCommunity

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAExtCommunity fields

type_high

ByteEnumField

0

type_low

_TypeLowField

None

value

_ExtCommValuePacketField

None

post_build(p, pay)
class scapy.contrib.bgp.BGPPAIPv6AddressSpecificExtComm

Bases: scapy.packet.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
fields_desc
BGPPAIPv6AddressSpecificExtComm fields

global_administrator

IP6Field

'::'

local_administrator

ShortField

0

class scapy.contrib.bgp.BGPPALocalPref

Bases: scapy.packet.Packet

Packet handling the LOCAL_PREF attribute value. References: RFC 4271

aliastypes
fields_desc
BGPPALocalPref fields

local_pref

IntField

0

class scapy.contrib.bgp.BGPPAMPReachNLRI

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAMPReachNLRI fields

afi

ShortEnumField

0

safi

ByteEnumField

0

nh_addr_len

ByteField

0

nh_v4_addr

IPField (Cond)

'0.0.0.0'

nh_v6_addr

IP6Field (Cond)

'::'

nh_v6_global

IP6Field (Cond)

'::'

nh_v6_link_local

IP6Field (Cond)

'::'

reserved

ByteField

0

nlri

MPReachNLRIPacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.BGPPAMPUnreachNLRI

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPAMPUnreachNLRI fields

afi

ShortEnumField

0

safi

ByteEnumField

0

afi_safi_specific

MPUnreachNLRIPacketField

None

post_build(p, pay)
class scapy.contrib.bgp.BGPPAMPUnreachNLRI_IPv6

Bases: scapy.packet.Packet

Packet handling the MP_UNREACH_NLRI attribute value, for IPv6 AFI.

aliastypes
fields_desc
BGPPAMPUnreachNLRI_IPv6 fields

withdrawn_routes

BGPNLRIPacketListField

[]

class scapy.contrib.bgp.BGPPAMultiExitDisc

Bases: scapy.packet.Packet

Packet handling the MULTI_EXIT_DISC attribute value. References: RFC 4271

aliastypes
fields_desc
BGPPAMultiExitDisc fields

med

IntField

0

class scapy.contrib.bgp.BGPPANextHop

Bases: scapy.packet.Packet

Packet handling the NEXT_HOP attribute value. References: RFC 4271

aliastypes
fields_desc
BGPPANextHop fields

next_hop

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPAOrigin

Bases: scapy.packet.Packet

Packet handling the ORIGIN attribute value. References: RFC 4271

aliastypes
fields_desc
BGPPAOrigin fields

origin

ByteEnumField

0

class scapy.contrib.bgp.BGPPAOriginatorID

Bases: scapy.packet.Packet

Packet handling the ORIGINATOR_ID attribute value. References: RFC 4456

aliastypes
fields_desc
BGPPAOriginatorID fields

originator_id

IPField

'0.0.0.0'

class scapy.contrib.bgp.BGPPathAttr

Bases: scapy.packet.Packet

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

aliastypes
fields_desc
BGPPathAttr fields

type_flags

FlagsField (8 bits)

<Flag 128 (Optional)>

type_code

ByteEnumField

0

attr_ext_len

ShortField (Cond)

None

attr_len

ByteField (Cond)

None

attribute

_PathAttrPacketField

None

post_build(p, pay)
class scapy.contrib.bgp.BGPPathAttrPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.PacketListField

PacketListField handling the path attributes (UPDATE message).

getfield(pkt, s)
class scapy.contrib.bgp.BGPRouteRefresh

Bases: scapy.contrib.bgp.BGP

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

aliastypes
fields_desc
BGPRouteRefresh fields

afi

ShortEnumField

1

subtype

ByteEnumField

0

safi

ByteEnumField

1

orf_data

PacketField

b''

class scapy.contrib.bgp.BGPUpdate

Bases: scapy.contrib.bgp.BGP

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

aliastypes
fields_desc
BGPUpdate fields

withdrawn_routes_len

FieldLenField

None

withdrawn_routes

BGPNLRIPacketListField

[]

path_attr_len

FieldLenField

None

path_attr

BGPPathAttrPacketListField

[]

nlri

BGPNLRIPacketListField

[]

post_build(p, pay)
class scapy.contrib.bgp.MPReachNLRIPacketListField(name, default, cls=None, count_from=None, length_from=None, next_cls_cb=None)

Bases: scapy.fields.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)
class scapy.contrib.bgp.MPUnreachNLRIPacketField(name, default, cls, remain=0)

Bases: scapy.fields.PacketField

PacketField handling the AFI specific part of the MP_UNREACH_NLRI attribute.

m2i(pkt, m)
scapy.contrib.bgp.has_extended_length(flags)

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