summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-01 16:02:42 +0100
committerDimitri Staessens <dimitri.staessens@intec.ugent.be>2016-03-01 16:02:42 +0100
commit7360b2c459ab31339aad20dbb438247aff088fd7 (patch)
treec449c27e62bb484e5f87272c37944615616c26b3
parent687055e46ddff677000d7e4e15c21ef9a1809b4d (diff)
parent52a5113760802e16b07d9d954237871d52cff70a (diff)
downloadouroboros-7360b2c459ab31339aad20dbb438247aff088fd7.tar.gz
ouroboros-7360b2c459ab31339aad20dbb438247aff088fd7.zip
Merge branch 'be' of bitbucket.org:ouroboros-rina/ouroboros into be-common
-rw-r--r--include/ouroboros/irm.h19
-rw-r--r--include/ouroboros/sockets.h16
-rw-r--r--src/irmd/main.c62
-rw-r--r--src/lib/irm.c116
-rw-r--r--src/lib/sockets.c228
-rw-r--r--src/tools/irm/main.c28
6 files changed, 329 insertions, 140 deletions
diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h
index 954e4b2d..819675d1 100644
--- a/include/ouroboros/irm.h
+++ b/include/ouroboros/irm.h
@@ -27,19 +27,18 @@
int irm_create_ipcp(rina_name_t name,
char * ipcp_type);
-int irm_destroy_ipcp(int ipcp_id);
+int irm_destroy_ipcp(rina_name_t name);
-int irm_bootstrap_ipcp(int ipcp_id,
+int irm_bootstrap_ipcp(rina_name_t name,
struct dif_info info);
-int irm_enroll_ipcp(int ipcp_id,
+int irm_enroll_ipcp(rina_name_t name,
char * dif_name);
-int irm_reg_ipcp(int ipcp_id,
- char ** difs);
-int irm_unreg_ipcp(int ipcp_id,
- char ** difs);
-
-char ** irm_list_ipcps();
-char ** irm_list_ipcp_types();
+int irm_reg_ipcp(rina_name_t name,
+ char ** difs,
+ size_t difs_size);
+int irm_unreg_ipcp(rina_name_t name,
+ char ** difs,
+ size_t difs_size);
#endif
diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h
index fe7ddb28..88e9564b 100644
--- a/include/ouroboros/sockets.h
+++ b/include/ouroboros/sockets.h
@@ -24,6 +24,7 @@
#define OUROBOROS_SOCKETS_H
#define IRM_SOCK_PATH "/tmp/irm_sock"
+#define IRM_MSG_BUF_SIZE 256
enum irm_msg_code {
IRM_CREATE_IPCP,
@@ -31,18 +32,17 @@ enum irm_msg_code {
IRM_BOOTSTRAP_IPCP,
IRM_ENROLL_IPCP,
IRM_REG_IPCP,
- IRM_UNREG_IPCP,
- IRM_LIST_IPCPS
+ IRM_UNREG_IPCP
};
struct irm_msg {
enum irm_msg_code code;
- union {
- struct {
- rina_name_t * name;
- char * ipcp_type;
- } create_ipcp;
- } msgs;
+ rina_name_t * name;
+ char * ipcp_type;
+ struct dif_info * info;
+ char * dif_name;
+ char ** difs;
+ size_t difs_size;
};
int client_socket_open(char * file_name);
diff --git a/src/irmd/main.c b/src/irmd/main.c
index 137b2b61..73533ef0 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -31,9 +31,6 @@
#include <stdlib.h>
#include <errno.h>
-#define BUF_SIZE 256
-
-
static void create_ipcp(rina_name_t * name,
char * ipcp_type)
{
@@ -47,6 +44,37 @@ static void create_ipcp(rina_name_t * name,
LOG_MISSING;
}
+static void destroy_ipcp(rina_name_t * name)
+{
+ LOG_MISSING;
+}
+
+static void bootstrap_ipcp(rina_name_t * name,
+ struct dif_info * info)
+{
+ LOG_MISSING;
+}
+
+static void enroll_ipcp(rina_name_t * name,
+ char * dif_name)
+{
+ LOG_MISSING;
+}
+
+static void reg_ipcp(rina_name_t * name,
+ char ** difs,
+ size_t difs_size)
+{
+ LOG_MISSING;
+}
+
+static void unreg_ipcp(rina_name_t * name,
+ char ** difs,
+ size_t difs_size)
+{
+ LOG_MISSING;
+}
+
int main()
{
int sockfd;
@@ -56,7 +84,7 @@ int main()
if (sockfd < 0)
return -1;
- buf = malloc(sizeof(*buf) * BUF_SIZE);
+ buf = malloc(sizeof(*buf) * IRM_MSG_BUF_SIZE);
if (buf == NULL) {
LOG_ERR("Cannot allocate memory");
return -ENOMEM;
@@ -74,7 +102,7 @@ int main()
continue;
}
- count = read(cli_sockfd, buf, BUF_SIZE);
+ count = read(cli_sockfd, buf, IRM_MSG_BUF_SIZE);
if (count) {
buffer.size = count;
buffer.data = buf;
@@ -85,8 +113,28 @@ int main()
LOG_DBG("Got message code %d", msg->code);
switch (msg->code) {
case IRM_CREATE_IPCP:
- create_ipcp(msg->msgs.create_ipcp.name,
- msg->msgs.create_ipcp.ipcp_type);
+ create_ipcp(msg->name, msg->ipcp_type);
+ break;
+ case IRM_DESTROY_IPCP:
+ destroy_ipcp(msg->name);
+ break;
+ case IRM_BOOTSTRAP_IPCP:
+ bootstrap_ipcp(msg->name,
+ msg->info);
+ break;
+ case IRM_ENROLL_IPCP:
+ enroll_ipcp(msg->name,
+ msg->dif_name);
+ break;
+ case IRM_REG_IPCP:
+ reg_ipcp(msg->name,
+ msg->difs,
+ msg->difs_size);
+ break;
+ case IRM_UNREG_IPCP:
+ unreg_ipcp(msg->name,
+ msg->difs,
+ msg->difs_size);
break;
default:
LOG_ERR("Don't know that message code");
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 69a98039..97000029 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -27,81 +27,133 @@
#include <ouroboros/logs.h>
#include <ouroboros/sockets.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) {
+ close(sockfd);
+ return -1;
+ }
+
+ close(sockfd);
+ return 0;
+}
+
int irm_create_ipcp(rina_name_t name,
char * ipcp_type)
{
- int sockfd;
struct irm_msg msg;
- buffer_t * buf;
if (ipcp_type == NULL)
return -1;
- sockfd = client_socket_open(IRM_SOCK_PATH);
- if (sockfd < 0)
- return -1;
-
msg.code = IRM_CREATE_IPCP;
- msg.msgs.create_ipcp.name = &name;
- msg.msgs.create_ipcp.ipcp_type = ipcp_type;
-
- buf = serialize_irm_msg(&msg);
- if (buf == NULL) {
- close(sockfd);
- return -1;
- }
+ msg.name = &name;
+ msg.ipcp_type = ipcp_type;
- if (write(sockfd, buf->data, buf->size) == -1) {
- close(sockfd);
+ if (send_irm_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
return -1;
}
- close(sockfd);
return 0;
}
-int irm_destroy_ipcp(int ipcp_id)
+int irm_destroy_ipcp(rina_name_t name)
{
+ struct irm_msg msg;
+
+ msg.code = IRM_DESTROY_IPCP;
+ msg.name = &name;
+
+ if (send_irm_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
return 0;
}
-int irm_bootstrap_ipcp(int ipcp_id,
+int irm_bootstrap_ipcp(rina_name_t name,
struct dif_info info)
{
+ struct irm_msg msg;
+
+ msg.code = IRM_BOOTSTRAP_IPCP;
+ msg.name = &name;
+ msg.info = &info;
+
+ if (send_irm_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
return 0;
}
-int irm_enroll_ipcp(int ipcp_id,
+int irm_enroll_ipcp(rina_name_t name,
char * dif_name)
{
+ struct irm_msg msg;
- return 0;
-}
+ msg.code = IRM_ENROLL_IPCP;
+ msg.name = &name;
+ msg.dif_name = dif_name;
-int irm_reg_ipcp(int ipcp_id,
- char ** difs)
-{
+ if (send_irm_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
return 0;
}
-int irm_unreg_ipcp(int ipcp_id,
- char ** difs)
+int irm_reg_ipcp(rina_name_t name,
+ char ** difs,
+ size_t difs_size)
{
+ struct irm_msg msg;
- return 0;
-}
+ msg.code = IRM_REG_IPCP;
+ msg.name = &name;
+ msg.difs = difs;
+ msg.difs_size = difs_size;
-char ** irm_list_ipcps()
-{
+ if (send_irm_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
return 0;
}
-char ** irm_list_ipcp_types()
+int irm_unreg_ipcp(rina_name_t name,
+ char ** difs,
+ size_t difs_size)
{
+ struct irm_msg msg;
+
+ msg.code = IRM_UNREG_IPCP;
+ msg.name = &name;
+ msg.difs = difs;
+ msg.difs_size = difs_size;
+
+ if (send_irm_msg(&msg)) {
+ LOG_ERR("Failed to send message to daemon");
+ return -1;
+ }
return 0;
}
diff --git a/src/lib/sockets.c b/src/lib/sockets.c
index ef4b3a47..c0331063 100644
--- a/src/lib/sockets.c
+++ b/src/lib/sockets.c
@@ -31,8 +31,6 @@
#include <string.h>
#include <malloc.h>
-#define BUFFER_SIZE 256
-
int client_socket_open(char * file_name)
{
int sockfd;
@@ -146,6 +144,14 @@ static void deser_copy_int(uint8_t * data,
deser_copy_value(sizeof(int), dst, data, offset);
}
+static void deser_copy_size_t(uint8_t * data,
+ size_t * dst,
+ int * offset)
+{
+ *dst = 0;
+ deser_copy_value(sizeof(size_t), dst, data, offset);
+}
+
static void deser_copy_enum(uint8_t * data,
enum irm_msg_code * dst,
int * offset)
@@ -160,13 +166,16 @@ buffer_t * serialize_irm_msg(struct irm_msg * msg)
uint8_t * data;
int offset = 0;
int i;
- char buffer[BUFFER_SIZE];
+ char ** pos;
+
+ if (msg == NULL)
+ return NULL;
buf = malloc(sizeof(*buf));
if (buf == NULL)
return NULL;
- buf->data = malloc(BUFFER_SIZE);
+ buf->data = malloc(IRM_MSG_BUF_SIZE);
if (buf->data == NULL) {
free(buf);
return NULL;
@@ -174,47 +183,75 @@ buffer_t * serialize_irm_msg(struct irm_msg * msg)
data = buf->data;
- ser_copy_value(sizeof(enum irm_msg_code),
- data,
- &msg->code,
- &offset);
+ ser_copy_value(sizeof(enum irm_msg_code), data, &msg->code, &offset);
+
+ if (msg->name == NULL ||
+ msg->name->ap_name == NULL ||
+ msg->name->ae_name == NULL ) {
+ LOG_ERR("Null pointer passed");
+ free(buf->data);
+ free(buf);
+ return NULL;
+ }
+
+ /*
+ * Every IRM message passes the name, may change
+ * Move to separate function when it does
+ */
+ ser_copy_value(strlen(msg->name->ap_name) + 1, data,
+ msg->name->ap_name, &offset);
+
+ ser_copy_value(sizeof(int), data, &msg->name->api_id, &offset);
+
+ ser_copy_value(strlen(msg->name->ae_name) + 1, data,
+ msg->name->ae_name, &offset);
+
+ ser_copy_value(sizeof(int), data, &msg->name->aei_id, &offset);
switch (msg->code) {
case IRM_CREATE_IPCP:
- if (!msg->msgs.create_ipcp.name ||
- !msg->msgs.create_ipcp.name->ap_name ||
- !msg->msgs.create_ipcp.name->ae_name ||
- !msg->msgs.create_ipcp.ipcp_type) {
+ if (!msg->ipcp_type) {
LOG_ERR("Null pointer passed");
free(buf->data);
free(buf);
return NULL;
}
- ser_copy_value(strlen(msg->msgs.create_ipcp.name->ap_name) + 1,
- data,
- msg->msgs.create_ipcp.name->ap_name,
- &offset);
-
- ser_copy_value(sizeof(int),
- data,
- &msg->msgs.create_ipcp.name->api_id,
- &offset);
-
- ser_copy_value(strlen(msg->msgs.create_ipcp.name->ae_name) + 1,
- data,
- msg->msgs.create_ipcp.name->ae_name,
- &offset);
-
- ser_copy_value(sizeof(int),
- data,
- &msg->msgs.create_ipcp.name->aei_id,
- &offset);
-
- ser_copy_value(strlen(msg->msgs.create_ipcp.ipcp_type) + 1,
- data,
- msg->msgs.create_ipcp.ipcp_type,
- &offset);
+ ser_copy_value(strlen(msg->ipcp_type) + 1, data,
+ msg->ipcp_type, &offset);
+ break;
+ case IRM_DESTROY_IPCP:
+ break;
+ case IRM_BOOTSTRAP_IPCP:
+ /* FIXME: Fields missing, need to define dif_info properly */
+ break;
+ case IRM_ENROLL_IPCP:
+ if (msg->dif_name == NULL) {
+ free(buf->data);
+ free(buf);
+ return NULL;
+ }
+
+ 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) {
+ free(buf->data);
+ free(buf);
+ return NULL;
+ }
+
+ 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;
default:
LOG_ERR("Don't know that code");
@@ -225,89 +262,114 @@ buffer_t * serialize_irm_msg(struct irm_msg * msg)
buf->size = offset;
- for (i = 0; i < buf->size; i++) {
- if (i > 0) sprintf(buffer + strlen(buffer), ":");
- sprintf(buffer + strlen(buffer), "%02X", data[i]);
- }
- LOG_DBGF("Serialized buffer to %s", buffer);
-
return buf;
}
struct irm_msg * deserialize_irm_msg(buffer_t * data)
{
struct irm_msg * msg;
- char buffer[BUFFER_SIZE];
- int i;
+ int i, j;
int offset = 0;
+ size_t difs_size;
- if (data == NULL ||
- data->data == NULL) {
+ if (data == NULL || data->data == NULL) {
LOG_ERR("Got a null pointer");
return NULL;
}
- memset(buffer, 0, sizeof(buffer));
- for (i = 0; i < data->size; i++) {
- if (i > 0) sprintf(buffer + strlen(buffer), ":");
- sprintf(buffer + strlen(buffer), "%02X", data->data[i]);
- }
- LOG_DBGF("Got buffer %s", buffer);
-
msg = malloc(sizeof(*msg));
if (msg == NULL) {
LOG_ERR("Failed to allocate memory");
return NULL;
}
- deser_copy_enum(data->data,
- &msg->code,
- &offset);
+ deser_copy_enum(data->data, &msg->code, &offset);
+
+ msg->name = malloc(sizeof(*(msg->name)));
+ if (msg->name == NULL) {
+ LOG_ERR("Failed to alloc memory");
+ free(msg);
+ return NULL;
+ }
+
+ if (deser_copy_string(data->data,
+ &msg->name->ap_name,
+ &offset)) {
+ free(msg->name);
+ free(msg);
+ return NULL;
+ }
+
+ deser_copy_int(data->data, &msg->name->api_id, &offset);
+
+ if (deser_copy_string(data->data,
+ &msg->name->ae_name,
+ &offset)) {
+ free(msg->name->ap_name);
+ free(msg->name);
+ free(msg);
+ return NULL;
+ }
+
+ deser_copy_int(data->data, &msg->name->aei_id, &offset);
switch (msg->code) {
case IRM_CREATE_IPCP:
- msg->msgs.create_ipcp.name =
- malloc(sizeof(*(msg->msgs.create_ipcp.name)));
- if (!msg->msgs.create_ipcp.name) {
- LOG_ERR("Failed to alloc memory");
+ if (deser_copy_string(data->data,
+ &msg->ipcp_type,
+ &offset)) {
+ free(msg->name->ae_name);
+ free(msg->name->ap_name);
+ free(msg->name);
free(msg);
return NULL;
}
+ break;
+ case IRM_DESTROY_IPCP:
+ break;
+ case IRM_BOOTSTRAP_IPCP:
+ break;
+ case IRM_ENROLL_IPCP:
if (deser_copy_string(data->data,
- &msg->msgs.create_ipcp.name->ap_name,
+ &msg->dif_name,
&offset)) {
- free(msg->msgs.create_ipcp.name);
+ free(msg->name->ae_name);
+ free(msg->name->ap_name);
+ free(msg->name);
free(msg);
return NULL;
}
- deser_copy_int(data->data,
- &msg->msgs.create_ipcp.name->api_id,
- &offset);
-
- if (deser_copy_string(data->data,
- &msg->msgs.create_ipcp.name->ae_name,
- &offset)) {
- free(msg->msgs.create_ipcp.name->ap_name);
- free(msg->msgs.create_ipcp.name);
+ break;
+ case IRM_REG_IPCP:
+ case IRM_UNREG_IPCP:
+ deser_copy_size_t(data->data, &difs_size, &offset);
+
+ msg->difs = malloc(sizeof(*(msg->difs)) * difs_size);
+ if (msg->difs == NULL) {
+ free(msg->name->ae_name);
+ free(msg->name->ap_name);
+ free(msg->name);
free(msg);
return NULL;
}
- deser_copy_int(data->data,
- &msg->msgs.create_ipcp.name->aei_id,
- &offset);
-
- if (deser_copy_string(data->data,
- &msg->msgs.create_ipcp.ipcp_type,
- &offset)) {
- free(msg->msgs.create_ipcp.name->ae_name);
- free(msg->msgs.create_ipcp.name->ap_name);
- free(msg->msgs.create_ipcp.name);
- free(msg);
- return NULL;
+ for (i = 0; i < difs_size; i++) {
+ if (deser_copy_string(data->data,
+ &msg->difs[i],
+ &offset)) {
+ for (j = 0; j < i; j++)
+ free(msg->difs[j]);
+ free(msg->difs);
+ free(msg->name->ae_name);
+ free(msg->name->ap_name);
+ free(msg->name);
+ free(msg);
+ return NULL;
+ }
}
+
break;
default:
LOG_ERR("Don't know that code");
diff --git a/src/tools/irm/main.c b/src/tools/irm/main.c
index 470a8166..ac09e1e7 100644
--- a/src/tools/irm/main.c
+++ b/src/tools/irm/main.c
@@ -34,12 +34,40 @@ int main () {
name.api_id = 1;
name.ae_name = "";
name.aei_id = 0;
+ struct dif_info info;
+ char * dif_name = "wienerschnitzel";
+ size_t difs_size = 1;
if (irm_create_ipcp(name, ipcp_type)) {
LOG_ERR("Failed to create IPCP");
return -1;
}
+ if (irm_destroy_ipcp(name)) {
+ LOG_ERR("Failed to destroy IPCP");
+ return -1;
+ }
+
+ if (irm_bootstrap_ipcp(name, info)) {
+ LOG_ERR("Failed to bootstrap IPCP");
+ return -1;
+ }
+
+ if (irm_enroll_ipcp(name, dif_name)) {
+ LOG_ERR("Failed to enroll IPCP");
+ return -1;
+ }
+
+ if (irm_reg_ipcp(name, &dif_name, difs_size)) {
+ LOG_ERR("Failed to register IPCP");
+ return -1;
+ }
+
+ if (irm_unreg_ipcp(name, &dif_name, difs_size)) {
+ LOG_ERR("Failed to unregister IPCP");
+ return -1;
+ }
+
return 0;
}