From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from localhost (localhost [127.0.0.1]) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTP id E00B51FB49 for ; Thu, 2 May 2019 11:10:08 -0400 (EDT) Received: from turing.freelists.org ([127.0.0.1]) by localhost (turing.freelists.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id dw_OiylBx-7G for ; Thu, 2 May 2019 11:10:08 -0400 (EDT) Received: from smtp15.mail.ru (smtp15.mail.ru [94.100.176.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by turing.freelists.org (Avenir Technologies Mail Multiplex) with ESMTPS id 74A221FA39 for ; Thu, 2 May 2019 11:10:08 -0400 (EDT) Subject: [tarantool-patches] Re: [PATCH 4/5] swim: allow to omit host in URI References: <6dcbe9a1f1efbc07092109336427520109f1e3a3.1556663421.git.v.shpilevoy@tarantool.org> <20190501052026.GD1139@atlas> From: Vladislav Shpilevoy Message-ID: <98cf0bc9-8b4a-cbb0-7656-4b83d6dc3d58@tarantool.org> Date: Thu, 2 May 2019 18:10:04 +0300 MIME-Version: 1.0 In-Reply-To: <20190501052026.GD1139@atlas> Content-Type: text/plain; charset=utf-8 Content-Language: en-US Content-Transfer-Encoding: 7bit Sender: tarantool-patches-bounce@freelists.org Errors-to: tarantool-patches-bounce@freelists.org Reply-To: tarantool-patches@freelists.org List-Help: List-Unsubscribe: List-software: Ecartis version 1.0.0 List-Id: tarantool-patches List-Subscribe: List-Owner: List-post: List-Archive: To: Konstantin Osipov Cc: tarantool-patches@freelists.org On 01/05/2019 08:20, Konstantin Osipov wrote: > * Vladislav Shpilevoy [19/05/01 08:07]: >> Before the patch swim.cfg() was returning an error on an attempt >> to use URI like 'port', without a host. But it would be useful, >> easy, and short to allow that, and use '127.0.0.1' host by >> default. Compare: >> >> swim:cfg({uri = 1234}) >> vs >> swim:cfg({uri = '127.0.0.1:1234'}) >> >> It is remarkable that box.cfg{listen} also allows to omit host. >> >> Note, that use '0.0.0.0' (INADDR_ANY) is forbidden. Otherwise >> >> 1) Different instances interacting with this one via not the >> same interfaces would see different source IP addresses. >> It would mess member tables; >> >> 2) This instance would not be able to encode its IP address >> in the meta section, because it has no a fixed IP. At the >> same time omission of it and usage of UDP header source >> address is not possible as well, because UDP header is not >> encrypted and therefore is not safe to look at. >> > > Thank you for an elaborate description. Please squash the patch > with the previous one. I believe at least some of this extensive > comment belongs to the source code. The patch is OK to push after > adding a comment. > Added: ================================================================ diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index c806000df..ada36156e 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -1710,6 +1710,27 @@ swim_uri_to_addr(const char *uri, struct sockaddr_in *addr, } *addr = *((struct sockaddr_in *) &storage); if (is_host_empty) { + /* + * This condition is satisfied when host is + * omitted and URI is "port". Note, that + * traditionally "port" is converted to + * "0.0.0.0:port" what means binding to all the + * interfaces simultaneously, but it would not + * work for SWIM. There is why: + * + * - Different instances interacting with this + * one via not the same interface would see + * different source IP addresses. It would + * mess member tables; + * + * - This instance would not be able to encode + * its IP address in the meta section, + * because it has no a fixed IP. At the same + * time omission of it and usage of UDP + * header source address is not possible as + * well, because UDP header is not encrypted + * and therefore is not safe to look at. + */ addr->sin_addr.s_addr = htonl(INADDR_LOOPBACK); } else if (addr->sin_addr.s_addr == 0) { diag_set(IllegalParams, "%s INADDR_ANY is not supported", diff --git a/src/lib/swim/swim.h b/src/lib/swim/swim.h index 2f53716c7..a3711dc27 100644 --- a/src/lib/swim/swim.h +++ b/src/lib/swim/swim.h @@ -77,7 +77,8 @@ swim_is_configured(const struct swim *swim); * Configure or reconfigure a SWIM instance. * * @param swim SWIM instance to configure. - * @param uri URI in the format "ip:port". + * @param uri URI in the format "ip:port", or "port". In the + * latter case host is "127.0.0.1" by default. * @param heartbeat_rate Rate of sending round messages. It does * not mean that each member will be checked each * @heartbeat_rate seconds. It is rather the protocol ================================================================