These functions seem to be a maze of linear operations over the entire set of nodes: yuck. We need to look for better ways. One choice is to memoize results at some level; another is to precompute results at some level; another is to replace linear low-level ops with sublinear ones.
David suggest that optimizing nodelist_add_node_and_family() would suffice here. The expensive part of that is the linear iteration through the entire nodelist. What if we use freebsd's tree.h to build a red-black tree of nodes sorted by address, so that it's easy to get "all the nodes with the same prefix as X"?