diff options
author | Dimitri Staessens <dimitri.staessens@ugent.be> | 2017-11-29 18:23:48 +0100 |
---|---|---|
committer | Sander Vrijders <sander.vrijders@ugent.be> | 2017-11-29 18:36:27 +0100 |
commit | a781a1611f6b1efe9711dab96dee57ea785280fb (patch) | |
tree | e9991fe1e070b46481ec46ecb15ecf16843a737f /src/tools/irm | |
parent | 4be8eb2ef77648e71ce22b465a49991b532d1ace (diff) | |
download | ouroboros-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')
-rw-r--r-- | src/tools/irm/irm_ipcp_bootstrap.c | 42 | ||||
-rw-r--r-- | src/tools/irm/irm_ipcp_enroll.c | 38 |
2 files changed, 64 insertions, 16 deletions
diff --git a/src/tools/irm/irm_ipcp_bootstrap.c b/src/tools/irm/irm_ipcp_bootstrap.c index ddda4550..3da78a2b 100644 --- a/src/tools/irm/irm_ipcp_bootstrap.c +++ b/src/tools/irm/irm_ipcp_bootstrap.c @@ -90,6 +90,7 @@ static void usage(void) " [routing <ROUTING_POLICY> (default: %s)]\n" " [pff [PFF_POLICY] (default: %s)]\n" " [hash [ALGORITHM] (default: %s)]\n" + " [autobind]\n" "where ADDRESS_POLICY = {"FLAT_RANDOM_ADDR_AUTH"}\n" " ROUTING_POLICY = {"LINK_STATE_ROUTING " " LINK_STATE_LFA_ROUTING "}\n" @@ -126,8 +127,11 @@ int do_bootstrap_ipcp(int argc, char ** argv) pid_t * apis = NULL; ssize_t len = 0; int i = 0; + bool autobind = false; + int cargs; while (argc > 0) { + cargs = 2; if (matches(*argv, "type") == 0) { ipcp_type = *(argv + 1); } else if (matches(*argv, "dif") == 0) { @@ -159,8 +163,10 @@ int do_bootstrap_ipcp(int argc, char ** argv) fd_size = atoi(*(argv + 1)); } else if (matches(*argv, "ttl") == 0) { has_ttl = true; - argc++; - argv--; + cargs = 1; + } else if (matches(*argv, "autobind") == 0) { + autobind = true; + cargs = 1; } else if (matches(*argv, "addr_auth") == 0) { if (strcmp(FLAT_RANDOM_ADDR_AUTH, *(argv + 1)) == 0) addr_auth_type = ADDR_AUTH_FLAT_RANDOM; @@ -186,8 +192,8 @@ int do_bootstrap_ipcp(int argc, char ** argv) return -1; } - argc -= 2; - argv += 2; + argc -= cargs; + argv += cargs; } if (name == NULL || dif_name == NULL || ipcp_type == NULL) { @@ -228,6 +234,11 @@ int do_bootstrap_ipcp(int argc, char ** argv) return -1; } + if (autobind && conf.type != IPCP_NORMAL) { + printf("Can only bind normal IPCPs, autobind disabled.\n"); + autobind = false; + } + len = irm_list_ipcps(name, &apis); if (len <= 0) { api = irm_create_ipcp(name, conf.type); @@ -236,14 +247,31 @@ int do_bootstrap_ipcp(int argc, char ** argv) len = irm_list_ipcps(name, &apis); } - for (i = 0; i < len; i++) + for (i = 0; i < len; i++) { + if (autobind && irm_bind_api(apis[i], name)) { + printf("Failed to bind %d to %s.\n", 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); + irm_unbind_api(apis[i], name); + free(apis); + return -1; + } + if (irm_bootstrap_ipcp(apis[i], &conf)) { + if (autobind) { + irm_unbind_api(apis[i], name); + irm_unbind_api(apis[i], dif_name); + } free(apis); return -1; } + } - if (apis != NULL) - free(apis); + free(apis); return 0; 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; } |