Re-work the adding/removing of ldp_if and ldp_addr.
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blobefb0c032fe996395daf136c1292271fc73364485
2 /*
3 * Copyright (C) James R. Leu 2000
4 * jleu@mindspring.com
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
8 */
10 #include "ldp_struct.h"
11 #include "ldp_cfg.h"
12 #include "ldp_global.h"
13 #include "ldp_entity.h"
14 #include "ldp_attr.h"
15 #include "ldp_if.h"
16 #include "ldp_peer.h"
17 #include "ldp_fec.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"
23 #include "ldp_hop.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");
42 ldp_global_delete(g);
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,
49 uint32_t flag)
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;
109 #if MPLS_USE_LSR
110 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
111 g->lsr_handle = global->lsr_handle;
113 #endif
115 mpls_lock_release(global->global_lock); /* UNLOCK */
117 LDP_EXIT(global->user_data, "ldp_cfg_global_get");
119 return MPLS_SUCCESS;
122 mpls_return_enum ldp_cfg_global_test(mpls_cfg_handle handle, ldp_global * g,
123 uint32_t flag)
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");
141 return retval;
144 mpls_return_enum ldp_cfg_global_set(mpls_cfg_handle handle, ldp_global * g,
145 uint32_t flag)
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));
190 #if MPLS_USE_LSR
191 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
192 global->lsr_handle = g->lsr_handle;
194 #endif
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 ==
199 MPLS_ADMIN_ENABLE) {
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;
210 } else {
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;
217 } else {
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;
224 } else {
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;
231 } else {
232 global->hellotime_interval = g->hellotime_interval;
235 #if MPLS_USE_LSR
236 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
237 global->lsr_handle = g->lsr_handle ;
239 #endif
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");
250 return retval;
253 /******************* ENTITY **********************/
255 /* must set ldp_entity->index */
256 mpls_return_enum ldp_cfg_entity_get(mpls_cfg_handle handle, ldp_entity * e,
257 uint32_t flag)
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");
353 return retval;
356 mpls_return_enum ldp_cfg_entity_getnext(mpls_cfg_handle handle, ldp_entity * e,
357 uint32_t flag)
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;
363 int index;
365 LDP_ENTER(g->user_data, "ldp_cfg_entity_getnext");
367 if (e->index == 0) {
368 index = 1;
369 } else {
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))) {
376 case MPLS_SUCCESS:
377 case MPLS_END_OF_LIST:
378 done = MPLS_BOOL_TRUE;
379 break;
380 case MPLS_FAILURE:
381 break;
382 default:
383 MPLS_ASSERT(0);
385 index++;
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");
395 return r;
398 mpls_return_enum ldp_cfg_entity_test(mpls_cfg_handle handle, ldp_entity * e,
399 uint32_t flag)
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)) {
412 if (e == NULL)
413 goto ldp_cfg_entity_test_end;
415 ldp_global_find_entity_index(global, e->index, &entity);
416 } else {
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");
437 return retval;
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,
442 uint32_t flag)
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;
459 } else {
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) {
476 case LDP_DIRECT:
477 ldp_entity_del_if(global, entity);
478 break;
479 case LDP_INDIRECT:
480 ldp_entity_del_peer(entity);
481 break;
482 default:
483 MPLS_ASSERT(0);
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) {
495 case LDP_DIRECT:
496 ldp_entity_del_if(global, entity);
497 break;
498 case LDP_INDIRECT:
499 ldp_entity_del_peer(entity);
500 break;
501 default:
502 MPLS_ASSERT(0);
506 /* link the new sub object */
507 switch (e->entity_type) {
508 case LDP_DIRECT:
510 ldp_if *iff = NULL;
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);
522 break;
524 case LDP_INDIRECT:
526 ldp_peer *peer = NULL;
528 if (ldp_global_find_peer_index(global, e->sub_index, &peer) !=
529 MPLS_SUCCESS) {
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);
538 break;
540 default:
541 MPLS_ASSERT(0);
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;
548 } else {
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;
569 } else {
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;
577 } else {
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;
585 } else {
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;
593 } else {
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;
633 } else {
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");
651 return retval;
654 mpls_return_enum ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle,
655 ldp_entity * e)
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;
661 ldp_adj *adj = 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
669 if (!e->adj_index) {
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);
677 while (adj) {
678 if (this_one == MPLS_BOOL_TRUE) {
679 adj_next = adj;
680 break;
683 /* since the entities are sort in the list ... */
684 if (adj->index > e->adj_index) {
685 break;
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 */
694 if (adj_next) {
695 e->adj_index = adj_next->index;
696 r = MPLS_SUCCESS;
699 LDP_EXIT(g->user_data, "ldp_cfg_entity_adj_getnext");
700 return r;
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;
708 ldp_if *iff = NULL;
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;
738 ldp_cfg_if_get_end:
739 mpls_lock_release(global->global_lock); /* UNLOCK */
741 LDP_EXIT(global->user_data, "ldp_cfg_if_get");
743 return retval;
746 mpls_return_enum ldp_cfg_if_getnext(mpls_cfg_handle handle, ldp_if * i,
747 uint32_t flag)
749 ldp_global *g = (ldp_global *) handle;
750 ldp_if *iff = NULL;
751 mpls_return_enum r = MPLS_FAILURE;
752 mpls_bool done = MPLS_BOOL_FALSE;
753 int index;
755 LDP_ENTER(g->user_data, "ldp_cfg_if_getnext");
757 if (i->index == 0) {
758 index = 1;
759 } else {
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))) {
766 case MPLS_SUCCESS:
767 case MPLS_END_OF_LIST:
768 done = MPLS_BOOL_TRUE;
769 break;
770 case MPLS_FAILURE:
771 break;
772 default:
773 MPLS_ASSERT(0);
775 index++;
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");
785 return r;
788 mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i,
789 uint32_t flag)
791 ldp_global *global = (ldp_global *) handle;
792 ldp_if *iff = NULL;
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);
803 } else {
804 retval = MPLS_SUCCESS;
805 goto ldp_cfg_if_test_end;
808 if ((iff == NULL) ||
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;
818 ldp_cfg_if_test_end:
819 mpls_lock_release(global->global_lock); /* UNLOCK */
821 LDP_EXIT(global->user_data, "ldp_cfg_if_test");
823 return retval;
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;
829 ldp_if *iff = NULL;
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(global)) == NULL) {
841 goto ldp_cfg_if_set_end;
843 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==
844 MPLS_BOOL_FALSE) {
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 } else {
853 ldp_global_find_if_index(global, i->index, &iff);
856 if ((iff == NULL) ||
857 ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
858 (flag & LDP_IF_CFG_WHEN_DOWN))) goto ldp_cfg_if_set_end;
860 if (flag & LDP_CFG_DEL) {
861 if (iff->entity != NULL) {
862 goto ldp_cfg_if_set_end;
865 iff->used_by_ldp = MPLS_BOOL_FALSE;
866 MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);
868 retval = MPLS_SUCCESS;
869 goto ldp_cfg_if_set_end;
871 if (flag & LDP_IF_CFG_INDEX) {
872 iff->index = i->index;
874 if (flag & LDP_IF_CFG_LABEL_SPACE) {
875 iff->label_space = i->label_space;
877 global->configuration_sequence_number++;
879 retval = MPLS_SUCCESS;
881 ldp_cfg_if_set_end:
882 mpls_lock_release(global->global_lock); /* UNLOCK */
884 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
886 return retval;
889 /******************* ATTR **********************/
891 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
892 uint32_t flag)
894 ldp_global *global = (ldp_global *) handle;
895 ldp_attr *attr = NULL;
896 mpls_return_enum retval = MPLS_FAILURE;
898 MPLS_ASSERT(global !=NULL && a != NULL);
900 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
902 mpls_lock_get(global->global_lock); /* LOCK */
904 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
905 goto ldp_cfg_attr_get_end;
907 if (flag & LDP_ATTR_CFG_STATE) {
908 a->state = attr->state;
910 if (flag & LDP_ATTR_CFG_FEC) {
911 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
913 if (flag & LDP_ATTR_CFG_LABEL) {
914 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
916 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
917 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
919 if (flag & LDP_ATTR_CFG_PATH) {
920 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
922 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
923 a->session_index = (attr->session) ? (attr->session->index) : 0;
925 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
926 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
928 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
929 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
931 if (flag & LDP_ATTR_CFG_INGRESS) {
932 a->ingress = attr->ingress;
934 retval = MPLS_SUCCESS;
936 ldp_cfg_attr_get_end:
937 mpls_lock_release(global->global_lock); /* UNLOCK */
939 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
941 return retval;
944 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
945 uint32_t flag)
947 ldp_global *g = (ldp_global *) handle;
948 ldp_attr *attr = NULL;
949 mpls_return_enum r = MPLS_FAILURE;
950 mpls_bool done = MPLS_BOOL_FALSE;
951 int index;
953 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
955 if (a->index == 0) {
956 index = 1;
957 } else {
958 index = a->index + 1;
961 mpls_lock_get(g->global_lock); /* LOCK */
962 while (done == MPLS_BOOL_FALSE) {
963 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
964 case MPLS_SUCCESS:
965 case MPLS_END_OF_LIST:
966 done = MPLS_BOOL_TRUE;
967 break;
968 case MPLS_FAILURE:
969 break;
970 default:
971 MPLS_ASSERT(0);
973 index++;
975 mpls_lock_release(g->global_lock); /* UNLOCK */
977 if (r == MPLS_SUCCESS) {
978 a->index = attr->index;
979 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
980 return ldp_cfg_attr_get(g, a, flag);
982 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
983 return r;
986 /******************* PEER **********************/
988 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
989 uint32_t flag)
991 ldp_global *global = (ldp_global *) handle;
992 ldp_peer *peer = NULL;
993 mpls_return_enum retval = MPLS_FAILURE;
995 MPLS_ASSERT(global !=NULL && p != NULL);
997 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
999 mpls_lock_get(global->global_lock); /* LOCK */
1001 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
1002 goto ldp_cfg_peer_get_end;
1004 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1005 p->label_space = peer->label_space;
1007 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1008 p->target_role = peer->target_role;
1010 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1011 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1013 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1014 p->entity_index = peer->entity->index;
1016 if (flag & LDP_PEER_CFG_OPER_STATE) {
1017 p->oper_state = peer->oper_state;
1019 if (flag & LDP_PEER_CFG_PEER_NAME) {
1020 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1022 if (flag & LDP_PEER_CFG_LOCAL_SOURCE_ADDR) {
1023 memcpy(&p->local_source_address, &peer->local_source_address,
1024 sizeof(mpls_inet_addr));
1026 retval = MPLS_SUCCESS;
1028 ldp_cfg_peer_get_end:
1029 mpls_lock_release(global->global_lock); /* UNLOCK */
1031 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1033 return retval;
1036 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1037 uint32_t flag)
1039 ldp_global *g = (ldp_global *) handle;
1040 ldp_peer *peer = NULL;
1041 mpls_return_enum r = MPLS_FAILURE;
1042 mpls_bool done = MPLS_BOOL_FALSE;
1043 int index;
1045 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1047 if (p->index == 0) {
1048 index = 1;
1049 } else {
1050 index = p->index + 1;
1053 mpls_lock_get(g->global_lock); /* LOCK */
1054 while (done == MPLS_BOOL_FALSE) {
1055 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1056 case MPLS_SUCCESS:
1057 case MPLS_END_OF_LIST:
1058 done = MPLS_BOOL_TRUE;
1059 break;
1060 case MPLS_FAILURE:
1061 break;
1062 default:
1063 MPLS_ASSERT(0);
1065 index++;
1067 mpls_lock_release(g->global_lock); /* UNLOCK */
1069 if (r == MPLS_SUCCESS) {
1070 p->index = peer->index;
1071 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1072 return ldp_cfg_peer_get(g, p, flag);
1074 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1075 return r;
1078 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1079 uint32_t flag)
1081 // ldp_global* g = (ldp_global*)handle;
1082 return MPLS_SUCCESS;
1085 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1086 uint32_t flag)
1088 ldp_global *global = (ldp_global *) handle;
1089 ldp_peer *peer = NULL;
1090 mpls_return_enum retval = MPLS_FAILURE;
1092 MPLS_ASSERT(global !=NULL && p != NULL);
1094 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1096 mpls_lock_get(global->global_lock); /* LOCK */
1098 if (flag & LDP_CFG_ADD) {
1099 if ((peer = ldp_peer_create()) == NULL) {
1100 goto ldp_cfg_peer_set_end;
1102 p->index = peer->index;
1103 _ldp_global_add_peer(global, peer);
1104 } else {
1105 ldp_global_find_peer_index(global, p->index, &peer);
1108 if (peer == NULL) {
1109 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1111 goto ldp_cfg_peer_set_end;
1113 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1114 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1116 goto ldp_cfg_peer_set_end;
1119 if (flag & LDP_CFG_DEL) {
1120 if (peer->entity != NULL) {
1121 LDP_PRINT(global->user_data,
1122 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1124 goto ldp_cfg_peer_set_end;
1127 _ldp_global_del_peer(global, peer);
1129 retval = MPLS_SUCCESS;
1130 goto ldp_cfg_peer_set_end;
1132 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1133 peer->label_space = p->label_space;
1135 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1136 peer->target_role = p->target_role;
1138 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1139 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1141 if (flag & LDP_PEER_CFG_PEER_NAME) {
1142 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1144 p->peer_name);
1145 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1147 global->configuration_sequence_number++;
1149 retval = MPLS_SUCCESS;
1151 ldp_cfg_peer_set_end:
1152 mpls_lock_release(global->global_lock); /* UNLOCK */
1154 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1156 return retval;
1158 /******************* FEC **********************/
1160 mpls_return_enum ldp_cfg_fec_get(mpls_cfg_handle handle, mpls_fec * f,
1161 uint32_t flag)
1163 ldp_global *global = (ldp_global *) handle;
1164 ldp_fec *fec = NULL;
1165 mpls_return_enum retval = MPLS_FAILURE;
1167 MPLS_ASSERT(global !=NULL && f != NULL);
1169 LDP_ENTER(global->user_data, "ldp_cfg_fec_get");
1171 mpls_lock_get(global->global_lock); /* LOCK */
1173 if (flag & LDP_FEC_CFG_BY_INDEX) {
1174 ldp_global_find_fec_index(global, f->index, &fec);
1175 } else {
1176 fec = ldp_fec_find(global, f);
1178 if (!fec)
1179 goto ldp_cfg_fec_get_end;
1181 memcpy(f, &fec->info, sizeof(mpls_fec));
1182 retval = MPLS_SUCCESS;
1184 ldp_cfg_fec_get_end:
1185 mpls_lock_release(global->global_lock); /* UNLOCK */
1187 LDP_EXIT(global->user_data, "ldp_cfg_fec_get");
1189 return retval;
1192 mpls_return_enum ldp_cfg_fec_getnext(mpls_cfg_handle handle, mpls_fec * f,
1193 uint32_t flag)
1195 ldp_global *g = (ldp_global *) handle;
1196 ldp_fec *fec = NULL;
1197 mpls_return_enum r = MPLS_FAILURE;
1198 mpls_bool done = MPLS_BOOL_FALSE;
1199 int index;
1201 LDP_ENTER(g->user_data, "ldp_cfg_fec_getnext");
1203 if (f->index == 0) {
1204 index = 1;
1205 } else {
1206 index = f->index + 1;
1209 mpls_lock_get(g->global_lock); /* LOCK */
1210 while (done == MPLS_BOOL_FALSE) {
1211 switch ((r = ldp_global_find_fec_index(g, index, &fec))) {
1212 case MPLS_SUCCESS:
1213 case MPLS_END_OF_LIST:
1214 done = MPLS_BOOL_TRUE;
1215 break;
1216 case MPLS_FAILURE:
1217 break;
1218 default:
1219 MPLS_ASSERT(0);
1221 index++;
1223 mpls_lock_release(g->global_lock); /* UNLOCK */
1225 if (r == MPLS_SUCCESS) {
1226 f->index = fec->index;
1227 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1228 return ldp_cfg_fec_get(g, f, flag);
1230 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1231 return r;
1234 mpls_return_enum ldp_cfg_fec_test(mpls_cfg_handle handle, mpls_fec * f,
1235 uint32_t flag)
1237 // ldp_global* g = (ldp_global*)handle;
1238 return MPLS_SUCCESS;
1241 mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f,
1242 uint32_t flag)
1244 ldp_global *global = (ldp_global *) handle;
1245 ldp_fec *fec = NULL;
1246 mpls_return_enum retval = MPLS_FAILURE;
1248 MPLS_ASSERT(global !=NULL && f != NULL);
1250 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1252 mpls_lock_get(global->global_lock); /* LOCK */
1254 if (flag & LDP_CFG_ADD) {
1255 if (ldp_fec_find(global, f) || (fec = ldp_fec_create()) == NULL) {
1256 goto ldp_cfg_fec_set_end;
1258 f->index = fec->index;
1259 mpls_fec2ldp_fec(f, fec);
1260 _ldp_global_add_fec(global, fec);
1261 ldp_fec_insert2(global, fec);
1262 } else {
1263 if (flag & LDP_FEC_CFG_BY_INDEX) {
1264 ldp_global_find_fec_index(global, f->index, &fec);
1265 } else {
1266 fec = ldp_fec_find(global, f);
1270 if (fec == NULL) {
1271 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1272 goto ldp_cfg_fec_set_end;
1275 if (flag & LDP_CFG_DEL) {
1276 ldp_fec_remove(global,&fec->info);
1277 _ldp_global_del_fec(global, fec);
1280 retval = MPLS_SUCCESS;
1282 ldp_cfg_fec_set_end:
1283 mpls_lock_release(global->global_lock); /* UNLOCK */
1285 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1287 return retval;
1290 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1291 mpls_nexthop *n, uint32_t flag)
1293 ldp_global *global = (ldp_global *) handle;
1294 ldp_fec *fec = NULL;
1295 ldp_nexthop *nh = NULL;
1296 mpls_return_enum retval = MPLS_FAILURE;
1298 MPLS_ASSERT(global !=NULL && f != NULL);
1300 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1302 mpls_lock_get(global->global_lock); /* LOCK */
1304 if (flag & LDP_FEC_CFG_BY_INDEX) {
1305 ldp_global_find_fec_index(global, f->index, &fec);
1306 } else {
1307 fec = ldp_fec_find(global, f);
1309 if (!fec)
1310 goto ldp_cfg_fec_nexthop_get_end;
1312 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1313 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1314 } else {
1315 nh = ldp_fec_nexthop_find(fec, n);
1317 if (!nh)
1318 goto ldp_cfg_fec_nexthop_get_end;
1320 memcpy(n, nh, sizeof(mpls_nexthop));
1321 retval = MPLS_SUCCESS;
1323 ldp_cfg_fec_nexthop_get_end:
1324 mpls_lock_release(global->global_lock); /* UNLOCK */
1326 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1328 return retval;
1331 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1332 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1334 ldp_global *global = (ldp_global *) handle;
1335 ldp_fec *fec = NULL;
1336 ldp_nexthop *nh = NULL;
1337 mpls_return_enum r = MPLS_FAILURE;
1338 mpls_bool done = MPLS_BOOL_FALSE;
1339 int index;
1341 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1343 if (n->index == 0) {
1344 index = 1;
1345 } else {
1346 index = n->index + 1;
1349 mpls_lock_get(global->global_lock); /* LOCK */
1351 if (flag & LDP_FEC_CFG_BY_INDEX) {
1352 ldp_global_find_fec_index(global, f->index, &fec);
1353 } else {
1354 fec = ldp_fec_find(global, f);
1356 if (!fec)
1357 goto ldp_cfg_fec_nexthop_getnext_end;
1359 while (done == MPLS_BOOL_FALSE) {
1360 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1361 case MPLS_SUCCESS:
1362 case MPLS_END_OF_LIST:
1363 done = MPLS_BOOL_TRUE;
1364 break;
1365 case MPLS_FAILURE:
1366 break;
1367 default:
1368 MPLS_ASSERT(0);
1370 index++;
1372 mpls_lock_release(global->global_lock); /* UNLOCK */
1374 if (r == MPLS_SUCCESS) {
1375 n->index = nh->index;
1376 LDP_EXIT(global->user_data, "ldp_cfg_fec_getnext");
1377 return ldp_cfg_fec_nexthop_get(global, f, n,
1378 flag & ~LDP_FEC_NEXTHOP_CFG_BY_INDEX);
1381 ldp_cfg_fec_nexthop_getnext_end:
1383 LDP_EXIT(global->user_data, "ldp_cfg_fec_getnext");
1384 return r;
1387 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1388 mpls_nexthop *n, uint32_t flag)
1390 // ldp_global* g = (ldp_global*)handle;
1391 return MPLS_SUCCESS;
1394 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1395 mpls_nexthop *n, uint32_t flag)
1397 ldp_global *global = (ldp_global *) handle;
1398 ldp_fec *fec = NULL;
1399 ldp_nexthop *nh = NULL;
1400 mpls_return_enum retval = MPLS_FAILURE;
1402 MPLS_ASSERT(global !=NULL && f != NULL && n != NULL);
1404 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1406 mpls_lock_get(global->global_lock); /* LOCK */
1408 if (flag & LDP_FEC_CFG_BY_INDEX) {
1409 ldp_global_find_fec_index(global, f->index, &fec);
1410 } else {
1411 fec = ldp_fec_find(global, f);
1413 if (!fec)
1414 goto ldp_cfg_fec_nexthop_set_end;
1416 if (flag & LDP_CFG_ADD) {
1417 if (ldp_fec_nexthop_find(fec, n) || (nh = ldp_nexthop_create()) == NULL) {
1418 goto ldp_cfg_fec_nexthop_set_end;
1420 n->index = nh->index;
1421 mpls_nexthop2ldp_nexthop(n, nh);
1422 _ldp_global_add_nexthop(global, nh);
1423 ldp_fec_add_nexthop(global, fec, nh);
1424 } else {
1425 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1426 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1427 } else {
1428 nh = ldp_fec_nexthop_find(fec, n);
1432 if (nh == NULL) {
1433 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1434 goto ldp_cfg_fec_nexthop_set_end;
1437 if (flag & LDP_CFG_DEL) {
1438 ldp_fec_del_nexthop(global, fec,nh);
1439 _ldp_global_del_nexthop(global, nh);
1442 retval = MPLS_SUCCESS;
1444 ldp_cfg_fec_nexthop_set_end:
1445 mpls_lock_release(global->global_lock); /* UNLOCK */
1447 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1449 return retval;
1452 /******************* ADJACENCY **********************/
1454 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1455 uint32_t flag)
1457 ldp_global *global = (ldp_global *) handle;
1458 ldp_adj *adj = NULL;
1459 mpls_return_enum retval = MPLS_FAILURE;
1461 MPLS_ASSERT(global !=NULL && a != NULL);
1463 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1465 mpls_lock_get(global->global_lock); /* LOCK */
1467 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1468 goto ldp_cfg_adj_get_end;
1470 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1471 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1472 sizeof(mpls_inet_addr));
1474 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1475 memcpy(&a->remote_source_address, &adj->remote_source_address,
1476 sizeof(mpls_inet_addr));
1478 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1479 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1480 sizeof(mpls_inet_addr));
1482 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1483 a->remote_csn = adj->remote_csn;
1485 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1486 a->remote_label_space = adj->remote_label_space;
1488 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1489 a->remote_hellotime = adj->remote_hellotime;
1491 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1492 a->entity_index = adj->entity ? adj->entity->index : 0;
1494 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1495 a->session_index = (adj->session) ? (adj->session->index) : 0;
1497 if (flag & LDP_ADJ_CFG_ROLE) {
1498 a->role = adj->role;
1500 retval = MPLS_SUCCESS;
1502 ldp_cfg_adj_get_end:
1504 mpls_lock_release(global->global_lock); /* UNLOCK */
1506 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1508 return retval;
1511 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1512 uint32_t flag)
1514 ldp_global *g = (ldp_global *) handle;
1515 ldp_adj *adj = NULL;
1516 mpls_return_enum r = MPLS_FAILURE;
1517 mpls_bool done = MPLS_BOOL_FALSE;
1518 int index;
1520 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1522 if (a->index == 0) {
1523 index = 1;
1524 } else {
1525 index = a->index + 1;
1528 mpls_lock_get(g->global_lock); /* LOCK */
1529 while (done == MPLS_BOOL_FALSE) {
1530 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1531 case MPLS_SUCCESS:
1532 case MPLS_END_OF_LIST:
1533 done = MPLS_BOOL_TRUE;
1534 break;
1535 case MPLS_FAILURE:
1536 break;
1537 default:
1538 MPLS_ASSERT(0);
1540 index++;
1542 mpls_lock_release(g->global_lock); /* UNLOCK */
1544 if (r == MPLS_SUCCESS) {
1545 a->index = adj->index;
1546 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1547 return ldp_cfg_adj_get(g, a, flag);
1549 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1550 return r;
1553 /******************* SESSION **********************/
1555 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1556 uint32_t flag)
1558 ldp_global *global = (ldp_global *) handle;
1559 ldp_session *session = NULL;
1560 mpls_return_enum retval = MPLS_FAILURE;
1562 MPLS_ASSERT(global !=NULL && s != NULL);
1564 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1566 mpls_lock_get(global->global_lock); /* LOCK */
1568 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1569 goto ldp_cfg_session_get_end;
1571 if (flag & LDP_SESSION_CFG_STATE) {
1572 s->state = session->state;
1574 if (flag & LDP_SESSION_CFG_OPER_UP) {
1575 s->oper_up = session->oper_up;
1577 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1578 s->oper_max_pdu = session->oper_max_pdu;
1580 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1581 s->oper_keepalive = session->oper_keepalive;
1583 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1584 s->oper_path_vector_limit = session->oper_path_vector_limit;
1586 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1587 s->oper_distribution_mode = session->oper_distribution_mode;
1589 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1590 s->oper_loop_detection = session->oper_loop_detection;
1592 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1593 s->remote_max_pdu = session->remote_max_pdu;
1595 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1596 s->remote_keepalive = session->remote_keepalive;
1598 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1599 s->remote_path_vector_limit = session->remote_path_vector_limit;
1601 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1602 s->remote_distribution_mode = session->remote_distribution_mode;
1604 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1605 s->remote_loop_detection = session->remote_loop_detection;
1607 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1608 s->remote_dest.addr.type = session->remote_dest.addr.type;
1609 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1611 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1612 s->remote_dest.port = session->remote_dest.port;
1614 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1615 s->no_label_resource_sent = session->no_label_resource_sent;
1617 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1618 s->no_label_resource_recv = session->no_label_resource_recv;
1620 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1621 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1622 s->adj_index = a ? a->index : 0;
1624 if (flag & LDP_SESSION_CFG_MESG_TX) {
1625 s->mesg_tx = session->mesg_tx;
1627 if (flag & LDP_SESSION_CFG_MESG_RX) {
1628 s->mesg_rx = session->mesg_rx;
1630 retval = MPLS_SUCCESS;
1632 ldp_cfg_session_get_end:
1633 mpls_lock_release(global->global_lock); /* UNLOCK */
1635 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1637 return retval;
1640 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1641 uint32_t flag)
1643 ldp_global *g = (ldp_global *) handle;
1644 ldp_session *ses = NULL;
1645 mpls_return_enum r = MPLS_FAILURE;
1646 mpls_bool done = MPLS_BOOL_FALSE;
1647 int index;
1649 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1651 if (s->index == 0) {
1652 index = 1;
1653 } else {
1654 index = s->index + 1;
1657 mpls_lock_get(g->global_lock); /* LOCK */
1658 while (done == MPLS_BOOL_FALSE) {
1659 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1660 case MPLS_SUCCESS:
1661 case MPLS_END_OF_LIST:
1662 done = MPLS_BOOL_TRUE;
1663 break;
1664 case MPLS_FAILURE:
1665 break;
1666 default:
1667 MPLS_ASSERT(0);
1669 index++;
1671 mpls_lock_release(g->global_lock); /* UNLOCK */
1673 if (r == MPLS_SUCCESS) {
1674 s->index = ses->index;
1676 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1677 return ldp_cfg_session_get(g, s, flag);
1680 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1682 return r;
1685 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1686 ldp_session * s)
1688 ldp_global *g = (ldp_global *) handle;
1689 mpls_bool this_one = MPLS_BOOL_FALSE;
1690 mpls_return_enum r = MPLS_FAILURE;
1691 ldp_adj *adj_next = NULL;
1692 ldp_adj *adj = NULL;
1693 ldp_session *session = NULL;
1695 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
1697 /* if an adj_index of zero is sent, get the index of
1698 * the first adj in the list
1700 if (!s->adj_index) {
1701 this_one = MPLS_BOOL_TRUE;
1704 mpls_lock_get(g->global_lock); /* LOCK */
1706 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
1707 adj = MPLS_LIST_HEAD(&session->adj_root);
1708 while (adj) {
1709 if (this_one == MPLS_BOOL_TRUE) {
1710 adj_next = adj;
1711 break;
1714 /* since the entities are sort in the list ... */
1715 if (adj->index > s->adj_index) {
1716 break;
1717 } else if (adj->index == s->adj_index) {
1718 this_one = MPLS_BOOL_TRUE;
1720 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
1723 mpls_lock_release(g->global_lock); /* UNLOCK */
1725 if (adj_next) {
1726 s->adj_index = adj_next->index;
1727 r = MPLS_SUCCESS;
1730 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
1731 return r;
1734 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
1735 ldp_session * s, ldp_addr * a, uint32_t flag)
1737 ldp_global *global = (ldp_global *) handle;
1738 ldp_session *session = NULL;
1739 ldp_addr *addr = NULL;
1740 mpls_return_enum retval = MPLS_FAILURE;
1742 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
1744 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
1746 mpls_lock_get(global->global_lock); /* LOCK */
1748 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1749 goto ldp_cfg_session_raddr_get_end;
1751 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
1752 goto ldp_cfg_session_raddr_get_end;
1754 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
1755 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
1757 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
1758 a->index = addr->index;
1760 retval = MPLS_SUCCESS;
1762 ldp_cfg_session_raddr_get_end:
1763 mpls_lock_release(global->global_lock); /* UNLOCK */
1765 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
1767 return retval;
1770 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
1771 ldp_session * s, ldp_addr * a, uint32_t flag)
1773 ldp_global *g = (ldp_global *) handle;
1774 ldp_addr *addr = NULL;
1775 mpls_return_enum r = MPLS_FAILURE;
1776 mpls_bool done = MPLS_BOOL_FALSE;
1777 ldp_session *sp = NULL;
1778 int index;
1780 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
1782 if (a->index == 0) {
1783 index = 1;
1784 } else {
1785 index = a->index + 1;
1788 r = ldp_global_find_session_index(g, s->index, &sp);
1789 if (r != MPLS_SUCCESS) {
1790 return r;
1793 mpls_lock_get(g->global_lock); /* LOCK */
1794 while (done == MPLS_BOOL_FALSE) {
1795 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
1796 case MPLS_SUCCESS:
1797 case MPLS_END_OF_LIST:
1798 done = MPLS_BOOL_TRUE;
1799 break;
1800 case MPLS_FAILURE:
1801 break;
1802 default:
1803 MPLS_ASSERT(0);
1805 index++;
1807 mpls_lock_release(g->global_lock); /* UNLOCK */
1809 if (r == MPLS_SUCCESS) {
1810 a->index = addr->index;
1811 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
1814 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1815 return r;
1818 /******************* IN LABEL **********************/
1820 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
1821 uint32_t flag)
1823 ldp_global *global = (ldp_global *) handle;
1824 ldp_inlabel *inlabel = NULL;
1825 mpls_return_enum retval = MPLS_FAILURE;
1827 MPLS_ASSERT(global !=NULL && i != NULL);
1829 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
1831 mpls_lock_get(global->global_lock); /* LOCK */
1833 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
1834 goto ldp_cfg_inlabel_get_end;
1836 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
1837 i->info.labelspace = inlabel->info.labelspace;
1839 if (flag & LDP_INLABEL_CFG_LABEL) {
1840 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
1842 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
1843 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
1846 retval = MPLS_SUCCESS;
1848 ldp_cfg_inlabel_get_end:
1849 mpls_lock_release(global->global_lock); /* UNLOCK */
1851 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
1853 return retval;
1856 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
1857 uint32_t flag)
1859 ldp_global *g = (ldp_global *) handle;
1860 ldp_inlabel *inlabel = NULL;
1861 mpls_return_enum r = MPLS_FAILURE;
1862 mpls_bool done = MPLS_BOOL_FALSE;
1863 int index;
1865 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
1867 if (i->index == 0) {
1868 index = 1;
1869 } else {
1870 index = i->index + 1;
1873 mpls_lock_get(g->global_lock); /* LOCK */
1874 while (done == MPLS_BOOL_FALSE) {
1875 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
1876 case MPLS_SUCCESS:
1877 case MPLS_END_OF_LIST:
1878 done = MPLS_BOOL_TRUE;
1879 break;
1880 case MPLS_FAILURE:
1881 break;
1882 default:
1883 MPLS_ASSERT(0);
1885 index++;
1887 mpls_lock_release(g->global_lock); /* UNLOCK */
1889 if (r == MPLS_SUCCESS) {
1890 i->index = inlabel->index;
1892 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
1893 return ldp_cfg_inlabel_get(g, i, flag);
1896 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
1898 return r;
1901 /******************* OUT LABEL **********************/
1903 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
1904 uint32_t flag)
1906 ldp_global *global = (ldp_global *) handle;
1907 ldp_outlabel *outlabel = NULL;
1908 mpls_return_enum retval = MPLS_FAILURE;
1910 MPLS_ASSERT(global !=NULL && o != NULL);
1912 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
1914 mpls_lock_get(global->global_lock); /* LOCK */
1916 if (ldp_global_find_outlabel_index(global, o->index,
1917 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
1919 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
1920 if (outlabel->nh) {
1921 o->nh_index = outlabel->nh->index;
1922 } else {
1923 o->nh_index = 0;
1926 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
1927 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
1929 if (flag & LDP_OUTLABEL_CFG_LABEL) {
1930 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
1932 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
1933 o->merge_count = outlabel->merge_count;
1936 retval = MPLS_SUCCESS;
1938 ldp_cfg_outlabel_get_end:
1939 mpls_lock_release(global->global_lock); /* UNLOCK */
1941 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
1943 return retval;
1946 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
1947 ldp_outlabel * o, uint32_t flag)
1949 ldp_global *g = (ldp_global *) handle;
1950 ldp_outlabel *outlabel = NULL;
1951 mpls_return_enum r = MPLS_FAILURE;
1952 mpls_bool done = MPLS_BOOL_FALSE;
1953 int index;
1955 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
1957 if (o->index == 0) {
1958 index = 1;
1959 } else {
1960 index = o->index + 1;
1963 mpls_lock_get(g->global_lock); /* LOCK */
1964 while (done == MPLS_BOOL_FALSE) {
1965 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
1966 case MPLS_SUCCESS:
1967 case MPLS_END_OF_LIST:
1968 done = MPLS_BOOL_TRUE;
1969 break;
1970 case MPLS_FAILURE:
1971 break;
1972 default:
1973 MPLS_ASSERT(0);
1975 index++;
1977 mpls_lock_release(g->global_lock); /* UNLOCK */
1979 if (r == MPLS_SUCCESS) {
1980 o->index = outlabel->index;
1982 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
1983 return ldp_cfg_outlabel_get(g, o, flag);
1986 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
1988 return r;
1991 /******************* TUNNEL **********************/
1993 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
1994 uint32_t flag)
1996 ldp_global *global = (ldp_global *) handle;
1997 mpls_return_enum retval = MPLS_FAILURE;
1998 ldp_tunnel *tunnel = NULL;
2000 MPLS_ASSERT(global !=NULL);
2002 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2004 mpls_lock_get(global->global_lock); /* LOCK */
2006 if (flag & LDP_CFG_ADD) {
2007 if (!(tunnel = ldp_tunnel_create())) {
2008 goto ldp_cfg_tunnel_set_end;
2010 _ldp_global_add_tunnel(global, tunnel);
2012 t->index = tunnel->index;
2013 } else {
2014 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2017 if (!tunnel) {
2018 LDP_PRINT(global->user_data,
2020 "ldp_cfg_tunnel_set:could not create tunnel\n");
2021 goto ldp_cfg_tunnel_set_end;
2024 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2025 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2026 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2028 goto ldp_cfg_tunnel_set_end;
2031 if (flag & LDP_CFG_DEL) {
2032 if (tunnel->outlabel)
2033 ldp_tunnel_del_outlabel(tunnel);
2034 if (tunnel->resource)
2035 ldp_tunnel_del_resource(tunnel);
2036 if (tunnel->hop_list)
2037 ldp_tunnel_del_hop_list(tunnel);
2038 _ldp_global_del_tunnel(global, tunnel);
2040 retval = MPLS_SUCCESS;
2041 goto ldp_cfg_tunnel_set_end;
2044 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2045 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2047 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2048 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2050 if (flag & LDP_TUNNEL_CFG_NAME) {
2051 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2053 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2054 tunnel->is_interface = t->is_interface;
2056 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2057 ldp_outlabel *outlabel = NULL;
2059 if (t->outlabel_index) {
2060 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2062 if (!outlabel) {
2063 goto ldp_cfg_tunnel_set_end;
2065 ldp_tunnel_add_outlabel(tunnel, outlabel);
2066 } else {
2067 ldp_tunnel_del_outlabel(tunnel);
2070 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2071 tunnel->setup_prio = t->setup_prio;
2073 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2074 tunnel->hold_prio = t->hold_prio;
2076 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2077 tunnel->instance_prio = t->instance_prio;
2079 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2080 tunnel->local_protect = t->local_protect;
2082 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2083 ldp_resource *resource = NULL;
2085 if (t->resource_index) {
2086 ldp_global_find_resource_index(global, t->resource_index, &resource);
2088 if (!resource) {
2089 goto ldp_cfg_tunnel_set_end;
2091 ldp_tunnel_add_resource(tunnel, resource);
2092 } else {
2093 ldp_tunnel_del_resource(tunnel);
2096 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2097 ldp_hop_list *hop_list = NULL;
2099 if (t->hop_list_index) {
2100 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2102 if (!hop_list) {
2103 goto ldp_cfg_tunnel_set_end;
2105 ldp_tunnel_add_hop_list(tunnel, hop_list);
2106 } else {
2107 ldp_tunnel_del_hop_list(tunnel);
2110 if (flag & LDP_TUNNEL_CFG_FEC) {
2111 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2113 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2114 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2115 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2116 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2117 goto ldp_cfg_tunnel_set_end;
2120 } else {
2121 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2122 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2123 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2124 goto ldp_cfg_tunnel_set_end;
2126 } else {
2127 LDP_PRINT(global->user_data,
2129 "ldp_cfg_tunnel_set: tunnel not ready\n");
2130 goto ldp_cfg_tunnel_set_end;
2135 retval = MPLS_SUCCESS;
2137 ldp_cfg_tunnel_set_end:
2139 mpls_lock_release(global->global_lock); /* UNLOCK */
2141 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2143 return retval;
2146 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2147 uint32_t flag)
2149 ldp_global *global = (ldp_global *) handle;
2150 mpls_return_enum retval = MPLS_FAILURE;
2151 ldp_tunnel *tunnel = NULL;
2153 MPLS_ASSERT(global !=NULL);
2155 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2157 mpls_lock_get(global->global_lock); /* LOCK */
2159 if (flag & LDP_CFG_ADD) {
2160 retval = MPLS_SUCCESS;
2161 goto ldp_cfg_tunnel_test_end;
2164 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2166 if (!tunnel) {
2167 goto ldp_cfg_tunnel_test_end;
2170 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2171 ldp_resource *resource = NULL;
2173 if (t->resource_index) {
2174 ldp_global_find_resource_index(global, t->resource_index, &resource);
2176 if (!resource) {
2177 goto ldp_cfg_tunnel_test_end;
2181 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2182 ldp_hop_list *hop_list = NULL;
2184 if (t->hop_list_index) {
2185 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2187 if (!hop_list) {
2188 goto ldp_cfg_tunnel_test_end;
2192 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2193 ldp_outlabel *outlabel = NULL;
2195 if (t->outlabel_index) {
2196 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2198 if (!outlabel) {
2199 goto ldp_cfg_tunnel_test_end;
2203 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2204 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2205 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2206 goto ldp_cfg_tunnel_test_end;
2208 retval = MPLS_SUCCESS;
2210 ldp_cfg_tunnel_test_end:
2212 mpls_lock_release(global->global_lock); /* UNLOCK */
2214 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2216 return retval;
2219 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2220 uint32_t flag)
2222 ldp_global *global = (ldp_global *) handle;
2223 mpls_return_enum retval = MPLS_FAILURE;
2224 ldp_tunnel *tunnel = NULL;
2226 MPLS_ASSERT(global !=NULL);
2228 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2230 mpls_lock_get(global->global_lock); /* LOCK */
2232 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2234 if (!tunnel) {
2235 goto ldp_cfg_tunnel_get_end;
2237 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2238 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2240 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2241 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2243 if (flag & LDP_TUNNEL_CFG_NAME) {
2244 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2246 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2247 t->is_interface = tunnel->is_interface;
2249 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2250 if (tunnel->outlabel) {
2251 t->outlabel_index = tunnel->outlabel->index;
2252 } else {
2253 t->outlabel_index = 0;
2256 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2257 t->setup_prio = tunnel->setup_prio;
2259 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2260 t->hold_prio = tunnel->hold_prio;
2262 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2263 tunnel->instance_prio = t->instance_prio;
2265 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2266 tunnel->local_protect = t->local_protect;
2268 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2269 if (tunnel->resource) {
2270 t->resource_index = tunnel->resource->index;
2271 } else {
2272 t->resource_index = 0;
2275 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2276 if (tunnel->hop_list) {
2277 t->hop_list_index = tunnel->hop_list->index;
2278 } else {
2279 t->hop_list_index = 0;
2282 if (flag & LDP_TUNNEL_CFG_FEC) {
2283 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2285 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2286 t->admin_state = tunnel->admin_state;
2288 retval = MPLS_SUCCESS;
2290 ldp_cfg_tunnel_get_end:
2292 mpls_lock_release(global->global_lock); /* UNLOCK */
2294 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2296 return retval;
2299 /******************* RESOURCE **********************/
2301 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2302 uint32_t flag)
2304 ldp_global *global = (ldp_global *) handle;
2305 mpls_return_enum retval = MPLS_FAILURE;
2306 ldp_resource *resource = NULL;
2308 MPLS_ASSERT(global !=NULL);
2310 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2312 mpls_lock_get(global->global_lock); /* LOCK */
2314 if (flag & LDP_CFG_ADD) {
2315 resource = ldp_resource_create();
2316 _ldp_global_add_resource(global, resource);
2318 r->index = resource->index;
2319 } else {
2320 ldp_global_find_resource_index(global, r->index, &resource);
2323 if (!resource) {
2324 goto ldp_cfg_resource_set_end;
2327 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2328 resource->max_rate = r->max_rate;
2330 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2331 resource->mean_rate = r->mean_rate;
2333 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2334 resource->burst_size = r->burst_size;
2336 retval = MPLS_SUCCESS;
2338 ldp_cfg_resource_set_end:
2340 mpls_lock_release(global->global_lock); /* UNLOCK */
2342 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2344 return retval;
2347 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2348 uint32_t flag)
2350 ldp_global *global = (ldp_global *) handle;
2351 mpls_return_enum retval = MPLS_FAILURE;
2352 ldp_resource *resource = NULL;
2354 MPLS_ASSERT(global !=NULL);
2356 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2358 mpls_lock_get(global->global_lock); /* LOCK */
2360 if (flag & LDP_CFG_ADD) {
2361 retval = MPLS_SUCCESS;
2362 goto ldp_cfg_resource_test_end;
2365 ldp_global_find_resource_index(global, r->index, &resource);
2367 if (!resource) {
2368 goto ldp_cfg_resource_test_end;
2371 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2372 goto ldp_cfg_resource_test_end;
2374 retval = MPLS_SUCCESS;
2376 ldp_cfg_resource_test_end:
2378 mpls_lock_release(global->global_lock); /* UNLOCK */
2380 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2382 return retval;
2385 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2386 uint32_t flag)
2388 ldp_global *global = (ldp_global *) handle;
2389 mpls_return_enum retval = MPLS_FAILURE;
2390 ldp_resource *resource = NULL;
2392 MPLS_ASSERT(global !=NULL);
2394 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2396 mpls_lock_get(global->global_lock); /* LOCK */
2398 ldp_global_find_resource_index(global, r->index, &resource);
2400 if (!resource) {
2401 goto ldp_cfg_resource_get_end;
2404 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2405 r->max_rate = resource->max_rate;
2407 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2408 r->mean_rate = resource->mean_rate;
2410 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2411 r->burst_size = resource->burst_size;
2413 retval = MPLS_SUCCESS;
2415 ldp_cfg_resource_get_end:
2417 mpls_lock_release(global->global_lock); /* UNLOCK */
2419 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2421 return retval;
2424 /******************* HOP **********************/
2426 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2427 uint32_t flag)
2429 ldp_global *global = (ldp_global *) handle;
2430 mpls_return_enum retval = MPLS_FAILURE;
2431 ldp_hop_list *hop_list = NULL;
2432 ldp_hop *hop = NULL;
2434 MPLS_ASSERT(global !=NULL);
2436 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2438 if (!h->hop_list_index && !h->index) {
2439 return retval;
2442 mpls_lock_get(global->global_lock); /* LOCK */
2444 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2446 if (!hop_list) {
2447 if (flag & LDP_CFG_ADD) {
2448 if (!(hop_list = ldp_hop_list_create())) {
2449 goto ldp_cfg_hop_set_end;
2451 _ldp_global_add_hop_list(global, hop_list);
2453 h->hop_list_index = hop_list->index;
2454 } else {
2455 goto ldp_cfg_hop_set_end;
2459 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2460 if (!hop) {
2461 if (h->index && (flag & LDP_CFG_ADD)) {
2462 if (!(hop = ldp_hop_create())) {
2463 goto ldp_cfg_hop_set_end;
2465 hop->index = h->index;
2466 ldp_hop_list_add_hop(hop_list, hop);
2467 } else {
2468 goto ldp_cfg_hop_set_end;
2472 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2473 hop->path_option = h->path_option;
2475 if (flag & LDP_HOP_CFG_ADDR) {
2476 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2478 if (flag & LDP_HOP_CFG_TYPE) {
2479 hop->type = h->type;
2481 retval = MPLS_SUCCESS;
2483 ldp_cfg_hop_set_end:
2485 mpls_lock_release(global->global_lock); /* UNLOCK */
2487 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2489 return retval;
2492 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2493 uint32_t flag)
2495 ldp_global *global = (ldp_global *) handle;
2496 mpls_return_enum retval = MPLS_FAILURE;
2497 ldp_hop_list *hop_list = NULL;
2498 ldp_hop *hop = NULL;
2500 MPLS_ASSERT(global !=NULL);
2502 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2504 mpls_lock_get(global->global_lock); /* LOCK */
2506 if (flag & LDP_CFG_ADD) {
2507 retval = MPLS_SUCCESS;
2508 goto ldp_cfg_hop_test_end;
2511 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2513 if (!hop_list) {
2514 goto ldp_cfg_hop_test_end;
2517 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2518 if (!hop) {
2519 goto ldp_cfg_hop_test_end;
2522 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2523 goto ldp_cfg_hop_test_end;
2525 retval = MPLS_SUCCESS;
2527 ldp_cfg_hop_test_end:
2529 mpls_lock_release(global->global_lock); /* UNLOCK */
2531 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2533 return retval;
2536 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2537 uint32_t flag)
2539 ldp_global *global = (ldp_global *) handle;
2540 mpls_return_enum retval = MPLS_FAILURE;
2541 ldp_hop_list *hop_list = NULL;
2542 ldp_hop *hop = NULL;
2544 MPLS_ASSERT(global !=NULL);
2546 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2548 mpls_lock_get(global->global_lock); /* LOCK */
2550 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2552 if (!hop_list) {
2553 goto ldp_cfg_hop_get_end;
2556 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2557 if (!hop) {
2558 goto ldp_cfg_hop_get_end;
2561 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2562 h->path_option = hop->path_option;
2564 if (flag & LDP_HOP_CFG_ADDR) {
2565 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2567 if (flag & LDP_HOP_CFG_TYPE) {
2568 h->type = hop->type;
2570 retval = MPLS_SUCCESS;
2572 ldp_cfg_hop_get_end:
2574 mpls_lock_release(global->global_lock); /* UNLOCK */
2576 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2578 return retval;