Skip to content

Commit

Permalink
Remove the notion of socket addresses.
Browse files Browse the repository at this point in the history
With the development of Flower making progress, the data returned by
getsockname()/getpeername() is going to become increasingly less
interesting. Data may get tunneled through UNIX sockets along the way,
meaning that addressing information will get lost.

Having the kernel report addresses attached to sockets is in principle a
bad idea. It makes software hard to test. For example, there is no way
to inject fake IP address information as part of system tests. Let's
kick all of this stuff out of the specification and move it into
userspace.
  • Loading branch information
EdSchouten committed Jul 24, 2017
1 parent 9fda03c commit 251ae36
Show file tree
Hide file tree
Showing 14 changed files with 81 additions and 295 deletions.
50 changes: 7 additions & 43 deletions cloudabi.txt
Original file line number Diff line number Diff line change
Expand Up @@ -756,20 +756,6 @@ flags uint64 rights
0x0000010000000000 sock_stat_get
| The right to invoke [sock_stat_get].

enum uint8 sa_family
| Socket address family.
@cprefix AF_
0 unspec
| The socket address family is unknown or is different
| from any of the other address families specified.
1 inet
| An IPv4 address.
2 inet6
| An IPv6 address.
3 unix
| The socket is local to the system, and may be bound to
| the file system.

flags uint8 sdflags
| Which channels on a socket need to be shut down.
@cprefix SHUT_
Expand Down Expand Up @@ -1200,43 +1186,21 @@ struct send_out
size so_datalen
| Number of bytes transmitted.

struct sockaddr
| Network address of a bound socket or its peer.
sa_family sa_family
| Address family.
variant sa_family
inet
struct sa_inet
array 4 uint8 addr
| IPv4 address.
uint16 port
| IPv4 port number.
inet6
struct sa_inet6
array 16 uint8 addr
| IPv6 address.
uint16 port
| IPv6 port number.

struct recv_out
| Results of [sock_recv].
size ro_datalen
| Number of bytes stored in [recv_in.ri_data].
size ro_fdslen
| Number of file descriptors stored in [recv_in.ri_fds].
sockaddr ro_sockname
| Address on which the message was received.
sockaddr ro_peername
| Address of the peer sending the message.
array 40 char ro_unused
| Fields that were used by previous implementations.
roflags ro_flags
| Message flags.

struct sockstat
| Socket attributes.
sockaddr ss_sockname
| The address to which this socket is bound.
sockaddr ss_peername
| The address to which this socket is connected.
array 40 char ss_unused
| Fields that were used by previous implementations.
errno ss_error
| Error code of the last completed asynchronous
| operation performed on this socket.
Expand Down Expand Up @@ -2016,9 +1980,9 @@ syscall sock_accept
in
fd sock
| The file descriptor of the listening socket.
ptr sockstat buf
| The attributes of the socket associated with
| the incoming connection.
ptr void unused
| Previously used to return the peer address.
| Should be null.
out
fd conn
| The socket associated with the incoming
Expand Down
89 changes: 8 additions & 81 deletions docs/cloudabi.html
Original file line number Diff line number Diff line change
Expand Up @@ -1373,10 +1373,10 @@ <h4><a href="#sock_accept" name="sock_accept"></a><code>cloudabi_sys_sock_accept
<li><p><a href="#sock_accept.sock" name="sock_accept.sock"></a><code><a href="#fd">cloudabi_fd_t</a> <strong>sock</strong></code></p>

<p>The file descriptor of the listening socket.</p></li>
<li><p><a href="#sock_accept.buf" name="sock_accept.buf"></a><code><a href="#sockstat">cloudabi_sockstat_t</a> *<strong>buf</strong></code></p>
<li><p><a href="#sock_accept.unused" name="sock_accept.unused"></a><code>void *<strong>unused</strong></code></p>

<p>The attributes of the socket associated with
the incoming connection.</p></li>
<p>Previously used to return the peer address.
Should be null.</p></li>
</ul>

<p>Outputs:</p>
Expand Down Expand Up @@ -2714,12 +2714,9 @@ <h4><a href="#recv_out" name="recv_out"></a><code>cloudabi_recv_out_t</code> (<c
<li><p><a href="#recv_out.ro_fdslen" name="recv_out.ro_fdslen"></a><code>size_t <strong>ro_fdslen</strong></code></p>

<p>Number of file descriptors stored in <a href="#recv_in.ri_fds"><code>cloudabi_recv_in_t::ri_fds</code></a>.</p></li>
<li><p><a href="#recv_out.ro_sockname" name="recv_out.ro_sockname"></a><code><a href="#sockaddr">cloudabi_sockaddr_t</a> <strong>ro_sockname</strong></code></p>
<li><p><a href="#recv_out.ro_unused" name="recv_out.ro_unused"></a><code>char <strong>ro_unused</strong>[40]</code></p>

<p>Address on which the message was received.</p></li>
<li><p><a href="#recv_out.ro_peername" name="recv_out.ro_peername"></a><code><a href="#sockaddr">cloudabi_sockaddr_t</a> <strong>ro_peername</strong></code></p>

<p>Address of the peer sending the message.</p></li>
<p>Fields that were used by previous implementations.</p></li>
<li><p><a href="#recv_out.ro_flags" name="recv_out.ro_flags"></a><code><a href="#roflags">cloudabi_roflags_t</a> <strong>ro_flags</strong></code></p>

<p>Message flags.</p></li>
Expand Down Expand Up @@ -2953,31 +2950,6 @@ <h4><a href="#roflags" name="roflags"></a><code>cloudabi_roflags_t</code> (<code
truncated.</p></li>
</ul>

<h4><a href="#sa_family" name="sa_family"></a><code>cloudabi_sa_family_t</code> (<code>uint8_t</code>)</h4>

<p>Socket address family.</p>

<p>Used by <a href="#sockaddr"><code>cloudabi_sockaddr_t</code></a>.</p>

<p>Possible values:</p>

<ul>
<li><p><a href="#sa_family.unspec" name="sa_family.unspec"></a><strong><code>CLOUDABI_AF_UNSPEC</code></strong></p>

<p>The socket address family is unknown or is different
from any of the other address families specified.</p></li>
<li><p><a href="#sa_family.inet" name="sa_family.inet"></a><strong><code>CLOUDABI_AF_INET</code></strong></p>

<p>An IPv4 address.</p></li>
<li><p><a href="#sa_family.inet6" name="sa_family.inet6"></a><strong><code>CLOUDABI_AF_INET6</code></strong></p>

<p>An IPv6 address.</p></li>
<li><p><a href="#sa_family.unix" name="sa_family.unix"></a><strong><code>CLOUDABI_AF_UNIX</code></strong></p>

<p>The socket is local to the system, and may be bound to
the file system.</p></li>
</ul>

<h4><a href="#scope" name="scope"></a><code>cloudabi_scope_t</code> (<code>uint8_t</code>)</h4>

<p>Indicates whether an object is stored in private or shared
Expand Down Expand Up @@ -3193,63 +3165,18 @@ <h4><a href="#signal" name="signal"></a><code>cloudabi_signal_t</code> (<code>ui
<p>Action: Terminates the process.</p></li>
</ul>

<h4><a href="#sockaddr" name="sockaddr"></a><code>cloudabi_sockaddr_t</code> (<code>struct</code>)</h4>

<p>Network address of a bound socket or its peer.</p>

<p>Used by <a href="#recv_out"><code>cloudabi_recv_out_t</code></a> and <a href="#sockstat"><code>cloudabi_sockstat_t</code></a>.</p>

<p>Members:</p>

<ul>
<li><p><a href="#sockaddr.sa_family" name="sockaddr.sa_family"></a><code><a href="#sa_family">cloudabi_sa_family_t</a> <strong>sa_family</strong></code></p>

<p>Address family.</p></li>
<li><p>When <code>sa_family</code> is <a href="#sa_family.inet"><code>CLOUDABI_AF_INET</code></a>:</p>

<ul>
<li><p><a href="#sockaddr.sa_inet" name="sockaddr.sa_inet"></a><strong><code>sa_inet</code></strong></p>

<ul>
<li><p><a href="#sockaddr.sa_inet.addr" name="sockaddr.sa_inet.addr"></a><code>uint8_t <strong>addr</strong>[4]</code></p>

<p>IPv4 address.</p></li>
<li><p><a href="#sockaddr.sa_inet.port" name="sockaddr.sa_inet.port"></a><code>uint16_t <strong>port</strong></code></p>

<p>IPv4 port number.</p></li>
</ul></li>
</ul></li>
<li><p>When <code>sa_family</code> is <a href="#sa_family.inet6"><code>CLOUDABI_AF_INET6</code></a>:</p>

<ul>
<li><p><a href="#sockaddr.sa_inet6" name="sockaddr.sa_inet6"></a><strong><code>sa_inet6</code></strong></p>

<ul>
<li><p><a href="#sockaddr.sa_inet6.addr" name="sockaddr.sa_inet6.addr"></a><code>uint8_t <strong>addr</strong>[16]</code></p>

<p>IPv6 address.</p></li>
<li><p><a href="#sockaddr.sa_inet6.port" name="sockaddr.sa_inet6.port"></a><code>uint16_t <strong>port</strong></code></p>

<p>IPv6 port number.</p></li>
</ul></li>
</ul></li>
</ul>

<h4><a href="#sockstat" name="sockstat"></a><code>cloudabi_sockstat_t</code> (<code>struct</code>)</h4>

<p>Socket attributes.</p>

<p>Used by <a href="#sock_accept"><code>cloudabi_sys_sock_accept()</code></a> and <a href="#sock_stat_get"><code>cloudabi_sys_sock_stat_get()</code></a>.</p>
<p>Used by <a href="#sock_stat_get"><code>cloudabi_sys_sock_stat_get()</code></a>.</p>

<p>Members:</p>

<ul>
<li><p><a href="#sockstat.ss_sockname" name="sockstat.ss_sockname"></a><code><a href="#sockaddr">cloudabi_sockaddr_t</a> <strong>ss_sockname</strong></code></p>

<p>The address to which this socket is bound.</p></li>
<li><p><a href="#sockstat.ss_peername" name="sockstat.ss_peername"></a><code><a href="#sockaddr">cloudabi_sockaddr_t</a> <strong>ss_peername</strong></code></p>
<li><p><a href="#sockstat.ss_unused" name="sockstat.ss_unused"></a><code>char <strong>ss_unused</strong>[40]</code></p>

<p>The address to which this socket is connected.</p></li>
<p>Fields that were used by previous implementations.</p></li>
<li><p><a href="#sockstat.ss_error" name="sockstat.ss_error"></a><code><a href="#errno">cloudabi_errno_t</a> <strong>ss_error</strong></code></p>

<p>Error code of the last completed asynchronous
Expand Down
86 changes: 8 additions & 78 deletions docs/cloudabi.md
Original file line number Diff line number Diff line change
Expand Up @@ -1203,10 +1203,10 @@ Inputs:

The file descriptor of the listening socket.

- <a href="#sock_accept.buf" name="sock_accept.buf"></a><code>[cloudabi\_sockstat\_t](#sockstat) *<strong>buf</strong></code>
- <a href="#sock_accept.unused" name="sock_accept.unused"></a><code>void *<strong>unused</strong></code>

The attributes of the socket associated with
the incoming connection.
Previously used to return the peer address.
Should be null.

Outputs:

Expand Down Expand Up @@ -2616,13 +2616,9 @@ Members:

Number of file descriptors stored in [`cloudabi_recv_in_t::ri_fds`](#recv_in.ri_fds).

- <a href="#recv_out.ro_sockname" name="recv_out.ro_sockname"></a><code>[cloudabi\_sockaddr\_t](#sockaddr) <strong>ro\_sockname</strong></code>
- <a href="#recv_out.ro_unused" name="recv_out.ro_unused"></a><code>char <strong>ro\_unused</strong>[40]</code>

Address on which the message was received.

- <a href="#recv_out.ro_peername" name="recv_out.ro_peername"></a><code>[cloudabi\_sockaddr\_t](#sockaddr) <strong>ro\_peername</strong></code>

Address of the peer sending the message.
Fields that were used by previous implementations.

- <a href="#recv_out.ro_flags" name="recv_out.ro_flags"></a><code>[cloudabi\_roflags\_t](#roflags) <strong>ro\_flags</strong></code>

Expand Down Expand Up @@ -2892,32 +2888,6 @@ Possible values:
Returned by [`cloudabi_sys_sock_recv()`](#sock_recv): Message data has been
truncated.

#### <a href="#sa_family" name="sa_family"></a>`cloudabi_sa_family_t` (`uint8_t`)

Socket address family.

Used by [`cloudabi_sockaddr_t`](#sockaddr).

Possible values:

- <a href="#sa_family.unspec" name="sa_family.unspec"></a>**`CLOUDABI_AF_UNSPEC`**

The socket address family is unknown or is different
from any of the other address families specified.

- <a href="#sa_family.inet" name="sa_family.inet"></a>**`CLOUDABI_AF_INET`**

An IPv4 address.

- <a href="#sa_family.inet6" name="sa_family.inet6"></a>**`CLOUDABI_AF_INET6`**

An IPv6 address.

- <a href="#sa_family.unix" name="sa_family.unix"></a>**`CLOUDABI_AF_UNIX`**

The socket is local to the system, and may be bound to
the file system.

#### <a href="#scope" name="scope"></a>`cloudabi_scope_t` (`uint8_t`)

Indicates whether an object is stored in private or shared
Expand Down Expand Up @@ -3152,57 +3122,17 @@ Possible values:

Action: Terminates the process.

#### <a href="#sockaddr" name="sockaddr"></a>`cloudabi_sockaddr_t` (`struct`)

Network address of a bound socket or its peer.

Used by [`cloudabi_recv_out_t`](#recv_out) and [`cloudabi_sockstat_t`](#sockstat).

Members:

- <a href="#sockaddr.sa_family" name="sockaddr.sa_family"></a><code>[cloudabi\_sa\_family\_t](#sa_family) <strong>sa\_family</strong></code>

Address family.

- When `sa_family` is [`CLOUDABI_AF_INET`](#sa_family.inet):

- <a href="#sockaddr.sa_inet" name="sockaddr.sa_inet"></a>**`sa_inet`**

- <a href="#sockaddr.sa_inet.addr" name="sockaddr.sa_inet.addr"></a><code>uint8\_t <strong>addr</strong>[4]</code>

IPv4 address.

- <a href="#sockaddr.sa_inet.port" name="sockaddr.sa_inet.port"></a><code>uint16\_t <strong>port</strong></code>

IPv4 port number.

- When `sa_family` is [`CLOUDABI_AF_INET6`](#sa_family.inet6):

- <a href="#sockaddr.sa_inet6" name="sockaddr.sa_inet6"></a>**`sa_inet6`**

- <a href="#sockaddr.sa_inet6.addr" name="sockaddr.sa_inet6.addr"></a><code>uint8\_t <strong>addr</strong>[16]</code>

IPv6 address.

- <a href="#sockaddr.sa_inet6.port" name="sockaddr.sa_inet6.port"></a><code>uint16\_t <strong>port</strong></code>

IPv6 port number.

#### <a href="#sockstat" name="sockstat"></a>`cloudabi_sockstat_t` (`struct`)

Socket attributes.

Used by [`cloudabi_sys_sock_accept()`](#sock_accept) and [`cloudabi_sys_sock_stat_get()`](#sock_stat_get).
Used by [`cloudabi_sys_sock_stat_get()`](#sock_stat_get).

Members:

- <a href="#sockstat.ss_sockname" name="sockstat.ss_sockname"></a><code>[cloudabi\_sockaddr\_t](#sockaddr) <strong>ss\_sockname</strong></code>

The address to which this socket is bound.

- <a href="#sockstat.ss_peername" name="sockstat.ss_peername"></a><code>[cloudabi\_sockaddr\_t](#sockaddr) <strong>ss\_peername</strong></code>
- <a href="#sockstat.ss_unused" name="sockstat.ss_unused"></a><code>char <strong>ss\_unused</strong>[40]</code>

The address to which this socket is connected.
Fields that were used by previous implementations.

- <a href="#sockstat.ss_error" name="sockstat.ss_error"></a><code>[cloudabi\_errno\_t](#errno) <strong>ss\_error</strong></code>

Expand Down
2 changes: 1 addition & 1 deletion freebsd/syscalls32.master
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@

44 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_sock_accept( \
cloudabi_fd_t sock, \
cloudabi_sockstat_t *buf); }
void *unused); }

45 AUE_NULL STD { void cloudabi_sys_sock_bind( \
cloudabi_fd_t sock, \
Expand Down
2 changes: 1 addition & 1 deletion freebsd/syscalls64.master
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@

44 AUE_NULL STD { cloudabi_fd_t cloudabi_sys_sock_accept( \
cloudabi_fd_t sock, \
cloudabi_sockstat_t *buf); }
void *unused); }

45 AUE_NULL STD { void cloudabi_sys_sock_bind( \
cloudabi_fd_t sock, \
Expand Down
28 changes: 13 additions & 15 deletions headers/cloudabi32_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,19 @@ _Static_assert(offsetof(cloudabi32_recv_in_t, ri_flags) == 16, "Incorrect layout
_Static_assert(sizeof(cloudabi32_recv_in_t) == 20, "Incorrect layout");
_Static_assert(_Alignof(cloudabi32_recv_in_t) == 4, "Incorrect layout");

typedef struct {
_Alignas(4) uint32_t ro_datalen;
_Alignas(4) uint32_t ro_fdslen;
_Alignas(1) char ro_unused[40];
_Alignas(2) cloudabi_roflags_t ro_flags;
} cloudabi32_recv_out_t;
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_datalen) == 0, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_fdslen) == 4, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_unused) == 8, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_flags) == 48, "Incorrect layout");
_Static_assert(sizeof(cloudabi32_recv_out_t) == 52, "Incorrect layout");
_Static_assert(_Alignof(cloudabi32_recv_out_t) == 4, "Incorrect layout");

typedef struct {
_Alignas(4) uint32_t si_data;
_Alignas(4) uint32_t si_data_len;
Expand Down Expand Up @@ -201,21 +214,6 @@ _Static_assert(_Alignof(cloudabi32_tcb_t) == 4, "Incorrect layout");

typedef void cloudabi32_threadentry_t(cloudabi_tid_t tid, uint32_t aux);

typedef struct {
_Alignas(4) uint32_t ro_datalen;
_Alignas(4) uint32_t ro_fdslen;
_Alignas(2) cloudabi_sockaddr_t ro_sockname;
_Alignas(2) cloudabi_sockaddr_t ro_peername;
_Alignas(2) cloudabi_roflags_t ro_flags;
} cloudabi32_recv_out_t;
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_datalen) == 0, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_fdslen) == 4, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_sockname) == 8, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_peername) == 28, "Incorrect layout");
_Static_assert(offsetof(cloudabi32_recv_out_t, ro_flags) == 48, "Incorrect layout");
_Static_assert(sizeof(cloudabi32_recv_out_t) == 52, "Incorrect layout");
_Static_assert(_Alignof(cloudabi32_recv_out_t) == 4, "Incorrect layout");

typedef struct {
_Alignas(4) uint32_t entry_point;
_Alignas(4) uint32_t stack;
Expand Down
Loading

0 comments on commit 251ae36

Please sign in to comment.