FECs are now inserted in the tree upon creation
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blobaf7d6a7a5761cc4b88a2a3c2ac49100c01732f44
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_addr.h"
19 #include "ldp_nexthop.h"
20 #include "ldp_tunnel.h"
21 #include "ldp_resource.h"
22 #include "mpls_ifmgr_impl.h"
23 #include "ldp_label_mapping.h"
24 #include "ldp_hop.h"
25 #include "ldp_hop_list.h"
26 #include "mpls_lock_impl.h"
27 #include "mpls_trace_impl.h"
28 #include "mpls_tree_impl.h"
30 mpls_cfg_handle ldp_cfg_open(mpls_instance_handle data)
32 ldp_global *g = ldp_global_create(data);
34 LDP_ENTER(data, "ldp_cfg_open");
35 LDP_EXIT(data, "ldp_cfg_open");
37 return (mpls_cfg_handle) g;
40 void ldp_cfg_close(mpls_cfg_handle g)
42 LDP_ENTER((mpls_instance_handle) g->user_data, "ldp_cfg_close");
43 ldp_global_delete(g);
44 LDP_EXIT((mpls_instance_handle) g->user_data, "ldp_cfg_close");
47 /******************* GLOBAL **********************/
49 mpls_return_enum ldp_cfg_global_get(mpls_cfg_handle handle, ldp_global * g,
50 uint32_t flag)
52 ldp_global *global = (ldp_global *) handle;
54 MPLS_ASSERT(global !=NULL);
56 LDP_ENTER(global->user_data, "ldp_cfg_global_get");
58 mpls_lock_get(global->global_lock); /* LOCK */
60 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
61 memcpy(&(g->lsr_identifier), &(global->lsr_identifier),
62 sizeof(mpls_inet_addr));
64 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
65 g->admin_state = global->admin_state;
67 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
68 g->lsp_control_mode = global->lsp_control_mode;
70 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
71 g->label_retention_mode = global->label_retention_mode;
73 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
74 g->lsp_repair_mode = global->lsp_repair_mode;
76 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
77 g->propagate_release = global->propagate_release;
79 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
80 g->label_merge = global->label_merge;
82 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
83 g->loop_detection_mode = global->loop_detection_mode;
85 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
86 g->ttl_less_domain = global->ttl_less_domain;
88 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
89 g->local_tcp_port = global->local_tcp_port;
91 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
92 g->local_udp_port = global->local_udp_port;
94 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
95 memcpy(&(g->transport_address), &(global->transport_address),
96 sizeof(mpls_inet_addr));
98 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
99 g->keepalive_timer = global->keepalive_timer;
101 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
102 g->keepalive_interval = global->keepalive_interval;
104 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
105 g->hellotime_timer = global->hellotime_timer;
107 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
108 g->hellotime_interval = global->hellotime_interval;
110 #if MPLS_USE_LSR
111 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
112 g->lsr_handle = global->lsr_handle;
114 #endif
116 mpls_lock_release(global->global_lock); /* UNLOCK */
118 LDP_EXIT(global->user_data, "ldp_cfg_global_get");
120 return MPLS_SUCCESS;
123 mpls_return_enum ldp_cfg_global_test(mpls_cfg_handle handle, ldp_global * g,
124 uint32_t flag)
126 ldp_global *global = (ldp_global *) handle;
127 mpls_return_enum retval = MPLS_SUCCESS;
129 MPLS_ASSERT(global !=NULL);
131 LDP_ENTER(global->user_data, "ldp_cfg_global_test");
133 mpls_lock_get(global->global_lock); /* LOCK */
135 if (global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN))
136 retval = MPLS_FAILURE;
138 mpls_lock_release(global->global_lock); /* UNLOCK */
140 LDP_EXIT(global->user_data, "ldp_cfg_global_test");
142 return retval;
145 mpls_return_enum ldp_cfg_global_set(mpls_cfg_handle handle, ldp_global * g,
146 uint32_t flag)
148 ldp_global *global = (ldp_global *) handle;
149 mpls_return_enum retval = MPLS_FAILURE;
151 MPLS_ASSERT(global !=NULL);
153 LDP_ENTER(global->user_data, "ldp_cfg_global_set");
155 mpls_lock_get(global->global_lock); /* LOCK */
157 if ((global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN)))
158 goto ldp_cfg_global_set_end;
160 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
161 global->lsp_control_mode = g->lsp_control_mode;
163 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
164 global->label_retention_mode = g->label_retention_mode;
166 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
167 global->lsp_repair_mode = g->lsp_repair_mode;
169 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
170 global->propagate_release = g->propagate_release;
172 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
173 global->label_merge = g->label_merge;
175 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
176 global->loop_detection_mode = g->loop_detection_mode;
178 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
179 global->ttl_less_domain = g->ttl_less_domain;
181 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
182 global->local_tcp_port = g->local_tcp_port;
184 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
185 global->local_udp_port = g->local_udp_port;
187 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
188 memcpy(&(global->lsr_identifier), &(g->lsr_identifier),
189 sizeof(mpls_inet_addr));
191 #if MPLS_USE_LSR
192 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
193 global->lsr_handle = g->lsr_handle;
195 #endif
196 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
197 if (global->admin_state == MPLS_ADMIN_ENABLE && g->admin_state == MPLS_ADMIN_DISABLE) {
198 ldp_global_shutdown(global);
199 } else if (global->admin_state == MPLS_ADMIN_DISABLE && g->admin_state ==
200 MPLS_ADMIN_ENABLE) {
201 ldp_global_startup(global);
204 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
205 memcpy(&(global->transport_address), &(g->transport_address),
206 sizeof(mpls_inet_addr));
208 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
209 if (g->keepalive_timer == 0) {
210 global->keepalive_timer = LDP_ENTITY_DEF_KEEPALIVE_TIMER;
211 } else {
212 global->keepalive_timer = g->keepalive_timer;
215 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
216 if (g->keepalive_interval == 0) {
217 global->keepalive_interval = LDP_ENTITY_DEF_KEEPALIVE_INTERVAL;
218 } else {
219 global->keepalive_interval = g->keepalive_interval;
222 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
223 if (g->hellotime_timer == 0) {
224 global->hellotime_timer = LDP_ENTITY_DEF_HELLOTIME_TIMER;
225 } else {
226 global->hellotime_timer = g->hellotime_timer;
229 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
230 if (g->hellotime_interval == 0) {
231 global->hellotime_interval = LDP_ENTITY_DEF_HELLOTIME_INTERVAL;
232 } else {
233 global->hellotime_interval = g->hellotime_interval;
236 #if MPLS_USE_LSR
237 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
238 global->lsr_handle = g->lsr_handle ;
240 #endif
241 global->configuration_sequence_number++;
243 retval = MPLS_SUCCESS;
245 ldp_cfg_global_set_end:
247 mpls_lock_release(global->global_lock); /* UNLOCK */
249 LDP_EXIT(global->user_data, "ldp_cfg_global_set");
251 return retval;
254 /******************* ENTITY **********************/
256 /* must set ldp_entity->index */
257 mpls_return_enum ldp_cfg_entity_get(mpls_cfg_handle handle, ldp_entity * e,
258 uint32_t flag)
260 ldp_global *global = (ldp_global *) handle;
261 ldp_entity *entity = NULL;
262 mpls_return_enum retval = MPLS_FAILURE;
264 MPLS_ASSERT(global !=NULL && e != NULL);
266 LDP_ENTER(global->user_data, "ldp_cfg_entity_get");
268 mpls_lock_get(global->global_lock); /* LOCK */
270 if (ldp_global_find_entity_index(global, e->index, &entity) != MPLS_SUCCESS)
271 goto ldp_cfg_entity_get_end;
273 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
274 e->admin_state = entity->admin_state;
276 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
277 e->transport_address = entity->transport_address;
279 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
280 e->protocol_version = entity->protocol_version;
282 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
283 e->remote_tcp_port = entity->remote_tcp_port;
285 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
286 e->remote_udp_port = entity->remote_udp_port;
288 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
289 e->max_pdu = entity->max_pdu;
291 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
292 e->keepalive_timer = entity->keepalive_timer;
294 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
295 e->keepalive_interval = entity->keepalive_interval;
297 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
298 e->hellotime_timer = entity->hellotime_timer;
300 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
301 e->hellotime_interval = entity->hellotime_interval;
303 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
304 e->session_setup_count = entity->session_setup_count;
306 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
307 e->session_backoff_timer = entity->session_backoff_timer;
309 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
310 e->label_distribution_mode = entity->label_distribution_mode;
312 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
313 e->path_vector_limit = entity->path_vector_limit;
315 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
316 e->hop_count_limit = entity->hop_count_limit;
318 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
319 e->label_request_count = entity->label_request_count;
321 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
322 e->label_request_timer = entity->label_request_timer;
324 if (flag & LDP_ENTITY_CFG_TYPE) {
325 e->entity_type = entity->entity_type;
327 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
328 e->sub_index = entity->sub_index;
330 if (flag & LDP_ENTITY_CFG_MESG_TX) {
331 e->mesg_tx = entity->mesg_tx;
333 if (flag & LDP_ENTITY_CFG_MESG_RX) {
334 e->mesg_rx = entity->mesg_rx;
336 if (flag & LDP_ENTITY_CFG_ADJ_COUNT) {
337 e->adj_count = e->adj_root.count;
339 if (flag & LDP_ENTITY_CFG_ADJ_INDEX) {
340 ldp_adj *a = MPLS_LIST_HEAD(&e->adj_root);
341 e->adj_index = a ? a->index : 0;
343 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
344 e->inherit_flag = entity->inherit_flag;
346 retval = MPLS_SUCCESS;
348 ldp_cfg_entity_get_end:
350 mpls_lock_release(global->global_lock); /* UNLOCK */
352 LDP_EXIT(global->user_data, "ldp_cfg_entity_get");
354 return retval;
357 mpls_return_enum ldp_cfg_entity_getnext(mpls_cfg_handle handle, ldp_entity * e,
358 uint32_t flag)
360 ldp_global *g = (ldp_global *) handle;
361 ldp_entity *entity = NULL;
362 mpls_return_enum r = MPLS_FAILURE;
363 mpls_bool done = MPLS_BOOL_FALSE;
364 int index;
366 LDP_ENTER(g->user_data, "ldp_cfg_entity_getnext");
368 if (e->index == 0) {
369 index = 1;
370 } else {
371 index = e->index + 1;
374 mpls_lock_get(g->global_lock); /* LOCK */
375 while (done == MPLS_BOOL_FALSE) {
376 switch ((r = ldp_global_find_entity_index(g, index, &entity))) {
377 case MPLS_SUCCESS:
378 case MPLS_END_OF_LIST:
379 done = MPLS_BOOL_TRUE;
380 break;
381 case MPLS_FAILURE:
382 break;
383 default:
384 MPLS_ASSERT(0);
386 index++;
388 mpls_lock_release(g->global_lock); /* UNLOCK */
390 if (r == MPLS_SUCCESS) {
391 e->index = entity->index;
392 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
393 return ldp_cfg_entity_get(g, e, flag);
395 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
396 return r;
399 mpls_return_enum ldp_cfg_entity_test(mpls_cfg_handle handle, ldp_entity * e,
400 uint32_t flag)
402 ldp_global *global = (ldp_global *) handle;
403 ldp_entity *entity = NULL;
404 mpls_return_enum retval = MPLS_FAILURE;
406 MPLS_ASSERT(global !=NULL);
408 LDP_ENTER(global->user_data, "ldp_cfg_entity_test");
410 mpls_lock_get(global->global_lock); /* LOCK */
412 if (!(flag & LDP_CFG_ADD)) {
413 if (e == NULL)
414 goto ldp_cfg_entity_test_end;
416 ldp_global_find_entity_index(global, e->index, &entity);
417 } else {
418 retval = MPLS_SUCCESS;
419 goto ldp_cfg_entity_test_end;
422 if (entity == NULL) {
423 goto ldp_cfg_entity_test_end;
426 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
427 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
428 goto ldp_cfg_entity_test_end;
431 retval = MPLS_SUCCESS;
433 ldp_cfg_entity_test_end:
434 mpls_lock_release(global->global_lock); /* UNLOCK */
436 LDP_EXIT(global->user_data, "ldp_cfg_entity_test");
438 return retval;
441 /* must set ldp_entity->index if not an add */
442 mpls_return_enum ldp_cfg_entity_set(mpls_cfg_handle handle, ldp_entity * e,
443 uint32_t flag)
445 ldp_global *global = (ldp_global *) handle;
446 ldp_entity *entity = NULL;
447 mpls_return_enum retval = MPLS_FAILURE;
449 MPLS_ASSERT(global !=NULL && e != NULL);
451 LDP_ENTER(global->user_data, "ldp_cfg_entity_set");
453 mpls_lock_get(global->global_lock); /* LOCK */
455 if (flag & LDP_CFG_ADD) {
456 entity = ldp_entity_create();
457 _ldp_global_add_entity(global, entity);
459 e->index = entity->index;
460 } else {
461 ldp_global_find_entity_index(global, e->index, &entity);
464 if (entity == NULL) {
465 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: can't find entity\n");
466 goto ldp_cfg_entity_set_end;
469 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
470 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
471 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity is active\n");
472 goto ldp_cfg_entity_set_end;
475 if (flag & LDP_CFG_DEL) {
476 switch (entity->entity_type) {
477 case LDP_DIRECT:
478 ldp_entity_del_if(global, entity);
479 break;
480 case LDP_INDIRECT:
481 ldp_entity_del_peer(entity);
482 break;
483 default:
484 MPLS_ASSERT(0);
486 _ldp_global_del_entity(global, entity);
488 retval = MPLS_SUCCESS;
489 goto ldp_cfg_entity_set_end;
492 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
493 if (entity->sub_index != 0) {
494 /* unlink the old sub object */
495 switch (entity->entity_type) {
496 case LDP_DIRECT:
497 ldp_entity_del_if(global, entity);
498 break;
499 case LDP_INDIRECT:
500 ldp_entity_del_peer(entity);
501 break;
502 default:
503 MPLS_ASSERT(0);
507 /* link the new sub object */
508 switch (e->entity_type) {
509 case LDP_DIRECT:
511 ldp_if *iff = NULL;
512 if (ldp_global_find_if_index(global, e->sub_index,
513 &iff) != MPLS_SUCCESS) {
514 LDP_PRINT(global->user_data,
515 "ldp_cfg_entity_set: no such interface\n");
517 if (flag & LDP_CFG_ADD) {
518 _ldp_global_del_entity(global, entity);
520 goto ldp_cfg_entity_set_end;
522 ldp_entity_add_if(entity, iff);
523 break;
525 case LDP_INDIRECT:
527 ldp_peer *peer = NULL;
529 if (ldp_global_find_peer_index(global, e->sub_index, &peer) !=
530 MPLS_SUCCESS) {
531 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: no such peer\n");
533 if (flag & LDP_CFG_ADD) {
534 _ldp_global_del_entity(global, entity);
536 goto ldp_cfg_entity_set_end;
538 ldp_entity_add_peer(entity, peer);
539 break;
541 default:
542 MPLS_ASSERT(0);
546 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
547 if (e->transport_address.type == MPLS_FAMILY_NONE) {
548 entity->inherit_flag |= LDP_ENTITY_CFG_TRANS_ADDR;
549 } else {
550 entity->inherit_flag &= ~LDP_ENTITY_CFG_TRANS_ADDR;
552 memcpy(&entity->transport_address, &e->transport_address,
553 sizeof(mpls_inet_addr));;
555 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
556 entity->protocol_version = e->protocol_version;
558 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
559 entity->remote_tcp_port = e->remote_tcp_port;
561 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
562 entity->remote_udp_port = e->remote_udp_port;
564 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
565 entity->max_pdu = e->max_pdu;
567 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
568 if (e->transport_address.type == MPLS_FAMILY_NONE) {
569 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_TIMER;
570 } else {
571 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER;
573 entity->keepalive_timer = e->keepalive_timer;
575 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
576 if (e->transport_address.type == MPLS_FAMILY_NONE) {
577 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
578 } else {
579 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
581 entity->keepalive_interval = e->keepalive_interval;
583 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
584 if (e->transport_address.type == MPLS_FAMILY_NONE) {
585 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_TIMER;
586 } else {
587 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_TIMER;
589 entity->hellotime_timer = e->hellotime_timer;
591 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
592 if (e->transport_address.type == MPLS_FAMILY_NONE) {
593 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
594 } else {
595 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
597 entity->hellotime_interval = e->hellotime_interval;
599 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
600 entity->session_setup_count = e->session_setup_count;
602 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
603 entity->session_backoff_timer = e->session_backoff_timer;
605 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
606 entity->label_distribution_mode = e->label_distribution_mode;
608 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
609 entity->path_vector_limit = e->path_vector_limit;
611 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
612 entity->hop_count_limit = e->hop_count_limit;
614 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
615 entity->label_request_count = e->label_request_count;
617 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
618 entity->label_request_timer = e->label_request_timer;
620 if (flag & LDP_ENTITY_CFG_TYPE) {
621 entity->entity_type = e->entity_type;
623 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
624 if (ldp_entity_is_active(entity) == MPLS_BOOL_TRUE &&
625 e->admin_state == MPLS_ADMIN_DISABLE) {
626 if (ldp_entity_shutdown(global, entity, 0) == MPLS_FAILURE) {
627 goto ldp_cfg_entity_set_end;
629 } else if (ldp_entity_is_active(entity) == MPLS_BOOL_FALSE &&
630 e->admin_state == MPLS_ADMIN_ENABLE && ldp_entity_is_ready(entity) == MPLS_BOOL_TRUE) {
631 if (ldp_entity_startup(global, entity) == MPLS_FAILURE) {
632 goto ldp_cfg_entity_set_end;
634 } else {
635 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity not ready\n");
637 goto ldp_cfg_entity_set_end;
640 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
641 entity->inherit_flag = e->inherit_flag;
643 global->configuration_sequence_number++;
645 retval = MPLS_SUCCESS;
647 ldp_cfg_entity_set_end:
648 mpls_lock_release(global->global_lock); /* UNLOCK */
650 LDP_EXIT(global->user_data, "ldp_cfg_entity_set");
652 return retval;
655 mpls_return_enum ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle,
656 ldp_entity * e)
658 ldp_global *g = (ldp_global *) handle;
659 mpls_bool this_one = MPLS_BOOL_FALSE;
660 mpls_return_enum r = MPLS_FAILURE;
661 ldp_adj *adj_next = NULL;
662 ldp_adj *adj = NULL;
663 ldp_entity *entity = NULL;
665 LDP_ENTER(g->user_data, "ldp_cfg_entity_adj_getnext");
667 /* if an adj_index of zero is sent, get the index of
668 * the first adj in the list
670 if (!e->adj_index) {
671 this_one = MPLS_BOOL_TRUE;
674 mpls_lock_get(g->global_lock); /* LOCK */
676 if (ldp_global_find_entity_index(g, e->index, &entity) == MPLS_SUCCESS) {
677 adj = MPLS_LIST_HEAD(&entity->adj_root);
678 while (adj) {
679 if (this_one == MPLS_BOOL_TRUE) {
680 adj_next = adj;
681 break;
684 /* since the entities are sort in the list ... */
685 if (adj->index > e->adj_index) {
686 break;
687 } else if (adj->index == e->adj_index) {
688 this_one = MPLS_BOOL_TRUE;
690 adj = MPLS_LIST_NEXT(&entity->adj_root, adj, _entity);
693 mpls_lock_release(g->global_lock); /* UNLOCK */
695 if (adj_next) {
696 e->adj_index = adj_next->index;
697 r = MPLS_SUCCESS;
700 LDP_EXIT(g->user_data, "ldp_cfg_entity_adj_getnext");
701 return r;
704 /******************* INTERFACE **********************/
706 mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
708 ldp_global *global = (ldp_global *) handle;
709 ldp_if *iff = NULL;
710 mpls_return_enum retval = MPLS_FAILURE;
712 MPLS_ASSERT(global !=NULL && i != NULL);
714 LDP_ENTER(global->user_data, "ldp_cfg_if_get");
716 mpls_lock_get(global->global_lock); /* LOCK */
718 if (flag & LDP_IF_CFG_BY_INDEX) {
719 ldp_global_find_if_index(global, i->index, &iff);
720 } else {
721 iff = ldp_global_find_if_handle(global, i->handle);
723 if (!iff)
724 goto ldp_cfg_if_get_end;
726 if (flag & LDP_IF_CFG_LABEL_SPACE) {
727 i->label_space = iff->label_space;
729 if (flag & LDP_IF_CFG_ENTITY_INDEX) {
730 i->entity_index = iff->entity ? iff->entity->index : 0;
732 if (flag & LDP_IF_CFG_OPER_STATE) {
733 i->oper_state = iff->oper_state;
735 retval = MPLS_SUCCESS;
737 ldp_cfg_if_get_end:
738 mpls_lock_release(global->global_lock); /* UNLOCK */
740 LDP_EXIT(global->user_data, "ldp_cfg_if_get");
742 return retval;
745 mpls_return_enum ldp_cfg_if_getnext(mpls_cfg_handle handle, ldp_if * i,
746 uint32_t flag)
748 ldp_global *g = (ldp_global *) handle;
749 ldp_if *iff = NULL;
750 mpls_return_enum r = MPLS_FAILURE;
751 mpls_bool done = MPLS_BOOL_FALSE;
752 int index;
754 LDP_ENTER(g->user_data, "ldp_cfg_if_getnext");
756 if (i->index == 0) {
757 index = 1;
758 } else {
759 index = i->index + 1;
762 mpls_lock_get(g->global_lock); /* LOCK */
763 while (done == MPLS_BOOL_FALSE) {
764 switch ((r = ldp_global_find_if_index(g, index, &iff))) {
765 case MPLS_SUCCESS:
766 case MPLS_END_OF_LIST:
767 done = MPLS_BOOL_TRUE;
768 break;
769 case MPLS_FAILURE:
770 break;
771 default:
772 MPLS_ASSERT(0);
774 index++;
776 mpls_lock_release(g->global_lock); /* UNLOCK */
778 if (r == MPLS_SUCCESS) {
779 i->index = iff->index;
780 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
781 return ldp_cfg_if_get(g, i, flag);
783 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
784 return r;
787 mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i,
788 uint32_t flag)
790 ldp_global *global = (ldp_global *) handle;
791 ldp_if *iff = NULL;
792 mpls_return_enum retval = MPLS_FAILURE;
794 MPLS_ASSERT(global !=NULL && i != NULL);
796 LDP_ENTER(global->user_data, "ldp_cfg_if_test");
798 mpls_lock_get(global->global_lock); /* LOCK */
800 if (!(flag & LDP_CFG_ADD)) {
801 ldp_global_find_if_index(global, i->index, &iff);
802 } else {
803 retval = MPLS_SUCCESS;
804 goto ldp_cfg_if_test_end;
807 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
808 (flag & LDP_IF_CFG_WHEN_DOWN))) {
809 goto ldp_cfg_if_test_end;
812 if (flag & LDP_CFG_DEL) {
813 if (iff->entity != NULL) {
814 goto ldp_cfg_if_test_end;
817 retval = MPLS_SUCCESS;
819 ldp_cfg_if_test_end:
820 mpls_lock_release(global->global_lock); /* UNLOCK */
822 LDP_EXIT(global->user_data, "ldp_cfg_if_test");
824 return retval;
827 mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
829 ldp_global *global = (ldp_global*)handle;
830 ldp_if *iff = NULL;
831 ldp_addr *ap;
832 ldp_nexthop *np;
833 mpls_return_enum retval = MPLS_FAILURE;
835 MPLS_ASSERT(global !=NULL && i != NULL);
837 LDP_ENTER(global->user_data, "ldp_cfg_if_set");
839 mpls_lock_get(global->global_lock); /* LOCK */
841 if (flag & LDP_CFG_ADD) {
842 /* duplicate interface handles are not allowed */
843 /* ADDs require a valid interface handle */
844 if (((iff = ldp_global_find_if_handle(global, i->handle)) != NULL) ||
845 (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==
846 MPLS_BOOL_FALSE) || ((iff = ldp_if_create(global)) == NULL)) {
847 goto ldp_cfg_if_set_end;
850 /* copy the handle from the user */
851 iff->handle = i->handle;
853 /* search for addrs and nexthops that are waiting for this interface */
854 ap = MPLS_LIST_HEAD(&global->addr);
855 while (ap) {
856 if (ap->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(ap, _if))) {
857 ldp_if_add_addr(iff, ap);
859 ap = MPLS_LIST_NEXT(&global->addr, ap, _global);
862 np = MPLS_LIST_HEAD(&global->nexthop);
863 while (np) {
864 if ((np->info.type & MPLS_NH_IF) &&
865 (np->info.if_handle == iff->handle) && (!MPLS_LIST_IN_LIST(np, _if))) {
866 ldp_if_add_nexthop(iff, np);
868 np = MPLS_LIST_NEXT(&global->nexthop, np, _global);
871 /* send the newly created index back to the user */
872 i->index = iff->index;
874 } else {
875 if (flag & LDP_IF_CFG_BY_INDEX) {
876 ldp_global_find_if_index(global, i->index, &iff);
877 } else {
878 iff = ldp_global_find_if_handle(global, i->handle);
883 * if we can't find this interface or if the interface is active and
884 * we are trying to change propertises that can not be changed on a
885 * active interface
887 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
888 (flag & LDP_IF_CFG_WHEN_DOWN))) {
889 goto ldp_cfg_if_set_end;
892 if (flag & LDP_IF_CFG_LABEL_SPACE) {
893 iff->label_space = i->label_space;
896 if (flag & LDP_CFG_DEL) {
898 * if this interface is still attached to a entity that it is not ready
899 * to be removed
901 if (iff->entity != NULL) {
902 goto ldp_cfg_if_set_end;
905 np = MPLS_LIST_HEAD(&iff->nh_root);
906 while (np) {
907 ldp_if_del_nexthop(global, iff, np);
908 np = MPLS_LIST_NEXT(&iff->nh_root, np, _if);
911 ap = MPLS_LIST_HEAD(&iff->addr_root);
912 while (ap) {
913 ldp_if_del_addr(global, iff, ap);
914 ap = MPLS_LIST_NEXT(&iff->addr_root, ap, _if);
917 MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);
920 global->configuration_sequence_number++;
922 retval = MPLS_SUCCESS;
924 ldp_cfg_if_set_end:
925 mpls_lock_release(global->global_lock); /* UNLOCK */
927 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
929 return retval;
932 /******************* ATTR **********************/
934 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
935 uint32_t flag)
937 ldp_global *global = (ldp_global *) handle;
938 ldp_attr *attr = NULL;
939 mpls_return_enum retval = MPLS_FAILURE;
941 MPLS_ASSERT(global !=NULL && a != NULL);
943 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
945 mpls_lock_get(global->global_lock); /* LOCK */
947 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
948 goto ldp_cfg_attr_get_end;
950 if (flag & LDP_ATTR_CFG_STATE) {
951 a->state = attr->state;
953 if (flag & LDP_ATTR_CFG_FEC) {
954 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
956 if (flag & LDP_ATTR_CFG_LABEL) {
957 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
959 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
960 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
962 if (flag & LDP_ATTR_CFG_PATH) {
963 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
965 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
966 a->session_index = (attr->session) ? (attr->session->index) : 0;
968 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
969 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
971 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
972 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
974 if (flag & LDP_ATTR_CFG_INGRESS) {
975 a->ingress = attr->ingress;
977 retval = MPLS_SUCCESS;
979 ldp_cfg_attr_get_end:
980 mpls_lock_release(global->global_lock); /* UNLOCK */
982 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
984 return retval;
987 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
988 uint32_t flag)
990 ldp_global *g = (ldp_global *) handle;
991 ldp_attr *attr = NULL;
992 mpls_return_enum r = MPLS_FAILURE;
993 mpls_bool done = MPLS_BOOL_FALSE;
994 int index;
996 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
998 if (a->index == 0) {
999 index = 1;
1000 } else {
1001 index = a->index + 1;
1004 mpls_lock_get(g->global_lock); /* LOCK */
1005 while (done == MPLS_BOOL_FALSE) {
1006 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
1007 case MPLS_SUCCESS:
1008 case MPLS_END_OF_LIST:
1009 done = MPLS_BOOL_TRUE;
1010 break;
1011 case MPLS_FAILURE:
1012 break;
1013 default:
1014 MPLS_ASSERT(0);
1016 index++;
1018 mpls_lock_release(g->global_lock); /* UNLOCK */
1020 if (r == MPLS_SUCCESS) {
1021 a->index = attr->index;
1022 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1023 return ldp_cfg_attr_get(g, a, flag);
1025 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1026 return r;
1029 /******************* PEER **********************/
1031 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
1032 uint32_t flag)
1034 ldp_global *global = (ldp_global *) handle;
1035 ldp_peer *peer = NULL;
1036 mpls_return_enum retval = MPLS_FAILURE;
1038 MPLS_ASSERT(global !=NULL && p != NULL);
1040 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
1042 mpls_lock_get(global->global_lock); /* LOCK */
1044 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
1045 goto ldp_cfg_peer_get_end;
1047 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1048 p->label_space = peer->label_space;
1050 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1051 p->target_role = peer->target_role;
1053 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1054 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1056 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1057 p->entity_index = peer->entity->index;
1059 if (flag & LDP_PEER_CFG_OPER_STATE) {
1060 p->oper_state = peer->oper_state;
1062 if (flag & LDP_PEER_CFG_PEER_NAME) {
1063 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1065 retval = MPLS_SUCCESS;
1067 ldp_cfg_peer_get_end:
1068 mpls_lock_release(global->global_lock); /* UNLOCK */
1070 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1072 return retval;
1075 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1076 uint32_t flag)
1078 ldp_global *g = (ldp_global *) handle;
1079 ldp_peer *peer = NULL;
1080 mpls_return_enum r = MPLS_FAILURE;
1081 mpls_bool done = MPLS_BOOL_FALSE;
1082 int index;
1084 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1086 if (p->index == 0) {
1087 index = 1;
1088 } else {
1089 index = p->index + 1;
1092 mpls_lock_get(g->global_lock); /* LOCK */
1093 while (done == MPLS_BOOL_FALSE) {
1094 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1095 case MPLS_SUCCESS:
1096 case MPLS_END_OF_LIST:
1097 done = MPLS_BOOL_TRUE;
1098 break;
1099 case MPLS_FAILURE:
1100 break;
1101 default:
1102 MPLS_ASSERT(0);
1104 index++;
1106 mpls_lock_release(g->global_lock); /* UNLOCK */
1108 if (r == MPLS_SUCCESS) {
1109 p->index = peer->index;
1110 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1111 return ldp_cfg_peer_get(g, p, flag);
1113 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1114 return r;
1117 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1118 uint32_t flag)
1120 // ldp_global* g = (ldp_global*)handle;
1121 return MPLS_SUCCESS;
1124 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1125 uint32_t flag)
1127 ldp_global *global = (ldp_global *) handle;
1128 ldp_peer *peer = NULL;
1129 mpls_return_enum retval = MPLS_FAILURE;
1131 MPLS_ASSERT(global !=NULL && p != NULL);
1133 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1135 mpls_lock_get(global->global_lock); /* LOCK */
1137 if (flag & LDP_CFG_ADD) {
1138 if ((peer = ldp_peer_create()) == NULL) {
1139 goto ldp_cfg_peer_set_end;
1141 p->index = peer->index;
1142 _ldp_global_add_peer(global, peer);
1143 } else {
1144 ldp_global_find_peer_index(global, p->index, &peer);
1147 if (peer == NULL) {
1148 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1150 goto ldp_cfg_peer_set_end;
1152 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1153 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1155 goto ldp_cfg_peer_set_end;
1158 if (flag & LDP_CFG_DEL) {
1159 if (peer->entity != NULL) {
1160 LDP_PRINT(global->user_data,
1161 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1163 goto ldp_cfg_peer_set_end;
1166 _ldp_global_del_peer(global, peer);
1168 retval = MPLS_SUCCESS;
1169 goto ldp_cfg_peer_set_end;
1171 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1172 peer->label_space = p->label_space;
1174 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1175 peer->target_role = p->target_role;
1177 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1178 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1180 if (flag & LDP_PEER_CFG_PEER_NAME) {
1181 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1183 p->peer_name);
1184 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1186 global->configuration_sequence_number++;
1188 retval = MPLS_SUCCESS;
1190 ldp_cfg_peer_set_end:
1191 mpls_lock_release(global->global_lock); /* UNLOCK */
1193 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1195 return retval;
1197 /******************* FEC **********************/
1199 mpls_return_enum ldp_cfg_fec_get(mpls_cfg_handle handle, mpls_fec * f,
1200 uint32_t flag)
1202 ldp_global *global = (ldp_global *) handle;
1203 ldp_fec *fec = NULL;
1204 mpls_return_enum retval = MPLS_FAILURE;
1206 MPLS_ASSERT(global !=NULL && f != NULL);
1208 LDP_ENTER(global->user_data, "ldp_cfg_fec_get");
1210 mpls_lock_get(global->global_lock); /* LOCK */
1212 if (flag & LDP_FEC_CFG_BY_INDEX) {
1213 ldp_global_find_fec_index(global, f->index, &fec);
1214 } else {
1215 fec = ldp_fec_find(global, f);
1217 if (!fec)
1218 goto ldp_cfg_fec_get_end;
1220 memcpy(f, &fec->info, sizeof(mpls_fec));
1221 f->index = fec->index;
1222 retval = MPLS_SUCCESS;
1224 ldp_cfg_fec_get_end:
1225 mpls_lock_release(global->global_lock); /* UNLOCK */
1227 LDP_EXIT(global->user_data, "ldp_cfg_fec_get");
1229 return retval;
1232 mpls_return_enum ldp_cfg_fec_getnext(mpls_cfg_handle handle, mpls_fec * f,
1233 uint32_t flag)
1235 ldp_global *g = (ldp_global *) handle;
1236 ldp_fec *fec = NULL;
1237 mpls_return_enum r = MPLS_FAILURE;
1238 mpls_bool done = MPLS_BOOL_FALSE;
1239 int index;
1241 LDP_ENTER(g->user_data, "ldp_cfg_fec_getnext");
1243 if (f->index == 0) {
1244 index = 1;
1245 } else {
1246 index = f->index + 1;
1249 mpls_lock_get(g->global_lock); /* LOCK */
1250 while (done == MPLS_BOOL_FALSE) {
1251 switch ((r = ldp_global_find_fec_index(g, index, &fec))) {
1252 case MPLS_SUCCESS:
1253 case MPLS_END_OF_LIST:
1254 done = MPLS_BOOL_TRUE;
1255 break;
1256 case MPLS_FAILURE:
1257 break;
1258 default:
1259 MPLS_ASSERT(0);
1261 index++;
1263 mpls_lock_release(g->global_lock); /* UNLOCK */
1265 if (r == MPLS_SUCCESS) {
1266 f->index = fec->index;
1267 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1268 return ldp_cfg_fec_get(g, f, flag);
1270 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1271 return r;
1274 mpls_return_enum ldp_cfg_fec_test(mpls_cfg_handle handle, mpls_fec * f,
1275 uint32_t flag)
1277 // ldp_global* g = (ldp_global*)handle;
1278 return MPLS_SUCCESS;
1281 mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f,
1282 uint32_t flag)
1284 ldp_global *global = (ldp_global *) handle;
1285 ldp_fec *fec = NULL;
1286 mpls_return_enum retval = MPLS_FAILURE;
1288 MPLS_ASSERT(global !=NULL && f != NULL);
1290 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1292 mpls_lock_get(global->global_lock); /* LOCK */
1294 if (flag & LDP_CFG_ADD) {
1295 if (ldp_fec_find(global, f) || (fec = ldp_fec_create(global, f)) == NULL) {
1296 goto ldp_cfg_fec_set_end;
1298 f->index = fec->index;
1299 } else {
1300 if (flag & LDP_FEC_CFG_BY_INDEX) {
1301 ldp_global_find_fec_index(global, f->index, &fec);
1302 } else {
1303 fec = ldp_fec_find(global, f);
1307 if (fec == NULL) {
1308 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1309 goto ldp_cfg_fec_set_end;
1312 if (flag & LDP_CFG_DEL) {
1313 MPLS_ASSERT(0);
1316 retval = MPLS_SUCCESS;
1318 ldp_cfg_fec_set_end:
1319 mpls_lock_release(global->global_lock); /* UNLOCK */
1321 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1323 return retval;
1326 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1327 mpls_nexthop *n, uint32_t flag)
1329 ldp_global *global = (ldp_global *) handle;
1330 ldp_fec *fec = NULL;
1331 ldp_nexthop *nh = NULL;
1332 mpls_return_enum retval = MPLS_FAILURE;
1334 MPLS_ASSERT(global !=NULL && f != NULL);
1336 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1338 mpls_lock_get(global->global_lock); /* LOCK */
1340 if (flag & LDP_FEC_CFG_BY_INDEX) {
1341 ldp_global_find_fec_index(global, f->index, &fec);
1342 } else {
1343 fec = ldp_fec_find(global, f);
1345 if (!fec)
1346 goto ldp_cfg_fec_nexthop_get_end;
1348 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1349 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1350 } else {
1351 nh = ldp_fec_nexthop_find(fec, n);
1353 if (!nh)
1354 goto ldp_cfg_fec_nexthop_get_end;
1356 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1357 n->index = nh->index;
1358 retval = MPLS_SUCCESS;
1360 ldp_cfg_fec_nexthop_get_end:
1361 mpls_lock_release(global->global_lock); /* UNLOCK */
1363 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1365 return retval;
1368 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1369 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1371 ldp_global *global = (ldp_global *) handle;
1372 ldp_fec *fec = NULL;
1373 ldp_nexthop *nh = NULL;
1374 mpls_return_enum r = MPLS_FAILURE;
1375 mpls_bool done = MPLS_BOOL_FALSE;
1376 int index;
1378 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1380 if (n->index == 0) {
1381 index = 1;
1382 } else {
1383 index = n->index + 1;
1386 mpls_lock_get(global->global_lock); /* LOCK */
1388 if (flag & LDP_FEC_CFG_BY_INDEX) {
1389 ldp_global_find_fec_index(global, f->index, &fec);
1390 } else {
1391 fec = ldp_fec_find(global, f);
1393 if (!fec)
1394 goto ldp_cfg_fec_nexthop_getnext_end;
1396 while (done == MPLS_BOOL_FALSE) {
1397 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1398 case MPLS_SUCCESS:
1399 case MPLS_END_OF_LIST:
1400 done = MPLS_BOOL_TRUE;
1401 break;
1402 case MPLS_FAILURE:
1403 break;
1404 default:
1405 MPLS_ASSERT(0);
1407 index++;
1409 mpls_lock_release(global->global_lock); /* UNLOCK */
1411 if (r == MPLS_SUCCESS) {
1412 n->index = nh->index;
1413 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1414 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1417 ldp_cfg_fec_nexthop_getnext_end:
1419 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1420 return r;
1423 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1424 mpls_nexthop *n, uint32_t flag)
1426 // ldp_global* g = (ldp_global*)handle;
1427 return MPLS_SUCCESS;
1430 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1431 mpls_nexthop *n, uint32_t flag)
1433 ldp_global *global = (ldp_global *) handle;
1434 ldp_fec *fec = NULL;
1435 ldp_nexthop *nh = NULL;
1436 mpls_return_enum retval = MPLS_FAILURE;
1438 MPLS_ASSERT(global !=NULL && f != NULL && n != NULL);
1440 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1442 mpls_lock_get(global->global_lock); /* LOCK */
1444 if (flag & LDP_FEC_CFG_BY_INDEX) {
1445 ldp_global_find_fec_index(global, f->index, &fec);
1446 } else {
1447 fec = ldp_fec_find(global, f);
1449 if (!fec)
1450 goto ldp_cfg_fec_nexthop_set_end;
1452 if (flag & LDP_CFG_ADD) {
1453 if (ldp_fec_nexthop_find(fec, n) || (nh = ldp_nexthop_create()) == NULL) {
1454 goto ldp_cfg_fec_nexthop_set_end;
1456 n->index = nh->index;
1457 mpls_nexthop2ldp_nexthop(n, nh);
1458 _ldp_global_add_nexthop(global, nh);
1459 ldp_fec_add_nexthop(global, fec, nh);
1460 } else {
1461 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1462 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1463 } else {
1464 nh = ldp_fec_nexthop_find(fec, n);
1468 if (nh == NULL) {
1469 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1470 goto ldp_cfg_fec_nexthop_set_end;
1473 if (flag & LDP_CFG_DEL) {
1474 ldp_fec_del_nexthop(global, fec, nh);
1475 _ldp_global_del_nexthop(global, nh);
1478 retval = MPLS_SUCCESS;
1480 ldp_cfg_fec_nexthop_set_end:
1481 mpls_lock_release(global->global_lock); /* UNLOCK */
1483 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1485 return retval;
1488 /******************* ADDR **********************/
1490 mpls_return_enum ldp_cfg_addr_get(mpls_cfg_handle handle, ldp_addr * a,
1491 uint32_t flag)
1493 ldp_global *global = (ldp_global *) handle;
1494 ldp_session *session = NULL;
1495 ldp_nexthop *nexthop = NULL;
1496 ldp_addr *addr = NULL;
1497 mpls_return_enum retval = MPLS_FAILURE;
1499 MPLS_ASSERT(global !=NULL && a != NULL);
1501 LDP_ENTER(global->user_data, "ldp_cfg_addr_get");
1503 mpls_lock_get(global->global_lock); /* LOCK */
1505 ldp_global_find_addr_index(global, a->index, &addr);
1507 if (!addr)
1508 goto ldp_cfg_addr_get_end;
1510 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1511 a->index = addr->index;
1513 if ((session = mpls_link_list_head_data(&addr->session_root))) {
1514 a->session_index = session->index;
1517 if ((nexthop = MPLS_LIST_HEAD(&addr->nh_root))) {
1518 a->nexthop_index = nexthop->index;
1521 if (addr->iff) {
1522 a->if_index = addr->iff->index;
1525 retval = MPLS_SUCCESS;
1527 ldp_cfg_addr_get_end:
1528 mpls_lock_release(global->global_lock); /* UNLOCK */
1530 LDP_EXIT(global->user_data, "ldp_cfg_addr_get");
1532 return retval;
1535 mpls_return_enum ldp_cfg_addr_getnext(mpls_cfg_handle handle, ldp_addr *a,
1536 uint32_t flag)
1538 ldp_global *global = (ldp_global *) handle;
1539 ldp_addr *addr = NULL;
1540 mpls_return_enum r = MPLS_FAILURE;
1541 mpls_bool done = MPLS_BOOL_FALSE;
1542 int index;
1544 LDP_ENTER(global->user_data, "ldp_cfg_addr_getnext");
1546 if (a->index == 0) {
1547 index = 1;
1548 } else {
1549 index = a->index + 1;
1552 mpls_lock_get(global->global_lock); /* LOCK */
1554 while (done == MPLS_BOOL_FALSE) {
1555 switch ((r = ldp_global_find_addr_index(global, index, &addr))) {
1556 case MPLS_SUCCESS:
1557 case MPLS_END_OF_LIST:
1558 done = MPLS_BOOL_TRUE;
1559 break;
1560 case MPLS_FAILURE:
1561 break;
1562 default:
1563 MPLS_ASSERT(0);
1565 index++;
1567 mpls_lock_release(global->global_lock); /* UNLOCK */
1569 if (r == MPLS_SUCCESS) {
1570 a->index = addr->index;
1571 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1572 return ldp_cfg_addr_get(global, a, flag);
1575 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1576 return r;
1579 /******************* IF ADDR **********************/
1581 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1582 ldp_addr * a, uint32_t flag)
1584 ldp_global *global = (ldp_global *) handle;
1585 ldp_addr *addr = NULL;
1586 ldp_if *iff = NULL;
1587 mpls_return_enum retval = MPLS_FAILURE;
1589 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1591 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1593 mpls_lock_get(global->global_lock); /* LOCK */
1595 if (flag & LDP_IF_CFG_BY_INDEX) {
1596 ldp_global_find_if_index(global, i->index, &iff);
1597 } else {
1598 iff = ldp_global_find_if_handle(global, i->handle);
1600 if (!iff)
1601 goto ldp_cfg_if_addr_get_end;
1603 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1604 ldp_if_find_addr_index(iff, a->index, &addr);
1605 } else {
1606 addr = ldp_if_addr_find(iff, &a->address);
1608 if (!addr)
1609 goto ldp_cfg_if_addr_get_end;
1611 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1612 a->index = addr->index;
1614 retval = MPLS_SUCCESS;
1616 ldp_cfg_if_addr_get_end:
1617 mpls_lock_release(global->global_lock); /* UNLOCK */
1619 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1621 return retval;
1624 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1625 ldp_if * i, ldp_addr *a, uint32_t flag)
1627 ldp_global *global = (ldp_global *) handle;
1628 ldp_if *iff = NULL;
1629 ldp_addr *addr = NULL;
1630 mpls_return_enum r = MPLS_FAILURE;
1631 mpls_bool done = MPLS_BOOL_FALSE;
1632 int index;
1634 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1636 if (a->index == 0) {
1637 index = 1;
1638 } else {
1639 index = a->index + 1;
1642 mpls_lock_get(global->global_lock); /* LOCK */
1644 if (flag & LDP_IF_CFG_BY_INDEX) {
1645 ldp_global_find_if_index(global, i->index, &iff);
1646 } else {
1647 iff = ldp_global_find_if_handle(global, i->handle);
1649 if (!iff)
1650 goto ldp_cfg_if_addr_getnext_end;
1652 while (done == MPLS_BOOL_FALSE) {
1653 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1654 case MPLS_SUCCESS:
1655 case MPLS_END_OF_LIST:
1656 done = MPLS_BOOL_TRUE;
1657 break;
1658 case MPLS_FAILURE:
1659 break;
1660 default:
1661 MPLS_ASSERT(0);
1663 index++;
1665 mpls_lock_release(global->global_lock); /* UNLOCK */
1667 if (r == MPLS_SUCCESS) {
1668 a->index = addr->index;
1669 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1670 return ldp_cfg_if_addr_get(global, i, a, flag);
1673 ldp_cfg_if_addr_getnext_end:
1675 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1676 return r;
1679 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1680 ldp_addr *a, uint32_t flag)
1682 ldp_global *global = (ldp_global *) handle;
1683 ldp_if *iff = NULL;
1684 ldp_addr *addr = NULL;
1685 mpls_return_enum retval = MPLS_FAILURE;
1687 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1689 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1691 mpls_lock_get(global->global_lock); /* LOCK */
1693 if (flag & LDP_FEC_CFG_BY_INDEX) {
1694 ldp_global_find_if_index(global, i->index, &iff);
1695 } else {
1696 iff = ldp_global_find_if_handle(global, i->handle);
1698 if (!iff)
1699 goto ldp_cfg_if_addr_set_end;
1701 if (flag & LDP_CFG_ADD) {
1702 if (ldp_if_addr_find(iff, &a->address) || (addr = ldp_addr_create(global,
1703 &a->address)) == NULL) {
1704 goto ldp_cfg_if_addr_set_end;
1706 a->index = addr->index;
1707 ldp_if_add_addr(iff, addr);
1708 } else {
1709 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1710 ldp_if_find_addr_index(iff, a->index, &addr);
1711 } else {
1712 addr = ldp_if_addr_find(iff, &a->address);
1716 if (addr == NULL) {
1717 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1718 goto ldp_cfg_if_addr_set_end;
1721 if (flag & LDP_CFG_DEL) {
1722 ldp_if_del_addr(global, iff ,addr);
1725 retval = MPLS_SUCCESS;
1727 ldp_cfg_if_addr_set_end:
1728 mpls_lock_release(global->global_lock); /* UNLOCK */
1730 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1732 return retval;
1735 /******************* ADJACENCY **********************/
1737 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1738 uint32_t flag)
1740 ldp_global *global = (ldp_global *) handle;
1741 ldp_adj *adj = NULL;
1742 mpls_return_enum retval = MPLS_FAILURE;
1744 MPLS_ASSERT(global !=NULL && a != NULL);
1746 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1748 mpls_lock_get(global->global_lock); /* LOCK */
1750 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1751 goto ldp_cfg_adj_get_end;
1753 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1754 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1755 sizeof(mpls_inet_addr));
1757 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1758 memcpy(&a->remote_source_address, &adj->remote_source_address,
1759 sizeof(mpls_inet_addr));
1761 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1762 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1763 sizeof(mpls_inet_addr));
1765 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1766 a->remote_csn = adj->remote_csn;
1768 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1769 a->remote_label_space = adj->remote_label_space;
1771 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1772 a->remote_hellotime = adj->remote_hellotime;
1774 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1775 a->entity_index = adj->entity ? adj->entity->index : 0;
1777 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1778 a->session_index = (adj->session) ? (adj->session->index) : 0;
1780 if (flag & LDP_ADJ_CFG_ROLE) {
1781 a->role = adj->role;
1783 retval = MPLS_SUCCESS;
1785 ldp_cfg_adj_get_end:
1787 mpls_lock_release(global->global_lock); /* UNLOCK */
1789 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1791 return retval;
1794 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1795 uint32_t flag)
1797 ldp_global *g = (ldp_global *) handle;
1798 ldp_adj *adj = NULL;
1799 mpls_return_enum r = MPLS_FAILURE;
1800 mpls_bool done = MPLS_BOOL_FALSE;
1801 int index;
1803 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1805 if (a->index == 0) {
1806 index = 1;
1807 } else {
1808 index = a->index + 1;
1811 mpls_lock_get(g->global_lock); /* LOCK */
1812 while (done == MPLS_BOOL_FALSE) {
1813 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1814 case MPLS_SUCCESS:
1815 case MPLS_END_OF_LIST:
1816 done = MPLS_BOOL_TRUE;
1817 break;
1818 case MPLS_FAILURE:
1819 break;
1820 default:
1821 MPLS_ASSERT(0);
1823 index++;
1825 mpls_lock_release(g->global_lock); /* UNLOCK */
1827 if (r == MPLS_SUCCESS) {
1828 a->index = adj->index;
1829 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1830 return ldp_cfg_adj_get(g, a, flag);
1832 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1833 return r;
1836 /******************* SESSION **********************/
1838 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1839 uint32_t flag)
1841 ldp_global *global = (ldp_global *) handle;
1842 ldp_session *session = NULL;
1843 mpls_return_enum retval = MPLS_FAILURE;
1845 MPLS_ASSERT(global !=NULL && s != NULL);
1847 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1849 mpls_lock_get(global->global_lock); /* LOCK */
1851 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1852 goto ldp_cfg_session_get_end;
1854 if (flag & LDP_SESSION_CFG_STATE) {
1855 s->state = session->state;
1857 if (flag & LDP_SESSION_CFG_OPER_UP) {
1858 s->oper_up = session->oper_up;
1860 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1861 s->oper_max_pdu = session->oper_max_pdu;
1863 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1864 s->oper_keepalive = session->oper_keepalive;
1866 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1867 s->oper_path_vector_limit = session->oper_path_vector_limit;
1869 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1870 s->oper_distribution_mode = session->oper_distribution_mode;
1872 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1873 s->oper_loop_detection = session->oper_loop_detection;
1875 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1876 s->remote_max_pdu = session->remote_max_pdu;
1878 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1879 s->remote_keepalive = session->remote_keepalive;
1881 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1882 s->remote_path_vector_limit = session->remote_path_vector_limit;
1884 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1885 s->remote_distribution_mode = session->remote_distribution_mode;
1887 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1888 s->remote_loop_detection = session->remote_loop_detection;
1890 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1891 s->remote_dest.addr.type = session->remote_dest.addr.type;
1892 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1894 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1895 s->remote_dest.port = session->remote_dest.port;
1897 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1898 s->no_label_resource_sent = session->no_label_resource_sent;
1900 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1901 s->no_label_resource_recv = session->no_label_resource_recv;
1903 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1904 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1905 s->adj_index = a ? a->index : 0;
1907 if (flag & LDP_SESSION_CFG_MESG_TX) {
1908 s->mesg_tx = session->mesg_tx;
1910 if (flag & LDP_SESSION_CFG_MESG_RX) {
1911 s->mesg_rx = session->mesg_rx;
1913 retval = MPLS_SUCCESS;
1915 ldp_cfg_session_get_end:
1916 mpls_lock_release(global->global_lock); /* UNLOCK */
1918 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1920 return retval;
1923 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1924 uint32_t flag)
1926 ldp_global *g = (ldp_global *) handle;
1927 ldp_session *ses = NULL;
1928 mpls_return_enum r = MPLS_FAILURE;
1929 mpls_bool done = MPLS_BOOL_FALSE;
1930 int index;
1932 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1934 if (s->index == 0) {
1935 index = 1;
1936 } else {
1937 index = s->index + 1;
1940 mpls_lock_get(g->global_lock); /* LOCK */
1941 while (done == MPLS_BOOL_FALSE) {
1942 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1943 case MPLS_SUCCESS:
1944 case MPLS_END_OF_LIST:
1945 done = MPLS_BOOL_TRUE;
1946 break;
1947 case MPLS_FAILURE:
1948 break;
1949 default:
1950 MPLS_ASSERT(0);
1952 index++;
1954 mpls_lock_release(g->global_lock); /* UNLOCK */
1956 if (r == MPLS_SUCCESS) {
1957 s->index = ses->index;
1959 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1960 return ldp_cfg_session_get(g, s, flag);
1963 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1965 return r;
1968 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1969 ldp_session * s)
1971 ldp_global *g = (ldp_global *) handle;
1972 mpls_bool this_one = MPLS_BOOL_FALSE;
1973 mpls_return_enum r = MPLS_FAILURE;
1974 ldp_adj *adj_next = NULL;
1975 ldp_adj *adj = NULL;
1976 ldp_session *session = NULL;
1978 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
1980 /* if an adj_index of zero is sent, get the index of
1981 * the first adj in the list
1983 if (!s->adj_index) {
1984 this_one = MPLS_BOOL_TRUE;
1987 mpls_lock_get(g->global_lock); /* LOCK */
1989 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
1990 adj = MPLS_LIST_HEAD(&session->adj_root);
1991 while (adj) {
1992 if (this_one == MPLS_BOOL_TRUE) {
1993 adj_next = adj;
1994 break;
1997 /* since the entities are sort in the list ... */
1998 if (adj->index > s->adj_index) {
1999 break;
2000 } else if (adj->index == s->adj_index) {
2001 this_one = MPLS_BOOL_TRUE;
2003 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
2006 mpls_lock_release(g->global_lock); /* UNLOCK */
2008 if (adj_next) {
2009 s->adj_index = adj_next->index;
2010 r = MPLS_SUCCESS;
2013 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
2014 return r;
2017 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
2018 ldp_session * s, ldp_addr * a, uint32_t flag)
2020 ldp_global *global = (ldp_global *) handle;
2021 ldp_session *session = NULL;
2022 ldp_addr *addr = NULL;
2023 mpls_return_enum retval = MPLS_FAILURE;
2025 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
2027 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
2029 mpls_lock_get(global->global_lock); /* LOCK */
2031 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
2032 goto ldp_cfg_session_raddr_get_end;
2034 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
2035 goto ldp_cfg_session_raddr_get_end;
2037 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
2038 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
2040 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
2041 a->index = addr->index;
2043 retval = MPLS_SUCCESS;
2045 ldp_cfg_session_raddr_get_end:
2046 mpls_lock_release(global->global_lock); /* UNLOCK */
2048 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
2050 return retval;
2053 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
2054 ldp_session * s, ldp_addr * a, uint32_t flag)
2056 ldp_global *g = (ldp_global *) handle;
2057 ldp_addr *addr = NULL;
2058 mpls_return_enum r = MPLS_FAILURE;
2059 mpls_bool done = MPLS_BOOL_FALSE;
2060 ldp_session *sp = NULL;
2061 int index;
2063 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
2065 if (a->index == 0) {
2066 index = 1;
2067 } else {
2068 index = a->index + 1;
2071 r = ldp_global_find_session_index(g, s->index, &sp);
2072 if (r != MPLS_SUCCESS) {
2073 return r;
2076 mpls_lock_get(g->global_lock); /* LOCK */
2077 while (done == MPLS_BOOL_FALSE) {
2078 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
2079 case MPLS_SUCCESS:
2080 case MPLS_END_OF_LIST:
2081 done = MPLS_BOOL_TRUE;
2082 break;
2083 case MPLS_FAILURE:
2084 break;
2085 default:
2086 MPLS_ASSERT(0);
2088 index++;
2090 mpls_lock_release(g->global_lock); /* UNLOCK */
2092 if (r == MPLS_SUCCESS) {
2093 a->index = addr->index;
2094 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2097 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2098 return r;
2101 /******************* IN LABEL **********************/
2103 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2104 uint32_t flag)
2106 ldp_global *global = (ldp_global *) handle;
2107 ldp_inlabel *inlabel = NULL;
2108 mpls_return_enum retval = MPLS_FAILURE;
2110 MPLS_ASSERT(global !=NULL && i != NULL);
2112 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2114 mpls_lock_get(global->global_lock); /* LOCK */
2116 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2117 goto ldp_cfg_inlabel_get_end;
2119 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2120 i->info.labelspace = inlabel->info.labelspace;
2122 if (flag & LDP_INLABEL_CFG_LABEL) {
2123 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2125 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2126 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2129 retval = MPLS_SUCCESS;
2131 ldp_cfg_inlabel_get_end:
2132 mpls_lock_release(global->global_lock); /* UNLOCK */
2134 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2136 return retval;
2139 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2140 uint32_t flag)
2142 ldp_global *g = (ldp_global *) handle;
2143 ldp_inlabel *inlabel = NULL;
2144 mpls_return_enum r = MPLS_FAILURE;
2145 mpls_bool done = MPLS_BOOL_FALSE;
2146 int index;
2148 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2150 if (i->index == 0) {
2151 index = 1;
2152 } else {
2153 index = i->index + 1;
2156 mpls_lock_get(g->global_lock); /* LOCK */
2157 while (done == MPLS_BOOL_FALSE) {
2158 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2159 case MPLS_SUCCESS:
2160 case MPLS_END_OF_LIST:
2161 done = MPLS_BOOL_TRUE;
2162 break;
2163 case MPLS_FAILURE:
2164 break;
2165 default:
2166 MPLS_ASSERT(0);
2168 index++;
2170 mpls_lock_release(g->global_lock); /* UNLOCK */
2172 if (r == MPLS_SUCCESS) {
2173 i->index = inlabel->index;
2175 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2176 return ldp_cfg_inlabel_get(g, i, flag);
2179 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2181 return r;
2184 /******************* OUT LABEL **********************/
2186 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2187 uint32_t flag)
2189 ldp_global *global = (ldp_global *) handle;
2190 ldp_outlabel *outlabel = NULL;
2191 mpls_return_enum retval = MPLS_FAILURE;
2193 MPLS_ASSERT(global !=NULL && o != NULL);
2195 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2197 mpls_lock_get(global->global_lock); /* LOCK */
2199 if (ldp_global_find_outlabel_index(global, o->index,
2200 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2202 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2203 if (outlabel->nh) {
2204 o->nh_index = outlabel->nh->index;
2205 } else {
2206 o->nh_index = 0;
2209 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2210 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2212 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2213 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2215 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2216 o->merge_count = outlabel->merge_count;
2219 retval = MPLS_SUCCESS;
2221 ldp_cfg_outlabel_get_end:
2222 mpls_lock_release(global->global_lock); /* UNLOCK */
2224 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2226 return retval;
2229 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2230 ldp_outlabel * o, uint32_t flag)
2232 ldp_global *g = (ldp_global *) handle;
2233 ldp_outlabel *outlabel = NULL;
2234 mpls_return_enum r = MPLS_FAILURE;
2235 mpls_bool done = MPLS_BOOL_FALSE;
2236 int index;
2238 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2240 if (o->index == 0) {
2241 index = 1;
2242 } else {
2243 index = o->index + 1;
2246 mpls_lock_get(g->global_lock); /* LOCK */
2247 while (done == MPLS_BOOL_FALSE) {
2248 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2249 case MPLS_SUCCESS:
2250 case MPLS_END_OF_LIST:
2251 done = MPLS_BOOL_TRUE;
2252 break;
2253 case MPLS_FAILURE:
2254 break;
2255 default:
2256 MPLS_ASSERT(0);
2258 index++;
2260 mpls_lock_release(g->global_lock); /* UNLOCK */
2262 if (r == MPLS_SUCCESS) {
2263 o->index = outlabel->index;
2265 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2266 return ldp_cfg_outlabel_get(g, o, flag);
2269 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2271 return r;
2274 /******************* TUNNEL **********************/
2276 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2277 uint32_t flag)
2279 ldp_global *global = (ldp_global *) handle;
2280 mpls_return_enum retval = MPLS_FAILURE;
2281 ldp_tunnel *tunnel = NULL;
2283 MPLS_ASSERT(global !=NULL);
2285 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2287 mpls_lock_get(global->global_lock); /* LOCK */
2289 if (flag & LDP_CFG_ADD) {
2290 if (!(tunnel = ldp_tunnel_create())) {
2291 goto ldp_cfg_tunnel_set_end;
2293 _ldp_global_add_tunnel(global, tunnel);
2295 t->index = tunnel->index;
2296 } else {
2297 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2300 if (!tunnel) {
2301 LDP_PRINT(global->user_data,
2303 "ldp_cfg_tunnel_set:could not create tunnel\n");
2304 goto ldp_cfg_tunnel_set_end;
2307 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2308 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2309 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2311 goto ldp_cfg_tunnel_set_end;
2314 if (flag & LDP_CFG_DEL) {
2315 if (tunnel->outlabel)
2316 ldp_tunnel_del_outlabel(tunnel);
2317 if (tunnel->resource)
2318 ldp_tunnel_del_resource(tunnel);
2319 if (tunnel->hop_list)
2320 ldp_tunnel_del_hop_list(tunnel);
2321 _ldp_global_del_tunnel(global, tunnel);
2323 retval = MPLS_SUCCESS;
2324 goto ldp_cfg_tunnel_set_end;
2327 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2328 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2330 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2331 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2333 if (flag & LDP_TUNNEL_CFG_NAME) {
2334 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2336 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2337 tunnel->is_interface = t->is_interface;
2339 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2340 ldp_outlabel *outlabel = NULL;
2342 if (t->outlabel_index) {
2343 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2345 if (!outlabel) {
2346 goto ldp_cfg_tunnel_set_end;
2348 ldp_tunnel_add_outlabel(tunnel, outlabel);
2349 } else {
2350 ldp_tunnel_del_outlabel(tunnel);
2353 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2354 tunnel->setup_prio = t->setup_prio;
2356 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2357 tunnel->hold_prio = t->hold_prio;
2359 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2360 tunnel->instance_prio = t->instance_prio;
2362 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2363 tunnel->local_protect = t->local_protect;
2365 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2366 ldp_resource *resource = NULL;
2368 if (t->resource_index) {
2369 ldp_global_find_resource_index(global, t->resource_index, &resource);
2371 if (!resource) {
2372 goto ldp_cfg_tunnel_set_end;
2374 ldp_tunnel_add_resource(tunnel, resource);
2375 } else {
2376 ldp_tunnel_del_resource(tunnel);
2379 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2380 ldp_hop_list *hop_list = NULL;
2382 if (t->hop_list_index) {
2383 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2385 if (!hop_list) {
2386 goto ldp_cfg_tunnel_set_end;
2388 ldp_tunnel_add_hop_list(tunnel, hop_list);
2389 } else {
2390 ldp_tunnel_del_hop_list(tunnel);
2393 if (flag & LDP_TUNNEL_CFG_FEC) {
2394 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2396 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2397 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2398 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2399 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2400 goto ldp_cfg_tunnel_set_end;
2403 } else {
2404 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2405 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2406 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2407 goto ldp_cfg_tunnel_set_end;
2409 } else {
2410 LDP_PRINT(global->user_data,
2412 "ldp_cfg_tunnel_set: tunnel not ready\n");
2413 goto ldp_cfg_tunnel_set_end;
2418 retval = MPLS_SUCCESS;
2420 ldp_cfg_tunnel_set_end:
2422 mpls_lock_release(global->global_lock); /* UNLOCK */
2424 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2426 return retval;
2429 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2430 uint32_t flag)
2432 ldp_global *global = (ldp_global *) handle;
2433 mpls_return_enum retval = MPLS_FAILURE;
2434 ldp_tunnel *tunnel = NULL;
2436 MPLS_ASSERT(global !=NULL);
2438 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2440 mpls_lock_get(global->global_lock); /* LOCK */
2442 if (flag & LDP_CFG_ADD) {
2443 retval = MPLS_SUCCESS;
2444 goto ldp_cfg_tunnel_test_end;
2447 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2449 if (!tunnel) {
2450 goto ldp_cfg_tunnel_test_end;
2453 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2454 ldp_resource *resource = NULL;
2456 if (t->resource_index) {
2457 ldp_global_find_resource_index(global, t->resource_index, &resource);
2459 if (!resource) {
2460 goto ldp_cfg_tunnel_test_end;
2464 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2465 ldp_hop_list *hop_list = NULL;
2467 if (t->hop_list_index) {
2468 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2470 if (!hop_list) {
2471 goto ldp_cfg_tunnel_test_end;
2475 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2476 ldp_outlabel *outlabel = NULL;
2478 if (t->outlabel_index) {
2479 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2481 if (!outlabel) {
2482 goto ldp_cfg_tunnel_test_end;
2486 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2487 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2488 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2489 goto ldp_cfg_tunnel_test_end;
2491 retval = MPLS_SUCCESS;
2493 ldp_cfg_tunnel_test_end:
2495 mpls_lock_release(global->global_lock); /* UNLOCK */
2497 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2499 return retval;
2502 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2503 uint32_t flag)
2505 ldp_global *global = (ldp_global *) handle;
2506 mpls_return_enum retval = MPLS_FAILURE;
2507 ldp_tunnel *tunnel = NULL;
2509 MPLS_ASSERT(global !=NULL);
2511 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2513 mpls_lock_get(global->global_lock); /* LOCK */
2515 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2517 if (!tunnel) {
2518 goto ldp_cfg_tunnel_get_end;
2520 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2521 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2523 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2524 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2526 if (flag & LDP_TUNNEL_CFG_NAME) {
2527 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2529 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2530 t->is_interface = tunnel->is_interface;
2532 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2533 if (tunnel->outlabel) {
2534 t->outlabel_index = tunnel->outlabel->index;
2535 } else {
2536 t->outlabel_index = 0;
2539 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2540 t->setup_prio = tunnel->setup_prio;
2542 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2543 t->hold_prio = tunnel->hold_prio;
2545 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2546 tunnel->instance_prio = t->instance_prio;
2548 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2549 tunnel->local_protect = t->local_protect;
2551 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2552 if (tunnel->resource) {
2553 t->resource_index = tunnel->resource->index;
2554 } else {
2555 t->resource_index = 0;
2558 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2559 if (tunnel->hop_list) {
2560 t->hop_list_index = tunnel->hop_list->index;
2561 } else {
2562 t->hop_list_index = 0;
2565 if (flag & LDP_TUNNEL_CFG_FEC) {
2566 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2568 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2569 t->admin_state = tunnel->admin_state;
2571 retval = MPLS_SUCCESS;
2573 ldp_cfg_tunnel_get_end:
2575 mpls_lock_release(global->global_lock); /* UNLOCK */
2577 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2579 return retval;
2582 /******************* RESOURCE **********************/
2584 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2585 uint32_t flag)
2587 ldp_global *global = (ldp_global *) handle;
2588 mpls_return_enum retval = MPLS_FAILURE;
2589 ldp_resource *resource = NULL;
2591 MPLS_ASSERT(global !=NULL);
2593 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2595 mpls_lock_get(global->global_lock); /* LOCK */
2597 if (flag & LDP_CFG_ADD) {
2598 resource = ldp_resource_create();
2599 _ldp_global_add_resource(global, resource);
2601 r->index = resource->index;
2602 } else {
2603 ldp_global_find_resource_index(global, r->index, &resource);
2606 if (!resource) {
2607 goto ldp_cfg_resource_set_end;
2610 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2611 resource->max_rate = r->max_rate;
2613 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2614 resource->mean_rate = r->mean_rate;
2616 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2617 resource->burst_size = r->burst_size;
2619 retval = MPLS_SUCCESS;
2621 ldp_cfg_resource_set_end:
2623 mpls_lock_release(global->global_lock); /* UNLOCK */
2625 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2627 return retval;
2630 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2631 uint32_t flag)
2633 ldp_global *global = (ldp_global *) handle;
2634 mpls_return_enum retval = MPLS_FAILURE;
2635 ldp_resource *resource = NULL;
2637 MPLS_ASSERT(global !=NULL);
2639 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2641 mpls_lock_get(global->global_lock); /* LOCK */
2643 if (flag & LDP_CFG_ADD) {
2644 retval = MPLS_SUCCESS;
2645 goto ldp_cfg_resource_test_end;
2648 ldp_global_find_resource_index(global, r->index, &resource);
2650 if (!resource) {
2651 goto ldp_cfg_resource_test_end;
2654 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2655 goto ldp_cfg_resource_test_end;
2657 retval = MPLS_SUCCESS;
2659 ldp_cfg_resource_test_end:
2661 mpls_lock_release(global->global_lock); /* UNLOCK */
2663 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2665 return retval;
2668 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2669 uint32_t flag)
2671 ldp_global *global = (ldp_global *) handle;
2672 mpls_return_enum retval = MPLS_FAILURE;
2673 ldp_resource *resource = NULL;
2675 MPLS_ASSERT(global !=NULL);
2677 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2679 mpls_lock_get(global->global_lock); /* LOCK */
2681 ldp_global_find_resource_index(global, r->index, &resource);
2683 if (!resource) {
2684 goto ldp_cfg_resource_get_end;
2687 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2688 r->max_rate = resource->max_rate;
2690 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2691 r->mean_rate = resource->mean_rate;
2693 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2694 r->burst_size = resource->burst_size;
2696 retval = MPLS_SUCCESS;
2698 ldp_cfg_resource_get_end:
2700 mpls_lock_release(global->global_lock); /* UNLOCK */
2702 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2704 return retval;
2707 /******************* HOP **********************/
2709 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2710 uint32_t flag)
2712 ldp_global *global = (ldp_global *) handle;
2713 mpls_return_enum retval = MPLS_FAILURE;
2714 ldp_hop_list *hop_list = NULL;
2715 ldp_hop *hop = NULL;
2717 MPLS_ASSERT(global !=NULL);
2719 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2721 if (!h->hop_list_index && !h->index) {
2722 return retval;
2725 mpls_lock_get(global->global_lock); /* LOCK */
2727 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2729 if (!hop_list) {
2730 if (flag & LDP_CFG_ADD) {
2731 if (!(hop_list = ldp_hop_list_create())) {
2732 goto ldp_cfg_hop_set_end;
2734 _ldp_global_add_hop_list(global, hop_list);
2736 h->hop_list_index = hop_list->index;
2737 } else {
2738 goto ldp_cfg_hop_set_end;
2742 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2743 if (!hop) {
2744 if (h->index && (flag & LDP_CFG_ADD)) {
2745 if (!(hop = ldp_hop_create())) {
2746 goto ldp_cfg_hop_set_end;
2748 hop->index = h->index;
2749 ldp_hop_list_add_hop(hop_list, hop);
2750 } else {
2751 goto ldp_cfg_hop_set_end;
2755 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2756 hop->path_option = h->path_option;
2758 if (flag & LDP_HOP_CFG_ADDR) {
2759 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2761 if (flag & LDP_HOP_CFG_TYPE) {
2762 hop->type = h->type;
2764 retval = MPLS_SUCCESS;
2766 ldp_cfg_hop_set_end:
2768 mpls_lock_release(global->global_lock); /* UNLOCK */
2770 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2772 return retval;
2775 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2776 uint32_t flag)
2778 ldp_global *global = (ldp_global *) handle;
2779 mpls_return_enum retval = MPLS_FAILURE;
2780 ldp_hop_list *hop_list = NULL;
2781 ldp_hop *hop = NULL;
2783 MPLS_ASSERT(global !=NULL);
2785 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2787 mpls_lock_get(global->global_lock); /* LOCK */
2789 if (flag & LDP_CFG_ADD) {
2790 retval = MPLS_SUCCESS;
2791 goto ldp_cfg_hop_test_end;
2794 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2796 if (!hop_list) {
2797 goto ldp_cfg_hop_test_end;
2800 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2801 if (!hop) {
2802 goto ldp_cfg_hop_test_end;
2805 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2806 goto ldp_cfg_hop_test_end;
2808 retval = MPLS_SUCCESS;
2810 ldp_cfg_hop_test_end:
2812 mpls_lock_release(global->global_lock); /* UNLOCK */
2814 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2816 return retval;
2819 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2820 uint32_t flag)
2822 ldp_global *global = (ldp_global *) handle;
2823 mpls_return_enum retval = MPLS_FAILURE;
2824 ldp_hop_list *hop_list = NULL;
2825 ldp_hop *hop = NULL;
2827 MPLS_ASSERT(global !=NULL);
2829 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2831 mpls_lock_get(global->global_lock); /* LOCK */
2833 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2835 if (!hop_list) {
2836 goto ldp_cfg_hop_get_end;
2839 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2840 if (!hop) {
2841 goto ldp_cfg_hop_get_end;
2844 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2845 h->path_option = hop->path_option;
2847 if (flag & LDP_HOP_CFG_ADDR) {
2848 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2850 if (flag & LDP_HOP_CFG_TYPE) {
2851 h->type = hop->type;
2853 retval = MPLS_SUCCESS;
2855 ldp_cfg_hop_get_end:
2857 mpls_lock_release(global->global_lock); /* UNLOCK */
2859 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2861 return retval;