3 * Copyright (C) James R. Leu 2000
6 * This software is covered under the LGPL, for more
7 * info check out http://www.gnu.org/copyleft/lgpl.html
11 #include "ldp_struct.h"
12 #include "ldp_outlabel.h"
13 #include "ldp_inlabel.h"
14 #include "ldp_session.h"
15 #include "ldp_entity.h"
17 #include "ldp_global.h"
19 #include "mpls_assert.h"
20 #include "mpls_mm_impl.h"
21 #include "mpls_trace_impl.h"
26 #include "mpls_mpls_impl.h"
29 static uint32_t _ldp_inlabel_next_index
= 1;
31 ldp_inlabel
*ldp_inlabel_create()
33 ldp_inlabel
*i
= (ldp_inlabel
*) mpls_malloc(sizeof(ldp_inlabel
));
36 memset(i
, 0, sizeof(ldp_inlabel
));
37 MPLS_REFCNT_INIT(i
, 0);
38 mpls_link_list_init(&i
->session_root
);
39 mpls_link_list_init(&i
->attr_root
);
40 MPLS_LIST_ELEM_INIT(i
, _global
);
41 MPLS_LIST_ELEM_INIT(i
, _outlabel
);
42 i
->index
= _ldp_inlabel_get_next_index();
43 i
->info
.label
.type
= MPLS_LABEL_TYPE_NONE
;
48 void ldp_inlabel_delete_complete(ldp_global
* g
, ldp_inlabel
* in
,
49 ldp_session
* s
, ldp_attr
* a
)
51 ldp_attr_del_inlabel(a
);
52 ldp_session_del_inlabel(s
, in
);
53 _ldp_global_del_inlabel(g
, in
);
54 ldp_inlabel_del_outlabel(g
, in
);
57 ldp_inlabel
*ldp_inlabel_create_complete(ldp_global
* g
, ldp_session
* s
,
60 ldp_inlabel
*in
= ldp_inlabel_create();
61 mpls_return_enum result
;
65 in
->info
.labelspace
= s
->cfg_label_space
;
67 in
->info
.family
= MPLS_FAMILY_IPV4
;
68 in
->info
.owner
= MPLS_OWNER_LDP
;
69 result
= _ldp_global_add_inlabel(g
, in
);
71 if (result
== MPLS_FAILURE
) {
72 _ldp_global_del_inlabel(g
, in
);
76 if (ldp_session_add_inlabel(s
, in
) == MPLS_FAILURE
) {
77 _ldp_global_del_inlabel(g
, in
);
81 mpls_label_struct2ldp_attr(&in
->info
.label
, a
);
82 ldp_attr_add_inlabel(a
, in
);
87 void ldp_inlabel_delete(ldp_inlabel
* i
)
89 LDP_PRINT(g
->user_data
,"inlabel delete\n");
90 MPLS_REFCNT_ASSERT(i
, 0);
94 mpls_return_enum
ldp_inlabel_add_outlabel(ldp_global
*g
, ldp_inlabel
*i
,
96 mpls_return_enum result
;
99 MPLS_ASSERT(i
->outlabel
== NULL
);
104 xcon
.insegment_index
= i
->info
.handle
;
105 xcon
.outsegment_index
= o
->info
.handle
;
106 xcon
.info
.owner
= MPLS_OWNER_LDP
;
107 result
= lsr_cfg_xconnect_set2(g
->lsr_handle
, &xcon
, LSR_CFG_ADD
|
108 LSR_XCONNECT_CFG_OUTSEGMENT
|LSR_XCONNECT_CFG_INSEGMENT
|
109 LSR_XCONNECT_CFG_LSPID
|LSR_XCONNECT_CFG_OWNER
);
112 result
= mpls_mpls_xconnect_add(g
->mpls_handle
, &i
->info
, &o
->info
);
114 if (result
== MPLS_SUCCESS
) {
117 _ldp_outlabel_add_inlabel(o
, i
);
122 mpls_return_enum
ldp_inlabel_del_outlabel(ldp_global
*g
, ldp_inlabel
* i
)
124 MPLS_ASSERT(i
&& i
->outlabel
);
128 xcon
.insegment_index
= i
->info
.handle
;
129 xcon
.outsegment_index
= i
->outlabel
->info
.handle
;
130 lsr_cfg_xconnect_set2(g
->lsr_handle
, &xcon
, LSR_CFG_DEL
);
132 mpls_mpls_xconnect_del(g
->mpls_handle
, &i
->info
, &i
->outlabel
->info
);
134 _ldp_outlabel_del_inlabel(i
->outlabel
, i
);
135 MPLS_REFCNT_RELEASE(i
->outlabel
, ldp_outlabel_delete
);
141 mpls_return_enum
_ldp_inlabel_add_attr(ldp_inlabel
* i
, ldp_attr
* a
)
146 if (mpls_link_list_add_tail(&i
->attr_root
, a
) == MPLS_SUCCESS
) {
150 MPLS_REFCNT_RELEASE(a
, ldp_attr_delete
);
154 void _ldp_inlabel_del_attr(ldp_inlabel
* i
, ldp_attr
* a
)
157 mpls_link_list_remove_data(&i
->attr_root
, a
);
158 MPLS_REFCNT_RELEASE(a
, ldp_attr_delete
);
162 mpls_return_enum
_ldp_inlabel_add_session(ldp_inlabel
* i
, ldp_session
* s
)
167 if (mpls_link_list_add_tail(&i
->session_root
, s
) == MPLS_SUCCESS
) {
170 MPLS_REFCNT_RELEASE(s
, ldp_session_delete
);
174 void _ldp_inlabel_del_session(ldp_inlabel
* i
, ldp_session
* s
)
177 mpls_link_list_remove_data(&i
->session_root
, s
);
178 MPLS_REFCNT_RELEASE(s
, ldp_session_delete
);
181 uint32_t _ldp_inlabel_get_next_index()
183 uint32_t retval
= _ldp_inlabel_next_index
;
185 _ldp_inlabel_next_index
++;
186 if (retval
> _ldp_inlabel_next_index
) {
187 _ldp_inlabel_next_index
= 1;