]> git.proxmox.com Git - mirror_frr.git/blobdiff - ldpd/lde_lib.c
Merge pull request #2932 from donaldsharp/ferr_fix
[mirror_frr.git] / ldpd / lde_lib.c
index 89aa6d4201593d64f8735bb04c494ddfd8705c26..28e455c7a58fc7009c64e6b96a0d9f76ed4d872d 100644 (file)
@@ -25,7 +25,7 @@
 
 #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 *);
@@ -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))
@@ -396,7 +400,7 @@ lde_kernel_update(struct fec *fec)
                lde_gc_start_timer();
        } else {
                fn->local_label = lde_update_label(fn);
-               if (fn->local_label != NO_LABEL && RB_EMPTY(&fn->upstream))
+               if (fn->local_label != NO_LABEL)
                        /* FEC.1: perform lsr label distribution procedure */
                        RB_FOREACH(ln, nbr_tree, &lde_nbrs)
                                lde_send_labelmapping(ln, fn, 1);
@@ -437,7 +441,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);
 
@@ -531,6 +534,8 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln)
                                pw->remote_mtu = map->fec.pwid.ifmtu;
                        if (map->flags & F_MAP_PW_STATUS)
                                pw->remote_status = map->pw_status;
+                       else
+                               pw->remote_status = PW_FORWARDING;
                        fnh->remote_label = map->label;
                        if (l2vpn_pw_ok(pw, fnh))
                                lde_send_change_klabel(fn, fnh);
@@ -538,18 +543,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
@@ -780,6 +779,7 @@ lde_check_withdraw(struct map *map, struct lde_nbr *ln)
                        pw = (struct l2vpn_pw *) fn->data;
                        if (pw == NULL)
                                continue;
+                       pw->remote_status = PW_NOT_FORWARDING;
                        break;
                default:
                        break;
@@ -808,6 +808,7 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln)
        struct fec_node *fn;
        struct fec_nh   *fnh;
        struct lde_map  *me;
+       struct l2vpn_pw *pw;
 
        /* LWd.2: send label release */
        lde_send_labelrelease(ln, NULL, map, map->label);
@@ -831,6 +832,9 @@ lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln)
                        case FEC_TYPE_PWID:
                                if (f->u.pwid.lsr_id.s_addr != ln->id.s_addr)
                                        continue;
+                               pw = (struct l2vpn_pw *) fn->data;
+                               if (pw)
+                                       pw->remote_status = PW_NOT_FORWARDING;
                                break;
                        default:
                                break;
@@ -911,8 +915,8 @@ 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;
 
                fec_remove(&ft, &fn->fec);