5 Author: Pekka Riikonen <priikone@silcnet.org>
7 Copyright (C) 2000 - 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.
21 * Route cache routines. Server uses these to route packets to specific
22 * routes. If route entry doesn't exist for a specific destination, server
23 * uses primary route (default route).
25 /* XXX Adding two ID's with same IP number replaces the old entry thus
26 gives wrong route. Thus, now disabled until figured out a better way
27 to do this or when removed the whole thing. This could be removed
28 because entry->router->connection gives always the most optimal route
29 for the ID anyway (unless new routes (faster perhaps) are established
30 after receiving this ID, this we don't know however). */
33 #include "serverincludes.h"
34 #include "server_internal.h"
37 /* Route cache hash table */
38 SilcServerRouteTable silc_route_cache[SILC_SERVER_ROUTE_SIZE];
40 /* Adds new route to the route cache. The argument `index' is the
41 index value generated by silc_server_route_hash. */
43 void silc_server_route_add(SilcUInt32 index, unsigned int dest,
44 SilcServerEntry router)
46 silc_route_cache[index].dest = dest;
47 silc_route_cache[index].router = router;
50 /* Checksk whether destination has a specific router. Returns the
51 router data if found, NULL otherwise. */
53 SilcServerEntry silc_server_route_check(SilcUInt32 dest,
58 index = silc_server_route_hash(dest, port);
60 if (silc_route_cache[index].router != NULL &&
61 silc_route_cache[index].dest == dest)
62 return silc_route_cache[index].router;
67 /* Returns the connection object for the fastest route for the given ID.
68 If we are normal server then this just returns our primary route. If
69 we are router we will do route lookup. */
71 SilcPacketStream silc_server_route_get(SilcServer server, void *id,
74 if (server->server_type == SILC_ROUTER) {
77 SilcServerEntry router = NULL;
82 dest = ((SilcClientID *)id)->ip.s_addr;
83 port = server->id->port;
86 dest = ((SilcServerID *)id)->ip.s_addr;
87 port = ((SilcServerID *)id)->port;
90 dest = ((SilcChannelID *)id)->ip.s_addr;
91 port = ((SilcChannelID *)id)->port;
99 router = silc_server_route_check(dest, port);
101 return router->connection;
104 return (server->id_entry->router)
105 ? server->id_entry->router->connection