github.com/metacubex/gvisor@v0.0.0-20240320004321-933faba989ec/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  // ErrInvalidEndpointState indicates the endpoint is in an invalid state.
   278  //
   279  // +stateify savable
   280  type ErrInvalidEndpointState struct{}
   281  
   282  func (*ErrInvalidEndpointState) isError() {}
   283  
   284  // IgnoreStats implements Error.
   285  func (*ErrInvalidEndpointState) IgnoreStats() bool {
   286  	return false
   287  }
   288  func (*ErrInvalidEndpointState) String() string { return "endpoint is in invalid state" }
   289  
   290  // ErrInvalidOptionValue indicates an invalid option value was provided.
   291  //
   292  // +stateify savable
   293  type ErrInvalidOptionValue struct{}
   294  
   295  func (*ErrInvalidOptionValue) isError() {}
   296  
   297  // IgnoreStats implements Error.
   298  func (*ErrInvalidOptionValue) IgnoreStats() bool {
   299  	return false
   300  }
   301  func (*ErrInvalidOptionValue) String() string { return "invalid option value specified" }
   302  
   303  // ErrInvalidPortRange indicates an attempt to set an invalid port range.
   304  //
   305  // +stateify savable
   306  type ErrInvalidPortRange struct{}
   307  
   308  func (*ErrInvalidPortRange) isError() {}
   309  
   310  // IgnoreStats implements Error.
   311  func (*ErrInvalidPortRange) IgnoreStats() bool {
   312  	return true
   313  }
   314  func (*ErrInvalidPortRange) String() string { return "invalid port range" }
   315  
   316  // ErrMalformedHeader indicates the operation encountered a malformed header.
   317  //
   318  // +stateify savable
   319  type ErrMalformedHeader struct{}
   320  
   321  func (*ErrMalformedHeader) isError() {}
   322  
   323  // IgnoreStats implements Error.
   324  func (*ErrMalformedHeader) IgnoreStats() bool {
   325  	return false
   326  }
   327  func (*ErrMalformedHeader) String() string { return "header is malformed" }
   328  
   329  // ErrMessageTooLong indicates the operation encountered a message whose length
   330  // exceeds the maximum permitted.
   331  //
   332  // +stateify savable
   333  type ErrMessageTooLong struct{}
   334  
   335  func (*ErrMessageTooLong) isError() {}
   336  
   337  // IgnoreStats implements Error.
   338  func (*ErrMessageTooLong) IgnoreStats() bool {
   339  	return false
   340  }
   341  func (*ErrMessageTooLong) String() string { return "message too long" }
   342  
   343  // ErrNetworkUnreachable indicates the operation is not able to reach the
   344  // destination network.
   345  //
   346  // +stateify savable
   347  type ErrNetworkUnreachable struct{}
   348  
   349  func (*ErrNetworkUnreachable) isError() {}
   350  
   351  // IgnoreStats implements Error.
   352  func (*ErrNetworkUnreachable) IgnoreStats() bool {
   353  	return false
   354  }
   355  func (*ErrNetworkUnreachable) String() string { return "network is unreachable" }
   356  
   357  // ErrNoBufferSpace indicates no buffer space is available.
   358  //
   359  // +stateify savable
   360  type ErrNoBufferSpace struct{}
   361  
   362  func (*ErrNoBufferSpace) isError() {}
   363  
   364  // IgnoreStats implements Error.
   365  func (*ErrNoBufferSpace) IgnoreStats() bool {
   366  	return false
   367  }
   368  func (*ErrNoBufferSpace) String() string { return "no buffer space available" }
   369  
   370  // ErrNoPortAvailable indicates no port could be allocated for the operation.
   371  //
   372  // +stateify savable
   373  type ErrNoPortAvailable struct{}
   374  
   375  func (*ErrNoPortAvailable) isError() {}
   376  
   377  // IgnoreStats implements Error.
   378  func (*ErrNoPortAvailable) IgnoreStats() bool {
   379  	return false
   380  }
   381  func (*ErrNoPortAvailable) String() string { return "no ports are available" }
   382  
   383  // ErrHostUnreachable indicates that a destination host could not be
   384  // reached.
   385  //
   386  // +stateify savable
   387  type ErrHostUnreachable struct{}
   388  
   389  func (*ErrHostUnreachable) isError() {}
   390  
   391  // IgnoreStats implements Error.
   392  func (*ErrHostUnreachable) IgnoreStats() bool {
   393  	return false
   394  }
   395  func (*ErrHostUnreachable) String() string { return "no route to host" }
   396  
   397  // ErrHostDown indicates that a destination host is down.
   398  //
   399  // +stateify savable
   400  type ErrHostDown struct{}
   401  
   402  func (*ErrHostDown) isError() {}
   403  
   404  // IgnoreStats implements Error.
   405  func (*ErrHostDown) IgnoreStats() bool {
   406  	return false
   407  }
   408  func (*ErrHostDown) String() string { return "host is down" }
   409  
   410  // ErrNoNet indicates that the host is not on the network.
   411  //
   412  // +stateify savable
   413  type ErrNoNet struct{}
   414  
   415  func (*ErrNoNet) isError() {}
   416  
   417  // IgnoreStats implements Error.
   418  func (*ErrNoNet) IgnoreStats() bool {
   419  	return false
   420  }
   421  func (*ErrNoNet) String() string { return "machine is not on the network" }
   422  
   423  // ErrNoSuchFile is used to indicate that ENOENT should be returned the to
   424  // calling application.
   425  //
   426  // +stateify savable
   427  type ErrNoSuchFile struct{}
   428  
   429  func (*ErrNoSuchFile) isError() {}
   430  
   431  // IgnoreStats implements Error.
   432  func (*ErrNoSuchFile) IgnoreStats() bool {
   433  	return false
   434  }
   435  func (*ErrNoSuchFile) String() string { return "no such file" }
   436  
   437  // ErrNotConnected indicates the endpoint is not connected.
   438  //
   439  // +stateify savable
   440  type ErrNotConnected struct{}
   441  
   442  func (*ErrNotConnected) isError() {}
   443  
   444  // IgnoreStats implements Error.
   445  func (*ErrNotConnected) IgnoreStats() bool {
   446  	return false
   447  }
   448  func (*ErrNotConnected) String() string { return "endpoint not connected" }
   449  
   450  // ErrNotPermitted indicates the operation is not permitted.
   451  //
   452  // +stateify savable
   453  type ErrNotPermitted struct{}
   454  
   455  func (*ErrNotPermitted) isError() {}
   456  
   457  // IgnoreStats implements Error.
   458  func (*ErrNotPermitted) IgnoreStats() bool {
   459  	return false
   460  }
   461  func (*ErrNotPermitted) String() string { return "operation not permitted" }
   462  
   463  // ErrNotSupported indicates the operation is not supported.
   464  //
   465  // +stateify savable
   466  type ErrNotSupported struct{}
   467  
   468  func (*ErrNotSupported) isError() {}
   469  
   470  // IgnoreStats implements Error.
   471  func (*ErrNotSupported) IgnoreStats() bool {
   472  	return false
   473  }
   474  func (*ErrNotSupported) String() string { return "operation not supported" }
   475  
   476  // ErrPortInUse indicates the provided port is in use.
   477  //
   478  // +stateify savable
   479  type ErrPortInUse struct{}
   480  
   481  func (*ErrPortInUse) isError() {}
   482  
   483  // IgnoreStats implements Error.
   484  func (*ErrPortInUse) IgnoreStats() bool {
   485  	return false
   486  }
   487  func (*ErrPortInUse) String() string { return "port is in use" }
   488  
   489  // ErrQueueSizeNotSupported indicates the endpoint does not allow queue size
   490  // operation.
   491  //
   492  // +stateify savable
   493  type ErrQueueSizeNotSupported struct{}
   494  
   495  func (*ErrQueueSizeNotSupported) isError() {}
   496  
   497  // IgnoreStats implements Error.
   498  func (*ErrQueueSizeNotSupported) IgnoreStats() bool {
   499  	return false
   500  }
   501  func (*ErrQueueSizeNotSupported) String() string { return "queue size querying not supported" }
   502  
   503  // ErrTimeout indicates the operation timed out.
   504  //
   505  // +stateify savable
   506  type ErrTimeout struct{}
   507  
   508  func (*ErrTimeout) isError() {}
   509  
   510  // IgnoreStats implements Error.
   511  func (*ErrTimeout) IgnoreStats() bool {
   512  	return false
   513  }
   514  func (*ErrTimeout) String() string { return "operation timed out" }
   515  
   516  // ErrUnknownDevice indicates an unknown device identifier was provided.
   517  //
   518  // +stateify savable
   519  type ErrUnknownDevice struct{}
   520  
   521  func (*ErrUnknownDevice) isError() {}
   522  
   523  // IgnoreStats implements Error.
   524  func (*ErrUnknownDevice) IgnoreStats() bool {
   525  	return false
   526  }
   527  func (*ErrUnknownDevice) String() string { return "unknown device" }
   528  
   529  // ErrUnknownNICID indicates an unknown NIC ID was provided.
   530  //
   531  // +stateify savable
   532  type ErrUnknownNICID struct{}
   533  
   534  func (*ErrUnknownNICID) isError() {}
   535  
   536  // IgnoreStats implements Error.
   537  func (*ErrUnknownNICID) IgnoreStats() bool {
   538  	return false
   539  }
   540  func (*ErrUnknownNICID) String() string { return "unknown nic id" }
   541  
   542  // ErrUnknownProtocol indicates an unknown protocol was requested.
   543  //
   544  // +stateify savable
   545  type ErrUnknownProtocol struct{}
   546  
   547  func (*ErrUnknownProtocol) isError() {}
   548  
   549  // IgnoreStats implements Error.
   550  func (*ErrUnknownProtocol) IgnoreStats() bool {
   551  	return false
   552  }
   553  func (*ErrUnknownProtocol) String() string { return "unknown protocol" }
   554  
   555  // ErrUnknownProtocolOption indicates an unknown protocol option was provided.
   556  //
   557  // +stateify savable
   558  type ErrUnknownProtocolOption struct{}
   559  
   560  func (*ErrUnknownProtocolOption) isError() {}
   561  
   562  // IgnoreStats implements Error.
   563  func (*ErrUnknownProtocolOption) IgnoreStats() bool {
   564  	return false
   565  }
   566  func (*ErrUnknownProtocolOption) String() string { return "unknown option for protocol" }
   567  
   568  // ErrWouldBlock indicates the operation would block.
   569  //
   570  // +stateify savable
   571  type ErrWouldBlock struct{}
   572  
   573  func (*ErrWouldBlock) isError() {}
   574  
   575  // IgnoreStats implements Error.
   576  func (*ErrWouldBlock) IgnoreStats() bool {
   577  	return true
   578  }
   579  func (*ErrWouldBlock) String() string { return "operation would block" }
   580  
   581  // ErrMissingRequiredFields indicates that a required field is missing.
   582  //
   583  // +stateify savable
   584  type ErrMissingRequiredFields struct{}
   585  
   586  func (*ErrMissingRequiredFields) isError() {}
   587  
   588  // IgnoreStats implements Error.
   589  func (*ErrMissingRequiredFields) IgnoreStats() bool {
   590  	return true
   591  }
   592  func (*ErrMissingRequiredFields) String() string { return "missing required fields" }
   593  
   594  // ErrMulticastInputCannotBeOutput indicates that an input interface matches an
   595  // output interface in the same multicast route.
   596  //
   597  // +stateify savable
   598  type ErrMulticastInputCannotBeOutput struct{}
   599  
   600  func (*ErrMulticastInputCannotBeOutput) isError() {}
   601  
   602  // IgnoreStats implements Error.
   603  func (*ErrMulticastInputCannotBeOutput) IgnoreStats() bool {
   604  	return true
   605  }
   606  func (*ErrMulticastInputCannotBeOutput) String() string { return "output cannot contain input" }
   607  
   608  // LINT.ThenChange(../syserr/netstack.go)