Initial revision
[silc.git] / apps / silcd / route.c
1 /*
2
3   route.c
4
5   Author: Pekka Riikonen <priikone@poseidon.pspt.fi>
6
7   Copyright (C) 2000 Pekka Riikonen
8
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.
13   
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.
18
19 */
20 /* 
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).
24  */
25 /*
26  * $Id$
27  * $Log$
28  * Revision 1.1  2000/06/27 11:36:56  priikone
29  * Initial revision
30  *
31  *
32  */
33
34 #include "serverincludes.h"
35 #include "route.h"
36
37 /* Route cache hash table */
38 SilcServerRouteTable silc_route_cache[SILC_SERVER_ROUTE_SIZE];
39
40 /* Adds new route to the route cache. The argument `index' is the
41    index value generated by silc_server_route_hash. */
42
43 void silc_server_route_add(unsigned int index, unsigned int dest,
44                            SilcServerList *router)
45 {
46   silc_route_cache[index].dest = dest;
47   silc_route_cache[index].router = router;
48 }
49
50 /* Checksk whether destination has a specific router. Returns the
51    router data if found, NULL otherwise. */
52
53 SilcServerList *silc_server_route_check(unsigned int dest, 
54                                         unsigned short port)
55 {
56   unsigned int index;
57
58   index = silc_server_route_hash(dest, port);
59
60   if (silc_route_cache[index].router != NULL &&
61       silc_route_cache[index].dest == dest)
62     return silc_route_cache[index].router;
63
64   return NULL;
65 }