Builds and Inits a new IP tree */
| 112 | |
| 113 | /* Builds and Inits a new IP tree */ |
| 114 | int 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; |
| 143 | error: |
| 144 | if (root) |
| 145 | shm_free(root); |
| 146 | return -1; |
| 147 | } |
| 148 | |
| 149 | |
| 150 |
no test coverage detected