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 send packets.
25 #include "serverincludes.h"
26 #include "server_internal.h"
28 /* Routine that sends packet or marks packet to be sent. This is used
29 directly only in special cases. Normal cases should use
30 silc_server_packet_send. Returns < 0 error. */
32 int silc_server_packet_send_real(SilcServer server,
33 SilcSocketConnection sock,
39 ret = silc_packet_send(sock, force_send);
43 /* Mark that there is some outgoing data available for this connection.
44 This call sets the connection both for input and output (the input
45 is set always and this call keeps the input setting, actually).
46 Actual data sending is performed by silc_server_packet_process. */
47 SILC_SET_CONNECTION_FOR_OUTPUT(sock->sock);
49 /* Mark to socket that data is pending in outgoing buffer. This flag
50 is needed if new data is added to the buffer before the earlier
51 put data is sent to the network. */
52 SILC_SET_OUTBUF_PENDING(sock);
57 /* Assembles a new packet to be sent out to network. This doesn't actually
58 send the packet but creates the packet and fills the outgoing data
59 buffer and marks the packet ready to be sent to network. However, If
60 argument force_send is TRUE the packet is sent immediately and not put
61 to queue. Normal case is that the packet is not sent immediately. */
63 void silc_server_packet_send(SilcServer server,
64 SilcSocketConnection sock,
66 SilcPacketFlags flags,
68 unsigned int data_len,
72 SilcIdType dst_id_type = SILC_ID_NONE;
77 /* Get data used in the packet sending, keys and stuff */
79 case SILC_SOCKET_TYPE_CLIENT:
80 dst_id = ((SilcClientEntry)sock->user_data)->id;
81 dst_id_type = SILC_ID_CLIENT;
83 case SILC_SOCKET_TYPE_SERVER:
84 case SILC_SOCKET_TYPE_ROUTER:
85 dst_id = ((SilcServerEntry)sock->user_data)->id;
86 dst_id_type = SILC_ID_SERVER;
92 silc_server_packet_send_dest(server, sock, type, flags, dst_id,
93 dst_id_type, data, data_len, force_send);
96 /* Assembles a new packet to be sent out to network. This doesn't actually
97 send the packet but creates the packet and fills the outgoing data
98 buffer and marks the packet ready to be sent to network. However, If
99 argument force_send is TRUE the packet is sent immediately and not put
100 to queue. Normal case is that the packet is not sent immediately.
101 Destination information is sent as argument for this function. */
103 void silc_server_packet_send_dest(SilcServer server,
104 SilcSocketConnection sock,
106 SilcPacketFlags flags,
108 SilcIdType dst_id_type,
110 unsigned int data_len,
113 SilcPacketContext packetdata;
114 SilcIDListData idata;
115 SilcCipher cipher = NULL;
116 SilcHmac hmac = NULL;
117 unsigned char *dst_id_data = NULL;
118 unsigned int dst_id_len = 0;
120 SILC_LOG_DEBUG(("Sending packet, type %d", type));
122 /* Get data used in the packet sending, keys and stuff */
123 idata = (SilcIDListData)sock->user_data;
126 dst_id_data = silc_id_id2str(dst_id, dst_id_type);
127 dst_id_len = silc_id_get_len(dst_id_type);
130 /* Set the packet context pointers */
131 packetdata.type = type;
132 packetdata.flags = flags;
133 packetdata.src_id = silc_id_id2str(server->id, server->id_type);
134 packetdata.src_id_len = SILC_ID_SERVER_LEN;
135 packetdata.src_id_type = server->id_type;
136 packetdata.dst_id = dst_id_data;
137 packetdata.dst_id_len = dst_id_len;
138 packetdata.dst_id_type = dst_id_type;
139 packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
140 packetdata.src_id_len + dst_id_len;
141 packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen);
143 /* Prepare outgoing data buffer for packet sending */
144 silc_packet_send_prepare(sock,
145 SILC_PACKET_HEADER_LEN +
146 packetdata.src_id_len +
147 packetdata.dst_id_len,
151 SILC_LOG_DEBUG(("Putting data to outgoing buffer, len %d", data_len));
153 packetdata.buffer = sock->outbuf;
155 /* Put the data to the buffer */
156 if (data && data_len)
157 silc_buffer_put(sock->outbuf, data, data_len);
159 /* Create the outgoing packet */
160 silc_packet_assemble(&packetdata);
163 cipher = idata->send_key;
167 /* Encrypt the packet */
168 silc_packet_encrypt(cipher, hmac, sock->outbuf, sock->outbuf->len);
170 SILC_LOG_HEXDUMP(("Outgoing packet, len %d", sock->outbuf->len),
171 sock->outbuf->data, sock->outbuf->len);
173 /* Now actually send the packet */
174 silc_server_packet_send_real(server, sock, force_send);
176 if (packetdata.src_id)
177 silc_free(packetdata.src_id);
178 if (packetdata.dst_id)
179 silc_free(packetdata.dst_id);
182 /* Assembles a new packet to be sent out to network. This doesn't actually
183 send the packet but creates the packet and fills the outgoing data
184 buffer and marks the packet ready to be sent to network. However, If
185 argument force_send is TRUE the packet is sent immediately and not put
186 to queue. Normal case is that the packet is not sent immediately.
187 The source and destination information is sent as argument for this
190 void silc_server_packet_send_srcdest(SilcServer server,
191 SilcSocketConnection sock,
193 SilcPacketFlags flags,
195 SilcIdType src_id_type,
197 SilcIdType dst_id_type,
199 unsigned int data_len,
202 SilcPacketContext packetdata;
203 SilcIDListData idata;
204 SilcCipher cipher = NULL;
205 SilcHmac hmac = NULL;
206 unsigned char *dst_id_data = NULL;
207 unsigned int dst_id_len = 0;
208 unsigned char *src_id_data = NULL;
209 unsigned int src_id_len = 0;
211 SILC_LOG_DEBUG(("Sending packet, type %d", type));
213 /* Get data used in the packet sending, keys and stuff */
214 idata = (SilcIDListData)sock->user_data;
217 dst_id_data = silc_id_id2str(dst_id, dst_id_type);
218 dst_id_len = silc_id_get_len(dst_id_type);
222 src_id_data = silc_id_id2str(src_id, src_id_type);
223 src_id_len = silc_id_get_len(src_id_type);
226 /* Set the packet context pointers */
227 packetdata.type = type;
228 packetdata.flags = flags;
229 packetdata.src_id = src_id_data;
230 packetdata.src_id_len = src_id_len;
231 packetdata.src_id_type = src_id_type;
232 packetdata.dst_id = dst_id_data;
233 packetdata.dst_id_len = dst_id_len;
234 packetdata.dst_id_type = dst_id_type;
235 packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
236 packetdata.src_id_len + dst_id_len;
237 packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen);
239 /* Prepare outgoing data buffer for packet sending */
240 silc_packet_send_prepare(sock,
241 SILC_PACKET_HEADER_LEN +
242 packetdata.src_id_len +
243 packetdata.dst_id_len,
247 SILC_LOG_DEBUG(("Putting data to outgoing buffer, len %d", data_len));
249 packetdata.buffer = sock->outbuf;
251 /* Put the data to the buffer */
252 if (data && data_len)
253 silc_buffer_put(sock->outbuf, data, data_len);
255 /* Create the outgoing packet */
256 silc_packet_assemble(&packetdata);
259 cipher = idata->send_key;
263 /* Encrypt the packet */
264 silc_packet_encrypt(cipher, hmac, sock->outbuf, sock->outbuf->len);
266 SILC_LOG_HEXDUMP(("Outgoing packet, len %d", sock->outbuf->len),
267 sock->outbuf->data, sock->outbuf->len);
269 /* Now actually send the packet */
270 silc_server_packet_send_real(server, sock, force_send);
272 if (packetdata.src_id)
273 silc_free(packetdata.src_id);
274 if (packetdata.dst_id)
275 silc_free(packetdata.dst_id);
278 /* Broadcast received packet to our primary route. This function is used
279 by router to further route received broadcast packet. It is expected
280 that the broadcast flag from the packet is checked before calling this
281 function. This does not test or set the broadcast flag. */
283 void silc_server_packet_broadcast(SilcServer server,
284 SilcSocketConnection sock,
285 SilcPacketContext *packet)
287 SilcBuffer buffer = packet->buffer;
288 SilcIDListData idata;
291 SILC_LOG_DEBUG(("Broadcasting received broadcast packet"));
293 /* If the packet is originated from our primary route we are
294 not allowed to send the packet. */
295 id = silc_id_str2id(packet->src_id, packet->src_id_len, packet->src_id_type);
296 if (id && SILC_ID_SERVER_COMPARE(id, server->router->id)) {
297 idata = (SilcIDListData)sock->user_data;
299 silc_buffer_push(buffer, buffer->data - buffer->head);
300 silc_packet_send_prepare(sock, 0, 0, buffer->len);
301 silc_buffer_put(sock->outbuf, buffer->data, buffer->len);
302 silc_packet_encrypt(idata->send_key, idata->hmac,
303 sock->outbuf, sock->outbuf->len);
305 SILC_LOG_HEXDUMP(("Broadcasted packet, len %d", sock->outbuf->len),
306 sock->outbuf->data, sock->outbuf->len);
308 /* Now actually send the packet */
309 silc_server_packet_send_real(server, sock, TRUE);
314 SILC_LOG_DEBUG(("Will not broadcast to primary route since it is the "
315 "original sender of this packet"));
319 /* Routes received packet to `sock'. This is used to route the packets that
320 router receives but are not destined to it. */
322 void silc_server_packet_route(SilcServer server,
323 SilcSocketConnection sock,
324 SilcPacketContext *packet)
326 SilcBuffer buffer = packet->buffer;
327 SilcIDListData idata;
329 SILC_LOG_DEBUG(("Routing received packet"));
331 idata = (SilcIDListData)sock->user_data;
333 silc_buffer_push(buffer, buffer->data - buffer->head);
334 silc_packet_send_prepare(sock, 0, 0, buffer->len);
335 silc_buffer_put(sock->outbuf, buffer->data, buffer->len);
336 silc_packet_encrypt(idata->send_key, idata->hmac,
337 sock->outbuf, sock->outbuf->len);
339 SILC_LOG_HEXDUMP(("Routed packet, len %d", sock->outbuf->len),
340 sock->outbuf->data, sock->outbuf->len);
342 /* Now actually send the packet */
343 silc_server_packet_send_real(server, sock, TRUE);
346 /* Internal routine to actually create the channel packet and send it
347 to network. This is common function in channel message sending. If
348 `channel_message' is TRUE this encrypts the message as it is strictly
349 a channel message. If FALSE normal encryption process is used. */
352 silc_server_packet_send_to_channel_real(SilcServer server,
353 SilcSocketConnection sock,
354 SilcPacketContext *packet,
358 unsigned int data_len,
362 packet->truelen = data_len + SILC_PACKET_HEADER_LEN +
363 packet->src_id_len + packet->dst_id_len;
365 /* Prepare outgoing data buffer for packet sending */
366 silc_packet_send_prepare(sock,
367 SILC_PACKET_HEADER_LEN +
373 packet->buffer = sock->outbuf;
375 /* Put the data to buffer, assemble and encrypt the packet. The packet
376 is encrypted with normal session key shared with the client. */
377 silc_buffer_put(sock->outbuf, data, data_len);
378 silc_packet_assemble(packet);
380 silc_packet_encrypt(cipher, hmac, sock->outbuf, SILC_PACKET_HEADER_LEN +
381 packet->src_id_len + packet->dst_id_len +
384 silc_packet_encrypt(cipher, hmac, sock->outbuf, sock->outbuf->len);
386 SILC_LOG_HEXDUMP(("Channel packet, len %d", sock->outbuf->len),
387 sock->outbuf->data, sock->outbuf->len);
389 /* Now actually send the packet */
390 silc_server_packet_send_real(server, sock, force_send);
393 /* This routine is used by the server to send packets to channel. The
394 packet sent with this function is distributed to all clients on
395 the channel. Usually this is used to send notify messages to the
396 channel, things like notify about new user joining to the channel.
397 If `route' is FALSE then the packet is sent only locally and will not
398 be routed anywhere (for router locally means cell wide). If `sender'
399 is provided then the packet is not sent to that connection since it
400 originally came from it. */
402 void silc_server_packet_send_to_channel(SilcServer server,
403 SilcSocketConnection sender,
404 SilcChannelEntry channel,
408 unsigned int data_len,
411 SilcSocketConnection sock = NULL;
412 SilcPacketContext packetdata;
413 SilcClientEntry client = NULL;
414 SilcServerEntry *routed = NULL;
415 SilcChannelClientEntry chl;
416 SilcIDListData idata;
417 unsigned int routed_count = 0;
419 /* This doesn't send channel message packets */
420 if (type == SILC_PACKET_CHANNEL_MESSAGE)
423 SILC_LOG_DEBUG(("Sending packet to channel"));
425 /* Set the packet context pointers. */
426 packetdata.flags = 0;
427 packetdata.type = type;
428 packetdata.src_id = silc_id_id2str(server->id, SILC_ID_SERVER);
429 packetdata.src_id_len = SILC_ID_SERVER_LEN;
430 packetdata.src_id_type = SILC_ID_SERVER;
431 packetdata.dst_id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
432 packetdata.dst_id_len = SILC_ID_CHANNEL_LEN;
433 packetdata.dst_id_type = SILC_ID_CHANNEL;
434 packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
435 packetdata.src_id_len + packetdata.dst_id_len;
436 packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen);
438 /* If there are global users in the channel we will send the message
439 first to our router for further routing. */
440 if (route && server->server_type == SILC_SERVER && !server->standalone &&
441 channel->global_users) {
442 SilcServerEntry router;
444 /* Get data used in packet header encryption, keys and stuff. */
445 router = server->router;
446 sock = (SilcSocketConnection)router->connection;
447 idata = (SilcIDListData)router;
449 if (sock != sender) {
450 SILC_LOG_DEBUG(("Sending channel message to router for routing"));
452 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
453 idata->send_key, idata->hmac,
454 data, data_len, FALSE,
459 /* Send the message to clients on the channel's client list. */
460 silc_list_start(channel->user_list);
461 while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) {
462 client = chl->client;
464 /* If client has router set it is not locally connected client and
465 we will route the message to the router set in the client. Though,
466 send locally connected server in all cases. */
467 if (server->server_type == SILC_ROUTER && client && client->router &&
468 ((!route && client->router->router == server->id_entry) || route)) {
471 /* Check if we have sent the packet to this route already */
472 for (k = 0; k < routed_count; k++)
473 if (routed[k] == client->router)
475 if (k < routed_count)
478 /* Get data used in packet header encryption, keys and stuff. */
479 sock = (SilcSocketConnection)client->router->connection;
480 idata = (SilcIDListData)client->router;
482 if (sender && sock == sender)
485 /* Send the packet */
486 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
487 idata->send_key, idata->hmac,
488 data, data_len, FALSE,
491 /* We want to make sure that the packet is routed to same router
492 only once. Mark this route as sent route. */
494 routed = silc_realloc(routed, sizeof(*routed) * (k + 1));
495 routed[k] = client->router;
501 if (client && client->router)
504 /* Send to locally connected client */
507 /* Get data used in packet header encryption, keys and stuff. */
508 sock = (SilcSocketConnection)client->connection;
509 idata = (SilcIDListData)client;
511 if (sender && sock == sender)
514 /* Send the packet */
515 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
516 idata->send_key, idata->hmac,
517 data, data_len, FALSE,
524 silc_free(packetdata.src_id);
525 silc_free(packetdata.dst_id);
528 /* This routine is explicitly used to relay messages to some channel.
529 Packets sent with this function we have received earlier and are
530 totally encrypted. This just sends the packet to all clients on
531 the channel. If the sender of the packet is someone on the channel
532 the message will not be sent to that client. The SILC Packet header
533 is encrypted with the session key shared between us and the client.
534 MAC is also computed before encrypting the header. Rest of the
535 packet will be untouched. */
537 void silc_server_packet_relay_to_channel(SilcServer server,
538 SilcSocketConnection sender_sock,
539 SilcChannelEntry channel,
541 SilcIdType sender_type,
543 unsigned int data_len,
547 SilcSocketConnection sock = NULL;
548 SilcPacketContext packetdata;
549 SilcClientEntry client = NULL;
550 SilcServerEntry *routed = NULL;
551 SilcChannelClientEntry chl;
552 unsigned int routed_count = 0;
553 SilcIDListData idata;
555 SILC_LOG_DEBUG(("Relaying packet to channel"));
557 /* Set the packet context pointers. */
558 packetdata.flags = 0;
559 packetdata.type = SILC_PACKET_CHANNEL_MESSAGE;
560 packetdata.src_id = silc_id_id2str(sender, sender_type);
561 packetdata.src_id_len = silc_id_get_len(sender_type);
562 packetdata.src_id_type = sender_type;
563 packetdata.dst_id = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
564 packetdata.dst_id_len = SILC_ID_CHANNEL_LEN;
565 packetdata.dst_id_type = SILC_ID_CHANNEL;
566 packetdata.padlen = SILC_PACKET_PADLEN((SILC_PACKET_HEADER_LEN +
567 packetdata.src_id_len +
568 packetdata.dst_id_len));
570 /* If there are global users in the channel we will send the message
571 first to our router for further routing. */
572 if (server->server_type == SILC_SERVER && !server->standalone &&
573 channel->global_users) {
574 SilcServerEntry router;
576 router = server->router;
578 /* Check that the sender is not our router. */
579 if (sender_sock != (SilcSocketConnection)router->connection) {
581 /* Get data used in packet header encryption, keys and stuff. */
582 sock = (SilcSocketConnection)router->connection;
583 idata = (SilcIDListData)router;
585 SILC_LOG_DEBUG(("Sending channel message to router for routing"));
587 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
588 idata->send_key, idata->hmac,
589 data, data_len, TRUE,
594 /* Send the message to clients on the channel's client list. */
595 silc_list_start(channel->user_list);
596 while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) {
597 client = chl->client;
601 /* If sender is one on the channel do not send it the packet. */
602 if (!found && !SILC_ID_CLIENT_COMPARE(client->id, sender)) {
607 /* If the client has set router it means that it is not locally
608 connected client and we will route the packet further. */
609 if (server->server_type == SILC_ROUTER && client->router) {
612 /* Sender maybe server as well so we want to make sure that
613 we won't send the message to the server it came from. */
614 if (!found && !SILC_ID_SERVER_COMPARE(client->router->id, sender)) {
619 /* Check if we have sent the packet to this route already */
620 for (k = 0; k < routed_count; k++)
621 if (routed[k] == client->router)
623 if (k < routed_count)
626 /* Get data used in packet header encryption, keys and stuff. */
627 sock = (SilcSocketConnection)client->router->connection;
628 idata = (SilcIDListData)client->router;
630 if (sender_sock && sock == sender_sock)
633 SILC_LOG_DEBUG(("Relaying packet to client ID(%s) %s (%s)",
634 silc_id_render(client->id, SILC_ID_CLIENT),
635 sock->hostname, sock->ip));
637 /* We want to make sure that the packet is routed to same router
638 only once. Mark this route as sent route. */
640 routed = silc_realloc(routed, sizeof(*routed) * (k + 1));
641 routed[k] = client->router;
644 /* If the remote connection is router then we'll decrypt the
645 channel message and re-encrypt it with the session key shared
646 between us and the remote router. This is done because the
647 channel keys are cell specific and we have different channel
648 key than the remote router has. */
649 if (sock->type == SILC_SOCKET_TYPE_ROUTER) {
651 /* If private key mode is not set then decrypt the packet
653 if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) {
654 unsigned char *tmp = silc_calloc(data_len, sizeof(*data));
655 memcpy(tmp, data, data_len);
657 /* Decrypt the channel message (we don't check the MAC) */
658 if (!silc_channel_message_payload_decrypt(tmp, data_len,
659 channel->channel_key,
661 memset(tmp, 0, data_len);
666 /* Now re-encrypt and send it to the router */
667 silc_server_packet_send_srcdest(server, sock,
668 SILC_PACKET_CHANNEL_MESSAGE, 0,
670 channel->id, SILC_ID_CHANNEL,
671 tmp, data_len, force_send);
673 /* Free the copy of the channel message */
674 memset(tmp, 0, data_len);
677 /* Private key mode is set, we don't have the channel key, so
678 just re-encrypt the entire packet and send it to the router. */
679 silc_server_packet_send_dest(server, sock,
680 SILC_PACKET_CHANNEL_MESSAGE, 0,
681 channel->id, SILC_ID_CHANNEL,
682 data, data_len, force_send);
687 /* Send the packet (to normal server) */
688 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
689 idata->send_key, idata->hmac,
690 data, data_len, TRUE,
696 if (client && client->router)
699 /* Get data used in packet header encryption, keys and stuff. */
700 sock = (SilcSocketConnection)client->connection;
701 idata = (SilcIDListData)client;
703 if (sender_sock && sock == sender_sock)
706 SILC_LOG_DEBUG(("Sending packet to client ID(%s) %s (%s)",
707 silc_id_render(client->id, SILC_ID_CLIENT),
708 sock->hostname, sock->ip));
710 /* Send the packet */
711 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
712 idata->send_key, idata->hmac,
713 data, data_len, TRUE,
718 silc_free(packetdata.src_id);
719 silc_free(packetdata.dst_id);
722 /* This function is used to send packets strictly to all local clients
723 on a particular channel. This is used for example to distribute new
724 channel key to all our locally connected clients on the channel.
725 The packets are always encrypted with the session key shared between
726 the client, this means these are not _to the channel_ but _to the client_
729 void silc_server_packet_send_local_channel(SilcServer server,
730 SilcChannelEntry channel,
732 SilcPacketFlags flags,
734 unsigned int data_len,
737 SilcChannelClientEntry chl;
738 SilcSocketConnection sock = NULL;
740 SILC_LOG_DEBUG(("Start"));
742 /* Send the message to clients on the channel's client list. */
743 silc_list_start(channel->user_list);
744 while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) {
745 if (chl->client && !chl->client->router) {
746 sock = (SilcSocketConnection)chl->client->connection;
748 /* Send the packet to the client */
749 silc_server_packet_send_dest(server, sock, type, flags, chl->client->id,
750 SILC_ID_CLIENT, data, data_len,
756 /* Routine used to send (relay, route) private messages to some destination.
757 If the private message key does not exist then the message is re-encrypted,
758 otherwise we just pass it along. This really is not used to send new
759 private messages (as server does not send them) but to relay received
762 void silc_server_send_private_message(SilcServer server,
763 SilcSocketConnection dst_sock,
766 SilcPacketContext *packet)
768 SilcBuffer buffer = packet->buffer;
770 /* Re-encrypt and send if private messge key does not exist */
771 if ((packet->flags & SILC_PACKET_FLAG_PRIVMSG_KEY) == FALSE) {
773 silc_buffer_push(buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
774 + packet->dst_id_len + packet->padlen);
775 silc_packet_send_prepare(dst_sock, 0, 0, buffer->len);
776 silc_buffer_put(dst_sock->outbuf, buffer->data, buffer->len);
778 /* Re-encrypt packet */
779 silc_packet_encrypt(cipher, hmac, dst_sock->outbuf, buffer->len);
781 /* Send the packet */
782 silc_server_packet_send_real(server, dst_sock, FALSE);
785 /* Key exist so encrypt just header and send it */
786 silc_buffer_push(buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
787 + packet->dst_id_len + packet->padlen);
788 silc_packet_send_prepare(dst_sock, 0, 0, buffer->len);
789 silc_buffer_put(dst_sock->outbuf, buffer->data, buffer->len);
792 silc_packet_encrypt(cipher, hmac, dst_sock->outbuf,
793 SILC_PACKET_HEADER_LEN + packet->src_id_len +
794 packet->dst_id_len + packet->padlen);
796 silc_server_packet_send_real(server, dst_sock, FALSE);
800 /* Sends current motd to client */
802 void silc_server_send_motd(SilcServer server,
803 SilcSocketConnection sock)
808 if (server->config && server->config->motd &&
809 server->config->motd->motd_file) {
811 motd = silc_file_read(server->config->motd->motd_file, &motd_len);
815 silc_server_send_notify(server, sock, FALSE, SILC_NOTIFY_TYPE_MOTD, 1,
821 /* Sends error message. Error messages may or may not have any
824 void silc_server_send_error(SilcServer server,
825 SilcSocketConnection sock,
826 const char *fmt, ...)
829 unsigned char buf[4096];
831 memset(buf, 0, sizeof(buf));
833 vsprintf(buf, fmt, ap);
836 silc_server_packet_send(server, sock, SILC_PACKET_ERROR, 0,
837 buf, strlen(buf), FALSE);
840 /* Sends notify message. If format is TRUE the variable arguments are
841 formatted and the formatted string is sent as argument payload. If it is
842 FALSE then each argument is sent as separate argument and their format
843 in the argument list must be { argument data, argument length }. */
845 void silc_server_send_notify(SilcServer server,
846 SilcSocketConnection sock,
849 unsigned int argc, ...)
856 packet = silc_notify_payload_encode(type, argc, ap);
857 silc_server_packet_send(server, sock, SILC_PACKET_NOTIFY, 0,
858 packet->data, packet->len, FALSE);
859 silc_buffer_free(packet);
862 /* Send CHANNEL_CHANGE notify type. This tells the receiver to replace the
863 `old_id' with the `new_id'. */
865 void silc_server_send_notify_channel_change(SilcServer server,
866 SilcSocketConnection sock,
868 SilcChannelID *old_id,
869 SilcChannelID *new_id,
872 SilcBuffer idp1, idp2;
874 idp1 = silc_id_payload_encode((void *)old_id, SILC_ID_CHANNEL);
875 idp2 = silc_id_payload_encode((void *)new_id, SILC_ID_CHANNEL);
877 silc_server_send_notify(server, sock, broadcast,
878 SILC_NOTIFY_TYPE_CHANNEL_CHANGE,
879 2, idp1->data, idp1->len, idp2->data, idp2->len);
880 silc_buffer_free(idp1);
881 silc_buffer_free(idp2);
884 /* Send NICK_CHANGE notify type. This tells the receiver to replace the
885 `old_id' with the `new_id'. */
887 void silc_server_send_notify_nick_change(SilcServer server,
888 SilcSocketConnection sock,
890 SilcClientID *old_id,
891 SilcClientID *new_id,
894 SilcBuffer idp1, idp2;
896 idp1 = silc_id_payload_encode((void *)old_id, SILC_ID_CLIENT);
897 idp2 = silc_id_payload_encode((void *)new_id, SILC_ID_CLIENT);
899 silc_server_send_notify(server, sock, broadcast,
900 SILC_NOTIFY_TYPE_NICK_CHANGE,
901 2, idp1->data, idp1->len, idp2->data, idp2->len);
902 silc_buffer_free(idp1);
903 silc_buffer_free(idp2);
906 /* Sends JOIN notify type. This tells that new client by `client_id' ID
907 has joined to the `channel'. */
909 void silc_server_send_notify_join(SilcServer server,
910 SilcSocketConnection sock,
912 SilcChannelEntry channel,
913 SilcClientID *client_id,
914 unsigned int client_id_len)
916 SilcBuffer idp1, idp2;
918 idp1 = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
919 idp2 = silc_id_payload_encode((void *)channel->id, SILC_ID_CHANNEL);
920 silc_server_send_notify(server, sock, broadcast, SILC_NOTIFY_TYPE_JOIN,
921 2, idp1->data, idp1->len,
922 idp2->data, idp2->len);
923 silc_buffer_free(idp1);
924 silc_buffer_free(idp2);
927 /* Sends LEAVE notify type. This tells that `client_id' has left the
928 `channel'. The Notify packet is always destined to the channel. */
930 void silc_server_send_notify_leave(SilcServer server,
931 SilcSocketConnection sock,
933 SilcChannelEntry channel,
934 SilcClientID *client_id,
935 unsigned int client_id_len)
939 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
940 silc_server_send_notify_dest(server, sock, broadcast, (void *)channel->id,
941 SILC_ID_CHANNEL, SILC_NOTIFY_TYPE_LEAVE,
942 1, idp->data, idp->len);
943 silc_buffer_free(idp);
946 /* Sends CMODE_CHANGE notify type. This tells that `client_id' changed the
947 `channel' mode to `mode. The Notify packet is always destined to
950 void silc_server_send_notify_cmode(SilcServer server,
951 SilcSocketConnection sock,
953 SilcChannelEntry channel,
954 unsigned int mode_mask,
955 SilcClientID *client_id,
956 unsigned int client_id_len,
957 char *cipher, char *hmac)
960 unsigned char mode[4];
962 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
963 SILC_PUT32_MSB(mode_mask, mode);
965 silc_server_send_notify_dest(server, sock, broadcast, (void *)channel->id,
966 SILC_ID_CHANNEL, SILC_NOTIFY_TYPE_CMODE_CHANGE,
967 4, idp->data, idp->len,
969 cipher, cipher ? strlen(cipher) : 0,
970 hmac, hmac ? strlen(hmac) : 0);
971 silc_buffer_free(idp);
974 /* Sends CUMODE_CHANGE notify type. This tells that `client_id' changed the
975 `target' client's mode on `channel'. The Notify packet is always
976 destined to the channel. */
978 void silc_server_send_notify_cumode(SilcServer server,
979 SilcSocketConnection sock,
981 SilcChannelEntry channel,
982 unsigned int mode_mask,
983 SilcClientID *client_id,
984 unsigned int client_id_len,
985 SilcClientID *target,
986 unsigned int target_len)
988 SilcBuffer idp1, idp2;
989 unsigned char mode[4];
991 idp1 = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
992 idp2 = silc_id_payload_encode((void *)target, SILC_ID_CLIENT);
993 SILC_PUT32_MSB(mode_mask, mode);
995 silc_server_send_notify_dest(server, sock, broadcast, (void *)channel->id,
997 SILC_NOTIFY_TYPE_CUMODE_CHANGE, 3,
998 idp1->data, idp1->len,
1000 idp2->data, idp2->len);
1001 silc_buffer_free(idp1);
1002 silc_buffer_free(idp2);
1005 /* Sends SIGNOFF notify type. This tells that `client_id' client has
1006 left SILC network. This function is used only between server and router
1007 traffic. This is not used to send the notify to the channel for
1008 client. The `message may be NULL. */
1010 void silc_server_send_notify_signoff(SilcServer server,
1011 SilcSocketConnection sock,
1013 SilcClientID *client_id,
1014 unsigned int client_id_len,
1019 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
1020 silc_server_send_notify(server, sock, broadcast,
1021 SILC_NOTIFY_TYPE_SIGNOFF,
1022 message ? 2 : 1, idp->data, idp->len,
1023 message, message ? strlen(message): 0);
1024 silc_buffer_free(idp);
1027 /* Sends SERVER_SIGNOFF notify type. This tells that `server_id' server
1028 has quit SILC network. */
1030 void silc_server_send_notify_server_signoff(SilcServer server,
1031 SilcSocketConnection sock,
1033 SilcServerID *server_id,
1034 unsigned int server_id_len)
1038 idp = silc_id_payload_encode((void *)server_id, SILC_ID_SERVER);
1039 silc_server_send_notify(server, sock, broadcast,
1040 SILC_NOTIFY_TYPE_SERVER_SIGNOFF,
1041 1, idp->data, idp->len);
1042 silc_buffer_free(idp);
1045 /* Sends TOPIC_SET notify type. This tells that `client_id' changed
1046 the `channel's topic to `topic'. The Notify packet is always destined
1047 to the channel. This function is used to send the topic set notifies
1050 void silc_server_send_notify_topic_set(SilcServer server,
1051 SilcSocketConnection sock,
1053 SilcChannelEntry channel,
1054 SilcClientID *client_id,
1055 unsigned int client_id_len,
1060 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
1061 silc_server_send_notify(server, sock, broadcast,
1062 SILC_NOTIFY_TYPE_SERVER_SIGNOFF,
1064 idp->data, idp->len,
1065 topic, topic ? strlen(topic) : 0);
1066 silc_buffer_free(idp);
1069 /* Send KICKED notify type. This tells that the `client_id' on `channel'
1070 was kicked off the channel. The `comment' may indicate the reason
1071 for the kicking. This function is used only between server and router
1074 void silc_server_send_notify_kicked(SilcServer server,
1075 SilcSocketConnection sock,
1077 SilcChannelEntry channel,
1078 SilcClientID *client_id,
1079 unsigned int client_id_len,
1084 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
1085 silc_server_send_notify_dest(server, sock, broadcast, (void *)channel->id,
1086 SILC_ID_CHANNEL, SILC_NOTIFY_TYPE_KICKED,
1087 comment ? 2 : 1, idp->data, idp->len,
1088 comment, comment ? strlen(comment) : 0);
1089 silc_buffer_free(idp);
1092 /* Send KILLED notify type. This tells that the `client_id' client was
1093 killed from the network. The `comment' may indicate the reason
1096 void silc_server_send_notify_killed(SilcServer server,
1097 SilcSocketConnection sock,
1099 SilcClientID *client_id,
1100 unsigned int client_id_len,
1105 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
1106 silc_server_send_notify_dest(server, sock, broadcast, (void *)client_id,
1107 SILC_ID_CLIENT, SILC_NOTIFY_TYPE_KILLED,
1108 comment ? 2 : 1, idp->data, idp->len,
1109 comment, comment ? strlen(comment) : 0);
1110 silc_buffer_free(idp);
1113 /* Sends UMODE_CHANGE notify type. This tells that `client_id' client's
1114 user mode in the SILC Network was changed. This function is used to
1115 send the packet between routers as broadcast packet. */
1117 void silc_server_send_notify_umode(SilcServer server,
1118 SilcSocketConnection sock,
1120 SilcClientID *client_id,
1121 unsigned int client_id_len,
1122 unsigned int mode_mask)
1125 unsigned char mode[4];
1127 idp = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
1128 SILC_PUT32_MSB(mode_mask, mode);
1130 silc_server_send_notify(server, sock, broadcast,
1131 SILC_NOTIFY_TYPE_UMODE_CHANGE, 2,
1132 idp->data, idp->len,
1134 silc_buffer_free(idp);
1137 /* Sends BAN notify type. This tells that ban has been either `add'ed
1138 or `del'eted on the `channel. This function is used to send the packet
1139 between routers as broadcast packet. */
1141 void silc_server_send_notify_ban(SilcServer server,
1142 SilcSocketConnection sock,
1144 SilcChannelEntry channel,
1145 char *add, char *del)
1149 idp = silc_id_payload_encode((void *)channel->id, SILC_ID_CHANNEL);
1150 silc_server_send_notify(server, sock, broadcast,
1151 SILC_NOTIFY_TYPE_BAN, 3,
1152 idp->data, idp->len,
1153 add, add ? strlen(add) : 0,
1154 del, del ? strlen(del) : 0);
1155 silc_buffer_free(idp);
1158 /* Sends INVITE notify type. This tells that invite has been either `add'ed
1159 or `del'eted on the `channel. The sender of the invite is the `client_id'.
1160 This function is used to send the packet between routers as broadcast
1163 void silc_server_send_notify_invite(SilcServer server,
1164 SilcSocketConnection sock,
1166 SilcChannelEntry channel,
1167 SilcClientID *client_id,
1168 unsigned int client_id_len,
1169 char *add, char *del)
1171 SilcBuffer idp, idp2;
1173 idp = silc_id_payload_encode((void *)channel->id, SILC_ID_CHANNEL);
1174 idp2 = silc_id_payload_encode((void *)client_id, SILC_ID_CLIENT);
1175 silc_server_send_notify(server, sock, broadcast,
1176 SILC_NOTIFY_TYPE_INVITE, 5,
1177 idp->data, idp->len,
1178 channel->channel_name, strlen(channel->channel_name),
1179 idp2->data, idp2->len,
1180 add, add ? strlen(add) : 0,
1181 del, del ? strlen(del) : 0);
1182 silc_buffer_free(idp);
1183 silc_buffer_free(idp2);
1186 /* Sends notify message destined to specific entity. */
1188 void silc_server_send_notify_dest(SilcServer server,
1189 SilcSocketConnection sock,
1192 SilcIdType dest_id_type,
1193 SilcNotifyType type,
1194 unsigned int argc, ...)
1201 packet = silc_notify_payload_encode(type, argc, ap);
1202 silc_server_packet_send_dest(server, sock, SILC_PACKET_NOTIFY, 0,
1203 dest_id, dest_id_type,
1204 packet->data, packet->len, FALSE);
1205 silc_buffer_free(packet);
1208 /* Sends notify message to a channel. The notify message sent is
1209 distributed to all clients on the channel. If `route_notify' is TRUE
1210 then the notify may be routed to primary route or to some other routers.
1211 If FALSE it is assured that the notify is sent only locally. If `sender'
1212 is provided then the packet is not sent to that connection since it
1213 originally came from it. */
1215 void silc_server_send_notify_to_channel(SilcServer server,
1216 SilcSocketConnection sender,
1217 SilcChannelEntry channel,
1218 unsigned char route_notify,
1219 SilcNotifyType type,
1220 unsigned int argc, ...)
1227 packet = silc_notify_payload_encode(type, argc, ap);
1228 silc_server_packet_send_to_channel(server, sender, channel,
1229 SILC_PACKET_NOTIFY, route_notify,
1230 packet->data, packet->len, FALSE);
1231 silc_buffer_free(packet);
1234 /* Send notify message to all channels the client has joined. It is quaranteed
1235 that the message is sent only once to a client (ie. if a client is joined
1236 on two same channel it will receive only one notify message). Also, this
1237 sends only to local clients (locally connected if we are server, and to
1238 local servers if we are router). If `sender' is provided the packet is
1239 not sent to that client at all. */
1241 void silc_server_send_notify_on_channels(SilcServer server,
1242 SilcClientEntry sender,
1243 SilcClientEntry client,
1244 SilcNotifyType type,
1245 unsigned int argc, ...)
1248 SilcSocketConnection sock = NULL;
1249 SilcPacketContext packetdata;
1251 SilcClientEntry *sent_clients = NULL;
1252 unsigned int sent_clients_count = 0;
1253 SilcServerEntry *routed = NULL;
1254 unsigned int routed_count = 0;
1255 SilcChannelEntry channel;
1256 SilcChannelClientEntry chl, chl2;
1257 SilcIDListData idata;
1259 unsigned char *data;
1260 unsigned int data_len;
1261 int force_send = FALSE;
1264 SILC_LOG_DEBUG(("Start"));
1266 if (!silc_list_count(client->channels))
1270 packet = silc_notify_payload_encode(type, argc, ap);
1271 data = packet->data;
1272 data_len = packet->len;
1274 /* Set the packet context pointers. */
1275 packetdata.flags = 0;
1276 packetdata.type = SILC_PACKET_NOTIFY;
1277 packetdata.src_id = silc_id_id2str(server->id, SILC_ID_SERVER);
1278 packetdata.src_id_len = SILC_ID_SERVER_LEN;
1279 packetdata.src_id_type = SILC_ID_SERVER;
1281 silc_list_start(client->channels);
1282 while ((chl = silc_list_get(client->channels)) != SILC_LIST_END) {
1283 channel = chl->channel;
1285 /* Send the message to all clients on the channel's client list. */
1286 silc_list_start(channel->user_list);
1287 while ((chl2 = silc_list_get(channel->user_list)) != SILC_LIST_END) {
1290 if (sender && c == sender)
1293 /* Check if we have sent the packet to this client already */
1294 for (k = 0; k < sent_clients_count; k++)
1295 if (sent_clients[k] == c)
1297 if (k < sent_clients_count)
1300 /* If we are router and if this client has router set it is not
1301 locally connected client and we will route the message to the
1302 router set in the client. */
1303 if (c && c->router && server->server_type == SILC_ROUTER) {
1304 /* Check if we have sent the packet to this route already */
1305 for (k = 0; k < routed_count; k++)
1306 if (routed[k] == c->router)
1308 if (k < routed_count)
1311 /* Get data used in packet header encryption, keys and stuff. */
1312 sock = (SilcSocketConnection)c->router->connection;
1313 idata = (SilcIDListData)c->router;
1315 packetdata.dst_id = silc_id_id2str(c->router->id, SILC_ID_SERVER);
1316 packetdata.dst_id_len = SILC_ID_SERVER_LEN;
1317 packetdata.dst_id_type = SILC_ID_SERVER;
1318 packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
1319 packetdata.src_id_len + packetdata.dst_id_len;
1320 packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen);
1322 /* Send the packet */
1323 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
1324 idata->send_key, idata->hmac,
1325 data, data_len, FALSE,
1328 silc_free(packetdata.dst_id);
1330 /* We want to make sure that the packet is routed to same router
1331 only once. Mark this route as sent route. */
1333 routed = silc_realloc(routed, sizeof(*routed) * (k + 1));
1334 routed[k] = c->router;
1343 /* Send to locally connected client */
1346 /* Get data used in packet header encryption, keys and stuff. */
1347 sock = (SilcSocketConnection)c->connection;
1348 idata = (SilcIDListData)c;
1350 packetdata.dst_id = silc_id_id2str(c->id, SILC_ID_CLIENT);
1351 packetdata.dst_id_len = SILC_ID_CLIENT_LEN;
1352 packetdata.dst_id_type = SILC_ID_CLIENT;
1353 packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN +
1354 packetdata.src_id_len + packetdata.dst_id_len;
1355 packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen);
1357 /* Send the packet */
1358 silc_server_packet_send_to_channel_real(server, sock, &packetdata,
1359 idata->send_key, idata->hmac,
1360 data, data_len, FALSE,
1363 silc_free(packetdata.dst_id);
1365 /* Make sure that we send the notify only once per client. */
1366 sent_clients = silc_realloc(sent_clients, sizeof(*sent_clients) *
1367 (sent_clients_count + 1));
1368 sent_clients[sent_clients_count] = c;
1369 sent_clients_count++;
1376 if (sent_clients_count)
1377 silc_free(sent_clients);
1378 silc_free(packetdata.src_id);
1381 /* Sends New ID Payload to remote end. The packet is used to distribute
1382 information about new registered clients, servers, channel etc. usually
1383 to routers so that they can keep these information up to date.
1384 If the argument `broadcast' is TRUE then the packet is sent as
1385 broadcast packet. */
1387 void silc_server_send_new_id(SilcServer server,
1388 SilcSocketConnection sock,
1390 void *id, SilcIdType id_type,
1391 unsigned int id_len)
1395 SILC_LOG_DEBUG(("Start"));
1397 idp = silc_id_payload_encode(id, id_type);
1398 silc_server_packet_send(server, sock, SILC_PACKET_NEW_ID,
1399 broadcast ? SILC_PACKET_FLAG_BROADCAST : 0,
1400 idp->data, idp->len, FALSE);
1401 silc_buffer_free(idp);
1404 /* Send New Channel Payload to notify about newly created channel in the
1405 SILC network. Normal server nevers sends this packet. Router uses this
1406 to notify other routers in the network about new channel. This packet
1409 void silc_server_send_new_channel(SilcServer server,
1410 SilcSocketConnection sock,
1414 unsigned int channel_id_len,
1419 unsigned int name_len = strlen(channel_name);
1421 SILC_LOG_DEBUG(("Start"));
1423 cid = silc_id_id2str(channel_id, SILC_ID_CHANNEL);
1427 /* Encode the channel payload */
1428 packet = silc_channel_payload_encode(channel_name, name_len,
1429 cid, channel_id_len, mode);
1431 silc_server_packet_send(server, sock, SILC_PACKET_NEW_CHANNEL,
1432 broadcast ? SILC_PACKET_FLAG_BROADCAST : 0,
1433 packet->data, packet->len, FALSE);
1436 silc_buffer_free(packet);
1439 /* Send Channel Key payload to distribute the new channel key. Normal server
1440 sends this to router when new client joins to existing channel. Router
1441 sends this to the local server who sent the join command in case where
1442 the channel did not exist yet. Both normal and router servers uses this
1443 also to send this to locally connected clients on the channel. This
1444 must not be broadcasted packet. Routers do not send this to each other.
1445 If `sender is provided then the packet is not sent to that connection since
1446 it originally came from it. */
1448 void silc_server_send_channel_key(SilcServer server,
1449 SilcSocketConnection sender,
1450 SilcChannelEntry channel,
1451 unsigned char route)
1454 unsigned char *chid;
1455 unsigned int tmp_len;
1457 SILC_LOG_DEBUG(("Start"));
1459 chid = silc_id_id2str(channel->id, SILC_ID_CHANNEL);
1463 /* Encode channel key packet */
1464 tmp_len = strlen(channel->channel_key->cipher->name);
1465 packet = silc_channel_key_payload_encode(SILC_ID_CHANNEL_LEN, chid, tmp_len,
1466 channel->channel_key->cipher->name,
1467 channel->key_len / 8, channel->key);
1469 silc_server_packet_send_to_channel(server, sender, channel,
1470 SILC_PACKET_CHANNEL_KEY,
1471 route, packet->data, packet->len, FALSE);
1472 silc_buffer_free(packet);
1476 /* Generic function to send any command. The arguments must be sent already
1477 encoded into correct form in correct order. */
1479 void silc_server_send_command(SilcServer server,
1480 SilcSocketConnection sock,
1481 SilcCommand command,
1482 unsigned int argc, ...)
1489 packet = silc_command_payload_encode_vap(command, 0, argc, ap);
1490 silc_server_packet_send(server, sock, SILC_PACKET_COMMAND, 0,
1491 packet->data, packet->len, TRUE);
1492 silc_buffer_free(packet);
1495 /* Send the heartbeat packet. */
1497 void silc_server_send_heartbeat(SilcServer server,
1498 SilcSocketConnection sock)
1500 silc_server_packet_send(server, sock, SILC_PACKET_HEARTBEAT, 0,
1504 /* Generic function to relay packet we've received. This is used to relay
1505 packets to a client but generally can be used to other purposes as well. */
1507 void silc_server_relay_packet(SilcServer server,
1508 SilcSocketConnection dst_sock,
1511 SilcPacketContext *packet,
1514 silc_buffer_push(packet->buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
1515 + packet->dst_id_len + packet->padlen);
1517 silc_packet_send_prepare(dst_sock, 0, 0, packet->buffer->len);
1518 silc_buffer_put(dst_sock->outbuf, packet->buffer->data, packet->buffer->len);
1520 /* Re-encrypt packet */
1521 silc_packet_encrypt(cipher, hmac, dst_sock->outbuf, packet->buffer->len);
1523 /* Send the packet */
1524 silc_server_packet_send_real(server, dst_sock, force_send);
1526 silc_buffer_pull(packet->buffer, SILC_PACKET_HEADER_LEN + packet->src_id_len
1527 + packet->dst_id_len + packet->padlen);
1530 /* Routine used to send the connection authentication packet. */
1532 void silc_server_send_connection_auth_request(SilcServer server,
1533 SilcSocketConnection sock,
1534 unsigned short conn_type,
1535 SilcAuthMethod auth_meth)
1539 packet = silc_buffer_alloc(4);
1540 silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet));
1541 silc_buffer_format(packet,
1542 SILC_STR_UI_SHORT(conn_type),
1543 SILC_STR_UI_SHORT(auth_meth),
1546 silc_server_packet_send(server, sock, SILC_PACKET_CONNECTION_AUTH_REQUEST,
1547 0, packet->data, packet->len, FALSE);
1548 silc_buffer_free(packet);