X-Git-Url: http://git.sameswireless.fr/l2tpns.git/blobdiff_plain/a54a4886e9dc530bb16e5eb0f6a8cfcb03824960..2d1fefdb103465c572f87a5bcea3d5281ae124b9:/ppp.c diff --git a/ppp.c b/ppp.c index 4114bb4..afbffd8 100644 --- a/ppp.c +++ b/ppp.c @@ -1999,16 +1999,57 @@ void processmpin(sessionidt s, tunnelidt t, uint8_t *p, uint16_t l) break; } } - //discard fragments received before the recently assembled frame - begin_index = this_fragmentation->start_index; - this_fragmentation->start_index = (end_index + 1) & MAXFRAGNUM_MASK; - this_fragmentation->start_seq = (this_fragmentation->fragment[end_index].seq + 1) & (this_bundle->max_seq-1); - //clear length and flags of the discarded fragments - while (begin_index != this_fragmentation->start_index) - { - this_fragmentation->fragment[begin_index].flags = 0; - this_fragmentation->fragment[begin_index].length = 0; - begin_index = (begin_index + 1) & MAXFRAGNUM_MASK; + +discard_lost_frames: + //discard fragments numbererd below M and part of an unassembled frame, + //but not the one from the frame beginning just before M + + // if we have something to discard + if (M_index != this_fragmentation->start_index) + { + // look for end of previous frame + // start at M-1, going backward + uint16_t index = M_index; + uint8_t end_or_hole_found = 0; + + while (index != this_fragmentation->start_index) + { + fragmentt *this_frag; + + if (!end_or_hole_found) + { + fragmentt *front_frag = &this_fragmentation->frag[index]; + + // before a MP_BEGIN, there must be a MP_END + if (front_frag->length && (front_frag->flags & MP_BEGIN)) + { + end_or_hole_found = 1; + end_index = index; + } + } + + index = (index + (MAXFRAGNUM-1)) & MAXFRAGNUM_MASK; + this_frag = &this_fragmentation->frag[index]; + + if (!end_or_hole_found) + { + // we are a hole or a MP_END + if (!this_frag->length || (this_frag->flags & MP_END)) + { + end_or_hole_found = 1; + end_index = index; + } + } + + if (end_or_hole_found) + { + this_frag->flags = 0; + this_frag->length = 0; + } + } + + this_fragmentation->start_index = (end_index + 1) & MAXFRAGNUM_MASK; + this_fragmentation->start_seq = (this_fragmentation->fragment[end_index].seq + 1) & (this_bundle->max_seq-1); } LOG(4, s, t, "MPPP after assembling: M index is =%d, start index is = %d, start seq=%d\n",M_index, this_fragmentation->start_index, this_fragmentation->start_seq);