]> git.proxmox.com Git - qemu.git/blob - hw/virtio-net.c
virtio-net: Fix MAC filter overflow handling
[qemu.git] / hw / virtio-net.c
1 /*
2 * Virtio Network Device
3 *
4 * Copyright IBM, Corp. 2007
5 *
6 * Authors:
7 * Anthony Liguori <aliguori@us.ibm.com>
8 *
9 * This work is licensed under the terms of the GNU GPL, version 2. See
10 * the COPYING file in the top-level directory.
11 *
12 */
13
14 #include "virtio.h"
15 #include "net.h"
16 #include "qemu-timer.h"
17 #include "virtio-net.h"
18
19 #define VIRTIO_NET_VM_VERSION 9
20
21 #define MAC_TABLE_ENTRIES 32
22 #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */
23
24 typedef struct VirtIONet
25 {
26 VirtIODevice vdev;
27 uint8_t mac[ETH_ALEN];
28 uint16_t status;
29 VirtQueue *rx_vq;
30 VirtQueue *tx_vq;
31 VirtQueue *ctrl_vq;
32 VLANClientState *vc;
33 QEMUTimer *tx_timer;
34 int tx_timer_active;
35 int mergeable_rx_bufs;
36 uint8_t promisc;
37 uint8_t allmulti;
38 struct {
39 int in_use;
40 uint8_t multi_overflow;
41 uint8_t uni_overflow;
42 uint8_t *macs;
43 } mac_table;
44 uint32_t *vlans;
45 } VirtIONet;
46
47 /* TODO
48 * - we could suppress RX interrupt if we were so inclined.
49 */
50
51 static VirtIONet *to_virtio_net(VirtIODevice *vdev)
52 {
53 return (VirtIONet *)vdev;
54 }
55
56 static void virtio_net_get_config(VirtIODevice *vdev, uint8_t *config)
57 {
58 VirtIONet *n = to_virtio_net(vdev);
59 struct virtio_net_config netcfg;
60
61 netcfg.status = n->status;
62 memcpy(netcfg.mac, n->mac, ETH_ALEN);
63 memcpy(config, &netcfg, sizeof(netcfg));
64 }
65
66 static void virtio_net_set_config(VirtIODevice *vdev, const uint8_t *config)
67 {
68 VirtIONet *n = to_virtio_net(vdev);
69 struct virtio_net_config netcfg;
70
71 memcpy(&netcfg, config, sizeof(netcfg));
72
73 if (memcmp(netcfg.mac, n->mac, ETH_ALEN)) {
74 memcpy(n->mac, netcfg.mac, ETH_ALEN);
75 qemu_format_nic_info_str(n->vc, n->mac);
76 }
77 }
78
79 static void virtio_net_set_link_status(VLANClientState *vc)
80 {
81 VirtIONet *n = vc->opaque;
82 uint16_t old_status = n->status;
83
84 if (vc->link_down)
85 n->status &= ~VIRTIO_NET_S_LINK_UP;
86 else
87 n->status |= VIRTIO_NET_S_LINK_UP;
88
89 if (n->status != old_status)
90 virtio_notify_config(&n->vdev);
91 }
92
93 static void virtio_net_reset(VirtIODevice *vdev)
94 {
95 VirtIONet *n = to_virtio_net(vdev);
96
97 /* Reset back to compatibility mode */
98 n->promisc = 1;
99 n->allmulti = 0;
100
101 /* Flush any MAC and VLAN filter table state */
102 n->mac_table.in_use = 0;
103 n->mac_table.multi_overflow = 0;
104 n->mac_table.uni_overflow = 0;
105 memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
106 memset(n->vlans, 0, MAX_VLAN >> 3);
107 }
108
109 static uint32_t virtio_net_get_features(VirtIODevice *vdev)
110 {
111 uint32_t features = (1 << VIRTIO_NET_F_MAC) |
112 (1 << VIRTIO_NET_F_STATUS) |
113 (1 << VIRTIO_NET_F_CTRL_VQ) |
114 (1 << VIRTIO_NET_F_CTRL_RX) |
115 (1 << VIRTIO_NET_F_CTRL_VLAN);
116
117 return features;
118 }
119
120 static uint32_t virtio_net_bad_features(VirtIODevice *vdev)
121 {
122 uint32_t features = 0;
123
124 /* Linux kernel 2.6.25. It understood MAC (as everyone must),
125 * but also these: */
126 features |= (1 << VIRTIO_NET_F_MAC);
127 features |= (1 << VIRTIO_NET_F_GUEST_CSUM);
128 features |= (1 << VIRTIO_NET_F_GUEST_TSO4);
129 features |= (1 << VIRTIO_NET_F_GUEST_TSO6);
130 features |= (1 << VIRTIO_NET_F_GUEST_ECN);
131
132 return features & virtio_net_get_features(vdev);
133 }
134
135 static void virtio_net_set_features(VirtIODevice *vdev, uint32_t features)
136 {
137 VirtIONet *n = to_virtio_net(vdev);
138
139 n->mergeable_rx_bufs = !!(features & (1 << VIRTIO_NET_F_MRG_RXBUF));
140 }
141
142 static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
143 VirtQueueElement *elem)
144 {
145 uint8_t on;
146
147 if (elem->out_num != 2 || elem->out_sg[1].iov_len != sizeof(on)) {
148 fprintf(stderr, "virtio-net ctrl invalid rx mode command\n");
149 exit(1);
150 }
151
152 on = ldub_p(elem->out_sg[1].iov_base);
153
154 if (cmd == VIRTIO_NET_CTRL_RX_MODE_PROMISC)
155 n->promisc = on;
156 else if (cmd == VIRTIO_NET_CTRL_RX_MODE_ALLMULTI)
157 n->allmulti = on;
158 else
159 return VIRTIO_NET_ERR;
160
161 return VIRTIO_NET_OK;
162 }
163
164 static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
165 VirtQueueElement *elem)
166 {
167 struct virtio_net_ctrl_mac mac_data;
168
169 if (cmd != VIRTIO_NET_CTRL_MAC_TABLE_SET || elem->out_num != 3 ||
170 elem->out_sg[1].iov_len < sizeof(mac_data) ||
171 elem->out_sg[2].iov_len < sizeof(mac_data))
172 return VIRTIO_NET_ERR;
173
174 n->mac_table.in_use = 0;
175 n->mac_table.uni_overflow = 0;
176 n->mac_table.multi_overflow = 0;
177 memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
178
179 mac_data.entries = ldl_le_p(elem->out_sg[1].iov_base);
180
181 if (sizeof(mac_data.entries) +
182 (mac_data.entries * ETH_ALEN) > elem->out_sg[1].iov_len)
183 return VIRTIO_NET_ERR;
184
185 if (mac_data.entries <= MAC_TABLE_ENTRIES) {
186 memcpy(n->mac_table.macs, elem->out_sg[1].iov_base + sizeof(mac_data),
187 mac_data.entries * ETH_ALEN);
188 n->mac_table.in_use += mac_data.entries;
189 } else {
190 n->mac_table.uni_overflow = 1;
191 }
192
193 mac_data.entries = ldl_le_p(elem->out_sg[2].iov_base);
194
195 if (sizeof(mac_data.entries) +
196 (mac_data.entries * ETH_ALEN) > elem->out_sg[2].iov_len)
197 return VIRTIO_NET_ERR;
198
199 if (mac_data.entries) {
200 if (n->mac_table.in_use + mac_data.entries <= MAC_TABLE_ENTRIES) {
201 memcpy(n->mac_table.macs + (n->mac_table.in_use * ETH_ALEN),
202 elem->out_sg[2].iov_base + sizeof(mac_data),
203 mac_data.entries * ETH_ALEN);
204 n->mac_table.in_use += mac_data.entries;
205 } else {
206 n->mac_table.multi_overflow = 1;
207 }
208 }
209
210 return VIRTIO_NET_OK;
211 }
212
213 static int virtio_net_handle_vlan_table(VirtIONet *n, uint8_t cmd,
214 VirtQueueElement *elem)
215 {
216 uint16_t vid;
217
218 if (elem->out_num != 2 || elem->out_sg[1].iov_len != sizeof(vid)) {
219 fprintf(stderr, "virtio-net ctrl invalid vlan command\n");
220 return VIRTIO_NET_ERR;
221 }
222
223 vid = lduw_le_p(elem->out_sg[1].iov_base);
224
225 if (vid >= MAX_VLAN)
226 return VIRTIO_NET_ERR;
227
228 if (cmd == VIRTIO_NET_CTRL_VLAN_ADD)
229 n->vlans[vid >> 5] |= (1U << (vid & 0x1f));
230 else if (cmd == VIRTIO_NET_CTRL_VLAN_DEL)
231 n->vlans[vid >> 5] &= ~(1U << (vid & 0x1f));
232 else
233 return VIRTIO_NET_ERR;
234
235 return VIRTIO_NET_OK;
236 }
237
238 static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
239 {
240 VirtIONet *n = to_virtio_net(vdev);
241 struct virtio_net_ctrl_hdr ctrl;
242 virtio_net_ctrl_ack status = VIRTIO_NET_ERR;
243 VirtQueueElement elem;
244
245 while (virtqueue_pop(vq, &elem)) {
246 if ((elem.in_num < 1) || (elem.out_num < 1)) {
247 fprintf(stderr, "virtio-net ctrl missing headers\n");
248 exit(1);
249 }
250
251 if (elem.out_sg[0].iov_len < sizeof(ctrl) ||
252 elem.in_sg[elem.in_num - 1].iov_len < sizeof(status)) {
253 fprintf(stderr, "virtio-net ctrl header not in correct element\n");
254 exit(1);
255 }
256
257 ctrl.class = ldub_p(elem.out_sg[0].iov_base);
258 ctrl.cmd = ldub_p(elem.out_sg[0].iov_base + sizeof(ctrl.class));
259
260 if (ctrl.class == VIRTIO_NET_CTRL_RX_MODE)
261 status = virtio_net_handle_rx_mode(n, ctrl.cmd, &elem);
262 else if (ctrl.class == VIRTIO_NET_CTRL_MAC)
263 status = virtio_net_handle_mac(n, ctrl.cmd, &elem);
264 else if (ctrl.class == VIRTIO_NET_CTRL_VLAN)
265 status = virtio_net_handle_vlan_table(n, ctrl.cmd, &elem);
266
267 stb_p(elem.in_sg[elem.in_num - 1].iov_base, status);
268
269 virtqueue_push(vq, &elem, sizeof(status));
270 virtio_notify(vdev, vq);
271 }
272 }
273
274 /* RX */
275
276 static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
277 {
278 VirtIONet *n = to_virtio_net(vdev);
279
280 qemu_flush_queued_packets(n->vc);
281 }
282
283 static int do_virtio_net_can_receive(VirtIONet *n, int bufsize)
284 {
285 if (!virtio_queue_ready(n->rx_vq) ||
286 !(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
287 return 0;
288
289 if (virtio_queue_empty(n->rx_vq) ||
290 (n->mergeable_rx_bufs &&
291 !virtqueue_avail_bytes(n->rx_vq, bufsize, 0))) {
292 virtio_queue_set_notification(n->rx_vq, 1);
293 return 0;
294 }
295
296 virtio_queue_set_notification(n->rx_vq, 0);
297 return 1;
298 }
299
300 static int virtio_net_can_receive(VLANClientState *vc)
301 {
302 VirtIONet *n = vc->opaque;
303
304 return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE);
305 }
306
307 static int iov_fill(struct iovec *iov, int iovcnt, const void *buf, int count)
308 {
309 int offset, i;
310
311 offset = i = 0;
312 while (offset < count && i < iovcnt) {
313 int len = MIN(iov[i].iov_len, count - offset);
314 memcpy(iov[i].iov_base, buf + offset, len);
315 offset += len;
316 i++;
317 }
318
319 return offset;
320 }
321
322 static int receive_header(VirtIONet *n, struct iovec *iov, int iovcnt,
323 const void *buf, size_t size, size_t hdr_len)
324 {
325 struct virtio_net_hdr *hdr = (struct virtio_net_hdr *)iov[0].iov_base;
326 int offset = 0;
327
328 hdr->flags = 0;
329 hdr->gso_type = VIRTIO_NET_HDR_GSO_NONE;
330
331 /* We only ever receive a struct virtio_net_hdr from the tapfd,
332 * but we may be passing along a larger header to the guest.
333 */
334 iov[0].iov_base += hdr_len;
335 iov[0].iov_len -= hdr_len;
336
337 return offset;
338 }
339
340 static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
341 {
342 static const uint8_t bcast[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
343 static const uint8_t vlan[] = {0x81, 0x00};
344 uint8_t *ptr = (uint8_t *)buf;
345 int i;
346
347 if (n->promisc)
348 return 1;
349
350 if (!memcmp(&ptr[12], vlan, sizeof(vlan))) {
351 int vid = be16_to_cpup((uint16_t *)(ptr + 14)) & 0xfff;
352 if (!(n->vlans[vid >> 5] & (1U << (vid & 0x1f))))
353 return 0;
354 }
355
356 if (ptr[0] & 1) { // multicast
357 if (!memcmp(ptr, bcast, sizeof(bcast))) {
358 return 1;
359 } else if (n->allmulti || n->mac_table.multi_overflow) {
360 return 1;
361 }
362 } else { // unicast
363 if (n->mac_table.uni_overflow) {
364 return 1;
365 } else if (!memcmp(ptr, n->mac, ETH_ALEN)) {
366 return 1;
367 }
368 }
369
370 for (i = 0; i < n->mac_table.in_use; i++) {
371 if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN))
372 return 1;
373 }
374
375 return 0;
376 }
377
378 static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
379 {
380 VirtIONet *n = vc->opaque;
381 struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
382 size_t hdr_len, offset, i;
383
384 if (!do_virtio_net_can_receive(n, size))
385 return 0;
386
387 if (!receive_filter(n, buf, size))
388 return size;
389
390 /* hdr_len refers to the header we supply to the guest */
391 hdr_len = n->mergeable_rx_bufs ?
392 sizeof(struct virtio_net_hdr_mrg_rxbuf) : sizeof(struct virtio_net_hdr);
393
394 offset = i = 0;
395
396 while (offset < size) {
397 VirtQueueElement elem;
398 int len, total;
399 struct iovec sg[VIRTQUEUE_MAX_SIZE];
400
401 len = total = 0;
402
403 if ((i != 0 && !n->mergeable_rx_bufs) ||
404 virtqueue_pop(n->rx_vq, &elem) == 0) {
405 if (i == 0)
406 return -1;
407 fprintf(stderr, "virtio-net truncating packet\n");
408 exit(1);
409 }
410
411 if (elem.in_num < 1) {
412 fprintf(stderr, "virtio-net receive queue contains no in buffers\n");
413 exit(1);
414 }
415
416 if (!n->mergeable_rx_bufs && elem.in_sg[0].iov_len != hdr_len) {
417 fprintf(stderr, "virtio-net header not in first element\n");
418 exit(1);
419 }
420
421 memcpy(&sg, &elem.in_sg[0], sizeof(sg[0]) * elem.in_num);
422
423 if (i == 0) {
424 if (n->mergeable_rx_bufs)
425 mhdr = (struct virtio_net_hdr_mrg_rxbuf *)sg[0].iov_base;
426
427 offset += receive_header(n, sg, elem.in_num,
428 buf + offset, size - offset, hdr_len);
429 total += hdr_len;
430 }
431
432 /* copy in packet. ugh */
433 len = iov_fill(sg, elem.in_num,
434 buf + offset, size - offset);
435 total += len;
436
437 /* signal other side */
438 virtqueue_fill(n->rx_vq, &elem, total, i++);
439
440 offset += len;
441 }
442
443 if (mhdr)
444 mhdr->num_buffers = i;
445
446 virtqueue_flush(n->rx_vq, i);
447 virtio_notify(&n->vdev, n->rx_vq);
448
449 return size;
450 }
451
452 /* TX */
453 static void virtio_net_flush_tx(VirtIONet *n, VirtQueue *vq)
454 {
455 VirtQueueElement elem;
456 int has_vnet_hdr = 0;
457
458 if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
459 return;
460
461 while (virtqueue_pop(vq, &elem)) {
462 ssize_t len = 0;
463 unsigned int out_num = elem.out_num;
464 struct iovec *out_sg = &elem.out_sg[0];
465 unsigned hdr_len;
466
467 /* hdr_len refers to the header received from the guest */
468 hdr_len = n->mergeable_rx_bufs ?
469 sizeof(struct virtio_net_hdr_mrg_rxbuf) :
470 sizeof(struct virtio_net_hdr);
471
472 if (out_num < 1 || out_sg->iov_len != hdr_len) {
473 fprintf(stderr, "virtio-net header not in first element\n");
474 exit(1);
475 }
476
477 /* ignore the header if GSO is not supported */
478 if (!has_vnet_hdr) {
479 out_num--;
480 out_sg++;
481 len += hdr_len;
482 } else if (n->mergeable_rx_bufs) {
483 /* tapfd expects a struct virtio_net_hdr */
484 hdr_len -= sizeof(struct virtio_net_hdr);
485 out_sg->iov_len -= hdr_len;
486 len += hdr_len;
487 }
488
489 len += qemu_sendv_packet(n->vc, out_sg, out_num);
490
491 virtqueue_push(vq, &elem, len);
492 virtio_notify(&n->vdev, vq);
493 }
494 }
495
496 static void virtio_net_handle_tx(VirtIODevice *vdev, VirtQueue *vq)
497 {
498 VirtIONet *n = to_virtio_net(vdev);
499
500 if (n->tx_timer_active) {
501 virtio_queue_set_notification(vq, 1);
502 qemu_del_timer(n->tx_timer);
503 n->tx_timer_active = 0;
504 virtio_net_flush_tx(n, vq);
505 } else {
506 qemu_mod_timer(n->tx_timer,
507 qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
508 n->tx_timer_active = 1;
509 virtio_queue_set_notification(vq, 0);
510 }
511 }
512
513 static void virtio_net_tx_timer(void *opaque)
514 {
515 VirtIONet *n = opaque;
516
517 n->tx_timer_active = 0;
518
519 /* Just in case the driver is not ready on more */
520 if (!(n->vdev.status & VIRTIO_CONFIG_S_DRIVER_OK))
521 return;
522
523 virtio_queue_set_notification(n->tx_vq, 1);
524 virtio_net_flush_tx(n, n->tx_vq);
525 }
526
527 static void virtio_net_save(QEMUFile *f, void *opaque)
528 {
529 VirtIONet *n = opaque;
530
531 virtio_save(&n->vdev, f);
532
533 qemu_put_buffer(f, n->mac, ETH_ALEN);
534 qemu_put_be32(f, n->tx_timer_active);
535 qemu_put_be32(f, n->mergeable_rx_bufs);
536 qemu_put_be16(f, n->status);
537 qemu_put_byte(f, n->promisc);
538 qemu_put_byte(f, n->allmulti);
539 qemu_put_be32(f, n->mac_table.in_use);
540 qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN);
541 qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
542 qemu_put_be32(f, 0); /* vnet-hdr placeholder */
543 qemu_put_byte(f, n->mac_table.multi_overflow);
544 qemu_put_byte(f, n->mac_table.uni_overflow);
545 }
546
547 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
548 {
549 VirtIONet *n = opaque;
550
551 if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
552 return -EINVAL;
553
554 virtio_load(&n->vdev, f);
555
556 qemu_get_buffer(f, n->mac, ETH_ALEN);
557 n->tx_timer_active = qemu_get_be32(f);
558 n->mergeable_rx_bufs = qemu_get_be32(f);
559
560 if (version_id >= 3)
561 n->status = qemu_get_be16(f);
562
563 if (version_id >= 4) {
564 if (version_id < 8) {
565 n->promisc = qemu_get_be32(f);
566 n->allmulti = qemu_get_be32(f);
567 } else {
568 n->promisc = qemu_get_byte(f);
569 n->allmulti = qemu_get_byte(f);
570 }
571 }
572
573 if (version_id >= 5) {
574 n->mac_table.in_use = qemu_get_be32(f);
575 /* MAC_TABLE_ENTRIES may be different from the saved image */
576 if (n->mac_table.in_use <= MAC_TABLE_ENTRIES) {
577 qemu_get_buffer(f, n->mac_table.macs,
578 n->mac_table.in_use * ETH_ALEN);
579 } else if (n->mac_table.in_use) {
580 qemu_fseek(f, n->mac_table.in_use * ETH_ALEN, SEEK_CUR);
581 n->mac_table.multi_overflow = n->mac_table.uni_overflow = 1;
582 n->mac_table.in_use = 0;
583 }
584 }
585
586 if (version_id >= 6)
587 qemu_get_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
588
589 if (version_id >= 7 && qemu_get_be32(f)) {
590 fprintf(stderr,
591 "virtio-net: saved image requires vnet header support\n");
592 exit(1);
593 }
594
595 if (version_id >= 9) {
596 n->mac_table.multi_overflow = qemu_get_byte(f);
597 n->mac_table.uni_overflow = qemu_get_byte(f);
598 }
599
600 if (n->tx_timer_active) {
601 qemu_mod_timer(n->tx_timer,
602 qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
603 }
604
605 return 0;
606 }
607
608 static void virtio_net_cleanup(VLANClientState *vc)
609 {
610 VirtIONet *n = vc->opaque;
611
612 unregister_savevm("virtio-net", n);
613
614 qemu_free(n->mac_table.macs);
615 qemu_free(n->vlans);
616
617 qemu_del_timer(n->tx_timer);
618 qemu_free_timer(n->tx_timer);
619
620 virtio_cleanup(&n->vdev);
621 }
622
623 VirtIODevice *virtio_net_init(DeviceState *dev)
624 {
625 VirtIONet *n;
626 static int virtio_net_id;
627
628 n = (VirtIONet *)virtio_common_init("virtio-net", VIRTIO_ID_NET,
629 sizeof(struct virtio_net_config),
630 sizeof(VirtIONet));
631
632 n->vdev.get_config = virtio_net_get_config;
633 n->vdev.set_config = virtio_net_set_config;
634 n->vdev.get_features = virtio_net_get_features;
635 n->vdev.set_features = virtio_net_set_features;
636 n->vdev.bad_features = virtio_net_bad_features;
637 n->vdev.reset = virtio_net_reset;
638 n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
639 n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
640 n->ctrl_vq = virtio_add_queue(&n->vdev, 16, virtio_net_handle_ctrl);
641 qdev_get_macaddr(dev, n->mac);
642 n->status = VIRTIO_NET_S_LINK_UP;
643 n->vc = qdev_get_vlan_client(dev,
644 virtio_net_can_receive,
645 virtio_net_receive, NULL,
646 virtio_net_cleanup, n);
647 n->vc->link_status_changed = virtio_net_set_link_status;
648
649 qemu_format_nic_info_str(n->vc, n->mac);
650
651 n->tx_timer = qemu_new_timer(vm_clock, virtio_net_tx_timer, n);
652 n->tx_timer_active = 0;
653 n->mergeable_rx_bufs = 0;
654 n->promisc = 1; /* for compatibility */
655
656 n->mac_table.macs = qemu_mallocz(MAC_TABLE_ENTRIES * ETH_ALEN);
657
658 n->vlans = qemu_mallocz(MAX_VLAN >> 3);
659
660 register_savevm("virtio-net", virtio_net_id++, VIRTIO_NET_VM_VERSION,
661 virtio_net_save, virtio_net_load, n);
662
663 return &n->vdev;
664 }