From f07df9dfc8d2807f208f82c8bc81627225ffeb6b Mon Sep 17 00:00:00 2001 From: Xu Xingliang Date: Wed, 7 Apr 2021 16:50:21 +0800 Subject: [PATCH] net: Forward socket option only when the socket type is usrsock Change-Id: I5e102c4c648936f96834120e2c508f7072436246 Signed-off-by: Jiuzhu Dong --- net/socket/getsockopt.c | 43 ++++++++++++++++++++++++----------------- net/socket/setsockopt.c | 16 +++++++++++---- 2 files changed, 37 insertions(+), 22 deletions(-) diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index 57c71e6bc2..5d46bd5fdf 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -87,7 +87,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, return -EINVAL; } - /* Process the option */ + /* Process the options always handled locally */ switch (option) { @@ -125,9 +125,31 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, net_dsec2timeval(timeo, (struct timeval *)value); *value_len = sizeof(struct timeval); } - break; -#ifndef CONFIG_NET_USRSOCK + return OK; + } + +#ifdef CONFIG_NET_USRSOCK + if (psock->s_type == SOCK_USRSOCK_TYPE) + { + if (option == SO_TYPE) + { + FAR struct usrsock_conn_s *conn = psock->s_conn; + + /* Return the actual socket type */ + + *(FAR int *)value = conn->type; + *value_len = sizeof(int); + + return OK; + } + + return -ENOPROTOOPT; + } +#endif + + switch (option) + { case SO_ACCEPTCONN: /* Reports whether socket listening is enabled */ if (*value_len < sizeof(int)) { @@ -204,20 +226,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, return -EINVAL; } -#ifdef CONFIG_NET_USRSOCK - if (psock->s_type == SOCK_USRSOCK_TYPE) - { - FAR struct usrsock_conn_s *conn = psock->s_conn; - - /* Return the actual socket type */ - - *(FAR int *)value = conn->type; - *value_len = sizeof(int); - - break; - } -#endif - /* Return the socket type */ *(FAR int *)value = psock->s_type; @@ -259,7 +267,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, case SO_RCVLOWAT: /* Sets the minimum number of bytes to input */ case SO_SNDBUF: /* Sets send buffer size */ case SO_SNDLOWAT: /* Sets the minimum number of bytes to output */ -#endif default: return -ENOPROTOOPT; diff --git a/net/socket/setsockopt.c b/net/socket/setsockopt.c index f85e5f48f7..fd22f315aa 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -82,7 +82,7 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, return -EINVAL; } - /* Process the option */ + /* Process the options always handled locally */ switch (option) { @@ -132,10 +132,19 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, _SO_SETOPT(psock->s_options, option); } } - break; -#ifndef CONFIG_NET_USRSOCK + 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 */ @@ -276,7 +285,6 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, case SO_ERROR: /* Reports and clears error status. */ case SO_TYPE: /* Reports the socket type */ -#endif default: return -ENOPROTOOPT; }