X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_setup.c;h=e3c543c9d8511ea1c1ece523d52c538be0e8c17f;hb=313a752cb5fbf27450d34c15b0085d2d8a4147af;hp=f0ccc3c85ca168be19f501a4f93465169c94ffa7;hpb=f0885b8d2fe69610e7e294735795d98db11157a5;p=tinc diff --git a/src/net_setup.c b/src/net_setup.c index f0ccc3c8..e3c543c9 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -46,6 +46,7 @@ char *myport; static io_t device_io; devops_t devops; +bool device_standby = false; char *proxyhost; char *proxyport; @@ -416,7 +417,7 @@ char *get_name(void) { return false; } if(gethostname(hostname, sizeof hostname) || !*hostname) { - logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", strerror(errno)); + logger(DEBUG_ALWAYS, LOG_ERR, "Could not get hostname: %s\n", sockstrerror(sockerrno)); return false; } hostname[31] = 0; @@ -726,6 +727,40 @@ static bool add_listen_address(char *address, bool bindto) { return true; } +void device_enable(void) { + if (devops.enable) + devops.enable(); + + /* Run tinc-up script to further initialize the tap interface */ + + char *envp[5] = {NULL}; + xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[3], "NAME=%s", myself->name); + + execute_script("tinc-up", envp); + + for(int i = 0; i < 4; i++) + free(envp[i]); +} + +void device_disable(void) { + char *envp[5] = {NULL}; + xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); + xasprintf(&envp[1], "DEVICE=%s", device ? : ""); + xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); + xasprintf(&envp[3], "NAME=%s", myself->name); + + execute_script("tinc-down", envp); + + for(int i = 0; i < 4; i++) + free(envp[i]); + + if (devops.disable) + devops.disable(); +} + /* Configure node_t myself and set up the local sockets (listen only) */ @@ -918,6 +953,8 @@ static bool setup_myself(void) { #endif } + get_config_bool(lookup_config(config_tree, "DeviceStandby"), &device_standby); + if(!devops.setup()) return false; @@ -943,7 +980,7 @@ static bool setup_myself(void) { for(int i = 0; i < listen_sockets; i++) { salen = sizeof sa; if(getsockname(i + 3, &sa.sa, &salen) < 0) { - logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(errno)); + logger(DEBUG_ALWAYS, LOG_ERR, "Could not get address of listen fd %d: %s", i + 3, sockstrerror(sockerrno)); return false; } @@ -1048,18 +1085,8 @@ bool setup_network(void) { if(!init_control()) return false; - /* Run tinc-up script to further initialize the tap interface */ - - char *envp[5] = {NULL}; - xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); - xasprintf(&envp[1], "DEVICE=%s", device ? : ""); - xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); - xasprintf(&envp[3], "NAME=%s", myself->name); - - execute_script("tinc-up", envp); - - for(int i = 0; i < 4; i++) - free(envp[i]); + if (!device_standby) + device_enable(); /* Run subnet-up scripts for our own subnets */ @@ -1098,25 +1125,17 @@ void close_network_connections(void) { close(listen_socket[i].udp.fd); } - char *envp[5] = {NULL}; - xasprintf(&envp[0], "NETNAME=%s", netname ? : ""); - xasprintf(&envp[1], "DEVICE=%s", device ? : ""); - xasprintf(&envp[2], "INTERFACE=%s", iface ? : ""); - xasprintf(&envp[3], "NAME=%s", myself->name); - exit_requests(); exit_edges(); exit_subnets(); exit_nodes(); exit_connections(); - execute_script("tinc-down", envp); + if (!device_standby) + device_disable(); if(myport) free(myport); - for(int i = 0; i < 4; i++) - free(envp[i]); - if (device_fd >= 0) io_del(&device_io); devops.close();