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"
18 #include "ldp_tunnel.h"
19 #include "ldp_resource.h"
20 #include "mpls_ifmgr_impl.h"
21 #include "ldp_label_mapping.h"
23 #include "ldp_hop_list.h"
24 #include "mpls_lock_impl.h"
25 #include "mpls_trace_impl.h"
26 #include "mpls_tree_impl.h"
28 mpls_cfg_handle
ldp_cfg_open(mpls_instance_handle data
)
30 ldp_global
*g
= ldp_global_create(data
);
32 LDP_ENTER(data
, "ldp_cfg_open");
33 LDP_EXIT(data
, "ldp_cfg_open");
35 return (mpls_cfg_handle
) g
;
38 void ldp_cfg_close(mpls_cfg_handle g
)
40 LDP_ENTER((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
42 LDP_EXIT((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
45 /******************* GLOBAL **********************/
47 mpls_return_enum
ldp_cfg_global_get(mpls_cfg_handle handle
, ldp_global
* g
,
50 ldp_global
*global
= (ldp_global
*) handle
;
52 MPLS_ASSERT(global
!=NULL
);
54 LDP_ENTER(global
->user_data
, "ldp_cfg_global_get");
56 mpls_lock_get(global
->global_lock
); /* LOCK */
58 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
59 memcpy(&(g
->lsr_identifier
), &(global
->lsr_identifier
),
60 sizeof(mpls_inet_addr
));
62 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
63 g
->admin_state
= global
->admin_state
;
65 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
66 g
->lsp_control_mode
= global
->lsp_control_mode
;
68 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
69 g
->label_retention_mode
= global
->label_retention_mode
;
71 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
72 g
->lsp_repair_mode
= global
->lsp_repair_mode
;
74 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
75 g
->propagate_release
= global
->propagate_release
;
77 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
78 g
->label_merge
= global
->label_merge
;
80 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
81 g
->loop_detection_mode
= global
->loop_detection_mode
;
83 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
84 g
->ttl_less_domain
= global
->ttl_less_domain
;
86 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
87 g
->local_tcp_port
= global
->local_tcp_port
;
89 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
90 g
->local_udp_port
= global
->local_udp_port
;
92 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
93 memcpy(&(g
->transport_address
), &(global
->transport_address
),
94 sizeof(mpls_inet_addr
));
96 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
97 g
->keepalive_timer
= global
->keepalive_timer
;
99 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
100 g
->keepalive_interval
= global
->keepalive_interval
;
102 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
103 g
->hellotime_timer
= global
->hellotime_timer
;
105 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
106 g
->hellotime_interval
= global
->hellotime_interval
;
109 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
110 g
->lsr_handle
= global
->lsr_handle
;
114 mpls_lock_release(global
->global_lock
); /* UNLOCK */
116 LDP_EXIT(global
->user_data
, "ldp_cfg_global_get");
121 mpls_return_enum
ldp_cfg_global_test(mpls_cfg_handle handle
, ldp_global
* g
,
124 ldp_global
*global
= (ldp_global
*) handle
;
125 mpls_return_enum retval
= MPLS_SUCCESS
;
127 MPLS_ASSERT(global
!=NULL
);
129 LDP_ENTER(global
->user_data
, "ldp_cfg_global_test");
131 mpls_lock_get(global
->global_lock
); /* LOCK */
133 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
))
134 retval
= MPLS_FAILURE
;
136 mpls_lock_release(global
->global_lock
); /* UNLOCK */
138 LDP_EXIT(global
->user_data
, "ldp_cfg_global_test");
143 mpls_return_enum
ldp_cfg_global_set(mpls_cfg_handle handle
, ldp_global
* g
,
146 ldp_global
*global
= (ldp_global
*) handle
;
147 mpls_return_enum retval
= MPLS_FAILURE
;
149 MPLS_ASSERT(global
!=NULL
);
151 LDP_ENTER(global
->user_data
, "ldp_cfg_global_set");
153 mpls_lock_get(global
->global_lock
); /* LOCK */
155 if ((global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
)))
156 goto ldp_cfg_global_set_end
;
158 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
159 global
->lsp_control_mode
= g
->lsp_control_mode
;
161 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
162 global
->label_retention_mode
= g
->label_retention_mode
;
164 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
165 global
->lsp_repair_mode
= g
->lsp_repair_mode
;
167 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
168 global
->propagate_release
= g
->propagate_release
;
170 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
171 global
->label_merge
= g
->label_merge
;
173 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
174 global
->loop_detection_mode
= g
->loop_detection_mode
;
176 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
177 global
->ttl_less_domain
= g
->ttl_less_domain
;
179 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
180 global
->local_tcp_port
= g
->local_tcp_port
;
182 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
183 global
->local_udp_port
= g
->local_udp_port
;
185 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
186 memcpy(&(global
->lsr_identifier
), &(g
->lsr_identifier
),
187 sizeof(mpls_inet_addr
));
190 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
191 global
->lsr_handle
= g
->lsr_handle
;
194 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
195 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& g
->admin_state
== MPLS_ADMIN_DISABLE
) {
196 ldp_global_shutdown(global
);
197 } else if (global
->admin_state
== MPLS_ADMIN_DISABLE
&& g
->admin_state
==
199 ldp_global_startup(global
);
202 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
203 memcpy(&(global
->transport_address
), &(g
->transport_address
),
204 sizeof(mpls_inet_addr
));
206 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
207 if (g
->keepalive_timer
== 0) {
208 global
->keepalive_timer
= LDP_ENTITY_DEF_KEEPALIVE_TIMER
;
210 global
->keepalive_timer
= g
->keepalive_timer
;
213 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
214 if (g
->keepalive_interval
== 0) {
215 global
->keepalive_interval
= LDP_ENTITY_DEF_KEEPALIVE_INTERVAL
;
217 global
->keepalive_interval
= g
->keepalive_interval
;
220 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
221 if (g
->hellotime_timer
== 0) {
222 global
->hellotime_timer
= LDP_ENTITY_DEF_HELLOTIME_TIMER
;
224 global
->hellotime_timer
= g
->hellotime_timer
;
227 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
228 if (g
->hellotime_interval
== 0) {
229 global
->hellotime_interval
= LDP_ENTITY_DEF_HELLOTIME_INTERVAL
;
231 global
->hellotime_interval
= g
->hellotime_interval
;
235 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
236 global
->lsr_handle
= g
->lsr_handle
;
239 global
->configuration_sequence_number
++;
241 retval
= MPLS_SUCCESS
;
243 ldp_cfg_global_set_end
:
245 mpls_lock_release(global
->global_lock
); /* UNLOCK */
247 LDP_EXIT(global
->user_data
, "ldp_cfg_global_set");
252 /******************* ENTITY **********************/
254 /* must set ldp_entity->index */
255 mpls_return_enum
ldp_cfg_entity_get(mpls_cfg_handle handle
, ldp_entity
* e
,
258 ldp_global
*global
= (ldp_global
*) handle
;
259 ldp_entity
*entity
= NULL
;
260 mpls_return_enum retval
= MPLS_FAILURE
;
262 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
264 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_get");
266 mpls_lock_get(global
->global_lock
); /* LOCK */
268 if (ldp_global_find_entity_index(global
, e
->index
, &entity
) != MPLS_SUCCESS
)
269 goto ldp_cfg_entity_get_end
;
271 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
272 e
->admin_state
= entity
->admin_state
;
274 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
275 e
->transport_address
= entity
->transport_address
;
277 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
278 e
->protocol_version
= entity
->protocol_version
;
280 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
281 e
->remote_tcp_port
= entity
->remote_tcp_port
;
283 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
284 e
->remote_udp_port
= entity
->remote_udp_port
;
286 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
287 e
->max_pdu
= entity
->max_pdu
;
289 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
290 e
->keepalive_timer
= entity
->keepalive_timer
;
292 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
293 e
->keepalive_interval
= entity
->keepalive_interval
;
295 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
296 e
->hellotime_timer
= entity
->hellotime_timer
;
298 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
299 e
->hellotime_interval
= entity
->hellotime_interval
;
301 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
302 e
->session_setup_count
= entity
->session_setup_count
;
304 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
305 e
->session_backoff_timer
= entity
->session_backoff_timer
;
307 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
308 e
->label_distribution_mode
= entity
->label_distribution_mode
;
310 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
311 e
->path_vector_limit
= entity
->path_vector_limit
;
313 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
314 e
->hop_count_limit
= entity
->hop_count_limit
;
316 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
317 e
->label_request_count
= entity
->label_request_count
;
319 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
320 e
->label_request_timer
= entity
->label_request_timer
;
322 if (flag
& LDP_ENTITY_CFG_TYPE
) {
323 e
->entity_type
= entity
->entity_type
;
325 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
326 e
->sub_index
= entity
->sub_index
;
328 if (flag
& LDP_ENTITY_CFG_MESG_TX
) {
329 e
->mesg_tx
= entity
->mesg_tx
;
331 if (flag
& LDP_ENTITY_CFG_MESG_RX
) {
332 e
->mesg_rx
= entity
->mesg_rx
;
334 if (flag
& LDP_ENTITY_CFG_ADJ_COUNT
) {
335 e
->adj_count
= e
->adj_root
.count
;
337 if (flag
& LDP_ENTITY_CFG_ADJ_INDEX
) {
338 ldp_adj
*a
= MPLS_LIST_HEAD(&e
->adj_root
);
339 e
->adj_index
= a
? a
->index
: 0;
341 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
342 e
->inherit_flag
= entity
->inherit_flag
;
344 retval
= MPLS_SUCCESS
;
346 ldp_cfg_entity_get_end
:
348 mpls_lock_release(global
->global_lock
); /* UNLOCK */
350 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_get");
355 mpls_return_enum
ldp_cfg_entity_getnext(mpls_cfg_handle handle
, ldp_entity
* e
,
358 ldp_global
*g
= (ldp_global
*) handle
;
359 ldp_entity
*entity
= NULL
;
360 mpls_return_enum r
= MPLS_FAILURE
;
361 mpls_bool done
= MPLS_BOOL_FALSE
;
364 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_getnext");
369 index
= e
->index
+ 1;
372 mpls_lock_get(g
->global_lock
); /* LOCK */
373 while (done
== MPLS_BOOL_FALSE
) {
374 switch ((r
= ldp_global_find_entity_index(g
, index
, &entity
))) {
376 case MPLS_END_OF_LIST
:
377 done
= MPLS_BOOL_TRUE
;
386 mpls_lock_release(g
->global_lock
); /* UNLOCK */
388 if (r
== MPLS_SUCCESS
) {
389 e
->index
= entity
->index
;
390 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
391 return ldp_cfg_entity_get(g
, e
, flag
);
393 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
397 mpls_return_enum
ldp_cfg_entity_test(mpls_cfg_handle handle
, ldp_entity
* e
,
400 ldp_global
*global
= (ldp_global
*) handle
;
401 ldp_entity
*entity
= NULL
;
402 mpls_return_enum retval
= MPLS_FAILURE
;
404 MPLS_ASSERT(global
!=NULL
);
406 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_test");
408 mpls_lock_get(global
->global_lock
); /* LOCK */
410 if (!(flag
& LDP_CFG_ADD
)) {
412 goto ldp_cfg_entity_test_end
;
414 ldp_global_find_entity_index(global
, e
->index
, &entity
);
416 retval
= MPLS_SUCCESS
;
417 goto ldp_cfg_entity_test_end
;
420 if (entity
== NULL
) {
421 goto ldp_cfg_entity_test_end
;
424 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
425 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
426 goto ldp_cfg_entity_test_end
;
429 retval
= MPLS_SUCCESS
;
431 ldp_cfg_entity_test_end
:
432 mpls_lock_release(global
->global_lock
); /* UNLOCK */
434 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_test");
439 /* must set ldp_entity->index if not an add */
440 mpls_return_enum
ldp_cfg_entity_set(mpls_cfg_handle handle
, ldp_entity
* e
,
443 ldp_global
*global
= (ldp_global
*) handle
;
444 ldp_entity
*entity
= NULL
;
445 mpls_return_enum retval
= MPLS_FAILURE
;
447 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
449 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_set");
451 mpls_lock_get(global
->global_lock
); /* LOCK */
453 if (flag
& LDP_CFG_ADD
) {
454 entity
= ldp_entity_create();
455 _ldp_global_add_entity(global
, entity
);
457 e
->index
= entity
->index
;
459 ldp_global_find_entity_index(global
, e
->index
, &entity
);
462 if (entity
== NULL
) {
463 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: can't find entity\n");
464 goto ldp_cfg_entity_set_end
;
467 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
468 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
469 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity is active\n");
470 goto ldp_cfg_entity_set_end
;
473 if (flag
& LDP_CFG_DEL
) {
474 switch (entity
->entity_type
) {
476 ldp_entity_del_if(entity
);
479 ldp_entity_del_peer(entity
);
484 _ldp_global_del_entity(global
, entity
);
486 retval
= MPLS_SUCCESS
;
487 goto ldp_cfg_entity_set_end
;
490 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
491 if (entity
->sub_index
!= 0) {
492 /* unlink the old sub object */
493 switch (entity
->entity_type
) {
495 ldp_entity_del_if(entity
);
498 ldp_entity_del_peer(entity
);
505 /* link the new sub object */
506 switch (e
->entity_type
) {
510 if (ldp_global_find_if_index(global
, e
->sub_index
,
511 &iff
) != MPLS_SUCCESS
) {
512 LDP_PRINT(global
->user_data
,
513 "ldp_cfg_entity_set: no such interface\n");
515 if (flag
& LDP_CFG_ADD
) {
516 _ldp_global_del_entity(global
, entity
);
518 goto ldp_cfg_entity_set_end
;
520 ldp_entity_add_if(entity
, iff
);
525 ldp_peer
*peer
= NULL
;
527 if (ldp_global_find_peer_index(global
, e
->sub_index
, &peer
) !=
529 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: no such peer\n");
531 if (flag
& LDP_CFG_ADD
) {
532 _ldp_global_del_entity(global
, entity
);
534 goto ldp_cfg_entity_set_end
;
536 ldp_entity_add_peer(entity
, peer
);
544 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
545 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
546 entity
->inherit_flag
|= LDP_ENTITY_CFG_TRANS_ADDR
;
548 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_TRANS_ADDR
;
550 memcpy(&entity
->transport_address
, &e
->transport_address
,
551 sizeof(mpls_inet_addr
));;
553 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
554 entity
->protocol_version
= e
->protocol_version
;
556 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
557 entity
->remote_tcp_port
= e
->remote_tcp_port
;
559 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
560 entity
->remote_udp_port
= e
->remote_udp_port
;
562 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
563 entity
->max_pdu
= e
->max_pdu
;
565 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
566 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
567 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
569 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
571 entity
->keepalive_timer
= e
->keepalive_timer
;
573 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
574 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
575 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
577 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
579 entity
->keepalive_interval
= e
->keepalive_interval
;
581 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
582 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
583 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_TIMER
;
585 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_TIMER
;
587 entity
->hellotime_timer
= e
->hellotime_timer
;
589 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
590 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
591 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
593 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
595 entity
->hellotime_interval
= e
->hellotime_interval
;
597 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
598 entity
->session_setup_count
= e
->session_setup_count
;
600 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
601 entity
->session_backoff_timer
= e
->session_backoff_timer
;
603 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
604 entity
->label_distribution_mode
= e
->label_distribution_mode
;
606 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
607 entity
->path_vector_limit
= e
->path_vector_limit
;
609 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
610 entity
->hop_count_limit
= e
->hop_count_limit
;
612 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
613 entity
->label_request_count
= e
->label_request_count
;
615 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
616 entity
->label_request_timer
= e
->label_request_timer
;
618 if (flag
& LDP_ENTITY_CFG_TYPE
) {
619 entity
->entity_type
= e
->entity_type
;
621 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
622 if (ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
&&
623 e
->admin_state
== MPLS_ADMIN_DISABLE
) {
624 if (ldp_entity_shutdown(global
, entity
, 0) == MPLS_FAILURE
) {
625 goto ldp_cfg_entity_set_end
;
627 } else if (ldp_entity_is_active(entity
) == MPLS_BOOL_FALSE
&&
628 e
->admin_state
== MPLS_ADMIN_ENABLE
&& ldp_entity_is_ready(entity
) == MPLS_BOOL_TRUE
) {
629 if (ldp_entity_startup(global
, entity
) == MPLS_FAILURE
) {
630 goto ldp_cfg_entity_set_end
;
633 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity not ready\n");
635 goto ldp_cfg_entity_set_end
;
638 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
639 entity
->inherit_flag
= e
->inherit_flag
;
641 global
->configuration_sequence_number
++;
643 retval
= MPLS_SUCCESS
;
645 ldp_cfg_entity_set_end
:
646 mpls_lock_release(global
->global_lock
); /* UNLOCK */
648 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_set");
653 mpls_return_enum
ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle
,
656 ldp_global
*g
= (ldp_global
*) handle
;
657 mpls_bool this_one
= MPLS_BOOL_FALSE
;
658 mpls_return_enum r
= MPLS_FAILURE
;
659 ldp_adj
*adj_next
= NULL
;
661 ldp_entity
*entity
= NULL
;
663 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_adj_getnext");
665 /* if an adj_index of zero is sent, get the index of
666 * the first adj in the list
669 this_one
= MPLS_BOOL_TRUE
;
672 mpls_lock_get(g
->global_lock
); /* LOCK */
674 if (ldp_global_find_entity_index(g
, e
->index
, &entity
) == MPLS_SUCCESS
) {
675 adj
= MPLS_LIST_HEAD(&entity
->adj_root
);
677 if (this_one
== MPLS_BOOL_TRUE
) {
682 /* since the entities are sort in the list ... */
683 if (adj
->index
> e
->adj_index
) {
685 } else if (adj
->index
== e
->adj_index
) {
686 this_one
= MPLS_BOOL_TRUE
;
688 adj
= MPLS_LIST_NEXT(&entity
->adj_root
, adj
, _entity
);
691 mpls_lock_release(g
->global_lock
); /* UNLOCK */
694 e
->adj_index
= adj_next
->index
;
698 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_adj_getnext");
702 /******************* INTERFACE **********************/
704 mpls_return_enum
ldp_cfg_if_get(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
706 ldp_global
*global
= (ldp_global
*) handle
;
708 mpls_return_enum retval
= MPLS_FAILURE
;
710 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
712 LDP_ENTER(global
->user_data
, "ldp_cfg_if_get");
714 mpls_lock_get(global
->global_lock
); /* LOCK */
716 if (ldp_global_find_if_index(global
, i
->index
, &iff
) != MPLS_SUCCESS
)
717 goto ldp_cfg_if_get_end
;
719 if (flag
& LDP_IF_CFG_NAME
) {
720 strncpy(i
->name
, iff
->name
, MPLS_MAX_IF_NAME
);
722 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
723 i
->label_space
= iff
->label_space
;
725 if (flag
& LDP_IF_CFG_ENTITY_INDEX
) {
726 i
->entity_index
= iff
->entity
? iff
->entity
->index
: 0;
728 if (flag
& LDP_IF_CFG_OPER_STATE
) {
729 i
->oper_state
= iff
->oper_state
;
731 if (flag
& LDP_IF_CFG_LOCAL_SOURCE_ADDR
) {
732 memcpy(&i
->local_source_address
, &iff
->local_source_address
,
733 sizeof(mpls_inet_addr
));
735 retval
= MPLS_SUCCESS
;
738 mpls_lock_release(global
->global_lock
); /* UNLOCK */
740 LDP_EXIT(global
->user_data
, "ldp_cfg_if_get");
745 mpls_return_enum
ldp_cfg_if_getnext(mpls_cfg_handle handle
, ldp_if
* i
,
748 ldp_global
*g
= (ldp_global
*) handle
;
750 mpls_return_enum r
= MPLS_FAILURE
;
751 mpls_bool done
= MPLS_BOOL_FALSE
;
754 LDP_ENTER(g
->user_data
, "ldp_cfg_if_getnext");
759 index
= i
->index
+ 1;
762 mpls_lock_get(g
->global_lock
); /* LOCK */
763 while (done
== MPLS_BOOL_FALSE
) {
764 switch ((r
= ldp_global_find_if_index(g
, index
, &iff
))) {
766 case MPLS_END_OF_LIST
:
767 done
= MPLS_BOOL_TRUE
;
776 mpls_lock_release(g
->global_lock
); /* UNLOCK */
778 if (r
== MPLS_SUCCESS
) {
779 i
->index
= iff
->index
;
780 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
781 return ldp_cfg_if_get(g
, i
, flag
);
783 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
787 mpls_return_enum
ldp_cfg_if_test(mpls_cfg_handle handle
, ldp_if
* i
,
790 ldp_global
*global
= (ldp_global
*) handle
;
792 mpls_return_enum retval
= MPLS_FAILURE
;
794 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
796 LDP_ENTER(global
->user_data
, "ldp_cfg_if_test");
798 mpls_lock_get(global
->global_lock
); /* LOCK */
800 if (!(flag
& LDP_CFG_ADD
)) {
801 ldp_global_find_if_index(global
, i
->index
, &iff
);
803 retval
= MPLS_SUCCESS
;
804 goto ldp_cfg_if_test_end
;
808 ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
809 (flag
& LDP_IF_CFG_WHEN_DOWN
))) goto ldp_cfg_if_test_end
;
811 if (flag
& LDP_CFG_DEL
) {
812 if (iff
->entity
!= NULL
)
813 goto ldp_cfg_if_test_end
;
815 retval
= MPLS_SUCCESS
;
818 mpls_lock_release(global
->global_lock
); /* UNLOCK */
820 LDP_EXIT(global
->user_data
, "ldp_cfg_if_test");
825 mpls_return_enum
ldp_cfg_if_set(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
827 ldp_global
*global
= (ldp_global
*)handle
;
829 mpls_return_enum retval
= MPLS_FAILURE
;
831 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
833 LDP_ENTER(global
->user_data
, "ldp_cfg_if_set");
835 mpls_lock_get(global
->global_lock
); /* LOCK */
837 if (flag
& LDP_CFG_ADD
) {
838 if ((iff
= ldp_global_find_if_handle(global
, i
->handle
)) == NULL
) {
839 if ((iff
= ldp_if_create()) == NULL
) {
840 goto ldp_cfg_if_set_end
;
842 if (mpls_if_handle_verify(global
->ifmgr_handle
, i
->handle
) ==
844 i
->handle
= mpls_ifmgr_open_if(global
->ifmgr_handle
, i
->name
);
846 iff
->handle
= i
->handle
;
848 i
->index
= iff
->index
;
849 strncpy(iff
->name
, i
->name
, MPLS_MAX_IF_NAME
);
850 iff
->used_by_ldp
= MPLS_BOOL_TRUE
;
851 _ldp_global_add_if(global
, iff
);
853 ldp_global_find_if_index(global
, i
->index
, &iff
);
857 ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
858 (flag
& LDP_IF_CFG_WHEN_DOWN
))) goto ldp_cfg_if_set_end
;
860 if (flag
& LDP_CFG_DEL
) {
861 if (iff
->entity
!= NULL
) {
862 goto ldp_cfg_if_set_end
;
865 iff
->used_by_ldp
= MPLS_BOOL_FALSE
;
866 _ldp_global_del_if(global
, iff
);
868 retval
= MPLS_SUCCESS
;
869 goto ldp_cfg_if_set_end
;
871 if (flag
& LDP_IF_CFG_INDEX
) {
872 iff
->index
= i
->index
;
874 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
875 iff
->label_space
= i
->label_space
;
877 global
->configuration_sequence_number
++;
879 retval
= MPLS_SUCCESS
;
882 mpls_lock_release(global
->global_lock
); /* UNLOCK */
884 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
889 /******************* ATTR **********************/
891 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
894 ldp_global
*global
= (ldp_global
*) handle
;
895 ldp_attr
*attr
= NULL
;
896 mpls_return_enum retval
= MPLS_FAILURE
;
898 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
900 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
902 mpls_lock_get(global
->global_lock
); /* LOCK */
904 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
905 goto ldp_cfg_attr_get_end
;
907 if (flag
& LDP_ATTR_CFG_STATE
) {
908 a
->state
= attr
->state
;
910 if (flag
& LDP_ATTR_CFG_FEC
) {
911 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
913 if (flag
& LDP_ATTR_CFG_LABEL
) {
914 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
916 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
917 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
919 if (flag
& LDP_ATTR_CFG_PATH
) {
920 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
922 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
923 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
925 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
926 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
928 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
929 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
931 if (flag
& LDP_ATTR_CFG_INGRESS
) {
932 a
->ingress
= attr
->ingress
;
934 retval
= MPLS_SUCCESS
;
936 ldp_cfg_attr_get_end
:
937 mpls_lock_release(global
->global_lock
); /* UNLOCK */
939 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
944 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
947 ldp_global
*g
= (ldp_global
*) handle
;
948 ldp_attr
*attr
= NULL
;
949 mpls_return_enum r
= MPLS_FAILURE
;
950 mpls_bool done
= MPLS_BOOL_FALSE
;
953 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
958 index
= a
->index
+ 1;
961 mpls_lock_get(g
->global_lock
); /* LOCK */
962 while (done
== MPLS_BOOL_FALSE
) {
963 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
965 case MPLS_END_OF_LIST
:
966 done
= MPLS_BOOL_TRUE
;
975 mpls_lock_release(g
->global_lock
); /* UNLOCK */
977 if (r
== MPLS_SUCCESS
) {
978 a
->index
= attr
->index
;
979 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
980 return ldp_cfg_attr_get(g
, a
, flag
);
982 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
986 /******************* PEER **********************/
988 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
991 ldp_global
*global
= (ldp_global
*) handle
;
992 ldp_peer
*peer
= NULL
;
993 mpls_return_enum retval
= MPLS_FAILURE
;
995 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
997 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
999 mpls_lock_get(global
->global_lock
); /* LOCK */
1001 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
1002 goto ldp_cfg_peer_get_end
;
1004 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1005 p
->label_space
= peer
->label_space
;
1007 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1008 p
->target_role
= peer
->target_role
;
1010 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1011 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1013 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1014 p
->entity_index
= peer
->entity
->index
;
1016 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1017 p
->oper_state
= peer
->oper_state
;
1019 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1020 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1022 if (flag
& LDP_PEER_CFG_LOCAL_SOURCE_ADDR
) {
1023 memcpy(&p
->local_source_address
, &peer
->local_source_address
,
1024 sizeof(mpls_inet_addr
));
1026 retval
= MPLS_SUCCESS
;
1028 ldp_cfg_peer_get_end
:
1029 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1031 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1036 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1039 ldp_global
*g
= (ldp_global
*) handle
;
1040 ldp_peer
*peer
= NULL
;
1041 mpls_return_enum r
= MPLS_FAILURE
;
1042 mpls_bool done
= MPLS_BOOL_FALSE
;
1045 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1047 if (p
->index
== 0) {
1050 index
= p
->index
+ 1;
1053 mpls_lock_get(g
->global_lock
); /* LOCK */
1054 while (done
== MPLS_BOOL_FALSE
) {
1055 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1057 case MPLS_END_OF_LIST
:
1058 done
= MPLS_BOOL_TRUE
;
1067 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1069 if (r
== MPLS_SUCCESS
) {
1070 p
->index
= peer
->index
;
1071 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1072 return ldp_cfg_peer_get(g
, p
, flag
);
1074 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1078 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1081 // ldp_global* g = (ldp_global*)handle;
1082 return MPLS_SUCCESS
;
1085 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1088 ldp_global
*global
= (ldp_global
*) handle
;
1089 ldp_peer
*peer
= NULL
;
1090 mpls_return_enum retval
= MPLS_FAILURE
;
1092 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1094 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1096 mpls_lock_get(global
->global_lock
); /* LOCK */
1098 if (flag
& LDP_CFG_ADD
) {
1099 if ((peer
= ldp_peer_create()) == NULL
) {
1100 goto ldp_cfg_peer_set_end
;
1102 p
->index
= peer
->index
;
1103 _ldp_global_add_peer(global
, peer
);
1105 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1109 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1111 goto ldp_cfg_peer_set_end
;
1113 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1114 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1116 goto ldp_cfg_peer_set_end
;
1119 if (flag
& LDP_CFG_DEL
) {
1120 if (peer
->entity
!= NULL
) {
1121 LDP_PRINT(global
->user_data
,
1122 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1124 goto ldp_cfg_peer_set_end
;
1127 _ldp_global_del_peer(global
, peer
);
1129 retval
= MPLS_SUCCESS
;
1130 goto ldp_cfg_peer_set_end
;
1132 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1133 peer
->label_space
= p
->label_space
;
1135 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1136 peer
->target_role
= p
->target_role
;
1138 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1139 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1141 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1142 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1145 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1147 global
->configuration_sequence_number
++;
1149 retval
= MPLS_SUCCESS
;
1151 ldp_cfg_peer_set_end
:
1152 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1154 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1158 /******************* FEC **********************/
1160 mpls_return_enum
ldp_cfg_fec_get2(mpls_cfg_handle handle
, ldp_fec
* f
,
1163 ldp_global
*global
= (ldp_global
*) handle
;
1164 ldp_fec
*fec
= NULL
;
1165 mpls_return_enum retval
= MPLS_FAILURE
;
1167 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1169 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get2");
1171 mpls_lock_get(global
->global_lock
); /* LOCK */
1173 if ((fec
= ldp_fec_find(global
, &f
->info
)) == NULL
)
1174 goto ldp_cfg_fec_get2_end
;
1176 f
->index
= fec
->index
;
1177 memcpy(&f
->info
, &fec
->info
, sizeof(mpls_fec
));
1178 retval
= MPLS_SUCCESS
;
1180 ldp_cfg_fec_get2_end
:
1181 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1183 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get2");
1188 mpls_return_enum
ldp_cfg_fec_get(mpls_cfg_handle handle
, ldp_fec
* f
,
1191 ldp_global
*global
= (ldp_global
*) handle
;
1192 ldp_fec
*fec
= NULL
;
1193 mpls_return_enum retval
= MPLS_FAILURE
;
1195 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1197 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get");
1199 mpls_lock_get(global
->global_lock
); /* LOCK */
1201 if (ldp_global_find_fec_index(global
, f
->index
, &fec
) != MPLS_SUCCESS
)
1202 goto ldp_cfg_fec_get_end
;
1204 memcpy(&f
->info
, &fec
->info
, sizeof(mpls_fec
));
1205 retval
= MPLS_SUCCESS
;
1207 ldp_cfg_fec_get_end
:
1208 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1210 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get");
1215 mpls_return_enum
ldp_cfg_fec_getnext(mpls_cfg_handle handle
, ldp_fec
* f
,
1218 ldp_global
*g
= (ldp_global
*) handle
;
1219 ldp_fec
*fec
= NULL
;
1220 mpls_return_enum r
= MPLS_FAILURE
;
1221 mpls_bool done
= MPLS_BOOL_FALSE
;
1224 LDP_ENTER(g
->user_data
, "ldp_cfg_fec_getnext");
1226 if (f
->index
== 0) {
1229 index
= f
->index
+ 1;
1232 mpls_lock_get(g
->global_lock
); /* LOCK */
1233 while (done
== MPLS_BOOL_FALSE
) {
1234 switch ((r
= ldp_global_find_fec_index(g
, index
, &fec
))) {
1236 case MPLS_END_OF_LIST
:
1237 done
= MPLS_BOOL_TRUE
;
1246 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1248 if (r
== MPLS_SUCCESS
) {
1249 f
->index
= fec
->index
;
1250 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1251 return ldp_cfg_fec_get(g
, f
, flag
);
1253 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1257 mpls_return_enum
ldp_cfg_fec_test(mpls_cfg_handle handle
, ldp_fec
* f
,
1260 // ldp_global* g = (ldp_global*)handle;
1261 return MPLS_SUCCESS
;
1264 mpls_return_enum
ldp_cfg_fec_set(mpls_cfg_handle handle
, ldp_fec
* f
,
1267 ldp_global
*global
= (ldp_global
*) handle
;
1268 ldp_fec
*fec
= NULL
;
1269 mpls_return_enum retval
= MPLS_FAILURE
;
1271 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1273 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_set");
1275 mpls_lock_get(global
->global_lock
); /* LOCK */
1277 if (flag
& LDP_CFG_ADD
) {
1278 if ((fec
= ldp_fec_create()) == NULL
) {
1279 goto ldp_cfg_fec_set_end
;
1281 f
->index
= fec
->index
;
1282 mpls_fec2ldp_fec(&f
->info
, fec
);
1283 _ldp_global_add_fec(global
, fec
);
1284 ldp_fec_insert2(global
, fec
);
1285 ldp_fec_process_add(global
, fec
);
1287 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1291 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_set: no such fec\n");
1292 goto ldp_cfg_fec_set_end
;
1295 if (flag
& LDP_CFG_DEL
) {
1296 ldp_session
*old_session
= ldp_get_next_hop_session_for_fec2(fec
);
1297 ldp_fec_remove(global
,&fec
->info
);
1298 _ldp_global_del_fec(global
, fec
);
1299 ldp_fec_process_change(global
, fec
, old_session
);
1300 retval
= MPLS_SUCCESS
;
1301 goto ldp_cfg_fec_set_end
;
1303 global
->configuration_sequence_number
++;
1305 retval
= MPLS_SUCCESS
;
1307 ldp_cfg_fec_set_end
:
1308 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1310 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1315 /******************* ADJACENCY **********************/
1317 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1320 ldp_global
*global
= (ldp_global
*) handle
;
1321 ldp_adj
*adj
= NULL
;
1322 mpls_return_enum retval
= MPLS_FAILURE
;
1324 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1326 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1328 mpls_lock_get(global
->global_lock
); /* LOCK */
1330 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1331 goto ldp_cfg_adj_get_end
;
1333 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1334 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1335 sizeof(mpls_inet_addr
));
1337 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1338 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1339 sizeof(mpls_inet_addr
));
1341 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1342 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1343 sizeof(mpls_inet_addr
));
1345 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1346 a
->remote_csn
= adj
->remote_csn
;
1348 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1349 a
->remote_label_space
= adj
->remote_label_space
;
1351 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1352 a
->remote_hellotime
= adj
->remote_hellotime
;
1354 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1355 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1357 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1358 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1360 if (flag
& LDP_ADJ_CFG_ROLE
) {
1361 a
->role
= adj
->role
;
1363 retval
= MPLS_SUCCESS
;
1365 ldp_cfg_adj_get_end
:
1367 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1369 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1374 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1377 ldp_global
*g
= (ldp_global
*) handle
;
1378 ldp_adj
*adj
= NULL
;
1379 mpls_return_enum r
= MPLS_FAILURE
;
1380 mpls_bool done
= MPLS_BOOL_FALSE
;
1383 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1385 if (a
->index
== 0) {
1388 index
= a
->index
+ 1;
1391 mpls_lock_get(g
->global_lock
); /* LOCK */
1392 while (done
== MPLS_BOOL_FALSE
) {
1393 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1395 case MPLS_END_OF_LIST
:
1396 done
= MPLS_BOOL_TRUE
;
1405 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1407 if (r
== MPLS_SUCCESS
) {
1408 a
->index
= adj
->index
;
1409 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1410 return ldp_cfg_adj_get(g
, a
, flag
);
1412 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1416 /******************* SESSION **********************/
1418 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1421 ldp_global
*global
= (ldp_global
*) handle
;
1422 ldp_session
*session
= NULL
;
1423 mpls_return_enum retval
= MPLS_FAILURE
;
1425 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1427 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1429 mpls_lock_get(global
->global_lock
); /* LOCK */
1431 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1432 goto ldp_cfg_session_get_end
;
1434 if (flag
& LDP_SESSION_CFG_STATE
) {
1435 s
->state
= session
->state
;
1437 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1438 s
->oper_up
= session
->oper_up
;
1440 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1441 s
->oper_max_pdu
= session
->oper_max_pdu
;
1443 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1444 s
->oper_keepalive
= session
->oper_keepalive
;
1446 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1447 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1449 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1450 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1452 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1453 s
->oper_loop_detection
= session
->oper_loop_detection
;
1455 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1456 s
->remote_max_pdu
= session
->remote_max_pdu
;
1458 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1459 s
->remote_keepalive
= session
->remote_keepalive
;
1461 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1462 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1464 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1465 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1467 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1468 s
->remote_loop_detection
= session
->remote_loop_detection
;
1470 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1471 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1472 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1474 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1475 s
->remote_dest
.port
= session
->remote_dest
.port
;
1477 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1478 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1480 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1481 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1483 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1484 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1485 s
->adj_index
= a
? a
->index
: 0;
1487 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1488 s
->mesg_tx
= session
->mesg_tx
;
1490 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1491 s
->mesg_rx
= session
->mesg_rx
;
1493 retval
= MPLS_SUCCESS
;
1495 ldp_cfg_session_get_end
:
1496 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1498 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1503 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1506 ldp_global
*g
= (ldp_global
*) handle
;
1507 ldp_session
*ses
= NULL
;
1508 mpls_return_enum r
= MPLS_FAILURE
;
1509 mpls_bool done
= MPLS_BOOL_FALSE
;
1512 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
1514 if (s
->index
== 0) {
1517 index
= s
->index
+ 1;
1520 mpls_lock_get(g
->global_lock
); /* LOCK */
1521 while (done
== MPLS_BOOL_FALSE
) {
1522 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
1524 case MPLS_END_OF_LIST
:
1525 done
= MPLS_BOOL_TRUE
;
1534 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1536 if (r
== MPLS_SUCCESS
) {
1537 s
->index
= ses
->index
;
1539 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1540 return ldp_cfg_session_get(g
, s
, flag
);
1543 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1548 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
1551 ldp_global
*g
= (ldp_global
*) handle
;
1552 mpls_bool this_one
= MPLS_BOOL_FALSE
;
1553 mpls_return_enum r
= MPLS_FAILURE
;
1554 ldp_adj
*adj_next
= NULL
;
1555 ldp_adj
*adj
= NULL
;
1556 ldp_session
*session
= NULL
;
1558 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
1560 /* if an adj_index of zero is sent, get the index of
1561 * the first adj in the list
1563 if (!s
->adj_index
) {
1564 this_one
= MPLS_BOOL_TRUE
;
1567 mpls_lock_get(g
->global_lock
); /* LOCK */
1569 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
1570 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
1572 if (this_one
== MPLS_BOOL_TRUE
) {
1577 /* since the entities are sort in the list ... */
1578 if (adj
->index
> s
->adj_index
) {
1580 } else if (adj
->index
== s
->adj_index
) {
1581 this_one
= MPLS_BOOL_TRUE
;
1583 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
1586 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1589 s
->adj_index
= adj_next
->index
;
1593 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
1597 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
1598 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
1600 ldp_global
*global
= (ldp_global
*) handle
;
1601 ldp_session
*session
= NULL
;
1602 ldp_addr
*addr
= NULL
;
1603 mpls_return_enum retval
= MPLS_FAILURE
;
1605 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
1607 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
1609 mpls_lock_get(global
->global_lock
); /* LOCK */
1611 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1612 goto ldp_cfg_session_raddr_get_end
;
1614 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
1615 goto ldp_cfg_session_raddr_get_end
;
1617 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
1618 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
1620 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
1621 a
->index
= addr
->index
;
1623 retval
= MPLS_SUCCESS
;
1625 ldp_cfg_session_raddr_get_end
:
1626 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1628 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
1633 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
1634 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
1636 ldp_global
*g
= (ldp_global
*) handle
;
1637 ldp_addr
*addr
= NULL
;
1638 mpls_return_enum r
= MPLS_FAILURE
;
1639 mpls_bool done
= MPLS_BOOL_FALSE
;
1640 ldp_session
*sp
= NULL
;
1643 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
1645 if (a
->index
== 0) {
1648 index
= a
->index
+ 1;
1651 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
1652 if (r
!= MPLS_SUCCESS
) {
1656 mpls_lock_get(g
->global_lock
); /* LOCK */
1657 while (done
== MPLS_BOOL_FALSE
) {
1658 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
1660 case MPLS_END_OF_LIST
:
1661 done
= MPLS_BOOL_TRUE
;
1670 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1672 if (r
== MPLS_SUCCESS
) {
1673 a
->index
= addr
->index
;
1674 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
1677 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
1681 /******************* IN LABEL **********************/
1683 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
1686 ldp_global
*global
= (ldp_global
*) handle
;
1687 ldp_inlabel
*inlabel
= NULL
;
1688 mpls_return_enum retval
= MPLS_FAILURE
;
1690 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
1692 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
1694 mpls_lock_get(global
->global_lock
); /* LOCK */
1696 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
1697 goto ldp_cfg_inlabel_get_end
;
1699 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
1700 i
->info
.labelspace
= inlabel
->info
.labelspace
;
1702 if (flag
& LDP_INLABEL_CFG_LABEL
) {
1703 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
1705 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
1706 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
1709 retval
= MPLS_SUCCESS
;
1711 ldp_cfg_inlabel_get_end
:
1712 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1714 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
1719 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
1722 ldp_global
*g
= (ldp_global
*) handle
;
1723 ldp_inlabel
*inlabel
= NULL
;
1724 mpls_return_enum r
= MPLS_FAILURE
;
1725 mpls_bool done
= MPLS_BOOL_FALSE
;
1728 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
1730 if (i
->index
== 0) {
1733 index
= i
->index
+ 1;
1736 mpls_lock_get(g
->global_lock
); /* LOCK */
1737 while (done
== MPLS_BOOL_FALSE
) {
1738 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
1740 case MPLS_END_OF_LIST
:
1741 done
= MPLS_BOOL_TRUE
;
1750 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1752 if (r
== MPLS_SUCCESS
) {
1753 i
->index
= inlabel
->index
;
1755 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
1756 return ldp_cfg_inlabel_get(g
, i
, flag
);
1759 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
1764 /******************* OUT LABEL **********************/
1766 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
1769 ldp_global
*global
= (ldp_global
*) handle
;
1770 ldp_outlabel
*outlabel
= NULL
;
1771 mpls_return_enum retval
= MPLS_FAILURE
;
1773 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
1775 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
1777 mpls_lock_get(global
->global_lock
); /* LOCK */
1779 if (ldp_global_find_outlabel_index(global
, o
->index
,
1780 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
1782 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
1783 if (outlabel
->nh
.type
& MPLS_NH_IP
) {
1784 o
->addr_index
= (outlabel
->nh
.addr
) ? (outlabel
->nh
.addr
->index
) : 0;
1785 o
->nh_type
|= MPLS_NH_IP
;
1787 if (outlabel
->nh
.type
& MPLS_NH_IF
) {
1788 o
->if_index
= (outlabel
->nh
.iff
) ? (outlabel
->nh
.iff
->index
) : 0;
1789 o
->nh_type
|= MPLS_NH_IF
;
1791 if (outlabel
->nh
.type
& MPLS_NH_OUTSEGMENT
) {
1792 o
->outlabel_index
= (outlabel
->nh
.outlabel
) ?
1793 (outlabel
->nh
.outlabel
->index
) : 0;
1794 o
->nh_type
|= MPLS_NH_OUTSEGMENT
;
1797 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
1798 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
1800 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
1801 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
1803 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
1804 o
->merge_count
= outlabel
->merge_count
;
1807 retval
= MPLS_SUCCESS
;
1809 ldp_cfg_outlabel_get_end
:
1810 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1812 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
1817 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
1818 ldp_outlabel
* o
, uint32_t flag
)
1820 ldp_global
*g
= (ldp_global
*) handle
;
1821 ldp_outlabel
*outlabel
= NULL
;
1822 mpls_return_enum r
= MPLS_FAILURE
;
1823 mpls_bool done
= MPLS_BOOL_FALSE
;
1826 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
1828 if (o
->index
== 0) {
1831 index
= o
->index
+ 1;
1834 mpls_lock_get(g
->global_lock
); /* LOCK */
1835 while (done
== MPLS_BOOL_FALSE
) {
1836 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
1838 case MPLS_END_OF_LIST
:
1839 done
= MPLS_BOOL_TRUE
;
1848 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1850 if (r
== MPLS_SUCCESS
) {
1851 o
->index
= outlabel
->index
;
1853 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
1854 return ldp_cfg_outlabel_get(g
, o
, flag
);
1857 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
1862 /******************* TUNNEL **********************/
1864 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
1867 ldp_global
*global
= (ldp_global
*) handle
;
1868 mpls_return_enum retval
= MPLS_FAILURE
;
1869 ldp_tunnel
*tunnel
= NULL
;
1871 MPLS_ASSERT(global
!=NULL
);
1873 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
1875 mpls_lock_get(global
->global_lock
); /* LOCK */
1877 if (flag
& LDP_CFG_ADD
) {
1878 if (!(tunnel
= ldp_tunnel_create())) {
1879 goto ldp_cfg_tunnel_set_end
;
1881 _ldp_global_add_tunnel(global
, tunnel
);
1883 t
->index
= tunnel
->index
;
1885 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
1889 LDP_PRINT(global
->user_data
,
1891 "ldp_cfg_tunnel_set:could not create tunnel\n");
1892 goto ldp_cfg_tunnel_set_end
;
1895 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
1896 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
1897 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
1899 goto ldp_cfg_tunnel_set_end
;
1902 if (flag
& LDP_CFG_DEL
) {
1903 if (tunnel
->outlabel
)
1904 ldp_tunnel_del_outlabel(tunnel
);
1905 if (tunnel
->resource
)
1906 ldp_tunnel_del_resource(tunnel
);
1907 if (tunnel
->hop_list
)
1908 ldp_tunnel_del_hop_list(tunnel
);
1909 _ldp_global_del_tunnel(global
, tunnel
);
1911 retval
= MPLS_SUCCESS
;
1912 goto ldp_cfg_tunnel_set_end
;
1915 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
1916 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
1918 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
1919 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
1921 if (flag
& LDP_TUNNEL_CFG_NAME
) {
1922 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
1924 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
1925 tunnel
->is_interface
= t
->is_interface
;
1927 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
1928 ldp_outlabel
*outlabel
= NULL
;
1930 if (t
->outlabel_index
) {
1931 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
1934 goto ldp_cfg_tunnel_set_end
;
1936 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
1938 ldp_tunnel_del_outlabel(tunnel
);
1941 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
1942 tunnel
->setup_prio
= t
->setup_prio
;
1944 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
1945 tunnel
->hold_prio
= t
->hold_prio
;
1947 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
1948 tunnel
->instance_prio
= t
->instance_prio
;
1950 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
1951 tunnel
->local_protect
= t
->local_protect
;
1953 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
1954 ldp_resource
*resource
= NULL
;
1956 if (t
->resource_index
) {
1957 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
1960 goto ldp_cfg_tunnel_set_end
;
1962 ldp_tunnel_add_resource(tunnel
, resource
);
1964 ldp_tunnel_del_resource(tunnel
);
1967 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
1968 ldp_hop_list
*hop_list
= NULL
;
1970 if (t
->hop_list_index
) {
1971 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
1974 goto ldp_cfg_tunnel_set_end
;
1976 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
1978 ldp_tunnel_del_hop_list(tunnel
);
1981 if (flag
& LDP_TUNNEL_CFG_FEC
) {
1982 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
1984 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
1985 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
1986 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
1987 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
1988 goto ldp_cfg_tunnel_set_end
;
1992 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
1993 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
1994 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
1995 goto ldp_cfg_tunnel_set_end
;
1998 LDP_PRINT(global
->user_data
,
2000 "ldp_cfg_tunnel_set: tunnel not ready\n");
2001 goto ldp_cfg_tunnel_set_end
;
2006 retval
= MPLS_SUCCESS
;
2008 ldp_cfg_tunnel_set_end
:
2010 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2012 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2017 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2020 ldp_global
*global
= (ldp_global
*) handle
;
2021 mpls_return_enum retval
= MPLS_FAILURE
;
2022 ldp_tunnel
*tunnel
= NULL
;
2024 MPLS_ASSERT(global
!=NULL
);
2026 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2028 mpls_lock_get(global
->global_lock
); /* LOCK */
2030 if (flag
& LDP_CFG_ADD
) {
2031 retval
= MPLS_SUCCESS
;
2032 goto ldp_cfg_tunnel_test_end
;
2035 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2038 goto ldp_cfg_tunnel_test_end
;
2041 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2042 ldp_resource
*resource
= NULL
;
2044 if (t
->resource_index
) {
2045 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2048 goto ldp_cfg_tunnel_test_end
;
2052 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2053 ldp_hop_list
*hop_list
= NULL
;
2055 if (t
->hop_list_index
) {
2056 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2059 goto ldp_cfg_tunnel_test_end
;
2063 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2064 ldp_outlabel
*outlabel
= NULL
;
2066 if (t
->outlabel_index
) {
2067 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2070 goto ldp_cfg_tunnel_test_end
;
2074 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2075 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2076 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2077 goto ldp_cfg_tunnel_test_end
;
2079 retval
= MPLS_SUCCESS
;
2081 ldp_cfg_tunnel_test_end
:
2083 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2085 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2090 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2093 ldp_global
*global
= (ldp_global
*) handle
;
2094 mpls_return_enum retval
= MPLS_FAILURE
;
2095 ldp_tunnel
*tunnel
= NULL
;
2097 MPLS_ASSERT(global
!=NULL
);
2099 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2101 mpls_lock_get(global
->global_lock
); /* LOCK */
2103 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2106 goto ldp_cfg_tunnel_get_end
;
2108 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2109 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2111 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2112 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2114 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2115 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2117 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2118 t
->is_interface
= tunnel
->is_interface
;
2120 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2121 if (tunnel
->outlabel
) {
2122 t
->outlabel_index
= tunnel
->outlabel
->index
;
2124 t
->outlabel_index
= 0;
2127 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2128 t
->setup_prio
= tunnel
->setup_prio
;
2130 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2131 t
->hold_prio
= tunnel
->hold_prio
;
2133 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2134 tunnel
->instance_prio
= t
->instance_prio
;
2136 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2137 tunnel
->local_protect
= t
->local_protect
;
2139 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2140 if (tunnel
->resource
) {
2141 t
->resource_index
= tunnel
->resource
->index
;
2143 t
->resource_index
= 0;
2146 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2147 if (tunnel
->hop_list
) {
2148 t
->hop_list_index
= tunnel
->hop_list
->index
;
2150 t
->hop_list_index
= 0;
2153 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2154 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2156 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2157 t
->admin_state
= tunnel
->admin_state
;
2159 retval
= MPLS_SUCCESS
;
2161 ldp_cfg_tunnel_get_end
:
2163 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2165 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2170 /******************* RESOURCE **********************/
2172 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2175 ldp_global
*global
= (ldp_global
*) handle
;
2176 mpls_return_enum retval
= MPLS_FAILURE
;
2177 ldp_resource
*resource
= NULL
;
2179 MPLS_ASSERT(global
!=NULL
);
2181 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2183 mpls_lock_get(global
->global_lock
); /* LOCK */
2185 if (flag
& LDP_CFG_ADD
) {
2186 resource
= ldp_resource_create();
2187 _ldp_global_add_resource(global
, resource
);
2189 r
->index
= resource
->index
;
2191 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2195 goto ldp_cfg_resource_set_end
;
2198 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2199 resource
->max_rate
= r
->max_rate
;
2201 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2202 resource
->mean_rate
= r
->mean_rate
;
2204 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2205 resource
->burst_size
= r
->burst_size
;
2207 retval
= MPLS_SUCCESS
;
2209 ldp_cfg_resource_set_end
:
2211 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2213 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2218 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2221 ldp_global
*global
= (ldp_global
*) handle
;
2222 mpls_return_enum retval
= MPLS_FAILURE
;
2223 ldp_resource
*resource
= NULL
;
2225 MPLS_ASSERT(global
!=NULL
);
2227 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2229 mpls_lock_get(global
->global_lock
); /* LOCK */
2231 if (flag
& LDP_CFG_ADD
) {
2232 retval
= MPLS_SUCCESS
;
2233 goto ldp_cfg_resource_test_end
;
2236 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2239 goto ldp_cfg_resource_test_end
;
2242 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2243 goto ldp_cfg_resource_test_end
;
2245 retval
= MPLS_SUCCESS
;
2247 ldp_cfg_resource_test_end
:
2249 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2251 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2256 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2259 ldp_global
*global
= (ldp_global
*) handle
;
2260 mpls_return_enum retval
= MPLS_FAILURE
;
2261 ldp_resource
*resource
= NULL
;
2263 MPLS_ASSERT(global
!=NULL
);
2265 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2267 mpls_lock_get(global
->global_lock
); /* LOCK */
2269 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2272 goto ldp_cfg_resource_get_end
;
2275 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2276 r
->max_rate
= resource
->max_rate
;
2278 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2279 r
->mean_rate
= resource
->mean_rate
;
2281 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2282 r
->burst_size
= resource
->burst_size
;
2284 retval
= MPLS_SUCCESS
;
2286 ldp_cfg_resource_get_end
:
2288 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2290 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2295 /******************* HOP **********************/
2297 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2300 ldp_global
*global
= (ldp_global
*) handle
;
2301 mpls_return_enum retval
= MPLS_FAILURE
;
2302 ldp_hop_list
*hop_list
= NULL
;
2303 ldp_hop
*hop
= NULL
;
2305 MPLS_ASSERT(global
!=NULL
);
2307 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2309 if (!h
->hop_list_index
&& !h
->index
) {
2313 mpls_lock_get(global
->global_lock
); /* LOCK */
2315 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2318 if (flag
& LDP_CFG_ADD
) {
2319 if (!(hop_list
= ldp_hop_list_create())) {
2320 goto ldp_cfg_hop_set_end
;
2322 _ldp_global_add_hop_list(global
, hop_list
);
2324 h
->hop_list_index
= hop_list
->index
;
2326 goto ldp_cfg_hop_set_end
;
2330 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2332 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2333 if (!(hop
= ldp_hop_create())) {
2334 goto ldp_cfg_hop_set_end
;
2336 hop
->index
= h
->index
;
2337 ldp_hop_list_add_hop(hop_list
, hop
);
2339 goto ldp_cfg_hop_set_end
;
2343 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2344 hop
->path_option
= h
->path_option
;
2346 if (flag
& LDP_HOP_CFG_ADDR
) {
2347 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2349 if (flag
& LDP_HOP_CFG_TYPE
) {
2350 hop
->type
= h
->type
;
2352 retval
= MPLS_SUCCESS
;
2354 ldp_cfg_hop_set_end
:
2356 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2358 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2363 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2366 ldp_global
*global
= (ldp_global
*) handle
;
2367 mpls_return_enum retval
= MPLS_FAILURE
;
2368 ldp_hop_list
*hop_list
= NULL
;
2369 ldp_hop
*hop
= NULL
;
2371 MPLS_ASSERT(global
!=NULL
);
2373 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2375 mpls_lock_get(global
->global_lock
); /* LOCK */
2377 if (flag
& LDP_CFG_ADD
) {
2378 retval
= MPLS_SUCCESS
;
2379 goto ldp_cfg_hop_test_end
;
2382 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2385 goto ldp_cfg_hop_test_end
;
2388 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2390 goto ldp_cfg_hop_test_end
;
2393 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2394 goto ldp_cfg_hop_test_end
;
2396 retval
= MPLS_SUCCESS
;
2398 ldp_cfg_hop_test_end
:
2400 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2402 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2407 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2410 ldp_global
*global
= (ldp_global
*) handle
;
2411 mpls_return_enum retval
= MPLS_FAILURE
;
2412 ldp_hop_list
*hop_list
= NULL
;
2413 ldp_hop
*hop
= NULL
;
2415 MPLS_ASSERT(global
!=NULL
);
2417 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2419 mpls_lock_get(global
->global_lock
); /* LOCK */
2421 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2424 goto ldp_cfg_hop_get_end
;
2427 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2429 goto ldp_cfg_hop_get_end
;
2432 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2433 h
->path_option
= hop
->path_option
;
2435 if (flag
& LDP_HOP_CFG_ADDR
) {
2436 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
2438 if (flag
& LDP_HOP_CFG_TYPE
) {
2439 h
->type
= hop
->type
;
2441 retval
= MPLS_SUCCESS
;
2443 ldp_cfg_hop_get_end
:
2445 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2447 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");