3 * Copyright (C) James R. Leu 2001
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
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
));
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();
34 void ldp_resource_delete(ldp_resource
* r
)
36 // LDP_PRINT(g->user_data,"resource delete\n");
37 MPLS_REFCNT_ASSERT(r
, 0);
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;
52 mpls_return_enum
_ldp_resource_add_tunnel(ldp_resource
* r
, ldp_tunnel
* t
)
62 mpls_return_enum
_ldp_resource_del_tunnel(ldp_resource
* r
)
65 MPLS_REFCNT_RELEASE(r
->tunnel
, ldp_tunnel_delete
);
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
;