summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-24 16:26:40 +0100
committerDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-24 16:26:40 +0100
commitc32ccc39cfc793729890204c8d810eb7608f4474 (patch)
treee01b29ae0ff52d617c656b5d85babd472aaa4149 /src
parent683114204c81a4e989042ee5de12c4fc71fc910c (diff)
parent72abee4fc44e5e5092e215d5afee556e6e59347c (diff)
downloadouroboros-c32ccc39cfc793729890204c8d810eb7608f4474.tar.gz
ouroboros-c32ccc39cfc793729890204c8d810eb7608f4474.zip
Merged in sandervrijders/ouroboros/be-irm-msg (pull request #40)
lib: Adds IRMd messages for the dev.h API calls
Diffstat (limited to 'src')
-rw-r--r--src/irmd/main.c6
-rw-r--r--src/lib/da.c6
-rw-r--r--src/lib/dev.c198
-rw-r--r--src/lib/ipcp.c18
-rw-r--r--src/lib/irm.c41
-rw-r--r--src/lib/rina_name.c61
-rw-r--r--src/lib/sockets.c285
-rw-r--r--src/tools/echo/echo_client.c5
-rw-r--r--src/tools/echo/echo_server.c4
-rw-r--r--src/tools/irm/irm_bootstrap_ipcp.c6
-rw-r--r--src/tools/irm/irm_create_ipcp.c4
-rw-r--r--src/tools/irm/irm_destroy_ipcp.c6
-rw-r--r--src/tools/irm/irm_enroll_ipcp.c4
-rw-r--r--src/tools/irm/irm_register_ipcp.c4
-rw-r--r--src/tools/irm/irm_unregister_ipcp.c4
-rw-r--r--src/tools/irm/irm_utils.c4
16 files changed, 450 insertions, 206 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 99896999..622b367d 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -143,7 +143,7 @@ static void enroll_ipcp(struct irm * instance,
char * dif_name)
{
pid_t pid = 0;
- rina_name_t * member;
+ char * member;
char ** n_1_difs = NULL;
ssize_t n_1_difs_size = 0;
@@ -161,7 +161,7 @@ static void enroll_ipcp(struct irm * instance,
n_1_difs_size = da_resolve_dap(member, n_1_difs);
if (n_1_difs_size != 0)
- if (ipcp_enroll(pid, dif_name, *member,
+ if (ipcp_enroll(pid, dif_name, member,
n_1_difs, n_1_difs_size))
LOG_ERR("Could not enroll IPCP");
}
@@ -231,7 +231,7 @@ int main()
}
count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE);
- if (count) {
+ if (count > 0) {
buffer.size = count;
buffer.data = buf;
msg = deserialize_irm_msg(&buffer);
diff --git a/src/lib/da.c b/src/lib/da.c
index ef59a409..8e7756d1 100644
--- a/src/lib/da.c
+++ b/src/lib/da.c
@@ -22,13 +22,13 @@
#include <ouroboros/da.h>
-rina_name_t * da_resolve_daf(char * daf_name)
+char * da_resolve_daf(char * daf_name)
{
return NULL;
}
-ssize_t da_resolve_dap(rina_name_t * name,
- char ** n_1_difs)
+ssize_t da_resolve_dap(char * name,
+ char ** n_1_difs)
{
return 0;
}
diff --git a/src/lib/dev.c b/src/lib/dev.c
index c072c5ef..7c0c8a15 100644
--- a/src/lib/dev.c
+++ b/src/lib/dev.c
@@ -24,65 +24,205 @@
#include <ouroboros/logs.h>
#include <ouroboros/dev.h>
+#include <ouroboros/sockets.h>
-int ap_reg(char * ap_name, char * ae_name,
- char ** difs, size_t difs_size)
-{
- LOG_MISSING;
+#include <stdlib.h>
- return -1;
+int ap_reg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
+{
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int fd = 0;
+
+ if (ap_name == NULL ||
+ difs == NULL ||
+ difs_size == 0) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_AP_REG;
+ msg.ap_name = ap_name;
+ msg.difs = difs;
+ msg.difs_size = difs_size;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ fd = recv_msg->fd;
+ free(recv_msg);
+
+ return fd;
}
-int ap_unreg(char * ap_name, char * ae_name,
- char ** difs, size_t difs_size)
+int ap_unreg(char * ap_name,
+ char ** difs,
+ size_t difs_size)
{
- LOG_MISSING;
-
- return -1;
+ struct irm_msg msg;
+
+ if (ap_name == NULL ||
+ difs == NULL ||
+ difs_size == 0) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_AP_UNREG;
+ msg.ap_name = ap_name;
+ msg.difs = difs;
+ msg.difs_size = difs_size;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
-int flow_accept(int fd, char * ap_name, char * ae_name)
+int flow_accept(int fd,
+ char * ap_name,
+ char * ae_name)
{
- LOG_MISSING;
-
- return -1;
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int cli_fd = 0;
+
+ if (ap_name == NULL) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_FLOW_ACCEPT;
+ msg.fd = fd;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ cli_fd = recv_msg->fd;
+ ap_name = recv_msg->ap_name;
+ if (ae_name == NULL)
+ ae_name = "";
+ else
+ ae_name = recv_msg->ae_name;
+ free(recv_msg);
+
+ return cli_fd;
}
-int flow_alloc_resp(int fd, int result)
+int flow_alloc_resp(int fd,
+ int result)
{
- LOG_MISSING;
+ struct irm_msg msg;
- return -1;
+ msg.code = IRM_FLOW_ALLOC_RESP;
+ msg.fd = fd;
+ msg.result = result;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
-int flow_alloc(char * dst_ap_name, char * dst_ae_name,
- char * src_ap_name, char * src_ae_name,
- struct qos_spec * qos, int oflags)
+int flow_alloc(char * dst_ap_name,
+ char * src_ap_name,
+ char * src_ae_name,
+ struct qos_spec * qos,
+ int oflags)
{
- LOG_MISSING;
-
- return -1;
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int fd = 0;
+
+ if (dst_ap_name == NULL ||
+ src_ap_name == NULL) {
+ LOG_ERR("Invalid arguments");
+ return -1;
+ }
+
+ msg.code = IRM_FLOW_ALLOC;
+ msg.dst_ap_name = dst_ap_name;
+ msg.ap_name = src_ap_name;
+ if (src_ae_name == NULL)
+ msg.ae_name = "";
+ else
+ msg.ae_name = src_ae_name;
+ msg.qos = qos;
+ msg.oflags = oflags;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ fd = recv_msg->fd;
+ free(recv_msg);
+
+ return fd;
}
int flow_alloc_res(int fd)
{
- LOG_MISSING;
+ struct irm_msg msg;
+ struct irm_msg * recv_msg = NULL;
+ int result = 0;
- return -1;
+ msg.code = IRM_FLOW_ALLOC_RES;
+ msg.fd = fd;
+
+ recv_msg = send_recv_irmd_msg(&msg);
+ if (recv_msg == NULL) {
+ LOG_ERR("Failed to send and receive message");
+ return -1;
+ }
+
+ result = recv_msg->result;
+ free(recv_msg);
+
+ return result;
}
int flow_dealloc(int fd)
{
- LOG_MISSING;
+ struct irm_msg msg;
- return -1;
+ msg.code = IRM_FLOW_DEALLOC;
+ msg.fd = fd;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
int flow_cntl(int fd, int oflags)
{
- LOG_MISSING;
+ struct irm_msg msg;
- return -1;
+ msg.fd = fd;
+ msg.oflags = oflags;
+
+ if (send_irmd_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
+
+ return 0;
}
ssize_t flow_write(int fd,
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 6bc3c75f..53d717ba 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -83,7 +83,6 @@ pid_t ipcp_create(rina_name_t name,
{
pid_t pid = 0;
char * api_id = NULL;
- char * aei_id = NULL;
size_t len = 0;
char * ipcp_dir = "bin/ipcpd";
char * full_name = NULL;
@@ -108,22 +107,13 @@ pid_t ipcp_create(rina_name_t name,
}
sprintf(api_id, "%d", name.api_id);
- aei_id = malloc(n_digits(name.aei_id) + 1);
- if (!aei_id) {
- LOG_ERR("Failed to malloc");
- free(api_id);
- exit(EXIT_FAILURE);
- }
- sprintf(aei_id, "%d", name.aei_id);
-
len += strlen(INSTALL_DIR);
len += strlen(ipcp_dir);
len += 2;
full_name = malloc(len);
- if (!full_name) {
+ if (full_name == NULL) {
LOG_ERR("Failed to malloc");
free(api_id);
- free(aei_id);
exit(EXIT_FAILURE);
}
@@ -133,7 +123,6 @@ pid_t ipcp_create(rina_name_t name,
char * argv[] = {full_name,
name.ap_name, api_id,
- name.ae_name, aei_id,
ipcp_type, 0};
char * envp[] = {0};
@@ -144,7 +133,6 @@ pid_t ipcp_create(rina_name_t name,
LOG_ERR("Failed to load IPCP daemon");
LOG_ERR("Make sure to run the installed version");
free(api_id);
- free(aei_id);
free(full_name);
exit(EXIT_FAILURE);
}
@@ -226,7 +214,7 @@ int ipcp_bootstrap(pid_t pid,
int ipcp_enroll(pid_t pid,
char * dif_name,
- rina_name_t member,
+ char * member_name,
char ** n_1_difs,
ssize_t n_1_difs_size)
{
@@ -240,7 +228,7 @@ int ipcp_enroll(pid_t pid,
msg.code = IPCP_ENROLL;
msg.dif_name = dif_name;
- msg.member = &member;
+ msg.ap_name = member_name;
msg.difs = n_1_difs;
msg.difs_size = n_1_difs_size;
diff --git a/src/lib/irm.c b/src/lib/irm.c
index e4804074..9fd13d52 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -28,35 +28,6 @@
#include <ouroboros/sockets.h>
#include <stdlib.h>
-static int send_irm_msg(struct irm_msg * msg)
-{
- int sockfd;
- buffer_t * buf;
-
- sockfd = client_socket_open(IRM_SOCK_PATH);
- if (sockfd < 0)
- return -1;
-
- buf = serialize_irm_msg(msg);
- if (buf == NULL) {
- close(sockfd);
- return -1;
- }
-
- if (write(sockfd, buf->data, buf->size) == -1) {
- free(buf->data);
- free(buf);
- close(sockfd);
- return -1;
- }
-
- free(buf->data);
- free(buf);
-
- close(sockfd);
- return 0;
-}
-
int irm_create_ipcp(rina_name_t name,
char * ipcp_type)
{
@@ -74,7 +45,7 @@ int irm_create_ipcp(rina_name_t name,
msg.name = &name;
msg.ipcp_type = ipcp_type;
- if (send_irm_msg(&msg)) {
+ if (send_irmd_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -94,7 +65,7 @@ int irm_destroy_ipcp(rina_name_t name)
msg.code = IRM_DESTROY_IPCP;
msg.name = &name;
- if (send_irm_msg(&msg)) {
+ if (send_irmd_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -116,7 +87,7 @@ int irm_bootstrap_ipcp(rina_name_t name,
msg.name = &name;
msg.conf = &conf;
- if (send_irm_msg(&msg)) {
+ if (send_irmd_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -138,7 +109,7 @@ int irm_enroll_ipcp(rina_name_t name,
msg.name = &name;
msg.dif_name = dif_name;
- if (send_irm_msg(&msg)) {
+ if (send_irmd_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -162,7 +133,7 @@ int irm_reg_ipcp(rina_name_t name,
msg.difs = difs;
msg.difs_size = difs_size;
- if (send_irm_msg(&msg)) {
+ if (send_irmd_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
@@ -186,7 +157,7 @@ int irm_unreg_ipcp(rina_name_t name,
msg.difs = difs;
msg.difs_size = difs_size;
- if (send_irm_msg(&msg)) {
+ if (send_irmd_msg(&msg)) {
LOG_ERR("Failed to send message to daemon");
return -1;
}
diff --git a/src/lib/rina_name.c b/src/lib/rina_name.c
index 471f6fda..2dcfbb08 100644
--- a/src/lib/rina_name.c
+++ b/src/lib/rina_name.c
@@ -58,17 +58,13 @@ rina_name_t * name_create()
tmp->ap_name = NULL;
tmp->api_id = 0;
- tmp->ae_name = NULL;
- tmp->aei_id = 0;
return tmp;
}
rina_name_t * name_init_from(rina_name_t * dst,
const char * ap_name,
- unsigned int api_id,
- const char * ae_name,
- unsigned int aei_id)
+ unsigned int api_id)
{
if (dst == NULL)
return NULL;
@@ -78,11 +74,8 @@ rina_name_t * name_init_from(rina_name_t * dst,
dst->ap_name = strdup(ap_name);
dst->api_id = api_id;
- dst->ae_name = strdup(ae_name);
- dst->aei_id = aei_id;
- if (dst->ap_name == NULL ||
- dst->ae_name == NULL) {
+ if (dst->ap_name == NULL) {
name_fini(dst);
return NULL;
}
@@ -92,9 +85,7 @@ rina_name_t * name_init_from(rina_name_t * dst,
rina_name_t * name_init_with(rina_name_t * dst,
char * ap_name,
- unsigned int api_id,
- char * ae_name,
- unsigned int aei_id)
+ unsigned int api_id)
{
if (dst == NULL)
return NULL;
@@ -104,8 +95,6 @@ rina_name_t * name_init_with(rina_name_t * dst,
dst->ap_name = ap_name;
dst->api_id = api_id;
- dst->ae_name = ae_name;
- dst->aei_id = aei_id;
return dst;
}
@@ -119,11 +108,6 @@ void name_fini(rina_name_t * n)
free(n->ap_name);
n->ap_name = NULL;
}
-
- if (n->ae_name != NULL) {
- free(n->ae_name);
- n->ae_name = NULL;
- }
}
void name_destroy(rina_name_t * ptr)
@@ -146,9 +130,7 @@ int name_cpy(const rina_name_t * src,
res = name_init_from(dst,
src->ap_name,
- src->api_id,
- src->ae_name,
- src->aei_id);
+ src->api_id);
if (res == NULL)
return -1;
@@ -182,8 +164,7 @@ rina_name_t * name_dup(const rina_name_t * src)
bool name_is_ok(const rina_name_t * n)
{ return (n != NULL &&
n->ap_name != NULL &&
- strlen(n->ap_name) &&
- n->ae_name != NULL); }
+ strlen(n->ap_name)); }
bool name_cmp(uint8_t flags,
const rina_name_t * a,
@@ -206,14 +187,6 @@ bool name_cmp(uint8_t flags,
if (a->api_id != b->api_id)
return false;
- if (flags & NAME_CMP_AEN)
- if (NAME_CMP_FIELD(a, b, ae_name))
- return false;
-
- if (flags & NAME_CMP_AEI)
- if (a->aei_id != b->aei_id)
- return false;
-
return true;
}
@@ -243,23 +216,13 @@ char * name_to_string(const rina_name_t * n)
1 : n_digits(n->api_id));
size += strlen(DELIMITER);
- size += (n->ae_name != NULL ?
- strlen(n->ae_name) : none_len);
- size += strlen(DELIMITER);
-
- size += (n->aei_id == 0 ?
- 1 : n_digits(n->aei_id));
- size += strlen(DELIMITER);
-
tmp = malloc(size);
if (!tmp)
return NULL;
- if (sprintf(tmp, "%s%s%d%s%s%s%d",
+ if (sprintf(tmp, "%s%s%d",
(n->ap_name != NULL ? n->ap_name : none),
- DELIMITER, n->api_id,
- DELIMITER, (n->ae_name != NULL ? n->ae_name : none),
- DELIMITER, n->aei_id)
+ DELIMITER, n->api_id)
!= size - 1) {
free(tmp);
return NULL;
@@ -276,9 +239,6 @@ rina_name_t * string_to_name(const char * s)
char * tmp_ap = NULL;
char * tmp_s_api = NULL;
unsigned int tmp_api = 0;
- char * tmp_ae = NULL;
- char * tmp_s_aei = NULL;
- unsigned int tmp_aei = 0;
char * tmp2;
if (s == NULL)
@@ -293,10 +253,6 @@ rina_name_t * string_to_name(const char * s)
tmp_s_api = strtok(NULL, DELIMITER);
if (tmp_s_api != NULL)
tmp_api = (unsigned int) strtol(tmp_s_api, &tmp2, 10);
- tmp_ae = strtok(NULL, DELIMITER);
- tmp_s_aei = strtok(NULL, DELIMITER);
- if (tmp_s_aei != NULL)
- tmp_aei = (unsigned int) strtol(tmp_s_aei, &tmp2, 10);
name = name_create();
if (name == NULL) {
@@ -305,8 +261,7 @@ rina_name_t * string_to_name(const char * s)
return NULL;
}
- if (!name_init_from(name, tmp_ap, tmp_api,
- tmp_ae, tmp_aei)) {
+ if (!name_init_from(name, tmp_ap, tmp_api)) {
name_destroy(name);
if (tmp1 != NULL)
free(tmp1);
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index 425d0354..b157b628 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -96,6 +96,76 @@ int server_socket_open(char * file_name)
return sockfd;
}
+int send_irmd_msg(struct irm_msg * msg)
+{
+ int sockfd;
+ buffer_t * buf;
+
+ sockfd = client_socket_open(IRM_SOCK_PATH);
+ if (sockfd < 0)
+ return -1;
+
+ buf = serialize_irm_msg(msg);
+ if (buf == NULL) {
+ close(sockfd);
+ return -1;
+ }
+
+ if (write(sockfd, buf->data, buf->size) == -1) {
+ free(buf->data);
+ free(buf);
+ close(sockfd);
+ return -1;
+ }
+
+ free(buf->data);
+ free(buf);
+
+ close(sockfd);
+ return 0;
+}
+
+struct irm_msg * send_recv_irmd_msg(struct irm_msg * msg)
+{
+ int sockfd;
+ buffer_t * buf;
+ ssize_t count = 0;
+ struct irm_msg * recv_msg = NULL;
+
+ sockfd = client_socket_open(IRM_SOCK_PATH);
+ if (sockfd < 0)
+ return NULL;
+
+ buf = serialize_irm_msg(msg);
+ if (buf == NULL) {
+ close(sockfd);
+ return NULL;
+ }
+
+ if (write(sockfd, buf->data, buf->size) == -1) {
+ free(buf->data);
+ free(buf);
+ close(sockfd);
+ return NULL;
+ }
+
+ count = read(sockfd, buf->data, IRM_MSG_BUF_SIZE);
+ if (count <= 0) {
+ free(buf->data);
+ free(buf);
+ close(sockfd);
+ return NULL;
+ }
+
+ recv_msg = deserialize_irm_msg(buf);
+
+ free(buf->data);
+ free(buf);
+
+ close(sockfd);
+ return recv_msg;
+}
+
char * ipcp_sock_path(pid_t pid)
{
char * full_name = NULL;
@@ -154,10 +224,6 @@ static void ser_copy_name(rina_name_t * name,
data, name->ap_name, offset);
ser_copy_value(sizeof(int), data,
&name->api_id, offset);
- ser_copy_value(strlen(name->ae_name) + 1,
- data, name->ae_name, offset);
- ser_copy_value(sizeof(int), data,
- &name->aei_id, offset);
}
static void deser_copy_value(size_t flen,
@@ -217,13 +283,6 @@ static rina_name_t * deser_copy_name(uint8_t * data,
deser_copy_int(data, &name->api_id, offset);
- if (deser_copy_string(data, &name->ae_name, offset)) {
- name_destroy(name);
- return NULL;
- }
-
- deser_copy_int(data, &name->aei_id, offset);
-
return name;
}
@@ -274,46 +333,82 @@ buffer_t * serialize_irm_msg(struct irm_msg * msg)
ser_copy_value(sizeof(enum irm_msg_code), data, &msg->code, &offset);
- if (!name_is_ok(msg->name)) {
- LOG_ERR("Null pointer passed");
- buffer_destroy(buf);
- return NULL;
- }
ser_copy_name(msg->name, data, &offset);
switch (msg->code) {
case IRM_CREATE_IPCP:
- if (!msg->ipcp_type) {
+ if (msg->ipcp_type == NULL ||
+ !name_is_ok(msg->name)) {
LOG_ERR("Null pointer passed");
buffer_destroy(buf);
return NULL;
}
-
+ ser_copy_name(msg->name, data, &offset);
ser_copy_value(strlen(msg->ipcp_type) + 1, data,
msg->ipcp_type, &offset);
break;
case IRM_DESTROY_IPCP:
+ if (!name_is_ok(msg->name)) {
+ LOG_ERR("Null pointer passed");
+ buffer_destroy(buf);
+ return NULL;
+ }
+ ser_copy_name(msg->name, data, &offset);
break;
case IRM_BOOTSTRAP_IPCP:
+ if (!name_is_ok(msg->name)) {
+ LOG_ERR("Null pointer passed");
+ buffer_destroy(buf);
+ return NULL;
+ }
+ ser_copy_name(msg->name, data, &offset);
/* FIXME: Fields missing, need to define dif_conf properly */
break;
case IRM_ENROLL_IPCP:
- if (msg->dif_name == NULL) {
+ if (msg->dif_name == NULL ||
+ !name_is_ok(msg->name)) {
buffer_destroy(buf);
return NULL;
}
+ ser_copy_name(msg->name, data, &offset);
ser_copy_value(strlen(msg->dif_name) + 1, data,
msg->dif_name, &offset);
break;
case IRM_REG_IPCP:
case IRM_UNREG_IPCP:
- if (msg->difs == NULL || msg->difs[0] == NULL) {
+ if (msg->difs == NULL ||
+ msg->difs[0] == NULL ||
+ !name_is_ok(msg->name)) {
buffer_destroy(buf);
return NULL;
}
+ ser_copy_name(msg->name, data, &offset);
+
+ ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset);
+
+ pos = msg->difs;
+ for (i = 0; i < msg->difs_size; i++) {
+ ser_copy_value(strlen(*pos) + 1, data, *pos, &offset);
+ pos++;
+ }
+
+ break;
+ case IRM_AP_REG:
+ case IRM_AP_UNREG:
+ if (msg->ap_name == NULL ||
+ msg->difs == NULL ||
+ msg->difs[0] == NULL) {
+ LOG_ERR("Invalid arguments");
+ buffer_destroy(buf);
+ return NULL;
+ }
+
+ ser_copy_value(strlen(msg->ap_name) + 1,
+ data, msg->ap_name, &offset);
+
ser_copy_value(sizeof(size_t), data, &msg->difs_size, &offset);
pos = msg->difs;
@@ -323,6 +418,83 @@ buffer_t * serialize_irm_msg(struct irm_msg * msg)
}
break;
+ case IRM_FLOW_ACCEPT:
+ if (msg->ap_name == NULL ||
+ msg->ae_name == NULL) {
+ LOG_ERR("Invalid arguments");
+ buffer_destroy(buf);
+ return NULL;
+ }
+
+ ser_copy_value(sizeof(int), data, &msg->fd, &offset);
+
+ ser_copy_value(strlen(msg->ap_name) + 1,
+ data, msg->ap_name, &offset);
+
+ ser_copy_value(strlen(msg->ae_name) + 1,
+ data, msg->ae_name, &offset);
+
+ break;
+ case IRM_FLOW_ALLOC_RESP:
+ ser_copy_value(sizeof(int), data, &msg->fd, &offset);
+
+ ser_copy_value(sizeof(int), data, &msg->result, &offset);
+
+ break;
+ case IRM_FLOW_ALLOC:
+ if (msg->ap_name == NULL ||
+ msg->ae_name == NULL ||
+ msg->dst_ap_name == NULL ||
+ msg->qos == NULL) {
+ LOG_ERR("Invalid arguments");
+ buffer_destroy(buf);
+ return NULL;
+ }
+
+ ser_copy_value(strlen(msg->dst_ap_name) + 1,
+ data, msg->dst_ap_name, &offset);
+
+ ser_copy_value(strlen(msg->ap_name) + 1,
+ data, msg->ap_name, &offset);
+
+ ser_copy_value(strlen(msg->ae_name) + 1,
+ data, msg->ae_name, &offset);
+
+ /* FIXME: Serialize qos spec here */
+
+ ser_copy_value(sizeof(int), data, &msg->oflags, &offset);
+
+ break;
+ case IRM_FLOW_ALLOC_RES:
+ case IRM_FLOW_DEALLOC:
+ ser_copy_value(sizeof(int), data, &msg->fd, &offset);
+ break;
+ case IRM_FLOW_CONTROL:
+ ser_copy_value(sizeof(int), data, &msg->fd, &offset);
+ ser_copy_value(sizeof(int), data, &msg->oflags, &offset);
+ break;
+ case IRM_FLOW_WRITE:
+ LOG_MISSING;
+ break;
+ case IRM_FLOW_READ:
+ LOG_MISSING;
+ break;
+ case IRM_AP_REG_R:
+ case IRM_FLOW_ALLOC_R:
+ ser_copy_value(sizeof(int), data, &msg->fd, &offset);
+ break;
+ case IRM_FLOW_ACCEPT_R:
+ ser_copy_value(sizeof(int), data, &msg->fd, &offset);
+
+ ser_copy_value(strlen(msg->ap_name) + 1,
+ data, msg->ap_name, &offset);
+
+ ser_copy_value(strlen(msg->ae_name) + 1,
+ data, msg->ae_name, &offset);
+ break;
+ case IRM_FLOW_ALLOC_RES_R:
+ ser_copy_value(sizeof(int), data, &msg->result, &offset);
+ break;
default:
LOG_ERR("Don't know that code");
buffer_destroy(buf);
@@ -355,15 +527,15 @@ struct irm_msg * deserialize_irm_msg(buffer_t * data)
deser_copy_value(sizeof(enum irm_msg_code),
&msg->code, data->data, &offset);
- msg->name = deser_copy_name(data->data, &offset);
- if (msg->name == NULL) {
- LOG_ERR("Failed to reconstruct name");
- free(msg);
- return NULL;
- }
-
switch (msg->code) {
case IRM_CREATE_IPCP:
+ msg->name = deser_copy_name(data->data, &offset);
+ if (msg->name == NULL) {
+ LOG_ERR("Failed to reconstruct name");
+ free(msg);
+ return NULL;
+ }
+
if (deser_copy_string(data->data,
&msg->ipcp_type,
&offset)) {
@@ -374,10 +546,31 @@ struct irm_msg * deserialize_irm_msg(buffer_t * data)
break;
case IRM_DESTROY_IPCP:
+ msg->name = deser_copy_name(data->data, &offset);
+ if (msg->name == NULL) {
+ LOG_ERR("Failed to reconstruct name");
+ free(msg);
+ return NULL;
+ }
+
break;
case IRM_BOOTSTRAP_IPCP:
+ msg->name = deser_copy_name(data->data, &offset);
+ if (msg->name == NULL) {
+ LOG_ERR("Failed to reconstruct name");
+ free(msg);
+ return NULL;
+ }
+
break;
case IRM_ENROLL_IPCP:
+ msg->name = deser_copy_name(data->data, &offset);
+ if (msg->name == NULL) {
+ LOG_ERR("Failed to reconstruct name");
+ free(msg);
+ return NULL;
+ }
+
if (deser_copy_string(data->data,
&msg->dif_name,
&offset)) {
@@ -389,6 +582,13 @@ struct irm_msg * deserialize_irm_msg(buffer_t * data)
break;
case IRM_REG_IPCP:
case IRM_UNREG_IPCP:
+ msg->name = deser_copy_name(data->data, &offset);
+ if (msg->name == NULL) {
+ LOG_ERR("Failed to reconstruct name");
+ free(msg);
+ return NULL;
+ }
+
deser_copy_size_t(data->data, &difs_size, &offset);
msg->difs_size = difs_size;
@@ -413,6 +613,22 @@ struct irm_msg * deserialize_irm_msg(buffer_t * data)
}
break;
+ case IRM_AP_REG:
+ case IRM_AP_REG_R:
+ case IRM_AP_UNREG:
+ case IRM_FLOW_ACCEPT:
+ case IRM_FLOW_ACCEPT_R:
+ case IRM_FLOW_ALLOC_RESP:
+ case IRM_FLOW_ALLOC:
+ case IRM_FLOW_ALLOC_R:
+ case IRM_FLOW_ALLOC_RES:
+ case IRM_FLOW_ALLOC_RES_R:
+ case IRM_FLOW_DEALLOC:
+ case IRM_FLOW_CONTROL:
+ case IRM_FLOW_WRITE:
+ case IRM_FLOW_READ:
+ LOG_MISSING;
+ break;
default:
LOG_ERR("Don't know that code");
free(msg);
@@ -454,12 +670,13 @@ buffer_t * serialize_ipcp_msg(struct ipcp_msg * msg)
ser_copy_value(strlen(msg->dif_name) + 1, data,
msg->dif_name, &offset);
- if (!name_is_ok(msg->member)) {
+ if (msg->ap_name == NULL) {
LOG_ERR("Null pointer passed");
buffer_destroy(buf);
return NULL;
}
- ser_copy_name(msg->member, data, &offset);
+ ser_copy_value(strlen(msg->ap_name) + 1, data,
+ msg->ap_name, &offset);
/* All these operations end with a list of DIFs */
case IPCP_REG:
@@ -520,8 +737,10 @@ struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data)
return NULL;
}
- msg->member = deser_copy_name(data->data, &offset);
- if (msg->member == NULL) {
+ deser_copy_string(data->data,
+ &msg->ap_name,
+ &offset);
+ if (msg->ap_name == NULL) {
LOG_ERR("Failed to reconstruct name");
free(msg->dif_name);
free(msg);
@@ -533,8 +752,8 @@ struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data)
msg->difs = malloc(sizeof(*(msg->difs)) * difs_size);
if (msg->difs == NULL) {
+ free(msg->ap_name);
free(msg->dif_name);
- name_destroy(msg->member);
free(msg);
return NULL;
}
@@ -547,7 +766,7 @@ struct ipcp_msg * deserialize_ipcp_msg(buffer_t * data)
free(msg->difs[j]);
free(msg->dif_name);
free(msg->difs);
- name_destroy(msg->member);
+ free(msg->ap_name);
free(msg);
return NULL;
}
diff --git a/src/tools/echo/echo_client.c b/src/tools/echo/echo_client.c
index 2f80a52a..196296f2 100644
--- a/src/tools/echo/echo_client.c
+++ b/src/tools/echo/echo_client.c
@@ -33,9 +33,8 @@ int client_main()
char * message = "Client says hi!";
ssize_t count = 0;
- fd = flow_alloc(SERVER_AP_NAME, NULL,
- CLIENT_AP_NAME, NULL,
- NULL, 0);
+ fd = flow_alloc(SERVER_AP_NAME, CLIENT_AP_NAME,
+ NULL, NULL, 0);
if (fd < 0) {
printf("Failed to allocate flow\n");
return -1;
diff --git a/src/tools/echo/echo_server.c b/src/tools/echo/echo_server.c
index f9682ab7..289f537a 100644
--- a/src/tools/echo/echo_server.c
+++ b/src/tools/echo/echo_server.c
@@ -34,7 +34,7 @@ void shutdown_server(int signo)
{
char * dif = DIF_NAME;
- if (ap_unreg(SERVER_AP_NAME, NULL, &dif, 1)) {
+ if (ap_unreg(SERVER_AP_NAME, &dif, 1)) {
printf("Failed to unregister application\n");
exit(EXIT_FAILURE);
}
@@ -59,7 +59,7 @@ int server_main()
return -1;
}
- server_fd = ap_reg(SERVER_AP_NAME, NULL, &dif, 1);
+ server_fd = ap_reg(SERVER_AP_NAME, &dif, 1);
if (server_fd < 0) {
printf("Failed to register application\n");
return -1;
diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c
index 8c64ba8f..89950069 100644
--- a/src/tools/irm/irm_bootstrap_ipcp.c
+++ b/src/tools/irm/irm_bootstrap_ipcp.c
@@ -32,9 +32,7 @@ static void usage()
/* FIXME: Add dif_config stuff */
printf("Usage: irm bootstrap_ipcp\n"
" ap <application process name>\n"
- " [api <application process instance>]\n"
- " [ae <application entity name]\n"
- " [aei <application entity instance>]\n");
+ " [api <application process instance>]\n");
}
@@ -47,8 +45,6 @@ int do_bootstrap_ipcp(int argc, char ** argv)
name.ap_name = NULL;
name.api_id = 0;
- name.ae_name = "";
- name.aei_id = 0;
while (argc > 0) {
if (!parse_name(argv, &name)) {
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
index 5c847988..854a15f9 100644
--- a/src/tools/irm/irm_create_ipcp.c
+++ b/src/tools/irm/irm_create_ipcp.c
@@ -35,8 +35,6 @@ static void usage()
printf("Usage: irm create_ipcp\n"
" ap <application process name>\n"
" [api <application process instance>]\n"
- " [ae <application entity name]\n"
- " [aei <application entity instance>]\n"
" type <ipc process type>\n");
}
@@ -47,8 +45,6 @@ int do_create_ipcp(int argc, char ** argv)
name.ap_name = NULL;
name.api_id = 0;
- name.ae_name = "";
- name.aei_id = 0;
while (argc > 0) {
if (!parse_name(argv, &name)) {
diff --git a/src/tools/irm/irm_destroy_ipcp.c b/src/tools/irm/irm_destroy_ipcp.c
index 467d1b50..4f02f9cb 100644
--- a/src/tools/irm/irm_destroy_ipcp.c
+++ b/src/tools/irm/irm_destroy_ipcp.c
@@ -31,9 +31,7 @@ static void usage()
{
printf("Usage: irm destroy_ipcp\n"
" ap <application process name>\n"
- " [api <application process instance>]\n"
- " [ae <application entity name]\n"
- " [aei <application entity instance>]\n");
+ " [api <application process instance>]\n");
}
int do_destroy_ipcp(int argc, char ** argv)
@@ -42,8 +40,6 @@ int do_destroy_ipcp(int argc, char ** argv)
name.ap_name = NULL;
name.api_id = 0;
- name.ae_name = "";
- name.aei_id = 0;
while (argc > 0) {
if (!parse_name(argv, &name)) {
diff --git a/src/tools/irm/irm_enroll_ipcp.c b/src/tools/irm/irm_enroll_ipcp.c
index 94f28f82..1dcdc919 100644
--- a/src/tools/irm/irm_enroll_ipcp.c
+++ b/src/tools/irm/irm_enroll_ipcp.c
@@ -32,8 +32,6 @@ static void usage()
printf("Usage: irm enroll_ipcp\n"
" ap <application process name>\n"
" [api <application process instance>]\n"
- " [ae <application entity name]\n"
- " [aei <application entity instance>]\n"
" dif <dif to enroll in>\n");
}
@@ -44,8 +42,6 @@ int do_enroll_ipcp(int argc, char ** argv)
name.ap_name = NULL;
name.api_id = 0;
- name.ae_name = "";
- name.aei_id = 0;
while (argc > 0) {
if (!parse_name(argv, &name)) {
diff --git a/src/tools/irm/irm_register_ipcp.c b/src/tools/irm/irm_register_ipcp.c
index c69ad350..468ef28f 100644
--- a/src/tools/irm/irm_register_ipcp.c
+++ b/src/tools/irm/irm_register_ipcp.c
@@ -37,8 +37,6 @@ static void usage()
printf("Usage: irm register_ipcp\n"
" ap <application process name>\n"
" [api <application process instance>]\n"
- " [ae <application entity name]\n"
- " [aei <application entity instance>]\n"
" dif <dif name to register with>\n"
" [dif <dif name to register with>]\n"
" [... (maximum %d difs)]\n", MAX_DIFS);
@@ -53,8 +51,6 @@ int do_register_ipcp(int argc, char ** argv)
name.ap_name = NULL;
name.api_id = 0;
- name.ae_name = "";
- name.aei_id = 0;
while (argc > 0) {
if (!parse_name(argv, &name)) {
diff --git a/src/tools/irm/irm_unregister_ipcp.c b/src/tools/irm/irm_unregister_ipcp.c
index a2dffc6c..0b669503 100644
--- a/src/tools/irm/irm_unregister_ipcp.c
+++ b/src/tools/irm/irm_unregister_ipcp.c
@@ -37,8 +37,6 @@ static void usage()
printf("Usage: irm unregister_ipcp\n"
" ap <application process name>\n"
" [api <application process instance>]\n"
- " [ae <application entity name]\n"
- " [aei <application entity instance>]\n"
" dif <dif name to unregister from>\n"
" [dif <dif name to unregister from>]\n"
" [... (maximum %d difs)]\n", MAX_DIFS);
@@ -53,8 +51,6 @@ int do_unregister_ipcp(int argc, char ** argv)
name.ap_name = NULL;
name.api_id = 0;
- name.ae_name = "";
- name.aei_id = 0;
while (argc > 0) {
if (!parse_name(argv, &name)) {
diff --git a/src/tools/irm/irm_utils.c b/src/tools/irm/irm_utils.c
index 021227fd..04cb7242 100644
--- a/src/tools/irm/irm_utils.c
+++ b/src/tools/irm/irm_utils.c
@@ -47,10 +47,6 @@ bool parse_name(char ** argv,
name->ap_name = *(argv + 1);
else if (matches(*argv, "api") == 0)
name->api_id = atoi(*(argv + 1));
- else if (matches(*argv, "ae") == 0)
- name->ae_name = *(argv + 1);
- else if (matches(*argv, "aei") == 0)
- name->aei_id = atoi(*(argv + 1));
else
found = false;