📄 loopdect.c
字号:
/* ****************************************************************** */
/* Product Name:MPLS PACK
/* Module Name: LDP File Name : LOOPDECT.C
/* Creat Date: 2002-1-16 Author : shi.zhaohui, sun baoping
/* Version: 1.0
/* History:
/* Date Version Modifier Activies
/* modify:
/* Change loop detection from router to one interface sbp 2002-1-16
/* loop detection for dod and du szh 2002-7-1
/* 2003.3.4 huyonghong modify path vector memmory manage
/* 2003-12-10 lixia mod for debug mpls */
/* ****************************************************************** */
#include "ldpvars.h"
/***********************************************************************/
/* FUNCTION NAME : loopdetcetpro()
/* DESCRIPTION: : when loop, process function
/* INPUT : unsigned short eventType,
void *inputMsg,
mplsLdpSession_t * session
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.07.1
/* GLOBAL : none
/* History :
/************************************************************************/
short loopdetcetpro(unsigned short eventType, void *inputMsg, mplsLdpSession_t * session)
{
unsigned long loopresult;
mplsLdpLblReqMsg_t *lblReqMsg;
mplsLdpLblMapMsg_t *lblMapMsg;
loopresult = funcloopdetect(eventType, inputMsg, session);
if(loopresult == LOOPDETECT)
{
if( eventType == MPLS_LBLREQ_MSGTYPE)
{
lblReqMsg = (mplsLdpLblReqMsg_t *)inputMsg;
sndnotifymsgproc(session, LOOPDETECT,lblReqMsg -> baseMsg.msgId,
MPLS_LBLREQ_MSGTYPE);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP, "==== label request message, find loop !!!====\n");
printf("==== label request message, find loop !!!====");
return LDP_FALSE;
}
else if( eventType == MPLS_LBLMAP_MSGTYPE)
{
lblMapMsg = (mplsLdpLblMapMsg_t *)inputMsg;
sndnotifymsgproc(session, LOOPDETECT,lblMapMsg -> baseMsg.msgId,
MPLS_LBLMAP_MSGTYPE);
FuncSendLblRelease(session, lblMapMsg);
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP, "==== label mapping message, find loop !!!====\n");
printf("==== label mapping message, find loop !!!====");
return LDP_FALSE;
}
}
return LDP_TRUE;
}
/***********************************************************************/
/* FUNCTION NAME : FuncSendLblRelease()
/* DESCRIPTION: : when mapping message loop, send label release to down
/* INPUT : mplsLdpSession_t * session,
mplsLdpLblMapMsg_t * lblMapMsg
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.07.1
/* GLOBAL : none
/* History :
/************************************************************************/
void FuncSendLblRelease(mplsLdpSession_t * session, mplsLdpLblMapMsg_t * lblMapMsg)
{
mplsLdpLbl_W_R_Msg_t lblRelMsg;
memset(&lblRelMsg,0,sizeof(mplsLdpLbl_W_R_Msg_t));
lblRelMsg.baseMsg.msgId = messageId[LBL_W_R_M];
lblRelMsg.baseMsg.flags.flags.msgType = MPLS_LBLREL_MSGTYPE;
lblRelMsg.baseMsg.flags.flags.uBit = 0;
AddMsgId(LBL_W_R_M);
lblRelMsg.fecTlvExists = 1;
MPLS_MEMCPY(&lblRelMsg.fecTlv,&lblMapMsg->fecTlv,sizeof(mplsLdpFecTlv_t));
/* if(lblMapMsg->genLblTlvExists == 1)
{
lblRelMsg.genLblTlvExists = 1;
genlbltolblmsg(lblMapMsg -> genLblTlv.label, &(lblRelMsg.genLblTlv));
}
else if(lblMapMsg->atmLblTlvExists == 1)
{
lblRelMsg.atmLblTlvExists = 1;
atmlbltolblmsg(lblMapMsg->atmLblTlv.flags.flags.vpi,
lblMapMsg->atmLblTlv.vci,
&(lblRelMsg.atmLblTlv));
} */
if(lblMapMsg->genLblTlvExists == 1)
{
lblRelMsg.genLblTlvExists = 1;
MPLS_MEMCPY(&lblRelMsg.genLblTlv,&lblMapMsg->genLblTlv,sizeof(mplsLdpGenLblTlv_t));
}
if(lblMapMsg->atmLblTlvExists == 1)
{
lblRelMsg.atmLblTlvExists = 1;
MPLS_MEMCPY(&lblRelMsg.atmLblTlv,&lblMapMsg->atmLblTlv,sizeof(mplsLdpAtmLblTlv_t));
}
if(lblMapMsg->frLblTlvExists == 1)
{
lblRelMsg.frLblTlvExists = 1;
MPLS_MEMCPY(&lblRelMsg.frLblTlv,&lblMapMsg->frLblTlv,sizeof(mplsLdpFrLblTlv_t));
}
if(lblMapMsg->lspidTlvExists == 1)
{
lblRelMsg.lspidTlvExists = 1;
MPLS_MEMCPY(&lblRelMsg.lspidTlv,&lblMapMsg->lspidTlv,sizeof(mplsLdpLspIdTlv_t));
}
lblRelMsg.statusTlvExists = 1;
lblRelMsg.status.baseTlv.flags.flags.uBit = 1;
lblRelMsg.status.baseTlv.flags.flags.fBit = 1;
lblRelMsg.status.baseTlv.flags.flags.type = MPLS_NOT_ST_TLVTYPE;
lblRelMsg.status.baseTlv.length = MPLS_STATUSFIXLEN;
lblRelMsg.status.flags.flags.error = 0;
lblRelMsg.status.flags.flags.forward = 1;
lblRelMsg.status.flags.flags.status = LOOPDETECT;
lblRelMsg.status.msgId = lblRelMsg.baseMsg.msgId;
lblRelMsg.status.msgType = MPLS_LBLREL_MSGTYPE;
#if 0
SendTcpMsg(session,MPLS_LBLREL_MSGTYPE,&lblRelMsg);
#endif
Func_lblmsg_wait_proce( session, MPLS_LBLREL_MSGTYPE, &lblRelMsg);
}
/***********************************************************************/
/* FUNCTION NAME : funcloopdetect()
/* DESCRIPTION: : detect if happen loop
/* INPUT : unsigned short eventType,
void *inputMsg,
mplsLdpSession_t * session
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.07.1
/* GLOBAL : none
/* History :
/************************************************************************/
unsigned long funcloopdetect(unsigned short eventType, void *inputMsg, mplsLdpSession_t * session)
{
mplsLdpLblReqMsg_t *lblReqMsg;
mplsLdpLblMapMsg_t *lblMapMsg;
unsigned short i;
if(session -> loopDetectionForPV == LOOPDETECT_HOPANDPV)
{
switch(eventType)
{
case MPLS_LBLREQ_MSGTYPE:
{
lblReqMsg = (mplsLdpLblReqMsg_t *)inputMsg;
if(lblReqMsg->hopCountTlvExists == 1 )
{
if(lblReqMsg->hopCountTlv.hcValue >= 255)
return(LOOPDETECT);
}
if(lblReqMsg->pathVecTlvExists == 1)
{
if((lblReqMsg->pathVecTlv.baseTlv.length/4)>= session -> pathVectorLimit)
return(LOOPDETECT);
for( i = 0; i < (lblReqMsg->pathVecTlv.baseTlv.length/4); i++)
{
if(lblReqMsg->pathVecTlv.lsrId[i] == lsrAttr.lsrAttribute.lsrId)
return(LOOPDETECT);
}
}
}
break;
case MPLS_LBLMAP_MSGTYPE:
{
lblMapMsg = (mplsLdpLblMapMsg_t *)inputMsg;
if(lblMapMsg->hopCountTlvExists == 1 )
{
if(lblMapMsg->hopCountTlv.hcValue >= 255)
return(LOOPDETECT);
}
if(lblMapMsg->pathVecTlvExists == 1)
{
if((lblMapMsg->pathVecTlv.baseTlv.length/4)>= session -> pathVectorLimit)
return(LOOPDETECT);
for( i = 0; i < (lblMapMsg->pathVecTlv.baseTlv.length/4); i++)
{
if(lblMapMsg->pathVecTlv.lsrId[i] == lsrAttr.lsrAttribute.lsrId)
return(LOOPDETECT);
}
}
}
break;
default: break;
}
}
return 0;
}
/***********************************************************************/
/* FUNCTION NAME : lblreqtocbbloopproc()
/* DESCRIPTION: : receive label request message, hop count tlv
and path vector tlv to CB
/* INPUT : mplsLdpLblReqMsg_t *lblReqMsg,
mplsLdpAttr *ldppAttr,
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.07.1
/* GLOBAL : none
/* History :
/************************************************************************/
void lblreqtocbbloopproc(mplsLdpLblReqMsg_t *lblReqMsg,
mplsLdpAttr *ldppAttr)
{
short rtcode;
if( lblReqMsg->hopCountTlvExists == 1 )
{
if(lblReqMsg->hopCountTlv.hcValue != 0)
{
ldppAttr -> hopcount = lblReqMsg->hopCountTlv.hcValue;
ldppAttr -> hopvalue_valid = 1;
}
else if(lblReqMsg->hopCountTlv.hcValue == 0) /* 0 express unknow value */
{
ldppAttr -> hopcount = 0;
ldppAttr -> hopvalue_valid = 1;
}
}
else
{
ldppAttr -> hopcount = 0;
ldppAttr -> hopvalue_valid = 0;
}
if(lblReqMsg->pathVecTlvExists == 1)
{
#ifdef MPLS_LOOP_MEM_PVTLV
rtcode = ldp_pathvector_malloc(ldppAttr,lblReqMsg->pathVecTlv.baseTlv.length);
if(rtcode != MPLS_TRUE)
{
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP, "lblreqtocbbloopproc,ldppAttr -> pAttr, out of memory\n");
printf("ldppAttr -> pAttr, out of memory");
}
else
{
memcpy(ldppAttr -> pAttr,&(lblReqMsg->pathVecTlv.lsrId[0]),\
lblReqMsg -> pathVecTlv.baseTlv.length );
ldppAttr -> len = lblReqMsg->pathVecTlv.baseTlv.length ;
ldppAttr -> attrvalue_valid = 1;
}
#endif
}
else
{
ldppAttr -> pAttr = MPLS_NULL;
ldppAttr -> len = 0;
ldppAttr -> attrvalue_valid = 0;
}
}
/***********************************************************************/
/* FUNCTION NAME : cbbtolblreqtlvloopproc()
/* DESCRIPTION: : send label request message, hop count tlv
and path vector tlv to message
/* INPUT : mplsLdpAttr * ldppAttr,
mplsLdpLblReqMsg_t * lblReqMsg,
uchar routetype
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.07.1
/* GLOBAL : none
/* History :
/************************************************************************/
void cbbtolblreqtlvloopproc(mplsLdpAttr * ldppAttr,
mplsLdpLblReqMsg_t * lblReqMsg,
unsigned char routetype)
{
lblReqMsg -> hopCountTlvExists = 1;
lblReqMsg -> pathVecTlvExists = 1;
lblReqMsg -> hopCountTlv.baseTlv.flags.flags.uBit = 0;
lblReqMsg -> hopCountTlv.baseTlv.flags.flags.fBit = 0;
lblReqMsg -> hopCountTlv.baseTlv.flags.flags.type = MPLS_HOPCOUNT_TLVTYPE;
lblReqMsg -> hopCountTlv.baseTlv.length = MPLS_HOPCOUNTFIXLEN;
lblReqMsg -> pathVecTlv.baseTlv.flags.flags.uBit = 0;
lblReqMsg -> pathVecTlv.baseTlv.flags.flags.fBit = 0;
lblReqMsg -> pathVecTlv.baseTlv.flags.flags.type = MPLS_PATH_TLVTYPE;
if(routetype == MPLS_NODE_INGRESS) /*141.tst,143.tst */
{
lblReqMsg -> hopCountTlv.hcValue = 1;
lblReqMsg -> pathVecTlv.lsrId[0] = lsrAttr.lsrAttribute.lsrId;
lblReqMsg -> pathVecTlv.baseTlv.length = 4;
/* for ingress free ldppAttr -> pAttr in abnormal, by szh 03-1-16 */
if(ldppAttr -> pAttr != MPLS_NULL)
{
ldp_pathvector_free(ldppAttr);
}
}
else if(ldppAttr -> hopcount != 0) /* 140.tst, */
{
lblReqMsg -> hopCountTlv.hcValue = (ldppAttr -> hopcount +1);
}
else /* 142.tst */
{
lblReqMsg -> hopCountTlv.hcValue = 0;
}
if(ldppAttr -> pAttr != MPLS_NULL) /*144.tst, */
{
memcpy(&(lblReqMsg->pathVecTlv.lsrId[0]),ldppAttr -> pAttr,ldppAttr -> len);
lblReqMsg->pathVecTlv.lsrId[ldppAttr -> len/4] = lsrAttr.lsrAttribute.lsrId;
lblReqMsg -> pathVecTlv.baseTlv.length = ldppAttr -> len + 4;
}
else /* 146.tst */
{
lblReqMsg -> pathVecTlv.lsrId[0] = lsrAttr.lsrAttribute.lsrId;
lblReqMsg -> pathVecTlv.baseTlv.length = 4;
}
}
/***********************************************************************/
/* FUNCTION NAME : sndfeclsp_mapmsg_looptlvproc_dod()
/* DESCRIPTION: : send label request message(dod), hop count tlv
and path vector tlv to message
/* INPUT : mplsLdpAttr * ldppAttr,
mplsLdpLblMapMsg_t * lblMapMsg,
unsigned char nodetype
/* OUTPUT : void
/* AUTHOR/DATE : shi.zhaohui/ 02.07.1
/* GLOBAL : none
/* History :
/************************************************************************/
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -