X-Git-Url: https://www.tinc-vpn.org/git/browse?p=tinc;a=blobdiff_plain;f=src%2Fnet_socket.c;h=b90dcf540b08f604b4862061b8c6ffb531fd47af;hp=78e1ad2c2703f945260f517af236551fa70f3a95;hb=9bab08e972ae0ca4b904a659d9aed46aaa9b5dd5;hpb=721e4caee0f7c6e003c297c95fb6d93bd4102219 diff --git a/src/net_socket.c b/src/net_socket.c index 78e1ad2c..b90dcf54 100644 --- a/src/net_socket.c +++ b/src/net_socket.c @@ -17,7 +17,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: net_socket.c,v 1.1.2.33 2003/07/29 22:59:00 guus Exp $ + $Id: net_socket.c,v 1.1.2.37 2003/12/20 21:09:33 guus Exp $ */ #include "system.h" @@ -49,31 +49,30 @@ int listen_sockets; int setup_listen_socket(const sockaddr_t *sa) { - int nfd, flags; + int nfd; char *addrstr; int option; char *iface; -#ifdef SO_BINDTODEVICE - struct ifreq ifr; -#endif cp(); nfd = socket(sa->sa.sa_family, SOCK_STREAM, IPPROTO_TCP); if(nfd < 0) { - logger(LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno)); + ifdebug(STATUS) logger(LOG_ERR, _("Creating metasocket failed: %s"), strerror(errno)); return -1; } #ifdef O_NONBLOCK - flags = fcntl(nfd, F_GETFL); + { + int flags = fcntl(nfd, F_GETFL); - if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { - closesocket(nfd); - logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", - strerror(errno)); - return -1; + if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { + closesocket(nfd); + logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", + strerror(errno)); + return -1; + } } #endif @@ -94,6 +93,8 @@ int setup_listen_socket(const sockaddr_t *sa) if(get_config_string (lookup_config(config_tree, "BindToInterface"), &iface)) { #if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) + struct ifreq ifr; + memset(&ifr, 0, sizeof(ifr)); strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ); @@ -129,13 +130,9 @@ int setup_listen_socket(const sockaddr_t *sa) int setup_vpn_in_socket(const sockaddr_t *sa) { - int nfd, flags; + int nfd; char *addrstr; int option; -#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) - char *iface; - struct ifreq ifr; -#endif cp(); @@ -147,29 +144,66 @@ int setup_vpn_in_socket(const sockaddr_t *sa) } #ifdef O_NONBLOCK - flags = fcntl(nfd, F_GETFL); - if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { - closesocket(nfd); - logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", - strerror(errno)); - return -1; + { + int flags = fcntl(nfd, F_GETFL); + + if(fcntl(nfd, F_SETFL, flags | O_NONBLOCK) < 0) { + closesocket(nfd); + logger(LOG_ERR, _("System call `%s' failed: %s"), "fcntl", + strerror(errno)); + return -1; + } } #endif option = 1; setsockopt(nfd, SOL_SOCKET, SO_REUSEADDR, &option, sizeof(option)); -#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) - if(get_config_string - (lookup_config(config_tree, "BindToInterface"), &iface)) { - memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ); +#if defined(SOL_IP) && defined(IP_MTU_DISCOVER) && defined(IP_PMTUDISC_DO) + { + bool choice; + + if(sa->sa.sa_family == AF_INET && get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice) { + option = IP_PMTUDISC_DO; + if(setsockopt(nfd, SOL_IP, IP_MTU_DISCOVER, &option, sizeof(option))) { + closesocket(nfd); + logger(LOG_ERR, _("Can't set PMTU discovery mode: %s"), strerror(errno)); + return -1; + } + } + } +#endif - if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr))) { - closesocket(nfd); - logger(LOG_ERR, _("Can't bind to interface %s: %s"), iface, - strerror(errno)); - return -1; +#if defined(SOL_IPV6) && defined(IPV6_MTU_DISCOVER) && defined(IPV6_PMTUDISC_DO) + { + bool choice; + + if(sa->sa.sa_family == AF_INET6 && get_config_bool(lookup_config(myself->connection->config_tree, "PMTUDiscovery"), &choice) && choice) { + option = IPV6_PMTUDISC_DO; + if(setsockopt(nfd, SOL_IPV6, IPV6_MTU_DISCOVER, &option, sizeof(option))) { + closesocket(nfd); + logger(LOG_ERR, _("Can't set PMTU discovery mode: %s"), strerror(errno)); + return -1; + } + } + } +#endif + +#if defined(SOL_SOCKET) && defined(SO_BINDTODEVICE) + { + char *iface; + struct ifreq ifr; + + if(get_config_string(lookup_config(config_tree, "BindToInterface"), &iface)) { + memset(&ifr, 0, sizeof(ifr)); + strncpy(ifr.ifr_ifrn.ifrn_name, iface, IFNAMSIZ); + + if(setsockopt(nfd, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr))) { + closesocket(nfd); + logger(LOG_ERR, _("Can't bind to interface %s: %s"), iface, + strerror(errno)); + return -1; + } } } #endif @@ -255,8 +289,7 @@ begin: goto begin; } - memcpy(&c->address, c->outgoing->aip->ai_addr, - c->outgoing->aip->ai_addrlen); + memcpy(&c->address, c->outgoing->aip->ai_addr, c->outgoing->aip->ai_addrlen); c->outgoing->aip = c->outgoing->aip->ai_next; if(c->hostname)