]>
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
*,
34 ifindex_t
, uint8_t, unsigned short);
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 (!RB_EMPTY(fec_tree
, fh
)) {
133 f
= RB_ROOT(fec_tree
, fh
);
140 /* routing table functions */
142 lde_nbr_is_nexthop(struct fec_node
*fn
, struct lde_nbr
*ln
)
146 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
)
147 if (lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
159 static struct ctl_rt rtctl
;
161 RB_FOREACH(f
, fec_tree
, &ft
) {
162 fn
= (struct fec_node
*)f
;
163 if (fn
->local_label
== NO_LABEL
&&
164 RB_EMPTY(lde_map_head
, &fn
->downstream
))
167 memset(&rtctl
, 0, sizeof(rtctl
));
168 switch (fn
->fec
.type
) {
171 rtctl
.prefix
.v4
= fn
->fec
.u
.ipv4
.prefix
;
172 rtctl
.prefixlen
= fn
->fec
.u
.ipv4
.prefixlen
;
176 rtctl
.prefix
.v6
= fn
->fec
.u
.ipv6
.prefix
;
177 rtctl
.prefixlen
= fn
->fec
.u
.ipv6
.prefixlen
;
183 rtctl
.local_label
= fn
->local_label
;
184 if (RB_EMPTY(lde_map_head
, &fn
->downstream
)) {
186 rtctl
.nexthop
.s_addr
= INADDR_ANY
;
187 rtctl
.remote_label
= NO_LABEL
;
188 rtctl
.no_downstream
= 1;
190 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_BEGIN
, 0, pid
, &rtctl
,
193 RB_FOREACH(me
, lde_map_head
, &fn
->upstream
) {
194 rtctl
.nexthop
= me
->nexthop
->id
;
195 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_SENT
, 0, pid
,
196 &rtctl
, sizeof(rtctl
));
199 RB_FOREACH(me
, lde_map_head
, &fn
->downstream
) {
200 rtctl
.in_use
= lde_nbr_is_nexthop(fn
, me
->nexthop
);
201 rtctl
.nexthop
= me
->nexthop
->id
;
202 rtctl
.remote_label
= me
->map
.label
;
203 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_RCVD
, 0, pid
,
204 &rtctl
, sizeof(rtctl
));
206 lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB_END
, 0, pid
, &rtctl
,
212 fec_snap(struct lde_nbr
*ln
)
217 RB_FOREACH(f
, fec_tree
, &ft
) {
218 fn
= (struct fec_node
*)f
;
219 if (fn
->local_label
== NO_LABEL
)
222 lde_send_labelmapping(ln
, fn
, 0);
225 lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END
, ln
->peerid
, 0, NULL
, 0);
231 struct fec_node
*fn
= arg
;
234 while ((fnh
= LIST_FIRST(&fn
->nexthops
))) {
236 assert(fnh
!= LIST_FIRST(&fn
->nexthops
));
238 if (!RB_EMPTY(lde_map_head
, &fn
->downstream
))
239 log_warnx("%s: fec %s downstream list not empty", __func__
,
241 if (!RB_EMPTY(lde_map_head
, &fn
->upstream
))
242 log_warnx("%s: fec %s upstream list not empty", __func__
,
251 fec_clear(&ft
, fec_free
);
254 static struct fec_node
*
255 fec_add(struct fec
*fec
)
259 fn
= calloc(1, sizeof(*fn
));
264 fn
->local_label
= NO_LABEL
;
265 RB_INIT(lde_map_head
, &fn
->upstream
);
266 RB_INIT(lde_map_head
, &fn
->downstream
);
267 LIST_INIT(&fn
->nexthops
);
269 if (fec_insert(&ft
, &fn
->fec
))
270 log_warnx("failed to add %s to ft tree",
277 fec_nh_find(struct fec_node
*fn
, int af
, union ldpd_addr
*nexthop
,
278 ifindex_t ifindex
, uint8_t route_type
, unsigned short route_instance
)
282 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
)
284 ldp_addrcmp(af
, &fnh
->nexthop
, nexthop
) == 0 &&
285 fnh
->ifindex
== ifindex
&&
286 fnh
->route_type
== route_type
&&
287 fnh
->route_instance
== route_instance
)
293 static struct fec_nh
*
294 fec_nh_add(struct fec_node
*fn
, int af
, union ldpd_addr
*nexthop
,
295 ifindex_t ifindex
, uint8_t route_type
, unsigned short route_instance
)
299 fnh
= calloc(1, sizeof(*fnh
));
304 fnh
->nexthop
= *nexthop
;
305 fnh
->ifindex
= ifindex
;
306 fnh
->remote_label
= NO_LABEL
;
307 fnh
->route_type
= route_type
;
308 fnh
->route_instance
= route_instance
;
309 LIST_INSERT_HEAD(&fn
->nexthops
, fnh
, entry
);
315 fec_nh_del(struct fec_nh
*fnh
)
317 LIST_REMOVE(fnh
, entry
);
322 lde_kernel_insert(struct fec
*fec
, int af
, union ldpd_addr
*nexthop
,
323 ifindex_t ifindex
, uint8_t route_type
, unsigned short route_instance
,
324 int connected
, void *data
)
329 fn
= (struct fec_node
*)fec_find(&ft
, fec
);
335 fnh
= fec_nh_find(fn
, af
, nexthop
, ifindex
, route_type
, route_instance
);
337 fnh
= fec_nh_add(fn
, af
, nexthop
, ifindex
, route_type
,
339 fnh
->flags
|= F_FEC_NH_NEW
;
341 fnh
->flags
|= F_FEC_NH_CONNECTED
;
345 lde_kernel_remove(struct fec
*fec
, int af
, union ldpd_addr
*nexthop
,
346 ifindex_t ifindex
, uint8_t route_type
, unsigned short route_instance
)
351 fn
= (struct fec_node
*)fec_find(&ft
, fec
);
355 fnh
= fec_nh_find(fn
, af
, nexthop
, ifindex
, route_type
, route_instance
);
360 lde_send_delete_klabel(fn
, fnh
);
365 * Whenever a route is changed, zebra advertises its new version without
366 * withdrawing the old one. So, after processing a ZEBRA_REDISTRIBUTE_IPV[46]_ADD
367 * message, we need to check for nexthops that were removed and, for each of
368 * them (if any), withdraw the associated labels from zebra.
371 lde_kernel_update(struct fec
*fec
)
374 struct fec_nh
*fnh
, *safe
;
378 fn
= (struct fec_node
*)fec_find(&ft
, fec
);
382 LIST_FOREACH_SAFE(fnh
, &fn
->nexthops
, entry
, safe
) {
383 if (fnh
->flags
& F_FEC_NH_NEW
)
384 fnh
->flags
&= ~F_FEC_NH_NEW
;
386 lde_send_delete_klabel(fn
, fnh
);
391 if (LIST_EMPTY(&fn
->nexthops
)) {
392 RB_FOREACH(ln
, nbr_tree
, &lde_nbrs
)
393 lde_send_labelwithdraw(ln
, fn
, NULL
, NULL
);
397 * Do not deallocate the local label now, do that only in the
398 * LIB garbage collector. This will prevent ldpd from changing
399 * the input label of some prefixes too often when running on
400 * an unstable network. Also, restart the garbage collector
401 * timer so that labels are deallocated only when the network
404 lde_gc_start_timer();
406 fn
->local_label
= lde_update_label(fn
);
407 if (fn
->local_label
!= NO_LABEL
)
408 /* FEC.1: perform lsr label distribution procedure */
409 RB_FOREACH(ln
, nbr_tree
, &lde_nbrs
)
410 lde_send_labelmapping(ln
, fn
, 1);
413 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
414 lde_send_change_klabel(fn
, fnh
);
416 switch (fn
->fec
.type
) {
419 ln
= lde_nbr_find_by_addr(fnh
->af
, &fnh
->nexthop
);
422 ln
= lde_nbr_find_by_lsrid(fn
->fec
.u
.pwid
.lsr_id
);
431 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
434 lde_check_mapping(&me
->map
, ln
);
440 lde_check_mapping(struct map
*map
, struct lde_nbr
*ln
)
449 lde_map2fec(map
, ln
->id
, &fec
);
453 if (lde_acl_check(ldeconf
->ipv4
.acl_label_accept_from
,
454 AF_INET
, (union ldpd_addr
*)&ln
->id
, 32) != FILTER_PERMIT
)
456 if (lde_acl_check(ldeconf
->ipv4
.acl_label_accept_for
,
457 AF_INET
, (union ldpd_addr
*)&fec
.u
.ipv4
.prefix
,
458 fec
.u
.ipv4
.prefixlen
) != FILTER_PERMIT
)
462 if (lde_acl_check(ldeconf
->ipv6
.acl_label_accept_from
,
463 AF_INET
, (union ldpd_addr
*)&ln
->id
, 32) != FILTER_PERMIT
)
465 if (lde_acl_check(ldeconf
->ipv6
.acl_label_accept_for
,
466 AF_INET6
, (union ldpd_addr
*)&fec
.u
.ipv6
.prefix
,
467 fec
.u
.ipv6
.prefixlen
) != FILTER_PERMIT
)
474 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
478 /* LMp.1: first check if we have a pending request running */
479 lre
= (struct lde_req
*)fec_find(&ln
->sent_req
, &fn
->fec
);
481 /* LMp.2: delete record of outstanding label request */
482 lde_req_del(ln
, lre
, 1);
484 /* RFC 4447 control word and status tlv negotiation */
485 if (map
->type
== MAP_TYPE_PWID
&& l2vpn_pw_negotiate(ln
, fn
, map
))
489 * LMp.3 - LMp.8: loop detection - unnecessary for frame-mode
494 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
497 if (me
->map
.label
!= map
->label
&& lre
== NULL
) {
499 lde_send_labelrelease(ln
, fn
, NULL
, me
->map
.label
);
502 * Can not use lde_nbr_find_by_addr() because there's
503 * the possibility of multipath.
505 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
506 if (lde_address_find(ln
, fnh
->af
,
507 &fnh
->nexthop
) == NULL
)
510 lde_send_delete_klabel(fn
, fnh
);
511 fnh
->remote_label
= NO_LABEL
;
517 * LMp.11 - 12: consider multiple nexthops in order to
520 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
521 /* LMp.15: install FEC in FIB */
525 if (!lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
528 fnh
->remote_label
= map
->label
;
529 lde_send_change_klabel(fn
, fnh
);
532 pw
= (struct l2vpn_pw
*) fn
->data
;
536 pw
->remote_group
= map
->fec
.pwid
.group_id
;
537 if (map
->flags
& F_MAP_PW_IFMTU
)
538 pw
->remote_mtu
= map
->fec
.pwid
.ifmtu
;
539 if (map
->flags
& F_MAP_PW_STATUS
)
540 pw
->remote_status
= map
->pw_status
;
542 pw
->remote_status
= PW_FORWARDING
;
543 fnh
->remote_label
= map
->label
;
544 if (l2vpn_pw_ok(pw
, fnh
))
545 lde_send_change_klabel(fn
, fnh
);
551 /* LMp.13 & LMp.16: Record the mapping from this peer */
553 me
= lde_map_add(ln
, fn
, 0);
557 * LMp.17 - LMp.27 are unnecessary since we don't need to implement
558 * loop detection. LMp.28 - LMp.30 are unnecessary because we are
564 lde_check_request(struct map
*map
, struct lde_nbr
*ln
)
571 /* wildcard label request */
572 if (map
->type
== MAP_TYPE_TYPED_WCARD
) {
573 lde_check_request_wcard(map
, ln
);
577 /* LRq.1: skip loop detection (not necessary) */
579 /* LRq.2: is there a next hop for fec? */
580 lde_map2fec(map
, ln
->id
, &fec
);
581 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
582 if (fn
== NULL
|| LIST_EMPTY(&fn
->nexthops
)) {
583 /* LRq.5: send No Route notification */
584 lde_send_notification(ln
, S_NO_ROUTE
, map
->msg_id
,
585 htons(MSG_TYPE_LABELREQUEST
));
589 /* LRq.3: is MsgSource the next hop? */
590 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
594 if (!lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
597 /* LRq.4: send Loop Detected notification */
598 lde_send_notification(ln
, S_LOOP_DETECTED
, map
->msg_id
,
599 htons(MSG_TYPE_LABELREQUEST
));
606 /* LRq.6: first check if we have a pending request running */
607 lre
= (struct lde_req
*)fec_find(&ln
->recv_req
, &fn
->fec
);
609 /* LRq.7: duplicate request */
612 /* LRq.8: record label request */
613 lre
= lde_req_add(ln
, &fn
->fec
, 0);
615 lre
->msg_id
= ntohl(map
->msg_id
);
617 /* LRq.9: perform LSR label distribution */
618 lde_send_labelmapping(ln
, fn
, 1);
621 * LRq.10: do nothing (Request Never) since we use liberal
623 * LRq.11 - 12 are unnecessary since we are merging capable.
628 lde_check_request_wcard(struct map
*map
, struct lde_nbr
*ln
)
634 RB_FOREACH(f
, fec_tree
, &ft
) {
635 fn
= (struct fec_node
*)f
;
637 /* only a typed wildcard is possible here */
638 if (lde_wildcard_apply(map
, &fn
->fec
, NULL
) == 0)
641 /* LRq.2: is there a next hop for fec? */
642 if (LIST_EMPTY(&fn
->nexthops
))
645 /* LRq.6: first check if we have a pending request running */
646 lre
= (struct lde_req
*)fec_find(&ln
->recv_req
, &fn
->fec
);
648 /* LRq.7: duplicate request */
651 /* LRq.8: record label request */
652 lre
= lde_req_add(ln
, &fn
->fec
, 0);
654 lre
->msg_id
= ntohl(map
->msg_id
);
656 /* LRq.9: perform LSR label distribution */
657 lde_send_labelmapping(ln
, fn
, 1);
662 lde_check_release(struct map
*map
, struct lde_nbr
*ln
)
666 struct lde_wdraw
*lw
;
668 struct fec
*pending_map
;
670 /* wildcard label release */
671 if (map
->type
== MAP_TYPE_WILDCARD
||
672 map
->type
== MAP_TYPE_TYPED_WCARD
||
673 (map
->type
== MAP_TYPE_PWID
&& !(map
->flags
& F_MAP_PW_ID
))) {
674 lde_check_release_wcard(map
, ln
);
678 lde_map2fec(map
, ln
->id
, &fec
);
679 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
680 /* LRl.1: does FEC match a known FEC? */
684 /* LRl.6: check sent map list and remove it if available */
685 me
= (struct lde_map
*)fec_find(&ln
->sent_map
, &fn
->fec
);
686 if (me
&& (map
->label
== NO_LABEL
|| map
->label
== me
->map
.label
))
687 lde_map_del(ln
, me
, 1);
689 /* LRl.3: first check if we have a pending withdraw running */
690 lw
= (struct lde_wdraw
*)fec_find(&ln
->sent_wdraw
, &fn
->fec
);
691 if (lw
&& (map
->label
== NO_LABEL
|| map
->label
== lw
->label
)) {
692 /* LRl.4: delete record of outstanding label withdraw */
693 lde_wdraw_del(ln
, lw
);
695 /* send pending label mapping if any */
696 pending_map
= fec_find(&ln
->sent_map_pending
, &fn
->fec
);
698 lde_send_labelmapping(ln
, fn
, 1);
699 lde_map_pending_del(ln
, pending_map
);
704 * LRl.11 - 13 are unnecessary since we remove the label from
705 * forwarding/switching as soon as the FEC is unreachable.
710 lde_check_release_wcard(struct map
*map
, struct lde_nbr
*ln
)
714 struct lde_wdraw
*lw
;
716 struct fec
*pending_map
;
718 RB_FOREACH(f
, fec_tree
, &ft
) {
719 fn
= (struct fec_node
*)f
;
720 me
= (struct lde_map
*)fec_find(&ln
->sent_map
, &fn
->fec
);
722 /* LRl.1: does FEC match a known FEC? */
723 if (lde_wildcard_apply(map
, &fn
->fec
, me
) == 0)
726 /* LRl.6: check sent map list and remove it if available */
728 (map
->label
== NO_LABEL
|| map
->label
== me
->map
.label
))
729 lde_map_del(ln
, me
, 1);
731 /* LRl.3: first check if we have a pending withdraw running */
732 lw
= (struct lde_wdraw
*)fec_find(&ln
->sent_wdraw
, &fn
->fec
);
733 if (lw
&& (map
->label
== NO_LABEL
|| map
->label
== lw
->label
)) {
734 /* LRl.4: delete record of outstanding lbl withdraw */
735 lde_wdraw_del(ln
, lw
);
737 /* send pending label mapping if any */
738 pending_map
= fec_find(&ln
->sent_map_pending
, &fn
->fec
);
740 lde_send_labelmapping(ln
, fn
, 1);
741 lde_map_pending_del(ln
, pending_map
);
746 * LRl.11 - 13 are unnecessary since we remove the label from
747 * forwarding/switching as soon as the FEC is unreachable.
753 lde_check_withdraw(struct map
*map
, struct lde_nbr
*ln
)
761 /* wildcard label withdraw */
762 if (map
->type
== MAP_TYPE_WILDCARD
||
763 map
->type
== MAP_TYPE_TYPED_WCARD
||
764 (map
->type
== MAP_TYPE_PWID
&& !(map
->flags
& F_MAP_PW_ID
))) {
765 lde_check_withdraw_wcard(map
, ln
);
769 lde_map2fec(map
, ln
->id
, &fec
);
770 fn
= (struct fec_node
*)fec_find(&ft
, &fec
);
774 /* LWd.1: remove label from forwarding/switching use */
775 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
779 if (!lde_address_find(ln
, fnh
->af
, &fnh
->nexthop
))
783 pw
= (struct l2vpn_pw
*) fn
->data
;
786 pw
->remote_status
= PW_NOT_FORWARDING
;
791 if (map
->label
!= NO_LABEL
&& map
->label
!= fnh
->remote_label
)
794 lde_send_delete_klabel(fn
, fnh
);
795 fnh
->remote_label
= NO_LABEL
;
798 /* LWd.2: send label release */
799 lde_send_labelrelease(ln
, fn
, NULL
, map
->label
);
801 /* LWd.3: check previously received label mapping */
802 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
803 if (me
&& (map
->label
== NO_LABEL
|| map
->label
== me
->map
.label
))
804 /* LWd.4: remove record of previously received lbl mapping */
805 lde_map_del(ln
, me
, 0);
809 lde_check_withdraw_wcard(struct map
*map
, struct lde_nbr
*ln
)
817 /* LWd.2: send label release */
818 lde_send_labelrelease(ln
, NULL
, map
, map
->label
);
820 RB_FOREACH(f
, fec_tree
, &ft
) {
821 fn
= (struct fec_node
*)f
;
822 me
= (struct lde_map
*)fec_find(&ln
->recv_map
, &fn
->fec
);
824 if (lde_wildcard_apply(map
, &fn
->fec
, me
) == 0)
827 /* LWd.1: remove label from forwarding/switching use */
828 LIST_FOREACH(fnh
, &fn
->nexthops
, entry
) {
832 if (!lde_address_find(ln
, fnh
->af
,
837 if (f
->u
.pwid
.lsr_id
.s_addr
!= ln
->id
.s_addr
)
839 pw
= (struct l2vpn_pw
*) fn
->data
;
841 pw
->remote_status
= PW_NOT_FORWARDING
;
846 if (map
->label
!= NO_LABEL
&& map
->label
!=
850 lde_send_delete_klabel(fn
, fnh
);
851 fnh
->remote_label
= NO_LABEL
;
854 /* LWd.3: check previously received label mapping */
855 if (me
&& (map
->label
== NO_LABEL
||
856 map
->label
== me
->map
.label
))
858 * LWd.4: remove record of previously received
861 lde_map_del(ln
, me
, 0);
866 lde_wildcard_apply(struct map
*wcard
, struct fec
*fec
, struct lde_map
*me
)
868 switch (wcard
->type
) {
869 case MAP_TYPE_WILDCARD
:
872 case MAP_TYPE_TYPED_WCARD
:
873 switch (wcard
->fec
.twcard
.type
) {
874 case MAP_TYPE_PREFIX
:
875 if (wcard
->fec
.twcard
.u
.prefix_af
== AF_INET
&&
876 fec
->type
!= FEC_TYPE_IPV4
)
878 if (wcard
->fec
.twcard
.u
.prefix_af
== AF_INET6
&&
879 fec
->type
!= FEC_TYPE_IPV6
)
883 if (fec
->type
!= FEC_TYPE_PWID
)
885 if (wcard
->fec
.twcard
.u
.pw_type
!= PW_TYPE_WILDCARD
&&
886 wcard
->fec
.twcard
.u
.pw_type
!= fec
->u
.pwid
.type
)
890 fatalx("lde_wildcard_apply: unexpected fec type");
894 /* RFC4447 pw-id group wildcard */
895 if (fec
->type
!= FEC_TYPE_PWID
)
897 if (fec
->u
.pwid
.type
!= wcard
->fec
.pwid
.type
)
899 if (me
== NULL
|| (me
->map
.fec
.pwid
.group_id
!=
900 wcard
->fec
.pwid
.group_id
))
904 fatalx("lde_wildcard_apply: unexpected fec type");
908 /* gabage collector timer: timer to remove dead entries from the LIB */
912 lde_gc_timer(struct thread
*thread
)
914 struct fec
*fec
, *safe
;
918 RB_FOREACH_SAFE(fec
, fec_tree
, &ft
, safe
) {
919 fn
= (struct fec_node
*) fec
;
921 if (!LIST_EMPTY(&fn
->nexthops
) ||
922 !RB_EMPTY(lde_map_head
, &fn
->downstream
) ||
923 !RB_EMPTY(lde_map_head
, &fn
->upstream
))
926 if (fn
->local_label
!= NO_LABEL
)
927 lde_free_label(fn
->local_label
);
929 fec_remove(&ft
, &fn
->fec
);
935 log_debug("%s: %u entries removed", __func__
, count
);
937 lde_gc_start_timer();
943 lde_gc_start_timer(void)
945 THREAD_TIMER_OFF(gc_timer
);
947 thread_add_timer(master
, lde_gc_timer
, NULL
, LDE_GC_INTERVAL
,
952 lde_gc_stop_timer(void)
954 THREAD_TIMER_OFF(gc_timer
);