diff options
author | Renato Westphal <renato@cvs.openbsd.org> | 2015-07-21 04:46:52 +0000 |
---|---|---|
committer | Renato Westphal <renato@cvs.openbsd.org> | 2015-07-21 04:46:52 +0000 |
commit | 148470b9931026e3695405993d37cd802326c5b8 (patch) | |
tree | f8d3d8c855f5dbee77f11d23e35352e14d8aa00a /usr.sbin/ldpd | |
parent | 7138456e49d38cd5574bca9455079217de32f7a5 (diff) |
Rename structures and functions to be more generic.
LDP work with FECs, where a FEC can be a prefix, a pseudowire and so on.
ok claudio@
Diffstat (limited to 'usr.sbin/ldpd')
-rw-r--r-- | usr.sbin/ldpd/lde.c | 110 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde.h | 30 | ||||
-rw-r--r-- | usr.sbin/ldpd/lde_lib.c | 337 |
3 files changed, 238 insertions, 239 deletions
diff --git a/usr.sbin/ldpd/lde.c b/usr.sbin/ldpd/lde.c index 14450d3cb62..6dd38944f0d 100644 --- a/usr.sbin/ldpd/lde.c +++ b/usr.sbin/ldpd/lde.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.c,v 1.35 2015/07/21 04:45:21 renato Exp $ */ +/* $OpenBSD: lde.c,v 1.36 2015/07/21 04:46:51 renato Exp $ */ /* * Copyright (c) 2004, 2005 Claudio Jeker <claudio@openbsd.org> @@ -162,7 +162,7 @@ void lde_shutdown(void) { lde_nbr_clear(); - rt_clear(); + fec_tree_clear(); config_clear(ldeconf); @@ -231,7 +231,7 @@ lde_dispatch_imsg(int fd, short event, void *bula) return; } - rt_snap(nbr); + fec_snap(nbr); break; case IMSG_LABEL_MAPPING: case IMSG_LABEL_REQUEST: @@ -471,39 +471,39 @@ lde_assign_label(void) } void -lde_send_change_klabel(struct rt_node *rr, struct rt_lsp *rl) +lde_send_change_klabel(struct fec_node *fn, struct fec_nh *fnh) { struct kroute kr; bzero(&kr, sizeof(kr)); - kr.prefix.s_addr = rr->fec.prefix.s_addr; - kr.prefixlen = rr->fec.prefixlen; - kr.local_label = rr->local_label; + kr.prefix.s_addr = fn->fec.prefix.s_addr; + kr.prefixlen = fn->fec.prefixlen; + kr.local_label = fn->local_label; - kr.nexthop.s_addr = rl->nexthop.s_addr; - kr.remote_label = rl->remote_label; + kr.nexthop.s_addr = fnh->nexthop.s_addr; + kr.remote_label = fnh->remote_label; lde_imsg_compose_parent(IMSG_KLABEL_CHANGE, 0, &kr, sizeof(kr)); } void -lde_send_delete_klabel(struct rt_node *rr, struct rt_lsp *rl) +lde_send_delete_klabel(struct fec_node *fn, struct fec_nh *fnh) { struct kroute kr; bzero(&kr, sizeof(kr)); - kr.prefix.s_addr = rr->fec.prefix.s_addr; - kr.prefixlen = rr->fec.prefixlen; - kr.local_label = rr->local_label; + kr.prefix.s_addr = fn->fec.prefix.s_addr; + kr.prefixlen = fn->fec.prefixlen; + kr.local_label = fn->local_label; - kr.nexthop.s_addr = rl->nexthop.s_addr; - kr.remote_label = rl->remote_label; + kr.nexthop.s_addr = fnh->nexthop.s_addr; + kr.remote_label = fnh->remote_label; lde_imsg_compose_parent(IMSG_KLABEL_DELETE, 0, &kr, sizeof(kr)); } void -lde_send_labelmapping(struct lde_nbr *ln, struct rt_node *rn) +lde_send_labelmapping(struct lde_nbr *ln, struct fec_node *fn) { struct lde_req *lre; struct lde_map *me; @@ -516,12 +516,12 @@ lde_send_labelmapping(struct lde_nbr *ln, struct rt_node *rn) */ bzero(&map, sizeof(map)); - map.label = rn->local_label; - map.prefix = rn->fec.prefix; - map.prefixlen = rn->fec.prefixlen; + map.label = fn->local_label; + map.prefix = fn->fec.prefix; + map.prefixlen = fn->fec.prefixlen; /* SL.6: is there a pending request for this mapping? */ - lre = (struct lde_req *)fec_find(&ln->recv_req, &rn->fec); + lre = (struct lde_req *)fec_find(&ln->recv_req, &fn->fec); if (lre) { /* set label request msg id in the mapping response. */ map.requestid = lre->msgid; @@ -536,24 +536,24 @@ lde_send_labelmapping(struct lde_nbr *ln, struct rt_node *rn) &map, sizeof(map)); /* SL.5: record sent label mapping */ - me = (struct lde_map *)fec_find(&ln->sent_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->sent_map, &fn->fec); if (me == NULL) - me = lde_map_add(ln, rn, 1); + me = lde_map_add(ln, fn, 1); me->label = map.label; } void -lde_send_labelwithdraw(struct lde_nbr *ln, struct rt_node *rn) +lde_send_labelwithdraw(struct lde_nbr *ln, struct fec_node *fn) { struct lde_wdraw *lw; struct map map; struct fec *f; bzero(&map, sizeof(map)); - if (rn) { - map.label = rn->local_label; - map.prefix = rn->fec.prefix; - map.prefixlen = rn->fec.prefixlen; + if (fn) { + map.label = fn->local_label; + map.prefix = fn->fec.prefix; + map.prefixlen = fn->fec.prefixlen; } else { map.label = NO_LABEL; map.flags = F_MAP_WILDCARD; @@ -565,33 +565,33 @@ lde_send_labelwithdraw(struct lde_nbr *ln, struct rt_node *rn) lde_imsg_compose_ldpe(IMSG_WITHDRAW_ADD_END, ln->peerid, 0, NULL, 0); /* SWd.2: record label withdraw. */ - if (rn) { - lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &rn->fec); + if (fn) { + lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &fn->fec); if (lw == NULL) - lw = lde_wdraw_add(ln, rn); + lw = lde_wdraw_add(ln, fn); lw->label = map.label; } else { - RB_FOREACH(f, fec_tree, &rt) { - rn = (struct rt_node *)f; + RB_FOREACH(f, fec_tree, &ft) { + fn = (struct fec_node *)f; lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, - &rn->fec); + &fn->fec); if (lw == NULL) - lw = lde_wdraw_add(ln, rn); + lw = lde_wdraw_add(ln, fn); lw->label = map.label; } } } void -lde_send_labelrelease(struct lde_nbr *ln, struct rt_node *rn, u_int32_t label) +lde_send_labelrelease(struct lde_nbr *ln, struct fec_node *fn, u_int32_t label) { struct map map; bzero(&map, sizeof(map)); - if (rn) { - map.prefix = rn->fec.prefix; - map.prefixlen = rn->fec.prefixlen; + if (fn) { + map.prefix = fn->fec.prefix; + map.prefixlen = fn->fec.prefixlen; } else map.flags = F_MAP_WILDCARD; map.label = label; @@ -670,20 +670,20 @@ void lde_nbr_del(struct lde_nbr *nbr) { struct fec *f; - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; if (nbr == NULL) return; /* uninstall received mappings */ - RB_FOREACH(f, fec_tree, &rt) { - rn = (struct rt_node *)f; + RB_FOREACH(f, fec_tree, &ft) { + fn = (struct fec_node *)f; - LIST_FOREACH(rl, &rn->lsp, entry) { - if (lde_address_find(nbr, &rl->nexthop)) { - lde_send_delete_klabel(rn, rl); - rl->remote_label = NO_LABEL; + LIST_FOREACH(fnh, &fn->nexthops, entry) { + if (lde_address_find(nbr, &fnh->nexthop)) { + lde_send_delete_klabel(fn, fnh); + fnh->remote_label = NO_LABEL; } } } @@ -711,7 +711,7 @@ lde_nbr_clear(void) } struct lde_map * -lde_map_add(struct lde_nbr *ln, struct rt_node *rn, int sent) +lde_map_add(struct lde_nbr *ln, struct fec_node *fn, int sent) { struct lde_map *me; @@ -719,17 +719,17 @@ lde_map_add(struct lde_nbr *ln, struct rt_node *rn, int sent) if (me == NULL) fatal("lde_map_add"); - me->fec = rn->fec; + me->fec = fn->fec; me->nexthop = ln; if (sent) { - LIST_INSERT_HEAD(&rn->upstream, me, entry); + LIST_INSERT_HEAD(&fn->upstream, me, entry); if (fec_insert(&ln->sent_map, &me->fec)) log_warnx("failed to add %s/%u to sent map", inet_ntoa(me->fec.prefix), me->fec.prefixlen); /* XXX on failure more cleanup is needed */ } else { - LIST_INSERT_HEAD(&rn->downstream, me, entry); + LIST_INSERT_HEAD(&fn->downstream, me, entry); if (fec_insert(&ln->recv_map, &me->fec)) log_warnx("failed to add %s/%u to recv map", inet_ntoa(me->fec.prefix), me->fec.prefixlen); @@ -761,16 +761,16 @@ lde_map_free(void *ptr) struct lde_req * lde_req_add(struct lde_nbr *ln, struct fec *fec, int sent) { - struct fec_tree *ft; + struct fec_tree *t; struct lde_req *lre; - ft = sent ? &ln->sent_req : &ln->recv_req; + t = sent ? &ln->sent_req : &ln->recv_req; lre = calloc(1, sizeof(*lre)); if (lre != NULL) { lre->fec = *fec; - if (fec_insert(ft, &lre->fec)) { + if (fec_insert(t, &lre->fec)) { log_warnx("failed to add %s/%u to %s req", inet_ntoa(lre->fec.prefix), lre->fec.prefixlen, sent ? "sent" : "recv"); @@ -794,7 +794,7 @@ lde_req_del(struct lde_nbr *ln, struct lde_req *lre, int sent) } struct lde_wdraw * -lde_wdraw_add(struct lde_nbr *ln, struct rt_node *rn) +lde_wdraw_add(struct lde_nbr *ln, struct fec_node *fn) { struct lde_wdraw *lw; @@ -802,7 +802,7 @@ lde_wdraw_add(struct lde_nbr *ln, struct rt_node *rn) if (lw == NULL) fatal("lde_wdraw_add"); - lw->fec = rn->fec; + lw->fec = fn->fec; if (fec_insert(&ln->sent_wdraw, &lw->fec)) log_warnx("failed to add %s/%u to sent wdraw", diff --git a/usr.sbin/ldpd/lde.h b/usr.sbin/ldpd/lde.h index 4bdbd7fa365..df00fa89427 100644 --- a/usr.sbin/ldpd/lde.h +++ b/usr.sbin/ldpd/lde.h @@ -1,4 +1,4 @@ -/* $OpenBSD: lde.h,v 1.26 2015/07/19 20:54:16 renato Exp $ */ +/* $OpenBSD: lde.h,v 1.27 2015/07/21 04:46:51 renato Exp $ */ /* * Copyright (c) 2004, 2005 Esben Norby <norby@openbsd.org> @@ -34,7 +34,7 @@ struct fec { u_int8_t prefixlen; }; RB_PROTOTYPE(fec_tree, fec, entry, fec_compare) -extern struct fec_tree rt; +extern struct fec_tree ft; /* request entries */ struct lde_req { @@ -77,17 +77,17 @@ struct lde_nbr { u_int32_t peerid; }; -struct rt_lsp { - LIST_ENTRY(rt_lsp) entry; +struct fec_nh { + LIST_ENTRY(fec_nh) entry; struct in_addr nexthop; u_int32_t remote_label; }; -struct rt_node { +struct fec_node { struct fec fec; - LIST_HEAD(, rt_lsp) lsp; /* label switching pathes */ + LIST_HEAD(, fec_nh) nexthops; /* fib nexthops */ LIST_HEAD(, lde_map) downstream; /* recv mappings */ LIST_HEAD(, lde_map) upstream; /* sent mappings */ @@ -101,18 +101,18 @@ int lde_imsg_compose_parent(int, pid_t, void *, u_int16_t); int lde_imsg_compose_ldpe(int, u_int32_t, pid_t, void *, u_int16_t); u_int32_t lde_assign_label(void); -void lde_send_change_klabel(struct rt_node *, struct rt_lsp *); -void lde_send_delete_klabel(struct rt_node *, struct rt_lsp *); -void lde_send_labelmapping(struct lde_nbr *, struct rt_node *); -void lde_send_labelwithdraw(struct lde_nbr *, struct rt_node *); -void lde_send_labelrelease(struct lde_nbr *, struct rt_node *, u_int32_t); +void lde_send_change_klabel(struct fec_node *, struct fec_nh *); +void lde_send_delete_klabel(struct fec_node *, struct fec_nh *); +void lde_send_labelmapping(struct lde_nbr *, struct fec_node *); +void lde_send_labelwithdraw(struct lde_nbr *, struct fec_node *); +void lde_send_labelrelease(struct lde_nbr *, struct fec_node *, u_int32_t); void lde_send_notification(u_int32_t, u_int32_t, u_int32_t, u_int32_t); -struct lde_map *lde_map_add(struct lde_nbr *, struct rt_node *, int); +struct lde_map *lde_map_add(struct lde_nbr *, struct fec_node *, int); void lde_map_del(struct lde_nbr *, struct lde_map *, int); struct lde_req *lde_req_add(struct lde_nbr *, struct fec *, int); void lde_req_del(struct lde_nbr *, struct lde_req *, int); -struct lde_wdraw *lde_wdraw_add(struct lde_nbr *, struct rt_node *); +struct lde_wdraw *lde_wdraw_add(struct lde_nbr *, struct fec_node *); void lde_wdraw_del(struct lde_nbr *, struct lde_wdraw *); struct lde_nbr *lde_find_address(struct in_addr); @@ -129,8 +129,8 @@ struct fec *fec_find(struct fec_tree *, struct fec *); void fec_clear(struct fec_tree *, void (*)(void *)); void rt_dump(pid_t); -void rt_snap(struct lde_nbr *); -void rt_clear(void); +void fec_snap(struct lde_nbr *); +void fec_tree_clear(void); void lde_kernel_insert(struct kroute *); void lde_kernel_remove(struct kroute *); diff --git a/usr.sbin/ldpd/lde_lib.c b/usr.sbin/ldpd/lde_lib.c index 90dda85c783..c9d3576b048 100644 --- a/usr.sbin/ldpd/lde_lib.c +++ b/usr.sbin/ldpd/lde_lib.c @@ -1,4 +1,4 @@ -/* $OpenBSD: lde_lib.c,v 1.37 2015/07/19 20:54:16 renato Exp $ */ +/* $OpenBSD: lde_lib.c,v 1.38 2015/07/21 04:46:51 renato Exp $ */ /* * Copyright (c) 2009 Michele Marchetto <michele@openbsd.org> @@ -40,12 +40,12 @@ static int fec_compare(struct fec *, struct fec *); -void rt_free(void *); -struct rt_node *rt_add(struct in_addr, u_int8_t); -struct rt_lsp *rt_lsp_find(struct rt_node *, struct in_addr); -struct rt_lsp *rt_lsp_add(struct rt_node *, struct in_addr); -void rt_lsp_del(struct rt_lsp *); -int lde_nbr_is_nexthop(struct rt_node *, struct lde_nbr *); +void fec_free(void *); +struct fec_node *fec_add(struct in_addr, u_int8_t); +struct fec_nh *fec_nh_find(struct fec_node *, struct in_addr); +struct fec_nh *fec_nh_add(struct fec_node *, struct in_addr); +void fec_nh_del(struct fec_nh *); +int lde_nbr_is_nexthop(struct fec_node *, struct lde_nbr *); RB_GENERATE(fec_tree, fec, entry, fec_compare) @@ -54,7 +54,7 @@ RB_PROTOTYPE(nbr_tree, lde_nbr, entry, lde_nbr_compare) extern struct ldpd_conf *ldeconf; -struct fec_tree rt = RB_INITIALIZER(&rt); +struct fec_tree ft = RB_INITIALIZER(&ft); /* FEC tree functions */ void @@ -127,12 +127,12 @@ fec_clear(struct fec_tree *fh, void (*free_cb)(void *)) /* routing table functions */ int -lde_nbr_is_nexthop(struct rt_node *rn, struct lde_nbr *ln) +lde_nbr_is_nexthop(struct fec_node *fn, struct lde_nbr *ln) { - struct rt_lsp *rl; + struct fec_nh *fnh; - LIST_FOREACH(rl, &rn->lsp, entry) - if (lde_address_find(ln, &rl->nexthop)) + LIST_FOREACH(fnh, &fn->nexthops, entry) + if (lde_address_find(ln, &fnh->nexthop)) return (1); return (0); @@ -142,30 +142,30 @@ void rt_dump(pid_t pid) { struct fec *f; - struct rt_node *rr; + struct fec_node *fn; struct lde_map *me; static struct ctl_rt rtctl; - RB_FOREACH(f, fec_tree, &rt) { - rr = (struct rt_node *)f; - if (rr->local_label == NO_LABEL && - LIST_EMPTY(&rr->downstream)) + RB_FOREACH(f, fec_tree, &ft) { + fn = (struct fec_node *)f; + if (fn->local_label == NO_LABEL && + LIST_EMPTY(&fn->downstream)) continue; - rtctl.prefix = rr->fec.prefix; - rtctl.prefixlen = rr->fec.prefixlen; - rtctl.flags = rr->flags; - rtctl.local_label = rr->local_label; + rtctl.prefix = fn->fec.prefix; + rtctl.prefixlen = fn->fec.prefixlen; + rtctl.flags = fn->flags; + rtctl.local_label = fn->local_label; - LIST_FOREACH(me, &rr->downstream, entry) { - rtctl.in_use = lde_nbr_is_nexthop(rr, me->nexthop); + LIST_FOREACH(me, &fn->downstream, entry) { + rtctl.in_use = lde_nbr_is_nexthop(fn, me->nexthop); rtctl.nexthop = me->nexthop->id; rtctl.remote_label = me->label; lde_imsg_compose_ldpe(IMSG_CTL_SHOW_LIB, 0, pid, &rtctl, sizeof(rtctl)); } - if (LIST_EMPTY(&rr->downstream)) { + if (LIST_EMPTY(&fn->downstream)) { rtctl.in_use = 0; rtctl.nexthop.s_addr = INADDR_ANY; rtctl.remote_label = NO_LABEL; @@ -177,18 +177,18 @@ rt_dump(pid_t pid) } void -rt_snap(struct lde_nbr *ln) +fec_snap(struct lde_nbr *ln) { struct fec *f; - struct rt_node *rn; + struct fec_node *fn; int count = 0; - RB_FOREACH(f, fec_tree, &rt) { - rn = (struct rt_node *)f; - if (rn->local_label == NO_LABEL) + RB_FOREACH(f, fec_tree, &ft) { + fn = (struct fec_node *)f; + if (fn->local_label == NO_LABEL) continue; - lde_send_labelmapping(ln, rn); + lde_send_labelmapping(ln, fn); count++; } if (count > 0) @@ -197,91 +197,91 @@ rt_snap(struct lde_nbr *ln) } void -rt_free(void *arg) +fec_free(void *arg) { - struct rt_node *rr = arg; - struct rt_lsp *rl; - - while ((rl = LIST_FIRST(&rr->lsp))) - rt_lsp_del(rl); - if (!LIST_EMPTY(&rr->downstream)) - log_warnx("rt_free: fec %s/%u downstream list not empty", - inet_ntoa(rr->fec.prefix), rr->fec.prefixlen); - if (!LIST_EMPTY(&rr->upstream)) - log_warnx("rt_free: fec %s/%u upstream list not empty", - inet_ntoa(rr->fec.prefix), rr->fec.prefixlen); - - free(rr); + struct fec_node *fn = arg; + struct fec_nh *fnh; + + while ((fnh = LIST_FIRST(&fn->nexthops))) + fec_nh_del(fnh); + if (!LIST_EMPTY(&fn->downstream)) + log_warnx("fec_free: fec %s/%u downstream list not empty", + inet_ntoa(fn->fec.prefix), fn->fec.prefixlen); + if (!LIST_EMPTY(&fn->upstream)) + log_warnx("fec_free: fec %s/%u upstream list not empty", + inet_ntoa(fn->fec.prefix), fn->fec.prefixlen); + + free(fn); } void -rt_clear(void) +fec_tree_clear(void) { - fec_clear(&rt, rt_free); + fec_clear(&ft, fec_free); } -struct rt_node * -rt_add(struct in_addr prefix, u_int8_t prefixlen) +struct fec_node * +fec_add(struct in_addr prefix, u_int8_t prefixlen) { - struct rt_node *rn; + struct fec_node *fn; - rn = calloc(1, sizeof(*rn)); - if (rn == NULL) - fatal("rt_add"); + fn = calloc(1, sizeof(*fn)); + if (fn == NULL) + fatal("fec_add"); - rn->fec.prefix.s_addr = prefix.s_addr; - rn->fec.prefixlen = prefixlen; - rn->local_label = NO_LABEL; - LIST_INIT(&rn->upstream); - LIST_INIT(&rn->downstream); - LIST_INIT(&rn->lsp); + fn->fec.prefix.s_addr = prefix.s_addr; + fn->fec.prefixlen = prefixlen; + fn->local_label = NO_LABEL; + LIST_INIT(&fn->upstream); + LIST_INIT(&fn->downstream); + LIST_INIT(&fn->nexthops); - if (fec_insert(&rt, &rn->fec)) - log_warnx("failed to add %s/%u to rt tree", - inet_ntoa(rn->fec.prefix), rn->fec.prefixlen); + if (fec_insert(&ft, &fn->fec)) + log_warnx("failed to add %s/%u to ft tree", + inet_ntoa(fn->fec.prefix), fn->fec.prefixlen); - return (rn); + return (fn); } -struct rt_lsp * -rt_lsp_find(struct rt_node *rn, struct in_addr nexthop) +struct fec_nh * +fec_nh_find(struct fec_node *fn, struct in_addr nexthop) { - struct rt_lsp *rl; + struct fec_nh *fnh; - LIST_FOREACH(rl, &rn->lsp, entry) - if (rl->nexthop.s_addr == nexthop.s_addr) - return (rl); + LIST_FOREACH(fnh, &fn->nexthops, entry) + if (fnh->nexthop.s_addr == nexthop.s_addr) + return (fnh); return (NULL); } -struct rt_lsp * -rt_lsp_add(struct rt_node *rn, struct in_addr nexthop) +struct fec_nh * +fec_nh_add(struct fec_node *fn, struct in_addr nexthop) { - struct rt_lsp *rl; + struct fec_nh *fnh; - rl = calloc(1, sizeof(*rl)); - if (rl == NULL) - fatal("rt_lsp_add"); + fnh = calloc(1, sizeof(*fnh)); + if (fnh == NULL) + fatal("fec_nh_add"); - rl->nexthop.s_addr = nexthop.s_addr; - rl->remote_label = NO_LABEL; - LIST_INSERT_HEAD(&rn->lsp, rl, entry); + fnh->nexthop.s_addr = nexthop.s_addr; + fnh->remote_label = NO_LABEL; + LIST_INSERT_HEAD(&fn->nexthops, fnh, entry); - return (rl); + return (fnh); } void -rt_lsp_del(struct rt_lsp *rl) +fec_nh_del(struct fec_nh *fnh) { - LIST_REMOVE(rl, entry); - free(rl); + LIST_REMOVE(fnh, entry); + free(fnh); } void lde_kernel_insert(struct kroute *kr) { - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; struct lde_map *me; struct lde_nbr *ln; char buf[16]; @@ -290,54 +290,54 @@ lde_kernel_insert(struct kroute *kr) inet_ntoa(kr->prefix), kr->prefixlen, inet_ntop(AF_INET, &kr->nexthop, buf, sizeof(buf))); - rn = (struct rt_node *)fec_find_prefix(&rt, kr->prefix.s_addr, + fn = (struct fec_node *)fec_find_prefix(&ft, kr->prefix.s_addr, kr->prefixlen); - if (rn == NULL) - rn = rt_add(kr->prefix, kr->prefixlen); + if (fn == NULL) + fn = fec_add(kr->prefix, kr->prefixlen); - if (rt_lsp_find(rn, kr->nexthop) != NULL) + if (fec_nh_find(fn, kr->nexthop) != NULL) return; - if (LIST_EMPTY(&rn->lsp)) { - if (rn->local_label == NO_LABEL) { + if (LIST_EMPTY(&fn->nexthops)) { + if (fn->local_label == NO_LABEL) { if (kr->flags & F_CONNECTED) - rn->local_label = MPLS_LABEL_IMPLNULL; + fn->local_label = MPLS_LABEL_IMPLNULL; else - rn->local_label = lde_assign_label(); + fn->local_label = lde_assign_label(); } else { /* Handle local label changes */ if ((kr->flags & F_CONNECTED) && - rn->local_label != MPLS_LABEL_IMPLNULL) { + fn->local_label != MPLS_LABEL_IMPLNULL) { /* explicit withdraw of the previous label */ RB_FOREACH(ln, nbr_tree, &lde_nbrs) - lde_send_labelwithdraw(ln, rn); - rn->local_label = MPLS_LABEL_IMPLNULL; + lde_send_labelwithdraw(ln, fn); + fn->local_label = MPLS_LABEL_IMPLNULL; } if (!(kr->flags & F_CONNECTED) && - rn->local_label == MPLS_LABEL_IMPLNULL) { + fn->local_label == MPLS_LABEL_IMPLNULL) { /* explicit withdraw of the previous label */ RB_FOREACH(ln, nbr_tree, &lde_nbrs) - lde_send_labelwithdraw(ln, rn); - rn->local_label = lde_assign_label(); + lde_send_labelwithdraw(ln, fn); + fn->local_label = lde_assign_label(); } } /* FEC.1: perform lsr label distribution procedure */ RB_FOREACH(ln, nbr_tree, &lde_nbrs) { - lde_send_labelmapping(ln, rn); + lde_send_labelmapping(ln, fn); lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); } } - rl = rt_lsp_add(rn, kr->nexthop); - lde_send_change_klabel(rn, rl); + fnh = fec_nh_add(fn, kr->nexthop); + lde_send_change_klabel(fn, fnh); - ln = lde_find_address(rl->nexthop); + ln = lde_find_address(fnh->nexthop); if (ln) { /* FEC.2 */ - me = (struct lde_map *)fec_find(&ln->recv_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec); if (me) { struct map map; @@ -355,8 +355,8 @@ lde_kernel_insert(struct kroute *kr) void lde_kernel_remove(struct kroute *kr) { - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; struct lde_nbr *ln; char buf[16]; @@ -364,40 +364,40 @@ lde_kernel_remove(struct kroute *kr) inet_ntoa(kr->prefix), kr->prefixlen, inet_ntop(AF_INET, &kr->nexthop, buf, sizeof(buf))); - rn = (struct rt_node *)fec_find_prefix(&rt, kr->prefix.s_addr, + fn = (struct fec_node *)fec_find_prefix(&ft, kr->prefix.s_addr, kr->prefixlen); - if (rn == NULL) + if (fn == NULL) /* route lost */ return; - rl = rt_lsp_find(rn, kr->nexthop); - if (rl == NULL) + fnh = fec_nh_find(fn, kr->nexthop); + if (fnh == NULL) /* route lost */ return; - rt_lsp_del(rl); - if (LIST_EMPTY(&rn->lsp)) + fec_nh_del(fnh); + if (LIST_EMPTY(&fn->nexthops)) RB_FOREACH(ln, nbr_tree, &lde_nbrs) - lde_send_labelwithdraw(ln, rn); + lde_send_labelwithdraw(ln, fn); } void lde_check_mapping(struct map *map, struct lde_nbr *ln) { - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; struct lde_req *lre; struct lde_nbr_address *addr; struct lde_map *me; int msgsource = 0; - rn = (struct rt_node *)fec_find_prefix(&rt, map->prefix.s_addr, + fn = (struct fec_node *)fec_find_prefix(&ft, map->prefix.s_addr, map->prefixlen); - if (rn == NULL) - rn = rt_add(map->prefix, map->prefixlen); + if (fn == NULL) + fn = fec_add(map->prefix, map->prefixlen); /* LMp.1: first check if we have a pending request running */ - lre = (struct lde_req *)fec_find(&ln->sent_req, &rn->fec); + lre = (struct lde_req *)fec_find(&ln->sent_req, &fn->fec); if (lre) /* LMp.2: delete record of outstanding label request */ lde_req_del(ln, lre, 1); @@ -408,19 +408,19 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln) */ /* LMp.9 */ - me = (struct lde_map *)fec_find(&ln->recv_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec); if (me) { /* LMp.10 */ if (me->label != map->label && lre == NULL) { /* LMp.10a */ - lde_send_labelrelease(ln, rn, me->label); + lde_send_labelrelease(ln, fn, me->label); - LIST_FOREACH(rl, &rn->lsp, entry) + LIST_FOREACH(fnh, &fn->nexthops, entry) TAILQ_FOREACH(addr, &ln->addr_list, entry) - if (rl->nexthop.s_addr == + if (fnh->nexthop.s_addr == addr->addr.s_addr) { - lde_send_delete_klabel(rn, rl); - rl->remote_label = NO_LABEL; + lde_send_delete_klabel(fn, fnh); + fnh->remote_label = NO_LABEL; } } } @@ -429,29 +429,28 @@ lde_check_mapping(struct map *map, struct lde_nbr *ln) * LMp.11 - 12: consider multiple nexthops in order to * support multipath */ - LIST_FOREACH(rl, &rn->lsp, entry) { - if (lde_address_find(ln, &rl->nexthop)) { + LIST_FOREACH(fnh, &fn->nexthops, entry) { + if (lde_address_find(ln, &fnh->nexthop)) { msgsource = 1; /* LMp.15: install FEC in FIB */ - rl->remote_label = map->label; - lde_send_change_klabel(rn, rl); + fnh->remote_label = map->label; + lde_send_change_klabel(fn, fnh); } } if (msgsource == 0) { /* LMp.13: perform lsr label release procedure */ if (me == NULL) - me = lde_map_add(ln, rn, 0); + me = lde_map_add(ln, fn, 0); me->label = map->label; return; } /* LMp.16: Record the mapping from this peer */ if (me == NULL) - me = lde_map_add(ln, rn, 0); + me = lde_map_add(ln, fn, 0); me->label = map->label; - /* * LMp.17 - LMp.27 are unnecessary since we don't need to implement * loop detection. LMp.28 - LMp.30 are unnecessary because we are @@ -463,23 +462,23 @@ void lde_check_request(struct map *map, struct lde_nbr *ln) { struct lde_req *lre; - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; /* TODO LRq.1: loop detection */ /* LRq.2: is there a next hop for fec? */ - rn = (struct rt_node *)fec_find_prefix(&rt, map->prefix.s_addr, + fn = (struct fec_node *)fec_find_prefix(&ft, map->prefix.s_addr, map->prefixlen); - if (rn == NULL || LIST_EMPTY(&rn->lsp)) { + if (fn == NULL || LIST_EMPTY(&fn->nexthops)) { lde_send_notification(ln->peerid, S_NO_ROUTE, map->messageid, MSG_TYPE_LABELREQUEST); return; } /* LRq.3: is MsgSource the next hop? */ - LIST_FOREACH(rl, &rn->lsp, entry) { - if (lde_address_find(ln, &rl->nexthop)) { + LIST_FOREACH(fnh, &fn->nexthops, entry) { + if (lde_address_find(ln, &fnh->nexthop)) { lde_send_notification(ln->peerid, S_LOOP_DETECTED, map->messageid, MSG_TYPE_LABELREQUEST); return; @@ -487,18 +486,18 @@ lde_check_request(struct map *map, struct lde_nbr *ln) } /* LRq.6: first check if we have a pending request running */ - lre = (struct lde_req *)fec_find(&ln->recv_req, &rn->fec); + lre = (struct lde_req *)fec_find(&ln->recv_req, &fn->fec); if (lre != NULL) /* LRq.7: duplicate request */ return; /* LRq.8: record label request */ - lre = lde_req_add(ln, &rn->fec, 0); + lre = lde_req_add(ln, &fn->fec, 0); if (lre != NULL) lre->msgid = map->messageid; /* LRq.9: perform LSR label distribution */ - lde_send_labelmapping(ln, rn); + lde_send_labelmapping(ln, fn); lde_imsg_compose_ldpe(IMSG_MAPPING_ADD_END, ln->peerid, 0, NULL, 0); /* @@ -511,18 +510,18 @@ lde_check_request(struct map *map, struct lde_nbr *ln) void lde_check_release(struct map *map, struct lde_nbr *ln) { - struct rt_node *rn; + struct fec_node *fn; struct lde_wdraw *lw; struct lde_map *me; - rn = (struct rt_node *)fec_find_prefix(&rt, map->prefix.s_addr, + fn = (struct fec_node *)fec_find_prefix(&ft, map->prefix.s_addr, map->prefixlen); /* LRl.1: does FEC match a known FEC? */ - if (rn == NULL) + if (fn == NULL) return; /* LRl.3: first check if we have a pending withdraw running */ - lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &rn->fec); + lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &fn->fec); if (lw && (map->label == NO_LABEL || (lw->label != NO_LABEL && map->label == lw->label))) { /* LRl.4: delete record of outstanding label withdraw */ @@ -530,7 +529,7 @@ lde_check_release(struct map *map, struct lde_nbr *ln) } /* LRl.6: check sent map list and remove it if available */ - me = (struct lde_map *)fec_find(&ln->sent_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->sent_map, &fn->fec); if (me && (map->label == NO_LABEL || map->label == me->label)) lde_map_del(ln, me, 1); @@ -544,15 +543,15 @@ void lde_check_release_wcard(struct map *map, struct lde_nbr *ln) { struct fec *f; - struct rt_node *rn; + struct fec_node *fn; struct lde_wdraw *lw; struct lde_map *me; - RB_FOREACH(f, fec_tree, &rt) { - rn = (struct rt_node *)f; + RB_FOREACH(f, fec_tree, &ft) { + fn = (struct fec_node *)f; /* LRl.3: first check if we have a pending withdraw running */ - lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &rn->fec); + lw = (struct lde_wdraw *)fec_find(&ln->sent_wdraw, &fn->fec); if (lw && (map->label == NO_LABEL || (lw->label != NO_LABEL && map->label == lw->label))) { /* LRl.4: delete record of outstanding lbl withdraw */ @@ -560,7 +559,7 @@ lde_check_release_wcard(struct map *map, struct lde_nbr *ln) } /* LRl.6: check sent map list and remove it if available */ - me = (struct lde_map *)fec_find(&ln->sent_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->sent_map, &fn->fec); if (me && (map->label == NO_LABEL || map->label == me->label)) { lde_map_del(ln, me, 1); @@ -576,28 +575,28 @@ lde_check_release_wcard(struct map *map, struct lde_nbr *ln) void lde_check_withdraw(struct map *map, struct lde_nbr *ln) { - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; struct lde_map *me; - rn = (struct rt_node *)fec_find_prefix(&rt, map->prefix.s_addr, + fn = (struct fec_node *)fec_find_prefix(&ft, map->prefix.s_addr, map->prefixlen); - if (rn == NULL) - rn = rt_add(map->prefix, map->prefixlen); + if (fn == NULL) + fn = fec_add(map->prefix, map->prefixlen); /* LWd.1: remove label from forwarding/switching use */ - LIST_FOREACH(rl, &rn->lsp, entry) { - if (lde_address_find(ln, &rl->nexthop)) { - lde_send_delete_klabel(rn, rl); - rl->remote_label = NO_LABEL; + LIST_FOREACH(fnh, &fn->nexthops, entry) { + if (lde_address_find(ln, &fnh->nexthop)) { + lde_send_delete_klabel(fn, fnh); + fnh->remote_label = NO_LABEL; } } /* LWd.2: send label release */ - lde_send_labelrelease(ln, rn, map->label); + lde_send_labelrelease(ln, fn, map->label); /* LWd.3: check previously received label mapping */ - me = (struct lde_map *)fec_find(&ln->recv_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec); if (me && (map->label == NO_LABEL || map->label == me->label)) /* LWd.4: remove record of previously received lbl mapping */ lde_map_del(ln, me, 0); @@ -607,26 +606,26 @@ void lde_check_withdraw_wcard(struct map *map, struct lde_nbr *ln) { struct fec *f; - struct rt_node *rn; - struct rt_lsp *rl; + struct fec_node *fn; + struct fec_nh *fnh; struct lde_map *me; /* LWd.2: send label release */ lde_send_labelrelease(ln, NULL, map->label); - RB_FOREACH(f, fec_tree, &rt) { - rn = (struct rt_node *)f; + RB_FOREACH(f, fec_tree, &ft) { + fn = (struct fec_node *)f; /* LWd.1: remove label from forwarding/switching use */ - LIST_FOREACH(rl, &rn->lsp, entry) { - if (lde_address_find(ln, &rl->nexthop)) { - lde_send_delete_klabel(rn, rl); - rl->remote_label = NO_LABEL; + LIST_FOREACH(fnh, &fn->nexthops, entry) { + if (lde_address_find(ln, &fnh->nexthop)) { + lde_send_delete_klabel(fn, fnh); + fnh->remote_label = NO_LABEL; } } /* LWd.3: check previously received label mapping */ - me = (struct lde_map *)fec_find(&ln->recv_map, &rn->fec); + me = (struct lde_map *)fec_find(&ln->recv_map, &fn->fec); if (me && (map->label == NO_LABEL || map->label == me->label)) /* * LWd.4: remove record of previously received |