rustbgpd_wire/constants.rs
1/// The 16-byte marker field (all 0xFF) that begins every BGP message.
2pub const MARKER: [u8; 16] = [0xFF; 16];
3
4/// Length of the BGP message header in bytes.
5pub const HEADER_LEN: usize = 19;
6
7/// Minimum valid BGP message length (header only, used by KEEPALIVE).
8pub const MIN_MESSAGE_LEN: u16 = 19;
9
10/// Maximum valid BGP message length per RFC 4271 §4.1.
11pub const MAX_MESSAGE_LEN: u16 = 4096;
12
13/// Maximum BGP message length with Extended Messages (RFC 8654).
14pub const EXTENDED_MAX_MESSAGE_LEN: u16 = 65535;
15
16/// Size of the marker field in the header.
17pub const MARKER_LEN: usize = 16;
18
19/// BGP protocol version.
20pub const BGP_VERSION: u8 = 4;
21
22/// `AS_TRANS` value for 4-byte ASN backward compatibility (RFC 6793).
23pub const AS_TRANS: u16 = 23456;
24
25/// Default BGP TCP port.
26pub const BGP_PORT: u16 = 179;
27
28/// Minimum non-zero hold time in seconds (RFC 4271 §4.2).
29pub const MIN_HOLD_TIME: u16 = 3;
30
31/// Minimum OPEN message length (header + version + AS + hold + ID + opt len).
32pub const MIN_OPEN_LEN: u16 = 29;
33
34/// Minimum UPDATE message length (header + withdrawn len + attrs len).
35pub const MIN_UPDATE_LEN: u16 = 23;
36
37/// Minimum NOTIFICATION message length (header + code + subcode).
38pub const MIN_NOTIFICATION_LEN: u16 = 21;
39
40/// Message type codes.
41pub mod message_type {
42 /// OPEN message (type 1).
43 pub const OPEN: u8 = 1;
44 /// UPDATE message (type 2).
45 pub const UPDATE: u8 = 2;
46 /// NOTIFICATION message (type 3).
47 pub const NOTIFICATION: u8 = 3;
48 /// KEEPALIVE message (type 4).
49 pub const KEEPALIVE: u8 = 4;
50 /// ROUTE-REFRESH message (type 5, RFC 2918).
51 pub const ROUTE_REFRESH: u8 = 5;
52}
53
54/// OPEN optional parameter type codes (RFC 5492).
55pub mod param_type {
56 /// Capabilities Optional Parameter (RFC 5492).
57 pub const CAPABILITIES: u8 = 2;
58}
59
60/// Capability codes (IANA BGP Capability Codes registry).
61pub mod capability_code {
62 /// RFC 4760: Multi-Protocol Extensions.
63 pub const MULTI_PROTOCOL: u8 = 1;
64 /// RFC 2918: Route Refresh.
65 pub const ROUTE_REFRESH: u8 = 2;
66 /// RFC 8950: Extended Next Hop Encoding.
67 pub const EXTENDED_NEXT_HOP: u8 = 5;
68 /// RFC 4724: Graceful Restart.
69 pub const GRACEFUL_RESTART: u8 = 64;
70 /// RFC 8654: Extended Messages.
71 pub const EXTENDED_MESSAGE: u8 = 6;
72 /// RFC 7911: Add-Path.
73 pub const ADD_PATH: u8 = 69;
74 /// RFC 7313: Enhanced Route Refresh.
75 pub const ENHANCED_ROUTE_REFRESH: u8 = 70;
76 /// RFC 9494: Long-Lived Graceful Restart.
77 pub const LONG_LIVED_GRACEFUL_RESTART: u8 = 71;
78 /// RFC 6793: 4-Byte AS Number.
79 pub const FOUR_OCTET_AS: u8 = 65;
80}
81
82/// Path attribute type codes (RFC 4271 §5).
83pub mod attr_type {
84 /// `ORIGIN` (type 1).
85 pub const ORIGIN: u8 = 1;
86 /// `AS_PATH` (type 2).
87 pub const AS_PATH: u8 = 2;
88 /// `NEXT_HOP` (type 3).
89 pub const NEXT_HOP: u8 = 3;
90 /// `MULTI_EXIT_DISC` (type 4).
91 pub const MULTI_EXIT_DISC: u8 = 4;
92 /// `LOCAL_PREF` (type 5).
93 pub const LOCAL_PREF: u8 = 5;
94 /// `ATOMIC_AGGREGATE` (type 6).
95 pub const ATOMIC_AGGREGATE: u8 = 6;
96 /// `AGGREGATOR` (type 7).
97 pub const AGGREGATOR: u8 = 7;
98 /// `COMMUNITIES` (type 8, RFC 1997).
99 pub const COMMUNITIES: u8 = 8;
100 /// RFC 4456: `ORIGINATOR_ID`.
101 pub const ORIGINATOR_ID: u8 = 9;
102 /// RFC 4456: `CLUSTER_LIST`.
103 pub const CLUSTER_LIST: u8 = 10;
104 /// RFC 4360: Extended Communities.
105 pub const EXTENDED_COMMUNITIES: u8 = 16;
106 /// RFC 8092: Large Communities.
107 pub const LARGE_COMMUNITIES: u8 = 32;
108 /// RFC 4760: `MP_REACH_NLRI`.
109 pub const MP_REACH_NLRI: u8 = 14;
110 /// RFC 4760: `MP_UNREACH_NLRI`.
111 pub const MP_UNREACH_NLRI: u8 = 15;
112}
113
114/// Path attribute flag bits (RFC 4271 §4.3).
115pub mod attr_flags {
116 /// Bit 7: attribute is optional (vs. well-known).
117 pub const OPTIONAL: u8 = 0x80;
118 /// Bit 6: attribute is transitive.
119 pub const TRANSITIVE: u8 = 0x40;
120 /// Bit 5: attribute is partial (incomplete transitive).
121 pub const PARTIAL: u8 = 0x20;
122 /// Bit 4: attribute length is 2 bytes (vs. 1 byte).
123 pub const EXTENDED_LENGTH: u8 = 0x10;
124}
125
126/// `AS_PATH` segment types (RFC 4271 §4.3).
127pub mod as_path_segment {
128 /// `AS_SET` segment type.
129 pub const AS_SET: u8 = 1;
130 /// `AS_SEQUENCE` segment type.
131 pub const AS_SEQUENCE: u8 = 2;
132}