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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
//! BGP-4 (RFC 4271) wire constants.
//!
//! Codepoints copied verbatim (name and value) from the codepoint authority
//! table, `.agents/docs/bgp-codepoints.md`, which is itself derived from and
//! kept in sync with `.agents/docs/bgp-manifest.md` (the full RFC/IANA
//! evidence record). Each constant cites its defining RFC in a line comment.
//! On any disagreement, the authority table — not this file — is the source of
//! truth.
//!
//! Message-type and attribute-flag codepoints carry the `BGP_TYPE_*` and
//! `BGP_ATTR_FLAG_*` names used by the builder, decode, and spec steps;
//! path-attribute type codes keep the authority's `ATTR_*` prefix.
// ---------------------------------------------------------------------------
// Fixed protocol constants (RFC 4271 §4.1, §4.2)
// ---------------------------------------------------------------------------
/// BGP TCP listen port. RFC 4271 §1 / IANA service registry.
pub const BGP_PORT: u16 = 179;
/// BGP protocol version carried in OPEN. RFC 4271 §4.2.
pub const BGP_VERSION: u8 = 4;
/// BGP message header Marker field length, in octets. RFC 4271 §4.1.
pub const BGP_MARKER_LEN: usize = 16;
/// BGP message header length (Marker + Length + Type), in octets. RFC 4271 §4.1.
pub const BGP_HEADER_LEN: usize = 19;
/// Maximum BGP message length, in octets. RFC 4271 §4.1.
pub const BGP_MAX_MESSAGE_LEN: usize = 4096;
/// Reserved 2-octet AS number signalling a 4-octet AS in AS4 attributes. RFC 6793 §9.
pub const AS_TRANS: u16 = 23456;
/// Minimum OPEN message length, in octets. RFC 4271 §4.2.
pub const BGP_MIN_OPEN_LEN: usize = 29;
/// Minimum UPDATE message length, in octets. RFC 4271 §4.3.
pub const BGP_MIN_UPDATE_LEN: usize = 23;
/// Minimum NOTIFICATION message length, in octets. RFC 4271 §4.5.
pub const BGP_MIN_NOTIFICATION_LEN: usize = 21;
/// KEEPALIVE message length (header only), in octets. RFC 4271 §4.4.
pub const BGP_KEEPALIVE_LEN: usize = 19;
// ---------------------------------------------------------------------------
// Message types (IANA `bgp-parameters-1`)
// ---------------------------------------------------------------------------
/// OPEN message type. RFC 4271.
pub const BGP_TYPE_OPEN: u8 = 1;
/// UPDATE message type. RFC 4271.
pub const BGP_TYPE_UPDATE: u8 = 2;
/// NOTIFICATION message type. RFC 4271.
pub const BGP_TYPE_NOTIFICATION: u8 = 3;
/// KEEPALIVE message type. RFC 4271.
pub const BGP_TYPE_KEEPALIVE: u8 = 4;
/// ROUTE-REFRESH message type. RFC 2918.
pub const BGP_TYPE_ROUTE_REFRESH: u8 = 5;
// ---------------------------------------------------------------------------
// OPEN optional parameter types (IANA `bgp-parameters-11`)
// ---------------------------------------------------------------------------
/// Authentication optional parameter type (deprecated). RFC 4271 / RFC 5492.
pub const OPT_PARAM_AUTHENTICATION: u8 = 1;
/// Capabilities optional parameter type. RFC 5492.
pub const OPT_PARAM_CAPABILITIES: u8 = 2;
/// Extended optional-parameters-length marker. RFC 9072.
pub const OPT_PARAM_EXTENDED_LENGTH: u8 = 255;
// ---------------------------------------------------------------------------
// Capability codes (IANA `capability-codes-2`)
// ---------------------------------------------------------------------------
/// Multiprotocol Extensions capability. RFC 2858 (obsoleted by RFC 4760).
pub const CAP_MULTIPROTOCOL: u8 = 1;
/// Route Refresh capability. RFC 2918.
pub const CAP_ROUTE_REFRESH: u8 = 2;
/// Graceful Restart capability. RFC 4724.
pub const CAP_GRACEFUL_RESTART: u8 = 64;
/// Four-octet AS Number capability. RFC 6793.
pub const CAP_FOUR_OCTET_AS: u8 = 65;
/// ADD-PATH capability. RFC 7911.
pub const CAP_ADD_PATH: u8 = 69;
/// Enhanced Route Refresh capability (preserve only). RFC 7313.
pub const CAP_ENHANCED_ROUTE_REFRESH: u8 = 70;
/// Prestandard Route Refresh capability (deprecated; preserve only). RFC 8810.
pub const CAP_ROUTE_REFRESH_OLD: u8 = 128;
// ---------------------------------------------------------------------------
// Path attribute type codes (IANA `bgp-parameters-2`)
// ---------------------------------------------------------------------------
/// ORIGIN path attribute. RFC 4271.
pub const ATTR_ORIGIN: u8 = 1;
/// AS_PATH path attribute. RFC 4271.
pub const ATTR_AS_PATH: u8 = 2;
/// NEXT_HOP path attribute. RFC 4271.
pub const ATTR_NEXT_HOP: u8 = 3;
/// MULTI_EXIT_DISC path attribute. RFC 4271.
pub const ATTR_MULTI_EXIT_DISC: u8 = 4;
/// LOCAL_PREF path attribute. RFC 4271.
pub const ATTR_LOCAL_PREF: u8 = 5;
/// ATOMIC_AGGREGATE path attribute. RFC 4271.
pub const ATTR_ATOMIC_AGGREGATE: u8 = 6;
/// AGGREGATOR path attribute. RFC 4271.
pub const ATTR_AGGREGATOR: u8 = 7;
/// COMMUNITIES path attribute. RFC 1997.
pub const ATTR_COMMUNITIES: u8 = 8;
/// ORIGINATOR_ID path attribute (preserve only). RFC 4456.
pub const ATTR_ORIGINATOR_ID: u8 = 9;
/// CLUSTER_LIST path attribute (preserve only). RFC 4456.
pub const ATTR_CLUSTER_LIST: u8 = 10;
/// MP_REACH_NLRI path attribute. RFC 4760.
pub const ATTR_MP_REACH_NLRI: u8 = 14;
/// MP_UNREACH_NLRI path attribute. RFC 4760.
pub const ATTR_MP_UNREACH_NLRI: u8 = 15;
/// EXTENDED COMMUNITIES path attribute. RFC 4360.
pub const ATTR_EXTENDED_COMMUNITIES: u8 = 16;
/// AS4_PATH path attribute. RFC 6793.
pub const ATTR_AS4_PATH: u8 = 17;
/// AS4_AGGREGATOR path attribute. RFC 6793.
pub const ATTR_AS4_AGGREGATOR: u8 = 18;
/// LARGE COMMUNITY path attribute. RFC 8092.
pub const ATTR_LARGE_COMMUNITY: u8 = 32;
// ---------------------------------------------------------------------------
// Attribute flags octet (RFC 4271 §4.3)
// ---------------------------------------------------------------------------
/// Optional bit: 1 = optional, 0 = well-known. RFC 4271 §4.3.
pub const BGP_ATTR_FLAG_OPTIONAL: u8 = 0x80;
/// Transitive bit: 1 = transitive; well-known MUST be 1. RFC 4271 §4.3.
pub const BGP_ATTR_FLAG_TRANSITIVE: u8 = 0x40;
/// Partial bit: 1 = partial, 0 = complete. RFC 4271 §4.3.
pub const BGP_ATTR_FLAG_PARTIAL: u8 = 0x20;
/// Extended-Length bit: 1 = 2-octet length, 0 = 1-octet. RFC 4271 §4.3.
pub const BGP_ATTR_FLAG_EXTENDED_LENGTH: u8 = 0x10;
// Well-known flag defaults per in-scope attribute (Optional/Transitive/Partial/
// Extended-Length bits; Partial = 0 and Extended-Length = 0 by default).
/// Default ORIGIN flags: well-known mandatory (transitive). RFC 4271 §4.3.
pub const ATTR_ORIGIN_FLAGS: u8 = 0x40;
/// Default AS_PATH flags: well-known mandatory (transitive). RFC 4271 §4.3.
pub const ATTR_AS_PATH_FLAGS: u8 = 0x40;
/// Default NEXT_HOP flags: well-known mandatory (transitive). RFC 4271 §4.3.
pub const ATTR_NEXT_HOP_FLAGS: u8 = 0x40;
/// Default MULTI_EXIT_DISC flags: optional non-transitive. RFC 4271 §4.3.
pub const ATTR_MULTI_EXIT_DISC_FLAGS: u8 = 0x80;
/// Default LOCAL_PREF flags: well-known discretionary (transitive). RFC 4271 §4.3.
pub const ATTR_LOCAL_PREF_FLAGS: u8 = 0x40;
/// Default ATOMIC_AGGREGATE flags: well-known discretionary (transitive). RFC 4271 §4.3.
pub const ATTR_ATOMIC_AGGREGATE_FLAGS: u8 = 0x40;
/// Default AGGREGATOR flags: optional transitive. RFC 4271 §4.3.
pub const ATTR_AGGREGATOR_FLAGS: u8 = 0xC0;
/// Default COMMUNITIES flags: optional transitive. RFC 1997.
pub const ATTR_COMMUNITIES_FLAGS: u8 = 0xC0;
/// Default MP_REACH_NLRI flags: optional non-transitive. RFC 4760 §3.
pub const ATTR_MP_REACH_NLRI_FLAGS: u8 = 0x80;
/// Default MP_UNREACH_NLRI flags: optional non-transitive. RFC 4760 §4.
pub const ATTR_MP_UNREACH_NLRI_FLAGS: u8 = 0x80;
/// Default EXTENDED COMMUNITIES flags: optional transitive. RFC 4360.
pub const ATTR_EXTENDED_COMMUNITIES_FLAGS: u8 = 0xC0;
/// Default AS4_PATH flags: optional transitive. RFC 6793 §3.
pub const ATTR_AS4_PATH_FLAGS: u8 = 0xC0;
/// Default AS4_AGGREGATOR flags: optional transitive. RFC 6793 §3.
pub const ATTR_AS4_AGGREGATOR_FLAGS: u8 = 0xC0;
/// Default LARGE COMMUNITY flags: optional transitive. RFC 8092.
pub const ATTR_LARGE_COMMUNITY_FLAGS: u8 = 0xC0;
// ---------------------------------------------------------------------------
// ORIGIN values (attribute type 1, RFC 4271 §5.1.1)
// ---------------------------------------------------------------------------
/// ORIGIN = IGP. RFC 4271 §5.1.1.
pub const ORIGIN_IGP: u8 = 0;
/// ORIGIN = EGP. RFC 4271 §5.1.1.
pub const ORIGIN_EGP: u8 = 1;
/// ORIGIN = INCOMPLETE. RFC 4271 §5.1.1.
pub const ORIGIN_INCOMPLETE: u8 = 2;
// ---------------------------------------------------------------------------
// AS_PATH segment types (attribute type 2, RFC 4271 §5.1.2)
// ---------------------------------------------------------------------------
/// AS_SET segment type. RFC 4271 §4.3.
pub const AS_PATH_SEG_AS_SET: u8 = 1;
/// AS_SEQUENCE segment type. RFC 4271 §4.3.
pub const AS_PATH_SEG_AS_SEQUENCE: u8 = 2;
/// AS_CONFED_SEQUENCE segment type. RFC 5065.
pub const AS_PATH_SEG_AS_CONFED_SEQUENCE: u8 = 3;
/// AS_CONFED_SET segment type. RFC 5065.
pub const AS_PATH_SEG_AS_CONFED_SET: u8 = 4;
// ---------------------------------------------------------------------------
// Well-known COMMUNITIES (attribute type 8, RFC 1997)
// ---------------------------------------------------------------------------
/// NO_EXPORT well-known community. RFC 1997.
pub const COMMUNITY_NO_EXPORT: u32 = 0xFFFF_FF01;
/// NO_ADVERTISE well-known community. RFC 1997.
pub const COMMUNITY_NO_ADVERTISE: u32 = 0xFFFF_FF02;
/// NO_EXPORT_SUBCONFED well-known community. RFC 1997.
pub const COMMUNITY_NO_EXPORT_SUBCONFED: u32 = 0xFFFF_FF03;
// ---------------------------------------------------------------------------
// NOTIFICATION error codes (IANA `bgp-parameters-3`, RFC 4271 §6)
// ---------------------------------------------------------------------------
/// Message Header Error. RFC 4271.
pub const NOTIFY_MESSAGE_HEADER_ERROR: u8 = 1;
/// OPEN Message Error. RFC 4271.
pub const NOTIFY_OPEN_MESSAGE_ERROR: u8 = 2;
/// UPDATE Message Error. RFC 4271.
pub const NOTIFY_UPDATE_MESSAGE_ERROR: u8 = 3;
/// Hold Timer Expired. RFC 4271.
pub const NOTIFY_HOLD_TIMER_EXPIRED: u8 = 4;
/// Finite State Machine Error. RFC 4271.
pub const NOTIFY_FSM_ERROR: u8 = 5;
/// Cease. RFC 4271.
pub const NOTIFY_CEASE: u8 = 6;
/// ROUTE-REFRESH Message Error. RFC 7313.
pub const NOTIFY_ROUTE_REFRESH_MESSAGE_ERROR: u8 = 7;
/// Send Hold Timer Expired. RFC 9687.
pub const NOTIFY_SEND_HOLD_TIMER_EXPIRED: u8 = 8;
/// Loss of LSDB Sync. RFC 9815.
pub const NOTIFY_LOSS_OF_LSDB_SYNC: u8 = 9;
// Message Header Error subcodes (error code 1, IANA `bgp-parameters-5`, RFC 4271 §6.1)
/// Connection Not Synchronized. RFC 4271.
pub const MSG_HEADER_ERR_CONNECTION_NOT_SYNCHRONIZED: u8 = 1;
/// Bad Message Length. RFC 4271.
pub const MSG_HEADER_ERR_BAD_MESSAGE_LENGTH: u8 = 2;
/// Bad Message Type. RFC 4271.
pub const MSG_HEADER_ERR_BAD_MESSAGE_TYPE: u8 = 3;
// OPEN Message Error subcodes (error code 2, IANA `bgp-parameters-6`, RFC 4271 §6.2)
/// Unsupported Version Number. RFC 4271.
pub const OPEN_ERR_UNSUPPORTED_VERSION_NUMBER: u8 = 1;
/// Bad Peer AS. RFC 4271.
pub const OPEN_ERR_BAD_PEER_AS: u8 = 2;
/// Bad BGP Identifier. RFC 4271.
pub const OPEN_ERR_BAD_BGP_IDENTIFIER: u8 = 3;
/// Unsupported Optional Parameter. RFC 4271.
pub const OPEN_ERR_UNSUPPORTED_OPTIONAL_PARAMETER: u8 = 4;
/// Unacceptable Hold Time. RFC 4271.
pub const OPEN_ERR_UNACCEPTABLE_HOLD_TIME: u8 = 6;
/// Unsupported Capability. RFC 5492.
pub const OPEN_ERR_UNSUPPORTED_CAPABILITY: u8 = 7;
/// Role Mismatch. RFC 9234.
pub const OPEN_ERR_ROLE_MISMATCH: u8 = 11;
// UPDATE Message Error subcodes (error code 3, IANA `bgp-parameters-7`, RFC 4271 §6.3)
/// Malformed Attribute List. RFC 4271.
pub const UPDATE_ERR_MALFORMED_ATTRIBUTE_LIST: u8 = 1;
/// Unrecognized Well-known Attribute. RFC 4271.
pub const UPDATE_ERR_UNRECOGNIZED_WELL_KNOWN_ATTRIBUTE: u8 = 2;
/// Missing Well-known Attribute. RFC 4271.
pub const UPDATE_ERR_MISSING_WELL_KNOWN_ATTRIBUTE: u8 = 3;
/// Attribute Flags Error. RFC 4271.
pub const UPDATE_ERR_ATTRIBUTE_FLAGS_ERROR: u8 = 4;
/// Attribute Length Error. RFC 4271.
pub const UPDATE_ERR_ATTRIBUTE_LENGTH_ERROR: u8 = 5;
/// Invalid ORIGIN Attribute. RFC 4271.
pub const UPDATE_ERR_INVALID_ORIGIN_ATTRIBUTE: u8 = 6;
/// Invalid NEXT_HOP Attribute. RFC 4271.
pub const UPDATE_ERR_INVALID_NEXT_HOP_ATTRIBUTE: u8 = 8;
/// Optional Attribute Error. RFC 4271.
pub const UPDATE_ERR_OPTIONAL_ATTRIBUTE_ERROR: u8 = 9;
/// Invalid Network Field. RFC 4271.
pub const UPDATE_ERR_INVALID_NETWORK_FIELD: u8 = 10;
/// Malformed AS_PATH. RFC 4271.
pub const UPDATE_ERR_MALFORMED_AS_PATH: u8 = 11;
// Finite State Machine Error subcodes (error code 5, IANA `bgp-finite-state-machine-error-subcodes`)
/// Unspecified Error. RFC 6608.
pub const FSM_ERR_UNSPECIFIED: u8 = 0;
/// Receive Unexpected Message in OpenSent State. RFC 6608.
pub const FSM_ERR_UNEXPECTED_MESSAGE_IN_OPENSENT: u8 = 1;
/// Receive Unexpected Message in OpenConfirm State. RFC 6608.
pub const FSM_ERR_UNEXPECTED_MESSAGE_IN_OPENCONFIRM: u8 = 2;
/// Receive Unexpected Message in Established State. RFC 6608.
pub const FSM_ERR_UNEXPECTED_MESSAGE_IN_ESTABLISHED: u8 = 3;
// Cease subcodes (error code 6, IANA `bgp-parameters-8`)
/// Maximum Number of Prefixes Reached. RFC 4486.
pub const CEASE_MAX_PREFIXES_REACHED: u8 = 1;
/// Administrative Shutdown. RFC 4486 (RFC 9003).
pub const CEASE_ADMINISTRATIVE_SHUTDOWN: u8 = 2;
/// Peer De-configured. RFC 4486.
pub const CEASE_PEER_DECONFIGURED: u8 = 3;
/// Administrative Reset. RFC 4486 (RFC 9003).
pub const CEASE_ADMINISTRATIVE_RESET: u8 = 4;
/// Connection Rejected. RFC 4486.
pub const CEASE_CONNECTION_REJECTED: u8 = 5;
/// Other Configuration Change. RFC 4486.
pub const CEASE_OTHER_CONFIGURATION_CHANGE: u8 = 6;
/// Connection Collision Resolution. RFC 4486.
pub const CEASE_CONNECTION_COLLISION_RESOLUTION: u8 = 7;
/// Out of Resources. RFC 4486.
pub const CEASE_OUT_OF_RESOURCES: u8 = 8;
/// Hard Reset. RFC 8538.
pub const CEASE_HARD_RESET: u8 = 9;
/// BFD Down. RFC 9384.
pub const CEASE_BFD_DOWN: u8 = 10;
// ROUTE-REFRESH Message Error subcodes (error code 7, IANA `route-refresh-error-subcodes`)
/// Invalid Message Length. RFC 7313.
pub const ROUTE_REFRESH_ERR_INVALID_MESSAGE_LENGTH: u8 = 1;
// ---------------------------------------------------------------------------
// ROUTE-REFRESH message subtypes (type 5 body, RFC 2918 / RFC 7313)
// ---------------------------------------------------------------------------
/// Normal route refresh. RFC 2918 (also RFC 5291).
pub const ROUTE_REFRESH_SUBTYPE_NORMAL: u8 = 0;
/// Begin-of-RIB (BoRR). RFC 7313.
pub const ROUTE_REFRESH_SUBTYPE_BORR: u8 = 1;
/// End-of-RIB (EoRR). RFC 7313.
pub const ROUTE_REFRESH_SUBTYPE_EORR: u8 = 2;
// ---------------------------------------------------------------------------
// AFI values (IANA `address-family-numbers-2`)
// ---------------------------------------------------------------------------
/// IPv4 address family. IANA Address Family Numbers.
pub const AFI_IPV4: u16 = 1;
/// IPv6 address family. IANA Address Family Numbers.
pub const AFI_IPV6: u16 = 2;
// ---------------------------------------------------------------------------
// SAFI values (IANA `safi-namespace-2`)
// ---------------------------------------------------------------------------
/// Unicast forwarding. RFC 4760.
pub const SAFI_UNICAST: u8 = 1;
/// Multicast forwarding. RFC 4760.
pub const SAFI_MULTICAST: u8 = 2;