Centralized the compare functions for structures in the MPLS layer
[mpls-ldp-portable.git] / lsr / lsr_cfg.c
blobfc8894da8b5e824c1dbc226be3684c942c4689d7
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 (lsr_global_find_if_index(global, i->index, &iff) != MPLS_SUCCESS)
787 goto lsr_cfg_if_get_end;
789 if (LSR_IF_CFG_INDEX & flag) {
790 i->index = iff->index;
792 if (LSR_IF_CFG_NAME & flag) {
793 strncpy(i->name, iff->name, MPLS_MAX_IF_NAME);
795 if (LSR_IF_CFG_OPER_STATE & flag) {
796 i->oper_state = iff->oper_state;
799 retval = MPLS_SUCCESS;
801 lsr_cfg_if_get_end:
802 mpls_lock_release(global->global_lock); /* UNLOCK */
804 LDP_EXIT(global->user_data, "lsr_cfg_if_get");
806 return retval;
809 mpls_return_enum lsr_cfg_if_getnext(mpls_cfg_handle handle, lsr_if * i,
810 uint32_t flag)
812 lsr_global *g = (lsr_global *) handle;
813 lsr_if *iff = NULL;
814 mpls_return_enum r = MPLS_FAILURE;
815 mpls_bool done = MPLS_BOOL_FALSE;
816 int index;
818 LDP_ENTER(g->user_data, "lsr_cfg_if_getnext");
820 if (i->index == 0) {
821 index = 1;
822 } else {
823 index = i->index + 1;
826 mpls_lock_get(g->global_lock); /* LOCK */
827 while (done == MPLS_BOOL_FALSE) {
828 switch ((r = lsr_global_find_if_index(g, index, &iff))) {
829 case MPLS_SUCCESS:
830 case MPLS_END_OF_LIST:
831 done = MPLS_BOOL_TRUE;
832 break;
833 case MPLS_FAILURE:
834 break;
835 default:
836 MPLS_ASSERT(0);
838 index++;
840 mpls_lock_release(g->global_lock); /* UNLOCK */
842 if (r == MPLS_SUCCESS) {
843 i->index = iff->index;
844 LDP_EXIT(g->user_data, "lsr_cfg_if_getnext");
845 return lsr_cfg_if_get(g, i, flag);
847 LDP_EXIT(g->user_data, "lsr_cfg_if_getnext");
848 return r;
851 mpls_return_enum lsr_cfg_if_test(mpls_cfg_handle handle, lsr_if * i,
852 uint32_t flag)
854 lsr_global *global = (lsr_global *) handle;
855 lsr_if *iff = NULL;
856 mpls_return_enum retval = MPLS_FAILURE;
858 MPLS_ASSERT(global !=NULL && i != NULL);
860 LDP_ENTER(global->user_data, "lsr_cfg_if_test");
862 mpls_lock_get(global->global_lock); /* LOCK */
864 if (!(flag & LSR_CFG_ADD)) {
865 lsr_global_find_if_index(global, i->index, &iff);
866 } else {
867 retval = MPLS_SUCCESS;
868 goto lsr_cfg_if_test_end;
871 retval = MPLS_SUCCESS;
873 lsr_cfg_if_test_end:
874 mpls_lock_release(global->global_lock); /* UNLOCK */
876 LDP_EXIT(global->user_data, "lsr_cfg_if_test");
878 return retval;
881 mpls_return_enum lsr_cfg_if_set(mpls_cfg_handle handle, lsr_if * i, uint32_t flag)
883 lsr_global *global = (lsr_global*)handle;
884 lsr_if *iff = NULL;
885 mpls_return_enum retval = MPLS_FAILURE;
887 MPLS_ASSERT(global !=NULL && i != NULL);
889 LDP_ENTER(global->user_data, "lsr_cfg_if_set");
891 mpls_lock_get(global->global_lock); /* LOCK */
893 if (flag & LSR_CFG_ADD) {
894 if ((iff = lsr_if_create()) == NULL) {
895 goto lsr_cfg_if_set_end;
897 i->handle = mpls_ifmgr_open_if(global->ifmgr_handle, i->name);
898 if (mpls_if_handle_verify(global->ifmgr_handle, i->handle) == MPLS_BOOL_FALSE) {
899 lsr_if_delete(iff);
900 goto lsr_cfg_if_set_end;
902 iff->handle = i->handle;
903 i->index = iff->index;
904 strncpy(iff->name, i->name, MPLS_MAX_IF_NAME);
905 _lsr_global_add_if(global, iff);
906 } else {
907 lsr_global_find_if_index(global, i->index, &iff);
910 if ((iff == NULL) ||
911 ((flag & LSR_IF_CFG_WHEN_DOWN) && (iff->oper_state == MPLS_OPER_UP)))
912 goto lsr_cfg_if_set_end;
914 if (flag & LSR_CFG_DEL) {
916 _lsr_global_del_if(global, iff);
918 retval = MPLS_SUCCESS;
919 goto lsr_cfg_if_set_end;
922 if (LSR_IF_CFG_NAME & flag) {
923 strncpy(iff->name, i->name, MPLS_MAX_IF_NAME);
925 if (LSR_IF_CFG_OPER_STATE & flag) {
926 iff->oper_state = i->oper_state;
929 retval = MPLS_SUCCESS;
931 lsr_cfg_if_set_end:
932 mpls_lock_release(global->global_lock); /* UNLOCK */
934 LDP_EXIT(global->user_data, "lsr_cfg_if_set");
936 return retval;
939 /******************* FTN **********************/
941 static void do_lsr_cfg_ftn_get(lsr_ftn * f, lsr_ftn *ftn, uint32_t flag)
943 if (LSR_FTN_CFG_INDEX & flag) {
944 f->index = ftn->index;
946 if (LSR_FTN_CFG_OUTSEGMENT & flag) {
947 f->outsegment_index = ftn->outsegment->index;
949 if (LSR_FTN_CFG_FEC & flag) {
950 memcpy(&f->fec,&ftn->fec,sizeof(mpls_fec));
954 mpls_return_enum lsr_cfg_ftn_get(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
956 lsr_global *global = (lsr_global *) handle;
957 lsr_ftn *ftn = NULL;
958 mpls_return_enum retval = MPLS_FAILURE;
960 MPLS_ASSERT(global != NULL && f != NULL);
962 LDP_ENTER(global->user_data, "lsr_cfg_ftn_get");
964 mpls_lock_get(global->global_lock); /* LOCK */
966 if (lsr_global_find_ftn_index(global, f->index, &ftn) != MPLS_SUCCESS)
967 goto lsr_cfg_ftn_get_end;
969 do_lsr_cfg_ftn_get(f, ftn, flag);
971 retval = MPLS_SUCCESS;
973 lsr_cfg_ftn_get_end:
974 mpls_lock_release(global->global_lock); /* UNLOCK */
976 LDP_EXIT(global->user_data, "lsr_cfg_ftn_get");
978 return retval;
981 mpls_return_enum lsr_cfg_ftn_get2(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
983 lsr_global *global = (lsr_global *) handle;
984 lsr_ftn *ftn = NULL;
985 mpls_return_enum retval = MPLS_FAILURE;
987 MPLS_ASSERT(global != NULL && f != NULL);
989 LDP_ENTER(global->user_data, "lsr_cfg_ftn_get2");
991 mpls_lock_get(global->global_lock); /* LOCK */
993 /* f->fec and f->outsegment_index are used for lookup */
994 if (lsr_global_find_ftn_index2(global, f, &ftn) != MPLS_SUCCESS)
995 goto lsr_cfg_ftn_get_end2;
997 do_lsr_cfg_ftn_get(f, ftn, flag);
999 retval = MPLS_SUCCESS;
1001 lsr_cfg_ftn_get_end2:
1002 mpls_lock_release(global->global_lock); /* UNLOCK */
1004 LDP_EXIT(global->user_data, "lsr_cfg_ftn_get2");
1006 return retval;
1009 mpls_return_enum lsr_cfg_ftn_getnext(mpls_cfg_handle handle, lsr_ftn * f,
1010 uint32_t flag)
1012 lsr_global *g = (lsr_global *) handle;
1013 lsr_ftn *ftn = NULL;
1014 mpls_return_enum r = MPLS_FAILURE;
1015 mpls_bool done = MPLS_BOOL_FALSE;
1016 int index;
1018 LDP_ENTER(g->user_data, "lsr_cfg_ftn_getnext");
1020 if (f->index == 0) {
1021 index = 1;
1022 } else {
1023 index = f->index + 1;
1026 mpls_lock_get(g->global_lock); /* LOCK */
1027 while (done == MPLS_BOOL_FALSE) {
1028 switch ((r = lsr_global_find_ftn_index(g, index, &ftn))) {
1029 case MPLS_SUCCESS:
1030 case MPLS_END_OF_LIST:
1031 done = MPLS_BOOL_TRUE;
1032 break;
1033 case MPLS_FAILURE:
1034 break;
1035 default:
1036 MPLS_ASSERT(0);
1038 index++;
1040 mpls_lock_release(g->global_lock); /* UNLOCK */
1042 if (r == MPLS_SUCCESS) {
1043 f->index = ftn->index;
1044 LDP_EXIT(g->user_data, "lsr_cfg_ftn_getnext");
1045 return lsr_cfg_ftn_get(g, f, flag);
1047 LDP_EXIT(g->user_data, "lsr_cfg_ftn_getnext");
1048 return r;
1051 mpls_return_enum lsr_cfg_ftn_test(mpls_cfg_handle handle, lsr_ftn * f,
1052 uint32_t flag)
1054 lsr_global *global = (lsr_global *) handle;
1055 lsr_ftn *ftn = NULL;
1056 mpls_return_enum retval = MPLS_FAILURE;
1058 MPLS_ASSERT(global !=NULL && f != NULL);
1060 LDP_ENTER(global->user_data, "lsr_cfg_ftn_test");
1062 mpls_lock_get(global->global_lock); /* LOCK */
1064 if (!(flag & LSR_CFG_ADD)) {
1065 lsr_global_find_ftn_index(global, f->index, &ftn);
1066 } else {
1067 retval = MPLS_SUCCESS;
1068 goto lsr_cfg_ftn_test_end;
1071 retval = MPLS_SUCCESS;
1073 lsr_cfg_ftn_test_end:
1074 mpls_lock_release(global->global_lock); /* UNLOCK */
1076 LDP_EXIT(global->user_data, "lsr_cfg_ftn_test");
1078 return retval;
1081 static mpls_return_enum do_lsr_cfg_ftn_set(lsr_global *global, lsr_ftn * f, lsr_ftn *ftn, uint32_t flag)
1083 mpls_return_enum retval = MPLS_FAILURE;
1085 if (flag & LSR_CFG_DEL) {
1087 mpls_mpls_fec2out_del(global->mpls_handle, &ftn->fec,
1088 &ftn->outsegment->info);
1089 _lsr_global_del_ftn(global, ftn);
1091 return MPLS_SUCCESS;
1094 if (LSR_FTN_CFG_OUTSEGMENT & flag) {
1095 lsr_outsegment *out = NULL;
1096 lsr_global_find_outsegment_index(global, f->outsegment_index, &out);
1097 if (!out) {
1098 return MPLS_FAILURE;
1100 lsr_outsegment_add_ftn(out,ftn);
1102 if (LSR_FTN_CFG_FEC & flag) {
1103 memcpy(&ftn->fec,&f->fec,sizeof(mpls_fec));
1106 retval = MPLS_SUCCESS;
1108 if (flag & LSR_CFG_ADD) {
1109 retval = mpls_mpls_fec2out_add(global->mpls_handle,&ftn->fec,
1110 &ftn->outsegment->info);
1111 if (retval == MPLS_SUCCESS) {
1112 _lsr_global_add_ftn(global, ftn);
1115 return retval;
1118 mpls_return_enum lsr_cfg_ftn_set(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
1120 lsr_global *global = (lsr_global*)handle;
1121 lsr_ftn *ftn = NULL;
1122 mpls_return_enum retval = MPLS_FAILURE;
1124 MPLS_ASSERT(global !=NULL && f != NULL);
1126 LDP_ENTER(global->user_data, "lsr_cfg_ftn_set");
1128 mpls_lock_get(global->global_lock); /* LOCK */
1130 if (flag & LSR_CFG_ADD) {
1131 if ((ftn = lsr_ftn_create()) == NULL) {
1132 goto lsr_cfg_ftn_set_end;
1134 f->index = ftn->index;
1135 } else {
1136 lsr_global_find_ftn_index(global, f->index, &ftn);
1139 if (ftn == NULL)
1140 goto lsr_cfg_ftn_set_end;
1142 retval = do_lsr_cfg_ftn_set(global, f, ftn, flag);
1144 lsr_cfg_ftn_set_end:
1145 mpls_lock_release(global->global_lock); /* UNLOCK */
1147 LDP_EXIT(global->user_data, "lsr_cfg_ftn_set");
1149 return retval;
1152 mpls_return_enum lsr_cfg_ftn_set2(mpls_cfg_handle handle, lsr_ftn * f, uint32_t flag)
1154 lsr_global *global = (lsr_global*)handle;
1155 lsr_ftn *ftn = NULL;
1156 mpls_return_enum retval = MPLS_FAILURE;
1158 MPLS_ASSERT(global !=NULL && f != NULL);
1160 LDP_ENTER(global->user_data, "lsr_cfg_ftn_set2");
1162 mpls_lock_get(global->global_lock); /* LOCK */
1164 if (flag & LSR_CFG_ADD) {
1165 if ((ftn = lsr_ftn_create()) == NULL) {
1166 goto lsr_cfg_ftn_set_end2;
1168 f->index = ftn->index;
1169 } else {
1170 /* f->fec and f->outsegment_index are used for lookup */
1171 lsr_global_find_ftn_index2(global, f, &ftn);
1174 if (ftn == NULL)
1175 goto lsr_cfg_ftn_set_end2;
1177 retval = do_lsr_cfg_ftn_set(global, f, ftn, flag);
1179 lsr_cfg_ftn_set_end2:
1180 mpls_lock_release(global->global_lock); /* UNLOCK */
1182 LDP_EXIT(global->user_data, "lsr_cfg_ftn_set2");
1184 return retval;