summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2018-06-08 09:45:36 +0200
committerSander Vrijders <sander.vrijders@ugent.be>2018-06-08 09:59:00 +0200
commit6379a9afb131ed95ca7073299e4e365e2a4abf3b (patch)
treebeab34ccd34716e5be87140dcc35c971646745de
parent91180700a44e857311ecc9eadbfc27c7f9b802cb (diff)
downloadouroboros-6379a9afb131ed95ca7073299e4e365e2a4abf3b.tar.gz
ouroboros-6379a9afb131ed95ca7073299e4e365e2a4abf3b.zip
lib: Fix rollover and return value in FRCT
The __frct_rcv should return -EAGAIN if there is no packet for the application, but 0 was always returned. Also fixes sequence number rollover. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
-rw-r--r--src/lib/frct.c10
1 files changed, 6 insertions, 4 deletions
diff --git a/src/lib/frct.c b/src/lib/frct.c
index 395fa2d8..bcb031c3 100644
--- a/src/lib/frct.c
+++ b/src/lib/frct.c
@@ -335,6 +335,7 @@ static int __frcti_rcv(struct frcti * frcti,
struct timespec now;
struct frct_cr * rcv_cr;
uint32_t seqno;
+ int ret = 0;
assert(frcti);
@@ -372,16 +373,17 @@ static int __frcti_rcv(struct frcti * frcti,
if (pci->flags & FRCT_CFG)
rcv_cr->cflags = pci->cflags;
} else { /* Out of order. */
- if (seqno < rcv_cr->lwe) /* Duplicate. */
+ if ((int32_t)(seqno - rcv_cr->lwe) < 0) /* Duplicate. */
goto drop_packet;
if (rcv_cr->cflags & FRCTFRTX) {
size_t pos = seqno & (RQ_SIZE - 1);
- if (seqno > rcv_cr->lwe + RQ_SIZE || /* Out of range. */
- frcti->rq[pos] != -1) /* Duplicate in rq. */
+ if ((seqno - RQ_SIZE - rcv_cr->lwe) > 0 /* Out of rq. */
+ || frcti->rq[pos] != -1) /* Duplicate in rq. */
goto drop_packet;
/* Queue. */
frcti->rq[pos] = idx;
+ ret = -EAGAIN;
} else {
rcv_cr->lwe = seqno;
}
@@ -394,7 +396,7 @@ static int __frcti_rcv(struct frcti * frcti,
pthread_rwlock_unlock(&frcti->lock);
- return 0;
+ return ret;
drop_packet:
shm_rdrbuff_remove(ai.rdrb, idx);