# HG changeset patch # User Timo Sirainen # Date 1509753567 -7200 # Node ID 6e235143e177722f30dcc48671249f362243fe31 # Parent 36e4e7fc0b1b3ac575a66418aa4457b69e3b47ce director: Use *_host.ip_str to avoid net_ip2addr() calls diff -r 36e4e7fc0b1b -r 6e235143e177 src/director/director-connection.c --- a/src/director/director-connection.c Sat Nov 04 01:51:25 2017 +0200 +++ b/src/director/director-connection.c Sat Nov 04 01:59:27 2017 +0200 @@ -250,7 +250,7 @@ return; connect_str = t_strdup_printf("CONNECT\t%s\t%u\n", - net_ip2addr(&host->ip), host->port); + host->ip_str, host->port); director_connection_send(conn, connect_str); o_stream_uncork(conn->output); @@ -449,7 +449,7 @@ conn->host->port != port)) { i_error("Remote director thinks it's someone else " "(connected to %s:%u, remote says it's %s:%u)", - net_ip2addr(&conn->host->ip), conn->host->port, + conn->host->ip_str, conn->host->port, net_ip2addr(&ip), port); return FALSE; } @@ -532,7 +532,7 @@ dir->self_host) < 0) { /* c) */ connect_str = t_strdup_printf("CONNECT\t%s\t%u\n", - net_ip2addr(&conn->host->ip), + conn->host->ip_str, conn->host->port); director_connection_send(dir->left, connect_str); } else { @@ -585,8 +585,8 @@ } else if (weak) { dir_debug("user refresh: %u weak update to %s ignored, " "we recently changed it to %s", - username_hash, net_ip2addr(&host->ip), - net_ip2addr(&user->host->ip)); + username_hash, host->ip_str, + user->host->ip_str); host = user->host; ret = TRUE; } else if (user->host == host) { @@ -597,15 +597,14 @@ and we should have as well. use the new host. */ dir_debug("user refresh: %u is nearly expired, " "replacing host %s with %s", username_hash, - net_ip2addr(&user->host->ip), net_ip2addr(&host->ip)); + user->host->ip_str, host->ip_str); ret = TRUE; } else if (USER_IS_BEING_KILLED(user)) { /* user is still being moved - ignore conflicting host updates from other directors who don't yet know about the move. */ dir_debug("user refresh: %u is being moved, " "preserve its host %s instead of replacing with %s", - username_hash, net_ip2addr(&user->host->ip), - net_ip2addr(&host->ip)); + username_hash, user->host->ip_str, host->ip_str); host = user->host; } else { /* non-weak user received a non-weak update with @@ -614,8 +613,7 @@ str_printfa(str, "User hash %u " "is being redirected to two hosts: %s and %s", - username_hash, net_ip2addr(&user->host->ip), - net_ip2addr(&host->ip)); + username_hash, user->host->ip_str, host->ip_str); str_printfa(str, " (old_ts=%ld", (long)user->timestamp); if (!conn->handshake_received) { @@ -952,7 +950,7 @@ this around the ring to the origin so it also knows it has travelled through the ring. */ dir_debug("user refresh: %u Remote USER-WEAK from %s seen by the entire ring, ignoring", - username_hash, net_ip2addr(&dir_host->ip)); + username_hash, dir_host->ip_str); weak_forward = TRUE; } @@ -1025,7 +1023,7 @@ host_tag = mail_host_get_tag(host); if (strcmp(tag, host_tag) != 0) { i_error("director(%s): Host %s changed tag from '%s' to '%s'", - conn->name, net_ip2addr(&host->ip), + conn->name, host->ip_str, host_tag, tag); mail_host_set_tag(host, tag); update = TRUE; @@ -1034,7 +1032,7 @@ string_t *str = t_str_new(128); str_printfa(str, "director(%s): Host %s is being updated before previous update had finished (", - conn->name, net_ip2addr(&host->ip)); + conn->name, host->ip_str); if (host->down != down && host->last_updown_change > last_updown_change) { /* our host has a newer change. preserve it. */ @@ -1320,7 +1318,7 @@ /* tell the "right" director about the "left" one */ director_update_send(dir, director_connection_get_host(conn), t_strdup_printf("DIRECTOR\t%s\t%u\n", - net_ip2addr(&conn->host->ip), + conn->host->ip_str, conn->host->port)); /* this is our "left" side. */ return director_connection_assign_left(conn); @@ -1517,7 +1515,7 @@ if (host->desynced_hosts_hash != hosts_hash) { dir_debug("Ignore director %s stale SYNC request whose hosts don't match us " "(seq=%u, remote hosts_hash=%u, my hosts_hash=%u)", - net_ip2addr(&host->ip), seq, hosts_hash, + host->ip_str, seq, hosts_hash, mail_hosts_hash(dir->mail_hosts)); host->desynced_hosts_hash = hosts_hash; return FALSE; @@ -1528,7 +1526,7 @@ changing rapidly. */ i_error("director(%s): Director %s SYNC request hosts don't match us - resending hosts " "(seq=%u, remote hosts_hash=%u, my hosts_hash=%u)", - conn->name, net_ip2addr(&host->ip), seq, + conn->name, host->ip_str, seq, hosts_hash, mail_hosts_hash(dir->mail_hosts)); director_resend_hosts(dir); return FALSE; @@ -1922,7 +1920,7 @@ str_truncate(str, 0); str_printfa(str, "DIRECTOR\t%s\t%u\n", - net_ip2addr(&(*hostp)->ip), (*hostp)->port); + (*hostp)->ip_str, (*hostp)->port); director_connection_send(conn, str_c(str)); } } @@ -1944,7 +1942,7 @@ const char *host_tag = mail_host_get_tag(host); str_printfa(str, "HOST\t%s\t%u", - net_ip2addr(&host->ip), host->vhost_count); + host->ip_str, host->vhost_count); if (host_tag[0] != '\0' || send_updowns) { str_append_c(str, '\t'); str_append_tabescaped(str, host_tag); @@ -1994,7 +1992,7 @@ str_printfa(str, "USER\t%u\t%s\t%u", user->username_hash, - net_ip2addr(&user->host->ip), + user->host->ip_str, user->timestamp); if (user->weak) str_append(str, "\tw"); diff -r 36e4e7fc0b1b -r 6e235143e177 src/director/director-host.c --- a/src/director/director-host.c Sat Nov 04 01:51:25 2017 +0200 +++ b/src/director/director-host.c Sat Nov 04 01:59:27 2017 +0200 @@ -36,7 +36,7 @@ host->ip = *ip; host->ip_str = i_strdup(net_ip2addr(&host->ip)); host->port = port; - host->name = i_strdup_printf("%s:%u", net_ip2addr(ip), port); + host->name = i_strdup_printf("%s:%u", host->ip_str, port); array_append(&dir->dir_hosts, &host, 1); diff -r 36e4e7fc0b1b -r 6e235143e177 src/director/director.c --- a/src/director/director.c Sat Nov 04 01:51:25 2017 +0200 +++ b/src/director/director.c Sat Nov 04 01:59:27 2017 +0200 @@ -145,7 +145,7 @@ (int)(ioloop_time - host->last_protocol_failure)); } i_info("Connecting to %s:%u (as %s%s): %s", - net_ip2addr(&host->ip), host->port, + host->ip_str, host->port, net_ip2addr(&dir->self_ip), str_c(str), reason); } @@ -377,7 +377,7 @@ str = t_str_new(128); str_printfa(str, "SYNC\t%s\t%u\t%u", - net_ip2addr(&host->ip), host->port, seq); + host->ip_str, host->port, seq); if (minor_version > 0 && director_connection_get_minor_version(dir->right) > 0) { /* only minor_version>0 supports extra parameters */ @@ -509,7 +509,7 @@ added_host->dir->ring_change_counter++; cmd = t_strdup_printf("DIRECTOR\t%s\t%u\n", - net_ip2addr(&added_host->ip), added_host->port); + added_host->ip_str, added_host->port); director_update_send(added_host->dir, src, cmd); } @@ -565,8 +565,7 @@ /* if our left or ride side gets removed, notify them first before disconnecting. */ cmd = t_strdup_printf("DIRECTOR-REMOVE\t%s\t%u\n", - net_ip2addr(&removed_host->ip), - removed_host->port); + removed_host->ip_str, removed_host->port); director_update_send_version(dir, src, DIRECTOR_VERSION_RING_REMOVE, cmd); @@ -602,9 +601,8 @@ str = t_str_new(128); str_printfa(str, "HOST\t%s\t%u\t%u\t%s\t%u", - net_ip2addr(&orig_src->ip), orig_src->port, - orig_src->last_seq, - net_ip2addr(&host->ip), host->vhost_count); + orig_src->ip_str, orig_src->port, orig_src->last_seq, + host->ip_str, host->vhost_count); if (dir->ring_min_version >= DIRECTOR_VERSION_TAGS_V2) { str_append_c(str, '\t'); str_append_tabescaped(str, host_tag); @@ -612,10 +610,10 @@ dir->ring_min_version < DIRECTOR_VERSION_TAGS_V2) { if (dir->ring_min_version < DIRECTOR_VERSION_TAGS) { i_error("Ring has directors that don't support tags - removing host %s with tag '%s'", - net_ip2addr(&host->ip), host_tag); + host->ip_str, host_tag); } else { i_error("Ring has directors that support mixed versions of tags - removing host %s with tag '%s'", - net_ip2addr(&host->ip), host_tag); + host->ip_str, host_tag); } director_remove_host(dir, NULL, NULL, host); return; @@ -649,7 +647,7 @@ dir_debug("Updating host %s vhost_count=%u " "down=%d last_updown_change=%ld (hosts_hash=%u)", - net_ip2addr(&host->ip), host->vhost_count, host->down, + host->ip_str, host->vhost_count, host->down, (long)host->last_updown_change, mail_hosts_hash(dir->mail_hosts)); @@ -676,8 +674,8 @@ director_update_send(dir, src, t_strdup_printf( "HOST-REMOVE\t%s\t%u\t%u\t%s\n", - net_ip2addr(&orig_src->ip), orig_src->port, - orig_src->last_seq, net_ip2addr(&host->ip))); + orig_src->ip_str, orig_src->port, + orig_src->last_seq, host->ip_str)); } user_directory_remove_host(users, host); @@ -698,8 +696,8 @@ director_update_send(dir, src, t_strdup_printf( "HOST-FLUSH\t%s\t%u\t%u\t%s\n", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq, - net_ip2addr(&host->ip))); + orig_src->ip_str, orig_src->port, orig_src->last_seq, + host->ip_str)); user_directory_remove_host(users, host); director_sync(dir); } @@ -711,7 +709,7 @@ i_assert(!user->weak); director_update_send(dir, src, t_strdup_printf("USER\t%u\t%s\n", - user->username_hash, net_ip2addr(&user->host->ip))); + user->username_hash, user->host->ip_str)); } void director_update_user_weak(struct director *dir, struct director_host *src, @@ -730,8 +728,8 @@ } cmd = t_strdup_printf("USER-WEAK\t%s\t%u\t%u\t%u\t%s\n", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq, - user->username_hash, net_ip2addr(&user->host->ip)); + orig_src->ip_str, orig_src->port, orig_src->last_seq, + user->username_hash, user->host->ip_str); if (src != dir->self_host && dir->left != NULL && dir->right != NULL && director_connection_get_host(dir->left) == @@ -775,8 +773,7 @@ i_error("%s: Failed to flush user hash %u in host %s: %s", ctx->socket_path, ctx->username_hash, - net_ip2addr(&ctx->host_ip), - data); + net_ip2addr(&ctx->host_ip), data); } i_stream_unref(&is); } else { @@ -803,7 +800,7 @@ { struct director_kill_context *ctx = user->kill_ctx; struct var_expand_table tab[] = { - { 'i', net_ip2addr(&user->host->ip), "ip" }, + { 'i', user->host->ip_str, "ip" }, { 'h', user->host->hostname, "host" }, { '\0', NULL, NULL } }; @@ -841,7 +838,7 @@ "FLUSH", t_strdup_printf("%u", user->username_hash), net_ip2addr(&ctx->old_host_ip), - net_ip2addr(&user->host->ip), + user->host->ip_str, ctx->old_host_down ? "down" : "up", dec2str(ctx->old_host_vhost_count), NULL @@ -856,7 +853,7 @@ i_error("%s: Failed to flush user hash %u in host %s: %s", ctx->socket_path, user->username_hash, - net_ip2addr(&user->host->ip), + user->host->ip_str, error); director_flush_user_continue(0, ctx); return; @@ -865,7 +862,7 @@ ctx->reply = iostream_temp_create_named("/tmp", 0, t_strdup_printf("flush response from %s", - net_ip2addr(&user->host->ip))); + user->host->ip_str)); o_stream_set_no_error_handling(ctx->reply, TRUE); program_client_set_output(ctx->pclient, ctx->reply); ctx->callback_pending = TRUE; @@ -1114,7 +1111,7 @@ old_host = user->host; user->timestamp = ioloop_time; dir_debug("User %u move forwarded: host is already %s", - username_hash, net_ip2addr(&host->ip)); + username_hash, host->ip_str); } else { /* user is looked up via the new host's tag, so if it's found the old tag has to be the same. */ @@ -1126,8 +1123,8 @@ user->host->user_count++; user->timestamp = ioloop_time; dir_debug("User %u move started: host %s -> %s", - username_hash, net_ip2addr(&old_host->ip), - net_ip2addr(&host->ip)); + username_hash, old_host->ip_str, + host->ip_str); } if (orig_src == NULL) { @@ -1136,8 +1133,8 @@ } director_update_send(dir, src, t_strdup_printf( "USER-MOVE\t%s\t%u\t%u\t%u\t%s\n", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq, - user->username_hash, net_ip2addr(&user->host->ip))); + orig_src->ip_str, orig_src->port, orig_src->last_seq, + user->username_hash, user->host->ip_str)); /* kill the user only after sending the USER-MOVE, because the kill may finish instantly. */ director_kill_user(dir, src, user, host->tag, old_host, FALSE); @@ -1166,7 +1163,7 @@ } str_truncate(cmd, 0); str_printfa(cmd, "USER-KICK\t%s\t%u\t%u\t", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq); + orig_src->ip_str, orig_src->port, orig_src->last_seq); str_append_tabescaped(cmd, username); str_append_c(cmd, '\n'); director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK, str_c(cmd)); @@ -1191,7 +1188,7 @@ } str_truncate(cmd, 0); str_printfa(cmd, "USER-KICK-ALT\t%s\t%u\t%u\t", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq); + orig_src->ip_str, orig_src->port, orig_src->last_seq); str_append_tabescaped(cmd, field); str_append_c(cmd, '\t'); str_append_tabescaped(cmd, value); @@ -1216,7 +1213,7 @@ orig_src->last_seq++; } cmd = t_strdup_printf("USER-KICK-HASH\t%s\t%u\t%u\t%u\t%s\n", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq, + orig_src->ip_str, orig_src->port, orig_src->last_seq, username_hash, net_ip2addr(except_ip)); director_update_send_version(dir, src, DIRECTOR_VERSION_USER_KICK, cmd); } @@ -1233,7 +1230,7 @@ } director_update_send(dir, src, t_strdup_printf( "USER-KILLED-EVERYWHERE\t%s\t%u\t%u\t%u\n", - net_ip2addr(&orig_src->ip), orig_src->port, orig_src->last_seq, + orig_src->ip_str, orig_src->port, orig_src->last_seq, username_hash)); } diff -r 36e4e7fc0b1b -r 6e235143e177 src/director/doveadm-connection.c --- a/src/director/doveadm-connection.c Sat Nov 04 01:51:25 2017 +0200 +++ b/src/director/doveadm-connection.c Sat Nov 04 01:59:27 2017 +0200 @@ -90,7 +90,7 @@ array_foreach(mail_hosts_get(conn->dir->mail_hosts), hostp) { str_printfa(str, "%s\t%u\t%u\t", - net_ip2addr(&(*hostp)->ip), (*hostp)->vhost_count, + (*hostp)->ip_str, (*hostp)->vhost_count, (*hostp)->user_count); str_append_tabescaped(str, mail_host_get_tag(*hostp)); str_printfa(str, "\t%c\t%ld", (*hostp)->down ? 'D' : 'U', @@ -131,13 +131,12 @@ else if (ret > 0) j++; else { - str_printfa(str, "%s\n", - net_ip2addr(&orig_hosts[i]->ip)); + str_printfa(str, "%s\n", orig_hosts[i]->ip_str); i++; } } for (; i < orig_hosts_count; i++) - str_printfa(str, "%s\n", net_ip2addr(&orig_hosts[i]->ip)); + str_printfa(str, "%s\n", orig_hosts[i]->ip_str); str_append_c(str, '\n'); o_stream_nsend(conn->output, str_data(str), str_len(str)); @@ -152,7 +151,7 @@ time_t last_failed = I_MAX(host->last_network_failure, host->last_protocol_failure); str_printfa(str, "%s\t%u\t%s\t%ld\t", - net_ip2addr(&host->ip), host->port, type, + host->ip_str, host->port, type, (long)last_failed); } @@ -653,7 +652,7 @@ if (user == NULL) str_append(str, "\t0"); else { - str_printfa(str, "%s\t%u", net_ip2addr(&user->host->ip), + str_printfa(str, "%s\t%u", user->host->ip_str, user->timestamp + conn->dir->set->director_user_expire); } @@ -663,7 +662,7 @@ if (host == NULL) str_append(str, "\t"); else - str_printfa(str, "\t%s", net_ip2addr(&host->ip)); + str_printfa(str, "\t%s", host->ip_str); /* get host with default configuration */ host = mail_host_get_by_hash(conn->dir->orig_config_hosts, @@ -671,7 +670,7 @@ if (host == NULL) str_append(str, "\t\n"); else - str_printfa(str, "\t%s\n", net_ip2addr(&host->ip)); + str_printfa(str, "\t%s\n", host->ip_str); o_stream_nsend(conn->output, str_data(str), str_len(str)); return DOVEADM_DIRECTOR_CMD_RET_OK; } @@ -702,7 +701,7 @@ o_stream_nsend_str(conn->output, t_strdup_printf( "%u\t%u\t%s\n", user->username_hash, expire_time, - net_ip2addr(&user->host->ip))); + user->host->ip_str)); } T_END; } director_iterate_users_deinit(&iter); diff -r 36e4e7fc0b1b -r 6e235143e177 src/director/mail-host.c --- a/src/director/mail-host.c Sat Nov 04 01:51:25 2017 +0200 +++ b/src/director/mail-host.c Sat Nov 04 01:59:27 2017 +0200 @@ -55,17 +55,14 @@ struct mail_vhost *vhost; struct md5_context md5_ctx, md5_ctx2; unsigned char md5[MD5_RESULTLEN]; - const char *ip_str; char num_str[MAX_INT_STRLEN]; unsigned int i, j; if (host->down || host->tag != tag) return; - ip_str = net_ip2addr(&host->ip); - md5_init(&md5_ctx); - md5_update(&md5_ctx, ip_str, strlen(ip_str)); + md5_update(&md5_ctx, host->ip_str, strlen(host->ip_str)); for (i = 0; i < host->vhost_count; i++) { md5_ctx2 = md5_ctx; @@ -369,7 +366,7 @@ const char *updown = down ? "down" : "up"; i_info("%sHost %s changed %s " "(vhost_count=%u last_updown_change=%ld)", - log_prefix, net_ip2addr(&host->ip), updown, + log_prefix, host->ip_str, updown, host->vhost_count, (long)host->last_updown_change); host->down = down; @@ -382,7 +379,7 @@ const char *log_prefix) { i_info("%sHost %s vhost count changed from %u to %u", - log_prefix, net_ip2addr(&host->ip), + log_prefix, host->ip_str, host->vhost_count, vhost_count); host->vhost_count = vhost_count;