Initial revision
[silc.git] / apps / silcd / route.h
1 /*
2
3   route.h
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 #ifndef ROUTE_H
22 #define ROUTE_H
23
24 /* Definitions */
25
26 /* Size of the route cache hash table */
27 #define SILC_SERVER_ROUTE_SIZE 256
28
29 /*
30    SILC Server Route table
31
32    Following short description of the fields.
33
34    unsigned int dest
35
36        Destination IPv4 address.  Can be used to quickly check whether
37        the found route entry is what the caller wanted.
38
39    SilcServerList *router
40
41        Pointer to the router specific data.
42
43 */
44 typedef struct {
45   unsigned int dest;
46   SilcServerList *router;
47 } SilcServerRouteTable;
48
49 /* Route cache hash table */
50 extern SilcServerRouteTable silc_route_cache[SILC_SERVER_ROUTE_SIZE];
51
52 /* Macros and super macros */
53
54 /* Returns route cache hash table entry index. This is IPv4 specific.
55    `port' argument may be zero (0) if it doesn't exist.  This has been
56    taken from Linux kernel's route cache code. */
57 extern inline
58 unsigned int silc_server_route_hash(unsigned int addr, 
59                                     unsigned short port)
60 {
61   unsigned int hash;
62   
63   hash = ((addr & 0xf0f0f0f0) >> 4) | ((addr & 0x0f0f0f0f) << 4);
64   hash ^= port;
65   hash ^= (hash >> 16);
66   hash ^= (hash >> 8);
67   
68   return hash & 0xff;
69 }
70
71 /* Prototypes */
72 void silc_server_route_add(unsigned int index, unsigned int dest,
73                            SilcServerList *router);
74 SilcServerList *silc_server_route_check(unsigned int dest, 
75                                         unsigned short port);
76
77 #endif