summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
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.c112
-rw-r--r--src/tools/irm/irm_create_ipcp.c21
9 files changed, 211 insertions, 39 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..70b7b3a5 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 IPCP_NORMAL:
+ 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 IPCP_SHIM_UDP:
+ 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..78a09362 100644
--- a/src/tools/irm/irm_bootstrap_ipcp.c
+++ b/src/tools/irm/irm_bootstrap_ipcp.c
@@ -22,43 +22,141 @@
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+#include <arpa/inet.h>
+
#include <ouroboros/irm.h>
-#include <ouroboros/common.h>
+#include <ouroboros/dif_config.h>
#include "irm_ops.h"
#include "irm_utils.h"
+#define NORMAL "normal"
+#define SHIM_UDP "shim-udp"
+
+#define DEFAULT_ADDR_SIZE 4
+#define DEFAULT_CEP_ID_SIZE 2
+#define DEFAULT_PDU_LEN_SIZE 2
+#define DEFAULT_QOS_ID_SIZE 1
+#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
+
static void usage()
{
/* FIXME: Add dif_config stuff */
printf("Usage: irm bootstrap_ipcp\n"
" ap <application process name>\n"
- " [api <application process instance>]\n");
+ " [api <application process instance>]\n"
+ " dif <DIF name>\n"
+ " type [TYPE]\n\n"
+ "where TYPE = {" NORMAL " " SHIM_UDP "}\n\n"
+ "if TYPE == " NORMAL "\n"
+ " [addr <address size> (default: %d)]\n"
+ " [cep_id <CEP-id size> (default: %d)]\n"
+ " [pdu_len <PDU length size> (default: %d)]\n"
+ " [qos_id <QoS-id 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"
+ " [min_pdu <minimum PDU size> (default: %d)]\n"
+ " [max_pdu <maximum PDU size> (default: %d)]\n"
+ "if TYPE == " SHIM_UDP "\n"
+ " ip <IP address in dotted notation>\n",
+ DEFAULT_ADDR_SIZE, DEFAULT_CEP_ID_SIZE,
+ DEFAULT_PDU_LEN_SIZE, DEFAULT_QOS_ID_SIZE,
+ DEFAULT_SEQ_NO_SIZE, DEFAULT_TTL_SIZE,
+ DEFAULT_CHK_SIZE, DEFAULT_MIN_PDU_SIZE,
+ DEFAULT_MAX_PDU_SIZE);
}
-
int do_bootstrap_ipcp(int argc, char ** argv)
{
- instance_name_t api = {NULL, 0};
+ instance_name_t api = {NULL, 0};
struct dif_config conf;
+ uint8_t addr_size = DEFAULT_ADDR_SIZE;
+ uint8_t cep_id_size = DEFAULT_CEP_ID_SIZE;
+ uint8_t pdu_length_size = DEFAULT_PDU_LEN_SIZE;
+ uint8_t qos_id_size = DEFAULT_QOS_ID_SIZE;
+ uint8_t seqno_size = DEFAULT_SEQ_NO_SIZE;
+ uint8_t ttl_size = DEFAULT_TTL_SIZE;
+ uint8_t chk_size = DEFAULT_CHK_SIZE;
+ uint32_t min_pdu_size = DEFAULT_MIN_PDU_SIZE;
+ uint32_t max_pdu_size = DEFAULT_MAX_PDU_SIZE;
+ uint32_t ip_addr = 0;
+ char * ipcp_type = NULL;
+ char * dif_name = NULL;
while (argc > 0) {
- if (matches(*argv, "ap") == 0) {
+ if (matches(*argv, "type") == 0) {
+ ipcp_type = *(argv + 1);
+ } else if (matches(*argv, "dif") == 0) {
+ dif_name = *(argv + 1);
+ } else if (matches(*argv, "ap") == 0) {
api.name = *(argv + 1);
} else if (matches(*argv, "api") == 0) {
api.id = atoi(*(argv + 1));
+ } else if (matches(*argv, "ip") == 0) {
+ if (inet_pton (AF_INET, *(argv + 1), &ip_addr) != 1) {
+ usage();
+ return -1;
+ }
+ } else if (matches(*argv, "addr") == 0) {
+ addr_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "cep_id") == 0) {
+ cep_id_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "pdu_len") == 0) {
+ pdu_length_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "qos_id") == 0) {
+ qos_id_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "seqno") == 0) {
+ seqno_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "ttl") == 0) {
+ ttl_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "chk") == 0) {
+ chk_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "min_pdu") == 0) {
+ min_pdu_size = atoi(*(argv + 1));
+ } else if (matches(*argv, "max_pdu") == 0) {
+ max_pdu_size = atoi(*(argv + 1));
} else {
printf("\"%s\" is unknown, try \"irm "
"destroy_ipcp\".\n", *argv);
return -1;
}
-
argc -= 2;
argv += 2;
}
- if (api.name == NULL) {
+ if (api.name == NULL || dif_name == NULL || ipcp_type == NULL) {
+ usage();
+ return -1;
+ }
+
+ conf.dif_name = dif_name;
+
+ if (strcmp(ipcp_type, NORMAL) == 0) {
+ conf.type = IPCP_NORMAL;
+ conf.addr_size = addr_size;
+ conf.cep_id_size = cep_id_size;
+ conf.pdu_length_size = pdu_length_size;
+ conf.qos_id_size = qos_id_size;
+ conf.seqno_size = seqno_size;
+ conf.ttl_size = ttl_size;
+ conf.chk_size = chk_size;
+ conf.min_pdu_size = min_pdu_size;
+ conf.max_pdu_size = max_pdu_size;
+ } else if (strcmp(ipcp_type, SHIM_UDP) == 0) {
+ conf.type = IPCP_SHIM_UDP;
+ if (ip_addr == 0) {
+ usage();
+ return -1;
+ }
+ conf.ip_addr = ip_addr;
+ } else {
usage();
return -1;
}
diff --git a/src/tools/irm/irm_create_ipcp.c b/src/tools/irm/irm_create_ipcp.c
index 73d20dce..08b55259 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 = IPCP_NORMAL;
+ else if (strcmp(ipcp_type, SHIM_UDP) == 0)
+ type = IPCP_SHIM_UDP;
+ else {
+ usage();
+ return -1;
+ }
+
+ return irm_create_ipcp(&api, type);
}