MCPcopy Create free account
hub / github.com/OpenSIPS/opensips / init_ip_tree

Function init_ip_tree

modules/pike/ip_tree.c:114–147  ·  view source on GitHub ↗

Builds and Inits a new IP tree */

Source from the content-addressed store, hash-verified

112
113/* Builds and Inits a new IP tree */
114int init_ip_tree(int maximum_hits)
115{
116 int size;
117 int i;
118
119 /* create the root */
120 root = (struct ip_tree*)shm_malloc(sizeof(struct ip_tree));
121 if (root==0) {
122 LM_ERR("shm malloc failed\n");
123 goto error;
124 }
125 memset( root, 0, sizeof(struct ip_tree));
126
127 /* init lock set */
128 size = MAX_IP_BRANCHES;
129 root->entry_lock_set = init_lock_set( &size );
130 if (root->entry_lock_set==0) {
131 LM_ERR("failed to create locks\n");
132 goto error;
133 }
134 /* assign to each branch a lock */
135 for(i=0;i<MAX_IP_BRANCHES;i++) {
136 root->entries[i].node = 0;
137 root->entries[i].lock_idx = i % size;
138 }
139
140 root->max_hits = maximum_hits;
141
142 return 0;
143error:
144 if (root)
145 shm_free(root);
146 return -1;
147}
148
149
150

Callers 1

pike_initFunction · 0.85

Calls 3

shm_mallocFunction · 0.85
init_lock_setFunction · 0.85
shm_freeFunction · 0.85

Tested by

no test coverage detected