📄 ldppdu.c
字号:
{
helloIndexExist = 1;
break;
}
/* 对已有的hello邻接,不必操作;对新的hello邻接,将其挂到session下 */
if (helloIndexExist == 0)
{
for (ii=0;ii<SESSION_OWNED_HELLO;ii++)
if (session2->helloArray[ii]==0)
{
session2->helloArray[ii]= hello->index;
break;
}
}
/* szh add protect 2003-9-11 */
if((session2->role == ACTIVE)&&(session2->state == NONEXISTENT)&&(session2->tmidCon==0))
{
/* 进入session状态机,状态是NONEXISTENT */
printf(" protect session, send tcp req message !!!");
session2->tcpConRetry = 0;
SessionFSM(session2,LDPSESINIT,NULL);
}
/* szh add end 2003-9-11 */
}
else
{
if((session2 != MPLS_NULL)&&(session2->state == TCP_RELEASE_AWAITED))
{
if(session2->tmidCon)
{
MPLS_CLEAR_TIMER(session2->tmidCon,ldptime_q,rtcode);
}
session2->tmidCon = 0;
/* delete lspcb whitch appended after session2,03-1-17 wengqing */
SessionDown(session2);
MibSession(&sesIndex_s,LDP_DELETE);
session2 = MPLS_NULL;
}
SendLdpHello(ldpEntity);
/* 4.1 如果没有相应的会话,或会话正在拆,创建新的session表项和peer表项*/
MPLS_MEMSET(&sessiontmp, 0, sizeof(mplsLdpSession_t));
sessiontmp.entityLdpId = entityLdpId;
sessiontmp.peerLdpId = peerLdpId;
sessiontmp.state = NONEXISTENT;
sessiontmp.protocolVersion = 1;
sessiontmp.maxPduLength = 4096;
sessiontmp.labelAdvertisement = ldpEntity->labelDistributionMethod;
sessiontmp.loopDetectionForPV = ldpEntity->loopDetectionCapable;
sessiontmp.pathVectorLimit = ldpEntity->pathvectorlimit;
sessiontmp.peerIpaddr = peerTransAddr;
if(ldpEntity->transportAddr == 0)
sessiontmp.localIpaddr = localAddr;
else
sessiontmp.localIpaddr = ldpEntity->transportAddr;
sessiontmp.nexthopaddr = peerAddr;
sessiontmp.LocalPort = 0;/* 赋初值 */
sessiontmp.PeerPort = 0;
for (ii=0;ii<SESSION_OWNED_HELLO;ii++)
sessiontmp.helloArray[ii] =0;
sessiontmp.helloArray[0] = hello->index;
sessiontmp.tcpConRetry = 0;
sessiontmp.tmidCon = 0;
sessiontmp.ifIndex = ifIndex;
sessiontmp.keepAliveHoldTime = ldpEntity->keepAliveHoldTimer * LDP_MIN_TIME_INTERVAL;
if (sessiontmp.localIpaddr > peerTransAddr)
sessiontmp.role = ACTIVE;
else
sessiontmp.role = PASSIVE;
session2 = (mplsLdpSession_t *)MibSession(&sessiontmp, LDP_SET);
if (session2 == MPLS_NULL)
return LDP_FALSE;
#ifdef __BGS10_MPLS_DEBUG
printf("===== LDP ENTITY SET SESSION TABLE.=====");
#endif
#ifdef __BGS10_MPLS_DEBUG
printf("===== LDP ENTITY SET PEER TABLE.=====");
#endif
peertmp.ldpId = peerLdpId;
peertmp.ifIndex = ifIndex;
/* fill loopDetectionForPV and pathVectorLimit in peertable 03-1-18 by hyh */
peertmp.loopDetectionForPV = session2->loopDetectionForPV;
peertmp.pathVectorLimit = session2->pathVectorLimit;
peertmp.labelDistributionMethod = session2->labelAdvertisement;
peer = (mplsLdpPeer_t *)MibPeer(&peertmp, LDP_SET);
if (peer == MPLS_NULL)
return LDP_FALSE;
/* 进入session状态机,状态是NONEXISTENT */
SessionFSM(session2,LDPSESINIT,NULL);
}
/* because no subnet judgement now */
/* so check if peer exist, if no set peer */
peer = NULL;
peerIndex = peerLdpId;
peer = (mplsLdpPeer_t *)MibPeer(&peerIndex, LDP_SEARCH);
if (peer == MPLS_NULL)
{
peertmp.ldpId = peerLdpId;
peertmp.ifIndex = session2->ifIndex;
/* fill loopDetectionForPV and pathVectorLimit in peertable 03-1-18 by hyh */
peertmp.loopDetectionForPV = session2->loopDetectionForPV;
peertmp.pathVectorLimit = session2->pathVectorLimit;
peertmp.labelDistributionMethod = session2->labelAdvertisement;
peer = (mplsLdpPeer_t *)MibPeer(&peertmp, LDP_SET);
if (peer == MPLS_NULL)
return LDP_FALSE;
}
/* 设置hello的sessionIndex, 对于所有情况都需要在hello表中唯一地填写最新的sessionIndex */
hello->sessionIndex = session2->index;
return LDP_TRUE;
}
/**************** 处理收到的PROT_UDP、PROT_TCP包 *****************/
short ProcUdpTcpMsg(LDPMSG_COMM * udptcpRecMsg)
{
/* 定义局部变量 */
unsigned char *buff;
unsigned short buffSize;
unsigned char *startPtr;
unsigned short totalSize;
mplsLdpMsg_t msgHead;
long encodedSize;
mplsLdpHeader_t testHeaderDecode;
mplsLdpId_t peerLdpId;
unsigned long localAddr, peerAddr;
unsigned short localport,peerport;
mplsLdpSession_t * session = MPLS_NULL;
ldpMibSessionIndexReq_t sesIndex_s;
ldpMibHelloIndexReq_t helloIndex;
mplsLdpHello_t *hello = MPLS_NULL;
mplsLdpHelloMsg_t helloMsg;
/* 给A041回缓冲确认 */
/* ASEND(LDP_BUF_MSG_ACK,&msgconf,sizeof(REQ_CONF),udptcpPid); */
/* 1.赋初值 */
buff = udptcpRecMsg->pdu;
buffSize = udptcpRecMsg->pdulen;
startPtr = buff;
localAddr = udptcpRecMsg->LocalIpaddr;
peerAddr = udptcpRecMsg->PeerIpaddr;
localport = udptcpRecMsg->LocalPort;
peerport = udptcpRecMsg->PeerPort;
#ifdef __BGS10_MPLS_DEBUG
/* printf("========MPLS udp/tcp Msg localAddr %x, peerAddr %x, LocalPort %d, PeerPort %d =======\n",
udptcpRecMsg->LocalIpaddr,udptcpRecMsg->PeerIpaddr,udptcpRecMsg->LocalPort,udptcpRecMsg->PeerPort);
*/
#endif
/* 2.解码 PDU 的头 */
encodedSize = Mpls_decodeLdpMsgHeader(&testHeaderDecode,startPtr,buffSize);
if (encodedSize < 0)
{
printf("========MODULE :%d Failed while decoding HEADER =======\n",selfLdpPid.module);
return LDP_FALSE;
}
startPtr += encodedSize;
if (testHeaderDecode.pduLength > buffSize)
{
printf("========MODULE :%d Header Length is longer than buffsize ERROR =======\n",
selfLdpPid.module);
return LDP_FALSE;
}
peerLdpId.lsrAddress = testHeaderDecode.lsrAddress;
peerLdpId.labelSpace = testHeaderDecode.labelSpace;
/*3.区分处理UDP、TCP包*/
switch(udptcpRecMsg->ProtType)
{
/* 3. 进入发现处理模块 */
case PROT_UDP:
#ifdef DEBUG_LDP_HELLO
printf("========MODULE :%d RECEIVE HELLO MSG =======\n",selfLdpPid.module);
#endif
if(testHeaderDecode.protocolVersion != 1)
return;
totalSize = 0;
while(totalSize < (unsigned short)(testHeaderDecode.pduLength - sizeof(mplsLdpId_t)))
{
Mpls_decodeLdpBaseMsg( &msgHead, startPtr, buffSize-MPLS_LDP_HDRSIZE);
switch(msgHead.flags.flags.msgType)
{
case MPLS_HELLO_MSGTYPE:
/*解码hello消息*/
encodedSize = Mpls_decodeLdpHelloMsg(&(ldp_recv_tcp_msg.helloMsg), startPtr,\
buffSize-MPLS_LDP_HDRSIZE-totalSize);
if (encodedSize < 0)
{
printf("========MODULE :%d Decode Hello Msg Error =======\n",selfLdpPid.module);
return LDP_FALSE;
}
totalSize += encodedSize;
startPtr += encodedSize;
/*进入hello处理*/
ProcessHello(&(ldp_recv_tcp_msg.helloMsg),localAddr,peerAddr,peerLdpId);
break;
default:
/*wengqing 2003.2.10 if hello decode error,directly return*/
/*encodedSize = msgHead.msgLength;
totalSize += encodedSize;
startPtr += encodedSize;
break;*/
return;
}
}
break;
/* 4. 进入会话处理模块 */
case PROT_TCP:
/*用传输地址查hello. add by hyh 2002-6-18 19:06*/
helloIndex.transAddr = peerAddr;
helloIndex.indexFlag = 3;
hello = (mplsLdpHello_t *)MibHello(&helloIndex,LDP_SEARCH);
if(hello == MPLS_NULL)
return LDP_FALSE;
/* 4.1 用entityLdpId和peerLdpId检索session表 */
sesIndex_s.unionIndex.entityLdpId = hello->entityLdpId;
sesIndex_s.unionIndex.peerLdpId = peerLdpId;
sesIndex_s.indexFlag = 2;
session = (mplsLdpSession_t *)(mplsLdpSession_t *)MibSession(&sesIndex_s,LDP_SEARCH);
if (session == MPLS_NULL)
{
sesIndex_s.sessionIndex = hello->sessionIndex;
sesIndex_s.indexFlag = 1;
session = (mplsLdpSession_t *)MibSession(&sesIndex_s, LDP_SEARCH);
if (session == MPLS_NULL)
return LDP_FALSE;
else
{
Mpls_decodeLdpBaseMsg( &msgHead, startPtr, buffSize-MPLS_LDP_HDRSIZE);
DelTmid(session);
sndnotifymsgproc(session,BADLDPID,msgHead.msgId,
msgHead.flags.flags.msgType);
SendTcpRel(session);
return LDP_FALSE;
}
}
else
{
Mpls_decodeLdpBaseMsg( &msgHead, startPtr, buffSize-MPLS_LDP_HDRSIZE);
if(testHeaderDecode.protocolVersion != session->protocolVersion)
{
DelTmid(session);
sndnotifymsgproc(session,BADPROTVER,msgHead.msgId,
msgHead.flags.flags.msgType);
SendTcpRel(session);
return LDP_FALSE;
}
if((testHeaderDecode.pduLength > session->maxPduLength)||
(testHeaderDecode.pduLength < 14 )||
(testHeaderDecode.pduLength != udptcpRecMsg->pdulen- MPLS_MSGHDRFIXLEN))
{
DelTmid(session);
sndnotifymsgproc(session,BADPDULEN,msgHead.msgId,
msgHead.flags.flags.msgType);
SendTcpRel(session);
return LDP_FALSE;
}
if((session -> LocalPort == udptcpRecMsg->LocalPort)
&& (session -> PeerPort == udptcpRecMsg->PeerPort))
{
#ifdef __BGS10_MPLS_DEBUG
printf("LDP Tcp message port match! \n");
#endif
}
else
{
printf("LDP Tcp message port mismatch! \n");
return LDP_FALSE;
}
}
/* 4.2 进入会话状态机的处理 */
while(buffSize > 0)
{
totalSize = 0;
while(totalSize < (unsigned short)(testHeaderDecode.pduLength - sizeof(mplsLdpId_t)))
{
/* 取出消息类型 */
encodedSize = 0;
Mpls_decodeLdpBaseMsg( &msgHead, startPtr, buffSize-MPLS_LDP_HDRSIZE);
if(msgHead.msgLength > buffSize-MPLS_LDP_HDRSIZE)
{
DelTmid(session);
sndnotifymsgproc(session,BADMSGLEN,msgHead.msgId,
msgHead.flags.flags.msgType);
SendTcpRel(session);
return LDP_FALSE;
}
switch(msgHead.flags.flags.msgType)
{
case MPLS_INIT_MSGTYPE:
#ifdef __BGS10_MPLS_DEBUG
printf("========MODULE :%d RECEIVE Init MSG =======\n",selfLdpPid.module);
#endif
encodedSize = Mpls_decodeLdpInitMsg(&ldp_recv_tcp_msg.initMsg, startPtr,\
buffSize-MPLS_LDP_HDRSIZE-totalSize);
if (encodedSize < 0)
{
printf("========MODULE :%d Decode INIT Msg Error =======\n",selfLdpPid.module);
/* return FALSE; */
/*return encodedSize;*/
break;
}
totalSize += encodedSize;
startPtr += encodedSize;
SessionFSM(session,MPLS_INIT_MSGTYPE,&ldp_recv_tcp_msg.initMsg);
break;
case MPLS_KEEPAL_MSGTYPE:
#ifdef __BGS10_MPLS_DEBUG
printf("========MODULE :%d RECEIVE KeepAl MSG =======\n",selfLdpPid.module);
#endif
encodedSize = Mpls_decodeLdpKeepAliveMsg(&ldp_recv_tcp_msg.keepAliveMsg,\
startPtr,buffSize-MPLS_LDP_HDRSIZE-totalSize);
if (encodedSize < 0)
{
printf("========MODULE :%d Decode KEEPAL Msg Error =======\n",selfLdpPid.module);
break;
}
totalSize += encodedSize;
startPtr += encodedSize;
SessionFSM(session,MPLS_KEEPAL_MSGTYPE,&ldp_recv_tcp_msg.keepAliveMsg);
break;
case MPLS_NOT_MSGTYPE:
#ifdef __BGS10_MPLS_DEBUG
printf("========MODULE :%d RECEIVE Not MSG =======\n",selfLdpPid.module);
#endif
encodedSize = Mpls_decodeLdpNotMsg( &ldp_recv_tcp_msg.notifMsg, startPtr,\
buffSize-MPLS_LDP_HDRSIZE-totalSize);
if (encodedSize < 0)
{
printf("========MODULE :%d Decode NOTIF Msg Error =======\n",selfLdpPid.module);
break;
}
totalSize += encodedSize;
startPtr += encodedSize;
SessionFSM(session,MPLS_NOT_MSGTYPE,&ldp_recv_tcp_msg.notifMsg);
break;
case MPLS_ADDR_MSGTYPE:
#ifdef __BGS10_MPLS_DEBUG
printf("========MODULE :%d RECEIVE Addr MSG =======\n",selfLdpPid.module);
#endif
encodedSize = Mpls_decodeLdpAdrMsg(&ldp_recv_tcp_msg.addrMsg, startPtr,\
buffSize-MPLS_LDP_HDRSIZE-totalSize);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -