On Wed, Apr 14, 2021 at 05:43:52PM -0700, Cong Wang . wrote:
On Wed, Mar 17, 2021 at 8:45 AM Stefan Hajnoczi [off-list ref] wrote:
quoted
Please stick to UDP semantics as much as possible so that applications
can be ported easily and developers aren't surprised by unexpected
behavior. UDP packets sent to a destination that has no listen socket
result in a Connection Refused error. vsock dgrams should behave in the
same way.
There is no connection refused error for UDP, as it is clearly connectionless.
What you suggested might be an ICMP unreachable error, however, vsock does
not have anything equivalent. So, I think there is no error returned
in this scenario
for vsock datagram.
Yes, exactly. UDP uses ICMP unreachable:
16:55:40.380292 IP 127.0.0.1.41519 > 127.0.0.1.1234: UDP, length 5
16:55:40.380308 IP 127.0.0.1 > 127.0.0.1: ICMP 127.0.0.1 udp port 1234 unreachable, length 41
This is mentioned a bit here:
https://tools.ietf.org/html/rfc8085#section-5.2
Here is how Python's socket module produces an ConnectionRefused
exception:
socket(AF_INET, SOCK_DGRAM|SOCK_CLOEXEC, IPPROTO_IP) = 3
sendto(3, "hello", 5, 0, {sa_family=AF_INET, sin_port=htons(1234), sin_addr=inet_addr("127.0.0.1")}, 16) = 5
getsockname(3, {sa_family=AF_INET, sin_port=htons(41519), sin_addr=inet_addr("0.0.0.0")}, [16]) = 0
getpeername(3, 0x7ffc43c99a20, [16]) = -1 ENOTCONN (Transport endpoint is not connected)
UDP itself may not carry this information but applications do rely on
the ICMP information as shown above.
The Linux network stack implementation is here:
net/ipv4/udp.c:__udp4_lib_err().
Please take a look and decide how vsock dgrams can have similar
semantics.
Stefan