📄 ldproute.c
字号:
/********************************************************************/
/* Product Name: MPLS PACK 1.0 */
/* Module Name: LDP */
/* File Name: ldproute.c */
/* Author Name: weng.qing */
/* Creat Date: 2002/6/19 */
/* Version : 1.0 */
/* Function : for route process function */
/*2002.12.28 Huyonghong ldp在业务板down时把close消息发给转发 */
/* 2003.2.25 Wengqing egress policy 删除时,先做路由删除再做路由增加 */
/* wengqing 2003.3.27 在session up时判断是否还有要删的块未处理,
若有,则定时5s再来检查,没有要删的块才开始新建立 */
/* 2003.4.3 huyonghong 更改mpls_policy_filter调用 */
/* 2003.4.21 wengqing 在策略判断deny退出时,先判断fec是否已存在,
如果存在,将存在的fec作路由删除操作 */
/* 2003.4.23 wengqing sessiondown时为保护设置控制块扫描链开关*/
/* 2003.5.29 wengqing 路由改变时,egress to 的lsp不做变动 */
/* 2003.5.29 wengqing 更新fec的localGenLabel时,先判断egress to,
后判断从lic来的路由 */
/* 2003-7-29 shizhaohui 修改fec_entry_update函数,对egress to配置的路由
需特殊处理
/* 2003-9-2 szh mod 修改RouteDelProc() 函数
/* 2003-9-11 szh mod RouteDelProc() add protect */
/* 2003.12.30 fengjun 在路由删除处理函数中,删除控制块函数会检查FEC是否需要删除,
外部的判断导致重复操作,可去除 */
/*2003.12.30 fengjun 用删除控制块函数代替直接的CR删宏操作 */
/* 2004-1-6 lixia add for debug mpls */
/* 2004-2-9 fengjun szh mod del fec control block */
/********************************************************************/
#include "ldpvars.h"
#include "mx_ax_bx.h"
mpls_fec_search GlobalSearch; /* 2004-1-7 lixia add for policy process */
void ProcessRoute(ROUTEMESSAGE_UPDATE * routeupdate)
{
unsigned short num;
IPFORWARDINGTAB * routeEntry;
mpls_fec_search * pSear = MPLS_NULL;
rt_change = 0;
/* when routing is dumping, tell oam */
if(oam_binding_get.start == 1)
{
oam_binding_get.dumping = 1;
}
/* send back msg acknownagement */
num = routeupdate->changenumber;
/* tell session to scan fec again,per change number, scan fec, not per fec change, scan fec */
if(num > 0)
{
for(pSear = g_fec_search_list.first;pSear;pSear = pSear->next)
{
pSear->stop = 1;
}
}
while(num -- > 0)
{
routeEntry = (IPFORWARDINGTAB *)(&routeupdate->IpForwardingTab[num]);
/* 屏蔽VPN和PPPOE路由 */
if((routeEntry->ServType == 1) || (routeEntry->vpnid != 0))
continue;
switch( routeEntry->Type )
{
case ROUTE_ADD:
RouteAddProc(routeEntry);
break;
case ROUTE_DELETE:
RouteDelProc(routeEntry);
break;
case ROUTE_CHANGE:
RouteNexthopChangeProc(routeEntry);
break;
default:
printf("mpls_err_log %x",routeEntry->Type);
break;
}
}
return;
}
/****************************************************************************/
/* Product Name: MPLS PACK1.0
* Module Name: LDP/CR_LDP
* File Name: ldppdu.h
* Author Name: weng.qing shi.zhaohui hu.yonghong
* Creat Date: 2002-6-18
* Version : 1.0
* Input : mplsLdpSession_t *, inbound seesion pointer;
* void *, inputEvent;
* Output : void
* Function : Label release process function
* Note :
*/
/****************************************************************************/
void RouteAddProc(IPFORWARDINGTAB * routemsg)
{
unsigned short length;
mplsLdpFecEntry * fec = MPLS_NULL;
mplsLdpSession_t * session;
mplsLdpDownCB * downCb = MPLS_NULL;
mplsLdpLspCB * lspCb = MPLS_NULL;
mplsLdpUpCB * upCb = MPLS_NULL;
mpls_local_addr * addrEntry = MPLS_NULL;
unsigned short dismode,nexthopchange;
unsigned short i;
unsigned short policy_action;
unsigned char egressto_type = 0;
unsigned long NextHop;
unsigned short Type;
if(routemsg->Dest == MPLS_LOOPBACK_ADDRESS)
return;
nexthopchange = 0;
MPLS_NETMASK2LENGTH((routemsg->NetMask),length)
#ifdef PSOS
if((length == 32)&&(routemsg->rt_type == MPLS_ROUTE_OWN))
{
/* for loopback address 32bit notify, when send twice, Juniper close session */
addrEntry = MPLS_NULL;
MPLS_ADDRESS_SEARCH(routemsg->Dest,addrEntry);
if(!addrEntry)
{
MPLS_ADDRESS_ADD(routemsg->Dest);
MPLS_MEMSET(&(ldp_snd_msg.addrMsg),0,sizeof(mplsLdpAdrMsg_t));
InitAdrMsg(&(ldp_snd_msg.addrMsg),MPLS_ADDR_MSGTYPE);
ldp_snd_msg.addrMsg.baseMsg.msgId = messageId[ADDR_M];
AddMsgId(ADDR_M);
ldp_snd_msg.addrMsg.addressList.address[0] = routemsg->Dest;
ldp_snd_msg.addrMsg.addressList.baseTlv.length = (unsigned short)(MPLS_ADDFAMFIXLEN + \
1*MPLS_IPv4LEN);
MPLS_WALK_SESSION_BEGIN(session,i)
dismode = 0;
MPLS_SESSION_DISTRIBUT_MODE(session,dismode);
if(dismode != DOWNSTREAMONDEMAND)
{
SendTcpMsg(session,MPLS_ADDR_MSGTYPE,&(ldp_snd_msg.addrMsg));
}
MPLS_WALK_SESSION_END(session,i)
}
}
#endif
policy_action = mpls_policy_filter(routemsg->Dest,routemsg->NetMask,routemsg->NextHop);
if(policy_action == 0) /* deny */
{
MPLS_FEC_SEARCH((routemsg->Dest),length,fec)
if(fec != MPLS_NULL)
{
if(fec->owner & MPLS_OWNER_ROUTE)
{
if(fec->nexthopAddr != routemsg->NextHop)
{
NextHop = routemsg->NextHop;
Type = routemsg->Type;
routemsg->NextHop = fec->nexthopAddr;
routemsg->Type = ROUTE_DELETE;
RouteDelProc(routemsg); //路由改变后直接删除原路由,如没改变则需手动删除
routemsg->NextHop = NextHop;
routemsg->Type = Type;
}
}
}
MPLS_FEC_SEARCH((routemsg->Dest),length,fec)
if(fec == MPLS_NULL)
MPLS_FEC_CREATE(routemsg->Dest,length,fec)
if(fec != MPLS_NULL) //没有立即删除的Fec和新建的
{
egressto_type = MPLS_DENY_POLICY;
fec_entry_update(fec,routemsg,egressto_type);
fec->pRes |= MPLS_DENY_POLICY;//dele
}
return;
}
else if(policy_action == 2) /* egress to */
{
routemsg->rt_type = MPLS_ROUTE_OWN;
egressto_type = MPLS_EGRESS_TO_POLICY;
}
#ifdef __BGS10_MPLS_DEBUG
MPLS_ERR_LOG("Route Add routemsg->Dest %x, Length %d,Nexthop %x",routemsg->Dest,length,routemsg->NextHop);
#endif
MPLS_FEC_SEARCH((routemsg->Dest),length,fec)
if(fec != MPLS_NULL)
{
/*********************************************************************/
/* Fec Entry may be deleted,because not process.
*/
/*********************************************************************/
/* protect for route add again, when routing loop */
if(fec->owner & MPLS_OWNER_ROUTE)
{
if(fec->nexthopAddr == routemsg->NextHop)
{
MPLS_ERR_LOG("Route Add twice,Don't bother me");
return;
}
else if(fec->nexthopAddr != routemsg->NextHop)
{
nexthopchange = 1;
MPLS_WALK_DOWN_BEGIN(fec,downCb,t_downCb);
if(downCb != MPLS_NULL)
{
switch(downCb->state)
{
case ESTABLISHED:
if(fec->nexthopSessionIndex == downCb->downSessionIndex)
wait_downfeclbl_append(downCb,fec,LDP_FWD_CLOSE);
break;
case RESPONSE_AWAITED:
/* send to up notification: no route */
downCb->waitflag |=0x1;
wait_downlblmsg_append(downCb,fec,MPLS_LBLABORT_MSGTYPE);
break;
default:
printf("mpls_err_log,RouteAddProc,downcb state error\n");
break;
}
}
MPLS_WALK_DOWN_END(fec,downCb,t_downCb)
/* 2003.5.29 wengqing egress to route change, not delete lsp already exist */
if(((fec->owner & MPLS_OWNER_POLICY) != MPLS_OWNER_POLICY) && ((fec->nodeType != MPLS_NODE_PROXY_EGRESS) || (routemsg->rt_type != MPLS_ROUTE_OWN)))
{
MPLS_WALK_LSP_BEGIN(fec,lspCb,t_lspCb)
if(lspCb != MPLS_NULL)
{
/* need judge the lspCb nodeType */
MPLS_ERR_LOG("Route Add different Nexthop,Del Process");
lspCb->pNexthopChange = 1;
if(!(lspCb->waitflag & 0x1))
LspCBFsm(MPLS_NULL,MPLS_ROUTE_DELETE,MPLS_NULL,LDP_HOP_LSP,fec,lspCb);
else
{
MPLS_ERR_LOG("Route lspCb->waitflag %x",lspCb->waitflag);
}
}
MPLS_WALK_LSP_END(fec,lspCb,t_lspCb)
}
}
}
/* 2003.02.25 wengqing for egress policy NextHop and IfIndex update */
if(routemsg->rt_type == MPLS_ROUTE_POLICY)
{
routemsg->NextHop = fec->nexthopAddr;
routemsg->IfIndex = fec->outIfindex;
}
fec_entry_update(fec,routemsg,egressto_type);
if(nexthopchange == 0)
{
MPLS_WALK_SESSION_BEGIN(session,i)
dismode = 0;
MPLS_SESSION_DISTRIBUT_MODE(session,dismode);
if(dismode == DOWNSTRAMUNSOLICITED)
{
MPLS_UPCB_CREATE(fec,session,upCb)
if(upCb)
{
upCb->upSessionIndex = session->index;
wait_uplblmsg_append(upCb,fec,MPLS_NULL,MPLS_NULL,MPLS_LBLMAP_MSGTYPE);
upCb->state = ESTABLISHED;
/*************************************************************/
/* add into message link list, set upCb flags
*/
/*************************************************************/
;
}
}
MPLS_WALK_SESSION_END(session,i)
}
/*********************************************************************/
/* here when route add, we could find fec, only because dynamic routing,
* but for precision conditional process here;
* not only because of downstream lsr label mapping,
*/
/*********************************************************************/
if(fec->nodeType != MPLS_NODE_PROXY_EGRESS &&
fec->nodeType != MPLS_NODE_EGRESS)
{
MPLS_NEXTHOP_SESSION_SEARCH(routemsg->NextHop,session);
dismode = 0;
if(session == MPLS_NULL)
{
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"RouteAddProc,nexthop %x,session == MPLS_NULL\n",routemsg->NextHop);
MPLS_ERR_LOG("session == MPLS_NULL");
return;
}
fec->nexthopSessionIndex = session->index;
MPLS_SESSION_DISTRIBUT_MODE(session,dismode);
if(dismode == DOWNSTRAMUNSOLICITED)
{
downCb = MPLS_NULL;
/*************************************************************/
/* down cb search should check downCb flags, not been withdraw
*/
/*************************************************************/
MPLS_DOWNCB_SEARCH(fec,session,downCb);
if(downCb != MPLS_NULL)
{
#ifdef __BGS10_MPLS_DEBUG
MPLS_ERR_LOG("add to wait_downfeclbl_append");
#endif
wait_downfeclbl_append(downCb,fec,LDP_FWD_CREATE);
}
}
else
{
MPLS_LSPCB_CREATE(fec,lspCb);
if(lspCb)
{
/* add into down session link list */
lspCb->lspIndex = MPLS_GET_LSP_INDEX;
lspCb->lspType = LDP_HOP_LSP;
lspCb->nodeType = MPLS_NODE_INGRESS;
lspCb->downSessionIndex = session->index;
lspCb->downifIndex = session->ifIndex;
lspCb->downPeerLdpid.lsrAddress = session->peerLdpId.lsrAddress;
lspCb->downPeerLdpid.labelSpace = session->peerLdpId.labelSpace;
ifindex2mod_req.ifIndex = lspCb->downifIndex;
ifindex2mod_req.mpls_protocol_type = MPLS_LABEL_SWITCH_PROTOCOL_ATM;
ifindex2mod_req.mpls_platform = local_platform;
mpls_ifindex2module(&ifindex2mod_req,&ifindex2mod_ack,MPLS_INTERFACE);
if(ifindex2mod_ack.ack == MPLS_SUCCESS)
{
lspCb->downAtmLabel.module = ifindex2mod_ack.mod;
lspCb->downAtmLabel.port = ifindex2mod_ack.port;
}
else
{
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"RouteAddProc,ERR get Down ATM Module & port\n");
MPLS_ERR_LOG("ERR get UP ATM Module & port");
/* should release up atm label */
MPLS_FEC_LSPCB_DELETE(fec,lspCb);
return;
}
MPLS_INSERT_INTO_DOWN_LSP_LIST(session->lsp_down_cb_list,lspCb,lspCb);
lspCb->status = IDLE;
lspCb->subStatus = IDLE;
if(!(lspCb->waitflag & 0x1))
LspCBFsm(session,MPLS_ROUTE_ADD,MPLS_NULL,LDP_HOP_LSP,fec,lspCb);
}
else
DEBUG_OUT(DEBUG_OWNER_MPLS, DEBUG_LEVEL_MPLS_LSP,"RouteAddProc,creat lspcb fail\n");
}
}
}
else
{
MPLS_FEC_CREATE(routemsg->Dest,length,fec)
if(fec != MPLS_NULL)
{
fec_entry_update(fec,routemsg,egressto_type);
MPLS_WALK_SESSION_BEGIN(session,i)
dismode = 0;
MPLS_SESSION_DISTRIBUT_MODE(session,dismode);
if(dismode == DOWNSTRAMUNSOLICITED)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -