You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@nuttx.apache.org by "dlizewski (via GitHub)" <gi...@apache.org> on 2023/10/31 17:11:20 UTC

[PR] Fallback with ENETDOWN [nuttx]

dlizewski opened a new pull request, #11107:
URL: https://github.com/apache/nuttx/pull/11107

   ## Summary
   #9647 added the ability to do runtime selection of usrsock and fallback to kernel provided sockets, but the problem is that it currently requires the application side usrsock daemon to be running in order to respond with -ENOSYS or -ENOTSUP.
   
   There is already code in usrsock that checks if there is an application side daemon listening and returns -ENETDOWN if nothing is listening.
   Specifically in "usrsock_request" in drivers/usrsock/usrsock_dev.c
   
   Enabling fallback to kernel socket with -ENETDOWN allows the application to not launch the usrsock daemon when not needed. Otherwise my application needs to keep the daemon running for the sole purpose of saying it's off wasting resources.
   
   This was likely the original intention of original author based on the comment in "usrsock_sockif_setup" which says:
   
   ```
    /* Let the user socket logic handle the setup...
      *
      * A return value of zero means that the operation was
      * successfully handled by usrsock.  A negative value means that
      * an error occurred.  The special error value -ENETDOWN means
      * that usrsock daemon is not running.  The caller should attempt
      * to open socket with kernel networking stack in this case.
      */
      ```
   
   
   ## Impact
   
   ## Testing
   
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Usrsock socket fallback with ENETDOWN [nuttx]

Posted by "dlizewski (via GitHub)" <gi...@apache.org>.
dlizewski commented on code in PR #11107:
URL: https://github.com/apache/nuttx/pull/11107#discussion_r1377994323


##########
net/socket/socket.c:
##########
@@ -104,9 +104,11 @@ int psock_socket(int domain, int type, int protocol,
 
   /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use
    * kernel's network stack, so fallback to kernel socket.
+   * When -ENETDOWN is returned, it means the usrsock daemon was never
+   * launched or is no longer running, so fallback to kernel socket.
    */
 
-  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP))
+  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP && ret != -ENETDOWN))

Review Comment:
   As far as I can see, -ENETDOWN is only returned from usrsock_sockif_setup() if either:
   a. the application side doesn't have the dev node open. In which case usrsockdev_is_opened() returns false in usrsock_request().
     usrsock_sockif_setup()->usrsock_socket()->do_socket_request()->usrsock_do_request()->usrsock_request returns() -> returns -ENETDOWN
   
   b. The USRSOCK_EVENT_ABORT event is sent to the callback "socket_event" registered in usrsock_socket().
   The USRSOCK_EVENT_ABORT is only set in usrsock_abort() which is called when the application closes the /dev/usrsock devnode. Both cases should fallback to kernel provided sockets.
   
   
   Is there another case of -ENETDOWN that I did not see?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Usrsock socket fallback with ENETDOWN [nuttx]

Posted by "dlizewski (via GitHub)" <gi...@apache.org>.
dlizewski commented on code in PR #11107:
URL: https://github.com/apache/nuttx/pull/11107#discussion_r1379343508


##########
net/socket/socket.c:
##########
@@ -104,9 +104,11 @@ int psock_socket(int domain, int type, int protocol,
 
   /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use
    * kernel's network stack, so fallback to kernel socket.
+   * When -ENETDOWN is returned, it means the usrsock daemon was never
+   * launched or is no longer running, so fallback to kernel socket.
    */
 
-  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP))
+  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP && ret != -ENETDOWN))

Review Comment:
   Thanks. I has missed that.
   
   There was a test which aborted the daemon and was checking to see ENETDOWN.
   I propagated the original return code of usrsock if it tired to fallback to kernel but the kernel doesn't have any sockets of that type compiled in. Which is what the behaviour would have been before #9647 when it used to only use usrsock if the kernel didnt provide a socket of that family.
   
   The other option was to keep the shutdown test but remove the check for ENETDOWN, but that felt like a reduciton of testing scope.
   
   



##########
net/socket/socket.c:
##########
@@ -104,9 +104,11 @@ int psock_socket(int domain, int type, int protocol,
 
   /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use
    * kernel's network stack, so fallback to kernel socket.
+   * When -ENETDOWN is returned, it means the usrsock daemon was never
+   * launched or is no longer running, so fallback to kernel socket.
    */
 
-  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP))
+  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP && ret != -ENETDOWN))

Review Comment:
   Thanks. I had missed that.
   
   There was a test which aborted the daemon and was checking to see ENETDOWN.
   I propagated the original return code of usrsock if it tired to fallback to kernel but the kernel doesn't have any sockets of that type compiled in. Which is what the behaviour would have been before #9647 when it used to only use usrsock if the kernel didnt provide a socket of that family.
   
   The other option was to keep the shutdown test but remove the check for ENETDOWN, but that felt like a reduciton of testing scope.
   
   



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Usrsock socket fallback with ENETDOWN [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #11107:
URL: https://github.com/apache/nuttx/pull/11107#discussion_r1378308214


##########
net/socket/socket.c:
##########
@@ -104,9 +104,11 @@ int psock_socket(int domain, int type, int protocol,
 
   /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use
    * kernel's network stack, so fallback to kernel socket.
+   * When -ENETDOWN is returned, it means the usrsock daemon was never
+   * launched or is no longer running, so fallback to kernel socket.
    */
 
-  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP))
+  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP && ret != -ENETDOWN))

Review Comment:
   Ok, but usrsock test fail with this patch, please fix it.



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Usrsock socket fallback with ENETDOWN [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 commented on code in PR #11107:
URL: https://github.com/apache/nuttx/pull/11107#discussion_r1377938070


##########
net/socket/socket.c:
##########
@@ -104,9 +104,11 @@ int psock_socket(int domain, int type, int protocol,
 
   /* When usrsock daemon returns -ENOSYS or -ENOTSUP, it means to use
    * kernel's network stack, so fallback to kernel socket.
+   * When -ENETDOWN is returned, it means the usrsock daemon was never
+   * launched or is no longer running, so fallback to kernel socket.
    */
 
-  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP))
+  if (ret == 0 || (ret != -ENOSYS && ret != -ENOTSUP && ret != -ENETDOWN))

Review Comment:
   since -ENETDOWN return in other case, should we change the errror code to -ENOSYS/-ENOTSUP if the server doesn't launch yet?



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


Re: [PR] Usrsock socket fallback with ENETDOWN [nuttx]

Posted by "xiaoxiang781216 (via GitHub)" <gi...@apache.org>.
xiaoxiang781216 merged PR #11107:
URL: https://github.com/apache/nuttx/pull/11107


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: commits-unsubscribe@nuttx.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org