📄 igmp_main.cpp
字号:
/*******************************************************
文件名: igmp_main.cpp
文件说明:
本文件是IGMP Proxy模块的主模块文件,负责
初始化变量,提供接收和发送数据包函数,
然后将区分不同类型的数据包交给其他模块
处理。
修改记录:
2. 2004-4-14 changzhan 修改接收函数,增加对PPPoE处理
1. 2004-4-7 changzhan 初次建立本文件
_MANGE_表示由主控盘进行所有用户管理aibin
*******************************************************/
/*
#include "igmp.h"
#include "igmp_interface.h"
#include <ipuplink.h>
#include <CustomMemory.h>
#include "semLib.h"
#include "stdlib.h"
#include "inetLib.h"
#include <CustomTimer.h>
*/
#include "igmpcon.h"
/*#include "Igmp_control.h"*/
#define IS_TIMER_MSG 1 /*add by aibin 2005-01-13 */
#define IS_IGMP_MSG 2 /*add by aibin 2005-01-13 */
#define MODULE_IGMPPROXY 13 /*组播代理模块号 */
#define ReservedVlan 4089
#define DefaultVlan 4088
int router_vid; /*add by aibin 2005-01-13 */
int nIGMPTaskId = 0;
int global_vlan;
int uplink_vlan_enable = 0; /*上联口发送的协议报文制定的特殊vlan,缺省不设,用组播vlan aibin 20080611 */
#ifdef TEST
BOOL contest = TRUE;
#else
BOOL contest = FALSE;
#endif
struct GroupAdd GZ_add[10 + 1]; /*广州ctc测试所加20080119 aibin */
int gz_ctc_test = 0; /*广州ctc测试所加, 测试要求加入报文和组播实际流量处于两个vlan,在该结构中保存协议报文vlan 20080119 aibin */
int timetick1;
int timetick2;
int timetick3;
int timetick4;
int timetick5;
int turbo = 0;
UINT groupid = 0;
struct GroupAdd add[MaxGroup];
struct Time_Tick timeget[4096];
/*move*/
int fpreviewflag = 0; /* preview function flag, 0:disble, 1:enble */
int figmpportflag = 0; /* igmp port swich, 0:disble, 1:enalbe */
int fgroupauthflag = 0; /* group auth flag, 0:disable, 1:enable */
int fsourcecon; /*节目源管理标志位 */
int gEc2IGMPProxyEnable = 1; /*ec2 igmp proxy 使能, 0 snooping模式,1,普通proxy模式,2,可控的proxy模式 */
UINT tIgmpPreviewTimer = 0; /*设置预览定时器aibin 2005-4-12 */
int previewtime1; /*预览时间 */
int previewinterval1; /*预览间隔 */
int Guserlimit; /*全局用户限制数量 */
int Ggrouplimit; /*全局用户加入组个数限制 */
char slot_module[MAX_UPLINK_PORT + 1]; /*槽位所属于的模块,0表示router模块端口,1表示host模块(上联口)端口 */
struct ethernet_information gEtherInfo; /*aibin */
MSG_Q_ID IGMPMsgQId = 0;
BOOL bIgmpDebug = FALSE;
SEM_ID semIgmpDelete = 0;
SEM_ID semIgmpReceive = 0;
SEM_ID semIgmpTimeOut = 0;
SEM_ID semPreJoin = 0;
SEM_ID semSwitch = 0;
USHORT usPortMapSessionId[MAX_UPLINK_PORT + 1];
BOOL bEnablePortIGMP[MAX_UPLINK_PORT + 1]; /*端口是否允许IGMP */
BOOL bHostEnableIGMPV1; /*是否兼容IGMPV1 */
BOOL bRouterEnableIGMPV1; /*是否兼容IGMPV1 */
BOOL bEnableSecurityOption; /*是否检查IP包安全选项 */
BOOL bEnableHostModule; /*是否打开以太网侧HOST功能 */
BOOL bEnableRouterModule; /*是否打开ATM侧Router功能 */
BOOL bEnableQueryElection; /*否进行IGMP V2 查询者选举 */
BOOL bEnableInstantLeave; /*是否允许端口开速离开 */
BOOL bQuerierFlag; /*查询者标志 */
BOOL bV1RouterPresentFlag; /*V1版本路由器存在标志 */
BOOL igmpageflag; /*V2 设置生存周期标志位aibin */
UCHAR ucRobustness; /*健壮性变量 */
USHORT usQueryInterval; /*通用查询周期 */
USHORT usStartupQueryInterval; /*初始查询周期 */
UCHAR ucStartupQueryCount; /*初始查询次数 */
USHORT usQueryResponseInterval; /*最大响应时间 */
USHORT usGroupMembershipInterval; /*V2成员存在周期 */
USHORT usLastMemberQueryInterval; /*最后成员查询周期 */
UCHAR ucLastMemberQueryCount; /*最后成员查询次数 */
USHORT usUnsolicitedReportInterval; /*主动报告发送周期 */
USHORT usV1RouterPresentTimeout; /*V1版本路由器存在超时 */
USHORT usOtherQuerierPresentInterval; /*其他查询者存在周期 */
USHORT testcount;
UINT tIgmpTestTimer; /*IGMP处理包测试定时器 */
UINT tIgmpMembershipTimer;
UINT tStartupQueryTimer; /*初始查询定时器 */
UINT tV1RouterPresentTimer; /*V1版本路由器存在定时器 */
UINT tOtherQuerierPresentTimer; /*其他查询者存在定时器 */
UINT tGeneralQueryTimer; /*通用查询定时器 */
UINT unGeneralQueryTimerCount;
ULONG ulEtherReceiveIgmpPkt; /*统计Ethernet收到的IGMP包总数 */
ULONG ulEtherReceiveIgmpV1Query; /*统计Ethernet收到的IGMP V1 Query包数 */
ULONG ulEtherReceiveIgmpV2Query; /*统计Ethernet收到的IGMP V2 Query包数 */
ULONG ulEtherReceiveIgmpV1MembershipReport; /*统计Ethernet收到的IGMP V1 Report包数 */
ULONG ulEtherReceiveIgmpV2MembershipReport; /*统计Ethernet收到的IGMP V2 Report包数 */
ULONG ulEtherReceiveIgmpV3MembershipReport;
ULONG ulEtherReceiveIgmpLeaveGroup; /*统计Ethernet收到的IGMP Leave包数 */
ULONG ulEtherReceiveIgmpBad; /*统计Ethernet收到的错误包数 */
ULONG ulEtherReceiveIgmpUnknown; /*统计Ethernet收到的无法识别的包数 */
ULONG ulATMReceiveIgmpPkt; /*统计ATM收到的IGMP包总数 */
ULONG ulATMReceiveIgmpV1Query; /*统计ATM收到的IGMP V1 Query包数 */
ULONG ulATMReceiveIgmpV2Query; /*统计ATM收到的IGMP V2 Query包数 */
ULONG ulATMReceiveIgmpV1MembershipReport; /*统计ATM收到的IGMP V1 Report包数 */
ULONG ulATMReceiveIgmpV2MembershipReport; /*统计ATM收到的IGMP V2 Report包数 */
ULONG ulATMReceiveIgmpV3MembershipReport;
ULONG ulATMReceiveIgmpLeaveGroup; /*统计ATM收到的IGMP Leave包数 */
ULONG ulATMReceiveIgmpBad; /*统计ATM收到的错误包数 */
ULONG ulATMReceiveIgmpUnknown; /*统计ATM收到的无法识别的包数 */
ULONG ulIGMPReceivePktAll; /*统计接收模块总共收到的包数 */
ULONG ulIGMPSendToQueueAll; /*统计接收模块发送进消息队列的包数 */
ULONG ulIGMPReceiveBadPktAll; /*统计接收模块收到的错误包数 */
ULONG ulIGMPDropPktAll; /*统计接收模块丢弃的包总数 */
ULONG ulIGMPMembershipQuerySent; /*统计发送查询包的总数 */
ULONG ulIGMPMembershipGeneralQuerySent; /*统计发送通用查询包的总数 */
ULONG ulIGMPMembershipSpecificQuerySent; /*统计发送特定查询包的总数 */
ULONG ulIGMPMembershipV1QuerySent; /*统计发送V1查询包的总数 */
ULONG ulIGMPMembershipV2QuerySent; /*统计发送V2查询包的总数 */
ULONG ulIGMPV1MembershipReportSent; /*统计发送版本1报告的总数 */
ULONG ulIGMPV2MembershipReportSent; /*统计发送版本2报告的总数 */
ULONG ulIGMPLeaveGroupSent; /*统计发送离开包的总数 */
ULONG ulIGMPEtherSent; /*统计Ether发送的包总数 */
ULONG ulGeneralQueryTimeOutTimes;
ULONG ulHostReportDelayTimeOutTimes;
ULONG ulGroupPortV2MembershipTimeOutTimes;
ULONG ulGroupPortLastMemberQueryTimeOutTimes;
ULONG ulGroupV1HostPresentTimeOutTimes;
ULONG ulGroupPortV1HostTimeOutTimes;
ULONG ulStartupQueryTimeOutTimes;
ULONG ulV1RouterPresentTimeOutTimes;
ULONG ulOtherQuerierPresentTimeOutTimes;
USHORT usCurrentMsgQLength;
USHORT usRealMaxMsgQLength;
USHORT usCurrentUser; /*当前组播用户数 */
USHORT usCurrentGroup; /*当前频道数 */
USHORT usCurrentTimer; /*当前定时器个数 */
UCHAR ucCurrentStartupQueryCount;
ULONG ulCustomMemoryUsed;
USHORT sMaxIGMPMsgQLength = 4096; /*IGMP 消息队列长度 */
GroupEntity *pGroupEntityList;
int nodelete;
int testReceieveJoin = 0; /*测试收到并处理的加入报文 */
int testReceiveLeave = 0; /*测试收到并处理的离开报文 */
struct Test_Mode modepar;
/****####修改开始 changzhan于 2004年8月24日14时25分(版本:4.3.2.2)####****/
/*GroupEntity IgmpGroupEntity[usMaxGroup];
TimerEntity IgmpTimerEntity[usMaxTimer];*/
GroupEntity *IgmpGroupEntity = NULL;
TimerEntity *IgmpTimerEntity = NULL;
/****************************************************************
Add for Pre-join IGMP Group 2005.7.10
*/
PreJoinNode *IgmpPreJoinNode = NULL;
PreJoinNode *pPreJoinList;
USHORT usCurrentPreJoinNode;
/****************************************************************
END
*/
/****####修改结束changzhan于 2004年8月24日14时25分(版本:4.3.2.2)####****/
#ifdef __cplusplus
extern "C"
{
#endif
/***************************************************
函数名称:IgmpInit
函数功能:IGMP Proxy模块初始化函数,负责
开启IGMP任务,初始化变量
输入参数:无
返回值:无
***************************************************/
int IgmpInit ()
{
/*USHORT i; */
char mac[6];
char date[20];
int i;
memset (add, 0, sizeof (add));
memset (timeget, 0, sizeof (timeget));
gEtherInfo.ipAddr = 0x0a190e39;
get_default_mac_addr (mac);
gEtherInfo.etherMac[0] = mac[0];
gEtherInfo.etherMac[1] = mac[1];
gEtherInfo.etherMac[2] = mac[2];
gEtherInfo.etherMac[3] = mac[3];
gEtherInfo.etherMac[4] = mac[4];
gEtherInfo.etherMac[5] = mac[5];
/*初始化时设定29:1-29:7为上联口 */
memset (slot_module, ROUTER_MODULE_PORT, sizeof (slot_module));
for (i = MIN_UPLINK_PORT; i <= MAX_UPLINK_PORT; i++)
slot_module[i] = HOST_MODULE_PORT;
if (nIGMPTaskId != 0)
{
return ERROR;
}
semIgmpDelete = semMCreate (SEM_Q_PRIORITY);
semIgmpReceive = semBCreate (SEM_Q_PRIORITY, SEM_FULL);
semIgmpTimeOut = semBCreate (SEM_Q_PRIORITY, SEM_FULL);
semPreJoin = semBCreate (SEM_Q_PRIORITY, SEM_FULL);
semSwitch = semBCreate (SEM_Q_PRIORITY, SEM_FULL);
if (!IgmpInitParameters ()) /*初始化全局变量 */
{
printf ("Parameters Init Fail!\n");
return ERROR;
}
/*创建消息队列 */
IGMPMsgQId =
msgQCreate (sMaxIGMPMsgQLength, sizeof (IGMPMsg), MSG_Q_FIFO);
if (IGMPMsgQId == 0)
{
printf ("Create the message queue failure!\n");
return ERROR;
}
/*启动主任务 */
nIGMPTaskId =
taskSpawn ("tIgmp", 55, 0, 8000, (FUNCPTR) IgmpMain, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0);
if (nIGMPTaskId == ERROR)
{
printf ("IGMP Task Spawn ERROR!\n");
nIGMPTaskId = 0;
return ERROR;
}
driver_igmpenable ();
#ifdef _AN5116_06A_
driver_dtag_igmpenable ();
#endif
/*命令行安装aibin */
/*printf ("IGMP Task Init OK!Task ID = 0x%x\n",nIGMPTaskId); */
return OK;
}
void set_igmp_proxy_default (void)
{
char mac[6];
char date[20];
int i;
gEtherInfo.ipAddr = 0x0a190e39;
set_igmp_cascade_default ();
global_vlan = DefaultVlan;
Guserlimit = 100; /* 每组用户容量最大为100个用户 */
Ggrouplimit = MaxGroup;
DelAllPreJoinNode ();
}
#ifdef __cplusplus
}
#endif
/***************************************************
函数名称:IgmpMain
函数功能:IGMP Proxy模块主函数,负责轮询
消息队列,并区分不同数据包
交给不同的子模块处理。
输入参数:无
返回值:无
备注: mod by aibin 2005-01-14
***************************************************/
void IgmpMain ()
{
IGMPMsg ReceiveIgmpMsg;
memset (&ReceiveIgmpMsg, 0, sizeof (IGMPMsg));
while (1)
{
if (msgQReceive (IGMPMsgQId, (char *) &ReceiveIgmpMsg, sizeof (IGMPMsg),
WAIT_FOREVER) == sizeof (IGMPMsg))
{
/*printf ("receive a msg\n");
printf("msg's port is %d, type is %d\n",ReceiveIgmpMsg.usPort,ReceiveIgmpMsg.ucIGMPType); */
//taskLock();
ProcessReceiveIgmpPkt (ReceiveIgmpMsg);
//taskUnlock();
}
else
{
if (bIgmpDebug)
{
printf ("msgQReceive failed!\n");
}
}
}
}
/***************************************************
函数名称:IgmpInitParameters
函数功能:初始化全局变量,启动初始查
询定时器
输入参数:无
返回值: TRUE 表示成功
FASLE 表示失败
***************************************************/
BOOL IgmpInitParameters (void)
{
USHORT i;
for (i = 1; i <= MAX_UPLINK_PORT; i++)
{
bEnablePortIGMP[i] = TRUE;
usPortMapSessionId[i] = 0;
}
/*move */
fpreviewflag = 0; /* preview function flag, 0:disble, 1:enble */
figmpportflag = 0; /* igmp port swich, 0:disble, 1:enalbe */
fgroupauthflag = 0; /* group auth flag, 0:disable, 1:enable */
fsourcecon = 0;
tIgmpPreviewTimer = 0; /*设置预览定时器aibin 2005-4-12 */
global_vlan = DefaultVlan;
Guserlimit = 100; /* 每组用户容量最大为100个用户 */
Ggrouplimit = 255;
igmpageflag = TRUE; /*使能生存周期设置 */
bHostEnableIGMPV1 = FALSE; /*Host是否兼容IGMPV1 */
bRouterEnableIGMPV1 = TRUE; /*Router是否兼容IGMPV1 */
bEnableHostModule = TRUE; /*是否打开以太网侧HOST功能 */
bEnableRouterModule = TRUE; /*是否打开ATM侧Router功能 */
bEnableQueryElection = FALSE; /*否进行IGMP V2 查询者选举 */
bEnableSecurityOption = TRUE; /*是否检查IP包安全选项 */
bQuerierFlag = TRUE; /*查询者标志 */
bV1RouterPresentFlag = FALSE; /*V1版本路由器存在标志 */
ucRobustness = 2; /*健壮性变量 */
usQueryInterval = 125; /*通用查询周期 */
usStartupQueryInterval = 31; /*初始查询周期 */
ucStartupQueryCount = 2; /*初始查询次数 */
usGroupMembershipInterval = 260; /*V2成员存在周期 */
usQueryResponseInterval = 10; /*最大响应时间(seconds) */
usLastMemberQueryInterval = 1; /*最后成员查询周期 */
ucLastMemberQueryCount = 2; /*最后成员查询次数 */
usUnsolicitedReportInterval = 10; /*主动报告发送周期 */
usV1RouterPresentTimeout = 400; /*V1版本路由器存在超时 */
usOtherQuerierPresentInterval = 255; /*其他查询者存在周期 */
tV1RouterPresentTimer = 0; /*V1版本路由器存在定时器 */
tOtherQuerierPresentTimer = 0; /*其他查询者存在定时器 */
ulATMReceiveIgmpPkt = 0; /*统计收到的IGMP包总数 */
ulATMReceiveIgmpV1Query = 0; /*统计收到的IGMP V1 Query包数 */
ulATMReceiveIgmpV2Query = 0; /*统计收到的IGMP V2 Query包数 */
ulATMReceiveIgmpV1MembershipReport = 0; /*统计收到的IGMP V1 Report包数 */
ulATMReceiveIgmpV2MembershipReport = 0; /*统计收到的IGMP V2 Report包数 */
ulATMReceiveIgmpV3MembershipReport = 0;
ulATMReceiveIgmpLeaveGroup = 0; /*统计收到的IGMP Leave包数 */
ulATMReceiveIgmpBad = 0; /*统计收到的错误包数 */
ulATMReceiveIgmpUnknown = 0; /*统计收到的无法识别的包数 */
ulEtherReceiveIgmpPkt = 0; /*统计收到的IGMP包总数 */
ulEtherReceiveIgmpV1Query = 0; /*统计收到的IGMP V1 Query包数 */
ulEtherReceiveIgmpV2Query = 0; /*统计收到的IGMP V2 Query包数 */
ulEtherReceiveIgmpV1MembershipReport = 0; /*统计收到的IGMP V1 Report包数 */
ulEtherReceiveIgmpV2MembershipReport = 0; /*统计收到的IGMP V2 Report包数 */
ulEtherReceiveIgmpV3MembershipReport = 0;
ulEtherReceiveIgmpLeaveGroup = 0; /*统计收到的IGMP Leave包数 */
ulEtherReceiveIgmpBad = 0; /*统计收到的错误包数 */
ulEtherReceiveIgmpUnknown = 0; /*统计收到的无法识别的包数 */
ulIGMPReceivePktAll = 0; /*统计接收模块总共收到的包数 */
ulIGMPSendToQueueAll = 0; /*统计接收模块发送进消息队列的包数 */
ulIGMPReceiveBadPktAll = 0; /*统计接收模块收到的错误包数 */
ulIGMPDropPktAll = 0; /*统计接收模块丢弃的包数 */
ulIGMPMembershipQuerySent = 0; /*统计发送查询包的总数 */
ulIGMPMembershipGeneralQuerySent = 0; /*统计发送通用查询包的总数 */
ulIGMPMembershipSpecificQuerySent = 0; /*统计发送特定查询包的总数 */
ulIGMPMembershipV1QuerySent = 0; /*统计发送V1查询包的总数 */
ulIGMPMembershipV2QuerySent = 0; /*统计发送V2查询包的总数 */
ulIGMPV1MembershipReportSent = 0; /*统计发送版本1报告的总数 */
ulIGMPV2MembershipReportSent = 0; /*统计发送版本2报告的总数 */
ulIGMPLeaveGroupSent = 0; /*统计发送离开包的总数 */
ulIGMPEtherSent = 0; /*统计Ether发送的包总数 */
ulGeneralQueryTimeOutTimes = 0;
ulHostReportDelayTimeOutTimes = 0;
ulGroupPortV2MembershipTimeOutTimes = 0;
ulGroupPortLastMemberQueryTimeOutTimes = 0;
ulGroupV1HostPresentTimeOutTimes = 0;
ulGroupPortV1HostTimeOutTimes = 0;
ulStartupQueryTimeOutTimes = 0;
ulV1RouterPresentTimeOutTimes = 0;
ulOtherQuerierPresentTimeOutTimes = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -