This file should have been deleted what ldp-portable was
[mpls-ldp-portable.git] / lsr / lsr_outsegment.c
blobc1b82e289a2c0198cc8f4784ec3741993ee9931c
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_outsegment.h"
12 #include "lsr_xconnect.h"
13 #include "lsr_ftn.h"
14 #include "lsr_if.h"
16 #include "mpls_assert.h"
17 #include "mpls_mm_impl.h"
18 #include "mpls_trace_impl.h"
20 uint32_t _lsr_outsegment_next_index = 1;
22 lsr_outsegment *lsr_outsegment_create()
24 lsr_outsegment *i = (lsr_outsegment *) mpls_malloc(sizeof(lsr_outsegment));
26 if (i) {
27 memset(i, 0, sizeof(lsr_outsegment));
28 MPLS_REFCNT_INIT(i, 0);
29 MPLS_LIST_ELEM_INIT(i, _global);
30 MPLS_LIST_ELEM_INIT(i, _if);
31 MPLS_LIST_INIT(&i->xconnect_root,lsr_xconnect);
32 MPLS_LIST_INIT(&i->ftn_root,lsr_ftn);
33 i->index = _lsr_outsegment_get_next_index();
35 return i;
38 void lsr_outsegment_delete(lsr_outsegment * i)
40 // LSR_PRINT(g->user_data,"if delete\n");
41 MPLS_REFCNT_ASSERT(i, 0);
42 mpls_free(i);
45 uint32_t _lsr_outsegment_get_next_index()
47 uint32_t retval = _lsr_outsegment_next_index;
49 _lsr_outsegment_next_index++;
50 if (retval > _lsr_outsegment_next_index) {
51 _lsr_outsegment_next_index = 1;
53 return retval;
56 mpls_return_enum lsr_outsegment_add_xconnect(lsr_outsegment *out, lsr_xconnect *x) {
57 if (out && x) {
58 MPLS_REFCNT_HOLD(x);
59 MPLS_LIST_ADD_HEAD(&out->xconnect_root, x, _outsegment, lsr_xconnect);
60 _lsr_xconnect_add_outsegment(x, out);
61 return MPLS_SUCCESS;
63 return MPLS_FAILURE;
66 mpls_return_enum lsr_outsegment_del_xconnect(lsr_outsegment *out, lsr_xconnect *x) {
67 if (out && x) {
68 MPLS_LIST_REMOVE(&out->xconnect_root, x, _outsegment);
69 _lsr_xconnect_del_outsegment(x);
70 MPLS_REFCNT_RELEASE(x, lsr_xconnect_delete);
71 return MPLS_SUCCESS;
73 return MPLS_FAILURE;
76 mpls_return_enum _lsr_outsegment_add_if(lsr_outsegment * o, lsr_if * iff)
78 if (o && iff) {
79 MPLS_REFCNT_HOLD(iff);
80 o->iff = iff;
81 return MPLS_SUCCESS;
83 return MPLS_FAILURE;
86 mpls_return_enum _lsr_outsegment_del_if(lsr_outsegment * o)
88 if (o && o->iff) {
89 MPLS_REFCNT_RELEASE(o->iff, lsr_if_delete);
90 o->iff = NULL;
91 return MPLS_SUCCESS;
93 return MPLS_FAILURE;
96 mpls_return_enum lsr_outsegment_add_ftn(lsr_outsegment *out, lsr_ftn *x) {
97 if (out && x) {
98 MPLS_REFCNT_HOLD(x);
99 MPLS_LIST_ADD_HEAD(&out->ftn_root, x, _outsegment, lsr_ftn);
100 _lsr_ftn_add_outsegment(x, out);
101 return MPLS_SUCCESS;
103 return MPLS_FAILURE;
106 mpls_return_enum lsr_outsegment_del_ftn(lsr_outsegment *out, lsr_ftn *x) {
107 if (out && x) {
108 MPLS_LIST_REMOVE(&out->ftn_root, x, _outsegment);
109 _lsr_ftn_del_outsegment(x);
110 MPLS_REFCNT_RELEASE(x, lsr_ftn_delete);
111 return MPLS_SUCCESS;
113 return MPLS_FAILURE;