From fb2a4fbefe6cf917787ff070cf5bbdecab1fb1e1 Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 10 Sep 2023 15:41:33 +0200 Subject: [PATCH] UDP: Enable sending and receiving of: local-address, traffic-class & hop-limit per packet. --- Posix-compatibility.md | 23 ++++++++++++++----- example-world.md | 51 ++++++++++++++++++++++++++++++++++++++++-- wit/udp.wit | 48 ++++++++++++++++++++++++++++++++++----- 3 files changed, 108 insertions(+), 14 deletions(-) diff --git a/Posix-compatibility.md b/Posix-compatibility.md index a2ba1c6..e3ea4f4 100644 --- a/Posix-compatibility.md +++ b/Posix-compatibility.md @@ -76,6 +76,13 @@ None of the flags are directly present in WASI Sockets: - `MSG_EOR`: N/A (not supported on TCP & UDP sockets) - `MSG_CMSG_CLOEXEC`: N/A (only used on Unix domain sockets) +The following ancillary messages are available as regular fields in the datagram parameter: +- `IP_PKTINFO`/`IPV6_PKTINFO` +- `IP_TOS`/`IPV6_TCLASS` +- `IP_TTL`/`IPV6_HOPLIMIT` + +There are included unconditionally. There is no need for their RECV* equivalents (IP_RECVTTL, IP_RECVTOS, IP_RECVPKTINFO, etc...) + ### `write`, `writev`, `send`, `sendto`, `sendmsg`, `sendmmsg` (non-standard) TCP sockets can be written to using [`streams::(blocking-)write`](streams). UDP sockets can be written to using [`udp::send`](udp). @@ -90,6 +97,10 @@ None of the flags are directly present in WASI Sockets: - `MSG_OOB` (UDP): N/A - `MSG_EOR`: N/A (not supported on TCP & UDP sockets) +The following ancillary messages are available as regular fields in the datagram parameter: +- `IP_PKTINFO`/`IPV6_PKTINFO` +- `IP_TOS`/`IPV6_TCLASS` +- `IP_TTL`/`IPV6_HOPLIMIT` ### `sendfile` (non-standard) - TCP: Part of the WASI Streams proposal as [`output-stream::forward`](streams) @@ -157,14 +168,14 @@ Columns: | IPV6_HDRINCL | ⛔ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | Out of scope. Raw sockets only. | | IP_TTL | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | [`tcp::(set-)unicast-hop-limit`](tcp)
[`udp::(set-)unicast-hop-limit`](udp) | | IPV6_UNICAST_HOPS | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | [`tcp::(set-)unicast-hop-limit`](tcp)
[`udp::(set-)unicast-hop-limit`](udp) | -| IP_RECVTTL | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | -| IPV6_RECVHOPLIMIT | ❔ | ❌ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | +| IP_RECVTTL | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | See [`udp::receive`](udp) | +| IPV6_RECVHOPLIMIT | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | See [`udp::receive`](udp)

IPV6_HOPLIMIT on Windows. | | IP_TOS | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | | | IPV6_TCLASS | ❔ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | | -| IP_RECVTOS | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | | -| IPV6_RECVTCLASS | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | | -| IP_RECVPKTINFO | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | IP_PKTINFO on Linux & Windows, IP_RECVDSTADDR+IP_RECVIF on MacOS & FreeBSD. | -| IPV6_RECVPKTINFO | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | IPV6_PKTINFO on Windows. | +| IP_RECVTOS | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | See [`udp::receive`](udp) | +| IPV6_RECVTCLASS | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ❌ | See [`udp::receive`](udp) | +| IP_RECVPKTINFO | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | See [`udp::receive`](udp)

IP_PKTINFO on Linux & Windows, IP_RECVDSTADDR+IP_RECVIF on MacOS & FreeBSD. | +| IPV6_RECVPKTINFO | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | See [`udp::receive`](udp)

IPV6_PKTINFO on Windows. | | IP_DONTFRAG | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | IP_DONTFRAGMENT on Windows, implementable using IP_MTU_DISCOVER on Linux. | | IPV6_DONTFRAG | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | | | IP_MTU_DISCOVER | ❔ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | | diff --git a/example-world.md b/example-world.md index 8c74520..f82ac76 100644 --- a/example-world.md +++ b/example-world.md @@ -325,8 +325,28 @@ mean "ready".

record datagram

Record Fields

Functions

@@ -432,12 +452,28 @@ If the TCP/UDP port is zero, the socket will be bound to a random free port.

This function attempts to receive up to max-results datagrams on the socket without blocking. The returned list may contain fewer elements than requested, but never more. If max-results is 0, this function returns successfully with an empty list.

+

If a platform does not support receiving a particular field, its value will be set to None in the returned datagram.

Typical errors

+

Implementors note:

+

The closest equivalent to this function is Linux' recvmmsg function while having the following options enabled:

+ +

Naming differences:

+

References

+

Implementors note

+

The closest equivalent to this function is Linux' sendmmsg with zero or more +ancillary messages for each not-None datagram field:

+ +

On Windows, when sending a traffic-class value, only the ECN bits (the lowest two) are allowed through.

References