Skip to main content

sctp_proto/
error.rs

1use thiserror::Error;
2
3use alloc::string::String;
4
5pub type Result<T> = core::result::Result<T, Error>;
6
7/// Errors triggered during SCTP association operation
8#[derive(Debug, Error, Eq, Clone, PartialEq)]
9#[non_exhaustive]
10pub enum Error {
11    #[error("raw is too small for a SCTP chunk")]
12    ErrChunkHeaderTooSmall,
13    #[error("not enough data left in SCTP packet to satisfy requested length")]
14    ErrChunkHeaderNotEnoughSpace,
15    #[error("chunk PADDING is non-zero at offset")]
16    ErrChunkHeaderPaddingNonZero,
17    #[error("chunk has invalid length")]
18    ErrChunkHeaderInvalidLength,
19
20    #[error("ChunkType is not of type ABORT")]
21    ErrChunkTypeNotAbort,
22    #[error("failed build Abort Chunk")]
23    ErrBuildAbortChunkFailed,
24    #[error("ChunkType is not of type COOKIEACK")]
25    ErrChunkTypeNotCookieAck,
26    #[error("ChunkType is not of type COOKIEECHO")]
27    ErrChunkTypeNotCookieEcho,
28    #[error("ChunkType is not of type ctError")]
29    ErrChunkTypeNotCt,
30    #[error("failed build Error Chunk")]
31    ErrBuildErrorChunkFailed,
32    #[error("failed to marshal stream")]
33    ErrMarshalStreamFailed,
34    #[error("chunk too short")]
35    ErrChunkTooShort,
36    #[error("ChunkType is not of type ForwardTsn")]
37    ErrChunkTypeNotForwardTsn,
38    #[error("ChunkType is not of type HEARTBEAT")]
39    ErrChunkTypeNotHeartbeat,
40    #[error("ChunkType is not of type HEARTBEATACK")]
41    ErrChunkTypeNotHeartbeatAck,
42    #[error("heartbeat is not long enough to contain Heartbeat Info")]
43    ErrHeartbeatNotLongEnoughInfo,
44    #[error("failed to parse param type")]
45    ErrParseParamTypeFailed,
46    #[error("heartbeat should only have HEARTBEAT param")]
47    ErrHeartbeatParam,
48    #[error("failed unmarshalling param in Heartbeat Chunk")]
49    ErrHeartbeatChunkUnmarshal,
50    #[error("unimplemented")]
51    ErrUnimplemented,
52    #[error("heartbeat Ack must have one param")]
53    ErrHeartbeatAckParams,
54    #[error("heartbeat Ack must have one param, and it should be a HeartbeatInfo")]
55    ErrHeartbeatAckNotHeartbeatInfo,
56    #[error("unable to marshal parameter for Heartbeat Ack")]
57    ErrHeartbeatAckMarshalParam,
58
59    #[error("raw is too small for error cause")]
60    ErrErrorCauseTooSmall,
61
62    #[error("unhandled ParamType: {typ}")]
63    ErrParamTypeUnhandled { typ: u16 },
64
65    #[error("unexpected ParamType")]
66    ErrParamTypeUnexpected,
67
68    #[error("param header too short")]
69    ErrParamHeaderTooShort,
70    #[error("param self reported length is shorter than header length")]
71    ErrParamHeaderSelfReportedLengthShorter,
72    #[error("param self reported length is longer than header length")]
73    ErrParamHeaderSelfReportedLengthLonger,
74    #[error("failed to parse param type")]
75    ErrParamHeaderParseFailed,
76
77    #[error("packet to short")]
78    ErrParamPacketTooShort,
79    #[error("outgoing SSN reset request parameter too short")]
80    ErrSsnResetRequestParamTooShort,
81    #[error("outgoing SSN reset request parameter has an invalid length")]
82    ErrSsnResetRequestParamInvalidLength,
83    #[error("reconfig response parameter too short")]
84    ErrReconfigRespParamTooShort,
85    #[error("supported address types parameter has an invalid length")]
86    ErrSupportedAddressTypesParamInvalidLength,
87    #[error("invalid algorithm type")]
88    ErrInvalidAlgorithmType,
89
90    #[error("failed to parse param type")]
91    ErrInitChunkParseParamTypeFailed,
92    #[error("failed unmarshalling param in Init Chunk")]
93    ErrInitChunkUnmarshalParam,
94    #[error("unable to marshal parameter for INIT/INITACK")]
95    ErrInitAckMarshalParam,
96
97    #[error("ChunkType is not of type INIT")]
98    ErrChunkTypeNotTypeInit,
99    #[error("chunk Value isn't long enough for mandatory parameters exp")]
100    ErrChunkValueNotLongEnough,
101    #[error("ChunkType of type INIT flags must be all 0")]
102    ErrChunkTypeInitFlagZero,
103    #[error("failed to unmarshal INIT body")]
104    ErrChunkTypeInitUnmarshalFailed,
105    #[error("failed marshaling INIT common data")]
106    ErrChunkTypeInitMarshalFailed,
107    #[error("ChunkType of type INIT ACK InitiateTag must not be 0")]
108    ErrChunkTypeInitInitiateTagZero,
109    #[error("INIT ACK inbound stream request must be > 0")]
110    ErrInitInboundStreamRequestZero,
111    #[error("INIT ACK outbound stream request must be > 0")]
112    ErrInitOutboundStreamRequestZero,
113    #[error("INIT ACK Advertised Receiver Window Credit (a_rwnd) must be >= 1500")]
114    ErrInitAdvertisedReceiver1500,
115
116    #[error("packet is smaller than the header size")]
117    ErrChunkPayloadSmall,
118    #[error("ChunkType is not of type PayloadData")]
119    ErrChunkTypeNotPayloadData,
120    #[error("ChunkType is not of type Reconfig")]
121    ErrChunkTypeNotReconfig,
122    #[error("ChunkReconfig has invalid ParamA")]
123    ErrChunkReconfigInvalidParamA,
124    #[error("ChunkReconfig has an unsupported parameter combination")]
125    ErrChunkReconfigInvalidParamCombination,
126
127    #[error("failed to parse param type")]
128    ErrChunkParseParamTypeFailed,
129    #[error("unable to marshal parameter A for reconfig")]
130    ErrChunkMarshalParamAReconfigFailed,
131    #[error("unable to marshal parameter B for reconfig")]
132    ErrChunkMarshalParamBReconfigFailed,
133
134    #[error("ChunkType is not of type SACK")]
135    ErrChunkTypeNotSack,
136    #[error("SACK Chunk size is not large enough to contain header")]
137    ErrSackSizeNotLargeEnoughInfo,
138
139    #[error("invalid chunk size")]
140    ErrInvalidChunkSize,
141    #[error("ChunkType is not of type SHUTDOWN")]
142    ErrChunkTypeNotShutdown,
143
144    #[error("ChunkType is not of type SHUTDOWN-ACK")]
145    ErrChunkTypeNotShutdownAck,
146    #[error("ChunkType is not of type SHUTDOWN-COMPLETE")]
147    ErrChunkTypeNotShutdownComplete,
148
149    #[error("raw is smaller than the minimum length for a SCTP packet")]
150    ErrPacketRawTooSmall,
151    #[error("unable to parse SCTP chunk, not enough data for complete header")]
152    ErrParseSctpChunkNotEnoughData,
153    #[error("failed to unmarshal, contains unknown chunk type")]
154    ErrUnmarshalUnknownChunkType,
155    #[error("checksum mismatch theirs")]
156    ErrChecksumMismatch,
157
158    #[error("unexpected chunk popped (unordered)")]
159    ErrUnexpectedChuckPoppedUnordered,
160    #[error("unexpected chunk popped (ordered)")]
161    ErrUnexpectedChuckPoppedOrdered,
162    #[error("unexpected q state (should've been selected)")]
163    ErrUnexpectedQState,
164    #[error("receive buffer exhausted during message reassembly")]
165    ErrReceiveBufferExhausted,
166    #[error("try again")]
167    ErrTryAgain,
168
169    #[error("abort chunk, with following errors: {0}")]
170    ErrAbortChunk(String),
171    #[error("shutdown called in non-Established state")]
172    ErrShutdownNonEstablished,
173    #[error("association closed before connecting")]
174    ErrAssociationClosedBeforeConn,
175    #[error("association init failed")]
176    ErrAssociationInitFailed,
177    #[error("association handshake closed")]
178    ErrAssociationHandshakeClosed,
179    #[error("silently discard")]
180    ErrSilentlyDiscard,
181    #[error("the init not stored to send")]
182    ErrInitNotStoredToSend,
183    #[error("cookieEcho not stored to send")]
184    ErrCookieEchoNotStoredToSend,
185    #[error("sctp packet must not have a source port of 0")]
186    ErrSctpPacketSourcePortZero,
187    #[error("sctp packet must not have a destination port of 0")]
188    ErrSctpPacketDestinationPortZero,
189    #[error("init chunk must not be bundled with any other chunk")]
190    ErrInitChunkBundled,
191    #[error("init chunk expects a verification tag of 0 on the packet when out-of-the-blue")]
192    ErrInitChunkVerifyTagNotZero,
193    #[error("todo: handle Init when in state")]
194    ErrHandleInitState,
195    #[error("no cookie in InitAck")]
196    ErrInitAckNoCookie,
197    #[error("there already exists a stream with identifier")]
198    ErrStreamAlreadyExist,
199    #[error("stream ID has a pending RE-CONFIG and cannot be reused yet")]
200    ErrStreamResetPending,
201    #[error("Failed to create a stream with identifier")]
202    ErrStreamCreateFailed,
203    #[error("unable to be popped from inflight queue TSN")]
204    ErrInflightQueueTsnPop,
205    #[error("requested non-existent TSN")]
206    ErrTsnRequestNotExist,
207    #[error("sending reset packet in non-Established state")]
208    ErrResetPacketInStateNotExist,
209    #[error("unexpected parameter type")]
210    ErrParameterType,
211    #[error("sending payload data in non-Established state")]
212    ErrPayloadDataStateNotExist,
213    #[error("unhandled chunk type")]
214    ErrChunkTypeUnhandled,
215    #[error("handshake failed (INIT ACK)")]
216    ErrHandshakeInitAck,
217    #[error("handshake failed (COOKIE ECHO)")]
218    ErrHandshakeCookieEcho,
219
220    #[error("outbound packet larger than maximum message size")]
221    ErrOutboundPacketTooLarge,
222    #[error("inbound packet larger than maximum message size")]
223    ErrInboundPacketTooLarge,
224    #[error("Stream closed")]
225    ErrStreamClosed,
226    #[error("Stream not existed")]
227    ErrStreamNotExisted,
228    #[error("Short buffer to be filled")]
229    ErrShortBuffer,
230    #[error("Io EOF")]
231    ErrEof,
232    #[error("Invalid SystemTime")]
233    ErrInvalidSystemTime,
234    #[error("Net Conn read error")]
235    ErrNetConnRead,
236    #[error("Max Data Channel ID")]
237    ErrMaxDataChannelID,
238
239    #[error("{0}")]
240    Other(String),
241}