]> git.proxmox.com Git - mirror_frr.git/blobdiff - ldpd/lde_lib.c
Merge pull request #5681 from opensourcerouting/manpage-rename
[mirror_frr.git] / ldpd / lde_lib.c
index c24a57b56a571728c0e079c6694aa478af0c305a..eb1a6d94349bb0c42de9148945c67ad9d2091866 100644 (file)
 
 #include "mpls.h"
 
-static __inline int     fec_compare(struct fec *, struct fec *);
+static __inline int     fec_compare(const struct fec *, const struct fec *);
 static int              lde_nbr_is_nexthop(struct fec_node *,
                            struct lde_nbr *);
 static void             fec_free(void *);
 static struct fec_node *fec_add(struct fec *fec);
 static struct fec_nh   *fec_nh_add(struct fec_node *, int, union ldpd_addr *,
-                           ifindex_t, uint8_t);
+                           ifindex_t, uint8_t, unsigned short);
 static void             fec_nh_del(struct fec_nh *);
 
 RB_GENERATE(fec_tree, fec, entry, fec_compare)
@@ -43,11 +43,11 @@ struct thread               *gc_timer;
 void
 fec_init(struct fec_tree *fh)
 {
-       RB_INIT(fh);
+       RB_INIT(fec_tree, fh);
 }
 
 static __inline int
-fec_compare(struct fec *a, struct fec *b)
+fec_compare(const struct fec *a, const struct fec *b)
 {
        if (a->type < b->type)
                return (-1);
@@ -129,7 +129,9 @@ fec_clear(struct fec_tree *fh, void (*free_cb)(void *))
 {
        struct fec      *f;
 
-       while ((f = RB_ROOT(fh)) != NULL) {
+       while (!RB_EMPTY(fec_tree, fh)) {
+               f = RB_ROOT(fec_tree, fh);
+
                fec_remove(fh, f);
                free_cb(f);
        }
@@ -159,7 +161,7 @@ rt_dump(pid_t pid)
        RB_FOREACH(f, fec_tree, &ft) {
                fn = (struct fec_node *)f;
                if (fn->local_label == NO_LABEL &&
-                   RB_EMPTY(&fn->downstream))
+                   RB_EMPTY(lde_map_head, &fn->downstream))
                        continue;
 
                memset(&rtctl, 0, sizeof(rtctl));
@@ -179,7 +181,7 @@ rt_dump(pid_t pid)
                }
 
                rtctl.local_label = fn->local_label;
-               if (RB_EMPTY(&fn->downstream)) {
+               if (RB_EMPTY(lde_map_head, &fn->downstream)) {
                        rtctl.in_use = 0;
                        rtctl.nexthop.s_addr = INADDR_ANY;
                        rtctl.remote_label = NO_LABEL;
@@ -229,12 +231,14 @@ fec_free(void *arg)
        struct fec_node *fn = arg;
        struct fec_nh   *fnh;
 
-       while ((fnh = LIST_FIRST(&fn->nexthops)))
+       while ((fnh = LIST_FIRST(&fn->nexthops))) {
                fec_nh_del(fnh);
-       if (!RB_EMPTY(&fn->downstream))
+               assert(fnh != LIST_FIRST(&fn->nexthops));
+       }
+       if (!RB_EMPTY(lde_map_head, &fn->downstream))
                log_warnx("%s: fec %s downstream list not empty", __func__,
                    log_fec(&fn->fec));
-       if (!RB_EMPTY(&fn->upstream))
+       if (!RB_EMPTY(lde_map_head, &fn->upstream))
                log_warnx("%s: fec %s upstream list not empty", __func__,
                    log_fec(&fn->fec));
 
@@ -258,8 +262,8 @@ fec_add(struct fec *fec)
 
        fn->fec = *fec;
        fn->local_label = NO_LABEL;
-       RB_INIT(&fn->upstream);
-       RB_INIT(&fn->downstream);
+       RB_INIT(lde_map_head, &fn->upstream);
+       RB_INIT(lde_map_head, &fn->downstream);
        LIST_INIT(&fn->nexthops);
 
        if (fec_insert(&ft, &fn->fec))
@@ -271,7 +275,7 @@ fec_add(struct fec *fec)
 
 struct fec_nh *
 fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance)
 {
        struct fec_nh   *fnh;
 
@@ -279,7 +283,8 @@ fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop,
                if (fnh->af == af &&
                    ldp_addrcmp(af, &fnh->nexthop, nexthop) == 0 &&
                    fnh->ifindex == ifindex &&
-                   fnh->priority == priority)
+                   fnh->route_type == route_type &&
+                   fnh->route_instance == route_instance)
                        return (fnh);
 
        return (NULL);
@@ -287,7 +292,7 @@ fec_nh_find(struct fec_node *fn, int af, union ldpd_addr *nexthop,
 
 static struct fec_nh *
 fec_nh_add(struct fec_node *fn, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance)
 {
        struct fec_nh   *fnh;
 
@@ -299,7 +304,8 @@ fec_nh_add(struct fec_node *fn, int af, union ldpd_addr *nexthop,
        fnh->nexthop = *nexthop;
        fnh->ifindex = ifindex;
        fnh->remote_label = NO_LABEL;
-       fnh->priority = priority;
+       fnh->route_type = route_type;
+       fnh->route_instance = route_instance;
        LIST_INSERT_HEAD(&fn->nexthops, fnh, entry);
 
        return (fnh);
@@ -314,7 +320,8 @@ fec_nh_del(struct fec_nh *fnh)
 
 void
 lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority, int connected, void *data)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance,
+    int connected, void *data)
 {
        struct fec_node         *fn;
        struct fec_nh           *fnh;
@@ -325,9 +332,10 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop,
        if (data)
                fn->data = data;
 
-       fnh = fec_nh_find(fn, af, nexthop, ifindex, priority);
+       fnh = fec_nh_find(fn, af, nexthop, ifindex, route_type, route_instance);
        if (fnh == NULL)
-               fnh = fec_nh_add(fn, af, nexthop, ifindex, priority);
+               fnh = fec_nh_add(fn, af, nexthop, ifindex, route_type,
+                   route_instance);
        fnh->flags |= F_FEC_NH_NEW;
        if (connected)
                fnh->flags |= F_FEC_NH_CONNECTED;
@@ -335,7 +343,7 @@ lde_kernel_insert(struct fec *fec, int af, union ldpd_addr *nexthop,
 
 void
 lde_kernel_remove(struct fec *fec, int af, union ldpd_addr *nexthop,
-    ifindex_t ifindex, uint8_t priority)
+    ifindex_t ifindex, uint8_t route_type, unsigned short route_instance)
 {
        struct fec_node         *fn;
        struct fec_nh           *fnh;
@@ -344,7 +352,7 @@ lde_kernel_remove(struct fec *fec, int af, union ldpd_addr *nexthop,
        if (fn == NULL)
                /* route lost */
                return;
-       fnh = fec_nh_find(fn, af, nexthop, ifindex, priority);
+       fnh = fec_nh_find(fn, af, nexthop, ifindex, route_type, route_instance);
        if (fnh == NULL)
                /* route lost */
                return;
@@ -437,7 +445,6 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln)
        struct lde_req          *lre;
        struct lde_map          *me;
        struct l2vpn_pw         *pw;
-       int                      msgsource = 0;
 
        lde_map2fec(map, ln->id, &fec);
 
@@ -540,18 +547,12 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln)
                default:
                        break;
                }
-
-               msgsource = 1;
        }
        /* LMp.13 & LMp.16: Record the mapping from this peer */
        if (me == NULL)
                me = lde_map_add(ln, fn, 0);
        me->map = *map;
 
-       if (msgsource == 0)
-               /* LMp.13: just return since we use liberal lbl retention */
-               return;
-
        /*
         * LMp.17 - LMp.27 are unnecessary since we don't need to implement
         * loop detection. LMp.28 - LMp.30 are unnecessary because we are
@@ -918,10 +919,13 @@ lde_gc_timer(struct thread *thread)
                fn = (struct fec_node *) fec;
 
                if (!LIST_EMPTY(&fn->nexthops) ||
-                   !RB_EMPTY(&fn->downstream) ||
-                   !RB_EMPTY(&fn->upstream))
+                   !RB_EMPTY(lde_map_head, &fn->downstream) ||
+                   !RB_EMPTY(lde_map_head, &fn->upstream))
                        continue;
 
+               if (fn->local_label != NO_LABEL)
+                       lde_free_label(fn->local_label);
+
                fec_remove(&ft, &fn->fec);
                free(fn);
                count++;
@@ -939,8 +943,9 @@ void
 lde_gc_start_timer(void)
 {
        THREAD_TIMER_OFF(gc_timer);
-       gc_timer = thread_add_timer(master, lde_gc_timer, NULL,
-           LDE_GC_INTERVAL);
+       gc_timer = NULL;
+       thread_add_timer(master, lde_gc_timer, NULL, LDE_GC_INTERVAL,
+                        &gc_timer);
 }
 
 void