diff options
author | Dimitri Staessens <[email protected]> | 2017-11-29 18:23:48 +0100 |
---|---|---|
committer | Sander Vrijders <[email protected]> | 2017-11-29 18:36:27 +0100 |
commit | a781a1611f6b1efe9711dab96dee57ea785280fb (patch) | |
tree | e9991fe1e070b46481ec46ecb15ecf16843a737f /src | |
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 <[email protected]>
Signed-off-by: Sander Vrijders <[email protected]>
Diffstat (limited to 'src')
-rw-r--r-- | src/ipcpd/normal/CMakeLists.txt | 2 | ||||
-rw-r--r-- | src/ipcpd/normal/main.c | 10 | ||||
-rw-r--r-- | src/tools/irm/irm_ipcp_bootstrap.c | 42 | ||||
-rw-r--r-- | src/tools/irm/irm_ipcp_enroll.c | 38 |
4 files changed, 65 insertions, 27 deletions
diff --git a/src/ipcpd/normal/CMakeLists.txt b/src/ipcpd/normal/CMakeLists.txt index c84d66ce..de0cd4af 100644 --- a/src/ipcpd/normal/CMakeLists.txt +++ b/src/ipcpd/normal/CMakeLists.txt @@ -50,7 +50,7 @@ set(SOURCE_FILES add_executable(ipcpd-normal ${SOURCE_FILES} ${IPCP_SOURCES} ${FLOW_ALLOC_SRCS} ${LS_PROTO_SRCS} ${KAD_PROTO_SRCS} ${ENROLL_PROTO_SRCS}) -target_link_libraries(ipcpd-normal LINK_PUBLIC ouroboros-dev ouroboros-irm) +target_link_libraries(ipcpd-normal LINK_PUBLIC ouroboros-dev) include(AddCompileFlags) if (CMAKE_BUILD_TYPE MATCHES "Debug*") diff --git a/src/ipcpd/normal/main.c b/src/ipcpd/normal/main.c index 719be77c..772b5792 100644 --- a/src/ipcpd/normal/main.c +++ b/src/ipcpd/normal/main.c @@ -29,7 +29,6 @@ #include <ouroboros/errno.h> #include <ouroboros/hash.h> #include <ouroboros/ipcp-dev.h> -#include <ouroboros/irm.h> #include <ouroboros/logs.h> #include <ouroboros/notifier.h> #include <ouroboros/rib.h> @@ -304,11 +303,6 @@ int main(int argc, goto fail_init; } - if (irm_bind_api(getpid(), ipcpi.name)) { - log_err("Failed to bind AP name."); - goto fail_bind_api; - } - /* These components must be init at creation. */ if (rib_init("ipcpd-normal")) { log_err("Failed to initialize RIB."); @@ -357,8 +351,6 @@ int main(int argc, rib_fini(); - irm_unbind_api(getpid(), ipcpi.name); - ipcp_fini(); exit(EXIT_SUCCESS); @@ -374,8 +366,6 @@ int main(int argc, fail_connmgr_init: rib_fini(); fail_rib_init: - irm_unbind_api(getpid(), ipcpi.name); - fail_bind_api: ipcp_fini(); fail_init: ipcp_create_r(getpid(), -1); 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; } |