an address can only be advertised by one session. Thus
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blob4c4709172b2829970fc0ee2deda9230b54293298
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 mpls_return_enum retval = MPLS_FAILURE;
1303 MPLS_ASSERT(global != NULL && f != NULL);
1305 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1307 mpls_lock_get(global->global_lock); /* LOCK */
1309 if (flag & LDP_CFG_ADD) {
1310 if (ldp_fec_find(global, f) || (fec = ldp_fec_create(global, f)) == NULL) {
1311 goto ldp_cfg_fec_set_end;
1313 MPLS_REFCNT_HOLD(fec);
1314 f->index = fec->index;
1315 } else {
1316 if (flag & LDP_FEC_CFG_BY_INDEX) {
1317 ldp_global_find_fec_index(global, f->index, &fec);
1318 } else {
1319 fec = ldp_fec_find(global, f);
1323 if (fec == NULL) {
1324 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1325 goto ldp_cfg_fec_set_end;
1328 if (flag & LDP_CFG_DEL) {
1330 * we can only delete the fec if all of the nexthops have been removed
1332 if (!MPLS_LIST_EMPTY(&fec->nh_root)) {
1333 goto ldp_cfg_fec_set_end;
1336 * we hold the last refcnt, this should result in a call to
1337 * ldp_fec_delete
1339 MPLS_REFCNT_RELEASE2(global, fec, ldp_fec_delete);
1342 retval = MPLS_SUCCESS;
1344 ldp_cfg_fec_set_end:
1345 mpls_lock_release(global->global_lock); /* UNLOCK */
1347 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1349 return retval;
1352 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1353 mpls_nexthop *n, uint32_t flag)
1355 ldp_global *global = (ldp_global *) handle;
1356 ldp_fec *fec = NULL;
1357 ldp_nexthop *nh = NULL;
1358 mpls_return_enum retval = MPLS_FAILURE;
1360 MPLS_ASSERT(global !=NULL && f != NULL);
1362 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1364 mpls_lock_get(global->global_lock); /* LOCK */
1366 if (flag & LDP_FEC_CFG_BY_INDEX) {
1367 ldp_global_find_fec_index(global, f->index, &fec);
1368 } else {
1369 fec = ldp_fec_find(global, f);
1371 if (!fec)
1372 goto ldp_cfg_fec_nexthop_get_end;
1374 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1375 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1376 } else {
1377 nh = ldp_fec_nexthop_find(fec, n);
1379 if (!nh)
1380 goto ldp_cfg_fec_nexthop_get_end;
1382 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1383 n->index = nh->index;
1384 retval = MPLS_SUCCESS;
1386 ldp_cfg_fec_nexthop_get_end:
1387 mpls_lock_release(global->global_lock); /* UNLOCK */
1389 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1391 return retval;
1394 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1395 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1397 ldp_global *global = (ldp_global *) handle;
1398 ldp_fec *fec = NULL;
1399 ldp_nexthop *nh = NULL;
1400 mpls_return_enum r = MPLS_FAILURE;
1401 mpls_bool done = MPLS_BOOL_FALSE;
1402 int index;
1404 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1406 if (n->index == 0) {
1407 index = 1;
1408 } else {
1409 index = n->index + 1;
1412 mpls_lock_get(global->global_lock); /* LOCK */
1414 if (flag & LDP_FEC_CFG_BY_INDEX) {
1415 ldp_global_find_fec_index(global, f->index, &fec);
1416 } else {
1417 fec = ldp_fec_find(global, f);
1419 if (!fec)
1420 goto ldp_cfg_fec_nexthop_getnext_end;
1422 while (done == MPLS_BOOL_FALSE) {
1423 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1424 case MPLS_SUCCESS:
1425 case MPLS_END_OF_LIST:
1426 done = MPLS_BOOL_TRUE;
1427 break;
1428 case MPLS_FAILURE:
1429 break;
1430 default:
1431 MPLS_ASSERT(0);
1433 index++;
1435 mpls_lock_release(global->global_lock); /* UNLOCK */
1437 if (r == MPLS_SUCCESS) {
1438 n->index = nh->index;
1439 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1440 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1443 ldp_cfg_fec_nexthop_getnext_end:
1445 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1446 return r;
1449 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1450 mpls_nexthop *n, uint32_t flag)
1452 // ldp_global* g = (ldp_global*)handle;
1453 return MPLS_SUCCESS;
1456 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1457 mpls_nexthop *n, uint32_t flag)
1459 ldp_global *global = (ldp_global *) handle;
1460 ldp_fec *fec = NULL;
1461 ldp_nexthop *nh = NULL;
1462 mpls_return_enum retval = MPLS_FAILURE;
1464 MPLS_ASSERT(global != NULL && f != NULL && n != NULL);
1466 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1468 mpls_lock_get(global->global_lock); /* LOCK */
1470 if (flag & LDP_FEC_CFG_BY_INDEX) {
1471 ldp_global_find_fec_index(global, f->index, &fec);
1472 } else {
1473 fec = ldp_fec_find(global, f);
1475 if (!fec)
1476 goto ldp_cfg_fec_nexthop_set_end;
1478 if (flag & LDP_CFG_ADD) {
1479 if (ldp_fec_nexthop_find(fec, n) ||
1480 (nh = ldp_nexthop_create(global, n)) == NULL) {
1481 goto ldp_cfg_fec_nexthop_set_end;
1483 n->index = nh->index;
1484 ldp_fec_add_nexthop(global, fec, nh);
1485 ldp_fec_process_add(global, fec, nh, NULL);
1486 } else {
1487 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1488 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1489 } else {
1490 nh = ldp_fec_nexthop_find(fec, n);
1494 if (nh == NULL) {
1495 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1496 goto ldp_cfg_fec_nexthop_set_end;
1499 if (flag & LDP_CFG_DEL) {
1500 MPLS_REFCNT_HOLD(nh);
1501 ldp_fec_del_nexthop(global, fec, nh);
1502 if (ldp_fec_process_change(global, fec, MPLS_LIST_HEAD(&fec->nh_root),
1503 nh, NULL) != MPLS_SUCCESS) {
1504 MPLS_ASSERT(0);
1506 MPLS_REFCNT_RELEASE2(global, nh, ldp_nexthop_delete);
1509 retval = MPLS_SUCCESS;
1511 ldp_cfg_fec_nexthop_set_end:
1512 mpls_lock_release(global->global_lock); /* UNLOCK */
1514 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1516 return retval;
1519 /******************* ADDR **********************/
1521 mpls_return_enum ldp_cfg_addr_get(mpls_cfg_handle handle, ldp_addr * a,
1522 uint32_t flag)
1524 ldp_global *global = (ldp_global *) handle;
1525 ldp_session *session = NULL;
1526 ldp_nexthop *nexthop = NULL;
1527 ldp_addr *addr = NULL;
1528 mpls_return_enum retval = MPLS_FAILURE;
1530 MPLS_ASSERT(global !=NULL && a != NULL);
1532 LDP_ENTER(global->user_data, "ldp_cfg_addr_get");
1534 mpls_lock_get(global->global_lock); /* LOCK */
1536 ldp_global_find_addr_index(global, a->index, &addr);
1538 if (!addr)
1539 goto ldp_cfg_addr_get_end;
1541 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1542 a->index = addr->index;
1544 if (addr->session) {
1545 a->session_index = addr->session->index;
1548 if ((nexthop = MPLS_LIST_HEAD(&addr->nh_root))) {
1549 a->nexthop_index = nexthop->index;
1552 if (addr->iff) {
1553 a->if_index = addr->iff->index;
1556 retval = MPLS_SUCCESS;
1558 ldp_cfg_addr_get_end:
1559 mpls_lock_release(global->global_lock); /* UNLOCK */
1561 LDP_EXIT(global->user_data, "ldp_cfg_addr_get");
1563 return retval;
1566 mpls_return_enum ldp_cfg_addr_getnext(mpls_cfg_handle handle, ldp_addr *a,
1567 uint32_t flag)
1569 ldp_global *global = (ldp_global *) handle;
1570 ldp_addr *addr = NULL;
1571 mpls_return_enum r = MPLS_FAILURE;
1572 mpls_bool done = MPLS_BOOL_FALSE;
1573 int index;
1575 LDP_ENTER(global->user_data, "ldp_cfg_addr_getnext");
1577 if (a->index == 0) {
1578 index = 1;
1579 } else {
1580 index = a->index + 1;
1583 mpls_lock_get(global->global_lock); /* LOCK */
1585 while (done == MPLS_BOOL_FALSE) {
1586 switch ((r = ldp_global_find_addr_index(global, index, &addr))) {
1587 case MPLS_SUCCESS:
1588 case MPLS_END_OF_LIST:
1589 done = MPLS_BOOL_TRUE;
1590 break;
1591 case MPLS_FAILURE:
1592 break;
1593 default:
1594 MPLS_ASSERT(0);
1596 index++;
1598 mpls_lock_release(global->global_lock); /* UNLOCK */
1600 if (r == MPLS_SUCCESS) {
1601 a->index = addr->index;
1602 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1603 return ldp_cfg_addr_get(global, a, flag);
1606 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1607 return r;
1610 /******************* IF ADDR **********************/
1612 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1613 ldp_addr * a, uint32_t flag)
1615 ldp_global *global = (ldp_global *) handle;
1616 ldp_addr *addr = NULL;
1617 ldp_if *iff = NULL;
1618 mpls_return_enum retval = MPLS_FAILURE;
1620 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1622 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1624 mpls_lock_get(global->global_lock); /* LOCK */
1626 if (flag & LDP_IF_CFG_BY_INDEX) {
1627 ldp_global_find_if_index(global, i->index, &iff);
1628 } else {
1629 iff = ldp_global_find_if_handle(global, i->handle);
1631 if (!iff)
1632 goto ldp_cfg_if_addr_get_end;
1634 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1635 ldp_if_find_addr_index(iff, a->index, &addr);
1636 } else {
1637 addr = ldp_if_addr_find(iff, &a->address);
1639 if (!addr)
1640 goto ldp_cfg_if_addr_get_end;
1642 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1643 a->index = addr->index;
1645 retval = MPLS_SUCCESS;
1647 ldp_cfg_if_addr_get_end:
1648 mpls_lock_release(global->global_lock); /* UNLOCK */
1650 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1652 return retval;
1655 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1656 ldp_if * i, ldp_addr *a, uint32_t flag)
1658 ldp_global *global = (ldp_global *) handle;
1659 ldp_if *iff = NULL;
1660 ldp_addr *addr = NULL;
1661 mpls_return_enum r = MPLS_FAILURE;
1662 mpls_bool done = MPLS_BOOL_FALSE;
1663 int index;
1665 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1667 if (a->index == 0) {
1668 index = 1;
1669 } else {
1670 index = a->index + 1;
1673 mpls_lock_get(global->global_lock); /* LOCK */
1675 if (flag & LDP_IF_CFG_BY_INDEX) {
1676 ldp_global_find_if_index(global, i->index, &iff);
1677 } else {
1678 iff = ldp_global_find_if_handle(global, i->handle);
1680 if (!iff)
1681 goto ldp_cfg_if_addr_getnext_end;
1683 while (done == MPLS_BOOL_FALSE) {
1684 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1685 case MPLS_SUCCESS:
1686 case MPLS_END_OF_LIST:
1687 done = MPLS_BOOL_TRUE;
1688 break;
1689 case MPLS_FAILURE:
1690 break;
1691 default:
1692 MPLS_ASSERT(0);
1694 index++;
1696 mpls_lock_release(global->global_lock); /* UNLOCK */
1698 if (r == MPLS_SUCCESS) {
1699 a->index = addr->index;
1700 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1701 return ldp_cfg_if_addr_get(global, i, a, flag);
1704 ldp_cfg_if_addr_getnext_end:
1706 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1707 return r;
1710 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1711 ldp_addr *a, uint32_t flag)
1713 ldp_global *global = (ldp_global *) handle;
1714 ldp_if *iff = NULL;
1715 ldp_addr *addr = NULL;
1716 mpls_return_enum retval = MPLS_FAILURE;
1718 MPLS_ASSERT(global != NULL && i != NULL && a != NULL);
1720 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1722 mpls_lock_get(global->global_lock); /* LOCK */
1724 if (flag & LDP_IF_CFG_BY_INDEX) {
1725 ldp_global_find_if_index(global, i->index, &iff);
1726 } else {
1727 iff = ldp_global_find_if_handle(global, i->handle);
1729 if (!iff)
1730 goto ldp_cfg_if_addr_set_end;
1732 if (flag & LDP_CFG_ADD) {
1733 if (ldp_if_addr_find(iff, &a->address) || ((addr = ldp_addr_create(global,
1734 &a->address)) == NULL)) {
1735 goto ldp_cfg_if_addr_set_end;
1737 a->index = addr->index;
1738 ldp_if_add_addr(iff, addr);
1739 ldp_addr_process_add(global, addr);
1740 } else {
1741 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1742 ldp_if_find_addr_index(iff, a->index, &addr);
1743 } else {
1744 addr = ldp_if_addr_find(iff, &a->address);
1748 if (addr == NULL) {
1749 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1750 goto ldp_cfg_if_addr_set_end;
1753 if (flag & LDP_CFG_DEL) {
1754 ldp_addr_process_remove(global, addr);
1755 ldp_if_del_addr(global, iff, addr);
1758 retval = MPLS_SUCCESS;
1760 ldp_cfg_if_addr_set_end:
1761 mpls_lock_release(global->global_lock); /* UNLOCK */
1763 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1765 return retval;
1768 /******************* ADJACENCY **********************/
1770 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1771 uint32_t flag)
1773 ldp_global *global = (ldp_global *) handle;
1774 ldp_adj *adj = NULL;
1775 mpls_return_enum retval = MPLS_FAILURE;
1777 MPLS_ASSERT(global != NULL && a != NULL);
1779 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1781 mpls_lock_get(global->global_lock); /* LOCK */
1783 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1784 goto ldp_cfg_adj_get_end;
1786 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1787 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1788 sizeof(mpls_inet_addr));
1790 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1791 memcpy(&a->remote_source_address, &adj->remote_source_address,
1792 sizeof(mpls_inet_addr));
1794 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1795 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1796 sizeof(mpls_inet_addr));
1798 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1799 a->remote_csn = adj->remote_csn;
1801 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1802 a->remote_label_space = adj->remote_label_space;
1804 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1805 a->remote_hellotime = adj->remote_hellotime;
1807 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1808 a->entity_index = adj->entity ? adj->entity->index : 0;
1810 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1811 a->session_index = (adj->session) ? (adj->session->index) : 0;
1813 if (flag & LDP_ADJ_CFG_ROLE) {
1814 a->role = adj->role;
1816 retval = MPLS_SUCCESS;
1818 ldp_cfg_adj_get_end:
1820 mpls_lock_release(global->global_lock); /* UNLOCK */
1822 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1824 return retval;
1827 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1828 uint32_t flag)
1830 ldp_global *g = (ldp_global *) handle;
1831 ldp_adj *adj = NULL;
1832 mpls_return_enum r = MPLS_FAILURE;
1833 mpls_bool done = MPLS_BOOL_FALSE;
1834 int index;
1836 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1838 if (a->index == 0) {
1839 index = 1;
1840 } else {
1841 index = a->index + 1;
1844 mpls_lock_get(g->global_lock); /* LOCK */
1845 while (done == MPLS_BOOL_FALSE) {
1846 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1847 case MPLS_SUCCESS:
1848 case MPLS_END_OF_LIST:
1849 done = MPLS_BOOL_TRUE;
1850 break;
1851 case MPLS_FAILURE:
1852 break;
1853 default:
1854 MPLS_ASSERT(0);
1856 index++;
1858 mpls_lock_release(g->global_lock); /* UNLOCK */
1860 if (r == MPLS_SUCCESS) {
1861 a->index = adj->index;
1862 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1863 return ldp_cfg_adj_get(g, a, flag);
1865 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1866 return r;
1869 /******************* SESSION **********************/
1871 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1872 uint32_t flag)
1874 ldp_global *global = (ldp_global *) handle;
1875 ldp_session *session = NULL;
1876 mpls_return_enum retval = MPLS_FAILURE;
1878 MPLS_ASSERT(global !=NULL && s != NULL);
1880 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1882 mpls_lock_get(global->global_lock); /* LOCK */
1884 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1885 goto ldp_cfg_session_get_end;
1887 if (flag & LDP_SESSION_CFG_STATE) {
1888 s->state = session->state;
1890 if (flag & LDP_SESSION_CFG_OPER_UP) {
1891 s->oper_up = session->oper_up;
1893 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1894 s->oper_max_pdu = session->oper_max_pdu;
1896 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1897 s->oper_keepalive = session->oper_keepalive;
1899 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1900 s->oper_path_vector_limit = session->oper_path_vector_limit;
1902 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1903 s->oper_distribution_mode = session->oper_distribution_mode;
1905 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1906 s->oper_loop_detection = session->oper_loop_detection;
1908 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1909 s->remote_max_pdu = session->remote_max_pdu;
1911 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1912 s->remote_keepalive = session->remote_keepalive;
1914 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1915 s->remote_path_vector_limit = session->remote_path_vector_limit;
1917 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1918 s->remote_distribution_mode = session->remote_distribution_mode;
1920 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1921 s->remote_loop_detection = session->remote_loop_detection;
1923 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1924 s->remote_dest.addr.type = session->remote_dest.addr.type;
1925 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1927 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1928 s->remote_dest.port = session->remote_dest.port;
1930 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1931 s->no_label_resource_sent = session->no_label_resource_sent;
1933 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1934 s->no_label_resource_recv = session->no_label_resource_recv;
1936 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1937 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1938 s->adj_index = a ? a->index : 0;
1940 if (flag & LDP_SESSION_CFG_MESG_TX) {
1941 s->mesg_tx = session->mesg_tx;
1943 if (flag & LDP_SESSION_CFG_MESG_RX) {
1944 s->mesg_rx = session->mesg_rx;
1946 retval = MPLS_SUCCESS;
1948 ldp_cfg_session_get_end:
1949 mpls_lock_release(global->global_lock); /* UNLOCK */
1951 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1953 return retval;
1956 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1957 uint32_t flag)
1959 ldp_global *g = (ldp_global *) handle;
1960 ldp_session *ses = NULL;
1961 mpls_return_enum r = MPLS_FAILURE;
1962 mpls_bool done = MPLS_BOOL_FALSE;
1963 int index;
1965 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1967 if (s->index == 0) {
1968 index = 1;
1969 } else {
1970 index = s->index + 1;
1973 mpls_lock_get(g->global_lock); /* LOCK */
1974 while (done == MPLS_BOOL_FALSE) {
1975 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1976 case MPLS_SUCCESS:
1977 case MPLS_END_OF_LIST:
1978 done = MPLS_BOOL_TRUE;
1979 break;
1980 case MPLS_FAILURE:
1981 break;
1982 default:
1983 MPLS_ASSERT(0);
1985 index++;
1987 mpls_lock_release(g->global_lock); /* UNLOCK */
1989 if (r == MPLS_SUCCESS) {
1990 s->index = ses->index;
1992 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1993 return ldp_cfg_session_get(g, s, flag);
1996 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1998 return r;
2001 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
2002 ldp_session * s)
2004 ldp_global *g = (ldp_global *) handle;
2005 mpls_bool this_one = MPLS_BOOL_FALSE;
2006 mpls_return_enum r = MPLS_FAILURE;
2007 ldp_adj *adj_next = NULL;
2008 ldp_adj *adj = NULL;
2009 ldp_session *session = NULL;
2011 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
2013 /* if an adj_index of zero is sent, get the index of
2014 * the first adj in the list
2016 if (!s->adj_index) {
2017 this_one = MPLS_BOOL_TRUE;
2020 mpls_lock_get(g->global_lock); /* LOCK */
2022 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
2023 adj = MPLS_LIST_HEAD(&session->adj_root);
2024 while (adj) {
2025 if (this_one == MPLS_BOOL_TRUE) {
2026 adj_next = adj;
2027 break;
2030 /* since the entities are sort in the list ... */
2031 if (adj->index > s->adj_index) {
2032 break;
2033 } else if (adj->index == s->adj_index) {
2034 this_one = MPLS_BOOL_TRUE;
2036 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
2039 mpls_lock_release(g->global_lock); /* UNLOCK */
2041 if (adj_next) {
2042 s->adj_index = adj_next->index;
2043 r = MPLS_SUCCESS;
2046 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
2047 return r;
2050 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
2051 ldp_session * s, ldp_addr * a, uint32_t flag)
2053 ldp_global *global = (ldp_global *) handle;
2054 ldp_session *session = NULL;
2055 ldp_addr *addr = NULL;
2056 mpls_return_enum retval = MPLS_FAILURE;
2058 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
2060 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
2062 mpls_lock_get(global->global_lock); /* LOCK */
2064 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
2065 goto ldp_cfg_session_raddr_get_end;
2067 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
2068 goto ldp_cfg_session_raddr_get_end;
2070 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
2071 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
2073 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
2074 a->index = addr->index;
2076 retval = MPLS_SUCCESS;
2078 ldp_cfg_session_raddr_get_end:
2079 mpls_lock_release(global->global_lock); /* UNLOCK */
2081 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
2083 return retval;
2086 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
2087 ldp_session * s, ldp_addr * a, uint32_t flag)
2089 ldp_global *g = (ldp_global *) handle;
2090 ldp_addr *addr = NULL;
2091 mpls_return_enum r = MPLS_FAILURE;
2092 mpls_bool done = MPLS_BOOL_FALSE;
2093 ldp_session *sp = NULL;
2094 int index;
2096 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
2098 if (a->index == 0) {
2099 index = 1;
2100 } else {
2101 index = a->index + 1;
2104 r = ldp_global_find_session_index(g, s->index, &sp);
2105 if (r != MPLS_SUCCESS) {
2106 return r;
2109 mpls_lock_get(g->global_lock); /* LOCK */
2110 while (done == MPLS_BOOL_FALSE) {
2111 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
2112 case MPLS_SUCCESS:
2113 case MPLS_END_OF_LIST:
2114 done = MPLS_BOOL_TRUE;
2115 break;
2116 case MPLS_FAILURE:
2117 break;
2118 default:
2119 MPLS_ASSERT(0);
2121 index++;
2123 mpls_lock_release(g->global_lock); /* UNLOCK */
2125 if (r == MPLS_SUCCESS) {
2126 a->index = addr->index;
2127 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2130 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2131 return r;
2134 /******************* IN LABEL **********************/
2136 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2137 uint32_t flag)
2139 ldp_global *global = (ldp_global *) handle;
2140 ldp_inlabel *inlabel = NULL;
2141 mpls_return_enum retval = MPLS_FAILURE;
2143 MPLS_ASSERT(global !=NULL && i != NULL);
2145 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2147 mpls_lock_get(global->global_lock); /* LOCK */
2149 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2150 goto ldp_cfg_inlabel_get_end;
2152 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2153 i->info.labelspace = inlabel->info.labelspace;
2155 if (flag & LDP_INLABEL_CFG_LABEL) {
2156 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2158 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2159 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2162 retval = MPLS_SUCCESS;
2164 ldp_cfg_inlabel_get_end:
2165 mpls_lock_release(global->global_lock); /* UNLOCK */
2167 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2169 return retval;
2172 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2173 uint32_t flag)
2175 ldp_global *g = (ldp_global *) handle;
2176 ldp_inlabel *inlabel = NULL;
2177 mpls_return_enum r = MPLS_FAILURE;
2178 mpls_bool done = MPLS_BOOL_FALSE;
2179 int index;
2181 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2183 if (i->index == 0) {
2184 index = 1;
2185 } else {
2186 index = i->index + 1;
2189 mpls_lock_get(g->global_lock); /* LOCK */
2190 while (done == MPLS_BOOL_FALSE) {
2191 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2192 case MPLS_SUCCESS:
2193 case MPLS_END_OF_LIST:
2194 done = MPLS_BOOL_TRUE;
2195 break;
2196 case MPLS_FAILURE:
2197 break;
2198 default:
2199 MPLS_ASSERT(0);
2201 index++;
2203 mpls_lock_release(g->global_lock); /* UNLOCK */
2205 if (r == MPLS_SUCCESS) {
2206 i->index = inlabel->index;
2208 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2209 return ldp_cfg_inlabel_get(g, i, flag);
2212 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2214 return r;
2217 /******************* OUT LABEL **********************/
2219 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2220 uint32_t flag)
2222 ldp_global *global = (ldp_global *) handle;
2223 ldp_outlabel *outlabel = NULL;
2224 mpls_return_enum retval = MPLS_FAILURE;
2226 MPLS_ASSERT(global !=NULL && o != NULL);
2228 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2230 mpls_lock_get(global->global_lock); /* LOCK */
2232 if (ldp_global_find_outlabel_index(global, o->index,
2233 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2235 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2236 if (outlabel->nh) {
2237 o->nh_index = outlabel->nh->index;
2238 } else {
2239 o->nh_index = 0;
2242 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2243 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2245 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2246 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2248 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2249 o->merge_count = outlabel->merge_count;
2252 retval = MPLS_SUCCESS;
2254 ldp_cfg_outlabel_get_end:
2255 mpls_lock_release(global->global_lock); /* UNLOCK */
2257 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2259 return retval;
2262 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2263 ldp_outlabel * o, uint32_t flag)
2265 ldp_global *g = (ldp_global *) handle;
2266 ldp_outlabel *outlabel = NULL;
2267 mpls_return_enum r = MPLS_FAILURE;
2268 mpls_bool done = MPLS_BOOL_FALSE;
2269 int index;
2271 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2273 if (o->index == 0) {
2274 index = 1;
2275 } else {
2276 index = o->index + 1;
2279 mpls_lock_get(g->global_lock); /* LOCK */
2280 while (done == MPLS_BOOL_FALSE) {
2281 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2282 case MPLS_SUCCESS:
2283 case MPLS_END_OF_LIST:
2284 done = MPLS_BOOL_TRUE;
2285 break;
2286 case MPLS_FAILURE:
2287 break;
2288 default:
2289 MPLS_ASSERT(0);
2291 index++;
2293 mpls_lock_release(g->global_lock); /* UNLOCK */
2295 if (r == MPLS_SUCCESS) {
2296 o->index = outlabel->index;
2298 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2299 return ldp_cfg_outlabel_get(g, o, flag);
2302 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2304 return r;
2307 /******************* TUNNEL **********************/
2309 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2310 uint32_t flag)
2312 ldp_global *global = (ldp_global *) handle;
2313 mpls_return_enum retval = MPLS_FAILURE;
2314 ldp_tunnel *tunnel = NULL;
2316 MPLS_ASSERT(global !=NULL);
2318 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2320 mpls_lock_get(global->global_lock); /* LOCK */
2322 if (flag & LDP_CFG_ADD) {
2323 if (!(tunnel = ldp_tunnel_create())) {
2324 goto ldp_cfg_tunnel_set_end;
2326 _ldp_global_add_tunnel(global, tunnel);
2328 t->index = tunnel->index;
2329 } else {
2330 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2333 if (!tunnel) {
2334 LDP_PRINT(global->user_data,
2336 "ldp_cfg_tunnel_set:could not create tunnel\n");
2337 goto ldp_cfg_tunnel_set_end;
2340 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2341 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2342 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2344 goto ldp_cfg_tunnel_set_end;
2347 if (flag & LDP_CFG_DEL) {
2348 if (tunnel->outlabel)
2349 ldp_tunnel_del_outlabel(tunnel);
2350 if (tunnel->resource)
2351 ldp_tunnel_del_resource(tunnel);
2352 if (tunnel->hop_list)
2353 ldp_tunnel_del_hop_list(tunnel);
2354 _ldp_global_del_tunnel(global, tunnel);
2356 retval = MPLS_SUCCESS;
2357 goto ldp_cfg_tunnel_set_end;
2360 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2361 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2363 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2364 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2366 if (flag & LDP_TUNNEL_CFG_NAME) {
2367 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2369 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2370 tunnel->is_interface = t->is_interface;
2372 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2373 ldp_outlabel *outlabel = NULL;
2375 if (t->outlabel_index) {
2376 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2378 if (!outlabel) {
2379 goto ldp_cfg_tunnel_set_end;
2381 ldp_tunnel_add_outlabel(tunnel, outlabel);
2382 } else {
2383 ldp_tunnel_del_outlabel(tunnel);
2386 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2387 tunnel->setup_prio = t->setup_prio;
2389 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2390 tunnel->hold_prio = t->hold_prio;
2392 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2393 tunnel->instance_prio = t->instance_prio;
2395 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2396 tunnel->local_protect = t->local_protect;
2398 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2399 ldp_resource *resource = NULL;
2401 if (t->resource_index) {
2402 ldp_global_find_resource_index(global, t->resource_index, &resource);
2404 if (!resource) {
2405 goto ldp_cfg_tunnel_set_end;
2407 ldp_tunnel_add_resource(tunnel, resource);
2408 } else {
2409 ldp_tunnel_del_resource(tunnel);
2412 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2413 ldp_hop_list *hop_list = NULL;
2415 if (t->hop_list_index) {
2416 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2418 if (!hop_list) {
2419 goto ldp_cfg_tunnel_set_end;
2421 ldp_tunnel_add_hop_list(tunnel, hop_list);
2422 } else {
2423 ldp_tunnel_del_hop_list(tunnel);
2426 if (flag & LDP_TUNNEL_CFG_FEC) {
2427 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2429 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2430 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2431 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2432 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2433 goto ldp_cfg_tunnel_set_end;
2436 } else {
2437 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2438 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2439 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2440 goto ldp_cfg_tunnel_set_end;
2442 } else {
2443 LDP_PRINT(global->user_data,
2445 "ldp_cfg_tunnel_set: tunnel not ready\n");
2446 goto ldp_cfg_tunnel_set_end;
2451 retval = MPLS_SUCCESS;
2453 ldp_cfg_tunnel_set_end:
2455 mpls_lock_release(global->global_lock); /* UNLOCK */
2457 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2459 return retval;
2462 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2463 uint32_t flag)
2465 ldp_global *global = (ldp_global *) handle;
2466 mpls_return_enum retval = MPLS_FAILURE;
2467 ldp_tunnel *tunnel = NULL;
2469 MPLS_ASSERT(global !=NULL);
2471 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2473 mpls_lock_get(global->global_lock); /* LOCK */
2475 if (flag & LDP_CFG_ADD) {
2476 retval = MPLS_SUCCESS;
2477 goto ldp_cfg_tunnel_test_end;
2480 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2482 if (!tunnel) {
2483 goto ldp_cfg_tunnel_test_end;
2486 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2487 ldp_resource *resource = NULL;
2489 if (t->resource_index) {
2490 ldp_global_find_resource_index(global, t->resource_index, &resource);
2492 if (!resource) {
2493 goto ldp_cfg_tunnel_test_end;
2497 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2498 ldp_hop_list *hop_list = NULL;
2500 if (t->hop_list_index) {
2501 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2503 if (!hop_list) {
2504 goto ldp_cfg_tunnel_test_end;
2508 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2509 ldp_outlabel *outlabel = NULL;
2511 if (t->outlabel_index) {
2512 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2514 if (!outlabel) {
2515 goto ldp_cfg_tunnel_test_end;
2519 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2520 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2521 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2522 goto ldp_cfg_tunnel_test_end;
2524 retval = MPLS_SUCCESS;
2526 ldp_cfg_tunnel_test_end:
2528 mpls_lock_release(global->global_lock); /* UNLOCK */
2530 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2532 return retval;
2535 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2536 uint32_t flag)
2538 ldp_global *global = (ldp_global *) handle;
2539 mpls_return_enum retval = MPLS_FAILURE;
2540 ldp_tunnel *tunnel = NULL;
2542 MPLS_ASSERT(global !=NULL);
2544 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2546 mpls_lock_get(global->global_lock); /* LOCK */
2548 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2550 if (!tunnel) {
2551 goto ldp_cfg_tunnel_get_end;
2553 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2554 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2556 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2557 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2559 if (flag & LDP_TUNNEL_CFG_NAME) {
2560 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2562 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2563 t->is_interface = tunnel->is_interface;
2565 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2566 if (tunnel->outlabel) {
2567 t->outlabel_index = tunnel->outlabel->index;
2568 } else {
2569 t->outlabel_index = 0;
2572 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2573 t->setup_prio = tunnel->setup_prio;
2575 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2576 t->hold_prio = tunnel->hold_prio;
2578 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2579 tunnel->instance_prio = t->instance_prio;
2581 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2582 tunnel->local_protect = t->local_protect;
2584 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2585 if (tunnel->resource) {
2586 t->resource_index = tunnel->resource->index;
2587 } else {
2588 t->resource_index = 0;
2591 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2592 if (tunnel->hop_list) {
2593 t->hop_list_index = tunnel->hop_list->index;
2594 } else {
2595 t->hop_list_index = 0;
2598 if (flag & LDP_TUNNEL_CFG_FEC) {
2599 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2601 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2602 t->admin_state = tunnel->admin_state;
2604 retval = MPLS_SUCCESS;
2606 ldp_cfg_tunnel_get_end:
2608 mpls_lock_release(global->global_lock); /* UNLOCK */
2610 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2612 return retval;
2615 /******************* RESOURCE **********************/
2617 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2618 uint32_t flag)
2620 ldp_global *global = (ldp_global *) handle;
2621 mpls_return_enum retval = MPLS_FAILURE;
2622 ldp_resource *resource = NULL;
2624 MPLS_ASSERT(global !=NULL);
2626 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2628 mpls_lock_get(global->global_lock); /* LOCK */
2630 if (flag & LDP_CFG_ADD) {
2631 resource = ldp_resource_create();
2632 _ldp_global_add_resource(global, resource);
2634 r->index = resource->index;
2635 } else {
2636 ldp_global_find_resource_index(global, r->index, &resource);
2639 if (!resource) {
2640 goto ldp_cfg_resource_set_end;
2643 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2644 resource->max_rate = r->max_rate;
2646 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2647 resource->mean_rate = r->mean_rate;
2649 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2650 resource->burst_size = r->burst_size;
2652 retval = MPLS_SUCCESS;
2654 ldp_cfg_resource_set_end:
2656 mpls_lock_release(global->global_lock); /* UNLOCK */
2658 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2660 return retval;
2663 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2664 uint32_t flag)
2666 ldp_global *global = (ldp_global *) handle;
2667 mpls_return_enum retval = MPLS_FAILURE;
2668 ldp_resource *resource = NULL;
2670 MPLS_ASSERT(global !=NULL);
2672 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2674 mpls_lock_get(global->global_lock); /* LOCK */
2676 if (flag & LDP_CFG_ADD) {
2677 retval = MPLS_SUCCESS;
2678 goto ldp_cfg_resource_test_end;
2681 ldp_global_find_resource_index(global, r->index, &resource);
2683 if (!resource) {
2684 goto ldp_cfg_resource_test_end;
2687 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2688 goto ldp_cfg_resource_test_end;
2690 retval = MPLS_SUCCESS;
2692 ldp_cfg_resource_test_end:
2694 mpls_lock_release(global->global_lock); /* UNLOCK */
2696 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2698 return retval;
2701 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2702 uint32_t flag)
2704 ldp_global *global = (ldp_global *) handle;
2705 mpls_return_enum retval = MPLS_FAILURE;
2706 ldp_resource *resource = NULL;
2708 MPLS_ASSERT(global !=NULL);
2710 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2712 mpls_lock_get(global->global_lock); /* LOCK */
2714 ldp_global_find_resource_index(global, r->index, &resource);
2716 if (!resource) {
2717 goto ldp_cfg_resource_get_end;
2720 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2721 r->max_rate = resource->max_rate;
2723 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2724 r->mean_rate = resource->mean_rate;
2726 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2727 r->burst_size = resource->burst_size;
2729 retval = MPLS_SUCCESS;
2731 ldp_cfg_resource_get_end:
2733 mpls_lock_release(global->global_lock); /* UNLOCK */
2735 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2737 return retval;
2740 /******************* HOP **********************/
2742 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2743 uint32_t flag)
2745 ldp_global *global = (ldp_global *) handle;
2746 mpls_return_enum retval = MPLS_FAILURE;
2747 ldp_hop_list *hop_list = NULL;
2748 ldp_hop *hop = NULL;
2750 MPLS_ASSERT(global !=NULL);
2752 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2754 if (!h->hop_list_index && !h->index) {
2755 return retval;
2758 mpls_lock_get(global->global_lock); /* LOCK */
2760 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2762 if (!hop_list) {
2763 if (flag & LDP_CFG_ADD) {
2764 if (!(hop_list = ldp_hop_list_create())) {
2765 goto ldp_cfg_hop_set_end;
2767 _ldp_global_add_hop_list(global, hop_list);
2769 h->hop_list_index = hop_list->index;
2770 } else {
2771 goto ldp_cfg_hop_set_end;
2775 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2776 if (!hop) {
2777 if (h->index && (flag & LDP_CFG_ADD)) {
2778 if (!(hop = ldp_hop_create())) {
2779 goto ldp_cfg_hop_set_end;
2781 hop->index = h->index;
2782 ldp_hop_list_add_hop(hop_list, hop);
2783 } else {
2784 goto ldp_cfg_hop_set_end;
2788 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2789 hop->path_option = h->path_option;
2791 if (flag & LDP_HOP_CFG_ADDR) {
2792 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2794 if (flag & LDP_HOP_CFG_TYPE) {
2795 hop->type = h->type;
2797 retval = MPLS_SUCCESS;
2799 ldp_cfg_hop_set_end:
2801 mpls_lock_release(global->global_lock); /* UNLOCK */
2803 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2805 return retval;
2808 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2809 uint32_t flag)
2811 ldp_global *global = (ldp_global *) handle;
2812 mpls_return_enum retval = MPLS_FAILURE;
2813 ldp_hop_list *hop_list = NULL;
2814 ldp_hop *hop = NULL;
2816 MPLS_ASSERT(global !=NULL);
2818 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2820 mpls_lock_get(global->global_lock); /* LOCK */
2822 if (flag & LDP_CFG_ADD) {
2823 retval = MPLS_SUCCESS;
2824 goto ldp_cfg_hop_test_end;
2827 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2829 if (!hop_list) {
2830 goto ldp_cfg_hop_test_end;
2833 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2834 if (!hop) {
2835 goto ldp_cfg_hop_test_end;
2838 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2839 goto ldp_cfg_hop_test_end;
2841 retval = MPLS_SUCCESS;
2843 ldp_cfg_hop_test_end:
2845 mpls_lock_release(global->global_lock); /* UNLOCK */
2847 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2849 return retval;
2852 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2853 uint32_t flag)
2855 ldp_global *global = (ldp_global *) handle;
2856 mpls_return_enum retval = MPLS_FAILURE;
2857 ldp_hop_list *hop_list = NULL;
2858 ldp_hop *hop = NULL;
2860 MPLS_ASSERT(global !=NULL);
2862 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2864 mpls_lock_get(global->global_lock); /* LOCK */
2866 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2868 if (!hop_list) {
2869 goto ldp_cfg_hop_get_end;
2872 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2873 if (!hop) {
2874 goto ldp_cfg_hop_get_end;
2877 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2878 h->path_option = hop->path_option;
2880 if (flag & LDP_HOP_CFG_ADDR) {
2881 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2883 if (flag & LDP_HOP_CFG_TYPE) {
2884 h->type = hop->type;
2886 retval = MPLS_SUCCESS;
2888 ldp_cfg_hop_get_end:
2890 mpls_lock_release(global->global_lock); /* UNLOCK */
2892 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2894 return retval;