]>
Commit | Line | Data |
---|---|---|
12e82c05 | 1 | work in progress |
2 | Add split functionality into ircd | |
3 | Add /split command | |
4 | Add /stats S/split (make /STATS s/S case sensitive, s spoofhosts) | |
5 | Add feature SPLIT | |
6 | Add split.c split.h m_split.c | |
7 | ||
7efbed3b | 8 | NOTE: feature SPLIT is default enabled as that is just easier when working on this patch. |
9 | ||
d61bc4d5 | 10 | diff -r 2267c134dc0d doc/api/log.txt |
11 | --- a/doc/api/log.txt Tue Jan 27 18:19:11 2009 +0100 | |
12 | +++ b/doc/api/log.txt Tue Jan 27 18:25:58 2009 +0100 | |
0c63b280 | 13 | @@ -41,7 +41,7 @@ |
14 | ||
15 | <enum> | |
16 | enum LogSys { | |
17 | - LS_SYSTEM, LS_CONFIG, LS_OPERMODE, LS_GLINE, LS_JUPE, LS_WHO, LS_NETWORK, | |
18 | + LS_SYSTEM, LS_CONFIG, LS_OPERMODE, LS_GLINE, LS_JUPE, LS_SPLIT, LS_WHO, LS_NETWORK, | |
19 | LS_OPERKILL, LS_SERVKILL, LS_USER, LS_OPER, LS_RESOLVER, LS_SOCKET, | |
20 | LS_DEBUG, LS_OLDLOG, | |
21 | LS_LAST_SYSTEM | |
d61bc4d5 | 22 | diff -r 2267c134dc0d include/handlers.h |
23 | --- a/include/handlers.h Tue Jan 27 18:19:11 2009 +0100 | |
24 | +++ b/include/handlers.h Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 25 | @@ -139,6 +139,7 @@ |
26 | extern int m_registered(struct Client*, struct Client*, int, char*[]); | |
27 | extern int m_sethost(struct Client*, struct Client*, int, char*[]); | |
28 | extern int m_silence(struct Client*, struct Client*, int, char*[]); | |
29 | +extern int m_split(struct Client*, struct Client*, int, char*[]); | |
30 | extern int m_stats(struct Client*, struct Client*, int, char*[]); | |
31 | extern int m_time(struct Client*, struct Client*, int, char*[]); | |
32 | extern int m_topic(struct Client*, struct Client*, int, char*[]); | |
d61bc4d5 | 33 | @@ -179,6 +180,7 @@ |
12e82c05 | 34 | extern int mo_rping(struct Client*, struct Client*, int, char*[]); |
35 | extern int mo_set(struct Client*, struct Client*, int, char*[]); | |
36 | extern int mo_settime(struct Client*, struct Client*, int, char*[]); | |
37 | +extern int mo_split(struct Client*, struct Client*, int, char*[]); | |
38 | extern int mo_squit(struct Client*, struct Client*, int, char*[]); | |
39 | extern int mo_stats(struct Client*, struct Client*, int, char*[]); | |
40 | extern int mo_trace(struct Client*, struct Client*, int, char*[]); | |
d61bc4d5 | 41 | @@ -234,6 +236,7 @@ |
12e82c05 | 42 | extern int ms_sethost(struct Client*, struct Client*, int, char*[]); |
43 | extern int ms_settime(struct Client*, struct Client*, int, char*[]); | |
44 | extern int ms_silence(struct Client*, struct Client*, int, char*[]); | |
45 | +extern int ms_split(struct Client*, struct Client*, int, char*[]); | |
46 | extern int ms_squit(struct Client*, struct Client*, int, char*[]); | |
47 | extern int ms_stats(struct Client*, struct Client*, int, char*[]); | |
48 | extern int ms_topic(struct Client*, struct Client*, int, char*[]); | |
d61bc4d5 | 49 | diff -r 2267c134dc0d include/ircd_features.h |
50 | --- a/include/ircd_features.h Tue Jan 27 18:19:11 2009 +0100 | |
51 | +++ b/include/ircd_features.h Tue Jan 27 18:25:58 2009 +0100 | |
52 | @@ -112,6 +112,10 @@ | |
12e82c05 | 53 | FEAT_SETHOST_USER, |
54 | FEAT_SETHOST_AUTO, | |
12e82c05 | 55 | |
65b70298 | 56 | + /* SPLIT */ |
57 | + FEAT_SPLIT, | |
58 | + FEAT_SPLIT_AUTO_EXPIRE, | |
59 | + | |
12e82c05 | 60 | /* HEAD_IN_SAND Features */ |
61 | FEAT_HIS_SNOTICES, | |
65b70298 | 62 | FEAT_HIS_SNOTICES_OPER_ONLY, |
d61bc4d5 | 63 | @@ -139,6 +143,7 @@ |
12e82c05 | 64 | FEAT_HIS_STATS_q, |
65 | FEAT_HIS_STATS_R, | |
66 | FEAT_HIS_STATS_r, | |
67 | + FEAT_HIS_STATS_S, | |
68 | FEAT_HIS_STATS_s, | |
69 | FEAT_HIS_STATS_t, | |
70 | FEAT_HIS_STATS_T, | |
d61bc4d5 | 71 | diff -r 2267c134dc0d include/ircd_log.h |
72 | --- a/include/ircd_log.h Tue Jan 27 18:19:11 2009 +0100 | |
73 | +++ b/include/ircd_log.h Tue Jan 27 18:25:58 2009 +0100 | |
0c63b280 | 74 | @@ -55,6 +55,7 @@ |
75 | LS_OPERMODE, /**< Uses of OPMODE, CLEARMODE< etc. */ | |
76 | LS_GLINE, /**< Adding, (de-)activating or removing GLINEs. */ | |
77 | LS_JUPE, /**< Adding, (de-)activating or removing JUPEs. */ | |
78 | + LS_SPLIT, /**< Adding, (de-)activating or removing SPLITs. */ | |
79 | LS_WHO, /**< Use of extended WHO privileges. */ | |
80 | LS_NETWORK, /**< New server connections. */ | |
81 | LS_OPERKILL, /**< Kills by IRC operators. */ | |
d61bc4d5 | 82 | diff -r 2267c134dc0d include/msg.h |
83 | --- a/include/msg.h Tue Jan 27 18:19:11 2009 +0100 | |
84 | +++ b/include/msg.h Tue Jan 27 18:25:58 2009 +0100 | |
85 | @@ -336,6 +336,10 @@ | |
12e82c05 | 86 | #define TOK_JUPE "JU" |
87 | #define CMD_JUPE MSG_JUPE, TOK_JUPE | |
88 | ||
89 | +#define MSG_SPLIT "SPLIT" /* SPLIT */ | |
90 | +#define TOK_SPLIT "SP" | |
91 | +#define CMD_SPLIT MSG_SPLIT, TOK_SPLIT | |
92 | + | |
93 | #define MSG_OPMODE "OPMODE" /* OPMO */ | |
94 | #define TOK_OPMODE "OM" | |
95 | #define CMD_OPMODE MSG_OPMODE, TOK_OPMODE | |
d61bc4d5 | 96 | diff -r 2267c134dc0d include/numeric.h |
97 | --- a/include/numeric.h Tue Jan 27 18:19:11 2009 +0100 | |
98 | +++ b/include/numeric.h Tue Jan 27 18:25:58 2009 +0100 | |
99 | @@ -118,6 +118,7 @@ | |
12e82c05 | 100 | #define RPL_STATSALINE 226 /* Hybrid, Undernet */ |
d61bc4d5 | 101 | #define RPL_STATSWELCOME 227 /* QuakeNet extension */ |
12e82c05 | 102 | #define RPL_STATSQLINE 228 /* Undernet extension */ |
103 | +#define RPL_STATSSPLIT 229 /* QuakeNet extension */ | |
65b70298 | 104 | #define RPL_STATSHEADER 230 /* QuakeNet extension */ |
12e82c05 | 105 | |
106 | /* RPL_SERVICEINFO 231 unused */ | |
d61bc4d5 | 107 | @@ -179,6 +180,8 @@ |
12e82c05 | 108 | #define RPL_STATSDLINE 275 /* Undernet extension */ |
109 | #define RPL_STATSRLINE 276 /* Undernet extension */ | |
110 | ||
111 | +#define RPL_SPLITLIST 278 /* QuakeNet extension */ | |
112 | +#define RPL_ENDOFSPLITLIST 279 /* QuakeNet extension */ | |
113 | #define RPL_GLIST 280 /* Undernet extension */ | |
114 | #define RPL_ENDOFGLIST 281 /* Undernet extension */ | |
115 | #define RPL_JUPELIST 282 /* Undernet extension - jupe -Kev */ | |
d61bc4d5 | 116 | @@ -445,6 +448,7 @@ |
117 | ||
118 | #define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */ | |
12e82c05 | 119 | |
120 | +#define ERR_NOSUCHSPLIT 510 /* QuakeNet extension */ | |
121 | #define ERR_SILELISTFULL 511 /* Undernet extension */ | |
122 | /* ERR_NOTIFYFULL 512 aircd */ | |
123 | /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */ | |
d61bc4d5 | 124 | diff -r 2267c134dc0d include/split.h |
12e82c05 | 125 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
d61bc4d5 | 126 | +++ b/include/split.h Tue Jan 27 18:25:58 2009 +0100 |
0c63b280 | 127 | @@ -0,0 +1,106 @@ |
128 | +#ifndef INCLUDED_split_h | |
129 | +#define INCLUDED_split_h | |
12e82c05 | 130 | +/* |
131 | + * IRC - Internet Relay Chat, include/split.h | |
132 | + * Copyright (C) 1990 Jarkko Oikarinen and | |
133 | + * University of Oulu, Computing Center | |
134 | + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu> | |
135 | + * | |
136 | + * This program is free software; you can redistribute it and/or modify | |
137 | + * it under the terms of the GNU General Public License as published by | |
138 | + * the Free Software Foundation; either version 2, or (at your option) | |
139 | + * any later version. | |
140 | + * | |
141 | + * This program is distributed in the hope that it will be useful, | |
142 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
143 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
144 | + * GNU General Public License for more details. | |
145 | + * | |
146 | + * You should have received a copy of the GNU General Public License | |
147 | + * along with this program; if not, write to the Free Software | |
148 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
149 | + */ | |
150 | +/** @file | |
151 | + * @brief Interface and declarations for split server handling. | |
152 | + * @version $Id: jupe.h 1208 2004-10-03 14:12:35Z entrope $ | |
153 | + */ | |
12e82c05 | 154 | +#ifndef INCLUDED_sys_types_h |
155 | +#include <sys/types.h> | |
156 | +#define INCLUDED_sys_types_h | |
157 | +#endif | |
158 | + | |
159 | + | |
160 | +struct Client; | |
161 | +struct StatDesc; | |
162 | + | |
65b70298 | 163 | +#define SPLIT_MAX_EXPIRE 2419200 /**< Maximum split expiration time (4 weeks). */ |
12e82c05 | 164 | + |
165 | +/* Describes a SPLIT server entry. */ | |
166 | +struct Split { | |
167 | + struct Split* sp_next; /**< Pointer to next Split. */ | |
168 | + struct Split** sp_prev_p; /**< Pointer to previous next pointer. */ | |
169 | + char* sp_server; /**< Name of server. */ | |
170 | + char* sp_reason; /**< Reason. */ | |
171 | + time_t sp_creation; /**< TODO: Creation time. What are we using this for then? */ | |
172 | + time_t sp_expire; /**< Expiration time. */ | |
173 | + time_t sp_lastmod; /**< Last modification time. */ | |
174 | + time_t sp_lifetime; /**< Life time. */ | |
175 | + unsigned int sp_flags; /**< Status flags. */ | |
176 | +}; | |
177 | + | |
178 | +/** Split state flags. */ | |
0c63b280 | 179 | +#define SPLIT_ACTIVE 0x01 /**< Split is active. */ |
180 | +#define SPLIT_REMOVING 0x02 /**< Split is being force removed (instead of deactivated). */ | |
181 | +#define SPLIT_BURST 0x04 /**< Split is for a server that is in progress of linking, | |
182 | + and will be destroyed at the end of burst */ | |
12e82c05 | 183 | + |
12e82c05 | 184 | +/* Actions to perform on a SPLIT. */ |
185 | +enum SplitAction { | |
186 | + SPLIT_ACTIVATE, /**< SPLIT should be activated. */ | |
187 | + SPLIT_DEACTIVATE, /**< SPLIT should be deactivated. */ | |
188 | + SPLIT_MODIFY, /**< SPLIT should be modified. */ | |
189 | + SPLIT_REMOVE /**< SPLIT should be removed. */ | |
190 | +}; | |
191 | + | |
12e82c05 | 192 | +/* Split update flags. */ |
55404221 | 193 | +#define SPLIT_EXPIRE 0x01 /**< Expiration time update. */ |
194 | +#define SPLIT_LIFETIME 0x02 /**< Record lifetime update. */ | |
195 | +#define SPLIT_REASON 0x04 /**< Reason update. */ | |
196 | +#define SPLIT_CREATION 0x08 /**< TODO: Creation time update - unused. */ | |
197 | +#define SPLIT_MODIFY 0x10 /**< No state change. */ | |
12e82c05 | 198 | + |
199 | +/* mask for Split update flags. */ | |
55404221 | 200 | +#define SPLIT_UPDATE (SPLIT_EXPIRE | SPLIT_CREATION | SPLIT_LIFETIME | SPLIT_REASON) |
12e82c05 | 201 | + |
202 | +/* test whether a split entry is active. */ | |
203 | +#define SplitIsActive(s) ((s)->sp_flags & SPLIT_ACTIVE) | |
0c63b280 | 204 | +/* test whether a split entry is marked for forced removal. */ |
205 | +#define SplitIsRemoving(s) ((s)->sp_flags & SPLIT_REMOVING) | |
206 | +/* test whether a split entry is part of a netmerge. */ | |
207 | +#define SplitIsBurst(s) ((s)->sp_flags & SPLIT_BURST) | |
12e82c05 | 208 | + |
209 | +extern int split_add(struct Client *cptr, struct Client *sptr, | |
210 | + char *server, const char *reason, | |
211 | + time_t creation, time_t expire, time_t lastmod, time_t lifetime, | |
212 | + unsigned int flags); | |
213 | +extern int split_modify(struct Client *cptr, struct Client *sptr, | |
214 | + struct Split *split, enum SplitAction action, const char *reason, | |
215 | + time_t creation, time_t expire, time_t lastmod, time_t lifetime, | |
216 | + unsigned int flags); | |
217 | +extern int split_remove(struct Client *cptr, struct Client *sptr, | |
218 | + struct Split *split, const char *reason); | |
219 | + | |
220 | +extern struct Split* split_find(char *server); | |
221 | +extern void split_free(struct Split *split); | |
222 | +extern int split_expire(struct Split* split); | |
223 | +extern void split_burst(struct Client *cptr); | |
224 | +extern int split_resend(struct Client *cptr, struct Split *split); | |
225 | +extern int split_list(struct Client *sptr, char *server); | |
0c63b280 | 226 | +extern void split_newserver(struct Client *acptr); |
227 | +extern int split_netmerge(struct Client *sptr); | |
228 | +extern int split_netbreak(struct Client *victim, const char *reason); | |
12e82c05 | 229 | +extern void split_conf(); |
230 | +extern void split_stats(struct Client *sptr, const struct StatDesc *sd, char *param); | |
231 | +extern int split_memory_count(size_t *sp_size); | |
232 | + | |
0c63b280 | 233 | +#endif /* INCLUDED_split_h */ |
d61bc4d5 | 234 | diff -r 2267c134dc0d ircd/Makefile.in |
235 | --- a/ircd/Makefile.in Tue Jan 27 18:19:11 2009 +0100 | |
236 | +++ b/ircd/Makefile.in Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 237 | @@ -173,6 +173,7 @@ |
238 | m_sethost.c \ | |
239 | m_settime.c \ | |
240 | m_silence.c \ | |
241 | + m_split.c \ | |
242 | m_squit.c \ | |
243 | m_stats.c \ | |
244 | m_time.c \ | |
d61bc4d5 | 245 | @@ -213,6 +214,7 @@ |
12e82c05 | 246 | s_stats.c \ |
247 | s_user.c \ | |
248 | send.c \ | |
249 | + split.c \ | |
250 | uping.c \ | |
251 | userload.c \ | |
d61bc4d5 | 252 | welcome.c \ |
253 | @@ -1054,6 +1056,15 @@ | |
12e82c05 | 254 | ../include/ircd_chattr.h ../include/list.h ../include/msg.h \ |
255 | ../include/numeric.h ../include/numnicks.h ../include/s_user.h \ | |
256 | ../include/send.h ../include/struct.h | |
257 | +m_split.o: m_split.c ../config.h ../include/client.h ../include/ircd_defs.h \ | |
258 | + ../include/dbuf.h ../include/msgq.h ../include/ircd_events.h \ | |
259 | + ../config.h ../include/ircd_handler.h ../include/res.h \ | |
260 | + ../include/capab.h ../include/split.h ../include/hash.h \ | |
261 | + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \ | |
262 | + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \ | |
263 | + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \ | |
264 | + ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \ | |
265 | + ../include/client.h ../include/s_misc.h ../include/send.h | |
266 | m_squit.o: m_squit.c ../config.h ../include/client.h \ | |
267 | ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \ | |
268 | ../include/ircd_events.h ../config.h ../include/ircd_handler.h \ | |
d61bc4d5 | 269 | @@ -1332,6 +1343,7 @@ |
12e82c05 | 270 | ../include/msgq.h ../include/numeric.h ../include/numnicks.h \ |
271 | ../include/res.h ../include/s_bsd.h ../include/s_conf.h \ | |
272 | ../include/s_user.h ../include/s_stats.h ../include/send.h \ | |
273 | + ../include/split.h \ | |
274 | ../include/struct.h ../include/sys.h ../include/whowas.h | |
275 | s_err.o: s_err.c ../config.h ../include/numeric.h ../include/ircd_log.h \ | |
276 | ../include/s_debug.h ../config.h ../include/ircd_defs.h | |
d61bc4d5 | 277 | @@ -1417,6 +1429,16 @@ |
12e82c05 | 278 | ../include/msg.h ../include/numnicks.h ../include/parse.h \ |
279 | ../include/s_bsd.h ../include/s_debug.h ../include/s_misc.h \ | |
280 | ../include/s_user.h ../include/struct.h ../include/sys.h | |
281 | +split.o: split.c ../config.h ../include/split.h ../include/client.h \ | |
282 | + ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \ | |
283 | + ../include/ircd_events.h ../config.h ../include/ircd_handler.h \ | |
284 | + ../include/res.h ../include/capab.h ../include/hash.h ../include/ircd.h \ | |
285 | + ../include/struct.h ../include/ircd_alloc.h ../include/ircd_features.h \ | |
286 | + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \ | |
287 | + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \ | |
288 | + ../include/numeric.h ../include/numnicks.h ../include/s_bsd.h \ | |
289 | + ../include/s_misc.h ../include/send.h ../include/struct.h \ | |
290 | + ../include/sys.h | |
291 | uping.o: uping.c ../config.h ../include/uping.h ../include/ircd_defs.h \ | |
292 | ../include/ircd_events.h ../config.h ../include/res.h \ | |
293 | ../include/client.h ../include/dbuf.h ../include/msgq.h \ | |
d61bc4d5 | 294 | diff -r 2267c134dc0d ircd/ircd.c |
295 | --- a/ircd/ircd.c Tue Jan 27 18:19:11 2009 +0100 | |
296 | +++ b/ircd/ircd.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 297 | @@ -55,6 +55,7 @@ |
298 | #include "s_misc.h" | |
299 | #include "s_stats.h" | |
300 | #include "send.h" | |
301 | +#include "split.h" | |
302 | #include "sys.h" | |
303 | #include "uping.h" | |
304 | #include "userload.h" | |
305 | @@ -763,6 +764,9 @@ | |
306 | Debug((DEBUG_NOTICE, "Server ready...")); | |
307 | log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready"); | |
308 | ||
309 | + /* create SPLITs */ | |
310 | + split_conf(); | |
311 | + | |
312 | event_loop(); | |
313 | ||
314 | return 0; | |
d61bc4d5 | 315 | diff -r 2267c134dc0d ircd/ircd_features.c |
316 | --- a/ircd/ircd_features.c Tue Jan 27 18:19:11 2009 +0100 | |
317 | +++ b/ircd/ircd_features.c Tue Jan 27 18:25:58 2009 +0100 | |
318 | @@ -366,6 +366,10 @@ | |
12e82c05 | 319 | F_B(SETHOST_USER, 0, 0, 0), |
320 | F_B(SETHOST_AUTO, 0, 0, 0), | |
12e82c05 | 321 | |
65b70298 | 322 | + /* SPLIT */ |
323 | + F_B(SPLIT, 0, 1, 0), | |
324 | + F_I(SPLIT_AUTO_EXPIRE, 0, 604800, 0), | |
325 | + | |
12e82c05 | 326 | /* HEAD_IN_SAND Features */ |
327 | F_B(HIS_SNOTICES, 0, 1, 0), | |
65b70298 | 328 | F_B(HIS_SNOTICES_OPER_ONLY, 0, 1, 0), |
d61bc4d5 | 329 | @@ -393,6 +397,7 @@ |
12e82c05 | 330 | F_B(HIS_STATS_q, 0, 1, 0), |
331 | F_B(HIS_STATS_R, 0, 1, 0), | |
332 | F_B(HIS_STATS_r, 0, 1, 0), | |
333 | + F_B(HIS_STATS_S, 0, 1, 0), | |
334 | F_B(HIS_STATS_s, 0, 1, 0), | |
335 | F_B(HIS_STATS_t, 0, 1, 0), | |
336 | F_B(HIS_STATS_T, 0, 1, 0), | |
d61bc4d5 | 337 | diff -r 2267c134dc0d ircd/ircd_log.c |
338 | --- a/ircd/ircd_log.c Tue Jan 27 18:19:11 2009 +0100 | |
339 | +++ b/ircd/ircd_log.c Tue Jan 27 18:25:58 2009 +0100 | |
0c63b280 | 340 | @@ -154,6 +154,7 @@ |
341 | S(OPERMODE, -1, SNO_HACK4), | |
342 | S(GLINE, -1, SNO_GLINE), | |
343 | S(JUPE, -1, SNO_NETWORK), | |
344 | + S(SPLIT, -1, SNO_NETWORK), | |
345 | S(WHO, -1, 0), | |
346 | S(NETWORK, -1, SNO_NETWORK), | |
347 | S(OPERKILL, -1, 0), | |
d61bc4d5 | 348 | diff -r 2267c134dc0d ircd/m_endburst.c |
349 | --- a/ircd/m_endburst.c Tue Jan 27 18:19:11 2009 +0100 | |
350 | +++ b/ircd/m_endburst.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 351 | @@ -85,6 +85,7 @@ |
352 | #include "client.h" | |
353 | #include "hash.h" | |
354 | #include "ircd.h" | |
355 | +#include "ircd_features.h" | |
356 | #include "ircd_log.h" | |
357 | #include "ircd_reply.h" | |
358 | #include "ircd_string.h" | |
359 | @@ -92,6 +93,7 @@ | |
360 | #include "numeric.h" | |
361 | #include "numnicks.h" | |
362 | #include "send.h" | |
363 | +#include "split.h" | |
364 | ||
365 | /* #include <assert.h> -- Now using assert in ircd_log.h */ | |
366 | ||
367 | @@ -125,6 +127,7 @@ | |
368 | int ms_end_of_burst(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
369 | { | |
370 | struct Channel *chan, *next_chan; | |
371 | + int split; | |
372 | ||
373 | assert(0 != cptr); | |
374 | assert(0 != sptr); | |
375 | @@ -135,6 +138,10 @@ | |
376 | dump_map(sptr, "*", 0, report_new_links, 0); | |
377 | sendto_opmask_butone(0, SNO_NETWORK, "Completed net.burst from %C.", | |
378 | sptr); | |
379 | + /* cleanup SPLITs, but only bother ops when FEAT_SPLIT is enabled. */ | |
0c63b280 | 380 | + split = split_netmerge(sptr); |
12e82c05 | 381 | + if (feature_bool(FEAT_SPLIT)) |
382 | + sendto_opmask_butone(0, SNO_NETWORK, "Removed %d SPLIT entries.", split); | |
383 | if (MyConnect(sptr)) | |
384 | sendcmdto_one(&me, CMD_END_OF_BURST_ACK, sptr, ""); | |
385 | ||
d61bc4d5 | 386 | diff -r 2267c134dc0d ircd/m_reburst.c |
387 | --- a/ircd/m_reburst.c Tue Jan 27 18:19:11 2009 +0100 | |
388 | +++ b/ircd/m_reburst.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 389 | @@ -102,6 +102,7 @@ |
390 | #include "ircd_snprintf.h" | |
391 | #include "gline.h" | |
392 | #include "jupe.h" | |
393 | +#include "split.h" | |
394 | ||
395 | /* #include <assert.h> -- Now using assert in ircd_log.h */ | |
396 | #include <stdlib.h> | |
397 | @@ -130,6 +131,10 @@ | |
398 | case 'J': | |
399 | jupe_burst(sptr); | |
400 | break; | |
401 | + case 's': | |
402 | + case 'S': | |
403 | + split_burst(sptr); | |
404 | + break; | |
405 | default: | |
406 | break; | |
407 | } | |
d61bc4d5 | 408 | diff -r 2267c134dc0d ircd/m_server.c |
409 | --- a/ircd/m_server.c Tue Jan 27 18:19:11 2009 +0100 | |
410 | +++ b/ircd/m_server.c Tue Jan 27 18:25:58 2009 +0100 | |
0c63b280 | 411 | @@ -47,6 +47,7 @@ |
412 | #include "s_misc.h" | |
413 | #include "s_serv.h" | |
414 | #include "send.h" | |
415 | +#include "split.h" | |
416 | #include "userload.h" | |
417 | ||
418 | /* #include <assert.h> -- Now using assert in ircd_log.h */ | |
419 | @@ -764,6 +765,9 @@ | |
420 | sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s", | |
421 | cli_name(sptr), cli_name(acptr)); | |
422 | } | |
423 | + /* new server - mark SPLIT for this server */ | |
424 | + split_newserver(acptr); | |
425 | + | |
426 | /* | |
427 | * Old sendto_serv_but_one() call removed because we now need to send | |
428 | * different names to different servers (domain name matching). | |
d61bc4d5 | 429 | diff -r 2267c134dc0d ircd/m_split.c |
12e82c05 | 430 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
d61bc4d5 | 431 | +++ b/ircd/m_split.c Tue Jan 27 18:25:58 2009 +0100 |
55404221 | 432 | @@ -0,0 +1,376 @@ |
12e82c05 | 433 | +/* |
434 | + * IRC - Internet Relay Chat, ircd/m_split.c | |
435 | + * Copyright (C) 1990 Jarkko Oikarinen and | |
436 | + * University of Oulu, Computing Center | |
437 | + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu> | |
438 | + * | |
439 | + * See file AUTHORS in IRC package for additional names of | |
440 | + * the programmers. | |
441 | + * | |
442 | + * This program is free software; you can redistribute it and/or modify | |
443 | + * it under the terms of the GNU General Public License as published by | |
444 | + * the Free Software Foundation; either version 1, or (at your option) | |
445 | + * any later version. | |
446 | + * | |
447 | + * This program is distributed in the hope that it will be useful, | |
448 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
449 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
450 | + * GNU General Public License for more details. | |
451 | + * | |
452 | + * You should have received a copy of the GNU General Public License | |
453 | + * along with this program; if not, write to the Free Software | |
454 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
455 | + * | |
456 | + * $Id: m_split.c 1737 2006-12-19 05:20:48Z entrope $ | |
457 | + */ | |
458 | + | |
459 | +/* | |
460 | + * m_functions execute protocol messages on this server: | |
461 | + * | |
462 | + * cptr is always NON-NULL, pointing to a *LOCAL* client | |
463 | + * structure (with an open socket connected!). This | |
464 | + * identifies the physical socket where the message | |
465 | + * originated (or which caused the m_function to be | |
466 | + * executed--some m_functions may call others...). | |
467 | + * | |
468 | + * sptr is the source of the message, defined by the | |
469 | + * prefix part of the message if present. If not | |
470 | + * or prefix not found, then sptr==cptr. | |
471 | + * | |
472 | + * (!IsServer(cptr)) => (cptr == sptr), because | |
473 | + * prefixes are taken *only* from servers... | |
474 | + * | |
475 | + * (IsServer(cptr)) | |
476 | + * (sptr == cptr) => the message didn't | |
477 | + * have the prefix. | |
478 | + * | |
479 | + * (sptr != cptr && IsServer(sptr) means | |
480 | + * the prefix specified servername. (?) | |
481 | + * | |
482 | + * (sptr != cptr && !IsServer(sptr) means | |
483 | + * that message originated from a remote | |
484 | + * user (not local). | |
485 | + * | |
486 | + * combining | |
487 | + * | |
488 | + * (!IsServer(sptr)) means that, sptr can safely | |
489 | + * taken as defining the target structure of the | |
490 | + * message in this server. | |
491 | + * | |
492 | + * *Always* true (if 'parse' and others are working correct): | |
493 | + * | |
494 | + * 1) sptr->from == cptr (note: cptr->from == cptr) | |
495 | + * | |
496 | + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr | |
497 | + * *cannot* be a local connection, unless it's | |
498 | + * actually cptr!). [MyConnect(x) should probably | |
499 | + * be defined as (x == x->from) --msa ] | |
500 | + * | |
501 | + * parc number of variable parameter strings (if zero, | |
502 | + * parv is allowed to be NULL) | |
503 | + * | |
504 | + * parv a NULL terminated list of parameter pointers, | |
505 | + * | |
506 | + * parv[0], sender (prefix string), if not present | |
507 | + * this points to an empty string. | |
508 | + * parv[1]...parv[parc-1] | |
509 | + * pointers to additional parameters | |
510 | + * parv[parc] == NULL, *always* | |
511 | + * | |
512 | + * note: it is guaranteed that parv[0]..parv[parc-1] are all | |
513 | + * non-NULL pointers. | |
514 | + */ | |
515 | +#include "config.h" | |
516 | + | |
517 | +#include "client.h" | |
518 | +#include "split.h" | |
519 | +#include "hash.h" | |
520 | +#include "ircd.h" | |
521 | +#include "ircd_features.h" | |
522 | +#include "ircd_log.h" | |
523 | +#include "ircd_reply.h" | |
524 | +#include "ircd_string.h" | |
525 | +#include "match.h" | |
526 | +#include "msg.h" | |
527 | +#include "numeric.h" | |
528 | +#include "numnicks.h" | |
529 | +#include "s_conf.h" | |
530 | +#include "s_debug.h" | |
531 | +#include "s_misc.h" | |
532 | +#include "send.h" | |
533 | + | |
534 | +/* #include <assert.h> -- Now using assert in ircd_log.h */ | |
535 | +#include <stdlib.h> | |
536 | +#include <string.h> | |
537 | + | |
538 | +/* | |
539 | + * ms_split - server message handler | |
540 | + * | |
541 | + * parv[0] = Send prefix | |
542 | + * parv[1] = (+|-)<server name> | |
543 | + * parv[2] = Creation time | |
544 | + * parv[3] = Expiration time | |
545 | + * parv[4] = Last modification time | |
546 | + * parv[5] = Life time | |
547 | + * parv[6] = Comment | |
548 | + * | |
549 | + */ | |
550 | +int ms_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
551 | +{ | |
552 | + struct Client *acptr = 0; | |
553 | + struct Split *asplit = 0; | |
554 | + unsigned int flags = 0; | |
555 | + enum SplitAction action = SPLIT_MODIFY; | |
556 | + time_t creation = 0, expire = 0, lastmod = 0, lifetime = 0; | |
55404221 | 557 | + char *server = 0, *tmp = 0; |
12e82c05 | 558 | + const char *reason = "No reason"; |
559 | + | |
55404221 | 560 | + /* reason is optional - for lazy services, we always send it */ |
561 | + if (parc < 5) | |
12e82c05 | 562 | + return need_more_params(sptr, "SPLIT"); |
563 | + | |
564 | + if (*server == '!') { | |
565 | + server++; | |
566 | + action = SPLIT_REMOVE; /* removing entry */ | |
567 | + } | |
568 | + | |
569 | + switch (*server) { /* handle + and - */ | |
570 | + case '+': /* activate the split entry */ | |
571 | + if (action != SPLIT_REMOVE) | |
572 | + action = SPLIT_ACTIVATE; | |
573 | + server++; | |
574 | + break; | |
575 | + | |
576 | + case '-': /* deactivate the entry */ | |
577 | + if (action != SPLIT_REMOVE) | |
578 | + action = SPLIT_DEACTIVATE; | |
579 | + server++; | |
580 | + break; | |
581 | + } | |
582 | + | |
583 | + /* Next, try to find the split entry... */ | |
55404221 | 584 | + server = parv[1]; |
12e82c05 | 585 | + asplit = split_find(server); |
586 | + | |
587 | + /* We now have all the pieces to tell us what we've got; let's put | |
588 | + * it all together and convert the rest of the arguments. | |
589 | + */ | |
590 | + | |
591 | + /* can't modify a split entry that doesn't exist, so remap to activate */ | |
592 | + if (!asplit && action == SPLIT_MODIFY) | |
593 | + action = SPLIT_ACTIVATE; | |
594 | + | |
55404221 | 595 | + /* set all flags for modification */ |
596 | + if (asplit && action != SPLIT_REMOVE) | |
597 | + flags = SPLIT_UPDATE; | |
598 | + | |
599 | + /* set the things we need */ | |
12e82c05 | 600 | + creation = atoi(parv[2]); |
601 | + expire = atoi(parv[3]); | |
602 | + lastmod = atoi(parv[4]); | |
603 | + lifetime = atoi(parv[5]); | |
55404221 | 604 | + /* got a reason too */ |
605 | + if (parc < 6) | |
606 | + reason = parv[parc - 1]; | |
12e82c05 | 607 | + |
608 | + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; " | |
609 | + "server %s, action %s, creation %Tu, expire %Tu, " | |
610 | + "lastmod %Tu, lifetime %Tu, reason: %s; split %s!", server, | |
611 | + action == SPLIT_REMOVE ? "!-" : | |
612 | + (action == SPLIT_ACTIVATE ? "+" : | |
613 | + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")), | |
614 | + creation, expire, lastmod, lifetime, reason, | |
615 | + asplit ? "EXISTS" : "does not exist")); | |
616 | + | |
617 | + /* OK, at this point, we have converted all available parameters. | |
618 | + * Let's actually do the action! | |
619 | + */ | |
620 | + if (asplit) { | |
621 | + if (action == SPLIT_REMOVE) | |
622 | + return split_remove(cptr, sptr, asplit, reason); | |
623 | + return split_modify(cptr, sptr, asplit, action, reason, creation, expire, | |
624 | + lastmod, lifetime, flags); | |
625 | + } | |
626 | + | |
55404221 | 627 | + /* desynch or cross - we do not have it so we cannot remove it */ |
628 | + /* TODO: manually propagate the message ? | |
629 | + * ..but if we do not have it, can our downlinks have it? | |
630 | + * they could if my oper force removed it earlier, and then my downlinks linked | |
631 | + * no, then they would have bursted it again to us.. argh | |
632 | + */ | |
633 | + if (!asplit && action == SPLIT_REMOVE) | |
634 | + return 0; | |
635 | + | |
12e82c05 | 636 | + assert(action != SPLIT_MODIFY); |
55404221 | 637 | + assert(action != SPLIT_REMOVE); |
12e82c05 | 638 | + |
55404221 | 639 | + /* only give one flag when needed - SPLIT_ACTIVE */ |
12e82c05 | 640 | + return split_add(cptr, sptr, server, reason, creation, expire, lastmod, lifetime, |
55404221 | 641 | + (flags & SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0); |
12e82c05 | 642 | +} |
643 | + | |
644 | + | |
645 | +/* | |
646 | + * mo_split - oper message handler | |
647 | + * | |
648 | + * Local listing: 1 or 2 params | |
649 | + * parv[0] = Send prefix | |
650 | + * parv[1] = [Server or mask to match] | |
651 | + * | |
652 | + * Add or modify entry: 3, 4 or 5 params (3 is * then) | |
653 | + * parv[0] = Send prefix | |
654 | + * parv[1] = [+|-]<server name> | |
655 | + * parv[2] = [Expiration offset] (required for new) | |
656 | + * parv[3] = [Comment] (required for new) | |
657 | + * | |
658 | + */ | |
659 | +int mo_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
660 | +{ | |
661 | + struct Client *acptr = 0; | |
662 | + struct Split *asplit = 0; | |
663 | + unsigned int flags = 0; | |
664 | + enum SplitAction action = SPLIT_MODIFY; | |
0c63b280 | 665 | + time_t expire = 0, lastmod = TStime(), creation = TStime(); |
12e82c05 | 666 | + char *server = parv[1], *end; |
667 | + const char *reason = NULL; | |
668 | + | |
55404221 | 669 | + /* listing */ |
12e82c05 | 670 | + if (parc < 2) { |
671 | + if (!HasPriv(sptr, PRIV_ROUTEINFO)) | |
672 | + return send_reply(sptr, ERR_NOPRIVILEGES); | |
673 | + else | |
674 | + return split_list(sptr, 0); | |
675 | + } | |
676 | + | |
55404221 | 677 | + /* force removal */ |
12e82c05 | 678 | + if (*server == '!') { |
679 | + server++; | |
55404221 | 680 | + action = SPLIT_REMOVE; |
12e82c05 | 681 | + } |
682 | + | |
683 | + switch (*server) { /* handle + and - */ | |
684 | + case '+': /* activate the split entry */ | |
685 | + if (action != SPLIT_REMOVE) | |
686 | + action = SPLIT_ACTIVATE; | |
687 | + server++; | |
688 | + break; | |
689 | + | |
690 | + case '-': /* deactivate the split entry */ | |
691 | + if (action != SPLIT_REMOVE) | |
692 | + action = SPLIT_DEACTIVATE; | |
693 | + server++; | |
694 | + break; | |
695 | + } | |
12e82c05 | 696 | + |
55404221 | 697 | + /* user wants listing */ |
698 | + if (action == SPLIT_MODIFY && parc == 2) | |
699 | + return split_list(sptr, server); | |
700 | + | |
701 | + /* if we have an expire, this must be it */ | |
702 | + if (parc > 2) | |
703 | + expire = strtol(parv[2], &end, 10); /* and the expiration */ | |
704 | + | |
705 | + /* got reason and expire */ | |
706 | + if (parc > 3) { | |
707 | + flags |= SPLIT_EXPIRE; | |
708 | + flags |= SPLIT_REASON; | |
709 | + } | |
710 | + /* got reason or expire */ | |
711 | + else if (parc > 2) { | |
712 | + if (*end != '\0') | |
12e82c05 | 713 | + flags |= SPLIT_REASON; |
55404221 | 714 | + else |
715 | + flags |= SPLIT_EXPIRE; | |
716 | + } | |
717 | + | |
718 | + /* set reason */ | |
719 | + if (flags & SPLIT_REASON) { | |
12e82c05 | 720 | + reason = parv[parc - 1]; |
55404221 | 721 | + if (reason[0] == '\0') /* reason is empty */ |
722 | + flags &= ~SPLIT_REASON; | |
12e82c05 | 723 | + } |
12e82c05 | 724 | + |
55404221 | 725 | + /* bad expire */ |
726 | + if (flags & SPLIT_EXPIRE && *end != '\0') | |
727 | + return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE, "%s :Bad expire time", parv[2]); | |
728 | + | |
729 | + /* require a reason for forced removal */ | |
730 | + if (!(flags & SPLIT_REASON) && action == SPLIT_REMOVE) | |
731 | + return need_more_params(sptr, "SPLIT"); | |
732 | + | |
733 | + /* we got expire */ | |
734 | + if (flags & SPLIT_EXPIRE) { | |
735 | + if (expire == 0) /* dummy value 0 given, no change to expire */ | |
736 | + flags &= ~SPLIT_EXPIRE; | |
737 | + else /* turn expire into timestamp */ | |
738 | + expire += TStime(); | |
739 | + } | |
740 | + | |
741 | + /* check feature and privs */ | |
12e82c05 | 742 | + if (!feature_bool(FEAT_SPLIT)) /* TODO: but allow force removal? */ |
743 | + return send_reply(sptr, ERR_DISABLED, "SPLIT"); | |
744 | + else if (!HasPriv(sptr, PRIV_SERVERINFO)) /* TODO: create PRIV_SPLIT - need help there */ | |
745 | + return send_reply(sptr, ERR_NOPRIVILEGES); | |
746 | + | |
55404221 | 747 | + /* find the split */ |
12e82c05 | 748 | + asplit = split_find(server); |
749 | + | |
750 | + /* We now have all the pieces to tell us what we've got; let's put | |
751 | + * it all together and convert the rest of the arguments. | |
752 | + */ | |
753 | + | |
55404221 | 754 | + /* SPLIT not found and thus we cannot: |
755 | + * remove SPLIT we do not have | |
756 | + * add new SPLIT without expire and reason | |
12e82c05 | 757 | + */ |
758 | + if (!asplit && | |
759 | + ((action == SPLIT_REMOVE) || | |
760 | + (action == SPLIT_ACTIVATE && !reason) || | |
761 | + (action == SPLIT_DEACTIVATE && !reason) || | |
762 | + (action == SPLIT_MODIFY && !reason))) | |
763 | + return send_reply(sptr, ERR_NOSUCHSPLIT, server); | |
764 | + | |
765 | + /* can't modify a split entry that doesn't exist, so remap to activate */ | |
766 | + if (!asplit && action == SPLIT_MODIFY) | |
767 | + action = SPLIT_ACTIVATE; | |
768 | + | |
769 | + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; " | |
770 | + "server %s, action %s, expire %Tu, " | |
771 | + "reason: %s; split %s! (fields present: %s %s)", server, | |
772 | + action == SPLIT_REMOVE ? "!-" : | |
773 | + (action == SPLIT_ACTIVATE ? "+" : | |
774 | + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")), | |
775 | + expire, reason, asplit ? "EXISTS" : "does not exist", | |
776 | + flags & SPLIT_EXPIRE ? "expire" : "", | |
777 | + flags & SPLIT_REASON ? "reason" : "")); | |
778 | + | |
779 | + if (asplit) { /* modifying an existing SPLIT */ | |
780 | + if (action == SPLIT_REMOVE) | |
781 | + return split_remove(cptr, sptr, asplit, reason); | |
782 | + return split_modify(cptr, sptr, asplit, action, reason, | |
783 | + asplit->sp_creation, expire, lastmod, asplit->sp_lifetime, flags); | |
784 | + } | |
785 | + | |
786 | + assert(action != SPLIT_MODIFY); | |
787 | + assert(action != SPLIT_REMOVE); | |
788 | + | |
789 | + /* create a new SPLIT */ | |
790 | + return split_add(cptr, sptr, server, reason, | |
791 | + creation, expire, lastmod, expire, | |
792 | + flags | ((action == SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0)); | |
793 | +} | |
794 | + | |
795 | +/* | |
796 | + * m_split - user message handler | |
797 | + * | |
798 | + * parv[0] = Send prefix | |
12e82c05 | 799 | + * parv[1] = [<server name>] |
800 | + * | |
801 | + */ | |
802 | +int m_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[]) | |
803 | +{ | |
804 | + if (parc < 2) | |
805 | + return split_list(sptr, 0); | |
806 | + | |
807 | + return split_list(sptr, parv[1]); | |
808 | +} | |
d61bc4d5 | 809 | diff -r 2267c134dc0d ircd/parse.c |
810 | --- a/ircd/parse.c Tue Jan 27 18:19:11 2009 +0100 | |
811 | +++ b/ircd/parse.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 812 | @@ -505,6 +505,13 @@ |
a87bc2c2 | 813 | /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */ |
814 | { m_unregistered, m_not_oper, ms_jupe, mo_jupe, m_ignore, mh_jupe } | |
815 | }, | |
12e82c05 | 816 | + { |
817 | + MSG_SPLIT, | |
818 | + TOK_SPLIT, | |
819 | + 0, MAXPARA, MFLG_SLOW, 0, NULL, | |
a87bc2c2 | 820 | + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */ |
821 | + { m_unregistered, m_not_oper, ms_split, mo_split, m_ignore, mh_nohelp } | |
822 | + }, | |
12e82c05 | 823 | { |
824 | MSG_OPMODE, | |
a87bc2c2 | 825 | TOK_OPMODE, |
d61bc4d5 | 826 | diff -r 2267c134dc0d ircd/s_conf.c |
827 | --- a/ircd/s_conf.c Tue Jan 27 18:19:11 2009 +0100 | |
828 | +++ b/ircd/s_conf.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 829 | @@ -53,6 +53,7 @@ |
830 | #include "s_debug.h" | |
831 | #include "s_misc.h" | |
832 | #include "send.h" | |
833 | +#include "split.h" | |
834 | #include "struct.h" | |
835 | #include "sys.h" | |
836 | ||
837 | @@ -1005,6 +1006,7 @@ | |
838 | } | |
839 | ||
840 | attach_conf_uworld(&me); | |
841 | + split_conf(); | |
842 | ||
843 | return ret; | |
844 | } | |
d61bc4d5 | 845 | diff -r 2267c134dc0d ircd/s_debug.c |
846 | --- a/ircd/s_debug.c Tue Jan 27 18:19:11 2009 +0100 | |
847 | +++ b/ircd/s_debug.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 848 | @@ -48,6 +48,7 @@ |
849 | #include "s_user.h" | |
850 | #include "s_stats.h" | |
851 | #include "send.h" | |
852 | +#include "split.h" | |
853 | #include "struct.h" | |
854 | #include "sys.h" | |
d61bc4d5 | 855 | #include "welcome.h" |
856 | @@ -233,6 +234,7 @@ | |
12e82c05 | 857 | wwa = 0, /* whowas aways */ |
858 | gl = 0, /* glines */ | |
d61bc4d5 | 859 | ju = 0, /* jupes */ |
860 | + sp = 0, /* split entries */ | |
861 | we = 0; /* welcome messages */ | |
12e82c05 | 862 | |
863 | size_t chm = 0, /* memory used by channels */ | |
d61bc4d5 | 864 | @@ -246,6 +248,7 @@ |
12e82c05 | 865 | wwm = 0, /* whowas array memory used */ |
866 | glm = 0, /* memory used by glines */ | |
867 | jum = 0, /* memory used by jupes */ | |
868 | + spm = 0, /* memory used by split entries */ | |
d61bc4d5 | 869 | wem = 0, /* memory used by welcome messages */ |
12e82c05 | 870 | com = 0, /* memory used by conf lines */ |
871 | dbufs_allocated = 0, /* memory used by dbufs */ | |
d61bc4d5 | 872 | @@ -351,10 +354,11 @@ |
12e82c05 | 873 | |
874 | gl = gline_memory_count(&glm); | |
875 | ju = jupe_memory_count(&jum); | |
876 | + sp = split_memory_count(&spm); | |
d61bc4d5 | 877 | we = welcome_memory_count(&wem); |
12e82c05 | 878 | send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, |
d61bc4d5 | 879 | - ":Glines %d(%zu) Jupes %d(%zu) WelcomeMessages %d(%zu)", |
880 | - gl, glm, ju, jum, we, wem); | |
881 | + ":Glines %d(%zu) Jupes %d(%zu) Splits %d(%zu) WelcomeMessages %d(%zu)", | |
882 | + gl, glm, ju, jum, sp, spm, we, wem); | |
12e82c05 | 883 | |
884 | send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG, | |
885 | ":Hash: client %d(%zu), chan is the same", HASHSIZE, | |
d61bc4d5 | 886 | diff -r 2267c134dc0d ircd/s_err.c |
887 | --- a/ircd/s_err.c Tue Jan 27 18:19:11 2009 +0100 | |
888 | +++ b/ircd/s_err.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 889 | @@ -490,7 +490,7 @@ |
890 | /* 228 */ | |
891 | { RPL_STATSQLINE, "Q %s :%s", "228" }, | |
892 | /* 229 */ | |
893 | - { 0 }, | |
894 | + { RPL_STATSSPLIT, "S %s %d %d %d %d %c :%s", "229" }, | |
895 | /* 230 */ | |
65b70298 | 896 | { RPL_STATSHEADER, 0, "230" }, |
12e82c05 | 897 | /* 231 */ |
898 | @@ -588,9 +588,9 @@ | |
899 | /* 277 */ | |
900 | { 0 }, | |
901 | /* 278 */ | |
902 | - { 0 }, | |
903 | + { RPL_SPLITLIST, "%s %Tu %Tu %Tu %Tu %c :%s", "278" }, | |
904 | /* 279 */ | |
905 | - { 0 }, | |
906 | + { RPL_ENDOFSPLITLIST, ":End of Split List", "279" }, | |
907 | /* 280 */ | |
65b70298 | 908 | { RPL_GLIST, "%s%s%s%s%s %Tu %Tu %Tu %s %s%s%c :%s", "280" }, |
12e82c05 | 909 | /* 281 */ |
910 | @@ -1052,7 +1052,7 @@ | |
911 | /* 509 */ | |
d61bc4d5 | 912 | { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" }, |
12e82c05 | 913 | /* 510 */ |
914 | - { 0 }, | |
915 | + { ERR_NOSUCHSPLIT, "%s :No such split", "510" }, | |
916 | /* 511 */ | |
917 | { ERR_SILELISTFULL, "%s :Your silence list is full", "511" }, | |
918 | /* 512 */ | |
d61bc4d5 | 919 | diff -r 2267c134dc0d ircd/s_misc.c |
920 | --- a/ircd/s_misc.c Tue Jan 27 18:19:11 2009 +0100 | |
921 | +++ b/ircd/s_misc.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 922 | @@ -53,6 +53,7 @@ |
923 | #include "s_stats.h" | |
924 | #include "s_user.h" | |
925 | #include "send.h" | |
926 | +#include "split.h" | |
927 | #include "struct.h" | |
928 | #include "sys.h" | |
929 | #include "uping.h" | |
930 | @@ -391,6 +392,7 @@ | |
931 | time_t on_for; | |
932 | ||
933 | char comment1[HOSTLEN + HOSTLEN + 2]; | |
934 | + char splitreason[BUFSIZE]; | |
935 | assert(killer); | |
936 | if (MyConnect(victim)) | |
937 | { | |
7efbed3b | 938 | @@ -497,6 +499,15 @@ |
12e82c05 | 939 | sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)", |
940 | cli_serv(victim)->up, victim, comment); | |
941 | dump_map(victim, "*", 0, report_lost_links, 0); | |
942 | + if (feature_bool(FEAT_SPLIT)) { | |
7efbed3b | 943 | + /* TODO: remote & local SQUIT ? servername oper is on? */ |
12e82c05 | 944 | + ircd_snprintf(0, splitreason, sizeof(splitreason), |
945 | + "Net break: %C %C (%s%s%s%s)", cli_serv(victim)->up, victim, | |
946 | + IsUser(killer) ? "SQUIT by " : "", IsUser(killer) ? cli_name(killer) : "", | |
947 | + IsUser(killer) ? ": " : "", comment); | |
948 | + sendto_opmask_butone(0, SNO_NETWORK, "Created %d SPLIT entries.", | |
0c63b280 | 949 | + split_netbreak(victim, splitreason)); |
12e82c05 | 950 | + } |
951 | } | |
952 | ||
953 | /* | |
d61bc4d5 | 954 | diff -r 2267c134dc0d ircd/s_serv.c |
955 | --- a/ircd/s_serv.c Tue Jan 27 18:19:11 2009 +0100 | |
956 | +++ b/ircd/s_serv.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 957 | @@ -54,6 +54,7 @@ |
958 | #include "s_misc.h" | |
959 | #include "s_user.h" | |
960 | #include "send.h" | |
961 | +#include "split.h" | |
962 | #include "struct.h" | |
963 | #include "sys.h" | |
964 | #include "userload.h" | |
d61bc4d5 | 965 | @@ -197,6 +198,7 @@ |
12e82c05 | 966 | */ |
967 | gline_burst(cptr); | |
968 | jupe_burst(cptr); | |
969 | + split_burst(cptr); | |
d61bc4d5 | 970 | welcome_burst(cptr); |
12e82c05 | 971 | |
972 | /* | |
d61bc4d5 | 973 | diff -r 2267c134dc0d ircd/s_stats.c |
974 | --- a/ircd/s_stats.c Tue Jan 27 18:19:11 2009 +0100 | |
975 | +++ b/ircd/s_stats.c Tue Jan 27 18:25:58 2009 +0100 | |
12e82c05 | 976 | @@ -52,6 +52,7 @@ |
977 | #include "s_stats.h" | |
978 | #include "s_user.h" | |
979 | #include "send.h" | |
980 | +#include "split.h" | |
981 | #include "struct.h" | |
982 | #include "userload.h" | |
d61bc4d5 | 983 | #include "welcome.h" |
984 | @@ -669,7 +670,10 @@ | |
12e82c05 | 985 | send_usage, 0, |
986 | "System resource usage (Debug only)." }, | |
987 | #endif | |
988 | - { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_s, | |
989 | + { 'S', "splits", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_S, | |
990 | + split_stats, 0, | |
991 | + "Server SPLITs information."}, | |
992 | + { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_s, | |
993 | stats_sline, 0, | |
994 | "Spoofed hosts information." }, | |
995 | { 'T', "motds", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_T, | |
d61bc4d5 | 996 | diff -r 2267c134dc0d ircd/split.c |
12e82c05 | 997 | --- /dev/null Thu Jan 01 00:00:00 1970 +0000 |
d61bc4d5 | 998 | +++ b/ircd/split.c Tue Jan 27 18:25:58 2009 +0100 |
55404221 | 999 | @@ -0,0 +1,786 @@ |
12e82c05 | 1000 | +/* |
1001 | + * IRC - Internet Relay Chat, ircd/split.c | |
1002 | + * Copyright (C) 1990 Jarkko Oikarinen and | |
1003 | + * University of Oulu, Finland | |
1004 | + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu> | |
1005 | + * | |
1006 | + * This program is free software; you can redistribute it and/or modify | |
1007 | + * it under the terms of the GNU General Public License as published by | |
1008 | + * the Free Software Foundation; either version 1, or (at your option) | |
1009 | + * any later version. | |
1010 | + * | |
1011 | + * This program is distributed in the hope that it will be useful, | |
1012 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
1013 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
1014 | + * GNU General Public License for more details. | |
1015 | + * | |
1016 | + * You should have received a copy of the GNU General Public License | |
1017 | + * along with this program; if not, write to the Free Software | |
1018 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
1019 | + */ | |
1020 | +/** @file | |
1021 | + * @brief Implementation of split server handling functions. | |
1022 | + * @version $Id: split.c 1633 2006-03-25 03:46:56Z entrope $ | |
1023 | + */ | |
1024 | +#include "config.h" | |
1025 | + | |
1026 | +#include "split.h" | |
1027 | +#include "client.h" | |
1028 | +#include "hash.h" | |
1029 | +#include "ircd.h" | |
1030 | +#include "ircd_alloc.h" | |
1031 | +#include "ircd_features.h" | |
1032 | +#include "ircd_log.h" | |
1033 | +#include "ircd_reply.h" | |
1034 | +#include "ircd_string.h" | |
1035 | +#include "list.h" | |
1036 | +#include "match.h" | |
1037 | +#include "msg.h" | |
1038 | +#include "numeric.h" | |
1039 | +#include "numnicks.h" | |
1040 | +#include "s_conf.h" | |
1041 | +#include "s_bsd.h" | |
1042 | +#include "s_debug.h" | |
1043 | +#include "s_misc.h" | |
1044 | +#include "send.h" | |
1045 | +#include "struct.h" | |
1046 | +#include "sys.h" /* FALSE bleah */ | |
1047 | + | |
1048 | +/* #include <assert.h> -- Now using assert in ircd_log.h */ | |
1049 | +#include <string.h> | |
1050 | + | |
1051 | +/** List of split entries. */ | |
1052 | +static struct Split *GlobalSplitList = 0; | |
1053 | + | |
1054 | +/** Allocate a new Split entry with the given parameters. | |
1055 | + * @param[in] server Server name for split entry. | |
1056 | + * @param[in] reason Reason for the split entry. | |
1057 | + * @param[in] creation Creation time for split entry. | |
1058 | + * @param[in] expire Expiration time for split entry. | |
1059 | + * @param[in] lastmod Last modification time for split entry. | |
1060 | + * @param[in] lifetime Life time for split entry. | |
1061 | + * @param[in] flags Flags to set for the split entry. | |
1062 | + */ | |
1063 | +static struct Split * | |
1064 | +split_make(char *server, const char *reason, | |
1065 | + time_t creation, time_t expire, time_t lastmod, time_t lifetime, | |
1066 | + unsigned int flags) | |
1067 | +{ | |
1068 | + struct Split *asplit; | |
1069 | + | |
1070 | + asplit = (struct Split*) MyMalloc(sizeof(struct Split)); /* alloc memory */ | |
1071 | + assert(0 != asplit); | |
1072 | + | |
1073 | + memset(asplit, 0, sizeof(*asplit)); | |
1074 | + /* TODO: some limit for servername length? HOSTLEN? */ | |
1075 | + DupString(asplit->sp_server, server); /* copy vital information */ | |
0c63b280 | 1076 | + /* TODO: some limit for reason length? QUITLEN TOPICLEN? */ |
65b70298 | 1077 | + /* TODO: prefix the reason here with the opername/ID? */ |
12e82c05 | 1078 | + DupString(asplit->sp_reason, reason); |
1079 | + /* TODO: what we use creation for and do we need it? */ | |
1080 | + asplit->sp_creation = creation; | |
1081 | + asplit->sp_expire = expire; | |
1082 | + /* TODO: are we using nettime etc.? CurrentTime is used. */ | |
65b70298 | 1083 | + /* TODO: TStime() is CurrentTime + TSoffset */ |
12e82c05 | 1084 | + asplit->sp_lastmod = lastmod; |
1085 | + asplit->sp_lifetime = lifetime; | |
12e82c05 | 1086 | + asplit->sp_flags = flags & SPLIT_ACTIVE; /* set split flags */ |
1087 | + | |
1088 | + asplit->sp_next = GlobalSplitList; /* link it into the list */ | |
1089 | + asplit->sp_prev_p = &GlobalSplitList; | |
1090 | + if (GlobalSplitList) | |
1091 | + GlobalSplitList->sp_prev_p = &asplit->sp_next; | |
1092 | + GlobalSplitList = asplit; | |
1093 | + | |
1094 | + return asplit; | |
1095 | +} | |
1096 | + | |
1097 | +/** Forward a split entry to another server. | |
1098 | + * @param[in] cptr Local client that sent us the split entry. | |
1099 | + * @param[in] sptr Originator of the split entry. | |
1100 | + * @param[in] split Split entry to forward. | |
1101 | + * @param[in] reason Reason to send upstream (used by split_remove) | |
1102 | + */ | |
1103 | +static void | |
1104 | +split_propagate(struct Client *cptr, struct Client *sptr, | |
1105 | + struct Split *split, const char *reason) | |
1106 | +{ | |
1107 | + sendcmdto_serv_butone(sptr, CMD_SPLIT, cptr, "%s%c%s %Tu %Tu %Tu %Tu :%s", | |
1108 | + SplitIsRemoving(split) ? "!" : "", | |
1109 | + SplitIsActive(split) && !SplitIsRemoving(split) ? '+' : '-', /* always !- not !+ */ | |
1110 | + split->sp_server, split->sp_creation, split->sp_expire, | |
1111 | + split->sp_lastmod, split->sp_lifetime, | |
65b70298 | 1112 | + /* TODO: does reason ? reason : split->sp_reason work too? */ |
12e82c05 | 1113 | + reason != NULL ? reason : split->sp_reason); |
1114 | +} | |
1115 | + | |
1116 | +/** Add a new server split entry. | |
1117 | + * @param[in] cptr Local client that sent us the split entry. | |
1118 | + * @param[in] sptr Originator of the split entry. | |
1119 | + * @param[in] server Server name to split entry. | |
1120 | + * @param[in] reason Reason for the split entry. | |
1121 | + * @param[in] expire Expiration timestamp. | |
1122 | + * @param[in] lastmod Last modification timestamp. | |
1123 | + * @param[in] flags Flags to set on the split entry. | |
1124 | + * @return Zero | |
1125 | + */ | |
1126 | +int | |
1127 | +split_add(struct Client *cptr, struct Client *sptr, char *server, const char *reason, | |
1128 | + time_t creation, time_t expire, time_t lastmod, time_t lifetime, | |
1129 | + unsigned int flags) | |
1130 | +{ | |
1131 | + | |
12e82c05 | 1132 | + struct Split *asplit; |
1133 | + struct Client *acptr; | |
55404221 | 1134 | + char noreason[BUFSIZE]; |
12e82c05 | 1135 | + |
55404221 | 1136 | + assert(0 != cptr); |
1137 | + assert(0 != sptr); | |
12e82c05 | 1138 | + assert(0 != server); |
1139 | + assert(0 != reason); | |
12e82c05 | 1140 | + |
1141 | + Debug((DEBUG_DEBUG, "split_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu, %Tu, " | |
1142 | + "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), server, reason, | |
1143 | + creation, expire, lastmod, lifetime, flags)); | |
1144 | + | |
1145 | + /* not adding SPLIT for server that is linked | |
1146 | + * if sptr is my user throw error | |
1147 | + * otherwise ignore - SERVER and SPLIT messages can cross, | |
1148 | + * or a server is bursting and it will see our end and destroy the SPLITs | |
1149 | + */ | |
1150 | + if ((acptr = FindServer(server))) { | |
1151 | + if (MyUser(sptr)) | |
1152 | + sendcmdto_one(&me, CMD_NOTICE, sptr, | |
1153 | + "%C :Cannot add SPLIT %s - server is linked.", sptr, server); | |
1154 | + return 0; | |
1155 | + } | |
1156 | + | |
1157 | + /* | |
1158 | + * You cannot set a negative (or zero) duration, nor can you set an | |
1159 | + * duration greater than SPLIT_MAX_EXPIRE. | |
1160 | + */ | |
0c63b280 | 1161 | + if (expire - TStime() <= 0 || expire - TStime() > SPLIT_MAX_EXPIRE) { |
55404221 | 1162 | + /* TODO: cptr or sptr here? */ |
1163 | + if (MyUser(sptr)) | |
0c63b280 | 1164 | + return send_reply(cptr, ERR_BADEXPIRE, expire - TStime()); |
1165 | + if (lifetime <= TStime()) /* no point going further */ | |
12e82c05 | 1166 | + /* CHECK: sptr may have the wrong idea about the nettime? |
1167 | + * or we could be wrong? | |
12e82c05 | 1168 | + * perhaps raise some sort of warning to ops |
65b70298 | 1169 | + */ |
12e82c05 | 1170 | + return 0; |
1171 | + } | |
1172 | + | |
55404221 | 1173 | + /* empty reason */ |
1174 | + if (reason[0] == '\0') | |
1175 | + ircd_snprintf(0, noreason, sizeof(noreason), "%C gave no reason.", sptr); | |
1176 | + | |
65b70298 | 1177 | + /* TODO: add opername */ |
12e82c05 | 1178 | + /* inform ops and log it */ |
1179 | + sendto_opmask_butone(0, SNO_NETWORK, "%s adding%sSPLIT for %s, expiring at %Tu: %s", | |
1180 | + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? | |
1181 | + cli_name(sptr) : cli_name((cli_user(sptr))->server), | |
1182 | + !(flags & SPLIT_ACTIVE) ? " deactivated " : " ", | |
55404221 | 1183 | + server, expire, reason[0] == '\0' ? noreason : reason); |
12e82c05 | 1184 | + |
0c63b280 | 1185 | + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE, |
12e82c05 | 1186 | + "%#C adding%sSPLIT for %s, expiring at %Tu: %s", |
1187 | + sptr, !(flags & SPLIT_ACTIVE) ? " deactivated " : " ", | |
55404221 | 1188 | + server, expire, reason[0] == '\0' ? noreason : reason); |
12e82c05 | 1189 | + |
1190 | + /* make the split entry */ | |
55404221 | 1191 | + asplit = split_make(server, reason[0] == '\0' ? noreason : reason, |
1192 | + creation, expire, lastmod, lifetime, flags); | |
12e82c05 | 1193 | + |
1194 | + assert(asplit); | |
1195 | + | |
1196 | + /* and propagate it */ | |
1197 | + split_propagate(cptr, sptr, asplit, NULL); | |
1198 | + | |
1199 | + return 0; | |
1200 | +} | |
1201 | + | |
1202 | + | |
1203 | +/** Modify a split entry. | |
1204 | + * @param[in] cptr Client that sent us the split modification. | |
1205 | + * @param[in] sptr Client that originated the split modification. | |
1206 | + * @param[in] split Split entry being modified. | |
1207 | + * @param[in] action Resultant status of the G-line. | |
1208 | + * @param[in] reason Reason. | |
1209 | + * @param[in] expire Expiration time. | |
1210 | + * @param[in] lastmod Last modification time. | |
1211 | + * @param[in] lifetime Lifetime. | |
1212 | + * @param[in] flags Bitwise combination of SPLIT_* flags. | |
1213 | + * @return Zero. | |
1214 | + */ | |
1215 | +int | |
1216 | +split_modify(struct Client *cptr, struct Client *sptr, struct Split *split, | |
1217 | + enum SplitAction action, const char *reason, | |
1218 | + time_t creation, time_t expire, time_t lastmod, time_t lifetime, | |
1219 | + unsigned int flags) | |
1220 | +{ | |
1221 | + struct Client* acptr; | |
1222 | + char buf[BUFSIZE]; | |
1223 | + int pos = 0; | |
1224 | + | |
55404221 | 1225 | + assert(0 != cptr); |
1226 | + assert(0 != sptr); | |
1227 | + assert(0 != split); | |
12e82c05 | 1228 | + |
55404221 | 1229 | + Debug((DEBUG_DEBUG, "split_modify(cptr \"%s\", sptr \"%s\", split \"%s\", reason \"%s\"," |
1230 | + " action %d, creation %Tu, expire %Tu, lastmod %Tu, lifetime %Tu, flags 0x%04x)", | |
1231 | + cli_name(cptr), cli_name(sptr), split->sp_server, reason, action, | |
12e82c05 | 1232 | + creation, expire, lastmod, lifetime, flags)); |
1233 | + | |
1234 | + /* not modifying SPLIT for server that is linked | |
1235 | + * if sptr is my user throw error | |
1236 | + * otherwise ignore - SERVER and SPLIT messages can cross. | |
1237 | + * | |
1238 | + * note: we cleanup SPLIT entries at end of burst, | |
1239 | + * and not when a server is introduced. | |
1240 | + * so between net junction and end of burst, | |
1241 | + * we can get SPLITs for a linked server. | |
65b70298 | 1242 | + * also more than one server can be bursting at a time. |
12e82c05 | 1243 | + */ |
12e82c05 | 1244 | + if ((acptr = FindServer(split->sp_server))) { |
1245 | + if (MyUser(sptr)) | |
1246 | + sendcmdto_one(&me, CMD_NOTICE, sptr, | |
1247 | + "%C :Cannot modify SPLIT %s - server is linked.", sptr, split->sp_server); | |
0c63b280 | 1248 | + /* SPLIT is not for a server part of a netmerge */ |
1249 | + if (!SplitIsBurst(split)) | |
1250 | + split_free(split); /* and free it */ | |
12e82c05 | 1251 | + return 0; |
1252 | + } | |
55404221 | 1253 | + |
1254 | + /* check lastmod */ | |
0c63b280 | 1255 | + if (split->sp_lastmod > lastmod) { /* we have a more recent version */ |
55404221 | 1256 | + if (IsBurstOrBurstAck(cptr)) /* middle of a burst, it will resync on its own */ |
1257 | + return 0; | |
12e82c05 | 1258 | + return split_resend(cptr, split); /* resync the server */ |
55404221 | 1259 | + } else if (split->sp_lastmod == lastmod) /* same version */ |
1260 | + return 0; | |
12e82c05 | 1261 | + |
55404221 | 1262 | + /* there is a change of some sort */ |
1263 | + /* check out the expiration time */ | |
1264 | + if (flags & SPLIT_EXPIRE) { | |
1265 | + if (expire != split->sp_expire) { | |
1266 | + /* bad expiration time */ | |
1267 | + if (MyUser(sptr) && (expire < TStime() || expire - TStime() > SPLIT_MAX_EXPIRE)) | |
0c63b280 | 1268 | + return send_reply(sptr, ERR_BADEXPIRE, expire - TStime()); |
55404221 | 1269 | + /* expire timestamp is in the past, so remap to deactivate */ |
1270 | + if (expire < TStime() && action == SPLIT_ACTIVATE) | |
1271 | + action = SPLIT_DEACTIVATE; | |
1272 | + } else | |
1273 | + flags &= ~SPLIT_EXPIRE; | |
1274 | + } | |
0c63b280 | 1275 | + |
12e82c05 | 1276 | + /* Next, check out lifetime */ |
1277 | + if (!(flags & SPLIT_LIFETIME) || !lifetime) | |
1278 | + lifetime = split->sp_lifetime; /* use Split lifetime */ | |
1279 | + | |
1280 | + lifetime = IRCD_MAX(lifetime, expire); /* set lifetime to the max */ | |
1281 | + | |
0c63b280 | 1282 | + /* now that we have the correct lifetime, check it */ |
1283 | + if (lifetime - TStime() <= 0) /* no point in going further */ | |
1284 | + return 0; | |
1285 | + | |
12e82c05 | 1286 | + /* OK, let's see which is greater... */ |
1287 | + if (lifetime > split->sp_lifetime) | |
1288 | + flags |= SPLIT_LIFETIME; /* have to update lifetime */ | |
1289 | + else { | |
1290 | + flags &= ~SPLIT_LIFETIME; /* no change to lifetime */ | |
1291 | + lifetime = 0; | |
1292 | + } | |
55404221 | 1293 | + |
12e82c05 | 1294 | + /* Finally, let's see if the reason needs to be updated */ |
55404221 | 1295 | + if ((flags & SPLIT_REASON) && (reason[0] == '\0' || !ircd_strcmp(split->sp_reason, reason))) |
12e82c05 | 1296 | + flags &= ~SPLIT_REASON; /* no changes to the reason */ |
1297 | + | |
1298 | + /* OK, now let's take a look at the action... */ | |
1299 | + if ((action == SPLIT_ACTIVATE && SplitIsActive(split)) || | |
1300 | + (action == SPLIT_DEACTIVATE && !SplitIsActive(split)) || | |
1301 | + /* can't activate an expired split entry */ | |
0c63b280 | 1302 | + (IRCD_MAX(split->sp_expire, expire) <= TStime())) |
12e82c05 | 1303 | + action = SPLIT_MODIFY; /* no activity state modifications */ |
1304 | + | |
1305 | + Debug((DEBUG_DEBUG, "About to perform changes; flags 0x%04x, action %s", | |
1306 | + flags, action == SPLIT_ACTIVATE ? "SPLIT_ACTIVATE" : | |
1307 | + (action == SPLIT_DEACTIVATE ? "SPLIT_DEACTIVATE" : | |
1308 | + (action == SPLIT_MODIFY ? "SPLIT_MODIFY" : "<UNKNOWN>")))); | |
1309 | + | |
1310 | + /* If there are no changes to perform, do no changes */ | |
55404221 | 1311 | + if (!(flags & SPLIT_UPDATE) && action == SPLIT_MODIFY) { |
1312 | + if (MyUser(sptr)) | |
1313 | + sendcmdto_one(&me, CMD_NOTICE, sptr, | |
1314 | + "%C :Cannot modify SPLIT %s - nothing to change.", sptr, split->sp_server); | |
12e82c05 | 1315 | + return 0; |
55404221 | 1316 | + } |
12e82c05 | 1317 | + |
1318 | + /* Start by updating lastmod, if indicated... */ | |
1319 | + split->sp_lastmod = lastmod; | |
1320 | + | |
1321 | + /* Then move on to activity status changes... */ | |
1322 | + switch (action) { | |
1323 | + case SPLIT_ACTIVATE: /* activating split entry */ | |
1324 | + split->sp_flags |= SPLIT_ACTIVE; /* make it active... */ | |
1325 | + pos += ircd_snprintf(0, buf, sizeof(buf), " activating SPLIT"); | |
1326 | + break; | |
1327 | + | |
1328 | + case SPLIT_DEACTIVATE: /* deactivating split entry */ | |
1329 | + split->sp_flags &= ~SPLIT_ACTIVE; /* make it inactive... */ | |
1330 | + pos += ircd_snprintf(0, buf, sizeof(buf), " deactivating SPLIT"); | |
1331 | + break; | |
1332 | + | |
1333 | + case SPLIT_MODIFY: /* no change to activity status */ | |
1334 | + break; | |
1335 | + } | |
1336 | + | |
55404221 | 1337 | + /* TODO: Handle creation changes... */ |
1338 | + | |
12e82c05 | 1339 | + /* Handle expiration changes... */ |
1340 | + if (flags & SPLIT_EXPIRE) { | |
1341 | + split->sp_expire = expire; /* save new expiration time */ | |
1342 | + if (pos < BUFSIZE) | |
1343 | + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos, | |
1344 | + "%s%s changing expiration time to %Tu", | |
1345 | + pos ? ";" : "", | |
1346 | + pos && !(flags & (SPLIT_LIFETIME | SPLIT_REASON)) ? | |
1347 | + " and" : "", expire); | |
1348 | + } | |
1349 | + | |
1350 | + /* Next, handle lifetime changes... */ | |
1351 | + if (flags & SPLIT_LIFETIME) { | |
1352 | + split->sp_lifetime = lifetime; /* save new lifetime */ | |
1353 | + if (pos < BUFSIZE) | |
1354 | + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos, | |
1355 | + "%s%s extending record lifetime to %Tu", | |
1356 | + pos ? ";" : "", pos && !(flags & SPLIT_REASON) ? | |
1357 | + " and" : "", lifetime); | |
1358 | + } | |
1359 | + | |
1360 | + /* Now, handle reason changes... */ | |
1361 | + if (flags & SPLIT_REASON) { | |
1362 | + MyFree(split->sp_reason); /* release old reason */ | |
1363 | + DupString(split->sp_reason, reason); /* store new reason */ | |
1364 | + if (pos < BUFSIZE) | |
1365 | + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos, | |
1366 | + "%s%s changing reason to \"%s\"", | |
1367 | + pos ? ";" : "", pos ? " and" : "", reason); | |
1368 | + } | |
1369 | + | |
65b70298 | 1370 | + /* TODO: add opername */ |
12e82c05 | 1371 | + /* All right, inform ops... */ |
1372 | + sendto_opmask_butone(0, SNO_NETWORK, "%s modifying SPLIT for %s:%s", | |
1373 | + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? | |
1374 | + cli_name(sptr) : cli_name((cli_user(sptr))->server), | |
1375 | + split->sp_server, buf); | |
1376 | + | |
12e82c05 | 1377 | + /* and log the change */ |
0c63b280 | 1378 | + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE, |
12e82c05 | 1379 | + "%#C modifying SPLIT for %s:%s", |
1380 | + sptr, split->sp_server, buf); | |
1381 | + | |
1382 | + /* and propagate it */ | |
1383 | + split_propagate(cptr, sptr, split, NULL); | |
1384 | + | |
1385 | + return 0; | |
1386 | +} | |
1387 | + | |
1388 | + | |
1389 | +/** Remove a split entry. | |
1390 | + * @param[in] cptr Local client that sent us the split entry. | |
1391 | + * @param[in] sptr Originator of the split entry. | |
1392 | + * @param[in] split Split entry to remove. | |
1393 | + * @param[in] reason Reason for removing this split entry. | |
1394 | + * @return Zero. | |
1395 | + */ | |
1396 | +int | |
1397 | +split_remove(struct Client *cptr, struct Client *sptr, struct Split *split, const char *reason) | |
1398 | +{ | |
1399 | + unsigned int saveflags = 0; | |
1400 | + | |
1401 | + assert(0 != split); | |
1402 | + assert(NULL != cptr); | |
1403 | + assert(NULL != sptr); | |
1404 | + | |
1405 | + Debug((DEBUG_DEBUG, "split_remove(\"%s\", \"%s\", \"%s\", \"%s\")", | |
1406 | + cli_name(cptr), cli_name(sptr), split->sp_server, reason)); | |
1407 | + | |
1408 | + /* deactivate entry and mark it for removal (used in split_propagate) */ | |
1409 | + split->sp_flags |= SPLIT_REMOVING; | |
0c63b280 | 1410 | + split->sp_flags &= ~SPLIT_ACTIVE; |
12e82c05 | 1411 | + |
65b70298 | 1412 | + /* TODO: add opername? */ |
12e82c05 | 1413 | + /* inform ops and log it */ |
1414 | + sendto_opmask_butone(0, SNO_NETWORK, "%s removing SPLIT for %s, expiring at %Tu: %s (%s)", | |
1415 | + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ? | |
1416 | + cli_name(sptr) : cli_name((cli_user(sptr))->server), | |
1417 | + split->sp_server, split->sp_expire, split->sp_reason, reason); | |
1418 | + | |
0c63b280 | 1419 | + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE, |
12e82c05 | 1420 | + "%#C removing SPLIT for %s, expiring at %Tu: %s (%s)", |
1421 | + sptr, split->sp_server, split->sp_expire, split->sp_reason, reason); | |
1422 | + | |
12e82c05 | 1423 | + /* propagate it */ |
1424 | + split_propagate(cptr, sptr, split, reason); | |
1425 | + | |
1426 | + /* destroy it */ | |
1427 | + split_free(split); | |
1428 | + | |
1429 | + return 0; | |
1430 | +} | |
1431 | + | |
1432 | + | |
1433 | +/** Find a split entry by name. | |
1434 | + * @param[in] server Split entry name to search for. | |
1435 | + * @return Matching split entry (or NULL if none match). | |
1436 | + */ | |
1437 | +struct Split * | |
1438 | +split_find(char *server) | |
1439 | +{ | |
1440 | + struct Split* split; | |
1441 | + struct Split* ssplit; | |
1442 | + | |
1443 | + for (split = GlobalSplitList; split; split = ssplit) { /* go through splits */ | |
1444 | + ssplit = split->sp_next; | |
1445 | + | |
1446 | + if (split_expire(split)) /* expire any that need expiring */ | |
1447 | + split_free(split); | |
1448 | + else if (0 == ircd_strcmp(server, split->sp_server)) /* found it yet? */ | |
1449 | + return split; | |
1450 | + } | |
1451 | + /* TODO: we return 0 not NULL? */ | |
1452 | + return 0; | |
1453 | +} | |
1454 | + | |
1455 | +/** Unlink and free an unused split entry. | |
1456 | + * @param[in] split Server split entry to free. | |
1457 | + */ | |
1458 | +void | |
1459 | +split_free(struct Split* split) | |
1460 | +{ | |
1461 | + /* TODO: use 0 or NULL ? */ | |
1462 | + assert(0 != split); | |
1463 | + | |
1464 | + *split->sp_prev_p = split->sp_next; /* squeeze this split entry out */ | |
1465 | + if (split->sp_next) | |
1466 | + split->sp_next->sp_prev_p = split->sp_prev_p; | |
1467 | + | |
1468 | + /* CHECK: the other fields in this struct are destroyed with MyFree() call? */ | |
1469 | + MyFree(split->sp_server); /* and free up the memory */ | |
1470 | + MyFree(split->sp_reason); | |
1471 | + MyFree(split); | |
1472 | +} | |
1473 | + | |
1474 | + | |
1475 | +/** Check whether a split entry has past its life time. | |
1476 | + * when entry is active and past expire time, but not life time, deactivate it | |
1477 | + * @param[in] split Server split entry to check. | |
1478 | + * @return 1 when entry can be free'd, 0 otherwise. | |
1479 | + */ | |
1480 | +int | |
1481 | +split_expire(struct Split* split) | |
1482 | +{ | |
1483 | + assert(0 != split); | |
1484 | + | |
65b70298 | 1485 | + /* TODO: also check if the server in SPLIT entry is linked atm? */ |
12e82c05 | 1486 | + /* past lifetime */ |
0c63b280 | 1487 | + if (split->sp_lifetime <= TStime()) |
12e82c05 | 1488 | + return 1; |
1489 | + | |
1490 | + /* past expire time, deactivate entry if it is active */ | |
0c63b280 | 1491 | + if ((split->sp_expire <= TStime()) && SplitIsActive(split)) |
1492 | + split->sp_flags &= ~SPLIT_ACTIVE; | |
12e82c05 | 1493 | + |
1494 | + return 0; | |
1495 | +} | |
1496 | + | |
1497 | +/** Send the full list of split entries to \a cptr. | |
1498 | + * @param[in] cptr Local server to send split entries to. | |
1499 | + */ | |
1500 | +void | |
1501 | +split_burst(struct Client *cptr) | |
1502 | +{ | |
1503 | + struct Split *split; | |
1504 | + struct Split *ssplit; | |
1505 | + | |
1506 | + assert(NULL != cptr); | |
1507 | + | |
1508 | + for (split = GlobalSplitList; split; split = ssplit) { /* go through splits */ | |
1509 | + ssplit = split->sp_next; | |
1510 | + | |
1511 | + /* expire any that need expiring */ | |
1512 | + if (split_expire(split)) | |
1513 | + split_free(split); | |
1514 | + /* if we have an entry for cptr, dont send it - but do not free here yet | |
1515 | + * free it at end of burst, to get the correct count for SPLITs removed. | |
1516 | + */ | |
1517 | + else if (ircd_strcmp(split->sp_server, cli_name(cptr)) == 0) | |
1518 | + continue; | |
1519 | + else | |
1520 | + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s", | |
1521 | + SplitIsActive(split) ? '+' : '-', split->sp_server, | |
1522 | + split->sp_creation, split->sp_expire, | |
1523 | + split->sp_lastmod, split->sp_lifetime, | |
1524 | + split->sp_reason); | |
1525 | + } | |
1526 | +} | |
1527 | + | |
1528 | +/** Forward a split to another server. | |
1529 | + * @param[in] cptr Server to send split entries to. | |
1530 | + * @param[in] split Split to forward. | |
1531 | + * @return Zero. | |
1532 | + */ | |
1533 | +int | |
1534 | +split_resend(struct Client *cptr, struct Split *split) | |
1535 | +{ | |
1536 | + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s", | |
1537 | + SplitIsActive(split) ? '+' : '-', split->sp_server, | |
1538 | + split->sp_creation, split->sp_expire, | |
1539 | + split->sp_lastmod, split->sp_lifetime, | |
1540 | + split->sp_reason); | |
1541 | + | |
1542 | + return 0; | |
1543 | +} | |
1544 | + | |
1545 | +/** Send a split entry (or a list of split entries) to a server. | |
1546 | + * @param[in] sptr Client searching for split entries. | |
1547 | + * @param[in] server Name of split entry to search for (if NULL, list all). | |
1548 | + * @return Zero. | |
1549 | + */ | |
1550 | +int | |
1551 | +split_list(struct Client *sptr, char *server) | |
1552 | +{ | |
1553 | + struct Split *split; | |
0c63b280 | 1554 | + int count = 0; |
12e82c05 | 1555 | + |
1556 | + assert(NULL != sptr); | |
1557 | + | |
0c63b280 | 1558 | + /* go through SPLITs */ |
1559 | + for (split = GlobalSplitList; split; split = split->sp_next) { | |
1560 | + if (split_expire(split)) { /* expire any that need expiring */ | |
1561 | + split_free(split); | |
1562 | + continue; | |
1563 | + } | |
1564 | + if (server && match(server, split->sp_server)) | |
1565 | + continue; | |
1566 | + count++; | |
12e82c05 | 1567 | + send_reply(sptr, RPL_SPLITLIST, split->sp_server, |
0c63b280 | 1568 | + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime, |
12e82c05 | 1569 | + SplitIsActive(split) ? '+' : '-', split->sp_reason); |
12e82c05 | 1570 | + } |
1571 | + | |
0c63b280 | 1572 | + /* server given and nothing found */ |
1573 | + if (server && !count) | |
1574 | + return send_reply(sptr, ERR_NOSUCHSPLIT, server); | |
1575 | + | |
12e82c05 | 1576 | + /* end of splitlist information */ |
1577 | + return send_reply(sptr, RPL_ENDOFSPLITLIST); | |
1578 | +} | |
1579 | + | |
1580 | + | |
0c63b280 | 1581 | +/** Mark SPLIT for new server with SPLIT_BURST |
1582 | + * @param[in] acptr Server introduced to the network | |
1583 | + */ | |
1584 | +void | |
1585 | +split_newserver(struct Client *acptr) | |
1586 | +{ | |
1587 | + struct Split *split; | |
1588 | + | |
1589 | + assert(NULL != acptr); | |
1590 | + | |
1591 | + Debug((DEBUG_DEBUG, "split_newserver(\"%s\")", cli_name(acptr))); | |
1592 | + | |
1593 | + /* mark the SPLIT with SPLIT_BURST | |
1594 | + * so we know this SPLIT is marked for removal already | |
1595 | + * but not remove it just yet to get the correct count | |
1596 | + * of SPLITs removed at the end of burst. | |
1597 | + * also we need the SPLIT in case the net breaks again | |
1598 | + * before end of burst? | |
1599 | + */ | |
1600 | + if ((split = split_find(cli_name(acptr)))) | |
1601 | + split->sp_flags |= SPLIT_BURST; | |
1602 | + return; | |
1603 | +} | |
1604 | + | |
1605 | + | |
12e82c05 | 1606 | +/** Auto destroy SPLITs for servers gained in a netmerge |
0c63b280 | 1607 | + * @param[in] sptr Server that has linked to the network |
12e82c05 | 1608 | + * @return Number of destroyed SPLITs |
1609 | + */ | |
1610 | +int | |
0c63b280 | 1611 | +split_netmerge(struct Client *sptr) |
12e82c05 | 1612 | +{ |
1613 | + struct DLink *lp; | |
1614 | + struct Split *split; | |
1615 | + int count = 0; | |
1616 | + | |
0c63b280 | 1617 | + assert(NULL != sptr); |
12e82c05 | 1618 | + |
0c63b280 | 1619 | + Debug((DEBUG_DEBUG, "split_netmerge(\"%s\")", cli_name(sptr))); |
12e82c05 | 1620 | + |
1621 | + /* find the SPLIT for this server */ | |
0c63b280 | 1622 | + if ((split = split_find(cli_name(sptr)))) { |
12e82c05 | 1623 | + split_free(split); |
1624 | + count++; | |
1625 | + } | |
1626 | + | |
1627 | + /* go over its downlinks */ | |
0c63b280 | 1628 | + for (lp = cli_serv(sptr)->down; lp; lp = lp->next) |
1629 | + count += split_netmerge(lp->value.cptr); | |
12e82c05 | 1630 | + return count; |
1631 | +} | |
1632 | + | |
1633 | + | |
1634 | +/** Auto create SPLITs for servers lost in a netbreak | |
0c63b280 | 1635 | + * @param[in] victim Server that lost link to network |
12e82c05 | 1636 | + * @param[in] reason Reason to add to SPLITs |
1637 | + * @return Number of created SPLITs | |
1638 | + */ | |
1639 | +int | |
0c63b280 | 1640 | +split_netbreak(struct Client *victim, const char *reason) |
12e82c05 | 1641 | +{ |
1642 | + struct DLink *lp; | |
1643 | + struct Split *split; | |
1644 | + int count = 0; | |
0c63b280 | 1645 | + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE), |
1646 | + lastmod = TStime(), lifetime = expire; | |
12e82c05 | 1647 | + unsigned int flags = SPLIT_ACTIVE; |
1648 | + | |
0c63b280 | 1649 | + assert(NULL != victim); |
12e82c05 | 1650 | + |
0c63b280 | 1651 | + Debug((DEBUG_DEBUG, "split_netbreak(\"%s\", \"%s\")", cli_name(victim), reason)); |
12e82c05 | 1652 | + |
65b70298 | 1653 | + /* bad auto expire value */ |
1654 | + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0) | |
1655 | + return 0; | |
1656 | + | |
0c63b280 | 1657 | + /* TODO: what if we do have a SPLIT for this server? |
1658 | + * we remove splits in end of burst | |
1659 | + * and if the netbreaks again before that | |
1660 | + * free the SPLIT and create a new one? | |
1661 | + * or simply update lastmod/lifetime/reason but leave the status? | |
1662 | + */ | |
12e82c05 | 1663 | + /* find the SPLIT for this server */ |
0c63b280 | 1664 | + if (!(split = split_find(cli_name(victim)))) { |
1665 | + split_make(cli_name(victim), reason, creation, expire, lastmod, lifetime, flags); | |
12e82c05 | 1666 | + count++; |
0c63b280 | 1667 | + } else |
1668 | + split->sp_flags &= SPLIT_BURST; /* clear the burst flag for it */ | |
12e82c05 | 1669 | + |
1670 | + /* go over its downlinks */ | |
0c63b280 | 1671 | + for (lp = cli_serv(victim)->down; lp; lp = lp->next) |
1672 | + count += split_netbreak(lp->value.cptr, reason); | |
12e82c05 | 1673 | + return count; |
1674 | +} | |
1675 | + | |
1676 | + | |
1677 | +/** Auto create SPLITs for servers we have a Connect Block for | |
1678 | + * | |
1679 | + */ | |
1680 | +void | |
1681 | +split_conf() | |
1682 | +{ | |
1683 | + struct ConfItem *conf; | |
1684 | + struct Client *server; | |
1685 | + struct Split *split; | |
1686 | + struct Split *asplit; | |
0c63b280 | 1687 | + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE), |
1688 | + lastmod = TStime(), lifetime = expire; | |
12e82c05 | 1689 | + unsigned int flags = SPLIT_ACTIVE; |
1690 | + char reason[BUFSIZE]; | |
1691 | + | |
1692 | + Debug((DEBUG_DEBUG, "split_conf()")); | |
1693 | + | |
1694 | + /* we are not set to generate SPLITs */ | |
1695 | + if (!feature_bool(FEAT_SPLIT)) | |
1696 | + return; | |
1697 | + | |
0c63b280 | 1698 | + /* TODO: log this problem? */ |
65b70298 | 1699 | + /* bad auto expire value */ |
1700 | + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0) | |
1701 | + return; | |
1702 | + | |
12e82c05 | 1703 | + ircd_snprintf(0, reason, sizeof(reason), |
0c63b280 | 1704 | + "Generated upon loading conf file on %C", &me); |
12e82c05 | 1705 | + |
1706 | + /* go over the conf contents */ | |
1707 | + for (conf = GlobalConfList; conf; conf = conf->next) { | |
1708 | + /* not a Connect Block */ | |
1709 | + if (CONF_SERVER != conf->status) | |
1710 | + continue; | |
1711 | + /* server is linked */ | |
1712 | + if (server = FindServer(conf->name)) | |
1713 | + continue; | |
1714 | + /* we have a SPLIT for this server already */ | |
1715 | + if (split = split_find(conf->name)) | |
1716 | + continue; | |
65b70298 | 1717 | + /* TODO: use SNO_OLDSNO here? |
1718 | + * just like nickcollisions on local users go there? | |
1719 | + * or at least change the source / message format? | |
1720 | + * /REHASH goes to SNO_OLDSNO? so this too? | |
1721 | + * if oper did rehash, add his name here? | |
1722 | + */ | |
12e82c05 | 1723 | + /* inform ops and log it */ |
1724 | + sendto_opmask_butone(0, SNO_NETWORK, "%C adding SPLIT for %s, expiring at %Tu: %s", | |
1725 | + &me, conf->name, expire, reason); | |
1726 | + | |
0c63b280 | 1727 | + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE, |
12e82c05 | 1728 | + "%C adding SPLIT for %s, expiring at %Tu: %s", |
1729 | + &me, conf->name, expire, reason); | |
1730 | + | |
1731 | + /* make the split entry */ | |
1732 | + asplit = split_make(conf->name, reason, creation, expire, lastmod, lifetime, flags); | |
1733 | + | |
1734 | + assert(asplit); | |
1735 | + | |
1736 | + /* and propagate it */ | |
1737 | + split_propagate(&me, &me, asplit, NULL); | |
1738 | + } | |
1739 | +} | |
1740 | + | |
1741 | + | |
1742 | +/** Statistics callback to list SPLITs. | |
1743 | + * @param[in] sptr Client requesting statistics. | |
1744 | + * @param[in] sd Stats descriptor for request (ignored). | |
1745 | + * @param[in] param Extra parameter from user (ignored). | |
1746 | + */ | |
1747 | +void | |
1748 | +split_stats(struct Client *sptr, const struct StatDesc *sd, | |
1749 | + char *param) | |
1750 | +{ | |
1751 | + struct Split *split; | |
12e82c05 | 1752 | + |
65b70298 | 1753 | + /* send header so the client knows what we are showing */ |
1754 | + send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER, | |
1755 | + "S Server Creation Expire Lastmod Lifetime Status :Reason"); | |
1756 | + | |
0c63b280 | 1757 | + for (split = GlobalSplitList; split; split = split->sp_next) { |
1758 | + if (param && match(param, split->sp_server)) | |
1759 | + continue; | |
12e82c05 | 1760 | + send_reply(sptr, RPL_STATSSPLIT, split->sp_server, |
1761 | + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime, | |
1762 | + SplitIsActive(split) ? '+' : '-', split->sp_reason); | |
0c63b280 | 1763 | + } |
12e82c05 | 1764 | +} |
1765 | + | |
1766 | + | |
1767 | +/** Count split entries and memory used by them. | |
1768 | + * @param[out] sp_size Receives total number of bytes allocated for split entries. | |
1769 | + * @return Number of split entries currently allocated. | |
1770 | + */ | |
1771 | +int | |
1772 | +split_memory_count(size_t *sp_size) | |
1773 | +{ | |
1774 | + struct Split *split; | |
1775 | + unsigned int sp = 0; | |
1776 | + | |
0c63b280 | 1777 | + for (split = GlobalSplitList; split; split = split->sp_next) { |
12e82c05 | 1778 | + sp++; |
1779 | + *sp_size += sizeof(struct Split); | |
1780 | + *sp_size += split->sp_server ? (strlen(split->sp_server) + 1) : 0; | |
1781 | + *sp_size += split->sp_reason ? (strlen(split->sp_reason) + 1) : 0; | |
1782 | + } | |
1783 | + return sp; | |
1784 | +} | |
1785 | + |