jabberd2  2.2.17
s2s.h
Go to the documentation of this file.
1 /*
2  * jabberd - Jabber Open Source Server
3  * Copyright (c) 2002 Jeremie Miller, Thomas Muldowney,
4  * Ryan Eatmon, Robert Norris
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation; either version 2 of the License, or
9  * (at your option) any later version.
10  *
11  * This program is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with this program; if not, write to the Free Software
18  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA02111-1307USA
19  */
20 
21 #ifdef HAVE_CONFIG_H
22 # include <config.h>
23 #endif
24 
25 #include "mio/mio.h"
26 #include "sx/sx.h"
27 
28 #ifdef HAVE_SIGNAL_H
29 # include <signal.h>
30 #endif
31 #ifdef HAVE_SYS_STAT_H
32 # include <sys/stat.h>
33 #endif
34 
35 #include <udns.h>
36 
37 /* forward decl */
38 typedef struct host_st *host_t;
39 typedef struct s2s_st *s2s_t;
40 typedef struct pkt_st *pkt_t;
41 typedef struct conn_st *conn_t;
42 typedef struct dnsquery_st *dnsquery_t;
43 typedef struct dnscache_st *dnscache_t;
44 typedef struct dnsres_st *dnsres_t;
45 
46 struct host_st {
48  char *realm;
49 
51  char *host_pemfile;
52 
54  char *host_cachain;
55 
57  int host_verify_mode;
58 };
59 
60 struct s2s_st {
62  char *id;
63 
65  char *router_ip;
67  char *router_user;
68  char *router_pass;
71 
74 
80 
84 
87 
90 
93 
96  char *log_facility;
97  char *log_ident;
98 
100  long long int packet_count;
102 
108 
110  char *local_ip;
112 
114  char **origin_ips;
116 
119 
122 
125 
128 
131 
134 
137 
140 
142  char **lookup_srv;
144 
147 
151 
154 
163 
166 
167  time_t next_check;
168  time_t next_expiry;
169 
175 
178 
181 
183  int started;
184 
186  int online;
187 
190 
193 
196 
199 
202 
205 
207  int udns_fd;
209 
213 
217 };
218 
219 struct pkt_st {
220  nad_t nad;
221 
222  jid_t from;
223  jid_t to;
224 
225  int db;
226 
228  int port;
229 };
230 
231 typedef enum {
236 } conn_state_t;
237 
238 struct conn_st {
239  s2s_t s2s;
240 
241  char *key;
242  char *dkey;
243 
246 
248  int port;
249 
252 
255 
258 
259  time_t init_time;
260 
261  int online;
262 
264  int verify;
265  time_t last_verify;
266 
269  time_t last_packet;
270 
271  unsigned int packet_count;
272 };
273 
274 #define DNS_MAX_RESULTS 50
275 
277 struct dnsquery_st {
278  s2s_t s2s;
279 
281  char *name;
282 
284  int srv_i;
285 
288 
290  char *cur_host;
291 
293  int cur_port;
294 
296  time_t cur_expiry;
297 
299  int cur_prio;
300 
303 
306 
308  time_t expiry;
309 
311  struct dns_query *query;
312 };
313 
315 struct dnscache_st {
317  char name[1024];
318 
321 
323  time_t expiry;
324 
325  time_t init_time;
326 
328  int pending;
329  dnsquery_t query;
330 };
331 
333 struct dnsres_st {
335  char *key;
336 
338  int prio;
339 
341  int weight;
342 
344  time_t expiry;
345 };
346 
347 extern sig_atomic_t s2s_lost_router;
348 
349 int s2s_router_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
350 int s2s_router_sx_callback(sx_t s, sx_event_t e, void *data, void *arg);
351 int s2s_domain_in_whitelist(s2s_t s2s, char *in_domain);
352 
353 char *s2s_route_key(pool_t p, char *local, char *remote);
354 int s2s_route_key_match(char *local, char *remote, char *rkey, int rkeylen);
355 char *s2s_db_key(pool_t p, char *secret, char *remote, char *id);
356 char *dns_make_ipport(char *host, int port);
357 
358 int out_packet(s2s_t s2s, pkt_t pkt);
359 int out_route(s2s_t s2s, char *route, int routelen, conn_t *out, int allow_bad);
360 int dns_select(s2s_t s2s, char *ip, int *port, time_t now, dnscache_t dns, int allow_bad);
361 void dns_resolve_domain(s2s_t s2s, dnscache_t dns);
362 void out_resolve(s2s_t s2s, char *domain, xht results, time_t expiry);
363 void out_dialback(s2s_t s2s, pkt_t pkt);
364 int out_bounce_domain_queues(s2s_t s2s, const char *domain, int err);
365 int out_bounce_route_queue(s2s_t s2s, char *rkey, int rkeylen, int err);
366 int out_bounce_conn_queues(conn_t out, int err);
367 void out_flush_domain_queues(s2s_t s2s, const char *domain);
368 void out_flush_route_queue(s2s_t s2s, char *rkey, int rkeylen);
369 
370 int in_mio_callback(mio_t m, mio_action_t a, mio_fd_t fd, void *data, void *arg);
371 
372 /* sx flag for outgoing dialback streams */
373 #define S2S_DB_HEADER (1<<10)
374 
375 /* max length of FQDN for whitelist matching */
376 #define MAX_DOMAIN_LEN 1023
377 
378 int s2s_db_init(sx_env_t env, sx_plugin_t p, va_list args);
379 
380 /* union for xhash_iter_get to comply with strict-alias rules for gcc3 */
381 union xhashv
382 {
383  void **val;
384  char **char_val;
385  conn_t *conn_val;
388  dnscache_t *dns_val;
389  dnsres_t *dnsres_val;
390 };
391 
392 void out_pkt_free(pkt_t pkt);