From f8c5fe24fb2003f4ea106f939fb13b56feb570f7 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 Signed-off-by: Xu Xingliang Change-Id: I5e102c4c648936f96834120e2c508f7072436246 --- net/socket/getsockopt.c | 40 +++++++++++++++++++++++----------------- net/socket/setsockopt.c | 13 ++++++++++--- 2 files changed, 33 insertions(+), 20 deletions(-) diff --git a/net/socket/getsockopt.c b/net/socket/getsockopt.c index a9e059bc5dd..0fcf6fbe20c 100644 --- a/net/socket/getsockopt.c +++ b/net/socket/getsockopt.c @@ -103,7 +103,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) { @@ -142,8 +142,29 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, *value_len = sizeof(struct timeval); } break; + } -#ifndef CONFIG_NET_USRSOCK +#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)) { @@ -220,20 +241,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; @@ -275,7 +282,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 39cb5b6b0f0..95e358993b4 100644 --- a/net/socket/setsockopt.c +++ b/net/socket/setsockopt.c @@ -98,7 +98,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) { @@ -149,9 +149,17 @@ static int psock_socketlevel_option(FAR struct socket *psock, int option, } } break; + } -#ifndef CONFIG_NET_USRSOCK +#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 */ @@ -292,7 +300,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; }