From: Vladislav Shpilevoy <v.shpilevoy@tarantool.org> To: tarantool-patches@freelists.org Cc: kostja@tarantool.org Subject: [tarantool-patches] [PATCH 1/4] swim: move sockaddr_in checkers to swim_proto.h Date: Wed, 17 Apr 2019 22:56:34 +0300 [thread overview] Message-ID: <1e3490a96e2daec7906def26f31265d995966204.1555530516.git.v.shpilevoy@tarantool.org> (raw) In-Reply-To: <cover.1555530516.git.v.shpilevoy@tarantool.org> In-Reply-To: <cover.1555530516.git.v.shpilevoy@tarantool.org> There are several places where it is necessary to check if a sockaddr_in is nullified, and to compare a couple of addresses. Some of them are in swim_proto.c, and more are coming in indirect SWIM messages patch. The patch moves the checkers into swim_proto.h so as to be usable from anywhere in SWIM. Also minor renames are made alongside. 'sockaddr_in' is too long to use in each related function's name, and is replaced with 'inaddr' by analogue with the standard library. Part of #3234 --- src/lib/swim/swim.c | 12 ++---------- src/lib/swim/swim_proto.c | 26 ++++++++++++++++---------- src/lib/swim/swim_proto.h | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 20 deletions(-) diff --git a/src/lib/swim/swim.c b/src/lib/swim/swim.c index 2dac6eedd..40fa3fb21 100644 --- a/src/lib/swim/swim.c +++ b/src/lib/swim/swim.c @@ -201,14 +201,6 @@ swim_uuid_str(const struct tt_uuid *uuid) return buf; } -/** Check if two AF_INET addresses are equal. */ -static bool -swim_sockaddr_in_eq(const struct sockaddr_in *a1, const struct sockaddr_in *a2) -{ - return a1->sin_port == a2->sin_port && - a1->sin_addr.s_addr == a2->sin_addr.s_addr; -} - /** * A cluster member description. This structure describes the * last known state of an instance. This state is updated @@ -950,7 +942,7 @@ swim_complete_step(struct swim_task *task, struct swim_member *m = rlist_first_entry(&swim->round_queue, struct swim_member, in_round_queue); - if (swim_sockaddr_in_eq(&m->addr, &task->dst)) { + if (swim_inaddr_eq(&m->addr, &task->dst)) { rlist_shift(&swim->round_queue); if (rc > 0) { /* @@ -1048,7 +1040,7 @@ static inline void swim_update_member_addr(struct swim *swim, struct swim_member *member, const struct sockaddr_in *addr, int incarnation_inc) { - if (! swim_sockaddr_in_eq(addr, &member->addr)) { + if (! swim_inaddr_eq(addr, &member->addr)) { member->incarnation += incarnation_inc; member->addr = *addr; swim_on_member_update(swim, member); diff --git a/src/lib/swim/swim_proto.c b/src/lib/swim/swim_proto.c index d84550663..cd9dd195b 100644 --- a/src/lib/swim/swim_proto.c +++ b/src/lib/swim/swim_proto.c @@ -154,6 +154,20 @@ swim_decode_uuid(struct tt_uuid *uuid, const char **pos, const char *end, return 0; } +/** + * Check if @a addr is not empty, i.e. not nullified. Set an error + * in the diagnostics area in case of emptiness. + */ +static inline int +swim_check_inaddr_not_empty(const struct sockaddr_in *addr, const char *prefix, + const char *addr_name) +{ + if (! swim_inaddr_is_empty(addr)) + return 0; + diag_set(SwimError, "%s %s address is mandatory", prefix, addr_name); + return -1; +} + void swim_member_def_create(struct swim_member_def *def) { @@ -236,15 +250,11 @@ swim_member_def_decode(struct swim_member_def *def, const char **pos, if (swim_decode_member_key(key, pos, end, prefix, def) != 0) return -1; } - if (def->addr.sin_port == 0 || def->addr.sin_addr.s_addr == 0) { - diag_set(SwimError, "%s member address is mandatory", prefix); - return -1; - } if (tt_uuid_is_nil(&def->uuid)) { diag_set(SwimError, "%s member uuid is mandatory", prefix); return -1; } - return 0; + return swim_check_inaddr_not_empty(&def->addr, prefix, "member"); } void @@ -429,11 +439,7 @@ swim_meta_def_decode(struct swim_meta_def *def, const char **pos, diag_set(SwimError, "%s version is mandatory", prefix); return -1; } - if (def->src.sin_port == 0 || def->src.sin_addr.s_addr == 0) { - diag_set(SwimError, "%s source address is mandatory", prefix); - return -1; - } - return 0; + return swim_check_inaddr_not_empty(&def->src, prefix, "source"); } void diff --git a/src/lib/swim/swim_proto.h b/src/lib/swim/swim_proto.h index ab4057185..c6ff4539d 100644 --- a/src/lib/swim/swim_proto.h +++ b/src/lib/swim/swim_proto.h @@ -472,4 +472,19 @@ int swim_decode_uuid(struct tt_uuid *uuid, const char **pos, const char *end, const char *prefix, const char *param_name); +/** Check if @a addr is not empty, i.e. not nullified. */ +static inline bool +swim_inaddr_is_empty(const struct sockaddr_in *addr) +{ + return addr->sin_port == 0 && addr->sin_addr.s_addr == 0; +} + +/** Check if two AF_INET addresses are equal. */ +static inline bool +swim_inaddr_eq(const struct sockaddr_in *a1, const struct sockaddr_in *a2) +{ + return a1->sin_port == a2->sin_port && + a1->sin_addr.s_addr == a2->sin_addr.s_addr; +} + #endif /* TARANTOOL_SWIM_PROTO_H_INCLUDED */ -- 2.17.2 (Apple Git-113)
next prev parent reply other threads:[~2019-04-17 19:56 UTC|newest] Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top 2019-04-17 19:56 [tarantool-patches] [PATCH 0/4] swim suspicion preparation Vladislav Shpilevoy 2019-04-17 19:56 ` Vladislav Shpilevoy [this message] 2019-04-18 11:35 ` [tarantool-patches] Re: [PATCH 1/4] swim: move sockaddr_in checkers to swim_proto.h Vladislav Shpilevoy 2019-04-18 15:16 ` Konstantin Osipov 2019-04-18 15:24 ` Vladislav Shpilevoy 2019-04-18 16:02 ` Konstantin Osipov 2019-04-18 18:34 ` Vladislav Shpilevoy 2019-04-18 15:15 ` Konstantin Osipov 2019-04-17 19:56 ` [tarantool-patches] [PATCH 2/4] swim: extract binary ip/port into a separate struct Vladislav Shpilevoy 2019-04-18 15:17 ` [tarantool-patches] " Konstantin Osipov 2019-04-18 18:34 ` Vladislav Shpilevoy 2019-04-17 19:56 ` [tarantool-patches] [PATCH 3/4] swim: fix a bug with invalidation of round msg in fly Vladislav Shpilevoy 2019-04-18 15:19 ` [tarantool-patches] " Konstantin Osipov 2019-04-18 18:34 ` Vladislav Shpilevoy 2019-04-17 19:56 ` [tarantool-patches] [PATCH 4/4] swim: do not rebuild packet meta multiple times Vladislav Shpilevoy 2019-04-18 17:23 ` [tarantool-patches] " Konstantin Osipov 2019-04-18 18:34 ` Vladislav Shpilevoy
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=1e3490a96e2daec7906def26f31265d995966204.1555530516.git.v.shpilevoy@tarantool.org \ --to=v.shpilevoy@tarantool.org \ --cc=kostja@tarantool.org \ --cc=tarantool-patches@freelists.org \ --subject='Re: [tarantool-patches] [PATCH 1/4] swim: move sockaddr_in checkers to swim_proto.h' \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: link
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox