Mercurial > notdcc
comparison dccd/dccd_defs.h @ 0:c7f6b056b673
First import of vendor version
author | Peter Gervai <grin@grin.hu> |
---|---|
date | Tue, 10 Mar 2009 13:49:58 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
-1:000000000000 | 0:c7f6b056b673 |
---|---|
1 /* Distributed Checksum Clearinghouse | |
2 * | |
3 * server daemon definitions | |
4 * | |
5 * Copyright (c) 2008 by Rhyolite Software, LLC | |
6 * | |
7 * This agreement is not applicable to any entity which sells anti-spam | |
8 * solutions to others or provides an anti-spam solution as part of a | |
9 * security solution sold to other entities, or to a private network | |
10 * which employs the DCC or uses data provided by operation of the DCC | |
11 * but does not provide corresponding data to other users. | |
12 * | |
13 * Permission to use, copy, modify, and distribute this software without | |
14 * changes for any purpose with or without fee is hereby granted, provided | |
15 * that the above copyright notice and this permission notice appear in all | |
16 * copies and any distributed versions or copies are either unchanged | |
17 * or not called anything similar to "DCC" or "Distributed Checksum | |
18 * Clearinghouse". | |
19 * | |
20 * Parties not eligible to receive a license under this agreement can | |
21 * obtain a commercial license to use DCC by contacting Rhyolite Software | |
22 * at sales@rhyolite.com. | |
23 * | |
24 * A commercial license would be for Distributed Checksum and Reputation | |
25 * Clearinghouse software. That software includes additional features. This | |
26 * free license for Distributed ChecksumClearinghouse Software does not in any | |
27 * way grant permision to use Distributed Checksum and Reputation Clearinghouse | |
28 * software | |
29 * | |
30 * THE SOFTWARE IS PROVIDED "AS IS" AND RHYOLITE SOFTWARE, LLC DISCLAIMS ALL | |
31 * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES | |
32 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL RHYOLITE SOFTWARE, LLC | |
33 * BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES | |
34 * OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
35 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
36 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
37 * SOFTWARE. | |
38 * | |
39 * Rhyolite Software DCC 1.3.103-1.221 $Revision$ | |
40 */ | |
41 | |
42 #ifndef DCCD_DEFS_H | |
43 #define DCCD_DEFS_H | |
44 | |
45 #include "srvr_defs.h" | |
46 #include "dcc_xhdr.h" | |
47 | |
48 extern DCC_EMSG dcc_emsg; | |
49 | |
50 extern u_char grey; | |
51 extern u_char background; | |
52 extern int stopint; | |
53 | |
54 extern DCC_SRVR_ID my_srvr_id; | |
55 | |
56 extern const char *brand; /* our brand name */ | |
57 | |
58 | |
59 extern u_char use_ipv6; | |
60 extern u_int16_t def_port; | |
61 typedef struct srvr_soc { | |
62 struct srvr_soc *fwd; | |
63 DCC_SOCKU su; | |
64 union { | |
65 struct dcc_in6_addr in6; | |
66 struct in_addr in4; | |
67 } arg_addr; | |
68 int udp; | |
69 int listen; | |
70 u_int16_t arg_port; | |
71 u_char arg_family; | |
72 u_char flags; | |
73 # define SRVR_SOC_ADDR 0x01 /* explicit IP address */ | |
74 # define SRVR_SOC_IF 0x02 /* port on all interfaces */ | |
75 # define SRVR_SOC_LISTEN 0x04 /* need a listen socket for port */ | |
76 # define SRVR_SOC_MARK 0X08 | |
77 # define SRVR_SOC_NEW 0X10 | |
78 } SRVR_SOC; | |
79 extern SRVR_SOC *srvr_socs; | |
80 extern int srvr_rcvbuf; | |
81 | |
82 | |
83 #define MAX_CMD_CLOCK_SKEW (DCC_MAX_RETRANS_DELAY_SECS*2) | |
84 #define MAX_FLOD_CLOCK_SKEW (4*60*60) /* refuse reports this far in advance */ | |
85 | |
86 | |
87 extern char our_hostname[MAXHOSTNAMELEN]; | |
88 extern DCC_SUM host_id_sum; /* advertised with our server-ID */ | |
89 extern time_t host_id_next, host_id_last; | |
90 #define DCC_SRVR_ID_SECS (24*60*60) /* defend server-IDs this often */ | |
91 #define DCC_SRVR_ID_SECS_ST (5*60) /* defend after daemon starts */ | |
92 | |
93 extern int flod_trace_gen; /* unsuppress tracing */ | |
94 | |
95 /* keepalive intervals | |
96 * An idle flooding link is kept alive, or known to be healthy, by the | |
97 * receiving server repeating its current position. If the link is | |
98 * broken, the receiving server's transmissions of its position will fail | |
99 * and the transmitting server will hear silence on the link. */ | |
100 #define KEEPALIVE_IN (10*60) | |
101 #define KEEPALIVE_OUT (KEEPALIVE_IN+FLODS_CK_SECS) | |
102 /* Things should be quicker while we are shutting down flooding | |
103 * Some TCP/IP implementations have retransmission delays that can | |
104 * totals 7 seconds, so we must not be too quick */ | |
105 #define KEEPALIVE_IN_STOP 30 | |
106 #define KEEPALIVE_OUT_STOP (KEEPALIVE_IN_STOP+FLODS_CK_SECS) | |
107 /* be really quick if stopping the daemon */ | |
108 #define SHUTDOWN_DELAY 2 | |
109 | |
110 #define IFP_DEAD(p,secs) DB_IS_TIME((p)->iflod_alive+(secs), secs) | |
111 #define OFP_DEAD(p,secs) DB_IS_TIME((p)->oflod_alive+(secs), secs) | |
112 | |
113 | |
114 /* Delay our reports and summaries of our reports by this much. | |
115 * It should be long enough to allow us to generate useful summaries, but | |
116 * it cannot be so long that we won't flood the summary when we make it. */ | |
117 extern int summarize_delay_secs; | |
118 | |
119 | |
120 extern int queue_max; | |
121 | |
122 extern u_char anon_off; /* turn off anonymous access */ | |
123 extern u_char query_only; /* 1=treat reports as queries */ | |
124 | |
125 extern time_t anon_delay_us; /* anonymous client delay */ | |
126 extern u_int anon_delay_inflate; | |
127 | |
128 extern struct timeval wake_time; /* when we awoke from select() */ | |
129 extern struct timeval req_recv_time; /* when request arrived */ | |
130 | |
131 extern u_char grey_weak_body; /* 1=ignore bodies for greylisting */ | |
132 extern u_char grey_weak_ip; /* 1=one good triple whitelists addr */ | |
133 | |
134 extern int grey_embargo; | |
135 extern int grey_window; | |
136 extern int grey_white; | |
137 | |
138 | |
139 /* rate limiting | |
140 * One of these structures is maintained for every recent client, | |
141 * where "recent" is at least one day */ | |
142 typedef u_int16_t RL_DATA_FG; | |
143 # define RL_FG_MARKED 0x0001 /* seen during `cdcc clients` */ | |
144 # define RL_FG_CK_BL 0x0002 /* 0=need to check list of addresses */ | |
145 # define RL_FG_TRACE 0x0004 | |
146 # define RL_FG_BL_ADDR 0x0008 /* blacklisted client or flood peer */ | |
147 # define RL_FG_BL_ID 0x0010 /* blacklisted client ID */ | |
148 # define RL_FG_BL_BAD 0x0020 /* ignored for bad behavior */ | |
149 # define RL_FG_BLS (RL_FG_BL_ADDR | RL_FG_BL_ID | RL_FG_BL_BAD) | |
150 # define RL_FG_PASSWD 0x0040 /* bad password */ | |
151 # define RL_FG_UKN_ID 0x0080 /* bad ID */ | |
152 # define RL_FG_ANON 0x0100 /* clnt_id=DCC_ID_ANON or bad */ | |
153 typedef struct { | |
154 u_int64_t requests; | |
155 u_int64_t requests_old; | |
156 u_int64_t nops; | |
157 u_int64_t nops_old; | |
158 time_t last_used; | |
159 time_t requests_avg_start; /* effective start of averaging */ | |
160 # define RL_AVG_TERM (60*60 * 48) | |
161 time_t requests_avg_aged; /* when last updated */ | |
162 # define RL_AVG_UPDATE (10*60) | |
163 u_int requests_avg_total; | |
164 u_int requests_avg; | |
165 u_int nops_avg_total; | |
166 u_int nops_avg; | |
167 # define RL_REQUESTS_AVG(d) max((d)->requests_avg, (d)->requests) | |
168 # define RL_NOPS_AVG(d) max((d)->nops_avg, (d)->nops) | |
169 int request_credits; /* limit operations */ | |
170 int bug_credits; /* limit complaints about this client */ | |
171 DCC_CLNT_ID clnt_id; | |
172 struct in6_addr clnt_addr; | |
173 u_char pkt_vers; /* recent protocol version */ | |
174 RL_DATA_FG flags; | |
175 } RL_DATA; | |
176 typedef struct rl { | |
177 struct rl *hfwd, *hbak, **bin; /* neighbors in hash chain & the bin */ | |
178 struct rl *older, *newer; /* global recently used chain */ | |
179 RL_DATA d; | |
180 short ref_cnt; /* in use by an entry in job queue */ | |
181 } RL; | |
182 | |
183 | |
184 /* rate-limit parameters | |
185 * Decrease request_credits by RL_SCALE for each event. | |
186 * Increase request_credits by .per_sec for every second. | |
187 * When request_credits <= 0, there have been too many events. | |
188 * Clamp request_credits at .lo to limit the duration of a penalty. | |
189 * Clamp request_credits at .hi to limit the duration over which | |
190 * the rate is averaged. | |
191 */ | |
192 typedef struct { | |
193 float penalty_secs; /* drop excess events for this long */ | |
194 int per_sec; /* allowed events/second * RL_SCALE */ | |
195 int lo; /* clamp credit count at this */ | |
196 int hi; /* reset credit count to this */ | |
197 } RL_RATE; | |
198 | |
199 extern RL_RATE rl_sub_rate; /* X/sec/paying customer */ | |
200 extern RL_RATE rl_anon_rate; /* X/sec/freeloader */ | |
201 extern RL_RATE rl_all_anon_rate; /* X/sec for all freeloaders */ | |
202 extern RL_RATE rl_bugs_rate; /* X complaints/sec */ | |
203 | |
204 #if defined(RL_MIN_MAX) | |
205 #if RL_MIN_MAX<1000 || RL_MIN_MAX>1000000 | |
206 #undef RL_MIN_MAX | |
207 #endif | |
208 #endif | |
209 #define RL_MIN_MAX_DEF (10*1000) | |
210 #define RL_MIN_MAX_MAX (1000*1000) /* fix ./configure if this changes */ | |
211 #define RL_AVG_SECS 10 /* average for this many seconds */ | |
212 #define RL_LIFE_SECS (RL_AVG_SECS*2) /* lifetime of rate limit block */ | |
213 | |
214 #define RL_OVF_CREDITS 0x7fffffff /* fit {bug,request}_credits */ | |
215 #define RL_SCALE 10 | |
216 #define RL_MAX_CREDITS (RL_OVF_CREDITS/RL_AVG_SECS/RL_SCALE/2) | |
217 | |
218 | |
219 extern time_t clients_cleared; | |
220 | |
221 | |
222 /* file containing rate limit blocks */ | |
223 #define CLIENTS_NM() (grey_on ? "grey_clients" : "dccd_clients") | |
224 #define BAD_CLIENTS_NM() (grey_on ? "grey_clients-bad" : "dccd_clients-bad") | |
225 | |
226 typedef struct { | |
227 char magic[80]; | |
228 char pad[40]; | |
229 time_t now; | |
230 time_t cleared; | |
231 int32_t anon_delay_us; | |
232 u_int32_t anon_delay_inflate; | |
233 int hash_len; | |
234 } CLIENTS_HEADER; | |
235 #define CLIENTS_MAGIC_VERSION "7" | |
236 #define CLIENTS_MAGIC_STR " client rate limit blocks version " | |
237 #define CLIENTS_MAGIC_BASE(g) ((g) ? "greylist" CLIENTS_MAGIC_STR \ | |
238 : "dccd" CLIENTS_MAGIC_STR) | |
239 #define CLIENTS_MAGIC_V(g,v) ((g) ? "greylist" CLIENTS_MAGIC_STR v \ | |
240 : "dccd" CLIENTS_MAGIC_STR v) | |
241 #define CLIENTS_MAGIC(g) CLIENTS_MAGIC_V(g,CLIENTS_MAGIC_VERSION) | |
242 | |
243 | |
244 | |
245 /* report cache used to detect duplicate reports | |
246 * One of these structures is maintained for every current operation */ | |
247 typedef struct ridc { | |
248 struct ridc *fwd, *bak, **hash; | |
249 struct ridc *older, *newer; | |
250 time_t last_used; | |
251 DCC_HDR hdr; | |
252 u_int16_t clnt_port; | |
253 int len; | |
254 u_char op; | |
255 u_char bad; | |
256 union { | |
257 DCC_ANSWER_BODY_CKS b; | |
258 DCC_ADMN_RESP_ANON_DELAY anon_delay; | |
259 char msg[DCC_ERROR_MSG_LEN]; | |
260 } result; | |
261 } RIDC; | |
262 | |
263 /* entry in main job queue */ | |
264 typedef struct dccd_queue { | |
265 struct dccd_queue *later, *earlier; | |
266 RL *rl; | |
267 RIDC *ridc; | |
268 SRVR_SOC *sp; | |
269 DCC_CLNT_ID clnt_id; | |
270 DCC_SOCKU clnt_su; /* send answer here */ | |
271 u_int pkt_len; | |
272 time_t delay_us; /* how long to delay the answer */ | |
273 struct timeval answer; /* when it should be answered */ | |
274 u_char flags; | |
275 # define Q_FG_RPT_OK 0x01 /* override dccd -Q */ | |
276 # define Q_FG_UNTRUSTED 0x02 | |
277 # define Q_FG_UKN_ID 0x04 | |
278 # define Q_FG_BAD_PASSWD 0x08 | |
279 DCC_PASSWD passwd; /* sign answers with this */ | |
280 union { | |
281 DCC_HDR hdr; | |
282 DCC_REPORT r; | |
283 DCC_DELETE d; | |
284 DCC_GREY_SPAM gs; | |
285 DCC_ADMN_REQ ad; | |
286 } pkt; | |
287 } QUEUE; | |
288 | |
289 | |
290 typedef struct iflod_info IFLOD_INFO; | |
291 | |
292 typedef struct { | |
293 DCC_SRVR_ID from_lo; | |
294 DCC_SRVR_ID from_hi; | |
295 u_char result; | |
296 } OFLOD_SRVR_ID_MAP; | |
297 typedef enum { | |
298 ID_MAP_NO, ID_MAP_REJ, ID_MAP_SELF | |
299 } ID_MAP_RESULT; | |
300 | |
301 typedef struct { | |
302 int cur, lim; /* signed because lim can be <0 */ | |
303 } FLOD_LIMCNT; | |
304 #define FLOD_LIM_CLEAR_SECS (5*60) | |
305 #define FLOD_LIM_COMPLAINTS 10 | |
306 | |
307 typedef u_int OPT_FLAGS; | |
308 typedef struct { | |
309 OPT_FLAGS flags; | |
310 # define FLOD_OPT_OFF 0x0001 | |
311 # define FLOD_OPT_TRACE 0x0002 | |
312 # define FLOD_OPT_TRACE2 0x0004 | |
313 # define FLOD_OPT_ROGUE 0x0008 | |
314 # define IFLOD_OPT_OFF_ROGUE(o) (((o)->i_opts.flags & FLOD_OPT_OFF) \ | |
315 | ((o)->o_opts.flags&FLOD_OPT_ROGUE)) | |
316 # define OFLOD_OPT_OFF_ROGUE(o) ((o)->o_opts.flags & (FLOD_OPT_OFF \ | |
317 | FLOD_OPT_ROGUE)) | |
318 # define FLOD_OPT_IPv4 0x0010 | |
319 # define FLOD_OPT_IPv6 0x0020 | |
320 # define FLOD_OPT_PASSIVE 0x0040 | |
321 # define FLOD_OPT_SOCKS 0x0080 | |
322 # define FLOD_OPT_NAT 0x0100 | |
323 # define FLOD_OPT_DEL_OK 0x0200 | |
324 # define FLOD_OPT_DEL_SET 0x0400 | |
325 # define FLOD_OPT_NO_LOG_DEL 0x0800 | |
326 # define FLOD_OPT_TRAPS 0x1000 | |
327 # define FLOD_OPT_SIMPLE 0x2000 | |
328 OFLOD_SRVR_ID_MAP srvr_map[10]; | |
329 u_char num_maps; | |
330 u_char path_len; | |
331 } OFLOD_OPTS; | |
332 | |
333 typedef struct { | |
334 FLOD_MMAP *mp; | |
335 int soc; /* outgoing socket */ | |
336 int lno; | |
337 char rem_portname[sizeof(flod_mmaps->mmaps[0].rem_portname)]; | |
338 char rem_hostname[sizeof(flod_mmaps->mmaps[0].rem_hostname)]; | |
339 char loc_hostname[DCC_MAXDOMAINLEN]; | |
340 DCC_SRVR_ID rem_id, in_passwd_id, out_passwd_id; | |
341 u_int16_t rem_port, loc_port; | |
342 DCC_SOCKU rem_su; /* target of the flood */ | |
343 time_t limit_reset; /* when to reset complaint limits */ | |
344 time_t oflod_alive; /* when last active */ | |
345 struct { | |
346 time_t saved; /* last wrote counts to file */ | |
347 u_int out_reports; /* total reports sent */ | |
348 u_int total; /* total reports received */ | |
349 u_int accepted; /* acceptable received reports */ | |
350 } cnts; | |
351 struct { | |
352 FLOD_LIMCNT stale; /* bad timestamp */ | |
353 FLOD_LIMCNT dup; /* already received */ | |
354 FLOD_LIMCNT wlist; /* whitelisted */ | |
355 FLOD_LIMCNT not_deleted; /* delete commands ignored */ | |
356 FLOD_LIMCNT bad_id; /* unrecognized server-IDs */ | |
357 FLOD_LIMCNT complaint; /* output complaint from peer */ | |
358 FLOD_LIMCNT iflod_bad; /* generic bad report */ | |
359 } lc; | |
360 DB_PTR xmit_pos; /* last transmitted position */ | |
361 DB_PTR recv_pos; /* heard this from target */ | |
362 DB_PTR cur_pos; /* completed to here */ | |
363 DB_PTR rewind_pos; /* will have rewound by here */ | |
364 int ibuf_len; | |
365 union { | |
366 DCC_FLOD_RESP r; | |
367 u_char b[sizeof(DCC_FLOD_RESP)*2]; | |
368 } ibuf; | |
369 u_int obuf_len; | |
370 union { | |
371 DCC_FLOD_STREAM s; | |
372 # define FLOD_BUF_SIZE 2048 | |
373 u_char b[FLOD_BUF_SIZE]; | |
374 } obuf; | |
375 OFLOD_OPTS i_opts; | |
376 OFLOD_OPTS o_opts; | |
377 IFLOD_INFO *ifp; | |
378 u_int flags; | |
379 # define OFLOD_FG_CONNECTED 0x0001 /* connect() complete */ | |
380 # define OFLOD_FG_NEW 0x0002 /* new connection */ | |
381 # define OFLOD_FG_SHUTDOWN 0x0004 /* brakes applied */ | |
382 # define OFLOD_FG_SHUTDOWN_REQ 0x0008 | |
383 # define OFLOD_FG_HAVE_2PASSWD 0x0010 /* have a 2nd password */ | |
384 # define OFLOD_FG_I_USED_2PASSWD 0x020 /* used the 2nd password */ | |
385 # define OFLOD_FG_O_USED_2PASSWD 0x040 | |
386 # define OFLOD_FG_EAGAIN 0x0080 /* recent bogus EAGAIN */ | |
387 u_char oversion; | |
388 } OFLOD_INFO; | |
389 | |
390 typedef struct { | |
391 int total; /* known peers */ | |
392 int open; /* active outgoing streams */ | |
393 OFLOD_INFO infos[DCCD_MAX_FLOODS]; | |
394 } OFLODS; | |
395 extern OFLODS oflods; | |
396 extern DB_PTR oflods_max_cur_pos; | |
397 | |
398 extern enum FLODS_ST { | |
399 FLODS_ST_OFF, FLODS_ST_RESTART, FLODS_ST_ON | |
400 } flods_st; | |
401 | |
402 extern DCC_TGTS flod_tholds[DCC_DIM_CKS]; | |
403 | |
404 | |
405 struct iflod_info { | |
406 int soc; /* incoming socket */ | |
407 DCC_SOCKU rem_su; /* sender of the flood */ | |
408 char rem_hostname[sizeof(flod_mmaps->mmaps[0].rem_hostname)]; | |
409 DCC_FLOD_POS pos, pos_sent; | |
410 OFLOD_INFO *ofp; | |
411 time_t iflod_alive; /* when last active */ | |
412 int ibuf_len; | |
413 u_char flags; | |
414 # define IFLOD_FG_CONNECTED 0x01 | |
415 # define IFLOD_FG_CLIENT 0x02 /* outgoing connection */ | |
416 # define IFLOD_FG_VERS_CK 0x04 | |
417 # define IFLOD_FG_END_REQ 0x08 | |
418 # define IFLOD_FG_FAST_LINGER 0x10 | |
419 union { | |
420 DCC_FLOD_STREAM s; | |
421 u_char b[FLOD_BUF_SIZE]; | |
422 } ibuf; | |
423 }; | |
424 | |
425 typedef struct { | |
426 int open; | |
427 IFLOD_INFO infos[DCCD_MAX_FLOODS]; | |
428 } IFLODS; | |
429 extern IFLODS iflods; | |
430 | |
431 extern int flods_off; /* # of reasons flooding is off */ | |
432 #define FLODS_OK() (!flods_off && !db_minimum_map) | |
433 #define FLODS_OK_ON() (FLODS_OK() && flods_st == FLODS_ST_ON) | |
434 extern u_int complained_many_iflods; | |
435 | |
436 typedef enum { | |
437 WFIX_DELAY, /* waiting for window overflow */ | |
438 WFIX_BUSY, /* measuring active load */ | |
439 WFIX_QUIET, /* waiting for clients to flee */ | |
440 WFIX_CHECK, /* counting clients that stayed */ | |
441 } DBCLEAN_WFIX_STATE; | |
442 extern DBCLEAN_WFIX_STATE dbclean_wfix_state; | |
443 | |
444 extern u_char stop_mode; /* 0=normal 1=reboot 2=with/DB clean */ | |
445 extern time_t next_flods_ck; | |
446 #define FLODS_CK_SECS 5 | |
447 #define RUSH_NEXT_FLODS_CK() {if (next_flods_ck > db_time.tv_sec + 1) \ | |
448 next_flods_ck = db_time.tv_sec + 1;} | |
449 #define MISC_CK_SECS FLODS_CK_SECS | |
450 #define CLIENTS_SAVE_SECS (30*60) | |
451 | |
452 extern time_t flod_mtime; | |
453 | |
454 #define FLOD_RETRY_SECS (5*60) /* retry connection no sooner */ | |
455 #define FLOD_SUBMAX_RETRY_SECS (60*60) /* retry when peer can't poke us */ | |
456 #define FLOD_MAX_RETRY_SECS (24*60*60) /* maximum backoff */ | |
457 #define FLOD_SOCKS_SOCKS_IRETRY 30 | |
458 | |
459 #define FLOD_IN_COMPLAIN (24*60*60) /* complain daily about input */ | |
460 #define FLOD_IN_COMPLAIN1 (2*60*60) /* 1st normal input complaint */ | |
461 #define FLOD_IN_COMPLAIN_NOW (5*60) /* complain as soon as possible */ | |
462 | |
463 extern time_t iflods_ok_timer; /* incoming flooding ok since then */ | |
464 #define IFLODS_OK_SECS (5*60) /* 5 minutes to catch up */ | |
465 | |
466 extern time_t need_clients_save; | |
467 | |
468 extern time_t got_hosts; /* resolve hostnames */ | |
469 #define FLOD_NAMES_RESOLVE_SECS (5*60) /* at most every 5 minutes */ | |
470 extern pid_t resolve_hosts_pid; | |
471 | |
472 extern const char *need_del_dbclean; | |
473 extern time_t del_dbclean_next; | |
474 #define DEL_DBCLEAN_SECS (30*60) /* limit dbclean if not urgent */ | |
475 extern time_t dbclean_limit; | |
476 #define DBCLEAN_LIMIT_SECS 15 /* not too often for any reason */ | |
477 extern time_t dbclean_limit_secs; | |
478 | |
479 extern DCCD_STATS dccd_stats; | |
480 | |
481 | |
482 /* Avoid the costs of generating and passing the args to syslog() by | |
483 * checking bits in the caller. | |
484 * If the server ran only on modern Unix, we could use gcc's macro varargs. */ | |
485 #define TMSG_BIT(t) (DCC_TRACE_##t##_BIT & dccd_tracemask) | |
486 #define TMSG_BLOCK(t,args) do {if TMSG_BIT(t) dcc_trace_msg args;} while (0) | |
487 #define TMSG(t,p) TMSG_BLOCK(t,(p)) | |
488 #define TMSG1(t,p,arg) TMSG_BLOCK(t,(p,arg)) | |
489 #define TMSG2(t,p,arg1,arg2) TMSG_BLOCK(t,(p,arg1,arg2)) | |
490 #define TMSG3(t,p,arg1,arg2,arg3) TMSG_BLOCK(t,(p,arg1,arg2,arg3)) | |
491 #define TMSG4(t,p,arg1,arg2,arg3,arg4) TMSG_BLOCK(t,(p,arg1,arg2,arg3,arg4)) | |
492 #define TMSG5(t,p,arg1,arg2,arg3,arg4,arg5) \ | |
493 TMSG_BLOCK(t,(p,arg1,arg2,arg3,arg4,arg5)) | |
494 | |
495 #define TMSG_FB(ofp) ((DCC_TRACE_FLOD_BIT & dccd_tracemask) \ | |
496 || ((ofp && (ofp->o_opts.flags & FLOD_OPT_TRACE)))) | |
497 #define TMSG_Fsub(ofp,args) do {if (TMSG_FB(ofp)) dcc_trace_msg args;} while(0) | |
498 #define TMSG_FLOD(ofp,p) TMSG_Fsub(ofp,(p)) | |
499 #define TMSG1_FLOD(ofp,p,arg) TMSG_Fsub(ofp,(p,arg)) | |
500 #define TMSG2_FLOD(ofp,p,arg1,arg2) TMSG_Fsub(ofp,(p,arg1,arg2)) | |
501 #define TMSG3_FLOD(ofp,p,arg1,arg2,arg3) TMSG_Fsub(ofp,(p,arg1,arg2,arg3)) | |
502 | |
503 #define TMSG_FB2(ofp) (((DCC_TRACE_FLOD_BIT \ | |
504 | DCC_TRACE_FLOD2_BIT) & dccd_tracemask) \ | |
505 || ((ofp && (ofp->o_opts.flags \ | |
506 & (FLOD_OPT_TRACE | FLOD_OPT_TRACE2))))) | |
507 #define TMSG_F2sub(ofp,args) do {if (TMSG_FB2(ofp))dcc_trace_msg args;} while(0) | |
508 #define TMSG_FLOD2(ofp,p) TMSG_F2sub(ofp,(p)) | |
509 #define TMSG1_FLOD2(ofp,p,arg) TMSG_F2sub(ofp,(p,arg)) | |
510 #define TMSG2_FLOD2(ofp,p,arg1,arg2) TMSG_F2sub(ofp,(p,arg1,arg2)) | |
511 #define TMSG3_FLOD2(ofp,p,arg1,arg2,arg3) TMSG_F2sub(ofp,(p,arg1,arg2,arg3)) | |
512 | |
513 | |
514 #define Q_CIP(q) dcc_su2str_err(&(q)->clnt_su) | |
515 | |
516 | |
517 static inline void | |
518 db_ptr2flod_pos(DCC_FLOD_POS bp, DB_PTR pos) | |
519 { | |
520 bp[7] = pos; bp[6] = pos>>8; | |
521 bp[5] = pos>>16; bp[4] = pos>>24; | |
522 bp[3] = pos>>32; bp[2] = pos>>40; | |
523 bp[1] = pos>>48; bp[0] = pos>>56; | |
524 } | |
525 | |
526 | |
527 static inline DB_PTR | |
528 flod_pos2db_ptr(const DCC_FLOD_POS pos) | |
529 { | |
530 return ((DB_PTR)pos[7] + (((DB_PTR)pos[6])<<8) | |
531 + (((DB_PTR)pos[5])<<16) + (((DB_PTR)pos[4])<<24) | |
532 + (((DB_PTR)pos[3])<<32) + (((DB_PTR)pos[2])<<40) | |
533 + (((DB_PTR)pos[1])<<48) + (((DB_PTR)pos[0])<<56)); | |
534 } | |
535 | |
536 | |
537 /* multiplicative hash function after Knuth vol. 3 */ | |
538 static inline u_int32_t | |
539 mhash(u_int32_t hashin, u_int nbins) | |
540 { | |
541 u_int64_t v; | |
542 | |
543 v = 0x9ccf9319; | |
544 v *= hashin; /* v=(hashin * Knuth's 0.6125423371 */ | |
545 v &= 0xffffffff; /* fractional part or modulo 1 */ | |
546 v *= nbins; | |
547 return v >> 32; | |
548 } | |
549 | |
550 | |
551 /* dccd.c */ | |
552 extern void free_q(QUEUE *); | |
553 extern void after_fork(void); | |
554 extern void set_dbclean_timer(void); | |
555 extern void bad_stop(const char *, ...) PATTRIB(1,2); | |
556 | |
557 /* iflod.c */ | |
558 extern ID_MAP_RESULT id_map(DCC_SRVR_ID, const OFLOD_OPTS *); | |
559 extern const char * ifp_rem_str(const IFLOD_INFO *); | |
560 #define CK_FLOD_CNTERR(lc) (++(lc)->cur <= ((lc)->lim + FLOD_LIM_COMPLAINTS)) | |
561 extern void flod_cnterr(const FLOD_LIMCNT *, const char *, ...) PATTRIB(2,3); | |
562 extern const char * ofp_rem_str(const OFLOD_INFO *); | |
563 extern void rpt_err(OFLOD_INFO *, u_char, u_char, | |
564 const char *, ...) PATTRIB(4,5); | |
565 extern u_char set_flod_socket(OFLOD_INFO *, u_char, int, | |
566 const char *, const DCC_SOCKU *); | |
567 extern u_char flod_names_resolve_ck(void); | |
568 extern u_char flod_names_resolve_start(void); | |
569 extern void iflod_listen_close(SRVR_SOC *); | |
570 extern void iflods_stop(const char *, u_char); | |
571 extern void iflod_start(SRVR_SOC *); | |
572 extern void iflods_listen(void); | |
573 extern void iflod_socks_start(OFLOD_INFO *); | |
574 extern u_char dccd_db_open(u_char); | |
575 extern void iflod_close(IFLOD_INFO *, u_char, u_char, u_char, | |
576 const char *, ...) PATTRIB(5,6); | |
577 extern u_char iflod_read(IFLOD_INFO *); | |
578 extern int iflod_send_pos(IFLOD_INFO *, u_char); | |
579 extern int flods_list(char *, int, u_char); | |
580 extern int flod_stats(char *, int, u_int32_t, u_char); | |
581 | |
582 /* oflod.c */ | |
583 extern void oflods_clear(void); | |
584 extern void oflod_open(OFLOD_INFO *); | |
585 extern u_char load_flod(u_char); | |
586 extern void save_flod_cnts(OFLOD_INFO *); | |
587 extern void oflod_close(OFLOD_INFO *, u_char); | |
588 extern int oflod_parse_eof(OFLOD_INFO *, u_char, const DCC_FLOD_END *, int); | |
589 extern void oflod_read(OFLOD_INFO *); | |
590 extern void oflod_write(OFLOD_INFO *); | |
591 extern void flods_stop(const char *, u_char); | |
592 extern const char *version_str(OFLOD_INFO *); | |
593 extern void flod_try_again(OFLOD_INFO *); | |
594 extern const char *flod_sign(OFLOD_INFO *, u_char, void *, int); | |
595 extern u_char oflod_connect_fin(OFLOD_INFO *); | |
596 extern void flods_restart(const char *, u_char); | |
597 extern int check_load_ids(u_char); | |
598 extern void flods_ck(u_char); | |
599 extern void flods_init(void); | |
600 | |
601 /* rl.c */ | |
602 extern void rl_inc(RL *, const RL_RATE *); | |
603 extern void clients_save(void); | |
604 extern void clients_load(void); | |
605 extern u_char ck_ip_bl(RL **, DCC_CLNT_ID, const struct in6_addr *); | |
606 extern void clients_get_id(DCC_ADMN_RESP_VAL *, int *, u_int, int, u_char, | |
607 const struct in6_addr *, const struct in6_addr *); | |
608 extern int clients_get(DCC_ADMN_RESP_VAL *, int *, u_int, int, u_char, | |
609 const struct in6_addr *, const struct in6_addr *); | |
610 #define CLIENTS_AGE (24*60*60) | |
611 #define CLIENTS_SAVE_AGE (14*CLIENTS_AGE) | |
612 extern void clients_clear(void); | |
613 extern u_char ck_sign(const ID_TBL **, DCC_PASSWD, DCC_CLNT_ID, | |
614 const void *, u_int); | |
615 extern u_char ck_clnt_srvr_id(QUEUE *); | |
616 extern u_char ck_clnt_id(QUEUE *); | |
617 extern const char *qop2str(const QUEUE *); | |
618 extern void check_blacklist_file(void); | |
619 | |
620 extern u_long dccd_tracemask; | |
621 | |
622 extern const char *from_id_ip(const QUEUE *, u_char); | |
623 extern const char *op_id_ip(const QUEUE *); | |
624 extern void vanon_msg(const char *, va_list); | |
625 extern void anon_msg(const char *, ...) PATTRIB(1,2); | |
626 extern void vclnt_msg(const QUEUE *, const char *, va_list); | |
627 extern void clnt_msg(const QUEUE *, const char *, ...) PATTRIB(2,3); | |
628 extern void drop_msg(QUEUE *, const char *, ...) PATTRIB(2,3); | |
629 | |
630 /* work.c */ | |
631 extern int find_srvr_rcd(const DCC_SUM, const char *); | |
632 extern int find_srvr_rcd_type(DCC_SRVR_ID); | |
633 extern ID_TBL *find_srvr_type(DCC_SRVR_ID); | |
634 extern void refresh_srvr_rcd(const DCC_SUM, DCC_SRVR_ID, const char *); | |
635 extern void stats_clear(void); | |
636 extern u_char summarize_dly(void); | |
637 extern u_char add_dly_rcd(DB_RCD *, u_char); | |
638 extern void do_work(QUEUE *); | |
639 extern void do_grey(QUEUE *); | |
640 extern void do_grey_spam(QUEUE *); | |
641 extern void do_nop(QUEUE *); | |
642 extern void do_admn(QUEUE *); | |
643 extern void do_delete(QUEUE *); | |
644 | |
645 | |
646 #endif /* DCCD_DEFS_H */ |