OSPFv1 - Open Shortest Path First Version 1

pcapkit.protocols.application.ospfv1.protocol contains OSPFv1, which implements an extractor for Open Shortest Path First version 1 (OSPFv1) [RFC 1131], obsoleted by RFC 1247. Its header (RFC 1131 Section A.2) is laid out as OSPFv2’s:

Octets

Bits

Name

Description

0

0

ospf.version

Version Number

1

8

ospf.type

Type

2

16

ospf.len

Packet Length (header included)

4

32

ospf.router_id

Router ID

8

64

ospf.area_id

Area ID

12

96

ospf.chksum

Checksum

14

112

ospf.autype

Authentication Type

16

128

ospf.auth

Authentication

It defines packet types 1 to 5 alone (Section A.2) and AuType 0 and 1 alone (Appendix E), which Packet and Authentication name, rather than OSPFv2’s IANA registries. Its Authentication field is kept as captured: the cryptographic authentication of RFC 2328 Appendix D.3 is OSPFv2’s.

Added in version 1.8.1.

class pcapkit.protocols.application.ospfv1.protocol.OSPFv1(file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]

Bases: OSPF[OSPFv1, OSPFv1]

This class implements Open Shortest Path First version 1.

Added in version 1.8.1.

Properties

property length: Literal[24]

Header length of current protocol.

Methods

classmethod id()[source]

Index ID of the protocol.

Return type:

tuple[Literal['OSPFv1']]

Returns:

Index ID of the protocol, narrowed to this member.

read(length=None, **kwargs)[source]

Read Open Shortest Path First version 1.

Structure of OSPFv1 header [RFC 1131]:

 0                   1                   2                   3
 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|   Version #   |     Type      |         Packet length         |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                          Router ID                            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                           Area ID                             |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|           Checksum            |             AuType            |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Authentication                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|                       Authentication                          |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Parameters:
  • length (int | None) – Length of packet data.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

OSPFv1

Returns:

Parsed packet data.

Raises:

ProtocolError – If the Version is not 1.

make(*, version=1, type=Packet.Hello, packet_length=None, router_id='0.0.0.0', area_id='0.0.0.0', checksum=None, auth_type=Authentication.No_authentication, auth_data=b'\x00\x00\x00\x00\x00\x00\x00\x00', payload=b'', trailer=b'', **kwargs)[source]

Make (construct) packet data.

Parameters:
  • version (int) – OSPF version number, 1.

  • type (Packet | int) – OSPF packet type.

  • packet_length (int | None) – Packet length (header included). If not given, it is computed as 24 plus the length of payload.

  • router_id (IPv4Address | str | bytes) – Router ID.

  • area_id (IPv4Address | str | bytes) – Area ID.

  • checksum (bytes | None) – Checksum; if None and CHECKSUM_COMPUTE is on, computed over the packet but its Authentication field (RFC 1131 Section A.2); zero otherwise.

  • auth_type (Authentication | int) – Authentication type.

  • auth_data (bytes) – Authentication data, 8 octets.

  • payload (bytes | ProtocolBase | Schema) – Payload data.

  • trailer (bytes) – Octets after the packet, outside the Packet Length; written as is.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

OSPFv1

Returns:

Constructed packet data.

Raises:

ProtocolError – If version is not 1; if auth_data is not 8 octets of bytes; if packet_length is not an int in 0..65535; if checksum is not two octets; or if type (8 bits) or auth_type (16 bits) is a name, a bool, or a member or code its field cannot carry.

Data Models

__length_hint__()[source]

Return an estimated length for the object.

Return type:

Literal[24]

Utilities

classmethod _make_data(data)[source]

Create key-value pairs from data for protocol construction.

Parameters:

data (OSPFv1) – protocol data

Return type:

dict[str, Any]

Returns:

Key-value pairs for protocol construction.

Header Schemas

class pcapkit.protocols.application.ospfv1.schema.OSPFv1(version=NO_VALUE, type=NO_VALUE, length=NO_VALUE, router_id=NO_VALUE, area_id=NO_VALUE, checksum=NO_VALUE, auth_type=NO_VALUE, auth_data=NO_VALUE, payload=NO_VALUE, trailer=NO_VALUE, *, __packet__=None, **kwargs)[source]

Bases: Schema

Header schema for OSPFv1 packet: the 24-octet header of RFC 1131 Section A.2, laid out as OSPFv2’s.

RFC 1131 defines AuType 0 and 1 alone (Appendix E), as Authentication names them, and each leaves the 64-bit Authentication field to the scheme, so the field is kept as its octets whatever the AuType.

Added in version 1.8.1.

version: int = <UInt8Field version>

Version.

type: Packet = <EnumField type>

Type.

length: int = <UInt16Field length>

Length.

router_id: IPv4Address = <IPv4AddressField router_id>

Router ID.

area_id: IPv4Address = <IPv4AddressField area_id>

Area ID.

checksum: bytes = <BytesField checksum>

Checksum.

auth_type: Authentication = <EnumField auth_type>

Authentication type.

auth_data: bytes = <BytesField auth_data>

Authentication data.

payload: bytes = <PayloadField payload>

Payload.

trailer: bytes = <PayloadField trailer>

Octets captured past the Packet Length; compare OSPFv2.trailer.

Data Models

class pcapkit.protocols.application.ospfv1.data.OSPFv1(version, type, len, router_id, area_id, chksum, autype, auth)[source]

Bases: Protocol

Data model for OSPFv1 packet (RFC 1131 Section A.2).

Added in version 1.8.1.

version: int

Version number.

type: Packet

Type.

len: int

Packet length (header included).

router_id: IPv4Address

Router ID.

area_id: IPv4Address

Area ID.

chksum: bytes

Checksum.

autype: Authentication

Authentication type.

auth: bytes

Authentication, the 64-bit field as captured.

trailer: bytes

Octets captured past the Packet Length, present only when there are any.

checksum_status: ChecksumStatus

Outcome of verifying chksum, present only when CHECKSUM_VERIFY is on.