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