static void fib6_purge_rt(struct rt6_info *rt, struct fib6_node *fn, struct net *net) { if (atomic_read(&rt->rt6i_ref) != 1) { /* This route is used as dummy address holder in some split * nodes. It is not leaked, but it still holds other resources, * which must be released in time. So, scan ascendant nodes * and replace dummy references to this route with references * to still alive ones. */ while (fn) { if (!(fn->fn_flags & RTN_RTINFO) && fn->leaf == rt) { fn->leaf = fib6_find_prefix(net, fn); atomic_inc(&fn->leaf->rt6i_ref); rt6_release(rt); } fn = fn->parent; } /* No more references are possible at this point. */ BUG_ON(atomic_read(&rt->rt6i_ref) != 1); } }
static void fib6_repair_tree(struct fib6_node *fn) { int children; int nstate; struct fib6_node *child, *pn; struct fib6_walker_t *w; int iter = 0; for (;;) { RT6_TRACE("fixing tree: plen=%d iter=%d\n", fn->fn_bit, iter); iter++; BUG_TRAP(!(fn->fn_flags&RTN_RTINFO)); BUG_TRAP(!(fn->fn_flags&RTN_TL_ROOT)); BUG_TRAP(fn->leaf==NULL); children = 0; child = NULL; if (fn->right) child = fn->right, children |= 1; if (fn->left) child = fn->left, children |= 2; if (children == 3 || SUBTREE(fn) #ifdef CONFIG_IPV6_SUBTREES /* Subtree root (i.e. fn) may have one child */ || (children && fn->fn_flags&RTN_ROOT) #endif ) { fn->leaf = fib6_find_prefix(fn); #if RT6_DEBUG >= 2 if (fn->leaf==NULL) { BUG_TRAP(fn->leaf); fn->leaf = &ip6_null_entry; } #endif atomic_inc(&fn->leaf->rt6i_ref); return; } pn = fn->parent; #ifdef CONFIG_IPV6_SUBTREES if (SUBTREE(pn) == fn) { BUG_TRAP(fn->fn_flags&RTN_ROOT); SUBTREE(pn) = NULL; nstate = FWS_L; } else { BUG_TRAP(!(fn->fn_flags&RTN_ROOT)); #endif if (pn->right == fn) pn->right = child; else if (pn->left == fn) pn->left = child; #if RT6_DEBUG >= 2 else BUG_TRAP(0); #endif if (child) child->parent = pn; nstate = FWS_R; #ifdef CONFIG_IPV6_SUBTREES } #endif FOR_WALKERS(w) { if (child == NULL) { if (w->root == fn) { w->root = w->node = NULL; RT6_TRACE("W %p adjusted by delroot 1\n", w); } else if (w->node == fn) { RT6_TRACE("W %p adjusted by delnode 1, s=%d/%d\n", w, w->state, nstate); w->node = pn; w->state = nstate; } } else { if (w->root == fn) { w->root = child; RT6_TRACE("W %p adjusted by delroot 2\n", w); } if (w->node == fn) { w->node = child; if (children&2) { RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state); w->state = w->state>=FWS_R ? FWS_U : FWS_INIT; } else { RT6_TRACE("W %p adjusted by delnode 2, s=%d\n", w, w->state); w->state = w->state>=FWS_C ? FWS_U : FWS_INIT; } } } } node_free(fn); if (pn->fn_flags&RTN_RTINFO || SUBTREE(pn)) return; rt6_release(pn->leaf); pn->leaf = NULL; fn = pn; } }