usbipd: enable tcp keepalive and set its options for accepted connection
Subsystems (2)
v2 cover usbipd: enable tcp keepalive and set its options for accepted connection
If usbip client does not close a TCP/IP connection to a daemon gracefully, the daemon will keep this connection open indefinitely.
The issue is that the client cannot attach this device again until the device will be rebinded by commands:
"usbip unbind -b ..." and "usbip bind -b ...".
This issue was reported by a user, look for details here
https://github.com/vadimgrn/usbip-win2/issues/109.
To reproduce this issue, run "usbip attach ..." to attach remote usb device and make a hard reset of this PC by pressing Reset button. usbipd will keep this connection forever and will not allow to attach this device again until unbind/bind will be executed.
To fix that, enable SO_KEEPALIVE for accepted connection and set keepalive parameters if corresponding program options are passed.
Vadym Hrynchyshyn (3):
usbipd: enable SO_KEEPALIVE socket option for accepted connection
usbipd: add long options to set TCP_KEEPIDLE/TCP_KEEPCNT/TCP_KEEPINTVL
socket options
usbipd: use usbip_to_int to simplify usbip_setup_port_number
implementation
tools/usb/usbip/configure.ac | 24 +++++++- tools/usb/usbip/src/usbip_network.c | 96 +++++++++++++++++++++++++---- tools/usb/usbip/src/usbip_network.h | 14 +++++ tools/usb/usbip/src/usbipd.c | 58 +++++++++++++++-- 4 files changed, 174 insertions(+), 18 deletions(-)
Signature · 1 line
2.43.0
PATCH v2 1/3 usbipd: enable SO_KEEPALIVE socket option for accepted connection
If usbip client does not close a TCP/IP connection to a daemon gracefully, the daemon will keep this connection open indefinitely.
The issue is that the client cannot attach this device again until the device will be rebinded on server side by commands:
usbip unbind -b X-Y
usbip bind -b X-Y
usbip client enables tcp keepalive by calling usbip_net_set_keepalive from usbip_net_tcp_connect. usbip daemon now enables this socket option too for accepted connection.
--- tools/usb/usbip/src/usbipd.c | 1 + 1 file changed, 1 insertion(+)
tools/usb/usbip/src/usbipd.c +1 -0
@@ -119,6 +119,7 @@ static int recv_request_import(int sockfd)if (found) {/* should set TCP_NODELAY for usbip */ usbip_net_set_nodelay (sockfd); +usbip_net_set_keepalive (sockfd);/* export device needs a TCP/IP socket descriptor */ status =usbip_export_device (edev, sockfd);
Signature · 1 line
2.43.0
PATCH v2 2/3 usbipd: add long options to set TCP_KEEPIDLE/TCP_KEEPCNT/TCP_KEEPINTVL socket options
In reply to Vadym HrynchyshynAdd usbip daemon options "--tcp-keepidle SECS", "--tcp-keepcnt CNT", "--tcp-keepintvl SECS". A user can add these parameters if default values do not satisfy him/her.
If the option is passed, set corresponding socket option for accepted connection. For example, if "--tcp-keepidle 60" is passed, call setsockopt(sockfd, IPPROTO_TCP, TCP_KEEPIDLE, ...).
configure.ac handles presence of these socket options. If TCP_KEEPIDLE/TCP_KEEPCNT/TCP_KEEPINTVL are not available, corresponding program options will not be added.
--- tools/usb/usbip/configure.ac | 24 +++++++- tools/usb/usbip/src/usbip_network.c | 85 +++++++++++++++++++++++++++++ tools/usb/usbip/src/usbip_network.h | 14 +++++ tools/usb/usbip/src/usbipd.c | 59 ++++++++++++++++++-- 4 files changed, 176 insertions(+), 6 deletions(-)
tools/usb/usbip/configure.ac +23 -1
@@ -29,7 +29,7 @@ AC_PROG_MAKE_SET AC_HEADER_DIRENT AC_HEADER_STDC AC_CHECK_HEADERS([arpa/inet.h fcntl.h netdb.h netinet/in.h stdint.h stdlib.h dnl - string.h sys/socket.h syslog.h unistd.h]) + string.h sys/socket.h syslog.h unistd.h netinet/tcp.h]) # Checks for typedefs, structures, and compiler characteristics. AC_TYPE_INT32_T
@@ -107,5 +107,27 @@ AC_ARG_WITH([fortify], dnl [ACTION-IF-NOT-GIVEN] [AC_MSG_RESULT([default])]) +AC_MSG_CHECKING([whether tcp keepalive options are available]) +AC_COMPILE_IFELSE( + [AC_LANG_PROGRAM( + [ #include <sys/socket.h> + #include <arpa/inet.h> + #include <netinet/tcp.h> ], + [ + int n = 0; + setsockopt(-1, IPPROTO_TCP, TCP_KEEPIDLE, &n, sizeof(n)); + setsockopt(-1, IPPROTO_TCP, TCP_KEEPCNT, &n, sizeof(n)); + setsockopt(-1, IPPROTO_TCP, TCP_KEEPINTVL, &n, sizeof(n)); + ] + )], + [ + AC_MSG_RESULT([yes]) + AC_DEFINE([HAVE_KEEPALIVE_OPTS], [1], + [Define to 1 if TCP_KEEPIDLE/TCP_KEEPCNT/TCP_KEEPINTVL + socket-level options are available.]) + ], + [ AC_MSG_RESULT([no]) ], +) + AC_CONFIG_FILES([Makefile libsrc/Makefile src/Makefile]) AC_OUTPUT
tools/usb/usbip/src/usbip_network.c +85 -0
97 lines not on this page · raw message
tools/usb/usbip/src/usbip_network.h +14 -0
@@ -18,6 +18,17 @@ extern int usbip_port;extern char *usbip_port_string;void usbip_setup_port_number (char *arg); +/** +* usbip_to_int - convert string to positive integer +* @name: name of the @val for logging +* @val: string to convert to integer using base 10 +* @maxval: max allowed result value +* +* Return: positive integer on success, zero if conversion +* is not possible or value is out of range [1...maxval]. +*/ +int usbip_to_int (const char *name,const char *val,int maxval); +/* ---------------------------------------------------------------------- */ /* Common header for all the kinds of PDUs. */ struct op_common {
@@ -172,6 +183,9 @@ int usbip_net_recv_op_common(int sockfd, uint16_t *code, int *status);int usbip_net_set_reuseaddr (int sockfd);int usbip_net_set_nodelay (int sockfd);int usbip_net_set_keepalive (int sockfd); +int usbip_net_set_keepidle (int sockfd,int seconds); +int usbip_net_set_keepcnt (int sockfd,int cnt); +int usbip_net_set_keepintvl (int sockfd,int seconds);int usbip_net_set_v6only (int sockfd);int usbip_net_tcp_connect (char *hostname,char *port);
tools/usb/usbip/src/usbipd.c +54 -5
115 lines not on this page · raw message
Signature · 1 line
2.43.0
PATCH v2 3/3 usbipd: use usbip_to_int to simplify usbip_setup_port_number implementation
In reply to Vadym Hrynchyshynusbip_to_int function is used for handling arguments of options --tcp-keepidle,--tcp-keepcnt,--tcp-keepintvl. It is now called from usbip_setup_port_number to handle tcp port number. This simplifies its implementation.
--- tools/usb/usbip/src/usbip_network.c | 25 +++++-------------------- 1 file changed, 5 insertions(+), 20 deletions(-)
tools/usb/usbip/src/usbip_network.c +5 -20
@@ -26,28 +26,13 @@ char *usbip_port_string = "3240";void usbip_setup_port_number (char *arg) {dbg ("parsing port arg '%s'" , arg); -char *end; -unsigned long int port =strtoul (arg, &end,10 ); - -if (end == arg) { -err ("port: could not parse '%s' as a decimal integer" , arg); -return ; - } +int port =usbip_to_int ("port" , arg,UINT16_MAX ); -if (*end !='\0' ) { -err ("port: garbage at end of '%s'" , arg); -return ; +if (port >0 ) { + usbip_port = port; + usbip_port_string = arg; +info ("using port %d (\"%s\")" , usbip_port, usbip_port_string); } - -if (port >UINT16_MAX ) { -err ("port: %s too high (max=%d)" , - arg,UINT16_MAX ); -return ; - } - - usbip_port = port; - usbip_port_string = arg; -info ("using port %d (\"%s\")" , usbip_port, usbip_port_string); }int usbip_to_int (const char *name,const char *val,int maxval)
Signature · 1 line
2.43.0
Greg KH
maintainerQuoted 25 lines · Vadym Hrynchyshyn
If usbip client does not close a TCP/IP connection to a daemon gracefully, the daemon will keep this connection open indefinitely.
The issue is that the client cannot attach this device again until the device will be rebinded by commands:
"usbip unbind -b ..." and "usbip bind -b ...".This issue was reported by a user, look for details here
https://github.com/vadimgrn/usbip-win2/issues/109.To reproduce this issue, run "usbip attach ..." to attach remote usb device and make a hard reset of this PC by pressing Reset button. usbipd will keep this connection forever and will not allow to attach this device again until unbind/bind will be executed.
To fix that, enable
SO_KEEPALIVEfor accepted connection and set keepalive parameters if corresponding program options are passed.Vadym Hrynchyshyn (3):
usbipd: enableSO_KEEPALIVEsocket option for accepted connection
usbipd: add long options to set TCP_KEEPIDLE/TCP_KEEPCNT/TCP_KEEPINTVL
socket options
usbipd: useusbip_to_intto simplifyusbip_setup_port_number
implementation
Quoted 10 lines
tools/usb/usbip/configure.ac | 24 +++++++- tools/usb/usbip/src/usbip_network.c | 96 +++++++++++++++++++++++++---- tools/usb/usbip/src/usbip_network.h | 14 +++++ tools/usb/usbip/src/usbipd.c | 58 +++++++++++++++-- 4 files changed, 174 insertions(+), 18 deletions(-)Signature · 1 line
2.43.0
Hi,
This is the friendly patch-bot of Greg Kroah-Hartman. You have sent him a patch that has triggered this response. He used to manually respond to these common problems, but in order to save his sanity (he kept writing the same thing over and over, yet to different people), I was created. Hopefully you will not take offence and will fix the problem in your patch and resubmit it so that it can be accepted into the Linux kernel tree.
You are receiving this message because of the following common error(s) as indicated below:
- This looks like a new version of a previously submitted patch, but you did not list below the --- line any changes from the previous version. Please read the section entitled "The canonical patch format" in the kernel file, Documentation/process/submitting-patches.rst for what needs to be done here to properly describe this.
If you wish to discuss this problem further, or you have questions about how to resolve this issue, please feel free to respond to this email and Greg will reply once he has dug out from the pending patches received from other developers.
thanks,
greg k-h's patch email bot