From e83ed53f212a2558ac364b07a65e161830ccf0e5 Mon Sep 17 00:00:00 2001 From: "James R. Leu" Date: Mon, 18 Aug 2003 23:08:05 -0600 Subject: [PATCH] Remove address callback. Locally attached address are now added deleted via ldp_cfg_if_addr_*. [git-p4: depot-paths = "//depot/ldp-portable/": change = 394] --- common/mpls_ifmgr_impl.h | 4 +-- ldp/ldp_addr.c | 43 ++++++++++++++++++++++++-- ldp/ldp_addr.h | 5 +++ ldp/ldp_cfg.c | 80 ++++++++++++++++++++++++++++++++++++++++++++++++ ldp/ldp_cfg.h | 5 +++ ldp/ldp_global.c | 2 +- ldp/ldp_if.c | 47 ++++++++++++++++++++++++++++ ldp/ldp_if.h | 3 ++ ldp/ldp_struct.h | 9 +++++- lsr/lsr_global.c | 2 +- rsvpte/rsvpte_global.c | 2 +- 11 files changed, 193 insertions(+), 9 deletions(-) diff --git a/common/mpls_ifmgr_impl.h b/common/mpls_ifmgr_impl.h index 2e3c3fd..ae993a7 100644 --- a/common/mpls_ifmgr_impl.h +++ b/common/mpls_ifmgr_impl.h @@ -16,11 +16,11 @@ #include "mpls_handle_type.h" /* - * in: handle,cfg,callback + * in: handle,cfg * return: mpls_ifmgr_handle */ extern mpls_ifmgr_handle mpls_ifmgr_open(const mpls_instance_handle handle, - const mpls_cfg_handle cfg, ldp_ifmgr_callback callback); + const mpls_cfg_handle cfg); /* * in: handle diff --git a/ldp/ldp_addr.c b/ldp/ldp_addr.c index 221b82f..79bae8d 100644 --- a/ldp/ldp_addr.c +++ b/ldp/ldp_addr.c @@ -17,6 +17,7 @@ #include "ldp_pdu_setup.h" #include "ldp_addr.h" #include "ldp_nexthop.h" +#include "ldp_if.h" #include "ldp_buf.h" #include "ldp_mesg.h" #include "mpls_list.h" @@ -41,6 +42,8 @@ ldp_addr *ldp_addr_create(ldp_global *g, mpls_inet_addr * address) 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); + MPLS_LIST_ELEM_INIT(a, _if); memcpy(&a->address, address, sizeof(mpls_inet_addr)); a->index = _ldp_addr_get_next_index(); _ldp_global_add_addr(g, a); @@ -75,15 +78,26 @@ 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; } - MPLS_REFCNT_HOLD(addr); - if (mpls_tree_insert(g->addr_tree, address->u.ipv4, 32, (void *)addr) != - MPLS_SUCCESS) { + + 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"); + MPLS_REFCNT_RELEASE2(g, addr, ldp_addr_delete); + return MPLS_FATAL; + } + return MPLS_SUCCESS; +} + void ldp_addr_remove(ldp_global *g, mpls_inet_addr * address) { ldp_addr *addr = NULL; @@ -94,6 +108,29 @@ void ldp_addr_remove(ldp_global *g, mpls_inet_addr * address) } } +void ldp_addr_add_if(ldp_addr * a, ldp_if * i) +{ + MPLS_ASSERT(a && i); + MPLS_REFCNT_HOLD(i); + a->iff = i; +} + +void ldp_addr_del_if(ldp_global *g, ldp_addr * a) +{ + MPLS_ASSERT(a); + MPLS_REFCNT_RELEASE2(g, a->iff, ldp_if_delete); + a->iff = NULL; +} + +mpls_bool ldp_addr_is_empty(ldp_addr *a) +{ + if (a->iff == NULL && MPLS_LIST_EMPTY(&a->nh_root) && + MPLS_LIST_EMPTY(&a->session_root)) { + return MPLS_BOOL_TRUE; + } + return MPLS_BOOL_FALSE; +} + mpls_return_enum _ldp_addr_add_session(ldp_addr * a, ldp_session * s) { MPLS_ASSERT(a && s); diff --git a/ldp/ldp_addr.h b/ldp/ldp_addr.h index 5d47e87..f02f6a3 100644 --- a/ldp/ldp_addr.h +++ b/ldp/ldp_addr.h @@ -13,9 +13,14 @@ #include "ldp_struct.h" extern ldp_addr *ldp_addr_find(ldp_global *g, mpls_inet_addr * address); +extern mpls_return_enum ldp_addr_insert2(ldp_global *g, ldp_addr *addr); extern ldp_addr *ldp_addr_insert(ldp_global *g, mpls_inet_addr * address); +extern void ldp_addr_remove(ldp_global *g, mpls_inet_addr * address); extern ldp_addr *ldp_addr_create(ldp_global *g, mpls_inet_addr * inet); extern void ldp_addr_delete(ldp_global *g, ldp_addr * a); +extern void ldp_addr_add_if(ldp_addr * a, ldp_if * i); +extern void ldp_addr_del_if(ldp_global *g, ldp_addr * a); +extern mpls_bool ldp_addr_is_empty(ldp_addr *a); extern mpls_return_enum _ldp_addr_add_session(ldp_addr * a, ldp_session * s); extern void _ldp_addr_del_session(ldp_addr * a, ldp_session * s); extern void ldp_addr_add_nexthop(ldp_addr * a, ldp_nexthop * nh); diff --git a/ldp/ldp_cfg.c b/ldp/ldp_cfg.c index efb0c03..1c36969 100644 --- a/ldp/ldp_cfg.c +++ b/ldp/ldp_cfg.c @@ -15,6 +15,7 @@ #include "ldp_if.h" #include "ldp_peer.h" #include "ldp_fec.h" +#include "ldp_addr.h" #include "ldp_nexthop.h" #include "ldp_tunnel.h" #include "ldp_resource.h" @@ -1449,6 +1450,85 @@ ldp_cfg_fec_nexthop_set_end: return retval; } +/******************* ADDR **********************/ + +mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i, + mpls_inet_addr * a, uint32_t flag) +{ + ldp_global *global = (ldp_global *) handle; + ldp_addr *addr = NULL; + ldp_if *iff = NULL; + mpls_return_enum retval = MPLS_FAILURE; + + MPLS_ASSERT(global !=NULL && i != NULL && a != NULL); + + LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get"); + + mpls_lock_get(global->global_lock); /* LOCK */ + + if ((iff = ldp_global_find_if_handle(global, i->handle)) == NULL) + goto ldp_cfg_if_addr_get_end; + + if (!(addr = ldp_if_addr_find(iff, a))) + goto ldp_cfg_if_addr_get_end; + + retval = MPLS_SUCCESS; + +ldp_cfg_if_addr_get_end: + mpls_lock_release(global->global_lock); /* UNLOCK */ + + LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get"); + + return retval; +} + +mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i, + mpls_inet_addr * a, uint32_t flag) +{ + ldp_global *global = (ldp_global *) handle; + ldp_addr *addr = NULL; + ldp_if *iff = NULL; + mpls_return_enum retval = MPLS_FAILURE; + + MPLS_ASSERT(global !=NULL && i != NULL && a != NULL); + + LDP_ENTER(global->user_data, "ldp_if_cfg_addr_set"); + + mpls_lock_get(global->global_lock); /* LOCK */ + + if ((iff = ldp_global_find_if_handle(global, i->handle)) == NULL) + goto ldp_cfg_if_addr_set_end; + + addr = ldp_if_addr_find(iff, a); + if (flag & LDP_CFG_ADD) { + if ((addr) || ((addr = ldp_addr_create(global, a)) == NULL)) { + goto ldp_cfg_if_addr_set_end; + } + ldp_addr_insert2(global, addr); + ldp_if_add_addr(iff, addr); + } + + if (addr == NULL) { + LDP_PRINT(global->user_data, "ldp_if_cfg_addr_set: no such addr\n"); + goto ldp_cfg_if_addr_set_end; + } + + if (flag & LDP_CFG_DEL) { + ldp_if_del_addr(global, iff, addr); + if (ldp_addr_is_empty(addr)) { + ldp_addr_remove(global, &addr->address); + } + } + + retval = MPLS_SUCCESS; + +ldp_cfg_if_addr_set_end: + mpls_lock_release(global->global_lock); /* UNLOCK */ + + LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set"); + + return retval; +} /******************* ADJACENCY **********************/ mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a, diff --git a/ldp/ldp_cfg.h b/ldp/ldp_cfg.h index b16ffd7..7aa5d39 100644 --- a/ldp/ldp_cfg.h +++ b/ldp/ldp_cfg.h @@ -257,6 +257,11 @@ extern mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i, extern mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t flag); +extern mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i, + mpls_inet_addr * a, uint32_t flag); +extern mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if *i, + mpls_inet_addr * a, uint32_t flag); + extern mpls_return_enum ldp_cfg_labelrange_get(mpls_cfg_handle handle, mpls_range * r, uint32_t flag); extern mpls_return_enum ldp_cfg_labelrange_test(mpls_cfg_handle handle, diff --git a/ldp/ldp_global.c b/ldp/ldp_global.c index 269e633..7907168 100644 --- a/ldp/ldp_global.c +++ b/ldp/ldp_global.c @@ -165,7 +165,7 @@ mpls_return_enum ldp_global_startup(ldp_global * g) goto ldp_global_startup_cleanup; } - g->ifmgr_handle = mpls_ifmgr_open(g->user_data, g, _ldp_global_ifmgr_callback); + g->ifmgr_handle = mpls_ifmgr_open(g->user_data, g); if (mpls_ifmgr_handle_verify(g->ifmgr_handle) == MPLS_BOOL_FALSE) { goto ldp_global_startup_cleanup; } diff --git a/ldp/ldp_if.c b/ldp/ldp_if.c index 755ab00..859d3ce 100644 --- a/ldp/ldp_if.c +++ b/ldp/ldp_if.c @@ -15,6 +15,7 @@ #include "ldp_entity.h" #include "ldp_nexthop.h" #include "ldp_nortel.h" +#include "ldp_addr.h" #include "ldp_if.h" #include "ldp_fec.h" #include "ldp_mesg.h" @@ -23,6 +24,7 @@ #include "mpls_assert.h" #include "mpls_mm_impl.h" +#include "mpls_compare.h" #include "mpls_socket_impl.h" #include "mpls_timer_impl.h" #include "mpls_ifmgr_impl.h" @@ -45,6 +47,7 @@ ldp_if *ldp_if_create(ldp_global *g) 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); i->label_space = -1; i->dest.addr.type = MPLS_FAMILY_IPV4; i->dest.addr.u.ipv4 = INADDR_ALLRTRS_GROUP; @@ -126,6 +129,50 @@ void ldp_if_del_nexthop(ldp_global *g, ldp_if * i, ldp_nexthop * n) MPLS_REFCNT_RELEASE(n, ldp_nexthop_delete); } +void ldp_if_add_addr(ldp_if * i, ldp_addr * a) +{ + ldp_addr *ap = NULL; + + MPLS_ASSERT(i && a); + MPLS_REFCNT_HOLD(a); + + ldp_addr_add_if(a,i); + + ap = MPLS_LIST_HEAD(&i->addr_root); + while (ap != NULL) { + if (ap->index > a->index) { + MPLS_LIST_INSERT_BEFORE(&i->addr_root, ap, a, _if); + return; + } + ap = MPLS_LIST_NEXT(&i->addr_root, ap, _if); + } + MPLS_LIST_ADD_TAIL(&i->addr_root, a, _if, ldp_addr); +} + +void ldp_if_del_addr(ldp_global *g, ldp_if * i, ldp_addr * a) +{ + MPLS_ASSERT(i && a); + MPLS_LIST_REMOVE(&i->addr_root, a, _if); + ldp_addr_del_if(g, a); + MPLS_REFCNT_RELEASE2(g, a, ldp_addr_delete); +} + +ldp_addr *ldp_if_addr_find(ldp_if *i, mpls_inet_addr *a) +{ + ldp_addr *ap = NULL; + + MPLS_ASSERT(i && a); + + ap = MPLS_LIST_HEAD(&i->addr_root); + do { + if (!mpls_inet_addr_compare(&ap->address, a)) { + return ap; + } + ap = MPLS_LIST_NEXT(&i->addr_root, ap, _if); + } while((ap = MPLS_LIST_NEXT(&i->addr_root, ap, _if))); + return NULL; +} + mpls_return_enum ldp_if_startup(ldp_global * g, ldp_if * i) { ldp_entity *e = NULL; diff --git a/ldp/ldp_if.h b/ldp/ldp_if.h index 069ff5b..13e4ea8 100644 --- a/ldp/ldp_if.h +++ b/ldp/ldp_if.h @@ -18,6 +18,9 @@ extern ldp_if *ldp_if_insert(ldp_global *g, mpls_if_handle handle); extern void ldp_if_remove(ldp_global *g, ldp_if *iff); extern void ldp_if_add_nexthop(ldp_if * i, ldp_nexthop * n); extern void ldp_if_del_nexthop(ldp_global *g, ldp_if * i, ldp_nexthop * n); +extern ldp_addr *ldp_if_addr_find(ldp_if *i, mpls_inet_addr *a); +extern void ldp_if_del_addr(ldp_global *g, ldp_if * i, ldp_addr * a); +extern void ldp_if_add_addr(ldp_if * i, ldp_addr * a); extern mpls_return_enum ldp_if_startup(ldp_global * g, ldp_if * i); extern mpls_return_enum ldp_if_shutdown(ldp_global * g, ldp_if * i); extern mpls_bool ldp_if_is_active(ldp_if * i); diff --git a/ldp/ldp_struct.h b/ldp/ldp_struct.h index 21d6697..7e1b071 100644 --- a/ldp/ldp_struct.h +++ b/ldp/ldp_struct.h @@ -340,6 +340,7 @@ typedef struct ldp_if { MPLS_LIST_ELEM(ldp_if) _global; struct mpls_link_list session_root; struct ldp_nexthop_list nh_root; + struct ldp_addr_list addr_root; struct ldp_entity *entity; mpls_timer_handle hellotime_send_timer; int hellotime_send_timer_duration; @@ -489,10 +490,16 @@ typedef struct ldp_adj { typedef struct ldp_addr { MPLS_REFCNT_FIELD; MPLS_LIST_ELEM(ldp_addr) _global; - MPLS_LIST_ELEM(ldp_addr) _addr; +// MPLS_LIST_ELEM(ldp_addr) _addr; + MPLS_LIST_ELEM(ldp_addr) _if; struct mpls_link_list session_root; struct ldp_nexthop_list nh_root; struct mpls_inet_addr address; + + /* + * if an address has a iff pointer it is locally attached + */ + struct ldp_if *iff; uint32_t index; } ldp_addr; diff --git a/lsr/lsr_global.c b/lsr/lsr_global.c index 4e3cd5e..83b4e95 100644 --- a/lsr/lsr_global.c +++ b/lsr/lsr_global.c @@ -56,7 +56,7 @@ mpls_return_enum lsr_global_startup(lsr_global * g) LDP_ENTER(g->user_data, "lsr_global_startup"); - g->ifmgr_handle = mpls_ifmgr_open(g->user_data, g, NULL); + g->ifmgr_handle = mpls_ifmgr_open(g->user_data, g); if (mpls_ifmgr_handle_verify(g->ifmgr_handle) == MPLS_BOOL_FALSE) { goto lsr_global_startup_cleanup; } diff --git a/rsvpte/rsvpte_global.c b/rsvpte/rsvpte_global.c index 44b65a6..11b54a4 100644 --- a/rsvpte/rsvpte_global.c +++ b/rsvpte/rsvpte_global.c @@ -102,7 +102,7 @@ mpls_return_enum rsvpte_global_startup(rsvpte_global * g) goto rsvpte_global_startup_cleanup; } - g->ifmgr_handle = mpls_ifmgr_open(g->user_data, g, _rsvpte_global_ifmgr_callback); + g->ifmgr_handle = mpls_ifmgr_open(g->user_data, g); if (mpls_ifmgr_handle_verify(g->ifmgr_handle) == MPLS_BOOL_FALSE) { goto rsvpte_global_startup_cleanup; } -- 2.11.4.GIT