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 5ad24aad236d doc/api/log.txt
11 --- a/doc/api/log.txt Sat Jan 31 14:38:44 2009 +0100
12 +++ b/doc/api/log.txt Sat Jan 31 15:25:32 2009 +0100
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 5ad24aad236d include/handlers.h
23 --- a/include/handlers.h Sat Jan 31 14:38:44 2009 +0100
24 +++ b/include/handlers.h Sat Jan 31 15:25:32 2009 +0100
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 5ad24aad236d include/ircd_features.h
50 --- a/include/ircd_features.h Sat Jan 31 14:38:44 2009 +0100
51 +++ b/include/ircd_features.h Sat Jan 31 15:25:32 2009 +0100
58 + FEAT_SPLIT_AUTO_EXPIRE,
60 /* HEAD_IN_SAND Features */
62 FEAT_HIS_SNOTICES_OPER_ONLY,
79 diff -r 5ad24aad236d include/ircd_log.h
80 --- a/include/ircd_log.h Sat Jan 31 14:38:44 2009 +0100
81 +++ b/include/ircd_log.h Sat Jan 31 15:25:32 2009 +0100
83 LS_OPERMODE, /**< Uses of OPMODE, CLEARMODE< etc. */
84 LS_GLINE, /**< Adding, (de-)activating or removing GLINEs. */
85 LS_JUPE, /**< Adding, (de-)activating or removing JUPEs. */
86 + LS_SPLIT, /**< Adding, (de-)activating or removing SPLITs. */
87 LS_WHO, /**< Use of extended WHO privileges. */
88 LS_NETWORK, /**< New server connections. */
89 LS_OPERKILL, /**< Kills by IRC operators. */
90 diff -r 5ad24aad236d include/msg.h
91 --- a/include/msg.h Sat Jan 31 14:38:44 2009 +0100
92 +++ b/include/msg.h Sat Jan 31 15:25:32 2009 +0100
95 #define CMD_JUPE MSG_JUPE, TOK_JUPE
97 +#define MSG_SPLIT "SPLIT" /* SPLIT */
98 +#define TOK_SPLIT "SP"
99 +#define CMD_SPLIT MSG_SPLIT, TOK_SPLIT
101 #define MSG_OPMODE "OPMODE" /* OPMO */
102 #define TOK_OPMODE "OM"
103 #define CMD_OPMODE MSG_OPMODE, TOK_OPMODE
104 diff -r 5ad24aad236d include/numeric.h
105 --- a/include/numeric.h Sat Jan 31 14:38:44 2009 +0100
106 +++ b/include/numeric.h Sat Jan 31 15:25:32 2009 +0100
108 #define RPL_STATSALINE 226 /* Hybrid, Undernet */
109 #define RPL_STATSWELCOME 227 /* QuakeNet extension */
110 #define RPL_STATSQLINE 228 /* Undernet extension */
111 +#define RPL_STATSSPLIT 229 /* QuakeNet extension */
112 #define RPL_STATSHEADER 230 /* QuakeNet extension */
114 /* RPL_SERVICEINFO 231 unused */
116 #define RPL_STATSDLINE 275 /* Undernet extension */
117 #define RPL_STATSRLINE 276 /* Undernet extension */
119 +#define RPL_SPLITLIST 278 /* QuakeNet extension */
120 +#define RPL_ENDOFSPLITLIST 279 /* QuakeNet extension */
121 #define RPL_GLIST 280 /* Undernet extension */
122 #define RPL_ENDOFGLIST 281 /* Undernet extension */
123 #define RPL_JUPELIST 282 /* Undernet extension - jupe -Kev */
126 #define ERR_NOSUCHWELCOME 509 /* QuakeNet extension */
128 +#define ERR_NOSUCHSPLIT 510 /* QuakeNet extension */
129 #define ERR_SILELISTFULL 511 /* Undernet extension */
130 /* ERR_NOTIFYFULL 512 aircd */
131 /* ERR_TOOMANYWATCH 512 Numeric List: Dalnet */
132 diff -r 5ad24aad236d include/split.h
133 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
134 +++ b/include/split.h Sat Jan 31 15:25:32 2009 +0100
136 +#ifndef INCLUDED_split_h
137 +#define INCLUDED_split_h
139 + * IRC - Internet Relay Chat, include/split.h
140 + * Copyright (C) 1990 Jarkko Oikarinen and
141 + * University of Oulu, Computing Center
142 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
144 + * This program is free software; you can redistribute it and/or modify
145 + * it under the terms of the GNU General Public License as published by
146 + * the Free Software Foundation; either version 2, or (at your option)
147 + * any later version.
149 + * This program is distributed in the hope that it will be useful,
150 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
151 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
152 + * GNU General Public License for more details.
154 + * You should have received a copy of the GNU General Public License
155 + * along with this program; if not, write to the Free Software
156 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
159 + * @brief Interface and declarations for split server handling.
161 +#ifndef INCLUDED_sys_types_h
162 +#include <sys/types.h>
163 +#define INCLUDED_sys_types_h
170 +#define SPLIT_MAX_EXPIRE 2419200 /**< Maximum split expiration time (4 weeks).
171 + * that an operator can use in /SPLIT
173 +#define SPLIT_MAX_DRIFT 600 /**< Maximum drift in seconds allowed in lastmod
175 + * when greater correct and throw warning
178 +/* Describes a SPLIT server entry. */
180 + struct Split* sp_next; /**< Pointer to next Split. */
181 + struct Split** sp_prev_p; /**< Pointer to previous next pointer. */
182 + char* sp_server; /**< Name of server. */
183 + char* sp_reason; /**< Reason. */
184 + time_t sp_creation; /**< TODO: Creation time. What are we using this for then? */
185 + time_t sp_expire; /**< Expiration time. */
186 + time_t sp_lastmod; /**< Last modification time. */
187 + time_t sp_lifetime; /**< Life time. */
188 + unsigned int sp_flags; /**< Status flags. */
191 +/** Split state flags. */
192 +#define SPLIT_ACTIVE 0x01 /**< Split is active. */
193 +#define SPLIT_REMOVING 0x02 /**< Split is being force removed (instead of deactivated). */
194 +#define SPLIT_BURST 0x04 /**< Split is for a server that is in progress of linking,
195 + and will be destroyed at the end of burst */
197 +/* Actions to perform on a SPLIT. */
199 + SPLIT_ACTIVATE, /**< SPLIT should be activated. */
200 + SPLIT_DEACTIVATE, /**< SPLIT should be deactivated. */
201 + SPLIT_MODIFY, /**< SPLIT should be modified. */
202 + SPLIT_REMOVE /**< SPLIT should be removed. */
205 +/* Split update flags. */
206 +#define SPLIT_EXPIRE 0x01 /**< Expiration time update. */
207 +#define SPLIT_LIFETIME 0x02 /**< Record lifetime update. */
208 +#define SPLIT_REASON 0x04 /**< Reason update. */
210 +/* mask for Split update flags. */
211 +#define SPLIT_UPDATE (SPLIT_EXPIRE | SPLIT_LIFETIME | SPLIT_REASON)
213 +/* test whether a split entry is active. */
214 +#define SplitIsActive(s) ((s)->sp_flags & SPLIT_ACTIVE)
215 +/* test whether a split entry is marked for forced removal. */
216 +#define SplitIsRemoving(s) ((s)->sp_flags & SPLIT_REMOVING)
217 +/* test whether a split entry is part of a netmerge. */
218 +#define SplitIsBurst(s) ((s)->sp_flags & SPLIT_BURST)
220 +extern int split_add(struct Client *cptr, struct Client *sptr,
221 + char *server, const char *reason,
222 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
223 + unsigned int flags);
224 +extern int split_modify(struct Client *cptr, struct Client *sptr,
225 + struct Split *split, enum SplitAction action, const char *reason,
226 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
227 + unsigned int flags);
228 +extern int split_remove(struct Client *cptr, struct Client *sptr,
229 + struct Split *split, const char *reason);
231 +extern struct Split* split_find(char *server);
232 +extern void split_free(struct Split *split);
233 +extern int split_expire(struct Split* split);
234 +extern void split_burst(struct Client *cptr);
235 +extern int split_resend(struct Client *cptr, struct Split *split);
236 +extern int split_list(struct Client *sptr, char *server);
237 +extern void split_newserver(struct Client *acptr);
238 +extern int split_netmerge(struct Client *sptr);
239 +extern int split_netbreak(struct Client *victim, const char *reason);
240 +extern void split_conf();
241 +extern void split_stats(struct Client *sptr, const struct StatDesc *sd, char *param);
242 +extern int split_memory_count(size_t *sp_size);
244 +#endif /* INCLUDED_split_h */
245 diff -r 5ad24aad236d ircd/Makefile.in
246 --- a/ircd/Makefile.in Sat Jan 31 14:38:44 2009 +0100
247 +++ b/ircd/Makefile.in Sat Jan 31 15:25:32 2009 +0100
264 @@ -1054,6 +1056,15 @@
265 ../include/ircd_chattr.h ../include/list.h ../include/msg.h \
266 ../include/numeric.h ../include/numnicks.h ../include/s_user.h \
267 ../include/send.h ../include/struct.h
268 +m_split.o: m_split.c ../config.h ../include/client.h ../include/ircd_defs.h \
269 + ../include/dbuf.h ../include/msgq.h ../include/ircd_events.h \
270 + ../config.h ../include/ircd_handler.h ../include/res.h \
271 + ../include/capab.h ../include/split.h ../include/hash.h \
272 + ../include/ircd.h ../include/struct.h ../include/ircd_features.h \
273 + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \
274 + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
275 + ../include/numeric.h ../include/numnicks.h ../include/s_conf.h \
276 + ../include/client.h ../include/s_misc.h ../include/send.h
277 m_squit.o: m_squit.c ../config.h ../include/client.h \
278 ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \
279 ../include/ircd_events.h ../config.h ../include/ircd_handler.h \
280 @@ -1332,6 +1343,7 @@
281 ../include/msgq.h ../include/numeric.h ../include/numnicks.h \
282 ../include/res.h ../include/s_bsd.h ../include/s_conf.h \
283 ../include/s_user.h ../include/s_stats.h ../include/send.h \
284 + ../include/split.h \
285 ../include/struct.h ../include/sys.h ../include/whowas.h
286 s_err.o: s_err.c ../config.h ../include/numeric.h ../include/ircd_log.h \
287 ../include/s_debug.h ../config.h ../include/ircd_defs.h
288 @@ -1417,6 +1429,16 @@
289 ../include/msg.h ../include/numnicks.h ../include/parse.h \
290 ../include/s_bsd.h ../include/s_debug.h ../include/s_misc.h \
291 ../include/s_user.h ../include/struct.h ../include/sys.h
292 +split.o: split.c ../config.h ../include/split.h ../include/client.h \
293 + ../include/ircd_defs.h ../include/dbuf.h ../include/msgq.h \
294 + ../include/ircd_events.h ../config.h ../include/ircd_handler.h \
295 + ../include/res.h ../include/capab.h ../include/hash.h ../include/ircd.h \
296 + ../include/struct.h ../include/ircd_alloc.h ../include/ircd_features.h \
297 + ../include/ircd_log.h ../include/ircd_reply.h ../include/ircd_string.h \
298 + ../include/ircd_chattr.h ../include/match.h ../include/msg.h \
299 + ../include/numeric.h ../include/numnicks.h ../include/s_bsd.h \
300 + ../include/s_misc.h ../include/send.h ../include/struct.h \
302 uping.o: uping.c ../config.h ../include/uping.h ../include/ircd_defs.h \
303 ../include/ircd_events.h ../config.h ../include/res.h \
304 ../include/client.h ../include/dbuf.h ../include/msgq.h \
305 diff -r 5ad24aad236d ircd/ircd.c
306 --- a/ircd/ircd.c Sat Jan 31 14:38:44 2009 +0100
307 +++ b/ircd/ircd.c Sat Jan 31 15:25:32 2009 +0100
315 #include "userload.h"
317 Debug((DEBUG_NOTICE, "Server ready..."));
318 log_write(LS_SYSTEM, L_NOTICE, 0, "Server Ready");
320 + /* create SPLITs */
326 diff -r 5ad24aad236d ircd/ircd_features.c
327 --- a/ircd/ircd_features.c Sat Jan 31 14:38:44 2009 +0100
328 +++ b/ircd/ircd_features.c Sat Jan 31 15:25:32 2009 +0100
330 F_B(SETHOST_USER, 0, 0, 0),
331 F_B(SETHOST_AUTO, 0, 0, 0),
334 + F_B(SPLIT, 0, 1, 0),
335 + F_I(SPLIT_AUTO_EXPIRE, 0, 604800, 0),
337 /* HEAD_IN_SAND Features */
338 F_B(HIS_SNOTICES, 0, 1, 0),
339 F_B(HIS_SNOTICES_OPER_ONLY, 0, 1, 0),
341 F_B(HIS_MAP, 0, 1, 0),
342 F_B(HIS_LINKS, 0, 1, 0),
343 F_B(HIS_TRACE, 0, 1, 0),
344 + F_B(HIS_SPLIT, 0, 1, 0),
345 F_B(HIS_STATS_a, 0, 1, 0),
346 F_B(HIS_STATS_c, 0, 1, 0),
347 F_B(HIS_STATS_d, 0, 1, 0),
349 F_B(HIS_STATS_q, 0, 1, 0),
350 F_B(HIS_STATS_R, 0, 1, 0),
351 F_B(HIS_STATS_r, 0, 1, 0),
352 + F_B(HIS_STATS_S, 0, 1, 0),
353 F_B(HIS_STATS_s, 0, 1, 0),
354 F_B(HIS_STATS_t, 0, 1, 0),
355 F_B(HIS_STATS_T, 0, 1, 0),
356 diff -r 5ad24aad236d ircd/ircd_log.c
357 --- a/ircd/ircd_log.c Sat Jan 31 14:38:44 2009 +0100
358 +++ b/ircd/ircd_log.c Sat Jan 31 15:25:32 2009 +0100
360 S(OPERMODE, -1, SNO_HACK4),
361 S(GLINE, -1, SNO_GLINE),
362 S(JUPE, -1, SNO_NETWORK),
363 + S(SPLIT, -1, SNO_NETWORK),
365 S(NETWORK, -1, SNO_NETWORK),
367 diff -r 5ad24aad236d ircd/m_endburst.c
368 --- a/ircd/m_endburst.c Sat Jan 31 14:38:44 2009 +0100
369 +++ b/ircd/m_endburst.c Sat Jan 31 15:25:32 2009 +0100
374 +#include "ircd_features.h"
375 #include "ircd_log.h"
376 #include "ircd_reply.h"
377 #include "ircd_string.h"
380 #include "numnicks.h"
384 /* #include <assert.h> -- Now using assert in ircd_log.h */
387 int ms_end_of_burst(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
389 struct Channel *chan, *next_chan;
395 dump_map(sptr, "*", 0, report_new_links, 0);
396 sendto_opmask_butone(0, SNO_NETWORK, "Completed net.burst from %C.",
398 + /* cleanup SPLITs, but only bother ops when FEAT_SPLIT is enabled. */
399 + split = split_netmerge(sptr);
400 + if (feature_bool(FEAT_SPLIT))
401 + sendto_opmask_butone(0, SNO_NETWORK, "Removed %d SPLIT entries.", split);
403 sendcmdto_one(&me, CMD_END_OF_BURST_ACK, sptr, "");
405 diff -r 5ad24aad236d ircd/m_reburst.c
406 --- a/ircd/m_reburst.c Sat Jan 31 14:38:44 2009 +0100
407 +++ b/ircd/m_reburst.c Sat Jan 31 15:25:32 2009 +0100
409 #include "ircd_snprintf.h"
414 /* #include <assert.h> -- Now using assert in ircd_log.h */
427 diff -r 5ad24aad236d ircd/m_server.c
428 --- a/ircd/m_server.c Sat Jan 31 14:38:44 2009 +0100
429 +++ b/ircd/m_server.c Sat Jan 31 15:25:32 2009 +0100
435 #include "userload.h"
437 /* #include <assert.h> -- Now using assert in ircd_log.h */
439 sendto_opmask_butone(0, SNO_NETWORK, "Net junction: %s %s",
440 cli_name(sptr), cli_name(acptr));
442 + /* new server - mark SPLIT for this server */
443 + split_newserver(acptr);
446 * Old sendto_serv_but_one() call removed because we now need to send
447 * different names to different servers (domain name matching).
448 diff -r 5ad24aad236d ircd/m_split.c
449 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
450 +++ b/ircd/m_split.c Sat Jan 31 15:25:32 2009 +0100
453 + * IRC - Internet Relay Chat, ircd/m_split.c
454 + * Copyright (C) 1990 Jarkko Oikarinen and
455 + * University of Oulu, Computing Center
456 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
458 + * See file AUTHORS in IRC package for additional names of
461 + * This program is free software; you can redistribute it and/or modify
462 + * it under the terms of the GNU General Public License as published by
463 + * the Free Software Foundation; either version 1, or (at your option)
464 + * any later version.
466 + * This program is distributed in the hope that it will be useful,
467 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
468 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
469 + * GNU General Public License for more details.
471 + * You should have received a copy of the GNU General Public License
472 + * along with this program; if not, write to the Free Software
473 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
478 + * m_functions execute protocol messages on this server:
480 + * cptr is always NON-NULL, pointing to a *LOCAL* client
481 + * structure (with an open socket connected!). This
482 + * identifies the physical socket where the message
483 + * originated (or which caused the m_function to be
484 + * executed--some m_functions may call others...).
486 + * sptr is the source of the message, defined by the
487 + * prefix part of the message if present. If not
488 + * or prefix not found, then sptr==cptr.
490 + * (!IsServer(cptr)) => (cptr == sptr), because
491 + * prefixes are taken *only* from servers...
494 + * (sptr == cptr) => the message didn't
497 + * (sptr != cptr && IsServer(sptr) means
498 + * the prefix specified servername. (?)
500 + * (sptr != cptr && !IsServer(sptr) means
501 + * that message originated from a remote
502 + * user (not local).
506 + * (!IsServer(sptr)) means that, sptr can safely
507 + * taken as defining the target structure of the
508 + * message in this server.
510 + * *Always* true (if 'parse' and others are working correct):
512 + * 1) sptr->from == cptr (note: cptr->from == cptr)
514 + * 2) MyConnect(sptr) <=> sptr == cptr (e.g. sptr
515 + * *cannot* be a local connection, unless it's
516 + * actually cptr!). [MyConnect(x) should probably
517 + * be defined as (x == x->from) --msa ]
519 + * parc number of variable parameter strings (if zero,
520 + * parv is allowed to be NULL)
522 + * parv a NULL terminated list of parameter pointers,
524 + * parv[0], sender (prefix string), if not present
525 + * this points to an empty string.
526 + * parv[1]...parv[parc-1]
527 + * pointers to additional parameters
528 + * parv[parc] == NULL, *always*
530 + * note: it is guaranteed that parv[0]..parv[parc-1] are all
531 + * non-NULL pointers.
539 +#include "ircd_features.h"
540 +#include "ircd_log.h"
541 +#include "ircd_reply.h"
542 +#include "ircd_string.h"
545 +#include "numeric.h"
546 +#include "numnicks.h"
548 +#include "s_debug.h"
552 +/* #include <assert.h> -- Now using assert in ircd_log.h */
557 + * ms_split - server message handler
559 + * parv[0] = Send prefix
560 + * parv[1] = (+|-)<server name>
561 + * parv[2] = Creation time
562 + * parv[3] = Expiration time
563 + * parv[4] = Last modification time
564 + * parv[5] = Life time
565 + * parv[6] = Comment
568 +int ms_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
570 + struct Split *asplit = 0;
571 + unsigned int flags = 0;
572 + enum SplitAction action = SPLIT_MODIFY;
573 + time_t creation = 0, expire = 0, lastmod = 0, lifetime = 0;
575 + const char *reason = "No reason";
577 + /* reason is optional - for lazy services, we always send it */
579 + protocol_violation(sptr, "Too few parameters for SPLIT (got %d - need at least 5)", parc);
580 + return need_more_params(sptr, "SPLIT");
586 + /* check for ! prefix - force removing */
587 + if (*server == '!') {
589 + action = SPLIT_REMOVE;
592 + /* check for + and - prefix */
595 + if (action != SPLIT_REMOVE)
596 + action = SPLIT_ACTIVATE;
601 + if (action != SPLIT_REMOVE)
602 + action = SPLIT_DEACTIVATE;
607 + /* Next, try to find the split entry... */
608 + asplit = split_find(server);
610 + /* We now have all the pieces to tell us what we've got; let's put
611 + * it all together and convert the rest of the arguments.
614 + /* cannot modify a split entry that does not exist - remap to activate */
615 + if (!asplit && action == SPLIT_MODIFY)
616 + action = SPLIT_ACTIVATE;
618 + /* set all flags for modification */
619 + if (asplit && action != SPLIT_REMOVE)
620 + flags = SPLIT_UPDATE;
622 + /* set the things we need */
623 + creation = atoi(parv[2]);
624 + expire = atoi(parv[3]);
625 + lastmod = atoi(parv[4]);
626 + lifetime = atoi(parv[5]);
628 + /* got a reason too */
630 + reason = parv[parc - 1];
632 + flags &= ~SPLIT_REASON;
635 + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; "
636 + "server %s, action %s, creation %Tu, expire %Tu, "
637 + "lastmod %Tu, lifetime %Tu, reason: %s; split %s!", server,
638 + action == SPLIT_REMOVE ? "!-" :
639 + (action == SPLIT_ACTIVATE ? "+" :
640 + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")),
641 + creation, expire, lastmod, lifetime, reason,
642 + asplit ? "EXISTS" : "does not exist"));
644 + /* modify or remove an existing SPLIT */
646 + if (action == SPLIT_REMOVE)
647 + return split_remove(cptr, sptr, asplit, reason);
648 + return split_modify(cptr, sptr, asplit, action, reason, creation, expire,
649 + lastmod, lifetime, flags);
652 + /* desynch or cross - we do not have it so we cannot remove it */
653 + /* TODO: manually propagate the message ?
655 + * but if we do not have it, can our downlinks have it?
656 + * they could if my oper force removed it earlier, and then my downlinks linked
657 + * no, then they would have bursted it again to us.. argh
659 + if (!asplit && action == SPLIT_REMOVE)
662 + /* this should not happen */
663 + assert(action != SPLIT_MODIFY);
664 + assert(action != SPLIT_REMOVE);
666 + /* create a new SPLIT */
667 + return split_add(cptr, sptr, server, reason, creation, expire, lastmod, lifetime,
668 + action == SPLIT_ACTIVATE ? SPLIT_ACTIVE : 0);
673 + * mo_split - oper message handler
675 + * Local listing: 1 or 2 params
676 + * parv[0] = Send prefix
677 + * parv[1] = [Server or mask to match]
679 + * Add or modify entry: 3, 4 or 5 params (3 is * then)
680 + * parv[0] = Send prefix
681 + * parv[1] = [+|-]<server name>
682 + * parv[2] = [Expiration offset] (required for new)
683 + * parv[3] = [Comment] (required for new)
686 +int mo_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
688 + struct Split *asplit = 0;
689 + unsigned int flags = 0;
690 + enum SplitAction action = SPLIT_MODIFY;
691 + time_t expire = 0, lastmod = TStime(), creation = TStime();
692 + char *server, *end;
693 + const char *reason = NULL;
695 + /* check HIS and privs */
696 + if (feature_bool(FEAT_HIS_SPLIT) && !HasPriv(sptr, PRIV_ROUTEINFO))
697 + return send_reply(sptr, ERR_NOPRIVILEGES);
701 + return split_list(sptr, 0);
706 + /* ! prefix - force removal */
707 + if (*server == '!') {
709 + action = SPLIT_REMOVE;
712 + /* handle + and - */
715 + if (action != SPLIT_REMOVE)
716 + action = SPLIT_ACTIVATE;
721 + if (action != SPLIT_REMOVE)
722 + action = SPLIT_DEACTIVATE;
727 + /* user wants listing */
728 + if (action == SPLIT_MODIFY && parc == 2)
729 + return split_list(sptr, server);
731 + /* if we have an expire, this must be it */
733 + expire = strtol(parv[2], &end, 10);
735 + /* got reason and expire */
737 + flags |= SPLIT_EXPIRE;
738 + flags |= SPLIT_REASON;
740 + /* got reason or expire */
741 + else if (parc > 2) {
743 + flags |= SPLIT_REASON;
745 + flags |= SPLIT_EXPIRE;
749 + if (flags & SPLIT_REASON) {
750 + reason = parv[parc - 1];
751 + /* ignore empty reason */
752 + if (EmptyString(reason))
753 + flags &= ~SPLIT_REASON;
757 + if (flags & SPLIT_EXPIRE && *end != '\0')
758 + return send_reply(sptr, SND_EXPLICIT | ERR_BADEXPIRE, "%s :Bad expire time", parv[2]);
760 + /* require a reason for forced removal */
761 + if (!(flags & SPLIT_REASON) && action == SPLIT_REMOVE)
762 + return need_more_params(sptr, "SPLIT");
764 + /* we got expire */
765 + if (flags & SPLIT_EXPIRE) {
766 + if (expire == 0) /* dummy value 0 given, no change to expire */
767 + flags &= ~SPLIT_EXPIRE;
768 + else /* turn expire into timestamp */
769 + expire += TStime();
772 + /* TODO: but allow force removal when disabled? */
773 + /* check feature and privs */
774 + if (!feature_bool(FEAT_SPLIT))
775 + return send_reply(sptr, ERR_DISABLED, "SPLIT");
776 + /* TODO: create PRIV_SPLIT - need help there */
777 + else if (!HasPriv(sptr, PRIV_SERVERINFO))
778 + return send_reply(sptr, ERR_NOPRIVILEGES);
780 + /* we have all we need - find the split */
781 + asplit = split_find(server);
783 + /* SPLIT not found and thus we cannot:
784 + * remove SPLIT we do not have
785 + * add new SPLIT without expire and reason
788 + ((action == SPLIT_REMOVE) ||
789 + (action == SPLIT_ACTIVATE && !reason) ||
790 + (action == SPLIT_DEACTIVATE && !reason) ||
791 + (action == SPLIT_MODIFY && !reason)))
792 + return send_reply(sptr, ERR_NOSUCHSPLIT, server);
794 + /* cannot modify a split entry that does not exist - remap to activate */
795 + if (!asplit && action == SPLIT_MODIFY)
796 + action = SPLIT_ACTIVATE;
799 + Debug((DEBUG_DEBUG, "I have a SPLIT I am acting upon now; "
800 + "server %s, action %s, expire %Tu, "
801 + "reason: %s; split %s! (fields present: %s %s)", server,
802 + action == SPLIT_REMOVE ? "!-" :
803 + (action == SPLIT_ACTIVATE ? "+" :
804 + (action == SPLIT_DEACTIVATE ? "-" : "(MODIFY)")),
805 + expire, reason, asplit ? "EXISTS" : "does not exist",
806 + flags & SPLIT_EXPIRE ? "expire" : "",
807 + flags & SPLIT_REASON ? "reason" : ""));
809 + /* modify or remove an existing SPLIT */
811 + if (action == SPLIT_REMOVE)
812 + return split_remove(cptr, sptr, asplit, reason);
813 + return split_modify(cptr, sptr, asplit, action, reason,
814 + asplit->sp_creation, expire, lastmod, asplit->sp_lifetime, flags);
817 + /* this should not happen */
818 + assert(action != SPLIT_MODIFY);
819 + assert(action != SPLIT_REMOVE);
821 + /* create a new SPLIT */
822 + return split_add(cptr, sptr, server, reason,
823 + creation, expire, lastmod, expire,
824 + (action == SPLIT_ACTIVATE) ? SPLIT_ACTIVE : 0);
829 + * m_split - user message handler
831 + * parv[0] = Send prefix
832 + * parv[1] = [<server name>]
835 +int m_split(struct Client* cptr, struct Client* sptr, int parc, char* parv[])
838 + /* ordinary users are not allowed to see it when HIS_SPLIT is true
839 + * and are not allowed to to give more than two parameters
842 + if (feature_bool(FEAT_HIS_SPLIT) || parc > 2)
843 + return send_reply(sptr, ERR_NOPRIVILEGES);
847 + return split_list(sptr, 0);
849 + /* looking for a match */
850 + return split_list(sptr, parv[1]);
852 diff -r 5ad24aad236d ircd/parse.c
853 --- a/ircd/parse.c Sat Jan 31 14:38:44 2009 +0100
854 +++ b/ircd/parse.c Sat Jan 31 15:25:32 2009 +0100
856 { m_unregistered, m_not_oper, ms_jupe, mo_jupe, m_ignore, mh_jupe }
861 + 0, MAXPARA, MFLG_SLOW, 0, NULL,
862 + /* UNREG, CLIENT, SERVER, OPER, SERVICE, HELP */
863 + { m_unregistered, m_split, ms_split, mo_split, m_ignore, mh_nohelp }
868 0, MAXPARA, MFLG_SLOW, 0, NULL,
869 diff -r 5ad24aad236d ircd/s_conf.c
870 --- a/ircd/s_conf.c Sat Jan 31 14:38:44 2009 +0100
871 +++ b/ircd/s_conf.c Sat Jan 31 15:25:32 2009 +0100
880 @@ -1005,6 +1006,7 @@
883 attach_conf_uworld(&me);
888 diff -r 5ad24aad236d ircd/s_debug.c
889 --- a/ircd/s_debug.c Sat Jan 31 14:38:44 2009 +0100
890 +++ b/ircd/s_debug.c Sat Jan 31 15:25:32 2009 +0100
900 aw = 0, /* aways set */
901 wwa = 0, /* whowas aways */
903 - ju = 0; /* jupes */
904 + ju = 0, /* jupes */
905 + sp = 0; /* splits */
907 size_t chm = 0, /* memory used by channels */
908 chbm = 0, /* memory used by channel bans */
910 wwm = 0, /* whowas array memory used */
911 glm = 0, /* memory used by glines */
912 jum = 0, /* memory used by jupes */
913 + spm = 0, /* memory used by splits */
914 com = 0, /* memory used by conf lines */
915 dbufs_allocated = 0, /* memory used by dbufs */
916 dbufs_used = 0, /* memory used by dbufs */
919 gl = gline_memory_count(&glm);
920 ju = jupe_memory_count(&jum);
921 + sp = split_memory_count(&spm);
922 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
923 - ":Glines %d(%zu) Jupes %d(%zu)", gl, glm, ju, jum);
924 + ":Glines %d(%zu) Jupes %d(%zu) Splits %d(%zu)", gl, glm, ju, jum, sp, spm);
926 send_reply(cptr, SND_EXPLICIT | RPL_STATSDEBUG,
927 ":Hash: client %d(%zu), chan is the same", HASHSIZE,
928 diff -r 5ad24aad236d ircd/s_err.c
929 --- a/ircd/s_err.c Sat Jan 31 14:38:44 2009 +0100
930 +++ b/ircd/s_err.c Sat Jan 31 15:25:32 2009 +0100
933 { RPL_STATSQLINE, "Q %s :%s", "228" },
936 + { RPL_STATSSPLIT, "S %s %d %d %d %d %c :%s", "229" },
938 { RPL_STATSHEADER, 0, "230" },
945 + { RPL_SPLITLIST, "%s %Tu %Tu %Tu %Tu %c :%s", "278" },
948 + { RPL_ENDOFSPLITLIST, ":End of Split List", "279" },
950 { RPL_GLIST, "%s%s%s%s%s %Tu %Tu %Tu %s %s%s%c :%s", "280" },
952 @@ -1052,7 +1052,7 @@
954 { ERR_NOSUCHWELCOME, "%s :No such welcome", "509" },
957 + { ERR_NOSUCHSPLIT, "%s :No such split", "510" },
959 { ERR_SILELISTFULL, "%s :Your silence list is full", "511" },
961 diff -r 5ad24aad236d ircd/s_misc.c
962 --- a/ircd/s_misc.c Sat Jan 31 14:38:44 2009 +0100
963 +++ b/ircd/s_misc.c Sat Jan 31 15:25:32 2009 +0100
975 char comment1[HOSTLEN + HOSTLEN + 2];
976 + char splitreason[BUFSIZE];
978 if (MyConnect(victim))
981 sendto_opmask_butone(0, SNO_NETWORK, "Net break: %C %C (%s)",
982 cli_serv(victim)->up, victim, comment);
983 dump_map(victim, "*", 0, report_lost_links, 0);
984 + if (feature_bool(FEAT_SPLIT)) {
985 + /* TODO: remote & local SQUIT ? servername oper is on? */
986 + ircd_snprintf(0, splitreason, sizeof(splitreason),
987 + "Net break: %C %C (%s%s%s%s)", cli_serv(victim)->up, victim,
988 + IsUser(killer) ? "SQUIT by " : "", IsUser(killer) ? cli_name(killer) : "",
989 + IsUser(killer) ? ": " : "", comment);
990 + sendto_opmask_butone(0, SNO_NETWORK, "Created %d SPLIT entries.",
991 + split_netbreak(victim, splitreason));
996 diff -r 5ad24aad236d ircd/s_serv.c
997 --- a/ircd/s_serv.c Sat Jan 31 14:38:44 2009 +0100
998 +++ b/ircd/s_serv.c Sat Jan 31 15:25:32 2009 +0100
1006 #include "userload.h"
1011 + split_burst(cptr);
1012 welcome_burst(cptr);
1015 diff -r 5ad24aad236d ircd/s_stats.c
1016 --- a/ircd/s_stats.c Sat Jan 31 14:38:44 2009 +0100
1017 +++ b/ircd/s_stats.c Sat Jan 31 15:25:32 2009 +0100
1019 #include "s_stats.h"
1024 #include "userload.h"
1025 #include "welcome.h"
1026 @@ -669,7 +670,10 @@
1028 "System resource usage (Debug only)." },
1030 - { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM), FEAT_HIS_STATS_s,
1031 + { 'S', "splits", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_S,
1033 + "Server SPLITs information."},
1034 + { 's', "spoofhosts", (STAT_FLAG_OPERFEAT | STAT_FLAG_VARPARAM | STAT_FLAG_CASESENS), FEAT_HIS_STATS_s,
1036 "Spoofed hosts information." },
1037 { 'T', "motds", (STAT_FLAG_OPERFEAT | STAT_FLAG_CASESENS), FEAT_HIS_STATS_T,
1038 diff -r 5ad24aad236d ircd/split.c
1039 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1040 +++ b/ircd/split.c Sat Jan 31 15:25:32 2009 +0100
1043 + * IRC - Internet Relay Chat, ircd/split.c
1044 + * Copyright (C) 1990 Jarkko Oikarinen and
1045 + * University of Oulu, Finland
1046 + * Copyright (C) 2000 Kevin L. Mitchell <klmitch@mit.edu>
1048 + * This program is free software; you can redistribute it and/or modify
1049 + * it under the terms of the GNU General Public License as published by
1050 + * the Free Software Foundation; either version 1, or (at your option)
1051 + * any later version.
1053 + * This program is distributed in the hope that it will be useful,
1054 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1055 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1056 + * GNU General Public License for more details.
1058 + * You should have received a copy of the GNU General Public License
1059 + * along with this program; if not, write to the Free Software
1060 + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
1063 + * @brief Implementation of split server handling functions.
1065 +#include "config.h"
1068 +#include "client.h"
1071 +#include "ircd_alloc.h"
1072 +#include "ircd_features.h"
1073 +#include "ircd_log.h"
1074 +#include "ircd_reply.h"
1075 +#include "ircd_snprintf.h"
1076 +#include "ircd_string.h"
1080 +#include "numeric.h"
1081 +#include "numnicks.h"
1082 +#include "s_conf.h"
1084 +#include "s_debug.h"
1085 +#include "s_misc.h"
1087 +#include "struct.h"
1088 +#include "sys.h" /* FALSE bleah */
1090 +/* #include <assert.h> -- Now using assert in ircd_log.h */
1091 +#include <string.h>
1093 +/** List of split entries. */
1094 +static struct Split *GlobalSplitList = 0;
1096 +/** Allocate a new Split entry with the given parameters.
1097 + * @param[in] server Server name for split entry.
1098 + * @param[in] reason Reason for the split entry.
1099 + * @param[in] creation Creation time for split entry.
1100 + * @param[in] expire Expiration time for split entry.
1101 + * @param[in] lastmod Last modification time for split entry.
1102 + * @param[in] lifetime Life time for split entry.
1103 + * @param[in] flags Flags to set for the split entry.
1105 +static struct Split *
1106 +split_make(char *server, const char *reason,
1107 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1108 + unsigned int flags)
1110 + struct Split *asplit;
1111 + char sp_server[HOSTLEN+1];
1112 + char sp_reason[TOPICLEN+1];
1114 + /* alloc memory */
1115 + asplit = (struct Split*) MyMalloc(sizeof(struct Split));
1117 + /* we should have it now */
1118 + assert(0 != asplit);
1120 + memset(asplit, 0, sizeof(*asplit));
1121 + ircd_strncpy(sp_server, server, HOSTLEN);
1122 + DupString(asplit->sp_server, sp_server);
1123 + /* TODO: prefix the reason here with the opername/ID? */
1124 + ircd_strncpy(sp_reason, reason, TOPICLEN);
1125 + DupString(asplit->sp_reason, sp_reason);
1126 + asplit->sp_creation = creation;
1127 + asplit->sp_expire = expire;
1128 + asplit->sp_lastmod = lastmod;
1129 + asplit->sp_lifetime = lifetime;
1130 + /* set split flags - only save SPLIT_ACTIVE */
1131 + asplit->sp_flags = flags & SPLIT_ACTIVE;
1133 + /* link it into the list */
1134 + asplit->sp_next = GlobalSplitList;
1135 + asplit->sp_prev_p = &GlobalSplitList;
1136 + if (GlobalSplitList)
1137 + GlobalSplitList->sp_prev_p = &asplit->sp_next;
1138 + GlobalSplitList = asplit;
1144 +/** Forward a split entry to another server.
1145 + * @param[in] cptr Local client that sent us the split entry.
1146 + * @param[in] sptr Originator of the split entry.
1147 + * @param[in] split Split entry to forward.
1148 + * @param[in] reason Reason to send upstream (used by split_remove)
1151 +split_propagate(struct Client *cptr, struct Client *sptr,
1152 + struct Split *split, const char *reason)
1154 + sendcmdto_serv_butone(sptr, CMD_SPLIT, cptr, "%s%c%s %Tu %Tu %Tu %Tu :%s",
1155 + SplitIsRemoving(split) ? "!" : "",
1156 + SplitIsActive(split) && !SplitIsRemoving(split) ? '+' : '-', /* always !- not !+ */
1157 + split->sp_server, split->sp_creation, split->sp_expire,
1158 + split->sp_lastmod, split->sp_lifetime,
1159 + EmptyString(reason) ? split->sp_reason : reason);
1163 +/** Add a new server split entry.
1164 + * @param[in] cptr Local client that sent us the split entry.
1165 + * @param[in] sptr Originator of the split entry.
1166 + * @param[in] server Server name to split entry.
1167 + * @param[in] reason Reason for the split entry.
1168 + * @param[in] expire Expiration timestamp.
1169 + * @param[in] lastmod Last modification timestamp.
1170 + * @param[in] flags Flags to set on the split entry.
1174 +split_add(struct Client *cptr, struct Client *sptr, char *server, const char *reason,
1175 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1176 + unsigned int flags)
1179 + struct Split *split;
1180 + char noreason[BUFSIZE];
1181 + static time_t rate;
1183 + assert(NULL != cptr);
1184 + assert(NULL != sptr);
1185 + assert(NULL != server);
1186 + assert(NULL != reason);
1189 + Debug((DEBUG_DEBUG, "split_add(\"%s\", \"%s\", \"%s\", \"%s\", %Tu, %Tu, %Tu, "
1190 + "%Tu, 0x%04x)", cli_name(cptr), cli_name(sptr), server, reason,
1191 + creation, expire, lastmod, lifetime, flags));
1193 + /* not adding SPLIT for server that is linked
1194 + * if sptr is my user throw error
1195 + * otherwise ignore - SERVER and SPLIT messages can cross,
1196 + * or a server is bursting and it will see our end and destroy the SPLITs
1198 + if (FindServer(server)) {
1200 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1201 + "%C :SPLIT: Cannot add SPLIT %s - server is linked.", sptr, server);
1206 + * You cannot set a negative (or zero) duration, nor can you set an
1207 + * duration greater than SPLIT_MAX_EXPIRE.
1209 + if (expire - TStime() <= 0 || expire - TStime() > SPLIT_MAX_EXPIRE) {
1211 + return send_reply(cptr, ERR_BADEXPIRE, expire - TStime());
1212 + if (lifetime <= TStime()) /* no point going further */
1213 + /* CHECK: sptr may have the wrong idea about the nettime?
1214 + * or we could be wrong?
1215 + * perhaps raise some sort of warning to ops
1220 + /* empty reason */
1221 + if (EmptyString(reason))
1222 + ircd_snprintf(0, noreason, sizeof(noreason), "%C gave no reason.", sptr);
1224 + /* lastmod is more than SPLIT_MAX_DRIFT seconds ahead of our idea of time
1225 + * correct and warn ops
1227 + if (lastmod - TStime() > SPLIT_MAX_DRIFT) {
1228 + sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
1229 + "Possible timestamp drift from %C; lastmod in SPLIT message is %is ahead of time",
1230 + IsServer(sptr) ? sptr : cli_user(sptr)->server, lastmod - TStime());
1231 + lastmod = TStime() + SPLIT_MAX_DRIFT;
1234 + /* make the split entry */
1235 + split = split_make(server, EmptyString(reason) ? noreason : reason,
1236 + creation, expire, lastmod, lifetime, flags);
1238 + /* got to have it now */
1242 + sendto_opmask_butone(0, SNO_NETWORK, "%s adding%sSPLIT for %s, expiring at %Tu: %s",
1243 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1244 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
1245 + SplitIsActive(split) ? " " : " deactivated ",
1246 + split->sp_server, split->sp_expire, split->sp_reason);
1249 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1250 + "%#C adding%sSPLIT for %s, expiring at %Tu: %s",
1251 + sptr, SplitIsActive(split) ? " " : " deactivated ",
1252 + split->sp_server, split->sp_expire, split->sp_reason);
1254 + /* and propagate it */
1255 + split_propagate(cptr, sptr, split, NULL);
1261 +/** Modify a split entry.
1262 + * @param[in] cptr Client that sent us the split modification.
1263 + * @param[in] sptr Client that originated the split modification.
1264 + * @param[in] split Split entry being modified.
1265 + * @param[in] action Resultant status of the SPLIT.
1266 + * @param[in] reason Reason.
1267 + * @param[in] expire Expiration time.
1268 + * @param[in] lastmod Last modification time.
1269 + * @param[in] lifetime Lifetime.
1270 + * @param[in] flags Bitwise combination of SPLIT_* flags.
1274 +split_modify(struct Client *cptr, struct Client *sptr, struct Split *split,
1275 + enum SplitAction action, const char *reason,
1276 + time_t creation, time_t expire, time_t lastmod, time_t lifetime,
1277 + unsigned int flags)
1279 + char buf[BUFSIZE];
1280 + char sp_reason[TOPICLEN+1];
1282 + static time_t rate;
1284 + assert(NULL != cptr);
1285 + assert(NULL != sptr);
1286 + assert(NULL != split);
1289 + Debug((DEBUG_DEBUG, "split_modify(cptr \"%s\", sptr \"%s\", split \"%s\", reason \"%s\","
1290 + " action %d, creation %Tu, expire %Tu, lastmod %Tu, lifetime %Tu, flags 0x%04x)",
1291 + cli_name(cptr), cli_name(sptr), split->sp_server, reason, action,
1292 + creation, expire, lastmod, lifetime, flags));
1294 + /* not modifying SPLIT for server that is linked
1295 + * if sptr is my user throw error
1296 + * otherwise ignore - SERVER and SPLIT messages can cross.
1298 + * note: we cleanup SPLIT entries at end of burst,
1299 + * and not when a server is introduced.
1300 + * so between net junction and end of burst,
1301 + * we can get SPLITs for a linked server.
1302 + * also more than one server can be bursting at a time.
1304 + if (FindServer(split->sp_server)) {
1306 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1307 + "%C :SPLIT: Cannot modify SPLIT %s - server is linked.", sptr, split->sp_server);
1309 + /* SPLIT is not for a server part of a netmerge - free it */
1310 + if (!SplitIsBurst(split))
1311 + split_free(split);
1315 + /* check lastmod */
1316 + /* check if my oper modifies the SPLIT
1317 + * in which case use the greater of lastmod and split->sp_lastmod+1
1319 + * because if the lastmod of the split is in the future (greater than TStime())
1320 + * my oper cannot modify it when we use TStime() as lastmod
1321 + * therefore use split->sp_lastmod+1 - ugly hack, but the only way in that situation
1322 + * to modify it, apart from force removing it first..
1325 + lastmod = IRCD_MAX(lastmod, split->sp_lastmod + 1);
1326 + /* we have a more recent version */
1327 + if (split->sp_lastmod > lastmod) {
1328 + /* middle of a burst, it will resync on its own */
1329 + if (IsBurstOrBurstAck(cptr))
1331 + /* resync the server */
1332 + return split_resend(cptr, split);
1333 + /* same version */
1334 + } else if (split->sp_lastmod == lastmod)
1337 + /* lastmod is more than SPLIT_MAX_DRIFT seconds ahead of our idea of time
1338 + * correct and warn ops
1340 + * not in case it is my oper
1341 + * we use the lastmod of either TStime() or the lastmod we have plus 1 second
1344 + if (lastmod - TStime() > SPLIT_MAX_DRIFT && !MyUser(sptr)) {
1345 + sendto_opmask_butone_ratelimited(0, SNO_NETWORK, &rate,
1346 + "Possible timestamp drift from %C; lastmod in SPLIT message is %is ahead of time",
1347 + IsServer(sptr) ? sptr : cli_user(sptr)->server, lastmod - TStime());
1348 + lastmod = TStime() + SPLIT_MAX_DRIFT;
1351 + /* we got here so there is a change of some sort */
1353 + /* check out the expiration time */
1354 + if (flags & SPLIT_EXPIRE) {
1355 + if (expire != split->sp_expire) {
1356 + /* bad expiration time */
1357 + if (MyUser(sptr) && (expire < TStime() || expire - TStime() > SPLIT_MAX_EXPIRE))
1358 + return send_reply(sptr, ERR_BADEXPIRE, expire - TStime());
1359 + /* expire timestamp is in the past, so remap to deactivate */
1360 + if (expire < TStime() && action == SPLIT_ACTIVATE)
1361 + action = SPLIT_DEACTIVATE;
1363 + flags &= ~SPLIT_EXPIRE;
1366 + /* check out lifetime */
1367 + if (!(flags & SPLIT_LIFETIME) || !lifetime)
1368 + lifetime = split->sp_lifetime; /* use Split lifetime */
1370 + /* raise lifetime when required */
1371 + lifetime = IRCD_MAX(lifetime, expire);
1373 + /* SPLIT already expired with this lifetime */
1374 + if (lifetime - TStime() <= 0)
1377 + /* check if lifetime needs to be updated */
1378 + if (lifetime > split->sp_lifetime)
1379 + flags |= SPLIT_LIFETIME;
1381 + flags &= ~SPLIT_LIFETIME;
1385 + /* no changes to the reason - empty or the same */
1386 + if ((flags & SPLIT_REASON) &&
1387 + (EmptyString(reason) || !ircd_strcmp(split->sp_reason, reason)))
1388 + flags &= ~SPLIT_REASON;
1390 + /* no status change
1391 + * activate but split is active
1392 + * deactivate but split is deactivated
1393 + * expire timestamp is in the past so it should be deactivated
1394 + * and cannot be activated anymore
1396 + if ((action == SPLIT_ACTIVATE && SplitIsActive(split)) ||
1397 + (action == SPLIT_DEACTIVATE && !SplitIsActive(split)) ||
1398 + (IRCD_MAX(split->sp_expire, expire) <= TStime()))
1399 + action = SPLIT_MODIFY;
1402 + Debug((DEBUG_DEBUG, "About to perform changes; flags 0x%04x, action %s",
1403 + flags, action == SPLIT_ACTIVATE ? "SPLIT_ACTIVATE" :
1404 + (action == SPLIT_DEACTIVATE ? "SPLIT_DEACTIVATE" :
1405 + (action == SPLIT_MODIFY ? "SPLIT_MODIFY" : "<UNKNOWN>"))));
1407 + /* nothing to change at all */
1408 + if (!(flags & SPLIT_UPDATE) && action == SPLIT_MODIFY) {
1410 + sendcmdto_one(&me, CMD_NOTICE, sptr,
1411 + "%C :SPLIT: Cannot modify SPLIT %s - nothing to change.", sptr, split->sp_server);
1415 + /* update lastmod */
1416 + split->sp_lastmod = lastmod;
1419 + /* activating split entry */
1420 + if (action == SPLIT_ACTIVATE) {
1421 + split->sp_flags |= SPLIT_ACTIVE;
1422 + pos += ircd_snprintf(0, buf, sizeof(buf), " activating SPLIT");
1425 + /* deactivating split entry */
1426 + if (action == SPLIT_DEACTIVATE) {
1427 + split->sp_flags &= ~SPLIT_ACTIVE;
1428 + pos += ircd_snprintf(0, buf, sizeof(buf), " deactivating SPLIT");
1432 + /* update expire */
1433 + if (flags & SPLIT_EXPIRE) {
1434 + split->sp_expire = expire;
1435 + if (pos < BUFSIZE)
1436 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1437 + "%s%s changing expiration time to %Tu",
1439 + pos && !(flags & (SPLIT_LIFETIME | SPLIT_REASON)) ?
1440 + " and" : "", expire);
1443 + /* update lifetime */
1444 + if (flags & SPLIT_LIFETIME) {
1445 + split->sp_lifetime = lifetime;
1446 + if (pos < BUFSIZE)
1447 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1448 + "%s%s extending record lifetime to %Tu",
1449 + pos ? ";" : "", pos && !(flags & SPLIT_REASON) ?
1450 + " and" : "", lifetime);
1453 + /* update reason */
1454 + if (flags & SPLIT_REASON) {
1455 + MyFree(split->sp_reason);
1456 + ircd_strncpy(sp_reason, reason, TOPICLEN);
1457 + DupString(split->sp_reason, sp_reason);
1458 + if (pos < BUFSIZE)
1459 + pos += ircd_snprintf(0, buf + pos, sizeof(buf) - pos,
1460 + "%s%s changing reason to \"%s\"",
1461 + pos ? ";" : "", pos ? " and" : "", sp_reason);
1465 + sendto_opmask_butone(0, SNO_NETWORK, "%s modifying SPLIT for %s:%s",
1466 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1467 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
1468 + split->sp_server, buf);
1471 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1472 + "%#C modifying SPLIT for %s:%s",
1473 + sptr, split->sp_server, buf);
1475 + /* and propagate it */
1476 + split_propagate(cptr, sptr, split, NULL);
1482 +/** Remove a split entry.
1483 + * @param[in] cptr Local client that sent us the split entry.
1484 + * @param[in] sptr Originator of the split entry.
1485 + * @param[in] split Split entry to remove.
1486 + * @param[in] reason Reason for removing this split entry.
1490 +split_remove(struct Client *cptr, struct Client *sptr, struct Split *split, const char *reason)
1492 + assert(NULL != cptr);
1493 + assert(NULL != sptr);
1494 + assert(NULL != split);
1495 + assert(NULL != reason);
1498 + Debug((DEBUG_DEBUG, "split_remove(\"%s\", \"%s\", \"%s\", \"%s\")",
1499 + cli_name(cptr), cli_name(sptr), split->sp_server, reason));
1501 + /* deactivate entry and mark it for removal (used in split_propagate) */
1502 + split->sp_flags |= SPLIT_REMOVING;
1503 + split->sp_flags &= ~SPLIT_ACTIVE;
1506 + sendto_opmask_butone(0, SNO_NETWORK, "%s removing SPLIT for %s, expiring at %Tu: %s (%s)",
1507 + (feature_bool(FEAT_HIS_SNOTICES) || IsServer(sptr)) ?
1508 + get_client_name_and_opername(sptr) : cli_name((cli_user(sptr))->server),
1509 + split->sp_server, split->sp_expire, split->sp_reason, reason);
1512 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1513 + "%#C removing SPLIT for %s, expiring at %Tu: %s (%s)",
1514 + sptr, split->sp_server, split->sp_expire, split->sp_reason, reason);
1516 + /* propagate it */
1517 + split_propagate(cptr, sptr, split, reason);
1520 + split_free(split);
1526 +/** Find a split entry by name.
1527 + * @param[in] server Split entry name to search for.
1528 + * @return Matching split entry (or NULL if none match).
1531 +split_find(char *server)
1533 + struct Split* split;
1534 + struct Split* ssplit;
1536 + /* go over SPLITs */
1537 + for (split = GlobalSplitList; split; split = ssplit) {
1538 + ssplit = split->sp_next;
1540 + /* expire any that need expiring */
1541 + if (split_expire(split))
1542 + split_free(split);
1545 + else if (0 == ircd_strcmp(server, split->sp_server))
1549 + /* nothing found */
1554 +/** Unlink and free an unused split entry.
1555 + * @param[in] split Server split entry to free.
1558 +split_free(struct Split* split)
1560 + assert(NULL != split);
1562 + /* squeeze this split entry out */
1563 + *split->sp_prev_p = split->sp_next;
1564 + if (split->sp_next)
1565 + split->sp_next->sp_prev_p = split->sp_prev_p;
1567 + /* and free up the memory */
1568 + MyFree(split->sp_server);
1569 + MyFree(split->sp_reason);
1574 +/** Check whether a split entry has past its life time.
1575 + * when entry is active and past expire time, but not life time, deactivate it
1576 + * @param[in] split Server split entry to check.
1577 + * @return 1 when entry can be free'd, 0 otherwise.
1580 +split_expire(struct Split* split)
1582 + assert(NULL != split);
1584 + /* TODO: also check if the server in SPLIT entry is linked atm? */
1585 + /* past lifetime */
1586 + if (split->sp_lifetime <= TStime())
1589 + /* past expire time, deactivate entry if it is active */
1590 + if ((split->sp_expire <= TStime()) && SplitIsActive(split))
1591 + split->sp_flags &= ~SPLIT_ACTIVE;
1597 +/** Send the full list of split entries to \a cptr.
1598 + * @param[in] cptr Local server to send split entries to.
1601 +split_burst(struct Client *cptr)
1603 + struct Split *split;
1604 + struct Split *ssplit;
1606 + assert(NULL != cptr);
1608 + /* go over SPLITs */
1609 + for (split = GlobalSplitList; split; split = ssplit) {
1610 + ssplit = split->sp_next;
1612 + /* expire any that need expiring */
1613 + if (split_expire(split)) {
1614 + split_free(split);
1618 + /* if we have an entry for cptr, dont send it - but do not free here yet
1619 + * free it at end of burst, to get the correct count for SPLITs removed.
1621 + if (ircd_strcmp(split->sp_server, cli_name(cptr)) == 0)
1625 + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s",
1626 + SplitIsActive(split) ? '+' : '-', split->sp_server,
1627 + split->sp_creation, split->sp_expire,
1628 + split->sp_lastmod, split->sp_lifetime,
1629 + split->sp_reason);
1634 +/** Forward a split to another server.
1635 + * @param[in] cptr Server to send split entries to.
1636 + * @param[in] split Split to forward.
1640 +split_resend(struct Client *cptr, struct Split *split)
1642 + sendcmdto_one(&me, CMD_SPLIT, cptr, "%c%s %Tu %Tu %Tu %Tu :%s",
1643 + SplitIsActive(split) ? '+' : '-', split->sp_server,
1644 + split->sp_creation, split->sp_expire,
1645 + split->sp_lastmod, split->sp_lifetime,
1646 + split->sp_reason);
1652 +/** List split entries to a client.
1653 + * @param[in] sptr Client searching for split entries.
1654 + * @param[in] server Name of split entry to search for (if NULL, list all).
1658 +split_list(struct Client *sptr, char *server)
1660 + struct Split *split;
1663 + assert(NULL != sptr);
1665 + /* go through SPLITs */
1666 + for (split = GlobalSplitList; split; split = split->sp_next) {
1668 + /* expire any that need expiring */
1669 + if (split_expire(split)) {
1670 + split_free(split);
1674 + /* server given and does not match */
1675 + if (server && match(server, split->sp_server))
1680 + send_reply(sptr, RPL_SPLITLIST, split->sp_server,
1681 + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime,
1682 + SplitIsActive(split) ? '+' : '-', split->sp_reason);
1685 + /* server given and nothing found */
1686 + if (server && !count)
1687 + return send_reply(sptr, ERR_NOSUCHSPLIT, server);
1689 + /* end of splitlist information */
1690 + return send_reply(sptr, RPL_ENDOFSPLITLIST);
1694 +/** Mark SPLIT for new server with SPLIT_BURST
1695 + * @param[in] acptr Server introduced to the network
1698 +split_newserver(struct Client *acptr)
1700 + struct Split *split;
1702 + assert(NULL != acptr);
1705 + Debug((DEBUG_DEBUG, "split_newserver(\"%s\")", cli_name(acptr)));
1707 + /* mark the SPLIT with SPLIT_BURST
1708 + * so we know this SPLIT is marked for removal already
1709 + * but not remove it just yet to get the correct count
1710 + * of SPLITs removed at the end of burst.
1712 + * also we need the SPLIT in case the net breaks again
1713 + * before end of burst?
1715 + if ((split = split_find(cli_name(acptr))))
1716 + split->sp_flags |= SPLIT_BURST;
1720 +/** Auto destroy SPLITs for servers gained in a netmerge
1721 + * @param[in] sptr Server that has linked to the network
1722 + * @return Number of destroyed SPLITs
1725 +split_netmerge(struct Client *sptr)
1728 + struct Split *split;
1731 + assert(NULL != sptr);
1734 + Debug((DEBUG_DEBUG, "split_netmerge(\"%s\")", cli_name(sptr)));
1736 + /* find the SPLIT for this server */
1737 + if ((split = split_find(cli_name(sptr)))) {
1738 + split_free(split);
1742 + /* go over its downlinks */
1743 + for (lp = cli_serv(sptr)->down; lp; lp = lp->next)
1744 + count += split_netmerge(lp->value.cptr);
1746 + /* return the number of SPLITs removed */
1751 +/** Auto create SPLITs for servers lost in a netbreak
1752 + * @param[in] victim Server that lost link to network
1753 + * @param[in] reason Reason to add to SPLITs
1754 + * @return Number of created SPLITs
1757 +split_netbreak(struct Client *victim, const char *reason)
1760 + struct Split *split;
1762 + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE),
1763 + lastmod = TStime(), lifetime = expire;
1764 + unsigned int flags = SPLIT_ACTIVE;
1766 + assert(NULL != victim);
1769 + Debug((DEBUG_DEBUG, "split_netbreak(\"%s\", \"%s\")", cli_name(victim), reason));
1771 + /* bad auto expire value */
1772 + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0)
1775 + /* TODO: what if we do have a SPLIT for this server?
1776 + * we remove splits in end of burst
1777 + * and if the netbreaks again before that
1778 + * free the SPLIT and create a new one?
1779 + * or simply update lastmod/lifetime/reason but leave the status?
1781 + /* find the SPLIT for this server */
1782 + if (!(split = split_find(cli_name(victim)))) {
1783 + split_make(cli_name(victim), reason, creation, expire, lastmod, lifetime, flags);
1786 + /* clear the burst flag for it */
1787 + split->sp_flags &= SPLIT_BURST;
1789 + /* go over its downlinks */
1790 + for (lp = cli_serv(victim)->down; lp; lp = lp->next)
1791 + count += split_netbreak(lp->value.cptr, reason);
1793 + /* return the number of SPLITs created */
1798 +/** Auto create SPLITs for servers we have a Connect Block for
1804 + struct ConfItem *conf;
1805 + struct Split *split;
1806 + time_t creation = TStime(), expire = TStime() + feature_int(FEAT_SPLIT_AUTO_EXPIRE),
1807 + lastmod = TStime(), lifetime = expire;
1808 + unsigned int flags = SPLIT_ACTIVE;
1809 + char reason[BUFSIZE];
1812 + Debug((DEBUG_DEBUG, "split_conf()"));
1814 + /* we are not set to generate SPLITs */
1815 + if (!feature_bool(FEAT_SPLIT))
1818 + /* TODO: log this problem? */
1819 + /* bad auto expire value */
1820 + if (feature_int(FEAT_SPLIT_AUTO_EXPIRE) <= 0)
1823 + ircd_snprintf(0, reason, sizeof(reason),
1824 + "Generated upon loading conf file on %C", &me);
1826 + /* go over the conf contents */
1827 + for (conf = GlobalConfList; conf; conf = conf->next) {
1829 + /* not a Connect Block */
1830 + if (CONF_SERVER != conf->status)
1833 + /* server is linked */
1834 + if (FindServer(conf->name))
1837 + /* we have a SPLIT for this server already */
1838 + if (split_find(conf->name))
1841 + /* TODO: use SNO_OLDSNO here?
1842 + * just like nickcollisions on local users go there?
1843 + * or at least change the source / message format?
1844 + * /REHASH goes to SNO_OLDSNO? so this too?
1845 + * if oper did rehash, add his name here?
1848 + sendto_opmask_butone(0, SNO_NETWORK, "%C adding SPLIT for %s, expiring at %Tu: %s",
1849 + &me, conf->name, expire, reason);
1852 + log_write(LS_SPLIT, L_INFO, LOG_NOSNOTICE,
1853 + "%C adding SPLIT for %s, expiring at %Tu: %s",
1854 + &me, conf->name, expire, reason);
1856 + /* make the split entry */
1857 + split = split_make(conf->name, reason, creation, expire, lastmod, lifetime, flags);
1859 + /* got to have it now */
1862 + /* and propagate it */
1863 + split_propagate(&me, &me, split, NULL);
1868 +/** Statistics callback to list SPLITs.
1869 + * @param[in] sptr Client requesting statistics.
1870 + * @param[in] sd Stats descriptor for request (ignored).
1871 + * @param[in] param Extra parameter from user (ignored).
1874 +split_stats(struct Client *sptr, const struct StatDesc *sd, char *param)
1876 + struct Split *split;
1878 + /* send header so the client knows what we are showing */
1879 + send_reply(sptr, SND_EXPLICIT | RPL_STATSHEADER,
1880 + "S Server Creation Expire Lastmod Lifetime Status :Reason");
1882 + /* go over SPLIT entries */
1883 + for (split = GlobalSplitList; split; split = split->sp_next) {
1885 + /* does not match */
1886 + if (param && match(param, split->sp_server))
1890 + send_reply(sptr, RPL_STATSSPLIT, split->sp_server,
1891 + split->sp_creation, split->sp_expire, split->sp_lastmod, split->sp_lifetime,
1892 + SplitIsActive(split) ? '+' : '-', split->sp_reason);
1897 +/** Count split entries and memory used by them.
1898 + * @param[out] sp_size Receives total number of bytes allocated for split entries.
1899 + * @return Number of split entries currently allocated.
1902 +split_memory_count(size_t *sp_size)
1904 + struct Split *split;
1905 + unsigned int sp = 0;
1907 + for (split = GlobalSplitList; split; split = split->sp_next) {
1909 + *sp_size += sizeof(struct Split);
1910 + *sp_size += split->sp_server ? (strlen(split->sp_server) + 1) : 0;
1911 + *sp_size += split->sp_reason ? (strlen(split->sp_reason) + 1) : 0;