]>
git.proxmox.com Git - mirror_frr.git/blob - ldpd/lde_lib.c
4 * Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
5 * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
7 * Permission to use, copy, modify, and distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
28 static __inline
int fec_compare(const struct fec
*, const struct fec
*);
29 static int lde_nbr_is_nexthop(struct fec_node
*,
31 static void fec_free(void *);
32 static struct fec_node
*fec_add(struct fec
*fec
);
33 static struct fec_nh
*fec_nh_add(struct fec_node
*, int, union ldpd_addr
*,
35 static void fec_nh_del(struct fec_nh
*);
37 RB_GENERATE(fec_tree
, fec
, entry
, fec_compare
)
39 struct fec_tree ft
= RB_INITIALIZER(&ft
);
40 struct thread
*gc_timer
;
42 /* FEC tree functions */
44 fec_init(struct fec_tree
*fh
)
46 RB_INIT(fec_tree
, fh
);
50 fec_compare(const struct fec
*a
, const struct fec
*b
)
52 if (a
->type
< b
->type
)
54 if (a
->type
> b
->type
)
59 if (ntohl(a
->u
.ipv4
.prefix
.s_addr
) <
60 ntohl(b
->u
.ipv4
.prefix
.s_addr
))
62 if (ntohl(a
->u
.ipv4
.prefix
.s_addr
) >
63 ntohl(b
->u
.ipv4
.prefix
.s_addr
))
65 if (a
->u
.ipv4
.prefixlen
< b
->u
.ipv4
.prefixlen
)
67 if (a
->u
.ipv4
.prefixlen
> b
->u
.ipv4
.prefixlen
)
71 if (memcmp(&a
->u
.ipv6
.prefix
, &b
->u
.ipv6
.prefix
,
72 sizeof(struct in6_addr
)) < 0)
74 if (memcmp(&a
->u
.ipv6
.prefix
, &b
->u
.ipv6
.prefix
,
75 sizeof(struct in6_addr
)) > 0)
77 if (a
->u
.ipv6
.prefixlen
< b
->u
.ipv6
.prefixlen
)
79 if (a
->u
.ipv6
.prefixlen
> b
->u
.ipv6
.prefixlen
)
83 if (a
->u
.pwid
.type
< b
->u
.pwid
.type
)
85 if (a
->u
.pwid
.type
> b
->u
.pwid
.type
)
87 if (a
->u
.pwid
.pwid
< b
->u
.pwid
.pwid
)
89 if (a
->u
.pwid
.pwid
> b
->u
.pwid
.pwid
)
91 if (ntohl(a
->u
.pwid
.lsr_id
.s_addr
) <
92 ntohl(b
->u
.pwid
.lsr_id
.s_addr
))
94 if (ntohl(a
->u
.pwid
.lsr_id
.s_addr
) >
95 ntohl(b
->u
.pwid
.lsr_id
.s_addr
))
104 fec_find(struct fec_tree
*fh
, struct fec
*f
)
106 return (RB_FIND(fec_tree
, fh
, f
));
110 fec_insert(struct fec_tree
*fh
, struct fec
*f
)
112 if (RB_INSERT(fec_tree
, fh
, f
) != NULL
)
118 fec_remove(struct fec_tree
*fh
, struct fec
*f
)
120 if (RB_REMOVE(fec_tree
, fh
, f
) == NULL
) {
121 log_warnx("%s failed for %s", __func__
, log_fec(f
));
128 fec_clear(struct fec_tree
*fh
, void (*free_cb
)(void *))
132 while ((f
= RB_ROOT(fec_tree
, fh
)) != NULL
) {
138 /* routing table functions */
140 lde_nbr_is_nexthop(struct fec_node
*fn
, struct lde_nbr
*ln
)
144 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
)
145 if (lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
157 static struct ctl_rt rtctl
;
159 RB_FOREACH(f
, fec_tree
, &ft
) {
160 fn
= (struct fec_node
*)f
;
161 if (fn
->local_label
== NO_LABEL
&&
162 RB_EMPTY(lde_map_head
, &fn
->downstream
))
165 memset(&rtctl
, 0, sizeof(rtctl
));
166 switch (fn
->fec
.type
) {
169 rtctl
.prefix
.v4
= fn
->fec
.u
.ipv4
.prefix
;
170 rtctl
.prefixlen
= fn
->fec
.u
.ipv4
.prefixlen
;
174 rtctl
.prefix
.v6
= fn
->fec
.u
.ipv6
.prefix
;
175 rtctl
.prefixlen
= fn
->fec
.u
.ipv6
.prefixlen
;
181 rtctl
.local_label
= fn
->local_label
;
182 if (RB_EMPTY(lde_map_head
, &fn
->downstream
)) {
184 rtctl
.nexthop
.s_addr
= INADDR_ANY
;
185 rtctl
.remote_label
= NO_LABEL
;
186 rtctl
.no_downstream
= 1;
188 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_BEGIN
, 0, pid
, &rtctl
,
191 RB_FOREACH(me
, lde_map_head
, &fn
->upstream
) {
192 rtctl
.nexthop
= me
->nexthop
->id
;
193 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_SENT
, 0, pid
,
194 &rtctl
, sizeof(rtctl
));
197 RB_FOREACH(me
, lde_map_head
, &fn
->downstream
) {
198 rtctl
.in_use
= lde_nbr_is_nexthop(fn
, me
->nexthop
);
199 rtctl
.nexthop
= me
->nexthop
->id
;
200 rtctl
.remote_label
= me
->map
.label
;
201 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_RCVD
, 0, pid
,
202 &rtctl
, sizeof(rtctl
));
204 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_END
, 0, pid
, &rtctl
,
210 fec_snap(struct lde_nbr
*ln
)
215 RB_FOREACH(f
, fec_tree
, &ft
) {
216 fn
= (struct fec_node
*)f
;
217 if (fn
->local_label
== NO_LABEL
)
220 lde_send_labelmapping(ln
, fn
, 0);
223 lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END
, ln
->peerid
, 0, NULL
, 0);
229 struct fec_node
*fn
= arg
;
232 while ((fnh
= LIST_FIRST(&fn
->nexthops
))) {
234 assert(fnh
!= LIST_FIRST(&fn
->nexthops
));
236 if (!RB_EMPTY(lde_map_head
, &fn
->downstream
))
237 log_warnx("%s: fec %s downstream list not empty", __func__
,
239 if (!RB_EMPTY(lde_map_head
, &fn
->upstream
))
240 log_warnx("%s: fec %s upstream list not empty", __func__
,
249 fec_clear(&ft
, fec_free
);
252 static struct fec_node
*
253 fec_add(struct fec
*fec
)
257 fn
= calloc(1, sizeof(*fn
));
262 fn
->local_label
= NO_LABEL
;
263 RB_INIT(lde_map_head
, &fn
->upstream
);
264 RB_INIT(lde_map_head
, &fn
->downstream
);
265 LIST_INIT(&fn
->nexthops
);
267 if (fec_insert(&ft
, &fn
->fec
))
268 log_warnx("failed to add %s to ft tree",
275 fec_nh_find(struct fec_node
*fn
, int af
, union ldpd_addr
*nexthop
,
276 ifindex_t ifindex
, uint8_t priority
)
280 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
)
282 ldp_addrcmp(af
, &fnh
->nexthop
, nexthop
) == 0 &&
283 fnh
->ifindex
== ifindex
&&
284 fnh
->priority
== priority
)
290 static struct fec_nh
*
291 fec_nh_add(struct fec_node
*fn
, int af
, union ldpd_addr
*nexthop
,
292 ifindex_t ifindex
, uint8_t priority
)
296 fnh
= calloc(1, sizeof(*fnh
));
301 fnh
->nexthop
= *nexthop
;
302 fnh
->ifindex
= ifindex
;
303 fnh
->remote_label
= NO_LABEL
;
304 fnh
->priority
= priority
;
305 LIST_INSERT_HEAD(&fn
->nexthops
, fnh
, entry
);
311 fec_nh_del(struct fec_nh
*fnh
)
313 LIST_REMOVE(fnh
, entry
);
318 lde_kernel_insert(struct fec
*fec
, int af
, union ldpd_addr
*nexthop
,
319 ifindex_t ifindex
, uint8_t priority
, int connected
, void *data
)
324 fn
= (struct fec_node
*)fec_find(&ft
, fec
);
330 fnh
= fec_nh_find(fn
, af
, nexthop
, ifindex
, priority
);
332 fnh
= fec_nh_add(fn
, af
, nexthop
, ifindex
, priority
);
333 fnh
->flags
|= F_FEC_NH_NEW
;
335 fnh
->flags
|= F_FEC_NH_CONNECTED
;
339 lde_kernel_remove(struct fec
*fec
, int af
, union ldpd_addr
*nexthop
,
340 ifindex_t ifindex
, uint8_t priority
)
345 fn
= (struct fec_node
*)fec_find(&ft
, fec
);
349 fnh
= fec_nh_find(fn
, af
, nexthop
, ifindex
, priority
);
354 lde_send_delete_klabel(fn
, fnh
);
359 * Whenever a route is changed, zebra advertises its new version without
360 * withdrawing the old one. So, after processing a ZEBRA_REDISTRIBUTE_IPV[46]_ADD
361 * message, we need to check for nexthops that were removed and, for each of
362 * them (if any), withdraw the associated labels from zebra.
365 lde_kernel_update(struct fec
*fec
)
368 struct fec_nh
*fnh
, *safe
;
372 fn
= (struct fec_node
*)fec_find(&ft
, fec
);
376 LIST_FOREACH_SAFE(fnh
, &fn
->nexthops
, entry
, safe
) {
377 if (fnh
->flags
& F_FEC_NH_NEW
)
378 fnh
->flags
&= ~F_FEC_NH_NEW
;
380 lde_send_delete_klabel(fn
, fnh
);
385 if (LIST_EMPTY(&fn
->nexthops
)) {
386 RB_FOREACH(ln
, nbr_tree
, &lde_nbrs
)
387 lde_send_labelwithdraw(ln
, fn
, NULL
, NULL
);
391 * Do not deallocate the local label now, do that only in the
392 * LIB garbage collector. This will prevent ldpd from changing
393 * the input label of some prefixes too often when running on
394 * an unstable network. Also, restart the garbage collector
395 * timer so that labels are deallocated only when the network
398 lde_gc_start_timer();
400 fn
->local_label
= lde_update_label(fn
);
401 if (fn
->local_label
!= NO_LABEL
)
402 /* FEC.1: perform lsr label distribution procedure */
403 RB_FOREACH(ln
, nbr_tree
, &lde_nbrs
)
404 lde_send_labelmapping(ln
, fn
, 1);
407 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
408 lde_send_change_klabel(fn
, fnh
);
410 switch (fn
->fec
.type
) {
413 ln
= lde_nbr_find_by_addr(fnh
->af
, &fnh
->nexthop
);
416 ln
= lde_nbr_find_by_lsrid(fn
->fec
.u
.pwid
.lsr_id
);
425 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
428 lde_check_mapping(&me
->map
, ln
);
434 lde_check_mapping(struct map
*map
, struct lde_nbr
*ln
)
443 lde_map2fec(map
, ln
->id
, &fec
);
447 if (lde_acl_check(ldeconf
->ipv4
.acl_label_accept_from
,
448 AF_INET
, (union ldpd_addr
*)&ln
->id
, 32) != FILTER_PERMIT
)
450 if (lde_acl_check(ldeconf
->ipv4
.acl_label_accept_for
,
451 AF_INET
, (union ldpd_addr
*)&fec
.u
.ipv4
.prefix
,
452 fec
.u
.ipv4
.prefixlen
) != FILTER_PERMIT
)
456 if (lde_acl_check(ldeconf
->ipv6
.acl_label_accept_from
,
457 AF_INET
, (union ldpd_addr
*)&ln
->id
, 32) != FILTER_PERMIT
)
459 if (lde_acl_check(ldeconf
->ipv6
.acl_label_accept_for
,
460 AF_INET6
, (union ldpd_addr
*)&fec
.u
.ipv6
.prefix
,
461 fec
.u
.ipv6
.prefixlen
) != FILTER_PERMIT
)
468 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
472 /* LMp.1: first check if we have a pending request running */
473 lre
= (struct lde_req
*)fec_find(&ln
->sent_req
, &fn
->fec
);
475 /* LMp.2: delete record of outstanding label request */
476 lde_req_del(ln
, lre
, 1);
478 /* RFC 4447 control word and status tlv negotiation */
479 if (map
->type
== MAP_TYPE_PWID
&& l2vpn_pw_negotiate(ln
, fn
, map
))
483 * LMp.3 - LMp.8: loop detection - unnecessary for frame-mode
488 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
491 if (me
->map
.label
!= map
->label
&& lre
== NULL
) {
493 lde_send_labelrelease(ln
, fn
, NULL
, me
->map
.label
);
496 * Can not use lde_nbr_find_by_addr() because there's
497 * the possibility of multipath.
499 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
500 if (lde_address_find(ln
, fnh
->af
,
501 &fnh
->nexthop
) == NULL
)
504 lde_send_delete_klabel(fn
, fnh
);
505 fnh
->remote_label
= NO_LABEL
;
511 * LMp.11 - 12: consider multiple nexthops in order to
514 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
515 /* LMp.15: install FEC in FIB */
519 if (!lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
522 fnh
->remote_label
= map
->label
;
523 lde_send_change_klabel(fn
, fnh
);
526 pw
= (struct l2vpn_pw
*) fn
->data
;
530 pw
->remote_group
= map
->fec
.pwid
.group_id
;
531 if (map
->flags
& F_MAP_PW_IFMTU
)
532 pw
->remote_mtu
= map
->fec
.pwid
.ifmtu
;
533 if (map
->flags
& F_MAP_PW_STATUS
)
534 pw
->remote_status
= map
->pw_status
;
536 pw
->remote_status
= PW_FORWARDING
;
537 fnh
->remote_label
= map
->label
;
538 if (l2vpn_pw_ok(pw
, fnh
))
539 lde_send_change_klabel(fn
, fnh
);
545 /* LMp.13 & LMp.16: Record the mapping from this peer */
547 me
= lde_map_add(ln
, fn
, 0);
551 * LMp.17 - LMp.27 are unnecessary since we don't need to implement
552 * loop detection. LMp.28 - LMp.30 are unnecessary because we are
558 lde_check_request(struct map
*map
, struct lde_nbr
*ln
)
565 /* wildcard label request */
566 if (map
->type
== MAP_TYPE_TYPED_WCARD
) {
567 lde_check_request_wcard(map
, ln
);
571 /* LRq.1: skip loop detection (not necessary) */
573 /* LRq.2: is there a next hop for fec? */
574 lde_map2fec(map
, ln
->id
, &fec
);
575 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
576 if (fn
== NULL
|| LIST_EMPTY(&fn
->nexthops
)) {
577 /* LRq.5: send No Route notification */
578 lde_send_notification(ln
, S_NO_ROUTE
, map
->msg_id
,
579 htons(MSG_TYPE_LABELREQUEST
));
583 /* LRq.3: is MsgSource the next hop? */
584 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
588 if (!lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
591 /* LRq.4: send Loop Detected notification */
592 lde_send_notification(ln
, S_LOOP_DETECTED
, map
->msg_id
,
593 htons(MSG_TYPE_LABELREQUEST
));
600 /* LRq.6: first check if we have a pending request running */
601 lre
= (struct lde_req
*)fec_find(&ln
->recv_req
, &fn
->fec
);
603 /* LRq.7: duplicate request */
606 /* LRq.8: record label request */
607 lre
= lde_req_add(ln
, &fn
->fec
, 0);
609 lre
->msg_id
= ntohl(map
->msg_id
);
611 /* LRq.9: perform LSR label distribution */
612 lde_send_labelmapping(ln
, fn
, 1);
615 * LRq.10: do nothing (Request Never) since we use liberal
617 * LRq.11 - 12 are unnecessary since we are merging capable.
622 lde_check_request_wcard(struct map
*map
, struct lde_nbr
*ln
)
628 RB_FOREACH(f
, fec_tree
, &ft
) {
629 fn
= (struct fec_node
*)f
;
631 /* only a typed wildcard is possible here */
632 if (lde_wildcard_apply(map
, &fn
->fec
, NULL
) == 0)
635 /* LRq.2: is there a next hop for fec? */
636 if (LIST_EMPTY(&fn
->nexthops
))
639 /* LRq.6: first check if we have a pending request running */
640 lre
= (struct lde_req
*)fec_find(&ln
->recv_req
, &fn
->fec
);
642 /* LRq.7: duplicate request */
645 /* LRq.8: record label request */
646 lre
= lde_req_add(ln
, &fn
->fec
, 0);
648 lre
->msg_id
= ntohl(map
->msg_id
);
650 /* LRq.9: perform LSR label distribution */
651 lde_send_labelmapping(ln
, fn
, 1);
656 lde_check_release(struct map
*map
, struct lde_nbr
*ln
)
660 struct lde_wdraw
*lw
;
662 struct fec
*pending_map
;
664 /* wildcard label release */
665 if (map
->type
== MAP_TYPE_WILDCARD
||
666 map
->type
== MAP_TYPE_TYPED_WCARD
||
667 (map
->type
== MAP_TYPE_PWID
&& !(map
->flags
& F_MAP_PW_ID
))) {
668 lde_check_release_wcard(map
, ln
);
672 lde_map2fec(map
, ln
->id
, &fec
);
673 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
674 /* LRl.1: does FEC match a known FEC? */
678 /* LRl.6: check sent map list and remove it if available */
679 me
= (struct lde_map
*)fec_find(&ln
->sent_map
, &fn
->fec
);
680 if (me
&& (map
->label
== NO_LABEL
|| map
->label
== me
->map
.label
))
681 lde_map_del(ln
, me
, 1);
683 /* LRl.3: first check if we have a pending withdraw running */
684 lw
= (struct lde_wdraw
*)fec_find(&ln
->sent_wdraw
, &fn
->fec
);
685 if (lw
&& (map
->label
== NO_LABEL
|| map
->label
== lw
->label
)) {
686 /* LRl.4: delete record of outstanding label withdraw */
687 lde_wdraw_del(ln
, lw
);
689 /* send pending label mapping if any */
690 pending_map
= fec_find(&ln
->sent_map_pending
, &fn
->fec
);
692 lde_send_labelmapping(ln
, fn
, 1);
693 lde_map_pending_del(ln
, pending_map
);
698 * LRl.11 - 13 are unnecessary since we remove the label from
699 * forwarding/switching as soon as the FEC is unreachable.
704 lde_check_release_wcard(struct map
*map
, struct lde_nbr
*ln
)
708 struct lde_wdraw
*lw
;
710 struct fec
*pending_map
;
712 RB_FOREACH(f
, fec_tree
, &ft
) {
713 fn
= (struct fec_node
*)f
;
714 me
= (struct lde_map
*)fec_find(&ln
->sent_map
, &fn
->fec
);
716 /* LRl.1: does FEC match a known FEC? */
717 if (lde_wildcard_apply(map
, &fn
->fec
, me
) == 0)
720 /* LRl.6: check sent map list and remove it if available */
722 (map
->label
== NO_LABEL
|| map
->label
== me
->map
.label
))
723 lde_map_del(ln
, me
, 1);
725 /* LRl.3: first check if we have a pending withdraw running */
726 lw
= (struct lde_wdraw
*)fec_find(&ln
->sent_wdraw
, &fn
->fec
);
727 if (lw
&& (map
->label
== NO_LABEL
|| map
->label
== lw
->label
)) {
728 /* LRl.4: delete record of outstanding lbl withdraw */
729 lde_wdraw_del(ln
, lw
);
731 /* send pending label mapping if any */
732 pending_map
= fec_find(&ln
->sent_map_pending
, &fn
->fec
);
734 lde_send_labelmapping(ln
, fn
, 1);
735 lde_map_pending_del(ln
, pending_map
);
740 * LRl.11 - 13 are unnecessary since we remove the label from
741 * forwarding/switching as soon as the FEC is unreachable.
747 lde_check_withdraw(struct map
*map
, struct lde_nbr
*ln
)
755 /* wildcard label withdraw */
756 if (map
->type
== MAP_TYPE_WILDCARD
||
757 map
->type
== MAP_TYPE_TYPED_WCARD
||
758 (map
->type
== MAP_TYPE_PWID
&& !(map
->flags
& F_MAP_PW_ID
))) {
759 lde_check_withdraw_wcard(map
, ln
);
763 lde_map2fec(map
, ln
->id
, &fec
);
764 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
768 /* LWd.1: remove label from forwarding/switching use */
769 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
773 if (!lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
777 pw
= (struct l2vpn_pw
*) fn
->data
;
780 pw
->remote_status
= PW_NOT_FORWARDING
;
785 if (map
->label
!= NO_LABEL
&& map
->label
!= fnh
->remote_label
)
788 lde_send_delete_klabel(fn
, fnh
);
789 fnh
->remote_label
= NO_LABEL
;
792 /* LWd.2: send label release */
793 lde_send_labelrelease(ln
, fn
, NULL
, map
->label
);
795 /* LWd.3: check previously received label mapping */
796 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
797 if (me
&& (map
->label
== NO_LABEL
|| map
->label
== me
->map
.label
))
798 /* LWd.4: remove record of previously received lbl mapping */
799 lde_map_del(ln
, me
, 0);
803 lde_check_withdraw_wcard(struct map
*map
, struct lde_nbr
*ln
)
811 /* LWd.2: send label release */
812 lde_send_labelrelease(ln
, NULL
, map
, map
->label
);
814 RB_FOREACH(f
, fec_tree
, &ft
) {
815 fn
= (struct fec_node
*)f
;
816 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
818 if (lde_wildcard_apply(map
, &fn
->fec
, me
) == 0)
821 /* LWd.1: remove label from forwarding/switching use */
822 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
826 if (!lde_address_find(ln
, fnh
->af
,
831 if (f
->u
.pwid
.lsr_id
.s_addr
!= ln
->id
.s_addr
)
833 pw
= (struct l2vpn_pw
*) fn
->data
;
835 pw
->remote_status
= PW_NOT_FORWARDING
;
840 if (map
->label
!= NO_LABEL
&& map
->label
!=
844 lde_send_delete_klabel(fn
, fnh
);
845 fnh
->remote_label
= NO_LABEL
;
848 /* LWd.3: check previously received label mapping */
849 if (me
&& (map
->label
== NO_LABEL
||
850 map
->label
== me
->map
.label
))
852 * LWd.4: remove record of previously received
855 lde_map_del(ln
, me
, 0);
860 lde_wildcard_apply(struct map
*wcard
, struct fec
*fec
, struct lde_map
*me
)
862 switch (wcard
->type
) {
863 case MAP_TYPE_WILDCARD
:
866 case MAP_TYPE_TYPED_WCARD
:
867 switch (wcard
->fec
.twcard
.type
) {
868 case MAP_TYPE_PREFIX
:
869 if (wcard
->fec
.twcard
.u
.prefix_af
== AF_INET
&&
870 fec
->type
!= FEC_TYPE_IPV4
)
872 if (wcard
->fec
.twcard
.u
.prefix_af
== AF_INET6
&&
873 fec
->type
!= FEC_TYPE_IPV6
)
877 if (fec
->type
!= FEC_TYPE_PWID
)
879 if (wcard
->fec
.twcard
.u
.pw_type
!= PW_TYPE_WILDCARD
&&
880 wcard
->fec
.twcard
.u
.pw_type
!= fec
->u
.pwid
.type
)
884 fatalx("lde_wildcard_apply: unexpected fec type");
888 /* RFC4447 pw-id group wildcard */
889 if (fec
->type
!= FEC_TYPE_PWID
)
891 if (fec
->u
.pwid
.type
!= wcard
->fec
.pwid
.type
)
893 if (me
== NULL
|| (me
->map
.fec
.pwid
.group_id
!=
894 wcard
->fec
.pwid
.group_id
))
898 fatalx("lde_wildcard_apply: unexpected fec type");
902 /* gabage collector timer: timer to remove dead entries from the LIB */
906 lde_gc_timer(struct thread
*thread
)
908 struct fec
*fec
, *safe
;
912 RB_FOREACH_SAFE(fec
, fec_tree
, &ft
, safe
) {
913 fn
= (struct fec_node
*) fec
;
915 if (!LIST_EMPTY(&fn
->nexthops
) ||
916 !RB_EMPTY(lde_map_head
, &fn
->downstream
) ||
917 !RB_EMPTY(lde_map_head
, &fn
->upstream
))
920 fec_remove(&ft
, &fn
->fec
);
926 log_debug("%s: %u entries removed", __func__
, count
);
928 lde_gc_start_timer();
934 lde_gc_start_timer(void)
936 THREAD_TIMER_OFF(gc_timer
);
938 thread_add_timer(master
, lde_gc_timer
, NULL
, LDE_GC_INTERVAL
,
943 lde_gc_stop_timer(void)
945 THREAD_TIMER_OFF(gc_timer
);