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 3bfc2ab..9b06d4d 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 4b597ad..c08153f 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 5e0fff2..86ed951 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 c5c8bcd..ea66384 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 98b607a..b940035 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 3e032b6..b1a30d2 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 b75f824..1b9d894 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 06dffc9..571b1ba 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 1752d47..0e23486 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 a9ea6eb..3054a98 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;