Commit f8e76fbf5190575c0f927fe3c5b0ec6934c6c3fc

Authored by Anthony Liguori
2 parents b319820d 4ffb17f5

Merge branch 'net-queue'

* net-queue: (28 commits)
  virtio-net: Increase filter and control limits
  virtio-net: Add new RX filter controls
  virtio-net: MAC filter optimization
  virtio-net: Fix MAC filter overflow handling
  virtio-net: reorganize receive_filter()
  virtio-net: Use a byte to store RX mode flags
  virtio-net: Add version_id 7 placeholder for vnet header support
  virtio-net: implement rx packet queueing
  net: make use of async packet sending API in tap client
  net: add qemu_send_packet_async()
  net: split out packet queueing and flushing into separate functions
  net: return status from qemu_deliver_packet()
  net: add return value to packet receive handler
  net: pass VLANClientState* as first arg to receive handlers
  net: re-name vc->fd_read() to vc->receive()
  net: add fd_readv() handler to qemu_new_vlan_client() args
  net: only read from tapfd when we can send
  net: vlan clients with no fd_can_read() can always receive
  net: move the tap buffer into TAPState
  net: factor tap_read_packet() out of tap_send()
  ...

Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
hw/dp8393x.c
@@ -407,9 +407,9 @@ static void do_transmit_packets(dp8393xState *s) @@ -407,9 +407,9 @@ static void do_transmit_packets(dp8393xState *s)
407 if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) { 407 if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
408 /* Loopback */ 408 /* Loopback */
409 s->regs[SONIC_TCR] |= SONIC_TCR_CRSL; 409 s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
410 - if (s->vc->fd_can_read(s)) { 410 + if (s->vc->can_receive(s->vc)) {
411 s->loopback_packet = 1; 411 s->loopback_packet = 1;
412 - s->vc->fd_read(s, s->tx_buffer, tx_len); 412 + s->vc->receive(s->vc, s->tx_buffer, tx_len);
413 } 413 }
414 } else { 414 } else {
415 /* Transmit packet */ 415 /* Transmit packet */
@@ -676,9 +676,9 @@ static CPUWriteMemoryFunc *dp8393x_write[3] = { @@ -676,9 +676,9 @@ static CPUWriteMemoryFunc *dp8393x_write[3] = {
676 dp8393x_writel, 676 dp8393x_writel,
677 }; 677 };
678 678
679 -static int nic_can_receive(void *opaque) 679 +static int nic_can_receive(VLANClientState *vc)
680 { 680 {
681 - dp8393xState *s = opaque; 681 + dp8393xState *s = vc->opaque;
682 682
683 if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) 683 if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN))
684 return 0; 684 return 0;
@@ -725,10 +725,10 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size) @@ -725,10 +725,10 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size)
725 return -1; 725 return -1;
726 } 726 }
727 727
728 -static void nic_receive(void *opaque, const uint8_t * buf, int size) 728 +static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
729 { 729 {
730 uint16_t data[10]; 730 uint16_t data[10];
731 - dp8393xState *s = opaque; 731 + dp8393xState *s = vc->opaque;
732 int packet_type; 732 int packet_type;
733 uint32_t available, address; 733 uint32_t available, address;
734 int width, rx_len = size; 734 int width, rx_len = size;
@@ -742,7 +742,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -742,7 +742,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
742 packet_type = receive_filter(s, buf, size); 742 packet_type = receive_filter(s, buf, size);
743 if (packet_type < 0) { 743 if (packet_type < 0) {
744 DPRINTF("packet not for netcard\n"); 744 DPRINTF("packet not for netcard\n");
745 - return; 745 + return -1;
746 } 746 }
747 747
748 /* XXX: Check byte ordering */ 748 /* XXX: Check byte ordering */
@@ -755,7 +755,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -755,7 +755,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
755 s->memory_rw(s->mem_opaque, address, (uint8_t*)data, size, 0); 755 s->memory_rw(s->mem_opaque, address, (uint8_t*)data, size, 0);
756 if (data[0 * width] & 0x1) { 756 if (data[0 * width] & 0x1) {
757 /* Still EOL ; stop reception */ 757 /* Still EOL ; stop reception */
758 - return; 758 + return -1;
759 } else { 759 } else {
760 s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA]; 760 s->regs[SONIC_CRDA] = s->regs[SONIC_LLFA];
761 } 761 }
@@ -833,6 +833,8 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -833,6 +833,8 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
833 833
834 /* Done */ 834 /* Done */
835 dp8393x_update_irq(s); 835 dp8393x_update_irq(s);
  836 +
  837 + return size;
836 } 838 }
837 839
838 static void nic_reset(void *opaque) 840 static void nic_reset(void *opaque)
@@ -888,8 +890,8 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift, @@ -888,8 +890,8 @@ void dp83932_init(NICInfo *nd, target_phys_addr_t base, int it_shift,
888 s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s); 890 s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s);
889 s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */ 891 s->regs[SONIC_SR] = 0x0004; /* only revision recognized by Linux */
890 892
891 - s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,  
892 - nic_receive, nic_can_receive, nic_cleanup, s); 893 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, nic_can_receive,
  894 + nic_receive, NULL, nic_cleanup, s);
893 895
894 qemu_format_nic_info_str(s->vc, nd->macaddr); 896 qemu_format_nic_info_str(s->vc, nd->macaddr);
895 qemu_register_reset(nic_reset, 0, s); 897 qemu_register_reset(nic_reset, 0, s);
hw/e1000.c
@@ -598,17 +598,17 @@ e1000_set_link_status(VLANClientState *vc) @@ -598,17 +598,17 @@ e1000_set_link_status(VLANClientState *vc)
598 } 598 }
599 599
600 static int 600 static int
601 -e1000_can_receive(void *opaque) 601 +e1000_can_receive(VLANClientState *vc)
602 { 602 {
603 - E1000State *s = opaque; 603 + E1000State *s = vc->opaque;
604 604
605 return (s->mac_reg[RCTL] & E1000_RCTL_EN); 605 return (s->mac_reg[RCTL] & E1000_RCTL_EN);
606 } 606 }
607 607
608 -static void  
609 -e1000_receive(void *opaque, const uint8_t *buf, int size) 608 +static ssize_t
  609 +e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
610 { 610 {
611 - E1000State *s = opaque; 611 + E1000State *s = vc->opaque;
612 struct e1000_rx_desc desc; 612 struct e1000_rx_desc desc;
613 target_phys_addr_t base; 613 target_phys_addr_t base;
614 unsigned int n, rdt; 614 unsigned int n, rdt;
@@ -617,16 +617,16 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) @@ -617,16 +617,16 @@ e1000_receive(void *opaque, const uint8_t *buf, int size)
617 uint8_t vlan_status = 0, vlan_offset = 0; 617 uint8_t vlan_status = 0, vlan_offset = 0;
618 618
619 if (!(s->mac_reg[RCTL] & E1000_RCTL_EN)) 619 if (!(s->mac_reg[RCTL] & E1000_RCTL_EN))
620 - return; 620 + return -1;
621 621
622 if (size > s->rxbuf_size) { 622 if (size > s->rxbuf_size) {
623 - DBGOUT(RX, "packet too large for buffers (%d > %d)\n", size,  
624 - s->rxbuf_size);  
625 - return; 623 + DBGOUT(RX, "packet too large for buffers (%lu > %d)\n",
  624 + (unsigned long)size, s->rxbuf_size);
  625 + return -1;
626 } 626 }
627 627
628 if (!receive_filter(s, buf, size)) 628 if (!receive_filter(s, buf, size))
629 - return; 629 + return size;
630 630
631 if (vlan_enabled(s) && is_vlan_packet(s, buf)) { 631 if (vlan_enabled(s) && is_vlan_packet(s, buf)) {
632 vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14))); 632 vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14)));
@@ -641,7 +641,7 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) @@ -641,7 +641,7 @@ e1000_receive(void *opaque, const uint8_t *buf, int size)
641 do { 641 do {
642 if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) { 642 if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) {
643 set_ics(s, 0, E1000_ICS_RXO); 643 set_ics(s, 0, E1000_ICS_RXO);
644 - return; 644 + return -1;
645 } 645 }
646 base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] + 646 base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] +
647 sizeof(desc) * s->mac_reg[RDH]; 647 sizeof(desc) * s->mac_reg[RDH];
@@ -665,7 +665,7 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) @@ -665,7 +665,7 @@ e1000_receive(void *opaque, const uint8_t *buf, int size)
665 DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n", 665 DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n",
666 rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]); 666 rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]);
667 set_ics(s, 0, E1000_ICS_RXO); 667 set_ics(s, 0, E1000_ICS_RXO);
668 - return; 668 + return -1;
669 } 669 }
670 } while (desc.buffer_addr == 0); 670 } while (desc.buffer_addr == 0);
671 671
@@ -683,6 +683,8 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) @@ -683,6 +683,8 @@ e1000_receive(void *opaque, const uint8_t *buf, int size)
683 n |= E1000_ICS_RXDMT0; 683 n |= E1000_ICS_RXDMT0;
684 684
685 set_ics(s, 0, n); 685 set_ics(s, 0, n);
  686 +
  687 + return size;
686 } 688 }
687 689
688 static uint32_t 690 static uint32_t
@@ -1119,8 +1121,8 @@ static void pci_e1000_init(PCIDevice *pci_dev) @@ -1119,8 +1121,8 @@ static void pci_e1000_init(PCIDevice *pci_dev)
1119 d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum; 1121 d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum;
1120 1122
1121 d->vc = qdev_get_vlan_client(&d->dev.qdev, 1123 d->vc = qdev_get_vlan_client(&d->dev.qdev,
1122 - e1000_receive, e1000_can_receive,  
1123 - e1000_cleanup, d); 1124 + e1000_can_receive, e1000_receive,
  1125 + NULL, e1000_cleanup, d);
1124 d->vc->link_status_changed = e1000_set_link_status; 1126 d->vc->link_status_changed = e1000_set_link_status;
1125 1127
1126 qemu_format_nic_info_str(d->vc, macaddr); 1128 qemu_format_nic_info_str(d->vc, macaddr);
hw/eepro100.c
@@ -1433,21 +1433,21 @@ static void pci_mmio_map(PCIDevice * pci_dev, int region_num, @@ -1433,21 +1433,21 @@ static void pci_mmio_map(PCIDevice * pci_dev, int region_num,
1433 } 1433 }
1434 } 1434 }
1435 1435
1436 -static int nic_can_receive(void *opaque) 1436 +static int nic_can_receive(VLANClientState *vc)
1437 { 1437 {
1438 - EEPRO100State *s = opaque; 1438 + EEPRO100State *s = vc->opaque;
1439 logout("%p\n", s); 1439 logout("%p\n", s);
1440 return get_ru_state(s) == ru_ready; 1440 return get_ru_state(s) == ru_ready;
1441 //~ return !eepro100_buffer_full(s); 1441 //~ return !eepro100_buffer_full(s);
1442 } 1442 }
1443 1443
1444 -static void nic_receive(void *opaque, const uint8_t * buf, int size) 1444 +static ssize_t nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
1445 { 1445 {
1446 /* TODO: 1446 /* TODO:
1447 * - Magic packets should set bit 30 in power management driver register. 1447 * - Magic packets should set bit 30 in power management driver register.
1448 * - Interesting packets should set bit 29 in power management driver register. 1448 * - Interesting packets should set bit 29 in power management driver register.
1449 */ 1449 */
1450 - EEPRO100State *s = opaque; 1450 + EEPRO100State *s = vc->opaque;
1451 uint16_t rfd_status = 0xa000; 1451 uint16_t rfd_status = 0xa000;
1452 static const uint8_t broadcast_macaddr[6] = 1452 static const uint8_t broadcast_macaddr[6] =
1453 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 1453 { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
@@ -1458,18 +1458,18 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -1458,18 +1458,18 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
1458 if (s->configuration[8] & 0x80) { 1458 if (s->configuration[8] & 0x80) {
1459 /* CSMA is disabled. */ 1459 /* CSMA is disabled. */
1460 logout("%p received while CSMA is disabled\n", s); 1460 logout("%p received while CSMA is disabled\n", s);
1461 - return; 1461 + return -1;
1462 } else if (size < 64 && (s->configuration[7] & 1)) { 1462 } else if (size < 64 && (s->configuration[7] & 1)) {
1463 /* Short frame and configuration byte 7/0 (discard short receive) set: 1463 /* Short frame and configuration byte 7/0 (discard short receive) set:
1464 * Short frame is discarded */ 1464 * Short frame is discarded */
1465 logout("%p received short frame (%d byte)\n", s, size); 1465 logout("%p received short frame (%d byte)\n", s, size);
1466 s->statistics.rx_short_frame_errors++; 1466 s->statistics.rx_short_frame_errors++;
1467 - //~ return; 1467 + //~ return -1;
1468 } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) { 1468 } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) {
1469 /* Long frame and configuration byte 18/3 (long receive ok) not set: 1469 /* Long frame and configuration byte 18/3 (long receive ok) not set:
1470 * Long frames are discarded. */ 1470 * Long frames are discarded. */
1471 logout("%p received long frame (%d byte), ignored\n", s, size); 1471 logout("%p received long frame (%d byte), ignored\n", s, size);
1472 - return; 1472 + return -1;
1473 } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!! 1473 } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!!
1474 /* Frame matches individual address. */ 1474 /* Frame matches individual address. */
1475 /* TODO: check configuration byte 15/4 (ignore U/L). */ 1475 /* TODO: check configuration byte 15/4 (ignore U/L). */
@@ -1485,7 +1485,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -1485,7 +1485,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
1485 assert(!(s->configuration[21] & BIT(3))); 1485 assert(!(s->configuration[21] & BIT(3)));
1486 int mcast_idx = compute_mcast_idx(buf); 1486 int mcast_idx = compute_mcast_idx(buf);
1487 if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) { 1487 if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) {
1488 - return; 1488 + return size;
1489 } 1489 }
1490 rfd_status |= 0x0002; 1490 rfd_status |= 0x0002;
1491 } else if (s->configuration[15] & 1) { 1491 } else if (s->configuration[15] & 1) {
@@ -1495,7 +1495,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -1495,7 +1495,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
1495 } else { 1495 } else {
1496 logout("%p received frame, ignored, len=%d,%s\n", s, size, 1496 logout("%p received frame, ignored, len=%d,%s\n", s, size,
1497 nic_dump(buf, size)); 1497 nic_dump(buf, size));
1498 - return; 1498 + return size;
1499 } 1499 }
1500 1500
1501 if (get_ru_state(s) != ru_ready) { 1501 if (get_ru_state(s) != ru_ready) {
@@ -1503,7 +1503,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -1503,7 +1503,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
1503 logout("no ressources, state=%u\n", get_ru_state(s)); 1503 logout("no ressources, state=%u\n", get_ru_state(s));
1504 s->statistics.rx_resource_errors++; 1504 s->statistics.rx_resource_errors++;
1505 //~ assert(!"no ressources"); 1505 //~ assert(!"no ressources");
1506 - return; 1506 + return -1;
1507 } 1507 }
1508 //~ !!! 1508 //~ !!!
1509 //~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}} 1509 //~ $3 = {status = 0x0, command = 0xc000, link = 0x2d220, rx_buf_addr = 0x207dc, count = 0x0, size = 0x5f8, packet = {0x0 <repeats 1518 times>}}
@@ -1540,6 +1540,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) @@ -1540,6 +1540,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size)
1540 /* S bit is set. */ 1540 /* S bit is set. */
1541 set_ru_state(s, ru_suspended); 1541 set_ru_state(s, ru_suspended);
1542 } 1542 }
  1543 + return size;
1543 } 1544 }
1544 1545
1545 static int nic_load(QEMUFile * f, void *opaque, int version_id) 1546 static int nic_load(QEMUFile * f, void *opaque, int version_id)
@@ -1766,7 +1767,7 @@ static void nic_init(PCIDevice *pci_dev, uint32_t device) @@ -1766,7 +1767,7 @@ static void nic_init(PCIDevice *pci_dev, uint32_t device)
1766 nic_reset(s); 1767 nic_reset(s);
1767 1768
1768 s->vc = qdev_get_vlan_client(&d->dev.qdev, 1769 s->vc = qdev_get_vlan_client(&d->dev.qdev,
1769 - nic_receive, nic_can_receive, 1770 + nic_can_receive, nic_receive, NULL,
1770 nic_cleanup, s); 1771 nic_cleanup, s);
1771 1772
1772 qemu_format_nic_info_str(s->vc, s->macaddr); 1773 qemu_format_nic_info_str(s->vc, s->macaddr);
hw/etraxfs_eth.c
@@ -496,21 +496,21 @@ static int eth_match_groupaddr(struct fs_eth *eth, const unsigned char *sa) @@ -496,21 +496,21 @@ static int eth_match_groupaddr(struct fs_eth *eth, const unsigned char *sa)
496 return match; 496 return match;
497 } 497 }
498 498
499 -static int eth_can_receive(void *opaque) 499 +static int eth_can_receive(VLANClientState *vc)
500 { 500 {
501 return 1; 501 return 1;
502 } 502 }
503 503
504 -static void eth_receive(void *opaque, const uint8_t *buf, int size) 504 +static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
505 { 505 {
506 unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; 506 unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
507 - struct fs_eth *eth = opaque; 507 + struct fs_eth *eth = vc->opaque;
508 int use_ma0 = eth->regs[RW_REC_CTRL] & 1; 508 int use_ma0 = eth->regs[RW_REC_CTRL] & 1;
509 int use_ma1 = eth->regs[RW_REC_CTRL] & 2; 509 int use_ma1 = eth->regs[RW_REC_CTRL] & 2;
510 int r_bcast = eth->regs[RW_REC_CTRL] & 8; 510 int r_bcast = eth->regs[RW_REC_CTRL] & 8;
511 511
512 if (size < 12) 512 if (size < 12)
513 - return; 513 + return -1;
514 514
515 D(printf("%x.%x.%x.%x.%x.%x ma=%d %d bc=%d\n", 515 D(printf("%x.%x.%x.%x.%x.%x ma=%d %d bc=%d\n",
516 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5], 516 buf[0], buf[1], buf[2], buf[3], buf[4], buf[5],
@@ -521,10 +521,12 @@ static void eth_receive(void *opaque, const uint8_t *buf, int size) @@ -521,10 +521,12 @@ static void eth_receive(void *opaque, const uint8_t *buf, int size)
521 && (!use_ma1 || memcmp(buf, eth->macaddr[1], 6)) 521 && (!use_ma1 || memcmp(buf, eth->macaddr[1], 6))
522 && (!r_bcast || memcmp(buf, sa_bcast, 6)) 522 && (!r_bcast || memcmp(buf, sa_bcast, 6))
523 && !eth_match_groupaddr(eth, buf)) 523 && !eth_match_groupaddr(eth, buf))
524 - return; 524 + return size;
525 525
526 /* FIXME: Find another way to pass on the fake csum. */ 526 /* FIXME: Find another way to pass on the fake csum. */
527 etraxfs_dmac_input(eth->dma_in, (void *)buf, size + 4, 1); 527 etraxfs_dmac_input(eth->dma_in, (void *)buf, size + 4, 1);
  528 +
  529 + return size;
528 } 530 }
529 531
530 static int eth_tx_push(void *opaque, unsigned char *buf, int len) 532 static int eth_tx_push(void *opaque, unsigned char *buf, int len)
@@ -593,7 +595,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env, @@ -593,7 +595,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
593 cpu_register_physical_memory (base, 0x5c, eth->ethregs); 595 cpu_register_physical_memory (base, 0x5c, eth->ethregs);
594 596
595 eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 597 eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
596 - eth_receive, eth_can_receive, 598 + eth_can_receive, eth_receive, NULL,
597 eth_cleanup, eth); 599 eth_cleanup, eth);
598 eth->vc->opaque = eth; 600 eth->vc->opaque = eth;
599 eth->vc->link_status_changed = eth_set_link; 601 eth->vc->link_status_changed = eth_set_link;
hw/mcf_fec.c
@@ -347,15 +347,15 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value) @@ -347,15 +347,15 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
347 mcf_fec_update(s); 347 mcf_fec_update(s);
348 } 348 }
349 349
350 -static int mcf_fec_can_receive(void *opaque) 350 +static int mcf_fec_can_receive(VLANClientState *vc)
351 { 351 {
352 - mcf_fec_state *s = (mcf_fec_state *)opaque; 352 + mcf_fec_state *s = vc->opaque;
353 return s->rx_enabled; 353 return s->rx_enabled;
354 } 354 }
355 355
356 -static void mcf_fec_receive(void *opaque, const uint8_t *buf, int size) 356 +static ssize_t mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
357 { 357 {
358 - mcf_fec_state *s = (mcf_fec_state *)opaque; 358 + mcf_fec_state *s = vc->opaque;
359 mcf_fec_bd bd; 359 mcf_fec_bd bd;
360 uint32_t flags = 0; 360 uint32_t flags = 0;
361 uint32_t addr; 361 uint32_t addr;
@@ -426,6 +426,7 @@ static void mcf_fec_receive(void *opaque, const uint8_t *buf, int size) @@ -426,6 +426,7 @@ static void mcf_fec_receive(void *opaque, const uint8_t *buf, int size)
426 s->rx_descriptor = addr; 426 s->rx_descriptor = addr;
427 mcf_fec_enable_rx(s); 427 mcf_fec_enable_rx(s);
428 mcf_fec_update(s); 428 mcf_fec_update(s);
  429 + return size;
429 } 430 }
430 431
431 static CPUReadMemoryFunc *mcf_fec_readfn[] = { 432 static CPUReadMemoryFunc *mcf_fec_readfn[] = {
@@ -462,7 +463,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq) @@ -462,7 +463,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
462 cpu_register_physical_memory(base, 0x400, s->mmio_index); 463 cpu_register_physical_memory(base, 0x400, s->mmio_index);
463 464
464 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 465 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
465 - mcf_fec_receive, mcf_fec_can_receive, 466 + mcf_fec_can_receive, mcf_fec_receive, NULL,
466 mcf_fec_cleanup, s); 467 mcf_fec_cleanup, s);
467 memcpy(s->macaddr, nd->macaddr, 6); 468 memcpy(s->macaddr, nd->macaddr, 6);
468 qemu_format_nic_info_str(s->vc, s->macaddr); 469 qemu_format_nic_info_str(s->vc, s->macaddr);
hw/mipsnet.c
@@ -66,24 +66,24 @@ static int mipsnet_buffer_full(MIPSnetState *s) @@ -66,24 +66,24 @@ static int mipsnet_buffer_full(MIPSnetState *s)
66 return 0; 66 return 0;
67 } 67 }
68 68
69 -static int mipsnet_can_receive(void *opaque) 69 +static int mipsnet_can_receive(VLANClientState *vc)
70 { 70 {
71 - MIPSnetState *s = opaque; 71 + MIPSnetState *s = vc->opaque;
72 72
73 if (s->busy) 73 if (s->busy)
74 return 0; 74 return 0;
75 return !mipsnet_buffer_full(s); 75 return !mipsnet_buffer_full(s);
76 } 76 }
77 77
78 -static void mipsnet_receive(void *opaque, const uint8_t *buf, int size) 78 +static ssize_t mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
79 { 79 {
80 - MIPSnetState *s = opaque; 80 + MIPSnetState *s = vc->opaque;
81 81
82 #ifdef DEBUG_MIPSNET_RECEIVE 82 #ifdef DEBUG_MIPSNET_RECEIVE
83 printf("mipsnet: receiving len=%d\n", size); 83 printf("mipsnet: receiving len=%d\n", size);
84 #endif 84 #endif
85 - if (!mipsnet_can_receive(opaque))  
86 - return; 85 + if (!mipsnet_can_receive(vc))
  86 + return -1;
87 87
88 s->busy = 1; 88 s->busy = 1;
89 89
@@ -98,6 +98,8 @@ static void mipsnet_receive(void *opaque, const uint8_t *buf, int size) @@ -98,6 +98,8 @@ static void mipsnet_receive(void *opaque, const uint8_t *buf, int size)
98 /* Now we can signal we have received something. */ 98 /* Now we can signal we have received something. */
99 s->intctl |= MIPSNET_INTCTL_RXDONE; 99 s->intctl |= MIPSNET_INTCTL_RXDONE;
100 mipsnet_update_irq(s); 100 mipsnet_update_irq(s);
  101 +
  102 + return size;
101 } 103 }
102 104
103 static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr) 105 static uint32_t mipsnet_ioport_read(void *opaque, uint32_t addr)
@@ -262,7 +264,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd) @@ -262,7 +264,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
262 s->irq = irq; 264 s->irq = irq;
263 if (nd && nd->vlan) { 265 if (nd && nd->vlan) {
264 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 266 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
265 - mipsnet_receive, mipsnet_can_receive, 267 + mipsnet_can_receive, mipsnet_receive, NULL,
266 mipsnet_cleanup, s); 268 mipsnet_cleanup, s);
267 } else { 269 } else {
268 s->vc = NULL; 270 s->vc = NULL;
hw/musicpal.c
@@ -557,14 +557,14 @@ static void eth_rx_desc_get(uint32_t addr, mv88w8618_rx_desc *desc) @@ -557,14 +557,14 @@ static void eth_rx_desc_get(uint32_t addr, mv88w8618_rx_desc *desc)
557 le32_to_cpus(&desc->next); 557 le32_to_cpus(&desc->next);
558 } 558 }
559 559
560 -static int eth_can_receive(void *opaque) 560 +static int eth_can_receive(VLANClientState *vc)
561 { 561 {
562 return 1; 562 return 1;
563 } 563 }
564 564
565 -static void eth_receive(void *opaque, const uint8_t *buf, int size) 565 +static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
566 { 566 {
567 - mv88w8618_eth_state *s = opaque; 567 + mv88w8618_eth_state *s = vc->opaque;
568 uint32_t desc_addr; 568 uint32_t desc_addr;
569 mv88w8618_rx_desc desc; 569 mv88w8618_rx_desc desc;
570 int i; 570 int i;
@@ -586,11 +586,12 @@ static void eth_receive(void *opaque, const uint8_t *buf, int size) @@ -586,11 +586,12 @@ static void eth_receive(void *opaque, const uint8_t *buf, int size)
586 if (s->icr & s->imr) 586 if (s->icr & s->imr)
587 qemu_irq_raise(s->irq); 587 qemu_irq_raise(s->irq);
588 eth_rx_desc_put(desc_addr, &desc); 588 eth_rx_desc_put(desc_addr, &desc);
589 - return; 589 + return size;
590 } 590 }
591 desc_addr = desc.next; 591 desc_addr = desc.next;
592 } while (desc_addr != s->rx_queue[i]); 592 } while (desc_addr != s->rx_queue[i]);
593 } 593 }
  594 + return size;
594 } 595 }
595 596
596 static void eth_tx_desc_put(uint32_t addr, mv88w8618_tx_desc *desc) 597 static void eth_tx_desc_put(uint32_t addr, mv88w8618_tx_desc *desc)
@@ -753,7 +754,7 @@ static void mv88w8618_eth_init(SysBusDevice *dev) @@ -753,7 +754,7 @@ static void mv88w8618_eth_init(SysBusDevice *dev)
753 754
754 sysbus_init_irq(dev, &s->irq); 755 sysbus_init_irq(dev, &s->irq);
755 s->vc = qdev_get_vlan_client(&dev->qdev, 756 s->vc = qdev_get_vlan_client(&dev->qdev,
756 - eth_receive, eth_can_receive, 757 + eth_can_receive, eth_receive, NULL,
757 eth_cleanup, s); 758 eth_cleanup, s);
758 s->mmio_index = cpu_register_io_memory(0, mv88w8618_eth_readfn, 759 s->mmio_index = cpu_register_io_memory(0, mv88w8618_eth_readfn,
759 mv88w8618_eth_writefn, s); 760 mv88w8618_eth_writefn, s);
hw/ne2000.c
@@ -213,9 +213,9 @@ static int ne2000_buffer_full(NE2000State *s) @@ -213,9 +213,9 @@ static int ne2000_buffer_full(NE2000State *s)
213 return 0; 213 return 0;
214 } 214 }
215 215
216 -static int ne2000_can_receive(void *opaque) 216 +static int ne2000_can_receive(VLANClientState *vc)
217 { 217 {
218 - NE2000State *s = opaque; 218 + NE2000State *s = vc->opaque;
219 219
220 if (s->cmd & E8390_STOP) 220 if (s->cmd & E8390_STOP)
221 return 1; 221 return 1;
@@ -224,9 +224,10 @@ static int ne2000_can_receive(void *opaque) @@ -224,9 +224,10 @@ static int ne2000_can_receive(void *opaque)
224 224
225 #define MIN_BUF_SIZE 60 225 #define MIN_BUF_SIZE 60
226 226
227 -static void ne2000_receive(void *opaque, const uint8_t *buf, int size) 227 +static ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
228 { 228 {
229 - NE2000State *s = opaque; 229 + NE2000State *s = vc->opaque;
  230 + int size = size_;
230 uint8_t *p; 231 uint8_t *p;
231 unsigned int total_len, next, avail, len, index, mcast_idx; 232 unsigned int total_len, next, avail, len, index, mcast_idx;
232 uint8_t buf1[60]; 233 uint8_t buf1[60];
@@ -238,7 +239,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) @@ -238,7 +239,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
238 #endif 239 #endif
239 240
240 if (s->cmd & E8390_STOP || ne2000_buffer_full(s)) 241 if (s->cmd & E8390_STOP || ne2000_buffer_full(s))
241 - return; 242 + return -1;
242 243
243 /* XXX: check this */ 244 /* XXX: check this */
244 if (s->rxcr & 0x10) { 245 if (s->rxcr & 0x10) {
@@ -247,14 +248,14 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) @@ -247,14 +248,14 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
247 if (!memcmp(buf, broadcast_macaddr, 6)) { 248 if (!memcmp(buf, broadcast_macaddr, 6)) {
248 /* broadcast address */ 249 /* broadcast address */
249 if (!(s->rxcr & 0x04)) 250 if (!(s->rxcr & 0x04))
250 - return; 251 + return size;
251 } else if (buf[0] & 0x01) { 252 } else if (buf[0] & 0x01) {
252 /* multicast */ 253 /* multicast */
253 if (!(s->rxcr & 0x08)) 254 if (!(s->rxcr & 0x08))
254 - return; 255 + return size;
255 mcast_idx = compute_mcast_idx(buf); 256 mcast_idx = compute_mcast_idx(buf);
256 if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) 257 if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7))))
257 - return; 258 + return size;
258 } else if (s->mem[0] == buf[0] && 259 } else if (s->mem[0] == buf[0] &&
259 s->mem[2] == buf[1] && 260 s->mem[2] == buf[1] &&
260 s->mem[4] == buf[2] && 261 s->mem[4] == buf[2] &&
@@ -263,7 +264,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) @@ -263,7 +264,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
263 s->mem[10] == buf[5]) { 264 s->mem[10] == buf[5]) {
264 /* match */ 265 /* match */
265 } else { 266 } else {
266 - return; 267 + return size;
267 } 268 }
268 } 269 }
269 270
@@ -316,6 +317,8 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) @@ -316,6 +317,8 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size)
316 /* now we can signal we have received something */ 317 /* now we can signal we have received something */
317 s->isr |= ENISR_RX; 318 s->isr |= ENISR_RX;
318 ne2000_update_irq(s); 319 ne2000_update_irq(s);
  320 +
  321 + return size_;
319 } 322 }
320 323
321 static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val) 324 static void ne2000_ioport_write(void *opaque, uint32_t addr, uint32_t val)
@@ -757,7 +760,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd) @@ -757,7 +760,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
757 ne2000_reset(s); 760 ne2000_reset(s);
758 761
759 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 762 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
760 - ne2000_receive, ne2000_can_receive, 763 + ne2000_can_receive, ne2000_receive, NULL,
761 isa_ne2000_cleanup, s); 764 isa_ne2000_cleanup, s);
762 765
763 qemu_format_nic_info_str(s->vc, s->macaddr); 766 qemu_format_nic_info_str(s->vc, s->macaddr);
@@ -821,7 +824,7 @@ static void pci_ne2000_init(PCIDevice *pci_dev) @@ -821,7 +824,7 @@ static void pci_ne2000_init(PCIDevice *pci_dev)
821 qdev_get_macaddr(&d->dev.qdev, s->macaddr); 824 qdev_get_macaddr(&d->dev.qdev, s->macaddr);
822 ne2000_reset(s); 825 ne2000_reset(s);
823 s->vc = qdev_get_vlan_client(&d->dev.qdev, 826 s->vc = qdev_get_vlan_client(&d->dev.qdev,
824 - ne2000_receive, ne2000_can_receive, 827 + ne2000_can_receive, ne2000_receive, NULL,
825 ne2000_cleanup, s); 828 ne2000_cleanup, s);
826 829
827 qemu_format_nic_info_str(s->vc, s->macaddr); 830 qemu_format_nic_info_str(s->vc, s->macaddr);
hw/pci-hotplug.c
@@ -33,11 +33,12 @@ @@ -33,11 +33,12 @@
33 #include "virtio-blk.h" 33 #include "virtio-blk.h"
34 34
35 #if defined(TARGET_I386) || defined(TARGET_X86_64) 35 #if defined(TARGET_I386) || defined(TARGET_X86_64)
36 -static PCIDevice *qemu_pci_hot_add_nic(PCIBus *pci_bus, const char *opts) 36 +static PCIDevice *qemu_pci_hot_add_nic(Monitor *mon, PCIBus *pci_bus,
  37 + const char *opts)
37 { 38 {
38 int ret; 39 int ret;
39 40
40 - ret = net_client_init("nic", opts); 41 + ret = net_client_init(mon, "nic", opts);
41 if (ret < 0) 42 if (ret < 0)
42 return NULL; 43 return NULL;
43 return pci_nic_init(pci_bus, &nd_table[ret], -1, "rtl8139"); 44 return pci_nic_init(pci_bus, &nd_table[ret], -1, "rtl8139");
@@ -149,7 +150,7 @@ void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type, @@ -149,7 +150,7 @@ void pci_device_hot_add(Monitor *mon, const char *pci_addr, const char *type,
149 } 150 }
150 151
151 if (strcmp(type, "nic") == 0) 152 if (strcmp(type, "nic") == 0)
152 - dev = qemu_pci_hot_add_nic(pci_bus, opts); 153 + dev = qemu_pci_hot_add_nic(mon, pci_bus, opts);
153 else if (strcmp(type, "storage") == 0) 154 else if (strcmp(type, "storage") == 0)
154 dev = qemu_pci_hot_add_storage(mon, pci_bus, opts); 155 dev = qemu_pci_hot_add_storage(mon, pci_bus, opts);
155 else 156 else
hw/pcnet.c
@@ -1062,9 +1062,9 @@ static int pcnet_tdte_poll(PCNetState *s) @@ -1062,9 +1062,9 @@ static int pcnet_tdte_poll(PCNetState *s)
1062 return !!(CSR_CXST(s) & 0x8000); 1062 return !!(CSR_CXST(s) & 0x8000);
1063 } 1063 }
1064 1064
1065 -static int pcnet_can_receive(void *opaque) 1065 +static int pcnet_can_receive(VLANClientState *vc)
1066 { 1066 {
1067 - PCNetState *s = opaque; 1067 + PCNetState *s = vc->opaque;
1068 if (CSR_STOP(s) || CSR_SPND(s)) 1068 if (CSR_STOP(s) || CSR_SPND(s))
1069 return 0; 1069 return 0;
1070 1070
@@ -1076,16 +1076,17 @@ static int pcnet_can_receive(void *opaque) @@ -1076,16 +1076,17 @@ static int pcnet_can_receive(void *opaque)
1076 1076
1077 #define MIN_BUF_SIZE 60 1077 #define MIN_BUF_SIZE 60
1078 1078
1079 -static void pcnet_receive(void *opaque, const uint8_t *buf, int size) 1079 +static ssize_t pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
1080 { 1080 {
1081 - PCNetState *s = opaque; 1081 + PCNetState *s = vc->opaque;
1082 int is_padr = 0, is_bcast = 0, is_ladr = 0; 1082 int is_padr = 0, is_bcast = 0, is_ladr = 0;
1083 uint8_t buf1[60]; 1083 uint8_t buf1[60];
1084 int remaining; 1084 int remaining;
1085 int crc_err = 0; 1085 int crc_err = 0;
  1086 + int size = size_;
1086 1087
1087 if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size) 1088 if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size)
1088 - return; 1089 + return -1;
1089 1090
1090 #ifdef PCNET_DEBUG 1091 #ifdef PCNET_DEBUG
1091 printf("pcnet_receive size=%d\n", size); 1092 printf("pcnet_receive size=%d\n", size);
@@ -1252,6 +1253,8 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size) @@ -1252,6 +1253,8 @@ static void pcnet_receive(void *opaque, const uint8_t *buf, int size)
1252 1253
1253 pcnet_poll(s); 1254 pcnet_poll(s);
1254 pcnet_update_irq(s); 1255 pcnet_update_irq(s);
  1256 +
  1257 + return size_;
1255 } 1258 }
1256 1259
1257 static void pcnet_transmit(PCNetState *s) 1260 static void pcnet_transmit(PCNetState *s)
@@ -1302,7 +1305,7 @@ static void pcnet_transmit(PCNetState *s) @@ -1302,7 +1305,7 @@ static void pcnet_transmit(PCNetState *s)
1302 if (BCR_SWSTYLE(s) == 1) 1305 if (BCR_SWSTYLE(s) == 1)
1303 add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS); 1306 add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS);
1304 s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC; 1307 s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC;
1305 - pcnet_receive(s, s->buffer, s->xmit_pos); 1308 + pcnet_receive(s->vc, s->buffer, s->xmit_pos);
1306 s->looptest = 0; 1309 s->looptest = 0;
1307 } else 1310 } else
1308 if (s->vc) 1311 if (s->vc)
@@ -1952,7 +1955,7 @@ static void pcnet_common_init(DeviceState *dev, PCNetState *s, @@ -1952,7 +1955,7 @@ static void pcnet_common_init(DeviceState *dev, PCNetState *s,
1952 1955
1953 qdev_get_macaddr(dev, s->macaddr); 1956 qdev_get_macaddr(dev, s->macaddr);
1954 s->vc = qdev_get_vlan_client(dev, 1957 s->vc = qdev_get_vlan_client(dev,
1955 - pcnet_receive, pcnet_can_receive, 1958 + pcnet_can_receive, pcnet_receive, NULL,
1956 cleanup, s); 1959 cleanup, s);
1957 pcnet_h_reset(s); 1960 pcnet_h_reset(s);
1958 register_savevm("pcnet", -1, 2, pcnet_save, pcnet_load, s); 1961 register_savevm("pcnet", -1, 2, pcnet_save, pcnet_load, s);
hw/qdev.c
@@ -258,15 +258,16 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin) @@ -258,15 +258,16 @@ void qdev_connect_gpio_out(DeviceState * dev, int n, qemu_irq pin)
258 } 258 }
259 259
260 VLANClientState *qdev_get_vlan_client(DeviceState *dev, 260 VLANClientState *qdev_get_vlan_client(DeviceState *dev,
261 - IOReadHandler *fd_read,  
262 - IOCanRWHandler *fd_can_read, 261 + NetCanReceive *can_receive,
  262 + NetReceive *receive,
  263 + NetReceiveIOV *receive_iov,
263 NetCleanup *cleanup, 264 NetCleanup *cleanup,
264 void *opaque) 265 void *opaque)
265 { 266 {
266 NICInfo *nd = dev->nd; 267 NICInfo *nd = dev->nd;
267 assert(nd); 268 assert(nd);
268 - return qemu_new_vlan_client(nd->vlan, nd->model, nd->name,  
269 - fd_read, fd_can_read, cleanup, opaque); 269 + return qemu_new_vlan_client(nd->vlan, nd->model, nd->name, can_receive,
  270 + receive, receive_iov, cleanup, opaque);
270 } 271 }
271 272
272 273
hw/rtl8139.c
@@ -790,9 +790,9 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high) @@ -790,9 +790,9 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high)
790 #endif 790 #endif
791 } 791 }
792 792
793 -static int rtl8139_can_receive(void *opaque) 793 +static int rtl8139_can_receive(VLANClientState *vc)
794 { 794 {
795 - RTL8139State *s = opaque; 795 + RTL8139State *s = vc->opaque;
796 int avail; 796 int avail;
797 797
798 /* Receive (drop) packets if card is disabled. */ 798 /* Receive (drop) packets if card is disabled. */
@@ -812,9 +812,10 @@ static int rtl8139_can_receive(void *opaque) @@ -812,9 +812,10 @@ static int rtl8139_can_receive(void *opaque)
812 } 812 }
813 } 813 }
814 814
815 -static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int do_interrupt) 815 +static ssize_t rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, size_t size_, int do_interrupt)
816 { 816 {
817 - RTL8139State *s = opaque; 817 + RTL8139State *s = vc->opaque;
  818 + int size = size_;
818 819
819 uint32_t packet_header = 0; 820 uint32_t packet_header = 0;
820 821
@@ -828,7 +829,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -828,7 +829,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
828 if (!s->clock_enabled) 829 if (!s->clock_enabled)
829 { 830 {
830 DEBUG_PRINT(("RTL8139: stopped ==========================\n")); 831 DEBUG_PRINT(("RTL8139: stopped ==========================\n"));
831 - return; 832 + return -1;
832 } 833 }
833 834
834 /* first check if receiver is enabled */ 835 /* first check if receiver is enabled */
@@ -836,7 +837,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -836,7 +837,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
836 if (!rtl8139_receiver_enabled(s)) 837 if (!rtl8139_receiver_enabled(s))
837 { 838 {
838 DEBUG_PRINT(("RTL8139: receiver disabled ================\n")); 839 DEBUG_PRINT(("RTL8139: receiver disabled ================\n"));
839 - return; 840 + return -1;
840 } 841 }
841 842
842 /* XXX: check this */ 843 /* XXX: check this */
@@ -854,7 +855,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -854,7 +855,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
854 /* update tally counter */ 855 /* update tally counter */
855 ++s->tally_counters.RxERR; 856 ++s->tally_counters.RxERR;
856 857
857 - return; 858 + return size;
858 } 859 }
859 860
860 packet_header |= RxBroadcast; 861 packet_header |= RxBroadcast;
@@ -873,7 +874,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -873,7 +874,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
873 /* update tally counter */ 874 /* update tally counter */
874 ++s->tally_counters.RxERR; 875 ++s->tally_counters.RxERR;
875 876
876 - return; 877 + return size;
877 } 878 }
878 879
879 int mcast_idx = compute_mcast_idx(buf); 880 int mcast_idx = compute_mcast_idx(buf);
@@ -885,7 +886,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -885,7 +886,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
885 /* update tally counter */ 886 /* update tally counter */
886 ++s->tally_counters.RxERR; 887 ++s->tally_counters.RxERR;
887 888
888 - return; 889 + return size;
889 } 890 }
890 891
891 packet_header |= RxMulticast; 892 packet_header |= RxMulticast;
@@ -909,7 +910,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -909,7 +910,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
909 /* update tally counter */ 910 /* update tally counter */
910 ++s->tally_counters.RxERR; 911 ++s->tally_counters.RxERR;
911 912
912 - return; 913 + return size;
913 } 914 }
914 915
915 packet_header |= RxPhysical; 916 packet_header |= RxPhysical;
@@ -926,7 +927,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -926,7 +927,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
926 /* update tally counter */ 927 /* update tally counter */
927 ++s->tally_counters.RxERR; 928 ++s->tally_counters.RxERR;
928 929
929 - return; 930 + return size;
930 } 931 }
931 } 932 }
932 933
@@ -993,7 +994,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -993,7 +994,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
993 ++s->tally_counters.MissPkt; 994 ++s->tally_counters.MissPkt;
994 995
995 rtl8139_update_irq(s); 996 rtl8139_update_irq(s);
996 - return; 997 + return size_;
997 } 998 }
998 999
999 uint32_t rx_space = rxdw0 & CP_RX_BUFFER_SIZE_MASK; 1000 uint32_t rx_space = rxdw0 & CP_RX_BUFFER_SIZE_MASK;
@@ -1013,7 +1014,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -1013,7 +1014,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
1013 ++s->tally_counters.MissPkt; 1014 ++s->tally_counters.MissPkt;
1014 1015
1015 rtl8139_update_irq(s); 1016 rtl8139_update_irq(s);
1016 - return; 1017 + return size_;
1017 } 1018 }
1018 1019
1019 target_phys_addr_t rx_addr = rtl8139_addr64(rxbufLO, rxbufHI); 1020 target_phys_addr_t rx_addr = rtl8139_addr64(rxbufLO, rxbufHI);
@@ -1118,7 +1119,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -1118,7 +1119,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
1118 s->IntrStatus |= RxOverflow; 1119 s->IntrStatus |= RxOverflow;
1119 ++s->RxMissed; 1120 ++s->RxMissed;
1120 rtl8139_update_irq(s); 1121 rtl8139_update_irq(s);
1121 - return; 1122 + return size_;
1122 } 1123 }
1123 1124
1124 packet_header |= RxStatusOK; 1125 packet_header |= RxStatusOK;
@@ -1156,11 +1157,13 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d @@ -1156,11 +1157,13 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
1156 { 1157 {
1157 rtl8139_update_irq(s); 1158 rtl8139_update_irq(s);
1158 } 1159 }
  1160 +
  1161 + return size_;
1159 } 1162 }
1160 1163
1161 -static void rtl8139_receive(void *opaque, const uint8_t *buf, int size) 1164 +static ssize_t rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1162 { 1165 {
1163 - rtl8139_do_receive(opaque, buf, size, 1); 1166 + return rtl8139_do_receive(vc, buf, size, 1);
1164 } 1167 }
1165 1168
1166 static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) 1169 static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
@@ -1758,7 +1761,7 @@ static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size @@ -1758,7 +1761,7 @@ static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size
1758 if (TxLoopBack == (s->TxConfig & TxLoopBack)) 1761 if (TxLoopBack == (s->TxConfig & TxLoopBack))
1759 { 1762 {
1760 DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n")); 1763 DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n"));
1761 - rtl8139_do_receive(s, buf, size, do_interrupt); 1764 + rtl8139_do_receive(s->vc, buf, size, do_interrupt);
1762 } 1765 }
1763 else 1766 else
1764 { 1767 {
@@ -3479,7 +3482,7 @@ static void pci_rtl8139_init(PCIDevice *dev) @@ -3479,7 +3482,7 @@ static void pci_rtl8139_init(PCIDevice *dev)
3479 qemu_register_reset(rtl8139_reset, 0, s); 3482 qemu_register_reset(rtl8139_reset, 0, s);
3480 rtl8139_reset(s); 3483 rtl8139_reset(s);
3481 s->vc = qdev_get_vlan_client(&dev->qdev, 3484 s->vc = qdev_get_vlan_client(&dev->qdev,
3482 - rtl8139_receive, rtl8139_can_receive, 3485 + rtl8139_can_receive, rtl8139_receive, NULL,
3483 rtl8139_cleanup, s); 3486 rtl8139_cleanup, s);
3484 3487
3485 qemu_format_nic_info_str(s->vc, s->macaddr); 3488 qemu_format_nic_info_str(s->vc, s->macaddr);
hw/smc91c111.c
@@ -591,9 +591,9 @@ static uint32_t smc91c111_readl(void *opaque, target_phys_addr_t offset) @@ -591,9 +591,9 @@ static uint32_t smc91c111_readl(void *opaque, target_phys_addr_t offset)
591 return val; 591 return val;
592 } 592 }
593 593
594 -static int smc91c111_can_receive(void *opaque) 594 +static int smc91c111_can_receive(VLANClientState *vc)
595 { 595 {
596 - smc91c111_state *s = (smc91c111_state *)opaque; 596 + smc91c111_state *s = vc->opaque;
597 597
598 if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) 598 if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST))
599 return 1; 599 return 1;
@@ -602,9 +602,9 @@ static int smc91c111_can_receive(void *opaque) @@ -602,9 +602,9 @@ static int smc91c111_can_receive(void *opaque)
602 return 1; 602 return 1;
603 } 603 }
604 604
605 -static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) 605 +static ssize_t smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
606 { 606 {
607 - smc91c111_state *s = (smc91c111_state *)opaque; 607 + smc91c111_state *s = vc->opaque;
608 int status; 608 int status;
609 int packetsize; 609 int packetsize;
610 uint32_t crc; 610 uint32_t crc;
@@ -612,7 +612,7 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) @@ -612,7 +612,7 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size)
612 uint8_t *p; 612 uint8_t *p;
613 613
614 if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) 614 if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST))
615 - return; 615 + return -1;
616 /* Short packets are padded with zeros. Receiving a packet 616 /* Short packets are padded with zeros. Receiving a packet
617 < 64 bytes long is considered an error condition. */ 617 < 64 bytes long is considered an error condition. */
618 if (size < 64) 618 if (size < 64)
@@ -625,10 +625,10 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) @@ -625,10 +625,10 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size)
625 packetsize += 4; 625 packetsize += 4;
626 /* TODO: Flag overrun and receive errors. */ 626 /* TODO: Flag overrun and receive errors. */
627 if (packetsize > 2048) 627 if (packetsize > 2048)
628 - return; 628 + return -1;
629 packetnum = smc91c111_allocate_packet(s); 629 packetnum = smc91c111_allocate_packet(s);
630 if (packetnum == 0x80) 630 if (packetnum == 0x80)
631 - return; 631 + return -1;
632 s->rx_fifo[s->rx_fifo_len++] = packetnum; 632 s->rx_fifo[s->rx_fifo_len++] = packetnum;
633 633
634 p = &s->data[packetnum][0]; 634 p = &s->data[packetnum][0];
@@ -676,6 +676,8 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) @@ -676,6 +676,8 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size)
676 /* TODO: Raise early RX interrupt? */ 676 /* TODO: Raise early RX interrupt? */
677 s->int_level |= INT_RCV; 677 s->int_level |= INT_RCV;
678 smc91c111_update(s); 678 smc91c111_update(s);
  679 +
  680 + return size;
679 } 681 }
680 682
681 static CPUReadMemoryFunc *smc91c111_readfn[] = { 683 static CPUReadMemoryFunc *smc91c111_readfn[] = {
@@ -711,7 +713,7 @@ static void smc91c111_init1(SysBusDevice *dev) @@ -711,7 +713,7 @@ static void smc91c111_init1(SysBusDevice *dev)
711 smc91c111_reset(s); 713 smc91c111_reset(s);
712 714
713 s->vc = qdev_get_vlan_client(&dev->qdev, 715 s->vc = qdev_get_vlan_client(&dev->qdev,
714 - smc91c111_receive, smc91c111_can_receive, 716 + smc91c111_can_receive, smc91c111_receive, NULL,
715 smc91c111_cleanup, s); 717 smc91c111_cleanup, s);
716 qemu_format_nic_info_str(s->vc, s->macaddr); 718 qemu_format_nic_info_str(s->vc, s->macaddr);
717 /* ??? Save/restore. */ 719 /* ??? Save/restore. */
hw/stellaris_enet.c
@@ -78,18 +78,18 @@ static void stellaris_enet_update(stellaris_enet_state *s) @@ -78,18 +78,18 @@ static void stellaris_enet_update(stellaris_enet_state *s)
78 } 78 }
79 79
80 /* TODO: Implement MAC address filtering. */ 80 /* TODO: Implement MAC address filtering. */
81 -static void stellaris_enet_receive(void *opaque, const uint8_t *buf, int size) 81 +static ssize_t stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
82 { 82 {
83 - stellaris_enet_state *s = (stellaris_enet_state *)opaque; 83 + stellaris_enet_state *s = vc->opaque;
84 int n; 84 int n;
85 uint8_t *p; 85 uint8_t *p;
86 uint32_t crc; 86 uint32_t crc;
87 87
88 if ((s->rctl & SE_RCTL_RXEN) == 0) 88 if ((s->rctl & SE_RCTL_RXEN) == 0)
89 - return; 89 + return -1;
90 if (s->np >= 31) { 90 if (s->np >= 31) {
91 DPRINTF("Packet dropped\n"); 91 DPRINTF("Packet dropped\n");
92 - return; 92 + return -1;
93 } 93 }
94 94
95 DPRINTF("Received packet len=%d\n", size); 95 DPRINTF("Received packet len=%d\n", size);
@@ -116,11 +116,13 @@ static void stellaris_enet_receive(void *opaque, const uint8_t *buf, int size) @@ -116,11 +116,13 @@ static void stellaris_enet_receive(void *opaque, const uint8_t *buf, int size)
116 116
117 s->ris |= SE_INT_RX; 117 s->ris |= SE_INT_RX;
118 stellaris_enet_update(s); 118 stellaris_enet_update(s);
  119 +
  120 + return size;
119 } 121 }
120 122
121 -static int stellaris_enet_can_receive(void *opaque) 123 +static int stellaris_enet_can_receive(VLANClientState *vc)
122 { 124 {
123 - stellaris_enet_state *s = (stellaris_enet_state *)opaque; 125 + stellaris_enet_state *s = vc->opaque;
124 126
125 if ((s->rctl & SE_RCTL_RXEN) == 0) 127 if ((s->rctl & SE_RCTL_RXEN) == 0)
126 return 1; 128 return 1;
@@ -128,9 +130,9 @@ static int stellaris_enet_can_receive(void *opaque) @@ -128,9 +130,9 @@ static int stellaris_enet_can_receive(void *opaque)
128 return (s->np < 31); 130 return (s->np < 31);
129 } 131 }
130 132
131 -static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset) 133 +static uint32_t stellaris_enet_read(VLANClientState *vc, target_phys_addr_t offset)
132 { 134 {
133 - stellaris_enet_state *s = (stellaris_enet_state *)opaque; 135 + stellaris_enet_state *s = vc->opaque;
134 uint32_t val; 136 uint32_t val;
135 137
136 switch (offset) { 138 switch (offset) {
@@ -405,8 +407,8 @@ static void stellaris_enet_init(SysBusDevice *dev) @@ -405,8 +407,8 @@ static void stellaris_enet_init(SysBusDevice *dev)
405 qdev_get_macaddr(&dev->qdev, s->macaddr); 407 qdev_get_macaddr(&dev->qdev, s->macaddr);
406 408
407 s->vc = qdev_get_vlan_client(&dev->qdev, 409 s->vc = qdev_get_vlan_client(&dev->qdev,
408 - stellaris_enet_receive,  
409 stellaris_enet_can_receive, 410 stellaris_enet_can_receive,
  411 + stellaris_enet_receive, NULL,
410 stellaris_enet_cleanup, s); 412 stellaris_enet_cleanup, s);
411 qemu_format_nic_info_str(s->vc, s->macaddr); 413 qemu_format_nic_info_str(s->vc, s->macaddr);
412 414
hw/usb-net.c
@@ -1369,17 +1369,17 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p) @@ -1369,17 +1369,17 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p)
1369 return ret; 1369 return ret;
1370 } 1370 }
1371 1371
1372 -static void usbnet_receive(void *opaque, const uint8_t *buf, int size) 1372 +static ssize_t usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1373 { 1373 {
1374 - USBNetState *s = opaque; 1374 + USBNetState *s = vc->opaque;
1375 struct rndis_packet_msg_type *msg; 1375 struct rndis_packet_msg_type *msg;
1376 1376
1377 if (s->rndis) { 1377 if (s->rndis) {
1378 msg = (struct rndis_packet_msg_type *) s->in_buf; 1378 msg = (struct rndis_packet_msg_type *) s->in_buf;
1379 if (!s->rndis_state == RNDIS_DATA_INITIALIZED) 1379 if (!s->rndis_state == RNDIS_DATA_INITIALIZED)
1380 - return; 1380 + return -1;
1381 if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) 1381 if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf))
1382 - return; 1382 + return -1;
1383 1383
1384 memset(msg, 0, sizeof(struct rndis_packet_msg_type)); 1384 memset(msg, 0, sizeof(struct rndis_packet_msg_type));
1385 msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG); 1385 msg->MessageType = cpu_to_le32(RNDIS_PACKET_MSG);
@@ -1398,16 +1398,17 @@ static void usbnet_receive(void *opaque, const uint8_t *buf, int size) @@ -1398,16 +1398,17 @@ static void usbnet_receive(void *opaque, const uint8_t *buf, int size)
1398 s->in_len = size + sizeof(struct rndis_packet_msg_type); 1398 s->in_len = size + sizeof(struct rndis_packet_msg_type);
1399 } else { 1399 } else {
1400 if (size > sizeof(s->in_buf)) 1400 if (size > sizeof(s->in_buf))
1401 - return; 1401 + return -1;
1402 memcpy(s->in_buf, buf, size); 1402 memcpy(s->in_buf, buf, size);
1403 s->in_len = size; 1403 s->in_len = size;
1404 } 1404 }
1405 s->in_ptr = 0; 1405 s->in_ptr = 0;
  1406 + return size;
1406 } 1407 }
1407 1408
1408 -static int usbnet_can_receive(void *opaque) 1409 +static int usbnet_can_receive(VLANClientState *vc)
1409 { 1410 {
1410 - USBNetState *s = opaque; 1411 + USBNetState *s = vc->opaque;
1411 1412
1412 if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED) 1413 if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED)
1413 return 1; 1414 return 1;
@@ -1458,8 +1459,9 @@ USBDevice *usb_net_init(NICInfo *nd) @@ -1458,8 +1459,9 @@ USBDevice *usb_net_init(NICInfo *nd)
1458 pstrcpy(s->dev.devname, sizeof(s->dev.devname), 1459 pstrcpy(s->dev.devname, sizeof(s->dev.devname),
1459 "QEMU USB Network Interface"); 1460 "QEMU USB Network Interface");
1460 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, 1461 s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
1461 - usbnet_receive,  
1462 usbnet_can_receive, 1462 usbnet_can_receive,
  1463 + usbnet_receive,
  1464 + NULL,
1463 usbnet_cleanup, s); 1465 usbnet_cleanup, s);
1464 1466
1465 qemu_format_nic_info_str(s->vc, s->mac); 1467 qemu_format_nic_info_str(s->vc, s->mac);
hw/virtio-net.c
@@ -16,9 +16,9 @@ @@ -16,9 +16,9 @@
16 #include "qemu-timer.h" 16 #include "qemu-timer.h"
17 #include "virtio-net.h" 17 #include "virtio-net.h"
18 18
19 -#define VIRTIO_NET_VM_VERSION 6 19 +#define VIRTIO_NET_VM_VERSION 10
20 20
21 -#define MAC_TABLE_ENTRIES 32 21 +#define MAC_TABLE_ENTRIES 64
22 #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ 22 #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */
23 23
24 typedef struct VirtIONet 24 typedef struct VirtIONet
@@ -33,10 +33,17 @@ typedef struct VirtIONet @@ -33,10 +33,17 @@ typedef struct VirtIONet
33 QEMUTimer *tx_timer; 33 QEMUTimer *tx_timer;
34 int tx_timer_active; 34 int tx_timer_active;
35 int mergeable_rx_bufs; 35 int mergeable_rx_bufs;
36 - int promisc;  
37 - int allmulti; 36 + uint8_t promisc;
  37 + uint8_t allmulti;
  38 + uint8_t alluni;
  39 + uint8_t nomulti;
  40 + uint8_t nouni;
  41 + uint8_t nobcast;
38 struct { 42 struct {
39 int in_use; 43 int in_use;
  44 + int first_multi;
  45 + uint8_t multi_overflow;
  46 + uint8_t uni_overflow;
40 uint8_t *macs; 47 uint8_t *macs;
41 } mac_table; 48 } mac_table;
42 uint32_t *vlans; 49 uint32_t *vlans;
@@ -95,9 +102,16 @@ static void virtio_net_reset(VirtIODevice *vdev) @@ -95,9 +102,16 @@ static void virtio_net_reset(VirtIODevice *vdev)
95 /* Reset back to compatibility mode */ 102 /* Reset back to compatibility mode */
96 n->promisc = 1; 103 n->promisc = 1;
97 n->allmulti = 0; 104 n->allmulti = 0;
  105 + n->alluni = 0;
  106 + n->nomulti = 0;
  107 + n->nouni = 0;
  108 + n->nobcast = 0;
98 109
99 /* Flush any MAC and VLAN filter table state */ 110 /* Flush any MAC and VLAN filter table state */
100 n->mac_table.in_use = 0; 111 n->mac_table.in_use = 0;
  112 + n->mac_table.first_multi = 0;
  113 + n->mac_table.multi_overflow = 0;
  114 + n->mac_table.uni_overflow = 0;
101 memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); 115 memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
102 memset(n->vlans, 0, MAX_VLAN >> 3); 116 memset(n->vlans, 0, MAX_VLAN >> 3);
103 } 117 }
@@ -108,7 +122,8 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev) @@ -108,7 +122,8 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev)
108 (1 << VIRTIO_NET_F_STATUS) | 122 (1 << VIRTIO_NET_F_STATUS) |
109 (1 << VIRTIO_NET_F_CTRL_VQ) | 123 (1 << VIRTIO_NET_F_CTRL_VQ) |
110 (1 << VIRTIO_NET_F_CTRL_RX) | 124 (1 << VIRTIO_NET_F_CTRL_RX) |
111 - (1 << VIRTIO_NET_F_CTRL_VLAN); 125 + (1 << VIRTIO_NET_F_CTRL_VLAN) |
  126 + (1 << VIRTIO_NET_F_CTRL_RX_EXTRA);
112 127
113 return features; 128 return features;
114 } 129 }
@@ -151,6 +166,14 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, @@ -151,6 +166,14 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd,
151 n->promisc = on; 166 n->promisc = on;
152 else if (cmd == VIRTIO_NET_CTRL_RX_MODE_ALLMULTI) 167 else if (cmd == VIRTIO_NET_CTRL_RX_MODE_ALLMULTI)
153 n->allmulti = on; 168 n->allmulti = on;
  169 + else if (cmd == VIRTIO_NET_CTRL_RX_MODE_ALLUNI)
  170 + n->alluni = on;
  171 + else if (cmd == VIRTIO_NET_CTRL_RX_MODE_NOMULTI)
  172 + n->nomulti = on;
  173 + else if (cmd == VIRTIO_NET_CTRL_RX_MODE_NOUNI)
  174 + n->nouni = on;
  175 + else if (cmd == VIRTIO_NET_CTRL_RX_MODE_NOBCAST)
  176 + n->nobcast = on;
154 else 177 else
155 return VIRTIO_NET_ERR; 178 return VIRTIO_NET_ERR;
156 179
@@ -168,6 +191,9 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, @@ -168,6 +191,9 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
168 return VIRTIO_NET_ERR; 191 return VIRTIO_NET_ERR;
169 192
170 n->mac_table.in_use = 0; 193 n->mac_table.in_use = 0;
  194 + n->mac_table.first_multi = 0;
  195 + n->mac_table.uni_overflow = 0;
  196 + n->mac_table.multi_overflow = 0;
171 memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); 197 memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN);
172 198
173 mac_data.entries = ldl_le_p(elem->out_sg[1].iov_base); 199 mac_data.entries = ldl_le_p(elem->out_sg[1].iov_base);
@@ -181,10 +207,11 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, @@ -181,10 +207,11 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
181 mac_data.entries * ETH_ALEN); 207 mac_data.entries * ETH_ALEN);
182 n->mac_table.in_use += mac_data.entries; 208 n->mac_table.in_use += mac_data.entries;
183 } else { 209 } else {
184 - n->promisc = 1;  
185 - return VIRTIO_NET_OK; 210 + n->mac_table.uni_overflow = 1;
186 } 211 }
187 212
  213 + n->mac_table.first_multi = n->mac_table.in_use;
  214 +
188 mac_data.entries = ldl_le_p(elem->out_sg[2].iov_base); 215 mac_data.entries = ldl_le_p(elem->out_sg[2].iov_base);
189 216
190 if (sizeof(mac_data.entries) + 217 if (sizeof(mac_data.entries) +
@@ -197,8 +224,9 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, @@ -197,8 +224,9 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd,
197 elem->out_sg[2].iov_base + sizeof(mac_data), 224 elem->out_sg[2].iov_base + sizeof(mac_data),
198 mac_data.entries * ETH_ALEN); 225 mac_data.entries * ETH_ALEN);
199 n->mac_table.in_use += mac_data.entries; 226 n->mac_table.in_use += mac_data.entries;
200 - } else  
201 - n->allmulti = 1; 227 + } else {
  228 + n->mac_table.multi_overflow = 1;
  229 + }
202 } 230 }
203 231
204 return VIRTIO_NET_OK; 232 return VIRTIO_NET_OK;
@@ -269,6 +297,9 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) @@ -269,6 +297,9 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq)
269 297
270 static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq) 298 static void virtio_net_handle_rx(VirtIODevice *vdev, VirtQueue *vq)
271 { 299 {
  300 + VirtIONet *n = to_virtio_net(vdev);
  301 +
  302 + qemu_flush_queued_packets(n->vc);
272 } 303 }
273 304
274 static int do_virtio_net_can_receive(VirtIONet *n, int bufsize) 305 static int do_virtio_net_can_receive(VirtIONet *n, int bufsize)
@@ -288,9 +319,9 @@ static int do_virtio_net_can_receive(VirtIONet *n, int bufsize) @@ -288,9 +319,9 @@ static int do_virtio_net_can_receive(VirtIONet *n, int bufsize)
288 return 1; 319 return 1;
289 } 320 }
290 321
291 -static int virtio_net_can_receive(void *opaque) 322 +static int virtio_net_can_receive(VLANClientState *vc)
292 { 323 {
293 - VirtIONet *n = opaque; 324 + VirtIONet *n = vc->opaque;
294 325
295 return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE); 326 return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE);
296 } 327 }
@@ -344,34 +375,50 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size) @@ -344,34 +375,50 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
344 return 0; 375 return 0;
345 } 376 }
346 377
347 - if ((ptr[0] & 1) && n->allmulti)  
348 - return 1;  
349 -  
350 - if (!memcmp(ptr, bcast, sizeof(bcast)))  
351 - return 1;  
352 -  
353 - if (!memcmp(ptr, n->mac, ETH_ALEN))  
354 - return 1; 378 + if (ptr[0] & 1) { // multicast
  379 + if (!memcmp(ptr, bcast, sizeof(bcast))) {
  380 + return !n->nobcast;
  381 + } else if (n->nomulti) {
  382 + return 0;
  383 + } else if (n->allmulti || n->mac_table.multi_overflow) {
  384 + return 1;
  385 + }
355 386
356 - for (i = 0; i < n->mac_table.in_use; i++) {  
357 - if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN)) 387 + for (i = n->mac_table.first_multi; i < n->mac_table.in_use; i++) {
  388 + if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN)) {
  389 + return 1;
  390 + }
  391 + }
  392 + } else { // unicast
  393 + if (n->nouni) {
  394 + return 0;
  395 + } else if (n->alluni || n->mac_table.uni_overflow) {
  396 + return 1;
  397 + } else if (!memcmp(ptr, n->mac, ETH_ALEN)) {
358 return 1; 398 return 1;
  399 + }
  400 +
  401 + for (i = 0; i < n->mac_table.first_multi; i++) {
  402 + if (!memcmp(ptr, &n->mac_table.macs[i * ETH_ALEN], ETH_ALEN)) {
  403 + return 1;
  404 + }
  405 + }
359 } 406 }
360 407
361 return 0; 408 return 0;
362 } 409 }
363 410
364 -static void virtio_net_receive(void *opaque, const uint8_t *buf, int size) 411 +static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
365 { 412 {
366 - VirtIONet *n = opaque; 413 + VirtIONet *n = vc->opaque;
367 struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL; 414 struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
368 size_t hdr_len, offset, i; 415 size_t hdr_len, offset, i;
369 416
370 if (!do_virtio_net_can_receive(n, size)) 417 if (!do_virtio_net_can_receive(n, size))
371 - return; 418 + return 0;
372 419
373 if (!receive_filter(n, buf, size)) 420 if (!receive_filter(n, buf, size))
374 - return; 421 + return size;
375 422
376 /* hdr_len refers to the header we supply to the guest */ 423 /* hdr_len refers to the header we supply to the guest */
377 hdr_len = n->mergeable_rx_bufs ? 424 hdr_len = n->mergeable_rx_bufs ?
@@ -389,7 +436,7 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size) @@ -389,7 +436,7 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
389 if ((i != 0 && !n->mergeable_rx_bufs) || 436 if ((i != 0 && !n->mergeable_rx_bufs) ||
390 virtqueue_pop(n->rx_vq, &elem) == 0) { 437 virtqueue_pop(n->rx_vq, &elem) == 0) {
391 if (i == 0) 438 if (i == 0)
392 - return; 439 + return -1;
393 fprintf(stderr, "virtio-net truncating packet\n"); 440 fprintf(stderr, "virtio-net truncating packet\n");
394 exit(1); 441 exit(1);
395 } 442 }
@@ -431,6 +478,8 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size) @@ -431,6 +478,8 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size)
431 478
432 virtqueue_flush(n->rx_vq, i); 479 virtqueue_flush(n->rx_vq, i);
433 virtio_notify(&n->vdev, n->rx_vq); 480 virtio_notify(&n->vdev, n->rx_vq);
  481 +
  482 + return size;
434 } 483 }
435 484
436 /* TX */ 485 /* TX */
@@ -518,16 +567,24 @@ static void virtio_net_save(QEMUFile *f, void *opaque) @@ -518,16 +567,24 @@ static void virtio_net_save(QEMUFile *f, void *opaque)
518 qemu_put_be32(f, n->tx_timer_active); 567 qemu_put_be32(f, n->tx_timer_active);
519 qemu_put_be32(f, n->mergeable_rx_bufs); 568 qemu_put_be32(f, n->mergeable_rx_bufs);
520 qemu_put_be16(f, n->status); 569 qemu_put_be16(f, n->status);
521 - qemu_put_be32(f, n->promisc);  
522 - qemu_put_be32(f, n->allmulti); 570 + qemu_put_byte(f, n->promisc);
  571 + qemu_put_byte(f, n->allmulti);
523 qemu_put_be32(f, n->mac_table.in_use); 572 qemu_put_be32(f, n->mac_table.in_use);
524 qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN); 573 qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN);
525 qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3); 574 qemu_put_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
  575 + qemu_put_be32(f, 0); /* vnet-hdr placeholder */
  576 + qemu_put_byte(f, n->mac_table.multi_overflow);
  577 + qemu_put_byte(f, n->mac_table.uni_overflow);
  578 + qemu_put_byte(f, n->alluni);
  579 + qemu_put_byte(f, n->nomulti);
  580 + qemu_put_byte(f, n->nouni);
  581 + qemu_put_byte(f, n->nobcast);
526 } 582 }
527 583
528 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) 584 static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
529 { 585 {
530 VirtIONet *n = opaque; 586 VirtIONet *n = opaque;
  587 + int i;
531 588
532 if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION) 589 if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION)
533 return -EINVAL; 590 return -EINVAL;
@@ -542,8 +599,13 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) @@ -542,8 +599,13 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
542 n->status = qemu_get_be16(f); 599 n->status = qemu_get_be16(f);
543 600
544 if (version_id >= 4) { 601 if (version_id >= 4) {
545 - n->promisc = qemu_get_be32(f);  
546 - n->allmulti = qemu_get_be32(f); 602 + if (version_id < 8) {
  603 + n->promisc = qemu_get_be32(f);
  604 + n->allmulti = qemu_get_be32(f);
  605 + } else {
  606 + n->promisc = qemu_get_byte(f);
  607 + n->allmulti = qemu_get_byte(f);
  608 + }
547 } 609 }
548 610
549 if (version_id >= 5) { 611 if (version_id >= 5) {
@@ -554,7 +616,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) @@ -554,7 +616,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
554 n->mac_table.in_use * ETH_ALEN); 616 n->mac_table.in_use * ETH_ALEN);
555 } else if (n->mac_table.in_use) { 617 } else if (n->mac_table.in_use) {
556 qemu_fseek(f, n->mac_table.in_use * ETH_ALEN, SEEK_CUR); 618 qemu_fseek(f, n->mac_table.in_use * ETH_ALEN, SEEK_CUR);
557 - n->promisc = 1; 619 + n->mac_table.multi_overflow = n->mac_table.uni_overflow = 1;
558 n->mac_table.in_use = 0; 620 n->mac_table.in_use = 0;
559 } 621 }
560 } 622 }
@@ -562,6 +624,32 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) @@ -562,6 +624,32 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id)
562 if (version_id >= 6) 624 if (version_id >= 6)
563 qemu_get_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3); 625 qemu_get_buffer(f, (uint8_t *)n->vlans, MAX_VLAN >> 3);
564 626
  627 + if (version_id >= 7 && qemu_get_be32(f)) {
  628 + fprintf(stderr,
  629 + "virtio-net: saved image requires vnet header support\n");
  630 + exit(1);
  631 + }
  632 +
  633 + if (version_id >= 9) {
  634 + n->mac_table.multi_overflow = qemu_get_byte(f);
  635 + n->mac_table.uni_overflow = qemu_get_byte(f);
  636 + }
  637 +
  638 + if (version_id >= 10) {
  639 + n->alluni = qemu_get_byte(f);
  640 + n->nomulti = qemu_get_byte(f);
  641 + n->nouni = qemu_get_byte(f);
  642 + n->nobcast = qemu_get_byte(f);
  643 + }
  644 +
  645 + /* Find the first multicast entry in the saved MAC filter */
  646 + for (i = 0; i < n->mac_table.in_use; i++) {
  647 + if (n->mac_table.macs[i * ETH_ALEN] & 1) {
  648 + break;
  649 + }
  650 + }
  651 + n->mac_table.first_multi = i;
  652 +
565 if (n->tx_timer_active) { 653 if (n->tx_timer_active) {
566 qemu_mod_timer(n->tx_timer, 654 qemu_mod_timer(n->tx_timer,
567 qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL); 655 qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL);
@@ -602,12 +690,12 @@ VirtIODevice *virtio_net_init(DeviceState *dev) @@ -602,12 +690,12 @@ VirtIODevice *virtio_net_init(DeviceState *dev)
602 n->vdev.reset = virtio_net_reset; 690 n->vdev.reset = virtio_net_reset;
603 n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx); 691 n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
604 n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx); 692 n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
605 - n->ctrl_vq = virtio_add_queue(&n->vdev, 16, virtio_net_handle_ctrl); 693 + n->ctrl_vq = virtio_add_queue(&n->vdev, 64, virtio_net_handle_ctrl);
606 qdev_get_macaddr(dev, n->mac); 694 qdev_get_macaddr(dev, n->mac);
607 n->status = VIRTIO_NET_S_LINK_UP; 695 n->status = VIRTIO_NET_S_LINK_UP;
608 n->vc = qdev_get_vlan_client(dev, 696 n->vc = qdev_get_vlan_client(dev,
609 - virtio_net_receive,  
610 virtio_net_can_receive, 697 virtio_net_can_receive,
  698 + virtio_net_receive, NULL,
611 virtio_net_cleanup, n); 699 virtio_net_cleanup, n);
612 n->vc->link_status_changed = virtio_net_set_link_status; 700 n->vc->link_status_changed = virtio_net_set_link_status;
613 701
hw/virtio-net.h
@@ -43,6 +43,7 @@ @@ -43,6 +43,7 @@
43 #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ 43 #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */
44 #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ 44 #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */
45 #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */ 45 #define VIRTIO_NET_F_CTRL_VLAN 19 /* Control channel VLAN filtering */
  46 +#define VIRTIO_NET_F_CTRL_RX_EXTRA 20 /* Extra RX mode control support */
46 47
47 #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */ 48 #define VIRTIO_NET_S_LINK_UP 1 /* Link is up */
48 49
@@ -103,14 +104,19 @@ typedef uint8_t virtio_net_ctrl_ack; @@ -103,14 +104,19 @@ typedef uint8_t virtio_net_ctrl_ack;
103 #define VIRTIO_NET_ERR 1 104 #define VIRTIO_NET_ERR 1
104 105
105 /* 106 /*
106 - * Control the RX mode, ie. promisucous and allmulti. PROMISC and  
107 - * ALLMULTI commands require an "out" sg entry containing a 1 byte  
108 - * state value, zero = disable, non-zero = enable. These commands  
109 - * are supported with the VIRTIO_NET_F_CTRL_RX feature. 107 + * Control the RX mode, ie. promisucous, allmulti, etc...
  108 + * All commands require an "out" sg entry containing a 1 byte
  109 + * state value, zero = disable, non-zero = enable. Commands
  110 + * 0 and 1 are supported with the VIRTIO_NET_F_CTRL_RX feature.
  111 + * Commands 2-5 are added with VIRTIO_NET_F_CTRL_RX_EXTRA.
110 */ 112 */
111 #define VIRTIO_NET_CTRL_RX_MODE 0 113 #define VIRTIO_NET_CTRL_RX_MODE 0
112 #define VIRTIO_NET_CTRL_RX_MODE_PROMISC 0 114 #define VIRTIO_NET_CTRL_RX_MODE_PROMISC 0
113 #define VIRTIO_NET_CTRL_RX_MODE_ALLMULTI 1 115 #define VIRTIO_NET_CTRL_RX_MODE_ALLMULTI 1
  116 + #define VIRTIO_NET_CTRL_RX_MODE_ALLUNI 2
  117 + #define VIRTIO_NET_CTRL_RX_MODE_NOMULTI 3
  118 + #define VIRTIO_NET_CTRL_RX_MODE_NOUNI 4
  119 + #define VIRTIO_NET_CTRL_RX_MODE_NOBCAST 5
114 120
115 /* 121 /*
116 * Control the MAC filter table. 122 * Control the MAC filter table.
hw/xen_nic.c
@@ -223,9 +223,9 @@ static void net_rx_response(struct XenNetDev *netdev, @@ -223,9 +223,9 @@ static void net_rx_response(struct XenNetDev *netdev,
223 223
224 #define NET_IP_ALIGN 2 224 #define NET_IP_ALIGN 2
225 225
226 -static int net_rx_ok(void *opaque) 226 +static int net_rx_ok(VLANClientState *vc)
227 { 227 {
228 - struct XenNetDev *netdev = opaque; 228 + struct XenNetDev *netdev = vc->opaque;
229 RING_IDX rc, rp; 229 RING_IDX rc, rp;
230 230
231 if (netdev->xendev.be_state != XenbusStateConnected) 231 if (netdev->xendev.be_state != XenbusStateConnected)
@@ -243,15 +243,15 @@ static int net_rx_ok(void *opaque) @@ -243,15 +243,15 @@ static int net_rx_ok(void *opaque)
243 return 1; 243 return 1;
244 } 244 }
245 245
246 -static void net_rx_packet(void *opaque, const uint8_t *buf, int size) 246 +static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
247 { 247 {
248 - struct XenNetDev *netdev = opaque; 248 + struct XenNetDev *netdev = vc->opaque;
249 netif_rx_request_t rxreq; 249 netif_rx_request_t rxreq;
250 RING_IDX rc, rp; 250 RING_IDX rc, rp;
251 void *page; 251 void *page;
252 252
253 if (netdev->xendev.be_state != XenbusStateConnected) 253 if (netdev->xendev.be_state != XenbusStateConnected)
254 - return; 254 + return -1;
255 255
256 rc = netdev->rx_ring.req_cons; 256 rc = netdev->rx_ring.req_cons;
257 rp = netdev->rx_ring.sring->req_prod; 257 rp = netdev->rx_ring.sring->req_prod;
@@ -259,12 +259,12 @@ static void net_rx_packet(void *opaque, const uint8_t *buf, int size) @@ -259,12 +259,12 @@ static void net_rx_packet(void *opaque, const uint8_t *buf, int size)
259 259
260 if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) { 260 if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) {
261 xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n"); 261 xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n");
262 - return; 262 + return -1;
263 } 263 }
264 if (size > XC_PAGE_SIZE - NET_IP_ALIGN) { 264 if (size > XC_PAGE_SIZE - NET_IP_ALIGN) {
265 - xen_be_printf(&netdev->xendev, 0, "packet too big (%d > %ld)",  
266 - size, XC_PAGE_SIZE - NET_IP_ALIGN);  
267 - return; 265 + xen_be_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)",
  266 + (unsigned long)size, XC_PAGE_SIZE - NET_IP_ALIGN);
  267 + return -1;
268 } 268 }
269 269
270 memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq)); 270 memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));
@@ -277,11 +277,13 @@ static void net_rx_packet(void *opaque, const uint8_t *buf, int size) @@ -277,11 +277,13 @@ static void net_rx_packet(void *opaque, const uint8_t *buf, int size)
277 xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n", 277 xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n",
278 rxreq.gref); 278 rxreq.gref);
279 net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); 279 net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0);
280 - return; 280 + return -1;
281 } 281 }
282 memcpy(page + NET_IP_ALIGN, buf, size); 282 memcpy(page + NET_IP_ALIGN, buf, size);
283 xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1); 283 xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);
284 net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0); 284 net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);
  285 +
  286 + return size;
285 } 287 }
286 288
287 /* ------------------------------------------------------------- */ 289 /* ------------------------------------------------------------- */
@@ -301,8 +303,8 @@ static int net_init(struct XenDevice *xendev) @@ -301,8 +303,8 @@ static int net_init(struct XenDevice *xendev)
301 303
302 vlan = qemu_find_vlan(netdev->xendev.dev); 304 vlan = qemu_find_vlan(netdev->xendev.dev);
303 netdev->vs = qemu_new_vlan_client(vlan, "xen", NULL, 305 netdev->vs = qemu_new_vlan_client(vlan, "xen", NULL,
304 - net_rx_packet, net_rx_ok, NULL,  
305 - netdev); 306 + net_rx_ok, net_rx_packet, NULL,
  307 + NULL, netdev);
306 snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str), 308 snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str),
307 "nic: xenbus vif macaddr=%s", netdev->mac); 309 "nic: xenbus vif macaddr=%s", netdev->mac);
308 310
@@ -332,8 +332,9 @@ static char *assign_name(VLANClientState *vc1, const char *model) @@ -332,8 +332,9 @@ static char *assign_name(VLANClientState *vc1, const char *model)
332 VLANClientState *qemu_new_vlan_client(VLANState *vlan, 332 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
333 const char *model, 333 const char *model,
334 const char *name, 334 const char *name,
335 - IOReadHandler *fd_read,  
336 - IOCanRWHandler *fd_can_read, 335 + NetCanReceive *can_receive,
  336 + NetReceive *receive,
  337 + NetReceiveIOV *receive_iov,
337 NetCleanup *cleanup, 338 NetCleanup *cleanup,
338 void *opaque) 339 void *opaque)
339 { 340 {
@@ -344,8 +345,9 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, @@ -344,8 +345,9 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
344 vc->name = strdup(name); 345 vc->name = strdup(name);
345 else 346 else
346 vc->name = assign_name(vc, model); 347 vc->name = assign_name(vc, model);
347 - vc->fd_read = fd_read;  
348 - vc->fd_can_read = fd_can_read; 348 + vc->can_receive = can_receive;
  349 + vc->receive = receive;
  350 + vc->receive_iov = receive_iov;
349 vc->cleanup = cleanup; 351 vc->cleanup = cleanup;
350 vc->opaque = opaque; 352 vc->opaque = opaque;
351 vc->vlan = vlan; 353 vc->vlan = vlan;
@@ -389,61 +391,126 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque) @@ -389,61 +391,126 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque)
389 return NULL; 391 return NULL;
390 } 392 }
391 393
392 -int qemu_can_send_packet(VLANClientState *vc1) 394 +int qemu_can_send_packet(VLANClientState *sender)
393 { 395 {
394 - VLANState *vlan = vc1->vlan; 396 + VLANState *vlan = sender->vlan;
395 VLANClientState *vc; 397 VLANClientState *vc;
396 398
397 - for(vc = vlan->first_client; vc != NULL; vc = vc->next) {  
398 - if (vc != vc1) {  
399 - if (vc->fd_can_read && vc->fd_can_read(vc->opaque))  
400 - return 1; 399 + for (vc = vlan->first_client; vc != NULL; vc = vc->next) {
  400 + if (vc == sender) {
  401 + continue;
  402 + }
  403 +
  404 + /* no can_receive() handler, they can always receive */
  405 + if (!vc->can_receive || vc->can_receive(vc)) {
  406 + return 1;
401 } 407 }
402 } 408 }
403 return 0; 409 return 0;
404 } 410 }
405 411
406 -static void 412 +static int
407 qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size) 413 qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size)
408 { 414 {
409 VLANClientState *vc; 415 VLANClientState *vc;
  416 + int ret = -1;
  417 +
  418 + sender->vlan->delivering = 1;
410 419
411 for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) { 420 for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
412 - if (vc != sender && !vc->link_down) {  
413 - vc->fd_read(vc->opaque, buf, size); 421 + ssize_t len;
  422 +
  423 + if (vc == sender) {
  424 + continue;
414 } 425 }
  426 +
  427 + if (vc->link_down) {
  428 + ret = size;
  429 + continue;
  430 + }
  431 +
  432 + len = vc->receive(vc, buf, size);
  433 +
  434 + ret = (ret >= 0) ? ret : len;
415 } 435 }
  436 +
  437 + sender->vlan->delivering = 0;
  438 +
  439 + return ret;
416 } 440 }
417 441
418 -void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size) 442 +void qemu_flush_queued_packets(VLANClientState *vc)
419 { 443 {
420 - VLANState *vlan = vc->vlan;  
421 VLANPacket *packet; 444 VLANPacket *packet;
422 445
423 - if (vc->link_down)  
424 - return; 446 + while ((packet = vc->vlan->send_queue) != NULL) {
  447 + int ret;
  448 +
  449 + vc->vlan->send_queue = packet->next;
  450 +
  451 + ret = qemu_deliver_packet(packet->sender, packet->data, packet->size);
  452 + if (ret == 0 && packet->sent_cb != NULL) {
  453 + packet->next = vc->vlan->send_queue;
  454 + vc->vlan->send_queue = packet;
  455 + break;
  456 + }
  457 +
  458 + if (packet->sent_cb)
  459 + packet->sent_cb(packet->sender);
  460 +
  461 + qemu_free(packet);
  462 + }
  463 +}
  464 +
  465 +static void qemu_enqueue_packet(VLANClientState *sender,
  466 + const uint8_t *buf, int size,
  467 + NetPacketSent *sent_cb)
  468 +{
  469 + VLANPacket *packet;
  470 +
  471 + packet = qemu_malloc(sizeof(VLANPacket) + size);
  472 + packet->next = sender->vlan->send_queue;
  473 + packet->sender = sender;
  474 + packet->size = size;
  475 + packet->sent_cb = sent_cb;
  476 + memcpy(packet->data, buf, size);
  477 + sender->vlan->send_queue = packet;
  478 +}
  479 +
  480 +ssize_t qemu_send_packet_async(VLANClientState *sender,
  481 + const uint8_t *buf, int size,
  482 + NetPacketSent *sent_cb)
  483 +{
  484 + int ret;
  485 +
  486 + if (sender->link_down) {
  487 + return size;
  488 + }
425 489
426 #ifdef DEBUG_NET 490 #ifdef DEBUG_NET
427 - printf("vlan %d send:\n", vlan->id); 491 + printf("vlan %d send:\n", sender->vlan->id);
428 hex_dump(stdout, buf, size); 492 hex_dump(stdout, buf, size);
429 #endif 493 #endif
430 - if (vlan->delivering) {  
431 - packet = qemu_malloc(sizeof(VLANPacket) + size);  
432 - packet->next = vlan->send_queue;  
433 - packet->sender = vc;  
434 - packet->size = size;  
435 - memcpy(packet->data, buf, size);  
436 - vlan->send_queue = packet;  
437 - } else {  
438 - vlan->delivering = 1;  
439 - qemu_deliver_packet(vc, buf, size);  
440 - while ((packet = vlan->send_queue) != NULL) {  
441 - qemu_deliver_packet(packet->sender, packet->data, packet->size);  
442 - vlan->send_queue = packet->next;  
443 - qemu_free(packet);  
444 - }  
445 - vlan->delivering = 0; 494 +
  495 + if (sender->vlan->delivering) {
  496 + qemu_enqueue_packet(sender, buf, size, NULL);
  497 + return size;
  498 + }
  499 +
  500 + ret = qemu_deliver_packet(sender, buf, size);
  501 + if (ret == 0 && sent_cb != NULL) {
  502 + qemu_enqueue_packet(sender, buf, size, sent_cb);
  503 + return 0;
446 } 504 }
  505 +
  506 + qemu_flush_queued_packets(sender);
  507 +
  508 + return ret;
  509 +}
  510 +
  511 +void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size)
  512 +{
  513 + qemu_send_packet_async(vc, buf, size, NULL);
447 } 514 }
448 515
449 static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov, 516 static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
@@ -461,9 +528,7 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov, @@ -461,9 +528,7 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
461 offset += len; 528 offset += len;
462 } 529 }
463 530
464 - vc->fd_read(vc->opaque, buffer, offset);  
465 -  
466 - return offset; 531 + return vc->receive(vc, buffer, offset);
467 } 532 }
468 533
469 static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt) 534 static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
@@ -476,44 +541,133 @@ static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt) @@ -476,44 +541,133 @@ static ssize_t calc_iov_length(const struct iovec *iov, int iovcnt)
476 return offset; 541 return offset;
477 } 542 }
478 543
479 -ssize_t qemu_sendv_packet(VLANClientState *vc1, const struct iovec *iov,  
480 - int iovcnt) 544 +static int qemu_deliver_packet_iov(VLANClientState *sender,
  545 + const struct iovec *iov, int iovcnt)
481 { 546 {
482 - VLANState *vlan = vc1->vlan;  
483 VLANClientState *vc; 547 VLANClientState *vc;
484 - ssize_t max_len = 0; 548 + int ret = -1;
485 549
486 - if (vc1->link_down)  
487 - return calc_iov_length(iov, iovcnt); 550 + sender->vlan->delivering = 1;
488 551
489 - for (vc = vlan->first_client; vc != NULL; vc = vc->next) {  
490 - ssize_t len = 0; 552 + for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
  553 + ssize_t len;
  554 +
  555 + if (vc == sender) {
  556 + continue;
  557 + }
491 558
492 - if (vc == vc1) 559 + if (vc->link_down) {
  560 + ret = calc_iov_length(iov, iovcnt);
493 continue; 561 continue;
  562 + }
494 563
495 - if (vc->link_down)  
496 - len = calc_iov_length(iov, iovcnt);  
497 - if (vc->fd_readv)  
498 - len = vc->fd_readv(vc->opaque, iov, iovcnt);  
499 - else if (vc->fd_read) 564 + if (vc->receive_iov) {
  565 + len = vc->receive_iov(vc, iov, iovcnt);
  566 + } else {
500 len = vc_sendv_compat(vc, iov, iovcnt); 567 len = vc_sendv_compat(vc, iov, iovcnt);
  568 + }
501 569
502 - max_len = MAX(max_len, len); 570 + ret = (ret >= 0) ? ret : len;
503 } 571 }
504 572
505 - return max_len; 573 + sender->vlan->delivering = 0;
  574 +
  575 + return ret;
  576 +}
  577 +
  578 +static ssize_t qemu_enqueue_packet_iov(VLANClientState *sender,
  579 + const struct iovec *iov, int iovcnt,
  580 + NetPacketSent *sent_cb)
  581 +{
  582 + VLANPacket *packet;
  583 + size_t max_len = 0;
  584 + int i;
  585 +
  586 + max_len = calc_iov_length(iov, iovcnt);
  587 +
  588 + packet = qemu_malloc(sizeof(VLANPacket) + max_len);
  589 + packet->next = sender->vlan->send_queue;
  590 + packet->sender = sender;
  591 + packet->sent_cb = sent_cb;
  592 + packet->size = 0;
  593 +
  594 + for (i = 0; i < iovcnt; i++) {
  595 + size_t len = iov[i].iov_len;
  596 +
  597 + memcpy(packet->data + packet->size, iov[i].iov_base, len);
  598 + packet->size += len;
  599 + }
  600 +
  601 + sender->vlan->send_queue = packet;
  602 +
  603 + return packet->size;
  604 +}
  605 +
  606 +ssize_t qemu_sendv_packet_async(VLANClientState *sender,
  607 + const struct iovec *iov, int iovcnt,
  608 + NetPacketSent *sent_cb)
  609 +{
  610 + int ret;
  611 +
  612 + if (sender->link_down) {
  613 + return calc_iov_length(iov, iovcnt);
  614 + }
  615 +
  616 + if (sender->vlan->delivering) {
  617 + return qemu_enqueue_packet_iov(sender, iov, iovcnt, NULL);
  618 + }
  619 +
  620 + ret = qemu_deliver_packet_iov(sender, iov, iovcnt);
  621 + if (ret == 0 && sent_cb != NULL) {
  622 + qemu_enqueue_packet_iov(sender, iov, iovcnt, sent_cb);
  623 + return 0;
  624 + }
  625 +
  626 + qemu_flush_queued_packets(sender);
  627 +
  628 + return ret;
  629 +}
  630 +
  631 +ssize_t
  632 +qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, int iovcnt)
  633 +{
  634 + return qemu_sendv_packet_async(vc, iov, iovcnt, NULL);
  635 +}
  636 +
  637 +static void config_error(Monitor *mon, const char *fmt, ...)
  638 +{
  639 + va_list ap;
  640 +
  641 + va_start(ap, fmt);
  642 + if (mon) {
  643 + monitor_vprintf(mon, fmt, ap);
  644 + } else {
  645 + fprintf(stderr, "qemu: ");
  646 + vfprintf(stderr, fmt, ap);
  647 + exit(1);
  648 + }
  649 + va_end(ap);
506 } 650 }
507 651
508 #if defined(CONFIG_SLIRP) 652 #if defined(CONFIG_SLIRP)
509 653
510 /* slirp network adapter */ 654 /* slirp network adapter */
511 655
  656 +struct slirp_config_str {
  657 + struct slirp_config_str *next;
  658 + const char *str;
  659 +};
  660 +
512 static int slirp_inited; 661 static int slirp_inited;
513 -static int slirp_restrict;  
514 -static char *slirp_ip; 662 +static struct slirp_config_str *slirp_redirs;
  663 +#ifndef _WIN32
  664 +static const char *slirp_smb_export;
  665 +#endif
515 static VLANClientState *slirp_vc; 666 static VLANClientState *slirp_vc;
516 667
  668 +static void slirp_smb(const char *exported_dir);
  669 +static void slirp_redirection(Monitor *mon, const char *redir_str);
  670 +
517 int slirp_can_output(void) 671 int slirp_can_output(void)
518 { 672 {
519 return !slirp_vc || qemu_can_send_packet(slirp_vc); 673 return !slirp_vc || qemu_can_send_packet(slirp_vc);
@@ -535,13 +689,14 @@ int slirp_is_inited(void) @@ -535,13 +689,14 @@ int slirp_is_inited(void)
535 return slirp_inited; 689 return slirp_inited;
536 } 690 }
537 691
538 -static void slirp_receive(void *opaque, const uint8_t *buf, int size) 692 +static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
539 { 693 {
540 #ifdef DEBUG_SLIRP 694 #ifdef DEBUG_SLIRP
541 printf("slirp input:\n"); 695 printf("slirp input:\n");
542 hex_dump(stdout, buf, size); 696 hex_dump(stdout, buf, size);
543 #endif 697 #endif
544 slirp_input(buf, size); 698 slirp_input(buf, size);
  699 + return size;
545 } 700 }
546 701
547 static int slirp_in_use; 702 static int slirp_in_use;
@@ -551,7 +706,8 @@ static void net_slirp_cleanup(VLANClientState *vc) @@ -551,7 +706,8 @@ static void net_slirp_cleanup(VLANClientState *vc)
551 slirp_in_use = 0; 706 slirp_in_use = 0;
552 } 707 }
553 708
554 -static int net_slirp_init(VLANState *vlan, const char *model, const char *name) 709 +static int net_slirp_init(VLANState *vlan, const char *model, const char *name,
  710 + int restricted, const char *ip)
555 { 711 {
556 if (slirp_in_use) { 712 if (slirp_in_use) {
557 /* slirp only supports a single instance so far */ 713 /* slirp only supports a single instance so far */
@@ -559,10 +715,24 @@ static int net_slirp_init(VLANState *vlan, const char *model, const char *name) @@ -559,10 +715,24 @@ static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
559 } 715 }
560 if (!slirp_inited) { 716 if (!slirp_inited) {
561 slirp_inited = 1; 717 slirp_inited = 1;
562 - slirp_init(slirp_restrict, slirp_ip); 718 + slirp_init(restricted, ip);
  719 +
  720 + while (slirp_redirs) {
  721 + struct slirp_config_str *config = slirp_redirs;
  722 +
  723 + slirp_redirection(NULL, config->str);
  724 + slirp_redirs = config->next;
  725 + qemu_free(config);
  726 + }
  727 +#ifndef _WIN32
  728 + if (slirp_smb_export) {
  729 + slirp_smb(slirp_smb_export);
  730 + }
  731 +#endif
563 } 732 }
564 - slirp_vc = qemu_new_vlan_client(vlan, model, name,  
565 - slirp_receive, NULL, net_slirp_cleanup, NULL); 733 +
  734 + slirp_vc = qemu_new_vlan_client(vlan, model, name, NULL, slirp_receive,
  735 + NULL, net_slirp_cleanup, NULL);
566 slirp_vc->info_str[0] = '\0'; 736 slirp_vc->info_str[0] = '\0';
567 slirp_in_use = 1; 737 slirp_in_use = 1;
568 return 0; 738 return 0;
@@ -643,32 +813,18 @@ static void net_slirp_redir_rm(Monitor *mon, const char *port_str) @@ -643,32 +813,18 @@ static void net_slirp_redir_rm(Monitor *mon, const char *port_str)
643 monitor_printf(mon, "invalid format\n"); 813 monitor_printf(mon, "invalid format\n");
644 } 814 }
645 815
646 -void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2) 816 +static void slirp_redirection(Monitor *mon, const char *redir_str)
647 { 817 {
648 - int is_udp;  
649 - char buf[256], *r;  
650 - const char *p, *errmsg;  
651 struct in_addr guest_addr; 818 struct in_addr guest_addr;
652 int host_port, guest_port; 819 int host_port, guest_port;
653 -  
654 - if (!slirp_inited) {  
655 - slirp_inited = 1;  
656 - slirp_init(slirp_restrict, slirp_ip);  
657 - }  
658 -  
659 - if (!strcmp(redir_str, "remove")) {  
660 - net_slirp_redir_rm(mon, redir_opt2);  
661 - return;  
662 - }  
663 -  
664 - if (!strcmp(redir_str, "list")) {  
665 - net_slirp_redir_list(mon);  
666 - return;  
667 - } 820 + const char *p;
  821 + char buf[256], *r;
  822 + int is_udp;
668 823
669 p = redir_str; 824 p = redir_str;
670 - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) 825 + if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
671 goto fail_syntax; 826 goto fail_syntax;
  827 + }
672 if (!strcmp(buf, "tcp") || buf[0] == '\0') { 828 if (!strcmp(buf, "tcp") || buf[0] == '\0') {
673 is_udp = 0; 829 is_udp = 0;
674 } else if (!strcmp(buf, "udp")) { 830 } else if (!strcmp(buf, "udp")) {
@@ -677,39 +833,65 @@ void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2 @@ -677,39 +833,65 @@ void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2
677 goto fail_syntax; 833 goto fail_syntax;
678 } 834 }
679 835
680 - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) 836 + if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
681 goto fail_syntax; 837 goto fail_syntax;
  838 + }
682 host_port = strtol(buf, &r, 0); 839 host_port = strtol(buf, &r, 0);
683 - if (r == buf) 840 + if (r == buf) {
684 goto fail_syntax; 841 goto fail_syntax;
  842 + }
685 843
686 - if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) 844 + if (get_str_sep(buf, sizeof(buf), &p, ':') < 0) {
687 goto fail_syntax; 845 goto fail_syntax;
  846 + }
688 if (buf[0] == '\0') { 847 if (buf[0] == '\0') {
689 pstrcpy(buf, sizeof(buf), "10.0.2.15"); 848 pstrcpy(buf, sizeof(buf), "10.0.2.15");
690 } 849 }
691 - if (!inet_aton(buf, &guest_addr)) 850 + if (!inet_aton(buf, &guest_addr)) {
692 goto fail_syntax; 851 goto fail_syntax;
  852 + }
693 853
694 guest_port = strtol(p, &r, 0); 854 guest_port = strtol(p, &r, 0);
695 - if (r == p) 855 + if (r == p) {
696 goto fail_syntax; 856 goto fail_syntax;
  857 + }
697 858
698 if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) { 859 if (slirp_redir(is_udp, host_port, guest_addr, guest_port) < 0) {
699 - errmsg = "could not set up redirection\n";  
700 - goto fail; 860 + config_error(mon, "could not set up redirection '%s'\n", redir_str);
701 } 861 }
702 return; 862 return;
703 863
704 fail_syntax: 864 fail_syntax:
705 - errmsg = "invalid redirection format\n";  
706 - fail:  
707 - if (mon) {  
708 - monitor_printf(mon, "%s", errmsg);  
709 - } else {  
710 - fprintf(stderr, "qemu: %s", errmsg);  
711 - exit(1); 865 + config_error(mon, "invalid redirection format '%s'\n", redir_str);
  866 +}
  867 +
  868 +void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2)
  869 +{
  870 + struct slirp_config_str *config;
  871 +
  872 + if (!slirp_inited) {
  873 + if (mon) {
  874 + monitor_printf(mon, "user mode network stack not in use\n");
  875 + } else {
  876 + config = qemu_malloc(sizeof(*config));
  877 + config->str = redir_str;
  878 + config->next = slirp_redirs;
  879 + slirp_redirs = config;
  880 + }
  881 + return;
  882 + }
  883 +
  884 + if (!strcmp(redir_str, "remove")) {
  885 + net_slirp_redir_rm(mon, redir_opt2);
  886 + return;
  887 + }
  888 +
  889 + if (!strcmp(redir_str, "list")) {
  890 + net_slirp_redir_list(mon);
  891 + return;
712 } 892 }
  893 +
  894 + slirp_redirection(mon, redir_str);
713 } 895 }
714 896
715 #ifndef _WIN32 897 #ifndef _WIN32
@@ -747,18 +929,12 @@ static void smb_exit(void) @@ -747,18 +929,12 @@ static void smb_exit(void)
747 erase_dir(smb_dir); 929 erase_dir(smb_dir);
748 } 930 }
749 931
750 -/* automatic user mode samba server configuration */  
751 -void net_slirp_smb(const char *exported_dir) 932 +static void slirp_smb(const char *exported_dir)
752 { 933 {
753 char smb_conf[1024]; 934 char smb_conf[1024];
754 char smb_cmdline[1024]; 935 char smb_cmdline[1024];
755 FILE *f; 936 FILE *f;
756 937
757 - if (!slirp_inited) {  
758 - slirp_inited = 1;  
759 - slirp_init(slirp_restrict, slirp_ip);  
760 - }  
761 -  
762 /* XXX: better tmp dir construction */ 938 /* XXX: better tmp dir construction */
763 snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid()); 939 snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid());
764 if (mkdir(smb_dir, 0700) < 0) { 940 if (mkdir(smb_dir, 0700) < 0) {
@@ -802,7 +978,21 @@ void net_slirp_smb(const char *exported_dir) @@ -802,7 +978,21 @@ void net_slirp_smb(const char *exported_dir)
802 slirp_add_exec(0, smb_cmdline, 4, 139); 978 slirp_add_exec(0, smb_cmdline, 4, 139);
803 } 979 }
804 980
  981 +/* automatic user mode samba server configuration */
  982 +void net_slirp_smb(const char *exported_dir)
  983 +{
  984 + if (slirp_smb_export) {
  985 + fprintf(stderr, "-smb given twice\n");
  986 + exit(1);
  987 + }
  988 + slirp_smb_export = exported_dir;
  989 + if (slirp_inited) {
  990 + slirp_smb(exported_dir);
  991 + }
  992 +}
  993 +
805 #endif /* !defined(_WIN32) */ 994 #endif /* !defined(_WIN32) */
  995 +
806 void do_info_slirp(Monitor *mon) 996 void do_info_slirp(Monitor *mon)
807 { 997 {
808 slirp_stats(); 998 slirp_stats();
@@ -834,14 +1024,15 @@ typedef struct TAPState { @@ -834,14 +1024,15 @@ typedef struct TAPState {
834 int fd; 1024 int fd;
835 char down_script[1024]; 1025 char down_script[1024];
836 char down_script_arg[128]; 1026 char down_script_arg[128];
  1027 + uint8_t buf[4096];
837 } TAPState; 1028 } TAPState;
838 1029
839 static int launch_script(const char *setup_script, const char *ifname, int fd); 1030 static int launch_script(const char *setup_script, const char *ifname, int fd);
840 1031
841 -static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov, 1032 +static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
842 int iovcnt) 1033 int iovcnt)
843 { 1034 {
844 - TAPState *s = opaque; 1035 + TAPState *s = vc->opaque;
845 ssize_t len; 1036 ssize_t len;
846 1037
847 do { 1038 do {
@@ -851,37 +1042,68 @@ static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov, @@ -851,37 +1042,68 @@ static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov,
851 return len; 1042 return len;
852 } 1043 }
853 1044
854 -static void tap_receive(void *opaque, const uint8_t *buf, int size) 1045 +static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
855 { 1046 {
856 - TAPState *s = opaque;  
857 - int ret;  
858 - for(;;) {  
859 - ret = write(s->fd, buf, size);  
860 - if (ret < 0 && (errno == EINTR || errno == EAGAIN)) {  
861 - } else {  
862 - break;  
863 - }  
864 - } 1047 + TAPState *s = vc->opaque;
  1048 + ssize_t len;
  1049 +
  1050 + do {
  1051 + len = write(s->fd, buf, size);
  1052 + } while (len == -1 && (errno == EINTR || errno == EAGAIN));
  1053 +
  1054 + return len;
865 } 1055 }
866 1056
867 -static void tap_send(void *opaque) 1057 +static int tap_can_send(void *opaque)
868 { 1058 {
869 TAPState *s = opaque; 1059 TAPState *s = opaque;
870 - uint8_t buf[4096];  
871 - int size; 1060 +
  1061 + return qemu_can_send_packet(s->vc);
  1062 +}
872 1063
873 #ifdef __sun__ 1064 #ifdef __sun__
  1065 +static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
  1066 +{
874 struct strbuf sbuf; 1067 struct strbuf sbuf;
875 int f = 0; 1068 int f = 0;
876 - sbuf.maxlen = sizeof(buf); 1069 +
  1070 + sbuf.maxlen = maxlen;
877 sbuf.buf = (char *)buf; 1071 sbuf.buf = (char *)buf;
878 - size = getmsg(s->fd, NULL, &sbuf, &f) >=0 ? sbuf.len : -1; 1072 +
  1073 + return getmsg(tapfd, NULL, &sbuf, &f) >= 0 ? sbuf.len : -1;
  1074 +}
879 #else 1075 #else
880 - size = read(s->fd, buf, sizeof(buf)); 1076 +static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen)
  1077 +{
  1078 + return read(tapfd, buf, maxlen);
  1079 +}
881 #endif 1080 #endif
882 - if (size > 0) {  
883 - qemu_send_packet(s->vc, buf, size);  
884 - } 1081 +
  1082 +static void tap_send(void *opaque);
  1083 +
  1084 +static void tap_send_completed(VLANClientState *vc)
  1085 +{
  1086 + TAPState *s = vc->opaque;
  1087 +
  1088 + qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s);
  1089 +}
  1090 +
  1091 +static void tap_send(void *opaque)
  1092 +{
  1093 + TAPState *s = opaque;
  1094 + int size;
  1095 +
  1096 + do {
  1097 + size = tap_read_packet(s->fd, s->buf, sizeof(s->buf));
  1098 + if (size <= 0) {
  1099 + break;
  1100 + }
  1101 +
  1102 + size = qemu_send_packet_async(s->vc, s->buf, size, tap_send_completed);
  1103 + if (size == 0) {
  1104 + qemu_set_fd_handler2(s->fd, NULL, NULL, NULL, NULL);
  1105 + }
  1106 + } while (size > 0);
885 } 1107 }
886 1108
887 static void tap_cleanup(VLANClientState *vc) 1109 static void tap_cleanup(VLANClientState *vc)
@@ -907,10 +1129,9 @@ static TAPState *net_tap_fd_init(VLANState *vlan, @@ -907,10 +1129,9 @@ static TAPState *net_tap_fd_init(VLANState *vlan,
907 1129
908 s = qemu_mallocz(sizeof(TAPState)); 1130 s = qemu_mallocz(sizeof(TAPState));
909 s->fd = fd; 1131 s->fd = fd;
910 - s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive,  
911 - NULL, tap_cleanup, s);  
912 - s->vc->fd_readv = tap_receive_iov;  
913 - qemu_set_fd_handler(s->fd, tap_send, NULL, s); 1132 + s->vc = qemu_new_vlan_client(vlan, model, name, NULL, tap_receive,
  1133 + tap_receive_iov, tap_cleanup, s);
  1134 + qemu_set_fd_handler2(s->fd, tap_can_send, tap_send, NULL, s);
914 snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); 1135 snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd);
915 return s; 1136 return s;
916 } 1137 }
@@ -1107,38 +1328,46 @@ static int tap_open(char *ifname, int ifname_size) @@ -1107,38 +1328,46 @@ static int tap_open(char *ifname, int ifname_size)
1107 1328
1108 static int launch_script(const char *setup_script, const char *ifname, int fd) 1329 static int launch_script(const char *setup_script, const char *ifname, int fd)
1109 { 1330 {
  1331 + sigset_t oldmask, mask;
1110 int pid, status; 1332 int pid, status;
1111 char *args[3]; 1333 char *args[3];
1112 char **parg; 1334 char **parg;
1113 1335
1114 - /* try to launch network script */  
1115 - pid = fork();  
1116 - if (pid >= 0) {  
1117 - if (pid == 0) {  
1118 - int open_max = sysconf (_SC_OPEN_MAX), i;  
1119 - for (i = 0; i < open_max; i++)  
1120 - if (i != STDIN_FILENO &&  
1121 - i != STDOUT_FILENO &&  
1122 - i != STDERR_FILENO &&  
1123 - i != fd)  
1124 - close(i);  
1125 -  
1126 - parg = args;  
1127 - *parg++ = (char *)setup_script;  
1128 - *parg++ = (char *)ifname;  
1129 - *parg++ = NULL;  
1130 - execv(setup_script, args);  
1131 - _exit(1);  
1132 - }  
1133 - while (waitpid(pid, &status, 0) != pid);  
1134 - if (!WIFEXITED(status) ||  
1135 - WEXITSTATUS(status) != 0) {  
1136 - fprintf(stderr, "%s: could not launch network script\n",  
1137 - setup_script);  
1138 - return -1; 1336 + sigemptyset(&mask);
  1337 + sigaddset(&mask, SIGCHLD);
  1338 + sigprocmask(SIG_BLOCK, &mask, &oldmask);
  1339 +
  1340 + /* try to launch network script */
  1341 + pid = fork();
  1342 + if (pid == 0) {
  1343 + int open_max = sysconf(_SC_OPEN_MAX), i;
  1344 +
  1345 + for (i = 0; i < open_max; i++) {
  1346 + if (i != STDIN_FILENO &&
  1347 + i != STDOUT_FILENO &&
  1348 + i != STDERR_FILENO &&
  1349 + i != fd) {
  1350 + close(i);
1139 } 1351 }
1140 } 1352 }
1141 - return 0; 1353 + parg = args;
  1354 + *parg++ = (char *)setup_script;
  1355 + *parg++ = (char *)ifname;
  1356 + *parg++ = NULL;
  1357 + execv(setup_script, args);
  1358 + _exit(1);
  1359 + } else if (pid > 0) {
  1360 + while (waitpid(pid, &status, 0) != pid) {
  1361 + /* loop */
  1362 + }
  1363 + sigprocmask(SIG_SETMASK, &oldmask, NULL);
  1364 +
  1365 + if (WIFEXITED(status) && WEXITSTATUS(status) == 0) {
  1366 + return 0;
  1367 + }
  1368 + }
  1369 + fprintf(stderr, "%s: could not launch network script\n", setup_script);
  1370 + return -1;
1142 } 1371 }
1143 1372
1144 static int net_tap_init(VLANState *vlan, const char *model, 1373 static int net_tap_init(VLANState *vlan, const char *model,
@@ -1194,17 +1423,16 @@ static void vde_to_qemu(void *opaque) @@ -1194,17 +1423,16 @@ static void vde_to_qemu(void *opaque)
1194 } 1423 }
1195 } 1424 }
1196 1425
1197 -static void vde_from_qemu(void *opaque, const uint8_t *buf, int size) 1426 +static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1198 { 1427 {
1199 - VDEState *s = opaque;  
1200 - int ret;  
1201 - for(;;) {  
1202 - ret = vde_send(s->vde, (const char *)buf, size, 0);  
1203 - if (ret < 0 && errno == EINTR) {  
1204 - } else {  
1205 - break;  
1206 - }  
1207 - } 1428 + VDEState *s = vc->opaque;
  1429 + ssize ret;
  1430 +
  1431 + do {
  1432 + ret = vde_send(s->vde, (const char *)buf, size, 0);
  1433 + } while (ret < 0 && errno == EINTR);
  1434 +
  1435 + return ret;
1208 } 1436 }
1209 1437
1210 static void vde_cleanup(VLANClientState *vc) 1438 static void vde_cleanup(VLANClientState *vc)
@@ -1235,7 +1463,7 @@ static int net_vde_init(VLANState *vlan, const char *model, @@ -1235,7 +1463,7 @@ static int net_vde_init(VLANState *vlan, const char *model,
1235 free(s); 1463 free(s);
1236 return -1; 1464 return -1;
1237 } 1465 }
1238 - s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, 1466 + s->vc = qemu_new_vlan_client(vlan, model, name, NULL, vde_receive,
1239 NULL, vde_cleanup, s); 1467 NULL, vde_cleanup, s);
1240 qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); 1468 qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
1241 snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d", 1469 snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
@@ -1263,21 +1491,22 @@ typedef struct NetSocketListenState { @@ -1263,21 +1491,22 @@ typedef struct NetSocketListenState {
1263 } NetSocketListenState; 1491 } NetSocketListenState;
1264 1492
1265 /* XXX: we consider we can send the whole packet without blocking */ 1493 /* XXX: we consider we can send the whole packet without blocking */
1266 -static void net_socket_receive(void *opaque, const uint8_t *buf, int size) 1494 +static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1267 { 1495 {
1268 - NetSocketState *s = opaque; 1496 + NetSocketState *s = vc->opaque;
1269 uint32_t len; 1497 uint32_t len;
1270 len = htonl(size); 1498 len = htonl(size);
1271 1499
1272 send_all(s->fd, (const uint8_t *)&len, sizeof(len)); 1500 send_all(s->fd, (const uint8_t *)&len, sizeof(len));
1273 - send_all(s->fd, buf, size); 1501 + return send_all(s->fd, buf, size);
1274 } 1502 }
1275 1503
1276 -static void net_socket_receive_dgram(void *opaque, const uint8_t *buf, int size) 1504 +static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
1277 { 1505 {
1278 - NetSocketState *s = opaque;  
1279 - sendto(s->fd, buf, size, 0,  
1280 - (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst)); 1506 + NetSocketState *s = vc->opaque;
  1507 +
  1508 + return sendto(s->fd, buf, size, 0,
  1509 + (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
1281 } 1510 }
1282 1511
1283 static void net_socket_send(void *opaque) 1512 static void net_socket_send(void *opaque)
@@ -1473,7 +1702,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, @@ -1473,7 +1702,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
1473 s = qemu_mallocz(sizeof(NetSocketState)); 1702 s = qemu_mallocz(sizeof(NetSocketState));
1474 s->fd = fd; 1703 s->fd = fd;
1475 1704
1476 - s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, 1705 + s->vc = qemu_new_vlan_client(vlan, model, name, NULL, net_socket_receive_dgram,
1477 NULL, net_socket_cleanup, s); 1706 NULL, net_socket_cleanup, s);
1478 qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s); 1707 qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
1479 1708
@@ -1501,7 +1730,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, @@ -1501,7 +1730,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
1501 NetSocketState *s; 1730 NetSocketState *s;
1502 s = qemu_mallocz(sizeof(NetSocketState)); 1731 s = qemu_mallocz(sizeof(NetSocketState));
1503 s->fd = fd; 1732 s->fd = fd;
1504 - s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive, 1733 + s->vc = qemu_new_vlan_client(vlan, model, name, NULL, net_socket_receive,
1505 NULL, net_socket_cleanup, s); 1734 NULL, net_socket_cleanup, s);
1506 snprintf(s->vc->info_str, sizeof(s->vc->info_str), 1735 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
1507 "socket: fd=%d", fd); 1736 "socket: fd=%d", fd);
@@ -1714,16 +1943,16 @@ struct pcap_sf_pkthdr { @@ -1714,16 +1943,16 @@ struct pcap_sf_pkthdr {
1714 uint32_t len; 1943 uint32_t len;
1715 }; 1944 };
1716 1945
1717 -static void dump_receive(void *opaque, const uint8_t *buf, int size) 1946 +static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1718 { 1947 {
1719 - DumpState *s = opaque; 1948 + DumpState *s = vc->opaque;
1720 struct pcap_sf_pkthdr hdr; 1949 struct pcap_sf_pkthdr hdr;
1721 int64_t ts; 1950 int64_t ts;
1722 int caplen; 1951 int caplen;
1723 1952
1724 /* Early return in case of previous error. */ 1953 /* Early return in case of previous error. */
1725 if (s->fd < 0) { 1954 if (s->fd < 0) {
1726 - return; 1955 + return size;
1727 } 1956 }
1728 1957
1729 ts = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec); 1958 ts = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec);
@@ -1739,6 +1968,8 @@ static void dump_receive(void *opaque, const uint8_t *buf, int size) @@ -1739,6 +1968,8 @@ static void dump_receive(void *opaque, const uint8_t *buf, int size)
1739 close(s->fd); 1968 close(s->fd);
1740 s->fd = -1; 1969 s->fd = -1;
1741 } 1970 }
  1971 +
  1972 + return size;
1742 } 1973 }
1743 1974
1744 static void net_dump_cleanup(VLANClientState *vc) 1975 static void net_dump_cleanup(VLANClientState *vc)
@@ -1749,7 +1980,7 @@ static void net_dump_cleanup(VLANClientState *vc) @@ -1749,7 +1980,7 @@ static void net_dump_cleanup(VLANClientState *vc)
1749 qemu_free(s); 1980 qemu_free(s);
1750 } 1981 }
1751 1982
1752 -static int net_dump_init(VLANState *vlan, const char *device, 1983 +static int net_dump_init(Monitor *mon, VLANState *vlan, const char *device,
1753 const char *name, const char *filename, int len) 1984 const char *name, const char *filename, int len)
1754 { 1985 {
1755 struct pcap_file_hdr hdr; 1986 struct pcap_file_hdr hdr;
@@ -1759,7 +1990,7 @@ static int net_dump_init(VLANState *vlan, const char *device, @@ -1759,7 +1990,7 @@ static int net_dump_init(VLANState *vlan, const char *device,
1759 1990
1760 s->fd = open(filename, O_CREAT | O_WRONLY, 0644); 1991 s->fd = open(filename, O_CREAT | O_WRONLY, 0644);
1761 if (s->fd < 0) { 1992 if (s->fd < 0) {
1762 - fprintf(stderr, "-net dump: can't open %s\n", filename); 1993 + config_error(mon, "-net dump: can't open %s\n", filename);
1763 return -1; 1994 return -1;
1764 } 1995 }
1765 1996
@@ -1774,13 +2005,13 @@ static int net_dump_init(VLANState *vlan, const char *device, @@ -1774,13 +2005,13 @@ static int net_dump_init(VLANState *vlan, const char *device,
1774 hdr.linktype = 1; 2005 hdr.linktype = 1;
1775 2006
1776 if (write(s->fd, &hdr, sizeof(hdr)) < sizeof(hdr)) { 2007 if (write(s->fd, &hdr, sizeof(hdr)) < sizeof(hdr)) {
1777 - perror("-net dump write error"); 2008 + config_error(mon, "-net dump write error: %s\n", strerror(errno));
1778 close(s->fd); 2009 close(s->fd);
1779 qemu_free(s); 2010 qemu_free(s);
1780 return -1; 2011 return -1;
1781 } 2012 }
1782 2013
1783 - s->pcap_vc = qemu_new_vlan_client(vlan, device, name, dump_receive, NULL, 2014 + s->pcap_vc = qemu_new_vlan_client(vlan, device, name, NULL, dump_receive, NULL,
1784 net_dump_cleanup, s); 2015 net_dump_cleanup, s);
1785 snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str), 2016 snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str),
1786 "dump to %s (len=%d)", filename, len); 2017 "dump to %s (len=%d)", filename, len);
@@ -1849,7 +2080,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, @@ -1849,7 +2080,7 @@ void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
1849 exit(exit_status); 2080 exit(exit_status);
1850 } 2081 }
1851 2082
1852 -int net_client_init(const char *device, const char *p) 2083 +int net_client_init(Monitor *mon, const char *device, const char *p)
1853 { 2084 {
1854 static const char * const fd_params[] = { 2085 static const char * const fd_params[] = {
1855 "vlan", "name", "fd", NULL 2086 "vlan", "name", "fd", NULL
@@ -1866,7 +2097,7 @@ int net_client_init(const char *device, const char *p) @@ -1866,7 +2097,7 @@ int net_client_init(const char *device, const char *p)
1866 vlan = qemu_find_vlan(vlan_id); 2097 vlan = qemu_find_vlan(vlan_id);
1867 2098
1868 if (get_param_value(buf, sizeof(buf), "name", p)) { 2099 if (get_param_value(buf, sizeof(buf), "name", p)) {
1869 - name = strdup(buf); 2100 + name = qemu_strdup(buf);
1870 } 2101 }
1871 if (!strcmp(device, "nic")) { 2102 if (!strcmp(device, "nic")) {
1872 static const char * const nic_params[] = { 2103 static const char * const nic_params[] = {
@@ -1876,12 +2107,13 @@ int net_client_init(const char *device, const char *p) @@ -1876,12 +2107,13 @@ int net_client_init(const char *device, const char *p)
1876 uint8_t *macaddr; 2107 uint8_t *macaddr;
1877 int idx = nic_get_free_idx(); 2108 int idx = nic_get_free_idx();
1878 2109
1879 - if (check_params(nic_params, p) < 0) {  
1880 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
1881 - return -1; 2110 + if (check_params(buf, sizeof(buf), nic_params, p) < 0) {
  2111 + config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);
  2112 + ret = -1;
  2113 + goto out;
1882 } 2114 }
1883 if (idx == -1 || nb_nics >= MAX_NICS) { 2115 if (idx == -1 || nb_nics >= MAX_NICS) {
1884 - fprintf(stderr, "Too Many NICs\n"); 2116 + config_error(mon, "Too Many NICs\n");
1885 ret = -1; 2117 ret = -1;
1886 goto out; 2118 goto out;
1887 } 2119 }
@@ -1896,7 +2128,7 @@ int net_client_init(const char *device, const char *p) @@ -1896,7 +2128,7 @@ int net_client_init(const char *device, const char *p)
1896 2128
1897 if (get_param_value(buf, sizeof(buf), "macaddr", p)) { 2129 if (get_param_value(buf, sizeof(buf), "macaddr", p)) {
1898 if (parse_macaddr(macaddr, buf) < 0) { 2130 if (parse_macaddr(macaddr, buf) < 0) {
1899 - fprintf(stderr, "invalid syntax for ethernet address\n"); 2131 + config_error(mon, "invalid syntax for ethernet address\n");
1900 ret = -1; 2132 ret = -1;
1901 goto out; 2133 goto out;
1902 } 2134 }
@@ -1914,8 +2146,9 @@ int net_client_init(const char *device, const char *p) @@ -1914,8 +2146,9 @@ int net_client_init(const char *device, const char *p)
1914 } else 2146 } else
1915 if (!strcmp(device, "none")) { 2147 if (!strcmp(device, "none")) {
1916 if (*p != '\0') { 2148 if (*p != '\0') {
1917 - fprintf(stderr, "qemu: 'none' takes no parameters\n");  
1918 - return -1; 2149 + config_error(mon, "'none' takes no parameters\n");
  2150 + ret = -1;
  2151 + goto out;
1919 } 2152 }
1920 /* does nothing. It is needed to signal that no network cards 2153 /* does nothing. It is needed to signal that no network cards
1921 are wanted */ 2154 are wanted */
@@ -1926,21 +2159,26 @@ int net_client_init(const char *device, const char *p) @@ -1926,21 +2159,26 @@ int net_client_init(const char *device, const char *p)
1926 static const char * const slirp_params[] = { 2159 static const char * const slirp_params[] = {
1927 "vlan", "name", "hostname", "restrict", "ip", NULL 2160 "vlan", "name", "hostname", "restrict", "ip", NULL
1928 }; 2161 };
1929 - if (check_params(slirp_params, p) < 0) {  
1930 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
1931 - return -1; 2162 + int restricted = 0;
  2163 + char *ip = NULL;
  2164 +
  2165 + if (check_params(buf, sizeof(buf), slirp_params, p) < 0) {
  2166 + config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);
  2167 + ret = -1;
  2168 + goto out;
1932 } 2169 }
1933 if (get_param_value(buf, sizeof(buf), "hostname", p)) { 2170 if (get_param_value(buf, sizeof(buf), "hostname", p)) {
1934 pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); 2171 pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
1935 } 2172 }
1936 if (get_param_value(buf, sizeof(buf), "restrict", p)) { 2173 if (get_param_value(buf, sizeof(buf), "restrict", p)) {
1937 - slirp_restrict = (buf[0] == 'y') ? 1 : 0; 2174 + restricted = (buf[0] == 'y') ? 1 : 0;
1938 } 2175 }
1939 if (get_param_value(buf, sizeof(buf), "ip", p)) { 2176 if (get_param_value(buf, sizeof(buf), "ip", p)) {
1940 - slirp_ip = strdup(buf); 2177 + ip = qemu_strdup(buf);
1941 } 2178 }
1942 vlan->nb_host_devs++; 2179 vlan->nb_host_devs++;
1943 - ret = net_slirp_init(vlan, device, name); 2180 + ret = net_slirp_init(vlan, device, name, restricted, ip);
  2181 + qemu_free(ip);
1944 } else if (!strcmp(device, "channel")) { 2182 } else if (!strcmp(device, "channel")) {
1945 long port; 2183 long port;
1946 char name[20], *devname; 2184 char name[20], *devname;
@@ -1949,7 +2187,7 @@ int net_client_init(const char *device, const char *p) @@ -1949,7 +2187,7 @@ int net_client_init(const char *device, const char *p)
1949 port = strtol(p, &devname, 10); 2187 port = strtol(p, &devname, 10);
1950 devname++; 2188 devname++;
1951 if (port < 1 || port > 65535) { 2189 if (port < 1 || port > 65535) {
1952 - fprintf(stderr, "vmchannel wrong port number\n"); 2190 + config_error(mon, "vmchannel wrong port number\n");
1953 ret = -1; 2191 ret = -1;
1954 goto out; 2192 goto out;
1955 } 2193 }
@@ -1957,8 +2195,8 @@ int net_client_init(const char *device, const char *p) @@ -1957,8 +2195,8 @@ int net_client_init(const char *device, const char *p)
1957 snprintf(name, 20, "vmchannel%ld", port); 2195 snprintf(name, 20, "vmchannel%ld", port);
1958 vmc->hd = qemu_chr_open(name, devname, NULL); 2196 vmc->hd = qemu_chr_open(name, devname, NULL);
1959 if (!vmc->hd) { 2197 if (!vmc->hd) {
1960 - fprintf(stderr, "qemu: could not open vmchannel device"  
1961 - "'%s'\n", devname); 2198 + config_error(mon, "could not open vmchannel device '%s'\n",
  2199 + devname);
1962 ret = -1; 2200 ret = -1;
1963 goto out; 2201 goto out;
1964 } 2202 }
@@ -1976,12 +2214,13 @@ int net_client_init(const char *device, const char *p) @@ -1976,12 +2214,13 @@ int net_client_init(const char *device, const char *p)
1976 }; 2214 };
1977 char ifname[64]; 2215 char ifname[64];
1978 2216
1979 - if (check_params(tap_params, p) < 0) {  
1980 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
1981 - return -1; 2217 + if (check_params(buf, sizeof(buf), tap_params, p) < 0) {
  2218 + config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);
  2219 + ret = -1;
  2220 + goto out;
1982 } 2221 }
1983 if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { 2222 if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
1984 - fprintf(stderr, "tap: no interface name\n"); 2223 + config_error(mon, "tap: no interface name\n");
1985 ret = -1; 2224 ret = -1;
1986 goto out; 2225 goto out;
1987 } 2226 }
@@ -1991,14 +2230,15 @@ int net_client_init(const char *device, const char *p) @@ -1991,14 +2230,15 @@ int net_client_init(const char *device, const char *p)
1991 #elif defined (_AIX) 2230 #elif defined (_AIX)
1992 #else 2231 #else
1993 if (!strcmp(device, "tap")) { 2232 if (!strcmp(device, "tap")) {
1994 - char ifname[64]; 2233 + char ifname[64], chkbuf[64];
1995 char setup_script[1024], down_script[1024]; 2234 char setup_script[1024], down_script[1024];
1996 int fd; 2235 int fd;
1997 vlan->nb_host_devs++; 2236 vlan->nb_host_devs++;
1998 if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { 2237 if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
1999 - if (check_params(fd_params, p) < 0) {  
2000 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2001 - return -1; 2238 + if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
  2239 + config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
  2240 + ret = -1;
  2241 + goto out;
2002 } 2242 }
2003 fd = strtol(buf, NULL, 0); 2243 fd = strtol(buf, NULL, 0);
2004 fcntl(fd, F_SETFL, O_NONBLOCK); 2244 fcntl(fd, F_SETFL, O_NONBLOCK);
@@ -2008,9 +2248,10 @@ int net_client_init(const char *device, const char *p) @@ -2008,9 +2248,10 @@ int net_client_init(const char *device, const char *p)
2008 static const char * const tap_params[] = { 2248 static const char * const tap_params[] = {
2009 "vlan", "name", "ifname", "script", "downscript", NULL 2249 "vlan", "name", "ifname", "script", "downscript", NULL
2010 }; 2250 };
2011 - if (check_params(tap_params, p) < 0) {  
2012 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2013 - return -1; 2251 + if (check_params(chkbuf, sizeof(chkbuf), tap_params, p) < 0) {
  2252 + config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
  2253 + ret = -1;
  2254 + goto out;
2014 } 2255 }
2015 if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { 2256 if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
2016 ifname[0] = '\0'; 2257 ifname[0] = '\0';
@@ -2026,11 +2267,13 @@ int net_client_init(const char *device, const char *p) @@ -2026,11 +2267,13 @@ int net_client_init(const char *device, const char *p)
2026 } else 2267 } else
2027 #endif 2268 #endif
2028 if (!strcmp(device, "socket")) { 2269 if (!strcmp(device, "socket")) {
  2270 + char chkbuf[64];
2029 if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { 2271 if (get_param_value(buf, sizeof(buf), "fd", p) > 0) {
2030 int fd; 2272 int fd;
2031 - if (check_params(fd_params, p) < 0) {  
2032 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2033 - return -1; 2273 + if (check_params(chkbuf, sizeof(chkbuf), fd_params, p) < 0) {
  2274 + config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
  2275 + ret = -1;
  2276 + goto out;
2034 } 2277 }
2035 fd = strtol(buf, NULL, 0); 2278 fd = strtol(buf, NULL, 0);
2036 ret = -1; 2279 ret = -1;
@@ -2040,31 +2283,34 @@ int net_client_init(const char *device, const char *p) @@ -2040,31 +2283,34 @@ int net_client_init(const char *device, const char *p)
2040 static const char * const listen_params[] = { 2283 static const char * const listen_params[] = {
2041 "vlan", "name", "listen", NULL 2284 "vlan", "name", "listen", NULL
2042 }; 2285 };
2043 - if (check_params(listen_params, p) < 0) {  
2044 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2045 - return -1; 2286 + if (check_params(chkbuf, sizeof(chkbuf), listen_params, p) < 0) {
  2287 + config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
  2288 + ret = -1;
  2289 + goto out;
2046 } 2290 }
2047 ret = net_socket_listen_init(vlan, device, name, buf); 2291 ret = net_socket_listen_init(vlan, device, name, buf);
2048 } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) { 2292 } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
2049 static const char * const connect_params[] = { 2293 static const char * const connect_params[] = {
2050 "vlan", "name", "connect", NULL 2294 "vlan", "name", "connect", NULL
2051 }; 2295 };
2052 - if (check_params(connect_params, p) < 0) {  
2053 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2054 - return -1; 2296 + if (check_params(chkbuf, sizeof(chkbuf), connect_params, p) < 0) {
  2297 + config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
  2298 + ret = -1;
  2299 + goto out;
2055 } 2300 }
2056 ret = net_socket_connect_init(vlan, device, name, buf); 2301 ret = net_socket_connect_init(vlan, device, name, buf);
2057 } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) { 2302 } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
2058 static const char * const mcast_params[] = { 2303 static const char * const mcast_params[] = {
2059 "vlan", "name", "mcast", NULL 2304 "vlan", "name", "mcast", NULL
2060 }; 2305 };
2061 - if (check_params(mcast_params, p) < 0) {  
2062 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2063 - return -1; 2306 + if (check_params(chkbuf, sizeof(chkbuf), mcast_params, p) < 0) {
  2307 + config_error(mon, "invalid parameter '%s' in '%s'\n", chkbuf, p);
  2308 + ret = -1;
  2309 + goto out;
2064 } 2310 }
2065 ret = net_socket_mcast_init(vlan, device, name, buf); 2311 ret = net_socket_mcast_init(vlan, device, name, buf);
2066 } else { 2312 } else {
2067 - fprintf(stderr, "Unknown socket options: %s\n", p); 2313 + config_error(mon, "Unknown socket options: %s\n", p);
2068 ret = -1; 2314 ret = -1;
2069 goto out; 2315 goto out;
2070 } 2316 }
@@ -2078,9 +2324,10 @@ int net_client_init(const char *device, const char *p) @@ -2078,9 +2324,10 @@ int net_client_init(const char *device, const char *p)
2078 char vde_sock[1024], vde_group[512]; 2324 char vde_sock[1024], vde_group[512];
2079 int vde_port, vde_mode; 2325 int vde_port, vde_mode;
2080 2326
2081 - if (check_params(vde_params, p) < 0) {  
2082 - fprintf(stderr, "qemu: invalid parameter in '%s'\n", p);  
2083 - return -1; 2327 + if (check_params(buf, sizeof(buf), vde_params, p) < 0) {
  2328 + config_error(mon, "invalid parameter '%s' in '%s'\n", buf, p);
  2329 + ret = -1;
  2330 + goto out;
2084 } 2331 }
2085 vlan->nb_host_devs++; 2332 vlan->nb_host_devs++;
2086 if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) { 2333 if (get_param_value(vde_sock, sizeof(vde_sock), "sock", p) <= 0) {
@@ -2111,18 +2358,17 @@ int net_client_init(const char *device, const char *p) @@ -2111,18 +2358,17 @@ int net_client_init(const char *device, const char *p)
2111 if (!get_param_value(buf, sizeof(buf), "file", p)) { 2358 if (!get_param_value(buf, sizeof(buf), "file", p)) {
2112 snprintf(buf, sizeof(buf), "qemu-vlan%d.pcap", vlan_id); 2359 snprintf(buf, sizeof(buf), "qemu-vlan%d.pcap", vlan_id);
2113 } 2360 }
2114 - ret = net_dump_init(vlan, device, name, buf, len); 2361 + ret = net_dump_init(mon, vlan, device, name, buf, len);
2115 } else { 2362 } else {
2116 - fprintf(stderr, "Unknown network device: %s\n", device); 2363 + config_error(mon, "Unknown network device: %s\n", device);
2117 ret = -1; 2364 ret = -1;
2118 goto out; 2365 goto out;
2119 } 2366 }
2120 if (ret < 0) { 2367 if (ret < 0) {
2121 - fprintf(stderr, "Could not initialize device '%s'\n", device); 2368 + config_error(mon, "Could not initialize device '%s'\n", device);
2122 } 2369 }
2123 out: 2370 out:
2124 - if (name)  
2125 - free(name); 2371 + qemu_free(name);
2126 return ret; 2372 return ret;
2127 } 2373 }
2128 2374
@@ -2160,7 +2406,7 @@ void net_host_device_add(Monitor *mon, const char *device, const char *opts) @@ -2160,7 +2406,7 @@ void net_host_device_add(Monitor *mon, const char *device, const char *opts)
2160 monitor_printf(mon, "invalid host network device %s\n", device); 2406 monitor_printf(mon, "invalid host network device %s\n", device);
2161 return; 2407 return;
2162 } 2408 }
2163 - if (net_client_init(device, opts ? opts : "") < 0) { 2409 + if (net_client_init(mon, device, opts ? opts : "") < 0) {
2164 monitor_printf(mon, "adding host network device %s failed\n", device); 2410 monitor_printf(mon, "adding host network device %s failed\n", device);
2165 } 2411 }
2166 } 2412 }
@@ -2206,7 +2452,7 @@ int net_client_parse(const char *str) @@ -2206,7 +2452,7 @@ int net_client_parse(const char *str)
2206 if (*p == ',') 2452 if (*p == ',')
2207 p++; 2453 p++;
2208 2454
2209 - return net_client_init(device, p); 2455 + return net_client_init(NULL, device, p);
2210 } 2456 }
2211 2457
2212 void do_info_network(Monitor *mon) 2458 void do_info_network(Monitor *mon)
@@ -5,19 +5,20 @@ @@ -5,19 +5,20 @@
5 5
6 /* VLANs support */ 6 /* VLANs support */
7 7
8 -typedef ssize_t (IOReadvHandler)(void *, const struct iovec *, int);  
9 -  
10 typedef struct VLANClientState VLANClientState; 8 typedef struct VLANClientState VLANClientState;
11 9
  10 +typedef int (NetCanReceive)(VLANClientState *);
  11 +typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
  12 +typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
12 typedef void (NetCleanup) (VLANClientState *); 13 typedef void (NetCleanup) (VLANClientState *);
13 typedef void (LinkStatusChanged)(VLANClientState *); 14 typedef void (LinkStatusChanged)(VLANClientState *);
14 15
15 struct VLANClientState { 16 struct VLANClientState {
16 - IOReadHandler *fd_read;  
17 - IOReadvHandler *fd_readv; 17 + NetReceive *receive;
  18 + NetReceiveIOV *receive_iov;
18 /* Packets may still be sent if this returns zero. It's used to 19 /* Packets may still be sent if this returns zero. It's used to
19 rate-limit the slirp code. */ 20 rate-limit the slirp code. */
20 - IOCanRWHandler *fd_can_read; 21 + NetCanReceive *can_receive;
21 NetCleanup *cleanup; 22 NetCleanup *cleanup;
22 LinkStatusChanged *link_status_changed; 23 LinkStatusChanged *link_status_changed;
23 int link_down; 24 int link_down;
@@ -31,10 +32,13 @@ struct VLANClientState { @@ -31,10 +32,13 @@ struct VLANClientState {
31 32
32 typedef struct VLANPacket VLANPacket; 33 typedef struct VLANPacket VLANPacket;
33 34
  35 +typedef void (NetPacketSent) (VLANClientState *);
  36 +
34 struct VLANPacket { 37 struct VLANPacket {
35 struct VLANPacket *next; 38 struct VLANPacket *next;
36 VLANClientState *sender; 39 VLANClientState *sender;
37 int size; 40 int size;
  41 + NetPacketSent *sent_cb;
38 uint8_t data[0]; 42 uint8_t data[0];
39 }; 43 };
40 44
@@ -51,8 +55,9 @@ VLANState *qemu_find_vlan(int id); @@ -51,8 +55,9 @@ VLANState *qemu_find_vlan(int id);
51 VLANClientState *qemu_new_vlan_client(VLANState *vlan, 55 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
52 const char *model, 56 const char *model,
53 const char *name, 57 const char *name,
54 - IOReadHandler *fd_read,  
55 - IOCanRWHandler *fd_can_read, 58 + NetCanReceive *can_receive,
  59 + NetReceive *receive,
  60 + NetReceiveIOV *receive_iov,
56 NetCleanup *cleanup, 61 NetCleanup *cleanup,
57 void *opaque); 62 void *opaque);
58 void qemu_del_vlan_client(VLANClientState *vc); 63 void qemu_del_vlan_client(VLANClientState *vc);
@@ -60,7 +65,12 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque); @@ -60,7 +65,12 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
60 int qemu_can_send_packet(VLANClientState *vc); 65 int qemu_can_send_packet(VLANClientState *vc);
61 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, 66 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
62 int iovcnt); 67 int iovcnt);
  68 +ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
  69 + int iovcnt, NetPacketSent *sent_cb);
63 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); 70 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
  71 +ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
  72 + int size, NetPacketSent *sent_cb);
  73 +void qemu_flush_queued_packets(VLANClientState *vc);
64 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); 74 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
65 void qemu_check_nic_model(NICInfo *nd, const char *model); 75 void qemu_check_nic_model(NICInfo *nd, const char *model);
66 void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, 76 void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
@@ -108,7 +118,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, @@ -108,7 +118,7 @@ uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
108 void net_checksum_calculate(uint8_t *data, int length); 118 void net_checksum_calculate(uint8_t *data, int length);
109 119
110 /* from net.c */ 120 /* from net.c */
111 -int net_client_init(const char *device, const char *p); 121 +int net_client_init(Monitor *mon, const char *device, const char *p);
112 void net_client_uninit(NICInfo *nd); 122 void net_client_uninit(NICInfo *nd);
113 int net_client_parse(const char *str); 123 int net_client_parse(const char *str);
114 void net_slirp_smb(const char *exported_dir); 124 void net_slirp_smb(const char *exported_dir);
@@ -129,8 +139,9 @@ void net_host_device_remove(Monitor *mon, int vlan_id, const char *device); @@ -129,8 +139,9 @@ void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
129 139
130 void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr); 140 void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
131 VLANClientState *qdev_get_vlan_client(DeviceState *dev, 141 VLANClientState *qdev_get_vlan_client(DeviceState *dev,
132 - IOReadHandler *fd_read,  
133 - IOCanRWHandler *fd_can_read, 142 + NetCanReceive *can_receive,
  143 + NetReceive *receive,
  144 + NetReceiveIOV *receive_iov,
134 NetCleanup *cleanup, 145 NetCleanup *cleanup,
135 void *opaque); 146 void *opaque);
136 147
savevm.c
@@ -131,7 +131,7 @@ static void qemu_announce_self_once(void *opaque) @@ -131,7 +131,7 @@ static void qemu_announce_self_once(void *opaque)
131 len = announce_self_create(buf, nd_table[i].macaddr); 131 len = announce_self_create(buf, nd_table[i].macaddr);
132 vlan = nd_table[i].vlan; 132 vlan = nd_table[i].vlan;
133 for(vc = vlan->first_client; vc != NULL; vc = vc->next) { 133 for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
134 - vc->fd_read(vc->opaque, buf, len); 134 + vc->receive(vc, buf, len);
135 } 135 }
136 } 136 }
137 if (count--) { 137 if (count--) {
slirp/libslirp.h
@@ -5,7 +5,7 @@ @@ -5,7 +5,7 @@
5 extern "C" { 5 extern "C" {
6 #endif 6 #endif
7 7
8 -void slirp_init(int restricted, char *special_ip); 8 +void slirp_init(int restricted, const char *special_ip);
9 9
10 void slirp_select_fill(int *pnfds, 10 void slirp_select_fill(int *pnfds,
11 fd_set *readfds, fd_set *writefds, fd_set *xfds); 11 fd_set *readfds, fd_set *writefds, fd_set *xfds);
slirp/slirp.c
@@ -171,7 +171,7 @@ static void slirp_cleanup(void) @@ -171,7 +171,7 @@ static void slirp_cleanup(void)
171 static void slirp_state_save(QEMUFile *f, void *opaque); 171 static void slirp_state_save(QEMUFile *f, void *opaque);
172 static int slirp_state_load(QEMUFile *f, void *opaque, int version_id); 172 static int slirp_state_load(QEMUFile *f, void *opaque, int version_id);
173 173
174 -void slirp_init(int restricted, char *special_ip) 174 +void slirp_init(int restricted, const char *special_ip)
175 { 175 {
176 // debug_init("/tmp/slirp.log", DEBUG_DEFAULT); 176 // debug_init("/tmp/slirp.log", DEBUG_DEFAULT);
177 177
sysemu.h
@@ -270,7 +270,8 @@ void usb_info(Monitor *mon); @@ -270,7 +270,8 @@ void usb_info(Monitor *mon);
270 270
271 int get_param_value(char *buf, int buf_size, 271 int get_param_value(char *buf, int buf_size,
272 const char *tag, const char *str); 272 const char *tag, const char *str);
273 -int check_params(const char * const *params, const char *str); 273 +int check_params(char *buf, int buf_size,
  274 + const char * const *params, const char *str);
274 275
275 void register_devices(void); 276 void register_devices(void);
276 277
tap-win32.c
@@ -650,11 +650,11 @@ static void tap_cleanup(VLANClientState *vc) @@ -650,11 +650,11 @@ static void tap_cleanup(VLANClientState *vc)
650 qemu_free(s); 650 qemu_free(s);
651 } 651 }
652 652
653 -static void tap_receive(void *opaque, const uint8_t *buf, int size) 653 +static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
654 { 654 {
655 - TAPState *s = opaque; 655 + TAPState *s = vc->opaque;
656 656
657 - tap_win32_write(s->handle, buf, size); 657 + return tap_win32_write(s->handle, buf, size);
658 } 658 }
659 659
660 static void tap_win32_send(void *opaque) 660 static void tap_win32_send(void *opaque)
@@ -684,7 +684,7 @@ int tap_win32_init(VLANState *vlan, const char *model, @@ -684,7 +684,7 @@ int tap_win32_init(VLANState *vlan, const char *model,
684 return -1; 684 return -1;
685 } 685 }
686 686
687 - s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, 687 + s->vc = qemu_new_vlan_client(vlan, model, name, NULL, tap_receive,
688 NULL, tap_cleanup, s); 688 NULL, tap_cleanup, s);
689 689
690 snprintf(s->vc->info_str, sizeof(s->vc->info_str), 690 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
@@ -1836,45 +1836,34 @@ int get_param_value(char *buf, int buf_size, @@ -1836,45 +1836,34 @@ int get_param_value(char *buf, int buf_size,
1836 return 0; 1836 return 0;
1837 } 1837 }
1838 1838
1839 -int check_params(const char * const *params, const char *str) 1839 +int check_params(char *buf, int buf_size,
  1840 + const char * const *params, const char *str)
1840 { 1841 {
1841 - int name_buf_size = 1;  
1842 const char *p; 1842 const char *p;
1843 - char *name_buf;  
1844 - int i, len;  
1845 - int ret = 0;  
1846 -  
1847 - for (i = 0; params[i] != NULL; i++) {  
1848 - len = strlen(params[i]) + 1;  
1849 - if (len > name_buf_size) {  
1850 - name_buf_size = len;  
1851 - }  
1852 - }  
1853 - name_buf = qemu_malloc(name_buf_size); 1843 + int i;
1854 1844
1855 p = str; 1845 p = str;
1856 while (*p != '\0') { 1846 while (*p != '\0') {
1857 - p = get_opt_name(name_buf, name_buf_size, p, '='); 1847 + p = get_opt_name(buf, buf_size, p, '=');
1858 if (*p != '=') { 1848 if (*p != '=') {
1859 - ret = -1;  
1860 - break; 1849 + return -1;
1861 } 1850 }
1862 p++; 1851 p++;
1863 - for(i = 0; params[i] != NULL; i++)  
1864 - if (!strcmp(params[i], name_buf)) 1852 + for (i = 0; params[i] != NULL; i++) {
  1853 + if (!strcmp(params[i], buf)) {
1865 break; 1854 break;
  1855 + }
  1856 + }
1866 if (params[i] == NULL) { 1857 if (params[i] == NULL) {
1867 - ret = -1;  
1868 - break; 1858 + return -1;
1869 } 1859 }
1870 p = get_opt_value(NULL, 0, p); 1860 p = get_opt_value(NULL, 0, p);
1871 - if (*p != ',') 1861 + if (*p != ',') {
1872 break; 1862 break;
  1863 + }
1873 p++; 1864 p++;
1874 } 1865 }
1875 -  
1876 - qemu_free(name_buf);  
1877 - return ret; 1866 + return 0;
1878 } 1867 }
1879 1868
1880 /***********************************************************/ 1869 /***********************************************************/
@@ -2227,8 +2216,9 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque) @@ -2227,8 +2216,9 @@ int drive_init(struct drive_opt *arg, int snapshot, void *opaque)
2227 "cache", "format", "serial", "werror", 2216 "cache", "format", "serial", "werror",
2228 NULL }; 2217 NULL };
2229 2218
2230 - if (check_params(params, str) < 0) {  
2231 - fprintf(stderr, "qemu: unknown parameter in '%s'\n", str); 2219 + if (check_params(buf, sizeof(buf), params, str) < 0) {
  2220 + fprintf(stderr, "qemu: unknown parameter '%s' in '%s'\n",
  2221 + buf, str);
2232 return -1; 2222 return -1;
2233 } 2223 }
2234 2224
@@ -2709,7 +2699,7 @@ static int usb_device_add(const char *devname, int is_hotplug) @@ -2709,7 +2699,7 @@ static int usb_device_add(const char *devname, int is_hotplug)
2709 } else if (strstart(devname, "net:", &p)) { 2699 } else if (strstart(devname, "net:", &p)) {
2710 int nic = nb_nics; 2700 int nic = nb_nics;
2711 2701
2712 - if (net_client_init("nic", p) < 0) 2702 + if (net_client_init(NULL, "nic", p) < 0)
2713 return -1; 2703 return -1;
2714 nd_table[nic].model = "usb"; 2704 nd_table[nic].model = "usb";
2715 dev = usb_net_init(&nd_table[nic]); 2705 dev = usb_net_init(&nd_table[nic]);
@@ -4783,7 +4773,12 @@ static void termsig_handler(int signal) @@ -4783,7 +4773,12 @@ static void termsig_handler(int signal)
4783 qemu_system_shutdown_request(); 4773 qemu_system_shutdown_request();
4784 } 4774 }
4785 4775
4786 -static void termsig_setup(void) 4776 +static void sigchld_handler(int signal)
  4777 +{
  4778 + waitpid(-1, NULL, WNOHANG);
  4779 +}
  4780 +
  4781 +static void sighandler_setup(void)
4787 { 4782 {
4788 struct sigaction act; 4783 struct sigaction act;
4789 4784
@@ -4792,6 +4787,10 @@ static void termsig_setup(void) @@ -4792,6 +4787,10 @@ static void termsig_setup(void)
4792 sigaction(SIGINT, &act, NULL); 4787 sigaction(SIGINT, &act, NULL);
4793 sigaction(SIGHUP, &act, NULL); 4788 sigaction(SIGHUP, &act, NULL);
4794 sigaction(SIGTERM, &act, NULL); 4789 sigaction(SIGTERM, &act, NULL);
  4790 +
  4791 + act.sa_handler = sigchld_handler;
  4792 + act.sa_flags = SA_NOCLDSTOP;
  4793 + sigaction(SIGCHLD, &act, NULL);
4795 } 4794 }
4796 4795
4797 #endif 4796 #endif
@@ -5920,7 +5919,7 @@ int main(int argc, char **argv, char **envp) @@ -5920,7 +5919,7 @@ int main(int argc, char **argv, char **envp)
5920 5919
5921 #ifndef _WIN32 5920 #ifndef _WIN32
5922 /* must be after terminal init, SDL library changes signal handlers */ 5921 /* must be after terminal init, SDL library changes signal handlers */
5923 - termsig_setup(); 5922 + sighandler_setup();
5924 #endif 5923 #endif
5925 5924
5926 /* Maintain compatibility with multiple stdio monitors */ 5925 /* Maintain compatibility with multiple stdio monitors */