From a781a1611f6b1efe9711dab96dee57ea785280fb Mon Sep 17 00:00:00 2001 From: Dimitri Staessens Date: Wed, 29 Nov 2017 18:23:48 +0100 Subject: 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 Signed-off-by: Sander Vrijders --- src/tools/irm/irm_ipcp_enroll.c | 38 +++++++++++++++++++++++++++++--------- 1 file changed, 29 insertions(+), 9 deletions(-) (limited to 'src/tools/irm/irm_ipcp_enroll.c') 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 \n" - " dif \n"); + " dif \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; } -- cgit v1.2.3