Add ``ExternalIp'' config directive to ServerInfo tag in
[silc.git] / apps / silcd / serverconfig.h
1 /*
2
3   serverconfig.h
4
5   Author: Giovanni Giacobbi <giovanni@giacobbi.net>
6
7   Copyright (C) 1997 - 2007 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; version 2 of the License.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18 */
19
20 #ifndef SERVERCONFIG_H
21 #define SERVERCONFIG_H
22
23 typedef struct SilcServerConfigCipherStruct {
24   char *name;
25   char *module;
26   SilcUInt32 key_length;
27   SilcUInt32 block_length;
28   struct SilcServerConfigCipherStruct *next;
29 } SilcServerConfigCipher;
30
31 typedef struct SilcServerConfigHashStruct {
32   char *name;
33   char *module;
34   SilcUInt32 block_length;
35   SilcUInt32 digest_length;
36   struct SilcServerConfigHashStruct *next;
37 } SilcServerConfigHash;
38
39 typedef struct SilcServerConfigHmacStruct {
40   char *name;
41   char *hash;
42   SilcUInt32 mac_length;
43   struct SilcServerConfigHmacStruct *next;
44 } SilcServerConfigHmac;
45
46 typedef struct SilcServerConfigPkcsStruct {
47   char *name;
48   struct SilcServerConfigPkcsStruct *next;
49 } SilcServerConfigPkcs;
50
51 typedef struct SilcServerConfigServerInfoInterfaceStruct {
52   char *server_ip;
53   char *public_ip;
54   SilcUInt16 port;
55   struct SilcServerConfigServerInfoInterfaceStruct *next;
56 } SilcServerConfigServerInfoInterface;
57
58 typedef struct SilcServerConfigServerInfoStruct {
59   char *server_name;
60   SilcServerConfigServerInfoInterface *primary;
61   SilcServerConfigServerInfoInterface *secondary;
62   char *external_ip;    /* E.g. public IP if we're in a NAT */
63   char *server_type;    /* E.g. "Test Server" */
64   char *location;       /* geographic location */
65   char *admin;          /* admin full name */
66   char *email;          /* admin's email address */
67   char *user;           /* userid the server should be runned at */
68   char *group;          /* ditto, but about groupid */
69   SilcPublicKey public_key;
70   SilcPrivateKey private_key;
71   char *motd_file;      /* path to text motd file (reading only) */
72   char *pid_file;       /* path to the pid file (for reading and writing) */
73 } SilcServerConfigServerInfo;
74
75 typedef struct SilcServerConfigLoggingStruct {
76   char *file;
77   SilcUInt32 maxsize;
78 } SilcServerConfigLogging;
79
80 /* Connection parameters */
81 typedef struct SilcServerConfigConnParams {
82   struct SilcServerConfigConnParams *next;
83   char *name;
84   char *version_protocol;
85   char *version_software;
86   char *version_software_vendor;
87   SilcUInt32 connections_max;
88   SilcUInt32 connections_max_per_host;
89   SilcUInt32 keepalive_secs;
90   SilcUInt32 reconnect_count;
91   SilcUInt32 reconnect_interval;
92   SilcUInt32 reconnect_interval_max;
93   SilcUInt32 key_exchange_rekey;
94   SilcUInt32 qos_rate_limit;
95   SilcUInt32 qos_bytes_limit;
96   SilcUInt32 qos_limit_sec;
97   SilcUInt32 qos_limit_usec;
98   SilcUInt32 chlimit;
99   unsigned int key_exchange_pfs      : 1;
100   unsigned int reconnect_keep_trying : 1;
101   unsigned int anonymous             : 1;
102   unsigned int qos                   : 1;
103 } SilcServerConfigConnParams;
104
105 /* Holds all client authentication data from config file */
106 typedef struct SilcServerConfigClientStruct {
107   char *host;
108   unsigned char *passphrase;
109   SilcUInt32 passphrase_len;
110   SilcBool publickeys;
111   SilcServerConfigConnParams *param;
112   struct SilcServerConfigClientStruct *next;
113 } SilcServerConfigClient;
114
115 /* Holds all server's administrators authentication data from config file */
116 typedef struct SilcServerConfigAdminStruct {
117   char *host;
118   char *user;
119   char *nick;
120   unsigned char *passphrase;
121   SilcUInt32 passphrase_len;
122   SilcBool publickeys;
123   struct SilcServerConfigAdminStruct *next;
124 } SilcServerConfigAdmin;
125
126 /* Holds all configured denied connections from config file */
127 typedef struct SilcServerConfigDenyStruct {
128   char *host;
129   char *reason;
130   struct SilcServerConfigDenyStruct *next;
131 } SilcServerConfigDeny;
132
133 /* Holds all configured server connections from config file */
134 typedef struct SilcServerConfigServerStruct {
135   char *host;
136   unsigned char *passphrase;
137   SilcUInt32 passphrase_len;
138   SilcBool publickeys;
139   SilcServerConfigConnParams *param;
140   SilcBool backup_router;
141   struct SilcServerConfigServerStruct *next;
142 } SilcServerConfigServer;
143
144 /* Holds all configured router connections from config file */
145 typedef struct SilcServerConfigRouterStruct {
146   char *host;
147   unsigned char *passphrase;
148   SilcUInt32 passphrase_len;
149   SilcBool publickeys;
150   SilcUInt16 port;
151   SilcServerConfigConnParams *param;
152   SilcBool initiator;
153   SilcBool backup_router;
154   SilcBool dynamic_connection;
155   char *backup_replace_ip;
156   SilcUInt16 backup_replace_port;
157   SilcBool backup_local;
158   struct SilcServerConfigRouterStruct *next;
159 } SilcServerConfigRouter;
160
161 /* define the SilcServerConfig object */
162 typedef struct {
163   SilcServer server;
164   void *tmp;
165
166   /* Reference count (when this reaches zero, config object is destroyed) */
167   SilcInt32 refcount;
168
169   /* The General section */
170   char *module_path;
171   SilcBool prefer_passphrase_auth;
172   SilcBool require_reverse_lookup;
173   SilcUInt32 channel_rekey_secs;
174   SilcUInt32 key_exchange_timeout;
175   SilcUInt32 conn_auth_timeout;
176   SilcServerConfigConnParams param;
177   SilcBool detach_disabled;
178   SilcUInt32 detach_timeout;
179   SilcBool logging_timestamp;
180   SilcBool logging_quick;
181   long logging_flushdelay;
182   char *debug_string;
183   SilcBool httpd;
184   char *httpd_ip;
185   SilcUInt16 httpd_port;
186   SilcBool dynamic_server;
187   SilcBool local_channels;
188
189   /* Other configuration sections */
190   SilcServerConfigCipher *cipher;
191   SilcServerConfigHash *hash;
192   SilcServerConfigHmac *hmac;
193   SilcServerConfigPkcs *pkcs;
194   SilcServerConfigLogging *logging_info;
195   SilcServerConfigLogging *logging_warnings;
196   SilcServerConfigLogging *logging_errors;
197   SilcServerConfigLogging *logging_fatals;
198   SilcServerConfigServerInfo *server_info;
199   SilcServerConfigConnParams *conn_params;
200   SilcServerConfigClient *clients;
201   SilcServerConfigAdmin *admins;
202   SilcServerConfigDeny *denied;
203   SilcServerConfigServer *servers;
204   SilcServerConfigRouter *routers;
205 } *SilcServerConfig;
206
207 typedef struct {
208   SilcServerConfig config;
209   void *ref_ptr;
210 } SilcServerConfigRef;
211
212 /* Prototypes */
213
214 /* Basic config operations */
215 SilcServerConfig silc_server_config_alloc(const char *filename,
216                                           SilcServer server);
217 void silc_server_config_destroy(SilcServerConfig config);
218 void silc_server_config_ref(SilcServerConfigRef *ref, SilcServerConfig config,
219                             void *ref_ptr);
220 void silc_server_config_unref(SilcServerConfigRef *ref);
221
222 /* Algorithm registering and reset functions */
223 SilcBool silc_server_config_register_ciphers(SilcServer server);
224 SilcBool silc_server_config_register_hashfuncs(SilcServer server);
225 SilcBool silc_server_config_register_hmacs(SilcServer server);
226 SilcBool silc_server_config_register_pkcs(SilcServer server);
227 void silc_server_config_setlogfiles(SilcServer server);
228
229 /* Run-time config access functions */
230 SilcServerConfigClient *
231 silc_server_config_find_client(SilcServer server, char *host);
232 SilcServerConfigAdmin *
233 silc_server_config_find_admin(SilcServer server, char *host, char *user,
234                               char *nick);
235 SilcServerConfigDeny *
236 silc_server_config_find_denied(SilcServer server, char *host);
237 SilcServerConfigServer *
238 silc_server_config_find_server_conn(SilcServer server, char *host);
239 SilcServerConfigRouter *
240 silc_server_config_find_router_conn(SilcServer server, char *host, int port);
241 SilcServerConfigRouter *
242 silc_server_config_find_backup_conn(SilcServer server, char *host);
243 SilcBool silc_server_config_is_primary_route(SilcServer server);
244 SilcServerConfigRouter *
245 silc_server_config_get_primary_router(SilcServer server);
246 SilcServerConfigRouter *
247 silc_server_config_get_backup_router(SilcServer server);
248
249 #endif  /* !SERVERCONFIG_H */