3 * Copyright (C) James R. Leu 2000
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
10 #include "ldp_struct.h"
12 #include "ldp_global.h"
13 #include "ldp_entity.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"
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");
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
,
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
;
111 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
112 g
->lsr_handle
= global
->lsr_handle
;
116 mpls_lock_release(global
->global_lock
); /* UNLOCK */
118 LDP_EXIT(global
->user_data
, "ldp_cfg_global_get");
123 mpls_return_enum
ldp_cfg_global_test(mpls_cfg_handle handle
, ldp_global
* g
,
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");
145 mpls_return_enum
ldp_cfg_global_set(mpls_cfg_handle handle
, ldp_global
* g
,
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
));
192 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
193 global
->lsr_handle
= g
->lsr_handle
;
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
==
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
;
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
;
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
;
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
;
233 global
->hellotime_interval
= g
->hellotime_interval
;
237 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
238 global
->lsr_handle
= g
->lsr_handle
;
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");
254 /******************* ENTITY **********************/
256 /* must set ldp_entity->index */
257 mpls_return_enum
ldp_cfg_entity_get(mpls_cfg_handle handle
, ldp_entity
* e
,
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");
357 mpls_return_enum
ldp_cfg_entity_getnext(mpls_cfg_handle handle
, ldp_entity
* e
,
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
;
366 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_getnext");
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
))) {
378 case MPLS_END_OF_LIST
:
379 done
= MPLS_BOOL_TRUE
;
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");
399 mpls_return_enum
ldp_cfg_entity_test(mpls_cfg_handle handle
, ldp_entity
* e
,
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
)) {
414 goto ldp_cfg_entity_test_end
;
416 ldp_global_find_entity_index(global
, e
->index
, &entity
);
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");
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
,
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
;
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
) {
478 ldp_entity_del_if(global
, entity
);
481 ldp_entity_del_peer(entity
);
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
) {
497 ldp_entity_del_if(global
, entity
);
500 ldp_entity_del_peer(entity
);
507 /* link the new sub object */
508 switch (e
->entity_type
) {
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
);
527 ldp_peer
*peer
= NULL
;
529 if (ldp_global_find_peer_index(global
, e
->sub_index
, &peer
) !=
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
);
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
;
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
;
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
;
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
;
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
;
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
;
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");
655 mpls_return_enum
ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle
,
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
;
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
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
);
679 if (this_one
== MPLS_BOOL_TRUE
) {
684 /* since the entities are sort in the list ... */
685 if (adj
->index
> e
->adj_index
) {
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 */
696 e
->adj_index
= adj_next
->index
;
700 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_adj_getnext");
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
;
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
);
721 iff
= ldp_global_find_if_handle(global
, i
->handle
);
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
;
738 mpls_lock_release(global
->global_lock
); /* UNLOCK */
740 LDP_EXIT(global
->user_data
, "ldp_cfg_if_get");
745 mpls_return_enum
ldp_cfg_if_getnext(mpls_cfg_handle handle
, ldp_if
* i
,
748 ldp_global
*g
= (ldp_global
*) handle
;
750 mpls_return_enum r
= MPLS_FAILURE
;
751 mpls_bool done
= MPLS_BOOL_FALSE
;
754 LDP_ENTER(g
->user_data
, "ldp_cfg_if_getnext");
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
))) {
766 case MPLS_END_OF_LIST
:
767 done
= MPLS_BOOL_TRUE
;
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");
787 mpls_return_enum
ldp_cfg_if_test(mpls_cfg_handle handle
, ldp_if
* i
,
790 ldp_global
*global
= (ldp_global
*) handle
;
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
);
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
;
820 mpls_lock_release(global
->global_lock
); /* UNLOCK */
822 LDP_EXIT(global
->user_data
, "ldp_cfg_if_test");
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
;
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
);
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
);
864 if ((np
->info
.type
& MPLS_NH_IF
) &&
865 (np
->info
.if_handle
== iff
->handle
) && (!MPLS_LIST_IN_LIST(np
, _if
))) {
866 ldp_if_add_nexthop(iff
, np
);
868 np
= MPLS_LIST_NEXT(&global
->nexthop
, np
, _global
);
871 /* send the newly created index back to the user */
872 i
->index
= iff
->index
;
875 if (flag
& LDP_IF_CFG_BY_INDEX
) {
876 ldp_global_find_if_index(global
, i
->index
, &iff
);
878 iff
= ldp_global_find_if_handle(global
, i
->handle
);
883 * if we can't find this interface or if the interface is active and
884 * we are trying to change propertises that can not be changed on a
887 if ((!iff
) || ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
888 (flag
& LDP_IF_CFG_WHEN_DOWN
))) {
889 goto ldp_cfg_if_set_end
;
892 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
893 iff
->label_space
= i
->label_space
;
896 if (flag
& LDP_CFG_DEL
) {
898 * if this interface is still attached to a entity that it is not ready
901 if (iff
->entity
!= NULL
) {
902 goto ldp_cfg_if_set_end
;
905 np
= MPLS_LIST_HEAD(&iff
->nh_root
);
907 ldp_if_del_nexthop(global
, iff
, np
);
908 np
= MPLS_LIST_NEXT(&iff
->nh_root
, np
, _if
);
911 ap
= MPLS_LIST_HEAD(&iff
->addr_root
);
913 ldp_if_del_addr(global
, iff
, ap
);
914 ap
= MPLS_LIST_NEXT(&iff
->addr_root
, ap
, _if
);
917 MPLS_REFCNT_RELEASE2(global
, iff
, ldp_if_delete
);
920 global
->configuration_sequence_number
++;
922 retval
= MPLS_SUCCESS
;
925 mpls_lock_release(global
->global_lock
); /* UNLOCK */
927 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
932 /******************* ATTR **********************/
934 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
937 ldp_global
*global
= (ldp_global
*) handle
;
938 ldp_attr
*attr
= NULL
;
939 mpls_return_enum retval
= MPLS_FAILURE
;
941 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
943 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
945 mpls_lock_get(global
->global_lock
); /* LOCK */
947 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
948 goto ldp_cfg_attr_get_end
;
950 if (flag
& LDP_ATTR_CFG_STATE
) {
951 a
->state
= attr
->state
;
953 if (flag
& LDP_ATTR_CFG_FEC
) {
954 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
956 if (flag
& LDP_ATTR_CFG_LABEL
) {
957 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
959 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
960 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
962 if (flag
& LDP_ATTR_CFG_PATH
) {
963 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
965 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
966 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
968 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
969 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
971 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
972 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
974 if (flag
& LDP_ATTR_CFG_INGRESS
) {
975 a
->ingress
= attr
->ingress
;
977 retval
= MPLS_SUCCESS
;
979 ldp_cfg_attr_get_end
:
980 mpls_lock_release(global
->global_lock
); /* UNLOCK */
982 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
987 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
990 ldp_global
*g
= (ldp_global
*) handle
;
991 ldp_attr
*attr
= NULL
;
992 mpls_return_enum r
= MPLS_FAILURE
;
993 mpls_bool done
= MPLS_BOOL_FALSE
;
996 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
1001 index
= a
->index
+ 1;
1004 mpls_lock_get(g
->global_lock
); /* LOCK */
1005 while (done
== MPLS_BOOL_FALSE
) {
1006 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
1008 case MPLS_END_OF_LIST
:
1009 done
= MPLS_BOOL_TRUE
;
1018 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1020 if (r
== MPLS_SUCCESS
) {
1021 a
->index
= attr
->index
;
1022 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1023 return ldp_cfg_attr_get(g
, a
, flag
);
1025 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1029 /******************* PEER **********************/
1031 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
1034 ldp_global
*global
= (ldp_global
*) handle
;
1035 ldp_peer
*peer
= NULL
;
1036 mpls_return_enum retval
= MPLS_FAILURE
;
1038 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1040 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
1042 mpls_lock_get(global
->global_lock
); /* LOCK */
1044 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
1045 goto ldp_cfg_peer_get_end
;
1047 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1048 p
->label_space
= peer
->label_space
;
1050 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1051 p
->target_role
= peer
->target_role
;
1053 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1054 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1056 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1057 p
->entity_index
= peer
->entity
->index
;
1059 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1060 p
->oper_state
= peer
->oper_state
;
1062 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1063 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1065 retval
= MPLS_SUCCESS
;
1067 ldp_cfg_peer_get_end
:
1068 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1070 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1075 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1078 ldp_global
*g
= (ldp_global
*) handle
;
1079 ldp_peer
*peer
= NULL
;
1080 mpls_return_enum r
= MPLS_FAILURE
;
1081 mpls_bool done
= MPLS_BOOL_FALSE
;
1084 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1086 if (p
->index
== 0) {
1089 index
= p
->index
+ 1;
1092 mpls_lock_get(g
->global_lock
); /* LOCK */
1093 while (done
== MPLS_BOOL_FALSE
) {
1094 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1096 case MPLS_END_OF_LIST
:
1097 done
= MPLS_BOOL_TRUE
;
1106 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1108 if (r
== MPLS_SUCCESS
) {
1109 p
->index
= peer
->index
;
1110 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1111 return ldp_cfg_peer_get(g
, p
, flag
);
1113 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1117 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1120 // ldp_global* g = (ldp_global*)handle;
1121 return MPLS_SUCCESS
;
1124 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1127 ldp_global
*global
= (ldp_global
*) handle
;
1128 ldp_peer
*peer
= NULL
;
1129 mpls_return_enum retval
= MPLS_FAILURE
;
1131 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1133 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1135 mpls_lock_get(global
->global_lock
); /* LOCK */
1137 if (flag
& LDP_CFG_ADD
) {
1138 if ((peer
= ldp_peer_create()) == NULL
) {
1139 goto ldp_cfg_peer_set_end
;
1141 p
->index
= peer
->index
;
1142 _ldp_global_add_peer(global
, peer
);
1144 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1148 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1150 goto ldp_cfg_peer_set_end
;
1152 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1153 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1155 goto ldp_cfg_peer_set_end
;
1158 if (flag
& LDP_CFG_DEL
) {
1159 if (peer
->entity
!= NULL
) {
1160 LDP_PRINT(global
->user_data
,
1161 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1163 goto ldp_cfg_peer_set_end
;
1166 _ldp_global_del_peer(global
, peer
);
1168 retval
= MPLS_SUCCESS
;
1169 goto ldp_cfg_peer_set_end
;
1171 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1172 peer
->label_space
= p
->label_space
;
1174 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1175 peer
->target_role
= p
->target_role
;
1177 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1178 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1180 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1181 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1184 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1186 global
->configuration_sequence_number
++;
1188 retval
= MPLS_SUCCESS
;
1190 ldp_cfg_peer_set_end
:
1191 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1193 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1197 /******************* FEC **********************/
1199 mpls_return_enum
ldp_cfg_fec_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1202 ldp_global
*global
= (ldp_global
*) handle
;
1203 ldp_fec
*fec
= NULL
;
1204 mpls_return_enum retval
= MPLS_FAILURE
;
1206 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1208 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get");
1210 mpls_lock_get(global
->global_lock
); /* LOCK */
1212 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1213 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1215 fec
= ldp_fec_find(global
, f
);
1218 goto ldp_cfg_fec_get_end
;
1220 memcpy(f
, &fec
->info
, sizeof(mpls_fec
));
1221 f
->index
= fec
->index
;
1222 retval
= MPLS_SUCCESS
;
1224 ldp_cfg_fec_get_end
:
1225 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1227 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get");
1232 mpls_return_enum
ldp_cfg_fec_getnext(mpls_cfg_handle handle
, mpls_fec
* f
,
1235 ldp_global
*g
= (ldp_global
*) handle
;
1236 ldp_fec
*fec
= NULL
;
1237 mpls_return_enum r
= MPLS_FAILURE
;
1238 mpls_bool done
= MPLS_BOOL_FALSE
;
1241 LDP_ENTER(g
->user_data
, "ldp_cfg_fec_getnext");
1243 if (f
->index
== 0) {
1246 index
= f
->index
+ 1;
1249 mpls_lock_get(g
->global_lock
); /* LOCK */
1250 while (done
== MPLS_BOOL_FALSE
) {
1251 switch ((r
= ldp_global_find_fec_index(g
, index
, &fec
))) {
1253 case MPLS_END_OF_LIST
:
1254 done
= MPLS_BOOL_TRUE
;
1263 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1265 if (r
== MPLS_SUCCESS
) {
1266 f
->index
= fec
->index
;
1267 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1268 return ldp_cfg_fec_get(g
, f
, flag
);
1270 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1274 mpls_return_enum
ldp_cfg_fec_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1277 // ldp_global* g = (ldp_global*)handle;
1278 return MPLS_SUCCESS
;
1281 mpls_return_enum
ldp_cfg_fec_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1284 ldp_global
*global
= (ldp_global
*) handle
;
1285 ldp_fec
*fec
= NULL
;
1286 mpls_return_enum retval
= MPLS_FAILURE
;
1288 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1290 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_set");
1292 mpls_lock_get(global
->global_lock
); /* LOCK */
1294 if (flag
& LDP_CFG_ADD
) {
1295 if (ldp_fec_find(global
, f
) || (fec
= ldp_fec_create(global
, f
)) == NULL
) {
1296 goto ldp_cfg_fec_set_end
;
1298 f
->index
= fec
->index
;
1300 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1301 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1303 fec
= ldp_fec_find(global
, f
);
1308 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_set: no such fec\n");
1309 goto ldp_cfg_fec_set_end
;
1312 if (flag
& LDP_CFG_DEL
) {
1316 retval
= MPLS_SUCCESS
;
1318 ldp_cfg_fec_set_end
:
1319 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1321 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1326 mpls_return_enum
ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1327 mpls_nexthop
*n
, uint32_t flag
)
1329 ldp_global
*global
= (ldp_global
*) handle
;
1330 ldp_fec
*fec
= NULL
;
1331 ldp_nexthop
*nh
= NULL
;
1332 mpls_return_enum retval
= MPLS_FAILURE
;
1334 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1336 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1338 mpls_lock_get(global
->global_lock
); /* LOCK */
1340 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1341 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1343 fec
= ldp_fec_find(global
, f
);
1346 goto ldp_cfg_fec_nexthop_get_end
;
1348 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1349 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1351 nh
= ldp_fec_nexthop_find(fec
, n
);
1354 goto ldp_cfg_fec_nexthop_get_end
;
1356 memcpy(n
, &nh
->info
, sizeof(mpls_nexthop
));
1357 n
->index
= nh
->index
;
1358 retval
= MPLS_SUCCESS
;
1360 ldp_cfg_fec_nexthop_get_end
:
1361 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1363 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1368 mpls_return_enum
ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle
,
1369 mpls_fec
* f
, mpls_nexthop
*n
, uint32_t flag
)
1371 ldp_global
*global
= (ldp_global
*) handle
;
1372 ldp_fec
*fec
= NULL
;
1373 ldp_nexthop
*nh
= NULL
;
1374 mpls_return_enum r
= MPLS_FAILURE
;
1375 mpls_bool done
= MPLS_BOOL_FALSE
;
1378 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1380 if (n
->index
== 0) {
1383 index
= n
->index
+ 1;
1386 mpls_lock_get(global
->global_lock
); /* LOCK */
1388 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1389 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1391 fec
= ldp_fec_find(global
, f
);
1394 goto ldp_cfg_fec_nexthop_getnext_end
;
1396 while (done
== MPLS_BOOL_FALSE
) {
1397 switch ((r
= ldp_fec_find_nexthop_index(fec
, index
, &nh
))) {
1399 case MPLS_END_OF_LIST
:
1400 done
= MPLS_BOOL_TRUE
;
1409 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1411 if (r
== MPLS_SUCCESS
) {
1412 n
->index
= nh
->index
;
1413 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1414 return ldp_cfg_fec_nexthop_get(global
, f
, n
, flag
);
1417 ldp_cfg_fec_nexthop_getnext_end
:
1419 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1423 mpls_return_enum
ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1424 mpls_nexthop
*n
, uint32_t flag
)
1426 // ldp_global* g = (ldp_global*)handle;
1427 return MPLS_SUCCESS
;
1430 mpls_return_enum
ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1431 mpls_nexthop
*n
, uint32_t flag
)
1433 ldp_global
*global
= (ldp_global
*) handle
;
1434 ldp_fec
*fec
= NULL
;
1435 ldp_nexthop
*nh
= NULL
;
1436 mpls_return_enum retval
= MPLS_FAILURE
;
1438 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
&& n
!= NULL
);
1440 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1442 mpls_lock_get(global
->global_lock
); /* LOCK */
1444 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1445 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1447 fec
= ldp_fec_find(global
, f
);
1450 goto ldp_cfg_fec_nexthop_set_end
;
1452 if (flag
& LDP_CFG_ADD
) {
1453 if (ldp_fec_nexthop_find(fec
, n
) || (nh
= ldp_nexthop_create()) == NULL
) {
1454 goto ldp_cfg_fec_nexthop_set_end
;
1456 n
->index
= nh
->index
;
1457 mpls_nexthop2ldp_nexthop(n
, nh
);
1458 _ldp_global_add_nexthop(global
, nh
);
1459 ldp_fec_add_nexthop(global
, fec
, nh
);
1461 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1462 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1464 nh
= ldp_fec_nexthop_find(fec
, n
);
1469 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_nexthop_set: no such nh\n");
1470 goto ldp_cfg_fec_nexthop_set_end
;
1473 if (flag
& LDP_CFG_DEL
) {
1474 ldp_fec_del_nexthop(global
, fec
, nh
);
1475 _ldp_global_del_nexthop(global
, nh
);
1478 retval
= MPLS_SUCCESS
;
1480 ldp_cfg_fec_nexthop_set_end
:
1481 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1483 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1488 /******************* ADDR **********************/
1490 mpls_return_enum
ldp_cfg_addr_get(mpls_cfg_handle handle
, ldp_addr
* a
,
1493 ldp_global
*global
= (ldp_global
*) handle
;
1494 ldp_session
*session
= NULL
;
1495 ldp_nexthop
*nexthop
= NULL
;
1496 ldp_addr
*addr
= NULL
;
1497 mpls_return_enum retval
= MPLS_FAILURE
;
1499 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1501 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_get");
1503 mpls_lock_get(global
->global_lock
); /* LOCK */
1505 ldp_global_find_addr_index(global
, a
->index
, &addr
);
1508 goto ldp_cfg_addr_get_end
;
1510 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1511 a
->index
= addr
->index
;
1513 if ((session
= mpls_link_list_head_data(&addr
->session_root
))) {
1514 a
->session_index
= session
->index
;
1517 if ((nexthop
= MPLS_LIST_HEAD(&addr
->nh_root
))) {
1518 a
->nexthop_index
= nexthop
->index
;
1522 a
->if_index
= addr
->iff
->index
;
1525 retval
= MPLS_SUCCESS
;
1527 ldp_cfg_addr_get_end
:
1528 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1530 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_get");
1535 mpls_return_enum
ldp_cfg_addr_getnext(mpls_cfg_handle handle
, ldp_addr
*a
,
1538 ldp_global
*global
= (ldp_global
*) handle
;
1539 ldp_addr
*addr
= NULL
;
1540 mpls_return_enum r
= MPLS_FAILURE
;
1541 mpls_bool done
= MPLS_BOOL_FALSE
;
1544 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_getnext");
1546 if (a
->index
== 0) {
1549 index
= a
->index
+ 1;
1552 mpls_lock_get(global
->global_lock
); /* LOCK */
1554 while (done
== MPLS_BOOL_FALSE
) {
1555 switch ((r
= ldp_global_find_addr_index(global
, index
, &addr
))) {
1557 case MPLS_END_OF_LIST
:
1558 done
= MPLS_BOOL_TRUE
;
1567 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1569 if (r
== MPLS_SUCCESS
) {
1570 a
->index
= addr
->index
;
1571 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1572 return ldp_cfg_addr_get(global
, a
, flag
);
1575 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1579 /******************* IF ADDR **********************/
1581 mpls_return_enum
ldp_cfg_if_addr_get(mpls_cfg_handle handle
, ldp_if
* i
,
1582 ldp_addr
* a
, uint32_t flag
)
1584 ldp_global
*global
= (ldp_global
*) handle
;
1585 ldp_addr
*addr
= NULL
;
1587 mpls_return_enum retval
= MPLS_FAILURE
;
1589 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1591 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_get");
1593 mpls_lock_get(global
->global_lock
); /* LOCK */
1595 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1596 ldp_global_find_if_index(global
, i
->index
, &iff
);
1598 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1601 goto ldp_cfg_if_addr_get_end
;
1603 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1604 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1606 addr
= ldp_if_addr_find(iff
, &a
->address
);
1609 goto ldp_cfg_if_addr_get_end
;
1611 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1612 a
->index
= addr
->index
;
1614 retval
= MPLS_SUCCESS
;
1616 ldp_cfg_if_addr_get_end
:
1617 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1619 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_get");
1624 mpls_return_enum
ldp_cfg_if_addr_getnext(mpls_cfg_handle handle
,
1625 ldp_if
* i
, ldp_addr
*a
, uint32_t flag
)
1627 ldp_global
*global
= (ldp_global
*) handle
;
1629 ldp_addr
*addr
= NULL
;
1630 mpls_return_enum r
= MPLS_FAILURE
;
1631 mpls_bool done
= MPLS_BOOL_FALSE
;
1634 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_getnext");
1636 if (a
->index
== 0) {
1639 index
= a
->index
+ 1;
1642 mpls_lock_get(global
->global_lock
); /* LOCK */
1644 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1645 ldp_global_find_if_index(global
, i
->index
, &iff
);
1647 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1650 goto ldp_cfg_if_addr_getnext_end
;
1652 while (done
== MPLS_BOOL_FALSE
) {
1653 switch ((r
= ldp_if_find_addr_index(iff
, index
, &addr
))) {
1655 case MPLS_END_OF_LIST
:
1656 done
= MPLS_BOOL_TRUE
;
1665 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1667 if (r
== MPLS_SUCCESS
) {
1668 a
->index
= addr
->index
;
1669 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1670 return ldp_cfg_if_addr_get(global
, i
, a
, flag
);
1673 ldp_cfg_if_addr_getnext_end
:
1675 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1679 mpls_return_enum
ldp_cfg_if_addr_set(mpls_cfg_handle handle
, ldp_if
* i
,
1680 ldp_addr
*a
, uint32_t flag
)
1682 ldp_global
*global
= (ldp_global
*) handle
;
1684 ldp_addr
*addr
= NULL
;
1685 mpls_return_enum retval
= MPLS_FAILURE
;
1687 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1689 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_set");
1691 mpls_lock_get(global
->global_lock
); /* LOCK */
1693 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1694 ldp_global_find_if_index(global
, i
->index
, &iff
);
1696 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1699 goto ldp_cfg_if_addr_set_end
;
1701 if (flag
& LDP_CFG_ADD
) {
1702 if (ldp_if_addr_find(iff
, &a
->address
) || (addr
= ldp_addr_create(global
,
1703 &a
->address
)) == NULL
) {
1704 goto ldp_cfg_if_addr_set_end
;
1706 a
->index
= addr
->index
;
1707 ldp_if_add_addr(iff
, addr
);
1709 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1710 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1712 addr
= ldp_if_addr_find(iff
, &a
->address
);
1717 LDP_PRINT(global
->user_data
, "ldp_cfg_if_addr_set: no such addr\n");
1718 goto ldp_cfg_if_addr_set_end
;
1721 if (flag
& LDP_CFG_DEL
) {
1722 ldp_if_del_addr(global
, iff
,addr
);
1725 retval
= MPLS_SUCCESS
;
1727 ldp_cfg_if_addr_set_end
:
1728 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1730 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_set");
1735 /******************* ADJACENCY **********************/
1737 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1740 ldp_global
*global
= (ldp_global
*) handle
;
1741 ldp_adj
*adj
= NULL
;
1742 mpls_return_enum retval
= MPLS_FAILURE
;
1744 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1746 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1748 mpls_lock_get(global
->global_lock
); /* LOCK */
1750 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1751 goto ldp_cfg_adj_get_end
;
1753 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1754 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1755 sizeof(mpls_inet_addr
));
1757 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1758 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1759 sizeof(mpls_inet_addr
));
1761 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1762 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1763 sizeof(mpls_inet_addr
));
1765 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1766 a
->remote_csn
= adj
->remote_csn
;
1768 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1769 a
->remote_label_space
= adj
->remote_label_space
;
1771 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1772 a
->remote_hellotime
= adj
->remote_hellotime
;
1774 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1775 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1777 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1778 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1780 if (flag
& LDP_ADJ_CFG_ROLE
) {
1781 a
->role
= adj
->role
;
1783 retval
= MPLS_SUCCESS
;
1785 ldp_cfg_adj_get_end
:
1787 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1789 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1794 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1797 ldp_global
*g
= (ldp_global
*) handle
;
1798 ldp_adj
*adj
= NULL
;
1799 mpls_return_enum r
= MPLS_FAILURE
;
1800 mpls_bool done
= MPLS_BOOL_FALSE
;
1803 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1805 if (a
->index
== 0) {
1808 index
= a
->index
+ 1;
1811 mpls_lock_get(g
->global_lock
); /* LOCK */
1812 while (done
== MPLS_BOOL_FALSE
) {
1813 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1815 case MPLS_END_OF_LIST
:
1816 done
= MPLS_BOOL_TRUE
;
1825 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1827 if (r
== MPLS_SUCCESS
) {
1828 a
->index
= adj
->index
;
1829 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1830 return ldp_cfg_adj_get(g
, a
, flag
);
1832 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1836 /******************* SESSION **********************/
1838 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1841 ldp_global
*global
= (ldp_global
*) handle
;
1842 ldp_session
*session
= NULL
;
1843 mpls_return_enum retval
= MPLS_FAILURE
;
1845 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1847 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1849 mpls_lock_get(global
->global_lock
); /* LOCK */
1851 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1852 goto ldp_cfg_session_get_end
;
1854 if (flag
& LDP_SESSION_CFG_STATE
) {
1855 s
->state
= session
->state
;
1857 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1858 s
->oper_up
= session
->oper_up
;
1860 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1861 s
->oper_max_pdu
= session
->oper_max_pdu
;
1863 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1864 s
->oper_keepalive
= session
->oper_keepalive
;
1866 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1867 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1869 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1870 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1872 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1873 s
->oper_loop_detection
= session
->oper_loop_detection
;
1875 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1876 s
->remote_max_pdu
= session
->remote_max_pdu
;
1878 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1879 s
->remote_keepalive
= session
->remote_keepalive
;
1881 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1882 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1884 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1885 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1887 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1888 s
->remote_loop_detection
= session
->remote_loop_detection
;
1890 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1891 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1892 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1894 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1895 s
->remote_dest
.port
= session
->remote_dest
.port
;
1897 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1898 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1900 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1901 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1903 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1904 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1905 s
->adj_index
= a
? a
->index
: 0;
1907 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1908 s
->mesg_tx
= session
->mesg_tx
;
1910 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1911 s
->mesg_rx
= session
->mesg_rx
;
1913 retval
= MPLS_SUCCESS
;
1915 ldp_cfg_session_get_end
:
1916 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1918 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1923 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1926 ldp_global
*g
= (ldp_global
*) handle
;
1927 ldp_session
*ses
= NULL
;
1928 mpls_return_enum r
= MPLS_FAILURE
;
1929 mpls_bool done
= MPLS_BOOL_FALSE
;
1932 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1934 if (s
->index
== 0) {
1937 index
= s
->index
+ 1;
1940 mpls_lock_get(g
->global_lock
); /* LOCK */
1941 while (done
== MPLS_BOOL_FALSE
) {
1942 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1944 case MPLS_END_OF_LIST
:
1945 done
= MPLS_BOOL_TRUE
;
1954 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1956 if (r
== MPLS_SUCCESS
) {
1957 s
->index
= ses
->index
;
1959 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1960 return ldp_cfg_session_get(g
, s
, flag
);
1963 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1968 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
1971 ldp_global
*g
= (ldp_global
*) handle
;
1972 mpls_bool this_one
= MPLS_BOOL_FALSE
;
1973 mpls_return_enum r
= MPLS_FAILURE
;
1974 ldp_adj
*adj_next
= NULL
;
1975 ldp_adj
*adj
= NULL
;
1976 ldp_session
*session
= NULL
;
1978 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
1980 /* if an adj_index of zero is sent, get the index of
1981 * the first adj in the list
1983 if (!s
->adj_index
) {
1984 this_one
= MPLS_BOOL_TRUE
;
1987 mpls_lock_get(g
->global_lock
); /* LOCK */
1989 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
1990 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
1992 if (this_one
== MPLS_BOOL_TRUE
) {
1997 /* since the entities are sort in the list ... */
1998 if (adj
->index
> s
->adj_index
) {
2000 } else if (adj
->index
== s
->adj_index
) {
2001 this_one
= MPLS_BOOL_TRUE
;
2003 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
2006 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2009 s
->adj_index
= adj_next
->index
;
2013 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
2017 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
2018 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2020 ldp_global
*global
= (ldp_global
*) handle
;
2021 ldp_session
*session
= NULL
;
2022 ldp_addr
*addr
= NULL
;
2023 mpls_return_enum retval
= MPLS_FAILURE
;
2025 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
2027 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
2029 mpls_lock_get(global
->global_lock
); /* LOCK */
2031 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
2032 goto ldp_cfg_session_raddr_get_end
;
2034 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
2035 goto ldp_cfg_session_raddr_get_end
;
2037 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
2038 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
2040 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
2041 a
->index
= addr
->index
;
2043 retval
= MPLS_SUCCESS
;
2045 ldp_cfg_session_raddr_get_end
:
2046 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2048 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
2053 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
2054 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2056 ldp_global
*g
= (ldp_global
*) handle
;
2057 ldp_addr
*addr
= NULL
;
2058 mpls_return_enum r
= MPLS_FAILURE
;
2059 mpls_bool done
= MPLS_BOOL_FALSE
;
2060 ldp_session
*sp
= NULL
;
2063 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
2065 if (a
->index
== 0) {
2068 index
= a
->index
+ 1;
2071 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
2072 if (r
!= MPLS_SUCCESS
) {
2076 mpls_lock_get(g
->global_lock
); /* LOCK */
2077 while (done
== MPLS_BOOL_FALSE
) {
2078 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
2080 case MPLS_END_OF_LIST
:
2081 done
= MPLS_BOOL_TRUE
;
2090 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2092 if (r
== MPLS_SUCCESS
) {
2093 a
->index
= addr
->index
;
2094 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
2097 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2101 /******************* IN LABEL **********************/
2103 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2106 ldp_global
*global
= (ldp_global
*) handle
;
2107 ldp_inlabel
*inlabel
= NULL
;
2108 mpls_return_enum retval
= MPLS_FAILURE
;
2110 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
2112 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
2114 mpls_lock_get(global
->global_lock
); /* LOCK */
2116 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
2117 goto ldp_cfg_inlabel_get_end
;
2119 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
2120 i
->info
.labelspace
= inlabel
->info
.labelspace
;
2122 if (flag
& LDP_INLABEL_CFG_LABEL
) {
2123 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
2125 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
2126 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
2129 retval
= MPLS_SUCCESS
;
2131 ldp_cfg_inlabel_get_end
:
2132 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2134 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
2139 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2142 ldp_global
*g
= (ldp_global
*) handle
;
2143 ldp_inlabel
*inlabel
= NULL
;
2144 mpls_return_enum r
= MPLS_FAILURE
;
2145 mpls_bool done
= MPLS_BOOL_FALSE
;
2148 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
2150 if (i
->index
== 0) {
2153 index
= i
->index
+ 1;
2156 mpls_lock_get(g
->global_lock
); /* LOCK */
2157 while (done
== MPLS_BOOL_FALSE
) {
2158 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
2160 case MPLS_END_OF_LIST
:
2161 done
= MPLS_BOOL_TRUE
;
2170 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2172 if (r
== MPLS_SUCCESS
) {
2173 i
->index
= inlabel
->index
;
2175 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2176 return ldp_cfg_inlabel_get(g
, i
, flag
);
2179 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2184 /******************* OUT LABEL **********************/
2186 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
2189 ldp_global
*global
= (ldp_global
*) handle
;
2190 ldp_outlabel
*outlabel
= NULL
;
2191 mpls_return_enum retval
= MPLS_FAILURE
;
2193 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
2195 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
2197 mpls_lock_get(global
->global_lock
); /* LOCK */
2199 if (ldp_global_find_outlabel_index(global
, o
->index
,
2200 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
2202 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
2204 o
->nh_index
= outlabel
->nh
->index
;
2209 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
2210 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
2212 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
2213 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
2215 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
2216 o
->merge_count
= outlabel
->merge_count
;
2219 retval
= MPLS_SUCCESS
;
2221 ldp_cfg_outlabel_get_end
:
2222 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2224 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
2229 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
2230 ldp_outlabel
* o
, uint32_t flag
)
2232 ldp_global
*g
= (ldp_global
*) handle
;
2233 ldp_outlabel
*outlabel
= NULL
;
2234 mpls_return_enum r
= MPLS_FAILURE
;
2235 mpls_bool done
= MPLS_BOOL_FALSE
;
2238 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
2240 if (o
->index
== 0) {
2243 index
= o
->index
+ 1;
2246 mpls_lock_get(g
->global_lock
); /* LOCK */
2247 while (done
== MPLS_BOOL_FALSE
) {
2248 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
2250 case MPLS_END_OF_LIST
:
2251 done
= MPLS_BOOL_TRUE
;
2260 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2262 if (r
== MPLS_SUCCESS
) {
2263 o
->index
= outlabel
->index
;
2265 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2266 return ldp_cfg_outlabel_get(g
, o
, flag
);
2269 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2274 /******************* TUNNEL **********************/
2276 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2279 ldp_global
*global
= (ldp_global
*) handle
;
2280 mpls_return_enum retval
= MPLS_FAILURE
;
2281 ldp_tunnel
*tunnel
= NULL
;
2283 MPLS_ASSERT(global
!=NULL
);
2285 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2287 mpls_lock_get(global
->global_lock
); /* LOCK */
2289 if (flag
& LDP_CFG_ADD
) {
2290 if (!(tunnel
= ldp_tunnel_create())) {
2291 goto ldp_cfg_tunnel_set_end
;
2293 _ldp_global_add_tunnel(global
, tunnel
);
2295 t
->index
= tunnel
->index
;
2297 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2301 LDP_PRINT(global
->user_data
,
2303 "ldp_cfg_tunnel_set:could not create tunnel\n");
2304 goto ldp_cfg_tunnel_set_end
;
2307 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2308 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2309 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2311 goto ldp_cfg_tunnel_set_end
;
2314 if (flag
& LDP_CFG_DEL
) {
2315 if (tunnel
->outlabel
)
2316 ldp_tunnel_del_outlabel(tunnel
);
2317 if (tunnel
->resource
)
2318 ldp_tunnel_del_resource(tunnel
);
2319 if (tunnel
->hop_list
)
2320 ldp_tunnel_del_hop_list(tunnel
);
2321 _ldp_global_del_tunnel(global
, tunnel
);
2323 retval
= MPLS_SUCCESS
;
2324 goto ldp_cfg_tunnel_set_end
;
2327 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2328 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2330 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2331 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2333 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2334 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2336 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2337 tunnel
->is_interface
= t
->is_interface
;
2339 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2340 ldp_outlabel
*outlabel
= NULL
;
2342 if (t
->outlabel_index
) {
2343 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2346 goto ldp_cfg_tunnel_set_end
;
2348 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2350 ldp_tunnel_del_outlabel(tunnel
);
2353 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2354 tunnel
->setup_prio
= t
->setup_prio
;
2356 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2357 tunnel
->hold_prio
= t
->hold_prio
;
2359 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2360 tunnel
->instance_prio
= t
->instance_prio
;
2362 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2363 tunnel
->local_protect
= t
->local_protect
;
2365 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2366 ldp_resource
*resource
= NULL
;
2368 if (t
->resource_index
) {
2369 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2372 goto ldp_cfg_tunnel_set_end
;
2374 ldp_tunnel_add_resource(tunnel
, resource
);
2376 ldp_tunnel_del_resource(tunnel
);
2379 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2380 ldp_hop_list
*hop_list
= NULL
;
2382 if (t
->hop_list_index
) {
2383 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2386 goto ldp_cfg_tunnel_set_end
;
2388 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2390 ldp_tunnel_del_hop_list(tunnel
);
2393 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2394 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2396 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2397 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2398 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2399 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2400 goto ldp_cfg_tunnel_set_end
;
2404 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2405 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2406 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2407 goto ldp_cfg_tunnel_set_end
;
2410 LDP_PRINT(global
->user_data
,
2412 "ldp_cfg_tunnel_set: tunnel not ready\n");
2413 goto ldp_cfg_tunnel_set_end
;
2418 retval
= MPLS_SUCCESS
;
2420 ldp_cfg_tunnel_set_end
:
2422 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2424 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2429 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2432 ldp_global
*global
= (ldp_global
*) handle
;
2433 mpls_return_enum retval
= MPLS_FAILURE
;
2434 ldp_tunnel
*tunnel
= NULL
;
2436 MPLS_ASSERT(global
!=NULL
);
2438 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2440 mpls_lock_get(global
->global_lock
); /* LOCK */
2442 if (flag
& LDP_CFG_ADD
) {
2443 retval
= MPLS_SUCCESS
;
2444 goto ldp_cfg_tunnel_test_end
;
2447 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2450 goto ldp_cfg_tunnel_test_end
;
2453 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2454 ldp_resource
*resource
= NULL
;
2456 if (t
->resource_index
) {
2457 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2460 goto ldp_cfg_tunnel_test_end
;
2464 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2465 ldp_hop_list
*hop_list
= NULL
;
2467 if (t
->hop_list_index
) {
2468 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2471 goto ldp_cfg_tunnel_test_end
;
2475 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2476 ldp_outlabel
*outlabel
= NULL
;
2478 if (t
->outlabel_index
) {
2479 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2482 goto ldp_cfg_tunnel_test_end
;
2486 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2487 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2488 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2489 goto ldp_cfg_tunnel_test_end
;
2491 retval
= MPLS_SUCCESS
;
2493 ldp_cfg_tunnel_test_end
:
2495 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2497 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2502 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2505 ldp_global
*global
= (ldp_global
*) handle
;
2506 mpls_return_enum retval
= MPLS_FAILURE
;
2507 ldp_tunnel
*tunnel
= NULL
;
2509 MPLS_ASSERT(global
!=NULL
);
2511 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2513 mpls_lock_get(global
->global_lock
); /* LOCK */
2515 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2518 goto ldp_cfg_tunnel_get_end
;
2520 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2521 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2523 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2524 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2526 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2527 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2529 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2530 t
->is_interface
= tunnel
->is_interface
;
2532 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2533 if (tunnel
->outlabel
) {
2534 t
->outlabel_index
= tunnel
->outlabel
->index
;
2536 t
->outlabel_index
= 0;
2539 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2540 t
->setup_prio
= tunnel
->setup_prio
;
2542 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2543 t
->hold_prio
= tunnel
->hold_prio
;
2545 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2546 tunnel
->instance_prio
= t
->instance_prio
;
2548 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2549 tunnel
->local_protect
= t
->local_protect
;
2551 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2552 if (tunnel
->resource
) {
2553 t
->resource_index
= tunnel
->resource
->index
;
2555 t
->resource_index
= 0;
2558 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2559 if (tunnel
->hop_list
) {
2560 t
->hop_list_index
= tunnel
->hop_list
->index
;
2562 t
->hop_list_index
= 0;
2565 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2566 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2568 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2569 t
->admin_state
= tunnel
->admin_state
;
2571 retval
= MPLS_SUCCESS
;
2573 ldp_cfg_tunnel_get_end
:
2575 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2577 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2582 /******************* RESOURCE **********************/
2584 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2587 ldp_global
*global
= (ldp_global
*) handle
;
2588 mpls_return_enum retval
= MPLS_FAILURE
;
2589 ldp_resource
*resource
= NULL
;
2591 MPLS_ASSERT(global
!=NULL
);
2593 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2595 mpls_lock_get(global
->global_lock
); /* LOCK */
2597 if (flag
& LDP_CFG_ADD
) {
2598 resource
= ldp_resource_create();
2599 _ldp_global_add_resource(global
, resource
);
2601 r
->index
= resource
->index
;
2603 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2607 goto ldp_cfg_resource_set_end
;
2610 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2611 resource
->max_rate
= r
->max_rate
;
2613 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2614 resource
->mean_rate
= r
->mean_rate
;
2616 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2617 resource
->burst_size
= r
->burst_size
;
2619 retval
= MPLS_SUCCESS
;
2621 ldp_cfg_resource_set_end
:
2623 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2625 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2630 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2633 ldp_global
*global
= (ldp_global
*) handle
;
2634 mpls_return_enum retval
= MPLS_FAILURE
;
2635 ldp_resource
*resource
= NULL
;
2637 MPLS_ASSERT(global
!=NULL
);
2639 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2641 mpls_lock_get(global
->global_lock
); /* LOCK */
2643 if (flag
& LDP_CFG_ADD
) {
2644 retval
= MPLS_SUCCESS
;
2645 goto ldp_cfg_resource_test_end
;
2648 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2651 goto ldp_cfg_resource_test_end
;
2654 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2655 goto ldp_cfg_resource_test_end
;
2657 retval
= MPLS_SUCCESS
;
2659 ldp_cfg_resource_test_end
:
2661 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2663 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2668 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2671 ldp_global
*global
= (ldp_global
*) handle
;
2672 mpls_return_enum retval
= MPLS_FAILURE
;
2673 ldp_resource
*resource
= NULL
;
2675 MPLS_ASSERT(global
!=NULL
);
2677 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2679 mpls_lock_get(global
->global_lock
); /* LOCK */
2681 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2684 goto ldp_cfg_resource_get_end
;
2687 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2688 r
->max_rate
= resource
->max_rate
;
2690 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2691 r
->mean_rate
= resource
->mean_rate
;
2693 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2694 r
->burst_size
= resource
->burst_size
;
2696 retval
= MPLS_SUCCESS
;
2698 ldp_cfg_resource_get_end
:
2700 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2702 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2707 /******************* HOP **********************/
2709 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2712 ldp_global
*global
= (ldp_global
*) handle
;
2713 mpls_return_enum retval
= MPLS_FAILURE
;
2714 ldp_hop_list
*hop_list
= NULL
;
2715 ldp_hop
*hop
= NULL
;
2717 MPLS_ASSERT(global
!=NULL
);
2719 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2721 if (!h
->hop_list_index
&& !h
->index
) {
2725 mpls_lock_get(global
->global_lock
); /* LOCK */
2727 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2730 if (flag
& LDP_CFG_ADD
) {
2731 if (!(hop_list
= ldp_hop_list_create())) {
2732 goto ldp_cfg_hop_set_end
;
2734 _ldp_global_add_hop_list(global
, hop_list
);
2736 h
->hop_list_index
= hop_list
->index
;
2738 goto ldp_cfg_hop_set_end
;
2742 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2744 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2745 if (!(hop
= ldp_hop_create())) {
2746 goto ldp_cfg_hop_set_end
;
2748 hop
->index
= h
->index
;
2749 ldp_hop_list_add_hop(hop_list
, hop
);
2751 goto ldp_cfg_hop_set_end
;
2755 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2756 hop
->path_option
= h
->path_option
;
2758 if (flag
& LDP_HOP_CFG_ADDR
) {
2759 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2761 if (flag
& LDP_HOP_CFG_TYPE
) {
2762 hop
->type
= h
->type
;
2764 retval
= MPLS_SUCCESS
;
2766 ldp_cfg_hop_set_end
:
2768 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2770 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2775 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2778 ldp_global
*global
= (ldp_global
*) handle
;
2779 mpls_return_enum retval
= MPLS_FAILURE
;
2780 ldp_hop_list
*hop_list
= NULL
;
2781 ldp_hop
*hop
= NULL
;
2783 MPLS_ASSERT(global
!=NULL
);
2785 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2787 mpls_lock_get(global
->global_lock
); /* LOCK */
2789 if (flag
& LDP_CFG_ADD
) {
2790 retval
= MPLS_SUCCESS
;
2791 goto ldp_cfg_hop_test_end
;
2794 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2797 goto ldp_cfg_hop_test_end
;
2800 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2802 goto ldp_cfg_hop_test_end
;
2805 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2806 goto ldp_cfg_hop_test_end
;
2808 retval
= MPLS_SUCCESS
;
2810 ldp_cfg_hop_test_end
:
2812 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2814 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2819 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2822 ldp_global
*global
= (ldp_global
*) handle
;
2823 mpls_return_enum retval
= MPLS_FAILURE
;
2824 ldp_hop_list
*hop_list
= NULL
;
2825 ldp_hop
*hop
= NULL
;
2827 MPLS_ASSERT(global
!=NULL
);
2829 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2831 mpls_lock_get(global
->global_lock
); /* LOCK */
2833 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2836 goto ldp_cfg_hop_get_end
;
2839 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2841 goto ldp_cfg_hop_get_end
;
2844 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2845 h
->path_option
= hop
->path_option
;
2847 if (flag
& LDP_HOP_CFG_ADDR
) {
2848 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2850 if (flag
& LDP_HOP_CFG_TYPE
) {
2851 h
->type
= hop
->type
;
2853 retval
= MPLS_SUCCESS
;
2855 ldp_cfg_hop_get_end
:
2857 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2859 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");