summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorSander Vrijders <[email protected]>2016-04-08 16:32:35 +0200
committerSander Vrijders <[email protected]>2016-04-08 16:36:39 +0200
commit6ad0fcf2f32f412091d0dfd58da1d8f5dc474809 (patch)
treeeb10657a977c7c4c410ae15216d4068535a9f058 /src
parentaffea724d1810410186b10c93c64b7a8ddbe7aca (diff)
downloadouroboros-6ad0fcf2f32f412091d0dfd58da1d8f5dc474809.tar.gz
ouroboros-6ad0fcf2f32f412091d0dfd58da1d8f5dc474809.zip
lib, irmd, irm: Add dif_config
This adds dif_config to the prototype, in which one is able to specify the parameters a DIF should have. The bootstrap operation of an IPCP takes this as parameter and is oblivious to whether it is a shim or a normal IPCP. The dif_config struct is also correctly serialized and deserialized and passed opaquely to the correct IPCP. This IPCP is in charge of deserializing it correctly.
Diffstat (limited to 'src')
-rw-r--r--src/irmd/main.c11
-rw-r--r--src/lib/CMakeLists.txt6
-rw-r--r--src/lib/dif_config.proto16
-rw-r--r--src/lib/ipcp.c16
-rw-r--r--src/lib/ipcpd_messages.proto4
-rw-r--r--src/lib/irm.c43
-rw-r--r--src/lib/irmd_messages.proto21
-rw-r--r--src/tools/irm/irm_bootstrap_ipcp.c4
-rw-r--r--src/tools/irm/irm_create_ipcp.c21
9 files changed, 107 insertions, 35 deletions
diff --git a/src/irmd/main.c b/src/irmd/main.c
index a900b0ed..1f1c4839 100644
--- a/src/irmd/main.c
+++ b/src/irmd/main.c
@@ -31,6 +31,7 @@
#include <ouroboros/list.h>
#include <ouroboros/instance_name.h>
#include <ouroboros/utils.h>
+#include <ouroboros/dif_config.h>
#include <sys/socket.h>
#include <sys/un.h>
@@ -84,7 +85,7 @@ static struct ipcp_entry * find_ipcp_by_name(instance_name_t * api)
}
static int create_ipcp(instance_name_t * api,
- char * ipcp_type)
+ enum ipcp_type ipcp_type)
{
pid_t pid;
struct ipcp_entry * tmp = NULL;
@@ -144,8 +145,8 @@ static int destroy_ipcp(instance_name_t * api)
return 0;
}
-static int bootstrap_ipcp(instance_name_t * api,
- struct dif_config * conf)
+static int bootstrap_ipcp(instance_name_t * api,
+ dif_config_msg_t * conf)
{
struct ipcp_entry * entry = NULL;
@@ -155,7 +156,7 @@ static int bootstrap_ipcp(instance_name_t * api,
return -1;
}
- entry->dif_name = strdup( conf->dif_name);
+ entry->dif_name = strdup(conf->dif_name);
if (entry->dif_name == NULL) {
LOG_ERR("Failed to strdup");
return -1;
@@ -389,7 +390,7 @@ int main()
break;
case IRM_MSG_CODE__IRM_BOOTSTRAP_IPCP:
ret_msg.has_result = true;
- ret_msg.result = bootstrap_ipcp(&api, NULL);
+ ret_msg.result = bootstrap_ipcp(&api, msg->conf);
break;
case IRM_MSG_CODE__IRM_ENROLL_IPCP:
ret_msg.has_result = true;
diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt
index 1f7b0f55..c2d1bcc7 100644
--- a/src/lib/CMakeLists.txt
+++ b/src/lib/CMakeLists.txt
@@ -8,6 +8,8 @@ find_package(ProtobufC REQUIRED)
include_directories(${PROTOBUF_INCLUDE_DIRS})
protobuf_generate_c(IRM_PROTO_SRCS IRM_PROTO_HDRS irmd_messages.proto)
protobuf_generate_c(IPCP_PROTO_SRCS IPCP_PROTO_HDRS ipcpd_messages.proto)
+protobuf_generate_c(DIF_CONFIG_PROTO_SRCS DIF_CONFIG_PROTO_HDRS
+ dif_config.proto)
find_library(LIBRT_LIBRARIES rt)
if(NOT LIBRT_LIBRARIES)
@@ -36,11 +38,11 @@ set(SOURCE_FILES
utils.c
)
-install(FILES ${IRM_PROTO_HDRS} ${IPCP_PROTO_HDRS}
+install(FILES ${IRM_PROTO_HDRS} ${IPCP_PROTO_HDRS} ${DIF_CONFIG_PROTO_HDRS}
DESTINATION include/ouroboros)
add_library(ouroboros SHARED ${SOURCE_FILES}
- ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS})
+ ${IRM_PROTO_SRCS} ${IPCP_PROTO_SRCS} ${DIF_CONFIG_PROTO_SRCS})
target_link_libraries(ouroboros ${LIBRT_LIBRARIES}
${LIBPTHREAD_LIBRARIES} ${PROTOBUF_C_LIBRARY})
diff --git a/src/lib/dif_config.proto b/src/lib/dif_config.proto
new file mode 100644
index 00000000..87cb222f
--- /dev/null
+++ b/src/lib/dif_config.proto
@@ -0,0 +1,16 @@
+message dif_config_msg {
+ required string dif_name = 1;
+ required int32 ipcp_type = 2;
+ // Config for normal IPCP
+ optional uint32 addr_size = 3;
+ optional uint32 cep_id_size = 4;
+ 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 uint32 min_pdu_size = 10;
+ optional uint32 max_pdu_size = 11;
+ // Config for shim UDP
+ optional uint32 ip_addr = 12;
+} \ No newline at end of file
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index d61fcb50..a0febe4e 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -100,7 +100,7 @@ static ipcp_msg_t * send_recv_ipcp_msg(pid_t pid,
}
pid_t ipcp_create(instance_name_t * api,
- char * ipcp_type)
+ enum ipcp_type ipcp_type)
{
pid_t pid = 0;
char * api_id = NULL;
@@ -108,11 +108,6 @@ pid_t ipcp_create(instance_name_t * api,
char * ipcp_dir = "bin/ipcpd";
char * full_name = NULL;
- if (ipcp_type == NULL)
- return -1;
-
- LOG_DBG("%lu", _POSIX_C_SOURCE);
-
pid = fork();
if (pid == -1) {
LOG_ERR("Failed to fork");
@@ -146,7 +141,7 @@ pid_t ipcp_create(instance_name_t * api,
char * argv[] = {full_name,
api->name, api_id,
- ipcp_type, 0};
+ 0};
char * envp[] = {0};
@@ -241,14 +236,19 @@ int ipcp_unreg(pid_t pid,
return ret;
}
+
int ipcp_bootstrap(pid_t pid,
- struct dif_config * conf)
+ dif_config_msg_t * conf)
{
ipcp_msg_t msg = IPCP_MSG__INIT;
ipcp_msg_t * recv_msg = NULL;
int ret = -1;
+ if (conf == NULL)
+ return -EINVAL;
+
msg.code = IPCP_MSG_CODE__IPCP_BOOTSTRAP;
+ msg.conf = conf;
recv_msg = send_recv_ipcp_msg(pid, &msg);
if (recv_msg == NULL)
diff --git a/src/lib/ipcpd_messages.proto b/src/lib/ipcpd_messages.proto
index bcdd54ae..b83c34c7 100644
--- a/src/lib/ipcpd_messages.proto
+++ b/src/lib/ipcpd_messages.proto
@@ -1,3 +1,5 @@
+import "dif_config.proto";
+
enum ipcp_msg_code {
IPCP_BOOTSTRAP = 1;
IPCP_ENROLL = 2;
@@ -14,7 +16,7 @@ enum ipcp_msg_code {
message ipcp_msg {
required ipcp_msg_code code = 1;
optional string ap_name = 2;
- // Missing dif_config field here
+ optional dif_config_msg conf = 3;
repeated string dif_name = 4;
optional int32 result = 5;
optional uint32 port_id = 6;
diff --git a/src/lib/irm.c b/src/lib/irm.c
index 7c187be1..3078e158 100644
--- a/src/lib/irm.c
+++ b/src/lib/irm.c
@@ -31,13 +31,13 @@
#include <stdlib.h>
int irm_create_ipcp(instance_name_t * api,
- char * ipcp_type)
+ enum ipcp_type ipcp_type)
{
irm_msg_t msg = IRM_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
- if (api == NULL || ipcp_type == NULL || api->name == NULL)
+ if (api == NULL || api->name == NULL)
return -EINVAL;
msg.code = IRM_MSG_CODE__IRM_CREATE_IPCP;
@@ -94,6 +94,7 @@ int irm_bootstrap_ipcp(instance_name_t * api,
struct dif_config * conf)
{
irm_msg_t msg = IRM_MSG__INIT;
+ dif_config_msg_t config = DIF_CONFIG_MSG__INIT;
irm_msg_t * recv_msg = NULL;
int ret = -1;
@@ -105,9 +106,45 @@ int irm_bootstrap_ipcp(instance_name_t * api,
msg.has_api_id = true;
msg.api_id = api->id;
+ msg.conf = &config;
+ config.dif_name = conf->dif_name;
+ config.ipcp_type = conf->type;
+
+ switch (conf->type) {
+ case NORMAL_IPCP:
+ config.has_addr_size = true;
+ config.has_cep_id_size = true;
+ 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_min_pdu_size = true;
+ config.has_max_pdu_size = true;
+
+ config.addr_size = conf->addr_size;
+ config.cep_id_size = conf->cep_id_size;
+ 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.min_pdu_size = conf->min_pdu_size;
+ config.max_pdu_size = conf->max_pdu_size;
+ break;
+ case SHIM_UDP_IPCP:
+ config.has_ip_addr = true;
+
+ config.ip_addr = conf->ip_addr;
+ break;
+ default:
+ return -1;
+ }
+
recv_msg = send_recv_irm_msg(&msg);
- if (recv_msg == NULL)
+ if (recv_msg == NULL) {
return -1;
+ }
if (recv_msg->has_result == false) {
irm_msg__free_unpacked(recv_msg, NULL);
diff --git a/src/lib/irmd_messages.proto b/src/lib/irmd_messages.proto
index 44070755..3a2432f3 100644
--- a/src/lib/irmd_messages.proto
+++ b/src/lib/irmd_messages.proto
@@ -1,3 +1,5 @@
+import "dif_config.proto";
+
enum irm_msg_code {
IRM_CREATE_IPCP = 1;
IRM_DESTROY_IPCP = 2;
@@ -26,14 +28,13 @@ message irm_msg {
optional string ap_name = 2;
optional uint32 api_id = 3;
optional string ae_name = 4;
- optional string ipcp_type = 5;
- // Missing dif_config field here
- repeated string dif_name = 7;
- optional int32 fd = 8;
- optional int32 result = 9;
- // Missing qos_spec here
- optional int32 oflags = 10;
- optional string dst_ap_name = 11;
- optional uint32 port_id = 12;
- optional int32 pid = 13;
+ optional uint32 ipcp_type = 5;
+ repeated string dif_name = 6;
+ optional int32 fd = 7;
+ optional int32 result = 8;
+ optional int32 oflags = 9;
+ optional string dst_ap_name = 10;
+ optional uint32 port_id = 11;
+ optional int32 pid = 12;
+ optional dif_config_msg conf = 13;
};
diff --git a/src/tools/irm/irm_bootstrap_ipcp.c b/src/tools/irm/irm_bootstrap_ipcp.c
index 03a913fb..e7acfccd 100644
--- a/src/tools/irm/irm_bootstrap_ipcp.c
+++ b/src/tools/irm/irm_bootstrap_ipcp.c
@@ -23,7 +23,7 @@
#include <stdio.h>
#include <stdlib.h>
#include <ouroboros/irm.h>
-#include <ouroboros/common.h>
+#include <ouroboros/dif_config.h>
#include "irm_ops.h"
#include "irm_utils.h"
@@ -36,7 +36,6 @@ static void usage()
" [api <application process instance>]\n");
}
-
int do_bootstrap_ipcp(int argc, char ** argv)
{
instance_name_t api = {NULL, 0};
@@ -53,7 +52,6 @@ int do_bootstrap_ipcp(int argc, char ** argv)
return -1;
}
-
argc -= 2;
argv += 2;
}
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
index 73d20dce..e4a0f22f 100644
--- a/src/tools/irm/irm_create_ipcp.c
+++ b/src/tools/irm/irm_create_ipcp.c
@@ -20,10 +20,11 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
-#include <stdio.h>
#include <ouroboros/irm.h>
#include <ouroboros/common.h>
#include <ouroboros/instance_name.h>
+
+#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
@@ -31,18 +32,23 @@
#include "irm_ops.h"
#include "irm_utils.h"
+#define NORMAL "normal"
+#define SHIM_UDP "shim-udp"
+
static void usage()
{
printf("Usage: irm create_ipcp\n"
" ap <application process name>\n"
" [api <application process instance>]\n"
- " type <ipc process type>\n");
+ " type [TYPE]\n\n"
+ "where TYPE = {" NORMAL " " SHIM_UDP "}\n");
}
int do_create_ipcp(int argc, char ** argv)
{
char * ipcp_type = NULL;
instance_name_t api = {NULL, 0};
+ enum ipcp_type type = 0;
while (argc > 0) {
if (matches(*argv, "type") == 0) {
@@ -66,5 +72,14 @@ int do_create_ipcp(int argc, char ** argv)
return -1;
}
- return irm_create_ipcp(&api, ipcp_type);
+ if (strcmp(ipcp_type, NORMAL) == 0)
+ type = NORMAL_IPCP;
+ else if (strcmp(ipcp_type, SHIM_UDP) == 0)
+ type = SHIM_UDP_IPCP;
+ else {
+ usage();
+ return -1;
+ }
+
+ return irm_create_ipcp(&api, type);
}