]> git.proxmox.com Git - mirror_frr.git/blobdiff - ripngd/ripng_offset.c
Merge pull request #12780 from opensourcerouting/spdx-license-id
[mirror_frr.git] / ripngd / ripng_offset.c
index 278df758924164116f9a21c7f48f0a4af5416cca..ba3ba558afda91a986556b63b4005c574b1c3bd6 100644 (file)
@@ -1,21 +1,6 @@
+// SPDX-License-Identifier: GPL-2.0-or-later
 /* RIPng offset-list
  * Copyright (C) 2000 Kunihiro Ishiguro <kunihiro@zebra.org>
- *
- * This file is part of GNU Zebra.
- *
- * GNU Zebra is free software; you can redistribute it and/or modify it
- * under the terms of the GNU General Public License as published by the
- * Free Software Foundation; either version 2, or (at your option) any
- * later version.
- *
- * GNU Zebra is distributed in the hope that it will be useful, but
- * WITHOUT ANY WARRANTY; without even the implied warranty of
- * 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 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
  */
 
 /* RIPng support by Vincent Jardin <vincent.jardin@6wind.com>
@@ -33,7 +18,7 @@
 
 #include "ripngd/ripngd.h"
 
-static struct list *ripng_offset_list_master;
+DEFINE_MTYPE_STATIC(RIPNGD, RIPNG_OFFSET_LIST, "RIPng offset lst");
 
 #define OFFSET_LIST_IN_NAME(O)  ((O)->direct[RIPNG_OFFSET_LIST_IN].alist_name)
 #define OFFSET_LIST_IN_METRIC(O)  ((O)->direct[RIPNG_OFFSET_LIST_IN].metric)
@@ -41,21 +26,28 @@ static struct list *ripng_offset_list_master;
 #define OFFSET_LIST_OUT_NAME(O)  ((O)->direct[RIPNG_OFFSET_LIST_OUT].alist_name)
 #define OFFSET_LIST_OUT_METRIC(O)  ((O)->direct[RIPNG_OFFSET_LIST_OUT].metric)
 
-struct ripng_offset_list *ripng_offset_list_new(const char *ifname)
+struct ripng_offset_list *ripng_offset_list_new(struct ripng *ripng,
+                                               const char *ifname)
 {
        struct ripng_offset_list *new;
 
        new = XCALLOC(MTYPE_RIPNG_OFFSET_LIST,
                      sizeof(struct ripng_offset_list));
+       new->ripng = ripng;
        new->ifname = strdup(ifname);
-       listnode_add_sort(ripng_offset_list_master, new);
+       listnode_add_sort(ripng->offset_list_master, new);
 
        return new;
 }
 
 void ripng_offset_list_del(struct ripng_offset_list *offset)
 {
-       listnode_delete(ripng_offset_list_master, offset);
+       listnode_delete(offset->ripng->offset_list_master, offset);
+       ripng_offset_list_free(offset);
+}
+
+void ripng_offset_list_free(struct ripng_offset_list *offset)
+{
        if (OFFSET_LIST_IN_NAME(offset))
                free(OFFSET_LIST_IN_NAME(offset));
        if (OFFSET_LIST_OUT_NAME(offset))
@@ -64,27 +56,29 @@ void ripng_offset_list_del(struct ripng_offset_list *offset)
        XFREE(MTYPE_RIPNG_OFFSET_LIST, offset);
 }
 
-struct ripng_offset_list *ripng_offset_list_lookup(const char *ifname)
+struct ripng_offset_list *ripng_offset_list_lookup(struct ripng *ripng,
+                                                  const char *ifname)
 {
        struct ripng_offset_list *offset;
        struct listnode *node, *nnode;
 
-       for (ALL_LIST_ELEMENTS(ripng_offset_list_master, node, nnode, offset)) {
+       for (ALL_LIST_ELEMENTS(ripng->offset_list_master, node, nnode,
+                              offset)) {
                if (strcmp(offset->ifname, ifname) == 0)
                        return offset;
        }
        return NULL;
 }
 
-/* If metric is modifed return 1. */
-int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp,
-                              uint8_t *metric)
+/* If metric is modified return 1. */
+int ripng_offset_list_apply_in(struct ripng *ripng, struct prefix_ipv6 *p,
+                              struct interface *ifp, uint8_t *metric)
 {
        struct ripng_offset_list *offset;
        struct access_list *alist;
 
        /* Look up offset-list with interface name. */
-       offset = ripng_offset_list_lookup(ifp->name);
+       offset = ripng_offset_list_lookup(ripng, ifp->name);
        if (offset && OFFSET_LIST_IN_NAME(offset)) {
                alist = access_list_lookup(AFI_IP6,
                                           OFFSET_LIST_IN_NAME(offset));
@@ -98,7 +92,7 @@ int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp,
                return 0;
        }
        /* Look up offset-list without interface name. */
-       offset = ripng_offset_list_lookup("*");
+       offset = ripng_offset_list_lookup(ripng, "*");
        if (offset && OFFSET_LIST_IN_NAME(offset)) {
                alist = access_list_lookup(AFI_IP6,
                                           OFFSET_LIST_IN_NAME(offset));
@@ -114,15 +108,15 @@ int ripng_offset_list_apply_in(struct prefix_ipv6 *p, struct interface *ifp,
        return 0;
 }
 
-/* If metric is modifed return 1. */
-int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp,
-                               uint8_t *metric)
+/* If metric is modified return 1. */
+int ripng_offset_list_apply_out(struct ripng *ripng, struct prefix_ipv6 *p,
+                               struct interface *ifp, uint8_t *metric)
 {
        struct ripng_offset_list *offset;
        struct access_list *alist;
 
        /* Look up offset-list with interface name. */
-       offset = ripng_offset_list_lookup(ifp->name);
+       offset = ripng_offset_list_lookup(ripng, ifp->name);
        if (offset && OFFSET_LIST_OUT_NAME(offset)) {
                alist = access_list_lookup(AFI_IP6,
                                           OFFSET_LIST_OUT_NAME(offset));
@@ -137,7 +131,7 @@ int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp,
        }
 
        /* Look up offset-list without interface name. */
-       offset = ripng_offset_list_lookup("*");
+       offset = ripng_offset_list_lookup(ripng, "*");
        if (offset && OFFSET_LIST_OUT_NAME(offset)) {
                alist = access_list_lookup(AFI_IP6,
                                           OFFSET_LIST_OUT_NAME(offset));
@@ -153,26 +147,7 @@ int ripng_offset_list_apply_out(struct prefix_ipv6 *p, struct interface *ifp,
        return 0;
 }
 
-static int offset_list_cmp(struct ripng_offset_list *o1,
-                          struct ripng_offset_list *o2)
+int offset_list_cmp(struct ripng_offset_list *o1, struct ripng_offset_list *o2)
 {
        return strcmp(o1->ifname, o2->ifname);
 }
-
-void ripng_offset_init(void)
-{
-       ripng_offset_list_master = list_new();
-       ripng_offset_list_master->cmp =
-               (int (*)(void *, void *))offset_list_cmp;
-       ripng_offset_list_master->del = (void (*)(void *))ripng_offset_list_del;
-}
-
-void ripng_offset_clean(void)
-{
-       list_delete(&ripng_offset_list_master);
-
-       ripng_offset_list_master = list_new();
-       ripng_offset_list_master->cmp =
-               (int (*)(void *, void *))offset_list_cmp;
-       ripng_offset_list_master->del = (void (*)(void *))ripng_offset_list_del;
-}