summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/ouroboros/ipcp-dev.h7
-rw-r--r--include/ouroboros/shm_du_buff.h53
-rw-r--r--include/ouroboros/shm_rdrbuff.h19
-rw-r--r--src/ipcpd/normal/dt.c12
-rw-r--r--src/ipcpd/normal/fa.c2
-rw-r--r--src/ipcpd/normal/frct.c10
-rw-r--r--src/ipcpd/normal/shm_pci.h2
-rw-r--r--src/ipcpd/shim-eth-llc/main.c2
-rw-r--r--src/ipcpd/shim-udp/main.c4
-rw-r--r--src/lib/dev.c28
-rw-r--r--src/lib/shm_rdrbuff.c25
11 files changed, 121 insertions, 43 deletions
diff --git a/include/ouroboros/ipcp-dev.h b/include/ouroboros/ipcp-dev.h
index 571689ca..cdf9f5c1 100644
--- a/include/ouroboros/ipcp-dev.h
+++ b/include/ouroboros/ipcp-dev.h
@@ -45,9 +45,12 @@ int ipcp_flow_write(int fd,
void ipcp_flow_fini(int fd);
-void ipcp_flow_del(struct shm_du_buff * sdb);
-
int ipcp_flow_get_qoscube(int fd,
qoscube_t * cube);
+int ipcp_sdb_reserve(struct shm_du_buff ** sdb,
+ size_t len);
+
+void ipcp_sdb_release(struct shm_du_buff * sdb);
+
#endif /* OUROBOROS_IPCP_DEV_H */
diff --git a/include/ouroboros/shm_du_buff.h b/include/ouroboros/shm_du_buff.h
new file mode 100644
index 00000000..9f796be1
--- /dev/null
+++ b/include/ouroboros/shm_du_buff.h
@@ -0,0 +1,53 @@
+/*
+ * Ouroboros - Copyright (C) 2016 - 2017
+ *
+ * Data Buffer element in Random Deletion Ring Buffer
+ *
+ * Dimitri Staessens <dimitri.staessens@ugent.be>
+ * Sander Vrijders <sander.vrijders@ugent.be>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public License
+ * version 2.1 as published by the Free Software Foundation.
+ *
+ * This library is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301 USA
+ */
+
+#ifndef OUROBOROS_SHM_DU_BUFF_H
+#define OUROBOROS_SHM_DU_BUFF_H
+
+#include <sys/types.h>
+#include <stdint.h>
+
+struct shm_du_buff;
+
+size_t shm_du_buff_get_idx(struct shm_du_buff * sdb);
+
+uint8_t * shm_du_buff_head(struct shm_du_buff * sdb);
+
+uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb);
+
+uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb,
+ size_t size);
+
+uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb,
+ size_t size);
+
+void shm_du_buff_head_release(struct shm_du_buff * sdb,
+ size_t size);
+
+void shm_du_buff_tail_release(struct shm_du_buff * sdb,
+ size_t size);
+
+void shm_du_buff_truncate(struct shm_du_buff * sdb,
+ size_t len);
+
+#endif /* OUROBOROS_SHM_DU_BUFF_H */
diff --git a/include/ouroboros/shm_rdrbuff.h b/include/ouroboros/shm_rdrbuff.h
index 92173388..13b99eef 100644
--- a/include/ouroboros/shm_rdrbuff.h
+++ b/include/ouroboros/shm_rdrbuff.h
@@ -24,17 +24,15 @@
#ifndef OUROBOROS_SHM_RDRBUFF_H
#define OUROBOROS_SHM_RDRBUFF_H
+#include <ouroboros/shm_du_buff.h>
#include <ouroboros/shared.h>
#include <stdint.h>
#include <pthread.h>
#include <sys/types.h>
-struct shm_du_buff;
struct shm_rdrbuff;
-size_t shm_du_buff_get_idx(struct shm_du_buff * sdb);
-
struct shm_rdrbuff * shm_rdrbuff_create(void);
struct shm_rdrbuff * shm_rdrbuff_open(void);
@@ -68,19 +66,4 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb,
int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb,
size_t idx);
-uint8_t * shm_du_buff_head(struct shm_du_buff * sdb);
-
-uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb);
-
-uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb,
- size_t size);
-
-uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb,
- size_t size);
-
-void shm_du_buff_head_release(struct shm_du_buff * sdb,
- size_t size);
-
-void shm_du_buff_tail_release(struct shm_du_buff * sdb,
- size_t size);
#endif /* OUROBOROS_SHM_RDRBUFF_H */
diff --git a/src/ipcpd/normal/dt.c b/src/ipcpd/normal/dt.c
index 593064f4..6ac73a93 100644
--- a/src/ipcpd/normal/dt.c
+++ b/src/ipcpd/normal/dt.c
@@ -93,7 +93,7 @@ static int sdu_handler(int fd,
if (pci.dst_addr != ipcpi.dt_addr) {
if (pci.ttl == 0) {
log_dbg("TTL was zero.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return 0;
}
@@ -103,7 +103,7 @@ static int sdu_handler(int fd,
if (fd < 0) {
pff_unlock(dt.pff[qc]);
log_err("No next hop for %" PRIu64, pci.dst_addr);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
@@ -111,7 +111,7 @@ static int sdu_handler(int fd,
if (ipcp_flow_write(fd, sdb)) {
log_err("Failed to write SDU to fd %d.", fd);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
} else {
@@ -268,7 +268,7 @@ int dt_write_sdu(struct pci * pci,
pff_unlock(dt.pff[pci->qos_id]);
log_err("Could not get nhop for address %" PRIu64,
pci->dst_addr);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
@@ -276,13 +276,13 @@ int dt_write_sdu(struct pci * pci,
if (shm_pci_ser(sdb, pci)) {
log_err("Failed to serialize PDU.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
if (ipcp_flow_write(fd, sdb)) {
log_err("Failed to write SDU to fd %d.", fd);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
diff --git a/src/ipcpd/normal/fa.c b/src/ipcpd/normal/fa.c
index 6c3df7a1..131100db 100644
--- a/src/ipcpd/normal/fa.c
+++ b/src/ipcpd/normal/fa.c
@@ -61,7 +61,7 @@ static int sdu_handler(int fd,
if (frct_i_write_sdu(fa.fd_to_cep_id[fd], sdb)) {
pthread_rwlock_unlock(&fa.flows_lock);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
log_warn("Failed to hand SDU to FRCT.");
return -1;
}
diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c
index bfcde1b3..71e32bd1 100644
--- a/src/ipcpd/normal/frct.c
+++ b/src/ipcpd/normal/frct.c
@@ -229,7 +229,7 @@ int frct_post_sdu(struct pci * pci,
pci->src_cep_id);
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -ENOMEM;
}
id = instance->cep_id;
@@ -237,7 +237,7 @@ int frct_post_sdu(struct pci * pci,
instance = frct.instances[pci->dst_cep_id];
if (instance == NULL) {
pthread_mutex_unlock(&frct.instances_lock);
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
id = pci->dst_cep_id;
@@ -253,16 +253,16 @@ int frct_post_sdu(struct pci * pci,
if (fa_post_buf(id, &buf)) {
log_err("Failed to hand buffer to FA.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
} else {
/* FIXME: Known cep-ids are delivered to FA (minimal DTP) */
if (fa_post_sdu(pci->dst_cep_id, sdb)) {
log_err("Failed to hand SDU to FA.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return -1;
}
}
diff --git a/src/ipcpd/normal/shm_pci.h b/src/ipcpd/normal/shm_pci.h
index 0c54c883..ff0b17ea 100644
--- a/src/ipcpd/normal/shm_pci.h
+++ b/src/ipcpd/normal/shm_pci.h
@@ -23,7 +23,7 @@
#ifndef OUROBOROS_IPCPD_NORMAL_SHM_PCI_H
#define OUROBOROS_IPCPD_NORMAL_SHM_PCI_H
-#include <ouroboros/shm_rdrbuff.h>
+#include <ouroboros/shm_du_buff.h>
#include <ouroboros/utils.h>
#include <ouroboros/qos.h>
diff --git a/src/ipcpd/shim-eth-llc/main.c b/src/ipcpd/shim-eth-llc/main.c
index 36cb12c4..72889236 100644
--- a/src/ipcpd/shim-eth-llc/main.c
+++ b/src/ipcpd/shim-eth-llc/main.c
@@ -731,7 +731,7 @@ static void * eth_llc_ipcp_sdu_writer(void * o)
shm_du_buff_head(sdb),
shm_du_buff_tail(sdb)
- shm_du_buff_head(sdb));
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
}
pthread_rwlock_unlock(&eth_llc_data.flows_lock);
}
diff --git a/src/ipcpd/shim-udp/main.c b/src/ipcpd/shim-udp/main.c
index 20e9b272..a3e87b86 100644
--- a/src/ipcpd/shim-udp/main.c
+++ b/src/ipcpd/shim-udp/main.c
@@ -501,7 +501,7 @@ static void * ipcp_udp_sdu_loop(void * o)
if (ipcp_get_state() != IPCP_OPERATIONAL) {
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
return (void *) 0; /* -ENOTENROLLED */
}
@@ -516,7 +516,7 @@ static void * ipcp_udp_sdu_loop(void * o)
0) < 0)
log_err("Failed to send SDU.");
- ipcp_flow_del(sdb);
+ ipcp_sdb_release(sdb);
}
}
diff --git a/src/lib/dev.c b/src/lib/dev.c
index 757f26a8..c46cd407 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -1430,6 +1430,32 @@ int ipcp_flow_write(int fd,
return 0;
}
+int ipcp_sdb_reserve(struct shm_du_buff ** sdb,
+ size_t len)
+{
+ struct shm_rdrbuff * rdrb;
+ ssize_t idx;
+
+ pthread_rwlock_rdlock(&ai.data_lock);
+
+ rdrb = ai.rdrb;
+
+ pthread_rwlock_unlock(&ai.data_lock);
+
+ idx = shm_rdrbuff_write_b(rdrb,
+ DU_BUFF_HEADSPACE,
+ DU_BUFF_TAILSPACE,
+ NULL,
+ len);
+
+ if (idx < 0)
+ return -1;
+
+ *sdb = shm_rdrbuff_get(rdrb, idx);
+
+ return 0;
+}
+
int ipcp_flow_fini(int fd)
{
struct shm_rbuff * rx_rb;
@@ -1539,7 +1565,7 @@ int ipcp_read_shim(int fd,
return 0;
}
-void ipcp_flow_del(struct shm_du_buff * sdb)
+void ipcp_sdb_release(struct shm_du_buff * sdb)
{
shm_rdrbuff_remove(ai.rdrb, shm_du_buff_get_idx(sdb));
}
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index 9dffdf74..ed9c3847 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -24,6 +24,7 @@
#include <ouroboros/config.h>
#include <ouroboros/errno.h>
#include <ouroboros/shm_rdrbuff.h>
+#include <ouroboros/shm_du_buff.h>
#include <ouroboros/time_utils.h>
#include <pthread.h>
@@ -333,7 +334,6 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
ssize_t sz = size + sizeof(*sdb);
assert(rdrb);
- assert(data);
#ifndef SHM_RDRB_MULTI_BLOCK
if (sz > SHM_RDRB_BLOCK_SIZE)
@@ -392,7 +392,8 @@ ssize_t shm_rdrbuff_write(struct shm_rdrbuff * rdrb,
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
- memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
+ if (data != NULL)
+ memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
}
@@ -412,7 +413,6 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
ssize_t sz = size + sizeof(*sdb);
assert(rdrb);
- assert(data);
#ifndef SHM_RDRB_MULTI_BLOCK
if (sz > SHM_RDRB_BLOCK_SIZE)
@@ -472,7 +472,9 @@ ssize_t shm_rdrbuff_write_b(struct shm_rdrbuff * rdrb,
sdb->size = size;
sdb->du_head = headspace;
sdb->du_tail = sdb->du_head + len;
- memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
+
+ if (data != NULL)
+ memcpy(((uint8_t *) (sdb + 1)) + headspace, data, len);
return sdb->idx;
}
@@ -495,7 +497,8 @@ ssize_t shm_rdrbuff_read(uint8_t ** dst,
return len;
}
-struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
+struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb,
+ size_t idx)
{
struct shm_du_buff * sdb;
@@ -507,7 +510,8 @@ struct shm_du_buff * shm_rdrbuff_get(struct shm_rdrbuff * rdrb, size_t idx)
return sdb;
}
-int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, size_t idx)
+int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb,
+ size_t idx)
{
assert(rdrb);
assert(idx < (SHM_BUFFER_SIZE));
@@ -609,3 +613,12 @@ void shm_du_buff_tail_release(struct shm_du_buff * sdb,
sdb->du_tail -= size;
}
+
+void shm_du_buff_truncate(struct shm_du_buff * sdb,
+ size_t len)
+{
+ assert(sdb);
+ assert(len <= sdb->size);
+
+ sdb->du_tail -= sdb->size - len;
+}