Mercurial > notdcc
comparison srvrlib/srvr_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 * common server 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.85 $Revision$ | |
40 */ | |
41 | |
42 #ifndef SRVR_DEFS_H | |
43 #define SRVR_DEFS_H | |
44 | |
45 #include "dcc_clnt.h" | |
46 #include "dcc_ids.h" | |
47 #include "dcc_heap_debug.h" | |
48 #include "db.h" | |
49 | |
50 typedef int64_t SCNTR; | |
51 | |
52 typedef struct { | |
53 struct timeval reset; | |
54 SCNTR nops; /* DCC_OP_NOP packets */ | |
55 SCNTR reports; /* DCC_OP_REPORT or DCC_OP_REPORT_REP */ | |
56 SCNTR report_retrans; /* duplicate reports */ | |
57 SCNTR report_reject; /* reports ignored by -Q */ | |
58 SCNTR report10; /* reports of >10 targets */ | |
59 SCNTR report100; /* reports of >100 targets */ | |
60 SCNTR report1000; /* reports of >1000 targets */ | |
61 SCNTR reportmany; /* reports of spam */ | |
62 SCNTR queries; /* DCC_OP_QUERY */ | |
63 SCNTR resp10; /* responses of >10 targets */ | |
64 SCNTR resp100; /* " " >100 targets */ | |
65 SCNTR resp1000; /* " " >1000 targets */ | |
66 SCNTR respmany; /* " " spam */ | |
67 SCNTR respwhite; /* whitelisted responses */ | |
68 SCNTR bad_op; /* unknown, blacklisted, over active */ | |
69 SCNTR bad_passwd; /* requests with bad passwords */ | |
70 SCNTR blist; /* blacklisted requests */ | |
71 SCNTR send_error; /* error responses sent */ | |
72 SCNTR admin; /* DCC_OP_ADMN */ | |
73 SCNTR rl; /* responses rate-limited */ | |
74 SCNTR anon_rl; /* anonymous responses rate-limited */ | |
75 SCNTR adds; /* reports added */ | |
76 SCNTR iflod_total; /* total reports received */ | |
77 SCNTR iflod_accepted; /* timely and properly signed */ | |
78 SCNTR iflod_stale; | |
79 SCNTR iflod_dup; | |
80 SCNTR iflod_wlist; /* locally whitelisted */ | |
81 SCNTR iflod_not_deleted; /* delete commands ignored */ | |
82 SCNTR norep; | |
83 SCNTR rep1; | |
84 SCNTR rep10; | |
85 SCNTR rep20; | |
86 SCNTR rep30; | |
87 SCNTR rep60; | |
88 SCNTR report_reps; /* DCC_OP_REPORT_REP packets */ | |
89 } DCCD_STATS; | |
90 | |
91 | |
92 typedef char FLOD_EMSG[DCC_FLOD_MAX_RESP]; | |
93 typedef struct { | |
94 int trace_gen; /* to get at least one trace message */ | |
95 u_char complained; | |
96 FLOD_EMSG trace_msg; | |
97 FLOD_EMSG msg; | |
98 } LAST_ERROR; | |
99 | |
100 | |
101 /* memory mapped file of flooding information | |
102 * it is memory mapped so that dblist can report the state of flooding | |
103 * and so dbclean can see when flooding has stopped */ | |
104 | |
105 #define GREY_FLOD_NM "grey_flod" | |
106 #define DCCD_FLOD_NM "flod" | |
107 extern DCC_PATH flod_mmap_path, flod_path; | |
108 | |
109 #ifndef DCCD_MAX_FLOODS | |
110 #define DCCD_MAX_FLOODS 32 | |
111 #endif | |
112 | |
113 typedef struct { | |
114 /* timer and backoff for ordinary connect() */ | |
115 time_t retry; | |
116 int retry_secs; | |
117 /* timer for complaints about missing incoming connection */ | |
118 time_t msg; | |
119 int msg_secs; | |
120 } CONN_TIMERS; | |
121 typedef u_int32_t FLOD_MMAP_FLAGS; | |
122 typedef struct { | |
123 char rem_hostname[DCC_MAXDOMAINLEN]; | |
124 char rem_portname[MAXPORTNAMELEN+1]; | |
125 u_int16_t rem_port; | |
126 DCC_SOCKU rem_su; /* address for hostname */ | |
127 int host_error; /* for failure to resolve hostname */ | |
128 DB_PTR confirm_pos; /* confirmed sent to here */ | |
129 DCC_SRVR_ID rem_id, in_passwd_id, out_passwd_id; | |
130 CONN_TIMERS otimers, itimers; | |
131 time_t ids_mtime; /* mtime ids file when we checked */ | |
132 FLOD_MMAP_FLAGS flags; | |
133 # define FLODMAP_FG_MARK 0x00000001 | |
134 # define FLODMAP_FG_IN_OFF 0x00000002 | |
135 # define FLODMAP_FG_OUT_OFF 0x00000004 | |
136 # define FLODMAP_FG_ROGUE 0x00000008 /* evil server */ | |
137 # define FLODMAP_FG_IN_CONN 0x00000010 /* input connected */ | |
138 # define FLODMAP_FG_OUT_CONN 0x00000020 /* output connected */ | |
139 # define FLODMAP_FG_IPv4 0x00000040 /* override IPv6 choice */ | |
140 # define FLODMAP_FG_IPv6 0x00000080 /* override IPv6 choice */ | |
141 # define FLODMAP_FG_PASSIVE 0x00000100 /* peer uses SOCKS */ | |
142 # define FLODMAP_FG_SOCKS 0x00000200 | |
143 # define FLODMAP_FG_NAT 0x00000400 /* SOCKS without library */ | |
144 # define FLODMAP_FG_NAT_AUTO 0x00000800 /* assumed NAT */ | |
145 # define FLODMAP_FG_ACT (FLODMAP_FG_SOCKS | FLODMAP_FG_NAT \ | |
146 | FLODMAP_FG_NAT_AUTO) | |
147 # define FLODMAP_FG_OUT_SRVR 0x00001000 /* connected by peer */ | |
148 # define FLODMAP_FG_IN_SRVR 0x00002000 /* connected by peer */ | |
149 # define FLODMAP_FG_REWINDING 0x00004000 /* answering rewind */ | |
150 # define FLODMAP_FG_NEED_REWIND 0x00008000 /* database purged */ | |
151 # define FLODMAP_FG_FFWD_IN 0x00010000 /* want fastforward */ | |
152 # define FLODMAP_FG_USE_2PASSWD 0x00020000 | |
153 # define FLODMAP_FG_LEAF 0x00040000 /* path length restricted */ | |
154 # define FLODMAP_FG_MAPPED 0x00080000 /* server-IDs translated */ | |
155 u_char iversion; /* incoming flood protocol */ | |
156 struct { | |
157 time_t cnts_cleared; | |
158 time_t in_conn_changed; | |
159 time_t out_conn_changed; | |
160 u_int out_total_conn; /* seconds connected */ | |
161 u_int in_total_conn; | |
162 SCNTR out_reports; /* total reports sent */ | |
163 SCNTR total; /* received */ | |
164 SCNTR accepted; | |
165 SCNTR stale; /* too old or in the future */ | |
166 SCNTR dup; /* already received */ | |
167 SCNTR wlist; /* whitelisted */ | |
168 SCNTR not_deleted; /* delete commands ignored */ | |
169 } cnts; | |
170 LAST_ERROR oflod_err; | |
171 LAST_ERROR iflod_err; | |
172 } FLOD_MMAP; | |
173 | |
174 typedef struct { | |
175 char magic[32]; | |
176 # define FLOD_MMAP_MAGIC "DCC flod map version 18" | |
177 char pad[32-sizeof(DB_PTR)]; | |
178 DB_PTR delay_pos; /* delay flooding newer than this */ | |
179 DB_SN sn; /* ensure match with database */ | |
180 FLOD_MMAP mmaps[DCCD_MAX_FLOODS]; | |
181 DCCD_STATS dccd_stats; | |
182 } FLOD_MMAPS; | |
183 extern FLOD_MMAPS *flod_mmaps; | |
184 | |
185 | |
186 static inline void | |
187 dcc_secs2ts(DCC_TS *ts, time_t secs) | |
188 { | |
189 u_int64_t t; | |
190 | |
191 t = ((u_int64_t)secs) << DCC_TS_SECS_LSHIFT; | |
192 ts->b[0] = t>>40; ts->b[1] = t>>32; | |
193 ts->b[2] = t>>24; ts->b[3] = t>>16; ts->b[4] = t>>8; ts->b[5] = t; | |
194 } | |
195 | |
196 static inline void | |
197 dcc_timeval2ts(DCC_TS *ts, const struct timeval *tv, int delta_secs) | |
198 { | |
199 u_int64_t t; | |
200 | |
201 t = ((u_int64_t)tv->tv_sec+delta_secs) << DCC_TS_SECS_LSHIFT; | |
202 t += tv->tv_usec >> DCC_TS_US_RSHIFT; | |
203 ts->b[0] = t>>40; ts->b[1] = t>>32; | |
204 ts->b[2] = t>>24; ts->b[3] = t>>16; ts->b[4] = t>>8; ts->b[5] = t; | |
205 } | |
206 | |
207 static inline void | |
208 dcc_ts2timeval(struct timeval *tv, const DCC_TS *ts) | |
209 { | |
210 u_int64_t t = ((((u_int64_t)ts->b[0])<<40) | |
211 + (((u_int64_t)ts->b[1])<<32) | |
212 + (((u_int64_t)ts->b[2])<<24) | |
213 + (((u_int64_t)ts->b[3])<<16) | |
214 + (((u_int64_t)ts->b[4])<<8) | |
215 + ts->b[5]); | |
216 tv->tv_sec = t >> DCC_TS_SECS_LSHIFT; | |
217 tv->tv_usec = ((t & DCC_TS_US_MASK) << DCC_TS_US_RSHIFT); | |
218 } | |
219 | |
220 static inline int | |
221 dcc_ts_newer_ts(const DCC_TS *ts1, const DCC_TS *ts2) | |
222 { | |
223 return memcmp(ts1, ts2, sizeof(DCC_TS)) > 0; | |
224 } | |
225 | |
226 static inline int | |
227 dcc_ts_older_ts(const DCC_TS *ts1, const DCC_TS *ts2) | |
228 { | |
229 return memcmp(ts1, ts2, sizeof(DCC_TS)) < 0; | |
230 } | |
231 | |
232 | |
233 #define DB_TYPE2STR(t) dcc_type2str_err(t,0,1,grey_on) | |
234 | |
235 /* not thread safe */ | |
236 extern DCC_PATH db_path_buf; | |
237 #define DB_NM2PATH_ERR(nm) fnm2abs_err(db_path_buf, nm) | |
238 | |
239 | |
240 extern void flod_mmap_path_set(void); | |
241 extern u_char flod_mmap_sync(DCC_EMSG, u_char); | |
242 extern u_char flod_unmap(DCC_EMSG, const DCCD_STATS *); | |
243 extern u_char flod_mmap(DCC_EMSG, const DB_SN *, const DCCD_STATS *, | |
244 u_char, u_char); | |
245 extern const char *flod_stats_printf(char *, int, int, int, int, int); | |
246 extern const char *flodmap_fg(char *, int, const char *, const FLOD_MMAP *); | |
247 extern int flod_running(const char *); | |
248 | |
249 extern int read_db(DCC_EMSG, void *, u_int, int, off_t, const char *); | |
250 extern u_char read_db_hdr(DCC_EMSG, DB_HDR *, int fd, const char *); | |
251 extern void read_rcd_invalidate(u_int); | |
252 extern int read_rcd(DCC_EMSG, DB_RCD *, int, off_t, const char *); | |
253 | |
254 extern char *ts2str(char *, u_int, const DCC_TS *); | |
255 extern const char *ts2str_err(const DCC_TS *); | |
256 | |
257 extern char *dcc_srvr_id2str(char *, u_int, DCC_SRVR_ID); | |
258 | |
259 | |
260 #endif /* SRVR_DEFS_H */ |