OSPF - Open Shortest Path First¶
pcapkit.protocols.link.ospf
contains
OSPF
only,
which implements extractor for Open Shortest Path
First (OSPF) [*], whose structure is described
as below:
Octets |
Bits |
Name |
Description |
---|---|---|---|
0 |
0 |
|
Version Number |
0 |
0 |
|
Type |
0 |
1 |
|
Packet Length (header included) |
0 |
2 |
|
Router ID |
0 |
4 |
|
Area ID |
0 |
6 |
|
Checksum |
0 |
7 |
|
Authentication Type |
1 |
8 |
|
Authentication |
- class pcapkit.protocols.link.ospf.OSPF(file=None, length=None, **kwargs)[source]¶
-
This class implements Open Shortest Path First.
- 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: 1>, type_default=None, type_namespace=None, type_reversed=False, router_id='0.0.0.0', area_id='0.0.0.0', checksum=b'\\x00\\x00', auth_type=<Authentication.No_Authentication: 0>, 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'', **kwargs)[source]¶
Make (construct) packet data.
- Parameters:
version (
int
) – OSPF version number.type (
Packet
|IntEnum
|IntEnum
|str
|int
) – OSPF packet type.type_default (
Optional
[int
]) – Default value fortype
if not specified.type_namespace (
Union
[dict
[str
,int
],dict
[int
,str
],Type
[IntEnum
],Type
[IntEnum
],None
]) – Namespace fortype
.type_reversed (
bool
) – Reverse namespace fortype
.router_id (
IPv4Address
|str
|bytes
|bytearray
) – Router ID.area_id (
IPv4Address
|str
|bytes
|bytearray
) – Area ID.checksum (
bytes
) – Checksum.auth_type (
Authentication
|IntEnum
|IntEnum
|str
|int
) – Authentication type.auth_type_default (
Optional
[int
]) – Default value forauth_type
if not specified.auth_type_namespace (
Union
[dict
[str
,int
],dict
[int
,str
],Type
[IntEnum
],Type
[IntEnum
],None
]) – Namespace forauth_type
.auth_type_reversed (
bool
) – Reverse namespace forauth_type
.auth_data (
bytes
|CrytographicAuthentication
|CrytographicAuthentication
) – Authentication data.payload (
bytes
|ProtocolBase
|Schema
) – Payload data.**kwargs (
Any
) – Arbitrary keyword arguments.
- Return type:
- Returns:
Constructed packet data.
- _read_encrypt_auth(schema)[source]¶
Read Authentication field when Cryptographic Authentication is employed, i.e.
autype
is2
.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 (
CrytographicAuthentication
) – 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_type – Authentication type.
auth_data (
bytes
|CrytographicAuthentication
|CrytographicAuthentication
) – Authentication data.
- Return type:
- Returns:
Authentication bytes.
- classmethod __index__()[source]¶
Numeral registry index of the protocol.
- Raises:
UnsupportedCall – This protocol has no registry entry.
- Return type:
Header Schemas¶
- class pcapkit.protocols.schema.link.ospf.OSPF(dict_=None, **kwargs)[source]¶
Bases:
Schema
Header schema for OSPF packet.
- version: int = <UInt8Field version>¶
Version.
- type: Enum_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: Enum_Authentication = <EnumField auth_type>¶
Authentication type.
- auth_data: bytes | CrytographicAuthentication = <SwitchField auth_data>¶
Authentication data.
- payload: bytes = <PayloadField payload>¶
Payload.
- class pcapkit.protocols.schema.link.ospf.CrytographicAuthentication(dict_=None, **kwargs)[source]¶
Bases:
Schema
Header schema for OSPF cryptographic authentication.
- reserved: bytes = <PaddingField reserved>¶
Reserved bytes.
- key_id: int = <UInt8Field key_id>¶
Key ID.
- len: int = <UInt8Field len>¶
Length.
- seq: int = <UInt32Field seq>¶
Sequence number.
Auxiliary Functions¶
- pcapkit.protocols.schema.link.ospf.ospf_auth_data_selector(pkt)[source]¶
Selector function for
OSPF.auth_data
field.- Parameters:
- Return type:
- Returns:
If
OSPF.auth_type
is 2, aSchemaField
wrappedCrytographicAuthentication
instance.Otherwise, a
BytesField
instance.
Data Models¶
- class pcapkit.protocols.data.link.ospf.OSPF(*args: VT, **kwargs: VT)[source]¶
Bases:
Protocol
Data model for OSPF packet.
- 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 | CrytographicAuthentication¶
Authentication.
- class pcapkit.protocols.data.link.ospf.CrytographicAuthentication(*args: VT, **kwargs: VT)[source]¶
Bases:
Data
Data model for OSPF crytographic authentication.
- key_id: int¶
Key ID.
- len: int¶
Authentication data length.
- seq: int¶
Cryptographic sequence number.
Footnotes