+// SPDX-License-Identifier: ISC
/* $OpenBSD$ */
/*
* Copyright (c) 2013, 2016 Renato Westphal <renato@openbsd.org>
* Copyright (c) 2009 Michele Marchetto <michele@openbsd.org>
- *
- * Permission to use, copy, modify, and distribute this software for any
- * purpose with or without fee is hereby granted, provided that the above
- * copyright notice and this permission notice appear in all copies.
- *
- * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
- * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
- * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
- * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
- * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#include <zebra.h>
#include "mpls.h"
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 *,
+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, unsigned short);
-static void fec_nh_del(struct fec_nh *);
+static void fec_nh_del(struct fec_nh *);
RB_GENERATE(fec_tree, fec, entry, fec_compare)
-struct fec_tree ft = RB_INITIALIZER(&ft);
-struct thread *gc_timer;
+struct fec_tree ft = RB_INITIALIZER(&ft);
+struct event *gc_timer;
/* FEC tree functions */
void
switch (a->type) {
case FEC_TYPE_IPV4:
- if (ntohl(a->u.ipv4.prefix.s_addr) <
- ntohl(b->u.ipv4.prefix.s_addr))
+ if (ntohl(a->u.ipv4.prefix.s_addr) < ntohl(b->u.ipv4.prefix.s_addr))
return (-1);
- if (ntohl(a->u.ipv4.prefix.s_addr) >
- ntohl(b->u.ipv4.prefix.s_addr))
+ if (ntohl(a->u.ipv4.prefix.s_addr) > ntohl(b->u.ipv4.prefix.s_addr))
return (1);
if (a->u.ipv4.prefixlen < b->u.ipv4.prefixlen)
return (-1);
return (-1);
if (a->u.pwid.pwid > b->u.pwid.pwid)
return (1);
- if (ntohl(a->u.pwid.lsr_id.s_addr) <
- ntohl(b->u.pwid.lsr_id.s_addr))
+ if (ntohl(a->u.pwid.lsr_id.s_addr) < ntohl(b->u.pwid.lsr_id.s_addr))
return (-1);
- if (ntohl(a->u.pwid.lsr_id.s_addr) >
- ntohl(b->u.pwid.lsr_id.s_addr))
+ if (ntohl(a->u.pwid.lsr_id.s_addr) > ntohl(b->u.pwid.lsr_id.s_addr))
return (1);
return (0);
}
rtctl.prefix.v6 = fn->fec.u.ipv6.prefix;
rtctl.prefixlen = fn->fec.u.ipv6.prefixlen;
break;
- default:
+ case FEC_TYPE_PWID:
continue;
}
fn->pw_remote_status = PW_FORWARDING;
if (fec_insert(&ft, &fn->fec))
- log_warnx("failed to add %s to ft tree",
- log_fec(&fn->fec));
+ log_warnx("failed to add %s to ft tree", log_fec(&fn->fec));
return (fn);
}
* installing in kernel and sending to peer
*/
iface = if_lookup(ldeconf, ifindex);
- if ((ldeconf->flags & F_LDPD_ORDERED_CONTROL) &&
+ if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL) &&
!connected && iface != NULL && fec->type != FEC_TYPE_PWID)
- fnh->flags |= F_FEC_NH_DEFER;
+ SET_FLAG(fnh->flags, F_FEC_NH_DEFER);
}
- fnh->flags |= F_FEC_NH_NEW;
+ SET_FLAG(fnh->flags, F_FEC_NH_NEW);
if (connected)
- fnh->flags |= F_FEC_NH_CONNECTED;
+ SET_FLAG(fnh->flags, F_FEC_NH_CONNECTED);
}
void
return;
LIST_FOREACH_SAFE(fnh, &fn->nexthops, entry, safe) {
- if (fnh->flags & F_FEC_NH_NEW) {
- fnh->flags &= ~F_FEC_NH_NEW;
+ if (CHECK_FLAG(fnh->flags, F_FEC_NH_NEW)) {
+ UNSET_FLAG(fnh->flags, F_FEC_NH_NEW);
/*
* if LDP configured on interface or a static route
* clear flag else treat fec as a connected route
*/
- if (ldeconf->flags & F_LDPD_ENABLED) {
+ if (CHECK_FLAG(ldeconf->flags, F_LDPD_ENABLED)) {
iface = if_lookup(ldeconf,fnh->ifindex);
- if (fnh->flags & F_FEC_NH_CONNECTED ||
+ if (CHECK_FLAG(fnh->flags, F_FEC_NH_CONNECTED) ||
iface ||
fnh->route_type == ZEBRA_ROUTE_STATIC)
- fnh->flags &=~F_FEC_NH_NO_LDP;
+ UNSET_FLAG(fnh->flags, F_FEC_NH_NO_LDP);
else
- fnh->flags |= F_FEC_NH_NO_LDP;
+ SET_FLAG(fnh->flags, F_FEC_NH_NO_LDP);
} else
- fnh->flags |= F_FEC_NH_NO_LDP;
+ SET_FLAG(fnh->flags, F_FEC_NH_NO_LDP);
} else {
lde_send_delete_klabel(fn, fnh);
fec_nh_del(fnh);
fec.u.ipv6.prefixlen) != FILTER_PERMIT)
return;
break;
- default:
+ case FEC_TYPE_PWID:
break;
}
/* RFC 4447 control word and status tlv negotiation */
if (map->type == MAP_TYPE_PWID && l2vpn_pw_negotiate(ln, fn, map)) {
- if (rcvd_label_mapping && map->flags & F_MAP_PW_STATUS)
+ if (rcvd_label_mapping && CHECK_FLAG(map->flags, F_MAP_PW_STATUS))
fn->pw_remote_status = map->pw_status;
return;
* the possibility of multipath.
*/
LIST_FOREACH(fnh, &fn->nexthops, entry) {
- if (lde_address_find(ln, fnh->af,
- &fnh->nexthop) == NULL)
+ if (lde_address_find(ln, fnh->af, &fnh->nexthop) == NULL)
continue;
lde_send_delete_klabel(fn, fnh);
* NH so clear flag and send labelmap msg to
* peer
*/
- if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) {
+ if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) {
send_map = true;
- fnh->flags &= ~F_FEC_NH_DEFER;
+ UNSET_FLAG(fnh->flags, F_FEC_NH_DEFER);
}
fnh->remote_label = map->label;
if (fn->local_label != NO_LABEL)
continue;
pw->remote_group = map->fec.pwid.group_id;
- if (map->flags & F_MAP_PW_IFMTU)
+ if (CHECK_FLAG(map->flags, F_MAP_PW_IFMTU))
pw->remote_mtu = map->fec.pwid.ifmtu;
- if (rcvd_label_mapping && map->flags & F_MAP_PW_STATUS) {
+ if (rcvd_label_mapping && CHECK_FLAG(map->flags, F_MAP_PW_STATUS)) {
pw->remote_status = map->pw_status;
fn->pw_remote_status = map->pw_status;
}
lde_send_notification(ln, S_LOOP_DETECTED, map->msg_id,
htons(MSG_TYPE_LABELREQUEST));
return;
- default:
+ case FEC_TYPE_PWID:
break;
}
}
/* wildcard label release */
if (map->type == MAP_TYPE_WILDCARD ||
map->type == MAP_TYPE_TYPED_WCARD ||
- (map->type == MAP_TYPE_PWID && !(map->flags & F_MAP_PW_ID))) {
+ (map->type == MAP_TYPE_PWID && !CHECK_FLAG(map->flags, F_MAP_PW_ID))) {
lde_check_release_wcard(map, ln);
return;
}
/* wildcard label withdraw */
if (map->type == MAP_TYPE_WILDCARD ||
map->type == MAP_TYPE_TYPED_WCARD ||
- (map->type == MAP_TYPE_PWID && !(map->flags & F_MAP_PW_ID))) {
+ (map->type == MAP_TYPE_PWID && !CHECK_FLAG(map->flags, F_MAP_PW_ID))) {
lde_check_withdraw_wcard(map, ln);
return;
}
return;
/* Ordered Control: additional withdraw steps */
- if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) {
+ if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) {
/* LWd.8: for each neighbor other that src of withdraw msg */
RB_FOREACH(lnbr, nbr_tree, &lde_nbrs) {
if (ln->peerid == lnbr->peerid)
continue;
/* LWd.9: check if previously sent a label mapping */
- me = (struct lde_map *)fec_find(&lnbr->sent_map,
- &fn->fec);
+ me = (struct lde_map *)fec_find(&lnbr->sent_map, &fn->fec);
/*
* LWd.10: does label sent to peer "map" to withdraw
switch (f->type) {
case FEC_TYPE_IPV4:
case FEC_TYPE_IPV6:
- if (!lde_address_find(ln, fnh->af,
- &fnh->nexthop))
+ if (!lde_address_find(ln, fnh->af, &fnh->nexthop))
continue;
break;
case FEC_TYPE_PWID:
default:
break;
}
- if (map->label != NO_LABEL && map->label !=
- fnh->remote_label)
+ if (map->label != NO_LABEL && map->label != fnh->remote_label)
continue;
lde_send_delete_klabel(fn, fnh);
lde_rlfa_update_clients(f, ln, MPLS_INVALID_LABEL);
/* LWd.3: check previously received label mapping */
- if (me && (map->label == NO_LABEL ||
- map->label == me->map.label))
+ if (me && (map->label == NO_LABEL || map->label == me->map.label))
/*
* LWd.4: remove record of previously received
* label mapping
continue;
/* Ordered Control: additional withdraw steps */
- if (ldeconf->flags & F_LDPD_ORDERED_CONTROL) {
+ if (CHECK_FLAG(ldeconf->flags, F_LDPD_ORDERED_CONTROL)) {
/*
* LWd.8: for each neighbor other that src of
* withdraw msg
/* LWd.9: check if previously sent a label
* mapping
*/
- me = (struct lde_map *)fec_find(
- &lnbr->sent_map, &fn->fec);
+ me = (struct lde_map *)fec_find(&lnbr->sent_map, &fn->fec);
/*
* LWd.10: does label sent to peer "map" to
* withdraw label
*/
if (me && lde_nbr_is_nexthop(fn, lnbr))
/* LWd.11: send label withdraw */
- lde_send_labelwithdraw(lnbr, fn, NULL,
- NULL);
+ lde_send_labelwithdraw(lnbr, fn, NULL, NULL);
}
}
}
/* gabage collector timer: timer to remove dead entries from the LIB */
/* ARGSUSED */
-int
-lde_gc_timer(struct thread *thread)
+void lde_gc_timer(struct event *thread)
{
struct fec *fec, *safe;
struct fec_node *fn;
log_debug("%s: %u entries removed", __func__, count);
lde_gc_start_timer();
-
- return (0);
}
void
lde_gc_start_timer(void)
{
- thread_cancel(&gc_timer);
- thread_add_timer(master, lde_gc_timer, NULL, LDE_GC_INTERVAL,
- &gc_timer);
+ EVENT_OFF(gc_timer);
+ event_add_timer(master, lde_gc_timer, NULL, LDE_GC_INTERVAL, &gc_timer);
}
void
lde_gc_stop_timer(void)
{
- thread_cancel(&gc_timer);
+ EVENT_OFF(gc_timer);
}