From a6b99c07d17c9cd373d13a19cb5b3a0853e31654 Mon Sep 17 00:00:00 2001 From: Aaron Jones Date: Tue, 5 Jul 2022 06:01:26 +0000 Subject: [PATCH] serv_connect(): ensure both sa_bind[]/sa_connect[] are always populated (#352) Due to [1], linking with SCTP sometimes does not multi-home correctly. This is triggered by the rand() on the lines immediately above these. The connect{} blocks already support an `aftype` parameter to instruct IRCd to prefer IPv4 or IPv6. This commit additionally ensures that the other structure is always populated with the other address (if any) if this parameter is specified. This will allow SCTP server-linking users to work around the bug and ensure that it always multi-homes by setting `connect::aftype` to IPv4. Without this commit, that would cause Solanum to not include the IPv6 addresses (if any) in the connect block in its SCTP setup. If there isn't a valid IP address in the other sockaddr, this should be of no consequence, because it will not be used by rb_connect_tcp(), and both rb_connect_sctp() and rb_sctp_bindx_only() already verify that there is a valid IP address in the sockaddr before making use of it. [1] https://marc.info/?l=linux-sctp&m=165684809726472&w=2 --- ircd/s_serv.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/ircd/s_serv.c b/ircd/s_serv.c index 98caf93a..7337db8f 100644 --- a/ircd/s_serv.c +++ b/ircd/s_serv.c @@ -1017,12 +1017,16 @@ serv_connect(struct server_conf *server_p, struct Client *by) else if(server_p->aftype == AF_INET || GET_SS_FAMILY(&server_p->connect4) == AF_INET) { sa_connect[0] = server_p->connect4; + sa_connect[1] = server_p->connect6; sa_bind[0] = server_p->bind4; + sa_bind[1] = server_p->bind6; } else if(server_p->aftype == AF_INET6 || GET_SS_FAMILY(&server_p->connect6) == AF_INET6) { sa_connect[0] = server_p->connect6; + sa_connect[1] = server_p->connect4; sa_bind[0] = server_p->bind6; + sa_bind[1] = server_p->bind4; } /* log */