summaryrefslogtreecommitdiff
path: root/src/lib/ipcp.c
diff options
context:
space:
mode:
authorDimitri Staessens <[email protected]>2016-03-15 15:48:52 +0100
committerDimitri Staessens <[email protected]>2016-03-15 15:48:52 +0100
commit04bf4380b30b58252d1d2aab75a9dcc5c084c831 (patch)
treea33ce52d5b71f49c75bc7de3f9549d6257b259e1 /src/lib/ipcp.c
parentceaea65296a9cb6e2235b0dd429ab3d590b634d3 (diff)
parent7ca8145790db15d7da3c2f1b260ad3421993b67c (diff)
downloadouroboros-04bf4380b30b58252d1d2aab75a9dcc5c084c831.tar.gz
ouroboros-04bf4380b30b58252d1d2aab75a9dcc5c084c831.zip
Merge branch 'be' of bitbucket.org:ouroboros-rina/ouroboros into b-du_buff
Diffstat (limited to 'src/lib/ipcp.c')
-rw-r--r--src/lib/ipcp.c103
1 files changed, 93 insertions, 10 deletions
diff --git a/src/lib/ipcp.c b/src/lib/ipcp.c
index 935330d5..294d518c 100644
--- a/src/lib/ipcp.c
+++ b/src/lib/ipcp.c
@@ -20,41 +20,124 @@
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
+#define OUROBOROS_PREFIX "lib-ipcp"
+
+#ifndef _POSIX_C_SOURCE
+#define _POSIX_C_SOURCE 199506L
+#endif
+
#include <ouroboros/ipcp.h>
+#include <ouroboros/common.h>
+#include <ouroboros/logs.h>
+#include <ouroboros/config.h>
+#include <ouroboros/utils.h>
+
+#include <stdlib.h>
+#include <string.h>
+#include <signal.h>
+#include <sys/types.h>
+#include <sys/wait.h>
-int ipcp_create(rina_name_t name,
- char * ipcp_type)
+pid_t ipcp_create(rina_name_t name,
+ char * ipcp_type)
{
- /* zero means failure */
- return 0;
+ pid_t pid = 0;
+ char * api_id = NULL;
+ char * aei_id = NULL;
+ size_t len = 0;
+ char * ipcp_dir = "bin/ipcpd";
+ char * full_name = NULL;
+
+ pid = fork();
+ if (pid == -1) {
+ LOG_ERR("Failed to fork");
+ return pid;
+ }
+
+ if (pid != 0) {
+ return pid;
+ }
+
+ api_id = malloc(n_digits(name.api_id) + 1);
+ if (!api_id) {
+ LOG_ERR("Failed to malloc");
+ exit(-1);
+ }
+ sprintf(api_id, "%d", name.api_id);
+
+ aei_id = malloc(n_digits(name.aei_id) + 1);
+ if (!aei_id) {
+ LOG_ERR("Failed to malloc");
+ exit(-1);
+ }
+ sprintf(aei_id, "%d", name.aei_id);
+
+ len += strlen(INSTALL_DIR);
+ len += strlen(ipcp_dir);
+ len += 2;
+ full_name = malloc(len);
+ if (!full_name) {
+ LOG_ERR("Failed to malloc");
+ exit(-1);
+ }
+
+ strcpy(full_name, INSTALL_DIR);
+ strcat(full_name, "/");
+ strcat(full_name, ipcp_dir);
+
+ char * argv[] = {full_name,
+ name.ap_name, api_id,
+ name.ae_name, aei_id,
+ ipcp_type, 0};
+
+ char * envp[] = {0};
+
+ execve(argv[0], &argv[0], envp);
+
+ LOG_DBG("%s", strerror(errno));
+ LOG_ERR("Failed to load IPCP daemon");
+ LOG_ERR("Make sure to run the installed version");
+ exit(-1);
}
-int ipcp_destroy(int pid)
+int ipcp_destroy(pid_t pid)
{
- return -1;
+ int status;
+
+ if (kill(pid, SIGTERM)) {
+ LOG_ERR("Failed to destroy IPCP");
+ return -1;
+ }
+
+ if (waitpid(pid, &status, 0) < 0) {
+ LOG_ERR("Failed to destroy IPCP");
+ return -1;
+ }
+
+ return 0;
}
-int ipcp_reg(int pid,
+int ipcp_reg(pid_t pid,
char ** difs,
size_t difs_size)
{
return -1;
}
-int ipcp_unreg(int pid,
+int ipcp_unreg(pid_t pid,
char ** difs,
size_t difs_size)
{
return -1;
}
-int ipcp_bootstrap(int pid,
+int ipcp_bootstrap(pid_t pid,
struct dif_config conf)
{
return -1;
}
-int ipcp_enroll(int pid,
+int ipcp_enroll(pid_t pid,
char * dif_name,
rina_name_t member,
char ** n_1_difs,