Skip to content

Commit a14bdde

Browse files
committed
Add IP_TOS, IPV6_TCLASS, IP_DONTFRAG & IPV6_DONTFRAG socket options
1 parent 846f8f8 commit a14bdde

File tree

4 files changed

+128
-6
lines changed

4 files changed

+128
-6
lines changed

Posix-compatibility.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -159,16 +159,16 @@ Columns:
159159
| IPV6_UNICAST_HOPS ||||||||||||||||| [`tcp::(set-)hop-limit`](tcp)<br/>[`udp::(set-)unicast-hop-limit`](udp) |
160160
| IP_RECVTTL ||||||||||||||||| |
161161
| IPV6_RECVHOPLIMIT ||||||||||||||||| |
162-
| IP_TOS | ||| ||||||||||||| |
163-
| IPV6_TCLASS | |||||||||||||||| |
162+
| IP_TOS | ||| ||||||||||||| [`tcp::(set-)traffic-class`](tcp)<br/>[`udp::(set-)traffic-class`](udp) |
163+
| IPV6_TCLASS | |||||||||||||||| [`tcp::(set-)traffic-class`](tcp)<br/>[`udp::(set-)traffic-class`](udp) |
164164
| IP_RECVTOS ||||||||||||||||| |
165165
| IPV6_RECVTCLASS ||||||||||||||||| |
166166
| IP_RECVPKTINFO ||||||||||||||||| IP_PKTINFO on Linux & Windows, IP_RECVDSTADDR+IP_RECVIF on MacOS & FreeBSD. |
167167
| IPV6_RECVPKTINFO ||||||||||||||||| IPV6_PKTINFO on Windows. |
168-
| IP_DONTFRAG | |||||||||||||||| IP_DONTFRAGMENT on Windows, implementable using IP_MTU_DISCOVER on Linux. |
169-
| IPV6_DONTFRAG | |||||||||||||||| |
170-
| IP_MTU_DISCOVER | |||||||||||||||| |
171-
| IPV6_MTU_DISCOVER | |||||||||||||||| |
168+
| IP_DONTFRAG | |||||||||||||||| [`udp::(set-)dont-fragment`](udp) <br/><br/> IP_DONTFRAGMENT on Windows, implementable using IP_MTU_DISCOVER on Linux. |
169+
| IPV6_DONTFRAG | |||||||||||||||| [`udp::(set-)dont-fragment`](udp) |
170+
| IP_MTU_DISCOVER |* |||||||||||||||| Only the IP_PMTUDISC_DO behaviour is supported as part of IP_DONTFRAG. |
171+
| IPV6_MTU_DISCOVER |* |||||||||||||||| Only the IP_PMTUDISC_DO behaviour is supported as part of IPV6_DONTFRAG. |
172172
| SO_RCVBUF ||||||||||||||||| [`tcp::(set-)receive-buffer-size`](tcp)<br/>[`udp::(set-)receive-buffer-size`](udp) |
173173
| SO_SNDBUF ||||||||||||||||| [`tcp::(set-)send-buffer-size`](tcp)<br/>[`udp::(set-)send-buffer-size`](udp) |
174174
| SO_RCVLOWAT ||||||||||||||||| |

example-world.md

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,6 +604,62 @@ call <a href="#remote_address"><code>remote-address</code></a> to get their addr
604604
<ul>
605605
<li><a name="set_unicast_hop_limit.0"></a> result&lt;_, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
606606
</ul>
607+
<h4><a name="traffic_class"><code>traffic-class: func</code></a></h4>
608+
<p>Equivalent to the IP_TOS &amp; IPV6_TCLASS socket options.</p>
609+
<p>The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits).</p>
610+
<h1>Implementors note</h1>
611+
<p>Windows does not support this.</p>
612+
<h1>Typical errors</h1>
613+
<ul>
614+
<li><code>concurrency-conflict</code>: (set) A <code>bind</code>, <code>connect</code> or <code>listen</code> operation is already in progress. (EALREADY)</li>
615+
</ul>
616+
<h5>Params</h5>
617+
<ul>
618+
<li><a name="traffic_class.this"><code>this</code></a>: <a href="#udp_socket"><a href="#udp_socket"><code>udp-socket</code></a></a></li>
619+
</ul>
620+
<h5>Return values</h5>
621+
<ul>
622+
<li><a name="traffic_class.0"></a> result&lt;<code>u8</code>, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
623+
</ul>
624+
<h4><a name="set_traffic_class"><code>set-traffic-class: func</code></a></h4>
625+
<h5>Params</h5>
626+
<ul>
627+
<li><a name="set_traffic_class.this"><code>this</code></a>: <a href="#udp_socket"><a href="#udp_socket"><code>udp-socket</code></a></a></li>
628+
<li><a name="set_traffic_class.value"><code>value</code></a>: <code>u8</code></li>
629+
</ul>
630+
<h5>Return values</h5>
631+
<ul>
632+
<li><a name="set_traffic_class.0"></a> result&lt;_, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
633+
</ul>
634+
<h4><a name="dont_fragment"><code>dont-fragment: func</code></a></h4>
635+
<p>Equivalent to the IP_DONTFRAG &amp; IPV6_DONTFRAG socket options.</p>
636+
<h1>Implementors note</h1>
637+
<ul>
638+
<li>IP_DONTFRAGMENT on Windows</li>
639+
<li>Linux has no direct equivalent, but the same effect can be reached by setting IP_MTU_DISCOVER to IP_PMTUDISC_DO.</li>
640+
</ul>
641+
<h1>Typical errors</h1>
642+
<ul>
643+
<li><code>concurrency-conflict</code>: (set) A <code>bind</code>, <code>connect</code> or <code>listen</code> operation is already in progress. (EALREADY)</li>
644+
</ul>
645+
<h5>Params</h5>
646+
<ul>
647+
<li><a name="dont_fragment.this"><code>this</code></a>: <a href="#udp_socket"><a href="#udp_socket"><code>udp-socket</code></a></a></li>
648+
</ul>
649+
<h5>Return values</h5>
650+
<ul>
651+
<li><a name="dont_fragment.0"></a> result&lt;<code>bool</code>, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
652+
</ul>
653+
<h4><a name="set_dont_fragment"><code>set-dont-fragment: func</code></a></h4>
654+
<h5>Params</h5>
655+
<ul>
656+
<li><a name="set_dont_fragment.this"><code>this</code></a>: <a href="#udp_socket"><a href="#udp_socket"><code>udp-socket</code></a></a></li>
657+
<li><a name="set_dont_fragment.value"><code>value</code></a>: <code>bool</code></li>
658+
</ul>
659+
<h5>Return values</h5>
660+
<ul>
661+
<li><a name="set_dont_fragment.0"></a> result&lt;_, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
662+
</ul>
607663
<h4><a name="receive_buffer_size"><code>receive-buffer-size: func</code></a></h4>
608664
<p>The kernel buffer space reserved for sends/receives on this socket.</p>
609665
<p>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 &amp; write to the connection.</p>
13571413
<ul>
13581414
<li><a name="set_hop_limit.0"></a> result&lt;_, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
13591415
</ul>
1416+
<h4><a name="traffic_class"><code>traffic-class: func</code></a></h4>
1417+
<p>Equivalent to the IP_TOS &amp; IPV6_TCLASS socket options.</p>
1418+
<p>The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits).</p>
1419+
<h1>Implementors note</h1>
1420+
<p>Windows does not support this.</p>
1421+
<h1>Typical errors</h1>
1422+
<ul>
1423+
<li><code>already-connected</code>: (set) The socket is already in the Connection state.</li>
1424+
<li><code>already-listening</code>: (set) The socket is already in the Listener state.</li>
1425+
<li><code>concurrency-conflict</code>: (set) A <code>bind</code>, <code>connect</code> or <code>listen</code> operation is already in progress. (EALREADY)</li>
1426+
</ul>
1427+
<h5>Params</h5>
1428+
<ul>
1429+
<li><a name="traffic_class.this"><code>this</code></a>: <a href="#tcp_socket"><a href="#tcp_socket"><code>tcp-socket</code></a></a></li>
1430+
</ul>
1431+
<h5>Return values</h5>
1432+
<ul>
1433+
<li><a name="traffic_class.0"></a> result&lt;<code>u8</code>, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
1434+
</ul>
1435+
<h4><a name="set_traffic_class"><code>set-traffic-class: func</code></a></h4>
1436+
<h5>Params</h5>
1437+
<ul>
1438+
<li><a name="set_traffic_class.this"><code>this</code></a>: <a href="#tcp_socket"><a href="#tcp_socket"><code>tcp-socket</code></a></a></li>
1439+
<li><a name="set_traffic_class.value"><code>value</code></a>: <code>u8</code></li>
1440+
</ul>
1441+
<h5>Return values</h5>
1442+
<ul>
1443+
<li><a name="set_traffic_class.0"></a> result&lt;_, <a href="#error_code"><a href="#error_code"><code>error-code</code></a></a>&gt;</li>
1444+
</ul>
13601445
<h4><a name="receive_buffer_size"><code>receive-buffer-size: func</code></a></h4>
13611446
<p>The kernel buffer space reserved for sends/receives on this socket.</p>
13621447
<p>Note #1: an implementation may choose to cap or round the buffer size when setting the value.

wit/tcp.wit

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -201,6 +201,20 @@ interface tcp {
201201
hop-limit: func(this: tcp-socket) -> result<u8, error-code>
202202
set-hop-limit: func(this: tcp-socket, value: u8) -> result<_, error-code>
203203

204+
/// Equivalent to the IP_TOS & IPV6_TCLASS socket options.
205+
///
206+
/// The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits).
207+
///
208+
/// # Implementors note
209+
/// Windows does not support this.
210+
///
211+
/// # Typical errors
212+
/// - `already-connected`: (set) The socket is already in the Connection state.
213+
/// - `already-listening`: (set) The socket is already in the Listener state.
214+
/// - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
215+
traffic-class: func(this: tcp-socket) -> result<u8, error-code>
216+
set-traffic-class: func(this: tcp-socket, value: u8) -> result<_, error-code>
217+
204218
/// The kernel buffer space reserved for sends/receives on this socket.
205219
///
206220
/// Note #1: an implementation may choose to cap or round the buffer size when setting the value.

wit/udp.wit

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,29 @@ interface udp {
189189
unicast-hop-limit: func(this: udp-socket) -> result<u8, error-code>
190190
set-unicast-hop-limit: func(this: udp-socket, value: u8) -> result<_, error-code>
191191

192+
/// Equivalent to the IP_TOS & IPV6_TCLASS socket options.
193+
///
194+
/// The value is typically composed of the DSCP (6 high bits) + ECN (2 low bits).
195+
///
196+
/// # Implementors note
197+
/// Windows does not support this.
198+
///
199+
/// # Typical errors
200+
/// - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
201+
traffic-class: func(this: udp-socket) -> result<u8, error-code>
202+
set-traffic-class: func(this: udp-socket, value: u8) -> result<_, error-code>
203+
204+
/// Equivalent to the IP_DONTFRAG & IPV6_DONTFRAG socket options.
205+
///
206+
/// # Implementors note
207+
/// - IP_DONTFRAGMENT on Windows
208+
/// - Linux has no direct equivalent, but the same effect can be reached by setting IP_MTU_DISCOVER to IP_PMTUDISC_DO.
209+
///
210+
/// # Typical errors
211+
/// - `concurrency-conflict`: (set) A `bind`, `connect` or `listen` operation is already in progress. (EALREADY)
212+
dont-fragment: func(this: udp-socket) -> result<bool, error-code>
213+
set-dont-fragment: func(this: udp-socket, value: bool) -> result<_, error-code>
214+
192215
/// The kernel buffer space reserved for sends/receives on this socket.
193216
///
194217
/// Note #1: an implementation may choose to cap or round the buffer size when setting the value.

0 commit comments

Comments
 (0)