blob: 55c73c592d9c1c08ce8140b6e3dc0c3b10a6eb2f [file] [log] [blame]
aliguori63a01ef2008-10-31 19:10:00 +00001/*
2 * QEMU System Emulator
3 *
4 * Copyright (c) 2003-2008 Fabrice Bellard
5 *
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:
12 *
13 * The above copyright notice and this permission notice shall be included in
14 * all copies or substantial portions of the Software.
15 *
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
22 * THE SOFTWARE.
23 */
Mark McLoughlin1df49e02009-11-25 18:48:58 +000024#include "net.h"
aliguori63a01ef2008-10-31 19:10:00 +000025
blueswir1d40cdb12009-03-07 16:52:02 +000026#include "config-host.h"
27
Mark McLoughlina8ed73f2009-10-22 17:49:05 +010028#include "net/tap.h"
Mark McLoughlin42281ac2009-11-25 18:48:56 +000029#include "net/socket.h"
Mark McLoughlin1abecf72009-11-25 18:48:57 +000030#include "net/dump.h"
Mark McLoughlin68ac40d2009-11-25 18:48:54 +000031#include "net/slirp.h"
Mark McLoughlin5c361cc2009-11-25 18:48:55 +000032#include "net/vde.h"
Mark McLoughlinf1d078c2009-11-25 18:49:27 +000033#include "net/util.h"
blueswir1511d2b12009-03-07 15:32:56 +000034#include "monitor.h"
Mark McLoughlin1df49e02009-11-25 18:48:58 +000035#include "qemu-common.h"
blueswir1511d2b12009-03-07 15:32:56 +000036#include "qemu_socket.h"
Amit Shah75422b02010-02-25 17:24:43 +053037#include "hw/qdev.h"
Benjamin Poirierce053662011-02-23 19:57:21 -050038#include "iov.h"
blueswir1511d2b12009-03-07 15:32:56 +000039
Mark McLoughlin5610c3a2009-10-08 19:58:23 +010040static QTAILQ_HEAD(, VLANState) vlans;
Mark McLoughlin577c4af2009-10-08 19:58:28 +010041static QTAILQ_HEAD(, VLANClientState) non_vlan_clients;
aliguori63a01ef2008-10-31 19:10:00 +000042
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +010043int default_net = 1;
44
aliguori63a01ef2008-10-31 19:10:00 +000045/***********************************************************/
46/* network device redirectors */
47
Mark McLoughlin68ac40d2009-11-25 18:48:54 +000048#if defined(DEBUG_NET)
aliguori63a01ef2008-10-31 19:10:00 +000049static void hex_dump(FILE *f, const uint8_t *buf, int size)
50{
51 int len, i, j, c;
52
53 for(i=0;i<size;i+=16) {
54 len = size - i;
55 if (len > 16)
56 len = 16;
57 fprintf(f, "%08x ", i);
58 for(j=0;j<16;j++) {
59 if (j < len)
60 fprintf(f, " %02x", buf[i+j]);
61 else
62 fprintf(f, " ");
63 }
64 fprintf(f, " ");
65 for(j=0;j<len;j++) {
66 c = buf[i+j];
67 if (c < ' ' || c > '~')
68 c = '.';
69 fprintf(f, "%c", c);
70 }
71 fprintf(f, "\n");
72 }
73}
74#endif
75
aliguori63a01ef2008-10-31 19:10:00 +000076static int get_str_sep(char *buf, int buf_size, const char **pp, int sep)
77{
78 const char *p, *p1;
79 int len;
80 p = *pp;
81 p1 = strchr(p, sep);
82 if (!p1)
83 return -1;
84 len = p1 - p;
85 p1++;
86 if (buf_size > 0) {
87 if (len > buf_size - 1)
88 len = buf_size - 1;
89 memcpy(buf, p, len);
90 buf[len] = '\0';
91 }
92 *pp = p1;
93 return 0;
94}
95
aliguori63a01ef2008-10-31 19:10:00 +000096int parse_host_port(struct sockaddr_in *saddr, const char *str)
97{
98 char buf[512];
99 struct hostent *he;
100 const char *p, *r;
101 int port;
102
103 p = str;
104 if (get_str_sep(buf, sizeof(buf), &p, ':') < 0)
105 return -1;
106 saddr->sin_family = AF_INET;
107 if (buf[0] == '\0') {
108 saddr->sin_addr.s_addr = 0;
109 } else {
blueswir1cd390082008-11-16 13:53:32 +0000110 if (qemu_isdigit(buf[0])) {
aliguori63a01ef2008-10-31 19:10:00 +0000111 if (!inet_aton(buf, &saddr->sin_addr))
112 return -1;
113 } else {
114 if ((he = gethostbyname(buf)) == NULL)
115 return - 1;
116 saddr->sin_addr = *(struct in_addr *)he->h_addr;
117 }
118 }
119 port = strtol(p, (char **)&r, 0);
120 if (r == p)
121 return -1;
122 saddr->sin_port = htons(port);
123 return 0;
124}
125
aliguori7cb7434b2009-01-07 17:46:21 +0000126void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6])
127{
128 snprintf(vc->info_str, sizeof(vc->info_str),
aliguori4dda4062009-01-08 19:01:37 +0000129 "model=%s,macaddr=%02x:%02x:%02x:%02x:%02x:%02x",
130 vc->model,
aliguori7cb7434b2009-01-07 17:46:21 +0000131 macaddr[0], macaddr[1], macaddr[2],
132 macaddr[3], macaddr[4], macaddr[5]);
133}
134
Gerd Hoffmann76d32cb2009-10-21 15:25:22 +0200135void qemu_macaddr_default_if_unset(MACAddr *macaddr)
136{
137 static int index = 0;
138 static const MACAddr zero = { .a = { 0,0,0,0,0,0 } };
139
140 if (memcmp(macaddr, &zero, sizeof(zero)) != 0)
141 return;
142 macaddr->a[0] = 0x52;
143 macaddr->a[1] = 0x54;
144 macaddr->a[2] = 0x00;
145 macaddr->a[3] = 0x12;
146 macaddr->a[4] = 0x34;
147 macaddr->a[5] = 0x56 + index++;
148}
149
aliguori676cff22009-01-07 17:43:44 +0000150static char *assign_name(VLANClientState *vc1, const char *model)
151{
152 VLANState *vlan;
Markus Armbruster53e51d82011-06-16 18:45:36 +0200153 VLANClientState *vc;
aliguori676cff22009-01-07 17:43:44 +0000154 char buf[256];
155 int id = 0;
156
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100157 QTAILQ_FOREACH(vlan, &vlans, next) {
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100158 QTAILQ_FOREACH(vc, &vlan->clients, next) {
159 if (vc != vc1 && strcmp(vc->model, model) == 0) {
aliguori676cff22009-01-07 17:43:44 +0000160 id++;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100161 }
162 }
aliguori676cff22009-01-07 17:43:44 +0000163 }
164
Markus Armbruster53e51d82011-06-16 18:45:36 +0200165 QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
166 if (vc != vc1 && strcmp(vc->model, model) == 0) {
167 id++;
168 }
169 }
170
aliguori676cff22009-01-07 17:43:44 +0000171 snprintf(buf, sizeof(buf), "%s.%d", model, id);
172
Mark McLoughlin02374aa2009-10-06 12:16:55 +0100173 return qemu_strdup(buf);
aliguori676cff22009-01-07 17:43:44 +0000174}
175
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100176static ssize_t qemu_deliver_packet(VLANClientState *sender,
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100177 unsigned flags,
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100178 const uint8_t *data,
179 size_t size,
180 void *opaque);
181static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100182 unsigned flags,
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100183 const struct iovec *iov,
184 int iovcnt,
185 void *opaque);
186
Mark McLoughlin45460d12009-11-25 18:49:02 +0000187VLANClientState *qemu_new_net_client(NetClientInfo *info,
188 VLANState *vlan,
189 VLANClientState *peer,
190 const char *model,
191 const char *name)
aliguori63a01ef2008-10-31 19:10:00 +0000192{
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100193 VLANClientState *vc;
194
Mark McLoughlin45460d12009-11-25 18:49:02 +0000195 assert(info->size >= sizeof(VLANClientState));
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100196
Mark McLoughlin45460d12009-11-25 18:49:02 +0000197 vc = qemu_mallocz(info->size);
198
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000199 vc->info = info;
Mark McLoughlin02374aa2009-10-06 12:16:55 +0100200 vc->model = qemu_strdup(model);
Mark McLoughlin45460d12009-11-25 18:49:02 +0000201 if (name) {
Mark McLoughlin02374aa2009-10-06 12:16:55 +0100202 vc->name = qemu_strdup(name);
Mark McLoughlin45460d12009-11-25 18:49:02 +0000203 } else {
aliguori7a9f6e42009-01-07 17:48:51 +0000204 vc->name = assign_name(vc, model);
Mark McLoughlin45460d12009-11-25 18:49:02 +0000205 }
aliguori63a01ef2008-10-31 19:10:00 +0000206
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100207 if (vlan) {
Mark McLoughlin283c7c62009-10-08 19:58:30 +0100208 assert(!peer);
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100209 vc->vlan = vlan;
210 QTAILQ_INSERT_TAIL(&vc->vlan->clients, vc, next);
Mark McLoughlin577c4af2009-10-08 19:58:28 +0100211 } else {
Mark McLoughlin283c7c62009-10-08 19:58:30 +0100212 if (peer) {
Markus Armbruster27f3f8a2010-02-26 15:50:51 +0100213 assert(!peer->peer);
Mark McLoughlin283c7c62009-10-08 19:58:30 +0100214 vc->peer = peer;
215 peer->peer = vc;
216 }
Mark McLoughlin577c4af2009-10-08 19:58:28 +0100217 QTAILQ_INSERT_TAIL(&non_vlan_clients, vc, next);
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100218
219 vc->send_queue = qemu_new_net_queue(qemu_deliver_packet,
220 qemu_deliver_packet_iov,
221 vc);
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100222 }
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100223
aliguori63a01ef2008-10-31 19:10:00 +0000224 return vc;
225}
226
Mark McLoughlinebef2c02009-11-25 18:49:10 +0000227NICState *qemu_new_nic(NetClientInfo *info,
228 NICConf *conf,
229 const char *model,
230 const char *name,
231 void *opaque)
232{
233 VLANClientState *nc;
234 NICState *nic;
235
236 assert(info->type == NET_CLIENT_TYPE_NIC);
237 assert(info->size >= sizeof(NICState));
238
239 nc = qemu_new_net_client(info, conf->vlan, conf->peer, model, name);
240
241 nic = DO_UPCAST(NICState, nc, nc);
242 nic->conf = conf;
243 nic->opaque = opaque;
244
245 return nic;
246}
247
Michael S. Tsirkina083a892010-09-20 18:08:41 +0200248static void qemu_cleanup_vlan_client(VLANClientState *vc)
aliguori63a01ef2008-10-31 19:10:00 +0000249{
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100250 if (vc->vlan) {
251 QTAILQ_REMOVE(&vc->vlan->clients, vc, next);
Mark McLoughlin577c4af2009-10-08 19:58:28 +0100252 } else {
253 QTAILQ_REMOVE(&non_vlan_clients, vc, next);
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100254 }
aliguori63a01ef2008-10-31 19:10:00 +0000255
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000256 if (vc->info->cleanup) {
257 vc->info->cleanup(vc);
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100258 }
Michael S. Tsirkina083a892010-09-20 18:08:41 +0200259}
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100260
Michael S. Tsirkina083a892010-09-20 18:08:41 +0200261static void qemu_free_vlan_client(VLANClientState *vc)
262{
263 if (!vc->vlan) {
264 if (vc->send_queue) {
265 qemu_del_net_queue(vc->send_queue);
266 }
267 if (vc->peer) {
268 vc->peer->peer = NULL;
269 }
270 }
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100271 qemu_free(vc->name);
272 qemu_free(vc->model);
273 qemu_free(vc);
aliguori63a01ef2008-10-31 19:10:00 +0000274}
275
Michael S. Tsirkina083a892010-09-20 18:08:41 +0200276void qemu_del_vlan_client(VLANClientState *vc)
277{
278 /* If there is a peer NIC, delete and cleanup client, but do not free. */
279 if (!vc->vlan && vc->peer && vc->peer->info->type == NET_CLIENT_TYPE_NIC) {
280 NICState *nic = DO_UPCAST(NICState, nc, vc->peer);
281 if (nic->peer_deleted) {
282 return;
283 }
284 nic->peer_deleted = true;
285 /* Let NIC know peer is gone. */
286 vc->peer->link_down = true;
287 if (vc->peer->info->link_status_changed) {
288 vc->peer->info->link_status_changed(vc->peer);
289 }
290 qemu_cleanup_vlan_client(vc);
291 return;
292 }
293
294 /* If this is a peer NIC and peer has already been deleted, free it now. */
295 if (!vc->vlan && vc->peer && vc->info->type == NET_CLIENT_TYPE_NIC) {
296 NICState *nic = DO_UPCAST(NICState, nc, vc);
297 if (nic->peer_deleted) {
298 qemu_free_vlan_client(vc->peer);
299 }
300 }
301
302 qemu_cleanup_vlan_client(vc);
303 qemu_free_vlan_client(vc);
304}
305
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000306VLANClientState *
Jan Kiszka1a609522009-06-24 14:42:31 +0200307qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
308 const char *client_str)
309{
310 VLANState *vlan;
311 VLANClientState *vc;
312
313 vlan = qemu_find_vlan(vlan_id, 0);
314 if (!vlan) {
315 monitor_printf(mon, "unknown VLAN %d\n", vlan_id);
316 return NULL;
317 }
318
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100319 QTAILQ_FOREACH(vc, &vlan->clients, next) {
Jan Kiszka1a609522009-06-24 14:42:31 +0200320 if (!strcmp(vc->name, client_str)) {
321 break;
322 }
323 }
324 if (!vc) {
325 monitor_printf(mon, "can't find device %s on VLAN %d\n",
326 client_str, vlan_id);
327 }
328
329 return vc;
330}
331
Mark McLoughlin57f9ef12009-11-25 18:49:31 +0000332void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
333{
334 VLANClientState *nc;
335 VLANState *vlan;
336
337 QTAILQ_FOREACH(nc, &non_vlan_clients, next) {
338 if (nc->info->type == NET_CLIENT_TYPE_NIC) {
339 func(DO_UPCAST(NICState, nc, nc), opaque);
340 }
341 }
342
343 QTAILQ_FOREACH(vlan, &vlans, next) {
344 QTAILQ_FOREACH(nc, &vlan->clients, next) {
345 if (nc->info->type == NET_CLIENT_TYPE_NIC) {
346 func(DO_UPCAST(NICState, nc, nc), opaque);
347 }
348 }
349 }
350}
351
Mark McLoughlin2e1e0642009-04-29 09:36:43 +0100352int qemu_can_send_packet(VLANClientState *sender)
aliguori63a01ef2008-10-31 19:10:00 +0000353{
Mark McLoughlin2e1e0642009-04-29 09:36:43 +0100354 VLANState *vlan = sender->vlan;
aliguori63a01ef2008-10-31 19:10:00 +0000355 VLANClientState *vc;
356
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100357 if (sender->peer) {
Mark McLoughlin893379e2009-10-27 18:16:36 +0000358 if (sender->peer->receive_disabled) {
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100359 return 0;
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000360 } else if (sender->peer->info->can_receive &&
361 !sender->peer->info->can_receive(sender->peer)) {
Mark McLoughlin893379e2009-10-27 18:16:36 +0000362 return 0;
363 } else {
364 return 1;
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100365 }
366 }
367
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100368 if (!sender->vlan) {
369 return 1;
370 }
371
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100372 QTAILQ_FOREACH(vc, &vlan->clients, next) {
Mark McLoughlin2e1e0642009-04-29 09:36:43 +0100373 if (vc == sender) {
374 continue;
375 }
376
Mark McLoughlincda90462009-05-18 13:13:16 +0100377 /* no can_receive() handler, they can always receive */
Vincent Palatin60c07d92011-03-02 17:25:02 -0500378 if (vc->info->can_receive && !vc->info->can_receive(vc)) {
379 return 0;
aliguori63a01ef2008-10-31 19:10:00 +0000380 }
381 }
Vincent Palatin60c07d92011-03-02 17:25:02 -0500382 return 1;
aliguori63a01ef2008-10-31 19:10:00 +0000383}
384
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100385static ssize_t qemu_deliver_packet(VLANClientState *sender,
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100386 unsigned flags,
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100387 const uint8_t *data,
388 size_t size,
389 void *opaque)
390{
391 VLANClientState *vc = opaque;
Mark McLoughlin893379e2009-10-27 18:16:36 +0000392 ssize_t ret;
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100393
394 if (vc->link_down) {
395 return size;
396 }
397
Mark McLoughlin893379e2009-10-27 18:16:36 +0000398 if (vc->receive_disabled) {
399 return 0;
400 }
401
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000402 if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->info->receive_raw) {
403 ret = vc->info->receive_raw(vc, data, size);
Mark McLoughlin893379e2009-10-27 18:16:36 +0000404 } else {
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000405 ret = vc->info->receive(vc, data, size);
Mark McLoughlin893379e2009-10-27 18:16:36 +0000406 }
407
408 if (ret == 0) {
409 vc->receive_disabled = 1;
410 };
411
412 return ret;
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100413}
414
Mark McLoughlinf7105842009-10-08 19:58:31 +0100415static ssize_t qemu_vlan_deliver_packet(VLANClientState *sender,
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100416 unsigned flags,
Mark McLoughlinf7105842009-10-08 19:58:31 +0100417 const uint8_t *buf,
418 size_t size,
419 void *opaque)
aliguori63a01ef2008-10-31 19:10:00 +0000420{
Mark McLoughlinf7105842009-10-08 19:58:31 +0100421 VLANState *vlan = opaque;
aliguori63a01ef2008-10-31 19:10:00 +0000422 VLANClientState *vc;
Mark McLoughlin893379e2009-10-27 18:16:36 +0000423 ssize_t ret = -1;
aliguori63a01ef2008-10-31 19:10:00 +0000424
Mark McLoughlinf7105842009-10-08 19:58:31 +0100425 QTAILQ_FOREACH(vc, &vlan->clients, next) {
Mark McLoughlin3e021d42009-04-29 11:34:52 +0100426 ssize_t len;
427
428 if (vc == sender) {
429 continue;
aliguori764a4d12009-04-21 19:56:41 +0000430 }
Mark McLoughlin3e021d42009-04-29 11:34:52 +0100431
432 if (vc->link_down) {
433 ret = size;
434 continue;
435 }
436
Mark McLoughlin893379e2009-10-27 18:16:36 +0000437 if (vc->receive_disabled) {
438 ret = 0;
439 continue;
440 }
441
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000442 if (flags & QEMU_NET_PACKET_FLAG_RAW && vc->info->receive_raw) {
443 len = vc->info->receive_raw(vc, buf, size);
Mark McLoughlin893379e2009-10-27 18:16:36 +0000444 } else {
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000445 len = vc->info->receive(vc, buf, size);
Mark McLoughlin893379e2009-10-27 18:16:36 +0000446 }
447
448 if (len == 0) {
449 vc->receive_disabled = 1;
450 }
Mark McLoughlin3e021d42009-04-29 11:34:52 +0100451
452 ret = (ret >= 0) ? ret : len;
Mark McLoughlin893379e2009-10-27 18:16:36 +0000453
aliguori764a4d12009-04-21 19:56:41 +0000454 }
Mark McLoughlin3e021d42009-04-29 11:34:52 +0100455
456 return ret;
aliguori764a4d12009-04-21 19:56:41 +0000457}
458
Mark McLoughlin8cad5512009-06-18 18:21:29 +0100459void qemu_purge_queued_packets(VLANClientState *vc)
460{
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100461 NetQueue *queue;
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100462
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100463 if (!vc->peer && !vc->vlan) {
464 return;
465 }
466
467 if (vc->peer) {
468 queue = vc->peer->send_queue;
469 } else {
470 queue = vc->vlan->send_queue;
471 }
472
473 qemu_net_queue_purge(queue, vc);
Mark McLoughlin8cad5512009-06-18 18:21:29 +0100474}
475
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100476void qemu_flush_queued_packets(VLANClientState *vc)
Mark McLoughline94667b2009-04-29 11:48:12 +0100477{
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100478 NetQueue *queue;
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100479
Mark McLoughlin893379e2009-10-27 18:16:36 +0000480 vc->receive_disabled = 0;
481
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100482 if (vc->vlan) {
483 queue = vc->vlan->send_queue;
484 } else {
485 queue = vc->send_queue;
486 }
487
488 qemu_net_queue_flush(queue);
Mark McLoughline94667b2009-04-29 11:48:12 +0100489}
490
Mark McLoughlinca77d172009-10-22 17:43:41 +0100491static ssize_t qemu_send_packet_async_with_flags(VLANClientState *sender,
492 unsigned flags,
493 const uint8_t *buf, int size,
494 NetPacketSent *sent_cb)
aliguori764a4d12009-04-21 19:56:41 +0000495{
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100496 NetQueue *queue;
Mark McLoughline94667b2009-04-29 11:48:12 +0100497
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100498#ifdef DEBUG_NET
Mark McLoughlind80b9fc2009-10-08 19:58:24 +0100499 printf("qemu_send_packet_async:\n");
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100500 hex_dump(stdout, buf, size);
501#endif
502
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100503 if (sender->link_down || (!sender->peer && !sender->vlan)) {
504 return size;
505 }
506
507 if (sender->peer) {
508 queue = sender->peer->send_queue;
509 } else {
510 queue = sender->vlan->send_queue;
511 }
512
Mark McLoughlinca77d172009-10-22 17:43:41 +0100513 return qemu_net_queue_send(queue, sender, flags, buf, size, sent_cb);
514}
515
516ssize_t qemu_send_packet_async(VLANClientState *sender,
517 const uint8_t *buf, int size,
518 NetPacketSent *sent_cb)
519{
520 return qemu_send_packet_async_with_flags(sender, QEMU_NET_PACKET_FLAG_NONE,
521 buf, size, sent_cb);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100522}
523
524void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size)
525{
526 qemu_send_packet_async(vc, buf, size, NULL);
aliguori63a01ef2008-10-31 19:10:00 +0000527}
528
Mark McLoughlinca77d172009-10-22 17:43:41 +0100529ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size)
530{
531 return qemu_send_packet_async_with_flags(vc, QEMU_NET_PACKET_FLAG_RAW,
532 buf, size, NULL);
533}
534
aliguorifbe78f42008-12-17 19:13:11 +0000535static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
536 int iovcnt)
537{
538 uint8_t buffer[4096];
Benjamin Poirierce053662011-02-23 19:57:21 -0500539 size_t offset;
aliguorifbe78f42008-12-17 19:13:11 +0000540
Benjamin Poirierce053662011-02-23 19:57:21 -0500541 offset = iov_to_buf(iov, iovcnt, buffer, 0, sizeof(buffer));
aliguorifbe78f42008-12-17 19:13:11 +0000542
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000543 return vc->info->receive(vc, buffer, offset);
aliguorifbe78f42008-12-17 19:13:11 +0000544}
545
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100546static ssize_t qemu_deliver_packet_iov(VLANClientState *sender,
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100547 unsigned flags,
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100548 const struct iovec *iov,
549 int iovcnt,
550 void *opaque)
551{
552 VLANClientState *vc = opaque;
553
554 if (vc->link_down) {
Benjamin Poirierce053662011-02-23 19:57:21 -0500555 return iov_size(iov, iovcnt);
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100556 }
557
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000558 if (vc->info->receive_iov) {
559 return vc->info->receive_iov(vc, iov, iovcnt);
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100560 } else {
561 return vc_sendv_compat(vc, iov, iovcnt);
562 }
563}
564
Mark McLoughlinf7105842009-10-08 19:58:31 +0100565static ssize_t qemu_vlan_deliver_packet_iov(VLANClientState *sender,
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100566 unsigned flags,
Mark McLoughlinf7105842009-10-08 19:58:31 +0100567 const struct iovec *iov,
568 int iovcnt,
569 void *opaque)
Mark McLoughline94667b2009-04-29 11:48:12 +0100570{
Mark McLoughlinf7105842009-10-08 19:58:31 +0100571 VLANState *vlan = opaque;
Mark McLoughline94667b2009-04-29 11:48:12 +0100572 VLANClientState *vc;
Mark McLoughlinf7105842009-10-08 19:58:31 +0100573 ssize_t ret = -1;
Mark McLoughline94667b2009-04-29 11:48:12 +0100574
Mark McLoughlinf7105842009-10-08 19:58:31 +0100575 QTAILQ_FOREACH(vc, &vlan->clients, next) {
Mark McLoughline94667b2009-04-29 11:48:12 +0100576 ssize_t len;
577
578 if (vc == sender) {
579 continue;
580 }
581
582 if (vc->link_down) {
Benjamin Poirierce053662011-02-23 19:57:21 -0500583 ret = iov_size(iov, iovcnt);
Mark McLoughline94667b2009-04-29 11:48:12 +0100584 continue;
585 }
586
Mark McLoughlinca77d172009-10-22 17:43:41 +0100587 assert(!(flags & QEMU_NET_PACKET_FLAG_RAW));
588
Mark McLoughlin665a3b02009-11-25 18:49:30 +0000589 if (vc->info->receive_iov) {
590 len = vc->info->receive_iov(vc, iov, iovcnt);
Mark McLoughline94667b2009-04-29 11:48:12 +0100591 } else {
592 len = vc_sendv_compat(vc, iov, iovcnt);
593 }
594
595 ret = (ret >= 0) ? ret : len;
596 }
597
Mark McLoughline94667b2009-04-29 11:48:12 +0100598 return ret;
599}
600
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100601ssize_t qemu_sendv_packet_async(VLANClientState *sender,
602 const struct iovec *iov, int iovcnt,
603 NetPacketSent *sent_cb)
aliguorifbe78f42008-12-17 19:13:11 +0000604{
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100605 NetQueue *queue;
606
607 if (sender->link_down || (!sender->peer && !sender->vlan)) {
Benjamin Poirierce053662011-02-23 19:57:21 -0500608 return iov_size(iov, iovcnt);
aliguorifbe78f42008-12-17 19:13:11 +0000609 }
610
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +0100611 if (sender->peer) {
612 queue = sender->peer->send_queue;
613 } else {
614 queue = sender->vlan->send_queue;
615 }
616
Mark McLoughlinc0b8e492009-10-22 17:43:40 +0100617 return qemu_net_queue_send_iov(queue, sender,
618 QEMU_NET_PACKET_FLAG_NONE,
619 iov, iovcnt, sent_cb);
aliguorifbe78f42008-12-17 19:13:11 +0000620}
621
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100622ssize_t
623qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)
624{
625 return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
626}
627
aliguori63a01ef2008-10-31 19:10:00 +0000628/* find or alloc a new VLAN */
Jan Kiszka1a609522009-06-24 14:42:31 +0200629VLANState *qemu_find_vlan(int id, int allocate)
aliguori63a01ef2008-10-31 19:10:00 +0000630{
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100631 VLANState *vlan;
632
633 QTAILQ_FOREACH(vlan, &vlans, next) {
634 if (vlan->id == id) {
aliguori63a01ef2008-10-31 19:10:00 +0000635 return vlan;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100636 }
aliguori63a01ef2008-10-31 19:10:00 +0000637 }
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100638
Jan Kiszka1a609522009-06-24 14:42:31 +0200639 if (!allocate) {
640 return NULL;
641 }
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100642
aliguori63a01ef2008-10-31 19:10:00 +0000643 vlan = qemu_mallocz(sizeof(VLANState));
aliguori63a01ef2008-10-31 19:10:00 +0000644 vlan->id = id;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100645 QTAILQ_INIT(&vlan->clients);
Mark McLoughlinf7105842009-10-08 19:58:31 +0100646
647 vlan->send_queue = qemu_new_net_queue(qemu_vlan_deliver_packet,
648 qemu_vlan_deliver_packet_iov,
649 vlan);
Mark McLoughlin5610c3a2009-10-08 19:58:23 +0100650
651 QTAILQ_INSERT_TAIL(&vlans, vlan, next);
652
aliguori63a01ef2008-10-31 19:10:00 +0000653 return vlan;
654}
655
Gerd Hoffmann2ef924b2009-10-21 15:25:24 +0200656VLANClientState *qemu_find_netdev(const char *id)
Mark McLoughlin5869c4d2009-10-08 19:58:29 +0100657{
658 VLANClientState *vc;
659
660 QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
661 if (!strcmp(vc->name, id)) {
662 return vc;
663 }
664 }
665
666 return NULL;
667}
668
aliguori76970792009-02-11 15:20:03 +0000669static int nic_get_free_idx(void)
670{
671 int index;
672
673 for (index = 0; index < MAX_NICS; index++)
674 if (!nd_table[index].used)
675 return index;
676 return -1;
677}
678
Markus Armbruster07caea32009-09-25 03:53:51 +0200679int qemu_show_nic_models(const char *arg, const char *const *models)
680{
681 int i;
682
683 if (!arg || strcmp(arg, "?"))
684 return 0;
685
686 fprintf(stderr, "qemu: Supported NIC models: ");
687 for (i = 0 ; models[i]; i++)
688 fprintf(stderr, "%s%c", models[i], models[i+1] ? ',' : '\n');
689 return 1;
690}
691
aliguorid07f22c2009-01-13 19:03:57 +0000692void qemu_check_nic_model(NICInfo *nd, const char *model)
693{
694 const char *models[2];
695
696 models[0] = model;
697 models[1] = NULL;
698
Markus Armbruster07caea32009-09-25 03:53:51 +0200699 if (qemu_show_nic_models(nd->model, models))
700 exit(0);
701 if (qemu_find_nic_model(nd, models, model) < 0)
702 exit(1);
aliguorid07f22c2009-01-13 19:03:57 +0000703}
704
Markus Armbruster07caea32009-09-25 03:53:51 +0200705int qemu_find_nic_model(NICInfo *nd, const char * const *models,
706 const char *default_model)
aliguorid07f22c2009-01-13 19:03:57 +0000707{
Markus Armbruster07caea32009-09-25 03:53:51 +0200708 int i;
aliguorid07f22c2009-01-13 19:03:57 +0000709
710 if (!nd->model)
Mark McLoughlin32a8e142009-10-06 12:16:51 +0100711 nd->model = qemu_strdup(default_model);
aliguorid07f22c2009-01-13 19:03:57 +0000712
Markus Armbruster07caea32009-09-25 03:53:51 +0200713 for (i = 0 ; models[i]; i++) {
714 if (strcmp(nd->model, models[i]) == 0)
715 return i;
aliguorid07f22c2009-01-13 19:03:57 +0000716 }
717
Markus Armbruster6daf1942011-06-22 14:03:54 +0200718 error_report("Unsupported NIC model: %s", nd->model);
Markus Armbruster07caea32009-09-25 03:53:51 +0200719 return -1;
aliguorid07f22c2009-01-13 19:03:57 +0000720}
721
Mark McLoughlin5281d752009-10-22 17:49:07 +0100722int net_handle_fd_param(Monitor *mon, const char *param)
Mark McLoughlinc1d6eed2009-07-22 09:11:42 +0100723{
Jason Wangf7c31d62010-10-25 13:39:59 +0800724 int fd;
725
726 if (!qemu_isdigit(param[0]) && mon) {
Mark McLoughlinc1d6eed2009-07-22 09:11:42 +0100727
728 fd = monitor_get_fd(mon, param);
729 if (fd == -1) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100730 error_report("No file descriptor named %s found", param);
Mark McLoughlinc1d6eed2009-07-22 09:11:42 +0100731 return -1;
732 }
Mark McLoughlinc1d6eed2009-07-22 09:11:42 +0100733 } else {
Jason Wangf7c31d62010-10-25 13:39:59 +0800734 char *endptr = NULL;
735
736 fd = strtol(param, &endptr, 10);
737 if (*endptr || (fd == 0 && param == endptr)) {
738 return -1;
739 }
Mark McLoughlinc1d6eed2009-07-22 09:11:42 +0100740 }
Jason Wangf7c31d62010-10-25 13:39:59 +0800741
742 return fd;
Mark McLoughlinc1d6eed2009-07-22 09:11:42 +0100743}
744
Mark McLoughlinf6b134a2009-10-08 19:58:27 +0100745static int net_init_nic(QemuOpts *opts,
746 Monitor *mon,
747 const char *name,
748 VLANState *vlan)
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100749{
750 int idx;
751 NICInfo *nd;
Mark McLoughlin5869c4d2009-10-08 19:58:29 +0100752 const char *netdev;
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100753
754 idx = nic_get_free_idx();
755 if (idx == -1 || nb_nics >= MAX_NICS) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100756 error_report("Too Many NICs");
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100757 return -1;
758 }
759
760 nd = &nd_table[idx];
761
762 memset(nd, 0, sizeof(*nd));
763
Mark McLoughlin5869c4d2009-10-08 19:58:29 +0100764 if ((netdev = qemu_opt_get(opts, "netdev"))) {
765 nd->netdev = qemu_find_netdev(netdev);
766 if (!nd->netdev) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100767 error_report("netdev '%s' not found", netdev);
Mark McLoughlin5869c4d2009-10-08 19:58:29 +0100768 return -1;
769 }
770 } else {
771 assert(vlan);
772 nd->vlan = vlan;
773 }
Mark McLoughlin6d952eb2009-10-08 19:58:21 +0100774 if (name) {
775 nd->name = qemu_strdup(name);
776 }
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100777 if (qemu_opt_get(opts, "model")) {
778 nd->model = qemu_strdup(qemu_opt_get(opts, "model"));
779 }
780 if (qemu_opt_get(opts, "addr")) {
781 nd->devaddr = qemu_strdup(qemu_opt_get(opts, "addr"));
782 }
783
784 nd->macaddr[0] = 0x52;
785 nd->macaddr[1] = 0x54;
786 nd->macaddr[2] = 0x00;
787 nd->macaddr[3] = 0x12;
788 nd->macaddr[4] = 0x34;
789 nd->macaddr[5] = 0x56 + idx;
790
791 if (qemu_opt_get(opts, "macaddr") &&
Mark McLoughlinf1d078c2009-11-25 18:49:27 +0000792 net_parse_macaddr(nd->macaddr, qemu_opt_get(opts, "macaddr")) < 0) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100793 error_report("invalid syntax for ethernet address");
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100794 return -1;
795 }
796
Amit Shah75422b02010-02-25 17:24:43 +0530797 nd->nvectors = qemu_opt_get_number(opts, "vectors",
798 DEV_NVECTORS_UNSPECIFIED);
799 if (nd->nvectors != DEV_NVECTORS_UNSPECIFIED &&
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100800 (nd->nvectors < 0 || nd->nvectors > 0x7ffffff)) {
Markus Armbruster1ecda022010-02-18 17:25:24 +0100801 error_report("invalid # of vectors: %d", nd->nvectors);
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100802 return -1;
803 }
804
805 nd->used = 1;
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100806 nb_nics++;
807
808 return idx;
809}
810
811#define NET_COMMON_PARAMS_DESC \
812 { \
813 .name = "type", \
814 .type = QEMU_OPT_STRING, \
815 .help = "net client type (nic, tap etc.)", \
816 }, { \
817 .name = "vlan", \
818 .type = QEMU_OPT_NUMBER, \
819 .help = "vlan number", \
820 }, { \
821 .name = "name", \
822 .type = QEMU_OPT_STRING, \
823 .help = "identifier for monitor commands", \
824 }
825
Mark McLoughlin6d952eb2009-10-08 19:58:21 +0100826typedef int (*net_client_init_func)(QemuOpts *opts,
827 Monitor *mon,
Mark McLoughlinf6b134a2009-10-08 19:58:27 +0100828 const char *name,
829 VLANState *vlan);
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100830
831/* magic number, but compiler will warn if too small */
832#define NET_MAX_DESC 20
833
Blue Swirl238431a2010-02-21 16:01:30 +0000834static const struct {
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100835 const char *type;
836 net_client_init_func init;
837 QemuOptDesc desc[NET_MAX_DESC];
838} net_client_types[] = {
839 {
840 .type = "none",
841 .desc = {
842 NET_COMMON_PARAMS_DESC,
843 { /* end of list */ }
844 },
845 }, {
846 .type = "nic",
847 .init = net_init_nic,
848 .desc = {
849 NET_COMMON_PARAMS_DESC,
850 {
Mark McLoughlin5869c4d2009-10-08 19:58:29 +0100851 .name = "netdev",
852 .type = QEMU_OPT_STRING,
853 .help = "id of -netdev to connect to",
854 },
855 {
Mark McLoughlinf83c6e12009-10-06 12:17:06 +0100856 .name = "macaddr",
857 .type = QEMU_OPT_STRING,
858 .help = "MAC address",
859 }, {
860 .name = "model",
861 .type = QEMU_OPT_STRING,
862 .help = "device model (e1000, rtl8139, virtio etc.)",
863 }, {
864 .name = "addr",
865 .type = QEMU_OPT_STRING,
866 .help = "PCI device address",
867 }, {
868 .name = "vectors",
869 .type = QEMU_OPT_NUMBER,
870 .help = "number of MSI-x vectors, 0 to disable MSI-X",
871 },
872 { /* end of list */ }
873 },
Mark McLoughlinec302ff2009-10-06 12:17:07 +0100874#ifdef CONFIG_SLIRP
875 }, {
876 .type = "user",
877 .init = net_init_slirp,
878 .desc = {
879 NET_COMMON_PARAMS_DESC,
880 {
881 .name = "hostname",
882 .type = QEMU_OPT_STRING,
883 .help = "client hostname reported by the builtin DHCP server",
884 }, {
885 .name = "restrict",
886 .type = QEMU_OPT_STRING,
887 .help = "isolate the guest from the host (y|yes|n|no)",
888 }, {
889 .name = "ip",
890 .type = QEMU_OPT_STRING,
891 .help = "legacy parameter, use net= instead",
892 }, {
893 .name = "net",
894 .type = QEMU_OPT_STRING,
895 .help = "IP address and optional netmask",
896 }, {
897 .name = "host",
898 .type = QEMU_OPT_STRING,
899 .help = "guest-visible address of the host",
900 }, {
901 .name = "tftp",
902 .type = QEMU_OPT_STRING,
903 .help = "root directory of the built-in TFTP server",
904 }, {
905 .name = "bootfile",
906 .type = QEMU_OPT_STRING,
907 .help = "BOOTP filename, for use with tftp=",
908 }, {
909 .name = "dhcpstart",
910 .type = QEMU_OPT_STRING,
911 .help = "the first of the 16 IPs the built-in DHCP server can assign",
912 }, {
913 .name = "dns",
914 .type = QEMU_OPT_STRING,
915 .help = "guest-visible address of the virtual nameserver",
916 }, {
917 .name = "smb",
918 .type = QEMU_OPT_STRING,
919 .help = "root directory of the built-in SMB server",
920 }, {
921 .name = "smbserver",
922 .type = QEMU_OPT_STRING,
923 .help = "IP address of the built-in SMB server",
924 }, {
925 .name = "hostfwd",
926 .type = QEMU_OPT_STRING,
927 .help = "guest port number to forward incoming TCP or UDP connections",
928 }, {
929 .name = "guestfwd",
930 .type = QEMU_OPT_STRING,
931 .help = "IP address and port to forward guest TCP connections",
932 },
933 { /* end of list */ }
934 },
935#endif
Mark McLoughlin8a1c5232009-10-06 12:17:08 +0100936 }, {
937 .type = "tap",
Mark McLoughlina8ed73f2009-10-22 17:49:05 +0100938 .init = net_init_tap,
Mark McLoughlin8a1c5232009-10-06 12:17:08 +0100939 .desc = {
940 NET_COMMON_PARAMS_DESC,
941 {
942 .name = "ifname",
943 .type = QEMU_OPT_STRING,
944 .help = "interface name",
945 },
Mark McLoughlina8ed73f2009-10-22 17:49:05 +0100946#ifndef _WIN32
Mark McLoughlin8a1c5232009-10-06 12:17:08 +0100947 {
948 .name = "fd",
949 .type = QEMU_OPT_STRING,
950 .help = "file descriptor of an already opened tap",
951 }, {
Mark McLoughlin8a1c5232009-10-06 12:17:08 +0100952 .name = "script",
953 .type = QEMU_OPT_STRING,
954 .help = "script to initialize the interface",
955 }, {
956 .name = "downscript",
957 .type = QEMU_OPT_STRING,
958 .help = "script to shut down the interface",
Mark McLoughlin8a1c5232009-10-06 12:17:08 +0100959 }, {
960 .name = "sndbuf",
961 .type = QEMU_OPT_SIZE,
962 .help = "send buffer limit"
Mark McLoughlinbaf74c92009-10-22 17:43:37 +0100963 }, {
964 .name = "vnet_hdr",
965 .type = QEMU_OPT_BOOL,
966 .help = "enable the IFF_VNET_HDR flag on the tap interface"
Michael S. Tsirkin82b0d802010-03-17 13:08:24 +0200967 }, {
968 .name = "vhost",
969 .type = QEMU_OPT_BOOL,
970 .help = "enable vhost-net network accelerator",
971 }, {
972 .name = "vhostfd",
973 .type = QEMU_OPT_STRING,
974 .help = "file descriptor of an already opened vhost net device",
Jason Wang96c94b22011-02-25 16:11:27 +0800975 }, {
976 .name = "vhostforce",
977 .type = QEMU_OPT_BOOL,
978 .help = "force vhost on for non-MSIX virtio guests",
979 },
Mark McLoughlina8ed73f2009-10-22 17:49:05 +0100980#endif /* _WIN32 */
Mark McLoughlin8a1c5232009-10-06 12:17:08 +0100981 { /* end of list */ }
982 },
Mark McLoughlin88ce16c2009-10-06 12:17:09 +0100983 }, {
984 .type = "socket",
985 .init = net_init_socket,
986 .desc = {
987 NET_COMMON_PARAMS_DESC,
988 {
989 .name = "fd",
990 .type = QEMU_OPT_STRING,
991 .help = "file descriptor of an already opened socket",
992 }, {
993 .name = "listen",
994 .type = QEMU_OPT_STRING,
995 .help = "port number, and optional hostname, to listen on",
996 }, {
997 .name = "connect",
998 .type = QEMU_OPT_STRING,
999 .help = "port number, and optional hostname, to connect to",
1000 }, {
1001 .name = "mcast",
1002 .type = QEMU_OPT_STRING,
1003 .help = "UDP multicast address and port number",
Mike Ryan3a75e742010-12-01 11:16:47 -08001004 }, {
1005 .name = "localaddr",
1006 .type = QEMU_OPT_STRING,
1007 .help = "source address for multicast packets",
Mark McLoughlin88ce16c2009-10-06 12:17:09 +01001008 },
1009 { /* end of list */ }
1010 },
Mark McLoughlindd510582009-10-06 12:17:10 +01001011#ifdef CONFIG_VDE
1012 }, {
1013 .type = "vde",
1014 .init = net_init_vde,
1015 .desc = {
1016 NET_COMMON_PARAMS_DESC,
1017 {
1018 .name = "sock",
1019 .type = QEMU_OPT_STRING,
1020 .help = "socket path",
1021 }, {
1022 .name = "port",
1023 .type = QEMU_OPT_NUMBER,
1024 .help = "port number",
1025 }, {
1026 .name = "group",
1027 .type = QEMU_OPT_STRING,
1028 .help = "group owner of socket",
1029 }, {
1030 .name = "mode",
1031 .type = QEMU_OPT_NUMBER,
1032 .help = "permissions for socket",
1033 },
1034 { /* end of list */ }
1035 },
1036#endif
Mark McLoughlined2955c2009-10-06 12:17:11 +01001037 }, {
1038 .type = "dump",
1039 .init = net_init_dump,
1040 .desc = {
1041 NET_COMMON_PARAMS_DESC,
1042 {
1043 .name = "len",
1044 .type = QEMU_OPT_SIZE,
1045 .help = "per-packet size limit (64k default)",
1046 }, {
1047 .name = "file",
1048 .type = QEMU_OPT_STRING,
1049 .help = "dump file path (default is qemu-vlan0.pcap)",
1050 },
1051 { /* end of list */ }
1052 },
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001053 },
1054 { /* end of list */ }
1055};
1056
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001057int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev)
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001058{
Mark McLoughlin6d952eb2009-10-08 19:58:21 +01001059 const char *name;
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001060 const char *type;
1061 int i;
1062
1063 type = qemu_opt_get(opts, "type");
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001064 if (!type) {
1065 qerror_report(QERR_MISSING_PARAMETER, "type");
1066 return -1;
1067 }
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001068
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001069 if (is_netdev) {
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001070 if (strcmp(type, "tap") != 0 &&
1071#ifdef CONFIG_SLIRP
1072 strcmp(type, "user") != 0 &&
1073#endif
1074#ifdef CONFIG_VDE
1075 strcmp(type, "vde") != 0 &&
1076#endif
1077 strcmp(type, "socket") != 0) {
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001078 qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
1079 "a netdev backend type");
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001080 return -1;
1081 }
1082
1083 if (qemu_opt_get(opts, "vlan")) {
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001084 qerror_report(QERR_INVALID_PARAMETER, "vlan");
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001085 return -1;
1086 }
1087 if (qemu_opt_get(opts, "name")) {
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001088 qerror_report(QERR_INVALID_PARAMETER, "name");
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001089 return -1;
1090 }
1091 if (!qemu_opts_id(opts)) {
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001092 qerror_report(QERR_MISSING_PARAMETER, "id");
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001093 return -1;
1094 }
1095 }
1096
Mark McLoughlin6d952eb2009-10-08 19:58:21 +01001097 name = qemu_opts_id(opts);
1098 if (!name) {
1099 name = qemu_opt_get(opts, "name");
1100 }
1101
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001102 for (i = 0; net_client_types[i].type != NULL; i++) {
1103 if (!strcmp(net_client_types[i].type, type)) {
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001104 VLANState *vlan = NULL;
Amit Shah50e32ea2010-06-08 21:13:58 +05301105 int ret;
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001106
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001107 if (qemu_opts_validate(opts, &net_client_types[i].desc[0]) == -1) {
1108 return -1;
1109 }
1110
Mark McLoughlin5869c4d2009-10-08 19:58:29 +01001111 /* Do not add to a vlan if it's a -netdev or a nic with a
1112 * netdev= parameter. */
1113 if (!(is_netdev ||
1114 (strcmp(type, "nic") == 0 && qemu_opt_get(opts, "netdev")))) {
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001115 vlan = qemu_find_vlan(qemu_opt_get_number(opts, "vlan", 0), 1);
1116 }
1117
Amit Shah03c71552010-06-15 13:30:39 +05301118 ret = 0;
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001119 if (net_client_types[i].init) {
Amit Shah50e32ea2010-06-08 21:13:58 +05301120 ret = net_client_types[i].init(opts, mon, name, vlan);
1121 if (ret < 0) {
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001122 /* TODO push error reporting into init() methods */
1123 qerror_report(QERR_DEVICE_INIT_FAILED, type);
1124 return -1;
1125 }
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001126 }
Amit Shah50e32ea2010-06-08 21:13:58 +05301127 return ret;
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001128 }
1129 }
1130
Markus Armbruster5294e2c2010-03-25 17:22:38 +01001131 qerror_report(QERR_INVALID_PARAMETER_VALUE, "type",
1132 "a network client type");
Mark McLoughlinf83c6e12009-10-06 12:17:06 +01001133 return -1;
1134}
1135
aliguori6f338c32009-02-11 15:21:54 +00001136static int net_host_check_device(const char *device)
1137{
1138 int i;
aliguoribb9ea792009-04-21 19:56:28 +00001139 const char *valid_param_list[] = { "tap", "socket", "dump"
aliguori6f338c32009-02-11 15:21:54 +00001140#ifdef CONFIG_SLIRP
1141 ,"user"
1142#endif
1143#ifdef CONFIG_VDE
1144 ,"vde"
1145#endif
1146 };
1147 for (i = 0; i < sizeof(valid_param_list) / sizeof(char *); i++) {
1148 if (!strncmp(valid_param_list[i], device,
1149 strlen(valid_param_list[i])))
1150 return 1;
1151 }
1152
1153 return 0;
1154}
1155
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03001156void net_host_device_add(Monitor *mon, const QDict *qdict)
aliguori6f338c32009-02-11 15:21:54 +00001157{
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03001158 const char *device = qdict_get_str(qdict, "device");
Mark McLoughlin7f1c9d22009-10-06 12:17:13 +01001159 const char *opts_str = qdict_get_try_str(qdict, "opts");
1160 QemuOpts *opts;
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03001161
aliguori6f338c32009-02-11 15:21:54 +00001162 if (!net_host_check_device(device)) {
aliguori376253e2009-03-05 23:01:23 +00001163 monitor_printf(mon, "invalid host network device %s\n", device);
aliguori6f338c32009-02-11 15:21:54 +00001164 return;
1165 }
Mark McLoughlin7f1c9d22009-10-06 12:17:13 +01001166
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001167 opts = qemu_opts_parse(qemu_find_opts("net"), opts_str ? opts_str : "", 0);
Mark McLoughlin7f1c9d22009-10-06 12:17:13 +01001168 if (!opts) {
Mark McLoughlin7f1c9d22009-10-06 12:17:13 +01001169 return;
1170 }
1171
1172 qemu_opt_set(opts, "type", device);
1173
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001174 if (net_client_init(mon, opts, 0) < 0) {
aliguori5c8be672009-04-21 19:56:32 +00001175 monitor_printf(mon, "adding host network device %s failed\n", device);
1176 }
aliguori6f338c32009-02-11 15:21:54 +00001177}
1178
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03001179void net_host_device_remove(Monitor *mon, const QDict *qdict)
aliguori6f338c32009-02-11 15:21:54 +00001180{
aliguori6f338c32009-02-11 15:21:54 +00001181 VLANClientState *vc;
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03001182 int vlan_id = qdict_get_int(qdict, "vlan_id");
1183 const char *device = qdict_get_str(qdict, "device");
aliguori6f338c32009-02-11 15:21:54 +00001184
Jan Kiszka1a609522009-06-24 14:42:31 +02001185 vc = qemu_find_vlan_client_by_name(mon, vlan_id, device);
aliguori6f338c32009-02-11 15:21:54 +00001186 if (!vc) {
aliguori6f338c32009-02-11 15:21:54 +00001187 return;
1188 }
aliguorie8f1f9d2009-04-21 19:56:08 +00001189 if (!net_host_check_device(vc->model)) {
1190 monitor_printf(mon, "invalid host network device %s\n", device);
1191 return;
1192 }
aliguori6f338c32009-02-11 15:21:54 +00001193 qemu_del_vlan_client(vc);
1194}
1195
Markus Armbrusterae82d322010-03-25 17:22:40 +01001196int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data)
1197{
1198 QemuOpts *opts;
1199 int res;
1200
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001201 opts = qemu_opts_from_qdict(qemu_find_opts("netdev"), qdict);
Markus Armbrusterae82d322010-03-25 17:22:40 +01001202 if (!opts) {
1203 return -1;
1204 }
1205
1206 res = net_client_init(mon, opts, 1);
Yoshiaki Tamura410cbaf2010-06-21 10:41:36 +09001207 if (res < 0) {
1208 qemu_opts_del(opts);
1209 }
1210
Markus Armbrusterae82d322010-03-25 17:22:40 +01001211 return res;
1212}
1213
Markus Armbrusterae82d322010-03-25 17:22:40 +01001214int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data)
1215{
1216 const char *id = qdict_get_str(qdict, "id");
1217 VLANClientState *vc;
1218
1219 vc = qemu_find_netdev(id);
1220 if (!vc || vc->info->type == NET_CLIENT_TYPE_NIC) {
1221 qerror_report(QERR_DEVICE_NOT_FOUND, id);
1222 return -1;
1223 }
Markus Armbrusterae82d322010-03-25 17:22:40 +01001224 qemu_del_vlan_client(vc);
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001225 qemu_opts_del(qemu_opts_find(qemu_find_opts("netdev"), id));
Markus Armbrusterae82d322010-03-25 17:22:40 +01001226 return 0;
1227}
1228
aliguori376253e2009-03-05 23:01:23 +00001229void do_info_network(Monitor *mon)
aliguori63a01ef2008-10-31 19:10:00 +00001230{
1231 VLANState *vlan;
Markus Armbrustera0104e02010-02-11 14:45:01 +01001232 VLANClientState *vc;
aliguori63a01ef2008-10-31 19:10:00 +00001233
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001234 QTAILQ_FOREACH(vlan, &vlans, next) {
aliguori376253e2009-03-05 23:01:23 +00001235 monitor_printf(mon, "VLAN %d devices:\n", vlan->id);
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001236
1237 QTAILQ_FOREACH(vc, &vlan->clients, next) {
aliguori376253e2009-03-05 23:01:23 +00001238 monitor_printf(mon, " %s: %s\n", vc->name, vc->info_str);
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001239 }
aliguori63a01ef2008-10-31 19:10:00 +00001240 }
Markus Armbrustera0104e02010-02-11 14:45:01 +01001241 monitor_printf(mon, "Devices not on any VLAN:\n");
1242 QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
1243 monitor_printf(mon, " %s: %s", vc->name, vc->info_str);
1244 if (vc->peer) {
1245 monitor_printf(mon, " peer=%s", vc->peer->name);
1246 }
1247 monitor_printf(mon, "\n");
1248 }
aliguori63a01ef2008-10-31 19:10:00 +00001249}
1250
Markus Armbruster5369e3c2010-03-26 09:07:11 +01001251int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data)
aliguori436e5e52009-01-08 19:44:06 +00001252{
1253 VLANState *vlan;
1254 VLANClientState *vc = NULL;
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03001255 const char *name = qdict_get_str(qdict, "name");
Markus Armbrusterc9b26a42010-03-26 09:07:10 +01001256 int up = qdict_get_bool(qdict, "up");
aliguori436e5e52009-01-08 19:44:06 +00001257
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001258 QTAILQ_FOREACH(vlan, &vlans, next) {
1259 QTAILQ_FOREACH(vc, &vlan->clients, next) {
1260 if (strcmp(vc->name, name) == 0) {
edgar_igldd5de372009-01-09 00:48:28 +00001261 goto done;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001262 }
1263 }
1264 }
Markus Armbruster2583ba92010-02-11 14:45:02 +01001265 vc = qemu_find_netdev(name);
edgar_igldd5de372009-01-09 00:48:28 +00001266done:
aliguori436e5e52009-01-08 19:44:06 +00001267
1268 if (!vc) {
Markus Armbruster5369e3c2010-03-26 09:07:11 +01001269 qerror_report(QERR_DEVICE_NOT_FOUND, name);
1270 return -1;
aliguori436e5e52009-01-08 19:44:06 +00001271 }
1272
Markus Armbrusterc9b26a42010-03-26 09:07:10 +01001273 vc->link_down = !up;
aliguori436e5e52009-01-08 19:44:06 +00001274
Mark McLoughlin665a3b02009-11-25 18:49:30 +00001275 if (vc->info->link_status_changed) {
1276 vc->info->link_status_changed(vc);
1277 }
Michael S. Tsirkinab1cbe12011-02-09 18:45:04 +02001278
1279 /* Notify peer. Don't update peer link status: this makes it possible to
1280 * disconnect from host network without notifying the guest.
1281 * FIXME: is disconnected link status change operation useful?
1282 *
1283 * Current behaviour is compatible with qemu vlans where there could be
1284 * multiple clients that can still communicate with each other in
1285 * disconnected mode. For now maintain this compatibility. */
1286 if (vc->peer && vc->peer->info->link_status_changed) {
1287 vc->peer->info->link_status_changed(vc->peer);
1288 }
Markus Armbruster5369e3c2010-03-26 09:07:11 +01001289 return 0;
aliguori436e5e52009-01-08 19:44:06 +00001290}
1291
aliguori63a01ef2008-10-31 19:10:00 +00001292void net_cleanup(void)
1293{
1294 VLANState *vlan;
Mark McLoughlin577c4af2009-10-08 19:58:28 +01001295 VLANClientState *vc, *next_vc;
aliguori63a01ef2008-10-31 19:10:00 +00001296
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001297 QTAILQ_FOREACH(vlan, &vlans, next) {
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001298 QTAILQ_FOREACH_SAFE(vc, &vlan->clients, next, next_vc) {
aliguorib946a152009-04-17 17:11:08 +00001299 qemu_del_vlan_client(vc);
aliguori63a01ef2008-10-31 19:10:00 +00001300 }
1301 }
Mark McLoughlin577c4af2009-10-08 19:58:28 +01001302
1303 QTAILQ_FOREACH_SAFE(vc, &non_vlan_clients, next, next_vc) {
1304 qemu_del_vlan_client(vc);
1305 }
aliguori63a01ef2008-10-31 19:10:00 +00001306}
1307
Markus Armbruster668680f2010-02-11 14:44:58 +01001308void net_check_clients(void)
aliguori63a01ef2008-10-31 19:10:00 +00001309{
1310 VLANState *vlan;
Markus Armbruster62112d12010-02-11 14:44:59 +01001311 VLANClientState *vc;
Peter Maydell48e2faf2011-05-20 16:50:01 +01001312 int i;
aliguori63a01ef2008-10-31 19:10:00 +00001313
Peter Maydell641f6ea2011-05-20 16:50:00 +01001314 /* Don't warn about the default network setup that you get if
1315 * no command line -net or -netdev options are specified. There
1316 * are two cases that we would otherwise complain about:
1317 * (1) board doesn't support a NIC but the implicit "-net nic"
1318 * requested one
1319 * (2) CONFIG_SLIRP not set, in which case the implicit "-net nic"
1320 * sets up a nic that isn't connected to anything.
1321 */
1322 if (default_net) {
1323 return;
1324 }
1325
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001326 QTAILQ_FOREACH(vlan, &vlans, next) {
Tristan Gingoldac60cc12011-03-15 14:20:54 +01001327 int has_nic = 0, has_host_dev = 0;
1328
Markus Armbruster62112d12010-02-11 14:44:59 +01001329 QTAILQ_FOREACH(vc, &vlan->clients, next) {
1330 switch (vc->info->type) {
1331 case NET_CLIENT_TYPE_NIC:
1332 has_nic = 1;
1333 break;
1334 case NET_CLIENT_TYPE_SLIRP:
1335 case NET_CLIENT_TYPE_TAP:
1336 case NET_CLIENT_TYPE_SOCKET:
1337 case NET_CLIENT_TYPE_VDE:
1338 has_host_dev = 1;
1339 break;
1340 default: ;
1341 }
1342 }
1343 if (has_host_dev && !has_nic)
aliguori63a01ef2008-10-31 19:10:00 +00001344 fprintf(stderr, "Warning: vlan %d with no nics\n", vlan->id);
Markus Armbruster62112d12010-02-11 14:44:59 +01001345 if (has_nic && !has_host_dev)
aliguori63a01ef2008-10-31 19:10:00 +00001346 fprintf(stderr,
1347 "Warning: vlan %d is not connected to host network\n",
1348 vlan->id);
1349 }
Markus Armbrusterefe32fd2010-02-11 14:45:00 +01001350 QTAILQ_FOREACH(vc, &non_vlan_clients, next) {
1351 if (!vc->peer) {
1352 fprintf(stderr, "Warning: %s %s has no peer\n",
1353 vc->info->type == NET_CLIENT_TYPE_NIC ? "nic" : "netdev",
1354 vc->name);
1355 }
1356 }
Peter Maydell48e2faf2011-05-20 16:50:01 +01001357
1358 /* Check that all NICs requested via -net nic actually got created.
1359 * NICs created via -device don't need to be checked here because
1360 * they are always instantiated.
1361 */
1362 for (i = 0; i < MAX_NICS; i++) {
1363 NICInfo *nd = &nd_table[i];
1364 if (nd->used && !nd->instantiated) {
1365 fprintf(stderr, "Warning: requested NIC (%s, model %s) "
1366 "was not created (not supported by this machine?)\n",
1367 nd->name ? nd->name : "anonymous",
1368 nd->model ? nd->model : "unspecified");
1369 }
1370 }
aliguori63a01ef2008-10-31 19:10:00 +00001371}
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001372
1373static int net_init_client(QemuOpts *opts, void *dummy)
1374{
Mark McLoughlinc1671a02009-10-12 09:52:00 +01001375 if (net_client_init(NULL, opts, 0) < 0)
1376 return -1;
1377 return 0;
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001378}
1379
1380static int net_init_netdev(QemuOpts *opts, void *dummy)
1381{
1382 return net_client_init(NULL, opts, 1);
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001383}
1384
1385int net_init_clients(void)
1386{
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001387 QemuOptsList *net = qemu_find_opts("net");
1388
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01001389 if (default_net) {
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001390 /* if no clients, we use a default config */
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001391 qemu_opts_set(net, NULL, "type", "nic");
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001392#ifdef CONFIG_SLIRP
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001393 qemu_opts_set(net, NULL, "type", "user");
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001394#endif
1395 }
1396
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001397 QTAILQ_INIT(&vlans);
Mark McLoughlin577c4af2009-10-08 19:58:28 +01001398 QTAILQ_INIT(&non_vlan_clients);
Mark McLoughlin5610c3a2009-10-08 19:58:23 +01001399
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001400 if (qemu_opts_foreach(qemu_find_opts("netdev"), net_init_netdev, NULL, 1) == -1)
Mark McLoughlinf6b134a2009-10-08 19:58:27 +01001401 return -1;
1402
Gerd Hoffmann3329f072010-08-20 13:52:01 +02001403 if (qemu_opts_foreach(net, net_init_client, NULL, 1) == -1) {
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001404 return -1;
1405 }
1406
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001407 return 0;
1408}
1409
Mark McLoughlin7f161aa2009-10-08 19:58:25 +01001410int net_client_parse(QemuOptsList *opts_list, const char *optarg)
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001411{
Juan Quintelaa3a766e2009-10-07 23:44:15 +02001412#if defined(CONFIG_SLIRP)
Mark McLoughlin68ac40d2009-11-25 18:48:54 +00001413 int ret;
1414 if (net_slirp_parse_legacy(opts_list, optarg, &ret)) {
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001415 return ret;
1416 }
Juan Quintelaa3a766e2009-10-07 23:44:15 +02001417#endif
Mark McLoughlin68ac40d2009-11-25 18:48:54 +00001418
Markus Armbruster8212c642010-02-10 19:52:18 +01001419 if (!qemu_opts_parse(opts_list, optarg, 1)) {
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001420 return -1;
1421 }
1422
Gerd Hoffmanncb4522c2009-12-08 13:11:47 +01001423 default_net = 0;
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +01001424 return 0;
1425}