The ldp entity should not startup or shutdown if the global
[mpls-ldp-portable.git] / rsvpte / rsvpte_cfg.c
blob72c750cd17875166dec51c8a8e3cff812f9bada5
1 /*
2 * Copyright (C) James R. Leu 2003
3 * jleu@mindspring.com
5 * This software is covered under the LGPL, for more
6 * info check out http://www.gnu.org/copyleft/lgpl.html
7 */
9 #include "rsvpte_struct.h"
10 #include "rsvpte_cfg.h"
11 #include "rsvpte_global.h"
12 #include "rsvpte_if.h"
13 #include "mpls_ifmgr_impl.h"
14 #include "mpls_lock_impl.h"
15 #include "mpls_trace_impl.h"
16 #include "mpls_tree_impl.h"
18 mpls_cfg_handle rsvpte_cfg_open(mpls_instance_handle data)
20 rsvpte_global *g = rsvpte_global_create(data);
22 LDP_ENTER(data, "rsvpte_cfg_open");
23 LDP_EXIT(data, "rsvpte_cfg_open");
25 return (mpls_cfg_handle) g;
28 void rsvpte_cfg_close(mpls_cfg_handle g)
30 LDP_ENTER((mpls_instance_handle) g->user_data, "rsvpte_cfg_close");
31 rsvpte_global_delete(g);
32 LDP_EXIT((mpls_instance_handle) g->user_data, "rsvpte_cfg_close");
35 /******************* GLOBAL **********************/
37 mpls_return_enum rsvpte_cfg_global_get(mpls_cfg_handle handle, rsvpte_global * g,
38 uint32_t flag)
40 rsvpte_global *global = (rsvpte_global *) handle;
42 MPLS_ASSERT(global !=NULL);
44 LDP_ENTER(global->user_data, "rsvpte_cfg_global_get");
46 mpls_lock_get(global->global_lock); /* LOCK */
48 if (flag & RSVPTE_GLOBAL_CFG_LSR_IDENTIFIER) {
49 memcpy(&(g->lsr_identifier), &(global->lsr_identifier),
50 sizeof(mpls_inet_addr));
52 if (flag & RSVPTE_GLOBAL_CFG_ADMIN_STATE) {
53 g->admin_state = global->admin_state;
55 #if MPLS_USE_LSR
56 if (flag & RSVPTE_GLOBAL_CFG_LSR_HANDLE) {
57 g->lsr_handle = global->lsr_handle;
59 #endif
61 mpls_lock_release(global->global_lock); /* UNLOCK */
63 LDP_EXIT(global->user_data, "rsvpte_cfg_global_get");
65 return MPLS_SUCCESS;
68 mpls_return_enum rsvpte_cfg_global_test(mpls_cfg_handle handle, rsvpte_global * g,
69 uint32_t flag)
71 rsvpte_global *global = (rsvpte_global *) handle;
72 mpls_return_enum retval = MPLS_SUCCESS;
74 MPLS_ASSERT(global !=NULL);
76 LDP_ENTER(global->user_data, "rsvpte_cfg_global_test");
78 mpls_lock_get(global->global_lock); /* LOCK */
80 if (global->admin_state == MPLS_ADMIN_ENABLE && (flag & RSVPTE_GLOBAL_CFG_WHEN_DOWN))
81 retval = MPLS_FAILURE;
83 mpls_lock_release(global->global_lock); /* UNLOCK */
85 LDP_EXIT(global->user_data, "rsvpte_cfg_global_test");
87 return retval;
90 mpls_return_enum rsvpte_cfg_global_set(mpls_cfg_handle handle, rsvpte_global * g,
91 uint32_t flag)
93 rsvpte_global *global = (rsvpte_global *) handle;
94 mpls_return_enum retval = MPLS_FAILURE;
96 MPLS_ASSERT(global !=NULL);
98 LDP_ENTER(global->user_data, "rsvpte_cfg_global_set");
100 mpls_lock_get(global->global_lock); /* LOCK */
102 if ((global->admin_state == MPLS_ADMIN_ENABLE && (flag & RSVPTE_GLOBAL_CFG_WHEN_DOWN)))
103 goto rsvpte_cfg_global_set_end;
105 if (flag & RSVPTE_GLOBAL_CFG_LSR_IDENTIFIER) {
106 memcpy(&(global->lsr_identifier), &(g->lsr_identifier),
107 sizeof(mpls_inet_addr));
109 #if MPLS_USE_LSR
110 if (flag & RSVPTE_GLOBAL_CFG_LSR_HANDLE) {
111 global->lsr_handle = g->lsr_handle ;
113 #endif
114 if (flag & RSVPTE_GLOBAL_CFG_ADMIN_STATE) {
115 if (global->admin_state == MPLS_ADMIN_ENABLE && g->admin_state == MPLS_ADMIN_DISABLE) {
116 rsvpte_global_shutdown(global);
117 } else if (global->admin_state == MPLS_ADMIN_DISABLE && g->admin_state ==
118 MPLS_ADMIN_ENABLE) {
119 rsvpte_global_startup(global);
123 retval = MPLS_SUCCESS;
125 rsvpte_cfg_global_set_end:
127 mpls_lock_release(global->global_lock); /* UNLOCK */
129 LDP_EXIT(global->user_data, "rsvpte_cfg_global_set");
131 return retval;
134 /******************* INTERFACE **********************/
136 mpls_return_enum rsvpte_cfg_if_get(mpls_cfg_handle handle, rsvpte_if * i, uint32_t flag)
138 rsvpte_global *global = (rsvpte_global *) handle;
139 rsvpte_if *iff = NULL;
140 mpls_return_enum retval = MPLS_FAILURE;
142 MPLS_ASSERT(global !=NULL && i != NULL);
144 LDP_ENTER(global->user_data, "rsvpte_cfg_if_get");
146 mpls_lock_get(global->global_lock); /* LOCK */
148 if (rsvpte_global_find_if_index(global, i->index, &iff) != MPLS_SUCCESS)
149 goto rsvpte_cfg_if_get_end;
151 if (flag & RSVPTE_IF_CFG_LABEL_SPACE) {
152 i->label_space = iff->label_space;
154 if (flag & RSVPTE_IF_CFG_ADMIN_STATE) {
155 i->admin_state = iff->admin_state;
157 if (flag & RSVPTE_IF_CFG_OPER_STATE) {
158 i->oper_state = iff->oper_state;
160 retval = MPLS_SUCCESS;
162 rsvpte_cfg_if_get_end:
163 mpls_lock_release(global->global_lock); /* UNLOCK */
165 LDP_EXIT(global->user_data, "rsvpte_cfg_if_get");
167 return retval;
170 mpls_return_enum rsvpte_cfg_if_getnext(mpls_cfg_handle handle, rsvpte_if * i,
171 uint32_t flag)
173 rsvpte_global *g = (rsvpte_global *) handle;
174 rsvpte_if *iff = NULL;
175 mpls_return_enum r = MPLS_FAILURE;
176 mpls_bool done = MPLS_BOOL_FALSE;
177 int index;
179 LDP_ENTER(g->user_data, "rsvpte_cfg_if_getnext");
181 if (i->index == 0) {
182 index = 1;
183 } else {
184 index = i->index + 1;
187 mpls_lock_get(g->global_lock); /* LOCK */
188 while (done == MPLS_BOOL_FALSE) {
189 switch ((r = rsvpte_global_find_if_index(g, index, &iff))) {
190 case MPLS_SUCCESS:
191 case MPLS_END_OF_LIST:
192 done = MPLS_BOOL_TRUE;
193 break;
194 case MPLS_FAILURE:
195 break;
196 default:
197 MPLS_ASSERT(0);
199 index++;
201 mpls_lock_release(g->global_lock); /* UNLOCK */
203 if (r == MPLS_SUCCESS) {
204 i->index = iff->index;
205 LDP_EXIT(g->user_data, "rsvpte_cfg_if_getnext");
206 return rsvpte_cfg_if_get(g, i, flag);
208 LDP_EXIT(g->user_data, "rsvpte_cfg_if_getnext");
209 return r;
212 mpls_return_enum rsvpte_cfg_if_test(mpls_cfg_handle handle, rsvpte_if * i,
213 uint32_t flag)
215 rsvpte_global *global = (rsvpte_global *) handle;
216 rsvpte_if *iff = NULL;
217 mpls_return_enum retval = MPLS_FAILURE;
219 MPLS_ASSERT(global !=NULL && i != NULL);
221 LDP_ENTER(global->user_data, "rsvpte_cfg_if_test");
223 mpls_lock_get(global->global_lock); /* LOCK */
225 if (!(flag & RSVPTE_CFG_ADD)) {
226 rsvpte_global_find_if_index(global, i->index, &iff);
227 } else {
228 retval = MPLS_SUCCESS;
229 goto rsvpte_cfg_if_test_end;
232 if ((iff == NULL) ||
233 ((rsvpte_if_is_active(iff) == MPLS_BOOL_TRUE) &&
234 (flag & RSVPTE_IF_CFG_WHEN_DOWN))) goto rsvpte_cfg_if_test_end;
236 if (flag & RSVPTE_CFG_DEL) {
238 if (iff->entity != NULL)
239 goto rsvpte_cfg_if_test_end;
242 retval = MPLS_SUCCESS;
244 rsvpte_cfg_if_test_end:
245 mpls_lock_release(global->global_lock); /* UNLOCK */
247 LDP_EXIT(global->user_data, "rsvpte_cfg_if_test");
249 return retval;
252 mpls_return_enum rsvpte_cfg_if_set(mpls_cfg_handle handle, rsvpte_if * i, uint32_t flag)
254 rsvpte_global *global = (rsvpte_global*)handle;
255 rsvpte_if *iff = NULL;
256 mpls_return_enum retval = MPLS_FAILURE;
258 MPLS_ASSERT(global !=NULL && i != NULL);
260 LDP_ENTER(global->user_data, "rsvpte_cfg_if_set");
262 mpls_lock_get(global->global_lock); /* LOCK */
264 if (flag & RSVPTE_CFG_ADD) {
265 if ((iff = rsvpte_if_create()) == NULL) {
266 goto rsvpte_cfg_if_set_end;
268 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) == MPLS_BOOL_FALSE) {
269 goto rsvpte_cfg_if_set_end;
271 iff->handle = i->handle;
272 i->index = iff->index;
273 _rsvpte_global_add_if(global, iff);
274 } else {
275 rsvpte_global_find_if_index(global, i->index, &iff);
278 if ((iff == NULL) ||
279 ((rsvpte_if_is_active(iff) == MPLS_BOOL_TRUE) &&
280 (flag & RSVPTE_IF_CFG_WHEN_DOWN))) goto rsvpte_cfg_if_set_end;
282 if (flag & RSVPTE_CFG_DEL) {
283 _rsvpte_global_del_if(global, iff);
285 retval = MPLS_SUCCESS;
286 goto rsvpte_cfg_if_set_end;
288 if (flag & RSVPTE_IF_CFG_LABEL_SPACE) {
289 iff->label_space = i->label_space;
291 if (flag & RSVPTE_IF_CFG_ADMIN_STATE) {
292 if (iff->admin_state == MPLS_ADMIN_ENABLE && i->admin_state ==
293 MPLS_ADMIN_DISABLE) {
294 rsvpte_if_shutdown(global, iff);
295 } else if (iff->admin_state == MPLS_ADMIN_DISABLE && i->admin_state ==
296 MPLS_ADMIN_ENABLE) {
297 rsvpte_if_startup(global, iff);
301 retval = MPLS_SUCCESS;
303 rsvpte_cfg_if_set_end:
304 mpls_lock_release(global->global_lock); /* UNLOCK */
306 LDP_EXIT(global->user_data, "rsvpte_cfg_if_set");
308 return retval;