net: Forward socket option only when the socket type is usrsock

Change-Id: I5e102c4c648936f96834120e2c508f7072436246
Signed-off-by: Jiuzhu Dong <dongjiuzhu1@xiaomi.com>
This commit is contained in:
Xu Xingliang 2021-04-07 16:50:21 +08:00 committed by Xiang Xiao
parent 105f305b1b
commit f07df9dfc8
2 changed files with 37 additions and 22 deletions

View File

@ -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;

View File

@ -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;
}