diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index e2f815b55c9..8eceed0e910 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -33,7 +33,6 @@ #include #include "socket/socket.h" -#include "usrsock/usrsock.h" #include "utils/utils.h" /**************************************************************************** @@ -122,21 +121,11 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, /* Then return the timeout value to the caller */ - net_dsec2timeval(timeo, (struct timeval *)value); - *value_len = sizeof(struct timeval); + net_dsec2timeval(timeo, (FAR struct timeval *)value); + *value_len = sizeof(struct timeval); return OK; } - } -#ifdef CONFIG_NET_USRSOCK - if (psock->s_type == SOCK_USRSOCK_TYPE) - { - return -ENOPROTOOPT; - } -#endif - - switch (option) - { case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */ { if (*value_len < sizeof(int)) @@ -297,6 +286,13 @@ int psock_getsockopt(FAR struct socket *psock, int level, int option, ret = psock_socketlevel_option(psock, option, value, value_len); } + /* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */ + + else if (ret == -ENOTTY) + { + ret = -ENOPROTOOPT; + } + return ret; } diff --git a/net/socket/net_sockif.c b/net/socket/net_sockif.c index ea8ccdcc1cc..ec9024111c3 100644 --- a/net/socket/net_sockif.c +++ b/net/socket/net_sockif.c @@ -38,6 +38,7 @@ #include "pkt/pkt.h" #include "bluetooth/bluetooth.h" #include "ieee802154/ieee802154.h" +#include "usrsock/usrsock.h" #include "socket/socket.h" /**************************************************************************** @@ -75,12 +76,12 @@ net_sockif(sa_family_t family, int type, int protocol) switch (family) { #ifdef HAVE_INET_SOCKETS -#ifdef HAVE_PFINET_SOCKETS +# ifdef HAVE_PFINET_SOCKETS case PF_INET: -#endif -#ifdef HAVE_PFINET6_SOCKETS +# endif +# ifdef HAVE_PFINET6_SOCKETS case PF_INET6: -#endif +# endif sockif = inet_sockif(family, type, protocol); break; #endif @@ -131,5 +132,12 @@ net_sockif(sa_family_t family, int type, int protocol) nerr("ERROR: Address family unsupported: %d\n", family); } +#ifdef CONFIG_NET_USRSOCK + if (sockif == NULL) + { + sockif = &g_usrsock_sockif; + } +#endif + return sockif; } diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index e2a13af450a..c6edf82aa99 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -38,7 +38,6 @@ #include #include "socket/socket.h" -#include "usrsock/usrsock.h" #include "utils/utils.h" /**************************************************************************** @@ -134,17 +133,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, return OK; } - } -#ifdef CONFIG_NET_USRSOCK - if (psock->s_type == SOCK_USRSOCK_TYPE) - { - return -ENOPROTOOPT; - } -#endif - - switch (option) - { case SO_BROADCAST: /* Permits sending of broadcast messages */ case SO_DEBUG: /* Enables recording of debugging information */ case SO_DONTROUTE: /* Requests outgoing messages bypass standard routing */ @@ -329,6 +318,13 @@ int psock_setsockopt(FAR struct socket *psock, int level, int option, ret = psock_socketlevel_option(psock, option, value, value_len); } + /* -ENOTTY really mean -ENOPROTOOPT, but skip the default action */ + + else if (ret == -ENOTTY) + { + ret = -ENOPROTOOPT; + } + return ret; } diff --git a/net/socket/socket.c b/net/socket/socket.c index 12e6649b2ea..af64b56d874 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -29,7 +29,6 @@ #include #include -#include "usrsock/usrsock.h" #include "socket/socket.h" #ifdef CONFIG_NET @@ -94,38 +93,23 @@ int psock_socket(int domain, int type, int protocol, psock->s_conn = NULL; psock->s_type = type & SOCK_TYPE_MASK; -#ifdef CONFIG_NET_USRSOCK - if (domain != PF_LOCAL && domain != PF_UNSPEC && domain != PF_RPMSG) + /* Get the socket interface */ + + sockif = net_sockif(domain, psock->s_type, protocol); + if (sockif == NULL) { - /* Handle special setup for USRSOCK sockets (user-space networking - * stack). - */ - - ret = g_usrsock_sockif.si_setup(psock, protocol); - psock->s_sockif = &g_usrsock_sockif; - } - else -#endif /* CONFIG_NET_USRSOCK */ - { - /* Get the socket interface */ - - sockif = net_sockif(domain, psock->s_type, protocol); - if (sockif == NULL) - { - nerr("ERROR: socket address family unsupported: %d\n", domain); - return -EAFNOSUPPORT; - } - - /* The remaining of the socket initialization depends on the address - * family. - */ - - DEBUGASSERT(sockif->si_setup != NULL); - psock->s_sockif = sockif; - - ret = sockif->si_setup(psock, protocol); + nerr("ERROR: socket address family unsupported: %d\n", domain); + return -EAFNOSUPPORT; } + /* The remaining of the socket initialization depends on the address + * family. + */ + + DEBUGASSERT(sockif->si_setup != NULL); + psock->s_sockif = sockif; + + ret = sockif->si_setup(psock, protocol); if (ret >= 0) { FAR struct socket_conn_s *conn = psock->s_conn; diff --git a/net/usrsock/usrsock.h b/net/usrsock/usrsock.h index 7cbb0fd7dd7..313db6dfe94 100644 --- a/net/usrsock/usrsock.h +++ b/net/usrsock/usrsock.h @@ -41,11 +41,6 @@ * Pre-processor Definitions ****************************************************************************/ -/* Internal socket type/domain for marking usrsock sockets */ - -#define SOCK_USRSOCK_TYPE 0x7f -#define PF_USRSOCK_DOMAIN 0x7f - /* Internal event flags */ #define USRSOCK_EVENT_CONNECT_READY (1 << 0) @@ -84,7 +79,6 @@ struct usrsock_conn_s enum usrsock_conn_state_e state; /* State of kernel<->daemon link for conn */ bool connected; /* Socket has been connected */ - int8_t type; /* Socket type (SOCK_STREAM, etc) */ int16_t usockid; /* Connection number used for kernel<->daemon */ uint16_t flags; /* Socket state flags */ diff --git a/net/usrsock/usrsock_accept.c b/net/usrsock/usrsock_accept.c index 64be6e0e488..eb6992aa910 100644 --- a/net/usrsock/usrsock_accept.c +++ b/net/usrsock/usrsock_accept.c @@ -409,7 +409,6 @@ int usrsock_accept(FAR struct socket *psock, FAR struct sockaddr *addr, if (ret >= 0) { newconn->connected = true; - newconn->type = conn->type; newconn->crefs = 1; newsock->s_type = psock->s_type; diff --git a/net/usrsock/usrsock_connect.c b/net/usrsock/usrsock_connect.c index 68e8e9e8d78..0a32d540b7e 100644 --- a/net/usrsock/usrsock_connect.c +++ b/net/usrsock/usrsock_connect.c @@ -172,7 +172,7 @@ int usrsock_connect(FAR struct socket *psock, } if (conn->connected && - (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET)) + (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET)) { /* Already connected. */ diff --git a/net/usrsock/usrsock_getsockopt.c b/net/usrsock/usrsock_getsockopt.c index 393f79dd205..21da7127d85 100644 --- a/net/usrsock/usrsock_getsockopt.c +++ b/net/usrsock/usrsock_getsockopt.c @@ -179,20 +179,12 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option, struct iovec inbufs[1]; int ret; - if (level == SOL_SOCKET) - { - if (option == SO_TYPE) - { - /* Return the actual socket type */ + /* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */ - *(FAR int *)value = conn->type; - *value_len = sizeof(int); - return OK; - } - else if (option == SO_RCVTIMEO || option == SO_SNDTIMEO) - { - return -ENOPROTOOPT; - } + if (level == SOL_SOCKET && (option == SO_TYPE || + option == SO_RCVTIMEO || option == SO_SNDTIMEO)) + { + return -ENOPROTOOPT; } net_lock(); @@ -249,6 +241,13 @@ int usrsock_getsockopt(FAR struct socket *psock, int level, int option, usrsock_teardown_datain(conn); usrsock_teardown_data_request_callback(&state); + /* Skip the default socket option handler */ + + if (ret == -ENOPROTOOPT) + { + ret = -ENOTTY; + } + errout_unlock: net_unlock(); return ret; diff --git a/net/usrsock/usrsock_poll.c b/net/usrsock/usrsock_poll.c index 8fe11d8b227..1f0555db1cc 100644 --- a/net/usrsock/usrsock_poll.c +++ b/net/usrsock/usrsock_poll.c @@ -200,8 +200,8 @@ static int usrsock_pollsetup(FAR struct socket *psock, /* Stream sockets need to be connected or connecting (or listening). */ - else if ((conn->type == SOCK_STREAM || - conn->type == SOCK_SEQPACKET) && + else if ((psock->s_type == SOCK_STREAM || + psock->s_type == SOCK_SEQPACKET) && !(conn->connected || conn->state == USRSOCK_CONN_STATE_CONNECTING)) { diff --git a/net/usrsock/usrsock_recvmsg.c b/net/usrsock/usrsock_recvmsg.c index e3881ac0970..afef0548dbc 100644 --- a/net/usrsock/usrsock_recvmsg.c +++ b/net/usrsock/usrsock_recvmsg.c @@ -246,7 +246,7 @@ ssize_t usrsock_recvmsg(FAR struct socket *psock, FAR struct msghdr *msg, goto errout_unlock; } - if (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET) + if (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET) { if (!conn->connected) { diff --git a/net/usrsock/usrsock_sendmsg.c b/net/usrsock/usrsock_sendmsg.c index f8c6ef9e0cb..6f14961cd42 100644 --- a/net/usrsock/usrsock_sendmsg.c +++ b/net/usrsock/usrsock_sendmsg.c @@ -225,7 +225,7 @@ ssize_t usrsock_sendmsg(FAR struct socket *psock, goto errout_unlock; } - if (conn->type == SOCK_STREAM || conn->type == SOCK_SEQPACKET) + if (psock->s_type == SOCK_STREAM || psock->s_type == SOCK_SEQPACKET) { if (!conn->connected) { diff --git a/net/usrsock/usrsock_setsockopt.c b/net/usrsock/usrsock_setsockopt.c index 3fc2c16c13b..923836a41c0 100644 --- a/net/usrsock/usrsock_setsockopt.c +++ b/net/usrsock/usrsock_setsockopt.c @@ -168,12 +168,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option, int ret; DEBUGASSERT(conn); - if (level == SOL_SOCKET) + + /* SO_[RCV|SND]TIMEO have to be handled locally to break the block i/o */ + + if (level == SOL_SOCKET && (option == SO_TYPE || + option == SO_RCVTIMEO || option == SO_SNDTIMEO)) { - if (option == SO_RCVTIMEO || option == SO_SNDTIMEO) - { - return -ENOPROTOOPT; - } + return -ENOPROTOOPT; } net_lock(); @@ -215,6 +216,13 @@ int usrsock_setsockopt(FAR struct socket *psock, int level, int option, usrsock_teardown_request_callback(&state); + /* Skip the default socket option handler */ + + if (ret == -ENOPROTOOPT) + { + ret = -ENOTTY; + } + errout_unlock: net_unlock(); return ret; diff --git a/net/usrsock/usrsock_socket.c b/net/usrsock/usrsock_socket.c index bc454fd0b33..edf7591fbac 100644 --- a/net/usrsock/usrsock_socket.c +++ b/net/usrsock/usrsock_socket.c @@ -233,9 +233,6 @@ int usrsock_socket(int domain, int type, int protocol, goto errout_teardown_callback; } - psock->s_type = SOCK_USRSOCK_TYPE; - psock->s_domain = PF_USRSOCK_DOMAIN; - conn->type = type; psock->s_conn = conn; conn->crefs = 1; diff --git a/net/usrsock/usrsock_sockif.c b/net/usrsock/usrsock_sockif.c index 6f83ca30faa..d5810a5c7ce 100644 --- a/net/usrsock/usrsock_sockif.c +++ b/net/usrsock/usrsock_sockif.c @@ -99,13 +99,8 @@ const struct sock_intf_s g_usrsock_sockif = static int usrsock_sockif_setup(FAR struct socket *psock, int protocol) { - int domain = psock->s_domain; - int type = psock->s_type; int ret; - psock->s_type = PF_UNSPEC; - psock->s_conn = NULL; - /* Let the user socket logic handle the setup... * * A return value of zero means that the operation was @@ -115,7 +110,7 @@ static int usrsock_sockif_setup(FAR struct socket *psock, int protocol) * to open socket with kernel networking stack in this case. */ - ret = usrsock_socket(domain, type, protocol, psock); + ret = usrsock_socket(psock->s_domain, psock->s_type, protocol, psock); if (ret == -ENETDOWN) { nwarn("WARNING: usrsock daemon is not running\n");