--- gvpe/src/device-tincd.C 2004/01/29 18:55:10 1.10 +++ gvpe/src/device-tincd.C 2007/12/02 00:45:42 1.20 @@ -1,8 +1,10 @@ /* device-tincd.C -- include one of the tincd low level implementations. - Copyright (C) 2003-2004 Marc Lehmann + Copyright (C) 2003-2005 Marc Lehmann - This program is free software; you can redistribute it and/or modify + This file is part of GVPE. + + GVPE is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. @@ -13,8 +15,8 @@ GNU General Public License for more details. You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + along with gvpe; if not, write to the Free Software + Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA */ #include @@ -61,11 +63,12 @@ #define cp() #define lookup_config(config_tree,key) (key) -#define MTU MAXSIZE +#define MTU MAX_MTU // BIGGEST hack of 'em all // will be casted to data_packet, due to structural similarity -struct vpn_packet_t : net_packet { +struct vpn_packet_t : net_packet +{ u8 data[MAXSIZE]; }; @@ -78,6 +81,8 @@ *res = conf.ifname; else if (!strcmp (key, "Device")) *res = 0; + else if (!strcmp (key, "DeviceType")) + *res = "tap"; else { slog (L_ERR, _("tincd layer asking for unknown config '%s'"), key); @@ -91,34 +96,51 @@ #if IF_linux # include "tincd/linux/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME hw ether $MAC mtu $MTU"; } + +#elif IF_bsd +# include "tincd/bsd/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } #elif IF_freebsd # include "tincd/freebsd/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } #elif IF_netbsd -#define IF_istun 1 +# define IF_istun 1 # include "tincd/netbsd/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME mtu $MTU"; } #elif IF_openbsd -#define IF_istun 1 +# define IF_istun 1 # include "tincd/openbsd/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME mtu $MTU"; } #elif IF_solaris +# define IF_istun 1 # include "tincd/solaris/device.c" +const char * tap_device::if_up () { return ""; } #elif IF_cygwin # include "tincd/cygwin/device.c" +const char * tap_device::if_up () { return ""; } #elif IF_mingw # include "tincd/mingw/device.c" +const char * tap_device::if_up () { return ""; } #elif IF_darwin -#define IF_istun 1 +# define IF_istun 1 # include "tincd/darwin/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } #elif IF_raw_socket -#define IF_istun 1 # include "tincd/raw_socket/device.c" +const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } + +#elif IF_uml_socket +# include "tincd/uml_socket/device.c" +const char * tap_device::if_up () { return 0; } #else # error No interface implementation for your IFTYPE/IFSUBTYPE combination. @@ -138,7 +160,12 @@ { device = "(null)"; - if (setup_device ()) + bool ok = setup_device (); + + if (device_info) + device = device_info; + + if (ok) { slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); fd = device_fd; @@ -164,7 +191,7 @@ if (!read_packet (reinterpret_cast(pkt))) { delete pkt; - slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, + slog (L_ERR, _("can't read from to %s %s: %s"), info (), device, strerror (errno)); return 0; } @@ -192,7 +219,7 @@ ether_emu.tap_to_tun (pkt) && #endif !write_packet (reinterpret_cast(pkt))) - slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, + slog (L_ERR, _("can't write to %s %s: %s"), info (), device, strerror (errno)); }