diff options
-rw-r--r-- | include/ouroboros/sockets.h | 46 | ||||
-rw-r--r-- | src/irmd/main.c | 57 | ||||
-rw-r--r-- | src/lib/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/lib/irm.c | 97 | ||||
-rw-r--r-- | src/lib/sockets.c | 94 | ||||
-rw-r--r-- | src/tools/irm/main.c | 13 |
6 files changed, 306 insertions, 3 deletions
diff --git a/include/ouroboros/sockets.h b/include/ouroboros/sockets.h new file mode 100644 index 00000000..fb2fa7db --- /dev/null +++ b/include/ouroboros/sockets.h @@ -0,0 +1,46 @@ +/* + * Ouroboros - Copyright (C) 2016 + * + * The sockets layer to communicate between daemons + * + * Sander Vrijders <sander.vrijders@intec.ugent.be> + * + * 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 IRM_SOCK_PATH "/tmp/irm_sock" + +enum irm_msg_code { + IRM_CREATE_IPCP, + IRM_DESTROY_IPCP, + IRM_BOOTSTRAP_IPCP, + IRM_ENROLL_IPCP, + IRM_REG_IPCP, + IRM_UNREG_IPCP, + IRM_LIST_IPCPS +}; + +struct irm_msg_sock { + enum irm_msg_code code; + union { + struct { + rina_name_t name; + char * ipcp_type; + } create_ipcp; + } irm_msg; +}; + +int client_socket_open(char * file_name); +int server_socket_open(char * file_name); 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 <sander.vrijders@intec.ugent.be> + * + * 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 <ouroboros/logs.h> +#include <ouroboros/common.h> +#include <ouroboros/sockets.h> +#include <ouroboros/irm.h> +#include <sys/socket.h> +#include <sys/un.h> + +#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 <sander.vrijders@intec.ugent.be> + * + * 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 <ouroboros/irm.h> +#include <ouroboros/common.h> +#include <ouroboros/logs.h> +#include <ouroboros/sockets.h> + +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 <sander.vrijders@intec.ugent.be> + * + * 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 <ouroboros/logs.h> +#include <ouroboros/common.h> +#include <ouroboros/sockets.h> +#include <sys/socket.h> +#include <sys/un.h> +#include <sys/stat.h> +#include <string.h> + +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 <ouroboros/logs.h> +#include <ouroboros/common.h> +#include <ouroboros/irm.h> 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; } |