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
;
1301 mpls_return_enum retval
= MPLS_FAILURE
;
1303 MPLS_ASSERT(global
!= NULL
&& f
!= NULL
);
1305 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_set");
1307 mpls_lock_get(global
->global_lock
); /* LOCK */
1309 if (flag
& LDP_CFG_ADD
) {
1310 if (ldp_fec_find(global
, f
) || (fec
= ldp_fec_create(global
, f
)) == NULL
) {
1311 goto ldp_cfg_fec_set_end
;
1313 MPLS_REFCNT_HOLD(fec
);
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
) {
1330 * we can only delete the fec if all of the nexthops have been removed
1332 if (!MPLS_LIST_EMPTY(&fec
->nh_root
)) {
1333 goto ldp_cfg_fec_set_end
;
1336 * we hold the last refcnt, this should result in a call to
1339 MPLS_REFCNT_RELEASE2(global
, fec
, ldp_fec_delete
);
1342 retval
= MPLS_SUCCESS
;
1344 ldp_cfg_fec_set_end
:
1345 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1347 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1352 mpls_return_enum
ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1353 mpls_nexthop
*n
, uint32_t flag
)
1355 ldp_global
*global
= (ldp_global
*) handle
;
1356 ldp_fec
*fec
= NULL
;
1357 ldp_nexthop
*nh
= NULL
;
1358 mpls_return_enum retval
= MPLS_FAILURE
;
1360 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1362 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1364 mpls_lock_get(global
->global_lock
); /* LOCK */
1366 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1367 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1369 fec
= ldp_fec_find(global
, f
);
1372 goto ldp_cfg_fec_nexthop_get_end
;
1374 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1375 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1377 nh
= ldp_fec_nexthop_find(fec
, n
);
1380 goto ldp_cfg_fec_nexthop_get_end
;
1382 memcpy(n
, &nh
->info
, sizeof(mpls_nexthop
));
1383 n
->index
= nh
->index
;
1384 retval
= MPLS_SUCCESS
;
1386 ldp_cfg_fec_nexthop_get_end
:
1387 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1389 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1394 mpls_return_enum
ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle
,
1395 mpls_fec
* f
, mpls_nexthop
*n
, uint32_t flag
)
1397 ldp_global
*global
= (ldp_global
*) handle
;
1398 ldp_fec
*fec
= NULL
;
1399 ldp_nexthop
*nh
= NULL
;
1400 mpls_return_enum r
= MPLS_FAILURE
;
1401 mpls_bool done
= MPLS_BOOL_FALSE
;
1404 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1406 if (n
->index
== 0) {
1409 index
= n
->index
+ 1;
1412 mpls_lock_get(global
->global_lock
); /* LOCK */
1414 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1415 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1417 fec
= ldp_fec_find(global
, f
);
1420 goto ldp_cfg_fec_nexthop_getnext_end
;
1422 while (done
== MPLS_BOOL_FALSE
) {
1423 switch ((r
= ldp_fec_find_nexthop_index(fec
, index
, &nh
))) {
1425 case MPLS_END_OF_LIST
:
1426 done
= MPLS_BOOL_TRUE
;
1435 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1437 if (r
== MPLS_SUCCESS
) {
1438 n
->index
= nh
->index
;
1439 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1440 return ldp_cfg_fec_nexthop_get(global
, f
, n
, flag
);
1443 ldp_cfg_fec_nexthop_getnext_end
:
1445 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1449 mpls_return_enum
ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1450 mpls_nexthop
*n
, uint32_t flag
)
1452 // ldp_global* g = (ldp_global*)handle;
1453 return MPLS_SUCCESS
;
1456 mpls_return_enum
ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1457 mpls_nexthop
*n
, uint32_t flag
)
1459 ldp_global
*global
= (ldp_global
*) handle
;
1460 ldp_fec
*fec
= NULL
;
1461 ldp_nexthop
*nh
= NULL
;
1462 mpls_return_enum retval
= MPLS_FAILURE
;
1464 MPLS_ASSERT(global
!= NULL
&& f
!= NULL
&& n
!= NULL
);
1466 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1468 mpls_lock_get(global
->global_lock
); /* LOCK */
1470 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1471 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1473 fec
= ldp_fec_find(global
, f
);
1476 goto ldp_cfg_fec_nexthop_set_end
;
1478 if (flag
& LDP_CFG_ADD
) {
1479 if (ldp_fec_nexthop_find(fec
, n
) ||
1480 (nh
= ldp_nexthop_create(global
, n
)) == NULL
) {
1481 goto ldp_cfg_fec_nexthop_set_end
;
1483 n
->index
= nh
->index
;
1484 ldp_fec_add_nexthop(global
, fec
, nh
);
1485 ldp_fec_process_add(global
, fec
, nh
, NULL
);
1487 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1488 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1490 nh
= ldp_fec_nexthop_find(fec
, n
);
1495 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_nexthop_set: no such nh\n");
1496 goto ldp_cfg_fec_nexthop_set_end
;
1499 if (flag
& LDP_CFG_DEL
) {
1500 MPLS_REFCNT_HOLD(nh
);
1501 ldp_fec_del_nexthop(global
, fec
, nh
);
1502 if (ldp_fec_process_change(global
, fec
, MPLS_LIST_HEAD(&fec
->nh_root
),
1503 nh
, NULL
) != MPLS_SUCCESS
) {
1506 MPLS_REFCNT_RELEASE2(global
, nh
, ldp_nexthop_delete
);
1509 retval
= MPLS_SUCCESS
;
1511 ldp_cfg_fec_nexthop_set_end
:
1512 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1514 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1519 /******************* ADDR **********************/
1521 mpls_return_enum
ldp_cfg_addr_get(mpls_cfg_handle handle
, ldp_addr
* a
,
1524 ldp_global
*global
= (ldp_global
*) handle
;
1525 ldp_session
*session
= NULL
;
1526 ldp_nexthop
*nexthop
= NULL
;
1527 ldp_addr
*addr
= NULL
;
1528 mpls_return_enum retval
= MPLS_FAILURE
;
1530 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1532 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_get");
1534 mpls_lock_get(global
->global_lock
); /* LOCK */
1536 ldp_global_find_addr_index(global
, a
->index
, &addr
);
1539 goto ldp_cfg_addr_get_end
;
1541 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1542 a
->index
= addr
->index
;
1544 if (addr
->session
) {
1545 a
->session_index
= addr
->session
->index
;
1548 if ((nexthop
= MPLS_LIST_HEAD(&addr
->nh_root
))) {
1549 a
->nexthop_index
= nexthop
->index
;
1553 a
->if_index
= addr
->iff
->index
;
1556 retval
= MPLS_SUCCESS
;
1558 ldp_cfg_addr_get_end
:
1559 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1561 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_get");
1566 mpls_return_enum
ldp_cfg_addr_getnext(mpls_cfg_handle handle
, ldp_addr
*a
,
1569 ldp_global
*global
= (ldp_global
*) handle
;
1570 ldp_addr
*addr
= NULL
;
1571 mpls_return_enum r
= MPLS_FAILURE
;
1572 mpls_bool done
= MPLS_BOOL_FALSE
;
1575 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_getnext");
1577 if (a
->index
== 0) {
1580 index
= a
->index
+ 1;
1583 mpls_lock_get(global
->global_lock
); /* LOCK */
1585 while (done
== MPLS_BOOL_FALSE
) {
1586 switch ((r
= ldp_global_find_addr_index(global
, index
, &addr
))) {
1588 case MPLS_END_OF_LIST
:
1589 done
= MPLS_BOOL_TRUE
;
1598 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1600 if (r
== MPLS_SUCCESS
) {
1601 a
->index
= addr
->index
;
1602 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1603 return ldp_cfg_addr_get(global
, a
, flag
);
1606 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1610 /******************* IF ADDR **********************/
1612 mpls_return_enum
ldp_cfg_if_addr_get(mpls_cfg_handle handle
, ldp_if
* i
,
1613 ldp_addr
* a
, uint32_t flag
)
1615 ldp_global
*global
= (ldp_global
*) handle
;
1616 ldp_addr
*addr
= NULL
;
1618 mpls_return_enum retval
= MPLS_FAILURE
;
1620 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1622 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_get");
1624 mpls_lock_get(global
->global_lock
); /* LOCK */
1626 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1627 ldp_global_find_if_index(global
, i
->index
, &iff
);
1629 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1632 goto ldp_cfg_if_addr_get_end
;
1634 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1635 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1637 addr
= ldp_if_addr_find(iff
, &a
->address
);
1640 goto ldp_cfg_if_addr_get_end
;
1642 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1643 a
->index
= addr
->index
;
1645 retval
= MPLS_SUCCESS
;
1647 ldp_cfg_if_addr_get_end
:
1648 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1650 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_get");
1655 mpls_return_enum
ldp_cfg_if_addr_getnext(mpls_cfg_handle handle
,
1656 ldp_if
* i
, ldp_addr
*a
, uint32_t flag
)
1658 ldp_global
*global
= (ldp_global
*) handle
;
1660 ldp_addr
*addr
= NULL
;
1661 mpls_return_enum r
= MPLS_FAILURE
;
1662 mpls_bool done
= MPLS_BOOL_FALSE
;
1665 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_getnext");
1667 if (a
->index
== 0) {
1670 index
= a
->index
+ 1;
1673 mpls_lock_get(global
->global_lock
); /* LOCK */
1675 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1676 ldp_global_find_if_index(global
, i
->index
, &iff
);
1678 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1681 goto ldp_cfg_if_addr_getnext_end
;
1683 while (done
== MPLS_BOOL_FALSE
) {
1684 switch ((r
= ldp_if_find_addr_index(iff
, index
, &addr
))) {
1686 case MPLS_END_OF_LIST
:
1687 done
= MPLS_BOOL_TRUE
;
1696 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1698 if (r
== MPLS_SUCCESS
) {
1699 a
->index
= addr
->index
;
1700 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1701 return ldp_cfg_if_addr_get(global
, i
, a
, flag
);
1704 ldp_cfg_if_addr_getnext_end
:
1706 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1710 mpls_return_enum
ldp_cfg_if_addr_set(mpls_cfg_handle handle
, ldp_if
* i
,
1711 ldp_addr
*a
, uint32_t flag
)
1713 ldp_global
*global
= (ldp_global
*) handle
;
1715 ldp_addr
*addr
= NULL
;
1716 mpls_return_enum retval
= MPLS_FAILURE
;
1718 MPLS_ASSERT(global
!= NULL
&& i
!= NULL
&& a
!= NULL
);
1720 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_set");
1722 mpls_lock_get(global
->global_lock
); /* LOCK */
1724 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1725 ldp_global_find_if_index(global
, i
->index
, &iff
);
1727 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1730 goto ldp_cfg_if_addr_set_end
;
1732 if (flag
& LDP_CFG_ADD
) {
1733 if (ldp_if_addr_find(iff
, &a
->address
) || ((addr
= ldp_addr_create(global
,
1734 &a
->address
)) == NULL
)) {
1735 goto ldp_cfg_if_addr_set_end
;
1737 a
->index
= addr
->index
;
1738 ldp_if_add_addr(iff
, addr
);
1739 ldp_addr_process_add(global
, addr
);
1741 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1742 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1744 addr
= ldp_if_addr_find(iff
, &a
->address
);
1749 LDP_PRINT(global
->user_data
, "ldp_cfg_if_addr_set: no such addr\n");
1750 goto ldp_cfg_if_addr_set_end
;
1753 if (flag
& LDP_CFG_DEL
) {
1754 ldp_addr_process_remove(global
, addr
);
1755 ldp_if_del_addr(global
, iff
, addr
);
1758 retval
= MPLS_SUCCESS
;
1760 ldp_cfg_if_addr_set_end
:
1761 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1763 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_set");
1768 /******************* ADJACENCY **********************/
1770 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1773 ldp_global
*global
= (ldp_global
*) handle
;
1774 ldp_adj
*adj
= NULL
;
1775 mpls_return_enum retval
= MPLS_FAILURE
;
1777 MPLS_ASSERT(global
!= NULL
&& a
!= NULL
);
1779 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1781 mpls_lock_get(global
->global_lock
); /* LOCK */
1783 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1784 goto ldp_cfg_adj_get_end
;
1786 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1787 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1788 sizeof(mpls_inet_addr
));
1790 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1791 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1792 sizeof(mpls_inet_addr
));
1794 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1795 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1796 sizeof(mpls_inet_addr
));
1798 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1799 a
->remote_csn
= adj
->remote_csn
;
1801 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1802 a
->remote_label_space
= adj
->remote_label_space
;
1804 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1805 a
->remote_hellotime
= adj
->remote_hellotime
;
1807 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1808 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1810 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1811 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1813 if (flag
& LDP_ADJ_CFG_ROLE
) {
1814 a
->role
= adj
->role
;
1816 retval
= MPLS_SUCCESS
;
1818 ldp_cfg_adj_get_end
:
1820 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1822 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1827 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1830 ldp_global
*g
= (ldp_global
*) handle
;
1831 ldp_adj
*adj
= NULL
;
1832 mpls_return_enum r
= MPLS_FAILURE
;
1833 mpls_bool done
= MPLS_BOOL_FALSE
;
1836 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1838 if (a
->index
== 0) {
1841 index
= a
->index
+ 1;
1844 mpls_lock_get(g
->global_lock
); /* LOCK */
1845 while (done
== MPLS_BOOL_FALSE
) {
1846 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1848 case MPLS_END_OF_LIST
:
1849 done
= MPLS_BOOL_TRUE
;
1858 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1860 if (r
== MPLS_SUCCESS
) {
1861 a
->index
= adj
->index
;
1862 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1863 return ldp_cfg_adj_get(g
, a
, flag
);
1865 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1869 /******************* SESSION **********************/
1871 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1874 ldp_global
*global
= (ldp_global
*) handle
;
1875 ldp_session
*session
= NULL
;
1876 mpls_return_enum retval
= MPLS_FAILURE
;
1878 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1880 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1882 mpls_lock_get(global
->global_lock
); /* LOCK */
1884 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1885 goto ldp_cfg_session_get_end
;
1887 if (flag
& LDP_SESSION_CFG_STATE
) {
1888 s
->state
= session
->state
;
1890 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1891 s
->oper_up
= session
->oper_up
;
1893 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1894 s
->oper_max_pdu
= session
->oper_max_pdu
;
1896 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1897 s
->oper_keepalive
= session
->oper_keepalive
;
1899 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1900 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1902 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1903 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1905 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1906 s
->oper_loop_detection
= session
->oper_loop_detection
;
1908 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1909 s
->remote_max_pdu
= session
->remote_max_pdu
;
1911 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1912 s
->remote_keepalive
= session
->remote_keepalive
;
1914 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1915 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1917 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1918 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1920 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1921 s
->remote_loop_detection
= session
->remote_loop_detection
;
1923 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1924 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1925 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1927 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1928 s
->remote_dest
.port
= session
->remote_dest
.port
;
1930 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1931 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1933 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1934 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1936 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1937 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1938 s
->adj_index
= a
? a
->index
: 0;
1940 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1941 s
->mesg_tx
= session
->mesg_tx
;
1943 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1944 s
->mesg_rx
= session
->mesg_rx
;
1946 retval
= MPLS_SUCCESS
;
1948 ldp_cfg_session_get_end
:
1949 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1951 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1956 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1959 ldp_global
*g
= (ldp_global
*) handle
;
1960 ldp_session
*ses
= NULL
;
1961 mpls_return_enum r
= MPLS_FAILURE
;
1962 mpls_bool done
= MPLS_BOOL_FALSE
;
1965 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1967 if (s
->index
== 0) {
1970 index
= s
->index
+ 1;
1973 mpls_lock_get(g
->global_lock
); /* LOCK */
1974 while (done
== MPLS_BOOL_FALSE
) {
1975 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1977 case MPLS_END_OF_LIST
:
1978 done
= MPLS_BOOL_TRUE
;
1987 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1989 if (r
== MPLS_SUCCESS
) {
1990 s
->index
= ses
->index
;
1992 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1993 return ldp_cfg_session_get(g
, s
, flag
);
1996 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2001 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
2004 ldp_global
*g
= (ldp_global
*) handle
;
2005 mpls_bool this_one
= MPLS_BOOL_FALSE
;
2006 mpls_return_enum r
= MPLS_FAILURE
;
2007 ldp_adj
*adj_next
= NULL
;
2008 ldp_adj
*adj
= NULL
;
2009 ldp_session
*session
= NULL
;
2011 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
2013 /* if an adj_index of zero is sent, get the index of
2014 * the first adj in the list
2016 if (!s
->adj_index
) {
2017 this_one
= MPLS_BOOL_TRUE
;
2020 mpls_lock_get(g
->global_lock
); /* LOCK */
2022 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
2023 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
2025 if (this_one
== MPLS_BOOL_TRUE
) {
2030 /* since the entities are sort in the list ... */
2031 if (adj
->index
> s
->adj_index
) {
2033 } else if (adj
->index
== s
->adj_index
) {
2034 this_one
= MPLS_BOOL_TRUE
;
2036 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
2039 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2042 s
->adj_index
= adj_next
->index
;
2046 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
2050 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
2051 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2053 ldp_global
*global
= (ldp_global
*) handle
;
2054 ldp_session
*session
= NULL
;
2055 ldp_addr
*addr
= NULL
;
2056 mpls_return_enum retval
= MPLS_FAILURE
;
2058 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
2060 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
2062 mpls_lock_get(global
->global_lock
); /* LOCK */
2064 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
2065 goto ldp_cfg_session_raddr_get_end
;
2067 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
2068 goto ldp_cfg_session_raddr_get_end
;
2070 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
2071 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
2073 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
2074 a
->index
= addr
->index
;
2076 retval
= MPLS_SUCCESS
;
2078 ldp_cfg_session_raddr_get_end
:
2079 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2081 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
2086 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
2087 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2089 ldp_global
*g
= (ldp_global
*) handle
;
2090 ldp_addr
*addr
= NULL
;
2091 mpls_return_enum r
= MPLS_FAILURE
;
2092 mpls_bool done
= MPLS_BOOL_FALSE
;
2093 ldp_session
*sp
= NULL
;
2096 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
2098 if (a
->index
== 0) {
2101 index
= a
->index
+ 1;
2104 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
2105 if (r
!= MPLS_SUCCESS
) {
2109 mpls_lock_get(g
->global_lock
); /* LOCK */
2110 while (done
== MPLS_BOOL_FALSE
) {
2111 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
2113 case MPLS_END_OF_LIST
:
2114 done
= MPLS_BOOL_TRUE
;
2123 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2125 if (r
== MPLS_SUCCESS
) {
2126 a
->index
= addr
->index
;
2127 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
2130 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2134 /******************* IN LABEL **********************/
2136 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2139 ldp_global
*global
= (ldp_global
*) handle
;
2140 ldp_inlabel
*inlabel
= NULL
;
2141 mpls_return_enum retval
= MPLS_FAILURE
;
2143 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
2145 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
2147 mpls_lock_get(global
->global_lock
); /* LOCK */
2149 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
2150 goto ldp_cfg_inlabel_get_end
;
2152 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
2153 i
->info
.labelspace
= inlabel
->info
.labelspace
;
2155 if (flag
& LDP_INLABEL_CFG_LABEL
) {
2156 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
2158 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
2159 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
2162 retval
= MPLS_SUCCESS
;
2164 ldp_cfg_inlabel_get_end
:
2165 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2167 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
2172 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2175 ldp_global
*g
= (ldp_global
*) handle
;
2176 ldp_inlabel
*inlabel
= NULL
;
2177 mpls_return_enum r
= MPLS_FAILURE
;
2178 mpls_bool done
= MPLS_BOOL_FALSE
;
2181 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
2183 if (i
->index
== 0) {
2186 index
= i
->index
+ 1;
2189 mpls_lock_get(g
->global_lock
); /* LOCK */
2190 while (done
== MPLS_BOOL_FALSE
) {
2191 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
2193 case MPLS_END_OF_LIST
:
2194 done
= MPLS_BOOL_TRUE
;
2203 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2205 if (r
== MPLS_SUCCESS
) {
2206 i
->index
= inlabel
->index
;
2208 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2209 return ldp_cfg_inlabel_get(g
, i
, flag
);
2212 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2217 /******************* OUT LABEL **********************/
2219 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
2222 ldp_global
*global
= (ldp_global
*) handle
;
2223 ldp_outlabel
*outlabel
= NULL
;
2224 mpls_return_enum retval
= MPLS_FAILURE
;
2226 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
2228 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
2230 mpls_lock_get(global
->global_lock
); /* LOCK */
2232 if (ldp_global_find_outlabel_index(global
, o
->index
,
2233 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
2235 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
2237 o
->nh_index
= outlabel
->nh
->index
;
2242 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
2243 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
2245 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
2246 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
2248 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
2249 o
->merge_count
= outlabel
->merge_count
;
2252 retval
= MPLS_SUCCESS
;
2254 ldp_cfg_outlabel_get_end
:
2255 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2257 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
2262 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
2263 ldp_outlabel
* o
, uint32_t flag
)
2265 ldp_global
*g
= (ldp_global
*) handle
;
2266 ldp_outlabel
*outlabel
= NULL
;
2267 mpls_return_enum r
= MPLS_FAILURE
;
2268 mpls_bool done
= MPLS_BOOL_FALSE
;
2271 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
2273 if (o
->index
== 0) {
2276 index
= o
->index
+ 1;
2279 mpls_lock_get(g
->global_lock
); /* LOCK */
2280 while (done
== MPLS_BOOL_FALSE
) {
2281 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
2283 case MPLS_END_OF_LIST
:
2284 done
= MPLS_BOOL_TRUE
;
2293 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2295 if (r
== MPLS_SUCCESS
) {
2296 o
->index
= outlabel
->index
;
2298 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2299 return ldp_cfg_outlabel_get(g
, o
, flag
);
2302 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2307 /******************* TUNNEL **********************/
2309 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2312 ldp_global
*global
= (ldp_global
*) handle
;
2313 mpls_return_enum retval
= MPLS_FAILURE
;
2314 ldp_tunnel
*tunnel
= NULL
;
2316 MPLS_ASSERT(global
!=NULL
);
2318 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2320 mpls_lock_get(global
->global_lock
); /* LOCK */
2322 if (flag
& LDP_CFG_ADD
) {
2323 if (!(tunnel
= ldp_tunnel_create())) {
2324 goto ldp_cfg_tunnel_set_end
;
2326 _ldp_global_add_tunnel(global
, tunnel
);
2328 t
->index
= tunnel
->index
;
2330 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2334 LDP_PRINT(global
->user_data
,
2336 "ldp_cfg_tunnel_set:could not create tunnel\n");
2337 goto ldp_cfg_tunnel_set_end
;
2340 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2341 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2342 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2344 goto ldp_cfg_tunnel_set_end
;
2347 if (flag
& LDP_CFG_DEL
) {
2348 if (tunnel
->outlabel
)
2349 ldp_tunnel_del_outlabel(tunnel
);
2350 if (tunnel
->resource
)
2351 ldp_tunnel_del_resource(tunnel
);
2352 if (tunnel
->hop_list
)
2353 ldp_tunnel_del_hop_list(tunnel
);
2354 _ldp_global_del_tunnel(global
, tunnel
);
2356 retval
= MPLS_SUCCESS
;
2357 goto ldp_cfg_tunnel_set_end
;
2360 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2361 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2363 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2364 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2366 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2367 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2369 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2370 tunnel
->is_interface
= t
->is_interface
;
2372 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2373 ldp_outlabel
*outlabel
= NULL
;
2375 if (t
->outlabel_index
) {
2376 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2379 goto ldp_cfg_tunnel_set_end
;
2381 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2383 ldp_tunnel_del_outlabel(tunnel
);
2386 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2387 tunnel
->setup_prio
= t
->setup_prio
;
2389 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2390 tunnel
->hold_prio
= t
->hold_prio
;
2392 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2393 tunnel
->instance_prio
= t
->instance_prio
;
2395 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2396 tunnel
->local_protect
= t
->local_protect
;
2398 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2399 ldp_resource
*resource
= NULL
;
2401 if (t
->resource_index
) {
2402 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2405 goto ldp_cfg_tunnel_set_end
;
2407 ldp_tunnel_add_resource(tunnel
, resource
);
2409 ldp_tunnel_del_resource(tunnel
);
2412 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2413 ldp_hop_list
*hop_list
= NULL
;
2415 if (t
->hop_list_index
) {
2416 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2419 goto ldp_cfg_tunnel_set_end
;
2421 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2423 ldp_tunnel_del_hop_list(tunnel
);
2426 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2427 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2429 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2430 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2431 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2432 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2433 goto ldp_cfg_tunnel_set_end
;
2437 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2438 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2439 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2440 goto ldp_cfg_tunnel_set_end
;
2443 LDP_PRINT(global
->user_data
,
2445 "ldp_cfg_tunnel_set: tunnel not ready\n");
2446 goto ldp_cfg_tunnel_set_end
;
2451 retval
= MPLS_SUCCESS
;
2453 ldp_cfg_tunnel_set_end
:
2455 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2457 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2462 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2465 ldp_global
*global
= (ldp_global
*) handle
;
2466 mpls_return_enum retval
= MPLS_FAILURE
;
2467 ldp_tunnel
*tunnel
= NULL
;
2469 MPLS_ASSERT(global
!=NULL
);
2471 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2473 mpls_lock_get(global
->global_lock
); /* LOCK */
2475 if (flag
& LDP_CFG_ADD
) {
2476 retval
= MPLS_SUCCESS
;
2477 goto ldp_cfg_tunnel_test_end
;
2480 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2483 goto ldp_cfg_tunnel_test_end
;
2486 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2487 ldp_resource
*resource
= NULL
;
2489 if (t
->resource_index
) {
2490 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2493 goto ldp_cfg_tunnel_test_end
;
2497 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2498 ldp_hop_list
*hop_list
= NULL
;
2500 if (t
->hop_list_index
) {
2501 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2504 goto ldp_cfg_tunnel_test_end
;
2508 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2509 ldp_outlabel
*outlabel
= NULL
;
2511 if (t
->outlabel_index
) {
2512 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2515 goto ldp_cfg_tunnel_test_end
;
2519 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2520 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2521 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2522 goto ldp_cfg_tunnel_test_end
;
2524 retval
= MPLS_SUCCESS
;
2526 ldp_cfg_tunnel_test_end
:
2528 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2530 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2535 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2538 ldp_global
*global
= (ldp_global
*) handle
;
2539 mpls_return_enum retval
= MPLS_FAILURE
;
2540 ldp_tunnel
*tunnel
= NULL
;
2542 MPLS_ASSERT(global
!=NULL
);
2544 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2546 mpls_lock_get(global
->global_lock
); /* LOCK */
2548 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2551 goto ldp_cfg_tunnel_get_end
;
2553 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2554 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2556 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2557 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2559 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2560 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2562 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2563 t
->is_interface
= tunnel
->is_interface
;
2565 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2566 if (tunnel
->outlabel
) {
2567 t
->outlabel_index
= tunnel
->outlabel
->index
;
2569 t
->outlabel_index
= 0;
2572 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2573 t
->setup_prio
= tunnel
->setup_prio
;
2575 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2576 t
->hold_prio
= tunnel
->hold_prio
;
2578 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2579 tunnel
->instance_prio
= t
->instance_prio
;
2581 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2582 tunnel
->local_protect
= t
->local_protect
;
2584 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2585 if (tunnel
->resource
) {
2586 t
->resource_index
= tunnel
->resource
->index
;
2588 t
->resource_index
= 0;
2591 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2592 if (tunnel
->hop_list
) {
2593 t
->hop_list_index
= tunnel
->hop_list
->index
;
2595 t
->hop_list_index
= 0;
2598 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2599 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2601 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2602 t
->admin_state
= tunnel
->admin_state
;
2604 retval
= MPLS_SUCCESS
;
2606 ldp_cfg_tunnel_get_end
:
2608 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2610 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2615 /******************* RESOURCE **********************/
2617 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2620 ldp_global
*global
= (ldp_global
*) handle
;
2621 mpls_return_enum retval
= MPLS_FAILURE
;
2622 ldp_resource
*resource
= NULL
;
2624 MPLS_ASSERT(global
!=NULL
);
2626 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2628 mpls_lock_get(global
->global_lock
); /* LOCK */
2630 if (flag
& LDP_CFG_ADD
) {
2631 resource
= ldp_resource_create();
2632 _ldp_global_add_resource(global
, resource
);
2634 r
->index
= resource
->index
;
2636 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2640 goto ldp_cfg_resource_set_end
;
2643 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2644 resource
->max_rate
= r
->max_rate
;
2646 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2647 resource
->mean_rate
= r
->mean_rate
;
2649 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2650 resource
->burst_size
= r
->burst_size
;
2652 retval
= MPLS_SUCCESS
;
2654 ldp_cfg_resource_set_end
:
2656 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2658 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2663 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2666 ldp_global
*global
= (ldp_global
*) handle
;
2667 mpls_return_enum retval
= MPLS_FAILURE
;
2668 ldp_resource
*resource
= NULL
;
2670 MPLS_ASSERT(global
!=NULL
);
2672 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2674 mpls_lock_get(global
->global_lock
); /* LOCK */
2676 if (flag
& LDP_CFG_ADD
) {
2677 retval
= MPLS_SUCCESS
;
2678 goto ldp_cfg_resource_test_end
;
2681 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2684 goto ldp_cfg_resource_test_end
;
2687 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2688 goto ldp_cfg_resource_test_end
;
2690 retval
= MPLS_SUCCESS
;
2692 ldp_cfg_resource_test_end
:
2694 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2696 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2701 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2704 ldp_global
*global
= (ldp_global
*) handle
;
2705 mpls_return_enum retval
= MPLS_FAILURE
;
2706 ldp_resource
*resource
= NULL
;
2708 MPLS_ASSERT(global
!=NULL
);
2710 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2712 mpls_lock_get(global
->global_lock
); /* LOCK */
2714 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2717 goto ldp_cfg_resource_get_end
;
2720 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2721 r
->max_rate
= resource
->max_rate
;
2723 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2724 r
->mean_rate
= resource
->mean_rate
;
2726 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2727 r
->burst_size
= resource
->burst_size
;
2729 retval
= MPLS_SUCCESS
;
2731 ldp_cfg_resource_get_end
:
2733 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2735 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2740 /******************* HOP **********************/
2742 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2745 ldp_global
*global
= (ldp_global
*) handle
;
2746 mpls_return_enum retval
= MPLS_FAILURE
;
2747 ldp_hop_list
*hop_list
= NULL
;
2748 ldp_hop
*hop
= NULL
;
2750 MPLS_ASSERT(global
!=NULL
);
2752 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2754 if (!h
->hop_list_index
&& !h
->index
) {
2758 mpls_lock_get(global
->global_lock
); /* LOCK */
2760 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2763 if (flag
& LDP_CFG_ADD
) {
2764 if (!(hop_list
= ldp_hop_list_create())) {
2765 goto ldp_cfg_hop_set_end
;
2767 _ldp_global_add_hop_list(global
, hop_list
);
2769 h
->hop_list_index
= hop_list
->index
;
2771 goto ldp_cfg_hop_set_end
;
2775 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2777 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2778 if (!(hop
= ldp_hop_create())) {
2779 goto ldp_cfg_hop_set_end
;
2781 hop
->index
= h
->index
;
2782 ldp_hop_list_add_hop(hop_list
, hop
);
2784 goto ldp_cfg_hop_set_end
;
2788 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2789 hop
->path_option
= h
->path_option
;
2791 if (flag
& LDP_HOP_CFG_ADDR
) {
2792 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2794 if (flag
& LDP_HOP_CFG_TYPE
) {
2795 hop
->type
= h
->type
;
2797 retval
= MPLS_SUCCESS
;
2799 ldp_cfg_hop_set_end
:
2801 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2803 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2808 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2811 ldp_global
*global
= (ldp_global
*) handle
;
2812 mpls_return_enum retval
= MPLS_FAILURE
;
2813 ldp_hop_list
*hop_list
= NULL
;
2814 ldp_hop
*hop
= NULL
;
2816 MPLS_ASSERT(global
!=NULL
);
2818 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2820 mpls_lock_get(global
->global_lock
); /* LOCK */
2822 if (flag
& LDP_CFG_ADD
) {
2823 retval
= MPLS_SUCCESS
;
2824 goto ldp_cfg_hop_test_end
;
2827 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2830 goto ldp_cfg_hop_test_end
;
2833 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2835 goto ldp_cfg_hop_test_end
;
2838 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2839 goto ldp_cfg_hop_test_end
;
2841 retval
= MPLS_SUCCESS
;
2843 ldp_cfg_hop_test_end
:
2845 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2847 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2852 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2855 ldp_global
*global
= (ldp_global
*) handle
;
2856 mpls_return_enum retval
= MPLS_FAILURE
;
2857 ldp_hop_list
*hop_list
= NULL
;
2858 ldp_hop
*hop
= NULL
;
2860 MPLS_ASSERT(global
!=NULL
);
2862 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2864 mpls_lock_get(global
->global_lock
); /* LOCK */
2866 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2869 goto ldp_cfg_hop_get_end
;
2872 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2874 goto ldp_cfg_hop_get_end
;
2877 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2878 h
->path_option
= hop
->path_option
;
2880 if (flag
& LDP_HOP_CFG_ADDR
) {
2881 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2883 if (flag
& LDP_HOP_CFG_TYPE
) {
2884 h
->type
= hop
->type
;
2886 retval
= MPLS_SUCCESS
;
2888 ldp_cfg_hop_get_end
:
2890 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2892 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");