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