X-Git-Url: https://tinc-vpn.org/git/browse?a=blobdiff_plain;f=src%2Fnet_setup.c;h=c4f2127ec0dee48bfe9a4f79c8ee48cfb35aef60;hb=fcf5b53e785fd191dd951b77ad831fe6ac78dce4;hp=eec1711af9e863b85456f56090f1f2b082388bfc;hpb=132bdb77a0792d85d03ad89f846cbd4024037393;p=tinc diff --git a/src/net_setup.c b/src/net_setup.c index eec1711a..c4f2127e 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -417,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; @@ -532,16 +532,6 @@ bool setup_myself_reloadable(void) { get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly); get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery); - memset(&localdiscovery_address, 0, sizeof localdiscovery_address); - if(get_config_string(lookup_config(config_tree, "LocalDiscoveryAddress"), &address)) { - struct addrinfo *ai = str2addrinfo(address, myport, SOCK_DGRAM); - free(address); - if(!ai) - return false; - memcpy(&localdiscovery_address, ai->ai_addr, ai->ai_addrlen); - } - - if(get_config_string(lookup_config(config_tree, "Mode"), &rmode)) { if(!strcasecmp(rmode, "router")) routing_mode = RMODE_ROUTER; @@ -596,6 +586,20 @@ bool setup_myself_reloadable(void) { free(bmode); } + const char* const DEFAULT_BROADCAST_SUBNETS[] = { "ff:ff:ff:ff:ff:ff", "255.255.255.255", "224.0.0.0/4", "ff00::/8" }; + for (size_t i = 0; i < sizeof(DEFAULT_BROADCAST_SUBNETS) / sizeof(*DEFAULT_BROADCAST_SUBNETS); i++) { + subnet_t *s = new_subnet(); + if (!str2net(s, DEFAULT_BROADCAST_SUBNETS[i])) + abort(); + subnet_add(NULL, s); + } + for (config_t* cfg = lookup_config(config_tree, "BroadcastSubnet"); cfg; cfg = lookup_config_next(config_tree, cfg)) { + subnet_t *s; + if (!get_config_subnet(cfg, &s)) + continue; + subnet_add(NULL, s); + } + #if !defined(SOL_IP) || !defined(IP_TOS) if(priorityinheritance) logger(DEBUG_ALWAYS, LOG_WARNING, "%s not supported on this platform", "PriorityInheritance"); @@ -980,7 +984,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; } @@ -1033,7 +1037,7 @@ static bool setup_myself(void) { /* If no Port option was specified, set myport to the port used by the first listening socket. */ - if(!port_specified) { + if(!port_specified || atoi(myport) == 0) { sockaddr_t sa; socklen_t salen = sizeof sa; if(!getsockname(listen_socket[0].udp.fd, &sa.sa, &salen)) {