From 6ad0fcf2f32f412091d0dfd58da1d8f5dc474809 Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Fri, 8 Apr 2016 16:32:35 +0200 Subject: 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. --- include/ouroboros/CMakeLists.txt | 1 + include/ouroboros/common.h | 24 --------------- include/ouroboros/dif_config.h | 61 ++++++++++++++++++++++++++++++++++++++ include/ouroboros/ipcp.h | 10 +++++-- include/ouroboros/irm.h | 12 ++++---- include/ouroboros/sockets.h | 3 ++ include/ouroboros/utils.h | 2 ++ src/irmd/main.c | 11 +++---- src/lib/CMakeLists.txt | 6 ++-- src/lib/dif_config.proto | 16 ++++++++++ src/lib/ipcp.c | 16 +++++----- src/lib/ipcpd_messages.proto | 4 ++- src/lib/irm.c | 43 +++++++++++++++++++++++++-- src/lib/irmd_messages.proto | 21 ++++++------- src/tools/irm/irm_bootstrap_ipcp.c | 4 +-- src/tools/irm/irm_create_ipcp.c | 21 +++++++++++-- 16 files changed, 188 insertions(+), 67 deletions(-) create mode 100644 include/ouroboros/dif_config.h create mode 100644 src/lib/dif_config.proto diff --git a/include/ouroboros/CMakeLists.txt b/include/ouroboros/CMakeLists.txt index 0b52a2bc..fb4884b7 100644 --- a/include/ouroboros/CMakeLists.txt +++ b/include/ouroboros/CMakeLists.txt @@ -8,6 +8,7 @@ set(HEADER_FILES common.h da.h dev.h + dif_config.h du_buff.h flow.h instance_name.h diff --git a/include/ouroboros/common.h b/include/ouroboros/common.h index 658c3618..971a382a 100644 --- a/include/ouroboros/common.h +++ b/include/ouroboros/common.h @@ -42,28 +42,4 @@ struct qos_spec { uint32_t jitter; }; -/* FIXME: What should be configurable in the DIF? */ -struct dif_config { - /* general data */ - char * dif_name; - - /* TODO: efficient policies */ - - /* dt field sizes in octets */ - uint8_t addr_size; - uint8_t cep_id_size; - uint8_t pdu_length_size; - uint8_t qos_id_size; - uint8_t seqno_size; - - /* constants for dup */ - uint8_t ttl_size; - uint8_t chk_size; - - /* values, octets */ - uint32_t min_pdu_size; - uint32_t max_pdu_size; - -}; - #endif /* OUROBOROS_COMMON_H */ diff --git a/include/ouroboros/dif_config.h b/include/ouroboros/dif_config.h new file mode 100644 index 00000000..5443085e --- /dev/null +++ b/include/ouroboros/dif_config.h @@ -0,0 +1,61 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * DIF configurations for each IPCP type + * + * Sander Vrijders + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. + */ + +#include + +#ifndef OUROBOROS_DIF_CONFIG_H +#define OUROBOROS_DIF_CONFIG_H + +enum ipcp_type { + NORMAL_IPCP = 1, + SHIM_UDP_IPCP +}; + +struct dif_config { + char * dif_name; + enum ipcp_type type; + + union { + /* Normal DIF */ + struct { + uint8_t addr_size; + uint8_t cep_id_size; + uint8_t pdu_length_size; + uint8_t qos_id_size; + uint8_t seqno_size; + + /* DUP constants */ + uint8_t ttl_size; + uint8_t chk_size; + + uint32_t min_pdu_size; + uint32_t max_pdu_size; + }; + /* Shim UDP */ + struct { + uint32_t ip_addr; + }; + }; +}; + + +#endif /* OUROBOROS_DIF_CONFIG_H */ diff --git a/include/ouroboros/ipcp.h b/include/ouroboros/ipcp.h index fdaf5c4a..3198a882 100644 --- a/include/ouroboros/ipcp.h +++ b/include/ouroboros/ipcp.h @@ -24,7 +24,9 @@ #define OUROBOROS_IPCP_H #include +#include #include +#include #include @@ -32,7 +34,8 @@ struct ipcp; /* Returns the process id */ pid_t ipcp_create(instance_name_t * api, - char * ipcp_type); + enum ipcp_type ipcp_type); + int ipcp_destroy(pid_t pid); int ipcp_reg(pid_t pid, @@ -42,12 +45,13 @@ int ipcp_unreg(pid_t pid, char ** difs, size_t difs_size); -int ipcp_bootstrap(pid_t pid, - struct dif_config * conf); int ipcp_enroll(pid_t pid, char * member_name, char * n_1_dif); +int ipcp_bootstrap(pid_t pid, + dif_config_msg_t * conf); + /* Flow related ops, these go from IRMd to IPCP */ int ipcp_ap_reg(pid_t pid, diff --git a/include/ouroboros/irm.h b/include/ouroboros/irm.h index 780bf77b..24bb2c42 100644 --- a/include/ouroboros/irm.h +++ b/include/ouroboros/irm.h @@ -23,18 +23,20 @@ #ifndef OUROBOROS_IRM_H #define OUROBOROS_IRM_H -#include "common.h" -#include "instance_name.h" +#include +#include int irm_create_ipcp(instance_name_t * api, - char * ipcp_type); + enum ipcp_type ipcp_type); + int irm_destroy_ipcp(instance_name_t * api); -int irm_bootstrap_ipcp(instance_name_t * api, - struct dif_config * conf); int irm_enroll_ipcp(instance_name_t * api, char * dif_name); +int irm_bootstrap_ipcp(instance_name_t * api, + struct dif_config * conf); + int irm_reg_ipcp(instance_name_t * api, char ** difs, size_t difs_size); diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h index 0c517bd4..be5ae651 100644 --- a/include/ouroboros/sockets.h +++ b/include/ouroboros/sockets.h @@ -27,6 +27,9 @@ #include +#include "dif_config.pb-c.h" +typedef DifConfigMsg dif_config_msg_t; + #include "irmd_messages.pb-c.h" typedef IrmMsg irm_msg_t; diff --git a/include/ouroboros/utils.h b/include/ouroboros/utils.h index 2eaccae9..2e5a4944 100644 --- a/include/ouroboros/utils.h +++ b/include/ouroboros/utils.h @@ -20,6 +20,8 @@ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */ +#define MAX(a,b) (a > b ? a : b) + /* * Returns the number of characters a uint would * need when represented as a string 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 #include #include +#include #include #include @@ -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 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 #include #include -#include +#include #include "irm_ops.h" #include "irm_utils.h" @@ -36,7 +36,6 @@ static void usage() " [api ]\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 #include #include #include + +#include #include #include #include @@ -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 \n" " [api ]\n" - " 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); } -- cgit v1.2.3