Various bug fixes to get basic label distribution working again
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blob32e611ecbea569de8912aae591124b15f7b79160
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->type & MPLS_NH_IF) && (np->info.if_handle == iff->handle) &&
865 (!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()) == NULL) {
1296 goto ldp_cfg_fec_set_end;
1298 f->index = fec->index;
1299 mpls_fec2ldp_fec(f, fec);
1300 _ldp_global_add_fec(global, fec);
1301 ldp_fec_insert2(global, fec);
1302 } else {
1303 if (flag & LDP_FEC_CFG_BY_INDEX) {
1304 ldp_global_find_fec_index(global, f->index, &fec);
1305 } else {
1306 fec = ldp_fec_find(global, f);
1310 if (fec == NULL) {
1311 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1312 goto ldp_cfg_fec_set_end;
1315 if (flag & LDP_CFG_DEL) {
1316 ldp_fec_remove(global,&fec->info);
1317 _ldp_global_del_fec(global, fec);
1320 retval = MPLS_SUCCESS;
1322 ldp_cfg_fec_set_end:
1323 mpls_lock_release(global->global_lock); /* UNLOCK */
1325 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1327 return retval;
1330 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1331 mpls_nexthop *n, uint32_t flag)
1333 ldp_global *global = (ldp_global *) handle;
1334 ldp_fec *fec = NULL;
1335 ldp_nexthop *nh = NULL;
1336 mpls_return_enum retval = MPLS_FAILURE;
1338 MPLS_ASSERT(global !=NULL && f != NULL);
1340 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1342 mpls_lock_get(global->global_lock); /* LOCK */
1344 if (flag & LDP_FEC_CFG_BY_INDEX) {
1345 ldp_global_find_fec_index(global, f->index, &fec);
1346 } else {
1347 fec = ldp_fec_find(global, f);
1349 if (!fec)
1350 goto ldp_cfg_fec_nexthop_get_end;
1352 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1353 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1354 } else {
1355 nh = ldp_fec_nexthop_find(fec, n);
1357 if (!nh)
1358 goto ldp_cfg_fec_nexthop_get_end;
1360 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1361 n->index = nh->index;
1362 retval = MPLS_SUCCESS;
1364 ldp_cfg_fec_nexthop_get_end:
1365 mpls_lock_release(global->global_lock); /* UNLOCK */
1367 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1369 return retval;
1372 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1373 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1375 ldp_global *global = (ldp_global *) handle;
1376 ldp_fec *fec = NULL;
1377 ldp_nexthop *nh = NULL;
1378 mpls_return_enum r = MPLS_FAILURE;
1379 mpls_bool done = MPLS_BOOL_FALSE;
1380 int index;
1382 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1384 if (n->index == 0) {
1385 index = 1;
1386 } else {
1387 index = n->index + 1;
1390 mpls_lock_get(global->global_lock); /* LOCK */
1392 if (flag & LDP_FEC_CFG_BY_INDEX) {
1393 ldp_global_find_fec_index(global, f->index, &fec);
1394 } else {
1395 fec = ldp_fec_find(global, f);
1397 if (!fec)
1398 goto ldp_cfg_fec_nexthop_getnext_end;
1400 while (done == MPLS_BOOL_FALSE) {
1401 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1402 case MPLS_SUCCESS:
1403 case MPLS_END_OF_LIST:
1404 done = MPLS_BOOL_TRUE;
1405 break;
1406 case MPLS_FAILURE:
1407 break;
1408 default:
1409 MPLS_ASSERT(0);
1411 index++;
1413 mpls_lock_release(global->global_lock); /* UNLOCK */
1415 if (r == MPLS_SUCCESS) {
1416 n->index = nh->index;
1417 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1418 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1421 ldp_cfg_fec_nexthop_getnext_end:
1423 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1424 return r;
1427 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1428 mpls_nexthop *n, uint32_t flag)
1430 // ldp_global* g = (ldp_global*)handle;
1431 return MPLS_SUCCESS;
1434 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1435 mpls_nexthop *n, uint32_t flag)
1437 ldp_global *global = (ldp_global *) handle;
1438 ldp_fec *fec = NULL;
1439 ldp_nexthop *nh = NULL;
1440 mpls_return_enum retval = MPLS_FAILURE;
1442 MPLS_ASSERT(global !=NULL && f != NULL && n != NULL);
1444 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1446 mpls_lock_get(global->global_lock); /* LOCK */
1448 if (flag & LDP_FEC_CFG_BY_INDEX) {
1449 ldp_global_find_fec_index(global, f->index, &fec);
1450 } else {
1451 fec = ldp_fec_find(global, f);
1453 if (!fec)
1454 goto ldp_cfg_fec_nexthop_set_end;
1456 if (flag & LDP_CFG_ADD) {
1457 if (ldp_fec_nexthop_find(fec, n) || (nh = ldp_nexthop_create()) == NULL) {
1458 goto ldp_cfg_fec_nexthop_set_end;
1460 n->index = nh->index;
1461 mpls_nexthop2ldp_nexthop(n, nh);
1462 _ldp_global_add_nexthop(global, nh);
1463 ldp_fec_add_nexthop(global, fec, nh);
1464 } else {
1465 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1466 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1467 } else {
1468 nh = ldp_fec_nexthop_find(fec, n);
1472 if (nh == NULL) {
1473 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1474 goto ldp_cfg_fec_nexthop_set_end;
1477 if (flag & LDP_CFG_DEL) {
1478 ldp_fec_del_nexthop(global, fec, nh);
1479 _ldp_global_del_nexthop(global, nh);
1482 retval = MPLS_SUCCESS;
1484 ldp_cfg_fec_nexthop_set_end:
1485 mpls_lock_release(global->global_lock); /* UNLOCK */
1487 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1489 return retval;
1492 /******************* ADDR **********************/
1494 mpls_return_enum ldp_cfg_addr_get(mpls_cfg_handle handle, ldp_addr * a,
1495 uint32_t flag)
1497 ldp_global *global = (ldp_global *) handle;
1498 ldp_session *session = NULL;
1499 ldp_nexthop *nexthop = NULL;
1500 ldp_addr *addr = NULL;
1501 mpls_return_enum retval = MPLS_FAILURE;
1503 MPLS_ASSERT(global !=NULL && a != NULL);
1505 LDP_ENTER(global->user_data, "ldp_cfg_addr_get");
1507 mpls_lock_get(global->global_lock); /* LOCK */
1509 ldp_global_find_addr_index(global, a->index, &addr);
1511 if (!addr)
1512 goto ldp_cfg_addr_get_end;
1514 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1515 a->index = addr->index;
1517 if ((session = mpls_link_list_head_data(&addr->session_root))) {
1518 a->session_index = session->index;
1521 if ((nexthop = MPLS_LIST_HEAD(&addr->nh_root))) {
1522 a->nexthop_index = nexthop->index;
1525 if (addr->iff) {
1526 a->if_index = addr->iff->index;
1529 retval = MPLS_SUCCESS;
1531 ldp_cfg_addr_get_end:
1532 mpls_lock_release(global->global_lock); /* UNLOCK */
1534 LDP_EXIT(global->user_data, "ldp_cfg_addr_get");
1536 return retval;
1539 mpls_return_enum ldp_cfg_addr_getnext(mpls_cfg_handle handle, ldp_addr *a,
1540 uint32_t flag)
1542 ldp_global *global = (ldp_global *) handle;
1543 ldp_addr *addr = NULL;
1544 mpls_return_enum r = MPLS_FAILURE;
1545 mpls_bool done = MPLS_BOOL_FALSE;
1546 int index;
1548 LDP_ENTER(global->user_data, "ldp_cfg_addr_getnext");
1550 if (a->index == 0) {
1551 index = 1;
1552 } else {
1553 index = a->index + 1;
1556 mpls_lock_get(global->global_lock); /* LOCK */
1558 while (done == MPLS_BOOL_FALSE) {
1559 switch ((r = ldp_global_find_addr_index(global, index, &addr))) {
1560 case MPLS_SUCCESS:
1561 case MPLS_END_OF_LIST:
1562 done = MPLS_BOOL_TRUE;
1563 break;
1564 case MPLS_FAILURE:
1565 break;
1566 default:
1567 MPLS_ASSERT(0);
1569 index++;
1571 mpls_lock_release(global->global_lock); /* UNLOCK */
1573 if (r == MPLS_SUCCESS) {
1574 a->index = addr->index;
1575 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1576 return ldp_cfg_addr_get(global, a, flag);
1579 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1580 return r;
1583 /******************* IF ADDR **********************/
1585 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1586 ldp_addr * a, uint32_t flag)
1588 ldp_global *global = (ldp_global *) handle;
1589 ldp_addr *addr = NULL;
1590 ldp_if *iff = NULL;
1591 mpls_return_enum retval = MPLS_FAILURE;
1593 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1595 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1597 mpls_lock_get(global->global_lock); /* LOCK */
1599 if (flag & LDP_IF_CFG_BY_INDEX) {
1600 ldp_global_find_if_index(global, i->index, &iff);
1601 } else {
1602 iff = ldp_global_find_if_handle(global, i->handle);
1604 if (!iff)
1605 goto ldp_cfg_if_addr_get_end;
1607 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1608 ldp_if_find_addr_index(iff, a->index, &addr);
1609 } else {
1610 addr = ldp_if_addr_find(iff, &a->address);
1612 if (!addr)
1613 goto ldp_cfg_if_addr_get_end;
1615 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1616 a->index = addr->index;
1618 retval = MPLS_SUCCESS;
1620 ldp_cfg_if_addr_get_end:
1621 mpls_lock_release(global->global_lock); /* UNLOCK */
1623 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1625 return retval;
1628 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1629 ldp_if * i, ldp_addr *a, uint32_t flag)
1631 ldp_global *global = (ldp_global *) handle;
1632 ldp_if *iff = NULL;
1633 ldp_addr *addr = NULL;
1634 mpls_return_enum r = MPLS_FAILURE;
1635 mpls_bool done = MPLS_BOOL_FALSE;
1636 int index;
1638 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1640 if (a->index == 0) {
1641 index = 1;
1642 } else {
1643 index = a->index + 1;
1646 mpls_lock_get(global->global_lock); /* LOCK */
1648 if (flag & LDP_IF_CFG_BY_INDEX) {
1649 ldp_global_find_if_index(global, i->index, &iff);
1650 } else {
1651 iff = ldp_global_find_if_handle(global, i->handle);
1653 if (!iff)
1654 goto ldp_cfg_if_addr_getnext_end;
1656 while (done == MPLS_BOOL_FALSE) {
1657 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1658 case MPLS_SUCCESS:
1659 case MPLS_END_OF_LIST:
1660 done = MPLS_BOOL_TRUE;
1661 break;
1662 case MPLS_FAILURE:
1663 break;
1664 default:
1665 MPLS_ASSERT(0);
1667 index++;
1669 mpls_lock_release(global->global_lock); /* UNLOCK */
1671 if (r == MPLS_SUCCESS) {
1672 a->index = addr->index;
1673 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1674 return ldp_cfg_if_addr_get(global, i, a, flag);
1677 ldp_cfg_if_addr_getnext_end:
1679 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1680 return r;
1683 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1684 ldp_addr *a, uint32_t flag)
1686 ldp_global *global = (ldp_global *) handle;
1687 ldp_if *iff = NULL;
1688 ldp_addr *addr = NULL;
1689 mpls_return_enum retval = MPLS_FAILURE;
1691 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1693 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1695 mpls_lock_get(global->global_lock); /* LOCK */
1697 if (flag & LDP_FEC_CFG_BY_INDEX) {
1698 ldp_global_find_if_index(global, i->index, &iff);
1699 } else {
1700 iff = ldp_global_find_if_handle(global, i->handle);
1702 if (!iff)
1703 goto ldp_cfg_if_addr_set_end;
1705 if (flag & LDP_CFG_ADD) {
1706 if (ldp_if_addr_find(iff, &a->address) || (addr = ldp_addr_create(global,
1707 &a->address)) == NULL) {
1708 goto ldp_cfg_if_addr_set_end;
1710 a->index = addr->index;
1711 ldp_if_add_addr(iff, addr);
1712 } else {
1713 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1714 ldp_if_find_addr_index(iff, a->index, &addr);
1715 } else {
1716 addr = ldp_if_addr_find(iff, &a->address);
1720 if (addr == NULL) {
1721 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1722 goto ldp_cfg_if_addr_set_end;
1725 if (flag & LDP_CFG_DEL) {
1726 ldp_if_del_addr(global, iff ,addr);
1729 retval = MPLS_SUCCESS;
1731 ldp_cfg_if_addr_set_end:
1732 mpls_lock_release(global->global_lock); /* UNLOCK */
1734 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1736 return retval;
1739 /******************* ADJACENCY **********************/
1741 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1742 uint32_t flag)
1744 ldp_global *global = (ldp_global *) handle;
1745 ldp_adj *adj = NULL;
1746 mpls_return_enum retval = MPLS_FAILURE;
1748 MPLS_ASSERT(global !=NULL && a != NULL);
1750 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1752 mpls_lock_get(global->global_lock); /* LOCK */
1754 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1755 goto ldp_cfg_adj_get_end;
1757 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1758 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1759 sizeof(mpls_inet_addr));
1761 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1762 memcpy(&a->remote_source_address, &adj->remote_source_address,
1763 sizeof(mpls_inet_addr));
1765 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1766 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1767 sizeof(mpls_inet_addr));
1769 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1770 a->remote_csn = adj->remote_csn;
1772 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1773 a->remote_label_space = adj->remote_label_space;
1775 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1776 a->remote_hellotime = adj->remote_hellotime;
1778 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1779 a->entity_index = adj->entity ? adj->entity->index : 0;
1781 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1782 a->session_index = (adj->session) ? (adj->session->index) : 0;
1784 if (flag & LDP_ADJ_CFG_ROLE) {
1785 a->role = adj->role;
1787 retval = MPLS_SUCCESS;
1789 ldp_cfg_adj_get_end:
1791 mpls_lock_release(global->global_lock); /* UNLOCK */
1793 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1795 return retval;
1798 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1799 uint32_t flag)
1801 ldp_global *g = (ldp_global *) handle;
1802 ldp_adj *adj = NULL;
1803 mpls_return_enum r = MPLS_FAILURE;
1804 mpls_bool done = MPLS_BOOL_FALSE;
1805 int index;
1807 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1809 if (a->index == 0) {
1810 index = 1;
1811 } else {
1812 index = a->index + 1;
1815 mpls_lock_get(g->global_lock); /* LOCK */
1816 while (done == MPLS_BOOL_FALSE) {
1817 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1818 case MPLS_SUCCESS:
1819 case MPLS_END_OF_LIST:
1820 done = MPLS_BOOL_TRUE;
1821 break;
1822 case MPLS_FAILURE:
1823 break;
1824 default:
1825 MPLS_ASSERT(0);
1827 index++;
1829 mpls_lock_release(g->global_lock); /* UNLOCK */
1831 if (r == MPLS_SUCCESS) {
1832 a->index = adj->index;
1833 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1834 return ldp_cfg_adj_get(g, a, flag);
1836 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1837 return r;
1840 /******************* SESSION **********************/
1842 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1843 uint32_t flag)
1845 ldp_global *global = (ldp_global *) handle;
1846 ldp_session *session = NULL;
1847 mpls_return_enum retval = MPLS_FAILURE;
1849 MPLS_ASSERT(global !=NULL && s != NULL);
1851 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1853 mpls_lock_get(global->global_lock); /* LOCK */
1855 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1856 goto ldp_cfg_session_get_end;
1858 if (flag & LDP_SESSION_CFG_STATE) {
1859 s->state = session->state;
1861 if (flag & LDP_SESSION_CFG_OPER_UP) {
1862 s->oper_up = session->oper_up;
1864 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1865 s->oper_max_pdu = session->oper_max_pdu;
1867 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1868 s->oper_keepalive = session->oper_keepalive;
1870 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1871 s->oper_path_vector_limit = session->oper_path_vector_limit;
1873 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1874 s->oper_distribution_mode = session->oper_distribution_mode;
1876 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1877 s->oper_loop_detection = session->oper_loop_detection;
1879 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1880 s->remote_max_pdu = session->remote_max_pdu;
1882 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1883 s->remote_keepalive = session->remote_keepalive;
1885 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1886 s->remote_path_vector_limit = session->remote_path_vector_limit;
1888 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1889 s->remote_distribution_mode = session->remote_distribution_mode;
1891 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1892 s->remote_loop_detection = session->remote_loop_detection;
1894 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1895 s->remote_dest.addr.type = session->remote_dest.addr.type;
1896 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1898 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1899 s->remote_dest.port = session->remote_dest.port;
1901 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1902 s->no_label_resource_sent = session->no_label_resource_sent;
1904 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1905 s->no_label_resource_recv = session->no_label_resource_recv;
1907 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1908 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1909 s->adj_index = a ? a->index : 0;
1911 if (flag & LDP_SESSION_CFG_MESG_TX) {
1912 s->mesg_tx = session->mesg_tx;
1914 if (flag & LDP_SESSION_CFG_MESG_RX) {
1915 s->mesg_rx = session->mesg_rx;
1917 retval = MPLS_SUCCESS;
1919 ldp_cfg_session_get_end:
1920 mpls_lock_release(global->global_lock); /* UNLOCK */
1922 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1924 return retval;
1927 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1928 uint32_t flag)
1930 ldp_global *g = (ldp_global *) handle;
1931 ldp_session *ses = NULL;
1932 mpls_return_enum r = MPLS_FAILURE;
1933 mpls_bool done = MPLS_BOOL_FALSE;
1934 int index;
1936 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1938 if (s->index == 0) {
1939 index = 1;
1940 } else {
1941 index = s->index + 1;
1944 mpls_lock_get(g->global_lock); /* LOCK */
1945 while (done == MPLS_BOOL_FALSE) {
1946 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1947 case MPLS_SUCCESS:
1948 case MPLS_END_OF_LIST:
1949 done = MPLS_BOOL_TRUE;
1950 break;
1951 case MPLS_FAILURE:
1952 break;
1953 default:
1954 MPLS_ASSERT(0);
1956 index++;
1958 mpls_lock_release(g->global_lock); /* UNLOCK */
1960 if (r == MPLS_SUCCESS) {
1961 s->index = ses->index;
1963 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1964 return ldp_cfg_session_get(g, s, flag);
1967 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1969 return r;
1972 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1973 ldp_session * s)
1975 ldp_global *g = (ldp_global *) handle;
1976 mpls_bool this_one = MPLS_BOOL_FALSE;
1977 mpls_return_enum r = MPLS_FAILURE;
1978 ldp_adj *adj_next = NULL;
1979 ldp_adj *adj = NULL;
1980 ldp_session *session = NULL;
1982 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
1984 /* if an adj_index of zero is sent, get the index of
1985 * the first adj in the list
1987 if (!s->adj_index) {
1988 this_one = MPLS_BOOL_TRUE;
1991 mpls_lock_get(g->global_lock); /* LOCK */
1993 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
1994 adj = MPLS_LIST_HEAD(&session->adj_root);
1995 while (adj) {
1996 if (this_one == MPLS_BOOL_TRUE) {
1997 adj_next = adj;
1998 break;
2001 /* since the entities are sort in the list ... */
2002 if (adj->index > s->adj_index) {
2003 break;
2004 } else if (adj->index == s->adj_index) {
2005 this_one = MPLS_BOOL_TRUE;
2007 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
2010 mpls_lock_release(g->global_lock); /* UNLOCK */
2012 if (adj_next) {
2013 s->adj_index = adj_next->index;
2014 r = MPLS_SUCCESS;
2017 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
2018 return r;
2021 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
2022 ldp_session * s, ldp_addr * a, uint32_t flag)
2024 ldp_global *global = (ldp_global *) handle;
2025 ldp_session *session = NULL;
2026 ldp_addr *addr = NULL;
2027 mpls_return_enum retval = MPLS_FAILURE;
2029 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
2031 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
2033 mpls_lock_get(global->global_lock); /* LOCK */
2035 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
2036 goto ldp_cfg_session_raddr_get_end;
2038 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
2039 goto ldp_cfg_session_raddr_get_end;
2041 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
2042 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
2044 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
2045 a->index = addr->index;
2047 retval = MPLS_SUCCESS;
2049 ldp_cfg_session_raddr_get_end:
2050 mpls_lock_release(global->global_lock); /* UNLOCK */
2052 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
2054 return retval;
2057 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
2058 ldp_session * s, ldp_addr * a, uint32_t flag)
2060 ldp_global *g = (ldp_global *) handle;
2061 ldp_addr *addr = NULL;
2062 mpls_return_enum r = MPLS_FAILURE;
2063 mpls_bool done = MPLS_BOOL_FALSE;
2064 ldp_session *sp = NULL;
2065 int index;
2067 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
2069 if (a->index == 0) {
2070 index = 1;
2071 } else {
2072 index = a->index + 1;
2075 r = ldp_global_find_session_index(g, s->index, &sp);
2076 if (r != MPLS_SUCCESS) {
2077 return r;
2080 mpls_lock_get(g->global_lock); /* LOCK */
2081 while (done == MPLS_BOOL_FALSE) {
2082 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
2083 case MPLS_SUCCESS:
2084 case MPLS_END_OF_LIST:
2085 done = MPLS_BOOL_TRUE;
2086 break;
2087 case MPLS_FAILURE:
2088 break;
2089 default:
2090 MPLS_ASSERT(0);
2092 index++;
2094 mpls_lock_release(g->global_lock); /* UNLOCK */
2096 if (r == MPLS_SUCCESS) {
2097 a->index = addr->index;
2098 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2101 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2102 return r;
2105 /******************* IN LABEL **********************/
2107 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2108 uint32_t flag)
2110 ldp_global *global = (ldp_global *) handle;
2111 ldp_inlabel *inlabel = NULL;
2112 mpls_return_enum retval = MPLS_FAILURE;
2114 MPLS_ASSERT(global !=NULL && i != NULL);
2116 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2118 mpls_lock_get(global->global_lock); /* LOCK */
2120 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2121 goto ldp_cfg_inlabel_get_end;
2123 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2124 i->info.labelspace = inlabel->info.labelspace;
2126 if (flag & LDP_INLABEL_CFG_LABEL) {
2127 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2129 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2130 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2133 retval = MPLS_SUCCESS;
2135 ldp_cfg_inlabel_get_end:
2136 mpls_lock_release(global->global_lock); /* UNLOCK */
2138 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2140 return retval;
2143 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2144 uint32_t flag)
2146 ldp_global *g = (ldp_global *) handle;
2147 ldp_inlabel *inlabel = NULL;
2148 mpls_return_enum r = MPLS_FAILURE;
2149 mpls_bool done = MPLS_BOOL_FALSE;
2150 int index;
2152 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2154 if (i->index == 0) {
2155 index = 1;
2156 } else {
2157 index = i->index + 1;
2160 mpls_lock_get(g->global_lock); /* LOCK */
2161 while (done == MPLS_BOOL_FALSE) {
2162 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2163 case MPLS_SUCCESS:
2164 case MPLS_END_OF_LIST:
2165 done = MPLS_BOOL_TRUE;
2166 break;
2167 case MPLS_FAILURE:
2168 break;
2169 default:
2170 MPLS_ASSERT(0);
2172 index++;
2174 mpls_lock_release(g->global_lock); /* UNLOCK */
2176 if (r == MPLS_SUCCESS) {
2177 i->index = inlabel->index;
2179 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2180 return ldp_cfg_inlabel_get(g, i, flag);
2183 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2185 return r;
2188 /******************* OUT LABEL **********************/
2190 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2191 uint32_t flag)
2193 ldp_global *global = (ldp_global *) handle;
2194 ldp_outlabel *outlabel = NULL;
2195 mpls_return_enum retval = MPLS_FAILURE;
2197 MPLS_ASSERT(global !=NULL && o != NULL);
2199 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2201 mpls_lock_get(global->global_lock); /* LOCK */
2203 if (ldp_global_find_outlabel_index(global, o->index,
2204 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2206 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2207 if (outlabel->nh) {
2208 o->nh_index = outlabel->nh->index;
2209 } else {
2210 o->nh_index = 0;
2213 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2214 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2216 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2217 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2219 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2220 o->merge_count = outlabel->merge_count;
2223 retval = MPLS_SUCCESS;
2225 ldp_cfg_outlabel_get_end:
2226 mpls_lock_release(global->global_lock); /* UNLOCK */
2228 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2230 return retval;
2233 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2234 ldp_outlabel * o, uint32_t flag)
2236 ldp_global *g = (ldp_global *) handle;
2237 ldp_outlabel *outlabel = NULL;
2238 mpls_return_enum r = MPLS_FAILURE;
2239 mpls_bool done = MPLS_BOOL_FALSE;
2240 int index;
2242 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2244 if (o->index == 0) {
2245 index = 1;
2246 } else {
2247 index = o->index + 1;
2250 mpls_lock_get(g->global_lock); /* LOCK */
2251 while (done == MPLS_BOOL_FALSE) {
2252 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2253 case MPLS_SUCCESS:
2254 case MPLS_END_OF_LIST:
2255 done = MPLS_BOOL_TRUE;
2256 break;
2257 case MPLS_FAILURE:
2258 break;
2259 default:
2260 MPLS_ASSERT(0);
2262 index++;
2264 mpls_lock_release(g->global_lock); /* UNLOCK */
2266 if (r == MPLS_SUCCESS) {
2267 o->index = outlabel->index;
2269 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2270 return ldp_cfg_outlabel_get(g, o, flag);
2273 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2275 return r;
2278 /******************* TUNNEL **********************/
2280 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2281 uint32_t flag)
2283 ldp_global *global = (ldp_global *) handle;
2284 mpls_return_enum retval = MPLS_FAILURE;
2285 ldp_tunnel *tunnel = NULL;
2287 MPLS_ASSERT(global !=NULL);
2289 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2291 mpls_lock_get(global->global_lock); /* LOCK */
2293 if (flag & LDP_CFG_ADD) {
2294 if (!(tunnel = ldp_tunnel_create())) {
2295 goto ldp_cfg_tunnel_set_end;
2297 _ldp_global_add_tunnel(global, tunnel);
2299 t->index = tunnel->index;
2300 } else {
2301 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2304 if (!tunnel) {
2305 LDP_PRINT(global->user_data,
2307 "ldp_cfg_tunnel_set:could not create tunnel\n");
2308 goto ldp_cfg_tunnel_set_end;
2311 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2312 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2313 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2315 goto ldp_cfg_tunnel_set_end;
2318 if (flag & LDP_CFG_DEL) {
2319 if (tunnel->outlabel)
2320 ldp_tunnel_del_outlabel(tunnel);
2321 if (tunnel->resource)
2322 ldp_tunnel_del_resource(tunnel);
2323 if (tunnel->hop_list)
2324 ldp_tunnel_del_hop_list(tunnel);
2325 _ldp_global_del_tunnel(global, tunnel);
2327 retval = MPLS_SUCCESS;
2328 goto ldp_cfg_tunnel_set_end;
2331 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2332 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2334 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2335 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2337 if (flag & LDP_TUNNEL_CFG_NAME) {
2338 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2340 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2341 tunnel->is_interface = t->is_interface;
2343 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2344 ldp_outlabel *outlabel = NULL;
2346 if (t->outlabel_index) {
2347 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2349 if (!outlabel) {
2350 goto ldp_cfg_tunnel_set_end;
2352 ldp_tunnel_add_outlabel(tunnel, outlabel);
2353 } else {
2354 ldp_tunnel_del_outlabel(tunnel);
2357 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2358 tunnel->setup_prio = t->setup_prio;
2360 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2361 tunnel->hold_prio = t->hold_prio;
2363 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2364 tunnel->instance_prio = t->instance_prio;
2366 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2367 tunnel->local_protect = t->local_protect;
2369 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2370 ldp_resource *resource = NULL;
2372 if (t->resource_index) {
2373 ldp_global_find_resource_index(global, t->resource_index, &resource);
2375 if (!resource) {
2376 goto ldp_cfg_tunnel_set_end;
2378 ldp_tunnel_add_resource(tunnel, resource);
2379 } else {
2380 ldp_tunnel_del_resource(tunnel);
2383 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2384 ldp_hop_list *hop_list = NULL;
2386 if (t->hop_list_index) {
2387 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2389 if (!hop_list) {
2390 goto ldp_cfg_tunnel_set_end;
2392 ldp_tunnel_add_hop_list(tunnel, hop_list);
2393 } else {
2394 ldp_tunnel_del_hop_list(tunnel);
2397 if (flag & LDP_TUNNEL_CFG_FEC) {
2398 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2400 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2401 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2402 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2403 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2404 goto ldp_cfg_tunnel_set_end;
2407 } else {
2408 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2409 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2410 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2411 goto ldp_cfg_tunnel_set_end;
2413 } else {
2414 LDP_PRINT(global->user_data,
2416 "ldp_cfg_tunnel_set: tunnel not ready\n");
2417 goto ldp_cfg_tunnel_set_end;
2422 retval = MPLS_SUCCESS;
2424 ldp_cfg_tunnel_set_end:
2426 mpls_lock_release(global->global_lock); /* UNLOCK */
2428 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2430 return retval;
2433 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2434 uint32_t flag)
2436 ldp_global *global = (ldp_global *) handle;
2437 mpls_return_enum retval = MPLS_FAILURE;
2438 ldp_tunnel *tunnel = NULL;
2440 MPLS_ASSERT(global !=NULL);
2442 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2444 mpls_lock_get(global->global_lock); /* LOCK */
2446 if (flag & LDP_CFG_ADD) {
2447 retval = MPLS_SUCCESS;
2448 goto ldp_cfg_tunnel_test_end;
2451 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2453 if (!tunnel) {
2454 goto ldp_cfg_tunnel_test_end;
2457 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2458 ldp_resource *resource = NULL;
2460 if (t->resource_index) {
2461 ldp_global_find_resource_index(global, t->resource_index, &resource);
2463 if (!resource) {
2464 goto ldp_cfg_tunnel_test_end;
2468 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2469 ldp_hop_list *hop_list = NULL;
2471 if (t->hop_list_index) {
2472 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2474 if (!hop_list) {
2475 goto ldp_cfg_tunnel_test_end;
2479 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2480 ldp_outlabel *outlabel = NULL;
2482 if (t->outlabel_index) {
2483 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2485 if (!outlabel) {
2486 goto ldp_cfg_tunnel_test_end;
2490 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2491 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2492 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2493 goto ldp_cfg_tunnel_test_end;
2495 retval = MPLS_SUCCESS;
2497 ldp_cfg_tunnel_test_end:
2499 mpls_lock_release(global->global_lock); /* UNLOCK */
2501 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2503 return retval;
2506 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2507 uint32_t flag)
2509 ldp_global *global = (ldp_global *) handle;
2510 mpls_return_enum retval = MPLS_FAILURE;
2511 ldp_tunnel *tunnel = NULL;
2513 MPLS_ASSERT(global !=NULL);
2515 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2517 mpls_lock_get(global->global_lock); /* LOCK */
2519 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2521 if (!tunnel) {
2522 goto ldp_cfg_tunnel_get_end;
2524 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2525 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2527 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2528 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2530 if (flag & LDP_TUNNEL_CFG_NAME) {
2531 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2533 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2534 t->is_interface = tunnel->is_interface;
2536 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2537 if (tunnel->outlabel) {
2538 t->outlabel_index = tunnel->outlabel->index;
2539 } else {
2540 t->outlabel_index = 0;
2543 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2544 t->setup_prio = tunnel->setup_prio;
2546 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2547 t->hold_prio = tunnel->hold_prio;
2549 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2550 tunnel->instance_prio = t->instance_prio;
2552 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2553 tunnel->local_protect = t->local_protect;
2555 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2556 if (tunnel->resource) {
2557 t->resource_index = tunnel->resource->index;
2558 } else {
2559 t->resource_index = 0;
2562 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2563 if (tunnel->hop_list) {
2564 t->hop_list_index = tunnel->hop_list->index;
2565 } else {
2566 t->hop_list_index = 0;
2569 if (flag & LDP_TUNNEL_CFG_FEC) {
2570 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2572 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2573 t->admin_state = tunnel->admin_state;
2575 retval = MPLS_SUCCESS;
2577 ldp_cfg_tunnel_get_end:
2579 mpls_lock_release(global->global_lock); /* UNLOCK */
2581 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2583 return retval;
2586 /******************* RESOURCE **********************/
2588 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2589 uint32_t flag)
2591 ldp_global *global = (ldp_global *) handle;
2592 mpls_return_enum retval = MPLS_FAILURE;
2593 ldp_resource *resource = NULL;
2595 MPLS_ASSERT(global !=NULL);
2597 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2599 mpls_lock_get(global->global_lock); /* LOCK */
2601 if (flag & LDP_CFG_ADD) {
2602 resource = ldp_resource_create();
2603 _ldp_global_add_resource(global, resource);
2605 r->index = resource->index;
2606 } else {
2607 ldp_global_find_resource_index(global, r->index, &resource);
2610 if (!resource) {
2611 goto ldp_cfg_resource_set_end;
2614 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2615 resource->max_rate = r->max_rate;
2617 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2618 resource->mean_rate = r->mean_rate;
2620 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2621 resource->burst_size = r->burst_size;
2623 retval = MPLS_SUCCESS;
2625 ldp_cfg_resource_set_end:
2627 mpls_lock_release(global->global_lock); /* UNLOCK */
2629 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2631 return retval;
2634 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2635 uint32_t flag)
2637 ldp_global *global = (ldp_global *) handle;
2638 mpls_return_enum retval = MPLS_FAILURE;
2639 ldp_resource *resource = NULL;
2641 MPLS_ASSERT(global !=NULL);
2643 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2645 mpls_lock_get(global->global_lock); /* LOCK */
2647 if (flag & LDP_CFG_ADD) {
2648 retval = MPLS_SUCCESS;
2649 goto ldp_cfg_resource_test_end;
2652 ldp_global_find_resource_index(global, r->index, &resource);
2654 if (!resource) {
2655 goto ldp_cfg_resource_test_end;
2658 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2659 goto ldp_cfg_resource_test_end;
2661 retval = MPLS_SUCCESS;
2663 ldp_cfg_resource_test_end:
2665 mpls_lock_release(global->global_lock); /* UNLOCK */
2667 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2669 return retval;
2672 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2673 uint32_t flag)
2675 ldp_global *global = (ldp_global *) handle;
2676 mpls_return_enum retval = MPLS_FAILURE;
2677 ldp_resource *resource = NULL;
2679 MPLS_ASSERT(global !=NULL);
2681 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2683 mpls_lock_get(global->global_lock); /* LOCK */
2685 ldp_global_find_resource_index(global, r->index, &resource);
2687 if (!resource) {
2688 goto ldp_cfg_resource_get_end;
2691 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2692 r->max_rate = resource->max_rate;
2694 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2695 r->mean_rate = resource->mean_rate;
2697 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2698 r->burst_size = resource->burst_size;
2700 retval = MPLS_SUCCESS;
2702 ldp_cfg_resource_get_end:
2704 mpls_lock_release(global->global_lock); /* UNLOCK */
2706 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2708 return retval;
2711 /******************* HOP **********************/
2713 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2714 uint32_t flag)
2716 ldp_global *global = (ldp_global *) handle;
2717 mpls_return_enum retval = MPLS_FAILURE;
2718 ldp_hop_list *hop_list = NULL;
2719 ldp_hop *hop = NULL;
2721 MPLS_ASSERT(global !=NULL);
2723 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2725 if (!h->hop_list_index && !h->index) {
2726 return retval;
2729 mpls_lock_get(global->global_lock); /* LOCK */
2731 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2733 if (!hop_list) {
2734 if (flag & LDP_CFG_ADD) {
2735 if (!(hop_list = ldp_hop_list_create())) {
2736 goto ldp_cfg_hop_set_end;
2738 _ldp_global_add_hop_list(global, hop_list);
2740 h->hop_list_index = hop_list->index;
2741 } else {
2742 goto ldp_cfg_hop_set_end;
2746 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2747 if (!hop) {
2748 if (h->index && (flag & LDP_CFG_ADD)) {
2749 if (!(hop = ldp_hop_create())) {
2750 goto ldp_cfg_hop_set_end;
2752 hop->index = h->index;
2753 ldp_hop_list_add_hop(hop_list, hop);
2754 } else {
2755 goto ldp_cfg_hop_set_end;
2759 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2760 hop->path_option = h->path_option;
2762 if (flag & LDP_HOP_CFG_ADDR) {
2763 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2765 if (flag & LDP_HOP_CFG_TYPE) {
2766 hop->type = h->type;
2768 retval = MPLS_SUCCESS;
2770 ldp_cfg_hop_set_end:
2772 mpls_lock_release(global->global_lock); /* UNLOCK */
2774 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2776 return retval;
2779 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2780 uint32_t flag)
2782 ldp_global *global = (ldp_global *) handle;
2783 mpls_return_enum retval = MPLS_FAILURE;
2784 ldp_hop_list *hop_list = NULL;
2785 ldp_hop *hop = NULL;
2787 MPLS_ASSERT(global !=NULL);
2789 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2791 mpls_lock_get(global->global_lock); /* LOCK */
2793 if (flag & LDP_CFG_ADD) {
2794 retval = MPLS_SUCCESS;
2795 goto ldp_cfg_hop_test_end;
2798 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2800 if (!hop_list) {
2801 goto ldp_cfg_hop_test_end;
2804 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2805 if (!hop) {
2806 goto ldp_cfg_hop_test_end;
2809 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2810 goto ldp_cfg_hop_test_end;
2812 retval = MPLS_SUCCESS;
2814 ldp_cfg_hop_test_end:
2816 mpls_lock_release(global->global_lock); /* UNLOCK */
2818 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2820 return retval;
2823 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2824 uint32_t flag)
2826 ldp_global *global = (ldp_global *) handle;
2827 mpls_return_enum retval = MPLS_FAILURE;
2828 ldp_hop_list *hop_list = NULL;
2829 ldp_hop *hop = NULL;
2831 MPLS_ASSERT(global !=NULL);
2833 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2835 mpls_lock_get(global->global_lock); /* LOCK */
2837 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2839 if (!hop_list) {
2840 goto ldp_cfg_hop_get_end;
2843 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2844 if (!hop) {
2845 goto ldp_cfg_hop_get_end;
2848 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2849 h->path_option = hop->path_option;
2851 if (flag & LDP_HOP_CFG_ADDR) {
2852 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2854 if (flag & LDP_HOP_CFG_TYPE) {
2855 h->type = hop->type;
2857 retval = MPLS_SUCCESS;
2859 ldp_cfg_hop_get_end:
2861 mpls_lock_release(global->global_lock); /* UNLOCK */
2863 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2865 return retval;