From a35ba1e7bcd778453ee4ad75fe8f0d7b39a6df42 Mon Sep 17 00:00:00 2001 From: SPRESENSE <41312067+SPRESENSE@users.noreply.github.com> Date: Tue, 27 Jun 2023 11:27:23 +0900 Subject: [PATCH] net: Create fallback option for usrsock Changed implementation to use the Kernel network stack when usrsock daemon returns an error. This change allows the Kernel network stack to be used instead of UsrSock when opening a Socket at a time when a VPN configured with TUN is enabled. --- net/socket/net_sockif.c | 8 -------- net/socket/socket.c | 20 ++++++++++++++++++++ 2 files changed, 20 insertions(+), 8 deletions(-) diff --git a/net/socket/net_sockif.c b/net/socket/net_sockif.c index ec9024111c3..e2bfc4736e1 100644 --- a/net/socket/net_sockif.c +++ b/net/socket/net_sockif.c @@ -38,7 +38,6 @@ #include "pkt/pkt.h" #include "bluetooth/bluetooth.h" #include "ieee802154/ieee802154.h" -#include "usrsock/usrsock.h" #include "socket/socket.h" /**************************************************************************** @@ -132,12 +131,5 @@ 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/socket.c b/net/socket/socket.c index e4a43cb49f1..964274b6e03 100644 --- a/net/socket/socket.c +++ b/net/socket/socket.c @@ -29,6 +29,7 @@ #include #include +#include "usrsock/usrsock.h" #include "socket/socket.h" #ifdef CONFIG_NET @@ -93,6 +94,25 @@ int psock_socket(int domain, int type, int protocol, psock->s_conn = NULL; psock->s_type = type & SOCK_TYPE_MASK; +#ifdef CONFIG_NET_USRSOCK + /* Get the usrsock interface */ + + sockif = &g_usrsock_sockif; + psock->s_sockif = sockif; + + ret = sockif->si_setup(psock); + + /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use + * kernel's network stack, so fallback to kernel socket. + */ + + if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP)) + { + return ret; + } + +#endif + /* Get the socket interface */ sockif = net_sockif(domain, psock->s_type, psock->s_proto);