- Added two extra configuration options, Interface and InterfaceIP, to
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 9 Aug 2000 14:02:16 +0000 (14:02 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 9 Aug 2000 14:02:16 +0000 (14:02 +0000)
  bind the listen socket to a network device or a specific IP.

src/conf.c
src/conf.h
src/net.c

index 3b1eb49..bfa0fee 100644 (file)
@@ -19,7 +19,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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 },
   { "Hostnames",    resolve_dns,    TYPE_BOOL },
   { "IndirectData", indirectdata,   TYPE_BOOL },
   { "TCPonly",      tcponly,        TYPE_BOOL },
+  { "Interface",    interface,      TYPE_NAME },
+  { "InterfaceIP",  interfaceip,    TYPE_IP },
   { NULL, 0, 0 }
 };
 
   { NULL, 0, 0 }
 };
 
index ca3c27e..b5d0892 100644 (file)
@@ -17,7 +17,7 @@
     along with this program; if not, write to the Free Software
     Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 
     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__
 */
 
 #ifndef __TINC_CONF_H__
@@ -50,6 +50,8 @@ typedef enum which_t {
   resolve_dns,
   indirectdata,
   tcponly,
   resolve_dns,
   indirectdata,
   tcponly,
+  interface,
+  interfaceip,
 } which_t;
 
 typedef struct config_t {
 } which_t;
 
 typedef struct config_t {
index 3df55a7..7d78060 100644 (file)
--- 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.
 
     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"
 */
 
 #include "config.h"
@@ -157,7 +157,7 @@ cp
   rp->from = ntohl(rp->from);
 
   total_socket_in += rp->len;
   rp->from = ntohl(rp->from);
 
   total_socket_in += rp->len;
-  
+
   if(rp->len >= 0)
     {
       f = lookup_conn(rp->from);
   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;
   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)
     {
 cp
   if((nfd = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
     {
@@ -486,10 +487,23 @@ cp
       return -1;
     }
 
       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);
   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)))
     {
 
   if(bind(nfd, (struct sockaddr *)&a, sizeof(struct sockaddr)))
     {
@@ -1128,7 +1142,7 @@ cp
       return -1;
     }
 
       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)
     {
 
   if(lenin<=0)
     {