Skip to content

Commit

Permalink
[Pal/Linux] Memorize the assigned ephemeral port during udp_bind()
Browse files Browse the repository at this point in the history
In Linux, if a port number (in the input UDP socket address) during
`bind()` is specified as 0, an ephemeral (random) port is assigned.
Previously, Linux PAL forgot to update the port in the UDP socket
address, so `getsockname()` always returned 0 instead of the actual
port. This commit fixes this bug.

Signed-off-by: Sonali Saha <sonali.saha@intel.com>
  • Loading branch information
sahason authored and dimakuv committed Sep 29, 2021
1 parent 5c505d4 commit 090db13
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
2 changes: 1 addition & 1 deletion LibOS/shim/test/ltp/ltp.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -1901,7 +1901,7 @@ timeout = 60
[sendfile09_64]
timeout = 60

# EINVAL from native sendmsg()
# uses recvmmsg(timeout) but timeout is unsupported in Gramine
[sendmmsg01]
skip = yes

Expand Down
7 changes: 7 additions & 0 deletions Pal/src/host/Linux/db_sockets.c
Original file line number Diff line number Diff line change
Expand Up @@ -609,6 +609,13 @@ static int udp_bind(PAL_HANDLE* handle, char* uri, int create, int options) {
}
}

/* call getsockname to get socket address */
ret = DO_SYSCALL(getsockname, fd, bind_addr, &bind_addrlen);
if (ret < 0) {
ret = unix_to_pal_error(ret);
goto failed;
}

*handle = socket_create_handle(PAL_TYPE_UDPSRV, fd, options, bind_addr, bind_addrlen, NULL, 0);

if (!(*handle)) {
Expand Down

0 comments on commit 090db13

Please sign in to comment.