summaryrefslogtreecommitdiff
path: root/src/tools/irm/irm_ipcp_enroll.c
diff options
context:
space:
mode:
authorDimitri Staessens <dimitri.staessens@ugent.be>2017-11-29 18:23:48 +0100
committerSander Vrijders <sander.vrijders@ugent.be>2017-11-29 18:36:27 +0100
commita781a1611f6b1efe9711dab96dee57ea785280fb (patch)
treee9991fe1e070b46481ec46ecb15ecf16843a737f /src/tools/irm/irm_ipcp_enroll.c
parent4be8eb2ef77648e71ce22b465a49991b532d1ace (diff)
downloadouroboros-a781a1611f6b1efe9711dab96dee57ea785280fb.tar.gz
ouroboros-a781a1611f6b1efe9711dab96dee57ea785280fb.zip
ipcpd: Don't bind from the IPCP
The binding of the normal IPCP to its name is moved from the source code to the irm tool introducing the "autobind" option for the bootstrap and enroll commands. With this option, the IPCP will be bound to the IPCP name and the DIF name automatically. Signed-off-by: Dimitri Staessens <dimitri.staessens@ugent.be> Signed-off-by: Sander Vrijders <sander.vrijders@ugent.be>
Diffstat (limited to 'src/tools/irm/irm_ipcp_enroll.c')
-rw-r--r--src/tools/irm/irm_ipcp_enroll.c38
1 files changed, 29 insertions, 9 deletions
diff --git a/src/tools/irm/irm_ipcp_enroll.c b/src/tools/irm/irm_ipcp_enroll.c
index 1a1d0ccc..1ebe9a6d 100644
--- a/src/tools/irm/irm_ipcp_enroll.c
+++ b/src/tools/irm/irm_ipcp_enroll.c
@@ -48,31 +48,38 @@ static void usage(void)
{
printf("Usage: irm ipcp enroll\n"
" name <ipcp name>\n"
- " dif <dif to enroll in>\n");
+ " dif <dif to enroll in>\n"
+ " [autobind]\n");
}
int do_enroll_ipcp(int argc, char ** argv)
{
- char * name = NULL;
- char * dif_name = NULL;
- pid_t * apis = NULL;
- pid_t api;
- ssize_t len = 0;
- int i = 0;
+ char * name = NULL;
+ char * dif_name = NULL;
+ pid_t * apis = NULL;
+ pid_t api;
+ ssize_t len = 0;
+ int i = 0;
+ bool autobind = false;
+ int cargs;
while (argc > 0) {
+ cargs = 2;
if (matches(*argv, "name") == 0) {
name = *(argv + 1);
} else if (matches(*argv, "dif") == 0) {
dif_name = *(argv + 1);
+ } else if (matches(*argv, "autobind") == 0) {
+ autobind = true;
+ cargs = 1;
} else {
printf("\"%s\" is unknown, try \"irm "
"enroll_ipcp\".\n", *argv);
return -1;
}
- argc -= 2;
- argv += 2;
+ argc -= cargs;
+ argv += cargs;
}
if (dif_name == NULL || name == NULL) {
@@ -89,7 +96,20 @@ int do_enroll_ipcp(int argc, char ** argv)
}
for (i = 0; i < len; i++) {
+ if (autobind && irm_bind_api(apis[i], name)) {
+ free(apis);
+ return -1;
+ }
+
if (irm_enroll_ipcp(apis[i], dif_name)) {
+ if (autobind)
+ irm_unbind_api(apis[i], name);
+ free(apis);
+ return -1;
+ }
+
+ if (autobind && irm_bind_api(apis[i], dif_name)) {
+ printf("Failed to bind %d to %s.\n", apis[i], dif_name);
free(apis);
return -1;
}