Remove mymac stuff from device.c.
authorGuus Sliepen <guus@tinc-vpn.org>
Wed, 11 Jun 2003 19:28:38 +0000 (19:28 +0000)
committerGuus Sliepen <guus@tinc-vpn.org>
Wed, 11 Jun 2003 19:28:38 +0000 (19:28 +0000)
src/cygwin/device.c
src/darwin/device.c
src/freebsd/device.c
src/linux/device.c
src/netbsd/device.c
src/openbsd/device.c
src/raw_socket/device.c
src/route.c
src/route.h
src/solaris/device.c

index 3bfc2ab1e1540cf0fc4aae867efa1fc0b39e6bcb..9b06d4d15ae2c029ecc6ba84536cf09c004f64f6 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: device.c,v 1.1.2.4 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.5 2003/06/11 19:28:36 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -47,8 +47,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 int setup_device(void)
 {
        struct ifreq ifr;
 int setup_device(void)
 {
        struct ifreq ifr;
@@ -66,15 +64,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        device_info = _("Stub device for Cygwin environment");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
        device_info = _("Stub device for Cygwin environment");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
index 4b597ad2f912271a578009b713cf08ab21dd5f53..c08153fe20083a15f3a3668b259e247163c74c2a 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: device.c,v 1.1.2.5 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.6 2003/06/11 19:28:36 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -51,8 +51,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 /*
   open the local ethertap device
 */
 /*
   open the local ethertap device
 */
@@ -71,15 +69,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        device_info = _("MacOS/X tun device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
        device_info = _("MacOS/X tun device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
@@ -110,8 +99,6 @@ int read_packet(vpn_packet_t *packet)
                return -1;
        }
 
                return -1;
        }
 
-       memcpy(packet->data, mymac.net.mac.address.x, 6);
-       memcpy(packet->data + 6, mymac.net.mac.address.x, 6);
        packet->data[12] = 0x08;
        packet->data[13] = 0x00;
 
        packet->data[12] = 0x08;
        packet->data[13] = 0x00;
 
index 5e0fff255585e1a851d81a42a4daeb5a4d4d1a41..86ed951b46f665a8e7f7ba0561d80a0930de7323 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: device.c,v 1.1.2.8 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.9 2003/06/11 19:28:37 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -51,8 +51,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 /*
   open the local ethertap device
 */
 /*
   open the local ethertap device
 */
@@ -71,15 +69,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        device_info = _("FreeBSD tap device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
        device_info = _("FreeBSD tap device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
index c5c8bcd4eec20ab815ad9f0d2dc618811e5b0831..ea66384604fef2849d42e17a4a403410c38748b2 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: device.c,v 1.1.2.14 2003/06/11 19:09:52 guus Exp $
+    $Id: device.c,v 1.1.2.15 2003/06/11 19:28:37 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -68,8 +68,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 /*
   open the local ethertap device
 */
 /*
   open the local ethertap device
 */
@@ -95,15 +93,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
 #ifdef HAVE_TUNTAP
        /* Ok now check if this is an old ethertap or a new tun/tap thingie */
 
 #ifdef HAVE_TUNTAP
        /* Ok now check if this is an old ethertap or a new tun/tap thingie */
 
@@ -131,6 +120,8 @@ int setup_device(void)
        } else
 #endif
        {
        } else
 #endif
        {
+               if(routing_mode == RMODE_ROUTER)
+                       overwrite_mac = 1;
                device_info = _("Linux ethertap device");
                device_type = DEVICE_TYPE_ETHERTAP;
                interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
                device_info = _("Linux ethertap device");
                device_type = DEVICE_TYPE_ETHERTAP;
                interface = rindex(device, '/') ? rindex(device, '/') + 1 : device;
index 98b607a32d8de8de3b8cea4b119d13c920d97f3a..b9400358e0ee5c9820004625699027aa13b12ebe 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: device.c,v 1.1.2.7 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.8 2003/06/11 19:28:37 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -56,8 +56,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 /*
   open the local ethertap device
 */
 /*
   open the local ethertap device
 */
@@ -75,15 +73,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        device_info = _("NetBSD tun device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
        device_info = _("NetBSD tun device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
@@ -110,8 +99,6 @@ int read_packet(vpn_packet_t *packet)
                return -1;
        }
 
                return -1;
        }
 
-       memcpy(packet->data, mymac.net.mac.address.x, 6);
-       memcpy(packet->data + 6, mymac.net.mac.address.x, 6);
        packet->data[12] = 0x08;
        packet->data[13] = 0x00;
 
        packet->data[12] = 0x08;
        packet->data[13] = 0x00;
 
index 3e032b6cfa2a375206e45cbeeeee22da71709cbe..b1a30d22a370c888296190df5aed1cd1a17c3e6f 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: device.c,v 1.1.2.12 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.13 2003/06/11 19:28:37 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -56,8 +56,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 /*
   open the local ethertap device
 */
 /*
   open the local ethertap device
 */
@@ -75,15 +73,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        device_info = _("OpenBSD tun device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
        device_info = _("OpenBSD tun device");
 
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
@@ -112,9 +101,6 @@ int read_packet(vpn_packet_t *packet)
                return -1;
        }
 
                return -1;
        }
 
-       memcpy(packet->data, mymac.net.mac.address.x, 6);
-       memcpy(packet->data + 6, mymac.net.mac.address.x, 6);
-
        switch (ntohl(type)) {
                case AF_INET:
                        packet->data[12] = 0x8;
        switch (ntohl(type)) {
                case AF_INET:
                        packet->data[12] = 0x8;
index b75f824d31090d21902710a32898f953467bfd17..1b9d8949fd56a69cab03a252ccdaf1717fbcb554 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: device.c,v 1.1.2.4 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.5 2003/06/11 19:28:38 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -53,8 +53,6 @@ char *device_info;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-extern subnet_t mymac;
-
 /*
   open the local ethertap device
 */
 /*
   open the local ethertap device
 */
@@ -99,15 +97,6 @@ int setup_device(void)
                return -1;
        }
 
                return -1;
        }
 
-       /* Set default MAC address for ethertap devices */
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
 
        return 0;
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
 
        return 0;
index 06dffc97324a20cc95ee449ba67840e00754f32e..571b1ba2edc8a25ea7eb2c18238865f95955f5df 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: route.c,v 1.1.2.49 2003/03/29 22:11:22 guus Exp $
+    $Id: route.c,v 1.1.2.50 2003/06/11 19:28:35 guus Exp $
 */
 
 #include "config.h"
 */
 
 #include "config.h"
@@ -67,7 +67,8 @@
 int routing_mode = RMODE_ROUTER;
 int priorityinheritance = 0;
 int macexpire = 600;
 int routing_mode = RMODE_ROUTER;
 int priorityinheritance = 0;
 int macexpire = 600;
-subnet_t mymac;
+int overwrite_mac = 0;
+mac_t mymac = {0xFE, 0xFD, 0, 0, 0, 0};
 
 /* RFC 1071 */
 
 
 /* RFC 1071 */
 
@@ -397,7 +398,8 @@ void route_neighborsol(vpn_packet_t *packet)
 
        /* First, snatch the source address from the neighbor solicitation packet */
 
 
        /* First, snatch the source address from the neighbor solicitation packet */
 
-       memcpy(mymac.net.mac.address.x, packet->data + 6, 6);
+       if(overwrite_mac)
+               memcpy(mymac.x, packet->data + 6, 6);
 
        /* Check if this is a valid neighbor solicitation request */
 
 
        /* Check if this is a valid neighbor solicitation request */
 
@@ -499,7 +501,8 @@ void route_arp(vpn_packet_t *packet)
 
        /* First, snatch the source address from the ARP packet */
 
 
        /* First, snatch the source address from the ARP packet */
 
-       memcpy(mymac.net.mac.address.x, packet->data + 6, 6);
+       if(overwrite_mac)
+               memcpy(mymac.x, packet->data + 6, 6);
 
        /* This routine generates replies to ARP requests.
           You don't need to set NOARP flag on the interface anymore (which is broken on FreeBSD).
 
        /* This routine generates replies to ARP requests.
           You don't need to set NOARP flag on the interface anymore (which is broken on FreeBSD).
@@ -628,7 +631,8 @@ void route_incoming(node_t *source, vpn_packet_t *packet)
 
                                if(n) {
                                        if(n == myself) {
 
                                if(n) {
                                        if(n == myself) {
-                                               memcpy(packet->data, mymac.net.mac.address.x, 6);
+                                               if(overwrite_mac)
+                                                       memcpy(packet->data, mymac.x, 6);
                                                write_packet(packet);
                                        } else
                                                send_packet(n, packet);
                                                write_packet(packet);
                                        } else
                                                send_packet(n, packet);
index 1752d4704a4c86027fdaf65cbb4c1650d2e182c7..0e23486fc1f1a04c71193290869d6c87bf2350dc 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: route.h,v 1.1.2.9 2002/09/09 21:25:07 guus Exp $
+    $Id: route.h,v 1.1.2.10 2003/06/11 19:28:35 guus Exp $
 */
 
 #ifndef __TINC_ROUTE_H__
 */
 
 #ifndef __TINC_ROUTE_H__
@@ -30,6 +30,7 @@ enum {
 };
 
 extern int routing_mode;
 };
 
 extern int routing_mode;
+extern int overwrite_mac;
 extern int priorityinheritance;
 extern int macexpire;
 
 extern int priorityinheritance;
 extern int macexpire;
 
index a9ea6eb9d60074d02b97ef323eba96b754ce5ac9..3054a98f1b083afeb571add6efb4916062730545 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: device.c,v 1.1.2.11 2002/09/10 21:29:42 guus Exp $
+    $Id: device.c,v 1.1.2.12 2003/06/11 19:28:38 guus Exp $
 */
 
 
 */
 
 
@@ -57,8 +57,6 @@ char *device_info = NULL;
 int device_total_in = 0;
 int device_total_out = 0;
 
 int device_total_in = 0;
 int device_total_out = 0;
 
-subnet_t mymac;
-
 int setup_device(void)
 {
        int ip_fd = -1, if_fd = -1;
 int setup_device(void)
 {
        int ip_fd = -1, if_fd = -1;
@@ -120,16 +118,6 @@ int setup_device(void)
 
        device_info = _("Solaris tun device");
 
 
        device_info = _("Solaris tun device");
 
-       /* Set default MAC address for ethertap devices */
-
-       mymac.type = SUBNET_MAC;
-       mymac.net.mac.address.x[0] = 0xfe;
-       mymac.net.mac.address.x[1] = 0xfd;
-       mymac.net.mac.address.x[2] = 0x00;
-       mymac.net.mac.address.x[3] = 0x00;
-       mymac.net.mac.address.x[4] = 0x00;
-       mymac.net.mac.address.x[5] = 0x00;
-
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
 
        return 0;
        syslog(LOG_INFO, _("%s is a %s"), device, device_info);
 
        return 0;
@@ -154,8 +142,6 @@ int read_packet(vpn_packet_t *packet)
                return -1;
        }
 
                return -1;
        }
 
-       memcpy(packet->data, mymac.net.mac.address.x, 6);
-       memcpy(packet->data + 6, mymac.net.mac.address.x, 6);
        packet->data[12] = 0x08;
        packet->data[13] = 0x00;
 
        packet->data[12] = 0x08;
        packet->data[13] = 0x00;