Skip to content

Commit dc87bb9

Browse files
committed
clusterer_controller: a socket drops other groups' multicast from the moment it is bound
IP_MULTICAST_ALL was cleared after bind() and IP_ADD_MEMBERSHIP, so the second cluster's socket on a shared port could queue the first cluster's multicast in between; its worker then forwarded the packet to the first cluster's worker, which had it already and logged it as a replay (netns group 8 under ASan, a node restarting while its first cluster was busy). The option is now set before bind().
1 parent 910a24e commit dc87bb9

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

‎modules-contrib/clusterer_controller/cl_ctr_wire.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,19 @@ int cl_ctr_setup_socket(cl_ctr_cluster_t *cl)
225225
}
226226
}
227227

228+
#ifdef IP_MULTICAST_ALL
229+
/* Linux delivers every group joined on this port host-wide by default, so
230+
* sibling clusters would read each other's multicast; must precede bind() */
231+
{
232+
int mc_all = 0;
233+
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_ALL,
234+
&mc_all, sizeof(mc_all)) < 0)
235+
LM_WARN("clusterer_controller: [cluster %d] IP_MULTICAST_ALL: %s - "
236+
"this socket may also receive other groups joined on port %d\n",
237+
cl->cluster_id, strerror(errno), cl->multicast_port);
238+
}
239+
#endif
240+
228241
if (bind(sock, (struct sockaddr *)&local, sizeof(local)) < 0) {
229242
LM_ERR("clusterer_controller: bind() port %d: %s\n",
230243
cl->multicast_port, strerror(errno));
@@ -246,19 +259,6 @@ int cl_ctr_setup_socket(cl_ctr_cluster_t *cl)
246259
return -1;
247260
}
248261

249-
#ifdef IP_MULTICAST_ALL
250-
/* Linux delivers every group joined on this port host-wide by default, so
251-
* sibling clusters would read each other's multicast */
252-
{
253-
int mc_all = 0;
254-
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_ALL,
255-
&mc_all, sizeof(mc_all)) < 0)
256-
LM_WARN("clusterer_controller: [cluster %d] IP_MULTICAST_ALL: %s - "
257-
"this socket may also receive other groups joined on port %d\n",
258-
cl->cluster_id, strerror(errno), cl->multicast_port);
259-
}
260-
#endif
261-
262262
if (setsockopt(sock, IPPROTO_IP, IP_MULTICAST_LOOP,
263263
&loop, sizeof(loop)) < 0)
264264
LM_WARN("clusterer_controller: IP_MULTICAST_LOOP: %s\n",

0 commit comments

Comments
 (0)