Révision | 066158ba81701c0ff591246de25e2717ad7d8f27 (tree) |
---|---|
l'heure | 2015-11-03 14:37:54 |
Auteur | phabrics <phabrics@phab...> |
Commiter | phabrics |
Changed openvpn host to use openvpn ethernet access methods.
@@ -275,9 +275,9 @@ _tme_bsd_bpf_config(struct tme_ethernet_connection *conn_eth, | ||
275 | 275 | TME_BSD_BPF_LEN(program) = bpf_filter_size - first_pc; |
276 | 276 | TME_BSD_BPF_INSNS(program) = bpf_filter + first_pc; |
277 | 277 | #ifdef HAVE_LSF |
278 | - if (setsockopt(bpf->tme_eth_fd, SOL_SOCKET, SO_ATTACH_FILTER, &program, sizeof(program)) == -1) { | |
278 | + if (setsockopt(bpf->tme_eth_handle, SOL_SOCKET, SO_ATTACH_FILTER, &program, sizeof(program)) == -1) { | |
279 | 279 | #else |
280 | - if (ioctl(bpf->tme_eth_fd, BIOCSETF, &program) < 0) { | |
280 | + if (ioctl(bpf->tme_eth_handle, BIOCSETF, &program) < 0) { | |
281 | 281 | #endif |
282 | 282 | tme_log(&bpf->tme_eth_element->tme_element_log_handle, 0, errno, |
283 | 283 | (&bpf->tme_eth_element->tme_element_log_handle, |
@@ -122,6 +122,16 @@ _TME_RCSID("$Id: eth-impl.h,v 1.1 2003/05/18 00:02:23 fredette Exp $"); | ||
122 | 122 | #ifdef HAVE_IFADDRS_H |
123 | 123 | #include <ifaddrs.h> |
124 | 124 | #endif |
125 | +#ifdef OPENVPN_HOST | |
126 | +#include "syshead.h" | |
127 | +#include "tun.h" | |
128 | +#define _tme_eth_static static | |
129 | +#ifndef TME_THREADS_SJLJ | |
130 | +#define OPENVPN_ETH | |
131 | +#endif | |
132 | +#else | |
133 | +#define _tme_eth_static | |
134 | +#endif | |
125 | 135 | |
126 | 136 | /* structures: */ |
127 | 137 |
@@ -147,8 +157,12 @@ struct tme_ethernet { | ||
147 | 157 | struct tme_ethernet_connection *tme_eth_eth_connection; |
148 | 158 | |
149 | 159 | /* the Ethernet file descriptor: */ |
150 | - int tme_eth_fd; | |
151 | - | |
160 | +#ifdef OPENVPN_ETH | |
161 | + struct tuntap *tme_eth_handle; | |
162 | +#else | |
163 | + int tme_eth_handle; | |
164 | +#endif | |
165 | + | |
152 | 166 | /* the size of the packet buffer for the interface: */ |
153 | 167 | size_t tme_eth_buffer_size; |
154 | 168 |
@@ -177,6 +191,7 @@ struct tme_ethernet { | ||
177 | 191 | }; |
178 | 192 | |
179 | 193 | /* prototypes: */ |
194 | +#ifndef OPENVPN_HOST | |
180 | 195 | #if 0 |
181 | 196 | int tme_eth_if_find _TME_P((_tme_const char *, |
182 | 197 | struct ifreq **, |
@@ -199,11 +214,15 @@ int tme_eth_connections_new _TME_P((struct tme_element *element, | ||
199 | 214 | const char * const *args, |
200 | 215 | struct tme_connection **_conns)); |
201 | 216 | |
202 | -int tme_eth_init _TME_P((struct tme_element *element, | |
203 | - int fd, | |
217 | +int tme_eth_init _TME_P((struct tme_element *element, | |
218 | +#ifdef OPENVPN_ETH | |
219 | + struct tuntap *tt, | |
220 | +#else | |
221 | + int fd, | |
222 | +#endif | |
204 | 223 | unsigned int sz, |
205 | 224 | void *data, |
206 | 225 | unsigned char *addr, |
207 | 226 | typeof(tme_eth_connections_new) eth_connections_new)); |
208 | - | |
227 | +#endif // !_tme_eth_static | |
209 | 228 | #endif /* !_HOST_ETH_IMPL_H */ |
@@ -99,7 +99,7 @@ _tme_eth_callout(struct tme_ethernet *eth, int new_callouts) | ||
99 | 99 | if (eth->tme_eth_callout_flags & TME_ETH_CALLOUT_RUNNING) { |
100 | 100 | return; |
101 | 101 | } |
102 | - | |
102 | + | |
103 | 103 | /* callouts are now running: */ |
104 | 104 | eth->tme_eth_callout_flags |= TME_ETH_CALLOUT_RUNNING; |
105 | 105 |
@@ -177,8 +177,11 @@ _tme_eth_callout(struct tme_ethernet *eth, int new_callouts) | ||
177 | 177 | assert(rc <= sizeof(frame)); |
178 | 178 | |
179 | 179 | /* do the write: */ |
180 | - status = tme_thread_write(eth->tme_eth_fd, frame, rc); | |
181 | - | |
180 | +#ifdef OPENVPN_ETH | |
181 | + status = write_tun(eth->tme_eth_handle, frame, rc); | |
182 | +#else | |
183 | + status = tme_thread_write(eth->tme_eth_handle, frame, rc); | |
184 | +#endif | |
182 | 185 | /* writes must succeed: */ |
183 | 186 | assert (status == rc); |
184 | 187 |
@@ -259,7 +262,7 @@ _tme_eth_th_reader(struct tme_ethernet *eth) | ||
259 | 262 | (ð->tme_eth_element->tme_element_log_handle, |
260 | 263 | _("calling read"))); |
261 | 264 | #if 0 |
262 | - rc = tme_thread_select_yield(eth->tme_eth_fd + 1, | |
265 | + rc = tme_thread_select_yield(eth->tme_eth_handle + 1, | |
263 | 266 | &fdset_read_in, |
264 | 267 | NULL, |
265 | 268 | NULL, |
@@ -268,9 +271,14 @@ _tme_eth_th_reader(struct tme_ethernet *eth) | ||
268 | 271 | |
269 | 272 | } |
270 | 273 | |
274 | +#elif defined(OPENVPN_ETH) | |
275 | + buffer_end = | |
276 | + read_tun(eth->tme_eth_handle, | |
277 | + eth->tme_eth_buffer, | |
278 | + eth->tme_eth_buffer_size); | |
271 | 279 | #else |
272 | 280 | buffer_end = |
273 | - tme_thread_read_yield(eth->tme_eth_fd, | |
281 | + tme_thread_read_yield(eth->tme_eth_handle, | |
274 | 282 | eth->tme_eth_buffer, |
275 | 283 | eth->tme_eth_buffer_size); |
276 | 284 | #endif |
@@ -477,7 +485,7 @@ _tme_eth_read(struct tme_ethernet_connection *conn_eth, | ||
477 | 485 | |
478 | 486 | #if 0 |
479 | 487 | /* this finds a network interface via traditional ioctls: */ |
480 | -int | |
488 | +_tme_eth_static int | |
481 | 489 | tme_eth_if_find(const char *ifr_name_user, struct ifreq **_ifreq, tme_uint8_t **_if_addr, unsigned int *_if_addr_size) |
482 | 490 | { |
483 | 491 | int saved_errno; |
@@ -647,7 +655,7 @@ tme_eth_if_find(const char *ifr_name_user, struct ifreq **_ifreq, tme_uint8_t ** | ||
647 | 655 | |
648 | 656 | #ifdef HAVE_IFADDRS_H |
649 | 657 | /* this finds a network interface via the ifaddrs api: */ |
650 | -int | |
658 | +_tme_eth_static int | |
651 | 659 | tme_eth_ifaddrs_find(const char *ifa_name_user, int family, struct ifaddrs **_ifaddr, tme_uint8_t **_if_addr, unsigned int *_if_addr_size) |
652 | 660 | { |
653 | 661 | struct ifaddrs *ifaddr, *ifa; |
@@ -793,7 +801,7 @@ tme_eth_ifaddrs_find(const char *ifa_name_user, int family, struct ifaddrs **_if | ||
793 | 801 | #endif // HAVE_IFADDRS_H |
794 | 802 | |
795 | 803 | /* Allocate an ethernet device */ |
796 | -int tme_eth_alloc(char *dev_filename, char **_output) | |
804 | +_tme_eth_static int tme_eth_alloc(char *dev_filename, char **_output) | |
797 | 805 | { |
798 | 806 | int fd, minor; |
799 | 807 | char dev_minor[4]; |
@@ -829,7 +837,7 @@ int tme_eth_alloc(char *dev_filename, char **_output) | ||
829 | 837 | } |
830 | 838 | |
831 | 839 | /* this makes a new connection side for a ETH: */ |
832 | -int | |
840 | +_tme_eth_static int | |
833 | 841 | tme_eth_connections_new(struct tme_element *element, |
834 | 842 | const char * const *args, |
835 | 843 | struct tme_connection **_conns) |
@@ -869,8 +877,12 @@ tme_eth_connections_new(struct tme_element *element, | ||
869 | 877 | return (TME_OK); |
870 | 878 | } |
871 | 879 | |
872 | -int tme_eth_init(struct tme_element *element, | |
873 | - int fd, | |
880 | +_tme_eth_static int tme_eth_init(struct tme_element *element, | |
881 | +#ifdef OPENVPN_ETH | |
882 | + struct tuntap *handle, | |
883 | +#else | |
884 | + int handle, | |
885 | +#endif | |
874 | 886 | unsigned int sz, |
875 | 887 | void *data, |
876 | 888 | unsigned char *addr, |
@@ -881,7 +893,7 @@ int tme_eth_init(struct tme_element *element, | ||
881 | 893 | /* start our data structure: */ |
882 | 894 | eth = tme_new0(struct tme_ethernet, 1); |
883 | 895 | eth->tme_eth_element = element; |
884 | - eth->tme_eth_fd = fd; | |
896 | + eth->tme_eth_handle = handle; | |
885 | 897 | eth->tme_eth_buffer_size = sz; |
886 | 898 | eth->tme_eth_buffer = tme_new(tme_uint8_t, sz); |
887 | 899 | eth->tme_eth_data = data; |
@@ -88,8 +88,9 @@ tme_host_openvpn_la_SOURCES = \ | ||
88 | 88 | tap.c \ |
89 | 89 | win32.h win32.c \ |
90 | 90 | cryptoapi.h cryptoapi.c |
91 | + | |
91 | 92 | tme_host_openvpn_la_LIBADD = \ |
92 | - ../eth/libeth.la \ | |
93 | + $(top_builddir)/generic/libtme-generic.la \ | |
93 | 94 | $(SOCKETS_LIBS) \ |
94 | 95 | $(OPTIONAL_LZO_LIBS) \ |
95 | 96 | $(OPTIONAL_PKCS11_HELPER_LIBS) \ |
@@ -97,6 +98,7 @@ tme_host_openvpn_la_LIBADD = \ | ||
97 | 98 | $(OPTIONAL_SELINUX_LIBS) \ |
98 | 99 | $(OPTIONAL_SYSTEMD_LIBS) \ |
99 | 100 | $(OPTIONAL_DL_LIBS) |
101 | + | |
100 | 102 | if WIN32 |
101 | 103 | tme_host_openvpn_la_SOURCES += openvpn_win32_resources.rc |
102 | 104 | tme_host_openvpn_la_LIBADD += -lgdi32 -lws2_32 -lwininet -lcrypt32 -liphlpapi -lwinmm |
@@ -106,7 +108,4 @@ tme_host_openvpn_la_LDFLAGS = -module -version-info 0:0:0 | ||
106 | 108 | |
107 | 109 | include $(top_srcdir)/modules |
108 | 110 | |
109 | -$(pkglib_LTLIBRARIES): ../eth/libeth.la | |
110 | -../eth/libeth.la: force | |
111 | - cd `dirname $@` && $(MAKE) `basename $@` | |
112 | -force: ; | |
111 | +tap.lo: ../eth/eth-impl.c |
@@ -34,9 +34,8 @@ | ||
34 | 34 | #include <tme/common.h> |
35 | 35 | |
36 | 36 | /* includes: */ |
37 | -#include "eth-if.h" | |
38 | -#include "syshead.h" | |
39 | -#include "tun.h" | |
37 | +#define OPENVPN_HOST | |
38 | +#include "eth-impl.c" | |
40 | 39 | |
41 | 40 | /* the new TAP function: */ |
42 | 41 | TME_ELEMENT_SUB_NEW_DECL(tme_host_openvpn,tap) { |
@@ -181,9 +180,10 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_openvpn,tap) { | ||
181 | 180 | do_ifconfig(tt, guess, TME_ETHERNET_FRAME_MAX, NULL); |
182 | 181 | } |
183 | 182 | |
183 | +#ifndef OPENVPN_ETH | |
184 | 184 | /* temporarily turn off ipv6 to disable protocol info being prepended to packets on Linux */ |
185 | 185 | tt->ipv6 = FALSE; |
186 | - | |
186 | +#endif | |
187 | 187 | /* open the tun device */ |
188 | 188 | open_tun(dev, |
189 | 189 | dev_type, |
@@ -220,6 +220,12 @@ TME_ELEMENT_SUB_NEW_DECL(tme_host_openvpn,tap) { | ||
220 | 220 | hwaddr[5])); |
221 | 221 | } |
222 | 222 | #endif |
223 | - return tme_eth_init(element, tt->fd, 4096, NULL, hwaddr, NULL); | |
223 | + return tme_eth_init(element, | |
224 | +#ifdef OPENVPN_ETH | |
225 | + tt, | |
226 | +#else | |
227 | + tt->fd, | |
228 | +#endif | |
229 | + 4096, NULL, hwaddr, NULL); | |
224 | 230 | |
225 | 231 | } |
@@ -248,7 +248,7 @@ _tme_tun_tap_config(struct tme_ethernet_connection *conn_eth, | ||
248 | 248 | |
249 | 249 | /* set the filter on the TAP device: */ |
250 | 250 | TME_TUN_TAP_LEN((TME_TUN_TAP_PROG *)tap_filter) = tap_filter_size; |
251 | - if (ioctl(tap->tme_eth_fd, TUNSETTXFILTER, tap_filter) < 0) { | |
251 | + if (ioctl(tap->tme_eth_handle, TUNSETTXFILTER, tap_filter) < 0) { | |
252 | 252 | tme_log(&tap->tme_eth_element->tme_element_log_handle, 0, errno, |
253 | 253 | (&tap->tme_eth_element->tme_element_log_handle, |
254 | 254 | _("failed to set the filter"))); |