Skip to content

Commit 064d057

Browse files
committed
cluster_backend_zeromq: Set Cluster::Backend::ZeroMQ::ipv6=T when needed
Now that Cluster::Backend::ZeroMQ::ipv6 defaults to false, ensure it is toggled to true if any of the node addresses resolves to an IPv6 address. Also, add brackets around IPv6 addresses for the ZeroMQ endpoints as otherwise ZeroMQ will consider the addresses as a device. Add a test for this, too. Relates to #5251
1 parent 2deebcd commit 064d057

8 files changed

Lines changed: 52 additions & 0 deletions

File tree

ZeekControl/plugins/cluster_backend_zeromq.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,12 @@ def init(self):
4646
# The manager address is used for listening of the XPUB/XSUB proxy.
4747
self.xpub_xsub_addr = ZeekControl.config.Config.manager().addr
4848

49+
# If the address looks like an IPv6 address, put brackets around it
50+
# so that libzmq does not interpret it as a device and instead as
51+
# an IPv6 address.
52+
if ":" in self.xpub_xsub_addr:
53+
self.xpub_xsub_addr = "[" + self.xpub_xsub_addr + "]"
54+
4955
# Check if this is a multi-node cluster (multiple IP addresses) and
5056
# tell the user about it.
5157
addrs = {n.addr for n in self.nodes()}
@@ -66,6 +72,12 @@ def init(self):
6672
"\n cluster_backend_zeromq.disable_unencrypted_warning = 1\n"
6773
)
6874

75+
# If any of the addresses used by nodes looks like an IPv6 address,
76+
# enable ZeroMQ IPv6 support via the configuration knob.
77+
self.ipv6 = False
78+
if any(":" in a for a in addrs):
79+
self.ipv6 = True
80+
6981
return True
7082

7183
def zeekctl_config(self):
@@ -86,6 +98,8 @@ def zeekctl_config(self):
8698
f'redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://{self.xpub_xsub_addr}:{self.xsub_port}";',
8799
f'redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://{self.xpub_xsub_addr}:{self.xpub_port}";',
88100
"",
101+
f'redef Cluster::Backend::ZeroMQ::ipv6 = {"T" if self.ipv6 else "F"};',
102+
"",
89103
]
90104
)
91105

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
### BTest baseline data generated by btest-diff. Do not edit. Use "btest -U/-u" to update. Requires BTest >= 0.63.
2+
@endif
3+
4+
redef Cluster::Backend::ZeroMQ::listen_xpub_endpoint = "tcp://[::1]:27760";
5+
redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://[::1]:27761";
6+
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://[::1]:27761";
7+
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://[::1]:27760";
8+
9+
redef Cluster::Backend::ZeroMQ::ipv6 = T;
10+
11+
# End code from cluster_backend_zeromq plugin

testing/Baseline/command.install-empty-file-extract-dir/standalone

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
2929
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
3030
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";
3131

32+
redef Cluster::Backend::ZeroMQ::ipv6 = F;
33+
3234
# Standalone: Run the XPUB/XSUB thread in standalone mode
3335
redef Cluster::Backend::ZeroMQ::run_proxy_thread = T;
3436

testing/Baseline/command.install-zeekctl-config/logger

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
3232
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
3333
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";
3434

35+
redef Cluster::Backend::ZeroMQ::ipv6 = F;
36+
3537
# End code from cluster_backend_zeromq plugin

testing/Baseline/command.install-zeekctl-config/no-logger

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,4 +32,6 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
3232
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
3333
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";
3434

35+
redef Cluster::Backend::ZeroMQ::ipv6 = F;
36+
3537
# End code from cluster_backend_zeromq plugin

testing/Baseline/command.install-zeekctl-config/standalone

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,8 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
3030
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
3131
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";
3232

33+
redef Cluster::Backend::ZeroMQ::ipv6 = F;
34+
3335
# Standalone: Run the XPUB/XSUB thread in standalone mode
3436
redef Cluster::Backend::ZeroMQ::run_proxy_thread = T;
3537

testing/Baseline/plugin.zeekctl-config/out

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ redef Cluster::Backend::ZeroMQ::listen_xsub_endpoint = "tcp://127.0.0.1:27761";
1212
redef Cluster::Backend::ZeroMQ::connect_xpub_endpoint = "tcp://127.0.0.1:27761";
1313
redef Cluster::Backend::ZeroMQ::connect_xsub_endpoint = "tcp://127.0.0.1:27760";
1414

15+
redef Cluster::Backend::ZeroMQ::ipv6 = F;
16+
1517
# Standalone: Run the XPUB/XSUB thread in standalone mode
1618
redef Cluster::Backend::ZeroMQ::run_proxy_thread = T;
1719

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
# @TEST-DOC: Test using IPv6 addresses enabled the Cluster::Backend::ZeroMQ::ipv6 option.
2+
#
3+
# @TEST-EXEC: bash %INPUT
4+
#
5+
# @TEST-EXEC: btest-diff zeekctl-config-redefs
6+
7+
. zeekctl-test-setup
8+
9+
config=$ZEEKCTL_INSTALL_PREFIX/spool/installed-scripts-do-not-touch/auto/zeekctl-config.zeek
10+
11+
installfile etc/node.cfg__cluster
12+
# Replace localhost with ::1 and verify that the ZeroMQ endpoints have
13+
# brackets and that the ipv6 option is set to T.
14+
sed -i 's/localhost/::1/g' $ZEEKCTL_INSTALL_PREFIX/etc/node.cfg
15+
zeekctl install
16+
17+
grep -C2 'redef.*Cluster::Backend' $config > zeekctl-config-redefs

0 commit comments

Comments
 (0)