… | |
… | |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
15 | GNU General Public License for more details. |
16 | |
16 | |
17 | You should have received a copy of the GNU General Public License |
17 | You should have received a copy of the GNU General Public License |
18 | along with gvpe; if not, write to the Free Software |
18 | along with gvpe; if not, write to the Free Software |
19 | Foundation, Inc. 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
19 | Foundation, Inc. 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA |
20 | */ |
20 | */ |
21 | |
21 | |
22 | #include <cstdio> |
22 | #include <cstdio> |
23 | #include <cstring> |
23 | #include <cstring> |
24 | #include <cerrno> |
24 | #include <cerrno> |
… | |
… | |
61 | #define ifdebug(subsys) if (0) |
61 | #define ifdebug(subsys) if (0) |
62 | |
62 | |
63 | #define cp() |
63 | #define cp() |
64 | #define lookup_config(config_tree,key) (key) |
64 | #define lookup_config(config_tree,key) (key) |
65 | |
65 | |
66 | #define MTU MAXSIZE |
66 | #define MTU MAX_MTU |
67 | |
67 | |
68 | // BIGGEST hack of 'em all |
68 | // BIGGEST hack of 'em all |
69 | // will be casted to data_packet, due to structural similarity |
69 | // will be casted to data_packet, due to structural similarity |
70 | struct vpn_packet_t : net_packet { |
70 | struct vpn_packet_t : net_packet |
|
|
71 | { |
71 | u8 data[MAXSIZE]; |
72 | u8 data[MAXSIZE]; |
72 | }; |
73 | }; |
73 | |
74 | |
74 | static bool overwrite_mac; |
75 | static bool overwrite_mac; |
75 | |
76 | |
… | |
… | |
78 | { |
79 | { |
79 | if (!strcmp (key, "Interface")) |
80 | if (!strcmp (key, "Interface")) |
80 | *res = conf.ifname; |
81 | *res = conf.ifname; |
81 | else if (!strcmp (key, "Device")) |
82 | else if (!strcmp (key, "Device")) |
82 | *res = 0; |
83 | *res = 0; |
|
|
84 | else if (!strcmp (key, "DeviceType")) |
|
|
85 | *res = "tap"; |
83 | else |
86 | else |
84 | { |
87 | { |
85 | slog (L_ERR, _("tincd layer asking for unknown config '%s'"), key); |
88 | slog (L_ERR, _("tincd layer asking for unknown config '%s'"), key); |
86 | *res = 0; |
89 | *res = 0; |
87 | } |
90 | } |
… | |
… | |
91 | |
94 | |
92 | #define netname conf.ifname |
95 | #define netname conf.ifname |
93 | |
96 | |
94 | #if IF_linux |
97 | #if IF_linux |
95 | # include "tincd/linux/device.c" |
98 | # include "tincd/linux/device.c" |
|
|
99 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME hw ether $MAC mtu $MTU"; } |
|
|
100 | |
|
|
101 | #elif IF_bsd |
|
|
102 | # include "tincd/bsd/device.c" |
|
|
103 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } |
96 | |
104 | |
97 | #elif IF_freebsd |
105 | #elif IF_freebsd |
98 | # include "tincd/freebsd/device.c" |
106 | # include "tincd/freebsd/device.c" |
|
|
107 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } |
99 | |
108 | |
100 | #elif IF_netbsd |
109 | #elif IF_netbsd |
101 | # define IF_istun 1 |
110 | # define IF_istun 1 |
102 | # include "tincd/netbsd/device.c" |
111 | # include "tincd/netbsd/device.c" |
|
|
112 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME mtu $MTU"; } |
103 | |
113 | |
104 | #elif IF_openbsd |
114 | #elif IF_openbsd |
105 | # define IF_istun 1 |
115 | # define IF_istun 1 |
106 | # include "tincd/openbsd/device.c" |
116 | # include "tincd/openbsd/device.c" |
|
|
117 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME mtu $MTU"; } |
107 | |
118 | |
108 | #elif IF_solaris |
119 | #elif IF_solaris |
109 | # define IF_istun 1 |
120 | # define IF_istun 1 |
110 | # include "tincd/solaris/device.c" |
121 | # include "tincd/solaris/device.c" |
|
|
122 | const char * tap_device::if_up () { return ""; } |
111 | |
123 | |
112 | #elif IF_cygwin |
124 | #elif IF_cygwin |
113 | # include "tincd/cygwin/device.c" |
125 | # include "tincd/cygwin/device.c" |
|
|
126 | const char * tap_device::if_up () { return ""; } |
114 | |
127 | |
115 | #elif IF_mingw |
128 | #elif IF_mingw |
116 | # include "tincd/mingw/device.c" |
129 | # include "tincd/mingw/device.c" |
|
|
130 | const char * tap_device::if_up () { return ""; } |
117 | |
131 | |
118 | #elif IF_darwin |
132 | #elif IF_darwin |
119 | # define IF_istun 1 |
133 | # define IF_istun 1 |
120 | # include "tincd/darwin/device.c" |
134 | # include "tincd/darwin/device.c" |
|
|
135 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } |
121 | |
136 | |
122 | #elif IF_raw_socket |
137 | #elif IF_raw_socket |
123 | # define IF_istun 1 |
|
|
124 | # include "tincd/raw_socket/device.c" |
138 | # include "tincd/raw_socket/device.c" |
|
|
139 | const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; } |
|
|
140 | |
|
|
141 | #elif IF_uml_socket |
|
|
142 | # include "tincd/uml_socket/device.c" |
|
|
143 | const char * tap_device::if_up () { return 0; } |
125 | |
144 | |
126 | #else |
145 | #else |
127 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
146 | # error No interface implementation for your IFTYPE/IFSUBTYPE combination. |
128 | #endif |
147 | #endif |
129 | |
148 | |
… | |
… | |
139 | |
158 | |
140 | tap_device::tap_device () |
159 | tap_device::tap_device () |
141 | { |
160 | { |
142 | device = "(null)"; |
161 | device = "(null)"; |
143 | |
162 | |
144 | if (setup_device ()) |
163 | bool ok = setup_device (); |
|
|
164 | |
|
|
165 | if (device_info) |
|
|
166 | device = device_info; |
|
|
167 | |
|
|
168 | if (ok) |
145 | { |
169 | { |
146 | slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); |
170 | slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); |
147 | fd = device_fd; |
171 | fd = device_fd; |
148 | strcpy (ifrname, iface); |
172 | strcpy (ifrname, iface); |
149 | } |
173 | } |
… | |
… | |
165 | tap_packet *pkt = new tap_packet; |
189 | tap_packet *pkt = new tap_packet; |
166 | |
190 | |
167 | if (!read_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
191 | if (!read_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
168 | { |
192 | { |
169 | delete pkt; |
193 | delete pkt; |
170 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, |
194 | slog (L_ERR, _("can't read from to %s %s: %s"), info (), device, |
171 | strerror (errno)); |
195 | strerror (errno)); |
172 | return 0; |
196 | return 0; |
173 | } |
197 | } |
174 | |
198 | |
175 | #if IF_istun |
199 | #if IF_istun |
… | |
… | |
193 | if ( |
217 | if ( |
194 | #if IF_istun |
218 | #if IF_istun |
195 | ether_emu.tap_to_tun (pkt) && |
219 | ether_emu.tap_to_tun (pkt) && |
196 | #endif |
220 | #endif |
197 | !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
221 | !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) |
198 | slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, |
222 | slog (L_ERR, _("can't write to %s %s: %s"), info (), device, |
199 | strerror (errno)); |
223 | strerror (errno)); |
200 | } |
224 | } |
201 | |
225 | |
202 | |
226 | |