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_bootstrap.c | 42 +++++++++++++++++++++++++++++++------- 1 file changed, 35 insertions(+), 7 deletions(-) (limited to 'src/tools/irm/irm_ipcp_bootstrap.c') 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 (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; -- cgit v1.2.3