Misc debug code
[mpls-ldp-portable.git] / lsr / lsr_cfg.c
bloba8ce6ab47ea77e68f31171688a5507e18debe6a5
2 /*
3 * Copyright (C) James R. Leu 2002
4 * jleu@mindspring.com
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
8 */
10 #include "lsr_struct.h"
11 #include "lsr_cfg.h"
12 #include "lsr_global.h"
13 #include "lsr_outsegment.h"
14 #include "lsr_insegment.h"
15 #include "lsr_xconnect.h"
16 #include "lsr_if.h"
17 #include "lsr_ftn.h"
19 #include "mpls_mm_impl.h"
20 #include "mpls_mpls_impl.h"
21 #include "mpls_ifmgr_impl.h"
22 #include "mpls_lock_impl.h"
23 #include "mpls_trace_impl.h"
25 mpls_cfg_handle lsr_cfg_open(mpls_instance_handle data)
27 lsr_global *g = NULL;
29 LDP_ENTER(data, "lsr_cfg_open");
30 g = lsr_global_create(data);
31 LDP_EXIT(data, "lsr_cfg_open");
33 return (mpls_cfg_handle) g;
36 void lsr_cfg_close(mpls_cfg_handle g)
38 LDP_ENTER((mpls_instance_handle) g->user_data, "lsr_cfg_close");
39 lsr_global_delete(g);
40 LDP_EXIT((mpls_instance_handle) g->user_data, "lsr_cfg_close");
43 /******************* GLOBAL **********************/
45 mpls_return_enum lsr_cfg_global_get(mpls_cfg_handle handle, lsr_global * g,
46 uint32_t flag)
48 lsr_global *global = (lsr_global *) handle;
50 MPLS_ASSERT(global !=NULL);
52 LDP_ENTER(global->user_data, "lsr_cfg_global_get");
54 mpls_lock_get(global->global_lock); /* LOCK */
56 if (flag & LSR_GLOBAL_CFG_ADMIN_STATE) {
57 g->admin_state = global->admin_state;
60 mpls_lock_release(global->global_lock); /* UNLOCK */
62 LDP_EXIT(global->user_data, "lsr_cfg_global_get");
64 return MPLS_SUCCESS;
67 mpls_return_enum lsr_cfg_global_test(mpls_cfg_handle handle, lsr_global * g,
68 uint32_t flag)
70 lsr_global *global = (lsr_global *) handle;
71 mpls_return_enum retval = MPLS_SUCCESS;
73 MPLS_ASSERT(global !=NULL);
75 LDP_ENTER(global->user_data, "lsr_cfg_global_test");
77 mpls_lock_get(global->global_lock); /* LOCK */
79 if ((global->admin_state == MPLS_ADMIN_ENABLE) &&
80 (flag & LSR_GLOBAL_CFG_WHEN_DOWN))
81 retval = MPLS_FAILURE;
83 mpls_lock_release(global->global_lock); /* UNLOCK */
85 LDP_EXIT(global->user_data, "lsr_cfg_global_test");
87 return retval;
90 mpls_return_enum lsr_cfg_global_set(mpls_cfg_handle handle, lsr_global * g,
91 uint32_t flag)
93 lsr_global *global = (lsr_global *) handle;
94 mpls_return_enum retval = MPLS_FAILURE;
96 MPLS_ASSERT(global !=NULL);
98 LDP_ENTER(global->user_data, "lsr_cfg_global_set");
100 mpls_lock_get(global->global_lock); /* LOCK */
102 if ((global->admin_state == MPLS_ADMIN_ENABLE) &&
103 (flag & LSR_GLOBAL_CFG_WHEN_DOWN))
104 goto lsr_cfg_global_set_end;
106 if (flag & LSR_GLOBAL_CFG_ADMIN_STATE) {
107 if ((global->admin_state == MPLS_ADMIN_ENABLE) &&
108 (g->admin_state == MPLS_ADMIN_DISABLE)) {
109 lsr_global_shutdown(global);
110 } else if ((global->admin_state == MPLS_ADMIN_DISABLE) &&
111 (g->admin_state == MPLS_ADMIN_ENABLE)) {
112 lsr_global_startup(global);
116 retval = MPLS_SUCCESS;
118 lsr_cfg_global_set_end:
120 mpls_lock_release(global->global_lock); /* UNLOCK */
122 LDP_EXIT(global->user_data, "lsr_cfg_global_set");
124 return retval;
127 /******************* OUTSEGMENT **********************/
129 mpls_return_enum lsr_cfg_outsegment_get(mpls_cfg_handle handle, lsr_outsegment * o, uint32_t flag)
131 lsr_global *global = (lsr_global *) handle;
132 lsr_outsegment *oseg = NULL;
133 mpls_return_enum retval = MPLS_FAILURE;
135 MPLS_ASSERT(global !=NULL && o != NULL);
137 LDP_ENTER(global->user_data, "lsr_cfg_outsegment_get");
139 mpls_lock_get(global->global_lock); /* LOCK */
141 if (lsr_global_find_outsegment_index(global, o->index, &oseg) != MPLS_SUCCESS)
142 goto lsr_cfg_outsegment_get_end;
144 if (LSR_OUTSEGMENT_CFG_INDEX & flag) {
145 o->index = oseg->index;
147 if (LSR_OUTSEGMENT_CFG_PUSH_LABEL & flag) {
148 o->info.push_label = oseg->info.push_label;
150 if (LSR_OUTSEGMENT_CFG_OWNER & flag) {
151 o->info.owner = oseg->info.owner;
153 if (LSR_OUTSEGMENT_CFG_INTERFACE & flag) {
154 o->if_index = oseg->iff ? oseg->iff->index : 0;
156 if (LSR_OUTSEGMENT_CFG_LABEL & flag) {
157 memcpy(&o->info.label, &oseg->info.label, sizeof(mpls_label_struct));
159 if (LSR_OUTSEGMENT_CFG_NEXTHOP & flag) {
160 memcpy(&o->info.nexthop, &oseg->info.nexthop, sizeof(mpls_nexthop));
163 retval = MPLS_SUCCESS;
165 lsr_cfg_outsegment_get_end:
166 mpls_lock_release(global->global_lock); /* UNLOCK */
168 LDP_EXIT(global->user_data, "lsr_cfg_outsegment_get");
170 return retval;
173 mpls_return_enum lsr_cfg_outsegment_getnext(mpls_cfg_handle handle, lsr_outsegment * i,
174 uint32_t flag)
176 lsr_global *g = (lsr_global *) handle;
177 lsr_outsegment *oseg = NULL;
178 mpls_return_enum r = MPLS_FAILURE;
179 mpls_bool done = MPLS_BOOL_FALSE;
180 int index;
182 LDP_ENTER(g->user_data, "lsr_cfg_outsegment_getnext");
184 if (i->index == 0) {
185 index = 1;
186 } else {
187 index = i->index + 1;
190 mpls_lock_get(g->global_lock); /* LOCK */
191 while (done == MPLS_BOOL_FALSE) {
192 switch ((r = lsr_global_find_outsegment_index(g, index, &oseg))) {
193 case MPLS_SUCCESS:
194 case MPLS_END_OF_LIST:
195 done = MPLS_BOOL_TRUE;
196 break;
197 case MPLS_FAILURE:
198 break;
199 default:
200 MPLS_ASSERT(0);
202 index++;
204 mpls_lock_release(g->global_lock); /* UNLOCK */
206 if (r == MPLS_SUCCESS) {
207 i->index = oseg->index;
208 LDP_EXIT(g->user_data, "lsr_cfg_outsegment_getnext");
209 return lsr_cfg_outsegment_get(g, i, flag);
211 LDP_EXIT(g->user_data, "lsr_cfg_outsegment_getnext");
212 return r;
215 mpls_return_enum lsr_cfg_outsegment_test(mpls_cfg_handle handle, lsr_outsegment * i,
216 uint32_t flag)
218 lsr_global *global = (lsr_global *) handle;
219 lsr_outsegment *oseg = NULL;
220 mpls_return_enum retval = MPLS_FAILURE;
222 MPLS_ASSERT(global !=NULL && i != NULL);
224 LDP_ENTER(global->user_data, "lsr_cfg_outsegment_test");
226 mpls_lock_get(global->global_lock); /* LOCK */
228 if (!(flag & LSR_CFG_ADD)) {
229 lsr_global_find_outsegment_index(global, i->index, &oseg);
230 } else {
231 retval = MPLS_SUCCESS;
232 goto lsr_cfg_outsegment_test_end;
235 retval = MPLS_SUCCESS;
237 lsr_cfg_outsegment_test_end:
238 mpls_lock_release(global->global_lock); /* UNLOCK */
240 LDP_EXIT(global->user_data, "lsr_cfg_outsegment_test");
242 return retval;
245 mpls_return_enum lsr_cfg_outsegment_set(mpls_cfg_handle handle, lsr_outsegment * o, uint32_t flag)
247 lsr_global *global = (lsr_global*)handle;
248 lsr_outsegment *oseg = NULL;
249 mpls_return_enum retval = MPLS_FAILURE;
251 MPLS_ASSERT(global !=NULL && o != NULL);
253 LDP_ENTER(global->user_data, "lsr_cfg_outsegment_set");
255 mpls_lock_get(global->global_lock); /* LOCK */
257 if (flag & LSR_CFG_ADD) {
258 if ((oseg = lsr_outsegment_create()) == NULL) {
259 goto lsr_cfg_outsegment_set_end;
261 o->index = oseg->index;
262 } else {
263 lsr_global_find_outsegment_index(global, o->index, &oseg);
266 if (oseg == NULL)
267 goto lsr_cfg_outsegment_set_end;
269 if (flag & LSR_CFG_DEL) {
270 _lsr_global_del_outsegment(global, oseg);
271 mpls_mpls_outsegment_del(global->mpls_handle,&oseg->info);
272 retval = MPLS_SUCCESS;
273 goto lsr_cfg_outsegment_set_end;
276 if (LSR_OUTSEGMENT_CFG_PUSH_LABEL & flag) {
277 oseg->info.push_label = o->info.push_label;
279 if (LSR_OUTSEGMENT_CFG_OWNER & flag) {
280 oseg->info.owner = o->info.owner;
282 if (LSR_OUTSEGMENT_CFG_INTERFACE & flag) {
283 lsr_if *iff = NULL;
284 if (lsr_global_find_if_index(global, o->if_index, &iff) == MPLS_SUCCESS) {
285 lsr_if_add_outsegment(iff,oseg);
288 if (LSR_OUTSEGMENT_CFG_LABEL & flag) {
289 memcpy(&oseg->info.label, &o->info.label, sizeof(mpls_label_struct));
291 if (LSR_OUTSEGMENT_CFG_NEXTHOP & flag) {
292 memcpy(&oseg->info.nexthop, &o->info.nexthop, sizeof(mpls_nexthop));
295 retval = MPLS_SUCCESS;
297 if (flag & LSR_CFG_ADD) {
298 retval = mpls_mpls_outsegment_add(global->mpls_handle,&oseg->info);
299 if (retval == MPLS_SUCCESS) {
300 _lsr_global_add_outsegment(global, oseg);
304 lsr_cfg_outsegment_set_end:
305 mpls_lock_release(global->global_lock); /* UNLOCK */
307 LDP_EXIT(global->user_data, "lsr_cfg_outsegment_set");
309 return retval;
311 /******************* INSEGMENT **********************/
313 mpls_return_enum lsr_cfg_insegment_get(mpls_cfg_handle handle, lsr_insegment * i, uint32_t flag)
315 lsr_global *global = (lsr_global *) handle;
316 lsr_insegment *iseg = NULL;
317 mpls_return_enum retval = MPLS_FAILURE;
319 MPLS_ASSERT(global !=NULL && i != NULL);
321 LDP_ENTER(global->user_data, "lsr_cfg_insegment_get");
323 mpls_lock_get(global->global_lock); /* LOCK */
325 if (lsr_global_find_insegment_index(global, i->index, &iseg) != MPLS_SUCCESS)
326 goto lsr_cfg_insegment_get_end;
328 if (LSR_INSEGMENT_CFG_INDEX & flag) {
329 i->index = iseg->index;
331 if (LSR_INSEGMENT_CFG_NPOP & flag) {
332 i->info.npop = iseg->info.npop;
334 if (LSR_INSEGMENT_CFG_FAMILY & flag) {
335 i->info.family = iseg->info.family;
337 if (LSR_INSEGMENT_CFG_LABELSPACE & flag) {
338 i->info.labelspace = iseg->info.labelspace;
340 if (LSR_INSEGMENT_CFG_LABEL & flag) {
341 memcpy(&i->info.label, &iseg->info.label, sizeof(mpls_label_struct));
343 if (LSR_INSEGMENT_CFG_OWNER & flag) {
344 i->info.owner = iseg->info.owner;
347 retval = MPLS_SUCCESS;
349 lsr_cfg_insegment_get_end:
350 mpls_lock_release(global->global_lock); /* UNLOCK */
352 LDP_EXIT(global->user_data, "lsr_cfg_insegment_get");
354 return retval;
357 mpls_return_enum lsr_cfg_insegment_getnext(mpls_cfg_handle handle, lsr_insegment * i,
358 uint32_t flag)
360 lsr_global *g = (lsr_global *) handle;
361 lsr_insegment *iseg = NULL;
362 mpls_return_enum r = MPLS_FAILURE;
363 mpls_bool done = MPLS_BOOL_FALSE;
364 int index;
366 LDP_ENTER(g->user_data, "lsr_cfg_insegment_getnext");
368 if (i->index == 0) {
369 index = 1;
370 } else {
371 index = i->index + 1;
374 mpls_lock_get(g->global_lock); /* LOCK */
375 while (done == MPLS_BOOL_FALSE) {
376 switch ((r = lsr_global_find_insegment_index(g, index, &iseg))) {
377 case MPLS_SUCCESS:
378 case MPLS_END_OF_LIST:
379 done = MPLS_BOOL_TRUE;
380 break;
381 case MPLS_FAILURE:
382 break;
383 default:
384 MPLS_ASSERT(0);
386 index++;
388 mpls_lock_release(g->global_lock); /* UNLOCK */
390 if (r == MPLS_SUCCESS) {
391 i->index = iseg->index;
392 LDP_EXIT(g->user_data, "lsr_cfg_insegment_getnext");
393 return lsr_cfg_insegment_get(g, i, flag);
395 LDP_EXIT(g->user_data, "lsr_cfg_insegment_getnext");
396 return r;
399 mpls_return_enum lsr_cfg_insegment_test(mpls_cfg_handle handle, lsr_insegment * i,
400 uint32_t flag)
402 lsr_global *global = (lsr_global *) handle;
403 lsr_insegment *iseg = NULL;
404 mpls_return_enum retval = MPLS_FAILURE;
406 MPLS_ASSERT(global !=NULL && i != NULL);
408 LDP_ENTER(global->user_data, "lsr_cfg_insegment_test");
410 mpls_lock_get(global->global_lock); /* LOCK */
412 if (!(flag & LSR_CFG_ADD)) {
413 lsr_global_find_insegment_index(global, i->index, &iseg);
414 } else {
415 retval = MPLS_SUCCESS;
416 goto lsr_cfg_insegment_test_end;
419 retval = MPLS_SUCCESS;
421 lsr_cfg_insegment_test_end:
422 mpls_lock_release(global->global_lock); /* UNLOCK */
424 LDP_EXIT(global->user_data, "lsr_cfg_insegment_test");
426 return retval;
429 mpls_return_enum lsr_cfg_insegment_set(mpls_cfg_handle handle, lsr_insegment * i, uint32_t flag)
431 lsr_global *global = (lsr_global*)handle;
432 lsr_insegment *iseg = NULL;
433 mpls_return_enum retval = MPLS_FAILURE;
435 MPLS_ASSERT(global !=NULL && i != NULL);
437 LDP_ENTER(global->user_data, "lsr_cfg_insegment_set");
439 mpls_lock_get(global->global_lock); /* LOCK */
441 if (flag & LSR_CFG_ADD) {
442 if ((iseg = lsr_insegment_create()) == NULL) {
443 goto lsr_cfg_insegment_set_end;
445 i->index = iseg->index;
446 } else {
447 lsr_global_find_insegment_index(global, i->index, &iseg);
450 if (iseg == NULL)
451 goto lsr_cfg_insegment_set_end;
453 if (flag & LSR_CFG_DEL) {
455 mpls_mpls_insegment_del(global->mpls_handle,&iseg->info);
456 _lsr_global_del_insegment(global, iseg);
458 retval = MPLS_SUCCESS;
459 goto lsr_cfg_insegment_set_end;
462 if (LSR_INSEGMENT_CFG_NPOP & flag) {
463 iseg->info.npop = i->info.npop;
465 if (LSR_INSEGMENT_CFG_FAMILY & flag) {
466 iseg->info.family = i->info.family;
468 if (LSR_INSEGMENT_CFG_LABELSPACE & flag) {
469 iseg->info.labelspace = i->info.labelspace;
471 if (LSR_INSEGMENT_CFG_LABEL & flag) {
472 memcpy(&iseg->info.label, &i->info.label, sizeof(mpls_label_struct));
474 if (LSR_INSEGMENT_CFG_OWNER & flag) {
475 iseg->info.owner = i->info.owner;
478 retval = MPLS_SUCCESS;
480 if (flag & LSR_CFG_ADD) {
481 retval = mpls_mpls_insegment_add(global->mpls_handle,&iseg->info);
482 if (retval == MPLS_SUCCESS) {
483 memcpy(&i->info.label, &iseg->info.label, sizeof(mpls_label_struct));
484 _lsr_global_add_insegment(global, iseg);
488 lsr_cfg_insegment_set_end:
489 mpls_lock_release(global->global_lock); /* UNLOCK */
491 LDP_EXIT(global->user_data, "lsr_cfg_insegment_set");
493 return retval;
495 /******************* XCONNECT **********************/
497 void do_lsr_cfg_xconnect_get(lsr_xconnect * x, lsr_xconnect * xcon,
498 uint32_t flag)
500 if (LSR_XCONNECT_CFG_INDEX & flag) {
501 x->index = xcon->index;
503 if (LSR_XCONNECT_CFG_OUTSEGMENT & flag) {
504 x->outsegment_index = xcon->outsegment ? xcon->outsegment->index : 0;
506 if (LSR_XCONNECT_CFG_INSEGMENT & flag) {
507 x->insegment_index = xcon->insegment->index;
509 if (LSR_XCONNECT_CFG_LSPID & flag) {
510 x->info.lspid = xcon->info.lspid;
512 if (LSR_XCONNECT_CFG_LABELSTACK & flag) {
513 x->info.stack_size = xcon->info.stack_size;
514 memcpy(x->info.stack,xcon->info.stack,
515 sizeof(mpls_label_struct) * xcon->info.stack_size);
517 if (LSR_XCONNECT_CFG_OWNER & flag) {
518 x->info.owner = xcon->info.owner;
522 mpls_return_enum lsr_cfg_xconnect_get(mpls_cfg_handle handle, lsr_xconnect * x, uint32_t flag)
524 lsr_global *global = (lsr_global *) handle;
525 lsr_xconnect *xcon = NULL;
526 mpls_return_enum retval = MPLS_FAILURE;
528 MPLS_ASSERT(global !=NULL && x != NULL);
530 LDP_ENTER(global->user_data, "lsr_cfg_xconnect_get");
532 mpls_lock_get(global->global_lock); /* LOCK */
534 if (lsr_global_find_xconnect_index(global, x->index, &xcon) != MPLS_SUCCESS)
535 goto lsr_cfg_xconnect_get_end;
537 do_lsr_cfg_xconnect_get(x, xcon, flag);
539 retval = MPLS_SUCCESS;
541 lsr_cfg_xconnect_get_end:
542 mpls_lock_release(global->global_lock); /* UNLOCK */
544 LDP_EXIT(global->user_data, "lsr_cfg_xconnect_get");
546 return retval;
549 mpls_return_enum lsr_cfg_xconnect_get2(mpls_cfg_handle handle, lsr_xconnect *x, uint32_t flag)
551 lsr_global *global = (lsr_global *) handle;
552 lsr_xconnect *xcon = NULL;
553 mpls_return_enum retval = MPLS_FAILURE;
555 MPLS_ASSERT(global !=NULL && x != NULL);
557 LDP_ENTER(global->user_data, "lsr_cfg_xconnect_get2");
559 mpls_lock_get(global->global_lock); /* LOCK */
561 if (lsr_global_find_xconnect_index2(global, x->insegment_index,
562 x->outsegment_index, &xcon) != MPLS_SUCCESS)
563 goto lsr_cfg_xconnect_get_end;
565 do_lsr_cfg_xconnect_get(x, xcon, flag);
567 retval = MPLS_SUCCESS;
569 lsr_cfg_xconnect_get_end:
570 mpls_lock_release(global->global_lock); /* UNLOCK */
572 LDP_EXIT(global->user_data, "lsr_cfg_xconnect_get2");
574 return retval;
577 mpls_return_enum lsr_cfg_xconnect_getnext(mpls_cfg_handle handle, lsr_xconnect * i, uint32_t flag)
579 lsr_global *g = (lsr_global *) handle;
580 lsr_xconnect *xcon = NULL;
581 mpls_return_enum r = MPLS_FAILURE;
582 mpls_bool done = MPLS_BOOL_FALSE;
583 int index;
585 LDP_ENTER(g->user_data, "lsr_cfg_xconnect_getnext");
587 if (i->index == 0) {
588 index = 1;
589 } else {
590 index = i->index + 1;
593 mpls_lock_get(g->global_lock); /* LOCK */
594 while (done == MPLS_BOOL_FALSE) {
595 switch ((r = lsr_global_find_xconnect_index(g, index, &xcon))) {
596 case MPLS_SUCCESS:
597 case MPLS_END_OF_LIST:
598 done = MPLS_BOOL_TRUE;
599 break;
600 case MPLS_FAILURE:
601 break;
602 default:
603 MPLS_ASSERT(0);
605 index++;
607 mpls_lock_release(g->global_lock); /* UNLOCK */
609 if (r == MPLS_SUCCESS) {
610 i->index = xcon->index;
611 LDP_EXIT(g->user_data, "lsr_cfg_xconnect_getnext");
612 return lsr_cfg_xconnect_get(g, i, flag);
614 LDP_EXIT(g->user_data, "lsr_cfg_xconnect_getnext");
615 return r;
618 mpls_return_enum lsr_cfg_xconnect_test(mpls_cfg_handle handle, lsr_xconnect * i,
619 uint32_t flag)
621 lsr_global *global = (lsr_global *) handle;
622 lsr_xconnect *xcon = NULL;
623 mpls_return_enum retval = MPLS_FAILURE;
625 MPLS_ASSERT(global !=NULL && i != NULL);
627 LDP_ENTER(global->user_data, "lsr_cfg_xconnect_test");
629 mpls_lock_get(global->global_lock); /* LOCK */
631 if (!(flag & LSR_CFG_ADD)) {
632 lsr_global_find_xconnect_index(global, i->index, &xcon);
633 } else {
634 retval = MPLS_SUCCESS;
635 goto lsr_cfg_xconnect_test_end;
638 retval = MPLS_SUCCESS;
640 lsr_cfg_xconnect_test_end:
641 mpls_lock_release(global->global_lock); /* UNLOCK */
643 LDP_EXIT(global->user_data, "lsr_cfg_xconnect_test");
645 return retval;
648 static mpls_return_enum do_lsr_cfg_xconnect_set(lsr_global *global, lsr_xconnect * x, lsr_xconnect * xcon, uint32_t flag)
650 mpls_return_enum retval = MPLS_FAILURE;
652 if (flag & LSR_CFG_DEL) {
654 mpls_mpls_xconnect_del(global->mpls_handle, &xcon->insegment->info,
655 &xcon->outsegment->info);
656 _lsr_global_del_xconnect(global, xcon);
658 return MPLS_SUCCESS;
661 if (LSR_XCONNECT_CFG_OUTSEGMENT & flag) {
662 lsr_outsegment *out = NULL;
663 lsr_global_find_outsegment_index(global, x->outsegment_index, &out);
664 if (!out) {
665 return MPLS_FAILURE;
667 lsr_outsegment_add_xconnect(out,xcon);
669 if (LSR_XCONNECT_CFG_INSEGMENT & flag) {
670 lsr_insegment *in = NULL;
671 lsr_global_find_insegment_index(global, x->insegment_index, &in);
672 if (!in) {
673 return MPLS_FAILURE;
675 lsr_insegment_add_xconnect(in,xcon);
677 if (LSR_XCONNECT_CFG_LSPID & flag) {
678 xcon->info.lspid = x->info.lspid;
680 if (LSR_XCONNECT_CFG_LABELSTACK & flag) {
681 xcon->info.stack_size = x->info.stack_size;
682 if (x->info.stack_size) {
683 memcpy(xcon->info.stack, x->info.stack,
684 sizeof(mpls_label_struct) * x->info.stack_size);
687 if (LSR_XCONNECT_CFG_OWNER & flag) {
688 xcon->info.owner = x->info.owner;
691 retval = MPLS_SUCCESS;
693 if (flag & LSR_CFG_ADD) {
694 retval = mpls_mpls_xconnect_add(global->mpls_handle,&xcon->insegment->info,
695 &xcon->outsegment->info);
696 if (retval == MPLS_SUCCESS) {
697 _lsr_global_add_xconnect(global, xcon);
700 return retval;
703 mpls_return_enum lsr_cfg_xconnect_set(mpls_cfg_handle handle, lsr_xconnect * x, uint32_t flag)
705 lsr_global *global = (lsr_global*)handle;
706 lsr_xconnect *xcon = NULL;
707 mpls_return_enum retval = MPLS_FAILURE;
709 MPLS_ASSERT(global !=NULL && x != NULL);
711 LDP_ENTER(global->user_data, "lsr_cfg_xconnect_set");
713 mpls_lock_get(global->global_lock); /* LOCK */
715 if (flag & LSR_CFG_ADD) {
716 if ((xcon = lsr_xconnect_create()) == NULL) {
717 goto lsr_cfg_xconnect_set_end;
719 x->index = xcon->index;
720 } else {
721 lsr_global_find_xconnect_index(global, x->index, &xcon);
724 if (xcon == NULL)
725 goto lsr_cfg_xconnect_set_end;
727 retval = do_lsr_cfg_xconnect_set(global,x,xcon,flag);
729 lsr_cfg_xconnect_set_end:
730 mpls_lock_release(global->global_lock); /* UNLOCK */
732 LDP_EXIT(global->user_data, "lsr_cfg_xconnect_set");
734 return retval;
737 mpls_return_enum lsr_cfg_xconnect_set2(mpls_cfg_handle handle, lsr_xconnect * x, uint32_t flag)
739 lsr_global *global = (lsr_global*)handle;
740 lsr_xconnect *xcon = NULL;
741 mpls_return_enum retval = MPLS_FAILURE;
743 MPLS_ASSERT(global !=NULL && x != NULL);
745 LDP_ENTER(global->user_data, "lsr_cfg_xconnect_set2");
747 mpls_lock_get(global->global_lock); /* LOCK */
749 if (flag & LSR_CFG_ADD) {
750 if ((xcon = lsr_xconnect_create()) == NULL) {
751 goto lsr_cfg_xconnect_set_end2;
753 x->index = xcon->index;
754 } else {
755 lsr_global_find_xconnect_index2(global, x->insegment_index,
756 x->outsegment_index, &xcon);
759 if (xcon == NULL)
760 goto lsr_cfg_xconnect_set_end2;
762 retval = do_lsr_cfg_xconnect_set(global,x,xcon,flag);
764 lsr_cfg_xconnect_set_end2:
765 mpls_lock_release(global->global_lock); /* UNLOCK */
767 LDP_EXIT(global->user_data, "lsr_cfg_xconnect_set2");
769 return retval;
772 /******************* INTERFACE **********************/
774 mpls_return_enum lsr_cfg_if_get(mpls_cfg_handle handle, lsr_if * i, uint32_t flag)
776 lsr_global *global = (lsr_global *) handle;
777 lsr_if *iff = NULL;
778 mpls_return_enum retval = MPLS_FAILURE;
780 MPLS_ASSERT(global !=NULL && i != NULL);
782 LDP_ENTER(global->user_data, "lsr_cfg_if_get");
784 mpls_lock_get(global->global_lock); /* LOCK */
786 if (flag & LSR_IF_CFG_BY_INDEX) {
787 lsr_global_find_if_index(global, i->index, &iff);
788 } else {
789 iff = lsr_global_find_if_handle(global, i->handle);
791 if (!iff)
792 goto lsr_cfg_if_get_end;
794 if (LSR_IF_CFG_INDEX & flag) {
795 i->index = iff->index;
797 if (LSR_IF_CFG_OPER_STATE & flag) {
798 i->oper_state = iff->oper_state;
801 retval = MPLS_SUCCESS;
803 lsr_cfg_if_get_end:
804 mpls_lock_release(global->global_lock); /* UNLOCK */
806 LDP_EXIT(global->user_data, "lsr_cfg_if_get");
808 return retval;
811 mpls_return_enum lsr_cfg_if_getnext(mpls_cfg_handle handle, lsr_if * i,
812 uint32_t flag)
814 lsr_global *g = (lsr_global *) handle;
815 lsr_if *iff = NULL;
816 mpls_return_enum r = MPLS_FAILURE;
817 mpls_bool done = MPLS_BOOL_FALSE;
818 int index;
820 LDP_ENTER(g->user_data, "lsr_cfg_if_getnext");
822 if (i->index == 0) {
823 index = 1;
824 } else {
825 index = i->index + 1;
828 mpls_lock_get(g->global_lock); /* LOCK */
829 while (done == MPLS_BOOL_FALSE) {
830 switch ((r = lsr_global_find_if_index(g, index, &iff))) {
831 case MPLS_SUCCESS:
832 case MPLS_END_OF_LIST:
833 done = MPLS_BOOL_TRUE;
834 break;
835 case MPLS_FAILURE:
836 break;
837 default:
838 MPLS_ASSERT(0);
840 index++;
842 mpls_lock_release(g->global_lock); /* UNLOCK */
844 if (r == MPLS_SUCCESS) {
845 i->index = iff->index;
846 LDP_EXIT(g->user_data, "lsr_cfg_if_getnext");
847 return lsr_cfg_if_get(g, i, flag);
849 LDP_EXIT(g->user_data, "lsr_cfg_if_getnext");
850 return r;
853 mpls_return_enum lsr_cfg_if_test(mpls_cfg_handle handle, lsr_if * i,
854 uint32_t flag)
856 lsr_global *global = (lsr_global *) handle;
857 lsr_if *iff = NULL;
858 mpls_return_enum retval = MPLS_FAILURE;
860 MPLS_ASSERT(global !=NULL && i != NULL);
862 LDP_ENTER(global->user_data, "lsr_cfg_if_test");
864 mpls_lock_get(global->global_lock); /* LOCK */
866 if (!(flag & LSR_CFG_ADD)) {
867 lsr_global_find_if_index(global, i->index, &iff);
868 } else {
869 retval = MPLS_SUCCESS;
870 goto lsr_cfg_if_test_end;
873 retval = MPLS_SUCCESS;
875 lsr_cfg_if_test_end:
876 mpls_lock_release(global->global_lock); /* UNLOCK */
878 LDP_EXIT(global->user_data, "lsr_cfg_if_test");
880 return retval;
883 mpls_return_enum lsr_cfg_if_set(mpls_cfg_handle handle, lsr_if * i, uint32_t flag)
885 lsr_global *global = (lsr_global*)handle;
886 lsr_if *iff = NULL;
887 mpls_return_enum retval = MPLS_FAILURE;
889 MPLS_ASSERT(global !=NULL && i != NULL);
891 LDP_ENTER(global->user_data, "lsr_cfg_if_set");
893 mpls_lock_get(global->global_lock); /* LOCK */
895 if (flag & LSR_CFG_ADD) {
896 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) ==
897 MPLS_BOOL_FALSE) {
898 /* ADDs must supply a valid handle */
899 goto lsr_cfg_if_set_end;
901 if ((iff = lsr_if_create()) == NULL) {
902 goto lsr_cfg_if_set_end;
905 /* ADDs must supply the handle */
906 iff->handle = i->handle;
907 _lsr_global_add_if(global, iff);
909 /* return the newly allocated index to the user */
910 i->index = iff->index;
911 } else {
912 if (flag & LSR_IF_CFG_BY_INDEX) {
913 lsr_global_find_if_index(global, i->index, &iff);
914 } else {
915 iff = lsr_global_find_if_handle(global, i->handle);
919 if ((iff == NULL) ||
920 ((flag & LSR_IF_CFG_WHEN_DOWN) && (iff->oper_state == MPLS_OPER_UP)))
921 goto lsr_cfg_if_set_end;
923 if (LSR_IF_CFG_OPER_STATE & flag) {
924 iff->oper_state = i->oper_state;
927 if (flag & LSR_CFG_DEL) {
928 _lsr_global_del_if(global, iff);
929 retval = MPLS_SUCCESS;
930 goto lsr_cfg_if_set_end;
933 retval = MPLS_SUCCESS;
935 lsr_cfg_if_set_end:
936 mpls_lock_release(global->global_lock); /* UNLOCK */
938 LDP_EXIT(global->user_data, "lsr_cfg_if_set");
940 return retval;
943 /******************* FTN **********************/
945 static void do_lsr_cfg_ftn_get(lsr_ftn * f, lsr_ftn *ftn, uint32_t flag)
947 if (LSR_FTN_CFG_INDEX & flag) {
948 f->index = ftn->index;
950 if (LSR_FTN_CFG_OUTSEGMENT & flag) {
951 f->outsegment_index = ftn->outsegment->index;
953 if (LSR_FTN_CFG_FEC & flag) {
954 memcpy(&f->fec,&ftn->fec,sizeof(mpls_fec));
958 mpls_return_enum lsr_cfg_ftn_get(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
960 lsr_global *global = (lsr_global *) handle;
961 lsr_ftn *ftn = NULL;
962 mpls_return_enum retval = MPLS_FAILURE;
964 MPLS_ASSERT(global != NULL && f != NULL);
966 LDP_ENTER(global->user_data, "lsr_cfg_ftn_get");
968 mpls_lock_get(global->global_lock); /* LOCK */
970 if (lsr_global_find_ftn_index(global, f->index, &ftn) != MPLS_SUCCESS)
971 goto lsr_cfg_ftn_get_end;
973 do_lsr_cfg_ftn_get(f, ftn, flag);
975 retval = MPLS_SUCCESS;
977 lsr_cfg_ftn_get_end:
978 mpls_lock_release(global->global_lock); /* UNLOCK */
980 LDP_EXIT(global->user_data, "lsr_cfg_ftn_get");
982 return retval;
985 mpls_return_enum lsr_cfg_ftn_get2(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
987 lsr_global *global = (lsr_global *) handle;
988 lsr_ftn *ftn = NULL;
989 mpls_return_enum retval = MPLS_FAILURE;
991 MPLS_ASSERT(global != NULL && f != NULL);
993 LDP_ENTER(global->user_data, "lsr_cfg_ftn_get2");
995 mpls_lock_get(global->global_lock); /* LOCK */
997 /* f->fec and f->outsegment_index are used for lookup */
998 if (lsr_global_find_ftn_index2(global, f, &ftn) != MPLS_SUCCESS)
999 goto lsr_cfg_ftn_get_end2;
1001 do_lsr_cfg_ftn_get(f, ftn, flag);
1003 retval = MPLS_SUCCESS;
1005 lsr_cfg_ftn_get_end2:
1006 mpls_lock_release(global->global_lock); /* UNLOCK */
1008 LDP_EXIT(global->user_data, "lsr_cfg_ftn_get2");
1010 return retval;
1013 mpls_return_enum lsr_cfg_ftn_getnext(mpls_cfg_handle handle, lsr_ftn * f,
1014 uint32_t flag)
1016 lsr_global *g = (lsr_global *) handle;
1017 lsr_ftn *ftn = NULL;
1018 mpls_return_enum r = MPLS_FAILURE;
1019 mpls_bool done = MPLS_BOOL_FALSE;
1020 int index;
1022 LDP_ENTER(g->user_data, "lsr_cfg_ftn_getnext");
1024 if (f->index == 0) {
1025 index = 1;
1026 } else {
1027 index = f->index + 1;
1030 mpls_lock_get(g->global_lock); /* LOCK */
1031 while (done == MPLS_BOOL_FALSE) {
1032 switch ((r = lsr_global_find_ftn_index(g, index, &ftn))) {
1033 case MPLS_SUCCESS:
1034 case MPLS_END_OF_LIST:
1035 done = MPLS_BOOL_TRUE;
1036 break;
1037 case MPLS_FAILURE:
1038 break;
1039 default:
1040 MPLS_ASSERT(0);
1042 index++;
1044 mpls_lock_release(g->global_lock); /* UNLOCK */
1046 if (r == MPLS_SUCCESS) {
1047 f->index = ftn->index;
1048 LDP_EXIT(g->user_data, "lsr_cfg_ftn_getnext");
1049 return lsr_cfg_ftn_get(g, f, flag);
1051 LDP_EXIT(g->user_data, "lsr_cfg_ftn_getnext");
1052 return r;
1055 mpls_return_enum lsr_cfg_ftn_test(mpls_cfg_handle handle, lsr_ftn * f,
1056 uint32_t flag)
1058 lsr_global *global = (lsr_global *) handle;
1059 lsr_ftn *ftn = NULL;
1060 mpls_return_enum retval = MPLS_FAILURE;
1062 MPLS_ASSERT(global !=NULL && f != NULL);
1064 LDP_ENTER(global->user_data, "lsr_cfg_ftn_test");
1066 mpls_lock_get(global->global_lock); /* LOCK */
1068 if (!(flag & LSR_CFG_ADD)) {
1069 lsr_global_find_ftn_index(global, f->index, &ftn);
1070 } else {
1071 retval = MPLS_SUCCESS;
1072 goto lsr_cfg_ftn_test_end;
1075 retval = MPLS_SUCCESS;
1077 lsr_cfg_ftn_test_end:
1078 mpls_lock_release(global->global_lock); /* UNLOCK */
1080 LDP_EXIT(global->user_data, "lsr_cfg_ftn_test");
1082 return retval;
1085 static mpls_return_enum do_lsr_cfg_ftn_set(lsr_global *global, lsr_ftn * f, lsr_ftn *ftn, uint32_t flag)
1087 mpls_return_enum retval = MPLS_FAILURE;
1089 if (flag & LSR_CFG_DEL) {
1091 mpls_mpls_fec2out_del(global->mpls_handle, &ftn->fec,
1092 &ftn->outsegment->info);
1093 _lsr_global_del_ftn(global, ftn);
1095 return MPLS_SUCCESS;
1098 if (LSR_FTN_CFG_OUTSEGMENT & flag) {
1099 lsr_outsegment *out = NULL;
1100 lsr_global_find_outsegment_index(global, f->outsegment_index, &out);
1101 if (!out) {
1102 return MPLS_FAILURE;
1104 lsr_outsegment_add_ftn(out,ftn);
1106 if (LSR_FTN_CFG_FEC & flag) {
1107 memcpy(&ftn->fec,&f->fec,sizeof(mpls_fec));
1110 retval = MPLS_SUCCESS;
1112 if (flag & LSR_CFG_ADD) {
1113 retval = mpls_mpls_fec2out_add(global->mpls_handle,&ftn->fec,
1114 &ftn->outsegment->info);
1115 if (retval == MPLS_SUCCESS) {
1116 _lsr_global_add_ftn(global, ftn);
1119 return retval;
1122 mpls_return_enum lsr_cfg_ftn_set(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
1124 lsr_global *global = (lsr_global*)handle;
1125 lsr_ftn *ftn = NULL;
1126 mpls_return_enum retval = MPLS_FAILURE;
1128 MPLS_ASSERT(global !=NULL && f != NULL);
1130 LDP_ENTER(global->user_data, "lsr_cfg_ftn_set");
1132 mpls_lock_get(global->global_lock); /* LOCK */
1134 if (flag & LSR_CFG_ADD) {
1135 if ((ftn = lsr_ftn_create()) == NULL) {
1136 goto lsr_cfg_ftn_set_end;
1138 f->index = ftn->index;
1139 } else {
1140 lsr_global_find_ftn_index(global, f->index, &ftn);
1143 if (ftn == NULL)
1144 goto lsr_cfg_ftn_set_end;
1146 MPLS_REFCNT_HOLD(ftn);
1147 retval = do_lsr_cfg_ftn_set(global, f, ftn, flag);
1148 MPLS_REFCNT_RELEASE(ftn,lsr_ftn_delete);
1150 lsr_cfg_ftn_set_end:
1151 mpls_lock_release(global->global_lock); /* UNLOCK */
1153 LDP_EXIT(global->user_data, "lsr_cfg_ftn_set");
1155 return retval;
1158 mpls_return_enum lsr_cfg_ftn_set2(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
1160 lsr_global *global = (lsr_global*)handle;
1161 lsr_ftn *ftn = NULL;
1162 mpls_return_enum retval = MPLS_FAILURE;
1164 MPLS_ASSERT(global !=NULL && f != NULL);
1166 LDP_ENTER(global->user_data, "lsr_cfg_ftn_set2");
1168 mpls_lock_get(global->global_lock); /* LOCK */
1170 if (flag & LSR_CFG_ADD) {
1171 if ((ftn = lsr_ftn_create()) == NULL) {
1172 goto lsr_cfg_ftn_set_end2;
1174 f->index = ftn->index;
1175 } else {
1176 /* f->fec and f->outsegment_index are used for lookup */
1177 lsr_global_find_ftn_index2(global, f, &ftn);
1180 if (ftn == NULL)
1181 goto lsr_cfg_ftn_set_end2;
1183 retval = do_lsr_cfg_ftn_set(global, f, ftn, flag);
1185 lsr_cfg_ftn_set_end2:
1186 mpls_lock_release(global->global_lock); /* UNLOCK */
1188 LDP_EXIT(global->user_data, "lsr_cfg_ftn_set2");
1190 return retval;