X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_setup.c;h=4b90737f3c68d4e8d43baf473e110f27ab2c4bf8;hp=3268f5db24b9c732b0a6371731efa77d3733c37c;hb=c373de2e9812700c0568640727ad917b6fc7d758;hpb=3b1fad04de6bed2f284fdf3d5b27d4162aeebc8c diff --git a/src/net_setup.c b/src/net_setup.c index 3268f5db..4b90737f 100644 --- a/src/net_setup.c +++ b/src/net_setup.c @@ -221,7 +221,6 @@ void load_all_subnets(void) { config_t *cfg; subnet_t *s, *s2; node_t *n; - bool result; xasprintf(&dname, "%s/hosts", confbase); dir = opendir(dname); @@ -243,10 +242,9 @@ void load_all_subnets(void) { xasprintf(&fname, "%s/hosts/%s", confbase, ent->d_name); init_configuration(&config_tree); - result = read_config_file(config_tree, fname); + read_config_options(config_tree, ent->d_name); + read_config_file(config_tree, fname); free(fname); - if(!result) - continue; if(!n) { n = new_node(); @@ -356,6 +354,7 @@ static bool setup_myself(void) { get_config_bool(lookup_config(config_tree, "DirectOnly"), &directonly); get_config_bool(lookup_config(config_tree, "StrictSubnets"), &strictsubnets); get_config_bool(lookup_config(config_tree, "TunnelServer"), &tunnelserver); + get_config_bool(lookup_config(config_tree, "LocalDiscovery"), &localdiscovery); strictsubnets |= tunnelserver; if(get_config_string(lookup_config(config_tree, "Mode"), &mode)) { @@ -397,6 +396,8 @@ static bool setup_myself(void) { myself->options |= OPTION_CLAMP_MSS; get_config_bool(lookup_config(config_tree, "PriorityInheritance"), &priorityinheritance); + get_config_bool(lookup_config(config_tree, "DecrementTTL"), &decrement_ttl); + get_config_bool(lookup_config(config_tree, "Broadcast"), &broadcast); #if !defined(SOL_IP) || !defined(IP_TOS) if(priorityinheritance) @@ -547,6 +548,8 @@ static bool setup_myself(void) { devops = dummy_devops; else if(!strcasecmp(type, "raw_socket")) devops = raw_socket_devops; + else if(!strcasecmp(type, "multicast")) + devops = multicast_devops; #ifdef ENABLE_UML else if(!strcasecmp(type, "uml")) devops = uml_devops; @@ -578,47 +581,71 @@ static bool setup_myself(void) { /* Open sockets */ - get_config_string(lookup_config(config_tree, "BindToAddress"), &address); + listen_sockets = 0; + cfg = lookup_config(config_tree, "BindToAddress"); - hint.ai_family = addressfamily; - hint.ai_socktype = SOCK_STREAM; - hint.ai_protocol = IPPROTO_TCP; - hint.ai_flags = AI_PASSIVE; + do { + get_config_string(cfg, &address); + if(cfg) + cfg = lookup_config_next(config_tree, cfg); - err = getaddrinfo(address, myport, &hint, &ai); + char *port = myport; - if(err || !ai) { - logger(LOG_ERR, "System call `%s' failed: %s", "getaddrinfo", - gai_strerror(err)); - return false; - } + if(address) { + char *space = strchr(address, ' '); + if(space) { + *space++ = 0; + port = space; + } - listen_sockets = 0; + if(!strcmp(address, "*")) + *address = 0; + } - for(aip = ai; aip; aip = aip->ai_next) { - listen_socket[listen_sockets].tcp = - setup_listen_socket((sockaddr_t *) aip->ai_addr); + hint.ai_family = addressfamily; + hint.ai_socktype = SOCK_STREAM; + hint.ai_protocol = IPPROTO_TCP; + hint.ai_flags = AI_PASSIVE; - if(listen_socket[listen_sockets].tcp < 0) - continue; + err = getaddrinfo(address && *address ? address : NULL, port, &hint, &ai); + free(address); - listen_socket[listen_sockets].udp = - setup_vpn_in_socket((sockaddr_t *) aip->ai_addr); + if(err || !ai) { + logger(LOG_ERR, "System call `%s' failed: %s", "getaddrinfo", + gai_strerror(err)); + return false; + } - if(listen_socket[listen_sockets].udp < 0) - continue; + for(aip = ai; aip; aip = aip->ai_next) { + if(listen_sockets >= MAXSOCKETS) { + logger(LOG_ERR, "Too many listening sockets"); + return false; + } - ifdebug(CONNECTIONS) { - hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr); - logger(LOG_NOTICE, "Listening on %s", hostname); - free(hostname); - } + listen_socket[listen_sockets].tcp = + setup_listen_socket((sockaddr_t *) aip->ai_addr); - memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen); - listen_sockets++; - } + if(listen_socket[listen_sockets].tcp < 0) + continue; + + listen_socket[listen_sockets].udp = + setup_vpn_in_socket((sockaddr_t *) aip->ai_addr); + + if(listen_socket[listen_sockets].udp < 0) + continue; + + ifdebug(CONNECTIONS) { + hostname = sockaddr2hostname((sockaddr_t *) aip->ai_addr); + logger(LOG_NOTICE, "Listening on %s", hostname); + free(hostname); + } + + memcpy(&listen_socket[listen_sockets].sa, aip->ai_addr, aip->ai_addrlen); + listen_sockets++; + } - freeaddrinfo(ai); + freeaddrinfo(ai); + } while(cfg); if(listen_sockets) logger(LOG_NOTICE, "Ready");