📄 ddos_proc.c
字号:
/*****************************************************************************
Copyright (c) 2007, Hangzhou H3C Technologies Co., Ltd. All rights reserved.
------------------------------------------------------------------------------
ddos_proc.c
Project Code: Comware V5
Module Name:
Date Created: 2008-09-17
Author: licai
Description: ddos模块处理函数
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
YYYY-MM-DD
*****************************************************************************/
#ifdef __cplusplus
extern "C"{
#endif
#include "vrpcfg.h"
#include "dopra_pub.h"
#include "cli_pub.h"
#include "if_pub.h"
#include "sec_mid.h"
#include "ddos_pub.h"
#include "../include/ddos_def.h"
#include "../include/ddos_type.h"
#include "../include/ddos_var.h"
#include "../include/ddos_func.h"
/*****************************************************************************
Func Name: DDOS_Init
Date Created: 2008-09-15
Author: licai
Description: ddos模块数据初始化
Input: IN LPVOID pStartContext
Output: 无
Return: VOS_OK, 初始化成功
Caution: 无
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
YYYY-MM-DD
*****************************************************************************/
ULONG DDOS_Init (IN LPVOID pStartContext)
{
(VOID) pStartContext;
/* 初始化业务链表 */
DLIST_InitHead (&g_stDDOSUserServiceList);
/* 初始化全局参数 */
g_stDDOSGlobalPara.ulThresMultiple = DDOS_DFT_THRESHOLD_MULTIPLE;
g_stDDOSGlobalPara.ulLowThresMultiple = DDOS_DFT_LOWTHRESHOLD_MULTIPLE;
g_stDDOSGlobalPara.ulIcmpLen = 0;
/* 初始化NS参数 */
VOS_Mem_Zero(&g_stDDOSNSPara,sizeof(DDOS_CFG_NSPARA_S));
g_stDDOSNSPara.ulTemplateInterval = DDOS_TEMPLATE_TMRINTVL_DFT;
return VOS_OK;
}
/*****************************************************************************
Func Name: DDOS_Run
Date Created: 2008-09-15
Author: licai
Description: ddos模块运行初始化
Input: IN LPVOID pStartContext
Output: 无
Return: VOS_OK, 初始化成功
Caution: 无
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
YYYY-MM-DD
*****************************************************************************/
ULONG DDOS_Run (IN LPVOID pStartContext)
{
DDOS_CFG_Init();
if (DDOS_PRODUCT_TYPE_GUARD == g_enDDOSProductType)
{
DDOS_RegIfEvent();
}
return VOS_OK;
}
/*****************************************************************************
Func Name: DDOS_Register_ConfData
Date Created: 2008-09-10
Author: songxiao
Description: 注册控制平面的PAF参数
Input: IN DDOS_CONF_S* pstConfData, PAF参数
Output: 无
Return: VOS_OK, 处理成功
VOS_ERR,处理失败
Caution: 无
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
YYYY-MM-DD
*****************************************************************************/
ULONG DDOS_Register_ConfData( IN DDOS_CONF_S* pstConfData )
{
if (NULL == pstConfData)
{
VOS_DBGASSERT(BOOL_FALSE);
return VOS_ERR;
}
else
{
g_enDDOSProductType = pstConfData->enProductType;
return VOS_OK;
}
}
/*****************************************************************************
Func Name: DDOS_Register_Driver
Date Created: 2008-09-10
Author: songxiao
Description: 驱动初始化注册
Input: 无
Output: 无
Return: VOS_OK, 处理成功
VOS_ERR, 处理失败
Caution: 无
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
YYYY-MM-DD
*****************************************************************************/
ULONG DDOS_Register_Driver (IN ULONG ulVersion, IN DDOS_DRV_INTF_S *pstDrvIntf)
{
(VOID)ulVersion;
if (NULL == pstDrvIntf)
{
VOS_DBGASSERT(BOOL_FALSE);
return VOS_ERR;
}
else
{
VOS_Mem_Copy(&g_stDDOSDrvInterface, pstDrvIntf, sizeof(DDOS_DRV_INTF_S));
return VOS_OK;
}
}
/*****************************************************************************
Func Name: DDOS_Weight
Date Created: 2008-09-15
Author: licai
Description: 计算掩码长度
Input: IN ULONG ulValue,IP地址掩码
Output: 无
Return: 掩码长度
Caution: 无
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
YYYY-MM-DD
*****************************************************************************/
ULONG DDOS_Weight (IN ULONG ulValue)
{
ULONG res = ulValue - ((ulValue >> 1) & 0x55555555);
res = (res & 0x33333333) + ((res >> 2) & 0x33333333);
res = (res + (res >> 4)) & 0x0F0F0F0F;
res = res + (res >> 8);
return (res + (res >> 16)) & 0x000000FF;
}
/*******************************************************************************
Func Name: DDOS_RegIfEvent
Date Created: 2008-11-25
Author: luohaijun
Description: 注册接口事件
Input: NULL
Output: NULL
Return: VOID
Caution: Important points if any
--------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------------
YYYY-MM-DD
*******************************************************************************/
VOID DDOS_RegIfEvent()
{
ULONG ulRet = VOS_ERR;
ULONG ulIfSelectHandle = 0; /* 接口选择句柄 */
/* 注册接口选择句柄 */
(VOID)IF_SelectHandle_Register(MID_DDOS, &ulIfSelectHandle);
/* 在结构中设置需要的接口类型 */
(VOID)IF_SelectType_Set(ulIfSelectHandle, IF_L3ETHERNET_TYPE);
(VOID)IF_SelectType_Set(ulIfSelectHandle, IF_L3GE_TYPE );
(VOID)IF_SelectType_Set(ulIfSelectHandle, IF_L3XGE_TYPE );
/* 向接口管理注册控制块handle,以后就可以用此handle存、取控制块 */
(VOID)IF_RegisterCB(MID_DDOS, ulIfSelectHandle, &g_ulDDOSIfCBHandle);
/* 向接口管理注册接口事件通知函数 */
ulRet = IF_RegIfEvent( MID_DDOS,
IF_IFMSG_CREATE|IF_IFMSG_DELETE, /* interface event */
ulIfSelectHandle,
IF_EVEPRI_NORMAL,
IF_MSGFLAG_CALLBACK,
NULL,
NULL,
NULL,
(IF_NOTIFY_FUNC_PF)DDOS_IfEventNotify);
VOS_DBGASSERT(VOS_OK == ulRet);
(VOID)IF_SelectHandle_UnRegister(ulIfSelectHandle);
return;
}
/*****************************************************************************
Func Name: DDOS_IfEventNotify
Date Created: 2008-11-25
Author: luohaijun
Description: 接口事件回调函数
Input: IN ULONG ulEvent, 事件类型
IN ULONG ulIfIndex, 接口索引,板事件时为无效
IN ULONG ulSequenceNo, 序列号
IN ULONG ulData,数据
Output: 无
Return: VOS_OK,返回成功
Caution:
------------------------------------------------------------------------------
Modification History
DATE NAME DESCRIPTION
--------------------------------------------------------------------------
*****************************************************************************/
ULONG DDOS_IfEventNotify (IN ULONG ulEvent,
IN ULONG ulIfIndex,
IN ULONG ulSequenceNo,
IN ULONG ulData)
{
ULONG ulRet = VOS_OK;
DDOS_CFG_INTERFACE_S * pstIfCfg = NULL;
/* 接口创建事件 */
if (IF_IFMSG_CREATE == (ulEvent & IF_IFMSG_CREATE))
{
pstIfCfg = VOS_Malloc(MID_DDOS, sizeof(DDOS_CFG_INTERFACE_S));
if (NULL == pstIfCfg)
{
return VOS_ERR;
}
/* 将内存清零 */
(VOID) VOS_Mem_Zero (pstIfCfg, sizeof (DDOS_CFG_INTERFACE_S));
pstIfCfg->enInterfaceType = DDOS_INTERFACE_NULL;
(VOID)IF_SetCBByHandle (ulIfIndex, g_ulDDOSIfCBHandle, (VOID *)pstIfCfg);
}
/* 接口删除事件 */
if (IF_IFMSG_DELETE == (ulEvent & IF_IFMSG_DELETE))
{
/* 获取接口控制块 */
ulRet = IF_GetCBByHandle (ulIfIndex, g_ulDDOSIfCBHandle, (VOID **)&pstIfCfg);
if (VOS_OK != ulRet)
{
return VOS_ERR;
}
if (NULL == pstIfCfg)
{
return VOS_OK;
}
/* 释放控制块 */
VOS_Free (pstIfCfg);
/*清空接口管理上挂接控制块指针*/
(VOID)IF_SetCBByHandle (ulIfIndex, g_ulDDOSIfCBHandle, NULL);
}
/* 通知接口管理处理结束*/
(VOID) IF_NotifyFinalStatus (ulEvent,
MID_DDOS,
ulIfIndex,
ulData,
ulSequenceNo,
IF_MSGRESULT_SUCCESS );
return VOS_OK;
}
#ifdef __cplusplus
}
#endif /* end of __cplusplus */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -