Base Class

pcapkit.foundation.reassembly.ip contains IP only, which reconstructs fragmented IP packets back to origin. The following algorithm implement is based on IP reassembly procedure introduced in RFC 791, using RCVBT (fragment receivedbit table). Though another algorithm is explained in RFC 815, replacing RCVBT, however, this implement still used the elder one.

class pcapkit.foundation.reassembly.ip.IP(*, strict=True, store=True)[source]

Bases: ReassemblyBase[Packet[_AT], Datagram[_AT], tuple[_AT, _AT, int, TransType], Buffer[_AT]], Generic[_AT]

Reassembly for IP payload.

Parameters:
  • strict (bool) – if return all datagrams (including those not implemented) when submit

  • store (bool) – if store reassembled datagram in memory, i.e., self._dtgram (if not, datagram will be discarded after callback)

Important

This class is not intended to be instantiated directly, but rather used as a base class for the protocol-aware reassembly classes.

reassembly(info)[source]

Reassembly procedure.

Parameters:

info (Packet[TypeVar(_AT, IPv4Address, IPv6Address)]) – info dict of packets to be reassembled

Return type:

None

submit(buf, *, bufid, checked=False)[source]

Submit reassembled payload.

Parameters:
  • buf (Buffer[TypeVar(_AT, IPv4Address, IPv6Address)]) – buffer dict of reassembled packets

  • bufid (tuple[TypeVar(_AT, IPv4Address, IPv6Address), TypeVar(_AT, IPv4Address, IPv6Address), int, TransType]) – buffer identifier

  • checked (bool) – buffer consistency checked flag

Return type:

list[Datagram[TypeVar(_AT, IPv4Address, IPv6Address)]]

Returns:

Reassembled packets.

Data Models

class pcapkit.foundation.reassembly.data.ip.Packet(*args: VT, **kwargs: VT)[source]

Bases: Info, Generic[_AT]

Data model for IPv4 and/or IPv6 packet representation..

bufid: BufferID

Buffer ID.

num: int

Original packet range number.

fo: int

Fragment offset.

ihl: int

Internet header length.

mf: bool

More fragments flag.

tl: int

Total length, header included.

header: bytes

Raw bytes type header.

payload: bytearray

Raw bytearray type payload.

pcapkit.foundation.reassembly.data.ip.BufferID: Tuple[_AT, _AT, int, pcapkit.const.reg.transtype.TransType]

Data module for buffer ID.

class pcapkit.foundation.reassembly.data.ip.Buffer(*args: VT, **kwargs: VT)[source]

Bases: Info, Generic[_AT]

Data model for IPv4 and/or IPv6 reassembly buffer entry.

TDL: int

Total data length.

RCVBT: bytearray

Fragment received bit table.

index: list[int]

List of reassembled packets.

header: bytes

Header buffer.

datagram: bytearray

Data buffer, holes set to b'\x00'.

class pcapkit.foundation.reassembly.data.ip.DatagramID(*args: VT, **kwargs: VT)[source]

Bases: Info, Generic[_AT]

Data model for IPv4 and/or IPv6 original packet identifier.

src: _AT

Source address.

dst: _AT

Destination address.

id: int

IP protocol identifier.

proto: TransType

Payload protocol type.

class pcapkit.foundation.reassembly.data.ip.Datagram(*args: VT, **kwargs: VT)[source]

Bases: Info, Generic[_AT]

Data model for IPv4 and/or IPv6 reassembled datagram.

completed: bool

Completed flag.

id: DatagramID[_AT]

Original packet identifier.

index: tuple[int, ...]

Packet numbers.

header: bytes

Initial IP header.

payload: bytes | tuple[bytes, ...]

Reassembled IP payload.

packet: Optional[Protocol]

Parsed IP payload.

Type Variables

pcapkit.foundation.reassembly.data.ip._AT: ipaddress.IPv4Address | ipaddress.IPv4Address