4 * Copyright (c) 2003-2008 Fabrice Bellard
5 * Copyright (c) 2009 Red Hat, Inc.
7 * Permission is hereby granted, free of charge, to any person obtaining a copy
8 * of this software and associated documentation files (the "Software"), to deal
9 * in the Software without restriction, including without limitation the rights
10 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11 * copies of the Software, and to permit persons to whom the Software is
12 * furnished to do so, subject to the following conditions:
14 * The above copyright notice and this permission notice shall be included in
15 * all copies or substantial portions of the Software.
17 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
20 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
28 #include "config-host.h"
30 #include <sys/ioctl.h>
33 #include <sys/socket.h>
38 #include "monitor/monitor.h"
39 #include "sysemu/sysemu.h"
40 #include "qemu-common.h"
41 #include "qemu/error-report.h"
45 #include "net/vhost_net.h"
47 typedef struct TAPState
{
50 char down_script
[1024];
51 char down_script_arg
[128];
52 uint8_t buf
[NET_BUFSIZE
];
58 VHostNetState
*vhost_net
;
59 unsigned host_vnet_hdr_len
;
62 static int launch_script(const char *setup_script
, const char *ifname
, int fd
);
64 static int tap_can_send(void *opaque
);
65 static void tap_send(void *opaque
);
66 static void tap_writable(void *opaque
);
68 static void tap_update_fd_handler(TAPState
*s
)
70 qemu_set_fd_handler2(s
->fd
,
71 s
->read_poll
&& s
->enabled
? tap_can_send
: NULL
,
72 s
->read_poll
&& s
->enabled
? tap_send
: NULL
,
73 s
->write_poll
&& s
->enabled
? tap_writable
: NULL
,
77 static void tap_read_poll(TAPState
*s
, bool enable
)
79 s
->read_poll
= enable
;
80 tap_update_fd_handler(s
);
83 static void tap_write_poll(TAPState
*s
, bool enable
)
85 s
->write_poll
= enable
;
86 tap_update_fd_handler(s
);
89 static void tap_writable(void *opaque
)
93 tap_write_poll(s
, false);
95 qemu_flush_queued_packets(&s
->nc
);
98 static ssize_t
tap_write_packet(TAPState
*s
, const struct iovec
*iov
, int iovcnt
)
103 len
= writev(s
->fd
, iov
, iovcnt
);
104 } while (len
== -1 && errno
== EINTR
);
106 if (len
== -1 && errno
== EAGAIN
) {
107 tap_write_poll(s
, true);
114 static ssize_t
tap_receive_iov(NetClientState
*nc
, const struct iovec
*iov
,
117 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
118 const struct iovec
*iovp
= iov
;
119 struct iovec iov_copy
[iovcnt
+ 1];
120 struct virtio_net_hdr_mrg_rxbuf hdr
= { };
122 if (s
->host_vnet_hdr_len
&& !s
->using_vnet_hdr
) {
123 iov_copy
[0].iov_base
= &hdr
;
124 iov_copy
[0].iov_len
= s
->host_vnet_hdr_len
;
125 memcpy(&iov_copy
[1], iov
, iovcnt
* sizeof(*iov
));
130 return tap_write_packet(s
, iovp
, iovcnt
);
133 static ssize_t
tap_receive_raw(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
135 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
138 struct virtio_net_hdr_mrg_rxbuf hdr
= { };
140 if (s
->host_vnet_hdr_len
) {
141 iov
[iovcnt
].iov_base
= &hdr
;
142 iov
[iovcnt
].iov_len
= s
->host_vnet_hdr_len
;
146 iov
[iovcnt
].iov_base
= (char *)buf
;
147 iov
[iovcnt
].iov_len
= size
;
150 return tap_write_packet(s
, iov
, iovcnt
);
153 static ssize_t
tap_receive(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
155 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
158 if (s
->host_vnet_hdr_len
&& !s
->using_vnet_hdr
) {
159 return tap_receive_raw(nc
, buf
, size
);
162 iov
[0].iov_base
= (char *)buf
;
163 iov
[0].iov_len
= size
;
165 return tap_write_packet(s
, iov
, 1);
168 static int tap_can_send(void *opaque
)
170 TAPState
*s
= opaque
;
172 return qemu_can_send_packet(&s
->nc
);
176 ssize_t
tap_read_packet(int tapfd
, uint8_t *buf
, int maxlen
)
178 return read(tapfd
, buf
, maxlen
);
182 static void tap_send_completed(NetClientState
*nc
, ssize_t len
)
184 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
185 tap_read_poll(s
, true);
188 static void tap_send(void *opaque
)
190 TAPState
*s
= opaque
;
194 while (qemu_can_send_packet(&s
->nc
)) {
195 uint8_t *buf
= s
->buf
;
197 size
= tap_read_packet(s
->fd
, s
->buf
, sizeof(s
->buf
));
202 if (s
->host_vnet_hdr_len
&& !s
->using_vnet_hdr
) {
203 buf
+= s
->host_vnet_hdr_len
;
204 size
-= s
->host_vnet_hdr_len
;
207 size
= qemu_send_packet_async(&s
->nc
, buf
, size
, tap_send_completed
);
209 tap_read_poll(s
, false);
211 } else if (size
< 0) {
216 * When the host keeps receiving more packets while tap_send() is
217 * running we can hog the QEMU global mutex. Limit the number of
218 * packets that are processed per tap_send() callback to prevent
219 * stalling the guest.
228 static bool tap_has_ufo(NetClientState
*nc
)
230 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
232 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
237 static bool tap_has_vnet_hdr(NetClientState
*nc
)
239 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
241 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
243 return !!s
->host_vnet_hdr_len
;
246 static bool tap_has_vnet_hdr_len(NetClientState
*nc
, int len
)
248 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
250 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
252 return !!tap_probe_vnet_hdr_len(s
->fd
, len
);
255 static void tap_set_vnet_hdr_len(NetClientState
*nc
, int len
)
257 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
259 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
260 assert(len
== sizeof(struct virtio_net_hdr_mrg_rxbuf
) ||
261 len
== sizeof(struct virtio_net_hdr
));
263 tap_fd_set_vnet_hdr_len(s
->fd
, len
);
264 s
->host_vnet_hdr_len
= len
;
267 static void tap_using_vnet_hdr(NetClientState
*nc
, bool using_vnet_hdr
)
269 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
271 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
272 assert(!!s
->host_vnet_hdr_len
== using_vnet_hdr
);
274 s
->using_vnet_hdr
= using_vnet_hdr
;
277 static void tap_set_offload(NetClientState
*nc
, int csum
, int tso4
,
278 int tso6
, int ecn
, int ufo
)
280 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
285 tap_fd_set_offload(s
->fd
, csum
, tso4
, tso6
, ecn
, ufo
);
288 static void tap_cleanup(NetClientState
*nc
)
290 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
293 vhost_net_cleanup(s
->vhost_net
);
297 qemu_purge_queued_packets(nc
);
299 if (s
->down_script
[0])
300 launch_script(s
->down_script
, s
->down_script_arg
, s
->fd
);
302 tap_read_poll(s
, false);
303 tap_write_poll(s
, false);
308 static void tap_poll(NetClientState
*nc
, bool enable
)
310 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
311 tap_read_poll(s
, enable
);
312 tap_write_poll(s
, enable
);
315 int tap_get_fd(NetClientState
*nc
)
317 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
318 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
324 static NetClientInfo net_tap_info
= {
325 .type
= NET_CLIENT_OPTIONS_KIND_TAP
,
326 .size
= sizeof(TAPState
),
327 .receive
= tap_receive
,
328 .receive_raw
= tap_receive_raw
,
329 .receive_iov
= tap_receive_iov
,
331 .cleanup
= tap_cleanup
,
332 .has_ufo
= tap_has_ufo
,
333 .has_vnet_hdr
= tap_has_vnet_hdr
,
334 .has_vnet_hdr_len
= tap_has_vnet_hdr_len
,
335 .using_vnet_hdr
= tap_using_vnet_hdr
,
336 .set_offload
= tap_set_offload
,
337 .set_vnet_hdr_len
= tap_set_vnet_hdr_len
,
340 static TAPState
*net_tap_fd_init(NetClientState
*peer
,
349 nc
= qemu_new_net_client(&net_tap_info
, peer
, model
, name
);
351 s
= DO_UPCAST(TAPState
, nc
, nc
);
354 s
->host_vnet_hdr_len
= vnet_hdr
? sizeof(struct virtio_net_hdr
) : 0;
355 s
->using_vnet_hdr
= false;
356 s
->has_ufo
= tap_probe_has_ufo(s
->fd
);
358 tap_set_offload(&s
->nc
, 0, 0, 0, 0, 0);
360 * Make sure host header length is set correctly in tap:
361 * it might have been modified by another instance of qemu.
363 if (tap_probe_vnet_hdr_len(s
->fd
, s
->host_vnet_hdr_len
)) {
364 tap_fd_set_vnet_hdr_len(s
->fd
, s
->host_vnet_hdr_len
);
366 tap_read_poll(s
, true);
371 static int launch_script(const char *setup_script
, const char *ifname
, int fd
)
377 /* try to launch network script */
380 int open_max
= sysconf(_SC_OPEN_MAX
), i
;
382 for (i
= 3; i
< open_max
; i
++) {
388 *parg
++ = (char *)setup_script
;
389 *parg
++ = (char *)ifname
;
391 execv(setup_script
, args
);
393 } else if (pid
> 0) {
394 while (waitpid(pid
, &status
, 0) != pid
) {
398 if (WIFEXITED(status
) && WEXITSTATUS(status
) == 0) {
402 fprintf(stderr
, "%s: could not launch network script\n", setup_script
);
406 static int recv_fd(int c
)
409 uint8_t msgbuf
[CMSG_SPACE(sizeof(fd
))];
410 struct msghdr msg
= {
411 .msg_control
= msgbuf
,
412 .msg_controllen
= sizeof(msgbuf
),
414 struct cmsghdr
*cmsg
;
419 cmsg
= CMSG_FIRSTHDR(&msg
);
420 cmsg
->cmsg_level
= SOL_SOCKET
;
421 cmsg
->cmsg_type
= SCM_RIGHTS
;
422 cmsg
->cmsg_len
= CMSG_LEN(sizeof(fd
));
423 msg
.msg_controllen
= cmsg
->cmsg_len
;
426 iov
.iov_len
= sizeof(req
);
431 len
= recvmsg(c
, &msg
, 0);
433 memcpy(&fd
, CMSG_DATA(cmsg
), sizeof(fd
));
440 static int net_bridge_run_helper(const char *helper
, const char *bridge
)
442 sigset_t oldmask
, mask
;
449 sigaddset(&mask
, SIGCHLD
);
450 sigprocmask(SIG_BLOCK
, &mask
, &oldmask
);
452 if (socketpair(PF_UNIX
, SOCK_STREAM
, 0, sv
) == -1) {
456 /* try to launch bridge helper */
459 int open_max
= sysconf(_SC_OPEN_MAX
), i
;
461 char br_buf
[6+IFNAMSIZ
] = {0};
462 char helper_cmd
[PATH_MAX
+ sizeof(fd_buf
) + sizeof(br_buf
) + 15];
464 for (i
= 3; i
< open_max
; i
++) {
470 snprintf(fd_buf
, sizeof(fd_buf
), "%s%d", "--fd=", sv
[1]);
472 if (strrchr(helper
, ' ') || strrchr(helper
, '\t')) {
473 /* assume helper is a command */
475 if (strstr(helper
, "--br=") == NULL
) {
476 snprintf(br_buf
, sizeof(br_buf
), "%s%s", "--br=", bridge
);
479 snprintf(helper_cmd
, sizeof(helper_cmd
), "%s %s %s %s",
480 helper
, "--use-vnet", fd_buf
, br_buf
);
483 *parg
++ = (char *)"sh";
484 *parg
++ = (char *)"-c";
485 *parg
++ = helper_cmd
;
488 execv("/bin/sh", args
);
490 /* assume helper is just the executable path name */
492 snprintf(br_buf
, sizeof(br_buf
), "%s%s", "--br=", bridge
);
495 *parg
++ = (char *)helper
;
496 *parg
++ = (char *)"--use-vnet";
505 } else if (pid
> 0) {
512 } while (fd
== -1 && errno
== EINTR
);
516 while (waitpid(pid
, &status
, 0) != pid
) {
519 sigprocmask(SIG_SETMASK
, &oldmask
, NULL
);
521 fprintf(stderr
, "failed to recv file descriptor\n");
525 if (WIFEXITED(status
) && WEXITSTATUS(status
) == 0) {
529 fprintf(stderr
, "failed to launch bridge helper\n");
533 int net_init_bridge(const NetClientOptions
*opts
, const char *name
,
534 NetClientState
*peer
)
536 const NetdevBridgeOptions
*bridge
;
537 const char *helper
, *br
;
542 assert(opts
->kind
== NET_CLIENT_OPTIONS_KIND_BRIDGE
);
543 bridge
= opts
->bridge
;
545 helper
= bridge
->has_helper
? bridge
->helper
: DEFAULT_BRIDGE_HELPER
;
546 br
= bridge
->has_br
? bridge
->br
: DEFAULT_BRIDGE_INTERFACE
;
548 fd
= net_bridge_run_helper(helper
, br
);
553 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
555 vnet_hdr
= tap_probe_vnet_hdr(fd
);
557 s
= net_tap_fd_init(peer
, "bridge", name
, fd
, vnet_hdr
);
563 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
), "helper=%s,br=%s", helper
,
569 static int net_tap_init(const NetdevTapOptions
*tap
, int *vnet_hdr
,
570 const char *setup_script
, char *ifname
,
571 size_t ifname_sz
, int mq_required
)
573 int fd
, vnet_hdr_required
;
575 if (tap
->has_vnet_hdr
) {
576 *vnet_hdr
= tap
->vnet_hdr
;
577 vnet_hdr_required
= *vnet_hdr
;
580 vnet_hdr_required
= 0;
583 TFR(fd
= tap_open(ifname
, ifname_sz
, vnet_hdr
, vnet_hdr_required
,
590 setup_script
[0] != '\0' &&
591 strcmp(setup_script
, "no") != 0 &&
592 launch_script(setup_script
, ifname
, fd
)) {
600 #define MAX_TAP_QUEUES 1024
602 static int net_init_tap_one(const NetdevTapOptions
*tap
, NetClientState
*peer
,
603 const char *model
, const char *name
,
604 const char *ifname
, const char *script
,
605 const char *downscript
, const char *vhostfdname
,
606 int vnet_hdr
, int fd
)
611 s
= net_tap_fd_init(peer
, model
, name
, fd
, vnet_hdr
);
616 if (tap_set_sndbuf(s
->fd
, tap
) < 0) {
620 if (tap
->has_fd
|| tap
->has_fds
) {
621 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
), "fd=%d", fd
);
622 } else if (tap
->has_helper
) {
623 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
), "helper=%s",
626 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
),
627 "ifname=%s,script=%s,downscript=%s", ifname
, script
,
630 if (strcmp(downscript
, "no") != 0) {
631 snprintf(s
->down_script
, sizeof(s
->down_script
), "%s", downscript
);
632 snprintf(s
->down_script_arg
, sizeof(s
->down_script_arg
),
637 if (tap
->has_vhost
? tap
->vhost
:
638 vhostfdname
|| (tap
->has_vhostforce
&& tap
->vhostforce
)) {
639 VhostNetOptions options
;
641 options
.backend_type
= VHOST_BACKEND_TYPE_KERNEL
;
642 options
.net_backend
= &s
->nc
;
643 options
.force
= tap
->has_vhostforce
&& tap
->vhostforce
;
645 if (tap
->has_vhostfd
|| tap
->has_vhostfds
) {
646 vhostfd
= monitor_handle_fd_param(cur_mon
, vhostfdname
);
651 vhostfd
= open("/dev/vhost-net", O_RDWR
);
653 error_report("tap: open vhost char device failed: %s",
658 options
.opaque
= (void *)(uintptr_t)vhostfd
;
660 s
->vhost_net
= vhost_net_init(&options
);
662 error_report("vhost-net requested but could not be initialized");
665 } else if (tap
->has_vhostfd
|| tap
->has_vhostfds
) {
666 error_report("vhostfd= is not valid without vhost");
673 static int get_fds(char *str
, char *fds
[], int max
)
675 char *ptr
= str
, *this;
676 size_t len
= strlen(str
);
679 while (i
< max
&& ptr
< str
+ len
) {
680 this = strchr(ptr
, ':');
683 fds
[i
] = g_strdup(ptr
);
685 fds
[i
] = g_strndup(ptr
, this - ptr
);
699 int net_init_tap(const NetClientOptions
*opts
, const char *name
,
700 NetClientState
*peer
)
702 const NetdevTapOptions
*tap
;
703 int fd
, vnet_hdr
= 0, i
= 0, queues
;
704 /* for the no-fd, no-helper case */
705 const char *script
= NULL
; /* suppress wrong "uninit'd use" gcc warning */
706 const char *downscript
= NULL
;
707 const char *vhostfdname
;
710 assert(opts
->kind
== NET_CLIENT_OPTIONS_KIND_TAP
);
712 queues
= tap
->has_queues
? tap
->queues
: 1;
713 vhostfdname
= tap
->has_vhostfd
? tap
->vhostfd
: NULL
;
715 /* QEMU vlans does not support multiqueue tap, in this case peer is set.
716 * For -netdev, peer is always NULL. */
717 if (peer
&& (tap
->has_queues
|| tap
->has_fds
|| tap
->has_vhostfds
)) {
718 error_report("Multiqueue tap cannot be used with QEMU vlans");
723 if (tap
->has_ifname
|| tap
->has_script
|| tap
->has_downscript
||
724 tap
->has_vnet_hdr
|| tap
->has_helper
|| tap
->has_queues
||
725 tap
->has_fds
|| tap
->has_vhostfds
) {
726 error_report("ifname=, script=, downscript=, vnet_hdr=, "
727 "helper=, queues=, fds=, and vhostfds= "
728 "are invalid with fd=");
732 fd
= monitor_handle_fd_param(cur_mon
, tap
->fd
);
737 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
739 vnet_hdr
= tap_probe_vnet_hdr(fd
);
741 if (net_init_tap_one(tap
, peer
, "tap", name
, NULL
,
743 vhostfdname
, vnet_hdr
, fd
)) {
746 } else if (tap
->has_fds
) {
747 char *fds
[MAX_TAP_QUEUES
];
748 char *vhost_fds
[MAX_TAP_QUEUES
];
751 if (tap
->has_ifname
|| tap
->has_script
|| tap
->has_downscript
||
752 tap
->has_vnet_hdr
|| tap
->has_helper
|| tap
->has_queues
||
754 error_report("ifname=, script=, downscript=, vnet_hdr=, "
755 "helper=, queues=, and vhostfd= "
756 "are invalid with fds=");
760 nfds
= get_fds(tap
->fds
, fds
, MAX_TAP_QUEUES
);
761 if (tap
->has_vhostfds
) {
762 nvhosts
= get_fds(tap
->vhostfds
, vhost_fds
, MAX_TAP_QUEUES
);
763 if (nfds
!= nvhosts
) {
764 error_report("The number of fds passed does not match the "
765 "number of vhostfds passed");
770 for (i
= 0; i
< nfds
; i
++) {
771 fd
= monitor_handle_fd_param(cur_mon
, fds
[i
]);
776 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
779 vnet_hdr
= tap_probe_vnet_hdr(fd
);
780 } else if (vnet_hdr
!= tap_probe_vnet_hdr(fd
)) {
781 error_report("vnet_hdr not consistent across given tap fds");
785 if (net_init_tap_one(tap
, peer
, "tap", name
, ifname
,
787 tap
->has_vhostfds
? vhost_fds
[i
] : NULL
,
792 } else if (tap
->has_helper
) {
793 if (tap
->has_ifname
|| tap
->has_script
|| tap
->has_downscript
||
794 tap
->has_vnet_hdr
|| tap
->has_queues
|| tap
->has_vhostfds
) {
795 error_report("ifname=, script=, downscript=, and vnet_hdr= "
796 "queues=, and vhostfds= are invalid with helper=");
800 fd
= net_bridge_run_helper(tap
->helper
, DEFAULT_BRIDGE_INTERFACE
);
805 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
806 vnet_hdr
= tap_probe_vnet_hdr(fd
);
808 if (net_init_tap_one(tap
, peer
, "bridge", name
, ifname
,
809 script
, downscript
, vhostfdname
,
815 if (tap
->has_vhostfds
) {
816 error_report("vhostfds= is invalid if fds= wasn't specified");
819 script
= tap
->has_script
? tap
->script
: DEFAULT_NETWORK_SCRIPT
;
820 downscript
= tap
->has_downscript
? tap
->downscript
:
821 DEFAULT_NETWORK_DOWN_SCRIPT
;
823 if (tap
->has_ifname
) {
824 pstrcpy(ifname
, sizeof ifname
, tap
->ifname
);
829 for (i
= 0; i
< queues
; i
++) {
830 fd
= net_tap_init(tap
, &vnet_hdr
, i
>= 1 ? "no" : script
,
831 ifname
, sizeof ifname
, queues
> 1);
836 if (queues
> 1 && i
== 0 && !tap
->has_ifname
) {
837 if (tap_fd_get_ifname(fd
, ifname
)) {
838 error_report("Fail to get ifname");
844 if (net_init_tap_one(tap
, peer
, "tap", name
, ifname
,
845 i
>= 1 ? "no" : script
,
846 i
>= 1 ? "no" : downscript
,
847 vhostfdname
, vnet_hdr
, fd
)) {
857 VHostNetState
*tap_get_vhost_net(NetClientState
*nc
)
859 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
860 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
864 int tap_enable(NetClientState
*nc
)
866 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
872 ret
= tap_fd_enable(s
->fd
);
875 tap_update_fd_handler(s
);
881 int tap_disable(NetClientState
*nc
)
883 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
886 if (s
->enabled
== 0) {
889 ret
= tap_fd_disable(s
->fd
);
891 qemu_purge_queued_packets(nc
);
893 tap_update_fd_handler(s
);