2 Add split functionality into ircd
4 Add /stats S/split (make /STATS s/S case sensitive, s spoofhosts)
6 Add split.c split.h m_split.c
8 NOTE: feature SPLIT is default enabled as that is just easier when working on this patch.
10 diff -r bcffa56c93d4 doc/api/log.txt
11 --- a/doc/api/log.txt Fri Jan 23 18:45:25 2009 +0100
12 +++ b/doc/api/log.txt Fri Jan 23 23:04:58 2009 +0100
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,
22 diff -r bcffa56c93d4 include/handlers.h
23 --- a/include/handlers.h Fri Jan 23 18:45:25 2009 +0100
24 +++ b/include/handlers.h Fri Jan 23 23:04:58 2009 +0100
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*[]);
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*[]);
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*[]);
49 diff -r bcffa56c93d4 include/ircd_features.h
50 --- a/include/ircd_features.h Fri Jan 23 18:45:25 2009 +0100
51 +++ b/include/ircd_features.h Fri Jan 23 23:04:58 2009 +0100
58 + FEAT_SPLIT_AUTO_EXPIRE,
60 /* HEAD_IN_SAND Features */
62 FEAT_HIS_SNOTICES_OPER_ONLY,
71 diff -r bcffa56c93d4 include/ircd_log.h
72 --- a/include/ircd_log.h Fri Jan 23 18:45:25 2009 +0100
73 +++ b/include/ircd_log.h Fri Jan 23 23:04:58 2009 +0100
75 LS_OPERMODE, /**< Uses of OPMODE, CLEARMODE< etc. */
76 LS_GLINE, /**< Adding, (de-)activating or removing GLINEs. */
77 LS_JUPE, /**< Adding, (de-)activating or removing JUPEs. */
78 + LS_SPLIT, /**< Adding, (de-)activating or removing SPLITs. */
79 LS_WHO, /**< Use of extended WHO privileges. */
80 LS_NETWORK, /**< New server connections. */
81 LS_OPERKILL, /**< Kills by IRC operators. */
82 diff -r bcffa56c93d4 include/msg.h
83 --- a/include/msg.h Fri Jan 23 18:45:25 2009 +0100
84 +++ b/include/msg.h Fri Jan 23 23:04:58 2009 +0100
87 #define CMD_JUPE MSG_JUPE, TOK_JUPE
89 +#define MSG_SPLIT "SPLIT" /* SPLIT */
90 +#define TOK_SPLIT "SP"
91 +#define CMD_SPLIT MSG_SPLIT, TOK_SPLIT
93 #define MSG_OPMODE "OPMODE" /* OPMO */
94 #define TOK_OPMODE "OM"
95 #define CMD_OPMODE MSG_OPMODE, TOK_OPMODE
96 diff -r bcffa56c93d4 include/numeric.h
97 --- a/include/numeric.h Fri Jan 23 18:45:25 2009 +0100
98 +++ b/include/numeric.h Fri Jan 23 23:04:58 2009 +0100
100 RPL_STATSVLINE 227 unreal */
101 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
102 #define RPL_STATSQLINE 228 /* Undernet extension */
103 +#define RPL_STATSSPLIT 229 /* QuakeNet extension */
104 #define RPL_STATSHEADER 230 /* QuakeNet extension */
106 /* RPL_SERVICEINFO 231 unused */
108 #define RPL_STATSDLINE 275 /* Undernet extension */
109 #define RPL_STATSRLINE 276 /* Undernet extension */
111 +#define RPL_SPLITLIST 278 /* QuakeNet extension */
112 +#define RPL_ENDOFSPLITLIST 279 /* QuakeNet extension */
113 #define RPL_GLIST 280 /* Undernet extension */
114 #define RPL_ENDOFGLIST 281 /* Undernet extension */
115 #define RPL_JUPELIST 282 /* Undernet extension - jupe -Kev */
117 /* ERR_GHOSTEDCLIENT 503 efnet */
118 /* ERR_VWORLDWARN 503 austnet */
120 +#define ERR_NOSUCHSPLIT 510 /* QuakeNet extension */
121 #define ERR_SILELISTFULL 511 /* Undernet extension */
122 /* ERR_NOTIFYFULL 512 aircd */
123 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
124 diff -r bcffa56c93d4 include/split.h
125 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
126 +++ b/include/split.h Fri Jan 23 23:04:58 2009 +0100
128 +#ifndef INCLUDED_split_h
129 +#define INCLUDED_split_h
131 + * IRC - Internet Relay Chat, include/split.h
132 + * Copyright (C) 1990 Jarkko Oikarinen and
133 + * University of Oulu, Computing Center
134 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
136 + * This program is free software; you can redistribute it and/or modify
137 + * it under the terms of the GNU General Public License as published by
138 + * the Free Software Foundation; either version 2, or (at your option)
139 + * any later version.
141 + * This program is distributed in the hope that it will be useful,
142 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
143 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
144 + * GNU General Public License for more details.
146 + * You should have received a copy of the GNU General Public License
147 + * along with this program; if not, write to the Free Software
148 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
151 + * @brief Interface and declarations for split server handling.
152 + * @version $Id: jupe.h 1208 2004-10-03 14:12:35Z entrope $
154 +#ifndef INCLUDED_sys_types_h
155 +#include <sys/types.h>
156 +#define INCLUDED_sys_types_h
163 +#define SPLIT_MAX_EXPIRE 2419200 /**< Maximum split expiration time (4 weeks). */
165 +/* Describes a SPLIT server entry. */
167 + struct Split* sp_next; /**< Pointer to next Split. */
168 + struct Split** sp_prev_p; /**< Pointer to previous next pointer. */
169 + char* sp_server; /**< Name of server. */
170 + char* sp_reason; /**< Reason. */
171 + time_t sp_creation; /**< TODO: Creation time. What are we using this for then? */
172 + time_t sp_expire; /**< Expiration time. */
173 + time_t sp_lastmod; /**< Last modification time. */
174 + time_t sp_lifetime; /**< Life time. */
175 + unsigned int sp_flags; /**< Status flags. */
178 +/** Split state flags. */
179 +#define SPLIT_ACTIVE 0x01 /**< Split is active. */
180 +#define SPLIT_REMOVING 0x02 /**< Split is being force removed (instead of deactivated). */
181 +#define SPLIT_BURST 0x04 /**< Split is for a server that is in progress of linking,
182 + and will be destroyed at the end of burst */
184 +/* Actions to perform on a SPLIT. */
186 + SPLIT_ACTIVATE, /**< SPLIT should be activated. */
187 + SPLIT_DEACTIVATE, /**< SPLIT should be deactivated. */
188 + SPLIT_MODIFY, /**< SPLIT should be modified. */
189 + SPLIT_REMOVE /**< SPLIT should be removed. */
192 +/* Split update flags. */
193 +#define SPLIT_EXPIRE 0x02 /**< Expiration time update. */
194 +#define SPLIT_LIFETIME 0x04 /**< Record lifetime update. */
195 +#define SPLIT_REASON 0x08 /**< Reason update. */
196 +#define SPLIT_CREATION 0x10 /**< TODO: Creation time update - unused. */
197 +#define SPLIT_MODIFY 0x20 /**< No state change. */
199 +/* mask for Split update flags. */
200 +#define SPLIT_UPDATE (SPLIT_EXPIRE | SPLIT_LIFETIME | SPLIT_REASON)
202 +/* test whether a split entry is active. */
203 +#define SplitIsActive(s) ((s)->sp_flags & SPLIT_ACTIVE)
204 +/* test whether a split entry is marked for forced removal. */
205 +#define SplitIsRemoving(s) ((s)->sp_flags & SPLIT_REMOVING)
206 +/* test whether a split entry is part of a netmerge. */
207 +#define SplitIsBurst(s) ((s)->sp_flags & SPLIT_BURST)
209 +extern int split_add(struct Client *cptr, struct Client *sptr,
210 + char *server, const char *reason,
211 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
212 + unsigned int flags);
213 +extern int split_modify(struct Client *cptr, struct Client *sptr,
214 + struct Split *split, enum SplitAction action, const char *reason,
215 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
216 + unsigned int flags);
217 +extern int split_remove(struct Client *cptr, struct Client *sptr,
218 + struct Split *split, const char *reason);
220 +extern struct Split* split_find(char *server);
221 +extern void split_free(struct Split *split);
222 +extern int split_expire(struct Split* split);
223 +extern void split_burst(struct Client *cptr);
224 +extern int split_resend(struct Client *cptr, struct Split *split);
225 +extern int split_list(struct Client *sptr, char *server);
226 +extern void split_newserver(struct Client *acptr);
227 +extern int split_netmerge(struct Client *sptr);
228 +extern int split_netbreak(struct Client *victim, const char *reason);
229 +extern void split_conf();
230 +extern void split_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
231 +extern int split_memory_count(size_t *sp_size);
233 +#endif /* INCLUDED_split_h */
234 diff -r bcffa56c93d4 ircd/Makefile.in
235 --- a/ircd/Makefile.in Fri Jan 23 18:45:25 2009 +0100
236 +++ b/ircd/Makefile.in Fri Jan 23 23:04:58 2009 +0100
253 @@ -1052,6 +1054,15 @@
254 ../include/ircd_chattr.h ../include/list.h ../include/msg.h \
255 ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
256 ../include/send.h ../include/struct.h
257 +m_split.o: m_split.c ../config.h ../include/client.h ../include/ircd_defs.h \
258 + ../include/dbuf.h ../include/msgq.h ../include/ircd_events.h \
259 + ../config.h ../include/ircd_handler.h ../include/res.h \
260 + ../include/capab.h ../include/split.h ../include/hash.h \
261 + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \
262 + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \
263 + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
264 + ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \
265 + ../include/client.h ../include/s_misc.h ../include/send.h
266 m_squit.o: m_squit.c ../config.h ../include/client.h \
267 ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \
268 ../include/ircd_events.h ../config.h ../include/ircd_handler.h \
269 @@ -1325,6 +1336,7 @@
270 ../include/msgq.h ../include/numeric.h ../include/numnicks.h \
271 ../include/res.h ../include/s_bsd.h ../include/s_conf.h \
272 ../include/s_user.h ../include/s_stats.h ../include/send.h \
273 + ../include/split.h \
274 ../include/struct.h ../include/sys.h ../include/whowas.h
275 s_err.o: s_err.c ../config.h ../include/numeric.h ../include/ircd_log.h \
276 ../include/s_debug.h ../config.h ../include/ircd_defs.h
277 @@ -1410,6 +1422,16 @@
278 ../include/msg.h ../include/numnicks.h ../include/parse.h \
279 ../include/s_bsd.h ../include/s_debug.h ../include/s_misc.h \
280 ../include/s_user.h ../include/struct.h ../include/sys.h
281 +split.o: split.c ../config.h ../include/split.h ../include/client.h \
282 + ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \
283 + ../include/ircd_events.h ../config.h ../include/ircd_handler.h \
284 + ../include/res.h ../include/capab.h ../include/hash.h ../include/ircd.h \
285 + ../include/struct.h ../include/ircd_alloc.h ../include/ircd_features.h \
286 + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \
287 + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
288 + ../include/numeric.h ../include/numnicks.h ../include/s_bsd.h \
289 + ../include/s_misc.h ../include/send.h ../include/struct.h \
291 uping.o: uping.c ../config.h ../include/uping.h ../include/ircd_defs.h \
292 ../include/ircd_events.h ../config.h ../include/res.h \
293 ../include/client.h ../include/dbuf.h ../include/msgq.h \
294 diff -r bcffa56c93d4 ircd/ircd.c
295 --- a/ircd/ircd.c Fri Jan 23 18:45:25 2009 +0100
296 +++ b/ircd/ircd.c Fri Jan 23 23:04:58 2009 +0100
304 #include "userload.h"
306 Debug((DEBUG_NOTICE, "Server ready..."));
307 log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");
309 + /* create SPLITs */
315 diff -r bcffa56c93d4 ircd/ircd_features.c
316 --- a/ircd/ircd_features.c Fri Jan 23 18:45:25 2009 +0100
317 +++ b/ircd/ircd_features.c Fri Jan 23 23:04:58 2009 +0100
319 F_B(SETHOST_USER, 0, 0, 0),
320 F_B(SETHOST_AUTO, 0, 0, 0),
323 + F_B(SPLIT, 0, 1, 0),
324 + F_I(SPLIT_AUTO_EXPIRE, 0, 604800, 0),
326 /* HEAD_IN_SAND Features */
327 F_B(HIS_SNOTICES, 0, 1, 0),
328 F_B(HIS_SNOTICES_OPER_ONLY, 0, 1, 0),
330 F_B(HIS_STATS_q, 0, 1, 0),
331 F_B(HIS_STATS_R, 0, 1, 0),
332 F_B(HIS_STATS_r, 0, 1, 0),
333 + F_B(HIS_STATS_S, 0, 1, 0),
334 F_B(HIS_STATS_s, 0, 1, 0),
335 F_B(HIS_STATS_t, 0, 1, 0),
336 F_B(HIS_STATS_T, 0, 1, 0),
337 diff -r bcffa56c93d4 ircd/ircd_log.c
338 --- a/ircd/ircd_log.c Fri Jan 23 18:45:25 2009 +0100
339 +++ b/ircd/ircd_log.c Fri Jan 23 23:04:58 2009 +0100
341 S(OPERMODE, -1, SNO_HACK4),
342 S(GLINE, -1, SNO_GLINE),
343 S(JUPE, -1, SNO_NETWORK),
344 + S(SPLIT, -1, SNO_NETWORK),
346 S(NETWORK, -1, SNO_NETWORK),
348 diff -r bcffa56c93d4 ircd/m_endburst.c
349 --- a/ircd/m_endburst.c Fri Jan 23 18:45:25 2009 +0100
350 +++ b/ircd/m_endburst.c Fri Jan 23 23:04:58 2009 +0100
355 +#include "ircd_features.h"
356 #include "ircd_log.h"
357 #include "ircd_reply.h"
358 #include "ircd_string.h"
361 #include "numnicks.h"
365 /* #include <assert.h> -- Now using assert in ircd_log.h */
368 int ms_end_of_burst(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
370 struct Channel *chan, *next_chan;
376 dump_map(sptr, "*", 0, report_new_links, 0);
377 sendto_opmask_butone(0, SNO_NETWORK, "Completed net.burst from %C.",
379 + /* cleanup SPLITs, but only bother ops when FEAT_SPLIT is enabled. */
380 + split = split_netmerge(sptr);
381 + if (feature_bool(FEAT_SPLIT))
382 + sendto_opmask_butone(0, SNO_NETWORK, "Removed %d SPLIT entries.", split);
384 sendcmdto_one(&me, CMD_END_OF_BURST_ACK, sptr, "");
386 diff -r bcffa56c93d4 ircd/m_reburst.c
387 --- a/ircd/m_reburst.c Fri Jan 23 18:45:25 2009 +0100
388 +++ b/ircd/m_reburst.c Fri Jan 23 23:04:58 2009 +0100
390 #include "ircd_snprintf.h"
395 /* #include <assert.h> -- Now using assert in ircd_log.h */
408 diff -r bcffa56c93d4 ircd/m_server.c
409 --- a/ircd/m_server.c Fri Jan 23 18:45:25 2009 +0100
410 +++ b/ircd/m_server.c Fri Jan 23 23:04:58 2009 +0100
416 #include "userload.h"
418 /* #include <assert.h> -- Now using assert in ircd_log.h */
420 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s",
421 cli_name(sptr), cli_name(acptr));
423 + /* new server - mark SPLIT for this server */
424 + split_newserver(acptr);
427 * Old sendto_serv_but_one() call removed because we now need to send
428 * different names to different servers (domain name matching).
429 diff -r bcffa56c93d4 ircd/m_split.c
430 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
431 +++ b/ircd/m_split.c Fri Jan 23 23:04:58 2009 +0100
434 + * IRC - Internet Relay Chat, ircd/m_split.c
435 + * Copyright (C) 1990 Jarkko Oikarinen and
436 + * University of Oulu, Computing Center
437 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
439 + * See file AUTHORS in IRC package for additional names of
442 + * This program is free software; you can redistribute it and/or modify
443 + * it under the terms of the GNU General Public License as published by
444 + * the Free Software Foundation; either version 1, or (at your option)
445 + * any later version.
447 + * This program is distributed in the hope that it will be useful,
448 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
449 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
450 + * GNU General Public License for more details.
452 + * You should have received a copy of the GNU General Public License
453 + * along with this program; if not, write to the Free Software
454 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
456 + * $Id: m_split.c 1737 2006-12-19 05:20:48Z entrope $
460 + * m_functions execute protocol messages on this server:
462 + * cptr is always NON-NULL, pointing to a *LOCAL* client
463 + * structure (with an open socket connected!). This
464 + * identifies the physical socket where the message
465 + * originated (or which caused the m_function to be
466 + * executed--some m_functions may call others...).
468 + * sptr is the source of the message, defined by the
469 + * prefix part of the message if present. If not
470 + * or prefix not found, then sptr==cptr.
472 + * (!IsServer(cptr)) => (cptr == sptr), because
473 + * prefixes are taken *only* from servers...
476 + * (sptr == cptr) => the message didn't
479 + * (sptr != cptr && IsServer(sptr) means
480 + * the prefix specified servername. (?)
482 + * (sptr != cptr && !IsServer(sptr) means
483 + * that message originated from a remote
484 + * user (not local).
488 + * (!IsServer(sptr)) means that, sptr can safely
489 + * taken as defining the target structure of the
490 + * message in this server.
492 + * *Always* true (if 'parse' and others are working correct):
494 + * 1) sptr->from == cptr (note: cptr->from == cptr)
496 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
497 + * *cannot* be a local connection, unless it's
498 + * actually cptr!). [MyConnect(x) should probably
499 + * be defined as (x == x->from) --msa ]
501 + * parc number of variable parameter strings (if zero,
502 + * parv is allowed to be NULL)
504 + * parv a NULL terminated list of parameter pointers,
506 + * parv[0], sender (prefix string), if not present
507 + * this points to an empty string.
508 + * parv[1]...parv[parc-1]
509 + * pointers to additional parameters
510 + * parv[parc] == NULL, *always*
512 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
513 + * non-NULL pointers.
521 +#include "ircd_features.h"
522 +#include "ircd_log.h"
523 +#include "ircd_reply.h"
524 +#include "ircd_string.h"
527 +#include "numeric.h"
528 +#include "numnicks.h"
530 +#include "s_debug.h"
534 +/* #include <assert.h> -- Now using assert in ircd_log.h */
539 + * ms_split - server message handler
541 + * parv[0] = Send prefix
542 + * parv[1] = (+|-)<server name>
543 + * parv[2] = Creation time
544 + * parv[3] = Expiration time
545 + * parv[4] = Last modification time
546 + * parv[5] = Life time
547 + * parv[6] = Comment
550 +int ms_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
552 + struct Client *acptr = 0;
553 + struct Split *asplit = 0;
554 + unsigned int flags = 0;
555 + enum SplitAction action = SPLIT_MODIFY;
556 + time_t creation = 0, expire = 0, lastmod = 0, lifetime = 0;
557 + char *server = parv[1], *tmp = 0;
558 + const char *reason = "No reason";
560 + /* TODO: perhaps make some fields optional? reason? */
562 + return need_more_params(sptr, "SPLIT");
564 + if (*server == '!') {
566 + action = SPLIT_REMOVE; /* removing entry */
569 + switch (*server) { /* handle + and - */
570 + case '+': /* activate the split entry */
571 + if (action != SPLIT_REMOVE)
572 + action = SPLIT_ACTIVATE;
576 + case '-': /* deactivate the entry */
577 + if (action != SPLIT_REMOVE)
578 + action = SPLIT_DEACTIVATE;
583 + /* Next, try to find the split entry... */
584 + asplit = split_find(server);
586 + /* We now have all the pieces to tell us what we've got; let's put
587 + * it all together and convert the rest of the arguments.
590 + /* can't modify a split entry that doesn't exist, so remap to activate */
591 + if (!asplit && action == SPLIT_MODIFY)
592 + action = SPLIT_ACTIVATE;
594 + /* OK, let's figure out what other parameters we may have... */
595 + creation = atoi(parv[2]);
596 + expire = atoi(parv[3]);
597 + lastmod = atoi(parv[4]);
598 + lifetime = atoi(parv[5]);
599 + reason = parv[parc - 1];
601 + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; "
602 + "server %s, action %s, creation %Tu, expire %Tu, "
603 + "lastmod %Tu, lifetime %Tu, reason: %s; split %s!", server,
604 + action == SPLIT_REMOVE ? "!-" :
605 + (action == SPLIT_ACTIVATE ? "+" :
606 + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")),
607 + creation, expire, lastmod, lifetime, reason,
608 + asplit ? "EXISTS" : "does not exist"));
610 + /* OK, at this point, we have converted all available parameters.
611 + * Let's actually do the action!
614 + if (action == SPLIT_REMOVE)
615 + return split_remove(cptr, sptr, asplit, reason);
616 + return split_modify(cptr, sptr, asplit, action, reason, creation, expire,
617 + lastmod, lifetime, flags);
620 + assert(action != SPLIT_MODIFY);
622 + return split_add(cptr, sptr, server, reason, creation, expire, lastmod, lifetime,
623 + flags | ((action == SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0));
628 + * mo_split - oper message handler
630 + * Local listing: 1 or 2 params
631 + * parv[0] = Send prefix
632 + * parv[1] = [Server or mask to match]
634 + * Add or modify entry: 3, 4 or 5 params (3 is * then)
635 + * parv[0] = Send prefix
636 + * parv[1] = [+|-]<server name>
637 + * parv[2] = [Expiration offset] (required for new)
638 + * parv[3] = [Comment] (required for new)
641 +int mo_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
643 + struct Client *acptr = 0;
644 + struct Split *asplit = 0;
645 + unsigned int flags = 0;
646 + enum SplitAction action = SPLIT_MODIFY;
647 + time_t expire = 0, lastmod = TStime(), creation = TStime();
648 + char *server = parv[1], *end;
649 + const char *reason = NULL;
652 + if (!HasPriv(sptr, PRIV_ROUTEINFO))
653 + return send_reply(sptr, ERR_NOPRIVILEGES);
655 + return split_list(sptr, 0);
658 + if (*server == '!') {
660 + action = SPLIT_REMOVE; /* force removal */
663 + switch (*server) { /* handle + and - */
664 + case '+': /* activate the split entry */
665 + if (action != SPLIT_REMOVE)
666 + action = SPLIT_ACTIVATE;
670 + case '-': /* deactivate the split entry */
671 + if (action != SPLIT_REMOVE)
672 + action = SPLIT_DEACTIVATE;
677 + /* OK, let's figure out the parameters... */
679 + /* no specific action */
681 + /* user wants a listing of a specific SPLIT */
683 + return split_list(sptr, server);
684 + expire = strtol(parv[2], &end, 10) + TStime(); /* and the expiration */
686 + return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE,
687 + "%s :Bad expire time", parv[2]);
689 + flags |= SPLIT_EXPIRE; /* remember that we got an expire time */
691 + if (parc > 3) { /* also got a reason... */
692 + reason = parv[parc - 1];
693 + flags |= SPLIT_REASON;
697 + case SPLIT_REMOVE: /* TODO: require reason for this, but not expire? */
699 + return need_more_params(sptr, "SPLIT");
700 + reason = parv[parc - 1];
701 + flags |= SPLIT_REASON;
704 + case SPLIT_ACTIVATE: /* TODO: require expire and reason when new */
706 + expire = strtol(parv[2], &end, 10) + TStime(); /* and the expiration */
708 + return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE,
709 + "%s :Bad expire time", parv[2]);
710 + flags |= SPLIT_EXPIRE; /* remember that we got an expire time */
713 + if (parc > 3) { /* also got a reason... */
714 + reason = parv[parc - 1];
715 + flags |= SPLIT_REASON;
719 + case SPLIT_DEACTIVATE: /* TODO: duplicate code? must be a cleaner way */
721 + expire = strtol(parv[2], &end, 10) + TStime(); /* and the expiration */
723 + return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE,
724 + "%s :Bad expire time", parv[2]);
725 + flags |= SPLIT_EXPIRE; /* remember that we got an expire time */
728 + if (parc > 3) { /* also got a reason... */
729 + reason = parv[parc - 1];
730 + flags |= SPLIT_REASON;
736 + /* check for permissions... */
737 + if (!feature_bool(FEAT_SPLIT)) /* TODO: but allow force removal? */
738 + return send_reply(sptr, ERR_DISABLED, "SPLIT");
739 + else if (!HasPriv(sptr, PRIV_SERVERINFO)) /* TODO: create PRIV_SPLIT - need help there */
740 + return send_reply(sptr, ERR_NOPRIVILEGES);
742 + /* Next, try to find the SPLIT... */
743 + asplit = split_find(server);
745 + /* We now have all the pieces to tell us what we've got; let's put
746 + * it all together and convert the rest of the arguments.
749 + /* SPLIT not found and thus we:
750 + * cannot remove SPLIT we do not have
751 + * cannot add new SPLIT without expire and reason
754 + ((action == SPLIT_REMOVE) ||
755 + (action == SPLIT_ACTIVATE && !reason) ||
756 + (action == SPLIT_DEACTIVATE && !reason) ||
757 + (action == SPLIT_MODIFY && !reason)))
758 + return send_reply(sptr, ERR_NOSUCHSPLIT, server);
760 + /* can't modify a split entry that doesn't exist, so remap to activate */
761 + if (!asplit && action == SPLIT_MODIFY)
762 + action = SPLIT_ACTIVATE;
764 + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; "
765 + "server %s, action %s, expire %Tu, "
766 + "reason: %s; split %s! (fields present: %s %s)", server,
767 + action == SPLIT_REMOVE ? "!-" :
768 + (action == SPLIT_ACTIVATE ? "+" :
769 + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")),
770 + expire, reason, asplit ? "EXISTS" : "does not exist",
771 + flags & SPLIT_EXPIRE ? "expire" : "",
772 + flags & SPLIT_REASON ? "reason" : ""));
774 + if (asplit) { /* modifying an existing SPLIT */
775 + if (action == SPLIT_REMOVE)
776 + return split_remove(cptr, sptr, asplit, reason);
777 + return split_modify(cptr, sptr, asplit, action, reason,
778 + asplit->sp_creation, expire, lastmod, asplit->sp_lifetime, flags);
781 + assert(action != SPLIT_MODIFY);
782 + assert(action != SPLIT_REMOVE);
784 + /* create a new SPLIT */
785 + return split_add(cptr, sptr, server, reason,
786 + creation, expire, lastmod, expire,
787 + flags | ((action == SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0));
791 + * m_split - user message handler
793 + * parv[0] = Send prefix
797 + * parv[1] = [<server name>]
800 +int m_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
803 + return split_list(sptr, 0);
805 + return split_list(sptr, parv[1]);
807 diff -r bcffa56c93d4 ircd/parse.c
808 --- a/ircd/parse.c Fri Jan 23 18:45:25 2009 +0100
809 +++ b/ircd/parse.c Fri Jan 23 23:04:58 2009 +0100
811 0, MAXPARA, MFLG_SLOW, 0, NULL,
812 /* UNREG, CLIENT, SERVER, OPER, SERVICE */
813 { m_unregistered, m_not_oper, ms_jupe, mo_jupe, m_ignore }
818 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
819 + /* UNREG, CLIENT, SERVER, OPER, SERVICE */
820 + { m_unregistered, m_not_oper, ms_split, mo_split, m_ignore }
824 diff -r bcffa56c93d4 ircd/s_conf.c
825 --- a/ircd/s_conf.c Fri Jan 23 18:45:25 2009 +0100
826 +++ b/ircd/s_conf.c Fri Jan 23 23:04:58 2009 +0100
835 @@ -1005,6 +1006,7 @@
838 attach_conf_uworld(&me);
843 diff -r bcffa56c93d4 ircd/s_debug.c
844 --- a/ircd/s_debug.c Fri Jan 23 18:45:25 2009 +0100
845 +++ b/ircd/s_debug.c Fri Jan 23 23:04:58 2009 +0100
855 aw = 0, /* aways set */
856 wwa = 0, /* whowas aways */
858 - ju = 0; /* jupes */
859 + ju = 0, /* jupes */
860 + sp = 0; /* split entries */
862 size_t chm = 0, /* memory used by channels */
863 chbm = 0, /* memory used by channel bans */
865 wwm = 0, /* whowas array memory used */
866 glm = 0, /* memory used by glines */
867 jum = 0, /* memory used by jupes */
868 + spm = 0, /* memory used by split entries */
869 com = 0, /* memory used by conf lines */
870 dbufs_allocated = 0, /* memory used by dbufs */
871 dbufs_used = 0, /* memory used by dbufs */
874 gl = gline_memory_count(&glm);
875 ju = jupe_memory_count(&jum);
876 + sp = split_memory_count(&spm);
877 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
878 - ":Glines %d(%zu) Jupes %d(%zu)", gl, glm, ju, jum);
879 + ":Glines %d(%zu) Jupes %d(%zu) Splits %d(%zu)", gl, glm, ju, jum, sp, spm);
881 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
882 ":Hash: client %d(%zu), chan is the same", HASHSIZE,
883 diff -r bcffa56c93d4 ircd/s_err.c
884 --- a/ircd/s_err.c Fri Jan 23 18:45:25 2009 +0100
885 +++ b/ircd/s_err.c Fri Jan 23 23:04:58 2009 +0100
888 { RPL_STATSQLINE, "Q %s :%s", "228" },
891 + { RPL_STATSSPLIT, "S %s %d %d %d %d %c :%s", "229" },
893 { RPL_STATSHEADER, 0, "230" },
900 + { RPL_SPLITLIST, "%s %Tu %Tu %Tu %Tu %c :%s", "278" },
903 + { RPL_ENDOFSPLITLIST, ":End of Split List", "279" },
905 { RPL_GLIST, "%s%s%s%s%s %Tu %Tu %Tu %s %s%s%c :%s", "280" },
907 @@ -1052,7 +1052,7 @@
912 + { ERR_NOSUCHSPLIT, "%s :No such split", "510" },
914 { ERR_SILELISTFULL, "%s :Your silence list is full", "511" },
916 diff -r bcffa56c93d4 ircd/s_misc.c
917 --- a/ircd/s_misc.c Fri Jan 23 18:45:25 2009 +0100
918 +++ b/ircd/s_misc.c Fri Jan 23 23:04:58 2009 +0100
930 char comment1[HOSTLEN + HOSTLEN + 2];
931 + char splitreason[BUFSIZE];
933 if (MyConnect(victim))
936 sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)",
937 cli_serv(victim)->up, victim, comment);
938 dump_map(victim, "*", 0, report_lost_links, 0);
939 + if (feature_bool(FEAT_SPLIT)) {
940 + /* TODO: remote & local SQUIT ? servername oper is on? */
941 + ircd_snprintf(0, splitreason, sizeof(splitreason),
942 + "Net break: %C %C (%s%s%s%s)", cli_serv(victim)->up, victim,
943 + IsUser(killer) ? "SQUIT by " : "", IsUser(killer) ? cli_name(killer) : "",
944 + IsUser(killer) ? ": " : "", comment);
945 + sendto_opmask_butone(0, SNO_NETWORK, "Created %d SPLIT entries.",
946 + split_netbreak(victim, splitreason));
951 diff -r bcffa56c93d4 ircd/s_serv.c
952 --- a/ircd/s_serv.c Fri Jan 23 18:45:25 2009 +0100
953 +++ b/ircd/s_serv.c Fri Jan 23 23:04:58 2009 +0100
961 #include "userload.h"
969 * Pass on my client information to the new server
970 diff -r bcffa56c93d4 ircd/s_stats.c
971 --- a/ircd/s_stats.c Fri Jan 23 18:45:25 2009 +0100
972 +++ b/ircd/s_stats.c Fri Jan 23 23:04:58 2009 +0100
979 #include "userload.h"
983 "System resource usage (Debug only)." },
985 - { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_s,
986 + { 'S', "splits", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_S,
988 + "Server SPLITs information."},
989 + { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_s,
991 "Spoofed hosts information." },
992 { 'T', "motds", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_T,
993 diff -r bcffa56c93d4 ircd/split.c
994 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
995 +++ b/ircd/split.c Fri Jan 23 23:04:58 2009 +0100
998 + * IRC - Internet Relay Chat, ircd/split.c
999 + * Copyright (C) 1990 Jarkko Oikarinen and
1000 + * University of Oulu, Finland
1001 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
1003 + * This program is free software; you can redistribute it and/or modify
1004 + * it under the terms of the GNU General Public License as published by
1005 + * the Free Software Foundation; either version 1, or (at your option)
1006 + * any later version.
1008 + * This program is distributed in the hope that it will be useful,
1009 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1010 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1011 + * GNU General Public License for more details.
1013 + * You should have received a copy of the GNU General Public License
1014 + * along with this program; if not, write to the Free Software
1015 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1018 + * @brief Implementation of split server handling functions.
1019 + * @version $Id: split.c 1633 2006-03-25 03:46:56Z entrope $
1021 +#include "config.h"
1024 +#include "client.h"
1027 +#include "ircd_alloc.h"
1028 +#include "ircd_features.h"
1029 +#include "ircd_log.h"
1030 +#include "ircd_reply.h"
1031 +#include "ircd_string.h"
1035 +#include "numeric.h"
1036 +#include "numnicks.h"
1037 +#include "s_conf.h"
1039 +#include "s_debug.h"
1040 +#include "s_misc.h"
1042 +#include "struct.h"
1043 +#include "sys.h" /* FALSE bleah */
1045 +/* #include <assert.h> -- Now using assert in ircd_log.h */
1046 +#include <string.h>
1048 +/** List of split entries. */
1049 +static struct Split *GlobalSplitList = 0;
1051 +/** Allocate a new Split entry with the given parameters.
1052 + * @param[in] server Server name for split entry.
1053 + * @param[in] reason Reason for the split entry.
1054 + * @param[in] creation Creation time for split entry.
1055 + * @param[in] expire Expiration time for split entry.
1056 + * @param[in] lastmod Last modification time for split entry.
1057 + * @param[in] lifetime Life time for split entry.
1058 + * @param[in] flags Flags to set for the split entry.
1060 +static struct Split *
1061 +split_make(char *server, const char *reason,
1062 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1063 + unsigned int flags)
1065 + struct Split *asplit;
1067 + asplit = (struct Split*) MyMalloc(sizeof(struct Split)); /* alloc memory */
1068 + assert(0 != asplit);
1070 + memset(asplit, 0, sizeof(*asplit));
1071 + /* TODO: some limit for servername length? HOSTLEN? */
1072 + DupString(asplit->sp_server, server); /* copy vital information */
1073 + /* TODO: some limit for reason length? QUITLEN TOPICLEN? */
1074 + /* TODO: prefix the reason here with the opername/ID? */
1075 + DupString(asplit->sp_reason, reason);
1076 + /* TODO: what we use creation for and do we need it? */
1077 + asplit->sp_creation = creation;
1078 + asplit->sp_expire = expire;
1079 + /* TODO: are we using nettime etc.? CurrentTime is used. */
1080 + /* TODO: TStime() is CurrentTime + TSoffset */
1081 + asplit->sp_lastmod = lastmod;
1082 + asplit->sp_lifetime = lifetime;
1083 + asplit->sp_flags = flags & SPLIT_ACTIVE; /* set split flags */
1085 + asplit->sp_next = GlobalSplitList; /* link it into the list */
1086 + asplit->sp_prev_p = &GlobalSplitList;
1087 + if (GlobalSplitList)
1088 + GlobalSplitList->sp_prev_p = &asplit->sp_next;
1089 + GlobalSplitList = asplit;
1094 +/** Forward a split entry to another server.
1095 + * @param[in] cptr Local client that sent us the split entry.
1096 + * @param[in] sptr Originator of the split entry.
1097 + * @param[in] split Split entry to forward.
1098 + * @param[in] reason Reason to send upstream (used by split_remove)
1101 +split_propagate(struct Client *cptr, struct Client *sptr,
1102 + struct Split *split, const char *reason)
1104 + sendcmdto_serv_butone(sptr, CMD_SPLIT, cptr, "%s%c%s %Tu %Tu %Tu %Tu :%s",
1105 + SplitIsRemoving(split) ? "!" : "",
1106 + SplitIsActive(split) && !SplitIsRemoving(split) ? '+' : '-', /* always !- not !+ */
1107 + split->sp_server, split->sp_creation, split->sp_expire,
1108 + split->sp_lastmod, split->sp_lifetime,
1109 + /* TODO: does reason ? reason : split->sp_reason work too? */
1110 + reason != NULL ? reason : split->sp_reason);
1113 +/** Add a new server split entry.
1114 + * @param[in] cptr Local client that sent us the split entry.
1115 + * @param[in] sptr Originator of the split entry.
1116 + * @param[in] server Server name to split entry.
1117 + * @param[in] reason Reason for the split entry.
1118 + * @param[in] expire Expiration timestamp.
1119 + * @param[in] lastmod Last modification timestamp.
1120 + * @param[in] flags Flags to set on the split entry.
1124 +split_add(struct Client *cptr, struct Client *sptr, char *server, const char *reason,
1125 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1126 + unsigned int flags)
1129 + struct Split *asplit;
1130 + struct Client *acptr;
1132 + assert(0 != server);
1133 + assert(0 != reason);
1134 + assert(NULL != cptr);
1135 + assert(NULL != sptr);
1137 + Debug((DEBUG_DEBUG, "split_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu, %Tu, "
1138 + "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), server, reason,
1139 + creation, expire, lastmod, lifetime, flags));
1141 + /* not adding SPLIT for server that is linked
1142 + * if sptr is my user throw error
1143 + * otherwise ignore - SERVER and SPLIT messages can cross,
1144 + * or a server is bursting and it will see our end and destroy the SPLITs
1146 + if ((acptr = FindServer(server))) {
1148 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1149 + "%C :Cannot add SPLIT %s - server is linked.", sptr, server);
1154 + * You cannot set a negative (or zero) duration, nor can you set an
1155 + * duration greater than SPLIT_MAX_EXPIRE.
1157 + if (expire - TStime() <= 0 || expire - TStime() > SPLIT_MAX_EXPIRE) {
1158 + if (!IsServer(cptr) && MyConnect(cptr))
1159 + return send_reply(cptr, ERR_BADEXPIRE, expire - TStime());
1160 + if (lifetime <= TStime()) /* no point going further */
1161 + /* CHECK: sptr may have the wrong idea about the nettime?
1162 + * or we could be wrong?
1163 + * perhaps raise some sort of warning to ops
1168 + /* TODO: add opername */
1169 + /* inform ops and log it */
1170 + sendto_opmask_butone(0, SNO_NETWORK, "%s adding%sSPLIT for %s, expiring at %Tu: %s",
1171 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1172 + cli_name(sptr) : cli_name((cli_user(sptr))->server),
1173 + !(flags & SPLIT_ACTIVE) ? " deactivated " : " ",
1174 + server, expire, reason);
1176 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1177 + "%#C adding%sSPLIT for %s, expiring at %Tu: %s",
1178 + sptr, !(flags & SPLIT_ACTIVE) ? " deactivated " : " ",
1179 + server, expire, reason);
1181 + /* make the split entry */
1182 + asplit = split_make(server, reason, creation, expire, lastmod, lifetime, flags);
1186 + /* and propagate it */
1187 + split_propagate(cptr, sptr, asplit, NULL);
1193 +/** Modify a split entry.
1194 + * @param[in] cptr Client that sent us the split modification.
1195 + * @param[in] sptr Client that originated the split modification.
1196 + * @param[in] split Split entry being modified.
1197 + * @param[in] action Resultant status of the G-line.
1198 + * @param[in] reason Reason.
1199 + * @param[in] expire Expiration time.
1200 + * @param[in] lastmod Last modification time.
1201 + * @param[in] lifetime Lifetime.
1202 + * @param[in] flags Bitwise combination of SPLIT_* flags.
1206 +split_modify(struct Client *cptr, struct Client *sptr, struct Split *split,
1207 + enum SplitAction action, const char *reason,
1208 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1209 + unsigned int flags)
1211 + struct Client* acptr;
1212 + char buf[BUFSIZE];
1215 + /* TODO: assert() on other inputs? */
1217 + assert(NULL != cptr);
1218 + assert(NULL != sptr);
1220 + Debug((DEBUG_DEBUG, "split_modify(\"%s\", \"%s\", \"%s\", \"%s\", %d, %Tu, %Tu, %Tu, "
1221 + "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), split->sp_server, reason, action,
1222 + creation, expire, lastmod, lifetime, flags));
1224 + /* not modifying SPLIT for server that is linked
1225 + * if sptr is my user throw error
1226 + * otherwise ignore - SERVER and SPLIT messages can cross.
1228 + * note: we cleanup SPLIT entries at end of burst,
1229 + * and not when a server is introduced.
1230 + * so between net junction and end of burst,
1231 + * we can get SPLITs for a linked server.
1232 + * also more than one server can be bursting at a time.
1234 + if ((acptr = FindServer(split->sp_server))) {
1236 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1237 + "%C :Cannot modify SPLIT %s - server is linked.", sptr, split->sp_server);
1238 + /* SPLIT is not for a server part of a netmerge */
1239 + if (!SplitIsBurst(split))
1240 + split_free(split); /* and free it */
1244 + /* First, let's check lastmod... */
1245 + if (split->sp_lastmod > lastmod) { /* we have a more recent version */
1246 + if (IsBurstOrBurstAck(cptr))
1247 + return 0; /* middle of a burst, it'll resync on its own */
1248 + return split_resend(cptr, split); /* resync the server */
1249 + } else if (split->sp_lastmod == lastmod)
1250 + return 0; /* we have that version of the split entry... */
1252 + /* All right, we know that there's a change of some sort. What is it? */
1253 + /* first, check out the expiration time... */
1254 + /* TODO: expire != 0 or NULL - check that we have something? */
1255 + if (expire != 0 && expire != split->sp_expire) {
1256 + if (expire - TStime() <= 0 || expire - TStime() > SPLIT_MAX_EXPIRE) {
1257 + if (!IsServer(sptr) && MyConnect(sptr)) /* bad expiration time */
1258 + return send_reply(sptr, ERR_BADEXPIRE, expire - TStime());
1260 + flags |= SPLIT_EXPIRE;
1262 + flags &= ~SPLIT_EXPIRE;
1264 + /* Next, check out lifetime */
1265 + if (!(flags & SPLIT_LIFETIME) || !lifetime)
1266 + lifetime = split->sp_lifetime; /* use Split lifetime */
1268 + lifetime = IRCD_MAX(lifetime, expire); /* set lifetime to the max */
1270 + /* now that we have the correct lifetime, check it */
1271 + if (lifetime - TStime() <= 0) /* no point in going further */
1274 + /* OK, let's see which is greater... */
1275 + if (lifetime > split->sp_lifetime)
1276 + flags |= SPLIT_LIFETIME; /* have to update lifetime */
1278 + flags &= ~SPLIT_LIFETIME; /* no change to lifetime */
1282 + /* Finally, let's see if the reason needs to be updated */
1283 + /* TODO: (reason) or use != NULL / 0 ? */
1284 + if ((flags & SPLIT_REASON) && reason &&
1285 + ircd_strcmp(split->sp_reason, reason) != 0)
1286 + flags &= ~SPLIT_REASON; /* no changes to the reason */
1288 + /* OK, now let's take a look at the action... */
1289 + if ((action == SPLIT_ACTIVATE && SplitIsActive(split)) ||
1290 + (action == SPLIT_DEACTIVATE && !SplitIsActive(split)) ||
1291 + /* can't activate an expired split entry */
1292 + (IRCD_MAX(split->sp_expire, expire) <= TStime()))
1293 + action = SPLIT_MODIFY; /* no activity state modifications */
1295 + Debug((DEBUG_DEBUG, "About to perform changes; flags 0x%04x, action %s",
1296 + flags, action == SPLIT_ACTIVATE ? "SPLIT_ACTIVATE" :
1297 + (action == SPLIT_DEACTIVATE ? "SPLIT_DEACTIVATE" :
1298 + (action == SPLIT_MODIFY ? "SPLIT_MODIFY" : "<UNKNOWN>"))));
1300 + /* If there are no changes to perform, do no changes */
1301 + if (!(flags & SPLIT_UPDATE) && action == SPLIT_MODIFY)
1304 + /* Start by updating lastmod, if indicated... */
1305 + split->sp_lastmod = lastmod;
1307 + /* Then move on to activity status changes... */
1309 + case SPLIT_ACTIVATE: /* activating split entry */
1310 + split->sp_flags |= SPLIT_ACTIVE; /* make it active... */
1311 + pos += ircd_snprintf(0, buf, sizeof(buf), " activating SPLIT");
1314 + case SPLIT_DEACTIVATE: /* deactivating split entry */
1315 + split->sp_flags &= ~SPLIT_ACTIVE; /* make it inactive... */
1316 + pos += ircd_snprintf(0, buf, sizeof(buf), " deactivating SPLIT");
1319 + case SPLIT_MODIFY: /* no change to activity status */
1323 + /* Handle expiration changes... */
1324 + if (flags & SPLIT_EXPIRE) {
1325 + split->sp_expire = expire; /* save new expiration time */
1326 + if (pos < BUFSIZE)
1327 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1328 + "%s%s changing expiration time to %Tu",
1330 + pos && !(flags & (SPLIT_LIFETIME | SPLIT_REASON)) ?
1331 + " and" : "", expire);
1334 + /* Next, handle lifetime changes... */
1335 + if (flags & SPLIT_LIFETIME) {
1336 + split->sp_lifetime = lifetime; /* save new lifetime */
1337 + if (pos < BUFSIZE)
1338 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1339 + "%s%s extending record lifetime to %Tu",
1340 + pos ? ";" : "", pos && !(flags & SPLIT_REASON) ?
1341 + " and" : "", lifetime);
1344 + /* Now, handle reason changes... */
1345 + if (flags & SPLIT_REASON) {
1346 + MyFree(split->sp_reason); /* release old reason */
1347 + DupString(split->sp_reason, reason); /* store new reason */
1348 + if (pos < BUFSIZE)
1349 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1350 + "%s%s changing reason to \"%s\"",
1351 + pos ? ";" : "", pos ? " and" : "", reason);
1354 + /* TODO: add opername */
1355 + /* All right, inform ops... */
1356 + sendto_opmask_butone(0, SNO_NETWORK, "%s modifying SPLIT for %s:%s",
1357 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1358 + cli_name(sptr) : cli_name((cli_user(sptr))->server),
1359 + split->sp_server, buf);
1361 + /* and log the change */
1362 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1363 + "%#C modifying SPLIT for %s:%s",
1364 + sptr, split->sp_server, buf);
1366 + /* and propagate it */
1367 + split_propagate(cptr, sptr, split, NULL);
1373 +/** Remove a split entry.
1374 + * @param[in] cptr Local client that sent us the split entry.
1375 + * @param[in] sptr Originator of the split entry.
1376 + * @param[in] split Split entry to remove.
1377 + * @param[in] reason Reason for removing this split entry.
1381 +split_remove(struct Client *cptr, struct Client *sptr, struct Split *split, const char *reason)
1383 + unsigned int saveflags = 0;
1385 + assert(0 != split);
1386 + assert(NULL != cptr);
1387 + assert(NULL != sptr);
1389 + Debug((DEBUG_DEBUG, "split_remove(\"%s\", \"%s\", \"%s\", \"%s\")",
1390 + cli_name(cptr), cli_name(sptr), split->sp_server, reason));
1392 + /* deactivate entry and mark it for removal (used in split_propagate) */
1393 + split->sp_flags |= SPLIT_REMOVING;
1394 + split->sp_flags &= ~SPLIT_ACTIVE;
1396 + /* TODO: add opername? */
1397 + /* inform ops and log it */
1398 + sendto_opmask_butone(0, SNO_NETWORK, "%s removing SPLIT for %s, expiring at %Tu: %s (%s)",
1399 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1400 + cli_name(sptr) : cli_name((cli_user(sptr))->server),
1401 + split->sp_server, split->sp_expire, split->sp_reason, reason);
1403 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1404 + "%#C removing SPLIT for %s, expiring at %Tu: %s (%s)",
1405 + sptr, split->sp_server, split->sp_expire, split->sp_reason, reason);
1407 + /* propagate it */
1408 + split_propagate(cptr, sptr, split, reason);
1411 + split_free(split);
1417 +/** Find a split entry by name.
1418 + * @param[in] server Split entry name to search for.
1419 + * @return Matching split entry (or NULL if none match).
1422 +split_find(char *server)
1424 + struct Split* split;
1425 + struct Split* ssplit;
1427 + for (split = GlobalSplitList; split; split = ssplit) { /* go through splits */
1428 + ssplit = split->sp_next;
1430 + if (split_expire(split)) /* expire any that need expiring */
1431 + split_free(split);
1432 + else if (0 == ircd_strcmp(server, split->sp_server)) /* found it yet? */
1435 + /* TODO: we return 0 not NULL? */
1439 +/** Unlink and free an unused split entry.
1440 + * @param[in] split Server split entry to free.
1443 +split_free(struct Split* split)
1445 + /* TODO: use 0 or NULL ? */
1446 + assert(0 != split);
1448 + *split->sp_prev_p = split->sp_next; /* squeeze this split entry out */
1449 + if (split->sp_next)
1450 + split->sp_next->sp_prev_p = split->sp_prev_p;
1452 + /* CHECK: the other fields in this struct are destroyed with MyFree() call? */
1453 + MyFree(split->sp_server); /* and free up the memory */
1454 + MyFree(split->sp_reason);
1459 +/** Check whether a split entry has past its life time.
1460 + * when entry is active and past expire time, but not life time, deactivate it
1461 + * @param[in] split Server split entry to check.
1462 + * @return 1 when entry can be free'd, 0 otherwise.
1465 +split_expire(struct Split* split)
1467 + assert(0 != split);
1469 + /* TODO: also check if the server in SPLIT entry is linked atm? */
1470 + /* past lifetime */
1471 + if (split->sp_lifetime <= TStime())
1474 + /* past expire time, deactivate entry if it is active */
1475 + if ((split->sp_expire <= TStime()) && SplitIsActive(split))
1476 + split->sp_flags &= ~SPLIT_ACTIVE;
1481 +/** Send the full list of split entries to \a cptr.
1482 + * @param[in] cptr Local server to send split entries to.
1485 +split_burst(struct Client *cptr)
1487 + struct Split *split;
1488 + struct Split *ssplit;
1490 + assert(NULL != cptr);
1492 + for (split = GlobalSplitList; split; split = ssplit) { /* go through splits */
1493 + ssplit = split->sp_next;
1495 + /* expire any that need expiring */
1496 + if (split_expire(split))
1497 + split_free(split);
1498 + /* if we have an entry for cptr, dont send it - but do not free here yet
1499 + * free it at end of burst, to get the correct count for SPLITs removed.
1501 + else if (ircd_strcmp(split->sp_server, cli_name(cptr)) == 0)
1504 + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s",
1505 + SplitIsActive(split) ? '+' : '-', split->sp_server,
1506 + split->sp_creation, split->sp_expire,
1507 + split->sp_lastmod, split->sp_lifetime,
1508 + split->sp_reason);
1512 +/** Forward a split to another server.
1513 + * @param[in] cptr Server to send split entries to.
1514 + * @param[in] split Split to forward.
1518 +split_resend(struct Client *cptr, struct Split *split)
1520 + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s",
1521 + SplitIsActive(split) ? '+' : '-', split->sp_server,
1522 + split->sp_creation, split->sp_expire,
1523 + split->sp_lastmod, split->sp_lifetime,
1524 + split->sp_reason);
1529 +/** Send a split entry (or a list of split entries) to a server.
1530 + * @param[in] sptr Client searching for split entries.
1531 + * @param[in] server Name of split entry to search for (if NULL, list all).
1535 +split_list(struct Client *sptr, char *server)
1537 + struct Split *split;
1540 + assert(NULL != sptr);
1542 + /* go through SPLITs */
1543 + for (split = GlobalSplitList; split; split = split->sp_next) {
1544 + if (split_expire(split)) { /* expire any that need expiring */
1545 + split_free(split);
1548 + if (server && match(server, split->sp_server))
1551 + send_reply(sptr, RPL_SPLITLIST, split->sp_server,
1552 + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime,
1553 + SplitIsActive(split) ? '+' : '-', split->sp_reason);
1556 + /* server given and nothing found */
1557 + if (server && !count)
1558 + return send_reply(sptr, ERR_NOSUCHSPLIT, server);
1560 + /* end of splitlist information */
1561 + return send_reply(sptr, RPL_ENDOFSPLITLIST);
1565 +/** Mark SPLIT for new server with SPLIT_BURST
1566 + * @param[in] acptr Server introduced to the network
1569 +split_newserver(struct Client *acptr)
1571 + struct Split *split;
1573 + assert(NULL != acptr);
1575 + Debug((DEBUG_DEBUG, "split_newserver(\"%s\")", cli_name(acptr)));
1577 + /* mark the SPLIT with SPLIT_BURST
1578 + * so we know this SPLIT is marked for removal already
1579 + * but not remove it just yet to get the correct count
1580 + * of SPLITs removed at the end of burst.
1581 + * also we need the SPLIT in case the net breaks again
1582 + * before end of burst?
1584 + if ((split = split_find(cli_name(acptr))))
1585 + split->sp_flags |= SPLIT_BURST;
1590 +/** Auto destroy SPLITs for servers gained in a netmerge
1591 + * @param[in] sptr Server that has linked to the network
1592 + * @return Number of destroyed SPLITs
1595 +split_netmerge(struct Client *sptr)
1598 + struct Split *split;
1601 + assert(NULL != sptr);
1603 + Debug((DEBUG_DEBUG, "split_netmerge(\"%s\")", cli_name(sptr)));
1605 + /* find the SPLIT for this server */
1606 + if ((split = split_find(cli_name(sptr)))) {
1607 + split_free(split);
1611 + /* go over its downlinks */
1612 + for (lp = cli_serv(sptr)->down; lp; lp = lp->next)
1613 + count += split_netmerge(lp->value.cptr);
1618 +/** Auto create SPLITs for servers lost in a netbreak
1619 + * @param[in] victim Server that lost link to network
1620 + * @param[in] reason Reason to add to SPLITs
1621 + * @return Number of created SPLITs
1624 +split_netbreak(struct Client *victim, const char *reason)
1627 + struct Split *split;
1629 + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE),
1630 + lastmod = TStime(), lifetime = expire;
1631 + unsigned int flags = SPLIT_ACTIVE;
1633 + assert(NULL != victim);
1635 + Debug((DEBUG_DEBUG, "split_netbreak(\"%s\", \"%s\")", cli_name(victim), reason));
1637 + /* bad auto expire value */
1638 + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0)
1641 + /* TODO: what if we do have a SPLIT for this server?
1642 + * we remove splits in end of burst
1643 + * and if the netbreaks again before that
1644 + * free the SPLIT and create a new one?
1645 + * or simply update lastmod/lifetime/reason but leave the status?
1647 + /* find the SPLIT for this server */
1648 + if (!(split = split_find(cli_name(victim)))) {
1649 + split_make(cli_name(victim), reason, creation, expire, lastmod, lifetime, flags);
1652 + split->sp_flags &= SPLIT_BURST; /* clear the burst flag for it */
1654 + /* go over its downlinks */
1655 + for (lp = cli_serv(victim)->down; lp; lp = lp->next)
1656 + count += split_netbreak(lp->value.cptr, reason);
1661 +/** Auto create SPLITs for servers we have a Connect Block for
1667 + struct ConfItem *conf;
1668 + struct Client *server;
1669 + struct Split *split;
1670 + struct Split *asplit;
1671 + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE),
1672 + lastmod = TStime(), lifetime = expire;
1673 + unsigned int flags = SPLIT_ACTIVE;
1674 + char reason[BUFSIZE];
1676 + Debug((DEBUG_DEBUG, "split_conf()"));
1678 + /* we are not set to generate SPLITs */
1679 + if (!feature_bool(FEAT_SPLIT))
1682 + /* TODO: log this problem? */
1683 + /* bad auto expire value */
1684 + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0)
1687 + ircd_snprintf(0, reason, sizeof(reason),
1688 + "Generated upon loading conf file on %C", &me);
1690 + /* go over the conf contents */
1691 + for (conf = GlobalConfList; conf; conf = conf->next) {
1692 + /* not a Connect Block */
1693 + if (CONF_SERVER != conf->status)
1695 + /* server is linked */
1696 + if (server = FindServer(conf->name))
1698 + /* we have a SPLIT for this server already */
1699 + if (split = split_find(conf->name))
1701 + /* TODO: use SNO_OLDSNO here?
1702 + * just like nickcollisions on local users go there?
1703 + * or at least change the source / message format?
1704 + * /REHASH goes to SNO_OLDSNO? so this too?
1705 + * if oper did rehash, add his name here?
1707 + /* inform ops and log it */
1708 + sendto_opmask_butone(0, SNO_NETWORK, "%C adding SPLIT for %s, expiring at %Tu: %s",
1709 + &me, conf->name, expire, reason);
1711 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1712 + "%C adding SPLIT for %s, expiring at %Tu: %s",
1713 + &me, conf->name, expire, reason);
1715 + /* make the split entry */
1716 + asplit = split_make(conf->name, reason, creation, expire, lastmod, lifetime, flags);
1720 + /* and propagate it */
1721 + split_propagate(&me, &me, asplit, NULL);
1726 +/** Statistics callback to list SPLITs.
1727 + * @param[in] sptr Client requesting statistics.
1728 + * @param[in] sd Stats descriptor for request (ignored).
1729 + * @param[in] param Extra parameter from user (ignored).
1732 +split_stats(struct Client *sptr, const struct StatDesc *sd,
1735 + struct Split *split;
1737 + /* send header so the client knows what we are showing */
1738 + send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER,
1739 + "S Server Creation Expire Lastmod Lifetime Status :Reason");
1741 + for (split = GlobalSplitList; split; split = split->sp_next) {
1742 + if (param && match(param, split->sp_server))
1744 + send_reply(sptr, RPL_STATSSPLIT, split->sp_server,
1745 + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime,
1746 + SplitIsActive(split) ? '+' : '-', split->sp_reason);
1751 +/** Count split entries and memory used by them.
1752 + * @param[out] sp_size Receives total number of bytes allocated for split entries.
1753 + * @return Number of split entries currently allocated.
1756 +split_memory_count(size_t *sp_size)
1758 + struct Split *split;
1759 + unsigned int sp = 0;
1761 + for (split = GlobalSplitList; split; split = split->sp_next) {
1763 + *sp_size += sizeof(struct Split);
1764 + *sp_size += split->sp_server ? (strlen(split->sp_server) + 1) : 0;
1765 + *sp_size += split->sp_reason ? (strlen(split->sp_reason) + 1) : 0;