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
;
889 MPLS_REFCNT_HOLD(iff
);
892 if (flag
& LDP_IF_CFG_BY_INDEX
) {
893 ldp_global_find_if_index(global
, i
->index
, &iff
);
895 iff
= ldp_global_find_if_handle(global
, i
->handle
);
900 * if we can't find this interface or if the interface is active and
901 * we are trying to change propertises that can not be changed on a
904 if ((!iff
) || ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
905 (flag
& LDP_IF_CFG_WHEN_DOWN
))) {
906 goto ldp_cfg_if_set_end
;
909 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
910 iff
->label_space
= i
->label_space
;
913 if (flag
& LDP_CFG_DEL
) {
915 * if this interface is still attached to a entity that it is not ready
918 if (iff
->entity
!= NULL
) {
919 goto ldp_cfg_if_set_end
;
922 np
= MPLS_LIST_HEAD(&iff
->nh_root
);
923 while ((np
= MPLS_LIST_HEAD(&iff
->nh_root
))) {
924 ldp_if_del_nexthop(global
, iff
, np
);
927 ap
= MPLS_LIST_HEAD(&iff
->addr_root
);
928 while ((ap
= MPLS_LIST_HEAD(&iff
->addr_root
))) {
929 ldp_if_del_addr(global
, iff
, ap
);
932 MPLS_REFCNT_RELEASE2(global
, iff
, ldp_if_delete
);
935 global
->configuration_sequence_number
++;
937 retval
= MPLS_SUCCESS
;
940 mpls_lock_release(global
->global_lock
); /* UNLOCK */
942 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
947 /******************* ATTR **********************/
949 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
952 ldp_global
*global
= (ldp_global
*) handle
;
953 ldp_attr
*attr
= NULL
;
954 mpls_return_enum retval
= MPLS_FAILURE
;
956 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
958 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
960 mpls_lock_get(global
->global_lock
); /* LOCK */
962 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
963 goto ldp_cfg_attr_get_end
;
965 if (flag
& LDP_ATTR_CFG_STATE
) {
966 a
->state
= attr
->state
;
968 if (flag
& LDP_ATTR_CFG_FEC
) {
969 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
971 if (flag
& LDP_ATTR_CFG_LABEL
) {
972 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
974 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
975 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
977 if (flag
& LDP_ATTR_CFG_PATH
) {
978 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
980 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
981 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
983 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
984 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
986 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
987 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
989 if (flag
& LDP_ATTR_CFG_INGRESS
) {
990 a
->ingress
= attr
->ingress
;
992 retval
= MPLS_SUCCESS
;
994 ldp_cfg_attr_get_end
:
995 mpls_lock_release(global
->global_lock
); /* UNLOCK */
997 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
1002 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
1005 ldp_global
*g
= (ldp_global
*) handle
;
1006 ldp_attr
*attr
= NULL
;
1007 mpls_return_enum r
= MPLS_FAILURE
;
1008 mpls_bool done
= MPLS_BOOL_FALSE
;
1011 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
1013 if (a
->index
== 0) {
1016 index
= a
->index
+ 1;
1019 mpls_lock_get(g
->global_lock
); /* LOCK */
1020 while (done
== MPLS_BOOL_FALSE
) {
1021 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
1023 case MPLS_END_OF_LIST
:
1024 done
= MPLS_BOOL_TRUE
;
1033 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1035 if (r
== MPLS_SUCCESS
) {
1036 a
->index
= attr
->index
;
1037 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1038 return ldp_cfg_attr_get(g
, a
, flag
);
1040 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1044 /******************* PEER **********************/
1046 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
1049 ldp_global
*global
= (ldp_global
*) handle
;
1050 ldp_peer
*peer
= NULL
;
1051 mpls_return_enum retval
= MPLS_FAILURE
;
1053 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1055 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
1057 mpls_lock_get(global
->global_lock
); /* LOCK */
1059 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
1060 goto ldp_cfg_peer_get_end
;
1062 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1063 p
->label_space
= peer
->label_space
;
1065 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1066 p
->target_role
= peer
->target_role
;
1068 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1069 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1071 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1072 p
->entity_index
= peer
->entity
->index
;
1074 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1075 p
->oper_state
= peer
->oper_state
;
1077 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1078 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1080 retval
= MPLS_SUCCESS
;
1082 ldp_cfg_peer_get_end
:
1083 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1085 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1090 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1093 ldp_global
*g
= (ldp_global
*) handle
;
1094 ldp_peer
*peer
= NULL
;
1095 mpls_return_enum r
= MPLS_FAILURE
;
1096 mpls_bool done
= MPLS_BOOL_FALSE
;
1099 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1101 if (p
->index
== 0) {
1104 index
= p
->index
+ 1;
1107 mpls_lock_get(g
->global_lock
); /* LOCK */
1108 while (done
== MPLS_BOOL_FALSE
) {
1109 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1111 case MPLS_END_OF_LIST
:
1112 done
= MPLS_BOOL_TRUE
;
1121 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1123 if (r
== MPLS_SUCCESS
) {
1124 p
->index
= peer
->index
;
1125 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1126 return ldp_cfg_peer_get(g
, p
, flag
);
1128 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1132 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1135 // ldp_global* g = (ldp_global*)handle;
1136 return MPLS_SUCCESS
;
1139 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1142 ldp_global
*global
= (ldp_global
*) handle
;
1143 ldp_peer
*peer
= NULL
;
1144 mpls_return_enum retval
= MPLS_FAILURE
;
1146 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1148 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1150 mpls_lock_get(global
->global_lock
); /* LOCK */
1152 if (flag
& LDP_CFG_ADD
) {
1153 if ((peer
= ldp_peer_create()) == NULL
) {
1154 goto ldp_cfg_peer_set_end
;
1156 p
->index
= peer
->index
;
1157 _ldp_global_add_peer(global
, peer
);
1159 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1163 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1165 goto ldp_cfg_peer_set_end
;
1167 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1168 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1170 goto ldp_cfg_peer_set_end
;
1173 if (flag
& LDP_CFG_DEL
) {
1174 if (peer
->entity
!= NULL
) {
1175 LDP_PRINT(global
->user_data
,
1176 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1178 goto ldp_cfg_peer_set_end
;
1181 _ldp_global_del_peer(global
, peer
);
1183 retval
= MPLS_SUCCESS
;
1184 goto ldp_cfg_peer_set_end
;
1186 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1187 peer
->label_space
= p
->label_space
;
1189 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1190 peer
->target_role
= p
->target_role
;
1192 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1193 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1195 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1196 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1199 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1201 global
->configuration_sequence_number
++;
1203 retval
= MPLS_SUCCESS
;
1205 ldp_cfg_peer_set_end
:
1206 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1208 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1212 /******************* FEC **********************/
1214 mpls_return_enum
ldp_cfg_fec_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1217 ldp_global
*global
= (ldp_global
*) handle
;
1218 ldp_fec
*fec
= NULL
;
1219 mpls_return_enum retval
= MPLS_FAILURE
;
1221 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1223 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get");
1225 mpls_lock_get(global
->global_lock
); /* LOCK */
1227 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1228 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1230 fec
= ldp_fec_find(global
, f
);
1233 goto ldp_cfg_fec_get_end
;
1235 memcpy(f
, &fec
->info
, sizeof(mpls_fec
));
1236 f
->index
= fec
->index
;
1237 retval
= MPLS_SUCCESS
;
1239 ldp_cfg_fec_get_end
:
1240 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1242 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get");
1247 mpls_return_enum
ldp_cfg_fec_getnext(mpls_cfg_handle handle
, mpls_fec
* f
,
1250 ldp_global
*g
= (ldp_global
*) handle
;
1251 ldp_fec
*fec
= NULL
;
1252 mpls_return_enum r
= MPLS_FAILURE
;
1253 mpls_bool done
= MPLS_BOOL_FALSE
;
1256 LDP_ENTER(g
->user_data
, "ldp_cfg_fec_getnext");
1258 if (f
->index
== 0) {
1261 index
= f
->index
+ 1;
1264 mpls_lock_get(g
->global_lock
); /* LOCK */
1265 while (done
== MPLS_BOOL_FALSE
) {
1266 switch ((r
= ldp_global_find_fec_index(g
, index
, &fec
))) {
1268 case MPLS_END_OF_LIST
:
1269 done
= MPLS_BOOL_TRUE
;
1278 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1280 if (r
== MPLS_SUCCESS
) {
1281 f
->index
= fec
->index
;
1282 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1283 return ldp_cfg_fec_get(g
, f
, flag
);
1285 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1289 mpls_return_enum
ldp_cfg_fec_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1292 // ldp_global* g = (ldp_global*)handle;
1293 return MPLS_SUCCESS
;
1296 mpls_return_enum
ldp_cfg_fec_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1299 ldp_global
*global
= (ldp_global
*) handle
;
1300 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 MPLS_REFCNT_HOLD(fec
);
1315 f
->index
= fec
->index
;
1317 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1318 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1320 fec
= ldp_fec_find(global
, f
);
1325 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_set: no such fec\n");
1326 goto ldp_cfg_fec_set_end
;
1329 if (flag
& LDP_CFG_DEL
) {
1331 * we can only delete the fec if all of the nexthops have been removed
1333 if (!MPLS_LIST_EMPTY(&fec
->nh_root
)) {
1334 goto ldp_cfg_fec_set_end
;
1337 * we hold the last refcnt, this should result in a call to
1340 MPLS_REFCNT_RELEASE2(global
, fec
, ldp_fec_delete
);
1343 retval
= MPLS_SUCCESS
;
1345 ldp_cfg_fec_set_end
:
1346 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1348 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1353 mpls_return_enum
ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1354 mpls_nexthop
*n
, uint32_t flag
)
1356 ldp_global
*global
= (ldp_global
*) handle
;
1357 ldp_fec
*fec
= NULL
;
1358 ldp_nexthop
*nh
= NULL
;
1359 mpls_return_enum retval
= MPLS_FAILURE
;
1361 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1363 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1365 mpls_lock_get(global
->global_lock
); /* LOCK */
1367 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1368 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1370 fec
= ldp_fec_find(global
, f
);
1373 goto ldp_cfg_fec_nexthop_get_end
;
1375 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1376 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1378 nh
= ldp_fec_nexthop_find(fec
, n
);
1381 goto ldp_cfg_fec_nexthop_get_end
;
1383 memcpy(n
, &nh
->info
, sizeof(mpls_nexthop
));
1384 n
->index
= nh
->index
;
1385 retval
= MPLS_SUCCESS
;
1387 ldp_cfg_fec_nexthop_get_end
:
1388 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1390 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1395 mpls_return_enum
ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle
,
1396 mpls_fec
* f
, mpls_nexthop
*n
, uint32_t flag
)
1398 ldp_global
*global
= (ldp_global
*) handle
;
1399 ldp_fec
*fec
= NULL
;
1400 ldp_nexthop
*nh
= NULL
;
1401 mpls_return_enum r
= MPLS_FAILURE
;
1402 mpls_bool done
= MPLS_BOOL_FALSE
;
1405 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1407 if (n
->index
== 0) {
1410 index
= n
->index
+ 1;
1413 mpls_lock_get(global
->global_lock
); /* LOCK */
1415 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1416 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1418 fec
= ldp_fec_find(global
, f
);
1421 goto ldp_cfg_fec_nexthop_getnext_end
;
1423 while (done
== MPLS_BOOL_FALSE
) {
1424 switch ((r
= ldp_fec_find_nexthop_index(fec
, index
, &nh
))) {
1426 case MPLS_END_OF_LIST
:
1427 done
= MPLS_BOOL_TRUE
;
1436 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1438 if (r
== MPLS_SUCCESS
) {
1439 n
->index
= nh
->index
;
1440 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1441 return ldp_cfg_fec_nexthop_get(global
, f
, n
, flag
);
1444 ldp_cfg_fec_nexthop_getnext_end
:
1446 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1450 mpls_return_enum
ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1451 mpls_nexthop
*n
, uint32_t flag
)
1453 // ldp_global* g = (ldp_global*)handle;
1454 return MPLS_SUCCESS
;
1457 mpls_return_enum
ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1458 mpls_nexthop
*n
, uint32_t flag
)
1460 ldp_global
*global
= (ldp_global
*) handle
;
1461 ldp_fec
*fec
= NULL
;
1462 ldp_nexthop
*nh
= NULL
;
1463 mpls_return_enum retval
= MPLS_FAILURE
;
1465 MPLS_ASSERT(global
!= NULL
&& f
!= NULL
&& n
!= NULL
);
1467 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1469 mpls_lock_get(global
->global_lock
); /* LOCK */
1471 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1472 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1474 fec
= ldp_fec_find(global
, f
);
1477 goto ldp_cfg_fec_nexthop_set_end
;
1479 if (flag
& LDP_CFG_ADD
) {
1480 if (ldp_fec_nexthop_find(fec
, n
) ||
1481 (nh
= ldp_nexthop_create(global
, n
)) == NULL
) {
1482 goto ldp_cfg_fec_nexthop_set_end
;
1484 n
->index
= nh
->index
;
1485 ldp_fec_add_nexthop(global
, fec
, nh
);
1486 ldp_fec_process_add(global
, fec
, nh
, NULL
);
1488 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1489 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1491 nh
= ldp_fec_nexthop_find(fec
, n
);
1496 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_nexthop_set: no such nh\n");
1497 goto ldp_cfg_fec_nexthop_set_end
;
1500 if (flag
& LDP_CFG_DEL
) {
1501 MPLS_REFCNT_HOLD(nh
);
1502 ldp_fec_del_nexthop(global
, fec
, nh
);
1503 if (ldp_fec_process_change(global
, fec
, MPLS_LIST_HEAD(&fec
->nh_root
),
1504 nh
, NULL
) != MPLS_SUCCESS
) {
1507 MPLS_REFCNT_RELEASE2(global
, nh
, ldp_nexthop_delete
);
1510 retval
= MPLS_SUCCESS
;
1512 ldp_cfg_fec_nexthop_set_end
:
1513 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1515 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1520 /******************* ADDR **********************/
1522 mpls_return_enum
ldp_cfg_addr_get(mpls_cfg_handle handle
, ldp_addr
* a
,
1525 ldp_global
*global
= (ldp_global
*) handle
;
1526 ldp_session
*session
= NULL
;
1527 ldp_nexthop
*nexthop
= NULL
;
1528 ldp_addr
*addr
= NULL
;
1529 mpls_return_enum retval
= MPLS_FAILURE
;
1531 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1533 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_get");
1535 mpls_lock_get(global
->global_lock
); /* LOCK */
1537 ldp_global_find_addr_index(global
, a
->index
, &addr
);
1540 goto ldp_cfg_addr_get_end
;
1542 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1543 a
->index
= addr
->index
;
1545 if ((session
= mpls_link_list_head_data(&addr
->session_root
))) {
1546 a
->session_index
= session
->index
;
1549 if ((nexthop
= MPLS_LIST_HEAD(&addr
->nh_root
))) {
1550 a
->nexthop_index
= nexthop
->index
;
1554 a
->if_index
= addr
->iff
->index
;
1557 retval
= MPLS_SUCCESS
;
1559 ldp_cfg_addr_get_end
:
1560 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1562 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_get");
1567 mpls_return_enum
ldp_cfg_addr_getnext(mpls_cfg_handle handle
, ldp_addr
*a
,
1570 ldp_global
*global
= (ldp_global
*) handle
;
1571 ldp_addr
*addr
= NULL
;
1572 mpls_return_enum r
= MPLS_FAILURE
;
1573 mpls_bool done
= MPLS_BOOL_FALSE
;
1576 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_getnext");
1578 if (a
->index
== 0) {
1581 index
= a
->index
+ 1;
1584 mpls_lock_get(global
->global_lock
); /* LOCK */
1586 while (done
== MPLS_BOOL_FALSE
) {
1587 switch ((r
= ldp_global_find_addr_index(global
, index
, &addr
))) {
1589 case MPLS_END_OF_LIST
:
1590 done
= MPLS_BOOL_TRUE
;
1599 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1601 if (r
== MPLS_SUCCESS
) {
1602 a
->index
= addr
->index
;
1603 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1604 return ldp_cfg_addr_get(global
, a
, flag
);
1607 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1611 /******************* IF ADDR **********************/
1613 mpls_return_enum
ldp_cfg_if_addr_get(mpls_cfg_handle handle
, ldp_if
* i
,
1614 ldp_addr
* a
, uint32_t flag
)
1616 ldp_global
*global
= (ldp_global
*) handle
;
1617 ldp_addr
*addr
= NULL
;
1619 mpls_return_enum retval
= MPLS_FAILURE
;
1621 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1623 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_get");
1625 mpls_lock_get(global
->global_lock
); /* LOCK */
1627 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1628 ldp_global_find_if_index(global
, i
->index
, &iff
);
1630 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1633 goto ldp_cfg_if_addr_get_end
;
1635 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1636 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1638 addr
= ldp_if_addr_find(iff
, &a
->address
);
1641 goto ldp_cfg_if_addr_get_end
;
1643 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1644 a
->index
= addr
->index
;
1646 retval
= MPLS_SUCCESS
;
1648 ldp_cfg_if_addr_get_end
:
1649 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1651 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_get");
1656 mpls_return_enum
ldp_cfg_if_addr_getnext(mpls_cfg_handle handle
,
1657 ldp_if
* i
, ldp_addr
*a
, uint32_t flag
)
1659 ldp_global
*global
= (ldp_global
*) handle
;
1661 ldp_addr
*addr
= NULL
;
1662 mpls_return_enum r
= MPLS_FAILURE
;
1663 mpls_bool done
= MPLS_BOOL_FALSE
;
1666 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_getnext");
1668 if (a
->index
== 0) {
1671 index
= a
->index
+ 1;
1674 mpls_lock_get(global
->global_lock
); /* LOCK */
1676 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1677 ldp_global_find_if_index(global
, i
->index
, &iff
);
1679 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1682 goto ldp_cfg_if_addr_getnext_end
;
1684 while (done
== MPLS_BOOL_FALSE
) {
1685 switch ((r
= ldp_if_find_addr_index(iff
, index
, &addr
))) {
1687 case MPLS_END_OF_LIST
:
1688 done
= MPLS_BOOL_TRUE
;
1697 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1699 if (r
== MPLS_SUCCESS
) {
1700 a
->index
= addr
->index
;
1701 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1702 return ldp_cfg_if_addr_get(global
, i
, a
, flag
);
1705 ldp_cfg_if_addr_getnext_end
:
1707 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1711 mpls_return_enum
ldp_cfg_if_addr_set(mpls_cfg_handle handle
, ldp_if
* i
,
1712 ldp_addr
*a
, uint32_t flag
)
1714 ldp_global
*global
= (ldp_global
*) handle
;
1716 ldp_addr
*addr
= NULL
;
1717 mpls_return_enum retval
= MPLS_FAILURE
;
1719 MPLS_ASSERT(global
!= NULL
&& i
!= NULL
&& a
!= NULL
);
1721 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_set");
1723 mpls_lock_get(global
->global_lock
); /* LOCK */
1725 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1726 ldp_global_find_if_index(global
, i
->index
, &iff
);
1728 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1731 goto ldp_cfg_if_addr_set_end
;
1733 if (flag
& LDP_CFG_ADD
) {
1734 if (ldp_if_addr_find(iff
, &a
->address
) || ((addr
= ldp_addr_create(global
,
1735 &a
->address
)) == NULL
)) {
1736 goto ldp_cfg_if_addr_set_end
;
1738 a
->index
= addr
->index
;
1739 ldp_if_add_addr(iff
, addr
);
1740 ldp_addr_process_add(global
, addr
);
1742 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1743 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1745 addr
= ldp_if_addr_find(iff
, &a
->address
);
1750 LDP_PRINT(global
->user_data
, "ldp_cfg_if_addr_set: no such addr\n");
1751 goto ldp_cfg_if_addr_set_end
;
1754 if (flag
& LDP_CFG_DEL
) {
1755 ldp_addr_process_remove(global
, addr
);
1756 ldp_if_del_addr(global
, iff
, addr
);
1759 retval
= MPLS_SUCCESS
;
1761 ldp_cfg_if_addr_set_end
:
1762 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1764 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_set");
1769 /******************* ADJACENCY **********************/
1771 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1774 ldp_global
*global
= (ldp_global
*) handle
;
1775 ldp_adj
*adj
= NULL
;
1776 mpls_return_enum retval
= MPLS_FAILURE
;
1778 MPLS_ASSERT(global
!= NULL
&& a
!= NULL
);
1780 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1782 mpls_lock_get(global
->global_lock
); /* LOCK */
1784 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1785 goto ldp_cfg_adj_get_end
;
1787 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1788 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1789 sizeof(mpls_inet_addr
));
1791 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1792 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1793 sizeof(mpls_inet_addr
));
1795 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1796 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1797 sizeof(mpls_inet_addr
));
1799 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1800 a
->remote_csn
= adj
->remote_csn
;
1802 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1803 a
->remote_label_space
= adj
->remote_label_space
;
1805 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1806 a
->remote_hellotime
= adj
->remote_hellotime
;
1808 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1809 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1811 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1812 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1814 if (flag
& LDP_ADJ_CFG_ROLE
) {
1815 a
->role
= adj
->role
;
1817 retval
= MPLS_SUCCESS
;
1819 ldp_cfg_adj_get_end
:
1821 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1823 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1828 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1831 ldp_global
*g
= (ldp_global
*) handle
;
1832 ldp_adj
*adj
= NULL
;
1833 mpls_return_enum r
= MPLS_FAILURE
;
1834 mpls_bool done
= MPLS_BOOL_FALSE
;
1837 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1839 if (a
->index
== 0) {
1842 index
= a
->index
+ 1;
1845 mpls_lock_get(g
->global_lock
); /* LOCK */
1846 while (done
== MPLS_BOOL_FALSE
) {
1847 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1849 case MPLS_END_OF_LIST
:
1850 done
= MPLS_BOOL_TRUE
;
1859 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1861 if (r
== MPLS_SUCCESS
) {
1862 a
->index
= adj
->index
;
1863 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1864 return ldp_cfg_adj_get(g
, a
, flag
);
1866 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1870 /******************* SESSION **********************/
1872 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1875 ldp_global
*global
= (ldp_global
*) handle
;
1876 ldp_session
*session
= NULL
;
1877 mpls_return_enum retval
= MPLS_FAILURE
;
1879 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1881 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1883 mpls_lock_get(global
->global_lock
); /* LOCK */
1885 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1886 goto ldp_cfg_session_get_end
;
1888 if (flag
& LDP_SESSION_CFG_STATE
) {
1889 s
->state
= session
->state
;
1891 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1892 s
->oper_up
= session
->oper_up
;
1894 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1895 s
->oper_max_pdu
= session
->oper_max_pdu
;
1897 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1898 s
->oper_keepalive
= session
->oper_keepalive
;
1900 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1901 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1903 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1904 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1906 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1907 s
->oper_loop_detection
= session
->oper_loop_detection
;
1909 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1910 s
->remote_max_pdu
= session
->remote_max_pdu
;
1912 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1913 s
->remote_keepalive
= session
->remote_keepalive
;
1915 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1916 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1918 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1919 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1921 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1922 s
->remote_loop_detection
= session
->remote_loop_detection
;
1924 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1925 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1926 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1928 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1929 s
->remote_dest
.port
= session
->remote_dest
.port
;
1931 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1932 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1934 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1935 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1937 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1938 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1939 s
->adj_index
= a
? a
->index
: 0;
1941 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1942 s
->mesg_tx
= session
->mesg_tx
;
1944 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1945 s
->mesg_rx
= session
->mesg_rx
;
1947 retval
= MPLS_SUCCESS
;
1949 ldp_cfg_session_get_end
:
1950 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1952 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1957 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1960 ldp_global
*g
= (ldp_global
*) handle
;
1961 ldp_session
*ses
= NULL
;
1962 mpls_return_enum r
= MPLS_FAILURE
;
1963 mpls_bool done
= MPLS_BOOL_FALSE
;
1966 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1968 if (s
->index
== 0) {
1971 index
= s
->index
+ 1;
1974 mpls_lock_get(g
->global_lock
); /* LOCK */
1975 while (done
== MPLS_BOOL_FALSE
) {
1976 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1978 case MPLS_END_OF_LIST
:
1979 done
= MPLS_BOOL_TRUE
;
1988 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1990 if (r
== MPLS_SUCCESS
) {
1991 s
->index
= ses
->index
;
1993 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1994 return ldp_cfg_session_get(g
, s
, flag
);
1997 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2002 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
2005 ldp_global
*g
= (ldp_global
*) handle
;
2006 mpls_bool this_one
= MPLS_BOOL_FALSE
;
2007 mpls_return_enum r
= MPLS_FAILURE
;
2008 ldp_adj
*adj_next
= NULL
;
2009 ldp_adj
*adj
= NULL
;
2010 ldp_session
*session
= NULL
;
2012 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
2014 /* if an adj_index of zero is sent, get the index of
2015 * the first adj in the list
2017 if (!s
->adj_index
) {
2018 this_one
= MPLS_BOOL_TRUE
;
2021 mpls_lock_get(g
->global_lock
); /* LOCK */
2023 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
2024 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
2026 if (this_one
== MPLS_BOOL_TRUE
) {
2031 /* since the entities are sort in the list ... */
2032 if (adj
->index
> s
->adj_index
) {
2034 } else if (adj
->index
== s
->adj_index
) {
2035 this_one
= MPLS_BOOL_TRUE
;
2037 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
2040 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2043 s
->adj_index
= adj_next
->index
;
2047 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
2051 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
2052 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2054 ldp_global
*global
= (ldp_global
*) handle
;
2055 ldp_session
*session
= NULL
;
2056 ldp_addr
*addr
= NULL
;
2057 mpls_return_enum retval
= MPLS_FAILURE
;
2059 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
2061 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
2063 mpls_lock_get(global
->global_lock
); /* LOCK */
2065 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
2066 goto ldp_cfg_session_raddr_get_end
;
2068 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
2069 goto ldp_cfg_session_raddr_get_end
;
2071 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
2072 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
2074 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
2075 a
->index
= addr
->index
;
2077 retval
= MPLS_SUCCESS
;
2079 ldp_cfg_session_raddr_get_end
:
2080 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2082 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
2087 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
2088 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2090 ldp_global
*g
= (ldp_global
*) handle
;
2091 ldp_addr
*addr
= NULL
;
2092 mpls_return_enum r
= MPLS_FAILURE
;
2093 mpls_bool done
= MPLS_BOOL_FALSE
;
2094 ldp_session
*sp
= NULL
;
2097 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
2099 if (a
->index
== 0) {
2102 index
= a
->index
+ 1;
2105 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
2106 if (r
!= MPLS_SUCCESS
) {
2110 mpls_lock_get(g
->global_lock
); /* LOCK */
2111 while (done
== MPLS_BOOL_FALSE
) {
2112 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
2114 case MPLS_END_OF_LIST
:
2115 done
= MPLS_BOOL_TRUE
;
2124 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2126 if (r
== MPLS_SUCCESS
) {
2127 a
->index
= addr
->index
;
2128 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
2131 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2135 /******************* IN LABEL **********************/
2137 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2140 ldp_global
*global
= (ldp_global
*) handle
;
2141 ldp_inlabel
*inlabel
= NULL
;
2142 mpls_return_enum retval
= MPLS_FAILURE
;
2144 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
2146 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
2148 mpls_lock_get(global
->global_lock
); /* LOCK */
2150 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
2151 goto ldp_cfg_inlabel_get_end
;
2153 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
2154 i
->info
.labelspace
= inlabel
->info
.labelspace
;
2156 if (flag
& LDP_INLABEL_CFG_LABEL
) {
2157 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
2159 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
2160 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
2163 retval
= MPLS_SUCCESS
;
2165 ldp_cfg_inlabel_get_end
:
2166 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2168 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
2173 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2176 ldp_global
*g
= (ldp_global
*) handle
;
2177 ldp_inlabel
*inlabel
= NULL
;
2178 mpls_return_enum r
= MPLS_FAILURE
;
2179 mpls_bool done
= MPLS_BOOL_FALSE
;
2182 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
2184 if (i
->index
== 0) {
2187 index
= i
->index
+ 1;
2190 mpls_lock_get(g
->global_lock
); /* LOCK */
2191 while (done
== MPLS_BOOL_FALSE
) {
2192 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
2194 case MPLS_END_OF_LIST
:
2195 done
= MPLS_BOOL_TRUE
;
2204 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2206 if (r
== MPLS_SUCCESS
) {
2207 i
->index
= inlabel
->index
;
2209 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2210 return ldp_cfg_inlabel_get(g
, i
, flag
);
2213 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2218 /******************* OUT LABEL **********************/
2220 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
2223 ldp_global
*global
= (ldp_global
*) handle
;
2224 ldp_outlabel
*outlabel
= NULL
;
2225 mpls_return_enum retval
= MPLS_FAILURE
;
2227 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
2229 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
2231 mpls_lock_get(global
->global_lock
); /* LOCK */
2233 if (ldp_global_find_outlabel_index(global
, o
->index
,
2234 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
2236 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
2238 o
->nh_index
= outlabel
->nh
->index
;
2243 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
2244 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
2246 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
2247 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
2249 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
2250 o
->merge_count
= outlabel
->merge_count
;
2253 retval
= MPLS_SUCCESS
;
2255 ldp_cfg_outlabel_get_end
:
2256 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2258 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
2263 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
2264 ldp_outlabel
* o
, uint32_t flag
)
2266 ldp_global
*g
= (ldp_global
*) handle
;
2267 ldp_outlabel
*outlabel
= NULL
;
2268 mpls_return_enum r
= MPLS_FAILURE
;
2269 mpls_bool done
= MPLS_BOOL_FALSE
;
2272 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
2274 if (o
->index
== 0) {
2277 index
= o
->index
+ 1;
2280 mpls_lock_get(g
->global_lock
); /* LOCK */
2281 while (done
== MPLS_BOOL_FALSE
) {
2282 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
2284 case MPLS_END_OF_LIST
:
2285 done
= MPLS_BOOL_TRUE
;
2294 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2296 if (r
== MPLS_SUCCESS
) {
2297 o
->index
= outlabel
->index
;
2299 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2300 return ldp_cfg_outlabel_get(g
, o
, flag
);
2303 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2308 /******************* TUNNEL **********************/
2310 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2313 ldp_global
*global
= (ldp_global
*) handle
;
2314 mpls_return_enum retval
= MPLS_FAILURE
;
2315 ldp_tunnel
*tunnel
= NULL
;
2317 MPLS_ASSERT(global
!=NULL
);
2319 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2321 mpls_lock_get(global
->global_lock
); /* LOCK */
2323 if (flag
& LDP_CFG_ADD
) {
2324 if (!(tunnel
= ldp_tunnel_create())) {
2325 goto ldp_cfg_tunnel_set_end
;
2327 _ldp_global_add_tunnel(global
, tunnel
);
2329 t
->index
= tunnel
->index
;
2331 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2335 LDP_PRINT(global
->user_data
,
2337 "ldp_cfg_tunnel_set:could not create tunnel\n");
2338 goto ldp_cfg_tunnel_set_end
;
2341 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2342 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2343 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2345 goto ldp_cfg_tunnel_set_end
;
2348 if (flag
& LDP_CFG_DEL
) {
2349 if (tunnel
->outlabel
)
2350 ldp_tunnel_del_outlabel(tunnel
);
2351 if (tunnel
->resource
)
2352 ldp_tunnel_del_resource(tunnel
);
2353 if (tunnel
->hop_list
)
2354 ldp_tunnel_del_hop_list(tunnel
);
2355 _ldp_global_del_tunnel(global
, tunnel
);
2357 retval
= MPLS_SUCCESS
;
2358 goto ldp_cfg_tunnel_set_end
;
2361 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2362 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2364 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2365 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2367 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2368 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2370 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2371 tunnel
->is_interface
= t
->is_interface
;
2373 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2374 ldp_outlabel
*outlabel
= NULL
;
2376 if (t
->outlabel_index
) {
2377 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2380 goto ldp_cfg_tunnel_set_end
;
2382 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2384 ldp_tunnel_del_outlabel(tunnel
);
2387 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2388 tunnel
->setup_prio
= t
->setup_prio
;
2390 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2391 tunnel
->hold_prio
= t
->hold_prio
;
2393 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2394 tunnel
->instance_prio
= t
->instance_prio
;
2396 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2397 tunnel
->local_protect
= t
->local_protect
;
2399 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2400 ldp_resource
*resource
= NULL
;
2402 if (t
->resource_index
) {
2403 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2406 goto ldp_cfg_tunnel_set_end
;
2408 ldp_tunnel_add_resource(tunnel
, resource
);
2410 ldp_tunnel_del_resource(tunnel
);
2413 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2414 ldp_hop_list
*hop_list
= NULL
;
2416 if (t
->hop_list_index
) {
2417 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2420 goto ldp_cfg_tunnel_set_end
;
2422 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2424 ldp_tunnel_del_hop_list(tunnel
);
2427 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2428 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2430 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2431 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2432 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2433 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2434 goto ldp_cfg_tunnel_set_end
;
2438 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2439 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2440 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2441 goto ldp_cfg_tunnel_set_end
;
2444 LDP_PRINT(global
->user_data
,
2446 "ldp_cfg_tunnel_set: tunnel not ready\n");
2447 goto ldp_cfg_tunnel_set_end
;
2452 retval
= MPLS_SUCCESS
;
2454 ldp_cfg_tunnel_set_end
:
2456 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2458 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2463 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2466 ldp_global
*global
= (ldp_global
*) handle
;
2467 mpls_return_enum retval
= MPLS_FAILURE
;
2468 ldp_tunnel
*tunnel
= NULL
;
2470 MPLS_ASSERT(global
!=NULL
);
2472 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2474 mpls_lock_get(global
->global_lock
); /* LOCK */
2476 if (flag
& LDP_CFG_ADD
) {
2477 retval
= MPLS_SUCCESS
;
2478 goto ldp_cfg_tunnel_test_end
;
2481 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2484 goto ldp_cfg_tunnel_test_end
;
2487 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2488 ldp_resource
*resource
= NULL
;
2490 if (t
->resource_index
) {
2491 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2494 goto ldp_cfg_tunnel_test_end
;
2498 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2499 ldp_hop_list
*hop_list
= NULL
;
2501 if (t
->hop_list_index
) {
2502 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2505 goto ldp_cfg_tunnel_test_end
;
2509 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2510 ldp_outlabel
*outlabel
= NULL
;
2512 if (t
->outlabel_index
) {
2513 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2516 goto ldp_cfg_tunnel_test_end
;
2520 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2521 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2522 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2523 goto ldp_cfg_tunnel_test_end
;
2525 retval
= MPLS_SUCCESS
;
2527 ldp_cfg_tunnel_test_end
:
2529 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2531 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2536 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2539 ldp_global
*global
= (ldp_global
*) handle
;
2540 mpls_return_enum retval
= MPLS_FAILURE
;
2541 ldp_tunnel
*tunnel
= NULL
;
2543 MPLS_ASSERT(global
!=NULL
);
2545 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2547 mpls_lock_get(global
->global_lock
); /* LOCK */
2549 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2552 goto ldp_cfg_tunnel_get_end
;
2554 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2555 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2557 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2558 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2560 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2561 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2563 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2564 t
->is_interface
= tunnel
->is_interface
;
2566 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2567 if (tunnel
->outlabel
) {
2568 t
->outlabel_index
= tunnel
->outlabel
->index
;
2570 t
->outlabel_index
= 0;
2573 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2574 t
->setup_prio
= tunnel
->setup_prio
;
2576 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2577 t
->hold_prio
= tunnel
->hold_prio
;
2579 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2580 tunnel
->instance_prio
= t
->instance_prio
;
2582 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2583 tunnel
->local_protect
= t
->local_protect
;
2585 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2586 if (tunnel
->resource
) {
2587 t
->resource_index
= tunnel
->resource
->index
;
2589 t
->resource_index
= 0;
2592 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2593 if (tunnel
->hop_list
) {
2594 t
->hop_list_index
= tunnel
->hop_list
->index
;
2596 t
->hop_list_index
= 0;
2599 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2600 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2602 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2603 t
->admin_state
= tunnel
->admin_state
;
2605 retval
= MPLS_SUCCESS
;
2607 ldp_cfg_tunnel_get_end
:
2609 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2611 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2616 /******************* RESOURCE **********************/
2618 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2621 ldp_global
*global
= (ldp_global
*) handle
;
2622 mpls_return_enum retval
= MPLS_FAILURE
;
2623 ldp_resource
*resource
= NULL
;
2625 MPLS_ASSERT(global
!=NULL
);
2627 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2629 mpls_lock_get(global
->global_lock
); /* LOCK */
2631 if (flag
& LDP_CFG_ADD
) {
2632 resource
= ldp_resource_create();
2633 _ldp_global_add_resource(global
, resource
);
2635 r
->index
= resource
->index
;
2637 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2641 goto ldp_cfg_resource_set_end
;
2644 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2645 resource
->max_rate
= r
->max_rate
;
2647 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2648 resource
->mean_rate
= r
->mean_rate
;
2650 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2651 resource
->burst_size
= r
->burst_size
;
2653 retval
= MPLS_SUCCESS
;
2655 ldp_cfg_resource_set_end
:
2657 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2659 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2664 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2667 ldp_global
*global
= (ldp_global
*) handle
;
2668 mpls_return_enum retval
= MPLS_FAILURE
;
2669 ldp_resource
*resource
= NULL
;
2671 MPLS_ASSERT(global
!=NULL
);
2673 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2675 mpls_lock_get(global
->global_lock
); /* LOCK */
2677 if (flag
& LDP_CFG_ADD
) {
2678 retval
= MPLS_SUCCESS
;
2679 goto ldp_cfg_resource_test_end
;
2682 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2685 goto ldp_cfg_resource_test_end
;
2688 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2689 goto ldp_cfg_resource_test_end
;
2691 retval
= MPLS_SUCCESS
;
2693 ldp_cfg_resource_test_end
:
2695 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2697 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2702 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2705 ldp_global
*global
= (ldp_global
*) handle
;
2706 mpls_return_enum retval
= MPLS_FAILURE
;
2707 ldp_resource
*resource
= NULL
;
2709 MPLS_ASSERT(global
!=NULL
);
2711 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2713 mpls_lock_get(global
->global_lock
); /* LOCK */
2715 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2718 goto ldp_cfg_resource_get_end
;
2721 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2722 r
->max_rate
= resource
->max_rate
;
2724 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2725 r
->mean_rate
= resource
->mean_rate
;
2727 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2728 r
->burst_size
= resource
->burst_size
;
2730 retval
= MPLS_SUCCESS
;
2732 ldp_cfg_resource_get_end
:
2734 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2736 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2741 /******************* HOP **********************/
2743 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2746 ldp_global
*global
= (ldp_global
*) handle
;
2747 mpls_return_enum retval
= MPLS_FAILURE
;
2748 ldp_hop_list
*hop_list
= NULL
;
2749 ldp_hop
*hop
= NULL
;
2751 MPLS_ASSERT(global
!=NULL
);
2753 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2755 if (!h
->hop_list_index
&& !h
->index
) {
2759 mpls_lock_get(global
->global_lock
); /* LOCK */
2761 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2764 if (flag
& LDP_CFG_ADD
) {
2765 if (!(hop_list
= ldp_hop_list_create())) {
2766 goto ldp_cfg_hop_set_end
;
2768 _ldp_global_add_hop_list(global
, hop_list
);
2770 h
->hop_list_index
= hop_list
->index
;
2772 goto ldp_cfg_hop_set_end
;
2776 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2778 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2779 if (!(hop
= ldp_hop_create())) {
2780 goto ldp_cfg_hop_set_end
;
2782 hop
->index
= h
->index
;
2783 ldp_hop_list_add_hop(hop_list
, hop
);
2785 goto ldp_cfg_hop_set_end
;
2789 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2790 hop
->path_option
= h
->path_option
;
2792 if (flag
& LDP_HOP_CFG_ADDR
) {
2793 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2795 if (flag
& LDP_HOP_CFG_TYPE
) {
2796 hop
->type
= h
->type
;
2798 retval
= MPLS_SUCCESS
;
2800 ldp_cfg_hop_set_end
:
2802 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2804 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2809 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2812 ldp_global
*global
= (ldp_global
*) handle
;
2813 mpls_return_enum retval
= MPLS_FAILURE
;
2814 ldp_hop_list
*hop_list
= NULL
;
2815 ldp_hop
*hop
= NULL
;
2817 MPLS_ASSERT(global
!=NULL
);
2819 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2821 mpls_lock_get(global
->global_lock
); /* LOCK */
2823 if (flag
& LDP_CFG_ADD
) {
2824 retval
= MPLS_SUCCESS
;
2825 goto ldp_cfg_hop_test_end
;
2828 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2831 goto ldp_cfg_hop_test_end
;
2834 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2836 goto ldp_cfg_hop_test_end
;
2839 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2840 goto ldp_cfg_hop_test_end
;
2842 retval
= MPLS_SUCCESS
;
2844 ldp_cfg_hop_test_end
:
2846 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2848 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2853 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2856 ldp_global
*global
= (ldp_global
*) handle
;
2857 mpls_return_enum retval
= MPLS_FAILURE
;
2858 ldp_hop_list
*hop_list
= NULL
;
2859 ldp_hop
*hop
= NULL
;
2861 MPLS_ASSERT(global
!=NULL
);
2863 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2865 mpls_lock_get(global
->global_lock
); /* LOCK */
2867 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2870 goto ldp_cfg_hop_get_end
;
2873 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2875 goto ldp_cfg_hop_get_end
;
2878 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2879 h
->path_option
= hop
->path_option
;
2881 if (flag
& LDP_HOP_CFG_ADDR
) {
2882 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2884 if (flag
& LDP_HOP_CFG_TYPE
) {
2885 h
->type
= hop
->type
;
2887 retval
= MPLS_SUCCESS
;
2889 ldp_cfg_hop_get_end
:
2891 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2893 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");