]>
Commit | Line | Data |
---|---|---|
f9e9119b P |
1 | #include "../core/nsmalloc.h" |
2 | #include "../lib/irc_string.h" | |
3 | #include "../lib/version.h" | |
4 | #include "patricia.h" | |
5 | #include "../core/error.h" | |
6 | #include "../core/hooks.h" | |
7 | #include "../control/control.h" | |
8 | ||
9 | #include <assert.h> /* assert */ | |
10 | #include <stdio.h> | |
11 | #include <string.h> | |
12 | ||
13 | MODULE_VERSION(""); | |
14 | ||
15 | patricia_tree_t *iptree; | |
16 | sstring *nodeextnames[PATRICIA_MAXSLOTS]; | |
17 | ||
18 | void patriciastats(int hooknum, void *arg); | |
19 | ||
20 | void _init(void) { | |
21 | iptree = patricia_new_tree(PATRICIA_MAXBITS); | |
22 | assert(iptree); | |
23 | ||
24 | registerhook(HOOK_CORE_STATSREQUEST,&patriciastats); | |
25 | } | |
26 | ||
27 | void _fini(void) { | |
28 | deregisterhook(HOOK_CORE_STATSREQUEST,&patriciastats); | |
29 | patricia_destroy_tree (iptree, NULL); | |
30 | nsfreeall(POOL_PATRICIA); | |
31 | } | |
32 | ||
33 | void patriciastats(int hooknum, void *arg) { | |
34 | long level=(long)arg; | |
35 | char buf[100]; | |
36 | patricia_node_t *head, *node; | |
37 | int i,j,k,l; | |
38 | ||
08a983e0 | 39 | if (level <= 5) |
f9e9119b P |
40 | return; |
41 | ||
42 | sprintf(buf, "Patricia: %6d Active Nodes (%d bits)", iptree->num_active_node, iptree->maxbits); | |
43 | triggerhook(HOOK_CORE_STATSREPLY,buf); | |
44 | ||
45 | head = iptree->head; | |
46 | ||
47 | i=0;j=0; | |
48 | PATRICIA_WALK_ALL(head, node) { | |
49 | if ( node->prefix ) | |
50 | j++; | |
51 | else | |
52 | i++; | |
53 | } PATRICIA_WALK_END; | |
54 | sprintf(buf, "Patricia: %6d Nodes, %6d Prefix (walk all)", i,j); | |
55 | triggerhook(HOOK_CORE_STATSREPLY,buf); | |
56 | ||
57 | head = iptree->head; | |
58 | i=0;j=0;k=0;l=0; | |
59 | PATRICIA_WALK(head, node) { | |
60 | if ( node->prefix ) { | |
61 | if (irc_in_addr_is_ipv4(&(node->prefix->sin))) | |
62 | k++; | |
63 | else | |
64 | l++; | |
65 | j++; | |
66 | } else | |
67 | i++; | |
68 | } PATRICIA_WALK_END; | |
69 | sprintf(buf, "Patricia: %6d Nodes, %6d Prefix (walk prefixes only)", i,j); | |
70 | triggerhook(HOOK_CORE_STATSREPLY,buf); | |
71 | sprintf(buf, "Patricia: %6d IP4Node, %6d IP6Node", k, l); | |
72 | triggerhook(HOOK_CORE_STATSREPLY,buf); | |
73 | ||
74 | j=0; | |
75 | for (i=0;i<PATRICIA_MAXSLOTS;i++) { | |
76 | if (nodeextnames[i]!=NULL) { | |
77 | j++; | |
78 | } | |
79 | } | |
80 | sprintf(buf, "Patricia: %6d ExtsUsed, %5d Max", j,PATRICIA_MAXSLOTS); | |
81 | triggerhook(HOOK_CORE_STATSREPLY,buf); | |
82 | ||
83 | } | |
84 | ||
85 | int registernodeext(const char *name) { | |
86 | int i; | |
87 | ||
88 | if (findnodeext(name)!=-1) { | |
89 | Error("patricia",ERR_WARNING,"Tried to register duplicate node extension %s",name); | |
90 | return -1; | |
91 | } | |
92 | ||
93 | for (i=0;i<PATRICIA_MAXSLOTS;i++) { | |
94 | if (nodeextnames[i]==NULL) { | |
95 | nodeextnames[i]=getsstring(name,100); | |
96 | return i; | |
97 | } | |
98 | } | |
99 | ||
100 | Error("patricia",ERR_WARNING,"Tried to register too many extensions: %s",name); | |
101 | return -1; | |
102 | } | |
103 | ||
104 | int findnodeext(const char *name) { | |
105 | int i; | |
106 | ||
107 | for (i=0;i<PATRICIA_MAXSLOTS;i++) { | |
108 | if (nodeextnames[i]!=NULL && !ircd_strcmp(name,nodeextnames[i]->content)) { | |
109 | return i; | |
110 | } | |
111 | } | |
112 | ||
113 | return -1; | |
114 | } | |
115 | ||
116 | void releasenodeext(int index) { | |
117 | patricia_node_t *head, *node; | |
118 | ||
119 | freesstring(nodeextnames[index]); | |
120 | nodeextnames[index]=NULL; | |
121 | ||
122 | head = iptree->head; | |
123 | ||
124 | PATRICIA_WALK_ALL(head, node) | |
125 | { | |
126 | node->exts[index]=NULL; | |
127 | } PATRICIA_WALK_END; | |
128 | } | |
129 |