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"
18 #include "ldp_nexthop.h"
19 #include "ldp_tunnel.h"
20 #include "ldp_resource.h"
21 #include "mpls_ifmgr_impl.h"
22 #include "ldp_label_mapping.h"
24 #include "ldp_hop_list.h"
25 #include "mpls_lock_impl.h"
26 #include "mpls_trace_impl.h"
27 #include "mpls_tree_impl.h"
29 mpls_cfg_handle
ldp_cfg_open(mpls_instance_handle data
)
31 ldp_global
*g
= ldp_global_create(data
);
33 LDP_ENTER(data
, "ldp_cfg_open");
34 LDP_EXIT(data
, "ldp_cfg_open");
36 return (mpls_cfg_handle
) g
;
39 void ldp_cfg_close(mpls_cfg_handle g
)
41 LDP_ENTER((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
43 LDP_EXIT((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
46 /******************* GLOBAL **********************/
48 mpls_return_enum
ldp_cfg_global_get(mpls_cfg_handle handle
, ldp_global
* g
,
51 ldp_global
*global
= (ldp_global
*) handle
;
53 MPLS_ASSERT(global
!=NULL
);
55 LDP_ENTER(global
->user_data
, "ldp_cfg_global_get");
57 mpls_lock_get(global
->global_lock
); /* LOCK */
59 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
60 memcpy(&(g
->lsr_identifier
), &(global
->lsr_identifier
),
61 sizeof(mpls_inet_addr
));
63 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
64 g
->admin_state
= global
->admin_state
;
66 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
67 g
->lsp_control_mode
= global
->lsp_control_mode
;
69 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
70 g
->label_retention_mode
= global
->label_retention_mode
;
72 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
73 g
->lsp_repair_mode
= global
->lsp_repair_mode
;
75 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
76 g
->propagate_release
= global
->propagate_release
;
78 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
79 g
->label_merge
= global
->label_merge
;
81 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
82 g
->loop_detection_mode
= global
->loop_detection_mode
;
84 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
85 g
->ttl_less_domain
= global
->ttl_less_domain
;
87 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
88 g
->local_tcp_port
= global
->local_tcp_port
;
90 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
91 g
->local_udp_port
= global
->local_udp_port
;
93 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
94 memcpy(&(g
->transport_address
), &(global
->transport_address
),
95 sizeof(mpls_inet_addr
));
97 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
98 g
->keepalive_timer
= global
->keepalive_timer
;
100 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
101 g
->keepalive_interval
= global
->keepalive_interval
;
103 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
104 g
->hellotime_timer
= global
->hellotime_timer
;
106 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
107 g
->hellotime_interval
= global
->hellotime_interval
;
110 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
111 g
->lsr_handle
= global
->lsr_handle
;
115 mpls_lock_release(global
->global_lock
); /* UNLOCK */
117 LDP_EXIT(global
->user_data
, "ldp_cfg_global_get");
122 mpls_return_enum
ldp_cfg_global_test(mpls_cfg_handle handle
, ldp_global
* g
,
125 ldp_global
*global
= (ldp_global
*) handle
;
126 mpls_return_enum retval
= MPLS_SUCCESS
;
128 MPLS_ASSERT(global
!=NULL
);
130 LDP_ENTER(global
->user_data
, "ldp_cfg_global_test");
132 mpls_lock_get(global
->global_lock
); /* LOCK */
134 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
))
135 retval
= MPLS_FAILURE
;
137 mpls_lock_release(global
->global_lock
); /* UNLOCK */
139 LDP_EXIT(global
->user_data
, "ldp_cfg_global_test");
144 mpls_return_enum
ldp_cfg_global_set(mpls_cfg_handle handle
, ldp_global
* g
,
147 ldp_global
*global
= (ldp_global
*) handle
;
148 mpls_return_enum retval
= MPLS_FAILURE
;
150 MPLS_ASSERT(global
!=NULL
);
152 LDP_ENTER(global
->user_data
, "ldp_cfg_global_set");
154 mpls_lock_get(global
->global_lock
); /* LOCK */
156 if ((global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
)))
157 goto ldp_cfg_global_set_end
;
159 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
160 global
->lsp_control_mode
= g
->lsp_control_mode
;
162 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
163 global
->label_retention_mode
= g
->label_retention_mode
;
165 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
166 global
->lsp_repair_mode
= g
->lsp_repair_mode
;
168 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
169 global
->propagate_release
= g
->propagate_release
;
171 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
172 global
->label_merge
= g
->label_merge
;
174 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
175 global
->loop_detection_mode
= g
->loop_detection_mode
;
177 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
178 global
->ttl_less_domain
= g
->ttl_less_domain
;
180 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
181 global
->local_tcp_port
= g
->local_tcp_port
;
183 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
184 global
->local_udp_port
= g
->local_udp_port
;
186 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
187 memcpy(&(global
->lsr_identifier
), &(g
->lsr_identifier
),
188 sizeof(mpls_inet_addr
));
191 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
192 global
->lsr_handle
= g
->lsr_handle
;
195 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
196 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& g
->admin_state
== MPLS_ADMIN_DISABLE
) {
197 ldp_global_shutdown(global
);
198 } else if (global
->admin_state
== MPLS_ADMIN_DISABLE
&& g
->admin_state
==
200 ldp_global_startup(global
);
203 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
204 memcpy(&(global
->transport_address
), &(g
->transport_address
),
205 sizeof(mpls_inet_addr
));
207 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
208 if (g
->keepalive_timer
== 0) {
209 global
->keepalive_timer
= LDP_ENTITY_DEF_KEEPALIVE_TIMER
;
211 global
->keepalive_timer
= g
->keepalive_timer
;
214 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
215 if (g
->keepalive_interval
== 0) {
216 global
->keepalive_interval
= LDP_ENTITY_DEF_KEEPALIVE_INTERVAL
;
218 global
->keepalive_interval
= g
->keepalive_interval
;
221 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
222 if (g
->hellotime_timer
== 0) {
223 global
->hellotime_timer
= LDP_ENTITY_DEF_HELLOTIME_TIMER
;
225 global
->hellotime_timer
= g
->hellotime_timer
;
228 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
229 if (g
->hellotime_interval
== 0) {
230 global
->hellotime_interval
= LDP_ENTITY_DEF_HELLOTIME_INTERVAL
;
232 global
->hellotime_interval
= g
->hellotime_interval
;
236 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
237 global
->lsr_handle
= g
->lsr_handle
;
240 global
->configuration_sequence_number
++;
242 retval
= MPLS_SUCCESS
;
244 ldp_cfg_global_set_end
:
246 mpls_lock_release(global
->global_lock
); /* UNLOCK */
248 LDP_EXIT(global
->user_data
, "ldp_cfg_global_set");
253 /******************* ENTITY **********************/
255 /* must set ldp_entity->index */
256 mpls_return_enum
ldp_cfg_entity_get(mpls_cfg_handle handle
, ldp_entity
* e
,
259 ldp_global
*global
= (ldp_global
*) handle
;
260 ldp_entity
*entity
= NULL
;
261 mpls_return_enum retval
= MPLS_FAILURE
;
263 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
265 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_get");
267 mpls_lock_get(global
->global_lock
); /* LOCK */
269 if (ldp_global_find_entity_index(global
, e
->index
, &entity
) != MPLS_SUCCESS
)
270 goto ldp_cfg_entity_get_end
;
272 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
273 e
->admin_state
= entity
->admin_state
;
275 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
276 e
->transport_address
= entity
->transport_address
;
278 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
279 e
->protocol_version
= entity
->protocol_version
;
281 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
282 e
->remote_tcp_port
= entity
->remote_tcp_port
;
284 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
285 e
->remote_udp_port
= entity
->remote_udp_port
;
287 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
288 e
->max_pdu
= entity
->max_pdu
;
290 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
291 e
->keepalive_timer
= entity
->keepalive_timer
;
293 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
294 e
->keepalive_interval
= entity
->keepalive_interval
;
296 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
297 e
->hellotime_timer
= entity
->hellotime_timer
;
299 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
300 e
->hellotime_interval
= entity
->hellotime_interval
;
302 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
303 e
->session_setup_count
= entity
->session_setup_count
;
305 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
306 e
->session_backoff_timer
= entity
->session_backoff_timer
;
308 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
309 e
->label_distribution_mode
= entity
->label_distribution_mode
;
311 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
312 e
->path_vector_limit
= entity
->path_vector_limit
;
314 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
315 e
->hop_count_limit
= entity
->hop_count_limit
;
317 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
318 e
->label_request_count
= entity
->label_request_count
;
320 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
321 e
->label_request_timer
= entity
->label_request_timer
;
323 if (flag
& LDP_ENTITY_CFG_TYPE
) {
324 e
->entity_type
= entity
->entity_type
;
326 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
327 e
->sub_index
= entity
->sub_index
;
329 if (flag
& LDP_ENTITY_CFG_MESG_TX
) {
330 e
->mesg_tx
= entity
->mesg_tx
;
332 if (flag
& LDP_ENTITY_CFG_MESG_RX
) {
333 e
->mesg_rx
= entity
->mesg_rx
;
335 if (flag
& LDP_ENTITY_CFG_ADJ_COUNT
) {
336 e
->adj_count
= e
->adj_root
.count
;
338 if (flag
& LDP_ENTITY_CFG_ADJ_INDEX
) {
339 ldp_adj
*a
= MPLS_LIST_HEAD(&e
->adj_root
);
340 e
->adj_index
= a
? a
->index
: 0;
342 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
343 e
->inherit_flag
= entity
->inherit_flag
;
345 retval
= MPLS_SUCCESS
;
347 ldp_cfg_entity_get_end
:
349 mpls_lock_release(global
->global_lock
); /* UNLOCK */
351 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_get");
356 mpls_return_enum
ldp_cfg_entity_getnext(mpls_cfg_handle handle
, ldp_entity
* e
,
359 ldp_global
*g
= (ldp_global
*) handle
;
360 ldp_entity
*entity
= NULL
;
361 mpls_return_enum r
= MPLS_FAILURE
;
362 mpls_bool done
= MPLS_BOOL_FALSE
;
365 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_getnext");
370 index
= e
->index
+ 1;
373 mpls_lock_get(g
->global_lock
); /* LOCK */
374 while (done
== MPLS_BOOL_FALSE
) {
375 switch ((r
= ldp_global_find_entity_index(g
, index
, &entity
))) {
377 case MPLS_END_OF_LIST
:
378 done
= MPLS_BOOL_TRUE
;
387 mpls_lock_release(g
->global_lock
); /* UNLOCK */
389 if (r
== MPLS_SUCCESS
) {
390 e
->index
= entity
->index
;
391 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
392 return ldp_cfg_entity_get(g
, e
, flag
);
394 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
398 mpls_return_enum
ldp_cfg_entity_test(mpls_cfg_handle handle
, ldp_entity
* e
,
401 ldp_global
*global
= (ldp_global
*) handle
;
402 ldp_entity
*entity
= NULL
;
403 mpls_return_enum retval
= MPLS_FAILURE
;
405 MPLS_ASSERT(global
!=NULL
);
407 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_test");
409 mpls_lock_get(global
->global_lock
); /* LOCK */
411 if (!(flag
& LDP_CFG_ADD
)) {
413 goto ldp_cfg_entity_test_end
;
415 ldp_global_find_entity_index(global
, e
->index
, &entity
);
417 retval
= MPLS_SUCCESS
;
418 goto ldp_cfg_entity_test_end
;
421 if (entity
== NULL
) {
422 goto ldp_cfg_entity_test_end
;
425 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
426 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
427 goto ldp_cfg_entity_test_end
;
430 retval
= MPLS_SUCCESS
;
432 ldp_cfg_entity_test_end
:
433 mpls_lock_release(global
->global_lock
); /* UNLOCK */
435 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_test");
440 /* must set ldp_entity->index if not an add */
441 mpls_return_enum
ldp_cfg_entity_set(mpls_cfg_handle handle
, ldp_entity
* e
,
444 ldp_global
*global
= (ldp_global
*) handle
;
445 ldp_entity
*entity
= NULL
;
446 mpls_return_enum retval
= MPLS_FAILURE
;
448 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
450 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_set");
452 mpls_lock_get(global
->global_lock
); /* LOCK */
454 if (flag
& LDP_CFG_ADD
) {
455 entity
= ldp_entity_create();
456 _ldp_global_add_entity(global
, entity
);
458 e
->index
= entity
->index
;
460 ldp_global_find_entity_index(global
, e
->index
, &entity
);
463 if (entity
== NULL
) {
464 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: can't find entity\n");
465 goto ldp_cfg_entity_set_end
;
468 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
469 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
470 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity is active\n");
471 goto ldp_cfg_entity_set_end
;
474 if (flag
& LDP_CFG_DEL
) {
475 switch (entity
->entity_type
) {
477 ldp_entity_del_if(entity
);
480 ldp_entity_del_peer(entity
);
485 _ldp_global_del_entity(global
, entity
);
487 retval
= MPLS_SUCCESS
;
488 goto ldp_cfg_entity_set_end
;
491 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
492 if (entity
->sub_index
!= 0) {
493 /* unlink the old sub object */
494 switch (entity
->entity_type
) {
496 ldp_entity_del_if(entity
);
499 ldp_entity_del_peer(entity
);
506 /* link the new sub object */
507 switch (e
->entity_type
) {
511 if (ldp_global_find_if_index(global
, e
->sub_index
,
512 &iff
) != MPLS_SUCCESS
) {
513 LDP_PRINT(global
->user_data
,
514 "ldp_cfg_entity_set: no such interface\n");
516 if (flag
& LDP_CFG_ADD
) {
517 _ldp_global_del_entity(global
, entity
);
519 goto ldp_cfg_entity_set_end
;
521 ldp_entity_add_if(entity
, iff
);
526 ldp_peer
*peer
= NULL
;
528 if (ldp_global_find_peer_index(global
, e
->sub_index
, &peer
) !=
530 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: no such peer\n");
532 if (flag
& LDP_CFG_ADD
) {
533 _ldp_global_del_entity(global
, entity
);
535 goto ldp_cfg_entity_set_end
;
537 ldp_entity_add_peer(entity
, peer
);
545 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
546 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
547 entity
->inherit_flag
|= LDP_ENTITY_CFG_TRANS_ADDR
;
549 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_TRANS_ADDR
;
551 memcpy(&entity
->transport_address
, &e
->transport_address
,
552 sizeof(mpls_inet_addr
));;
554 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
555 entity
->protocol_version
= e
->protocol_version
;
557 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
558 entity
->remote_tcp_port
= e
->remote_tcp_port
;
560 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
561 entity
->remote_udp_port
= e
->remote_udp_port
;
563 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
564 entity
->max_pdu
= e
->max_pdu
;
566 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
567 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
568 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
570 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
572 entity
->keepalive_timer
= e
->keepalive_timer
;
574 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
575 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
576 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
578 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
580 entity
->keepalive_interval
= e
->keepalive_interval
;
582 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
583 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
584 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_TIMER
;
586 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_TIMER
;
588 entity
->hellotime_timer
= e
->hellotime_timer
;
590 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
591 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
592 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
594 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
596 entity
->hellotime_interval
= e
->hellotime_interval
;
598 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
599 entity
->session_setup_count
= e
->session_setup_count
;
601 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
602 entity
->session_backoff_timer
= e
->session_backoff_timer
;
604 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
605 entity
->label_distribution_mode
= e
->label_distribution_mode
;
607 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
608 entity
->path_vector_limit
= e
->path_vector_limit
;
610 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
611 entity
->hop_count_limit
= e
->hop_count_limit
;
613 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
614 entity
->label_request_count
= e
->label_request_count
;
616 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
617 entity
->label_request_timer
= e
->label_request_timer
;
619 if (flag
& LDP_ENTITY_CFG_TYPE
) {
620 entity
->entity_type
= e
->entity_type
;
622 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
623 if (ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
&&
624 e
->admin_state
== MPLS_ADMIN_DISABLE
) {
625 if (ldp_entity_shutdown(global
, entity
, 0) == MPLS_FAILURE
) {
626 goto ldp_cfg_entity_set_end
;
628 } else if (ldp_entity_is_active(entity
) == MPLS_BOOL_FALSE
&&
629 e
->admin_state
== MPLS_ADMIN_ENABLE
&& ldp_entity_is_ready(entity
) == MPLS_BOOL_TRUE
) {
630 if (ldp_entity_startup(global
, entity
) == MPLS_FAILURE
) {
631 goto ldp_cfg_entity_set_end
;
634 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity not ready\n");
636 goto ldp_cfg_entity_set_end
;
639 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
640 entity
->inherit_flag
= e
->inherit_flag
;
642 global
->configuration_sequence_number
++;
644 retval
= MPLS_SUCCESS
;
646 ldp_cfg_entity_set_end
:
647 mpls_lock_release(global
->global_lock
); /* UNLOCK */
649 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_set");
654 mpls_return_enum
ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle
,
657 ldp_global
*g
= (ldp_global
*) handle
;
658 mpls_bool this_one
= MPLS_BOOL_FALSE
;
659 mpls_return_enum r
= MPLS_FAILURE
;
660 ldp_adj
*adj_next
= NULL
;
662 ldp_entity
*entity
= NULL
;
664 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_adj_getnext");
666 /* if an adj_index of zero is sent, get the index of
667 * the first adj in the list
670 this_one
= MPLS_BOOL_TRUE
;
673 mpls_lock_get(g
->global_lock
); /* LOCK */
675 if (ldp_global_find_entity_index(g
, e
->index
, &entity
) == MPLS_SUCCESS
) {
676 adj
= MPLS_LIST_HEAD(&entity
->adj_root
);
678 if (this_one
== MPLS_BOOL_TRUE
) {
683 /* since the entities are sort in the list ... */
684 if (adj
->index
> e
->adj_index
) {
686 } else if (adj
->index
== e
->adj_index
) {
687 this_one
= MPLS_BOOL_TRUE
;
689 adj
= MPLS_LIST_NEXT(&entity
->adj_root
, adj
, _entity
);
692 mpls_lock_release(g
->global_lock
); /* UNLOCK */
695 e
->adj_index
= adj_next
->index
;
699 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_adj_getnext");
703 /******************* INTERFACE **********************/
705 mpls_return_enum
ldp_cfg_if_get(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
707 ldp_global
*global
= (ldp_global
*) handle
;
709 mpls_return_enum retval
= MPLS_FAILURE
;
711 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
713 LDP_ENTER(global
->user_data
, "ldp_cfg_if_get");
715 mpls_lock_get(global
->global_lock
); /* LOCK */
717 if (ldp_global_find_if_index(global
, i
->index
, &iff
) != MPLS_SUCCESS
)
718 goto ldp_cfg_if_get_end
;
720 if (flag
& LDP_IF_CFG_NAME
) {
721 strncpy(i
->name
, iff
->name
, MPLS_MAX_IF_NAME
);
723 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
724 i
->label_space
= iff
->label_space
;
726 if (flag
& LDP_IF_CFG_ENTITY_INDEX
) {
727 i
->entity_index
= iff
->entity
? iff
->entity
->index
: 0;
729 if (flag
& LDP_IF_CFG_OPER_STATE
) {
730 i
->oper_state
= iff
->oper_state
;
732 if (flag
& LDP_IF_CFG_LOCAL_SOURCE_ADDR
) {
733 memcpy(&i
->local_source_address
, &iff
->local_source_address
,
734 sizeof(mpls_inet_addr
));
736 retval
= MPLS_SUCCESS
;
739 mpls_lock_release(global
->global_lock
); /* UNLOCK */
741 LDP_EXIT(global
->user_data
, "ldp_cfg_if_get");
746 mpls_return_enum
ldp_cfg_if_getnext(mpls_cfg_handle handle
, ldp_if
* i
,
749 ldp_global
*g
= (ldp_global
*) handle
;
751 mpls_return_enum r
= MPLS_FAILURE
;
752 mpls_bool done
= MPLS_BOOL_FALSE
;
755 LDP_ENTER(g
->user_data
, "ldp_cfg_if_getnext");
760 index
= i
->index
+ 1;
763 mpls_lock_get(g
->global_lock
); /* LOCK */
764 while (done
== MPLS_BOOL_FALSE
) {
765 switch ((r
= ldp_global_find_if_index(g
, index
, &iff
))) {
767 case MPLS_END_OF_LIST
:
768 done
= MPLS_BOOL_TRUE
;
777 mpls_lock_release(g
->global_lock
); /* UNLOCK */
779 if (r
== MPLS_SUCCESS
) {
780 i
->index
= iff
->index
;
781 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
782 return ldp_cfg_if_get(g
, i
, flag
);
784 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
788 mpls_return_enum
ldp_cfg_if_test(mpls_cfg_handle handle
, ldp_if
* i
,
791 ldp_global
*global
= (ldp_global
*) handle
;
793 mpls_return_enum retval
= MPLS_FAILURE
;
795 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
797 LDP_ENTER(global
->user_data
, "ldp_cfg_if_test");
799 mpls_lock_get(global
->global_lock
); /* LOCK */
801 if (!(flag
& LDP_CFG_ADD
)) {
802 ldp_global_find_if_index(global
, i
->index
, &iff
);
804 retval
= MPLS_SUCCESS
;
805 goto ldp_cfg_if_test_end
;
809 ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
810 (flag
& LDP_IF_CFG_WHEN_DOWN
))) goto ldp_cfg_if_test_end
;
812 if (flag
& LDP_CFG_DEL
) {
813 if (iff
->entity
!= NULL
)
814 goto ldp_cfg_if_test_end
;
816 retval
= MPLS_SUCCESS
;
819 mpls_lock_release(global
->global_lock
); /* UNLOCK */
821 LDP_EXIT(global
->user_data
, "ldp_cfg_if_test");
826 mpls_return_enum
ldp_cfg_if_set(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
828 ldp_global
*global
= (ldp_global
*)handle
;
830 mpls_return_enum retval
= MPLS_FAILURE
;
832 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
834 LDP_ENTER(global
->user_data
, "ldp_cfg_if_set");
836 mpls_lock_get(global
->global_lock
); /* LOCK */
838 if (flag
& LDP_CFG_ADD
) {
839 if ((iff
= ldp_global_find_if_handle(global
, i
->handle
)) == NULL
) {
840 if ((iff
= ldp_if_create()) == NULL
) {
841 goto ldp_cfg_if_set_end
;
843 if (mpls_if_handle_verify(global
->ifmgr_handle
, i
->handle
) ==
845 i
->handle
= mpls_ifmgr_open_if(global
->ifmgr_handle
, i
->name
);
847 iff
->handle
= i
->handle
;
849 i
->index
= iff
->index
;
850 strncpy(iff
->name
, i
->name
, MPLS_MAX_IF_NAME
);
851 iff
->used_by_ldp
= MPLS_BOOL_TRUE
;
852 _ldp_global_add_if(global
, iff
);
854 ldp_global_find_if_index(global
, i
->index
, &iff
);
858 ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
859 (flag
& LDP_IF_CFG_WHEN_DOWN
))) goto ldp_cfg_if_set_end
;
861 if (flag
& LDP_CFG_DEL
) {
862 if (iff
->entity
!= NULL
) {
863 goto ldp_cfg_if_set_end
;
866 iff
->used_by_ldp
= MPLS_BOOL_FALSE
;
867 _ldp_global_del_if(global
, iff
);
869 retval
= MPLS_SUCCESS
;
870 goto ldp_cfg_if_set_end
;
872 if (flag
& LDP_IF_CFG_INDEX
) {
873 iff
->index
= i
->index
;
875 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
876 iff
->label_space
= i
->label_space
;
878 global
->configuration_sequence_number
++;
880 retval
= MPLS_SUCCESS
;
883 mpls_lock_release(global
->global_lock
); /* UNLOCK */
885 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
890 /******************* ATTR **********************/
892 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
895 ldp_global
*global
= (ldp_global
*) handle
;
896 ldp_attr
*attr
= NULL
;
897 mpls_return_enum retval
= MPLS_FAILURE
;
899 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
901 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
903 mpls_lock_get(global
->global_lock
); /* LOCK */
905 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
906 goto ldp_cfg_attr_get_end
;
908 if (flag
& LDP_ATTR_CFG_STATE
) {
909 a
->state
= attr
->state
;
911 if (flag
& LDP_ATTR_CFG_FEC
) {
912 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
914 if (flag
& LDP_ATTR_CFG_LABEL
) {
915 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
917 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
918 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
920 if (flag
& LDP_ATTR_CFG_PATH
) {
921 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
923 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
924 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
926 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
927 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
929 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
930 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
932 if (flag
& LDP_ATTR_CFG_INGRESS
) {
933 a
->ingress
= attr
->ingress
;
935 retval
= MPLS_SUCCESS
;
937 ldp_cfg_attr_get_end
:
938 mpls_lock_release(global
->global_lock
); /* UNLOCK */
940 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
945 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
948 ldp_global
*g
= (ldp_global
*) handle
;
949 ldp_attr
*attr
= NULL
;
950 mpls_return_enum r
= MPLS_FAILURE
;
951 mpls_bool done
= MPLS_BOOL_FALSE
;
954 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
959 index
= a
->index
+ 1;
962 mpls_lock_get(g
->global_lock
); /* LOCK */
963 while (done
== MPLS_BOOL_FALSE
) {
964 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
966 case MPLS_END_OF_LIST
:
967 done
= MPLS_BOOL_TRUE
;
976 mpls_lock_release(g
->global_lock
); /* UNLOCK */
978 if (r
== MPLS_SUCCESS
) {
979 a
->index
= attr
->index
;
980 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
981 return ldp_cfg_attr_get(g
, a
, flag
);
983 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
987 /******************* PEER **********************/
989 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
992 ldp_global
*global
= (ldp_global
*) handle
;
993 ldp_peer
*peer
= NULL
;
994 mpls_return_enum retval
= MPLS_FAILURE
;
996 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
998 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
1000 mpls_lock_get(global
->global_lock
); /* LOCK */
1002 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
1003 goto ldp_cfg_peer_get_end
;
1005 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1006 p
->label_space
= peer
->label_space
;
1008 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1009 p
->target_role
= peer
->target_role
;
1011 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1012 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1014 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1015 p
->entity_index
= peer
->entity
->index
;
1017 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1018 p
->oper_state
= peer
->oper_state
;
1020 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1021 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1023 if (flag
& LDP_PEER_CFG_LOCAL_SOURCE_ADDR
) {
1024 memcpy(&p
->local_source_address
, &peer
->local_source_address
,
1025 sizeof(mpls_inet_addr
));
1027 retval
= MPLS_SUCCESS
;
1029 ldp_cfg_peer_get_end
:
1030 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1032 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1037 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1040 ldp_global
*g
= (ldp_global
*) handle
;
1041 ldp_peer
*peer
= NULL
;
1042 mpls_return_enum r
= MPLS_FAILURE
;
1043 mpls_bool done
= MPLS_BOOL_FALSE
;
1046 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1048 if (p
->index
== 0) {
1051 index
= p
->index
+ 1;
1054 mpls_lock_get(g
->global_lock
); /* LOCK */
1055 while (done
== MPLS_BOOL_FALSE
) {
1056 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1058 case MPLS_END_OF_LIST
:
1059 done
= MPLS_BOOL_TRUE
;
1068 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1070 if (r
== MPLS_SUCCESS
) {
1071 p
->index
= peer
->index
;
1072 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1073 return ldp_cfg_peer_get(g
, p
, flag
);
1075 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1079 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1082 // ldp_global* g = (ldp_global*)handle;
1083 return MPLS_SUCCESS
;
1086 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1089 ldp_global
*global
= (ldp_global
*) handle
;
1090 ldp_peer
*peer
= NULL
;
1091 mpls_return_enum retval
= MPLS_FAILURE
;
1093 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1095 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1097 mpls_lock_get(global
->global_lock
); /* LOCK */
1099 if (flag
& LDP_CFG_ADD
) {
1100 if ((peer
= ldp_peer_create()) == NULL
) {
1101 goto ldp_cfg_peer_set_end
;
1103 p
->index
= peer
->index
;
1104 _ldp_global_add_peer(global
, peer
);
1106 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1110 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1112 goto ldp_cfg_peer_set_end
;
1114 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1115 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1117 goto ldp_cfg_peer_set_end
;
1120 if (flag
& LDP_CFG_DEL
) {
1121 if (peer
->entity
!= NULL
) {
1122 LDP_PRINT(global
->user_data
,
1123 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1125 goto ldp_cfg_peer_set_end
;
1128 _ldp_global_del_peer(global
, peer
);
1130 retval
= MPLS_SUCCESS
;
1131 goto ldp_cfg_peer_set_end
;
1133 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1134 peer
->label_space
= p
->label_space
;
1136 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1137 peer
->target_role
= p
->target_role
;
1139 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1140 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1142 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1143 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1146 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1148 global
->configuration_sequence_number
++;
1150 retval
= MPLS_SUCCESS
;
1152 ldp_cfg_peer_set_end
:
1153 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1155 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1159 /******************* FEC **********************/
1161 mpls_return_enum
ldp_cfg_fec_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1164 ldp_global
*global
= (ldp_global
*) handle
;
1165 ldp_fec
*fec
= NULL
;
1166 mpls_return_enum retval
= MPLS_FAILURE
;
1168 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1170 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get");
1172 mpls_lock_get(global
->global_lock
); /* LOCK */
1174 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1175 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1177 fec
= ldp_fec_find(global
, f
);
1180 goto ldp_cfg_fec_get_end
;
1182 memcpy(f
, &fec
->info
, sizeof(mpls_fec
));
1183 retval
= MPLS_SUCCESS
;
1185 ldp_cfg_fec_get_end
:
1186 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1188 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get");
1193 mpls_return_enum
ldp_cfg_fec_getnext(mpls_cfg_handle handle
, mpls_fec
* f
,
1196 ldp_global
*g
= (ldp_global
*) handle
;
1197 ldp_fec
*fec
= NULL
;
1198 mpls_return_enum r
= MPLS_FAILURE
;
1199 mpls_bool done
= MPLS_BOOL_FALSE
;
1202 LDP_ENTER(g
->user_data
, "ldp_cfg_fec_getnext");
1204 if (f
->index
== 0) {
1207 index
= f
->index
+ 1;
1210 mpls_lock_get(g
->global_lock
); /* LOCK */
1211 while (done
== MPLS_BOOL_FALSE
) {
1212 switch ((r
= ldp_global_find_fec_index(g
, index
, &fec
))) {
1214 case MPLS_END_OF_LIST
:
1215 done
= MPLS_BOOL_TRUE
;
1224 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1226 if (r
== MPLS_SUCCESS
) {
1227 f
->index
= fec
->index
;
1228 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1229 return ldp_cfg_fec_get(g
, f
, flag
);
1231 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1235 mpls_return_enum
ldp_cfg_fec_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1238 // ldp_global* g = (ldp_global*)handle;
1239 return MPLS_SUCCESS
;
1242 mpls_return_enum
ldp_cfg_fec_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1245 ldp_global
*global
= (ldp_global
*) handle
;
1246 ldp_fec
*fec
= NULL
;
1247 mpls_return_enum retval
= MPLS_FAILURE
;
1249 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1251 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_set");
1253 mpls_lock_get(global
->global_lock
); /* LOCK */
1255 if (flag
& LDP_CFG_ADD
) {
1256 if (ldp_fec_find(global
, f
) || (fec
= ldp_fec_create()) == NULL
) {
1257 goto ldp_cfg_fec_set_end
;
1259 f
->index
= fec
->index
;
1260 mpls_fec2ldp_fec(f
, fec
);
1261 _ldp_global_add_fec(global
, fec
);
1262 ldp_fec_insert2(global
, fec
);
1264 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1265 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1267 fec
= ldp_fec_find(global
, f
);
1272 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_set: no such fec\n");
1273 goto ldp_cfg_fec_set_end
;
1276 if (flag
& LDP_CFG_DEL
) {
1277 ldp_fec_remove(global
,&fec
->info
);
1278 _ldp_global_del_fec(global
, fec
);
1281 retval
= MPLS_SUCCESS
;
1283 ldp_cfg_fec_set_end
:
1284 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1286 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1291 mpls_return_enum
ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1292 mpls_nexthop
*n
, uint32_t flag
)
1294 ldp_global
*global
= (ldp_global
*) handle
;
1295 ldp_fec
*fec
= NULL
;
1296 ldp_nexthop
*nh
= NULL
;
1297 mpls_return_enum retval
= MPLS_FAILURE
;
1299 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1301 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1303 mpls_lock_get(global
->global_lock
); /* LOCK */
1305 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1306 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1308 fec
= ldp_fec_find(global
, f
);
1311 goto ldp_cfg_fec_nexthop_get_end
;
1313 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1314 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1316 nh
= ldp_fec_nexthop_find(fec
, n
);
1319 goto ldp_cfg_fec_nexthop_get_end
;
1321 memcpy(n
, nh
, sizeof(mpls_nexthop
));
1322 retval
= MPLS_SUCCESS
;
1324 ldp_cfg_fec_nexthop_get_end
:
1325 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1327 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1332 mpls_return_enum
ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle
,
1333 mpls_fec
* f
, mpls_nexthop
*n
, uint32_t flag
)
1335 ldp_global
*global
= (ldp_global
*) handle
;
1336 ldp_fec
*fec
= NULL
;
1337 ldp_nexthop
*nh
= NULL
;
1338 mpls_return_enum r
= MPLS_FAILURE
;
1339 mpls_bool done
= MPLS_BOOL_FALSE
;
1342 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1344 if (n
->index
== 0) {
1347 index
= n
->index
+ 1;
1350 mpls_lock_get(global
->global_lock
); /* LOCK */
1352 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1353 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1355 fec
= ldp_fec_find(global
, f
);
1358 goto ldp_cfg_fec_nexthop_getnext_end
;
1360 while (done
== MPLS_BOOL_FALSE
) {
1361 switch ((r
= ldp_fec_find_nexthop_index(fec
, index
, &nh
))) {
1363 case MPLS_END_OF_LIST
:
1364 done
= MPLS_BOOL_TRUE
;
1373 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1375 if (r
== MPLS_SUCCESS
) {
1376 n
->index
= nh
->index
;
1377 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_getnext");
1378 return ldp_cfg_fec_nexthop_get(global
, f
, n
,
1379 flag
& ~LDP_FEC_NEXTHOP_CFG_BY_INDEX
);
1382 ldp_cfg_fec_nexthop_getnext_end
:
1384 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_getnext");
1388 mpls_return_enum
ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1389 mpls_nexthop
*n
, uint32_t flag
)
1391 // ldp_global* g = (ldp_global*)handle;
1392 return MPLS_SUCCESS
;
1395 mpls_return_enum
ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1396 mpls_nexthop
*n
, uint32_t flag
)
1398 ldp_global
*global
= (ldp_global
*) handle
;
1399 ldp_fec
*fec
= NULL
;
1400 ldp_nexthop
*nh
= NULL
;
1401 mpls_return_enum retval
= MPLS_FAILURE
;
1403 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
&& n
!= NULL
);
1405 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1407 mpls_lock_get(global
->global_lock
); /* LOCK */
1409 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1410 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1412 fec
= ldp_fec_find(global
, f
);
1415 goto ldp_cfg_fec_nexthop_set_end
;
1417 if (flag
& LDP_CFG_ADD
) {
1418 if (ldp_fec_nexthop_find(fec
, n
) || (nh
= ldp_nexthop_create()) == NULL
) {
1419 goto ldp_cfg_fec_nexthop_set_end
;
1421 n
->index
= nh
->index
;
1422 mpls_nexthop2ldp_nexthop(n
, nh
);
1423 _ldp_global_add_nexthop(global
, nh
);
1424 ldp_fec_add_nexthop(global
, fec
, nh
);
1426 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1427 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1429 nh
= ldp_fec_nexthop_find(fec
, n
);
1434 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_nexthop_set: no such nh\n");
1435 goto ldp_cfg_fec_nexthop_set_end
;
1438 if (flag
& LDP_CFG_DEL
) {
1439 ldp_fec_del_nexthop(fec
,nh
);
1440 _ldp_global_del_nexthop(global
, nh
);
1443 retval
= MPLS_SUCCESS
;
1445 ldp_cfg_fec_nexthop_set_end
:
1446 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1448 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1453 /******************* ADJACENCY **********************/
1455 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1458 ldp_global
*global
= (ldp_global
*) handle
;
1459 ldp_adj
*adj
= NULL
;
1460 mpls_return_enum retval
= MPLS_FAILURE
;
1462 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1464 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1466 mpls_lock_get(global
->global_lock
); /* LOCK */
1468 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1469 goto ldp_cfg_adj_get_end
;
1471 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1472 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1473 sizeof(mpls_inet_addr
));
1475 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1476 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1477 sizeof(mpls_inet_addr
));
1479 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1480 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1481 sizeof(mpls_inet_addr
));
1483 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1484 a
->remote_csn
= adj
->remote_csn
;
1486 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1487 a
->remote_label_space
= adj
->remote_label_space
;
1489 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1490 a
->remote_hellotime
= adj
->remote_hellotime
;
1492 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1493 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1495 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1496 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1498 if (flag
& LDP_ADJ_CFG_ROLE
) {
1499 a
->role
= adj
->role
;
1501 retval
= MPLS_SUCCESS
;
1503 ldp_cfg_adj_get_end
:
1505 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1507 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1512 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1515 ldp_global
*g
= (ldp_global
*) handle
;
1516 ldp_adj
*adj
= NULL
;
1517 mpls_return_enum r
= MPLS_FAILURE
;
1518 mpls_bool done
= MPLS_BOOL_FALSE
;
1521 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1523 if (a
->index
== 0) {
1526 index
= a
->index
+ 1;
1529 mpls_lock_get(g
->global_lock
); /* LOCK */
1530 while (done
== MPLS_BOOL_FALSE
) {
1531 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1533 case MPLS_END_OF_LIST
:
1534 done
= MPLS_BOOL_TRUE
;
1543 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1545 if (r
== MPLS_SUCCESS
) {
1546 a
->index
= adj
->index
;
1547 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1548 return ldp_cfg_adj_get(g
, a
, flag
);
1550 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1554 /******************* SESSION **********************/
1556 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1559 ldp_global
*global
= (ldp_global
*) handle
;
1560 ldp_session
*session
= NULL
;
1561 mpls_return_enum retval
= MPLS_FAILURE
;
1563 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1565 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1567 mpls_lock_get(global
->global_lock
); /* LOCK */
1569 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1570 goto ldp_cfg_session_get_end
;
1572 if (flag
& LDP_SESSION_CFG_STATE
) {
1573 s
->state
= session
->state
;
1575 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1576 s
->oper_up
= session
->oper_up
;
1578 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1579 s
->oper_max_pdu
= session
->oper_max_pdu
;
1581 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1582 s
->oper_keepalive
= session
->oper_keepalive
;
1584 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1585 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1587 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1588 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1590 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1591 s
->oper_loop_detection
= session
->oper_loop_detection
;
1593 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1594 s
->remote_max_pdu
= session
->remote_max_pdu
;
1596 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1597 s
->remote_keepalive
= session
->remote_keepalive
;
1599 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1600 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1602 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1603 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1605 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1606 s
->remote_loop_detection
= session
->remote_loop_detection
;
1608 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1609 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1610 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1612 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1613 s
->remote_dest
.port
= session
->remote_dest
.port
;
1615 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1616 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1618 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1619 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1621 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1622 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1623 s
->adj_index
= a
? a
->index
: 0;
1625 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1626 s
->mesg_tx
= session
->mesg_tx
;
1628 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1629 s
->mesg_rx
= session
->mesg_rx
;
1631 retval
= MPLS_SUCCESS
;
1633 ldp_cfg_session_get_end
:
1634 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1636 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1641 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1644 ldp_global
*g
= (ldp_global
*) handle
;
1645 ldp_session
*ses
= NULL
;
1646 mpls_return_enum r
= MPLS_FAILURE
;
1647 mpls_bool done
= MPLS_BOOL_FALSE
;
1650 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1652 if (s
->index
== 0) {
1655 index
= s
->index
+ 1;
1658 mpls_lock_get(g
->global_lock
); /* LOCK */
1659 while (done
== MPLS_BOOL_FALSE
) {
1660 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1662 case MPLS_END_OF_LIST
:
1663 done
= MPLS_BOOL_TRUE
;
1672 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1674 if (r
== MPLS_SUCCESS
) {
1675 s
->index
= ses
->index
;
1677 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1678 return ldp_cfg_session_get(g
, s
, flag
);
1681 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1686 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
1689 ldp_global
*g
= (ldp_global
*) handle
;
1690 mpls_bool this_one
= MPLS_BOOL_FALSE
;
1691 mpls_return_enum r
= MPLS_FAILURE
;
1692 ldp_adj
*adj_next
= NULL
;
1693 ldp_adj
*adj
= NULL
;
1694 ldp_session
*session
= NULL
;
1696 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
1698 /* if an adj_index of zero is sent, get the index of
1699 * the first adj in the list
1701 if (!s
->adj_index
) {
1702 this_one
= MPLS_BOOL_TRUE
;
1705 mpls_lock_get(g
->global_lock
); /* LOCK */
1707 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
1708 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
1710 if (this_one
== MPLS_BOOL_TRUE
) {
1715 /* since the entities are sort in the list ... */
1716 if (adj
->index
> s
->adj_index
) {
1718 } else if (adj
->index
== s
->adj_index
) {
1719 this_one
= MPLS_BOOL_TRUE
;
1721 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
1724 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1727 s
->adj_index
= adj_next
->index
;
1731 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
1735 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
1736 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
1738 ldp_global
*global
= (ldp_global
*) handle
;
1739 ldp_session
*session
= NULL
;
1740 ldp_addr
*addr
= NULL
;
1741 mpls_return_enum retval
= MPLS_FAILURE
;
1743 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
1745 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
1747 mpls_lock_get(global
->global_lock
); /* LOCK */
1749 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1750 goto ldp_cfg_session_raddr_get_end
;
1752 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
1753 goto ldp_cfg_session_raddr_get_end
;
1755 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
1756 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
1758 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
1759 a
->index
= addr
->index
;
1761 retval
= MPLS_SUCCESS
;
1763 ldp_cfg_session_raddr_get_end
:
1764 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1766 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
1771 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
1772 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
1774 ldp_global
*g
= (ldp_global
*) handle
;
1775 ldp_addr
*addr
= NULL
;
1776 mpls_return_enum r
= MPLS_FAILURE
;
1777 mpls_bool done
= MPLS_BOOL_FALSE
;
1778 ldp_session
*sp
= NULL
;
1781 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
1783 if (a
->index
== 0) {
1786 index
= a
->index
+ 1;
1789 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
1790 if (r
!= MPLS_SUCCESS
) {
1794 mpls_lock_get(g
->global_lock
); /* LOCK */
1795 while (done
== MPLS_BOOL_FALSE
) {
1796 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
1798 case MPLS_END_OF_LIST
:
1799 done
= MPLS_BOOL_TRUE
;
1808 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1810 if (r
== MPLS_SUCCESS
) {
1811 a
->index
= addr
->index
;
1812 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
1815 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1819 /******************* IN LABEL **********************/
1821 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
1824 ldp_global
*global
= (ldp_global
*) handle
;
1825 ldp_inlabel
*inlabel
= NULL
;
1826 mpls_return_enum retval
= MPLS_FAILURE
;
1828 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
1830 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
1832 mpls_lock_get(global
->global_lock
); /* LOCK */
1834 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
1835 goto ldp_cfg_inlabel_get_end
;
1837 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
1838 i
->info
.labelspace
= inlabel
->info
.labelspace
;
1840 if (flag
& LDP_INLABEL_CFG_LABEL
) {
1841 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
1843 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
1844 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
1847 retval
= MPLS_SUCCESS
;
1849 ldp_cfg_inlabel_get_end
:
1850 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1852 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
1857 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
1860 ldp_global
*g
= (ldp_global
*) handle
;
1861 ldp_inlabel
*inlabel
= NULL
;
1862 mpls_return_enum r
= MPLS_FAILURE
;
1863 mpls_bool done
= MPLS_BOOL_FALSE
;
1866 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
1868 if (i
->index
== 0) {
1871 index
= i
->index
+ 1;
1874 mpls_lock_get(g
->global_lock
); /* LOCK */
1875 while (done
== MPLS_BOOL_FALSE
) {
1876 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
1878 case MPLS_END_OF_LIST
:
1879 done
= MPLS_BOOL_TRUE
;
1888 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1890 if (r
== MPLS_SUCCESS
) {
1891 i
->index
= inlabel
->index
;
1893 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
1894 return ldp_cfg_inlabel_get(g
, i
, flag
);
1897 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
1902 /******************* OUT LABEL **********************/
1904 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
1907 ldp_global
*global
= (ldp_global
*) handle
;
1908 ldp_outlabel
*outlabel
= NULL
;
1909 mpls_return_enum retval
= MPLS_FAILURE
;
1911 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
1913 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
1915 mpls_lock_get(global
->global_lock
); /* LOCK */
1917 if (ldp_global_find_outlabel_index(global
, o
->index
,
1918 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
1920 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
1921 if (outlabel
->nh
.type
& MPLS_NH_IP
) {
1922 o
->addr_index
= (outlabel
->nh
.addr
) ? (outlabel
->nh
.addr
->index
) : 0;
1923 o
->nh_type
|= MPLS_NH_IP
;
1925 if (outlabel
->nh
.type
& MPLS_NH_IF
) {
1926 o
->if_index
= (outlabel
->nh
.iff
) ? (outlabel
->nh
.iff
->index
) : 0;
1927 o
->nh_type
|= MPLS_NH_IF
;
1929 if (outlabel
->nh
.type
& MPLS_NH_OUTSEGMENT
) {
1930 o
->outlabel_index
= (outlabel
->nh
.outlabel
) ?
1931 (outlabel
->nh
.outlabel
->index
) : 0;
1932 o
->nh_type
|= MPLS_NH_OUTSEGMENT
;
1935 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
1936 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
1938 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
1939 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
1941 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
1942 o
->merge_count
= outlabel
->merge_count
;
1945 retval
= MPLS_SUCCESS
;
1947 ldp_cfg_outlabel_get_end
:
1948 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1950 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
1955 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
1956 ldp_outlabel
* o
, uint32_t flag
)
1958 ldp_global
*g
= (ldp_global
*) handle
;
1959 ldp_outlabel
*outlabel
= NULL
;
1960 mpls_return_enum r
= MPLS_FAILURE
;
1961 mpls_bool done
= MPLS_BOOL_FALSE
;
1964 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
1966 if (o
->index
== 0) {
1969 index
= o
->index
+ 1;
1972 mpls_lock_get(g
->global_lock
); /* LOCK */
1973 while (done
== MPLS_BOOL_FALSE
) {
1974 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
1976 case MPLS_END_OF_LIST
:
1977 done
= MPLS_BOOL_TRUE
;
1986 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1988 if (r
== MPLS_SUCCESS
) {
1989 o
->index
= outlabel
->index
;
1991 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
1992 return ldp_cfg_outlabel_get(g
, o
, flag
);
1995 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2000 /******************* TUNNEL **********************/
2002 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2005 ldp_global
*global
= (ldp_global
*) handle
;
2006 mpls_return_enum retval
= MPLS_FAILURE
;
2007 ldp_tunnel
*tunnel
= NULL
;
2009 MPLS_ASSERT(global
!=NULL
);
2011 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2013 mpls_lock_get(global
->global_lock
); /* LOCK */
2015 if (flag
& LDP_CFG_ADD
) {
2016 if (!(tunnel
= ldp_tunnel_create())) {
2017 goto ldp_cfg_tunnel_set_end
;
2019 _ldp_global_add_tunnel(global
, tunnel
);
2021 t
->index
= tunnel
->index
;
2023 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2027 LDP_PRINT(global
->user_data
,
2029 "ldp_cfg_tunnel_set:could not create tunnel\n");
2030 goto ldp_cfg_tunnel_set_end
;
2033 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2034 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2035 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2037 goto ldp_cfg_tunnel_set_end
;
2040 if (flag
& LDP_CFG_DEL
) {
2041 if (tunnel
->outlabel
)
2042 ldp_tunnel_del_outlabel(tunnel
);
2043 if (tunnel
->resource
)
2044 ldp_tunnel_del_resource(tunnel
);
2045 if (tunnel
->hop_list
)
2046 ldp_tunnel_del_hop_list(tunnel
);
2047 _ldp_global_del_tunnel(global
, tunnel
);
2049 retval
= MPLS_SUCCESS
;
2050 goto ldp_cfg_tunnel_set_end
;
2053 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2054 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2056 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2057 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2059 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2060 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2062 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2063 tunnel
->is_interface
= t
->is_interface
;
2065 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2066 ldp_outlabel
*outlabel
= NULL
;
2068 if (t
->outlabel_index
) {
2069 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2072 goto ldp_cfg_tunnel_set_end
;
2074 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2076 ldp_tunnel_del_outlabel(tunnel
);
2079 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2080 tunnel
->setup_prio
= t
->setup_prio
;
2082 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2083 tunnel
->hold_prio
= t
->hold_prio
;
2085 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2086 tunnel
->instance_prio
= t
->instance_prio
;
2088 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2089 tunnel
->local_protect
= t
->local_protect
;
2091 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2092 ldp_resource
*resource
= NULL
;
2094 if (t
->resource_index
) {
2095 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2098 goto ldp_cfg_tunnel_set_end
;
2100 ldp_tunnel_add_resource(tunnel
, resource
);
2102 ldp_tunnel_del_resource(tunnel
);
2105 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2106 ldp_hop_list
*hop_list
= NULL
;
2108 if (t
->hop_list_index
) {
2109 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2112 goto ldp_cfg_tunnel_set_end
;
2114 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2116 ldp_tunnel_del_hop_list(tunnel
);
2119 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2120 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2122 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2123 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2124 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2125 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2126 goto ldp_cfg_tunnel_set_end
;
2130 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2131 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2132 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2133 goto ldp_cfg_tunnel_set_end
;
2136 LDP_PRINT(global
->user_data
,
2138 "ldp_cfg_tunnel_set: tunnel not ready\n");
2139 goto ldp_cfg_tunnel_set_end
;
2144 retval
= MPLS_SUCCESS
;
2146 ldp_cfg_tunnel_set_end
:
2148 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2150 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2155 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2158 ldp_global
*global
= (ldp_global
*) handle
;
2159 mpls_return_enum retval
= MPLS_FAILURE
;
2160 ldp_tunnel
*tunnel
= NULL
;
2162 MPLS_ASSERT(global
!=NULL
);
2164 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2166 mpls_lock_get(global
->global_lock
); /* LOCK */
2168 if (flag
& LDP_CFG_ADD
) {
2169 retval
= MPLS_SUCCESS
;
2170 goto ldp_cfg_tunnel_test_end
;
2173 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2176 goto ldp_cfg_tunnel_test_end
;
2179 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2180 ldp_resource
*resource
= NULL
;
2182 if (t
->resource_index
) {
2183 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2186 goto ldp_cfg_tunnel_test_end
;
2190 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2191 ldp_hop_list
*hop_list
= NULL
;
2193 if (t
->hop_list_index
) {
2194 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2197 goto ldp_cfg_tunnel_test_end
;
2201 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2202 ldp_outlabel
*outlabel
= NULL
;
2204 if (t
->outlabel_index
) {
2205 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2208 goto ldp_cfg_tunnel_test_end
;
2212 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2213 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2214 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2215 goto ldp_cfg_tunnel_test_end
;
2217 retval
= MPLS_SUCCESS
;
2219 ldp_cfg_tunnel_test_end
:
2221 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2223 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2228 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2231 ldp_global
*global
= (ldp_global
*) handle
;
2232 mpls_return_enum retval
= MPLS_FAILURE
;
2233 ldp_tunnel
*tunnel
= NULL
;
2235 MPLS_ASSERT(global
!=NULL
);
2237 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2239 mpls_lock_get(global
->global_lock
); /* LOCK */
2241 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2244 goto ldp_cfg_tunnel_get_end
;
2246 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2247 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2249 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2250 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2252 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2253 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2255 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2256 t
->is_interface
= tunnel
->is_interface
;
2258 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2259 if (tunnel
->outlabel
) {
2260 t
->outlabel_index
= tunnel
->outlabel
->index
;
2262 t
->outlabel_index
= 0;
2265 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2266 t
->setup_prio
= tunnel
->setup_prio
;
2268 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2269 t
->hold_prio
= tunnel
->hold_prio
;
2271 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2272 tunnel
->instance_prio
= t
->instance_prio
;
2274 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2275 tunnel
->local_protect
= t
->local_protect
;
2277 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2278 if (tunnel
->resource
) {
2279 t
->resource_index
= tunnel
->resource
->index
;
2281 t
->resource_index
= 0;
2284 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2285 if (tunnel
->hop_list
) {
2286 t
->hop_list_index
= tunnel
->hop_list
->index
;
2288 t
->hop_list_index
= 0;
2291 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2292 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2294 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2295 t
->admin_state
= tunnel
->admin_state
;
2297 retval
= MPLS_SUCCESS
;
2299 ldp_cfg_tunnel_get_end
:
2301 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2303 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2308 /******************* RESOURCE **********************/
2310 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2313 ldp_global
*global
= (ldp_global
*) handle
;
2314 mpls_return_enum retval
= MPLS_FAILURE
;
2315 ldp_resource
*resource
= NULL
;
2317 MPLS_ASSERT(global
!=NULL
);
2319 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2321 mpls_lock_get(global
->global_lock
); /* LOCK */
2323 if (flag
& LDP_CFG_ADD
) {
2324 resource
= ldp_resource_create();
2325 _ldp_global_add_resource(global
, resource
);
2327 r
->index
= resource
->index
;
2329 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2333 goto ldp_cfg_resource_set_end
;
2336 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2337 resource
->max_rate
= r
->max_rate
;
2339 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2340 resource
->mean_rate
= r
->mean_rate
;
2342 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2343 resource
->burst_size
= r
->burst_size
;
2345 retval
= MPLS_SUCCESS
;
2347 ldp_cfg_resource_set_end
:
2349 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2351 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2356 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2359 ldp_global
*global
= (ldp_global
*) handle
;
2360 mpls_return_enum retval
= MPLS_FAILURE
;
2361 ldp_resource
*resource
= NULL
;
2363 MPLS_ASSERT(global
!=NULL
);
2365 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2367 mpls_lock_get(global
->global_lock
); /* LOCK */
2369 if (flag
& LDP_CFG_ADD
) {
2370 retval
= MPLS_SUCCESS
;
2371 goto ldp_cfg_resource_test_end
;
2374 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2377 goto ldp_cfg_resource_test_end
;
2380 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2381 goto ldp_cfg_resource_test_end
;
2383 retval
= MPLS_SUCCESS
;
2385 ldp_cfg_resource_test_end
:
2387 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2389 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2394 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2397 ldp_global
*global
= (ldp_global
*) handle
;
2398 mpls_return_enum retval
= MPLS_FAILURE
;
2399 ldp_resource
*resource
= NULL
;
2401 MPLS_ASSERT(global
!=NULL
);
2403 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2405 mpls_lock_get(global
->global_lock
); /* LOCK */
2407 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2410 goto ldp_cfg_resource_get_end
;
2413 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2414 r
->max_rate
= resource
->max_rate
;
2416 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2417 r
->mean_rate
= resource
->mean_rate
;
2419 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2420 r
->burst_size
= resource
->burst_size
;
2422 retval
= MPLS_SUCCESS
;
2424 ldp_cfg_resource_get_end
:
2426 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2428 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2433 /******************* HOP **********************/
2435 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2438 ldp_global
*global
= (ldp_global
*) handle
;
2439 mpls_return_enum retval
= MPLS_FAILURE
;
2440 ldp_hop_list
*hop_list
= NULL
;
2441 ldp_hop
*hop
= NULL
;
2443 MPLS_ASSERT(global
!=NULL
);
2445 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2447 if (!h
->hop_list_index
&& !h
->index
) {
2451 mpls_lock_get(global
->global_lock
); /* LOCK */
2453 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2456 if (flag
& LDP_CFG_ADD
) {
2457 if (!(hop_list
= ldp_hop_list_create())) {
2458 goto ldp_cfg_hop_set_end
;
2460 _ldp_global_add_hop_list(global
, hop_list
);
2462 h
->hop_list_index
= hop_list
->index
;
2464 goto ldp_cfg_hop_set_end
;
2468 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2470 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2471 if (!(hop
= ldp_hop_create())) {
2472 goto ldp_cfg_hop_set_end
;
2474 hop
->index
= h
->index
;
2475 ldp_hop_list_add_hop(hop_list
, hop
);
2477 goto ldp_cfg_hop_set_end
;
2481 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2482 hop
->path_option
= h
->path_option
;
2484 if (flag
& LDP_HOP_CFG_ADDR
) {
2485 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2487 if (flag
& LDP_HOP_CFG_TYPE
) {
2488 hop
->type
= h
->type
;
2490 retval
= MPLS_SUCCESS
;
2492 ldp_cfg_hop_set_end
:
2494 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2496 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2501 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2504 ldp_global
*global
= (ldp_global
*) handle
;
2505 mpls_return_enum retval
= MPLS_FAILURE
;
2506 ldp_hop_list
*hop_list
= NULL
;
2507 ldp_hop
*hop
= NULL
;
2509 MPLS_ASSERT(global
!=NULL
);
2511 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2513 mpls_lock_get(global
->global_lock
); /* LOCK */
2515 if (flag
& LDP_CFG_ADD
) {
2516 retval
= MPLS_SUCCESS
;
2517 goto ldp_cfg_hop_test_end
;
2520 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2523 goto ldp_cfg_hop_test_end
;
2526 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2528 goto ldp_cfg_hop_test_end
;
2531 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2532 goto ldp_cfg_hop_test_end
;
2534 retval
= MPLS_SUCCESS
;
2536 ldp_cfg_hop_test_end
:
2538 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2540 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2545 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2548 ldp_global
*global
= (ldp_global
*) handle
;
2549 mpls_return_enum retval
= MPLS_FAILURE
;
2550 ldp_hop_list
*hop_list
= NULL
;
2551 ldp_hop
*hop
= NULL
;
2553 MPLS_ASSERT(global
!=NULL
);
2555 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2557 mpls_lock_get(global
->global_lock
); /* LOCK */
2559 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2562 goto ldp_cfg_hop_get_end
;
2565 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2567 goto ldp_cfg_hop_get_end
;
2570 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2571 h
->path_option
= hop
->path_option
;
2573 if (flag
& LDP_HOP_CFG_ADDR
) {
2574 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2576 if (flag
& LDP_HOP_CFG_TYPE
) {
2577 h
->type
= hop
->type
;
2579 retval
= MPLS_SUCCESS
;
2581 ldp_cfg_hop_get_end
:
2583 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2585 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");