📄 mpreassemble.c
字号:
* mp_reassemble_fragments_length - Find the length of reassembled packet.* * This function computes the packet length of the reassembled mp fragments.** RETURNS: packet_length*/LOCAL int mp_reassemble_fragments_length ( PFW_PLUGIN_OBJ_STATE *pMpFramingLayerState, ULONG first_fragment_index, ULONG last_fragment_index ) { int packet_length = 0; MP_FRAGMENT_CLASS *first_mp_fragment = NULL; MP_FRAGMENT_CLASS *last_mp_fragment = NULL; MP_FRAGMENT_CLASS *temp_mp_fragment = NULL; MP_FRAMING_LAYER_STACK_DATA *pStackData = (MP_FRAMING_LAYER_STACK_DATA *) pMpFramingLayerState->stackData; /* intialize packet length to 0 */ packet_length = 0; /* Buffer - F.......L */ if (first_fragment_index <= last_fragment_index) { /* get the first node in the list */ first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* get the first node in the list */ last_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* * traverse upto the first_fragment_index in the list, * to get its pointer */ while (first_fragment_index != first_mp_fragment->indexInList) first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (first_mp_fragment); /* * traverse upto the last_fragment_index in the list, * to get its pointer */ while (last_fragment_index != last_mp_fragment->indexInList) last_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (last_mp_fragment); /* * add all the lengths from first fragment * to last fragment, i.e., F.....L */ while (first_mp_fragment != last_mp_fragment) { packet_length = packet_length + first_mp_fragment->length; first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (first_mp_fragment); } /* * last fragment's length was not added in the loop, * so add it explicitly here */ packet_length = packet_length + last_mp_fragment->length; } else /* ROLL OVER - 0.....L - F.....Max */ { /* get the first node in the list */ first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* get the first node in the list */ last_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* * traverse upto the first_fragment_index in the list, * to get its pointer */ while (first_fragment_index != first_mp_fragment->indexInList) first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (first_mp_fragment); /* * traverse upto the last_fragment_index in the list, * to get its pointer */ while (last_fragment_index != last_mp_fragment->indexInList) last_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (last_mp_fragment); temp_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle. receiving_end.buffer.ppp_fragments)); /* 0.........L */ while (temp_mp_fragment != last_mp_fragment) { packet_length = packet_length + temp_mp_fragment->length; temp_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (temp_mp_fragment); } /* * last fragments length was not added in the loop, * so add it explicitly here */ packet_length = packet_length + last_mp_fragment->length; /* F.........Max */ while (first_mp_fragment->next != NULL) { packet_length = packet_length + first_mp_fragment->length; first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT (first_mp_fragment); } /* * last fragments length was not added in the loop, * so add it explicitly here */ packet_length = packet_length + first_mp_fragment->length; } return packet_length; }/********************************************************************************* mp_assemble_received_packet_from_fragments - Reassemble the received packet* from the bufered fragments.* * This function assembles the received packet from the fragments.** RETURNS: PASS or FAIL.*/LOCAL TEST mp_assemble_received_packet_from_fragments ( PFW_PLUGIN_OBJ_STATE *pMpFramingLayerState, ULONG first_fragment_index, ULONG last_fragment_index, M_BLK_ID *packet_to_be_passed_up ) { M_BLK_ID firstMBlkId = NULL; M_BLK_ID tempMBlkId = NULL; M_BLK_ID endMBlkId = NULL; MP_FRAGMENT_CLASS *first_mp_fragment = NULL; MP_FRAGMENT_CLASS *mp_fragment = NULL; MP_FRAGMENT_CLASS *last_mp_fragment = NULL; MP_FRAMING_LAYER_STACK_DATA *pStackData = (MP_FRAMING_LAYER_STACK_DATA *) pMpFramingLayerState->stackData; if (packet_to_be_passed_up == NULL) return FAIL; /* ONLY fragment */ if (first_fragment_index == last_fragment_index) { mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); if (mp_fragment->mblk_fragment != NULL) { /* traverse upto the first_fragment_index to get its pointer */ while (mp_fragment->indexInList != first_fragment_index) mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT ((SL_NODE *) mp_fragment); firstMBlkId = mp_fragment->mblk_fragment; if (pStackData->bundle.receiving_end. use_short_sequence_number == TRUE) { firstMBlkId->mBlkHdr.mData += sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); firstMBlkId->mBlkHdr.mLen -= sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); if ((firstMBlkId->mBlkHdr.mFlags & M_PKTHDR) && (firstMBlkId->mBlkHdr.mNext != NULL)) { firstMBlkId->mBlkPktHdr.len -= sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); } discard_fragment_range (pMpFramingLayerState, first_fragment_index, last_fragment_index, FALSE); } else { firstMBlkId->mBlkHdr.mData += sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); firstMBlkId->mBlkHdr.mLen -= sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); if ((firstMBlkId->mBlkHdr.mFlags & M_PKTHDR) && (firstMBlkId->mBlkHdr.mNext != NULL)) { firstMBlkId->mBlkPktHdr.len -= sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); } discard_fragment_range (pMpFramingLayerState, first_fragment_index, last_fragment_index, FALSE); } *packet_to_be_passed_up = firstMBlkId; return PASS; } else { discard_fragment_range (pMpFramingLayerState, first_fragment_index, last_fragment_index, TRUE); } } /* Buffer - F......L */ if (first_fragment_index < last_fragment_index) /* changed <= to < */ { /* get the first node in the list */ mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* traverse upto the first_fragment_index to get its pointer */ while (mp_fragment->indexInList != first_fragment_index) { mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT ((SL_NODE *) mp_fragment); } /* this is the first M_BLK_ID, chain it from here */ firstMBlkId = mp_fragment->mblk_fragment; /* skip the MP header - check SSNHF or LSNHF */ if (pStackData->bundle.receiving_end. use_short_sequence_number == TRUE) { firstMBlkId->mBlkHdr.mData += sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); firstMBlkId->mBlkHdr.mLen -= sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); if ((firstMBlkId->mBlkHdr.mFlags & M_PKTHDR) && (firstMBlkId->mBlkHdr.mNext != NULL)) { firstMBlkId->mBlkPktHdr.len -= sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); } } else { firstMBlkId->mBlkHdr.mData += sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); firstMBlkId->mBlkHdr.mLen -= sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); if ((firstMBlkId->mBlkHdr.mFlags & M_PKTHDR) && (firstMBlkId->mBlkHdr.mNext != NULL)) { firstMBlkId->mBlkPktHdr.len -= sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); } } /* get the first node in the list */ first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* get the first node in the list */ last_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* * traverse upto the first_fragment_index + 1, to get its pointer +1, * coz, first fragment is already with the chain */ while ((first_mp_fragment->indexInList != first_fragment_index + 1) && (first_mp_fragment != NULL)) first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT ((SL_NODE *) first_mp_fragment); /* traverse upto the last_fragment_index, to get its pointer */ while (last_mp_fragment->indexInList != last_fragment_index) { last_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT ((SL_NODE *)last_mp_fragment); } /* Buffer - F......L */ endMBlkId = firstMBlkId; while (first_mp_fragment != last_mp_fragment) { /* check if it is fragment is NULL */ if (first_mp_fragment->mblk_fragment != NULL) { tempMBlkId = first_mp_fragment->mblk_fragment; /* skip the MP Header - check SSNHF or LSNHF */ if (pStackData->bundle.receiving_end. use_short_sequence_number == TRUE) { tempMBlkId->mBlkHdr.mData += sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mLen -= sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mFlags &= (~M_PKTHDR); } else { tempMBlkId->mBlkHdr.mData += sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mLen -= sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mFlags &= (~M_PKTHDR); } /* check if the MBLK contains more than one cluster in it */ while (endMBlkId->mBlkHdr.mNext != NULL) { endMBlkId = endMBlkId->mBlkHdr.mNext; } /* attach the new fragment */ endMBlkId->mBlkHdr.mNext = tempMBlkId; endMBlkId = tempMBlkId; } else { /* * discard if it is NULL - from first to last fragments * pass TRUE here, so that the MBLK-CLBLK-Cluster chain is also * freed */ discard_fragment_range (pMpFramingLayerState, first_fragment_index, last_fragment_index, TRUE); return (FAIL); } /* move to the next fragment in the list */ first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT ((SL_NODE *)first_mp_fragment); } /* End of while */ /* we have not added the last fragment, so explicitly do it here */ tempMBlkId = last_mp_fragment->mblk_fragment; if (pStackData->bundle.receiving_end. use_short_sequence_number == TRUE) { tempMBlkId->mBlkHdr.mData += sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mLen -= sizeof (SHORT_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mFlags &= (~M_PKTHDR); } else { tempMBlkId->mBlkHdr.mData += sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mLen -= sizeof (LONG_SEQUENCE_NUMBER_MP_HEADER); tempMBlkId->mBlkHdr.mFlags &= (~M_PKTHDR); } while (endMBlkId->mBlkHdr.mNext != NULL) { endMBlkId = endMBlkId->mBlkHdr.mNext; } endMBlkId->mBlkHdr.mNext = tempMBlkId; endMBlkId = tempMBlkId; /* * discard the fragments, pass FALSE so that * MBLK-CLBLK-Cluster chain is not freed */ discard_fragment_range (pMpFramingLayerState, first_fragment_index, last_fragment_index, FALSE); } else /* ROLL OVER - 0......L and F.....Max */ { /* Buffer F......... Max */ /* get first node in the list */ first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_FIRST (&(pStackData->bundle.receiving_end.buffer.ppp_fragments)); /* traverse upto first_mp_fragment in the list, to get its pointer */ while (first_mp_fragment->indexInList != first_fragment_index) { first_mp_fragment = (MP_FRAGMENT_CLASS *) SLL_NEXT ((SL_NODE *)first_mp_fragment); } firstMBlkId = first_mp_fragment->mblk_fragment;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -