]> git.proxmox.com Git - mirror_frr.git/blobdiff - lib/linklist.c
*: make consistent & update GPLv2 file headers
[mirror_frr.git] / lib / linklist.c
index 370b2fa615e6aa7a1f6bb62e2592b84b55d4d352..0aee54d44ce25a81c5e65f541cfdf7fde5945505 100644 (file)
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * General Public License for more details.
  *
- * You should have received a copy of the GNU General Public License
- * along with GNU Zebra; see the file COPYING.  If not, write to the Free
- * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
- * 02111-1307, USA.
+ * You should have received a copy of the GNU General Public License along
+ * with this program; see the file COPYING; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
 #include <zebra.h>
@@ -24,6 +23,9 @@
 #include "linklist.h"
 #include "memory.h"
 
+DEFINE_MTYPE_STATIC(LIB, LINK_LIST, "Link List")
+DEFINE_MTYPE_STATIC(LIB, LINK_NODE, "Link Node")
+
 /* Allocate new list. */
 struct list *
 list_new (void)
@@ -122,7 +124,7 @@ listnode_add_sort (struct list *list, void *val)
   list->count++;
 }
 
-void
+struct listnode *
 listnode_add_after (struct list *list, struct listnode *pp, void *val)
 {
   struct listnode *nn;
@@ -157,8 +159,54 @@ listnode_add_after (struct list *list, struct listnode *pp, void *val)
       pp->next = nn;
     }
   list->count++;
+  return nn;
+}
+
+struct listnode *
+listnode_add_before (struct list *list, struct listnode *pp, void *val)
+{
+  struct listnode *nn;
+
+  assert (val != NULL);
+
+  nn = listnode_new ();
+  nn->data = val;
+
+  if (pp == NULL)
+    {
+      if (list->tail)
+        list->tail->next = nn;
+      else
+        list->head = nn;
+
+      nn->prev = list->tail;
+      nn->next = pp;
+
+      list->tail = nn;
+    }
+  else
+    {
+      if (pp->prev)
+       pp->prev->next = nn;
+      else
+       list->head = nn;
+
+      nn->prev = pp->prev;
+      nn->next = pp;
+
+      pp->prev = nn;
+    }
+  list->count++;
+  return nn;
 }
 
+/* Move given listnode to tail of the list */
+void
+listnode_move_to_tail (struct list *l, struct listnode *n)
+{
+  LISTNODE_DETACH(l,n);
+  LISTNODE_ATTACH(l,n);
+}
 
 /* Delete specific date pointer from the list. */
 void
@@ -259,52 +307,6 @@ list_delete_node (struct list *list, struct listnode *node)
   listnode_free (node);
 }
 
-/* ospf_spf.c */
-void
-list_add_node_prev (struct list *list, struct listnode *current, void *val)
-{
-  struct listnode *node;
-  
-  assert (val != NULL);
-  
-  node = listnode_new ();
-  node->next = current;
-  node->data = val;
-
-  if (current->prev == NULL)
-    list->head = node;
-  else
-    current->prev->next = node;
-
-  node->prev = current->prev;
-  current->prev = node;
-
-  list->count++;
-}
-
-/* ospf_spf.c */
-void
-list_add_node_next (struct list *list, struct listnode *current, void *val)
-{
-  struct listnode *node;
-  
-  assert (val != NULL);
-  
-  node = listnode_new ();
-  node->prev = current;
-  node->data = val;
-
-  if (current->next == NULL)
-    list->tail = node;
-  else
-    current->next->prev = node;
-
-  node->next = current->next;
-  current->next = node;
-
-  list->count++;
-}
-
 /* ospf_spf.c */
 void
 list_add_list (struct list *l, struct list *m)