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 void ldp_cfg_global_attr(mpls_cfg_handle handle
) {
50 ldp_global
*global
= (ldp_global
*) handle
;
51 ldp_attr
*attr
= MPLS_LIST_HEAD(&global
->attr
);
53 if (attr
->state
== LDP_LSP_STATE_MAP_SENT
&& attr
->ds_attr
) {
54 fprintf(stderr
, "%p(%s) xc to %p(%s)\n", attr
,
55 attr
->session
->session_name
, attr
->ds_attr
,
56 attr
->ds_attr
->session
->session_name
);
58 attr
= MPLS_LIST_NEXT(&global
->attr
, attr
, _global
);
62 mpls_return_enum
ldp_cfg_global_get(mpls_cfg_handle handle
, ldp_global
* g
,
65 ldp_global
*global
= (ldp_global
*) handle
;
67 MPLS_ASSERT(global
!=NULL
);
69 LDP_ENTER(global
->user_data
, "ldp_cfg_global_get");
71 mpls_lock_get(global
->global_lock
); /* LOCK */
73 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
74 memcpy(&(g
->lsr_identifier
), &(global
->lsr_identifier
),
75 sizeof(mpls_inet_addr
));
77 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
78 g
->admin_state
= global
->admin_state
;
80 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
81 g
->lsp_control_mode
= global
->lsp_control_mode
;
83 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
84 g
->label_retention_mode
= global
->label_retention_mode
;
86 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
87 g
->lsp_repair_mode
= global
->lsp_repair_mode
;
89 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
90 g
->propagate_release
= global
->propagate_release
;
92 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
93 g
->label_merge
= global
->label_merge
;
95 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
96 g
->loop_detection_mode
= global
->loop_detection_mode
;
98 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
99 g
->ttl_less_domain
= global
->ttl_less_domain
;
101 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
102 g
->local_tcp_port
= global
->local_tcp_port
;
104 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
105 g
->local_udp_port
= global
->local_udp_port
;
107 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
108 memcpy(&(g
->transport_address
), &(global
->transport_address
),
109 sizeof(mpls_inet_addr
));
111 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
112 g
->keepalive_timer
= global
->keepalive_timer
;
114 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
115 g
->keepalive_interval
= global
->keepalive_interval
;
117 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
118 g
->hellotime_timer
= global
->hellotime_timer
;
120 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
121 g
->hellotime_interval
= global
->hellotime_interval
;
124 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
125 g
->lsr_handle
= global
->lsr_handle
;
129 mpls_lock_release(global
->global_lock
); /* UNLOCK */
131 LDP_EXIT(global
->user_data
, "ldp_cfg_global_get");
136 mpls_return_enum
ldp_cfg_global_test(mpls_cfg_handle handle
, ldp_global
* g
,
139 ldp_global
*global
= (ldp_global
*) handle
;
140 mpls_return_enum retval
= MPLS_SUCCESS
;
142 MPLS_ASSERT(global
!=NULL
);
144 LDP_ENTER(global
->user_data
, "ldp_cfg_global_test");
146 mpls_lock_get(global
->global_lock
); /* LOCK */
148 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
))
149 retval
= MPLS_FAILURE
;
151 mpls_lock_release(global
->global_lock
); /* UNLOCK */
153 LDP_EXIT(global
->user_data
, "ldp_cfg_global_test");
158 mpls_return_enum
ldp_cfg_global_set(mpls_cfg_handle handle
, ldp_global
* g
,
161 ldp_global
*global
= (ldp_global
*) handle
;
162 mpls_return_enum retval
= MPLS_FAILURE
;
164 MPLS_ASSERT(global
!=NULL
);
166 LDP_ENTER(global
->user_data
, "ldp_cfg_global_set");
168 mpls_lock_get(global
->global_lock
); /* LOCK */
170 if ((global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
)))
171 goto ldp_cfg_global_set_end
;
173 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
174 global
->lsp_control_mode
= g
->lsp_control_mode
;
176 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
177 global
->label_retention_mode
= g
->label_retention_mode
;
179 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
180 global
->lsp_repair_mode
= g
->lsp_repair_mode
;
182 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
183 global
->propagate_release
= g
->propagate_release
;
185 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
186 global
->label_merge
= g
->label_merge
;
188 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
189 global
->loop_detection_mode
= g
->loop_detection_mode
;
191 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
192 global
->ttl_less_domain
= g
->ttl_less_domain
;
194 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
195 global
->local_tcp_port
= g
->local_tcp_port
;
197 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
198 global
->local_udp_port
= g
->local_udp_port
;
200 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
201 memcpy(&(global
->lsr_identifier
), &(g
->lsr_identifier
),
202 sizeof(mpls_inet_addr
));
205 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
206 global
->lsr_handle
= g
->lsr_handle
;
209 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
210 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& g
->admin_state
== MPLS_ADMIN_DISABLE
) {
211 ldp_global_shutdown(global
);
212 } else if (global
->admin_state
== MPLS_ADMIN_DISABLE
&& g
->admin_state
==
214 ldp_global_startup(global
);
217 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
218 memcpy(&(global
->transport_address
), &(g
->transport_address
),
219 sizeof(mpls_inet_addr
));
221 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
222 if (g
->keepalive_timer
== 0) {
223 global
->keepalive_timer
= LDP_ENTITY_DEF_KEEPALIVE_TIMER
;
225 global
->keepalive_timer
= g
->keepalive_timer
;
228 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
229 if (g
->keepalive_interval
== 0) {
230 global
->keepalive_interval
= LDP_ENTITY_DEF_KEEPALIVE_INTERVAL
;
232 global
->keepalive_interval
= g
->keepalive_interval
;
235 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
236 if (g
->hellotime_timer
== 0) {
237 global
->hellotime_timer
= LDP_ENTITY_DEF_HELLOTIME_TIMER
;
239 global
->hellotime_timer
= g
->hellotime_timer
;
242 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
243 if (g
->hellotime_interval
== 0) {
244 global
->hellotime_interval
= LDP_ENTITY_DEF_HELLOTIME_INTERVAL
;
246 global
->hellotime_interval
= g
->hellotime_interval
;
250 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
251 global
->lsr_handle
= g
->lsr_handle
;
254 global
->configuration_sequence_number
++;
256 retval
= MPLS_SUCCESS
;
258 ldp_cfg_global_set_end
:
260 mpls_lock_release(global
->global_lock
); /* UNLOCK */
262 LDP_EXIT(global
->user_data
, "ldp_cfg_global_set");
267 /******************* ENTITY **********************/
269 /* must set ldp_entity->index */
270 mpls_return_enum
ldp_cfg_entity_get(mpls_cfg_handle handle
, ldp_entity
* e
,
273 ldp_global
*global
= (ldp_global
*) handle
;
274 ldp_entity
*entity
= NULL
;
275 mpls_return_enum retval
= MPLS_FAILURE
;
277 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
279 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_get");
281 mpls_lock_get(global
->global_lock
); /* LOCK */
283 if (ldp_global_find_entity_index(global
, e
->index
, &entity
) != MPLS_SUCCESS
)
284 goto ldp_cfg_entity_get_end
;
286 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
287 e
->admin_state
= entity
->admin_state
;
289 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
290 e
->transport_address
= entity
->transport_address
;
292 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
293 e
->protocol_version
= entity
->protocol_version
;
295 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
296 e
->remote_tcp_port
= entity
->remote_tcp_port
;
298 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
299 e
->remote_udp_port
= entity
->remote_udp_port
;
301 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
302 e
->max_pdu
= entity
->max_pdu
;
304 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
305 e
->keepalive_timer
= entity
->keepalive_timer
;
307 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
308 e
->keepalive_interval
= entity
->keepalive_interval
;
310 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
311 e
->hellotime_timer
= entity
->hellotime_timer
;
313 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
314 e
->hellotime_interval
= entity
->hellotime_interval
;
316 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
317 e
->session_setup_count
= entity
->session_setup_count
;
319 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
320 e
->session_backoff_timer
= entity
->session_backoff_timer
;
322 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
323 e
->label_distribution_mode
= entity
->label_distribution_mode
;
325 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
326 e
->path_vector_limit
= entity
->path_vector_limit
;
328 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
329 e
->hop_count_limit
= entity
->hop_count_limit
;
331 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
332 e
->label_request_count
= entity
->label_request_count
;
334 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
335 e
->label_request_timer
= entity
->label_request_timer
;
337 if (flag
& LDP_ENTITY_CFG_TYPE
) {
338 e
->entity_type
= entity
->entity_type
;
340 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
341 e
->sub_index
= entity
->sub_index
;
343 if (flag
& LDP_ENTITY_CFG_MESG_TX
) {
344 e
->mesg_tx
= entity
->mesg_tx
;
346 if (flag
& LDP_ENTITY_CFG_MESG_RX
) {
347 e
->mesg_rx
= entity
->mesg_rx
;
349 if (flag
& LDP_ENTITY_CFG_ADJ_COUNT
) {
350 e
->adj_count
= entity
->adj_root
.count
;
352 if (flag
& LDP_ENTITY_CFG_ADJ_INDEX
) {
353 ldp_adj
*a
= MPLS_LIST_HEAD(&entity
->adj_root
);
354 e
->adj_index
= a
? a
->index
: 0;
356 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
357 e
->inherit_flag
= entity
->inherit_flag
;
359 retval
= MPLS_SUCCESS
;
361 ldp_cfg_entity_get_end
:
363 mpls_lock_release(global
->global_lock
); /* UNLOCK */
365 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_get");
370 mpls_return_enum
ldp_cfg_entity_getnext(mpls_cfg_handle handle
, ldp_entity
* e
,
373 ldp_global
*g
= (ldp_global
*) handle
;
374 ldp_entity
*entity
= NULL
;
375 mpls_return_enum r
= MPLS_FAILURE
;
376 mpls_bool done
= MPLS_BOOL_FALSE
;
379 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_getnext");
384 index
= e
->index
+ 1;
387 mpls_lock_get(g
->global_lock
); /* LOCK */
388 while (done
== MPLS_BOOL_FALSE
) {
389 switch ((r
= ldp_global_find_entity_index(g
, index
, &entity
))) {
391 case MPLS_END_OF_LIST
:
392 done
= MPLS_BOOL_TRUE
;
401 mpls_lock_release(g
->global_lock
); /* UNLOCK */
403 if (r
== MPLS_SUCCESS
) {
404 e
->index
= entity
->index
;
405 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
406 return ldp_cfg_entity_get(g
, e
, flag
);
408 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
412 mpls_return_enum
ldp_cfg_entity_test(mpls_cfg_handle handle
, ldp_entity
* e
,
415 ldp_global
*global
= (ldp_global
*) handle
;
416 ldp_entity
*entity
= NULL
;
417 mpls_return_enum retval
= MPLS_FAILURE
;
419 MPLS_ASSERT(global
!=NULL
);
421 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_test");
423 mpls_lock_get(global
->global_lock
); /* LOCK */
425 if (!(flag
& LDP_CFG_ADD
)) {
427 goto ldp_cfg_entity_test_end
;
429 ldp_global_find_entity_index(global
, e
->index
, &entity
);
431 retval
= MPLS_SUCCESS
;
432 goto ldp_cfg_entity_test_end
;
435 if (entity
== NULL
) {
436 goto ldp_cfg_entity_test_end
;
439 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
440 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
441 goto ldp_cfg_entity_test_end
;
444 retval
= MPLS_SUCCESS
;
446 ldp_cfg_entity_test_end
:
447 mpls_lock_release(global
->global_lock
); /* UNLOCK */
449 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_test");
454 /* must set ldp_entity->index if not an add */
455 mpls_return_enum
ldp_cfg_entity_set(mpls_cfg_handle handle
, ldp_entity
* e
,
458 ldp_global
*global
= (ldp_global
*) handle
;
459 ldp_entity
*entity
= NULL
;
460 mpls_return_enum retval
= MPLS_FAILURE
;
462 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
464 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_set");
466 mpls_lock_get(global
->global_lock
); /* LOCK */
468 if (flag
& LDP_CFG_ADD
) {
469 entity
= ldp_entity_create();
470 _ldp_global_add_entity(global
, entity
);
472 e
->index
= entity
->index
;
474 ldp_global_find_entity_index(global
, e
->index
, &entity
);
477 if (entity
== NULL
) {
478 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: can't find entity\n");
479 goto ldp_cfg_entity_set_end
;
482 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
483 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
484 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity is active\n");
485 goto ldp_cfg_entity_set_end
;
488 if (flag
& LDP_CFG_DEL
) {
489 switch (entity
->entity_type
) {
491 ldp_entity_del_if(global
, entity
);
494 ldp_entity_del_peer(entity
);
499 _ldp_global_del_entity(global
, entity
);
501 retval
= MPLS_SUCCESS
;
502 goto ldp_cfg_entity_set_end
;
505 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
506 if (entity
->sub_index
!= 0) {
507 /* unlink the old sub object */
508 switch (entity
->entity_type
) {
510 ldp_entity_del_if(global
, entity
);
513 ldp_entity_del_peer(entity
);
520 /* link the new sub object */
521 switch (e
->entity_type
) {
525 if (ldp_global_find_if_index(global
, e
->sub_index
,
526 &iff
) != MPLS_SUCCESS
) {
527 LDP_PRINT(global
->user_data
,
528 "ldp_cfg_entity_set: no such interface\n");
530 if (flag
& LDP_CFG_ADD
) {
531 _ldp_global_del_entity(global
, entity
);
533 goto ldp_cfg_entity_set_end
;
535 ldp_entity_add_if(entity
, iff
);
540 ldp_peer
*peer
= NULL
;
542 if (ldp_global_find_peer_index(global
, e
->sub_index
, &peer
) !=
544 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: no such peer\n");
546 if (flag
& LDP_CFG_ADD
) {
547 _ldp_global_del_entity(global
, entity
);
549 goto ldp_cfg_entity_set_end
;
551 ldp_entity_add_peer(entity
, peer
);
559 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
560 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
561 entity
->inherit_flag
|= LDP_ENTITY_CFG_TRANS_ADDR
;
563 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_TRANS_ADDR
;
565 memcpy(&entity
->transport_address
, &e
->transport_address
,
566 sizeof(mpls_inet_addr
));;
568 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
569 entity
->protocol_version
= e
->protocol_version
;
571 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
572 entity
->remote_tcp_port
= e
->remote_tcp_port
;
574 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
575 entity
->remote_udp_port
= e
->remote_udp_port
;
577 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
578 entity
->max_pdu
= e
->max_pdu
;
580 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
581 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
582 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
584 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
586 entity
->keepalive_timer
= e
->keepalive_timer
;
588 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
589 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
590 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
592 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
594 entity
->keepalive_interval
= e
->keepalive_interval
;
596 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
597 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
598 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_TIMER
;
600 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_TIMER
;
602 entity
->hellotime_timer
= e
->hellotime_timer
;
604 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
605 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
606 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
608 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
610 entity
->hellotime_interval
= e
->hellotime_interval
;
612 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
613 entity
->session_setup_count
= e
->session_setup_count
;
615 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
616 entity
->session_backoff_timer
= e
->session_backoff_timer
;
618 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
619 entity
->label_distribution_mode
= e
->label_distribution_mode
;
621 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
622 entity
->path_vector_limit
= e
->path_vector_limit
;
624 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
625 entity
->hop_count_limit
= e
->hop_count_limit
;
627 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
628 entity
->label_request_count
= e
->label_request_count
;
630 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
631 entity
->label_request_timer
= e
->label_request_timer
;
633 if (flag
& LDP_ENTITY_CFG_TYPE
) {
634 entity
->entity_type
= e
->entity_type
;
636 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
637 if (ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
&&
638 e
->admin_state
== MPLS_ADMIN_DISABLE
) {
639 if (ldp_entity_shutdown(global
, entity
, 0) == MPLS_FAILURE
) {
640 goto ldp_cfg_entity_set_end
;
642 } else if (ldp_entity_is_active(entity
) == MPLS_BOOL_FALSE
&&
643 e
->admin_state
== MPLS_ADMIN_ENABLE
&& ldp_entity_is_ready(entity
) == MPLS_BOOL_TRUE
) {
644 if (ldp_entity_startup(global
, entity
) == MPLS_FAILURE
) {
645 goto ldp_cfg_entity_set_end
;
648 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity not ready\n");
650 goto ldp_cfg_entity_set_end
;
653 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
654 entity
->inherit_flag
= e
->inherit_flag
;
656 global
->configuration_sequence_number
++;
658 retval
= MPLS_SUCCESS
;
660 ldp_cfg_entity_set_end
:
661 mpls_lock_release(global
->global_lock
); /* UNLOCK */
663 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_set");
668 mpls_return_enum
ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle
,
671 ldp_global
*g
= (ldp_global
*) handle
;
672 mpls_bool this_one
= MPLS_BOOL_FALSE
;
673 mpls_return_enum r
= MPLS_FAILURE
;
674 ldp_adj
*adj_next
= NULL
;
676 ldp_entity
*entity
= NULL
;
678 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_adj_getnext");
680 /* if an adj_index of zero is sent, get the index of
681 * the first adj in the list
684 this_one
= MPLS_BOOL_TRUE
;
687 mpls_lock_get(g
->global_lock
); /* LOCK */
689 if (ldp_global_find_entity_index(g
, e
->index
, &entity
) == MPLS_SUCCESS
) {
690 adj
= MPLS_LIST_HEAD(&entity
->adj_root
);
692 if (this_one
== MPLS_BOOL_TRUE
) {
697 /* since the entities are sort in the list ... */
698 if (adj
->index
> e
->adj_index
) {
700 } else if (adj
->index
== e
->adj_index
) {
701 this_one
= MPLS_BOOL_TRUE
;
703 adj
= MPLS_LIST_NEXT(&entity
->adj_root
, adj
, _entity
);
706 mpls_lock_release(g
->global_lock
); /* UNLOCK */
709 e
->adj_index
= adj_next
->index
;
713 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_adj_getnext");
717 /******************* INTERFACE **********************/
719 mpls_return_enum
ldp_cfg_if_get(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
721 ldp_global
*global
= (ldp_global
*) handle
;
723 mpls_return_enum retval
= MPLS_FAILURE
;
725 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
727 LDP_ENTER(global
->user_data
, "ldp_cfg_if_get");
729 mpls_lock_get(global
->global_lock
); /* LOCK */
731 if (flag
& LDP_IF_CFG_BY_INDEX
) {
732 ldp_global_find_if_index(global
, i
->index
, &iff
);
734 iff
= ldp_global_find_if_handle(global
, i
->handle
);
737 goto ldp_cfg_if_get_end
;
739 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
740 i
->label_space
= iff
->label_space
;
742 if (flag
& LDP_IF_CFG_ENTITY_INDEX
) {
743 i
->entity_index
= iff
->entity
? iff
->entity
->index
: 0;
745 if (flag
& LDP_IF_CFG_OPER_STATE
) {
746 i
->oper_state
= iff
->oper_state
;
748 if (flag
& LDP_IF_CFG_HANDLE
) {
749 memcpy(&i
->handle
, &iff
->handle
, sizeof(mpls_if_handle
));
751 retval
= MPLS_SUCCESS
;
754 mpls_lock_release(global
->global_lock
); /* UNLOCK */
756 LDP_EXIT(global
->user_data
, "ldp_cfg_if_get");
761 mpls_return_enum
ldp_cfg_if_getnext(mpls_cfg_handle handle
, ldp_if
* i
,
764 ldp_global
*g
= (ldp_global
*) handle
;
766 mpls_return_enum r
= MPLS_FAILURE
;
767 mpls_bool done
= MPLS_BOOL_FALSE
;
770 LDP_ENTER(g
->user_data
, "ldp_cfg_if_getnext");
775 index
= i
->index
+ 1;
778 mpls_lock_get(g
->global_lock
); /* LOCK */
779 while (done
== MPLS_BOOL_FALSE
) {
780 switch ((r
= ldp_global_find_if_index(g
, index
, &iff
))) {
782 case MPLS_END_OF_LIST
:
783 done
= MPLS_BOOL_TRUE
;
792 mpls_lock_release(g
->global_lock
); /* UNLOCK */
794 if (r
== MPLS_SUCCESS
) {
795 i
->index
= iff
->index
;
796 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
797 return ldp_cfg_if_get(g
, i
, flag
);
799 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
803 mpls_return_enum
ldp_cfg_if_test(mpls_cfg_handle handle
, ldp_if
* i
,
806 ldp_global
*global
= (ldp_global
*) handle
;
808 mpls_return_enum retval
= MPLS_FAILURE
;
810 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
812 LDP_ENTER(global
->user_data
, "ldp_cfg_if_test");
814 mpls_lock_get(global
->global_lock
); /* LOCK */
816 if (!(flag
& LDP_CFG_ADD
)) {
817 ldp_global_find_if_index(global
, i
->index
, &iff
);
819 retval
= MPLS_SUCCESS
;
820 goto ldp_cfg_if_test_end
;
823 if ((!iff
) || ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
824 (flag
& LDP_IF_CFG_WHEN_DOWN
))) {
825 goto ldp_cfg_if_test_end
;
828 if (flag
& LDP_CFG_DEL
) {
829 if (iff
->entity
!= NULL
) {
830 goto ldp_cfg_if_test_end
;
833 retval
= MPLS_SUCCESS
;
836 mpls_lock_release(global
->global_lock
); /* UNLOCK */
838 LDP_EXIT(global
->user_data
, "ldp_cfg_if_test");
843 mpls_return_enum
ldp_cfg_if_set(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
845 ldp_global
*global
= (ldp_global
*)handle
;
849 mpls_return_enum retval
= MPLS_FAILURE
;
851 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
853 LDP_ENTER(global
->user_data
, "ldp_cfg_if_set");
855 mpls_lock_get(global
->global_lock
); /* LOCK */
857 if (flag
& LDP_CFG_ADD
) {
858 /* duplicate interface handles are not allowed */
859 /* ADDs require a valid interface handle */
860 if (((iff
= ldp_global_find_if_handle(global
, i
->handle
)) != NULL
) ||
861 (mpls_if_handle_verify(global
->ifmgr_handle
, i
->handle
) ==
862 MPLS_BOOL_FALSE
) || ((iff
= ldp_if_create(global
)) == NULL
)) {
863 goto ldp_cfg_if_set_end
;
866 /* copy the handle from the user */
867 iff
->handle
= i
->handle
;
869 /* search for addrs and nexthops that are waiting for this interface */
870 ap
= MPLS_LIST_HEAD(&global
->addr
);
872 if (ap
->if_handle
== iff
->handle
&& (!MPLS_LIST_IN_LIST(ap
, _if
))) {
873 ldp_if_add_addr(iff
, ap
);
875 ap
= MPLS_LIST_NEXT(&global
->addr
, ap
, _global
);
878 np
= MPLS_LIST_HEAD(&global
->nexthop
);
880 if ((np
->info
.type
& MPLS_NH_IF
) &&
881 (np
->info
.if_handle
== iff
->handle
) && (!MPLS_LIST_IN_LIST(np
, _if
))) {
882 ldp_if_add_nexthop(iff
, np
);
884 np
= MPLS_LIST_NEXT(&global
->nexthop
, np
, _global
);
887 /* send the newly created index back to the user */
888 i
->index
= iff
->index
;
891 if (flag
& LDP_IF_CFG_BY_INDEX
) {
892 ldp_global_find_if_index(global
, i
->index
, &iff
);
894 iff
= ldp_global_find_if_handle(global
, i
->handle
);
899 * if we can't find this interface or if the interface is active and
900 * we are trying to change propertises that can not be changed on a
903 if ((!iff
) || ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
904 (flag
& LDP_IF_CFG_WHEN_DOWN
))) {
905 goto ldp_cfg_if_set_end
;
908 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
909 iff
->label_space
= i
->label_space
;
912 if (flag
& LDP_CFG_DEL
) {
914 * if this interface is still attached to a entity that it is not ready
917 if (iff
->entity
!= NULL
) {
918 goto ldp_cfg_if_set_end
;
921 np
= MPLS_LIST_HEAD(&iff
->nh_root
);
923 ldp_if_del_nexthop(global
, iff
, np
);
924 np
= MPLS_LIST_NEXT(&iff
->nh_root
, np
, _if
);
927 ap
= MPLS_LIST_HEAD(&iff
->addr_root
);
929 ldp_if_del_addr(global
, iff
, ap
);
930 ap
= MPLS_LIST_NEXT(&iff
->addr_root
, ap
, _if
);
933 MPLS_REFCNT_RELEASE2(global
, iff
, ldp_if_delete
);
936 global
->configuration_sequence_number
++;
938 retval
= MPLS_SUCCESS
;
941 mpls_lock_release(global
->global_lock
); /* UNLOCK */
943 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
948 /******************* ATTR **********************/
950 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
953 ldp_global
*global
= (ldp_global
*) handle
;
954 ldp_attr
*attr
= NULL
;
955 mpls_return_enum retval
= MPLS_FAILURE
;
957 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
959 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
961 mpls_lock_get(global
->global_lock
); /* LOCK */
963 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
964 goto ldp_cfg_attr_get_end
;
966 if (flag
& LDP_ATTR_CFG_STATE
) {
967 a
->state
= attr
->state
;
969 if (flag
& LDP_ATTR_CFG_FEC
) {
970 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
972 if (flag
& LDP_ATTR_CFG_LABEL
) {
973 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
975 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
976 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
978 if (flag
& LDP_ATTR_CFG_PATH
) {
979 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
981 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
982 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
984 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
985 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
987 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
988 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
990 if (flag
& LDP_ATTR_CFG_INGRESS
) {
991 a
->ingress
= attr
->ingress
;
993 retval
= MPLS_SUCCESS
;
995 ldp_cfg_attr_get_end
:
996 mpls_lock_release(global
->global_lock
); /* UNLOCK */
998 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
1003 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
1006 ldp_global
*g
= (ldp_global
*) handle
;
1007 ldp_attr
*attr
= NULL
;
1008 mpls_return_enum r
= MPLS_FAILURE
;
1009 mpls_bool done
= MPLS_BOOL_FALSE
;
1012 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
1014 if (a
->index
== 0) {
1017 index
= a
->index
+ 1;
1020 mpls_lock_get(g
->global_lock
); /* LOCK */
1021 while (done
== MPLS_BOOL_FALSE
) {
1022 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
1024 case MPLS_END_OF_LIST
:
1025 done
= MPLS_BOOL_TRUE
;
1034 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1036 if (r
== MPLS_SUCCESS
) {
1037 a
->index
= attr
->index
;
1038 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1039 return ldp_cfg_attr_get(g
, a
, flag
);
1041 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1045 /******************* PEER **********************/
1047 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
1050 ldp_global
*global
= (ldp_global
*) handle
;
1051 ldp_peer
*peer
= NULL
;
1052 mpls_return_enum retval
= MPLS_FAILURE
;
1054 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1056 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
1058 mpls_lock_get(global
->global_lock
); /* LOCK */
1060 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
1061 goto ldp_cfg_peer_get_end
;
1063 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1064 p
->label_space
= peer
->label_space
;
1066 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1067 p
->target_role
= peer
->target_role
;
1069 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1070 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1072 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1073 p
->entity_index
= peer
->entity
->index
;
1075 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1076 p
->oper_state
= peer
->oper_state
;
1078 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1079 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1081 retval
= MPLS_SUCCESS
;
1083 ldp_cfg_peer_get_end
:
1084 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1086 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1091 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1094 ldp_global
*g
= (ldp_global
*) handle
;
1095 ldp_peer
*peer
= NULL
;
1096 mpls_return_enum r
= MPLS_FAILURE
;
1097 mpls_bool done
= MPLS_BOOL_FALSE
;
1100 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1102 if (p
->index
== 0) {
1105 index
= p
->index
+ 1;
1108 mpls_lock_get(g
->global_lock
); /* LOCK */
1109 while (done
== MPLS_BOOL_FALSE
) {
1110 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1112 case MPLS_END_OF_LIST
:
1113 done
= MPLS_BOOL_TRUE
;
1122 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1124 if (r
== MPLS_SUCCESS
) {
1125 p
->index
= peer
->index
;
1126 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1127 return ldp_cfg_peer_get(g
, p
, flag
);
1129 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1133 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1136 // ldp_global* g = (ldp_global*)handle;
1137 return MPLS_SUCCESS
;
1140 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1143 ldp_global
*global
= (ldp_global
*) handle
;
1144 ldp_peer
*peer
= NULL
;
1145 mpls_return_enum retval
= MPLS_FAILURE
;
1147 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1149 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1151 mpls_lock_get(global
->global_lock
); /* LOCK */
1153 if (flag
& LDP_CFG_ADD
) {
1154 if ((peer
= ldp_peer_create()) == NULL
) {
1155 goto ldp_cfg_peer_set_end
;
1157 p
->index
= peer
->index
;
1158 _ldp_global_add_peer(global
, peer
);
1160 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1164 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1166 goto ldp_cfg_peer_set_end
;
1168 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1169 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1171 goto ldp_cfg_peer_set_end
;
1174 if (flag
& LDP_CFG_DEL
) {
1175 if (peer
->entity
!= NULL
) {
1176 LDP_PRINT(global
->user_data
,
1177 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1179 goto ldp_cfg_peer_set_end
;
1182 _ldp_global_del_peer(global
, peer
);
1184 retval
= MPLS_SUCCESS
;
1185 goto ldp_cfg_peer_set_end
;
1187 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1188 peer
->label_space
= p
->label_space
;
1190 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1191 peer
->target_role
= p
->target_role
;
1193 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1194 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1196 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1197 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1200 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1202 global
->configuration_sequence_number
++;
1204 retval
= MPLS_SUCCESS
;
1206 ldp_cfg_peer_set_end
:
1207 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1209 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1213 /******************* FEC **********************/
1215 mpls_return_enum
ldp_cfg_fec_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1218 ldp_global
*global
= (ldp_global
*) handle
;
1219 ldp_fec
*fec
= NULL
;
1220 mpls_return_enum retval
= MPLS_FAILURE
;
1222 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1224 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get");
1226 mpls_lock_get(global
->global_lock
); /* LOCK */
1228 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1229 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1231 fec
= ldp_fec_find(global
, f
);
1234 goto ldp_cfg_fec_get_end
;
1236 memcpy(f
, &fec
->info
, sizeof(mpls_fec
));
1237 f
->index
= fec
->index
;
1238 retval
= MPLS_SUCCESS
;
1240 ldp_cfg_fec_get_end
:
1241 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1243 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get");
1248 mpls_return_enum
ldp_cfg_fec_getnext(mpls_cfg_handle handle
, mpls_fec
* f
,
1251 ldp_global
*g
= (ldp_global
*) handle
;
1252 ldp_fec
*fec
= NULL
;
1253 mpls_return_enum r
= MPLS_FAILURE
;
1254 mpls_bool done
= MPLS_BOOL_FALSE
;
1257 LDP_ENTER(g
->user_data
, "ldp_cfg_fec_getnext");
1259 if (f
->index
== 0) {
1262 index
= f
->index
+ 1;
1265 mpls_lock_get(g
->global_lock
); /* LOCK */
1266 while (done
== MPLS_BOOL_FALSE
) {
1267 switch ((r
= ldp_global_find_fec_index(g
, index
, &fec
))) {
1269 case MPLS_END_OF_LIST
:
1270 done
= MPLS_BOOL_TRUE
;
1279 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1281 if (r
== MPLS_SUCCESS
) {
1282 f
->index
= fec
->index
;
1283 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1284 return ldp_cfg_fec_get(g
, f
, flag
);
1286 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1290 mpls_return_enum
ldp_cfg_fec_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1293 // ldp_global* g = (ldp_global*)handle;
1294 return MPLS_SUCCESS
;
1297 mpls_return_enum
ldp_cfg_fec_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1300 ldp_global
*global
= (ldp_global
*) handle
;
1301 ldp_fec
*fec
= NULL
;
1302 mpls_return_enum retval
= MPLS_FAILURE
;
1304 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1306 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_set");
1308 mpls_lock_get(global
->global_lock
); /* LOCK */
1310 if (flag
& LDP_CFG_ADD
) {
1311 if (ldp_fec_find(global
, f
) || (fec
= ldp_fec_create(global
, f
)) == NULL
) {
1312 goto ldp_cfg_fec_set_end
;
1314 f
->index
= fec
->index
;
1316 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1317 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1319 fec
= ldp_fec_find(global
, f
);
1324 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_set: no such fec\n");
1325 goto ldp_cfg_fec_set_end
;
1328 if (flag
& LDP_CFG_DEL
) {
1332 retval
= MPLS_SUCCESS
;
1334 ldp_cfg_fec_set_end
:
1335 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1337 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1342 mpls_return_enum
ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1343 mpls_nexthop
*n
, uint32_t flag
)
1345 ldp_global
*global
= (ldp_global
*) handle
;
1346 ldp_fec
*fec
= NULL
;
1347 ldp_nexthop
*nh
= NULL
;
1348 mpls_return_enum retval
= MPLS_FAILURE
;
1350 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1352 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1354 mpls_lock_get(global
->global_lock
); /* LOCK */
1356 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1357 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1359 fec
= ldp_fec_find(global
, f
);
1362 goto ldp_cfg_fec_nexthop_get_end
;
1364 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1365 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1367 nh
= ldp_fec_nexthop_find(fec
, n
);
1370 goto ldp_cfg_fec_nexthop_get_end
;
1372 memcpy(n
, &nh
->info
, sizeof(mpls_nexthop
));
1373 n
->index
= nh
->index
;
1374 retval
= MPLS_SUCCESS
;
1376 ldp_cfg_fec_nexthop_get_end
:
1377 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1379 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1384 mpls_return_enum
ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle
,
1385 mpls_fec
* f
, mpls_nexthop
*n
, uint32_t flag
)
1387 ldp_global
*global
= (ldp_global
*) handle
;
1388 ldp_fec
*fec
= NULL
;
1389 ldp_nexthop
*nh
= NULL
;
1390 mpls_return_enum r
= MPLS_FAILURE
;
1391 mpls_bool done
= MPLS_BOOL_FALSE
;
1394 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1396 if (n
->index
== 0) {
1399 index
= n
->index
+ 1;
1402 mpls_lock_get(global
->global_lock
); /* LOCK */
1404 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1405 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1407 fec
= ldp_fec_find(global
, f
);
1410 goto ldp_cfg_fec_nexthop_getnext_end
;
1412 while (done
== MPLS_BOOL_FALSE
) {
1413 switch ((r
= ldp_fec_find_nexthop_index(fec
, index
, &nh
))) {
1415 case MPLS_END_OF_LIST
:
1416 done
= MPLS_BOOL_TRUE
;
1425 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1427 if (r
== MPLS_SUCCESS
) {
1428 n
->index
= nh
->index
;
1429 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1430 return ldp_cfg_fec_nexthop_get(global
, f
, n
, flag
);
1433 ldp_cfg_fec_nexthop_getnext_end
:
1435 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1439 mpls_return_enum
ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1440 mpls_nexthop
*n
, uint32_t flag
)
1442 // ldp_global* g = (ldp_global*)handle;
1443 return MPLS_SUCCESS
;
1446 mpls_return_enum
ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1447 mpls_nexthop
*n
, uint32_t flag
)
1449 ldp_global
*global
= (ldp_global
*) handle
;
1450 ldp_fec
*fec
= NULL
;
1451 ldp_nexthop
*nh
= NULL
;
1452 mpls_return_enum retval
= MPLS_FAILURE
;
1454 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
&& n
!= NULL
);
1456 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1458 mpls_lock_get(global
->global_lock
); /* LOCK */
1460 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1461 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1463 fec
= ldp_fec_find(global
, f
);
1466 goto ldp_cfg_fec_nexthop_set_end
;
1468 if (flag
& LDP_CFG_ADD
) {
1469 if (ldp_fec_nexthop_find(fec
, n
) || (nh
= ldp_nexthop_create()) == NULL
) {
1470 goto ldp_cfg_fec_nexthop_set_end
;
1472 n
->index
= nh
->index
;
1473 mpls_nexthop2ldp_nexthop(n
, nh
);
1474 _ldp_global_add_nexthop(global
, nh
);
1475 ldp_fec_add_nexthop(global
, fec
, nh
);
1476 ldp_fec_process_add(global
, fec
, nh
, NULL
);
1478 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1479 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1481 nh
= ldp_fec_nexthop_find(fec
, n
);
1486 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_nexthop_set: no such nh\n");
1487 goto ldp_cfg_fec_nexthop_set_end
;
1490 if (flag
& LDP_CFG_DEL
) {
1491 ldp_fec_del_nexthop(global
, fec
, nh
);
1492 if (ldp_fec_process_change(global
, fec
, MPLS_LIST_HEAD(&fec
->nh_root
),
1493 nh
, NULL
) != MPLS_SUCCESS
) {
1496 _ldp_global_del_nexthop(global
, nh
);
1499 retval
= MPLS_SUCCESS
;
1501 ldp_cfg_fec_nexthop_set_end
:
1502 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1504 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1509 /******************* ADDR **********************/
1511 mpls_return_enum
ldp_cfg_addr_get(mpls_cfg_handle handle
, ldp_addr
* a
,
1514 ldp_global
*global
= (ldp_global
*) handle
;
1515 ldp_session
*session
= NULL
;
1516 ldp_nexthop
*nexthop
= NULL
;
1517 ldp_addr
*addr
= NULL
;
1518 mpls_return_enum retval
= MPLS_FAILURE
;
1520 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1522 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_get");
1524 mpls_lock_get(global
->global_lock
); /* LOCK */
1526 ldp_global_find_addr_index(global
, a
->index
, &addr
);
1529 goto ldp_cfg_addr_get_end
;
1531 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1532 a
->index
= addr
->index
;
1534 if ((session
= mpls_link_list_head_data(&addr
->session_root
))) {
1535 a
->session_index
= session
->index
;
1538 if ((nexthop
= MPLS_LIST_HEAD(&addr
->nh_root
))) {
1539 a
->nexthop_index
= nexthop
->index
;
1543 a
->if_index
= addr
->iff
->index
;
1546 retval
= MPLS_SUCCESS
;
1548 ldp_cfg_addr_get_end
:
1549 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1551 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_get");
1556 mpls_return_enum
ldp_cfg_addr_getnext(mpls_cfg_handle handle
, ldp_addr
*a
,
1559 ldp_global
*global
= (ldp_global
*) handle
;
1560 ldp_addr
*addr
= NULL
;
1561 mpls_return_enum r
= MPLS_FAILURE
;
1562 mpls_bool done
= MPLS_BOOL_FALSE
;
1565 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_getnext");
1567 if (a
->index
== 0) {
1570 index
= a
->index
+ 1;
1573 mpls_lock_get(global
->global_lock
); /* LOCK */
1575 while (done
== MPLS_BOOL_FALSE
) {
1576 switch ((r
= ldp_global_find_addr_index(global
, index
, &addr
))) {
1578 case MPLS_END_OF_LIST
:
1579 done
= MPLS_BOOL_TRUE
;
1588 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1590 if (r
== MPLS_SUCCESS
) {
1591 a
->index
= addr
->index
;
1592 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1593 return ldp_cfg_addr_get(global
, a
, flag
);
1596 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1600 /******************* IF ADDR **********************/
1602 mpls_return_enum
ldp_cfg_if_addr_get(mpls_cfg_handle handle
, ldp_if
* i
,
1603 ldp_addr
* a
, uint32_t flag
)
1605 ldp_global
*global
= (ldp_global
*) handle
;
1606 ldp_addr
*addr
= NULL
;
1608 mpls_return_enum retval
= MPLS_FAILURE
;
1610 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1612 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_get");
1614 mpls_lock_get(global
->global_lock
); /* LOCK */
1616 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1617 ldp_global_find_if_index(global
, i
->index
, &iff
);
1619 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1622 goto ldp_cfg_if_addr_get_end
;
1624 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1625 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1627 addr
= ldp_if_addr_find(iff
, &a
->address
);
1630 goto ldp_cfg_if_addr_get_end
;
1632 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1633 a
->index
= addr
->index
;
1635 retval
= MPLS_SUCCESS
;
1637 ldp_cfg_if_addr_get_end
:
1638 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1640 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_get");
1645 mpls_return_enum
ldp_cfg_if_addr_getnext(mpls_cfg_handle handle
,
1646 ldp_if
* i
, ldp_addr
*a
, uint32_t flag
)
1648 ldp_global
*global
= (ldp_global
*) handle
;
1650 ldp_addr
*addr
= NULL
;
1651 mpls_return_enum r
= MPLS_FAILURE
;
1652 mpls_bool done
= MPLS_BOOL_FALSE
;
1655 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_getnext");
1657 if (a
->index
== 0) {
1660 index
= a
->index
+ 1;
1663 mpls_lock_get(global
->global_lock
); /* LOCK */
1665 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1666 ldp_global_find_if_index(global
, i
->index
, &iff
);
1668 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1671 goto ldp_cfg_if_addr_getnext_end
;
1673 while (done
== MPLS_BOOL_FALSE
) {
1674 switch ((r
= ldp_if_find_addr_index(iff
, index
, &addr
))) {
1676 case MPLS_END_OF_LIST
:
1677 done
= MPLS_BOOL_TRUE
;
1686 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1688 if (r
== MPLS_SUCCESS
) {
1689 a
->index
= addr
->index
;
1690 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1691 return ldp_cfg_if_addr_get(global
, i
, a
, flag
);
1694 ldp_cfg_if_addr_getnext_end
:
1696 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1700 mpls_return_enum
ldp_cfg_if_addr_set(mpls_cfg_handle handle
, ldp_if
* i
,
1701 ldp_addr
*a
, uint32_t flag
)
1703 ldp_global
*global
= (ldp_global
*) handle
;
1705 ldp_addr
*addr
= NULL
;
1706 mpls_return_enum retval
= MPLS_FAILURE
;
1708 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1710 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_set");
1712 mpls_lock_get(global
->global_lock
); /* LOCK */
1714 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1715 ldp_global_find_if_index(global
, i
->index
, &iff
);
1717 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1720 goto ldp_cfg_if_addr_set_end
;
1722 if (flag
& LDP_CFG_ADD
) {
1723 if (ldp_if_addr_find(iff
, &a
->address
) || (addr
= ldp_addr_create(global
,
1724 &a
->address
)) == NULL
) {
1725 goto ldp_cfg_if_addr_set_end
;
1727 a
->index
= addr
->index
;
1728 ldp_if_add_addr(iff
, addr
);
1730 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1731 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1733 addr
= ldp_if_addr_find(iff
, &a
->address
);
1738 LDP_PRINT(global
->user_data
, "ldp_cfg_if_addr_set: no such addr\n");
1739 goto ldp_cfg_if_addr_set_end
;
1742 if (flag
& LDP_CFG_DEL
) {
1743 ldp_if_del_addr(global
, iff
,addr
);
1746 retval
= MPLS_SUCCESS
;
1748 ldp_cfg_if_addr_set_end
:
1749 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1751 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_set");
1756 /******************* ADJACENCY **********************/
1758 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1761 ldp_global
*global
= (ldp_global
*) handle
;
1762 ldp_adj
*adj
= NULL
;
1763 mpls_return_enum retval
= MPLS_FAILURE
;
1765 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1767 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1769 mpls_lock_get(global
->global_lock
); /* LOCK */
1771 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1772 goto ldp_cfg_adj_get_end
;
1774 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1775 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1776 sizeof(mpls_inet_addr
));
1778 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1779 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1780 sizeof(mpls_inet_addr
));
1782 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1783 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1784 sizeof(mpls_inet_addr
));
1786 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1787 a
->remote_csn
= adj
->remote_csn
;
1789 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1790 a
->remote_label_space
= adj
->remote_label_space
;
1792 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1793 a
->remote_hellotime
= adj
->remote_hellotime
;
1795 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1796 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1798 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1799 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1801 if (flag
& LDP_ADJ_CFG_ROLE
) {
1802 a
->role
= adj
->role
;
1804 retval
= MPLS_SUCCESS
;
1806 ldp_cfg_adj_get_end
:
1808 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1810 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1815 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1818 ldp_global
*g
= (ldp_global
*) handle
;
1819 ldp_adj
*adj
= NULL
;
1820 mpls_return_enum r
= MPLS_FAILURE
;
1821 mpls_bool done
= MPLS_BOOL_FALSE
;
1824 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1826 if (a
->index
== 0) {
1829 index
= a
->index
+ 1;
1832 mpls_lock_get(g
->global_lock
); /* LOCK */
1833 while (done
== MPLS_BOOL_FALSE
) {
1834 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1836 case MPLS_END_OF_LIST
:
1837 done
= MPLS_BOOL_TRUE
;
1846 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1848 if (r
== MPLS_SUCCESS
) {
1849 a
->index
= adj
->index
;
1850 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1851 return ldp_cfg_adj_get(g
, a
, flag
);
1853 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1857 /******************* SESSION **********************/
1859 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1862 ldp_global
*global
= (ldp_global
*) handle
;
1863 ldp_session
*session
= NULL
;
1864 mpls_return_enum retval
= MPLS_FAILURE
;
1866 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1868 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1870 mpls_lock_get(global
->global_lock
); /* LOCK */
1872 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1873 goto ldp_cfg_session_get_end
;
1875 if (flag
& LDP_SESSION_CFG_STATE
) {
1876 s
->state
= session
->state
;
1878 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1879 s
->oper_up
= session
->oper_up
;
1881 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1882 s
->oper_max_pdu
= session
->oper_max_pdu
;
1884 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1885 s
->oper_keepalive
= session
->oper_keepalive
;
1887 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1888 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1890 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1891 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1893 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1894 s
->oper_loop_detection
= session
->oper_loop_detection
;
1896 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1897 s
->remote_max_pdu
= session
->remote_max_pdu
;
1899 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1900 s
->remote_keepalive
= session
->remote_keepalive
;
1902 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1903 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1905 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1906 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1908 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1909 s
->remote_loop_detection
= session
->remote_loop_detection
;
1911 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1912 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1913 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1915 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1916 s
->remote_dest
.port
= session
->remote_dest
.port
;
1918 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1919 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1921 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1922 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1924 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1925 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1926 s
->adj_index
= a
? a
->index
: 0;
1928 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1929 s
->mesg_tx
= session
->mesg_tx
;
1931 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1932 s
->mesg_rx
= session
->mesg_rx
;
1934 retval
= MPLS_SUCCESS
;
1936 ldp_cfg_session_get_end
:
1937 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1939 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1944 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1947 ldp_global
*g
= (ldp_global
*) handle
;
1948 ldp_session
*ses
= NULL
;
1949 mpls_return_enum r
= MPLS_FAILURE
;
1950 mpls_bool done
= MPLS_BOOL_FALSE
;
1953 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1955 if (s
->index
== 0) {
1958 index
= s
->index
+ 1;
1961 mpls_lock_get(g
->global_lock
); /* LOCK */
1962 while (done
== MPLS_BOOL_FALSE
) {
1963 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1965 case MPLS_END_OF_LIST
:
1966 done
= MPLS_BOOL_TRUE
;
1975 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1977 if (r
== MPLS_SUCCESS
) {
1978 s
->index
= ses
->index
;
1980 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1981 return ldp_cfg_session_get(g
, s
, flag
);
1984 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1989 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
1992 ldp_global
*g
= (ldp_global
*) handle
;
1993 mpls_bool this_one
= MPLS_BOOL_FALSE
;
1994 mpls_return_enum r
= MPLS_FAILURE
;
1995 ldp_adj
*adj_next
= NULL
;
1996 ldp_adj
*adj
= NULL
;
1997 ldp_session
*session
= NULL
;
1999 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
2001 /* if an adj_index of zero is sent, get the index of
2002 * the first adj in the list
2004 if (!s
->adj_index
) {
2005 this_one
= MPLS_BOOL_TRUE
;
2008 mpls_lock_get(g
->global_lock
); /* LOCK */
2010 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
2011 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
2013 if (this_one
== MPLS_BOOL_TRUE
) {
2018 /* since the entities are sort in the list ... */
2019 if (adj
->index
> s
->adj_index
) {
2021 } else if (adj
->index
== s
->adj_index
) {
2022 this_one
= MPLS_BOOL_TRUE
;
2024 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
2027 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2030 s
->adj_index
= adj_next
->index
;
2034 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
2038 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
2039 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2041 ldp_global
*global
= (ldp_global
*) handle
;
2042 ldp_session
*session
= NULL
;
2043 ldp_addr
*addr
= NULL
;
2044 mpls_return_enum retval
= MPLS_FAILURE
;
2046 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
2048 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
2050 mpls_lock_get(global
->global_lock
); /* LOCK */
2052 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
2053 goto ldp_cfg_session_raddr_get_end
;
2055 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
2056 goto ldp_cfg_session_raddr_get_end
;
2058 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
2059 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
2061 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
2062 a
->index
= addr
->index
;
2064 retval
= MPLS_SUCCESS
;
2066 ldp_cfg_session_raddr_get_end
:
2067 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2069 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
2074 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
2075 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2077 ldp_global
*g
= (ldp_global
*) handle
;
2078 ldp_addr
*addr
= NULL
;
2079 mpls_return_enum r
= MPLS_FAILURE
;
2080 mpls_bool done
= MPLS_BOOL_FALSE
;
2081 ldp_session
*sp
= NULL
;
2084 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
2086 if (a
->index
== 0) {
2089 index
= a
->index
+ 1;
2092 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
2093 if (r
!= MPLS_SUCCESS
) {
2097 mpls_lock_get(g
->global_lock
); /* LOCK */
2098 while (done
== MPLS_BOOL_FALSE
) {
2099 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
2101 case MPLS_END_OF_LIST
:
2102 done
= MPLS_BOOL_TRUE
;
2111 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2113 if (r
== MPLS_SUCCESS
) {
2114 a
->index
= addr
->index
;
2115 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
2118 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2122 /******************* IN LABEL **********************/
2124 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2127 ldp_global
*global
= (ldp_global
*) handle
;
2128 ldp_inlabel
*inlabel
= NULL
;
2129 mpls_return_enum retval
= MPLS_FAILURE
;
2131 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
2133 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
2135 mpls_lock_get(global
->global_lock
); /* LOCK */
2137 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
2138 goto ldp_cfg_inlabel_get_end
;
2140 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
2141 i
->info
.labelspace
= inlabel
->info
.labelspace
;
2143 if (flag
& LDP_INLABEL_CFG_LABEL
) {
2144 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
2146 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
2147 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
2150 retval
= MPLS_SUCCESS
;
2152 ldp_cfg_inlabel_get_end
:
2153 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2155 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
2160 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2163 ldp_global
*g
= (ldp_global
*) handle
;
2164 ldp_inlabel
*inlabel
= NULL
;
2165 mpls_return_enum r
= MPLS_FAILURE
;
2166 mpls_bool done
= MPLS_BOOL_FALSE
;
2169 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
2171 if (i
->index
== 0) {
2174 index
= i
->index
+ 1;
2177 mpls_lock_get(g
->global_lock
); /* LOCK */
2178 while (done
== MPLS_BOOL_FALSE
) {
2179 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
2181 case MPLS_END_OF_LIST
:
2182 done
= MPLS_BOOL_TRUE
;
2191 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2193 if (r
== MPLS_SUCCESS
) {
2194 i
->index
= inlabel
->index
;
2196 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2197 return ldp_cfg_inlabel_get(g
, i
, flag
);
2200 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2205 /******************* OUT LABEL **********************/
2207 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
2210 ldp_global
*global
= (ldp_global
*) handle
;
2211 ldp_outlabel
*outlabel
= NULL
;
2212 mpls_return_enum retval
= MPLS_FAILURE
;
2214 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
2216 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
2218 mpls_lock_get(global
->global_lock
); /* LOCK */
2220 if (ldp_global_find_outlabel_index(global
, o
->index
,
2221 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
2223 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
2225 o
->nh_index
= outlabel
->nh
->index
;
2230 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
2231 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
2233 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
2234 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
2236 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
2237 o
->merge_count
= outlabel
->merge_count
;
2240 retval
= MPLS_SUCCESS
;
2242 ldp_cfg_outlabel_get_end
:
2243 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2245 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
2250 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
2251 ldp_outlabel
* o
, uint32_t flag
)
2253 ldp_global
*g
= (ldp_global
*) handle
;
2254 ldp_outlabel
*outlabel
= NULL
;
2255 mpls_return_enum r
= MPLS_FAILURE
;
2256 mpls_bool done
= MPLS_BOOL_FALSE
;
2259 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
2261 if (o
->index
== 0) {
2264 index
= o
->index
+ 1;
2267 mpls_lock_get(g
->global_lock
); /* LOCK */
2268 while (done
== MPLS_BOOL_FALSE
) {
2269 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
2271 case MPLS_END_OF_LIST
:
2272 done
= MPLS_BOOL_TRUE
;
2281 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2283 if (r
== MPLS_SUCCESS
) {
2284 o
->index
= outlabel
->index
;
2286 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2287 return ldp_cfg_outlabel_get(g
, o
, flag
);
2290 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2295 /******************* TUNNEL **********************/
2297 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2300 ldp_global
*global
= (ldp_global
*) handle
;
2301 mpls_return_enum retval
= MPLS_FAILURE
;
2302 ldp_tunnel
*tunnel
= NULL
;
2304 MPLS_ASSERT(global
!=NULL
);
2306 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2308 mpls_lock_get(global
->global_lock
); /* LOCK */
2310 if (flag
& LDP_CFG_ADD
) {
2311 if (!(tunnel
= ldp_tunnel_create())) {
2312 goto ldp_cfg_tunnel_set_end
;
2314 _ldp_global_add_tunnel(global
, tunnel
);
2316 t
->index
= tunnel
->index
;
2318 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2322 LDP_PRINT(global
->user_data
,
2324 "ldp_cfg_tunnel_set:could not create tunnel\n");
2325 goto ldp_cfg_tunnel_set_end
;
2328 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2329 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2330 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2332 goto ldp_cfg_tunnel_set_end
;
2335 if (flag
& LDP_CFG_DEL
) {
2336 if (tunnel
->outlabel
)
2337 ldp_tunnel_del_outlabel(tunnel
);
2338 if (tunnel
->resource
)
2339 ldp_tunnel_del_resource(tunnel
);
2340 if (tunnel
->hop_list
)
2341 ldp_tunnel_del_hop_list(tunnel
);
2342 _ldp_global_del_tunnel(global
, tunnel
);
2344 retval
= MPLS_SUCCESS
;
2345 goto ldp_cfg_tunnel_set_end
;
2348 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2349 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2351 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2352 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2354 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2355 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2357 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2358 tunnel
->is_interface
= t
->is_interface
;
2360 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2361 ldp_outlabel
*outlabel
= NULL
;
2363 if (t
->outlabel_index
) {
2364 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2367 goto ldp_cfg_tunnel_set_end
;
2369 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2371 ldp_tunnel_del_outlabel(tunnel
);
2374 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2375 tunnel
->setup_prio
= t
->setup_prio
;
2377 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2378 tunnel
->hold_prio
= t
->hold_prio
;
2380 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2381 tunnel
->instance_prio
= t
->instance_prio
;
2383 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2384 tunnel
->local_protect
= t
->local_protect
;
2386 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2387 ldp_resource
*resource
= NULL
;
2389 if (t
->resource_index
) {
2390 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2393 goto ldp_cfg_tunnel_set_end
;
2395 ldp_tunnel_add_resource(tunnel
, resource
);
2397 ldp_tunnel_del_resource(tunnel
);
2400 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2401 ldp_hop_list
*hop_list
= NULL
;
2403 if (t
->hop_list_index
) {
2404 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2407 goto ldp_cfg_tunnel_set_end
;
2409 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2411 ldp_tunnel_del_hop_list(tunnel
);
2414 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2415 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2417 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2418 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2419 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2420 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2421 goto ldp_cfg_tunnel_set_end
;
2425 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2426 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2427 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2428 goto ldp_cfg_tunnel_set_end
;
2431 LDP_PRINT(global
->user_data
,
2433 "ldp_cfg_tunnel_set: tunnel not ready\n");
2434 goto ldp_cfg_tunnel_set_end
;
2439 retval
= MPLS_SUCCESS
;
2441 ldp_cfg_tunnel_set_end
:
2443 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2445 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2450 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2453 ldp_global
*global
= (ldp_global
*) handle
;
2454 mpls_return_enum retval
= MPLS_FAILURE
;
2455 ldp_tunnel
*tunnel
= NULL
;
2457 MPLS_ASSERT(global
!=NULL
);
2459 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2461 mpls_lock_get(global
->global_lock
); /* LOCK */
2463 if (flag
& LDP_CFG_ADD
) {
2464 retval
= MPLS_SUCCESS
;
2465 goto ldp_cfg_tunnel_test_end
;
2468 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2471 goto ldp_cfg_tunnel_test_end
;
2474 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2475 ldp_resource
*resource
= NULL
;
2477 if (t
->resource_index
) {
2478 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2481 goto ldp_cfg_tunnel_test_end
;
2485 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2486 ldp_hop_list
*hop_list
= NULL
;
2488 if (t
->hop_list_index
) {
2489 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2492 goto ldp_cfg_tunnel_test_end
;
2496 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2497 ldp_outlabel
*outlabel
= NULL
;
2499 if (t
->outlabel_index
) {
2500 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2503 goto ldp_cfg_tunnel_test_end
;
2507 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2508 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2509 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2510 goto ldp_cfg_tunnel_test_end
;
2512 retval
= MPLS_SUCCESS
;
2514 ldp_cfg_tunnel_test_end
:
2516 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2518 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2523 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2526 ldp_global
*global
= (ldp_global
*) handle
;
2527 mpls_return_enum retval
= MPLS_FAILURE
;
2528 ldp_tunnel
*tunnel
= NULL
;
2530 MPLS_ASSERT(global
!=NULL
);
2532 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2534 mpls_lock_get(global
->global_lock
); /* LOCK */
2536 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2539 goto ldp_cfg_tunnel_get_end
;
2541 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2542 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2544 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2545 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2547 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2548 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2550 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2551 t
->is_interface
= tunnel
->is_interface
;
2553 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2554 if (tunnel
->outlabel
) {
2555 t
->outlabel_index
= tunnel
->outlabel
->index
;
2557 t
->outlabel_index
= 0;
2560 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2561 t
->setup_prio
= tunnel
->setup_prio
;
2563 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2564 t
->hold_prio
= tunnel
->hold_prio
;
2566 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2567 tunnel
->instance_prio
= t
->instance_prio
;
2569 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2570 tunnel
->local_protect
= t
->local_protect
;
2572 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2573 if (tunnel
->resource
) {
2574 t
->resource_index
= tunnel
->resource
->index
;
2576 t
->resource_index
= 0;
2579 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2580 if (tunnel
->hop_list
) {
2581 t
->hop_list_index
= tunnel
->hop_list
->index
;
2583 t
->hop_list_index
= 0;
2586 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2587 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2589 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2590 t
->admin_state
= tunnel
->admin_state
;
2592 retval
= MPLS_SUCCESS
;
2594 ldp_cfg_tunnel_get_end
:
2596 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2598 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2603 /******************* RESOURCE **********************/
2605 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2608 ldp_global
*global
= (ldp_global
*) handle
;
2609 mpls_return_enum retval
= MPLS_FAILURE
;
2610 ldp_resource
*resource
= NULL
;
2612 MPLS_ASSERT(global
!=NULL
);
2614 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2616 mpls_lock_get(global
->global_lock
); /* LOCK */
2618 if (flag
& LDP_CFG_ADD
) {
2619 resource
= ldp_resource_create();
2620 _ldp_global_add_resource(global
, resource
);
2622 r
->index
= resource
->index
;
2624 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2628 goto ldp_cfg_resource_set_end
;
2631 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2632 resource
->max_rate
= r
->max_rate
;
2634 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2635 resource
->mean_rate
= r
->mean_rate
;
2637 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2638 resource
->burst_size
= r
->burst_size
;
2640 retval
= MPLS_SUCCESS
;
2642 ldp_cfg_resource_set_end
:
2644 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2646 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2651 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2654 ldp_global
*global
= (ldp_global
*) handle
;
2655 mpls_return_enum retval
= MPLS_FAILURE
;
2656 ldp_resource
*resource
= NULL
;
2658 MPLS_ASSERT(global
!=NULL
);
2660 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2662 mpls_lock_get(global
->global_lock
); /* LOCK */
2664 if (flag
& LDP_CFG_ADD
) {
2665 retval
= MPLS_SUCCESS
;
2666 goto ldp_cfg_resource_test_end
;
2669 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2672 goto ldp_cfg_resource_test_end
;
2675 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2676 goto ldp_cfg_resource_test_end
;
2678 retval
= MPLS_SUCCESS
;
2680 ldp_cfg_resource_test_end
:
2682 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2684 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2689 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2692 ldp_global
*global
= (ldp_global
*) handle
;
2693 mpls_return_enum retval
= MPLS_FAILURE
;
2694 ldp_resource
*resource
= NULL
;
2696 MPLS_ASSERT(global
!=NULL
);
2698 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2700 mpls_lock_get(global
->global_lock
); /* LOCK */
2702 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2705 goto ldp_cfg_resource_get_end
;
2708 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2709 r
->max_rate
= resource
->max_rate
;
2711 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2712 r
->mean_rate
= resource
->mean_rate
;
2714 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2715 r
->burst_size
= resource
->burst_size
;
2717 retval
= MPLS_SUCCESS
;
2719 ldp_cfg_resource_get_end
:
2721 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2723 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2728 /******************* HOP **********************/
2730 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2733 ldp_global
*global
= (ldp_global
*) handle
;
2734 mpls_return_enum retval
= MPLS_FAILURE
;
2735 ldp_hop_list
*hop_list
= NULL
;
2736 ldp_hop
*hop
= NULL
;
2738 MPLS_ASSERT(global
!=NULL
);
2740 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2742 if (!h
->hop_list_index
&& !h
->index
) {
2746 mpls_lock_get(global
->global_lock
); /* LOCK */
2748 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2751 if (flag
& LDP_CFG_ADD
) {
2752 if (!(hop_list
= ldp_hop_list_create())) {
2753 goto ldp_cfg_hop_set_end
;
2755 _ldp_global_add_hop_list(global
, hop_list
);
2757 h
->hop_list_index
= hop_list
->index
;
2759 goto ldp_cfg_hop_set_end
;
2763 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2765 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2766 if (!(hop
= ldp_hop_create())) {
2767 goto ldp_cfg_hop_set_end
;
2769 hop
->index
= h
->index
;
2770 ldp_hop_list_add_hop(hop_list
, hop
);
2772 goto ldp_cfg_hop_set_end
;
2776 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2777 hop
->path_option
= h
->path_option
;
2779 if (flag
& LDP_HOP_CFG_ADDR
) {
2780 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2782 if (flag
& LDP_HOP_CFG_TYPE
) {
2783 hop
->type
= h
->type
;
2785 retval
= MPLS_SUCCESS
;
2787 ldp_cfg_hop_set_end
:
2789 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2791 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2796 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2799 ldp_global
*global
= (ldp_global
*) handle
;
2800 mpls_return_enum retval
= MPLS_FAILURE
;
2801 ldp_hop_list
*hop_list
= NULL
;
2802 ldp_hop
*hop
= NULL
;
2804 MPLS_ASSERT(global
!=NULL
);
2806 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2808 mpls_lock_get(global
->global_lock
); /* LOCK */
2810 if (flag
& LDP_CFG_ADD
) {
2811 retval
= MPLS_SUCCESS
;
2812 goto ldp_cfg_hop_test_end
;
2815 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2818 goto ldp_cfg_hop_test_end
;
2821 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2823 goto ldp_cfg_hop_test_end
;
2826 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2827 goto ldp_cfg_hop_test_end
;
2829 retval
= MPLS_SUCCESS
;
2831 ldp_cfg_hop_test_end
:
2833 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2835 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2840 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2843 ldp_global
*global
= (ldp_global
*) handle
;
2844 mpls_return_enum retval
= MPLS_FAILURE
;
2845 ldp_hop_list
*hop_list
= NULL
;
2846 ldp_hop
*hop
= NULL
;
2848 MPLS_ASSERT(global
!=NULL
);
2850 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2852 mpls_lock_get(global
->global_lock
); /* LOCK */
2854 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2857 goto ldp_cfg_hop_get_end
;
2860 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2862 goto ldp_cfg_hop_get_end
;
2865 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2866 h
->path_option
= hop
->path_option
;
2868 if (flag
& LDP_HOP_CFG_ADDR
) {
2869 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2871 if (flag
& LDP_HOP_CFG_TYPE
) {
2872 h
->type
= hop
->type
;
2874 retval
= MPLS_SUCCESS
;
2876 ldp_cfg_hop_get_end
:
2878 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2880 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");