You can now put an option "Mode" in tinc.conf, and choose from:
authorGuus Sliepen <guus@tinc-vpn.org>
Tue, 5 Jun 2001 19:39:54 +0000 (19:39 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Tue, 5 Jun 2001 19:39:54 +0000 (19:39 +0000)
- Mode = router (default, work like tinc has always worked)
- Mode = switch (work like a switch)
- Mode = hub    (work like a hub, broadcasting everything)

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

index 93c0fa3..0eaf0ca 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.40 2001/01/17 01:30:05 zarq Exp $
+    $Id: conf.c,v 1.9.4.41 2001/06/05 19:39:54 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -83,6 +83,7 @@ static internal_config_t hazahaza[] = {
   { "RestrictSubnets", config_restrictsubnets, TYPE_BOOL },
   { "Subnet",       config_subnet,         TYPE_IP },          /* Use IPv4 subnets only for now */
   { "TCPonly",      config_tcponly,        TYPE_BOOL },
   { "RestrictSubnets", config_restrictsubnets, TYPE_BOOL },
   { "Subnet",       config_subnet,         TYPE_IP },          /* Use IPv4 subnets only for now */
   { "TCPonly",      config_tcponly,        TYPE_BOOL },
+  { "Mode",         config_mode,           TYPE_NAME },
   { NULL, 0, 0 }
 };
 
   { NULL, 0, 0 }
 };
 
index d1fb609..8f0c2b3 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.23 2001/02/27 16:37:24 guus Exp $
+    $Id: conf.h,v 1.6.4.24 2001/06/05 19:39:54 guus Exp $
 */
 
 #ifndef __TINC_CONF_H__
 */
 
 #ifndef __TINC_CONF_H__
@@ -55,6 +55,7 @@ typedef enum which_t {
   config_restrictport,
   config_indirectdata,
   config_tcponly,
   config_restrictport,
   config_indirectdata,
   config_tcponly,
+  config_mode,
 } which_t;
 
 typedef struct config_t {
 } which_t;
 
 typedef struct config_t {
index 266dbab..59ec5f9 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.111 2001/06/05 16:09:55 guus Exp $
+    $Id: net.c,v 1.35.4.112 2001/06/05 19:39:54 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -792,14 +792,6 @@ cp
   else
     myself->port = cfg->data.val;
 
   else
     myself->port = cfg->data.val;
 
-  if((cfg = get_config_val(myself->config, config_indirectdata)))
-    if(cfg->data.val == stupid_true)
-      myself->options |= OPTION_INDIRECT;
-
-  if((cfg = get_config_val(myself->config, config_tcponly)))
-    if(cfg->data.val == stupid_true)
-      myself->options |= OPTION_TCPONLY;
-
 /* Read in all the subnets specified in the host configuration file */
 
   for(next = myself->config; (cfg = get_config_val(next, config_subnet)); next = cfg->next)
 /* Read in all the subnets specified in the host configuration file */
 
   for(next = myself->config; (cfg = get_config_val(next, config_subnet)); next = cfg->next)
@@ -820,6 +812,48 @@ cp
       subnet_add(myself, net);
     }
 
       subnet_add(myself, net);
     }
 
+cp
+  /* Check some options */
+
+  if((cfg = get_config_val(config, config_indirectdata)))
+    if(cfg->data.val == stupid_true)
+      myself->options |= OPTION_INDIRECT;
+
+  if((cfg = get_config_val(config, config_tcponly)))
+    if(cfg->data.val == stupid_true)
+      myself->options |= OPTION_TCPONLY;
+
+  if((cfg = get_config_val(myself->config, config_indirectdata)))
+    if(cfg->data.val == stupid_true)
+      myself->options |= OPTION_INDIRECT;
+
+  if((cfg = get_config_val(myself->config, config_tcponly)))
+    if(cfg->data.val == stupid_true)
+      myself->options |= OPTION_TCPONLY;
+
+  if(myself->options & OPTION_TCPONLY)
+    myself->options |= OPTION_INDIRECT;
+
+  if((cfg = get_config_val(config, config_mode)))
+    {
+      if(!strcasecmp(cfg->data.ptr, "router"))
+        routing_mode = RMODE_ROUTER;
+      else if (!strcasecmp(cfg->data.ptr, "switch"))
+        routing_mode = RMODE_SWITCH;
+      else if (!strcasecmp(cfg->data.ptr, "hub"))
+        routing_mode = RMODE_HUB;
+      else
+        {
+          syslog(LOG_ERR, _("Invalid routing mode!"));
+          return -1;
+        }
+    }
+  else
+    routing_mode = RMODE_ROUTER;
+
+cp
+  /* Open sockets */
+  
   if((myself->meta_socket = setup_listen_meta_socket(myself->port)) < 0)
     {
       syslog(LOG_ERR, _("Unable to set up a listening TCP socket!"));
   if((myself->meta_socket = setup_listen_meta_socket(myself->port)) < 0)
     {
       syslog(LOG_ERR, _("Unable to set up a listening TCP socket!"));
@@ -848,22 +882,6 @@ cp
 
   keyexpires = time(NULL) + keylifetime;
 cp
 
   keyexpires = time(NULL) + keylifetime;
 cp
-  /* Check some options */
-
-  if((cfg = get_config_val(config, config_indirectdata)))
-    {
-      if(cfg->data.val == stupid_true)
-        myself->options |= OPTION_INDIRECT;
-    }
-
-  if((cfg = get_config_val(config, config_tcponly)))
-    {
-      if(cfg->data.val == stupid_true)
-        myself->options |= OPTION_TCPONLY;
-    }
-
-  if(myself->options & OPTION_TCPONLY)
-    myself->options |= OPTION_INDIRECT;
 
   /* Activate ourselves */
 
 
   /* Activate ourselves */