Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions ZeekControl/plugins/cluster_backend_zeromq.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ def init(self):
# The manager address is used for listening of the XPUB/XSUB proxy.
self.xpub_xsub_addr = ZeekControl.config.Config.manager().addr

# If the address looks like an IPv6 address, put brackets around it
# so that libzmq does not interpret it as a device and instead as
# an IPv6 address.
if ":" in self.xpub_xsub_addr:
self.xpub_xsub_addr = "[" + self.xpub_xsub_addr + "]"

# Check if this is a multi-node cluster (multiple IP addresses) and
# tell the user about it.
addrs = {n.addr for n in self.nodes()}
Expand All @@ -66,6 +72,12 @@ def init(self):
"\n cluster_backend_zeromq.disable_unencrypted_warning = 1\n"
)

# If any of the addresses used by nodes looks like an IPv6 address,
# enable ZeroMQ IPv6 support via the configuration knob.
self.ipv6 = False
if any(":" in a for a in addrs):
self.ipv6 = True

return True

def zeekctl_config(self):
Expand All @@ -86,6 +98,8 @@ def zeekctl_config(self):
f'redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://{self.xpub_xsub_addr}:{self.xsub_port}";',
f'redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://{self.xpub_xsub_addr}:{self.xpub_port}";',
"",
f'redef Cluster::Backend::ZeroMQ::ipv6 = {"T" if self.ipv6 else "F"};',
"",
]
)

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
@endif

redef Cluster::Backend::ZeroMQ::listen_xpub_endpoint = "tcp://[::1]:27760";
redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://[::1]:27761";
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://[::1]:27761";
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://[::1]:27760";

redef Cluster::Backend::ZeroMQ::ipv6 = T;

# End code from cluster_backend_zeromq plugin
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";

redef Cluster::Backend::ZeroMQ::ipv6 = F;

# Standalone: Run the XPUB/XSUB thread in standalone mode
redef Cluster::Backend::ZeroMQ::run_proxy_thread = T;

Expand Down
2 changes: 2 additions & 0 deletions testing/Baseline/command.install-zeekctl-config/logger
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";

redef Cluster::Backend::ZeroMQ::ipv6 = F;

# End code from cluster_backend_zeromq plugin
2 changes: 2 additions & 0 deletions testing/Baseline/command.install-zeekctl-config/no-logger
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,6 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";

redef Cluster::Backend::ZeroMQ::ipv6 = F;

# End code from cluster_backend_zeromq plugin
2 changes: 2 additions & 0 deletions testing/Baseline/command.install-zeekctl-config/standalone
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";

redef Cluster::Backend::ZeroMQ::ipv6 = F;

# Standalone: Run the XPUB/XSUB thread in standalone mode
redef Cluster::Backend::ZeroMQ::run_proxy_thread = T;

Expand Down
2 changes: 2 additions & 0 deletions testing/Baseline/plugin.zeekctl-config/out
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";

redef Cluster::Backend::ZeroMQ::ipv6 = F;

# Standalone: Run the XPUB/XSUB thread in standalone mode
redef Cluster::Backend::ZeroMQ::run_proxy_thread = T;

Expand Down
17 changes: 17 additions & 0 deletions testing/command/install-cluster-backend-zeromq-ipv6.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# @TEST-DOC: Test using IPv6 addresses enabled the Cluster::Backend::ZeroMQ::ipv6 option.
#
# @TEST-EXEC: bash %INPUT
#
# @TEST-EXEC: btest-diff zeekctl-config-redefs

. zeekctl-test-setup

config=$ZEEKCTL_INSTALL_PREFIX/spool/installed-scripts-do-not-touch/auto/zeekctl-config.zeek

installfile etc/node.cfg__cluster
# Replace localhost with ::1 and verify that the ZeroMQ endpoints have
# brackets and that the ipv6 option is set to T.
sed -i 's/localhost/::1/g' $ZEEKCTL_INSTALL_PREFIX/etc/node.cfg
zeekctl install

grep -C2 'redef.*Cluster::Backend' $config > zeekctl-config-redefs
Loading