You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by xi...@apache.org on 2023/09/20 17:08:20 UTC

[nuttx] 03/03: net: Create fallback option for usrsock

This is an automated email from the ASF dual-hosted git repository.

xiaoxiang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git

commit a35ba1e7bcd778453ee4ad75fe8f0d7b39a6df42
Author: SPRESENSE <41...@users.noreply.github.com>
AuthorDate: Tue Jun 27 11:27:23 2023 +0900

    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 ec9024111c..e2bfc4736e 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 e4a43cb49f..964274b6e0 100644
--- a/net/socket/socket.c
+++ b/net/socket/socket.c
@@ -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);