From b7135030098342d428431c8ec44168c731870668 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Fri, 29 Mar 2002 08:45:36 +0000 Subject: [PATCH] updates. --- CHANGES | 6 ++++ apps/silcd/server.c | 60 +++++++++++++++++++++++++++++++++------ apps/silcd/server_util.c | 27 ++++++++++++++++++ apps/silcd/server_util.h | 9 ++++++ apps/silcd/serverconfig.c | 29 +++++++++---------- apps/silcd/serverconfig.h | 2 -- apps/silcd/silcd.c | 4 +-- 7 files changed, 108 insertions(+), 29 deletions(-) diff --git a/CHANGES b/CHANGES index e0bf6491..ff8dfd07 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,9 @@ +Fri Mar 29 10:41:07 EET 2002 Pekka Riikonen + + * And yet again reverted back the config thing since Johnny + screwed it up. Affected file silcd/serverconfig.[ch], server.c, + and silcd.c. + Fri Mar 29 03:26:12 CET 2002 Johnny Mnemonic * Added preliminary checking during config parsing for a valid diff --git a/apps/silcd/server.c b/apps/silcd/server.c index c00c3ea9..5a0a9ebd 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -282,7 +282,7 @@ bool silc_server_init(SilcServer server) timeout. It expires as soon as the caller calls silc_server_run. This task performs authentication protocol and key exchange with our primary router. */ - silc_schedule_task_add(server->schedule, sock, + silc_schedule_task_add(server->schedule, 0, silc_server_connect_to_router, (void *)server, 0, 1, SILC_TASK_TIMEOUT, @@ -356,15 +356,10 @@ bool silc_server_init(SilcServer server) bool silc_server_rehash(SilcServer server) { SilcServerConfig newconfig; + SilcUInt32 max_conns; SILC_LOG_INFO(("Rehashing server")); - /* Our old config is gone now. We'll unreference our reference made in - silc_server_init and then destroy it since we are destroying it - underneath the application (layer which called silc_server_init). */ - silc_server_config_unref(&server->config_ref); - silc_server_config_destroy(server->config); - /* Reset the logging system */ silc_log_quick = TRUE; silc_log_flush_all(); @@ -376,10 +371,23 @@ bool silc_server_rehash(SilcServer server) return FALSE; } + max_conns = server->config->param.connections_max; + + /* Our old config is gone now. We'll unreference our reference made in + silc_server_init and then destroy it since we are destroying it + underneath the application (layer which called silc_server_init). */ + silc_server_config_unref(&server->config_ref); + silc_server_config_destroy(server->config); + /* Take new config context */ server->config = newconfig; silc_server_config_ref(&server->config_ref, server->config, server->config); + /* Reinit scheduler if necessary */ + if (server->config->param.connections_max > max_conns) + silc_schedule_reinit(server->schedule, + server->config->param.connections_max); + /* Fix the server_name field */ if (strcmp(server->server_name, newconfig->server_info->server_name)) { silc_free(server->server_name); @@ -416,6 +424,31 @@ bool silc_server_rehash(SilcServer server) silc_pkcs_private_key_set(server->pkcs, server->private_key); } + /* Go through all configured routers after rehash */ + silc_schedule_task_add(server->schedule, 0, + silc_server_connect_to_router, + (void *)server, 0, 1, + SILC_TASK_TIMEOUT, + SILC_TASK_PRI_NORMAL); + + /* Check whether our router status has changed */ + if (server->config->servers) { + SilcServerConfigServer *ptr = server->config->servers; + + server->server_type = SILC_ROUTER; + while (ptr) { + if (ptr->backup_router) { + server->server_type = SILC_BACKUP_ROUTER; + server->backup_router = TRUE; + server->id_entry->server_type = SILC_BACKUP_ROUTER; + break; + } + ptr = ptr->next; + } + } + + SILC_LOG_DEBUG(("Server rehashed")); + return TRUE; } @@ -662,6 +695,17 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router) ptr->host, ptr->port)); if (ptr->initiator) { + /* Check whether we are connected to this host already */ + if (silc_server_num_sockets_by_remote(server, + silc_net_is_ip(ptr->host) ? + ptr->host : NULL, + silc_net_is_ip(ptr->host) ? + NULL : ptr->host, ptr->port, + SILC_SOCKET_TYPE_ROUTER)) { + SILC_LOG_DEBUG(("We are already connected to this router")); + continue; + } + /* Allocate connection object for hold connection specific stuff. */ sconn = silc_calloc(1, sizeof(*sconn)); sconn->server = server; @@ -676,7 +720,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router) if (!server->router_conn && !sconn->backup) server->router_conn = sconn; - silc_schedule_task_add(server->schedule, fd, + silc_schedule_task_add(server->schedule, 0, silc_server_connect_router, (void *)sconn, 0, 1, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index cad3223a..abc20ce6 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -809,6 +809,33 @@ SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip, return count; } +/* Find number of sockets by IP address indicated by remote host, indicatd + by `ip' or `hostname', `port', and `type'. Returns 0 if socket connections + does not exist. If `ip' is provided then `hostname' is ignored. */ + +SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server, + const char *ip, + const char *hostname, + SilcUInt16 port, + SilcSocketType type) +{ + int i, count; + + if (!ip && !hostname) + return 0; + + for (i = 0, count = 0; i < server->config->param.connections_max; i++) { + if (server->sockets[i] && + ((ip && !strcmp(server->sockets[i]->ip, ip)) || + (hostname && !strcmp(server->sockets[i]->hostname, hostname))) && + server->sockets[i]->port == port && + server->sockets[i]->type == type) + count++; + } + + return count; +} + /* Finds locally cached public key by the public key received in the SKE. If we have it locally cached then we trust it and will use it in the authentication protocol. Returns the locally cached public key or NULL diff --git a/apps/silcd/server_util.h b/apps/silcd/server_util.h index 8300a4b5..ebb4b4fc 100644 --- a/apps/silcd/server_util.h +++ b/apps/silcd/server_util.h @@ -87,6 +87,15 @@ char *silc_server_name_modify_bad(const char *name, SilcUInt32 name_len); SilcUInt32 silc_server_num_sockets_by_ip(SilcServer server, const char *ip, SilcSocketType type); +/* Find number of sockets by IP address indicated by remote host, indicatd + by `ip' or `hostname', `port', and `type'. Returns 0 if socket connections + does not exist. If `ip' is provided then `hostname' is ignored. */ +SilcUInt32 silc_server_num_sockets_by_remote(SilcServer server, + const char *ip, + const char *hostname, + SilcUInt16 port, + SilcSocketType type); + /* Finds locally cached public key by the public key received in the SKE. If we have it locally cached then we trust it and will use it in the authentication protocol. Returns the locally cached public key or NULL diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index 0b31048a..b4c264b3 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -884,10 +884,6 @@ SILC_CONFIG_CALLBACK(fetch_server) goto got_err; } } - else if (!strcmp(name, "versionid")) { - CONFIG_IS_DOUBLE(tmp->version); - tmp->version = strdup((char *) val); - } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); tmp->param = my_find_param(config, (char *) val, line); @@ -906,7 +902,6 @@ SILC_CONFIG_CALLBACK(fetch_server) got_err: silc_free(tmp->host); - silc_free(tmp->version); CONFIG_FREE_AUTH(tmp); silc_free(tmp); config->tmp = NULL; @@ -966,10 +961,6 @@ SILC_CONFIG_CALLBACK(fetch_router) goto got_err; } } - else if (!strcmp(name, "versionid")) { - CONFIG_IS_DOUBLE(tmp->version); - tmp->version = strdup((char *) val); - } else if (!strcmp(name, "params")) { CONFIG_IS_DOUBLE(tmp->param); tmp->param = my_find_param(config, (char *) val, line); @@ -1004,7 +995,6 @@ SILC_CONFIG_CALLBACK(fetch_router) got_err: silc_free(tmp->host); - silc_free(tmp->version); silc_free(tmp->backup_replace_ip); CONFIG_FREE_AUTH(tmp); silc_free(tmp); @@ -1144,7 +1134,6 @@ static const SilcConfigTable table_serverconn[] = { { "host", SILC_CONFIG_ARG_STRE, fetch_server, NULL }, { "passphrase", SILC_CONFIG_ARG_STR, fetch_server, NULL }, { "publickey", SILC_CONFIG_ARG_STR, fetch_server, NULL }, - { "versionid", SILC_CONFIG_ARG_STR, fetch_server, NULL }, { "params", SILC_CONFIG_ARG_STR, fetch_server, NULL }, { "backup", SILC_CONFIG_ARG_TOGGLE, fetch_server, NULL }, { 0, 0, 0, 0 } @@ -1155,7 +1144,6 @@ static const SilcConfigTable table_routerconn[] = { { "port", SILC_CONFIG_ARG_INT, fetch_router, NULL }, { "passphrase", SILC_CONFIG_ARG_STR, fetch_router, NULL }, { "publickey", SILC_CONFIG_ARG_STR, fetch_router, NULL }, - { "versionid", SILC_CONFIG_ARG_STR, fetch_router, NULL }, { "params", SILC_CONFIG_ARG_STR, fetch_router, NULL }, { "initiator", SILC_CONFIG_ARG_TOGGLE, fetch_router, NULL }, { "backuphost", SILC_CONFIG_ARG_STRE, fetch_router, NULL }, @@ -1310,7 +1298,11 @@ void silc_server_config_destroy(SilcServerConfig config) SILC_LOG_DEBUG(("Freeing config context")); + /* Destroy general config stuff */ silc_free(config->module_path); + silc_free(config->param.version_protocol); + silc_free(config->param.version_software); + silc_free(config->param.version_software_vendor); /* Destroy Logging channels */ if (config->logging_info) @@ -1361,8 +1353,15 @@ void silc_server_config_destroy(SilcServerConfig config) silc_free(di->name); silc_free(di); } - SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient, - config->clients) + SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigConnParams, + config->conn_params) + silc_free(di->name); + silc_free(di->version_protocol); + silc_free(di->version_software); + silc_free(di->version_software_vendor); + silc_free(di); + } + SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigClient, config->clients) silc_free(di->host); CONFIG_FREE_AUTH(di); silc_free(di); @@ -1382,14 +1381,12 @@ void silc_server_config_destroy(SilcServerConfig config) SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigServer, config->servers) silc_free(di->host); - silc_free(di->version); CONFIG_FREE_AUTH(di); silc_free(di); } SILC_SERVER_CONFIG_LIST_DESTROY(SilcServerConfigRouter, config->routers) silc_free(di->host); - silc_free(di->version); silc_free(di->backup_replace_ip); CONFIG_FREE_AUTH(di); silc_free(di); diff --git a/apps/silcd/serverconfig.h b/apps/silcd/serverconfig.h index cd5e2201..4d79063d 100644 --- a/apps/silcd/serverconfig.h +++ b/apps/silcd/serverconfig.h @@ -122,7 +122,6 @@ typedef struct SilcServerConfigServerStruct { unsigned char *passphrase; SilcUInt32 passphrase_len; SilcHashTable publickeys; - char *version; SilcServerConfigConnParams *param; bool backup_router; struct SilcServerConfigServerStruct *next; @@ -135,7 +134,6 @@ typedef struct SilcServerConfigRouterStruct { SilcUInt32 passphrase_len; SilcHashTable publickeys; SilcUInt16 port; - char *version; SilcServerConfigConnParams *param; bool initiator; bool backup_router; diff --git a/apps/silcd/silcd.c b/apps/silcd/silcd.c index 2ad30724..82d29d7a 100644 --- a/apps/silcd/silcd.c +++ b/apps/silcd/silcd.c @@ -381,9 +381,6 @@ int main(int argc, char **argv) if (silcd->config == NULL) goto fail; silcd->config_file = silcd_config_file; - /* Since silc_server_config_alloc returns an unreferenced config object - we must immediately increment it. */ - silc_server_config_ref(&silcd->config_ref, silcd->config, silcd->config); /* Check for another silcd running */ silc_server_checkpid(silcd); @@ -428,6 +425,7 @@ int main(int argc, char **argv) /* Stop the server and free it. */ silc_server_stop(silcd); silc_server_free(silcd); + silc_server_config_destroy(silcd->config); /* Flush the logging system */ silc_log_flush_all(); -- 2.24.0