Print standard delete message
[mpls-ldp-portable.git] / ldp / ldp_resource.c
blobbf8245c4449ce932d2c9fd5b18216934d2b744dc
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_resource.h"
12 #include "ldp_tunnel.h"
14 #include "mpls_assert.h"
15 #include "mpls_mm_impl.h"
16 #include "mpls_trace_impl.h"
18 static uint32_t _ldp_resource_next_index = 1;
20 ldp_resource *ldp_resource_create()
22 ldp_resource *r = (ldp_resource *) mpls_malloc(sizeof(ldp_resource));
24 if (r) {
25 memset(r, 0, sizeof(ldp_resource));
26 MPLS_REFCNT_INIT(r, 0);
27 MPLS_LIST_ELEM_INIT(r, _global);
29 r->index = _ldp_resource_get_next_index();
31 return r;
34 void ldp_resource_delete(ldp_resource * r)
36 // LDP_PRINT(g->user_data,"resource delete\n");
37 MPLS_REFCNT_ASSERT(r, 0);
38 mpls_free(r);
41 uint32_t _ldp_resource_get_next_index()
43 uint32_t retval = _ldp_resource_next_index;
45 _ldp_resource_next_index++;
46 if (retval > _ldp_resource_next_index) {
47 _ldp_resource_next_index = 1;
49 return retval;
52 mpls_return_enum _ldp_resource_add_tunnel(ldp_resource * r, ldp_tunnel * t)
54 if (r && t) {
55 MPLS_REFCNT_HOLD(t);
56 r->tunnel = t;
57 return MPLS_SUCCESS;
59 return MPLS_FAILURE;
62 mpls_return_enum _ldp_resource_del_tunnel(ldp_resource * r)
64 if (r && r->tunnel) {
65 MPLS_REFCNT_RELEASE(r->tunnel, ldp_tunnel_delete);
66 r->tunnel = NULL;
67 return MPLS_SUCCESS;
69 return MPLS_FAILURE;
72 mpls_bool ldp_resource_in_use(ldp_resource * r)
74 if (r->tunnel && (r->tunnel->admin_state == MPLS_ADMIN_ENABLE)) {
75 return MPLS_BOOL_TRUE;
77 return MPLS_BOOL_FALSE;