errors.go raw
1 // Copyright 2021 The gVisor Authors.
2 //
3 // Licensed under the Apache License, Version 2.0 (the "License");
4 // you may not use this file except in compliance with the License.
5 // You may obtain a copy of the License at
6 //
7 // http://www.apache.org/licenses/LICENSE-2.0
8 //
9 // Unless required by applicable law or agreed to in writing, software
10 // distributed under the License is distributed on an "AS IS" BASIS,
11 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 // See the License for the specific language governing permissions and
13 // limitations under the License.
14
15 package tcpip
16
17 import (
18 "fmt"
19 )
20
21 // Error represents an error in the netstack error space.
22 //
23 // The error interface is intentionally omitted to avoid loss of type
24 // information that would occur if these errors were passed as error.
25 type Error interface {
26 isError()
27
28 // IgnoreStats indicates whether this error should be included in failure
29 // counts in tcpip.Stats structs.
30 IgnoreStats() bool
31
32 fmt.Stringer
33 }
34
35 const maxErrno = 134
36
37 // LINT.IfChange
38
39 // ErrAborted indicates the operation was aborted.
40 //
41 // +stateify savable
42 type ErrAborted struct{}
43
44 func (*ErrAborted) isError() {}
45
46 // IgnoreStats implements Error.
47 func (*ErrAborted) IgnoreStats() bool {
48 return false
49 }
50 func (*ErrAborted) String() string {
51 return "operation aborted"
52 }
53
54 // ErrAddressFamilyNotSupported indicates the operation does not support the
55 // given address family.
56 //
57 // +stateify savable
58 type ErrAddressFamilyNotSupported struct{}
59
60 func (*ErrAddressFamilyNotSupported) isError() {}
61
62 // IgnoreStats implements Error.
63 func (*ErrAddressFamilyNotSupported) IgnoreStats() bool {
64 return false
65 }
66 func (*ErrAddressFamilyNotSupported) String() string {
67 return "address family not supported by protocol"
68 }
69
70 // ErrAlreadyBound indicates the endpoint is already bound.
71 //
72 // +stateify savable
73 type ErrAlreadyBound struct{}
74
75 func (*ErrAlreadyBound) isError() {}
76
77 // IgnoreStats implements Error.
78 func (*ErrAlreadyBound) IgnoreStats() bool {
79 return true
80 }
81 func (*ErrAlreadyBound) String() string { return "endpoint already bound" }
82
83 // ErrAlreadyConnected indicates the endpoint is already connected.
84 //
85 // +stateify savable
86 type ErrAlreadyConnected struct{}
87
88 func (*ErrAlreadyConnected) isError() {}
89
90 // IgnoreStats implements Error.
91 func (*ErrAlreadyConnected) IgnoreStats() bool {
92 return true
93 }
94 func (*ErrAlreadyConnected) String() string { return "endpoint is already connected" }
95
96 // ErrAlreadyConnecting indicates the endpoint is already connecting.
97 //
98 // +stateify savable
99 type ErrAlreadyConnecting struct{}
100
101 func (*ErrAlreadyConnecting) isError() {}
102
103 // IgnoreStats implements Error.
104 func (*ErrAlreadyConnecting) IgnoreStats() bool {
105 return true
106 }
107 func (*ErrAlreadyConnecting) String() string { return "endpoint is already connecting" }
108
109 // ErrBadAddress indicates a bad address was provided.
110 //
111 // +stateify savable
112 type ErrBadAddress struct{}
113
114 func (*ErrBadAddress) isError() {}
115
116 // IgnoreStats implements Error.
117 func (*ErrBadAddress) IgnoreStats() bool {
118 return false
119 }
120 func (*ErrBadAddress) String() string { return "bad address" }
121
122 // ErrBadBuffer indicates a bad buffer was provided.
123 //
124 // +stateify savable
125 type ErrBadBuffer struct{}
126
127 func (*ErrBadBuffer) isError() {}
128
129 // IgnoreStats implements Error.
130 func (*ErrBadBuffer) IgnoreStats() bool {
131 return false
132 }
133 func (*ErrBadBuffer) String() string { return "bad buffer" }
134
135 // ErrBadLocalAddress indicates a bad local address was provided.
136 //
137 // +stateify savable
138 type ErrBadLocalAddress struct{}
139
140 func (*ErrBadLocalAddress) isError() {}
141
142 // IgnoreStats implements Error.
143 func (*ErrBadLocalAddress) IgnoreStats() bool {
144 return false
145 }
146 func (*ErrBadLocalAddress) String() string { return "bad local address" }
147
148 // ErrBroadcastDisabled indicates broadcast is not enabled on the endpoint.
149 //
150 // +stateify savable
151 type ErrBroadcastDisabled struct{}
152
153 func (*ErrBroadcastDisabled) isError() {}
154
155 // IgnoreStats implements Error.
156 func (*ErrBroadcastDisabled) IgnoreStats() bool {
157 return false
158 }
159 func (*ErrBroadcastDisabled) String() string { return "broadcast socket option disabled" }
160
161 // ErrClosedForReceive indicates the endpoint is closed for incoming data.
162 //
163 // +stateify savable
164 type ErrClosedForReceive struct{}
165
166 func (*ErrClosedForReceive) isError() {}
167
168 // IgnoreStats implements Error.
169 func (*ErrClosedForReceive) IgnoreStats() bool {
170 return false
171 }
172 func (*ErrClosedForReceive) String() string { return "endpoint is closed for receive" }
173
174 // ErrClosedForSend indicates the endpoint is closed for outgoing data.
175 //
176 // +stateify savable
177 type ErrClosedForSend struct{}
178
179 func (*ErrClosedForSend) isError() {}
180
181 // IgnoreStats implements Error.
182 func (*ErrClosedForSend) IgnoreStats() bool {
183 return false
184 }
185 func (*ErrClosedForSend) String() string { return "endpoint is closed for send" }
186
187 // ErrConnectStarted indicates the endpoint is connecting asynchronously.
188 //
189 // +stateify savable
190 type ErrConnectStarted struct{}
191
192 func (*ErrConnectStarted) isError() {}
193
194 // IgnoreStats implements Error.
195 func (*ErrConnectStarted) IgnoreStats() bool {
196 return true
197 }
198 func (*ErrConnectStarted) String() string { return "connection attempt started" }
199
200 // ErrConnectionAborted indicates the connection was aborted.
201 //
202 // +stateify savable
203 type ErrConnectionAborted struct{}
204
205 func (*ErrConnectionAborted) isError() {}
206
207 // IgnoreStats implements Error.
208 func (*ErrConnectionAborted) IgnoreStats() bool {
209 return false
210 }
211 func (*ErrConnectionAborted) String() string { return "connection aborted" }
212
213 // ErrConnectionRefused indicates the connection was refused.
214 //
215 // +stateify savable
216 type ErrConnectionRefused struct{}
217
218 func (*ErrConnectionRefused) isError() {}
219
220 // IgnoreStats implements Error.
221 func (*ErrConnectionRefused) IgnoreStats() bool {
222 return false
223 }
224 func (*ErrConnectionRefused) String() string { return "connection was refused" }
225
226 // ErrConnectionReset indicates the connection was reset.
227 //
228 // +stateify savable
229 type ErrConnectionReset struct{}
230
231 func (*ErrConnectionReset) isError() {}
232
233 // IgnoreStats implements Error.
234 func (*ErrConnectionReset) IgnoreStats() bool {
235 return false
236 }
237 func (*ErrConnectionReset) String() string { return "connection reset by peer" }
238
239 // ErrDestinationRequired indicates the operation requires a destination
240 // address, and one was not provided.
241 //
242 // +stateify savable
243 type ErrDestinationRequired struct{}
244
245 func (*ErrDestinationRequired) isError() {}
246
247 // IgnoreStats implements Error.
248 func (*ErrDestinationRequired) IgnoreStats() bool {
249 return false
250 }
251 func (*ErrDestinationRequired) String() string { return "destination address is required" }
252
253 // ErrDuplicateAddress indicates the operation encountered a duplicate address.
254 //
255 // +stateify savable
256 type ErrDuplicateAddress struct{}
257
258 func (*ErrDuplicateAddress) isError() {}
259
260 // IgnoreStats implements Error.
261 func (*ErrDuplicateAddress) IgnoreStats() bool {
262 return false
263 }
264 func (*ErrDuplicateAddress) String() string { return "duplicate address" }
265
266 // ErrDuplicateNICID indicates the operation encountered a duplicate NIC ID.
267 //
268 // +stateify savable
269 type ErrDuplicateNICID struct{}
270
271 func (*ErrDuplicateNICID) isError() {}
272
273 // IgnoreStats implements Error.
274 func (*ErrDuplicateNICID) IgnoreStats() bool {
275 return false
276 }
277 func (*ErrDuplicateNICID) String() string { return "duplicate nic id" }
278
279 // ErrInvalidNICID indicates the operation used an invalid NIC ID.
280 //
281 // +stateify savable
282 type ErrInvalidNICID struct{}
283
284 func (*ErrInvalidNICID) isError() {}
285
286 // IgnoreStats implements Error.
287 func (*ErrInvalidNICID) IgnoreStats() bool {
288 return false
289 }
290 func (*ErrInvalidNICID) String() string { return "invalid nic id" }
291
292 // ErrInvalidEndpointState indicates the endpoint is in an invalid state.
293 //
294 // +stateify savable
295 type ErrInvalidEndpointState struct{}
296
297 func (*ErrInvalidEndpointState) isError() {}
298
299 // IgnoreStats implements Error.
300 func (*ErrInvalidEndpointState) IgnoreStats() bool {
301 return false
302 }
303 func (*ErrInvalidEndpointState) String() string { return "endpoint is in invalid state" }
304
305 // ErrInvalidOptionValue indicates an invalid option value was provided.
306 //
307 // +stateify savable
308 type ErrInvalidOptionValue struct{}
309
310 func (*ErrInvalidOptionValue) isError() {}
311
312 // IgnoreStats implements Error.
313 func (*ErrInvalidOptionValue) IgnoreStats() bool {
314 return false
315 }
316 func (*ErrInvalidOptionValue) String() string { return "invalid option value specified" }
317
318 // ErrInvalidPortRange indicates an attempt to set an invalid port range.
319 //
320 // +stateify savable
321 type ErrInvalidPortRange struct{}
322
323 func (*ErrInvalidPortRange) isError() {}
324
325 // IgnoreStats implements Error.
326 func (*ErrInvalidPortRange) IgnoreStats() bool {
327 return true
328 }
329 func (*ErrInvalidPortRange) String() string { return "invalid port range" }
330
331 // ErrMalformedHeader indicates the operation encountered a malformed header.
332 //
333 // +stateify savable
334 type ErrMalformedHeader struct{}
335
336 func (*ErrMalformedHeader) isError() {}
337
338 // IgnoreStats implements Error.
339 func (*ErrMalformedHeader) IgnoreStats() bool {
340 return false
341 }
342 func (*ErrMalformedHeader) String() string { return "header is malformed" }
343
344 // ErrMessageTooLong indicates the operation encountered a message whose length
345 // exceeds the maximum permitted.
346 //
347 // +stateify savable
348 type ErrMessageTooLong struct{}
349
350 func (*ErrMessageTooLong) isError() {}
351
352 // IgnoreStats implements Error.
353 func (*ErrMessageTooLong) IgnoreStats() bool {
354 return false
355 }
356 func (*ErrMessageTooLong) String() string { return "message too long" }
357
358 // ErrNetworkUnreachable indicates the operation is not able to reach the
359 // destination network.
360 //
361 // +stateify savable
362 type ErrNetworkUnreachable struct{}
363
364 func (*ErrNetworkUnreachable) isError() {}
365
366 // IgnoreStats implements Error.
367 func (*ErrNetworkUnreachable) IgnoreStats() bool {
368 return false
369 }
370 func (*ErrNetworkUnreachable) String() string { return "network is unreachable" }
371
372 // ErrNoBufferSpace indicates no buffer space is available.
373 //
374 // +stateify savable
375 type ErrNoBufferSpace struct{}
376
377 func (*ErrNoBufferSpace) isError() {}
378
379 // IgnoreStats implements Error.
380 func (*ErrNoBufferSpace) IgnoreStats() bool {
381 return false
382 }
383 func (*ErrNoBufferSpace) String() string { return "no buffer space available" }
384
385 // ErrNoPortAvailable indicates no port could be allocated for the operation.
386 //
387 // +stateify savable
388 type ErrNoPortAvailable struct{}
389
390 func (*ErrNoPortAvailable) isError() {}
391
392 // IgnoreStats implements Error.
393 func (*ErrNoPortAvailable) IgnoreStats() bool {
394 return false
395 }
396 func (*ErrNoPortAvailable) String() string { return "no ports are available" }
397
398 // ErrHostUnreachable indicates that a destination host could not be
399 // reached.
400 //
401 // +stateify savable
402 type ErrHostUnreachable struct{}
403
404 func (*ErrHostUnreachable) isError() {}
405
406 // IgnoreStats implements Error.
407 func (*ErrHostUnreachable) IgnoreStats() bool {
408 return false
409 }
410 func (*ErrHostUnreachable) String() string { return "no route to host" }
411
412 // ErrHostDown indicates that a destination host is down.
413 //
414 // +stateify savable
415 type ErrHostDown struct{}
416
417 func (*ErrHostDown) isError() {}
418
419 // IgnoreStats implements Error.
420 func (*ErrHostDown) IgnoreStats() bool {
421 return false
422 }
423 func (*ErrHostDown) String() string { return "host is down" }
424
425 // ErrNoNet indicates that the host is not on the network.
426 //
427 // +stateify savable
428 type ErrNoNet struct{}
429
430 func (*ErrNoNet) isError() {}
431
432 // IgnoreStats implements Error.
433 func (*ErrNoNet) IgnoreStats() bool {
434 return false
435 }
436 func (*ErrNoNet) String() string { return "machine is not on the network" }
437
438 // ErrNoSuchFile is used to indicate that ENOENT should be returned the to
439 // calling application.
440 //
441 // +stateify savable
442 type ErrNoSuchFile struct{}
443
444 func (*ErrNoSuchFile) isError() {}
445
446 // IgnoreStats implements Error.
447 func (*ErrNoSuchFile) IgnoreStats() bool {
448 return false
449 }
450 func (*ErrNoSuchFile) String() string { return "no such file" }
451
452 // ErrNotConnected indicates the endpoint is not connected.
453 //
454 // +stateify savable
455 type ErrNotConnected struct{}
456
457 func (*ErrNotConnected) isError() {}
458
459 // IgnoreStats implements Error.
460 func (*ErrNotConnected) IgnoreStats() bool {
461 return false
462 }
463 func (*ErrNotConnected) String() string { return "endpoint not connected" }
464
465 // ErrNotPermitted indicates the operation is not permitted.
466 //
467 // +stateify savable
468 type ErrNotPermitted struct{}
469
470 func (*ErrNotPermitted) isError() {}
471
472 // IgnoreStats implements Error.
473 func (*ErrNotPermitted) IgnoreStats() bool {
474 return false
475 }
476 func (*ErrNotPermitted) String() string { return "operation not permitted" }
477
478 // ErrNotSupported indicates the operation is not supported.
479 //
480 // +stateify savable
481 type ErrNotSupported struct{}
482
483 func (*ErrNotSupported) isError() {}
484
485 // IgnoreStats implements Error.
486 func (*ErrNotSupported) IgnoreStats() bool {
487 return false
488 }
489 func (*ErrNotSupported) String() string { return "operation not supported" }
490
491 // ErrPortInUse indicates the provided port is in use.
492 //
493 // +stateify savable
494 type ErrPortInUse struct{}
495
496 func (*ErrPortInUse) isError() {}
497
498 // IgnoreStats implements Error.
499 func (*ErrPortInUse) IgnoreStats() bool {
500 return false
501 }
502 func (*ErrPortInUse) String() string { return "port is in use" }
503
504 // ErrQueueSizeNotSupported indicates the endpoint does not allow queue size
505 // operation.
506 //
507 // +stateify savable
508 type ErrQueueSizeNotSupported struct{}
509
510 func (*ErrQueueSizeNotSupported) isError() {}
511
512 // IgnoreStats implements Error.
513 func (*ErrQueueSizeNotSupported) IgnoreStats() bool {
514 return false
515 }
516 func (*ErrQueueSizeNotSupported) String() string { return "queue size querying not supported" }
517
518 // ErrTimeout indicates the operation timed out.
519 //
520 // +stateify savable
521 type ErrTimeout struct{}
522
523 func (*ErrTimeout) isError() {}
524
525 // IgnoreStats implements Error.
526 func (*ErrTimeout) IgnoreStats() bool {
527 return false
528 }
529 func (*ErrTimeout) String() string { return "operation timed out" }
530
531 // ErrUnknownDevice indicates an unknown device identifier was provided.
532 //
533 // +stateify savable
534 type ErrUnknownDevice struct{}
535
536 func (*ErrUnknownDevice) isError() {}
537
538 // IgnoreStats implements Error.
539 func (*ErrUnknownDevice) IgnoreStats() bool {
540 return false
541 }
542 func (*ErrUnknownDevice) String() string { return "unknown device" }
543
544 // ErrUnknownNICID indicates an unknown NIC ID was provided.
545 //
546 // +stateify savable
547 type ErrUnknownNICID struct{}
548
549 func (*ErrUnknownNICID) isError() {}
550
551 // IgnoreStats implements Error.
552 func (*ErrUnknownNICID) IgnoreStats() bool {
553 return false
554 }
555 func (*ErrUnknownNICID) String() string { return "unknown nic id" }
556
557 // ErrUnknownProtocol indicates an unknown protocol was requested.
558 //
559 // +stateify savable
560 type ErrUnknownProtocol struct{}
561
562 func (*ErrUnknownProtocol) isError() {}
563
564 // IgnoreStats implements Error.
565 func (*ErrUnknownProtocol) IgnoreStats() bool {
566 return false
567 }
568 func (*ErrUnknownProtocol) String() string { return "unknown protocol" }
569
570 // ErrUnknownProtocolOption indicates an unknown protocol option was provided.
571 //
572 // +stateify savable
573 type ErrUnknownProtocolOption struct{}
574
575 func (*ErrUnknownProtocolOption) isError() {}
576
577 // IgnoreStats implements Error.
578 func (*ErrUnknownProtocolOption) IgnoreStats() bool {
579 return false
580 }
581 func (*ErrUnknownProtocolOption) String() string { return "unknown option for protocol" }
582
583 // ErrWouldBlock indicates the operation would block.
584 //
585 // +stateify savable
586 type ErrWouldBlock struct{}
587
588 func (*ErrWouldBlock) isError() {}
589
590 // IgnoreStats implements Error.
591 func (*ErrWouldBlock) IgnoreStats() bool {
592 return true
593 }
594 func (*ErrWouldBlock) String() string { return "operation would block" }
595
596 // ErrMissingRequiredFields indicates that a required field is missing.
597 //
598 // +stateify savable
599 type ErrMissingRequiredFields struct{}
600
601 func (*ErrMissingRequiredFields) isError() {}
602
603 // IgnoreStats implements Error.
604 func (*ErrMissingRequiredFields) IgnoreStats() bool {
605 return true
606 }
607 func (*ErrMissingRequiredFields) String() string { return "missing required fields" }
608
609 // ErrMulticastInputCannotBeOutput indicates that an input interface matches an
610 // output interface in the same multicast route.
611 //
612 // +stateify savable
613 type ErrMulticastInputCannotBeOutput struct{}
614
615 func (*ErrMulticastInputCannotBeOutput) isError() {}
616
617 // IgnoreStats implements Error.
618 func (*ErrMulticastInputCannotBeOutput) IgnoreStats() bool {
619 return true
620 }
621 func (*ErrMulticastInputCannotBeOutput) String() string { return "output cannot contain input" }
622
623 // ErrEndpointBusy indicates that the operation cannot be completed because the
624 // endpoint is busy.
625 //
626 // +stateify savable
627 type ErrEndpointBusy struct{}
628
629 // isError implements Error.
630 func (*ErrEndpointBusy) isError() {}
631
632 // IgnoreStats implements Error.
633 func (*ErrEndpointBusy) IgnoreStats() bool {
634 return true
635 }
636
637 func (*ErrEndpointBusy) String() string {
638 return "operation cannot be completed because the endpoint is busy"
639 }
640
641 // LINT.ThenChange(../syserr/netstack.go)
642