No longer need mpls_ifmgr_get_address mpls_ifmgr_open_if and
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blob615dd79400374e214ec15c3de4bc6089d6579144
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->if_handle == iff->handle && (!MPLS_LIST_IN_LIST(np, _if))) {
865 ldp_if_add_nexthop(iff, np);
867 np = MPLS_LIST_NEXT(&global->nexthop, np, _global);
870 /* send the newly created index back to the user */
871 i->index = iff->index;
873 } else {
874 if (flag & LDP_IF_CFG_BY_INDEX) {
875 ldp_global_find_if_index(global, i->index, &iff);
876 } else {
877 iff = ldp_global_find_if_handle(global, i->handle);
882 * if we can't find this interface or if the interface is active and
883 * we are trying to change propertises that can not be changed on a
884 * active interface
886 if ((!iff) || ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
887 (flag & LDP_IF_CFG_WHEN_DOWN))) {
888 goto ldp_cfg_if_set_end;
891 if (flag & LDP_IF_CFG_LABEL_SPACE) {
892 iff->label_space = i->label_space;
895 if (flag & LDP_CFG_DEL) {
897 * if this interface is still attached to a entity that it is not ready
898 * to be removed
900 if (iff->entity != NULL) {
901 goto ldp_cfg_if_set_end;
904 np = MPLS_LIST_HEAD(&iff->nh_root);
905 while (np) {
906 ldp_if_del_nexthop(global, iff, np);
907 np = MPLS_LIST_NEXT(&iff->nh_root, np, _if);
910 ap = MPLS_LIST_HEAD(&iff->addr_root);
911 while (ap) {
912 ldp_if_del_addr(global, iff, ap);
913 ap = MPLS_LIST_NEXT(&iff->addr_root, ap, _if);
916 MPLS_REFCNT_RELEASE2(global, iff, ldp_if_delete);
919 global->configuration_sequence_number++;
921 retval = MPLS_SUCCESS;
923 ldp_cfg_if_set_end:
924 mpls_lock_release(global->global_lock); /* UNLOCK */
926 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
928 return retval;
931 /******************* ATTR **********************/
933 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
934 uint32_t flag)
936 ldp_global *global = (ldp_global *) handle;
937 ldp_attr *attr = NULL;
938 mpls_return_enum retval = MPLS_FAILURE;
940 MPLS_ASSERT(global !=NULL && a != NULL);
942 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
944 mpls_lock_get(global->global_lock); /* LOCK */
946 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
947 goto ldp_cfg_attr_get_end;
949 if (flag & LDP_ATTR_CFG_STATE) {
950 a->state = attr->state;
952 if (flag & LDP_ATTR_CFG_FEC) {
953 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
955 if (flag & LDP_ATTR_CFG_LABEL) {
956 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
958 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
959 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
961 if (flag & LDP_ATTR_CFG_PATH) {
962 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
964 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
965 a->session_index = (attr->session) ? (attr->session->index) : 0;
967 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
968 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
970 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
971 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
973 if (flag & LDP_ATTR_CFG_INGRESS) {
974 a->ingress = attr->ingress;
976 retval = MPLS_SUCCESS;
978 ldp_cfg_attr_get_end:
979 mpls_lock_release(global->global_lock); /* UNLOCK */
981 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
983 return retval;
986 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
987 uint32_t flag)
989 ldp_global *g = (ldp_global *) handle;
990 ldp_attr *attr = NULL;
991 mpls_return_enum r = MPLS_FAILURE;
992 mpls_bool done = MPLS_BOOL_FALSE;
993 int index;
995 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
997 if (a->index == 0) {
998 index = 1;
999 } else {
1000 index = a->index + 1;
1003 mpls_lock_get(g->global_lock); /* LOCK */
1004 while (done == MPLS_BOOL_FALSE) {
1005 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
1006 case MPLS_SUCCESS:
1007 case MPLS_END_OF_LIST:
1008 done = MPLS_BOOL_TRUE;
1009 break;
1010 case MPLS_FAILURE:
1011 break;
1012 default:
1013 MPLS_ASSERT(0);
1015 index++;
1017 mpls_lock_release(g->global_lock); /* UNLOCK */
1019 if (r == MPLS_SUCCESS) {
1020 a->index = attr->index;
1021 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1022 return ldp_cfg_attr_get(g, a, flag);
1024 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
1025 return r;
1028 /******************* PEER **********************/
1030 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
1031 uint32_t flag)
1033 ldp_global *global = (ldp_global *) handle;
1034 ldp_peer *peer = NULL;
1035 mpls_return_enum retval = MPLS_FAILURE;
1037 MPLS_ASSERT(global !=NULL && p != NULL);
1039 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
1041 mpls_lock_get(global->global_lock); /* LOCK */
1043 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
1044 goto ldp_cfg_peer_get_end;
1046 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1047 p->label_space = peer->label_space;
1049 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1050 p->target_role = peer->target_role;
1052 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1053 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1055 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1056 p->entity_index = peer->entity->index;
1058 if (flag & LDP_PEER_CFG_OPER_STATE) {
1059 p->oper_state = peer->oper_state;
1061 if (flag & LDP_PEER_CFG_PEER_NAME) {
1062 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1064 retval = MPLS_SUCCESS;
1066 ldp_cfg_peer_get_end:
1067 mpls_lock_release(global->global_lock); /* UNLOCK */
1069 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1071 return retval;
1074 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1075 uint32_t flag)
1077 ldp_global *g = (ldp_global *) handle;
1078 ldp_peer *peer = NULL;
1079 mpls_return_enum r = MPLS_FAILURE;
1080 mpls_bool done = MPLS_BOOL_FALSE;
1081 int index;
1083 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1085 if (p->index == 0) {
1086 index = 1;
1087 } else {
1088 index = p->index + 1;
1091 mpls_lock_get(g->global_lock); /* LOCK */
1092 while (done == MPLS_BOOL_FALSE) {
1093 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1094 case MPLS_SUCCESS:
1095 case MPLS_END_OF_LIST:
1096 done = MPLS_BOOL_TRUE;
1097 break;
1098 case MPLS_FAILURE:
1099 break;
1100 default:
1101 MPLS_ASSERT(0);
1103 index++;
1105 mpls_lock_release(g->global_lock); /* UNLOCK */
1107 if (r == MPLS_SUCCESS) {
1108 p->index = peer->index;
1109 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1110 return ldp_cfg_peer_get(g, p, flag);
1112 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1113 return r;
1116 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1117 uint32_t flag)
1119 // ldp_global* g = (ldp_global*)handle;
1120 return MPLS_SUCCESS;
1123 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1124 uint32_t flag)
1126 ldp_global *global = (ldp_global *) handle;
1127 ldp_peer *peer = NULL;
1128 mpls_return_enum retval = MPLS_FAILURE;
1130 MPLS_ASSERT(global !=NULL && p != NULL);
1132 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1134 mpls_lock_get(global->global_lock); /* LOCK */
1136 if (flag & LDP_CFG_ADD) {
1137 if ((peer = ldp_peer_create()) == NULL) {
1138 goto ldp_cfg_peer_set_end;
1140 p->index = peer->index;
1141 _ldp_global_add_peer(global, peer);
1142 } else {
1143 ldp_global_find_peer_index(global, p->index, &peer);
1146 if (peer == NULL) {
1147 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1149 goto ldp_cfg_peer_set_end;
1151 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1152 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1154 goto ldp_cfg_peer_set_end;
1157 if (flag & LDP_CFG_DEL) {
1158 if (peer->entity != NULL) {
1159 LDP_PRINT(global->user_data,
1160 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1162 goto ldp_cfg_peer_set_end;
1165 _ldp_global_del_peer(global, peer);
1167 retval = MPLS_SUCCESS;
1168 goto ldp_cfg_peer_set_end;
1170 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1171 peer->label_space = p->label_space;
1173 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1174 peer->target_role = p->target_role;
1176 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1177 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1179 if (flag & LDP_PEER_CFG_PEER_NAME) {
1180 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1182 p->peer_name);
1183 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1185 global->configuration_sequence_number++;
1187 retval = MPLS_SUCCESS;
1189 ldp_cfg_peer_set_end:
1190 mpls_lock_release(global->global_lock); /* UNLOCK */
1192 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1194 return retval;
1196 /******************* FEC **********************/
1198 mpls_return_enum ldp_cfg_fec_get(mpls_cfg_handle handle, mpls_fec * f,
1199 uint32_t flag)
1201 ldp_global *global = (ldp_global *) handle;
1202 ldp_fec *fec = NULL;
1203 mpls_return_enum retval = MPLS_FAILURE;
1205 MPLS_ASSERT(global !=NULL && f != NULL);
1207 LDP_ENTER(global->user_data, "ldp_cfg_fec_get");
1209 mpls_lock_get(global->global_lock); /* LOCK */
1211 if (flag & LDP_FEC_CFG_BY_INDEX) {
1212 ldp_global_find_fec_index(global, f->index, &fec);
1213 } else {
1214 fec = ldp_fec_find(global, f);
1216 if (!fec)
1217 goto ldp_cfg_fec_get_end;
1219 memcpy(f, &fec->info, sizeof(mpls_fec));
1220 f->index = fec->index;
1221 retval = MPLS_SUCCESS;
1223 ldp_cfg_fec_get_end:
1224 mpls_lock_release(global->global_lock); /* UNLOCK */
1226 LDP_EXIT(global->user_data, "ldp_cfg_fec_get");
1228 return retval;
1231 mpls_return_enum ldp_cfg_fec_getnext(mpls_cfg_handle handle, mpls_fec * f,
1232 uint32_t flag)
1234 ldp_global *g = (ldp_global *) handle;
1235 ldp_fec *fec = NULL;
1236 mpls_return_enum r = MPLS_FAILURE;
1237 mpls_bool done = MPLS_BOOL_FALSE;
1238 int index;
1240 LDP_ENTER(g->user_data, "ldp_cfg_fec_getnext");
1242 if (f->index == 0) {
1243 index = 1;
1244 } else {
1245 index = f->index + 1;
1248 mpls_lock_get(g->global_lock); /* LOCK */
1249 while (done == MPLS_BOOL_FALSE) {
1250 switch ((r = ldp_global_find_fec_index(g, index, &fec))) {
1251 case MPLS_SUCCESS:
1252 case MPLS_END_OF_LIST:
1253 done = MPLS_BOOL_TRUE;
1254 break;
1255 case MPLS_FAILURE:
1256 break;
1257 default:
1258 MPLS_ASSERT(0);
1260 index++;
1262 mpls_lock_release(g->global_lock); /* UNLOCK */
1264 if (r == MPLS_SUCCESS) {
1265 f->index = fec->index;
1266 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1267 return ldp_cfg_fec_get(g, f, flag);
1269 LDP_EXIT(g->user_data, "ldp_cfg_fec_getnext");
1270 return r;
1273 mpls_return_enum ldp_cfg_fec_test(mpls_cfg_handle handle, mpls_fec * f,
1274 uint32_t flag)
1276 // ldp_global* g = (ldp_global*)handle;
1277 return MPLS_SUCCESS;
1280 mpls_return_enum ldp_cfg_fec_set(mpls_cfg_handle handle, mpls_fec * f,
1281 uint32_t flag)
1283 ldp_global *global = (ldp_global *) handle;
1284 ldp_fec *fec = NULL;
1285 mpls_return_enum retval = MPLS_FAILURE;
1287 MPLS_ASSERT(global !=NULL && f != NULL);
1289 LDP_ENTER(global->user_data, "ldp_cfg_fec_set");
1291 mpls_lock_get(global->global_lock); /* LOCK */
1293 if (flag & LDP_CFG_ADD) {
1294 if (ldp_fec_find(global, f) || (fec = ldp_fec_create()) == NULL) {
1295 goto ldp_cfg_fec_set_end;
1297 f->index = fec->index;
1298 mpls_fec2ldp_fec(f, fec);
1299 _ldp_global_add_fec(global, fec);
1300 ldp_fec_insert2(global, fec);
1301 } else {
1302 if (flag & LDP_FEC_CFG_BY_INDEX) {
1303 ldp_global_find_fec_index(global, f->index, &fec);
1304 } else {
1305 fec = ldp_fec_find(global, f);
1309 if (fec == NULL) {
1310 LDP_PRINT(global->user_data, "ldp_cfg_fec_set: no such fec\n");
1311 goto ldp_cfg_fec_set_end;
1314 if (flag & LDP_CFG_DEL) {
1315 ldp_fec_remove(global,&fec->info);
1316 _ldp_global_del_fec(global, fec);
1319 retval = MPLS_SUCCESS;
1321 ldp_cfg_fec_set_end:
1322 mpls_lock_release(global->global_lock); /* UNLOCK */
1324 LDP_EXIT(global->user_data, "ldp_cfg_fec_set");
1326 return retval;
1329 mpls_return_enum ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle, mpls_fec * f,
1330 mpls_nexthop *n, uint32_t flag)
1332 ldp_global *global = (ldp_global *) handle;
1333 ldp_fec *fec = NULL;
1334 ldp_nexthop *nh = NULL;
1335 mpls_return_enum retval = MPLS_FAILURE;
1337 MPLS_ASSERT(global !=NULL && f != NULL);
1339 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_get");
1341 mpls_lock_get(global->global_lock); /* LOCK */
1343 if (flag & LDP_FEC_CFG_BY_INDEX) {
1344 ldp_global_find_fec_index(global, f->index, &fec);
1345 } else {
1346 fec = ldp_fec_find(global, f);
1348 if (!fec)
1349 goto ldp_cfg_fec_nexthop_get_end;
1351 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1352 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1353 } else {
1354 nh = ldp_fec_nexthop_find(fec, n);
1356 if (!nh)
1357 goto ldp_cfg_fec_nexthop_get_end;
1359 memcpy(n, &nh->info, sizeof(mpls_nexthop));
1360 n->index = nh->index;
1361 retval = MPLS_SUCCESS;
1363 ldp_cfg_fec_nexthop_get_end:
1364 mpls_lock_release(global->global_lock); /* UNLOCK */
1366 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_get");
1368 return retval;
1371 mpls_return_enum ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle,
1372 mpls_fec * f, mpls_nexthop *n, uint32_t flag)
1374 ldp_global *global = (ldp_global *) handle;
1375 ldp_fec *fec = NULL;
1376 ldp_nexthop *nh = NULL;
1377 mpls_return_enum r = MPLS_FAILURE;
1378 mpls_bool done = MPLS_BOOL_FALSE;
1379 int index;
1381 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1383 if (n->index == 0) {
1384 index = 1;
1385 } else {
1386 index = n->index + 1;
1389 mpls_lock_get(global->global_lock); /* LOCK */
1391 if (flag & LDP_FEC_CFG_BY_INDEX) {
1392 ldp_global_find_fec_index(global, f->index, &fec);
1393 } else {
1394 fec = ldp_fec_find(global, f);
1396 if (!fec)
1397 goto ldp_cfg_fec_nexthop_getnext_end;
1399 while (done == MPLS_BOOL_FALSE) {
1400 switch ((r = ldp_fec_find_nexthop_index(fec, index, &nh))) {
1401 case MPLS_SUCCESS:
1402 case MPLS_END_OF_LIST:
1403 done = MPLS_BOOL_TRUE;
1404 break;
1405 case MPLS_FAILURE:
1406 break;
1407 default:
1408 MPLS_ASSERT(0);
1410 index++;
1412 mpls_lock_release(global->global_lock); /* UNLOCK */
1414 if (r == MPLS_SUCCESS) {
1415 n->index = nh->index;
1416 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1417 return ldp_cfg_fec_nexthop_get(global, f, n, flag);
1420 ldp_cfg_fec_nexthop_getnext_end:
1422 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_getnext");
1423 return r;
1426 mpls_return_enum ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle, mpls_fec * f,
1427 mpls_nexthop *n, uint32_t flag)
1429 // ldp_global* g = (ldp_global*)handle;
1430 return MPLS_SUCCESS;
1433 mpls_return_enum ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle, mpls_fec * f,
1434 mpls_nexthop *n, uint32_t flag)
1436 ldp_global *global = (ldp_global *) handle;
1437 ldp_fec *fec = NULL;
1438 ldp_nexthop *nh = NULL;
1439 mpls_return_enum retval = MPLS_FAILURE;
1441 MPLS_ASSERT(global !=NULL && f != NULL && n != NULL);
1443 LDP_ENTER(global->user_data, "ldp_cfg_fec_nexthop_set");
1445 mpls_lock_get(global->global_lock); /* LOCK */
1447 if (flag & LDP_FEC_CFG_BY_INDEX) {
1448 ldp_global_find_fec_index(global, f->index, &fec);
1449 } else {
1450 fec = ldp_fec_find(global, f);
1452 if (!fec)
1453 goto ldp_cfg_fec_nexthop_set_end;
1455 if (flag & LDP_CFG_ADD) {
1456 if (ldp_fec_nexthop_find(fec, n) || (nh = ldp_nexthop_create()) == NULL) {
1457 goto ldp_cfg_fec_nexthop_set_end;
1459 n->index = nh->index;
1460 mpls_nexthop2ldp_nexthop(n, nh);
1461 _ldp_global_add_nexthop(global, nh);
1462 ldp_fec_add_nexthop(global, fec, nh);
1463 } else {
1464 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1465 ldp_fec_find_nexthop_index(fec, n->index, &nh);
1466 } else {
1467 nh = ldp_fec_nexthop_find(fec, n);
1471 if (nh == NULL) {
1472 LDP_PRINT(global->user_data, "ldp_cfg_fec_nexthop_set: no such nh\n");
1473 goto ldp_cfg_fec_nexthop_set_end;
1476 if (flag & LDP_CFG_DEL) {
1477 ldp_fec_del_nexthop(global, fec, nh);
1478 _ldp_global_del_nexthop(global, nh);
1481 retval = MPLS_SUCCESS;
1483 ldp_cfg_fec_nexthop_set_end:
1484 mpls_lock_release(global->global_lock); /* UNLOCK */
1486 LDP_EXIT(global->user_data, "ldp_cfg_fec_nexthop_set");
1488 return retval;
1491 /******************* ADDR **********************/
1493 mpls_return_enum ldp_cfg_if_addr_get(mpls_cfg_handle handle, ldp_if * i,
1494 ldp_addr * a, uint32_t flag)
1496 ldp_global *global = (ldp_global *) handle;
1497 ldp_addr *addr = NULL;
1498 ldp_if *iff = NULL;
1499 mpls_return_enum retval = MPLS_FAILURE;
1501 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1503 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_get");
1505 mpls_lock_get(global->global_lock); /* LOCK */
1507 if (flag & LDP_IF_CFG_BY_INDEX) {
1508 ldp_global_find_if_index(global, i->index, &iff);
1509 } else {
1510 iff = ldp_global_find_if_handle(global, i->handle);
1512 if (!iff)
1513 goto ldp_cfg_if_addr_get_end;
1515 if (flag & LDP_IF_ADDR_CFG_BY_INDEX) {
1516 ldp_if_find_addr_index(iff, a->index, &addr);
1517 } else {
1518 addr = ldp_if_addr_find(iff, &a->address);
1520 if (!addr)
1521 goto ldp_cfg_if_addr_get_end;
1523 memcpy(&a->address, &addr->address, sizeof(mpls_inet_addr));
1524 a->index = addr->index;
1526 retval = MPLS_SUCCESS;
1528 ldp_cfg_if_addr_get_end:
1529 mpls_lock_release(global->global_lock); /* UNLOCK */
1531 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_get");
1533 return retval;
1536 mpls_return_enum ldp_cfg_if_addr_getnext(mpls_cfg_handle handle,
1537 ldp_if * i, ldp_addr *a, uint32_t flag)
1539 ldp_global *global = (ldp_global *) handle;
1540 ldp_if *iff = NULL;
1541 ldp_addr *addr = NULL;
1542 mpls_return_enum r = MPLS_FAILURE;
1543 mpls_bool done = MPLS_BOOL_FALSE;
1544 int index;
1546 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_getnext");
1548 if (a->index == 0) {
1549 index = 1;
1550 } else {
1551 index = a->index + 1;
1554 mpls_lock_get(global->global_lock); /* LOCK */
1556 if (flag & LDP_IF_CFG_BY_INDEX) {
1557 ldp_global_find_if_index(global, i->index, &iff);
1558 } else {
1559 iff = ldp_global_find_if_handle(global, i->handle);
1561 if (!iff)
1562 goto ldp_cfg_if_addr_getnext_end;
1564 while (done == MPLS_BOOL_FALSE) {
1565 switch ((r = ldp_if_find_addr_index(iff, index, &addr))) {
1566 case MPLS_SUCCESS:
1567 case MPLS_END_OF_LIST:
1568 done = MPLS_BOOL_TRUE;
1569 break;
1570 case MPLS_FAILURE:
1571 break;
1572 default:
1573 MPLS_ASSERT(0);
1575 index++;
1577 mpls_lock_release(global->global_lock); /* UNLOCK */
1579 if (r == MPLS_SUCCESS) {
1580 a->index = addr->index;
1581 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1582 return ldp_cfg_if_addr_get(global, i, a, flag);
1585 ldp_cfg_if_addr_getnext_end:
1587 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_getnext");
1588 return r;
1591 mpls_return_enum ldp_cfg_if_addr_set(mpls_cfg_handle handle, ldp_if * i,
1592 ldp_addr *a, uint32_t flag)
1594 ldp_global *global = (ldp_global *) handle;
1595 ldp_if *iff = NULL;
1596 ldp_addr *addr = NULL;
1597 mpls_return_enum retval = MPLS_FAILURE;
1599 MPLS_ASSERT(global !=NULL && i != NULL && a != NULL);
1601 LDP_ENTER(global->user_data, "ldp_cfg_if_addr_set");
1603 mpls_lock_get(global->global_lock); /* LOCK */
1605 if (flag & LDP_FEC_CFG_BY_INDEX) {
1606 ldp_global_find_if_index(global, i->index, &iff);
1607 } else {
1608 iff = ldp_global_find_if_handle(global, i->handle);
1610 if (!iff)
1611 goto ldp_cfg_if_addr_set_end;
1613 if (flag & LDP_CFG_ADD) {
1614 if (ldp_if_addr_find(iff, &a->address) || (addr = ldp_addr_create(global,
1615 &a->address)) == NULL) {
1616 goto ldp_cfg_if_addr_set_end;
1618 a->index = addr->index;
1619 ldp_if_add_addr(iff, addr);
1620 } else {
1621 if (flag & LDP_FEC_NEXTHOP_CFG_BY_INDEX) {
1622 ldp_if_find_addr_index(iff, a->index, &addr);
1623 } else {
1624 fprintf(stderr, "ldp_cfg_if_addr_set: iff = %p\n", iff);
1625 addr = ldp_if_addr_find(iff, &a->address);
1629 if (addr == NULL) {
1630 LDP_PRINT(global->user_data, "ldp_cfg_if_addr_set: no such addr\n");
1631 goto ldp_cfg_if_addr_set_end;
1634 if (flag & LDP_CFG_DEL) {
1635 ldp_if_del_addr(global, iff ,addr);
1638 retval = MPLS_SUCCESS;
1640 ldp_cfg_if_addr_set_end:
1641 mpls_lock_release(global->global_lock); /* UNLOCK */
1643 LDP_EXIT(global->user_data, "ldp_cfg_if_addr_set");
1645 return retval;
1648 /******************* ADJACENCY **********************/
1650 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1651 uint32_t flag)
1653 ldp_global *global = (ldp_global *) handle;
1654 ldp_adj *adj = NULL;
1655 mpls_return_enum retval = MPLS_FAILURE;
1657 MPLS_ASSERT(global !=NULL && a != NULL);
1659 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1661 mpls_lock_get(global->global_lock); /* LOCK */
1663 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1664 goto ldp_cfg_adj_get_end;
1666 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1667 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1668 sizeof(mpls_inet_addr));
1670 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1671 memcpy(&a->remote_source_address, &adj->remote_source_address,
1672 sizeof(mpls_inet_addr));
1674 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1675 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1676 sizeof(mpls_inet_addr));
1678 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1679 a->remote_csn = adj->remote_csn;
1681 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1682 a->remote_label_space = adj->remote_label_space;
1684 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1685 a->remote_hellotime = adj->remote_hellotime;
1687 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1688 a->entity_index = adj->entity ? adj->entity->index : 0;
1690 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1691 a->session_index = (adj->session) ? (adj->session->index) : 0;
1693 if (flag & LDP_ADJ_CFG_ROLE) {
1694 a->role = adj->role;
1696 retval = MPLS_SUCCESS;
1698 ldp_cfg_adj_get_end:
1700 mpls_lock_release(global->global_lock); /* UNLOCK */
1702 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1704 return retval;
1707 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1708 uint32_t flag)
1710 ldp_global *g = (ldp_global *) handle;
1711 ldp_adj *adj = NULL;
1712 mpls_return_enum r = MPLS_FAILURE;
1713 mpls_bool done = MPLS_BOOL_FALSE;
1714 int index;
1716 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1718 if (a->index == 0) {
1719 index = 1;
1720 } else {
1721 index = a->index + 1;
1724 mpls_lock_get(g->global_lock); /* LOCK */
1725 while (done == MPLS_BOOL_FALSE) {
1726 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1727 case MPLS_SUCCESS:
1728 case MPLS_END_OF_LIST:
1729 done = MPLS_BOOL_TRUE;
1730 break;
1731 case MPLS_FAILURE:
1732 break;
1733 default:
1734 MPLS_ASSERT(0);
1736 index++;
1738 mpls_lock_release(g->global_lock); /* UNLOCK */
1740 if (r == MPLS_SUCCESS) {
1741 a->index = adj->index;
1742 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1743 return ldp_cfg_adj_get(g, a, flag);
1745 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1746 return r;
1749 /******************* SESSION **********************/
1751 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1752 uint32_t flag)
1754 ldp_global *global = (ldp_global *) handle;
1755 ldp_session *session = NULL;
1756 mpls_return_enum retval = MPLS_FAILURE;
1758 MPLS_ASSERT(global !=NULL && s != NULL);
1760 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1762 mpls_lock_get(global->global_lock); /* LOCK */
1764 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1765 goto ldp_cfg_session_get_end;
1767 if (flag & LDP_SESSION_CFG_STATE) {
1768 s->state = session->state;
1770 if (flag & LDP_SESSION_CFG_OPER_UP) {
1771 s->oper_up = session->oper_up;
1773 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1774 s->oper_max_pdu = session->oper_max_pdu;
1776 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1777 s->oper_keepalive = session->oper_keepalive;
1779 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1780 s->oper_path_vector_limit = session->oper_path_vector_limit;
1782 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1783 s->oper_distribution_mode = session->oper_distribution_mode;
1785 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1786 s->oper_loop_detection = session->oper_loop_detection;
1788 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1789 s->remote_max_pdu = session->remote_max_pdu;
1791 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1792 s->remote_keepalive = session->remote_keepalive;
1794 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1795 s->remote_path_vector_limit = session->remote_path_vector_limit;
1797 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1798 s->remote_distribution_mode = session->remote_distribution_mode;
1800 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1801 s->remote_loop_detection = session->remote_loop_detection;
1803 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1804 s->remote_dest.addr.type = session->remote_dest.addr.type;
1805 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1807 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1808 s->remote_dest.port = session->remote_dest.port;
1810 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1811 s->no_label_resource_sent = session->no_label_resource_sent;
1813 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1814 s->no_label_resource_recv = session->no_label_resource_recv;
1816 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1817 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1818 s->adj_index = a ? a->index : 0;
1820 if (flag & LDP_SESSION_CFG_MESG_TX) {
1821 s->mesg_tx = session->mesg_tx;
1823 if (flag & LDP_SESSION_CFG_MESG_RX) {
1824 s->mesg_rx = session->mesg_rx;
1826 retval = MPLS_SUCCESS;
1828 ldp_cfg_session_get_end:
1829 mpls_lock_release(global->global_lock); /* UNLOCK */
1831 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1833 return retval;
1836 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1837 uint32_t flag)
1839 ldp_global *g = (ldp_global *) handle;
1840 ldp_session *ses = NULL;
1841 mpls_return_enum r = MPLS_FAILURE;
1842 mpls_bool done = MPLS_BOOL_FALSE;
1843 int index;
1845 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1847 if (s->index == 0) {
1848 index = 1;
1849 } else {
1850 index = s->index + 1;
1853 mpls_lock_get(g->global_lock); /* LOCK */
1854 while (done == MPLS_BOOL_FALSE) {
1855 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1856 case MPLS_SUCCESS:
1857 case MPLS_END_OF_LIST:
1858 done = MPLS_BOOL_TRUE;
1859 break;
1860 case MPLS_FAILURE:
1861 break;
1862 default:
1863 MPLS_ASSERT(0);
1865 index++;
1867 mpls_lock_release(g->global_lock); /* UNLOCK */
1869 if (r == MPLS_SUCCESS) {
1870 s->index = ses->index;
1872 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1873 return ldp_cfg_session_get(g, s, flag);
1876 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1878 return r;
1881 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1882 ldp_session * s)
1884 ldp_global *g = (ldp_global *) handle;
1885 mpls_bool this_one = MPLS_BOOL_FALSE;
1886 mpls_return_enum r = MPLS_FAILURE;
1887 ldp_adj *adj_next = NULL;
1888 ldp_adj *adj = NULL;
1889 ldp_session *session = NULL;
1891 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
1893 /* if an adj_index of zero is sent, get the index of
1894 * the first adj in the list
1896 if (!s->adj_index) {
1897 this_one = MPLS_BOOL_TRUE;
1900 mpls_lock_get(g->global_lock); /* LOCK */
1902 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
1903 adj = MPLS_LIST_HEAD(&session->adj_root);
1904 while (adj) {
1905 if (this_one == MPLS_BOOL_TRUE) {
1906 adj_next = adj;
1907 break;
1910 /* since the entities are sort in the list ... */
1911 if (adj->index > s->adj_index) {
1912 break;
1913 } else if (adj->index == s->adj_index) {
1914 this_one = MPLS_BOOL_TRUE;
1916 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
1919 mpls_lock_release(g->global_lock); /* UNLOCK */
1921 if (adj_next) {
1922 s->adj_index = adj_next->index;
1923 r = MPLS_SUCCESS;
1926 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
1927 return r;
1930 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
1931 ldp_session * s, ldp_addr * a, uint32_t flag)
1933 ldp_global *global = (ldp_global *) handle;
1934 ldp_session *session = NULL;
1935 ldp_addr *addr = NULL;
1936 mpls_return_enum retval = MPLS_FAILURE;
1938 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
1940 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
1942 mpls_lock_get(global->global_lock); /* LOCK */
1944 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1945 goto ldp_cfg_session_raddr_get_end;
1947 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
1948 goto ldp_cfg_session_raddr_get_end;
1950 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
1951 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
1953 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
1954 a->index = addr->index;
1956 retval = MPLS_SUCCESS;
1958 ldp_cfg_session_raddr_get_end:
1959 mpls_lock_release(global->global_lock); /* UNLOCK */
1961 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
1963 return retval;
1966 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
1967 ldp_session * s, ldp_addr * a, uint32_t flag)
1969 ldp_global *g = (ldp_global *) handle;
1970 ldp_addr *addr = NULL;
1971 mpls_return_enum r = MPLS_FAILURE;
1972 mpls_bool done = MPLS_BOOL_FALSE;
1973 ldp_session *sp = NULL;
1974 int index;
1976 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
1978 if (a->index == 0) {
1979 index = 1;
1980 } else {
1981 index = a->index + 1;
1984 r = ldp_global_find_session_index(g, s->index, &sp);
1985 if (r != MPLS_SUCCESS) {
1986 return r;
1989 mpls_lock_get(g->global_lock); /* LOCK */
1990 while (done == MPLS_BOOL_FALSE) {
1991 switch ((r = ldp_session_find_raddr_index(sp, index, &addr))) {
1992 case MPLS_SUCCESS:
1993 case MPLS_END_OF_LIST:
1994 done = MPLS_BOOL_TRUE;
1995 break;
1996 case MPLS_FAILURE:
1997 break;
1998 default:
1999 MPLS_ASSERT(0);
2001 index++;
2003 mpls_lock_release(g->global_lock); /* UNLOCK */
2005 if (r == MPLS_SUCCESS) {
2006 a->index = addr->index;
2007 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
2010 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
2011 return r;
2014 /******************* IN LABEL **********************/
2016 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
2017 uint32_t flag)
2019 ldp_global *global = (ldp_global *) handle;
2020 ldp_inlabel *inlabel = NULL;
2021 mpls_return_enum retval = MPLS_FAILURE;
2023 MPLS_ASSERT(global !=NULL && i != NULL);
2025 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
2027 mpls_lock_get(global->global_lock); /* LOCK */
2029 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
2030 goto ldp_cfg_inlabel_get_end;
2032 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
2033 i->info.labelspace = inlabel->info.labelspace;
2035 if (flag & LDP_INLABEL_CFG_LABEL) {
2036 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
2038 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
2039 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
2042 retval = MPLS_SUCCESS;
2044 ldp_cfg_inlabel_get_end:
2045 mpls_lock_release(global->global_lock); /* UNLOCK */
2047 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
2049 return retval;
2052 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
2053 uint32_t flag)
2055 ldp_global *g = (ldp_global *) handle;
2056 ldp_inlabel *inlabel = NULL;
2057 mpls_return_enum r = MPLS_FAILURE;
2058 mpls_bool done = MPLS_BOOL_FALSE;
2059 int index;
2061 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
2063 if (i->index == 0) {
2064 index = 1;
2065 } else {
2066 index = i->index + 1;
2069 mpls_lock_get(g->global_lock); /* LOCK */
2070 while (done == MPLS_BOOL_FALSE) {
2071 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
2072 case MPLS_SUCCESS:
2073 case MPLS_END_OF_LIST:
2074 done = MPLS_BOOL_TRUE;
2075 break;
2076 case MPLS_FAILURE:
2077 break;
2078 default:
2079 MPLS_ASSERT(0);
2081 index++;
2083 mpls_lock_release(g->global_lock); /* UNLOCK */
2085 if (r == MPLS_SUCCESS) {
2086 i->index = inlabel->index;
2088 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2089 return ldp_cfg_inlabel_get(g, i, flag);
2092 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
2094 return r;
2097 /******************* OUT LABEL **********************/
2099 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
2100 uint32_t flag)
2102 ldp_global *global = (ldp_global *) handle;
2103 ldp_outlabel *outlabel = NULL;
2104 mpls_return_enum retval = MPLS_FAILURE;
2106 MPLS_ASSERT(global !=NULL && o != NULL);
2108 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
2110 mpls_lock_get(global->global_lock); /* LOCK */
2112 if (ldp_global_find_outlabel_index(global, o->index,
2113 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
2115 if (flag & LDP_OUTLABEL_CFG_NH_INDEX) {
2116 if (outlabel->nh) {
2117 o->nh_index = outlabel->nh->index;
2118 } else {
2119 o->nh_index = 0;
2122 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
2123 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
2125 if (flag & LDP_OUTLABEL_CFG_LABEL) {
2126 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
2128 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
2129 o->merge_count = outlabel->merge_count;
2132 retval = MPLS_SUCCESS;
2134 ldp_cfg_outlabel_get_end:
2135 mpls_lock_release(global->global_lock); /* UNLOCK */
2137 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
2139 return retval;
2142 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
2143 ldp_outlabel * o, uint32_t flag)
2145 ldp_global *g = (ldp_global *) handle;
2146 ldp_outlabel *outlabel = NULL;
2147 mpls_return_enum r = MPLS_FAILURE;
2148 mpls_bool done = MPLS_BOOL_FALSE;
2149 int index;
2151 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
2153 if (o->index == 0) {
2154 index = 1;
2155 } else {
2156 index = o->index + 1;
2159 mpls_lock_get(g->global_lock); /* LOCK */
2160 while (done == MPLS_BOOL_FALSE) {
2161 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
2162 case MPLS_SUCCESS:
2163 case MPLS_END_OF_LIST:
2164 done = MPLS_BOOL_TRUE;
2165 break;
2166 case MPLS_FAILURE:
2167 break;
2168 default:
2169 MPLS_ASSERT(0);
2171 index++;
2173 mpls_lock_release(g->global_lock); /* UNLOCK */
2175 if (r == MPLS_SUCCESS) {
2176 o->index = outlabel->index;
2178 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2179 return ldp_cfg_outlabel_get(g, o, flag);
2182 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
2184 return r;
2187 /******************* TUNNEL **********************/
2189 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
2190 uint32_t flag)
2192 ldp_global *global = (ldp_global *) handle;
2193 mpls_return_enum retval = MPLS_FAILURE;
2194 ldp_tunnel *tunnel = NULL;
2196 MPLS_ASSERT(global !=NULL);
2198 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
2200 mpls_lock_get(global->global_lock); /* LOCK */
2202 if (flag & LDP_CFG_ADD) {
2203 if (!(tunnel = ldp_tunnel_create())) {
2204 goto ldp_cfg_tunnel_set_end;
2206 _ldp_global_add_tunnel(global, tunnel);
2208 t->index = tunnel->index;
2209 } else {
2210 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2213 if (!tunnel) {
2214 LDP_PRINT(global->user_data,
2216 "ldp_cfg_tunnel_set:could not create tunnel\n");
2217 goto ldp_cfg_tunnel_set_end;
2220 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
2221 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
2222 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
2224 goto ldp_cfg_tunnel_set_end;
2227 if (flag & LDP_CFG_DEL) {
2228 if (tunnel->outlabel)
2229 ldp_tunnel_del_outlabel(tunnel);
2230 if (tunnel->resource)
2231 ldp_tunnel_del_resource(tunnel);
2232 if (tunnel->hop_list)
2233 ldp_tunnel_del_hop_list(tunnel);
2234 _ldp_global_del_tunnel(global, tunnel);
2236 retval = MPLS_SUCCESS;
2237 goto ldp_cfg_tunnel_set_end;
2240 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2241 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
2243 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2244 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
2246 if (flag & LDP_TUNNEL_CFG_NAME) {
2247 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
2249 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2250 tunnel->is_interface = t->is_interface;
2252 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2253 ldp_outlabel *outlabel = NULL;
2255 if (t->outlabel_index) {
2256 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2258 if (!outlabel) {
2259 goto ldp_cfg_tunnel_set_end;
2261 ldp_tunnel_add_outlabel(tunnel, outlabel);
2262 } else {
2263 ldp_tunnel_del_outlabel(tunnel);
2266 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2267 tunnel->setup_prio = t->setup_prio;
2269 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2270 tunnel->hold_prio = t->hold_prio;
2272 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2273 tunnel->instance_prio = t->instance_prio;
2275 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2276 tunnel->local_protect = t->local_protect;
2278 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2279 ldp_resource *resource = NULL;
2281 if (t->resource_index) {
2282 ldp_global_find_resource_index(global, t->resource_index, &resource);
2284 if (!resource) {
2285 goto ldp_cfg_tunnel_set_end;
2287 ldp_tunnel_add_resource(tunnel, resource);
2288 } else {
2289 ldp_tunnel_del_resource(tunnel);
2292 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2293 ldp_hop_list *hop_list = NULL;
2295 if (t->hop_list_index) {
2296 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2298 if (!hop_list) {
2299 goto ldp_cfg_tunnel_set_end;
2301 ldp_tunnel_add_hop_list(tunnel, hop_list);
2302 } else {
2303 ldp_tunnel_del_hop_list(tunnel);
2306 if (flag & LDP_TUNNEL_CFG_FEC) {
2307 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
2309 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2310 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
2311 if (t->admin_state == MPLS_ADMIN_DISABLE) {
2312 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
2313 goto ldp_cfg_tunnel_set_end;
2316 } else {
2317 if (t->admin_state == MPLS_ADMIN_ENABLE) {
2318 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
2319 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
2320 goto ldp_cfg_tunnel_set_end;
2322 } else {
2323 LDP_PRINT(global->user_data,
2325 "ldp_cfg_tunnel_set: tunnel not ready\n");
2326 goto ldp_cfg_tunnel_set_end;
2331 retval = MPLS_SUCCESS;
2333 ldp_cfg_tunnel_set_end:
2335 mpls_lock_release(global->global_lock); /* UNLOCK */
2337 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2339 return retval;
2342 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2343 uint32_t flag)
2345 ldp_global *global = (ldp_global *) handle;
2346 mpls_return_enum retval = MPLS_FAILURE;
2347 ldp_tunnel *tunnel = NULL;
2349 MPLS_ASSERT(global !=NULL);
2351 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2353 mpls_lock_get(global->global_lock); /* LOCK */
2355 if (flag & LDP_CFG_ADD) {
2356 retval = MPLS_SUCCESS;
2357 goto ldp_cfg_tunnel_test_end;
2360 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2362 if (!tunnel) {
2363 goto ldp_cfg_tunnel_test_end;
2366 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2367 ldp_resource *resource = NULL;
2369 if (t->resource_index) {
2370 ldp_global_find_resource_index(global, t->resource_index, &resource);
2372 if (!resource) {
2373 goto ldp_cfg_tunnel_test_end;
2377 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2378 ldp_hop_list *hop_list = NULL;
2380 if (t->hop_list_index) {
2381 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2383 if (!hop_list) {
2384 goto ldp_cfg_tunnel_test_end;
2388 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2389 ldp_outlabel *outlabel = NULL;
2391 if (t->outlabel_index) {
2392 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2394 if (!outlabel) {
2395 goto ldp_cfg_tunnel_test_end;
2399 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2400 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2401 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2402 goto ldp_cfg_tunnel_test_end;
2404 retval = MPLS_SUCCESS;
2406 ldp_cfg_tunnel_test_end:
2408 mpls_lock_release(global->global_lock); /* UNLOCK */
2410 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2412 return retval;
2415 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2416 uint32_t flag)
2418 ldp_global *global = (ldp_global *) handle;
2419 mpls_return_enum retval = MPLS_FAILURE;
2420 ldp_tunnel *tunnel = NULL;
2422 MPLS_ASSERT(global !=NULL);
2424 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2426 mpls_lock_get(global->global_lock); /* LOCK */
2428 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2430 if (!tunnel) {
2431 goto ldp_cfg_tunnel_get_end;
2433 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2434 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2436 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2437 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2439 if (flag & LDP_TUNNEL_CFG_NAME) {
2440 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2442 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2443 t->is_interface = tunnel->is_interface;
2445 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2446 if (tunnel->outlabel) {
2447 t->outlabel_index = tunnel->outlabel->index;
2448 } else {
2449 t->outlabel_index = 0;
2452 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2453 t->setup_prio = tunnel->setup_prio;
2455 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2456 t->hold_prio = tunnel->hold_prio;
2458 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2459 tunnel->instance_prio = t->instance_prio;
2461 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2462 tunnel->local_protect = t->local_protect;
2464 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2465 if (tunnel->resource) {
2466 t->resource_index = tunnel->resource->index;
2467 } else {
2468 t->resource_index = 0;
2471 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2472 if (tunnel->hop_list) {
2473 t->hop_list_index = tunnel->hop_list->index;
2474 } else {
2475 t->hop_list_index = 0;
2478 if (flag & LDP_TUNNEL_CFG_FEC) {
2479 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2481 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2482 t->admin_state = tunnel->admin_state;
2484 retval = MPLS_SUCCESS;
2486 ldp_cfg_tunnel_get_end:
2488 mpls_lock_release(global->global_lock); /* UNLOCK */
2490 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2492 return retval;
2495 /******************* RESOURCE **********************/
2497 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2498 uint32_t flag)
2500 ldp_global *global = (ldp_global *) handle;
2501 mpls_return_enum retval = MPLS_FAILURE;
2502 ldp_resource *resource = NULL;
2504 MPLS_ASSERT(global !=NULL);
2506 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2508 mpls_lock_get(global->global_lock); /* LOCK */
2510 if (flag & LDP_CFG_ADD) {
2511 resource = ldp_resource_create();
2512 _ldp_global_add_resource(global, resource);
2514 r->index = resource->index;
2515 } else {
2516 ldp_global_find_resource_index(global, r->index, &resource);
2519 if (!resource) {
2520 goto ldp_cfg_resource_set_end;
2523 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2524 resource->max_rate = r->max_rate;
2526 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2527 resource->mean_rate = r->mean_rate;
2529 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2530 resource->burst_size = r->burst_size;
2532 retval = MPLS_SUCCESS;
2534 ldp_cfg_resource_set_end:
2536 mpls_lock_release(global->global_lock); /* UNLOCK */
2538 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2540 return retval;
2543 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2544 uint32_t flag)
2546 ldp_global *global = (ldp_global *) handle;
2547 mpls_return_enum retval = MPLS_FAILURE;
2548 ldp_resource *resource = NULL;
2550 MPLS_ASSERT(global !=NULL);
2552 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2554 mpls_lock_get(global->global_lock); /* LOCK */
2556 if (flag & LDP_CFG_ADD) {
2557 retval = MPLS_SUCCESS;
2558 goto ldp_cfg_resource_test_end;
2561 ldp_global_find_resource_index(global, r->index, &resource);
2563 if (!resource) {
2564 goto ldp_cfg_resource_test_end;
2567 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2568 goto ldp_cfg_resource_test_end;
2570 retval = MPLS_SUCCESS;
2572 ldp_cfg_resource_test_end:
2574 mpls_lock_release(global->global_lock); /* UNLOCK */
2576 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2578 return retval;
2581 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2582 uint32_t flag)
2584 ldp_global *global = (ldp_global *) handle;
2585 mpls_return_enum retval = MPLS_FAILURE;
2586 ldp_resource *resource = NULL;
2588 MPLS_ASSERT(global !=NULL);
2590 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2592 mpls_lock_get(global->global_lock); /* LOCK */
2594 ldp_global_find_resource_index(global, r->index, &resource);
2596 if (!resource) {
2597 goto ldp_cfg_resource_get_end;
2600 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2601 r->max_rate = resource->max_rate;
2603 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2604 r->mean_rate = resource->mean_rate;
2606 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2607 r->burst_size = resource->burst_size;
2609 retval = MPLS_SUCCESS;
2611 ldp_cfg_resource_get_end:
2613 mpls_lock_release(global->global_lock); /* UNLOCK */
2615 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2617 return retval;
2620 /******************* HOP **********************/
2622 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2623 uint32_t flag)
2625 ldp_global *global = (ldp_global *) handle;
2626 mpls_return_enum retval = MPLS_FAILURE;
2627 ldp_hop_list *hop_list = NULL;
2628 ldp_hop *hop = NULL;
2630 MPLS_ASSERT(global !=NULL);
2632 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2634 if (!h->hop_list_index && !h->index) {
2635 return retval;
2638 mpls_lock_get(global->global_lock); /* LOCK */
2640 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2642 if (!hop_list) {
2643 if (flag & LDP_CFG_ADD) {
2644 if (!(hop_list = ldp_hop_list_create())) {
2645 goto ldp_cfg_hop_set_end;
2647 _ldp_global_add_hop_list(global, hop_list);
2649 h->hop_list_index = hop_list->index;
2650 } else {
2651 goto ldp_cfg_hop_set_end;
2655 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2656 if (!hop) {
2657 if (h->index && (flag & LDP_CFG_ADD)) {
2658 if (!(hop = ldp_hop_create())) {
2659 goto ldp_cfg_hop_set_end;
2661 hop->index = h->index;
2662 ldp_hop_list_add_hop(hop_list, hop);
2663 } else {
2664 goto ldp_cfg_hop_set_end;
2668 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2669 hop->path_option = h->path_option;
2671 if (flag & LDP_HOP_CFG_ADDR) {
2672 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2674 if (flag & LDP_HOP_CFG_TYPE) {
2675 hop->type = h->type;
2677 retval = MPLS_SUCCESS;
2679 ldp_cfg_hop_set_end:
2681 mpls_lock_release(global->global_lock); /* UNLOCK */
2683 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2685 return retval;
2688 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2689 uint32_t flag)
2691 ldp_global *global = (ldp_global *) handle;
2692 mpls_return_enum retval = MPLS_FAILURE;
2693 ldp_hop_list *hop_list = NULL;
2694 ldp_hop *hop = NULL;
2696 MPLS_ASSERT(global !=NULL);
2698 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2700 mpls_lock_get(global->global_lock); /* LOCK */
2702 if (flag & LDP_CFG_ADD) {
2703 retval = MPLS_SUCCESS;
2704 goto ldp_cfg_hop_test_end;
2707 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2709 if (!hop_list) {
2710 goto ldp_cfg_hop_test_end;
2713 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2714 if (!hop) {
2715 goto ldp_cfg_hop_test_end;
2718 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2719 goto ldp_cfg_hop_test_end;
2721 retval = MPLS_SUCCESS;
2723 ldp_cfg_hop_test_end:
2725 mpls_lock_release(global->global_lock); /* UNLOCK */
2727 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2729 return retval;
2732 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2733 uint32_t flag)
2735 ldp_global *global = (ldp_global *) handle;
2736 mpls_return_enum retval = MPLS_FAILURE;
2737 ldp_hop_list *hop_list = NULL;
2738 ldp_hop *hop = NULL;
2740 MPLS_ASSERT(global !=NULL);
2742 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2744 mpls_lock_get(global->global_lock); /* LOCK */
2746 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2748 if (!hop_list) {
2749 goto ldp_cfg_hop_get_end;
2752 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2753 if (!hop) {
2754 goto ldp_cfg_hop_get_end;
2757 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2758 h->path_option = hop->path_option;
2760 if (flag & LDP_HOP_CFG_ADDR) {
2761 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2763 if (flag & LDP_HOP_CFG_TYPE) {
2764 h->type = hop->type;
2766 retval = MPLS_SUCCESS;
2768 ldp_cfg_hop_get_end:
2770 mpls_lock_release(global->global_lock); /* UNLOCK */
2772 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2774 return retval;