* Add a pointer (ptr) to a node. */
| 247 | * Add a pointer (ptr) to a node. |
| 248 | */ |
| 249 | static int |
| 250 | acl_add_ptr(struct acl_build_context *context, |
| 251 | struct rte_acl_node *node, |
| 252 | struct rte_acl_node *ptr, |
| 253 | struct rte_acl_bitset *bits) |
| 254 | { |
| 255 | uint32_t n, num_ptrs; |
| 256 | struct rte_acl_ptr_set *ptrs = NULL; |
| 257 | |
| 258 | /* |
| 259 | * If there's already a pointer to the same node, just add to the bitset |
| 260 | */ |
| 261 | for (n = 0; n < node->num_ptrs; n++) { |
| 262 | if (node->ptrs[n].ptr != NULL) { |
| 263 | if (node->ptrs[n].ptr == ptr) { |
| 264 | acl_include(&node->ptrs[n].values, bits, -1); |
| 265 | acl_include(&node->values, bits, -1); |
| 266 | return 0; |
| 267 | } |
| 268 | } |
| 269 | } |
| 270 | |
| 271 | /* if there's no room for another pointer, make room */ |
| 272 | if (node->num_ptrs >= node->max_ptrs) { |
| 273 | /* add room for more pointers */ |
| 274 | num_ptrs = node->max_ptrs + ACL_PTR_ALLOC; |
| 275 | ptrs = acl_build_alloc(context, num_ptrs, sizeof(*ptrs)); |
| 276 | |
| 277 | /* copy current points to new memory allocation */ |
| 278 | if (node->ptrs != NULL) { |
| 279 | memcpy(ptrs, node->ptrs, |
| 280 | node->num_ptrs * sizeof(*ptrs)); |
| 281 | acl_build_free(context, node->max_ptrs * sizeof(*ptrs), |
| 282 | node->ptrs); |
| 283 | } |
| 284 | node->ptrs = ptrs; |
| 285 | node->max_ptrs = num_ptrs; |
| 286 | } |
| 287 | |
| 288 | /* Find available ptr and add a new pointer to this node */ |
| 289 | for (n = node->min_add; n < node->max_ptrs; n++) { |
| 290 | if (node->ptrs[n].ptr == NULL) { |
| 291 | node->ptrs[n].ptr = ptr; |
| 292 | acl_include(&node->ptrs[n].values, bits, 0); |
| 293 | acl_include(&node->values, bits, -1); |
| 294 | if (ptr != NULL) |
| 295 | ptr->ref_count++; |
| 296 | if (node->num_ptrs <= n) |
| 297 | node->num_ptrs = n + 1; |
| 298 | return 0; |
| 299 | } |
| 300 | } |
| 301 | |
| 302 | return 0; |
| 303 | } |
| 304 | |
| 305 | /* |
| 306 | * Add a pointer for a range of values |
no test coverage detected