From a3eb060b8d4419c1af85d3acf081f45cdc27708d Mon Sep 17 00:00:00 2001 From: Sander Vrijders Date: Tue, 23 Feb 2016 17:04:49 +0100 Subject: lib: Initial messages for the IRM This provides the initial messages to be passed between the irmd and libouroboros-irm. --- src/irmd/main.c | 57 +++++++++++++++++++++++++++-- src/lib/CMakeLists.txt | 2 ++ src/lib/irm.c | 97 ++++++++++++++++++++++++++++++++++++++++++++++++++ src/lib/sockets.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++++ src/tools/irm/main.c | 13 ++++++- 5 files changed, 260 insertions(+), 3 deletions(-) create mode 100644 src/lib/irm.c create mode 100644 src/lib/sockets.c (limited to 'src') diff --git a/src/irmd/main.c b/src/irmd/main.c index 8ab071e0..b4e43534 100644 --- a/src/irmd/main.c +++ b/src/irmd/main.c @@ -1,10 +1,63 @@ -#define OUROBOROS_PREFIX "irm" +/* + * Ouroboros - Copyright (C) 2016 + * + * The IPC Resource Manager + * + * 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. + */ + +#define OUROBOROS_PREFIX "irmd" #include +#include +#include +#include +#include +#include + +#define BUF_SIZE 256 int main() { - LOG_DBG("Test of the IRM"); + int sockfd; + + sockfd = server_socket_open(IRM_SOCK_PATH); + if (sockfd < 0) + return -1; + + while (true) { + int cli_sockfd; + struct irm_msg_sock msg; + ssize_t count; + char buf[BUF_SIZE]; + + cli_sockfd = accept(sockfd, 0, 0); + if (cli_sockfd < 0) { + LOG_ERR("Cannot accept new connection"); + } + + count = read(cli_sockfd, buf, BUF_SIZE); + if (count) { + msg = (struct struct irm_msg_sock) buf; + LOG_INFO("Got message code %d", buf.code); + } + + close(cli_sockfd); + } return 0; } diff --git a/src/lib/CMakeLists.txt b/src/lib/CMakeLists.txt index 9a6f1946..2e0d6b6b 100644 --- a/src/lib/CMakeLists.txt +++ b/src/lib/CMakeLists.txt @@ -9,6 +9,8 @@ set(SOURCE_FILES bitmap.c cdap.c du_buff.c + irm.c + sockets.c ) add_library(ouroboros SHARED ${SOURCE_FILES}) diff --git a/src/lib/irm.c b/src/lib/irm.c new file mode 100644 index 00000000..da229d3e --- /dev/null +++ b/src/lib/irm.c @@ -0,0 +1,97 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * The API to instruct the IRM + * + * 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. + */ + +#define OUROBOROS_PREFIX "libouroboros-irm" + +#include +#include +#include +#include + +int irm_create_ipcp(rina_name_t name, + char * ipcp_type) +{ + int sockfd; + struct irm_msg_sock msg; + + if (!ipcp_type) + return -1; + + sockfd = client_socket_open(IRM_SOCK_PATH); + if (sockfd < 0) + return -1; + + msg.code = IRM_CREATE_IPCP; + msg.irm_msg.create_ipcp.name = name; + msg.irm_msg.create_ipcp.ipcp_type = ipcp_type; + + write(sockfd, &msg, sizeof(msg)); + close(sockfd); + + return 0; +} + +int irm_destroy_ipcp(int ipcp_id) +{ + + return 0; +} + +int irm_bootstrap_ipcp(int ipcp_id, + struct dif_info info) +{ + + return 0; +} + +int irm_enroll_ipcp(int ipcp_id, + char * dif_name) +{ + + return 0; +} + +int irm_reg_ipcp(int ipcp_id, + char ** difs) +{ + + return 0; +} + +int irm_unreg_ipcp(int ipcp_id, + char ** difs) +{ + + return 0; +} + +char ** irm_list_ipcps() +{ + + return 0; +} + +char ** irm_list_ipcp_types() +{ + + return 0; +} diff --git a/src/lib/sockets.c b/src/lib/sockets.c new file mode 100644 index 00000000..8917f55a --- /dev/null +++ b/src/lib/sockets.c @@ -0,0 +1,94 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * The sockets layer to communicate between daemons + * + * 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. + */ + +#define OUROBOROS_PREFIX "libouroboros-sockets" + +#include +#include +#include +#include +#include +#include +#include + +int client_socket_open(char * file_name) +{ + int sockfd; + struct sockaddr_un serv_addr; + + sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd < 0) { + LOG_ERR("Failed to open socket"); + return -1; + } + + serv_addr.sun_family = AF_UNIX; + sprintf(serv_addr.sun_path, file_name); + + if (connect(sockfd, + (struct sockaddr *) &serv_addr, + sizeof(serv_addr))) { + LOG_ERR("Failed to connect to server"); + return -1; + } + + return sockfd; +} + +int server_socket_open(char * file_name) +{ + int sockfd; + struct sockaddr_un serv_addr; + struct stat sb; + + if (!stat(file_name, &sb)) { + /* File exists */ + if (unlink(file_name)) { + LOG_ERR("Failed to unlink filename: %s", + strerror(errno)); + return -1; + } + } + + sockfd = socket(AF_UNIX, SOCK_STREAM, 0); + if (sockfd < 0) { + LOG_ERR("Failed to open socket"); + return -1; + } + + serv_addr.sun_family = AF_UNIX; + sprintf(serv_addr.sun_path, file_name); + + if (bind(sockfd, + (struct sockaddr *) &serv_addr, + sizeof(serv_addr))) { + LOG_ERR("Failed to bind socket"); + return -1; + } + + if (listen(sockfd, 0)) { + LOG_ERR("Failed to listen to socket"); + return -1; + } + + return sockfd; +} diff --git a/src/tools/irm/main.c b/src/tools/irm/main.c index bad1000e..6439243c 100644 --- a/src/tools/irm/main.c +++ b/src/tools/irm/main.c @@ -23,10 +23,21 @@ #define OUROBOROS_PREFIX "irm" #include +#include +#include int main () { + char * ap_name = "test"; + char * ipcp_type = "normal-ipcp"; + rina_name_t name; + name.ap_name = ap_name; + name.api_id = 1; + + if (irm_create_ipcp(name, ipcp_type)) { + LOG_ERR("Failed to create IPCP"); + return -1; + } - LOG_DBG("Test of the IRM tool"); return 0; } -- cgit v1.2.3