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_socket_impl.h"
28 #include "mpls_trace_impl.h"
29 #include "mpls_tree_impl.h"
31 mpls_cfg_handle
ldp_cfg_open(mpls_instance_handle data
)
33 ldp_global
*g
= ldp_global_create(data
);
35 LDP_ENTER(data
, "ldp_cfg_open");
36 LDP_EXIT(data
, "ldp_cfg_open");
38 return (mpls_cfg_handle
) g
;
41 void ldp_cfg_close(mpls_cfg_handle g
)
43 LDP_ENTER((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
45 LDP_EXIT((mpls_instance_handle
) g
->user_data
, "ldp_cfg_close");
48 /******************* GLOBAL **********************/
50 void ldp_cfg_global_attr(mpls_cfg_handle handle
) {
51 ldp_global
*global
= (ldp_global
*) handle
;
52 ldp_attr
*attr
= MPLS_LIST_HEAD(&global
->attr
);
54 if (attr
->state
== LDP_LSP_STATE_MAP_SENT
&& attr
->ds_attr
) {
55 LDP_PRINT(global
->user_data
, "%p(%s) xc to %p(%s)", attr
,
56 attr
->session
->session_name
, attr
->ds_attr
,
57 attr
->ds_attr
->session
->session_name
);
59 attr
= MPLS_LIST_NEXT(&global
->attr
, attr
, _global
);
63 mpls_return_enum
ldp_cfg_global_get(mpls_cfg_handle handle
, ldp_global
* g
,
66 ldp_global
*global
= (ldp_global
*) handle
;
68 MPLS_ASSERT(global
!=NULL
);
70 LDP_ENTER(global
->user_data
, "ldp_cfg_global_get");
72 mpls_lock_get(global
->global_lock
); /* LOCK */
74 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
75 memcpy(&(g
->lsr_identifier
), &(global
->lsr_identifier
),
76 sizeof(mpls_inet_addr
));
78 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
79 g
->admin_state
= global
->admin_state
;
81 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
82 g
->lsp_control_mode
= global
->lsp_control_mode
;
84 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
85 g
->label_retention_mode
= global
->label_retention_mode
;
87 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
88 g
->lsp_repair_mode
= global
->lsp_repair_mode
;
90 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
91 g
->propagate_release
= global
->propagate_release
;
93 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
94 g
->label_merge
= global
->label_merge
;
96 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
97 g
->loop_detection_mode
= global
->loop_detection_mode
;
99 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
100 g
->ttl_less_domain
= global
->ttl_less_domain
;
102 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
103 g
->local_tcp_port
= global
->local_tcp_port
;
105 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
106 g
->local_udp_port
= global
->local_udp_port
;
108 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
109 memcpy(&(g
->transport_address
), &(global
->transport_address
),
110 sizeof(mpls_inet_addr
));
112 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
113 g
->keepalive_timer
= global
->keepalive_timer
;
115 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
116 g
->keepalive_interval
= global
->keepalive_interval
;
118 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
119 g
->hellotime_timer
= global
->hellotime_timer
;
121 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
122 g
->hellotime_interval
= global
->hellotime_interval
;
125 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
126 g
->lsr_handle
= global
->lsr_handle
;
130 mpls_lock_release(global
->global_lock
); /* UNLOCK */
132 LDP_EXIT(global
->user_data
, "ldp_cfg_global_get");
137 mpls_return_enum
ldp_cfg_global_test(mpls_cfg_handle handle
, ldp_global
* g
,
140 ldp_global
*global
= (ldp_global
*) handle
;
141 mpls_return_enum retval
= MPLS_SUCCESS
;
143 MPLS_ASSERT(global
!=NULL
);
145 LDP_ENTER(global
->user_data
, "ldp_cfg_global_test");
147 mpls_lock_get(global
->global_lock
); /* LOCK */
149 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
))
150 retval
= MPLS_FAILURE
;
152 mpls_lock_release(global
->global_lock
); /* UNLOCK */
154 LDP_EXIT(global
->user_data
, "ldp_cfg_global_test");
159 mpls_return_enum
ldp_cfg_global_set(mpls_cfg_handle handle
, ldp_global
* g
,
162 ldp_global
*global
= (ldp_global
*) handle
;
163 mpls_return_enum retval
= MPLS_FAILURE
;
165 MPLS_ASSERT(global
!=NULL
);
167 LDP_ENTER(global
->user_data
, "ldp_cfg_global_set");
169 mpls_lock_get(global
->global_lock
); /* LOCK */
171 if ((global
->admin_state
== MPLS_ADMIN_ENABLE
&& (flag
& LDP_GLOBAL_CFG_WHEN_DOWN
)))
172 goto ldp_cfg_global_set_end
;
174 if (flag
& LDP_GLOBAL_CFG_CONTROL_MODE
) {
175 global
->lsp_control_mode
= g
->lsp_control_mode
;
177 if (flag
& LDP_GLOBAL_CFG_RETENTION_MODE
) {
178 global
->label_retention_mode
= g
->label_retention_mode
;
180 if (flag
& LDP_GLOBAL_CFG_REPAIR_MODE
) {
181 global
->lsp_repair_mode
= g
->lsp_repair_mode
;
183 if (flag
& LDP_GLOBAL_CFG_PROPOGATE_RELEASE
) {
184 global
->propagate_release
= g
->propagate_release
;
186 if (flag
& LDP_GLOBAL_CFG_LABEL_MERGE
) {
187 global
->label_merge
= g
->label_merge
;
189 if (flag
& LDP_GLOBAL_CFG_LOOP_DETECTION_MODE
) {
190 global
->loop_detection_mode
= g
->loop_detection_mode
;
192 if (flag
& LDP_GLOBAL_CFG_TTLLESS_DOMAIN
) {
193 global
->ttl_less_domain
= g
->ttl_less_domain
;
195 if (flag
& LDP_GLOBAL_CFG_LOCAL_TCP_PORT
) {
196 global
->local_tcp_port
= g
->local_tcp_port
;
198 if (flag
& LDP_GLOBAL_CFG_LOCAL_UDP_PORT
) {
199 global
->local_udp_port
= g
->local_udp_port
;
201 if (flag
& LDP_GLOBAL_CFG_LSR_IDENTIFIER
) {
202 memcpy(&(global
->lsr_identifier
), &(g
->lsr_identifier
),
203 sizeof(mpls_inet_addr
));
206 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
207 global
->lsr_handle
= g
->lsr_handle
;
210 if (flag
& LDP_GLOBAL_CFG_ADMIN_STATE
) {
211 if (global
->admin_state
== MPLS_ADMIN_ENABLE
&& g
->admin_state
== MPLS_ADMIN_DISABLE
) {
212 ldp_global_shutdown(global
);
213 } else if (global
->admin_state
== MPLS_ADMIN_DISABLE
&& g
->admin_state
==
215 ldp_global_startup(global
);
218 if (flag
& LDP_GLOBAL_CFG_TRANS_ADDR
) {
219 memcpy(&(global
->transport_address
), &(g
->transport_address
),
220 sizeof(mpls_inet_addr
));
222 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_TIMER
) {
223 if (g
->keepalive_timer
== 0) {
224 global
->keepalive_timer
= LDP_ENTITY_DEF_KEEPALIVE_TIMER
;
226 global
->keepalive_timer
= g
->keepalive_timer
;
229 if (flag
& LDP_GLOBAL_CFG_KEEPALIVE_INTERVAL
) {
230 if (g
->keepalive_interval
== 0) {
231 global
->keepalive_interval
= LDP_ENTITY_DEF_KEEPALIVE_INTERVAL
;
233 global
->keepalive_interval
= g
->keepalive_interval
;
236 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_TIMER
) {
237 if (g
->hellotime_timer
== 0) {
238 global
->hellotime_timer
= LDP_ENTITY_DEF_HELLOTIME_TIMER
;
240 global
->hellotime_timer
= g
->hellotime_timer
;
243 if (flag
& LDP_GLOBAL_CFG_HELLOTIME_INTERVAL
) {
244 if (g
->hellotime_interval
== 0) {
245 global
->hellotime_interval
= LDP_ENTITY_DEF_HELLOTIME_INTERVAL
;
247 global
->hellotime_interval
= g
->hellotime_interval
;
251 if (flag
& LDP_GLOBAL_CFG_LSR_HANDLE
) {
252 global
->lsr_handle
= g
->lsr_handle
;
255 global
->configuration_sequence_number
++;
257 retval
= MPLS_SUCCESS
;
259 ldp_cfg_global_set_end
:
261 mpls_lock_release(global
->global_lock
); /* UNLOCK */
263 LDP_EXIT(global
->user_data
, "ldp_cfg_global_set");
268 /******************* ENTITY **********************/
270 /* must set ldp_entity->index */
271 mpls_return_enum
ldp_cfg_entity_get(mpls_cfg_handle handle
, ldp_entity
* e
,
274 ldp_global
*global
= (ldp_global
*) handle
;
275 ldp_entity
*entity
= NULL
;
276 mpls_return_enum retval
= MPLS_FAILURE
;
278 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
280 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_get");
282 mpls_lock_get(global
->global_lock
); /* LOCK */
284 if (ldp_global_find_entity_index(global
, e
->index
, &entity
) != MPLS_SUCCESS
)
285 goto ldp_cfg_entity_get_end
;
287 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
288 e
->admin_state
= entity
->admin_state
;
290 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
291 e
->transport_address
= entity
->transport_address
;
293 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
294 e
->protocol_version
= entity
->protocol_version
;
296 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
297 e
->remote_tcp_port
= entity
->remote_tcp_port
;
299 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
300 e
->remote_udp_port
= entity
->remote_udp_port
;
302 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
303 e
->max_pdu
= entity
->max_pdu
;
305 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
306 e
->keepalive_timer
= entity
->keepalive_timer
;
308 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
309 e
->keepalive_interval
= entity
->keepalive_interval
;
311 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
312 e
->hellotime_timer
= entity
->hellotime_timer
;
314 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
315 e
->hellotime_interval
= entity
->hellotime_interval
;
317 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
318 e
->session_setup_count
= entity
->session_setup_count
;
320 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
321 e
->session_backoff_timer
= entity
->session_backoff_timer
;
323 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
324 e
->label_distribution_mode
= entity
->label_distribution_mode
;
326 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
327 e
->path_vector_limit
= entity
->path_vector_limit
;
329 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
330 e
->hop_count_limit
= entity
->hop_count_limit
;
332 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
333 e
->label_request_count
= entity
->label_request_count
;
335 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
336 e
->label_request_timer
= entity
->label_request_timer
;
338 if (flag
& LDP_ENTITY_CFG_TYPE
) {
339 e
->entity_type
= entity
->entity_type
;
341 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
342 e
->sub_index
= entity
->sub_index
;
344 if (flag
& LDP_ENTITY_CFG_MESG_TX
) {
345 e
->mesg_tx
= entity
->mesg_tx
;
347 if (flag
& LDP_ENTITY_CFG_MESG_RX
) {
348 e
->mesg_rx
= entity
->mesg_rx
;
350 if (flag
& LDP_ENTITY_CFG_ADJ_COUNT
) {
351 e
->adj_count
= entity
->adj_root
.count
;
353 if (flag
& LDP_ENTITY_CFG_ADJ_INDEX
) {
354 ldp_adj
*a
= MPLS_LIST_HEAD(&entity
->adj_root
);
355 e
->adj_index
= a
? a
->index
: 0;
357 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
358 e
->inherit_flag
= entity
->inherit_flag
;
360 retval
= MPLS_SUCCESS
;
362 ldp_cfg_entity_get_end
:
364 mpls_lock_release(global
->global_lock
); /* UNLOCK */
366 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_get");
371 mpls_return_enum
ldp_cfg_entity_getnext(mpls_cfg_handle handle
, ldp_entity
* e
,
374 ldp_global
*g
= (ldp_global
*) handle
;
375 ldp_entity
*entity
= NULL
;
376 mpls_return_enum r
= MPLS_FAILURE
;
377 mpls_bool done
= MPLS_BOOL_FALSE
;
380 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_getnext");
385 index
= e
->index
+ 1;
388 mpls_lock_get(g
->global_lock
); /* LOCK */
389 while (done
== MPLS_BOOL_FALSE
) {
390 switch ((r
= ldp_global_find_entity_index(g
, index
, &entity
))) {
392 case MPLS_END_OF_LIST
:
393 done
= MPLS_BOOL_TRUE
;
402 mpls_lock_release(g
->global_lock
); /* UNLOCK */
404 if (r
== MPLS_SUCCESS
) {
405 e
->index
= entity
->index
;
406 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
407 return ldp_cfg_entity_get(g
, e
, flag
);
409 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_getnext");
413 mpls_return_enum
ldp_cfg_entity_test(mpls_cfg_handle handle
, ldp_entity
* e
,
416 ldp_global
*global
= (ldp_global
*) handle
;
417 ldp_entity
*entity
= NULL
;
418 mpls_return_enum retval
= MPLS_FAILURE
;
420 MPLS_ASSERT(global
!=NULL
);
422 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_test");
424 mpls_lock_get(global
->global_lock
); /* LOCK */
426 if (!(flag
& LDP_CFG_ADD
)) {
428 goto ldp_cfg_entity_test_end
;
430 ldp_global_find_entity_index(global
, e
->index
, &entity
);
432 retval
= MPLS_SUCCESS
;
433 goto ldp_cfg_entity_test_end
;
436 if (entity
== NULL
) {
437 goto ldp_cfg_entity_test_end
;
440 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
441 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
442 goto ldp_cfg_entity_test_end
;
445 retval
= MPLS_SUCCESS
;
447 ldp_cfg_entity_test_end
:
448 mpls_lock_release(global
->global_lock
); /* UNLOCK */
450 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_test");
455 /* must set ldp_entity->index if not an add */
456 mpls_return_enum
ldp_cfg_entity_set(mpls_cfg_handle handle
, ldp_entity
* e
,
459 ldp_global
*global
= (ldp_global
*) handle
;
460 ldp_entity
*entity
= NULL
;
461 mpls_return_enum retval
= MPLS_FAILURE
;
463 MPLS_ASSERT(global
!=NULL
&& e
!= NULL
);
465 LDP_ENTER(global
->user_data
, "ldp_cfg_entity_set");
467 mpls_lock_get(global
->global_lock
); /* LOCK */
469 if (flag
& LDP_CFG_ADD
) {
470 entity
= ldp_entity_create();
471 _ldp_global_add_entity(global
, entity
);
473 e
->index
= entity
->index
;
475 ldp_global_find_entity_index(global
, e
->index
, &entity
);
478 if (entity
== NULL
) {
479 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: can't find entity\n");
480 goto ldp_cfg_entity_set_end
;
483 if ((ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
) &&
484 (flag
& LDP_ENTITY_CFG_WHEN_DOWN
)) {
485 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity is active\n");
486 goto ldp_cfg_entity_set_end
;
489 if (flag
& LDP_CFG_DEL
) {
490 switch (entity
->entity_type
) {
492 ldp_entity_del_if(global
, entity
);
495 ldp_entity_del_peer(entity
);
500 _ldp_global_del_entity(global
, entity
);
502 retval
= MPLS_SUCCESS
;
503 goto ldp_cfg_entity_set_end
;
506 if (flag
& LDP_ENTITY_CFG_SUB_INDEX
) {
507 if (entity
->sub_index
!= 0) {
508 /* unlink the old sub object */
509 switch (entity
->entity_type
) {
511 ldp_entity_del_if(global
, entity
);
514 ldp_entity_del_peer(entity
);
521 /* link the new sub object */
522 switch (e
->entity_type
) {
526 if (ldp_global_find_if_index(global
, e
->sub_index
,
527 &iff
) != MPLS_SUCCESS
) {
528 LDP_PRINT(global
->user_data
,
529 "ldp_cfg_entity_set: no such interface\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_if(entity
, iff
);
541 ldp_peer
*peer
= NULL
;
543 if (ldp_global_find_peer_index(global
, e
->sub_index
, &peer
) !=
545 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: no such peer\n");
547 if (flag
& LDP_CFG_ADD
) {
548 _ldp_global_del_entity(global
, entity
);
550 goto ldp_cfg_entity_set_end
;
552 ldp_entity_add_peer(entity
, peer
);
560 if (flag
& LDP_ENTITY_CFG_TRANS_ADDR
) {
561 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
562 entity
->inherit_flag
|= LDP_ENTITY_CFG_TRANS_ADDR
;
564 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_TRANS_ADDR
;
566 memcpy(&entity
->transport_address
, &e
->transport_address
,
567 sizeof(mpls_inet_addr
));;
569 if (flag
& LDP_ENTITY_CFG_PROTO_VER
) {
570 entity
->protocol_version
= e
->protocol_version
;
572 if (flag
& LDP_ENTITY_CFG_REMOTE_TCP
) {
573 entity
->remote_tcp_port
= e
->remote_tcp_port
;
575 if (flag
& LDP_ENTITY_CFG_REMOTE_UDP
) {
576 entity
->remote_udp_port
= e
->remote_udp_port
;
578 if (flag
& LDP_ENTITY_CFG_MAX_PDU
) {
579 entity
->max_pdu
= e
->max_pdu
;
581 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_TIMER
) {
582 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
583 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
585 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_TIMER
;
587 entity
->keepalive_timer
= e
->keepalive_timer
;
589 if (flag
& LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
) {
590 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
591 entity
->inherit_flag
|= LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
593 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_KEEPALIVE_INTERVAL
;
595 entity
->keepalive_interval
= e
->keepalive_interval
;
597 if (flag
& LDP_ENTITY_CFG_HELLOTIME_TIMER
) {
598 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
599 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_TIMER
;
601 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_TIMER
;
603 entity
->hellotime_timer
= e
->hellotime_timer
;
605 if (flag
& LDP_ENTITY_CFG_HELLOTIME_INTERVAL
) {
606 if (e
->transport_address
.type
== MPLS_FAMILY_NONE
) {
607 entity
->inherit_flag
|= LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
609 entity
->inherit_flag
&= ~LDP_ENTITY_CFG_HELLOTIME_INTERVAL
;
611 entity
->hellotime_interval
= e
->hellotime_interval
;
613 if (flag
& LDP_ENTITY_CFG_SESSION_SETUP_COUNT
) {
614 entity
->session_setup_count
= e
->session_setup_count
;
616 if (flag
& LDP_ENTITY_CFG_SESSION_BACKOFF_TIMER
) {
617 entity
->session_backoff_timer
= e
->session_backoff_timer
;
619 if (flag
& LDP_ENTITY_CFG_DISTRIBUTION_MODE
) {
620 entity
->label_distribution_mode
= e
->label_distribution_mode
;
622 if (flag
& LDP_ENTITY_CFG_PATHVECTOR_LIMIT
) {
623 entity
->path_vector_limit
= e
->path_vector_limit
;
625 if (flag
& LDP_ENTITY_CFG_HOPCOUNT_LIMIT
) {
626 entity
->hop_count_limit
= e
->hop_count_limit
;
628 if (flag
& LDP_ENTITY_CFG_REQUEST_COUNT
) {
629 entity
->label_request_count
= e
->label_request_count
;
631 if (flag
& LDP_ENTITY_CFG_REQUEST_TIMER
) {
632 entity
->label_request_timer
= e
->label_request_timer
;
634 if (flag
& LDP_ENTITY_CFG_TYPE
) {
635 entity
->entity_type
= e
->entity_type
;
637 if (flag
& LDP_ENTITY_CFG_ADMIN_STATE
) {
638 if (ldp_entity_is_active(entity
) == MPLS_BOOL_TRUE
&&
639 e
->admin_state
== MPLS_ADMIN_DISABLE
) {
640 if (ldp_entity_shutdown(global
, entity
, 0) == MPLS_FAILURE
) {
641 goto ldp_cfg_entity_set_end
;
643 } else if (ldp_entity_is_active(entity
) == MPLS_BOOL_FALSE
&&
644 e
->admin_state
== MPLS_ADMIN_ENABLE
&& ldp_entity_is_ready(entity
) == MPLS_BOOL_TRUE
) {
645 if (ldp_entity_startup(global
, entity
) == MPLS_FAILURE
) {
646 goto ldp_cfg_entity_set_end
;
649 LDP_PRINT(global
->user_data
, "ldp_cfg_entity_set: entity not ready\n");
651 goto ldp_cfg_entity_set_end
;
654 if (flag
& LDP_ENTITY_CFG_INHERIT_FLAG
) {
655 entity
->inherit_flag
= e
->inherit_flag
;
657 global
->configuration_sequence_number
++;
659 retval
= MPLS_SUCCESS
;
661 ldp_cfg_entity_set_end
:
662 mpls_lock_release(global
->global_lock
); /* UNLOCK */
664 LDP_EXIT(global
->user_data
, "ldp_cfg_entity_set");
669 mpls_return_enum
ldp_cfg_entity_adj_getnext(mpls_cfg_handle handle
,
672 ldp_global
*g
= (ldp_global
*) handle
;
673 mpls_bool this_one
= MPLS_BOOL_FALSE
;
674 mpls_return_enum r
= MPLS_FAILURE
;
675 ldp_adj
*adj_next
= NULL
;
677 ldp_entity
*entity
= NULL
;
679 LDP_ENTER(g
->user_data
, "ldp_cfg_entity_adj_getnext");
681 /* if an adj_index of zero is sent, get the index of
682 * the first adj in the list
685 this_one
= MPLS_BOOL_TRUE
;
688 mpls_lock_get(g
->global_lock
); /* LOCK */
690 if (ldp_global_find_entity_index(g
, e
->index
, &entity
) == MPLS_SUCCESS
) {
691 adj
= MPLS_LIST_HEAD(&entity
->adj_root
);
693 if (this_one
== MPLS_BOOL_TRUE
) {
698 /* since the entities are sort in the list ... */
699 if (adj
->index
> e
->adj_index
) {
701 } else if (adj
->index
== e
->adj_index
) {
702 this_one
= MPLS_BOOL_TRUE
;
704 adj
= MPLS_LIST_NEXT(&entity
->adj_root
, adj
, _entity
);
707 mpls_lock_release(g
->global_lock
); /* UNLOCK */
710 e
->adj_index
= adj_next
->index
;
714 LDP_EXIT(g
->user_data
, "ldp_cfg_entity_adj_getnext");
718 /******************* INTERFACE **********************/
720 mpls_return_enum
ldp_cfg_if_get(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
722 ldp_global
*global
= (ldp_global
*) handle
;
724 mpls_return_enum retval
= MPLS_FAILURE
;
726 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
728 LDP_ENTER(global
->user_data
, "ldp_cfg_if_get");
730 mpls_lock_get(global
->global_lock
); /* LOCK */
732 if (flag
& LDP_IF_CFG_BY_INDEX
) {
733 ldp_global_find_if_index(global
, i
->index
, &iff
);
735 iff
= ldp_global_find_if_handle(global
, i
->handle
);
738 goto ldp_cfg_if_get_end
;
740 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
741 i
->label_space
= iff
->label_space
;
743 if (flag
& LDP_IF_CFG_ENTITY_INDEX
) {
744 i
->entity_index
= iff
->entity
? iff
->entity
->index
: 0;
746 if (flag
& LDP_IF_CFG_OPER_STATE
) {
747 i
->oper_state
= iff
->oper_state
;
749 if (flag
& LDP_IF_CFG_HANDLE
) {
750 memcpy(&i
->handle
, &iff
->handle
, sizeof(mpls_if_handle
));
752 retval
= MPLS_SUCCESS
;
755 mpls_lock_release(global
->global_lock
); /* UNLOCK */
757 LDP_EXIT(global
->user_data
, "ldp_cfg_if_get");
762 mpls_return_enum
ldp_cfg_if_getnext(mpls_cfg_handle handle
, ldp_if
* i
,
765 ldp_global
*g
= (ldp_global
*) handle
;
767 mpls_return_enum r
= MPLS_FAILURE
;
768 mpls_bool done
= MPLS_BOOL_FALSE
;
771 LDP_ENTER(g
->user_data
, "ldp_cfg_if_getnext");
776 index
= i
->index
+ 1;
779 mpls_lock_get(g
->global_lock
); /* LOCK */
780 while (done
== MPLS_BOOL_FALSE
) {
781 switch ((r
= ldp_global_find_if_index(g
, index
, &iff
))) {
783 case MPLS_END_OF_LIST
:
784 done
= MPLS_BOOL_TRUE
;
793 mpls_lock_release(g
->global_lock
); /* UNLOCK */
795 if (r
== MPLS_SUCCESS
) {
796 i
->index
= iff
->index
;
797 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
798 return ldp_cfg_if_get(g
, i
, flag
);
800 LDP_EXIT(g
->user_data
, "ldp_cfg_if_getnext");
804 mpls_return_enum
ldp_cfg_if_test(mpls_cfg_handle handle
, ldp_if
* i
,
807 ldp_global
*global
= (ldp_global
*) handle
;
809 mpls_return_enum retval
= MPLS_FAILURE
;
811 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
813 LDP_ENTER(global
->user_data
, "ldp_cfg_if_test");
815 mpls_lock_get(global
->global_lock
); /* LOCK */
817 if (!(flag
& LDP_CFG_ADD
)) {
818 ldp_global_find_if_index(global
, i
->index
, &iff
);
820 retval
= MPLS_SUCCESS
;
821 goto ldp_cfg_if_test_end
;
824 if ((!iff
) || ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
825 (flag
& LDP_IF_CFG_WHEN_DOWN
))) {
826 goto ldp_cfg_if_test_end
;
829 if (flag
& LDP_CFG_DEL
) {
830 if (iff
->entity
!= NULL
) {
831 goto ldp_cfg_if_test_end
;
834 retval
= MPLS_SUCCESS
;
837 mpls_lock_release(global
->global_lock
); /* UNLOCK */
839 LDP_EXIT(global
->user_data
, "ldp_cfg_if_test");
844 mpls_return_enum
ldp_cfg_if_set(mpls_cfg_handle handle
, ldp_if
* i
, uint32_t flag
)
846 ldp_global
*global
= (ldp_global
*)handle
;
850 mpls_return_enum retval
= MPLS_FAILURE
;
852 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
854 LDP_ENTER(global
->user_data
, "ldp_cfg_if_set");
856 mpls_lock_get(global
->global_lock
); /* LOCK */
858 if (flag
& LDP_CFG_ADD
) {
859 /* duplicate interface handles are not allowed */
860 /* ADDs require a valid interface handle */
861 if ((iff
= ldp_global_find_if_handle(global
, i
->handle
)) != NULL
) {
862 LDP_PRINT(global
->user_data
, "Duplicate interface exists");
863 goto ldp_cfg_if_set_end
;
865 if (mpls_if_handle_verify(global
->ifmgr_handle
, i
->handle
) ==
867 LDP_PRINT(global
->user_data
, "Invalid interface handle");
868 goto ldp_cfg_if_set_end
;
870 if ((iff
= ldp_if_create(global
)) == NULL
) {
871 LDP_PRINT(global
->user_data
, "Failure creating interface");
872 goto ldp_cfg_if_set_end
;
875 /* copy the handle from the user */
876 iff
->handle
= i
->handle
;
878 /* search for addrs and nexthops that are waiting for this interface */
879 ap
= MPLS_LIST_HEAD(&global
->addr
);
881 if (ap
->if_handle
== iff
->handle
&& (!MPLS_LIST_IN_LIST(ap
, _if
))) {
882 ldp_if_add_addr(iff
, ap
);
884 ap
= MPLS_LIST_NEXT(&global
->addr
, ap
, _global
);
887 np
= MPLS_LIST_HEAD(&global
->nexthop
);
889 if ((np
->info
.type
& MPLS_NH_IF
) &&
890 (np
->info
.if_handle
== iff
->handle
) && (!MPLS_LIST_IN_LIST(np
, _if
))) {
891 ldp_if_add_nexthop(iff
, np
);
893 np
= MPLS_LIST_NEXT(&global
->nexthop
, np
, _global
);
896 /* send the newly created index back to the user */
897 i
->index
= iff
->index
;
898 MPLS_REFCNT_HOLD(iff
);
901 if (flag
& LDP_IF_CFG_BY_INDEX
) {
902 ldp_global_find_if_index(global
, i
->index
, &iff
);
904 iff
= ldp_global_find_if_handle(global
, i
->handle
);
909 * if we can't find this interface or if the interface is active and
910 * we are trying to change propertises that can not be changed on a
913 if ((!iff
) || ((ldp_if_is_active(iff
) == MPLS_BOOL_TRUE
) &&
914 (flag
& LDP_IF_CFG_WHEN_DOWN
))) {
915 goto ldp_cfg_if_set_end
;
918 if (flag
& LDP_IF_CFG_LABEL_SPACE
) {
919 iff
->label_space
= i
->label_space
;
922 if (flag
& LDP_CFG_DEL
) {
924 * if this interface is still attached to a entity that it is not ready
927 if (iff
->entity
!= NULL
) {
928 goto ldp_cfg_if_set_end
;
931 np
= MPLS_LIST_HEAD(&iff
->nh_root
);
932 while ((np
= MPLS_LIST_HEAD(&iff
->nh_root
))) {
933 ldp_if_del_nexthop(global
, iff
, np
);
936 ap
= MPLS_LIST_HEAD(&iff
->addr_root
);
937 while ((ap
= MPLS_LIST_HEAD(&iff
->addr_root
))) {
938 ldp_if_del_addr(global
, iff
, ap
);
941 MPLS_REFCNT_RELEASE2(global
, iff
, ldp_if_delete
);
944 global
->configuration_sequence_number
++;
946 retval
= MPLS_SUCCESS
;
949 mpls_lock_release(global
->global_lock
); /* UNLOCK */
951 LDP_EXIT(global
->user_data
, "ldp_cfg_if_set");
956 /******************* ATTR **********************/
958 mpls_return_enum
ldp_cfg_attr_get(mpls_cfg_handle handle
, ldp_attr
* a
,
961 ldp_global
*global
= (ldp_global
*) handle
;
962 ldp_attr
*attr
= NULL
;
963 mpls_return_enum retval
= MPLS_FAILURE
;
965 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
967 LDP_ENTER(global
->user_data
, "ldp_cfg_attr_get");
969 mpls_lock_get(global
->global_lock
); /* LOCK */
971 if (ldp_global_find_attr_index(global
, a
->index
, &attr
) != MPLS_SUCCESS
)
972 goto ldp_cfg_attr_get_end
;
974 if (flag
& LDP_ATTR_CFG_STATE
) {
975 a
->state
= attr
->state
;
977 if (flag
& LDP_ATTR_CFG_FEC
) {
978 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_FEC
);
980 if (flag
& LDP_ATTR_CFG_LABEL
) {
981 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_LABEL
);
983 if (flag
& LDP_ATTR_CFG_HOP_COUNT
) {
984 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_HOPCOUNT
);
986 if (flag
& LDP_ATTR_CFG_PATH
) {
987 ldp_attr2ldp_attr(attr
, a
, LDP_ATTR_PATH
);
989 if (flag
& LDP_ATTR_CFG_SESSION_INDEX
) {
990 a
->session_index
= (attr
->session
) ? (attr
->session
->index
) : 0;
992 if (flag
& LDP_ATTR_CFG_INLABEL_INDEX
) {
993 a
->inlabel_index
= (attr
->inlabel
) ? (attr
->inlabel
->index
) : 0;
995 if (flag
& LDP_ATTR_CFG_OUTLABEL_INDEX
) {
996 a
->outlabel_index
= (attr
->outlabel
) ? (attr
->outlabel
->index
) : 0;
998 if (flag
& LDP_ATTR_CFG_INGRESS
) {
999 a
->ingress
= attr
->ingress
;
1001 retval
= MPLS_SUCCESS
;
1003 ldp_cfg_attr_get_end
:
1004 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1006 LDP_EXIT(global
->user_data
, "ldp_cfg_attr_get");
1011 mpls_return_enum
ldp_cfg_attr_getnext(mpls_cfg_handle handle
, ldp_attr
* a
,
1014 ldp_global
*g
= (ldp_global
*) handle
;
1015 ldp_attr
*attr
= NULL
;
1016 mpls_return_enum r
= MPLS_FAILURE
;
1017 mpls_bool done
= MPLS_BOOL_FALSE
;
1020 LDP_ENTER(g
->user_data
, "ldp_cfg_attr_getnext");
1022 if (a
->index
== 0) {
1025 index
= a
->index
+ 1;
1028 mpls_lock_get(g
->global_lock
); /* LOCK */
1029 while (done
== MPLS_BOOL_FALSE
) {
1030 switch ((r
= ldp_global_find_attr_index(g
, index
, &attr
))) {
1032 case MPLS_END_OF_LIST
:
1033 done
= MPLS_BOOL_TRUE
;
1042 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1044 if (r
== MPLS_SUCCESS
) {
1045 a
->index
= attr
->index
;
1046 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1047 return ldp_cfg_attr_get(g
, a
, flag
);
1049 LDP_EXIT(g
->user_data
, "ldp_cfg_attr_getnext");
1053 /******************* PEER **********************/
1055 mpls_return_enum
ldp_cfg_peer_get(mpls_cfg_handle handle
, ldp_peer
* p
,
1058 ldp_global
*global
= (ldp_global
*) handle
;
1059 ldp_peer
*peer
= NULL
;
1060 mpls_return_enum retval
= MPLS_FAILURE
;
1062 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1064 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_get");
1066 mpls_lock_get(global
->global_lock
); /* LOCK */
1068 if (ldp_global_find_peer_index(global
, p
->index
, &peer
) != MPLS_SUCCESS
)
1069 goto ldp_cfg_peer_get_end
;
1071 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1072 p
->label_space
= peer
->label_space
;
1074 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1075 p
->target_role
= peer
->target_role
;
1077 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1078 memcpy(&p
->dest
.addr
, &peer
->dest
.addr
, sizeof(mpls_inet_addr
));
1080 if (flag
& LDP_PEER_CFG_ENTITY_INDEX
) {
1081 p
->entity_index
= peer
->entity
->index
;
1083 if (flag
& LDP_PEER_CFG_OPER_STATE
) {
1084 p
->oper_state
= peer
->oper_state
;
1086 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1087 strncpy(p
->peer_name
, peer
->peer_name
, MPLS_MAX_IF_NAME
);
1089 retval
= MPLS_SUCCESS
;
1091 ldp_cfg_peer_get_end
:
1092 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1094 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_get");
1099 mpls_return_enum
ldp_cfg_peer_getnext(mpls_cfg_handle handle
, ldp_peer
* p
,
1102 ldp_global
*g
= (ldp_global
*) handle
;
1103 ldp_peer
*peer
= NULL
;
1104 mpls_return_enum r
= MPLS_FAILURE
;
1105 mpls_bool done
= MPLS_BOOL_FALSE
;
1108 LDP_ENTER(g
->user_data
, "ldp_cfg_peer_getnext");
1110 if (p
->index
== 0) {
1113 index
= p
->index
+ 1;
1116 mpls_lock_get(g
->global_lock
); /* LOCK */
1117 while (done
== MPLS_BOOL_FALSE
) {
1118 switch ((r
= ldp_global_find_peer_index(g
, index
, &peer
))) {
1120 case MPLS_END_OF_LIST
:
1121 done
= MPLS_BOOL_TRUE
;
1130 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1132 if (r
== MPLS_SUCCESS
) {
1133 p
->index
= peer
->index
;
1134 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1135 return ldp_cfg_peer_get(g
, p
, flag
);
1137 LDP_EXIT(g
->user_data
, "ldp_cfg_peer_getnext");
1141 mpls_return_enum
ldp_cfg_peer_test(mpls_cfg_handle handle
, ldp_peer
* p
,
1144 // ldp_global* g = (ldp_global*)handle;
1145 return MPLS_SUCCESS
;
1148 mpls_return_enum
ldp_cfg_peer_set(mpls_cfg_handle handle
, ldp_peer
* p
,
1151 ldp_global
*global
= (ldp_global
*) handle
;
1152 ldp_peer
*peer
= NULL
;
1153 mpls_return_enum retval
= MPLS_FAILURE
;
1155 MPLS_ASSERT(global
!=NULL
&& p
!= NULL
);
1157 LDP_ENTER(global
->user_data
, "ldp_cfg_peer_set");
1159 mpls_lock_get(global
->global_lock
); /* LOCK */
1161 if (flag
& LDP_CFG_ADD
) {
1162 if ((peer
= ldp_peer_create()) == NULL
) {
1163 goto ldp_cfg_peer_set_end
;
1165 p
->index
= peer
->index
;
1166 _ldp_global_add_peer(global
, peer
);
1168 ldp_global_find_peer_index(global
, p
->index
, &peer
);
1172 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: no such peer\n");
1174 goto ldp_cfg_peer_set_end
;
1176 if ((ldp_peer_is_active(peer
) == MPLS_BOOL_TRUE
) && (flag
& LDP_PEER_CFG_WHEN_DOWN
)) {
1177 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer is activer\n");
1179 goto ldp_cfg_peer_set_end
;
1182 if (flag
& LDP_CFG_DEL
) {
1183 if (peer
->entity
!= NULL
) {
1184 LDP_PRINT(global
->user_data
,
1185 "ldp_cfg_peer_set: not cleanup correctly is activer\n");
1187 goto ldp_cfg_peer_set_end
;
1190 _ldp_global_del_peer(global
, peer
);
1192 retval
= MPLS_SUCCESS
;
1193 goto ldp_cfg_peer_set_end
;
1195 if (flag
& LDP_PEER_CFG_LABEL_SPACE
) {
1196 peer
->label_space
= p
->label_space
;
1198 if (flag
& LDP_PEER_CFG_TARGET_ROLE
) {
1199 peer
->target_role
= p
->target_role
;
1201 if (flag
& LDP_PEER_CFG_DEST_ADDR
) {
1202 memcpy(&peer
->dest
.addr
, &p
->dest
.addr
, sizeof(mpls_inet_addr
));
1204 if (flag
& LDP_PEER_CFG_PEER_NAME
) {
1205 LDP_PRINT(global
->user_data
, "ldp_cfg_peer_set: peer_name = %s\n",
1208 strncpy(peer
->peer_name
, p
->peer_name
, MPLS_MAX_IF_NAME
);
1210 global
->configuration_sequence_number
++;
1212 retval
= MPLS_SUCCESS
;
1214 ldp_cfg_peer_set_end
:
1215 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1217 LDP_EXIT(global
->user_data
, "ldp_cfg_peer_set");
1221 /******************* FEC **********************/
1223 mpls_return_enum
ldp_cfg_fec_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1226 ldp_global
*global
= (ldp_global
*) handle
;
1227 ldp_fec
*fec
= NULL
;
1228 mpls_return_enum retval
= MPLS_FAILURE
;
1230 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1232 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_get");
1234 mpls_lock_get(global
->global_lock
); /* LOCK */
1236 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1237 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1239 fec
= ldp_fec_find(global
, f
);
1242 goto ldp_cfg_fec_get_end
;
1244 memcpy(f
, &fec
->info
, sizeof(mpls_fec
));
1245 f
->index
= fec
->index
;
1246 f
->is_route
= fec
->is_route
;
1247 retval
= MPLS_SUCCESS
;
1249 ldp_cfg_fec_get_end
:
1250 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1252 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_get");
1257 mpls_return_enum
ldp_cfg_fec_getnext(mpls_cfg_handle handle
, mpls_fec
* f
,
1260 ldp_global
*g
= (ldp_global
*) handle
;
1261 ldp_fec
*fec
= NULL
;
1262 mpls_return_enum r
= MPLS_FAILURE
;
1263 mpls_bool done
= MPLS_BOOL_FALSE
;
1266 LDP_ENTER(g
->user_data
, "ldp_cfg_fec_getnext");
1268 if (f
->index
== 0) {
1271 index
= f
->index
+ 1;
1274 mpls_lock_get(g
->global_lock
); /* LOCK */
1275 while (done
== MPLS_BOOL_FALSE
) {
1276 switch ((r
= ldp_global_find_fec_index(g
, index
, &fec
))) {
1278 case MPLS_END_OF_LIST
:
1279 done
= MPLS_BOOL_TRUE
;
1288 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1290 if (r
== MPLS_SUCCESS
) {
1291 f
->index
= fec
->index
;
1292 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1293 return ldp_cfg_fec_get(g
, f
, flag
);
1295 LDP_EXIT(g
->user_data
, "ldp_cfg_fec_getnext");
1299 mpls_return_enum
ldp_cfg_fec_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1302 // ldp_global* g = (ldp_global*)handle;
1303 return MPLS_SUCCESS
;
1306 mpls_return_enum
ldp_cfg_fec_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1309 ldp_global
*global
= (ldp_global
*) handle
;
1310 ldp_fec
*fec
= NULL
;
1311 mpls_return_enum retval
= MPLS_FAILURE
;
1313 MPLS_ASSERT(global
!= NULL
&& f
!= NULL
);
1315 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_set");
1317 mpls_lock_get(global
->global_lock
); /* LOCK */
1319 if (flag
& LDP_CFG_ADD
) {
1320 if ((fec
= ldp_fec_find(global
, f
))) {
1321 if (fec
->is_route
== MPLS_BOOL_TRUE
) {
1322 goto ldp_cfg_fec_set_end
;
1325 if ((fec
= ldp_fec_create(global
, f
)) == NULL
) {
1326 goto ldp_cfg_fec_set_end
;
1329 fec
->is_route
= MPLS_BOOL_TRUE
;
1330 MPLS_REFCNT_HOLD(fec
);
1331 f
->index
= fec
->index
;
1333 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1334 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1336 fec
= ldp_fec_find(global
, f
);
1341 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_set: no such fec\n");
1342 goto ldp_cfg_fec_set_end
;
1345 if (flag
& LDP_CFG_DEL
) {
1347 * we can only delete the fec if all of the nexthops have been removed
1349 if (!MPLS_LIST_EMPTY(&fec
->nh_root
)) {
1350 goto ldp_cfg_fec_set_end
;
1353 fec
->is_route
= MPLS_BOOL_FALSE
;
1356 * we hold the last refcnt, this should result in a call to
1359 MPLS_REFCNT_RELEASE2(global
, fec
, ldp_fec_delete
);
1362 retval
= MPLS_SUCCESS
;
1364 ldp_cfg_fec_set_end
:
1365 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1367 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_set");
1371 mpls_return_enum
ldp_cfg_fec_nexthop_get(mpls_cfg_handle handle
, mpls_fec
* f
,
1372 mpls_nexthop
*n
, uint32_t flag
)
1374 ldp_global
*global
= (ldp_global
*) handle
;
1375 ldp_fec
*fec
= NULL
;
1376 ldp_nexthop
*nh
= NULL
;
1377 mpls_return_enum retval
= MPLS_FAILURE
;
1379 MPLS_ASSERT(global
!=NULL
&& f
!= NULL
);
1381 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1383 mpls_lock_get(global
->global_lock
); /* LOCK */
1385 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1386 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1388 fec
= ldp_fec_find(global
, f
);
1391 goto ldp_cfg_fec_nexthop_get_end
;
1393 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1394 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1396 nh
= ldp_fec_nexthop_find(fec
, n
);
1399 goto ldp_cfg_fec_nexthop_get_end
;
1401 memcpy(n
, &nh
->info
, sizeof(mpls_nexthop
));
1402 n
->index
= nh
->index
;
1403 retval
= MPLS_SUCCESS
;
1405 ldp_cfg_fec_nexthop_get_end
:
1406 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1408 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_get");
1413 mpls_return_enum
ldp_cfg_fec_nexthop_getnext(mpls_cfg_handle handle
,
1414 mpls_fec
* f
, mpls_nexthop
*n
, uint32_t flag
)
1416 ldp_global
*global
= (ldp_global
*) handle
;
1417 ldp_fec
*fec
= NULL
;
1418 ldp_nexthop
*nh
= NULL
;
1419 mpls_return_enum r
= MPLS_FAILURE
;
1420 mpls_bool done
= MPLS_BOOL_FALSE
;
1423 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1425 if (n
->index
== 0) {
1428 index
= n
->index
+ 1;
1431 mpls_lock_get(global
->global_lock
); /* LOCK */
1433 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1434 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1436 fec
= ldp_fec_find(global
, f
);
1439 goto ldp_cfg_fec_nexthop_getnext_end
;
1441 while (done
== MPLS_BOOL_FALSE
) {
1442 switch ((r
= ldp_fec_find_nexthop_index(fec
, index
, &nh
))) {
1444 case MPLS_END_OF_LIST
:
1445 done
= MPLS_BOOL_TRUE
;
1454 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1456 if (r
== MPLS_SUCCESS
) {
1457 n
->index
= nh
->index
;
1458 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1459 return ldp_cfg_fec_nexthop_get(global
, f
, n
, flag
);
1462 ldp_cfg_fec_nexthop_getnext_end
:
1464 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_getnext");
1468 mpls_return_enum
ldp_cfg_fec_nexthop_test(mpls_cfg_handle handle
, mpls_fec
* f
,
1469 mpls_nexthop
*n
, uint32_t flag
)
1471 // ldp_global* g = (ldp_global*)handle;
1472 return MPLS_SUCCESS
;
1475 mpls_return_enum
ldp_cfg_fec_nexthop_set(mpls_cfg_handle handle
, mpls_fec
* f
,
1476 mpls_nexthop
*n
, uint32_t flag
)
1478 ldp_global
*global
= (ldp_global
*) handle
;
1479 ldp_fec
*fec
= NULL
;
1480 ldp_nexthop
*nh
= NULL
;
1481 mpls_return_enum retval
= MPLS_FAILURE
;
1483 MPLS_ASSERT(global
!= NULL
&& f
!= NULL
&& n
!= NULL
);
1485 LDP_ENTER(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1487 mpls_lock_get(global
->global_lock
); /* LOCK */
1489 if (flag
& LDP_FEC_CFG_BY_INDEX
) {
1490 ldp_global_find_fec_index(global
, f
->index
, &fec
);
1492 fec
= ldp_fec_find(global
, f
);
1495 goto ldp_cfg_fec_nexthop_set_end
;
1497 if (flag
& LDP_CFG_ADD
) {
1498 if (ldp_fec_nexthop_find(fec
, n
) ||
1499 (nh
= ldp_nexthop_create(global
, n
)) == NULL
) {
1500 goto ldp_cfg_fec_nexthop_set_end
;
1502 n
->index
= nh
->index
;
1503 ldp_fec_add_nexthop(global
, fec
, nh
);
1504 ldp_fec_process_add(global
, fec
, nh
, NULL
);
1506 if (flag
& LDP_FEC_NEXTHOP_CFG_BY_INDEX
) {
1507 ldp_fec_find_nexthop_index(fec
, n
->index
, &nh
);
1509 nh
= ldp_fec_nexthop_find(fec
, n
);
1514 LDP_PRINT(global
->user_data
, "ldp_cfg_fec_nexthop_set: no such nh\n");
1515 goto ldp_cfg_fec_nexthop_set_end
;
1518 if (flag
& LDP_CFG_DEL
) {
1519 MPLS_REFCNT_HOLD(nh
);
1520 ldp_fec_del_nexthop(global
, fec
, nh
);
1521 if (ldp_fec_process_change(global
, fec
, MPLS_LIST_HEAD(&fec
->nh_root
),
1522 nh
, NULL
) != MPLS_SUCCESS
) {
1525 MPLS_REFCNT_RELEASE2(global
, nh
, ldp_nexthop_delete
);
1528 retval
= MPLS_SUCCESS
;
1530 ldp_cfg_fec_nexthop_set_end
:
1531 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1533 LDP_EXIT(global
->user_data
, "ldp_cfg_fec_nexthop_set");
1538 /******************* ADDR **********************/
1540 mpls_return_enum
ldp_cfg_addr_get(mpls_cfg_handle handle
, ldp_addr
* a
,
1543 ldp_global
*global
= (ldp_global
*) handle
;
1544 ldp_nexthop
*nexthop
= NULL
;
1545 ldp_addr
*addr
= NULL
;
1546 mpls_return_enum retval
= MPLS_FAILURE
;
1548 MPLS_ASSERT(global
!=NULL
&& a
!= NULL
);
1550 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_get");
1552 mpls_lock_get(global
->global_lock
); /* LOCK */
1554 ldp_global_find_addr_index(global
, a
->index
, &addr
);
1557 goto ldp_cfg_addr_get_end
;
1559 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1560 a
->index
= addr
->index
;
1562 if (addr
->session
) {
1563 a
->session_index
= addr
->session
->index
;
1566 if ((nexthop
= MPLS_LIST_HEAD(&addr
->nh_root
))) {
1567 a
->nexthop_index
= nexthop
->index
;
1571 a
->if_index
= addr
->iff
->index
;
1574 retval
= MPLS_SUCCESS
;
1576 ldp_cfg_addr_get_end
:
1577 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1579 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_get");
1584 mpls_return_enum
ldp_cfg_addr_getnext(mpls_cfg_handle handle
, ldp_addr
*a
,
1587 ldp_global
*global
= (ldp_global
*) handle
;
1588 ldp_addr
*addr
= NULL
;
1589 mpls_return_enum r
= MPLS_FAILURE
;
1590 mpls_bool done
= MPLS_BOOL_FALSE
;
1593 LDP_ENTER(global
->user_data
, "ldp_cfg_addr_getnext");
1595 if (a
->index
== 0) {
1598 index
= a
->index
+ 1;
1601 mpls_lock_get(global
->global_lock
); /* LOCK */
1603 while (done
== MPLS_BOOL_FALSE
) {
1604 switch ((r
= ldp_global_find_addr_index(global
, index
, &addr
))) {
1606 case MPLS_END_OF_LIST
:
1607 done
= MPLS_BOOL_TRUE
;
1616 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1618 if (r
== MPLS_SUCCESS
) {
1619 a
->index
= addr
->index
;
1620 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1621 return ldp_cfg_addr_get(global
, a
, flag
);
1624 LDP_EXIT(global
->user_data
, "ldp_cfg_addr_getnext");
1628 /******************* IF ADDR **********************/
1630 mpls_return_enum
ldp_cfg_if_addr_get(mpls_cfg_handle handle
, ldp_if
* i
,
1631 ldp_addr
* a
, uint32_t flag
)
1633 ldp_global
*global
= (ldp_global
*) handle
;
1634 ldp_addr
*addr
= NULL
;
1636 mpls_return_enum retval
= MPLS_FAILURE
;
1638 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
&& a
!= NULL
);
1640 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_get");
1642 mpls_lock_get(global
->global_lock
); /* LOCK */
1644 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1645 ldp_global_find_if_index(global
, i
->index
, &iff
);
1647 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1650 goto ldp_cfg_if_addr_get_end
;
1652 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1653 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1655 addr
= ldp_if_addr_find(iff
, &a
->address
);
1658 goto ldp_cfg_if_addr_get_end
;
1660 memcpy(&a
->address
, &addr
->address
, sizeof(mpls_inet_addr
));
1661 a
->index
= addr
->index
;
1663 retval
= MPLS_SUCCESS
;
1665 ldp_cfg_if_addr_get_end
:
1666 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1668 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_get");
1673 mpls_return_enum
ldp_cfg_if_addr_getnext(mpls_cfg_handle handle
,
1674 ldp_if
* i
, ldp_addr
*a
, uint32_t flag
)
1676 ldp_global
*global
= (ldp_global
*) handle
;
1678 ldp_addr
*addr
= NULL
;
1679 mpls_return_enum r
= MPLS_FAILURE
;
1680 mpls_bool done
= MPLS_BOOL_FALSE
;
1683 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_getnext");
1685 if (a
->index
== 0) {
1688 index
= a
->index
+ 1;
1691 mpls_lock_get(global
->global_lock
); /* LOCK */
1693 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1694 ldp_global_find_if_index(global
, i
->index
, &iff
);
1696 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1699 goto ldp_cfg_if_addr_getnext_end
;
1701 while (done
== MPLS_BOOL_FALSE
) {
1702 switch ((r
= ldp_if_find_addr_index(iff
, index
, &addr
))) {
1704 case MPLS_END_OF_LIST
:
1705 done
= MPLS_BOOL_TRUE
;
1714 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1716 if (r
== MPLS_SUCCESS
) {
1717 a
->index
= addr
->index
;
1718 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1719 return ldp_cfg_if_addr_get(global
, i
, a
, flag
);
1722 ldp_cfg_if_addr_getnext_end
:
1724 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_getnext");
1728 mpls_return_enum
ldp_cfg_if_addr_set(mpls_cfg_handle handle
, ldp_if
* i
,
1729 ldp_addr
*a
, uint32_t flag
)
1731 ldp_global
*global
= (ldp_global
*) handle
;
1733 ldp_addr
*addr
= NULL
;
1734 mpls_return_enum retval
= MPLS_FAILURE
;
1736 MPLS_ASSERT(global
!= NULL
&& i
!= NULL
&& a
!= NULL
);
1738 LDP_ENTER(global
->user_data
, "ldp_cfg_if_addr_set");
1740 mpls_lock_get(global
->global_lock
); /* LOCK */
1742 if (flag
& LDP_IF_CFG_BY_INDEX
) {
1743 ldp_global_find_if_index(global
, i
->index
, &iff
);
1745 iff
= ldp_global_find_if_handle(global
, i
->handle
);
1748 LDP_PRINT(global
->user_data
, "ldp_cfg_if_addr_set: no such iff\n");
1749 goto ldp_cfg_if_addr_set_end
;
1752 if (flag
& LDP_CFG_ADD
) {
1753 if (ldp_if_addr_find(iff
, &a
->address
) || ((addr
= ldp_addr_create(global
,
1754 &a
->address
)) == NULL
)) {
1755 goto ldp_cfg_if_addr_set_end
;
1757 a
->index
= addr
->index
;
1758 ldp_if_add_addr(iff
, addr
);
1759 ldp_addr_process_add(global
, addr
);
1761 if (flag
& LDP_IF_ADDR_CFG_BY_INDEX
) {
1762 ldp_if_find_addr_index(iff
, a
->index
, &addr
);
1764 addr
= ldp_if_addr_find(iff
, &a
->address
);
1769 LDP_PRINT(global
->user_data
, "ldp_cfg_if_addr_set: no such addr\n");
1770 goto ldp_cfg_if_addr_set_end
;
1773 if (flag
& LDP_CFG_DEL
) {
1774 ldp_addr_process_remove(global
, addr
);
1775 ldp_if_del_addr(global
, iff
, addr
);
1778 retval
= MPLS_SUCCESS
;
1780 ldp_cfg_if_addr_set_end
:
1781 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1783 LDP_EXIT(global
->user_data
, "ldp_cfg_if_addr_set");
1788 /******************* ADJACENCY **********************/
1790 mpls_return_enum
ldp_cfg_adj_get(mpls_cfg_handle handle
, ldp_adj
* a
,
1793 ldp_global
*global
= (ldp_global
*) handle
;
1794 ldp_adj
*adj
= NULL
;
1795 mpls_return_enum retval
= MPLS_FAILURE
;
1797 MPLS_ASSERT(global
!= NULL
&& a
!= NULL
);
1799 LDP_ENTER(global
->user_data
, "ldp_cfg_adj_get");
1801 mpls_lock_get(global
->global_lock
); /* LOCK */
1803 if (ldp_global_find_adj_index(global
, a
->index
, &adj
) != MPLS_SUCCESS
)
1804 goto ldp_cfg_adj_get_end
;
1806 if (flag
& LDP_ADJ_CFG_REMOTE_TRADDR
) {
1807 memcpy(&a
->remote_transport_address
, &adj
->remote_transport_address
,
1808 sizeof(mpls_inet_addr
));
1810 if (flag
& LDP_ADJ_CFG_REMOTE_SRCADDR
) {
1811 memcpy(&a
->remote_source_address
, &adj
->remote_source_address
,
1812 sizeof(mpls_inet_addr
));
1814 if (flag
& LDP_ADJ_CFG_REMOTE_LSRADDR
) {
1815 memcpy(&a
->remote_lsr_address
, &adj
->remote_lsr_address
,
1816 sizeof(mpls_inet_addr
));
1818 if (flag
& LDP_ADJ_CFG_REMOTE_CSN
) {
1819 a
->remote_csn
= adj
->remote_csn
;
1821 if (flag
& LDP_ADJ_CFG_REMOTE_LABELSPACE
) {
1822 a
->remote_label_space
= adj
->remote_label_space
;
1824 if (flag
& LDP_ADJ_CFG_REMOTE_HELLOTIME
) {
1825 a
->remote_hellotime
= adj
->remote_hellotime
;
1827 if (flag
& LDP_ADJ_CFG_ENTITY_INDEX
) {
1828 a
->entity_index
= adj
->entity
? adj
->entity
->index
: 0;
1830 if (flag
& LDP_ADJ_CFG_REMOTE_SESSION_INDEX
) {
1831 a
->session_index
= (adj
->session
) ? (adj
->session
->index
) : 0;
1833 if (flag
& LDP_ADJ_CFG_ROLE
) {
1834 a
->role
= adj
->role
;
1836 retval
= MPLS_SUCCESS
;
1838 ldp_cfg_adj_get_end
:
1840 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1842 LDP_EXIT(global
->user_data
, "ldp_cfg_adj_get");
1847 mpls_return_enum
ldp_cfg_adj_getnext(mpls_cfg_handle handle
, ldp_adj
* a
,
1850 ldp_global
*g
= (ldp_global
*) handle
;
1851 ldp_adj
*adj
= NULL
;
1852 mpls_return_enum r
= MPLS_FAILURE
;
1853 mpls_bool done
= MPLS_BOOL_FALSE
;
1856 LDP_ENTER(g
->user_data
, "ldp_cfg_adj_getnext");
1858 if (a
->index
== 0) {
1861 index
= a
->index
+ 1;
1864 mpls_lock_get(g
->global_lock
); /* LOCK */
1865 while (done
== MPLS_BOOL_FALSE
) {
1866 switch ((r
= ldp_global_find_adj_index(g
, index
, &adj
))) {
1868 case MPLS_END_OF_LIST
:
1869 done
= MPLS_BOOL_TRUE
;
1878 mpls_lock_release(g
->global_lock
); /* UNLOCK */
1880 if (r
== MPLS_SUCCESS
) {
1881 a
->index
= adj
->index
;
1882 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1883 return ldp_cfg_adj_get(g
, a
, flag
);
1885 LDP_EXIT(g
->user_data
, "ldp_cfg_adj_getnext");
1889 /******************* SESSION **********************/
1891 mpls_return_enum
ldp_cfg_session_get(mpls_cfg_handle handle
, ldp_session
* s
,
1894 ldp_global
*global
= (ldp_global
*) handle
;
1895 ldp_session
*session
= NULL
;
1896 mpls_return_enum retval
= MPLS_FAILURE
;
1898 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
);
1900 LDP_ENTER(global
->user_data
, "ldp_cfg_session_get");
1902 mpls_lock_get(global
->global_lock
); /* LOCK */
1904 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
1905 goto ldp_cfg_session_get_end
;
1907 if (flag
& LDP_SESSION_CFG_STATE
) {
1908 s
->state
= session
->state
;
1910 if (flag
& LDP_SESSION_CFG_OPER_UP
) {
1911 s
->oper_up
= session
->oper_up
;
1913 if (flag
& LDP_SESSION_CFG_MAX_PDU
) {
1914 s
->oper_max_pdu
= session
->oper_max_pdu
;
1916 if (flag
& LDP_SESSION_CFG_KEEPALIVE
) {
1917 s
->oper_keepalive
= session
->oper_keepalive
;
1919 if (flag
& LDP_SESSION_CFG_PATH_LIMIT
) {
1920 s
->oper_path_vector_limit
= session
->oper_path_vector_limit
;
1922 if (flag
& LDP_SESSION_CFG_DIST_MODE
) {
1923 s
->oper_distribution_mode
= session
->oper_distribution_mode
;
1925 if (flag
& LDP_SESSION_CFG_LOOP_DETECTION
) {
1926 s
->oper_loop_detection
= session
->oper_loop_detection
;
1928 if (flag
& LDP_SESSION_CFG_REMOTE_MAX_PDU
) {
1929 s
->remote_max_pdu
= session
->remote_max_pdu
;
1931 if (flag
& LDP_SESSION_CFG_REMOTE_KEEPALIVE
) {
1932 s
->remote_keepalive
= session
->remote_keepalive
;
1934 if (flag
& LDP_SESSION_CFG_REMOTE_PATH_LIMIT
) {
1935 s
->remote_path_vector_limit
= session
->remote_path_vector_limit
;
1937 if (flag
& LDP_SESSION_CFG_REMOTE_DIST_MODE
) {
1938 s
->remote_distribution_mode
= session
->remote_distribution_mode
;
1940 if (flag
& LDP_SESSION_CFG_REMOTE_LOOP_DETECTION
) {
1941 s
->remote_loop_detection
= session
->remote_loop_detection
;
1943 if (flag
& LDP_SESSION_CFG_REMOTE_ADDR
) {
1944 s
->remote_dest
.addr
.type
= session
->remote_dest
.addr
.type
;
1945 s
->remote_dest
.addr
.u
.ipv4
= session
->remote_dest
.addr
.u
.ipv4
;
1947 if (flag
& LDP_SESSION_CFG_REMOTE_PORT
) {
1948 s
->remote_dest
.port
= session
->remote_dest
.port
;
1950 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_LOCAL
) {
1951 s
->no_label_resource_sent
= session
->no_label_resource_sent
;
1953 if (flag
& LDP_SESSION_CFG_LABEL_RESOURCE_STATE_REMOTE
) {
1954 s
->no_label_resource_recv
= session
->no_label_resource_recv
;
1956 if (flag
& LDP_SESSION_CFG_ADJ_INDEX
) {
1957 ldp_adj
*a
= MPLS_LIST_HEAD(&session
->adj_root
);
1958 s
->adj_index
= a
? a
->index
: 0;
1960 if (flag
& LDP_SESSION_CFG_MESG_TX
) {
1961 s
->mesg_tx
= session
->mesg_tx
;
1963 if (flag
& LDP_SESSION_CFG_MESG_RX
) {
1964 s
->mesg_rx
= session
->mesg_rx
;
1966 if (flag
& LDP_SESSION_CFG_LOCAL_NAME
) {
1967 if (mpls_socket_handle_verify(global
->socket_handle
,
1968 session
->socket
) == MPLS_BOOL_TRUE
) {
1969 mpls_socket_get_local_name(global
->socket_handle
, session
->socket
,
1973 if (flag
& LDP_SESSION_CFG_REMOTE_NAME
) {
1974 if (mpls_socket_handle_verify(global
->socket_handle
,
1975 session
->socket
) == MPLS_BOOL_TRUE
) {
1976 mpls_socket_get_remote_name(global
->socket_handle
, session
->socket
,
1980 retval
= MPLS_SUCCESS
;
1982 ldp_cfg_session_get_end
:
1983 mpls_lock_release(global
->global_lock
); /* UNLOCK */
1985 LDP_EXIT(global
->user_data
, "ldp_cfg_session_get");
1990 mpls_return_enum
ldp_cfg_session_getnext(mpls_cfg_handle handle
, ldp_session
* s
,
1993 ldp_global
*g
= (ldp_global
*) handle
;
1994 ldp_session
*ses
= NULL
;
1995 mpls_return_enum r
= MPLS_FAILURE
;
1996 mpls_bool done
= MPLS_BOOL_FALSE
;
1999 LDP_ENTER(g
->user_data
, "ldp_cfg_session_getnext");
2001 if (s
->index
== 0) {
2004 index
= s
->index
+ 1;
2007 mpls_lock_get(g
->global_lock
); /* LOCK */
2008 while (done
== MPLS_BOOL_FALSE
) {
2009 switch ((r
= ldp_global_find_session_index(g
, index
, &ses
))) {
2011 case MPLS_END_OF_LIST
:
2012 done
= MPLS_BOOL_TRUE
;
2021 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2023 if (r
== MPLS_SUCCESS
) {
2024 s
->index
= ses
->index
;
2026 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2027 return ldp_cfg_session_get(g
, s
, flag
);
2030 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2035 mpls_return_enum
ldp_cfg_session_adj_getnext(mpls_cfg_handle handle
,
2038 ldp_global
*g
= (ldp_global
*) handle
;
2039 mpls_bool this_one
= MPLS_BOOL_FALSE
;
2040 mpls_return_enum r
= MPLS_FAILURE
;
2041 ldp_adj
*adj_next
= NULL
;
2042 ldp_adj
*adj
= NULL
;
2043 ldp_session
*session
= NULL
;
2045 LDP_ENTER(g
->user_data
, "ldp_cfg_session_adj_getnext");
2047 /* if an adj_index of zero is sent, get the index of
2048 * the first adj in the list
2050 if (!s
->adj_index
) {
2051 this_one
= MPLS_BOOL_TRUE
;
2054 mpls_lock_get(g
->global_lock
); /* LOCK */
2056 if (ldp_global_find_session_index(g
, s
->index
, &session
) == MPLS_SUCCESS
) {
2057 adj
= MPLS_LIST_HEAD(&session
->adj_root
);
2059 if (this_one
== MPLS_BOOL_TRUE
) {
2064 /* since the entities are sort in the list ... */
2065 if (adj
->index
> s
->adj_index
) {
2067 } else if (adj
->index
== s
->adj_index
) {
2068 this_one
= MPLS_BOOL_TRUE
;
2070 adj
= MPLS_LIST_NEXT(&session
->adj_root
, adj
, _session
);
2073 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2076 s
->adj_index
= adj_next
->index
;
2080 LDP_EXIT(g
->user_data
, "ldp_cfg_session_adj_getnext");
2084 mpls_return_enum
ldp_cfg_session_raddr_get(mpls_cfg_handle handle
,
2085 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2087 ldp_global
*global
= (ldp_global
*) handle
;
2088 ldp_session
*session
= NULL
;
2089 ldp_addr
*addr
= NULL
;
2090 mpls_return_enum retval
= MPLS_FAILURE
;
2092 MPLS_ASSERT(global
!=NULL
&& s
!= NULL
&& a
!= NULL
);
2094 LDP_ENTER(global
->user_data
, "ldp_cfg_session_raddr_get");
2096 mpls_lock_get(global
->global_lock
); /* LOCK */
2098 if (ldp_global_find_session_index(global
, s
->index
, &session
) != MPLS_SUCCESS
)
2099 goto ldp_cfg_session_raddr_get_end
;
2101 if (ldp_session_find_raddr_index(session
, a
->index
, &addr
) != MPLS_SUCCESS
)
2102 goto ldp_cfg_session_raddr_get_end
;
2104 if (flag
& LDP_SESSION_RADDR_CFG_ADDR
) {
2105 memcpy(&a
->address
,&addr
->address
,sizeof(struct mpls_inet_addr
));
2107 if (flag
& LDP_SESSION_RADDR_CFG_INDEX
) {
2108 a
->index
= addr
->index
;
2110 retval
= MPLS_SUCCESS
;
2112 ldp_cfg_session_raddr_get_end
:
2113 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2115 LDP_EXIT(global
->user_data
, "ldp_cfg_session_raddr_get");
2120 mpls_return_enum
ldp_cfg_session_raddr_getnext(mpls_cfg_handle handle
,
2121 ldp_session
* s
, ldp_addr
* a
, uint32_t flag
)
2123 ldp_global
*g
= (ldp_global
*) handle
;
2124 ldp_addr
*addr
= NULL
;
2125 mpls_return_enum r
= MPLS_FAILURE
;
2126 mpls_bool done
= MPLS_BOOL_FALSE
;
2127 ldp_session
*sp
= NULL
;
2130 LDP_ENTER(g
->user_data
, "ldp_cfg_session_raddr_getnext");
2132 if (a
->index
== 0) {
2135 index
= a
->index
+ 1;
2138 r
= ldp_global_find_session_index(g
, s
->index
, &sp
);
2139 if (r
!= MPLS_SUCCESS
) {
2143 mpls_lock_get(g
->global_lock
); /* LOCK */
2144 while (done
== MPLS_BOOL_FALSE
) {
2145 switch ((r
= ldp_session_find_raddr_index(sp
, index
, &addr
))) {
2147 case MPLS_END_OF_LIST
:
2148 done
= MPLS_BOOL_TRUE
;
2157 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2159 if (r
== MPLS_SUCCESS
) {
2160 a
->index
= addr
->index
;
2161 r
= ldp_cfg_session_raddr_get(handle
, sp
, a
, flag
);
2164 LDP_EXIT(g
->user_data
, "ldp_cfg_session_getnext");
2168 /******************* IN LABEL **********************/
2170 mpls_return_enum
ldp_cfg_inlabel_get(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2173 ldp_global
*global
= (ldp_global
*) handle
;
2174 ldp_inlabel
*inlabel
= NULL
;
2175 mpls_return_enum retval
= MPLS_FAILURE
;
2177 MPLS_ASSERT(global
!=NULL
&& i
!= NULL
);
2179 LDP_ENTER(global
->user_data
, "ldp_cfg_inlabel_get");
2181 mpls_lock_get(global
->global_lock
); /* LOCK */
2183 if (ldp_global_find_inlabel_index(global
, i
->index
, &inlabel
) != MPLS_SUCCESS
)
2184 goto ldp_cfg_inlabel_get_end
;
2186 if (flag
& LDP_INLABEL_CFG_LABELSPACE
) {
2187 i
->info
.labelspace
= inlabel
->info
.labelspace
;
2189 if (flag
& LDP_INLABEL_CFG_LABEL
) {
2190 memcpy(&i
->info
.label
, &inlabel
->info
.label
, sizeof(mpls_label_struct
));
2192 if (flag
& LDP_INLABEL_CFG_OUTLABEL_INDEX
) {
2193 i
->outlabel_index
= (inlabel
->outlabel
) ? (inlabel
->outlabel
->index
) : 0;
2196 retval
= MPLS_SUCCESS
;
2198 ldp_cfg_inlabel_get_end
:
2199 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2201 LDP_EXIT(global
->user_data
, "ldp_cfg_inlabel_get");
2206 mpls_return_enum
ldp_cfg_inlabel_getnext(mpls_cfg_handle handle
, ldp_inlabel
* i
,
2209 ldp_global
*g
= (ldp_global
*) handle
;
2210 ldp_inlabel
*inlabel
= NULL
;
2211 mpls_return_enum r
= MPLS_FAILURE
;
2212 mpls_bool done
= MPLS_BOOL_FALSE
;
2215 LDP_ENTER(g
->user_data
, "ldp_cfg_inlabel_getnext");
2217 if (i
->index
== 0) {
2220 index
= i
->index
+ 1;
2223 mpls_lock_get(g
->global_lock
); /* LOCK */
2224 while (done
== MPLS_BOOL_FALSE
) {
2225 switch ((r
= ldp_global_find_inlabel_index(g
, index
, &inlabel
))) {
2227 case MPLS_END_OF_LIST
:
2228 done
= MPLS_BOOL_TRUE
;
2237 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2239 if (r
== MPLS_SUCCESS
) {
2240 i
->index
= inlabel
->index
;
2242 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2243 return ldp_cfg_inlabel_get(g
, i
, flag
);
2246 LDP_EXIT(g
->user_data
, "ldp_cfg_inlabel_getnext");
2251 /******************* OUT LABEL **********************/
2253 mpls_return_enum
ldp_cfg_outlabel_get(mpls_cfg_handle handle
, ldp_outlabel
* o
,
2256 ldp_global
*global
= (ldp_global
*) handle
;
2257 ldp_outlabel
*outlabel
= NULL
;
2258 mpls_return_enum retval
= MPLS_FAILURE
;
2260 MPLS_ASSERT(global
!=NULL
&& o
!= NULL
);
2262 LDP_ENTER(global
->user_data
, "ldp_cfg_outlabel_get");
2264 mpls_lock_get(global
->global_lock
); /* LOCK */
2266 if (ldp_global_find_outlabel_index(global
, o
->index
,
2267 &outlabel
) != MPLS_SUCCESS
) goto ldp_cfg_outlabel_get_end
;
2269 if (flag
& LDP_OUTLABEL_CFG_NH_INDEX
) {
2271 o
->nh_index
= outlabel
->nh
->index
;
2276 if (flag
& LDP_OUTLABEL_CFG_SESSION_INDEX
) {
2277 o
->session_index
= (outlabel
->session
) ? (outlabel
->session
->index
) : 0;
2279 if (flag
& LDP_OUTLABEL_CFG_LABEL
) {
2280 memcpy(&o
->info
.label
, &outlabel
->info
.label
, sizeof(mpls_label_struct
));
2282 if (flag
& LDP_OUTLABEL_CFG_MERGE_COUNT
) {
2283 o
->merge_count
= outlabel
->merge_count
;
2286 retval
= MPLS_SUCCESS
;
2288 ldp_cfg_outlabel_get_end
:
2289 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2291 LDP_EXIT(global
->user_data
, "ldp_cfg_outlabel_get");
2296 mpls_return_enum
ldp_cfg_outlabel_getnext(mpls_cfg_handle handle
,
2297 ldp_outlabel
* o
, uint32_t flag
)
2299 ldp_global
*g
= (ldp_global
*) handle
;
2300 ldp_outlabel
*outlabel
= NULL
;
2301 mpls_return_enum r
= MPLS_FAILURE
;
2302 mpls_bool done
= MPLS_BOOL_FALSE
;
2305 LDP_ENTER(g
->user_data
, "ldp_cfg_outlabel_getnext");
2307 if (o
->index
== 0) {
2310 index
= o
->index
+ 1;
2313 mpls_lock_get(g
->global_lock
); /* LOCK */
2314 while (done
== MPLS_BOOL_FALSE
) {
2315 switch ((r
= ldp_global_find_outlabel_index(g
, index
, &outlabel
))) {
2317 case MPLS_END_OF_LIST
:
2318 done
= MPLS_BOOL_TRUE
;
2327 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2329 if (r
== MPLS_SUCCESS
) {
2330 o
->index
= outlabel
->index
;
2332 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2333 return ldp_cfg_outlabel_get(g
, o
, flag
);
2336 LDP_EXIT(g
->user_data
, "ldp_cfg_outlabel_getnext");
2341 /******************* TUNNEL **********************/
2343 mpls_return_enum
ldp_cfg_tunnel_set(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2346 ldp_global
*global
= (ldp_global
*) handle
;
2347 mpls_return_enum retval
= MPLS_FAILURE
;
2348 ldp_tunnel
*tunnel
= NULL
;
2350 MPLS_ASSERT(global
!=NULL
);
2352 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_set");
2354 mpls_lock_get(global
->global_lock
); /* LOCK */
2356 if (flag
& LDP_CFG_ADD
) {
2357 if (!(tunnel
= ldp_tunnel_create())) {
2358 goto ldp_cfg_tunnel_set_end
;
2360 _ldp_global_add_tunnel(global
, tunnel
);
2362 t
->index
= tunnel
->index
;
2364 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2368 LDP_PRINT(global
->user_data
,
2370 "ldp_cfg_tunnel_set:could not create tunnel\n");
2371 goto ldp_cfg_tunnel_set_end
;
2374 if ((ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) &&
2375 (flag
& LDP_TUNNEL_CFG_WHEN_DOWN
)) {
2376 LDP_PRINT(global
->user_data
, "ldp_cfg_tunnel_set: tunnel is active\n");
2378 goto ldp_cfg_tunnel_set_end
;
2381 if (flag
& LDP_CFG_DEL
) {
2382 if (tunnel
->outlabel
)
2383 ldp_tunnel_del_outlabel(global
, tunnel
);
2384 if (tunnel
->resource
)
2385 ldp_tunnel_del_resource(tunnel
);
2386 if (tunnel
->hop_list
)
2387 ldp_tunnel_del_hop_list(tunnel
);
2388 _ldp_global_del_tunnel(global
, tunnel
);
2390 retval
= MPLS_SUCCESS
;
2391 goto ldp_cfg_tunnel_set_end
;
2394 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2395 memcpy(&tunnel
->ingress_lsrid
, &t
->ingress_lsrid
, sizeof(ldp_addr
));
2397 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2398 memcpy(&tunnel
->egress_lsrid
, &t
->egress_lsrid
, sizeof(ldp_addr
));
2400 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2401 memcpy(&tunnel
->name
, &t
->name
, MPLS_MAX_IF_NAME
);
2403 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2404 tunnel
->is_interface
= t
->is_interface
;
2406 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2407 ldp_outlabel
*outlabel
= NULL
;
2409 if (t
->outlabel_index
) {
2410 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2413 goto ldp_cfg_tunnel_set_end
;
2415 ldp_tunnel_add_outlabel(tunnel
, outlabel
);
2417 ldp_tunnel_del_outlabel(global
, tunnel
);
2420 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2421 tunnel
->setup_prio
= t
->setup_prio
;
2423 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2424 tunnel
->hold_prio
= t
->hold_prio
;
2426 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2427 tunnel
->instance_prio
= t
->instance_prio
;
2429 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2430 tunnel
->local_protect
= t
->local_protect
;
2432 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2433 ldp_resource
*resource
= NULL
;
2435 if (t
->resource_index
) {
2436 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2439 goto ldp_cfg_tunnel_set_end
;
2441 ldp_tunnel_add_resource(tunnel
, resource
);
2443 ldp_tunnel_del_resource(tunnel
);
2446 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2447 ldp_hop_list
*hop_list
= NULL
;
2449 if (t
->hop_list_index
) {
2450 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2453 goto ldp_cfg_tunnel_set_end
;
2455 ldp_tunnel_add_hop_list(tunnel
, hop_list
);
2457 ldp_tunnel_del_hop_list(tunnel
);
2460 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2461 memcpy(&tunnel
->fec
, &t
->fec
, sizeof(ldp_fec
));
2463 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2464 if (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_TRUE
) {
2465 if (t
->admin_state
== MPLS_ADMIN_DISABLE
) {
2466 if (ldp_tunnel_shutdown(global
, tunnel
, 0) == MPLS_FAILURE
) {
2467 goto ldp_cfg_tunnel_set_end
;
2471 if (t
->admin_state
== MPLS_ADMIN_ENABLE
) {
2472 if (ldp_tunnel_is_ready(tunnel
) == MPLS_BOOL_TRUE
) {
2473 if (ldp_tunnel_startup(global
, tunnel
) == MPLS_FAILURE
) {
2474 goto ldp_cfg_tunnel_set_end
;
2477 LDP_PRINT(global
->user_data
,
2479 "ldp_cfg_tunnel_set: tunnel not ready\n");
2480 goto ldp_cfg_tunnel_set_end
;
2485 retval
= MPLS_SUCCESS
;
2487 ldp_cfg_tunnel_set_end
:
2489 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2491 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_set");
2496 mpls_return_enum
ldp_cfg_tunnel_test(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2499 ldp_global
*global
= (ldp_global
*) handle
;
2500 mpls_return_enum retval
= MPLS_FAILURE
;
2501 ldp_tunnel
*tunnel
= NULL
;
2503 MPLS_ASSERT(global
!=NULL
);
2505 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_test");
2507 mpls_lock_get(global
->global_lock
); /* LOCK */
2509 if (flag
& LDP_CFG_ADD
) {
2510 retval
= MPLS_SUCCESS
;
2511 goto ldp_cfg_tunnel_test_end
;
2514 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2517 goto ldp_cfg_tunnel_test_end
;
2520 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2521 ldp_resource
*resource
= NULL
;
2523 if (t
->resource_index
) {
2524 ldp_global_find_resource_index(global
, t
->resource_index
, &resource
);
2527 goto ldp_cfg_tunnel_test_end
;
2531 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2532 ldp_hop_list
*hop_list
= NULL
;
2534 if (t
->hop_list_index
) {
2535 ldp_global_find_hop_list_index(global
, t
->hop_list_index
, &hop_list
);
2538 goto ldp_cfg_tunnel_test_end
;
2542 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2543 ldp_outlabel
*outlabel
= NULL
;
2545 if (t
->outlabel_index
) {
2546 ldp_global_find_outlabel_index(global
, t
->outlabel_index
, &outlabel
);
2549 goto ldp_cfg_tunnel_test_end
;
2553 if ((flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) &&
2554 (ldp_tunnel_is_active(tunnel
) == MPLS_BOOL_FALSE
) &&
2555 (t
->admin_state
== MPLS_ADMIN_ENABLE
) && (ldp_tunnel_is_ready(tunnel
) != MPLS_BOOL_TRUE
)) {
2556 goto ldp_cfg_tunnel_test_end
;
2558 retval
= MPLS_SUCCESS
;
2560 ldp_cfg_tunnel_test_end
:
2562 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2564 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_test");
2569 mpls_return_enum
ldp_cfg_tunnel_get(mpls_cfg_handle handle
, ldp_tunnel
* t
,
2572 ldp_global
*global
= (ldp_global
*) handle
;
2573 mpls_return_enum retval
= MPLS_FAILURE
;
2574 ldp_tunnel
*tunnel
= NULL
;
2576 MPLS_ASSERT(global
!=NULL
);
2578 LDP_ENTER(global
->user_data
, "ldp_cfg_tunnel_get");
2580 mpls_lock_get(global
->global_lock
); /* LOCK */
2582 ldp_global_find_tunnel_index(global
, t
->index
, &tunnel
);
2585 goto ldp_cfg_tunnel_get_end
;
2587 if (flag
& LDP_TUNNEL_CFG_INGRESS
) {
2588 memcpy(&t
->ingress_lsrid
, &tunnel
->ingress_lsrid
, sizeof(ldp_addr
));
2590 if (flag
& LDP_TUNNEL_CFG_EGRESS
) {
2591 memcpy(&t
->egress_lsrid
, &tunnel
->egress_lsrid
, sizeof(ldp_addr
));
2593 if (flag
& LDP_TUNNEL_CFG_NAME
) {
2594 memcpy(&t
->name
, &tunnel
->name
, MPLS_MAX_IF_NAME
);
2596 if (flag
& LDP_TUNNEL_CFG_IS_IF
) {
2597 t
->is_interface
= tunnel
->is_interface
;
2599 if (flag
& LDP_TUNNEL_CFG_OUTLABEL
) {
2600 if (tunnel
->outlabel
) {
2601 t
->outlabel_index
= tunnel
->outlabel
->index
;
2603 t
->outlabel_index
= 0;
2606 if (flag
& LDP_TUNNEL_CFG_SETUP_PRIO
) {
2607 t
->setup_prio
= tunnel
->setup_prio
;
2609 if (flag
& LDP_TUNNEL_CFG_HOLD_PRIO
) {
2610 t
->hold_prio
= tunnel
->hold_prio
;
2612 if (flag
& LDP_TUNNEL_CFG_INSTANCE_PRIO
) {
2613 tunnel
->instance_prio
= t
->instance_prio
;
2615 if (flag
& LDP_TUNNEL_CFG_LOCAL_PROTECT
) {
2616 tunnel
->local_protect
= t
->local_protect
;
2618 if (flag
& LDP_TUNNEL_CFG_RESOURCE_INDEX
) {
2619 if (tunnel
->resource
) {
2620 t
->resource_index
= tunnel
->resource
->index
;
2622 t
->resource_index
= 0;
2625 if (flag
& LDP_TUNNEL_CFG_HOP_LIST_INDEX
) {
2626 if (tunnel
->hop_list
) {
2627 t
->hop_list_index
= tunnel
->hop_list
->index
;
2629 t
->hop_list_index
= 0;
2632 if (flag
& LDP_TUNNEL_CFG_FEC
) {
2633 memcpy(&t
->fec
, &tunnel
->fec
, sizeof(ldp_fec
));
2635 if (flag
& LDP_TUNNEL_CFG_ADMIN_STATE
) {
2636 t
->admin_state
= tunnel
->admin_state
;
2638 retval
= MPLS_SUCCESS
;
2640 ldp_cfg_tunnel_get_end
:
2642 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2644 LDP_EXIT(global
->user_data
, "ldp_cfg_tunnel_get");
2649 mpls_return_enum
ldp_cfg_tunnel_getnext(mpls_cfg_handle handle
,
2650 ldp_tunnel
* r
, uint32_t flag
)
2652 ldp_global
*g
= (ldp_global
*) handle
;
2653 ldp_tunnel
*tunnel
= NULL
;
2654 mpls_return_enum ret
= MPLS_FAILURE
;
2655 mpls_bool done
= MPLS_BOOL_FALSE
;
2658 LDP_ENTER(g
->user_data
, "ldp_cfg_tunnel_getnext");
2660 if (r
->index
== 0) {
2663 index
= r
->index
+ 1;
2666 mpls_lock_get(g
->global_lock
); /* LOCK */
2667 while (done
== MPLS_BOOL_FALSE
) {
2668 switch ((ret
= ldp_global_find_tunnel_index(g
, index
, &tunnel
))) {
2670 case MPLS_END_OF_LIST
:
2671 done
= MPLS_BOOL_TRUE
;
2680 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2682 if (ret
== MPLS_SUCCESS
) {
2683 r
->index
= tunnel
->index
;
2685 LDP_EXIT(g
->user_data
, "ldp_cfg_tunnel_getnext");
2686 return ldp_cfg_tunnel_get(g
, r
, flag
);
2689 LDP_EXIT(g
->user_data
, "ldp_cfg_tunnel_getnext");
2694 /******************* RESOURCE **********************/
2696 mpls_return_enum
ldp_cfg_resource_set(mpls_cfg_handle handle
, ldp_resource
* r
,
2699 ldp_global
*global
= (ldp_global
*) handle
;
2700 mpls_return_enum retval
= MPLS_FAILURE
;
2701 ldp_resource
*resource
= NULL
;
2703 MPLS_ASSERT(global
!=NULL
);
2705 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_set");
2707 mpls_lock_get(global
->global_lock
); /* LOCK */
2709 if (flag
& LDP_CFG_ADD
) {
2710 resource
= ldp_resource_create();
2711 _ldp_global_add_resource(global
, resource
);
2713 r
->index
= resource
->index
;
2715 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2719 goto ldp_cfg_resource_set_end
;
2722 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2723 resource
->max_rate
= r
->max_rate
;
2725 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2726 resource
->mean_rate
= r
->mean_rate
;
2728 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2729 resource
->burst_size
= r
->burst_size
;
2731 retval
= MPLS_SUCCESS
;
2733 ldp_cfg_resource_set_end
:
2735 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2737 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_set");
2742 mpls_return_enum
ldp_cfg_resource_test(mpls_cfg_handle handle
, ldp_resource
* r
,
2745 ldp_global
*global
= (ldp_global
*) handle
;
2746 mpls_return_enum retval
= MPLS_FAILURE
;
2747 ldp_resource
*resource
= NULL
;
2749 MPLS_ASSERT(global
!=NULL
);
2751 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_test");
2753 mpls_lock_get(global
->global_lock
); /* LOCK */
2755 if (flag
& LDP_CFG_ADD
) {
2756 retval
= MPLS_SUCCESS
;
2757 goto ldp_cfg_resource_test_end
;
2760 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2763 goto ldp_cfg_resource_test_end
;
2766 if (ldp_resource_in_use(resource
) == MPLS_BOOL_TRUE
) {
2767 goto ldp_cfg_resource_test_end
;
2769 retval
= MPLS_SUCCESS
;
2771 ldp_cfg_resource_test_end
:
2773 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2775 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_test");
2780 mpls_return_enum
ldp_cfg_resource_get(mpls_cfg_handle handle
, ldp_resource
* r
,
2783 ldp_global
*global
= (ldp_global
*) handle
;
2784 mpls_return_enum retval
= MPLS_FAILURE
;
2785 ldp_resource
*resource
= NULL
;
2787 MPLS_ASSERT(global
!=NULL
);
2789 LDP_ENTER(global
->user_data
, "ldp_cfg_resource_get");
2791 mpls_lock_get(global
->global_lock
); /* LOCK */
2793 ldp_global_find_resource_index(global
, r
->index
, &resource
);
2796 goto ldp_cfg_resource_get_end
;
2799 if (flag
& LDP_RESOURCE_CFG_MAXBPS
) {
2800 r
->max_rate
= resource
->max_rate
;
2802 if (flag
& LDP_RESOURCE_CFG_MEANBPS
) {
2803 r
->mean_rate
= resource
->mean_rate
;
2805 if (flag
& LDP_RESOURCE_CFG_BURSTSIZE
) {
2806 r
->burst_size
= resource
->burst_size
;
2808 retval
= MPLS_SUCCESS
;
2810 ldp_cfg_resource_get_end
:
2812 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2814 LDP_EXIT(global
->user_data
, "ldp_cfg_resource_get");
2819 mpls_return_enum
ldp_cfg_resource_getnext(mpls_cfg_handle handle
,
2820 ldp_resource
* r
, uint32_t flag
)
2822 ldp_global
*g
= (ldp_global
*) handle
;
2823 ldp_resource
*resource
= NULL
;
2824 mpls_return_enum ret
= MPLS_FAILURE
;
2825 mpls_bool done
= MPLS_BOOL_FALSE
;
2828 LDP_ENTER(g
->user_data
, "ldp_cfg_resource_getnext");
2830 if (r
->index
== 0) {
2833 index
= r
->index
+ 1;
2836 mpls_lock_get(g
->global_lock
); /* LOCK */
2837 while (done
== MPLS_BOOL_FALSE
) {
2838 switch ((ret
= ldp_global_find_resource_index(g
, index
, &resource
))) {
2840 case MPLS_END_OF_LIST
:
2841 done
= MPLS_BOOL_TRUE
;
2850 mpls_lock_release(g
->global_lock
); /* UNLOCK */
2852 if (ret
== MPLS_SUCCESS
) {
2853 r
->index
= resource
->index
;
2855 LDP_EXIT(g
->user_data
, "ldp_cfg_resource_getnext");
2856 return ldp_cfg_resource_get(g
, r
, flag
);
2859 LDP_EXIT(g
->user_data
, "ldp_cfg_resource_getnext");
2864 /******************* HOP **********************/
2866 mpls_return_enum
ldp_cfg_hop_set(mpls_cfg_handle handle
, ldp_hop
* h
,
2869 ldp_global
*global
= (ldp_global
*) handle
;
2870 mpls_return_enum retval
= MPLS_FAILURE
;
2871 ldp_hop_list
*hop_list
= NULL
;
2872 ldp_hop
*hop
= NULL
;
2874 MPLS_ASSERT(global
!=NULL
);
2876 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_set");
2878 if (!h
->hop_list_index
&& !h
->index
) {
2882 mpls_lock_get(global
->global_lock
); /* LOCK */
2884 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2887 if (flag
& LDP_CFG_ADD
) {
2888 if (!(hop_list
= ldp_hop_list_create())) {
2889 goto ldp_cfg_hop_set_end
;
2891 _ldp_global_add_hop_list(global
, hop_list
);
2893 h
->hop_list_index
= hop_list
->index
;
2895 goto ldp_cfg_hop_set_end
;
2899 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2901 if (h
->index
&& (flag
& LDP_CFG_ADD
)) {
2902 if (!(hop
= ldp_hop_create())) {
2903 goto ldp_cfg_hop_set_end
;
2905 hop
->index
= h
->index
;
2906 ldp_hop_list_add_hop(hop_list
, hop
);
2908 goto ldp_cfg_hop_set_end
;
2912 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
2913 hop
->path_option
= h
->path_option
;
2915 if (flag
& LDP_HOP_CFG_ADDR
) {
2916 memcpy(&hop
->addr
, &h
->addr
, sizeof(ldp_addr
));
2918 if (flag
& LDP_HOP_CFG_TYPE
) {
2919 hop
->type
= h
->type
;
2921 retval
= MPLS_SUCCESS
;
2923 ldp_cfg_hop_set_end
:
2925 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2927 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_set");
2932 mpls_return_enum
ldp_cfg_hop_test(mpls_cfg_handle handle
, ldp_hop
* h
,
2935 ldp_global
*global
= (ldp_global
*) handle
;
2936 mpls_return_enum retval
= MPLS_FAILURE
;
2937 ldp_hop_list
*hop_list
= NULL
;
2938 ldp_hop
*hop
= NULL
;
2940 MPLS_ASSERT(global
!=NULL
);
2942 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_test");
2944 mpls_lock_get(global
->global_lock
); /* LOCK */
2946 if (flag
& LDP_CFG_ADD
) {
2947 retval
= MPLS_SUCCESS
;
2948 goto ldp_cfg_hop_test_end
;
2951 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2954 goto ldp_cfg_hop_test_end
;
2957 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2959 goto ldp_cfg_hop_test_end
;
2962 if (ldp_hop_in_use(hop
) == MPLS_BOOL_TRUE
) {
2963 goto ldp_cfg_hop_test_end
;
2965 retval
= MPLS_SUCCESS
;
2967 ldp_cfg_hop_test_end
:
2969 mpls_lock_release(global
->global_lock
); /* UNLOCK */
2971 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_test");
2976 mpls_return_enum
ldp_cfg_hop_get(mpls_cfg_handle handle
, ldp_hop
* h
,
2979 ldp_global
*global
= (ldp_global
*) handle
;
2980 mpls_return_enum retval
= MPLS_FAILURE
;
2981 ldp_hop_list
*hop_list
= NULL
;
2982 ldp_hop
*hop
= NULL
;
2984 MPLS_ASSERT(global
!=NULL
);
2986 LDP_ENTER(global
->user_data
, "ldp_cfg_hop_get");
2988 mpls_lock_get(global
->global_lock
); /* LOCK */
2990 ldp_global_find_hop_list_index(global
, h
->hop_list_index
, &hop_list
);
2993 goto ldp_cfg_hop_get_end
;
2996 ldp_hop_list_find_hop_index(hop_list
, h
->index
, &hop
);
2998 goto ldp_cfg_hop_get_end
;
3001 if (flag
& LDP_HOP_CFG_PATH_OPTION
) {
3002 h
->path_option
= hop
->path_option
;
3004 if (flag
& LDP_HOP_CFG_ADDR
) {
3005 memcpy(&h
->addr
, &hop
->addr
, sizeof(ldp_addr
));
3007 if (flag
& LDP_HOP_CFG_TYPE
) {
3008 h
->type
= hop
->type
;
3010 retval
= MPLS_SUCCESS
;
3012 ldp_cfg_hop_get_end
:
3014 mpls_lock_release(global
->global_lock
); /* UNLOCK */
3016 LDP_EXIT(global
->user_data
, "ldp_cfg_hop_get");
3021 /******************* NEXTHOP **********************/
3022 mpls_return_enum
ldp_cfg_nexthop_get(mpls_cfg_handle handle
, ldp_nexthop
* n
,
3025 ldp_global
*global
= (ldp_global
*) handle
;
3026 ldp_nexthop
*nexthop
= NULL
;
3027 mpls_return_enum retval
= MPLS_FAILURE
;
3029 MPLS_ASSERT(global
!=NULL
&& n
!= NULL
);
3031 LDP_ENTER(global
->user_data
, "ldp_cfg_nexthop_get");
3033 mpls_lock_get(global
->global_lock
); /* LOCK */
3035 if (ldp_global_find_nexthop_index(global
, n
->index
, &nexthop
) != MPLS_SUCCESS
)
3036 goto ldp_cfg_nexthop_get_end
;
3039 n
->fec_index
= nexthop
->fec
->index
;
3041 n
->addr_index
= nexthop
->addr
->index
;
3042 if (nexthop
->outlabel
)
3043 n
->outlabel_index
= nexthop
->outlabel
->index
;
3045 n
->if_index
= nexthop
->iff
->index
;
3047 memcpy (&n
->info
, &nexthop
->info
, sizeof(nexthop
->info
));
3049 retval
= MPLS_SUCCESS
;
3051 ldp_cfg_nexthop_get_end
:
3052 mpls_lock_release(global
->global_lock
); /* UNLOCK */
3054 LDP_EXIT(global
->user_data
, "ldp_cfg_nexthop_get");
3059 mpls_return_enum
ldp_cfg_nexthop_getnext(mpls_cfg_handle handle
, ldp_nexthop
* n
,
3062 ldp_global
*g
= (ldp_global
*) handle
;
3063 ldp_nexthop
*ses
= NULL
;
3064 mpls_return_enum r
= MPLS_FAILURE
;
3065 mpls_bool done
= MPLS_BOOL_FALSE
;
3068 LDP_ENTER(g
->user_data
, "ldp_cfg_nexthop_getnext");
3070 if (n
->index
== 0) {
3073 index
= n
->index
+ 1;
3076 mpls_lock_get(g
->global_lock
); /* LOCK */
3077 while (done
== MPLS_BOOL_FALSE
) {
3078 switch ((r
= ldp_global_find_nexthop_index(g
, index
, &ses
))) {
3080 case MPLS_END_OF_LIST
:
3081 done
= MPLS_BOOL_TRUE
;
3090 mpls_lock_release(g
->global_lock
); /* UNLOCK */
3092 if (r
== MPLS_SUCCESS
) {
3093 n
->index
= ses
->index
;
3095 LDP_EXIT(g
->user_data
, "ldp_cfg_nexthop_getnext");
3096 return ldp_cfg_nexthop_get(g
, n
, flag
);
3099 LDP_EXIT(g
->user_data
, "ldp_cfg_nexthop_getnext");