summaryrefslogtreecommitdiffstats
path: root/src/socket_wrapper.c
Commit message (Collapse)AuthorAgeFilesLines
...
* swrap: trace the SOCKET_WRAPPER_PCAP_FILE locationStefan Metzmacher2020-03-191-0/+1
| | | | Signed-off-by: Stefan Metzmacher <metze@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Do not leak buf in swrap_sendmsg()socket_wrapper-1.2.3Andreas Schneider2019-03-211-0/+1
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Add missing NULL checks to socket_wrapper_dir()Andreas Schneider2019-03-211-0/+19
| | | | | | | | This return either malloc'ed memory or NULL. Make sure there is no problem. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Print a warning if SOCKET_WRAPPER_DIR is not setAndreas Schneider2019-03-211-0/+1
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Add paranoia NULL checksAndreas Schneider2019-03-211-0/+10
| | | | | | | csbuild complains about missing NULL checks here. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Fix strict aliasing issues in swrap_pcap_packet_init()Andreas Schneider2019-03-211-51/+61
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Fix "Value stored never used" warningAnoop C S2019-03-211-1/+0
| | | | | | Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Do not use FALL_THROUGH for empty case statementsAmitay Isaacs2019-03-061-2/+0
| | | | | Signed-off-by: Amitay Isaacs <amitay@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Fix a TODOAnoop C S2019-02-121-19/+54
| | | | | | | | Use realpath(3) instead of strncmp(3) Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Ralph Boehme <slow@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Add env variable to disable deep bindingAndreas Schneider2019-02-121-5/+15
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Use #ifdef instead of #if for config.h definitionsAndreas Schneider2019-01-111-6/+6
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Volker Lendecke <vl@samba.org>
* swrap: Add an overflow checkVolker Lendecke2019-01-111-0/+5
| | | | | Signed-off-by: Volker Lendecke <vl@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Do not log if we are over the limit in find_socket_info_index()Andreas Schneider2018-11-131-4/+16
| | | | | | | | | | | | | There are applications which do: for (fd = 0; fd <= getdtablesize(); fd++) { close(fd) }; This produced millions of error messsages. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Also log the fd in swrap_socket()Andreas Schneider2018-11-131-2/+3
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Fix comparison of different signednessAndreas Schneider2018-11-131-2/+2
| | | | | | | Found by csbuild. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Also log the process nameAndreas Schneider2018-11-131-2/+24
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Better handling for default values in socket_wrapper_max_sockets()Andreas Schneider2018-11-131-5/+15
| | | | | | | Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Always allocate the socket fd array to the maximumAndreas Schneider2018-11-131-9/+16
| | | | | | | | | | This will allow that we can deal with duplicates if the default value is used. Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Rename global variable for max socketsAndreas Schneider2018-11-131-6/+8
| | | | | | | | | We also need a mutex to protect access to it. Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Andreas Schneider <asn@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Protect IPv6 case in swrap_socket()Andreas Schneider2018-11-061-0/+2
| | | | | | | Fixes the build on OmniOS Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Fix coverity issuesAnoop C S2018-10-291-4/+2
| | | | | | | | | CID 184220 CID 184221 Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Don't do a deep bind if we run with libasanAndreas Schneider2018-10-231-1/+9
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Add a mutex for resetting socket indexAndreas Schneider2018-10-231-2/+22
| | | | | | | Fixes a helgrind error. Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Fix helgrind errorsAnoop C S2018-10-231-4/+32
| | | | | | Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* cmake: Suppress helgrind race condition warning we created on purposeAndreas Schneider2018-10-231-0/+6
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Ralph Boehme <slow@samba.org>
* swrap: Add error check around pthread mutex locksAnoop C S2018-08-091-52/+114
| | | | | | Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Fix thread deadlock found by Coverity scanAnoop C S2018-08-091-2/+4
| | | | | | | | | CID 175897 CID 175898 Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Update headerAndreas Schneider2018-08-091-4/+6
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Replace socket_fds linked list with an arrayAnoop C S2018-06-141-192/+122
| | | | | | | | | | | | | | | | | | | | | | | | | | | | | This fixes the following bug: As we are using a doubly linked list, we need a mutex which needs to be locked when we are reading it that we do not end up with invalid pointers. The following can happen: We are in swrap_close() which calls find_socket_info_fd() this locks the mutex for the linked list. Now we get a singal SIGCHILD and the signal handler is called. The signal handler calls swrap_write() and we try to find out if the socket is managed by socket_wrapper calling find_socket_info_fd() again -> DEADLOCK! By moving to an array to handle the socket fds and using the fd as the array access, we do not need a mutex for reading anymore. All we need is a memory barrier. This change also improves the performance as we move from the a linked list to a hash table! Pair-Programmed-With: Andreas Schneider <asn@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Update free-list only when refcount is zeroAnoop C S2018-05-021-5/+6
| | | | | | Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Move metadata into socket_info_meta structureMichael Adam2018-05-021-10/+16
| | | | | | | | | | | Separating out the metadata related information to another sub-structure to make it more clean and structured. Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Implement thread safety using pthread mutexesAnoop C S2018-05-021-38/+235
| | | | | | | | | | | | | | | | | | | Added a new mutex variable to socket_info structure along with new macros for locking and unlocking mutex corresponding to each socket_info entry. Apart from individual mutex defined in socket_info structure, 4 new mutexes are added to protect the concurrent access of globally used swrap parameters from different threads. All other individual wrappers and helper routines are also made capable of acquiring relevant mutex locks before operating on such global parameters. Pair-Programmed-With: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Rearrange swrap_remove_staleAnoop C S2018-05-021-6/+8
| | | | | | | | | In preparation to implement thread safety, re-ordering lines of code to properly align to lockign calls Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Rearrange swrap_closeAnoop C S2018-05-021-5/+6
| | | | | | | | | In preparation to implement thread safety, re-ordering lines of code to properly align to locking calls. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Remove swrap_first_free_indexAnoop C S2018-05-021-22/+0
| | | | | | | | | swrap_first_free_index is no longer used as the whole logic now implemented within swrap_create_socket. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Use swrap_create_socket within swrap_acceptAnoop C S2018-05-021-28/+12
| | | | | | | | | Replace the current logic of socket creation within swrap_accept with more cleaner version using swrap_create_socket. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Use swrap_create_socket within swrap_socketAnoop C S2018-05-021-27/+5
| | | | | | | | | Replace the current logic of socket creation within swrap_socket with more cleaner version using swrap_create_socket. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Add new routines to handle socket creationAnoop C S2018-05-021-0/+50
| | | | | | | | | | | A new function named swrap_create_socket is introduced which cleanly performs all stuff related to creation of new socket file descriptors and updation of relevant metadata including the free-list and reference counter. Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Internal reorganization of core socket_info structuresMichael Adam2018-05-021-14/+29
| | | | | | | | | | | | | | | | The change basically splits socket_info structure into two structures, namely, - socket_info: to store the core information corresponding to a socket entry. - socket_info_container: wrapping structure to hold the socket_info data as well as metadata(currently refcount and next_free). Pair-Programmed-With: Anoop C S <anoopcs@redhat.com> Signed-off-by: Michael Adam <obnox@samba.org> Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Reorder code inside swrap_socketMichael Adam2018-05-021-16/+18
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Use swrap_get_socket_info inside socket_wrapper_first_free_indexMichael Adam2018-05-021-3/+5
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: set errno to ENFILE if there is no more free socket_infoMichael Adam2018-05-021-2/+1
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: New helper functions to treat next_freeMichael Adam2018-05-021-10/+20
| | | | | | | | | | - swrap_get_next_free - swrap_set_next_free to avoid accessing socket_info.next_free directly Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Use helper functions to manage refcountAnoop C S2018-05-021-9/+24
| | | | | | | | | - swrap_get_refcount - swrap_alter_refcount Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Use helper function swrap_get_socket_infoAnoop C S2018-05-021-12/+20
| | | | | | Signed-off-by: Anoop C S <anoopcs@redhat.com> Reviewed-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Make early-libc-out more obvious by removing elseMichael Adam2018-05-021-1/+3
| | | | | Signed-off-by: Michael Adam <obnox@samba.org> Reviewed-by: Andreas Schneider <asn@samba.org>
* swrap: Avoid double semicolons in the codeAndreas Schneider2018-02-201-1/+1
| | | | | | | | Compilers that don't support fallthrough will end up with an empty FALL_THROUGH define and just see a semicolon. The probably will warn that there are double semicolons in the code. Signed-off-by: Andreas Schneider <asn@samba.org>
* swrap: Avoid symbol binding deadlocks during forkAndreas Schneider2017-12-041-15/+21
| | | | | | | | | | | | | | | | | | | | | | | If there is a signal handler defined, e.g. for SIGCHILD and this signal handler is called during pthread_atfork() has just locked all mutexes and we want to check if a symbol is bound, we end up in a deadlock. (gdb) bt 0 __lll_lock_wait () at ../sysdeps/unix/sysv/linux/x86_64/lowlevellock.S:135 1 0x00007fe48837aef5 in __GI___pthread_mutex_lock (mutex=0x7fe4889a71c0 <libc_symbol_binding_mutex>) at ../nptl/pthread_mutex_lock.c:80 2 0x00007fe48879b2f1 in libc_write (fd=14, buf=0x7ffdad6436e8, count=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:1070 3 0x00007fe4887a21cb in swrap_write (s=14, buf=0x7ffdad6436e8, len=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5137 4 0x00007fe4887a2359 in write (s=14, buf=0x7ffdad6436e8, len=8) at /home/asn/workspace/projects/socket_wrapper/src/socket_wrapper.c:5171 5 0x00007fe48713e5f2 in tevent_common_wakeup_fd (fd=14) at ../lib/tevent/tevent.c:959 6 0x00007fe48713e61f in tevent_common_wakeup (ev=ev@entry=0x55d04922e280) at ../lib/tevent/tevent.c:975 7 0x00007fe487141d38 in tevent_common_signal_handler (signum=<optimized out>) at ../lib/tevent/tevent_signal.c:109 8 <signal handler called> 9 0x00007fe4844de081 in __libc_fork () at ../sysdeps/nptl/fork.c:135 10 0x000055d047e8ddb3 in smbd_accept_connection (ev=0x55d04922e280, fde=<optimized out>, flags=<optimized out>, private_data=<optimized out>) at ../source3/smbd/server.c:992 Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Bind all symbols during prepareAndreas Schneider2017-12-041-7/+72
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
* swrap: Whitespace fixesAndreas Schneider2017-12-041-2/+2
| | | | | Signed-off-by: Andreas Schneider <asn@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>