Changed the relationship between entity-adj-sessios (again)
[mpls-ldp-portable.git] / lsr / lsr_insegment.c
blob92d38b1f44bfae2807bd2fb8b41cd6ea3239e5b6
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_insegment.h"
12 #include "lsr_xconnect.h"
14 #include "mpls_assert.h"
15 #include "mpls_mm_impl.h"
16 #include "mpls_trace_impl.h"
18 uint32_t _lsr_insegment_next_index = 1;
20 lsr_insegment *lsr_insegment_create()
22 lsr_insegment *i = (lsr_insegment *) mpls_malloc(sizeof(lsr_insegment));
24 if (i) {
25 memset(i, 0, sizeof(lsr_insegment));
26 MPLS_REFCNT_INIT(i, 0);
27 MPLS_LIST_ELEM_INIT(i, _outsegment);
28 MPLS_LIST_ELEM_INIT(i, _global);
29 MPLS_LIST_INIT(&i->xconnect_root,lsr_xconnect);
30 i->index = _lsr_insegment_get_next_index();
32 return i;
35 void lsr_insegment_delete(lsr_insegment * i)
37 // LSR_PRINT(g->user_data,"if delete\n");
38 MPLS_REFCNT_ASSERT(i, 0);
39 mpls_free(i);
42 uint32_t _lsr_insegment_get_next_index()
44 uint32_t retval = _lsr_insegment_next_index;
46 _lsr_insegment_next_index++;
47 if (retval > _lsr_insegment_next_index) {
48 _lsr_insegment_next_index = 1;
50 return retval;
53 mpls_return_enum lsr_insegment_add_xconnect(lsr_insegment *in, lsr_xconnect *x) {
54 if (in && x) {
55 MPLS_REFCNT_HOLD(x);
56 MPLS_LIST_ADD_HEAD(&in->xconnect_root, x, _insegment, lsr_xconnect);
57 _lsr_xconnect_add_insegment(x, in);
58 return MPLS_SUCCESS;
60 return MPLS_FAILURE;
63 mpls_return_enum lsr_insegment_del_xconnect(lsr_insegment *in, lsr_xconnect *x) {
64 if (in && x) {
65 MPLS_LIST_REMOVE(&in->xconnect_root, x, _insegment);
66 _lsr_xconnect_del_insegment(x);
67 MPLS_REFCNT_RELEASE(x, lsr_xconnect_delete);
68 return MPLS_SUCCESS;
70 return MPLS_FAILURE;