?? zl5011xpacketrx.c
字號:
{
templateInUse = &(zl5011xPacketRxTemplatesIPv6[par->protocolType]);
}
/* allow the application to specify a protocol number to use */
lanRxSetProtocolMatch->matchNum = par->protocolMatchNumber;
lanRxSetProtocolMatch->output.discardUdpCheckFails = par->discardUdpCheckFails;
lanRxSetProtocolMatch->output.protocolIpv4 = par->ipVer4;
lanRxSetProtocolMatch->output.protocolVlan = par->enableVlan;
lanRxSetProtocolMatch->output.timestampShift = templateInUse->timestampShift;
if (par->forceOneByteSeq == ZL5011X_TRUE)
{
lanRxSetProtocolMatch->output.protocolTwoByteSeq = ZL5011X_FALSE;
}
else
{
lanRxSetProtocolMatch->output.protocolTwoByteSeq = templateInUse->protocolSeqLength16Bits;
}
/* Set up the location of the PW byte, allowing for the optional VLAN header and
L2TPv3 cookie */
lanRxSetProtocolMatch->output.extractPwByte = (Uint8T)(templateInUse->extractPwByte + vlanOffset + cookieOffset);
for (n = 0; n < ZL5011X_PKC_PROTOCOL_NUM_MATCH_FIELDS; n++)
{
protocolMatchIndex = n;
headerMatchIndex = n;
if (n >= (ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE))
{
headerMatchIndex += snapOffset;
}
/* If the ethernet header contains SNAP, then this field is removed by the device,
so need to skip over those bytes from the incoming header */
lanRxSetProtocolMatch->match.protocolMatchBytes[protocolMatchIndex] = par->header[headerMatchIndex];
}
for (n = 0; n < (ZL5011X_PKC_PROTOCOL_NUM_MATCH_FIELDS - vlanOffset - cookieOffset); n++)
{
protocolMaskIndex = n;
templateMaskIndex = n;
if (n >= (ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE))
{
protocolMaskIndex += vlanOffset;
}
if (protocolMaskIndex >= (l2tpHeaderPos + ZL5011X_PKT_L2TPV3_HDR_LEN - snapOffset))
{
protocolMaskIndex += cookieOffset;
}
if (protocolMaskIndex >= ZL5011X_PKC_PROTOCOL_NUM_MATCH_FIELDS)
{
break;
}
/* The bytes indexed in the template are indexed without knowledge of the
presence of VLAN or SNAP. Since SNAP will have been removed by the time
this stuff is applied, we only need to worry about VLAN. If VLAN is
present, then when the byte index gets to the VLAN position, the mask
has to be shifted by the size of VLAN. */
lanRxSetProtocolMatch->match.protocolMaskBytes[protocolMaskIndex] = templateInUse->protocolMaskBytes[templateMaskIndex];
if (udpHeader == ZL5011X_TRUE)
{
/* using UDP header so apply the required masks for the port addresses */
if (templateMaskIndex == (udpPos + ZL5011X_PKT_UDP_SRC_PORT_POS + 0))
{
lanRxSetProtocolMatch->match.protocolMaskBytes[protocolMaskIndex] = (Uint8T)(~(par->srcUdpPortMask) >> 8);
}
if (templateMaskIndex == (udpPos + ZL5011X_PKT_UDP_SRC_PORT_POS + 1))
{
lanRxSetProtocolMatch->match.protocolMaskBytes[protocolMaskIndex] = (Uint8T)(~(par->srcUdpPortMask) >> 0);
}
if (templateMaskIndex == (udpPos + ZL5011X_PKT_UDP_DEST_PORT_POS + 0))
{
lanRxSetProtocolMatch->match.protocolMaskBytes[protocolMaskIndex] = (Uint8T)(~(par->destUdpPortMask) >> 8);
}
if (templateMaskIndex == (udpPos + ZL5011X_PKT_UDP_DEST_PORT_POS + 1))
{
lanRxSetProtocolMatch->match.protocolMaskBytes[protocolMaskIndex] = (Uint8T)(~(par->destUdpPortMask) >> 0);
}
}
}
if (par->matchDestMacAddress == ZL5011X_TRUE)
{
for (n = 0; n < ZL5011X_MAC_SIZE; n++)
{
lanRxSetProtocolMatch->match.protocolMaskBytes[n] = ZL5011X_MASK_IN;
}
}
if ((par->matchDestIpv4Address == ZL5011X_TRUE) && (ipv4Header == ZL5011X_TRUE))
{
/* using IPv4 header and need to add dest src address to the protocol match */
Uint32T ipPos;
ipPos = ZL5011X_PKT_ETHERNET_HDR_LEN + vlanOffset + ZL5011X_PKT_IPV4_DEST_POS;
for (n = 0; n < (ZL5011X_PKT_IPV4_ADDR_LEN / 2); n++)
{
lanRxSetProtocolMatch->match.protocolMaskBytes[ipPos + n] = ZL5011X_MASK_IN;
}
}
/* if VLAN is enabled, then the ethertype check in the template will be checking the ethertype
part of the VLAN header, so need to add in a check for the ethertype in the ethernet header */
if (par->enableVlan == ZL5011X_TRUE)
{
lanRxSetProtocolMatch->match.protocolMaskBytes[ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE] = ZL5011X_MASK_IN;
lanRxSetProtocolMatch->match.protocolMaskBytes[ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE + 1] = ZL5011X_MASK_IN;
}
/* work out if the sequence number needs to be different from that in the template */
seqOffset = 0;
if (par->rtpForceSeqNumber == ZL5011X_TRUE)
{
/* The template is setup for using the first sequence number in the protocol stack by default.
But in this case choosing to use the RTP field so work out the offset */
if ((par->protocolType == ZL5011X_MPLS_PW_RTP) || (par->protocolType == ZL5011X_MPLS_RTCP_CTRL) ||
(par->protocolType == ZL5011X_CUSTOM8_PW_RTP))
{
seqOffset = (ZL5011X_PKT_PW_HDR_LEN - ZL5011X_PKT_PW_SEQ_POS) + ZL5011X_PKT_RTP_SEQ_POS;
}
}
else
{
/* The template is setup for using the first sequence number in the protocol stack by default.
But in this case choosing to use the PW field so work out the offset */
if ((par->protocolType == ZL5011X_IP_UDP_RTP_PW) || (par->protocolType == ZL5011X_IP_L2TPV3_RTP_PW) ||
(par->protocolType == ZL5011X_IP_UDP_RTCP_CTRL) || (par->protocolType == ZL5011X_IP_L2TPV3_RTCP_CTRL) ||
(par->protocolType == ZL5011X_CUSTOM8_RTP_PW) ||
(par->protocolType == ZL5011X_IP_UDP_RTP_PW_ALT))
{
seqOffset = (ZL5011X_PKT_RTP_HDR_LEN - ZL5011X_PKT_RTP_SEQ_POS) + ZL5011X_PKT_PW_SEQ_POS;
}
}
for (n = 0; n < ZL5011X_PKC_PROTOCOL_MAX_SEQ_BYTES; n++)
{
/* adjust the position, since it comes after the VLAN and L2TP cookie (if present) */
lanRxSetProtocolMatch->output.extractSequenceBytes[n] = (Uint8T)(templateInUse->extractSequenceBytes[n] +
vlanOffset + cookieOffset + seqOffset);
}
for (n = 0; n < ZL5011X_PKC_PROTOCOL_MAX_TIMESTAMP_BYTES; n++)
{
if (par->disableTimestamp == ZL5011X_FALSE)
{
/* adjust the position, since it comes after the VLAN and L2TP cookie (if present) */
lanRxSetProtocolMatch->output.extractTimestampBytes[n] = (Uint8T)(templateInUse->extractTimestampBytes[n] +
vlanOffset + cookieOffset);
}
else
{
/* don't want to extract the timestamp, so just set the position to the
first byte in the packet */
lanRxSetProtocolMatch->output.extractTimestampBytes[n] = 0;
}
}
for (n = 0; n < ZL5011X_PKC_PROTOCOL_MAX_LENGTH_BYTES; n++)
{
/* adjust the position, since it comes after the VLAN and before L2TP cookie (if present) */
lanRxSetProtocolMatch->output.extractLengthBytes[n] = (Uint8T)(templateInUse->extractLengthBytes[n] +
vlanOffset);
}
for (n = 0; n < ZL5011X_PKC_CLASSIFY_NUM_MATCH_FIELDS; n++)
{
/* work out if any VLAN or L2TP cookie offset is applicable to this entry in the
template. If so, then adjust as appropriate */
if (templateInUse->extractClassifyBytes[n] >= (ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE))
{
tempOffset = vlanOffset;
}
else
{
tempOffset = 0;
}
if (templateInUse->extractClassifyBytes[n] >= (l2tpHeaderPos + ZL5011X_PKT_L2TPV3_HDR_LEN - snapOffset - vlanOffset))
{
/* if L2TP is not enabled then the offset will be zero, so doesn't matter if it gets added */
tempOffset += cookieOffset;
}
lanRxSetProtocolMatch->output.extractClassifyBytes[n] = (Uint8T)(templateInUse->extractClassifyBytes[n] + tempOffset);
}
for (n = 0; n < ZL5011X_PKC_CLASSIFY_NUM_CHECK_FIELDS; n++)
{
/* work out if any VLAN or L2TP cookie offset is applicable to this entry in the
template. If so, then adjust as appropriate */
if (templateInUse->extractCheckBytes[n] >= (ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE))
{
tempOffset = vlanOffset;
}
else
{
tempOffset = 0;
}
if (templateInUse->extractCheckBytes[n] >= (l2tpHeaderPos + ZL5011X_PKT_L2TPV3_HDR_LEN - snapOffset - vlanOffset))
{
tempOffset += cookieOffset;
}
lanRxSetProtocolMatch->output.extractCheckBytes[n] = (Uint8T)(templateInUse->extractCheckBytes[n] + tempOffset);
lanRxSetProtocolMatch->output.checkMask[n] = templateInUse->checkMask[n];
if ((templateInUse->extractCheckBytes[n] == templateInUse->extractPwByte) &&
(templateInUse->extractPwByte != 0))
{
Uint32T pwMask;
/* PW status byte field, so set the mask independently of the template */
if (par->statusByteMask == (Uint32T)ZL5011X_INVALID)
{
/* L, R and top M bit are ignored for packet acceptance */
pwMask = ZL5011X_PACKET_DEFAULT_STATUS_MASK;
}
else
{
pwMask = ~par->statusByteMask & 0xff;
}
lanRxSetProtocolMatch->output.checkMask[n] = pwMask;
}
/* if this is a length field, then mask out the check if length is NOT to be used */
if ((templateInUse->extractCheckBytes[n] != 0) &&
(par->lengthUsage != ZL5011X_PACKET_LENGTH_CHECK) &&
((templateInUse->extractCheckBytes[n] == templateInUse->extractLengthBytes[0]) ||
(templateInUse->extractCheckBytes[n] == templateInUse->extractLengthBytes[1])))
{
lanRxSetProtocolMatch->output.checkMask[n] = ZL5011X_MASK_OUT;
}
}
/* If VLAN is enabled then the there are some extra matches for the VLAN ID
that can applied (either for classification or checking) */
if (par->enableVlan == ZL5011X_TRUE)
{
/* If the VLAN ID is to be checked, then setup the fields */
if (templateInUse->vlanCheckPos[0] < ZL5011X_PKC_CLASSIFY_NUM_CHECK_FIELDS)
{
lanRxSetProtocolMatch->output.extractCheckBytes[templateInUse->vlanCheckPos[0]] =
ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE + ZL5011X_PKT_ETHERTYPE_LEN;
lanRxSetProtocolMatch->output.checkMask[templateInUse->vlanCheckPos[0]] =
(Uint8T)(ZL5011X_MASK_IN_VLAN_ID >> 8);
}
if (templateInUse->vlanCheckPos[1] < ZL5011X_PKC_CLASSIFY_NUM_CHECK_FIELDS)
{
lanRxSetProtocolMatch->output.extractCheckBytes[templateInUse->vlanCheckPos[1]] =
ZL5011X_MAC_SIZE + ZL5011X_MAC_SIZE + ZL5011X_PKT_ETHERTYPE_LEN + 1;
lanRxSetProtocolMatch->output.checkMask[templateInUse->vlanCheckPos[1]] =
(Uint8T)ZL5011X_MASK_IN_VLAN_ID;
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -