3 * Copyright (C) James R. Leu 2000
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
10 #include "ldp_struct.h"
12 #include "ldp_global.h"
13 #include "ldp_entity.h"
17 #include "ldp_tunnel.h"
18 #include "ldp_resource.h"
19 #include "mpls_ifmgr_impl.h"
21 #include "ldp_hop_list.h"
22 #include "mpls_lock_impl.h"
23 #include "mpls_trace_impl.h"
24 #include "mpls_tree_impl.h"
26 mpls_cfg_handle
ldp_cfg_open(mpls_instance_handle data
)
28 ldp_global
*g
= ldp_global_create(data
);
30 LDP_ENTER(data
, "ldp_cfg_open");
31 LDP_EXIT(data
, "ldp_cfg_open");
33 return (mpls_cfg_handle
) g
;
36 void ldp_cfg_close(mpls_cfg_handle g
)
38 LDP_ENTER((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
40 LDP_EXIT((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
43 /******************* GLOBAL **********************/
45 mpls_return_enum
ldp_cfg_global_get(mpls_cfg_handle handle
, ldp_global
* g
,
48 ldp_global
*global
= (ldp_global
*) handle
;
50 MPLS_ASSERT(global
!=NULL
);
52 LDP_ENTER(global
->user_data
, "ldp_cfg_global_get");
54 mpls_lock_get(global
->global_lock
); /* LOCK */
56 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
57 memcpy(&(g
->lsr_identifier
), &(global
->lsr_identifier
),
58 sizeof(mpls_inet_addr
));
60 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
61 g
->admin_state
= global
->admin_state
;
63 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
64 g
->lsp_control_mode
= global
->lsp_control_mode
;
66 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
67 g
->label_retention_mode
= global
->label_retention_mode
;
69 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
70 g
->lsp_repair_mode
= global
->lsp_repair_mode
;
72 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
73 g
->propagate_release
= global
->propagate_release
;
75 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
76 g
->label_merge
= global
->label_merge
;
78 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
79 g
->loop_detection_mode
= global
->loop_detection_mode
;
81 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
82 g
->ttl_less_domain
= global
->ttl_less_domain
;
84 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
85 g
->local_tcp_port
= global
->local_tcp_port
;
87 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
88 g
->local_udp_port
= global
->local_udp_port
;
90 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
91 memcpy(&(g
->transport_address
), &(global
->transport_address
),
92 sizeof(mpls_inet_addr
));
94 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
95 g
->keepalive_timer
= global
->keepalive_timer
;
97 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
98 g
->keepalive_interval
= global
->keepalive_interval
;
100 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
101 g
->hellotime_timer
= global
->hellotime_timer
;
103 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
104 g
->hellotime_interval
= global
->hellotime_interval
;
107 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
108 g
->lsr_handle
= global
->lsr_handle
;
112 mpls_lock_release(global
->global_lock
); /* UNLOCK */
114 LDP_EXIT(global
->user_data
, "ldp_cfg_global_get");
119 mpls_return_enum
ldp_cfg_global_test(mpls_cfg_handle handle
, ldp_global
* g
,
122 ldp_global
*global
= (ldp_global
*) handle
;
123 mpls_return_enum retval
= MPLS_SUCCESS
;
125 MPLS_ASSERT(global
!=NULL
);
127 LDP_ENTER(global
->user_data
, "ldp_cfg_global_test");
129 mpls_lock_get(global
->global_lock
); /* LOCK */
131 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
))
132 retval
= MPLS_FAILURE
;
134 mpls_lock_release(global
->global_lock
); /* UNLOCK */
136 LDP_EXIT(global
->user_data
, "ldp_cfg_global_test");
141 mpls_return_enum
ldp_cfg_global_set(mpls_cfg_handle handle
, ldp_global
* g
,
144 ldp_global
*global
= (ldp_global
*) handle
;
145 mpls_return_enum retval
= MPLS_FAILURE
;
147 MPLS_ASSERT(global
!=NULL
);
149 LDP_ENTER(global
->user_data
, "ldp_cfg_global_set");
151 mpls_lock_get(global
->global_lock
); /* LOCK */
153 if ((global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
)))
154 goto ldp_cfg_global_set_end
;
156 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
157 global
->lsp_control_mode
= g
->lsp_control_mode
;
159 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
160 global
->label_retention_mode
= g
->label_retention_mode
;
162 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
163 global
->lsp_repair_mode
= g
->lsp_repair_mode
;
165 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
166 global
->propagate_release
= g
->propagate_release
;
168 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
169 global
->label_merge
= g
->label_merge
;
171 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
172 global
->loop_detection_mode
= g
->loop_detection_mode
;
174 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
175 global
->ttl_less_domain
= g
->ttl_less_domain
;
177 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
178 global
->local_tcp_port
= g
->local_tcp_port
;
180 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
181 global
->local_udp_port
= g
->local_udp_port
;
183 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
184 memcpy(&(global
->lsr_identifier
), &(g
->lsr_identifier
),
185 sizeof(mpls_inet_addr
));
188 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
189 global
->lsr_handle
= g
->lsr_handle
;
192 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
193 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& g
->admin_state
== MPLS_ADMIN_DISABLE
) {
194 ldp_global_shutdown(global
);
195 } else if (global
->admin_state
== MPLS_ADMIN_DISABLE
&& g
->admin_state
==
197 ldp_global_startup(global
);
200 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
201 memcpy(&(global
->transport_address
), &(g
->transport_address
),
202 sizeof(mpls_inet_addr
));
204 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
205 if (g
->keepalive_timer
== 0) {
206 global
->keepalive_timer
= LDP_ENTITY_DEF_KEEPALIVE_TIMER
;
208 global
->keepalive_timer
= g
->keepalive_timer
;
211 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
212 if (g
->keepalive_interval
== 0) {
213 global
->keepalive_interval
= LDP_ENTITY_DEF_KEEPALIVE_INTERVAL
;
215 global
->keepalive_interval
= g
->keepalive_interval
;
218 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
219 if (g
->hellotime_timer
== 0) {
220 global
->hellotime_timer
= LDP_ENTITY_DEF_HELLOTIME_TIMER
;
222 global
->hellotime_timer
= g
->hellotime_timer
;
225 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
226 if (g
->hellotime_interval
== 0) {
227 global
->hellotime_interval
= LDP_ENTITY_DEF_HELLOTIME_INTERVAL
;
229 global
->hellotime_interval
= g
->hellotime_interval
;
233 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
234 global
->lsr_handle
= g
->lsr_handle
;
237 global
->configuration_sequence_number
++;
239 retval
= MPLS_SUCCESS
;
241 ldp_cfg_global_set_end
:
243 mpls_lock_release(global
->global_lock
); /* UNLOCK */
245 LDP_EXIT(global
->user_data
, "ldp_cfg_global_set");
250 /******************* ENTITY **********************/
252 /* must set ldp_entity->index */
253 mpls_return_enum
ldp_cfg_entity_get(mpls_cfg_handle handle
, ldp_entity
* e
,
256 ldp_global
*global
= (ldp_global
*) handle
;
257 ldp_entity
*entity
= NULL
;
258 mpls_return_enum retval
= MPLS_FAILURE
;
260 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
262 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_get");
264 mpls_lock_get(global
->global_lock
); /* LOCK */
266 if (ldp_global_find_entity_index(global
, e
->index
, &entity
) != MPLS_SUCCESS
)
267 goto ldp_cfg_entity_get_end
;
269 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
270 e
->admin_state
= entity
->admin_state
;
272 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
273 e
->transport_address
= entity
->transport_address
;
275 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
276 e
->protocol_version
= entity
->protocol_version
;
278 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
279 e
->remote_tcp_port
= entity
->remote_tcp_port
;
281 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
282 e
->remote_udp_port
= entity
->remote_udp_port
;
284 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
285 e
->max_pdu
= entity
->max_pdu
;
287 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
288 e
->keepalive_timer
= entity
->keepalive_timer
;
290 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
291 e
->keepalive_interval
= entity
->keepalive_interval
;
293 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
294 e
->hellotime_timer
= entity
->hellotime_timer
;
296 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
297 e
->hellotime_interval
= entity
->hellotime_interval
;
299 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
300 e
->session_setup_count
= entity
->session_setup_count
;
302 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
303 e
->session_backoff_timer
= entity
->session_backoff_timer
;
305 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
306 e
->label_distribution_mode
= entity
->label_distribution_mode
;
308 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
309 e
->path_vector_limit
= entity
->path_vector_limit
;
311 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
312 e
->hop_count_limit
= entity
->hop_count_limit
;
314 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
315 e
->label_request_count
= entity
->label_request_count
;
317 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
318 e
->label_request_timer
= entity
->label_request_timer
;
320 if (flag
& LDP_ENTITY_CFG_TYPE
) {
321 e
->entity_type
= entity
->entity_type
;
323 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
324 e
->sub_index
= entity
->sub_index
;
326 if (flag
& LDP_ENTITY_CFG_MESG_TX
) {
327 e
->mesg_tx
= entity
->mesg_tx
;
329 if (flag
& LDP_ENTITY_CFG_MESG_RX
) {
330 e
->mesg_rx
= entity
->mesg_rx
;
332 if (flag
& LDP_ENTITY_CFG_ADJ_COUNT
) {
333 e
->adj_count
= e
->adj_root
.count
;
335 if (flag
& LDP_ENTITY_CFG_ADJ_INDEX
) {
336 ldp_adj
*a
= MPLS_LIST_HEAD(&e
->adj_root
);
337 e
->adj_index
= a
? a
->index
: 0;
339 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
340 e
->inherit_flag
= entity
->inherit_flag
;
342 retval
= MPLS_SUCCESS
;
344 ldp_cfg_entity_get_end
:
346 mpls_lock_release(global
->global_lock
); /* UNLOCK */
348 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_get");
353 mpls_return_enum
ldp_cfg_entity_getnext(mpls_cfg_handle handle
, ldp_entity
* e
,
356 ldp_global
*g
= (ldp_global
*) handle
;
357 ldp_entity
*entity
= NULL
;
358 mpls_return_enum r
= MPLS_FAILURE
;
359 mpls_bool done
= MPLS_BOOL_FALSE
;
362 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_getnext");
367 index
= e
->index
+ 1;
370 mpls_lock_get(g
->global_lock
); /* LOCK */
371 while (done
== MPLS_BOOL_FALSE
) {
372 switch ((r
= ldp_global_find_entity_index(g
, index
, &entity
))) {
374 case MPLS_END_OF_LIST
:
375 done
= MPLS_BOOL_TRUE
;
384 mpls_lock_release(g
->global_lock
); /* UNLOCK */
386 if (r
== MPLS_SUCCESS
) {
387 e
->index
= entity
->index
;
388 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
389 return ldp_cfg_entity_get(g
, e
, flag
);
391 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
395 mpls_return_enum
ldp_cfg_entity_test(mpls_cfg_handle handle
, ldp_entity
* e
,
398 ldp_global
*global
= (ldp_global
*) handle
;
399 ldp_entity
*entity
= NULL
;
400 mpls_return_enum retval
= MPLS_FAILURE
;
402 MPLS_ASSERT(global
!=NULL
);
404 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_test");
406 mpls_lock_get(global
->global_lock
); /* LOCK */
408 if (!(flag
& LDP_CFG_ADD
)) {
410 goto ldp_cfg_entity_test_end
;
412 ldp_global_find_entity_index(global
, e
->index
, &entity
);
414 retval
= MPLS_SUCCESS
;
415 goto ldp_cfg_entity_test_end
;
418 if (entity
== NULL
) {
419 goto ldp_cfg_entity_test_end
;
422 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
423 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
424 goto ldp_cfg_entity_test_end
;
427 retval
= MPLS_SUCCESS
;
429 ldp_cfg_entity_test_end
:
430 mpls_lock_release(global
->global_lock
); /* UNLOCK */
432 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_test");
437 /* must set ldp_entity->index if not an add */
438 mpls_return_enum
ldp_cfg_entity_set(mpls_cfg_handle handle
, ldp_entity
* e
,
441 ldp_global
*global
= (ldp_global
*) handle
;
442 ldp_entity
*entity
= NULL
;
443 mpls_return_enum retval
= MPLS_FAILURE
;
445 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
447 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_set");
449 mpls_lock_get(global
->global_lock
); /* LOCK */
451 if (flag
& LDP_CFG_ADD
) {
452 entity
= ldp_entity_create();
453 _ldp_global_add_entity(global
, entity
);
455 e
->index
= entity
->index
;
457 ldp_global_find_entity_index(global
, e
->index
, &entity
);
460 if (entity
== NULL
) {
461 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: can't find entity\n");
462 goto ldp_cfg_entity_set_end
;
465 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
466 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
467 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity is active\n");
468 goto ldp_cfg_entity_set_end
;
471 if (flag
& LDP_CFG_DEL
) {
472 switch (entity
->entity_type
) {
474 ldp_entity_del_if(entity
);
477 ldp_entity_del_peer(entity
);
482 _ldp_global_del_entity(global
, entity
);
484 retval
= MPLS_SUCCESS
;
485 goto ldp_cfg_entity_set_end
;
488 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
489 if (entity
->sub_index
!= 0) {
490 /* unlink the old sub object */
491 switch (entity
->entity_type
) {
493 ldp_entity_del_if(entity
);
496 ldp_entity_del_peer(entity
);
503 /* link the new sub object */
504 switch (e
->entity_type
) {
508 if (ldp_global_find_if_index(global
, e
->sub_index
,
509 &iff
) != MPLS_SUCCESS
) {
510 LDP_PRINT(global
->user_data
,
511 "ldp_cfg_entity_set: no such interface\n");
513 if (flag
& LDP_CFG_ADD
) {
514 _ldp_global_del_entity(global
, entity
);
516 goto ldp_cfg_entity_set_end
;
518 ldp_entity_add_if(entity
, iff
);
523 ldp_peer
*peer
= NULL
;
525 if (ldp_global_find_peer_index(global
, e
->sub_index
, &peer
) !=
527 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: no such peer\n");
529 if (flag
& LDP_CFG_ADD
) {
530 _ldp_global_del_entity(global
, entity
);
532 goto ldp_cfg_entity_set_end
;
534 ldp_entity_add_peer(entity
, peer
);
542 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
543 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
544 entity
->inherit_flag
|= LDP_ENTITY_CFG_TRANS_ADDR
;
546 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_TRANS_ADDR
;
548 memcpy(&entity
->transport_address
, &e
->transport_address
,
549 sizeof(mpls_inet_addr
));;
551 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
552 entity
->protocol_version
= e
->protocol_version
;
554 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
555 entity
->remote_tcp_port
= e
->remote_tcp_port
;
557 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
558 entity
->remote_udp_port
= e
->remote_udp_port
;
560 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
561 entity
->max_pdu
= e
->max_pdu
;
563 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
564 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
565 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
567 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
569 entity
->keepalive_timer
= e
->keepalive_timer
;
571 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
572 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
573 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
575 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
577 entity
->keepalive_interval
= e
->keepalive_interval
;
579 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
580 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
581 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_TIMER
;
583 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_TIMER
;
585 entity
->hellotime_timer
= e
->hellotime_timer
;
587 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
588 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
589 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
591 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
593 entity
->hellotime_interval
= e
->hellotime_interval
;
595 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
596 entity
->session_setup_count
= e
->session_setup_count
;
598 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
599 entity
->session_backoff_timer
= e
->session_backoff_timer
;
601 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
602 entity
->label_distribution_mode
= e
->label_distribution_mode
;
604 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
605 entity
->path_vector_limit
= e
->path_vector_limit
;
607 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
608 entity
->hop_count_limit
= e
->hop_count_limit
;
610 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
611 entity
->label_request_count
= e
->label_request_count
;
613 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
614 entity
->label_request_timer
= e
->label_request_timer
;
616 if (flag
& LDP_ENTITY_CFG_TYPE
) {
617 entity
->entity_type
= e
->entity_type
;
619 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
620 if (ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
&&
621 e
->admin_state
== MPLS_ADMIN_DISABLE
) {
622 if (ldp_entity_shutdown(global
, entity
, 0) == MPLS_FAILURE
) {
623 goto ldp_cfg_entity_set_end
;
625 } else if (ldp_entity_is_active(entity
) == MPLS_BOOL_FALSE
&&
626 e
->admin_state
== MPLS_ADMIN_ENABLE
&& ldp_entity_is_ready(entity
) == MPLS_BOOL_TRUE
) {
627 if (ldp_entity_startup(global
, entity
) == MPLS_FAILURE
) {
628 goto ldp_cfg_entity_set_end
;
631 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity not ready\n");
633 goto ldp_cfg_entity_set_end
;
636 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
637 entity
->inherit_flag
= e
->inherit_flag
;
639 global
->configuration_sequence_number
++;
641 retval
= MPLS_SUCCESS
;
643 ldp_cfg_entity_set_end
:
644 mpls_lock_release(global
->global_lock
); /* UNLOCK */
646 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_set");
651 mpls_return_enum
ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle
,
654 ldp_global
*g
= (ldp_global
*) handle
;
655 mpls_bool this_one
= MPLS_BOOL_FALSE
;
656 mpls_return_enum r
= MPLS_FAILURE
;
657 ldp_adj
*adj_next
= NULL
;
659 ldp_entity
*entity
= NULL
;
661 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_adj_getnext");
663 /* if an adj_index of zero is sent, get the index of
664 * the first adj in the list
667 this_one
= MPLS_BOOL_TRUE
;
670 mpls_lock_get(g
->global_lock
); /* LOCK */
672 if (ldp_global_find_entity_index(g
, e
->index
, &entity
) == MPLS_SUCCESS
) {
673 adj
= MPLS_LIST_HEAD(&entity
->adj_root
);
675 if (this_one
== MPLS_BOOL_TRUE
) {
680 /* since the entities are sort in the list ... */
681 if (adj
->index
> e
->adj_index
) {
683 } else if (adj
->index
== e
->adj_index
) {
684 this_one
= MPLS_BOOL_TRUE
;
686 adj
= MPLS_LIST_NEXT(&entity
->adj_root
, adj
, _entity
);
689 mpls_lock_release(g
->global_lock
); /* UNLOCK */
692 e
->adj_index
= adj_next
->index
;
696 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_adj_getnext");
700 /******************* INTERFACE **********************/
702 mpls_return_enum
ldp_cfg_if_get(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
704 ldp_global
*global
= (ldp_global
*) handle
;
706 mpls_return_enum retval
= MPLS_FAILURE
;
708 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
710 LDP_ENTER(global
->user_data
, "ldp_cfg_if_get");
712 mpls_lock_get(global
->global_lock
); /* LOCK */
714 if (ldp_global_find_if_index(global
, i
->index
, &iff
) != MPLS_SUCCESS
)
715 goto ldp_cfg_if_get_end
;
717 if (flag
& LDP_IF_CFG_NAME
) {
718 strncpy(i
->name
, iff
->name
, MPLS_MAX_IF_NAME
);
720 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
721 i
->label_space
= iff
->label_space
;
723 if (flag
& LDP_IF_CFG_ENTITY_INDEX
) {
724 i
->entity_index
= iff
->entity
? iff
->entity
->index
: 0;
726 if (flag
& LDP_IF_CFG_OPER_STATE
) {
727 i
->oper_state
= iff
->oper_state
;
729 if (flag
& LDP_IF_CFG_LOCAL_SOURCE_ADDR
) {
730 memcpy(&i
->local_source_address
, &iff
->local_source_address
,
731 sizeof(mpls_inet_addr
));
733 retval
= MPLS_SUCCESS
;
736 mpls_lock_release(global
->global_lock
); /* UNLOCK */
738 LDP_EXIT(global
->user_data
, "ldp_cfg_if_get");
743 mpls_return_enum
ldp_cfg_if_getnext(mpls_cfg_handle handle
, ldp_if
* i
,
746 ldp_global
*g
= (ldp_global
*) handle
;
748 mpls_return_enum r
= MPLS_FAILURE
;
749 mpls_bool done
= MPLS_BOOL_FALSE
;
752 LDP_ENTER(g
->user_data
, "ldp_cfg_if_getnext");
757 index
= i
->index
+ 1;
760 mpls_lock_get(g
->global_lock
); /* LOCK */
761 while (done
== MPLS_BOOL_FALSE
) {
762 switch ((r
= ldp_global_find_if_index(g
, index
, &iff
))) {
764 case MPLS_END_OF_LIST
:
765 done
= MPLS_BOOL_TRUE
;
774 mpls_lock_release(g
->global_lock
); /* UNLOCK */
776 if (r
== MPLS_SUCCESS
) {
777 i
->index
= iff
->index
;
778 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
779 return ldp_cfg_if_get(g
, i
, flag
);
781 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
785 mpls_return_enum
ldp_cfg_if_test(mpls_cfg_handle handle
, ldp_if
* i
,
788 ldp_global
*global
= (ldp_global
*) handle
;
790 mpls_return_enum retval
= MPLS_FAILURE
;
792 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
794 LDP_ENTER(global
->user_data
, "ldp_cfg_if_test");
796 mpls_lock_get(global
->global_lock
); /* LOCK */
798 if (!(flag
& LDP_CFG_ADD
)) {
799 ldp_global_find_if_index(global
, i
->index
, &iff
);
801 retval
= MPLS_SUCCESS
;
802 goto ldp_cfg_if_test_end
;
806 ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
807 (flag
& LDP_IF_CFG_WHEN_DOWN
))) goto ldp_cfg_if_test_end
;
809 if (flag
& LDP_CFG_DEL
) {
810 if (iff
->entity
!= NULL
)
811 goto ldp_cfg_if_test_end
;
813 retval
= MPLS_SUCCESS
;
816 mpls_lock_release(global
->global_lock
); /* UNLOCK */
818 LDP_EXIT(global
->user_data
, "ldp_cfg_if_test");
823 mpls_return_enum
ldp_cfg_if_set(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
825 ldp_global
*global
= (ldp_global
*)handle
;
827 mpls_return_enum retval
= MPLS_FAILURE
;
829 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
831 LDP_ENTER(global
->user_data
, "ldp_cfg_if_set");
833 mpls_lock_get(global
->global_lock
); /* LOCK */
835 if (flag
& LDP_CFG_ADD
) {
836 if ((iff
= ldp_if_create()) == NULL
) {
837 goto ldp_cfg_if_set_end
;
839 if (mpls_if_handle_verify(global
->ifmgr_handle
, i
->handle
) == MPLS_BOOL_FALSE
) {
840 i
->handle
= mpls_ifmgr_open_if(global
->ifmgr_handle
, i
->name
);
842 iff
->handle
= i
->handle
;
843 i
->index
= iff
->index
;
844 strncpy(iff
->name
, i
->name
, MPLS_MAX_IF_NAME
);
845 _ldp_global_add_if(global
, iff
);
847 ldp_global_find_if_index(global
, i
->index
, &iff
);
851 ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
852 (flag
& LDP_IF_CFG_WHEN_DOWN
))) goto ldp_cfg_if_set_end
;
854 if (flag
& LDP_CFG_DEL
) {
855 if (iff
->entity
!= NULL
) {
856 goto ldp_cfg_if_set_end
;
859 _ldp_global_del_if(global
, iff
);
861 retval
= MPLS_SUCCESS
;
862 goto ldp_cfg_if_set_end
;
864 if (flag
& LDP_IF_CFG_INDEX
) {
865 iff
->index
= i
->index
;
867 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
868 iff
->label_space
= i
->label_space
;
870 global
->configuration_sequence_number
++;
872 retval
= MPLS_SUCCESS
;
875 mpls_lock_release(global
->global_lock
); /* UNLOCK */
877 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
882 /******************* ATTR **********************/
884 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
887 ldp_global
*global
= (ldp_global
*) handle
;
888 ldp_attr
*attr
= NULL
;
889 mpls_return_enum retval
= MPLS_FAILURE
;
891 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
893 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
895 mpls_lock_get(global
->global_lock
); /* LOCK */
897 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
898 goto ldp_cfg_attr_get_end
;
900 if (flag
& LDP_ATTR_CFG_STATE
) {
901 a
->state
= attr
->state
;
903 if (flag
& LDP_ATTR_CFG_FEC
) {
904 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
906 if (flag
& LDP_ATTR_CFG_LABEL
) {
907 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
909 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
910 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
912 if (flag
& LDP_ATTR_CFG_PATH
) {
913 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
915 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
916 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
918 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
919 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
921 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
922 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
924 if (flag
& LDP_ATTR_CFG_INGRESS
) {
925 a
->ingress
= attr
->ingress
;
927 retval
= MPLS_SUCCESS
;
929 ldp_cfg_attr_get_end
:
930 mpls_lock_release(global
->global_lock
); /* UNLOCK */
932 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
937 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
940 ldp_global
*g
= (ldp_global
*) handle
;
941 ldp_attr
*attr
= NULL
;
942 mpls_return_enum r
= MPLS_FAILURE
;
943 mpls_bool done
= MPLS_BOOL_FALSE
;
946 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
951 index
= a
->index
+ 1;
954 mpls_lock_get(g
->global_lock
); /* LOCK */
955 while (done
== MPLS_BOOL_FALSE
) {
956 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
958 case MPLS_END_OF_LIST
:
959 done
= MPLS_BOOL_TRUE
;
968 mpls_lock_release(g
->global_lock
); /* UNLOCK */
970 if (r
== MPLS_SUCCESS
) {
971 a
->index
= attr
->index
;
972 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
973 return ldp_cfg_attr_get(g
, a
, flag
);
975 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
979 /******************* PEER **********************/
981 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
984 ldp_global
*global
= (ldp_global
*) handle
;
985 ldp_peer
*peer
= NULL
;
986 mpls_return_enum retval
= MPLS_FAILURE
;
988 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
990 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
992 mpls_lock_get(global
->global_lock
); /* LOCK */
994 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
995 goto ldp_cfg_peer_get_end
;
997 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
998 p
->label_space
= peer
->label_space
;
1000 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1001 p
->target_role
= peer
->target_role
;
1003 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1004 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1006 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1007 p
->entity_index
= peer
->entity
->index
;
1009 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1010 p
->oper_state
= peer
->oper_state
;
1012 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1013 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1015 if (flag
& LDP_PEER_CFG_LOCAL_SOURCE_ADDR
) {
1016 memcpy(&p
->local_source_address
, &peer
->local_source_address
,
1017 sizeof(mpls_inet_addr
));
1019 retval
= MPLS_SUCCESS
;
1021 ldp_cfg_peer_get_end
:
1022 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1024 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1029 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1032 ldp_global
*g
= (ldp_global
*) handle
;
1033 ldp_peer
*peer
= NULL
;
1034 mpls_return_enum r
= MPLS_FAILURE
;
1035 mpls_bool done
= MPLS_BOOL_FALSE
;
1038 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1040 if (p
->index
== 0) {
1043 index
= p
->index
+ 1;
1046 mpls_lock_get(g
->global_lock
); /* LOCK */
1047 while (done
== MPLS_BOOL_FALSE
) {
1048 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1050 case MPLS_END_OF_LIST
:
1051 done
= MPLS_BOOL_TRUE
;
1060 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1062 if (r
== MPLS_SUCCESS
) {
1063 p
->index
= peer
->index
;
1064 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1065 return ldp_cfg_peer_get(g
, p
, flag
);
1067 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1071 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1074 // ldp_global* g = (ldp_global*)handle;
1075 return MPLS_SUCCESS
;
1078 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1081 ldp_global
*global
= (ldp_global
*) handle
;
1082 ldp_peer
*peer
= NULL
;
1083 mpls_return_enum retval
= MPLS_FAILURE
;
1085 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1087 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1089 mpls_lock_get(global
->global_lock
); /* LOCK */
1091 if (flag
& LDP_CFG_ADD
) {
1092 if ((peer
= ldp_peer_create()) == NULL
) {
1093 goto ldp_cfg_peer_set_end
;
1095 p
->index
= peer
->index
;
1096 _ldp_global_add_peer(global
, peer
);
1098 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1102 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1104 goto ldp_cfg_peer_set_end
;
1106 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1107 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1109 goto ldp_cfg_peer_set_end
;
1112 if (flag
& LDP_CFG_DEL
) {
1113 if (peer
->entity
!= NULL
) {
1114 LDP_PRINT(global
->user_data
,
1115 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1117 goto ldp_cfg_peer_set_end
;
1120 _ldp_global_del_peer(global
, peer
);
1122 retval
= MPLS_SUCCESS
;
1123 goto ldp_cfg_peer_set_end
;
1125 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1126 peer
->label_space
= p
->label_space
;
1128 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1129 peer
->target_role
= p
->target_role
;
1131 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1132 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1134 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1135 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1138 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1140 global
->configuration_sequence_number
++;
1142 retval
= MPLS_SUCCESS
;
1144 ldp_cfg_peer_set_end
:
1145 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1147 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1152 /******************* ADJACENCY **********************/
1154 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1157 ldp_global
*global
= (ldp_global
*) handle
;
1158 ldp_adj
*adj
= NULL
;
1159 mpls_return_enum retval
= MPLS_FAILURE
;
1161 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1163 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1165 mpls_lock_get(global
->global_lock
); /* LOCK */
1167 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1168 goto ldp_cfg_adj_get_end
;
1170 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1171 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1172 sizeof(mpls_inet_addr
));
1174 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1175 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1176 sizeof(mpls_inet_addr
));
1178 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1179 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1180 sizeof(mpls_inet_addr
));
1182 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1183 a
->remote_csn
= adj
->remote_csn
;
1185 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1186 a
->remote_label_space
= adj
->remote_label_space
;
1188 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1189 a
->remote_hellotime
= adj
->remote_hellotime
;
1191 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1192 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1194 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1195 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1197 if (flag
& LDP_ADJ_CFG_ROLE
) {
1198 a
->role
= adj
->role
;
1200 retval
= MPLS_SUCCESS
;
1202 ldp_cfg_adj_get_end
:
1204 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1206 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1211 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1214 ldp_global
*g
= (ldp_global
*) handle
;
1215 ldp_adj
*adj
= NULL
;
1216 mpls_return_enum r
= MPLS_FAILURE
;
1217 mpls_bool done
= MPLS_BOOL_FALSE
;
1220 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1222 if (a
->index
== 0) {
1225 index
= a
->index
+ 1;
1228 mpls_lock_get(g
->global_lock
); /* LOCK */
1229 while (done
== MPLS_BOOL_FALSE
) {
1230 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1232 case MPLS_END_OF_LIST
:
1233 done
= MPLS_BOOL_TRUE
;
1242 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1244 if (r
== MPLS_SUCCESS
) {
1245 a
->index
= adj
->index
;
1246 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1247 return ldp_cfg_adj_get(g
, a
, flag
);
1249 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1253 /******************* SESSION **********************/
1255 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1258 ldp_global
*global
= (ldp_global
*) handle
;
1259 ldp_session
*session
= NULL
;
1260 mpls_return_enum retval
= MPLS_FAILURE
;
1262 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1264 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1266 mpls_lock_get(global
->global_lock
); /* LOCK */
1268 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1269 goto ldp_cfg_session_get_end
;
1271 if (flag
& LDP_SESSION_CFG_STATE
) {
1272 s
->state
= session
->state
;
1274 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1275 s
->oper_up
= session
->oper_up
;
1277 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1278 s
->oper_max_pdu
= session
->oper_max_pdu
;
1280 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1281 s
->oper_keepalive
= session
->oper_keepalive
;
1283 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1284 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1286 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1287 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1289 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1290 s
->oper_loop_detection
= session
->oper_loop_detection
;
1292 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1293 s
->remote_max_pdu
= session
->remote_max_pdu
;
1295 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1296 s
->remote_keepalive
= session
->remote_keepalive
;
1298 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1299 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1301 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1302 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1304 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1305 s
->remote_loop_detection
= session
->remote_loop_detection
;
1307 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1308 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1309 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1311 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1312 s
->remote_dest
.port
= session
->remote_dest
.port
;
1314 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1315 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1317 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1318 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1320 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1321 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1322 s
->adj_index
= a
? a
->index
: 0;
1324 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1325 s
->mesg_tx
= session
->mesg_tx
;
1327 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1328 s
->mesg_rx
= session
->mesg_rx
;
1330 retval
= MPLS_SUCCESS
;
1332 ldp_cfg_session_get_end
:
1333 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1335 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1340 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1343 ldp_global
*g
= (ldp_global
*) handle
;
1344 ldp_session
*ses
= NULL
;
1345 mpls_return_enum r
= MPLS_FAILURE
;
1346 mpls_bool done
= MPLS_BOOL_FALSE
;
1349 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1351 if (s
->index
== 0) {
1354 index
= s
->index
+ 1;
1357 mpls_lock_get(g
->global_lock
); /* LOCK */
1358 while (done
== MPLS_BOOL_FALSE
) {
1359 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1361 case MPLS_END_OF_LIST
:
1362 done
= MPLS_BOOL_TRUE
;
1371 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1373 if (r
== MPLS_SUCCESS
) {
1374 s
->index
= ses
->index
;
1376 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1377 return ldp_cfg_session_get(g
, s
, flag
);
1380 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1385 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
1388 ldp_global
*g
= (ldp_global
*) handle
;
1389 mpls_bool this_one
= MPLS_BOOL_FALSE
;
1390 mpls_return_enum r
= MPLS_FAILURE
;
1391 ldp_adj
*adj_next
= NULL
;
1392 ldp_adj
*adj
= NULL
;
1393 ldp_session
*session
= NULL
;
1395 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
1397 /* if an adj_index of zero is sent, get the index of
1398 * the first adj in the list
1400 if (!s
->adj_index
) {
1401 this_one
= MPLS_BOOL_TRUE
;
1404 mpls_lock_get(g
->global_lock
); /* LOCK */
1406 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
1407 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
1409 if (this_one
== MPLS_BOOL_TRUE
) {
1414 /* since the entities are sort in the list ... */
1415 if (adj
->index
> s
->adj_index
) {
1417 } else if (adj
->index
== s
->adj_index
) {
1418 this_one
= MPLS_BOOL_TRUE
;
1420 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
1423 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1426 s
->adj_index
= adj_next
->index
;
1430 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
1434 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
1435 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
1437 ldp_global
*global
= (ldp_global
*) handle
;
1438 ldp_session
*session
= NULL
;
1439 ldp_addr
*addr
= NULL
;
1440 mpls_return_enum retval
= MPLS_FAILURE
;
1442 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
1444 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
1446 mpls_lock_get(global
->global_lock
); /* LOCK */
1448 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1449 goto ldp_cfg_session_raddr_get_end
;
1451 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
1452 goto ldp_cfg_session_raddr_get_end
;
1454 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
1455 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
1457 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
1458 a
->index
= addr
->index
;
1460 retval
= MPLS_SUCCESS
;
1462 ldp_cfg_session_raddr_get_end
:
1463 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1465 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
1470 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
1471 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
1473 ldp_global
*g
= (ldp_global
*) handle
;
1474 ldp_addr
*addr
= NULL
;
1475 mpls_return_enum r
= MPLS_FAILURE
;
1476 mpls_bool done
= MPLS_BOOL_FALSE
;
1477 ldp_session
*sp
= NULL
;
1480 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
1482 if (a
->index
== 0) {
1485 index
= a
->index
+ 1;
1488 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
1489 if (r
!= MPLS_SUCCESS
) {
1493 mpls_lock_get(g
->global_lock
); /* LOCK */
1494 while (done
== MPLS_BOOL_FALSE
) {
1495 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
1497 case MPLS_END_OF_LIST
:
1498 done
= MPLS_BOOL_TRUE
;
1507 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1509 if (r
== MPLS_SUCCESS
) {
1510 a
->index
= addr
->index
;
1511 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
1514 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1518 /******************* IN LABEL **********************/
1520 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
1523 ldp_global
*global
= (ldp_global
*) handle
;
1524 ldp_inlabel
*inlabel
= NULL
;
1525 mpls_return_enum retval
= MPLS_FAILURE
;
1527 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
1529 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
1531 mpls_lock_get(global
->global_lock
); /* LOCK */
1533 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
1534 goto ldp_cfg_inlabel_get_end
;
1536 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
1537 i
->info
.labelspace
= inlabel
->info
.labelspace
;
1539 if (flag
& LDP_INLABEL_CFG_LABEL
) {
1540 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
1542 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
1543 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
1546 retval
= MPLS_SUCCESS
;
1548 ldp_cfg_inlabel_get_end
:
1549 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1551 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
1556 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
1559 ldp_global
*g
= (ldp_global
*) handle
;
1560 ldp_inlabel
*inlabel
= NULL
;
1561 mpls_return_enum r
= MPLS_FAILURE
;
1562 mpls_bool done
= MPLS_BOOL_FALSE
;
1565 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
1567 if (i
->index
== 0) {
1570 index
= i
->index
+ 1;
1573 mpls_lock_get(g
->global_lock
); /* LOCK */
1574 while (done
== MPLS_BOOL_FALSE
) {
1575 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
1577 case MPLS_END_OF_LIST
:
1578 done
= MPLS_BOOL_TRUE
;
1587 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1589 if (r
== MPLS_SUCCESS
) {
1590 i
->index
= inlabel
->index
;
1592 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
1593 return ldp_cfg_inlabel_get(g
, i
, flag
);
1596 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
1601 /******************* OUT LABEL **********************/
1603 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
1606 ldp_global
*global
= (ldp_global
*) handle
;
1607 ldp_outlabel
*outlabel
= NULL
;
1608 mpls_return_enum retval
= MPLS_FAILURE
;
1610 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
1612 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
1614 mpls_lock_get(global
->global_lock
); /* LOCK */
1616 if (ldp_global_find_outlabel_index(global
, o
->index
,
1617 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
1619 if (flag
& LDP_OUTLABEL_CFG_ADDR_INDEX
) {
1620 o
->addr_index
= (outlabel
->addr
) ? (outlabel
->addr
->index
) : 0;
1622 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
1623 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
1625 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
1626 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
1628 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
1629 o
->merge_count
= outlabel
->merge_count
;
1632 retval
= MPLS_SUCCESS
;
1634 ldp_cfg_outlabel_get_end
:
1635 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1637 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
1642 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
1643 ldp_outlabel
* o
, uint32_t flag
)
1645 ldp_global
*g
= (ldp_global
*) handle
;
1646 ldp_outlabel
*outlabel
= NULL
;
1647 mpls_return_enum r
= MPLS_FAILURE
;
1648 mpls_bool done
= MPLS_BOOL_FALSE
;
1651 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
1653 if (o
->index
== 0) {
1656 index
= o
->index
+ 1;
1659 mpls_lock_get(g
->global_lock
); /* LOCK */
1660 while (done
== MPLS_BOOL_FALSE
) {
1661 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
1663 case MPLS_END_OF_LIST
:
1664 done
= MPLS_BOOL_TRUE
;
1673 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1675 if (r
== MPLS_SUCCESS
) {
1676 o
->index
= outlabel
->index
;
1678 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
1679 return ldp_cfg_outlabel_get(g
, o
, flag
);
1682 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
1687 /******************* TUNNEL **********************/
1689 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
1692 ldp_global
*global
= (ldp_global
*) handle
;
1693 mpls_return_enum retval
= MPLS_FAILURE
;
1694 ldp_tunnel
*tunnel
= NULL
;
1696 MPLS_ASSERT(global
!=NULL
);
1698 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
1700 mpls_lock_get(global
->global_lock
); /* LOCK */
1702 if (flag
& LDP_CFG_ADD
) {
1703 if (!(tunnel
= ldp_tunnel_create())) {
1704 goto ldp_cfg_tunnel_set_end
;
1706 _ldp_global_add_tunnel(global
, tunnel
);
1708 t
->index
= tunnel
->index
;
1710 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
1714 LDP_PRINT(global
->user_data
,
1716 "ldp_cfg_tunnel_set:could not create tunnel\n");
1717 goto ldp_cfg_tunnel_set_end
;
1720 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
1721 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
1722 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
1724 goto ldp_cfg_tunnel_set_end
;
1727 if (flag
& LDP_CFG_DEL
) {
1728 if (tunnel
->outlabel
)
1729 ldp_tunnel_del_outlabel(tunnel
);
1730 if (tunnel
->resource
)
1731 ldp_tunnel_del_resource(tunnel
);
1732 if (tunnel
->hop_list
)
1733 ldp_tunnel_del_hop_list(tunnel
);
1734 _ldp_global_del_tunnel(global
, tunnel
);
1736 retval
= MPLS_SUCCESS
;
1737 goto ldp_cfg_tunnel_set_end
;
1740 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
1741 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
1743 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
1744 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
1746 if (flag
& LDP_TUNNEL_CFG_NAME
) {
1747 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
1749 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
1750 tunnel
->is_interface
= t
->is_interface
;
1752 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
1753 ldp_outlabel
*outlabel
= NULL
;
1755 if (t
->outlabel_index
) {
1756 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
1759 goto ldp_cfg_tunnel_set_end
;
1761 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
1763 ldp_tunnel_del_outlabel(tunnel
);
1766 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
1767 tunnel
->setup_prio
= t
->setup_prio
;
1769 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
1770 tunnel
->hold_prio
= t
->hold_prio
;
1772 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
1773 tunnel
->instance_prio
= t
->instance_prio
;
1775 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
1776 tunnel
->local_protect
= t
->local_protect
;
1778 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
1779 ldp_resource
*resource
= NULL
;
1781 if (t
->resource_index
) {
1782 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
1785 goto ldp_cfg_tunnel_set_end
;
1787 ldp_tunnel_add_resource(tunnel
, resource
);
1789 ldp_tunnel_del_resource(tunnel
);
1792 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
1793 ldp_hop_list
*hop_list
= NULL
;
1795 if (t
->hop_list_index
) {
1796 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
1799 goto ldp_cfg_tunnel_set_end
;
1801 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
1803 ldp_tunnel_del_hop_list(tunnel
);
1806 if (flag
& LDP_TUNNEL_CFG_FEC
) {
1807 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
1809 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
1810 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
1811 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
1812 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
1813 goto ldp_cfg_tunnel_set_end
;
1817 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
1818 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
1819 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
1820 goto ldp_cfg_tunnel_set_end
;
1823 LDP_PRINT(global
->user_data
,
1825 "ldp_cfg_tunnel_set: tunnel not ready\n");
1826 goto ldp_cfg_tunnel_set_end
;
1831 retval
= MPLS_SUCCESS
;
1833 ldp_cfg_tunnel_set_end
:
1835 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1837 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
1842 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
1845 ldp_global
*global
= (ldp_global
*) handle
;
1846 mpls_return_enum retval
= MPLS_FAILURE
;
1847 ldp_tunnel
*tunnel
= NULL
;
1849 MPLS_ASSERT(global
!=NULL
);
1851 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
1853 mpls_lock_get(global
->global_lock
); /* LOCK */
1855 if (flag
& LDP_CFG_ADD
) {
1856 retval
= MPLS_SUCCESS
;
1857 goto ldp_cfg_tunnel_test_end
;
1860 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
1863 goto ldp_cfg_tunnel_test_end
;
1866 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
1867 ldp_resource
*resource
= NULL
;
1869 if (t
->resource_index
) {
1870 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
1873 goto ldp_cfg_tunnel_test_end
;
1877 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
1878 ldp_hop_list
*hop_list
= NULL
;
1880 if (t
->hop_list_index
) {
1881 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
1884 goto ldp_cfg_tunnel_test_end
;
1888 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
1889 ldp_outlabel
*outlabel
= NULL
;
1891 if (t
->outlabel_index
) {
1892 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
1895 goto ldp_cfg_tunnel_test_end
;
1899 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
1900 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
1901 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
1902 goto ldp_cfg_tunnel_test_end
;
1904 retval
= MPLS_SUCCESS
;
1906 ldp_cfg_tunnel_test_end
:
1908 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1910 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
1915 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
1918 ldp_global
*global
= (ldp_global
*) handle
;
1919 mpls_return_enum retval
= MPLS_FAILURE
;
1920 ldp_tunnel
*tunnel
= NULL
;
1922 MPLS_ASSERT(global
!=NULL
);
1924 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
1926 mpls_lock_get(global
->global_lock
); /* LOCK */
1928 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
1931 goto ldp_cfg_tunnel_get_end
;
1933 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
1934 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
1936 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
1937 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
1939 if (flag
& LDP_TUNNEL_CFG_NAME
) {
1940 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
1942 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
1943 t
->is_interface
= tunnel
->is_interface
;
1945 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
1946 if (tunnel
->outlabel
) {
1947 t
->outlabel_index
= tunnel
->outlabel
->index
;
1949 t
->outlabel_index
= 0;
1952 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
1953 t
->setup_prio
= tunnel
->setup_prio
;
1955 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
1956 t
->hold_prio
= tunnel
->hold_prio
;
1958 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
1959 tunnel
->instance_prio
= t
->instance_prio
;
1961 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
1962 tunnel
->local_protect
= t
->local_protect
;
1964 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
1965 if (tunnel
->resource
) {
1966 t
->resource_index
= tunnel
->resource
->index
;
1968 t
->resource_index
= 0;
1971 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
1972 if (tunnel
->hop_list
) {
1973 t
->hop_list_index
= tunnel
->hop_list
->index
;
1975 t
->hop_list_index
= 0;
1978 if (flag
& LDP_TUNNEL_CFG_FEC
) {
1979 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
1981 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
1982 t
->admin_state
= tunnel
->admin_state
;
1984 retval
= MPLS_SUCCESS
;
1986 ldp_cfg_tunnel_get_end
:
1988 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1990 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
1995 /******************* RESOURCE **********************/
1997 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2000 ldp_global
*global
= (ldp_global
*) handle
;
2001 mpls_return_enum retval
= MPLS_FAILURE
;
2002 ldp_resource
*resource
= NULL
;
2004 MPLS_ASSERT(global
!=NULL
);
2006 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2008 mpls_lock_get(global
->global_lock
); /* LOCK */
2010 if (flag
& LDP_CFG_ADD
) {
2011 resource
= ldp_resource_create();
2012 _ldp_global_add_resource(global
, resource
);
2014 r
->index
= resource
->index
;
2016 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2020 goto ldp_cfg_resource_set_end
;
2023 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2024 resource
->max_rate
= r
->max_rate
;
2026 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2027 resource
->mean_rate
= r
->mean_rate
;
2029 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2030 resource
->burst_size
= r
->burst_size
;
2032 retval
= MPLS_SUCCESS
;
2034 ldp_cfg_resource_set_end
:
2036 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2038 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2043 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2046 ldp_global
*global
= (ldp_global
*) handle
;
2047 mpls_return_enum retval
= MPLS_FAILURE
;
2048 ldp_resource
*resource
= NULL
;
2050 MPLS_ASSERT(global
!=NULL
);
2052 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2054 mpls_lock_get(global
->global_lock
); /* LOCK */
2056 if (flag
& LDP_CFG_ADD
) {
2057 retval
= MPLS_SUCCESS
;
2058 goto ldp_cfg_resource_test_end
;
2061 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2064 goto ldp_cfg_resource_test_end
;
2067 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2068 goto ldp_cfg_resource_test_end
;
2070 retval
= MPLS_SUCCESS
;
2072 ldp_cfg_resource_test_end
:
2074 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2076 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2081 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2084 ldp_global
*global
= (ldp_global
*) handle
;
2085 mpls_return_enum retval
= MPLS_FAILURE
;
2086 ldp_resource
*resource
= NULL
;
2088 MPLS_ASSERT(global
!=NULL
);
2090 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2092 mpls_lock_get(global
->global_lock
); /* LOCK */
2094 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2097 goto ldp_cfg_resource_get_end
;
2100 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2101 r
->max_rate
= resource
->max_rate
;
2103 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2104 r
->mean_rate
= resource
->mean_rate
;
2106 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2107 r
->burst_size
= resource
->burst_size
;
2109 retval
= MPLS_SUCCESS
;
2111 ldp_cfg_resource_get_end
:
2113 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2115 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2120 /******************* HOP **********************/
2122 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2125 ldp_global
*global
= (ldp_global
*) handle
;
2126 mpls_return_enum retval
= MPLS_FAILURE
;
2127 ldp_hop_list
*hop_list
= NULL
;
2128 ldp_hop
*hop
= NULL
;
2130 MPLS_ASSERT(global
!=NULL
);
2132 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2134 if (!h
->hop_list_index
&& !h
->index
) {
2138 mpls_lock_get(global
->global_lock
); /* LOCK */
2140 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2143 if (flag
& LDP_CFG_ADD
) {
2144 if (!(hop_list
= ldp_hop_list_create())) {
2145 goto ldp_cfg_hop_set_end
;
2147 _ldp_global_add_hop_list(global
, hop_list
);
2149 h
->hop_list_index
= hop_list
->index
;
2151 goto ldp_cfg_hop_set_end
;
2155 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2157 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2158 if (!(hop
= ldp_hop_create())) {
2159 goto ldp_cfg_hop_set_end
;
2161 hop
->index
= h
->index
;
2162 ldp_hop_list_add_hop(hop_list
, hop
);
2164 goto ldp_cfg_hop_set_end
;
2168 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2169 hop
->path_option
= h
->path_option
;
2171 if (flag
& LDP_HOP_CFG_ADDR
) {
2172 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2174 if (flag
& LDP_HOP_CFG_TYPE
) {
2175 hop
->type
= h
->type
;
2177 retval
= MPLS_SUCCESS
;
2179 ldp_cfg_hop_set_end
:
2181 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2183 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2188 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2191 ldp_global
*global
= (ldp_global
*) handle
;
2192 mpls_return_enum retval
= MPLS_FAILURE
;
2193 ldp_hop_list
*hop_list
= NULL
;
2194 ldp_hop
*hop
= NULL
;
2196 MPLS_ASSERT(global
!=NULL
);
2198 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2200 mpls_lock_get(global
->global_lock
); /* LOCK */
2202 if (flag
& LDP_CFG_ADD
) {
2203 retval
= MPLS_SUCCESS
;
2204 goto ldp_cfg_hop_test_end
;
2207 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2210 goto ldp_cfg_hop_test_end
;
2213 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2215 goto ldp_cfg_hop_test_end
;
2218 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2219 goto ldp_cfg_hop_test_end
;
2221 retval
= MPLS_SUCCESS
;
2223 ldp_cfg_hop_test_end
:
2225 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2227 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2232 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2235 ldp_global
*global
= (ldp_global
*) handle
;
2236 mpls_return_enum retval
= MPLS_FAILURE
;
2237 ldp_hop_list
*hop_list
= NULL
;
2238 ldp_hop
*hop
= NULL
;
2240 MPLS_ASSERT(global
!=NULL
);
2242 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2244 mpls_lock_get(global
->global_lock
); /* LOCK */
2246 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2249 goto ldp_cfg_hop_get_end
;
2252 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2254 goto ldp_cfg_hop_get_end
;
2257 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2258 h
->path_option
= hop
->path_option
;
2260 if (flag
& LDP_HOP_CFG_ADDR
) {
2261 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2263 if (flag
& LDP_HOP_CFG_TYPE
) {
2264 h
->type
= hop
->type
;
2266 retval
= MPLS_SUCCESS
;
2268 ldp_cfg_hop_get_end
:
2270 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2272 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");