From d2cd9a87f0148db6c12fd5b146ea4ee8bca060d7 Mon Sep 17 00:00:00 2001 From: "James R. Leu" Date: Sun, 21 Sep 2003 21:48:19 -0600 Subject: [PATCH] Various bug fixes to get basic label distribution working again [git-p4: depot-paths = "//depot/ldp-portable/": change = 409] --- ldp/ldp_cfg.c | 4 +- ldp/ldp_fec.c | 10 +++ ldp/ldp_fec.h | 1 + ldp/ldp_global.c | 1 + ldp/ldp_label_mapping.c | 169 ++++++++++++++++++++++++------------------------ ldp/ldp_nexthop.c | 2 +- ldp/ldp_session.c | 7 +- ldp/ldp_state_funcs.c | 10 +-- 8 files changed, 108 insertions(+), 96 deletions(-) diff --git a/ldp/ldp_cfg.c b/ldp/ldp_cfg.c index 71de3b9..32e611e 100644 --- a/ldp/ldp_cfg.c +++ b/ldp/ldp_cfg.c @@ -861,7 +861,8 @@ mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t fla np = MPLS_LIST_HEAD(&global->nexthop); while (np) { - if (np->info.if_handle == iff->handle && (!MPLS_LIST_IN_LIST(np, _if))) { + if ((np->type & MPLS_NH_IF) && (np->info.if_handle == iff->handle) && + (!MPLS_LIST_IN_LIST(np, _if))) { ldp_if_add_nexthop(iff, np); } np = MPLS_LIST_NEXT(&global->nexthop, np, _global); @@ -1712,7 +1713,6 @@ mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i, if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) { ldp_if_find_addr_index(iff, a->index, &addr); } else { - fprintf(stderr, "ldp_cfg_if_addr_set: iff = %p\n", iff); addr = ldp_if_addr_find(iff, &a->address); } } diff --git a/ldp/ldp_fec.c b/ldp/ldp_fec.c index c8149f3..1d6e4c5 100644 --- a/ldp/ldp_fec.c +++ b/ldp/ldp_fec.c @@ -141,6 +141,16 @@ ldp_fec *ldp_fec_insert(ldp_global *g, mpls_fec * fec) return f; } +ldp_fec *ldp_fec_find2(ldp_global *g, mpls_fec *fec) +{ + ldp_fec *f = NULL; + f = ldp_fec_find(g, fec); + if (!f) { + f = ldp_fec_insert(g, fec); + } + return f; +} + void ldp_fec_remove(ldp_global *g, mpls_fec *fec) { ldp_fec *f = NULL; diff --git a/ldp/ldp_fec.h b/ldp/ldp_fec.h index ae6e163..66765cb 100644 --- a/ldp/ldp_fec.h +++ b/ldp/ldp_fec.h @@ -11,6 +11,7 @@ #define _LDP_FEC_H_ extern ldp_fec *ldp_fec_find(ldp_global *g, mpls_fec *fec); +extern ldp_fec *ldp_fec_find2(ldp_global *g, mpls_fec *fec); extern ldp_nexthop *ldp_fec_nexthop_find(ldp_fec *f, mpls_nexthop *n); extern mpls_return_enum ldp_fec_find_nexthop_index(ldp_fec *f, int index, ldp_nexthop **n); diff --git a/ldp/ldp_global.c b/ldp/ldp_global.c index 2ca7560..1978831 100644 --- a/ldp/ldp_global.c +++ b/ldp/ldp_global.c @@ -313,6 +313,7 @@ mpls_return_enum ldp_global_startup(ldp_global * g) if (ldp_fec_add_nexthop(g, f, n) != MPLS_SUCCESS) { goto ldp_global_startup_cleanup; } + _ldp_global_add_nexthop(g, n); } while (mpls_fib_getnext_route(g->fib_handle, &fec, &nexthop) == MPLS_SUCCESS); } diff --git a/ldp/ldp_label_mapping.c b/ldp/ldp_label_mapping.c index c1de4f6..ab3516e 100644 --- a/ldp/ldp_label_mapping.c +++ b/ldp/ldp_label_mapping.c @@ -394,100 +394,99 @@ void ldp_label_mapping_initial_callback(mpls_timer_handle timer, void *extra, mpls_timer_stop(g->timer_handle, timer); - if ((f = MPLS_LIST_HEAD(&g->fec))) { - do { - if ((nh = MPLS_LIST_HEAD(&f->nh_root))) { - do { - switch (f->info.type) { - case MPLS_FEC_PREFIX: - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "Processing prefix FEC: %08x/%d ", - f->info.u.prefix.network.u.ipv4, f->info.u.prefix.length); - break; - case MPLS_FEC_HOST: - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "Processing host FEC: %08x ", - f->info.u.host.u.ipv4); - break; - case MPLS_FEC_L2CC: - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "Processingu L2CC FEC: %d %d %d ", - f->info.u.l2cc.connection_id, f->info.u.l2cc.group_id, - f->info.u.l2cc.type); - break; - default: - MPLS_ASSERT(0); - } + f = MPLS_LIST_HEAD(&g->fec); + while (f) { + nh = MPLS_LIST_HEAD(&f->nh_root); + while (nh) { + switch (f->info.type) { + case MPLS_FEC_PREFIX: + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "Processing prefix FEC: %08x/%d ", + f->info.u.prefix.network.u.ipv4, f->info.u.prefix.length); + break; + case MPLS_FEC_HOST: + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "Processing host FEC: %08x ", + f->info.u.host.u.ipv4); + break; + case MPLS_FEC_L2CC: + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "Processingu L2CC FEC: %d %d %d ", + f->info.u.l2cc.connection_id, f->info.u.l2cc.group_id, + f->info.u.l2cc.type); + break; + default: + MPLS_ASSERT(0); + } - if (nh->type & MPLS_NH_IP) { - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "via %08x\n", nh->addr->address.u.ipv4); - } - if (nh->type & MPLS_NH_IF) { - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "via %p\n", nh->iff->handle); - } + if (nh->type & MPLS_NH_IP) { + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "via %08x\n", nh->addr->address.u.ipv4); + } + if (nh->type & MPLS_NH_IF && nh->iff) { + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "via %p\n", nh->iff->handle); + } - /* are we allowed to export this route from the rib */ - if (mpls_policy_export_check(g->user_data, &f->info, &nh->info) == - MPLS_BOOL_FALSE) { - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_POLICY, "Rejected by export policy\n"); - continue; - } + /* are we allowed to export this route from the rib */ + if (mpls_policy_export_check(g->user_data, &f->info, &nh->info) == + MPLS_BOOL_FALSE) { + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_POLICY, "Rejected by export policy\n"); + goto ldp_label_mapping_initial_callback_end_nh; + } - /* have we already sent a mapping for this fec to the new session? */ - if ((us_attr = ldp_attr_find_upstream_state2(g, s, f, - LDP_LSP_STATE_MAP_SENT))) { - /* no need to sent another mapping */ - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "Already sent this FEC to session %d\n", - s->index); - continue; - } + /* have we already sent a mapping for this fec to the new session? */ + if ((us_attr = ldp_attr_find_upstream_state2(g, s, f, + LDP_LSP_STATE_MAP_SENT))) { + /* no need to sent another mapping */ + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "Already sent this FEC to session %d\n", + s->index); + goto ldp_label_mapping_initial_callback_end_nh; + } - if (!(nh_session = ldp_get_next_hop_session_for_fec2(f,nh))) { - ds_attr = NULL; - } else { - if (nh_session->index == s->index) { - LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "Nexthop session(%d) == session(%d)\n", - nh_session->index, s->index); - continue; - } - ds_attr = ldp_attr_find_downstream_state2(g, nh_session, f, - LDP_LSP_STATE_MAP_RECV); - } + if (!(nh_session = ldp_get_next_hop_session_for_fec2(f,nh))) { + ds_attr = NULL; + } else { + if (nh_session->index == s->index) { + LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, + LDP_TRACE_FLAG_ROUTE, "Nexthop session(%d) == session(%d)\n", + nh_session->index, s->index); + goto ldp_label_mapping_initial_callback_end_nh; + } + ds_attr = ldp_attr_find_downstream_state2(g, nh_session, f, + LDP_LSP_STATE_MAP_RECV); + } - if ((g->label_merge != MPLS_BOOL_TRUE) && - ldp_attr_num_us2ds(ds_attr)) { - /* we have a ds label, but can't use it */ - ds_attr = NULL; - } + if ((g->label_merge != MPLS_BOOL_TRUE) && + ldp_attr_num_us2ds(ds_attr)) { + /* we have a ds label, but can't use it */ + ds_attr = NULL; + } - us_attr = NULL; - if (ds_attr) { - /* we can use it, merge on baby */ - ldp_label_mapping_with_xc(g, s, f, &us_attr, ds_attr); - } else { - /* we don't have a ds label */ - - /* we will be egress? */ - if (g->lsp_control_mode == LDP_CONTROL_ORDERED) { - if (mpls_policy_egress_check(g->user_data, &f->info, - &nh->info) == MPLS_BOOL_TRUE) { - ldp_label_mapping_with_xc(g, s, f, &us_attr, NULL); - } - } else { - ldp_label_mapping_with_xc(g, s, f, &us_attr, NULL); - } + us_attr = NULL; + if (ds_attr) { + /* we can use it, merge on baby */ + ldp_label_mapping_with_xc(g, s, f, &us_attr, ds_attr); + } else { + /* we don't have a ds label */ + + /* we will be egress? */ + if (g->lsp_control_mode == LDP_CONTROL_ORDERED) { + if (mpls_policy_egress_check(g->user_data, &f->info, + &nh->info) == MPLS_BOOL_TRUE) { + ldp_label_mapping_with_xc(g, s, f, &us_attr, NULL); } - } while ((nh = MPLS_LIST_NEXT(&f->nh_root, nh, _fec))); + } else { + ldp_label_mapping_with_xc(g, s, f, &us_attr, NULL); + } } - } while ((f = MPLS_LIST_NEXT(&g->fec, f, _global))); - done = MPLS_BOOL_TRUE; +ldp_label_mapping_initial_callback_end_nh: + nh = MPLS_LIST_NEXT(&f->nh_root, nh, _fec); + } + f = MPLS_LIST_NEXT(&g->fec, f, _global); } - done = MPLS_BOOL_TRUE; if (done == MPLS_BOOL_TRUE) { diff --git a/ldp/ldp_nexthop.c b/ldp/ldp_nexthop.c index dd59ee2..a505cae 100644 --- a/ldp/ldp_nexthop.c +++ b/ldp/ldp_nexthop.c @@ -113,7 +113,7 @@ void ldp_nexthop_add_outlabel2(ldp_nexthop * n, ldp_outlabel * o) MPLS_ASSERT(n && o); MPLS_REFCNT_HOLD(o); MPLS_LIST_ADD_HEAD(&n->outlabel_root, o, _nexthop, ldp_outlabel); - ldp_outlabel_add_nexthop2(o, n); + memcpy(&o->info.nexthop, &n->info, sizeof(mpls_nexthop)); } void ldp_nexthop_del_outlabel2(ldp_nexthop * n, ldp_outlabel * o) diff --git a/ldp/ldp_session.c b/ldp/ldp_session.c index 41eb613..e35ca84 100644 --- a/ldp/ldp_session.c +++ b/ldp/ldp_session.c @@ -732,6 +732,8 @@ mpls_return_enum ldp_session_backoff_start(ldp_global * g, ldp_session * s) ldp_session *ldp_session_for_nexthop(ldp_nexthop *nh) { + MPLS_ASSERT(nh); + if (nh->type & MPLS_NH_IP) { MPLS_ASSERT(mpls_link_list_count(&nh->addr->session_root) < 2); ldp_session *s = mpls_link_list_head_data(&nh->addr->session_root); @@ -740,9 +742,8 @@ ldp_session *ldp_session_for_nexthop(ldp_nexthop *nh) } } if (nh->type & MPLS_NH_IF) { - MPLS_ASSERT(nh->iff->is_p2p); - ldp_session *s = mpls_link_list_head_data(&nh->iff->session_root); - if (s) { + ldp_session *s = NULL; + if (nh->iff && (s = mpls_link_list_head_data(&nh->iff->session_root))) { return s; } } diff --git a/ldp/ldp_state_funcs.c b/ldp/ldp_state_funcs.c index a3174c7..6718fae 100644 --- a/ldp/ldp_state_funcs.c +++ b/ldp/ldp_state_funcs.c @@ -296,7 +296,7 @@ mpls_return_enum ldp_state_process(ldp_global * g, ldp_session * s, ldp_adj * a, MPLS_REFCNT_HOLD(r_attr); rel_with2attr(rw, r_attr); - f = ldp_fec_find(g, &fec); + f = ldp_fec_find2(g, &fec); retval = ldp_label_withdraw_process(g, s, a, e, r_attr, f); MPLS_REFCNT_RELEASE(r_attr, ldp_attr_delete); @@ -319,7 +319,7 @@ mpls_return_enum ldp_state_process(ldp_global * g, ldp_session * s, ldp_adj * a, MPLS_REFCNT_HOLD(r_attr); rel_with2attr(rw, r_attr); - f = ldp_fec_find(g, &fec); + f = ldp_fec_find2(g, &fec); retval = ldp_label_release_process(g, s, a, e, r_attr, f); MPLS_REFCNT_RELEASE(r_attr, ldp_attr_delete); @@ -344,7 +344,7 @@ mpls_return_enum ldp_state_process(ldp_global * g, ldp_session * s, ldp_adj * a, MPLS_REFCNT_HOLD(r_attr); req2attr(req, r_attr, LDP_ATTR_ALL & ~LDP_ATTR_FEC); - f = ldp_fec_find(g, &fec); + f = ldp_fec_find2(g, &fec); retval = ldp_label_request_process(g, s, a, e, r_attr, f); MPLS_REFCNT_RELEASE(r_attr, ldp_attr_delete); @@ -366,7 +366,7 @@ mpls_return_enum ldp_state_process(ldp_global * g, ldp_session * s, ldp_adj * a, MPLS_REFCNT_HOLD(r_attr); map2attr(map, r_attr, LDP_ATTR_ALL & ~LDP_ATTR_FEC); - f = ldp_fec_find(g, &fec); + f = ldp_fec_find2(g, &fec); retval = ldp_label_mapping_process(g, s, a, e, r_attr, f); MPLS_REFCNT_RELEASE(r_attr, ldp_attr_delete); @@ -388,7 +388,7 @@ mpls_return_enum ldp_state_process(ldp_global * g, ldp_session * s, ldp_adj * a, MPLS_REFCNT_HOLD(r_attr); abort2attr(abrt, r_attr, LDP_ATTR_ALL & ~LDP_ATTR_FEC); - f = ldp_fec_find(g, &fec); + f = ldp_fec_find2(g, &fec); retval = ldp_label_abort_process(g, s, a, e, r_attr, f); MPLS_REFCNT_RELEASE(r_attr, ldp_attr_delete); -- 2.11.4.GIT