]>
jfr.im git - irc/quakenet/newserv.git/blob - patricia/patricia.c
1 #include "../core/nsmalloc.h"
2 #include "../lib/irc_string.h"
3 #include "../lib/version.h"
5 #include "../core/error.h"
6 #include "../core/hooks.h"
7 #include "../control/control.h"
9 #include <assert.h> /* assert */
15 patricia_tree_t
*iptree
;
16 sstring
*nodeextnames
[PATRICIA_MAXSLOTS
];
18 void patriciastats(int hooknum
, void *arg
);
21 iptree
= patricia_new_tree(PATRICIA_MAXBITS
);
24 registerhook(HOOK_CORE_STATSREQUEST
,&patriciastats
);
28 deregisterhook(HOOK_CORE_STATSREQUEST
,&patriciastats
);
29 patricia_destroy_tree (iptree
, NULL
);
30 nsfreeall(POOL_PATRICIA
);
33 void patriciastats(int hooknum
, void *arg
) {
36 patricia_node_t
*head
, *node
;
42 sprintf(buf
, "Patricia: %6d Active Nodes (%d bits)", iptree
->num_active_node
, iptree
->maxbits
);
43 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
48 PATRICIA_WALK_ALL(head
, node
) {
50 refcnt
+=node
->prefix
->ref_count
;
55 sprintf(buf
, "Patricia: %6d Nodes, %6d Prefix (walk all), references %6d", i
,j
, refcnt
);
56 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
59 i
=0;j
=0;k
=0;l
=0,refcnt
=0;
60 PATRICIA_WALK(head
, node
) {
62 if (irc_in_addr_is_ipv4(&(node
->prefix
->sin
)))
66 refcnt
+=node
->prefix
->ref_count
;
71 sprintf(buf
, "Patricia: %6d Nodes, %6d Prefix (walk prefixes only), references %6d", i
,j
, refcnt
);
72 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
73 sprintf(buf
, "Patricia: %6d IP4Node, %6d IP6Node", k
, l
);
74 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
77 for (i
=0;i
<PATRICIA_MAXSLOTS
;i
++) {
78 if (nodeextnames
[i
]!=NULL
) {
82 sprintf(buf
, "Patricia: %6d ExtsUsed, %5d Max", j
,PATRICIA_MAXSLOTS
);
83 triggerhook(HOOK_CORE_STATSREPLY
,buf
);
87 int registernodeext(const char *name
) {
90 if (findnodeext(name
)!=-1) {
91 Error("patricia",ERR_WARNING
,"Tried to register duplicate node extension %s",name
);
95 for (i
=0;i
<PATRICIA_MAXSLOTS
;i
++) {
96 if (nodeextnames
[i
]==NULL
) {
97 nodeextnames
[i
]=getsstring(name
,100);
102 Error("patricia",ERR_WARNING
,"Tried to register too many extensions: %s",name
);
106 int findnodeext(const char *name
) {
109 for (i
=0;i
<PATRICIA_MAXSLOTS
;i
++) {
110 if (nodeextnames
[i
]!=NULL
&& !ircd_strcmp(name
,nodeextnames
[i
]->content
)) {
118 void releasenodeext(int index
) {
119 patricia_node_t
*head
, *node
;
121 freesstring(nodeextnames
[index
]);
122 nodeextnames
[index
]=NULL
;
126 PATRICIA_WALK_CLEAR(head
, node
)
128 if ( node
->exts
[index
] ) {
129 derefnode(iptree
,node
);
130 node
->exts
[index
]=NULL
;
132 } PATRICIA_WALK_CLEAR_END
;