From f16ea39889c0fd65f3e533cf40cc3a0a33ac1c33 Mon Sep 17 00:00:00 2001 From: Dirk Engling Date: Tue, 3 Nov 2026 06:02:47 +0100 Subject: Let a user pick their cluster's own multicast group --- src/ot_config.c | 6 ++++++ src/ot_livesync.c | 18 ++++++++++++++---- src/ot_livesync.h | 4 ++++ 3 files changed, 24 insertions(+), 4 deletions(-) (limited to 'src') diff --git a/src/ot_config.c b/src/ot_config.c index 95136b5..4064d1b 100644 --- a/src/ot_config.c +++ b/src/ot_config.c @@ -208,6 +208,7 @@ typedef enum { CONFIG_TRACKER_REDIRECT_URL, CONFIG_LIVESYNC_CLUSTER_NODE_IP, CONFIG_LIVESYNC_CLUSTER_LISTEN, + CONFIG_LIVESYNC_CLUSTER_GROUP, } config_kind; typedef struct { @@ -247,6 +248,7 @@ static const config_key config_keys[] = { #ifdef WANT_SYNC_LIVE CONFIG_KEY("livesync.cluster.node_ip", CONFIG_LIVESYNC_CLUSTER_NODE_IP), CONFIG_KEY("livesync.cluster.listen", CONFIG_LIVESYNC_CLUSTER_LISTEN), + CONFIG_KEY("livesync.cluster.group", CONFIG_LIVESYNC_CLUSTER_GROUP), #endif }; static const size_t config_entry_count = sizeof(config_keys) / sizeof(config_keys[0]); @@ -378,6 +380,10 @@ static int parse_configfile(char *config_filename) { set_config_option(&g_redirecturl, p); break; #ifdef WANT_SYNC_LIVE + case CONFIG_LIVESYNC_CLUSTER_GROUP: + if (!ip_parse(p, tmpip) || livesync_set_group(tmpip) == -1) + goto parse_error; + break; case CONFIG_LIVESYNC_CLUSTER_NODE_IP: if (!scan_ip6_net(p, &tmpnet)) goto parse_error; diff --git a/src/ot_livesync.c b/src/ot_livesync.c index 11b75d2..85577f7 100644 --- a/src/ot_livesync.c +++ b/src/ot_livesync.c @@ -22,8 +22,10 @@ #ifdef WANT_SYNC_LIVE -ot_ip6 groupip_1 = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 224, 0, 23, 5}; -static uint16_t g_port = LIVESYNC_PORT; +/* The multicast group, legacy opentrackers joined by default 224.0.23.5, so it + stays the default */ +static ot_ip6 g_group = {0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0xff, 0xff, 224, 0, 23, 5}; +static uint16_t g_port = LIVESYNC_PORT; #define LIVESYNC_INCOMING_BUFFSIZE (256 * 256) @@ -96,6 +98,14 @@ void livesync_deinit(void) { close(g_socket_out); } +int livesync_set_group(const ot_ip6 group) { + /* v4 multicast is 224.0.0.0/4, and the socket layer has nothing else */ + if (!ip_is_v4mapped(group) || (group[12] & 0xf0) != 0xe0) + return -1; + memcpy(g_group, group, sizeof(ot_ip6)); + return 0; +} + void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { if (!ip_is_v4mapped(ip)) exerr("v6 mcast support not yet available."); @@ -105,7 +115,7 @@ void livesync_bind_mcast(ot_ip6 ip, uint16_t port) { g_port = port; - if ((g_socket_in = socket_mcast_join(groupip_1, ip, port)) == -1) + if ((g_socket_in = socket_mcast_join(g_group, ip, port)) == -1) exerr("Error: Cant bind live sync incoming socket."); if ((g_socket_out = socket_mcast_bind(ip, port, 0)) == -1) @@ -125,7 +135,7 @@ static void livesync_issue_peersync(sync_buffer *buf) { has modified the protected element */ pthread_mutex_unlock(&g_outbuf_mutex); - socket_mcast_send(g_socket_out, mycopy, fill, groupip_1, g_port); + socket_mcast_send(g_socket_out, mycopy, fill, g_group, g_port); } static void livesync_handle_peersync(struct ot_workstruct *ws, size_t peer_size) { diff --git a/src/ot_livesync.h b/src/ot_livesync.h index d8d20b3..cf3c64c 100644 --- a/src/ot_livesync.h +++ b/src/ot_livesync.h @@ -48,6 +48,10 @@ void livesync_init(void); void livesync_deinit(void); +/* The group to join and to send to, (defaults to 224.0.23.5). + Returns -1 if group is not a v4 multicast address. */ +int livesync_set_group(const ot_ip6 group); + /* Join multicast group for listening and create sending socket */ void livesync_bind_mcast(ot_ip6 ip, uint16_t port); -- cgit v1.3