Tap and VLAN socket support for win32
PATCH 1/1 Tap and VLAN socket support for win32
Hi,
I updated a patch to support tap for win32.
Here is patches and a binary.
These patches are applied by patch -p1 option. Tap patch can be applied on top of VLAN patch. VLAN patch is updated.
http://www.h7.dion.ne.jp/~qemu-win/download/qemu-20060111-vlan.patch
http://www.h7.dion.ne.jp/~qemu-win/download/qemu-20060111-tap.patch
http://www.h6.dion.ne.jp/~kazuw/qemu-win/qemu-20060111-vlan-tap.zip
Options are:
-net nic -net tap,ifname=my-tap
Use ifname to set a name of Tap.
my-tap is the name of my TAP-Win32 Adapter.
Don't use the same network address as a physical network.
For example, if the physical network is 192.168.0.x, use different network 192.168.10.y for TAP-Win32 Adapter.
For more information,
http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html#vlan
Regards,
Kazu
Wow, thanks! I almost gave up on seeing someone port over this patch :)
--
"I decry the current tendency to seek patents on algorithms. There are better ways to earn a living than to prevent other people from making use of one's contributions to computer science."
Donald Knuth
Quoted 26 lines · Kazu
Hi,
I updated a patch to support tap for win32.
Here is patches and a binary.
These patches are applied by patch -p1 option. Tap patch can be applied on top of VLAN patch. VLAN patch is updated.
http://www.h7.dion.ne.jp/~qemu-win/download/qemu-20060111-vlan.patch
http://www.h7.dion.ne.jp/~qemu-win/download/qemu-20060111-tap.patchhttp://www.h6.dion.ne.jp/~kazuw/qemu-win/qemu-20060111-vlan-tap.zip
Options are:
-net nic -net tap,ifname=my-tap
Use ifname to set a name of Tap.
my-tap is the name of my TAP-Win32 Adapter.Don't use the same network address as a physical network.
For example, if the physical network is 192.168.0.x, use different network 192.168.10.y for TAP-Win32 Adapter.For more information,
http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html#vlanRegards,
Kazu
Fabrice Bellard
AppliedHi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
Regards,
Fabrice.
Quoted 37 lines · Kazu
Hi,
I updated a patch to support tap for win32.
Here is patches and a binary.
These patches are applied by patch -p1 option. Tap patch can be applied on top of VLAN patch. VLAN patch is updated.
http://www.h7.dion.ne.jp/~qemu-win/download/qemu-20060111-vlan.patch
http://www.h7.dion.ne.jp/~qemu-win/download/qemu-20060111-tap.patchhttp://www.h6.dion.ne.jp/~kazuw/qemu-win/qemu-20060111-vlan-tap.zip
Options are:
-net nic -net tap,ifname=my-tap
Use ifname to set a name of Tap.
my-tap is the name of my TAP-Win32 Adapter.Don't use the same network address as a physical network. For example, if the physical network is 192.168.0.x, use different network 192.168.10.y for TAP-Win32 Adapter.
For more information,
http://www.h7.dion.ne.jp/~qemu-win/TapWin32-en.html#vlanRegards,
Kazu_______________________________________________
Qemu-devel mailing list
[email protected]
http://lists.nongnu.org/mailman/listinfo/qemu-devel
Quoted 5 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
-net socket,connect doesn't work. On Windows host, connect returns with err = WSAEWOULDBLOCK and second time err = WSAEINVAL. I think changing the place of EWOULDBLOCK would be good. On Linux host, EWOULDBLOCK is the same as EAGAIN but a patch works on both Linux and Windows.
For -net socket,mcast, bind have to be done by sin_addr.s_addr = INADDR_ANY. It seems that it works on Linux host.
Regards,
Kazu
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.160
vl.c 2 Feb 2006 09:28:19 -0000 renamed from vl.c 1 Feb 2006 23:06:55 -0000 1.160 +9 -3
@@ -2335,7 +2335,13 @@ goto fail; } - ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr)); + struct sockaddr_in addr; + memset(&addr, 0, sizeof(addr)); + addr.sin_family = AF_INET; + addr.sin_port = mcastaddr->sin_port; + addr.sin_addr.s_addr = INADDR_ANY; + + ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr)); if (ret < 0) { perror("bind"); goto fail;
@@ -2561,8 +2567,8 @@ ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr)); if (ret < 0) { err = socket_error(); - if (err == EINTR || err == EWOULDBLOCK) { - } else if (err == EINPROGRESS) { + if (err == EINTR) { + } else if (err == EINPROGRESS || err == EWOULDBLOCK) { break; } else { perror("connect");
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.160
vl.c +9 -3
@@ -2335,7 +2335,13 @@ goto fail; } - ret =bind (fd, (struct sockaddr *)mcastaddr,sizeof (*mcastaddr)); +struct sockaddr_in addr; +memset (&addr,0 ,sizeof (addr)); + addr.sin_family =AF_INET ; + addr.sin_port = mcastaddr->sin_port; + addr.sin_addr.s_addr =INADDR_ANY ; + + ret =bind (fd, (struct sockaddr *)&addr,sizeof (addr));if (ret <0 ) {perror ("bind" ); goto fail;
@@ -2561,8 +2567,8 @@ ret =connect (fd, (struct sockaddr *)&saddr,sizeof (saddr));if (ret <0 ) { err =socket_error (); -if (err ==EINTR || err ==EWOULDBLOCK ) { - }else if (err ==EINPROGRESS ) { +if (err ==EINTR ) { + }else if (err ==EINPROGRESS || err ==EWOULDBLOCK ) {break ; }else {perror ("connect" );
Quoted 4 lines · Kazu
Quoted 2 lines · Fabrice Bellard
Hi,
Quoted 8 lines
Quoted 3 lines
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
-net socket,connect doesn't work. On Windows host, connect returns with err = WSAEWOULDBLOCK and second time err = WSAEINVAL. I think changing the place of EWOULDBLOCK would be good. On Linux host, EWOULDBLOCK is the same as EAGAIN but a patch works on both Linux and Windows.
Unfortunately on Linux the correct return value we are expecting is EINPROGRESS. EAGAIN means that the 'connect' was not initiated so it is necessary to redo it.
Quoted 3 lines
For -net socket,mcast, bind have to be done by sin_addr.s_addr =
INADDR_ANY. It seems that it works on Linux host.
It works on Linux but it is not correct because it prevents from listening to several multicast addresses at the same time. If doing the same on Windows is not possible I agree to make a special case.
Fabrice.
Quoted 16 lines · Fabrice Bellard
Quoted 8 lines · Kazu
Quoted 5 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
Quoted 6 lines
-net socket,connect doesn't work. On Windows host, connect returns with err
= WSAEWOULDBLOCK and second time err = WSAEINVAL. I think changing the place
of EWOULDBLOCK would be good. On Linux host, EWOULDBLOCK is the same as EAGAIN but a patch works on both Linux and Windows.
Quoted 4 lines
Unfortunately on Linux the correct return value we are expecting is EINPROGRESS. EAGAIN means that the 'connect' was not initiated so it is necessary to redo it.
There is not good way to detect a completion of asynchronous connect. So I used an event object to detect it. A patch is attached.
Quoted 9 lines
Quoted 4 lines
For -net socket,mcast, bind have to be done by sin_addr.s_addr =
INADDR_ANY.
It seems that it works on Linux host.It works on Linux but it is not correct because it prevents from listening to several multicast addresses at the same time. If doing the same on Windows is not possible I agree to make a special case.
I couldn't find a way to set a multicast address. I made it a special case in the patch
Regard,
Kazu
Index: vl.c
===================================================================
RCS file: /sources/qemu/qemu/vl.c,v
retrieving revision 1.162
vl.c 8 Feb 2006 05:50:28 -0000 renamed from vl.c 5 Feb 2006 04:14:41 -0000 1.162 +0 -0
@@ -1083,9 +1083,10 @@
#define socket_error() WSAGetLastError()
#undef EINTR
-#define EWOULDBLOCK WSAEWOULDBLOCK
-#define EINTR WSAEINTR
-#define EINPROGRESS WSAEINPROGRESS
+#define EWOULDBLOCK WSAEWOULDBLOCK +#define EINTR WSAEINTR +#define EINPROGRESS WSAEINPROGRESS
+#define EADDRNOTAVAIL WSAEADDRNOTAVAIL
static void socket_cleanup(void)
{
@@ -1136,6 +1137,59 @@
ioctlsocket(fd, FIONBIO, &opt); }
+static int socket_set_event(SOCKET fd, WSAEVENT *phEvent) +{
+ int ret;
+
+ *phEvent = WSACreateEvent();
+ if (*phEvent == WSA_INVALID_EVENT) {
+ perror("connect: CreateEvent");
+ return -1;
+ }
+
+ ret = WSAEventSelect(fd, *phEvent, FD_CONNECT);
+ if (ret == SOCKET_ERROR) {
+ perror("connect: EventSelect");
+ return -1;
+ }
+ return 0;
+}
+
+static int socket_wait_event(SOCKET fd, WSAEVENT *phEvent) +{
+ WSANETWORKEVENTS events;
+ int ret;
+
+ ret = WSAWaitForMultipleEvents(1, phEvent, FALSE, WSA_INFINITE, FALSE);
+ if (ret == WSA_WAIT_FAILED) {
+ perror("connect: Wait");
+ goto fail;
+ }
+
+ ret = WSAEnumNetworkEvents(fd, *phEvent, &events);
+ if (ret == SOCKET_ERROR) {
+ perror("connect: EnumEvent");
+ goto fail;
+ } else {
+ if (events.lNetworkEvents & FD_CONNECT) {
+ if (events.iErrorCode[FD_CONNECT_BIT] == 0) {
+ if (*phEvent != WSA_INVALID_EVENT)
+ WSACloseEvent(*phEvent);
+ return 1;
+ } else {
+ perror("connect: refused");
+ goto fail;
+ }
+ } else {
+ perror("connect: fd_connect");
+ goto fail;
+ }
+ }
+ fail:
+ if (*phEvent != WSA_INVALID_EVENT)
+ WSACloseEvent(*phEvent);
+ return 0;
+}
#else
#define socket_error() errno
@@ -2330,7 +2384,9 @@
{
struct ip_mreq imr;
int fd;
- int val, ret;
+ int val, ret, err;
+ struct sockaddr_in addr;
+
if (!IN_MULTICAST(ntohl(mcastaddr->sin_addr.s_addr))) { fprintf(stderr, "qemu: error: specified mcastaddr \"%s\" (0x%08x) does not
contain a multicast address\n",
inet_ntoa(mcastaddr->sin_addr),
@@ -2354,8 +2410,22 @@
ret = bind(fd, (struct sockaddr *)mcastaddr, sizeof(*mcastaddr));
if (ret < 0) {
- perror("bind");
- goto fail;
+ err = socket_error();
+ if (err == EADDRNOTAVAIL) {
+ memset(&addr, 0, sizeof(addr));
+ addr.sin_family = AF_INET;
+ addr.sin_port = mcastaddr->sin_port;
+ addr.sin_addr.s_addr = INADDR_ANY;+
+ ret = bind(fd, (struct sockaddr *)&addr, sizeof(addr));
+ if (ret < 0) {
+ perror("bind");
+ goto fail;
+ }
+ } else {
+ perror("bind");
+ goto fail;
+ }
}
/* Add host to multicast group */
@@ -2557,11 +2627,15 @@
return 0;
}+
static int net_socket_connect_init(VLANState *vlan, const char *host_str)
{
NetSocketState *s;
int fd, connected, ret, err;
struct sockaddr_in saddr;+#ifdef _WIN32
+ WSAEVENT hEvent;
+#endif
if (parse_host_port(&saddr, host_str) < 0)
return -1;
@@ -2573,6 +2647,26 @@
}
socket_set_nonblock(fd);+#ifdef _WIN32
+ ret = socket_set_event(fd, &hEvent);
+ if (ret < 0) {
+ perror("connect: set_event");
+ closesocket(fd);
+ return -1;+ }
+
+ connected = 0;
+ ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
+
+ err = socket_wait_event(fd, &hEvent);
+ if (err > 0) {
+ connected = 1;
+ } else {
+ perror("connect");
+ closesocket(fd);
+ return -1;
+ }
+#else
connected = 0;
for(;;) {
ret = connect(fd, (struct sockaddr *)&saddr, sizeof(saddr));
@@ -2591,6 +2685,8 @@
break;
}
}
+#endif
+
s = net_socket_fd_init(vlan, fd, connected);
if (!s)
return -1;Hi,
I send this mail again because it doesn't reach qemu-devel list by unknown security reason.
Quoted 10 lines · Fabrice Bellard
Quoted 9 lines · Kazu
Quoted 5 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
-net socket,connect doesn't work. On Windows host, connect returns with
err
Quoted 9 lines
Quoted 4 lines
= WSAEWOULDBLOCK and second time err = WSAEINVAL. I think changing the place
of EWOULDBLOCK would be good. On Linux host, EWOULDBLOCK is the same as EAGAIN but a patch works on both Linux and Windows.Unfortunately on Linux the correct return value we are expecting is EINPROGRESS. EAGAIN means that the 'connect' was not initiated so it is necessary to redo it.
There is not good way to detect a completion of asynchronous connect. So I used an event object to detect it. A patch is attached.
Quoted 9 lines
Quoted 4 lines
For -net socket,mcast, bind have to be done by sin_addr.s_addr =
INADDR_ANY.
It seems that it works on Linux host.It works on Linux but it is not correct because it prevents from listening to several multicast addresses at the same time. If doing the same on Windows is not possible I agree to make a special case.
I couldn't find a way to set a multicast address. I made it a special case in the patch
Regards,
Kazu
Quoted 9 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
Regards,
Fabrice.
Have you decided to accept the GPL license on it then?
http://lists.gnu.org/archive/html/qemu-devel/2004-10/msg00217.html
Signature · 2 lines
Infinite complexity begets infinite beauty. Infinite precision begets infinite perfection.
Quoted 9 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
Regards,
Fabrice.
Have you decided to accept the GPL license on it then?
http://lists.gnu.org/archive/html/qemu-devel/2004-10/msg00217.html
Signature · 2 lines
Infinite complexity begets infinite beauty. Infinite precision begets infinite perfection.
Quoted 9 lines · Jim C. Brown
Quoted 7 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
Regards,
Quoted 7 lines
Quoted 2 lines
Fabrice.
Have you decided to accept the GPL license on it then?
http://lists.gnu.org/archive/html/qemu-devel/2004-10/msg00217.html
Yes because the features are packed in a single file which can be removed if needed.
Fabrice.
Quoted 14 lines · Fabrice Bellard
Quoted 13 lines · Jim C. Brown
Quoted 9 lines · Fabrice Bellard
Hi,
I merged your patches and I made important changes to simplify them. I did not do any tests so tell me if you see problems.
Regards,
Fabrice.
Quoted 5 lines
Quoted 3 lines
Have you decided to accept the GPL license on it then?
http://lists.gnu.org/archive/html/qemu-devel/2004-10/msg00217.html
Yes because the features are packed in a single file which can be removed if needed.
Just checking, would that make it illegal to use this feature together with kqemu?
David
In message: <[email protected]>
David Fraser <[email protected]> writes:
: Fabrice Bellard wrote:
: > Jim C. Brown wrote:
: >> On Thu, Feb 02, 2006 at 12:10:36AM +0100, Fabrice Bellard wrote:
: >>
: >>> Hi,
: >>>
: >>> I merged your patches and I made important changes to simplify them. I : >>> did not do any tests so tell me if you see problems.
: >>>
: >>> Regards,
: >>>
: >>> Fabrice.
: >>>
: >>
: >>
: >> Have you decided to accept the GPL license on it then?
: >>
: >> http://lists.gnu.org/archive/html/qemu-devel/2004-10/msg00217.html
: >
: > Yes because the features are packed in a single file which can be : > removed if needed.
: Just checking, would that make it illegal to use this feature together : with kqemu?
No. The GPL is about distribution, not use.
It might make certain binary packages contrary to rights granted by the GPL.
Warner