Skip to content

Commit

Permalink
net: Create fallback option for usrsock
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
SPRESENSE committed Sep 20, 2023
1 parent 1a71910 commit 8ada634
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 8 deletions.
8 changes: 0 additions & 8 deletions net/socket/net_sockif.c
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@
#include "pkt/pkt.h"
#include "bluetooth/bluetooth.h"
#include "ieee802154/ieee802154.h"
#include "usrsock/usrsock.h"
#include "socket/socket.h"

/****************************************************************************
Expand Down Expand Up @@ -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;
}
20 changes: 20 additions & 0 deletions net/socket/socket.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#include <assert.h>
#include <debug.h>

#include "usrsock/usrsock.h"
#include "socket/socket.h"

#ifdef CONFIG_NET
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 8ada634

Please sign in to comment.