From: Vasu Dasari <vdasari@gmail.com>
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blobdfafe67e087b4bcdd7fa0b342163f816e9e0b0a8
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 LDP_PRINT(global->user_data, "%p(%s) xc to %p(%s)", 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 LDP_PRINT(global->user_data, "Duplicate interface exists");
862 goto ldp_cfg_if_set_end;
864 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==
865 MPLS_BOOL_FALSE) {
866 LDP_PRINT(global->user_data, "Invalid interface handle");
867 goto ldp_cfg_if_set_end;
869 if ((iff = ldp_if_create(global)) == NULL) {
870 LDP_PRINT(global->user_data, "Failure creating interface");
871 goto ldp_cfg_if_set_end;
874 /* copy the handle from the user */
875 iff->handle = i->handle;
877 /* search for addrs and nexthops that are waiting for this interface */
878 ap = MPLS_LIST_HEAD(&global->addr);
879 while (ap) {
880 if (ap->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(ap, _if))) {
881 ldp_if_add_addr(iff, ap);
883 ap = MPLS_LIST_NEXT(&global->addr, ap, _global);
886 np = MPLS_LIST_HEAD(&global->nexthop);
887 while (np) {
888 if ((np->info.type & MPLS_NH_IF) &&
889 (np->info.if_handle == iff->handle) && (!MPLS_LIST_IN_LIST(np, _if))) {
890 ldp_if_add_nexthop(iff, np);
892 np = MPLS_LIST_NEXT(&global->nexthop, np, _global);
895 /* send the newly created index back to the user */
896 i->index = iff->index;
897 MPLS_REFCNT_HOLD(iff);
899 } else {
900 if (flag & LDP_IF_CFG_BY_INDEX) {
901 ldp_global_find_if_index(global, i->index, &iff);
902 } else {
903 iff = ldp_global_find_if_handle(global, i->handle);
908 * if we can't find this interface or if the interface is active and
909 * we are trying to change propertises that can not be changed on a
910 * active interface
912 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
913 (flag & LDP_IF_CFG_WHEN_DOWN))) {
914 goto ldp_cfg_if_set_end;
917 if (flag & LDP_IF_CFG_LABEL_SPACE) {
918 iff->label_space = i->label_space;
921 if (flag & LDP_CFG_DEL) {
923 * if this interface is still attached to a entity that it is not ready
924 * to be removed
926 if (iff->entity != NULL) {
927 goto ldp_cfg_if_set_end;
930 np = MPLS_LIST_HEAD(&iff->nh_root);
931 while ((np = MPLS_LIST_HEAD(&iff->nh_root))) {
932 ldp_if_del_nexthop(global, iff, np);
935 ap = MPLS_LIST_HEAD(&iff->addr_root);
936 while ((ap = MPLS_LIST_HEAD(&iff->addr_root))) {
937 ldp_if_del_addr(global, iff, ap);
940 MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);
943 global->configuration_sequence_number++;
945 retval = MPLS_SUCCESS;
947 ldp_cfg_if_set_end:
948 mpls_lock_release(global->global_lock); /* UNLOCK */
950 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
952 return retval;
955 /******************* ATTR **********************/
957 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
958 uint32_t flag)
960 ldp_global *global = (ldp_global *) handle;
961 ldp_attr *attr = NULL;
962 mpls_return_enum retval = MPLS_FAILURE;
964 MPLS_ASSERT(global !=NULL && a != NULL);
966 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
968 mpls_lock_get(global->global_lock); /* LOCK */
970 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
971 goto ldp_cfg_attr_get_end;
973 if (flag & LDP_ATTR_CFG_STATE) {
974 a->state = attr->state;
976 if (flag & LDP_ATTR_CFG_FEC) {
977 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
979 if (flag & LDP_ATTR_CFG_LABEL) {
980 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
982 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
983 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
985 if (flag & LDP_ATTR_CFG_PATH) {
986 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
988 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
989 a->session_index = (attr->session) ? (attr->session->index) : 0;
991 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
992 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
994 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
995 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
997 if (flag & LDP_ATTR_CFG_INGRESS) {
998 a->ingress = attr->ingress;
1000 retval = MPLS_SUCCESS;
1002 ldp_cfg_attr_get_end:
1003 mpls_lock_release(global->global_lock); /* UNLOCK */
1005 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
1007 return retval;
1010 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
1011 uint32_t flag)
1013 ldp_global *g = (ldp_global *) handle;
1014 ldp_attr *attr = NULL;
1015 mpls_return_enum r = MPLS_FAILURE;
1016 mpls_bool done = MPLS_BOOL_FALSE;
1017 int index;
1019 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
1021 if (a->index == 0) {
1022 index = 1;
1023 } else {
1024 index = a->index + 1;
1027 mpls_lock_get(g->global_lock); /* LOCK */
1028 while (done == MPLS_BOOL_FALSE) {
1029 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
1030 case MPLS_SUCCESS:
1031 case MPLS_END_OF_LIST:
1032 done = MPLS_BOOL_TRUE;
1033 break;
1034 case MPLS_FAILURE:
1035 break;
1036 default:
1037 MPLS_ASSERT(0);
1039 index++;
1041 mpls_lock_release(g->global_lock); /* UNLOCK */
1043 if (r == MPLS_SUCCESS) {
1044 a->index = attr->index;
1045 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1046 return ldp_cfg_attr_get(g, a, flag);
1048 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1049 return r;
1052 /******************* PEER **********************/
1054 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
1055 uint32_t flag)
1057 ldp_global *global = (ldp_global *) handle;
1058 ldp_peer *peer = NULL;
1059 mpls_return_enum retval = MPLS_FAILURE;
1061 MPLS_ASSERT(global !=NULL && p != NULL);
1063 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
1065 mpls_lock_get(global->global_lock); /* LOCK */
1067 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
1068 goto ldp_cfg_peer_get_end;
1070 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1071 p->label_space = peer->label_space;
1073 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1074 p->target_role = peer->target_role;
1076 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1077 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1079 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1080 p->entity_index = peer->entity->index;
1082 if (flag & LDP_PEER_CFG_OPER_STATE) {
1083 p->oper_state = peer->oper_state;
1085 if (flag & LDP_PEER_CFG_PEER_NAME) {
1086 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1088 retval = MPLS_SUCCESS;
1090 ldp_cfg_peer_get_end:
1091 mpls_lock_release(global->global_lock); /* UNLOCK */
1093 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1095 return retval;
1098 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1099 uint32_t flag)
1101 ldp_global *g = (ldp_global *) handle;
1102 ldp_peer *peer = NULL;
1103 mpls_return_enum r = MPLS_FAILURE;
1104 mpls_bool done = MPLS_BOOL_FALSE;
1105 int index;
1107 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1109 if (p->index == 0) {
1110 index = 1;
1111 } else {
1112 index = p->index + 1;
1115 mpls_lock_get(g->global_lock); /* LOCK */
1116 while (done == MPLS_BOOL_FALSE) {
1117 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1118 case MPLS_SUCCESS:
1119 case MPLS_END_OF_LIST:
1120 done = MPLS_BOOL_TRUE;
1121 break;
1122 case MPLS_FAILURE:
1123 break;
1124 default:
1125 MPLS_ASSERT(0);
1127 index++;
1129 mpls_lock_release(g->global_lock); /* UNLOCK */
1131 if (r == MPLS_SUCCESS) {
1132 p->index = peer->index;
1133 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1134 return ldp_cfg_peer_get(g, p, flag);
1136 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1137 return r;
1140 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1141 uint32_t flag)
1143 // ldp_global* g = (ldp_global*)handle;
1144 return MPLS_SUCCESS;
1147 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1148 uint32_t flag)
1150 ldp_global *global = (ldp_global *) handle;
1151 ldp_peer *peer = NULL;
1152 mpls_return_enum retval = MPLS_FAILURE;
1154 MPLS_ASSERT(global !=NULL && p != NULL);
1156 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1158 mpls_lock_get(global->global_lock); /* LOCK */
1160 if (flag & LDP_CFG_ADD) {
1161 if ((peer = ldp_peer_create()) == NULL) {
1162 goto ldp_cfg_peer_set_end;
1164 p->index = peer->index;
1165 _ldp_global_add_peer(global, peer);
1166 } else {
1167 ldp_global_find_peer_index(global, p->index, &peer);
1170 if (peer == NULL) {
1171 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1173 goto ldp_cfg_peer_set_end;
1175 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1176 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1178 goto ldp_cfg_peer_set_end;
1181 if (flag & LDP_CFG_DEL) {
1182 if (peer->entity != NULL) {
1183 LDP_PRINT(global->user_data,
1184 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1186 goto ldp_cfg_peer_set_end;
1189 _ldp_global_del_peer(global, peer);
1191 retval = MPLS_SUCCESS;
1192 goto ldp_cfg_peer_set_end;
1194 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1195 peer->label_space = p->label_space;
1197 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1198 peer->target_role = p->target_role;
1200 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1201 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1203 if (flag & LDP_PEER_CFG_PEER_NAME) {
1204 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1206 p->peer_name);
1207 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1209 global->configuration_sequence_number++;
1211 retval = MPLS_SUCCESS;
1213 ldp_cfg_peer_set_end:
1214 mpls_lock_release(global->global_lock); /* UNLOCK */
1216 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1218 return retval;
1220 /******************* FEC **********************/
1222 mpls_return_enum ldp_cfg_fec_get(mpls_cfg_handle handle, mpls_fec * f,
1223 uint32_t flag)
1225 ldp_global *global = (ldp_global *) handle;
1226 ldp_fec *fec = NULL;
1227 mpls_return_enum retval = MPLS_FAILURE;
1229 MPLS_ASSERT(global !=NULL && f != NULL);
1231 LDP_ENTER(global->user_data, "ldp_cfg_fec_get");
1233 mpls_lock_get(global->global_lock); /* LOCK */
1235 if (flag & LDP_FEC_CFG_BY_INDEX) {
1236 ldp_global_find_fec_index(global, f->index, &fec);
1237 } else {
1238 fec = ldp_fec_find(global, f);
1240 if (!fec)
1241 goto ldp_cfg_fec_get_end;
1243 memcpy(f, &fec->info, sizeof(mpls_fec));
1244 f->index = fec->index;
1245 f->is_route = fec->is_route;
1246 retval = MPLS_SUCCESS;
1248 ldp_cfg_fec_get_end:
1249 mpls_lock_release(global->global_lock); /* UNLOCK */
1251 LDP_EXIT(global->user_data, "ldp_cfg_fec_get");
1253 return retval;
1256 mpls_return_enum ldp_cfg_fec_getnext(mpls_cfg_handle handle, mpls_fec * f,
1257 uint32_t flag)
1259 ldp_global *g = (ldp_global *) handle;
1260 ldp_fec *fec = NULL;
1261 mpls_return_enum r = MPLS_FAILURE;
1262 mpls_bool done = MPLS_BOOL_FALSE;
1263 int index;
1265 LDP_ENTER(g->user_data, "ldp_cfg_fec_getnext");
1267 if (f->index == 0) {
1268 index = 1;
1269 } else {
1270 index = f->index + 1;
1273 mpls_lock_get(g->global_lock); /* LOCK */
1274 while (done == MPLS_BOOL_FALSE) {
1275 switch ((r = ldp_global_find_fec_index(g, index, &fec))) {
1276 case MPLS_SUCCESS:
1277 case MPLS_END_OF_LIST:
1278 done = MPLS_BOOL_TRUE;
1279 break;
1280 case MPLS_FAILURE:
1281 break;
1282 default:
1283 MPLS_ASSERT(0);
1285 index++;
1287 mpls_lock_release(g->global_lock); /* UNLOCK */
1289 if (r == MPLS_SUCCESS) {
1290 f->index = fec->index;
1291 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1292 return ldp_cfg_fec_get(g, f, flag);
1294 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1295 return r;
1298 mpls_return_enum ldp_cfg_fec_test(mpls_cfg_handle handle, mpls_fec * f,
1299 uint32_t flag)
1301 // ldp_global* g = (ldp_global*)handle;
1302 return MPLS_SUCCESS;
1305 mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f,
1306 uint32_t flag)
1308 ldp_global *global = (ldp_global *) handle;
1309 ldp_fec *fec = NULL;
1310 mpls_return_enum retval = MPLS_FAILURE;
1312 MPLS_ASSERT(global != NULL && f != NULL);
1314 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1316 mpls_lock_get(global->global_lock); /* LOCK */
1318 if (flag & LDP_CFG_ADD) {
1319 if ((fec = ldp_fec_find(global, f))) {
1320 if (fec->is_route == MPLS_BOOL_TRUE) {
1321 goto ldp_cfg_fec_set_end;
1323 } else {
1324 if ((fec = ldp_fec_create(global, f)) == NULL) {
1325 goto ldp_cfg_fec_set_end;
1328 fec->is_route = MPLS_BOOL_TRUE;
1329 MPLS_REFCNT_HOLD(fec);
1330 f->index = fec->index;
1331 } else {
1332 if (flag & LDP_FEC_CFG_BY_INDEX) {
1333 ldp_global_find_fec_index(global, f->index, &fec);
1334 } else {
1335 fec = ldp_fec_find(global, f);
1339 if (fec == NULL) {
1340 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1341 goto ldp_cfg_fec_set_end;
1344 if (flag & LDP_CFG_DEL) {
1346 * we can only delete the fec if all of the nexthops have been removed
1348 if (!MPLS_LIST_EMPTY(&fec->nh_root)) {
1349 goto ldp_cfg_fec_set_end;
1352 fec->is_route = MPLS_BOOL_FALSE;
1355 * we hold the last refcnt, this should result in a call to
1356 * ldp_fec_delete
1358 MPLS_REFCNT_RELEASE2(global, fec, ldp_fec_delete);
1361 retval = MPLS_SUCCESS;
1363 ldp_cfg_fec_set_end:
1364 mpls_lock_release(global->global_lock); /* UNLOCK */
1366 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1367 return retval;
1370 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1371 mpls_nexthop *n, uint32_t flag)
1373 ldp_global *global = (ldp_global *) handle;
1374 ldp_fec *fec = NULL;
1375 ldp_nexthop *nh = NULL;
1376 mpls_return_enum retval = MPLS_FAILURE;
1378 MPLS_ASSERT(global !=NULL && f != NULL);
1380 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1382 mpls_lock_get(global->global_lock); /* LOCK */
1384 if (flag & LDP_FEC_CFG_BY_INDEX) {
1385 ldp_global_find_fec_index(global, f->index, &fec);
1386 } else {
1387 fec = ldp_fec_find(global, f);
1389 if (!fec)
1390 goto ldp_cfg_fec_nexthop_get_end;
1392 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1393 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1394 } else {
1395 nh = ldp_fec_nexthop_find(fec, n);
1397 if (!nh)
1398 goto ldp_cfg_fec_nexthop_get_end;
1400 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1401 n->index = nh->index;
1402 retval = MPLS_SUCCESS;
1404 ldp_cfg_fec_nexthop_get_end:
1405 mpls_lock_release(global->global_lock); /* UNLOCK */
1407 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1409 return retval;
1412 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1413 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1415 ldp_global *global = (ldp_global *) handle;
1416 ldp_fec *fec = NULL;
1417 ldp_nexthop *nh = NULL;
1418 mpls_return_enum r = MPLS_FAILURE;
1419 mpls_bool done = MPLS_BOOL_FALSE;
1420 int index;
1422 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1424 if (n->index == 0) {
1425 index = 1;
1426 } else {
1427 index = n->index + 1;
1430 mpls_lock_get(global->global_lock); /* LOCK */
1432 if (flag & LDP_FEC_CFG_BY_INDEX) {
1433 ldp_global_find_fec_index(global, f->index, &fec);
1434 } else {
1435 fec = ldp_fec_find(global, f);
1437 if (!fec)
1438 goto ldp_cfg_fec_nexthop_getnext_end;
1440 while (done == MPLS_BOOL_FALSE) {
1441 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1442 case MPLS_SUCCESS:
1443 case MPLS_END_OF_LIST:
1444 done = MPLS_BOOL_TRUE;
1445 break;
1446 case MPLS_FAILURE:
1447 break;
1448 default:
1449 MPLS_ASSERT(0);
1451 index++;
1453 mpls_lock_release(global->global_lock); /* UNLOCK */
1455 if (r == MPLS_SUCCESS) {
1456 n->index = nh->index;
1457 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1458 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1461 ldp_cfg_fec_nexthop_getnext_end:
1463 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1464 return r;
1467 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1468 mpls_nexthop *n, uint32_t flag)
1470 // ldp_global* g = (ldp_global*)handle;
1471 return MPLS_SUCCESS;
1474 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1475 mpls_nexthop *n, uint32_t flag)
1477 ldp_global *global = (ldp_global *) handle;
1478 ldp_fec *fec = NULL;
1479 ldp_nexthop *nh = NULL;
1480 mpls_return_enum retval = MPLS_FAILURE;
1482 MPLS_ASSERT(global != NULL && f != NULL && n != NULL);
1484 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1486 mpls_lock_get(global->global_lock); /* LOCK */
1488 if (flag & LDP_FEC_CFG_BY_INDEX) {
1489 ldp_global_find_fec_index(global, f->index, &fec);
1490 } else {
1491 fec = ldp_fec_find(global, f);
1493 if (!fec)
1494 goto ldp_cfg_fec_nexthop_set_end;
1496 if (flag & LDP_CFG_ADD) {
1497 if (ldp_fec_nexthop_find(fec, n) ||
1498 (nh = ldp_nexthop_create(global, n)) == NULL) {
1499 goto ldp_cfg_fec_nexthop_set_end;
1501 n->index = nh->index;
1502 ldp_fec_add_nexthop(global, fec, nh);
1503 ldp_fec_process_add(global, fec, nh, NULL);
1504 } else {
1505 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1506 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1507 } else {
1508 nh = ldp_fec_nexthop_find(fec, n);
1512 if (nh == NULL) {
1513 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1514 goto ldp_cfg_fec_nexthop_set_end;
1517 if (flag & LDP_CFG_DEL) {
1518 MPLS_REFCNT_HOLD(nh);
1519 ldp_fec_del_nexthop(global, fec, nh);
1520 if (ldp_fec_process_change(global, fec, MPLS_LIST_HEAD(&fec->nh_root),
1521 nh, NULL) != MPLS_SUCCESS) {
1522 MPLS_ASSERT(0);
1524 MPLS_REFCNT_RELEASE2(global, nh, ldp_nexthop_delete);
1527 retval = MPLS_SUCCESS;
1529 ldp_cfg_fec_nexthop_set_end:
1530 mpls_lock_release(global->global_lock); /* UNLOCK */
1532 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1534 return retval;
1537 /******************* ADDR **********************/
1539 mpls_return_enum ldp_cfg_addr_get(mpls_cfg_handle handle, ldp_addr * a,
1540 uint32_t flag)
1542 ldp_global *global = (ldp_global *) handle;
1543 ldp_session *session = NULL;
1544 ldp_nexthop *nexthop = NULL;
1545 ldp_addr *addr = NULL;
1546 mpls_return_enum retval = MPLS_FAILURE;
1548 MPLS_ASSERT(global !=NULL && a != NULL);
1550 LDP_ENTER(global->user_data, "ldp_cfg_addr_get");
1552 mpls_lock_get(global->global_lock); /* LOCK */
1554 ldp_global_find_addr_index(global, a->index, &addr);
1556 if (!addr)
1557 goto ldp_cfg_addr_get_end;
1559 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1560 a->index = addr->index;
1562 if (addr->session) {
1563 a->session_index = addr->session->index;
1566 if ((nexthop = MPLS_LIST_HEAD(&addr->nh_root))) {
1567 a->nexthop_index = nexthop->index;
1570 if (addr->iff) {
1571 a->if_index = addr->iff->index;
1574 retval = MPLS_SUCCESS;
1576 ldp_cfg_addr_get_end:
1577 mpls_lock_release(global->global_lock); /* UNLOCK */
1579 LDP_EXIT(global->user_data, "ldp_cfg_addr_get");
1581 return retval;
1584 mpls_return_enum ldp_cfg_addr_getnext(mpls_cfg_handle handle, ldp_addr *a,
1585 uint32_t flag)
1587 ldp_global *global = (ldp_global *) handle;
1588 ldp_addr *addr = NULL;
1589 mpls_return_enum r = MPLS_FAILURE;
1590 mpls_bool done = MPLS_BOOL_FALSE;
1591 int index;
1593 LDP_ENTER(global->user_data, "ldp_cfg_addr_getnext");
1595 if (a->index == 0) {
1596 index = 1;
1597 } else {
1598 index = a->index + 1;
1601 mpls_lock_get(global->global_lock); /* LOCK */
1603 while (done == MPLS_BOOL_FALSE) {
1604 switch ((r = ldp_global_find_addr_index(global, index, &addr))) {
1605 case MPLS_SUCCESS:
1606 case MPLS_END_OF_LIST:
1607 done = MPLS_BOOL_TRUE;
1608 break;
1609 case MPLS_FAILURE:
1610 break;
1611 default:
1612 MPLS_ASSERT(0);
1614 index++;
1616 mpls_lock_release(global->global_lock); /* UNLOCK */
1618 if (r == MPLS_SUCCESS) {
1619 a->index = addr->index;
1620 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1621 return ldp_cfg_addr_get(global, a, flag);
1624 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1625 return r;
1628 /******************* IF ADDR **********************/
1630 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1631 ldp_addr * a, uint32_t flag)
1633 ldp_global *global = (ldp_global *) handle;
1634 ldp_addr *addr = NULL;
1635 ldp_if *iff = NULL;
1636 mpls_return_enum retval = MPLS_FAILURE;
1638 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1640 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1642 mpls_lock_get(global->global_lock); /* LOCK */
1644 if (flag & LDP_IF_CFG_BY_INDEX) {
1645 ldp_global_find_if_index(global, i->index, &iff);
1646 } else {
1647 iff = ldp_global_find_if_handle(global, i->handle);
1649 if (!iff)
1650 goto ldp_cfg_if_addr_get_end;
1652 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1653 ldp_if_find_addr_index(iff, a->index, &addr);
1654 } else {
1655 addr = ldp_if_addr_find(iff, &a->address);
1657 if (!addr)
1658 goto ldp_cfg_if_addr_get_end;
1660 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1661 a->index = addr->index;
1663 retval = MPLS_SUCCESS;
1665 ldp_cfg_if_addr_get_end:
1666 mpls_lock_release(global->global_lock); /* UNLOCK */
1668 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1670 return retval;
1673 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1674 ldp_if * i, ldp_addr *a, uint32_t flag)
1676 ldp_global *global = (ldp_global *) handle;
1677 ldp_if *iff = NULL;
1678 ldp_addr *addr = NULL;
1679 mpls_return_enum r = MPLS_FAILURE;
1680 mpls_bool done = MPLS_BOOL_FALSE;
1681 int index;
1683 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1685 if (a->index == 0) {
1686 index = 1;
1687 } else {
1688 index = a->index + 1;
1691 mpls_lock_get(global->global_lock); /* LOCK */
1693 if (flag & LDP_IF_CFG_BY_INDEX) {
1694 ldp_global_find_if_index(global, i->index, &iff);
1695 } else {
1696 iff = ldp_global_find_if_handle(global, i->handle);
1698 if (!iff)
1699 goto ldp_cfg_if_addr_getnext_end;
1701 while (done == MPLS_BOOL_FALSE) {
1702 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1703 case MPLS_SUCCESS:
1704 case MPLS_END_OF_LIST:
1705 done = MPLS_BOOL_TRUE;
1706 break;
1707 case MPLS_FAILURE:
1708 break;
1709 default:
1710 MPLS_ASSERT(0);
1712 index++;
1714 mpls_lock_release(global->global_lock); /* UNLOCK */
1716 if (r == MPLS_SUCCESS) {
1717 a->index = addr->index;
1718 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1719 return ldp_cfg_if_addr_get(global, i, a, flag);
1722 ldp_cfg_if_addr_getnext_end:
1724 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1725 return r;
1728 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1729 ldp_addr *a, uint32_t flag)
1731 ldp_global *global = (ldp_global *) handle;
1732 ldp_if *iff = NULL;
1733 ldp_addr *addr = NULL;
1734 mpls_return_enum retval = MPLS_FAILURE;
1736 MPLS_ASSERT(global != NULL && i != NULL && a != NULL);
1738 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1740 mpls_lock_get(global->global_lock); /* LOCK */
1742 if (flag & LDP_IF_CFG_BY_INDEX) {
1743 ldp_global_find_if_index(global, i->index, &iff);
1744 } else {
1745 iff = ldp_global_find_if_handle(global, i->handle);
1747 if (!iff) {
1748 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such iff\n");
1749 goto ldp_cfg_if_addr_set_end;
1752 if (flag & LDP_CFG_ADD) {
1753 if (ldp_if_addr_find(iff, &a->address) || ((addr = ldp_addr_create(global,
1754 &a->address)) == NULL)) {
1755 goto ldp_cfg_if_addr_set_end;
1757 a->index = addr->index;
1758 ldp_if_add_addr(iff, addr);
1759 ldp_addr_process_add(global, addr);
1760 } else {
1761 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1762 ldp_if_find_addr_index(iff, a->index, &addr);
1763 } else {
1764 addr = ldp_if_addr_find(iff, &a->address);
1768 if (addr == NULL) {
1769 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1770 goto ldp_cfg_if_addr_set_end;
1773 if (flag & LDP_CFG_DEL) {
1774 ldp_addr_process_remove(global, addr);
1775 ldp_if_del_addr(global, iff, addr);
1778 retval = MPLS_SUCCESS;
1780 ldp_cfg_if_addr_set_end:
1781 mpls_lock_release(global->global_lock); /* UNLOCK */
1783 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1785 return retval;
1788 /******************* ADJACENCY **********************/
1790 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1791 uint32_t flag)
1793 ldp_global *global = (ldp_global *) handle;
1794 ldp_adj *adj = NULL;
1795 mpls_return_enum retval = MPLS_FAILURE;
1797 MPLS_ASSERT(global != NULL && a != NULL);
1799 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1801 mpls_lock_get(global->global_lock); /* LOCK */
1803 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1804 goto ldp_cfg_adj_get_end;
1806 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1807 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1808 sizeof(mpls_inet_addr));
1810 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1811 memcpy(&a->remote_source_address, &adj->remote_source_address,
1812 sizeof(mpls_inet_addr));
1814 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1815 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1816 sizeof(mpls_inet_addr));
1818 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1819 a->remote_csn = adj->remote_csn;
1821 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1822 a->remote_label_space = adj->remote_label_space;
1824 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1825 a->remote_hellotime = adj->remote_hellotime;
1827 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1828 a->entity_index = adj->entity ? adj->entity->index : 0;
1830 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1831 a->session_index = (adj->session) ? (adj->session->index) : 0;
1833 if (flag & LDP_ADJ_CFG_ROLE) {
1834 a->role = adj->role;
1836 retval = MPLS_SUCCESS;
1838 ldp_cfg_adj_get_end:
1840 mpls_lock_release(global->global_lock); /* UNLOCK */
1842 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1844 return retval;
1847 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1848 uint32_t flag)
1850 ldp_global *g = (ldp_global *) handle;
1851 ldp_adj *adj = NULL;
1852 mpls_return_enum r = MPLS_FAILURE;
1853 mpls_bool done = MPLS_BOOL_FALSE;
1854 int index;
1856 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1858 if (a->index == 0) {
1859 index = 1;
1860 } else {
1861 index = a->index + 1;
1864 mpls_lock_get(g->global_lock); /* LOCK */
1865 while (done == MPLS_BOOL_FALSE) {
1866 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1867 case MPLS_SUCCESS:
1868 case MPLS_END_OF_LIST:
1869 done = MPLS_BOOL_TRUE;
1870 break;
1871 case MPLS_FAILURE:
1872 break;
1873 default:
1874 MPLS_ASSERT(0);
1876 index++;
1878 mpls_lock_release(g->global_lock); /* UNLOCK */
1880 if (r == MPLS_SUCCESS) {
1881 a->index = adj->index;
1882 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1883 return ldp_cfg_adj_get(g, a, flag);
1885 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1886 return r;
1889 /******************* SESSION **********************/
1891 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1892 uint32_t flag)
1894 ldp_global *global = (ldp_global *) handle;
1895 ldp_session *session = NULL;
1896 mpls_return_enum retval = MPLS_FAILURE;
1898 MPLS_ASSERT(global !=NULL && s != NULL);
1900 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1902 mpls_lock_get(global->global_lock); /* LOCK */
1904 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1905 goto ldp_cfg_session_get_end;
1907 if (flag & LDP_SESSION_CFG_STATE) {
1908 s->state = session->state;
1910 if (flag & LDP_SESSION_CFG_OPER_UP) {
1911 s->oper_up = session->oper_up;
1913 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1914 s->oper_max_pdu = session->oper_max_pdu;
1916 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1917 s->oper_keepalive = session->oper_keepalive;
1919 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1920 s->oper_path_vector_limit = session->oper_path_vector_limit;
1922 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1923 s->oper_distribution_mode = session->oper_distribution_mode;
1925 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1926 s->oper_loop_detection = session->oper_loop_detection;
1928 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1929 s->remote_max_pdu = session->remote_max_pdu;
1931 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1932 s->remote_keepalive = session->remote_keepalive;
1934 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1935 s->remote_path_vector_limit = session->remote_path_vector_limit;
1937 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1938 s->remote_distribution_mode = session->remote_distribution_mode;
1940 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1941 s->remote_loop_detection = session->remote_loop_detection;
1943 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1944 s->remote_dest.addr.type = session->remote_dest.addr.type;
1945 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1947 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1948 s->remote_dest.port = session->remote_dest.port;
1950 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1951 s->no_label_resource_sent = session->no_label_resource_sent;
1953 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1954 s->no_label_resource_recv = session->no_label_resource_recv;
1956 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1957 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1958 s->adj_index = a ? a->index : 0;
1960 if (flag & LDP_SESSION_CFG_MESG_TX) {
1961 s->mesg_tx = session->mesg_tx;
1963 if (flag & LDP_SESSION_CFG_MESG_RX) {
1964 s->mesg_rx = session->mesg_rx;
1966 if (flag & LDP_SESSION_CFG_LOCAL_NAME) {
1967 if (mpls_socket_handle_verify(global->socket_handle,
1968 session->socket) == MPLS_BOOL_TRUE) {
1969 mpls_socket_get_local_name(global->socket_handle, session->socket,
1970 &s->local_name);
1973 if (flag & LDP_SESSION_CFG_REMOTE_NAME) {
1974 if (mpls_socket_handle_verify(global->socket_handle,
1975 session->socket) == MPLS_BOOL_TRUE) {
1976 mpls_socket_get_remote_name(global->socket_handle, session->socket,
1977 &s->remote_name);
1980 retval = MPLS_SUCCESS;
1982 ldp_cfg_session_get_end:
1983 mpls_lock_release(global->global_lock); /* UNLOCK */
1985 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1987 return retval;
1990 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1991 uint32_t flag)
1993 ldp_global *g = (ldp_global *) handle;
1994 ldp_session *ses = NULL;
1995 mpls_return_enum r = MPLS_FAILURE;
1996 mpls_bool done = MPLS_BOOL_FALSE;
1997 int index;
1999 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
2001 if (s->index == 0) {
2002 index = 1;
2003 } else {
2004 index = s->index + 1;
2007 mpls_lock_get(g->global_lock); /* LOCK */
2008 while (done == MPLS_BOOL_FALSE) {
2009 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
2010 case MPLS_SUCCESS:
2011 case MPLS_END_OF_LIST:
2012 done = MPLS_BOOL_TRUE;
2013 break;
2014 case MPLS_FAILURE:
2015 break;
2016 default:
2017 MPLS_ASSERT(0);
2019 index++;
2021 mpls_lock_release(g->global_lock); /* UNLOCK */
2023 if (r == MPLS_SUCCESS) {
2024 s->index = ses->index;
2026 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2027 return ldp_cfg_session_get(g, s, flag);
2030 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2032 return r;
2035 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
2036 ldp_session * s)
2038 ldp_global *g = (ldp_global *) handle;
2039 mpls_bool this_one = MPLS_BOOL_FALSE;
2040 mpls_return_enum r = MPLS_FAILURE;
2041 ldp_adj *adj_next = NULL;
2042 ldp_adj *adj = NULL;
2043 ldp_session *session = NULL;
2045 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
2047 /* if an adj_index of zero is sent, get the index of
2048 * the first adj in the list
2050 if (!s->adj_index) {
2051 this_one = MPLS_BOOL_TRUE;
2054 mpls_lock_get(g->global_lock); /* LOCK */
2056 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
2057 adj = MPLS_LIST_HEAD(&session->adj_root);
2058 while (adj) {
2059 if (this_one == MPLS_BOOL_TRUE) {
2060 adj_next = adj;
2061 break;
2064 /* since the entities are sort in the list ... */
2065 if (adj->index > s->adj_index) {
2066 break;
2067 } else if (adj->index == s->adj_index) {
2068 this_one = MPLS_BOOL_TRUE;
2070 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
2073 mpls_lock_release(g->global_lock); /* UNLOCK */
2075 if (adj_next) {
2076 s->adj_index = adj_next->index;
2077 r = MPLS_SUCCESS;
2080 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
2081 return r;
2084 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
2085 ldp_session * s, ldp_addr * a, uint32_t flag)
2087 ldp_global *global = (ldp_global *) handle;
2088 ldp_session *session = NULL;
2089 ldp_addr *addr = NULL;
2090 mpls_return_enum retval = MPLS_FAILURE;
2092 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
2094 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
2096 mpls_lock_get(global->global_lock); /* LOCK */
2098 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
2099 goto ldp_cfg_session_raddr_get_end;
2101 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
2102 goto ldp_cfg_session_raddr_get_end;
2104 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
2105 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
2107 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
2108 a->index = addr->index;
2110 retval = MPLS_SUCCESS;
2112 ldp_cfg_session_raddr_get_end:
2113 mpls_lock_release(global->global_lock); /* UNLOCK */
2115 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
2117 return retval;
2120 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
2121 ldp_session * s, ldp_addr * a, uint32_t flag)
2123 ldp_global *g = (ldp_global *) handle;
2124 ldp_addr *addr = NULL;
2125 mpls_return_enum r = MPLS_FAILURE;
2126 mpls_bool done = MPLS_BOOL_FALSE;
2127 ldp_session *sp = NULL;
2128 int index;
2130 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
2132 if (a->index == 0) {
2133 index = 1;
2134 } else {
2135 index = a->index + 1;
2138 r = ldp_global_find_session_index(g, s->index, &sp);
2139 if (r != MPLS_SUCCESS) {
2140 return r;
2143 mpls_lock_get(g->global_lock); /* LOCK */
2144 while (done == MPLS_BOOL_FALSE) {
2145 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
2146 case MPLS_SUCCESS:
2147 case MPLS_END_OF_LIST:
2148 done = MPLS_BOOL_TRUE;
2149 break;
2150 case MPLS_FAILURE:
2151 break;
2152 default:
2153 MPLS_ASSERT(0);
2155 index++;
2157 mpls_lock_release(g->global_lock); /* UNLOCK */
2159 if (r == MPLS_SUCCESS) {
2160 a->index = addr->index;
2161 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2164 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2165 return r;
2168 /******************* IN LABEL **********************/
2170 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2171 uint32_t flag)
2173 ldp_global *global = (ldp_global *) handle;
2174 ldp_inlabel *inlabel = NULL;
2175 mpls_return_enum retval = MPLS_FAILURE;
2177 MPLS_ASSERT(global !=NULL && i != NULL);
2179 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2181 mpls_lock_get(global->global_lock); /* LOCK */
2183 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2184 goto ldp_cfg_inlabel_get_end;
2186 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2187 i->info.labelspace = inlabel->info.labelspace;
2189 if (flag & LDP_INLABEL_CFG_LABEL) {
2190 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2192 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2193 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2196 retval = MPLS_SUCCESS;
2198 ldp_cfg_inlabel_get_end:
2199 mpls_lock_release(global->global_lock); /* UNLOCK */
2201 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2203 return retval;
2206 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2207 uint32_t flag)
2209 ldp_global *g = (ldp_global *) handle;
2210 ldp_inlabel *inlabel = NULL;
2211 mpls_return_enum r = MPLS_FAILURE;
2212 mpls_bool done = MPLS_BOOL_FALSE;
2213 int index;
2215 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2217 if (i->index == 0) {
2218 index = 1;
2219 } else {
2220 index = i->index + 1;
2223 mpls_lock_get(g->global_lock); /* LOCK */
2224 while (done == MPLS_BOOL_FALSE) {
2225 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2226 case MPLS_SUCCESS:
2227 case MPLS_END_OF_LIST:
2228 done = MPLS_BOOL_TRUE;
2229 break;
2230 case MPLS_FAILURE:
2231 break;
2232 default:
2233 MPLS_ASSERT(0);
2235 index++;
2237 mpls_lock_release(g->global_lock); /* UNLOCK */
2239 if (r == MPLS_SUCCESS) {
2240 i->index = inlabel->index;
2242 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2243 return ldp_cfg_inlabel_get(g, i, flag);
2246 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2248 return r;
2251 /******************* OUT LABEL **********************/
2253 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2254 uint32_t flag)
2256 ldp_global *global = (ldp_global *) handle;
2257 ldp_outlabel *outlabel = NULL;
2258 mpls_return_enum retval = MPLS_FAILURE;
2260 MPLS_ASSERT(global !=NULL && o != NULL);
2262 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2264 mpls_lock_get(global->global_lock); /* LOCK */
2266 if (ldp_global_find_outlabel_index(global, o->index,
2267 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2269 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2270 if (outlabel->nh) {
2271 o->nh_index = outlabel->nh->index;
2272 } else {
2273 o->nh_index = 0;
2276 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2277 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2279 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2280 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2282 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2283 o->merge_count = outlabel->merge_count;
2286 retval = MPLS_SUCCESS;
2288 ldp_cfg_outlabel_get_end:
2289 mpls_lock_release(global->global_lock); /* UNLOCK */
2291 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2293 return retval;
2296 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2297 ldp_outlabel * o, uint32_t flag)
2299 ldp_global *g = (ldp_global *) handle;
2300 ldp_outlabel *outlabel = NULL;
2301 mpls_return_enum r = MPLS_FAILURE;
2302 mpls_bool done = MPLS_BOOL_FALSE;
2303 int index;
2305 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2307 if (o->index == 0) {
2308 index = 1;
2309 } else {
2310 index = o->index + 1;
2313 mpls_lock_get(g->global_lock); /* LOCK */
2314 while (done == MPLS_BOOL_FALSE) {
2315 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2316 case MPLS_SUCCESS:
2317 case MPLS_END_OF_LIST:
2318 done = MPLS_BOOL_TRUE;
2319 break;
2320 case MPLS_FAILURE:
2321 break;
2322 default:
2323 MPLS_ASSERT(0);
2325 index++;
2327 mpls_lock_release(g->global_lock); /* UNLOCK */
2329 if (r == MPLS_SUCCESS) {
2330 o->index = outlabel->index;
2332 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2333 return ldp_cfg_outlabel_get(g, o, flag);
2336 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2338 return r;
2341 /******************* TUNNEL **********************/
2343 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2344 uint32_t flag)
2346 ldp_global *global = (ldp_global *) handle;
2347 mpls_return_enum retval = MPLS_FAILURE;
2348 ldp_tunnel *tunnel = NULL;
2350 MPLS_ASSERT(global !=NULL);
2352 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2354 mpls_lock_get(global->global_lock); /* LOCK */
2356 if (flag & LDP_CFG_ADD) {
2357 if (!(tunnel = ldp_tunnel_create())) {
2358 goto ldp_cfg_tunnel_set_end;
2360 _ldp_global_add_tunnel(global, tunnel);
2362 t->index = tunnel->index;
2363 } else {
2364 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2367 if (!tunnel) {
2368 LDP_PRINT(global->user_data,
2370 "ldp_cfg_tunnel_set:could not create tunnel\n");
2371 goto ldp_cfg_tunnel_set_end;
2374 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2375 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2376 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2378 goto ldp_cfg_tunnel_set_end;
2381 if (flag & LDP_CFG_DEL) {
2382 if (tunnel->outlabel)
2383 ldp_tunnel_del_outlabel(global, tunnel);
2384 if (tunnel->resource)
2385 ldp_tunnel_del_resource(tunnel);
2386 if (tunnel->hop_list)
2387 ldp_tunnel_del_hop_list(tunnel);
2388 _ldp_global_del_tunnel(global, tunnel);
2390 retval = MPLS_SUCCESS;
2391 goto ldp_cfg_tunnel_set_end;
2394 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2395 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2397 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2398 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2400 if (flag & LDP_TUNNEL_CFG_NAME) {
2401 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2403 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2404 tunnel->is_interface = t->is_interface;
2406 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2407 ldp_outlabel *outlabel = NULL;
2409 if (t->outlabel_index) {
2410 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2412 if (!outlabel) {
2413 goto ldp_cfg_tunnel_set_end;
2415 ldp_tunnel_add_outlabel(tunnel, outlabel);
2416 } else {
2417 ldp_tunnel_del_outlabel(global, tunnel);
2420 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2421 tunnel->setup_prio = t->setup_prio;
2423 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2424 tunnel->hold_prio = t->hold_prio;
2426 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2427 tunnel->instance_prio = t->instance_prio;
2429 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2430 tunnel->local_protect = t->local_protect;
2432 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2433 ldp_resource *resource = NULL;
2435 if (t->resource_index) {
2436 ldp_global_find_resource_index(global, t->resource_index, &resource);
2438 if (!resource) {
2439 goto ldp_cfg_tunnel_set_end;
2441 ldp_tunnel_add_resource(tunnel, resource);
2442 } else {
2443 ldp_tunnel_del_resource(tunnel);
2446 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2447 ldp_hop_list *hop_list = NULL;
2449 if (t->hop_list_index) {
2450 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2452 if (!hop_list) {
2453 goto ldp_cfg_tunnel_set_end;
2455 ldp_tunnel_add_hop_list(tunnel, hop_list);
2456 } else {
2457 ldp_tunnel_del_hop_list(tunnel);
2460 if (flag & LDP_TUNNEL_CFG_FEC) {
2461 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2463 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2464 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2465 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2466 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2467 goto ldp_cfg_tunnel_set_end;
2470 } else {
2471 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2472 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2473 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2474 goto ldp_cfg_tunnel_set_end;
2476 } else {
2477 LDP_PRINT(global->user_data,
2479 "ldp_cfg_tunnel_set: tunnel not ready\n");
2480 goto ldp_cfg_tunnel_set_end;
2485 retval = MPLS_SUCCESS;
2487 ldp_cfg_tunnel_set_end:
2489 mpls_lock_release(global->global_lock); /* UNLOCK */
2491 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2493 return retval;
2496 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2497 uint32_t flag)
2499 ldp_global *global = (ldp_global *) handle;
2500 mpls_return_enum retval = MPLS_FAILURE;
2501 ldp_tunnel *tunnel = NULL;
2503 MPLS_ASSERT(global !=NULL);
2505 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2507 mpls_lock_get(global->global_lock); /* LOCK */
2509 if (flag & LDP_CFG_ADD) {
2510 retval = MPLS_SUCCESS;
2511 goto ldp_cfg_tunnel_test_end;
2514 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2516 if (!tunnel) {
2517 goto ldp_cfg_tunnel_test_end;
2520 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2521 ldp_resource *resource = NULL;
2523 if (t->resource_index) {
2524 ldp_global_find_resource_index(global, t->resource_index, &resource);
2526 if (!resource) {
2527 goto ldp_cfg_tunnel_test_end;
2531 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2532 ldp_hop_list *hop_list = NULL;
2534 if (t->hop_list_index) {
2535 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2537 if (!hop_list) {
2538 goto ldp_cfg_tunnel_test_end;
2542 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2543 ldp_outlabel *outlabel = NULL;
2545 if (t->outlabel_index) {
2546 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2548 if (!outlabel) {
2549 goto ldp_cfg_tunnel_test_end;
2553 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2554 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2555 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2556 goto ldp_cfg_tunnel_test_end;
2558 retval = MPLS_SUCCESS;
2560 ldp_cfg_tunnel_test_end:
2562 mpls_lock_release(global->global_lock); /* UNLOCK */
2564 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2566 return retval;
2569 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2570 uint32_t flag)
2572 ldp_global *global = (ldp_global *) handle;
2573 mpls_return_enum retval = MPLS_FAILURE;
2574 ldp_tunnel *tunnel = NULL;
2576 MPLS_ASSERT(global !=NULL);
2578 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2580 mpls_lock_get(global->global_lock); /* LOCK */
2582 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2584 if (!tunnel) {
2585 goto ldp_cfg_tunnel_get_end;
2587 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2588 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2590 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2591 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2593 if (flag & LDP_TUNNEL_CFG_NAME) {
2594 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2596 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2597 t->is_interface = tunnel->is_interface;
2599 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2600 if (tunnel->outlabel) {
2601 t->outlabel_index = tunnel->outlabel->index;
2602 } else {
2603 t->outlabel_index = 0;
2606 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2607 t->setup_prio = tunnel->setup_prio;
2609 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2610 t->hold_prio = tunnel->hold_prio;
2612 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2613 tunnel->instance_prio = t->instance_prio;
2615 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2616 tunnel->local_protect = t->local_protect;
2618 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2619 if (tunnel->resource) {
2620 t->resource_index = tunnel->resource->index;
2621 } else {
2622 t->resource_index = 0;
2625 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2626 if (tunnel->hop_list) {
2627 t->hop_list_index = tunnel->hop_list->index;
2628 } else {
2629 t->hop_list_index = 0;
2632 if (flag & LDP_TUNNEL_CFG_FEC) {
2633 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2635 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2636 t->admin_state = tunnel->admin_state;
2638 retval = MPLS_SUCCESS;
2640 ldp_cfg_tunnel_get_end:
2642 mpls_lock_release(global->global_lock); /* UNLOCK */
2644 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2646 return retval;
2649 mpls_return_enum ldp_cfg_tunnel_getnext(mpls_cfg_handle handle,
2650 ldp_tunnel * r, uint32_t flag)
2652 ldp_global *g = (ldp_global *) handle;
2653 ldp_tunnel *tunnel = NULL;
2654 mpls_return_enum ret = MPLS_FAILURE;
2655 mpls_bool done = MPLS_BOOL_FALSE;
2656 int index;
2658 LDP_ENTER(g->user_data, "ldp_cfg_tunnel_getnext");
2660 if (r->index == 0) {
2661 index = 1;
2662 } else {
2663 index = r->index + 1;
2666 mpls_lock_get(g->global_lock); /* LOCK */
2667 while (done == MPLS_BOOL_FALSE) {
2668 switch ((ret = ldp_global_find_tunnel_index(g, index, &tunnel))) {
2669 case MPLS_SUCCESS:
2670 case MPLS_END_OF_LIST:
2671 done = MPLS_BOOL_TRUE;
2672 break;
2673 case MPLS_FAILURE:
2674 break;
2675 default:
2676 MPLS_ASSERT(0);
2678 index++;
2680 mpls_lock_release(g->global_lock); /* UNLOCK */
2682 if (ret == MPLS_SUCCESS) {
2683 r->index = tunnel->index;
2685 LDP_EXIT(g->user_data, "ldp_cfg_tunnel_getnext");
2686 return ldp_cfg_tunnel_get(g, r, flag);
2689 LDP_EXIT(g->user_data, "ldp_cfg_tunnel_getnext");
2691 return ret;
2694 /******************* RESOURCE **********************/
2696 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2697 uint32_t flag)
2699 ldp_global *global = (ldp_global *) handle;
2700 mpls_return_enum retval = MPLS_FAILURE;
2701 ldp_resource *resource = NULL;
2703 MPLS_ASSERT(global !=NULL);
2705 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2707 mpls_lock_get(global->global_lock); /* LOCK */
2709 if (flag & LDP_CFG_ADD) {
2710 resource = ldp_resource_create();
2711 _ldp_global_add_resource(global, resource);
2713 r->index = resource->index;
2714 } else {
2715 ldp_global_find_resource_index(global, r->index, &resource);
2718 if (!resource) {
2719 goto ldp_cfg_resource_set_end;
2722 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2723 resource->max_rate = r->max_rate;
2725 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2726 resource->mean_rate = r->mean_rate;
2728 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2729 resource->burst_size = r->burst_size;
2731 retval = MPLS_SUCCESS;
2733 ldp_cfg_resource_set_end:
2735 mpls_lock_release(global->global_lock); /* UNLOCK */
2737 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2739 return retval;
2742 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2743 uint32_t flag)
2745 ldp_global *global = (ldp_global *) handle;
2746 mpls_return_enum retval = MPLS_FAILURE;
2747 ldp_resource *resource = NULL;
2749 MPLS_ASSERT(global !=NULL);
2751 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2753 mpls_lock_get(global->global_lock); /* LOCK */
2755 if (flag & LDP_CFG_ADD) {
2756 retval = MPLS_SUCCESS;
2757 goto ldp_cfg_resource_test_end;
2760 ldp_global_find_resource_index(global, r->index, &resource);
2762 if (!resource) {
2763 goto ldp_cfg_resource_test_end;
2766 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2767 goto ldp_cfg_resource_test_end;
2769 retval = MPLS_SUCCESS;
2771 ldp_cfg_resource_test_end:
2773 mpls_lock_release(global->global_lock); /* UNLOCK */
2775 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2777 return retval;
2780 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2781 uint32_t flag)
2783 ldp_global *global = (ldp_global *) handle;
2784 mpls_return_enum retval = MPLS_FAILURE;
2785 ldp_resource *resource = NULL;
2787 MPLS_ASSERT(global !=NULL);
2789 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2791 mpls_lock_get(global->global_lock); /* LOCK */
2793 ldp_global_find_resource_index(global, r->index, &resource);
2795 if (!resource) {
2796 goto ldp_cfg_resource_get_end;
2799 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2800 r->max_rate = resource->max_rate;
2802 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2803 r->mean_rate = resource->mean_rate;
2805 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2806 r->burst_size = resource->burst_size;
2808 retval = MPLS_SUCCESS;
2810 ldp_cfg_resource_get_end:
2812 mpls_lock_release(global->global_lock); /* UNLOCK */
2814 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2816 return retval;
2819 mpls_return_enum ldp_cfg_resource_getnext(mpls_cfg_handle handle,
2820 ldp_resource * r, uint32_t flag)
2822 ldp_global *g = (ldp_global *) handle;
2823 ldp_resource *resource = NULL;
2824 mpls_return_enum ret = MPLS_FAILURE;
2825 mpls_bool done = MPLS_BOOL_FALSE;
2826 int index;
2828 LDP_ENTER(g->user_data, "ldp_cfg_resource_getnext");
2830 if (r->index == 0) {
2831 index = 1;
2832 } else {
2833 index = r->index + 1;
2836 mpls_lock_get(g->global_lock); /* LOCK */
2837 while (done == MPLS_BOOL_FALSE) {
2838 switch ((ret = ldp_global_find_resource_index(g, index, &resource))) {
2839 case MPLS_SUCCESS:
2840 case MPLS_END_OF_LIST:
2841 done = MPLS_BOOL_TRUE;
2842 break;
2843 case MPLS_FAILURE:
2844 break;
2845 default:
2846 MPLS_ASSERT(0);
2848 index++;
2850 mpls_lock_release(g->global_lock); /* UNLOCK */
2852 if (ret == MPLS_SUCCESS) {
2853 r->index = resource->index;
2855 LDP_EXIT(g->user_data, "ldp_cfg_resource_getnext");
2856 return ldp_cfg_resource_get(g, r, flag);
2859 LDP_EXIT(g->user_data, "ldp_cfg_resource_getnext");
2861 return ret;
2864 /******************* HOP **********************/
2866 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2867 uint32_t flag)
2869 ldp_global *global = (ldp_global *) handle;
2870 mpls_return_enum retval = MPLS_FAILURE;
2871 ldp_hop_list *hop_list = NULL;
2872 ldp_hop *hop = NULL;
2874 MPLS_ASSERT(global !=NULL);
2876 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2878 if (!h->hop_list_index && !h->index) {
2879 return retval;
2882 mpls_lock_get(global->global_lock); /* LOCK */
2884 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2886 if (!hop_list) {
2887 if (flag & LDP_CFG_ADD) {
2888 if (!(hop_list = ldp_hop_list_create())) {
2889 goto ldp_cfg_hop_set_end;
2891 _ldp_global_add_hop_list(global, hop_list);
2893 h->hop_list_index = hop_list->index;
2894 } else {
2895 goto ldp_cfg_hop_set_end;
2899 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2900 if (!hop) {
2901 if (h->index && (flag & LDP_CFG_ADD)) {
2902 if (!(hop = ldp_hop_create())) {
2903 goto ldp_cfg_hop_set_end;
2905 hop->index = h->index;
2906 ldp_hop_list_add_hop(hop_list, hop);
2907 } else {
2908 goto ldp_cfg_hop_set_end;
2912 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2913 hop->path_option = h->path_option;
2915 if (flag & LDP_HOP_CFG_ADDR) {
2916 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2918 if (flag & LDP_HOP_CFG_TYPE) {
2919 hop->type = h->type;
2921 retval = MPLS_SUCCESS;
2923 ldp_cfg_hop_set_end:
2925 mpls_lock_release(global->global_lock); /* UNLOCK */
2927 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2929 return retval;
2932 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2933 uint32_t flag)
2935 ldp_global *global = (ldp_global *) handle;
2936 mpls_return_enum retval = MPLS_FAILURE;
2937 ldp_hop_list *hop_list = NULL;
2938 ldp_hop *hop = NULL;
2940 MPLS_ASSERT(global !=NULL);
2942 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2944 mpls_lock_get(global->global_lock); /* LOCK */
2946 if (flag & LDP_CFG_ADD) {
2947 retval = MPLS_SUCCESS;
2948 goto ldp_cfg_hop_test_end;
2951 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2953 if (!hop_list) {
2954 goto ldp_cfg_hop_test_end;
2957 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2958 if (!hop) {
2959 goto ldp_cfg_hop_test_end;
2962 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2963 goto ldp_cfg_hop_test_end;
2965 retval = MPLS_SUCCESS;
2967 ldp_cfg_hop_test_end:
2969 mpls_lock_release(global->global_lock); /* UNLOCK */
2971 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2973 return retval;
2976 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2977 uint32_t flag)
2979 ldp_global *global = (ldp_global *) handle;
2980 mpls_return_enum retval = MPLS_FAILURE;
2981 ldp_hop_list *hop_list = NULL;
2982 ldp_hop *hop = NULL;
2984 MPLS_ASSERT(global !=NULL);
2986 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2988 mpls_lock_get(global->global_lock); /* LOCK */
2990 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2992 if (!hop_list) {
2993 goto ldp_cfg_hop_get_end;
2996 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2997 if (!hop) {
2998 goto ldp_cfg_hop_get_end;
3001 if (flag & LDP_HOP_CFG_PATH_OPTION) {
3002 h->path_option = hop->path_option;
3004 if (flag & LDP_HOP_CFG_ADDR) {
3005 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
3007 if (flag & LDP_HOP_CFG_TYPE) {
3008 h->type = hop->type;
3010 retval = MPLS_SUCCESS;
3012 ldp_cfg_hop_get_end:
3014 mpls_lock_release(global->global_lock); /* UNLOCK */
3016 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
3018 return retval;