OSPF - Open Shortest Path First¶
pcapkit.protocols.application.ospf contains
OSPF only,
which implements an extractor for Open Shortest Path
First (OSPF) [*], whose structure is described
as below:
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.5.0: Moved here from pcapkit.protocols.link.ospf, with its data model and
header schema. OSPF derives
from Application, so
its layer is 'Application' (#719).
Removed in version 1.5.0: pcapkit.protocols.link.ospf, pcapkit.protocols.data.link.ospf and
pcapkit.protocols.schema.link.ospf, the OSPF name that
pcapkit.protocols.link, pcapkit.protocols.data.link and
pcapkit.protocols.schema.link each exported, and the
OSPF_CrytographicAuthentication name that
pcapkit.protocols.data.link and pcapkit.protocols.schema.link
exported, with no alias (#719, #1090).
Changed in version 1.5.0: A rebuild keeps the parsed Packet Length and the octets past it, where
make() recomputed the
length from the payload and dropped those octets; it takes them as
packet_length and trailer (#1249, #1455).
- class pcapkit.protocols.application.ospf.OSPF(file=None, length=None, **kwargs)[source]¶
Bases:
Application[OSPF,OSPF]This class implements Open Shortest Path First.
A routing protocol computes the forwarding table rather than forwarding packets, so it is a user of the stack rather than part of its forwarding path. RFC 1812 Section 7 places it accordingly, titling that chapter “APPLICATION LAYER - ROUTING PROTOCOLS” with OSPF at §7.2.2, while RFC 1812 Section 4.1 confines the internet layer to IP, ICMP and IGMP. Hence
Applicationas the base, andlayer == 'Application'. See Protocol Layer Placement.Note
The subpackage does not track the dispatch tier. OSPF is dispatched from
Internet.__proto__atOSPFIGP(IANA protocol number 89), since IP is what carries it.- read(length=None, **kwargs)[source]¶
Read Open Shortest Path First.
Structure of OSPF 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 | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
- make(version=2, type=Packet.Hello, type_default=None, type_namespace=None, type_reversed=False, packet_length=None, router_id='0.0.0.0', area_id='0.0.0.0', checksum=b'\x00\x00', auth_type=Authentication.No_Authentication, auth_type_default=None, auth_type_namespace=None, auth_type_reversed=False, 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.type (
Packet|IntEnum|aenum.IntEnum|str|int) – OSPF packet type.type_default (
int|None) – Default value fortypeif not specified.type_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[aenum.IntEnum] |None) – Namespace fortype.type_reversed (
bool) – Reverse namespace fortype.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) – Checksum.auth_type (
Authentication|IntEnum|aenum.IntEnum|str|int) – Authentication type.auth_type_default (
int|None) – Default value forauth_typeif not specified.auth_type_namespace (
dict[str,int] |dict[int,str] |Type[IntEnum] |Type[aenum.IntEnum] |None) – Namespace forauth_type.auth_type_reversed (
bool) – Reverse namespace forauth_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
auth_datais of an invalid type, isbytesthat are not exactly 8 octets long, or is adictmissing a required key; or ifpacket_lengthis not anintin0..65535.
Changed in version 1.5.0:
packet_lengthis a new parameter beforerouter_id, so a 1.4.x positional argument meant forrouter_idor a later parameter lands one parameter early (#1249).
- _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, or is adictmissing a required key.
- _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.The description below uses
self.__class__.__name__rather thanself.alias, becausealiashere readsself._version, whichread()only assigns from the wire – unavailable to a construction-only instance that never went throughread().
Header Schemas¶
- class pcapkit.protocols.schema.application.ospf.OSPF(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 OSPF packet.
- 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.schema.application.ospf.CryptographicAuthentication(reserved=NO_VALUE, key_id=NO_VALUE, len=NO_VALUE, seq=NO_VALUE, *, __packet__=None, **kwargs)[source]¶
Bases:
SchemaHeader schema for OSPF 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).
Auxiliary Functions¶
- pcapkit.protocols.schema.application.ospf.ospf_auth_data_selector(pkt)[source]¶
Selector function for
OSPF.auth_datafield.- Parameters:
- Return type:
- Returns:
A
SchemaFieldwrappedCryptographicAuthenticationinstance ifOSPF.auth_typeis 2, and aBytesFieldinstance otherwise.
Data Models¶
- class pcapkit.protocols.data.application.ospf.OSPF(version, type, len, router_id, area_id, chksum, autype)[source]¶
Bases:
ProtocolData model for OSPF packet.
- router_id: IPv4Address¶
Router ID.
- area_id: IPv4Address¶
Area ID.
- autype: Authentication¶
Authentication type.
- auth: bytes | CryptographicAuthentication¶
Authentication.
- class pcapkit.protocols.data.application.ospf.CryptographicAuthentication(reserved, key_id, len, seq)[source]¶
Bases:
DataData model for OSPF 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).
Footnotes