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