head = iptree->head;
- PATRICIA_WALK_ALL(head, node)
+ PATRICIA_WALK_CLEAR(head, node)
{
- node->exts[index]=NULL;
- } PATRICIA_WALK_END;
+ if ( node->exts[index] ) {
+ if (node->prefix) {
+ if (node->prefix->ref_count == 1) {
+ patricia_remove(iptree, node);
+ } else {
+ patricia_deref_prefix(node->prefix);
+ }
+ }
+ }
+ node->exts[index]=NULL;
+ } PATRICIA_WALK_CLEAR_END;
}
} \
} while (0)
+#define PATRICIA_WALK_CLEAR(Xhead, Xnode) \
+ patricia_node_t *Xstack[PATRICIA_MAXBITS+1]; \
+ patricia_node_t **Xsp = Xstack; \
+ patricia_node_t *Xrn = (Xhead); \
+ while ((Xnode = Xrn)) { \
+ patricia_node_t *l = Xrn->l; \
+ patricia_node_t *r = Xrn->r; \
+
+#define PATRICIA_WALK_CLEAR_END \
+ if (l) { \
+ if (r) { \
+ *Xsp++ = r; \
+ } \
+ Xrn = l; \
+ } else if (r) { \
+ Xrn = r; \
+ } else if (Xsp != Xstack) { \
+ Xrn = *(--Xsp); \
+ } else { \
+ Xrn = (patricia_node_t *) 0; \
+ } \
+ }
+
#endif /* _PATRICIA_H */