From: Guus Sliepen Date: Wed, 9 Aug 2000 14:02:16 +0000 (+0000) Subject: - Added two extra configuration options, Interface and InterfaceIP, to X-Git-Tag: release-1.0pre3~140 X-Git-Url: https://tinc-vpn.org/git/browse?a=commitdiff_plain;h=9acd4379f705edc8b736e21b9011434e63f7dd95;p=tinc - Added two extra configuration options, Interface and InterfaceIP, to bind the listen socket to a network device or a specific IP. --- diff --git a/src/conf.c b/src/conf.c index 3b1eb49c..bfa0fee1 100644 --- a/src/conf.c +++ b/src/conf.c @@ -19,7 +19,7 @@ along with this program; if not, write to the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. - $Id: conf.c,v 1.9.4.7 2000/08/07 14:52:14 guus Exp $ + $Id: conf.c,v 1.9.4.8 2000/08/09 14:02:15 guus Exp $ */ @@ -72,6 +72,8 @@ static internal_config_t hazahaza[] = { { "Hostnames", resolve_dns, TYPE_BOOL }, { "IndirectData", indirectdata, TYPE_BOOL }, { "TCPonly", tcponly, TYPE_BOOL }, + { "Interface", interface, TYPE_NAME }, + { "InterfaceIP", interfaceip, TYPE_IP }, { NULL, 0, 0 } }; diff --git a/src/conf.h b/src/conf.h index ca3c27e1..b5d08924 100644 --- a/src/conf.h +++ b/src/conf.h @@ -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: conf.h,v 1.6.4.7 2000/08/07 16:27:27 guus Exp $ + $Id: conf.h,v 1.6.4.8 2000/08/09 14:02:16 guus Exp $ */ #ifndef __TINC_CONF_H__ @@ -50,6 +50,8 @@ typedef enum which_t { resolve_dns, indirectdata, tcponly, + interface, + interfaceip, } which_t; typedef struct config_t { diff --git a/src/net.c b/src/net.c index 3df55a76..7d780608 100644 --- a/src/net.c +++ b/src/net.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.c,v 1.35.4.25 2000/08/09 09:34:21 guus Exp $ + $Id: net.c,v 1.35.4.26 2000/08/09 14:02:16 guus Exp $ */ #include "config.h" @@ -157,7 +157,7 @@ cp rp->from = ntohl(rp->from); total_socket_in += rp->len; - + if(rp->len >= 0) { f = lookup_conn(rp->from); @@ -460,6 +460,7 @@ int setup_listen_meta_socket(int port) int nfd, flags; struct sockaddr_in a; const int one = 1; + config_t const *cfg; cp if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0) { @@ -486,10 +487,23 @@ cp return -1; } + if((cfg = get_config_val(interface))) + { + if(setsockopt(nfd, SOL_SOCKET, SO_KEEPALIVE, cfg->data.ptr, strlen(cfg->data.ptr))) + { + syslog(LOG_ERR, _("Unable to bind listen socket to interface %s: %m"), cfg->data.ptr); + return -1; + } + } + memset(&a, 0, sizeof(a)); a.sin_family = AF_INET; a.sin_port = htons(port); - a.sin_addr.s_addr = htonl(INADDR_ANY); + + if((cfg = get_config_val(interfaceip))) + a.sin_addr.s_addr = htonl(cfg->data.ip->ip); + else + a.sin_addr.s_addr = htonl(INADDR_ANY); if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr))) { @@ -1128,7 +1142,7 @@ cp return -1; } - lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE-cl->buflen); + lenin = read(cl->meta_socket, cl->buffer, MAXBUFSIZE - cl->buflen); if(lenin<=0) {