📄 igmp_main.cpp
字号:
*/
timetick1 = tickGet ();
if (*(IgmpPkt + 38) == 0x16)
{
timeget[groupid].tick1 = tickGet ();
}
ulIGMPReceivePktAll++;
/***********************************************************************************/
#if 1
if (turbo)
{
groupaddress = htonl (*((ULONG *) (IgmpPkt + 42)));
if (*(IgmpPkt + 38) == 0x16)
{
ulATMReceiveIgmpV2MembershipReport++;
for (i = 0; i < MaxGroup; i++)
{
if (add[i].groupaddress == groupaddress)
{
if (add[i].slot[usPort])
{
return OK;
}
else
{
add[i].slot[usPort] = 1;
add[i].count++;
AddPortToGroup (groupaddress, usPort);
timeget[groupid].tick4 = tickGet ();
groupid++;
return OK;
}
}
}
//printf("Rx Join\n");
if (usCurrentGroup >= MaxGroup)
return ERROR;
usCurrentGroup++;
AddGroup (groupaddress);
timeget[groupid].tick2 = tickGet ();
AddPortToGroup (groupaddress, usPort);
SendIgmpPkt (IGMPV2MembershipReport, groupaddress, 0, 0);
/*uESend((UINT *) IgmpPkt, usLength, 0, 0); */
timeget[groupid].tick3 = tickGet ();
timeget[groupid].groupaddress = groupaddress;
i = 0;
while (i < MaxGroup)
{
if (!add[i].groupaddress)
{
add[i].groupaddress = groupaddress;
add[i].count++;
add[i].slot[usPort] = 1;
timeget[groupid].tick4 = tickGet ();
groupid++;
return OK;
}
i++;
}
}
else if (*(IgmpPkt + 38) == 0x17)
{
ulATMReceiveIgmpLeaveGroup++;
for (i = 0; i < MaxGroup; i++)
{
if (add[i].groupaddress == groupaddress)
{
if (add[i].slot[usPort])
{
DelPortFromGroup1 (groupaddress, usPort);
add[i].slot[usPort] = 0;
add[i].count--;
if (!add[i].count)
{
DelGroup (groupaddress);
add[i].groupaddress = 0;
usCurrentGroup--;
SendIgmpPkt (IGMPLeaveGroup, groupaddress, 0,
0);
}
return OK;
}
}
}
return OK;
}
else if (*(IgmpPkt + 38) == 0x11)
{
/*发IGMP 查询报文 */
for (i = 1; i <= MAX_UPLINK_PORT; i++)
{
if (i == usPort)
continue;
SendIgmpPkt (0x11, 0, i, 10);
}
}
else
{
return OK;
}
}
#endif
/***********************************************************************************/
/*ParameterNotUse (UINT (usLength)); */
/*有效性检查 */
if (nIGMPTaskId == 0)
{
if (bIgmpDebug)
{
printf ("IGMP Task does not exist,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
if (usPort > MAX_UPLINK_PORT)
{
if (bIgmpDebug)
{
printf ("IGMP Port out of range!\n");
}
ulIGMPDropPktAll++;
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
/*统计队列长度 */
MsgNum = msgQNumMsgs (IGMPMsgQId);
usCurrentMsgQLength = USHORT (MsgNum);
if (usCurrentMsgQLength > usRealMaxMsgQLength)
{
usRealMaxMsgQLength = usCurrentMsgQLength;
}
if (MsgNum >= sMaxIGMPMsgQLength) /*队列已经满了 */
{
if (bIgmpDebug)
{
printf ("MessageQueue is Full,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
semTake (semIgmpReceive, WAIT_FOREVER);
/*开始对收到的包进行解码 */
if (htons (*((USHORT *) (IgmpPkt + 12))) != 0x8100) /*无VLAN TAG */
{
ReceiveIgmpMsg.VlanTag = 0;
if (htons (*((USHORT *) (IgmpPkt + 12))) == 0x8864) /*有PPPoE封装 */
{
/*printf("Rx IGMP with PPPoE\n"); */
PPPoEFlag = 1;
IpHeaderInPkt = (ipheader *) (IgmpPkt + 22);
usSessionId = htons (*((USHORT *) (IgmpPkt + 16)));
}
else /*无PPPoE封装 */
{
PPPoEFlag = 0;
IpHeaderInPkt = (ipheader *) (IgmpPkt + 14);
usSessionId = 0;
}
IpHeaderLength = IpHeaderInPkt->headerlength * 4;
IpProtocolInPkt = IpHeaderInPkt->protocol;
if (IpProtocolInPkt != 2) /*不是IGMP包 */
{
if (bIgmpDebug)
{
printf ("Not IGMP Pkt,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
/*printf ("Not IGMP Pkt,Receive ERROR!\n"); */
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
if (IpHeaderInPkt->ttl != 1) /*IGMP包TTL必须等于1,参见RFC2236 */
{
if (bIgmpDebug)
{
printf ("TTL != 1,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
/*printf ("TTL != 1,Receive ERROR!\n"); */
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
if (!VerifyChecksum ((UCHAR *) IpHeaderInPkt, IpHeaderLength, 10)) /*校验和检查 */
{
if (bIgmpDebug)
{
printf ("Bad IP Checksum,Receive ERROR!\n");
for (int iii = 0; iii < 64; iii++)
printf ("%0x - ", *(IgmpPkt + iii));
printf ("\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
/*printf ("Bad IP Checksum,Receive ERROR!\n"); */
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
/*if(ntohl (IpHeaderInPkt->daddr) == 0xe0000016)
IGMPV3Flag = 1; */
IgmpHeaderInPkt =
(igmpheader *) (IgmpPkt + IpHeaderLength + 14 + PPPoEFlag * 8);
if (!VerifyChecksum ((UCHAR *) IgmpHeaderInPkt, sizeof (igmpheader),
2))
{
if (IgmpHeaderInPkt->ucType != IGMPV3MembershipReport)
{
if (bIgmpDebug)
{
printf ("Bad IGMP Checksum,Receive ERROR!\n");
for (int iii = 0; iii < 64; iii++)
printf ("%0x - ", *(IgmpPkt + iii));
printf ("\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
}
if (bEnableSecurityOption)
{
if ((IgmpHeaderInPkt->ucType == IGMPV2MembershipReport) ||
(IgmpHeaderInPkt->ucType == IGMPLeaveGroup) ||
(IgmpHeaderInPkt->ucType == IGMPV3MembershipReport))
{
if (IpHeaderLength <= 5)
{
if (bIgmpDebug)
{
printf ("No Security Option,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
else
{
if (htonl (*((UINT *) (IgmpPkt + 34 + PPPoEFlag * 8))) != 0x94040000) /*Security Option */
{
if (bIgmpDebug)
{
printf ("Bad Security Option,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
}
}
}
ReceiveIgmpMsg.ucIGMPType = IgmpHeaderInPkt->ucType;
ReceiveIgmpMsg.unSourceAddress = ntohl (IpHeaderInPkt->saddr);
ReceiveIgmpMsg.unDestinationAddress = ntohl (IpHeaderInPkt->daddr);
p = (char *) IgmpHeaderInPkt;
user = (UCHAR *) (p + 8);
ReceiveIgmpMsg.user = *user;
if (IgmpHeaderInPkt->ucType == IGMPV3MembershipReport)
{
ReceiveIgmpMsg.unGroupAddress =
htonl (*((UINT *) (IgmpPkt + 50 + PPPoEFlag * 8)));
}
else
{
ReceiveIgmpMsg.unGroupAddress =
ntohl (IgmpHeaderInPkt->unGroupAddress);
}
ReceiveIgmpMsg.ucMaxResponseTime =
(UCHAR) (IgmpHeaderInPkt->ucMaxRespTime / 10);
ReceiveIgmpMsg.usPort = usPort;
ReceiveIgmpMsg.usSessionId = usSessionId;
}
else /*带有VLAN TAG */
{
ReceiveIgmpMsg.VlanTag = htons (*((USHORT *) (IgmpPkt + 14)));
if (htons (*((USHORT *) (IgmpPkt + 16))) == 0x8864) /*有PPPoE封装 */
{
//printf("PPPoE w 802.1q\n");
PPPoEFlag = 1;
IpHeaderInPkt = (ipheader *) (IgmpPkt + 26);
usSessionId = htons (*((USHORT *) (IgmpPkt + 20)));
}
else /*无PPPoE封装 */
{
PPPoEFlag = 0;
IpHeaderInPkt = (ipheader *) (IgmpPkt + 18);
usSessionId = 0;
}
IpHeaderLength = IpHeaderInPkt->headerlength * 4;
IpProtocolInPkt = IpHeaderInPkt->protocol;
if (IpProtocolInPkt != 2)
{
if (bIgmpDebug)
{
printf ("Not IGMP Pkt,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
if (IpHeaderInPkt->ttl != 1)
{
printf ("TTL != 1,Receive ERROR!\n");
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
/*
if(PPPoEFlag)
{
IgmpHeaderInPkt = (igmpheader *) (IgmpPkt + IpHeaderLength * 4 + 26);
}
else
{ */
IgmpHeaderInPkt =
(igmpheader *) (IgmpPkt + IpHeaderLength + 18 + PPPoEFlag * 8);
/*} */
if (bEnableSecurityOption)
{
if ((IgmpHeaderInPkt->ucType == IGMPV2MembershipReport) ||
(IgmpHeaderInPkt->ucType == IGMPLeaveGroup) ||
(IgmpHeaderInPkt->ucType == IGMPV3MembershipReport))
{
if (IpHeaderLength <= 5)
{
if (bIgmpDebug)
{
printf ("No Security Option,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
else
{
if (htonl (*((UINT *) (IgmpPkt + 38 + PPPoEFlag * 8))) != 0x94040000) /*Security Option */
{
if (bIgmpDebug)
{
printf ("Bad Security Option,Receive ERROR!\n");
}
ulIGMPDropPktAll++;
ulIGMPReceiveBadPktAll++;
semGive (semIgmpReceive);
free ((void *) IgmpPkt);
/*device_driver_free ((void *) IgmpPkt); */
IgmpPkt = NULL;
return ERROR;
}
}
}
}
ReceiveIgmpMsg.ucIGMPType = IgmpHeaderInPkt->ucType;
//printf("type = 0x%x\n",IgmpHeaderInPkt->ucType);
ReceiveIgmpMsg.unSourceAddress = ntohl (IpHeaderInPkt->saddr);
ReceiveIgmpMsg.unDestinationAddress = ntohl (IpHeaderInPkt->daddr);
if (IgmpHeaderInPkt->ucType == IGMPV3MembershipReport)
{
ReceiveIgmpMsg.unGroupAddress =
htonl (*((UINT *) (IgmpPkt + 54 + PPPoEFlag * 8)));
}
else
{
ReceiveIgmpMsg.unGroupAddress =
ntohl (IgmpHeaderInPkt->unGroupAddress);
}
ReceiveIgmpMsg.ucMaxResponseTime =
(UCHAR) (IgmpHeaderInPkt->ucMaxRespTime / 10);
ReceiveIgmpMsg.usPort = usPort;
ReceiveIgmpMsg.usSessionId = usSessionId;
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -