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.1 by pcg, Tue Oct 14 03:22:09 2003 UTC vs.
Revision 1.10 by pcg, Thu Jan 29 18:55:10 2004 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-2004 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.
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"
31 32
33// following headers used by cygwin (maybe others)
34#include "netcompat.h"
35#include <signal.h>
36
37#define xstrdup(strd) strdup(str)
38
39/* make the tincd sources feel comfortable in our environment. */
40/* this was reasonably easy to do. */
32#define routing_mode 1 41#define routing_mode 1
33#define RMODE_ROUTER 0 42#define RMODE_ROUTER 0
34 43
35/* need iso c-90 or ugly workaround :( */ 44#define LOG_TO_L(level) \
36#define logger(level, ...) slog ( \
37 (level) == LOG_ERR ? L_ERR \ 45 (level) == LOG_ERR ? L_ERR \
38 : (level) == LOG_DEBUG ? L_DEBUG \ 46 : (level) == LOG_DEBUG ? L_DEBUG \
39 : (level) == LOG_WARNING ? L_WARN \ 47 : (level) == LOG_WARNING ? L_WARN \
40 : (level) == LOG_INFO ? L_INFO \ 48 : (level) == LOG_INFO ? L_INFO \
41 : L_NOTICE, __VA_ARGS__) 49 : L_NOTICE
50
51#if __STDC_VERSION__ > 199900
52# define logger(level, ...) slog (LOG_TO_L(level), __VA_ARGS__)
53#elif __GNUC__
54# define logger(level, args...) slog (LOG_TO_L(level), ## args)
55#else
56# error either need ISO-C 99 compliant compiler or gcc.
57#endif
42 58
43#define ifdebug(subsys) if (0) 59#define ifdebug(subsys) if (0)
44 60
45#define cp() 61#define cp()
46#define lookup_config(config_tree,key) (key) 62#define lookup_config(config_tree,key) (key)
50// BIGGEST hack of 'em all 66// BIGGEST hack of 'em all
51// will be casted to data_packet, due to structural similarity 67// will be casted to data_packet, due to structural similarity
52struct vpn_packet_t : net_packet { 68struct vpn_packet_t : net_packet {
53 u8 data[MAXSIZE]; 69 u8 data[MAXSIZE];
54}; 70};
55
56static tap_device *self;
57 71
58static bool overwrite_mac; 72static bool overwrite_mac;
59 73
60static bool 74static bool
61get_config_string(const char *key, char **res) 75get_config_string(const char *key, char **res)
75 89
76#define netname conf.ifname 90#define netname conf.ifname
77 91
78#if IF_linux 92#if IF_linux
79# include "tincd/linux/device.c" 93# include "tincd/linux/device.c"
94
80#elif IF_freebsd 95#elif IF_freebsd
81# include "tincd/freebsd/device.c" 96# include "tincd/freebsd/device.c"
97
82#elif IF_netbsd 98#elif IF_netbsd
99#define IF_istun 1
83# 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
84#elif IF_solaris 106#elif IF_solaris
85# include "tincd/solaris/device.c" 107# include "tincd/solaris/device.c"
108
86#elif IF_cygwin 109#elif IF_cygwin
87# include "tincd/cygwin/device.c" 110# include "tincd/cygwin/device.c"
111
88#elif IF_mingw 112#elif IF_mingw
89# include "tincd/mingw/device.c" 113# include "tincd/mingw/device.c"
114
90#elif IF_darwin 115#elif IF_darwin
116#define IF_istun 1
91# include "tincd/darwin/device.c" 117# include "tincd/darwin/device.c"
118
92#elif IF_raw_socket 119#elif IF_raw_socket
120#define IF_istun 1
93# include "tincd/raw_socket/device.c" 121# include "tincd/raw_socket/device.c"
122
94#else 123#else
95# 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"
96#endif 129#endif
97 130
98const char * 131const char *
99tap_device::info () 132tap_device::info ()
100{ 133{
101 return _("tincd compatibility layer"); 134 return _("tincd compatibility layer");
102} 135}
103 136
104tap_device::tap_device () 137tap_device::tap_device ()
105{ 138{
106 self = this; 139 device = "(null)";
107 140
108 if (setup_device ()) 141 if (setup_device ())
109 { 142 {
110 //slog (L_DEBUG, _("%s is a %s"), device, info ()); 143 slog (L_DEBUG, _("interface %s on %s initialized"), info (), device);
111 fd = device_fd; 144 fd = device_fd;
112 strcpy (ifrname, iface); 145 strcpy (ifrname, iface);
113 } 146 }
114 else 147 else
115 { 148 {
116 slog (L_ERR, _("error while configuring tincd device (%s/%s)"), device, info ()); 149 slog (L_ERR, _("error while configuring tincd device %s on %s"), info (), device);
117 exit (1); 150 exit (EXIT_FAILURE);
118 } 151 }
119} 152}
120 153
121tap_device::~tap_device () 154tap_device::~tap_device ()
122{ 155{
134 slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, 167 slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE,
135 strerror (errno)); 168 strerror (errno));
136 return 0; 169 return 0;
137 } 170 }
138 171
172#if IF_istun
173 // assume ipv4
174 (*pkt)[12] = 0x08;
175 (*pkt)[13] = 0x00;
176
177 if (!ether_emu.tun_to_tap (pkt))
178 {
179 delete pkt;
180 return 0;
181 }
182#endif
183
139 return pkt; 184 return pkt;
140} 185}
141 186
142void 187void
143tap_device::send (tap_packet *pkt) 188tap_device::send (tap_packet *pkt)
144{ 189{
190 if (
191#if IF_istun
192 ether_emu.tap_to_tun (pkt) &&
193#endif
145 if (!write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) 194 !write_packet (reinterpret_cast<vpn_packet_t *>(pkt)))
146 slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, 195 slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE,
147 strerror (errno)); 196 strerror (errno));
148} 197}
149 198
150 199

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines