1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
|
/*
* Ouroboros - Copyright (C) 2016
*
* The API to instruct IPCPs
*
* 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 "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>
pid_t ipcp_create(rina_name_t name,
char * ipcp_type)
{
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(pid_t pid)
{
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(pid_t pid,
char ** difs,
size_t difs_size)
{
return -1;
}
int ipcp_unreg(pid_t pid,
char ** difs,
size_t difs_size)
{
return -1;
}
int ipcp_bootstrap(pid_t pid,
struct dif_config conf)
{
return -1;
}
int ipcp_enroll(pid_t pid,
char * dif_name,
rina_name_t member,
char ** n_1_difs,
ssize_t n_1_difs_size)
{
return -1;
}
|