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.12 by pcg, Thu Mar 3 16:54:34 2005 UTC vs.
Revision 1.17 by pcg, Fri Mar 25 15:38:07 2005 UTC

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
70struct vpn_packet_t : net_packet { 70struct vpn_packet_t : net_packet {
71 u8 data[MAXSIZE]; 71 u8 data[MAXSIZE];
91 91
92#define netname conf.ifname 92#define netname conf.ifname
93 93
94#if IF_linux 94#if IF_linux
95# include "tincd/linux/device.c" 95# include "tincd/linux/device.c"
96const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME hw ether $MAC mtu $MTU"; }
96 97
97#elif IF_freebsd 98#elif IF_freebsd
98# include "tincd/freebsd/device.c" 99# include "tincd/freebsd/device.c"
100const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; }
99 101
100#elif IF_netbsd 102#elif IF_netbsd
101# define IF_istun 1 103# define IF_istun 1
102# include "tincd/netbsd/device.c" 104# include "tincd/netbsd/device.c"
105const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME mtu $MTU"; }
103 106
104#elif IF_openbsd 107#elif IF_openbsd
105# define IF_istun 1 108# define IF_istun 1
106# include "tincd/openbsd/device.c" 109# include "tincd/openbsd/device.c"
110const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME mtu $MTU"; }
107 111
108#elif IF_solaris 112#elif IF_solaris
109# define IF_istun 1 113# define IF_istun 1
110# include "tincd/solaris/device.c" 114# include "tincd/solaris/device.c"
115const char * tap_device::if_up () { return ""; }
111 116
112#elif IF_cygwin 117#elif IF_cygwin
113# include "tincd/cygwin/device.c" 118# include "tincd/cygwin/device.c"
119const char * tap_device::if_up () { return ""; }
114 120
115#elif IF_mingw 121#elif IF_mingw
116# include "tincd/mingw/device.c" 122# include "tincd/mingw/device.c"
123const char * tap_device::if_up () { return ""; }
117 124
118#elif IF_darwin 125#elif IF_darwin
119# define IF_istun 1 126# define IF_istun 1
120# include "tincd/darwin/device.c" 127# include "tincd/darwin/device.c"
128const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; }
121 129
122#elif IF_raw_socket 130#elif IF_raw_socket
123# define IF_istun 1
124# include "tincd/raw_socket/device.c" 131# include "tincd/raw_socket/device.c"
132const char * tap_device::if_up () { return "/sbin/ifconfig $IFNAME ether $MAC mtu $MTU"; }
133
134#elif IF_uml_socket
135# include "tincd/uml_socket/device.c"
136const char * tap_device::if_up () { return 0; }
125 137
126#else 138#else
127# error No interface implementation for your IFTYPE/IFSUBTYPE combination. 139# error No interface implementation for your IFTYPE/IFSUBTYPE combination.
128#endif 140#endif
129 141
139 151
140tap_device::tap_device () 152tap_device::tap_device ()
141{ 153{
142 device = "(null)"; 154 device = "(null)";
143 155
144 if (setup_device ()) 156 bool ok = setup_device ();
157
158 if (device_info)
159 device = device_info;
160
161 if (ok)
145 { 162 {
146 slog (L_DEBUG, _("interface %s on %s initialized"), info (), device); 163 slog (L_DEBUG, _("interface %s on %s initialized"), info (), device);
147 fd = device_fd; 164 fd = device_fd;
148 strcpy (ifrname, iface); 165 strcpy (ifrname, iface);
149 } 166 }
165 tap_packet *pkt = new tap_packet; 182 tap_packet *pkt = new tap_packet;
166 183
167 if (!read_packet (reinterpret_cast<vpn_packet_t *>(pkt))) 184 if (!read_packet (reinterpret_cast<vpn_packet_t *>(pkt)))
168 { 185 {
169 delete pkt; 186 delete pkt;
170 slog (L_ERR, _("can't read from to %s %s: %s"), info (), DEFAULT_DEVICE, 187 slog (L_ERR, _("can't read from to %s %s: %s"), info (), device,
171 strerror (errno)); 188 strerror (errno));
172 return 0; 189 return 0;
173 } 190 }
174 191
175#if IF_istun 192#if IF_istun
193 if ( 210 if (
194#if IF_istun 211#if IF_istun
195 ether_emu.tap_to_tun (pkt) && 212 ether_emu.tap_to_tun (pkt) &&
196#endif 213#endif
197 !write_packet (reinterpret_cast<vpn_packet_t *>(pkt))) 214 !write_packet (reinterpret_cast<vpn_packet_t *>(pkt)))
198 slog (L_ERR, _("can't write to %s %s: %s"), info (), DEFAULT_DEVICE, 215 slog (L_ERR, _("can't write to %s %s: %s"), info (), device,
199 strerror (errno)); 216 strerror (errno));
200} 217}
201 218
202 219

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines