updates.
authorPekka Riikonen <priikone@silcnet.org>
Thu, 7 Mar 2002 18:10:06 +0000 (18:10 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Thu, 7 Mar 2002 18:10:06 +0000 (18:10 +0000)
CHANGES
TODO
TODO-1.0 [new file with mode: 0644]
apps/silcd/packet_receive.c
apps/silcd/protocol.c
apps/silcd/server.c
lib/silcutil/silcschedule.c
lib/silcutil/silcschedule.h
lib/silcutil/silcschedule_i.h
lib/silcutil/unix/silcunixschedule.c

diff --git a/CHANGES b/CHANGES
index 708d41ad44e724ca1fa52ed0acf0b1aa643e4f67..7b9d3ec89dffe3653cef3c145bec39e21785d756 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,11 @@
+Thu Mar  7 19:21:22 EET 2002  Pekka Riikonen <priikone@silcnet.org>
+
+       * Changed silc_mutex_[un]lock calls in lib/silcutil/silcschedule.c
+         to SILC_SCHEDULE_[UN]LOCK macros.
+
+       * Added more error printing to logs in server code.  Affected
+         files silcd/server.c and silcd/protocol.c.
+
 Tue Mar  5 14:37:27 EET 2002  Pekka Riikonen <priikone@silcnet.org>
 
        * Changed all silc_[hash|hmac|cipher|pkcs]_default tables to
diff --git a/TODO b/TODO
index 4af357e61b520ee0124b99243cf3479763e489da..bea85c6865f60f7ecebff161ab6ee3b52e6d1dc3 100644 (file)
--- a/TODO
+++ b/TODO
@@ -216,141 +216,3 @@ describe new stuff to be added to protocol versions 1.x.
  10. Check command reply error status types in various commands,
      specifically NO_FOPRIV is missing from many commands.  To be 
      included in protocol version 1.1.
-
-
-TODO After 1.0
-==============
-
-A rough list of stuff that is going to be done to SILC after 1.0 or at
-least could be done.
-
- o Implement the defined SilcDH API.  The definition is in
-   lib/silccrypt/silcdh.h.
-
- o X.509 certificate support.  SILC protocol supports certificates and
-   it would be great to have support for them.  This is a big task as
-   support has to be made for ASN.1 as well.  I've looked into OpenSSL 
-   package as it has X.509 certificate support (and ASN.1 as well).  
-   The code does not look very good to my eye but it has some potentials.
-   This should be looked at more closely.
-
-   Naturally own SILC Certificate API has to be defined regardles what
-   the actual X.509 library is (OpenSSL X.509 or something else).  Other
-   choice is to write own X.509 library but I'm not going to do it - 
-   I can help to migrate the OpenSSL X.509 into SILC and I can help if 
-   someone would like to write the X.509 library - but I'm not going 
-   to start writing one myself.  Anyhow, the OpenSSL X.509 lib should
-   be checked.
-
-   Other package that should be checked is the NSS's X509 library,
-   which I like more over OpenSSL package.
-
- o SSH2 public keys support, allowing the use of SSH2 public keys in
-   SILC.
-
- o OpenPGP certificate support, allowing the use of PGP public keys
-   in SILC.
-
- o Compression routines are missing.  The protocol supports packet
-   compression thus it must be implemented.  SILC Zip API must be
-   defined.
-
- o Optimizations in Libraries
-
-       o There is currently three (3) allocations per packet in the
-         silc_packet_receive_process, which is used to process and
-         dispatch all packets in the packet queue to the parser callback
-         function.  First allocation is for parse_ctx, second for the
-         SilcPacketContext, and third for packet->buffer where the actual
-         data is saved.
-
-         The parse_ctx allocation can be removed by adding it as a
-         structure to the SilcPacketContext.  When the SilcPacketContext
-         is allocated there is space for the parse context already.
-
-         The silc_packet_context_alloc could have a free list of
-         packet contexts.  If free packet context is found from the list
-         it is returned instead of allocating a new one.  The library
-         could at first allocate them and save them to the free list
-         until enough contexts for smooth processing exists in the list.
-         This would remove a big allocation since the structure is
-         quite big, and even bigger if it would include the parse_ctx.
-
-         The packet->buffer can be optimized too if the SilcBuffer
-         interface would support free lists as well.  Maybe such could
-         be done in the same way as for SilcPacketContext.  The
-         silc_buffer_alloc would check free list before actually 
-         allocating new memory.  Since the packets in the SILC protocol
-         usually are about the same size (due to padding) it would be
-         easy to find suitable size buffer from the free list very
-         quickly.
-
-         These naturally cause the overal memory consumption to grow
-         but would take away many allocations that can be done several
-         times in a second.
-
-       o Move the actual file descriptor task callback (the callback that
-         handles the incoming data, outgoing data etc, that is implemnted
-         in server and client separately (silc_server_packet_process and
-         silc_client_packet_proces)) to the low level socket connection
-         handling routines, and create an interface where the application
-         can register a callbacks for incoming data, outoing data and EOF
-         receiving, which the library will call when necessary.  This way 
-         we can move the data handling in one place.
-
-       o Add silc_id_str2id to accept the destination buffer as argument
-         and thus not require any memory allocation.  Same will happen
-         with silc_id_payload_* functions.
-
-       o Remove the `truelen' field from SilcBuffer as it is entirely
-         redundant since we can get the true length of the buffer by
-         doing buffer->end - buffer->header.  Add SILC_BUFFER_TRUELEN
-         macro instead.  Consider also removing `len' field too since
-         it effectively is buffer->tail - buffer->data, and adding
-         SILC_BUFFER_LEN macro can do the same.  These would save
-         totally 8 bytes of memory per buffer.
-
-         Add also perhaps function silc_buffer_alloc_size that would
-         effectively do: 
-
-               return silc_buffer_pull_tail(silc_buffer_alloc(size),
-                                            size);
-
-         to not require the user to give the pull_tail anymore.
-
- o Optimizations in Server
-
-       o Remove the big switch statement from the function 
-         silc_server_packet_parse_type and replace it with predefined
-         table of function pointers where each of the slot in table
-         represents the packet type value.
-
-         Same could be done with notify packets which has big switch 
-         statement too.  Same kind of table of notify callbacks could be
-         done as well.
-
-       o The parser callback in the server will add a timeout task for
-         all packets.  It will require registering and allocating a
-         new task to the SilcSchedule.  Maybe, at least, for server
-         and router packets the parser would be called immediately
-         instead of adding it to the scheduler with 0 timeout.  It
-         should be analyzed too how slow the task registering process
-         actually is, and find out ways to optimize it.
-
-       o The SERVER_SIGNOFF notify handing is not optimal, because it'll
-         cause sending of multiple SIGNOFF notify's instead of the one
-         SERVER_SIGNOFF notify that the server received.  This should be
-         optimized so that the only SERVER_SIGNOFF is sent and not
-         SIGNOFF of notify at all (using SIGNOFF takes the idea about
-         SERVER_SIGNOFF away entirely).
-
- o Add SilcAsyncOperation to utility library.  Any function that takes
-   callback as an argument must return SilcAsyncOperation.
-
- o Add DSS support.
-
- o Cipher optimizations (asm, that this) at least for i386 would be nice.
-
- o Add builtin SOCKS and HTTP Proxy support, well the SOCKS at least.
-   SILC currently supports SOCKS4 and SOCKS5 but it needs to be compiled
-   in separately.
diff --git a/TODO-1.0 b/TODO-1.0
new file mode 100644 (file)
index 0000000..601712e
--- /dev/null
+++ b/TODO-1.0
@@ -0,0 +1,151 @@
+TODO After 1.0
+==============
+
+A rough list of stuff that is going to be done to SILC after 1.0 or at
+least could be done.
+
+ o Implement the defined SilcDH API.  The definition is in
+   lib/silccrypt/silcdh.h.
+
+ o X.509 certificate support.  SILC protocol supports certificates and
+   it would be great to have support for them.  This is a big task as
+   support has to be made for ASN.1 as well.  I've looked into OpenSSL 
+   package as it has X.509 certificate support (and ASN.1 as well).  
+   The code does not look very good to my eye but it has some potentials.
+   This should be looked at more closely.
+
+   Naturally own SILC Certificate API has to be defined regardles what
+   the actual X.509 library is (OpenSSL X.509 or something else).  Other
+   choice is to write own X.509 library but I'm not going to do it - 
+   I can help to migrate the OpenSSL X.509 into SILC and I can help if 
+   someone would like to write the X.509 library - but I'm not going 
+   to start writing one myself.  Anyhow, the OpenSSL X.509 lib should
+   be checked.
+
+   Other package that should be checked is the NSS's X509 library,
+   which I like more over OpenSSL package.
+
+ o SSH2 public keys support, allowing the use of SSH2 public keys in
+   SILC.
+
+ o OpenPGP certificate support, allowing the use of PGP public keys
+   in SILC.
+
+ o Compression routines are missing.  The protocol supports packet
+   compression thus it must be implemented.  SILC Zip API must be
+   defined.
+
+ o Optimizations in Libraries
+
+       o There is currently three (3) allocations per packet in the
+         silc_packet_receive_process, which is used to process and
+         dispatch all packets in the packet queue to the parser callback
+         function.  First allocation is for parse_ctx, second for the
+         SilcPacketContext, and third for packet->buffer where the actual
+         data is saved.
+
+         The parse_ctx allocation can be removed by adding it as a
+         structure to the SilcPacketContext.  When the SilcPacketContext
+         is allocated there is space for the parse context already.
+
+         The silc_packet_context_alloc could have a free list of
+         packet contexts.  If free packet context is found from the list
+         it is returned instead of allocating a new one.  The library
+         could at first allocate them and save them to the free list
+         until enough contexts for smooth processing exists in the list.
+         This would remove a big allocation since the structure is
+         quite big, and even bigger if it would include the parse_ctx.
+
+         The packet->buffer can be optimized too if the SilcBuffer
+         interface would support free lists as well.  Maybe such could
+         be done in the same way as for SilcPacketContext.  The
+         silc_buffer_alloc would check free list before actually 
+         allocating new memory.  Since the packets in the SILC protocol
+         usually are about the same size (due to padding) it would be
+         easy to find suitable size buffer from the free list very
+         quickly.
+
+         These naturally cause the overal memory consumption to grow
+         but would take away many allocations that can be done several
+         times in a second.
+
+       o Move the actual file descriptor task callback (the callback that
+         handles the incoming data, outgoing data etc, that is implemnted
+         in server and client separately (silc_server_packet_process and
+         silc_client_packet_proces)) to the low level socket connection
+         handling routines, and create an interface where the application
+         can register a callbacks for incoming data, outoing data and EOF
+         receiving, which the library will call when necessary.  This way 
+         we can move the data handling in one place.
+
+       o Add silc_id_str2id to accept the destination buffer as argument
+         and thus not require any memory allocation.  Same will happen
+         with silc_id_payload_* functions.
+
+       o Remove the `truelen' field from SilcBuffer as it is entirely
+         redundant since we can get the true length of the buffer by
+         doing buffer->end - buffer->header.  Add SILC_BUFFER_TRUELEN
+         macro instead.  Consider also removing `len' field too since
+         it effectively is buffer->tail - buffer->data, and adding
+         SILC_BUFFER_LEN macro can do the same.  These would save
+         totally 8 bytes of memory per buffer.
+
+         Add also perhaps function silc_buffer_alloc_size that would
+         effectively do: 
+
+               return silc_buffer_pull_tail(silc_buffer_alloc(size),
+                                            size);
+
+         to not require the user to give the pull_tail anymore.
+
+       o Scheduler can be optimized for FD tasks by changing the fd_queue
+         to SilcHashTable instead of using linked list.  We need to do
+         one-to-one mapping of FD to task and hash table is more efficient
+         for this usage.
+
+         Also redefine the silc_select to perhaps return a separate
+         structure of the events that actually occurred, instead of
+         returning the events in the fd_list which is then traversed
+         in the generic code to find the changed events.  This can be
+         made faster by having own struct which includes only the
+         changed events, thus the tarversing is faster since the whole
+         fd_list is not traversed anymore (it is still traversed in the
+         silc_select but at least it removes one extra tarversing later
+         for the same list).
+
+ o Optimizations in Server
+
+       o Remove the big switch statement from the function 
+         silc_server_packet_parse_type and replace it with predefined
+         table of function pointers where each of the slot in table
+         represents the packet type value.
+
+         Same could be done with notify packets which has big switch 
+         statement too.  Same kind of table of notify callbacks could be
+         done as well.
+
+       o The parser callback in the server will add a timeout task for
+         all packets.  It will require registering and allocating a
+         new task to the SilcSchedule.  Maybe, at least, for server
+         and router packets the parser would be called immediately
+         instead of adding it to the scheduler with 0 timeout.  It
+         should be analyzed too how slow the task registering process
+         actually is, and find out ways to optimize it.
+
+       o The SERVER_SIGNOFF notify handing is not optimal, because it'll
+         cause sending of multiple SIGNOFF notify's instead of the one
+         SERVER_SIGNOFF notify that the server received.  This should be
+         optimized so that the only SERVER_SIGNOFF is sent and not
+         SIGNOFF of notify at all (using SIGNOFF takes the idea about
+         SERVER_SIGNOFF away entirely).
+
+ o Add SilcAsyncOperation to utility library.  Any function that takes
+   callback as an argument must return SilcAsyncOperation.
+
+ o Add DSS support.
+
+ o Cipher optimizations (asm, that this) at least for i386 would be nice.
+
+ o Add builtin SOCKS and HTTP Proxy support, well the SOCKS at least.
+   SILC currently supports SOCKS4 and SOCKS5 but it needs to be compiled
+   in separately.
index 07d1e1c86fad97b154863f60dee0baf6003a9169..1c817358a4d4f02b710d7de50876c88976258fcc 100644 (file)
@@ -1540,7 +1540,7 @@ SilcClientEntry silc_server_new_client(SilcServer server,
 
   /* Remove the old cache entry. */
   if (!silc_idcache_del_by_context(server->local_list->clients, client)) {
-    SILC_LOG_ERROR(("Lost client's cache entry - bad thing"));
+    SILC_LOG_ERROR(("Lost client's cache entry - report a bug"));
     silc_server_disconnect_remote(server, sock, "Server closed connection: "
                                   "Unknown client");
     return NULL;
@@ -1555,6 +1555,8 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   if (ret == -1) {
     silc_free(username);
     silc_free(realname);
+    SILC_LOG_ERROR(("Client %s (%s) sent incomplete information, closing "
+                   "connection", sock->hostname, sock->ip));
     silc_server_disconnect_remote(server, sock, "Server closed connection: "
                                   "Incomplete client information");
     return NULL;
@@ -1563,6 +1565,8 @@ SilcClientEntry silc_server_new_client(SilcServer server,
   if (!username) {
     silc_free(username);
     silc_free(realname);
+    SILC_LOG_ERROR(("Client %s (%s) did not send its username, closing "
+                   "connection", sock->hostname, sock->ip));
     silc_server_disconnect_remote(server, sock, "Server closed connection: "
                                   "Incomplete client information");
     return NULL;
@@ -1596,6 +1600,8 @@ SilcClientEntry silc_server_new_client(SilcServer server,
       silc_free(username);
       silc_free(hostname);
       silc_free(realname);
+      SILC_LOG_ERROR(("Client %s (%s) sent incomplete information, closing "
+                     "connection", sock->hostname, sock->ip));
       silc_server_disconnect_remote(server, sock, 
                                    "Server closed connection: "
                                    "Incomplete client information");
@@ -1614,6 +1620,8 @@ SilcClientEntry silc_server_new_client(SilcServer server,
       silc_free(hostname);
       silc_free(phostname);
       silc_free(realname);
+      SILC_LOG_ERROR(("Client %s (%s) sent incomplete information, closing "
+                     "connection", sock->hostname, sock->ip));
       silc_server_disconnect_remote(server, sock, 
                                    "Server closed connection: "
                                    "Incomplete client information");
index d3c0fce5f066598f41e294456daedb7f722d092e..a33184d7b1e9d2087afcc8c3e04b80f3b25b792b 100644 (file)
@@ -227,10 +227,12 @@ int silc_server_protocol_ke_set_keys(SilcServer server,
   /* Allocate cipher to be used in the communication */
   if (!silc_cipher_alloc(cipher->cipher->name, &idata->send_key)) {
     silc_free(conn_data);
+    SILC_LOG_ERROR(("Cannot allocate algorithm: %s", cipher->cipher->name));
     return FALSE;
   }
   if (!silc_cipher_alloc(cipher->cipher->name, &idata->receive_key)) {
     silc_free(conn_data);
+    SILC_LOG_ERROR(("Cannot allocate algorithm: %s", cipher->cipher->name));
     return FALSE;
   }
   
@@ -239,6 +241,8 @@ int silc_server_protocol_ke_set_keys(SilcServer server,
     silc_cipher_free(idata->send_key);
     silc_cipher_free(idata->receive_key);
     silc_free(conn_data);
+    SILC_LOG_ERROR(("Cannot allocate algorithm: %s", 
+                   silc_hmac_get_name(hmac)));
     return FALSE;
   }
 
@@ -248,6 +252,8 @@ int silc_server_protocol_ke_set_keys(SilcServer server,
     silc_cipher_free(idata->receive_key);
     silc_hmac_free(idata->hmac_send);
     silc_free(conn_data);
+    SILC_LOG_ERROR(("Cannot allocate algorithm: %s", 
+                   silc_hmac_get_name(hmac)));
     return FALSE;
   }
 
@@ -291,6 +297,7 @@ int silc_server_protocol_ke_set_keys(SilcServer server,
     silc_hmac_free(idata->hmac_send);
     silc_hmac_free(idata->hmac_receive);
     silc_free(conn_data);
+    SILC_LOG_ERROR(("Cannot allocate algorithm: %s", hash->hash->name));
     return FALSE;
   }
 
@@ -373,6 +380,10 @@ SilcSKEStatus silc_ske_check_version(SilcSKE ske, unsigned char *version,
   if (maj == 0 && min < 5)
     status = SILC_SKE_STATUS_BAD_VERSION;
 
+  if (status == SILC_SKE_STATUS_BAD_VERSION)
+    SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version", 
+                   ske->sock->hostname, ske->sock->ip, version));
+
   return status;
 }
 
@@ -394,8 +405,8 @@ static void silc_server_protocol_ke_continue(SilcSKE ske, void *context)
   SILC_LOG_DEBUG(("Start"));
 
   if (ske->status != SILC_SKE_STATUS_OK) {
-    SILC_LOG_WARNING(("Error (%s) during Key Exchange protocol",
-                     silc_ske_map_status(ske->status)));
+    SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
+                   silc_ske_map_status(ske->status)));
     SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
                    silc_ske_map_status(ske->status)));
     
@@ -482,8 +493,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange)
        return;
 
       if (status != SILC_SKE_STATUS_OK) {
-       SILC_LOG_WARNING(("Error (%s) during Key Exchange protocol",
-                         silc_ske_map_status(status)));
+       SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
+                       silc_ske_map_status(status)));
        SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
                        silc_ske_map_status(status)));
 
@@ -519,8 +530,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange)
        return;
 
       if (status != SILC_SKE_STATUS_OK) {
-       SILC_LOG_WARNING(("Error (%s) during Key Exchange protocol",
-                         silc_ske_map_status(status)));
+       SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
+                       silc_ske_map_status(status)));
        SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
                        silc_ske_map_status(status)));
 
@@ -562,8 +573,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange)
        return;
 
       if (status != SILC_SKE_STATUS_OK) {
-       SILC_LOG_WARNING(("Error (%s) during Key Exchange protocol",
-                         silc_ske_map_status(status)));
+       SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
+                       silc_ske_map_status(status)));
        SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
                        silc_ske_map_status(status)));
 
@@ -600,8 +611,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange)
        return;
 
       if (status != SILC_SKE_STATUS_OK) {
-       SILC_LOG_WARNING(("Error (%s) during Key Exchange protocol",
-                         silc_ske_map_status(status)));
+       SILC_LOG_ERROR(("Error (%s) during Key Exchange protocol",
+                       silc_ske_map_status(status)));
        SILC_LOG_DEBUG(("Error (%s) during Key Exchange protocol",
                        silc_ske_map_status(status)));
 
@@ -626,6 +637,9 @@ SILC_TASK_CALLBACK(silc_server_protocol_key_exchange)
       status = silc_ske_process_key_material(ctx->ske, 16, key_len, hash_len,
                                             keymat);
       if (status != SILC_SKE_STATUS_OK) {
+       SILC_LOG_ERROR(("Error during Key Exchange protocol: "
+                       "could not process key material"));
+
        protocol->state = SILC_PROTOCOL_STATE_ERROR;
        silc_protocol_execute(protocol, server->schedule, 0, 300000);
        silc_ske_free_key_material(keymat);
@@ -896,14 +910,14 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
                                   SILC_STR_UI_SHORT(&conn_type),
                                   SILC_STR_END);
        if (ret == -1) {
-         SILC_LOG_DEBUG(("Bad payload in authentication packet"));
+         SILC_LOG_ERROR(("Bad payload in authentication packet"));
          protocol->state = SILC_PROTOCOL_STATE_ERROR;
          silc_protocol_execute(protocol, server->schedule, 0, 300000);
          return;
        }
        
        if (payload_len != ctx->packet->buffer->len) {
-         SILC_LOG_DEBUG(("Bad payload in authentication packet"));
+         SILC_LOG_ERROR(("Bad payload length in authentication packet"));
          protocol->state = SILC_PROTOCOL_STATE_ERROR;
          silc_protocol_execute(protocol, server->schedule, 0, 300000);
          return;
@@ -913,7 +927,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
        
        if (conn_type < SILC_SOCKET_TYPE_CLIENT || 
            conn_type > SILC_SOCKET_TYPE_ROUTER) {
-         SILC_LOG_ERROR(("Bad connection type %d", conn_type));
+         SILC_LOG_ERROR(("Bad connection type (%d) in authentication packet",
+                         conn_type));
          protocol->state = SILC_PROTOCOL_STATE_ERROR;
          silc_protocol_execute(protocol, server->schedule, 0, 300000);
          return;
@@ -927,7 +942,7 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
                                                                payload_len),
                                     SILC_STR_END);
          if (ret == -1) {
-           SILC_LOG_DEBUG(("Bad payload in authentication packet"));
+           SILC_LOG_DEBUG(("Bad payload in authentication payload"));
            protocol->state = SILC_PROTOCOL_STATE_ERROR;
            silc_protocol_execute(protocol, server->schedule, 0, 300000);
            return;
@@ -1140,9 +1155,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
        */
       unsigned char error[4];
 
-      SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
-
       /* Authentication failed */
+      SILC_PUT32_MSB(SILC_AUTH_FAILED, error);
       silc_server_packet_send(server, ctx->sock, SILC_PACKET_FAILURE,
                              0, error, 4, TRUE);
 
@@ -1170,6 +1184,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth)
      * We have received failure from remote
      */
 
+    SILC_LOG_ERROR(("Received Authentication Failure"));
+
     /* Unregister the timeout task since the protocol has ended. 
        This was the timeout task to be executed if the protocol is
        not completed fast enough. */
@@ -1364,7 +1380,9 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
           */
 
          if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_1) {
-           /* Error in protocol */
+           SILC_LOG_ERROR(("Error during Re-key (PFS): re-key state is "
+                           "incorrect (received %d, expected %d packet)",
+                           ctx->packet->type, SILC_PACKET_KEY_EXCHANGE_1));
            protocol->state = SILC_PROTOCOL_STATE_ERROR;
            silc_protocol_execute(protocol, server->schedule, 0, 300000);
            return;
@@ -1382,9 +1400,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
       
          status = silc_ske_responder_phase_2(ctx->ske, ctx->packet->buffer);
          if (status != SILC_SKE_STATUS_OK) {
-           SILC_LOG_WARNING(("Error (%s) during Re-key (PFS)",
-                             silc_ske_map_status(status)));
-           
+           SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
+                           silc_ske_map_status(status)));
            protocol->state = SILC_PROTOCOL_STATE_ERROR;
            silc_protocol_execute(protocol, server->schedule, 0, 300000);
            return;
@@ -1437,9 +1454,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
       
          status = silc_ske_initiator_phase_2(ctx->ske, NULL, NULL, 0);
          if (status != SILC_SKE_STATUS_OK) {
-           SILC_LOG_WARNING(("Error (%s) during Re-key (PFS)",
-                             silc_ske_map_status(status)));
-           
+           SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
+                           silc_ske_map_status(status)));
            protocol->state = SILC_PROTOCOL_STATE_ERROR;
            silc_protocol_execute(protocol, server->schedule, 0, 300000);
            return;
@@ -1482,9 +1498,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
        status = silc_ske_responder_finish(ctx->ske, NULL, NULL, 
                                           SILC_SKE_PK_TYPE_SILC);
        if (status != SILC_SKE_STATUS_OK) {
-         SILC_LOG_WARNING(("Error (%s) during Re-key (PFS)",
-                           silc_ske_map_status(status)));
-         
+         SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
+                         silc_ske_map_status(status)));
          protocol->state = SILC_PROTOCOL_STATE_ERROR;
          silc_protocol_execute(protocol, server->schedule, 0, 300000);
          return;
@@ -1497,7 +1512,9 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
         * The packet type must be KE packet
         */
        if (ctx->packet->type != SILC_PACKET_KEY_EXCHANGE_2) {
-         /* Error in protocol */
+         SILC_LOG_ERROR(("Error during Re-key (PFS): re-key state is "
+                         "incorrect (received %d, expected %d packet)",
+                         ctx->packet->type, SILC_PACKET_KEY_EXCHANGE_2));
          protocol->state = SILC_PROTOCOL_STATE_ERROR;
          silc_protocol_execute(protocol, server->schedule, 0, 300000);
          return;
@@ -1505,9 +1522,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
        
        status = silc_ske_initiator_finish(ctx->ske, ctx->packet->buffer);
        if (status != SILC_SKE_STATUS_OK) {
-         SILC_LOG_WARNING(("Error (%s) during Re-key (PFS)",
-                           silc_ske_map_status(status)));
-         
+         SILC_LOG_ERROR(("Error (%s) during Re-key (PFS)",
+                         silc_ske_map_status(status)));
          protocol->state = SILC_PROTOCOL_STATE_ERROR;
          silc_protocol_execute(protocol, server->schedule, 0, 300000);
          return;
@@ -1535,7 +1551,9 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
      */
 
     if (ctx->packet->type != SILC_PACKET_REKEY_DONE) {
-      /* Error in protocol */
+      SILC_LOG_ERROR(("Error during Re-key (PFS): re-key state is "
+                     "incorrect (received %d, expected %d packet)",
+                     ctx->packet->type, SILC_PACKET_REKEY_DONE));
       protocol->state = SILC_PROTOCOL_STATE_ERROR;
       silc_protocol_execute(protocol, server->schedule, 0, 300000);
       return;
@@ -1562,10 +1580,9 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
      * Error occured
      */
 
-    if (ctx->pfs == TRUE) {
+    if (ctx->pfs == TRUE)
       /* Send abort notification */
       silc_ske_abort(ctx->ske, ctx->ske->status);
-    }
 
     /* Assure that after calling final callback there cannot be pending
        executions for this protocol anymore. This just unregisters any 
@@ -1584,6 +1601,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_rekey)
      * We have received failure from remote
      */
 
+    SILC_LOG_ERROR(("Error during Re-Key: received Failure"));
+
     /* Assure that after calling final callback there cannot be pending
        executions for this protocol anymore. This just unregisters any 
        timeout callbacks for this protocol. */
index d16d3f00d350f8ca05bdabff9e98bdba3b75c286..85cd3c0066ab64953937b8d05ecc527b69f43518 100644 (file)
@@ -1036,7 +1036,7 @@ silc_server_accept_new_connection_lookup(SilcSocketConnection sock,
      later when outgoing data is available. */
   SILC_REGISTER_CONNECTION_FOR_IO(sock->sock);
 
-  SILC_LOG_INFO(("Incoming connection s (%s)", sock->hostname,
+  SILC_LOG_INFO(("Incoming connection %s (%s)", sock->hostname,
                 sock->ip));
 
   port = server->sockets[server->sock]->port; /* Listenning port */
@@ -1347,7 +1347,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
       }
 
       SILC_LOG_DEBUG(("Remote host is client"));
-      SILC_LOG_INFO(("Connection s (%s) is client", sock->hostname,
+      SILC_LOG_INFO(("Connection %s (%s) is client", sock->hostname,
                     sock->ip));
 
       /* Add the client to the client ID cache. The nickname and Client ID
index 884091838213d1b0f92dbf7600b0fcb66e33780a..0305893e27679a9a706d09820d9c616cdeed8b14 100644 (file)
@@ -28,7 +28,8 @@ typedef struct SilcTaskQueueStruct *SilcTaskQueue;
 /* System specific routines. Implemented under unix/ and win32/. */
 
 /* System specific select(). Returns same values as normal select(). */
-int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeout);
+int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, 
+               struct timeval *timeout);
 
 /* Initializes the wakeup of the scheduler. In multi-threaded environment
    the scheduler needs to be wakenup when tasks are added or removed from
@@ -69,6 +70,10 @@ static void silc_task_del_by_fd(SilcTaskQueue queue, SilcUInt32 fd);
    type == SILC_TASK_TIMEOUT ? schedule->timeout_queue :               \
    schedule->generic_queue)
 
+/* Locks */
+#define SILC_SCHEDULE_LOCK(schedule) silc_mutex_lock(schedule->lock)
+#define SILC_SCHEDULE_UNLOCK(schedule) silc_mutex_unlock(schedule->lock)
+
 /* SILC Task object. Represents one task in the scheduler. */
 struct SilcTaskStruct {
   SilcUInt32 fd;
@@ -254,13 +259,13 @@ bool silc_schedule_uninit(SilcSchedule schedule)
 
 bool silc_schedule_reinit(SilcSchedule schedule, int max_tasks)
 {
-  silc_mutex_lock(schedule->lock);
+  SILC_SCHEDULE_LOCK(schedule);
   if (schedule->max_fd <= max_tasks)
     return FALSE;
   schedule->fd_list = silc_realloc(schedule->fd_list, 
                                   (sizeof(*schedule->fd_list) * max_tasks));
   schedule->max_fd = max_tasks;
-  silc_mutex_unlock(schedule->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
   return TRUE;
 }
 
@@ -306,18 +311,18 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
       /* Is the task ready for reading */
       if (task->valid && schedule->fd_list[i].revents & SILC_TASK_READ) {
        silc_mutex_unlock(schedule->fd_queue->lock);
-       silc_mutex_unlock(schedule->lock);
+       SILC_SCHEDULE_UNLOCK(schedule);
        task->callback(schedule, SILC_TASK_READ, task->fd, task->context);
-       silc_mutex_lock(schedule->lock);
+       SILC_SCHEDULE_LOCK(schedule);
        silc_mutex_lock(schedule->fd_queue->lock);
       }
 
       /* Is the task ready for writing */
       if (task->valid && schedule->fd_list[i].revents & SILC_TASK_WRITE) {
        silc_mutex_unlock(schedule->fd_queue->lock);
-       silc_mutex_unlock(schedule->lock);
+       SILC_SCHEDULE_UNLOCK(schedule);
        task->callback(schedule, SILC_TASK_WRITE, task->fd, task->context);
-       silc_mutex_lock(schedule->lock);
+       SILC_SCHEDULE_LOCK(schedule);
        silc_mutex_lock(schedule->fd_queue->lock);
       }
 
@@ -345,18 +350,18 @@ static void silc_schedule_dispatch_nontimeout(SilcSchedule schedule)
        /* Is the task ready for reading */                             
        if (task->valid && schedule->fd_list[i].revents & SILC_TASK_READ) {
          silc_mutex_unlock(schedule->generic_queue->lock);
-         silc_mutex_unlock(schedule->lock);
+         SILC_SCHEDULE_UNLOCK(schedule);
          task->callback(schedule, SILC_TASK_READ, fd, task->context);
-         silc_mutex_lock(schedule->lock);
+         SILC_SCHEDULE_LOCK(schedule);
          silc_mutex_lock(schedule->generic_queue->lock);
        }
 
        /* Is the task ready for writing */                             
        if (task->valid && schedule->fd_list[i].revents & SILC_TASK_WRITE) {
          silc_mutex_unlock(schedule->generic_queue->lock);
-         silc_mutex_unlock(schedule->lock);
+         SILC_SCHEDULE_UNLOCK(schedule);
          task->callback(schedule, SILC_TASK_WRITE, fd, task->context);
-         silc_mutex_lock(schedule->lock);
+         SILC_SCHEDULE_LOCK(schedule);
          silc_mutex_lock(schedule->generic_queue->lock);
        }
 
@@ -414,9 +419,9 @@ static void silc_schedule_dispatch_timeout(SilcSchedule schedule)
       if (silc_schedule_task_timeout_compare(&task->timeout, &curtime)) {
         if (task->valid) {
          silc_mutex_unlock(queue->lock);
-         silc_mutex_unlock(schedule->lock);
+         SILC_SCHEDULE_UNLOCK(schedule);
          task->callback(schedule, SILC_TASK_EXPIRE, task->fd, task->context);
-         silc_mutex_lock(schedule->lock);
+         SILC_SCHEDULE_LOCK(schedule);
          silc_mutex_lock(queue->lock);
        }
 
@@ -518,7 +523,7 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
   SILC_LOG_DEBUG(("In scheduler loop"));
 
   if (!schedule->is_locked)
-    silc_mutex_lock(schedule->lock);
+    SILC_SCHEDULE_LOCK(schedule);
 
   /* If the task queues aren't initialized or we aren't valid anymore
      we will return */
@@ -526,7 +531,7 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
        && !schedule->generic_queue) || schedule->valid == FALSE) {
     SILC_LOG_DEBUG(("Scheduler not valid anymore, exiting"));
     if (!schedule->is_locked)
-      silc_mutex_unlock(schedule->lock);
+      SILC_SCHEDULE_UNLOCK(schedule);
     return FALSE;
   }
 
@@ -542,7 +547,7 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
     schedule->timeout = &timeout;
   }
 
-  silc_mutex_unlock(schedule->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
 
   /* This is the main select(). The program blocks here until some
      of the selected file descriptors change status or the selected
@@ -551,7 +556,7 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
   ret = silc_select(schedule->fd_list, schedule->last_fd + 1, 
                    schedule->timeout);
 
-  silc_mutex_lock(schedule->lock);
+  SILC_SCHEDULE_LOCK(schedule);
 
   switch (ret) {
   case -1:
@@ -574,7 +579,7 @@ bool silc_schedule_one(SilcSchedule schedule, int timeout_usecs)
   }
 
   if (!schedule->is_locked)
-    silc_mutex_unlock(schedule->lock);
+    SILC_SCHEDULE_UNLOCK(schedule);
 
   return TRUE;
 }
@@ -592,14 +597,14 @@ void silc_schedule(SilcSchedule schedule)
     return;
   }
 
-  silc_mutex_lock(schedule->lock);
+  SILC_SCHEDULE_LOCK(schedule);
   schedule->is_locked = TRUE;
 
   /* Start the scheduler loop */
   while (silc_schedule_one(schedule, -1)) 
     ;
 
-  silc_mutex_unlock(schedule->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
 }
 
 /* Wakes up the scheduler. This is used only in multi-threaded
@@ -613,9 +618,9 @@ void silc_schedule_wakeup(SilcSchedule schedule)
 {
 #ifdef SILC_THREADS
   SILC_LOG_DEBUG(("Wakeup scheduler"));
-  silc_mutex_lock(schedule->lock);
+  SILC_SCHEDULE_LOCK(schedule);
   silc_schedule_wakeup_internal(schedule->wakeup);
-  silc_mutex_unlock(schedule->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
 #endif
 }
 
@@ -798,7 +803,7 @@ void silc_schedule_set_listen_fd(SilcSchedule schedule,
   int i;
   bool found = FALSE;
 
-  silc_mutex_lock(schedule->lock);
+  SILC_SCHEDULE_LOCK(schedule);
 
   for (i = 0; i < schedule->max_fd; i++)
     if (schedule->fd_list[i].fd == fd) {
@@ -820,7 +825,7 @@ void silc_schedule_set_listen_fd(SilcSchedule schedule,
        break;
       }
 
-  silc_mutex_unlock(schedule->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
 }
 
 /* Removes a file descriptor from listen list. */
@@ -829,7 +834,7 @@ void silc_schedule_unset_listen_fd(SilcSchedule schedule, SilcUInt32 fd)
 {
   int i;
 
-  silc_mutex_lock(schedule->lock);
+  SILC_SCHEDULE_LOCK(schedule);
 
   SILC_LOG_DEBUG(("Unset listen fd %d", fd));
 
@@ -842,7 +847,7 @@ void silc_schedule_unset_listen_fd(SilcSchedule schedule, SilcUInt32 fd)
       break;
     }
 
-  silc_mutex_unlock(schedule->lock);
+  SILC_SCHEDULE_UNLOCK(schedule);
 }
 
 /* Allocates a newtask task queue into the scheduler */
index 95e279a333eaec58bae3c80d4e3f83e5dd970f02..e7479f4f4b0be61f9e29fb833d6c48504876e7b1 100644 (file)
@@ -120,7 +120,7 @@ typedef enum {
   /* File descriptor task that performs some event over file descriptors.
      These tasks are for example network connections. */
   SILC_TASK_FD,
-  
+
   /* Timeout tasks are tasks that are executed after the specified 
      time has elapsed. After the task is executed the task is removed
      automatically from the scheduler. It is safe to re-register the
index a1db680eb5c7a01bdceae04dc5d2d5f3f25eb1e5..7e2b6026cf14bf95a228cdd2a127b64b4ea78b86 100644 (file)
@@ -26,7 +26,7 @@
 /* Schedule FD structure. Includes the file descriptors that the scheduler
    will listen. This is given as argument to the silc_select function. */
 typedef struct {
-  SilcUInt32 fd;                       /* The file descriptor (or handle on WIN32) */
+  SilcUInt32 fd;                       /* The file descriptor (or handle on WIN32) */
   SilcUInt16 events;           /* Mask of task events, if events is 0 then
                                   the fd must be omitted. */
   SilcUInt16 revents;          /* Returned events mask */
index 2449445b1ceffb949ecdfdf9ac1f7a1b175c2c83..98a1d8a4fc32527d728d1ce98e15142f020f6013 100644 (file)
@@ -24,7 +24,8 @@
 
 /* Calls normal select() system call. */
 
-int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, struct timeval *timeout)
+int silc_select(SilcScheduleFd fds, SilcUInt32 fds_count, 
+               struct timeval *timeout)
 {
   fd_set in, out;
   int ret, i, max_fd = 0;