From 186079e7fb070072090a395379f6b5f754604c2a Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 6 May 2001 13:24:11 +0000 Subject: [PATCH] updates. --- CHANGES | 18 ++++ TODO | 8 +- apps/silcd/command.c | 45 ++++------ apps/silcd/idlist.c | 4 +- apps/silcd/packet_receive.c | 29 ++++--- apps/silcd/packet_send.c | 55 +++++------- apps/silcd/packet_send.h | 23 ++--- apps/silcd/route.c | 7 +- apps/silcd/server.c | 44 ++++++---- apps/silcd/serverid.c | 9 +- lib/silcclient/client.c | 26 ++++-- lib/silcclient/client_channel.c | 6 +- lib/silcclient/client_notify.c | 2 +- lib/silcclient/client_prvmsg.c | 6 +- lib/silcclient/command.c | 3 +- lib/silcclient/command_reply.c | 2 +- lib/silccore/id.c | 143 +++++++++++++++++++++++++++----- lib/silccore/id.h | 84 ++++++++++--------- lib/silccore/idcache.c | 18 ++-- lib/silccore/silcauth.c | 2 +- lib/silccore/silcpayload.c | 2 +- lib/silcutil/silcutil.c | 30 ++++++- prepare | 2 +- 23 files changed, 349 insertions(+), 219 deletions(-) diff --git a/CHANGES b/CHANGES index 373cc2e6..e41102a9 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,21 @@ +Sun May 6 13:59:48 EEST 2001 Pekka Riikonen + + * Added new SilcIDIP structure into the lib/silccore/id.h and + replaced the old `ip' fields from all SILC ID's to that type. + This is a step towards IPv6 support. + + The silc_id_get_len takes now the ID as an extra argument. + Added new function silc_id_compare into lib/silccore/id.[ch]. + The silc_id_id2str, silc_id_str2id and silc_id_dup now supports + both IPv4 and IPv6 based ID's. + + The affected files are lib/silccore/id.[ch] and other files + around the tree using these routines. + + * Removed the ID length arguments in server from various + silc_server_send_notify_* routines -> they are not needed + anymore. + Sat May 5 13:56:33 EEST 2001 Pekka Riikonen * Fixed memory leak in silc_encode_pem_file in the file diff --git a/TODO b/TODO index 266b3f52..2c685800 100644 --- a/TODO +++ b/TODO @@ -57,7 +57,13 @@ TODO/bugs In SILC Server TODO/bugs In SILC Libraries =========================== - o IPv6 support for ID's and into the code. + o silc_server_get_users_on_channel does not support IPv6 based Client + ID's. + + o silc_server_route_get and the route code in general supports only + IPv4. + + o silcd/serverid.c and its routines supports only IPv4. o Compression routines are missing. The protocol supports packet compression thus it must be implemented. SILC Comp API must be diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 554fbb94..a961f6c9 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -1761,7 +1761,7 @@ SILC_SERVER_CMD_FUNC(nick) silc_server_send_notify_nick_change(server, server->router->connection, server->server_type == SILC_SERVER ? FALSE : TRUE, client->id, - new_id, SILC_ID_CLIENT_LEN); + new_id); /* Remove old cache entry */ silc_idcache_del_by_id(server->local_list->clients, SILC_ID_CLIENT, @@ -1770,10 +1770,8 @@ SILC_SERVER_CMD_FUNC(nick) oidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); /* Free old ID */ - if (client->id) { - memset(client->id, 0, SILC_ID_CLIENT_LEN); + if (client->id) silc_free(client->id); - } /* Save the nickname as this client is our local client */ if (client->nickname) @@ -2071,7 +2069,7 @@ SILC_SERVER_CMD_FUNC(topic) silc_server_send_notify_topic_set(server, server->router->connection, server->server_type == SILC_ROUTER ? TRUE : FALSE, channel, client->id, - SILC_ID_CLIENT_LEN, channel->topic); + channel->topic); idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); @@ -2302,8 +2300,7 @@ SILC_SERVER_CMD_FUNC(invite) silc_server_send_notify_invite(server, server->router->connection, server->server_type == SILC_ROUTER ? TRUE : FALSE, channel, - sender->id, SILC_ID_CLIENT_LEN, - add, del); + sender->id, add, del); /* Send command reply */ tmp = silc_argument_get_arg_type(cmd->args, 1, &len); @@ -2471,15 +2468,13 @@ SILC_SERVER_CMD_FUNC(kill) /* Send KILLED notify to primary route */ if (!server->standalone) silc_server_send_notify_killed(server, server->router->connection, TRUE, - remote_client->id, SILC_ID_CLIENT_LEN, - comment); + remote_client->id, comment); /* Send KILLED notify to the client directly */ silc_server_send_notify_killed(server, remote_client->connection ? remote_client->connection : remote_client->router->connection, FALSE, - remote_client->id, SILC_ID_CLIENT_LEN, - comment); + remote_client->id, comment); /* Remove the client from all channels. This generates new keys to the channels as well. */ @@ -2684,7 +2679,7 @@ SILC_SERVER_CMD_FUNC(ping) if (!id) goto out; - if (!SILC_ID_SERVER_COMPARE(id, server->id)) { + if (SILC_ID_SERVER_COMPARE(id, server->id)) { /* Send our reply */ silc_server_command_send_status_reply(cmd, SILC_COMMAND_PING, SILC_STATUS_OK); @@ -2906,8 +2901,7 @@ static void silc_server_command_join_channel(SilcServer server, if (!server->standalone) silc_server_send_notify_join(server, server->router->connection, server->server_type == SILC_ROUTER ? - TRUE : FALSE, channel, client->id, - SILC_ID_CLIENT_LEN); + TRUE : FALSE, channel, client->id); } silc_buffer_free(reply); @@ -2984,7 +2978,7 @@ SILC_SERVER_CMD_FUNC(join) be same as the client's ID. */ if (cmd->sock->type == SILC_SOCKET_TYPE_CLIENT) { SilcClientEntry entry = (SilcClientEntry)cmd->sock->user_data; - if (SILC_ID_CLIENT_COMPARE(entry->id, client_id)) { + if (!SILC_ID_CLIENT_COMPARE(entry->id, client_id)) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_JOIN, SILC_STATUS_ERR_NOT_ENOUGH_PARAMS); goto out; @@ -3317,8 +3311,7 @@ SILC_SERVER_CMD_FUNC(umode) /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, - client->id, SILC_ID_CLIENT_LEN, - client->mode); + client->id, client->mode); /* Send command reply to sender */ packet = silc_command_reply_payload_encode_va(SILC_COMMAND_UMODE, @@ -3727,7 +3720,6 @@ SILC_SERVER_CMD_FUNC(cmode) server->server_type == SILC_ROUTER ? TRUE : FALSE, channel, mode_mask, client->id, SILC_ID_CLIENT, - SILC_ID_CLIENT_LEN, cipher, hmac); /* Send command reply to sender */ @@ -3975,9 +3967,8 @@ SILC_SERVER_CMD_FUNC(cumode) server->server_type == SILC_ROUTER ? TRUE : FALSE, channel, target_mask, client->id, - SILC_ID_CLIENT, SILC_ID_CLIENT_LEN, - target_client->id, - SILC_ID_CLIENT_LEN); + SILC_ID_CLIENT, + target_client->id); } /* Send command reply to sender */ @@ -4136,8 +4127,7 @@ SILC_SERVER_CMD_FUNC(kick) silc_server_send_notify_kicked(server, server->router->connection, server->server_type == SILC_ROUTER ? TRUE : FALSE, channel, - target_client->id, SILC_ID_CLIENT_LEN, - comment); + target_client->id, comment); if (!(channel->mode & SILC_CHANNEL_MODE_PRIVKEY)) { /* Re-generate channel key */ @@ -4216,8 +4206,7 @@ SILC_SERVER_CMD_FUNC(oper) /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, - client->id, SILC_ID_CLIENT_LEN, - client->mode); + client->id, client->mode); /* Send reply to the sender */ silc_server_command_send_status_reply(cmd, SILC_COMMAND_OPER, @@ -4292,8 +4281,7 @@ SILC_SERVER_CMD_FUNC(silcoper) /* Send UMODE change to primary router */ if (!server->standalone) silc_server_send_notify_umode(server, server->router->connection, TRUE, - client->id, SILC_ID_CLIENT_LEN, - client->mode); + client->id, client->mode); /* Send reply to the sender */ silc_server_command_send_status_reply(cmd, SILC_COMMAND_SILCOPER, @@ -4639,8 +4627,7 @@ SILC_SERVER_CMD_FUNC(leave) if (!server->standalone) silc_server_send_notify_leave(server, server->router->connection, server->server_type == SILC_ROUTER ? - TRUE : FALSE, channel, id_entry->id, - SILC_ID_CLIENT_LEN); + TRUE : FALSE, channel, id_entry->id); silc_server_command_send_status_reply(cmd, SILC_COMMAND_LEAVE, SILC_STATUS_OK); diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 6785ab45..e6f79f3c 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -458,7 +458,7 @@ silc_idlist_find_client_by_hash(SilcIDList id_list, char *nickname, while (id_cache) { client = (SilcClientEntry)id_cache->context; - if (client && !SILC_ID_COMPARE_HASH(client->id, hash)) + if (client && SILC_ID_COMPARE_HASH(client->id, hash)) break; id_cache = NULL; @@ -532,7 +532,7 @@ silc_idlist_replace_client_id(SilcIDList id_list, SilcClientID *old_id, /* If the old ID Cache data was the hash value of the old Client ID replace it with the hash of new Client ID */ - if (id_cache->data && !SILC_ID_COMPARE_HASH(old_id, id_cache->data)) { + if (id_cache->data && SILC_ID_COMPARE_HASH(old_id, id_cache->data)) { silc_free(id_cache->data); id_cache->data = silc_calloc(sizeof(new_id->hash), sizeof(unsigned char)); memcpy(id_cache->data, new_id->hash, sizeof(new_id->hash)); diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 9f1e4ccc..b325fd6a 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -526,8 +526,7 @@ void silc_server_notify(SilcServer server, silc_server_send_notify_cumode(server, sock, FALSE, channel, (mode & (~SILC_CHANNEL_UMODE_CHANFO)), server->id, SILC_ID_SERVER, - SILC_ID_SERVER_LEN, - client->id, SILC_ID_CLIENT_LEN); + client->id); silc_free(channel_id); /* Change the mode back if we changed it */ @@ -1139,7 +1138,7 @@ void silc_server_command_reply(SilcServer server, if (packet->dst_id_type == SILC_ID_SERVER) { /* For now this must be for us */ - if (SILC_ID_SERVER_COMPARE(packet->dst_id, server->id_string)) { + if (memcmp(packet->dst_id, server->id_string, packet->dst_id_len)) { SILC_LOG_ERROR(("Cannot process command reply to unknown server")); return; } @@ -1216,7 +1215,7 @@ void silc_server_channel_message(SilcServer server, if (packet->src_id_type == SILC_ID_CLIENT) { silc_list_start(channel->user_list); while ((chl = silc_list_get(channel->user_list)) != SILC_LIST_END) { - if (chl->client && !SILC_ID_CLIENT_COMPARE(chl->client->id, sender)) { + if (chl->client && SILC_ID_CLIENT_COMPARE(chl->client->id, sender)) { sender_entry = chl->client; break; } @@ -1280,6 +1279,7 @@ SilcClientEntry silc_server_new_client(SilcServer server, SilcBuffer reply; SilcIDListData idata; char *username = NULL, *realname = NULL, *id_string; + uint32 id_len; int ret; SILC_LOG_DEBUG(("Creating new client")); @@ -1337,6 +1337,7 @@ SilcClientEntry silc_server_new_client(SilcServer server, client->username = username; client->userinfo = realname ? realname : strdup(" "); client->id = client_id; + id_len = silc_id_get_len(client_id, SILC_ID_CLIENT); /* Update the cache entry */ cache->id = (void *)client_id; @@ -1350,16 +1351,16 @@ SilcClientEntry silc_server_new_client(SilcServer server, silc_server_send_new_id(server, (SilcSocketConnection) server->router->connection, server->server_type == SILC_ROUTER ? TRUE : FALSE, - client->id, SILC_ID_CLIENT, SILC_ID_CLIENT_LEN); + client->id, SILC_ID_CLIENT, id_len); /* Send the new client ID to the client. */ id_string = silc_id_id2str(client->id, SILC_ID_CLIENT); - reply = silc_buffer_alloc(2 + 2 + SILC_ID_CLIENT_LEN); + reply = silc_buffer_alloc(2 + 2 + id_len); silc_buffer_pull_tail(reply, SILC_BUFFER_END(reply)); silc_buffer_format(reply, SILC_STR_UI_SHORT(SILC_ID_CLIENT), - SILC_STR_UI_SHORT(SILC_ID_CLIENT_LEN), - SILC_STR_UI_XNSTRING(id_string, SILC_ID_CLIENT_LEN), + SILC_STR_UI_SHORT(id_len), + SILC_STR_UI_XNSTRING(id_string, id_len), SILC_STR_END); silc_server_packet_send(server, sock, SILC_PACKET_NEW_ID, 0, reply->data, reply->len, FALSE); @@ -1508,7 +1509,7 @@ SilcServerEntry silc_server_new_server(SilcServer server, server->router->connection != sock) silc_server_send_new_id(server, server->router->connection, TRUE, new_server->id, SILC_ID_SERVER, - SILC_ID_SERVER_LEN); + silc_id_get_len(server_id, SILC_ID_SERVER)); if (server->server_type == SILC_ROUTER) server->stat.cell_servers++; @@ -1624,7 +1625,7 @@ static void silc_server_new_id_real(SilcServer server, case SILC_ID_SERVER: /* If the ID is mine, ignore it. */ - if (!SILC_ID_SERVER_COMPARE(id, server->id)) { + if (SILC_ID_SERVER_COMPARE(id, server->id)) { SILC_LOG_DEBUG(("Ignoring my own ID as new ID")); break; } @@ -1834,14 +1835,12 @@ void silc_server_new_channel(SilcServer server, if (!channel->id) channel_id = silc_id_dup(channel_id, SILC_ID_CHANNEL); - if (SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) { + if (!SILC_ID_CHANNEL_COMPARE(channel_id, channel->id)) { /* They don't match, send CHANNEL_CHANGE notify to the server to force the ID change. */ SILC_LOG_DEBUG(("Forcing the server to change Channel ID")); silc_server_send_notify_channel_change(server, sock, FALSE, - channel_id, - channel->id, - SILC_ID_CHANNEL_LEN); + channel_id, channel->id); } /* If the mode is different from what we have then enforce the @@ -1851,7 +1850,7 @@ void silc_server_new_channel(SilcServer server, SILC_LOG_DEBUG(("Forcing the server to change channel mode")); silc_server_send_notify_cmode(server, sock, FALSE, channel, channel->mode, server->id, - SILC_ID_SERVER, SILC_ID_SERVER_LEN, + SILC_ID_SERVER, channel->cipher, channel->hmac_name); } diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 814758b8..dc0d84a1 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -129,14 +129,14 @@ void silc_server_packet_send_dest(SilcServer server, if (dst_id) { dst_id_data = silc_id_id2str(dst_id, dst_id_type); - dst_id_len = silc_id_get_len(dst_id_type); + dst_id_len = silc_id_get_len(dst_id, dst_id_type); } /* Set the packet context pointers */ packetdata.type = type; packetdata.flags = flags; packetdata.src_id = silc_id_id2str(server->id, server->id_type); - packetdata.src_id_len = SILC_ID_SERVER_LEN; + packetdata.src_id_len = silc_id_get_len(server->id, server->id_type); packetdata.src_id_type = server->id_type; packetdata.dst_id = dst_id_data; packetdata.dst_id_len = dst_id_len; @@ -220,12 +220,12 @@ void silc_server_packet_send_srcdest(SilcServer server, if (dst_id) { dst_id_data = silc_id_id2str(dst_id, dst_id_type); - dst_id_len = silc_id_get_len(dst_id_type); + dst_id_len = silc_id_get_len(dst_id, dst_id_type); } if (src_id) { src_id_data = silc_id_id2str(src_id, src_id_type); - src_id_len = silc_id_get_len(src_id_type); + src_id_len = silc_id_get_len(src_id, src_id_type); } /* Set the packet context pointers */ @@ -298,7 +298,7 @@ void silc_server_packet_broadcast(SilcServer server, /* If the packet is originated from our primary route we are not allowed to send the packet. */ id = silc_id_str2id(packet->src_id, packet->src_id_len, packet->src_id_type); - if (id && SILC_ID_SERVER_COMPARE(id, server->router->id)) { + if (id && !SILC_ID_SERVER_COMPARE(id, server->router->id)) { idata = (SilcIDListData)sock->user_data; silc_buffer_push(buffer, buffer->data - buffer->head); @@ -431,11 +431,11 @@ void silc_server_packet_send_to_channel(SilcServer server, packetdata.flags = 0; packetdata.type = type; packetdata.src_id = silc_id_id2str(server->id, SILC_ID_SERVER); - packetdata.src_id_len = SILC_ID_SERVER_LEN; + packetdata.src_id_len = silc_id_get_len(server->id, SILC_ID_SERVER); packetdata.src_id_type = SILC_ID_SERVER; packetdata.dst_id = silc_id_id2str(channel->id, SILC_ID_CHANNEL); packetdata.dst_id_len = SILC_ID_CHANNEL_LEN; - packetdata.dst_id_type = SILC_ID_CHANNEL; + packetdata.dst_id_type = silc_id_get_len(channel->id, SILC_ID_CHANNEL); packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN + packetdata.src_id_len + packetdata.dst_id_len; packetdata.padlen = SILC_PACKET_PADLEN(packetdata.truelen); @@ -611,11 +611,11 @@ void silc_server_packet_relay_to_channel(SilcServer server, packetdata.flags = 0; packetdata.type = SILC_PACKET_CHANNEL_MESSAGE; packetdata.src_id = silc_id_id2str(sender, sender_type); - packetdata.src_id_len = silc_id_get_len(sender_type); + packetdata.src_id_len = silc_id_get_len(sender, sender_type); packetdata.src_id_type = sender_type; packetdata.dst_id = silc_id_id2str(channel->id, SILC_ID_CHANNEL); packetdata.dst_id_len = SILC_ID_CHANNEL_LEN; - packetdata.dst_id_type = SILC_ID_CHANNEL; + packetdata.dst_id_type = silc_id_get_len(channel->id, SILC_ID_CHANNEL); packetdata.padlen = SILC_PACKET_PADLEN((SILC_PACKET_HEADER_LEN + packetdata.src_id_len + packetdata.dst_id_len)); @@ -662,7 +662,7 @@ void silc_server_packet_relay_to_channel(SilcServer server, /* If sender is one on the channel do not send it the packet. */ if (!found && sender_type == SILC_ID_CLIENT && - !SILC_ID_CLIENT_COMPARE(client->id, sender)) { + SILC_ID_CLIENT_COMPARE(client->id, sender)) { found = TRUE; continue; } @@ -674,7 +674,7 @@ void silc_server_packet_relay_to_channel(SilcServer server, /* Sender maybe server as well so we want to make sure that we won't send the message to the server it came from. */ - if (!found && !SILC_ID_SERVER_COMPARE(client->router->id, sender)) { + if (!found && SILC_ID_SERVER_COMPARE(client->router->id, sender)) { found = TRUE; continue; } @@ -963,8 +963,7 @@ void silc_server_send_notify_channel_change(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelID *old_id, - SilcChannelID *new_id, - uint32 id_len) + SilcChannelID *new_id) { SilcBuffer idp1, idp2; @@ -985,8 +984,7 @@ void silc_server_send_notify_nick_change(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *old_id, - SilcClientID *new_id, - uint32 id_len) + SilcClientID *new_id) { SilcBuffer idp1, idp2; @@ -1007,8 +1005,7 @@ void silc_server_send_notify_join(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, - SilcClientID *client_id, - uint32 client_id_len) + SilcClientID *client_id) { SilcBuffer idp1, idp2; @@ -1028,8 +1025,7 @@ void silc_server_send_notify_leave(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, - SilcClientID *client_id, - uint32 client_id_len) + SilcClientID *client_id) { SilcBuffer idp; @@ -1050,7 +1046,6 @@ void silc_server_send_notify_cmode(SilcServer server, SilcChannelEntry channel, uint32 mode_mask, void *id, SilcIdType id_type, - uint32 id_len, char *cipher, char *hmac) { SilcBuffer idp; @@ -1078,9 +1073,7 @@ void silc_server_send_notify_cumode(SilcServer server, SilcChannelEntry channel, uint32 mode_mask, void *id, SilcIdType id_type, - uint32 id_len, - SilcClientID *target, - uint32 target_len) + SilcClientID *target) { SilcBuffer idp1, idp2; unsigned char mode[4]; @@ -1108,7 +1101,6 @@ void silc_server_send_notify_signoff(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *client_id, - uint32 client_id_len, char *message) { SilcBuffer idp; @@ -1131,7 +1123,6 @@ void silc_server_send_notify_topic_set(SilcServer server, int broadcast, SilcChannelEntry channel, SilcClientID *client_id, - uint32 client_id_len, char *topic) { SilcBuffer idp; @@ -1155,7 +1146,6 @@ void silc_server_send_notify_kicked(SilcServer server, int broadcast, SilcChannelEntry channel, SilcClientID *client_id, - uint32 client_id_len, char *comment) { SilcBuffer idp; @@ -1176,7 +1166,6 @@ void silc_server_send_notify_killed(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *client_id, - uint32 client_id_len, char *comment) { SilcBuffer idp; @@ -1197,7 +1186,6 @@ void silc_server_send_notify_umode(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *client_id, - uint32 client_id_len, uint32 mode_mask) { SilcBuffer idp; @@ -1244,7 +1232,6 @@ void silc_server_send_notify_invite(SilcServer server, int broadcast, SilcChannelEntry channel, SilcClientID *client_id, - uint32 client_id_len, char *add, char *del) { SilcBuffer idp, idp2; @@ -1354,7 +1341,7 @@ void silc_server_send_notify_on_channels(SilcServer server, packetdata.flags = 0; packetdata.type = SILC_PACKET_NOTIFY; packetdata.src_id = silc_id_id2str(server->id, SILC_ID_SERVER); - packetdata.src_id_len = SILC_ID_SERVER_LEN; + packetdata.src_id_len = silc_id_get_len(server->id, SILC_ID_SERVER); packetdata.src_id_type = SILC_ID_SERVER; silc_list_start(client->channels); @@ -1392,7 +1379,7 @@ void silc_server_send_notify_on_channels(SilcServer server, idata = (SilcIDListData)c->router; packetdata.dst_id = silc_id_id2str(c->router->id, SILC_ID_SERVER); - packetdata.dst_id_len = SILC_ID_SERVER_LEN; + packetdata.dst_id_len = silc_id_get_len(c->router->id, SILC_ID_SERVER); packetdata.dst_id_type = SILC_ID_SERVER; packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN + packetdata.src_id_len + packetdata.dst_id_len; @@ -1428,7 +1415,7 @@ void silc_server_send_notify_on_channels(SilcServer server, idata = (SilcIDListData)c; packetdata.dst_id = silc_id_id2str(c->id, SILC_ID_CLIENT); - packetdata.dst_id_len = SILC_ID_CLIENT_LEN; + packetdata.dst_id_len = silc_id_get_len(c->id, SILC_ID_CLIENT); packetdata.dst_id_type = SILC_ID_CLIENT; packetdata.truelen = data_len + SILC_PACKET_HEADER_LEN + packetdata.src_id_len + packetdata.dst_id_len; @@ -1543,7 +1530,9 @@ void silc_server_send_channel_key(SilcServer server, /* Encode channel key packet */ tmp_len = strlen(channel->channel_key->cipher->name); - packet = silc_channel_key_payload_encode(SILC_ID_CHANNEL_LEN, chid, tmp_len, + packet = silc_channel_key_payload_encode(silc_id_get_len(channel->id, + SILC_ID_CHANNEL), + chid, tmp_len, channel->channel_key->cipher->name, channel->key_len / 8, channel->key); diff --git a/apps/silcd/packet_send.h b/apps/silcd/packet_send.h index 944284cf..5a185233 100644 --- a/apps/silcd/packet_send.h +++ b/apps/silcd/packet_send.h @@ -108,33 +108,28 @@ void silc_server_send_notify_channel_change(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelID *old_id, - SilcChannelID *new_id, - uint32 id_len); + SilcChannelID *new_id); void silc_server_send_notify_nick_change(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *old_id, - SilcClientID *new_id, - uint32 id_len); + SilcClientID *new_id); void silc_server_send_notify_join(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, - SilcClientID *client_id, - uint32 client_id_len); + SilcClientID *client_id); void silc_server_send_notify_leave(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, - SilcClientID *client_id, - uint32 client_id_len); + SilcClientID *client_id); void silc_server_send_notify_cmode(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, uint32 mode_mask, void *id, SilcIdType id_type, - uint32 id_len, char *cipher, char *hmac); void silc_server_send_notify_cumode(SilcServer server, SilcSocketConnection sock, @@ -142,40 +137,33 @@ void silc_server_send_notify_cumode(SilcServer server, SilcChannelEntry channel, uint32 mode_mask, void *id, SilcIdType id_type, - uint32 id_len, - SilcClientID *target, - uint32 target_len); + SilcClientID *target); void silc_server_send_notify_signoff(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *client_id, - uint32 client_id_len, char *message); void silc_server_send_notify_topic_set(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, SilcClientID *client_id, - uint32 client_id_len, char *topic); void silc_server_send_notify_kicked(SilcServer server, SilcSocketConnection sock, int broadcast, SilcChannelEntry channel, SilcClientID *client_id, - uint32 client_id_len, char *comment); void silc_server_send_notify_killed(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *client_id, - uint32 client_id_len, char *comment); void silc_server_send_notify_umode(SilcServer server, SilcSocketConnection sock, int broadcast, SilcClientID *client_id, - uint32 client_id_len, uint32 mode_mask); void silc_server_send_notify_ban(SilcServer server, SilcSocketConnection sock, @@ -187,7 +175,6 @@ void silc_server_send_notify_invite(SilcServer server, int broadcast, SilcChannelEntry channel, SilcClientID *client_id, - uint32 client_id_len, char *add, char *del); void silc_server_send_notify_dest(SilcServer server, SilcSocketConnection sock, diff --git a/apps/silcd/route.c b/apps/silcd/route.c index f166075a..eac09e64 100644 --- a/apps/silcd/route.c +++ b/apps/silcd/route.c @@ -72,9 +72,10 @@ SilcSocketConnection silc_server_route_get(SilcServer server, void *id, SilcIdType id_type) { if (server->server_type == SILC_ROUTER) { - uint32 dest; - uint16 port; + uint32 dest = 0; + uint16 port = 0; SilcServerEntry router = NULL; +#if 0 switch(id_type) { case SILC_ID_CLIENT: @@ -93,6 +94,8 @@ SilcSocketConnection silc_server_route_get(SilcServer server, void *id, return NULL; } +#endif + router = silc_server_route_check(dest, port); if (!router) return (SilcSocketConnection)server->id_entry->router->connection; diff --git a/apps/silcd/server.c b/apps/silcd/server.c index eaa5eaf4..e6a89600 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -216,7 +216,7 @@ int silc_server_init(SilcServer server) server->id = id; server->id_string = silc_id_id2str(id, SILC_ID_SERVER); - server->id_string_len = silc_id_get_len(SILC_ID_SERVER); + server->id_string_len = silc_id_get_len(id, SILC_ID_SERVER); server->id_type = SILC_ID_SERVER; server->server_name = server->config->server_info->server_name; @@ -828,6 +828,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_final) SilcBuffer packet; SilcServerHBContext hb_context; unsigned char *id_string; + uint32 id_len; SilcIDListData idata; SILC_LOG_DEBUG(("Start")); @@ -856,12 +857,12 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_final) /* Send NEW_SERVER packet to the router. We will become registered to the SILC network after sending this packet. */ id_string = silc_id_id2str(server->id, SILC_ID_SERVER); - packet = silc_buffer_alloc(2 + 2 + SILC_ID_SERVER_LEN + - strlen(server->server_name)); + id_len = silc_id_get_len(server->id, SILC_ID_SERVER); + packet = silc_buffer_alloc(2 + 2 + id_len + strlen(server->server_name)); silc_buffer_pull_tail(packet, SILC_BUFFER_END(packet)); silc_buffer_format(packet, - SILC_STR_UI_SHORT(SILC_ID_SERVER_LEN), - SILC_STR_UI_XNSTRING(id_string, SILC_ID_SERVER_LEN), + SILC_STR_UI_SHORT(id_len), + SILC_STR_UI_XNSTRING(id_string, id_len), SILC_STR_UI_SHORT(strlen(server->server_name)), SILC_STR_UI_XNSTRING(server->server_name, strlen(server->server_name)), @@ -1538,7 +1539,7 @@ SILC_TASK_CALLBACK(silc_server_packet_parse_real) if (client && client->id) { void *id = silc_id_str2id(packet->src_id, packet->src_id_len, packet->src_id_type); - if (!id || SILC_ID_CLIENT_COMPARE(client->id, id)) { + if (!id || !SILC_ID_CLIENT_COMPARE(client->id, id)) { silc_free(id); goto out; } @@ -1552,7 +1553,7 @@ SILC_TASK_CALLBACK(silc_server_packet_parse_real) if (!(packet->flags & SILC_PACKET_FLAG_BROADCAST) && packet->dst_id_type == SILC_ID_SERVER && sock->type != SILC_SOCKET_TYPE_CLIENT && - SILC_ID_SERVER_COMPARE(packet->dst_id, server->id_string)) { + memcmp(packet->dst_id, server->id_string, packet->dst_id_len)) { /* Route the packet to fastest route for the destination ID */ void *id = silc_id_str2id(packet->dst_id, packet->dst_id_len, @@ -2179,8 +2180,7 @@ void silc_server_free_client_data(SilcServer server, if (notify && !server->standalone && server->router) silc_server_send_notify_signoff(server, server->router->connection, server->server_type == SILC_SERVER ? - FALSE : TRUE, client->id, - SILC_ID_CLIENT_LEN, signoff); + FALSE : TRUE, client->id, signoff); /* Remove client from all channels */ if (notify) @@ -2806,7 +2806,8 @@ SilcChannelEntry silc_server_create_new_channel(SilcServer server, to our primary route. */ if (broadcast && server->standalone == FALSE) silc_server_send_new_channel(server, server->router->connection, TRUE, - channel_name, entry->id, SILC_ID_CHANNEL_LEN, + channel_name, entry->id, + silc_id_get_len(entry->id, SILC_ID_CHANNEL), entry->mode); server->stat.my_channels++; @@ -2864,7 +2865,8 @@ silc_server_create_new_channel_with_id(SilcServer server, to our primary route. */ if (broadcast && server->standalone == FALSE) silc_server_send_new_channel(server, server->router->connection, TRUE, - channel_name, entry->id, SILC_ID_CHANNEL_LEN, + channel_name, entry->id, + silc_id_get_len(entry->id, SILC_ID_CHANNEL), entry->mode); server->stat.my_channels++; @@ -3312,6 +3314,7 @@ void silc_server_announce_get_channels(SilcServer server, SilcIDCacheEntry id_cache; SilcChannelEntry channel; unsigned char *cid; + uint32 id_len; uint16 name_len; int len; @@ -3325,9 +3328,10 @@ void silc_server_announce_get_channels(SilcServer server, channel = (SilcChannelEntry)id_cache->context; cid = silc_id_id2str(channel->id, SILC_ID_CHANNEL); + id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL); name_len = strlen(channel->channel_name); - len = 4 + name_len + SILC_ID_CHANNEL_LEN + 4; + len = 4 + name_len + id_len + 4; *channels = silc_buffer_realloc(*channels, (*channels ? (*channels)->truelen + len : len)); @@ -3337,8 +3341,8 @@ void silc_server_announce_get_channels(SilcServer server, SILC_STR_UI_SHORT(name_len), SILC_STR_UI_XNSTRING(channel->channel_name, name_len), - SILC_STR_UI_SHORT(SILC_ID_CHANNEL_LEN), - SILC_STR_UI_XNSTRING(cid, SILC_ID_CHANNEL_LEN), + SILC_STR_UI_SHORT(id_len), + SILC_STR_UI_XNSTRING(cid, id_len), SILC_STR_UI_INT(channel->mode), SILC_STR_END); silc_buffer_pull(*channels, len); @@ -3456,6 +3460,8 @@ void silc_server_get_users_on_channel(SilcServer server, SilcBuffer idp; uint32 list_count = 0; + /* XXX rewrite - this does not support IPv6 based Client ID's. */ + client_id_list = silc_buffer_alloc((SILC_ID_CLIENT_LEN + 4) * silc_list_count(channel->user_list)); client_mode_list = silc_buffer_alloc(4 * @@ -3519,7 +3525,7 @@ void silc_server_save_users_on_channel(SilcServer server, SILC_GET32_MSB(mode, mode_list->data); silc_buffer_pull(mode_list, 4); - if (noadd && !SILC_ID_CLIENT_COMPARE(client_id, noadd)) { + if (noadd && SILC_ID_CLIENT_COMPARE(client_id, noadd)) { silc_free(client_id); continue; } @@ -3660,6 +3666,7 @@ SilcBuffer silc_server_get_client_channel_list(SilcServer server, SilcChannelEntry channel; SilcChannelClientEntry chl; unsigned char *cid; + uint32 id_len; uint16 name_len; int len; @@ -3671,9 +3678,10 @@ SilcBuffer silc_server_get_client_channel_list(SilcServer server, continue; cid = silc_id_id2str(channel->id, SILC_ID_CHANNEL); + id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL); name_len = strlen(channel->channel_name); - len = 4 + name_len + SILC_ID_CHANNEL_LEN + 4; + len = 4 + name_len + id_len + 4; buffer = silc_buffer_realloc(buffer, (buffer ? (buffer)->truelen + len : len)); silc_buffer_pull_tail(buffer, ((buffer)->end - (buffer)->data)); @@ -3681,8 +3689,8 @@ SilcBuffer silc_server_get_client_channel_list(SilcServer server, SILC_STR_UI_SHORT(name_len), SILC_STR_UI_XNSTRING(channel->channel_name, name_len), - SILC_STR_UI_SHORT(SILC_ID_CHANNEL_LEN), - SILC_STR_UI_XNSTRING(cid, SILC_ID_CHANNEL_LEN), + SILC_STR_UI_SHORT(id_len), + SILC_STR_UI_XNSTRING(cid, id_len), SILC_STR_UI_INT(chl->mode), /* Client's mode */ SILC_STR_END); silc_buffer_pull(buffer, len); diff --git a/apps/silcd/serverid.c b/apps/silcd/serverid.c index d4061dd4..42a5afe5 100644 --- a/apps/silcd/serverid.c +++ b/apps/silcd/serverid.c @@ -44,7 +44,8 @@ void silc_id_create_server_id(int sock, SilcRng rng, SilcServerID **new_id) } /* Create the ID */ - (*new_id)->ip = server.sin_addr; + SILC_PUT32_MSB(server.sin_addr.s_addr, (*new_id)->ip.data); + (*new_id)->ip.data_len = 4; (*new_id)->port = server.sin_port; (*new_id)->rnd = silc_rng_get_rn16(rng); @@ -67,7 +68,8 @@ void silc_id_create_client_id(SilcServerID *server_id, SilcRng rng, silc_hash_make(md5hash, nickname, strlen(nickname), hash); /* Create the ID */ - (*new_id)->ip.s_addr = server_id->ip.s_addr; + memcpy((*new_id)->ip.data, server_id->ip.data, server_id->ip.data_len); + (*new_id)->ip.data_len = server_id->ip.data_len; (*new_id)->rnd = silc_rng_get_byte(rng); memcpy((*new_id)->hash, hash, CLIENTID_HASH_LEN); @@ -84,7 +86,8 @@ void silc_id_create_channel_id(SilcServerID *router_id, SilcRng rng, *new_id = silc_calloc(1, sizeof(**new_id)); /* Create the ID */ - (*new_id)->ip.s_addr = router_id->ip.s_addr; + memcpy((*new_id)->ip.data, router_id->ip.data, router_id->ip.data_len); + (*new_id)->ip.data_len = router_id->ip.data_len; (*new_id)->port = router_id->port; (*new_id)->rnd = silc_rng_get_rn16(rng); diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index f870a2a3..1609cbe1 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -553,7 +553,7 @@ SILC_TASK_CALLBACK(silc_client_connect_to_server_final) /* Save remote ID. */ conn->remote_id = ctx->dest_id; conn->remote_id_data = silc_id_id2str(ctx->dest_id, SILC_ID_SERVER); - conn->remote_id_data_len = SILC_ID_SERVER_LEN; + conn->remote_id_data_len = silc_id_get_len(ctx->dest_id, SILC_ID_SERVER); /* Register re-key timeout */ conn->rekey->timeout = 3600; /* XXX hardcoded */ @@ -1088,15 +1088,19 @@ void silc_client_packet_send(SilcClient client, packetdata.flags = 0; packetdata.type = type; if (sock->user_data && - ((SilcClientConnection)sock->user_data)->local_id_data) + ((SilcClientConnection)sock->user_data)->local_id_data) { packetdata.src_id = ((SilcClientConnection)sock->user_data)->local_id_data; - else + packetdata.src_id_len = + silc_id_get_len(((SilcClientConnection)sock->user_data)->local_id, + SILC_ID_CLIENT); + } else { packetdata.src_id = silc_calloc(SILC_ID_CLIENT_LEN, sizeof(unsigned char)); - packetdata.src_id_len = SILC_ID_CLIENT_LEN; + packetdata.src_id_len = SILC_ID_CLIENT_LEN; + } packetdata.src_id_type = SILC_ID_CLIENT; if (dst_id) { packetdata.dst_id = silc_id_id2str(dst_id, dst_id_type); - packetdata.dst_id_len = silc_id_get_len(dst_id_type); + packetdata.dst_id_len = silc_id_get_len(dst_id, dst_id_type); packetdata.dst_id_type = dst_id_type; } else { packetdata.dst_id = NULL; @@ -1185,15 +1189,19 @@ void silc_client_packet_send_flush(SilcClient client, packetdata.flags = 0; packetdata.type = type; if (sock->user_data && - ((SilcClientConnection)sock->user_data)->local_id_data) + ((SilcClientConnection)sock->user_data)->local_id_data) { packetdata.src_id = ((SilcClientConnection)sock->user_data)->local_id_data; - else + packetdata.src_id_len = + silc_id_get_len(((SilcClientConnection)sock->user_data)->local_id, + SILC_ID_CLIENT); + } else { packetdata.src_id = silc_calloc(SILC_ID_CLIENT_LEN, sizeof(unsigned char)); - packetdata.src_id_len = SILC_ID_CLIENT_LEN; + packetdata.src_id_len = SILC_ID_CLIENT_LEN; + } packetdata.src_id_type = SILC_ID_CLIENT; if (dst_id) { packetdata.dst_id = silc_id_id2str(dst_id, dst_id_type); - packetdata.dst_id_len = silc_id_get_len(dst_id_type); + packetdata.dst_id_len = silc_id_get_len(dst_id, dst_id_type); packetdata.dst_id_type = dst_id_type; } else { packetdata.dst_id = NULL; diff --git a/lib/silcclient/client_channel.c b/lib/silcclient/client_channel.c index 62396c5f..f3dff85b 100644 --- a/lib/silcclient/client_channel.c +++ b/lib/silcclient/client_channel.c @@ -109,10 +109,10 @@ void silc_client_send_channel_message(SilcClient client, packetdata.flags = 0; packetdata.type = SILC_PACKET_CHANNEL_MESSAGE; packetdata.src_id = conn->local_id_data; - packetdata.src_id_len = SILC_ID_CLIENT_LEN; + packetdata.src_id_len = silc_id_get_len(conn->local_id, SILC_ID_CLIENT); packetdata.src_id_type = SILC_ID_CLIENT; packetdata.dst_id = id_string; - packetdata.dst_id_len = SILC_ID_CHANNEL_LEN; + packetdata.dst_id_len = silc_id_get_len(channel->id, SILC_ID_CHANNEL); packetdata.dst_id_type = SILC_ID_CHANNEL; packetdata.truelen = payload->len + SILC_PACKET_HEADER_LEN + packetdata.src_id_len + packetdata.dst_id_len; @@ -222,7 +222,7 @@ void silc_client_channel_message(SilcClient client, /* Find client entry */ silc_list_start(channel->clients); while ((chu = silc_list_get(channel->clients)) != SILC_LIST_END) { - if (!SILC_ID_CLIENT_COMPARE(chu->client->id, client_id)) { + if (SILC_ID_CLIENT_COMPARE(chu->client->id, client_id)) { found = TRUE; break; } diff --git a/lib/silcclient/client_notify.c b/lib/silcclient/client_notify.c index 2bd0aeb6..109fb0a7 100644 --- a/lib/silcclient/client_notify.c +++ b/lib/silcclient/client_notify.c @@ -365,7 +365,7 @@ void silc_client_notify_by_server(SilcClient client, goto out; /* Ignore my ID */ - if (!SILC_ID_CLIENT_COMPARE(client_id, conn->local_id)) + if (SILC_ID_CLIENT_COMPARE(client_id, conn->local_id)) break; /* Find old Client entry */ diff --git a/lib/silcclient/client_prvmsg.c b/lib/silcclient/client_prvmsg.c index cc0155b2..2df8325d 100644 --- a/lib/silcclient/client_prvmsg.c +++ b/lib/silcclient/client_prvmsg.c @@ -74,10 +74,10 @@ void silc_client_send_private_message(SilcClient client, packetdata.flags = SILC_PACKET_FLAG_PRIVMSG_KEY; packetdata.type = SILC_PACKET_PRIVATE_MESSAGE; packetdata.src_id = conn->local_id_data; - packetdata.src_id_len = SILC_ID_CLIENT_LEN; + packetdata.src_id_len = silc_id_get_len(conn->local_id, SILC_ID_CLIENT); packetdata.src_id_type = SILC_ID_CLIENT; packetdata.dst_id = silc_id_id2str(client_entry->id, SILC_ID_CLIENT); - packetdata.dst_id_len = SILC_ID_CLIENT_LEN; + packetdata.dst_id_len = silc_id_get_len(client_entry->id, SILC_ID_CLIENT); packetdata.dst_id_type = SILC_ID_CLIENT; packetdata.truelen = buffer->len + SILC_PACKET_HEADER_LEN + packetdata.src_id_len + packetdata.dst_id_len; @@ -181,7 +181,7 @@ void silc_client_private_message(SilcClient client, sender with the set away message. */ if (conn->away && conn->away->away) { /* If it's me, ignore */ - if (!SILC_ID_CLIENT_COMPARE(remote_id, conn->local_id)) + if (SILC_ID_CLIENT_COMPARE(remote_id, conn->local_id)) goto out; /* Send the away message */ diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index ffa55d5c..0ad1e136 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -862,7 +862,8 @@ SILC_CLIENT_CMD_FUNC(ping) /* Send the command */ buffer = silc_command_payload_encode_va(SILC_COMMAND_PING, 0, 1, 1, conn->remote_id_data, - SILC_ID_SERVER_LEN); + silc_id_get_len(conn->remote_id, + SILC_ID_SERVER)); silc_client_packet_send(cmd->client, conn->sock, SILC_PACKET_COMMAND, NULL, 0, NULL, NULL, buffer->data, buffer->len, TRUE); silc_buffer_free(buffer); diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index d91710fa..8029eefb 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -874,7 +874,7 @@ SILC_CLIENT_CMD_REPLY_FUNC(ping) } for (i = 0; i < conn->ping_count; i++) { - if (!SILC_ID_SERVER_COMPARE(conn->ping[i].dest_id, id)) { + if (SILC_ID_SERVER_COMPARE(conn->ping[i].dest_id, id)) { diff = curtime - conn->ping[i].start_time; cmd->client->ops->say(cmd->client, conn, "Ping reply from %s: %d second%s", diff --git a/lib/silccore/id.c b/lib/silccore/id.c index f39783ce..51c95d95 100644 --- a/lib/silccore/id.c +++ b/lib/silccore/id.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2000 Pekka Riikonen + Copyright (C) 1997 - 2001 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -20,6 +20,12 @@ /* $Id$ */ #include "silcincludes.h" +#include "id.h" + +/* ID lengths (in bytes) without the IP address part */ +#define ID_SERVER_LEN_PART 4 +#define ID_CLIENT_LEN_PART CLIENTID_HASH_LEN + 1 +#define ID_CHANNEL_LEN_PART 4 /* Converts ID to string. */ @@ -29,28 +35,29 @@ unsigned char *silc_id_id2str(void *id, SilcIdType type) SilcServerID *server_id; SilcClientID *client_id; SilcChannelID *channel_id; + uint32 id_len = silc_id_get_len(id, type); switch(type) { case SILC_ID_SERVER: server_id = (SilcServerID *)id; - ret_id = silc_calloc(8, sizeof(unsigned char)); - SILC_PUT32_MSB(server_id->ip.s_addr, ret_id); + ret_id = silc_calloc(id_len, sizeof(unsigned char)); + memcpy(ret_id, server_id->ip.data, server_id->ip.data_len); SILC_PUT16_MSB(server_id->port, &ret_id[4]); SILC_PUT16_MSB(server_id->rnd, &ret_id[6]); return ret_id; break; case SILC_ID_CLIENT: client_id = (SilcClientID *)id; - ret_id = silc_calloc(16, sizeof(unsigned char)); - SILC_PUT32_MSB(client_id->ip.s_addr, ret_id); + ret_id = silc_calloc(id_len, sizeof(unsigned char)); + memcpy(ret_id, client_id->ip.data, client_id->ip.data_len); ret_id[4] = client_id->rnd; memcpy(&ret_id[5], client_id->hash, CLIENTID_HASH_LEN); return ret_id; break; case SILC_ID_CHANNEL: channel_id = (SilcChannelID *)id; - ret_id = silc_calloc(8, sizeof(unsigned char)); - SILC_PUT32_MSB(channel_id->ip.s_addr, ret_id); + ret_id = silc_calloc(id_len, sizeof(unsigned char)); + memcpy(ret_id, channel_id->ip.data, channel_id->ip.data_len); SILC_PUT16_MSB(channel_id->port, &ret_id[4]); SILC_PUT16_MSB(channel_id->rnd, &ret_id[6]); return ret_id; @@ -70,11 +77,14 @@ void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type) { SilcServerID *server_id; - if (id_len != SILC_ID_SERVER_LEN) + if (id_len != ID_SERVER_LEN_PART + 4 && + id_len != ID_SERVER_LEN_PART + 16) return NULL; server_id = silc_calloc(1, sizeof(*server_id)); - SILC_GET32_MSB(server_id->ip.s_addr, id); + memcpy(server_id->ip.data, id, (id_len > ID_SERVER_LEN_PART + 4 ? + 16 : 4)); + server_id->ip.data_len = (id_len > ID_SERVER_LEN_PART + 4 ? 16 : 4); SILC_GET16_MSB(server_id->port, &id[4]); SILC_GET16_MSB(server_id->rnd, &id[6]); return server_id; @@ -84,11 +94,14 @@ void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type) { SilcClientID *client_id; - if (id_len != SILC_ID_CLIENT_LEN) + if (id_len != ID_CLIENT_LEN_PART + 4 && + id_len != ID_CLIENT_LEN_PART + 16) return NULL; client_id = silc_calloc(1, sizeof(*client_id)); - SILC_GET32_MSB(client_id->ip.s_addr, id); + memcpy(client_id->ip.data, id, (id_len > ID_CLIENT_LEN_PART + 4 ? + 16 : 4)); + client_id->ip.data_len = (id_len > ID_CLIENT_LEN_PART + 4 ? 16 : 4); client_id->rnd = id[4]; memcpy(client_id->hash, &id[5], CLIENTID_HASH_LEN); return client_id; @@ -98,11 +111,14 @@ void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type) { SilcChannelID *channel_id; - if (id_len != SILC_ID_CHANNEL_LEN) + if (id_len != ID_CHANNEL_LEN_PART + 4 && + id_len != ID_CHANNEL_LEN_PART + 16) return NULL; channel_id = silc_calloc(1, sizeof(*channel_id)); - SILC_GET32_MSB(channel_id->ip.s_addr, id); + memcpy(channel_id->ip.data, id, (id_len > ID_CHANNEL_LEN_PART + 4 ? + 16 : 4)); + channel_id->ip.data_len = (id_len > ID_CHANNEL_LEN_PART + 4 ? 16 : 4); SILC_GET16_MSB(channel_id->port, &id[4]); SILC_GET16_MSB(channel_id->rnd, &id[6]); return channel_id; @@ -115,17 +131,26 @@ void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type) /* Returns length of the ID */ -uint32 silc_id_get_len(SilcIdType type) +uint32 silc_id_get_len(void *id, SilcIdType type) { switch(type) { case SILC_ID_SERVER: - return SILC_ID_SERVER_LEN; + { + SilcServerID *server_id = (SilcServerID *)id; + return ID_SERVER_LEN_PART + server_id->ip.data_len; + } break; case SILC_ID_CLIENT: - return SILC_ID_CLIENT_LEN; + { + SilcClientID *client_id = (SilcClientID *)id; + return ID_CLIENT_LEN_PART + client_id->ip.data_len; + } break; case SILC_ID_CHANNEL: - return SILC_ID_CHANNEL_LEN; + { + SilcChannelID *channel_id = (SilcChannelID *)id; + return ID_CHANNEL_LEN_PART + channel_id->ip.data_len; + } break; } @@ -136,8 +161,84 @@ uint32 silc_id_get_len(SilcIdType type) void *silc_id_dup(void *id, SilcIdType type) { - int len = silc_id_get_len(type); - void *new = silc_calloc(1, len); - memcpy(new, id, len); - return new; + switch(type) { + case SILC_ID_SERVER: + { + SilcServerID *server_id = (SilcServerID *)id, *new; + new = silc_calloc(1, sizeof(*server_id)); + memcpy(&new->ip, &server_id->ip, sizeof(server_id->ip)); + new->port = server_id->port; + new->rnd = server_id->rnd; + return new; + } + break; + case SILC_ID_CLIENT: + { + SilcClientID *client_id = (SilcClientID *)id, *new; + new = silc_calloc(1, sizeof(*client_id)); + memcpy(&new->ip, &client_id->ip, sizeof(client_id->ip)); + new->rnd = client_id->rnd; + memcpy(new->hash, client_id->hash, CLIENTID_HASH_LEN); + return new; + } + break; + case SILC_ID_CHANNEL: + { + SilcChannelID *channel_id = (SilcChannelID *)id, *new; + new = silc_calloc(1, sizeof(*channel_id)); + memcpy(&new->ip, &channel_id->ip, sizeof(channel_id->ip)); + new->port = channel_id->port; + new->rnd = channel_id->rnd; + return new; + } + break; + } + + return NULL; +} + +/* Returns TRUE if the `id2' is equal to `id1'. */ + +bool silc_id_compare(void *id1, void *id2, SilcIdType type) +{ + switch(type) { + case SILC_ID_SERVER: + { + SilcServerID *server_id1 = (SilcServerID *)id1; + SilcServerID *server_id2 = (SilcServerID *)id2; + if (!memcmp(server_id1->ip.data, server_id2->ip.data, + server_id1->ip.data_len) && + server_id1->port == server_id2->port && + server_id1->rnd == server_id2->rnd) + return TRUE; + return FALSE; + } + break; + case SILC_ID_CLIENT: + { + SilcClientID *client_id1 = (SilcClientID *)id1; + SilcClientID *client_id2 = (SilcClientID *)id2; + if (!memcmp(client_id1->ip.data, client_id2->ip.data, + client_id1->ip.data_len) && + client_id1->rnd == client_id2->rnd && + !memcmp(client_id1->hash, client_id2->hash, CLIENTID_HASH_LEN)) + return TRUE; + return FALSE; + } + break; + case SILC_ID_CHANNEL: + { + SilcChannelID *channel_id1 = (SilcChannelID *)id1; + SilcChannelID *channel_id2 = (SilcChannelID *)id2; + if (!memcmp(channel_id1->ip.data, channel_id2->ip.data, + channel_id1->ip.data_len) && + channel_id1->port == channel_id2->port && + channel_id1->rnd == channel_id2->rnd) + return TRUE; + return FALSE; + } + break; + } + + return FALSE; } diff --git a/lib/silccore/id.h b/lib/silccore/id.h index 8fe79ad3..a024a25d 100644 --- a/lib/silccore/id.h +++ b/lib/silccore/id.h @@ -22,20 +22,12 @@ packet sending and reception. However, client never creates these but it receives the correct ID's from server. Clients, servers and channels are identified by the these ID's. - - Note that these are currently IPv4 specific, although adding IPv6 - support is not a bad task and SILC protocol already supports IPv6. */ #ifndef ID_H #define ID_H -#define SILC_ID_SERVER_LEN (64 / 8) -#define SILC_ID_CLIENT_LEN (128 / 8) -#define SILC_ID_CHANNEL_LEN (64 / 8) -#define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */ - -/* SILC ID Types */ +/* The SILC ID Types */ #define SILC_ID_NONE 0 #define SILC_ID_SERVER 1 #define SILC_ID_CLIENT 2 @@ -44,69 +36,78 @@ /* Type definition for the ID types. */ typedef uint16 SilcIdType; +/* The ID Lenghts. These are IPv4 based and should be noted if used directly + that these cannot be used with IPv6. */ +#define SILC_ID_SERVER_LEN (64 / 8) +#define SILC_ID_CLIENT_LEN (128 / 8) +#define SILC_ID_CHANNEL_LEN (64 / 8) + +#define CLIENTID_HASH_LEN (88 / 8) /* Client ID's 88 bit MD5 hash */ + +/* + SILC ID IP structure. + + Generic IP address structure to indicate either IPv4 or IPv6 address. + This structure is used inside all SILC ID's. The true length of the + ID depends of the length of the IP address. +*/ +typedef struct { + unsigned char data[16]; /* IP data */ + uint8 data_len; /* Length of the data (4 or 16) */ +} SilcIDIP; + /* - 64 bit SilcServerID structure: + 64 or 160 bit SilcServerID structure: - 32 bit IP address + n bit IP address 16 bit port 16 bit random number */ typedef struct { - struct in_addr ip; /* 32 bit IP */ - uint16 port; /* 16 bit port */ - uint16 rnd; /* 16 bit random number */ + SilcIDIP ip; /* n bit IP address */ + uint16 port; /* 16 bit port */ + uint16 rnd; /* 16 bit random number */ } SilcServerID; /* - 128 bit SilcClientID structure: + 128 or 224 bit SilcClientID structure: - 32 bit ServerID IP address [bits 1-32] + n bit ServerID IP address [bits 1-32 or bits 1-128] 8 bit random number 88 bit hash value from nickname */ typedef struct { - struct in_addr ip; /* 32 bit IP */ + SilcIDIP ip; /* n bit IP address */ unsigned char rnd; /* 8 bit random number */ unsigned char hash[CLIENTID_HASH_LEN]; /* 88 bit MD5 hash */ } SilcClientID; /* - 64 bit SilcChannel ID structure: + 64 or 160 bit SilcChannel ID structure: - 32 bit Router's ServerID IP address [bits 1-32] - 16 bit Router's ServerID port [bits 33-48] + n bit Router's ServerID IP address [bits 1-32 or bits 1-128] + 16 bit Router's ServerID port [bits 33-48 or bits 129-144] 16 bit random number */ typedef struct { - struct in_addr ip; /* 32 bit IP */ - uint16 port; /* 16 bit port */ - uint16 rnd; /* 16 bit random number */ + SilcIDIP ip; /* n bit IP address */ + uint16 port; /* 16 bit port */ + uint16 rnd; /* 16 bit random number */ } SilcChannelID; /* Macros */ -/* Compares two ID's */ -#define SILC_ID_COMPARE(id1, id2, len) (memcmp(id1, id2, len)) - -/* Compares Channel ID's */ -#define SILC_ID_CHANNEL_COMPARE(id1, id2) \ - SILC_ID_COMPARE(id1, id2, SILC_ID_CHANNEL_LEN) - /* Compares Client ID's */ -#define SILC_ID_CLIENT_COMPARE(id1, id2) \ - SILC_ID_COMPARE(id1, id2, SILC_ID_CLIENT_LEN) +#define SILC_ID_CLIENT_COMPARE(id1, id2) \ + silc_id_compare(id1, id2, SILC_ID_CLIENT) /* Compares Server ID's */ -#define SILC_ID_SERVER_COMPARE(id1, id2) \ - SILC_ID_COMPARE(id1, id2, SILC_ID_SERVER_LEN) +#define SILC_ID_SERVER_COMPARE(id1, id2) \ + silc_id_compare(id1, id2, SILC_ID_SERVER) /* Compares Channel ID's */ -#define SILC_ID_CHANNEL_COMPARE(id1, id2) \ - SILC_ID_COMPARE(id1, id2, SILC_ID_CHANNEL_LEN) - -/* Compares IP addresses from the ID's. */ -#define SILC_ID_COMPARE_IP(id1, id2) \ - SILC_ID_COMPARE(id1, id2, 4) +#define SILC_ID_CHANNEL_COMPARE(id1, id2) \ + silc_id_compare(id1, id2, SILC_ID_CHANNEL) /* Compare nickname hash from Client ID */ #define SILC_ID_COMPARE_HASH(id, _hash) \ @@ -115,7 +116,8 @@ typedef struct { /* Prototypes */ unsigned char *silc_id_id2str(void *id, SilcIdType type); void *silc_id_str2id(unsigned char *id, uint32 id_len, SilcIdType type); -uint32 silc_id_get_len(SilcIdType type); +uint32 silc_id_get_len(void *id, SilcIdType type); void *silc_id_dup(void *id, SilcIdType type); +bool silc_id_compare(void *id1, void *id2, SilcIdType type); #endif diff --git a/lib/silccore/idcache.c b/lib/silccore/idcache.c index caf6549f..164d1515 100644 --- a/lib/silccore/idcache.c +++ b/lib/silccore/idcache.c @@ -316,19 +316,17 @@ int silc_idcache_find_by_data_loose(SilcIDCache cache, unsigned char *data, int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type, SilcIDCacheList *ret) { - int i, id_len; + int i; SilcIDCacheList list; if (!cache || !cache->cache || !id) return FALSE; - id_len = silc_id_get_len(type); - list = silc_idcache_list_alloc(); if (id != SILC_ID_CACHE_ANY) { for (i = 0; i < cache->cache_count; i++) - if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) + if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) silc_idcache_list_add(list, &(cache->cache[i])); } else { for (i = 0; i < cache->cache_count; i++) @@ -354,15 +352,13 @@ int silc_idcache_find_by_id(SilcIDCache cache, void *id, SilcIdType type, int silc_idcache_find_by_id_one(SilcIDCache cache, void *id, SilcIdType type, SilcIDCacheEntry *ret) { - int i, id_len; + int i; if (!cache || !cache->cache || !id) return FALSE; - id_len = silc_id_get_len(type); - for (i = 0; i < cache->cache_count; i++) - if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) { + if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) { if (ret) *ret = &(cache->cache[i]); return TRUE; @@ -481,15 +477,13 @@ int silc_idcache_del_by_data(SilcIDCache cache, unsigned char *data) int silc_idcache_del_by_id(SilcIDCache cache, SilcIdType type, void *id) { - int i, id_len; + int i; if (!cache || !cache->cache || !id) return FALSE; - id_len = silc_id_get_len(type); - for (i = 0; i < cache->cache_count; i++) - if (cache->cache[i].id && !memcmp(cache->cache[i].id, id, id_len)) { + if (cache->cache[i].id && silc_id_compare(cache->cache[i].id, id, type)) { cache->cache[i].id = NULL; cache->cache[i].data = NULL; cache->cache[i].type = 0; diff --git a/lib/silccore/silcauth.c b/lib/silccore/silcauth.c index 285def35..a06246fd 100644 --- a/lib/silccore/silcauth.c +++ b/lib/silccore/silcauth.c @@ -178,7 +178,7 @@ silc_auth_public_key_encode_data(SilcPublicKey public_key, silc_free(pk); return NULL; } - id_len = silc_id_get_len(type); + id_len = silc_id_get_len(id, type); buf = silc_buffer_alloc(random_len + id_len + pk_len); silc_buffer_pull_tail(buf, SILC_BUFFER_END(buf)); diff --git a/lib/silccore/silcpayload.c b/lib/silccore/silcpayload.c index e3104ada..1dc8f830 100644 --- a/lib/silccore/silcpayload.c +++ b/lib/silccore/silcpayload.c @@ -175,7 +175,7 @@ SilcBuffer silc_id_payload_encode(void *id, SilcIdType type) type == SILC_ID_SERVER ? "Server" : "Channel")); id_data = silc_id_id2str(id, type); - len = silc_id_get_len(type); + len = silc_id_get_len(id, type); buffer = silc_buffer_alloc(4 + len); silc_buffer_pull_tail(buffer, SILC_BUFFER_END(buffer)); diff --git a/lib/silcutil/silcutil.c b/lib/silcutil/silcutil.c index 8867c717..6b118ee8 100644 --- a/lib/silcutil/silcutil.c +++ b/lib/silcutil/silcutil.c @@ -487,7 +487,15 @@ char *silc_id_render(void *id, uint16 type) case SILC_ID_SERVER: { SilcServerID *server_id = (SilcServerID *)id; - strcat(rid, inet_ntoa(server_id->ip)); + struct in_addr ipv4; + + if (server_id->ip.data_len > 4) { + + } else { + SILC_GET32_MSB(ipv4.s_addr, server_id->ip.data); + strcat(rid, inet_ntoa(ipv4)); + } + memset(tmp, 0, sizeof(tmp)); snprintf(tmp, sizeof(tmp), ",%d,", ntohs(server_id->port)); strcat(rid, tmp); @@ -500,7 +508,15 @@ char *silc_id_render(void *id, uint16 type) case SILC_ID_CLIENT: { SilcClientID *client_id = (SilcClientID *)id; - strcat(rid, inet_ntoa(client_id->ip)); + struct in_addr ipv4; + + if (client_id->ip.data_len > 4) { + + } else { + SILC_GET32_MSB(ipv4.s_addr, client_id->ip.data); + strcat(rid, inet_ntoa(ipv4)); + } + memset(tmp, 0, sizeof(tmp)); snprintf(tmp, sizeof(tmp), ",%02x,", client_id->rnd); strcat(rid, tmp); @@ -514,7 +530,15 @@ char *silc_id_render(void *id, uint16 type) case SILC_ID_CHANNEL: { SilcChannelID *channel_id = (SilcChannelID *)id; - strcat(rid, inet_ntoa(channel_id->ip)); + struct in_addr ipv4; + + if (channel_id->ip.data_len > 4) { + + } else { + SILC_GET32_MSB(ipv4.s_addr, channel_id->ip.data); + strcat(rid, inet_ntoa(ipv4)); + } + memset(tmp, 0, sizeof(tmp)); snprintf(tmp, sizeof(tmp), ",%d,", ntohs(channel_id->port)); strcat(rid, tmp); diff --git a/prepare b/prepare index cfe5f9cc..9810f48f 100755 --- a/prepare +++ b/prepare @@ -25,7 +25,7 @@ # temporary files (including these prepare* scripts) are removed. # -SILC_VERSION=0.2.1 +SILC_VERSION=0.2.2 version=$1 if test "$version" = ""; then -- 2.24.0