ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/gvpe/src/device-tincd.C
(Generate patch)

Comparing gvpe/src/device-tincd.C (file contents):
Revision 1.2 by pcg, Tue Oct 14 03:59:32 2003 UTC vs.
Revision 1.7 by pcg, Thu Oct 16 20:13:21 2003 UTC

1/* 1/*
2 device-tincd.C -- include one of the tincd low level implementations. 2 device-tincd.C -- include one of the tincd low level implementations.
3 Copyright (C) 2003 Marc Lehmann <pcg@goof.com>
3 4
4 This program is free software; you can redistribute it and/or modify 5 This program is free software; you can redistribute it and/or modify
5 it under the terms of the GNU General Public License as published by 6 it under the terms of the GNU General Public License as published by
6 the Free Software Foundation; either version 2 of the License, or 7 the Free Software Foundation; either version 2 of the License, or
7 (at your option) any later version. 8 (at your option) any later version.
26#include <unistd.h> 27#include <unistd.h>
27#include <syslog.h> 28#include <syslog.h>
28#include <fcntl.h> 29#include <fcntl.h>
29 30
30#include "conf.h" 31#include "conf.h"
32
33// following headers used by cygwin (maybe others)
34#include "netcompat.h"
35#include <signal.h>
36
37#define xstrdup(strd) strdup(str)
31 38
32/* make the tincd sources feel comfortable in our environment. */ 39/* make the tincd sources feel comfortable in our environment. */
33/* this was reasonably easy to do. */ 40/* this was reasonably easy to do. */
34#define routing_mode 1 41#define routing_mode 1
35#define RMODE_ROUTER 0 42#define RMODE_ROUTER 0
60// will be casted to data_packet, due to structural similarity 67// will be casted to data_packet, due to structural similarity
61struct vpn_packet_t : net_packet { 68struct vpn_packet_t : net_packet {
62 u8 data[MAXSIZE]; 69 u8 data[MAXSIZE];
63}; 70};
64 71
65static tap_device *self;
66
67static bool overwrite_mac; 72static bool overwrite_mac;
68 73
69static bool 74static bool
70get_config_string(const char *key, char **res) 75get_config_string(const char *key, char **res)
71{ 76{
84 89
85#define netname conf.ifname 90#define netname conf.ifname
86 91
87#if IF_linux 92#if IF_linux
88# include "tincd/linux/device.c" 93# include "tincd/linux/device.c"
94
89#elif IF_freebsd 95#elif IF_freebsd
90# include "tincd/freebsd/device.c" 96# include "tincd/freebsd/device.c"
97
91#elif IF_netbsd 98#elif IF_netbsd
99#define IF_istun 1
92# include "tincd/netbsd/device.c" 100# include "tincd/netbsd/device.c"
101
102#elif IF_openbsd
103#define IF_istun 1
104# include "tincd/openbsd/device.c"
105
93#elif IF_solaris 106#elif IF_solaris
94# include "tincd/solaris/device.c" 107# include "tincd/solaris/device.c"
108
95#elif IF_cygwin 109#elif IF_cygwin
96# include "tincd/cygwin/device.c" 110# include "tincd/cygwin/device.c"
111
97#elif IF_mingw 112#elif IF_mingw
98# include "tincd/mingw/device.c" 113# include "tincd/mingw/device.c"
114
99#elif IF_darwin 115#elif IF_darwin
116#define IF_istun 1
100# include "tincd/darwin/device.c" 117# include "tincd/darwin/device.c"
118
101#elif IF_raw_socket 119#elif IF_raw_socket
120#define IF_istun 1
102# include "tincd/raw_socket/device.c" 121# include "tincd/raw_socket/device.c"
122
103#else 123#else
104# error No interface implementation for your IFTYPE/IFSUBTYPE combination. 124# error No interface implementation for your IFTYPE/IFSUBTYPE combination.
125#endif
126
127#if IF_istun
128# include "ether_emu.C"
105#endif 129#endif
106 130
107const char * 131const char *
108tap_device::info () 132tap_device::info ()
109{ 133{
110 return _("tincd compatibility layer"); 134 return _("tincd compatibility layer");
111} 135}
112 136
113tap_device::tap_device () 137tap_device::tap_device ()
114{ 138{
115 self = this;
116
117 if (setup_device ()) 139 if (setup_device ())
118 { 140 {
119 //slog (L_DEBUG, _("%s is a %s"), device, info ()); 141 slog (L_DEBUG, _("interface %s initialized"), info ());
120 fd = device_fd; 142 fd = device_fd;
121 strcpy (ifrname, iface); 143 strcpy (ifrname, iface);
122 } 144 }
123 else 145 else
124 { 146 {
125 slog (L_ERR, _("error while configuring tincd device (%s/%s)"), device, info ()); 147 slog (L_ERR, _("error while configuring tincd device (%s)"), info ());
126 exit (1); 148 exit (1);
127 } 149 }
128} 150}
129 151
130tap_device::~tap_device () 152tap_device::~tap_device ()
143 slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, 165 slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE,
144 strerror (errno)); 166 strerror (errno));
145 return 0; 167 return 0;
146 } 168 }
147 169
170#if IF_istun
171 // assume ipv4
172 (*pkt)[12] = 0x08;
173 (*pkt)[13] = 0x00;
174
175 if (!ether_emu.tun_to_tap (pkt))
176 {
177 delete pkt;
178 return 0;
179 }
180#endif
181
148 return pkt; 182 return pkt;
149} 183}
150 184
151void 185void
152tap_device::send (tap_packet *pkt) 186tap_device::send (tap_packet *pkt)
153{ 187{
188 if (
189#if IF_istun
190 ether_emu.tap_to_tun (pkt) &&
191#endif
154 if (!write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) 192 !write_packet (reinterpret_cast<vpn_packet_t *>(pkt)))
155 slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, 193 slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE,
156 strerror (errno)); 194 strerror (errno));
157} 195}
158 196
159 197

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines