From 5eb10cdd89dec361f2cb47932b6be6f22b1b1567 Mon Sep 17 00:00:00 2001 From: "James R. Leu" Date: Tue, 15 Jun 2004 15:52:20 -0600 Subject: [PATCH] Re-work iff, addr, fec, nexthop life cycle. iff and fec are now held by cfg. [git-p4: depot-paths = "//depot/ldp-portable/": change = 754] --- ldp/ldp_addr.c | 24 +++++++++++------------- ldp/ldp_cfg.c | 21 +++++++++++++-------- ldp/ldp_fec.c | 4 ++-- ldp/ldp_global.c | 36 +++++++++++++++--------------------- ldp/ldp_if.c | 16 +++++++++++++--- ldp/ldp_nexthop.c | 24 +++++++++++++++--------- ldp/ldp_nexthop.h | 6 +++--- ldp/ldp_outlabel.c | 12 ++++++------ ldp/ldp_outlabel.h | 4 ++-- 9 files changed, 80 insertions(+), 67 deletions(-) diff --git a/ldp/ldp_addr.c b/ldp/ldp_addr.c index 10ddb28..0fbea23 100644 --- a/ldp/ldp_addr.c +++ b/ldp/ldp_addr.c @@ -39,7 +39,13 @@ ldp_addr *ldp_addr_create(ldp_global *g, mpls_inet_addr * address) * when this refcnt gets to zero, it will be removed from the * global list and deleted */ + /* + * TESTING: jleu 6/7/2004, since I want the addr to be cleaned up + * when it no longer has a nexthop, fec, or label, the only things that + * should increment the ref are those (nh, fec, label etc), not global + * nor inserting into the tree. MPLS_REFCNT_INIT(a, 1); + */ mpls_link_list_init(&a->session_root); MPLS_LIST_INIT(&a->nh_root, ldp_nexthop); MPLS_LIST_ELEM_INIT(a, _global); @@ -47,14 +53,16 @@ ldp_addr *ldp_addr_create(ldp_global *g, mpls_inet_addr * address) memcpy(&a->address, address, sizeof(mpls_inet_addr)); a->index = _ldp_addr_get_next_index(); _ldp_global_add_addr(g, a); + ldp_addr_insert2(g, a); } return a; } void ldp_addr_delete(ldp_global *g, ldp_addr * a) { - LDP_PRINT(g->user_data,"addr delete\n"); + fprintf(stderr, "addr delete: %p\n", a); MPLS_REFCNT_ASSERT(a, 0); + ldp_addr_remove(g, &a->address); _ldp_global_del_addr(g, a); mpls_free(a); } @@ -78,17 +86,11 @@ ldp_addr *ldp_addr_insert(ldp_global *g, mpls_inet_addr * address) LDP_PRINT(g->user_data, "ldp_addr_insert: error creating address\n"); return NULL; } - - if (ldp_addr_insert2(g, addr) != MPLS_SUCCESS) { - LDP_PRINT(g->user_data, "ldp_addr_insert: error adding addr\n"); - return NULL; - } return addr; } mpls_return_enum ldp_addr_insert2(ldp_global *g, ldp_addr *addr) { - MPLS_REFCNT_HOLD(addr); if (mpls_tree_insert(g->addr_tree, addr->address.u.ipv4, 32, (void *)addr) != MPLS_SUCCESS) { LDP_PRINT(g->user_data, "ldp_addr_insert2: error adding addr\n"); @@ -101,11 +103,7 @@ mpls_return_enum ldp_addr_insert2(ldp_global *g, ldp_addr *addr) void ldp_addr_remove(ldp_global *g, mpls_inet_addr * address) { ldp_addr *addr = NULL; - - if (mpls_tree_remove(g->addr_tree, address->u.ipv4, 32, (void **)&addr) == - MPLS_SUCCESS) { - MPLS_REFCNT_RELEASE2(g, addr, ldp_addr_delete); - } + mpls_tree_remove(g->addr_tree, address->u.ipv4, 32, (void **)&addr); } void ldp_addr_add_if(ldp_addr * a, ldp_if * i) @@ -174,7 +172,7 @@ void ldp_addr_del_nexthop(ldp_global *g, ldp_addr * a, ldp_nexthop * nh) MPLS_ASSERT(a && nh); MPLS_LIST_REMOVE(&a->nh_root, nh, _addr); ldp_nexthop_del_addr(g, nh); - MPLS_REFCNT_RELEASE(nh, ldp_nexthop_delete); + MPLS_REFCNT_RELEASE2(g, nh, ldp_nexthop_delete); } uint32_t _ldp_addr_get_next_index() diff --git a/ldp/ldp_cfg.c b/ldp/ldp_cfg.c index 1ce5e6c..72b9481 100644 --- a/ldp/ldp_cfg.c +++ b/ldp/ldp_cfg.c @@ -886,6 +886,7 @@ mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t fla /* send the newly created index back to the user */ i->index = iff->index; + MPLS_REFCNT_HOLD(iff); } else { if (flag & LDP_IF_CFG_BY_INDEX) { @@ -919,15 +920,13 @@ mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t fla } np = MPLS_LIST_HEAD(&iff->nh_root); - while (np) { + while ((np = MPLS_LIST_HEAD(&iff->nh_root))) { ldp_if_del_nexthop(global, iff, np); - np = MPLS_LIST_NEXT(&iff->nh_root, np, _if); } ap = MPLS_LIST_HEAD(&iff->addr_root); - while (ap) { + while ((ap = MPLS_LIST_HEAD(&iff->addr_root))) { ldp_if_del_addr(global, iff, ap); - ap = MPLS_LIST_NEXT(&iff->addr_root, ap, _if); } MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete); @@ -1299,6 +1298,7 @@ mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f, { ldp_global *global = (ldp_global *) handle; ldp_fec *fec = NULL; + ldp_nexthop *nh; mpls_return_enum retval = MPLS_FAILURE; MPLS_ASSERT(global !=NULL && f != NULL); @@ -1311,6 +1311,7 @@ mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f, if (ldp_fec_find(global, f) || (fec = ldp_fec_create(global, f)) == NULL) { goto ldp_cfg_fec_set_end; } + MPLS_REFCNT_HOLD(fec); f->index = fec->index; } else { if (flag & LDP_FEC_CFG_BY_INDEX) { @@ -1326,7 +1327,12 @@ mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f, } if (flag & LDP_CFG_DEL) { - MPLS_ASSERT(0); + + while ((nh = MPLS_LIST_HEAD(&fec->nh_root))) { + ldp_fec_del_nexthop(global, fec, nh); + } + + MPLS_REFCNT_RELEASE2(global, fec, ldp_fec_delete); } retval = MPLS_SUCCESS; @@ -1466,12 +1472,11 @@ mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f, goto ldp_cfg_fec_nexthop_set_end; if (flag & LDP_CFG_ADD) { - if (ldp_fec_nexthop_find(fec, n) || (nh = ldp_nexthop_create()) == NULL) { + if (ldp_fec_nexthop_find(fec, n) || + (nh = ldp_nexthop_create(global, n)) == NULL) { goto ldp_cfg_fec_nexthop_set_end; } n->index = nh->index; - mpls_nexthop2ldp_nexthop(n, nh); - _ldp_global_add_nexthop(global, nh); ldp_fec_add_nexthop(global, fec, nh); ldp_fec_process_add(global, fec, nh, NULL); } else { diff --git a/ldp/ldp_fec.c b/ldp/ldp_fec.c index 8596733..3bfa039 100644 --- a/ldp/ldp_fec.c +++ b/ldp/ldp_fec.c @@ -301,13 +301,13 @@ void ldp_fec_del_nexthop(ldp_global *g, ldp_fec * f, ldp_nexthop *nh) ldp_if_del_nexthop(g, nh->iff, nh); } if (nh->outlabel) { - ldp_outlabel_del_nexthop(nh->outlabel, nh); + ldp_outlabel_del_nexthop(g, nh->outlabel, nh); } MPLS_LIST_REMOVE(&f->nh_root, nh, _fec); ldp_nexthop_del_fec(g, nh); - MPLS_REFCNT_RELEASE(nh, ldp_nexthop_delete); + MPLS_REFCNT_RELEASE2(g, nh, ldp_nexthop_delete); } mpls_return_enum ldp_fec_process_add(ldp_global * g, ldp_fec * f, diff --git a/ldp/ldp_global.c b/ldp/ldp_global.c index f7aa040..945fb4e 100644 --- a/ldp/ldp_global.c +++ b/ldp/ldp_global.c @@ -255,6 +255,7 @@ mpls_return_enum ldp_global_startup(ldp_global * g) mpls_socket_readlist_add(g->socket_handle, g->listen_socket, 0, MPLS_SOCKET_TCP_LISTEN); +#if 0 { mpls_if_handle iff; mpls_inet_addr addr; @@ -314,6 +315,7 @@ mpls_return_enum ldp_global_startup(ldp_global * g) MPLS_SUCCESS); } } +#endif e = MPLS_LIST_HEAD(&g->entity); while (e != NULL) { @@ -341,6 +343,10 @@ ldp_global_startup_cleanup: mpls_return_enum ldp_global_shutdown(ldp_global * g) { ldp_entity *e = NULL; + ldp_nexthop *n; + ldp_fec *f; + ldp_addr *a; + ldp_if *i; MPLS_ASSERT(g); @@ -354,24 +360,18 @@ mpls_return_enum ldp_global_shutdown(ldp_global * g) g->admin_state = MPLS_ADMIN_DISABLE; - { - ldp_nexthop *n; - ldp_fec *f; - while ((f = MPLS_LIST_HEAD(&g->fec))) { - while ((n = MPLS_LIST_HEAD(&f->nh_root))) { - ldp_fec_del_nexthop(g, f, n); - } + while ((f = MPLS_LIST_HEAD(&g->fec))) { + while ((n = MPLS_LIST_HEAD(&f->nh_root))) { + ldp_fec_del_nexthop(g, f, n); } + MPLS_REFCNT_RELEASE2(g, f, ldp_fec_delete); } - { - ldp_addr *a; - ldp_if *i; - while ((i = MPLS_LIST_HEAD(&g->iff))) { - while ((a = MPLS_LIST_HEAD(&i->addr_root))) { - ldp_if_del_addr(g, i, a); - } - ldp_if_remove(g, i); + + while ((i = MPLS_LIST_HEAD(&g->iff))) { + while ((a = MPLS_LIST_HEAD(&i->addr_root))) { + ldp_if_del_addr(g, i, a); } + MPLS_REFCNT_RELEASE2(g, i, ldp_if_delete); } mpls_socket_readlist_del(g->socket_handle, g->hello_socket); @@ -546,15 +546,11 @@ void _ldp_global_add_entity(ldp_global * g, ldp_entity * e) while (ep != NULL) { if (ep->index > e->index) { MPLS_LIST_INSERT_BEFORE(&g->entity, ep, e, _global); - fprintf(stderr, "global add entity: n: %p p: %p\n", e->_global.lle_next, - e->_global.lle_prev); return; } ep = MPLS_LIST_NEXT(&g->entity, ep, _global); } MPLS_LIST_ADD_TAIL(&g->entity, e, _global, ldp_entity); - fprintf(stderr, "global add entity: n: %p p: %p\n", e->_global.lle_next, - e->_global.lle_prev); } void _ldp_global_del_entity(ldp_global * g, ldp_entity * e) @@ -1271,7 +1267,6 @@ void _ldp_global_add_nexthop(ldp_global * g, ldp_nexthop * nh) ldp_nexthop *nhp = NULL; MPLS_ASSERT(g && nh); - MPLS_REFCNT_HOLD(nh); nhp = MPLS_LIST_HEAD(&g->nexthop); while (nhp != NULL) { if (nhp->index > nh->index) { @@ -1287,5 +1282,4 @@ void _ldp_global_del_nexthop(ldp_global * g, ldp_nexthop * nh) { MPLS_ASSERT(g && nh); MPLS_LIST_REMOVE(&g->nexthop, nh, _global); - MPLS_REFCNT_RELEASE(nh, ldp_nexthop_delete); } diff --git a/ldp/ldp_if.c b/ldp/ldp_if.c index 20878d5..49a88a3 100644 --- a/ldp/ldp_if.c +++ b/ldp/ldp_if.c @@ -44,7 +44,13 @@ ldp_if *ldp_if_create(ldp_global *g) * when this refcnt gets to zero, it will be removed from the * global list and deleted */ + /* + * TESTING: jleu 6/7/2004, since I want the iff to be cleaned up + * when it no longer has a nexthop, fec, or label, the only things that + * should increment the ref are those (nh, fec, label etc), not global + * nor inserting into the tree. MPLS_REFCNT_INIT(i, 1); + */ MPLS_LIST_ELEM_INIT(i, _global); MPLS_LIST_INIT(&i->nh_root, ldp_nexthop); MPLS_LIST_INIT(&i->addr_root, ldp_addr); @@ -63,11 +69,13 @@ ldp_if *ldp_if_create(ldp_global *g) void ldp_if_delete(ldp_global *g, ldp_if * i) { - LDP_PRINT(g->user_data,"if delete\n"); - _ldp_global_del_if(g, i); + fprintf(stderr, "if delete: %p\n", i); MPLS_REFCNT_ASSERT(i, 0); mpls_free(i->tx_buffer); mpls_free(i->tx_message); + i->tx_buffer = NULL; + i->tx_message = NULL; + _ldp_global_del_if(g, i); mpls_free(i); } @@ -91,11 +99,13 @@ ldp_if *ldp_if_insert(ldp_global *g, mpls_if_handle handle) return iff; } +#if 0 void ldp_if_remove(ldp_global *g, ldp_if *iff) { MPLS_ASSERT(g && iff); MPLS_REFCNT_RELEASE2(g, iff, ldp_if_delete); } +#endif void ldp_if_add_nexthop(ldp_if * i, ldp_nexthop * n) { @@ -122,7 +132,7 @@ void ldp_if_del_nexthop(ldp_global *g, ldp_if * i, ldp_nexthop * n) MPLS_ASSERT(i && n); MPLS_LIST_REMOVE(&i->nh_root, n, _if); ldp_nexthop_del_if(g, n); - MPLS_REFCNT_RELEASE(n, ldp_nexthop_delete); + MPLS_REFCNT_RELEASE2(g, n, ldp_nexthop_delete); } void ldp_if_add_addr(ldp_if * i, ldp_addr * a) diff --git a/ldp/ldp_nexthop.c b/ldp/ldp_nexthop.c index acf7798..354a017 100644 --- a/ldp/ldp_nexthop.c +++ b/ldp/ldp_nexthop.c @@ -13,6 +13,7 @@ #include "ldp_addr.h" #include "ldp_session.h" #include "ldp_outlabel.h" +#include "ldp_global.h" #include "mpls_assert.h" #include "mpls_compare.h" #include "mpls_mm_impl.h" @@ -29,6 +30,11 @@ static uint32_t _ldp_nexthop_next_index = 1; static uint32_t _ldp_nexthop_get_next_index(); +void mpls_nexthop2ldp_nexthop(mpls_nexthop *mnh, ldp_nexthop *lnh) +{ + memcpy(&lnh->info, mnh, sizeof(mpls_nexthop)); +} + ldp_nexthop *ldp_nexthop_for_fec_session(ldp_fec *fec, ldp_session *s) { ldp_nexthop *nh = MPLS_LIST_HEAD(&fec->nh_root); @@ -43,7 +49,7 @@ ldp_nexthop *ldp_nexthop_for_fec_session(ldp_fec *fec, ldp_session *s) return NULL; } -ldp_nexthop *ldp_nexthop_create() +ldp_nexthop *ldp_nexthop_create(ldp_global *g, mpls_nexthop *n) { ldp_nexthop *nh = (ldp_nexthop *) mpls_malloc(sizeof(ldp_nexthop)); @@ -56,12 +62,17 @@ ldp_nexthop *ldp_nexthop_create() MPLS_LIST_ELEM_INIT(nh, _if); MPLS_LIST_ELEM_INIT(nh, _outlabel); nh->index = _ldp_nexthop_get_next_index(); + mpls_nexthop2ldp_nexthop(n, nh); + _ldp_global_add_nexthop(g, nh); } return nh; } -void ldp_nexthop_delete(ldp_nexthop *nh) +void ldp_nexthop_delete(ldp_global *g, ldp_nexthop *nh) { + fprintf(stderr, "nexthop delete: %p\n", nh); + MPLS_REFCNT_ASSERT(nh, 0); + _ldp_global_del_nexthop(g, nh); mpls_free(nh); } @@ -116,11 +127,11 @@ void ldp_nexthop_add_outlabel2(ldp_nexthop * n, ldp_outlabel * o) memcpy(&o->info.nexthop, &n->info, sizeof(mpls_nexthop)); } -void ldp_nexthop_del_outlabel2(ldp_nexthop * n, ldp_outlabel * o) +void ldp_nexthop_del_outlabel2(ldp_global *g, ldp_nexthop * n, ldp_outlabel * o) { MPLS_ASSERT(n && o); MPLS_LIST_REMOVE(&n->outlabel_root, o, _nexthop); - ldp_outlabel_del_nexthop2(o); + ldp_outlabel_del_nexthop2(g, o); MPLS_REFCNT_RELEASE(o, ldp_outlabel_delete); } @@ -138,11 +149,6 @@ void ldp_nexthop_del_fec(ldp_global *g, ldp_nexthop * nh) nh->fec = NULL; } -void mpls_nexthop2ldp_nexthop(mpls_nexthop *mnh, ldp_nexthop *lnh) -{ - memcpy(&lnh->info, mnh, sizeof(mpls_nexthop)); -} - static uint32_t _ldp_nexthop_get_next_index() { uint32_t retval = _ldp_nexthop_next_index; diff --git a/ldp/ldp_nexthop.h b/ldp/ldp_nexthop.h index facdc14..6113dcf 100644 --- a/ldp/ldp_nexthop.h +++ b/ldp/ldp_nexthop.h @@ -10,9 +10,9 @@ #ifndef _LDP_NEXTHOP_H_ #define _LDP_NEXTHOP_H_ -extern ldp_nexthop *ldp_nexthop_create(); +extern ldp_nexthop *ldp_nexthop_create(ldp_global *g, mpls_nexthop *n); extern ldp_nexthop *ldp_nexthop_for_fec_session(ldp_fec *fec, ldp_session *s); -extern void ldp_nexthop_delete(ldp_nexthop *nh); +extern void ldp_nexthop_delete(ldp_global *g, ldp_nexthop *nh); extern void ldp_nexthop_add_if(ldp_nexthop * nh, ldp_if * i); extern void ldp_nexthop_del_if(ldp_global *g, ldp_nexthop * nh); extern void ldp_nexthop_add_addr(ldp_nexthop * nh, ldp_addr * a); @@ -20,7 +20,7 @@ extern void ldp_nexthop_del_addr(ldp_global *g, ldp_nexthop * nh); extern void ldp_nexthop_add_outlabel(ldp_nexthop * nh, ldp_outlabel * o); extern void ldp_nexthop_del_outlabel(ldp_nexthop * nh); extern void ldp_nexthop_add_outlabel2(ldp_nexthop * nh, ldp_outlabel * o); -extern void ldp_nexthop_del_outlabel2(ldp_nexthop * nh, ldp_outlabel * o); +extern void ldp_nexthop_del_outlabel2(ldp_global *g, ldp_nexthop * nh, ldp_outlabel * o); extern void ldp_nexthop_add_fec(ldp_nexthop * nh, ldp_fec * f); extern void ldp_nexthop_del_fec(ldp_global * g, ldp_nexthop * nh); extern void mpls_nexthop2ldp_nexthop(mpls_nexthop *mnh, ldp_nexthop *lnh); diff --git a/ldp/ldp_outlabel.c b/ldp/ldp_outlabel.c index c09e332..c1d1a5f 100644 --- a/ldp/ldp_outlabel.c +++ b/ldp/ldp_outlabel.c @@ -77,7 +77,7 @@ void ldp_outlabel_delete_complete(ldp_global * g, ldp_outlabel * out) ldp_session_del_outlabel(out->session, out); } _ldp_global_del_outlabel(g, out); - ldp_outlabel_del_nexthop2(out); + ldp_outlabel_del_nexthop2(g, out); } void _ldp_outlabel_add_inlabel(ldp_outlabel * o, ldp_inlabel * i) @@ -130,12 +130,12 @@ void ldp_outlabel_add_nexthop(ldp_outlabel * o, ldp_nexthop * nh) MPLS_LIST_ADD_TAIL(&o->nh_root, nh, _outlabel, ldp_nexthop); } -void ldp_outlabel_del_nexthop(ldp_outlabel * o, ldp_nexthop * nh) +void ldp_outlabel_del_nexthop(ldp_global *g, ldp_outlabel * o, ldp_nexthop * nh) { MPLS_ASSERT(o && nh); MPLS_LIST_REMOVE(&o->nh_root, nh, _outlabel); ldp_nexthop_del_outlabel(nh); - MPLS_REFCNT_RELEASE(nh, ldp_nexthop_delete); + MPLS_REFCNT_RELEASE2(g, nh, ldp_nexthop_delete); } void ldp_outlabel_add_nexthop2(ldp_outlabel * o, ldp_nexthop * nh) @@ -146,11 +146,11 @@ void ldp_outlabel_add_nexthop2(ldp_outlabel * o, ldp_nexthop * nh) ldp_nexthop_add_outlabel2(nh, o); } -void ldp_outlabel_del_nexthop2(ldp_outlabel * o) +void ldp_outlabel_del_nexthop2(ldp_global *g, ldp_outlabel * o) { MPLS_ASSERT(o); - ldp_nexthop_del_outlabel2(o->nh, o); - MPLS_REFCNT_RELEASE(o->nh, ldp_nexthop_delete); + ldp_nexthop_del_outlabel2(g, o->nh, o); + MPLS_REFCNT_RELEASE2(g, o->nh, ldp_nexthop_delete); o->nh = NULL; } diff --git a/ldp/ldp_outlabel.h b/ldp/ldp_outlabel.h index 9043d00..061a3ea 100644 --- a/ldp/ldp_outlabel.h +++ b/ldp/ldp_outlabel.h @@ -29,10 +29,10 @@ extern void _ldp_outlabel_add_attr(ldp_outlabel * o, ldp_attr * a); extern void _ldp_outlabel_del_attr(ldp_outlabel * o); extern void ldp_outlabel_add_nexthop(ldp_outlabel * o, ldp_nexthop * nh); -extern void ldp_outlabel_del_nexthop(ldp_outlabel * o, ldp_nexthop * nh); +extern void ldp_outlabel_del_nexthop(ldp_global *g, ldp_outlabel * o, ldp_nexthop * nh); extern void ldp_outlabel_add_nexthop2(ldp_outlabel * o, ldp_nexthop * nh); -extern void ldp_outlabel_del_nexthop2(ldp_outlabel * o); +extern void ldp_outlabel_del_nexthop2(ldp_global *g, ldp_outlabel * o); extern void _ldp_outlabel_add_tunnel(ldp_outlabel * o, ldp_tunnel * t); extern void _ldp_outlabel_del_tunnel(ldp_outlabel * o, ldp_tunnel * t); -- 2.11.4.GIT