5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 1997 - 2002 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.
24 /* Forward declarations */
25 typedef struct SilcServerEntryStruct *SilcServerEntry;
26 typedef struct SilcClientEntryStruct *SilcClientEntry;
27 typedef struct SilcChannelEntryStruct *SilcChannelEntry;
29 /* Context for holding cache information to periodically purge
36 /* Channel key re-key context. */
38 SilcChannelEntry channel;
41 } *SilcServerChannelRekey;
43 /* Generic rekey context for connections */
45 /* Current sending encryption key, provided for re-key. The `pfs'
46 is TRUE if the Perfect Forward Secrecy is performed in re-key. */
47 unsigned char *send_enc_key;
48 SilcUInt32 enc_key_len;
55 /* ID List Entry status flags. */
56 typedef SilcUInt8 SilcIDListStatus;
57 #define SILC_IDLIST_STATUS_NONE 0x00 /* No status */
58 #define SILC_IDLIST_STATUS_REGISTERED 0x01 /* Entry is registered */
59 #define SILC_IDLIST_STATUS_RESOLVED 0x02 /* Entry info is resolved */
60 #define SILC_IDLIST_STATUS_RESOLVING 0x04 /* Entry is being resolved
61 with WHOIS or IDENTIFY */
62 #define SILC_IDLIST_STATUS_DISABLED 0x08 /* Entry is disabled */
63 #define SILC_IDLIST_STATUS_RESUMED 0x10 /* Entry is resumed */
64 #define SILC_IDLIST_STATUS_LOCAL 0x20 /* Entry locally connected */
65 #define SILC_IDLIST_STATUS_RESUME_RES 0x40 /* Entry resolved while
67 #define SILC_IDLIST_STATUS_NOATTR 0x80 /* Entry does not support
68 attributes in WHOIS */
71 Generic ID list data structure.
73 This structure is included in all ID list entries and it includes data
74 pointers that are common to all ID entries. This structure is always
75 defined to the first field in the ID entries and is used to explicitly
76 type cast to this type without first explicitly casting to correct ID
77 entry type. Hence, the ID list entry is type casted to this type to
78 get this data from the ID entry (which is usually opaque pointer).
80 Note that some of the fields may be NULL.
84 /* Send and receive symmetric keys */
86 SilcCipher receive_key;
90 SilcHmac hmac_receive;
92 /* Packet sequence numbers */
94 SilcUInt32 psn_receive;
96 /* Hash selected in the SKE protocol, NULL if not needed at all */
100 SilcPublicKey public_key;
101 unsigned char fingerprint[20];
104 SilcServerRekey rekey;
106 long last_receive; /* Time last received data */
107 long last_sent; /* Time last sent data */
109 unsigned long created; /* Time when entry was created */
111 SilcIDListStatus status; /* Status mask of the entry */
112 } *SilcIDListData, SilcIDListDataStruct;
115 SILC Server entry object.
117 This entry holds information about servers in SILC network. However,
118 contents of this entry is highly dependent of what kind of server we are
119 (normal server or router server) and whether the entry is used as a local
120 list or a global list. These factors dictates the contents of this entry.
122 This entry is defined as follows:
124 Server type List type Contents
125 =======================================================================
126 server local list Server itself
127 server global list NULL
128 router local list All servers is the cell
129 router global list All servers in the SILC network
131 Following short description of the fields:
133 SilcIDListDataStruct data
135 Generic data structure to hold data common to all ID entries.
139 Logical name of the server. There is no limit of the length of the
140 server name. This is usually the same name as defined in DNS.
142 SilcUInt8 server_type
144 Type of the server. SILC_SERVER or SILC_ROUTER are the possible
149 ID of the server. This includes all the relevant information about
150 the server SILC will ever need. These are also the informations
151 that is broadcasted between servers and routers in the SILC network.
156 Server info (from INFO command) saved temporarily and motd (from
157 MOTD command) saved temporarily.
159 SilcServerEntry router
161 This is a pointer back to the server list. This is the router server
162 where this server is connected to. If this is the router itself and
163 it doesn't have a route this is NULL.
166 SilcCipher receive_key
168 Data sending and receiving keys.
172 A pointer, usually, to the socket list for fast referencing to
173 the data used in connection with this server. This may be anything
174 but as just said, this is usually pointer to the socket connection
178 struct SilcServerEntryStruct {
179 /* Generic data structure. DO NOT add anything before this! */
180 SilcIDListDataStruct data;
183 SilcUInt8 server_type;
188 /* Pointer to the router */
189 SilcServerEntry router;
191 /* Connection data */
196 SILC Channel Client entry structure.
198 This entry used only by the SilcChannelEntry object and it holds
199 information about current clients (ie. users) on channel. Following
200 short description of the fields:
202 SilcClientEntry client
204 Pointer to the client list. This is the client currently on channel.
208 Client's current mode on the channel.
210 SilcChannelEntry channel
212 Back pointer back to channel. As this structure is also used by
213 SilcClientEntry we have this here for fast access to the channel when
214 used by SilcClientEntry.
217 typedef struct SilcChannelClientEntryStruct {
218 SilcClientEntry client;
220 SilcChannelEntry channel;
221 } *SilcChannelClientEntry;
224 SILC Client entry object.
226 This entry holds information about connected clients ie. users in the SILC
227 network. The contents of this entrt is depended on whether we are normal
228 server or router server and whether the list is a local or global list.
230 This entry is defined as follows:
232 Server type List type Contents
233 =======================================================================
234 server local list All clients in server
235 server global list NULL
236 router local list All clients in cell
237 router global list All clients in SILC
239 Following short description of the fields:
241 SilcIDListDataStruct data
243 Generic data structure to hold data common to all ID entries.
245 unsigned char *nickname
247 The nickname of the client.
251 The name of the server where the client is from. MAy be NULL.
255 Client's usename. This is defined in the following manner:
257 Server type List type Contents
258 ====================================================
259 server local list User's name
260 router local list NULL
261 router global list NULL
263 Router doesn't hold this information since it is not vital data
264 for the router. If this information is needed by the client it is
265 fetched when it is needed.
269 Information about user. This is free information and can be virtually
270 anything. This is defined in following manner:
272 Server type List type Contents
273 ====================================================
274 server local list User's information
275 router local list NULL
276 router global list NULL
278 Router doesn't hold this information since it is not vital data
279 for the router. If this information is needed by the client it is
280 fetched when it is needed.
284 ID of the client. This includes all the information SILC will ever
285 need. Notice that no nickname of the user is saved anywhere. This is
286 beacuse of SilcClientID includes 88 bit hash value of the user's
287 nickname which can be used to track down specific user by their
288 nickname. Nickname is not relevant information that would need to be
293 Client's mode. Client maybe for example server operator or
294 router operator (SILC operator).
298 Time of last time client executed command. We are strict and will
299 not allow any command to be exeucted more than once in about
300 2 seconds. This is result of normal time().
302 SilcUInt8 fast_command
304 Counter to check command bursts. By default, up to 5 commands
305 are allowed before limiting the execution. See command flags
308 SilcServerEntry router
310 This is a pointer to the server list. This is the router server whose
311 cell this client is coming from. This is used to route messages to
314 SilcHashTable channels;
316 All the channels this client has joined. The context saved in the
317 hash table shares memory with the channel entrys `user_list' hash
322 A pointer, usually, to the socket list for fast referencing to
323 the data used in connection with this client. This may be anything
324 but as just said, this is usually pointer to the socket connection
327 SilcUInt16 resolve_cmd_ident
329 Command identifier for the entry when the entry's data.status
330 is SILC_IDLIST_STATUS_RESOLVING. If this entry is asked to be
331 resolved when the status is set then the resolver may attach to
332 this command identifier and handle the process after the resolving
336 struct SilcClientEntryStruct {
337 /* Generic data structure. DO NOT add anything before this! */
338 SilcIDListDataStruct data;
340 unsigned char *nickname;
348 SilcUInt8 fast_command;
350 /* Requested Attributes */
351 unsigned char *attrs;
352 SilcUInt16 attrs_len;
354 /* Pointer to the router */
355 SilcServerEntry router;
357 /* All channels this client has joined */
358 SilcHashTable channels;
360 /* Connection data */
363 /* Last time updated/accessed */
364 unsigned long updated;
366 /* data.status is RESOLVING and this includes the resolving command
368 SilcUInt16 resolve_cmd_ident;
372 SILC Channel entry object.
374 This entry holds information about channels in SILC network. The contents
375 of this entry is depended on whether we are normal server or router server
376 and whether the list is a local or global list.
378 This entry is defined as follows:
380 Server type List type Contents
381 =======================================================================
382 server local list All channels in server
383 server global list NULL
384 router local list All channels in cell
385 router global list All channels in SILC
387 Following short description of the fields:
391 Logical name of the channel.
395 Current mode of the channel. See lib/silccore/silcchannel.h for
400 ID of the channel. This includes all the information SILC will ever
405 Boolean value to tell whether there are users outside this server
406 on this channel. This is set to TRUE if router sends message to
407 the server that there are users outside your server on your
408 channel as well. This way server knows that messages needs to be
409 sent to the router for further routing. If this is a normal
410 server and this channel is not created on this server this field
411 is always TRUE. If this server is a router this field is ignored.
415 Current topic of the channel.
419 Default cipher of the channel. If this is NULL then server picks
420 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
424 Default hmac of the channel. If this is NULL then server picks
425 the cipher to be used. This can be set at SILC_COMMAND_JOIN.
427 SilcPublicKey founder_key
429 If the SILC_CMODE_FOUNDER_AUTH has been set then this will include
430 the founder's public key. When the mode and this key is set the
431 channel is also permanent channel and cannot be destroyed.
433 SilcHashTable user_list
435 All users joined on this channel. Note that the context saved to
436 this entry shares memory with the client entrys `channels' hash
439 SilcServerEntry router
441 This is a pointer to the server list. This is the router server
442 whose cell this channel belongs to. This is used to route messages
445 SilcCipher channel_key
447 The key of the channel (the cipher actually).
452 Raw key data of the channel key.
454 unsigned char iv[SILC_CIPHER_MAX_IV_SIZE]
456 Current initial vector. Initial vector is received always along
457 with the channel packet. By default this is filled with NULL.
463 SilcServerChannelRekey rekey
465 Channel key re-key context.
468 struct SilcChannelEntryStruct {
475 SilcPublicKey founder_key;
477 SilcUInt32 user_limit;
478 unsigned char *passphrase;
479 SilcHashTable invite_list;
480 SilcHashTable ban_list;
482 /* All users on this channel */
483 SilcHashTable user_list;
484 SilcUInt32 user_count;
486 /* Pointer to the router */
487 SilcServerEntry router;
490 SilcCipher channel_key;
495 SilcServerChannelRekey rekey;
496 unsigned long created;
497 unsigned long updated;
500 unsigned int global_users : 1;
501 unsigned int disabled : 1;
502 unsigned int users_resolved : 1;
508 As for remainder these lists are defined as follows:
510 Entry list (cache) Server type List type Contents
511 =======================================================================
512 servers server local list Server itself
513 servers server global list NULL
514 servers router local list All servers in cell
515 servers router global list All servers in SILC
517 clients server local list All clients in server
518 clients server global list NULL
519 clients router local list All clients in cell
520 clients router global list All clients in SILC
522 channels server local list All channels in server
523 channels server global list NULL
524 channels router local list All channels in cell
525 channels router global list All channels in SILC
527 As seen on the list normal server never defines a global list. This is
528 because of normal server don't know anything about anything global data,
529 they get it from the router if and when they need it. Routers, on the
530 other hand, always define local and global lists because routers really
531 know all the relevant data in the SILC network.
533 This object is used as local and global list by the server/router.
534 Above table shows how this is defined on different conditions.
536 This object holds pointers to the ID cache system. Every ID cache entry
537 has a specific context pointer to allocated entry (server, client or
541 typedef struct SilcIDListStruct {
544 SilcIDCache channels;
548 ID Entry for Unknown connections.
550 This is used during authentication phases where we still don't know
551 what kind of connection remote connection is, hence, we will use this
552 structure instead until we know what type of connection remote end is.
554 This is not in any list. This is always individually allocated and
559 /* Generic data structure. DO NOT add anything before this! */
560 SilcIDListDataStruct data;
564 void silc_idlist_add_data(void *entry, SilcIDListData idata);
565 void silc_idlist_del_data(void *entry);
566 SILC_TASK_CALLBACK_GLOBAL(silc_idlist_purge);
568 silc_idlist_add_server(SilcIDList id_list,
569 char *server_name, int server_type,
570 SilcServerID *id, SilcServerEntry router,
573 silc_idlist_find_server_by_id(SilcIDList id_list, SilcServerID *id,
574 bool registered, SilcIDCacheEntry *ret_entry);
576 silc_idlist_find_server_by_name(SilcIDList id_list, char *name,
577 bool registered, SilcIDCacheEntry *ret_entry);
579 silc_idlist_find_server_by_conn(SilcIDList id_list, char *hostname,
580 int port, bool registered,
581 SilcIDCacheEntry *ret_entry);
583 silc_idlist_replace_server_id(SilcIDList id_list, SilcServerID *old_id,
584 SilcServerID *new_id);
585 int silc_idlist_del_server(SilcIDList id_list, SilcServerEntry entry);
587 silc_idlist_add_client(SilcIDList id_list, char *nickname, char *username,
588 char *userinfo, SilcClientID *id,
589 SilcServerEntry router, void *connection,
591 int silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry);
592 int silc_idlist_get_clients_by_nickname(SilcIDList id_list, char *nickname,
594 SilcClientEntry **clients,
595 SilcUInt32 *clients_count);
596 int silc_idlist_get_clients_by_hash(SilcIDList id_list, char *nickname,
598 SilcClientEntry **clients,
599 SilcUInt32 *clients_count);
601 silc_idlist_find_client_by_id(SilcIDList id_list, SilcClientID *id,
602 bool registered, SilcIDCacheEntry *ret_entry);
604 silc_idlist_replace_client_id(SilcServer server,
605 SilcIDList id_list, SilcClientID *old_id,
606 SilcClientID *new_id, const char *nickname);
607 void silc_idlist_client_destructor(SilcIDCache cache,
608 SilcIDCacheEntry entry);
610 silc_idlist_add_channel(SilcIDList id_list, char *channel_name, int mode,
611 SilcChannelID *id, SilcServerEntry router,
612 SilcCipher channel_key, SilcHmac hmac,
614 int silc_idlist_del_channel(SilcIDList id_list, SilcChannelEntry entry);
616 silc_idlist_find_channel_by_name(SilcIDList id_list, char *name,
617 SilcIDCacheEntry *ret_entry);
619 silc_idlist_find_channel_by_id(SilcIDList id_list, SilcChannelID *id,
620 SilcIDCacheEntry *ret_entry);
622 silc_idlist_replace_channel_id(SilcIDList id_list, SilcChannelID *old_id,
623 SilcChannelID *new_id);
625 silc_idlist_get_channels(SilcIDList id_list, SilcChannelID *channel_id,
626 SilcUInt32 *channels_count);