summaryrefslogtreecommitdiff
path: root/src/lib
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib')
-rw-r--r--src/lib/CMakeLists.txt2
-rw-r--r--src/lib/config.h.in1
-rw-r--r--src/lib/dev.c63
-rw-r--r--src/lib/frct.c36
4 files changed, 58 insertions, 44 deletions
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 84a9fd72..f66e7ab9 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -176,6 +176,8 @@ set(SHM_RDRB_MULTI_BLOCK true CACHE BOOL
"Packet buffer multiblock packet support")
set(SHM_RBUFF_LOCKLESS 0 CACHE BOOL
"Enable shared memory lockless rbuff support")
+set(QOS_DISABLE_CRC 0 CACHE BOOL
+ "Ignores ber setting on all QoS cubes")
set(SOURCE_FILES_DEV
# Add source files here
diff --git a/src/lib/config.h.in b/src/lib/config.h.in
index 69e7f4b0..e8cfeba3 100644
--- a/src/lib/config.h.in
+++ b/src/lib/config.h.in
@@ -28,6 +28,7 @@
#cmakedefine SHM_RBUFF_LOCKLESS
#cmakedefine SHM_RDRB_MULTI_BLOCK
+#cmakedefine QOS_DISABLE_CRC
#define SHM_RBUFF_PREFIX "@SHM_RBUFF_PREFIX@"
#define SHM_LOCKFILE_NAME "@SHM_LOCKFILE_NAME@"
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 117ce49d..a7b342ba 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -61,6 +61,8 @@
#define NO_PART -1
#define DONE_PART -2
+#define CRCLEN (sizeof(uint32_t))
+
struct flow_set {
size_t idx;
};
@@ -566,6 +568,10 @@ int flow_alloc(const char * dst,
irm_msg_t * recv_msg;
int fd;
+#ifdef QOS_DISABLE_CRC
+ if (qs != NULL)
+ qs->ber = 1;
+#endif
msg.code = IRM_MSG_CODE__IRM_FLOW_ALLOC;
msg.dst = (char *) dst;
msg.has_pid = true;
@@ -813,16 +819,40 @@ int fccntl(int fd,
return -EPERM;
}
+static int chk_crc(struct shm_du_buff * sdb)
+{
+ uint32_t crc;
+ uint8_t * head = shm_du_buff_head(sdb);
+ uint8_t * tail = shm_du_buff_tail_release(sdb, CRCLEN);
+
+ mem_hash(HASH_CRC32, &crc, head, tail - head);
+
+ return !(crc == *((uint32_t *) tail));
+}
+
+static int add_crc(struct shm_du_buff * sdb)
+{
+ uint8_t * head = shm_du_buff_head(sdb);
+ uint8_t * tail = shm_du_buff_tail_alloc(sdb, CRCLEN);
+ if (tail == NULL)
+ return -1;
+
+ mem_hash(HASH_CRC32, tail, head, tail - head);
+
+ return 0;
+}
+
ssize_t flow_write(int fd,
const void * buf,
size_t count)
{
- struct flow * flow;
- ssize_t idx;
- int ret;
- int flags;
- struct timespec abs;
- struct timespec * abstime = NULL;
+ struct flow * flow;
+ ssize_t idx;
+ int ret;
+ int flags;
+ struct timespec abs;
+ struct timespec * abstime = NULL;
+ struct shm_du_buff * sdb;
if (buf == NULL)
return 0;
@@ -869,14 +899,21 @@ ssize_t flow_write(int fd,
if (idx < 0)
return idx;
- if (frcti_snd(flow->frcti, shm_rdrbuff_get(ai.rdrb, idx)) < 0) {
+ sdb = shm_rdrbuff_get(ai.rdrb, idx);
+
+ if (frcti_snd(flow->frcti, sdb) < 0) {
+ shm_rdrbuff_remove(ai.rdrb, idx);
+ return -ENOMEM;
+ }
+
+ if (flow->spec.ber == 0 && add_crc(sdb) != 0) {
shm_rdrbuff_remove(ai.rdrb, idx);
return -ENOMEM;
}
pthread_rwlock_rdlock(&ai.lock);
- ret = shm_rbuff_write(ai.flows[fd].tx_rb, idx);
+ ret = shm_rbuff_write(flow->tx_rb, idx);
if (ret < 0)
shm_rdrbuff_remove(ai.rdrb, idx);
else
@@ -944,6 +981,8 @@ ssize_t flow_read(int fd,
if (idx < 0)
return idx;
sdb = shm_rdrbuff_get(ai.rdrb, idx);
+ if (flow->spec.ber == 0 && chk_crc(sdb) != 0)
+ continue;
} while (frcti_rcv(flow->frcti, sdb) != 0);
}
}
@@ -1341,6 +1380,8 @@ int ipcp_flow_read(int fd,
if (idx < 0)
return idx;
*sdb = shm_rdrbuff_get(ai.rdrb, idx);
+ if (flow->spec.ber == 0 && chk_crc(*sdb) != 0)
+ continue;
} while (frcti_rcv(flow->frcti, *sdb) != 0);
return 0;
@@ -1376,6 +1417,12 @@ int ipcp_flow_write(int fd,
return -ENOMEM;
}
+ if (flow->spec.ber == 0 && add_crc(sdb) != 0) {
+ pthread_rwlock_unlock(&ai.lock);
+ shm_rdrbuff_remove(ai.rdrb, idx);
+ return -ENOMEM;
+ }
+
ret = shm_rbuff_write(flow->tx_rb, idx);
if (ret == 0)
shm_flow_set_notify(flow->set, flow->flow_id, FLOW_PKT);
diff --git a/src/lib/frct.c b/src/lib/frct.c
index 2e5c385d..424367c3 100644
--- a/src/lib/frct.c
+++ b/src/lib/frct.c
@@ -31,7 +31,6 @@
#define TW_RESOLUTION 1 /* ms */
#define FRCT_PCILEN (sizeof(struct frct_pci))
-#define FRCT_CRCLEN (sizeof(uint32_t))
struct frct_cr {
uint32_t lwe;
@@ -204,22 +203,6 @@ static ssize_t __frcti_queued_pdu(struct frcti * frcti)
return idx;
}
-static int frct_chk_crc(uint8_t * head,
- uint8_t * tail)
-{
- uint32_t crc;
-
- mem_hash(HASH_CRC32, &crc, head, tail - head);
-
- return crc == *((uint32_t *) tail);
-}
-
-static void frct_add_crc(uint8_t * head,
- uint8_t * tail)
-{
- mem_hash(HASH_CRC32, tail, head, tail - head);
-}
-
static struct frct_pci * frcti_alloc_head(struct shm_du_buff * sdb)
{
struct frct_pci * pci = NULL;
@@ -252,18 +235,6 @@ static int __frcti_snd(struct frcti * frcti,
pci->flags |= FRCT_DATA;
- if (snd_cr->cflags & FRCTFERRCHCK) {
- uint8_t * tail = shm_du_buff_tail_alloc(sdb, FRCT_CRCLEN);
- if (tail == NULL) {
- pthread_rwlock_unlock(&frcti->lock);
- return -1;
- }
-
- frct_add_crc((uint8_t *) pci, tail);
-
- pci->flags |= FRCT_CRC;
- }
-
/* Set DRF if there are no unacknowledged packets. */
if (frcti->seqno == snd_cr->lwe)
pci->flags |= FRCT_DRF;
@@ -317,13 +288,6 @@ static int __frcti_rcv(struct frcti * frcti,
idx = shm_du_buff_get_idx(sdb);
- /* PDU may be corrupted. */
- if (pci->flags & FRCT_CRC) {
- uint8_t * tail = shm_du_buff_tail_release(sdb, FRCT_CRCLEN);
- if (frct_chk_crc((uint8_t *) pci, tail))
- goto drop_packet;
- }
-
seqno = ntoh32(pci->seqno);
/* Check if receiver inactivity is true. */