scapy.contrib.bgp module

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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

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 = [<class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
classmethod dispatch_hook(_pkt=None, *args, **kargs)

Returns the right class for the given data.

guess_payload_class(p)

DEV: Guesses the next payload class from layer bonds. Can be overloaded to use a different mechanism.

Parameters:payload (str) – the layer’s payload
Returns:the payload class
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 = [<class 'scapy.contrib.bgp.BGPAuthenticationInformation'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPAuthenticationInformation).authentication_code>, <Field (BGPAuthenticationInformation).authentication_data>]
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 = [<class 'scapy.contrib.bgp.BGPCapFourBytesASN'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPCapFourBytesASN).code>, <Field (BGPCapFourBytesASN).length>, <Field (BGPCapFourBytesASN).asn>]
class scapy.contrib.bgp.BGPCapGeneric

Bases: scapy.contrib.bgp.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 = [<Field (BGPCapGeneric).code>, <Field (BGPCapGeneric).length>, <Field (BGPCapGeneric).cap_data>]
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 = [<class 'scapy.contrib.bgp.BGPCapGracefulRestart.GRTuple'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (GRTuple).afi>, <Field (GRTuple).safi>, <Field (GRTuple).flags>]
aliastypes = [<class 'scapy.contrib.bgp.BGPCapGracefulRestart'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPCapGracefulRestart).code>, <Field (BGPCapGracefulRestart).length>, <Field (BGPCapGracefulRestart).restart_flags>, <Field (BGPCapGracefulRestart).restart_time>, <Field (BGPCapGracefulRestart).entries>]
class scapy.contrib.bgp.BGPCapMultiprotocol

Bases: scapy.contrib.bgp.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 = [<Field (BGPCapMultiprotocol).code>, <Field (BGPCapMultiprotocol).length>, <Field (BGPCapMultiprotocol).afi>, <Field (BGPCapMultiprotocol).reserved>, <Field (BGPCapMultiprotocol).safi>]
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 = [<class 'scapy.contrib.bgp.BGPCapORF'>, <class 'scapy.contrib.bgp.BGPCapability'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPCapORF).code>, <Field (BGPCapORF).length>, <Field (BGPCapORF).orf>]
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 = [<class 'scapy.contrib.bgp.BGPCapORFBlock.ORFTuple'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (ORFTuple).orf_type>, <Field (ORFTuple).send_receive>]
aliastypes = [<class 'scapy.contrib.bgp.BGPCapORFBlock'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPCapORFBlock).afi>, <Field (BGPCapORFBlock).reserved>, <Field (BGPCapORFBlock).safi>, <Field (BGPCapORFBlock).orf_number>, <Field (BGPCapORFBlock).entries>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

class scapy.contrib.bgp.BGPCapability

Bases: scapy.packet.Packet

Generic BGP capability.

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

Returns the right class for the given data.

getlayer(cls, nb=1, _track=None, _subclass=True, **flt)

Return the nb^th layer that is an instance of cls, matching flt values.

haslayer(cls)

true if self has a layer that is an instance of cls. Superseded by “cls in self” syntax.

post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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)

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

getfield(pkt, s)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

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)

Convert internal value to a length usable by a FieldLenField

i2m(pkt, i)

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

i2repr(pkt, i)

Convert internal value to a nice representation

m2i(pkt, m)

Convert machine value to internal value

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)

Add an internal value to a string

Copy the network representation of field val (belonging to layer pkt) to the raw string packet s, and return the new string packet.

getfield(pkt, s)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

h2i(pkt, h)

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

i2h(pkt, i)

“Internal” representation to “human” representation.

i2len(pkt, i)

Convert internal value to a length usable by a FieldLenField

i2m(pkt, i)

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

i2repr(pkt, i)

Convert internal value to a nice representation

m2i(pkt, m)

Convert machine value to internal value

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 = [<class 'scapy.contrib.bgp.BGPHeader'>, <class 'scapy.packet.Packet'>]
classmethod dispatch_hook(_pkt=None, *args, **kargs)

Returns the right class for the given data.

fields_desc = [<Field (BGPHeader,BGPKeepAlive).marker>, <Field (BGPHeader,BGPKeepAlive).len>, <Field (BGPHeader,BGPKeepAlive).type>]
guess_payload_class(payload)

DEV: Guesses the next payload class from layer bonds. Can be overloaded to use a different mechanism.

Parameters:payload (str) – the layer’s payload
Returns:the payload class
payload_guess = [({'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)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

class scapy.contrib.bgp.BGPKeepAlive

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

KEEPALIVE message.

aliastypes = [<class 'scapy.contrib.bgp.BGPKeepAlive'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

class scapy.contrib.bgp.BGPNLRI_IPv4

Bases: scapy.packet.Packet

Packet handling IPv4 NLRI fields.

aliastypes = [<class 'scapy.contrib.bgp.BGPNLRI_IPv4'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPNLRI_IPv4).prefix>]
class scapy.contrib.bgp.BGPNLRI_IPv6

Bases: scapy.packet.Packet

Packet handling IPv6 NLRI fields.

aliastypes = [<class 'scapy.contrib.bgp.BGPNLRI_IPv6'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPNLRI_IPv6).prefix>]
class scapy.contrib.bgp.BGPNotification

Bases: scapy.contrib.bgp.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 = [<Field (BGPNotification).error_code>, <Field (BGPNotification).error_subcode>, <Field (BGPNotification).data>]
class scapy.contrib.bgp.BGPORF

Bases: scapy.packet.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 = [<Field (BGPORF).when_to_refresh>, <Field (BGPORF).orf_type>, <Field (BGPORF).orf_len>, <Field (BGPORF).entries>]
class scapy.contrib.bgp.BGPORFAddressPrefix

Bases: scapy.contrib.bgp.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 = [<Field (BGPORFAddressPrefix).action>, <Field (BGPORFAddressPrefix).match>, <Field (BGPORFAddressPrefix).reserved>, <Field (BGPORFAddressPrefix).sequence>, <Field (BGPORFAddressPrefix).min_len>, <Field (BGPORFAddressPrefix).max_len>, <Field (BGPORFAddressPrefix).prefix>]
class scapy.contrib.bgp.BGPORFCoveringPrefix

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPORFCoveringPrefix'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPORFCoveringPrefix).action>, <Field (BGPORFCoveringPrefix).match>, <Field (BGPORFCoveringPrefix).reserved>, <Field (BGPORFCoveringPrefix).sequence>, <Field (BGPORFCoveringPrefix).min_len>, <Field (BGPORFCoveringPrefix).max_len>, <Field (BGPORFCoveringPrefix).rt>, <Field (BGPORFCoveringPrefix).import_rt>, <Field (BGPORFCoveringPrefix).route_type>, <Field (BGPORFCoveringPrefix).host_addr>]
class scapy.contrib.bgp.BGPORFEntry

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPORFEntry'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPORFEntry).action>, <Field (BGPORFEntry).match>, <Field (BGPORFEntry).reserved>, <Field (BGPORFEntry).value>]
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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

m2i(pkt, m)

Convert machine value to internal value

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 = [<class 'scapy.contrib.bgp.BGPOpen'>, <class 'scapy.contrib.bgp.BGP'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPOpen).version>, <Field (BGPOpen).my_as>, <Field (BGPOpen).hold_time>, <Field (BGPOpen).bgp_id>, <Field (BGPOpen).opt_param_len>, <Field (BGPOpen).opt_params>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

class scapy.contrib.bgp.BGPOptParam

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPOptParam'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPOptParam).param_type>, <Field (BGPOptParam).param_length>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

class scapy.contrib.bgp.BGPPAAS4Aggregator

Bases: scapy.packet.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 = [<Field (BGPPAAS4Aggregator).aggregator_asn>, <Field (BGPPAAS4Aggregator).speaker_address>]
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 = [<class 'scapy.contrib.bgp.BGPPAAS4BytesPath.ASPathSegment'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (ASPathSegment).segment_type>, <Field (ASPathSegment).segment_length>, <Field (ASPathSegment).segment_value>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAS4BytesPath'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAAS4BytesPath).segments>]
class scapy.contrib.bgp.BGPPAAS4Path

Bases: scapy.packet.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 = [<Field (BGPPAAS4Path).segment_type>, <Field (BGPPAAS4Path).segment_length>, <Field (BGPPAAS4Path).segment_value>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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 = [<class 'scapy.contrib.bgp.BGPPAASPath.ASPathSegment'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (ASPathSegment).segment_type>, <Field (ASPathSegment).segment_length>, <Field (ASPathSegment).segment_value>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

AS_TRANS = 23456
aliastypes = [<class 'scapy.contrib.bgp.BGPPAASPath'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAASPath).segments>]
class scapy.contrib.bgp.BGPPAAggregator

Bases: scapy.packet.Packet

Packet handling the AGGREGATOR attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAAggregator'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAAggregator).aggregator_asn>, <Field (BGPPAAggregator).speaker_address>]
class scapy.contrib.bgp.BGPPAAtomicAggregate

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

Bases: scapy.packet.Packet

Packet handling the CLUSTER_LIST attribute value. References: RFC 4456

aliastypes = [<class 'scapy.contrib.bgp.BGPPAClusterList'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAClusterList).cluster_list>]
class scapy.contrib.bgp.BGPPACommunity

Bases: scapy.packet.Packet

Packet handling the COMMUNITIES attribute value. References: RFC 1997

aliastypes = [<class 'scapy.contrib.bgp.BGPPACommunity'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPACommunity).community>]
class scapy.contrib.bgp.BGPPAExtCommFourOctetASSpecific

Bases: scapy.packet.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 = [<Field (BGPPAExtCommFourOctetASSpecific).global_administrator>, <Field (BGPPAExtCommFourOctetASSpecific).local_administrator>]
class scapy.contrib.bgp.BGPPAExtCommIPv4AddressSpecific

Bases: scapy.packet.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 = [<Field (BGPPAExtCommIPv4AddressSpecific).global_administrator>, <Field (BGPPAExtCommIPv4AddressSpecific).local_administrator>]
class scapy.contrib.bgp.BGPPAExtCommOpaque

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommOpaque'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAExtCommOpaque).value>]
class scapy.contrib.bgp.BGPPAExtCommRedirectAS2Byte

Bases: scapy.packet.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 = [<Field (BGPPAExtCommRedirectAS2Byte).asn>, <Field (BGPPAExtCommRedirectAS2Byte).value>]
class scapy.contrib.bgp.BGPPAExtCommRedirectAS4Byte

Bases: scapy.packet.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 = [<Field (BGPPAExtCommRedirectAS4Byte).asn>, <Field (BGPPAExtCommRedirectAS4Byte).value>]
class scapy.contrib.bgp.BGPPAExtCommRedirectIPv4

Bases: scapy.packet.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 = [<Field (BGPPAExtCommRedirectIPv4).ip_addr>, <Field (BGPPAExtCommRedirectIPv4).value>]
class scapy.contrib.bgp.BGPPAExtCommTrafficAction

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTrafficAction'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAExtCommTrafficAction).reserved>, <Field (BGPPAExtCommTrafficAction).sample>, <Field (BGPPAExtCommTrafficAction).terminal_action>]
class scapy.contrib.bgp.BGPPAExtCommTrafficMarking

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTrafficMarking'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAExtCommTrafficMarking).dscp>]
class scapy.contrib.bgp.BGPPAExtCommTrafficRate

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommTrafficRate'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAExtCommTrafficRate).id>, <Field (BGPPAExtCommTrafficRate).rate>]
class scapy.contrib.bgp.BGPPAExtCommTwoOctetASSpecific

Bases: scapy.packet.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 = [<Field (BGPPAExtCommTwoOctetASSpecific).global_administrator>, <Field (BGPPAExtCommTwoOctetASSpecific).local_administrator>]
class scapy.contrib.bgp.BGPPAExtComms

Bases: scapy.packet.Packet

Packet handling the multiple extended communities.

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtComms'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAExtComms).extended_communities>]
class scapy.contrib.bgp.BGPPAExtCommunity

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPPAExtCommunity'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAExtCommunity).type_high>, <Field (BGPPAExtCommunity).type_low>, <Field (BGPPAExtCommunity).value>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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 = [<class 'scapy.contrib.bgp.BGPPAIPv6AddressSpecificExtComm'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAIPv6AddressSpecificExtComm).global_administrator>, <Field (BGPPAIPv6AddressSpecificExtComm).local_administrator>]
class scapy.contrib.bgp.BGPPALocalPref

Bases: scapy.packet.Packet

Packet handling the LOCAL_PREF attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPALocalPref'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPALocalPref).local_pref>]
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 = [<class 'scapy.contrib.bgp.BGPPAMPReachNLRI'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAMPReachNLRI).afi>, <Field (BGPPAMPReachNLRI).safi>, <Field (BGPPAMPReachNLRI).nh_addr_len>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <Field (BGPPAMPReachNLRI).reserved>, <Field (BGPPAMPReachNLRI).nlri>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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 = [<class 'scapy.contrib.bgp.BGPPAMPUnreachNLRI'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAMPUnreachNLRI).afi>, <Field (BGPPAMPUnreachNLRI).safi>, <Field (BGPPAMPUnreachNLRI).afi_safi_specific>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

class scapy.contrib.bgp.BGPPAMPUnreachNLRI_IPv6

Bases: scapy.packet.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 = [<Field (BGPPAMPUnreachNLRI_IPv6).withdrawn_routes>]
class scapy.contrib.bgp.BGPPAMultiExitDisc

Bases: scapy.packet.Packet

Packet handling the MULTI_EXIT_DISC attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAMultiExitDisc'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAMultiExitDisc).med>]
class scapy.contrib.bgp.BGPPANextHop

Bases: scapy.packet.Packet

Packet handling the NEXT_HOP attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPANextHop'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPANextHop).next_hop>]
class scapy.contrib.bgp.BGPPAOrigin

Bases: scapy.packet.Packet

Packet handling the ORIGIN attribute value. References: RFC 4271

aliastypes = [<class 'scapy.contrib.bgp.BGPPAOrigin'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAOrigin).origin>]
class scapy.contrib.bgp.BGPPAOriginatorID

Bases: scapy.packet.Packet

Packet handling the ORIGINATOR_ID attribute value. References: RFC 4456

aliastypes = [<class 'scapy.contrib.bgp.BGPPAOriginatorID'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPAOriginatorID).originator_id>]
class scapy.contrib.bgp.BGPPathAttr

Bases: scapy.packet.Packet

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

aliastypes = [<class 'scapy.contrib.bgp.BGPPathAttr'>, <class 'scapy.packet.Packet'>]
fields_desc = [<Field (BGPPathAttr).type_flags>, <Field (BGPPathAttr).type_code>, <scapy.fields.ConditionalField object>, <scapy.fields.ConditionalField object>, <Field (BGPPathAttr).attribute>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

class scapy.contrib.bgp.BGPRouteRefresh

Bases: scapy.contrib.bgp.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 = [<Field (BGPRouteRefresh).afi>, <Field (BGPRouteRefresh).subtype>, <Field (BGPRouteRefresh).safi>, <Field (BGPRouteRefresh).orf_data>]
class scapy.contrib.bgp.BGPUpdate

Bases: scapy.contrib.bgp.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 = [<Field (BGPUpdate).withdrawn_routes_len>, <Field (BGPUpdate).withdrawn_routes>, <Field (BGPUpdate).path_attr_len>, <Field (BGPUpdate).path_attr>, <Field (BGPUpdate).nlri>]
post_build(p, pay)

DEV: called right after the current layer is build.

Parameters:
  • pkt (str) – the current packet (build by self_buil function)
  • pay (str) – the packet payload (build by do_build_payload function)
Returns:

a string of the packet with the payload

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)

Extract an internal value from a string

Extract from the raw packet s the field value belonging to layer pkt.

Returns a two-element list, first the raw packet string after having removed the extracted field, second the extracted field itself in internal representation.

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)

Convert machine value to internal value

scapy.contrib.bgp.has_extended_length(flags)

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