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
10 #include "ldp_struct.h"
11 #include "ldp_session.h"
15 #include "ldp_notif.h"
16 #include "ldp_entity.h"
17 #include "ldp_inlabel.h"
18 #include "ldp_outlabel.h"
19 #include "ldp_nexthop.h"
20 #include "ldp_global.h"
21 #include "ldp_pdu_setup.h"
22 #include "ldp_label_rel_with.h"
23 #include "ldp_label_mapping.h"
24 #include "ldp_label_request.h"
26 #include "mpls_timer_impl.h"
27 #include "mpls_fib_impl.h"
28 #include "mpls_lock_impl.h"
29 #include "mpls_tree_impl.h"
30 #include "mpls_trace_impl.h"
31 #include "mpls_mm_impl.h"
32 #include "mpls_policy_impl.h"
37 #include "mpls_mpls_impl.h"
40 mpls_return_enum
ldp_label_mapping_with_xc(ldp_global
* g
, ldp_session
* s
,
41 ldp_fec
* f
, ldp_attr
** us_attr
, ldp_attr
* ds_attr
)
43 mpls_return_enum result
= MPLS_SUCCESS
;
44 mpls_bool propogating
= MPLS_BOOL_TRUE
;
45 mpls_bool egress
= MPLS_BOOL_FALSE
;
46 mpls_bool egress_flag
= MPLS_BOOL_FALSE
;
47 mpls_bool created
= MPLS_BOOL_FALSE
;
52 nh
= MPLS_LIST_HEAD(&f
->nh_root
);
54 if (egress_flag
== MPLS_BOOL_FALSE
) {
55 egress_flag
= mpls_policy_egress_check(g
->user_data
, &f
->info
, &nh
->info
);
57 nh
= MPLS_LIST_NEXT(&f
->nh_root
, nh
, _fec
);
61 if (!((*us_attr
) = ldp_attr_create(&f
->info
))) {
64 created
= MPLS_BOOL_TRUE
;
66 if ((!ds_attr
) && (egress_flag
== MPLS_BOOL_TRUE
)) {
67 propogating
= MPLS_BOOL_FALSE
;
68 egress
= MPLS_BOOL_TRUE
;
71 Prepare_Label_Mapping_Attributes(g
, s
, &f
->info
, ds_attr
, (*us_attr
),
72 propogating
, MPLS_BOOL_TRUE
, egress
);
74 result
= ldp_label_mapping_send(g
, s
, f
, (*us_attr
), ds_attr
);
75 if (result
!= MPLS_SUCCESS
) {
76 if (created
== MPLS_BOOL_TRUE
) {
77 ldp_attr_delete(*us_attr
);
82 if (created
== MPLS_BOOL_TRUE
) {
83 result
= ldp_attr_insert_upstream2(g
, s
, (*us_attr
), f
);
84 if (result
!= MPLS_SUCCESS
) {
85 ldp_attr_delete(*us_attr
);
91 * If we have a downstream mapping (not neccessarily installed) and
92 * the downstream and upstream session are not the same....
94 if (ds_attr
&& ((*us_attr
)->session
->index
!= ds_attr
->session
->index
)) {
95 /* then link the attra */
96 ldp_attr_add_us2ds((*us_attr
), ds_attr
);
98 /* if we just created the upstream, and we have install the
99 * downstream, then cross connect them */
100 if ((created
== MPLS_BOOL_TRUE
) && ds_attr
->outlabel
) {
102 if ((*us_attr
)->inlabel
->outlabel
) {
104 * if we use an existing upstream mapping (in ldp_label_mapping_send())
105 * the inlabel will already be be connected to an outlabel;
107 MPLS_ASSERT((*us_attr
)->inlabel
->outlabel
== ds_attr
->outlabel
);
109 LDP_TRACE_LOG(g
->user_data
,MPLS_TRACE_STATE_ALL
,LDP_TRACE_FLAG_BINDING
,
110 "Cross Connect Added for %08x/%d from %s -> %s\n",
111 f
->info
.u
.prefix
.network
.u
.ipv4
, f
->info
.u
.prefix
.length
,
112 (*us_attr
)->session
->session_name
, ds_attr
->session
->session_name
);
114 result
= ldp_inlabel_add_outlabel(g
,(*us_attr
)->inlabel
,
116 if (result
!= MPLS_SUCCESS
) {
125 ldp_session
*ldp_get_next_hop_session_for_fec2(ldp_fec
* f
, ldp_nexthop
*nh
) {
126 ldp_session
*session
= NULL
;
128 * find the info about the next hop for this FEC
130 if (nh
->addr
&& nh
->addr
->session
) {
131 session
= nh
->addr
->session
;
132 } else if (nh
->iff
&& nh
->iff
->is_p2p
== MPLS_BOOL_TRUE
&&
134 ldp_adj
*adj
= MPLS_LIST_HEAD(&nh
->iff
->entity
->adj_root
);
135 session
= adj
? adj
->session
: NULL
;
140 mpls_return_enum
ldp_get_next_hop_session_for_fec(ldp_global
* g
,
141 mpls_fec
* fec
, mpls_nexthop
*nh
, ldp_session
** next_hop_session
)
144 ldp_nexthop
*n
= NULL
;
146 MPLS_ASSERT(next_hop_session
);
148 if (!(f
= ldp_fec_find(g
, fec
))) {
149 return MPLS_NO_ROUTE
;
152 if (!(n
= ldp_fec_nexthop_find(f
, nh
))) {
153 return MPLS_NO_ROUTE
;
156 *next_hop_session
= ldp_get_next_hop_session_for_fec2(f
,n
);
157 return (*next_hop_session
) ? MPLS_SUCCESS
: MPLS_FAILURE
;
160 mpls_return_enum
Check_Received_Attributes(ldp_global
* g
, ldp_session
* s
,
161 ldp_attr
* r_attr
, uint16_t type
)
166 if (!r_attr
->hopCountTlvExists
) { /* CRa.1 */
167 goto Check_Received_Attributes_5
;
170 if (r_attr
->hopCountTlv
.hcValue
>= s
->cfg_hop_count_limit
) { /* CRa.2 */
171 LDP_PRINT(g
->user_data
, "CRa.2\n");
172 goto Check_Received_Attributes_6
;
175 if (!r_attr
->pathVecTlvExists
) { /* CRa.3 */
176 goto Check_Received_Attributes_5
;
179 for (i
= 0; i
< MPLS_MAXHOPSNUMBER
; i
++) { /* CRa.4 */
180 if (r_attr
->pathVecTlv
.lsrId
[i
]) {
182 if (r_attr
->pathVecTlv
.lsrId
[i
] == g
->lsr_identifier
.u
.ipv4
) {
183 goto Check_Received_Attributes_6
;
184 LDP_PRINT(g
->user_data
, "CRa.4a\n");
186 if (count
> s
->oper_path_vector_limit
) {
187 goto Check_Received_Attributes_6
;
188 LDP_PRINT(g
->user_data
, "CRa.4b\n");
193 Check_Received_Attributes_5
:
196 Check_Received_Attributes_6
:
197 if (type
!= MPLS_LBLMAP_MSGTYPE
) {
198 ldp_notif_send(g
, s
, r_attr
, LDP_NOTIF_LOOP_DETECTED
); /* CRa.7 */
200 return MPLS_FAILURE
; /* CRa.8 */
203 void Prepare_Label_Mapping_Attributes(ldp_global
* g
, ldp_session
* s
,
204 mpls_fec
* fec
, ldp_attr
* r_attr
, ldp_attr
* s_attr
, mpls_bool propogating
,
205 mpls_bool already
, mpls_bool egress
)
210 /* NOTE: PMpA.21 is the end of the procedure (ie return) */
211 /* this function uses goto quite extensivly for a REASON!! */
212 /* Check Appedix A of the LDP draft */
214 LDP_ENTER(g
->user_data
, "Prepare_Label_Mapping_Attributes");
217 memset(&dummy
, 0, sizeof(ldp_attr
));
218 mpls_fec2fec_tlv(fec
, &dummy
.fecTlv
, 0);
219 dummy
.fecTlvExists
= 1;
220 dummy
.fecTlv
.numberFecElements
= 1;
224 if (!(s
->oper_loop_detection
== LDP_LOOP_HOPCOUNT
||
225 s
->oper_loop_detection
== LDP_LOOP_HOPCOUNT_PATHVECTOR
||
226 r_attr
->hopCountTlvExists
)) { /* PMpA.1 */
227 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
231 if (egress
) {/* PMpA.2 */
232 /* I'm egress (for now) */
233 s_attr
->hopCountTlvExists
= 1;
234 s_attr
->hopCountTlv
.hcValue
= 1; /* PMpA.3 */
235 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
239 if (!(r_attr
->hopCountTlvExists
)) { /* PMpA.4 */
240 goto Prepare_Label_Mapping_Attributes_8
;
243 if (!(g
->ttl_less_domain
== MPLS_BOOL_TRUE
&&
244 s
->cfg_remote_in_ttl_less_domain
== MPLS_BOOL_TRUE
)) { /* PMpA.5 */
245 goto Prepare_Label_Mapping_Attributes_7
;
248 s_attr
->hopCountTlvExists
= 1;
249 s_attr
->hopCountTlv
.hcValue
= 1; /* PMpA.6 */
250 goto Prepare_Label_Mapping_Attributes_9
;
252 Prepare_Label_Mapping_Attributes_7
:
253 s_attr
->hopCountTlvExists
= 1;
254 s_attr
->hopCountTlv
.hcValue
= (r_attr
->hopCountTlv
.hcValue
) ?
255 (r_attr
->hopCountTlv
.hcValue
+ 1) : 0;
256 goto Prepare_Label_Mapping_Attributes_9
;
258 Prepare_Label_Mapping_Attributes_8
:
259 s_attr
->hopCountTlvExists
= 1;
260 s_attr
->hopCountTlv
.hcValue
= 0;
262 Prepare_Label_Mapping_Attributes_9
:
263 if (s
->oper_loop_detection
== LDP_LOOP_NONE
) {
264 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
268 if (r_attr
->pathVecTlvExists
) { /* PMpA.10 */
269 goto Prepare_Label_Mapping_Attributes_19
;
272 if (propogating
== MPLS_BOOL_FALSE
) { /* PMpA.11 */
273 goto Prepare_Label_Mapping_Attributes_20
;
276 if (g
->label_merge
!= MPLS_BOOL_TRUE
) { /* PMpA.12 */
277 goto Prepare_Label_Mapping_Attributes_14
;
280 if (already
== MPLS_BOOL_FALSE
) { /* PMpA.13 */
281 goto Prepare_Label_Mapping_Attributes_20
;
284 Prepare_Label_Mapping_Attributes_14
:
285 if (!r_attr
->hopCountTlvExists
) {
286 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
290 if (r_attr
->hopCountTlv
.hcValue
== 0) { /* PMpA.15 */
291 goto Prepare_Label_Mapping_Attributes_20
;
294 if (already
== MPLS_BOOL_FALSE
) { /* PMpA.16 */
295 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
299 /* r_attr contain PrevHopCount _IF_ we had one */
300 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
301 return; /* PMpA.17 */
303 if (r_attr
->hopCountTlv
.hcValue
!= 0) { /* PMpA.18 */
304 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
308 Prepare_Label_Mapping_Attributes_19
:
309 s_attr
->pathVecTlvExists
= 1;
310 s_attr
->pathVecTlv
.lsrId
[0] = g
->lsr_identifier
.u
.ipv4
;
311 for (i
= 1; i
< (MPLS_MAXHOPSNUMBER
- 1); i
++) {
312 if (r_attr
->pathVecTlv
.lsrId
[i
- 1]) {
313 s_attr
->pathVecTlv
.lsrId
[0] = r_attr
->pathVecTlv
.lsrId
[i
- 1];
317 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
320 Prepare_Label_Mapping_Attributes_20
:
321 s_attr
->pathVecTlvExists
= 1;
322 s_attr
->pathVecTlv
.lsrId
[0] = g
->lsr_identifier
.u
.ipv4
;
324 LDP_EXIT(g
->user_data
, "Prepare_Label_Mapping_Attributes");
328 void map2attr(mplsLdpLblMapMsg_t
* map
, ldp_attr
* attr
, uint32_t flag
)
330 attr
->msg_id
= map
->baseMsg
.msgId
;
332 if (map
->fecTlvExists
&& flag
& LDP_ATTR_FEC
) {
333 memcpy(&attr
->fecTlv
, &map
->fecTlv
, sizeof(mplsLdpFecTlv_t
));
334 attr
->fecTlvExists
= 1;
336 if (map
->genLblTlvExists
&& flag
& LDP_ATTR_LABEL
) {
337 memcpy(&attr
->genLblTlv
, &map
->genLblTlv
, sizeof(mplsLdpGenLblTlv_t
));
338 attr
->genLblTlvExists
= 1;
339 } else if (map
->atmLblTlvExists
&& flag
& LDP_ATTR_LABEL
) {
340 memcpy(&attr
->atmLblTlv
, &map
->atmLblTlv
, sizeof(mplsLdpAtmLblTlv_t
));
341 attr
->atmLblTlvExists
= 1;
342 } else if (map
->frLblTlvExists
&& flag
& LDP_ATTR_LABEL
) {
343 memcpy(&attr
->frLblTlv
, &map
->frLblTlv
, sizeof(mplsLdpFrLblTlv_t
));
344 attr
->frLblTlvExists
= 1;
346 if (map
->hopCountTlvExists
&& flag
& LDP_ATTR_HOPCOUNT
) {
347 memcpy(&attr
->hopCountTlv
, &map
->hopCountTlv
, sizeof(mplsLdpHopTlv_t
));
348 attr
->hopCountTlvExists
= 1;
350 if (map
->pathVecTlvExists
&& flag
& LDP_ATTR_PATH
) {
351 memcpy(&attr
->pathVecTlv
, &map
->pathVecTlv
, sizeof(mplsLdpPathTlv_t
));
352 attr
->pathVecTlvExists
= 1;
354 if (map
->lblMsgIdTlvExists
&& flag
& LDP_ATTR_MSGID
) {
355 memcpy(&attr
->lblMsgIdTlv
, &map
->lblMsgIdTlv
, sizeof(mplsLdpLblMsgIdTlv_t
));
356 attr
->lblMsgIdTlvExists
= 1;
358 if (map
->lspidTlvExists
&& flag
& LDP_ATTR_LSPID
) {
359 memcpy(&attr
->lspidTlv
, &map
->lspidTlv
, sizeof(mplsLdpLspIdTlv_t
));
360 attr
->lspidTlvExists
= 1;
362 if (map
->trafficTlvExists
&& flag
& LDP_ATTR_TRAFFIC
) {
363 memcpy(&attr
->trafficTlv
, &map
->trafficTlv
, sizeof(mplsLdpTrafficTlv_t
));
364 attr
->trafficTlvExists
= 1;
368 void attr2map(ldp_attr
* attr
, mplsLdpLblMapMsg_t
* map
)
370 if (attr
->fecTlvExists
) {
371 memcpy(&map
->fecTlv
, &attr
->fecTlv
, sizeof(mplsLdpFecTlv_t
));
372 map
->fecTlvExists
= 1;
374 if (attr
->genLblTlvExists
) {
375 memcpy(&map
->genLblTlv
, &attr
->genLblTlv
, sizeof(mplsLdpGenLblTlv_t
));
376 map
->genLblTlvExists
= 1;
378 if (attr
->atmLblTlvExists
) {
379 memcpy(&map
->atmLblTlv
, &attr
->atmLblTlv
, sizeof(mplsLdpAtmLblTlv_t
));
380 map
->atmLblTlvExists
= 1;
382 if (attr
->frLblTlvExists
) {
383 memcpy(&map
->frLblTlv
, &attr
->frLblTlv
, sizeof(mplsLdpFrLblTlv_t
));
384 map
->frLblTlvExists
= 1;
386 if (attr
->hopCountTlvExists
) {
387 memcpy(&map
->hopCountTlv
, &attr
->hopCountTlv
, sizeof(mplsLdpHopTlv_t
));
388 map
->hopCountTlvExists
= 1;
390 if (attr
->pathVecTlvExists
) {
391 memcpy(&map
->pathVecTlv
, &attr
->pathVecTlv
, sizeof(mplsLdpPathTlv_t
));
392 map
->pathVecTlvExists
= 1;
394 if (attr
->lblMsgIdTlvExists
) {
395 memcpy(&map
->lblMsgIdTlv
, &attr
->lblMsgIdTlv
, sizeof(mplsLdpLblMsgIdTlv_t
));
396 map
->lblMsgIdTlvExists
= 1;
398 if (attr
->lspidTlvExists
) {
399 memcpy(&map
->lspidTlv
, &attr
->lspidTlv
, sizeof(mplsLdpLspIdTlv_t
));
400 map
->lspidTlvExists
= 1;
402 if (attr
->trafficTlvExists
) {
403 memcpy(&map
->trafficTlv
, &attr
->trafficTlv
, sizeof(mplsLdpTrafficTlv_t
));
404 map
->trafficTlvExists
= 1;
408 void ldp_label_mapping_initial_callback(mpls_timer_handle timer
, void *extra
,
409 mpls_cfg_handle handle
)
411 ldp_session
*s
= (ldp_session
*) extra
;
412 ldp_global
*g
= (ldp_global
*)handle
;
413 ldp_attr
*ds_attr
= NULL
;
414 ldp_attr
*us_attr
= NULL
;
415 ldp_session
*nh_session
= NULL
;
416 mpls_bool done
= MPLS_BOOL_FALSE
;
420 LDP_ENTER(g
->user_data
, "ldp_label_mapping_initial_callback");
422 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
, LDP_TRACE_FLAG_TIMER
,
423 "Initial Label Mapping fired: session(%d)\n", s
->index
);
425 mpls_lock_get(g
->global_lock
);
427 mpls_timer_stop(g
->timer_handle
, timer
);
429 f
= MPLS_LIST_HEAD(&g
->fec
);
431 nh
= MPLS_LIST_HEAD(&f
->nh_root
);
433 switch (f
->info
.type
) {
434 case MPLS_FEC_PREFIX
:
435 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
436 LDP_TRACE_FLAG_ROUTE
, "Processing prefix FEC: %08x/%d ",
437 f
->info
.u
.prefix
.network
.u
.ipv4
, f
->info
.u
.prefix
.length
);
440 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
441 LDP_TRACE_FLAG_ROUTE
, "Processing host FEC: %08x ",
442 f
->info
.u
.host
.u
.ipv4
);
445 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
446 LDP_TRACE_FLAG_ROUTE
, "Processingu L2CC FEC: %d %d %d ",
447 f
->info
.u
.l2cc
.connection_id
, f
->info
.u
.l2cc
.group_id
,
448 f
->info
.u
.l2cc
.type
);
454 if (nh
->info
.type
& MPLS_NH_IP
) {
455 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
456 LDP_TRACE_FLAG_ROUTE
, "via %08x\n", nh
->addr
->address
.u
.ipv4
);
458 if (nh
->info
.type
& MPLS_NH_IF
&& nh
->iff
) {
459 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
460 LDP_TRACE_FLAG_ROUTE
, "via %p\n", nh
->iff
->handle
);
463 /* are we allowed to export this route from the rib */
464 if (mpls_policy_export_check(g
->user_data
, &f
->info
, &nh
->info
) ==
466 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
467 LDP_TRACE_FLAG_POLICY
, "Rejected by export policy\n");
468 goto ldp_label_mapping_initial_callback_end_nh
;
471 /* have we already sent a mapping for this fec to the new session? */
472 if ((us_attr
= ldp_attr_find_upstream_state2(g
, s
, f
,
473 LDP_LSP_STATE_MAP_SENT
))) {
474 /* no need to sent another mapping */
475 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
476 LDP_TRACE_FLAG_ROUTE
, "Already sent this FEC to session %d\n",
478 goto ldp_label_mapping_initial_callback_end_nh
;
481 if (!(nh_session
= ldp_get_next_hop_session_for_fec2(f
,nh
))) {
484 if (nh_session
->index
== s
->index
) {
485 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
,
486 LDP_TRACE_FLAG_ROUTE
, "Nexthop session(%d) == session(%d)\n",
487 nh_session
->index
, s
->index
);
488 goto ldp_label_mapping_initial_callback_end_nh
;
490 ds_attr
= ldp_attr_find_downstream_state2(g
, nh_session
, f
,
491 LDP_LSP_STATE_MAP_RECV
);
494 if ((g
->label_merge
!= MPLS_BOOL_TRUE
) &&
495 ldp_attr_num_us2ds(ds_attr
)) {
496 /* we have a ds label, but can't use it */
502 /* we can use it, merge on baby */
503 ldp_label_mapping_with_xc(g
, s
, f
, &us_attr
, ds_attr
);
505 /* we don't have a ds label */
507 /* we will be egress? */
508 if (g
->lsp_control_mode
== LDP_CONTROL_ORDERED
) {
509 if (mpls_policy_egress_check(g
->user_data
, &f
->info
,
510 &nh
->info
) == MPLS_BOOL_TRUE
) {
511 ldp_label_mapping_with_xc(g
, s
, f
, &us_attr
, NULL
);
514 ldp_label_mapping_with_xc(g
, s
, f
, &us_attr
, NULL
);
517 ldp_label_mapping_initial_callback_end_nh
:
518 nh
= MPLS_LIST_NEXT(&f
->nh_root
, nh
, _fec
);
520 f
= MPLS_LIST_NEXT(&g
->fec
, f
, _global
);
522 done
= MPLS_BOOL_TRUE
;
524 if (done
== MPLS_BOOL_TRUE
) {
525 mpls_timer_delete(g
->timer_handle
, timer
);
526 MPLS_REFCNT_RELEASE(s
, ldp_session_delete
);
527 s
->initial_distribution_timer
= (mpls_timer_handle
) 0;
529 mpls_timer_start(g
->timer_handle
, timer
, MPLS_TIMER_ONESHOT
);
530 /* need to mark the session with where it left off */
533 mpls_lock_release(g
->global_lock
);
535 LDP_EXIT(g
->user_data
, "ldp_label_mapping_initial_callback");
538 mpls_return_enum
ldp_label_mapping_send(ldp_global
* g
, ldp_session
* s
,
539 ldp_fec
*f
, ldp_attr
* us_attr
, ldp_attr
* ds_attr
)
541 ldp_inlabel
*in
= NULL
;
542 ldp_attr
*us_temp
, *existing
= NULL
;
544 LDP_ENTER(g
->user_data
, "ldp_label_mapping_send");
545 MPLS_ASSERT(us_attr
);
549 * before we can enable this, inlabels need to keep track of all of
550 * the attr that link to it. Then when running in DU independent mode we
551 * can correctly attach the us and ds attrs involved when propogating a
552 * new mapping for a FEC we've already distributed labels for
554 existing
= ldp_attr_find_upstream_map_in_labelspace(f
, s
->cfg_label_space
);
558 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
, LDP_TRACE_FLAG_BINDING
,
559 "Using an existing label\n");
560 in
= existing
->inlabel
;
561 ldp_attr_add_inlabel(us_attr
, in
);
563 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
, LDP_TRACE_FLAG_BINDING
,
564 "Generating a label\n");
565 in
= ldp_inlabel_create_complete(g
, s
, us_attr
);
568 if (!in
) { /* SL.1-3 */
572 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
, LDP_TRACE_FLAG_BINDING
,
575 us_attr
->state
= LDP_LSP_STATE_MAP_SENT
;
577 us_attr
->msg_id
= g
->message_identifier
;
578 ldp_label_mapping_prepare_msg(s
->tx_message
, g
->message_identifier
++,
581 if (ldp_mesg_send_tcp(g
, s
, s
->tx_message
) != MPLS_SUCCESS
) { /* SL.4 */
582 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_SEND
, LDP_TRACE_FLAG_ERROR
,
583 "Failed sending Label Mapping to %s\n",
585 goto ldp_label_mapping_send_error
;
588 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_SEND
, LDP_TRACE_FLAG_LABEL
,
589 "Label Mapping Sent to %s for %08x/%d\n",
591 us_attr
->fecTlv
.fecElArray
[0].addressEl
.address
,
592 us_attr
->fecTlv
.fecElArray
[0].addressEl
.preLen
);
594 us_attr
->state
= LDP_LSP_STATE_MAP_SENT
; /* SL.6,7 */
596 LDP_EXIT(g
->user_data
, "ldp_label_mapping_send");
597 return MPLS_SUCCESS
; /* SL.8 */
600 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
, LDP_TRACE_FLAG_STATE
,
601 "No Label Resources\n");
603 while ((us_temp
= ldp_attr_find_upstream_state2(g
, s
, us_attr
->fec
,
604 LDP_LSP_STATE_REQ_RECV
)) != NULL
) { /* SL.9 */
605 ldp_notif_send(g
, s
, us_temp
, LDP_NOTIF_NO_LABEL_RESOURCES_AVAILABLE
);
607 s
->no_label_resource_sent
= MPLS_BOOL_TRUE
; /* SL.12 */
608 us_temp
->state
= LDP_LSP_STATE_NO_LABEL_RESOURCE_SENT
; /* SL.13 */
611 LDP_EXIT(g
->user_data
, "ldp_label_mapping_send");
615 ldp_label_mapping_send_error
:
617 LDP_EXIT(g
->user_data
, "ldp_label_mapping_send-error");
621 void ldp_label_mapping_prepare_msg(ldp_mesg
* msg
, uint32_t msgid
,
624 mplsLdpLblMapMsg_t
*map
= NULL
;
629 ldp_mesg_prepare(msg
, MPLS_LBLMAP_MSGTYPE
, msgid
);
632 if (s_attr
->fecTlvExists
) {
633 /* JLEU: only 1 FEC is allowed!! */
634 map
->fecTlvExists
= 1;
635 map
->baseMsg
.msgLength
+= setupFecTlv(&map
->fecTlv
);
636 map
->baseMsg
.msgLength
+= addFecElem2FecTlv(&map
->fecTlv
,
637 &s_attr
->fecTlv
.fecElArray
[0]);
639 if (s_attr
->genLblTlvExists
) {
640 map
->genLblTlvExists
= 1;
641 map
->baseMsg
.msgLength
+= setupGenLblTlv(&map
->genLblTlv
,
642 s_attr
->genLblTlv
.label
);
644 if (s_attr
->atmLblTlvExists
) {
645 map
->atmLblTlvExists
= 1;
646 map
->baseMsg
.msgLength
+= setupAtmLblTlv(&map
->atmLblTlv
, 0, 0,
647 s_attr
->atmLblTlv
.flags
.flags
.vpi
, s_attr
->atmLblTlv
.vci
);
649 if (s_attr
->frLblTlvExists
) {
650 map
->frLblTlvExists
= 1;
651 map
->baseMsg
.msgLength
+= setupFrLblTlv(&map
->frLblTlv
, 0,
652 s_attr
->frLblTlv
.flags
.flags
.len
, s_attr
->frLblTlv
.flags
.flags
.dlci
);
654 if (s_attr
->hopCountTlvExists
) {
655 map
->hopCountTlvExists
= 1;
656 map
->baseMsg
.msgLength
+= setupHopCountTlv(&map
->hopCountTlv
,
657 s_attr
->hopCountTlv
.hcValue
);
659 if (s_attr
->pathVecTlvExists
) {
660 map
->pathVecTlvExists
= 1;
661 map
->baseMsg
.msgLength
+= setupPathTlv(&map
->pathVecTlv
);
662 for (i
= 0; i
< MPLS_MAXHOPSNUMBER
; i
++) {
663 if (s_attr
->pathVecTlv
.lsrId
[i
]) {
664 map
->baseMsg
.msgLength
+= addLsrId2PathTlv(&map
->pathVecTlv
,
665 s_attr
->pathVecTlv
.lsrId
[i
]);
670 if (s_attr
->lblMsgIdTlvExists
) {
672 if (s_attr
->lspidTlvExists
) {
674 if (s_attr
->trafficTlvExists
) {
679 mpls_return_enum
ldp_label_mapping_process(ldp_global
* g
, ldp_session
* s
,
680 ldp_adj
* a
, ldp_entity
* e
, ldp_attr
* r_attr
, ldp_fec
* f
)
682 mpls_return_enum retval
= MPLS_SUCCESS
;
683 ldp_session
*peer
= NULL
;
684 ldp_attr_list
*us_list
= NULL
;
685 ldp_attr_list
*ds_list
= NULL
;
686 ldp_attr
*ds_attr
= NULL
;
687 ldp_attr
*ds_temp
= NULL
;
688 ldp_attr
*us_attr
= NULL
;
689 ldp_attr
*us_temp
= NULL
;
691 ldp_nexthop
*nh
= NULL
;
693 ldp_outlabel
*out
= NULL
;
694 mpls_bool requested
= MPLS_BOOL_FALSE
;
695 ldp_attr
*existing
= NULL
;
696 mpls_bool need_request
= MPLS_BOOL_FALSE
;
698 LDP_ENTER(g
->user_data
, "ldp_label_mapping_process");
700 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
, LDP_TRACE_FLAG_LABEL
,
701 "Label Mapping Recv from %s for %08x/%d\n",
703 r_attr
->fecTlv
.fecElArray
[0].addressEl
.address
,
704 r_attr
->fecTlv
.fecElArray
[0].addressEl
.preLen
);
706 if ((ds_attr
= ldp_attr_find_downstream_state2(g
, s
, f
,
707 LDP_LSP_STATE_REQ_SENT
)) != NULL
) { /* LMp.1 */
708 /* just remove the req from the tree, we will use the r_attr sent to us */
709 ldp_attr_delete_downstream(g
, s
, ds_attr
);
710 requested
= MPLS_BOOL_TRUE
;
712 requested
= MPLS_BOOL_FALSE
;
716 ds_attr
->state
= LDP_LSP_STATE_MAP_RECV
; /* LMp.2 */
719 * ds_attr is the mapping we will keep and is NOT in the tree, unless
720 * it is an update mapping ...
722 if (Check_Received_Attributes(g
, s
, ds_attr
, MPLS_LBLMAP_MSGTYPE
) ==
723 MPLS_SUCCESS
) { /* LMp.3 */
728 * A loop was detected
730 if ((ds_list
= ldp_attr_find_downstream_all2(g
, s
, f
))) {
731 ds_temp
= MPLS_LIST_HEAD(ds_list
);
733 * check all the labels this session has received from "s" for "fec"
734 * do we have a duplicat?
737 if ((ds_temp
->state
== LDP_LSP_STATE_MAP_RECV
) && /* LMp.4 */
738 ldp_attr_is_equal(ds_temp
, ds_attr
, LDP_ATTR_LABEL
) == /* LMp.5 */
740 /* remove record of the label and remove it switching */
741 ldp_attr_remove_complete(g
, ds_temp
, MPLS_BOOL_TRUE
); /* LMp.6,7 */
743 * I think this is supposed to be 32 NOT 33, we need to release
748 ds_temp
= MPLS_LIST_NEXT(ds_list
, ds_temp
, _fs
);
752 LDP_PRINT(g
->user_data
, "Receive_Label_Map_8: send release");
753 if (ldp_label_release_send(g
, s
, ds_attr
, LDP_NOTIF_LOOP_DETECTED
) !=
754 MPLS_SUCCESS
) { /* LMp.8 */
755 retval
= MPLS_FAILURE
;
763 ds_temp
= ldp_attr_find_downstream_state2(g
, s
, f
, LDP_LSP_STATE_MAP_RECV
);
764 if (requested
== MPLS_BOOL_TRUE
||
765 g
->label_merge
== MPLS_BOOL_FALSE
|| !ds_temp
) {
766 /* !merging then this is always a new LSP
767 * merging w/o a recv'd mapping is a new LSP
768 * this check comes from Note 6
773 /* searching all recv'd attrs for matched mappings,
774 * stop after finding 1st match
776 if ((ds_list
= ldp_attr_find_downstream_all2(g
, s
, f
))) {
777 ds_temp
= MPLS_LIST_HEAD(ds_list
);
779 if (ds_temp
->state
== LDP_LSP_STATE_MAP_RECV
) { /* LMp.9 */
780 if (ldp_attr_is_equal(ds_attr
, ds_temp
, LDP_ATTR_LABEL
) ==
781 MPLS_BOOL_TRUE
) { /* LMp.10 */
783 * this mapping matches an existing mapping, but it
784 * could contain updated attributes
790 * we have been given another label for the same FEC and we
791 * didn't request it, release it
793 LDP_PRINT(g
->user_data
, "LMp.10 dup without req\n");
797 ds_temp
= MPLS_LIST_NEXT(ds_list
, ds_temp
, _fs
);
801 ldp_attr2ldp_attr(ds_attr
, existing
, LDP_ATTR_HOPCOUNT
| LDP_ATTR_PATH
|
802 LDP_ATTR_MSGID
| LDP_ATTR_LSPID
| LDP_ATTR_TRAFFIC
);
805 * no need to free ds_attr, since it was not added to the tree it
806 * will be deleted when we exit ldp_label_mapping_process(), see
807 * ldp_state_process().
811 * from this point on.... if this is an updated mapping then ds_attr
812 * is the existing mapping which has now been update, else ds_attr
818 * existing ONLY has a value for updated label mapping
820 nh
= ldp_nexthop_for_fec_session(f
,s
); /* LMp.11 */
823 * the following departs from the procedure, it allows for filtering
826 * Are we configured to accept and INSTALL this mapping?
828 if (mpls_policy_import_check(g
->user_data
, &f
->info
, &nh
->info
) ==
831 * policy has rejected it, store it away
833 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
, LDP_TRACE_FLAG_LABEL
,
834 "Label Mapping for %08x/%d from %s filtered by import policy\n",
835 r_attr
->fecTlv
.fecElArray
[0].addressEl
.address
,
836 r_attr
->fecTlv
.fecElArray
[0].addressEl
.preLen
, s
->session_name
);
839 ds_attr
->filtered
= MPLS_BOOL_TRUE
;
840 if (ds_attr
->outlabel
&& ds_attr
->outlabel
->switching
== MPLS_BOOL_TRUE
) {
841 /* the mapping has been filtered, but the original wasn't? */
845 ds_attr
->filtered
= MPLS_BOOL_TRUE
;
846 if (ldp_attr_insert_downstream(g
, s
, ds_attr
) != MPLS_SUCCESS
) {
847 retval
= MPLS_FAILURE
;
853 if (!nh
) { /* LMp.12 */
855 * if we did not find a nh hop for this FEC that corresponded to the
856 * MsgSource then the MsgSource is not a nexthop for the FEC
858 if (g
->label_retention_mode
== LDP_RETENTION_CONSERVATIVE
) { /* LMp.13C */
859 LDP_PRINT(g
->user_data
, "LMp.13C conservative\n");
866 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
, LDP_TRACE_FLAG_LABEL
,
867 "Session %s is not a valid nexthop for %08x/%d\n", s
->session_name
,
868 r_attr
->fecTlv
.fecElArray
[0].addressEl
.address
,
869 r_attr
->fecTlv
.fecElArray
[0].addressEl
.preLen
);
873 if (ldp_attr_insert_downstream(g
, s
, ds_attr
) != MPLS_SUCCESS
) {
874 retval
= MPLS_FAILURE
;
881 * this is slightly different form the procedure, we can still be
882 * transit for a FEC we are not configured to be ingress for.
883 * Either way we only need to do the "install for fwd/switching"
884 * only once. We could arrive here multiple times due to updates,
885 * only install it the first time
887 if ((!existing
) || (!existing
->outlabel
)) {
889 * we haven't installed it yet.
890 * Either new (!existing), or a result of a "Detect FEC Nexthop Change"
891 * and we had this mapping in our database (!existing->outlabel))
894 if (!(out
= ldp_outlabel_create_complete(g
, s
, ds_attr
, nh
))) {
895 LDP_PRINT(g
->user_data
, "LMp.15 failure creating outlabel\n");
899 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_ALL
, LDP_TRACE_FLAG_BINDING
,
900 "Out Label Added\n");
904 * are we configured to act as ingress for this FEC?
906 if (mpls_policy_ingress_check(g
->user_data
, &f
->info
, &nh
->info
) ==
907 MPLS_BOOL_TRUE
) { /* LMp.14 */
909 * yep, bind the label to the FEC
911 if (ds_attr
->ingress
!= MPLS_BOOL_TRUE
) {
914 ftn
.outsegment_index
= ds_attr
->outlabel
->info
.handle
;
915 memcpy(&ftn
.fec
, &f
->info
, sizeof(mpls_fec
));
916 lsr_cfg_ftn_set2(g
->lsr_handle
, &ftn
, LSR_CFG_ADD
|LSR_FTN_CFG_FEC
|
917 LSR_FTN_CFG_OUTSEGMENT
);
919 mpls_mpls_fec2out_add(g
->mpls_handle
, &f
->info
, &ds_attr
->outlabel
->info
);
921 ds_attr
->ingress
= MPLS_BOOL_TRUE
;
922 ds_attr
->outlabel
->merge_count
++;
923 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
, LDP_TRACE_FLAG_BINDING
,
924 "Acting as ingress for %08x/%d from %s\n",
925 r_attr
->fecTlv
.fecElArray
[0].addressEl
.address
,
926 r_attr
->fecTlv
.fecElArray
[0].addressEl
.preLen
, s
->session_name
);
930 /* create a set of attrs that we will fill and compare against
931 * if this mapping were to be propogate these are the attrs it would have
932 * by comparing what we did sent in the past to these, we con figure out
933 * if we need to send an updated mapping
935 memset(&dumb_attr
, 0, sizeof(ldp_attr
));
936 mpls_fec2fec_tlv(&f
->info
, &dumb_attr
.fecTlv
, 0);
937 dumb_attr
.fecTlvExists
= 1;
938 dumb_attr
.fecTlv
.numberFecElements
= 1;
941 * by definition (we received a label mapping that will be used) this
942 * LSR is _not_ the egress, so calculate a hop and path based on the
943 * mapping we received. We will compare this with mapping that have
944 * already been sent. If they differ, we will send an updated mapping
946 Prepare_Label_Mapping_Attributes(g
, s
, &f
->info
, ds_attr
, &dumb_attr
,
947 MPLS_BOOL_TRUE
, MPLS_BOOL_TRUE
, MPLS_BOOL_FALSE
);
951 * this is the first time we've seen this mapping, add it to the database.
952 * all future updates will modify this entry in place
955 if (ldp_attr_insert_downstream(g
, s
, ds_attr
) != MPLS_SUCCESS
) {
956 retval
= MPLS_FAILURE
;
961 peer
= MPLS_LIST_HEAD(&g
->session
);
962 while (peer
) { /* LMp.17 */
964 /* can't send messages to non-operational sessions */
965 if (peer
->state
!= LDP_STATE_OPERATIONAL
) {
970 * don't send the mapping to the session
971 * from which we recv'd the mapping
973 if (peer
->index
== s
->index
) {
978 * it is just as easy to walk the list of all upstream attr for this
979 * peer as it is to the individual check to see if we have sent a
980 * label mapping for this FEC LSP
984 if ((us_list
= ldp_attr_find_upstream_all2(g
, peer
, f
))) {
985 us_temp
= MPLS_LIST_HEAD(us_list
);
988 * if we have sent a label mapping for the FEC and that label mapping
989 * was an done in independent mode or it is part of an LSP created
990 * due as part of an existing received label mapping
993 if (us_temp
->state
== LDP_LSP_STATE_MAP_SENT
) {
995 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
,
996 LDP_TRACE_FLAG_BINDING
, "Already sent mapping for %08x/%d to %s\n",
997 r_attr
->fecTlv
.fecElArray
[0].addressEl
.address
,
998 r_attr
->fecTlv
.fecElArray
[0].addressEl
.preLen
, peer
->session_name
);
1000 if ((!existing
) || (existing
->index
== us_temp
->ds_attr
->index
)) {
1002 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
,
1003 LDP_TRACE_FLAG_BINDING
, "Part of same LSP\n");
1006 if (ldp_attr_is_equal(us_temp
, &dumb_attr
,
1007 LDP_ATTR_HOPCOUNT
| LDP_ATTR_PATH
) != MPLS_BOOL_TRUE
) {
1009 LDP_TRACE_LOG(g
->user_data
, MPLS_TRACE_STATE_RECV
,
1010 LDP_TRACE_FLAG_BINDING
, "Propogating updated attrs\n");
1012 /* send an updated label mapping */
1013 if (ldp_label_mapping_with_xc(g
, us_temp
->session
, f
, &us_temp
,
1014 ds_attr
) != MPLS_SUCCESS
) { /* LMp.24-26 */
1015 retval
= MPLS_FAILURE
;
1021 us_temp
= MPLS_LIST_NEXT(us_list
, us_temp
, _fs
);
1025 if ((peer
->oper_distribution_mode
== LDP_DISTRIBUTION_UNSOLICITED
) &&
1026 (g
->lsp_control_mode
== LDP_CONTROL_ORDERED
)) { /* LMp.19 */
1029 * if we're not merging and we have multiple ORDERED DU sessions,
1030 * we will need to start requesting labels after we propogate the
1031 * mapping to the first peer
1033 if (need_request
== MPLS_BOOL_TRUE
) {
1034 if (ldp_attr_find_downstream_state2(g
, peer
, f
,
1035 LDP_LSP_STATE_REQ_SENT
) == NULL
) {
1037 * we don't have a request for FEC to peer outstanding, make one
1040 if (ldp_label_request_for_xc(g
, peer
, &f
->info
, NULL
, &ds_temp
) !=
1042 retval
= MPLS_FAILURE
;
1048 * We're in DU more, either we're merging, or we're not merging and
1049 * this is the first peer we're propogating this mapping to
1053 if (ldp_label_mapping_with_xc(g
, peer
, f
, &us_attr
, ds_attr
) !=
1055 retval
= MPLS_FAILURE
;
1059 * if we're not merging, we will need to request a label for
1062 if (g
->label_merge
== MPLS_BOOL_FALSE
) {
1063 need_request
= MPLS_BOOL_TRUE
;
1069 while ((us_temp
= ldp_attr_find_upstream_state2(g
, peer
, f
,
1070 LDP_LSP_STATE_REQ_RECV
))) {
1072 if (peer
->oper_distribution_mode
== LDP_DISTRIBUTION_UNSOLICITED
) {
1073 if (need_request
== MPLS_BOOL_TRUE
) {
1074 if (ldp_attr_find_downstream_state2(g
, peer
, f
,
1075 LDP_LSP_STATE_REQ_SENT
) == NULL
) {
1077 * we don't have a request for FEC to peer outstanding
1080 if (ldp_label_request_for_xc(g
, peer
, &f
->info
, us_temp
,
1081 &ds_temp
) != MPLS_SUCCESS
) {
1082 retval
= MPLS_FAILURE
;
1087 if (ldp_label_mapping_with_xc(g
, peer
, f
, &us_temp
,
1088 ds_attr
) != MPLS_SUCCESS
) {
1089 retval
= MPLS_FAILURE
;
1094 if ((us_list
= ldp_attr_find_upstream_all2(g
, peer
, f
))) {
1095 us_temp
= MPLS_LIST_HEAD(ds_list
);
1097 if (us_temp
->state
== LDP_LSP_STATE_REQ_RECV
) {
1098 if (need_request
== MPLS_BOOL_TRUE
) {
1099 if (ldp_attr_find_downstream_state2(g
, peer
, f
,
1100 LDP_LSP_STATE_REQ_SENT
) == NULL
) {
1102 * we don't have a request for FEC to peer outstanding
1105 if (ldp_label_request_for_xc(g
, peer
, &f
->info
, us_temp
,
1106 &ds_temp
) != MPLS_SUCCESS
) {
1107 retval
= MPLS_FAILURE
;
1112 if (ldp_label_mapping_with_xc(g
, peer
, f
, &us_temp
,
1113 ds_attr
) != MPLS_SUCCESS
) {
1114 retval
= MPLS_FAILURE
;
1118 * if we're not merging, we will need to request a label for
1121 if (g
->label_merge
== MPLS_BOOL_FALSE
) {
1122 need_request
= MPLS_BOOL_TRUE
;
1126 us_temp
= MPLS_LIST_NEXT(us_list
, us_temp
, _fs
);
1133 peer
= MPLS_LIST_NEXT(&g
->session
, peer
, _global
);
1137 LDP_EXIT(g
->user_data
, "ldp_label_mapping_process");
1141 LDP_PRINT(g
->user_data
, "Receive_Label_Map_32: send release");
1142 if (ldp_label_release_send(g
, s
, ds_attr
, LDP_NOTIF_NONE
) != MPLS_SUCCESS
) {
1143 retval
= MPLS_FAILURE
;
1145 LDP_EXIT(g
->user_data
, "ldp_label_mapping_process");