ViewVC Help
View File | Revision Log | Show Annotations | View Changeset | Root Listing
root/svn/ircd-hybrid-7.2/modules/m_stats.c
Revision: 1011
Committed: Fri Sep 18 10:14:09 2009 UTC (14 years, 6 months ago) by michael
Content type: text/x-csrc
File size: 47808 byte(s)
Log Message:
- move list manipulation routines from tools.c to list.c
- mem_frob() goes to memory.c
- sort out redundant/unneeded header includes

File Contents

# Content
1 /*
2 * ircd-hybrid: an advanced Internet Relay Chat Daemon(ircd).
3 * m_stats.c: Sends the user statistics or config information.
4 *
5 * Copyright (C) 2002 by the past and present ircd coders, and others.
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307
20 * USA
21 *
22 * $Id$
23 */
24
25 #include "stdinc.h"
26 #include "list.h" /* dlink_node/dlink_list */
27 #include "balloc.h"
28 #include "handlers.h" /* m_pass prototype */
29 #include "client.h" /* Client */
30 #include "common.h" /* TRUE/FALSE */
31 #include "irc_string.h"
32 #include "ircd.h" /* me */
33 #include "listener.h" /* show_ports */
34 #include "s_gline.h"
35 #include "ircd_handler.h"
36 #include "msg.h" /* Message */
37 #include "hostmask.h"
38 #include "numeric.h" /* ERR_xxx */
39 #include "send.h" /* sendto_one */
40 #include "fdlist.h" /* PF and friends */
41 #include "s_bsd.h" /* highest_fd */
42 #include "s_conf.h" /* AccessItem, report_configured_links */
43 #include "s_misc.h" /* serv_info */
44 #include "s_serv.h" /* hunt_server */
45 #include "s_user.h" /* show_opers */
46 #include "event.h" /* events */
47 #include "dbuf.h"
48 #include "parse.h"
49 #include "modules.h"
50 #include "hook.h"
51 #include "resv.h" /* report_resv */
52 #include "whowas.h"
53 #include "watch.h"
54
55 static void do_stats(struct Client *, int, char **);
56 static void m_stats(struct Client *, struct Client *, int, char *[]);
57 static void mo_stats(struct Client *, struct Client *, int, char *[]);
58 static void ms_stats(struct Client *, struct Client *, int, char *[]);
59
60 struct Message stats_msgtab = {
61 "STATS", 0, 0, 2, 0, MFLG_SLOW, 0,
62 { m_unregistered, m_stats, ms_stats, m_ignore, mo_stats, m_ignore }
63 };
64
65 #ifndef STATIC_MODULES
66 const char *_version = "$Revision$";
67 static struct Callback *stats_cb;
68
69 static void *
70 va_stats(va_list args)
71 {
72 struct Client *source_p = va_arg(args, struct Client *);
73 int parc = va_arg(args, int);
74 char **parv = va_arg(args, char **);
75
76 do_stats(source_p, parc, parv);
77 return NULL;
78 }
79
80 void
81 _modinit(void)
82 {
83 stats_cb = register_callback("doing_stats", va_stats);
84 mod_add_cmd(&stats_msgtab);
85 }
86
87 void
88 _moddeinit(void)
89 {
90 mod_del_cmd(&stats_msgtab);
91 uninstall_hook(stats_cb, va_stats);
92 }
93 #endif
94
95 static char *parse_stats_args(int, char **, int *, int *);
96 static void stats_L(struct Client *, char *, int, int, char);
97 static void stats_L_list(struct Client *s, char *, int, int, dlink_list *, char);
98
99 static void stats_dns_servers(struct Client *);
100 static void stats_connect(struct Client *);
101 static void stats_deny(struct Client *);
102 static void stats_tdeny(struct Client *);
103 static void stats_exempt(struct Client *);
104 static void stats_events(struct Client *);
105 static void stats_pending_glines(struct Client *);
106 static void stats_glines(struct Client *);
107 static void stats_gdeny(struct Client *);
108 static void stats_hubleaf(struct Client *);
109 static void stats_auth(struct Client *);
110 static void stats_tklines(struct Client *);
111 static void stats_klines(struct Client *);
112 static void stats_messages(struct Client *);
113 static void stats_oper(struct Client *);
114 static void stats_operedup(struct Client *);
115 static void stats_ports(struct Client *);
116 static void stats_resv(struct Client *);
117 static void stats_usage(struct Client *);
118 static void stats_tstats(struct Client *);
119 static void stats_uptime(struct Client *);
120 static void stats_shared(struct Client *);
121 static void stats_servers(struct Client *);
122 static void stats_gecos(struct Client *);
123 static void stats_class(struct Client *);
124 static void stats_memory(struct Client *);
125 static void stats_servlinks(struct Client *);
126 static void stats_ltrace(struct Client *, int, char **);
127 static void stats_ziplinks(struct Client *);
128
129 /* This table contains the possible stats items, in order:
130 * /stats name, function to call, operonly? adminonly? /stats letter
131 * case only matters in the stats letter column.. -- fl_ */
132 static const struct StatsStruct
133 {
134 const unsigned char letter;
135 void (*handler)();
136 const unsigned int need_oper;
137 const unsigned int need_admin;
138 } stats_cmd_table[] = {
139 /* letter function need_oper need_admin */
140 { 'a', stats_dns_servers, 1, 1, },
141 { 'A', stats_dns_servers, 1, 1, },
142 { 'c', stats_connect, 1, 0, },
143 { 'C', stats_connect, 1, 0, },
144 { 'd', stats_tdeny, 1, 0, },
145 { 'D', stats_deny, 1, 0, },
146 { 'e', stats_exempt, 1, 0, },
147 { 'E', stats_events, 1, 1, },
148 { 'f', fd_dump, 1, 1, },
149 { 'F', fd_dump, 1, 1, },
150 { 'g', stats_pending_glines, 1, 0, },
151 { 'G', stats_glines, 1, 0, },
152 { 'h', stats_hooks, 1, 1, },
153 { 'H', stats_hubleaf, 1, 0, },
154 { 'i', stats_auth, 0, 0, },
155 { 'I', stats_auth, 0, 0, },
156 { 'k', stats_tklines, 0, 0, },
157 { 'K', stats_klines, 0, 0, },
158 { 'l', stats_ltrace, 1, 0, },
159 { 'L', stats_ltrace, 1, 0, },
160 { 'm', stats_messages, 0, 0, },
161 { 'M', stats_messages, 0, 0, },
162 { 'o', stats_oper, 0, 0, },
163 { 'O', stats_oper, 0, 0, },
164 { 'p', stats_operedup, 0, 0, },
165 { 'P', stats_ports, 0, 0, },
166 { 'q', stats_resv, 1, 0, },
167 { 'Q', stats_resv, 1, 0, },
168 { 'r', stats_usage, 1, 0, },
169 { 'R', stats_usage, 1, 0, },
170 { 't', stats_tstats, 1, 0, },
171 { 'T', stats_tstats, 1, 0, },
172 { 'u', stats_uptime, 0, 0, },
173 { 'U', stats_shared, 1, 0, },
174 { 'v', stats_servers, 1, 0, },
175 { 'V', stats_gdeny, 1, 0, },
176 { 'x', stats_gecos, 1, 0, },
177 { 'X', stats_gecos, 1, 0, },
178 { 'y', stats_class, 1, 0, },
179 { 'Y', stats_class, 1, 0, },
180 { 'z', stats_memory, 1, 0, },
181 { 'Z', stats_ziplinks, 1, 0, },
182 { '?', stats_servlinks, 0, 0, },
183 { '\0', NULL, 0, 0, }
184 };
185
186 const char *from, *to;
187
188 static void
189 do_stats(struct Client *source_p, int parc, char **parv)
190 {
191 char statchar = *parv[1];
192 int i;
193
194 if (statchar == '\0')
195 {
196 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
197 from, to, '*');
198 return;
199 }
200
201 for (i = 0; stats_cmd_table[i].handler; i++)
202 {
203 if (stats_cmd_table[i].letter == statchar)
204 {
205 /* The stats table says what privs are needed, so check --fl_ */
206 if ((stats_cmd_table[i].need_admin && !IsAdmin(source_p)) ||
207 (stats_cmd_table[i].need_oper && !IsOper(source_p)))
208 {
209 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
210 from, to);
211 break;
212 }
213
214 /* Blah, stats L needs the parameters, none of the others do.. */
215 if (statchar == 'L' || statchar == 'l')
216 stats_cmd_table[i].handler(source_p, parc, parv);
217 else
218 stats_cmd_table[i].handler(source_p);
219
220 break;
221 }
222 }
223
224 sendto_one(source_p, form_str(RPL_ENDOFSTATS),
225 from, to, statchar);
226 }
227
228 /*
229 * m_stats()
230 * parv[0] = sender prefix
231 * parv[1] = stat letter/command
232 * parv[2] = (if present) server/mask in stats L
233 *
234 * This will search the tables for the appropriate stats letter/command,
235 * if found execute it.
236 */
237 static void
238 m_stats(struct Client *client_p, struct Client *source_p,
239 int parc, char *parv[])
240 {
241 static time_t last_used = 0;
242
243 /* Is the stats meant for us? */
244 if (!ConfigFileEntry.disable_remote)
245 if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv) != HUNTED_ISME)
246 return;
247
248 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
249 {
250 from = me.id;
251 to = source_p->id;
252 }
253 else
254 {
255 from = me.name;
256 to = source_p->name;
257 }
258
259 /* Check the user is actually allowed to do /stats, and isnt flooding */
260 if ((last_used + ConfigFileEntry.pace_wait) > CurrentTime)
261 {
262 sendto_one(source_p,form_str(RPL_LOAD2HI),
263 from, to);
264 return;
265 }
266 else
267 last_used = CurrentTime;
268
269 #ifdef STATIC_MODULES
270 do_stats(source_p, parc, parv);
271 #else
272 execute_callback(stats_cb, source_p, parc, parv);
273 #endif
274 }
275
276 /*
277 * mo_stats()
278 * parv[0] = sender prefix
279 * parv[1] = stat letter/command
280 * parv[2] = (if present) server/mask in stats L, or target
281 *
282 * This will search the tables for the appropriate stats letter,
283 * if found execute it.
284 */
285 static void
286 mo_stats(struct Client *client_p, struct Client *source_p,
287 int parc, char *parv[])
288 {
289 if (hunt_server(client_p, source_p, ":%s STATS %s :%s", 2,
290 parc, parv) != HUNTED_ISME)
291 return;
292
293 if (!MyClient(source_p) && IsCapable(source_p->from, CAP_TS6) && HasID(source_p))
294 {
295 from = me.id;
296 to = source_p->id;
297 }
298 else
299 {
300 from = me.name;
301 to = source_p->name;
302 }
303
304 #ifdef STATIC_MODULES
305 do_stats(source_p, parc, parv);
306 #else
307 execute_callback(stats_cb, source_p, parc, parv);
308 #endif
309 }
310
311 /*
312 * This is part of the STATS replies. There is no offical numeric for this
313 * since this isnt an official command, in much the same way as HASH isnt.
314 * It is also possible that some systems wont support this call or have
315 * different field names for "struct rusage".
316 * -avalon
317 */
318 static void
319 send_usage(struct Client *source_p)
320 {
321 struct rusage rus;
322 time_t secs;
323 time_t rup;
324 #ifdef hz
325 # define hzz hz
326 #else
327 # ifdef HZ
328 # define hzz HZ
329 # else
330 int hzz = 1;
331 # endif
332 #endif
333
334 if (getrusage(RUSAGE_SELF, &rus) == -1)
335 {
336 sendto_one(source_p, ":%s NOTICE %s :Getruseage error: %s",
337 me.name, source_p->name, strerror(errno));
338 return;
339 }
340
341 secs = rus.ru_utime.tv_sec + rus.ru_stime.tv_sec;
342
343 if (secs == 0)
344 secs = 1;
345
346 rup = (CurrentTime - me.since) * hzz;
347
348 if (rup == 0)
349 rup = 1;
350
351 sendto_one(source_p,
352 ":%s %d %s R :CPU Secs %d:%d User %d:%d System %d:%d",
353 me.name, RPL_STATSDEBUG, source_p->name, (int)(secs/60), (int)(secs%60),
354 (int)(rus.ru_utime.tv_sec/60), (int)(rus.ru_utime.tv_sec%60),
355 (int)(rus.ru_stime.tv_sec/60), (int)(rus.ru_stime.tv_sec%60));
356 sendto_one(source_p, ":%s %d %s R :RSS %ld ShMem %ld Data %ld Stack %ld",
357 me.name, RPL_STATSDEBUG, source_p->name, rus.ru_maxrss,
358 (rus.ru_ixrss / rup), (rus.ru_idrss / rup),
359 (rus.ru_isrss / rup));
360 sendto_one(source_p, ":%s %d %s R :Swaps %d Reclaims %d Faults %d",
361 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nswap,
362 (int)rus.ru_minflt, (int)rus.ru_majflt);
363 sendto_one(source_p, ":%s %d %s R :Block in %d out %d",
364 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_inblock,
365 (int)rus.ru_oublock);
366 sendto_one(source_p, ":%s %d %s R :Msg Rcv %d Send %d",
367 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_msgrcv,
368 (int)rus.ru_msgsnd);
369 sendto_one(source_p, ":%s %d %s R :Signals %d Context Vol. %d Invol %d",
370 me.name, RPL_STATSDEBUG, source_p->name, (int)rus.ru_nsignals,
371 (int)rus.ru_nvcsw, (int)rus.ru_nivcsw);
372 }
373
374 static void
375 count_memory(struct Client *source_p)
376 {
377 const dlink_node *gptr = NULL;
378 const dlink_node *dlink = NULL;
379
380 unsigned int local_client_conf_count = 0; /* local client conf links */
381 unsigned int users_counted = 0; /* user structs */
382
383 unsigned int channel_users = 0; /* XXX */
384 unsigned int channel_invites = 0;
385 unsigned int channel_bans = 0;
386 unsigned int channel_except = 0;
387 unsigned int channel_invex = 0;
388
389 unsigned int wwu = 0; /* whowas users */
390 unsigned int class_count = 0; /* classes */
391 unsigned int aways_counted = 0;
392 unsigned int number_ips_stored; /* number of ip addresses hashed */
393
394 uint64_t channel_memory = 0;
395 uint64_t channel_ban_memory = 0;
396 uint64_t channel_except_memory = 0;
397 uint64_t channel_invex_memory = 0;
398
399 unsigned int safelist_count = 0;
400 uint64_t safelist_memory = 0;
401
402 uint64_t away_memory = 0; /* memory used by aways */
403 uint64_t wwm = 0; /* whowas array memory used */
404 uint64_t conf_memory = 0; /* memory used by conf lines */
405 uint64_t mem_ips_stored; /* memory used by ip address hash */
406
407 uint64_t client_hash_table_size = 0;
408 uint64_t channel_hash_table_size = 0;
409 uint64_t resv_hash_table_size = 0;
410 uint64_t id_hash_table_size = 0;
411 uint64_t total_channel_memory = 0;
412 uint64_t totww = 0;
413
414 unsigned int local_client_count = 0;
415 unsigned int remote_client_count = 0;
416
417 uint64_t local_client_memory_used = 0;
418 uint64_t remote_client_memory_used = 0;
419
420 uint64_t total_memory = 0;
421 unsigned int topic_count = 0;
422
423 unsigned int wlh = 0; /* watchlist headers */
424 unsigned int wle = 0; /* watchlist entries */
425 uint64_t wlhm = 0; /* watchlist memory used */
426
427 count_whowas_memory(&wwu, &wwm);
428
429 DLINK_FOREACH(gptr, global_client_list.head)
430 {
431 struct Client *target_p = gptr->data;
432
433 if (MyConnect(target_p))
434 {
435 ++local_client_count;
436 local_client_conf_count += dlink_list_length(&target_p->localClient->confs);
437 wle += dlink_list_length(&target_p->localClient->watches);
438 }
439 else
440 ++remote_client_count;
441
442 if (IsClient(target_p))
443 {
444 ++users_counted;
445
446 if (target_p->away != NULL)
447 {
448 ++aways_counted;
449 away_memory += strlen(target_p->away) + 1;
450 }
451 }
452 }
453
454 /* Count up all channels, ban lists, except lists, Invex lists */
455 channel_memory = dlink_list_length(&global_channel_list) *
456 sizeof(struct Channel);
457 DLINK_FOREACH(gptr, global_channel_list.head)
458 {
459 const struct Ban *actualBan;
460 const struct Channel *chptr = gptr->data;
461
462 channel_users += dlink_list_length(&chptr->members);
463 channel_invites += dlink_list_length(&chptr->invites);
464
465 if (chptr->topic != NULL)
466 ++topic_count;
467
468 if ((channel_bans = dlink_list_length(&chptr->banlist)))
469 {
470 channel_ban_memory = channel_bans * sizeof(struct Ban);
471
472 DLINK_FOREACH(dlink, chptr->banlist.head)
473 {
474 actualBan = dlink->data;
475 assert(actualBan->who);
476
477 channel_ban_memory += actualBan->len + 3;
478 channel_ban_memory += strlen(actualBan->who) + 1;
479 }
480 }
481
482 if ((channel_except = dlink_list_length(&chptr->exceptlist)))
483 {
484 channel_except_memory = channel_except * sizeof(struct Ban);
485
486 DLINK_FOREACH(dlink, chptr->exceptlist.head)
487 {
488 actualBan = dlink->data;
489 assert(actualBan->who);
490
491 channel_except_memory += actualBan->len + 3;
492 channel_except_memory += strlen(actualBan->who) + 1;
493 }
494 }
495
496 if ((channel_invex = dlink_list_length(&chptr->invexlist)))
497 {
498 channel_invex_memory = channel_invex * sizeof(struct Ban);
499
500 DLINK_FOREACH(dlink, chptr->invexlist.head)
501 {
502 actualBan = dlink->data;
503 assert(actualBan->who);
504
505 channel_invex_memory += actualBan->len + 3;
506 channel_invex_memory += strlen(actualBan->who) + 1;
507 }
508 }
509 }
510
511 if ((safelist_count = dlink_list_length(&listing_client_list)))
512 {
513 safelist_memory = safelist_count * sizeof(struct ListTask);
514 DLINK_FOREACH(gptr, listing_client_list.head)
515 {
516 const struct Client *acptr = gptr->data;
517
518 DLINK_FOREACH(dlink, acptr->localClient->list_task->show_mask.head)
519 safelist_memory += strlen(dlink->data);
520
521 DLINK_FOREACH(dlink, acptr->localClient->list_task->hide_mask.head)
522 safelist_memory += strlen(dlink->data);
523 }
524 }
525
526 #if 0
527 /* XXX THIS has to be fixed !!!! -db */
528 /* count up all config items */
529 DLINK_FOREACH(dlink, ConfigItemList.head)
530 {
531 aconf = dlink->data;
532 conf_memory += aconf->host ? strlen(aconf->host)+1 : 0;
533 conf_memory += aconf->passwd ? strlen(aconf->passwd)+1 : 0;
534 conf_memory += aconf->name ? strlen(aconf->name)+1 : 0;
535 conf_memory += sizeof(struct AccessItem);
536 }
537 #endif
538 /* count up all classes */
539 class_count = dlink_list_length(&class_items);
540
541 watch_count_memory(&wlh, &wlhm);
542
543 sendto_one(source_p, ":%s %d %s z :WATCH headers %u(%u) entries %d(%d)",
544 me.name, RPL_STATSDEBUG, source_p->name, wlh, wlhm, wle,
545 wle * sizeof(dlink_node));
546
547 sendto_one(source_p, ":%s %d %s z :Clients %u(%u)",
548 me.name, RPL_STATSDEBUG, source_p->name, users_counted,
549 (users_counted * sizeof(struct Client)));
550
551 sendto_one(source_p, ":%s %d %s z :User aways %u(%llu)",
552 me.name, RPL_STATSDEBUG, source_p->name,
553 aways_counted, away_memory);
554
555 sendto_one(source_p, ":%s %d %s z :Attached confs %u(%llu)",
556 me.name, RPL_STATSDEBUG, source_p->name,
557 local_client_conf_count,
558 (unsigned long long)(local_client_conf_count * sizeof(dlink_node)));
559
560 /* XXX ConfigItemList fix */
561 #if 0
562 sendto_one(source_p, ":%s %d %s z :Conflines %lu(%d)",
563 me.name, RPL_STATSDEBUG, source_p->name,
564 dlink_list_length(&ConfigItemList), (int) conf_memory);
565 #endif
566
567 sendto_one(source_p, ":%s %d %s z :Resv channels %lu(%lu) nicks %lu(%lu)",
568 me.name, RPL_STATSDEBUG, source_p->name,
569 dlink_list_length(&resv_channel_list),
570 dlink_list_length(&resv_channel_list) * sizeof(struct ResvChannel),
571 dlink_list_length(&nresv_items),
572 dlink_list_length(&nresv_items) * sizeof(struct MatchItem));
573
574 sendto_one(source_p, ":%s %d %s z :Classes %u(%llu)",
575 me.name, RPL_STATSDEBUG, source_p->name,
576 class_count, (unsigned long long)(class_count * sizeof(struct ClassItem)));
577
578 sendto_one(source_p, ":%s %d %s z :Channels %lu(%llu) Topics %u(%d)",
579 me.name, RPL_STATSDEBUG, source_p->name,
580 dlink_list_length(&global_channel_list),
581 channel_memory, topic_count, topic_count *
582 (TOPICLEN + 1 + USERHOST_REPLYLEN));
583
584 sendto_one(source_p, ":%s %d %s z :Bans %u(%llu)",
585 me.name, RPL_STATSDEBUG, source_p->name,
586 channel_bans, channel_ban_memory);
587
588 sendto_one(source_p, ":%s %d %s z :Exceptions %u(%llu)",
589 me.name, RPL_STATSDEBUG, source_p->name,
590 channel_except, channel_except_memory);
591
592 sendto_one(source_p, ":%s %d %s z :Invex %u(%llu)",
593 me.name, RPL_STATSDEBUG, source_p->name,
594 channel_invex, channel_invex_memory);
595
596 sendto_one(source_p, ":%s %d %s z :Channel members %u(%llu) invites %u(%llu)",
597 me.name, RPL_STATSDEBUG, source_p->name, channel_users,
598 (unsigned long long)(channel_users * sizeof(struct Membership)),
599 channel_invites, (unsigned long long)channel_invites *
600 sizeof(dlink_node) * 2);
601
602 total_channel_memory = channel_memory + channel_ban_memory +
603 channel_users * sizeof(struct Membership) +
604 (channel_invites * sizeof(dlink_node)*2);
605
606 sendto_one(source_p, ":%s %d %s z :Safelist %u(%llu)",
607 me.name, RPL_STATSDEBUG, source_p->name,
608 safelist_count, safelist_memory);
609
610 sendto_one(source_p, ":%s %d %s z :Whowas users %u(%llu)",
611 me.name, RPL_STATSDEBUG, source_p->name,
612 wwu, (unsigned long long)(wwu * sizeof(struct Client)));
613
614 sendto_one(source_p, ":%s %d %s z :Whowas array %u(%llu)",
615 me.name, RPL_STATSDEBUG, source_p->name,
616 NICKNAMEHISTORYLENGTH, wwm);
617
618 totww = wwu * sizeof(struct Client) + wwm;
619 /****
620 client_hash_table_size = hash_get_client_table_size();
621 channel_hash_table_size = hash_get_channel_table_size();
622 resv_hash_table_size = hash_get_resv_table_size();
623 id_hash_table_size = hash_get_id_table_size();
624
625 sendto_one(source_p, ":%s %d %s z :Hash: client %u(%lu) chan %u(%lu) resv "
626 "%u(%lu) id %u(%lu)",
627 me.name, RPL_STATSDEBUG, source_p->name,
628 U_MAX, client_hash_table_size,
629 CH_MAX, channel_hash_table_size , R_MAX,
630 resv_hash_table_size, U_MAX, id_hash_table_size);
631 ****/
632 count_ip_hash(&number_ips_stored,&mem_ips_stored);
633 sendto_one(source_p, ":%s %d %s z :iphash %u(%llu)",
634 me.name, RPL_STATSDEBUG, source_p->name,
635 number_ips_stored, mem_ips_stored);
636
637 total_memory = totww + total_channel_memory + conf_memory + class_count *
638 sizeof(struct ClassItem);
639 total_memory += client_hash_table_size;
640 total_memory += channel_hash_table_size;
641 total_memory += resv_hash_table_size;
642 total_memory += id_hash_table_size;
643
644 sendto_one(source_p, ":%s %d %s z :Total: whowas %llu channel %llu conf %llu",
645 me.name, RPL_STATSDEBUG, source_p->name, totww,
646 total_channel_memory, conf_memory);
647
648 local_client_memory_used = local_client_count*(sizeof(struct Client) + sizeof(struct LocalUser));
649 total_memory += local_client_memory_used;
650 sendto_one(source_p, ":%s %d %s z :Local client Memory in use: %d(%llu)",
651 me.name, RPL_STATSDEBUG, source_p->name, local_client_count,
652 local_client_memory_used);
653
654 remote_client_memory_used = remote_client_count * sizeof(struct Client);
655 total_memory += remote_client_memory_used;
656 sendto_one(source_p, ":%s %d %s z :Remote client Memory in use: %d(%llu)",
657 me.name, RPL_STATSDEBUG, source_p->name, remote_client_count,
658 remote_client_memory_used);
659
660 block_heap_report_stats(source_p);
661
662 sendto_one(source_p,
663 ":%s %d %s z :TOTAL: %llu",
664 me.name, RPL_STATSDEBUG, source_p->name,
665 total_memory);
666 }
667
668 static void
669 stats_dns_servers(struct Client *source_p)
670 {
671 report_dns_servers(source_p);
672 }
673
674 static void
675 stats_connect(struct Client *source_p)
676 {
677 report_confitem_types(source_p, SERVER_TYPE, 0);
678 }
679
680 /* stats_deny()
681 *
682 * input - client to report to
683 * output - none
684 * side effects - client is given dline list.
685 */
686 static void
687 stats_deny(struct Client *source_p)
688 {
689 struct AddressRec *arec;
690 struct ConfItem *conf;
691 struct AccessItem *aconf;
692 int i;
693
694 for (i = 0; i < ATABLE_SIZE; i++)
695 {
696 for (arec = atable[i]; arec; arec=arec->next)
697 {
698 if (arec->type == CONF_DLINE)
699 {
700 aconf = arec->aconf;
701
702 /* dont report a tdline as a dline */
703 if (aconf->flags & CONF_FLAGS_TEMPORARY)
704 continue;
705
706 conf = unmap_conf_item(aconf);
707
708 sendto_one(source_p, form_str(RPL_STATSDLINE),
709 from, to, 'D', aconf->host, aconf->reason,
710 aconf->oper_reason);
711 }
712 }
713 }
714 }
715
716 /* stats_tdeny()
717 *
718 * input - client to report to
719 * output - none
720 * side effects - client is given dline list.
721 */
722 static void
723 stats_tdeny(struct Client *source_p)
724 {
725 struct AddressRec *arec;
726 struct ConfItem *conf;
727 struct AccessItem *aconf;
728 int i;
729
730 for (i = 0; i < ATABLE_SIZE; i++)
731 {
732 for (arec = atable[i]; arec; arec=arec->next)
733 {
734 if (arec->type == CONF_DLINE)
735 {
736 aconf = arec->aconf;
737
738 /* dont report a permanent dline as a tdline */
739 if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
740 continue;
741
742 conf = unmap_conf_item(aconf);
743
744 sendto_one(source_p, form_str(RPL_STATSDLINE),
745 from, to, 'd', aconf->host, aconf->reason,
746 aconf->oper_reason);
747 }
748 }
749 }
750 }
751
752 /* stats_exempt()
753 *
754 * input - client to report to
755 * output - none
756 * side effects - client is given list of exempt blocks
757 */
758 static void
759 stats_exempt(struct Client *source_p)
760 {
761 struct AddressRec *arec;
762 struct ConfItem *conf;
763 struct AccessItem *aconf;
764 int i;
765
766 if (ConfigFileEntry.stats_e_disabled)
767 {
768 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
769 from, to);
770 return;
771 }
772
773 for (i = 0; i < ATABLE_SIZE; i++)
774 {
775 for (arec = atable[i]; arec; arec=arec->next)
776 {
777 if (arec->type == CONF_EXEMPTDLINE)
778 {
779 aconf = arec->aconf;
780
781 conf = unmap_conf_item(aconf);
782
783 sendto_one(source_p, form_str(RPL_STATSDLINE),
784 from, to, 'e', aconf->host,
785 aconf->reason, aconf->oper_reason);
786 }
787 }
788 }
789 }
790
791 static void
792 stats_events(struct Client *source_p)
793 {
794 show_events(source_p);
795 }
796
797 /* stats_pending_glines()
798 *
799 * input - client pointer
800 * output - none
801 * side effects - client is shown list of pending glines
802 */
803 static void
804 stats_pending_glines(struct Client *source_p)
805 {
806 const dlink_node *dn_ptr = NULL;
807 const struct gline_pending *glp_ptr = NULL;
808 char timebuffer[MAX_DATE_STRING] = { '\0' };
809 struct tm *tmptr = NULL;
810
811 if (!ConfigFileEntry.glines)
812 {
813 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
814 from, to);
815 return;
816 }
817
818 if (dlink_list_length(&pending_glines[GLINE_PENDING_ADD_TYPE]) > 0)
819 sendto_one(source_p, ":%s NOTICE %s :Pending G-lines",
820 from, to);
821
822 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_ADD_TYPE].head)
823 {
824 glp_ptr = dn_ptr->data;
825 tmptr = localtime(&glp_ptr->vote_1.time_request);
826 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
827
828 sendto_one(source_p,
829 ":%s NOTICE %s :1) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
830 from, to, glp_ptr->vote_1.oper_nick,
831 glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
832 glp_ptr->vote_1.oper_server, timebuffer,
833 glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
834
835 if (glp_ptr->vote_2.oper_nick[0] != '\0')
836 {
837 tmptr = localtime(&glp_ptr->vote_2.time_request);
838 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
839 sendto_one(source_p,
840 ":%s NOTICE %s :2) %s!%s@%s on %s requested gline at %s for %s@%s [%s]",
841 from, to, glp_ptr->vote_2.oper_nick,
842 glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
843 glp_ptr->vote_2.oper_server, timebuffer,
844 glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
845 }
846 }
847
848 sendto_one(source_p, ":%s NOTICE %s :End of Pending G-lines",
849 from, to);
850
851 if (dlink_list_length(&pending_glines[GLINE_PENDING_DEL_TYPE]) > 0)
852 sendto_one(source_p, ":%s NOTICE %s :Pending UNG-lines",
853 from, to);
854
855 DLINK_FOREACH(dn_ptr, pending_glines[GLINE_PENDING_DEL_TYPE].head)
856 {
857 glp_ptr = dn_ptr->data;
858 tmptr = localtime(&glp_ptr->vote_1.time_request);
859 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
860
861 sendto_one(source_p,
862 ":%s NOTICE %s :1) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
863 from, to, glp_ptr->vote_1.oper_nick,
864 glp_ptr->vote_1.oper_user, glp_ptr->vote_1.oper_host,
865 glp_ptr->vote_1.oper_server, timebuffer,
866 glp_ptr->user, glp_ptr->host, glp_ptr->vote_1.reason);
867
868 if (glp_ptr->vote_2.oper_nick[0] != '\0')
869 {
870 tmptr = localtime(&glp_ptr->vote_2.time_request);
871 strftime(timebuffer, MAX_DATE_STRING, "%Y/%m/%d %H:%M:%S", tmptr);
872 sendto_one(source_p,
873 ":%s NOTICE %s :2) %s!%s@%s on %s requested ungline at %s for %s@%s [%s]",
874 from, to, glp_ptr->vote_2.oper_nick,
875 glp_ptr->vote_2.oper_user, glp_ptr->vote_2.oper_host,
876 glp_ptr->vote_2.oper_server, timebuffer,
877 glp_ptr->user, glp_ptr->host, glp_ptr->vote_2.reason);
878
879 }
880 }
881
882 sendto_one(source_p, ":%s NOTICE %s :End of Pending UNG-lines",
883 from, to);
884 }
885
886 /* stats_glines()
887 *
888 * input - client pointer
889 * output - none
890 * side effects - client is shown list of glines
891 */
892 static void
893 stats_glines(struct Client *source_p)
894 {
895 struct AddressRec *arec = NULL;
896 int i = 0;
897
898 if (!ConfigFileEntry.glines)
899 {
900 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
901 from, to);
902 return;
903 }
904
905 for (; i < ATABLE_SIZE; ++i)
906 {
907 for (arec = atable[i]; arec; arec = arec->next)
908 {
909 if (arec->type == CONF_GLINE)
910 {
911 const struct AccessItem *aconf = arec->aconf;
912
913 sendto_one(source_p, form_str(RPL_STATSKLINE),
914 from, to, "G",
915 aconf->host ? aconf->host : "*",
916 aconf->user ? aconf->user : "*",
917 aconf->reason ? aconf->reason : "No reason", "" );
918 }
919 }
920 }
921 }
922
923 /* stats_gdeny()
924 *
925 * input - client pointer
926 * outputs - none
927 * side effects - client is shown gline ACL
928 */
929 static void
930 stats_gdeny(struct Client *source_p)
931 {
932 if (!ConfigFileEntry.glines)
933 {
934 sendto_one(source_p, ":%s NOTICE %s :This server does not support G-Lines",
935 from, to);
936 return;
937 }
938
939 report_confitem_types(source_p, GDENY_TYPE, 0);
940 }
941
942 static void
943 stats_hubleaf(struct Client *source_p)
944 {
945 report_confitem_types(source_p, HUB_TYPE, 0);
946 report_confitem_types(source_p, LEAF_TYPE, 0);
947 }
948
949 static void
950 stats_auth(struct Client *source_p)
951 {
952 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
953 if ((ConfigFileEntry.stats_i_oper_only == 2) && !IsOper(source_p))
954 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
955 from, to);
956
957 /* If unopered, Only return matching auth blocks */
958 else if ((ConfigFileEntry.stats_i_oper_only == 1) && !IsOper(source_p))
959 {
960 struct ConfItem *conf;
961 struct AccessItem *aconf;
962
963 if (MyConnect(source_p))
964 aconf = find_conf_by_address(source_p->host,
965 &source_p->localClient->ip,
966 CONF_CLIENT,
967 source_p->localClient->aftype,
968 source_p->username,
969 source_p->localClient->passwd);
970 else
971 aconf = find_conf_by_address(source_p->host, NULL, CONF_CLIENT,
972 0, source_p->username, NULL);
973
974 if (aconf == NULL)
975 return;
976
977 conf = unmap_conf_item(aconf);
978
979 sendto_one(source_p, form_str(RPL_STATSILINE), from,
980 to, 'I',
981 "*", show_iline_prefix(source_p, aconf, aconf->user),
982 aconf->host, aconf->port,
983 aconf->class_ptr ? aconf->class_ptr->name : "<default>");
984 }
985 /* They are opered, or allowed to see all auth blocks */
986 else
987 report_auth(source_p);
988 }
989
990 static void
991 stats_tklines(struct Client *source_p)
992 {
993 struct ConfItem *conf;
994 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
995 if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
996 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
997 from, to);
998
999 /* If unopered, Only return matching klines */
1000 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1001 {
1002 struct AccessItem *aconf;
1003
1004 if (MyConnect(source_p))
1005 aconf = find_conf_by_address(source_p->host,
1006 &source_p->localClient->ip,
1007 CONF_KILL,
1008 source_p->localClient->aftype,
1009 source_p->username, NULL);
1010 else
1011 aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1012 0, source_p->username, NULL);
1013
1014 if (aconf == NULL)
1015 return;
1016
1017 /* dont report a permanent kline as a tkline */
1018 if (!(aconf->flags & CONF_FLAGS_TEMPORARY))
1019 return;
1020
1021 conf = unmap_conf_item(aconf);
1022
1023 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1024 to, "k", aconf->host, aconf->user, aconf->reason, "");
1025 }
1026 /* Theyre opered, or allowed to see all klines */
1027 else {
1028 report_Klines(source_p, 1);
1029 report_confitem_types(source_p, RKLINE_TYPE, 1);
1030 }
1031 }
1032
1033 static void
1034 stats_klines(struct Client *source_p)
1035 {
1036 /* Oper only, if unopered, return ERR_NOPRIVILEGES */
1037 if ((ConfigFileEntry.stats_k_oper_only == 2) && !IsOper(source_p))
1038 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1039 from, to);
1040
1041 /* If unopered, Only return matching klines */
1042 else if ((ConfigFileEntry.stats_k_oper_only == 1) && !IsOper(source_p))
1043 {
1044 struct AccessItem *aconf;
1045
1046 /* search for a kline */
1047 if (MyConnect(source_p))
1048 aconf = find_conf_by_address(source_p->host,
1049 &source_p->localClient->ip,
1050 CONF_KILL,
1051 source_p->localClient->aftype,
1052 source_p->username, NULL);
1053 else
1054 aconf = find_conf_by_address(source_p->host, NULL, CONF_KILL,
1055 0, source_p->username, NULL);
1056
1057 if (aconf == NULL)
1058 return;
1059
1060 /* dont report a tkline as a kline */
1061 if (aconf->flags & CONF_FLAGS_TEMPORARY)
1062 return;
1063
1064 sendto_one(source_p, form_str(RPL_STATSKLINE), from,
1065 to, "K", aconf->host, aconf->user, aconf->reason,
1066 aconf->oper_reason);
1067 }
1068 /* Theyre opered, or allowed to see all klines */
1069 else {
1070 report_Klines(source_p, 0);
1071 report_confitem_types(source_p, RKLINE_TYPE, 0);
1072 }
1073 }
1074
1075 static void
1076 stats_messages(struct Client *source_p)
1077 {
1078 report_messages(source_p);
1079 }
1080
1081 static void
1082 stats_oper(struct Client *source_p)
1083 {
1084 if (!IsOper(source_p) && ConfigFileEntry.stats_o_oper_only)
1085 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1086 from, to);
1087 else
1088 report_confitem_types(source_p, OPER_TYPE, 0);
1089 }
1090
1091 /* stats_operedup()
1092 *
1093 * input - client pointer
1094 * output - none
1095 * side effects - client is shown a list of active opers
1096 */
1097 static void
1098 stats_operedup(struct Client *source_p)
1099 {
1100 dlink_node *ptr;
1101
1102 DLINK_FOREACH(ptr, oper_list.head)
1103 {
1104 const struct Client *target_p = ptr->data;
1105
1106 if (IsOperHidden(target_p) && !IsOper(source_p))
1107 continue;
1108
1109 if (MyClient(source_p) && IsOper(source_p))
1110 sendto_one(source_p, ":%s %d %s p :[%c][%s] %s (%s@%s) Idle: %d",
1111 from, RPL_STATSDEBUG, to,
1112 IsAdmin(target_p) ?
1113 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1114 oper_privs_as_string(target_p->localClient->operflags),
1115 target_p->name, target_p->username, target_p->host,
1116 (int)(CurrentTime - target_p->localClient->last));
1117 else
1118 sendto_one(source_p, ":%s %d %s p :[%c] %s (%s@%s) Idle: %d",
1119 from, RPL_STATSDEBUG, to,
1120 IsAdmin(target_p) ?
1121 (IsOperHiddenAdmin(target_p) ? 'O' : 'A') : 'O',
1122 target_p->name, target_p->username, target_p->host,
1123 (int)(CurrentTime - target_p->localClient->last));
1124 }
1125
1126 sendto_one(source_p, ":%s %d %s p :%lu OPER(s)",
1127 from, RPL_STATSDEBUG, to, dlink_list_length(&oper_list));
1128 }
1129
1130 static void
1131 stats_ports(struct Client *source_p)
1132 {
1133 if (!IsOper(source_p) && ConfigFileEntry.stats_P_oper_only)
1134 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1135 from, to);
1136 else
1137 show_ports(source_p);
1138 }
1139
1140 static void
1141 stats_resv(struct Client *source_p)
1142 {
1143 report_resv(source_p);
1144 }
1145
1146 static void
1147 stats_usage(struct Client *source_p)
1148 {
1149 send_usage(source_p);
1150 }
1151
1152 static void
1153 stats_tstats(struct Client *source_p)
1154 {
1155 const struct Client *target_p = NULL;
1156 const dlink_node *ptr = NULL;
1157 struct ServerStatistics *sp;
1158 struct ServerStatistics tmp;
1159
1160 sp = &tmp;
1161 memcpy(sp, &ServerStats, sizeof(struct ServerStatistics));
1162
1163 /*
1164 * must use the += operator. is_sv is not the number of currently
1165 * active server connections. Note the incrementation in
1166 * s_bsd.c:close_connection.
1167 */
1168 sp->is_sv += dlink_list_length(&serv_list);
1169
1170 DLINK_FOREACH(ptr, serv_list.head)
1171 {
1172 target_p = ptr->data;
1173
1174 sp->is_sbs += target_p->localClient->send.bytes;
1175 sp->is_sbr += target_p->localClient->recv.bytes;
1176 sp->is_sti += CurrentTime - target_p->firsttime;
1177 }
1178
1179 sp->is_cl += dlink_list_length(&local_client_list);
1180
1181 DLINK_FOREACH(ptr, local_client_list.head)
1182 {
1183 target_p = ptr->data;
1184
1185 sp->is_cbs += target_p->localClient->send.bytes;
1186 sp->is_cbr += target_p->localClient->recv.bytes;
1187 sp->is_cti += CurrentTime - target_p->firsttime;
1188 }
1189
1190 sp->is_ni += dlink_list_length(&unknown_list);
1191
1192 sendto_one(source_p, ":%s %d %s T :accepts %u refused %u",
1193 me.name, RPL_STATSDEBUG, source_p->name, sp->is_ac, sp->is_ref);
1194 sendto_one(source_p, ":%s %d %s T :unknown commands %u prefixes %u",
1195 me.name, RPL_STATSDEBUG, source_p->name, sp->is_unco, sp->is_unpf);
1196 sendto_one(source_p, ":%s %d %s T :nick collisions %u unknown closes %u",
1197 me.name, RPL_STATSDEBUG, source_p->name, sp->is_kill, sp->is_ni);
1198 sendto_one(source_p, ":%s %d %s T :wrong direction %u empty %u",
1199 me.name, RPL_STATSDEBUG, source_p->name, sp->is_wrdi, sp->is_empt);
1200 sendto_one(source_p, ":%s %d %s T :numerics seen %u",
1201 me.name, RPL_STATSDEBUG, source_p->name, sp->is_num);
1202 sendto_one(source_p, ":%s %d %s T :auth successes %u fails %u",
1203 me.name, RPL_STATSDEBUG, source_p->name, sp->is_asuc, sp->is_abad);
1204 sendto_one(source_p, ":%s %d %s T :Client Server",
1205 me.name, RPL_STATSDEBUG, source_p->name);
1206
1207 sendto_one(source_p, ":%s %d %s T :connected %u %u",
1208 me.name, RPL_STATSDEBUG, source_p->name,
1209 (unsigned int)sp->is_cl,
1210 (unsigned int)sp->is_sv);
1211 sendto_one(source_p, ":%s %d %s T :bytes sent %llu %llu",
1212 me.name, RPL_STATSDEBUG, source_p->name,
1213 sp->is_cbs, sp->is_sbs);
1214 sendto_one(source_p, ":%s %d %s T :bytes recv %llu %llu",
1215 me.name, RPL_STATSDEBUG, source_p->name,
1216 sp->is_cbr, sp->is_sbr);
1217 sendto_one(source_p, ":%s %d %s T :time connected %u %u",
1218 me.name, RPL_STATSDEBUG, source_p->name,
1219 (unsigned int)sp->is_cti,
1220 (unsigned int)sp->is_sti);
1221 }
1222
1223 static void
1224 stats_uptime(struct Client *source_p)
1225 {
1226 time_t now = CurrentTime - me.since;
1227 sendto_one(source_p, form_str(RPL_STATSUPTIME), from, to,
1228 now/86400, (now/3600)%24, (now/60)%60, now%60);
1229 if (!ConfigFileEntry.disable_remote || IsOper(source_p))
1230 sendto_one(source_p, form_str(RPL_STATSCONN), from, to,
1231 MaxConnectionCount, MaxClientCount, Count.totalrestartcount);
1232 }
1233
1234 static void
1235 stats_shared(struct Client *source_p)
1236 {
1237 report_confitem_types(source_p, ULINE_TYPE, 0);
1238 }
1239
1240 /* stats_servers()
1241 *
1242 * input - client pointer
1243 * output - none
1244 * side effects - client is shown lists of who connected servers
1245 */
1246 static void
1247 stats_servers(struct Client *source_p)
1248 {
1249 struct Client *target_p;
1250 dlink_node *ptr;
1251 int j = 0;
1252
1253 DLINK_FOREACH(ptr, serv_list.head)
1254 {
1255 target_p = ptr->data;
1256
1257 j++;
1258
1259 sendto_one(source_p, ":%s %d %s v :%s (%s!%s@%s) Idle: %d",
1260 from, RPL_STATSDEBUG, to,
1261 target_p->name,
1262 (target_p->serv->by[0] ? target_p->serv->by : "Remote."),
1263 "*", "*", (int)(CurrentTime - target_p->lasttime));
1264 }
1265
1266 sendto_one(source_p, ":%s %d %s v :%d Server(s)",
1267 from, RPL_STATSDEBUG, to, j);
1268 }
1269
1270 static void
1271 stats_gecos(struct Client *source_p)
1272 {
1273 report_confitem_types(source_p, XLINE_TYPE, 0);
1274 report_confitem_types(source_p, RXLINE_TYPE, 0);
1275 }
1276
1277 static void
1278 stats_class(struct Client *source_p)
1279 {
1280 report_confitem_types(source_p, CLASS_TYPE, 0);
1281 }
1282
1283 static void
1284 stats_memory(struct Client *source_p)
1285 {
1286 count_memory(source_p);
1287 }
1288
1289 static void
1290 stats_ziplinks(struct Client *source_p)
1291 {
1292 dlink_node *ptr = NULL;
1293 unsigned int sent_data = 0;
1294
1295 DLINK_FOREACH(ptr, serv_list.head)
1296 {
1297 const struct Client *target_p = ptr->data;
1298
1299 if (IsCapable(target_p, CAP_ZIP))
1300 {
1301 /* we use memcpy(3) and a local copy of the structure to
1302 * work around a register use bug on GCC on the SPARC.
1303 * -jmallett, 04/27/2002
1304 */
1305 struct ZipStats zipstats;
1306
1307 memcpy(&zipstats, &target_p->localClient->zipstats, sizeof(zipstats));
1308
1309 sendto_one(source_p, ":%s %d %s Z :ZipLinks stats for %s send[%.2f%% "
1310 "compression (%llu bytes data/%llu bytes wire)] recv[%.2f%% "
1311 "compression (%llu bytes data/%llu bytes wire)]",
1312 from, RPL_STATSDEBUG, to, target_p->name,
1313 zipstats.out_ratio, zipstats.out, zipstats.out_wire,
1314 zipstats.in_ratio, zipstats.in, zipstats.in_wire);
1315 ++sent_data;
1316 }
1317 }
1318
1319 sendto_one(source_p, ":%s %d %s Z :%u ziplink(s)",
1320 from, RPL_STATSDEBUG, to, sent_data);
1321 }
1322
1323 static void
1324 stats_servlinks(struct Client *source_p)
1325 {
1326 uint64_t sendB = 0, recvB = 0;
1327 time_t uptime = 0;
1328 dlink_node *ptr = NULL;
1329
1330 if (ConfigServerHide.flatten_links && !IsOper(source_p))
1331 {
1332 sendto_one(source_p, form_str(ERR_NOPRIVILEGES),
1333 from, to);
1334 return;
1335 }
1336
1337 DLINK_FOREACH(ptr, serv_list.head)
1338 {
1339 struct Client *target_p = ptr->data;
1340
1341 sendB += target_p->localClient->send.bytes;
1342 recvB += target_p->localClient->recv.bytes;
1343
1344 /* ":%s 211 %s %s %u %u %llu %u %llu :%u %u %s" */
1345 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1346 from, to,
1347 get_client_name(target_p, IsAdmin(source_p) ? SHOW_IP : MASK_IP),
1348 dbuf_length(&target_p->localClient->buf_sendq),
1349 target_p->localClient->send.messages,
1350 target_p->localClient->send.bytes >> 10,
1351 target_p->localClient->recv.messages,
1352 target_p->localClient->recv.bytes >> 10,
1353 (unsigned)(CurrentTime - target_p->firsttime),
1354 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since): 0,
1355 IsOper(source_p) ? show_capabilities(target_p) : "TS");
1356 }
1357
1358 sendB >>= 10;
1359 recvB >>= 10;
1360
1361 sendto_one(source_p, ":%s %d %s ? :%u total server(s)",
1362 from, RPL_STATSDEBUG, to, dlink_list_length(&serv_list));
1363 sendto_one(source_p, ":%s %d %s ? :Sent total : %7.2f %s",
1364 from, RPL_STATSDEBUG, to,
1365 _GMKv(sendB), _GMKs(sendB));
1366 sendto_one(source_p, ":%s %d %s ? :Recv total : %7.2f %s",
1367 from, RPL_STATSDEBUG, to,
1368 _GMKv(recvB), _GMKs(recvB));
1369
1370 uptime = (CurrentTime - me.since);
1371
1372 sendto_one(source_p, ":%s %d %s ? :Server send: %7.2f %s (%4.1f K/s)",
1373 from, RPL_STATSDEBUG, to,
1374 _GMKv((me.localClient->send.bytes>>10)),
1375 _GMKs((me.localClient->send.bytes>>10)),
1376 (float)((float)((me.localClient->send.bytes) >> 10) /
1377 (float)uptime));
1378 sendto_one(source_p, ":%s %d %s ? :Server recv: %7.2f %s (%4.1f K/s)",
1379 from, RPL_STATSDEBUG, to,
1380 _GMKv((me.localClient->recv.bytes>>10)),
1381 _GMKs((me.localClient->recv.bytes>>10)),
1382 (float)((float)((me.localClient->recv.bytes) >> 10) /
1383 (float)uptime));
1384 }
1385
1386 static void
1387 stats_ltrace(struct Client *source_p, int parc, char *parv[])
1388 {
1389 int doall = 0;
1390 int wilds = 0;
1391 char *name = NULL;
1392 char statchar;
1393
1394 if ((name = parse_stats_args(parc, parv, &doall, &wilds)) != NULL)
1395 {
1396 statchar = parv[1][0];
1397
1398 stats_L(source_p, name, doall, wilds, statchar);
1399 }
1400 else
1401 sendto_one(source_p, form_str(ERR_NEEDMOREPARAMS),
1402 from, to, "STATS");
1403 }
1404
1405 /*
1406 * ms_stats - STATS message handler
1407 * parv[0] = sender prefix
1408 * parv[1] = statistics selector (defaults to Message frequency)
1409 * parv[2] = server name (current server defaulted, if omitted)
1410 */
1411 static void
1412 ms_stats(struct Client *client_p, struct Client *source_p,
1413 int parc, char *parv[])
1414 {
1415 if (hunt_server(client_p,source_p,":%s STATS %s :%s",2,parc,parv)!=HUNTED_ISME)
1416 return;
1417
1418 if (IsClient(source_p))
1419 mo_stats(client_p, source_p, parc, parv);
1420 }
1421
1422 /*
1423 * stats_L
1424 *
1425 * inputs - pointer to client to report to
1426 * - doall flag
1427 * - wild card or not
1428 * output - NONE
1429 * side effects -
1430 */
1431 static void
1432 stats_L(struct Client *source_p,char *name,int doall,
1433 int wilds,char statchar)
1434 {
1435 stats_L_list(source_p, name, doall, wilds, &unknown_list, statchar);
1436 stats_L_list(source_p, name, doall, wilds, &local_client_list, statchar);
1437 stats_L_list(source_p, name, doall, wilds, &serv_list, statchar);
1438 }
1439
1440 static void
1441 stats_L_list(struct Client *source_p,char *name, int doall, int wilds,
1442 dlink_list *list,char statchar)
1443 {
1444 dlink_node *ptr;
1445 struct Client *target_p;
1446
1447 /*
1448 * send info about connections which match, or all if the
1449 * mask matches from. Only restrictions are on those who
1450 * are invisible not being visible to 'foreigners' who use
1451 * a wild card based search to list it.
1452 */
1453 DLINK_FOREACH(ptr, list->head)
1454 {
1455 target_p = ptr->data;
1456
1457 if (IsInvisible(target_p) && (doall || wilds) &&
1458 !(MyConnect(source_p) && IsOper(source_p)) &&
1459 !IsOper(target_p) && (target_p != source_p))
1460 continue;
1461 if (!doall && wilds && !match(name, target_p->name))
1462 continue;
1463 if (!(doall || wilds) && irccmp(name, target_p->name))
1464 continue;
1465
1466 /* This basically shows ips for our opers if its not a server/admin, or
1467 * its one of our admins. */
1468 if(MyClient(source_p) && IsOper(source_p) &&
1469 (IsAdmin(source_p) ||
1470 (!IsServer(target_p) && !IsAdmin(target_p) &&
1471 !IsHandshake(target_p) && !IsConnecting(target_p))))
1472 {
1473 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1474 from, to,
1475 (IsUpper(statchar)) ?
1476 get_client_name(target_p, SHOW_IP) :
1477 get_client_name(target_p, HIDE_IP),
1478 dbuf_length(&target_p->localClient->buf_sendq),
1479 target_p->localClient->send.messages,
1480 target_p->localClient->send.bytes>>10,
1481 target_p->localClient->recv.messages,
1482 target_p->localClient->recv.bytes>>10,
1483 (unsigned)(CurrentTime - target_p->firsttime),
1484 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1485 IsServer(target_p) ? show_capabilities(target_p) : "-");
1486 }
1487 else
1488 {
1489 /* If its a hidden ip, an admin, or a server, mask the real IP */
1490 if(IsIPSpoof(target_p) || IsServer(target_p) || IsAdmin(target_p)
1491 || IsHandshake(target_p) || IsConnecting(target_p))
1492 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1493 from, to,
1494 get_client_name(target_p, MASK_IP),
1495 dbuf_length(&target_p->localClient->buf_sendq),
1496 target_p->localClient->send.messages,
1497 target_p->localClient->send.bytes>>10,
1498 target_p->localClient->recv.messages,
1499 target_p->localClient->recv.bytes>>10,
1500 (unsigned)(CurrentTime - target_p->firsttime),
1501 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1502 IsServer(target_p) ? show_capabilities(target_p) : "-");
1503 else /* show the real IP */
1504 sendto_one(source_p, form_str(RPL_STATSLINKINFO),
1505 from, to,
1506 (IsUpper(statchar)) ?
1507 get_client_name(target_p, SHOW_IP) :
1508 get_client_name(target_p, HIDE_IP),
1509 dbuf_length(&target_p->localClient->buf_sendq),
1510 target_p->localClient->send.messages,
1511 target_p->localClient->send.bytes>>10,
1512 target_p->localClient->recv.messages,
1513 target_p->localClient->recv.bytes>>10,
1514 (unsigned)(CurrentTime - target_p->firsttime),
1515 (CurrentTime > target_p->since) ? (unsigned)(CurrentTime - target_p->since):0,
1516 IsServer(target_p) ? show_capabilities(target_p) : "-");
1517 }
1518 }
1519 }
1520
1521 /* parse_stats_args()
1522 *
1523 * inputs - arg count
1524 * - args
1525 * - doall flag
1526 * - wild card or not
1527 * output - pointer to name to use
1528 * side effects -
1529 * common parse routine for m_stats args
1530 *
1531 */
1532 static char *
1533 parse_stats_args(int parc, char *parv[], int *doall, int *wilds)
1534 {
1535 char *name;
1536
1537 if (parc > 2)
1538 {
1539 name = parv[2];
1540
1541 if (!irccmp(name, from))
1542 *doall = 2;
1543 else if (match(name, from))
1544 *doall = 1;
1545
1546 if (strchr(name, '*') ||
1547 strchr(name, '?'))
1548 *wilds = 1;
1549
1550 return(name);
1551 }
1552 else
1553 return(NULL);
1554 }

Properties

Name Value
svn:eol-style native
svn:keywords Id Revision