2009-08-12 09:40:16 +02:00
|
|
|
/*
|
2016-01-28 15:07:31 +01:00
|
|
|
Copyright (c) 2007-2016 Contributors as noted in the AUTHORS file
|
2009-08-12 09:40:16 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
This file is part of libzmq, the ZeroMQ core engine in C++.
|
2009-08-12 09:40:16 +02:00
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
libzmq is free software; you can redistribute it and/or modify it under
|
|
|
|
the terms of the GNU Lesser General Public License (LGPL) as published
|
|
|
|
by the Free Software Foundation; either version 3 of the License, or
|
2009-08-12 09:40:16 +02:00
|
|
|
(at your option) any later version.
|
|
|
|
|
2015-06-02 22:33:55 +02:00
|
|
|
As a special exception, the Contributors give you permission to link
|
|
|
|
this library with independent modules to produce an executable,
|
|
|
|
regardless of the license terms of these independent modules, and to
|
|
|
|
copy and distribute the resulting executable under terms of your choice,
|
|
|
|
provided that you also meet, for each linked independent module, the
|
|
|
|
terms and conditions of the license of that module. An independent
|
|
|
|
module is a module which is not derived from or based on this library.
|
|
|
|
If you modify this library, you must extend this exception to your
|
|
|
|
version of the library.
|
|
|
|
|
|
|
|
libzmq is distributed in the hope that it will be useful, but WITHOUT
|
|
|
|
ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
|
|
|
|
FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
|
|
|
|
License for more details.
|
2009-08-12 09:40:16 +02:00
|
|
|
|
2010-10-30 15:08:28 +02:00
|
|
|
You should have received a copy of the GNU Lesser General Public License
|
2009-08-12 09:40:16 +02:00
|
|
|
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
2016-02-18 17:56:52 +01:00
|
|
|
#include "precompiled.hpp"
|
2010-04-09 13:04:15 +02:00
|
|
|
#include <string.h>
|
2018-05-28 18:46:36 +02:00
|
|
|
#include <limits.h>
|
2018-05-18 17:47:47 +02:00
|
|
|
#include <set>
|
2010-04-09 13:04:15 +02:00
|
|
|
|
2009-08-12 09:40:16 +02:00
|
|
|
#include "options.hpp"
|
2009-09-21 14:39:59 +02:00
|
|
|
#include "err.hpp"
|
2016-01-30 08:31:23 +01:00
|
|
|
#include "macros.hpp"
|
2009-08-12 09:40:16 +02:00
|
|
|
|
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-28 15:35:09 +02:00
|
|
|
#ifndef ZMQ_HAVE_WINDOWS
|
|
|
|
#include <net/if.h>
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if defined IFNAMSIZ
|
|
|
|
#define BINDDEVSIZ IFNAMSIZ
|
|
|
|
#else
|
|
|
|
#define BINDDEVSIZ 16
|
|
|
|
#endif
|
|
|
|
|
2018-03-06 11:16:22 +01:00
|
|
|
static int sockopt_invalid ()
|
|
|
|
{
|
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
|
|
|
zmq_assert (false);
|
|
|
|
#endif
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
int zmq::do_getsockopt (void *const optval_,
|
|
|
|
size_t *const optvallen_,
|
|
|
|
const std::string &value_)
|
|
|
|
{
|
|
|
|
return do_getsockopt (optval_, optvallen_, value_.c_str (),
|
|
|
|
value_.size () + 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
int zmq::do_getsockopt (void *const optval_,
|
|
|
|
size_t *const optvallen_,
|
|
|
|
const void *value_,
|
|
|
|
const size_t value_len_)
|
|
|
|
{
|
|
|
|
// TODO behaviour is inconsistent with options_t::getsockopt; there, an
|
|
|
|
// *exact* length match is required except for string-like (but not the
|
|
|
|
// CURVE keys!) (and therefore null-ing remaining memory is a no-op, see
|
|
|
|
// comment below)
|
|
|
|
if (*optvallen_ < value_len_) {
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
memcpy (optval_, value_, value_len_);
|
|
|
|
// TODO why is the remaining memory null-ed?
|
2018-05-18 15:54:00 +02:00
|
|
|
memset (static_cast<char *> (optval_) + value_len_, 0,
|
|
|
|
*optvallen_ - value_len_);
|
2018-03-06 11:16:22 +01:00
|
|
|
*optvallen_ = value_len_;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
#ifdef ZMQ_HAVE_CURVE
|
|
|
|
static int do_getsockopt_curve_key (void *const optval_,
|
2019-12-08 14:59:41 +01:00
|
|
|
const size_t *const optvallen_,
|
2018-03-06 11:16:22 +01:00
|
|
|
const uint8_t (&curve_key_)[CURVE_KEYSIZE])
|
|
|
|
{
|
|
|
|
if (*optvallen_ == CURVE_KEYSIZE) {
|
|
|
|
memcpy (optval_, curve_key_, CURVE_KEYSIZE);
|
|
|
|
return 0;
|
2018-05-25 23:10:10 +02:00
|
|
|
}
|
|
|
|
if (*optvallen_ == CURVE_KEYSIZE_Z85 + 1) {
|
2018-05-18 15:54:00 +02:00
|
|
|
zmq_z85_encode (static_cast<char *> (optval_), curve_key_,
|
|
|
|
CURVE_KEYSIZE);
|
2018-03-06 11:16:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
template <typename T>
|
2019-12-23 13:39:40 +01:00
|
|
|
static int do_setsockopt (const void *const optval_,
|
|
|
|
const size_t optvallen_,
|
|
|
|
T *const out_value_)
|
2018-03-06 11:16:22 +01:00
|
|
|
{
|
|
|
|
if (optvallen_ == sizeof (T)) {
|
|
|
|
memcpy (out_value_, optval_, sizeof (T));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int zmq::do_setsockopt_int_as_bool_strict (const void *const optval_,
|
|
|
|
const size_t optvallen_,
|
|
|
|
bool *const out_value_)
|
|
|
|
{
|
|
|
|
// TODO handling of values other than 0 or 1 is not consistent,
|
|
|
|
// here it is disallowed, but for other options such as
|
|
|
|
// ZMQ_ROUTER_RAW any positive value is accepted
|
2018-03-06 21:27:16 +01:00
|
|
|
int value = -1;
|
2018-03-06 11:16:22 +01:00
|
|
|
if (do_setsockopt (optval_, optvallen_, &value) == -1)
|
|
|
|
return -1;
|
|
|
|
if (value == 0 || value == 1) {
|
|
|
|
*out_value_ = (value != 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
|
|
|
|
int zmq::do_setsockopt_int_as_bool_relaxed (const void *const optval_,
|
|
|
|
const size_t optvallen_,
|
|
|
|
bool *const out_value_)
|
|
|
|
{
|
2018-03-06 21:27:16 +01:00
|
|
|
int value = -1;
|
2018-03-06 11:16:22 +01:00
|
|
|
if (do_setsockopt (optval_, optvallen_, &value) == -1)
|
|
|
|
return -1;
|
|
|
|
*out_value_ = (value != 0);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_setsockopt_string_allow_empty_strict (const void *const optval_,
|
|
|
|
const size_t optvallen_,
|
|
|
|
std::string *const out_value_,
|
|
|
|
const size_t max_len_)
|
|
|
|
{
|
|
|
|
// TODO why is optval_ != NULL not allowed in case of optvallen_== 0?
|
|
|
|
// TODO why are empty strings allowed for some socket options, but not for others?
|
|
|
|
if (optval_ == NULL && optvallen_ == 0) {
|
|
|
|
out_value_->clear ();
|
|
|
|
return 0;
|
2018-05-25 23:10:10 +02:00
|
|
|
}
|
|
|
|
if (optval_ != NULL && optvallen_ > 0 && optvallen_ <= max_len_) {
|
2018-05-18 15:54:00 +02:00
|
|
|
out_value_->assign (static_cast<const char *> (optval_), optvallen_);
|
2018-03-06 11:16:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
|
|
|
|
static int
|
|
|
|
do_setsockopt_string_allow_empty_relaxed (const void *const optval_,
|
|
|
|
const size_t optvallen_,
|
|
|
|
std::string *const out_value_,
|
|
|
|
const size_t max_len_)
|
|
|
|
{
|
|
|
|
// TODO use either do_setsockopt_string_allow_empty_relaxed or
|
|
|
|
// do_setsockopt_string_allow_empty_strict everywhere
|
|
|
|
if (optvallen_ > 0 && optvallen_ <= max_len_) {
|
2018-05-18 15:54:00 +02:00
|
|
|
out_value_->assign (static_cast<const char *> (optval_), optvallen_);
|
2018-03-06 11:16:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
2019-12-23 13:39:40 +01:00
|
|
|
static int do_setsockopt_set (const void *const optval_,
|
|
|
|
const size_t optvallen_,
|
|
|
|
std::set<T> *const set_)
|
2018-03-06 11:16:22 +01:00
|
|
|
{
|
|
|
|
if (optvallen_ == 0 && optval_ == NULL) {
|
|
|
|
set_->clear ();
|
|
|
|
return 0;
|
2018-05-30 13:13:31 +02:00
|
|
|
}
|
|
|
|
if (optvallen_ == sizeof (T) && optval_ != NULL) {
|
|
|
|
set_->insert (*(static_cast<const T *> (optval_)));
|
2018-03-06 11:16:22 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
return sockopt_invalid ();
|
|
|
|
}
|
|
|
|
|
2018-05-30 13:13:31 +02:00
|
|
|
// TODO why is 1000 a sensible default?
|
|
|
|
const int default_hwm = 1000;
|
|
|
|
|
2009-08-12 09:40:16 +02:00
|
|
|
zmq::options_t::options_t () :
|
2018-05-30 13:13:31 +02:00
|
|
|
sndhwm (default_hwm),
|
|
|
|
rcvhwm (default_hwm),
|
2009-09-11 17:58:37 +02:00
|
|
|
affinity (0),
|
2017-09-06 17:45:56 +02:00
|
|
|
routing_id_size (0),
|
2009-09-14 11:25:57 +02:00
|
|
|
rate (100),
|
2011-03-24 14:36:40 +01:00
|
|
|
recovery_ivl (10000),
|
2011-05-15 18:25:43 +02:00
|
|
|
multicast_hops (1),
|
2015-11-23 20:35:02 +01:00
|
|
|
multicast_maxtpdu (1500),
|
2016-05-03 18:37:39 +02:00
|
|
|
sndbuf (-1),
|
|
|
|
rcvbuf (-1),
|
2013-11-25 04:01:21 +01:00
|
|
|
tos (0),
|
2021-01-06 23:22:41 +01:00
|
|
|
priority (0),
|
2010-09-28 15:27:45 +02:00
|
|
|
type (-1),
|
2014-11-17 11:56:59 +01:00
|
|
|
linger (-1),
|
2015-08-04 14:47:07 +02:00
|
|
|
connect_timeout (0),
|
2016-02-09 09:33:29 +01:00
|
|
|
tcp_maxrt (0),
|
2020-02-23 18:17:22 +01:00
|
|
|
reconnect_stop (0),
|
2010-10-17 09:54:12 +02:00
|
|
|
reconnect_ivl (100),
|
2011-01-26 07:01:06 +01:00
|
|
|
reconnect_ivl_max (0),
|
2010-10-17 10:23:58 +02:00
|
|
|
backlog (100),
|
2011-03-02 09:00:36 +01:00
|
|
|
maxmsgsize (-1),
|
2011-06-17 12:22:02 +02:00
|
|
|
rcvtimeo (-1),
|
|
|
|
sndtimeo (-1),
|
2018-05-25 23:03:52 +02:00
|
|
|
ipv6 (false),
|
2013-03-12 16:11:19 +01:00
|
|
|
immediate (0),
|
2011-11-04 08:00:47 +01:00
|
|
|
filter (false),
|
2015-01-26 15:59:19 +01:00
|
|
|
invert_matching (false),
|
2017-09-06 17:45:56 +02:00
|
|
|
recv_routing_id (false),
|
2015-01-23 15:25:40 +01:00
|
|
|
raw_socket (false),
|
2015-07-23 23:20:31 +02:00
|
|
|
raw_notify (true),
|
2012-04-05 17:39:53 +02:00
|
|
|
tcp_keepalive (-1),
|
|
|
|
tcp_keepalive_cnt (-1),
|
|
|
|
tcp_keepalive_idle (-1),
|
|
|
|
tcp_keepalive_intvl (-1),
|
2013-05-15 17:54:03 +02:00
|
|
|
mechanism (ZMQ_NULL),
|
2013-05-17 17:46:30 +02:00
|
|
|
as_server (0),
|
2017-04-21 01:28:30 +02:00
|
|
|
gss_principal_nt (ZMQ_GSSAPI_NT_HOSTBASED),
|
|
|
|
gss_service_principal_nt (ZMQ_GSSAPI_NT_HOSTBASED),
|
2014-04-23 21:45:13 +02:00
|
|
|
gss_plaintext (false),
|
2013-08-17 21:59:07 +02:00
|
|
|
socket_id (0),
|
2014-05-09 15:54:24 +02:00
|
|
|
conflate (false),
|
2015-06-05 11:43:40 +02:00
|
|
|
handshake_ivl (30000),
|
2015-03-17 02:39:16 +01:00
|
|
|
connected (false),
|
|
|
|
heartbeat_ttl (0),
|
|
|
|
heartbeat_interval (0),
|
2016-02-01 13:00:45 +01:00
|
|
|
heartbeat_timeout (-1),
|
2017-10-07 19:34:18 +02:00
|
|
|
use_fd (-1),
|
2018-02-05 17:09:39 +01:00
|
|
|
zap_enforce_domain (false),
|
2018-03-05 13:19:20 +01:00
|
|
|
loopback_fastpath (false),
|
2018-05-10 16:56:49 +02:00
|
|
|
multicast_loop (true),
|
2019-06-27 06:34:56 +02:00
|
|
|
in_batch_size (8192),
|
|
|
|
out_batch_size (8192),
|
2018-08-15 09:54:08 +02:00
|
|
|
zero_copy (true),
|
2019-02-01 11:43:45 +01:00
|
|
|
router_notify (0),
|
2019-09-29 17:30:37 +02:00
|
|
|
monitor_event_version (1),
|
2020-04-17 08:50:59 +02:00
|
|
|
wss_trust_system (false),
|
|
|
|
hello_msg (),
|
2020-04-17 12:20:57 +02:00
|
|
|
can_send_hello_msg (false),
|
|
|
|
disconnect_msg (),
|
2021-05-15 00:05:56 +02:00
|
|
|
can_recv_disconnect_msg (false),
|
2021-06-06 13:28:29 +02:00
|
|
|
hiccup_msg (),
|
|
|
|
can_recv_hiccup_msg (false),
|
2021-05-15 00:05:56 +02:00
|
|
|
busy_poll (0)
|
2009-08-12 09:40:16 +02:00
|
|
|
{
|
2016-02-16 12:54:23 +01:00
|
|
|
memset (curve_public_key, 0, CURVE_KEYSIZE);
|
|
|
|
memset (curve_secret_key, 0, CURVE_KEYSIZE);
|
|
|
|
memset (curve_server_key, 0, CURVE_KEYSIZE);
|
2015-12-07 13:19:45 +01:00
|
|
|
#if defined ZMQ_HAVE_VMCI
|
|
|
|
vmci_buffer_size = 0;
|
|
|
|
vmci_buffer_min_size = 0;
|
|
|
|
vmci_buffer_max_size = 0;
|
|
|
|
vmci_connect_timeout = -1;
|
|
|
|
#endif
|
2009-08-12 09:40:16 +02:00
|
|
|
}
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2018-05-24 17:58:30 +02:00
|
|
|
int zmq::options_t::set_curve_key (uint8_t *destination_,
|
2016-12-16 16:44:31 +01:00
|
|
|
const void *optval_,
|
|
|
|
size_t optvallen_)
|
|
|
|
{
|
|
|
|
switch (optvallen_) {
|
|
|
|
case CURVE_KEYSIZE:
|
2018-05-24 17:58:30 +02:00
|
|
|
memcpy (destination_, optval_, optvallen_);
|
2016-12-16 16:44:31 +01:00
|
|
|
mechanism = ZMQ_CURVE;
|
|
|
|
return 0;
|
|
|
|
|
2020-08-23 14:47:07 +02:00
|
|
|
case CURVE_KEYSIZE_Z85 + 1: {
|
|
|
|
const std::string s (static_cast<const char *> (optval_),
|
|
|
|
optvallen_);
|
|
|
|
|
|
|
|
if (zmq_z85_decode (destination_, s.c_str ())) {
|
2016-12-16 16:44:31 +01:00
|
|
|
mechanism = ZMQ_CURVE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2020-08-23 14:47:07 +02:00
|
|
|
}
|
2016-12-16 16:44:31 +01:00
|
|
|
|
|
|
|
case CURVE_KEYSIZE_Z85:
|
|
|
|
char z85_key[CURVE_KEYSIZE_Z85 + 1];
|
2018-05-28 17:46:47 +02:00
|
|
|
memcpy (z85_key, reinterpret_cast<const char *> (optval_),
|
|
|
|
optvallen_);
|
2016-12-16 16:44:31 +01:00
|
|
|
z85_key[CURVE_KEYSIZE_Z85] = 0;
|
2018-05-24 17:58:30 +02:00
|
|
|
if (zmq_z85_decode (destination_, z85_key)) {
|
2016-12-16 16:44:31 +01:00
|
|
|
mechanism = ZMQ_CURVE;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
2018-05-25 10:50:47 +02:00
|
|
|
const int deciseconds_per_millisecond = 100;
|
|
|
|
|
2009-09-21 14:39:59 +02:00
|
|
|
int zmq::options_t::setsockopt (int option_,
|
|
|
|
const void *optval_,
|
|
|
|
size_t optvallen_)
|
|
|
|
{
|
2019-12-25 13:51:21 +01:00
|
|
|
const bool is_int = (optvallen_ == sizeof (int));
|
2016-02-07 04:20:42 +01:00
|
|
|
int value = 0;
|
|
|
|
if (is_int)
|
|
|
|
memcpy (&value, optval_, sizeof (int));
|
2014-06-17 16:14:19 +02:00
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
Problem: API violations are treated as recoverable errors
The example is applications passing invalid arguments to a socket option
and then failing to check the return code. The results can be very hard
to diagnose. Here are some threads that show the pain this causes:
* https://github.com/zeromq/zyre/issues/179
* http://lists.zeromq.org/pipermail/zeromq-dev/2014-June/026388.html
One common argument is that a library should never assert, and should
pass errors back to the calling application. The counter argument is
that when an application is broken enough to pass garbage to libzmq,
it cannot be trusted to handle the resulting errors properly. Empirical
evidence from CZMQ, where we systematically assert on bad arguments, is
that this militant approach makes applications more, not less, robust.
I don't see any valid use cases for returning errors on bad arguments,
with one exception: zmq_setsockopt can be used to probe whether libzmq
was e.g. built with CURVE security. I'd argue that it's nasty to use a
side effect like this. If apps need to probe how libzmq was built, this
should be done explicitly, and for ALL build options, not just CURVE.
There are/were no libzmq test cases that check the return code for an
invalid option.
For now I've enabled militant assertions using --with-militant at
configure time. However I'd like to make this the default setting.
2014-06-17 15:49:52 +02:00
|
|
|
bool malformed = true; // Did caller pass a bad option value?
|
2014-06-17 16:14:19 +02:00
|
|
|
#endif
|
2014-06-17 16:24:56 +02:00
|
|
|
|
2009-09-21 14:39:59 +02:00
|
|
|
switch (option_) {
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_SNDHWM:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
sndhwm = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RCVHWM:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
rcvhwm = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_AFFINITY:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt (optval_, optvallen_, &affinity);
|
2013-01-30 23:53:09 +01:00
|
|
|
|
2017-09-06 17:45:56 +02:00
|
|
|
case ZMQ_ROUTING_ID:
|
|
|
|
// Routing id is any binary string from 1 to 255 octets
|
2018-05-30 13:13:31 +02:00
|
|
|
if (optvallen_ > 0 && optvallen_ <= UCHAR_MAX) {
|
2018-05-18 15:54:00 +02:00
|
|
|
routing_id_size = static_cast<unsigned char> (optvallen_);
|
2017-09-06 17:45:56 +02:00
|
|
|
memcpy (routing_id, optval_, routing_id_size);
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
2013-01-30 23:53:09 +01:00
|
|
|
}
|
|
|
|
break;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RATE:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value > 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
rate = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RECOVERY_IVL:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
recovery_ivl = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2011-11-02 14:33:58 +01:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_SNDBUF:
|
2016-05-03 18:37:39 +02:00
|
|
|
if (is_int && value >= -1) {
|
2013-01-30 23:53:09 +01:00
|
|
|
sndbuf = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2011-11-02 14:33:58 +01:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RCVBUF:
|
2016-05-03 18:37:39 +02:00
|
|
|
if (is_int && value >= -1) {
|
2013-01-30 23:53:09 +01:00
|
|
|
rcvbuf = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2012-04-13 11:26:57 +02:00
|
|
|
|
2013-11-25 04:01:21 +01:00
|
|
|
case ZMQ_TOS:
|
|
|
|
if (is_int && value >= 0) {
|
|
|
|
tos = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_LINGER:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= -1) {
|
2018-02-08 23:10:45 +01:00
|
|
|
linger.store (value);
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2015-08-04 14:47:07 +02:00
|
|
|
case ZMQ_CONNECT_TIMEOUT:
|
|
|
|
if (is_int && value >= 0) {
|
|
|
|
connect_timeout = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-02-09 09:33:29 +01:00
|
|
|
case ZMQ_TCP_MAXRT:
|
2015-08-06 17:36:27 +02:00
|
|
|
if (is_int && value >= 0) {
|
2016-02-09 09:33:29 +01:00
|
|
|
tcp_maxrt = value;
|
2015-08-06 17:36:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-02-23 18:17:22 +01:00
|
|
|
case ZMQ_RECONNECT_STOP:
|
|
|
|
if (is_int) {
|
|
|
|
reconnect_stop = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RECONNECT_IVL:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= -1) {
|
2013-01-30 23:53:09 +01:00
|
|
|
reconnect_ivl = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2009-12-10 09:47:24 +01:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RECONNECT_IVL_MAX:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
reconnect_ivl_max = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2010-10-16 10:53:29 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_BACKLOG:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
backlog = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2010-10-17 09:54:12 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_MAXMSGSIZE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt (optval_, optvallen_, &maxmsgsize);
|
2010-10-17 10:23:58 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_MULTICAST_HOPS:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value > 0) {
|
2013-01-30 23:53:09 +01:00
|
|
|
multicast_hops = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2011-01-26 07:01:06 +01:00
|
|
|
|
2015-11-23 20:35:02 +01:00
|
|
|
case ZMQ_MULTICAST_MAXTPDU:
|
|
|
|
if (is_int && value > 0) {
|
|
|
|
multicast_maxtpdu = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_RCVTIMEO:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= -1) {
|
2013-01-30 23:53:09 +01:00
|
|
|
rcvtimeo = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2010-10-17 10:23:58 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_SNDTIMEO:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && value >= -1) {
|
2013-01-30 23:53:09 +01:00
|
|
|
sndtimeo = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2011-03-02 09:00:36 +01:00
|
|
|
|
2013-01-31 20:47:45 +01:00
|
|
|
/* Deprecated in favor of ZMQ_IPV6 */
|
2018-03-06 11:16:22 +01:00
|
|
|
case ZMQ_IPV4ONLY: {
|
|
|
|
bool value;
|
2019-12-25 13:51:21 +01:00
|
|
|
const int rc =
|
2018-03-06 11:16:22 +01:00
|
|
|
do_setsockopt_int_as_bool_strict (optval_, optvallen_, &value);
|
|
|
|
if (rc == 0)
|
|
|
|
ipv6 = !value;
|
|
|
|
return rc;
|
|
|
|
}
|
2011-05-15 18:25:43 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
/* To replace the somewhat surprising IPV4ONLY */
|
|
|
|
case ZMQ_IPV6:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_int_as_bool_strict (optval_, optvallen_,
|
|
|
|
&ipv6);
|
2011-06-17 12:22:02 +02:00
|
|
|
|
2014-06-22 10:32:22 +02:00
|
|
|
case ZMQ_SOCKS_PROXY:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_string_allow_empty_strict (
|
|
|
|
optval_, optvallen_, &socks_proxy_address, SIZE_MAX);
|
2014-06-22 10:32:22 +02:00
|
|
|
|
2019-06-10 15:01:23 +02:00
|
|
|
case ZMQ_SOCKS_USERNAME:
|
|
|
|
/* Make empty string or NULL equivalent. */
|
|
|
|
if (optval_ == NULL || optvallen_ == 0) {
|
2019-06-10 19:40:30 +02:00
|
|
|
socks_proxy_username.clear ();
|
2019-06-10 15:01:23 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return do_setsockopt_string_allow_empty_strict (
|
2019-06-10 19:40:30 +02:00
|
|
|
optval_, optvallen_, &socks_proxy_username, 255);
|
2019-06-10 15:01:23 +02:00
|
|
|
}
|
|
|
|
case ZMQ_SOCKS_PASSWORD:
|
|
|
|
/* Make empty string or NULL equivalent. */
|
|
|
|
if (optval_ == NULL || optvallen_ == 0) {
|
2019-06-10 19:40:30 +02:00
|
|
|
socks_proxy_password.clear ();
|
2019-06-10 15:01:23 +02:00
|
|
|
return 0;
|
|
|
|
} else {
|
|
|
|
return do_setsockopt_string_allow_empty_strict (
|
2019-06-10 19:40:30 +02:00
|
|
|
optval_, optvallen_, &socks_proxy_password, 255);
|
2019-06-10 15:01:23 +02:00
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_TCP_KEEPALIVE:
|
2014-01-31 12:02:42 +01:00
|
|
|
if (is_int && (value == -1 || value == 0 || value == 1)) {
|
2013-01-30 23:53:09 +01:00
|
|
|
tcp_keepalive = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2011-06-17 12:22:02 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_TCP_KEEPALIVE_CNT:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && (value == -1 || value >= 0)) {
|
2013-01-30 23:53:09 +01:00
|
|
|
tcp_keepalive_cnt = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2009-09-21 14:39:59 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_TCP_KEEPALIVE_IDLE:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && (value == -1 || value >= 0)) {
|
2013-01-30 23:53:09 +01:00
|
|
|
tcp_keepalive_idle = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2012-04-05 17:39:53 +02:00
|
|
|
|
2013-01-30 23:53:09 +01:00
|
|
|
case ZMQ_TCP_KEEPALIVE_INTVL:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && (value == -1 || value >= 0)) {
|
2013-01-30 23:53:09 +01:00
|
|
|
tcp_keepalive_intvl = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-03-12 16:11:19 +01:00
|
|
|
case ZMQ_IMMEDIATE:
|
2018-03-06 11:16:22 +01:00
|
|
|
// TODO why is immediate not bool (and called non_immediate, as its meaning appears to be reversed)
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int && (value == 0 || value == 1)) {
|
2013-03-12 16:11:19 +01:00
|
|
|
immediate = value;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2012-04-12 16:37:14 +02:00
|
|
|
|
2018-03-06 11:16:22 +01:00
|
|
|
case ZMQ_TCP_ACCEPT_FILTER: {
|
|
|
|
std::string filter_str;
|
|
|
|
int rc = do_setsockopt_string_allow_empty_strict (
|
2018-05-28 18:46:36 +02:00
|
|
|
optval_, optvallen_, &filter_str, UCHAR_MAX);
|
2018-03-06 11:16:22 +01:00
|
|
|
if (rc == 0) {
|
|
|
|
if (filter_str.empty ()) {
|
|
|
|
tcp_accept_filters.clear ();
|
|
|
|
} else {
|
|
|
|
tcp_address_mask_t mask;
|
|
|
|
rc = mask.resolve (filter_str.c_str (), ipv6);
|
|
|
|
if (rc == 0) {
|
|
|
|
tcp_accept_filters.push_back (mask);
|
|
|
|
}
|
2013-05-15 17:54:03 +02:00
|
|
|
}
|
|
|
|
}
|
2018-03-06 11:16:22 +01:00
|
|
|
return rc;
|
|
|
|
}
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2016-02-11 13:32:01 +01:00
|
|
|
#if defined ZMQ_HAVE_SO_PEERCRED || defined ZMQ_HAVE_LOCAL_PEERCRED
|
2013-12-06 18:58:10 +01:00
|
|
|
case ZMQ_IPC_FILTER_UID:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_set (optval_, optvallen_,
|
|
|
|
&ipc_uid_accept_filters);
|
|
|
|
|
2013-12-04 23:17:39 +01:00
|
|
|
|
2013-12-06 18:58:10 +01:00
|
|
|
case ZMQ_IPC_FILTER_GID:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_set (optval_, optvallen_,
|
|
|
|
&ipc_gid_accept_filters);
|
2016-02-11 13:32:01 +01:00
|
|
|
#endif
|
2013-12-04 23:17:39 +01:00
|
|
|
|
2016-02-11 13:32:01 +01:00
|
|
|
#if defined ZMQ_HAVE_SO_PEERCRED
|
2013-12-06 18:58:10 +01:00
|
|
|
case ZMQ_IPC_FILTER_PID:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_set (optval_, optvallen_,
|
|
|
|
&ipc_pid_accept_filters);
|
2016-02-11 13:32:01 +01:00
|
|
|
#endif
|
2013-12-04 23:17:39 +01:00
|
|
|
|
2013-09-17 14:05:41 +02:00
|
|
|
case ZMQ_PLAIN_SERVER:
|
|
|
|
if (is_int && (value == 0 || value == 1)) {
|
2013-05-17 17:46:30 +02:00
|
|
|
as_server = value;
|
2013-09-17 14:05:41 +02:00
|
|
|
mechanism = value ? ZMQ_PLAIN : ZMQ_NULL;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_PLAIN_USERNAME:
|
|
|
|
if (optvallen_ == 0 && optval_ == NULL) {
|
|
|
|
mechanism = ZMQ_NULL;
|
|
|
|
return 0;
|
2018-05-30 13:13:31 +02:00
|
|
|
} else if (optvallen_ > 0 && optvallen_ <= UCHAR_MAX
|
|
|
|
&& optval_ != NULL) {
|
2018-05-18 15:54:00 +02:00
|
|
|
plain_username.assign (static_cast<const char *> (optval_),
|
|
|
|
optvallen_);
|
2013-09-17 14:05:41 +02:00
|
|
|
as_server = 0;
|
2013-05-15 17:54:03 +02:00
|
|
|
mechanism = ZMQ_PLAIN;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_PLAIN_PASSWORD:
|
|
|
|
if (optvallen_ == 0 && optval_ == NULL) {
|
|
|
|
mechanism = ZMQ_NULL;
|
|
|
|
return 0;
|
2018-05-30 13:13:31 +02:00
|
|
|
} else if (optvallen_ > 0 && optvallen_ <= UCHAR_MAX
|
|
|
|
&& optval_ != NULL) {
|
2018-05-18 15:54:00 +02:00
|
|
|
plain_password.assign (static_cast<const char *> (optval_),
|
|
|
|
optvallen_);
|
2013-09-17 14:05:41 +02:00
|
|
|
as_server = 0;
|
2013-05-15 17:54:03 +02:00
|
|
|
mechanism = ZMQ_PLAIN;
|
|
|
|
return 0;
|
2012-04-12 16:37:14 +02:00
|
|
|
}
|
2013-01-30 23:53:09 +01:00
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
|
|
|
case ZMQ_ZAP_DOMAIN:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_string_allow_empty_relaxed (
|
2018-05-28 18:46:36 +02:00
|
|
|
optval_, optvallen_, &zap_domain, UCHAR_MAX);
|
2019-12-23 13:39:40 +01:00
|
|
|
|
2016-02-11 13:32:01 +01:00
|
|
|
// If curve encryption isn't built, these options provoke EINVAL
|
|
|
|
#ifdef ZMQ_HAVE_CURVE
|
2013-09-17 14:05:41 +02:00
|
|
|
case ZMQ_CURVE_SERVER:
|
2013-09-17 14:05:55 +02:00
|
|
|
if (is_int && (value == 0 || value == 1)) {
|
2013-06-20 18:09:12 +02:00
|
|
|
as_server = value;
|
2013-09-17 14:05:55 +02:00
|
|
|
mechanism = value ? ZMQ_CURVE : ZMQ_NULL;
|
2013-06-20 18:09:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
case ZMQ_CURVE_PUBLICKEY:
|
2016-12-16 16:44:31 +01:00
|
|
|
if (0 == set_curve_key (curve_public_key, optval_, optvallen_)) {
|
2013-09-17 14:05:55 +02:00
|
|
|
return 0;
|
2016-12-16 17:50:17 +01:00
|
|
|
}
|
2013-06-20 18:09:12 +02:00
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
case ZMQ_CURVE_SECRETKEY:
|
2016-12-16 16:44:31 +01:00
|
|
|
if (0 == set_curve_key (curve_secret_key, optval_, optvallen_)) {
|
2013-09-17 14:05:55 +02:00
|
|
|
return 0;
|
2016-12-16 17:50:17 +01:00
|
|
|
}
|
2013-09-17 12:44:14 +02:00
|
|
|
break;
|
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
case ZMQ_CURVE_SERVERKEY:
|
2016-12-16 16:44:31 +01:00
|
|
|
if (0 == set_curve_key (curve_server_key, optval_, optvallen_)) {
|
2014-08-09 10:24:26 +02:00
|
|
|
as_server = 0;
|
2013-09-17 14:05:55 +02:00
|
|
|
return 0;
|
2016-12-16 17:50:17 +01:00
|
|
|
}
|
2013-06-20 18:09:12 +02:00
|
|
|
break;
|
2016-02-11 13:32:01 +01:00
|
|
|
#endif
|
2014-08-12 09:31:19 +02:00
|
|
|
|
2013-08-17 21:59:07 +02:00
|
|
|
case ZMQ_CONFLATE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_int_as_bool_strict (optval_, optvallen_,
|
|
|
|
&conflate);
|
2014-06-17 16:32:47 +02:00
|
|
|
|
|
|
|
// If libgssapi isn't installed, these options provoke EINVAL
|
2016-02-11 13:32:01 +01:00
|
|
|
#ifdef HAVE_LIBGSSAPI_KRB5
|
2013-09-25 05:20:01 +02:00
|
|
|
case ZMQ_GSSAPI_SERVER:
|
|
|
|
if (is_int && (value == 0 || value == 1)) {
|
|
|
|
as_server = value;
|
|
|
|
mechanism = ZMQ_GSSAPI;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-06-17 16:32:47 +02:00
|
|
|
|
2014-04-23 19:20:22 +02:00
|
|
|
case ZMQ_GSSAPI_PRINCIPAL:
|
2018-05-30 13:13:31 +02:00
|
|
|
if (optvallen_ > 0 && optvallen_ <= UCHAR_MAX && optval_ != NULL) {
|
2014-04-23 19:20:22 +02:00
|
|
|
gss_principal.assign ((const char *) optval_, optvallen_);
|
2013-11-20 23:01:16 +01:00
|
|
|
mechanism = ZMQ_GSSAPI;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-04-23 19:20:22 +02:00
|
|
|
case ZMQ_GSSAPI_SERVICE_PRINCIPAL:
|
2018-05-30 13:13:31 +02:00
|
|
|
if (optvallen_ > 0 && optvallen_ <= UCHAR_MAX && optval_ != NULL) {
|
2014-04-23 19:20:22 +02:00
|
|
|
gss_service_principal.assign ((const char *) optval_,
|
|
|
|
optvallen_);
|
2013-09-25 05:20:01 +02:00
|
|
|
mechanism = ZMQ_GSSAPI;
|
2013-11-21 19:46:23 +01:00
|
|
|
as_server = 0;
|
2013-09-25 05:20:01 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-08-17 21:59:07 +02:00
|
|
|
|
2014-04-23 20:01:54 +02:00
|
|
|
case ZMQ_GSSAPI_PLAINTEXT:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_int_as_bool_strict (optval_, optvallen_,
|
|
|
|
&gss_plaintext);
|
2017-04-25 19:07:58 +02:00
|
|
|
|
2017-04-21 01:28:30 +02:00
|
|
|
case ZMQ_GSSAPI_PRINCIPAL_NAMETYPE:
|
|
|
|
if (is_int
|
|
|
|
&& (value == ZMQ_GSSAPI_NT_HOSTBASED
|
|
|
|
|| value == ZMQ_GSSAPI_NT_USER_NAME
|
|
|
|
|| value == ZMQ_GSSAPI_NT_KRB5_PRINCIPAL)) {
|
|
|
|
gss_principal_nt = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2017-04-25 19:07:58 +02:00
|
|
|
|
2017-04-21 01:28:30 +02:00
|
|
|
case ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE:
|
|
|
|
if (is_int
|
|
|
|
&& (value == ZMQ_GSSAPI_NT_HOSTBASED
|
|
|
|
|| value == ZMQ_GSSAPI_NT_USER_NAME
|
|
|
|
|| value == ZMQ_GSSAPI_NT_KRB5_PRINCIPAL)) {
|
|
|
|
gss_service_principal_nt = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2016-02-11 13:32:01 +01:00
|
|
|
#endif
|
2014-06-17 16:32:47 +02:00
|
|
|
|
2014-05-09 15:54:24 +02:00
|
|
|
case ZMQ_HANDSHAKE_IVL:
|
|
|
|
if (is_int && value >= 0) {
|
|
|
|
handshake_ivl = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-01-26 15:59:19 +01:00
|
|
|
case ZMQ_INVERT_MATCHING:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_int_as_bool_relaxed (optval_, optvallen_,
|
|
|
|
&invert_matching);
|
2015-01-26 15:59:19 +01:00
|
|
|
|
2015-03-17 02:39:16 +01:00
|
|
|
case ZMQ_HEARTBEAT_IVL:
|
|
|
|
if (is_int && value >= 0) {
|
|
|
|
heartbeat_interval = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_HEARTBEAT_TTL:
|
2015-06-26 20:08:08 +02:00
|
|
|
// Convert this to deciseconds from milliseconds
|
2018-05-25 10:50:47 +02:00
|
|
|
value = value / deciseconds_per_millisecond;
|
|
|
|
if (is_int && value >= 0 && value <= UINT16_MAX) {
|
2018-05-18 15:54:00 +02:00
|
|
|
heartbeat_ttl = static_cast<uint16_t> (value);
|
2015-03-17 02:39:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_HEARTBEAT_TIMEOUT:
|
|
|
|
if (is_int && value >= 0) {
|
|
|
|
heartbeat_timeout = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-02-11 13:32:01 +01:00
|
|
|
#ifdef ZMQ_HAVE_VMCI
|
2015-12-07 13:19:45 +01:00
|
|
|
case ZMQ_VMCI_BUFFER_SIZE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt (optval_, optvallen_, &vmci_buffer_size);
|
2015-12-07 13:19:45 +01:00
|
|
|
|
|
|
|
case ZMQ_VMCI_BUFFER_MIN_SIZE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt (optval_, optvallen_, &vmci_buffer_min_size);
|
2015-12-07 13:19:45 +01:00
|
|
|
|
|
|
|
case ZMQ_VMCI_BUFFER_MAX_SIZE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt (optval_, optvallen_, &vmci_buffer_max_size);
|
2015-12-07 13:19:45 +01:00
|
|
|
|
|
|
|
case ZMQ_VMCI_CONNECT_TIMEOUT:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt (optval_, optvallen_, &vmci_connect_timeout);
|
2016-02-11 13:32:01 +01:00
|
|
|
#endif
|
2015-12-07 13:19:45 +01:00
|
|
|
|
2016-02-09 10:36:14 +01:00
|
|
|
case ZMQ_USE_FD:
|
2016-02-01 13:00:45 +01:00
|
|
|
if (is_int && value >= -1) {
|
2016-02-09 10:36:14 +01:00
|
|
|
use_fd = value;
|
2016-02-01 13:00:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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-28 15:35:09 +02:00
|
|
|
case ZMQ_BINDTODEVICE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_string_allow_empty_strict (
|
|
|
|
optval_, optvallen_, &bound_device, BINDDEVSIZ);
|
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-28 15:35:09 +02:00
|
|
|
|
2017-10-07 19:34:18 +02:00
|
|
|
case ZMQ_ZAP_ENFORCE_DOMAIN:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_int_as_bool_relaxed (optval_, optvallen_,
|
|
|
|
&zap_enforce_domain);
|
2017-10-07 19:34:18 +02:00
|
|
|
|
2018-02-05 17:09:39 +01:00
|
|
|
case ZMQ_LOOPBACK_FASTPATH:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_setsockopt_int_as_bool_relaxed (optval_, optvallen_,
|
|
|
|
&loopback_fastpath);
|
2017-10-07 19:34:18 +02:00
|
|
|
|
2018-03-12 01:41:33 +01:00
|
|
|
case ZMQ_METADATA:
|
|
|
|
if (optvallen_ > 0 && !is_int) {
|
2020-08-22 18:00:57 +02:00
|
|
|
const std::string s (static_cast<const char *> (optval_),
|
|
|
|
optvallen_);
|
2018-05-30 13:13:31 +02:00
|
|
|
const size_t pos = s.find (':');
|
2018-03-12 01:41:33 +01:00
|
|
|
if (pos != std::string::npos && pos != 0
|
|
|
|
&& pos != s.length () - 1) {
|
2018-05-30 13:13:31 +02:00
|
|
|
const std::string key = s.substr (0, pos);
|
2018-05-28 17:46:47 +02:00
|
|
|
if (key.compare (0, 2, "X-") == 0
|
|
|
|
&& key.length () <= UCHAR_MAX) {
|
|
|
|
std::string val = s.substr (pos + 1, s.length ());
|
2018-03-12 01:41:33 +01:00
|
|
|
app_metadata.insert (
|
|
|
|
std::pair<std::string, std::string> (key, val));
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
2018-05-10 16:56:49 +02:00
|
|
|
|
|
|
|
case ZMQ_MULTICAST_LOOP:
|
|
|
|
return do_setsockopt_int_as_bool_relaxed (optval_, optvallen_,
|
|
|
|
&multicast_loop);
|
|
|
|
|
2019-06-27 06:34:56 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
case ZMQ_IN_BATCH_SIZE:
|
|
|
|
if (is_int && value > 0) {
|
|
|
|
in_batch_size = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_OUT_BATCH_SIZE:
|
|
|
|
if (is_int && value > 0) {
|
|
|
|
out_batch_size = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2019-09-29 17:30:37 +02:00
|
|
|
|
2021-05-15 00:05:56 +02:00
|
|
|
case ZMQ_BUSY_POLL:
|
|
|
|
if (is_int) {
|
|
|
|
busy_poll = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2019-12-11 12:13:34 +01:00
|
|
|
#ifdef ZMQ_HAVE_WSS
|
2019-09-29 17:30:37 +02:00
|
|
|
case ZMQ_WSS_KEY_PEM:
|
|
|
|
// TODO: check if valid certificate
|
|
|
|
wss_key_pem = std::string ((char *) optval_, optvallen_);
|
|
|
|
return 0;
|
|
|
|
case ZMQ_WSS_CERT_PEM:
|
|
|
|
// TODO: check if valid certificate
|
|
|
|
wss_cert_pem = std::string ((char *) optval_, optvallen_);
|
|
|
|
return 0;
|
|
|
|
case ZMQ_WSS_TRUST_PEM:
|
|
|
|
// TODO: check if valid certificate
|
|
|
|
wss_trust_pem = std::string ((char *) optval_, optvallen_);
|
|
|
|
return 0;
|
|
|
|
case ZMQ_WSS_HOSTNAME:
|
|
|
|
wss_hostname = std::string ((char *) optval_, optvallen_);
|
|
|
|
return 0;
|
|
|
|
case ZMQ_WSS_TRUST_SYSTEM:
|
|
|
|
return do_setsockopt_int_as_bool_strict (optval_, optvallen_,
|
|
|
|
&wss_trust_system);
|
2019-12-11 12:13:34 +01:00
|
|
|
#endif
|
2020-04-17 08:50:59 +02:00
|
|
|
|
|
|
|
case ZMQ_HELLO_MSG:
|
|
|
|
if (optvallen_ > 0) {
|
|
|
|
unsigned char *bytes = (unsigned char *) optval_;
|
|
|
|
hello_msg =
|
|
|
|
std::vector<unsigned char> (bytes, bytes + optvallen_);
|
|
|
|
} else {
|
|
|
|
hello_msg = std::vector<unsigned char> ();
|
|
|
|
}
|
|
|
|
|
2020-04-17 12:20:57 +02:00
|
|
|
return 0;
|
|
|
|
|
|
|
|
case ZMQ_DISCONNECT_MSG:
|
|
|
|
if (optvallen_ > 0) {
|
|
|
|
unsigned char *bytes = (unsigned char *) optval_;
|
|
|
|
disconnect_msg =
|
|
|
|
std::vector<unsigned char> (bytes, bytes + optvallen_);
|
|
|
|
} else {
|
|
|
|
disconnect_msg = std::vector<unsigned char> ();
|
|
|
|
}
|
2020-04-17 08:50:59 +02:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
2021-01-06 23:22:41 +01:00
|
|
|
case ZMQ_PRIORITY:
|
|
|
|
if (is_int && value >= 0) {
|
|
|
|
priority = value;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2021-06-06 13:28:29 +02:00
|
|
|
case ZMQ_HICCUP_MSG:
|
|
|
|
if (optvallen_ > 0) {
|
|
|
|
unsigned char *bytes = (unsigned char *) optval_;
|
|
|
|
hiccup_msg =
|
|
|
|
std::vector<unsigned char> (bytes, bytes + optvallen_);
|
|
|
|
} else {
|
|
|
|
hiccup_msg = std::vector<unsigned char> ();
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
|
|
|
|
|
2019-06-27 06:34:56 +02:00
|
|
|
#endif
|
|
|
|
|
2013-08-17 21:59:07 +02:00
|
|
|
default:
|
2014-06-17 16:14:19 +02:00
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
Problem: API violations are treated as recoverable errors
The example is applications passing invalid arguments to a socket option
and then failing to check the return code. The results can be very hard
to diagnose. Here are some threads that show the pain this causes:
* https://github.com/zeromq/zyre/issues/179
* http://lists.zeromq.org/pipermail/zeromq-dev/2014-June/026388.html
One common argument is that a library should never assert, and should
pass errors back to the calling application. The counter argument is
that when an application is broken enough to pass garbage to libzmq,
it cannot be trusted to handle the resulting errors properly. Empirical
evidence from CZMQ, where we systematically assert on bad arguments, is
that this militant approach makes applications more, not less, robust.
I don't see any valid use cases for returning errors on bad arguments,
with one exception: zmq_setsockopt can be used to probe whether libzmq
was e.g. built with CURVE security. I'd argue that it's nasty to use a
side effect like this. If apps need to probe how libzmq was built, this
should be done explicitly, and for ALL build options, not just CURVE.
There are/were no libzmq test cases that check the return code for an
invalid option.
For now I've enabled militant assertions using --with-militant at
configure time. However I'd like to make this the default setting.
2014-06-17 15:49:52 +02:00
|
|
|
// There are valid scenarios for probing with unknown socket option
|
|
|
|
// values, e.g. to check if security is enabled or not. This will not
|
|
|
|
// provoke a militant assert. However, passing bad values to a valid
|
|
|
|
// socket option will, if ZMQ_ACT_MILITANT is defined.
|
|
|
|
malformed = false;
|
2014-06-17 16:14:19 +02:00
|
|
|
#endif
|
2013-08-17 21:59:07 +02:00
|
|
|
break;
|
2013-01-30 23:53:09 +01:00
|
|
|
}
|
2018-03-06 11:16:22 +01:00
|
|
|
|
2019-05-18 18:02:06 +02:00
|
|
|
// TODO mechanism should either be set explicitly, or determined when
|
|
|
|
// connecting. currently, it depends on the order of setsockopt calls
|
|
|
|
// if there is some inconsistency, which is confusing. in addition,
|
|
|
|
// the assumed or set mechanism should be queryable (as a socket option)
|
2018-03-06 11:16:22 +01:00
|
|
|
|
Problem: API violations are treated as recoverable errors
The example is applications passing invalid arguments to a socket option
and then failing to check the return code. The results can be very hard
to diagnose. Here are some threads that show the pain this causes:
* https://github.com/zeromq/zyre/issues/179
* http://lists.zeromq.org/pipermail/zeromq-dev/2014-June/026388.html
One common argument is that a library should never assert, and should
pass errors back to the calling application. The counter argument is
that when an application is broken enough to pass garbage to libzmq,
it cannot be trusted to handle the resulting errors properly. Empirical
evidence from CZMQ, where we systematically assert on bad arguments, is
that this militant approach makes applications more, not less, robust.
I don't see any valid use cases for returning errors on bad arguments,
with one exception: zmq_setsockopt can be used to probe whether libzmq
was e.g. built with CURVE security. I'd argue that it's nasty to use a
side effect like this. If apps need to probe how libzmq was built, this
should be done explicitly, and for ALL build options, not just CURVE.
There are/were no libzmq test cases that check the return code for an
invalid option.
For now I've enabled militant assertions using --with-militant at
configure time. However I'd like to make this the default setting.
2014-06-17 15:49:52 +02:00
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
|
|
|
// There is no valid use case for passing an error back to the application
|
|
|
|
// when it sent malformed arguments to a socket option. Use ./configure
|
|
|
|
// --with-militant to enable this checking.
|
|
|
|
if (malformed)
|
|
|
|
zmq_assert (false);
|
|
|
|
#endif
|
2013-05-15 17:54:03 +02:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
2009-09-21 14:39:59 +02:00
|
|
|
}
|
2010-04-09 13:04:15 +02:00
|
|
|
|
2015-06-05 11:43:40 +02:00
|
|
|
int zmq::options_t::getsockopt (int option_,
|
|
|
|
void *optval_,
|
|
|
|
size_t *optvallen_) const
|
2010-04-09 13:04:15 +02:00
|
|
|
{
|
2018-05-30 13:13:31 +02:00
|
|
|
const bool is_int = (*optvallen_ == sizeof (int));
|
2018-05-18 15:54:00 +02:00
|
|
|
int *value = static_cast<int *> (optval_);
|
2014-06-17 16:24:56 +02:00
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
|
|
|
bool malformed = true; // Did caller pass a bad option value?
|
|
|
|
#endif
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2010-04-09 13:04:15 +02:00
|
|
|
switch (option_) {
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_SNDHWM:
|
|
|
|
if (is_int) {
|
|
|
|
*value = sndhwm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_RCVHWM:
|
|
|
|
if (is_int) {
|
|
|
|
*value = rcvhwm;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_AFFINITY:
|
|
|
|
if (*optvallen_ == sizeof (uint64_t)) {
|
2018-05-18 15:54:00 +02:00
|
|
|
*(static_cast<uint64_t *> (optval_)) = affinity;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2017-09-06 17:45:56 +02:00
|
|
|
case ZMQ_ROUTING_ID:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, routing_id,
|
|
|
|
routing_id_size);
|
2013-05-15 17:54:03 +02:00
|
|
|
|
|
|
|
case ZMQ_RATE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = rate;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_RECOVERY_IVL:
|
|
|
|
if (is_int) {
|
|
|
|
*value = recovery_ivl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_SNDBUF:
|
|
|
|
if (is_int) {
|
|
|
|
*value = sndbuf;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_RCVBUF:
|
|
|
|
if (is_int) {
|
|
|
|
*value = rcvbuf;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-11-25 04:01:21 +01:00
|
|
|
case ZMQ_TOS:
|
|
|
|
if (is_int) {
|
|
|
|
*value = tos;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-08-12 09:31:19 +02:00
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_TYPE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = type;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_LINGER:
|
|
|
|
if (is_int) {
|
2018-02-08 23:10:45 +01:00
|
|
|
*value = linger.load ();
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2010-04-09 13:04:15 +02:00
|
|
|
|
2015-08-04 14:47:07 +02:00
|
|
|
case ZMQ_CONNECT_TIMEOUT:
|
|
|
|
if (is_int) {
|
|
|
|
*value = connect_timeout;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-02-09 09:33:29 +01:00
|
|
|
case ZMQ_TCP_MAXRT:
|
2015-08-06 17:36:27 +02:00
|
|
|
if (is_int) {
|
2016-02-09 09:33:29 +01:00
|
|
|
*value = tcp_maxrt;
|
2015-08-06 17:36:27 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2020-02-23 18:17:22 +01:00
|
|
|
case ZMQ_RECONNECT_STOP:
|
|
|
|
if (is_int) {
|
|
|
|
*value = reconnect_stop;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_RECONNECT_IVL:
|
|
|
|
if (is_int) {
|
|
|
|
*value = reconnect_ivl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_RECONNECT_IVL_MAX:
|
|
|
|
if (is_int) {
|
|
|
|
*value = reconnect_ivl_max;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_BACKLOG:
|
|
|
|
if (is_int) {
|
|
|
|
*value = backlog;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_MAXMSGSIZE:
|
|
|
|
if (*optvallen_ == sizeof (int64_t)) {
|
2018-05-18 15:54:00 +02:00
|
|
|
*(static_cast<int64_t *> (optval_)) = maxmsgsize;
|
2013-05-15 17:54:03 +02:00
|
|
|
*optvallen_ = sizeof (int64_t);
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_MULTICAST_HOPS:
|
|
|
|
if (is_int) {
|
|
|
|
*value = multicast_hops;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-11-23 20:35:02 +01:00
|
|
|
case ZMQ_MULTICAST_MAXTPDU:
|
|
|
|
if (is_int) {
|
|
|
|
*value = multicast_maxtpdu;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_RCVTIMEO:
|
|
|
|
if (is_int) {
|
|
|
|
*value = rcvtimeo;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_SNDTIMEO:
|
|
|
|
if (is_int) {
|
|
|
|
*value = sndtimeo;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_IPV4ONLY:
|
|
|
|
if (is_int) {
|
|
|
|
*value = 1 - ipv6;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_IPV6:
|
|
|
|
if (is_int) {
|
|
|
|
*value = ipv6;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_IMMEDIATE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = immediate;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2014-06-22 10:32:22 +02:00
|
|
|
case ZMQ_SOCKS_PROXY:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, socks_proxy_address);
|
2014-06-22 10:32:22 +02:00
|
|
|
|
2019-06-10 15:01:23 +02:00
|
|
|
case ZMQ_SOCKS_USERNAME:
|
|
|
|
return do_getsockopt (optval_, optvallen_, socks_proxy_username);
|
|
|
|
|
|
|
|
case ZMQ_SOCKS_PASSWORD:
|
|
|
|
return do_getsockopt (optval_, optvallen_, socks_proxy_password);
|
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_TCP_KEEPALIVE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = tcp_keepalive;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_TCP_KEEPALIVE_CNT:
|
|
|
|
if (is_int) {
|
|
|
|
*value = tcp_keepalive_cnt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_TCP_KEEPALIVE_IDLE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = tcp_keepalive_idle;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_TCP_KEEPALIVE_INTVL:
|
|
|
|
if (is_int) {
|
|
|
|
*value = tcp_keepalive_intvl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_MECHANISM:
|
|
|
|
if (is_int) {
|
|
|
|
*value = mechanism;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-09-17 14:05:41 +02:00
|
|
|
case ZMQ_PLAIN_SERVER:
|
2013-05-15 17:54:03 +02:00
|
|
|
if (is_int) {
|
2013-09-17 14:05:41 +02:00
|
|
|
*value = as_server && mechanism == ZMQ_PLAIN;
|
2013-05-15 17:54:03 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_PLAIN_USERNAME:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, plain_username);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-05-15 17:54:03 +02:00
|
|
|
case ZMQ_PLAIN_PASSWORD:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, plain_password);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
|
|
|
case ZMQ_ZAP_DOMAIN:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, zap_domain);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2016-02-11 13:32:01 +01:00
|
|
|
// If curve encryption isn't built, these options provoke EINVAL
|
|
|
|
#ifdef ZMQ_HAVE_CURVE
|
2013-09-17 14:05:41 +02:00
|
|
|
case ZMQ_CURVE_SERVER:
|
2013-06-20 18:09:12 +02:00
|
|
|
if (is_int) {
|
2013-09-17 14:05:55 +02:00
|
|
|
*value = as_server && mechanism == ZMQ_CURVE;
|
2013-06-20 18:09:12 +02:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
case ZMQ_CURVE_PUBLICKEY:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt_curve_key (optval_, optvallen_,
|
|
|
|
curve_public_key);
|
2013-09-09 20:40:34 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
case ZMQ_CURVE_SECRETKEY:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt_curve_key (optval_, optvallen_,
|
|
|
|
curve_secret_key);
|
2013-09-17 12:44:14 +02:00
|
|
|
|
2013-09-17 14:05:55 +02:00
|
|
|
case ZMQ_CURVE_SERVERKEY:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt_curve_key (optval_, optvallen_,
|
|
|
|
curve_server_key);
|
2016-02-11 13:32:01 +01:00
|
|
|
#endif
|
2013-08-17 21:59:07 +02:00
|
|
|
|
|
|
|
case ZMQ_CONFLATE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = conflate;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-08-12 09:31:19 +02:00
|
|
|
|
2014-06-17 16:32:47 +02:00
|
|
|
// If libgssapi isn't installed, these options provoke EINVAL
|
2016-02-11 13:32:01 +01:00
|
|
|
#ifdef HAVE_LIBGSSAPI_KRB5
|
2013-09-25 05:20:01 +02:00
|
|
|
case ZMQ_GSSAPI_SERVER:
|
|
|
|
if (is_int) {
|
|
|
|
*value = as_server && mechanism == ZMQ_GSSAPI;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2013-11-20 23:01:16 +01:00
|
|
|
|
2014-04-23 19:20:22 +02:00
|
|
|
case ZMQ_GSSAPI_PRINCIPAL:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, gss_principal);
|
2013-08-17 21:59:07 +02:00
|
|
|
|
2014-04-23 19:20:22 +02:00
|
|
|
case ZMQ_GSSAPI_SERVICE_PRINCIPAL:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, gss_service_principal);
|
2013-09-25 05:20:01 +02:00
|
|
|
|
2014-04-23 20:01:54 +02:00
|
|
|
case ZMQ_GSSAPI_PLAINTEXT:
|
|
|
|
if (is_int) {
|
|
|
|
*value = gss_plaintext;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2017-04-25 19:07:58 +02:00
|
|
|
|
2017-04-24 23:57:15 +02:00
|
|
|
case ZMQ_GSSAPI_PRINCIPAL_NAMETYPE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = gss_principal_nt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
case ZMQ_GSSAPI_SERVICE_PRINCIPAL_NAMETYPE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = gss_service_principal_nt;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-06-17 16:32:47 +02:00
|
|
|
#endif
|
|
|
|
|
2014-05-09 15:54:24 +02:00
|
|
|
case ZMQ_HANDSHAKE_IVL:
|
|
|
|
if (is_int) {
|
|
|
|
*value = handshake_ivl;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2014-08-08 19:36:00 +02:00
|
|
|
|
2015-01-26 15:59:19 +01:00
|
|
|
case ZMQ_INVERT_MATCHING:
|
|
|
|
if (is_int) {
|
|
|
|
*value = invert_matching;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2015-03-17 02:39:16 +01:00
|
|
|
case ZMQ_HEARTBEAT_IVL:
|
|
|
|
if (is_int) {
|
|
|
|
*value = heartbeat_interval;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_HEARTBEAT_TTL:
|
|
|
|
if (is_int) {
|
2015-06-26 20:08:08 +02:00
|
|
|
// Convert the internal deciseconds value to milliseconds
|
|
|
|
*value = heartbeat_ttl * 100;
|
2015-03-17 02:39:16 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_HEARTBEAT_TIMEOUT:
|
|
|
|
if (is_int) {
|
|
|
|
*value = heartbeat_timeout;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2016-02-09 10:36:14 +01:00
|
|
|
case ZMQ_USE_FD:
|
2016-02-01 13:00:45 +01:00
|
|
|
if (is_int) {
|
2016-02-09 10:36:14 +01:00
|
|
|
*value = use_fd;
|
2016-02-01 13:00:45 +01:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
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-28 15:35:09 +02:00
|
|
|
case ZMQ_BINDTODEVICE:
|
2018-03-06 11:16:22 +01:00
|
|
|
return do_getsockopt (optval_, optvallen_, bound_device);
|
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-28 15:35:09 +02:00
|
|
|
|
2017-10-07 19:34:18 +02:00
|
|
|
case ZMQ_ZAP_ENFORCE_DOMAIN:
|
|
|
|
if (is_int) {
|
|
|
|
*value = zap_enforce_domain;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-02-05 17:09:39 +01:00
|
|
|
case ZMQ_LOOPBACK_FASTPATH:
|
|
|
|
if (is_int) {
|
|
|
|
*value = loopback_fastpath;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-05-10 16:56:49 +02:00
|
|
|
case ZMQ_MULTICAST_LOOP:
|
|
|
|
if (is_int) {
|
|
|
|
*value = multicast_loop;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
2018-08-15 09:54:08 +02:00
|
|
|
#ifdef ZMQ_BUILD_DRAFT_API
|
|
|
|
case ZMQ_ROUTER_NOTIFY:
|
|
|
|
if (is_int) {
|
|
|
|
*value = router_notify;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2020-06-27 00:41:44 +02:00
|
|
|
|
2019-06-27 06:34:56 +02:00
|
|
|
case ZMQ_IN_BATCH_SIZE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = in_batch_size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
case ZMQ_OUT_BATCH_SIZE:
|
|
|
|
if (is_int) {
|
|
|
|
*value = out_batch_size;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2021-01-06 23:22:41 +01:00
|
|
|
|
|
|
|
case ZMQ_PRIORITY:
|
|
|
|
if (is_int) {
|
|
|
|
*value = priority;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
break;
|
2021-05-15 00:05:56 +02:00
|
|
|
|
|
|
|
case ZMQ_BUSY_POLL:
|
|
|
|
if (is_int) {
|
|
|
|
*value = busy_poll;
|
|
|
|
}
|
|
|
|
break;
|
2018-08-15 09:54:08 +02:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2014-06-17 16:24:56 +02:00
|
|
|
default:
|
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
|
|
|
malformed = false;
|
|
|
|
#endif
|
|
|
|
break;
|
Problem: API violations are treated as recoverable errors
The example is applications passing invalid arguments to a socket option
and then failing to check the return code. The results can be very hard
to diagnose. Here are some threads that show the pain this causes:
* https://github.com/zeromq/zyre/issues/179
* http://lists.zeromq.org/pipermail/zeromq-dev/2014-June/026388.html
One common argument is that a library should never assert, and should
pass errors back to the calling application. The counter argument is
that when an application is broken enough to pass garbage to libzmq,
it cannot be trusted to handle the resulting errors properly. Empirical
evidence from CZMQ, where we systematically assert on bad arguments, is
that this militant approach makes applications more, not less, robust.
I don't see any valid use cases for returning errors on bad arguments,
with one exception: zmq_setsockopt can be used to probe whether libzmq
was e.g. built with CURVE security. I'd argue that it's nasty to use a
side effect like this. If apps need to probe how libzmq was built, this
should be done explicitly, and for ALL build options, not just CURVE.
There are/were no libzmq test cases that check the return code for an
invalid option.
For now I've enabled militant assertions using --with-militant at
configure time. However I'd like to make this the default setting.
2014-06-17 15:49:52 +02:00
|
|
|
}
|
2014-06-17 16:24:56 +02:00
|
|
|
#if defined(ZMQ_ACT_MILITANT)
|
|
|
|
if (malformed)
|
|
|
|
zmq_assert (false);
|
|
|
|
#endif
|
2010-04-09 13:04:15 +02:00
|
|
|
errno = EINVAL;
|
|
|
|
return -1;
|
|
|
|
}
|