summaryrefslogtreecommitdiff
path: root/lib/tsocket
Commit message (Collapse)AuthorAgeFilesLines
* lib:tsocket: Fix code spellingAndreas Schneider2023-04-142-4/+4
| | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* tsocket: Increase tcp_user_timeout max_loopsAndrew Bartlett2023-03-141-1/+1
| | | | | | | | | | | | | | Often, on rackspace GitLab CI runners, we get: UNEXPECTED(failure): samba.unittests.tsocket_tstream.test_tstream_more_tcp_user_timeout_spin(none) REASON: Exception: Exception: 0xf == 0xf ../../lib/tsocket/tests/test_tstream.c:405: error: Failure! This allows us more spins before we fail the test. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15328 Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Joseph Sutton <josephsutton@catalyst.net.nz>
* lib/tsocket: fix a typo in the tsocket guide docBjörn Baumbach2023-01-171-1/+1
| | | | | | | | Signed-off-by: Björn Baumbach <bb@sernet.de> Reviewed-by: Ralph Boehme <slow@samba.org> Autobuild-User(master): Björn Baumbach <bb@sernet.de> Autobuild-Date(master): Tue Jan 17 18:23:18 UTC 2023 on sn-devel-184
* tsocket: Fix the build on FreeBSDVolker Lendecke2022-12-122-21/+36
| | | | | | | FreeBSD does not have TCP_USER_TIMEOUT Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/tsocket: avoid endless cpu-spinning in tstream_bsd_fde_handler()Stefan Metzmacher2022-10-191-5/+116
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | | There were some reports that strace output an LDAP server socket is in CLOSE_WAIT state, returning EAGAIN for writev over and over (after a call to epoll() each time). In the tstream_bsd code the problem happens when we have a pending writev_send, while there's no readv_send pending. In that case we still ask for TEVENT_FD_READ in order to notice connection errors early, so we try to call writev even if the socket doesn't report TEVENT_FD_WRITE. And there are situations where we do that over and over again. It happens like this with a Linux kernel: tcp_fin() has this: struct tcp_sock *tp = tcp_sk(sk); inet_csk_schedule_ack(sk); sk->sk_shutdown |= RCV_SHUTDOWN; sock_set_flag(sk, SOCK_DONE); switch (sk->sk_state) { case TCP_SYN_RECV: case TCP_ESTABLISHED: /* Move to CLOSE_WAIT */ tcp_set_state(sk, TCP_CLOSE_WAIT); inet_csk_enter_pingpong_mode(sk); break; It means RCV_SHUTDOWN gets set as well as TCP_CLOSE_WAIT, but sk->sk_err is not changed to indicate an error. tcp_sendmsg_locked has this: ... err = -EPIPE; if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) goto do_error; while (msg_data_left(msg)) { int copy = 0; skb = tcp_write_queue_tail(sk); if (skb) copy = size_goal - skb->len; if (copy <= 0 || !tcp_skb_can_collapse_to(skb)) { bool first_skb; new_segment: if (!sk_stream_memory_free(sk)) goto wait_for_space; ... wait_for_space: set_bit(SOCK_NOSPACE, &sk->sk_socket->flags); if (copied) tcp_push(sk, flags & ~MSG_MORE, mss_now, TCP_NAGLE_PUSH, size_goal); err = sk_stream_wait_memory(sk, &timeo); if (err != 0) goto do_error; It means if (sk->sk_err || (sk->sk_shutdown & SEND_SHUTDOWN)) doesn't hit as we only have RCV_SHUTDOWN and sk_stream_wait_memory returns -EAGAIN. tcp_poll has this: if (sk->sk_shutdown & RCV_SHUTDOWN) mask |= EPOLLIN | EPOLLRDNORM | EPOLLRDHUP; So we'll get EPOLLIN | EPOLLRDNORM | EPOLLRDHUP triggering TEVENT_FD_READ and writev/sendmsg keeps getting EAGAIN. So we need to always clear TEVENT_FD_READ if we don't have readable handler in order to avoid burning cpu. But we turn it on again after a timeout of 1 second in order to monitor the error state of the connection. And now that our tsocket_bsd_error() helper checks for POLLRDHUP, we can check if the socket is in an error state before calling the writable handler when TEVENT_FD_READ was reported. Only on error we'll call the writable handler, which will pick the error without calling writev(). BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib/tsocket: remember the first error as tstream_bsd->errorStefan Metzmacher2022-10-191-0/+39
| | | | | | | | | | If we found that the connection is broken, there's no point in trying to use it anymore, so just return the first error we detected. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib/tsocket: check for errors indicated by poll() before getsockopt(fd, ↵Stefan Metzmacher2022-10-191-1/+79
| | | | | | | | | | | | | | | SOL_SOCKET, SO_ERROR) This also returns an error if we got TCP_FIN from the peer, which is only reported by an explicit POLLRDHUP check. Also on FreeBSD getsockopt(fd, SOL_SOCKET, SO_ERROR) fetches and resets the error, so a 2nd call no longer returns an error. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib/tsocket: split out tsocket_bsd_error() from tsocket_bsd_pending()Stefan Metzmacher2022-10-191-19/+23
| | | | | | | | | This will be used on its own soon. BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* lib/tsocket: Add tests for loop on EAGAINAndrew Bartlett2022-10-194-0/+641
| | | | | | | | | BUG: https://bugzilla.samba.org/show_bug.cgi?id=15202 Pair-Programmed-With: Stefan Metzmacher <metze@samba.org> Signed-off-by: Andrew Bartlett <abartlet@samba.org> Signed-off-by: Stefan Metzmacher <metze@samba.org>
* selftest: test tsocket_address_inet_from_hostport_stringsUri Simchoni2021-09-281-0/+143
| | | | | | | | Signed-off-by: Uri Simchoni <uri@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Tue Sep 28 10:34:12 UTC 2021 on sn-devel-184
* selftest: add more tests for test_address_inet_from_stringsUri Simchoni2021-09-281-0/+43
| | | | | | | Test the case of NULL address as input Signed-off-by: Uri Simchoni <uri@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib/tsocket: new function to parse host port strs.Matthew Grant2021-09-282-0/+143
| | | | | | | | | | | | | | | | | | tsocket_address_inet_from_hostport_strings() on top of tsocket_address_inet_from_strings(), implementing the ability to parse a port number appended to an IPv6 or IPv4 address. IPv6 addresses can also optionally have square brackets around them, but these are needed to specify the port number as colon is used to delimit port from the IP address in the string. Note that this code just recognises and parses the strings with port given, or just IPv6 with square brackets. The rest of the parsing is passed on to tsocket_address_inet_from strings(), and errors from there passed back up the stack. Signed-off-by: Matthew Grant <grantma@mattgrant.net.nz> Reviewed-by: Uri Simchoni <uri@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib/tsocket: Fix build on FreebsdAmitay Isaacs2021-09-161-0/+2
| | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the following build error on freebsd. [1567/3959] Compiling lib/tsocket/tsocket_bsd.c ../../lib/tsocket/tsocket_bsd.c:415:8: error: use of undeclared identifier 'EAI_ADDRFAMILY' case EAI_ADDRFAMILY: ^ On FreeBSD EAI_ADDRFAMILY is obsoleted. Here's the relevant excerpt from netdb.h on FreeBSD 13. ----------------------------------------------------------------- /* * Error return codes from gai_strerror(3), see RFC 3493. */ #if 0 /* Obsoleted on RFC 2553bis-02 */ #define EAI_ADDRFAMILY 1 /* address family for hostname not supported */ #endif ----------------------------------------------------------------- Signed-off-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Uri Simchoni <uri@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Sep 16 19:42:19 UTC 2021 on sn-devel-184
* tsocket: set errno on some failures of tsocket_address_inet_from_stringsUri Simchoni2021-09-131-0/+2
| | | | | | | | | | | Fix setting errno on all failure modes of tsocket_address_inet_from_strings. Signed-off-by: Uri Simchoni <uri@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Sep 13 22:27:59 UTC 2021 on sn-devel-184
* selftest: add a unit test for tsocket_address_inet_from_stringsUri Simchoni2021-09-132-0/+189
| | | | | Signed-off-by: Uri Simchoni <uri@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/tsocket: Free subreq as soon as possibleSamuel Cabrero2021-07-081-0/+1
| | | | | | | | | | | This is not a memory leak as it is freed when the parent req's state is freed, but will help in low memory situations. Signed-off-by: Samuel Cabrero <scabrero@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Thu Jul 8 10:21:25 UTC 2021 on sn-devel-184
* tsocket: Fix a few typosVolker Lendecke2021-01-141-3/+3
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Samuel Cabrero <scabrero@samba.org>
* tsocket: Fix a typoVolker Lendecke2020-06-151-1/+1
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* Rename macro argument s_addr due to it already being definedPeter Eriksson2020-02-282-7/+7
| | | | | | Signed-off-by: Peter Eriksson <pen@lysator.liu.se> Reviewed-by: Jeremy Allison <jra@samba.org> Reviewed-by: Andrew Bartlett <abartlet@samba.org>
* lib/tsocket: add a comment regarding TEVENT_FD_READ in ↵Stefan Metzmacher2020-02-261-0/+8
| | | | | | | | | | tstream_bsd_connect_send() This is different compared to the raw usage of [e]poll where [E]POLLOUT is enough to see errors via POLLERR/POLLHUP. Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* Spelling fixes s/implentation/implementation/Mathieu Parent2019-09-011-1/+1
| | | | | | Signed-off-by: Mathieu Parent <math.parent@gmail.com> Reviewed-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz>
* lib:tsocket: New function to build a tsocket_context from samba_addressSamuel Cabrero2019-07-222-0/+39
| | | | | Signed-off-by: Samuel Cabrero <scabrero@suse.de> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* s3:utils: New struct to fix strict aliasing issues with sockets APISamuel Cabrero2019-07-221-59/+47
| | | | | Signed-off-by: Samuel Cabrero <scabrero@suse.de> Reviewed-by: Andreas Schneider <asn@samba.org>
* tsocket: Simplify tsocket.hVolker Lendecke2019-03-221-1/+0
| | | | | | | tevent.h already includes talloc.h Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib:tsocket: Check for DOXYGEN as a #defineAndreas Schneider2018-12-171-1/+1
| | | | | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Gary Lockyer <gary@catalyst.net.nz> Autobuild-User(master): Gary Lockyer <gary@samba.org> Autobuild-Date(master): Mon Dec 17 00:10:10 CET 2018 on sn-devel-144
* tsocket: Fix typosVolker Lendecke2018-01-041-2/+2
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* tsocket: Do not dereference a NULL pointerAndreas Schneider2016-06-301-4/+8
| | | | | | | | | | | | | | | Make sure the lrbsda pointer is not allocated and we will not end up dereferencing a NULL pointer. In practice this can't happen, but this change links the pointer with the code that uses it. Found by Coverity. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Thu Jun 30 02:53:02 CEST 2016 on sn-devel-144
* lib/tsocket: workaround sockets not supporting FIONREADRalph Boehme2016-02-101-1/+61
| | | | | | | | | | | | | | | | | | Netlink sockets don't support querying pending bytes with ioctl(fd, FIONREAD, ...) and would return EOPNOTSUPP, so use recvmsg() with MSG_PEEK|MSG_TRUNC as a fallback. The MSG_TRUNC flag to recvmsg() is Linux only, but netlink is as well, so we're safe for now. Bug: https://bugzilla.samba.org/show_bug.cgi?id=11714 Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Amitay Isaacs <amitay@gmail.com> Reviewed-by: Martin Schwenke <martin@meltin.net> Autobuild-User(master): Ralph Böhme <slow@samba.org> Autobuild-Date(master): Wed Feb 10 10:30:24 CET 2016 on sn-devel-144
* lib/tsocket: fix non-blockging connect() error handlingRalph Boehme2015-10-211-8/+5
| | | | | | | | | Non-blockging connect() either returns immediate success, or -1 with errno EINPROGESS as indication that the connection is pending. All other errnos indicate immediate failure. Signed-off-by: Ralph Boehme <slow@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* Fix a typoVolker Lendecke2015-06-191-2/+2
| | | | | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Ira Cooper <ira@samba.org> Autobuild-User(master): Volker Lendecke <vl@samba.org> Autobuild-Date(master): Fri Jun 19 01:05:17 CEST 2015 on sn-devel-104
* lib/tsocket: add tdgram_inet_udp_broadcast_socket()Stefan Metzmacher2015-06-122-0/+59
| | | | | | | | | | | This is similar to tdgram_inet_udp_socket(), but it allows the use of ipv4 broadcast traffic. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* lib/tsocket: add tdgram_bsd_existing_socket() helper functionStefan Metzmacher2015-06-122-0/+66
| | | | | | | | | | | | This is similar to tstream_bsd_existing_socket(). Both help to migrate strange code path to using the tstream or tdgram abstractions. BUG: https://bugzilla.samba.org/show_bug.cgi?id=11316 Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* tsocket: Use common code in tsocket_bsd_common_prepare_fdVolker Lendecke2015-06-052-30/+8
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: "Stefan (metze) Metzmacher" <metze@samba.org>
* tsocket: Use iov_advanceVolker Lendecke2015-02-242-51/+18
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* tsocket: Fix a typoVolker Lendecke2015-02-241-1/+1
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org>
* tsocket: Pass the full port number to getaddrinfo().Andreas Schneider2013-07-011-1/+1
| | | | | | | | | | The code stripped port numbers above 9999 down to 4 digits. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Mon Jul 1 21:10:53 CEST 2013 on sn-devel-104
* tsocket: Add some constVolker Lendecke2013-06-142-3/+3
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* tsocket: ENOMEM can be retried on illumos/Solaris.Ira Cooper2013-03-131-0/+6
| | | | | | | | | | The writev system call can return -1 and errno ENOMEM, as a retriable condition. Reviewed-by: Jeremy Allison <jra@samba.org> Autobuild-User(master): Jeremy Allison <jra@samba.org> Autobuild-Date(master): Wed Mar 13 23:50:05 CET 2013 on sn-devel-104
* tsocket_bsd: Attempt to increase the SO_SNDBUF if we get EMSGSIZE in sendto()Andrew Bartlett2013-03-041-0/+26
| | | | | | | | | | | | | | This matches what was done for lib/socket/socket_unix.c in c692bb02b039ae8fef6ba968fd13b36ad7d62a72. (and is based on that patch by Landon Fuller <landonf@bikemonkey.org>) Andrew Bartlett Reviewed-by: Stefan Metzmacher <metze@samba.org> Autobuild-User(master): Stefan Metzmacher <metze@samba.org> Autobuild-Date(master): Mon Mar 4 11:15:35 CET 2013 on sn-devel-104
* lib/tsocket: optimize syscalls in tstream_readv_pdu_send()Stefan Metzmacher2012-11-051-0/+29
| | | | | | | Once we've got the first part of a pdu we try to optimize readv calls for the rest of the pdu. Signed-off-by: Stefan Metzmacher <metze@samba.org>
* lib/tsocket: disable the syscall optimization for recvfrom/readv by defaultStefan Metzmacher2012-11-052-6/+109
| | | | | | | | | We only do the optimization on recvfrom/readv if the caller asked for it. This is needed because in most cases we preferr to flush send buffers before receiving incoming requests. Signed-off-by: Stefan Metzmacher <metze@samba.org>
* lib/tsocket: fix loop in tdgram_bsd_recvfrom() (bug #9184)Stefan Metzmacher2012-10-231-1/+9
| | | | | | | | | | | | | If the socket is not readable yet, we need to retry if tsocket_bsd_pending() returns 0. See also https://lists.samba.org/archive/samba-technical/2012-October/087164.html metze Autobuild-User(master): Andrew Bartlett <abartlet@samba.org> Autobuild-Date(master): Tue Oct 23 14:44:21 CEST 2012 on sn-devel-104
* lib/tsocket: fix receiving of udp packets from 0 bytes (bug #9184)Stefan Metzmacher2012-09-221-4/+1
| | | | | | | | | It's possible for a client to send 0 bytes in a UDP packet, we need still need to call recvfrom() and skip the invalid packet at a higher level. Otherwise the kernel receive queue is blocked. metze
* tsocket: Fix a couple of typos and spellings in tsocket_guide.txtMichael Adam2012-04-171-26/+27
| | | | | Autobuild-User: Michael Adam <obnox@samba.org> Autobuild-Date: Tue Apr 17 14:41:53 CEST 2012 on sn-devel-104
* tsocket: make use of tevent_queue_add_optimize_empty() to optimize for the ↵Stefan Metzmacher2011-08-101-37/+48
| | | | | | empty queue case metze
* Use tevent_req_oomVolker Lendecke2011-06-201-3/+3
| | | | This fixes a few Coverity errors
* tsocket: fill in sa.sa_len if the system supports itStefan Metzmacher2010-11-051-0/+12
| | | | metze
* s4: Remove the old perl/m4/make/mk-based build system.Jelmer Vernooij2010-10-311-13/+0
| | | | | | | | The new waf-based build system now has all the same functionality, and the old build system has been broken for quite some time. Autobuild-User: Jelmer Vernooij <jelmer@samba.org> Autobuild-Date: Sun Oct 31 02:01:44 UTC 2010 on sn-devel-104
* tsocket: let tstream_inet_tcp_connect_recv() optionally return the used ↵Stefan Metzmacher2010-10-232-5/+11
| | | | | | | | | | | | local address tstream_inet_tcp_connect_send() usually only gets no local port number and it may use the wildcard address '0.0.0.0' or '::'. tstream_inet_tcp_connect_recv() provides the used local address and port which are used on the wire. metze
* tsocket: ask the kernel for the specific local address after a tcp connectStefan Metzmacher2010-10-231-3/+54
| | | | metze