If and when I implement RSVP-TE I need the naming scheme to make
[mpls-ldp-portable.git] / ldp / ldp_cfg.c
blob8bf54e42625a64031e1b7052c8cab4ac4f25a8d0
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_l2cc.h"
18 #include "ldp_tunnel.h"
19 #include "ldp_resource.h"
20 #include "mpls_ifmgr_impl.h"
21 #include "ldp_hop.h"
22 #include "ldp_hop_list.h"
23 #include "mpls_lock_impl.h"
24 #include "mpls_trace_impl.h"
25 #include "mpls_tree_impl.h"
27 mpls_cfg_handle ldp_cfg_open(mpls_instance_handle data)
29 ldp_global *g = ldp_global_create(data);
31 LDP_ENTER(data, "ldp_cfg_open");
32 LDP_EXIT(data, "ldp_cfg_open");
34 return (mpls_cfg_handle) g;
37 void ldp_cfg_close(mpls_cfg_handle g)
39 LDP_ENTER((mpls_instance_handle) g->user_data, "ldp_cfg_close");
40 ldp_global_delete(g);
41 LDP_EXIT((mpls_instance_handle) g->user_data, "ldp_cfg_close");
44 /******************* GLOBAL **********************/
46 mpls_return_enum ldp_cfg_global_get(mpls_cfg_handle handle, ldp_global * g,
47 uint32_t flag)
49 ldp_global *global = (ldp_global *) handle;
51 MPLS_ASSERT(global !=NULL);
53 LDP_ENTER(global->user_data, "ldp_cfg_global_get");
55 mpls_lock_get(global->global_lock); /* LOCK */
57 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
58 memcpy(&(g->lsr_identifier), &(global->lsr_identifier),
59 sizeof(mpls_inet_addr));
61 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
62 g->admin_state = global->admin_state;
64 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
65 g->lsp_control_mode = global->lsp_control_mode;
67 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
68 g->label_retention_mode = global->label_retention_mode;
70 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
71 g->lsp_repair_mode = global->lsp_repair_mode;
73 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
74 g->propagate_release = global->propagate_release;
76 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
77 g->label_merge = global->label_merge;
79 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
80 g->loop_detection_mode = global->loop_detection_mode;
82 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
83 g->ttl_less_domain = global->ttl_less_domain;
85 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
86 g->local_tcp_port = global->local_tcp_port;
88 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
89 g->local_udp_port = global->local_udp_port;
91 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
92 memcpy(&(g->transport_address), &(global->transport_address),
93 sizeof(mpls_inet_addr));
95 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
96 g->keepalive_timer = global->keepalive_timer;
98 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
99 g->keepalive_interval = global->keepalive_interval;
101 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
102 g->hellotime_timer = global->hellotime_timer;
104 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
105 g->hellotime_interval = global->hellotime_interval;
107 #if MPLS_USE_LSR
108 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
109 g->lsr_handle = global->lsr_handle;
111 #endif
113 mpls_lock_release(global->global_lock); /* UNLOCK */
115 LDP_EXIT(global->user_data, "ldp_cfg_global_get");
117 return MPLS_SUCCESS;
120 mpls_return_enum ldp_cfg_global_test(mpls_cfg_handle handle, ldp_global * g,
121 uint32_t flag)
123 ldp_global *global = (ldp_global *) handle;
124 mpls_return_enum retval = MPLS_SUCCESS;
126 MPLS_ASSERT(global !=NULL);
128 LDP_ENTER(global->user_data, "ldp_cfg_global_test");
130 mpls_lock_get(global->global_lock); /* LOCK */
132 if (global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN))
133 retval = MPLS_FAILURE;
135 mpls_lock_release(global->global_lock); /* UNLOCK */
137 LDP_EXIT(global->user_data, "ldp_cfg_global_test");
139 return retval;
142 mpls_return_enum ldp_cfg_global_set(mpls_cfg_handle handle, ldp_global * g,
143 uint32_t flag)
145 ldp_global *global = (ldp_global *) handle;
146 mpls_return_enum retval = MPLS_FAILURE;
148 MPLS_ASSERT(global !=NULL);
150 LDP_ENTER(global->user_data, "ldp_cfg_global_set");
152 mpls_lock_get(global->global_lock); /* LOCK */
154 if ((global->admin_state == MPLS_ADMIN_ENABLE && (flag & LDP_GLOBAL_CFG_WHEN_DOWN)))
155 goto ldp_cfg_global_set_end;
157 if (flag & LDP_GLOBAL_CFG_CONTROL_MODE) {
158 global->lsp_control_mode = g->lsp_control_mode;
160 if (flag & LDP_GLOBAL_CFG_RETENTION_MODE) {
161 global->label_retention_mode = g->label_retention_mode;
163 if (flag & LDP_GLOBAL_CFG_REPAIR_MODE) {
164 global->lsp_repair_mode = g->lsp_repair_mode;
166 if (flag & LDP_GLOBAL_CFG_PROPOGATE_RELEASE) {
167 global->propagate_release = g->propagate_release;
169 if (flag & LDP_GLOBAL_CFG_LABEL_MERGE) {
170 global->label_merge = g->label_merge;
172 if (flag & LDP_GLOBAL_CFG_LOOP_DETECTION_MODE) {
173 global->loop_detection_mode = g->loop_detection_mode;
175 if (flag & LDP_GLOBAL_CFG_TTLLESS_DOMAIN) {
176 global->ttl_less_domain = g->ttl_less_domain;
178 if (flag & LDP_GLOBAL_CFG_LOCAL_TCP_PORT) {
179 global->local_tcp_port = g->local_tcp_port;
181 if (flag & LDP_GLOBAL_CFG_LOCAL_UDP_PORT) {
182 global->local_udp_port = g->local_udp_port;
184 if (flag & LDP_GLOBAL_CFG_LSR_IDENTIFIER) {
185 memcpy(&(global->lsr_identifier), &(g->lsr_identifier),
186 sizeof(mpls_inet_addr));
188 #if MPLS_USE_LSR
189 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
190 global->lsr_handle = g->lsr_handle;
192 #endif
193 if (flag & LDP_GLOBAL_CFG_ADMIN_STATE) {
194 if (global->admin_state == MPLS_ADMIN_ENABLE && g->admin_state == MPLS_ADMIN_DISABLE) {
195 ldp_global_shutdown(global);
196 } else if (global->admin_state == MPLS_ADMIN_DISABLE && g->admin_state ==
197 MPLS_ADMIN_ENABLE) {
198 ldp_global_startup(global);
201 if (flag & LDP_GLOBAL_CFG_TRANS_ADDR) {
202 memcpy(&(global->transport_address), &(g->transport_address),
203 sizeof(mpls_inet_addr));
205 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_TIMER) {
206 if (g->keepalive_timer == 0) {
207 global->keepalive_timer = LDP_ENTITY_DEF_KEEPALIVE_TIMER;
208 } else {
209 global->keepalive_timer = g->keepalive_timer;
212 if (flag & LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL) {
213 if (g->keepalive_interval == 0) {
214 global->keepalive_interval = LDP_ENTITY_DEF_KEEPALIVE_INTERVAL;
215 } else {
216 global->keepalive_interval = g->keepalive_interval;
219 if (flag & LDP_GLOBAL_CFG_HELLOTIME_TIMER) {
220 if (g->hellotime_timer == 0) {
221 global->hellotime_timer = LDP_ENTITY_DEF_HELLOTIME_TIMER;
222 } else {
223 global->hellotime_timer = g->hellotime_timer;
226 if (flag & LDP_GLOBAL_CFG_HELLOTIME_INTERVAL) {
227 if (g->hellotime_interval == 0) {
228 global->hellotime_interval = LDP_ENTITY_DEF_HELLOTIME_INTERVAL;
229 } else {
230 global->hellotime_interval = g->hellotime_interval;
233 #if MPLS_USE_LSR
234 if (flag & LDP_GLOBAL_CFG_LSR_HANDLE) {
235 global->lsr_handle = g->lsr_handle ;
237 #endif
238 global->configuration_sequence_number++;
240 retval = MPLS_SUCCESS;
242 ldp_cfg_global_set_end:
244 mpls_lock_release(global->global_lock); /* UNLOCK */
246 LDP_EXIT(global->user_data, "ldp_cfg_global_set");
248 return retval;
251 /******************* ENTITY **********************/
253 /* must set ldp_entity->index */
254 mpls_return_enum ldp_cfg_entity_get(mpls_cfg_handle handle, ldp_entity * e,
255 uint32_t flag)
257 ldp_global *global = (ldp_global *) handle;
258 ldp_entity *entity = NULL;
259 mpls_return_enum retval = MPLS_FAILURE;
261 MPLS_ASSERT(global !=NULL && e != NULL);
263 LDP_ENTER(global->user_data, "ldp_cfg_entity_get");
265 mpls_lock_get(global->global_lock); /* LOCK */
267 if (ldp_global_find_entity_index(global, e->index, &entity) != MPLS_SUCCESS)
268 goto ldp_cfg_entity_get_end;
270 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
271 e->admin_state = entity->admin_state;
273 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
274 e->transport_address = entity->transport_address;
276 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
277 e->protocol_version = entity->protocol_version;
279 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
280 e->remote_tcp_port = entity->remote_tcp_port;
282 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
283 e->remote_udp_port = entity->remote_udp_port;
285 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
286 e->max_pdu = entity->max_pdu;
288 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
289 e->keepalive_timer = entity->keepalive_timer;
291 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
292 e->keepalive_interval = entity->keepalive_interval;
294 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
295 e->hellotime_timer = entity->hellotime_timer;
297 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
298 e->hellotime_interval = entity->hellotime_interval;
300 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
301 e->session_setup_count = entity->session_setup_count;
303 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
304 e->session_backoff_timer = entity->session_backoff_timer;
306 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
307 e->label_distribution_mode = entity->label_distribution_mode;
309 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
310 e->path_vector_limit = entity->path_vector_limit;
312 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
313 e->hop_count_limit = entity->hop_count_limit;
315 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
316 e->label_request_count = entity->label_request_count;
318 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
319 e->label_request_timer = entity->label_request_timer;
321 if (flag & LDP_ENTITY_CFG_TYPE) {
322 e->entity_type = entity->entity_type;
324 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
325 e->sub_index = entity->sub_index;
327 if (flag & LDP_ENTITY_CFG_MESG_TX) {
328 e->mesg_tx = entity->mesg_tx;
330 if (flag & LDP_ENTITY_CFG_MESG_RX) {
331 e->mesg_rx = entity->mesg_rx;
333 if (flag & LDP_ENTITY_CFG_ADJ_COUNT) {
334 e->adj_count = e->adj_root.count;
336 if (flag & LDP_ENTITY_CFG_ADJ_INDEX) {
337 ldp_adj *a = MPLS_LIST_HEAD(&e->adj_root);
338 e->adj_index = a ? a->index : 0;
340 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
341 e->inherit_flag = entity->inherit_flag;
343 retval = MPLS_SUCCESS;
345 ldp_cfg_entity_get_end:
347 mpls_lock_release(global->global_lock); /* UNLOCK */
349 LDP_EXIT(global->user_data, "ldp_cfg_entity_get");
351 return retval;
354 mpls_return_enum ldp_cfg_entity_getnext(mpls_cfg_handle handle, ldp_entity * e,
355 uint32_t flag)
357 ldp_global *g = (ldp_global *) handle;
358 ldp_entity *entity = NULL;
359 mpls_return_enum r = MPLS_FAILURE;
360 mpls_bool done = MPLS_BOOL_FALSE;
361 int index;
363 LDP_ENTER(g->user_data, "ldp_cfg_entity_getnext");
365 if (e->index == 0) {
366 index = 1;
367 } else {
368 index = e->index + 1;
371 mpls_lock_get(g->global_lock); /* LOCK */
372 while (done == MPLS_BOOL_FALSE) {
373 switch ((r = ldp_global_find_entity_index(g, index, &entity))) {
374 case MPLS_SUCCESS:
375 case MPLS_END_OF_LIST:
376 done = MPLS_BOOL_TRUE;
377 break;
378 case MPLS_FAILURE:
379 break;
380 default:
381 MPLS_ASSERT(0);
383 index++;
385 mpls_lock_release(g->global_lock); /* UNLOCK */
387 if (r == MPLS_SUCCESS) {
388 e->index = entity->index;
389 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
390 return ldp_cfg_entity_get(g, e, flag);
392 LDP_EXIT(g->user_data, "ldp_cfg_entity_getnext");
393 return r;
396 mpls_return_enum ldp_cfg_entity_test(mpls_cfg_handle handle, ldp_entity * e,
397 uint32_t flag)
399 ldp_global *global = (ldp_global *) handle;
400 ldp_entity *entity = NULL;
401 mpls_return_enum retval = MPLS_FAILURE;
403 MPLS_ASSERT(global !=NULL);
405 LDP_ENTER(global->user_data, "ldp_cfg_entity_test");
407 mpls_lock_get(global->global_lock); /* LOCK */
409 if (!(flag & LDP_CFG_ADD)) {
410 if (e == NULL)
411 goto ldp_cfg_entity_test_end;
413 ldp_global_find_entity_index(global, e->index, &entity);
414 } else {
415 retval = MPLS_SUCCESS;
416 goto ldp_cfg_entity_test_end;
419 if (entity == NULL) {
420 goto ldp_cfg_entity_test_end;
423 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
424 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
425 goto ldp_cfg_entity_test_end;
428 retval = MPLS_SUCCESS;
430 ldp_cfg_entity_test_end:
431 mpls_lock_release(global->global_lock); /* UNLOCK */
433 LDP_EXIT(global->user_data, "ldp_cfg_entity_test");
435 return retval;
438 /* must set ldp_entity->index if not an add */
439 mpls_return_enum ldp_cfg_entity_set(mpls_cfg_handle handle, ldp_entity * e,
440 uint32_t flag)
442 ldp_global *global = (ldp_global *) handle;
443 ldp_entity *entity = NULL;
444 mpls_return_enum retval = MPLS_FAILURE;
446 MPLS_ASSERT(global !=NULL && e != NULL);
448 LDP_ENTER(global->user_data, "ldp_cfg_entity_set");
450 mpls_lock_get(global->global_lock); /* LOCK */
452 if (flag & LDP_CFG_ADD) {
453 entity = ldp_entity_create();
454 _ldp_global_add_entity(global, entity);
456 e->index = entity->index;
457 } else {
458 ldp_global_find_entity_index(global, e->index, &entity);
461 if (entity == NULL) {
462 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: can't find entity\n");
463 goto ldp_cfg_entity_set_end;
466 if ((ldp_entity_is_active(entity) == MPLS_BOOL_TRUE) &&
467 (flag & LDP_ENTITY_CFG_WHEN_DOWN)) {
468 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity is active\n");
469 goto ldp_cfg_entity_set_end;
472 if (flag & LDP_CFG_DEL) {
473 switch (entity->entity_type) {
474 case LDP_DIRECT:
475 ldp_entity_del_if(entity);
476 break;
477 case LDP_INDIRECT:
478 ldp_entity_del_peer(entity);
479 break;
480 default:
481 MPLS_ASSERT(0);
483 _ldp_global_del_entity(global, entity);
485 retval = MPLS_SUCCESS;
486 goto ldp_cfg_entity_set_end;
489 if (flag & LDP_ENTITY_CFG_SUB_INDEX) {
490 if (entity->sub_index != 0) {
491 /* unlink the old sub object */
492 switch (entity->entity_type) {
493 case LDP_DIRECT:
494 ldp_entity_del_if(entity);
495 break;
496 case LDP_INDIRECT:
497 ldp_entity_del_peer(entity);
498 break;
499 default:
500 MPLS_ASSERT(0);
504 /* link the new sub object */
505 switch (e->entity_type) {
506 case LDP_DIRECT:
508 ldp_if *iff = NULL;
509 if (ldp_global_find_if_index(global, e->sub_index,
510 &iff) != MPLS_SUCCESS) {
511 LDP_PRINT(global->user_data,
512 "ldp_cfg_entity_set: no such interface\n");
514 if (flag & LDP_CFG_ADD) {
515 _ldp_global_del_entity(global, entity);
517 goto ldp_cfg_entity_set_end;
519 ldp_entity_add_if(entity, iff);
520 break;
522 case LDP_INDIRECT:
524 ldp_peer *peer = NULL;
526 if (ldp_global_find_peer_index(global, e->sub_index, &peer) !=
527 MPLS_SUCCESS) {
528 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: no such peer\n");
530 if (flag & LDP_CFG_ADD) {
531 _ldp_global_del_entity(global, entity);
533 goto ldp_cfg_entity_set_end;
535 ldp_entity_add_peer(entity, peer);
536 break;
538 default:
539 MPLS_ASSERT(0);
543 if (flag & LDP_ENTITY_CFG_TRANS_ADDR) {
544 if (e->transport_address.type == MPLS_FAMILY_NONE) {
545 entity->inherit_flag |= LDP_ENTITY_CFG_TRANS_ADDR;
546 } else {
547 entity->inherit_flag &= ~LDP_ENTITY_CFG_TRANS_ADDR;
549 memcpy(&entity->transport_address, &e->transport_address,
550 sizeof(mpls_inet_addr));;
552 if (flag & LDP_ENTITY_CFG_PROTO_VER) {
553 entity->protocol_version = e->protocol_version;
555 if (flag & LDP_ENTITY_CFG_REMOTE_TCP) {
556 entity->remote_tcp_port = e->remote_tcp_port;
558 if (flag & LDP_ENTITY_CFG_REMOTE_UDP) {
559 entity->remote_udp_port = e->remote_udp_port;
561 if (flag & LDP_ENTITY_CFG_MAX_PDU) {
562 entity->max_pdu = e->max_pdu;
564 if (flag & LDP_ENTITY_CFG_KEEPALIVE_TIMER) {
565 if (e->transport_address.type == MPLS_FAMILY_NONE) {
566 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_TIMER;
567 } else {
568 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER;
570 entity->keepalive_timer = e->keepalive_timer;
572 if (flag & LDP_ENTITY_CFG_KEEPALIVE_INTERVAL) {
573 if (e->transport_address.type == MPLS_FAMILY_NONE) {
574 entity->inherit_flag |= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
575 } else {
576 entity->inherit_flag &= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL;
578 entity->keepalive_interval = e->keepalive_interval;
580 if (flag & LDP_ENTITY_CFG_HELLOTIME_TIMER) {
581 if (e->transport_address.type == MPLS_FAMILY_NONE) {
582 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_TIMER;
583 } else {
584 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_TIMER;
586 entity->hellotime_timer = e->hellotime_timer;
588 if (flag & LDP_ENTITY_CFG_HELLOTIME_INTERVAL) {
589 if (e->transport_address.type == MPLS_FAMILY_NONE) {
590 entity->inherit_flag |= LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
591 } else {
592 entity->inherit_flag &= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL;
594 entity->hellotime_interval = e->hellotime_interval;
596 if (flag & LDP_ENTITY_CFG_SESSION_SETUP_COUNT) {
597 entity->session_setup_count = e->session_setup_count;
599 if (flag & LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER) {
600 entity->session_backoff_timer = e->session_backoff_timer;
602 if (flag & LDP_ENTITY_CFG_DISTRIBUTION_MODE) {
603 entity->label_distribution_mode = e->label_distribution_mode;
605 if (flag & LDP_ENTITY_CFG_PATHVECTOR_LIMIT) {
606 entity->path_vector_limit = e->path_vector_limit;
608 if (flag & LDP_ENTITY_CFG_HOPCOUNT_LIMIT) {
609 entity->hop_count_limit = e->hop_count_limit;
611 if (flag & LDP_ENTITY_CFG_REQUEST_COUNT) {
612 entity->label_request_count = e->label_request_count;
614 if (flag & LDP_ENTITY_CFG_REQUEST_TIMER) {
615 entity->label_request_timer = e->label_request_timer;
617 if (flag & LDP_ENTITY_CFG_TYPE) {
618 entity->entity_type = e->entity_type;
620 if (flag & LDP_ENTITY_CFG_ADMIN_STATE) {
621 if (ldp_entity_is_active(entity) == MPLS_BOOL_TRUE &&
622 e->admin_state == MPLS_ADMIN_DISABLE) {
623 if (ldp_entity_shutdown(global, entity, 0) == MPLS_FAILURE) {
624 goto ldp_cfg_entity_set_end;
626 } else if (ldp_entity_is_active(entity) == MPLS_BOOL_FALSE &&
627 e->admin_state == MPLS_ADMIN_ENABLE && ldp_entity_is_ready(entity) == MPLS_BOOL_TRUE) {
628 if (ldp_entity_startup(global, entity) == MPLS_FAILURE) {
629 goto ldp_cfg_entity_set_end;
631 } else {
632 LDP_PRINT(global->user_data, "ldp_cfg_entity_set: entity not ready\n");
634 goto ldp_cfg_entity_set_end;
637 if (flag & LDP_ENTITY_CFG_INHERIT_FLAG) {
638 entity->inherit_flag = e->inherit_flag;
640 global->configuration_sequence_number++;
642 retval = MPLS_SUCCESS;
644 ldp_cfg_entity_set_end:
645 mpls_lock_release(global->global_lock); /* UNLOCK */
647 LDP_EXIT(global->user_data, "ldp_cfg_entity_set");
649 return retval;
652 mpls_return_enum ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle,
653 ldp_entity * e)
655 ldp_global *g = (ldp_global *) handle;
656 mpls_bool this_one = MPLS_BOOL_FALSE;
657 mpls_return_enum r = MPLS_FAILURE;
658 ldp_adj *adj_next = NULL;
659 ldp_adj *adj = NULL;
660 ldp_entity *entity = NULL;
662 LDP_ENTER(g->user_data, "ldp_cfg_entity_adj_getnext");
664 /* if an adj_index of zero is sent, get the index of
665 * the first adj in the list
667 if (!e->adj_index) {
668 this_one = MPLS_BOOL_TRUE;
671 mpls_lock_get(g->global_lock); /* LOCK */
673 if (ldp_global_find_entity_index(g, e->index, &entity) == MPLS_SUCCESS) {
674 adj = MPLS_LIST_HEAD(&entity->adj_root);
675 while (adj) {
676 if (this_one == MPLS_BOOL_TRUE) {
677 adj_next = adj;
678 break;
681 /* since the entities are sort in the list ... */
682 if (adj->index > e->adj_index) {
683 break;
684 } else if (adj->index == e->adj_index) {
685 this_one = MPLS_BOOL_TRUE;
687 adj = MPLS_LIST_NEXT(&entity->adj_root, adj, _entity);
690 mpls_lock_release(g->global_lock); /* UNLOCK */
692 if (adj_next) {
693 e->adj_index = adj_next->index;
694 r = MPLS_SUCCESS;
697 LDP_EXIT(g->user_data, "ldp_cfg_entity_adj_getnext");
698 return r;
701 /******************* INTERFACE **********************/
703 mpls_return_enum ldp_cfg_if_get(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
705 ldp_global *global = (ldp_global *) handle;
706 ldp_if *iff = NULL;
707 mpls_return_enum retval = MPLS_FAILURE;
709 MPLS_ASSERT(global !=NULL && i != NULL);
711 LDP_ENTER(global->user_data, "ldp_cfg_if_get");
713 mpls_lock_get(global->global_lock); /* LOCK */
715 if (ldp_global_find_if_index(global, i->index, &iff) != MPLS_SUCCESS)
716 goto ldp_cfg_if_get_end;
718 if (flag & LDP_IF_CFG_NAME) {
719 strncpy(i->name, iff->name, MPLS_MAX_IF_NAME);
721 if (flag & LDP_IF_CFG_LABEL_SPACE) {
722 i->label_space = iff->label_space;
724 if (flag & LDP_IF_CFG_ENTITY_INDEX) {
725 i->entity_index = iff->entity ? iff->entity->index : 0;
727 if (flag & LDP_IF_CFG_OPER_STATE) {
728 i->oper_state = iff->oper_state;
730 if (flag & LDP_IF_CFG_LOCAL_SOURCE_ADDR) {
731 memcpy(&i->local_source_address, &iff->local_source_address,
732 sizeof(mpls_inet_addr));
734 retval = MPLS_SUCCESS;
736 ldp_cfg_if_get_end:
737 mpls_lock_release(global->global_lock); /* UNLOCK */
739 LDP_EXIT(global->user_data, "ldp_cfg_if_get");
741 return retval;
744 mpls_return_enum ldp_cfg_if_getnext(mpls_cfg_handle handle, ldp_if * i,
745 uint32_t flag)
747 ldp_global *g = (ldp_global *) handle;
748 ldp_if *iff = NULL;
749 mpls_return_enum r = MPLS_FAILURE;
750 mpls_bool done = MPLS_BOOL_FALSE;
751 int index;
753 LDP_ENTER(g->user_data, "ldp_cfg_if_getnext");
755 if (i->index == 0) {
756 index = 1;
757 } else {
758 index = i->index + 1;
761 mpls_lock_get(g->global_lock); /* LOCK */
762 while (done == MPLS_BOOL_FALSE) {
763 switch ((r = ldp_global_find_if_index(g, index, &iff))) {
764 case MPLS_SUCCESS:
765 case MPLS_END_OF_LIST:
766 done = MPLS_BOOL_TRUE;
767 break;
768 case MPLS_FAILURE:
769 break;
770 default:
771 MPLS_ASSERT(0);
773 index++;
775 mpls_lock_release(g->global_lock); /* UNLOCK */
777 if (r == MPLS_SUCCESS) {
778 i->index = iff->index;
779 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
780 return ldp_cfg_if_get(g, i, flag);
782 LDP_EXIT(g->user_data, "ldp_cfg_if_getnext");
783 return r;
786 mpls_return_enum ldp_cfg_if_test(mpls_cfg_handle handle, ldp_if * i,
787 uint32_t flag)
789 ldp_global *global = (ldp_global *) handle;
790 ldp_if *iff = NULL;
791 mpls_return_enum retval = MPLS_FAILURE;
793 MPLS_ASSERT(global !=NULL && i != NULL);
795 LDP_ENTER(global->user_data, "ldp_cfg_if_test");
797 mpls_lock_get(global->global_lock); /* LOCK */
799 if (!(flag & LDP_CFG_ADD)) {
800 ldp_global_find_if_index(global, i->index, &iff);
801 } else {
802 retval = MPLS_SUCCESS;
803 goto ldp_cfg_if_test_end;
806 if ((iff == NULL) ||
807 ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
808 (flag & LDP_IF_CFG_WHEN_DOWN))) goto ldp_cfg_if_test_end;
810 if (flag & LDP_CFG_DEL) {
811 if (iff->entity != NULL)
812 goto ldp_cfg_if_test_end;
814 retval = MPLS_SUCCESS;
816 ldp_cfg_if_test_end:
817 mpls_lock_release(global->global_lock); /* UNLOCK */
819 LDP_EXIT(global->user_data, "ldp_cfg_if_test");
821 return retval;
824 mpls_return_enum ldp_cfg_if_set(mpls_cfg_handle handle, ldp_if * i, uint32_t flag)
826 ldp_global *global = (ldp_global*)handle;
827 ldp_if *iff = NULL;
828 mpls_return_enum retval = MPLS_FAILURE;
830 MPLS_ASSERT(global !=NULL && i != NULL);
832 LDP_ENTER(global->user_data, "ldp_cfg_if_set");
834 mpls_lock_get(global->global_lock); /* LOCK */
836 if (flag & LDP_CFG_ADD) {
837 if ((iff = ldp_if_create()) == NULL) {
838 goto ldp_cfg_if_set_end;
840 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) == MPLS_BOOL_FALSE) {
841 i->handle = mpls_ifmgr_open_if(global->ifmgr_handle, i->name);
843 iff->handle = i->handle;
844 i->index = iff->index;
845 strncpy(iff->name, i->name, MPLS_MAX_IF_NAME);
846 _ldp_global_add_if(global, iff);
847 } else {
848 ldp_global_find_if_index(global, i->index, &iff);
851 if ((iff == NULL) ||
852 ((ldp_if_is_active(iff) == MPLS_BOOL_TRUE) &&
853 (flag & LDP_IF_CFG_WHEN_DOWN))) goto ldp_cfg_if_set_end;
855 if (flag & LDP_CFG_DEL) {
856 if (iff->entity != NULL) {
857 goto ldp_cfg_if_set_end;
860 _ldp_global_del_if(global, iff);
862 retval = MPLS_SUCCESS;
863 goto ldp_cfg_if_set_end;
865 if (flag & LDP_IF_CFG_INDEX) {
866 iff->index = i->index;
868 if (flag & LDP_IF_CFG_LABEL_SPACE) {
869 iff->label_space = i->label_space;
871 global->configuration_sequence_number++;
873 retval = MPLS_SUCCESS;
875 ldp_cfg_if_set_end:
876 mpls_lock_release(global->global_lock); /* UNLOCK */
878 LDP_EXIT(global->user_data, "ldp_cfg_if_set");
880 return retval;
883 /******************* ATTR **********************/
885 mpls_return_enum ldp_cfg_attr_get(mpls_cfg_handle handle, ldp_attr * a,
886 uint32_t flag)
888 ldp_global *global = (ldp_global *) handle;
889 ldp_attr *attr = NULL;
890 mpls_return_enum retval = MPLS_FAILURE;
892 MPLS_ASSERT(global !=NULL && a != NULL);
894 LDP_ENTER(global->user_data, "ldp_cfg_attr_get");
896 mpls_lock_get(global->global_lock); /* LOCK */
898 if (ldp_global_find_attr_index(global, a->index, &attr) != MPLS_SUCCESS)
899 goto ldp_cfg_attr_get_end;
901 if (flag & LDP_ATTR_CFG_STATE) {
902 a->state = attr->state;
904 if (flag & LDP_ATTR_CFG_FEC) {
905 ldp_attr2ldp_attr(attr, a, LDP_ATTR_FEC);
907 if (flag & LDP_ATTR_CFG_LABEL) {
908 ldp_attr2ldp_attr(attr, a, LDP_ATTR_LABEL);
910 if (flag & LDP_ATTR_CFG_HOP_COUNT) {
911 ldp_attr2ldp_attr(attr, a, LDP_ATTR_HOPCOUNT);
913 if (flag & LDP_ATTR_CFG_PATH) {
914 ldp_attr2ldp_attr(attr, a, LDP_ATTR_PATH);
916 if (flag & LDP_ATTR_CFG_SESSION_INDEX) {
917 a->session_index = (attr->session) ? (attr->session->index) : 0;
919 if (flag & LDP_ATTR_CFG_INLABEL_INDEX) {
920 a->inlabel_index = (attr->inlabel) ? (attr->inlabel->index) : 0;
922 if (flag & LDP_ATTR_CFG_OUTLABEL_INDEX) {
923 a->outlabel_index = (attr->outlabel) ? (attr->outlabel->index) : 0;
925 if (flag & LDP_ATTR_CFG_INGRESS) {
926 a->ingress = attr->ingress;
928 retval = MPLS_SUCCESS;
930 ldp_cfg_attr_get_end:
931 mpls_lock_release(global->global_lock); /* UNLOCK */
933 LDP_EXIT(global->user_data, "ldp_cfg_attr_get");
935 return retval;
938 mpls_return_enum ldp_cfg_attr_getnext(mpls_cfg_handle handle, ldp_attr * a,
939 uint32_t flag)
941 ldp_global *g = (ldp_global *) handle;
942 ldp_attr *attr = NULL;
943 mpls_return_enum r = MPLS_FAILURE;
944 mpls_bool done = MPLS_BOOL_FALSE;
945 int index;
947 LDP_ENTER(g->user_data, "ldp_cfg_attr_getnext");
949 if (a->index == 0) {
950 index = 1;
951 } else {
952 index = a->index + 1;
955 mpls_lock_get(g->global_lock); /* LOCK */
956 while (done == MPLS_BOOL_FALSE) {
957 switch ((r = ldp_global_find_attr_index(g, index, &attr))) {
958 case MPLS_SUCCESS:
959 case MPLS_END_OF_LIST:
960 done = MPLS_BOOL_TRUE;
961 break;
962 case MPLS_FAILURE:
963 break;
964 default:
965 MPLS_ASSERT(0);
967 index++;
969 mpls_lock_release(g->global_lock); /* UNLOCK */
971 if (r == MPLS_SUCCESS) {
972 a->index = attr->index;
973 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
974 return ldp_cfg_attr_get(g, a, flag);
976 LDP_EXIT(g->user_data, "ldp_cfg_attr_getnext");
977 return r;
980 /******************* PEER **********************/
982 mpls_return_enum ldp_cfg_peer_get(mpls_cfg_handle handle, ldp_peer * p,
983 uint32_t flag)
985 ldp_global *global = (ldp_global *) handle;
986 ldp_peer *peer = NULL;
987 mpls_return_enum retval = MPLS_FAILURE;
989 MPLS_ASSERT(global !=NULL && p != NULL);
991 LDP_ENTER(global->user_data, "ldp_cfg_peer_get");
993 mpls_lock_get(global->global_lock); /* LOCK */
995 if (ldp_global_find_peer_index(global, p->index, &peer) != MPLS_SUCCESS)
996 goto ldp_cfg_peer_get_end;
998 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
999 p->label_space = peer->label_space;
1001 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1002 p->target_role = peer->target_role;
1004 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1005 memcpy(&p->dest.addr, &peer->dest.addr, sizeof(mpls_inet_addr));
1007 if (flag & LDP_PEER_CFG_ENTITY_INDEX) {
1008 p->entity_index = peer->entity->index;
1010 if (flag & LDP_PEER_CFG_OPER_STATE) {
1011 p->oper_state = peer->oper_state;
1013 if (flag & LDP_PEER_CFG_PEER_NAME) {
1014 strncpy(p->peer_name, peer->peer_name, MPLS_MAX_IF_NAME);
1016 if (flag & LDP_PEER_CFG_LOCAL_SOURCE_ADDR) {
1017 memcpy(&p->local_source_address, &peer->local_source_address,
1018 sizeof(mpls_inet_addr));
1020 retval = MPLS_SUCCESS;
1022 ldp_cfg_peer_get_end:
1023 mpls_lock_release(global->global_lock); /* UNLOCK */
1025 LDP_EXIT(global->user_data, "ldp_cfg_peer_get");
1027 return retval;
1030 mpls_return_enum ldp_cfg_peer_getnext(mpls_cfg_handle handle, ldp_peer * p,
1031 uint32_t flag)
1033 ldp_global *g = (ldp_global *) handle;
1034 ldp_peer *peer = NULL;
1035 mpls_return_enum r = MPLS_FAILURE;
1036 mpls_bool done = MPLS_BOOL_FALSE;
1037 int index;
1039 LDP_ENTER(g->user_data, "ldp_cfg_peer_getnext");
1041 if (p->index == 0) {
1042 index = 1;
1043 } else {
1044 index = p->index + 1;
1047 mpls_lock_get(g->global_lock); /* LOCK */
1048 while (done == MPLS_BOOL_FALSE) {
1049 switch ((r = ldp_global_find_peer_index(g, index, &peer))) {
1050 case MPLS_SUCCESS:
1051 case MPLS_END_OF_LIST:
1052 done = MPLS_BOOL_TRUE;
1053 break;
1054 case MPLS_FAILURE:
1055 break;
1056 default:
1057 MPLS_ASSERT(0);
1059 index++;
1061 mpls_lock_release(g->global_lock); /* UNLOCK */
1063 if (r == MPLS_SUCCESS) {
1064 p->index = peer->index;
1065 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1066 return ldp_cfg_peer_get(g, p, flag);
1068 LDP_EXIT(g->user_data, "ldp_cfg_peer_getnext");
1069 return r;
1072 mpls_return_enum ldp_cfg_peer_test(mpls_cfg_handle handle, ldp_peer * p,
1073 uint32_t flag)
1075 // ldp_global* g = (ldp_global*)handle;
1076 return MPLS_SUCCESS;
1079 mpls_return_enum ldp_cfg_peer_set(mpls_cfg_handle handle, ldp_peer * p,
1080 uint32_t flag)
1082 ldp_global *global = (ldp_global *) handle;
1083 ldp_peer *peer = NULL;
1084 mpls_return_enum retval = MPLS_FAILURE;
1086 MPLS_ASSERT(global !=NULL && p != NULL);
1088 LDP_ENTER(global->user_data, "ldp_cfg_peer_set");
1090 mpls_lock_get(global->global_lock); /* LOCK */
1092 if (flag & LDP_CFG_ADD) {
1093 if ((peer = ldp_peer_create()) == NULL) {
1094 goto ldp_cfg_peer_set_end;
1096 p->index = peer->index;
1097 _ldp_global_add_peer(global, peer);
1098 } else {
1099 ldp_global_find_peer_index(global, p->index, &peer);
1102 if (peer == NULL) {
1103 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: no such peer\n");
1105 goto ldp_cfg_peer_set_end;
1107 if ((ldp_peer_is_active(peer) == MPLS_BOOL_TRUE) && (flag & LDP_PEER_CFG_WHEN_DOWN)) {
1108 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer is activer\n");
1110 goto ldp_cfg_peer_set_end;
1113 if (flag & LDP_CFG_DEL) {
1114 if (peer->entity != NULL) {
1115 LDP_PRINT(global->user_data,
1116 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1118 goto ldp_cfg_peer_set_end;
1121 _ldp_global_del_peer(global, peer);
1123 retval = MPLS_SUCCESS;
1124 goto ldp_cfg_peer_set_end;
1126 if (flag & LDP_PEER_CFG_LABEL_SPACE) {
1127 peer->label_space = p->label_space;
1129 if (flag & LDP_PEER_CFG_TARGET_ROLE) {
1130 peer->target_role = p->target_role;
1132 if (flag & LDP_PEER_CFG_DEST_ADDR) {
1133 memcpy(&peer->dest.addr, &p->dest.addr, sizeof(mpls_inet_addr));
1135 if (flag & LDP_PEER_CFG_PEER_NAME) {
1136 LDP_PRINT(global->user_data, "ldp_cfg_peer_set: peer_name = %s\n",
1138 p->peer_name);
1139 strncpy(peer->peer_name, p->peer_name, MPLS_MAX_IF_NAME);
1141 global->configuration_sequence_number++;
1143 retval = MPLS_SUCCESS;
1145 ldp_cfg_peer_set_end:
1146 mpls_lock_release(global->global_lock); /* UNLOCK */
1148 LDP_EXIT(global->user_data, "ldp_cfg_peer_set");
1150 return retval;
1152 /******************* L2CC **********************/
1154 mpls_return_enum ldp_cfg_l2cc_get(mpls_cfg_handle handle, ldp_l2cc * l,
1155 uint32_t flag)
1157 ldp_global *global = (ldp_global *) handle;
1158 ldp_l2cc *l2cc = NULL;
1159 mpls_return_enum retval = MPLS_FAILURE;
1161 MPLS_ASSERT(global !=NULL && l != NULL);
1163 LDP_ENTER(global->user_data, "ldp_cfg_l2cc_get");
1165 mpls_lock_get(global->global_lock); /* LOCK */
1167 if (ldp_global_find_l2cc_index(global, l->index, &l2cc) != MPLS_SUCCESS)
1168 goto ldp_cfg_l2cc_get_end;
1170 if (flag & LDP_L2CC_CFG_PEER_ADDR) {
1171 memcpy(&l->peer_addr, &l2cc->peer_addr, sizeof(mpls_inet_addr));
1173 if (flag & LDP_L2CC_CFG_FEC) {
1174 memcpy(&l->info, &l2cc->info, sizeof(mpls_fec));
1176 if (flag & LDP_L2CC_CFG_OUTSEGMENT_INDEX) {
1177 l->outlabel_index = l2cc->outlabel ? l2cc->outlabel->index : 0;
1179 if (flag & LDP_L2CC_CFG_ADMIN_STATE) {
1180 l->admin_state = l2cc->admin_state;
1182 retval = MPLS_SUCCESS;
1184 ldp_cfg_l2cc_get_end:
1185 mpls_lock_release(global->global_lock); /* UNLOCK */
1187 LDP_EXIT(global->user_data, "ldp_cfg_l2cc_get");
1189 return retval;
1192 mpls_return_enum ldp_cfg_l2cc_getnext(mpls_cfg_handle handle, ldp_l2cc * l,
1193 uint32_t flag)
1195 ldp_global *g = (ldp_global *) handle;
1196 ldp_l2cc *l2cc = NULL;
1197 mpls_return_enum r = MPLS_FAILURE;
1198 mpls_bool done = MPLS_BOOL_FALSE;
1199 int index;
1201 LDP_ENTER(g->user_data, "ldp_cfg_l2cc_getnext");
1203 if (l->index == 0) {
1204 index = 1;
1205 } else {
1206 index = l->index + 1;
1209 mpls_lock_get(g->global_lock); /* LOCK */
1210 while (done == MPLS_BOOL_FALSE) {
1211 switch ((r = ldp_global_find_l2cc_index(g, index, &l2cc))) {
1212 case MPLS_SUCCESS:
1213 case MPLS_END_OF_LIST:
1214 done = MPLS_BOOL_TRUE;
1215 break;
1216 case MPLS_FAILURE:
1217 break;
1218 default:
1219 MPLS_ASSERT(0);
1221 index++;
1223 mpls_lock_release(g->global_lock); /* UNLOCK */
1225 if (r == MPLS_SUCCESS) {
1226 l->index = l2cc->index;
1227 LDP_EXIT(g->user_data, "ldp_cfg_l2cc_getnext");
1228 return ldp_cfg_l2cc_get(g, l, flag);
1230 LDP_EXIT(g->user_data, "ldp_cfg_l2cc_getnext");
1231 return r;
1234 mpls_return_enum ldp_cfg_l2cc_test(mpls_cfg_handle handle, ldp_l2cc * l,
1235 uint32_t flag)
1237 // ldp_global* g = (ldp_global*)handle;
1238 return MPLS_SUCCESS;
1241 mpls_return_enum ldp_cfg_l2cc_set(mpls_cfg_handle handle, ldp_l2cc * l,
1242 uint32_t flag)
1244 ldp_global *global = (ldp_global *) handle;
1245 ldp_l2cc *l2cc = NULL;
1246 mpls_return_enum retval = MPLS_FAILURE;
1248 MPLS_ASSERT(global !=NULL && l != NULL);
1250 LDP_ENTER(global->user_data, "ldp_cfg_l2cc_set");
1252 mpls_lock_get(global->global_lock); /* LOCK */
1254 if (flag & LDP_CFG_ADD) {
1255 if ((l2cc = ldp_l2cc_create()) == NULL) {
1256 goto ldp_cfg_l2cc_set_end;
1258 l->index = l2cc->index;
1259 _ldp_global_add_l2cc(global, l2cc);
1260 } else {
1261 ldp_global_find_l2cc_index(global, l->index, &l2cc);
1264 if (l2cc == NULL) {
1265 LDP_PRINT(global->user_data, "ldp_cfg_l2cc_set: no such l2cc\n");
1267 goto ldp_cfg_l2cc_set_end;
1269 if ((ldp_l2cc_is_active(l2cc) == MPLS_BOOL_TRUE) && (flag & LDP_L2CC_CFG_WHEN_DOWN)) {
1270 LDP_PRINT(global->user_data, "ldp_cfg_l2cc_set: l2cc is active\n");
1272 goto ldp_cfg_l2cc_set_end;
1275 if (flag & LDP_CFG_DEL) {
1276 _ldp_global_del_l2cc(global, l2cc);
1277 retval = MPLS_SUCCESS;
1278 goto ldp_cfg_l2cc_set_end;
1280 if (flag & LDP_L2CC_CFG_PEER_ADDR) {
1281 memcpy(&l2cc->peer_addr, &l->peer_addr, sizeof(mpls_inet_addr));
1283 if (flag & LDP_L2CC_CFG_FEC) {
1284 memcpy(&l2cc->info, &l->info, sizeof(mpls_fec));
1286 if (flag & LDP_L2CC_CFG_ADMIN_STATE) {
1287 if (ldp_l2cc_is_active(l2cc) == MPLS_BOOL_TRUE &&
1288 l->admin_state == MPLS_ADMIN_DISABLE) {
1289 if (ldp_l2cc_shutdown(global, l2cc) == MPLS_FAILURE) {
1290 goto ldp_cfg_l2cc_set_end;
1292 } else if (ldp_l2cc_is_active(l2cc) == MPLS_BOOL_FALSE &&
1293 l->admin_state == MPLS_ADMIN_ENABLE && ldp_l2cc_is_ready(l2cc) == MPLS_BOOL_TRUE) {
1294 if (ldp_l2cc_startup(global, l2cc) == MPLS_FAILURE) {
1295 goto ldp_cfg_l2cc_set_end;
1297 } else {
1298 LDP_PRINT(global->user_data, "ldp_cfg_l2cc_set: l2cc not ready\n");
1300 goto ldp_cfg_l2cc_set_end;
1303 global->configuration_sequence_number++;
1305 retval = MPLS_SUCCESS;
1307 ldp_cfg_l2cc_set_end:
1308 mpls_lock_release(global->global_lock); /* UNLOCK */
1310 LDP_EXIT(global->user_data, "ldp_cfg_l2cc_set");
1312 return retval;
1315 /******************* ADJACENCY **********************/
1317 mpls_return_enum ldp_cfg_adj_get(mpls_cfg_handle handle, ldp_adj * a,
1318 uint32_t flag)
1320 ldp_global *global = (ldp_global *) handle;
1321 ldp_adj *adj = NULL;
1322 mpls_return_enum retval = MPLS_FAILURE;
1324 MPLS_ASSERT(global !=NULL && a != NULL);
1326 LDP_ENTER(global->user_data, "ldp_cfg_adj_get");
1328 mpls_lock_get(global->global_lock); /* LOCK */
1330 if (ldp_global_find_adj_index(global, a->index, &adj) != MPLS_SUCCESS)
1331 goto ldp_cfg_adj_get_end;
1333 if (flag & LDP_ADJ_CFG_REMOTE_TRADDR) {
1334 memcpy(&a->remote_transport_address, &adj->remote_transport_address,
1335 sizeof(mpls_inet_addr));
1337 if (flag & LDP_ADJ_CFG_REMOTE_SRCADDR) {
1338 memcpy(&a->remote_source_address, &adj->remote_source_address,
1339 sizeof(mpls_inet_addr));
1341 if (flag & LDP_ADJ_CFG_REMOTE_LSRADDR) {
1342 memcpy(&a->remote_lsr_address, &adj->remote_lsr_address,
1343 sizeof(mpls_inet_addr));
1345 if (flag & LDP_ADJ_CFG_REMOTE_CSN) {
1346 a->remote_csn = adj->remote_csn;
1348 if (flag & LDP_ADJ_CFG_REMOTE_LABELSPACE) {
1349 a->remote_label_space = adj->remote_label_space;
1351 if (flag & LDP_ADJ_CFG_REMOTE_HELLOTIME) {
1352 a->remote_hellotime = adj->remote_hellotime;
1354 if (flag & LDP_ADJ_CFG_ENTITY_INDEX) {
1355 a->entity_index = adj->entity ? adj->entity->index : 0;
1357 if (flag & LDP_ADJ_CFG_REMOTE_SESSION_INDEX) {
1358 a->session_index = (adj->session) ? (adj->session->index) : 0;
1360 if (flag & LDP_ADJ_CFG_ROLE) {
1361 a->role = adj->role;
1363 retval = MPLS_SUCCESS;
1365 ldp_cfg_adj_get_end:
1367 mpls_lock_release(global->global_lock); /* UNLOCK */
1369 LDP_EXIT(global->user_data, "ldp_cfg_adj_get");
1371 return retval;
1374 mpls_return_enum ldp_cfg_adj_getnext(mpls_cfg_handle handle, ldp_adj * a,
1375 uint32_t flag)
1377 ldp_global *g = (ldp_global *) handle;
1378 ldp_adj *adj = NULL;
1379 mpls_return_enum r = MPLS_FAILURE;
1380 mpls_bool done = MPLS_BOOL_FALSE;
1381 int index;
1383 LDP_ENTER(g->user_data, "ldp_cfg_adj_getnext");
1385 if (a->index == 0) {
1386 index = 1;
1387 } else {
1388 index = a->index + 1;
1391 mpls_lock_get(g->global_lock); /* LOCK */
1392 while (done == MPLS_BOOL_FALSE) {
1393 switch ((r = ldp_global_find_adj_index(g, index, &adj))) {
1394 case MPLS_SUCCESS:
1395 case MPLS_END_OF_LIST:
1396 done = MPLS_BOOL_TRUE;
1397 break;
1398 case MPLS_FAILURE:
1399 break;
1400 default:
1401 MPLS_ASSERT(0);
1403 index++;
1405 mpls_lock_release(g->global_lock); /* UNLOCK */
1407 if (r == MPLS_SUCCESS) {
1408 a->index = adj->index;
1409 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1410 return ldp_cfg_adj_get(g, a, flag);
1412 LDP_EXIT(g->user_data, "ldp_cfg_adj_getnext");
1413 return r;
1416 /******************* SESSION **********************/
1418 mpls_return_enum ldp_cfg_session_get(mpls_cfg_handle handle, ldp_session * s,
1419 uint32_t flag)
1421 ldp_global *global = (ldp_global *) handle;
1422 ldp_session *session = NULL;
1423 mpls_return_enum retval = MPLS_FAILURE;
1425 MPLS_ASSERT(global !=NULL && s != NULL);
1427 LDP_ENTER(global->user_data, "ldp_cfg_session_get");
1429 mpls_lock_get(global->global_lock); /* LOCK */
1431 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1432 goto ldp_cfg_session_get_end;
1434 if (flag & LDP_SESSION_CFG_STATE) {
1435 s->state = session->state;
1437 if (flag & LDP_SESSION_CFG_OPER_UP) {
1438 s->oper_up = session->oper_up;
1440 if (flag & LDP_SESSION_CFG_MAX_PDU) {
1441 s->oper_max_pdu = session->oper_max_pdu;
1443 if (flag & LDP_SESSION_CFG_KEEPALIVE) {
1444 s->oper_keepalive = session->oper_keepalive;
1446 if (flag & LDP_SESSION_CFG_PATH_LIMIT) {
1447 s->oper_path_vector_limit = session->oper_path_vector_limit;
1449 if (flag & LDP_SESSION_CFG_DIST_MODE) {
1450 s->oper_distribution_mode = session->oper_distribution_mode;
1452 if (flag & LDP_SESSION_CFG_LOOP_DETECTION) {
1453 s->oper_loop_detection = session->oper_loop_detection;
1455 if (flag & LDP_SESSION_CFG_REMOTE_MAX_PDU) {
1456 s->remote_max_pdu = session->remote_max_pdu;
1458 if (flag & LDP_SESSION_CFG_REMOTE_KEEPALIVE) {
1459 s->remote_keepalive = session->remote_keepalive;
1461 if (flag & LDP_SESSION_CFG_REMOTE_PATH_LIMIT) {
1462 s->remote_path_vector_limit = session->remote_path_vector_limit;
1464 if (flag & LDP_SESSION_CFG_REMOTE_DIST_MODE) {
1465 s->remote_distribution_mode = session->remote_distribution_mode;
1467 if (flag & LDP_SESSION_CFG_REMOTE_LOOP_DETECTION) {
1468 s->remote_loop_detection = session->remote_loop_detection;
1470 if (flag & LDP_SESSION_CFG_REMOTE_ADDR) {
1471 s->remote_dest.addr.type = session->remote_dest.addr.type;
1472 s->remote_dest.addr.u.ipv4 = session->remote_dest.addr.u.ipv4;
1474 if (flag & LDP_SESSION_CFG_REMOTE_PORT) {
1475 s->remote_dest.port = session->remote_dest.port;
1477 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL) {
1478 s->no_label_resource_sent = session->no_label_resource_sent;
1480 if (flag & LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE) {
1481 s->no_label_resource_recv = session->no_label_resource_recv;
1483 if (flag & LDP_SESSION_CFG_ADJ_INDEX) {
1484 ldp_adj *a = MPLS_LIST_HEAD(&session->adj_root);
1485 s->adj_index = a ? a->index : 0;
1487 if (flag & LDP_SESSION_CFG_MESG_TX) {
1488 s->mesg_tx = session->mesg_tx;
1490 if (flag & LDP_SESSION_CFG_MESG_RX) {
1491 s->mesg_rx = session->mesg_rx;
1493 retval = MPLS_SUCCESS;
1495 ldp_cfg_session_get_end:
1496 mpls_lock_release(global->global_lock); /* UNLOCK */
1498 LDP_EXIT(global->user_data, "ldp_cfg_session_get");
1500 return retval;
1503 mpls_return_enum ldp_cfg_session_getnext(mpls_cfg_handle handle, ldp_session * s,
1504 uint32_t flag)
1506 ldp_global *g = (ldp_global *) handle;
1507 ldp_session *ses = NULL;
1508 mpls_return_enum r = MPLS_FAILURE;
1509 mpls_bool done = MPLS_BOOL_FALSE;
1510 int index;
1512 LDP_ENTER(g->user_data, "ldp_cfg_session_getnext");
1514 if (s->index == 0) {
1515 index = 1;
1516 } else {
1517 index = s->index + 1;
1520 mpls_lock_get(g->global_lock); /* LOCK */
1521 while (done == MPLS_BOOL_FALSE) {
1522 switch ((r = ldp_global_find_session_index(g, index, &ses))) {
1523 case MPLS_SUCCESS:
1524 case MPLS_END_OF_LIST:
1525 done = MPLS_BOOL_TRUE;
1526 break;
1527 case MPLS_FAILURE:
1528 break;
1529 default:
1530 MPLS_ASSERT(0);
1532 index++;
1534 mpls_lock_release(g->global_lock); /* UNLOCK */
1536 if (r == MPLS_SUCCESS) {
1537 s->index = ses->index;
1539 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1540 return ldp_cfg_session_get(g, s, flag);
1543 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1545 return r;
1548 mpls_return_enum ldp_cfg_session_adj_getnext(mpls_cfg_handle handle,
1549 ldp_session * s)
1551 ldp_global *g = (ldp_global *) handle;
1552 mpls_bool this_one = MPLS_BOOL_FALSE;
1553 mpls_return_enum r = MPLS_FAILURE;
1554 ldp_adj *adj_next = NULL;
1555 ldp_adj *adj = NULL;
1556 ldp_session *session = NULL;
1558 LDP_ENTER(g->user_data, "ldp_cfg_session_adj_getnext");
1560 /* if an adj_index of zero is sent, get the index of
1561 * the first adj in the list
1563 if (!s->adj_index) {
1564 this_one = MPLS_BOOL_TRUE;
1567 mpls_lock_get(g->global_lock); /* LOCK */
1569 if (ldp_global_find_session_index(g, s->index, &session) == MPLS_SUCCESS) {
1570 adj = MPLS_LIST_HEAD(&session->adj_root);
1571 while (adj) {
1572 if (this_one == MPLS_BOOL_TRUE) {
1573 adj_next = adj;
1574 break;
1577 /* since the entities are sort in the list ... */
1578 if (adj->index > s->adj_index) {
1579 break;
1580 } else if (adj->index == s->adj_index) {
1581 this_one = MPLS_BOOL_TRUE;
1583 adj = MPLS_LIST_NEXT(&session->adj_root, adj, _session);
1586 mpls_lock_release(g->global_lock); /* UNLOCK */
1588 if (adj_next) {
1589 s->adj_index = adj_next->index;
1590 r = MPLS_SUCCESS;
1593 LDP_EXIT(g->user_data, "ldp_cfg_session_adj_getnext");
1594 return r;
1597 mpls_return_enum ldp_cfg_session_raddr_get(mpls_cfg_handle handle,
1598 ldp_session * s, ldp_addr * a, uint32_t flag)
1600 ldp_global *global = (ldp_global *) handle;
1601 ldp_session *session = NULL;
1602 ldp_addr *addr = NULL;
1603 mpls_return_enum retval = MPLS_FAILURE;
1605 MPLS_ASSERT(global !=NULL && s != NULL && a != NULL);
1607 LDP_ENTER(global->user_data, "ldp_cfg_session_raddr_get");
1609 mpls_lock_get(global->global_lock); /* LOCK */
1611 if (ldp_global_find_session_index(global, s->index, &session) != MPLS_SUCCESS)
1612 goto ldp_cfg_session_raddr_get_end;
1614 if (ldp_session_find_raddr_index(session, a->index, &addr) != MPLS_SUCCESS)
1615 goto ldp_cfg_session_raddr_get_end;
1617 if (flag & LDP_SESSION_RADDR_CFG_ADDR) {
1618 memcpy(&a->address,&addr->address,sizeof(struct mpls_inet_addr));
1620 if (flag & LDP_SESSION_RADDR_CFG_INDEX) {
1621 a->index = addr->index;
1623 retval = MPLS_SUCCESS;
1625 ldp_cfg_session_raddr_get_end:
1626 mpls_lock_release(global->global_lock); /* UNLOCK */
1628 LDP_EXIT(global->user_data, "ldp_cfg_session_raddr_get");
1630 return retval;
1633 mpls_return_enum ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle,
1634 ldp_session * s, ldp_addr * a, uint32_t flag)
1636 ldp_global *g = (ldp_global *) handle;
1637 ldp_addr *addr = NULL;
1638 mpls_return_enum r = MPLS_FAILURE;
1639 mpls_bool done = MPLS_BOOL_FALSE;
1640 ldp_session *sp = NULL;
1641 int index;
1643 LDP_ENTER(g->user_data, "ldp_cfg_session_raddr_getnext");
1645 if (a->index == 0) {
1646 index = 1;
1647 } else {
1648 index = a->index + 1;
1651 r = ldp_global_find_session_index(g, s->index, &sp);
1652 if (r != MPLS_SUCCESS) {
1653 return r;
1656 mpls_lock_get(g->global_lock); /* LOCK */
1657 while (done == MPLS_BOOL_FALSE) {
1658 switch ((r = ldp_session_find_raddr_index(sp, 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(g->global_lock); /* UNLOCK */
1672 if (r == MPLS_SUCCESS) {
1673 a->index = addr->index;
1674 r = ldp_cfg_session_raddr_get(handle, sp, a, flag);
1677 LDP_EXIT(g->user_data, "ldp_cfg_session_getnext");
1678 return r;
1681 /******************* IN LABEL **********************/
1683 mpls_return_enum ldp_cfg_inlabel_get(mpls_cfg_handle handle, ldp_inlabel * i,
1684 uint32_t flag)
1686 ldp_global *global = (ldp_global *) handle;
1687 ldp_inlabel *inlabel = NULL;
1688 mpls_return_enum retval = MPLS_FAILURE;
1690 MPLS_ASSERT(global !=NULL && i != NULL);
1692 LDP_ENTER(global->user_data, "ldp_cfg_inlabel_get");
1694 mpls_lock_get(global->global_lock); /* LOCK */
1696 if (ldp_global_find_inlabel_index(global, i->index, &inlabel) != MPLS_SUCCESS)
1697 goto ldp_cfg_inlabel_get_end;
1699 if (flag & LDP_INLABEL_CFG_LABELSPACE) {
1700 i->info.labelspace = inlabel->info.labelspace;
1702 if (flag & LDP_INLABEL_CFG_LABEL) {
1703 memcpy(&i->info.label, &inlabel->info.label, sizeof(mpls_label_struct));
1705 if (flag & LDP_INLABEL_CFG_OUTLABEL_INDEX) {
1706 i->outlabel_index = (inlabel->outlabel) ? (inlabel->outlabel->index) : 0;
1709 retval = MPLS_SUCCESS;
1711 ldp_cfg_inlabel_get_end:
1712 mpls_lock_release(global->global_lock); /* UNLOCK */
1714 LDP_EXIT(global->user_data, "ldp_cfg_inlabel_get");
1716 return retval;
1719 mpls_return_enum ldp_cfg_inlabel_getnext(mpls_cfg_handle handle, ldp_inlabel * i,
1720 uint32_t flag)
1722 ldp_global *g = (ldp_global *) handle;
1723 ldp_inlabel *inlabel = NULL;
1724 mpls_return_enum r = MPLS_FAILURE;
1725 mpls_bool done = MPLS_BOOL_FALSE;
1726 int index;
1728 LDP_ENTER(g->user_data, "ldp_cfg_inlabel_getnext");
1730 if (i->index == 0) {
1731 index = 1;
1732 } else {
1733 index = i->index + 1;
1736 mpls_lock_get(g->global_lock); /* LOCK */
1737 while (done == MPLS_BOOL_FALSE) {
1738 switch ((r = ldp_global_find_inlabel_index(g, index, &inlabel))) {
1739 case MPLS_SUCCESS:
1740 case MPLS_END_OF_LIST:
1741 done = MPLS_BOOL_TRUE;
1742 break;
1743 case MPLS_FAILURE:
1744 break;
1745 default:
1746 MPLS_ASSERT(0);
1748 index++;
1750 mpls_lock_release(g->global_lock); /* UNLOCK */
1752 if (r == MPLS_SUCCESS) {
1753 i->index = inlabel->index;
1755 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
1756 return ldp_cfg_inlabel_get(g, i, flag);
1759 LDP_EXIT(g->user_data, "ldp_cfg_inlabel_getnext");
1761 return r;
1764 /******************* OUT LABEL **********************/
1766 mpls_return_enum ldp_cfg_outlabel_get(mpls_cfg_handle handle, ldp_outlabel * o,
1767 uint32_t flag)
1769 ldp_global *global = (ldp_global *) handle;
1770 ldp_outlabel *outlabel = NULL;
1771 mpls_return_enum retval = MPLS_FAILURE;
1773 MPLS_ASSERT(global !=NULL && o != NULL);
1775 LDP_ENTER(global->user_data, "ldp_cfg_outlabel_get");
1777 mpls_lock_get(global->global_lock); /* LOCK */
1779 if (ldp_global_find_outlabel_index(global, o->index,
1780 &outlabel) != MPLS_SUCCESS) goto ldp_cfg_outlabel_get_end;
1782 if (flag & LDP_OUTLABEL_CFG_ADDR_INDEX) {
1783 o->addr_index = (outlabel->addr) ? (outlabel->addr->index) : 0;
1785 if (flag & LDP_OUTLABEL_CFG_SESSION_INDEX) {
1786 o->session_index = (outlabel->session) ? (outlabel->session->index) : 0;
1788 if (flag & LDP_OUTLABEL_CFG_LABEL) {
1789 memcpy(&o->info.label, &outlabel->info.label, sizeof(mpls_label_struct));
1791 if (flag & LDP_OUTLABEL_CFG_MERGE_COUNT) {
1792 o->merge_count = outlabel->merge_count;
1795 retval = MPLS_SUCCESS;
1797 ldp_cfg_outlabel_get_end:
1798 mpls_lock_release(global->global_lock); /* UNLOCK */
1800 LDP_EXIT(global->user_data, "ldp_cfg_outlabel_get");
1802 return retval;
1805 mpls_return_enum ldp_cfg_outlabel_getnext(mpls_cfg_handle handle,
1806 ldp_outlabel * o, uint32_t flag)
1808 ldp_global *g = (ldp_global *) handle;
1809 ldp_outlabel *outlabel = NULL;
1810 mpls_return_enum r = MPLS_FAILURE;
1811 mpls_bool done = MPLS_BOOL_FALSE;
1812 int index;
1814 LDP_ENTER(g->user_data, "ldp_cfg_outlabel_getnext");
1816 if (o->index == 0) {
1817 index = 1;
1818 } else {
1819 index = o->index + 1;
1822 mpls_lock_get(g->global_lock); /* LOCK */
1823 while (done == MPLS_BOOL_FALSE) {
1824 switch ((r = ldp_global_find_outlabel_index(g, index, &outlabel))) {
1825 case MPLS_SUCCESS:
1826 case MPLS_END_OF_LIST:
1827 done = MPLS_BOOL_TRUE;
1828 break;
1829 case MPLS_FAILURE:
1830 break;
1831 default:
1832 MPLS_ASSERT(0);
1834 index++;
1836 mpls_lock_release(g->global_lock); /* UNLOCK */
1838 if (r == MPLS_SUCCESS) {
1839 o->index = outlabel->index;
1841 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
1842 return ldp_cfg_outlabel_get(g, o, flag);
1845 LDP_EXIT(g->user_data, "ldp_cfg_outlabel_getnext");
1847 return r;
1850 /******************* TUNNEL **********************/
1852 mpls_return_enum ldp_cfg_tunnel_set(mpls_cfg_handle handle, ldp_tunnel * t,
1853 uint32_t flag)
1855 ldp_global *global = (ldp_global *) handle;
1856 mpls_return_enum retval = MPLS_FAILURE;
1857 ldp_tunnel *tunnel = NULL;
1859 MPLS_ASSERT(global !=NULL);
1861 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_set");
1863 mpls_lock_get(global->global_lock); /* LOCK */
1865 if (flag & LDP_CFG_ADD) {
1866 if (!(tunnel = ldp_tunnel_create())) {
1867 goto ldp_cfg_tunnel_set_end;
1869 _ldp_global_add_tunnel(global, tunnel);
1871 t->index = tunnel->index;
1872 } else {
1873 ldp_global_find_tunnel_index(global, t->index, &tunnel);
1876 if (!tunnel) {
1877 LDP_PRINT(global->user_data,
1879 "ldp_cfg_tunnel_set:could not create tunnel\n");
1880 goto ldp_cfg_tunnel_set_end;
1883 if ((ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) &&
1884 (flag & LDP_TUNNEL_CFG_WHEN_DOWN)) {
1885 LDP_PRINT(global->user_data, "ldp_cfg_tunnel_set: tunnel is active\n");
1887 goto ldp_cfg_tunnel_set_end;
1890 if (flag & LDP_CFG_DEL) {
1891 if (tunnel->outlabel)
1892 ldp_tunnel_del_outlabel(tunnel);
1893 if (tunnel->resource)
1894 ldp_tunnel_del_resource(tunnel);
1895 if (tunnel->hop_list)
1896 ldp_tunnel_del_hop_list(tunnel);
1897 _ldp_global_del_tunnel(global, tunnel);
1899 retval = MPLS_SUCCESS;
1900 goto ldp_cfg_tunnel_set_end;
1903 if (flag & LDP_TUNNEL_CFG_INGRESS) {
1904 memcpy(&tunnel->ingress_lsrid, &t->ingress_lsrid, sizeof(ldp_addr));
1906 if (flag & LDP_TUNNEL_CFG_EGRESS) {
1907 memcpy(&tunnel->egress_lsrid, &t->egress_lsrid, sizeof(ldp_addr));
1909 if (flag & LDP_TUNNEL_CFG_NAME) {
1910 memcpy(&tunnel->name, &t->name, MPLS_MAX_IF_NAME);
1912 if (flag & LDP_TUNNEL_CFG_IS_IF) {
1913 tunnel->is_interface = t->is_interface;
1915 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
1916 ldp_outlabel *outlabel = NULL;
1918 if (t->outlabel_index) {
1919 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
1921 if (!outlabel) {
1922 goto ldp_cfg_tunnel_set_end;
1924 ldp_tunnel_add_outlabel(tunnel, outlabel);
1925 } else {
1926 ldp_tunnel_del_outlabel(tunnel);
1929 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
1930 tunnel->setup_prio = t->setup_prio;
1932 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
1933 tunnel->hold_prio = t->hold_prio;
1935 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
1936 tunnel->instance_prio = t->instance_prio;
1938 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
1939 tunnel->local_protect = t->local_protect;
1941 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
1942 ldp_resource *resource = NULL;
1944 if (t->resource_index) {
1945 ldp_global_find_resource_index(global, t->resource_index, &resource);
1947 if (!resource) {
1948 goto ldp_cfg_tunnel_set_end;
1950 ldp_tunnel_add_resource(tunnel, resource);
1951 } else {
1952 ldp_tunnel_del_resource(tunnel);
1955 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
1956 ldp_hop_list *hop_list = NULL;
1958 if (t->hop_list_index) {
1959 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
1961 if (!hop_list) {
1962 goto ldp_cfg_tunnel_set_end;
1964 ldp_tunnel_add_hop_list(tunnel, hop_list);
1965 } else {
1966 ldp_tunnel_del_hop_list(tunnel);
1969 if (flag & LDP_TUNNEL_CFG_FEC) {
1970 memcpy(&tunnel->fec, &t->fec, sizeof(ldp_fec));
1972 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
1973 if (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_TRUE) {
1974 if (t->admin_state == MPLS_ADMIN_DISABLE) {
1975 if (ldp_tunnel_shutdown(global, tunnel, 0) == MPLS_FAILURE) {
1976 goto ldp_cfg_tunnel_set_end;
1979 } else {
1980 if (t->admin_state == MPLS_ADMIN_ENABLE) {
1981 if (ldp_tunnel_is_ready(tunnel) == MPLS_BOOL_TRUE) {
1982 if (ldp_tunnel_startup(global, tunnel) == MPLS_FAILURE) {
1983 goto ldp_cfg_tunnel_set_end;
1985 } else {
1986 LDP_PRINT(global->user_data,
1988 "ldp_cfg_tunnel_set: tunnel not ready\n");
1989 goto ldp_cfg_tunnel_set_end;
1994 retval = MPLS_SUCCESS;
1996 ldp_cfg_tunnel_set_end:
1998 mpls_lock_release(global->global_lock); /* UNLOCK */
2000 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_set");
2002 return retval;
2005 mpls_return_enum ldp_cfg_tunnel_test(mpls_cfg_handle handle, ldp_tunnel * t,
2006 uint32_t flag)
2008 ldp_global *global = (ldp_global *) handle;
2009 mpls_return_enum retval = MPLS_FAILURE;
2010 ldp_tunnel *tunnel = NULL;
2012 MPLS_ASSERT(global !=NULL);
2014 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_test");
2016 mpls_lock_get(global->global_lock); /* LOCK */
2018 if (flag & LDP_CFG_ADD) {
2019 retval = MPLS_SUCCESS;
2020 goto ldp_cfg_tunnel_test_end;
2023 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2025 if (!tunnel) {
2026 goto ldp_cfg_tunnel_test_end;
2029 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2030 ldp_resource *resource = NULL;
2032 if (t->resource_index) {
2033 ldp_global_find_resource_index(global, t->resource_index, &resource);
2035 if (!resource) {
2036 goto ldp_cfg_tunnel_test_end;
2040 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2041 ldp_hop_list *hop_list = NULL;
2043 if (t->hop_list_index) {
2044 ldp_global_find_hop_list_index(global, t->hop_list_index, &hop_list);
2046 if (!hop_list) {
2047 goto ldp_cfg_tunnel_test_end;
2051 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2052 ldp_outlabel *outlabel = NULL;
2054 if (t->outlabel_index) {
2055 ldp_global_find_outlabel_index(global, t->outlabel_index, &outlabel);
2057 if (!outlabel) {
2058 goto ldp_cfg_tunnel_test_end;
2062 if ((flag & LDP_TUNNEL_CFG_ADMIN_STATE) &&
2063 (ldp_tunnel_is_active(tunnel) == MPLS_BOOL_FALSE) &&
2064 (t->admin_state == MPLS_ADMIN_ENABLE) && (ldp_tunnel_is_ready(tunnel) != MPLS_BOOL_TRUE)) {
2065 goto ldp_cfg_tunnel_test_end;
2067 retval = MPLS_SUCCESS;
2069 ldp_cfg_tunnel_test_end:
2071 mpls_lock_release(global->global_lock); /* UNLOCK */
2073 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_test");
2075 return retval;
2078 mpls_return_enum ldp_cfg_tunnel_get(mpls_cfg_handle handle, ldp_tunnel * t,
2079 uint32_t flag)
2081 ldp_global *global = (ldp_global *) handle;
2082 mpls_return_enum retval = MPLS_FAILURE;
2083 ldp_tunnel *tunnel = NULL;
2085 MPLS_ASSERT(global !=NULL);
2087 LDP_ENTER(global->user_data, "ldp_cfg_tunnel_get");
2089 mpls_lock_get(global->global_lock); /* LOCK */
2091 ldp_global_find_tunnel_index(global, t->index, &tunnel);
2093 if (!tunnel) {
2094 goto ldp_cfg_tunnel_get_end;
2096 if (flag & LDP_TUNNEL_CFG_INGRESS) {
2097 memcpy(&t->ingress_lsrid, &tunnel->ingress_lsrid, sizeof(ldp_addr));
2099 if (flag & LDP_TUNNEL_CFG_EGRESS) {
2100 memcpy(&t->egress_lsrid, &tunnel->egress_lsrid, sizeof(ldp_addr));
2102 if (flag & LDP_TUNNEL_CFG_NAME) {
2103 memcpy(&t->name, &tunnel->name, MPLS_MAX_IF_NAME);
2105 if (flag & LDP_TUNNEL_CFG_IS_IF) {
2106 t->is_interface = tunnel->is_interface;
2108 if (flag & LDP_TUNNEL_CFG_OUTLABEL) {
2109 if (tunnel->outlabel) {
2110 t->outlabel_index = tunnel->outlabel->index;
2111 } else {
2112 t->outlabel_index = 0;
2115 if (flag & LDP_TUNNEL_CFG_SETUP_PRIO) {
2116 t->setup_prio = tunnel->setup_prio;
2118 if (flag & LDP_TUNNEL_CFG_HOLD_PRIO) {
2119 t->hold_prio = tunnel->hold_prio;
2121 if (flag & LDP_TUNNEL_CFG_INSTANCE_PRIO) {
2122 tunnel->instance_prio = t->instance_prio;
2124 if (flag & LDP_TUNNEL_CFG_LOCAL_PROTECT) {
2125 tunnel->local_protect = t->local_protect;
2127 if (flag & LDP_TUNNEL_CFG_RESOURCE_INDEX) {
2128 if (tunnel->resource) {
2129 t->resource_index = tunnel->resource->index;
2130 } else {
2131 t->resource_index = 0;
2134 if (flag & LDP_TUNNEL_CFG_HOP_LIST_INDEX) {
2135 if (tunnel->hop_list) {
2136 t->hop_list_index = tunnel->hop_list->index;
2137 } else {
2138 t->hop_list_index = 0;
2141 if (flag & LDP_TUNNEL_CFG_FEC) {
2142 memcpy(&t->fec, &tunnel->fec, sizeof(ldp_fec));
2144 if (flag & LDP_TUNNEL_CFG_ADMIN_STATE) {
2145 t->admin_state = tunnel->admin_state;
2147 retval = MPLS_SUCCESS;
2149 ldp_cfg_tunnel_get_end:
2151 mpls_lock_release(global->global_lock); /* UNLOCK */
2153 LDP_EXIT(global->user_data, "ldp_cfg_tunnel_get");
2155 return retval;
2158 /******************* RESOURCE **********************/
2160 mpls_return_enum ldp_cfg_resource_set(mpls_cfg_handle handle, ldp_resource * r,
2161 uint32_t flag)
2163 ldp_global *global = (ldp_global *) handle;
2164 mpls_return_enum retval = MPLS_FAILURE;
2165 ldp_resource *resource = NULL;
2167 MPLS_ASSERT(global !=NULL);
2169 LDP_ENTER(global->user_data, "ldp_cfg_resource_set");
2171 mpls_lock_get(global->global_lock); /* LOCK */
2173 if (flag & LDP_CFG_ADD) {
2174 resource = ldp_resource_create();
2175 _ldp_global_add_resource(global, resource);
2177 r->index = resource->index;
2178 } else {
2179 ldp_global_find_resource_index(global, r->index, &resource);
2182 if (!resource) {
2183 goto ldp_cfg_resource_set_end;
2186 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2187 resource->max_rate = r->max_rate;
2189 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2190 resource->mean_rate = r->mean_rate;
2192 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2193 resource->burst_size = r->burst_size;
2195 retval = MPLS_SUCCESS;
2197 ldp_cfg_resource_set_end:
2199 mpls_lock_release(global->global_lock); /* UNLOCK */
2201 LDP_EXIT(global->user_data, "ldp_cfg_resource_set");
2203 return retval;
2206 mpls_return_enum ldp_cfg_resource_test(mpls_cfg_handle handle, ldp_resource * r,
2207 uint32_t flag)
2209 ldp_global *global = (ldp_global *) handle;
2210 mpls_return_enum retval = MPLS_FAILURE;
2211 ldp_resource *resource = NULL;
2213 MPLS_ASSERT(global !=NULL);
2215 LDP_ENTER(global->user_data, "ldp_cfg_resource_test");
2217 mpls_lock_get(global->global_lock); /* LOCK */
2219 if (flag & LDP_CFG_ADD) {
2220 retval = MPLS_SUCCESS;
2221 goto ldp_cfg_resource_test_end;
2224 ldp_global_find_resource_index(global, r->index, &resource);
2226 if (!resource) {
2227 goto ldp_cfg_resource_test_end;
2230 if (ldp_resource_in_use(resource) == MPLS_BOOL_TRUE) {
2231 goto ldp_cfg_resource_test_end;
2233 retval = MPLS_SUCCESS;
2235 ldp_cfg_resource_test_end:
2237 mpls_lock_release(global->global_lock); /* UNLOCK */
2239 LDP_EXIT(global->user_data, "ldp_cfg_resource_test");
2241 return retval;
2244 mpls_return_enum ldp_cfg_resource_get(mpls_cfg_handle handle, ldp_resource * r,
2245 uint32_t flag)
2247 ldp_global *global = (ldp_global *) handle;
2248 mpls_return_enum retval = MPLS_FAILURE;
2249 ldp_resource *resource = NULL;
2251 MPLS_ASSERT(global !=NULL);
2253 LDP_ENTER(global->user_data, "ldp_cfg_resource_get");
2255 mpls_lock_get(global->global_lock); /* LOCK */
2257 ldp_global_find_resource_index(global, r->index, &resource);
2259 if (!resource) {
2260 goto ldp_cfg_resource_get_end;
2263 if (flag & LDP_RESOURCE_CFG_MAXBPS) {
2264 r->max_rate = resource->max_rate;
2266 if (flag & LDP_RESOURCE_CFG_MEANBPS) {
2267 r->mean_rate = resource->mean_rate;
2269 if (flag & LDP_RESOURCE_CFG_BURSTSIZE) {
2270 r->burst_size = resource->burst_size;
2272 retval = MPLS_SUCCESS;
2274 ldp_cfg_resource_get_end:
2276 mpls_lock_release(global->global_lock); /* UNLOCK */
2278 LDP_EXIT(global->user_data, "ldp_cfg_resource_get");
2280 return retval;
2283 /******************* HOP **********************/
2285 mpls_return_enum ldp_cfg_hop_set(mpls_cfg_handle handle, ldp_hop * h,
2286 uint32_t flag)
2288 ldp_global *global = (ldp_global *) handle;
2289 mpls_return_enum retval = MPLS_FAILURE;
2290 ldp_hop_list *hop_list = NULL;
2291 ldp_hop *hop = NULL;
2293 MPLS_ASSERT(global !=NULL);
2295 LDP_ENTER(global->user_data, "ldp_cfg_hop_set");
2297 if (!h->hop_list_index && !h->index) {
2298 return retval;
2301 mpls_lock_get(global->global_lock); /* LOCK */
2303 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2305 if (!hop_list) {
2306 if (flag & LDP_CFG_ADD) {
2307 if (!(hop_list = ldp_hop_list_create())) {
2308 goto ldp_cfg_hop_set_end;
2310 _ldp_global_add_hop_list(global, hop_list);
2312 h->hop_list_index = hop_list->index;
2313 } else {
2314 goto ldp_cfg_hop_set_end;
2318 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2319 if (!hop) {
2320 if (h->index && (flag & LDP_CFG_ADD)) {
2321 if (!(hop = ldp_hop_create())) {
2322 goto ldp_cfg_hop_set_end;
2324 hop->index = h->index;
2325 ldp_hop_list_add_hop(hop_list, hop);
2326 } else {
2327 goto ldp_cfg_hop_set_end;
2331 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2332 hop->path_option = h->path_option;
2334 if (flag & LDP_HOP_CFG_ADDR) {
2335 memcpy(&hop->addr, &h->addr, sizeof(ldp_addr));
2337 if (flag & LDP_HOP_CFG_TYPE) {
2338 hop->type = h->type;
2340 retval = MPLS_SUCCESS;
2342 ldp_cfg_hop_set_end:
2344 mpls_lock_release(global->global_lock); /* UNLOCK */
2346 LDP_EXIT(global->user_data, "ldp_cfg_hop_set");
2348 return retval;
2351 mpls_return_enum ldp_cfg_hop_test(mpls_cfg_handle handle, ldp_hop * h,
2352 uint32_t flag)
2354 ldp_global *global = (ldp_global *) handle;
2355 mpls_return_enum retval = MPLS_FAILURE;
2356 ldp_hop_list *hop_list = NULL;
2357 ldp_hop *hop = NULL;
2359 MPLS_ASSERT(global !=NULL);
2361 LDP_ENTER(global->user_data, "ldp_cfg_hop_test");
2363 mpls_lock_get(global->global_lock); /* LOCK */
2365 if (flag & LDP_CFG_ADD) {
2366 retval = MPLS_SUCCESS;
2367 goto ldp_cfg_hop_test_end;
2370 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2372 if (!hop_list) {
2373 goto ldp_cfg_hop_test_end;
2376 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2377 if (!hop) {
2378 goto ldp_cfg_hop_test_end;
2381 if (ldp_hop_in_use(hop) == MPLS_BOOL_TRUE) {
2382 goto ldp_cfg_hop_test_end;
2384 retval = MPLS_SUCCESS;
2386 ldp_cfg_hop_test_end:
2388 mpls_lock_release(global->global_lock); /* UNLOCK */
2390 LDP_EXIT(global->user_data, "ldp_cfg_hop_test");
2392 return retval;
2395 mpls_return_enum ldp_cfg_hop_get(mpls_cfg_handle handle, ldp_hop * h,
2396 uint32_t flag)
2398 ldp_global *global = (ldp_global *) handle;
2399 mpls_return_enum retval = MPLS_FAILURE;
2400 ldp_hop_list *hop_list = NULL;
2401 ldp_hop *hop = NULL;
2403 MPLS_ASSERT(global !=NULL);
2405 LDP_ENTER(global->user_data, "ldp_cfg_hop_get");
2407 mpls_lock_get(global->global_lock); /* LOCK */
2409 ldp_global_find_hop_list_index(global, h->hop_list_index, &hop_list);
2411 if (!hop_list) {
2412 goto ldp_cfg_hop_get_end;
2415 ldp_hop_list_find_hop_index(hop_list, h->index, &hop);
2416 if (!hop) {
2417 goto ldp_cfg_hop_get_end;
2420 if (flag & LDP_HOP_CFG_PATH_OPTION) {
2421 h->path_option = hop->path_option;
2423 if (flag & LDP_HOP_CFG_ADDR) {
2424 memcpy(&h->addr, &hop->addr, sizeof(ldp_addr));
2426 if (flag & LDP_HOP_CFG_TYPE) {
2427 h->type = hop->type;
2429 retval = MPLS_SUCCESS;
2431 ldp_cfg_hop_get_end:
2433 mpls_lock_release(global->global_lock); /* UNLOCK */
2435 LDP_EXIT(global->user_data, "ldp_cfg_hop_get");
2437 return retval;