LDP now reacts to FEC adds and deletes
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blob57bd2fca7f2e7a8113853ef6d2007841625fc574
2 /*
3 * Copyright (C) James R. Leu 2000
4 * jleu@mindspring.com
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
8 */
10 #include "ldp_struct.h"
11 #include "ldp_cfg.h"
12 #include "ldp_global.h"
13 #include "ldp_entity.h"
14 #include "ldp_attr.h"
15 #include "ldp_if.h"
16 #include "ldp_peer.h"
17 #include "ldp_fec.h"
18 #include "ldp_addr.h"
19 #include "ldp_nexthop.h"
20 #include "ldp_tunnel.h"
21 #include "ldp_resource.h"
22 #include "mpls_ifmgr_impl.h"
23 #include "ldp_label_mapping.h"
24 #include "ldp_hop.h"
25 #include "ldp_hop_list.h"
26 #include "mpls_lock_impl.h"
27 #include "mpls_trace_impl.h"
28 #include "mpls_tree_impl.h"
30 mpls_cfg_handle ldp_cfg_open(mpls_instance_handle data)
32 ldp_global *g = ldp_global_create(data);
34 LDP_ENTER(data, "ldp_cfg_open");
35 LDP_EXIT(data, "ldp_cfg_open");
37 return (mpls_cfg_handle) g;
40 void ldp_cfg_close(mpls_cfg_handle g)
42 LDP_ENTER((mpls_instance_handle) g->user_data, "ldp_cfg_close");
43 ldp_global_delete(g);
44 LDP_EXIT((mpls_instance_handle) g->user_data, "ldp_cfg_close");
47 /******************* GLOBAL **********************/
49 mpls_return_enum ldp_cfg_global_get(mpls_cfg_handle handle, ldp_global * g,
50 uint32_t flag)
52 ldp_global *global = (ldp_global *) handle;
54 MPLS_ASSERT(global !=NULL);
56 LDP_ENTER(global->user_data, "ldp_cfg_global_get");
58 mpls_lock_get(global->global_lock); /* LOCK */
60 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
61 memcpy(&(g->lsr_identifier), &(global->lsr_identifier),
62 sizeof(mpls_inet_addr));
64 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
65 g->admin_state = global->admin_state;
67 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
68 g->lsp_control_mode = global->lsp_control_mode;
70 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
71 g->label_retention_mode = global->label_retention_mode;
73 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
74 g->lsp_repair_mode = global->lsp_repair_mode;
76 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
77 g->propagate_release = global->propagate_release;
79 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
80 g->label_merge = global->label_merge;
82 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
83 g->loop_detection_mode = global->loop_detection_mode;
85 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
86 g->ttl_less_domain = global->ttl_less_domain;
88 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
89 g->local_tcp_port = global->local_tcp_port;
91 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
92 g->local_udp_port = global->local_udp_port;
94 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
95 memcpy(&(g->transport_address), &(global->transport_address),
96 sizeof(mpls_inet_addr));
98 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
99 g->keepalive_timer = global->keepalive_timer;
101 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
102 g->keepalive_interval = global->keepalive_interval;
104 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
105 g->hellotime_timer = global->hellotime_timer;
107 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
108 g->hellotime_interval = global->hellotime_interval;
110 #if MPLS_USE_LSR
111 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
112 g->lsr_handle = global->lsr_handle;
114 #endif
116 mpls_lock_release(global->global_lock); /* UNLOCK */
118 LDP_EXIT(global->user_data, "ldp_cfg_global_get");
120 return MPLS_SUCCESS;
123 mpls_return_enum ldp_cfg_global_test(mpls_cfg_handle handle, ldp_global * g,
124 uint32_t flag)
126 ldp_global *global = (ldp_global *) handle;
127 mpls_return_enum retval = MPLS_SUCCESS;
129 MPLS_ASSERT(global !=NULL);
131 LDP_ENTER(global->user_data, "ldp_cfg_global_test");
133 mpls_lock_get(global->global_lock); /* LOCK */
135 if (global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN))
136 retval = MPLS_FAILURE;
138 mpls_lock_release(global->global_lock); /* UNLOCK */
140 LDP_EXIT(global->user_data, "ldp_cfg_global_test");
142 return retval;
145 mpls_return_enum ldp_cfg_global_set(mpls_cfg_handle handle, ldp_global * g,
146 uint32_t flag)
148 ldp_global *global = (ldp_global *) handle;
149 mpls_return_enum retval = MPLS_FAILURE;
151 MPLS_ASSERT(global !=NULL);
153 LDP_ENTER(global->user_data, "ldp_cfg_global_set");
155 mpls_lock_get(global->global_lock); /* LOCK */
157 if ((global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN)))
158 goto ldp_cfg_global_set_end;
160 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
161 global->lsp_control_mode = g->lsp_control_mode;
163 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
164 global->label_retention_mode = g->label_retention_mode;
166 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
167 global->lsp_repair_mode = g->lsp_repair_mode;
169 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
170 global->propagate_release = g->propagate_release;
172 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
173 global->label_merge = g->label_merge;
175 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
176 global->loop_detection_mode = g->loop_detection_mode;
178 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
179 global->ttl_less_domain = g->ttl_less_domain;
181 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
182 global->local_tcp_port = g->local_tcp_port;
184 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
185 global->local_udp_port = g->local_udp_port;
187 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
188 memcpy(&(global->lsr_identifier), &(g->lsr_identifier),
189 sizeof(mpls_inet_addr));
191 #if MPLS_USE_LSR
192 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
193 global->lsr_handle = g->lsr_handle;
195 #endif
196 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
197 if (global->admin_state == MPLS_ADMIN_ENABLE && g->admin_state == MPLS_ADMIN_DISABLE) {
198 ldp_global_shutdown(global);
199 } else if (global->admin_state == MPLS_ADMIN_DISABLE && g->admin_state ==
200 MPLS_ADMIN_ENABLE) {
201 ldp_global_startup(global);
204 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
205 memcpy(&(global->transport_address), &(g->transport_address),
206 sizeof(mpls_inet_addr));
208 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
209 if (g->keepalive_timer == 0) {
210 global->keepalive_timer = LDP_ENTITY_DEF_KEEPALIVE_TIMER;
211 } else {
212 global->keepalive_timer = g->keepalive_timer;
215 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
216 if (g->keepalive_interval == 0) {
217 global->keepalive_interval = LDP_ENTITY_DEF_KEEPALIVE_INTERVAL;
218 } else {
219 global->keepalive_interval = g->keepalive_interval;
222 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
223 if (g->hellotime_timer == 0) {
224 global->hellotime_timer = LDP_ENTITY_DEF_HELLOTIME_TIMER;
225 } else {
226 global->hellotime_timer = g->hellotime_timer;
229 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
230 if (g->hellotime_interval == 0) {
231 global->hellotime_interval = LDP_ENTITY_DEF_HELLOTIME_INTERVAL;
232 } else {
233 global->hellotime_interval = g->hellotime_interval;
236 #if MPLS_USE_LSR
237 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
238 global->lsr_handle = g->lsr_handle ;
240 #endif
241 global->configuration_sequence_number++;
243 retval = MPLS_SUCCESS;
245 ldp_cfg_global_set_end:
247 mpls_lock_release(global->global_lock); /* UNLOCK */
249 LDP_EXIT(global->user_data, "ldp_cfg_global_set");
251 return retval;
254 /******************* ENTITY **********************/
256 /* must set ldp_entity->index */
257 mpls_return_enum ldp_cfg_entity_get(mpls_cfg_handle handle, ldp_entity * e,
258 uint32_t flag)
260 ldp_global *global = (ldp_global *) handle;
261 ldp_entity *entity = NULL;
262 mpls_return_enum retval = MPLS_FAILURE;
264 MPLS_ASSERT(global !=NULL && e != NULL);
266 LDP_ENTER(global->user_data, "ldp_cfg_entity_get");
268 mpls_lock_get(global->global_lock); /* LOCK */
270 if (ldp_global_find_entity_index(global, e->index, &entity) != MPLS_SUCCESS)
271 goto ldp_cfg_entity_get_end;
273 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
274 e->admin_state = entity->admin_state;
276 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
277 e->transport_address = entity->transport_address;
279 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
280 e->protocol_version = entity->protocol_version;
282 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
283 e->remote_tcp_port = entity->remote_tcp_port;
285 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
286 e->remote_udp_port = entity->remote_udp_port;
288 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
289 e->max_pdu = entity->max_pdu;
291 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
292 e->keepalive_timer = entity->keepalive_timer;
294 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
295 e->keepalive_interval = entity->keepalive_interval;
297 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
298 e->hellotime_timer = entity->hellotime_timer;
300 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
301 e->hellotime_interval = entity->hellotime_interval;
303 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
304 e->session_setup_count = entity->session_setup_count;
306 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
307 e->session_backoff_timer = entity->session_backoff_timer;
309 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
310 e->label_distribution_mode = entity->label_distribution_mode;
312 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
313 e->path_vector_limit = entity->path_vector_limit;
315 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
316 e->hop_count_limit = entity->hop_count_limit;
318 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
319 e->label_request_count = entity->label_request_count;
321 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
322 e->label_request_timer = entity->label_request_timer;
324 if (flag & LDP_ENTITY_CFG_TYPE) {
325 e->entity_type = entity->entity_type;
327 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
328 e->sub_index = entity->sub_index;
330 if (flag & LDP_ENTITY_CFG_MESG_TX) {
331 e->mesg_tx = entity->mesg_tx;
333 if (flag & LDP_ENTITY_CFG_MESG_RX) {
334 e->mesg_rx = entity->mesg_rx;
336 if (flag & LDP_ENTITY_CFG_ADJ_COUNT) {
337 e->adj_count = e->adj_root.count;
339 if (flag & LDP_ENTITY_CFG_ADJ_INDEX) {
340 ldp_adj *a = MPLS_LIST_HEAD(&e->adj_root);
341 e->adj_index = a ? a->index : 0;
343 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
344 e->inherit_flag = entity->inherit_flag;
346 retval = MPLS_SUCCESS;
348 ldp_cfg_entity_get_end:
350 mpls_lock_release(global->global_lock); /* UNLOCK */
352 LDP_EXIT(global->user_data, "ldp_cfg_entity_get");
354 return retval;
357 mpls_return_enum ldp_cfg_entity_getnext(mpls_cfg_handle handle, ldp_entity * e,
358 uint32_t flag)
360 ldp_global *g = (ldp_global *) handle;
361 ldp_entity *entity = NULL;
362 mpls_return_enum r = MPLS_FAILURE;
363 mpls_bool done = MPLS_BOOL_FALSE;
364 int index;
366 LDP_ENTER(g->user_data, "ldp_cfg_entity_getnext");
368 if (e->index == 0) {
369 index = 1;
370 } else {
371 index = e->index + 1;
374 mpls_lock_get(g->global_lock); /* LOCK */
375 while (done == MPLS_BOOL_FALSE) {
376 switch ((r = ldp_global_find_entity_index(g, index, &entity))) {
377 case MPLS_SUCCESS:
378 case MPLS_END_OF_LIST:
379 done = MPLS_BOOL_TRUE;
380 break;
381 case MPLS_FAILURE:
382 break;
383 default:
384 MPLS_ASSERT(0);
386 index++;
388 mpls_lock_release(g->global_lock); /* UNLOCK */
390 if (r == MPLS_SUCCESS) {
391 e->index = entity->index;
392 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
393 return ldp_cfg_entity_get(g, e, flag);
395 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
396 return r;
399 mpls_return_enum ldp_cfg_entity_test(mpls_cfg_handle handle, ldp_entity * e,
400 uint32_t flag)
402 ldp_global *global = (ldp_global *) handle;
403 ldp_entity *entity = NULL;
404 mpls_return_enum retval = MPLS_FAILURE;
406 MPLS_ASSERT(global !=NULL);
408 LDP_ENTER(global->user_data, "ldp_cfg_entity_test");
410 mpls_lock_get(global->global_lock); /* LOCK */
412 if (!(flag & LDP_CFG_ADD)) {
413 if (e == NULL)
414 goto ldp_cfg_entity_test_end;
416 ldp_global_find_entity_index(global, e->index, &entity);
417 } else {
418 retval = MPLS_SUCCESS;
419 goto ldp_cfg_entity_test_end;
422 if (entity == NULL) {
423 goto ldp_cfg_entity_test_end;
426 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
427 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
428 goto ldp_cfg_entity_test_end;
431 retval = MPLS_SUCCESS;
433 ldp_cfg_entity_test_end:
434 mpls_lock_release(global->global_lock); /* UNLOCK */
436 LDP_EXIT(global->user_data, "ldp_cfg_entity_test");
438 return retval;
441 /* must set ldp_entity->index if not an add */
442 mpls_return_enum ldp_cfg_entity_set(mpls_cfg_handle handle, ldp_entity * e,
443 uint32_t flag)
445 ldp_global *global = (ldp_global *) handle;
446 ldp_entity *entity = NULL;
447 mpls_return_enum retval = MPLS_FAILURE;
449 MPLS_ASSERT(global !=NULL && e != NULL);
451 LDP_ENTER(global->user_data, "ldp_cfg_entity_set");
453 mpls_lock_get(global->global_lock); /* LOCK */
455 if (flag & LDP_CFG_ADD) {
456 entity = ldp_entity_create();
457 _ldp_global_add_entity(global, entity);
459 e->index = entity->index;
460 } else {
461 ldp_global_find_entity_index(global, e->index, &entity);
464 if (entity == NULL) {
465 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: can't find entity\n");
466 goto ldp_cfg_entity_set_end;
469 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
470 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
471 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity is active\n");
472 goto ldp_cfg_entity_set_end;
475 if (flag & LDP_CFG_DEL) {
476 switch (entity->entity_type) {
477 case LDP_DIRECT:
478 ldp_entity_del_if(global, entity);
479 break;
480 case LDP_INDIRECT:
481 ldp_entity_del_peer(entity);
482 break;
483 default:
484 MPLS_ASSERT(0);
486 _ldp_global_del_entity(global, entity);
488 retval = MPLS_SUCCESS;
489 goto ldp_cfg_entity_set_end;
492 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
493 if (entity->sub_index != 0) {
494 /* unlink the old sub object */
495 switch (entity->entity_type) {
496 case LDP_DIRECT:
497 ldp_entity_del_if(global, entity);
498 break;
499 case LDP_INDIRECT:
500 ldp_entity_del_peer(entity);
501 break;
502 default:
503 MPLS_ASSERT(0);
507 /* link the new sub object */
508 switch (e->entity_type) {
509 case LDP_DIRECT:
511 ldp_if *iff = NULL;
512 if (ldp_global_find_if_index(global, e->sub_index,
513 &iff) != MPLS_SUCCESS) {
514 LDP_PRINT(global->user_data,
515 "ldp_cfg_entity_set: no such interface\n");
517 if (flag & LDP_CFG_ADD) {
518 _ldp_global_del_entity(global, entity);
520 goto ldp_cfg_entity_set_end;
522 ldp_entity_add_if(entity, iff);
523 break;
525 case LDP_INDIRECT:
527 ldp_peer *peer = NULL;
529 if (ldp_global_find_peer_index(global, e->sub_index, &peer) !=
530 MPLS_SUCCESS) {
531 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: no such peer\n");
533 if (flag & LDP_CFG_ADD) {
534 _ldp_global_del_entity(global, entity);
536 goto ldp_cfg_entity_set_end;
538 ldp_entity_add_peer(entity, peer);
539 break;
541 default:
542 MPLS_ASSERT(0);
546 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
547 if (e->transport_address.type == MPLS_FAMILY_NONE) {
548 entity->inherit_flag |= LDP_ENTITY_CFG_TRANS_ADDR;
549 } else {
550 entity->inherit_flag &= ~LDP_ENTITY_CFG_TRANS_ADDR;
552 memcpy(&entity->transport_address, &e->transport_address,
553 sizeof(mpls_inet_addr));;
555 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
556 entity->protocol_version = e->protocol_version;
558 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
559 entity->remote_tcp_port = e->remote_tcp_port;
561 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
562 entity->remote_udp_port = e->remote_udp_port;
564 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
565 entity->max_pdu = e->max_pdu;
567 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
568 if (e->transport_address.type == MPLS_FAMILY_NONE) {
569 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_TIMER;
570 } else {
571 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER;
573 entity->keepalive_timer = e->keepalive_timer;
575 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
576 if (e->transport_address.type == MPLS_FAMILY_NONE) {
577 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
578 } else {
579 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
581 entity->keepalive_interval = e->keepalive_interval;
583 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
584 if (e->transport_address.type == MPLS_FAMILY_NONE) {
585 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_TIMER;
586 } else {
587 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_TIMER;
589 entity->hellotime_timer = e->hellotime_timer;
591 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
592 if (e->transport_address.type == MPLS_FAMILY_NONE) {
593 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
594 } else {
595 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
597 entity->hellotime_interval = e->hellotime_interval;
599 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
600 entity->session_setup_count = e->session_setup_count;
602 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
603 entity->session_backoff_timer = e->session_backoff_timer;
605 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
606 entity->label_distribution_mode = e->label_distribution_mode;
608 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
609 entity->path_vector_limit = e->path_vector_limit;
611 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
612 entity->hop_count_limit = e->hop_count_limit;
614 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
615 entity->label_request_count = e->label_request_count;
617 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
618 entity->label_request_timer = e->label_request_timer;
620 if (flag & LDP_ENTITY_CFG_TYPE) {
621 entity->entity_type = e->entity_type;
623 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
624 if (ldp_entity_is_active(entity) == MPLS_BOOL_TRUE &&
625 e->admin_state == MPLS_ADMIN_DISABLE) {
626 if (ldp_entity_shutdown(global, entity, 0) == MPLS_FAILURE) {
627 goto ldp_cfg_entity_set_end;
629 } else if (ldp_entity_is_active(entity) == MPLS_BOOL_FALSE &&
630 e->admin_state == MPLS_ADMIN_ENABLE && ldp_entity_is_ready(entity) == MPLS_BOOL_TRUE) {
631 if (ldp_entity_startup(global, entity) == MPLS_FAILURE) {
632 goto ldp_cfg_entity_set_end;
634 } else {
635 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity not ready\n");
637 goto ldp_cfg_entity_set_end;
640 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
641 entity->inherit_flag = e->inherit_flag;
643 global->configuration_sequence_number++;
645 retval = MPLS_SUCCESS;
647 ldp_cfg_entity_set_end:
648 mpls_lock_release(global->global_lock); /* UNLOCK */
650 LDP_EXIT(global->user_data, "ldp_cfg_entity_set");
652 return retval;
655 mpls_return_enum ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle,
656 ldp_entity * e)
658 ldp_global *g = (ldp_global *) handle;
659 mpls_bool this_one = MPLS_BOOL_FALSE;
660 mpls_return_enum r = MPLS_FAILURE;
661 ldp_adj *adj_next = NULL;
662 ldp_adj *adj = NULL;
663 ldp_entity *entity = NULL;
665 LDP_ENTER(g->user_data, "ldp_cfg_entity_adj_getnext");
667 /* if an adj_index of zero is sent, get the index of
668 * the first adj in the list
670 if (!e->adj_index) {
671 this_one = MPLS_BOOL_TRUE;
674 mpls_lock_get(g->global_lock); /* LOCK */
676 if (ldp_global_find_entity_index(g, e->index, &entity) == MPLS_SUCCESS) {
677 adj = MPLS_LIST_HEAD(&entity->adj_root);
678 while (adj) {
679 if (this_one == MPLS_BOOL_TRUE) {
680 adj_next = adj;
681 break;
684 /* since the entities are sort in the list ... */
685 if (adj->index > e->adj_index) {
686 break;
687 } else if (adj->index == e->adj_index) {
688 this_one = MPLS_BOOL_TRUE;
690 adj = MPLS_LIST_NEXT(&entity->adj_root, adj, _entity);
693 mpls_lock_release(g->global_lock); /* UNLOCK */
695 if (adj_next) {
696 e->adj_index = adj_next->index;
697 r = MPLS_SUCCESS;
700 LDP_EXIT(g->user_data, "ldp_cfg_entity_adj_getnext");
701 return r;
704 /******************* INTERFACE **********************/
706 mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
708 ldp_global *global = (ldp_global *) handle;
709 ldp_if *iff = NULL;
710 mpls_return_enum retval = MPLS_FAILURE;
712 MPLS_ASSERT(global !=NULL && i != NULL);
714 LDP_ENTER(global->user_data, "ldp_cfg_if_get");
716 mpls_lock_get(global->global_lock); /* LOCK */
718 if (flag & LDP_IF_CFG_BY_INDEX) {
719 ldp_global_find_if_index(global, i->index, &iff);
720 } else {
721 iff = ldp_global_find_if_handle(global, i->handle);
723 if (!iff)
724 goto ldp_cfg_if_get_end;
726 if (flag & LDP_IF_CFG_LABEL_SPACE) {
727 i->label_space = iff->label_space;
729 if (flag & LDP_IF_CFG_ENTITY_INDEX) {
730 i->entity_index = iff->entity ? iff->entity->index : 0;
732 if (flag & LDP_IF_CFG_OPER_STATE) {
733 i->oper_state = iff->oper_state;
735 retval = MPLS_SUCCESS;
737 ldp_cfg_if_get_end:
738 mpls_lock_release(global->global_lock); /* UNLOCK */
740 LDP_EXIT(global->user_data, "ldp_cfg_if_get");
742 return retval;
745 mpls_return_enum ldp_cfg_if_getnext(mpls_cfg_handle handle, ldp_if * i,
746 uint32_t flag)
748 ldp_global *g = (ldp_global *) handle;
749 ldp_if *iff = NULL;
750 mpls_return_enum r = MPLS_FAILURE;
751 mpls_bool done = MPLS_BOOL_FALSE;
752 int index;
754 LDP_ENTER(g->user_data, "ldp_cfg_if_getnext");
756 if (i->index == 0) {
757 index = 1;
758 } else {
759 index = i->index + 1;
762 mpls_lock_get(g->global_lock); /* LOCK */
763 while (done == MPLS_BOOL_FALSE) {
764 switch ((r = ldp_global_find_if_index(g, index, &iff))) {
765 case MPLS_SUCCESS:
766 case MPLS_END_OF_LIST:
767 done = MPLS_BOOL_TRUE;
768 break;
769 case MPLS_FAILURE:
770 break;
771 default:
772 MPLS_ASSERT(0);
774 index++;
776 mpls_lock_release(g->global_lock); /* UNLOCK */
778 if (r == MPLS_SUCCESS) {
779 i->index = iff->index;
780 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
781 return ldp_cfg_if_get(g, i, flag);
783 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
784 return r;
787 mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i,
788 uint32_t flag)
790 ldp_global *global = (ldp_global *) handle;
791 ldp_if *iff = NULL;
792 mpls_return_enum retval = MPLS_FAILURE;
794 MPLS_ASSERT(global !=NULL && i != NULL);
796 LDP_ENTER(global->user_data, "ldp_cfg_if_test");
798 mpls_lock_get(global->global_lock); /* LOCK */
800 if (!(flag & LDP_CFG_ADD)) {
801 ldp_global_find_if_index(global, i->index, &iff);
802 } else {
803 retval = MPLS_SUCCESS;
804 goto ldp_cfg_if_test_end;
807 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
808 (flag & LDP_IF_CFG_WHEN_DOWN))) {
809 goto ldp_cfg_if_test_end;
812 if (flag & LDP_CFG_DEL) {
813 if (iff->entity != NULL) {
814 goto ldp_cfg_if_test_end;
817 retval = MPLS_SUCCESS;
819 ldp_cfg_if_test_end:
820 mpls_lock_release(global->global_lock); /* UNLOCK */
822 LDP_EXIT(global->user_data, "ldp_cfg_if_test");
824 return retval;
827 mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
829 ldp_global *global = (ldp_global*)handle;
830 ldp_if *iff = NULL;
831 ldp_addr *ap;
832 ldp_nexthop *np;
833 mpls_return_enum retval = MPLS_FAILURE;
835 MPLS_ASSERT(global !=NULL && i != NULL);
837 LDP_ENTER(global->user_data, "ldp_cfg_if_set");
839 mpls_lock_get(global->global_lock); /* LOCK */
841 if (flag & LDP_CFG_ADD) {
842 /* duplicate interface handles are not allowed */
843 /* ADDs require a valid interface handle */
844 if (((iff = ldp_global_find_if_handle(global, i->handle)) != NULL) ||
845 (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==
846 MPLS_BOOL_FALSE) || ((iff = ldp_if_create(global)) == NULL)) {
847 goto ldp_cfg_if_set_end;
850 /* copy the handle from the user */
851 iff->handle = i->handle;
853 /* search for addrs and nexthops that are waiting for this interface */
854 ap = MPLS_LIST_HEAD(&global->addr);
855 while (ap) {
856 if (ap->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(ap, _if))) {
857 ldp_if_add_addr(iff, ap);
859 ap = MPLS_LIST_NEXT(&global->addr, ap, _global);
862 np = MPLS_LIST_HEAD(&global->nexthop);
863 while (np) {
864 if ((np->info.type & MPLS_NH_IF) &&
865 (np->info.if_handle == iff->handle) && (!MPLS_LIST_IN_LIST(np, _if))) {
866 ldp_if_add_nexthop(iff, np);
868 np = MPLS_LIST_NEXT(&global->nexthop, np, _global);
871 /* send the newly created index back to the user */
872 i->index = iff->index;
874 } else {
875 if (flag & LDP_IF_CFG_BY_INDEX) {
876 ldp_global_find_if_index(global, i->index, &iff);
877 } else {
878 iff = ldp_global_find_if_handle(global, i->handle);
883 * if we can't find this interface or if the interface is active and
884 * we are trying to change propertises that can not be changed on a
885 * active interface
887 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
888 (flag & LDP_IF_CFG_WHEN_DOWN))) {
889 goto ldp_cfg_if_set_end;
892 if (flag & LDP_IF_CFG_LABEL_SPACE) {
893 iff->label_space = i->label_space;
896 if (flag & LDP_CFG_DEL) {
898 * if this interface is still attached to a entity that it is not ready
899 * to be removed
901 if (iff->entity != NULL) {
902 goto ldp_cfg_if_set_end;
905 np = MPLS_LIST_HEAD(&iff->nh_root);
906 while (np) {
907 ldp_if_del_nexthop(global, iff, np);
908 np = MPLS_LIST_NEXT(&iff->nh_root, np, _if);
911 ap = MPLS_LIST_HEAD(&iff->addr_root);
912 while (ap) {
913 ldp_if_del_addr(global, iff, ap);
914 ap = MPLS_LIST_NEXT(&iff->addr_root, ap, _if);
917 MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);
920 global->configuration_sequence_number++;
922 retval = MPLS_SUCCESS;
924 ldp_cfg_if_set_end:
925 mpls_lock_release(global->global_lock); /* UNLOCK */
927 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
929 return retval;
932 /******************* ATTR **********************/
934 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
935 uint32_t flag)
937 ldp_global *global = (ldp_global *) handle;
938 ldp_attr *attr = NULL;
939 mpls_return_enum retval = MPLS_FAILURE;
941 MPLS_ASSERT(global !=NULL && a != NULL);
943 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
945 mpls_lock_get(global->global_lock); /* LOCK */
947 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
948 goto ldp_cfg_attr_get_end;
950 if (flag & LDP_ATTR_CFG_STATE) {
951 a->state = attr->state;
953 if (flag & LDP_ATTR_CFG_FEC) {
954 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
956 if (flag & LDP_ATTR_CFG_LABEL) {
957 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
959 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
960 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
962 if (flag & LDP_ATTR_CFG_PATH) {
963 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
965 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
966 a->session_index = (attr->session) ? (attr->session->index) : 0;
968 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
969 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
971 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
972 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
974 if (flag & LDP_ATTR_CFG_INGRESS) {
975 a->ingress = attr->ingress;
977 retval = MPLS_SUCCESS;
979 ldp_cfg_attr_get_end:
980 mpls_lock_release(global->global_lock); /* UNLOCK */
982 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
984 return retval;
987 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
988 uint32_t flag)
990 ldp_global *g = (ldp_global *) handle;
991 ldp_attr *attr = NULL;
992 mpls_return_enum r = MPLS_FAILURE;
993 mpls_bool done = MPLS_BOOL_FALSE;
994 int index;
996 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
998 if (a->index == 0) {
999 index = 1;
1000 } else {
1001 index = a->index + 1;
1004 mpls_lock_get(g->global_lock); /* LOCK */
1005 while (done == MPLS_BOOL_FALSE) {
1006 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
1007 case MPLS_SUCCESS:
1008 case MPLS_END_OF_LIST:
1009 done = MPLS_BOOL_TRUE;
1010 break;
1011 case MPLS_FAILURE:
1012 break;
1013 default:
1014 MPLS_ASSERT(0);
1016 index++;
1018 mpls_lock_release(g->global_lock); /* UNLOCK */
1020 if (r == MPLS_SUCCESS) {
1021 a->index = attr->index;
1022 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1023 return ldp_cfg_attr_get(g, a, flag);
1025 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1026 return r;
1029 /******************* PEER **********************/
1031 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
1032 uint32_t flag)
1034 ldp_global *global = (ldp_global *) handle;
1035 ldp_peer *peer = NULL;
1036 mpls_return_enum retval = MPLS_FAILURE;
1038 MPLS_ASSERT(global !=NULL && p != NULL);
1040 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
1042 mpls_lock_get(global->global_lock); /* LOCK */
1044 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
1045 goto ldp_cfg_peer_get_end;
1047 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1048 p->label_space = peer->label_space;
1050 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1051 p->target_role = peer->target_role;
1053 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1054 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1056 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1057 p->entity_index = peer->entity->index;
1059 if (flag & LDP_PEER_CFG_OPER_STATE) {
1060 p->oper_state = peer->oper_state;
1062 if (flag & LDP_PEER_CFG_PEER_NAME) {
1063 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1065 retval = MPLS_SUCCESS;
1067 ldp_cfg_peer_get_end:
1068 mpls_lock_release(global->global_lock); /* UNLOCK */
1070 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1072 return retval;
1075 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1076 uint32_t flag)
1078 ldp_global *g = (ldp_global *) handle;
1079 ldp_peer *peer = NULL;
1080 mpls_return_enum r = MPLS_FAILURE;
1081 mpls_bool done = MPLS_BOOL_FALSE;
1082 int index;
1084 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1086 if (p->index == 0) {
1087 index = 1;
1088 } else {
1089 index = p->index + 1;
1092 mpls_lock_get(g->global_lock); /* LOCK */
1093 while (done == MPLS_BOOL_FALSE) {
1094 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1095 case MPLS_SUCCESS:
1096 case MPLS_END_OF_LIST:
1097 done = MPLS_BOOL_TRUE;
1098 break;
1099 case MPLS_FAILURE:
1100 break;
1101 default:
1102 MPLS_ASSERT(0);
1104 index++;
1106 mpls_lock_release(g->global_lock); /* UNLOCK */
1108 if (r == MPLS_SUCCESS) {
1109 p->index = peer->index;
1110 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1111 return ldp_cfg_peer_get(g, p, flag);
1113 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1114 return r;
1117 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1118 uint32_t flag)
1120 // ldp_global* g = (ldp_global*)handle;
1121 return MPLS_SUCCESS;
1124 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1125 uint32_t flag)
1127 ldp_global *global = (ldp_global *) handle;
1128 ldp_peer *peer = NULL;
1129 mpls_return_enum retval = MPLS_FAILURE;
1131 MPLS_ASSERT(global !=NULL && p != NULL);
1133 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1135 mpls_lock_get(global->global_lock); /* LOCK */
1137 if (flag & LDP_CFG_ADD) {
1138 if ((peer = ldp_peer_create()) == NULL) {
1139 goto ldp_cfg_peer_set_end;
1141 p->index = peer->index;
1142 _ldp_global_add_peer(global, peer);
1143 } else {
1144 ldp_global_find_peer_index(global, p->index, &peer);
1147 if (peer == NULL) {
1148 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1150 goto ldp_cfg_peer_set_end;
1152 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1153 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1155 goto ldp_cfg_peer_set_end;
1158 if (flag & LDP_CFG_DEL) {
1159 if (peer->entity != NULL) {
1160 LDP_PRINT(global->user_data,
1161 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1163 goto ldp_cfg_peer_set_end;
1166 _ldp_global_del_peer(global, peer);
1168 retval = MPLS_SUCCESS;
1169 goto ldp_cfg_peer_set_end;
1171 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1172 peer->label_space = p->label_space;
1174 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1175 peer->target_role = p->target_role;
1177 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1178 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1180 if (flag & LDP_PEER_CFG_PEER_NAME) {
1181 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1183 p->peer_name);
1184 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1186 global->configuration_sequence_number++;
1188 retval = MPLS_SUCCESS;
1190 ldp_cfg_peer_set_end:
1191 mpls_lock_release(global->global_lock); /* UNLOCK */
1193 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1195 return retval;
1197 /******************* FEC **********************/
1199 mpls_return_enum ldp_cfg_fec_get(mpls_cfg_handle handle, mpls_fec * f,
1200 uint32_t flag)
1202 ldp_global *global = (ldp_global *) handle;
1203 ldp_fec *fec = NULL;
1204 mpls_return_enum retval = MPLS_FAILURE;
1206 MPLS_ASSERT(global !=NULL && f != NULL);
1208 LDP_ENTER(global->user_data, "ldp_cfg_fec_get");
1210 mpls_lock_get(global->global_lock); /* LOCK */
1212 if (flag & LDP_FEC_CFG_BY_INDEX) {
1213 ldp_global_find_fec_index(global, f->index, &fec);
1214 } else {
1215 fec = ldp_fec_find(global, f);
1217 if (!fec)
1218 goto ldp_cfg_fec_get_end;
1220 memcpy(f, &fec->info, sizeof(mpls_fec));
1221 f->index = fec->index;
1222 retval = MPLS_SUCCESS;
1224 ldp_cfg_fec_get_end:
1225 mpls_lock_release(global->global_lock); /* UNLOCK */
1227 LDP_EXIT(global->user_data, "ldp_cfg_fec_get");
1229 return retval;
1232 mpls_return_enum ldp_cfg_fec_getnext(mpls_cfg_handle handle, mpls_fec * f,
1233 uint32_t flag)
1235 ldp_global *g = (ldp_global *) handle;
1236 ldp_fec *fec = NULL;
1237 mpls_return_enum r = MPLS_FAILURE;
1238 mpls_bool done = MPLS_BOOL_FALSE;
1239 int index;
1241 LDP_ENTER(g->user_data, "ldp_cfg_fec_getnext");
1243 if (f->index == 0) {
1244 index = 1;
1245 } else {
1246 index = f->index + 1;
1249 mpls_lock_get(g->global_lock); /* LOCK */
1250 while (done == MPLS_BOOL_FALSE) {
1251 switch ((r = ldp_global_find_fec_index(g, index, &fec))) {
1252 case MPLS_SUCCESS:
1253 case MPLS_END_OF_LIST:
1254 done = MPLS_BOOL_TRUE;
1255 break;
1256 case MPLS_FAILURE:
1257 break;
1258 default:
1259 MPLS_ASSERT(0);
1261 index++;
1263 mpls_lock_release(g->global_lock); /* UNLOCK */
1265 if (r == MPLS_SUCCESS) {
1266 f->index = fec->index;
1267 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1268 return ldp_cfg_fec_get(g, f, flag);
1270 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1271 return r;
1274 mpls_return_enum ldp_cfg_fec_test(mpls_cfg_handle handle, mpls_fec * f,
1275 uint32_t flag)
1277 // ldp_global* g = (ldp_global*)handle;
1278 return MPLS_SUCCESS;
1281 mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f,
1282 uint32_t flag)
1284 ldp_global *global = (ldp_global *) handle;
1285 ldp_fec *fec = NULL;
1286 mpls_return_enum retval = MPLS_FAILURE;
1288 MPLS_ASSERT(global !=NULL && f != NULL);
1290 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1292 mpls_lock_get(global->global_lock); /* LOCK */
1294 if (flag & LDP_CFG_ADD) {
1295 if (ldp_fec_find(global, f) || (fec = ldp_fec_create(global, f)) == NULL) {
1296 goto ldp_cfg_fec_set_end;
1298 f->index = fec->index;
1299 } else {
1300 if (flag & LDP_FEC_CFG_BY_INDEX) {
1301 ldp_global_find_fec_index(global, f->index, &fec);
1302 } else {
1303 fec = ldp_fec_find(global, f);
1307 if (fec == NULL) {
1308 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1309 goto ldp_cfg_fec_set_end;
1312 if (flag & LDP_CFG_DEL) {
1313 MPLS_ASSERT(0);
1316 retval = MPLS_SUCCESS;
1318 ldp_cfg_fec_set_end:
1319 mpls_lock_release(global->global_lock); /* UNLOCK */
1321 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1323 return retval;
1326 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1327 mpls_nexthop *n, uint32_t flag)
1329 ldp_global *global = (ldp_global *) handle;
1330 ldp_fec *fec = NULL;
1331 ldp_nexthop *nh = NULL;
1332 mpls_return_enum retval = MPLS_FAILURE;
1334 MPLS_ASSERT(global !=NULL && f != NULL);
1336 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1338 mpls_lock_get(global->global_lock); /* LOCK */
1340 if (flag & LDP_FEC_CFG_BY_INDEX) {
1341 ldp_global_find_fec_index(global, f->index, &fec);
1342 } else {
1343 fec = ldp_fec_find(global, f);
1345 if (!fec)
1346 goto ldp_cfg_fec_nexthop_get_end;
1348 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1349 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1350 } else {
1351 nh = ldp_fec_nexthop_find(fec, n);
1353 if (!nh)
1354 goto ldp_cfg_fec_nexthop_get_end;
1356 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1357 n->index = nh->index;
1358 retval = MPLS_SUCCESS;
1360 ldp_cfg_fec_nexthop_get_end:
1361 mpls_lock_release(global->global_lock); /* UNLOCK */
1363 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1365 return retval;
1368 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1369 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1371 ldp_global *global = (ldp_global *) handle;
1372 ldp_fec *fec = NULL;
1373 ldp_nexthop *nh = NULL;
1374 mpls_return_enum r = MPLS_FAILURE;
1375 mpls_bool done = MPLS_BOOL_FALSE;
1376 int index;
1378 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1380 if (n->index == 0) {
1381 index = 1;
1382 } else {
1383 index = n->index + 1;
1386 mpls_lock_get(global->global_lock); /* LOCK */
1388 if (flag & LDP_FEC_CFG_BY_INDEX) {
1389 ldp_global_find_fec_index(global, f->index, &fec);
1390 } else {
1391 fec = ldp_fec_find(global, f);
1393 if (!fec)
1394 goto ldp_cfg_fec_nexthop_getnext_end;
1396 while (done == MPLS_BOOL_FALSE) {
1397 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1398 case MPLS_SUCCESS:
1399 case MPLS_END_OF_LIST:
1400 done = MPLS_BOOL_TRUE;
1401 break;
1402 case MPLS_FAILURE:
1403 break;
1404 default:
1405 MPLS_ASSERT(0);
1407 index++;
1409 mpls_lock_release(global->global_lock); /* UNLOCK */
1411 if (r == MPLS_SUCCESS) {
1412 n->index = nh->index;
1413 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1414 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1417 ldp_cfg_fec_nexthop_getnext_end:
1419 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1420 return r;
1423 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1424 mpls_nexthop *n, uint32_t flag)
1426 // ldp_global* g = (ldp_global*)handle;
1427 return MPLS_SUCCESS;
1430 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1431 mpls_nexthop *n, uint32_t flag)
1433 ldp_global *global = (ldp_global *) handle;
1434 ldp_fec *fec = NULL;
1435 ldp_nexthop *nh = NULL;
1436 mpls_return_enum retval = MPLS_FAILURE;
1438 MPLS_ASSERT(global !=NULL && f != NULL && n != NULL);
1440 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1442 mpls_lock_get(global->global_lock); /* LOCK */
1444 if (flag & LDP_FEC_CFG_BY_INDEX) {
1445 ldp_global_find_fec_index(global, f->index, &fec);
1446 } else {
1447 fec = ldp_fec_find(global, f);
1449 if (!fec)
1450 goto ldp_cfg_fec_nexthop_set_end;
1452 if (flag & LDP_CFG_ADD) {
1453 if (ldp_fec_nexthop_find(fec, n) || (nh = ldp_nexthop_create()) == NULL) {
1454 goto ldp_cfg_fec_nexthop_set_end;
1456 n->index = nh->index;
1457 mpls_nexthop2ldp_nexthop(n, nh);
1458 _ldp_global_add_nexthop(global, nh);
1459 ldp_fec_add_nexthop(global, fec, nh);
1460 ldp_fec_process_add(global, fec, nh, NULL);
1461 } else {
1462 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1463 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1464 } else {
1465 nh = ldp_fec_nexthop_find(fec, n);
1469 if (nh == NULL) {
1470 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1471 goto ldp_cfg_fec_nexthop_set_end;
1474 if (flag & LDP_CFG_DEL) {
1475 ldp_fec_del_nexthop(global, fec, nh);
1476 if (ldp_fec_process_change(global, fec, MPLS_LIST_HEAD(&fec->nh_root),
1477 nh, NULL) != MPLS_SUCCESS) {
1478 MPLS_ASSERT(0);
1480 _ldp_global_del_nexthop(global, nh);
1483 retval = MPLS_SUCCESS;
1485 ldp_cfg_fec_nexthop_set_end:
1486 mpls_lock_release(global->global_lock); /* UNLOCK */
1488 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1490 return retval;
1493 /******************* ADDR **********************/
1495 mpls_return_enum ldp_cfg_addr_get(mpls_cfg_handle handle, ldp_addr * a,
1496 uint32_t flag)
1498 ldp_global *global = (ldp_global *) handle;
1499 ldp_session *session = NULL;
1500 ldp_nexthop *nexthop = NULL;
1501 ldp_addr *addr = NULL;
1502 mpls_return_enum retval = MPLS_FAILURE;
1504 MPLS_ASSERT(global !=NULL && a != NULL);
1506 LDP_ENTER(global->user_data, "ldp_cfg_addr_get");
1508 mpls_lock_get(global->global_lock); /* LOCK */
1510 ldp_global_find_addr_index(global, a->index, &addr);
1512 if (!addr)
1513 goto ldp_cfg_addr_get_end;
1515 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1516 a->index = addr->index;
1518 if ((session = mpls_link_list_head_data(&addr->session_root))) {
1519 a->session_index = session->index;
1522 if ((nexthop = MPLS_LIST_HEAD(&addr->nh_root))) {
1523 a->nexthop_index = nexthop->index;
1526 if (addr->iff) {
1527 a->if_index = addr->iff->index;
1530 retval = MPLS_SUCCESS;
1532 ldp_cfg_addr_get_end:
1533 mpls_lock_release(global->global_lock); /* UNLOCK */
1535 LDP_EXIT(global->user_data, "ldp_cfg_addr_get");
1537 return retval;
1540 mpls_return_enum ldp_cfg_addr_getnext(mpls_cfg_handle handle, ldp_addr *a,
1541 uint32_t flag)
1543 ldp_global *global = (ldp_global *) handle;
1544 ldp_addr *addr = NULL;
1545 mpls_return_enum r = MPLS_FAILURE;
1546 mpls_bool done = MPLS_BOOL_FALSE;
1547 int index;
1549 LDP_ENTER(global->user_data, "ldp_cfg_addr_getnext");
1551 if (a->index == 0) {
1552 index = 1;
1553 } else {
1554 index = a->index + 1;
1557 mpls_lock_get(global->global_lock); /* LOCK */
1559 while (done == MPLS_BOOL_FALSE) {
1560 switch ((r = ldp_global_find_addr_index(global, index, &addr))) {
1561 case MPLS_SUCCESS:
1562 case MPLS_END_OF_LIST:
1563 done = MPLS_BOOL_TRUE;
1564 break;
1565 case MPLS_FAILURE:
1566 break;
1567 default:
1568 MPLS_ASSERT(0);
1570 index++;
1572 mpls_lock_release(global->global_lock); /* UNLOCK */
1574 if (r == MPLS_SUCCESS) {
1575 a->index = addr->index;
1576 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1577 return ldp_cfg_addr_get(global, a, flag);
1580 LDP_EXIT(global->user_data, "ldp_cfg_addr_getnext");
1581 return r;
1584 /******************* IF ADDR **********************/
1586 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1587 ldp_addr * a, uint32_t flag)
1589 ldp_global *global = (ldp_global *) handle;
1590 ldp_addr *addr = NULL;
1591 ldp_if *iff = NULL;
1592 mpls_return_enum retval = MPLS_FAILURE;
1594 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1596 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1598 mpls_lock_get(global->global_lock); /* LOCK */
1600 if (flag & LDP_IF_CFG_BY_INDEX) {
1601 ldp_global_find_if_index(global, i->index, &iff);
1602 } else {
1603 iff = ldp_global_find_if_handle(global, i->handle);
1605 if (!iff)
1606 goto ldp_cfg_if_addr_get_end;
1608 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1609 ldp_if_find_addr_index(iff, a->index, &addr);
1610 } else {
1611 addr = ldp_if_addr_find(iff, &a->address);
1613 if (!addr)
1614 goto ldp_cfg_if_addr_get_end;
1616 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1617 a->index = addr->index;
1619 retval = MPLS_SUCCESS;
1621 ldp_cfg_if_addr_get_end:
1622 mpls_lock_release(global->global_lock); /* UNLOCK */
1624 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1626 return retval;
1629 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1630 ldp_if * i, ldp_addr *a, uint32_t flag)
1632 ldp_global *global = (ldp_global *) handle;
1633 ldp_if *iff = NULL;
1634 ldp_addr *addr = NULL;
1635 mpls_return_enum r = MPLS_FAILURE;
1636 mpls_bool done = MPLS_BOOL_FALSE;
1637 int index;
1639 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1641 if (a->index == 0) {
1642 index = 1;
1643 } else {
1644 index = a->index + 1;
1647 mpls_lock_get(global->global_lock); /* LOCK */
1649 if (flag & LDP_IF_CFG_BY_INDEX) {
1650 ldp_global_find_if_index(global, i->index, &iff);
1651 } else {
1652 iff = ldp_global_find_if_handle(global, i->handle);
1654 if (!iff)
1655 goto ldp_cfg_if_addr_getnext_end;
1657 while (done == MPLS_BOOL_FALSE) {
1658 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1659 case MPLS_SUCCESS:
1660 case MPLS_END_OF_LIST:
1661 done = MPLS_BOOL_TRUE;
1662 break;
1663 case MPLS_FAILURE:
1664 break;
1665 default:
1666 MPLS_ASSERT(0);
1668 index++;
1670 mpls_lock_release(global->global_lock); /* UNLOCK */
1672 if (r == MPLS_SUCCESS) {
1673 a->index = addr->index;
1674 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1675 return ldp_cfg_if_addr_get(global, i, a, flag);
1678 ldp_cfg_if_addr_getnext_end:
1680 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1681 return r;
1684 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1685 ldp_addr *a, uint32_t flag)
1687 ldp_global *global = (ldp_global *) handle;
1688 ldp_if *iff = NULL;
1689 ldp_addr *addr = NULL;
1690 mpls_return_enum retval = MPLS_FAILURE;
1692 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1694 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1696 mpls_lock_get(global->global_lock); /* LOCK */
1698 if (flag & LDP_FEC_CFG_BY_INDEX) {
1699 ldp_global_find_if_index(global, i->index, &iff);
1700 } else {
1701 iff = ldp_global_find_if_handle(global, i->handle);
1703 if (!iff)
1704 goto ldp_cfg_if_addr_set_end;
1706 if (flag & LDP_CFG_ADD) {
1707 if (ldp_if_addr_find(iff, &a->address) || (addr = ldp_addr_create(global,
1708 &a->address)) == NULL) {
1709 goto ldp_cfg_if_addr_set_end;
1711 a->index = addr->index;
1712 ldp_if_add_addr(iff, addr);
1713 } else {
1714 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1715 ldp_if_find_addr_index(iff, a->index, &addr);
1716 } else {
1717 addr = ldp_if_addr_find(iff, &a->address);
1721 if (addr == NULL) {
1722 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1723 goto ldp_cfg_if_addr_set_end;
1726 if (flag & LDP_CFG_DEL) {
1727 ldp_if_del_addr(global, iff ,addr);
1730 retval = MPLS_SUCCESS;
1732 ldp_cfg_if_addr_set_end:
1733 mpls_lock_release(global->global_lock); /* UNLOCK */
1735 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1737 return retval;
1740 /******************* ADJACENCY **********************/
1742 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1743 uint32_t flag)
1745 ldp_global *global = (ldp_global *) handle;
1746 ldp_adj *adj = NULL;
1747 mpls_return_enum retval = MPLS_FAILURE;
1749 MPLS_ASSERT(global !=NULL && a != NULL);
1751 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1753 mpls_lock_get(global->global_lock); /* LOCK */
1755 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1756 goto ldp_cfg_adj_get_end;
1758 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1759 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1760 sizeof(mpls_inet_addr));
1762 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1763 memcpy(&a->remote_source_address, &adj->remote_source_address,
1764 sizeof(mpls_inet_addr));
1766 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1767 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1768 sizeof(mpls_inet_addr));
1770 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1771 a->remote_csn = adj->remote_csn;
1773 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1774 a->remote_label_space = adj->remote_label_space;
1776 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1777 a->remote_hellotime = adj->remote_hellotime;
1779 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1780 a->entity_index = adj->entity ? adj->entity->index : 0;
1782 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1783 a->session_index = (adj->session) ? (adj->session->index) : 0;
1785 if (flag & LDP_ADJ_CFG_ROLE) {
1786 a->role = adj->role;
1788 retval = MPLS_SUCCESS;
1790 ldp_cfg_adj_get_end:
1792 mpls_lock_release(global->global_lock); /* UNLOCK */
1794 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1796 return retval;
1799 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1800 uint32_t flag)
1802 ldp_global *g = (ldp_global *) handle;
1803 ldp_adj *adj = NULL;
1804 mpls_return_enum r = MPLS_FAILURE;
1805 mpls_bool done = MPLS_BOOL_FALSE;
1806 int index;
1808 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1810 if (a->index == 0) {
1811 index = 1;
1812 } else {
1813 index = a->index + 1;
1816 mpls_lock_get(g->global_lock); /* LOCK */
1817 while (done == MPLS_BOOL_FALSE) {
1818 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1819 case MPLS_SUCCESS:
1820 case MPLS_END_OF_LIST:
1821 done = MPLS_BOOL_TRUE;
1822 break;
1823 case MPLS_FAILURE:
1824 break;
1825 default:
1826 MPLS_ASSERT(0);
1828 index++;
1830 mpls_lock_release(g->global_lock); /* UNLOCK */
1832 if (r == MPLS_SUCCESS) {
1833 a->index = adj->index;
1834 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1835 return ldp_cfg_adj_get(g, a, flag);
1837 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1838 return r;
1841 /******************* SESSION **********************/
1843 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1844 uint32_t flag)
1846 ldp_global *global = (ldp_global *) handle;
1847 ldp_session *session = NULL;
1848 mpls_return_enum retval = MPLS_FAILURE;
1850 MPLS_ASSERT(global !=NULL && s != NULL);
1852 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1854 mpls_lock_get(global->global_lock); /* LOCK */
1856 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1857 goto ldp_cfg_session_get_end;
1859 if (flag & LDP_SESSION_CFG_STATE) {
1860 s->state = session->state;
1862 if (flag & LDP_SESSION_CFG_OPER_UP) {
1863 s->oper_up = session->oper_up;
1865 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1866 s->oper_max_pdu = session->oper_max_pdu;
1868 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1869 s->oper_keepalive = session->oper_keepalive;
1871 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1872 s->oper_path_vector_limit = session->oper_path_vector_limit;
1874 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1875 s->oper_distribution_mode = session->oper_distribution_mode;
1877 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1878 s->oper_loop_detection = session->oper_loop_detection;
1880 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1881 s->remote_max_pdu = session->remote_max_pdu;
1883 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1884 s->remote_keepalive = session->remote_keepalive;
1886 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1887 s->remote_path_vector_limit = session->remote_path_vector_limit;
1889 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1890 s->remote_distribution_mode = session->remote_distribution_mode;
1892 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1893 s->remote_loop_detection = session->remote_loop_detection;
1895 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1896 s->remote_dest.addr.type = session->remote_dest.addr.type;
1897 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1899 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1900 s->remote_dest.port = session->remote_dest.port;
1902 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1903 s->no_label_resource_sent = session->no_label_resource_sent;
1905 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1906 s->no_label_resource_recv = session->no_label_resource_recv;
1908 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1909 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1910 s->adj_index = a ? a->index : 0;
1912 if (flag & LDP_SESSION_CFG_MESG_TX) {
1913 s->mesg_tx = session->mesg_tx;
1915 if (flag & LDP_SESSION_CFG_MESG_RX) {
1916 s->mesg_rx = session->mesg_rx;
1918 retval = MPLS_SUCCESS;
1920 ldp_cfg_session_get_end:
1921 mpls_lock_release(global->global_lock); /* UNLOCK */
1923 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1925 return retval;
1928 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1929 uint32_t flag)
1931 ldp_global *g = (ldp_global *) handle;
1932 ldp_session *ses = NULL;
1933 mpls_return_enum r = MPLS_FAILURE;
1934 mpls_bool done = MPLS_BOOL_FALSE;
1935 int index;
1937 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1939 if (s->index == 0) {
1940 index = 1;
1941 } else {
1942 index = s->index + 1;
1945 mpls_lock_get(g->global_lock); /* LOCK */
1946 while (done == MPLS_BOOL_FALSE) {
1947 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1948 case MPLS_SUCCESS:
1949 case MPLS_END_OF_LIST:
1950 done = MPLS_BOOL_TRUE;
1951 break;
1952 case MPLS_FAILURE:
1953 break;
1954 default:
1955 MPLS_ASSERT(0);
1957 index++;
1959 mpls_lock_release(g->global_lock); /* UNLOCK */
1961 if (r == MPLS_SUCCESS) {
1962 s->index = ses->index;
1964 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1965 return ldp_cfg_session_get(g, s, flag);
1968 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1970 return r;
1973 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1974 ldp_session * s)
1976 ldp_global *g = (ldp_global *) handle;
1977 mpls_bool this_one = MPLS_BOOL_FALSE;
1978 mpls_return_enum r = MPLS_FAILURE;
1979 ldp_adj *adj_next = NULL;
1980 ldp_adj *adj = NULL;
1981 ldp_session *session = NULL;
1983 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
1985 /* if an adj_index of zero is sent, get the index of
1986 * the first adj in the list
1988 if (!s->adj_index) {
1989 this_one = MPLS_BOOL_TRUE;
1992 mpls_lock_get(g->global_lock); /* LOCK */
1994 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
1995 adj = MPLS_LIST_HEAD(&session->adj_root);
1996 while (adj) {
1997 if (this_one == MPLS_BOOL_TRUE) {
1998 adj_next = adj;
1999 break;
2002 /* since the entities are sort in the list ... */
2003 if (adj->index > s->adj_index) {
2004 break;
2005 } else if (adj->index == s->adj_index) {
2006 this_one = MPLS_BOOL_TRUE;
2008 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
2011 mpls_lock_release(g->global_lock); /* UNLOCK */
2013 if (adj_next) {
2014 s->adj_index = adj_next->index;
2015 r = MPLS_SUCCESS;
2018 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
2019 return r;
2022 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
2023 ldp_session * s, ldp_addr * a, uint32_t flag)
2025 ldp_global *global = (ldp_global *) handle;
2026 ldp_session *session = NULL;
2027 ldp_addr *addr = NULL;
2028 mpls_return_enum retval = MPLS_FAILURE;
2030 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
2032 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
2034 mpls_lock_get(global->global_lock); /* LOCK */
2036 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
2037 goto ldp_cfg_session_raddr_get_end;
2039 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
2040 goto ldp_cfg_session_raddr_get_end;
2042 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
2043 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
2045 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
2046 a->index = addr->index;
2048 retval = MPLS_SUCCESS;
2050 ldp_cfg_session_raddr_get_end:
2051 mpls_lock_release(global->global_lock); /* UNLOCK */
2053 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
2055 return retval;
2058 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
2059 ldp_session * s, ldp_addr * a, uint32_t flag)
2061 ldp_global *g = (ldp_global *) handle;
2062 ldp_addr *addr = NULL;
2063 mpls_return_enum r = MPLS_FAILURE;
2064 mpls_bool done = MPLS_BOOL_FALSE;
2065 ldp_session *sp = NULL;
2066 int index;
2068 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
2070 if (a->index == 0) {
2071 index = 1;
2072 } else {
2073 index = a->index + 1;
2076 r = ldp_global_find_session_index(g, s->index, &sp);
2077 if (r != MPLS_SUCCESS) {
2078 return r;
2081 mpls_lock_get(g->global_lock); /* LOCK */
2082 while (done == MPLS_BOOL_FALSE) {
2083 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
2084 case MPLS_SUCCESS:
2085 case MPLS_END_OF_LIST:
2086 done = MPLS_BOOL_TRUE;
2087 break;
2088 case MPLS_FAILURE:
2089 break;
2090 default:
2091 MPLS_ASSERT(0);
2093 index++;
2095 mpls_lock_release(g->global_lock); /* UNLOCK */
2097 if (r == MPLS_SUCCESS) {
2098 a->index = addr->index;
2099 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2102 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2103 return r;
2106 /******************* IN LABEL **********************/
2108 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2109 uint32_t flag)
2111 ldp_global *global = (ldp_global *) handle;
2112 ldp_inlabel *inlabel = NULL;
2113 mpls_return_enum retval = MPLS_FAILURE;
2115 MPLS_ASSERT(global !=NULL && i != NULL);
2117 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2119 mpls_lock_get(global->global_lock); /* LOCK */
2121 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2122 goto ldp_cfg_inlabel_get_end;
2124 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2125 i->info.labelspace = inlabel->info.labelspace;
2127 if (flag & LDP_INLABEL_CFG_LABEL) {
2128 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2130 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2131 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2134 retval = MPLS_SUCCESS;
2136 ldp_cfg_inlabel_get_end:
2137 mpls_lock_release(global->global_lock); /* UNLOCK */
2139 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2141 return retval;
2144 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2145 uint32_t flag)
2147 ldp_global *g = (ldp_global *) handle;
2148 ldp_inlabel *inlabel = NULL;
2149 mpls_return_enum r = MPLS_FAILURE;
2150 mpls_bool done = MPLS_BOOL_FALSE;
2151 int index;
2153 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2155 if (i->index == 0) {
2156 index = 1;
2157 } else {
2158 index = i->index + 1;
2161 mpls_lock_get(g->global_lock); /* LOCK */
2162 while (done == MPLS_BOOL_FALSE) {
2163 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2164 case MPLS_SUCCESS:
2165 case MPLS_END_OF_LIST:
2166 done = MPLS_BOOL_TRUE;
2167 break;
2168 case MPLS_FAILURE:
2169 break;
2170 default:
2171 MPLS_ASSERT(0);
2173 index++;
2175 mpls_lock_release(g->global_lock); /* UNLOCK */
2177 if (r == MPLS_SUCCESS) {
2178 i->index = inlabel->index;
2180 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2181 return ldp_cfg_inlabel_get(g, i, flag);
2184 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2186 return r;
2189 /******************* OUT LABEL **********************/
2191 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2192 uint32_t flag)
2194 ldp_global *global = (ldp_global *) handle;
2195 ldp_outlabel *outlabel = NULL;
2196 mpls_return_enum retval = MPLS_FAILURE;
2198 MPLS_ASSERT(global !=NULL && o != NULL);
2200 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2202 mpls_lock_get(global->global_lock); /* LOCK */
2204 if (ldp_global_find_outlabel_index(global, o->index,
2205 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2207 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2208 if (outlabel->nh) {
2209 o->nh_index = outlabel->nh->index;
2210 } else {
2211 o->nh_index = 0;
2214 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2215 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2217 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2218 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2220 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2221 o->merge_count = outlabel->merge_count;
2224 retval = MPLS_SUCCESS;
2226 ldp_cfg_outlabel_get_end:
2227 mpls_lock_release(global->global_lock); /* UNLOCK */
2229 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2231 return retval;
2234 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2235 ldp_outlabel * o, uint32_t flag)
2237 ldp_global *g = (ldp_global *) handle;
2238 ldp_outlabel *outlabel = NULL;
2239 mpls_return_enum r = MPLS_FAILURE;
2240 mpls_bool done = MPLS_BOOL_FALSE;
2241 int index;
2243 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2245 if (o->index == 0) {
2246 index = 1;
2247 } else {
2248 index = o->index + 1;
2251 mpls_lock_get(g->global_lock); /* LOCK */
2252 while (done == MPLS_BOOL_FALSE) {
2253 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2254 case MPLS_SUCCESS:
2255 case MPLS_END_OF_LIST:
2256 done = MPLS_BOOL_TRUE;
2257 break;
2258 case MPLS_FAILURE:
2259 break;
2260 default:
2261 MPLS_ASSERT(0);
2263 index++;
2265 mpls_lock_release(g->global_lock); /* UNLOCK */
2267 if (r == MPLS_SUCCESS) {
2268 o->index = outlabel->index;
2270 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2271 return ldp_cfg_outlabel_get(g, o, flag);
2274 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2276 return r;
2279 /******************* TUNNEL **********************/
2281 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2282 uint32_t flag)
2284 ldp_global *global = (ldp_global *) handle;
2285 mpls_return_enum retval = MPLS_FAILURE;
2286 ldp_tunnel *tunnel = NULL;
2288 MPLS_ASSERT(global !=NULL);
2290 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2292 mpls_lock_get(global->global_lock); /* LOCK */
2294 if (flag & LDP_CFG_ADD) {
2295 if (!(tunnel = ldp_tunnel_create())) {
2296 goto ldp_cfg_tunnel_set_end;
2298 _ldp_global_add_tunnel(global, tunnel);
2300 t->index = tunnel->index;
2301 } else {
2302 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2305 if (!tunnel) {
2306 LDP_PRINT(global->user_data,
2308 "ldp_cfg_tunnel_set:could not create tunnel\n");
2309 goto ldp_cfg_tunnel_set_end;
2312 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2313 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2314 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2316 goto ldp_cfg_tunnel_set_end;
2319 if (flag & LDP_CFG_DEL) {
2320 if (tunnel->outlabel)
2321 ldp_tunnel_del_outlabel(tunnel);
2322 if (tunnel->resource)
2323 ldp_tunnel_del_resource(tunnel);
2324 if (tunnel->hop_list)
2325 ldp_tunnel_del_hop_list(tunnel);
2326 _ldp_global_del_tunnel(global, tunnel);
2328 retval = MPLS_SUCCESS;
2329 goto ldp_cfg_tunnel_set_end;
2332 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2333 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2335 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2336 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2338 if (flag & LDP_TUNNEL_CFG_NAME) {
2339 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2341 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2342 tunnel->is_interface = t->is_interface;
2344 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2345 ldp_outlabel *outlabel = NULL;
2347 if (t->outlabel_index) {
2348 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2350 if (!outlabel) {
2351 goto ldp_cfg_tunnel_set_end;
2353 ldp_tunnel_add_outlabel(tunnel, outlabel);
2354 } else {
2355 ldp_tunnel_del_outlabel(tunnel);
2358 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2359 tunnel->setup_prio = t->setup_prio;
2361 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2362 tunnel->hold_prio = t->hold_prio;
2364 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2365 tunnel->instance_prio = t->instance_prio;
2367 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2368 tunnel->local_protect = t->local_protect;
2370 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2371 ldp_resource *resource = NULL;
2373 if (t->resource_index) {
2374 ldp_global_find_resource_index(global, t->resource_index, &resource);
2376 if (!resource) {
2377 goto ldp_cfg_tunnel_set_end;
2379 ldp_tunnel_add_resource(tunnel, resource);
2380 } else {
2381 ldp_tunnel_del_resource(tunnel);
2384 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2385 ldp_hop_list *hop_list = NULL;
2387 if (t->hop_list_index) {
2388 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2390 if (!hop_list) {
2391 goto ldp_cfg_tunnel_set_end;
2393 ldp_tunnel_add_hop_list(tunnel, hop_list);
2394 } else {
2395 ldp_tunnel_del_hop_list(tunnel);
2398 if (flag & LDP_TUNNEL_CFG_FEC) {
2399 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2401 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2402 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2403 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2404 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2405 goto ldp_cfg_tunnel_set_end;
2408 } else {
2409 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2410 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2411 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2412 goto ldp_cfg_tunnel_set_end;
2414 } else {
2415 LDP_PRINT(global->user_data,
2417 "ldp_cfg_tunnel_set: tunnel not ready\n");
2418 goto ldp_cfg_tunnel_set_end;
2423 retval = MPLS_SUCCESS;
2425 ldp_cfg_tunnel_set_end:
2427 mpls_lock_release(global->global_lock); /* UNLOCK */
2429 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2431 return retval;
2434 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2435 uint32_t flag)
2437 ldp_global *global = (ldp_global *) handle;
2438 mpls_return_enum retval = MPLS_FAILURE;
2439 ldp_tunnel *tunnel = NULL;
2441 MPLS_ASSERT(global !=NULL);
2443 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2445 mpls_lock_get(global->global_lock); /* LOCK */
2447 if (flag & LDP_CFG_ADD) {
2448 retval = MPLS_SUCCESS;
2449 goto ldp_cfg_tunnel_test_end;
2452 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2454 if (!tunnel) {
2455 goto ldp_cfg_tunnel_test_end;
2458 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2459 ldp_resource *resource = NULL;
2461 if (t->resource_index) {
2462 ldp_global_find_resource_index(global, t->resource_index, &resource);
2464 if (!resource) {
2465 goto ldp_cfg_tunnel_test_end;
2469 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2470 ldp_hop_list *hop_list = NULL;
2472 if (t->hop_list_index) {
2473 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2475 if (!hop_list) {
2476 goto ldp_cfg_tunnel_test_end;
2480 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2481 ldp_outlabel *outlabel = NULL;
2483 if (t->outlabel_index) {
2484 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2486 if (!outlabel) {
2487 goto ldp_cfg_tunnel_test_end;
2491 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2492 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2493 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2494 goto ldp_cfg_tunnel_test_end;
2496 retval = MPLS_SUCCESS;
2498 ldp_cfg_tunnel_test_end:
2500 mpls_lock_release(global->global_lock); /* UNLOCK */
2502 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2504 return retval;
2507 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2508 uint32_t flag)
2510 ldp_global *global = (ldp_global *) handle;
2511 mpls_return_enum retval = MPLS_FAILURE;
2512 ldp_tunnel *tunnel = NULL;
2514 MPLS_ASSERT(global !=NULL);
2516 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2518 mpls_lock_get(global->global_lock); /* LOCK */
2520 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2522 if (!tunnel) {
2523 goto ldp_cfg_tunnel_get_end;
2525 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2526 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2528 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2529 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2531 if (flag & LDP_TUNNEL_CFG_NAME) {
2532 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2534 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2535 t->is_interface = tunnel->is_interface;
2537 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2538 if (tunnel->outlabel) {
2539 t->outlabel_index = tunnel->outlabel->index;
2540 } else {
2541 t->outlabel_index = 0;
2544 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2545 t->setup_prio = tunnel->setup_prio;
2547 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2548 t->hold_prio = tunnel->hold_prio;
2550 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2551 tunnel->instance_prio = t->instance_prio;
2553 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2554 tunnel->local_protect = t->local_protect;
2556 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2557 if (tunnel->resource) {
2558 t->resource_index = tunnel->resource->index;
2559 } else {
2560 t->resource_index = 0;
2563 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2564 if (tunnel->hop_list) {
2565 t->hop_list_index = tunnel->hop_list->index;
2566 } else {
2567 t->hop_list_index = 0;
2570 if (flag & LDP_TUNNEL_CFG_FEC) {
2571 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2573 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2574 t->admin_state = tunnel->admin_state;
2576 retval = MPLS_SUCCESS;
2578 ldp_cfg_tunnel_get_end:
2580 mpls_lock_release(global->global_lock); /* UNLOCK */
2582 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2584 return retval;
2587 /******************* RESOURCE **********************/
2589 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2590 uint32_t flag)
2592 ldp_global *global = (ldp_global *) handle;
2593 mpls_return_enum retval = MPLS_FAILURE;
2594 ldp_resource *resource = NULL;
2596 MPLS_ASSERT(global !=NULL);
2598 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2600 mpls_lock_get(global->global_lock); /* LOCK */
2602 if (flag & LDP_CFG_ADD) {
2603 resource = ldp_resource_create();
2604 _ldp_global_add_resource(global, resource);
2606 r->index = resource->index;
2607 } else {
2608 ldp_global_find_resource_index(global, r->index, &resource);
2611 if (!resource) {
2612 goto ldp_cfg_resource_set_end;
2615 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2616 resource->max_rate = r->max_rate;
2618 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2619 resource->mean_rate = r->mean_rate;
2621 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2622 resource->burst_size = r->burst_size;
2624 retval = MPLS_SUCCESS;
2626 ldp_cfg_resource_set_end:
2628 mpls_lock_release(global->global_lock); /* UNLOCK */
2630 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2632 return retval;
2635 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2636 uint32_t flag)
2638 ldp_global *global = (ldp_global *) handle;
2639 mpls_return_enum retval = MPLS_FAILURE;
2640 ldp_resource *resource = NULL;
2642 MPLS_ASSERT(global !=NULL);
2644 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2646 mpls_lock_get(global->global_lock); /* LOCK */
2648 if (flag & LDP_CFG_ADD) {
2649 retval = MPLS_SUCCESS;
2650 goto ldp_cfg_resource_test_end;
2653 ldp_global_find_resource_index(global, r->index, &resource);
2655 if (!resource) {
2656 goto ldp_cfg_resource_test_end;
2659 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2660 goto ldp_cfg_resource_test_end;
2662 retval = MPLS_SUCCESS;
2664 ldp_cfg_resource_test_end:
2666 mpls_lock_release(global->global_lock); /* UNLOCK */
2668 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2670 return retval;
2673 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2674 uint32_t flag)
2676 ldp_global *global = (ldp_global *) handle;
2677 mpls_return_enum retval = MPLS_FAILURE;
2678 ldp_resource *resource = NULL;
2680 MPLS_ASSERT(global !=NULL);
2682 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2684 mpls_lock_get(global->global_lock); /* LOCK */
2686 ldp_global_find_resource_index(global, r->index, &resource);
2688 if (!resource) {
2689 goto ldp_cfg_resource_get_end;
2692 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2693 r->max_rate = resource->max_rate;
2695 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2696 r->mean_rate = resource->mean_rate;
2698 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2699 r->burst_size = resource->burst_size;
2701 retval = MPLS_SUCCESS;
2703 ldp_cfg_resource_get_end:
2705 mpls_lock_release(global->global_lock); /* UNLOCK */
2707 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2709 return retval;
2712 /******************* HOP **********************/
2714 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2715 uint32_t flag)
2717 ldp_global *global = (ldp_global *) handle;
2718 mpls_return_enum retval = MPLS_FAILURE;
2719 ldp_hop_list *hop_list = NULL;
2720 ldp_hop *hop = NULL;
2722 MPLS_ASSERT(global !=NULL);
2724 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2726 if (!h->hop_list_index && !h->index) {
2727 return retval;
2730 mpls_lock_get(global->global_lock); /* LOCK */
2732 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2734 if (!hop_list) {
2735 if (flag & LDP_CFG_ADD) {
2736 if (!(hop_list = ldp_hop_list_create())) {
2737 goto ldp_cfg_hop_set_end;
2739 _ldp_global_add_hop_list(global, hop_list);
2741 h->hop_list_index = hop_list->index;
2742 } else {
2743 goto ldp_cfg_hop_set_end;
2747 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2748 if (!hop) {
2749 if (h->index && (flag & LDP_CFG_ADD)) {
2750 if (!(hop = ldp_hop_create())) {
2751 goto ldp_cfg_hop_set_end;
2753 hop->index = h->index;
2754 ldp_hop_list_add_hop(hop_list, hop);
2755 } else {
2756 goto ldp_cfg_hop_set_end;
2760 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2761 hop->path_option = h->path_option;
2763 if (flag & LDP_HOP_CFG_ADDR) {
2764 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2766 if (flag & LDP_HOP_CFG_TYPE) {
2767 hop->type = h->type;
2769 retval = MPLS_SUCCESS;
2771 ldp_cfg_hop_set_end:
2773 mpls_lock_release(global->global_lock); /* UNLOCK */
2775 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2777 return retval;
2780 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2781 uint32_t flag)
2783 ldp_global *global = (ldp_global *) handle;
2784 mpls_return_enum retval = MPLS_FAILURE;
2785 ldp_hop_list *hop_list = NULL;
2786 ldp_hop *hop = NULL;
2788 MPLS_ASSERT(global !=NULL);
2790 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2792 mpls_lock_get(global->global_lock); /* LOCK */
2794 if (flag & LDP_CFG_ADD) {
2795 retval = MPLS_SUCCESS;
2796 goto ldp_cfg_hop_test_end;
2799 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2801 if (!hop_list) {
2802 goto ldp_cfg_hop_test_end;
2805 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2806 if (!hop) {
2807 goto ldp_cfg_hop_test_end;
2810 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2811 goto ldp_cfg_hop_test_end;
2813 retval = MPLS_SUCCESS;
2815 ldp_cfg_hop_test_end:
2817 mpls_lock_release(global->global_lock); /* UNLOCK */
2819 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2821 return retval;
2824 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2825 uint32_t flag)
2827 ldp_global *global = (ldp_global *) handle;
2828 mpls_return_enum retval = MPLS_FAILURE;
2829 ldp_hop_list *hop_list = NULL;
2830 ldp_hop *hop = NULL;
2832 MPLS_ASSERT(global !=NULL);
2834 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2836 mpls_lock_get(global->global_lock); /* LOCK */
2838 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2840 if (!hop_list) {
2841 goto ldp_cfg_hop_get_end;
2844 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2845 if (!hop) {
2846 goto ldp_cfg_hop_get_end;
2849 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2850 h->path_option = hop->path_option;
2852 if (flag & LDP_HOP_CFG_ADDR) {
2853 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2855 if (flag & LDP_HOP_CFG_TYPE) {
2856 h->type = hop->type;
2858 retval = MPLS_SUCCESS;
2860 ldp_cfg_hop_get_end:
2862 mpls_lock_release(global->global_lock); /* UNLOCK */
2864 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2866 return retval;