From a14bddee289c3206d11800b36b1567ed1a18e7ff Mon Sep 17 00:00:00 2001 From: Dave Bakker Date: Sun, 10 Sep 2023 13:35:23 +0200 Subject: [PATCH] Add IP_TOS, IPV6_TCLASS, IP_DONTFRAG & IPV6_DONTFRAG socket options --- Posix-compatibility.md | 12 +++--- example-world.md | 85 ++++++++++++++++++++++++++++++++++++++++++ wit/tcp.wit | 14 +++++++ wit/udp.wit | 23 ++++++++++++ 4 files changed, 128 insertions(+), 6 deletions(-) diff --git a/Posix-compatibility.md b/Posix-compatibility.md index 350fbea..f66fd8e 100644 --- a/Posix-compatibility.md +++ b/Posix-compatibility.md @@ -159,16 +159,16 @@ Columns: | IPV6_UNICAST_HOPS | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | [`tcp::(set-)hop-limit`](tcp)
[`udp::(set-)unicast-hop-limit`](udp) | | IP_RECVTTL | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | | IPV6_RECVHOPLIMIT | ❔ | ❌ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | -| IP_TOS | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | | -| IPV6_TCLASS | ❔ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | | +| IP_TOS | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | [`tcp::(set-)traffic-class`](tcp)
[`udp::(set-)traffic-class`](udp) | +| IPV6_TCLASS | ✅ | ❌ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | [`tcp::(set-)traffic-class`](tcp)
[`udp::(set-)traffic-class`](udp) | | 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_DONTFRAG | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | IP_DONTFRAGMENT on Windows, implementable using IP_MTU_DISCOVER on Linux. | -| IPV6_DONTFRAG | ❔ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | | -| IP_MTU_DISCOVER | ❔ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | | -| IPV6_MTU_DISCOVER | ❔ | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | | +| IP_DONTFRAG | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | [`udp::(set-)dont-fragment`](udp)

IP_DONTFRAGMENT on Windows, implementable using IP_MTU_DISCOVER on Linux. | +| IPV6_DONTFRAG | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ❌ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | [`udp::(set-)dont-fragment`](udp) | +| IP_MTU_DISCOVER | ❔* | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | Only the IP_PMTUDISC_DO behaviour is supported as part of IP_DONTFRAG. | +| IPV6_MTU_DISCOVER | ❔* | ❌ | ✅ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | Only the IP_PMTUDISC_DO behaviour is supported as part of IPV6_DONTFRAG. | | SO_RCVBUF | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ✅ | ❌ | [`tcp::(set-)receive-buffer-size`](tcp)
[`udp::(set-)receive-buffer-size`](udp) | | SO_SNDBUF | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ❌ | [`tcp::(set-)send-buffer-size`](tcp)
[`udp::(set-)send-buffer-size`](udp) | | SO_RCVLOWAT | ❔ | ✅ | ✅ | ❌ | ✅ | ✅ | ❌ | ✅ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | ❌ | | diff --git a/example-world.md b/example-world.md index be07656..c0a8e5f 100644 --- a/example-world.md +++ b/example-world.md @@ -604,6 +604,62 @@ call remote-address to get their addr +

traffic-class: func

+

Equivalent to the IP_TOS & IPV6_TCLASS socket options.

+

The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits).

+

Implementors note

+

Windows does not support this.

+

Typical errors

+ +
Params
+ +
Return values
+ +

set-traffic-class: func

+
Params
+ +
Return values
+ +

dont-fragment: func

+

Equivalent to the IP_DONTFRAG & IPV6_DONTFRAG socket options.

+

Implementors note

+ +

Typical errors

+ +
Params
+ +
Return values
+ +

set-dont-fragment: func

+
Params
+ +
Return values
+

receive-buffer-size: func

The kernel buffer space reserved for sends/receives on this socket.

Note #1: an implementation may choose to cap or round the buffer size when setting the value. @@ -1357,6 +1413,35 @@ a pair of streams that can be used to read & write to the connection.

+

traffic-class: func

+

Equivalent to the IP_TOS & IPV6_TCLASS socket options.

+

The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits).

+

Implementors note

+

Windows does not support this.

+

Typical errors

+ +
Params
+ +
Return values
+ +

set-traffic-class: func

+
Params
+ +
Return values
+

receive-buffer-size: func

The kernel buffer space reserved for sends/receives on this socket.

Note #1: an implementation may choose to cap or round the buffer size when setting the value. diff --git a/wit/tcp.wit b/wit/tcp.wit index 9ccf50f..1796663 100644 --- a/wit/tcp.wit +++ b/wit/tcp.wit @@ -201,6 +201,20 @@ interface tcp { hop-limit: func(this: tcp-socket) -> result set-hop-limit: func(this: tcp-socket, value: u8) -> result<_, error-code> + /// Equivalent to the IP_TOS & IPV6_TCLASS socket options. + /// + /// The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits). + /// + /// # Implementors note + /// Windows does not support this. + /// + /// # Typical errors + /// - `already-connected`: (set) The socket is already in the Connection state. + /// - `already-listening`: (set) The socket is already in the Listener state. + /// - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY) + traffic-class: func(this: tcp-socket) -> result + set-traffic-class: func(this: tcp-socket, value: u8) -> result<_, error-code> + /// The kernel buffer space reserved for sends/receives on this socket. /// /// Note #1: an implementation may choose to cap or round the buffer size when setting the value. diff --git a/wit/udp.wit b/wit/udp.wit index 700b9e2..aa8067b 100644 --- a/wit/udp.wit +++ b/wit/udp.wit @@ -189,6 +189,29 @@ interface udp { unicast-hop-limit: func(this: udp-socket) -> result set-unicast-hop-limit: func(this: udp-socket, value: u8) -> result<_, error-code> + /// Equivalent to the IP_TOS & IPV6_TCLASS socket options. + /// + /// The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits). + /// + /// # Implementors note + /// Windows does not support this. + /// + /// # Typical errors + /// - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY) + traffic-class: func(this: udp-socket) -> result + set-traffic-class: func(this: udp-socket, value: u8) -> result<_, error-code> + + /// Equivalent to the IP_DONTFRAG & IPV6_DONTFRAG socket options. + /// + /// # Implementors note + /// - IP_DONTFRAGMENT on Windows + /// - Linux has no direct equivalent, but the same effect can be reached by setting IP_MTU_DISCOVER to IP_PMTUDISC_DO. + /// + /// # Typical errors + /// - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY) + dont-fragment: func(this: udp-socket) -> result + set-dont-fragment: func(this: udp-socket, value: bool) -> result<_, error-code> + /// The kernel buffer space reserved for sends/receives on this socket. /// /// Note #1: an implementation may choose to cap or round the buffer size when setting the value.