In the case of a route being and there is not an alternate
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blob72b94818afc041305d674c1a440ba0d4eba7f801
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 void ldp_cfg_global_attr(mpls_cfg_handle handle) {
50 ldp_global *global = (ldp_global *) handle;
51 ldp_attr *attr = MPLS_LIST_HEAD(&global->attr);
52 while (attr) {
53 if (attr->state == LDP_LSP_STATE_MAP_SENT && attr->ds_attr) {
54 fprintf(stderr, "%p(%s) xc to %p(%s)\n", attr,
55 attr->session->session_name, attr->ds_attr,
56 attr->ds_attr->session->session_name);
58 attr = MPLS_LIST_NEXT(&global->attr, attr, _global);
62 mpls_return_enum ldp_cfg_global_get(mpls_cfg_handle handle, ldp_global * g,
63 uint32_t flag)
65 ldp_global *global = (ldp_global *) handle;
67 MPLS_ASSERT(global !=NULL);
69 LDP_ENTER(global->user_data, "ldp_cfg_global_get");
71 mpls_lock_get(global->global_lock); /* LOCK */
73 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
74 memcpy(&(g->lsr_identifier), &(global->lsr_identifier),
75 sizeof(mpls_inet_addr));
77 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
78 g->admin_state = global->admin_state;
80 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
81 g->lsp_control_mode = global->lsp_control_mode;
83 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
84 g->label_retention_mode = global->label_retention_mode;
86 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
87 g->lsp_repair_mode = global->lsp_repair_mode;
89 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
90 g->propagate_release = global->propagate_release;
92 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
93 g->label_merge = global->label_merge;
95 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
96 g->loop_detection_mode = global->loop_detection_mode;
98 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
99 g->ttl_less_domain = global->ttl_less_domain;
101 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
102 g->local_tcp_port = global->local_tcp_port;
104 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
105 g->local_udp_port = global->local_udp_port;
107 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
108 memcpy(&(g->transport_address), &(global->transport_address),
109 sizeof(mpls_inet_addr));
111 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
112 g->keepalive_timer = global->keepalive_timer;
114 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
115 g->keepalive_interval = global->keepalive_interval;
117 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
118 g->hellotime_timer = global->hellotime_timer;
120 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
121 g->hellotime_interval = global->hellotime_interval;
123 #if MPLS_USE_LSR
124 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
125 g->lsr_handle = global->lsr_handle;
127 #endif
129 mpls_lock_release(global->global_lock); /* UNLOCK */
131 LDP_EXIT(global->user_data, "ldp_cfg_global_get");
133 return MPLS_SUCCESS;
136 mpls_return_enum ldp_cfg_global_test(mpls_cfg_handle handle, ldp_global * g,
137 uint32_t flag)
139 ldp_global *global = (ldp_global *) handle;
140 mpls_return_enum retval = MPLS_SUCCESS;
142 MPLS_ASSERT(global !=NULL);
144 LDP_ENTER(global->user_data, "ldp_cfg_global_test");
146 mpls_lock_get(global->global_lock); /* LOCK */
148 if (global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN))
149 retval = MPLS_FAILURE;
151 mpls_lock_release(global->global_lock); /* UNLOCK */
153 LDP_EXIT(global->user_data, "ldp_cfg_global_test");
155 return retval;
158 mpls_return_enum ldp_cfg_global_set(mpls_cfg_handle handle, ldp_global * g,
159 uint32_t flag)
161 ldp_global *global = (ldp_global *) handle;
162 mpls_return_enum retval = MPLS_FAILURE;
164 MPLS_ASSERT(global !=NULL);
166 LDP_ENTER(global->user_data, "ldp_cfg_global_set");
168 mpls_lock_get(global->global_lock); /* LOCK */
170 if ((global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN)))
171 goto ldp_cfg_global_set_end;
173 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
174 global->lsp_control_mode = g->lsp_control_mode;
176 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
177 global->label_retention_mode = g->label_retention_mode;
179 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
180 global->lsp_repair_mode = g->lsp_repair_mode;
182 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
183 global->propagate_release = g->propagate_release;
185 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
186 global->label_merge = g->label_merge;
188 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
189 global->loop_detection_mode = g->loop_detection_mode;
191 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
192 global->ttl_less_domain = g->ttl_less_domain;
194 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
195 global->local_tcp_port = g->local_tcp_port;
197 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
198 global->local_udp_port = g->local_udp_port;
200 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
201 memcpy(&(global->lsr_identifier), &(g->lsr_identifier),
202 sizeof(mpls_inet_addr));
204 #if MPLS_USE_LSR
205 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
206 global->lsr_handle = g->lsr_handle;
208 #endif
209 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
210 if (global->admin_state == MPLS_ADMIN_ENABLE && g->admin_state == MPLS_ADMIN_DISABLE) {
211 ldp_global_shutdown(global);
212 } else if (global->admin_state == MPLS_ADMIN_DISABLE && g->admin_state ==
213 MPLS_ADMIN_ENABLE) {
214 ldp_global_startup(global);
217 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
218 memcpy(&(global->transport_address), &(g->transport_address),
219 sizeof(mpls_inet_addr));
221 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
222 if (g->keepalive_timer == 0) {
223 global->keepalive_timer = LDP_ENTITY_DEF_KEEPALIVE_TIMER;
224 } else {
225 global->keepalive_timer = g->keepalive_timer;
228 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
229 if (g->keepalive_interval == 0) {
230 global->keepalive_interval = LDP_ENTITY_DEF_KEEPALIVE_INTERVAL;
231 } else {
232 global->keepalive_interval = g->keepalive_interval;
235 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
236 if (g->hellotime_timer == 0) {
237 global->hellotime_timer = LDP_ENTITY_DEF_HELLOTIME_TIMER;
238 } else {
239 global->hellotime_timer = g->hellotime_timer;
242 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
243 if (g->hellotime_interval == 0) {
244 global->hellotime_interval = LDP_ENTITY_DEF_HELLOTIME_INTERVAL;
245 } else {
246 global->hellotime_interval = g->hellotime_interval;
249 #if MPLS_USE_LSR
250 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
251 global->lsr_handle = g->lsr_handle ;
253 #endif
254 global->configuration_sequence_number++;
256 retval = MPLS_SUCCESS;
258 ldp_cfg_global_set_end:
260 mpls_lock_release(global->global_lock); /* UNLOCK */
262 LDP_EXIT(global->user_data, "ldp_cfg_global_set");
264 return retval;
267 /******************* ENTITY **********************/
269 /* must set ldp_entity->index */
270 mpls_return_enum ldp_cfg_entity_get(mpls_cfg_handle handle, ldp_entity * e,
271 uint32_t flag)
273 ldp_global *global = (ldp_global *) handle;
274 ldp_entity *entity = NULL;
275 mpls_return_enum retval = MPLS_FAILURE;
277 MPLS_ASSERT(global !=NULL && e != NULL);
279 LDP_ENTER(global->user_data, "ldp_cfg_entity_get");
281 mpls_lock_get(global->global_lock); /* LOCK */
283 if (ldp_global_find_entity_index(global, e->index, &entity) != MPLS_SUCCESS)
284 goto ldp_cfg_entity_get_end;
286 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
287 e->admin_state = entity->admin_state;
289 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
290 e->transport_address = entity->transport_address;
292 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
293 e->protocol_version = entity->protocol_version;
295 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
296 e->remote_tcp_port = entity->remote_tcp_port;
298 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
299 e->remote_udp_port = entity->remote_udp_port;
301 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
302 e->max_pdu = entity->max_pdu;
304 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
305 e->keepalive_timer = entity->keepalive_timer;
307 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
308 e->keepalive_interval = entity->keepalive_interval;
310 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
311 e->hellotime_timer = entity->hellotime_timer;
313 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
314 e->hellotime_interval = entity->hellotime_interval;
316 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
317 e->session_setup_count = entity->session_setup_count;
319 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
320 e->session_backoff_timer = entity->session_backoff_timer;
322 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
323 e->label_distribution_mode = entity->label_distribution_mode;
325 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
326 e->path_vector_limit = entity->path_vector_limit;
328 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
329 e->hop_count_limit = entity->hop_count_limit;
331 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
332 e->label_request_count = entity->label_request_count;
334 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
335 e->label_request_timer = entity->label_request_timer;
337 if (flag & LDP_ENTITY_CFG_TYPE) {
338 e->entity_type = entity->entity_type;
340 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
341 e->sub_index = entity->sub_index;
343 if (flag & LDP_ENTITY_CFG_MESG_TX) {
344 e->mesg_tx = entity->mesg_tx;
346 if (flag & LDP_ENTITY_CFG_MESG_RX) {
347 e->mesg_rx = entity->mesg_rx;
349 if (flag & LDP_ENTITY_CFG_ADJ_COUNT) {
350 e->adj_count = entity->adj_root.count;
352 if (flag & LDP_ENTITY_CFG_ADJ_INDEX) {
353 ldp_adj *a = MPLS_LIST_HEAD(&entity->adj_root);
354 e->adj_index = a ? a->index : 0;
356 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
357 e->inherit_flag = entity->inherit_flag;
359 retval = MPLS_SUCCESS;
361 ldp_cfg_entity_get_end:
363 mpls_lock_release(global->global_lock); /* UNLOCK */
365 LDP_EXIT(global->user_data, "ldp_cfg_entity_get");
367 return retval;
370 mpls_return_enum ldp_cfg_entity_getnext(mpls_cfg_handle handle, ldp_entity * e,
371 uint32_t flag)
373 ldp_global *g = (ldp_global *) handle;
374 ldp_entity *entity = NULL;
375 mpls_return_enum r = MPLS_FAILURE;
376 mpls_bool done = MPLS_BOOL_FALSE;
377 int index;
379 LDP_ENTER(g->user_data, "ldp_cfg_entity_getnext");
381 if (e->index == 0) {
382 index = 1;
383 } else {
384 index = e->index + 1;
387 mpls_lock_get(g->global_lock); /* LOCK */
388 while (done == MPLS_BOOL_FALSE) {
389 switch ((r = ldp_global_find_entity_index(g, index, &entity))) {
390 case MPLS_SUCCESS:
391 case MPLS_END_OF_LIST:
392 done = MPLS_BOOL_TRUE;
393 break;
394 case MPLS_FAILURE:
395 break;
396 default:
397 MPLS_ASSERT(0);
399 index++;
401 mpls_lock_release(g->global_lock); /* UNLOCK */
403 if (r == MPLS_SUCCESS) {
404 e->index = entity->index;
405 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
406 return ldp_cfg_entity_get(g, e, flag);
408 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
409 return r;
412 mpls_return_enum ldp_cfg_entity_test(mpls_cfg_handle handle, ldp_entity * e,
413 uint32_t flag)
415 ldp_global *global = (ldp_global *) handle;
416 ldp_entity *entity = NULL;
417 mpls_return_enum retval = MPLS_FAILURE;
419 MPLS_ASSERT(global !=NULL);
421 LDP_ENTER(global->user_data, "ldp_cfg_entity_test");
423 mpls_lock_get(global->global_lock); /* LOCK */
425 if (!(flag & LDP_CFG_ADD)) {
426 if (e == NULL)
427 goto ldp_cfg_entity_test_end;
429 ldp_global_find_entity_index(global, e->index, &entity);
430 } else {
431 retval = MPLS_SUCCESS;
432 goto ldp_cfg_entity_test_end;
435 if (entity == NULL) {
436 goto ldp_cfg_entity_test_end;
439 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
440 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
441 goto ldp_cfg_entity_test_end;
444 retval = MPLS_SUCCESS;
446 ldp_cfg_entity_test_end:
447 mpls_lock_release(global->global_lock); /* UNLOCK */
449 LDP_EXIT(global->user_data, "ldp_cfg_entity_test");
451 return retval;
454 /* must set ldp_entity->index if not an add */
455 mpls_return_enum ldp_cfg_entity_set(mpls_cfg_handle handle, ldp_entity * e,
456 uint32_t flag)
458 ldp_global *global = (ldp_global *) handle;
459 ldp_entity *entity = NULL;
460 mpls_return_enum retval = MPLS_FAILURE;
462 MPLS_ASSERT(global !=NULL && e != NULL);
464 LDP_ENTER(global->user_data, "ldp_cfg_entity_set");
466 mpls_lock_get(global->global_lock); /* LOCK */
468 if (flag & LDP_CFG_ADD) {
469 entity = ldp_entity_create();
470 _ldp_global_add_entity(global, entity);
472 e->index = entity->index;
473 } else {
474 ldp_global_find_entity_index(global, e->index, &entity);
477 if (entity == NULL) {
478 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: can't find entity\n");
479 goto ldp_cfg_entity_set_end;
482 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
483 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
484 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity is active\n");
485 goto ldp_cfg_entity_set_end;
488 if (flag & LDP_CFG_DEL) {
489 switch (entity->entity_type) {
490 case LDP_DIRECT:
491 ldp_entity_del_if(global, entity);
492 break;
493 case LDP_INDIRECT:
494 ldp_entity_del_peer(entity);
495 break;
496 default:
497 MPLS_ASSERT(0);
499 _ldp_global_del_entity(global, entity);
501 retval = MPLS_SUCCESS;
502 goto ldp_cfg_entity_set_end;
505 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
506 if (entity->sub_index != 0) {
507 /* unlink the old sub object */
508 switch (entity->entity_type) {
509 case LDP_DIRECT:
510 ldp_entity_del_if(global, entity);
511 break;
512 case LDP_INDIRECT:
513 ldp_entity_del_peer(entity);
514 break;
515 default:
516 MPLS_ASSERT(0);
520 /* link the new sub object */
521 switch (e->entity_type) {
522 case LDP_DIRECT:
524 ldp_if *iff = NULL;
525 if (ldp_global_find_if_index(global, e->sub_index,
526 &iff) != MPLS_SUCCESS) {
527 LDP_PRINT(global->user_data,
528 "ldp_cfg_entity_set: no such interface\n");
530 if (flag & LDP_CFG_ADD) {
531 _ldp_global_del_entity(global, entity);
533 goto ldp_cfg_entity_set_end;
535 ldp_entity_add_if(entity, iff);
536 break;
538 case LDP_INDIRECT:
540 ldp_peer *peer = NULL;
542 if (ldp_global_find_peer_index(global, e->sub_index, &peer) !=
543 MPLS_SUCCESS) {
544 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: no such peer\n");
546 if (flag & LDP_CFG_ADD) {
547 _ldp_global_del_entity(global, entity);
549 goto ldp_cfg_entity_set_end;
551 ldp_entity_add_peer(entity, peer);
552 break;
554 default:
555 MPLS_ASSERT(0);
559 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
560 if (e->transport_address.type == MPLS_FAMILY_NONE) {
561 entity->inherit_flag |= LDP_ENTITY_CFG_TRANS_ADDR;
562 } else {
563 entity->inherit_flag &= ~LDP_ENTITY_CFG_TRANS_ADDR;
565 memcpy(&entity->transport_address, &e->transport_address,
566 sizeof(mpls_inet_addr));;
568 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
569 entity->protocol_version = e->protocol_version;
571 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
572 entity->remote_tcp_port = e->remote_tcp_port;
574 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
575 entity->remote_udp_port = e->remote_udp_port;
577 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
578 entity->max_pdu = e->max_pdu;
580 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
581 if (e->transport_address.type == MPLS_FAMILY_NONE) {
582 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_TIMER;
583 } else {
584 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER;
586 entity->keepalive_timer = e->keepalive_timer;
588 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
589 if (e->transport_address.type == MPLS_FAMILY_NONE) {
590 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
591 } else {
592 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
594 entity->keepalive_interval = e->keepalive_interval;
596 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
597 if (e->transport_address.type == MPLS_FAMILY_NONE) {
598 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_TIMER;
599 } else {
600 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_TIMER;
602 entity->hellotime_timer = e->hellotime_timer;
604 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
605 if (e->transport_address.type == MPLS_FAMILY_NONE) {
606 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
607 } else {
608 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
610 entity->hellotime_interval = e->hellotime_interval;
612 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
613 entity->session_setup_count = e->session_setup_count;
615 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
616 entity->session_backoff_timer = e->session_backoff_timer;
618 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
619 entity->label_distribution_mode = e->label_distribution_mode;
621 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
622 entity->path_vector_limit = e->path_vector_limit;
624 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
625 entity->hop_count_limit = e->hop_count_limit;
627 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
628 entity->label_request_count = e->label_request_count;
630 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
631 entity->label_request_timer = e->label_request_timer;
633 if (flag & LDP_ENTITY_CFG_TYPE) {
634 entity->entity_type = e->entity_type;
636 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
637 if (ldp_entity_is_active(entity) == MPLS_BOOL_TRUE &&
638 e->admin_state == MPLS_ADMIN_DISABLE) {
639 if (ldp_entity_shutdown(global, entity, 0) == MPLS_FAILURE) {
640 goto ldp_cfg_entity_set_end;
642 } else if (ldp_entity_is_active(entity) == MPLS_BOOL_FALSE &&
643 e->admin_state == MPLS_ADMIN_ENABLE && ldp_entity_is_ready(entity) == MPLS_BOOL_TRUE) {
644 if (ldp_entity_startup(global, entity) == MPLS_FAILURE) {
645 goto ldp_cfg_entity_set_end;
647 } else {
648 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity not ready\n");
650 goto ldp_cfg_entity_set_end;
653 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
654 entity->inherit_flag = e->inherit_flag;
656 global->configuration_sequence_number++;
658 retval = MPLS_SUCCESS;
660 ldp_cfg_entity_set_end:
661 mpls_lock_release(global->global_lock); /* UNLOCK */
663 LDP_EXIT(global->user_data, "ldp_cfg_entity_set");
665 return retval;
668 mpls_return_enum ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle,
669 ldp_entity * e)
671 ldp_global *g = (ldp_global *) handle;
672 mpls_bool this_one = MPLS_BOOL_FALSE;
673 mpls_return_enum r = MPLS_FAILURE;
674 ldp_adj *adj_next = NULL;
675 ldp_adj *adj = NULL;
676 ldp_entity *entity = NULL;
678 LDP_ENTER(g->user_data, "ldp_cfg_entity_adj_getnext");
680 /* if an adj_index of zero is sent, get the index of
681 * the first adj in the list
683 if (!e->adj_index) {
684 this_one = MPLS_BOOL_TRUE;
687 mpls_lock_get(g->global_lock); /* LOCK */
689 if (ldp_global_find_entity_index(g, e->index, &entity) == MPLS_SUCCESS) {
690 adj = MPLS_LIST_HEAD(&entity->adj_root);
691 while (adj) {
692 if (this_one == MPLS_BOOL_TRUE) {
693 adj_next = adj;
694 break;
697 /* since the entities are sort in the list ... */
698 if (adj->index > e->adj_index) {
699 break;
700 } else if (adj->index == e->adj_index) {
701 this_one = MPLS_BOOL_TRUE;
703 adj = MPLS_LIST_NEXT(&entity->adj_root, adj, _entity);
706 mpls_lock_release(g->global_lock); /* UNLOCK */
708 if (adj_next) {
709 e->adj_index = adj_next->index;
710 r = MPLS_SUCCESS;
713 LDP_EXIT(g->user_data, "ldp_cfg_entity_adj_getnext");
714 return r;
717 /******************* INTERFACE **********************/
719 mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
721 ldp_global *global = (ldp_global *) handle;
722 ldp_if *iff = NULL;
723 mpls_return_enum retval = MPLS_FAILURE;
725 MPLS_ASSERT(global !=NULL && i != NULL);
727 LDP_ENTER(global->user_data, "ldp_cfg_if_get");
729 mpls_lock_get(global->global_lock); /* LOCK */
731 if (flag & LDP_IF_CFG_BY_INDEX) {
732 ldp_global_find_if_index(global, i->index, &iff);
733 } else {
734 iff = ldp_global_find_if_handle(global, i->handle);
736 if (!iff)
737 goto ldp_cfg_if_get_end;
739 if (flag & LDP_IF_CFG_LABEL_SPACE) {
740 i->label_space = iff->label_space;
742 if (flag & LDP_IF_CFG_ENTITY_INDEX) {
743 i->entity_index = iff->entity ? iff->entity->index : 0;
745 if (flag & LDP_IF_CFG_OPER_STATE) {
746 i->oper_state = iff->oper_state;
748 if (flag & LDP_IF_CFG_HANDLE) {
749 memcpy(&i->handle, &iff->handle, sizeof(mpls_if_handle));
751 retval = MPLS_SUCCESS;
753 ldp_cfg_if_get_end:
754 mpls_lock_release(global->global_lock); /* UNLOCK */
756 LDP_EXIT(global->user_data, "ldp_cfg_if_get");
758 return retval;
761 mpls_return_enum ldp_cfg_if_getnext(mpls_cfg_handle handle, ldp_if * i,
762 uint32_t flag)
764 ldp_global *g = (ldp_global *) handle;
765 ldp_if *iff = NULL;
766 mpls_return_enum r = MPLS_FAILURE;
767 mpls_bool done = MPLS_BOOL_FALSE;
768 int index;
770 LDP_ENTER(g->user_data, "ldp_cfg_if_getnext");
772 if (i->index == 0) {
773 index = 1;
774 } else {
775 index = i->index + 1;
778 mpls_lock_get(g->global_lock); /* LOCK */
779 while (done == MPLS_BOOL_FALSE) {
780 switch ((r = ldp_global_find_if_index(g, index, &iff))) {
781 case MPLS_SUCCESS:
782 case MPLS_END_OF_LIST:
783 done = MPLS_BOOL_TRUE;
784 break;
785 case MPLS_FAILURE:
786 break;
787 default:
788 MPLS_ASSERT(0);
790 index++;
792 mpls_lock_release(g->global_lock); /* UNLOCK */
794 if (r == MPLS_SUCCESS) {
795 i->index = iff->index;
796 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
797 return ldp_cfg_if_get(g, i, flag);
799 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
800 return r;
803 mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i,
804 uint32_t flag)
806 ldp_global *global = (ldp_global *) handle;
807 ldp_if *iff = NULL;
808 mpls_return_enum retval = MPLS_FAILURE;
810 MPLS_ASSERT(global !=NULL && i != NULL);
812 LDP_ENTER(global->user_data, "ldp_cfg_if_test");
814 mpls_lock_get(global->global_lock); /* LOCK */
816 if (!(flag & LDP_CFG_ADD)) {
817 ldp_global_find_if_index(global, i->index, &iff);
818 } else {
819 retval = MPLS_SUCCESS;
820 goto ldp_cfg_if_test_end;
823 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
824 (flag & LDP_IF_CFG_WHEN_DOWN))) {
825 goto ldp_cfg_if_test_end;
828 if (flag & LDP_CFG_DEL) {
829 if (iff->entity != NULL) {
830 goto ldp_cfg_if_test_end;
833 retval = MPLS_SUCCESS;
835 ldp_cfg_if_test_end:
836 mpls_lock_release(global->global_lock); /* UNLOCK */
838 LDP_EXIT(global->user_data, "ldp_cfg_if_test");
840 return retval;
843 mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
845 ldp_global *global = (ldp_global*)handle;
846 ldp_if *iff = NULL;
847 ldp_addr *ap;
848 ldp_nexthop *np;
849 mpls_return_enum retval = MPLS_FAILURE;
851 MPLS_ASSERT(global !=NULL && i != NULL);
853 LDP_ENTER(global->user_data, "ldp_cfg_if_set");
855 mpls_lock_get(global->global_lock); /* LOCK */
857 if (flag & LDP_CFG_ADD) {
858 /* duplicate interface handles are not allowed */
859 /* ADDs require a valid interface handle */
860 if (((iff = ldp_global_find_if_handle(global, i->handle)) != NULL) ||
861 (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==
862 MPLS_BOOL_FALSE) || ((iff = ldp_if_create(global)) == NULL)) {
863 goto ldp_cfg_if_set_end;
866 /* copy the handle from the user */
867 iff->handle = i->handle;
869 /* search for addrs and nexthops that are waiting for this interface */
870 ap = MPLS_LIST_HEAD(&global->addr);
871 while (ap) {
872 if (ap->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(ap, _if))) {
873 ldp_if_add_addr(iff, ap);
875 ap = MPLS_LIST_NEXT(&global->addr, ap, _global);
878 np = MPLS_LIST_HEAD(&global->nexthop);
879 while (np) {
880 if ((np->info.type & MPLS_NH_IF) &&
881 (np->info.if_handle == iff->handle) && (!MPLS_LIST_IN_LIST(np, _if))) {
882 ldp_if_add_nexthop(iff, np);
884 np = MPLS_LIST_NEXT(&global->nexthop, np, _global);
887 /* send the newly created index back to the user */
888 i->index = iff->index;
889 MPLS_REFCNT_HOLD(iff);
891 } else {
892 if (flag & LDP_IF_CFG_BY_INDEX) {
893 ldp_global_find_if_index(global, i->index, &iff);
894 } else {
895 iff = ldp_global_find_if_handle(global, i->handle);
900 * if we can't find this interface or if the interface is active and
901 * we are trying to change propertises that can not be changed on a
902 * active interface
904 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
905 (flag & LDP_IF_CFG_WHEN_DOWN))) {
906 goto ldp_cfg_if_set_end;
909 if (flag & LDP_IF_CFG_LABEL_SPACE) {
910 iff->label_space = i->label_space;
913 if (flag & LDP_CFG_DEL) {
915 * if this interface is still attached to a entity that it is not ready
916 * to be removed
918 if (iff->entity != NULL) {
919 goto ldp_cfg_if_set_end;
922 np = MPLS_LIST_HEAD(&iff->nh_root);
923 while ((np = MPLS_LIST_HEAD(&iff->nh_root))) {
924 ldp_if_del_nexthop(global, iff, np);
927 ap = MPLS_LIST_HEAD(&iff->addr_root);
928 while ((ap = MPLS_LIST_HEAD(&iff->addr_root))) {
929 ldp_if_del_addr(global, iff, ap);
932 MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);
935 global->configuration_sequence_number++;
937 retval = MPLS_SUCCESS;
939 ldp_cfg_if_set_end:
940 mpls_lock_release(global->global_lock); /* UNLOCK */
942 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
944 return retval;
947 /******************* ATTR **********************/
949 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
950 uint32_t flag)
952 ldp_global *global = (ldp_global *) handle;
953 ldp_attr *attr = NULL;
954 mpls_return_enum retval = MPLS_FAILURE;
956 MPLS_ASSERT(global !=NULL && a != NULL);
958 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
960 mpls_lock_get(global->global_lock); /* LOCK */
962 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
963 goto ldp_cfg_attr_get_end;
965 if (flag & LDP_ATTR_CFG_STATE) {
966 a->state = attr->state;
968 if (flag & LDP_ATTR_CFG_FEC) {
969 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
971 if (flag & LDP_ATTR_CFG_LABEL) {
972 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
974 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
975 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
977 if (flag & LDP_ATTR_CFG_PATH) {
978 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
980 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
981 a->session_index = (attr->session) ? (attr->session->index) : 0;
983 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
984 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
986 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
987 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
989 if (flag & LDP_ATTR_CFG_INGRESS) {
990 a->ingress = attr->ingress;
992 retval = MPLS_SUCCESS;
994 ldp_cfg_attr_get_end:
995 mpls_lock_release(global->global_lock); /* UNLOCK */
997 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
999 return retval;
1002 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
1003 uint32_t flag)
1005 ldp_global *g = (ldp_global *) handle;
1006 ldp_attr *attr = NULL;
1007 mpls_return_enum r = MPLS_FAILURE;
1008 mpls_bool done = MPLS_BOOL_FALSE;
1009 int index;
1011 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
1013 if (a->index == 0) {
1014 index = 1;
1015 } else {
1016 index = a->index + 1;
1019 mpls_lock_get(g->global_lock); /* LOCK */
1020 while (done == MPLS_BOOL_FALSE) {
1021 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
1022 case MPLS_SUCCESS:
1023 case MPLS_END_OF_LIST:
1024 done = MPLS_BOOL_TRUE;
1025 break;
1026 case MPLS_FAILURE:
1027 break;
1028 default:
1029 MPLS_ASSERT(0);
1031 index++;
1033 mpls_lock_release(g->global_lock); /* UNLOCK */
1035 if (r == MPLS_SUCCESS) {
1036 a->index = attr->index;
1037 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1038 return ldp_cfg_attr_get(g, a, flag);
1040 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1041 return r;
1044 /******************* PEER **********************/
1046 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
1047 uint32_t flag)
1049 ldp_global *global = (ldp_global *) handle;
1050 ldp_peer *peer = NULL;
1051 mpls_return_enum retval = MPLS_FAILURE;
1053 MPLS_ASSERT(global !=NULL && p != NULL);
1055 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
1057 mpls_lock_get(global->global_lock); /* LOCK */
1059 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
1060 goto ldp_cfg_peer_get_end;
1062 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1063 p->label_space = peer->label_space;
1065 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1066 p->target_role = peer->target_role;
1068 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1069 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1071 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1072 p->entity_index = peer->entity->index;
1074 if (flag & LDP_PEER_CFG_OPER_STATE) {
1075 p->oper_state = peer->oper_state;
1077 if (flag & LDP_PEER_CFG_PEER_NAME) {
1078 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1080 retval = MPLS_SUCCESS;
1082 ldp_cfg_peer_get_end:
1083 mpls_lock_release(global->global_lock); /* UNLOCK */
1085 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1087 return retval;
1090 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1091 uint32_t flag)
1093 ldp_global *g = (ldp_global *) handle;
1094 ldp_peer *peer = NULL;
1095 mpls_return_enum r = MPLS_FAILURE;
1096 mpls_bool done = MPLS_BOOL_FALSE;
1097 int index;
1099 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1101 if (p->index == 0) {
1102 index = 1;
1103 } else {
1104 index = p->index + 1;
1107 mpls_lock_get(g->global_lock); /* LOCK */
1108 while (done == MPLS_BOOL_FALSE) {
1109 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1110 case MPLS_SUCCESS:
1111 case MPLS_END_OF_LIST:
1112 done = MPLS_BOOL_TRUE;
1113 break;
1114 case MPLS_FAILURE:
1115 break;
1116 default:
1117 MPLS_ASSERT(0);
1119 index++;
1121 mpls_lock_release(g->global_lock); /* UNLOCK */
1123 if (r == MPLS_SUCCESS) {
1124 p->index = peer->index;
1125 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1126 return ldp_cfg_peer_get(g, p, flag);
1128 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1129 return r;
1132 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1133 uint32_t flag)
1135 // ldp_global* g = (ldp_global*)handle;
1136 return MPLS_SUCCESS;
1139 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1140 uint32_t flag)
1142 ldp_global *global = (ldp_global *) handle;
1143 ldp_peer *peer = NULL;
1144 mpls_return_enum retval = MPLS_FAILURE;
1146 MPLS_ASSERT(global !=NULL && p != NULL);
1148 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1150 mpls_lock_get(global->global_lock); /* LOCK */
1152 if (flag & LDP_CFG_ADD) {
1153 if ((peer = ldp_peer_create()) == NULL) {
1154 goto ldp_cfg_peer_set_end;
1156 p->index = peer->index;
1157 _ldp_global_add_peer(global, peer);
1158 } else {
1159 ldp_global_find_peer_index(global, p->index, &peer);
1162 if (peer == NULL) {
1163 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1165 goto ldp_cfg_peer_set_end;
1167 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1168 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1170 goto ldp_cfg_peer_set_end;
1173 if (flag & LDP_CFG_DEL) {
1174 if (peer->entity != NULL) {
1175 LDP_PRINT(global->user_data,
1176 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1178 goto ldp_cfg_peer_set_end;
1181 _ldp_global_del_peer(global, peer);
1183 retval = MPLS_SUCCESS;
1184 goto ldp_cfg_peer_set_end;
1186 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1187 peer->label_space = p->label_space;
1189 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1190 peer->target_role = p->target_role;
1192 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1193 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1195 if (flag & LDP_PEER_CFG_PEER_NAME) {
1196 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1198 p->peer_name);
1199 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1201 global->configuration_sequence_number++;
1203 retval = MPLS_SUCCESS;
1205 ldp_cfg_peer_set_end:
1206 mpls_lock_release(global->global_lock); /* UNLOCK */
1208 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1210 return retval;
1212 /******************* FEC **********************/
1214 mpls_return_enum ldp_cfg_fec_get(mpls_cfg_handle handle, mpls_fec * f,
1215 uint32_t flag)
1217 ldp_global *global = (ldp_global *) handle;
1218 ldp_fec *fec = NULL;
1219 mpls_return_enum retval = MPLS_FAILURE;
1221 MPLS_ASSERT(global !=NULL && f != NULL);
1223 LDP_ENTER(global->user_data, "ldp_cfg_fec_get");
1225 mpls_lock_get(global->global_lock); /* LOCK */
1227 if (flag & LDP_FEC_CFG_BY_INDEX) {
1228 ldp_global_find_fec_index(global, f->index, &fec);
1229 } else {
1230 fec = ldp_fec_find(global, f);
1232 if (!fec)
1233 goto ldp_cfg_fec_get_end;
1235 memcpy(f, &fec->info, sizeof(mpls_fec));
1236 f->index = fec->index;
1237 retval = MPLS_SUCCESS;
1239 ldp_cfg_fec_get_end:
1240 mpls_lock_release(global->global_lock); /* UNLOCK */
1242 LDP_EXIT(global->user_data, "ldp_cfg_fec_get");
1244 return retval;
1247 mpls_return_enum ldp_cfg_fec_getnext(mpls_cfg_handle handle, mpls_fec * f,
1248 uint32_t flag)
1250 ldp_global *g = (ldp_global *) handle;
1251 ldp_fec *fec = NULL;
1252 mpls_return_enum r = MPLS_FAILURE;
1253 mpls_bool done = MPLS_BOOL_FALSE;
1254 int index;
1256 LDP_ENTER(g->user_data, "ldp_cfg_fec_getnext");
1258 if (f->index == 0) {
1259 index = 1;
1260 } else {
1261 index = f->index + 1;
1264 mpls_lock_get(g->global_lock); /* LOCK */
1265 while (done == MPLS_BOOL_FALSE) {
1266 switch ((r = ldp_global_find_fec_index(g, index, &fec))) {
1267 case MPLS_SUCCESS:
1268 case MPLS_END_OF_LIST:
1269 done = MPLS_BOOL_TRUE;
1270 break;
1271 case MPLS_FAILURE:
1272 break;
1273 default:
1274 MPLS_ASSERT(0);
1276 index++;
1278 mpls_lock_release(g->global_lock); /* UNLOCK */
1280 if (r == MPLS_SUCCESS) {
1281 f->index = fec->index;
1282 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1283 return ldp_cfg_fec_get(g, f, flag);
1285 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1286 return r;
1289 mpls_return_enum ldp_cfg_fec_test(mpls_cfg_handle handle, mpls_fec * f,
1290 uint32_t flag)
1292 // ldp_global* g = (ldp_global*)handle;
1293 return MPLS_SUCCESS;
1296 mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f,
1297 uint32_t flag)
1299 ldp_global *global = (ldp_global *) handle;
1300 ldp_fec *fec = NULL;
1301 ldp_nexthop *nh;
1302 mpls_return_enum retval = MPLS_FAILURE;
1304 MPLS_ASSERT(global !=NULL && f != NULL);
1306 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1308 mpls_lock_get(global->global_lock); /* LOCK */
1310 if (flag & LDP_CFG_ADD) {
1311 if (ldp_fec_find(global, f) || (fec = ldp_fec_create(global, f)) == NULL) {
1312 goto ldp_cfg_fec_set_end;
1314 MPLS_REFCNT_HOLD(fec);
1315 f->index = fec->index;
1316 } else {
1317 if (flag & LDP_FEC_CFG_BY_INDEX) {
1318 ldp_global_find_fec_index(global, f->index, &fec);
1319 } else {
1320 fec = ldp_fec_find(global, f);
1324 if (fec == NULL) {
1325 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1326 goto ldp_cfg_fec_set_end;
1329 if (flag & LDP_CFG_DEL) {
1331 while ((nh = MPLS_LIST_HEAD(&fec->nh_root))) {
1332 ldp_fec_del_nexthop(global, fec, nh);
1335 MPLS_REFCNT_RELEASE2(global, fec, ldp_fec_delete);
1338 retval = MPLS_SUCCESS;
1340 ldp_cfg_fec_set_end:
1341 mpls_lock_release(global->global_lock); /* UNLOCK */
1343 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1345 return retval;
1348 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1349 mpls_nexthop *n, uint32_t flag)
1351 ldp_global *global = (ldp_global *) handle;
1352 ldp_fec *fec = NULL;
1353 ldp_nexthop *nh = NULL;
1354 mpls_return_enum retval = MPLS_FAILURE;
1356 MPLS_ASSERT(global !=NULL && f != NULL);
1358 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1360 mpls_lock_get(global->global_lock); /* LOCK */
1362 if (flag & LDP_FEC_CFG_BY_INDEX) {
1363 ldp_global_find_fec_index(global, f->index, &fec);
1364 } else {
1365 fec = ldp_fec_find(global, f);
1367 if (!fec)
1368 goto ldp_cfg_fec_nexthop_get_end;
1370 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1371 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1372 } else {
1373 nh = ldp_fec_nexthop_find(fec, n);
1375 if (!nh)
1376 goto ldp_cfg_fec_nexthop_get_end;
1378 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1379 n->index = nh->index;
1380 retval = MPLS_SUCCESS;
1382 ldp_cfg_fec_nexthop_get_end:
1383 mpls_lock_release(global->global_lock); /* UNLOCK */
1385 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1387 return retval;
1390 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1391 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1393 ldp_global *global = (ldp_global *) handle;
1394 ldp_fec *fec = NULL;
1395 ldp_nexthop *nh = NULL;
1396 mpls_return_enum r = MPLS_FAILURE;
1397 mpls_bool done = MPLS_BOOL_FALSE;
1398 int index;
1400 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1402 if (n->index == 0) {
1403 index = 1;
1404 } else {
1405 index = n->index + 1;
1408 mpls_lock_get(global->global_lock); /* LOCK */
1410 if (flag & LDP_FEC_CFG_BY_INDEX) {
1411 ldp_global_find_fec_index(global, f->index, &fec);
1412 } else {
1413 fec = ldp_fec_find(global, f);
1415 if (!fec)
1416 goto ldp_cfg_fec_nexthop_getnext_end;
1418 while (done == MPLS_BOOL_FALSE) {
1419 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1420 case MPLS_SUCCESS:
1421 case MPLS_END_OF_LIST:
1422 done = MPLS_BOOL_TRUE;
1423 break;
1424 case MPLS_FAILURE:
1425 break;
1426 default:
1427 MPLS_ASSERT(0);
1429 index++;
1431 mpls_lock_release(global->global_lock); /* UNLOCK */
1433 if (r == MPLS_SUCCESS) {
1434 n->index = nh->index;
1435 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1436 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1439 ldp_cfg_fec_nexthop_getnext_end:
1441 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1442 return r;
1445 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1446 mpls_nexthop *n, uint32_t flag)
1448 // ldp_global* g = (ldp_global*)handle;
1449 return MPLS_SUCCESS;
1452 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1453 mpls_nexthop *n, uint32_t flag)
1455 ldp_global *global = (ldp_global *) handle;
1456 ldp_fec *fec = NULL;
1457 ldp_nexthop *nh = NULL;
1458 mpls_return_enum retval = MPLS_FAILURE;
1460 MPLS_ASSERT(global !=NULL && f != NULL && n != NULL);
1462 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1464 mpls_lock_get(global->global_lock); /* LOCK */
1466 if (flag & LDP_FEC_CFG_BY_INDEX) {
1467 ldp_global_find_fec_index(global, f->index, &fec);
1468 } else {
1469 fec = ldp_fec_find(global, f);
1471 if (!fec)
1472 goto ldp_cfg_fec_nexthop_set_end;
1474 if (flag & LDP_CFG_ADD) {
1475 if (ldp_fec_nexthop_find(fec, n) ||
1476 (nh = ldp_nexthop_create(global, n)) == NULL) {
1477 goto ldp_cfg_fec_nexthop_set_end;
1479 n->index = nh->index;
1480 ldp_fec_add_nexthop(global, fec, nh);
1481 ldp_fec_process_add(global, fec, nh, NULL);
1482 } else {
1483 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1484 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1485 } else {
1486 nh = ldp_fec_nexthop_find(fec, n);
1490 if (nh == NULL) {
1491 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1492 goto ldp_cfg_fec_nexthop_set_end;
1495 if (flag & LDP_CFG_DEL) {
1496 ldp_fec_del_nexthop(global, fec, nh);
1497 if (ldp_fec_process_change(global, fec, MPLS_LIST_HEAD(&fec->nh_root),
1498 nh, NULL) != MPLS_SUCCESS) {
1499 MPLS_ASSERT(0);
1501 _ldp_global_del_nexthop(global, nh);
1504 retval = MPLS_SUCCESS;
1506 ldp_cfg_fec_nexthop_set_end:
1507 mpls_lock_release(global->global_lock); /* UNLOCK */
1509 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1511 return retval;
1514 /******************* ADDR **********************/
1516 mpls_return_enum ldp_cfg_addr_get(mpls_cfg_handle handle, ldp_addr * a,
1517 uint32_t flag)
1519 ldp_global *global = (ldp_global *) handle;
1520 ldp_session *session = NULL;
1521 ldp_nexthop *nexthop = NULL;
1522 ldp_addr *addr = NULL;
1523 mpls_return_enum retval = MPLS_FAILURE;
1525 MPLS_ASSERT(global !=NULL && a != NULL);
1527 LDP_ENTER(global->user_data, "ldp_cfg_addr_get");
1529 mpls_lock_get(global->global_lock); /* LOCK */
1531 ldp_global_find_addr_index(global, a->index, &addr);
1533 if (!addr)
1534 goto ldp_cfg_addr_get_end;
1536 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1537 a->index = addr->index;
1539 if ((session = mpls_link_list_head_data(&addr->session_root))) {
1540 a->session_index = session->index;
1543 if ((nexthop = MPLS_LIST_HEAD(&addr->nh_root))) {
1544 a->nexthop_index = nexthop->index;
1547 if (addr->iff) {
1548 a->if_index = addr->iff->index;
1551 retval = MPLS_SUCCESS;
1553 ldp_cfg_addr_get_end:
1554 mpls_lock_release(global->global_lock); /* UNLOCK */
1556 LDP_EXIT(global->user_data, "ldp_cfg_addr_get");
1558 return retval;
1561 mpls_return_enum ldp_cfg_addr_getnext(mpls_cfg_handle handle, ldp_addr *a,
1562 uint32_t flag)
1564 ldp_global *global = (ldp_global *) handle;
1565 ldp_addr *addr = NULL;
1566 mpls_return_enum r = MPLS_FAILURE;
1567 mpls_bool done = MPLS_BOOL_FALSE;
1568 int index;
1570 LDP_ENTER(global->user_data, "ldp_cfg_addr_getnext");
1572 if (a->index == 0) {
1573 index = 1;
1574 } else {
1575 index = a->index + 1;
1578 mpls_lock_get(global->global_lock); /* LOCK */
1580 while (done == MPLS_BOOL_FALSE) {
1581 switch ((r = ldp_global_find_addr_index(global, index, &addr))) {
1582 case MPLS_SUCCESS:
1583 case MPLS_END_OF_LIST:
1584 done = MPLS_BOOL_TRUE;
1585 break;
1586 case MPLS_FAILURE:
1587 break;
1588 default:
1589 MPLS_ASSERT(0);
1591 index++;
1593 mpls_lock_release(global->global_lock); /* UNLOCK */
1595 if (r == MPLS_SUCCESS) {
1596 a->index = addr->index;
1597 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1598 return ldp_cfg_addr_get(global, a, flag);
1601 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1602 return r;
1605 /******************* IF ADDR **********************/
1607 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1608 ldp_addr * a, uint32_t flag)
1610 ldp_global *global = (ldp_global *) handle;
1611 ldp_addr *addr = NULL;
1612 ldp_if *iff = NULL;
1613 mpls_return_enum retval = MPLS_FAILURE;
1615 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1617 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1619 mpls_lock_get(global->global_lock); /* LOCK */
1621 if (flag & LDP_IF_CFG_BY_INDEX) {
1622 ldp_global_find_if_index(global, i->index, &iff);
1623 } else {
1624 iff = ldp_global_find_if_handle(global, i->handle);
1626 if (!iff)
1627 goto ldp_cfg_if_addr_get_end;
1629 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1630 ldp_if_find_addr_index(iff, a->index, &addr);
1631 } else {
1632 addr = ldp_if_addr_find(iff, &a->address);
1634 if (!addr)
1635 goto ldp_cfg_if_addr_get_end;
1637 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1638 a->index = addr->index;
1640 retval = MPLS_SUCCESS;
1642 ldp_cfg_if_addr_get_end:
1643 mpls_lock_release(global->global_lock); /* UNLOCK */
1645 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1647 return retval;
1650 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1651 ldp_if * i, ldp_addr *a, uint32_t flag)
1653 ldp_global *global = (ldp_global *) handle;
1654 ldp_if *iff = NULL;
1655 ldp_addr *addr = NULL;
1656 mpls_return_enum r = MPLS_FAILURE;
1657 mpls_bool done = MPLS_BOOL_FALSE;
1658 int index;
1660 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1662 if (a->index == 0) {
1663 index = 1;
1664 } else {
1665 index = a->index + 1;
1668 mpls_lock_get(global->global_lock); /* LOCK */
1670 if (flag & LDP_IF_CFG_BY_INDEX) {
1671 ldp_global_find_if_index(global, i->index, &iff);
1672 } else {
1673 iff = ldp_global_find_if_handle(global, i->handle);
1675 if (!iff)
1676 goto ldp_cfg_if_addr_getnext_end;
1678 while (done == MPLS_BOOL_FALSE) {
1679 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1680 case MPLS_SUCCESS:
1681 case MPLS_END_OF_LIST:
1682 done = MPLS_BOOL_TRUE;
1683 break;
1684 case MPLS_FAILURE:
1685 break;
1686 default:
1687 MPLS_ASSERT(0);
1689 index++;
1691 mpls_lock_release(global->global_lock); /* UNLOCK */
1693 if (r == MPLS_SUCCESS) {
1694 a->index = addr->index;
1695 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1696 return ldp_cfg_if_addr_get(global, i, a, flag);
1699 ldp_cfg_if_addr_getnext_end:
1701 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1702 return r;
1705 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1706 ldp_addr *a, uint32_t flag)
1708 ldp_global *global = (ldp_global *) handle;
1709 ldp_if *iff = NULL;
1710 ldp_addr *addr = NULL;
1711 mpls_return_enum retval = MPLS_FAILURE;
1713 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1715 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1717 mpls_lock_get(global->global_lock); /* LOCK */
1719 if (flag & LDP_FEC_CFG_BY_INDEX) {
1720 ldp_global_find_if_index(global, i->index, &iff);
1721 } else {
1722 iff = ldp_global_find_if_handle(global, i->handle);
1724 if (!iff)
1725 goto ldp_cfg_if_addr_set_end;
1727 if (flag & LDP_CFG_ADD) {
1728 if (ldp_if_addr_find(iff, &a->address) || (addr = ldp_addr_create(global,
1729 &a->address)) == NULL) {
1730 goto ldp_cfg_if_addr_set_end;
1732 a->index = addr->index;
1733 ldp_if_add_addr(iff, addr);
1734 } else {
1735 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1736 ldp_if_find_addr_index(iff, a->index, &addr);
1737 } else {
1738 addr = ldp_if_addr_find(iff, &a->address);
1742 if (addr == NULL) {
1743 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1744 goto ldp_cfg_if_addr_set_end;
1747 if (flag & LDP_CFG_DEL) {
1748 ldp_if_del_addr(global, iff ,addr);
1751 retval = MPLS_SUCCESS;
1753 ldp_cfg_if_addr_set_end:
1754 mpls_lock_release(global->global_lock); /* UNLOCK */
1756 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1758 return retval;
1761 /******************* ADJACENCY **********************/
1763 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1764 uint32_t flag)
1766 ldp_global *global = (ldp_global *) handle;
1767 ldp_adj *adj = NULL;
1768 mpls_return_enum retval = MPLS_FAILURE;
1770 MPLS_ASSERT(global !=NULL && a != NULL);
1772 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1774 mpls_lock_get(global->global_lock); /* LOCK */
1776 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1777 goto ldp_cfg_adj_get_end;
1779 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1780 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1781 sizeof(mpls_inet_addr));
1783 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1784 memcpy(&a->remote_source_address, &adj->remote_source_address,
1785 sizeof(mpls_inet_addr));
1787 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1788 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1789 sizeof(mpls_inet_addr));
1791 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1792 a->remote_csn = adj->remote_csn;
1794 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1795 a->remote_label_space = adj->remote_label_space;
1797 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1798 a->remote_hellotime = adj->remote_hellotime;
1800 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1801 a->entity_index = adj->entity ? adj->entity->index : 0;
1803 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1804 a->session_index = (adj->session) ? (adj->session->index) : 0;
1806 if (flag & LDP_ADJ_CFG_ROLE) {
1807 a->role = adj->role;
1809 retval = MPLS_SUCCESS;
1811 ldp_cfg_adj_get_end:
1813 mpls_lock_release(global->global_lock); /* UNLOCK */
1815 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1817 return retval;
1820 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1821 uint32_t flag)
1823 ldp_global *g = (ldp_global *) handle;
1824 ldp_adj *adj = NULL;
1825 mpls_return_enum r = MPLS_FAILURE;
1826 mpls_bool done = MPLS_BOOL_FALSE;
1827 int index;
1829 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1831 if (a->index == 0) {
1832 index = 1;
1833 } else {
1834 index = a->index + 1;
1837 mpls_lock_get(g->global_lock); /* LOCK */
1838 while (done == MPLS_BOOL_FALSE) {
1839 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1840 case MPLS_SUCCESS:
1841 case MPLS_END_OF_LIST:
1842 done = MPLS_BOOL_TRUE;
1843 break;
1844 case MPLS_FAILURE:
1845 break;
1846 default:
1847 MPLS_ASSERT(0);
1849 index++;
1851 mpls_lock_release(g->global_lock); /* UNLOCK */
1853 if (r == MPLS_SUCCESS) {
1854 a->index = adj->index;
1855 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1856 return ldp_cfg_adj_get(g, a, flag);
1858 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1859 return r;
1862 /******************* SESSION **********************/
1864 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1865 uint32_t flag)
1867 ldp_global *global = (ldp_global *) handle;
1868 ldp_session *session = NULL;
1869 mpls_return_enum retval = MPLS_FAILURE;
1871 MPLS_ASSERT(global !=NULL && s != NULL);
1873 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1875 mpls_lock_get(global->global_lock); /* LOCK */
1877 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1878 goto ldp_cfg_session_get_end;
1880 if (flag & LDP_SESSION_CFG_STATE) {
1881 s->state = session->state;
1883 if (flag & LDP_SESSION_CFG_OPER_UP) {
1884 s->oper_up = session->oper_up;
1886 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1887 s->oper_max_pdu = session->oper_max_pdu;
1889 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1890 s->oper_keepalive = session->oper_keepalive;
1892 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1893 s->oper_path_vector_limit = session->oper_path_vector_limit;
1895 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1896 s->oper_distribution_mode = session->oper_distribution_mode;
1898 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1899 s->oper_loop_detection = session->oper_loop_detection;
1901 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1902 s->remote_max_pdu = session->remote_max_pdu;
1904 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1905 s->remote_keepalive = session->remote_keepalive;
1907 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1908 s->remote_path_vector_limit = session->remote_path_vector_limit;
1910 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1911 s->remote_distribution_mode = session->remote_distribution_mode;
1913 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1914 s->remote_loop_detection = session->remote_loop_detection;
1916 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1917 s->remote_dest.addr.type = session->remote_dest.addr.type;
1918 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1920 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1921 s->remote_dest.port = session->remote_dest.port;
1923 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1924 s->no_label_resource_sent = session->no_label_resource_sent;
1926 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1927 s->no_label_resource_recv = session->no_label_resource_recv;
1929 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1930 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1931 s->adj_index = a ? a->index : 0;
1933 if (flag & LDP_SESSION_CFG_MESG_TX) {
1934 s->mesg_tx = session->mesg_tx;
1936 if (flag & LDP_SESSION_CFG_MESG_RX) {
1937 s->mesg_rx = session->mesg_rx;
1939 retval = MPLS_SUCCESS;
1941 ldp_cfg_session_get_end:
1942 mpls_lock_release(global->global_lock); /* UNLOCK */
1944 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1946 return retval;
1949 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1950 uint32_t flag)
1952 ldp_global *g = (ldp_global *) handle;
1953 ldp_session *ses = NULL;
1954 mpls_return_enum r = MPLS_FAILURE;
1955 mpls_bool done = MPLS_BOOL_FALSE;
1956 int index;
1958 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1960 if (s->index == 0) {
1961 index = 1;
1962 } else {
1963 index = s->index + 1;
1966 mpls_lock_get(g->global_lock); /* LOCK */
1967 while (done == MPLS_BOOL_FALSE) {
1968 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1969 case MPLS_SUCCESS:
1970 case MPLS_END_OF_LIST:
1971 done = MPLS_BOOL_TRUE;
1972 break;
1973 case MPLS_FAILURE:
1974 break;
1975 default:
1976 MPLS_ASSERT(0);
1978 index++;
1980 mpls_lock_release(g->global_lock); /* UNLOCK */
1982 if (r == MPLS_SUCCESS) {
1983 s->index = ses->index;
1985 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1986 return ldp_cfg_session_get(g, s, flag);
1989 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1991 return r;
1994 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1995 ldp_session * s)
1997 ldp_global *g = (ldp_global *) handle;
1998 mpls_bool this_one = MPLS_BOOL_FALSE;
1999 mpls_return_enum r = MPLS_FAILURE;
2000 ldp_adj *adj_next = NULL;
2001 ldp_adj *adj = NULL;
2002 ldp_session *session = NULL;
2004 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
2006 /* if an adj_index of zero is sent, get the index of
2007 * the first adj in the list
2009 if (!s->adj_index) {
2010 this_one = MPLS_BOOL_TRUE;
2013 mpls_lock_get(g->global_lock); /* LOCK */
2015 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
2016 adj = MPLS_LIST_HEAD(&session->adj_root);
2017 while (adj) {
2018 if (this_one == MPLS_BOOL_TRUE) {
2019 adj_next = adj;
2020 break;
2023 /* since the entities are sort in the list ... */
2024 if (adj->index > s->adj_index) {
2025 break;
2026 } else if (adj->index == s->adj_index) {
2027 this_one = MPLS_BOOL_TRUE;
2029 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
2032 mpls_lock_release(g->global_lock); /* UNLOCK */
2034 if (adj_next) {
2035 s->adj_index = adj_next->index;
2036 r = MPLS_SUCCESS;
2039 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
2040 return r;
2043 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
2044 ldp_session * s, ldp_addr * a, uint32_t flag)
2046 ldp_global *global = (ldp_global *) handle;
2047 ldp_session *session = NULL;
2048 ldp_addr *addr = NULL;
2049 mpls_return_enum retval = MPLS_FAILURE;
2051 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
2053 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
2055 mpls_lock_get(global->global_lock); /* LOCK */
2057 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
2058 goto ldp_cfg_session_raddr_get_end;
2060 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
2061 goto ldp_cfg_session_raddr_get_end;
2063 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
2064 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
2066 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
2067 a->index = addr->index;
2069 retval = MPLS_SUCCESS;
2071 ldp_cfg_session_raddr_get_end:
2072 mpls_lock_release(global->global_lock); /* UNLOCK */
2074 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
2076 return retval;
2079 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
2080 ldp_session * s, ldp_addr * a, uint32_t flag)
2082 ldp_global *g = (ldp_global *) handle;
2083 ldp_addr *addr = NULL;
2084 mpls_return_enum r = MPLS_FAILURE;
2085 mpls_bool done = MPLS_BOOL_FALSE;
2086 ldp_session *sp = NULL;
2087 int index;
2089 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
2091 if (a->index == 0) {
2092 index = 1;
2093 } else {
2094 index = a->index + 1;
2097 r = ldp_global_find_session_index(g, s->index, &sp);
2098 if (r != MPLS_SUCCESS) {
2099 return r;
2102 mpls_lock_get(g->global_lock); /* LOCK */
2103 while (done == MPLS_BOOL_FALSE) {
2104 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
2105 case MPLS_SUCCESS:
2106 case MPLS_END_OF_LIST:
2107 done = MPLS_BOOL_TRUE;
2108 break;
2109 case MPLS_FAILURE:
2110 break;
2111 default:
2112 MPLS_ASSERT(0);
2114 index++;
2116 mpls_lock_release(g->global_lock); /* UNLOCK */
2118 if (r == MPLS_SUCCESS) {
2119 a->index = addr->index;
2120 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2123 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2124 return r;
2127 /******************* IN LABEL **********************/
2129 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2130 uint32_t flag)
2132 ldp_global *global = (ldp_global *) handle;
2133 ldp_inlabel *inlabel = NULL;
2134 mpls_return_enum retval = MPLS_FAILURE;
2136 MPLS_ASSERT(global !=NULL && i != NULL);
2138 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2140 mpls_lock_get(global->global_lock); /* LOCK */
2142 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2143 goto ldp_cfg_inlabel_get_end;
2145 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2146 i->info.labelspace = inlabel->info.labelspace;
2148 if (flag & LDP_INLABEL_CFG_LABEL) {
2149 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2151 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2152 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2155 retval = MPLS_SUCCESS;
2157 ldp_cfg_inlabel_get_end:
2158 mpls_lock_release(global->global_lock); /* UNLOCK */
2160 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2162 return retval;
2165 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2166 uint32_t flag)
2168 ldp_global *g = (ldp_global *) handle;
2169 ldp_inlabel *inlabel = NULL;
2170 mpls_return_enum r = MPLS_FAILURE;
2171 mpls_bool done = MPLS_BOOL_FALSE;
2172 int index;
2174 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2176 if (i->index == 0) {
2177 index = 1;
2178 } else {
2179 index = i->index + 1;
2182 mpls_lock_get(g->global_lock); /* LOCK */
2183 while (done == MPLS_BOOL_FALSE) {
2184 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2185 case MPLS_SUCCESS:
2186 case MPLS_END_OF_LIST:
2187 done = MPLS_BOOL_TRUE;
2188 break;
2189 case MPLS_FAILURE:
2190 break;
2191 default:
2192 MPLS_ASSERT(0);
2194 index++;
2196 mpls_lock_release(g->global_lock); /* UNLOCK */
2198 if (r == MPLS_SUCCESS) {
2199 i->index = inlabel->index;
2201 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2202 return ldp_cfg_inlabel_get(g, i, flag);
2205 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2207 return r;
2210 /******************* OUT LABEL **********************/
2212 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2213 uint32_t flag)
2215 ldp_global *global = (ldp_global *) handle;
2216 ldp_outlabel *outlabel = NULL;
2217 mpls_return_enum retval = MPLS_FAILURE;
2219 MPLS_ASSERT(global !=NULL && o != NULL);
2221 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2223 mpls_lock_get(global->global_lock); /* LOCK */
2225 if (ldp_global_find_outlabel_index(global, o->index,
2226 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2228 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2229 if (outlabel->nh) {
2230 o->nh_index = outlabel->nh->index;
2231 } else {
2232 o->nh_index = 0;
2235 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2236 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2238 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2239 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2241 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2242 o->merge_count = outlabel->merge_count;
2245 retval = MPLS_SUCCESS;
2247 ldp_cfg_outlabel_get_end:
2248 mpls_lock_release(global->global_lock); /* UNLOCK */
2250 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2252 return retval;
2255 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2256 ldp_outlabel * o, uint32_t flag)
2258 ldp_global *g = (ldp_global *) handle;
2259 ldp_outlabel *outlabel = NULL;
2260 mpls_return_enum r = MPLS_FAILURE;
2261 mpls_bool done = MPLS_BOOL_FALSE;
2262 int index;
2264 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2266 if (o->index == 0) {
2267 index = 1;
2268 } else {
2269 index = o->index + 1;
2272 mpls_lock_get(g->global_lock); /* LOCK */
2273 while (done == MPLS_BOOL_FALSE) {
2274 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2275 case MPLS_SUCCESS:
2276 case MPLS_END_OF_LIST:
2277 done = MPLS_BOOL_TRUE;
2278 break;
2279 case MPLS_FAILURE:
2280 break;
2281 default:
2282 MPLS_ASSERT(0);
2284 index++;
2286 mpls_lock_release(g->global_lock); /* UNLOCK */
2288 if (r == MPLS_SUCCESS) {
2289 o->index = outlabel->index;
2291 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2292 return ldp_cfg_outlabel_get(g, o, flag);
2295 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2297 return r;
2300 /******************* TUNNEL **********************/
2302 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2303 uint32_t flag)
2305 ldp_global *global = (ldp_global *) handle;
2306 mpls_return_enum retval = MPLS_FAILURE;
2307 ldp_tunnel *tunnel = NULL;
2309 MPLS_ASSERT(global !=NULL);
2311 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2313 mpls_lock_get(global->global_lock); /* LOCK */
2315 if (flag & LDP_CFG_ADD) {
2316 if (!(tunnel = ldp_tunnel_create())) {
2317 goto ldp_cfg_tunnel_set_end;
2319 _ldp_global_add_tunnel(global, tunnel);
2321 t->index = tunnel->index;
2322 } else {
2323 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2326 if (!tunnel) {
2327 LDP_PRINT(global->user_data,
2329 "ldp_cfg_tunnel_set:could not create tunnel\n");
2330 goto ldp_cfg_tunnel_set_end;
2333 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2334 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2335 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2337 goto ldp_cfg_tunnel_set_end;
2340 if (flag & LDP_CFG_DEL) {
2341 if (tunnel->outlabel)
2342 ldp_tunnel_del_outlabel(tunnel);
2343 if (tunnel->resource)
2344 ldp_tunnel_del_resource(tunnel);
2345 if (tunnel->hop_list)
2346 ldp_tunnel_del_hop_list(tunnel);
2347 _ldp_global_del_tunnel(global, tunnel);
2349 retval = MPLS_SUCCESS;
2350 goto ldp_cfg_tunnel_set_end;
2353 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2354 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2356 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2357 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2359 if (flag & LDP_TUNNEL_CFG_NAME) {
2360 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2362 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2363 tunnel->is_interface = t->is_interface;
2365 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2366 ldp_outlabel *outlabel = NULL;
2368 if (t->outlabel_index) {
2369 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2371 if (!outlabel) {
2372 goto ldp_cfg_tunnel_set_end;
2374 ldp_tunnel_add_outlabel(tunnel, outlabel);
2375 } else {
2376 ldp_tunnel_del_outlabel(tunnel);
2379 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2380 tunnel->setup_prio = t->setup_prio;
2382 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2383 tunnel->hold_prio = t->hold_prio;
2385 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2386 tunnel->instance_prio = t->instance_prio;
2388 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2389 tunnel->local_protect = t->local_protect;
2391 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2392 ldp_resource *resource = NULL;
2394 if (t->resource_index) {
2395 ldp_global_find_resource_index(global, t->resource_index, &resource);
2397 if (!resource) {
2398 goto ldp_cfg_tunnel_set_end;
2400 ldp_tunnel_add_resource(tunnel, resource);
2401 } else {
2402 ldp_tunnel_del_resource(tunnel);
2405 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2406 ldp_hop_list *hop_list = NULL;
2408 if (t->hop_list_index) {
2409 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2411 if (!hop_list) {
2412 goto ldp_cfg_tunnel_set_end;
2414 ldp_tunnel_add_hop_list(tunnel, hop_list);
2415 } else {
2416 ldp_tunnel_del_hop_list(tunnel);
2419 if (flag & LDP_TUNNEL_CFG_FEC) {
2420 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2422 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2423 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2424 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2425 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2426 goto ldp_cfg_tunnel_set_end;
2429 } else {
2430 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2431 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2432 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2433 goto ldp_cfg_tunnel_set_end;
2435 } else {
2436 LDP_PRINT(global->user_data,
2438 "ldp_cfg_tunnel_set: tunnel not ready\n");
2439 goto ldp_cfg_tunnel_set_end;
2444 retval = MPLS_SUCCESS;
2446 ldp_cfg_tunnel_set_end:
2448 mpls_lock_release(global->global_lock); /* UNLOCK */
2450 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2452 return retval;
2455 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2456 uint32_t flag)
2458 ldp_global *global = (ldp_global *) handle;
2459 mpls_return_enum retval = MPLS_FAILURE;
2460 ldp_tunnel *tunnel = NULL;
2462 MPLS_ASSERT(global !=NULL);
2464 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2466 mpls_lock_get(global->global_lock); /* LOCK */
2468 if (flag & LDP_CFG_ADD) {
2469 retval = MPLS_SUCCESS;
2470 goto ldp_cfg_tunnel_test_end;
2473 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2475 if (!tunnel) {
2476 goto ldp_cfg_tunnel_test_end;
2479 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2480 ldp_resource *resource = NULL;
2482 if (t->resource_index) {
2483 ldp_global_find_resource_index(global, t->resource_index, &resource);
2485 if (!resource) {
2486 goto ldp_cfg_tunnel_test_end;
2490 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2491 ldp_hop_list *hop_list = NULL;
2493 if (t->hop_list_index) {
2494 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2496 if (!hop_list) {
2497 goto ldp_cfg_tunnel_test_end;
2501 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2502 ldp_outlabel *outlabel = NULL;
2504 if (t->outlabel_index) {
2505 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2507 if (!outlabel) {
2508 goto ldp_cfg_tunnel_test_end;
2512 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2513 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2514 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2515 goto ldp_cfg_tunnel_test_end;
2517 retval = MPLS_SUCCESS;
2519 ldp_cfg_tunnel_test_end:
2521 mpls_lock_release(global->global_lock); /* UNLOCK */
2523 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2525 return retval;
2528 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2529 uint32_t flag)
2531 ldp_global *global = (ldp_global *) handle;
2532 mpls_return_enum retval = MPLS_FAILURE;
2533 ldp_tunnel *tunnel = NULL;
2535 MPLS_ASSERT(global !=NULL);
2537 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2539 mpls_lock_get(global->global_lock); /* LOCK */
2541 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2543 if (!tunnel) {
2544 goto ldp_cfg_tunnel_get_end;
2546 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2547 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2549 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2550 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2552 if (flag & LDP_TUNNEL_CFG_NAME) {
2553 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2555 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2556 t->is_interface = tunnel->is_interface;
2558 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2559 if (tunnel->outlabel) {
2560 t->outlabel_index = tunnel->outlabel->index;
2561 } else {
2562 t->outlabel_index = 0;
2565 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2566 t->setup_prio = tunnel->setup_prio;
2568 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2569 t->hold_prio = tunnel->hold_prio;
2571 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2572 tunnel->instance_prio = t->instance_prio;
2574 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2575 tunnel->local_protect = t->local_protect;
2577 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2578 if (tunnel->resource) {
2579 t->resource_index = tunnel->resource->index;
2580 } else {
2581 t->resource_index = 0;
2584 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2585 if (tunnel->hop_list) {
2586 t->hop_list_index = tunnel->hop_list->index;
2587 } else {
2588 t->hop_list_index = 0;
2591 if (flag & LDP_TUNNEL_CFG_FEC) {
2592 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2594 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2595 t->admin_state = tunnel->admin_state;
2597 retval = MPLS_SUCCESS;
2599 ldp_cfg_tunnel_get_end:
2601 mpls_lock_release(global->global_lock); /* UNLOCK */
2603 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2605 return retval;
2608 /******************* RESOURCE **********************/
2610 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2611 uint32_t flag)
2613 ldp_global *global = (ldp_global *) handle;
2614 mpls_return_enum retval = MPLS_FAILURE;
2615 ldp_resource *resource = NULL;
2617 MPLS_ASSERT(global !=NULL);
2619 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2621 mpls_lock_get(global->global_lock); /* LOCK */
2623 if (flag & LDP_CFG_ADD) {
2624 resource = ldp_resource_create();
2625 _ldp_global_add_resource(global, resource);
2627 r->index = resource->index;
2628 } else {
2629 ldp_global_find_resource_index(global, r->index, &resource);
2632 if (!resource) {
2633 goto ldp_cfg_resource_set_end;
2636 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2637 resource->max_rate = r->max_rate;
2639 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2640 resource->mean_rate = r->mean_rate;
2642 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2643 resource->burst_size = r->burst_size;
2645 retval = MPLS_SUCCESS;
2647 ldp_cfg_resource_set_end:
2649 mpls_lock_release(global->global_lock); /* UNLOCK */
2651 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2653 return retval;
2656 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2657 uint32_t flag)
2659 ldp_global *global = (ldp_global *) handle;
2660 mpls_return_enum retval = MPLS_FAILURE;
2661 ldp_resource *resource = NULL;
2663 MPLS_ASSERT(global !=NULL);
2665 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2667 mpls_lock_get(global->global_lock); /* LOCK */
2669 if (flag & LDP_CFG_ADD) {
2670 retval = MPLS_SUCCESS;
2671 goto ldp_cfg_resource_test_end;
2674 ldp_global_find_resource_index(global, r->index, &resource);
2676 if (!resource) {
2677 goto ldp_cfg_resource_test_end;
2680 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2681 goto ldp_cfg_resource_test_end;
2683 retval = MPLS_SUCCESS;
2685 ldp_cfg_resource_test_end:
2687 mpls_lock_release(global->global_lock); /* UNLOCK */
2689 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2691 return retval;
2694 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2695 uint32_t flag)
2697 ldp_global *global = (ldp_global *) handle;
2698 mpls_return_enum retval = MPLS_FAILURE;
2699 ldp_resource *resource = NULL;
2701 MPLS_ASSERT(global !=NULL);
2703 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2705 mpls_lock_get(global->global_lock); /* LOCK */
2707 ldp_global_find_resource_index(global, r->index, &resource);
2709 if (!resource) {
2710 goto ldp_cfg_resource_get_end;
2713 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2714 r->max_rate = resource->max_rate;
2716 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2717 r->mean_rate = resource->mean_rate;
2719 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2720 r->burst_size = resource->burst_size;
2722 retval = MPLS_SUCCESS;
2724 ldp_cfg_resource_get_end:
2726 mpls_lock_release(global->global_lock); /* UNLOCK */
2728 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2730 return retval;
2733 /******************* HOP **********************/
2735 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2736 uint32_t flag)
2738 ldp_global *global = (ldp_global *) handle;
2739 mpls_return_enum retval = MPLS_FAILURE;
2740 ldp_hop_list *hop_list = NULL;
2741 ldp_hop *hop = NULL;
2743 MPLS_ASSERT(global !=NULL);
2745 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2747 if (!h->hop_list_index && !h->index) {
2748 return retval;
2751 mpls_lock_get(global->global_lock); /* LOCK */
2753 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2755 if (!hop_list) {
2756 if (flag & LDP_CFG_ADD) {
2757 if (!(hop_list = ldp_hop_list_create())) {
2758 goto ldp_cfg_hop_set_end;
2760 _ldp_global_add_hop_list(global, hop_list);
2762 h->hop_list_index = hop_list->index;
2763 } else {
2764 goto ldp_cfg_hop_set_end;
2768 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2769 if (!hop) {
2770 if (h->index && (flag & LDP_CFG_ADD)) {
2771 if (!(hop = ldp_hop_create())) {
2772 goto ldp_cfg_hop_set_end;
2774 hop->index = h->index;
2775 ldp_hop_list_add_hop(hop_list, hop);
2776 } else {
2777 goto ldp_cfg_hop_set_end;
2781 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2782 hop->path_option = h->path_option;
2784 if (flag & LDP_HOP_CFG_ADDR) {
2785 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2787 if (flag & LDP_HOP_CFG_TYPE) {
2788 hop->type = h->type;
2790 retval = MPLS_SUCCESS;
2792 ldp_cfg_hop_set_end:
2794 mpls_lock_release(global->global_lock); /* UNLOCK */
2796 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2798 return retval;
2801 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2802 uint32_t flag)
2804 ldp_global *global = (ldp_global *) handle;
2805 mpls_return_enum retval = MPLS_FAILURE;
2806 ldp_hop_list *hop_list = NULL;
2807 ldp_hop *hop = NULL;
2809 MPLS_ASSERT(global !=NULL);
2811 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2813 mpls_lock_get(global->global_lock); /* LOCK */
2815 if (flag & LDP_CFG_ADD) {
2816 retval = MPLS_SUCCESS;
2817 goto ldp_cfg_hop_test_end;
2820 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2822 if (!hop_list) {
2823 goto ldp_cfg_hop_test_end;
2826 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2827 if (!hop) {
2828 goto ldp_cfg_hop_test_end;
2831 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2832 goto ldp_cfg_hop_test_end;
2834 retval = MPLS_SUCCESS;
2836 ldp_cfg_hop_test_end:
2838 mpls_lock_release(global->global_lock); /* UNLOCK */
2840 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2842 return retval;
2845 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2846 uint32_t flag)
2848 ldp_global *global = (ldp_global *) handle;
2849 mpls_return_enum retval = MPLS_FAILURE;
2850 ldp_hop_list *hop_list = NULL;
2851 ldp_hop *hop = NULL;
2853 MPLS_ASSERT(global !=NULL);
2855 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2857 mpls_lock_get(global->global_lock); /* LOCK */
2859 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2861 if (!hop_list) {
2862 goto ldp_cfg_hop_get_end;
2865 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2866 if (!hop) {
2867 goto ldp_cfg_hop_get_end;
2870 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2871 h->path_option = hop->path_option;
2873 if (flag & LDP_HOP_CFG_ADDR) {
2874 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2876 if (flag & LDP_HOP_CFG_TYPE) {
2877 h->type = hop->type;
2879 retval = MPLS_SUCCESS;
2881 ldp_cfg_hop_get_end:
2883 mpls_lock_release(global->global_lock); /* UNLOCK */
2885 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2887 return retval;