summaryrefslogtreecommitdiffhomepage
path: root/pkg/tcpip
diff options
context:
space:
mode:
authorgVisor bot <gvisor-bot@google.com>2020-05-27 17:51:40 +0000
committergVisor bot <gvisor-bot@google.com>2020-05-27 17:51:40 +0000
commit84452958e1397b337a806f815e07ae69c4f4c896 (patch)
tree138422671bc14bd0c66f83c31be1a991888f3359 /pkg/tcpip
parentbae1520437ecbd3dd217880cb51eb24b59d26f51 (diff)
parent0bc022b7f3c13bb7c5c8d47d1781820161e7b1ad (diff)
Merge release-20200518.0-45-g0bc022b7 (automated)
Diffstat (limited to 'pkg/tcpip')
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/adapters/gonet/gonet.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/adapters/gonet/gonet_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/buffer/buffer_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/hash/jenkins/jenkins_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/header_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ipv6_extension_headers.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ndp_neighbor_advert.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ndp_neighbor_solicit.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ndp_options.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ndp_router_advert.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ndp_router_solicit.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/header/ndpoptionidentifier_string.go0
-rw-r--r--pkg/tcpip/header/tcp.go29
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/channel/channel.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/channel/channel_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/fdbased/fdbased_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/fdbased/fdbased_unsafe_state_autogen.go0
-rw-r--r--pkg/tcpip/link/fdbased/packet_dispatchers.go2
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/loopback/loopback_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/muxed/injectable.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/muxed/muxed_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/qdisc/fifo/endpoint.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/qdisc/fifo/fifo_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/qdisc/fifo/packet_buffer_queue.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/rawfile/rawfile_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/rawfile/rawfile_unsafe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/pipe/pipe.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/pipe/pipe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/pipe/pipe_unsafe.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/pipe/pipe_unsafe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/pipe/rx.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/pipe/tx.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/queue/queue_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/queue/rx.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/queue/tx.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/rx.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/sharedmem.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/sharedmem_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/sharedmem_unsafe.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/sharedmem_unsafe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sharedmem/tx.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/sniffer/sniffer_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/tun/device.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/tun/protocol.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/tun/tun_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/tun/tun_unsafe.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/tun/tun_unsafe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/waitable/waitable.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/link/waitable/waitable_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/network/arp/arp_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/network/fragmentation/fragmentation_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/network/fragmentation/reassembler_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/network/hash/hash_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/network/ipv4/ipv4_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/network/ipv6/ipv6_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/ports/ports_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/seqnum/seqnum_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/conntrack.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/dhcpv6configurationfromndpra_string.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/forwarder.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/iptables.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/iptables_targets.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/iptables_types.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/linkaddrentry_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/ndp.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/packet_buffer.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/packet_buffer_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/rand.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/stack/stack_state_autogen.go0
-rw-r--r--pkg/tcpip/tcpip.go65
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/tcpip_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/tcpip_unsafe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/timer.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/icmp/icmp_packet_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/icmp/icmp_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/packet/endpoint.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/packet/endpoint_state.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/packet/packet_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/packet/packet_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/raw/raw_packet_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/raw/raw_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/connect_unsafe.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/dispatcher.go0
-rw-r--r--pkg/tcpip/transport/tcp/endpoint_state.go68
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/rcv_state.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/tcp_endpoint_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/tcp_segment_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/tcp_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcp/tcp_unsafe_state_autogen.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcpconntrack/tcp_conntrack.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/tcpconntrack/tcpconntrack_state_autogen.go0
-rw-r--r--pkg/tcpip/transport/udp/endpoint.go32
-rw-r--r--pkg/tcpip/transport/udp/endpoint_state.go18
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/udp/udp_packet_list.go0
-rw-r--r--[-rwxr-xr-x]pkg/tcpip/transport/udp/udp_state_autogen.go3
95 files changed, 138 insertions, 79 deletions
diff --git a/pkg/tcpip/adapters/gonet/gonet.go b/pkg/tcpip/adapters/gonet/gonet.go
index 6e0db2741..6e0db2741 100755..100644
--- a/pkg/tcpip/adapters/gonet/gonet.go
+++ b/pkg/tcpip/adapters/gonet/gonet.go
diff --git a/pkg/tcpip/adapters/gonet/gonet_state_autogen.go b/pkg/tcpip/adapters/gonet/gonet_state_autogen.go
index 7a5c5419e..7a5c5419e 100755..100644
--- a/pkg/tcpip/adapters/gonet/gonet_state_autogen.go
+++ b/pkg/tcpip/adapters/gonet/gonet_state_autogen.go
diff --git a/pkg/tcpip/buffer/buffer_state_autogen.go b/pkg/tcpip/buffer/buffer_state_autogen.go
index 954487771..954487771 100755..100644
--- a/pkg/tcpip/buffer/buffer_state_autogen.go
+++ b/pkg/tcpip/buffer/buffer_state_autogen.go
diff --git a/pkg/tcpip/hash/jenkins/jenkins_state_autogen.go b/pkg/tcpip/hash/jenkins/jenkins_state_autogen.go
index 216cc5a2e..216cc5a2e 100755..100644
--- a/pkg/tcpip/hash/jenkins/jenkins_state_autogen.go
+++ b/pkg/tcpip/hash/jenkins/jenkins_state_autogen.go
diff --git a/pkg/tcpip/header/header_state_autogen.go b/pkg/tcpip/header/header_state_autogen.go
index 015d7e12a..015d7e12a 100755..100644
--- a/pkg/tcpip/header/header_state_autogen.go
+++ b/pkg/tcpip/header/header_state_autogen.go
diff --git a/pkg/tcpip/header/ipv6_extension_headers.go b/pkg/tcpip/header/ipv6_extension_headers.go
index 2c4591409..2c4591409 100755..100644
--- a/pkg/tcpip/header/ipv6_extension_headers.go
+++ b/pkg/tcpip/header/ipv6_extension_headers.go
diff --git a/pkg/tcpip/header/ndp_neighbor_advert.go b/pkg/tcpip/header/ndp_neighbor_advert.go
index 505c92668..505c92668 100755..100644
--- a/pkg/tcpip/header/ndp_neighbor_advert.go
+++ b/pkg/tcpip/header/ndp_neighbor_advert.go
diff --git a/pkg/tcpip/header/ndp_neighbor_solicit.go b/pkg/tcpip/header/ndp_neighbor_solicit.go
index 3a1b8e139..3a1b8e139 100755..100644
--- a/pkg/tcpip/header/ndp_neighbor_solicit.go
+++ b/pkg/tcpip/header/ndp_neighbor_solicit.go
diff --git a/pkg/tcpip/header/ndp_options.go b/pkg/tcpip/header/ndp_options.go
index 5d3975c56..5d3975c56 100755..100644
--- a/pkg/tcpip/header/ndp_options.go
+++ b/pkg/tcpip/header/ndp_options.go
diff --git a/pkg/tcpip/header/ndp_router_advert.go b/pkg/tcpip/header/ndp_router_advert.go
index bf7610863..bf7610863 100755..100644
--- a/pkg/tcpip/header/ndp_router_advert.go
+++ b/pkg/tcpip/header/ndp_router_advert.go
diff --git a/pkg/tcpip/header/ndp_router_solicit.go b/pkg/tcpip/header/ndp_router_solicit.go
index 9e67ba95d..9e67ba95d 100755..100644
--- a/pkg/tcpip/header/ndp_router_solicit.go
+++ b/pkg/tcpip/header/ndp_router_solicit.go
diff --git a/pkg/tcpip/header/ndpoptionidentifier_string.go b/pkg/tcpip/header/ndpoptionidentifier_string.go
index 6fe9a336b..6fe9a336b 100755..100644
--- a/pkg/tcpip/header/ndpoptionidentifier_string.go
+++ b/pkg/tcpip/header/ndpoptionidentifier_string.go
diff --git a/pkg/tcpip/header/tcp.go b/pkg/tcpip/header/tcp.go
index 29454c4b9..4c6f808e5 100644
--- a/pkg/tcpip/header/tcp.go
+++ b/pkg/tcpip/header/tcp.go
@@ -66,6 +66,14 @@ const (
TCPOptionSACK = 5
)
+// Option Lengths.
+const (
+ TCPOptionMSSLength = 4
+ TCPOptionTSLength = 10
+ TCPOptionWSLength = 3
+ TCPOptionSackPermittedLength = 2
+)
+
// TCPFields contains the fields of a TCP packet. It is used to describe the
// fields of a packet that needs to be encoded.
type TCPFields struct {
@@ -494,14 +502,11 @@ func ParseTCPOptions(b []byte) TCPOptions {
// returns without encoding anything. It returns the number of bytes written to
// the provided buffer.
func EncodeMSSOption(mss uint32, b []byte) int {
- // mssOptionSize is the number of bytes in a valid MSS option.
- const mssOptionSize = 4
-
- if len(b) < mssOptionSize {
+ if len(b) < TCPOptionMSSLength {
return 0
}
- b[0], b[1], b[2], b[3] = TCPOptionMSS, mssOptionSize, byte(mss>>8), byte(mss)
- return mssOptionSize
+ b[0], b[1], b[2], b[3] = TCPOptionMSS, TCPOptionMSSLength, byte(mss>>8), byte(mss)
+ return TCPOptionMSSLength
}
// EncodeWSOption encodes the WS TCP option with the WS value in the
@@ -509,10 +514,10 @@ func EncodeMSSOption(mss uint32, b []byte) int {
// returns without encoding anything. It returns the number of bytes written to
// the provided buffer.
func EncodeWSOption(ws int, b []byte) int {
- if len(b) < 3 {
+ if len(b) < TCPOptionWSLength {
return 0
}
- b[0], b[1], b[2] = TCPOptionWS, 3, uint8(ws)
+ b[0], b[1], b[2] = TCPOptionWS, TCPOptionWSLength, uint8(ws)
return int(b[1])
}
@@ -521,10 +526,10 @@ func EncodeWSOption(ws int, b []byte) int {
// just returns without encoding anything. It returns the number of bytes
// written to the provided buffer.
func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int {
- if len(b) < 10 {
+ if len(b) < TCPOptionTSLength {
return 0
}
- b[0], b[1] = TCPOptionTS, 10
+ b[0], b[1] = TCPOptionTS, TCPOptionTSLength
binary.BigEndian.PutUint32(b[2:], tsVal)
binary.BigEndian.PutUint32(b[6:], tsEcr)
return int(b[1])
@@ -535,11 +540,11 @@ func EncodeTSOption(tsVal, tsEcr uint32, b []byte) int {
// encoding anything. It returns the number of bytes written to the provided
// buffer.
func EncodeSACKPermittedOption(b []byte) int {
- if len(b) < 2 {
+ if len(b) < TCPOptionSackPermittedLength {
return 0
}
- b[0], b[1] = TCPOptionSACKPermitted, 2
+ b[0], b[1] = TCPOptionSACKPermitted, TCPOptionSackPermittedLength
return int(b[1])
}
diff --git a/pkg/tcpip/link/channel/channel.go b/pkg/tcpip/link/channel/channel.go
index 9bf67686d..9bf67686d 100755..100644
--- a/pkg/tcpip/link/channel/channel.go
+++ b/pkg/tcpip/link/channel/channel.go
diff --git a/pkg/tcpip/link/channel/channel_state_autogen.go b/pkg/tcpip/link/channel/channel_state_autogen.go
index ce52482a2..ce52482a2 100755..100644
--- a/pkg/tcpip/link/channel/channel_state_autogen.go
+++ b/pkg/tcpip/link/channel/channel_state_autogen.go
diff --git a/pkg/tcpip/link/fdbased/fdbased_state_autogen.go b/pkg/tcpip/link/fdbased/fdbased_state_autogen.go
index b84e8f21c..b84e8f21c 100755..100644
--- a/pkg/tcpip/link/fdbased/fdbased_state_autogen.go
+++ b/pkg/tcpip/link/fdbased/fdbased_state_autogen.go
diff --git a/pkg/tcpip/link/fdbased/fdbased_unsafe_state_autogen.go b/pkg/tcpip/link/fdbased/fdbased_unsafe_state_autogen.go
index e2ed505b2..e2ed505b2 100755..100644
--- a/pkg/tcpip/link/fdbased/fdbased_unsafe_state_autogen.go
+++ b/pkg/tcpip/link/fdbased/fdbased_unsafe_state_autogen.go
diff --git a/pkg/tcpip/link/fdbased/packet_dispatchers.go b/pkg/tcpip/link/fdbased/packet_dispatchers.go
index cb4cbea69..3aaabd1aa 100644
--- a/pkg/tcpip/link/fdbased/packet_dispatchers.go
+++ b/pkg/tcpip/link/fdbased/packet_dispatchers.go
@@ -169,7 +169,7 @@ type recvMMsgDispatcher struct {
// iovecs is an array of array of iovec records where each iovec base
// pointer and length are initialzed to the corresponding view above,
- // except when GSO is neabled then the first iovec in each array of
+ // except when GSO is enabled then the first iovec in each array of
// iovecs points to a buffer for the vnet header which is stripped
// before the views are passed up the stack for further processing.
iovecs [][]syscall.Iovec
diff --git a/pkg/tcpip/link/loopback/loopback_state_autogen.go b/pkg/tcpip/link/loopback/loopback_state_autogen.go
index c00fd9f19..c00fd9f19 100755..100644
--- a/pkg/tcpip/link/loopback/loopback_state_autogen.go
+++ b/pkg/tcpip/link/loopback/loopback_state_autogen.go
diff --git a/pkg/tcpip/link/muxed/injectable.go b/pkg/tcpip/link/muxed/injectable.go
index a5478ce17..a5478ce17 100755..100644
--- a/pkg/tcpip/link/muxed/injectable.go
+++ b/pkg/tcpip/link/muxed/injectable.go
diff --git a/pkg/tcpip/link/muxed/muxed_state_autogen.go b/pkg/tcpip/link/muxed/muxed_state_autogen.go
index 56330e2a5..56330e2a5 100755..100644
--- a/pkg/tcpip/link/muxed/muxed_state_autogen.go
+++ b/pkg/tcpip/link/muxed/muxed_state_autogen.go
diff --git a/pkg/tcpip/link/qdisc/fifo/endpoint.go b/pkg/tcpip/link/qdisc/fifo/endpoint.go
index 54432194d..54432194d 100755..100644
--- a/pkg/tcpip/link/qdisc/fifo/endpoint.go
+++ b/pkg/tcpip/link/qdisc/fifo/endpoint.go
diff --git a/pkg/tcpip/link/qdisc/fifo/fifo_state_autogen.go b/pkg/tcpip/link/qdisc/fifo/fifo_state_autogen.go
index 9eb52b1cb..9eb52b1cb 100755..100644
--- a/pkg/tcpip/link/qdisc/fifo/fifo_state_autogen.go
+++ b/pkg/tcpip/link/qdisc/fifo/fifo_state_autogen.go
diff --git a/pkg/tcpip/link/qdisc/fifo/packet_buffer_queue.go b/pkg/tcpip/link/qdisc/fifo/packet_buffer_queue.go
index eb5abb906..eb5abb906 100755..100644
--- a/pkg/tcpip/link/qdisc/fifo/packet_buffer_queue.go
+++ b/pkg/tcpip/link/qdisc/fifo/packet_buffer_queue.go
diff --git a/pkg/tcpip/link/rawfile/rawfile_state_autogen.go b/pkg/tcpip/link/rawfile/rawfile_state_autogen.go
index 338e9679b..338e9679b 100755..100644
--- a/pkg/tcpip/link/rawfile/rawfile_state_autogen.go
+++ b/pkg/tcpip/link/rawfile/rawfile_state_autogen.go
diff --git a/pkg/tcpip/link/rawfile/rawfile_unsafe_state_autogen.go b/pkg/tcpip/link/rawfile/rawfile_unsafe_state_autogen.go
index 70d62c4a1..70d62c4a1 100755..100644
--- a/pkg/tcpip/link/rawfile/rawfile_unsafe_state_autogen.go
+++ b/pkg/tcpip/link/rawfile/rawfile_unsafe_state_autogen.go
diff --git a/pkg/tcpip/link/sharedmem/pipe/pipe.go b/pkg/tcpip/link/sharedmem/pipe/pipe.go
index 74c9f0311..74c9f0311 100755..100644
--- a/pkg/tcpip/link/sharedmem/pipe/pipe.go
+++ b/pkg/tcpip/link/sharedmem/pipe/pipe.go
diff --git a/pkg/tcpip/link/sharedmem/pipe/pipe_state_autogen.go b/pkg/tcpip/link/sharedmem/pipe/pipe_state_autogen.go
index d3b40feb4..d3b40feb4 100755..100644
--- a/pkg/tcpip/link/sharedmem/pipe/pipe_state_autogen.go
+++ b/pkg/tcpip/link/sharedmem/pipe/pipe_state_autogen.go
diff --git a/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe.go b/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe.go
index 62d17029e..62d17029e 100755..100644
--- a/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe.go
+++ b/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe.go
diff --git a/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe_state_autogen.go b/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe_state_autogen.go
index d3b40feb4..d3b40feb4 100755..100644
--- a/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe_state_autogen.go
+++ b/pkg/tcpip/link/sharedmem/pipe/pipe_unsafe_state_autogen.go
diff --git a/pkg/tcpip/link/sharedmem/pipe/rx.go b/pkg/tcpip/link/sharedmem/pipe/rx.go
index f22e533ac..f22e533ac 100755..100644
--- a/pkg/tcpip/link/sharedmem/pipe/rx.go
+++ b/pkg/tcpip/link/sharedmem/pipe/rx.go
diff --git a/pkg/tcpip/link/sharedmem/pipe/tx.go b/pkg/tcpip/link/sharedmem/pipe/tx.go
index 9841eb231..9841eb231 100755..100644
--- a/pkg/tcpip/link/sharedmem/pipe/tx.go
+++ b/pkg/tcpip/link/sharedmem/pipe/tx.go
diff --git a/pkg/tcpip/link/sharedmem/queue/queue_state_autogen.go b/pkg/tcpip/link/sharedmem/queue/queue_state_autogen.go
index 563d4fbb4..563d4fbb4 100755..100644
--- a/pkg/tcpip/link/sharedmem/queue/queue_state_autogen.go
+++ b/pkg/tcpip/link/sharedmem/queue/queue_state_autogen.go
diff --git a/pkg/tcpip/link/sharedmem/queue/rx.go b/pkg/tcpip/link/sharedmem/queue/rx.go
index 696e6c9e5..696e6c9e5 100755..100644
--- a/pkg/tcpip/link/sharedmem/queue/rx.go
+++ b/pkg/tcpip/link/sharedmem/queue/rx.go
diff --git a/pkg/tcpip/link/sharedmem/queue/tx.go b/pkg/tcpip/link/sharedmem/queue/tx.go
index beffe807b..beffe807b 100755..100644
--- a/pkg/tcpip/link/sharedmem/queue/tx.go
+++ b/pkg/tcpip/link/sharedmem/queue/tx.go
diff --git a/pkg/tcpip/link/sharedmem/rx.go b/pkg/tcpip/link/sharedmem/rx.go
index eec11e4cb..eec11e4cb 100755..100644
--- a/pkg/tcpip/link/sharedmem/rx.go
+++ b/pkg/tcpip/link/sharedmem/rx.go
diff --git a/pkg/tcpip/link/sharedmem/sharedmem.go b/pkg/tcpip/link/sharedmem/sharedmem.go
index 0796d717e..0796d717e 100755..100644
--- a/pkg/tcpip/link/sharedmem/sharedmem.go
+++ b/pkg/tcpip/link/sharedmem/sharedmem.go
diff --git a/pkg/tcpip/link/sharedmem/sharedmem_state_autogen.go b/pkg/tcpip/link/sharedmem/sharedmem_state_autogen.go
index bc12017b2..bc12017b2 100755..100644
--- a/pkg/tcpip/link/sharedmem/sharedmem_state_autogen.go
+++ b/pkg/tcpip/link/sharedmem/sharedmem_state_autogen.go
diff --git a/pkg/tcpip/link/sharedmem/sharedmem_unsafe.go b/pkg/tcpip/link/sharedmem/sharedmem_unsafe.go
index f7e816a41..f7e816a41 100755..100644
--- a/pkg/tcpip/link/sharedmem/sharedmem_unsafe.go
+++ b/pkg/tcpip/link/sharedmem/sharedmem_unsafe.go
diff --git a/pkg/tcpip/link/sharedmem/sharedmem_unsafe_state_autogen.go b/pkg/tcpip/link/sharedmem/sharedmem_unsafe_state_autogen.go
index ac3a66520..ac3a66520 100755..100644
--- a/pkg/tcpip/link/sharedmem/sharedmem_unsafe_state_autogen.go
+++ b/pkg/tcpip/link/sharedmem/sharedmem_unsafe_state_autogen.go
diff --git a/pkg/tcpip/link/sharedmem/tx.go b/pkg/tcpip/link/sharedmem/tx.go
index 6b8d7859d..6b8d7859d 100755..100644
--- a/pkg/tcpip/link/sharedmem/tx.go
+++ b/pkg/tcpip/link/sharedmem/tx.go
diff --git a/pkg/tcpip/link/sniffer/sniffer_state_autogen.go b/pkg/tcpip/link/sniffer/sniffer_state_autogen.go
index 8d79defea..8d79defea 100755..100644
--- a/pkg/tcpip/link/sniffer/sniffer_state_autogen.go
+++ b/pkg/tcpip/link/sniffer/sniffer_state_autogen.go
diff --git a/pkg/tcpip/link/tun/device.go b/pkg/tcpip/link/tun/device.go
index 617446ea2..617446ea2 100755..100644
--- a/pkg/tcpip/link/tun/device.go
+++ b/pkg/tcpip/link/tun/device.go
diff --git a/pkg/tcpip/link/tun/protocol.go b/pkg/tcpip/link/tun/protocol.go
index 89d9d91a9..89d9d91a9 100755..100644
--- a/pkg/tcpip/link/tun/protocol.go
+++ b/pkg/tcpip/link/tun/protocol.go
diff --git a/pkg/tcpip/link/tun/tun_state_autogen.go b/pkg/tcpip/link/tun/tun_state_autogen.go
index 4b70647af..4b70647af 100755..100644
--- a/pkg/tcpip/link/tun/tun_state_autogen.go
+++ b/pkg/tcpip/link/tun/tun_state_autogen.go
diff --git a/pkg/tcpip/link/tun/tun_unsafe.go b/pkg/tcpip/link/tun/tun_unsafe.go
index 09ca9b527..09ca9b527 100755..100644
--- a/pkg/tcpip/link/tun/tun_unsafe.go
+++ b/pkg/tcpip/link/tun/tun_unsafe.go
diff --git a/pkg/tcpip/link/tun/tun_unsafe_state_autogen.go b/pkg/tcpip/link/tun/tun_unsafe_state_autogen.go
index 149299ea3..149299ea3 100755..100644
--- a/pkg/tcpip/link/tun/tun_unsafe_state_autogen.go
+++ b/pkg/tcpip/link/tun/tun_unsafe_state_autogen.go
diff --git a/pkg/tcpip/link/waitable/waitable.go b/pkg/tcpip/link/waitable/waitable.go
index 2b3741276..2b3741276 100755..100644
--- a/pkg/tcpip/link/waitable/waitable.go
+++ b/pkg/tcpip/link/waitable/waitable.go
diff --git a/pkg/tcpip/link/waitable/waitable_state_autogen.go b/pkg/tcpip/link/waitable/waitable_state_autogen.go
index 059424fa0..059424fa0 100755..100644
--- a/pkg/tcpip/link/waitable/waitable_state_autogen.go
+++ b/pkg/tcpip/link/waitable/waitable_state_autogen.go
diff --git a/pkg/tcpip/network/arp/arp_state_autogen.go b/pkg/tcpip/network/arp/arp_state_autogen.go
index 5cd8535e3..5cd8535e3 100755..100644
--- a/pkg/tcpip/network/arp/arp_state_autogen.go
+++ b/pkg/tcpip/network/arp/arp_state_autogen.go
diff --git a/pkg/tcpip/network/fragmentation/fragmentation_state_autogen.go b/pkg/tcpip/network/fragmentation/fragmentation_state_autogen.go
index cbaecdaa7..cbaecdaa7 100755..100644
--- a/pkg/tcpip/network/fragmentation/fragmentation_state_autogen.go
+++ b/pkg/tcpip/network/fragmentation/fragmentation_state_autogen.go
diff --git a/pkg/tcpip/network/fragmentation/reassembler_list.go b/pkg/tcpip/network/fragmentation/reassembler_list.go
index b5d40bd25..b5d40bd25 100755..100644
--- a/pkg/tcpip/network/fragmentation/reassembler_list.go
+++ b/pkg/tcpip/network/fragmentation/reassembler_list.go
diff --git a/pkg/tcpip/network/hash/hash_state_autogen.go b/pkg/tcpip/network/hash/hash_state_autogen.go
index 9467fe298..9467fe298 100755..100644
--- a/pkg/tcpip/network/hash/hash_state_autogen.go
+++ b/pkg/tcpip/network/hash/hash_state_autogen.go
diff --git a/pkg/tcpip/network/ipv4/ipv4_state_autogen.go b/pkg/tcpip/network/ipv4/ipv4_state_autogen.go
index 250b2128e..250b2128e 100755..100644
--- a/pkg/tcpip/network/ipv4/ipv4_state_autogen.go
+++ b/pkg/tcpip/network/ipv4/ipv4_state_autogen.go
diff --git a/pkg/tcpip/network/ipv6/ipv6_state_autogen.go b/pkg/tcpip/network/ipv6/ipv6_state_autogen.go
index 40c67d440..40c67d440 100755..100644
--- a/pkg/tcpip/network/ipv6/ipv6_state_autogen.go
+++ b/pkg/tcpip/network/ipv6/ipv6_state_autogen.go
diff --git a/pkg/tcpip/ports/ports_state_autogen.go b/pkg/tcpip/ports/ports_state_autogen.go
index f0ee1bb11..f0ee1bb11 100755..100644
--- a/pkg/tcpip/ports/ports_state_autogen.go
+++ b/pkg/tcpip/ports/ports_state_autogen.go
diff --git a/pkg/tcpip/seqnum/seqnum_state_autogen.go b/pkg/tcpip/seqnum/seqnum_state_autogen.go
index 23e79811d..23e79811d 100755..100644
--- a/pkg/tcpip/seqnum/seqnum_state_autogen.go
+++ b/pkg/tcpip/seqnum/seqnum_state_autogen.go
diff --git a/pkg/tcpip/stack/conntrack.go b/pkg/tcpip/stack/conntrack.go
index 7d1ede1f2..7d1ede1f2 100755..100644
--- a/pkg/tcpip/stack/conntrack.go
+++ b/pkg/tcpip/stack/conntrack.go
diff --git a/pkg/tcpip/stack/dhcpv6configurationfromndpra_string.go b/pkg/tcpip/stack/dhcpv6configurationfromndpra_string.go
index d199ded6a..d199ded6a 100755..100644
--- a/pkg/tcpip/stack/dhcpv6configurationfromndpra_string.go
+++ b/pkg/tcpip/stack/dhcpv6configurationfromndpra_string.go
diff --git a/pkg/tcpip/stack/forwarder.go b/pkg/tcpip/stack/forwarder.go
index 6b64cd37f..6b64cd37f 100755..100644
--- a/pkg/tcpip/stack/forwarder.go
+++ b/pkg/tcpip/stack/forwarder.go
diff --git a/pkg/tcpip/stack/iptables.go b/pkg/tcpip/stack/iptables.go
index 443423b3c..443423b3c 100755..100644
--- a/pkg/tcpip/stack/iptables.go
+++ b/pkg/tcpip/stack/iptables.go
diff --git a/pkg/tcpip/stack/iptables_targets.go b/pkg/tcpip/stack/iptables_targets.go
index 36cc6275d..36cc6275d 100755..100644
--- a/pkg/tcpip/stack/iptables_targets.go
+++ b/pkg/tcpip/stack/iptables_targets.go
diff --git a/pkg/tcpip/stack/iptables_types.go b/pkg/tcpip/stack/iptables_types.go
index fe06007ae..fe06007ae 100755..100644
--- a/pkg/tcpip/stack/iptables_types.go
+++ b/pkg/tcpip/stack/iptables_types.go
diff --git a/pkg/tcpip/stack/linkaddrentry_list.go b/pkg/tcpip/stack/linkaddrentry_list.go
index 43022f9b3..43022f9b3 100755..100644
--- a/pkg/tcpip/stack/linkaddrentry_list.go
+++ b/pkg/tcpip/stack/linkaddrentry_list.go
diff --git a/pkg/tcpip/stack/ndp.go b/pkg/tcpip/stack/ndp.go
index 526c7d6ff..526c7d6ff 100755..100644
--- a/pkg/tcpip/stack/ndp.go
+++ b/pkg/tcpip/stack/ndp.go
diff --git a/pkg/tcpip/stack/packet_buffer.go b/pkg/tcpip/stack/packet_buffer.go
index 926df4d7b..926df4d7b 100755..100644
--- a/pkg/tcpip/stack/packet_buffer.go
+++ b/pkg/tcpip/stack/packet_buffer.go
diff --git a/pkg/tcpip/stack/packet_buffer_list.go b/pkg/tcpip/stack/packet_buffer_list.go
index 460c74c5a..460c74c5a 100755..100644
--- a/pkg/tcpip/stack/packet_buffer_list.go
+++ b/pkg/tcpip/stack/packet_buffer_list.go
diff --git a/pkg/tcpip/stack/rand.go b/pkg/tcpip/stack/rand.go
index 421fb5c15..421fb5c15 100755..100644
--- a/pkg/tcpip/stack/rand.go
+++ b/pkg/tcpip/stack/rand.go
diff --git a/pkg/tcpip/stack/stack_state_autogen.go b/pkg/tcpip/stack/stack_state_autogen.go
index 6e98e8e95..6e98e8e95 100755..100644
--- a/pkg/tcpip/stack/stack_state_autogen.go
+++ b/pkg/tcpip/stack/stack_state_autogen.go
diff --git a/pkg/tcpip/tcpip.go b/pkg/tcpip/tcpip.go
index 45e930ad8..b7b227328 100644
--- a/pkg/tcpip/tcpip.go
+++ b/pkg/tcpip/tcpip.go
@@ -110,6 +110,71 @@ var (
ErrAddressFamilyNotSupported = &Error{msg: "address family not supported by protocol"}
)
+var messageToError map[string]*Error
+
+var populate sync.Once
+
+// StringToError converts an error message to the error.
+func StringToError(s string) *Error {
+ populate.Do(func() {
+ var errors = []*Error{
+ ErrUnknownProtocol,
+ ErrUnknownNICID,
+ ErrUnknownDevice,
+ ErrUnknownProtocolOption,
+ ErrDuplicateNICID,
+ ErrDuplicateAddress,
+ ErrNoRoute,
+ ErrBadLinkEndpoint,
+ ErrAlreadyBound,
+ ErrInvalidEndpointState,
+ ErrAlreadyConnecting,
+ ErrAlreadyConnected,
+ ErrNoPortAvailable,
+ ErrPortInUse,
+ ErrBadLocalAddress,
+ ErrClosedForSend,
+ ErrClosedForReceive,
+ ErrWouldBlock,
+ ErrConnectionRefused,
+ ErrTimeout,
+ ErrAborted,
+ ErrConnectStarted,
+ ErrDestinationRequired,
+ ErrNotSupported,
+ ErrQueueSizeNotSupported,
+ ErrNotConnected,
+ ErrConnectionReset,
+ ErrConnectionAborted,
+ ErrNoSuchFile,
+ ErrInvalidOptionValue,
+ ErrNoLinkAddress,
+ ErrBadAddress,
+ ErrNetworkUnreachable,
+ ErrMessageTooLong,
+ ErrNoBufferSpace,
+ ErrBroadcastDisabled,
+ ErrNotPermitted,
+ ErrAddressFamilyNotSupported,
+ }
+
+ messageToError = make(map[string]*Error)
+ for _, e := range errors {
+ if messageToError[e.String()] != nil {
+ panic("tcpip errors with duplicated message: " + e.String())
+ }
+ messageToError[e.String()] = e
+ }
+ })
+
+ e, ok := messageToError[s]
+ if !ok {
+ panic("unknown error message: " + s)
+ }
+
+ return e
+}
+
// Errors related to Subnet
var (
errSubnetLengthMismatch = errors.New("subnet length of address and mask differ")
diff --git a/pkg/tcpip/tcpip_state_autogen.go b/pkg/tcpip/tcpip_state_autogen.go
index 8ea900688..8ea900688 100755..100644
--- a/pkg/tcpip/tcpip_state_autogen.go
+++ b/pkg/tcpip/tcpip_state_autogen.go
diff --git a/pkg/tcpip/tcpip_unsafe_state_autogen.go b/pkg/tcpip/tcpip_unsafe_state_autogen.go
index 32d2350f4..32d2350f4 100755..100644
--- a/pkg/tcpip/tcpip_unsafe_state_autogen.go
+++ b/pkg/tcpip/tcpip_unsafe_state_autogen.go
diff --git a/pkg/tcpip/timer.go b/pkg/tcpip/timer.go
index 59f3b391f..59f3b391f 100755..100644
--- a/pkg/tcpip/timer.go
+++ b/pkg/tcpip/timer.go
diff --git a/pkg/tcpip/transport/icmp/icmp_packet_list.go b/pkg/tcpip/transport/icmp/icmp_packet_list.go
index 42d63f976..42d63f976 100755..100644
--- a/pkg/tcpip/transport/icmp/icmp_packet_list.go
+++ b/pkg/tcpip/transport/icmp/icmp_packet_list.go
diff --git a/pkg/tcpip/transport/icmp/icmp_state_autogen.go b/pkg/tcpip/transport/icmp/icmp_state_autogen.go
index c26460a4b..c26460a4b 100755..100644
--- a/pkg/tcpip/transport/icmp/icmp_state_autogen.go
+++ b/pkg/tcpip/transport/icmp/icmp_state_autogen.go
diff --git a/pkg/tcpip/transport/packet/endpoint.go b/pkg/tcpip/transport/packet/endpoint.go
index 23158173d..23158173d 100755..100644
--- a/pkg/tcpip/transport/packet/endpoint.go
+++ b/pkg/tcpip/transport/packet/endpoint.go
diff --git a/pkg/tcpip/transport/packet/endpoint_state.go b/pkg/tcpip/transport/packet/endpoint_state.go
index 9b88f17e4..9b88f17e4 100755..100644
--- a/pkg/tcpip/transport/packet/endpoint_state.go
+++ b/pkg/tcpip/transport/packet/endpoint_state.go
diff --git a/pkg/tcpip/transport/packet/packet_list.go b/pkg/tcpip/transport/packet/packet_list.go
index 5231b066f..5231b066f 100755..100644
--- a/pkg/tcpip/transport/packet/packet_list.go
+++ b/pkg/tcpip/transport/packet/packet_list.go
diff --git a/pkg/tcpip/transport/packet/packet_state_autogen.go b/pkg/tcpip/transport/packet/packet_state_autogen.go
index 8ff339e08..8ff339e08 100755..100644
--- a/pkg/tcpip/transport/packet/packet_state_autogen.go
+++ b/pkg/tcpip/transport/packet/packet_state_autogen.go
diff --git a/pkg/tcpip/transport/raw/raw_packet_list.go b/pkg/tcpip/transport/raw/raw_packet_list.go
index 15a8c845b..15a8c845b 100755..100644
--- a/pkg/tcpip/transport/raw/raw_packet_list.go
+++ b/pkg/tcpip/transport/raw/raw_packet_list.go
diff --git a/pkg/tcpip/transport/raw/raw_state_autogen.go b/pkg/tcpip/transport/raw/raw_state_autogen.go
index c755fa847..c755fa847 100755..100644
--- a/pkg/tcpip/transport/raw/raw_state_autogen.go
+++ b/pkg/tcpip/transport/raw/raw_state_autogen.go
diff --git a/pkg/tcpip/transport/tcp/connect_unsafe.go b/pkg/tcpip/transport/tcp/connect_unsafe.go
index cfc304616..cfc304616 100755..100644
--- a/pkg/tcpip/transport/tcp/connect_unsafe.go
+++ b/pkg/tcpip/transport/tcp/connect_unsafe.go
diff --git a/pkg/tcpip/transport/tcp/dispatcher.go b/pkg/tcpip/transport/tcp/dispatcher.go
index 6062ca916..6062ca916 100755..100644
--- a/pkg/tcpip/transport/tcp/dispatcher.go
+++ b/pkg/tcpip/transport/tcp/dispatcher.go
diff --git a/pkg/tcpip/transport/tcp/endpoint_state.go b/pkg/tcpip/transport/tcp/endpoint_state.go
index 8b7562396..fc43c11e2 100644
--- a/pkg/tcpip/transport/tcp/endpoint_state.go
+++ b/pkg/tcpip/transport/tcp/endpoint_state.go
@@ -314,7 +314,7 @@ func (e *endpoint) loadLastError(s string) {
return
}
- e.lastError = loadError(s)
+ e.lastError = tcpip.StringToError(s)
}
// saveHardError is invoked by stateify.
@@ -332,71 +332,7 @@ func (e *EndpointInfo) loadHardError(s string) {
return
}
- e.HardError = loadError(s)
-}
-
-var messageToError map[string]*tcpip.Error
-
-var populate sync.Once
-
-func loadError(s string) *tcpip.Error {
- populate.Do(func() {
- var errors = []*tcpip.Error{
- tcpip.ErrUnknownProtocol,
- tcpip.ErrUnknownNICID,
- tcpip.ErrUnknownDevice,
- tcpip.ErrUnknownProtocolOption,
- tcpip.ErrDuplicateNICID,
- tcpip.ErrDuplicateAddress,
- tcpip.ErrNoRoute,
- tcpip.ErrBadLinkEndpoint,
- tcpip.ErrAlreadyBound,
- tcpip.ErrInvalidEndpointState,
- tcpip.ErrAlreadyConnecting,
- tcpip.ErrAlreadyConnected,
- tcpip.ErrNoPortAvailable,
- tcpip.ErrPortInUse,
- tcpip.ErrBadLocalAddress,
- tcpip.ErrClosedForSend,
- tcpip.ErrClosedForReceive,
- tcpip.ErrWouldBlock,
- tcpip.ErrConnectionRefused,
- tcpip.ErrTimeout,
- tcpip.ErrAborted,
- tcpip.ErrConnectStarted,
- tcpip.ErrDestinationRequired,
- tcpip.ErrNotSupported,
- tcpip.ErrQueueSizeNotSupported,
- tcpip.ErrNotConnected,
- tcpip.ErrConnectionReset,
- tcpip.ErrConnectionAborted,
- tcpip.ErrNoSuchFile,
- tcpip.ErrInvalidOptionValue,
- tcpip.ErrNoLinkAddress,
- tcpip.ErrBadAddress,
- tcpip.ErrNetworkUnreachable,
- tcpip.ErrMessageTooLong,
- tcpip.ErrNoBufferSpace,
- tcpip.ErrBroadcastDisabled,
- tcpip.ErrNotPermitted,
- tcpip.ErrAddressFamilyNotSupported,
- }
-
- messageToError = make(map[string]*tcpip.Error)
- for _, e := range errors {
- if messageToError[e.String()] != nil {
- panic("tcpip errors with duplicated message: " + e.String())
- }
- messageToError[e.String()] = e
- }
- })
-
- e, ok := messageToError[s]
- if !ok {
- panic("unknown error message: " + s)
- }
-
- return e
+ e.HardError = tcpip.StringToError(s)
}
// saveMeasureTime is invoked by stateify.
diff --git a/pkg/tcpip/transport/tcp/rcv_state.go b/pkg/tcpip/transport/tcp/rcv_state.go
index 2bf21a2e7..2bf21a2e7 100755..100644
--- a/pkg/tcpip/transport/tcp/rcv_state.go
+++ b/pkg/tcpip/transport/tcp/rcv_state.go
diff --git a/pkg/tcpip/transport/tcp/tcp_endpoint_list.go b/pkg/tcpip/transport/tcp/tcp_endpoint_list.go
index fb7046d8f..fb7046d8f 100755..100644
--- a/pkg/tcpip/transport/tcp/tcp_endpoint_list.go
+++ b/pkg/tcpip/transport/tcp/tcp_endpoint_list.go
diff --git a/pkg/tcpip/transport/tcp/tcp_segment_list.go b/pkg/tcpip/transport/tcp/tcp_segment_list.go
index 21638041c..21638041c 100755..100644
--- a/pkg/tcpip/transport/tcp/tcp_segment_list.go
+++ b/pkg/tcpip/transport/tcp/tcp_segment_list.go
diff --git a/pkg/tcpip/transport/tcp/tcp_state_autogen.go b/pkg/tcpip/transport/tcp/tcp_state_autogen.go
index e5d0a218a..e5d0a218a 100755..100644
--- a/pkg/tcpip/transport/tcp/tcp_state_autogen.go
+++ b/pkg/tcpip/transport/tcp/tcp_state_autogen.go
diff --git a/pkg/tcpip/transport/tcp/tcp_unsafe_state_autogen.go b/pkg/tcpip/transport/tcp/tcp_unsafe_state_autogen.go
index 4cb82fcc9..4cb82fcc9 100755..100644
--- a/pkg/tcpip/transport/tcp/tcp_unsafe_state_autogen.go
+++ b/pkg/tcpip/transport/tcp/tcp_unsafe_state_autogen.go
diff --git a/pkg/tcpip/transport/tcpconntrack/tcp_conntrack.go b/pkg/tcpip/transport/tcpconntrack/tcp_conntrack.go
index 12bc1b5b5..12bc1b5b5 100755..100644
--- a/pkg/tcpip/transport/tcpconntrack/tcp_conntrack.go
+++ b/pkg/tcpip/transport/tcpconntrack/tcp_conntrack.go
diff --git a/pkg/tcpip/transport/tcpconntrack/tcpconntrack_state_autogen.go b/pkg/tcpip/transport/tcpconntrack/tcpconntrack_state_autogen.go
index ff53204da..ff53204da 100755..100644
--- a/pkg/tcpip/transport/tcpconntrack/tcpconntrack_state_autogen.go
+++ b/pkg/tcpip/transport/tcpconntrack/tcpconntrack_state_autogen.go
diff --git a/pkg/tcpip/transport/udp/endpoint.go b/pkg/tcpip/transport/udp/endpoint.go
index 756ab913a..647b2067a 100644
--- a/pkg/tcpip/transport/udp/endpoint.go
+++ b/pkg/tcpip/transport/udp/endpoint.go
@@ -106,6 +106,9 @@ type endpoint struct {
bindToDevice tcpip.NICID
broadcast bool
+ lastErrorMu sync.Mutex `state:"nosave"`
+ lastError *tcpip.Error `state:".(string)"`
+
// Values used to reserve a port or register a transport endpoint.
// (which ever happens first).
boundBindToDevice tcpip.NICID
@@ -188,6 +191,15 @@ func (e *endpoint) UniqueID() uint64 {
return e.uniqueID
}
+func (e *endpoint) takeLastError() *tcpip.Error {
+ e.lastErrorMu.Lock()
+ defer e.lastErrorMu.Unlock()
+
+ err := e.lastError
+ e.lastError = nil
+ return err
+}
+
// Abort implements stack.TransportEndpoint.Abort.
func (e *endpoint) Abort() {
e.Close()
@@ -243,6 +255,10 @@ func (e *endpoint) IPTables() (stack.IPTables, error) {
// Read reads data from the endpoint. This method does not block if
// there is no data pending.
func (e *endpoint) Read(addr *tcpip.FullAddress) (buffer.View, tcpip.ControlMessages, *tcpip.Error) {
+ if err := e.takeLastError(); err != nil {
+ return buffer.View{}, tcpip.ControlMessages{}, err
+ }
+
e.rcvMu.Lock()
if e.rcvList.Empty() {
@@ -382,6 +398,10 @@ func (e *endpoint) Write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, <-c
}
func (e *endpoint) write(p tcpip.Payloader, opts tcpip.WriteOptions) (int64, <-chan struct{}, *tcpip.Error) {
+ if err := e.takeLastError(); err != nil {
+ return 0, nil, err
+ }
+
// MSG_MORE is unimplemented. (This also means that MSG_EOR is a no-op.)
if opts.More {
return 0, nil, tcpip.ErrInvalidOptionValue
@@ -853,6 +873,7 @@ func (e *endpoint) GetSockOptInt(opt tcpip.SockOptInt) (int, *tcpip.Error) {
func (e *endpoint) GetSockOpt(opt interface{}) *tcpip.Error {
switch o := opt.(type) {
case tcpip.ErrorOption:
+ return e.takeLastError()
case *tcpip.MulticastInterfaceOption:
e.mu.Lock()
*o = tcpip.MulticastInterfaceOption{
@@ -1316,6 +1337,17 @@ func (e *endpoint) HandlePacket(r *stack.Route, id stack.TransportEndpointID, pk
// HandleControlPacket implements stack.TransportEndpoint.HandleControlPacket.
func (e *endpoint) HandleControlPacket(id stack.TransportEndpointID, typ stack.ControlType, extra uint32, pkt stack.PacketBuffer) {
+ if typ == stack.ControlPortUnreachable {
+ e.mu.RLock()
+ defer e.mu.RUnlock()
+
+ if e.state == StateConnected {
+ e.lastErrorMu.Lock()
+ defer e.lastErrorMu.Unlock()
+
+ e.lastError = tcpip.ErrConnectionRefused
+ }
+ }
}
// State implements tcpip.Endpoint.State.
diff --git a/pkg/tcpip/transport/udp/endpoint_state.go b/pkg/tcpip/transport/udp/endpoint_state.go
index 466bd9381..851e6b635 100644
--- a/pkg/tcpip/transport/udp/endpoint_state.go
+++ b/pkg/tcpip/transport/udp/endpoint_state.go
@@ -37,6 +37,24 @@ func (u *udpPacket) loadData(data buffer.VectorisedView) {
u.data = data
}
+// saveLastError is invoked by stateify.
+func (e *endpoint) saveLastError() string {
+ if e.lastError == nil {
+ return ""
+ }
+
+ return e.lastError.String()
+}
+
+// loadLastError is invoked by stateify.
+func (e *endpoint) loadLastError(s string) {
+ if s == "" {
+ return
+ }
+
+ e.lastError = tcpip.StringToError(s)
+}
+
// beforeSave is invoked by stateify.
func (e *endpoint) beforeSave() {
// Stop incoming packets from being handled (and mutate endpoint state).
diff --git a/pkg/tcpip/transport/udp/udp_packet_list.go b/pkg/tcpip/transport/udp/udp_packet_list.go
index a6513e1e4..a6513e1e4 100755..100644
--- a/pkg/tcpip/transport/udp/udp_packet_list.go
+++ b/pkg/tcpip/transport/udp/udp_packet_list.go
diff --git a/pkg/tcpip/transport/udp/udp_state_autogen.go b/pkg/tcpip/transport/udp/udp_state_autogen.go
index e8ab82021..a6d58f290 100755..100644
--- a/pkg/tcpip/transport/udp/udp_state_autogen.go
+++ b/pkg/tcpip/transport/udp/udp_state_autogen.go
@@ -33,6 +33,8 @@ func (x *endpoint) save(m state.Map) {
x.beforeSave()
var rcvBufSizeMax int = x.saveRcvBufSizeMax()
m.SaveValue("rcvBufSizeMax", rcvBufSizeMax)
+ var lastError string = x.saveLastError()
+ m.SaveValue("lastError", lastError)
m.Save("TransportEndpointInfo", &x.TransportEndpointInfo)
m.Save("waiterQueue", &x.waiterQueue)
m.Save("uniqueID", &x.uniqueID)
@@ -95,6 +97,7 @@ func (x *endpoint) load(m state.Map) {
m.Load("effectiveNetProtos", &x.effectiveNetProtos)
m.Load("owner", &x.owner)
m.LoadValue("rcvBufSizeMax", new(int), func(y interface{}) { x.loadRcvBufSizeMax(y.(int)) })
+ m.LoadValue("lastError", new(string), func(y interface{}) { x.loadLastError(y.(string)) })
m.AfterLoad(x.afterLoad)
}