+Sun Oct 14 18:28:22 EDT 2001 Pekka Riikonen <priikone@silcnet.org>
+
+ * Assure that router cannot reroute the same channel message
+ to the sender. Affected file silcd/packet_receive.c.
+
+Sat Oct 13 12:46:18 EDT 2001 Pekka Riikonen <priikone@silcnet.org>
+
+ * Made better checks that the channel message is not sent
+ to the router it came from. Affected file is
+ silcd/packet_send.c. Fixed memory leak too.
+
+ * Announce informations for incoming router connection, but
+ only after checking if it is replaced by backup router.
+ Affected file silcd/packet_receive.c.
+
Fri Oct 12 18:37:24 EDT 2001 Pekka Riikonen <priikone@silcnet.org>
* Fixed the backup resuming protocol to work in multiple
TODO/bugs In SILC Server
========================
+ o Server signoff notifys does not go to normal servers from routers.
+
o On normal server the channel count can go negative (like -3 channels).
o Change the sever to connect to another server from low ports (706)
returns only the channels the server knows about. The protocol spec
does not prohibit of sending the LIST to the router.
+ o Announcements are incomplete: channel topics are not announced,
+ user modes (UMODE) are not announced.
+
o Incomplete IPv6 support:
o silcd/serverid.c and its routines supports only IPv4.
entry = silc_idlist_find_server_by_name(server->local_list,
tmp, TRUE, NULL);
if (!entry && check_global)
- entry = silc_idlist_find_server_by_name(server->local_list,
+ entry = silc_idlist_find_server_by_name(server->global_list,
tmp, TRUE, NULL);
if (entry) {
*servers = silc_realloc(*servers, sizeof(**servers) *
entry = silc_idlist_find_channel_by_name(server->local_list,
tmp, NULL);
if (!entry && check_global)
- entry = silc_idlist_find_channel_by_name(server->local_list,
+ entry = silc_idlist_find_channel_by_name(server->global_list,
tmp, NULL);
if (entry) {
*channels = silc_realloc(*channels, sizeof(**channels) *
server_entry = silc_idlist_find_server_by_conn(server->local_list,
name, port, FALSE, NULL);
+ if (!server_entry)
+ server_entry = silc_idlist_find_server_by_conn(server->global_list,
+ name, port, FALSE, NULL);
if (!server_entry) {
silc_server_command_send_status_reply(cmd, SILC_COMMAND_CLOSE,
SILC_STATUS_ERR_NO_SERVER_ID);
SilcChannelID *id = NULL;
void *sender = NULL;
void *sender_entry = NULL;
+ bool local = TRUE;
SILC_LOG_DEBUG(("Processing channel message"));
if (packet->src_id_type == SILC_ID_CLIENT) {
sender_entry = silc_idlist_find_client_by_id(server->local_list,
sender, TRUE, NULL);
- if (!sender_entry)
+ if (!sender_entry) {
+ local = FALSE;
sender_entry = silc_idlist_find_client_by_id(server->global_list,
sender, TRUE, NULL);
+ }
if (!sender_entry || !silc_server_client_on_channel(sender_entry,
channel)) {
SILC_LOG_DEBUG(("Client not on channel"));
goto out;
}
+
+ /* If the packet is coming from router, but the client entry is
+ local entry to us then some router is rerouting this to us and it is
+ not allowed. */
+ if (server->server_type == SILC_ROUTER &&
+ sock->type == SILC_SOCKET_TYPE_ROUTER && local) {
+ SILC_LOG_DEBUG(("Channel message rerouted to the sender, drop it"));
+ goto out;
+ }
}
/* Distribute the packet to our local clients. This will send the
unsigned char *server_name, *id_string;
uint16 id_len, name_len;
int ret;
+ bool local = TRUE;
SILC_LOG_DEBUG(("Creating new server"));
idata = (SilcIDListData)new_server;
/* Remove the old cache entry */
- silc_idcache_del_by_context(server->local_list->servers, new_server);
+ if (!silc_idcache_del_by_context(server->local_list->servers, new_server)) {
+ silc_idcache_del_by_context(server->global_list->servers, new_server);
+ local = FALSE;
+ }
/* Parse the incoming packet */
ret = silc_buffer_unformat(buffer,
silc_id_render(server_id, SILC_ID_SERVER)));
/* Add again the entry to the ID cache. */
- silc_idcache_add(server->local_list->servers, server_name, server_id,
+ silc_idcache_add(local ? server->local_list->servers :
+ server->global_list->servers, server_name, server_id,
new_server, FALSE);
/* Distribute the information about new server in the SILC network
/* Mark the router disabled. The data sent earlier will go but nothing
after this does not go to this connection. */
idata->status |= SILC_IDLIST_STATUS_DISABLED;
+ } else {
+ /* If it is router announce our stuff to it. */
+ if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
+ server->server_type == SILC_ROUTER) {
+ silc_server_announce_servers(server, FALSE, 0, sock);
+ silc_server_announce_clients(server, 0, sock);
+ silc_server_announce_channels(server, 0, sock);
+ }
}
return new_server;
{
SilcBuffer buffer = packet->buffer;
SilcIDList id_list;
- SilcServerEntry router;
+ SilcServerEntry router, server_entry;
SilcSocketConnection router_sock;
SilcIDPayload idp;
SilcIdType id_type;
id_type = silc_id_payload_get_type(idp);
/* Normal server cannot have other normal server connections */
- if (id_type == SILC_ID_SERVER && sock->type == SILC_SOCKET_TYPE_SERVER)
+ server_entry = (SilcServerEntry)sock->user_data;
+ if (id_type == SILC_ID_SERVER && sock->type == SILC_SOCKET_TYPE_SERVER &&
+ server_entry->server_type == SILC_SERVER)
goto out;
id = silc_id_payload_get_id(idp);
if (!id)
goto out;
- if (sock->type == SILC_SOCKET_TYPE_SERVER)
- id_list = server->local_list;
- else
- id_list = server->global_list;
-
/* If the packet is coming from server then use the sender as the
origin of the the packet. If it came from router then check the real
sender of the packet and use that as the origin. */
if (sock->type == SILC_SOCKET_TYPE_SERVER) {
+ id_list = server->local_list;
router_sock = sock;
router = sock->user_data;
+
+ if (server_entry->server_type == SILC_BACKUP_ROUTER &&
+ id_type == SILC_ID_SERVER)
+ id_list = server->global_list;
} else {
void *sender_id = silc_id_str2id(packet->src_id, packet->src_id_len,
packet->src_id_type);
if (!router)
goto out;
router_sock = sock;
+ id_list = server->global_list;
}
switch(id_type) {
SilcIDListData idata;
uint32 routed_count = 0;
bool gone = FALSE;
+ int k;
/* This doesn't send channel message packets */
assert(type != SILC_PACKET_CHANNEL_MESSAGE);
}
}
+ routed = silc_calloc(silc_hash_table_count(channel->user_list),
+ sizeof(*routed));
+
/* Send the message to clients on the channel's client list. */
silc_hash_table_list(channel->user_list, &htl);
while (silc_hash_table_get(&htl, NULL, (void *)&chl)) {
client = chl->client;
+ if (!client)
+ continue;
/* If client has router set it is not locally connected client and
we will route the message to the router set in the client. Though,
send locally connected server in all cases. */
- if (server->server_type == SILC_ROUTER && client && client->router &&
+ if (server->server_type == SILC_ROUTER && client->router &&
((!route && client->router->router == server->id_entry) || route)) {
- int k;
/* Check if we have sent the packet to this route already */
for (k = 0; k < routed_count; k++)
data, data_len, FALSE,
force_send);
- /* We want to make sure that the packet is routed to same router
- only once. Mark this route as sent route. */
- k = routed_count;
- routed = silc_realloc(routed, sizeof(*routed) * (k + 1));
- routed[k] = client->router;
- routed_count++;
-
+ /* Mark this route routed already */
+ routed[routed_count++] = client->router;
continue;
}
- if (client && client->router)
+ if (client->router)
continue;
/* Send to locally connected client */
- if (client) {
-
- /* Get data used in packet header encryption, keys and stuff. */
- sock = (SilcSocketConnection)client->connection;
- idata = (SilcIDListData)client;
- if (sender && sock == sender)
- continue;
+ /* Get data used in packet header encryption, keys and stuff. */
+ sock = (SilcSocketConnection)client->connection;
+ idata = (SilcIDListData)client;
+
+ if (sender && sock == sender)
+ continue;
/* Send the packet */
- silc_server_packet_send_to_channel_real(server, sock, &packetdata,
- idata->send_key,
- idata->hmac_send,
- data, data_len, FALSE,
- force_send);
- }
+ silc_server_packet_send_to_channel_real(server, sock, &packetdata,
+ idata->send_key,
+ idata->hmac_send,
+ data, data_len, FALSE,
+ force_send);
}
- if (routed_count)
- silc_free(routed);
+ silc_free(routed);
silc_free(packetdata.src_id);
silc_free(packetdata.dst_id);
}
SilcIDListData idata;
SilcHashTableList htl;
bool gone = FALSE;
+ int k;
SILC_LOG_DEBUG(("Relaying packet to channel"));
first to our router for further routing. */
if (server->server_type != SILC_ROUTER && !server->standalone &&
channel->global_users) {
- SilcServerEntry router;
-
- router = server->router;
+ SilcServerEntry router = server->router;
/* Check that the sender is not our router. */
if (sender_sock != (SilcSocketConnection)router->connection) {
}
}
+ routed = silc_calloc(silc_hash_table_count(channel->user_list),
+ sizeof(*routed));
+
+ /* Mark that to the route the original sender if from is not routed */
+ if (sender_type == SILC_ID_CLIENT) {
+ client = (SilcClientEntry)sender_entry;
+ if (client->router) {
+ routed[routed_count++] = client->router;
+ SILC_LOG_DEBUG(("************* router %s",
+ silc_id_render(client->router->id, SILC_ID_SERVER)));
+ }
+ }
+
/* Send the message to clients on the channel's client list. */
silc_hash_table_list(channel->user_list, &htl);
while (silc_hash_table_get(&htl, NULL, (void *)&chl)) {
client = chl->client;
+ if (!client)
+ continue;
+
+ /* Do not send to the sender */
+ if (!found && client == sender_entry) {
+ found = TRUE;
+ continue;
+ }
- if (client) {
+ /* If the client has set router it means that it is not locally
+ connected client and we will route the packet further. */
+ if (server->server_type == SILC_ROUTER && client->router) {
- /* If sender is one on the channel do not send it the packet. */
- if (!found && sender_type == SILC_ID_CLIENT &&
- SILC_ID_CLIENT_COMPARE(client->id, sender)) {
+ /* Sender maybe server as well so we want to make sure that
+ we won't send the message to the server it came from. */
+ if (!found && SILC_ID_SERVER_COMPARE(client->router->id, sender)) {
found = TRUE;
+ routed[routed_count++] = client->router;
continue;
}
- /* If the client has set router it means that it is not locally
- connected client and we will route the packet further. */
- if (server->server_type == SILC_ROUTER && client->router) {
- int k;
+ /* Check if we have sent the packet to this route already */
+ for (k = 0; k < routed_count; k++)
+ if (routed[k] == client->router)
+ break;
+ if (k < routed_count)
+ continue;
+
+ /* Get data used in packet header encryption, keys and stuff. */
+ sock = (SilcSocketConnection)client->router->connection;
+ idata = (SilcIDListData)client->router;
- /* Sender maybe server as well so we want to make sure that
- we won't send the message to the server it came from. */
- if (!found && SILC_ID_SERVER_COMPARE(client->router->id, sender)) {
- found = TRUE;
- continue;
- }
+ /* Do not send to the sender. Check first whether the true
+ sender's router is same as this client's router. Also check
+ if the sender socket is the same as this client's router
+ socket. */
+ if (sender_entry &&
+ ((SilcClientEntry)sender_entry)->router == client->router)
+ continue;
+ if (sender_sock && sock == sender_sock)
+ continue;
- /* Check if we have sent the packet to this route already */
- for (k = 0; k < routed_count; k++)
- if (routed[k] == client->router)
- break;
- if (k < routed_count)
- continue;
+ SILC_LOG_DEBUG(("Relaying packet to client ID(%s) %s (%s)",
+ silc_id_render(client->id, SILC_ID_CLIENT),
+ sock->hostname, sock->ip));
+
+ /* Mark this route routed already. */
+ routed[routed_count++] = client->router;
- /* Get data used in packet header encryption, keys and stuff. */
- sock = (SilcSocketConnection)client->router->connection;
- idata = (SilcIDListData)client->router;
-
- /* Do not send to the sender. Check first whether the true
- sender's router is same as this client's router. Also check
- if the sender socket is the same as this client's router
- socket. */
- if (sender_entry &&
- ((SilcClientEntry)sender_entry)->router == client->router)
- continue;
- if (sender_sock && sock == sender_sock)
+ /* If the remote connection is router then we'll decrypt the
+ channel message and re-encrypt it with the session key shared
+ between us and the remote router. This is done because the
+ channel keys are cell specific and we have different channel
+ key than the remote router has. */
+ if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
+ if (gone)
continue;
- SILC_LOG_DEBUG(("Relaying packet to client ID(%s) %s (%s)",
- silc_id_render(client->id, SILC_ID_CLIENT),
- sock->hostname, sock->ip));
-
- /* We want to make sure that the packet is routed to same router
- only once. Mark this route as sent route. */
- k = routed_count;
- routed = silc_realloc(routed, sizeof(*routed) * (k + 1));
- routed[k] = client->router;
- routed_count++;
-
- /* If the remote connection is router then we'll decrypt the
- channel message and re-encrypt it with the session key shared
- between us and the remote router. This is done because the
- channel keys are cell specific and we have different channel
- key than the remote router has. */
- if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
-
- if (gone)
- continue;
+ SILC_LOG_DEBUG(("Remote is router, encrypt with session key"));
+ gone = TRUE;
- SILC_LOG_DEBUG(("Remote is router, encrypt with session key"));
- gone = TRUE;
-
- /* If private key mode is not set then decrypt the packet
- and re-encrypt it */
- if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
- unsigned char *tmp = silc_calloc(data_len, sizeof(*data));
- memcpy(tmp, data, data_len);
-
- /* Decrypt the channel message (we don't check the MAC) */
- if (channel->channel_key &&
- !silc_channel_message_payload_decrypt(tmp, data_len,
- channel->channel_key,
- NULL)) {
- memset(tmp, 0, data_len);
- silc_free(tmp);
- continue;
- }
-
- /* Now re-encrypt and send it to the router */
- silc_server_packet_send_srcdest(server, sock,
- SILC_PACKET_CHANNEL_MESSAGE, 0,
- sender, sender_type,
- channel->id, SILC_ID_CHANNEL,
- tmp, data_len, force_send);
-
- /* Free the copy of the channel message */
+ /* If private key mode is not set then decrypt the packet
+ and re-encrypt it */
+ if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
+ unsigned char *tmp = silc_calloc(data_len, sizeof(*data));
+ memcpy(tmp, data, data_len);
+
+ /* Decrypt the channel message (we don't check the MAC) */
+ if (channel->channel_key &&
+ !silc_channel_message_payload_decrypt(tmp, data_len,
+ channel->channel_key,
+ NULL)) {
memset(tmp, 0, data_len);
silc_free(tmp);
- } else {
- /* Private key mode is set, we don't have the channel key, so
- just re-encrypt the entire packet and send it to the router. */
- silc_server_packet_send_srcdest(server, sock,
- SILC_PACKET_CHANNEL_MESSAGE, 0,
- sender, sender_type,
- channel->id, SILC_ID_CHANNEL,
- data, data_len, force_send);
+ continue;
}
- continue;
- }
-
- /* Send the packet (to normal server) */
- silc_server_packet_send_to_channel_real(server, sock, &packetdata,
- idata->send_key,
- idata->hmac_send,
- data, data_len, TRUE,
- force_send);
+ /* Now re-encrypt and send it to the router */
+ silc_server_packet_send_srcdest(server, sock,
+ SILC_PACKET_CHANNEL_MESSAGE, 0,
+ sender, sender_type,
+ channel->id, SILC_ID_CHANNEL,
+ tmp, data_len, force_send);
+
+ /* Free the copy of the channel message */
+ memset(tmp, 0, data_len);
+ silc_free(tmp);
+ } else {
+ /* Private key mode is set, we don't have the channel key, so
+ just re-encrypt the entire packet and send it to the router. */
+ silc_server_packet_send_srcdest(server, sock,
+ SILC_PACKET_CHANNEL_MESSAGE, 0,
+ sender, sender_type,
+ channel->id, SILC_ID_CHANNEL,
+ data, data_len, force_send);
+ }
continue;
}
- if (client && client->router)
- continue;
-
- /* Get data used in packet header encryption, keys and stuff. */
- sock = (SilcSocketConnection)client->connection;
- idata = (SilcIDListData)client;
-
- if (sender_sock && sock == sender_sock)
- continue;
-
- SILC_LOG_DEBUG(("Sending packet to client ID(%s) %s (%s)",
- silc_id_render(client->id, SILC_ID_CLIENT),
- sock->hostname, sock->ip));
-
- /* Send the packet */
+ /* Send the packet (to normal server) */
silc_server_packet_send_to_channel_real(server, sock, &packetdata,
idata->send_key,
idata->hmac_send,
data, data_len, TRUE,
force_send);
+
+ continue;
}
+
+ if (client->router)
+ continue;
+
+ /* Get data used in packet header encryption, keys and stuff. */
+ sock = (SilcSocketConnection)client->connection;
+ idata = (SilcIDListData)client;
+
+ if (sender_sock && sock == sender_sock)
+ continue;
+
+ SILC_LOG_DEBUG(("Sending packet to client ID(%s) %s (%s)",
+ silc_id_render(client->id, SILC_ID_CLIENT),
+ sock->hostname, sock->ip));
+
+ /* Send the packet */
+ silc_server_packet_send_to_channel_real(server, sock, &packetdata,
+ idata->send_key,
+ idata->hmac_send,
+ data, data_len, TRUE,
+ force_send);
}
+ silc_free(routed);
silc_free(packetdata.src_id);
silc_free(packetdata.dst_id);
}
/* We want to make sure that the packet is routed to same router
only once. Mark this route as sent route. */
- k = routed_count;
- routed = silc_realloc(routed, sizeof(*routed) * (k + 1));
- routed[k] = c->router;
- routed_count++;
-
+ routed = silc_realloc(routed, sizeof(*routed) * (routed_count + 1));
+ routed[routed_count++] = c->router;
continue;
}
/* Make sure that we send the notify only once per client. */
sent_clients = silc_realloc(sent_clients, sizeof(*sent_clients) *
(sent_clients_count + 1));
- sent_clients[sent_clients_count] = c;
- sent_clients_count++;
+ sent_clients[sent_clients_count++] = c;
}
}
}
- if (routed_count)
- silc_free(routed);
- if (sent_clients_count)
- silc_free(sent_clients);
+ silc_free(routed);
+ silc_free(sent_clients);
silc_free(packetdata.src_id);
va_end(ap);
}
SILC_LOG_DEBUG(("New server id(%s)",
silc_id_render(ctx->dest_id, SILC_ID_SERVER)));
- /* Add the connected router to local server list */
- id_entry = silc_idlist_add_server(server->local_list, strdup(sock->hostname),
+ /* Add the connected router to global server list */
+ id_entry = silc_idlist_add_server(server->global_list,
+ strdup(sock->hostname),
SILC_ROUTER, ctx->dest_id, NULL, sock);
if (!id_entry) {
silc_free(ctx->dest_id);
server. We mark ourselves as router for this server if we really
are router. */
new_server =
- silc_idlist_add_server(server->local_list, NULL,
- ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
- SILC_SERVER : SILC_ROUTER, NULL,
- ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
- server->id_entry :
- (conn->backup_router ? server->id_entry :
- NULL), sock);
+ silc_idlist_add_server((ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
+ server->local_list : (conn->backup_router ?
+ server->local_list :
+ server->global_list)),
+ NULL,
+ (ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
+ SILC_SERVER : SILC_ROUTER),
+ NULL,
+ (ctx->conn_type == SILC_SOCKET_TYPE_SERVER ?
+ server->id_entry : (conn->backup_router ?
+ server->id_entry : NULL)),
+ sock);
if (!new_server) {
SILC_LOG_ERROR(("Could not add new server to cache"));
silc_free(sock->user_data);
conn->backup_replace_port, conn->backup_local);
/* Change it back to SERVER type since that's what it really is. */
- if (conn->backup_local) {
+ if (conn->backup_local)
ctx->conn_type = SILC_SOCKET_TYPE_SERVER;
- new_server->server_type = SILC_BACKUP_ROUTER;
- }
+
+ new_server->server_type = SILC_BACKUP_ROUTER;
}
/* Check whether this connection is to be our primary router connection
silc_server_backup_del(server, user_data);
silc_server_backup_replaced_del(server, user_data);
silc_idlist_del_data(user_data);
- silc_idlist_del_server(server->local_list, user_data);
+ if (!silc_idlist_del_server(server->local_list, user_data))
+ silc_idlist_del_server(server->global_list, user_data);
server->stat.my_servers--;
server->stat.servers--;
if (server->server_type == SILC_ROUTER)
if (silc_idcache_list_first(list, &id_cache)) {
while (id_cache) {
server_entry = (SilcServerEntry)id_cache->context;
- if ((server_entry == server->id_entry) ||
- !server_entry->connection) {
+ if (!server_entry || (server_entry == server->id_entry) ||
+ !server_entry->connection || !server_entry->data.send_key ||
+ (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)) {
if (!silc_idcache_list_next(list, &id_cache))
break;
else
ctx->sessions[ctx->sessions_count].server_entry = server_entry;
SILC_LOG_DEBUG(("********************************"));
- SILC_LOG_DEBUG(("START for session %d", ctx->sessions_count));
+ SILC_LOG_DEBUG(("START (local) for session %d",
+ ctx->sessions_count));
+
+ /* This connection is performing this protocol too now */
+ ((SilcSocketConnection)server_entry->connection)->protocol =
+ protocol;
+
+ if (server_entry->server_type == SILC_ROUTER)
+ packet->data[0] = SILC_SERVER_BACKUP_START;
+ else
+ packet->data[0] = SILC_SERVER_BACKUP_START_GLOBAL;
+ packet->data[1] = ctx->sessions_count;
+ silc_server_packet_send(server, server_entry->connection,
+ SILC_PACKET_RESUME_ROUTER, 0,
+ packet->data, packet->len, FALSE);
+ ctx->sessions_count++;
+
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ }
+ }
+
+ silc_idcache_list_free(list);
+ }
+
+ if (silc_idcache_get_all(server->global_list->servers, &list)) {
+ if (silc_idcache_list_first(list, &id_cache)) {
+ while (id_cache) {
+ server_entry = (SilcServerEntry)id_cache->context;
+ if (!server_entry || (server_entry == server->id_entry) ||
+ !server_entry->connection || !server_entry->data.send_key ||
+ (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)) {
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ else
+ continue;
+ }
+
+ ctx->sessions = silc_realloc(ctx->sessions,
+ sizeof(*ctx->sessions) *
+ (ctx->sessions_count + 1));
+ ctx->sessions[ctx->sessions_count].session = ctx->sessions_count;
+ ctx->sessions[ctx->sessions_count].connected = FALSE;
+ ctx->sessions[ctx->sessions_count].server_entry = server_entry;
+
+ SILC_LOG_DEBUG(("********************************"));
+ SILC_LOG_DEBUG(("START (global) for session %d",
+ ctx->sessions_count));
/* This connection is performing this protocol too now */
((SilcSocketConnection)server_entry->connection)->protocol =
silc_buffer_free(packet);
- /* If we are router then announce our possible servers. */
- if (server->server_type == SILC_ROUTER)
- silc_server_announce_servers(server, FALSE, 0, ctx->sock);
+ /* Announce all of our information */
+ silc_server_announce_servers(server, TRUE, 0, ctx->sock);
silc_server_announce_clients(server, 0, ctx->sock);
silc_server_announce_channels(server, 0, ctx->sock);
break;
}
- /* Switch announced informations to our entry instead of using the
+ /* Switch announced informations to our primary router of using the
backup router. */
silc_server_update_clients_by_server(server, ctx->sock->user_data,
- server->id_entry, TRUE, FALSE);
+ server->router, TRUE, FALSE);
packet = silc_buffer_alloc(2);
silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
if (silc_idcache_list_first(list, &id_cache)) {
while (id_cache) {
server_entry = (SilcServerEntry)id_cache->context;
- if ((server_entry == server->id_entry) ||
- !server_entry->connection) {
+ if (!server_entry || (server_entry == server->id_entry) ||
+ !server_entry->connection || !server_entry->data.send_key) {
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ else
+ continue;
+ }
+
+ SILC_LOG_DEBUG(("********************************"));
+ SILC_LOG_DEBUG(("RESUMED packet (local)"));
+
+ server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
+
+ /* This connection is performing this protocol too now */
+ ((SilcSocketConnection)server_entry->connection)->protocol =
+ protocol;
+
+ if (server_entry->server_type == SILC_ROUTER)
+ packet->data[0] = SILC_SERVER_BACKUP_RESUMED;
+ else
+ packet->data[0] = SILC_SERVER_BACKUP_RESUMED_GLOBAL;
+ silc_server_packet_send(server, server_entry->connection,
+ SILC_PACKET_RESUME_ROUTER, 0,
+ packet->data, packet->len, FALSE);
+
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ }
+ }
+
+ silc_idcache_list_free(list);
+ }
+
+ if (silc_idcache_get_all(server->global_list->servers, &list)) {
+ if (silc_idcache_list_first(list, &id_cache)) {
+ while (id_cache) {
+ server_entry = (SilcServerEntry)id_cache->context;
+ if (!server_entry || (server_entry == server->id_entry) ||
+ !server_entry->connection || !server_entry->data.send_key) {
if (!silc_idcache_list_next(list, &id_cache))
break;
else
}
SILC_LOG_DEBUG(("********************************"));
- SILC_LOG_DEBUG(("RESUMED packet"));
+ SILC_LOG_DEBUG(("RESUMED packet (global)"));
server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
&backup_router)) {
if (backup_router == server->router) {
+ server->id_entry->router = router;
+ server->router = router;
SILC_LOG_INFO(("Switching back to primary router %s",
server->router->server_name));
SILC_LOG_DEBUG(("Switching back to primary router %s",
server->router->server_name));
- server->id_entry->router = router;
- server->router = router;
} else {
SILC_LOG_INFO(("Resuming the use of router %s",
router->server_name));
idata = (SilcIDListData)server->router;
idata->status &= ~SILC_IDLIST_STATUS_DISABLED;
- /* Update the client entries of the backup router to the new router */
+ /* Update the client entries of the backup router to the new
+ router */
silc_server_update_clients_by_server(server, backup_router,
- router, FALSE, FALSE);
+ router, TRUE, FALSE);
silc_server_backup_replaced_del(server, backup_router);
silc_server_backup_add(server, backup_router,
ctx->sock->ip, ctx->sock->port,
/* Announce all of our information to the router. */
if (server->server_type == SILC_ROUTER)
silc_server_announce_servers(server, FALSE, 0, router->connection);
-
+
/* Announce our clients and channels to the router */
silc_server_announce_clients(server, 0, router->connection);
silc_server_announce_channels(server, 0, router->connection);
silc_idcache_list_free(list);
}
+ if (silc_idcache_get_all(server->global_list->servers, &list)) {
+ if (silc_idcache_list_first(list, &id_cache)) {
+ while (id_cache) {
+ server_entry = (SilcServerEntry)id_cache->context;
+ sock = (SilcSocketConnection)server_entry->connection;
+
+ if (sock->protocol == protocol) {
+ sock->protocol = NULL;
+
+ if (server_entry->data.status & SILC_IDLIST_STATUS_DISABLED)
+ server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED;
+ }
+
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ }
+ }
+ silc_idcache_list_free(list);
+ }
+
if (ctx->sock->protocol)
ctx->sock->protocol = NULL;
silc_protocol_free(protocol);
static SilcServerEntry
silc_server_update_clients_by_real_server(SilcServer server,
- SilcClientEntry client)
+ SilcServerEntry from,
+ SilcClientEntry client,
+ bool local,
+ SilcIDCacheEntry client_cache)
{
SilcServerEntry server_entry;
SilcIDCacheEntry id_cache = NULL;
if (silc_idcache_list_first(list, &id_cache)) {
while (id_cache) {
server_entry = (SilcServerEntry)id_cache->context;
- if (SILC_ID_COMPARE(server_entry->id, client->id,
+ if (server_entry != from &&
+ SILC_ID_COMPARE(server_entry->id, client->id,
+ client->id->ip.data_len)) {
+ SILC_LOG_DEBUG(("Found (local) %s",
+ silc_id_render(server_entry->id, SILC_ID_SERVER)));
+
+ /* If the client is not marked as local then move it to local list
+ since the server is local. */
+ if (server_entry->server_type != SILC_BACKUP_ROUTER && !local) {
+ SILC_LOG_DEBUG(("Moving client to local list"));
+ silc_idcache_add(server->local_list->clients, client_cache->name,
+ client_cache->id, client_cache->context,
+ client_cache->expire);
+ silc_idcache_del_by_context(server->global_list->clients, client);
+ }
+
+ silc_idcache_list_free(list);
+ return server_entry;
+ }
+
+ if (!silc_idcache_list_next(list, &id_cache))
+ break;
+ }
+ }
+
+ silc_idcache_list_free(list);
+
+ if (!silc_idcache_get_all(server->global_list->servers, &list))
+ return NULL;
+
+ if (silc_idcache_list_first(list, &id_cache)) {
+ while (id_cache) {
+ server_entry = (SilcServerEntry)id_cache->context;
+ if (server_entry != from &&
+ SILC_ID_COMPARE(server_entry->id, client->id,
client->id->ip.data_len)) {
- SILC_LOG_DEBUG(("Found"));
+ SILC_LOG_DEBUG(("Found (global) %s",
+ silc_id_render(server_entry->id, SILC_ID_SERVER)));
+
+ /* If the client is marked as local then move it to global list
+ since the server is global. */
+ if (server_entry->server_type != SILC_BACKUP_ROUTER && local) {
+ SILC_LOG_DEBUG(("Moving client to global list"));
+ silc_idcache_add(server->global_list->clients, client_cache->name,
+ client_cache->id, client_cache->context,
+ client_cache->expire);
+ silc_idcache_del_by_context(server->local_list->clients, client);
+ }
+
silc_idcache_list_free(list);
return server_entry;
}
SilcIDCacheList list = NULL;
SilcIDCacheEntry id_cache = NULL;
SilcClientEntry client = NULL;
+ bool local;
SILC_LOG_DEBUG(("Start"));
SILC_LOG_DEBUG(("to %s", silc_id_render(to->id,
SILC_ID_SERVER)));
+
+ local = TRUE;
if (silc_idcache_get_all(server->local_list->clients, &list)) {
if (silc_idcache_list_first(list, &id_cache)) {
while (id_cache) {
client = (SilcClientEntry)id_cache->context;
+
if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) {
if (!silc_idcache_list_next(list, &id_cache))
break;
continue;
}
+ SILC_LOG_DEBUG(("Client (local) %s",
+ silc_id_render(client->id, SILC_ID_CLIENT)));
+
if (client->router == from) {
/* Skip clients that are *really* owned by the `from' */
if (remove_from && SILC_ID_COMPARE(from->id, client->id,
if (resolve_real_server) {
client->router =
- silc_server_update_clients_by_real_server(server, client);
+ silc_server_update_clients_by_real_server(server, from, client,
+ local, id_cache);
if (!client->router)
client->router = to;
} else {
silc_idcache_list_free(list);
}
+ local = FALSE;
if (silc_idcache_get_all(server->global_list->clients, &list)) {
if (silc_idcache_list_first(list, &id_cache)) {
while (id_cache) {
client = (SilcClientEntry)id_cache->context;
+
+
if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED)) {
if (!silc_idcache_list_next(list, &id_cache))
break;
continue;
}
+ SILC_LOG_DEBUG(("Client (global) %s",
+ silc_id_render(client->id, SILC_ID_CLIENT)));
+
if (client->router == from) {
/* Skip clients that are *really* owned by the `from' */
if (remove_from && SILC_ID_COMPARE(from->id, client->id,
if (resolve_real_server) {
client->router =
- silc_server_update_clients_by_real_server(server, client);
+ silc_server_update_clients_by_real_server(server, from, client,
+ local, id_cache);
if (!client->router)
client->router = to;
} else {
212.146.42.101:212.146.42.101:706
[Logging]
-#infologfile:silcd2.log:10000
-#warninglogfile:/var/log/silcd_warning.log:10000
-#errorlogfile:silcd2.log:10000
-#fatallogfile:/var/log/silcd_error.log:
+infologfile:cell1_server1.log:
+warninglogfile:cell1_server1.log:
+errorlogfile:cell1_server1.log:
+fatallogfile:cell1_server1.log:
[ConnectionClass]
1:100:100:100
[RouterConnection]
# my primary
-212.146.42.250:passwd:priikone:706:1:1:1:0
+212.146.42.250:passwd:priikone:706:1:1:1
# our backup router in the cell
-212.146.42.100:passwd:priikone:706:1:1:1:1
+212.146.42.100:passwd:priikone:706:1:1:1:212.146.42.250:706:1
[DenyConnection]
212.146.42.102:212.146.42.102:706
[Logging]
-#infologfile:silcd2.log:10000
-#warninglogfile:/var/log/silcd_warning.log:10000
-#errorlogfile:silcd2.log:10000
-#fatallogfile:/var/log/silcd_error.log:
+infologfile:cell1_server2.log:
+warninglogfile:cell1_server2.log:
+errorlogfile:cell1_server2.log:
+fatallogfile:cell1_server2.log:
[ConnectionClass]
1:100:100:100
[RouterConnection]
# my primary
-212.146.42.250:passwd:priikone:706:1:1:1:0
+212.146.42.250:passwd:priikone:706:1:1:1
# our backup router in the cell
-212.146.42.100:passwd:priikone:706:1:1:1:1
+212.146.42.100:passwd:priikone:706:1:1:1:212.146.42.250:706:1
[DenyConnection]
212.146.42.130:212.146.42.130:706
[Logging]
-#infologfile:silcd2.log:10000
-#warninglogfile:/var/log/silcd_warning.log:10000
-#errorlogfile:silcd2.log:10000
-#fatallogfile:/var/log/silcd_error.log:
+infologfile:cell2_server1.log:
+warninglogfile:cell2_server1.log:
+errorlogfile:cell2_server1.log:
+fatallogfile:cell2_server1.log:
[ConnectionClass]
1:100:100:100
[RouterConnection]
# my primary
-212.146.42.251:passwd:priikone:706:1:1:1:0
+212.146.42.251:passwd:priikone:706:1:1:1
[DenyConnection]
212.146.42.131:212.146.42.131:706
[Logging]
-#infologfile:silcd2.log:10000
-#warninglogfile:/var/log/silcd_warning.log:10000
-#errorlogfile:silcd2.log:10000
-#fatallogfile:/var/log/silcd_error.log:
+infologfile:cell2_server2.log:
+warninglogfile:cell2_server2.log:
+errorlogfile:cell2_server2.log:
+fatallogfile:cell2_server2.log:
[ConnectionClass]
1:100:100:100
[RouterConnection]
# my primary
-212.146.42.251:passwd:priikone:706:1:1:1:0
+212.146.42.251:passwd:priikone:706:1:1:1
[DenyConnection]
212.146.42.150:212.146.42.150:706
[Logging]
-#infologfile:silcd2.log:10000
-#warninglogfile:/var/log/silcd_warning.log:10000
-#errorlogfile:silcd2.log:10000
-#fatallogfile:/var/log/silcd_error.log:
+infologfile:cell3_server1.log:
+warninglogfile:cell3_server1.log:
+errorlogfile:cell3_server1.log:
+fatallogfile:cell3_server1.log:
[ConnectionClass]
1:100:100:100
[RouterConnection]
# my primary
-212.146.42.252:passwd:priikone:706:1:1:1:0
+212.146.42.252:passwd:priikone:706:1:1:1
[DenyConnection]
212.146.42.151:212.146.42.151:706
[Logging]
-#infologfile:silcd2.log:10000
-#warninglogfile:/var/log/silcd_warning.log:10000
-#errorlogfile:silcd2.log:10000
-#fatallogfile:/var/log/silcd_error.log:
+infologfile:cell3_server2.log:
+warninglogfile:cell3_server2.log:
+errorlogfile:cell3_server2.log:
+fatallogfile:cell3_server2.log:
[ConnectionClass]
1:100:100:100
[RouterConnection]
# my primary
-212.146.42.252:passwd:priikone:706:1:1:1:0
+212.146.42.252:passwd:priikone:706:1:1:1
[DenyConnection]