jabberd2
2.2.16
|
00001 /* 00002 * jabberd - Jabber Open Source Server 00003 * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney, 00004 * Ryan Eatmon, Robert Norris 00005 * 00006 * This program is free software; you can redistribute it and/or modify 00007 * it under the terms of the GNU General Public License as published by 00008 * the Free Software Foundation; either version 2 of the License, or 00009 * (at your option) any later version. 00010 * 00011 * This program is distributed in the hope that it will be useful, 00012 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00013 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the 00014 * GNU General Public License for more details. 00015 * 00016 * You should have received a copy of the GNU General Public License 00017 * along with this program; if not, write to the Free Software 00018 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA 00019 */ 00020 00021 #ifdef HAVE_CONFIG_H 00022 # include <config.h> 00023 #endif 00024 00025 #include "mio/mio.h" 00026 #include "sx/sx.h" 00027 00028 #ifdef HAVE_SIGNAL_H 00029 # include <signal.h> 00030 #endif 00031 #ifdef HAVE_SYS_STAT_H 00032 # include <sys/stat.h> 00033 #endif 00034 00035 #include <udns.h> 00036 00037 /* forward decl */ 00038 typedef struct host_st *host_t; 00039 typedef struct s2s_st *s2s_t; 00040 typedef struct pkt_st *pkt_t; 00041 typedef struct conn_st *conn_t; 00042 typedef struct dnsquery_st *dnsquery_t; 00043 typedef struct dnscache_st *dnscache_t; 00044 typedef struct dnsres_st *dnsres_t; 00045 00046 struct host_st { 00048 char *realm; 00049 00051 char *host_pemfile; 00052 00054 char *host_cachain; 00055 00057 int host_verify_mode; 00058 }; 00059 00060 struct s2s_st { 00062 char *id; 00063 00065 char *router_ip; 00066 int router_port; 00067 char *router_user; 00068 char *router_pass; 00069 char *router_pemfile; 00070 int router_default; 00071 00073 mio_t mio; 00074 00076 sx_env_t sx_env; 00077 sx_plugin_t sx_ssl; 00078 sx_plugin_t sx_sasl; 00079 sx_plugin_t sx_db; 00080 00082 sx_t router; 00083 mio_fd_t fd; 00084 00086 mio_fd_t server_fd; 00087 00089 config_t config; 00090 00092 log_t log; 00093 00095 log_type_t log_type; 00096 char *log_facility; 00097 char *log_ident; 00098 00100 long long int packet_count; 00101 char *packet_stats; 00102 00104 int retry_init; 00105 int retry_lost; 00106 int retry_sleep; 00107 int retry_left; 00108 00110 char *local_ip; 00111 int local_port; 00112 00114 char **origin_ips; 00115 int origin_nips; 00116 00118 char *local_secret; 00119 00121 char *local_pemfile; 00122 00124 char *local_cachain; 00125 00127 int local_verify_mode; 00128 00130 xht hosts; 00131 00133 int io_max_fds; 00134 00136 int stanza_size_limit; 00137 00139 int compression; 00140 00142 char **lookup_srv; 00143 int lookup_nsrv; 00144 00146 int resolve_aaaa; 00147 00149 int dns_min_ttl; 00150 int dns_max_ttl; 00151 00153 int etc_hosts_ttl; 00154 00156 int check_interval; 00157 int check_queue; 00158 int check_invalid; 00159 int check_keepalive; 00160 int check_idle; 00161 int check_dnscache; 00162 int retry_limit; 00163 00164 time_t last_queue_check; 00165 time_t last_invalid_check; 00166 00167 time_t next_check; 00168 time_t next_expiry; 00169 00171 int require_tls; 00172 int enable_whitelist; 00173 char **whitelist_domains; 00174 int n_whitelist_domains; 00175 00177 jqueue_t dead; 00178 00180 jqueue_t dead_conn; 00181 00183 int started; 00184 00186 int online; 00187 00189 xht outq; 00190 00192 int out_reuse; 00193 00195 xht out_host; 00196 00198 xht out_dest; 00199 00201 xht in; 00202 00204 xht in_accept; 00205 00207 int udns_fd; 00208 mio_fd_t udns_mio_fd; 00209 00211 xht dnscache; 00212 int dns_cache_enabled; 00213 00215 xht dns_bad; 00216 int dns_bad_timeout; 00217 }; 00218 00219 struct pkt_st { 00220 nad_t nad; 00221 00222 jid_t from; 00223 jid_t to; 00224 00225 int db; 00226 00227 char ip[INET6_ADDRSTRLEN+1]; 00228 int port; 00229 }; 00230 00231 typedef enum { 00232 conn_NONE, 00233 conn_INPROGRESS, 00234 conn_VALID, 00235 conn_INVALID 00236 } conn_state_t; 00237 00238 struct conn_st { 00239 s2s_t s2s; 00240 00241 char *key; 00242 char *dkey; 00243 00244 sx_t s; 00245 mio_fd_t fd; 00246 00247 char ip[INET6_ADDRSTRLEN+1]; 00248 int port; 00249 00251 xht states; 00252 00254 xht states_time; 00255 00257 xht routes; 00258 00259 time_t init_time; 00260 00261 int online; 00262 00264 int verify; 00265 time_t last_verify; 00266 00268 time_t last_activity; 00269 time_t last_packet; 00270 00271 unsigned int packet_count; 00272 }; 00273 00274 #define DNS_MAX_RESULTS 50 00275 00277 struct dnsquery_st { 00278 s2s_t s2s; 00279 00281 char *name; 00282 00284 int srv_i; 00285 00287 xht hosts; 00288 00290 char *cur_host; 00291 00293 int cur_port; 00294 00296 time_t cur_expiry; 00297 00299 int cur_prio; 00300 00302 int cur_weight; 00303 00305 xht results; 00306 00308 time_t expiry; 00309 00311 struct dns_query *query; 00312 }; 00313 00315 struct dnscache_st { 00317 char name[1024]; 00318 00320 xht results; 00321 00323 time_t expiry; 00324 00325 time_t init_time; 00326 00328 int pending; 00329 dnsquery_t query; 00330 }; 00331 00333 struct dnsres_st { 00335 char *key; 00336 00338 int prio; 00339 00341 int weight; 00342 00344 time_t expiry; 00345 }; 00346 00347 extern sig_atomic_t s2s_lost_router; 00348 00349 int s2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg); 00350 int s2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg); 00351 int s2s_domain_in_whitelist(s2s_t s2s, char *in_domain); 00352 00353 char *s2s_route_key(pool_t p, char *local, char *remote); 00354 int s2s_route_key_match(char *local, char *remote, char *rkey, int rkeylen); 00355 char *s2s_db_key(pool_t p, char *secret, char *remote, char *id); 00356 char *dns_make_ipport(char *host, int port); 00357 00358 int out_packet(s2s_t s2s, pkt_t pkt); 00359 int out_route(s2s_t s2s, char *route, int routelen, conn_t *out, int allow_bad); 00360 int dns_select(s2s_t s2s, char *ip, int *port, time_t now, dnscache_t dns, int allow_bad); 00361 void dns_resolve_domain(s2s_t s2s, dnscache_t dns); 00362 void out_resolve(s2s_t s2s, char *domain, xht results, time_t expiry); 00363 void out_dialback(s2s_t s2s, pkt_t pkt); 00364 int out_bounce_domain_queues(s2s_t s2s, const char *domain, int err); 00365 int out_bounce_route_queue(s2s_t s2s, char *rkey, int rkeylen, int err); 00366 int out_bounce_conn_queues(conn_t out, int err); 00367 void out_flush_domain_queues(s2s_t s2s, const char *domain); 00368 void out_flush_route_queue(s2s_t s2s, char *rkey, int rkeylen); 00369 00370 int in_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg); 00371 00372 /* sx flag for outgoing dialback streams */ 00373 #define S2S_DB_HEADER (1<<10) 00374 00375 /* max length of FQDN for whitelist matching */ 00376 #define MAX_DOMAIN_LEN 1023 00377 00378 int s2s_db_init(sx_env_t env, sx_plugin_t p, va_list args); 00379 00380 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */ 00381 union xhashv 00382 { 00383 void **val; 00384 char **char_val; 00385 conn_t *conn_val; 00386 conn_state_t *state_val; 00387 jqueue_t *jq_val; 00388 dnscache_t *dns_val; 00389 dnsres_t *dnsres_val; 00390 }; 00391 00392 void out_pkt_free(pkt_t pkt);