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