bgp_packet/
errors.rs

1use thiserror::Error;
2
3#[derive(Debug, Error)]
4#[repr(u8)]
5pub enum BgpError {
6    #[error("Message header error")]
7    MsgHeader(MsgHeaderSubcode) = 1,
8
9    #[error("Open message error")]
10    OpenMsg(OpenMsgSubcode) = 2,
11
12    #[error("Update message error")]
13    UpdateMsg(UpdateMsgSubcode) = 3,
14
15    #[error("Hold timer expired")]
16    HoldTimer = 4,
17
18    #[error("Finite state machine error")]
19    FsmError(FsmSubcode) = 5,
20
21    #[error("Cease")]
22    Cease(CeaseSubcode) = 6,
23
24    #[error("Route refresh message error")]
25    RouteRefresh(RouteRefreshSubcode) = 7,
26
27    #[error("Send hold timer expired")]
28    SendHoldTimer = 8,
29}
30
31#[derive(Debug, Error)]
32pub enum MsgHeaderSubcode {
33    #[error("Connection not synchronized")]
34    ConnNotSynchronized = 1,
35
36    #[error("Bad message length")]
37    BadMessageLength = 2,
38
39    #[error("Bad message type")]
40    BadMessagType = 3,
41}
42
43#[derive(Debug, Error)]
44pub enum OpenMsgSubcode {
45    #[error("Unsupported BGP version number")]
46    UnsupportedVersion = 1,
47
48    #[error("Bad peer AS number")]
49    BadPeerAs = 2,
50
51    #[error("Bad BGP identifier")]
52    BadBgpId = 3,
53
54    #[error("Unsupported optional parameter")]
55    UnsupportedOptionalParam = 4,
56
57    #[error("Unacceptable hold time")]
58    UnacceptableHoldTime = 6,
59
60    #[error("Unsupported capability")]
61    UnsupportedCapability = 7,
62
63    #[error("Role mismatch")]
64    RoleMismatch = 8,
65}
66
67#[derive(Debug, Error)]
68pub enum UpdateMsgSubcode {
69    #[error("Malformed attribute list")]
70    MalforedAttrs = 1,
71
72    #[error("Unrecognized well known attribute")]
73    UnrecognizedWellKnownAttr = 2,
74
75    #[error("Missing well known attribute")]
76    MissingWellKnown = 3,
77
78    #[error("Attribute flags error")]
79    AttributeFlags = 4,
80
81    #[error("Attribute length error")]
82    AttributeLength = 5,
83
84    #[error("Invalid origin")]
85    InvalidOrigin = 6,
86
87    #[error("Invalid next hop")]
88    InvalidNextHop = 8,
89
90    #[error("Optional attribute error")]
91    OptionalAttribute = 9,
92
93    #[error("Invalid network field")]
94    InvalidNetworkField = 10,
95
96    #[error("Malformed AS path")]
97    MalformedAsPath = 11,
98}
99
100#[derive(Debug, Error)]
101pub enum FsmSubcode {
102    #[error("Received an unexpected message in OpenSent state")]
103    UnexpectedOpenSent = 1,
104
105    #[error("Received an unexpected message in OpenConfirm state")]
106    UnexpectedOpenConfirm = 2,
107
108    #[error("Received an unexpected message in Established state")]
109    UnexpectedEstablished = 3,
110}
111
112#[derive(Debug, Error)]
113pub enum CeaseSubcode {
114    #[error("Maximum number of prefixes reached")]
115    MaxPrefixes = 1,
116
117    #[error("Administrative shutdown")]
118    AdminShutdown = 2,
119
120    #[error("Peer deconfigured")]
121    PeerDeconf = 3,
122
123    #[error("Administrative reset")]
124    AdminReset = 4,
125
126    #[error("Connection rejected")]
127    ConnRejected = 5,
128
129    #[error("Configuration change")]
130    ConfChange = 6,
131
132    #[error("Connection collision resolution")]
133    ConnCollisionResolution = 7,
134
135    #[error("Out of resources")]
136    OutOfResources = 8,
137
138    #[error("Hard reset")]
139    HardReset = 9,
140
141    #[error("BFD down")]
142    BfdDown = 10,
143}
144
145#[derive(Debug, Error)]
146pub enum RouteRefreshSubcode {
147    #[error("Invalid message length")]
148    InvalidLength = 1,
149}