Forgot to add these files
[mpls-ldp-portable.git] / rsvpte / rsvpte_cfg.c
blob43ba1387366813ece78126571cd4000077579eaa
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_NAME) {
152 strncpy(i->name, iff->name, MPLS_MAX_IF_NAME);
154 if (flag & RSVPTE_IF_CFG_LABEL_SPACE) {
155 i->label_space = iff->label_space;
157 if (flag & RSVPTE_IF_CFG_ADMIN_STATE) {
158 i->admin_state = iff->admin_state;
160 if (flag & RSVPTE_IF_CFG_OPER_STATE) {
161 i->oper_state = iff->oper_state;
163 if (flag & RSVPTE_IF_CFG_LOCAL_SOURCE_ADDR) {
164 memcpy(&i->local_source_address, &iff->local_source_address,
165 sizeof(mpls_inet_addr));
167 retval = MPLS_SUCCESS;
169 rsvpte_cfg_if_get_end:
170 mpls_lock_release(global->global_lock); /* UNLOCK */
172 LDP_EXIT(global->user_data, "rsvpte_cfg_if_get");
174 return retval;
177 mpls_return_enum rsvpte_cfg_if_getnext(mpls_cfg_handle handle, rsvpte_if * i,
178 uint32_t flag)
180 rsvpte_global *g = (rsvpte_global *) handle;
181 rsvpte_if *iff = NULL;
182 mpls_return_enum r = MPLS_FAILURE;
183 mpls_bool done = MPLS_BOOL_FALSE;
184 int index;
186 LDP_ENTER(g->user_data, "rsvpte_cfg_if_getnext");
188 if (i->index == 0) {
189 index = 1;
190 } else {
191 index = i->index + 1;
194 mpls_lock_get(g->global_lock); /* LOCK */
195 while (done == MPLS_BOOL_FALSE) {
196 switch ((r = rsvpte_global_find_if_index(g, index, &iff))) {
197 case MPLS_SUCCESS:
198 case MPLS_END_OF_LIST:
199 done = MPLS_BOOL_TRUE;
200 break;
201 case MPLS_FAILURE:
202 break;
203 default:
204 MPLS_ASSERT(0);
206 index++;
208 mpls_lock_release(g->global_lock); /* UNLOCK */
210 if (r == MPLS_SUCCESS) {
211 i->index = iff->index;
212 LDP_EXIT(g->user_data, "rsvpte_cfg_if_getnext");
213 return rsvpte_cfg_if_get(g, i, flag);
215 LDP_EXIT(g->user_data, "rsvpte_cfg_if_getnext");
216 return r;
219 mpls_return_enum rsvpte_cfg_if_test(mpls_cfg_handle handle, rsvpte_if * i,
220 uint32_t flag)
222 rsvpte_global *global = (rsvpte_global *) handle;
223 rsvpte_if *iff = NULL;
224 mpls_return_enum retval = MPLS_FAILURE;
226 MPLS_ASSERT(global !=NULL && i != NULL);
228 LDP_ENTER(global->user_data, "rsvpte_cfg_if_test");
230 mpls_lock_get(global->global_lock); /* LOCK */
232 if (!(flag & RSVPTE_CFG_ADD)) {
233 rsvpte_global_find_if_index(global, i->index, &iff);
234 } else {
235 retval = MPLS_SUCCESS;
236 goto rsvpte_cfg_if_test_end;
239 if ((iff == NULL) ||
240 ((rsvpte_if_is_active(iff) == MPLS_BOOL_TRUE) &&
241 (flag & RSVPTE_IF_CFG_WHEN_DOWN))) goto rsvpte_cfg_if_test_end;
243 if (flag & RSVPTE_CFG_DEL) {
245 if (iff->entity != NULL)
246 goto rsvpte_cfg_if_test_end;
249 retval = MPLS_SUCCESS;
251 rsvpte_cfg_if_test_end:
252 mpls_lock_release(global->global_lock); /* UNLOCK */
254 LDP_EXIT(global->user_data, "rsvpte_cfg_if_test");
256 return retval;
259 mpls_return_enum rsvpte_cfg_if_set(mpls_cfg_handle handle, rsvpte_if * i, uint32_t flag)
261 rsvpte_global *global = (rsvpte_global*)handle;
262 rsvpte_if *iff = NULL;
263 mpls_return_enum retval = MPLS_FAILURE;
265 MPLS_ASSERT(global !=NULL && i != NULL);
267 LDP_ENTER(global->user_data, "rsvpte_cfg_if_set");
269 mpls_lock_get(global->global_lock); /* LOCK */
271 if (flag & RSVPTE_CFG_ADD) {
272 if ((iff = rsvpte_if_create()) == NULL) {
273 goto rsvpte_cfg_if_set_end;
275 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) == MPLS_BOOL_FALSE) {
276 i->handle = mpls_ifmgr_open_if(global->ifmgr_handle, i->name);
278 iff->handle = i->handle;
279 i->index = iff->index;
280 strncpy(iff->name, i->name, MPLS_MAX_IF_NAME);
281 _rsvpte_global_add_if(global, iff);
282 } else {
283 rsvpte_global_find_if_index(global, i->index, &iff);
286 if ((iff == NULL) ||
287 ((rsvpte_if_is_active(iff) == MPLS_BOOL_TRUE) &&
288 (flag & RSVPTE_IF_CFG_WHEN_DOWN))) goto rsvpte_cfg_if_set_end;
290 if (flag & RSVPTE_CFG_DEL) {
291 _rsvpte_global_del_if(global, iff);
293 retval = MPLS_SUCCESS;
294 goto rsvpte_cfg_if_set_end;
296 if (flag & RSVPTE_IF_CFG_LABEL_SPACE) {
297 iff->label_space = i->label_space;
299 if (flag & RSVPTE_IF_CFG_ADMIN_STATE) {
300 if (iff->admin_state == MPLS_ADMIN_ENABLE && i->admin_state ==
301 MPLS_ADMIN_DISABLE) {
302 rsvpte_if_shutdown(global, iff);
303 } else if (iff->admin_state == MPLS_ADMIN_DISABLE && i->admin_state ==
304 MPLS_ADMIN_ENABLE) {
305 rsvpte_if_startup(global, iff);
309 retval = MPLS_SUCCESS;
311 rsvpte_cfg_if_set_end:
312 mpls_lock_release(global->global_lock); /* UNLOCK */
314 LDP_EXIT(global->user_data, "rsvpte_cfg_if_set");
316 return retval;