Lines Matching full:cp
293 static void tcindex_free_perfect_hash(struct tcindex_data *cp) in tcindex_free_perfect_hash() argument
297 for (i = 0; i < cp->hash; i++) in tcindex_free_perfect_hash()
298 tcf_exts_destroy(&cp->perfect[i].exts); in tcindex_free_perfect_hash()
299 kfree(cp->perfect); in tcindex_free_perfect_hash()
302 static int tcindex_alloc_perfect_hash(struct net *net, struct tcindex_data *cp) in tcindex_alloc_perfect_hash() argument
306 cp->perfect = kcalloc(cp->hash, sizeof(struct tcindex_filter_result), in tcindex_alloc_perfect_hash()
308 if (!cp->perfect) in tcindex_alloc_perfect_hash()
311 for (i = 0; i < cp->hash; i++) { in tcindex_alloc_perfect_hash()
312 err = tcf_exts_init(&cp->perfect[i].exts, net, in tcindex_alloc_perfect_hash()
316 cp->perfect[i].p = cp; in tcindex_alloc_perfect_hash()
322 tcindex_free_perfect_hash(cp); in tcindex_alloc_perfect_hash()
333 struct tcindex_data *cp = NULL, *oldp; in tcindex_set_parms() local
351 cp = kzalloc(sizeof(*cp), GFP_KERNEL); in tcindex_set_parms()
352 if (!cp) in tcindex_set_parms()
355 cp->mask = p->mask; in tcindex_set_parms()
356 cp->shift = p->shift; in tcindex_set_parms()
357 cp->hash = p->hash; in tcindex_set_parms()
358 cp->alloc_hash = p->alloc_hash; in tcindex_set_parms()
359 cp->fall_through = p->fall_through; in tcindex_set_parms()
360 cp->tp = tp; in tcindex_set_parms()
361 refcount_set(&cp->refcnt, 1); /* Paired with tcindex_destroy_work() */ in tcindex_set_parms()
364 cp->hash = nla_get_u32(tb[TCA_TCINDEX_HASH]); in tcindex_set_parms()
367 cp->mask = nla_get_u16(tb[TCA_TCINDEX_MASK]); in tcindex_set_parms()
370 cp->shift = nla_get_u32(tb[TCA_TCINDEX_SHIFT]); in tcindex_set_parms()
372 if (!cp->hash) { in tcindex_set_parms()
376 if ((cp->mask >> cp->shift) < PERFECT_HASH_THRESHOLD) in tcindex_set_parms()
377 cp->hash = (cp->mask >> cp->shift) + 1; in tcindex_set_parms()
379 cp->hash = DEFAULT_HASH_SIZE; in tcindex_set_parms()
385 if (tcindex_alloc_perfect_hash(net, cp) < 0) in tcindex_set_parms()
387 cp->alloc_hash = cp->hash; in tcindex_set_parms()
388 for (i = 0; i < min(cp->hash, p->hash); i++) in tcindex_set_parms()
389 cp->perfect[i].res = p->perfect[i].res; in tcindex_set_parms()
392 cp->h = p->h; in tcindex_set_parms()
394 err = tcindex_filter_result_init(&new_filter_result, cp, net); in tcindex_set_parms()
405 if (cp->perfect) { in tcindex_set_parms()
406 if (!valid_perfect_hash(cp) || in tcindex_set_parms()
407 cp->hash > cp->alloc_hash) in tcindex_set_parms()
409 } else if (cp->h && cp->hash != cp->alloc_hash) { in tcindex_set_parms()
415 cp->fall_through = nla_get_u32(tb[TCA_TCINDEX_FALL_THROUGH]); in tcindex_set_parms()
417 if (!cp->perfect && !cp->h) in tcindex_set_parms()
418 cp->alloc_hash = cp->hash; in tcindex_set_parms()
425 if (cp->perfect || valid_perfect_hash(cp)) in tcindex_set_parms()
426 if (handle >= cp->alloc_hash) in tcindex_set_parms()
431 if (!cp->perfect && !cp->h) { in tcindex_set_parms()
432 if (valid_perfect_hash(cp)) { in tcindex_set_parms()
433 if (tcindex_alloc_perfect_hash(net, cp) < 0) in tcindex_set_parms()
439 hash = kcalloc(cp->hash, in tcindex_set_parms()
446 cp->h = hash; in tcindex_set_parms()
451 if (cp->perfect) in tcindex_set_parms()
452 r = cp->perfect + handle; in tcindex_set_parms()
454 r = tcindex_lookup(cp, handle) ? : &new_filter_result; in tcindex_set_parms()
462 err = tcindex_filter_result_init(&f->result, cp, net); in tcindex_set_parms()
475 err = tcindex_filter_result_init(old_r, cp, net); in tcindex_set_parms()
486 rcu_assign_pointer(tp->root, cp); in tcindex_set_parms()
495 fp = cp->h + (handle % cp->hash); in tcindex_set_parms()
512 tcindex_free_perfect_hash(cp); in tcindex_set_parms()
514 kfree(cp->h); in tcindex_set_parms()
517 kfree(cp); in tcindex_set_parms()