4 * Copyright (c) 2003-2008 Fabrice Bellard
6 * Permission is hereby granted, free of charge, to any person obtaining a copy
7 * of this software and associated documentation files (the "Software"), to deal
8 * in the Software without restriction, including without limitation the rights
9 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10 * copies of the Software, and to permit persons to whom the Software is
11 * furnished to do so, subject to the following conditions:
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
24 #include "qemu-common.h"
28 #include "qemu-timer.h"
29 #include "qemu-char.h"
30 #include "audio/audio.h"
41 #include <sys/times.h>
45 #include <sys/ioctl.h>
46 #include <sys/resource.h>
47 #include <sys/socket.h>
48 #include <netinet/in.h>
51 #include <net/if_tap.h>
54 #include <linux/if_tun.h>
56 #include <arpa/inet.h>
59 #include <sys/select.h>
67 #elif defined (__GLIBC__) && defined (__FreeBSD_kernel__)
68 #include <freebsd/stdlib.h>
73 #include <linux/rtc.h>
75 /* For the benefit of older linux systems which don't supply it,
76 we use a local copy of hpet.h. */
77 /* #include <linux/hpet.h> */
80 #include <linux/ppdev.h>
81 #include <linux/parport.h>
85 #include <sys/ethernet.h>
86 #include <sys/sockio.h>
87 #include <netinet/arp.h>
88 #include <netinet/in.h>
89 #include <netinet/in_systm.h>
90 #include <netinet/ip.h>
91 #include <netinet/ip_icmp.h> // must come after ip.h
92 #include <netinet/udp.h>
93 #include <netinet/tcp.h>
101 #include "qemu_socket.h"
103 #if defined(CONFIG_SLIRP)
104 #include "libslirp.h"
107 #if defined(__OpenBSD__)
111 #if defined(CONFIG_VDE)
112 #include <libvdeplug.h>
117 #include <sys/timeb.h>
118 #include <mmsystem.h>
119 #define getopt_long_only getopt_long
120 #define memalign(align, size) malloc(size)
123 // FIXME: #include "qemu-kvm.h"
125 static VLANState
*first_vlan
;
127 /***********************************************************/
128 /* network device redirectors */
130 #if defined(DEBUG_NET) || defined(DEBUG_SLIRP)
131 static void hex_dump(FILE *f
, const uint8_t *buf
, int size
)
135 for(i
=0;i
<size
;i
+=16) {
139 fprintf(f
, "%08x ", i
);
142 fprintf(f
, " %02x", buf
[i
+j
]);
149 if (c
< ' ' || c
> '~')
158 static int parse_macaddr(uint8_t *macaddr
, const char *p
)
165 offset
= strtol(p
, &last_char
, 0);
166 if (0 == errno
&& '\0' == *last_char
&&
167 offset
>= 0 && offset
<= 0xFFFFFF) {
168 macaddr
[3] = (offset
& 0xFF0000) >> 16;
169 macaddr
[4] = (offset
& 0xFF00) >> 8;
170 macaddr
[5] = offset
& 0xFF;
173 for(i
= 0; i
< 6; i
++) {
174 macaddr
[i
] = strtol(p
, (char **)&p
, 16);
179 if (*p
!= ':' && *p
!= '-')
190 static int get_str_sep(char *buf
, int buf_size
, const char **pp
, int sep
)
201 if (len
> buf_size
- 1)
210 int parse_host_src_port(struct sockaddr_in
*haddr
,
211 struct sockaddr_in
*saddr
,
212 const char *input_str
)
214 char *str
= strdup(input_str
);
215 char *host_str
= str
;
217 const char *src_str2
;
221 * Chop off any extra arguments at the end of the string which
222 * would start with a comma, then fill in the src port information
223 * if it was provided else use the "any address" and "any port".
225 if ((ptr
= strchr(str
,',')))
228 if ((src_str
= strchr(input_str
,'@'))) {
233 if (parse_host_port(haddr
, host_str
) < 0)
237 if (!src_str
|| *src_str
== '\0')
240 if (parse_host_port(saddr
, src_str2
) < 0)
251 int parse_host_port(struct sockaddr_in
*saddr
, const char *str
)
259 if (get_str_sep(buf
, sizeof(buf
), &p
, ':') < 0)
261 saddr
->sin_family
= AF_INET
;
262 if (buf
[0] == '\0') {
263 saddr
->sin_addr
.s_addr
= 0;
265 if (qemu_isdigit(buf
[0])) {
266 if (!inet_aton(buf
, &saddr
->sin_addr
))
269 if ((he
= gethostbyname(buf
)) == NULL
)
271 saddr
->sin_addr
= *(struct in_addr
*)he
->h_addr
;
274 port
= strtol(p
, (char **)&r
, 0);
277 saddr
->sin_port
= htons(port
);
281 #if !defined(_WIN32) && 0
282 static int parse_unix_path(struct sockaddr_un
*uaddr
, const char *str
)
287 len
= MIN(108, strlen(str
));
288 p
= strchr(str
, ',');
290 len
= MIN(len
, p
- str
);
292 memset(uaddr
, 0, sizeof(*uaddr
));
294 uaddr
->sun_family
= AF_UNIX
;
295 memcpy(uaddr
->sun_path
, str
, len
);
301 void qemu_format_nic_info_str(VLANClientState
*vc
, uint8_t macaddr
[6])
303 snprintf(vc
->info_str
, sizeof(vc
->info_str
),
304 "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
306 macaddr
[0], macaddr
[1], macaddr
[2],
307 macaddr
[3], macaddr
[4], macaddr
[5]);
310 static char *assign_name(VLANClientState
*vc1
, const char *model
)
316 for (vlan
= first_vlan
; vlan
; vlan
= vlan
->next
) {
319 for (vc
= vlan
->first_client
; vc
; vc
= vc
->next
)
320 if (vc
!= vc1
&& strcmp(vc
->model
, model
) == 0)
324 snprintf(buf
, sizeof(buf
), "%s.%d", model
, id
);
329 VLANClientState
*qemu_new_vlan_client(VLANState
*vlan
,
332 IOReadHandler
*fd_read
,
333 IOCanRWHandler
*fd_can_read
,
336 VLANClientState
*vc
, **pvc
;
337 vc
= qemu_mallocz(sizeof(VLANClientState
));
340 vc
->model
= strdup(model
);
342 vc
->name
= strdup(name
);
344 vc
->name
= assign_name(vc
, model
);
345 vc
->fd_read
= fd_read
;
346 vc
->fd_can_read
= fd_can_read
;
351 pvc
= &vlan
->first_client
;
358 void qemu_del_vlan_client(VLANClientState
*vc
)
360 VLANClientState
**pvc
= &vc
->vlan
->first_client
;
373 int qemu_can_send_packet(VLANClientState
*vc1
)
375 VLANState
*vlan
= vc1
->vlan
;
378 for(vc
= vlan
->first_client
; vc
!= NULL
; vc
= vc
->next
) {
380 if (vc
->fd_can_read
&& vc
->fd_can_read(vc
->opaque
))
387 int qemu_send_packet(VLANClientState
*vc1
, const uint8_t *buf
, int size
)
389 VLANState
*vlan
= vc1
->vlan
;
397 printf("vlan %d send:\n", vlan
->id
);
398 hex_dump(stdout
, buf
, size
);
400 for(vc
= vlan
->first_client
; vc
!= NULL
; vc
= vc
->next
) {
401 if (vc
!= vc1
&& !vc
->link_down
) {
402 if (!vc
->fd_can_read
|| vc
->fd_can_read(vc
->opaque
)) {
403 vc
->fd_read(vc
->opaque
, buf
, size
);
411 static ssize_t
vc_sendv_compat(VLANClientState
*vc
, const struct iovec
*iov
,
414 uint8_t buffer
[4096];
418 for (i
= 0; i
< iovcnt
; i
++) {
421 len
= MIN(sizeof(buffer
) - offset
, iov
[i
].iov_len
);
422 memcpy(buffer
+ offset
, iov
[i
].iov_base
, len
);
426 vc
->fd_read(vc
->opaque
, buffer
, offset
);
431 ssize_t
qemu_sendv_packet(VLANClientState
*vc1
, const struct iovec
*iov
,
434 VLANState
*vlan
= vc1
->vlan
;
438 for (vc
= vlan
->first_client
; vc
!= NULL
; vc
= vc
->next
) {
445 len
= vc
->fd_readv(vc
->opaque
, iov
, iovcnt
);
446 else if (vc
->fd_read
)
447 len
= vc_sendv_compat(vc
, iov
, iovcnt
);
449 max_len
= MAX(max_len
, len
);
455 #if defined(CONFIG_SLIRP)
457 /* slirp network adapter */
459 static int slirp_inited
;
460 static int slirp_restrict
;
461 static char *slirp_ip
;
462 static VLANClientState
*slirp_vc
;
464 int slirp_can_output(void)
466 return !slirp_vc
|| qemu_can_send_packet(slirp_vc
);
469 void slirp_output(const uint8_t *pkt
, int pkt_len
)
472 printf("slirp output:\n");
473 hex_dump(stdout
, pkt
, pkt_len
);
477 qemu_send_packet(slirp_vc
, pkt
, pkt_len
);
480 int slirp_is_inited(void)
485 static void slirp_receive(void *opaque
, const uint8_t *buf
, int size
)
488 printf("slirp input:\n");
489 hex_dump(stdout
, buf
, size
);
491 slirp_input(buf
, size
);
494 static int net_slirp_init(VLANState
*vlan
, const char *model
, const char *name
)
498 slirp_init(slirp_restrict
, slirp_ip
);
500 slirp_vc
= qemu_new_vlan_client(vlan
, model
, name
,
501 slirp_receive
, NULL
, NULL
);
502 slirp_vc
->info_str
[0] = '\0';
506 void net_slirp_redir(const char *redir_str
)
511 struct in_addr guest_addr
;
512 int host_port
, guest_port
;
516 slirp_init(slirp_restrict
, slirp_ip
);
520 if (get_str_sep(buf
, sizeof(buf
), &p
, ':') < 0)
522 if (!strcmp(buf
, "tcp")) {
524 } else if (!strcmp(buf
, "udp")) {
530 if (get_str_sep(buf
, sizeof(buf
), &p
, ':') < 0)
532 host_port
= strtol(buf
, &r
, 0);
536 if (get_str_sep(buf
, sizeof(buf
), &p
, ':') < 0)
538 if (buf
[0] == '\0') {
539 pstrcpy(buf
, sizeof(buf
), "10.0.2.15");
541 if (!inet_aton(buf
, &guest_addr
))
544 guest_port
= strtol(p
, &r
, 0);
548 if (slirp_redir(is_udp
, host_port
, guest_addr
, guest_port
) < 0) {
549 fprintf(stderr
, "qemu: could not set up redirection\n");
554 fprintf(stderr
, "qemu: syntax: -redir [tcp|udp]:host-port:[guest-host]:guest-port\n");
560 static char smb_dir
[1024];
562 static void erase_dir(char *dir_name
)
568 /* erase all the files in the directory */
569 if ((d
= opendir(dir_name
)) != 0) {
574 if (strcmp(de
->d_name
, ".") != 0 &&
575 strcmp(de
->d_name
, "..") != 0) {
576 snprintf(filename
, sizeof(filename
), "%s/%s",
577 smb_dir
, de
->d_name
);
578 if (unlink(filename
) != 0) /* is it a directory? */
587 /* automatic user mode samba server configuration */
588 static void smb_exit(void)
593 /* automatic user mode samba server configuration */
594 void net_slirp_smb(const char *exported_dir
)
597 char smb_cmdline
[1024];
602 slirp_init(slirp_restrict
, slirp_ip
);
605 /* XXX: better tmp dir construction */
606 snprintf(smb_dir
, sizeof(smb_dir
), "/tmp/qemu-smb.%d", getpid());
607 if (mkdir(smb_dir
, 0700) < 0) {
608 fprintf(stderr
, "qemu: could not create samba server dir '%s'\n", smb_dir
);
611 snprintf(smb_conf
, sizeof(smb_conf
), "%s/%s", smb_dir
, "smb.conf");
613 f
= fopen(smb_conf
, "w");
615 fprintf(stderr
, "qemu: could not create samba server configuration file '%s'\n", smb_conf
);
622 "socket address=127.0.0.1\n"
624 "lock directory=%s\n"
625 "log file=%s/log.smbd\n"
626 "smb passwd file=%s/smbpasswd\n"
642 snprintf(smb_cmdline
, sizeof(smb_cmdline
), "%s -s %s",
643 SMBD_COMMAND
, smb_conf
);
645 slirp_add_exec(0, smb_cmdline
, 4, 139);
648 #endif /* !defined(_WIN32) */
649 void do_info_slirp(void)
654 #endif /* CONFIG_SLIRP */
658 int tap_has_vnet_hdr(void *opaque
)
663 void tap_using_vnet_hdr(void *opaque
, int using_vnet_hdr
)
667 #else /* !defined(_WIN32) */
669 /* Maximum GSO packet size (64k) plus plenty of room for
670 * the ethernet and virtio_net headers
672 #define TAP_BUFSIZE (4096 + 65536)
675 #include <linux/virtio_net.h>
678 typedef struct TAPState
{
681 char down_script
[1024];
682 char down_script_arg
[128];
683 char buf
[TAP_BUFSIZE
];
685 unsigned int has_vnet_hdr
: 1;
686 unsigned int using_vnet_hdr
: 1;
690 static ssize_t
tap_receive_iov(void *opaque
, const struct iovec
*iov
,
693 TAPState
*s
= opaque
;
697 len
= writev(s
->fd
, iov
, iovcnt
);
698 } while (len
== -1 && (errno
== EINTR
|| errno
== EAGAIN
));
704 static void tap_receive(void *opaque
, const uint8_t *buf
, int size
)
710 TAPState
*s
= opaque
;
711 struct virtio_net_hdr hdr
= { 0, };
713 if (s
->has_vnet_hdr
&& !s
->using_vnet_hdr
) {
714 iov
[i
].iov_base
= &hdr
;
715 iov
[i
].iov_len
= sizeof(hdr
);
720 iov
[i
].iov_base
= (char *) buf
;
721 iov
[i
].iov_len
= size
;
724 tap_receive_iov(opaque
, iov
, i
);
727 static int tap_can_send(void *opaque
)
729 TAPState
*s
= opaque
;
733 /* Check to see if any of our clients can receive a packet */
734 for (vc
= s
->vc
->vlan
->first_client
; vc
; vc
= vc
->next
) {
739 if (!vc
->fd_can_read
) {
740 /* no fd_can_read handler, they always can receive */
743 can_receive
= vc
->fd_can_read(vc
->opaque
);
745 /* Once someone can receive, we try to send a packet */
753 static int tap_send_packet(TAPState
*s
)
755 uint8_t *buf
= s
->buf
;
759 if (s
->has_vnet_hdr
&& !s
->using_vnet_hdr
) {
760 buf
+= sizeof(struct virtio_net_hdr
);
761 size
-= sizeof(struct virtio_net_hdr
);
765 return qemu_send_packet(s
->vc
, buf
, size
);
768 static void tap_send(void *opaque
)
770 TAPState
*s
= opaque
;
772 /* First try to send any buffered packet */
776 /* If noone can receive the packet, buffer it */
777 err
= tap_send_packet(s
);
782 /* Read packets until we hit EAGAIN */
787 sbuf
.maxlen
= sizeof(s
->buf
);
789 s
->size
= getmsg(s
->fd
, NULL
, &sbuf
, &f
) >=0 ? sbuf
.len
: -1;
791 // FIXME: kvm_sleep_begin();
792 s
->size
= read(s
->fd
, s
->buf
, sizeof(s
->buf
));
793 // FIXME: kvm_sleep_end();
796 if (s
->size
== -1 && errno
== EINTR
)
802 /* If noone can receive the packet, buffer it */
803 err
= tap_send_packet(s
);
807 } while (s
->size
> 0);
810 int tap_has_vnet_hdr(void *opaque
)
812 VLANClientState
*vc
= opaque
;
813 TAPState
*s
= vc
->opaque
;
815 return s
? s
->has_vnet_hdr
: 0;
818 void tap_using_vnet_hdr(void *opaque
, int using_vnet_hdr
)
820 VLANClientState
*vc
= opaque
;
821 TAPState
*s
= vc
->opaque
;
823 if (!s
|| !s
->has_vnet_hdr
)
826 s
->using_vnet_hdr
= using_vnet_hdr
!= 0;
829 static int tap_probe_vnet_hdr(int fd
)
831 #if defined(TUNGETIFF) && defined(IFF_VNET_HDR)
834 if (ioctl(fd
, TUNGETIFF
, &ifr
) != 0) {
835 fprintf(stderr
, "TUNGETIFF ioctl() failed: %s\n", strerror(errno
));
839 return ifr
.ifr_flags
& IFF_VNET_HDR
;
846 static void tap_set_offload(VLANClientState
*vc
, int csum
, int tso4
, int tso6
,
849 TAPState
*s
= vc
->opaque
;
850 unsigned int offload
= 0;
853 offload
|= TUN_F_CSUM
;
855 offload
|= TUN_F_TSO4
;
857 offload
|= TUN_F_TSO6
;
858 if ((tso4
|| tso6
) && ecn
)
859 offload
|= TUN_F_TSO_ECN
;
862 if (ioctl(s
->fd
, TUNSETOFFLOAD
, offload
) != 0)
863 fprintf(stderr
, "TUNSETOFFLOAD ioctl() failed: %s\n",
866 #endif /* TUNSETOFFLOAD */
870 static TAPState
*net_tap_fd_init(VLANState
*vlan
,
878 s
= qemu_mallocz(sizeof(TAPState
));
882 s
->has_vnet_hdr
= vnet_hdr
!= 0;
883 s
->vc
= qemu_new_vlan_client(vlan
, model
, name
, tap_receive
, NULL
, s
);
885 s
->vc
->fd_readv
= tap_receive_iov
;
888 s
->vc
->set_offload
= tap_set_offload
;
890 qemu_set_fd_handler2(s
->fd
, tap_can_send
, tap_send
, NULL
, s
);
891 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
), "fd=%d", fd
);
895 #if defined (_BSD) || defined (__FreeBSD_kernel__)
896 static int tap_open(char *ifname
, int ifname_size
)
902 TFR(fd
= open("/dev/tap", O_RDWR
));
904 fprintf(stderr
, "warning: could not open /dev/tap: no virtual network emulation\n");
909 dev
= devname(s
.st_rdev
, S_IFCHR
);
910 pstrcpy(ifname
, ifname_size
, dev
);
912 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
915 #elif defined(__sun__)
916 #define TUNNEWPPA (('T'<<16) | 0x0001)
918 * Allocate TAP device, returns opened fd.
919 * Stores dev name in the first arg(must be large enough).
921 int tap_alloc(char *dev
, size_t dev_size
)
923 int tap_fd
, if_fd
, ppa
= -1;
924 static int ip_fd
= 0;
927 static int arp_fd
= 0;
928 int ip_muxid
, arp_muxid
;
929 struct strioctl strioc_if
, strioc_ppa
;
930 int link_type
= I_PLINK
;;
932 char actual_name
[32] = "";
934 memset(&ifr
, 0x0, sizeof(ifr
));
938 while( *ptr
&& !qemu_isdigit((int)*ptr
) ) ptr
++;
942 /* Check if IP device was opened */
946 TFR(ip_fd
= open("/dev/udp", O_RDWR
, 0));
948 syslog(LOG_ERR
, "Can't open /dev/ip (actually /dev/udp)");
952 TFR(tap_fd
= open("/dev/tap", O_RDWR
, 0));
954 syslog(LOG_ERR
, "Can't open /dev/tap");
958 /* Assign a new PPA and get its unit number. */
959 strioc_ppa
.ic_cmd
= TUNNEWPPA
;
960 strioc_ppa
.ic_timout
= 0;
961 strioc_ppa
.ic_len
= sizeof(ppa
);
962 strioc_ppa
.ic_dp
= (char *)&ppa
;
963 if ((ppa
= ioctl (tap_fd
, I_STR
, &strioc_ppa
)) < 0)
964 syslog (LOG_ERR
, "Can't assign new interface");
966 TFR(if_fd
= open("/dev/tap", O_RDWR
, 0));
968 syslog(LOG_ERR
, "Can't open /dev/tap (2)");
971 if(ioctl(if_fd
, I_PUSH
, "ip") < 0){
972 syslog(LOG_ERR
, "Can't push IP module");
976 if (ioctl(if_fd
, SIOCGLIFFLAGS
, &ifr
) < 0)
977 syslog(LOG_ERR
, "Can't get flags\n");
979 snprintf (actual_name
, 32, "tap%d", ppa
);
980 pstrcpy(ifr
.lifr_name
, sizeof(ifr
.lifr_name
), actual_name
);
983 /* Assign ppa according to the unit number returned by tun device */
985 if (ioctl (if_fd
, SIOCSLIFNAME
, &ifr
) < 0)
986 syslog (LOG_ERR
, "Can't set PPA %d", ppa
);
987 if (ioctl(if_fd
, SIOCGLIFFLAGS
, &ifr
) <0)
988 syslog (LOG_ERR
, "Can't get flags\n");
989 /* Push arp module to if_fd */
990 if (ioctl (if_fd
, I_PUSH
, "arp") < 0)
991 syslog (LOG_ERR
, "Can't push ARP module (2)");
993 /* Push arp module to ip_fd */
994 if (ioctl (ip_fd
, I_POP
, NULL
) < 0)
995 syslog (LOG_ERR
, "I_POP failed\n");
996 if (ioctl (ip_fd
, I_PUSH
, "arp") < 0)
997 syslog (LOG_ERR
, "Can't push ARP module (3)\n");
999 TFR(arp_fd
= open ("/dev/tap", O_RDWR
, 0));
1001 syslog (LOG_ERR
, "Can't open %s\n", "/dev/tap");
1003 /* Set ifname to arp */
1004 strioc_if
.ic_cmd
= SIOCSLIFNAME
;
1005 strioc_if
.ic_timout
= 0;
1006 strioc_if
.ic_len
= sizeof(ifr
);
1007 strioc_if
.ic_dp
= (char *)&ifr
;
1008 if (ioctl(arp_fd
, I_STR
, &strioc_if
) < 0){
1009 syslog (LOG_ERR
, "Can't set ifname to arp\n");
1012 if((ip_muxid
= ioctl(ip_fd
, I_LINK
, if_fd
)) < 0){
1013 syslog(LOG_ERR
, "Can't link TAP device to IP");
1017 if ((arp_muxid
= ioctl (ip_fd
, link_type
, arp_fd
)) < 0)
1018 syslog (LOG_ERR
, "Can't link TAP device to ARP");
1022 memset(&ifr
, 0x0, sizeof(ifr
));
1023 pstrcpy(ifr
.lifr_name
, sizeof(ifr
.lifr_name
), actual_name
);
1024 ifr
.lifr_ip_muxid
= ip_muxid
;
1025 ifr
.lifr_arp_muxid
= arp_muxid
;
1027 if (ioctl (ip_fd
, SIOCSLIFMUXID
, &ifr
) < 0)
1029 ioctl (ip_fd
, I_PUNLINK
, arp_muxid
);
1030 ioctl (ip_fd
, I_PUNLINK
, ip_muxid
);
1031 syslog (LOG_ERR
, "Can't set multiplexor id");
1034 snprintf(dev
, dev_size
, "tap%d", ppa
);
1038 static int tap_open(char *ifname
, int ifname_size
, int *vnet_hdr
)
1042 if( (fd
= tap_alloc(dev
, sizeof(dev
))) < 0 ){
1043 fprintf(stderr
, "Cannot allocate TAP device\n");
1046 pstrcpy(ifname
, ifname_size
, dev
);
1047 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
1050 #elif defined (_AIX)
1051 static int tap_open(char *ifname
, int ifname_size
)
1053 fprintf (stderr
, "no tap on AIX\n");
1057 static int tap_open(char *ifname
, int ifname_size
, int *vnet_hdr
)
1062 TFR(fd
= open("/dev/net/tun", O_RDWR
));
1064 fprintf(stderr
, "warning: could not open /dev/net/tun: no virtual network emulation\n");
1067 memset(&ifr
, 0, sizeof(ifr
));
1068 ifr
.ifr_flags
= IFF_TAP
| IFF_NO_PI
;
1070 #if defined(TUNGETFEATURES) && defined(IFF_VNET_HDR)
1072 unsigned int features
;
1074 if (ioctl(fd
, TUNGETFEATURES
, &features
) == 0 &&
1075 features
& IFF_VNET_HDR
) {
1077 ifr
.ifr_flags
|= IFF_VNET_HDR
;
1082 if (ifname
[0] != '\0')
1083 pstrcpy(ifr
.ifr_name
, IFNAMSIZ
, ifname
);
1085 pstrcpy(ifr
.ifr_name
, IFNAMSIZ
, "tap%d");
1086 ret
= ioctl(fd
, TUNSETIFF
, (void *) &ifr
);
1088 fprintf(stderr
, "warning: could not configure /dev/net/tun: no virtual network emulation\n");
1092 pstrcpy(ifname
, ifname_size
, ifr
.ifr_name
);
1093 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
1098 static int launch_script(const char *setup_script
, const char *ifname
, int fd
)
1104 /* try to launch network script */
1108 int open_max
= sysconf (_SC_OPEN_MAX
), i
;
1109 for (i
= 0; i
< open_max
; i
++)
1110 if (i
!= STDIN_FILENO
&&
1111 i
!= STDOUT_FILENO
&&
1112 i
!= STDERR_FILENO
&&
1117 *parg
++ = (char *)setup_script
;
1118 *parg
++ = (char *)ifname
;
1120 execv(setup_script
, args
);
1123 while (waitpid(pid
, &status
, 0) != pid
);
1124 if (!WIFEXITED(status
) ||
1125 WEXITSTATUS(status
) != 0) {
1126 fprintf(stderr
, "%s: could not launch network script\n",
1134 static int net_tap_init(VLANState
*vlan
, const char *model
,
1135 const char *name
, const char *ifname1
,
1136 const char *setup_script
, const char *down_script
)
1143 if (ifname1
!= NULL
)
1144 pstrcpy(ifname
, sizeof(ifname
), ifname1
);
1148 TFR(fd
= tap_open(ifname
, sizeof(ifname
), &vnet_hdr
));
1152 if (!setup_script
|| !strcmp(setup_script
, "no"))
1154 if (setup_script
[0] != '\0') {
1155 if (launch_script(setup_script
, ifname
, fd
))
1158 s
= net_tap_fd_init(vlan
, model
, name
, fd
, vnet_hdr
);
1162 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
),
1163 "ifname=%s,script=%s,downscript=%s",
1164 ifname
, setup_script
, down_script
);
1165 if (down_script
&& strcmp(down_script
, "no")) {
1166 snprintf(s
->down_script
, sizeof(s
->down_script
), "%s", down_script
);
1167 snprintf(s
->down_script_arg
, sizeof(s
->down_script_arg
), "%s", ifname
);
1172 #endif /* !_WIN32 */
1174 #if defined(CONFIG_VDE)
1175 typedef struct VDEState
{
1176 VLANClientState
*vc
;
1180 static void vde_to_qemu(void *opaque
)
1182 VDEState
*s
= opaque
;
1186 size
= vde_recv(s
->vde
, buf
, sizeof(buf
), 0);
1188 qemu_send_packet(s
->vc
, buf
, size
);
1192 static void vde_from_qemu(void *opaque
, const uint8_t *buf
, int size
)
1194 VDEState
*s
= opaque
;
1197 ret
= vde_send(s
->vde
, buf
, size
, 0);
1198 if (ret
< 0 && errno
== EINTR
) {
1205 static int net_vde_init(VLANState
*vlan
, const char *model
,
1206 const char *name
, const char *sock
,
1207 int port
, const char *group
, int mode
)
1210 char *init_group
= strlen(group
) ? (char *)group
: NULL
;
1211 char *init_sock
= strlen(sock
) ? (char *)sock
: NULL
;
1213 struct vde_open_args args
= {
1215 .group
= init_group
,
1219 s
= qemu_mallocz(sizeof(VDEState
));
1222 s
->vde
= vde_open(init_sock
, "QEMU", &args
);
1227 s
->vc
= qemu_new_vlan_client(vlan
, model
, name
, vde_from_qemu
, NULL
, s
);
1228 qemu_set_fd_handler(vde_datafd(s
->vde
), vde_to_qemu
, NULL
, s
);
1229 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
), "sock=%s,fd=%d",
1230 sock
, vde_datafd(s
->vde
));
1235 /* network connection */
1236 typedef struct NetSocketState
{
1237 VLANClientState
*vc
;
1239 int state
; /* 0 = getting length, 1 = getting data */
1243 struct sockaddr_in dgram_dst
; /* contains inet host and port destination iff connectionless (SOCK_DGRAM) */
1246 typedef struct NetSocketListenState
{
1251 } NetSocketListenState
;
1253 /* XXX: we consider we can send the whole packet without blocking */
1254 static void net_socket_receive(void *opaque
, const uint8_t *buf
, int size
)
1256 NetSocketState
*s
= opaque
;
1260 send_all(s
->fd
, (const uint8_t *)&len
, sizeof(len
));
1261 send_all(s
->fd
, buf
, size
);
1264 static void net_socket_receive_dgram(void *opaque
, const uint8_t *buf
, int size
)
1266 NetSocketState
*s
= opaque
;
1267 sendto(s
->fd
, buf
, size
, 0,
1268 (struct sockaddr
*)&s
->dgram_dst
, sizeof(s
->dgram_dst
));
1271 static void net_socket_send(void *opaque
)
1273 NetSocketState
*s
= opaque
;
1278 size
= recv(s
->fd
, buf1
, sizeof(buf1
), 0);
1280 err
= socket_error();
1281 if (err
!= EWOULDBLOCK
)
1283 } else if (size
== 0) {
1284 /* end of connection */
1286 qemu_set_fd_handler(s
->fd
, NULL
, NULL
, NULL
);
1292 /* reassemble a packet from the network */
1298 memcpy(s
->buf
+ s
->index
, buf
, l
);
1302 if (s
->index
== 4) {
1304 s
->packet_len
= ntohl(*(uint32_t *)s
->buf
);
1310 l
= s
->packet_len
- s
->index
;
1313 memcpy(s
->buf
+ s
->index
, buf
, l
);
1317 if (s
->index
>= s
->packet_len
) {
1318 qemu_send_packet(s
->vc
, s
->buf
, s
->packet_len
);
1327 static void net_socket_send_dgram(void *opaque
)
1329 NetSocketState
*s
= opaque
;
1332 size
= recv(s
->fd
, s
->buf
, sizeof(s
->buf
), 0);
1336 /* end of connection */
1337 qemu_set_fd_handler(s
->fd
, NULL
, NULL
, NULL
);
1340 qemu_send_packet(s
->vc
, s
->buf
, size
);
1343 static int net_socket_mcast_create(struct sockaddr_in
*mcastaddr
)
1348 if (!IN_MULTICAST(ntohl(mcastaddr
->sin_addr
.s_addr
))) {
1349 fprintf(stderr
, "qemu: error: specified mcastaddr \"%s\" (0x%08x) does not contain a multicast address\n",
1350 inet_ntoa(mcastaddr
->sin_addr
),
1351 (int)ntohl(mcastaddr
->sin_addr
.s_addr
));
1355 fd
= socket(PF_INET
, SOCK_DGRAM
, 0);
1357 perror("socket(PF_INET, SOCK_DGRAM)");
1362 ret
=setsockopt(fd
, SOL_SOCKET
, SO_REUSEADDR
,
1363 (const char *)&val
, sizeof(val
));
1365 perror("setsockopt(SOL_SOCKET, SO_REUSEADDR)");
1369 ret
= bind(fd
, (struct sockaddr
*)mcastaddr
, sizeof(*mcastaddr
));
1375 /* Add host to multicast group */
1376 imr
.imr_multiaddr
= mcastaddr
->sin_addr
;
1377 imr
.imr_interface
.s_addr
= htonl(INADDR_ANY
);
1379 ret
= setsockopt(fd
, IPPROTO_IP
, IP_ADD_MEMBERSHIP
,
1380 (const char *)&imr
, sizeof(struct ip_mreq
));
1382 perror("setsockopt(IP_ADD_MEMBERSHIP)");
1386 /* Force mcast msgs to loopback (eg. several QEMUs in same host */
1388 ret
=setsockopt(fd
, IPPROTO_IP
, IP_MULTICAST_LOOP
,
1389 (const char *)&val
, sizeof(val
));
1391 perror("setsockopt(SOL_IP, IP_MULTICAST_LOOP)");
1395 socket_set_nonblock(fd
);
1403 static NetSocketState
*net_socket_fd_init_dgram(VLANState
*vlan
,
1406 int fd
, int is_connected
)
1408 struct sockaddr_in saddr
;
1410 socklen_t saddr_len
;
1413 /* fd passed: multicast: "learn" dgram_dst address from bound address and save it
1414 * Because this may be "shared" socket from a "master" process, datagrams would be recv()
1415 * by ONLY ONE process: we must "clone" this dgram socket --jjo
1419 if (getsockname(fd
, (struct sockaddr
*) &saddr
, &saddr_len
) == 0) {
1421 if (saddr
.sin_addr
.s_addr
==0) {
1422 fprintf(stderr
, "qemu: error: init_dgram: fd=%d unbound, cannot setup multicast dst addr\n",
1426 /* clone dgram socket */
1427 newfd
= net_socket_mcast_create(&saddr
);
1429 /* error already reported by net_socket_mcast_create() */
1433 /* clone newfd to fd, close newfd */
1438 fprintf(stderr
, "qemu: error: init_dgram: fd=%d failed getsockname(): %s\n",
1439 fd
, strerror(errno
));
1444 s
= qemu_mallocz(sizeof(NetSocketState
));
1449 s
->vc
= qemu_new_vlan_client(vlan
, model
, name
, net_socket_receive_dgram
, NULL
, s
);
1450 qemu_set_fd_handler(s
->fd
, net_socket_send_dgram
, NULL
, s
);
1452 /* mcast: save bound address as dst */
1453 if (is_connected
) s
->dgram_dst
=saddr
;
1455 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
),
1456 "socket: fd=%d (%s mcast=%s:%d)",
1457 fd
, is_connected
? "cloned" : "",
1458 inet_ntoa(saddr
.sin_addr
), ntohs(saddr
.sin_port
));
1462 static void net_socket_connect(void *opaque
)
1464 NetSocketState
*s
= opaque
;
1465 qemu_set_fd_handler(s
->fd
, net_socket_send
, NULL
, s
);
1468 static NetSocketState
*net_socket_fd_init_stream(VLANState
*vlan
,
1471 int fd
, int is_connected
)
1474 s
= qemu_mallocz(sizeof(NetSocketState
));
1478 s
->vc
= qemu_new_vlan_client(vlan
, model
, name
,
1479 net_socket_receive
, NULL
, s
);
1480 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
),
1481 "socket: fd=%d", fd
);
1483 net_socket_connect(s
);
1485 qemu_set_fd_handler(s
->fd
, NULL
, net_socket_connect
, s
);
1490 static NetSocketState
*net_socket_fd_init(VLANState
*vlan
,
1491 const char *model
, const char *name
,
1492 int fd
, int is_connected
)
1494 int so_type
=-1, optlen
=sizeof(so_type
);
1496 if(getsockopt(fd
, SOL_SOCKET
, SO_TYPE
, (char *)&so_type
,
1497 (socklen_t
*)&optlen
)< 0) {
1498 fprintf(stderr
, "qemu: error: getsockopt(SO_TYPE) for fd=%d failed\n", fd
);
1503 return net_socket_fd_init_dgram(vlan
, model
, name
, fd
, is_connected
);
1505 return net_socket_fd_init_stream(vlan
, model
, name
, fd
, is_connected
);
1507 /* who knows ... this could be a eg. a pty, do warn and continue as stream */
1508 fprintf(stderr
, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type
, fd
);
1509 return net_socket_fd_init_stream(vlan
, model
, name
, fd
, is_connected
);
1514 static void net_socket_accept(void *opaque
)
1516 NetSocketListenState
*s
= opaque
;
1518 struct sockaddr_in saddr
;
1523 len
= sizeof(saddr
);
1524 fd
= accept(s
->fd
, (struct sockaddr
*)&saddr
, &len
);
1525 if (fd
< 0 && errno
!= EINTR
) {
1527 } else if (fd
>= 0) {
1531 s1
= net_socket_fd_init(s
->vlan
, s
->model
, s
->name
, fd
, 1);
1535 snprintf(s1
->vc
->info_str
, sizeof(s1
->vc
->info_str
),
1536 "socket: connection from %s:%d",
1537 inet_ntoa(saddr
.sin_addr
), ntohs(saddr
.sin_port
));
1541 static int net_socket_listen_init(VLANState
*vlan
,
1544 const char *host_str
)
1546 NetSocketListenState
*s
;
1548 struct sockaddr_in saddr
;
1550 if (parse_host_port(&saddr
, host_str
) < 0)
1553 s
= qemu_mallocz(sizeof(NetSocketListenState
));
1557 fd
= socket(PF_INET
, SOCK_STREAM
, 0);
1562 socket_set_nonblock(fd
);
1564 /* allow fast reuse */
1566 setsockopt(fd
, SOL_SOCKET
, SO_REUSEADDR
, (const char *)&val
, sizeof(val
));
1568 ret
= bind(fd
, (struct sockaddr
*)&saddr
, sizeof(saddr
));
1573 ret
= listen(fd
, 0);
1579 s
->model
= strdup(model
);
1580 s
->name
= strdup(name
);
1582 qemu_set_fd_handler(fd
, net_socket_accept
, NULL
, s
);
1586 static int net_socket_connect_init(VLANState
*vlan
,
1589 const char *host_str
)
1592 int fd
, connected
, ret
, err
;
1593 struct sockaddr_in saddr
;
1595 if (parse_host_port(&saddr
, host_str
) < 0)
1598 fd
= socket(PF_INET
, SOCK_STREAM
, 0);
1603 socket_set_nonblock(fd
);
1607 ret
= connect(fd
, (struct sockaddr
*)&saddr
, sizeof(saddr
));
1609 err
= socket_error();
1610 if (err
== EINTR
|| err
== EWOULDBLOCK
) {
1611 } else if (err
== EINPROGRESS
) {
1614 } else if (err
== WSAEALREADY
) {
1627 s
= net_socket_fd_init(vlan
, model
, name
, fd
, connected
);
1630 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
),
1631 "socket: connect to %s:%d",
1632 inet_ntoa(saddr
.sin_addr
), ntohs(saddr
.sin_port
));
1636 static int net_socket_mcast_init(VLANState
*vlan
,
1639 const char *host_str
)
1643 struct sockaddr_in saddr
;
1645 if (parse_host_port(&saddr
, host_str
) < 0)
1649 fd
= net_socket_mcast_create(&saddr
);
1653 s
= net_socket_fd_init(vlan
, model
, name
, fd
, 0);
1657 s
->dgram_dst
= saddr
;
1659 snprintf(s
->vc
->info_str
, sizeof(s
->vc
->info_str
),
1660 "socket: mcast=%s:%d",
1661 inet_ntoa(saddr
.sin_addr
), ntohs(saddr
.sin_port
));
1666 /* find or alloc a new VLAN */
1667 VLANState
*qemu_find_vlan(int id
)
1669 VLANState
**pvlan
, *vlan
;
1670 for(vlan
= first_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
1674 vlan
= qemu_mallocz(sizeof(VLANState
));
1679 pvlan
= &first_vlan
;
1680 while (*pvlan
!= NULL
)
1681 pvlan
= &(*pvlan
)->next
;
1686 void qemu_check_nic_model(NICInfo
*nd
, const char *model
)
1688 const char *models
[2];
1693 qemu_check_nic_model_list(nd
, models
, model
);
1696 void qemu_check_nic_model_list(NICInfo
*nd
, const char * const *models
,
1697 const char *default_model
)
1699 int i
, exit_status
= 0;
1702 nd
->model
= strdup(default_model
);
1704 if (strcmp(nd
->model
, "?") != 0) {
1705 for (i
= 0 ; models
[i
]; i
++)
1706 if (strcmp(nd
->model
, models
[i
]) == 0)
1709 fprintf(stderr
, "qemu: Unsupported NIC model: %s\n", nd
->model
);
1713 fprintf(stderr
, "qemu: Supported NIC models: ");
1714 for (i
= 0 ; models
[i
]; i
++)
1715 fprintf(stderr
, "%s%c", models
[i
], models
[i
+1] ? ',' : '\n');
1720 int net_client_init(const char *device
, const char *p
)
1728 if (get_param_value(buf
, sizeof(buf
), "vlan", p
)) {
1729 vlan_id
= strtol(buf
, NULL
, 0);
1731 vlan
= qemu_find_vlan(vlan_id
);
1733 fprintf(stderr
, "Could not create vlan %d\n", vlan_id
);
1736 if (get_param_value(buf
, sizeof(buf
), "name", p
)) {
1739 if (!strcmp(device
, "nic")) {
1743 if (nb_nics
>= MAX_NICS
) {
1744 fprintf(stderr
, "Too Many NICs\n");
1747 nd
= &nd_table
[nb_nics
];
1748 macaddr
= nd
->macaddr
;
1754 macaddr
[5] = 0x56 + nb_nics
;
1756 if (get_param_value(buf
, sizeof(buf
), "macaddr", p
)) {
1757 if (parse_macaddr(macaddr
, buf
) < 0) {
1758 fprintf(stderr
, "invalid syntax for ethernet address\n");
1762 if (get_param_value(buf
, sizeof(buf
), "model", p
)) {
1763 nd
->model
= strdup(buf
);
1769 vlan
->nb_guest_devs
++;
1772 if (!strcmp(device
, "none")) {
1773 /* does nothing. It is needed to signal that no network cards
1778 if (!strcmp(device
, "user")) {
1779 if (get_param_value(buf
, sizeof(buf
), "hostname", p
)) {
1780 pstrcpy(slirp_hostname
, sizeof(slirp_hostname
), buf
);
1782 if (get_param_value(buf
, sizeof(buf
), "restrict", p
)) {
1783 slirp_restrict
= (buf
[0] == 'y') ? 1 : 0;
1785 if (get_param_value(buf
, sizeof(buf
), "ip", p
)) {
1786 slirp_ip
= strdup(buf
);
1788 vlan
->nb_host_devs
++;
1789 ret
= net_slirp_init(vlan
, device
, name
);
1793 if (!strcmp(device
, "tap")) {
1795 if (get_param_value(ifname
, sizeof(ifname
), "ifname", p
) <= 0) {
1796 fprintf(stderr
, "tap: no interface name\n");
1799 vlan
->nb_host_devs
++;
1800 ret
= tap_win32_init(vlan
, device
, name
, ifname
);
1802 #elif defined (_AIX)
1804 if (!strcmp(device
, "tap")) {
1806 char setup_script
[1024], down_script
[1024];
1808 vlan
->nb_host_devs
++;
1809 if (get_param_value(buf
, sizeof(buf
), "fd", p
) > 0) {
1810 fd
= strtol(buf
, NULL
, 0);
1811 fcntl(fd
, F_SETFL
, O_NONBLOCK
);
1813 if (net_tap_fd_init(vlan
, device
, name
, fd
,
1814 tap_probe_vnet_hdr(fd
)))
1817 if (get_param_value(ifname
, sizeof(ifname
), "ifname", p
) <= 0) {
1820 if (get_param_value(setup_script
, sizeof(setup_script
), "script", p
) == 0) {
1821 pstrcpy(setup_script
, sizeof(setup_script
), DEFAULT_NETWORK_SCRIPT
);
1823 if (get_param_value(down_script
, sizeof(down_script
), "downscript", p
) == 0) {
1824 pstrcpy(down_script
, sizeof(down_script
), DEFAULT_NETWORK_DOWN_SCRIPT
);
1826 ret
= net_tap_init(vlan
, device
, name
, ifname
, setup_script
, down_script
);
1830 if (!strcmp(device
, "socket")) {
1831 if (get_param_value(buf
, sizeof(buf
), "fd", p
) > 0) {
1833 fd
= strtol(buf
, NULL
, 0);
1835 if (net_socket_fd_init(vlan
, device
, name
, fd
, 1))
1837 } else if (get_param_value(buf
, sizeof(buf
), "listen", p
) > 0) {
1838 ret
= net_socket_listen_init(vlan
, device
, name
, buf
);
1839 } else if (get_param_value(buf
, sizeof(buf
), "connect", p
) > 0) {
1840 ret
= net_socket_connect_init(vlan
, device
, name
, buf
);
1841 } else if (get_param_value(buf
, sizeof(buf
), "mcast", p
) > 0) {
1842 ret
= net_socket_mcast_init(vlan
, device
, name
, buf
);
1844 fprintf(stderr
, "Unknown socket options: %s\n", p
);
1847 vlan
->nb_host_devs
++;
1850 if (!strcmp(device
, "vde")) {
1851 char vde_sock
[1024], vde_group
[512];
1852 int vde_port
, vde_mode
;
1853 vlan
->nb_host_devs
++;
1854 if (get_param_value(vde_sock
, sizeof(vde_sock
), "sock", p
) <= 0) {
1857 if (get_param_value(buf
, sizeof(buf
), "port", p
) > 0) {
1858 vde_port
= strtol(buf
, NULL
, 10);
1862 if (get_param_value(vde_group
, sizeof(vde_group
), "group", p
) <= 0) {
1863 vde_group
[0] = '\0';
1865 if (get_param_value(buf
, sizeof(buf
), "mode", p
) > 0) {
1866 vde_mode
= strtol(buf
, NULL
, 8);
1870 ret
= net_vde_init(vlan
, device
, name
, vde_sock
, vde_port
, vde_group
, vde_mode
);
1874 fprintf(stderr
, "Unknown network device: %s\n", device
);
1880 fprintf(stderr
, "Could not initialize device '%s'\n", device
);
1887 void net_client_uninit(NICInfo
*nd
)
1889 nd
->vlan
->nb_guest_devs
--; /* XXX: free vlan on last reference */
1892 free((void *)nd
->model
);
1895 int net_client_parse(const char *str
)
1903 while (*p
!= '\0' && *p
!= ',') {
1904 if ((q
- device
) < sizeof(device
) - 1)
1912 return net_client_init(device
, p
);
1915 void do_info_network(void)
1918 VLANClientState
*vc
;
1920 for(vlan
= first_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
1921 term_printf("VLAN %d devices:\n", vlan
->id
);
1922 for(vc
= vlan
->first_client
; vc
!= NULL
; vc
= vc
->next
)
1923 term_printf(" %s: %s\n", vc
->name
, vc
->info_str
);
1927 int do_set_link(const char *name
, const char *up_or_down
)
1930 VLANClientState
*vc
= NULL
;
1932 for (vlan
= first_vlan
; vlan
!= NULL
; vlan
= vlan
->next
)
1933 for (vc
= vlan
->first_client
; vc
!= NULL
; vc
= vc
->next
)
1934 if (strcmp(vc
->name
, name
) == 0)
1939 term_printf("could not find network device '%s'", name
);
1943 if (strcmp(up_or_down
, "up") == 0)
1945 else if (strcmp(up_or_down
, "down") == 0)
1948 term_printf("invalid link status '%s'; only 'up' or 'down' valid\n",
1951 if (vc
->link_status_changed
)
1952 vc
->link_status_changed(vc
);
1957 void net_cleanup(void)
1961 #if !defined(_WIN32)
1962 /* close network clients */
1963 for(vlan
= first_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
1964 VLANClientState
*vc
;
1966 for(vc
= vlan
->first_client
; vc
!= NULL
; vc
= vc
->next
) {
1967 if (vc
->fd_read
== tap_receive
) {
1968 TAPState
*s
= vc
->opaque
;
1970 if (s
->down_script
[0])
1971 launch_script(s
->down_script
, s
->down_script_arg
, s
->fd
);
1973 #if defined(CONFIG_VDE)
1974 if (vc
->fd_read
== vde_from_qemu
) {
1975 VDEState
*s
= vc
->opaque
;
1984 void net_client_check(void)
1988 for(vlan
= first_vlan
; vlan
!= NULL
; vlan
= vlan
->next
) {
1989 if (vlan
->nb_guest_devs
== 0 && vlan
->nb_host_devs
== 0)
1991 if (vlan
->nb_guest_devs
== 0)
1992 fprintf(stderr
, "Warning: vlan %d with no nics\n", vlan
->id
);
1993 if (vlan
->nb_host_devs
== 0)
1995 "Warning: vlan %d is not connected to host network\n",