mirror of
https://github.com/zerotier/ZeroTierOne.git
synced 2024-12-25 07:31:05 +00:00
Improved error reporting
This commit is contained in:
parent
0912d4be59
commit
da536cc311
@ -628,7 +628,10 @@ err_t NetconEthernetTap::nc_recved(void *arg, struct tcp_pcb *tpcb, struct pbuf
|
|||||||
void NetconEthernetTap::nc_err(void *arg, err_t err)
|
void NetconEthernetTap::nc_err(void *arg, err_t err)
|
||||||
{
|
{
|
||||||
Larg *l = (Larg*)arg;
|
Larg *l = (Larg*)arg;
|
||||||
fprintf(stderr, "larg = %x, nc_err() = %d\n", l, err);
|
//fprintf(stderr, "larg = %x, nc_err() = %d\n", l, err);
|
||||||
|
|
||||||
|
if(!l->conn)
|
||||||
|
fprintf(stderr, "nc_err(): Connection is NULL!\n");
|
||||||
|
|
||||||
if(l->conn) {
|
if(l->conn) {
|
||||||
switch(err)
|
switch(err)
|
||||||
@ -636,38 +639,48 @@ void NetconEthernetTap::nc_err(void *arg, err_t err)
|
|||||||
// FIXME: Check if connection is pending first?
|
// FIXME: Check if connection is pending first?
|
||||||
|
|
||||||
case ERR_MEM:
|
case ERR_MEM:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_MEM->ENOMEM\n");
|
||||||
l->tap->send_return_value(l->conn, -1, ENOMEM);
|
l->tap->send_return_value(l->conn, -1, ENOMEM);
|
||||||
break;
|
break;
|
||||||
case ERR_BUF:
|
case ERR_BUF:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_BUF->ENOBUFS\n");
|
||||||
l->tap->send_return_value(l->conn, -1, ENOBUFS);
|
l->tap->send_return_value(l->conn, -1, ENOBUFS);
|
||||||
break;
|
break;
|
||||||
case ERR_TIMEOUT:
|
case ERR_TIMEOUT:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_TIMEOUT->ETIMEDOUT\n");
|
||||||
l->tap->send_return_value(l->conn, -1, ETIMEDOUT);
|
l->tap->send_return_value(l->conn, -1, ETIMEDOUT);
|
||||||
break;
|
break;
|
||||||
case ERR_RTE:
|
case ERR_RTE:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_RTE->ENETUNREACH\n");
|
||||||
l->tap->send_return_value(l->conn, -1, ENETUNREACH);
|
l->tap->send_return_value(l->conn, -1, ENETUNREACH);
|
||||||
break;
|
break;
|
||||||
case ERR_INPROGRESS:
|
case ERR_INPROGRESS:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_INPROGRESS->EINPROGRESS\n");
|
||||||
l->tap->send_return_value(l->conn, -1, EINPROGRESS);
|
l->tap->send_return_value(l->conn, -1, EINPROGRESS);
|
||||||
break;
|
break;
|
||||||
case ERR_VAL:
|
case ERR_VAL:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_VAL->EINVAL\n");
|
||||||
l->tap->send_return_value(l->conn, -1, EINVAL);
|
l->tap->send_return_value(l->conn, -1, EINVAL);
|
||||||
break;
|
break;
|
||||||
case ERR_WOULDBLOCK:
|
case ERR_WOULDBLOCK:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_WOULDBLOCK->EWOULDBLOCK\n");
|
||||||
l->tap->send_return_value(l->conn, -1, EWOULDBLOCK);
|
l->tap->send_return_value(l->conn, -1, EWOULDBLOCK);
|
||||||
break;
|
break;
|
||||||
case ERR_USE:
|
case ERR_USE:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_USE->EADDRINUSE\n");
|
||||||
l->tap->send_return_value(l->conn, -1, EADDRINUSE);
|
l->tap->send_return_value(l->conn, -1, EADDRINUSE);
|
||||||
break;
|
break;
|
||||||
case ERR_ISCONN:
|
case ERR_ISCONN:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_ISCONN->EISCONN\n");
|
||||||
l->tap->send_return_value(l->conn, -1, EISCONN);
|
l->tap->send_return_value(l->conn, -1, EISCONN);
|
||||||
break;
|
break;
|
||||||
|
case ERR_ABRT:
|
||||||
|
fprintf(stderr, "nc_err(): ERR_ABRT->ETIMEDOUT\n"); // FIXME: Correct?
|
||||||
|
l->tap->send_return_value(l->conn, -1, ETIMEDOUT);
|
||||||
|
break;
|
||||||
|
|
||||||
// FIXME: Below are errors which don't have a standard errno correlate
|
// FIXME: Below are errors which don't have a standard errno correlate
|
||||||
|
|
||||||
case ERR_ABRT:
|
|
||||||
l->tap->send_return_value(l->conn, -1, -1);
|
|
||||||
break;
|
|
||||||
case ERR_RST:
|
case ERR_RST:
|
||||||
l->tap->send_return_value(l->conn, -1, -1);
|
l->tap->send_return_value(l->conn, -1, -1);
|
||||||
break;
|
break;
|
||||||
|
@ -514,6 +514,7 @@ void sock_domain_to_str(int domain)
|
|||||||
|
|
||||||
int socket(SOCKET_SIG)
|
int socket(SOCKET_SIG)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
#ifdef CHECKS
|
#ifdef CHECKS
|
||||||
/* Check that type makes sense */
|
/* Check that type makes sense */
|
||||||
int flags = socket_type & ~SOCK_TYPE_MASK;
|
int flags = socket_type & ~SOCK_TYPE_MASK;
|
||||||
@ -572,13 +573,16 @@ int socket(SOCKET_SIG)
|
|||||||
}
|
}
|
||||||
else { // Try to read retval+errno since we RXed a bad fd
|
else { // Try to read retval+errno since we RXed a bad fd
|
||||||
dwr("Error, service sent bad fd.\n");
|
dwr("Error, service sent bad fd.\n");
|
||||||
return get_retval();
|
err = get_retval();
|
||||||
|
pthread_mutex_unlock(&lock);
|
||||||
|
return err;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
dwr("Error while receiving new FD.\n");
|
dwr("Error while receiving new FD.\n");
|
||||||
|
err = get_retval();
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
return get_retval();
|
return err;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
@ -591,7 +595,7 @@ int socket(SOCKET_SIG)
|
|||||||
connect() intercept function */
|
connect() intercept function */
|
||||||
int connect(CONNECT_SIG)
|
int connect(CONNECT_SIG)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
/* FIXME: Check that address is in user space, return EFAULT ? */
|
/* FIXME: Check that address is in user space, return EFAULT ? */
|
||||||
|
|
||||||
#ifdef DUMMY
|
#ifdef DUMMY
|
||||||
@ -635,23 +639,9 @@ int connect(CONNECT_SIG)
|
|||||||
memcpy(&cmd[1], &rpc_st, sizeof(struct connect_st));
|
memcpy(&cmd[1], &rpc_st, sizeof(struct connect_st));
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
send_command(fdret_sock, cmd);
|
send_command(fdret_sock, cmd);
|
||||||
|
err = get_retval();
|
||||||
if(fdret_sock >= 0) {
|
|
||||||
int retval;
|
|
||||||
char mynewbuf[BUF_SZ];
|
|
||||||
memset(&mynewbuf, '\0', sizeof(mynewbuf));
|
|
||||||
int n_read = read(fdret_sock, &mynewbuf, sizeof(mynewbuf));
|
|
||||||
if(n_read > 0) {
|
|
||||||
memcpy(&retval, &mynewbuf[1], sizeof(int));
|
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
return retval;
|
return err;
|
||||||
}
|
|
||||||
else {
|
|
||||||
pthread_mutex_unlock(&lock);
|
|
||||||
dwr("unable to read connect: return value\n");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return -1;
|
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -696,6 +686,7 @@ int poll(POLL_SIG)
|
|||||||
bind() intercept function */
|
bind() intercept function */
|
||||||
int bind(BIND_SIG)
|
int bind(BIND_SIG)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
#ifdef DUMMY
|
#ifdef DUMMY
|
||||||
dwr("bind(%d)\n", sockfd);
|
dwr("bind(%d)\n", sockfd);
|
||||||
return realbind(sockfd, addr, addrlen);
|
return realbind(sockfd, addr, addrlen);
|
||||||
@ -735,9 +726,10 @@ int bind(BIND_SIG)
|
|||||||
memcpy(&cmd[1], &rpc_st, sizeof(struct bind_st));
|
memcpy(&cmd[1], &rpc_st, sizeof(struct bind_st));
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
send_command(fdret_sock, cmd);
|
send_command(fdret_sock, cmd);
|
||||||
|
err = get_retval();
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
errno = ERR_OK;
|
errno = ERR_OK;
|
||||||
return get_retval();
|
return err;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -842,6 +834,7 @@ int accept(ACCEPT_SIG)
|
|||||||
listen() intercept function */
|
listen() intercept function */
|
||||||
int listen(LISTEN_SIG)
|
int listen(LISTEN_SIG)
|
||||||
{
|
{
|
||||||
|
int err;
|
||||||
/* FIXME: Check that this socket supports listen(), return EOPNOTSUPP */
|
/* FIXME: Check that this socket supports listen(), return EOPNOTSUPP */
|
||||||
/* FIXME: Check that the provided fd is a socket, return ENOTSOCK */
|
/* FIXME: Check that the provided fd is a socket, return ENOTSOCK */
|
||||||
|
|
||||||
@ -865,8 +858,9 @@ int listen(LISTEN_SIG)
|
|||||||
memcpy(&cmd[1], &rpc_st, sizeof(struct listen_st));
|
memcpy(&cmd[1], &rpc_st, sizeof(struct listen_st));
|
||||||
pthread_mutex_lock(&lock);
|
pthread_mutex_lock(&lock);
|
||||||
send_command(fdret_sock, cmd);
|
send_command(fdret_sock, cmd);
|
||||||
|
err = get_retval();
|
||||||
pthread_mutex_unlock(&lock);
|
pthread_mutex_unlock(&lock);
|
||||||
errno = ERR_OK;
|
errno = ERR_OK;
|
||||||
return get_retval();
|
return err;
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
Binary file not shown.
Loading…
Reference in New Issue
Block a user