summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authordimitri staessens <dimitri.staessens@intec.ugent.be>2016-09-07 15:00:12 +0200
committerdimitri staessens <dimitri.staessens@intec.ugent.be>2016-09-07 15:00:12 +0200
commitab83ed430081d2833faa31b7f1cf187b043e56be (patch)
treebc432f673bb453b8fc7789cff363b9b49e8fbaf5 /src
parentdd1047b0e457c45d45a1b5b83972d4a75968cce2 (diff)
parent2cf4f88fc8b957c15ae93a2eb3e56ebdb07a0381 (diff)
downloadouroboros-ab83ed430081d2833faa31b7f1cf187b043e56be.tar.gz
ouroboros-ab83ed430081d2833faa31b7f1cf187b043e56be.zip
Merged in sandervrijders/ouroboros/be-shm-pci (pull request #247)
ipcpd: normal: Add operations to get and set the PCI
Diffstat (limited to 'src')
-rw-r--r--src/ipcpd/ipcp.c12
-rw-r--r--src/ipcpd/normal/CMakeLists.txt6
-rw-r--r--src/ipcpd/normal/crc32.c83
-rw-r--r--src/ipcpd/normal/crc32.h30
-rw-r--r--src/ipcpd/normal/dt_const.h13
-rw-r--r--src/ipcpd/normal/frct.c8
-rw-r--r--src/ipcpd/normal/frct.h29
-rw-r--r--src/ipcpd/normal/ribmgr.c12
-rw-r--r--src/ipcpd/normal/shm_pci.c234
-rw-r--r--src/ipcpd/normal/shm_pci.h26
-rw-r--r--src/ipcpd/normal/static_info.proto4
-rw-r--r--src/lib/dif_config.proto4
-rw-r--r--src/lib/irm.c8
-rw-r--r--src/lib/shm_rdrbuff.c117
-rw-r--r--src/tools/irm/irm_ipcp_bootstrap.c25
15 files changed, 372 insertions, 239 deletions
diff --git a/src/ipcpd/ipcp.c b/src/ipcpd/ipcp.c
index 12111a51..ec5ab927 100644
--- a/src/ipcpd/ipcp.c
+++ b/src/ipcpd/ipcp.c
@@ -252,12 +252,12 @@ void * ipcp_main_loop(void * o)
conf.cep_id_size = conf_msg->cep_id_size;
conf.pdu_length_size
= conf_msg->pdu_length_size;
- conf.qos_id_size = conf_msg->qos_id_size;
- conf.seqno_size = conf_msg->seqno_size;
- conf.ttl_size = conf_msg->seqno_size;
- conf.chk_size = conf_msg->chk_size;
- conf.min_pdu_size = conf_msg->min_pdu_size;
- conf.max_pdu_size = conf_msg->max_pdu_size;
+ conf.qos_id_size = conf_msg->qos_id_size;
+ conf.seqno_size = conf_msg->seqno_size;
+ conf.has_ttl = conf_msg->has_ttl;
+ conf.has_chk = conf_msg->has_chk;
+ conf.min_pdu_size = conf_msg->min_pdu_size;
+ conf.max_pdu_size = conf_msg->max_pdu_size;
}
if (conf_msg->ipcp_type == IPCP_SHIM_UDP) {
conf.ip_addr = conf_msg->ip_addr;
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt
index 68dca4b3..654bb127 100644
--- a/src/ipcpd/normal/CMakeLists.txt
+++ b/src/ipcpd/normal/CMakeLists.txt
@@ -22,12 +22,14 @@ protobuf_generate_c(FLOW_ALLOC_SRCS FLOW_ALLOC_HDRS
set(SOURCE_FILES
# Add source files here
- main.c
+ cdap_request.c
+ crc32.c
fmgr.c
frct.c
- cdap_request.c
+ main.c
ribmgr.c
rmt.c
+ shm_pci.c
)
add_executable (ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES}
diff --git a/src/ipcpd/normal/crc32.c b/src/ipcpd/normal/crc32.c
new file mode 100644
index 00000000..ad3e2b35
--- /dev/null
+++ b/src/ipcpd/normal/crc32.c
@@ -0,0 +1,83 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * 32-bit Cyclic Redundancy Check
+ *
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#include <stddef.h>
+
+#include "crc32.h"
+
+static const uint32_t crc32_table[256] = {
+ 0x00000000, 0x77073096, 0xee0e612c, 0x990951ba, 0x076dc419, 0x706af48f,
+ 0xe963a535, 0x9e6495a3, 0x0edb8832, 0x79dcb8a4, 0xe0d5e91e, 0x97d2d988,
+ 0x09b64c2b, 0x7eb17cbd, 0xe7b82d07, 0x90bf1d91, 0x1db71064, 0x6ab020f2,
+ 0xf3b97148, 0x84be41de, 0x1adad47d, 0x6ddde4eb, 0xf4d4b551, 0x83d385c7,
+ 0x136c9856, 0x646ba8c0, 0xfd62f97a, 0x8a65c9ec, 0x14015c4f, 0x63066cd9,
+ 0xfa0f3d63, 0x8d080df5, 0x3b6e20c8, 0x4c69105e, 0xd56041e4, 0xa2677172,
+ 0x3c03e4d1, 0x4b04d447, 0xd20d85fd, 0xa50ab56b, 0x35b5a8fa, 0x42b2986c,
+ 0xdbbbc9d6, 0xacbcf940, 0x32d86ce3, 0x45df5c75, 0xdcd60dcf, 0xabd13d59,
+ 0x26d930ac, 0x51de003a, 0xc8d75180, 0xbfd06116, 0x21b4f4b5, 0x56b3c423,
+ 0xcfba9599, 0xb8bda50f, 0x2802b89e, 0x5f058808, 0xc60cd9b2, 0xb10be924,
+ 0x2f6f7c87, 0x58684c11, 0xc1611dab, 0xb6662d3d, 0x76dc4190, 0x01db7106,
+ 0x98d220bc, 0xefd5102a, 0x71b18589, 0x06b6b51f, 0x9fbfe4a5, 0xe8b8d433,
+ 0x7807c9a2, 0x0f00f934, 0x9609a88e, 0xe10e9818, 0x7f6a0dbb, 0x086d3d2d,
+ 0x91646c97, 0xe6635c01, 0x6b6b51f4, 0x1c6c6162, 0x856530d8, 0xf262004e,
+ 0x6c0695ed, 0x1b01a57b, 0x8208f4c1, 0xf50fc457, 0x65b0d9c6, 0x12b7e950,
+ 0x8bbeb8ea, 0xfcb9887c, 0x62dd1ddf, 0x15da2d49, 0x8cd37cf3, 0xfbd44c65,
+ 0x4db26158, 0x3ab551ce, 0xa3bc0074, 0xd4bb30e2, 0x4adfa541, 0x3dd895d7,
+ 0xa4d1c46d, 0xd3d6f4fb, 0x4369e96a, 0x346ed9fc, 0xad678846, 0xda60b8d0,
+ 0x44042d73, 0x33031de5, 0xaa0a4c5f, 0xdd0d7cc9, 0x5005713c, 0x270241aa,
+ 0xbe0b1010, 0xc90c2086, 0x5768b525, 0x206f85b3, 0xb966d409, 0xce61e49f,
+ 0x5edef90e, 0x29d9c998, 0xb0d09822, 0xc7d7a8b4, 0x59b33d17, 0x2eb40d81,
+ 0xb7bd5c3b, 0xc0ba6cad, 0xedb88320, 0x9abfb3b6, 0x03b6e20c, 0x74b1d29a,
+ 0xead54739, 0x9dd277af, 0x04db2615, 0x73dc1683, 0xe3630b12, 0x94643b84,
+ 0x0d6d6a3e, 0x7a6a5aa8, 0xe40ecf0b, 0x9309ff9d, 0x0a00ae27, 0x7d079eb1,
+ 0xf00f9344, 0x8708a3d2, 0x1e01f268, 0x6906c2fe, 0xf762575d, 0x806567cb,
+ 0x196c3671, 0x6e6b06e7, 0xfed41b76, 0x89d32be0, 0x10da7a5a, 0x67dd4acc,
+ 0xf9b9df6f, 0x8ebeeff9, 0x17b7be43, 0x60b08ed5, 0xd6d6a3e8, 0xa1d1937e,
+ 0x38d8c2c4, 0x4fdff252, 0xd1bb67f1, 0xa6bc5767, 0x3fb506dd, 0x48b2364b,
+ 0xd80d2bda, 0xaf0a1b4c, 0x36034af6, 0x41047a60, 0xdf60efc3, 0xa867df55,
+ 0x316e8eef, 0x4669be79, 0xcb61b38c, 0xbc66831a, 0x256fd2a0, 0x5268e236,
+ 0xcc0c7795, 0xbb0b4703, 0x220216b9, 0x5505262f, 0xc5ba3bbe, 0xb2bd0b28,
+ 0x2bb45a92, 0x5cb36a04, 0xc2d7ffa7, 0xb5d0cf31, 0x2cd99e8b, 0x5bdeae1d,
+ 0x9b64c2b0, 0xec63f226, 0x756aa39c, 0x026d930a, 0x9c0906a9, 0xeb0e363f,
+ 0x72076785, 0x05005713, 0x95bf4a82, 0xe2b87a14, 0x7bb12bae, 0x0cb61b38,
+ 0x92d28e9b, 0xe5d5be0d, 0x7cdcefb7, 0x0bdbdf21, 0x86d3d2d4, 0xf1d4e242,
+ 0x68ddb3f8, 0x1fda836e, 0x81be16cd, 0xf6b9265b, 0x6fb077e1, 0x18b74777,
+ 0x88085ae6, 0xff0f6a70, 0x66063bca, 0x11010b5c, 0x8f659eff, 0xf862ae69,
+ 0x616bffd3, 0x166ccf45, 0xa00ae278, 0xd70dd2ee, 0x4e048354, 0x3903b3c2,
+ 0xa7672661, 0xd06016f7, 0x4969474d, 0x3e6e77db, 0xaed16a4a, 0xd9d65adc,
+ 0x40df0b66, 0x37d83bf0, 0xa9bcae53, 0xdebb9ec5, 0x47b2cf7f, 0x30b5ffe9,
+ 0xbdbdf21c, 0xcabac28a, 0x53b39330, 0x24b4a3a6, 0xbad03605, 0xcdd70693,
+ 0x54de5729, 0x23d967bf, 0xb3667a2e, 0xc4614ab8, 0x5d681b02, 0x2a6f2b94,
+ 0xb40bbe37, 0xc30c8ea1, 0x5a05df1b, 0x2d02ef8d
+};
+
+void crc32(uint32_t * crc, const uint8_t * buf, size_t len)
+{
+ size_t n;
+
+ *crc = *crc ^ 0xffffffff;
+
+ for (n = 0; n < len; n++)
+ *crc = crc32_table[(*crc ^ buf[n]) & 0xff] ^ (*crc >> 8);
+
+ *crc = *crc ^ 0xffffffff;
+}
diff --git a/src/ipcpd/normal/crc32.h b/src/ipcpd/normal/crc32.h
new file mode 100644
index 00000000..f22bbc19
--- /dev/null
+++ b/src/ipcpd/normal/crc32.h
@@ -0,0 +1,30 @@
+/*
+ * Ouroboros - Copyright (C) 2016
+ *
+ * 32-bit Cyclic Redundancy Check
+ *
+ * Sander Vrijders <sander.vrijders@intec.ugent.be>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program 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 General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+ */
+
+#ifndef OUROBOROS_IPCP_CRC32_H
+#define OUROBOROS_IPCP_CRC32_H
+
+#include <stdint.h>
+
+void crc32(uint32_t * crc, const uint8_t * buf, size_t len);
+
+#endif /* OUROBOROS_IPCP_CRC32_H */
diff --git a/src/ipcpd/normal/dt_const.h b/src/ipcpd/normal/dt_const.h
index b33f16c5..eda66838 100644
--- a/src/ipcpd/normal/dt_const.h
+++ b/src/ipcpd/normal/dt_const.h
@@ -25,14 +25,15 @@
#define IPCP_DT_CONST_H
#include <stdint.h>
+#include <stdbool.h>
struct dt_const {
- uint8_t addr_size;
- uint8_t cep_id_size;
- uint8_t pdu_length_size;
- uint8_t seqno_size;
- uint8_t ttl_size;
- uint8_t chk_size;
+ uint8_t addr_size;
+ uint8_t cep_id_size;
+ uint8_t pdu_length_size;
+ uint8_t seqno_size;
+ bool has_ttl;
+ bool has_chk;
uint32_t min_pdu_size;
uint32_t max_pdu_size;
};
diff --git a/src/ipcpd/normal/frct.c b/src/ipcpd/normal/frct.c
index 7c2eba61..417815b7 100644
--- a/src/ipcpd/normal/frct.c
+++ b/src/ipcpd/normal/frct.c
@@ -126,6 +126,14 @@ int frct_fini()
return 0;
}
+struct dt_const * frct_dt_const()
+{
+ if (frct == NULL)
+ return NULL;
+
+ return frct->dtc;
+}
+
int frct_dt_flow(int fd,
enum qos_cube qos)
{
diff --git a/src/ipcpd/normal/frct.h b/src/ipcpd/normal/frct.h
index 91b2dfc7..09873445 100644
--- a/src/ipcpd/normal/frct.h
+++ b/src/ipcpd/normal/frct.h
@@ -30,26 +30,29 @@
struct frct_i;
-int frct_init(struct dt_const * dtc,
- uint32_t address);
-int frct_fini();
+int frct_init(struct dt_const * dtc,
+ uint32_t address);
+int frct_fini();
+
+struct dt_const * frct_dt_const();
+
+int frct_dt_flow(int fd,
+ enum qos_cube qos);
-int frct_dt_flow(int fd,
- enum qos_cube qos);
/*
* FIXME: Will take the index in the DU map,
* possibly cep-ids and address
*/
-int frct_rmt_post();
+int frct_rmt_post();
-struct frct_i * frct_i_create(uint32_t address,
- buffer_t * buf,
- enum qos_cube cube);
+struct frct_i * frct_i_create(uint32_t address,
+ buffer_t * buf,
+ enum qos_cube cube);
/* FIXME: Hand QoS cube here too? We received it in the flow alloc message. */
-int frct_i_accept(struct frct_i * instance,
- buffer_t * buf);
-int frct_i_destroy(struct frct_i * instance,
- buffer_t * buf);
+int frct_i_accept(struct frct_i * instance,
+ buffer_t * buf);
+int frct_i_destroy(struct frct_i * instance,
+ buffer_t * buf);
/* FIXME: Add read/write ops for frct instances */
diff --git a/src/ipcpd/normal/ribmgr.c b/src/ipcpd/normal/ribmgr.c
index 007361fd..9733abc9 100644
--- a/src/ipcpd/normal/ribmgr.c
+++ b/src/ipcpd/normal/ribmgr.c
@@ -241,8 +241,8 @@ int ribmgr_cdap_write(struct cdap * instance,
rib->dtc.cep_id_size = msg->cep_id_size;
rib->dtc.pdu_length_size = msg->pdu_length_size;
rib->dtc.seqno_size = msg->seqno_size;
- rib->dtc.ttl_size = msg->ttl_size;
- rib->dtc.chk_size = msg->chk_size;
+ rib->dtc.has_ttl = msg->has_ttl;
+ rib->dtc.has_chk = msg->has_chk;
rib->dtc.min_pdu_size = msg->min_pdu_size;
rib->dtc.max_pdu_size = msg->max_pdu_size;
@@ -318,8 +318,8 @@ int ribmgr_cdap_start(struct cdap * instance,
stat_info.cep_id_size = rib->dtc.cep_id_size;
stat_info.pdu_length_size = rib->dtc.pdu_length_size;
stat_info.seqno_size = rib->dtc.seqno_size;
- stat_info.ttl_size = rib->dtc.ttl_size;
- stat_info.chk_size = rib->dtc.chk_size;
+ stat_info.has_ttl = rib->dtc.has_ttl;
+ stat_info.has_chk = rib->dtc.has_chk;
stat_info.min_pdu_size = rib->dtc.min_pdu_size;
stat_info.max_pdu_size = rib->dtc.max_pdu_size;
@@ -529,8 +529,8 @@ int ribmgr_bootstrap(struct dif_config * conf)
rib->dtc.cep_id_size = conf->cep_id_size;
rib->dtc.pdu_length_size = conf->pdu_length_size;
rib->dtc.seqno_size = conf->seqno_size;
- rib->dtc.ttl_size = conf->ttl_size;
- rib->dtc.chk_size = conf->chk_size;
+ rib->dtc.has_ttl = conf->has_ttl;
+ rib->dtc.has_chk = conf->has_chk;
rib->dtc.min_pdu_size = conf->min_pdu_size;
rib->dtc.max_pdu_size = conf->max_pdu_size;
diff --git a/src/ipcpd/normal/shm_pci.c b/src/ipcpd/normal/shm_pci.c
index 144bd15e..94629790 100644
--- a/src/ipcpd/normal/shm_pci.c
+++ b/src/ipcpd/normal/shm_pci.c
@@ -21,127 +21,183 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <ourboros/errno.h>
-
-#include "shm_pci.h"
-#include <stdlib.h>
-
-#define SHM_PCI_HEAD_SIZE(a, b) a.addr_size * 2 + \
- a.cep_id_size * 2 + \
- a.pdu_length_size + \
- b.ttl_size + \
- a.seqno_size + \
- a.qos_id_size
-#define SHM_PCI_TAIL_SIZE(b) b.chk_size
-
#define OUROBOROS_PREFIX "ipcpd/shm_pci"
#include <ouroboros/logs.h>
+#include <ouroboros/errno.h>
-struct shm_pci {
- /* head */
- uint8_t * dst_addr;
- uint8_t * src_addr;
- uint8_t * dst_cep_id;
- uint8_t * src_cep_id;
- uint8_t * pdu_length;
- uint8_t * ttl;
- uint8_t * seqno;
- uint8_t * qos_id;
+#include <stdlib.h>
+#include <string.h>
- uint8_t * chk;
+#include "shm_pci.h"
+#include "frct.h"
+#include "crc32.h"
- struct shm_du_buff * dub;
+#define QOS_ID_SIZE 1
+#define DEFAULT_TTL 60
+#define TTL_SIZE 1
+#define CHK_SIZE 4
- struct ipcp_dtp_const dtpc;
- struct ipcp_dup_const dupc;
+static int shm_pci_head_size(struct dt_const * dtc)
+{
+ int len = 0;
-};
+ len = dtc->addr_size * 2 + dtc->cep_id_size * 2
+ + dtc->pdu_length_size + dtc->seqno_size
+ + QOS_ID_SIZE;
-shm_pci_t * shm_pci_create(struct shm_du_buff * dub,
- const struct ipcp_dtp_const * dtpc,
- const struct ipcp_dup_const * dupc)
+ if (dtc->has_ttl)
+ len += TTL_SIZE;
+
+ return len;
+}
+
+static int shm_pci_tail_size(struct dt_const * dtc)
{
- struct shm_pci * p;
+ return dtc->has_chk ? CHK_SIZE : 0;
+}
- if (dub == NULL) {
- LOG_DBGF("Bogus input. Bugging out.");
- return NULL;
+int shm_pci_ser(struct shm_du_buff * sdb,
+ struct pci * pci)
+{
+ uint8_t * head;
+ uint8_t * tail;
+ int offset = 0;
+ struct dt_const * dtc;
+ uint8_t ttl = DEFAULT_TTL;
+
+ dtc = frct_dt_const();
+ if (dtc == NULL)
+ return -1;
+
+ head = shm_du_buff_head_alloc(sdb, shm_pci_head_size(dtc));
+ if (head == NULL)
+ return -1;
+
+ memcpy(head, &pci->dst_addr, dtc->addr_size);
+ offset += dtc->addr_size;
+ memcpy(head + offset, &pci->src_addr, dtc->addr_size);
+ offset += dtc->addr_size;
+ memcpy(head + offset, &pci->dst_cep_id, dtc->cep_id_size);
+ offset += dtc->cep_id_size;
+ memcpy(head + offset, &pci->src_cep_id, dtc->cep_id_size);
+ offset += dtc->cep_id_size;
+ memcpy(head + offset, &pci->pdu_length, dtc->pdu_length_size);
+ offset += dtc->pdu_length_size;
+ memcpy(head + offset, &pci->seqno, dtc->seqno_size);
+ offset += dtc->seqno_size;
+ memcpy(head + offset, &pci->qos_id, QOS_ID_SIZE);
+ offset += QOS_ID_SIZE;
+ if (dtc->has_ttl)
+ memcpy(head + offset, &ttl, TTL_SIZE);
+
+ if (dtc->has_chk) {
+ tail = shm_du_buff_tail_alloc(sdb, shm_pci_tail_size(dtc));
+ if (tail == NULL) {
+ shm_du_buff_head_release(sdb, shm_pci_tail_size(dtc));
+ return -1;
+ }
+
+ crc32((uint32_t *) tail, head, tail - head);
}
- p = malloc(sizeof *p);
+ return 0;
+}
- if (p == NULL)
- return NULL;
+struct pci * shm_pci_des(struct shm_du_buff * sdb)
+{
+ uint8_t * head;
+ struct pci * pci;
+ int offset = 0;
+ struct dt_const * dtc;
- p->dub = dub;
+ head = shm_du_buff_head(sdb);
+ if (head == NULL)
+ return NULL;
- p->dtpc = *dtpc;
- p->dupc = *dupc;
+ dtc = frct_dt_const();
+ if (dtc == NULL)
+ return NULL;
- p->dst_addr = NULL;
- p->src_addr = NULL;
- p->dst_cep_id = NULL;
- p->src_cep_id = NULL;
- p->pdu_length = NULL;
- p->ttl = NULL;
- p->seqno = NULL;
- p->qos_id = NULL;
- p->chk = NULL;
+ pci = malloc(sizeof(*pci));
+ if (pci == NULL)
+ return NULL;
- return p;
+ memcpy(&pci->dst_addr, head, dtc->addr_size);
+ offset += dtc->addr_size;
+ memcpy(&pci->src_addr, head + offset, dtc->addr_size);
+ offset += dtc->addr_size;
+ memcpy(&pci->dst_cep_id, head + offset, dtc->cep_id_size);
+ offset += dtc->cep_id_size;
+ memcpy(&pci->src_cep_id, head + offset, dtc->cep_id_size);
+ offset += dtc->cep_id_size;
+ memcpy(&pci->pdu_length, head + offset, dtc->pdu_length_size);
+ offset += dtc->pdu_length_size;
+ memcpy(&pci->seqno, head + offset, dtc->seqno_size);
+ offset += dtc->seqno_size;
+ memcpy(&pci->qos_id, head + offset, QOS_ID_SIZE);
+ offset += QOS_ID_SIZE;
+ if (dtc->has_ttl)
+ memcpy(&pci->ttl, head + offset, TTL_SIZE);
+
+ return pci;
}
-void shm_pci_destroy(shm_pci_t * pci)
+int shm_pci_shrink(struct shm_du_buff * sdb)
{
- free(pci);
-}
+ struct dt_const * dtc;
-int shm_pci_init(shm_pci_t * pci)
-{
- if (pci == NULL) {
- LOG_DBGF("Bogus input. Bugging out.");
- return -EINVAL;
- }
+ if (sdb == NULL)
+ return -1;
- uint8_t * pci_head = shm_du_buff_head_alloc(
- pci->dub, SHM_PCI_HEAD_SIZE(pci->dtpc, pci->dupc));
- uint8_t * pci_tail = shm_du_buff_tail_alloc(
- pci->dub, SHM_PCI_TAIL_SIZE(pci->dupc));
+ dtc = frct_dt_const();
+ if (dtc == NULL)
+ return -1;
- if (pci_head == NULL) {
- LOG_DBG("Failed to allocate space for PCI at head.");
- return -ENOBUFS;
+ if (shm_du_buff_head_release(sdb, shm_pci_head_size(dtc))) {
+ LOG_ERR("Failed to shrink head.");
+ return -1;
}
- if (pci_tail == NULL) {
- LOG_DBG("Failed to allocate space for PCI at tail.");
- return -ENOBUFS;
+ if (shm_du_buff_tail_release(sdb, shm_pci_tail_size(dtc))) {
+ LOG_ERR("Failed to shrink tail.");
+ return -1;
}
- pci->dst_addr = pci_head;
- pci->src_addr = (pci_head += pci->dtpc.addr_size);
- pci->dst_cep_id = (pci_head += pci->dtpc.addr_size);
- pci->src_cep_id = (pci_head += pci->dtpc.cep_id_size);
- pci->pdu_length = (pci_head += pci->dtpc.cep_id_size);
- pci->ttl = (pci_head += pci->dtpc.pdu_length_size);
- pci->seqno = (pci_head += pci->dupc.ttl_size);
- pci->qos_id = (pci_head += pci->dtpc.seqno_size);
-
- pci->chk = (pci_tail);
-
return 0;
}
-void shm_pci_release(shm_pci_t * pci)
+int shm_pci_dec_ttl(struct shm_du_buff * sdb)
{
- if (pci == NULL)
- return;
+ struct dt_const * dtc;
+ int offset = 0;
+ uint8_t * head;
+ uint8_t * tail;
- if (pci->dub == NULL)
- return;
+ dtc = frct_dt_const();
+ if (dtc == NULL)
+ return -1;
- shm_du_buff_head_release(pci->dub, SHM_PCI_HEAD_SIZE(pci->dtpc,
- pci->dupc));
- shm_du_buff_tail_release(pci->dub, SHM_PCI_TAIL_SIZE(pci->dupc));
+ if (dtc->has_ttl == false)
+ return 0;
+
+ offset = shm_pci_head_size(dtc) - 1;
+
+ head = shm_du_buff_head(sdb);
+ if (head == NULL)
+ return -1;
+
+ head[offset]--;
+
+ if (dtc->has_chk) {
+ tail = shm_du_buff_tail(sdb);
+ if (tail == NULL)
+ return -1;
+
+ tail -= CHK_SIZE;
+
+ crc32((uint32_t *) tail, head, tail - head);
+ }
+
+ return 0;
}
diff --git a/src/ipcpd/normal/shm_pci.h b/src/ipcpd/normal/shm_pci.h
index cb8dd5dd..aa9770b4 100644
--- a/src/ipcpd/normal/shm_pci.h
+++ b/src/ipcpd/normal/shm_pci.h
@@ -24,20 +24,28 @@
#ifndef OUROBOROS_IPCP_SHM_PCI_H
#define OUROBOROS_IPCP_SHM_PCI_H
-#include <ouroboros/shm_du_map.h>
+#include <ouroboros/shm_rdrbuff.h>
#include <dt_const.h>
-struct shm_pci;
+struct pci {
+ uint64_t dst_addr;
+ uint64_t src_addr;
+ uint32_t dst_cep_id;
+ uint32_t src_cep_id;
+ uint32_t pdu_length;
+ uint64_t seqno;
+ uint8_t qos_id;
+ uint8_t ttl;
+};
-typedef struct shm_pci shm_pci_t;
+int shm_pci_ser(struct shm_du_buff * sdb,
+ struct pci * pci);
-shm_pci_t * shm_pci_create(struct shm_du_buff * dub,
- const struct ipcp_dtp_const * dtpc,
- const struct ipcp_dup_const * dupc);
-void shm_pci_destroy(shm_pci_t * pci);
+struct pci * shm_pci_des(struct shm_du_buff * sdb);
-int shm_pci_init(shm_pci_t * pci);
-void shm_pci_release(shm_pci_t * pci);
+int shm_pci_shrink(struct shm_du_buff * sdb);
+
+int shm_pci_dec_ttl(struct shm_du_buff * sdb);
#endif /* OUROBOROS_IPCP_SHM_PCI_H */
diff --git a/src/ipcpd/normal/static_info.proto b/src/ipcpd/normal/static_info.proto
index 24b7994a..04824a38 100644
--- a/src/ipcpd/normal/static_info.proto
+++ b/src/ipcpd/normal/static_info.proto
@@ -3,8 +3,8 @@ message static_info_msg {
required uint32 cep_id_size = 2;
required uint32 pdu_length_size = 3;
required uint32 seqno_size = 4;
- required uint32 ttl_size = 5;
- required uint32 chk_size = 6;
+ required bool has_ttl = 5;
+ required bool has_chk = 6;
required uint32 min_pdu_size = 7;
required uint32 max_pdu_size = 8;
required uint32 address = 9;
diff --git a/src/lib/dif_config.proto b/src/lib/dif_config.proto
index dbdf19e5..338634d1 100644
--- a/src/lib/dif_config.proto
+++ b/src/lib/dif_config.proto
@@ -7,8 +7,8 @@ message dif_config_msg {
optional uint32 pdu_length_size = 5;
optional uint32 qos_id_size = 6;
optional uint32 seqno_size = 7;
- optional uint32 ttl_size = 8;
- optional uint32 chk_size = 9;
+ optional bool has_ttl = 8;
+ optional bool has_chk = 9;
optional uint32 min_pdu_size = 10;
optional uint32 max_pdu_size = 11;
// Config for shim UDP
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 64a4fa0f..fce11ba5 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -115,8 +115,8 @@ int irm_bootstrap_ipcp(pid_t api,
config.has_pdu_length_size = true;
config.has_qos_id_size = true;
config.has_seqno_size = true;
- config.has_ttl_size = true;
- config.has_chk_size = true;
+ config.has_has_ttl = true;
+ config.has_has_chk = true;
config.has_min_pdu_size = true;
config.has_max_pdu_size = true;
@@ -125,8 +125,8 @@ int irm_bootstrap_ipcp(pid_t api,
config.pdu_length_size = conf->pdu_length_size;
config.qos_id_size = conf->qos_id_size;
config.seqno_size = conf->seqno_size;
- config.ttl_size = conf->ttl_size;
- config.chk_size = conf->chk_size;
+ config.has_ttl = conf->has_ttl;
+ config.has_chk = conf->has_chk;
config.min_pdu_size = conf->min_pdu_size;
config.max_pdu_size = conf->max_pdu_size;
break;
diff --git a/src/lib/shm_rdrbuff.c b/src/lib/shm_rdrbuff.c
index 3eae8f97..7c4927fc 100644
--- a/src/lib/shm_rdrbuff.c
+++ b/src/lib/shm_rdrbuff.c
@@ -688,32 +688,32 @@ int shm_rdrbuff_remove(struct shm_rdrbuff * rdrb, ssize_t idx)
return 0;
}
-uint8_t * shm_du_buff_head_alloc(struct shm_rdrbuff * rdrb,
- ssize_t idx,
- size_t size)
+uint8_t * shm_du_buff_head(struct shm_du_buff * sdb)
{
- struct shm_du_buff * sdb;
- uint8_t * buf;
-
- if (rdrb == NULL)
+ if (sdb == NULL)
return NULL;
- if (idx < 0 || idx > SHM_BUFFER_SIZE)
+ return (uint8_t *) (sdb + 1) + sdb->du_head;
+}
+
+uint8_t * shm_du_buff_tail(struct shm_du_buff * sdb)
+{
+ if (sdb == NULL)
return NULL;
-#ifdef __APPLE__
- pthread_mutex_lock(rdrb->lock);
-#else
- if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) {
- LOG_DBGF("Recovering dead mutex.");
- pthread_mutex_consistent(rdrb->lock);
- }
-#endif
- sdb = idx_to_du_buff_ptr(rdrb, idx);
+ return (uint8_t *) (sdb + 1) + sdb->du_tail;
+}
+
+uint8_t * shm_du_buff_head_alloc(struct shm_du_buff * sdb,
+ size_t size)
+{
+ uint8_t * buf = NULL;
+
+ if (sdb == NULL)
+ return NULL;
if ((long) (sdb->du_head - size) < 0) {
- pthread_mutex_unlock(rdrb->lock);
- LOG_DBGF("Failed to allocate PCI headspace.");
+ LOG_ERR("Failed to allocate PCI headspace.");
return NULL;
}
@@ -721,37 +721,19 @@ uint8_t * shm_du_buff_head_alloc(struct shm_rdrbuff * rdrb,
buf = (uint8_t *) (sdb + 1) + sdb->du_head;
- pthread_mutex_unlock(rdrb->lock);
-
return buf;
}
-uint8_t * shm_du_buff_tail_alloc(struct shm_rdrbuff * rdrb,
- ssize_t idx,
+uint8_t * shm_du_buff_tail_alloc(struct shm_du_buff * sdb,
size_t size)
{
- struct shm_du_buff * sdb;
- uint8_t * buf;
-
- if (rdrb == NULL)
- return NULL;
+ uint8_t * buf = NULL;
- if (idx < 0 || idx > SHM_BUFFER_SIZE)
+ if (sdb == NULL)
return NULL;
-#ifdef __APPLE__
- pthread_mutex_lock(rdrb->lock);
-#else
- if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) {
- LOG_DBGF("Recovering dead mutex.");
- pthread_mutex_consistent(rdrb->lock);
- }
-#endif
- sdb = idx_to_du_buff_ptr(rdrb, idx);
-
if (sdb->du_tail + size >= sdb->size) {
- pthread_mutex_unlock(rdrb->lock);
- LOG_DBGF("Failed to allocate PCI tailspace.");
+ LOG_ERR("Failed to allocate PCI tailspace.");
return NULL;
}
@@ -759,78 +741,37 @@ uint8_t * shm_du_buff_tail_alloc(struct shm_rdrbuff * rdrb,
sdb->du_tail += size;
- pthread_mutex_unlock(rdrb->lock);
-
return buf;
}
-int shm_du_buff_head_release(struct shm_rdrbuff * rdrb,
- ssize_t idx,
+int shm_du_buff_head_release(struct shm_du_buff * sdb,
size_t size)
{
- struct shm_du_buff * sdb;
-
- if (rdrb == NULL)
- return -1;
-
- if (idx < 0 || idx > SHM_BUFFER_SIZE)
+ if (sdb == NULL)
return -1;
-#ifdef __APPLE__
- pthread_mutex_lock(rdrb->lock);
-#else
- if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) {
- LOG_DBGF("Recovering dead mutex.");
- pthread_mutex_consistent(rdrb->lock);
- }
-#endif
-
- sdb = idx_to_du_buff_ptr(rdrb, idx);
-
if (size > sdb->du_tail - sdb->du_head) {
- pthread_mutex_unlock(rdrb->lock);
- LOG_DBGF("Tried to release beyond sdu boundary.");
+ LOG_DBGF("Tried to release beyond SDU boundary.");
return -EOVERFLOW;
}
sdb->du_head += size;
- pthread_mutex_unlock(rdrb->lock);
-
return 0;
}
-int shm_du_buff_tail_release(struct shm_rdrbuff * rdrb,
- ssize_t idx,
+int shm_du_buff_tail_release(struct shm_du_buff * sdb,
size_t size)
{
- struct shm_du_buff * sdb;
-
- if (rdrb == NULL)
- return -1;
-
- if (idx < 0 || idx > SHM_BUFFER_SIZE)
+ if (sdb == NULL)
return -1;
-#ifdef __APPLE__
- pthread_mutex_lock(rdrb->lock);
-#else
- if (pthread_mutex_lock(rdrb->lock) == EOWNERDEAD) {
- LOG_DBGF("Recovering dead mutex.");
- pthread_mutex_consistent(rdrb->lock);
- }
-#endif
- sdb = idx_to_du_buff_ptr(rdrb, idx);
-
if (size > sdb->du_tail - sdb->du_head) {
- pthread_mutex_unlock(rdrb->lock);
- LOG_DBGF("Tried to release beyond sdu boundary.");
+ LOG_ERR("Tried to release beyond SDU boundary.");
return -EOVERFLOW;
}
sdb->du_tail -= size;
- pthread_mutex_unlock(rdrb->lock);
-
return 0;
}
diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c
index 3db43e6e..ba9b7e2e 100644
--- a/src/tools/irm/irm_ipcp_bootstrap.c
+++ b/src/tools/irm/irm_ipcp_bootstrap.c
@@ -42,8 +42,6 @@
#define DEFAULT_CEP_ID_SIZE 2
#define DEFAULT_PDU_LEN_SIZE 2
#define DEFAULT_SEQ_NO_SIZE 4
-#define DEFAULT_TTL_SIZE 1
-#define DEFAULT_CHK_SIZE 2
#define DEFAULT_MIN_PDU_SIZE 0
#define DEFAULT_MAX_PDU_SIZE 9000
#define DEFAULT_DDNS 0
@@ -62,8 +60,8 @@ static void usage()
" [cep_id <CEP-id size> (default: %d)]\n"
" [pdu_len <PDU length size> (default: %d)]\n"
" [seqno <sequence number size> (default: %d)]\n"
- " [ttl <time to live size> (default: %d)]\n"
- " [chk <checksum size> (default: %d)]\n"
+ " [ttl <add time to live value in the PCI>]\n"
+ " [chk <add 32-bit checksum in the PCI>]\n"
" [min_pdu <minimum PDU size> (default: %d)]\n"
" [max_pdu <maximum PDU size> (default: %d)]\n"
"if TYPE == " SHIM_UDP "\n"
@@ -74,7 +72,6 @@ static void usage()
" if_name <interface name>\n",
DEFAULT_ADDR_SIZE, DEFAULT_CEP_ID_SIZE,
DEFAULT_PDU_LEN_SIZE, DEFAULT_SEQ_NO_SIZE,
- DEFAULT_TTL_SIZE, DEFAULT_CHK_SIZE,
DEFAULT_MIN_PDU_SIZE, DEFAULT_MAX_PDU_SIZE, DEFAULT_DDNS);
}
@@ -86,8 +83,8 @@ int do_bootstrap_ipcp(int argc, char ** argv)
uint8_t cep_id_size = DEFAULT_CEP_ID_SIZE;
uint8_t pdu_length_size = DEFAULT_PDU_LEN_SIZE;
uint8_t seqno_size = DEFAULT_SEQ_NO_SIZE;
- uint8_t ttl_size = DEFAULT_TTL_SIZE;
- uint8_t chk_size = DEFAULT_CHK_SIZE;
+ bool has_ttl = false;
+ bool has_chk = false;
uint32_t min_pdu_size = DEFAULT_MIN_PDU_SIZE;
uint32_t max_pdu_size = DEFAULT_MAX_PDU_SIZE;
uint32_t ip_addr = 0;
@@ -112,7 +109,7 @@ int do_bootstrap_ipcp(int argc, char ** argv)
return -1;
}
} else if (matches(*argv, "dns") == 0) {
- if (inet_pton (AF_INET, *(argv + 1), &dns_addr) != 1) {
+ if (inet_pton(AF_INET, *(argv + 1), &dns_addr) != 1) {
usage();
return -1;
}
@@ -127,9 +124,13 @@ int do_bootstrap_ipcp(int argc, char ** argv)
} else if (matches(*argv, "seqno") == 0) {
seqno_size = atoi(*(argv + 1));
} else if (matches(*argv, "ttl") == 0) {
- ttl_size = atoi(*(argv + 1));
+ has_ttl = true;
+ argc++;
+ argv--;
} else if (matches(*argv, "chk") == 0) {
- chk_size = atoi(*(argv + 1));
+ has_chk = true;
+ argc++;
+ argv--;
} else if (matches(*argv, "min_pdu") == 0) {
min_pdu_size = atoi(*(argv + 1));
} else if (matches(*argv, "max_pdu") == 0) {
@@ -157,8 +158,8 @@ int do_bootstrap_ipcp(int argc, char ** argv)
conf.cep_id_size = cep_id_size;
conf.pdu_length_size = pdu_length_size;
conf.seqno_size = seqno_size;
- conf.ttl_size = ttl_size;
- conf.chk_size = chk_size;
+ conf.has_ttl = has_ttl;
+ conf.has_chk = has_chk;
conf.min_pdu_size = min_pdu_size;
conf.max_pdu_size = max_pdu_size;
} else if (strcmp(ipcp_type, SHIM_UDP) == 0) {