1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
//! OSPFv2 (RFC 2328) wire constants.
//!
//! Codepoints and fixed lengths taken from RFC 2328 (OSPF Version 2). Each
//! constant cites its defining RFC section in a line comment. These values are
//! the codepoints the OSPF builder, decode, and spec steps consume.
// ---------------------------------------------------------------------------
// Version (RFC 2328 §A.3.1)
// ---------------------------------------------------------------------------
/// OSPF protocol version carried in the common header. RFC 2328 §A.3.1.
pub const OSPF_VERSION_2: u8 = 2;
// ---------------------------------------------------------------------------
// Packet types (RFC 2328 §A.3.1)
// ---------------------------------------------------------------------------
/// Hello packet type. RFC 2328 §A.3.1 / §A.3.2.
pub const OSPF_TYPE_HELLO: u8 = 1;
/// Database Description packet type. RFC 2328 §A.3.1 / §A.3.3.
pub const OSPF_TYPE_DATABASE_DESCRIPTION: u8 = 2;
/// Link State Request packet type. RFC 2328 §A.3.1 / §A.3.4.
pub const OSPF_TYPE_LINK_STATE_REQUEST: u8 = 3;
/// Link State Update packet type. RFC 2328 §A.3.1 / §A.3.5.
pub const OSPF_TYPE_LINK_STATE_UPDATE: u8 = 4;
/// Link State Acknowledgment packet type. RFC 2328 §A.3.1 / §A.3.6.
pub const OSPF_TYPE_LINK_STATE_ACK: u8 = 5;
// ---------------------------------------------------------------------------
// Fixed lengths (RFC 2328 §A.3.1)
// ---------------------------------------------------------------------------
/// OSPF common header length, in octets. RFC 2328 §A.3.1.
pub const OSPF_HEADER_LEN: usize = 24;
/// OSPF Authentication field length, in octets. RFC 2328 §A.3.1.
pub const OSPF_AUTH_LEN: usize = 8;
// ---------------------------------------------------------------------------
// Options field bits (RFC 2328 §A.2, extended by RFC 3101, RFC 5250, et al.)
// ---------------------------------------------------------------------------
//
// The OSPFv2 Options field is a single octet that appears in the Hello,
// Database Description, and LSA-header (RFC 2328 §A.4.1) records and advertises
// each router's optional capabilities. The bit values below are the canonical
// definitions consumed everywhere in the OSPF module; the NSSA-LSA P-bit
// (`OSPF_OPTIONS_NP`) is re-exported through `lsa::nssa` for backward
// compatibility.
/// T/MT-bit (0x01) of the OSPFv2 Options field: historical TOS-routing /
/// multi-topology capability (RFC 2328 §A.2; the original RFC 1583 T-bit, later
/// repurposed as the MT-bit by RFC 4915).
pub const OSPF_OPTIONS_MT: u8 = 0x01;
/// E-bit (0x02) of the OSPFv2 Options field: the router accepts and forwards
/// AS-External-LSAs (RFC 2328 §A.2). Cleared inside a stub area.
pub const OSPF_OPTIONS_E: u8 = 0x02;
/// MC-bit (0x04) of the OSPFv2 Options field: the router forwards IP multicast
/// datagrams per the MOSPF specification (RFC 2328 §A.2, RFC 1584).
pub const OSPF_OPTIONS_MC: u8 = 0x04;
/// N/P-bit (0x08) of the OSPFv2 Options field. In a Hello/DD header this is the
/// N-bit signalling NSSA support (RFC 3101 §2.4); in a Type-7 NSSA-LSA header
/// it is the P-bit requesting Type-7-to-Type-5 translation (RFC 3101 §2.5).
pub const OSPF_OPTIONS_NP: u8 = 0x08;
/// L/EA-bit (0x10) of the OSPFv2 Options field: the router supports the
/// link-local signalling / external-attributes extension (RFC 2328 §A.2,
/// RFC 5613 / the historical RFC 1793 EA-bit position).
pub const OSPF_OPTIONS_L: u8 = 0x10;
/// DC-bit (0x20) of the OSPFv2 Options field: the router supports OSPF over
/// demand circuits (RFC 2328 §A.2, RFC 1793).
pub const OSPF_OPTIONS_DC: u8 = 0x20;
/// O-bit (0x40) of the OSPFv2 Options field: the router is opaque-LSA capable
/// (RFC 5250 §2.1; advertised in Database Description packets only).
pub const OSPF_OPTIONS_O: u8 = 0x40;
/// DN-bit (0x80) of the OSPFv2 Options field: the down-bit used for BGP/OSPF VPN
/// loop avoidance (RFC 2328 §A.2 reserved position, RFC 4576).
pub const OSPF_OPTIONS_DN: u8 = 0x80;
// ---------------------------------------------------------------------------
// Authentication types (RFC 2328 §A.3.1, §D)
// ---------------------------------------------------------------------------
/// Null authentication (AuType 0). RFC 2328 §D.1.
pub const OSPF_AUTYPE_NULL: u16 = 0;
/// Simple password authentication (AuType 1). RFC 2328 §D.2.
pub const OSPF_AUTYPE_SIMPLE: u16 = 1;
/// Cryptographic authentication (AuType 2). RFC 2328 §D.3.
pub const OSPF_AUTYPE_CRYPTOGRAPHIC: u16 = 2;
// ---------------------------------------------------------------------------
// Display helpers
// ---------------------------------------------------------------------------
/// Short human-readable name for an OSPF packet Type code (RFC 2328 §A.3.1),
/// used by `summary()` and `inspection_fields()`. Unrecognized codes map to
/// `"Unknown"`.
/// Render the set bits of an OSPFv2 Options octet (RFC 2328 §A.2) as a
/// `|`-joined label list, used by `summary()` and `inspection_fields()`.
///
/// Bits are emitted in ascending bit-value order (`MT|E|MC|NP|L|DC|O|DN`), so a
/// value of `0x42` renders as `"E|O"`. A value with no recognized bits set
/// (including `0x00`) renders as the empty string, letting callers fall back to
/// the raw hex value.
/// Short human-readable name for an OSPF Authentication Type (AuType) code
/// (RFC 2328 §A.3.1, §D), used by `inspection_fields()`. Unrecognized codes map
/// to `"Unknown"`.