Were referencing a file that should have been dead for a long
[mpls-ldp-portable.git] / ldp / ldp_tunnel.c
blob54b139ad8583a81d3622afcb3bbf12da3497737d
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_tunnel.h"
12 #include "ldp_hop_list.h"
13 #include "ldp_resource.h"
14 #include "ldp_outlabel.h"
16 #include "mpls_assert.h"
17 #include "mpls_mm_impl.h"
18 #include "mpls_trace_impl.h"
20 static uint32_t _ldp_tunnel_next_index = 1;
22 ldp_tunnel *ldp_tunnel_create()
24 ldp_tunnel *t = (ldp_tunnel *) mpls_malloc(sizeof(ldp_tunnel));
26 if (t) {
27 memset(t, 0, sizeof(ldp_tunnel));
28 MPLS_REFCNT_INIT(t, 0);
29 MPLS_LIST_ELEM_INIT(t, _global);
30 MPLS_LIST_ELEM_INIT(t, _outlabel);
32 t->index = _ldp_tunnel_get_next_index();
34 return t;
37 void ldp_tunnel_delete(ldp_tunnel * t)
39 // LDP_PRINT(g->user_data,"tunnel delete\n");
40 MPLS_REFCNT_ASSERT(t, 0);
41 mpls_free(t);
44 uint32_t _ldp_tunnel_get_next_index()
46 uint32_t retval = _ldp_tunnel_next_index;
48 _ldp_tunnel_next_index++;
49 if (retval > _ldp_tunnel_next_index) {
50 _ldp_tunnel_next_index = 1;
52 return retval;
55 mpls_bool ldp_tunnel_is_active(ldp_tunnel * t)
57 if (t->admin_state == MPLS_ADMIN_ENABLE) {
58 return MPLS_BOOL_TRUE;
60 return MPLS_BOOL_FALSE;
63 mpls_bool ldp_tunnel_is_ready(ldp_tunnel * t)
65 return MPLS_BOOL_TRUE;
68 mpls_return_enum ldp_tunnel_add_resource(ldp_tunnel * t, ldp_resource * r)
70 if (t && r) {
71 MPLS_REFCNT_HOLD(r);
72 MPLS_ASSERT(t->resource == NULL);
73 t->resource = r;
74 _ldp_resource_add_tunnel(r, t);
75 return MPLS_SUCCESS;
77 return MPLS_FAILURE;
80 mpls_return_enum ldp_tunnel_del_resource(ldp_tunnel * t)
82 if (t && t->resource) {
83 _ldp_resource_del_tunnel(t->resource);
84 MPLS_REFCNT_RELEASE(t->resource, ldp_resource_delete);
85 t->resource = NULL;
86 return MPLS_SUCCESS;
88 return MPLS_FAILURE;
91 mpls_return_enum ldp_tunnel_add_hop_list(ldp_tunnel * t, ldp_hop_list * h)
93 if (t && h) {
94 MPLS_REFCNT_HOLD(h);
95 MPLS_ASSERT(t->hop_list == NULL);
96 t->hop_list = h;
97 _ldp_hop_list_add_tunnel(h, t);
98 return MPLS_SUCCESS;
100 return MPLS_FAILURE;
103 mpls_return_enum ldp_tunnel_del_hop_list(ldp_tunnel * t)
105 if (t && t->hop_list) {
106 _ldp_hop_list_del_tunnel(t->hop_list);
107 MPLS_REFCNT_RELEASE(t->hop_list, ldp_hop_list_delete);
108 t->hop_list = NULL;
109 return MPLS_SUCCESS;
111 return MPLS_FAILURE;
114 mpls_return_enum ldp_tunnel_add_outlabel(ldp_tunnel * t, ldp_outlabel * o)
116 if (t && o) {
117 MPLS_REFCNT_HOLD(o);
118 MPLS_ASSERT(t->outlabel == NULL);
119 t->outlabel = o;
120 _ldp_outlabel_add_tunnel(o, t);
121 return MPLS_SUCCESS;
123 return MPLS_FAILURE;
126 mpls_return_enum ldp_tunnel_del_outlabel(ldp_tunnel * t)
128 if (t && t->outlabel) {
129 _ldp_outlabel_del_tunnel(t->outlabel, t);
130 MPLS_REFCNT_RELEASE(t->outlabel, ldp_outlabel_delete);
131 t->outlabel = NULL;
132 return MPLS_SUCCESS;
134 return MPLS_FAILURE;
137 mpls_return_enum ldp_tunnel_startup(ldp_global * global, ldp_tunnel * tunnel)
139 return MPLS_FAILURE;
142 mpls_return_enum ldp_tunnel_shutdown(ldp_global * global, ldp_tunnel * tunnel,
143 int flag)
145 return MPLS_SUCCESS;