]> 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 edf686537fdd5cb37832d501e4cef7f7a19838fe..eb1a6d94349bb0c42de9148945c67ad9d2091866 100644 (file)
@@ -31,7 +31,7 @@ static int             lde_nbr_is_nexthop(struct fec_node *,
 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)
@@ -129,7 +129,9 @@ fec_clear(struct fec_tree *fh, void (*free_cb)(void *))
 {
        struct fec      *f;
 
-       while ((f = RB_ROOT(fec_tree, fh)) != NULL) {
+       while (!RB_EMPTY(fec_tree, fh)) {
+               f = RB_ROOT(fec_tree, fh);
+
                fec_remove(fh, f);
                free_cb(f);
        }
@@ -229,8 +231,10 @@ 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);
+               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));
@@ -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;
@@ -396,8 +404,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(lde_map_head, &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);
@@ -531,6 +538,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);
@@ -774,6 +783,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;
@@ -802,6 +812,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);
@@ -825,6 +836,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;
@@ -909,6 +923,9 @@ lde_gc_timer(struct thread *thread)
                    !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++;