Hello community, here is the log from the commit of package socket_wrapper for openSUSE:Factory checked in at 2020-06-23 21:01:36 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Comparing /work/SRC/openSUSE:Factory/socket_wrapper (Old) and /work/SRC/openSUSE:Factory/.socket_wrapper.new.2956 (New) ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Package is "socket_wrapper" Tue Jun 23 21:01:36 2020 rev:15 rq:816408 version:1.2.5 Changes: -------- --- /work/SRC/openSUSE:Factory/socket_wrapper/socket_wrapper.changes 2020-03-25 23:43:38.240000293 +0100 +++ /work/SRC/openSUSE:Factory/.socket_wrapper.new.2956/socket_wrapper.changes 2020-06-23 21:02:03.925353707 +0200 @@ -1,0 +2,6 @@ +Mon Jun 22 15:05:19 UTC 2020 - Andreas Schneider <[email protected]> + +- Update to version 1.2.5 + * https://gitlab.com/cwrap/socket_wrapper/-/blob/master/CHANGELOG + +------------------------------------------------------------------- Old: ---- socket_wrapper-1.2.4.tar.gz socket_wrapper-1.2.4.tar.gz.asc New: ---- socket_wrapper-1.2.5.tar.gz socket_wrapper-1.2.5.tar.gz.asc ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ Other differences: ------------------ ++++++ socket_wrapper.spec ++++++ --- /var/tmp/diff_new_pack.pMAbLY/_old 2020-06-23 21:02:05.609359126 +0200 +++ /var/tmp/diff_new_pack.pMAbLY/_new 2020-06-23 21:02:05.613359139 +0200 @@ -24,7 +24,7 @@ ############################# NOTE ################################## Name: socket_wrapper -Version: 1.2.4 +Version: 1.2.5 Release: 0 Summary: A library passing all socket communications trough Unix sockets License: BSD-3-Clause ++++++ socket_wrapper-1.2.4.tar.gz -> socket_wrapper-1.2.5.tar.gz ++++++ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/CHANGELOG new/socket_wrapper-1.2.5/CHANGELOG --- old/socket_wrapper-1.2.4/CHANGELOG 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/CHANGELOG 2020-06-22 17:00:42.000000000 +0200 @@ -1,6 +1,11 @@ ChangeLog ========== +version 1.2.5 (released 2020-06-22) + * Added basic support for TCP_INFO and SIOCOUTQ/TIOCOUTQ/FIONWRITE + * Add SOCKET_WRAPPER_DIR_ALLOW_ORIG and abort() early if + SOCKET_WRAPPER_DIR is unusable + version 1.2.4 (released 2020-03-24) * Added support for 10.53.57.0 network * Added _{socket,close,connect,...} symbols on FreeBSD diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/CMakeLists.txt new/socket_wrapper-1.2.5/CMakeLists.txt --- old/socket_wrapper-1.2.4/CMakeLists.txt 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/CMakeLists.txt 2020-06-22 17:00:42.000000000 +0200 @@ -11,7 +11,7 @@ include(DefineCMakeDefaults) include(DefineCompilerFlags) -project(socket_wrapper VERSION 1.2.4 LANGUAGES C) +project(socket_wrapper VERSION 1.2.5 LANGUAGES C) # global needed variables set(APPLICATION_NAME ${PROJECT_NAME}) @@ -25,7 +25,7 @@ # Increment PATCH. set(LIBRARY_VERSION_MAJOR 0) set(LIBRARY_VERSION_MINOR 1) -set(LIBRARY_VERSION_PATCH 14) +set(LIBRARY_VERSION_PATCH 15) set(LIBRARY_VERSION "${LIBRARY_VERSION_MAJOR}.${LIBRARY_VERSION_MINOR}.${LIBRARY_VERSION_PATCH}") set(LIBRARY_SOVERSION ${LIBRARY_VERSION_MAJOR}) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/ConfigureChecks.cmake new/socket_wrapper-1.2.5/ConfigureChecks.cmake --- old/socket_wrapper-1.2.4/ConfigureChecks.cmake 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/ConfigureChecks.cmake 2020-06-22 17:00:35.000000000 +0200 @@ -43,6 +43,7 @@ endif(CMAKE_COMPILER_IS_GNUCC AND NOT MINGW AND NOT OS2) # HEADERS +check_include_file(netinet/tcp_fsm.h HAVE_NETINET_TCP_FSM_H) check_include_file(sys/filio.h HAVE_SYS_FILIO_H) check_include_file(sys/signalfd.h HAVE_SYS_SIGNALFD_H) check_include_file(sys/eventfd.h HAVE_SYS_EVENTFD_H) diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/config.h.cmake new/socket_wrapper-1.2.5/config.h.cmake --- old/socket_wrapper-1.2.4/config.h.cmake 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/config.h.cmake 2020-06-22 17:00:35.000000000 +0200 @@ -9,6 +9,7 @@ /************************** HEADER FILES *************************/ +#cmakedefine HAVE_NETINET_TCP_FSM_H 1 #cmakedefine HAVE_SYS_FILIO_H 1 #cmakedefine HAVE_SYS_SIGNALFD_H 1 #cmakedefine HAVE_SYS_EVENTFD_H 1 diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/doc/socket_wrapper.1 new/socket_wrapper-1.2.5/doc/socket_wrapper.1 --- old/socket_wrapper-1.2.4/doc/socket_wrapper.1 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/doc/socket_wrapper.1 2020-06-22 17:00:35.000000000 +0200 @@ -1,7 +1,7 @@ '\" t .\" Title: socket_wrapper .\" Author: Samba Team -.\" Generator: DocBook XSL Stylesheets vsnapshot <http://docbook.sf.net/> +.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/> .\" Date: 2018-11-28 .\" Manual: \ \& .\" Source: \ \& @@ -157,6 +157,11 @@ .RS 4 This allows you to disable deep binding in socket_wrapper\&. This is useful for running valgrind tools or sanitizers like (address, undefined, thread)\&. .RE +.PP +\fBSOCKET_WRAPPER_DIR_ALLOW_ORIG\fR +.RS 4 +SOCKET_WRAPPER_DIR is resolved by socket_wrapper using realpath(3)\&. Given that Unix sockets are constructed relative to this directory, the resulting path can sometimes be too long to allow valid socket paths to be constructed due to length restrictions\&. Setting this variable (to any value) allows socket_wrapper to fall back to the original value of SOCKET_WRAPPER_DIR if realpath(3) makes it too long to be usable\&. +.RE .SH "EXAMPLE" .sp .if n \{\ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/doc/socket_wrapper.1.txt new/socket_wrapper-1.2.5/doc/socket_wrapper.1.txt --- old/socket_wrapper-1.2.4/doc/socket_wrapper.1.txt 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/doc/socket_wrapper.1.txt 2020-06-22 17:00:35.000000000 +0200 @@ -95,6 +95,16 @@ This allows you to disable deep binding in socket_wrapper. This is useful for running valgrind tools or sanitizers like (address, undefined, thread). +*SOCKET_WRAPPER_DIR_ALLOW_ORIG*:: + +SOCKET_WRAPPER_DIR is resolved by socket_wrapper using realpath(3). +Given that Unix sockets are constructed relative to this directory, +the resulting path can sometimes be too long to allow valid socket +paths to be constructed due to length restrictions. Setting this +variable (to any value) allows socket_wrapper to fall back to the +original value of SOCKET_WRAPPER_DIR if realpath(3) makes it too long +to be usable. + EXAMPLE ------- diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/src/socket_wrapper.c new/socket_wrapper-1.2.5/src/socket_wrapper.c --- old/socket_wrapper-1.2.4/src/socket_wrapper.c 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/src/socket_wrapper.c 2020-06-22 17:00:35.000000000 +0200 @@ -66,6 +66,9 @@ #include <sys/un.h> #include <netinet/in.h> #include <netinet/tcp.h> +#ifdef HAVE_NETINET_TCP_FSM_H +#include <netinet/tcp_fsm.h> +#endif #include <arpa/inet.h> #include <fcntl.h> #include <stdlib.h> @@ -264,6 +267,7 @@ int defer_connect; int pktinfo; int tcp_nodelay; + int listening; /* The unix path so we can unlink it on close() */ struct sockaddr_un un_addr; @@ -658,7 +662,7 @@ handle = swrap.libc.handle = swrap.libc.socket_handle = RTLD_NEXT; #else SWRAP_LOG(SWRAP_LOG_ERROR, - "Failed to dlopen library: %s\n", + "Failed to dlopen library: %s", dlerror()); exit(-1); #endif @@ -677,7 +681,7 @@ func = dlsym(handle, fn_name); if (func == NULL) { SWRAP_LOG(SWRAP_LOG_ERROR, - "Failed to find %s: %s\n", + "Failed to find %s: %s", fn_name, dlerror()); exit(-1); @@ -1221,7 +1225,7 @@ ret = inet_pton(AF_INET, net_str, &nv); if (ret <= 0) { SWRAP_LOG(SWRAP_LOG_ERROR, - "INVALID IPv4 Network [%s]\n", + "INVALID IPv4 Network [%s]", net_str); abort(); } @@ -1238,7 +1242,7 @@ default: SWRAP_LOG(SWRAP_LOG_ERROR, "INVALID IPv4 Network [%s][0x%x] should be " - "127.0.0.0 or 10.53.57.0\n", + "127.0.0.0 or 10.53.57.0", net_str, (unsigned)hv); abort(); } @@ -1268,7 +1272,7 @@ if (iface == 0 || iface > MAX_WRAPPED_INTERFACES) { SWRAP_LOG(SWRAP_LOG_ERROR, - "swrap_ipv4_iface(%u) invalid!\n", + "swrap_ipv4_iface(%u) invalid!", iface); abort(); return -1; @@ -1370,13 +1374,72 @@ sic->meta.next_free = next_free; } +static int swrap_un_path(struct sockaddr_un *un, + const char *swrap_dir, + char type, + unsigned int iface, + unsigned int prt) +{ + int ret; + + ret = snprintf(un->sun_path, + sizeof(un->sun_path), + "%s/"SOCKET_FORMAT, + swrap_dir, + type, + iface, + prt); + if ((size_t)ret >= sizeof(un->sun_path)) { + return ENAMETOOLONG; + } + + return 0; +} + +static int swrap_un_path_EINVAL(struct sockaddr_un *un, + const char *swrap_dir) +{ + int ret; + + ret = snprintf(un->sun_path, + sizeof(un->sun_path), + "%s/EINVAL", + swrap_dir); + + if ((size_t)ret >= sizeof(un->sun_path)) { + return ENAMETOOLONG; + } + + return 0; +} + +static bool swrap_dir_usable(const char *swrap_dir) +{ + struct sockaddr_un un; + int ret; + + ret = swrap_un_path(&un, swrap_dir, SOCKET_TYPE_CHAR_TCP, 0, 0); + if (ret == 0) { + return true; + } + + ret = swrap_un_path_EINVAL(&un, swrap_dir); + if (ret == 0) { + return true; + } + + return false; +} + static char *socket_wrapper_dir(void) { char *swrap_dir = NULL; char *s = getenv("SOCKET_WRAPPER_DIR"); + char *t; + bool ok; if (s == NULL) { - SWRAP_LOG(SWRAP_LOG_WARN, "SOCKET_WRAPPER_DIR not set\n"); + SWRAP_LOG(SWRAP_LOG_WARN, "SOCKET_WRAPPER_DIR not set"); return NULL; } @@ -1385,9 +1448,43 @@ SWRAP_LOG(SWRAP_LOG_ERROR, "Unable to resolve socket_wrapper dir path: %s", strerror(errno)); - return NULL; + abort(); + } + + ok = swrap_dir_usable(swrap_dir); + if (ok) { + goto done; + } + + free(swrap_dir); + + ok = swrap_dir_usable(s); + if (!ok) { + SWRAP_LOG(SWRAP_LOG_ERROR, "SOCKET_WRAPPER_DIR is too long"); + abort(); + } + + t = getenv("SOCKET_WRAPPER_DIR_ALLOW_ORIG"); + if (t == NULL) { + SWRAP_LOG(SWRAP_LOG_ERROR, + "realpath(SOCKET_WRAPPER_DIR) too long and " + "SOCKET_WRAPPER_DIR_ALLOW_ORIG not set"); + abort(); + } + swrap_dir = strdup(s); + if (swrap_dir == NULL) { + SWRAP_LOG(SWRAP_LOG_ERROR, + "Unable to duplicate socket_wrapper dir path"); + abort(); + } + + SWRAP_LOG(SWRAP_LOG_WARN, + "realpath(SOCKET_WRAPPER_DIR) too long, " + "using original SOCKET_WRAPPER_DIR\n"); + +done: SWRAP_LOG(SWRAP_LOG_TRACE, "socket_wrapper_dir: %s", swrap_dir); return swrap_dir; } @@ -1631,7 +1728,7 @@ static void set_socket_info_index(int fd, int idx) { SWRAP_LOG(SWRAP_LOG_TRACE, - "fd=%d idx=%d\n", + "fd=%d idx=%d", fd, idx); socket_fds_idx[fd] = idx; /* This builtin issues a full memory barrier. */ @@ -1641,7 +1738,7 @@ static void reset_socket_info_index(int fd) { SWRAP_LOG(SWRAP_LOG_TRACE, - "fd=%d idx=%d\n", + "fd=%d idx=%d", fd, -1); set_socket_info_index(fd, -1); } @@ -1844,7 +1941,7 @@ b_type = SOCKET_TYPE_CHAR_UDP; break; default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!"); errno = ESOCKTNOSUPPORT; return -1; } @@ -1891,7 +1988,7 @@ type = SOCKET_TYPE_CHAR_UDP_V6; break; default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!"); errno = ESOCKTNOSUPPORT; return -1; } @@ -1914,13 +2011,13 @@ } #endif default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family!"); errno = ENETUNREACH; return -1; } if (prt == 0) { - SWRAP_LOG(SWRAP_LOG_WARN, "Port not set\n"); + SWRAP_LOG(SWRAP_LOG_WARN, "Port not set"); errno = EINVAL; return -1; } @@ -1932,16 +2029,14 @@ } if (is_bcast) { - snprintf(un->sun_path, sizeof(un->sun_path), - "%s/EINVAL", swrap_dir); + swrap_un_path_EINVAL(un, swrap_dir); SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path); SAFE_FREE(swrap_dir); /* the caller need to do more processing */ return 0; } - snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, - swrap_dir, type, iface, prt); + swrap_un_path(un, swrap_dir, type, iface, prt); SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path); SAFE_FREE(swrap_dir); @@ -1987,7 +2082,7 @@ b_type = SOCKET_TYPE_CHAR_UDP; break; default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!"); errno = ESOCKTNOSUPPORT; return -1; } @@ -2046,7 +2141,7 @@ type = SOCKET_TYPE_CHAR_UDP_V6; break; default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!"); errno = ESOCKTNOSUPPORT; return -1; } @@ -2087,7 +2182,7 @@ } #endif default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family"); errno = EADDRNOTAVAIL; return -1; } @@ -2109,8 +2204,7 @@ if (prt == 0) { /* handle auto-allocation of ephemeral ports */ for (prt = 5001; prt < 10000; prt++) { - snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, - swrap_dir, type, iface, prt); + swrap_un_path(un, swrap_dir, type, iface, prt); if (stat(un->sun_path, &st) == 0) continue; set_port(si->family, prt, &si->myname); @@ -2126,8 +2220,7 @@ } } - snprintf(un->sun_path, sizeof(un->sun_path), "%s/"SOCKET_FORMAT, - swrap_dir, type, iface, prt); + swrap_un_path(un, swrap_dir, type, iface, prt); SWRAP_LOG(SWRAP_LOG_DEBUG, "un path [%s]", un->sun_path); SAFE_FREE(swrap_dir); @@ -2329,7 +2422,7 @@ case SOCK_DGRAM: break; default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!"); errno = ESOCKTNOSUPPORT; return -1; } @@ -2343,7 +2436,7 @@ } errno = EAFNOSUPPORT; - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family"); return -1; } @@ -2374,7 +2467,7 @@ case SOCK_DGRAM: break; default: - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown socket type!"); errno = ESOCKTNOSUPPORT; return -1; } @@ -2387,7 +2480,7 @@ break; } - SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family\n"); + SWRAP_LOG(SWRAP_LOG_ERROR, "Unknown address family"); errno = EAFNOSUPPORT; return -1; } @@ -3719,9 +3812,11 @@ for (i = 0; i < SOCKET_MAX_SOCKETS; i++) { port = autobind_start + i; - snprintf(un_addr.sa.un.sun_path, sizeof(un_addr.sa.un.sun_path), - "%s/"SOCKET_FORMAT, swrap_dir, type, - socket_wrapper_default_iface(), port); + swrap_un_path(&un_addr.sa.un, + swrap_dir, + type, + socket_wrapper_default_iface(), + port); if (stat(un_addr.sa.un.sun_path, &st) == 0) continue; ret = libc_bind(fd, &un_addr.sa.s, un_addr.sa_socklen); @@ -3787,7 +3882,7 @@ if (si->family != serv_addr->sa_family) { SWRAP_LOG(SWRAP_LOG_ERROR, - "called for fd=%d (family=%d) called with invalid family=%d\n", + "called for fd=%d (family=%d) called with invalid family=%d", s, si->family, serv_addr->sa_family); errno = EINVAL; ret = -1; @@ -4097,6 +4192,9 @@ } ret = libc_listen(s, backlog); + if (ret == 0) { + si->listening = 1; + } out: SWRAP_UNLOCK_SI(si); @@ -4446,6 +4544,56 @@ ret = 0; goto done; #endif /* TCP_NODELAY */ +#ifdef TCP_INFO + case TCP_INFO: { + struct tcp_info info; + socklen_t ilen = sizeof(info); + +#ifdef HAVE_NETINET_TCP_FSM_H +/* This is FreeBSD */ +# define __TCP_LISTEN TCPS_LISTEN +# define __TCP_ESTABLISHED TCPS_ESTABLISHED +# define __TCP_CLOSE TCPS_CLOSED +#else +/* This is Linux */ +# define __TCP_LISTEN TCP_LISTEN +# define __TCP_ESTABLISHED TCP_ESTABLISHED +# define __TCP_CLOSE TCP_CLOSE +#endif + + ZERO_STRUCT(info); + if (si->listening) { + info.tcpi_state = __TCP_LISTEN; + } else if (si->connected) { + /* + * For now we just fake a few values + * supported both by FreeBSD and Linux + */ + info.tcpi_state = __TCP_ESTABLISHED; + info.tcpi_rto = 200000; /* 200 msec */ + info.tcpi_rtt = 5000; /* 5 msec */ + info.tcpi_rttvar = 5000; /* 5 msec */ + } else { + info.tcpi_state = __TCP_CLOSE; + info.tcpi_rto = 1000000; /* 1 sec */ + info.tcpi_rtt = 0; + info.tcpi_rttvar = 250000; /* 250 msec */ + } + + if (optval == NULL || optlen == NULL || + *optlen < (socklen_t)ilen) { + errno = EINVAL; + ret = -1; + goto done; + } + + *optlen = ilen; + memcpy(optval, &info, ilen); + + ret = 0; + goto done; + } +#endif /* TCP_INFO */ default: break; } @@ -4578,7 +4726,7 @@ { struct socket_info *si = find_socket_info(s); va_list ap; - int value; + int *value_ptr = NULL; int rc; if (!si) { @@ -4593,14 +4741,34 @@ switch (r) { case FIONREAD: - value = *((int *)va_arg(ap, int *)); + if (rc == 0) { + value_ptr = ((int *)va_arg(ap, int *)); + } if (rc == -1 && errno != EAGAIN && errno != ENOBUFS) { swrap_pcap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0); - } else if (value == 0) { /* END OF FILE */ + } else if (value_ptr != NULL && *value_ptr == 0) { /* END OF FILE */ swrap_pcap_dump_packet(si, NULL, SWRAP_PENDING_RST, NULL, 0); } break; +#ifdef FIONWRITE + case FIONWRITE: + /* this is FreeBSD */ + FALL_THROUGH; /* to TIOCOUTQ */ +#endif /* FIONWRITE */ + case TIOCOUTQ: /* same as SIOCOUTQ on Linux */ + /* + * This may return more bytes then the application + * sent into the socket, for tcp it should + * return the number of unacked bytes. + * + * On AF_UNIX, all bytes are immediately acked! + */ + if (rc == 0) { + value_ptr = ((int *)va_arg(ap, int *)); + *value_ptr = 0; + } + break; } va_end(ap); @@ -5529,9 +5697,11 @@ } for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) { - snprintf(un_addr.sa.un.sun_path, - sizeof(un_addr.sa.un.sun_path), - "%s/"SOCKET_FORMAT, swrap_dir, type, iface, prt); + swrap_un_path(&un_addr.sa.un, + swrap_dir, + type, + iface, + prt); if (stat(un_addr.sa.un.sun_path, &st) != 0) continue; /* ignore the any errors in broadcast sends */ @@ -6038,8 +6208,7 @@ } for(iface=0; iface <= MAX_WRAPPED_INTERFACES; iface++) { - snprintf(un_addr.sun_path, sizeof(un_addr.sun_path), "%s/"SOCKET_FORMAT, - swrap_dir, type, iface, prt); + swrap_un_path(&un_addr, swrap_dir, type, iface, prt); if (stat(un_addr.sun_path, &st) != 0) continue; msg.msg_name = &un_addr; /* optional address */ diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/tests/echo_srv.c new/socket_wrapper-1.2.5/tests/echo_srv.c --- old/socket_wrapper-1.2.4/tests/echo_srv.c 2020-03-24 13:29:41.000000000 +0100 +++ new/socket_wrapper-1.2.5/tests/echo_srv.c 2020-06-22 17:00:35.000000000 +0200 @@ -9,6 +9,10 @@ #include <arpa/inet.h> #include <netinet/in.h> +#include <netinet/tcp.h> +#ifdef HAVE_NETINET_TCP_FSM_H +#include <netinet/tcp_fsm.h> +#endif #include <netdb.h> #include <resolv.h> @@ -315,6 +319,34 @@ perror("listen"); return ret; } +#ifdef TCP_INFO + { + struct tcp_info info; + socklen_t optlen = sizeof(info); + + ZERO_STRUCT(info); + ret = getsockopt(sock, IPPROTO_TCP, TCP_INFO, &info, &optlen); + if (ret == -1) { + ret = errno; + perror("TCP_INFO failed"); + close(sock); + return ret; + } +#ifdef HAVE_NETINET_TCP_FSM_H +/* This is FreeBSD */ +# define __TCP_LISTEN TCPS_LISTEN +#else +/* This is Linux */ +# define __TCP_LISTEN TCP_LISTEN +#endif + if (info.tcpi_state != __TCP_LISTEN) { + errno = ret = ERANGE; + perror("not __TCP_LISTEN => ERANGE..."); + close(sock); + return ret; + } + } +#endif /* TCP_INFO */ } *_sock = sock; diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/tests/test_echo_tcp_socket_options.c new/socket_wrapper-1.2.5/tests/test_echo_tcp_socket_options.c --- old/socket_wrapper-1.2.4/tests/test_echo_tcp_socket_options.c 2018-11-13 17:47:01.000000000 +0100 +++ new/socket_wrapper-1.2.5/tests/test_echo_tcp_socket_options.c 2020-06-22 17:00:35.000000000 +0200 @@ -11,12 +11,25 @@ #include <sys/socket.h> #include <netinet/in.h> #include <netinet/tcp.h> +#ifdef HAVE_NETINET_TCP_FSM_H +#include <netinet/tcp_fsm.h> +#endif #include <arpa/inet.h> #include <netdb.h> #include <stdlib.h> #include <stdio.h> #include <unistd.h> +#ifdef HAVE_NETINET_TCP_FSM_H +/* This is FreeBSD */ +# define __TCP_ESTABLISHED TCPS_ESTABLISHED +# define __TCP_CLOSE TCPS_CLOSED +#else +/* This is Linux */ +# define __TCP_ESTABLISHED TCP_ESTABLISHED +# define __TCP_CLOSE TCP_CLOSE +#endif + #ifndef ZERO_STRUCT #define ZERO_STRUCT(x) memset((char *)&(x), 0, sizeof(x)) #endif @@ -300,6 +313,9 @@ .sa_socklen = sizeof(struct sockaddr_in), }; int opt = -1; +#ifdef TCP_INFO + struct tcp_info info; +#endif socklen_t optlen = sizeof(int); int rc; @@ -318,9 +334,27 @@ &addr.sa.in.sin_addr); assert_int_equal(rc, 1); +#ifdef TCP_INFO + ZERO_STRUCT(info); + optlen = sizeof(info); + rc = getsockopt(s, IPPROTO_TCP, TCP_INFO, &info, &optlen); + assert_return_code(rc, errno); + assert_int_equal(optlen, sizeof(info)); + printf("info.tcpi_state=0x%x\n", info.tcpi_state); + printf("info.tcpi_rto=%u\n", info.tcpi_rto); + printf("info.tcpi_rtt=%u\n", info.tcpi_rtt); + printf("info.tcpi_rttvar=%u\n", info.tcpi_rttvar); + assert_int_equal(info.tcpi_state, __TCP_CLOSE); + assert_int_not_equal(info.tcpi_rto, 0); + assert_int_equal(info.tcpi_rtt, 0); + assert_int_not_equal(info.tcpi_rttvar, 0); +#endif /* TCP_INFO */ + rc = connect(s, &addr.sa.s, addr.sa_socklen); assert_int_equal(rc, 0); + opt = -1; + optlen = sizeof(int); rc = getsockopt(s, IPPROTO_TCP, TCP_NODELAY, &opt, &optlen); assert_return_code(rc, errno); assert_int_equal(opt, 0); @@ -336,6 +370,22 @@ assert_return_code(rc, errno); assert_int_equal(opt, 1); +#ifdef TCP_INFO + ZERO_STRUCT(info); + optlen = sizeof(info); + rc = getsockopt(s, IPPROTO_TCP, TCP_INFO, &info, &optlen); + assert_return_code(rc, errno); + assert_int_equal(optlen, sizeof(info)); + printf("info.tcpi_state=0x%x\n", info.tcpi_state); + printf("info.tcpi_rto=%u\n", info.tcpi_rto); + printf("info.tcpi_rtt=%u\n", info.tcpi_rtt); + printf("info.tcpi_rttvar=%u\n", info.tcpi_rttvar); + assert_int_equal(info.tcpi_state, __TCP_ESTABLISHED); + assert_int_not_equal(info.tcpi_rto, 0); + assert_int_not_equal(info.tcpi_rtt, 0); + assert_int_not_equal(info.tcpi_rttvar, 0); +#endif /* TCP_INFO */ + close(s); } diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' '--exclude=.svnignore' old/socket_wrapper-1.2.4/tests/torture.c new/socket_wrapper-1.2.5/tests/torture.c --- old/socket_wrapper-1.2.4/tests/torture.c 2018-11-19 17:17:13.000000000 +0100 +++ new/socket_wrapper-1.2.5/tests/torture.c 2020-06-20 10:22:40.000000000 +0200 @@ -255,8 +255,7 @@ void torture_teardown_echo_srv(void **state) { struct torture_state *s = *state; - char buf[8] = {0}; - long int tmp; + char buf[12] = {0}; /* -2147483648 + null byte */ ssize_t rc; pid_t pid; int fd; @@ -277,13 +276,12 @@ buf[sizeof(buf) - 1] = '\0'; - tmp = strtol(buf, NULL, 10); - if (tmp == 0 || tmp > 0xFFFF || errno == ERANGE) { + errno = 0; + pid = strtol(buf, NULL, 10); + if (pid == 0 || errno != 0) { goto done; } - pid = (pid_t)(tmp & 0xFFFF); - for (count = 0; count < 10; count++) { /* Make sure the daemon goes away! */ kill(pid, SIGTERM);
