Added comments to clarify the relationships
[mpls-ldp-portable.git] / ldp / ldp_hop.c
blobcd1655dea27d711293f20fdb351777e0a34b9f35
2 /*
3 * Copyright (C) James R. Leu 2001
4 * jleu@mindspring.com
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
8 */
10 #include "ldp_struct.h"
11 #include "ldp_hop_list.h"
12 #include "ldp_hop.h"
14 #include "mpls_assert.h"
15 #include "mpls_mm_impl.h"
16 #include "mpls_trace_impl.h"
18 ldp_hop *ldp_hop_create()
20 ldp_hop *h = (ldp_hop *) mpls_malloc(sizeof(ldp_hop));
22 if (h) {
23 memset(h, 0, sizeof(ldp_hop));
24 MPLS_REFCNT_INIT(h, 0);
25 MPLS_LIST_ELEM_INIT(h, _hop_list);
27 return h;
30 void ldp_hop_delete(ldp_hop * h)
32 // LDP_PRINT(g->user_data,"hop delete\n");
33 MPLS_REFCNT_ASSERT(h, 0);
34 mpls_free(h);
37 mpls_return_enum _ldp_hop_add_hop_list(ldp_hop * h, ldp_hop_list * hl)
39 if (h && hl) {
40 MPLS_REFCNT_HOLD(hl);
41 h->hop_list = hl;
42 return MPLS_SUCCESS;
44 return MPLS_FAILURE;
47 mpls_return_enum _ldp_hop_del_hop_list(ldp_hop * h)
49 if (h && h->hop_list) {
50 MPLS_REFCNT_RELEASE(h->hop_list, ldp_hop_list_delete);
51 h->hop_list = NULL;
52 return MPLS_SUCCESS;
54 return MPLS_FAILURE;
57 mpls_bool ldp_hop_in_use(ldp_hop * h)
59 if (h->hop_list && h->hop_list->tunnel &&
60 (h->hop_list->tunnel->admin_state == MPLS_ADMIN_ENABLE)) {
61 return MPLS_BOOL_TRUE;
63 return MPLS_BOOL_FALSE;