Lines Matching full:cp

281 static void tcindex_free_perfect_hash(struct tcindex_data *cp);
296 static void tcindex_free_perfect_hash(struct tcindex_data *cp) in tcindex_free_perfect_hash() argument
300 for (i = 0; i < cp->hash; i++) in tcindex_free_perfect_hash()
301 tcf_exts_destroy(&cp->perfect[i].exts); in tcindex_free_perfect_hash()
302 kfree(cp->perfect); in tcindex_free_perfect_hash()
305 static int tcindex_alloc_perfect_hash(struct net *net, struct tcindex_data *cp) in tcindex_alloc_perfect_hash() argument
309 cp->perfect = kcalloc(cp->hash, sizeof(struct tcindex_filter_result), in tcindex_alloc_perfect_hash()
311 if (!cp->perfect) in tcindex_alloc_perfect_hash()
314 for (i = 0; i < cp->hash; i++) { in tcindex_alloc_perfect_hash()
315 err = tcf_exts_init(&cp->perfect[i].exts, net, in tcindex_alloc_perfect_hash()
319 cp->perfect[i].p = cp; in tcindex_alloc_perfect_hash()
325 tcindex_free_perfect_hash(cp); in tcindex_alloc_perfect_hash()
336 struct tcindex_data *cp = NULL, *oldp; in tcindex_set_parms() local
354 cp = kzalloc(sizeof(*cp), GFP_KERNEL); in tcindex_set_parms()
355 if (!cp) in tcindex_set_parms()
358 cp->mask = p->mask; in tcindex_set_parms()
359 cp->shift = p->shift; in tcindex_set_parms()
360 cp->hash = p->hash; in tcindex_set_parms()
361 cp->alloc_hash = p->alloc_hash; in tcindex_set_parms()
362 cp->fall_through = p->fall_through; in tcindex_set_parms()
363 cp->tp = tp; in tcindex_set_parms()
364 refcount_set(&cp->refcnt, 1); /* Paired with tcindex_destroy_work() */ in tcindex_set_parms()
367 cp->hash = nla_get_u32(tb[TCA_TCINDEX_HASH]); in tcindex_set_parms()
370 cp->mask = nla_get_u16(tb[TCA_TCINDEX_MASK]); in tcindex_set_parms()
373 cp->shift = nla_get_u32(tb[TCA_TCINDEX_SHIFT]); in tcindex_set_parms()
374 if (cp->shift > 16) { in tcindex_set_parms()
379 if (!cp->hash) { in tcindex_set_parms()
383 if ((cp->mask >> cp->shift) < PERFECT_HASH_THRESHOLD) in tcindex_set_parms()
384 cp->hash = (cp->mask >> cp->shift) + 1; in tcindex_set_parms()
386 cp->hash = DEFAULT_HASH_SIZE; in tcindex_set_parms()
392 if (tcindex_alloc_perfect_hash(net, cp) < 0) in tcindex_set_parms()
394 cp->alloc_hash = cp->hash; in tcindex_set_parms()
395 for (i = 0; i < min(cp->hash, p->hash); i++) in tcindex_set_parms()
396 cp->perfect[i].res = p->perfect[i].res; in tcindex_set_parms()
399 cp->h = p->h; in tcindex_set_parms()
401 err = tcindex_filter_result_init(&new_filter_result, cp, net); in tcindex_set_parms()
412 if (cp->perfect) { in tcindex_set_parms()
413 if (!valid_perfect_hash(cp) || in tcindex_set_parms()
414 cp->hash > cp->alloc_hash) in tcindex_set_parms()
416 } else if (cp->h && cp->hash != cp->alloc_hash) { in tcindex_set_parms()
422 cp->fall_through = nla_get_u32(tb[TCA_TCINDEX_FALL_THROUGH]); in tcindex_set_parms()
424 if (!cp->perfect && !cp->h) in tcindex_set_parms()
425 cp->alloc_hash = cp->hash; in tcindex_set_parms()
432 if (cp->perfect || valid_perfect_hash(cp)) in tcindex_set_parms()
433 if (handle >= cp->alloc_hash) in tcindex_set_parms()
438 if (!cp->perfect && !cp->h) { in tcindex_set_parms()
439 if (valid_perfect_hash(cp)) { in tcindex_set_parms()
440 if (tcindex_alloc_perfect_hash(net, cp) < 0) in tcindex_set_parms()
446 hash = kcalloc(cp->hash, in tcindex_set_parms()
453 cp->h = hash; in tcindex_set_parms()
458 if (cp->perfect) in tcindex_set_parms()
459 r = cp->perfect + handle; in tcindex_set_parms()
461 r = tcindex_lookup(cp, handle) ? : &new_filter_result; in tcindex_set_parms()
469 err = tcindex_filter_result_init(&f->result, cp, net); in tcindex_set_parms()
482 err = tcindex_filter_result_init(old_r, cp, net); in tcindex_set_parms()
493 rcu_assign_pointer(tp->root, cp); in tcindex_set_parms()
502 fp = cp->h + (handle % cp->hash); in tcindex_set_parms()
519 tcindex_free_perfect_hash(cp); in tcindex_set_parms()
521 kfree(cp->h); in tcindex_set_parms()
524 kfree(cp); in tcindex_set_parms()