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 void launch_script(const char *setup_script
, const char *ifname
,
63 int fd
, Error
**errp
);
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_handler(s
->fd
,
71 s
->read_poll
&& s
->enabled
? tap_send
: NULL
,
72 s
->write_poll
&& s
->enabled
? tap_writable
: NULL
,
76 static void tap_read_poll(TAPState
*s
, bool enable
)
78 s
->read_poll
= enable
;
79 tap_update_fd_handler(s
);
82 static void tap_write_poll(TAPState
*s
, bool enable
)
84 s
->write_poll
= enable
;
85 tap_update_fd_handler(s
);
88 static void tap_writable(void *opaque
)
92 tap_write_poll(s
, false);
94 qemu_flush_queued_packets(&s
->nc
);
97 static ssize_t
tap_write_packet(TAPState
*s
, const struct iovec
*iov
, int iovcnt
)
102 len
= writev(s
->fd
, iov
, iovcnt
);
103 } while (len
== -1 && errno
== EINTR
);
105 if (len
== -1 && errno
== EAGAIN
) {
106 tap_write_poll(s
, true);
113 static ssize_t
tap_receive_iov(NetClientState
*nc
, const struct iovec
*iov
,
116 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
117 const struct iovec
*iovp
= iov
;
118 struct iovec iov_copy
[iovcnt
+ 1];
119 struct virtio_net_hdr_mrg_rxbuf hdr
= { };
121 if (s
->host_vnet_hdr_len
&& !s
->using_vnet_hdr
) {
122 iov_copy
[0].iov_base
= &hdr
;
123 iov_copy
[0].iov_len
= s
->host_vnet_hdr_len
;
124 memcpy(&iov_copy
[1], iov
, iovcnt
* sizeof(*iov
));
129 return tap_write_packet(s
, iovp
, iovcnt
);
132 static ssize_t
tap_receive_raw(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
134 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
137 struct virtio_net_hdr_mrg_rxbuf hdr
= { };
139 if (s
->host_vnet_hdr_len
) {
140 iov
[iovcnt
].iov_base
= &hdr
;
141 iov
[iovcnt
].iov_len
= s
->host_vnet_hdr_len
;
145 iov
[iovcnt
].iov_base
= (char *)buf
;
146 iov
[iovcnt
].iov_len
= size
;
149 return tap_write_packet(s
, iov
, iovcnt
);
152 static ssize_t
tap_receive(NetClientState
*nc
, const uint8_t *buf
, size_t size
)
154 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
157 if (s
->host_vnet_hdr_len
&& !s
->using_vnet_hdr
) {
158 return tap_receive_raw(nc
, buf
, size
);
161 iov
[0].iov_base
= (char *)buf
;
162 iov
[0].iov_len
= size
;
164 return tap_write_packet(s
, iov
, 1);
168 ssize_t
tap_read_packet(int tapfd
, uint8_t *buf
, int maxlen
)
170 return read(tapfd
, buf
, maxlen
);
174 static void tap_send_completed(NetClientState
*nc
, ssize_t len
)
176 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
177 tap_read_poll(s
, true);
180 static void tap_send(void *opaque
)
182 TAPState
*s
= opaque
;
187 uint8_t *buf
= s
->buf
;
189 size
= tap_read_packet(s
->fd
, s
->buf
, sizeof(s
->buf
));
194 if (s
->host_vnet_hdr_len
&& !s
->using_vnet_hdr
) {
195 buf
+= s
->host_vnet_hdr_len
;
196 size
-= s
->host_vnet_hdr_len
;
199 size
= qemu_send_packet_async(&s
->nc
, buf
, size
, tap_send_completed
);
201 tap_read_poll(s
, false);
203 } else if (size
< 0) {
208 * When the host keeps receiving more packets while tap_send() is
209 * running we can hog the QEMU global mutex. Limit the number of
210 * packets that are processed per tap_send() callback to prevent
211 * stalling the guest.
220 static bool tap_has_ufo(NetClientState
*nc
)
222 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
224 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
229 static bool tap_has_vnet_hdr(NetClientState
*nc
)
231 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
233 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
235 return !!s
->host_vnet_hdr_len
;
238 static bool tap_has_vnet_hdr_len(NetClientState
*nc
, int len
)
240 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
242 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
244 return !!tap_probe_vnet_hdr_len(s
->fd
, len
);
247 static void tap_set_vnet_hdr_len(NetClientState
*nc
, int len
)
249 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
251 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
252 assert(len
== sizeof(struct virtio_net_hdr_mrg_rxbuf
) ||
253 len
== sizeof(struct virtio_net_hdr
));
255 tap_fd_set_vnet_hdr_len(s
->fd
, len
);
256 s
->host_vnet_hdr_len
= len
;
259 static void tap_using_vnet_hdr(NetClientState
*nc
, bool using_vnet_hdr
)
261 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
263 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
264 assert(!!s
->host_vnet_hdr_len
== using_vnet_hdr
);
266 s
->using_vnet_hdr
= using_vnet_hdr
;
269 static void tap_set_offload(NetClientState
*nc
, int csum
, int tso4
,
270 int tso6
, int ecn
, int ufo
)
272 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
277 tap_fd_set_offload(s
->fd
, csum
, tso4
, tso6
, ecn
, ufo
);
280 static void tap_cleanup(NetClientState
*nc
)
282 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
286 vhost_net_cleanup(s
->vhost_net
);
290 qemu_purge_queued_packets(nc
);
292 if (s
->down_script
[0]) {
293 launch_script(s
->down_script
, s
->down_script_arg
, s
->fd
, &err
);
295 error_report_err(err
);
299 tap_read_poll(s
, false);
300 tap_write_poll(s
, false);
305 static void tap_poll(NetClientState
*nc
, bool enable
)
307 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
308 tap_read_poll(s
, enable
);
309 tap_write_poll(s
, enable
);
312 int tap_get_fd(NetClientState
*nc
)
314 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
315 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
321 static NetClientInfo net_tap_info
= {
322 .type
= NET_CLIENT_OPTIONS_KIND_TAP
,
323 .size
= sizeof(TAPState
),
324 .receive
= tap_receive
,
325 .receive_raw
= tap_receive_raw
,
326 .receive_iov
= tap_receive_iov
,
328 .cleanup
= tap_cleanup
,
329 .has_ufo
= tap_has_ufo
,
330 .has_vnet_hdr
= tap_has_vnet_hdr
,
331 .has_vnet_hdr_len
= tap_has_vnet_hdr_len
,
332 .using_vnet_hdr
= tap_using_vnet_hdr
,
333 .set_offload
= tap_set_offload
,
334 .set_vnet_hdr_len
= tap_set_vnet_hdr_len
,
337 static TAPState
*net_tap_fd_init(NetClientState
*peer
,
346 nc
= qemu_new_net_client(&net_tap_info
, peer
, model
, name
);
348 s
= DO_UPCAST(TAPState
, nc
, nc
);
351 s
->host_vnet_hdr_len
= vnet_hdr
? sizeof(struct virtio_net_hdr
) : 0;
352 s
->using_vnet_hdr
= false;
353 s
->has_ufo
= tap_probe_has_ufo(s
->fd
);
355 tap_set_offload(&s
->nc
, 0, 0, 0, 0, 0);
357 * Make sure host header length is set correctly in tap:
358 * it might have been modified by another instance of qemu.
360 if (tap_probe_vnet_hdr_len(s
->fd
, s
->host_vnet_hdr_len
)) {
361 tap_fd_set_vnet_hdr_len(s
->fd
, s
->host_vnet_hdr_len
);
363 tap_read_poll(s
, true);
368 static void launch_script(const char *setup_script
, const char *ifname
,
369 int fd
, Error
**errp
)
375 /* try to launch network script */
378 error_setg_errno(errp
, errno
, "could not launch network script %s",
383 int open_max
= sysconf(_SC_OPEN_MAX
), i
;
385 for (i
= 3; i
< open_max
; i
++) {
391 *parg
++ = (char *)setup_script
;
392 *parg
++ = (char *)ifname
;
394 execv(setup_script
, args
);
397 while (waitpid(pid
, &status
, 0) != pid
) {
401 if (WIFEXITED(status
) && WEXITSTATUS(status
) == 0) {
404 error_setg(errp
, "network script %s failed with status %d",
405 setup_script
, status
);
409 static int recv_fd(int c
)
412 uint8_t msgbuf
[CMSG_SPACE(sizeof(fd
))];
413 struct msghdr msg
= {
414 .msg_control
= msgbuf
,
415 .msg_controllen
= sizeof(msgbuf
),
417 struct cmsghdr
*cmsg
;
422 cmsg
= CMSG_FIRSTHDR(&msg
);
423 cmsg
->cmsg_level
= SOL_SOCKET
;
424 cmsg
->cmsg_type
= SCM_RIGHTS
;
425 cmsg
->cmsg_len
= CMSG_LEN(sizeof(fd
));
426 msg
.msg_controllen
= cmsg
->cmsg_len
;
429 iov
.iov_len
= sizeof(req
);
434 len
= recvmsg(c
, &msg
, 0);
436 memcpy(&fd
, CMSG_DATA(cmsg
), sizeof(fd
));
443 static int net_bridge_run_helper(const char *helper
, const char *bridge
,
446 sigset_t oldmask
, mask
;
453 sigaddset(&mask
, SIGCHLD
);
454 sigprocmask(SIG_BLOCK
, &mask
, &oldmask
);
456 if (socketpair(PF_UNIX
, SOCK_STREAM
, 0, sv
) == -1) {
457 error_setg_errno(errp
, errno
, "socketpair() failed");
461 /* try to launch bridge helper */
464 error_setg_errno(errp
, errno
, "Can't fork bridge helper");
468 int open_max
= sysconf(_SC_OPEN_MAX
), i
;
470 char br_buf
[6+IFNAMSIZ
] = {0};
471 char helper_cmd
[PATH_MAX
+ sizeof(fd_buf
) + sizeof(br_buf
) + 15];
473 for (i
= 3; i
< open_max
; i
++) {
479 snprintf(fd_buf
, sizeof(fd_buf
), "%s%d", "--fd=", sv
[1]);
481 if (strrchr(helper
, ' ') || strrchr(helper
, '\t')) {
482 /* assume helper is a command */
484 if (strstr(helper
, "--br=") == NULL
) {
485 snprintf(br_buf
, sizeof(br_buf
), "%s%s", "--br=", bridge
);
488 snprintf(helper_cmd
, sizeof(helper_cmd
), "%s %s %s %s",
489 helper
, "--use-vnet", fd_buf
, br_buf
);
492 *parg
++ = (char *)"sh";
493 *parg
++ = (char *)"-c";
494 *parg
++ = helper_cmd
;
497 execv("/bin/sh", args
);
499 /* assume helper is just the executable path name */
501 snprintf(br_buf
, sizeof(br_buf
), "%s%s", "--br=", bridge
);
504 *parg
++ = (char *)helper
;
505 *parg
++ = (char *)"--use-vnet";
522 } while (fd
== -1 && errno
== EINTR
);
527 while (waitpid(pid
, &status
, 0) != pid
) {
530 sigprocmask(SIG_SETMASK
, &oldmask
, NULL
);
532 error_setg_errno(errp
, saved_errno
,
533 "failed to recv file descriptor");
536 if (!WIFEXITED(status
) || WEXITSTATUS(status
) != 0) {
537 error_setg(errp
, "bridge helper failed");
544 int net_init_bridge(const NetClientOptions
*opts
, const char *name
,
545 NetClientState
*peer
, Error
**errp
)
547 const NetdevBridgeOptions
*bridge
;
548 const char *helper
, *br
;
552 assert(opts
->kind
== NET_CLIENT_OPTIONS_KIND_BRIDGE
);
553 bridge
= opts
->bridge
;
555 helper
= bridge
->has_helper
? bridge
->helper
: DEFAULT_BRIDGE_HELPER
;
556 br
= bridge
->has_br
? bridge
->br
: DEFAULT_BRIDGE_INTERFACE
;
558 fd
= net_bridge_run_helper(helper
, br
, errp
);
563 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
564 vnet_hdr
= tap_probe_vnet_hdr(fd
);
565 s
= net_tap_fd_init(peer
, "bridge", name
, fd
, vnet_hdr
);
567 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
), "helper=%s,br=%s", helper
,
573 static int net_tap_init(const NetdevTapOptions
*tap
, int *vnet_hdr
,
574 const char *setup_script
, char *ifname
,
575 size_t ifname_sz
, int mq_required
, Error
**errp
)
578 int fd
, vnet_hdr_required
;
580 if (tap
->has_vnet_hdr
) {
581 *vnet_hdr
= tap
->vnet_hdr
;
582 vnet_hdr_required
= *vnet_hdr
;
585 vnet_hdr_required
= 0;
588 TFR(fd
= tap_open(ifname
, ifname_sz
, vnet_hdr
, vnet_hdr_required
,
595 setup_script
[0] != '\0' &&
596 strcmp(setup_script
, "no") != 0) {
597 launch_script(setup_script
, ifname
, fd
, &err
);
599 error_propagate(errp
, err
);
608 #define MAX_TAP_QUEUES 1024
610 static void net_init_tap_one(const NetdevTapOptions
*tap
, NetClientState
*peer
,
611 const char *model
, const char *name
,
612 const char *ifname
, const char *script
,
613 const char *downscript
, const char *vhostfdname
,
614 int vnet_hdr
, int fd
, Error
**errp
)
617 TAPState
*s
= net_tap_fd_init(peer
, model
, name
, fd
, vnet_hdr
);
620 tap_set_sndbuf(s
->fd
, tap
, &err
);
622 error_propagate(errp
, err
);
626 if (tap
->has_fd
|| tap
->has_fds
) {
627 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
), "fd=%d", fd
);
628 } else if (tap
->has_helper
) {
629 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
), "helper=%s",
632 snprintf(s
->nc
.info_str
, sizeof(s
->nc
.info_str
),
633 "ifname=%s,script=%s,downscript=%s", ifname
, script
,
636 if (strcmp(downscript
, "no") != 0) {
637 snprintf(s
->down_script
, sizeof(s
->down_script
), "%s", downscript
);
638 snprintf(s
->down_script_arg
, sizeof(s
->down_script_arg
),
643 if (tap
->has_vhost
? tap
->vhost
:
644 vhostfdname
|| (tap
->has_vhostforce
&& tap
->vhostforce
)) {
645 VhostNetOptions options
;
647 options
.backend_type
= VHOST_BACKEND_TYPE_KERNEL
;
648 options
.net_backend
= &s
->nc
;
649 options
.force
= tap
->has_vhostforce
&& tap
->vhostforce
;
651 if (tap
->has_vhostfd
|| tap
->has_vhostfds
) {
652 vhostfd
= monitor_fd_param(cur_mon
, vhostfdname
, &err
);
654 error_propagate(errp
, err
);
658 vhostfd
= open("/dev/vhost-net", O_RDWR
);
660 error_setg_errno(errp
, errno
,
661 "tap: open vhost char device failed");
665 options
.opaque
= (void *)(uintptr_t)vhostfd
;
667 s
->vhost_net
= vhost_net_init(&options
);
670 "vhost-net requested but could not be initialized");
673 } else if (tap
->has_vhostfd
|| tap
->has_vhostfds
) {
674 error_setg(errp
, "vhostfd= is not valid without vhost");
678 static int get_fds(char *str
, char *fds
[], int max
)
680 char *ptr
= str
, *this;
681 size_t len
= strlen(str
);
684 while (i
< max
&& ptr
< str
+ len
) {
685 this = strchr(ptr
, ':');
688 fds
[i
] = g_strdup(ptr
);
690 fds
[i
] = g_strndup(ptr
, this - ptr
);
704 int net_init_tap(const NetClientOptions
*opts
, const char *name
,
705 NetClientState
*peer
, Error
**errp
)
707 const NetdevTapOptions
*tap
;
708 int fd
, vnet_hdr
= 0, i
= 0, queues
;
709 /* for the no-fd, no-helper case */
710 const char *script
= NULL
; /* suppress wrong "uninit'd use" gcc warning */
711 const char *downscript
= NULL
;
713 const char *vhostfdname
;
716 assert(opts
->kind
== NET_CLIENT_OPTIONS_KIND_TAP
);
718 queues
= tap
->has_queues
? tap
->queues
: 1;
719 vhostfdname
= tap
->has_vhostfd
? tap
->vhostfd
: NULL
;
721 /* QEMU vlans does not support multiqueue tap, in this case peer is set.
722 * For -netdev, peer is always NULL. */
723 if (peer
&& (tap
->has_queues
|| tap
->has_fds
|| tap
->has_vhostfds
)) {
724 error_setg(errp
, "Multiqueue tap cannot be used with QEMU vlans");
729 if (tap
->has_ifname
|| tap
->has_script
|| tap
->has_downscript
||
730 tap
->has_vnet_hdr
|| tap
->has_helper
|| tap
->has_queues
||
731 tap
->has_fds
|| tap
->has_vhostfds
) {
732 error_setg(errp
, "ifname=, script=, downscript=, vnet_hdr=, "
733 "helper=, queues=, fds=, and vhostfds= "
734 "are invalid with fd=");
738 fd
= monitor_fd_param(cur_mon
, tap
->fd
, &err
);
740 error_propagate(errp
, err
);
744 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
746 vnet_hdr
= tap_probe_vnet_hdr(fd
);
748 net_init_tap_one(tap
, peer
, "tap", name
, NULL
,
750 vhostfdname
, vnet_hdr
, fd
, &err
);
752 error_propagate(errp
, err
);
755 } else if (tap
->has_fds
) {
756 char *fds
[MAX_TAP_QUEUES
];
757 char *vhost_fds
[MAX_TAP_QUEUES
];
760 if (tap
->has_ifname
|| tap
->has_script
|| tap
->has_downscript
||
761 tap
->has_vnet_hdr
|| tap
->has_helper
|| tap
->has_queues
||
763 error_setg(errp
, "ifname=, script=, downscript=, vnet_hdr=, "
764 "helper=, queues=, and vhostfd= "
765 "are invalid with fds=");
769 nfds
= get_fds(tap
->fds
, fds
, MAX_TAP_QUEUES
);
770 if (tap
->has_vhostfds
) {
771 nvhosts
= get_fds(tap
->vhostfds
, vhost_fds
, MAX_TAP_QUEUES
);
772 if (nfds
!= nvhosts
) {
773 error_setg(errp
, "The number of fds passed does not match "
774 "the number of vhostfds passed");
779 for (i
= 0; i
< nfds
; i
++) {
780 fd
= monitor_fd_param(cur_mon
, fds
[i
], &err
);
782 error_propagate(errp
, err
);
786 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
789 vnet_hdr
= tap_probe_vnet_hdr(fd
);
790 } else if (vnet_hdr
!= tap_probe_vnet_hdr(fd
)) {
792 "vnet_hdr not consistent across given tap fds");
796 net_init_tap_one(tap
, peer
, "tap", name
, ifname
,
798 tap
->has_vhostfds
? vhost_fds
[i
] : NULL
,
801 error_propagate(errp
, err
);
805 } else if (tap
->has_helper
) {
806 if (tap
->has_ifname
|| tap
->has_script
|| tap
->has_downscript
||
807 tap
->has_vnet_hdr
|| tap
->has_queues
|| tap
->has_vhostfds
) {
808 error_setg(errp
, "ifname=, script=, downscript=, vnet_hdr=, "
809 "queues=, and vhostfds= are invalid with helper=");
813 fd
= net_bridge_run_helper(tap
->helper
, DEFAULT_BRIDGE_INTERFACE
,
819 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
820 vnet_hdr
= tap_probe_vnet_hdr(fd
);
822 net_init_tap_one(tap
, peer
, "bridge", name
, ifname
,
823 script
, downscript
, vhostfdname
,
826 error_propagate(errp
, err
);
831 if (tap
->has_vhostfds
) {
832 error_setg(errp
, "vhostfds= is invalid if fds= wasn't specified");
835 script
= tap
->has_script
? tap
->script
: DEFAULT_NETWORK_SCRIPT
;
836 downscript
= tap
->has_downscript
? tap
->downscript
:
837 DEFAULT_NETWORK_DOWN_SCRIPT
;
839 if (tap
->has_ifname
) {
840 pstrcpy(ifname
, sizeof ifname
, tap
->ifname
);
845 for (i
= 0; i
< queues
; i
++) {
846 fd
= net_tap_init(tap
, &vnet_hdr
, i
>= 1 ? "no" : script
,
847 ifname
, sizeof ifname
, queues
> 1, errp
);
852 if (queues
> 1 && i
== 0 && !tap
->has_ifname
) {
853 if (tap_fd_get_ifname(fd
, ifname
)) {
854 error_setg(errp
, "Fail to get ifname");
860 net_init_tap_one(tap
, peer
, "tap", name
, ifname
,
861 i
>= 1 ? "no" : script
,
862 i
>= 1 ? "no" : downscript
,
863 vhostfdname
, vnet_hdr
, fd
, &err
);
865 error_propagate(errp
, err
);
875 VHostNetState
*tap_get_vhost_net(NetClientState
*nc
)
877 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
878 assert(nc
->info
->type
== NET_CLIENT_OPTIONS_KIND_TAP
);
882 int tap_enable(NetClientState
*nc
)
884 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
890 ret
= tap_fd_enable(s
->fd
);
893 tap_update_fd_handler(s
);
899 int tap_disable(NetClientState
*nc
)
901 TAPState
*s
= DO_UPCAST(TAPState
, nc
, nc
);
904 if (s
->enabled
== 0) {
907 ret
= tap_fd_disable(s
->fd
);
909 qemu_purge_queued_packets(nc
);
911 tap_update_fd_handler(s
);