Browse code

Patch to support --topology subnet on Mac OS X (Mathias Sundman).

git-svn-id: http://svn.openvpn.net/projects/openvpn/branches/BETA21/openvpn@832 e7ae566f-a301-0410-adde-c780ea21d3b5

james authored on 2005/12/05 10:21:49
Showing 4 changed files
... ...
@@ -16,6 +16,7 @@ $Id$
16 16
   (David Stipp).
17 17
 * Fixed typo in manage.c where inline function declaration
18 18
   was declared without the "static" keyword (David Stipp).
19
+* Patch to support --topology subnet on Mac OS X (Mathias Sundman).
19 20
 
20 21
 2005.11.12 -- Version 2.1-beta7
21 22
 
... ...
@@ -45,7 +45,6 @@
45 45
 
46 46
 #include "memdbg.h"
47 47
 
48
-static void add_route (struct route *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
49 48
 static void delete_route (const struct route *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
50 49
 static bool get_default_gateway (in_addr_t *ret);
51 50
 static void get_bypass_addresses (struct route_bypass *rb, const unsigned int flags);
... ...
@@ -741,7 +740,7 @@ setenv_routes (struct env_set *es, const struct route_list *rl)
741 741
     setenv_route (es, &rl->routes[i], i + 1);
742 742
 }
743 743
 
744
-static void
744
+void
745 745
 add_route (struct route *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es)
746 746
 {
747 747
   struct gc_arena gc;
... ...
@@ -118,6 +118,8 @@ struct route_option_list *new_route_option_list (struct gc_arena *a);
118 118
 
119 119
 struct route_list *new_route_list (struct gc_arena *a);
120 120
 
121
+void add_route (struct route *r, const struct tuntap *tt, unsigned int flags, const struct env_set *es);
122
+
121 123
 void add_route_to_option_list (struct route_option_list *l,
122 124
 			       const char *network,
123 125
 			       const char *netmask,
... ...
@@ -44,6 +44,7 @@
44 44
 #include "misc.h"
45 45
 #include "socket.h"
46 46
 #include "manage.h"
47
+#include "route.h"
47 48
 
48 49
 #include "memdbg.h"
49 50
 
... ...
@@ -746,18 +747,41 @@ do_ifconfig (struct tuntap *tt,
746 746
 			  tun_mtu
747 747
 			  );
748 748
       else
749
-	openvpn_snprintf (command_line, sizeof (command_line),
750
-			  IFCONFIG_PATH " %s %s netmask %s mtu %d up",
751
-			  actual,
752
-			  ifconfig_local,
753
-			  ifconfig_remote_netmask,
754
-			  tun_mtu
755
-			  );
756
-
749
+        {
750
+          if (tt->topology == TOP_SUBNET)
751
+    	    openvpn_snprintf (command_line, sizeof (command_line),
752
+			      IFCONFIG_PATH " %s %s %s netmask %s mtu %d up",
753
+			      actual,
754
+			      ifconfig_local,
755
+			      ifconfig_local,
756
+			      ifconfig_remote_netmask,
757
+			      tun_mtu
758
+			      );
759
+	  else
760
+    	    openvpn_snprintf (command_line, sizeof (command_line),
761
+			      IFCONFIG_PATH " %s %s netmask %s mtu %d up",
762
+			      actual,
763
+			      ifconfig_local,
764
+			      ifconfig_remote_netmask,
765
+			      tun_mtu
766
+			      );
767
+	}
757 768
       msg (M_INFO, "%s", command_line);
758 769
       system_check (command_line, es, S_FATAL, "Mac OS X ifconfig failed");
759 770
       tt->did_ifconfig = true;
760 771
 
772
+      /* Add a network route for the local tun interface */
773
+      if (!tun && tt->topology == TOP_SUBNET)
774
+	{
775
+	  struct route r;
776
+	  CLEAR (r);
777
+	  r.defined = true;
778
+	  r.network = tt->local & tt->remote_netmask;
779
+	  r.netmask = tt->remote_netmask;
780
+	  r.gateway = tt->local;
781
+	  add_route (&r, tt, 0, es);
782
+	}
783
+
761 784
 #elif defined(TARGET_FREEBSD)
762 785
 
763 786
       /* example: ifconfig tun2 10.2.0.2 10.2.0.1 mtu 1450 netmask 255.255.255.255 up */