mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2024-07-02 19:08:57 +00:00
fixed bug #43110 (call getpeername() before listen() will cause a error) by re-sorting the error numbers and letting listen() continue on ERR_CONN
This commit is contained in:
parent
4335e99f2e
commit
3c40d93f36
|
@ -117,6 +117,10 @@ HISTORY
|
||||||
|
|
||||||
++ Bugfixes:
|
++ Bugfixes:
|
||||||
|
|
||||||
|
2014-09-02: Simon Goldschmidt
|
||||||
|
* err.h/.c, sockets.c, api_msg.c: fixed bug #43110 call getpeername() before
|
||||||
|
listen() will cause a error
|
||||||
|
|
||||||
2014-09-02: Simon Goldschmidt
|
2014-09-02: Simon Goldschmidt
|
||||||
* sockets.c: fixed bug #42117 lwip_fcntl does not set errno
|
* sockets.c: fixed bug #42117 lwip_fcntl does not set errno
|
||||||
|
|
||||||
|
|
|
@ -1074,7 +1074,7 @@ lwip_netconn_do_disconnect(struct api_msg_msg *msg)
|
||||||
void
|
void
|
||||||
lwip_netconn_do_listen(struct api_msg_msg *msg)
|
lwip_netconn_do_listen(struct api_msg_msg *msg)
|
||||||
{
|
{
|
||||||
if (ERR_IS_FATAL(msg->conn->last_err)) {
|
if (ERR_IS_FATAL_LISTENCONNECT(msg->conn->last_err)) {
|
||||||
msg->err = msg->conn->last_err;
|
msg->err = msg->conn->last_err;
|
||||||
} else {
|
} else {
|
||||||
msg->err = ERR_CONN;
|
msg->err = ERR_CONN;
|
||||||
|
@ -1082,45 +1082,50 @@ lwip_netconn_do_listen(struct api_msg_msg *msg)
|
||||||
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP) {
|
if (NETCONNTYPE_GROUP(msg->conn->type) == NETCONN_TCP) {
|
||||||
if (msg->conn->state == NETCONN_NONE) {
|
if (msg->conn->state == NETCONN_NONE) {
|
||||||
struct tcp_pcb* lpcb;
|
struct tcp_pcb* lpcb;
|
||||||
#if LWIP_IPV6
|
if (msg->conn->pcb.tcp->state != CLOSED) {
|
||||||
if ((msg->conn->flags & NETCONN_FLAG_IPV6_V6ONLY) == 0) {
|
/* connection is not closed, cannot listen */
|
||||||
#if TCP_LISTEN_BACKLOG
|
msg->err = ERR_VAL;
|
||||||
lpcb = tcp_listen_dual_with_backlog(msg->conn->pcb.tcp, msg->msg.lb.backlog);
|
|
||||||
#else /* TCP_LISTEN_BACKLOG */
|
|
||||||
lpcb = tcp_listen_dual(msg->conn->pcb.tcp);
|
|
||||||
#endif /* TCP_LISTEN_BACKLOG */
|
|
||||||
} else
|
|
||||||
#endif /* LWIP_IPV6 */
|
|
||||||
{
|
|
||||||
#if TCP_LISTEN_BACKLOG
|
|
||||||
lpcb = tcp_listen_with_backlog(msg->conn->pcb.tcp, msg->msg.lb.backlog);
|
|
||||||
#else /* TCP_LISTEN_BACKLOG */
|
|
||||||
lpcb = tcp_listen(msg->conn->pcb.tcp);
|
|
||||||
#endif /* TCP_LISTEN_BACKLOG */
|
|
||||||
}
|
|
||||||
if (lpcb == NULL) {
|
|
||||||
/* in this case, the old pcb is still allocated */
|
|
||||||
msg->err = ERR_MEM;
|
|
||||||
} else {
|
} else {
|
||||||
/* delete the recvmbox and allocate the acceptmbox */
|
#if LWIP_IPV6
|
||||||
if (sys_mbox_valid(&msg->conn->recvmbox)) {
|
if ((msg->conn->flags & NETCONN_FLAG_IPV6_V6ONLY) == 0) {
|
||||||
/** @todo: should we drain the recvmbox here? */
|
#if TCP_LISTEN_BACKLOG
|
||||||
sys_mbox_free(&msg->conn->recvmbox);
|
lpcb = tcp_listen_dual_with_backlog(msg->conn->pcb.tcp, msg->msg.lb.backlog);
|
||||||
sys_mbox_set_invalid(&msg->conn->recvmbox);
|
#else /* TCP_LISTEN_BACKLOG */
|
||||||
|
lpcb = tcp_listen_dual(msg->conn->pcb.tcp);
|
||||||
|
#endif /* TCP_LISTEN_BACKLOG */
|
||||||
|
} else
|
||||||
|
#endif /* LWIP_IPV6 */
|
||||||
|
{
|
||||||
|
#if TCP_LISTEN_BACKLOG
|
||||||
|
lpcb = tcp_listen_with_backlog(msg->conn->pcb.tcp, msg->msg.lb.backlog);
|
||||||
|
#else /* TCP_LISTEN_BACKLOG */
|
||||||
|
lpcb = tcp_listen(msg->conn->pcb.tcp);
|
||||||
|
#endif /* TCP_LISTEN_BACKLOG */
|
||||||
}
|
}
|
||||||
msg->err = ERR_OK;
|
if (lpcb == NULL) {
|
||||||
if (!sys_mbox_valid(&msg->conn->acceptmbox)) {
|
/* in this case, the old pcb is still allocated */
|
||||||
msg->err = sys_mbox_new(&msg->conn->acceptmbox, DEFAULT_ACCEPTMBOX_SIZE);
|
msg->err = ERR_MEM;
|
||||||
}
|
|
||||||
if (msg->err == ERR_OK) {
|
|
||||||
msg->conn->state = NETCONN_LISTEN;
|
|
||||||
msg->conn->pcb.tcp = lpcb;
|
|
||||||
tcp_arg(msg->conn->pcb.tcp, msg->conn);
|
|
||||||
tcp_accept(msg->conn->pcb.tcp, accept_function);
|
|
||||||
} else {
|
} else {
|
||||||
/* since the old pcb is already deallocated, free lpcb now */
|
/* delete the recvmbox and allocate the acceptmbox */
|
||||||
tcp_close(lpcb);
|
if (sys_mbox_valid(&msg->conn->recvmbox)) {
|
||||||
msg->conn->pcb.tcp = NULL;
|
/** @todo: should we drain the recvmbox here? */
|
||||||
|
sys_mbox_free(&msg->conn->recvmbox);
|
||||||
|
sys_mbox_set_invalid(&msg->conn->recvmbox);
|
||||||
|
}
|
||||||
|
msg->err = ERR_OK;
|
||||||
|
if (!sys_mbox_valid(&msg->conn->acceptmbox)) {
|
||||||
|
msg->err = sys_mbox_new(&msg->conn->acceptmbox, DEFAULT_ACCEPTMBOX_SIZE);
|
||||||
|
}
|
||||||
|
if (msg->err == ERR_OK) {
|
||||||
|
msg->conn->state = NETCONN_LISTEN;
|
||||||
|
msg->conn->pcb.tcp = lpcb;
|
||||||
|
tcp_arg(msg->conn->pcb.tcp, msg->conn);
|
||||||
|
tcp_accept(msg->conn->pcb.tcp, accept_function);
|
||||||
|
} else {
|
||||||
|
/* since the old pcb is already deallocated, free lpcb now */
|
||||||
|
tcp_close(lpcb);
|
||||||
|
msg->conn->pcb.tcp = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,10 +51,10 @@ static const char *err_strerr[] = {
|
||||||
"Operation would block.", /* ERR_WOULDBLOCK -7 */
|
"Operation would block.", /* ERR_WOULDBLOCK -7 */
|
||||||
"Address in use.", /* ERR_USE -8 */
|
"Address in use.", /* ERR_USE -8 */
|
||||||
"Already connected.", /* ERR_ISCONN -9 */
|
"Already connected.", /* ERR_ISCONN -9 */
|
||||||
"Connection aborted.", /* ERR_ABRT -10 */
|
"Not connected.", /* ERR_CONN -10 */
|
||||||
"Connection reset.", /* ERR_RST -11 */
|
"Connection aborted.", /* ERR_ABRT -11 */
|
||||||
"Connection closed.", /* ERR_CLSD -12 */
|
"Connection reset.", /* ERR_RST -12 */
|
||||||
"Not connected.", /* ERR_CONN -13 */
|
"Connection closed.", /* ERR_CLSD -13 */
|
||||||
"Illegal argument.", /* ERR_ARG -14 */
|
"Illegal argument.", /* ERR_ARG -14 */
|
||||||
"Low-level netif error.", /* ERR_IF -15 */
|
"Low-level netif error.", /* ERR_IF -15 */
|
||||||
};
|
};
|
||||||
|
|
|
@ -208,10 +208,10 @@ static const int err_to_errno_table[] = {
|
||||||
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
|
EWOULDBLOCK, /* ERR_WOULDBLOCK -7 Operation would block. */
|
||||||
EADDRINUSE, /* ERR_USE -8 Address in use. */
|
EADDRINUSE, /* ERR_USE -8 Address in use. */
|
||||||
EALREADY, /* ERR_ISCONN -9 Already connected. */
|
EALREADY, /* ERR_ISCONN -9 Already connected. */
|
||||||
ECONNABORTED, /* ERR_ABRT -10 Connection aborted. */
|
ENOTCONN, /* ERR_CONN -10 Not connected. */
|
||||||
ECONNRESET, /* ERR_RST -11 Connection reset. */
|
ECONNABORTED, /* ERR_ABRT -11 Connection aborted. */
|
||||||
ENOTCONN, /* ERR_CLSD -12 Connection closed. */
|
ECONNRESET, /* ERR_RST -12 Connection reset. */
|
||||||
ENOTCONN, /* ERR_CONN -13 Not connected. */
|
ENOTCONN, /* ERR_CLSD -13 Connection closed. */
|
||||||
EIO, /* ERR_ARG -14 Illegal argument. */
|
EIO, /* ERR_ARG -14 Illegal argument. */
|
||||||
-1, /* ERR_IF -15 Low-level netif error */
|
-1, /* ERR_IF -15 Low-level netif error */
|
||||||
};
|
};
|
||||||
|
|
|
@ -62,10 +62,12 @@ typedef s8_t err_t;
|
||||||
|
|
||||||
#define ERR_IS_FATAL(e) ((e) < ERR_ISCONN)
|
#define ERR_IS_FATAL(e) ((e) < ERR_ISCONN)
|
||||||
|
|
||||||
#define ERR_ABRT -10 /* Connection aborted. */
|
#define ERR_CONN -10 /* Not connected. */
|
||||||
#define ERR_RST -11 /* Connection reset. */
|
#define ERR_IS_FATAL_LISTENCONNECT(e) ((e) < ERR_CONN)
|
||||||
#define ERR_CLSD -12 /* Connection closed. */
|
|
||||||
#define ERR_CONN -13 /* Not connected. */
|
#define ERR_ABRT -11 /* Connection aborted. */
|
||||||
|
#define ERR_RST -12 /* Connection reset. */
|
||||||
|
#define ERR_CLSD -13 /* Connection closed. */
|
||||||
|
|
||||||
#define ERR_ARG -14 /* Illegal argument. */
|
#define ERR_ARG -14 /* Illegal argument. */
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue
Block a user