OSPFv2 - Open Shortest Path First Version 2¶
pcapkit.protocols.application.ospfv2.protocol contains
OSPFv2, which implements an
extractor for Open Shortest Path First version 2 (OSPFv2) [RFC 2328], whose
header (RFC 2328 Appendix A.3.1) is:
Octets |
Bits |
Name |
Description |
|---|---|---|---|
0 |
0 |
|
Version Number |
1 |
8 |
|
Type |
2 |
16 |
|
Packet Length (header included) |
4 |
32 |
|
Router ID |
8 |
64 |
|
Area ID |
12 |
96 |
|
Checksum |
14 |
112 |
|
Authentication Type |
16 |
128 |
|
Authentication |
Added in version 1.8.1: Takes over the parsing that OSPF
carried, with its header schema and data model (#3105).
- class pcapkit.protocols.application.ospfv2.protocol.OSPFv2(file, length=None, /, *, version=None, layer=None, protocol=None, context=None)[source]¶
-
This class implements Open Shortest Path First version 2.
Properties
Methods
- read(length=None, **kwargs)[source]¶
Read Open Shortest Path First version 2.
Structure of OSPFv2 header [RFC 2328]:
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:
- Return type:
- Returns:
Parsed packet data.
- Raises:
ProtocolError – If the Version is not 2 (RFC 2328 Section 8.2).
- make(*, version=2, 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,2.packet_length (
int|None) – Packet length (header included). If not given, it is computed as 24 plus the length ofpayload. Give it explicitly whenpayloadcarries octets outside the OSPF packet, or pass those astrailerinstead.router_id (
IPv4Address|str|bytes|bytearray) – Router ID.area_id (
IPv4Address|str|bytes|bytearray) – Area ID.checksum (
bytes|None) – Checksum; ifNoneandCHECKSUM_COMPUTEis on, computed for version 2 over the packet but its authentication field (RFC 2328 Appendix A.3.1); zero otherwise, as cryptographic authentication leaves it (RFC 2328 Appendix D.4.3).auth_type (
Authentication|int) – Authentication type.auth_data (
bytes|CryptographicAuthentication|CryptographicAuthentication|dict[str,Any]) – Authentication data: 8 octets, or, under cryptographic authentication, also a schema, a data model, or thedictform of a data model.payload (
bytes|ProtocolBase|Schema) – Payload data.trailer (
bytes) – Octets after the packet, outside the Packet Length, such as the message digest appended under cryptographic authentication (RFC 2328 Appendix D.4.3); written as is.**kwargs (
Any) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- Raises:
ProtocolError – If
versionis not 2; ifauth_datais of an invalid type, isbytesthat are not exactly 8 octets long, is adictmissing a required key, or carriesreservedoctets that are not two; ifpacket_lengthis not anintin0..65535; ifchecksumis not two octets; or iftype(8 bits) orauth_type(16 bits) is a name, abool, or a member or code its field cannot carry.
Data Models
Utilities
- _read_encrypt_auth(schema)[source]¶
Read Authentication field when Cryptographic Authentication is employed, i.e.
autypeis2.Structure of Cryptographic Authentication [RFC 2328]:
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 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | 0 | Key ID | Auth Data Len | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Cryptographic sequence number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- Parameters:
schema (
CryptographicAuthentication) – parsed authentication data- Return type:
- Returns:
Parsed packet data.
- _make_encrypt_auth(auth_data)[source]¶
Make Authentication field when Cryptographic Authentication is employed.
- Parameters:
auth_data (
bytes|CryptographicAuthentication|CryptographicAuthentication|dict[str,Any]) – Authentication data, as raw octets, a schema, a data model, or thedictform of a data model.- Return type:
- Returns:
Authentication schema.
- Raises:
ProtocolError – If
auth_datais of an invalid type, isbytesthat are not exactly 8 octets long, is adictmissing a required key, or carriesreservedoctets that are not two.
- _make_id_numbers(id)[source]¶
Make router and area IDs.
- Parameters:
id (
IPv4Address|str|bytes|bytearray) – ID.- Return type:
- Returns:
ID bytes.
- Raises:
FieldValueError – If
idis abool(seeparse_ip_address()).
Notes
Latent rather than live: nothing in this module calls this method (
make()buildsrouter_id/area_idstraight from its own arguments), so the only caller is a unit test. It is routed throughparse_ip_address()anyway, so that a future caller passing aboolgetsFieldValueErrorrather than a silent0.0.0.1.
Header Schemas¶
- class pcapkit.protocols.application.ospfv2.schema.OSPFv2(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:
SchemaHeader schema for OSPFv2 packet: the 24-octet header of RFC 2328 Appendix A.3.1.
Added in version 1.8.1: Renamed from
OSPFinpcapkit.protocols.application.ospf.schema(#3105).- router_id: IPv4Address = <IPv4AddressField router_id>¶
Router ID.
- area_id: IPv4Address = <IPv4AddressField area_id>¶
Area ID.
- auth_type: Authentication = <EnumField auth_type>¶
Authentication type.
- auth_data: bytes | CryptographicAuthentication = <SwitchField auth_data>¶
Authentication data.
- trailer: bytes = <PayloadField trailer>¶
Octets captured past the Packet Length, such as the message digest that cryptographic authentication appends (RFC 2328 Appendix D.4.3); compare
IPv4.trailer.
- class pcapkit.protocols.application.ospfv2.schema.CryptographicAuthentication(reserved=NO_VALUE, key_id=NO_VALUE, len=NO_VALUE, seq=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for OSPFv2 cryptographic authentication.
Added in version 1.5.0: Renamed from
CrytographicAuthentication, whichpcapkit.protocols.schemaexported asOSPF_CrytographicAuthentication(#1090).Removed in version 1.5.0:
CrytographicAuthenticationandOSPF_CrytographicAuthentication, with no alias (#1090).Changed in version 1.8.1: Moved here from
pcapkit.protocols.application.ospf.schema(#3105).
Auxiliary Functions¶
- pcapkit.protocols.application.ospfv2.schema.ospf_auth_data_selector(pkt)[source]¶
Selector function for
OSPFv2.auth_datafield.- Parameters:
- Return type:
- Returns:
A
SchemaFieldwrappedCryptographicAuthenticationinstance ifOSPFv2.auth_typeis 2, and aBytesFieldinstance otherwise.
Changed in version 1.8.1: Moved here from
pcapkit.protocols.application.ospf.schema(#3105).
Data Models¶
- class pcapkit.protocols.application.ospfv2.data.OSPFv2(version, type, len, router_id, area_id, chksum, autype)[source]¶
Bases:
ProtocolData model for OSPFv2 packet (RFC 2328 Appendix A.3.1).
Added in version 1.8.1: Renamed from
OSPFinpcapkit.protocols.application.ospf.data(#3105).- router_id: IPv4Address¶
Router ID.
- area_id: IPv4Address¶
Area ID.
- autype: Authentication¶
Authentication type.
- auth: bytes | CryptographicAuthentication¶
Authentication.
- checksum_status: ChecksumStatus¶
Outcome of verifying
chksum, present only for version 2 whenCHECKSUM_VERIFYis on.
- class pcapkit.protocols.application.ospfv2.data.CryptographicAuthentication(reserved, key_id, len, seq)[source]¶
Bases:
DataData model for OSPFv2 cryptographic authentication.
Added in version 1.5.0: Renamed from
CrytographicAuthentication, whichpcapkit.protocols.dataexported asOSPF_CrytographicAuthentication(#1090).Removed in version 1.5.0:
CrytographicAuthenticationandOSPF_CrytographicAuthentication, with no alias (#1090).Changed in version 1.8.1: Moved here from
pcapkit.protocols.application.ospf.data(#3105).