From 4230103ff633904c69cc18d861bf42781f57bb64 Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Sat, 17 Mar 2018 14:55:46 +0100 Subject: lib: Allow disabling partial read This allows disabling partial reads. It adds a flag FLOWFRNOPART that disables partial reads. Partial read is different from partial delivery (FRCTFPARTIAL), which allows delivery of fragments of an incomplete packet and thus potentially corrupted data. FLOWFRNOPART will never deliver corrupted data (unless FRCTFPARTIAL is also set). If FLOWFRNOPART is set and the buffer provided to flow_read is too small for the SDU, that SDU will be discarded and -EMSGSIZE is returned; Signed-off-by: Dimitri Staessens Signed-off-by: Sander Vrijders --- src/lib/dev.c | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/lib') diff --git a/src/lib/dev.c b/src/lib/dev.c index 115cd565..d0766783 100644 --- a/src/lib/dev.c +++ b/src/lib/dev.c @@ -897,6 +897,7 @@ ssize_t flow_read(int fd, struct timespec * abstime = NULL; struct flow * flow; bool noblock; + bool partrd; if (fd < 0 || fd > PROG_MAX_FLOWS) return -EBADF; @@ -919,6 +920,7 @@ ssize_t flow_read(int fd, rb = flow->rx_rb; noblock = flow->oflags & FLOWFRNOBLOCK; + partrd = !(flow->oflags & FLOWFRNOPART); if (ai.flows[fd].rcv_timesout) { ts_add(&abs, &flow->rcv_timeo, &abs); @@ -948,14 +950,20 @@ ssize_t flow_read(int fd, if (n <= (ssize_t) count) { memcpy(buf, sdu, n); shm_rdrbuff_remove(ai.rdrb, idx); - flow->part_idx = (n == (ssize_t) count) ? DONE_PART : NO_PART; + flow->part_idx = (partrd && n == (ssize_t) count) ? + DONE_PART : NO_PART; return n; } else { - memcpy(buf, sdu, count); - sdb = shm_rdrbuff_get(ai.rdrb, idx); - shm_du_buff_head_release(sdb, n); - flow->part_idx = idx; - return count; + if (partrd) { + memcpy(buf, sdu, count); + sdb = shm_rdrbuff_get(ai.rdrb, idx); + shm_du_buff_head_release(sdb, n); + flow->part_idx = idx; + return count; + } else { + shm_rdrbuff_remove(ai.rdrb, idx); + return -EMSGSIZE; + } } } -- cgit v1.2.3