Beispiel #1
0
class SessionTerm(formats.NoPayloadPacket):
    ''' An flag-dependent SESS_TERM message. '''

    @enum.unique
    class Flag(enum.IntEnum):
        ''' Message flags.
        Flags must be in LSbit-first order.
        '''
        REPLY = 0x01

    @enum.unique
    class Reason(enum.IntEnum):
        ''' Reason code points. '''
        UNKNOWN = 0
        IDLE_TIMEOUT = 1
        VERSION_MISMATCH = 2
        BUSY = 3
        CONTACT_FAILURE = 4
        RESOURCE_EXHAUSTION = 5

    fields_desc = [
        fields.FlagsField('flags', default=0, size=8,
                          names=[item.name for item in Flag]),
        fields.ByteEnumField('reason', default=Reason.UNKNOWN,
                             enum={item.value: item.name for item in Reason}),
    ]
Beispiel #2
0
class ContactV3(formats.NoPayloadPacket):
    ''' TCPCLv3 contact header pseudo-message. '''

    #: Flags must be in LSbit-first order
    @enum.unique
    class Flag(enum.IntEnum):
        ENA_ACK = 0x01
        ENA_FRAG = 0x02
        ENA_REFUSE = 0x04
        ENA_LENGTH = 0x08

    fields_desc = [
        fields.FlagsField('flags',
                          default=0,
                          size=8,
                          names=[item.name for item in Flag]),
        formats.UInt16Field('keepalive', default=0),
        formats.SdnvFieldLenField('nodeid_length',
                                  default=None,
                                  length_of='nodeid_data'),
        fields.StrLenField('nodeid_data',
                           default='',
                           length_from=lambda pkt: pkt.nodeid_length),
    ]

    def post_dissection(self, pkt):
        ''' Verify consistency of packet. '''
        formats.verify_sized_item(self.nodeid_length, self.nodeid_data)
        packet.Packet.post_dissection(self, pkt)
Beispiel #3
0
class TransferAck(formats.NoPayloadPacket):
    ''' An XFER_ACK with no payload. '''

    fields_desc = [
        fields.FlagsField('flags', default=0, size=8,
                          names=[item.name for item in TransferSegment.Flag]),
        formats.UInt64Field('transfer_id', default=0),
        formats.UInt64Field('length', default=None),
    ]
Beispiel #4
0
class ContactV4(formats.NoPayloadPacket):
    ''' TCPCLv4 Contact header pseudo-message. '''

    #: Largest 64-bit size value
    SIZE_MAX = 2**64 - 1

    #: Flags must be in LSbit-first order
    @enum.unique
    class Flag(enum.IntEnum):
        CAN_TLS = 0x01

    fields_desc = [
        fields.FlagsField(
            'flags',
            default=0,
            size=8,
            # names in LSbit-first order
            names=[item.name for item in Flag]),
    ]
Beispiel #5
0
class TransferSegment(formats.NoPayloadPacket):
    ''' A XFER_SEGMENT with bundle data as field. '''

    @enum.unique
    class Flag(enum.IntEnum):
        ''' Message flags.
        Flags must be in LSbit-first order.
        '''
        END = 0x1
        START = 0x2

    fields_desc = [
        fields.FlagsField('flags', default=0, size=8,
                          names=[item.name for item in Flag]),
        formats.UInt64Field('transfer_id', default=0),
        fields.ConditionalField(
            cond=lambda pkt: pkt.flags & TransferSegment.Flag.START,
            fld=formats.UInt32FieldLenField(
                'ext_size', default=None, length_of='ext_items'),
        ),
        fields.ConditionalField(
            cond=lambda pkt: pkt.flags & TransferSegment.Flag.START,
            fld=formats.ExtensionListField('ext_items', default=[],
                                           cls=TransferExtendHeader,
                                           length_from=lambda pkt: pkt.ext_size),
        ),
        formats.UInt64FieldLenField('length', default=None, length_of='data'),
        formats.BlobField('data', default=b'',
                          length_from=lambda pkt: pkt.length),
    ]

    def post_dissection(self, pkt):
        ''' Verify consistency of packet. '''
        (field, val) = self.getfield_and_val('ext_items')
        if val is not None:
            encoded = field.addfield(self, b'', val)
            formats.verify_sized_item(self.ext_size, encoded)

        formats.verify_sized_item(self.length, self.getfieldval('data'))
        packet.Packet.post_dissection(self, pkt)
Beispiel #6
0
class TlvHead(packet.Packet):
    ''' Generic TLV header with data as payload. '''

    @classmethod
    def bind_extension(cls, ext_id):
        ''' Bind an extension class to a derived header class.
        This decorator should be applied to extension type classes.

        :param cls: The header class to extend.
        :param ext_id: The extension type ID number.
        '''

        def func(ext_cls):
            packet.bind_layers(cls, ext_cls, type=ext_id)
            return ext_cls

        return func

    @enum.unique
    class Flag(enum.IntEnum):
        ''' Message flags.
        Flags must be in LSbit-first order.
        '''
        CRITICAL = 0x01

    fields_desc = [
        fields.FlagsField('flags', default=0, size=8,
                          names=[item.name for item in Flag]),
        formats.UInt16Field('type', default=None),
        formats.UInt16PayloadLenField('length', default=None),
    ]

    def post_dissection(self, pkt):
        ''' Verify consistency of packet. '''
        formats.verify_sized_item(self.length, self.payload)
        packet.Packet.post_dissection(self, pkt)