From 2ce44505196b47b02ac2eeed55d017412cb2f2ef Mon Sep 17 00:00:00 2001 From: "James R. Leu" Date: Fri, 5 Sep 2003 00:33:07 -0600 Subject: [PATCH] No longer need mpls_ifmgr_get_address mpls_ifmgr_open_if and mpls_ifmgr_close_if. we now need mpls_ifmgr_get_name ldp_if nolonger needs localaddress and name If an ldp_addr or ldp_nexthop are added which have a if_handle for an interface which doesn't exist yet, leave the iff pointer NULL. When the interface is added it will search for 'dangling' ldp_addr and ldp_nexthop and attach them. These are also correctly detached when the interface is deleted. [git-p4: depot-paths = "//depot/ldp-portable/": change = 405] --- common/mpls_ifmgr_impl.h | 29 ++++--------- ldp/ldp_addr.c | 2 +- ldp/ldp_cfg.c | 108 ++++++++++++++++++++++++++++++----------------- ldp/ldp_cfg.h | 11 +++-- ldp/ldp_fec.c | 8 ++-- ldp/ldp_global.c | 11 ++--- ldp/ldp_hello.c | 8 +++- ldp/ldp_if.c | 8 ---- ldp/ldp_label_mapping.c | 2 +- ldp/ldp_label_request.c | 2 +- ldp/ldp_struct.h | 17 ++++---- 11 files changed, 108 insertions(+), 98 deletions(-) diff --git a/common/mpls_ifmgr_impl.h b/common/mpls_ifmgr_impl.h index ae993a7..72bf7be 100644 --- a/common/mpls_ifmgr_impl.h +++ b/common/mpls_ifmgr_impl.h @@ -28,27 +28,6 @@ extern mpls_ifmgr_handle mpls_ifmgr_open(const mpls_instance_handle handle, extern void mpls_ifmgr_close(const mpls_ifmgr_handle handle); /* - * in: handle,name - * return: mpls_if_handle - */ -extern mpls_if_handle mpls_ifmgr_open_if(const mpls_ifmgr_handle, - const char *name); - -/* - * in: handle,iff - */ -extern void mpls_ifmgr_close_if(const mpls_ifmgr_handle, const mpls_if_handle iff); - -/* - * in: handle,iff,addr,mask,flags - * out: addr,mask,flags - * return: mpls_return_enum - */ -extern mpls_return_enum mpls_ifmgr_get_address(const mpls_ifmgr_handle, - const mpls_if_handle iff, mpls_inet_addr * addr, mpls_inet_addr * mask, - uint32_t * flags); - -/* * in: handle,iff,mtu * out: mtu * return: mpls_return_enum @@ -57,6 +36,14 @@ extern mpls_return_enum mpls_ifmgr_get_mtu(const mpls_ifmgr_handle, const mpls_if_handle iff, int *mtu); /* + * in: handle,iff,name,size + * out: name + * return: mpls_return_enum + */ +extern mpls_return_enum mpls_ifmgr_get_name(const mpls_ifmgr_handle, + const mpls_if_handle iff, char *name, int len); + +/* * in: handle, handle, addr * return: mpls_return_enum */ diff --git a/ldp/ldp_addr.c b/ldp/ldp_addr.c index 79bae8d..63dc3f3 100644 --- a/ldp/ldp_addr.c +++ b/ldp/ldp_addr.c @@ -292,7 +292,7 @@ mpls_return_enum ldp_addr_process(ldp_global * g, ldp_session * s, inet.u.ipv4 = body->addressList.address[i]; if (msg->u.generic.flags.flags.msgType == MPLS_ADDR_MSGTYPE) { - if (!(addr == ldp_addr_find(g, &inet))) { + if (!(addr = ldp_addr_find(g, &inet))) { /* it's not in the tree, put it there! */ if ((addr = ldp_addr_insert(g, &inet)) == NULL) { LDP_PRINT(g->user_data, "ldp_addr_process: error adding addr\n"); diff --git a/ldp/ldp_cfg.c b/ldp/ldp_cfg.c index 3c13ae7..615dd79 100644 --- a/ldp/ldp_cfg.c +++ b/ldp/ldp_cfg.c @@ -723,9 +723,6 @@ mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t fla if (!iff) goto ldp_cfg_if_get_end; - if (flag & LDP_IF_CFG_NAME) { - strncpy(i->name, iff->name, MPLS_MAX_IF_NAME); - } if (flag & LDP_IF_CFG_LABEL_SPACE) { i->label_space = iff->label_space; } @@ -735,10 +732,6 @@ mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t fla if (flag & LDP_IF_CFG_OPER_STATE) { i->oper_state = iff->oper_state; } - if (flag & LDP_IF_CFG_LOCAL_SOURCE_ADDR) { - memcpy(&i->local_source_address, &iff->local_source_address, - sizeof(mpls_inet_addr)); - } retval = MPLS_SUCCESS; ldp_cfg_if_get_end: @@ -811,13 +804,15 @@ mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i, goto ldp_cfg_if_test_end; } - if ((iff == NULL) || - ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) && -(flag & LDP_IF_CFG_WHEN_DOWN))) goto ldp_cfg_if_test_end; + if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) && + (flag & LDP_IF_CFG_WHEN_DOWN))) { + goto ldp_cfg_if_test_end; + } if (flag & LDP_CFG_DEL) { - if (iff->entity != NULL) + if (iff->entity != NULL) { goto ldp_cfg_if_test_end; + } } retval = MPLS_SUCCESS; @@ -833,6 +828,8 @@ mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t fla { ldp_global *global = (ldp_global*)handle; ldp_if *iff = NULL; + ldp_addr *ap; + ldp_nexthop *np; mpls_return_enum retval = MPLS_FAILURE; MPLS_ASSERT(global !=NULL && i != NULL); @@ -842,44 +839,83 @@ mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t fla mpls_lock_get(global->global_lock); /* LOCK */ if (flag & LDP_CFG_ADD) { - if ((iff = ldp_global_find_if_handle(global, i->handle)) == NULL) { - if ((iff = ldp_if_create(global)) == NULL) { - goto ldp_cfg_if_set_end; + /* duplicate interface handles are not allowed */ + /* ADDs require a valid interface handle */ + if (((iff = ldp_global_find_if_handle(global, i->handle)) != NULL) || + (mpls_if_handle_verify(global->ifmgr_handle, i->handle) == + MPLS_BOOL_FALSE) || ((iff = ldp_if_create(global)) == NULL)) { + goto ldp_cfg_if_set_end; + } + + /* copy the handle from the user */ + iff->handle = i->handle; + + /* search for addrs and nexthops that are waiting for this interface */ + ap = MPLS_LIST_HEAD(&global->addr); + while (ap) { + if (ap->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(ap, _if))) { + ldp_if_add_addr(iff, ap); } - if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) == - MPLS_BOOL_FALSE) { - i->handle = mpls_ifmgr_open_if(global->ifmgr_handle, i->name); + ap = MPLS_LIST_NEXT(&global->addr, ap, _global); + } + + np = MPLS_LIST_HEAD(&global->nexthop); + while (np) { + if (np->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(np, _if))) { + ldp_if_add_nexthop(iff, np); } - iff->handle = i->handle; + np = MPLS_LIST_NEXT(&global->nexthop, np, _global); } + + /* send the newly created index back to the user */ i->index = iff->index; - strncpy(iff->name, i->name, MPLS_MAX_IF_NAME); - iff->used_by_ldp = MPLS_BOOL_TRUE; + } else { - ldp_global_find_if_index(global, i->index, &iff); + if (flag & LDP_IF_CFG_BY_INDEX) { + ldp_global_find_if_index(global, i->index, &iff); + } else { + iff = ldp_global_find_if_handle(global, i->handle); + } } - if ((iff == NULL) || - ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) && -(flag & LDP_IF_CFG_WHEN_DOWN))) goto ldp_cfg_if_set_end; + /* + * if we can't find this interface or if the interface is active and + * we are trying to change propertises that can not be changed on a + * active interface + */ + if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) && + (flag & LDP_IF_CFG_WHEN_DOWN))) { + goto ldp_cfg_if_set_end; + } + + if (flag & LDP_IF_CFG_LABEL_SPACE) { + iff->label_space = i->label_space; + } if (flag & LDP_CFG_DEL) { + /* + * if this interface is still attached to a entity that it is not ready + * to be removed + */ if (iff->entity != NULL) { goto ldp_cfg_if_set_end; } - iff->used_by_ldp = MPLS_BOOL_FALSE; - MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete); + np = MPLS_LIST_HEAD(&iff->nh_root); + while (np) { + ldp_if_del_nexthop(global, iff, np); + np = MPLS_LIST_NEXT(&iff->nh_root, np, _if); + } - retval = MPLS_SUCCESS; - goto ldp_cfg_if_set_end; - } - if (flag & LDP_IF_CFG_INDEX) { - iff->index = i->index; - } - if (flag & LDP_IF_CFG_LABEL_SPACE) { - iff->label_space = i->label_space; + ap = MPLS_LIST_HEAD(&iff->addr_root); + while (ap) { + ldp_if_del_addr(global, iff, ap); + ap = MPLS_LIST_NEXT(&iff->addr_root, ap, _if); + } + + MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete); } + global->configuration_sequence_number++; retval = MPLS_SUCCESS; @@ -1025,10 +1061,6 @@ mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p, if (flag & LDP_PEER_CFG_PEER_NAME) { strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME); } - if (flag & LDP_PEER_CFG_LOCAL_SOURCE_ADDR) { - memcpy(&p->local_source_address, &peer->local_source_address, - sizeof(mpls_inet_addr)); - } retval = MPLS_SUCCESS; ldp_cfg_peer_get_end: diff --git a/ldp/ldp_cfg.h b/ldp/ldp_cfg.h index 7014eeb..a9ddac6 100644 --- a/ldp/ldp_cfg.h +++ b/ldp/ldp_cfg.h @@ -76,19 +76,18 @@ #define LDP_FEC_CFG_BY_INDEX 0x00000002 #define LDP_FEC_NEXTHOP_CFG_BY_INDEX 0x00000004 -#define LDP_IF_CFG_BY_INDEX 0x00000002 -#define LDP_IF_ADDR_CFG_BY_INDEX 0x00000004 - #define LDP_IF_CFG_LABEL_SPACE 0x00000002 #define LDP_IF_CFG_INDEX 0x00000004 #define LDP_IF_CFG_ENTITY_INDEX 0x00000008 #define LDP_IF_CFG_OPER_STATE 0x00000010 -#define LDP_IF_CFG_LOCAL_SOURCE_ADDR 0x00000020 -#define LDP_IF_CFG_NAME 0x00000040 +#define LDP_IF_CFG_BY_INDEX 0x00000080 +#define LDP_IF_ADDR_CFG_BY_INDEX 0x00000100 #define LDP_IF_CFG_WHEN_DOWN (LDP_CFG_DEL|\ LDP_IF_CFG_LABEL_SPACE|\ - LDP_IF_CFG_INDEX) + LDP_IF_CFG_INDEX|\ + LDP_IF_CFG_ENTITY_INDEX|\ + LDP_IF_CFG_OPER_STATE) #define LDP_PEER_CFG_LABEL_SPACE 0x00000002 #define LDP_PEER_CFG_DEST_ADDR 0x00000004 diff --git a/ldp/ldp_fec.c b/ldp/ldp_fec.c index 746d08f..1738545 100644 --- a/ldp/ldp_fec.c +++ b/ldp/ldp_fec.c @@ -235,12 +235,10 @@ mpls_return_enum ldp_fec_add_nexthop(ldp_global *g, ldp_fec * f, if (nh->type & MPLS_NH_IF) { ldp_if *iff = NULL; if (!(iff = ldp_global_find_if_handle(g, nh->info.if_handle))) { - if (!(iff = ldp_if_insert(g, nh->info.if_handle))) { - goto ldp_fec_add_nexthop_error; - } + nh->if_handle = nh->info.if_handle; + } else { + ldp_if_add_nexthop(iff, nh); } - - ldp_if_add_nexthop(iff, nh); } if (nh->type & MPLS_NH_OUTSEGMENT) { diff --git a/ldp/ldp_global.c b/ldp/ldp_global.c index eeb6b5d..3a98f0a 100644 --- a/ldp/ldp_global.c +++ b/ldp/ldp_global.c @@ -268,16 +268,13 @@ mpls_return_enum ldp_global_startup(ldp_global * g) do { ldp_addr *a; ldp_if *i; - if (!(i = ldp_global_find_if_handle(g, iff))) { - i = ldp_if_insert(g, iff); - } - if (!i) { - goto ldp_global_startup_cleanup; - } if (!(a = ldp_addr_create(g, &addr))) { goto ldp_global_startup_cleanup; } - ldp_if_add_addr(i, a); + a->if_handle = iff; + if ((i = ldp_global_find_if_handle(g, iff))) { + ldp_if_add_addr(i, a); + } } while (mpls_ifmgr_getnext_address(g->ifmgr_handle, &iff, &addr) == MPLS_SUCCESS); } diff --git a/ldp/ldp_hello.c b/ldp/ldp_hello.c index cd9fdaf..f031d39 100644 --- a/ldp/ldp_hello.c +++ b/ldp/ldp_hello.c @@ -188,7 +188,11 @@ mpls_return_enum ldp_hello_process(ldp_global * g, ldp_adj * a, ldp_entity *e, hellotime = 15; } - local = &e->p.iff->local_source_address; + if (MPLS_LIST_HEAD(&e->p.iff->addr_root)) { + local = &(MPLS_LIST_HEAD(&e->p.iff->addr_root)->address); + } else { + local = &g->lsr_identifier; + } break; case LDP_INDIRECT: @@ -197,7 +201,7 @@ mpls_return_enum ldp_hello_process(ldp_global * g, ldp_adj * a, ldp_entity *e, hellotime = 45; } - local = &e->p.peer->local_source_address; + local = &g->lsr_identifier; break; default: MPLS_ASSERT(0); diff --git a/ldp/ldp_if.c b/ldp/ldp_if.c index 130dcb9..20878d5 100644 --- a/ldp/ldp_if.c +++ b/ldp/ldp_if.c @@ -55,8 +55,6 @@ ldp_if *ldp_if_create(ldp_global *g) i->tx_message = ldp_mesg_create(); i->index = _ldp_if_get_next_index(); i->oper_state = MPLS_OPER_DOWN; - i->used_by_ldp = MPLS_BOOL_FALSE; - i->used_by_fec = MPLS_BOOL_FALSE; i->is_p2p = MPLS_BOOL_FALSE; _ldp_global_add_if(g, i); } @@ -89,7 +87,6 @@ ldp_if *ldp_if_insert(ldp_global *g, mpls_if_handle handle) LDP_PRINT(g->user_data,"ldp_if_insert: unable to alloc ldp_if\n"); return NULL; } - iff->used_by_fec = MPLS_BOOL_TRUE; iff->handle = handle; return iff; } @@ -97,7 +94,6 @@ ldp_if *ldp_if_insert(ldp_global *g, mpls_if_handle handle) void ldp_if_remove(ldp_global *g, ldp_if *iff) { MPLS_ASSERT(g && iff); - iff->used_by_fec = MPLS_BOOL_FALSE; MPLS_REFCNT_RELEASE2(g, iff, ldp_if_delete); } @@ -214,10 +210,6 @@ mpls_return_enum ldp_if_startup(ldp_global * g, ldp_if * i) MPLS_ASSERT(e != NULL); MPLS_ASSERT(e->p.iff != NULL); - if (mpls_ifmgr_get_address(g->ifmgr_handle, i->handle, - &i->local_source_address, NULL, NULL) == MPLS_FAILURE) { - goto ldp_if_startup_delay; - } if (mpls_socket_multicast_if_join(g->socket_handle, g->hello_socket, i, &i->dest.addr) == MPLS_FAILURE) { goto ldp_if_startup_delay; diff --git a/ldp/ldp_label_mapping.c b/ldp/ldp_label_mapping.c index 97e742b..53cf187 100644 --- a/ldp/ldp_label_mapping.c +++ b/ldp/ldp_label_mapping.c @@ -425,7 +425,7 @@ void ldp_label_mapping_initial_callback(mpls_timer_handle timer, void *extra, } if (nh->type & MPLS_NH_IF) { LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "via %s\n", nh->iff->name); + LDP_TRACE_FLAG_ROUTE, "via %p\n", nh->iff->handle); } /* are we allowed to export this route from the rib */ diff --git a/ldp/ldp_label_request.c b/ldp/ldp_label_request.c index ba4e585..f120852 100644 --- a/ldp/ldp_label_request.c +++ b/ldp/ldp_label_request.c @@ -231,7 +231,7 @@ void ldp_label_request_initial_callback(mpls_timer_handle timer, void *extra, } if (nh->type & MPLS_NH_IF) { LDP_TRACE_LOG(g->user_data, MPLS_TRACE_STATE_ALL, - LDP_TRACE_FLAG_ROUTE, "via %s\n", nh->iff->name); + LDP_TRACE_FLAG_ROUTE, "via %p\n", nh->iff->handle); } /* check to see if export policy allows us to 'see' this route */ diff --git a/ldp/ldp_struct.h b/ldp/ldp_struct.h index 7e1b071..9b5dc40 100644 --- a/ldp/ldp_struct.h +++ b/ldp/ldp_struct.h @@ -346,7 +346,6 @@ typedef struct ldp_if { int hellotime_send_timer_duration; int label_space; uint32_t index; - struct mpls_inet_addr local_source_address; mpls_if_handle handle; struct ldp_mesg *tx_message; @@ -356,10 +355,7 @@ typedef struct ldp_if { /* YES this is a dest, it is what we use for sendto */ struct mpls_dest dest; - char name[MPLS_MAX_IF_NAME]; mpls_oper_state_enum oper_state; - mpls_bool used_by_ldp; - mpls_bool used_by_fec; mpls_bool is_p2p; /* only used for cfg gets */ @@ -375,7 +371,6 @@ typedef struct ldp_peer { int hellotime_send_timer_duration; int label_space; uint32_t index; - struct mpls_inet_addr local_source_address; struct ldp_mesg *tx_message; struct ldp_buf *tx_buffer; @@ -490,16 +485,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) _if; struct mpls_link_list session_root; struct ldp_nexthop_list nh_root; struct mpls_inet_addr address; + struct ldp_if *iff; /* - * if an address has a iff pointer it is locally attached + * if an address has a if_handle it is locally attached */ - struct ldp_if *iff; + mpls_if_handle if_handle; uint32_t index; } ldp_addr; @@ -519,6 +514,12 @@ typedef struct ldp_nexthop { struct ldp_if *iff; struct ldp_outlabel *outlabel; struct mpls_nexthop info; + + /* + * if the nexthop exists before the interface has been added + * the handle will be valid + */ + mpls_if_handle if_handle; uint32_t index; } ldp_nexthop; -- 2.11.4.GIT