📄 pppasyncframing.c
字号:
netMblkClChainFree(inFrame); RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInDiscards, 1); return ERROR; } else { /* netTupleGet will not clear mLen */ outPacket->mBlkHdr.mLen = 0; outPacket->mBlkHdr.mFlags &= ~M_PKTHDR; outPacket->mBlkPktHdr.len = 0; } if (stackData->peerToLocalACCompression == TRUE) outPacket->mBlkHdr.mData += 2; if (stackData->peerToLocalProtocolCompression == TRUE) outPacket->mBlkHdr.mData += 1; /* decode the packet by removing all the stuffed AHDLC's escape chars */ if (convertAsynchronousDataToNormalData(state,inFrame,outPacket) == ERROR) {#ifdef PPP_DEBUG printf ("PPP: Error: Bad data on asynchronous port \n");#endif /* PPP_DEBUG */ netMblkClChainFree(inFrame); netMblkClChainFree(outPacket); return ERROR; } /* free received Frame */ netMblkClChainFree(inFrame); if (stackData->receiveFcsSize == PPP_16BIT_FCS) { /* find the end of the decoded packet chain; use inFrame as temp store*/ inFrame = outPacket; while(inFrame->mBlkHdr.mNext != NULL) inFrame = inFrame->mBlkHdr.mNext; /* Check the FCS */ calculated16BitCkSum = calculate16BitFcs(PPPINITFCS16, outPacket); if (calculated16BitCkSum != PPPGOODFCS16) { (counterInterface->pppLinkStatusBadFCSsIncrement)( stackData->pppLinkCounterInterface.state);#ifdef PPP_DEBUG printf ("PPP: Error: Bad 16 Bit Checksum on Asynchronous port \n");#endif /* PPP_DEBUG */ netMblkClChainFree(outPacket); RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); return (ERROR); } /* delete 16-bit FCS from end of frame */ m_adj(outPacket, -2); } else if (stackData->receiveFcsSize == PPP_32BIT_FCS) { /* find the end of the decoded packet chain; use inFrame as temp store*/ inFrame = outPacket; while(inFrame->mBlkHdr.mNext != NULL) inFrame = inFrame->mBlkHdr.mNext; /* Check the FCS */ calculated32BitCkSum = calculate32BitFcs(PPPINITFCS32, outPacket); if (calculated32BitCkSum != PPPGOODFCS32) { (counterInterface->pppLinkStatusBadFCSsIncrement)( stackData->pppLinkCounterInterface.state);#ifdef PPP_DEBUG printf ("PPP: Error: Bad 32 Bit Checksum on Asynchronous port \n");#endif /* PPP_DEBUG */ netMblkClChainFree(outPacket); RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); return (ERROR); } /* delete 32-bit FCS from end of frame */ m_adj(outPacket, -4); } else if (stackData->receiveFcsSize != PPP_NULL_FCS) /* NULL FCS */ { netMblkClChainFree(outPacket); RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); return ERROR; } if (decompress_ppp_header(state,outPacket) == ERROR) { netMblkClChainFree(outPacket); return ERROR; } /* strip HDLC header */ outPacket->mBlkHdr.mData +=2; outPacket->mBlkHdr.mLen -=2; outPacket->mBlkPktHdr.len -= 2; /* Check if total packet length - protocol field exceeds local MRU */ if (outPacket->mBlkPktHdr.len - sizeof (PPP_HEADER) > max (stackData->localMru,DEFAULT_MAXIMUM_MRU)) { (counterInterface->pppLinkStatusPacketTooLongsIncrement)( stackData->pppLinkStatusInterface.state);#ifdef PPP_DEBUG printf ("PPP: Error: Packet Too Long: Information Field = %d \n", outPacket->mBlkPktHdr.len - 2);#endif /* PPP_DEBUG */ RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); netMblkClChainFree(outPacket); return (ERROR); } *packet = outPacket; return (OK); }/********************************************************************************* convertAsynchronousDataToNormalData - convert asynchronous data to normal** RETURNS: OK or ERROR*/LOCAL STATUS convertAsynchronousDataToNormalData ( PFW_PLUGIN_OBJ_STATE * state, M_BLK_ID inFrame, M_BLK_ID outPacket ) { BYTE actualByte = 0; USHORT byteCounter; USHORT numberOfBytes = 0; char * pData = NULL; int byteCount = 0; int totalBytesDecoded = 0; BOOL escape; M_BLK_ID outPacketChainHead = outPacket; ASYNC_FRAMING_STACK_DATA *stackData = state->stackData; escape = FALSE; do { numberOfBytes = inFrame->mBlkHdr.mLen; pData = inFrame->mBlkHdr.mData; for (byteCounter = 0; byteCounter < numberOfBytes; ++byteCounter) { actualByte = *((BYTE *) ((ULONG) pData + byteCounter)); switch (actualByte) { case HDLC_FLAG_SEQUENCE: /* * Flags should only ever occur at the end of the frame * (otherwise something is wrong with the SIO adapter). * * According to RFC1662, a control escape'd FLAG indicates * an aborted frame, which should be silently discarded. * * In any case, FLAGs are never copied to the output mbuf. */ if (escape) { printf ("PPP: flag after control escape.\n"); return (ERROR); /* escaped FLAG: discard frame */ } else if ((byteCounter == numberOfBytes - 1) && (inFrame->mBlkHdr.mNext == NULL)) { ; /* elide end-of-frame FLAG */ } else { printf ("PPP: Error: Flag in mid-frame.\n"); return (ERROR); } break; case ASYNC_CONTROL_ESCAPE_SEQUENCE: /* * Set the 'escape' state so the next byte is decoded. * Do not copy the control escape to the output mbuf. * * It is an error for the control escape character to * appear in an escaped state. */ if (escape) { printf ("PPP: Error: Consecutive control escape " "sequences found in packet on Async port\n"); return (ERROR); } escape = TRUE; break; default: /* * Any other character: decode if it's escaped, and copy * to the output mbuf. */ if ((actualByte < 0x20) && (stackData->peerToLocalACCMap & (1 << actualByte))) { continue; /* ugh! (continue 'for' loop) */ } if (escape) { actualByte ^= ASYNC_SIXTH_BIT_COMPLEMENT; escape = FALSE; } outPacket->mBlkHdr.mData [byteCount++] = actualByte; outPacket->mBlkHdr.mLen++; totalBytesDecoded++; /* * If at the end of the current output mbuf, add another * one to the chain. */ if ((outPacket->mBlkHdr.mData + byteCount) == (outPacket->pClBlk->clNode.pClBuf + outPacket->pClBlk->clSize)) { M_BLK_ID pNextMblk; if ((pNextMblk = netTupleGet (stackData->netPoolId, outPacket->mBlkHdr.mLen, M_DONTWAIT, MT_DATA, TRUE)) == NULL) { printf ("AsyncFraming:Failed to get another mBlk " "for decoded frame:Stack 0x%x\n", (UINT32) state->stackObj); return ERROR; } /* netTupleGet will not clear mLen */ pNextMblk->mBlkHdr.mLen = 0; pNextMblk->mBlkHdr.mFlags &= ~M_PKTHDR; pNextMblk->mBlkPktHdr.len = 0; outPacket->mBlkHdr.mNext = pNextMblk; outPacket = outPacket->mBlkHdr.mNext; byteCount = 0; } break; } } } while ((inFrame = inFrame->mBlkHdr.mNext) != NULL); /* * Check that the last byte seen was a FLAG - if not, the frame is * damaged (i.e. the SIO adapter is broken). */ if (actualByte != HDLC_FLAG_SEQUENCE) { printf ("PPP: Error: frame ends with non-FLAG.\n"); return (ERROR); } outPacketChainHead->mBlkHdr.mFlags |= M_PKTHDR; outPacketChainHead->mBlkPktHdr.len = totalBytesDecoded; return (OK); }/********************************************************************************* decompress_ppp_header - decompress the PPP header** RETURNS: OK or ERROR*/LOCAL STATUS decompress_ppp_header ( PFW_PLUGIN_OBJ_STATE *state, M_BLK_ID packet ) { UCHAR protocol_type_in_bytes[sizeof (USHORT_ENUM (PPP_PROTOCOL_TYPE))]; BOOL address_and_control_fields_are_compressed; BOOL protocol_field_is_compressed; _PPP_HEADER ppp_header; ASYNC_FRAMING_STACK_DATA *stackData = state->stackData; _PPP_PACKET *sptr_rxed_packet = (_PPP_PACKET *)packet->mBlkHdr.mData; int lengthAdj; USHORT_ENUM (PPP_PROTOCOL_TYPE) protocol_type; PPP_LINK_STATUS_COUNTER_INCREMENT_INTERFACE * counterInterface = (PPP_LINK_STATUS_COUNTER_INCREMENT_INTERFACE*) stackData->pppLinkCounterInterface.interfaceObj; if ((sptr_rxed_packet->header.hdlc_address == HDLC_ADDRESS) && (sptr_rxed_packet->header.hdlc_control == UNNUMBERED_INFORMATION) && (sptr_rxed_packet->header.protocol_type == LCP_PROTOCOL)) { return (OK); } address_and_control_fields_are_compressed = FALSE; protocol_field_is_compressed = FALSE; ppp_header.hdlc_address = HDLC_ADDRESS; ppp_header.hdlc_control = UNNUMBERED_INFORMATION; if (stackData->peerToLocalACCompression == TRUE) { if (sptr_rxed_packet->header.hdlc_address != HDLC_ADDRESS) { address_and_control_fields_are_compressed = TRUE; memcpy (&protocol_type_in_bytes[0],(char *)sptr_rxed_packet, sizeof (USHORT_ENUM (PPP_PROTOCOL_TYPE))); } else { USHORT protocol_type = sptr_rxed_packet->header.protocol_type; memcpy (&protocol_type_in_bytes[0], &protocol_type, sizeof (USHORT_ENUM (PPP_PROTOCOL_TYPE))); } } else { /* Check address and control fields */ if (sptr_rxed_packet->header.hdlc_address != HDLC_ADDRESS) { (counterInterface->pppLinkStatusBadAddressesIncrement)( stackData->pppLinkStatusInterface.state);#ifdef PPP_DEBUG printf ("PPP: Error: Bad Address Field on Asynchronous port \n");#endif /* PPP_DEBUG */ RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); return (ERROR); /* Discard frame */ } if (sptr_rxed_packet->header.hdlc_control != UNNUMBERED_INFORMATION) { (counterInterface->pppLinkStatusBadControlsIncrement)( stackData->pppLinkStatusInterface.state);#ifdef PPP_DEBUG printf ("PPP: Error: Bad Control Field on Asynchronous port \n");#endif /* PPP_DEBUG */ RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); return (ERROR); /* Discard frame */ } protocol_type = sptr_rxed_packet->header.protocol_type; memcpy (&protocol_type_in_bytes[0], &protocol_type, sizeof (USHORT_ENUM (PPP_PROTOCOL_TYPE))); } if ((protocol_type_in_bytes[0] & 0x1) == 0) { memcpy (&protocol_type, (void *)&protocol_type_in_bytes[0], sizeof (USHORT_ENUM (PPP_PROTOCOL_TYPE))); ppp_header.protocol_type = protocol_type; } else { if (stackData->peerToLocalProtocolCompression != TRUE) { RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInErrors, 1); RFC2233_COUNTER_UPDATE(stackData->pfwRFC2233CountTest, stackData->pfwRFC2233CountPair, M2_ctrId_ifInUnknownProtos, 1); return (ERROR); /* Discard frame */ } protocol_field_is_compressed = TRUE; *((char *) &ppp_header.protocol_type) = 0x00; *(((char *) &ppp_header.protocol_type) + 1) = protocol_type_in_bytes[0]; } if (address_and_control_fields_are_compressed == TRUE) { sptr_rxed_packet = (_PPP_PACKET *) (((ULONG) sptr_rxed_packet) - (sizeof (ppp_header.hdlc_address) + sizeof (ppp_header.hdlc_control))); lengthAdj = (USHORT) (sizeof (ppp_header.hdlc_address) + sizeof (ppp_header.hdlc_control)); packet->mBlkHdr.mLen += lengthAdj; packet->mBlkPktHdr.len += lengthAdj; } if (protocol_field_is_compressed == TRUE) { sptr_rxed_packet = (_PPP_PACKET *) (((ULONG) sptr_rxed_packet) - sizeof (char)); packet->mBlkHdr.mLen += (USHORT) sizeof (char); packet->mBlkPktHdr.len += (USHORT) sizeof (char); } memcpy ((char *)sptr_rxed_packet,&ppp_header,sizeof (_PPP_HEADER)); packet->mBlkHdr.mData = (char *)sptr_rxed_packet; return (OK); }/******************************************************************************** AsyncFrameEventHandler -** This routine collects ppp attributes**/LOCAL STATUS AsyncFrameEventHandler ( PFW_PLUGIN_OBJ_STATE * state, void *eventData ) { PPP_ATTRIBUTES *p_ppp_attr_data = (PPP_ATTRIBUTES *)eventData; p_ppp_attr_data->framingType = PPP_ASYNC_FRAMING; return OK; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -