+ remove_address_from_interface(i);
+
+ p = i;
+ }
+ if (p)
+ remove_from_map_and_free(map, p);
+}
+
+static inline int add_nid_to_list(struct nid_list **head, nid_t nid)
+{
+ struct nid_list *i, *new;
+
+ for (i = *head; i && i->next && i->next->nid < nid; i = i->next)
+ ;
+ /* check if this nid is first in the list */
+ if (i && i->nid == nid)
+ return 0;
+ /* check if it's already in the list */
+ if (i && i->next && i->next->nid == nid)
+ return 0;
+
+ /* add it */
+ new = calloc(1, sizeof(struct nid_list));
+ if (!new)
+ return -1;
+ new->nid = nid;
+
+ /* this is the lowest nid in the list */
+ if (i == *head) {
+ *head = new;
+ new->next = i;
+ }
+ /* in the middle/at the end */
+ else if (i) {
+ new->next = i->next;
+ i->next = new;
+ }
+ /* there was no list */
+ else
+ *head = new;
+
+ return 1;
+}
+
+static inline void free_nid_list(struct nid_list *head)
+{
+ struct nid_list *p;
+ for (p = NULL; head; head = head->next) {
+ if (p)
+ free(p);
+ p = head;
+ }
+ if (p)
+ free(p);
+}
+
+static inline void cleanup_nid(struct nid_prefix_map *map,
+ nid_t nid)
+{
+ struct nid_prefix_map *i, *p = NULL;
+ for (i = map->n.next; i->nid < nid; i = i->n.next)
+ ;
+ /* this nid doesn't have any entries in the map */
+ if (i->nid != nid)
+ return;
+ for (; i->nid == nid; i = i->n.next) {
+ if (p)
+ remove_from_map_and_free(map, p);
+ remove_address_from_interface(i);
+ p = i;
+ }
+ if (p)
+ remove_from_map_and_free(map, p);
+}