From 90b680ff05ea4a658865085e7be524854d5861e2 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Thu, 11 Oct 2001 21:07:28 +0000 Subject: [PATCH] updates. --- CHANGES | 12 ++++ TODO | 2 + apps/silcd/server.c | 34 +++++++--- apps/silcd/server.h | 2 + apps/silcd/server_backup.c | 108 +++++++++++++++++++++--------- apps/silcd/server_backup.h | 23 +++---- apps/silcd/server_internal.h | 4 +- apps/silcd/serverconfig.c | 37 +++++----- apps/silcd/serverconfig.h | 2 + doc/Makefile.am.pre | 6 +- doc/example_silcd.conf | 19 ++++-- doc/examples/README | 7 +- doc/examples/cell1_backup.conf | 10 +-- doc/examples/cell1_router.conf | 8 +-- doc/examples/cell2_router.conf | 6 +- doc/examples/cell3_router.conf | 6 +- lib/silcutil/silcnet.c | 1 + lib/silcutil/silcnet.h | 16 +++++ lib/silcutil/unix/silcunixnet.c | 19 ++++++ lib/silcutil/win32/silcwin32net.c | 18 +++++ 20 files changed, 248 insertions(+), 92 deletions(-) diff --git a/CHANGES b/CHANGES index 67902536..477550ee 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,15 @@ +Thu Oct 11 22:19:26 EDT 2001 Pekka Riikonen + + * Changed the backup router adding and getting interfaces + in the server. The router that will be replaced by the + specified backup router is now sent as argument. Affected + files silcd/serverconfig.[ch], silcd/backup_router.[ch], and + silcd/server.c. + + * Added silc_net_addr2bin_ne to return the binary form of + the IP address in network byte order. Affected files + lib/silcutil/[unix/win32].silc[unix/win32]net.[ch]. + Thu Oct 11 12:14:19 EDT 2001 Pekka Riikonen * Check for existing server ID in silc_server_new_server diff --git a/TODO b/TODO index feaa084f..fa210ce6 100644 --- a/TODO +++ b/TODO @@ -1,6 +1,8 @@ TODO/bugs in Irssi SILC client ============================== + o /key msg * list crashes the client + o Add local command to switch the channel's private key when channel has several private keys. Currently sending channel messages with many keys is not possible because changing the key is not possible by the diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 101235e4..dfc40225 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -659,7 +659,11 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router) sconn->remote_host = strdup(ptr->host); sconn->remote_port = ptr->port; sconn->backup = ptr->backup_router; - + if (sconn->backup) { + sconn->backup_replace_ip = strdup(ptr->backup_replace_ip); + sconn->backup_replace_port = ptr->backup_replace_port; + } + silc_schedule_task_add(server->schedule, fd, silc_server_connect_router, (void *)sconn, 0, 1, SILC_TASK_TIMEOUT, @@ -939,7 +943,8 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_final) } } else { /* Add this server to be our backup router */ - silc_server_backup_add(server, id_entry, FALSE); + silc_server_backup_add(server, id_entry, sconn->backup_replace_ip, + sconn->backup_replace_port, FALSE); } sock->protocol = NULL; @@ -953,6 +958,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_final) /* Free the temporary connection data context */ if (sconn) { silc_free(sconn->remote_host); + silc_free(sconn->backup_replace_ip); silc_free(sconn); } @@ -1359,7 +1365,8 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final) /* If the incoming connection is router and marked as backup router then add it to be one of our backups */ if (ctx->conn_type == SILC_SOCKET_TYPE_ROUTER && conn->backup_router) { - silc_server_backup_add(server, new_server, conn->backup_local); + silc_server_backup_add(server, new_server, conn->backup_replace_ip, + conn->backup_replace_port, conn->backup_local); /* Change it back to SERVER type since that's what it really is. */ if (conn->backup_local) { @@ -2323,11 +2330,12 @@ void silc_server_free_sock_user_data(SilcServer server, SilcServerEntry user_data = (SilcServerEntry)sock->user_data; SilcServerEntry backup_router = NULL; + if (user_data->id) + backup_router = silc_server_backup_get(server, user_data->id); + /* If this was our primary router connection then we're lost to the outside world. */ if (server->router == user_data) { - backup_router = silc_server_backup_get(server); - /* Check whether we have a backup router connection */ if (!backup_router || backup_router == user_data) { silc_schedule_task_add(server->schedule, 0, @@ -2348,6 +2356,7 @@ void silc_server_free_sock_user_data(SilcServer server, server->id_entry->router = backup_router; server->router = backup_router; server->router_connect = time(0); + server->backup_primary = TRUE; if (server->server_type == SILC_BACKUP_ROUTER) { server->server_type = SILC_ROUTER; @@ -2362,6 +2371,15 @@ void silc_server_free_sock_user_data(SilcServer server, silc_server_backup_replaced_add(server, user_data->id, backup_router); } + } else if (backup_router) { + SILC_LOG_INFO(("Enabling the use of backup router %s", + backup_router->server_name)); + SILC_LOG_DEBUG(("Enabling the use of backup router %s", + backup_router->server_name)); + + /* Mark this connection as replaced */ + silc_server_backup_replaced_add(server, user_data->id, + backup_router); } if (!backup_router) { @@ -2392,13 +2410,13 @@ void silc_server_free_sock_user_data(SilcServer server, The backup router knows all the other stuff already. */ if (server->server_type == SILC_ROUTER) silc_server_announce_servers(server, FALSE, time(0) - 300, - server->router->connection); + backup_router->connection); /* Announce our clients and channels to the router */ silc_server_announce_clients(server, time(0) - 300, - server->router->connection); + backup_router->connection); silc_server_announce_channels(server, time(0) - 300, - server->router->connection); + backup_router->connection); } break; } diff --git a/apps/silcd/server.h b/apps/silcd/server.h index d2abd2c9..a09d41b9 100644 --- a/apps/silcd/server.h +++ b/apps/silcd/server.h @@ -84,6 +84,8 @@ typedef struct { char *remote_host; int remote_port; bool backup; + char *backup_replace_ip; + int backup_replace_port; /* Current connection retry info */ uint32 retry_count; diff --git a/apps/silcd/server_backup.c b/apps/silcd/server_backup.c index 96f9c33f..3a16e54a 100644 --- a/apps/silcd/server_backup.c +++ b/apps/silcd/server_backup.c @@ -26,6 +26,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_backup_done); /* Backup router */ typedef struct { SilcServerEntry server; + SilcIDIP ip; + uint16 port; bool local; } SilcServerBackupEntry; @@ -63,16 +65,22 @@ typedef struct { long start; } *SilcServerBackupProtocolContext; -/* Sets the `backup_server' to be one of our backup router. This can be - called multiple times to set multiple backup routers. If `local' is - TRUE then the `backup_server' is in the local cell, if FALSE it is - in some other cell. */ +/* Adds the `backup_server' to be one of our backup router. This can be + called multiple times to set multiple backup routers. The `ip' and `port' + is the IP and port that the `backup_router' will replace if the `ip' + will become unresponsive. If `local' is TRUE then the `backup_server' is + in the local cell, if FALSE it is in some other cell. */ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server, - bool local) + const char *ip, int port, bool local) { int i; + SILC_LOG_DEBUG(("Start")); + + if (!ip) + return; + if (!server->backup) server->backup = silc_calloc(1, sizeof(*server->backup)); @@ -80,6 +88,11 @@ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server, if (!server->backup->servers[i].server) { server->backup->servers[i].server = backup_server; server->backup->servers[i].local = local; + memset(server->backup->servers[i].ip.data, 0, + sizeof(server->backup->servers[i].ip.data)); + silc_net_addr2bin_ne(ip, server->backup->servers[i].ip.data, + sizeof(server->backup->servers[i].ip.data)); + //server->backup->servers[i].port = port; return; } } @@ -90,38 +103,46 @@ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server, (i + 1)); server->backup->servers[i].server = backup_server; server->backup->servers[i].local = local; + memset(server->backup->servers[i].ip.data, 0, + sizeof(server->backup->servers[i].ip.data)); + silc_net_addr2bin_ne(ip, server->backup->servers[i].ip.data, + sizeof(server->backup->servers[i].ip.data)); + //server->backup->servers[i].port = server_id->port; server->backup->servers_count++; } -/* Returns the first backup router context. Returns NULL if we do not have - any backup servers. */ +/* Returns backup router for IP and port in `replacing' or NULL if there + does not exist backup router. */ -SilcServerEntry silc_server_backup_get(SilcServer server) +SilcServerEntry silc_server_backup_get(SilcServer server, + SilcServerID *server_id) { - SilcServerEntry backup_router; int i; + SILC_LOG_DEBUG(("Start")); + if (!server->backup) return NULL; for (i = 0; i < server->backup->servers_count; i++) { - if (server->backup->servers[i].server) { - backup_router = server->backup->servers[i].server; - server->backup->servers[i].server = NULL; - return backup_router; - } + SILC_LOG_HEXDUMP(("IP"), server_id->ip.data, 16); + SILC_LOG_HEXDUMP(("IP"), server->backup->servers[i].ip.data, 16); + if (server->backup->servers[i].server && + !memcmp(&server->backup->servers[i].ip, &server_id->ip.data, + sizeof(server_id->ip.data))) + return server->backup->servers[i].server; } return NULL; } -/* Deletes the backup server `server_entry. */ - -void silc_server_backup_del(SilcServer server, - SilcServerEntry server_entry) +/* Deletes the backup server `server_entry'. */ +void silc_server_backup_del(SilcServer server, SilcServerEntry server_entry) { int i; + SILC_LOG_DEBUG(("Start")); + if (!server->backup) return ; @@ -145,6 +166,8 @@ void silc_server_backup_replaced_add(SilcServer server, int i; SilcServerBackupReplaced *r = silc_calloc(1, sizeof(*r));; + SILC_LOG_DEBUG(("Start")); + if (!server->backup) server->backup = silc_calloc(1, sizeof(*server->backup)); if (!server->backup->replaced) { @@ -186,7 +209,9 @@ bool silc_server_backup_replaced_get(SilcServer server, { int i; - SILC_LOG_DEBUG(("***********************************************")); + SILC_LOG_DEBUG(("Start")); + + SILC_LOG_DEBUG(("*************************************")); if (!server->backup || !server->backup->replaced) return FALSE; @@ -197,8 +222,8 @@ bool silc_server_backup_replaced_get(SilcServer server, SILC_LOG_HEXDUMP(("IP"), server_id->ip.data, server_id->ip.data_len); SILC_LOG_HEXDUMP(("IP"), server->backup->replaced[i]->ip.data, server->backup->replaced[i]->ip.data_len); - if (!memcmp(&server->backup->replaced[i]->ip, &server_id->ip, - sizeof(server_id->ip))) { + if (!memcmp(&server->backup->replaced[i]->ip, &server_id->ip.data, + sizeof(server_id->ip.data))) { if (server_entry) *server_entry = server->backup->replaced[i]->server; SILC_LOG_DEBUG(("REPLACED")); @@ -217,6 +242,8 @@ void silc_server_backup_replaced_del(SilcServer server, { int i; + SILC_LOG_DEBUG(("Start")); + if (!server->backup || !server->backup->replaced) return; @@ -382,6 +409,7 @@ void silc_server_backup_resume_router(SilcServer server, SILC_LOG_DEBUG(("Start")); + SILC_LOG_DEBUG(("********************************")); ret = silc_buffer_unformat(packet->buffer, SILC_STR_UI_CHAR(&type), SILC_STR_UI_CHAR(&session), @@ -389,6 +417,7 @@ void silc_server_backup_resume_router(SilcServer server, if (ret < 0) return; + SILC_LOG_DEBUG(("********************************")); /* If the backup resuming protocol is active then process the packet in the protocol. */ if (sock->protocol && sock->protocol->protocol && @@ -419,6 +448,7 @@ void silc_server_backup_resume_router(SilcServer server, return; } + SILC_LOG_DEBUG(("********************************")); /* We don't have protocol active. If we are router and the packet is coming from our primary router then lets check whether it means we've been replaced by an backup router in my cell. This is usually received @@ -432,11 +462,15 @@ void silc_server_backup_resume_router(SilcServer server, to use it at this moment. */ SilcIDListData idata = (SilcIDListData)sock->user_data; + SILC_LOG_INFO(("We are replaced by an backup router in this cell, will " + "wait untill backup resuming protocol is executed")); + SILC_LOG_DEBUG(("We are replaced by an backup router in this cell")); idata->status |= SILC_IDLIST_STATUS_DISABLED; return; } + SILC_LOG_DEBUG(("********************************")); if (type == SILC_SERVER_BACKUP_START || type == SILC_SERVER_BACKUP_START_GLOBAL) { /* We have received a start for resuming protocol. */ @@ -458,6 +492,7 @@ void silc_server_backup_resume_router(SilcServer server, silc_server_protocol_backup_done); silc_protocol_execute(sock->protocol, server->schedule, 0, 0); } + SILC_LOG_DEBUG(("EEEEEEEEEEEEEEEEEEEEEEEEe")); } /* Timeout task callback to connect to remote router */ @@ -478,7 +513,7 @@ SILC_TASK_CALLBACK(silc_server_backup_connect_to_router) if (sock < 0) { silc_schedule_task_add(server->schedule, 0, silc_server_backup_connect_to_router, - context, 2, 0, SILC_TASK_TIMEOUT, + context, 5, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); return; } @@ -506,7 +541,7 @@ void silc_server_backup_reconnect(SilcServer server, sconn->callback_context = context; silc_schedule_task_add(server->schedule, 0, silc_server_backup_connect_to_router, - sconn, 2, 0, SILC_TASK_TIMEOUT, + sconn, 1, 0, SILC_TASK_TIMEOUT, SILC_TASK_PRI_NORMAL); } @@ -568,6 +603,8 @@ static void silc_server_backup_connect_primary(SilcServer server, (SilcServerBackupProtocolContext)backup_router->protocol->context; SilcBuffer buffer; + SILC_LOG_DEBUG(("Start")); + SILC_LOG_DEBUG(("********************************")); SILC_LOG_DEBUG(("Sending CONNECTED packet, session %d", ctx->session)); @@ -754,18 +791,11 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup) to be back online. We send the CONNECTED packet after we've established the connection to the primary router. */ primary = silc_server_config_get_primary_router(server->config); - if (primary) { + if (primary && server->backup_primary) { silc_server_backup_reconnect(server, primary->host, primary->port, silc_server_backup_connect_primary, ctx->sock); - if (server->server_type == SILC_ROUTER && - (!server->router || - server->router->data.status & SILC_IDLIST_STATUS_DISABLED)) - protocol->state++; - else - protocol->state = SILC_PROTOCOL_STATE_END; - } else { /* Nowhere to connect just return the CONNECTED packet */ @@ -783,9 +813,15 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup) SILC_PACKET_RESUME_ROUTER, 0, packet->data, packet->len, FALSE); silc_buffer_free(packet); - protocol->state++; } + if (server->server_type == SILC_ROUTER && + (!server->router || + server->router->data.status & SILC_IDLIST_STATUS_DISABLED)) + protocol->state++; + else + protocol->state = SILC_PROTOCOL_STATE_END; + ctx->sessions = silc_realloc(ctx->sessions, sizeof(*ctx->sessions) * (ctx->sessions_count + 1)); @@ -889,6 +925,8 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup) SILC_LOG_DEBUG(("********************************")); SILC_LOG_DEBUG(("RESUMED packet")); + server_entry->data.status &= ~SILC_IDLIST_STATUS_DISABLED; + /* This connection is performing this protocol too now */ ((SilcSocketConnection)server_entry->connection)->protocol = protocol; @@ -960,7 +998,11 @@ SILC_TASK_CALLBACK_GLOBAL(silc_server_protocol_backup) silc_server_update_clients_by_server(server, backup_router, primary, TRUE, FALSE); silc_server_backup_replaced_del(server, backup_router); - silc_server_backup_add(server, backup_router, + silc_server_backup_add(server, backup_router, + ((SilcSocketConnection)primary-> + connection)->ip, + ((SilcSocketConnection)primary-> + connection)->port, backup_router->server_type != SILC_ROUTER ? TRUE : FALSE); } diff --git a/apps/silcd/server_backup.h b/apps/silcd/server_backup.h index 42df86e2..57f6a05d 100644 --- a/apps/silcd/server_backup.h +++ b/apps/silcd/server_backup.h @@ -30,21 +30,20 @@ #define SILC_SERVER_BACKUP_REPLACED 20 /* Adds the `backup_server' to be one of our backup router. This can be - called multiple times to set multiple backup routers. If `local' is - TRUE then the `backup_server' is in the local cell, if FALSE it is - in some other cell. */ + called multiple times to set multiple backup routers. The `replacing' is + the IP and port that the `backup_router' will replace if the `replacing' + will become unresponsive. If `local' is TRUE then the `backup_server' is + in the local cell, if FALSE it is in some other cell. */ void silc_server_backup_add(SilcServer server, SilcServerEntry backup_server, - bool local); + const char *ip, int port, bool local); -/* Returns the first backup router context. Returns NULL if we do not have - any backup servers. This removes the returned server from being - backup router and needs to be added later with silc_server_backup_add - if it needs to be backup router again. */ -SilcServerEntry silc_server_backup_get(SilcServer server); +/* Returns backup router for IP and port in `replacing' or NULL if there + does not exist backup router. */ +SilcServerEntry silc_server_backup_get(SilcServer server, + SilcServerID *server_id); -/* Deletes the backup server `server_entry. */ -void silc_server_backup_del(SilcServer server, - SilcServerEntry server_entry); +/* Deletes the backup server `server_entry'. */ +void silc_server_backup_del(SilcServer server, SilcServerEntry server_entry); /* Marks the IP address and port from the `server_id' as being replaced by backup router indicated by the `server'. If the router connects at diff --git a/apps/silcd/server_internal.h b/apps/silcd/server_internal.h index 5cd0241e..a40adec6 100644 --- a/apps/silcd/server_internal.h +++ b/apps/silcd/server_internal.h @@ -77,7 +77,9 @@ struct SilcServerStruct { SilcServerEntry router; /* Pointer to the primary router */ unsigned long router_connect; /* Time when router was connected */ SilcServerBackup backup; /* Backup routers */ - bool backup_router; + bool backup_router; /* TRUE if this is backup router */ + bool backup_primary; /* TRUE if we've switched our primary + router to a backup router. */ /* Current command identifier, 0 not used */ uint16 cmd_ident; diff --git a/apps/silcd/serverconfig.c b/apps/silcd/serverconfig.c index ecc35e2f..5aaec489 100644 --- a/apps/silcd/serverconfig.c +++ b/apps/silcd/serverconfig.c @@ -951,22 +951,27 @@ int silc_server_config_parse_lines(SilcServerConfig config, silc_free(tmp); } - /* Check whether this connection is backup router connection */ - ret = silc_config_get_token(line, &tmp); - if (ret != -1) { - config->routers->backup_router = atoi(tmp); - if (config->routers->backup_router != 0) - config->routers->backup_router = TRUE; - silc_free(tmp); - } - - /* Check whether this backup is local (in cell) or remote (other cell) */ - ret = silc_config_get_token(line, &tmp); - if (ret != -1) { - config->routers->backup_local = atoi(tmp); - if (config->routers->backup_local != 0) - config->routers->backup_local = TRUE; - silc_free(tmp); + /* Get backup replace IP */ + ret = silc_config_get_token(line, &config->routers->backup_replace_ip); + if (ret != -1) + config->routers->backup_router = TRUE; + + if (config->routers->backup_router) { + /* Get backup replace port */ + ret = silc_config_get_token(line, &tmp); + if (ret != -1) { + config->routers->backup_replace_port = atoi(tmp); + silc_free(tmp); + } + + /* Check whether the backup connection is local */ + ret = silc_config_get_token(line, &tmp); + if (ret != -1) { + config->routers->backup_local = atoi(tmp); + if (config->routers->backup_local != 0) + config->routers->backup_local = TRUE; + silc_free(tmp); + } } check = TRUE; diff --git a/apps/silcd/serverconfig.h b/apps/silcd/serverconfig.h index 0c424a43..1df1e95a 100644 --- a/apps/silcd/serverconfig.h +++ b/apps/silcd/serverconfig.h @@ -133,6 +133,8 @@ typedef struct SilcServerConfigSectionServerConnectionStruct { uint32 class; bool initiator; bool backup_router; + char *backup_replace_ip; + uint16 backup_replace_port; bool backup_local; struct SilcServerConfigSectionServerConnectionStruct *next; struct SilcServerConfigSectionServerConnectionStruct *prev; diff --git a/doc/Makefile.am.pre b/doc/Makefile.am.pre index f0070076..fa293af5 100644 --- a/doc/Makefile.am.pre +++ b/doc/Makefile.am.pre @@ -78,10 +78,14 @@ endif endif if SILC_DIST_TOOLKIT -SILC_EXTRA_DIST = toolkit +SILC_EXTRA_DIST = toolkit examples +else +if SILC_DIST_SERVER +SILC_EXTRA_DIST = examples else SILC_EXTRA_DIST = endif +endif EXTRA_DIST = \ CodingStyle \ diff --git a/doc/example_silcd.conf b/doc/example_silcd.conf index 6f9afc63..aa29aabf 100644 --- a/doc/example_silcd.conf +++ b/doc/example_silcd.conf @@ -1,3 +1,9 @@ +# +# Example configuration file. Note that this attempts to present various +# configuration possibilities and may not actually give any sensible +# configuration. For real life example see the examples/ directory. +# + # # Configured ciphers. # @@ -173,7 +179,8 @@ infologfile:/usr/local/silc/logs/silcd.log:10000 # configured connection is the primary route. # # Format: ::::: -# ::: +# :::: +# # # The is either passphrase or file path to the public key # file. If you are the initiator of the connection then set the @@ -181,14 +188,16 @@ infologfile:/usr/local/silc/logs/silcd.log:10000 # incoming connection) then set it to 0. # # If the connection is backup router connection then set the to value 1. For normal connection set it to 0. If this +# replace IP> to the IP address of the router that the backup router will +# replace if it becomes unavailable. Set also the router's port to the +# . For normal connection leave both empty. If this # backup router is in our cell then set the to value 1. # If the backup router is in other cell then set it to value 0. # [RouterConnection] -#10.2.1.100:passwd:veryverysecret:706:1:1:1:0:0 -#10.2.100.131:pubkey:/path/to/the/publickey:706:1:1:1:0:0 -#10.2.100.100:pubkey:/path/to/the/publickey:706:1:1:0:1:1 +#10.2.1.100:passwd:veryverysecret:706:1:1:1 +#10.2.100.131:pubkey:/path/to/the/publickey:706:1:1:1 +#10.2.100.100:pubkey:/path/to/the/publickey:706:1:1:0:10.2.1.6:706:1 # # Denied connections. diff --git a/doc/examples/README b/doc/examples/README index baf3a03e..fa0b5520 100644 --- a/doc/examples/README +++ b/doc/examples/README @@ -1,5 +1,5 @@ This directory includes example files for a small SILC network. The -network conists of three (3) routers, and seven (7) servers. One of +network consists of three (3) routers, and seven (7) servers. One of the cell also has a backup router too. The topology of the network is as follows: @@ -24,6 +24,11 @@ keys. They are the silcd.pub and silcd.prv in this directory. Also, to make authentication simple all servers and routers authenticate themselves to other routers by simple password. +Also note that the format in the configuration file is very raw so if you +need any help to understand what some setting means please check the +documented example configuration files in doc/ directory. Mainly, the +example_silcd.conf. + If you want to test this network you should change the IP addresses in the configuration file or perhaps set IP aliases for you local machine. diff --git a/doc/examples/cell1_backup.conf b/doc/examples/cell1_backup.conf index d8df37a2..24cb20f0 100644 --- a/doc/examples/cell1_backup.conf +++ b/doc/examples/cell1_backup.conf @@ -51,15 +51,15 @@ backup.cell1.com:212.146.42.100:Kuopio, Finland:706 [ServerConnection] # backup connections -212.146.42.101:passwd:priikone:706:1:1 -212.146.42.102:passwd:priikone:706:1:1 +212.146.42.101:passwd:priikone:706:1:1:1 +212.146.42.102:passwd:priikone:706:1:1:1 [RouterConnection] # my primary -212.146.42.250:passwd:priikone:706:1:1:1:0 +212.146.42.250:passwd:priikone:706:1:1:1 # backup connection to my primary's primary -212.146.42.251:passwd:priikone:706:1:1:1:1 +212.146.42.251:passwd:priikone:706:1:1:1:212.146.42.250:706 # this use my primary as it's primary and me as backup -212.146.42.252:passwd:priikone:706:1:1:0:1 +212.146.42.252:passwd:priikone:706:1:1:0:212.146.42.250:706 [DenyConnection] diff --git a/doc/examples/cell1_router.conf b/doc/examples/cell1_router.conf index c0fea700..f243e09c 100644 --- a/doc/examples/cell1_router.conf +++ b/doc/examples/cell1_router.conf @@ -62,10 +62,10 @@ router.cell1.com:212.146.42.250:Kuopio, Finland:706 [RouterConnection] # my primary -212.146.42.251:passwd:priikone:706:1:1:1:0 +212.146.42.251:passwd:priikone:706:1:1:1 # this use me as primary -212.146.42.252:passwd:priikone:706:1:1:0:0 -# our backup router -212.146.42.100:passwd:priikone:706:1:1:0:1:1 +212.146.42.252:passwd:priikone:706:1:1:0 +# our backup router (it will replace me if I'll go down) +212.146.42.100:passwd:priikone:706:1:1:0:212.146.42.250:706:1 [DenyConnection] diff --git a/doc/examples/cell2_router.conf b/doc/examples/cell2_router.conf index 29380410..5ac59464 100644 --- a/doc/examples/cell2_router.conf +++ b/doc/examples/cell2_router.conf @@ -61,10 +61,10 @@ router.cell2.com:212.146.42.251:Kuopio, Finland:706 [RouterConnection] # my primary -212.146.42.252:passwd:priikone:706:1:1:1:0 +212.146.42.252:passwd:priikone:706:1:1:1 # this use me as primary -212.146.42.250:passwd:priikone:706:1:1:0:0 +212.146.42.250:passwd:priikone:706:1:1:0 # this is the 212.146.42.250 router's backup router -212.146.42.100:passwd:priikone:706:1:1:0:1:0 +212.146.42.100:passwd:priikone:706:1:1:0:212.146.42.250:706:0 [DenyConnection] diff --git a/doc/examples/cell3_router.conf b/doc/examples/cell3_router.conf index c6cd593c..b4a9dab4 100644 --- a/doc/examples/cell3_router.conf +++ b/doc/examples/cell3_router.conf @@ -61,11 +61,11 @@ router.cell3.com:212.146.42.252:Kuopio, Finland:706 [RouterConnection] # my primary -212.146.42.250:passwd:priikone:706:1:1:1:0 +212.146.42.250:passwd:priikone:706:1:1:1 # this use me as primary -212.146.42.251:passwd:priikone:706:1:1:0:0 +212.146.42.251:passwd:priikone:706:1:1:0 # this is 212.146.42.250 router's (my primary's) backup router -212.146.42.100:passwd:priikone:706:1:1:1:1:0 +212.146.42.100:passwd:priikone:706:1:1:1:212.146.42.250:706:0 [DenyConnection] diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index ad563705..35d64270 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -43,6 +43,7 @@ int silc_net_get_socket_opt(int sock, int level, int option, { return getsockopt(sock, level, option, optval, opt_len); } + /* Checks whether IP address sent as argument is valid IP address. */ bool silc_net_is_ip(const char *addr) diff --git a/lib/silcutil/silcnet.h b/lib/silcutil/silcnet.h index 53cad167..2cfa2430 100644 --- a/lib/silcutil/silcnet.h +++ b/lib/silcutil/silcnet.h @@ -206,6 +206,22 @@ bool silc_net_is_ip(const char *addr); bool silc_net_addr2bin(const char *addr, unsigned char *bin, uint32 bin_len); +/****f* silcutil/SilcNetAPI/silc_net_addr2bin_ne + * + * SYNOPSIS + * + * bool silc_net_addr2bin_ne(const char *addr, unsigned char *bin, + * uint32 bin_len); + * + * DESCRIPTION + * + * Converts the IP number string from numbers-and-dots notation to + * binary form in network byte order. + * + ***/ +bool silc_net_addr2bin_ne(const char *addr, unsigned char *bin, + uint32 bin_len); + /****f* silcutil/SilcNetAPI/silc_net_check_host_by_sock * * SYNOPSIS diff --git a/lib/silcutil/unix/silcunixnet.c b/lib/silcutil/unix/silcunixnet.c index 5268d554..4a97ee31 100644 --- a/lib/silcutil/unix/silcunixnet.c +++ b/lib/silcutil/unix/silcunixnet.c @@ -285,3 +285,22 @@ bool silc_net_addr2bin(const char *addr, unsigned char *bin, return ret != 0; } + +/* Converts the IP number string from numbers-and-dots notation to + binary form in network byte order. */ + +bool silc_net_addr2bin_ne(const char *addr, unsigned char *bin, + uint32 bin_len) +{ + struct in_addr tmp; + int ret; + + ret = inet_aton(addr, &tmp); + + if (bin_len < 4) + return FALSE; + + SILC_PUT32_MSB(tmp.s_addr, bin); + + return ret != 0; +} diff --git a/lib/silcutil/win32/silcwin32net.c b/lib/silcutil/win32/silcwin32net.c index e4ffc6aa..25bde190 100644 --- a/lib/silcutil/win32/silcwin32net.c +++ b/lib/silcutil/win32/silcwin32net.c @@ -237,6 +237,24 @@ bool silc_net_addr2bin(const char *addr, unsigned char *bin, return ret != INADDR_NONE; } +/* Converts the IP number string from numbers-and-dots notation to + binary form in network byte order. */ + +bool silc_net_addr2bin_ne(const char *addr, unsigned char *bin, + uint32 bin_len) +{ + unsigned long ret; + + ret = inet_addr(addr); + + if (bin_len < 4) + return FALSE; + + SILC_PUT32_MSB(ret, bin); + + return ret != INADDR_NONE; +} + /* Set socket to non-blocking mode. */ int silc_net_set_socket_nonblock(int sock) -- 2.24.0