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