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_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");
177 mpls_return_enum
rsvpte_cfg_if_getnext(mpls_cfg_handle handle
, rsvpte_if
* i
,
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
;
186 LDP_ENTER(g
->user_data
, "rsvpte_cfg_if_getnext");
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
))) {
198 case MPLS_END_OF_LIST
:
199 done
= MPLS_BOOL_TRUE
;
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");
219 mpls_return_enum
rsvpte_cfg_if_test(mpls_cfg_handle handle
, rsvpte_if
* i
,
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
);
235 retval
= MPLS_SUCCESS
;
236 goto rsvpte_cfg_if_test_end
;
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");
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
);
283 rsvpte_global_find_if_index(global
, i
->index
, &iff
);
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
==
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");