0
0
mirror of https://github.com/zeromq/libzmq.git synced 2024-12-31 01:43:02 +08:00

2729 Commits

Author SHA1 Message Date
Simon Giesecke
cef9cfa091
Revert "Problem: mis-detection of threadsafe_static_init causes test failures" 2018-03-07 15:03:07 +01:00
Luca Boccassi
9bd2d3f937 Problem: mis-detection of threadsafe_static_init causes test failures
Solution: do not rely __cplusplus >= 201103L to detect whether the
compiler supports thread safe static initialisation, but check only
the proper feature preprocessor macro.
GCC introduced it in version 8, and Clang in version 6.
2018-03-06 23:11:03 +00:00
Luca Boccassi
e0b1992dd7 Problem: build broken with gcc-4.7
Solution: initialise variable in options.cpp to dummy value to fix
compiler complaint:

 src/options.cpp: In function
  'int zmq::do_setsockopt_int_as_bool_strict(const void*, size_t, bool*)':
 src/options.cpp:121:5: error: 'value' may be used uninitialized in
  this function [-Werror=maybe-uninitialized]
 src/options.cpp: In function
  'int zmq::do_setsockopt_int_as_bool_relaxed(const void*, size_t, bool*)':
 src/options.cpp:135:31: error: 'value' may be used uninitialized in
  this function [-Werror=maybe-uninitialized]
2018-03-06 20:29:47 +00:00
Luca Boccassi
ec58ba04f3
Merge pull request #2972 from sigiesec/reduce-sockopt-code-duplication
Problem: code duplication in getsockopt/setsockopt
2018-03-06 20:08:46 +00:00
Simon Giesecke
6f967c3a13 Problem: code duplication in getsockopt/setsockopt
Solution: extracted common code into do_getsockopt/do_setsockopt functions
2018-03-06 16:41:30 +01:00
Luca Boccassi
10d2b2885e
Merge pull request #2971 from ZMQers/fix-static-init
Problem: static initialization order fiasco
2018-03-06 09:18:52 +00:00
Luca Boccassi
541ca30d8e Problem: make clang-format still shows error in the CI
Solution: run make clang-format-diff and commit the changes.
2018-03-05 22:41:11 +00:00
Luca Boccassi
4ea1e78d9d
Merge pull request #2969 from skaes/master
Problem: enormous memory increase due to zero copy decoding
2018-03-05 17:40:33 +00:00
Stefan Kaes
fcbd2a5710 Problem: enormous memory increase due to zero copy decoding
The zero copy decoding strategy implemented for 4.2.0 can lead to a large
increase of main memory usage in some cases (I have seen one program go up to
40G from 10G after upgrading from 4.1.4). This commit adds a new option to
contexts, called ZMQ_ZERO_COPY_RECV, which allows one to switch to the old
decoding strategy.
2018-03-05 18:13:28 +01:00
Ryan Hileman
3658b2b580 Problem: pthread condvar timeouts are broken (#2967)
* fix pthread condvar timeouts

This fixes a race condition / hang for threadsafe sockets.
Context: https://github.com/zeromq/czmq/issues/1873#issuecomment-370279244
2018-03-05 16:36:10 +00:00
Simon Giesecke
8cdfc8b9dd Problem: static initialization order fiasco
Solution: use local statics when available in a thread-safe implementation
2018-03-05 16:30:57 +01:00
Simon Giesecke
9cd01bb54f Problem: inconsistent return values from mtrie_t::rm
Solution: Return an enum from rm instead of a bool, and adapt existing uses
2018-03-02 13:42:50 +01:00
Simon Giesecke
36cdcc6c1a Problem: docs of mtrie referring to subscriptions and pipes
Solution: generalized terms to entries/values
2018-03-02 13:42:47 +01:00
Simon Giesecke
5d5def40b5 Problem: casts required due to void* arguments in a C++ class
Solution: introduce a type template argument
2018-03-02 13:42:42 +01:00
Simon Giesecke
5fb0e97ab7 Problem: semantic issues
Solution: added some TODO comments, improved existing documentation
2018-03-02 13:42:31 +01:00
Simon Giesecke
a9712c0bf2 Problem: no unittests for mtrie
Solution: made mtrie generic (to remove complex dependency on pipe_t),
and added some unit tests
2018-03-02 13:32:51 +01:00
Simon Giesecke
9fc3692e3f Problem: read-only arguments of mtrie are not declared as const
Solution: add const, introduce typedef
2018-03-02 13:32:50 +01:00
Romain Geissler
1e03f7b2d4 Fix gcc 8 build warning/error with -O3. 2018-02-27 10:12:22 +01:00
Pontus Sköldström
78aa9b1983 Support addressing TIPC Port Identity
ZeroMQ currently supports location independent addressing using TIPC
Port Names with tipc://{type,instance}. This commits adds support for
connecting and binding using TIPC Port Identity addresses. To connect
using Port Identities the expected format is tipc://<Z.C.N:Ref>, e.g.
"tipc://<1.2.3:123123>". To bind using TIPC Port Identities the expected
format is "tipc://<*>".
2018-02-19 17:34:40 +01:00
Kachanovskiy
e10464e45e Fix for build break when SIO_LOOPBACK_FAST_PATH is not defined (i.e. in VS2010) 2018-02-13 23:04:08 +01:00
Simon Giesecke
94743fd21f Problem: wrong formatting in several files
Solution: apply clang-format
2018-02-13 18:40:43 +01:00
Simon Giesecke
90c6d993be Problem: kqueue_t fails unittest_poller
Solution: fix shutdown of kqueue_t
2018-02-13 18:38:30 +01:00
Simon Giesecke
3b90ad8c63 Problem: support of std::atomic is incomplete in VS <2015
Solution: use std::atomic only from VS 2015
2018-02-13 18:38:29 +01:00
Simon Giesecke
96131b5b4e Problem: no documentation of the poller concept
Solution: added documentation
2018-02-13 18:38:25 +01:00
Simon Giesecke
a8e9032dc5 Problem: unreachable code in io_thread_t::process_stop
Solution: replaced by assertion
2018-02-13 18:38:24 +01:00
Simon Giesecke
a5738529e8 Problem: wsa_assert does not include error code
Solution: extend output of wsa_assert
2018-02-13 18:38:22 +01:00
Simon Giesecke
e8e24030ea Problem: network initialization and shutdown functions not available for
reuse

Solution: extract into functions defined in ip.hpp

Problem: signaler_t::make_fdpair not reusable

Solution: move make_fdpair to ip.hpp

Problem: epoll worker with no fds cannot be stopped

Solution: use interruptible epoll_pwait call

Problem: insufficient unit tests for poller

Solution: add test cases
2018-02-13 18:38:17 +01:00
Simon Giesecke
c62574ffca Problem: segfault in select_t::trigger_events
Solution: fixed access to stale vector
2018-02-12 14:42:46 +01:00
Simon Giesecke
11a5388637 Problem: data race w.r.t. select_t::stopping
Solution: change termination condition of select_t
2018-02-12 14:42:33 +01:00
Simon Giesecke
e650240580 Problem: data race w.r.t. poll_t::stopping
Solution: remove stopping, stop on thread-safe conditions; add
additional checks for correct thread-safe usage
2018-02-12 14:41:53 +01:00
Simon Giesecke
08201bc1b9 Problem: select blocks forever under Unix
Solution: fixed call of select, and initialization of poll_t members
2018-02-12 14:39:02 +01:00
Luca Boccassi
a30133d8f5
Merge pull request #2935 from ZMQers/unity-base
Problem: no test framework, no unit tests
2018-02-12 11:01:08 +00:00
Luca Boccassi
d0e01b4bb2 Problem: regression with "select" on *nix (#2940)
* Problem: build failure with select as polling mechanism

Solution: cast mailbox_handle argument to (poller_t::handle_t) like in
the reaper thread class.

* Problem: build failure due to INT_MAX use without include

Solution: include limits and climits in src/select.cpp where INT_MAX is
used

* Problem: build failure due to unused variable in select.cpp

Solution: move the declaration of int rc inside the ifdef block where
it is actually used

* Problem: reference to wrong variable in select.cpp breaks build

Solution: fix it

* Problem: family_entry_t constructor has no body, build fails on *nix

Solution: add empty inline function in the struct

* Problem: no test coverage for poll and select

Solution: add Travis jobs for them on Linux

* Problem: Travis jobs cannot run in container infra

Solution: set sudo: false as it is not required anymore
2018-02-12 03:01:03 -05:00
Simon Giesecke
7ea924c763 Problem: segfault on thread_t::stop if thread was never started
Solution: add started flag
2018-02-11 17:25:36 +00:00
Simon Giesecke
f87d3ab294 Problem: pollers unnecessarily depend on whole ctx_t, but actually use only start_thread method
Solution: extract thread_ctx_t from ctx_t
2018-02-11 17:25:36 +00:00
Simon Giesecke
5873894c83 Problem: wrong assertion macro used on Windows
Solution: use wsa_assert instead of errno_assert
2018-02-11 13:52:41 +01:00
Simon Giesecke
2f27bcd74b Problem: assertion failure in poll_t::poll if timer_event retired a
pollset entry

Solution: clean up retired entries before poll
2018-02-11 13:49:26 +01:00
Simon Giesecke
a2af3d18cc Problem: unittest_poller fails for poll_t
Solution: fixed behaviour in corner cases
2018-02-11 13:49:25 +01:00
Luca Boccassi
c33cb38af2
Merge pull request #2928 from eponsko/master
Add support for ZMQ_XPUB_NODROP on ZMQ_RADIO sockets
2018-02-09 17:15:47 +00:00
Pontus Sköldström
a57f7e3824 Add support for ZMQ_XPUB_NODROP on ZMQ_RADIO sockets
Solves issue #2927
2018-02-09 16:20:50 +01:00
Simon Giesecke
a5e763039d Problem: use of TCP loopback fastpath not available for user sockets
Solution: add socket option
2018-02-09 14:22:42 +01:00
sigiesec
490d76da2f Problem: SIO_LOOPBACK_FAST_PATH not activated for signaler socket pair
Solution: activate SIO_LOOPBACK_FAST_PATH if available

See #2899
2018-02-09 13:50:40 +01:00
sigiesec
88d8c768d1 Problem: test_timers frequently fails on travis-ci
Solution: relaxed test assertions, based on the actual time passed,
instead of assuming that this equals to the time slept
2018-02-09 09:55:40 +01:00
Simon Giesecke
3baefc66ea Problem: incomplete assertions around modifications of fd_entries vs.
load

Solution: add assertions, partially in debug build only, improved naming
2018-02-09 09:53:02 +01:00
Simon Giesecke
a1d55d0506 Problem: race conditions for options.linger (#2910)
* Problem: race conditions for options.linger

Solution: make options.linger atomic
2018-02-08 22:10:45 +00:00
Simon Giesecke
de0c669323 Problem: std::atomic not used on Visual C++ although it is available (#2930)
* Problem: std::atomic not used on Visual C++ although it is available

Solution: change conditional compilation to recognize _MSC_VER
2018-02-08 22:01:02 +00:00
Luca Boccassi
cdfc6bb8b3
Merge pull request #2924 from sigiesec/tcp-cleanup
Problem: duplicated code, redundant member handle_valid, asymmetry between tcp_connecter and tcp_listener
2018-02-08 21:57:46 +00:00
Luca Boccassi
9fbd125b41
Merge pull request #2917 from ZMQers/thread-safe-simplification
Problem: code duplication and unnecessary nesting around ZMQ_THREAD_SAFE querying
2018-02-08 21:57:06 +00:00
sigiesec
147fe9ed77 Problem: code duplication and unnecessary nesting around ZMQ_THREAD_SAFE
querying

Solution: remove code duplication and rearrange conditions
2018-02-08 22:54:30 +01:00
Luca Boccassi
cb9ccfa154
Merge pull request #2921 from sigiesec/mechanism-cleanup
Problem: code style issues in mechanism_t and socket_base_t
2018-02-08 21:53:14 +00:00
Luca Boccassi
2e849a4d60
Merge pull request #2913 from ZMQers/add-const
Problem: several fields are non-const without need
2018-02-08 21:47:21 +00:00
Simon Giesecke
2c2ea82789 Problem: duplicated code, redundant member handle_valid, asymmetry between
tcp_connecter and tcp_listener

Solution: remove duplication and redundant member, align handling of
handle in tcp_connecter and tcp_listener
2018-02-08 22:20:01 +01:00
sigiesec
06d805ff82 Problem: unnecessary complex operations in socket_base_t::term_endpoint
Solution: use simpler operations, construct std::string only once
2018-02-08 22:19:54 +01:00
sigiesec
9a6993adce Problem: several code style issues in mechanism_t: code and data duplication,
unnecessary construction of temporary std::string

Solution: removed duplication, removed construction of std::string
2018-02-08 22:19:54 +01:00
sigiesec
368eff9ecb Problem: several fields are non-const without need
Solution: add const where easily possible
2018-02-08 22:17:03 +01:00
sigiesec
5b510656d0 Problem: unreachable code around socket_base_t::add/remove_signaler
Solution: replaced by assertion
2018-02-08 22:16:30 +01:00
sigiesec
41f459e1dc Problem: formatting inconsistent
Solution: applied clang-format
2018-02-02 15:47:43 +01:00
Pontus Sköldström
542fe67f25 Problem: ZMQ_DISH triggers assert when hitting the watermark(?)
Solves issue #2907 by checking whether the msg already has a group
2018-02-02 14:01:45 +01:00
sigiesec
206c832167 Problem: in case of exhausted resources on creation of a context, assertions are triggered
Solution: signal error to caller, and apply appropriate cleanup
2018-01-31 20:53:06 +01:00
Simon Giesecke
7488be61c2 Problem: add_fd might be called with fd_ == retired_fd
Solution: add assertion
2018-01-25 16:03:43 +01:00
Bill Torpey
ec05166545 prevent duplicate connections from PUB sockets also (see https://github.com/zeromq/libzmq/issues/788) 2017-12-29 14:36:59 -05:00
evoskuil
9622984241 Problem: vc++ 11.0 (vs 2012) compile fails on move semantics. 2017-12-14 14:58:02 -08:00
evoskuil
8d78e08f71 Problem: fn pointers are not bool (vc++ warning C4550). 2017-12-14 12:47:38 -08:00
Jasper Lievisse Adriaanse
22b57f6f28 Problem: Build is broken on OpenBSD
Solution: re-instate block for OpenBSD erroneously removed in 9622a830
2017-12-14 09:47:49 +01:00
Luca Boccassi
ac552ba448 Problem: accept4 not available on all platforms
Solution: check for availability in CMake and autoconf before using it
2017-11-18 11:33:53 +00:00
ccpaging
e8ad51e62f Clean code for Visual Studio 2008 compiler 2017-11-16 14:09:13 +08:00
Rolf Timmermans
c8592dfbc3 Problem: REQ socket with ZMQ_REQ_RELAXED does not report ZMQ_POLLOUT when queried for events after first message.
Solution: Check for strictness before returning false if no reply has been received.
2017-11-08 09:55:14 +01:00
Anton Bärwald
630f6d6ae7 Problem: On OSX usleep() changes the errno value
Solution: Update errno value after calling usleep()
2017-11-02 16:01:11 +01:00
sigiesec
f9d7eea6f9 Problem: code duplication
Solution: unified Windows & non-Windows code further
2017-10-26 11:05:39 +02:00
sigiesec
e7817ad38d Problem: code duplication
Solution: reduced code duplication by introducing local variables and
new function trigger_events
2017-10-26 10:47:05 +02:00
sigiesec
37914d1be2 Problem: get_fd_family call is expensive and called frequently for the
same fds

Solution: cache results of get_fd_family
2017-10-26 09:46:11 +02:00
sigiesec
cd32603c0e Problem: wsa_events are initialized/destroyed within every loop
iteration even if not used

Solution: Move wsa_events closer to usage
2017-10-25 18:30:03 +02:00
f18m
2aa0e6fd4d Change ZMQ_THREAD_AFFINITY to ZMQ_THREAD_AFFINITY_CPU_ADD/ZMQ_THREAD_AFFINITY_CPU_REMOVE. Avoid prefix thread names when no prefix was set. 2017-10-25 09:55:47 +02:00
Yann Diorcet
81327af557 Partial Windows XP support 2017-10-24 13:12:34 +02:00
Simon Giesecke
7ec58b279a Problem: one missed optimization opportunity for blob_t map lookup
Solution: create referencing blob_t
2017-10-23 11:12:15 +02:00
Simon Giesecke
a4aceb272b Problem: use of std::map::insert is inefficient
Solution: use std::map::emplace instead, where available
2017-10-22 17:15:00 +02:00
Simon Giesecke
0897b3e07b Problem: excessive memory allocations around blob_t (#2796)
* Problem: excessive memory allocations around blob_t

Solution: redefine blob_t as a custom type, and use reference/move
semantics where possible
2017-10-21 12:19:51 +01:00
sigiesec
cfb2129557 Problem: comment before sndtimeo/rcvtimeo does not specify dimension
Solution: add "milliseconds"
2017-10-18 15:04:54 +02:00
f18m
f25cd6e7be Background thread names (#2784)
* Add ZMQ_THREAD_NAME_PREFIX ctx option
2017-10-17 12:06:50 +01:00
f18m
bfbb4ff2e9 Background threads enhancements (#2778)
* Background thread scheduling 

- add ZMQ_THREAD_AFFINITY ctx option; set all thread scheduling options
from the context of the secondary thread instead of using the main
process thread context!
- change ZMQ_THREAD_PRIORITY to support setting NICE of the background
thread when using SCHED_OTHER
2017-10-16 12:29:03 +01:00
Luca Boccassi
b6aee51691 Problem: strict ZAP protocol adherence is backward incompatible
Solution: add ZMQ_ZAP_ENFORCE_DOMAIN to hide backward incompatible
change and make it disabled by default.
In a future release that breaks API compatibility we can then switch
the default to enabled in order to achieve full RFC compatibility.

Fixes #2762
2017-10-09 17:48:33 +01:00
Luca Boccassi
50bddbaac9 Problem: dead code in options.hpp
Solution: remove unused zap_ipc_creds boolean variable
2017-10-09 13:52:56 +01:00
Luca Boccassi
e3ee55b191 Problem: missing indentation for UDP branch
Solution: fix it
2017-10-09 13:52:56 +01:00
Luca Boccassi
c8f3f8a5da Problem: ambiguos bitwise ANDs in if statements
Solution: wrap bitwise ANDs in brackets as the static analyzer suggests
2017-10-09 13:52:56 +01:00
Luca Boccassi
7ad06f1449 Problem: IPC event_closed logs -1 as the FD
Solution: take a copy of the file descriptor before setting it to
retired_fd.
2017-10-06 09:53:59 +01:00
Luca Boccassi
9be8cebd21 Merge pull request #2765 from GreatFruitOmsk/issue-2764
Problem: Race condition in IPC sockets
2017-10-06 09:25:33 +01:00
Ilya Kulakov
656cdb959a Problem: Race condition in IPC sockets
Solution: Don't unlink file on close

File may not belong to the socket at that point.
2017-10-05 14:57:10 -07:00
Christopher Hall
997825bdf1 add __FreeBSD__ to ifdefs
On FreeBSD the sysmbol __FreeBSD_kernel__ is only defines if a
specific param.h file is included, unlike Debian/kFreeBSD where this
symbol is always defined.  So also compile the FreeBSD specific code
if __FreeBSD__ is defined for FreeBSD 11 & 12 compatibility.

Signed-off-by: Christopher Hall <hsw@ms2.hinet.net>
2017-10-03 15:30:42 +08:00
Luca Boccassi
44f96a3652 Merge pull request #2745 from sigiesec/rename-identity
Problem: term "identity" is confusing
2017-09-20 10:08:45 +02:00
sigiesec
2c8a7223b8 Problem: remaining use of "identity"
Solution: replaced by "routing id"
2017-09-19 17:55:00 +02:00
sigiesec
7e3f4b1d32 Problem: ZMTP protocol broken w.r.t. Identity property
Solution: differentiate propertly between ZMTP property names and ZeroMQ API property names
2017-09-19 17:55:00 +02:00
sigiesec
a5e3a65ae2 Problem: inconsistency between zmq.h and zmq_draft.h
Solution: fix zmq_draft.h
2017-09-19 17:55:00 +02:00
sigiesec
4b821d8f84 Problem: remaining uses of "identity"
Solution: replaced by "routing id"
2017-09-19 17:54:59 +02:00
sigiesec
fab57634b4 Problem: Message metadata properties still refer to "identity"
Solution: Renamed, but support querying the property by its old name
2017-09-19 17:53:53 +02:00
sigiesec
27c7e52a5a Problem: Usage of "rid" in server_t
Solution: Replaced by "routing_id"
2017-09-19 17:53:53 +02:00
sigiesec
41bae55af7 Problem: inconsistent naming related to routing ids
Solution: renamed routing_id fields in pipe_t, renamed ZMQ_CONNECT_RID to ZMQ_CONNECT_ROUTING_ID
2017-09-19 17:53:53 +02:00
sigiesec
9e7507b38b Problem: term "identity" is confusing
Solution: replace by "routing id"
2017-09-19 17:53:44 +02:00
Luca Boccassi
edb4ca1023 Problem: zmq_connect fails after disconnect due to RECONNECT_IVL == -1
Solution: when a connection breaks and ZMQ_RECONNECT_IVL is set to -1,
which means a reconnection will not be attempted, send a message from
the I/O thread to the application thread to make the socket call
term_endpoint, which is the equivalent of manually calling
zmq_disconnect.
This way subsequent zmq_connect call to the same endpoint will attempt
again to do a connection.
Otherwise, for some socket types like SUBs, those new connects will
fail as the endpoint is recorded, despite the connection having been
permanently closed.

Add test cases to exercise this corner case with TCP and IPC.
2017-09-19 14:05:43 +01:00
sigiesec
e546f9296e Problem: duplicated code & inconsistent behaviour between
mechanisms

Solution: uniformly require a ZAP domain to be set to activate ZAP
handling, clarify comment on Stonehouse pattern
2017-09-18 17:01:38 +02:00
sigiesec
a5f94cb610 Problem: tests without ZAP handler are failing
Solution: emit events as expected by tests, and refuse connections when
ZAP is required but no handler started

Addresses #2711 partially
2017-09-18 12:58:09 +02:00
Luca Boccassi
5de2a82be8 Merge pull request #2744 from msune/refactor_poller_wait
Problem: duplicated socket_poller::wait() code
2017-09-13 00:48:26 +02:00
Marc Sune
5b92989540 Problem: duplicated socket_poller::wait() code
zmq::socket_poller_t::wait() had an important set of common lines
between POLL and SELECT variant.

Solution: refactor zmq::socket_poller_t::wait() and add the
following methods:

zmq::socket_poller_t::zero_trail_events()
zmq::socket_poller_t::check_events()
zmq::socket_poller_t::adjust_timeout()

Signed-off-by: Marc Sune <mardevel@gmail.com>
2017-09-12 21:47:57 +02:00
Doron Somech
af03241dcb Revert "Problem: term "identity" is confusing" 2017-09-07 15:47:43 +03:00
sigiesec
deae59dca9 Problem: Message metadata properties still refer to "identity"
Solution: Renamed, but support querying the property by its old name
2017-09-07 10:33:25 +02:00
sigiesec
ae2ea1a655 Problem: Usage of "rid" in server_t
Solution: Replaced by "routing_id"
2017-09-07 10:33:25 +02:00
sigiesec
e00131dd43 Problem: inconsistent naming related to routing ids
Solution: renamed routing_id fields in pipe_t, renamed ZMQ_CONNECT_RID to ZMQ_CONNECT_ROUTING_ID
2017-09-07 10:33:13 +02:00
sigiesec
1daf83079a Problem: term "identity" is confusing
Solution: replace by "routing id"
2017-09-06 17:45:56 +02:00
Luca Boccassi
4fac78ec31 Problem: proxy stat 5th multipart message treated as 1st
Solution: fix it
2017-09-06 08:27:29 +01:00
Luca Boccassi
d7da31ed25 Problem: typo in comment in proxy.cpp
Solution: fix it
2017-09-06 08:27:17 +01:00
Luca Boccassi
b8695a47b5 Problem: proxy_steerable STATISTICS returns conflated buffers
Solution: split each stat into its own frame, to make it simpler and
easier to use it, especially from high level bindings
2017-09-06 01:28:28 +01:00
Luca Boccassi
78c4d33600 Problem: new STATISTICS proxy_steerable not behind DRAFT
Solution: ifdef it until it's declared stable
2017-09-05 17:37:52 +01:00
f18m
4be9513443 Add "STATISTICS" command to zmq_proxy_steerable() (#2737)
* Issue #2736: Add STATISTICS command to zmq_proxy_steerable()
2017-09-05 17:05:04 +01:00
Luca Boccassi
f4b32aa792 Merge pull request #2734 from pavel-pimenov/fix-v1001
Variable is assigned but is not used until the end of the function
2017-09-04 15:25:43 +01:00
pavel.pimenov
0e8bf3520c V728 An excessive check 'options.mechanism == 0' can be simplified.
The '||' operator is surrounded by opposite expressions. session_base.cpp 377
2017-09-04 15:25:31 +03:00
pavel.pimenov
51ac7d28c5 V1001 The 'ptr' variable is assigned but is not used until the end of the function. 2017-09-04 15:15:35 +03:00
Luca Boccassi
8feed48bb9 Problem: switch statements without breaks
Solution: add /* FALLTHROUGH */ comments so that nagging compilers
don't nag
2017-09-01 20:01:15 +01:00
Luca Boccassi
31089326fb Problem: unused variables warnings in get_peer_state
Solution: wrap arguments with LIBZMQ_UNUSED
2017-09-01 19:57:00 +01:00
Luca Boccassi
31e3977ab9 Merge pull request #2731 from sigiesec/fix-issue-2723
Problem: assertion in src\select.cpp:111 on Windows or hang on zmq_ctx_destroy
2017-09-01 19:51:39 +01:00
sigiesec
79e28af4ce Problem: new function zmq_socket_get_peer_state not in zmq_draft.h
Solution: added function to zmq_draft.h
2017-09-01 17:15:23 +02:00
sigiesec
48a1e637b6 Problem: zmq_socket_get_peer_state is not implemented
Solution: add initial implementation
2017-09-01 16:28:58 +02:00
sigiesec
f4d139bd16 Problem: duplicated code in socket-related functions
Solution: extract as_socket_base_t function
2017-09-01 16:28:58 +02:00
sigiesec
efa86fe629 Problem: no test case using the proposed zmq_socket_get_peer_state function
Solution: added test case (with dummy implementation of zmq_socket_get_peer_state)
2017-09-01 16:28:58 +02:00
sigiesec
23e018f37a Problem: termination is requested from a session's owner when already in
pending termination while processing an error

Solution: terminate pipe instead

Fixes #2723
2017-09-01 11:55:31 +02:00
sigiesec
eb8105cde1 Problem: assertion failure in select.cpp:111 under Windows
Solution: handle case when get_fd_family fails
2017-09-01 11:55:31 +02:00
bjovke
91e0d689bb Problem: Inconsistent size_t/int usage. Solution: types corrected. 2017-08-28 15:03:46 +02:00
Jim Klimov
40a3b0746f Problem: cosmetic setThreadName() can be fatal
Solution: do not assert() the values returned; if we failed to set the thread name - we just have harder debugging, not flawed production conditions.
Closes github issue #2679

Signed-off-by: Jim Klimov <EvgenyKlimov@eaton.com>
2017-08-25 15:30:03 +02:00
sigiesec
6147e45a07 Problem: missing tests for zmq_timers_* corner cases, missing handling of such corner cases, code duplication, missing assertions in test code
Solution: add tests, add checks to timers_t, add match_by_id functor, add assertions
2017-08-23 09:41:34 +02:00
sigiesec
f685a3ffd2 Solution: unreachable code paths in socket_poller_t
Problem: replaced by assertions resp. removed
2017-08-22 21:23:09 +02:00
sigiesec
a71f7b0405 Problem: zmq_poller_* uses ETIMEDOUT (instead of the usual EAGAIN) to indicate timeouts
Solution: replace ETIMEDOUT within socket_poller_t and all client code by EAGAIN

Fixes #2713
2017-08-22 20:00:29 +02:00
sigiesec
6a3c053a3e Problem: EFAULT is returned for bad file descriptors passed to zmq_poller_*_fd
Solution: Return EBADF instead
2017-08-22 19:43:56 +02:00
sigiesec
74303b08e6 Problem: calling zmq_poller_wait* with NULL events causes an assertion, as opposed to other NULL arguments, which return an error
Solution: return EFAULT when such an operation is attempted
2017-08-22 19:43:56 +02:00
sigiesec
c1a4cfdd9f Problem: waiting on an empty poller with infinite timeout waits forever
Solution: return EFAULT when such an operation is attempted
2017-08-22 19:43:56 +02:00
sigiesec
2e4fc4faf0 Problem: zmq_poller_*_fd functions do not check for invalid fd
Solution: add checks, added test cases
2017-08-22 19:28:07 +02:00
sigiesec
c3c2515542 Problem: code duplication within zmq::select_t::rm_fd
Solution: extract find_fd_entry_by_handle from rm_fd
2017-08-21 14:36:50 +02:00
sigiesec
bd0675b93f Problem: no tests for client-side events for successful handshake and authentication failure in handshake
Solution: added tests for CURVE, add emitting of client-side event in curve_client_t; add ZAP code 300/500 tests for all mechanisms; suppress sending an error message for ZAP code 300
2017-08-20 22:45:14 +02:00
Luca Boccassi
f6ce019fff Problem: incompatible parameter passed to send_zap_request
Solution: cast from void* to uint8_t* to match new definition
2017-08-19 17:40:15 +01:00
Luca Boccassi
7c85bf2f88 Problem: uninitialised variables in gssapi_server constructor
Solution: initialise session and peer_address
2017-08-19 17:40:15 +01:00
Luca Boccassi
2ba0149ee4 Problem: gssapi_mechanism_base_t initialisation misses one param
Solution: pass the session as well as the options
2017-08-19 17:40:15 +01:00
Luca Boccassi
83c9c0b55f Problem: gssapi_client does not have a peer_address param
Solution: remove it from the gssapi_mechanism_base initialiser
2017-08-19 17:40:15 +01:00
Luca Boccassi
24b2f61b1b Problem: gssapi_server out of date with zap_client
Solution: remove local unused zap_client variable
2017-08-19 17:40:15 +01:00
Luca Boccassi
c8097af884 Problem: DRAFT GSSAPI socket options in wrong section cause duplication
Solution: move them together with the other DRAFT socket options, and
change value of DRAFT ZMQ_BINDTODEVICE from 90 to 92 to avoid clash
2017-08-19 17:40:15 +01:00
Luca Boccassi
6f49e40e36 Problem: gssapi_mechanism_base does not include mechanism_base
Solution: include mechanism_base.hpp instead of mechanism.hpp
2017-08-19 17:40:15 +01:00
Luca Boccassi
e2ffa2a77b Problem: produce_ready in gssapi_mechanism_base not deduped
Solution: call make_command_with_basic_properties
2017-08-19 17:40:15 +01:00
Luca Boccassi
90b6c102bb Problem: various unused variables warnings
Solution: use LIBZMQ_UNUSED where necessary
2017-08-19 12:18:51 +01:00
Luca Boccassi
7be3efc936 Problem: TODO in gssapi mechanism
Solution: remove it.
Looking at the code:

https://github.com/krb5/krb5/blob/master/src/lib/gssapi/mechglue/g_unseal.c#L55

gss_unwrap as the very first thing checks that plaintext is not a
null pointer, which in our case it's true given it's on the stack,
and then initialises its members to 0 length and null ptr.

https://github.com/krb5/krb5/blob/master/src/lib/gssapi/mechglue/g_rel_buffer.c#L36

So it should be safe to release it in all cases, and the release API
seems to check again if it's not a null pointer and then if the
members are 0 length and null pointer it's a no-op.
2017-08-18 15:58:35 +01:00
Luca Boccassi
77444e206c Problem: free on stack variable in GSSAPI mechanism
Solution: free wrapper.value instead of wrapper.
2017-08-18 15:57:51 +01:00
sigiesec
898691e2eb Problem: gssapi_mechanism_base_t aborts the application when it receives a message it cannot decode
Solution: emit an ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL event instead of using zmq_assert
2017-08-18 12:29:37 +02:00
sigiesec
301f3c70c2 Problem: code duplication between curve_client_t and curve_server_t decode and encode
Solution: extracted common base class curve_mechanism_base_t
2017-08-18 11:34:22 +02:00
sigiesec
44f6aa3de6 Problem: gssapi_* do not emit ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL events
Solution: emit appropriate events
2017-08-18 10:30:48 +02:00
sigiesec
ca7eee357e Problem: no ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL events emitted in plain_client_t
Solution: emit events at appropriate places
2017-08-18 10:15:44 +02:00
sigiesec
c66ae4656f Problem: curve_client_t may emit misleading event on bad data processed by curve_client_t::decode
Solution: use check_basic_command_structure in curve_client_t::decode, also prepare other client mechanisms to use that method by rearranging inheritance hierarchy
2017-08-18 10:04:58 +02:00
sigiesec
e22ca065d6 Problem: curve_client_t does not emit handshake failure events
Solution: add handshake failure events to curve_client_t
2017-08-18 09:18:06 +02:00
sigiesec
9bec68354c Problem: console output for NULL protocol errors
Solution: emit socket monitor events for NULL protocol errors (like CURVE)
2017-08-18 09:18:06 +02:00
sigiesec
11b3c93852 Problem: console output for PLAIN protocol errors
Solution: emit socket monitor events for PLAIN protocol errors (like CURVE)
2017-08-18 09:18:06 +02:00
sigiesec
e2d3ba9c62 Problem: classification ZMQ_HANDSHAKE_FAILED_* events is coarse-grained and partially misleading
Solution: redesign ZMQ_HANDSHAKE_FAILED_* events, introduce new class of ZMQ_HANDSHAKE_FAILED_AUTH events
2017-08-18 09:17:59 +02:00
sigiesec
f9985708b7 Problem: unreachable code in zap_client_t
Solution: replaced unreachable code by assertions and adapted uses
2017-08-17 12:54:05 +02:00
sigiesec
f107b53768 Problem: deviating behavior regarding monitoring events between mechanisms
Solution: move relevant behavior to zap_client_t
2017-08-17 12:10:00 +02:00
sigiesec
8dce0396fb Problem: inconsistent handling of ZAP replies
Solution: unification, pulled up common behaviour to zap_client_t/zap_client_common_handshake_t
2017-08-17 09:44:05 +02:00
sigiesec
8c58ef7f5c Problem: zap_msg_available duplicated between curve_server_t and plain_server_t (with deviating behaviour)
Solution: pull up into zap_client_common_handshake_t, along with handle_zap_status_code and error_detail/current_error_detail
2017-08-16 18:05:36 +02:00
sigiesec
314a3acfa9 Problem: status method duplicated between curve_server_t and plain_server_t
Solution: extract into new intermediate base class zap_client_common_handshake_t
2017-08-16 18:05:36 +02:00
sigiesec
ebba815a4d Problem: duplicate but equivalent state enums in curve_server_t and plain_server_t
Solution: pull state enum up to zap_client_t and unify names of enum values
2017-08-16 18:05:35 +02:00
sigiesec
414c6f45b8 Problem: receive_and_process_zap_reply is duplicated in all mechanisms
Solution: extract receive_and_process_zap_reply into zap_client_t and convert zap_client_t into base class of the server mechanism classes
2017-08-16 18:05:35 +02:00
sigiesec
d7a3778387 Problem: plain_server_t duplicates zap_client_t::send_zap_request
Solution: Use zap_client_t::send_zap_request
2017-08-16 18:05:35 +02:00
sigiesec
014b201d3e Problem: ZAP message without credentials is not terminated
Solution: Set more flag depending on presence of credentials
2017-08-16 18:05:35 +02:00
sigiesec
b324c66b6f Problem: null_mechanism duplicates zap_client_t::send_zap_request\nSolution: use zap_client_t::send_zap_request 2017-08-16 18:05:34 +02:00
sigiesec
f3884f3380 Problem: gssapi_server_t duplicates zap_client_t::send_zap_request
Solution: Use zap_client_t::send_zap_request
2017-08-16 18:04:31 +02:00
sigiesec
6e8a0b31be Problem: ZAP client code is duplicated in all mechanisms
Solution: created a zap_client_t class, extracted first function send_zap_request from curve_server_t
2017-08-16 18:04:30 +02:00
Simon Giesecke
4a18f6204c Problem: Possible buffer overruns related to metadata in various mechanisms (#2683)
* Problem: no test case with CURVE encryption and large identity

Solution: added test case (currently crashing)

* Problem: possible buffer overflow in mechanism_t::add_property

Solution: add target buffer length parameter and check the buffer is sufficiently large

* Problem: test cases accidentally excluded from build

Solution: remove #if/#endif

* Problem: possible buffer overruns related to metadata at various locations

Solution: allocate buffer large enough for actual metadata, reduce code duplication

* Problem: syntax error related to pointer type conversion

Solution: change argument type of make_command_with_basic_properties to const char *

* Problem: large metadata may cause an assertion in produce_initiate

Solution: Allow metadata of arbitrary size in produce_initiate
2017-08-15 18:42:31 +01:00
Simon Giesecke
d5e4319edc [WIP, do not merge] Problem: insufficient tests for ZMTP-CURVE protocol errors (#2680)
* Extracted connect_vanilla_socket function

* Problem: no tests for ZMTP-CURVE protocol errors

Solution: added two test cases with erroneous HELLO commands

* Problem: insufficient tests for ZMTP-CURVE protocol errors

Solution: added two test cases with erroneous HELLO command version

* Problem: test HELLO message is invalid apart from deliberate errors

Solution: create cryptographically correct HELLO message
add tweetnacl.c to test_security_curve

* Problem: nonce is incorrect, build fails with GCC

Solution: use correct non prefix

* Problem: make builds are failing

Solution: transfer CMake changes to (auto)make files

* Problem: nonce is incorrect, build fails with GCC

Solution: use correct non prefix

* Problem: make builds are failing

Solution: transfer CMake changes to (auto)make files

* Problem: no test with INITIATE command with invalid length

Solution: added test case

* Problem: code duplication between test_security_curve.cpp and curve_client.cpp

Solution: extracted parts of zmq::curve_client_t::produce_hello into reusable function

* Problem: code duplication between test_security_curve.cpp and curve_client.cpp

Solution: extracted further parts of zmq::curve_client_t into reusable functions
added missing file

* Problem: mechanism_t::add_property can be declared static

Solution: declare mechanism_t::add_property static

* Problem: intermediate crypto data needs to be passed between static function calls to curve_client_tools_t

Solution: add non-static member functions

* Problem: msg_t instance may be closed twice

Solution: remove offending close

* Problem: prepare_hello uses static curve_client_tools_t::produce_hello

Solution: Use non-static curve_client_tools_t::produce_hello

* Problem: no test with invalid command name where INITIATE command is expected

Solution: added test case

* Problem: make builds are failing due to curve_client_tools.hpp not being found

Solution: add curve_client_tools.hpp to list of source files

* Problem: wrong initializer order in zmq::curve_client_t

Solution: reorder

* Problem: under non-Windows systems, test fails because random_open was not called

Solution: call random_open/random_close within test

* Problem: conflict between custom function htonll and macro definition on Darwin

Solution: define htonll function only if not defined as a macro

* Problem: nullptr not defined on all platforms

Solution: replace nullptr by NULL

* Problem: libsodium builds not working

Solution: adapt compile and link file sets for libsodium builds

* Problem: Makefile.am broken

Solution: Fix syntax

* Problem: no tests for garbage encrypted cookie or content in INITIATE

Solution: added test cases

* Problem: test cases accidentally excluded from build

Solution: remove #if/#endif

* Solution: some error cases are unreachable

Problem: for the time being, added some comments without changing the code

* Added comments on hard-to-test cases
2017-08-15 15:28:24 +01:00
Luca Boccassi
e376c81c2d Problem: SIGBUS on SPARC64
Solution: force the compiler to make the atomic_counter_t alignment
friendly.
This will ensure that the pointers inside the buffers allocated by
shared_message_memory are aligned, at the cost of growing the memory
size of atomic_counter_t from 4 to 8 bytes on 64 bit (when not using
mutexes).
Note that although content_t contains an atomic_counter_t, the
compiler already padded the struct so there is no change in the
buffer sizes used by the engines, save for the extra 4 bytes for the
buffer's own single atomic counter.
Fixes #2588
2017-08-11 17:48:23 +01:00
Luca Boccassi
f0ae5e585c Problem: C++11 atomic API never used
Solution: remove requirement to manually define macro and just check
for the C++ supported version.
Note that compiler intrinsics still have priority if available, to
avoid changes unless necessary.
2017-08-11 17:47:18 +01:00
Alain O'Dea
454d1eda65
Problem: log for bad ZAP status code is confusing
Solution: log that handler sent bad status code to clarify ZAP debugging
2017-08-10 10:59:18 -02:30
Luca Boccassi
75fba539d0 Problem: PGM/NORM builds broken due to i_engine API change
Solution: implement get_endpoint in the NORM and PGM engines too
2017-08-08 15:18:07 +01:00
Simon Giesecke
a6cef4ef86 Problem: ZAP status codes != 200 do not result in an appropriate monitor event (#2665)
* Problem: missing test for status code 300, inadequate assertion for status code 500

Solution: add test, change assertion (currently test fails)

* Problem: gcc compiler error deprecated conversion from string constant

Solution: declare variable as const

* Problem: in case of ZAP handler returning a status code other than 200, no appropriate event is emitted

Solution: immediately emit event after receiving reply from ZAP handler

* Problem: endpoint address is not included in zap-reply monitor event

Solution: added functions to retrieve endpoint address in zmq::i_engine and zmq::session_base_t
removed unused code block in zmq::stream_engine_t::next_handshake_command

* Problem: wrong formatting

Solution: fix formatting

* Problem: test fails because of EPIPE

Solution: add EPIPE/ECONNRESET/ECONNAGAIN handling for more test cases
2017-08-08 13:10:20 +01:00
Luca Boccassi
3046fe2053 Problem: getrandom usage breaks build
Solution: add missing flags parameter
2017-08-07 08:43:25 +02:00
Luca Boccassi
dc51ebeb1f Problem: valgrind shows unitialised errors in backtrace print
Solution: fix them
2017-08-05 18:04:15 +01:00
Simon Giesecke
41108b203e Problem: zmq::curve_server_t::produce_error sends sizeof std::string instead of status code length
Solution: send status code length (always 3) instead
2017-08-04 16:54:46 +02:00
Simon Giesecke
9949965717 Problem: Property names are duplicated at several places
Solution: Define them in zmq.h and use them (currently in DRAFT API)
2017-08-04 10:33:51 +02:00
Simon Giesecke
c191909c0e Problem: Misleading error code in case ZAP handler sends an invalid status code (#2646)
Solution: Use EPROTO instead of EACCES error code in that case
2017-08-03 14:20:35 +01:00
Simon Giesecke
5d4e30eb13 Replace console output by monitoring events for curve security issues (#2645)
* Fixing #2002 one way of doing it

 * Mechanisms can implement a new method `error_detail()`
 * This error detail have three values for the moment: no_detail
 (default), protocol, encryption.
    + generic enough to make sense for all mechanisms.
    - low granularity level on information.

* Fixing #2002: implementation of the error details

The ZMQ_EVENT_HANDSHAKE_FAILED event carries the error details
as value.

* Removed Microsoft extenstion for enum member access

This was leading to compilation error under linux.

* Adaptation of CURVE test cases

* Monitoring event: changed API for detailed events

Removed ZMQ_EVENT_HANDSHAKE_FAILED and replaced it by:
- ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL,
- ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL,
- ZMQ_EVENT_HANDSHAKE_FAILED_ENCRYPTION

Adaptation of text case `security_curve`

* Removed event value comparison

This was introduced for the previous API model adaptation

* Removed the prints in std output and added missing details

`current_error_detail` was not set in every protocol error cases

* Fixed initialization of current_error_detail

* Fixed error in greeting test case

The handshake failure due to mechanism mismatch in greeting is actually
a protocol error. The error handling method consider it like so and
send a protocol handshake failure monitoring event instead of no_detail.

Fixed the test_security_curve expectation as well.

* Upgraded tests of monitoring events

The tests check the number of monitoring events received

* Problem: does not build under Linux or without ZMQ_DRAFT_API

Solution:
- properly use ZMQ_DRAFT_API conditional compilation
- use receive timeouts instead of Sleep

* Problem: duplicate definition of variable 'timeout'

Solution: merged definitions

* Problem: inconsistent timing dependencies

Solution: reduce timing dependency by using timeouts at more places

* Problem: assertion failure under Linux due to unexpected monitor event

Solution: output event type to aid debugging

* Problem: erroneous assertion code

* Problem: assertion failure with a garbage server key due to an extra third event

Solution: changed assertion to expect three events (needs to be checked)

* Problem: extra include directive to non-existent file

Solution: removed include directive

* Problem: assertion failure on appveyor for unknown reason

Solution: improve debug output

* Problem: no build with libsodium and draft api

Solution: add build configurations with libsodium and draft api

* Problem: assertion failure on CI

Solution: change assertion to reflect actual behaviour on CI (at least temporarily)

* Problem: error in condition in assertion code

* Problem: assertion failure on CI

Solution: generalize assertion to match behavior on CI

* Problem: assertion failures on CI

Solution: removed inconsistent assertion on no monitor events before flushing
improved debuggability by converting function into macro

* Problem: diverging test code for three analogous test cases with garbage key

Solution: extract common code into function

* Problem: does not build without ZMQ_BUILD_DRAFT_API

Solution: introduce dummy variable

* Attempt to remove workaround regarding ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL again

* Problem: EAGAIN error after handshake complete if there is no more data in inbuffer

Solution: Skip tcp_read attempt in that case

* Problem: handshaking event emitted after handshaking failed

Solution: use stream_engine_t::handshaking instead of mechanism_t::status() to determine whether still handshaking

* Include error code in debug output

* Improve debugging output: output flushed events

* Split up ZMQ_EVENT_HANDSHAKE_FAILED_PROTOCOL into ZMQ_EVENT_HANDSHAKE_FAILED_ZMTP and ZMQ_EVENT_HANDSHAKE_FAILED_ZAP

* Fixed compilation without ZMQ_BUILD_DRAFT_API

* Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency

* Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency

* Renamed ZMQ_EVENT_HANDSHAKE_SUCCEED to ZMQ_EVENT_HANDSHAKE_SUCCEEDED for language consistency

* Fixed assert_monitor_event (require event instead of allowing no event)
Reverted erroneous change to handshaking condition
Renamed test_wrong_key to test_garbage_key
Generalized assumption in test_garbage_key to allow for ZMQ_EVENT_HANDSHAKE_FAILED_NO_DETAIL with error == EPIPE

* Better isolate test cases from each other by providing a fresh context & server for each

* Added diagnostic output

* Changed assertion to reflect actual behavior on CI

* Fixed formatting, observe maximum line length

* Fixed formatting, observe maximum line length

* Increase timeout to check if this fixes valgrind run

* Close server with close_zero_linger

* Increase timeout to check if this fixes valgrind run

* Increase timeout to check if this fixes valgrind run

* Generalize assertion to also work with valgrind

* Fixed formatting

* Add more diagnostic output

* Generalize assertion to also work with valgrind
2017-08-03 14:15:56 +01:00
Luca Boccassi
bb0b518e7f Problem: ZMQ_BINDTODEVICE not used for ZMQ_DISH
Solution: apply the option outside of the send/recv_enabled blocks so
that it is used for all types of UDP sockets
2017-07-31 16:31:31 +01:00
Luca Boccassi
415bdbc1b9 Problem: ZMQ_BINDTODEVICE is DRAFT but not DRAFT
Solution: move definition in the DRAFT section of the header
2017-07-31 16:31:31 +01:00
Brian Russell
b963542e8f Add socket option BINDTODEVICE
Linux now supports Virtual Routing and Forwarding (VRF) as per:

https://www.kernel.org/doc/Documentation/networking/vrf.txt

In order for an application to bind or connect to a socket with an
address in a VRF, they need to first bind the socket to the VRF device:

    setsockopt(sd, SOL_SOCKET, SO_BINDTODEVICE, dev, strlen(dev)+1);

Note "dev" is the VRF device, eg. VRF "blue", rather than an interface
enslaved to the VRF.

Add a new socket option, ZMQ_BINDTODEVICE, to bind a socket to a device.
In general, if a socket is bound to a device, eg. an interface, only
packets received from that particular device are processed by the socket.

If device is a VRF device, then subsequent binds/connects to that socket
use addresses in the VRF routing table.
2017-07-31 15:31:47 +01:00
Luca Boccassi
fbb6bbdcb8 Problem: reading from /dev/urandom is clunky
Solution: if available use the getrandom function as it doesn't
require any synchronization, state or cleanup
2017-07-28 11:28:19 +01:00
Luca Boccassi
2626fdfa23 Problem: tweetnacl leaks file descriptor on fork+exec
Solution: open with O_CLOEXEC if available or set FD_CLOEXEC if not
2017-07-28 11:27:55 +01:00
Luca Boccassi
e015a0f8b9 Problem: fd leak in tweetnacl with one ctx per thread
Solution: add a crypto [de-]initialiser, refcounted and serialised
through critical sections.
This is necessary as utility APIs such as zmq_curve_keypair also
call into the sodium/tweetnacl libraries and need the initialisation
outside of the zmq context.
Also the libsodium documentation explicitly says that sodium_init
must not be called concurrently from multiple threads, which could
have happened until now. Also the randombytes_close function does
not appear to be thread safe either.
This change guarantees that the library is initialised only once at
any given time across the whole program.
Fixes #2632
2017-07-28 11:27:53 +01:00
Luca Boccassi
a7bf010ee2 Problem: misleading indentation in tweetnacl.c
Solution: fix it
2017-07-27 21:04:43 +01:00
pavel.pimenov
dfd9d48496 Suppress C4324 (VC++2017)
'zmq::command_t': structure was padded due to alignment specifier
https://msdn.microsoft.com/en-us/library/92fdk6xx.aspx
2017-07-27 07:06:19 +03:00
Eamonn Coughlan
cfb59dde21 Problem: can't set IPV6_V6ONLY on OpenBSD
Solution: skip setsockopt call resulting in EINVAL
2017-07-22 22:53:12 +02:00
Marc Sune
b7b89a8f60 Fix ROUTER's xhas_out() in MANDATORY mode
Before this commit, xhas_out() was returning true regardless. This
was correct before the ZMQ_ROUTER_MANDATORY flag as introduced.
However, ZMQ_POLLOUT.

With this commit, _if_ ZMQ_ROUTER_MANDATORY is set, xhas_out() will
return false if ALL peer's outgoing pipes are full.

There is an outstanding high-level design question:

If ZMQ_ROUTER_MANDATORY is set, and zmq_poll() waits for ZMQ_POLLOUT
events, zmq_poll() will immediately wake up if only 1 pipe has
room to send, regardless of the peer, creating a busy loop of
zmq_poll() wake-up, zmq_send() (EAGAIN). There is no way for
the application to selectively wait for ZMQ_POLLOUT for specific
peer(s), which seems somehow necessary in ZMQ_ROUTER_MANDATORY.

This discussion will be addressed in a separate issue.

Signed-off-by: Marc Sune <marc@voltanet.io>
Signed-off-by: Fredi Raspall <fredi@voltanet.io>
2017-07-14 15:55:58 +02:00
Luca Boccassi
d04065b778 Problem: CURVE server (connect) fails when client rebinds
Solution: if a CURVE server is using zmq_connect, the same session
will be used for any client "reconnect" (actual binds). This is
acceptable, so do not assert if zap_pipe already exists during the
handshake, but simply reuse it.
Fixes #2608
2017-07-01 17:37:07 +01:00
bjovke
9ef34addb8 Problem: When using print_backtrace() on Linux with libunwind, printout of stack traces from multiple threads are interleaved. Solution: added static mutex to serialize printing of stack traces. 2017-06-27 20:29:08 +02:00
bjovke
69355730a4 Problem: intermittent memory leak for req/rep send/recv. #2602 Solution: memory leak fixed. 2017-06-27 20:15:08 +02:00
Luca Boccassi
3536c4b9c4 Problem: XPUB_MANUAL subscriptions not removed on peer term
Solution: remove the pipe from the real trie when a peer disconnects.
Also add a unit test that exercises the behaviour by reconnecting
a different socket and sending a message that matches.
Fixes #2601 and introduced by #2042
2017-06-22 01:02:08 +01:00
Luca Boccassi
6ad0b08da9 Problem: GSSAPI can no longer be used without ZAP
Solution: do not fail if ZAP is not enabled.
GSSAPI already provides authentication and can be used separately,
so it is a valid use case.
2017-06-13 22:56:49 +01:00
Luca Boccassi
0ce18eac25 Problem: CURVE can no longer be used without ZAP
Solution: revert change that made ZAP mandatory.
The "Stonehouse" pattern, where CURVE is used only for encryption and
without authentication, is a valid use case so we should still
support it.
Also restore CURVE testing in the test_heartbeat.

Fixes #2594
2017-06-13 22:56:32 +01:00
Luca Boccassi
33695d1da8 Problem: ZAP is allowed to be configured incorrectly or not to work
Solution: if inproc://zeromq.zap.01 exists, which means ZAP is
enabled, abort immediately if it cannot be used (eg: out of memory)
or it is configured incorrectly (eg: wrong socket type).
Otherwise authentication failures will simply be ignored and
unauthorised peers will be allowed to slip in.
2017-06-13 22:56:31 +01:00
sunddy
af598f2e1c fix bug: dish client does not resend subscriptions to radio server after radio server restart
problem: for zmq radio/dish pattern, if the radio process restarts, the dish will not resend subscriptions to radio. And the result is that the dish will never receive any more messages.

solution: in session_base_t::reconnect (), take ZMQ_DISH into consideration when invoking hiccup method.
2017-06-12 12:26:21 +08:00
laplaceyang
67a6594fc0 fix bug: coredump if set linger and immediate together
In function session_base_t::reconnect, if we set immediate to 1 and set linger, we will get into first block of reconnect function, and set pipe to NULL, but we forget to cancel timer of linger. Once timer tiggered, we will get coredump. Solution: cancel timer in the end of set pipe to NULL
2017-06-02 11:36:41 +08:00
rkfg
72b4b6830f Problem: abort at socket creation on Android with jzmq
Solution: don't set thread name on Android

Setting a thread name on Android may fail with "permission
denied" error and abort the process due to failed assertion.
Tested on Android 5 and 6 (two phones).
Strangely enough, it only happens on signed APKs and is fine
in debug. Using JeroMQ is not an option as we need TCP keepalive
settings and authentication which JeroMQ doesn't support.
2017-05-17 15:05:37 +03:00
Luca Boccassi
bdc676f687 Problem: REP leaves label msgs for dead REQ in pipe
Solution: roll back the pipe if writing messages other than the
first fails in router::xsend. Roll it back also when the pipe is
terminating.
Also add test case that reproduces the memory leak when ran with
valgrind.
Fixes #2567
2017-05-17 09:18:15 +01:00
BJovke
1489fc1ac5 Revert "Problem: REP leaves label msgs for dead REQ in pipe" 2017-05-16 11:20:03 +02:00
Luca Boccassi
0999fdd885 Problem: REP leaves label msgs for dead REQ in pipe
Solution: roll back the pipe if writing messages other than the
first fails in router::xsend.
Also add test case that reproduces the memory leak when ran with
valgrind.
Fixes #2567
2017-05-10 23:44:03 +01:00
KIU Shueng Chuan
d11f501dc1 problem: not using official api FD_ZERO to init fd_set
solution: fix it

In particular, on Windows, using FD_ZERO is much more efficient than
zeroing out the whole structure.
2017-05-06 08:03:09 +08:00
Luca Boccassi
ae461dc2a9 Problem: cannot use wildcard port with source address
Solution: fix TCP endpoint parsing to allow
tcp://127.0.0.1:*;127.0.0.1:1000
2017-05-01 14:57:29 +01:00
Luca Boccassi
90c76fbd60 Problem: new zmq_poller used by zmq_poll without DRAFTs
Solution: do not define ZMQ_HAVE_POLLER in src/zmq_drafts.h otherwise
src/zmq.cpp will implement zmq_poll using the new poller classes.
Same for ZMQ_HAVE_TIMERS, even though it has no internal effect, but
to be safe against future development.
2017-04-28 16:10:01 +01:00
Jim Garlick
53918fc115 gssapi: drop unnecessary ifdefs
Problem: GSSAPI DRAFT code was made conditional on
ZMQ_BUILD_DRAFT_API, but zmq_draft.h duplicates the DRAFT
symbols definitions from zmq.h so this is unnecessary.

Solution: drop the extra ifdefs
2017-04-25 13:50:12 -07:00
Jim Garlick
c978d3bb0a gssapi: renumber socket options
Problem: GSSAPI NAMETYPE socket option numbers were modified
+1000 when moved to DRAFT section, but should use the definitive
values while in DRAFT to minimize disruption later.

Solution: renumber the socket options
2017-04-25 09:58:07 -07:00
Jim Garlick
8892087e99 gssapi: add NAMETYPE options to zmq_getsockopt
Problem: GSSAPI NAMETYPE options were added to zmq_setsockopt()
but not zmq_getsockopt().

Add them to zmq_getsockopt().
2017-04-24 16:12:42 -07:00
Jim Garlick
9fbf2e2eb6 gssapi: move new options to DRAFT section
Problem: The new GSSAPI NAMESPACE options should have been
added to the DRAFT section of the API so they can be changed
until stabilized.

Solution:
- Move defines to the DRAFT section of zmq.h
- Duplicate them in zmq_draft.h, as is the local custom
- Compile only if defined (ZMQ_BUILD_DRAFT_API)
- Refactor internals slightly to avoid #ifdef hell
2017-04-24 16:12:27 -07:00
Jim Garlick
0b185e8297 gssapi: add NAMETYPE socket options
Problem: principals are looked up unconditionally
with the GSS_C_NT_HOSTBASED_SERVICE name type.

Solution: Add two new socket options to set the name type
for ZMQ_GSSAPI_PRINCIPAL and ZMQ_GSSAPI_SERVICE_PRINCIPAL:

ZMQ_GSSAPI_PRINCIPAL_NAMETYPE
ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE

They take an integer argument which must be one of
ZMQ_GSSAPI_NT_HOSTBASED (0) - default
ZMQ_GSSAPI_NT_USER_NAME (1)
ZMQ_GSSAPI_NT_KRB5_PRINCIPAL (2)

These correspond to GSSAPI name types of:
GSS_C_NT_HOSTBASED_SERVICE
GSS_C_NT_USER_NAME
GSS_KRB5_NT_PRINCIPAL_NAME

Fixes #2542
2017-04-21 13:08:45 -07:00
Luca Boccassi
427292561c Merge pull request #2541 from garlick/gssapi_fix
fix misc. bugs in GSSAPI support
2017-04-20 18:49:05 +01:00
Jim Garlick
2b9a352a3c gssapi: use gss_buffer_desc consistently
Problem: one call to gss_import_name() includes the terminating
NULL in a gss_buffer_desc.length, and one doesn't.

According to the examples at:
http://docs.oracle.com/cd/E19253-01/816-4863/overview-22/index.html
the NULL should be included in the length.

Solution:  Fix one case to include the terminating NULL in the length.
2017-04-20 09:42:06 -07:00
Jim Garlick
4e22dd0e97 gssapi: fail if client sets wrong principal
Problem: if client sets ZMQ_GSSAPI_PRINCIPAL to a name
for which credentials cannot be obtained, authentication
proceeds with default credentials.

Solution: Before initializing the security context, check
whether there was a failed attempt to acquire credentials
for a specific principal and bail out if so.

Fixes #2531
2017-04-20 09:42:06 -07:00
Jim Garlick
f2b579ce02 gssapi: use GSS_C_BOTH to acquire credentials
Problem: if client sets the ZMQ_GSSAPI_PRINCIPAL to a valid
principal, authentication fails.

When an application sets ZMQ_GSSAPI_PRINCIPAL, whether as a
client or a server, libzmq internally calls gss_acquire_cred()
with cred_usage=GSS_C_ACCEPT.  This cred_usage setting is for
acceptors (servers) only, thus it doesn't work for initiators
(clients).

Solution: Change the cred_usage parameter to GSS_C_BOTH to allow
initiators to set ZMQ_GSSAPI_PRINCIPAL.
2017-04-20 09:42:06 -07:00
Juan A. Garcia Pardo
52ce6aab86 Problem: Windows build broken by #if ZMQ_USE_POLL
Solution: use #if defined ZMQ_USE_POLL
2017-04-20 15:53:06 +02:00
Asmod4n
ce602d08db change macOS < 10.12 clock to SYSTEM_CLOCK, fixes #2537 (#2538)
* change macOS < 10.12 clock to SYSTEM_CLOCK, fixes #2537

* remove clock_id option from alt_clock_gettime since we always want a monotonic clock.

* update header definition for alt_clock_gettime

* pass clock definition down to host_get_clock_service for macOS < 10.12

* change to monotonic clocks
2017-04-19 23:13:06 +01:00
BJovke
1d4014dc52 Problem: Minor inconsistency in macro syntax. Solution: Code fixed. (#2534)
* Problem: Minor inconsistency in macro syntax. Solution: Code fixed.
2017-04-14 17:10:57 +01:00
bjovke
dc7bbe35b4 Problem: FD set copying on Windows still not optimal on some places. Solution: Improved memcpy() of FD sets for Windows builds. 2017-04-14 16:31:05 +02:00
bjovke
aa3540e657 Problem: misleading indentation and visually ambiguous if/else block ordering.
Solution: fixed indentation and if/else block.
2017-04-11 13:14:13 +02:00
Luca Boccassi
d815228246 Merge pull request #2523 from bjovke/my_working_branch
Critical BUG introduced with #2518 fixed.
2017-04-10 20:09:07 +01:00
bjovke
c635ee7e9d Critical BUG introduced with #2518 fixed. 2017-04-10 20:09:22 +02:00
Jake Cobb
f89e3ee854 Problem: Bad style in tcp.hpp/cpp
Solution: Add spaces between function
name and parentheses.
2017-04-10 13:57:29 -04:00
Luca Boccassi
2df4e87849 Merge pull request #2522 from bjovke/my_working_branch
Another macro correction.
2017-04-10 17:31:32 +01:00
Jake Cobb
cd39b00e19 Consistency of Windows TCP tuning assertions
Treat ECONNRESET, ENETRESET and EINTR as non-fatal
failures in TCP Tuning on Windows as they are in the
Unixes.  Also adds ENETRESET to the Unix list that was missing.
2017-04-10 10:57:17 -04:00
bjovke
9bee9d6d03 Another macro correction. 2017-04-10 16:14:26 +02:00
bjovke
b6fb1f64a5 Macro correction. 2017-04-10 15:39:20 +02:00
bjovke
30cd655b3d Case found not covered in latest zmq::proxy() code. 2017-04-10 14:10:47 +02:00
bjovke
26520fe152 zmq::socket_poller_t speed improvement for constructor and wait() function. 2017-04-10 11:35:08 +02:00
bjovke
a7977a5e84 Reworked zmq::proxy() for improved performance. 2017-04-10 11:34:24 +02:00
bjovke
3e55545ab0 Code reformatting of proxy.cpp 2017-04-10 11:30:52 +02:00
Luca Boccassi
6853e3f935 Merge pull request #2514 from lytboris/freebsd-enable-ai_v4mapped
re-enable AI_V4MAPPED on FreeBSD & DragonFlyBSD
2017-04-09 10:24:50 +01:00
Boris Lytochkin
ef8b0c60fc re-enable AI_V4MAPPED on FreeBSD & DragonFlyBSD
Detect AI_V4MAPPED is not supported in getaddrinfo() on the fly
and retry query. This issue was seen on ancient FreeBSD releases
and current implementation does support this flag correctly.
2017-04-09 11:49:21 +03:00
Boris Lytochkin
2b1bbf1673 fix a typo - assigment was used instead of comparison 2017-04-09 11:37:22 +03:00
Boris Lytochkin
8bc92bde34 choose IP(v6) address based on ipv6_ flag in a correct way 2017-04-08 23:00:23 +03:00
bjovke
319eb27f19 Unnecessary dynamic memory allocation for zmq::socket_poller_t in zmq_poller_poll(). Fixed by allocating zmq::socket_poller_t from stack. 2017-04-04 11:51:59 +02:00
Jake Cobb
5d5263ed8a Prevent DOS by asserts in TCP tuning (#2492)
* Prevent DOS by asserts in TCP tuning

-Propagates socket option errors from the
tuning functions to the callers.
-Asserts a subset of error conditions during tuning,
excluding external network causes.
-Checks tuning results in 3 call sites and treats
them like failures to connect, accept, etc.

* Fix variable name

* Remove lambda requiring C++11
2017-04-04 09:55:26 +01:00
bbdb68
1d58a00992 Problem: no windows UWP support
* add define for windows/UWP

* prevent issue with COM references

* gettickcount not available on uwp

* add compiler definitions

* add convenitnece cmake file

* brute force uwp compilation

* fix compiler version

* cosmetics
2017-04-04 09:50:33 +01:00
evoskuil
1dd9cac24d Problem: xpub_t.xattach_pipe no handle msg.copy or pipe_t.write fails. 2017-03-30 14:45:40 -07:00
evoskuil
6436bc51e6 Problem: sub.xsetsockopt leaks message (0..n bytes) payload on fail. 2017-03-30 14:06:39 -07:00
evoskuil
1b79da0d7d Problem: proxy leaks one message payload (0..n bytes) on close. 2017-03-30 13:57:48 -07:00
evoskuil
4ea7d01803 Problem: send_failure() util name undergeneralized (for read success). 2017-03-30 13:57:47 -07:00
evoskuil
8c165ad1d2 Problem: excess whitespace (style). 2017-03-30 13:57:47 -07:00
evoskuil
a014e77ef7 Problem: leaks on send_zap_request fail, use of goto idiom is fragile. 2017-03-29 16:48:40 -07:00
evoskuil
29a5c98d83 Problem: zap_connect() asserts on write fail (yet returns fail codes). 2017-03-29 14:31:48 -07:00
evoskuil
a0ccdc866e Problem: secure servers ignore zap_connect failre code and set ready. 2017-03-29 14:31:47 -07:00
evoskuil
f44300cb00 Problem: assert used for ZAP error handling aborts process. 2017-03-29 10:43:56 -07:00
Thomas Braun
33e29bd383 Problem: Out of memory condition not always checked
Solution: Use the appropriate assertion macro.
2017-03-27 23:58:38 +02:00
Thomas Braun
fe9f6b2837 Problem: GSSAPI check for Out of memory is done conditionally
Solution: Do it unconditionally.
2017-03-27 23:58:27 +02:00
Thomas Braun
19f30f7926 Problem: throwing version of new called
Solution: Pass (std::nothrow) as done in all other places.
2017-03-27 23:58:19 +02:00