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. |
… | |
… | |
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) |
… | |
… | |
75 | |
91 | |
76 | #define netname conf.ifname |
92 | #define netname conf.ifname |
77 | |
93 | |
78 | #if IF_linux |
94 | #if IF_linux |
79 | # include "tincd/linux/device.c" |
95 | # include "tincd/linux/device.c" |
|
|
96 | |
80 | #elif IF_freebsd |
97 | #elif IF_freebsd |
81 | # include "tincd/freebsd/device.c" |
98 | # include "tincd/freebsd/device.c" |
|
|
99 | |
82 | #elif IF_netbsd |
100 | #elif IF_netbsd |
|
|
101 | #define IF_istun 1 |
83 | # include "tincd/netbsd/device.c" |
102 | # include "tincd/netbsd/device.c" |
|
|
103 | |
|
|
104 | #elif IF_openbsd |
|
|
105 | #define IF_istun 1 |
|
|
106 | # include "tincd/openbsd/device.c" |
|
|
107 | |
84 | #elif IF_solaris |
108 | #elif IF_solaris |
85 | # include "tincd/solaris/device.c" |
109 | # include "tincd/solaris/device.c" |
|
|
110 | |
86 | #elif IF_cygwin |
111 | #elif IF_cygwin |
87 | # include "tincd/cygwin/device.c" |
112 | # include "tincd/cygwin/device.c" |
|
|
113 | |
88 | #elif IF_mingw |
114 | #elif IF_mingw |
89 | # include "tincd/mingw/device.c" |
115 | # include "tincd/mingw/device.c" |
|
|
116 | |
90 | #elif IF_darwin |
117 | #elif IF_darwin |
|
|
118 | #define IF_istun 1 |
91 | # include "tincd/darwin/device.c" |
119 | # include "tincd/darwin/device.c" |
|
|
120 | |
92 | #elif IF_raw_socket |
121 | #elif IF_raw_socket |
|
|
122 | #define IF_istun 1 |
93 | # include "tincd/raw_socket/device.c" |
123 | # include "tincd/raw_socket/device.c" |
|
|
124 | |
94 | #else |
125 | #else |
95 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
126 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
|
|
127 | #endif |
|
|
128 | |
|
|
129 | #if IF_istun |
|
|
130 | # include "ether_emu.C" |
96 | #endif |
131 | #endif |
97 | |
132 | |
98 | const char * |
133 | const char * |
99 | tap_device::info () |
134 | tap_device::info () |
100 | { |
135 | { |
… | |
… | |
134 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, |
169 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, |
135 | strerror (errno)); |
170 | strerror (errno)); |
136 | return 0; |
171 | return 0; |
137 | } |
172 | } |
138 | |
173 | |
|
|
174 | #if IF_istun |
|
|
175 | // assume ipv4 |
|
|
176 | (*pkt)[12] = 0x08; |
|
|
177 | (*pkt)[13] = 0x00; |
|
|
178 | |
|
|
179 | if (!ether_emu.tun_to_tap (pkt)) |
|
|
180 | { |
|
|
181 | delete pkt; |
|
|
182 | return 0; |
|
|
183 | } |
|
|
184 | #endif |
|
|
185 | |
139 | return pkt; |
186 | return pkt; |
140 | } |
187 | } |
141 | |
188 | |
142 | void |
189 | void |
143 | tap_device::send (tap_packet *pkt) |
190 | tap_device::send (tap_packet *pkt) |
144 | { |
191 | { |
|
|
192 | if ( |
|
|
193 | #if IF_istun |
|
|
194 | ether_emu.tap_to_tun (pkt) && |
|
|
195 | #endif |
145 | if (!write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
196 | !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
146 | slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, |
197 | slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, |
147 | strerror (errno)); |
198 | strerror (errno)); |
148 | } |
199 | } |
149 | |
200 | |
150 | |
201 | |