From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from [87.239.111.99] (localhost [127.0.0.1]) by dev.tarantool.org (Postfix) with ESMTP id 4C3FC6EC56; Thu, 18 Mar 2021 03:02:37 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 4C3FC6EC56 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=tarantool.org; s=dev; t=1616025757; bh=0FjWl+voE6a2BjKD/MU/3qb+rNZJXbazNkalgejf//I=; h=To:Date:In-Reply-To:References:Subject:List-Id:List-Unsubscribe: List-Archive:List-Post:List-Help:List-Subscribe:From:Reply-To: From; b=npun1Eb/X1wftYeQ/1MSVzFjXnefWGojA/fY52U2tFzCO7h91LuyUrlJDvxYrPf30 Ull0Gj+zbw9tre9S7ip3/Jkj9yadGS2832NSaX3XCyL95+dpIzEUBtunvxdVJQ/cmY WTmTAq2069C8MaiV/tawwO/7x/1CcUmtF8yLD69g= Received: from smtpng3.m.smailru.net (smtpng3.m.smailru.net [94.100.177.149]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dev.tarantool.org (Postfix) with ESMTPS id 217346EC56 for ; Thu, 18 Mar 2021 03:02:07 +0300 (MSK) DKIM-Filter: OpenDKIM Filter v2.11.0 dev.tarantool.org 217346EC56 Received: by smtpng3.m.smailru.net with esmtpa (envelope-from ) id 1lMg74-0006fv-Ca; Thu, 18 Mar 2021 03:02:06 +0300 To: tarantool-patches@dev.tarantool.org, gorcunov@gmail.com, sergepetrenko@tarantool.org Date: Thu, 18 Mar 2021 01:02:03 +0100 Message-Id: X-Mailer: git-send-email 2.24.3 (Apple Git-128) In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-7564579A: 646B95376F6C166E X-77F55803: 4F1203BC0FB41BD96485A7A9FC13189387C0BEA1E3D4462C4B99C4D0C48865C5182A05F53808504062581B7F65981BCA9708BE665B267805084705230AA6619418CD15F39ECF78F3 X-7FA49CB5: FF5795518A3D127A4AD6D5ED66289B5278DA827A17800CE712EB008F780777E9EA1F7E6F0F101C67BD4B6F7A4D31EC0BCC500DACC3FED6E28638F802B75D45FF8AA50765F790063726CA83C7ABDB938E8638F802B75D45FF914D58D5BE9E6BC131B5C99E7648C95CF89CA98302ED496FAE0A24F8E5B38BE878BFF26C95E843E8A471835C12D1D9774AD6D5ED66289B5278DA827A17800CE71AE4D56B06699BBC9FA2833FD35BB23D2EF20D2F80756B5F868A13BD56FB6657A471835C12D1D977725E5C173C3A84C317B107DEF921CE79117882F4460429728AD0CFFFB425014E868A13BD56FB6657A7F4EDE966BC389F9E8FC8737B5C2249BF3059D42242344A089D37D7C0E48F6CCF19DD082D7633A0E7DDDDC251EA7DABAAAE862A0553A39223F8577A6DFFEA7C74F8CD32ECFF047543847C11F186F3C5E7DDDDC251EA7DABCC89B49CDF41148F90DBEB212AEC08F22623479134186CDE6BA297DBC24807EABDAD6C7F3747799A X-B7AD71C0: AC4F5C86D027EB782CDD5689AFBDA7A2BBE337FB72E923155C0AF1600DCBC20BB63DED767380FDF6A760FB8BC5CA0399 X-C1DE0DAB: C20DE7B7AB408E4181F030C43753B8186998911F362727C414F749A5E30D975CF89CA98302ED496FAE0A24F8E5B38BE878BFF26C95E843E89C2B6934AE262D3EE7EAB7254005DCED7532B743992DF240BDC6A1CF3F042BAD6DF99611D93F60EF0417BEADF48D1460699F904B3F4130E343918A1A30D5E7FCCB5012B2E24CD356 X-C8649E89: 4E36BF7865823D7055A7F0CF078B5EC49A30900B95165D34A783A638E01A3CDEB7065723B3F71CC1DB841222DB50894C09DF571726A21EB172B85F3F66C5D9D61D7E09C32AA3244C4349442278A2D1FD018A91519425DF5FE3D93501275E802FFACE5A9C96DEB163 X-D57D3AED: 3ZO7eAau8CL7WIMRKs4sN3D3tLDjz0dLbV79QFUyzQ2Ujvy7cMT6pYYqY16iZVKkSc3dCLJ7zSJH7+u4VD18S7Vl4ZUrpaVfd2+vE6kuoey4m4VkSEu530nj6fImhcD4MUrOEAnl0W826KZ9Q+tr5ycPtXkTV4k65bRjmOUUP8cvGozZ33TWg5HZplvhhXbhDGzqmQDTd6OAevLeAnq3Ra9uf7zvY2zzsIhlcp/Y7m53TZgf2aB4JOg4gkr2biojBN5tWX4G0Zw40tO0h8Ihaw== X-Mailru-Sender: 689FA8AB762F73936BC43F508A06382223FF3F6E265658CF3A129B8A228CCDFB3841015FED1DE5223CC9A89AB576DD93FB559BB5D741EB963CF37A108A312F5C27E8A8C3839CE0E267EA787935ED9F1B X-Mras: Ok Subject: [Tarantool-patches] [PATCH 1/2] swim: add SO_BROADCAST option X-BeenThere: tarantool-patches@dev.tarantool.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: Tarantool development patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , From: Vladislav Shpilevoy via Tarantool-patches Reply-To: Vladislav Shpilevoy Errors-To: tarantool-patches-bounces@dev.tarantool.org Sender: "Tarantool-patches" Swim node couldn't talk to broadcast network interfaces because the option SO_BROADCAST wasn't set. It worked fine for localhost broadcast, but failed for all the other IPs. There is no a test, because the tests work for the localhost only anyway. It still fails on Mac though in case the swim node was bound to 127.0.0.1. Then somewhy sendto() raises EADDRNOTAVAIL on attempt to broadcast beyond the local machine. Not present on Linux, where such an error simply can't be returned from sendto(). This error is ignored on Mac, because it is not critical. Part of #5906 --- src/lib/swim/swim_io.c | 19 +++++++++++++++++-- src/lib/swim/swim_transport_udp.c | 23 ++++++++++++++--------- 2 files changed, 31 insertions(+), 11 deletions(-) diff --git a/src/lib/swim/swim_io.c b/src/lib/swim/swim_io.c index c8558c43e..45df36ba4 100644 --- a/src/lib/swim/swim_io.c +++ b/src/lib/swim/swim_io.c @@ -512,8 +512,23 @@ static inline void swim_complete_send(struct swim_scheduler *scheduler, struct swim_task *task, ssize_t size) { - if (size < 0) - diag_log(); + if (size < 0) { + bool is_critical = false; +#if TARGET_OS_DARWIN + /* + * On Mac this error happens regularly if SWIM is bound to + * the localhost and tries to broadcast out of the machine. This + * is not critical, because will happen in the tests a lot, and + * in prod it simply should not bind to localhost if there are + * multiple machines in the cluster. Besides, Mac as a platform + * is not supposed to be used in prod. + */ + struct error *last = diag_last_error(diag_get()); + is_critical = (last->saved_errno == EADDRNOTAVAIL); +#endif + if (is_critical) + diag_log(); + } if (task->complete != NULL) task->complete(task, scheduler, size); } diff --git a/src/lib/swim/swim_transport_udp.c b/src/lib/swim/swim_transport_udp.c index c0317a20b..12626cc49 100644 --- a/src/lib/swim/swim_transport_udp.c +++ b/src/lib/swim/swim_transport_udp.c @@ -80,25 +80,27 @@ swim_transport_bind(struct swim_transport *transport, return 0; } + int is_on = 1; + int real_port = new_addr->sin_port; int fd = sio_socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP); if (fd < 0) return -1; - if (sio_bind(fd, (struct sockaddr *) addr, addr_len) != 0 || - evio_setsockopt_server(fd, AF_INET, SOCK_DGRAM) != 0) { + if (sio_bind(fd, (struct sockaddr *) addr, addr_len) != 0) { if (errno == EADDRINUSE) diag_set(SocketError, sio_socketname(fd), "bind"); - close(fd); - return -1; + goto end_error; } - int real_port = new_addr->sin_port; + if (sio_setsockopt(fd, SOL_SOCKET, SO_BROADCAST, &is_on, + sizeof(is_on)) != 0) + goto end_error; + if (evio_setsockopt_server(fd, AF_INET, SOCK_DGRAM) != 0) + goto end_error; if (is_new_port_any) { struct sockaddr_in real_addr; addr_len = sizeof(real_addr); if (sio_getsockname(fd, (struct sockaddr *) &real_addr, - &addr_len) != 0) { - close(fd); - return -1; - } + &addr_len) != 0) + goto end_error; real_port = real_addr.sin_port; } if (transport->fd != -1) @@ -107,6 +109,9 @@ swim_transport_bind(struct swim_transport *transport, transport->addr = *new_addr; transport->addr.sin_port = real_port; return 0; +end_error: + close(fd); + return -1; } void -- 2.24.3 (Apple Git-128)