diff options
author | dimitri staessens <[email protected]> | 2017-05-12 13:05:47 +0200 |
---|---|---|
committer | dimitri staessens <[email protected]> | 2017-05-15 12:06:09 +0200 |
commit | 9903b8a2f9a7dc8ebac6928dcf2d2b5593ea0615 (patch) | |
tree | ea16469c2d8fbcb417ed89e0bbd550834d0602a6 /src/ipcpd/normal/dt_pci.c | |
parent | b36acfd93b1dc16a153ca9b9077d113732accb4e (diff) | |
download | ouroboros-9903b8a2f9a7dc8ebac6928dcf2d2b5593ea0615.tar.gz ouroboros-9903b8a2f9a7dc8ebac6928dcf2d2b5593ea0615.zip |
ipcpd: Allow specifying fixed syntax
This commits adds the functions and messages to specify a fixed
protocol syntax during CACEP. It also revises the messages for
specifying the DT protocol syntax from the irm tool.
Diffstat (limited to 'src/ipcpd/normal/dt_pci.c')
-rw-r--r-- | src/ipcpd/normal/dt_pci.c | 70 |
1 files changed, 26 insertions, 44 deletions
diff --git a/src/ipcpd/normal/dt_pci.c b/src/ipcpd/normal/dt_pci.c index 9f3b9a91..a4f99142 100644 --- a/src/ipcpd/normal/dt_pci.c +++ b/src/ipcpd/normal/dt_pci.c @@ -25,7 +25,6 @@ #include <ouroboros/crc32.h> #include <ouroboros/rib.h> -#include "dt_const.h" #include "dt_pci.h" #include "ribconfig.h" @@ -33,16 +32,13 @@ #include <string.h> #include <assert.h> -#define PDU_TYPE_SIZE 1 -#define QC_SIZE 1 #define DEFAULT_TTL 60 -#define TTL_SIZE 1 -#define CHK_SIZE 4 struct { - struct dt_const dtc; + uint8_t addr_size; + uint8_t fd_size; + bool has_ttl; size_t head_size; - size_t tail_size; /* offsets */ size_t qc_o; @@ -50,29 +46,28 @@ struct { size_t fd_o; } dt_pci_info; -int dt_pci_init(void) +int dt_pci_init() { /* read dt constants from the RIB */ if (rib_read(BOOT_PATH "/dt/const/addr_size", - &dt_pci_info.dtc.addr_size, - sizeof(dt_pci_info.dtc.addr_size)) < 0 || + &dt_pci_info.addr_size, + sizeof(dt_pci_info.addr_size)) < 0 || + rib_read(BOOT_PATH "/dt/const/fd_size", + &dt_pci_info.fd_size, + sizeof(dt_pci_info.fd_size)) < 0 || rib_read(BOOT_PATH "/dt/const/has_ttl", - &dt_pci_info.dtc.has_ttl, - sizeof(dt_pci_info.dtc.has_ttl)) < 0 || - rib_read(BOOT_PATH "/dt/const/has_chk", - &dt_pci_info.dtc.has_chk, - sizeof(dt_pci_info.dtc.has_chk)) < 0) + &dt_pci_info.has_ttl, + sizeof(dt_pci_info.has_ttl)) < 0) return -1; - dt_pci_info.qc_o = dt_pci_info.dtc.addr_size; - dt_pci_info.ttl_o = dt_pci_info.qc_o + QC_SIZE; - if (dt_pci_info.dtc.has_ttl) - dt_pci_info.fd_o = dt_pci_info.ttl_o + TTL_SIZE; + dt_pci_info.qc_o = dt_pci_info.addr_size; + dt_pci_info.ttl_o = dt_pci_info.qc_o + QOS_LEN; + if (dt_pci_info.has_ttl) + dt_pci_info.fd_o = dt_pci_info.ttl_o + TTL_LEN; else dt_pci_info.fd_o = dt_pci_info.ttl_o; - dt_pci_info.head_size = dt_pci_info.fd_o + PDU_TYPE_SIZE; - dt_pci_info.tail_size = dt_pci_info.dtc.has_chk ? CHK_SIZE : 0; + dt_pci_info.head_size = dt_pci_info.fd_o + dt_pci_info.fd_size; return 0; } @@ -85,7 +80,6 @@ int dt_pci_ser(struct shm_du_buff * sdb, struct dt_pci * dt_pci) { uint8_t * head; - uint8_t * tail; uint8_t ttl = DEFAULT_TTL; assert(sdb); @@ -96,22 +90,11 @@ int dt_pci_ser(struct shm_du_buff * sdb, return -EPERM; /* FIXME: Add check and operations for Big Endian machines */ - memcpy(head, &dt_pci->dst_addr, dt_pci_info.dtc.addr_size); - memcpy(head + dt_pci_info.qc_o, &dt_pci->qc, QC_SIZE); - if (dt_pci_info.dtc.has_ttl) - memcpy(head + dt_pci_info.ttl_o, &ttl, TTL_SIZE); - memcpy(head + dt_pci_info.fd_o, &dt_pci->fd, PDU_TYPE_SIZE); - - if (dt_pci_info.dtc.has_chk) { - tail = shm_du_buff_tail_alloc(sdb, dt_pci_info.tail_size); - if (tail == NULL) { - shm_du_buff_head_release(sdb, dt_pci_info.head_size); - return -EPERM; - } - - *((uint32_t *) tail) = 0; - crc32((uint32_t *) tail, head, tail - head); - } + memcpy(head, &dt_pci->dst_addr, dt_pci_info.addr_size); + memcpy(head + dt_pci_info.qc_o, &dt_pci->qc, QOS_LEN); + if (dt_pci_info.has_ttl) + memcpy(head + dt_pci_info.ttl_o, &ttl, TTL_LEN); + memcpy(head + dt_pci_info.fd_o, &dt_pci->fd, dt_pci_info.fd_size); return 0; } @@ -127,17 +110,17 @@ void dt_pci_des(struct shm_du_buff * sdb, head = shm_du_buff_head(sdb); /* FIXME: Add check and operations for Big Endian machines */ - memcpy(&dt_pci->dst_addr, head, dt_pci_info.dtc.addr_size); - memcpy(&dt_pci->qc, head + dt_pci_info.qc_o, QC_SIZE); + memcpy(&dt_pci->dst_addr, head, dt_pci_info.addr_size); + memcpy(&dt_pci->qc, head + dt_pci_info.qc_o, QOS_LEN); - if (dt_pci_info.dtc.has_ttl) { + if (dt_pci_info.has_ttl) { --*(head + dt_pci_info.ttl_o); /* decrease TTL */ - memcpy(&dt_pci->ttl, head + dt_pci_info.ttl_o, TTL_SIZE); + memcpy(&dt_pci->ttl, head + dt_pci_info.ttl_o, TTL_LEN); } else { dt_pci->ttl = 1; } - memcpy(&dt_pci->fd, head + dt_pci_info.fd_o, PDU_TYPE_SIZE); + memcpy(&dt_pci->fd, head + dt_pci_info.fd_o, dt_pci_info.fd_size); } void dt_pci_shrink(struct shm_du_buff * sdb) @@ -145,5 +128,4 @@ void dt_pci_shrink(struct shm_du_buff * sdb) assert(sdb); shm_du_buff_head_release(sdb, dt_pci_info.head_size); - shm_du_buff_tail_release(sdb, dt_pci_info.tail_size); } |