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.
This commit is contained in:
SPRESENSE 2023-06-27 11:27:23 +09:00 committed by Xiang Xiao
parent 011d45e956
commit a35ba1e7bc
2 changed files with 20 additions and 8 deletions

View File

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

View File

@ -29,6 +29,7 @@
#include <assert.h>
#include <debug.h>
#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);