5 Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
7 Copyright (C) 1997 - 2001 Pekka Riikonen
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 2 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
21 * Server packet routines to handle received packets.
25 #include "serverincludes.h"
26 #include "server_internal.h"
28 extern char *server_version;
30 /* Received notify packet. Server can receive notify packets from router.
31 Server then relays the notify messages to clients if needed. */
33 void silc_server_notify(SilcServer server,
34 SilcSocketConnection sock,
35 SilcPacketContext *packet)
37 SilcNotifyPayload payload;
39 SilcArgumentPayload args;
40 SilcChannelID *channel_id = NULL, *channel_id2;
41 SilcClientID *client_id, *client_id2;
42 SilcServerID *server_id;
43 SilcChannelEntry channel;
44 SilcClientEntry client;
45 SilcServerEntry server_entry;
46 SilcChannelClientEntry chl;
47 SilcIDCacheEntry cache;
48 SilcHashTableList htl;
53 SILC_LOG_DEBUG(("Start"));
55 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
56 packet->src_id_type != SILC_ID_SERVER)
62 /* If the packet is destined directly to a client then relay the packet
63 before processing it. */
64 if (packet->dst_id_type == SILC_ID_CLIENT) {
66 SilcSocketConnection dst_sock;
68 /* Get the route to the client */
69 dst_sock = silc_server_get_client_route(server, packet->dst_id,
70 packet->dst_id_len, NULL, &idata);
72 /* Relay the packet */
73 silc_server_relay_packet(server, dst_sock, idata->send_key,
74 idata->hmac_receive, idata->psn_send++,
78 /* Parse the Notify Payload */
79 payload = silc_notify_payload_parse(packet->buffer);
83 /* If we are router and this packet is not already broadcast packet
84 we will broadcast it. The sending socket really cannot be router or
85 the router is buggy. If this packet is coming from router then it must
86 have the broadcast flag set already and we won't do anything. */
87 if (!server->standalone && server->server_type == SILC_ROUTER &&
88 sock->type == SILC_SOCKET_TYPE_SERVER &&
89 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
90 SILC_LOG_DEBUG(("Broadcasting received Notify packet"));
91 if (packet->dst_id_type == SILC_ID_CHANNEL) {
92 /* Packet is destined to channel */
93 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
98 silc_server_packet_send_dest(server, server->router->connection,
100 packet->flags | SILC_PACKET_FLAG_BROADCAST,
101 channel_id, SILC_ID_CHANNEL,
102 packet->buffer->data, packet->buffer->len,
104 silc_server_backup_send_dest(server, (SilcServerEntry)sock->user_data,
105 packet->type, packet->flags,
106 channel_id, SILC_ID_CHANNEL,
107 packet->buffer->data, packet->buffer->len,
110 /* Packet is destined to client or server */
111 silc_server_packet_send(server, server->router->connection,
113 packet->flags | SILC_PACKET_FLAG_BROADCAST,
114 packet->buffer->data, packet->buffer->len,
116 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
117 packet->type, packet->flags,
118 packet->buffer->data, packet->buffer->len,
123 type = silc_notify_get_type(payload);
124 args = silc_notify_get_args(payload);
129 case SILC_NOTIFY_TYPE_JOIN:
131 * Distribute the notify to local clients on the channel
133 SILC_LOG_DEBUG(("JOIN notify"));
136 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
139 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
143 /* Get channel entry */
144 channel = silc_idlist_find_channel_by_id(server->global_list,
147 channel = silc_idlist_find_channel_by_id(server->local_list,
150 silc_free(channel_id);
154 silc_free(channel_id);
157 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
160 client_id = silc_id_payload_parse_id(tmp, tmp_len);
164 /* If the the client is not in local list we check global list (ie. the
165 channel will be global channel) and if it does not exist then create
166 entry for the client. */
167 client = silc_idlist_find_client_by_id(server->global_list,
168 client_id, server->server_type,
171 client = silc_idlist_find_client_by_id(server->local_list,
172 client_id, server->server_type,
175 /* If router did not find the client the it is bogus */
176 if (server->server_type != SILC_SERVER)
180 silc_idlist_add_client(server->global_list, NULL, NULL, NULL,
181 silc_id_dup(client_id, SILC_ID_CLIENT),
182 sock->user_data, NULL);
184 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
185 silc_free(client_id);
189 client->data.status |= SILC_IDLIST_STATUS_REGISTERED;
193 /* Do not process the notify if the client is not registered */
194 if (!(client->data.status & SILC_IDLIST_STATUS_REGISTERED))
197 /* Do not add client to channel if it is there already */
198 if (silc_server_client_on_channel(client, channel)) {
199 SILC_LOG_DEBUG(("Client already on channel"));
203 /* Send to channel */
204 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
205 FALSE, packet->buffer->data,
206 packet->buffer->len, FALSE);
208 if (server->server_type != SILC_ROUTER &&
209 sock->type == SILC_SOCKET_TYPE_ROUTER)
210 /* The channel is global now */
211 channel->global_users = TRUE;
213 /* JOIN the global client to the channel (local clients (if router
214 created the channel) is joined in the pending JOIN command). */
215 chl = silc_calloc(1, sizeof(*chl));
216 chl->client = client;
217 chl->channel = channel;
219 /* If this is the first one on the channel then it is the founder of
221 if (!silc_hash_table_count(channel->user_list))
222 chl->mode = (SILC_CHANNEL_UMODE_CHANOP | SILC_CHANNEL_UMODE_CHANFO);
224 silc_hash_table_add(channel->user_list, client, chl);
225 silc_hash_table_add(client->channels, channel, chl);
226 silc_free(client_id);
230 case SILC_NOTIFY_TYPE_LEAVE:
232 * Distribute the notify to local clients on the channel
234 SILC_LOG_DEBUG(("LEAVE notify"));
237 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
238 packet->dst_id_type);
243 /* Get channel entry */
244 channel = silc_idlist_find_channel_by_id(server->global_list,
247 channel = silc_idlist_find_channel_by_id(server->local_list,
250 silc_free(channel_id);
256 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
258 silc_free(channel_id);
261 client_id = silc_id_payload_parse_id(tmp, tmp_len);
263 silc_free(channel_id);
267 /* Get client entry */
268 client = silc_idlist_find_client_by_id(server->global_list,
269 client_id, TRUE, NULL);
271 client = silc_idlist_find_client_by_id(server->local_list,
272 client_id, TRUE, NULL);
274 silc_free(client_id);
275 silc_free(channel_id);
279 silc_free(client_id);
281 /* Check if on channel */
282 if (!silc_server_client_on_channel(client, channel))
285 /* Send the leave notify to channel */
286 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
287 FALSE, packet->buffer->data,
288 packet->buffer->len, FALSE);
290 /* Remove the user from channel */
291 silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
294 case SILC_NOTIFY_TYPE_SIGNOFF:
296 * Distribute the notify to local clients on the channel
298 SILC_LOG_DEBUG(("SIGNOFF notify"));
301 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
304 client_id = silc_id_payload_parse_id(tmp, tmp_len);
308 /* Get client entry */
309 client = silc_idlist_find_client_by_id(server->global_list,
310 client_id, TRUE, &cache);
312 client = silc_idlist_find_client_by_id(server->local_list,
313 client_id, TRUE, &cache);
315 silc_free(client_id);
319 silc_free(client_id);
321 /* Get signoff message */
322 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
326 /* Remove the client from all channels. */
327 silc_server_remove_from_channels(server, NULL, client, TRUE, tmp, FALSE);
329 client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
330 cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
331 server->stat.clients--;
332 if (server->server_type == SILC_ROUTER)
333 server->stat.cell_clients--;
336 case SILC_NOTIFY_TYPE_TOPIC_SET:
338 * Distribute the notify to local clients on the channel
341 SILC_LOG_DEBUG(("TOPIC SET notify"));
344 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
345 packet->dst_id_type);
350 /* Get channel entry */
351 channel = silc_idlist_find_channel_by_id(server->global_list,
354 channel = silc_idlist_find_channel_by_id(server->local_list,
357 silc_free(channel_id);
363 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
365 silc_free(channel_id);
370 silc_free(channel->topic);
371 channel->topic = silc_calloc(tmp_len + 1, sizeof(*channel->topic));
372 memcpy(channel->topic, tmp, tmp_len);
374 /* Send the same notify to the channel */
375 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
376 FALSE, packet->buffer->data,
377 packet->buffer->len, FALSE);
378 silc_free(channel_id);
381 case SILC_NOTIFY_TYPE_NICK_CHANGE:
384 * Distribute the notify to local clients on the channel
386 unsigned char *id, *id2;
388 SILC_LOG_DEBUG(("NICK CHANGE notify"));
390 /* Get old client ID */
391 id = silc_argument_get_arg_type(args, 1, &tmp_len);
394 client_id = silc_id_payload_parse_id(id, tmp_len);
398 /* Get new client ID */
399 id2 = silc_argument_get_arg_type(args, 2, &tmp_len);
402 client_id2 = silc_id_payload_parse_id(id2, tmp_len);
406 SILC_LOG_DEBUG(("Old Client ID id(%s)",
407 silc_id_render(client_id, SILC_ID_CLIENT)));
408 SILC_LOG_DEBUG(("New Client ID id(%s)",
409 silc_id_render(client_id2, SILC_ID_CLIENT)));
411 /* Replace the Client ID */
412 client = silc_idlist_replace_client_id(server->global_list, client_id,
415 client = silc_idlist_replace_client_id(server->local_list, client_id,
419 /* The nickname is not valid anymore, set it NULL. This causes that
420 the nickname will be queried if someone wants to know it. */
421 if (client->nickname)
422 silc_free(client->nickname);
423 client->nickname = NULL;
425 /* Send the NICK_CHANGE notify type to local clients on the channels
426 this client is joined to. */
427 silc_server_send_notify_on_channels(server, NULL, client,
428 SILC_NOTIFY_TYPE_NICK_CHANGE, 2,
433 silc_free(client_id);
435 silc_free(client_id2);
439 case SILC_NOTIFY_TYPE_CMODE_CHANGE:
441 * Distribute the notify to local clients on the channel
444 SILC_LOG_DEBUG(("CMODE CHANGE notify"));
447 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
448 packet->dst_id_type);
453 /* Get channel entry */
454 channel = silc_idlist_find_channel_by_id(server->global_list,
457 channel = silc_idlist_find_channel_by_id(server->local_list,
460 silc_free(channel_id);
466 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
468 silc_free(channel_id);
472 SILC_GET32_MSB(mode, tmp);
474 /* Check if mode changed */
475 if (channel->mode == mode)
478 /* Send the same notify to the channel */
479 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
480 FALSE, packet->buffer->data,
481 packet->buffer->len, FALSE);
483 /* If the channel had private keys set and the mode was removed then
484 we must re-generate and re-distribute a new channel key */
485 if (channel->mode & SILC_CHANNEL_MODE_PRIVKEY &&
486 !(mode & SILC_CHANNEL_MODE_PRIVKEY)) {
487 /* Re-generate channel key */
488 if (!silc_server_create_channel_key(server, channel, 0))
491 /* Send the channel key. This sends it to our local clients and if
492 we are normal server to our router as well. */
493 silc_server_send_channel_key(server, NULL, channel,
494 server->server_type == SILC_ROUTER ?
495 FALSE : !server->standalone);
499 channel->mode = mode;
500 silc_free(channel_id);
503 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
505 unsigned char hash[32];
508 silc_hmac_free(channel->hmac);
509 if (!silc_hmac_alloc(tmp, NULL, &channel->hmac))
512 /* Set the HMAC key out of current channel key. The client must do
514 silc_hash_make(silc_hmac_get_hash(channel->hmac), channel->key,
515 channel->key_len / 8,
517 silc_hmac_set_key(channel->hmac, hash,
518 silc_hash_len(silc_hmac_get_hash(channel->hmac)));
519 memset(hash, 0, sizeof(hash));
524 case SILC_NOTIFY_TYPE_CUMODE_CHANGE:
527 * Distribute the notify to local clients on the channel
529 SilcChannelClientEntry chl2 = NULL;
530 bool notify_sent = FALSE;
532 SILC_LOG_DEBUG(("CUMODE CHANGE notify"));
535 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
536 packet->dst_id_type);
541 /* Get channel entry */
542 channel = silc_idlist_find_channel_by_id(server->global_list,
545 channel = silc_idlist_find_channel_by_id(server->local_list,
548 silc_free(channel_id);
554 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
556 silc_free(channel_id);
560 SILC_GET32_MSB(mode, tmp);
562 /* Get target client */
563 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
566 client_id = silc_id_payload_parse_id(tmp, tmp_len);
570 /* Get client entry */
571 client = silc_idlist_find_client_by_id(server->global_list,
572 client_id, TRUE, NULL);
574 client = silc_idlist_find_client_by_id(server->local_list,
575 client_id, TRUE, NULL);
577 silc_free(client_id);
581 silc_free(client_id);
583 /* Get entry to the channel user list */
584 silc_hash_table_list(channel->user_list, &htl);
585 while (silc_hash_table_get(&htl, NULL, (void *)&chl)) {
586 /* If the mode is channel founder and we already find a client
587 to have that mode on the channel we will enforce the sender
588 to change the channel founder mode away. There can be only one
589 channel founder on the channel. */
590 if (server->server_type == SILC_ROUTER &&
591 mode & SILC_CHANNEL_UMODE_CHANFO &&
592 chl->mode & SILC_CHANNEL_UMODE_CHANFO) {
594 unsigned char cumode[4];
596 if (chl->client == client && chl->mode == mode) {
601 mode &= ~SILC_CHANNEL_UMODE_CHANFO;
602 silc_server_send_notify_cumode(server, sock, FALSE, channel, mode,
603 client->id, SILC_ID_CLIENT,
606 idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT);
607 SILC_PUT32_MSB(mode, cumode);
608 silc_server_send_notify_to_channel(server, sock, channel, FALSE,
609 SILC_NOTIFY_TYPE_CUMODE_CHANGE,
610 3, idp->data, idp->len,
612 idp->data, idp->len);
613 silc_buffer_free(idp);
616 /* Force the mode change if we alredy set the mode */
619 silc_free(channel_id);
624 if (chl->client == client) {
625 if (chl->mode == mode) {
630 /* Change the mode */
632 if (!(mode & SILC_CHANNEL_UMODE_CHANFO))
639 /* Send the same notify to the channel */
641 silc_server_packet_send_to_channel(server, sock, channel,
643 FALSE, packet->buffer->data,
644 packet->buffer->len, FALSE);
646 silc_free(channel_id);
650 case SILC_NOTIFY_TYPE_INVITE:
652 if (packet->dst_id_type == SILC_ID_CLIENT)
655 SILC_LOG_DEBUG(("INVITE notify"));
658 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
661 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
665 /* Get channel entry */
666 channel = silc_idlist_find_channel_by_id(server->global_list,
669 channel = silc_idlist_find_channel_by_id(server->local_list,
672 silc_free(channel_id);
676 silc_free(channel_id);
678 /* Get the added invite */
679 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
681 if (!channel->invite_list)
682 channel->invite_list = silc_calloc(tmp_len + 2,
683 sizeof(*channel->invite_list));
685 channel->invite_list = silc_realloc(channel->invite_list,
686 sizeof(*channel->invite_list) *
688 strlen(channel->invite_list) +
690 if (tmp[tmp_len - 1] == ',')
691 tmp[tmp_len - 1] = '\0';
693 strncat(channel->invite_list, tmp, tmp_len);
694 strncat(channel->invite_list, ",", 1);
697 /* Get the deleted invite */
698 tmp = silc_argument_get_arg_type(args, 4, &tmp_len);
699 if (tmp && channel->invite_list) {
700 char *start, *end, *n;
702 if (!strncmp(channel->invite_list, tmp,
703 strlen(channel->invite_list) - 1)) {
704 silc_free(channel->invite_list);
705 channel->invite_list = NULL;
707 start = strstr(channel->invite_list, tmp);
708 if (start && strlen(start) >= tmp_len) {
709 end = start + tmp_len;
710 n = silc_calloc(strlen(channel->invite_list) - tmp_len, sizeof(*n));
711 strncat(n, channel->invite_list, start - channel->invite_list);
712 strncat(n, end + 1, ((channel->invite_list +
713 strlen(channel->invite_list)) - end) - 1);
714 silc_free(channel->invite_list);
715 channel->invite_list = n;
722 case SILC_NOTIFY_TYPE_CHANNEL_CHANGE:
724 * Distribute to the local clients on the channel and change the
728 SILC_LOG_DEBUG(("CHANNEL CHANGE"));
730 if (sock->type != SILC_SOCKET_TYPE_ROUTER)
733 /* Get the old Channel ID */
734 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
737 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
741 /* Get the channel entry */
742 channel = silc_idlist_find_channel_by_id(server->global_list,
745 channel = silc_idlist_find_channel_by_id(server->local_list,
748 silc_free(channel_id);
753 /* Send the notify to the channel */
754 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
755 FALSE, packet->buffer->data,
756 packet->buffer->len, FALSE);
758 /* Get the new Channel ID */
759 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
762 channel_id2 = silc_id_payload_parse_id(tmp, tmp_len);
766 SILC_LOG_DEBUG(("Old Channel ID id(%s)",
767 silc_id_render(channel_id, SILC_ID_CHANNEL)));
768 SILC_LOG_DEBUG(("New Channel ID id(%s)",
769 silc_id_render(channel_id2, SILC_ID_CHANNEL)));
771 /* Replace the Channel ID */
772 if (!silc_idlist_replace_channel_id(server->global_list, channel_id,
774 if (!silc_idlist_replace_channel_id(server->local_list, channel_id,
776 silc_free(channel_id2);
781 SilcBuffer users = NULL, users_modes = NULL;
783 /* Re-announce our clients on the channel as the ID has changed now */
784 silc_server_announce_get_channel_users(server, channel, &users,
787 silc_buffer_push(users, users->data - users->head);
788 silc_server_packet_send(server, sock,
789 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
790 users->data, users->len, FALSE);
791 silc_buffer_free(users);
794 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
795 silc_server_packet_send_dest(server, sock,
796 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
797 channel->id, SILC_ID_CHANNEL,
799 users_modes->len, FALSE);
800 silc_buffer_free(users_modes);
804 silc_free(channel_id);
808 case SILC_NOTIFY_TYPE_SERVER_SIGNOFF:
810 * Remove the server entry and all clients that this server owns.
813 SILC_LOG_DEBUG(("SERVER SIGNOFF notify"));
816 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
819 server_id = silc_id_payload_parse_id(tmp, tmp_len);
823 /* Get server entry */
824 server_entry = silc_idlist_find_server_by_id(server->global_list,
825 server_id, TRUE, NULL);
827 server_entry = silc_idlist_find_server_by_id(server->local_list,
828 server_id, TRUE, NULL);
830 /* If we are normal server then we might not have the server. Check
831 whether router was kind enough to send the list of all clients
832 that actually was to be removed. Remove them if the list is
834 if (server->server_type != SILC_ROUTER &&
835 silc_argument_get_arg_num(args) > 1) {
838 for (i = 1; i < silc_argument_get_arg_num(args); i++) {
840 tmp = silc_argument_get_arg_type(args, i + 1, &tmp_len);
843 client_id = silc_id_payload_parse_id(tmp, tmp_len);
847 /* Get client entry */
848 client = silc_idlist_find_client_by_id(server->global_list,
849 client_id, TRUE, &cache);
851 client = silc_idlist_find_client_by_id(server->local_list,
852 client_id, TRUE, &cache);
854 silc_free(client_id);
858 silc_free(client_id);
860 /* Remove the client from all channels. */
861 silc_server_remove_from_channels(server, NULL, client,
864 client->data.status &= ~SILC_IDLIST_STATUS_REGISTERED;
865 cache->expire = SILC_ID_CACHE_EXPIRE_DEF;
866 server->stat.clients--;
867 if (server->server_type == SILC_ROUTER)
868 server->stat.cell_clients--;
872 silc_free(server_id);
876 silc_free(server_id);
878 /* Free all client entries that this server owns as they will
879 become invalid now as well. */
880 silc_server_remove_clients_by_server(server, server_entry, TRUE);
882 /* Remove the server entry */
883 if (!silc_idlist_del_server(server->global_list, server_entry))
884 silc_idlist_del_server(server->local_list, server_entry);
886 /* XXX update statistics */
890 case SILC_NOTIFY_TYPE_KICKED:
892 * Distribute the notify to local clients on the channel
895 SILC_LOG_DEBUG(("KICKED notify"));
898 channel_id = silc_id_str2id(packet->dst_id, packet->dst_id_len,
899 packet->dst_id_type);
904 /* Get channel entry */
905 channel = silc_idlist_find_channel_by_id(server->global_list,
908 channel = silc_idlist_find_channel_by_id(server->local_list,
911 silc_free(channel_id);
915 silc_free(channel_id);
918 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
921 client_id = silc_id_payload_parse_id(tmp, tmp_len);
925 /* If the the client is not in local list we check global list */
926 client = silc_idlist_find_client_by_id(server->global_list,
927 client_id, TRUE, NULL);
929 client = silc_idlist_find_client_by_id(server->local_list,
930 client_id, TRUE, NULL);
932 silc_free(client_id);
937 /* Send to channel */
938 silc_server_packet_send_to_channel(server, sock, channel, packet->type,
939 FALSE, packet->buffer->data,
940 packet->buffer->len, FALSE);
942 /* Remove the client from channel */
943 silc_server_remove_from_one_channel(server, sock, channel, client, FALSE);
947 case SILC_NOTIFY_TYPE_KILLED:
950 * Distribute the notify to local clients on channels
955 SILC_LOG_DEBUG(("KILLED notify"));
958 id = silc_argument_get_arg_type(args, 1, &id_len);
961 client_id = silc_id_payload_parse_id(id, id_len);
965 /* If the the client is not in local list we check global list */
966 client = silc_idlist_find_client_by_id(server->global_list,
967 client_id, TRUE, NULL);
969 client = silc_idlist_find_client_by_id(server->local_list,
970 client_id, TRUE, NULL);
972 silc_free(client_id);
976 silc_free(client_id);
978 /* If the client is one of ours, then close the connection to the
979 client now. This removes the client from all channels as well. */
980 if (packet->dst_id_type == SILC_ID_CLIENT && client->connection) {
981 sock = client->connection;
982 silc_server_free_client_data(server, NULL, client, FALSE, NULL);
983 silc_server_close_connection(server, sock);
988 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
992 /* Send the notify to local clients on the channels except to the
993 client who is killed. */
994 silc_server_send_notify_on_channels(server, client, client,
995 SILC_NOTIFY_TYPE_KILLED,
1000 /* Remove the client from all channels */
1001 silc_server_remove_from_channels(server, NULL, client, FALSE, NULL,
1007 case SILC_NOTIFY_TYPE_UMODE_CHANGE:
1009 * Save the mode of the client.
1012 SILC_LOG_DEBUG(("UMODE_CHANGE notify"));
1015 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1018 client_id = silc_id_payload_parse_id(tmp, tmp_len);
1022 /* Get client entry */
1023 client = silc_idlist_find_client_by_id(server->global_list,
1024 client_id, TRUE, NULL);
1026 client = silc_idlist_find_client_by_id(server->local_list,
1027 client_id, TRUE, NULL);
1029 silc_free(client_id);
1033 silc_free(client_id);
1036 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1041 SILC_GET32_MSB(client->mode, tmp);
1045 case SILC_NOTIFY_TYPE_BAN:
1050 SILC_LOG_DEBUG(("BAN notify"));
1052 /* Get Channel ID */
1053 tmp = silc_argument_get_arg_type(args, 1, &tmp_len);
1056 channel_id = silc_id_payload_parse_id(tmp, tmp_len);
1060 /* Get channel entry */
1061 channel = silc_idlist_find_channel_by_id(server->global_list,
1064 channel = silc_idlist_find_channel_by_id(server->local_list,
1067 silc_free(channel_id);
1071 silc_free(channel_id);
1073 /* Get the new ban and add it to the ban list */
1074 tmp = silc_argument_get_arg_type(args, 2, &tmp_len);
1076 if (!channel->ban_list)
1077 channel->ban_list = silc_calloc(tmp_len + 2,
1078 sizeof(*channel->ban_list));
1080 channel->ban_list = silc_realloc(channel->ban_list,
1081 sizeof(*channel->ban_list) *
1083 strlen(channel->ban_list) + 2));
1084 strncat(channel->ban_list, tmp, tmp_len);
1085 strncat(channel->ban_list, ",", 1);
1088 /* Get the ban to be removed and remove it from the list */
1089 tmp = silc_argument_get_arg_type(args, 3, &tmp_len);
1090 if (tmp && channel->ban_list) {
1091 char *start, *end, *n;
1093 if (!strcmp(channel->ban_list, tmp)) {
1094 silc_free(channel->ban_list);
1095 channel->ban_list = NULL;
1097 start = strstr(channel->ban_list, tmp);
1098 if (start && strlen(start) >= tmp_len) {
1099 end = start + tmp_len;
1100 n = silc_calloc(strlen(channel->ban_list) - tmp_len, sizeof(*n));
1101 strncat(n, channel->ban_list, start - channel->ban_list);
1102 strncat(n, end + 1, ((channel->ban_list +
1103 strlen(channel->ban_list)) - end) - 1);
1104 silc_free(channel->ban_list);
1105 channel->ban_list = n;
1112 /* Ignore rest of the notify types for now */
1113 case SILC_NOTIFY_TYPE_NONE:
1114 case SILC_NOTIFY_TYPE_MOTD:
1121 silc_notify_payload_free(payload);
1124 void silc_server_notify_list(SilcServer server,
1125 SilcSocketConnection sock,
1126 SilcPacketContext *packet)
1128 SilcPacketContext *new;
1132 SILC_LOG_DEBUG(("Processing Notify List"));
1134 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
1135 packet->src_id_type != SILC_ID_SERVER)
1138 /* Make copy of the original packet context, except for the actual
1139 data buffer, which we will here now fetch from the original buffer. */
1140 new = silc_packet_context_alloc();
1141 new->type = SILC_PACKET_NOTIFY;
1142 new->flags = packet->flags;
1143 new->src_id = packet->src_id;
1144 new->src_id_len = packet->src_id_len;
1145 new->src_id_type = packet->src_id_type;
1146 new->dst_id = packet->dst_id;
1147 new->dst_id_len = packet->dst_id_len;
1148 new->dst_id_type = packet->dst_id_type;
1150 buffer = silc_buffer_alloc(1024);
1151 new->buffer = buffer;
1153 while (packet->buffer->len) {
1154 SILC_GET16_MSB(len, packet->buffer->data + 2);
1155 if (len > packet->buffer->len)
1158 if (len > buffer->truelen) {
1159 silc_buffer_free(buffer);
1160 buffer = silc_buffer_alloc(1024 + len);
1163 silc_buffer_pull_tail(buffer, len);
1164 silc_buffer_put(buffer, packet->buffer->data, len);
1166 /* Process the Notify */
1167 silc_server_notify(server, sock, new);
1169 silc_buffer_push_tail(buffer, len);
1170 silc_buffer_pull(packet->buffer, len);
1173 silc_buffer_free(buffer);
1177 /* Received private message. This resolves the destination of the message
1178 and sends the packet. This is used by both server and router. If the
1179 destination is our locally connected client this sends the packet to
1180 the client. This may also send the message for further routing if
1181 the destination is not in our server (or router). */
1183 void silc_server_private_message(SilcServer server,
1184 SilcSocketConnection sock,
1185 SilcPacketContext *packet)
1187 SilcSocketConnection dst_sock;
1188 SilcIDListData idata;
1190 SILC_LOG_DEBUG(("Start"));
1192 if (packet->src_id_type != SILC_ID_CLIENT ||
1193 packet->dst_id_type != SILC_ID_CLIENT)
1196 if (!packet->dst_id)
1199 /* Get the route to the client */
1200 dst_sock = silc_server_get_client_route(server, packet->dst_id,
1201 packet->dst_id_len, NULL, &idata);
1205 /* Send the private message */
1206 silc_server_send_private_message(server, dst_sock, idata->send_key,
1207 idata->hmac_send, idata->psn_send++,
1211 /* Received private message key packet.. This packet is never for us. It is to
1212 the client in the packet's destination ID. Sending of this sort of packet
1213 equals sending private message, ie. it is sent point to point from
1214 one client to another. */
1216 void silc_server_private_message_key(SilcServer server,
1217 SilcSocketConnection sock,
1218 SilcPacketContext *packet)
1220 SilcSocketConnection dst_sock;
1221 SilcIDListData idata;
1223 SILC_LOG_DEBUG(("Start"));
1225 if (packet->src_id_type != SILC_ID_CLIENT ||
1226 packet->dst_id_type != SILC_ID_CLIENT)
1229 if (!packet->dst_id)
1232 /* Get the route to the client */
1233 dst_sock = silc_server_get_client_route(server, packet->dst_id,
1234 packet->dst_id_len, NULL, &idata);
1238 /* Relay the packet */
1239 silc_server_relay_packet(server, dst_sock, idata->send_key,
1240 idata->hmac_send, idata->psn_send++, packet, FALSE);
1243 /* Processes incoming command reply packet. The command reply packet may
1244 be destined to one of our clients or it may directly for us. We will
1245 call the command reply routine after processing the packet. */
1247 void silc_server_command_reply(SilcServer server,
1248 SilcSocketConnection sock,
1249 SilcPacketContext *packet)
1251 SilcBuffer buffer = packet->buffer;
1252 SilcClientEntry client = NULL;
1253 SilcSocketConnection dst_sock;
1254 SilcIDListData idata;
1255 SilcClientID *id = NULL;
1257 SILC_LOG_DEBUG(("Start"));
1259 /* Source must be server or router */
1260 if (packet->src_id_type != SILC_ID_SERVER &&
1261 sock->type != SILC_SOCKET_TYPE_ROUTER)
1264 if (packet->dst_id_type == SILC_ID_CHANNEL)
1267 if (packet->dst_id_type == SILC_ID_CLIENT) {
1268 /* Destination must be one of ours */
1269 id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CLIENT);
1272 client = silc_idlist_find_client_by_id(server->local_list, id, TRUE, NULL);
1274 SILC_LOG_ERROR(("Cannot process command reply to unknown client"));
1280 if (packet->dst_id_type == SILC_ID_SERVER) {
1281 /* For now this must be for us */
1282 if (memcmp(packet->dst_id, server->id_string, packet->dst_id_len)) {
1283 SILC_LOG_ERROR(("Cannot process command reply to unknown server"));
1288 /* Execute command reply locally for the command */
1289 silc_server_command_reply_process(server, sock, buffer);
1291 if (packet->dst_id_type == SILC_ID_CLIENT && client && id) {
1292 /* Relay the packet to the client */
1294 dst_sock = (SilcSocketConnection)client->connection;
1295 silc_buffer_push(buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
1296 + packet->dst_id_len + packet->padlen);
1298 silc_packet_send_prepare(dst_sock, 0, 0, buffer->len);
1299 silc_buffer_put(dst_sock->outbuf, buffer->data, buffer->len);
1301 idata = (SilcIDListData)client;
1303 /* Encrypt packet */
1304 silc_packet_encrypt(idata->send_key, idata->hmac_send, idata->psn_send++,
1305 dst_sock->outbuf, buffer->len);
1307 /* Send the packet */
1308 silc_server_packet_send_real(server, dst_sock, TRUE);
1314 /* Process received channel message. The message can be originated from
1315 client or server. */
1317 void silc_server_channel_message(SilcServer server,
1318 SilcSocketConnection sock,
1319 SilcPacketContext *packet)
1321 SilcChannelEntry channel = NULL;
1322 SilcChannelID *id = NULL;
1323 void *sender = NULL;
1324 void *sender_entry = NULL;
1327 SILC_LOG_DEBUG(("Processing channel message"));
1330 if (packet->dst_id_type != SILC_ID_CHANNEL) {
1331 SILC_LOG_DEBUG(("Received bad message for channel, dropped"));
1335 /* Find channel entry */
1336 id = silc_id_str2id(packet->dst_id, packet->dst_id_len, SILC_ID_CHANNEL);
1339 channel = silc_idlist_find_channel_by_id(server->local_list, id, NULL);
1341 channel = silc_idlist_find_channel_by_id(server->global_list, id, NULL);
1343 SILC_LOG_DEBUG(("Could not find channel"));
1348 /* See that this client is on the channel. If the original sender is
1349 not client (as it can be server as well) we don't do the check. */
1350 sender = silc_id_str2id(packet->src_id, packet->src_id_len,
1351 packet->src_id_type);
1354 if (packet->src_id_type == SILC_ID_CLIENT) {
1355 sender_entry = silc_idlist_find_client_by_id(server->local_list,
1356 sender, TRUE, NULL);
1357 if (!sender_entry) {
1359 sender_entry = silc_idlist_find_client_by_id(server->global_list,
1360 sender, TRUE, NULL);
1362 if (!sender_entry || !silc_server_client_on_channel(sender_entry,
1364 SILC_LOG_DEBUG(("Client not on channel"));
1368 /* If the packet is coming from router, but the client entry is
1369 local entry to us then some router is rerouting this to us and it is
1371 if (server->server_type == SILC_ROUTER &&
1372 sock->type == SILC_SOCKET_TYPE_ROUTER && local) {
1373 SILC_LOG_DEBUG(("Channel message rerouted to the sender, drop it"));
1378 /* Distribute the packet to our local clients. This will send the
1379 packet for further routing as well, if needed. */
1380 silc_server_packet_relay_to_channel(server, sock, channel, sender,
1381 packet->src_id_type, sender_entry,
1382 packet->buffer->data,
1383 packet->buffer->len, FALSE);
1392 /* Received channel key packet. We distribute the key to all of our locally
1393 connected clients on the channel. */
1395 void silc_server_channel_key(SilcServer server,
1396 SilcSocketConnection sock,
1397 SilcPacketContext *packet)
1399 SilcBuffer buffer = packet->buffer;
1400 SilcChannelEntry channel;
1402 if (packet->src_id_type != SILC_ID_SERVER ||
1403 (server->server_type == SILC_ROUTER &&
1404 sock->type == SILC_SOCKET_TYPE_ROUTER))
1407 /* Save the channel key */
1408 channel = silc_server_save_channel_key(server, buffer, NULL);
1412 /* Distribute the key to everybody who is on the channel. If we are router
1413 we will also send it to locally connected servers. */
1414 silc_server_send_channel_key(server, sock, channel, FALSE);
1416 if (server->server_type != SILC_BACKUP_ROUTER) {
1417 /* Distribute to local cell backup routers. */
1418 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
1419 SILC_PACKET_CHANNEL_KEY, 0,
1420 buffer->data, buffer->len, FALSE, TRUE);
1424 /* Received New Client packet and processes it. Creates Client ID for the
1425 client. Client becomes registered after calling this functions. */
1427 SilcClientEntry silc_server_new_client(SilcServer server,
1428 SilcSocketConnection sock,
1429 SilcPacketContext *packet)
1431 SilcBuffer buffer = packet->buffer;
1432 SilcClientEntry client;
1433 SilcClientID *client_id;
1435 SilcIDListData idata;
1436 char *username = NULL, *realname = NULL, *id_string;
1439 char *hostname, *nickname;
1442 SILC_LOG_DEBUG(("Creating new client"));
1444 if (sock->type != SILC_SOCKET_TYPE_CLIENT)
1447 /* Take client entry */
1448 client = (SilcClientEntry)sock->user_data;
1449 idata = (SilcIDListData)client;
1451 /* Remove the old cache entry */
1452 if (!silc_idcache_del_by_context(server->local_list->clients, client)) {
1453 SILC_LOG_ERROR(("Lost client's cache entry - bad thing"));
1454 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1459 /* Parse incoming packet */
1460 ret = silc_buffer_unformat(buffer,
1461 SILC_STR_UI16_STRING_ALLOC(&username),
1462 SILC_STR_UI16_STRING_ALLOC(&realname),
1466 silc_free(username);
1468 silc_free(realname);
1469 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1470 "Incomplete client information");
1475 silc_free(username);
1477 silc_free(realname);
1478 silc_server_disconnect_remote(server, sock, "Server closed connection: "
1479 "Incomplete client information");
1483 if (strlen(username) > 128)
1484 username[127] = '\0';
1486 nickname = strdup(username);
1488 /* Make sanity checks for the hostname of the client. If the hostname
1489 is provided in the `username' check that it is the same than the
1490 resolved hostname, or if not resolved the hostname that appears in
1491 the client's public key. If the hostname is not present then put
1492 it from the resolved name or from the public key. */
1493 if (strchr(username, '@')) {
1494 SilcPublicKeyIdentifier pident;
1495 int tlen = strcspn(username, "@");
1496 char *phostname = NULL;
1498 hostname = silc_calloc((strlen(username) - tlen) + 1, sizeof(char));
1499 memcpy(hostname, username + tlen + 1, strlen(username) - tlen - 1);
1501 if (strcmp(sock->hostname, sock->ip) &&
1502 strcmp(sock->hostname, hostname)) {
1503 silc_free(username);
1504 silc_free(hostname);
1506 silc_free(realname);
1507 silc_server_disconnect_remote(server, sock,
1508 "Server closed connection: "
1509 "Incomplete client information");
1513 pident = silc_pkcs_decode_identifier(client->data.public_key->identifier);
1515 phostname = strdup(pident->host);
1516 silc_pkcs_free_identifier(pident);
1519 if (!strcmp(sock->hostname, sock->ip) &&
1520 phostname && strcmp(phostname, hostname)) {
1521 silc_free(username);
1522 silc_free(hostname);
1524 silc_free(phostname);
1526 silc_free(realname);
1527 silc_server_disconnect_remote(server, sock,
1528 "Server closed connection: "
1529 "Incomplete client information");
1534 silc_free(phostname);
1536 /* The hostname is not present, add it. */
1538 /* XXX For now we cannot take the host name from the public key since
1539 they are not trusted or we cannot verify them as trusted. Just take
1540 what the resolved name or address is. */
1542 if (strcmp(sock->hostname, sock->ip)) {
1544 newusername = silc_calloc(strlen(username) +
1545 strlen(sock->hostname) + 2,
1546 sizeof(*newusername));
1547 strncat(newusername, username, strlen(username));
1548 strncat(newusername, "@", 1);
1549 strncat(newusername, sock->hostname, strlen(sock->hostname));
1550 silc_free(username);
1551 username = newusername;
1554 SilcPublicKeyIdentifier pident =
1555 silc_pkcs_decode_identifier(client->data.public_key->identifier);
1558 newusername = silc_calloc(strlen(username) +
1559 strlen(pident->host) + 2,
1560 sizeof(*newusername));
1561 strncat(newusername, username, strlen(username));
1562 strncat(newusername, "@", 1);
1563 strncat(newusername, pident->host, strlen(pident->host));
1564 silc_free(username);
1565 username = newusername;
1566 silc_pkcs_free_identifier(pident);
1572 /* Create Client ID */
1573 while (!silc_id_create_client_id(server, server->id, server->rng,
1574 server->md5hash, nickname, &client_id)) {
1576 snprintf(&nickname[strlen(nickname) - 1], 1, "%d", nickfail);
1579 /* Update client entry */
1580 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
1581 client->nickname = nickname;
1582 client->username = username;
1583 client->userinfo = realname ? realname : strdup(" ");
1584 client->id = client_id;
1585 id_len = silc_id_get_len(client_id, SILC_ID_CLIENT);
1587 /* Add the client again to the ID cache */
1588 silc_idcache_add(server->local_list->clients, client->nickname,
1589 client_id, client, FALSE);
1591 /* Notify our router about new client on the SILC network */
1592 if (!server->standalone)
1593 silc_server_send_new_id(server, (SilcSocketConnection)
1594 server->router->connection,
1595 server->server_type == SILC_ROUTER ? TRUE : FALSE,
1596 client->id, SILC_ID_CLIENT, id_len);
1598 /* Send the new client ID to the client. */
1599 id_string = silc_id_id2str(client->id, SILC_ID_CLIENT);
1600 reply = silc_buffer_alloc(2 + 2 + id_len);
1601 silc_buffer_pull_tail(reply, SILC_BUFFER_END(reply));
1602 silc_buffer_format(reply,
1603 SILC_STR_UI_SHORT(SILC_ID_CLIENT),
1604 SILC_STR_UI_SHORT(id_len),
1605 SILC_STR_UI_XNSTRING(id_string, id_len),
1607 silc_server_packet_send(server, sock, SILC_PACKET_NEW_ID, 0,
1608 reply->data, reply->len, FALSE);
1609 silc_free(id_string);
1610 silc_buffer_free(reply);
1612 /* Send some nice info to the client */
1613 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1614 ("Welcome to the SILC Network %s",
1616 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1617 ("Your host is %s, running version %s",
1618 server->config->server_info->server_name,
1620 if (server->server_type == SILC_ROUTER) {
1621 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1622 ("There are %d clients on %d servers in SILC "
1623 "Network", server->stat.clients,
1624 server->stat.servers + 1));
1625 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1626 ("There are %d clients on %d server in our cell",
1627 server->stat.cell_clients,
1628 server->stat.cell_servers + 1));
1629 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1630 ("I have %d clients, %d channels, %d servers and "
1632 server->stat.my_clients,
1633 server->stat.my_channels,
1634 server->stat.my_servers,
1635 server->stat.my_routers));
1636 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1637 ("%d server operators and %d router operators "
1639 server->stat.my_server_ops,
1640 server->stat.my_router_ops));
1642 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1643 ("I have %d clients and %d channels formed",
1644 server->stat.my_clients,
1645 server->stat.my_channels));
1646 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1647 ("%d operators online",
1648 server->stat.my_server_ops));
1650 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1651 ("Your connection is secured with %s cipher, "
1652 "key length %d bits",
1653 idata->send_key->cipher->name,
1654 idata->send_key->cipher->key_len));
1655 SILC_SERVER_SEND_NOTIFY(server, sock, SILC_NOTIFY_TYPE_NONE,
1656 ("Your current nickname is %s",
1660 silc_server_send_motd(server, sock);
1665 /* Create new server. This processes received New Server packet and
1666 saves the received Server ID. The server is our locally connected
1667 server thus we save all the information and save it to local list.
1668 This funtion can be used by both normal server and router server.
1669 If normal server uses this it means that its router has connected
1670 to the server. If router uses this it means that one of the cell's
1671 servers is connected to the router. */
1673 SilcServerEntry silc_server_new_server(SilcServer server,
1674 SilcSocketConnection sock,
1675 SilcPacketContext *packet)
1677 SilcBuffer buffer = packet->buffer;
1678 SilcServerEntry new_server, server_entry;
1679 SilcServerID *server_id;
1680 SilcIDListData idata;
1681 unsigned char *server_name, *id_string;
1682 uint16 id_len, name_len;
1686 SILC_LOG_DEBUG(("Creating new server"));
1688 if (sock->type != SILC_SOCKET_TYPE_SERVER &&
1689 sock->type != SILC_SOCKET_TYPE_ROUTER)
1692 /* Take server entry */
1693 new_server = (SilcServerEntry)sock->user_data;
1694 idata = (SilcIDListData)new_server;
1696 /* Remove the old cache entry */
1697 if (!silc_idcache_del_by_context(server->local_list->servers, new_server)) {
1698 silc_idcache_del_by_context(server->global_list->servers, new_server);
1702 /* Parse the incoming packet */
1703 ret = silc_buffer_unformat(buffer,
1704 SILC_STR_UI16_NSTRING_ALLOC(&id_string, &id_len),
1705 SILC_STR_UI16_NSTRING_ALLOC(&server_name,
1710 silc_free(id_string);
1712 silc_free(server_name);
1716 if (id_len > buffer->len) {
1717 silc_free(id_string);
1718 silc_free(server_name);
1723 server_name[255] = '\0';
1726 server_id = silc_id_str2id(id_string, id_len, SILC_ID_SERVER);
1728 silc_free(id_string);
1729 silc_free(server_name);
1732 silc_free(id_string);
1734 /* Check that we do not have this ID already */
1735 server_entry = silc_idlist_find_server_by_id(server->local_list,
1736 server_id, TRUE, NULL);
1738 silc_idcache_del_by_context(server->local_list->servers, server_entry);
1740 server_entry = silc_idlist_find_server_by_id(server->global_list,
1741 server_id, TRUE, NULL);
1743 silc_idcache_del_by_context(server->global_list->servers, server_entry);
1746 /* Update server entry */
1747 idata->status |= SILC_IDLIST_STATUS_REGISTERED;
1748 new_server->server_name = server_name;
1749 new_server->id = server_id;
1751 SILC_LOG_DEBUG(("New server id(%s)",
1752 silc_id_render(server_id, SILC_ID_SERVER)));
1754 /* Add again the entry to the ID cache. */
1755 silc_idcache_add(local ? server->local_list->servers :
1756 server->global_list->servers, server_name, server_id,
1759 /* Distribute the information about new server in the SILC network
1760 to our router. If we are normal server we won't send anything
1761 since this connection must be our router connection. */
1762 if (server->server_type == SILC_ROUTER && !server->standalone &&
1763 server->router->connection != sock)
1764 silc_server_send_new_id(server, server->router->connection,
1765 TRUE, new_server->id, SILC_ID_SERVER,
1766 silc_id_get_len(server_id, SILC_ID_SERVER));
1768 if (server->server_type == SILC_ROUTER)
1769 server->stat.cell_servers++;
1771 /* Check whether this router connection has been replaced by an
1772 backup router. If it has been then we'll disable the server and will
1773 ignore everything it will send until the backup router resuming
1774 protocol has been completed. */
1775 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
1776 silc_server_backup_replaced_get(server, server_id, NULL)) {
1777 /* Send packet to the server indicating that it cannot use this
1778 connection as it has been replaced by backup router. */
1779 SilcBuffer packet = silc_buffer_alloc(2);
1780 silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
1781 silc_buffer_format(packet,
1782 SILC_STR_UI_CHAR(SILC_SERVER_BACKUP_REPLACED),
1783 SILC_STR_UI_CHAR(0),
1785 silc_server_packet_send(server, sock,
1786 SILC_PACKET_RESUME_ROUTER, 0,
1787 packet->data, packet->len, TRUE);
1788 silc_buffer_free(packet);
1790 /* Mark the router disabled. The data sent earlier will go but nothing
1791 after this does not go to this connection. */
1792 idata->status |= SILC_IDLIST_STATUS_DISABLED;
1794 /* If it is router announce our stuff to it. */
1795 if (sock->type == SILC_SOCKET_TYPE_ROUTER &&
1796 server->server_type == SILC_ROUTER) {
1797 silc_server_announce_servers(server, FALSE, 0, sock);
1798 silc_server_announce_clients(server, 0, sock);
1799 silc_server_announce_channels(server, 0, sock);
1806 /* Processes incoming New ID packet. New ID Payload is used to distribute
1807 information about newly registered clients and servers. */
1809 static void silc_server_new_id_real(SilcServer server,
1810 SilcSocketConnection sock,
1811 SilcPacketContext *packet,
1814 SilcBuffer buffer = packet->buffer;
1816 SilcServerEntry router, server_entry;
1817 SilcSocketConnection router_sock;
1822 SILC_LOG_DEBUG(("Processing new ID"));
1824 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
1825 server->server_type == SILC_SERVER ||
1826 packet->src_id_type != SILC_ID_SERVER)
1829 idp = silc_id_payload_parse(buffer);
1833 id_type = silc_id_payload_get_type(idp);
1835 /* Normal server cannot have other normal server connections */
1836 server_entry = (SilcServerEntry)sock->user_data;
1837 if (id_type == SILC_ID_SERVER && sock->type == SILC_SOCKET_TYPE_SERVER &&
1838 server_entry->server_type == SILC_SERVER)
1841 id = silc_id_payload_get_id(idp);
1845 /* If the packet is coming from server then use the sender as the
1846 origin of the the packet. If it came from router then check the real
1847 sender of the packet and use that as the origin. */
1848 if (sock->type == SILC_SOCKET_TYPE_SERVER) {
1849 id_list = server->local_list;
1851 router = sock->user_data;
1853 /* If the sender is backup router and ID is server (and we are not
1854 backup router) then switch the entry to global list. */
1855 if (server_entry->server_type == SILC_BACKUP_ROUTER &&
1856 id_type == SILC_ID_SERVER &&
1857 server->id_entry->server_type != SILC_BACKUP_ROUTER) {
1858 id_list = server->global_list;
1859 router_sock = server->router ? server->router->connection : sock;
1862 void *sender_id = silc_id_str2id(packet->src_id, packet->src_id_len,
1863 packet->src_id_type);
1864 router = silc_idlist_find_server_by_id(server->global_list,
1865 sender_id, TRUE, NULL);
1867 router = silc_idlist_find_server_by_id(server->local_list,
1868 sender_id, TRUE, NULL);
1869 silc_free(sender_id);
1873 id_list = server->global_list;
1877 case SILC_ID_CLIENT:
1879 SilcClientEntry entry;
1881 /* Check that we do not have this client already */
1882 entry = silc_idlist_find_client_by_id(server->global_list,
1883 id, server->server_type,
1886 entry = silc_idlist_find_client_by_id(server->local_list,
1887 id, server->server_type,
1890 SILC_LOG_DEBUG(("Ignoring client that we already have"));
1894 SILC_LOG_DEBUG(("New client id(%s) from [%s] %s",
1895 silc_id_render(id, SILC_ID_CLIENT),
1896 sock->type == SILC_SOCKET_TYPE_SERVER ?
1897 "Server" : "Router", sock->hostname));
1899 /* As a router we keep information of all global information in our
1900 global list. Cell wide information however is kept in the local
1902 entry = silc_idlist_add_client(id_list, NULL, NULL, NULL,
1905 SILC_LOG_ERROR(("Could not add new client to the ID Cache"));
1907 /* Inform the sender that the ID is not usable */
1908 silc_server_send_notify_signoff(server, sock, FALSE, id, NULL);
1911 entry->nickname = NULL;
1912 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
1914 if (sock->type == SILC_SOCKET_TYPE_SERVER)
1915 server->stat.cell_clients++;
1916 server->stat.clients++;
1920 case SILC_ID_SERVER:
1922 SilcServerEntry entry;
1924 /* If the ID is mine, ignore it. */
1925 if (SILC_ID_SERVER_COMPARE(id, server->id)) {
1926 SILC_LOG_DEBUG(("Ignoring my own ID as new ID"));
1930 /* If the ID is the sender's ID, ignore it (we have it already) */
1931 if (SILC_ID_SERVER_COMPARE(id, router->id)) {
1932 SILC_LOG_DEBUG(("Ignoring sender's own ID"));
1936 /* Check that we do not have this server already */
1937 entry = silc_idlist_find_server_by_id(server->global_list,
1938 id, server->server_type,
1941 entry = silc_idlist_find_server_by_id(server->local_list,
1942 id, server->server_type,
1945 SILC_LOG_DEBUG(("Ignoring server that we already have"));
1949 SILC_LOG_DEBUG(("New server id(%s) from [%s] %s",
1950 silc_id_render(id, SILC_ID_SERVER),
1951 sock->type == SILC_SOCKET_TYPE_SERVER ?
1952 "Server" : "Router", sock->hostname));
1954 /* As a router we keep information of all global information in our
1955 global list. Cell wide information however is kept in the local
1957 entry = silc_idlist_add_server(id_list, NULL, 0, id, router,
1960 SILC_LOG_ERROR(("Could not add new server to the ID Cache"));
1963 entry->data.status |= SILC_IDLIST_STATUS_REGISTERED;
1965 if (sock->type == SILC_SOCKET_TYPE_SERVER)
1966 server->stat.cell_servers++;
1967 server->stat.servers++;
1971 case SILC_ID_CHANNEL:
1972 SILC_LOG_ERROR(("Channel cannot be registered with NEW_ID packet"));
1981 /* If the sender of this packet is server and we are router we need to
1982 broadcast this packet to other routers in the network. */
1983 if (broadcast && !server->standalone && server->server_type == SILC_ROUTER &&
1984 sock->type == SILC_SOCKET_TYPE_SERVER &&
1985 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
1986 SILC_LOG_DEBUG(("Broadcasting received New ID packet"));
1987 silc_server_packet_send(server, server->router->connection,
1989 packet->flags | SILC_PACKET_FLAG_BROADCAST,
1990 buffer->data, buffer->len, FALSE);
1991 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
1992 packet->type, packet->flags,
1993 packet->buffer->data, packet->buffer->len,
1998 silc_id_payload_free(idp);
2002 /* Processes incoming New ID packet. New ID Payload is used to distribute
2003 information about newly registered clients and servers. */
2005 void silc_server_new_id(SilcServer server, SilcSocketConnection sock,
2006 SilcPacketContext *packet)
2008 silc_server_new_id_real(server, sock, packet, TRUE);
2011 /* Receoved New Id List packet, list of New ID payloads inside one
2012 packet. Process the New ID payloads one by one. */
2014 void silc_server_new_id_list(SilcServer server, SilcSocketConnection sock,
2015 SilcPacketContext *packet)
2017 SilcPacketContext *new_id;
2021 SILC_LOG_DEBUG(("Processing New ID List"));
2023 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2024 packet->src_id_type != SILC_ID_SERVER)
2027 /* If the sender of this packet is server and we are router we need to
2028 broadcast this packet to other routers in the network. Broadcast
2029 this list packet instead of multiple New ID packets. */
2030 if (!server->standalone && server->server_type == SILC_ROUTER &&
2031 sock->type == SILC_SOCKET_TYPE_SERVER &&
2032 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2033 SILC_LOG_DEBUG(("Broadcasting received New ID List packet"));
2034 silc_server_packet_send(server, server->router->connection,
2036 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2037 packet->buffer->data, packet->buffer->len, FALSE);
2038 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2039 packet->type, packet->flags,
2040 packet->buffer->data, packet->buffer->len,
2044 /* Make copy of the original packet context, except for the actual
2045 data buffer, which we will here now fetch from the original buffer. */
2046 new_id = silc_packet_context_alloc();
2047 new_id->type = SILC_PACKET_NEW_ID;
2048 new_id->flags = packet->flags;
2049 new_id->src_id = packet->src_id;
2050 new_id->src_id_len = packet->src_id_len;
2051 new_id->src_id_type = packet->src_id_type;
2052 new_id->dst_id = packet->dst_id;
2053 new_id->dst_id_len = packet->dst_id_len;
2054 new_id->dst_id_type = packet->dst_id_type;
2056 idp = silc_buffer_alloc(256);
2057 new_id->buffer = idp;
2059 while (packet->buffer->len) {
2060 SILC_GET16_MSB(id_len, packet->buffer->data + 2);
2061 if ((id_len > packet->buffer->len) ||
2062 (id_len > idp->truelen))
2065 silc_buffer_pull_tail(idp, 4 + id_len);
2066 silc_buffer_put(idp, packet->buffer->data, 4 + id_len);
2068 /* Process the New ID */
2069 silc_server_new_id_real(server, sock, new_id, FALSE);
2071 silc_buffer_push_tail(idp, 4 + id_len);
2072 silc_buffer_pull(packet->buffer, 4 + id_len);
2075 silc_buffer_free(idp);
2079 /* Received New Channel packet. Information about new channels in the
2080 network are distributed using this packet. Save the information about
2081 the new channel. This usually comes from router but also normal server
2082 can send this to notify channels it has when it connects to us. */
2084 void silc_server_new_channel(SilcServer server,
2085 SilcSocketConnection sock,
2086 SilcPacketContext *packet)
2088 SilcChannelPayload payload;
2089 SilcChannelID *channel_id;
2095 SilcServerEntry server_entry;
2096 SilcChannelEntry channel;
2098 SILC_LOG_DEBUG(("Processing New Channel"));
2100 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2101 packet->src_id_type != SILC_ID_SERVER ||
2102 server->server_type == SILC_SERVER)
2105 /* Parse the channel payload */
2106 payload = silc_channel_payload_parse(packet->buffer);
2110 /* Get the channel ID */
2111 channel_id = silc_channel_get_id_parse(payload);
2113 silc_channel_payload_free(payload);
2117 channel_name = silc_channel_get_name(payload, &name_len);
2119 channel_name[255] = '\0';
2121 id = silc_channel_get_id(payload, &id_len);
2123 server_entry = (SilcServerEntry)sock->user_data;
2125 if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
2126 /* Add the channel to global list as it is coming from router. It
2127 cannot be our own channel as it is coming from router. */
2129 /* Check that we don't already have this channel */
2130 channel = silc_idlist_find_channel_by_name(server->local_list,
2131 channel_name, NULL);
2133 channel = silc_idlist_find_channel_by_name(server->global_list,
2134 channel_name, NULL);
2136 SILC_LOG_DEBUG(("New channel id(%s) from [Router] %s",
2137 silc_id_render(channel_id, SILC_ID_CHANNEL),
2140 silc_idlist_add_channel(server->global_list, strdup(channel_name),
2141 0, channel_id, sock->user_data, NULL, NULL);
2142 server->stat.channels++;
2145 /* The channel is coming from our server, thus it is in our cell
2146 we will add it to our local list. */
2149 SILC_LOG_DEBUG(("Channel id(%s) from [Server] %s",
2150 silc_id_render(channel_id, SILC_ID_CHANNEL),
2153 /* Check that we don't already have this channel */
2154 channel = silc_idlist_find_channel_by_name(server->local_list,
2155 channel_name, NULL);
2157 channel = silc_idlist_find_channel_by_name(server->global_list,
2158 channel_name, NULL);
2160 /* If the channel does not exist, then create it. This creates a new
2161 key to the channel as well that we will send to the server. */
2163 /* The protocol says that the Channel ID's IP address must be based
2164 on the router's IP address. Check whether the ID is based in our
2165 IP and if it is not then create a new ID and enforce the server
2166 to switch the ID. */
2167 if (server_entry->server_type != SILC_BACKUP_ROUTER &&
2168 !SILC_ID_COMPARE(channel_id, server->id, server->id->ip.data_len)) {
2170 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2172 if (silc_id_create_channel_id(server, server->id, server->rng, &tmp)) {
2173 silc_server_send_notify_channel_change(server, sock, FALSE,
2175 silc_free(channel_id);
2180 /* Create the channel with the provided Channel ID */
2181 channel = silc_server_create_new_channel_with_id(server, NULL, NULL,
2185 silc_channel_payload_free(payload);
2186 silc_free(channel_id);
2190 /* Get the mode and set it to the channel */
2191 channel->mode = silc_channel_get_mode(payload);
2193 /* Send the new channel key to the server */
2194 chk = silc_channel_key_payload_encode(id_len, id,
2195 strlen(channel->channel_key->
2197 channel->channel_key->cipher->name,
2198 channel->key_len / 8,
2200 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2201 chk->data, chk->len, FALSE);
2202 silc_buffer_free(chk);
2205 /* The channel exist by that name, check whether the ID's match.
2206 If they don't then we'll force the server to use the ID we have.
2207 We also create a new key for the channel. */
2208 SilcBuffer users = NULL, users_modes = NULL;
2210 if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) {
2211 /* They don't match, send CHANNEL_CHANGE notify to the server to
2212 force the ID change. */
2213 SILC_LOG_DEBUG(("Forcing the server to change Channel ID"));
2214 silc_server_send_notify_channel_change(server, sock, FALSE,
2215 channel_id, channel->id);
2218 /* If the mode is different from what we have then enforce the
2220 mode = silc_channel_get_mode(payload);
2221 if (channel->mode != mode) {
2222 SILC_LOG_DEBUG(("Forcing the server to change channel mode"));
2223 silc_server_send_notify_cmode(server, sock, FALSE, channel,
2224 channel->mode, server->id,
2226 channel->cipher, channel->hmac_name);
2229 /* Create new key for the channel and send it to the server and
2230 everybody else possibly on the channel. */
2232 if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
2233 if (!silc_server_create_channel_key(server, channel, 0))
2236 /* Send to the channel */
2237 silc_server_send_channel_key(server, sock, channel, FALSE);
2238 id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
2239 id_len = SILC_ID_CHANNEL_LEN;
2241 /* Send to the server */
2242 chk = silc_channel_key_payload_encode(id_len, id,
2243 strlen(channel->channel_key->
2245 channel->channel_key->
2247 channel->key_len / 8,
2249 silc_server_packet_send(server, sock, SILC_PACKET_CHANNEL_KEY, 0,
2250 chk->data, chk->len, FALSE);
2251 silc_buffer_free(chk);
2255 silc_free(channel_id);
2257 /* Since the channel is coming from server and we also know about it
2258 then send the JOIN notify to the server so that it see's our
2259 users on the channel "joining" the channel. */
2260 silc_server_announce_get_channel_users(server, channel, &users,
2263 silc_buffer_push(users, users->data - users->head);
2264 silc_server_packet_send(server, sock,
2265 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2266 users->data, users->len, FALSE);
2267 silc_buffer_free(users);
2270 silc_buffer_push(users_modes, users_modes->data - users_modes->head);
2271 silc_server_packet_send_dest(server, sock,
2272 SILC_PACKET_NOTIFY, SILC_PACKET_FLAG_LIST,
2273 channel->id, SILC_ID_CHANNEL,
2275 users_modes->len, FALSE);
2276 silc_buffer_free(users_modes);
2281 silc_channel_payload_free(payload);
2284 /* Received New Channel List packet, list of New Channel List payloads inside
2285 one packet. Process the New Channel payloads one by one. */
2287 void silc_server_new_channel_list(SilcServer server,
2288 SilcSocketConnection sock,
2289 SilcPacketContext *packet)
2291 SilcPacketContext *new;
2295 SILC_LOG_DEBUG(("Processing New Channel List"));
2297 if (sock->type == SILC_SOCKET_TYPE_CLIENT ||
2298 packet->src_id_type != SILC_ID_SERVER ||
2299 server->server_type == SILC_SERVER)
2302 /* If the sender of this packet is server and we are router we need to
2303 broadcast this packet to other routers in the network. Broadcast
2304 this list packet instead of multiple New Channel packets. */
2305 if (!server->standalone && server->server_type == SILC_ROUTER &&
2306 sock->type == SILC_SOCKET_TYPE_SERVER &&
2307 !(packet->flags & SILC_PACKET_FLAG_BROADCAST)) {
2308 SILC_LOG_DEBUG(("Broadcasting received New Channel List packet"));
2309 silc_server_packet_send(server, server->router->connection,
2311 packet->flags | SILC_PACKET_FLAG_BROADCAST,
2312 packet->buffer->data, packet->buffer->len, FALSE);
2313 silc_server_backup_send(server, (SilcServerEntry)sock->user_data,
2314 packet->type, packet->flags,
2315 packet->buffer->data, packet->buffer->len,
2319 /* Make copy of the original packet context, except for the actual
2320 data buffer, which we will here now fetch from the original buffer. */
2321 new = silc_packet_context_alloc();
2322 new->type = SILC_PACKET_NEW_CHANNEL;
2323 new->flags = packet->flags;
2324 new->src_id = packet->src_id;
2325 new->src_id_len = packet->src_id_len;
2326 new->src_id_type = packet->src_id_type;
2327 new->dst_id = packet->dst_id;
2328 new->dst_id_len = packet->dst_id_len;
2329 new->dst_id_type = packet->dst_id_type;
2331 buffer = silc_buffer_alloc(512);
2332 new->buffer = buffer;
2334 while (packet->buffer->len) {
2335 SILC_GET16_MSB(len1, packet->buffer->data);
2336 if ((len1 > packet->buffer->len) ||
2337 (len1 > buffer->truelen))
2340 SILC_GET16_MSB(len2, packet->buffer->data + 2 + len1);
2341 if ((len2 > packet->buffer->len) ||
2342 (len2 > buffer->truelen))
2345 silc_buffer_pull_tail(buffer, 8 + len1 + len2);
2346 silc_buffer_put(buffer, packet->buffer->data, 8 + len1 + len2);
2348 /* Process the New Channel */
2349 silc_server_new_channel(server, sock, new);
2351 silc_buffer_push_tail(buffer, 8 + len1 + len2);
2352 silc_buffer_pull(packet->buffer, 8 + len1 + len2);
2355 silc_buffer_free(buffer);
2359 /* Received key agreement packet. This packet is never for us. It is to
2360 the client in the packet's destination ID. Sending of this sort of packet
2361 equals sending private message, ie. it is sent point to point from
2362 one client to another. */
2364 void silc_server_key_agreement(SilcServer server,
2365 SilcSocketConnection sock,
2366 SilcPacketContext *packet)
2368 SilcSocketConnection dst_sock;
2369 SilcIDListData idata;
2371 SILC_LOG_DEBUG(("Start"));
2373 if (packet->src_id_type != SILC_ID_CLIENT ||
2374 packet->dst_id_type != SILC_ID_CLIENT)
2377 if (!packet->dst_id)
2380 /* Get the route to the client */
2381 dst_sock = silc_server_get_client_route(server, packet->dst_id,
2382 packet->dst_id_len, NULL, &idata);
2386 /* Relay the packet */
2387 silc_server_relay_packet(server, dst_sock, idata->send_key,
2388 idata->hmac_send, idata->psn_send++,
2392 /* Received connection auth request packet that is used during connection
2393 phase to resolve the mandatory authentication method. This packet can
2394 actually be received at anytime but usually it is used only during
2395 the connection authentication phase. Now, protocol says that this packet
2396 can come from client or server, however, we support only this coming
2397 from client and expect that server always knows what authentication
2400 void silc_server_connection_auth_request(SilcServer server,
2401 SilcSocketConnection sock,
2402 SilcPacketContext *packet)
2404 SilcServerConfigSectionClientConnection *client = NULL;
2407 SilcAuthMethod auth_meth;
2409 SILC_LOG_DEBUG(("Start"));
2411 if (packet->src_id_type && packet->src_id_type != SILC_ID_CLIENT)
2414 /* Parse the payload */
2415 ret = silc_buffer_unformat(packet->buffer,
2416 SILC_STR_UI_SHORT(&conn_type),
2417 SILC_STR_UI_SHORT(NULL),
2422 if (conn_type != SILC_SOCKET_TYPE_CLIENT)
2425 /* Get the authentication method for the client */
2426 auth_meth = SILC_AUTH_NONE;
2427 port = server->sockets[server->sock]->port; /* Listenning port */
2428 client = silc_server_config_find_client_conn(server->config,
2432 client = silc_server_config_find_client_conn(server->config,
2436 auth_meth = client->auth_meth;
2438 /* Send it back to the client */
2439 silc_server_send_connection_auth_request(server, sock,
2444 /* Received REKEY packet. The sender of the packet wants to regenerate
2445 its session keys. This starts the REKEY protocol. */
2447 void silc_server_rekey(SilcServer server,
2448 SilcSocketConnection sock,
2449 SilcPacketContext *packet)
2451 SilcProtocol protocol;
2452 SilcServerRekeyInternalContext *proto_ctx;
2453 SilcIDListData idata = (SilcIDListData)sock->user_data;
2455 SILC_LOG_DEBUG(("Start"));
2457 /* Allocate internal protocol context. This is sent as context
2459 proto_ctx = silc_calloc(1, sizeof(*proto_ctx));
2460 proto_ctx->server = (void *)server;
2461 proto_ctx->sock = sock;
2462 proto_ctx->responder = TRUE;
2463 proto_ctx->pfs = idata->rekey->pfs;
2465 /* Perform rekey protocol. Will call the final callback after the
2466 protocol is over. */
2467 silc_protocol_alloc(SILC_PROTOCOL_SERVER_REKEY,
2468 &protocol, proto_ctx, silc_server_rekey_final);
2469 sock->protocol = protocol;
2471 if (proto_ctx->pfs == FALSE)
2472 /* Run the protocol */
2473 silc_protocol_execute(protocol, server->schedule, 0, 0);
2476 /* Received file transger packet. This packet is never for us. It is to
2477 the client in the packet's destination ID. Sending of this sort of packet
2478 equals sending private message, ie. it is sent point to point from
2479 one client to another. */
2481 void silc_server_ftp(SilcServer server,
2482 SilcSocketConnection sock,
2483 SilcPacketContext *packet)
2485 SilcSocketConnection dst_sock;
2486 SilcIDListData idata;
2488 SILC_LOG_DEBUG(("Start"));
2490 if (packet->src_id_type != SILC_ID_CLIENT ||
2491 packet->dst_id_type != SILC_ID_CLIENT)
2494 if (!packet->dst_id)
2497 /* Get the route to the client */
2498 dst_sock = silc_server_get_client_route(server, packet->dst_id,
2499 packet->dst_id_len, NULL, &idata);
2503 /* Relay the packet */
2504 silc_server_relay_packet(server, dst_sock, idata->send_key,
2505 idata->hmac_send, idata->psn_send++,