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
);
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_if_del_addr(global
, iff
, addr
);
1757 retval
= MPLS_SUCCESS
;
1759 ldp_cfg_if_addr_set_end
:
1760 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1762 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_set");
1767 /******************* ADJACENCY **********************/
1769 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1772 ldp_global
*global
= (ldp_global
*) handle
;
1773 ldp_adj
*adj
= NULL
;
1774 mpls_return_enum retval
= MPLS_FAILURE
;
1776 MPLS_ASSERT(global
!= NULL
&& a
!= NULL
);
1778 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1780 mpls_lock_get(global
->global_lock
); /* LOCK */
1782 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1783 goto ldp_cfg_adj_get_end
;
1785 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1786 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1787 sizeof(mpls_inet_addr
));
1789 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1790 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1791 sizeof(mpls_inet_addr
));
1793 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1794 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1795 sizeof(mpls_inet_addr
));
1797 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1798 a
->remote_csn
= adj
->remote_csn
;
1800 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1801 a
->remote_label_space
= adj
->remote_label_space
;
1803 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1804 a
->remote_hellotime
= adj
->remote_hellotime
;
1806 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1807 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1809 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1810 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1812 if (flag
& LDP_ADJ_CFG_ROLE
) {
1813 a
->role
= adj
->role
;
1815 retval
= MPLS_SUCCESS
;
1817 ldp_cfg_adj_get_end
:
1819 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1821 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1826 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1829 ldp_global
*g
= (ldp_global
*) handle
;
1830 ldp_adj
*adj
= NULL
;
1831 mpls_return_enum r
= MPLS_FAILURE
;
1832 mpls_bool done
= MPLS_BOOL_FALSE
;
1835 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1837 if (a
->index
== 0) {
1840 index
= a
->index
+ 1;
1843 mpls_lock_get(g
->global_lock
); /* LOCK */
1844 while (done
== MPLS_BOOL_FALSE
) {
1845 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1847 case MPLS_END_OF_LIST
:
1848 done
= MPLS_BOOL_TRUE
;
1857 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1859 if (r
== MPLS_SUCCESS
) {
1860 a
->index
= adj
->index
;
1861 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1862 return ldp_cfg_adj_get(g
, a
, flag
);
1864 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1868 /******************* SESSION **********************/
1870 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1873 ldp_global
*global
= (ldp_global
*) handle
;
1874 ldp_session
*session
= NULL
;
1875 mpls_return_enum retval
= MPLS_FAILURE
;
1877 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1879 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1881 mpls_lock_get(global
->global_lock
); /* LOCK */
1883 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1884 goto ldp_cfg_session_get_end
;
1886 if (flag
& LDP_SESSION_CFG_STATE
) {
1887 s
->state
= session
->state
;
1889 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1890 s
->oper_up
= session
->oper_up
;
1892 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1893 s
->oper_max_pdu
= session
->oper_max_pdu
;
1895 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1896 s
->oper_keepalive
= session
->oper_keepalive
;
1898 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1899 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1901 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1902 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1904 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1905 s
->oper_loop_detection
= session
->oper_loop_detection
;
1907 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1908 s
->remote_max_pdu
= session
->remote_max_pdu
;
1910 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1911 s
->remote_keepalive
= session
->remote_keepalive
;
1913 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1914 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1916 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1917 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1919 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1920 s
->remote_loop_detection
= session
->remote_loop_detection
;
1922 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1923 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1924 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1926 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1927 s
->remote_dest
.port
= session
->remote_dest
.port
;
1929 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1930 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1932 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1933 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1935 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1936 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1937 s
->adj_index
= a
? a
->index
: 0;
1939 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1940 s
->mesg_tx
= session
->mesg_tx
;
1942 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1943 s
->mesg_rx
= session
->mesg_rx
;
1945 retval
= MPLS_SUCCESS
;
1947 ldp_cfg_session_get_end
:
1948 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1950 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1955 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1958 ldp_global
*g
= (ldp_global
*) handle
;
1959 ldp_session
*ses
= NULL
;
1960 mpls_return_enum r
= MPLS_FAILURE
;
1961 mpls_bool done
= MPLS_BOOL_FALSE
;
1964 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1966 if (s
->index
== 0) {
1969 index
= s
->index
+ 1;
1972 mpls_lock_get(g
->global_lock
); /* LOCK */
1973 while (done
== MPLS_BOOL_FALSE
) {
1974 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1976 case MPLS_END_OF_LIST
:
1977 done
= MPLS_BOOL_TRUE
;
1986 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1988 if (r
== MPLS_SUCCESS
) {
1989 s
->index
= ses
->index
;
1991 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1992 return ldp_cfg_session_get(g
, s
, flag
);
1995 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2000 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
2003 ldp_global
*g
= (ldp_global
*) handle
;
2004 mpls_bool this_one
= MPLS_BOOL_FALSE
;
2005 mpls_return_enum r
= MPLS_FAILURE
;
2006 ldp_adj
*adj_next
= NULL
;
2007 ldp_adj
*adj
= NULL
;
2008 ldp_session
*session
= NULL
;
2010 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
2012 /* if an adj_index of zero is sent, get the index of
2013 * the first adj in the list
2015 if (!s
->adj_index
) {
2016 this_one
= MPLS_BOOL_TRUE
;
2019 mpls_lock_get(g
->global_lock
); /* LOCK */
2021 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
2022 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
2024 if (this_one
== MPLS_BOOL_TRUE
) {
2029 /* since the entities are sort in the list ... */
2030 if (adj
->index
> s
->adj_index
) {
2032 } else if (adj
->index
== s
->adj_index
) {
2033 this_one
= MPLS_BOOL_TRUE
;
2035 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
2038 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2041 s
->adj_index
= adj_next
->index
;
2045 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
2049 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
2050 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2052 ldp_global
*global
= (ldp_global
*) handle
;
2053 ldp_session
*session
= NULL
;
2054 ldp_addr
*addr
= NULL
;
2055 mpls_return_enum retval
= MPLS_FAILURE
;
2057 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
2059 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
2061 mpls_lock_get(global
->global_lock
); /* LOCK */
2063 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
2064 goto ldp_cfg_session_raddr_get_end
;
2066 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
2067 goto ldp_cfg_session_raddr_get_end
;
2069 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
2070 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
2072 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
2073 a
->index
= addr
->index
;
2075 retval
= MPLS_SUCCESS
;
2077 ldp_cfg_session_raddr_get_end
:
2078 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2080 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
2085 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
2086 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2088 ldp_global
*g
= (ldp_global
*) handle
;
2089 ldp_addr
*addr
= NULL
;
2090 mpls_return_enum r
= MPLS_FAILURE
;
2091 mpls_bool done
= MPLS_BOOL_FALSE
;
2092 ldp_session
*sp
= NULL
;
2095 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
2097 if (a
->index
== 0) {
2100 index
= a
->index
+ 1;
2103 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
2104 if (r
!= MPLS_SUCCESS
) {
2108 mpls_lock_get(g
->global_lock
); /* LOCK */
2109 while (done
== MPLS_BOOL_FALSE
) {
2110 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
2112 case MPLS_END_OF_LIST
:
2113 done
= MPLS_BOOL_TRUE
;
2122 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2124 if (r
== MPLS_SUCCESS
) {
2125 a
->index
= addr
->index
;
2126 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
2129 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2133 /******************* IN LABEL **********************/
2135 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2138 ldp_global
*global
= (ldp_global
*) handle
;
2139 ldp_inlabel
*inlabel
= NULL
;
2140 mpls_return_enum retval
= MPLS_FAILURE
;
2142 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
2144 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
2146 mpls_lock_get(global
->global_lock
); /* LOCK */
2148 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
2149 goto ldp_cfg_inlabel_get_end
;
2151 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
2152 i
->info
.labelspace
= inlabel
->info
.labelspace
;
2154 if (flag
& LDP_INLABEL_CFG_LABEL
) {
2155 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
2157 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
2158 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
2161 retval
= MPLS_SUCCESS
;
2163 ldp_cfg_inlabel_get_end
:
2164 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2166 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
2171 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2174 ldp_global
*g
= (ldp_global
*) handle
;
2175 ldp_inlabel
*inlabel
= NULL
;
2176 mpls_return_enum r
= MPLS_FAILURE
;
2177 mpls_bool done
= MPLS_BOOL_FALSE
;
2180 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
2182 if (i
->index
== 0) {
2185 index
= i
->index
+ 1;
2188 mpls_lock_get(g
->global_lock
); /* LOCK */
2189 while (done
== MPLS_BOOL_FALSE
) {
2190 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
2192 case MPLS_END_OF_LIST
:
2193 done
= MPLS_BOOL_TRUE
;
2202 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2204 if (r
== MPLS_SUCCESS
) {
2205 i
->index
= inlabel
->index
;
2207 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2208 return ldp_cfg_inlabel_get(g
, i
, flag
);
2211 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2216 /******************* OUT LABEL **********************/
2218 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
2221 ldp_global
*global
= (ldp_global
*) handle
;
2222 ldp_outlabel
*outlabel
= NULL
;
2223 mpls_return_enum retval
= MPLS_FAILURE
;
2225 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
2227 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
2229 mpls_lock_get(global
->global_lock
); /* LOCK */
2231 if (ldp_global_find_outlabel_index(global
, o
->index
,
2232 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
2234 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
2236 o
->nh_index
= outlabel
->nh
->index
;
2241 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
2242 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
2244 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
2245 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
2247 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
2248 o
->merge_count
= outlabel
->merge_count
;
2251 retval
= MPLS_SUCCESS
;
2253 ldp_cfg_outlabel_get_end
:
2254 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2256 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
2261 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
2262 ldp_outlabel
* o
, uint32_t flag
)
2264 ldp_global
*g
= (ldp_global
*) handle
;
2265 ldp_outlabel
*outlabel
= NULL
;
2266 mpls_return_enum r
= MPLS_FAILURE
;
2267 mpls_bool done
= MPLS_BOOL_FALSE
;
2270 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
2272 if (o
->index
== 0) {
2275 index
= o
->index
+ 1;
2278 mpls_lock_get(g
->global_lock
); /* LOCK */
2279 while (done
== MPLS_BOOL_FALSE
) {
2280 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
2282 case MPLS_END_OF_LIST
:
2283 done
= MPLS_BOOL_TRUE
;
2292 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2294 if (r
== MPLS_SUCCESS
) {
2295 o
->index
= outlabel
->index
;
2297 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2298 return ldp_cfg_outlabel_get(g
, o
, flag
);
2301 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2306 /******************* TUNNEL **********************/
2308 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2311 ldp_global
*global
= (ldp_global
*) handle
;
2312 mpls_return_enum retval
= MPLS_FAILURE
;
2313 ldp_tunnel
*tunnel
= NULL
;
2315 MPLS_ASSERT(global
!=NULL
);
2317 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2319 mpls_lock_get(global
->global_lock
); /* LOCK */
2321 if (flag
& LDP_CFG_ADD
) {
2322 if (!(tunnel
= ldp_tunnel_create())) {
2323 goto ldp_cfg_tunnel_set_end
;
2325 _ldp_global_add_tunnel(global
, tunnel
);
2327 t
->index
= tunnel
->index
;
2329 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2333 LDP_PRINT(global
->user_data
,
2335 "ldp_cfg_tunnel_set:could not create tunnel\n");
2336 goto ldp_cfg_tunnel_set_end
;
2339 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2340 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2341 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2343 goto ldp_cfg_tunnel_set_end
;
2346 if (flag
& LDP_CFG_DEL
) {
2347 if (tunnel
->outlabel
)
2348 ldp_tunnel_del_outlabel(tunnel
);
2349 if (tunnel
->resource
)
2350 ldp_tunnel_del_resource(tunnel
);
2351 if (tunnel
->hop_list
)
2352 ldp_tunnel_del_hop_list(tunnel
);
2353 _ldp_global_del_tunnel(global
, tunnel
);
2355 retval
= MPLS_SUCCESS
;
2356 goto ldp_cfg_tunnel_set_end
;
2359 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2360 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2362 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2363 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2365 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2366 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2368 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2369 tunnel
->is_interface
= t
->is_interface
;
2371 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2372 ldp_outlabel
*outlabel
= NULL
;
2374 if (t
->outlabel_index
) {
2375 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2378 goto ldp_cfg_tunnel_set_end
;
2380 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2382 ldp_tunnel_del_outlabel(tunnel
);
2385 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2386 tunnel
->setup_prio
= t
->setup_prio
;
2388 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2389 tunnel
->hold_prio
= t
->hold_prio
;
2391 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2392 tunnel
->instance_prio
= t
->instance_prio
;
2394 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2395 tunnel
->local_protect
= t
->local_protect
;
2397 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2398 ldp_resource
*resource
= NULL
;
2400 if (t
->resource_index
) {
2401 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2404 goto ldp_cfg_tunnel_set_end
;
2406 ldp_tunnel_add_resource(tunnel
, resource
);
2408 ldp_tunnel_del_resource(tunnel
);
2411 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2412 ldp_hop_list
*hop_list
= NULL
;
2414 if (t
->hop_list_index
) {
2415 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2418 goto ldp_cfg_tunnel_set_end
;
2420 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2422 ldp_tunnel_del_hop_list(tunnel
);
2425 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2426 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2428 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2429 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2430 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2431 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2432 goto ldp_cfg_tunnel_set_end
;
2436 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2437 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2438 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2439 goto ldp_cfg_tunnel_set_end
;
2442 LDP_PRINT(global
->user_data
,
2444 "ldp_cfg_tunnel_set: tunnel not ready\n");
2445 goto ldp_cfg_tunnel_set_end
;
2450 retval
= MPLS_SUCCESS
;
2452 ldp_cfg_tunnel_set_end
:
2454 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2456 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2461 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2464 ldp_global
*global
= (ldp_global
*) handle
;
2465 mpls_return_enum retval
= MPLS_FAILURE
;
2466 ldp_tunnel
*tunnel
= NULL
;
2468 MPLS_ASSERT(global
!=NULL
);
2470 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2472 mpls_lock_get(global
->global_lock
); /* LOCK */
2474 if (flag
& LDP_CFG_ADD
) {
2475 retval
= MPLS_SUCCESS
;
2476 goto ldp_cfg_tunnel_test_end
;
2479 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2482 goto ldp_cfg_tunnel_test_end
;
2485 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2486 ldp_resource
*resource
= NULL
;
2488 if (t
->resource_index
) {
2489 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2492 goto ldp_cfg_tunnel_test_end
;
2496 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2497 ldp_hop_list
*hop_list
= NULL
;
2499 if (t
->hop_list_index
) {
2500 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2503 goto ldp_cfg_tunnel_test_end
;
2507 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2508 ldp_outlabel
*outlabel
= NULL
;
2510 if (t
->outlabel_index
) {
2511 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2514 goto ldp_cfg_tunnel_test_end
;
2518 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2519 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2520 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2521 goto ldp_cfg_tunnel_test_end
;
2523 retval
= MPLS_SUCCESS
;
2525 ldp_cfg_tunnel_test_end
:
2527 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2529 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2534 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2537 ldp_global
*global
= (ldp_global
*) handle
;
2538 mpls_return_enum retval
= MPLS_FAILURE
;
2539 ldp_tunnel
*tunnel
= NULL
;
2541 MPLS_ASSERT(global
!=NULL
);
2543 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2545 mpls_lock_get(global
->global_lock
); /* LOCK */
2547 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2550 goto ldp_cfg_tunnel_get_end
;
2552 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2553 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2555 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2556 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2558 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2559 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2561 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2562 t
->is_interface
= tunnel
->is_interface
;
2564 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2565 if (tunnel
->outlabel
) {
2566 t
->outlabel_index
= tunnel
->outlabel
->index
;
2568 t
->outlabel_index
= 0;
2571 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2572 t
->setup_prio
= tunnel
->setup_prio
;
2574 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2575 t
->hold_prio
= tunnel
->hold_prio
;
2577 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2578 tunnel
->instance_prio
= t
->instance_prio
;
2580 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2581 tunnel
->local_protect
= t
->local_protect
;
2583 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2584 if (tunnel
->resource
) {
2585 t
->resource_index
= tunnel
->resource
->index
;
2587 t
->resource_index
= 0;
2590 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2591 if (tunnel
->hop_list
) {
2592 t
->hop_list_index
= tunnel
->hop_list
->index
;
2594 t
->hop_list_index
= 0;
2597 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2598 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2600 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2601 t
->admin_state
= tunnel
->admin_state
;
2603 retval
= MPLS_SUCCESS
;
2605 ldp_cfg_tunnel_get_end
:
2607 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2609 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2614 /******************* RESOURCE **********************/
2616 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2619 ldp_global
*global
= (ldp_global
*) handle
;
2620 mpls_return_enum retval
= MPLS_FAILURE
;
2621 ldp_resource
*resource
= NULL
;
2623 MPLS_ASSERT(global
!=NULL
);
2625 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2627 mpls_lock_get(global
->global_lock
); /* LOCK */
2629 if (flag
& LDP_CFG_ADD
) {
2630 resource
= ldp_resource_create();
2631 _ldp_global_add_resource(global
, resource
);
2633 r
->index
= resource
->index
;
2635 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2639 goto ldp_cfg_resource_set_end
;
2642 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2643 resource
->max_rate
= r
->max_rate
;
2645 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2646 resource
->mean_rate
= r
->mean_rate
;
2648 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2649 resource
->burst_size
= r
->burst_size
;
2651 retval
= MPLS_SUCCESS
;
2653 ldp_cfg_resource_set_end
:
2655 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2657 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2662 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2665 ldp_global
*global
= (ldp_global
*) handle
;
2666 mpls_return_enum retval
= MPLS_FAILURE
;
2667 ldp_resource
*resource
= NULL
;
2669 MPLS_ASSERT(global
!=NULL
);
2671 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2673 mpls_lock_get(global
->global_lock
); /* LOCK */
2675 if (flag
& LDP_CFG_ADD
) {
2676 retval
= MPLS_SUCCESS
;
2677 goto ldp_cfg_resource_test_end
;
2680 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2683 goto ldp_cfg_resource_test_end
;
2686 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2687 goto ldp_cfg_resource_test_end
;
2689 retval
= MPLS_SUCCESS
;
2691 ldp_cfg_resource_test_end
:
2693 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2695 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2700 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2703 ldp_global
*global
= (ldp_global
*) handle
;
2704 mpls_return_enum retval
= MPLS_FAILURE
;
2705 ldp_resource
*resource
= NULL
;
2707 MPLS_ASSERT(global
!=NULL
);
2709 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2711 mpls_lock_get(global
->global_lock
); /* LOCK */
2713 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2716 goto ldp_cfg_resource_get_end
;
2719 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2720 r
->max_rate
= resource
->max_rate
;
2722 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2723 r
->mean_rate
= resource
->mean_rate
;
2725 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2726 r
->burst_size
= resource
->burst_size
;
2728 retval
= MPLS_SUCCESS
;
2730 ldp_cfg_resource_get_end
:
2732 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2734 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2739 /******************* HOP **********************/
2741 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2744 ldp_global
*global
= (ldp_global
*) handle
;
2745 mpls_return_enum retval
= MPLS_FAILURE
;
2746 ldp_hop_list
*hop_list
= NULL
;
2747 ldp_hop
*hop
= NULL
;
2749 MPLS_ASSERT(global
!=NULL
);
2751 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2753 if (!h
->hop_list_index
&& !h
->index
) {
2757 mpls_lock_get(global
->global_lock
); /* LOCK */
2759 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2762 if (flag
& LDP_CFG_ADD
) {
2763 if (!(hop_list
= ldp_hop_list_create())) {
2764 goto ldp_cfg_hop_set_end
;
2766 _ldp_global_add_hop_list(global
, hop_list
);
2768 h
->hop_list_index
= hop_list
->index
;
2770 goto ldp_cfg_hop_set_end
;
2774 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2776 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2777 if (!(hop
= ldp_hop_create())) {
2778 goto ldp_cfg_hop_set_end
;
2780 hop
->index
= h
->index
;
2781 ldp_hop_list_add_hop(hop_list
, hop
);
2783 goto ldp_cfg_hop_set_end
;
2787 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2788 hop
->path_option
= h
->path_option
;
2790 if (flag
& LDP_HOP_CFG_ADDR
) {
2791 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2793 if (flag
& LDP_HOP_CFG_TYPE
) {
2794 hop
->type
= h
->type
;
2796 retval
= MPLS_SUCCESS
;
2798 ldp_cfg_hop_set_end
:
2800 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2802 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2807 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2810 ldp_global
*global
= (ldp_global
*) handle
;
2811 mpls_return_enum retval
= MPLS_FAILURE
;
2812 ldp_hop_list
*hop_list
= NULL
;
2813 ldp_hop
*hop
= NULL
;
2815 MPLS_ASSERT(global
!=NULL
);
2817 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2819 mpls_lock_get(global
->global_lock
); /* LOCK */
2821 if (flag
& LDP_CFG_ADD
) {
2822 retval
= MPLS_SUCCESS
;
2823 goto ldp_cfg_hop_test_end
;
2826 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2829 goto ldp_cfg_hop_test_end
;
2832 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2834 goto ldp_cfg_hop_test_end
;
2837 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2838 goto ldp_cfg_hop_test_end
;
2840 retval
= MPLS_SUCCESS
;
2842 ldp_cfg_hop_test_end
:
2844 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2846 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2851 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2854 ldp_global
*global
= (ldp_global
*) handle
;
2855 mpls_return_enum retval
= MPLS_FAILURE
;
2856 ldp_hop_list
*hop_list
= NULL
;
2857 ldp_hop
*hop
= NULL
;
2859 MPLS_ASSERT(global
!=NULL
);
2861 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2863 mpls_lock_get(global
->global_lock
); /* LOCK */
2865 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2868 goto ldp_cfg_hop_get_end
;
2871 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2873 goto ldp_cfg_hop_get_end
;
2876 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2877 h
->path_option
= hop
->path_option
;
2879 if (flag
& LDP_HOP_CFG_ADDR
) {
2880 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2882 if (flag
& LDP_HOP_CFG_TYPE
) {
2883 h
->type
= hop
->type
;
2885 retval
= MPLS_SUCCESS
;
2887 ldp_cfg_hop_get_end
:
2889 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2891 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");