Skip to content

Commit

Permalink
patches/tinyemu: Avoid Out-Of-Band assumptions on WASI
Browse files Browse the repository at this point in the history
Instead of assuming OOB to be supported, just jump to connected-state after
a successful connect() and leave it at that.
  • Loading branch information
fredldotme committed Sep 19, 2023
1 parent b458e25 commit 1c3ddb9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
2 changes: 2 additions & 0 deletions patches/tinyemu/tinyemu/slirp/misc.c
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,10 @@ fork_exec(struct socket *so, const char *ex, int do_pty)
closesocket(s);
opt = 1;
setsockopt(so->s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
#ifndef WASI
opt = 1;
setsockopt(so->s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
#endif
}
fd_nonblock(so->s);

Expand Down
3 changes: 3 additions & 0 deletions patches/tinyemu/tinyemu/slirp/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -635,7 +635,10 @@ tcp_listen(Slirp *slirp, uint32_t haddr, u_int hport, uint32_t laddr,
#endif
return NULL;
}

#ifndef WASI
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
#endif

getsockname(s,(struct sockaddr *)&addr,&addrlen);
so->so_fport = addr.sin_port;
Expand Down
10 changes: 8 additions & 2 deletions patches/tinyemu/tinyemu/slirp/tcp_input.c
Original file line number Diff line number Diff line change
Expand Up @@ -578,7 +578,13 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso)
goto cont_input;
}

if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK)) {
#ifdef WASI
if((tcp_fconnect(so) == 0)) {
goto cont_conn;
}
#else
if((tcp_fconnect(so) == -1) && (errno != EINPROGRESS) && (errno != EWOULDBLOCK))
{
u_char code=ICMP_UNREACH_NET;
DEBUG_MISC((dfd," tcp fconnect errno = %d-%s\n",
errno,strerror(errno)));
Expand Down Expand Up @@ -612,7 +618,7 @@ tcp_input(struct mbuf *m, int iphlen, struct socket *inso)
tp->t_state = TCPS_SYN_RECEIVED;
}
return;

#endif
cont_conn:
/* m==NULL
* Check if the connect succeeded
Expand Down
11 changes: 10 additions & 1 deletion patches/tinyemu/tinyemu/slirp/tcp_subr.c
Original file line number Diff line number Diff line change
Expand Up @@ -332,8 +332,10 @@ int tcp_fconnect(struct socket *so)
fd_nonblock(s);
opt = 1;
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(opt ));
#ifndef WASI
opt = 1;
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(opt ));
#endif

addr.sin_family = AF_INET;
if ((so->so_faddr.s_addr & slirp->vnetwork_mask.s_addr) ==
Expand All @@ -355,11 +357,16 @@ int tcp_fconnect(struct socket *so)
/* We don't care what port we get */
ret = connect(s,(struct sockaddr *)&addr,sizeof (addr));

if (ret == 0) {
soisfconnected(so);
} else
{
/*
* If it's not in progress, it failed, so we just return 0,
* without clearing SS_NOFDREF
*/
soisfconnecting(so);
soisfconnecting(so);
}
}

return(ret);
Expand Down Expand Up @@ -420,8 +427,10 @@ tcp_connect(struct socket *inso)
fd_nonblock(s);
opt = 1;
setsockopt(s,SOL_SOCKET,SO_REUSEADDR,(char *)&opt,sizeof(int));
#ifndef WASI
opt = 1;
setsockopt(s,SOL_SOCKET,SO_OOBINLINE,(char *)&opt,sizeof(int));
#endif
opt = 1;
setsockopt(s,IPPROTO_TCP,TCP_NODELAY,(char *)&opt,sizeof(int));

Expand Down

0 comments on commit 1c3ddb9

Please sign in to comment.