3 * Copyright (C) James R. Leu 2002
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
10 #include "lsr_struct.h"
11 #include "lsr_outsegment.h"
12 #include "lsr_xconnect.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
));
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();
38 void lsr_outsegment_delete(lsr_outsegment
* i
)
40 // LSR_PRINT(g->user_data,"if delete\n");
41 MPLS_REFCNT_ASSERT(i
, 0);
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;
56 mpls_return_enum
lsr_outsegment_add_xconnect(lsr_outsegment
*out
, lsr_xconnect
*x
) {
59 MPLS_LIST_ADD_HEAD(&out
->xconnect_root
, x
, _outsegment
, lsr_xconnect
);
60 _lsr_xconnect_add_outsegment(x
, out
);
66 mpls_return_enum
lsr_outsegment_del_xconnect(lsr_outsegment
*out
, lsr_xconnect
*x
) {
68 MPLS_LIST_REMOVE(&out
->xconnect_root
, x
, _outsegment
);
69 _lsr_xconnect_del_outsegment(x
);
70 MPLS_REFCNT_RELEASE(x
, lsr_xconnect_delete
);
76 mpls_return_enum
_lsr_outsegment_add_if(lsr_outsegment
* o
, lsr_if
* iff
)
79 MPLS_REFCNT_HOLD(iff
);
86 mpls_return_enum
_lsr_outsegment_del_if(lsr_outsegment
* o
)
89 MPLS_REFCNT_RELEASE(o
->iff
, lsr_if_delete
);
96 mpls_return_enum
lsr_outsegment_add_ftn(lsr_outsegment
*out
, lsr_ftn
*x
) {
99 MPLS_LIST_ADD_HEAD(&out
->ftn_root
, x
, _outsegment
, lsr_ftn
);
100 _lsr_ftn_add_outsegment(x
, out
);
106 mpls_return_enum
lsr_outsegment_del_ftn(lsr_outsegment
*out
, lsr_ftn
*x
) {
108 MPLS_LIST_REMOVE(&out
->ftn_root
, x
, _outsegment
);
109 _lsr_ftn_del_outsegment(x
);
110 MPLS_REFCNT_RELEASE(x
, lsr_ftn_delete
);