Centralized the compare functions for structures in the MPLS layer
[mpls-ldp-portable.git] / lsr / lsr_xconnect.c
blob6144e49d8ab309ea2645aec3be48116745e3738d
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_xconnect.h"
12 #include "lsr_outsegment.h"
13 #include "lsr_insegment.h"
15 #include "mpls_assert.h"
16 #include "mpls_mm_impl.h"
17 #include "mpls_trace_impl.h"
19 uint32_t _lsr_xconnect_next_index = 1;
21 lsr_xconnect *lsr_xconnect_create()
23 lsr_xconnect *i = (lsr_xconnect *) mpls_malloc(sizeof(lsr_xconnect));
25 if (i) {
26 memset(i, 0, sizeof(lsr_xconnect));
27 MPLS_REFCNT_INIT(i, 0);
28 MPLS_LIST_ELEM_INIT(i, _outsegment);
29 MPLS_LIST_ELEM_INIT(i, _insegment);
30 MPLS_LIST_ELEM_INIT(i, _global);
31 i->index = _lsr_xconnect_get_next_index();
33 return i;
36 void lsr_xconnect_delete(lsr_xconnect * i)
38 // LSR_PRINT(g->user_data,"if delete\n");
39 MPLS_REFCNT_ASSERT(i, 0);
40 mpls_free(i);
43 uint32_t _lsr_xconnect_get_next_index()
45 uint32_t retval = _lsr_xconnect_next_index;
47 _lsr_xconnect_next_index++;
48 if (retval > _lsr_xconnect_next_index) {
49 _lsr_xconnect_next_index = 1;
51 return retval;
54 mpls_return_enum _lsr_xconnect_add_outsegment(lsr_xconnect * x, lsr_outsegment * o)
56 if (x && o) {
57 MPLS_REFCNT_HOLD(o);
58 x->outsegment = o;
59 return MPLS_SUCCESS;
61 return MPLS_FAILURE;
64 mpls_return_enum _lsr_xconnect_del_outsegment(lsr_xconnect * x)
66 if (x && x->outsegment) {
67 MPLS_REFCNT_RELEASE(x->outsegment, lsr_outsegment_delete);
68 x->outsegment = NULL;
69 return MPLS_SUCCESS;
71 return MPLS_FAILURE;
74 mpls_return_enum _lsr_xconnect_add_insegment(lsr_xconnect * x, lsr_insegment * i)
76 if (x && i) {
77 MPLS_REFCNT_HOLD(i);
78 x->insegment = i;
79 return MPLS_SUCCESS;
81 return MPLS_FAILURE;
84 mpls_return_enum _lsr_xconnect_del_insegment(lsr_xconnect * x)
86 if (x && x->insegment) {
87 MPLS_REFCNT_RELEASE(x->insegment, lsr_insegment_delete);
88 x->insegment = NULL;
89 return MPLS_SUCCESS;
91 return MPLS_FAILURE;