2 * Copyright (C) James R. Leu 2003
5 * This software is covered under the LGPL, for more
6 * info check out http://www.gnu.org/copyleft/lgpl.html
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
,
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
;
56 if (flag
& RSVPTE_GLOBAL_CFG_LSR_HANDLE
) {
57 g
->lsr_handle
= global
->lsr_handle
;
61 mpls_lock_release(global
->global_lock
); /* UNLOCK */
63 LDP_EXIT(global
->user_data
, "rsvpte_cfg_global_get");
68 mpls_return_enum
rsvpte_cfg_global_test(mpls_cfg_handle handle
, rsvpte_global
* g
,
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");
90 mpls_return_enum
rsvpte_cfg_global_set(mpls_cfg_handle handle
, rsvpte_global
* g
,
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
));
110 if (flag
& RSVPTE_GLOBAL_CFG_LSR_HANDLE
) {
111 global
->lsr_handle
= g
->lsr_handle
;
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
==
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");
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");
170 mpls_return_enum
rsvpte_cfg_if_getnext(mpls_cfg_handle handle
, rsvpte_if
* i
,
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
;
179 LDP_ENTER(g
->user_data
, "rsvpte_cfg_if_getnext");
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
))) {
191 case MPLS_END_OF_LIST
:
192 done
= MPLS_BOOL_TRUE
;
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");
212 mpls_return_enum
rsvpte_cfg_if_test(mpls_cfg_handle handle
, rsvpte_if
* i
,
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
);
228 retval
= MPLS_SUCCESS
;
229 goto rsvpte_cfg_if_test_end
;
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");
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
);
275 rsvpte_global_find_if_index(global
, i
->index
, &iff
);
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
==
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");