Commit f8e76fbf5190575c0f927fe3c5b0ec6934c6c3fc
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>
Showing
26 changed files
with
834 additions
and
453 deletions
hw/dp8393x.c
... | ... | @@ -407,9 +407,9 @@ static void do_transmit_packets(dp8393xState *s) |
407 | 407 | if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) { |
408 | 408 | /* Loopback */ |
409 | 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 | 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 | 414 | } else { |
415 | 415 | /* Transmit packet */ |
... | ... | @@ -676,9 +676,9 @@ static CPUWriteMemoryFunc *dp8393x_write[3] = { |
676 | 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 | 683 | if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) |
684 | 684 | return 0; |
... | ... | @@ -725,10 +725,10 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size) |
725 | 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 | 730 | uint16_t data[10]; |
731 | - dp8393xState *s = opaque; | |
731 | + dp8393xState *s = vc->opaque; | |
732 | 732 | int packet_type; |
733 | 733 | uint32_t available, address; |
734 | 734 | int width, rx_len = size; |
... | ... | @@ -742,7 +742,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) |
742 | 742 | packet_type = receive_filter(s, buf, size); |
743 | 743 | if (packet_type < 0) { |
744 | 744 | DPRINTF("packet not for netcard\n"); |
745 | - return; | |
745 | + return -1; | |
746 | 746 | } |
747 | 747 | |
748 | 748 | /* XXX: Check byte ordering */ |
... | ... | @@ -755,7 +755,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) |
755 | 755 | s->memory_rw(s->mem_opaque, address, (uint8_t*)data, size, 0); |
756 | 756 | if (data[0 * width] & 0x1) { |
757 | 757 | /* Still EOL ; stop reception */ |
758 | - return; | |
758 | + return -1; | |
759 | 759 | } else { |
760 | 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 | 833 | |
834 | 834 | /* Done */ |
835 | 835 | dp8393x_update_irq(s); |
836 | + | |
837 | + return size; | |
836 | 838 | } |
837 | 839 | |
838 | 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 | 890 | s->watchdog = qemu_new_timer(vm_clock, dp8393x_watchdog, s); |
889 | 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 | 896 | qemu_format_nic_info_str(s->vc, nd->macaddr); |
895 | 897 | qemu_register_reset(nic_reset, 0, s); | ... | ... |
hw/e1000.c
... | ... | @@ -598,17 +598,17 @@ e1000_set_link_status(VLANClientState *vc) |
598 | 598 | } |
599 | 599 | |
600 | 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 | 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 | 612 | struct e1000_rx_desc desc; |
613 | 613 | target_phys_addr_t base; |
614 | 614 | unsigned int n, rdt; |
... | ... | @@ -617,16 +617,16 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) |
617 | 617 | uint8_t vlan_status = 0, vlan_offset = 0; |
618 | 618 | |
619 | 619 | if (!(s->mac_reg[RCTL] & E1000_RCTL_EN)) |
620 | - return; | |
620 | + return -1; | |
621 | 621 | |
622 | 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 | 628 | if (!receive_filter(s, buf, size)) |
629 | - return; | |
629 | + return size; | |
630 | 630 | |
631 | 631 | if (vlan_enabled(s) && is_vlan_packet(s, buf)) { |
632 | 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 | 641 | do { |
642 | 642 | if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) { |
643 | 643 | set_ics(s, 0, E1000_ICS_RXO); |
644 | - return; | |
644 | + return -1; | |
645 | 645 | } |
646 | 646 | base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] + |
647 | 647 | sizeof(desc) * s->mac_reg[RDH]; |
... | ... | @@ -665,7 +665,7 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) |
665 | 665 | DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n", |
666 | 666 | rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]); |
667 | 667 | set_ics(s, 0, E1000_ICS_RXO); |
668 | - return; | |
668 | + return -1; | |
669 | 669 | } |
670 | 670 | } while (desc.buffer_addr == 0); |
671 | 671 | |
... | ... | @@ -683,6 +683,8 @@ e1000_receive(void *opaque, const uint8_t *buf, int size) |
683 | 683 | n |= E1000_ICS_RXDMT0; |
684 | 684 | |
685 | 685 | set_ics(s, 0, n); |
686 | + | |
687 | + return size; | |
686 | 688 | } |
687 | 689 | |
688 | 690 | static uint32_t |
... | ... | @@ -1119,8 +1121,8 @@ static void pci_e1000_init(PCIDevice *pci_dev) |
1119 | 1121 | d->eeprom_data[EEPROM_CHECKSUM_REG] = checksum; |
1120 | 1122 | |
1121 | 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 | 1126 | d->vc->link_status_changed = e1000_set_link_status; |
1125 | 1127 | |
1126 | 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 | 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 | 1439 | logout("%p\n", s); |
1440 | 1440 | return get_ru_state(s) == ru_ready; |
1441 | 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 | 1446 | /* TODO: |
1447 | 1447 | * - Magic packets should set bit 30 in power management driver register. |
1448 | 1448 | * - Interesting packets should set bit 29 in power management driver register. |
1449 | 1449 | */ |
1450 | - EEPRO100State *s = opaque; | |
1450 | + EEPRO100State *s = vc->opaque; | |
1451 | 1451 | uint16_t rfd_status = 0xa000; |
1452 | 1452 | static const uint8_t broadcast_macaddr[6] = |
1453 | 1453 | { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; |
... | ... | @@ -1458,18 +1458,18 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) |
1458 | 1458 | if (s->configuration[8] & 0x80) { |
1459 | 1459 | /* CSMA is disabled. */ |
1460 | 1460 | logout("%p received while CSMA is disabled\n", s); |
1461 | - return; | |
1461 | + return -1; | |
1462 | 1462 | } else if (size < 64 && (s->configuration[7] & 1)) { |
1463 | 1463 | /* Short frame and configuration byte 7/0 (discard short receive) set: |
1464 | 1464 | * Short frame is discarded */ |
1465 | 1465 | logout("%p received short frame (%d byte)\n", s, size); |
1466 | 1466 | s->statistics.rx_short_frame_errors++; |
1467 | - //~ return; | |
1467 | + //~ return -1; | |
1468 | 1468 | } else if ((size > MAX_ETH_FRAME_SIZE + 4) && !(s->configuration[18] & 8)) { |
1469 | 1469 | /* Long frame and configuration byte 18/3 (long receive ok) not set: |
1470 | 1470 | * Long frames are discarded. */ |
1471 | 1471 | logout("%p received long frame (%d byte), ignored\n", s, size); |
1472 | - return; | |
1472 | + return -1; | |
1473 | 1473 | } else if (memcmp(buf, s->macaddr, 6) == 0) { // !!! |
1474 | 1474 | /* Frame matches individual address. */ |
1475 | 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 | 1485 | assert(!(s->configuration[21] & BIT(3))); |
1486 | 1486 | int mcast_idx = compute_mcast_idx(buf); |
1487 | 1487 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) { |
1488 | - return; | |
1488 | + return size; | |
1489 | 1489 | } |
1490 | 1490 | rfd_status |= 0x0002; |
1491 | 1491 | } else if (s->configuration[15] & 1) { |
... | ... | @@ -1495,7 +1495,7 @@ static void nic_receive(void *opaque, const uint8_t * buf, int size) |
1495 | 1495 | } else { |
1496 | 1496 | logout("%p received frame, ignored, len=%d,%s\n", s, size, |
1497 | 1497 | nic_dump(buf, size)); |
1498 | - return; | |
1498 | + return size; | |
1499 | 1499 | } |
1500 | 1500 | |
1501 | 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 | 1503 | logout("no ressources, state=%u\n", get_ru_state(s)); |
1504 | 1504 | s->statistics.rx_resource_errors++; |
1505 | 1505 | //~ assert(!"no ressources"); |
1506 | - return; | |
1506 | + return -1; | |
1507 | 1507 | } |
1508 | 1508 | //~ !!! |
1509 | 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 | 1540 | /* S bit is set. */ |
1541 | 1541 | set_ru_state(s, ru_suspended); |
1542 | 1542 | } |
1543 | + return size; | |
1543 | 1544 | } |
1544 | 1545 | |
1545 | 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 | 1767 | nic_reset(s); |
1767 | 1768 | |
1768 | 1769 | s->vc = qdev_get_vlan_client(&d->dev.qdev, |
1769 | - nic_receive, nic_can_receive, | |
1770 | + nic_can_receive, nic_receive, NULL, | |
1770 | 1771 | nic_cleanup, s); |
1771 | 1772 | |
1772 | 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 | 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 | 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 | 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 | 508 | int use_ma0 = eth->regs[RW_REC_CTRL] & 1; |
509 | 509 | int use_ma1 = eth->regs[RW_REC_CTRL] & 2; |
510 | 510 | int r_bcast = eth->regs[RW_REC_CTRL] & 8; |
511 | 511 | |
512 | 512 | if (size < 12) |
513 | - return; | |
513 | + return -1; | |
514 | 514 | |
515 | 515 | D(printf("%x.%x.%x.%x.%x.%x ma=%d %d bc=%d\n", |
516 | 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 | 521 | && (!use_ma1 || memcmp(buf, eth->macaddr[1], 6)) |
522 | 522 | && (!r_bcast || memcmp(buf, sa_bcast, 6)) |
523 | 523 | && !eth_match_groupaddr(eth, buf)) |
524 | - return; | |
524 | + return size; | |
525 | 525 | |
526 | 526 | /* FIXME: Find another way to pass on the fake csum. */ |
527 | 527 | etraxfs_dmac_input(eth->dma_in, (void *)buf, size + 4, 1); |
528 | + | |
529 | + return size; | |
528 | 530 | } |
529 | 531 | |
530 | 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 | 595 | cpu_register_physical_memory (base, 0x5c, eth->ethregs); |
594 | 596 | |
595 | 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 | 599 | eth_cleanup, eth); |
598 | 600 | eth->vc->opaque = eth; |
599 | 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 | 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 | 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 | 359 | mcf_fec_bd bd; |
360 | 360 | uint32_t flags = 0; |
361 | 361 | uint32_t addr; |
... | ... | @@ -426,6 +426,7 @@ static void mcf_fec_receive(void *opaque, const uint8_t *buf, int size) |
426 | 426 | s->rx_descriptor = addr; |
427 | 427 | mcf_fec_enable_rx(s); |
428 | 428 | mcf_fec_update(s); |
429 | + return size; | |
429 | 430 | } |
430 | 431 | |
431 | 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 | 463 | cpu_register_physical_memory(base, 0x400, s->mmio_index); |
463 | 464 | |
464 | 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 | 467 | mcf_fec_cleanup, s); |
467 | 468 | memcpy(s->macaddr, nd->macaddr, 6); |
468 | 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 | 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 | 73 | if (s->busy) |
74 | 74 | return 0; |
75 | 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 | 82 | #ifdef DEBUG_MIPSNET_RECEIVE |
83 | 83 | printf("mipsnet: receiving len=%d\n", size); |
84 | 84 | #endif |
85 | - if (!mipsnet_can_receive(opaque)) | |
86 | - return; | |
85 | + if (!mipsnet_can_receive(vc)) | |
86 | + return -1; | |
87 | 87 | |
88 | 88 | s->busy = 1; |
89 | 89 | |
... | ... | @@ -98,6 +98,8 @@ static void mipsnet_receive(void *opaque, const uint8_t *buf, int size) |
98 | 98 | /* Now we can signal we have received something. */ |
99 | 99 | s->intctl |= MIPSNET_INTCTL_RXDONE; |
100 | 100 | mipsnet_update_irq(s); |
101 | + | |
102 | + return size; | |
101 | 103 | } |
102 | 104 | |
103 | 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 | 264 | s->irq = irq; |
263 | 265 | if (nd && nd->vlan) { |
264 | 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 | 268 | mipsnet_cleanup, s); |
267 | 269 | } else { |
268 | 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 | 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 | 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 | 568 | uint32_t desc_addr; |
569 | 569 | mv88w8618_rx_desc desc; |
570 | 570 | int i; |
... | ... | @@ -586,11 +586,12 @@ static void eth_receive(void *opaque, const uint8_t *buf, int size) |
586 | 586 | if (s->icr & s->imr) |
587 | 587 | qemu_irq_raise(s->irq); |
588 | 588 | eth_rx_desc_put(desc_addr, &desc); |
589 | - return; | |
589 | + return size; | |
590 | 590 | } |
591 | 591 | desc_addr = desc.next; |
592 | 592 | } while (desc_addr != s->rx_queue[i]); |
593 | 593 | } |
594 | + return size; | |
594 | 595 | } |
595 | 596 | |
596 | 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 | 754 | |
754 | 755 | sysbus_init_irq(dev, &s->irq); |
755 | 756 | s->vc = qdev_get_vlan_client(&dev->qdev, |
756 | - eth_receive, eth_can_receive, | |
757 | + eth_can_receive, eth_receive, NULL, | |
757 | 758 | eth_cleanup, s); |
758 | 759 | s->mmio_index = cpu_register_io_memory(0, mv88w8618_eth_readfn, |
759 | 760 | mv88w8618_eth_writefn, s); | ... | ... |
hw/ne2000.c
... | ... | @@ -213,9 +213,9 @@ static int ne2000_buffer_full(NE2000State *s) |
213 | 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 | 220 | if (s->cmd & E8390_STOP) |
221 | 221 | return 1; |
... | ... | @@ -224,9 +224,10 @@ static int ne2000_can_receive(void *opaque) |
224 | 224 | |
225 | 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 | 231 | uint8_t *p; |
231 | 232 | unsigned int total_len, next, avail, len, index, mcast_idx; |
232 | 233 | uint8_t buf1[60]; |
... | ... | @@ -238,7 +239,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) |
238 | 239 | #endif |
239 | 240 | |
240 | 241 | if (s->cmd & E8390_STOP || ne2000_buffer_full(s)) |
241 | - return; | |
242 | + return -1; | |
242 | 243 | |
243 | 244 | /* XXX: check this */ |
244 | 245 | if (s->rxcr & 0x10) { |
... | ... | @@ -247,14 +248,14 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) |
247 | 248 | if (!memcmp(buf, broadcast_macaddr, 6)) { |
248 | 249 | /* broadcast address */ |
249 | 250 | if (!(s->rxcr & 0x04)) |
250 | - return; | |
251 | + return size; | |
251 | 252 | } else if (buf[0] & 0x01) { |
252 | 253 | /* multicast */ |
253 | 254 | if (!(s->rxcr & 0x08)) |
254 | - return; | |
255 | + return size; | |
255 | 256 | mcast_idx = compute_mcast_idx(buf); |
256 | 257 | if (!(s->mult[mcast_idx >> 3] & (1 << (mcast_idx & 7)))) |
257 | - return; | |
258 | + return size; | |
258 | 259 | } else if (s->mem[0] == buf[0] && |
259 | 260 | s->mem[2] == buf[1] && |
260 | 261 | s->mem[4] == buf[2] && |
... | ... | @@ -263,7 +264,7 @@ static void ne2000_receive(void *opaque, const uint8_t *buf, int size) |
263 | 264 | s->mem[10] == buf[5]) { |
264 | 265 | /* match */ |
265 | 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 | 317 | /* now we can signal we have received something */ |
317 | 318 | s->isr |= ENISR_RX; |
318 | 319 | ne2000_update_irq(s); |
320 | + | |
321 | + return size_; | |
319 | 322 | } |
320 | 323 | |
321 | 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 | 760 | ne2000_reset(s); |
758 | 761 | |
759 | 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 | 764 | isa_ne2000_cleanup, s); |
762 | 765 | |
763 | 766 | qemu_format_nic_info_str(s->vc, s->macaddr); |
... | ... | @@ -821,7 +824,7 @@ static void pci_ne2000_init(PCIDevice *pci_dev) |
821 | 824 | qdev_get_macaddr(&d->dev.qdev, s->macaddr); |
822 | 825 | ne2000_reset(s); |
823 | 826 | s->vc = qdev_get_vlan_client(&d->dev.qdev, |
824 | - ne2000_receive, ne2000_can_receive, | |
827 | + ne2000_can_receive, ne2000_receive, NULL, | |
825 | 828 | ne2000_cleanup, s); |
826 | 829 | |
827 | 830 | qemu_format_nic_info_str(s->vc, s->macaddr); | ... | ... |
hw/pci-hotplug.c
... | ... | @@ -33,11 +33,12 @@ |
33 | 33 | #include "virtio-blk.h" |
34 | 34 | |
35 | 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 | 39 | int ret; |
39 | 40 | |
40 | - ret = net_client_init("nic", opts); | |
41 | + ret = net_client_init(mon, "nic", opts); | |
41 | 42 | if (ret < 0) |
42 | 43 | return NULL; |
43 | 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 | 150 | } |
150 | 151 | |
151 | 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 | 154 | else if (strcmp(type, "storage") == 0) |
154 | 155 | dev = qemu_pci_hot_add_storage(mon, pci_bus, opts); |
155 | 156 | else | ... | ... |
hw/pcnet.c
... | ... | @@ -1062,9 +1062,9 @@ static int pcnet_tdte_poll(PCNetState *s) |
1062 | 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 | 1068 | if (CSR_STOP(s) || CSR_SPND(s)) |
1069 | 1069 | return 0; |
1070 | 1070 | |
... | ... | @@ -1076,16 +1076,17 @@ static int pcnet_can_receive(void *opaque) |
1076 | 1076 | |
1077 | 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 | 1082 | int is_padr = 0, is_bcast = 0, is_ladr = 0; |
1083 | 1083 | uint8_t buf1[60]; |
1084 | 1084 | int remaining; |
1085 | 1085 | int crc_err = 0; |
1086 | + int size = size_; | |
1086 | 1087 | |
1087 | 1088 | if (CSR_DRX(s) || CSR_STOP(s) || CSR_SPND(s) || !size) |
1088 | - return; | |
1089 | + return -1; | |
1089 | 1090 | |
1090 | 1091 | #ifdef PCNET_DEBUG |
1091 | 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 | 1253 | |
1253 | 1254 | pcnet_poll(s); |
1254 | 1255 | pcnet_update_irq(s); |
1256 | + | |
1257 | + return size_; | |
1255 | 1258 | } |
1256 | 1259 | |
1257 | 1260 | static void pcnet_transmit(PCNetState *s) |
... | ... | @@ -1302,7 +1305,7 @@ static void pcnet_transmit(PCNetState *s) |
1302 | 1305 | if (BCR_SWSTYLE(s) == 1) |
1303 | 1306 | add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS); |
1304 | 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 | 1309 | s->looptest = 0; |
1307 | 1310 | } else |
1308 | 1311 | if (s->vc) |
... | ... | @@ -1952,7 +1955,7 @@ static void pcnet_common_init(DeviceState *dev, PCNetState *s, |
1952 | 1955 | |
1953 | 1956 | qdev_get_macaddr(dev, s->macaddr); |
1954 | 1957 | s->vc = qdev_get_vlan_client(dev, |
1955 | - pcnet_receive, pcnet_can_receive, | |
1958 | + pcnet_can_receive, pcnet_receive, NULL, | |
1956 | 1959 | cleanup, s); |
1957 | 1960 | pcnet_h_reset(s); |
1958 | 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 | 258 | } |
259 | 259 | |
260 | 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 | 264 | NetCleanup *cleanup, |
264 | 265 | void *opaque) |
265 | 266 | { |
266 | 267 | NICInfo *nd = dev->nd; |
267 | 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 | 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 | 796 | int avail; |
797 | 797 | |
798 | 798 | /* Receive (drop) packets if card is disabled. */ |
... | ... | @@ -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 | 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 | 829 | if (!s->clock_enabled) |
829 | 830 | { |
830 | 831 | DEBUG_PRINT(("RTL8139: stopped ==========================\n")); |
831 | - return; | |
832 | + return -1; | |
832 | 833 | } |
833 | 834 | |
834 | 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 | 837 | if (!rtl8139_receiver_enabled(s)) |
837 | 838 | { |
838 | 839 | DEBUG_PRINT(("RTL8139: receiver disabled ================\n")); |
839 | - return; | |
840 | + return -1; | |
840 | 841 | } |
841 | 842 | |
842 | 843 | /* XXX: check this */ |
... | ... | @@ -854,7 +855,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d |
854 | 855 | /* update tally counter */ |
855 | 856 | ++s->tally_counters.RxERR; |
856 | 857 | |
857 | - return; | |
858 | + return size; | |
858 | 859 | } |
859 | 860 | |
860 | 861 | packet_header |= RxBroadcast; |
... | ... | @@ -873,7 +874,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d |
873 | 874 | /* update tally counter */ |
874 | 875 | ++s->tally_counters.RxERR; |
875 | 876 | |
876 | - return; | |
877 | + return size; | |
877 | 878 | } |
878 | 879 | |
879 | 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 | 886 | /* update tally counter */ |
886 | 887 | ++s->tally_counters.RxERR; |
887 | 888 | |
888 | - return; | |
889 | + return size; | |
889 | 890 | } |
890 | 891 | |
891 | 892 | packet_header |= RxMulticast; |
... | ... | @@ -909,7 +910,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d |
909 | 910 | /* update tally counter */ |
910 | 911 | ++s->tally_counters.RxERR; |
911 | 912 | |
912 | - return; | |
913 | + return size; | |
913 | 914 | } |
914 | 915 | |
915 | 916 | packet_header |= RxPhysical; |
... | ... | @@ -926,7 +927,7 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d |
926 | 927 | /* update tally counter */ |
927 | 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 | 994 | ++s->tally_counters.MissPkt; |
994 | 995 | |
995 | 996 | rtl8139_update_irq(s); |
996 | - return; | |
997 | + return size_; | |
997 | 998 | } |
998 | 999 | |
999 | 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 | 1014 | ++s->tally_counters.MissPkt; |
1014 | 1015 | |
1015 | 1016 | rtl8139_update_irq(s); |
1016 | - return; | |
1017 | + return size_; | |
1017 | 1018 | } |
1018 | 1019 | |
1019 | 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 | 1119 | s->IntrStatus |= RxOverflow; |
1119 | 1120 | ++s->RxMissed; |
1120 | 1121 | rtl8139_update_irq(s); |
1121 | - return; | |
1122 | + return size_; | |
1122 | 1123 | } |
1123 | 1124 | |
1124 | 1125 | packet_header |= RxStatusOK; |
... | ... | @@ -1156,11 +1157,13 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d |
1156 | 1157 | { |
1157 | 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 | 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 | 1761 | if (TxLoopBack == (s->TxConfig & TxLoopBack)) |
1759 | 1762 | { |
1760 | 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 | 1766 | else |
1764 | 1767 | { |
... | ... | @@ -3479,7 +3482,7 @@ static void pci_rtl8139_init(PCIDevice *dev) |
3479 | 3482 | qemu_register_reset(rtl8139_reset, 0, s); |
3480 | 3483 | rtl8139_reset(s); |
3481 | 3484 | s->vc = qdev_get_vlan_client(&dev->qdev, |
3482 | - rtl8139_receive, rtl8139_can_receive, | |
3485 | + rtl8139_can_receive, rtl8139_receive, NULL, | |
3483 | 3486 | rtl8139_cleanup, s); |
3484 | 3487 | |
3485 | 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 | 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 | 598 | if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) |
599 | 599 | return 1; |
... | ... | @@ -602,9 +602,9 @@ static int smc91c111_can_receive(void *opaque) |
602 | 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 | 608 | int status; |
609 | 609 | int packetsize; |
610 | 610 | uint32_t crc; |
... | ... | @@ -612,7 +612,7 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) |
612 | 612 | uint8_t *p; |
613 | 613 | |
614 | 614 | if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) |
615 | - return; | |
615 | + return -1; | |
616 | 616 | /* Short packets are padded with zeros. Receiving a packet |
617 | 617 | < 64 bytes long is considered an error condition. */ |
618 | 618 | if (size < 64) |
... | ... | @@ -625,10 +625,10 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) |
625 | 625 | packetsize += 4; |
626 | 626 | /* TODO: Flag overrun and receive errors. */ |
627 | 627 | if (packetsize > 2048) |
628 | - return; | |
628 | + return -1; | |
629 | 629 | packetnum = smc91c111_allocate_packet(s); |
630 | 630 | if (packetnum == 0x80) |
631 | - return; | |
631 | + return -1; | |
632 | 632 | s->rx_fifo[s->rx_fifo_len++] = packetnum; |
633 | 633 | |
634 | 634 | p = &s->data[packetnum][0]; |
... | ... | @@ -676,6 +676,8 @@ static void smc91c111_receive(void *opaque, const uint8_t *buf, int size) |
676 | 676 | /* TODO: Raise early RX interrupt? */ |
677 | 677 | s->int_level |= INT_RCV; |
678 | 678 | smc91c111_update(s); |
679 | + | |
680 | + return size; | |
679 | 681 | } |
680 | 682 | |
681 | 683 | static CPUReadMemoryFunc *smc91c111_readfn[] = { |
... | ... | @@ -711,7 +713,7 @@ static void smc91c111_init1(SysBusDevice *dev) |
711 | 713 | smc91c111_reset(s); |
712 | 714 | |
713 | 715 | s->vc = qdev_get_vlan_client(&dev->qdev, |
714 | - smc91c111_receive, smc91c111_can_receive, | |
716 | + smc91c111_can_receive, smc91c111_receive, NULL, | |
715 | 717 | smc91c111_cleanup, s); |
716 | 718 | qemu_format_nic_info_str(s->vc, s->macaddr); |
717 | 719 | /* ??? Save/restore. */ | ... | ... |
hw/stellaris_enet.c
... | ... | @@ -78,18 +78,18 @@ static void stellaris_enet_update(stellaris_enet_state *s) |
78 | 78 | } |
79 | 79 | |
80 | 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 | 84 | int n; |
85 | 85 | uint8_t *p; |
86 | 86 | uint32_t crc; |
87 | 87 | |
88 | 88 | if ((s->rctl & SE_RCTL_RXEN) == 0) |
89 | - return; | |
89 | + return -1; | |
90 | 90 | if (s->np >= 31) { |
91 | 91 | DPRINTF("Packet dropped\n"); |
92 | - return; | |
92 | + return -1; | |
93 | 93 | } |
94 | 94 | |
95 | 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 | 116 | |
117 | 117 | s->ris |= SE_INT_RX; |
118 | 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 | 127 | if ((s->rctl & SE_RCTL_RXEN) == 0) |
126 | 128 | return 1; |
... | ... | @@ -128,9 +130,9 @@ static int stellaris_enet_can_receive(void *opaque) |
128 | 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 | 136 | uint32_t val; |
135 | 137 | |
136 | 138 | switch (offset) { |
... | ... | @@ -405,8 +407,8 @@ static void stellaris_enet_init(SysBusDevice *dev) |
405 | 407 | qdev_get_macaddr(&dev->qdev, s->macaddr); |
406 | 408 | |
407 | 409 | s->vc = qdev_get_vlan_client(&dev->qdev, |
408 | - stellaris_enet_receive, | |
409 | 410 | stellaris_enet_can_receive, |
411 | + stellaris_enet_receive, NULL, | |
410 | 412 | stellaris_enet_cleanup, s); |
411 | 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 | 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 | 1375 | struct rndis_packet_msg_type *msg; |
1376 | 1376 | |
1377 | 1377 | if (s->rndis) { |
1378 | 1378 | msg = (struct rndis_packet_msg_type *) s->in_buf; |
1379 | 1379 | if (!s->rndis_state == RNDIS_DATA_INITIALIZED) |
1380 | - return; | |
1380 | + return -1; | |
1381 | 1381 | if (size + sizeof(struct rndis_packet_msg_type) > sizeof(s->in_buf)) |
1382 | - return; | |
1382 | + return -1; | |
1383 | 1383 | |
1384 | 1384 | memset(msg, 0, sizeof(struct rndis_packet_msg_type)); |
1385 | 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 | 1398 | s->in_len = size + sizeof(struct rndis_packet_msg_type); |
1399 | 1399 | } else { |
1400 | 1400 | if (size > sizeof(s->in_buf)) |
1401 | - return; | |
1401 | + return -1; | |
1402 | 1402 | memcpy(s->in_buf, buf, size); |
1403 | 1403 | s->in_len = size; |
1404 | 1404 | } |
1405 | 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 | 1413 | if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED) |
1413 | 1414 | return 1; |
... | ... | @@ -1458,8 +1459,9 @@ USBDevice *usb_net_init(NICInfo *nd) |
1458 | 1459 | pstrcpy(s->dev.devname, sizeof(s->dev.devname), |
1459 | 1460 | "QEMU USB Network Interface"); |
1460 | 1461 | s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name, |
1461 | - usbnet_receive, | |
1462 | 1462 | usbnet_can_receive, |
1463 | + usbnet_receive, | |
1464 | + NULL, | |
1463 | 1465 | usbnet_cleanup, s); |
1464 | 1466 | |
1465 | 1467 | qemu_format_nic_info_str(s->vc, s->mac); | ... | ... |
hw/virtio-net.c
... | ... | @@ -16,9 +16,9 @@ |
16 | 16 | #include "qemu-timer.h" |
17 | 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 | 22 | #define MAX_VLAN (1 << 12) /* Per 802.1Q definition */ |
23 | 23 | |
24 | 24 | typedef struct VirtIONet |
... | ... | @@ -33,10 +33,17 @@ typedef struct VirtIONet |
33 | 33 | QEMUTimer *tx_timer; |
34 | 34 | int tx_timer_active; |
35 | 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 | 42 | struct { |
39 | 43 | int in_use; |
44 | + int first_multi; | |
45 | + uint8_t multi_overflow; | |
46 | + uint8_t uni_overflow; | |
40 | 47 | uint8_t *macs; |
41 | 48 | } mac_table; |
42 | 49 | uint32_t *vlans; |
... | ... | @@ -95,9 +102,16 @@ static void virtio_net_reset(VirtIODevice *vdev) |
95 | 102 | /* Reset back to compatibility mode */ |
96 | 103 | n->promisc = 1; |
97 | 104 | n->allmulti = 0; |
105 | + n->alluni = 0; | |
106 | + n->nomulti = 0; | |
107 | + n->nouni = 0; | |
108 | + n->nobcast = 0; | |
98 | 109 | |
99 | 110 | /* Flush any MAC and VLAN filter table state */ |
100 | 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 | 115 | memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); |
102 | 116 | memset(n->vlans, 0, MAX_VLAN >> 3); |
103 | 117 | } |
... | ... | @@ -108,7 +122,8 @@ static uint32_t virtio_net_get_features(VirtIODevice *vdev) |
108 | 122 | (1 << VIRTIO_NET_F_STATUS) | |
109 | 123 | (1 << VIRTIO_NET_F_CTRL_VQ) | |
110 | 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 | 128 | return features; |
114 | 129 | } |
... | ... | @@ -151,6 +166,14 @@ static int virtio_net_handle_rx_mode(VirtIONet *n, uint8_t cmd, |
151 | 166 | n->promisc = on; |
152 | 167 | else if (cmd == VIRTIO_NET_CTRL_RX_MODE_ALLMULTI) |
153 | 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 | 177 | else |
155 | 178 | return VIRTIO_NET_ERR; |
156 | 179 | |
... | ... | @@ -168,6 +191,9 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, |
168 | 191 | return VIRTIO_NET_ERR; |
169 | 192 | |
170 | 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 | 197 | memset(n->mac_table.macs, 0, MAC_TABLE_ENTRIES * ETH_ALEN); |
172 | 198 | |
173 | 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 | 207 | mac_data.entries * ETH_ALEN); |
182 | 208 | n->mac_table.in_use += mac_data.entries; |
183 | 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 | 215 | mac_data.entries = ldl_le_p(elem->out_sg[2].iov_base); |
189 | 216 | |
190 | 217 | if (sizeof(mac_data.entries) + |
... | ... | @@ -197,8 +224,9 @@ static int virtio_net_handle_mac(VirtIONet *n, uint8_t cmd, |
197 | 224 | elem->out_sg[2].iov_base + sizeof(mac_data), |
198 | 225 | mac_data.entries * ETH_ALEN); |
199 | 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 | 232 | return VIRTIO_NET_OK; |
... | ... | @@ -269,6 +297,9 @@ static void virtio_net_handle_ctrl(VirtIODevice *vdev, VirtQueue *vq) |
269 | 297 | |
270 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 414 | struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL; |
368 | 415 | size_t hdr_len, offset, i; |
369 | 416 | |
370 | 417 | if (!do_virtio_net_can_receive(n, size)) |
371 | - return; | |
418 | + return 0; | |
372 | 419 | |
373 | 420 | if (!receive_filter(n, buf, size)) |
374 | - return; | |
421 | + return size; | |
375 | 422 | |
376 | 423 | /* hdr_len refers to the header we supply to the guest */ |
377 | 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 | 436 | if ((i != 0 && !n->mergeable_rx_bufs) || |
390 | 437 | virtqueue_pop(n->rx_vq, &elem) == 0) { |
391 | 438 | if (i == 0) |
392 | - return; | |
439 | + return -1; | |
393 | 440 | fprintf(stderr, "virtio-net truncating packet\n"); |
394 | 441 | exit(1); |
395 | 442 | } |
... | ... | @@ -431,6 +478,8 @@ static void virtio_net_receive(void *opaque, const uint8_t *buf, int size) |
431 | 478 | |
432 | 479 | virtqueue_flush(n->rx_vq, i); |
433 | 480 | virtio_notify(&n->vdev, n->rx_vq); |
481 | + | |
482 | + return size; | |
434 | 483 | } |
435 | 484 | |
436 | 485 | /* TX */ |
... | ... | @@ -518,16 +567,24 @@ static void virtio_net_save(QEMUFile *f, void *opaque) |
518 | 567 | qemu_put_be32(f, n->tx_timer_active); |
519 | 568 | qemu_put_be32(f, n->mergeable_rx_bufs); |
520 | 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 | 572 | qemu_put_be32(f, n->mac_table.in_use); |
524 | 573 | qemu_put_buffer(f, n->mac_table.macs, n->mac_table.in_use * ETH_ALEN); |
525 | 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 | 584 | static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) |
529 | 585 | { |
530 | 586 | VirtIONet *n = opaque; |
587 | + int i; | |
531 | 588 | |
532 | 589 | if (version_id < 2 || version_id > VIRTIO_NET_VM_VERSION) |
533 | 590 | return -EINVAL; |
... | ... | @@ -542,8 +599,13 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) |
542 | 599 | n->status = qemu_get_be16(f); |
543 | 600 | |
544 | 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 | 611 | if (version_id >= 5) { |
... | ... | @@ -554,7 +616,7 @@ static int virtio_net_load(QEMUFile *f, void *opaque, int version_id) |
554 | 616 | n->mac_table.in_use * ETH_ALEN); |
555 | 617 | } else if (n->mac_table.in_use) { |
556 | 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 | 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 | 624 | if (version_id >= 6) |
563 | 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 | 653 | if (n->tx_timer_active) { |
566 | 654 | qemu_mod_timer(n->tx_timer, |
567 | 655 | qemu_get_clock(vm_clock) + TX_TIMER_INTERVAL); |
... | ... | @@ -602,12 +690,12 @@ VirtIODevice *virtio_net_init(DeviceState *dev) |
602 | 690 | n->vdev.reset = virtio_net_reset; |
603 | 691 | n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx); |
604 | 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 | 694 | qdev_get_macaddr(dev, n->mac); |
607 | 695 | n->status = VIRTIO_NET_S_LINK_UP; |
608 | 696 | n->vc = qdev_get_vlan_client(dev, |
609 | - virtio_net_receive, | |
610 | 697 | virtio_net_can_receive, |
698 | + virtio_net_receive, NULL, | |
611 | 699 | virtio_net_cleanup, n); |
612 | 700 | n->vc->link_status_changed = virtio_net_set_link_status; |
613 | 701 | ... | ... |
hw/virtio-net.h
... | ... | @@ -43,6 +43,7 @@ |
43 | 43 | #define VIRTIO_NET_F_CTRL_VQ 17 /* Control channel available */ |
44 | 44 | #define VIRTIO_NET_F_CTRL_RX 18 /* Control channel RX mode support */ |
45 | 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 | 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 | 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 | 113 | #define VIRTIO_NET_CTRL_RX_MODE 0 |
112 | 114 | #define VIRTIO_NET_CTRL_RX_MODE_PROMISC 0 |
113 | 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 | 122 | * Control the MAC filter table. | ... | ... |
hw/xen_nic.c
... | ... | @@ -223,9 +223,9 @@ static void net_rx_response(struct XenNetDev *netdev, |
223 | 223 | |
224 | 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 | 229 | RING_IDX rc, rp; |
230 | 230 | |
231 | 231 | if (netdev->xendev.be_state != XenbusStateConnected) |
... | ... | @@ -243,15 +243,15 @@ static int net_rx_ok(void *opaque) |
243 | 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 | 249 | netif_rx_request_t rxreq; |
250 | 250 | RING_IDX rc, rp; |
251 | 251 | void *page; |
252 | 252 | |
253 | 253 | if (netdev->xendev.be_state != XenbusStateConnected) |
254 | - return; | |
254 | + return -1; | |
255 | 255 | |
256 | 256 | rc = netdev->rx_ring.req_cons; |
257 | 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 | 259 | |
260 | 260 | if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) { |
261 | 261 | xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n"); |
262 | - return; | |
262 | + return -1; | |
263 | 263 | } |
264 | 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 | 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 | 277 | xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n", |
278 | 278 | rxreq.gref); |
279 | 279 | net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); |
280 | - return; | |
280 | + return -1; | |
281 | 281 | } |
282 | 282 | memcpy(page + NET_IP_ALIGN, buf, size); |
283 | 283 | xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1); |
284 | 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 | 303 | |
302 | 304 | vlan = qemu_find_vlan(netdev->xendev.dev); |
303 | 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 | 308 | snprintf(netdev->vs->info_str, sizeof(netdev->vs->info_str), |
307 | 309 | "nic: xenbus vif macaddr=%s", netdev->mac); |
308 | 310 | ... | ... |
net.c
... | ... | @@ -332,8 +332,9 @@ static char *assign_name(VLANClientState *vc1, const char *model) |
332 | 332 | VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
333 | 333 | const char *model, |
334 | 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 | 338 | NetCleanup *cleanup, |
338 | 339 | void *opaque) |
339 | 340 | { |
... | ... | @@ -344,8 +345,9 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
344 | 345 | vc->name = strdup(name); |
345 | 346 | else |
346 | 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 | 351 | vc->cleanup = cleanup; |
350 | 352 | vc->opaque = opaque; |
351 | 353 | vc->vlan = vlan; |
... | ... | @@ -389,61 +391,126 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque) |
389 | 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 | 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 | 409 | return 0; |
404 | 410 | } |
405 | 411 | |
406 | -static void | |
412 | +static int | |
407 | 413 | qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size) |
408 | 414 | { |
409 | 415 | VLANClientState *vc; |
416 | + int ret = -1; | |
417 | + | |
418 | + sender->vlan->delivering = 1; | |
410 | 419 | |
411 | 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 | 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 | 490 | #ifdef DEBUG_NET |
427 | - printf("vlan %d send:\n", vlan->id); | |
491 | + printf("vlan %d send:\n", sender->vlan->id); | |
428 | 492 | hex_dump(stdout, buf, size); |
429 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 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 | 652 | #if defined(CONFIG_SLIRP) |
509 | 653 | |
510 | 654 | /* slirp network adapter */ |
511 | 655 | |
656 | +struct slirp_config_str { | |
657 | + struct slirp_config_str *next; | |
658 | + const char *str; | |
659 | +}; | |
660 | + | |
512 | 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 | 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 | 671 | int slirp_can_output(void) |
518 | 672 | { |
519 | 673 | return !slirp_vc || qemu_can_send_packet(slirp_vc); |
... | ... | @@ -535,13 +689,14 @@ int slirp_is_inited(void) |
535 | 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 | 694 | #ifdef DEBUG_SLIRP |
541 | 695 | printf("slirp input:\n"); |
542 | 696 | hex_dump(stdout, buf, size); |
543 | 697 | #endif |
544 | 698 | slirp_input(buf, size); |
699 | + return size; | |
545 | 700 | } |
546 | 701 | |
547 | 702 | static int slirp_in_use; |
... | ... | @@ -551,7 +706,8 @@ static void net_slirp_cleanup(VLANClientState *vc) |
551 | 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 | 712 | if (slirp_in_use) { |
557 | 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 | 715 | } |
560 | 716 | if (!slirp_inited) { |
561 | 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 | 736 | slirp_vc->info_str[0] = '\0'; |
567 | 737 | slirp_in_use = 1; |
568 | 738 | return 0; |
... | ... | @@ -643,32 +813,18 @@ static void net_slirp_redir_rm(Monitor *mon, const char *port_str) |
643 | 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 | 818 | struct in_addr guest_addr; |
652 | 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 | 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 | 826 | goto fail_syntax; |
827 | + } | |
672 | 828 | if (!strcmp(buf, "tcp") || buf[0] == '\0') { |
673 | 829 | is_udp = 0; |
674 | 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 | 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 | 837 | goto fail_syntax; |
838 | + } | |
682 | 839 | host_port = strtol(buf, &r, 0); |
683 | - if (r == buf) | |
840 | + if (r == buf) { | |
684 | 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 | 845 | goto fail_syntax; |
846 | + } | |
688 | 847 | if (buf[0] == '\0') { |
689 | 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 | 851 | goto fail_syntax; |
852 | + } | |
693 | 853 | |
694 | 854 | guest_port = strtol(p, &r, 0); |
695 | - if (r == p) | |
855 | + if (r == p) { | |
696 | 856 | goto fail_syntax; |
857 | + } | |
697 | 858 | |
698 | 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 | 862 | return; |
703 | 863 | |
704 | 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 | 897 | #ifndef _WIN32 |
... | ... | @@ -747,18 +929,12 @@ static void smb_exit(void) |
747 | 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 | 934 | char smb_conf[1024]; |
754 | 935 | char smb_cmdline[1024]; |
755 | 936 | FILE *f; |
756 | 937 | |
757 | - if (!slirp_inited) { | |
758 | - slirp_inited = 1; | |
759 | - slirp_init(slirp_restrict, slirp_ip); | |
760 | - } | |
761 | - | |
762 | 938 | /* XXX: better tmp dir construction */ |
763 | 939 | snprintf(smb_dir, sizeof(smb_dir), "/tmp/qemu-smb.%ld", (long)getpid()); |
764 | 940 | if (mkdir(smb_dir, 0700) < 0) { |
... | ... | @@ -802,7 +978,21 @@ void net_slirp_smb(const char *exported_dir) |
802 | 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 | 994 | #endif /* !defined(_WIN32) */ |
995 | + | |
806 | 996 | void do_info_slirp(Monitor *mon) |
807 | 997 | { |
808 | 998 | slirp_stats(); |
... | ... | @@ -834,14 +1024,15 @@ typedef struct TAPState { |
834 | 1024 | int fd; |
835 | 1025 | char down_script[1024]; |
836 | 1026 | char down_script_arg[128]; |
1027 | + uint8_t buf[4096]; | |
837 | 1028 | } TAPState; |
838 | 1029 | |
839 | 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 | 1033 | int iovcnt) |
843 | 1034 | { |
844 | - TAPState *s = opaque; | |
1035 | + TAPState *s = vc->opaque; | |
845 | 1036 | ssize_t len; |
846 | 1037 | |
847 | 1038 | do { |
... | ... | @@ -851,37 +1042,68 @@ static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov, |
851 | 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 | 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 | 1064 | #ifdef __sun__ |
1065 | +static ssize_t tap_read_packet(int tapfd, uint8_t *buf, int maxlen) | |
1066 | +{ | |
874 | 1067 | struct strbuf sbuf; |
875 | 1068 | int f = 0; |
876 | - sbuf.maxlen = sizeof(buf); | |
1069 | + | |
1070 | + sbuf.maxlen = maxlen; | |
877 | 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 | 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 | 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 | 1109 | static void tap_cleanup(VLANClientState *vc) |
... | ... | @@ -907,10 +1129,9 @@ static TAPState *net_tap_fd_init(VLANState *vlan, |
907 | 1129 | |
908 | 1130 | s = qemu_mallocz(sizeof(TAPState)); |
909 | 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 | 1135 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); |
915 | 1136 | return s; |
916 | 1137 | } |
... | ... | @@ -1107,38 +1328,46 @@ static int tap_open(char *ifname, int ifname_size) |
1107 | 1328 | |
1108 | 1329 | static int launch_script(const char *setup_script, const char *ifname, int fd) |
1109 | 1330 | { |
1331 | + sigset_t oldmask, mask; | |
1110 | 1332 | int pid, status; |
1111 | 1333 | char *args[3]; |
1112 | 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 | 1373 | static int net_tap_init(VLANState *vlan, const char *model, |
... | ... | @@ -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 | 1438 | static void vde_cleanup(VLANClientState *vc) |
... | ... | @@ -1235,7 +1463,7 @@ static int net_vde_init(VLANState *vlan, const char *model, |
1235 | 1463 | free(s); |
1236 | 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 | 1467 | NULL, vde_cleanup, s); |
1240 | 1468 | qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); |
1241 | 1469 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d", |
... | ... | @@ -1263,21 +1491,22 @@ typedef struct NetSocketListenState { |
1263 | 1491 | } NetSocketListenState; |
1264 | 1492 | |
1265 | 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 | 1497 | uint32_t len; |
1270 | 1498 | len = htonl(size); |
1271 | 1499 | |
1272 | 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 | 1512 | static void net_socket_send(void *opaque) |
... | ... | @@ -1473,7 +1702,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, |
1473 | 1702 | s = qemu_mallocz(sizeof(NetSocketState)); |
1474 | 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 | 1706 | NULL, net_socket_cleanup, s); |
1478 | 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 | 1730 | NetSocketState *s; |
1502 | 1731 | s = qemu_mallocz(sizeof(NetSocketState)); |
1503 | 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 | 1734 | NULL, net_socket_cleanup, s); |
1506 | 1735 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), |
1507 | 1736 | "socket: fd=%d", fd); |
... | ... | @@ -1714,16 +1943,16 @@ struct pcap_sf_pkthdr { |
1714 | 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 | 1949 | struct pcap_sf_pkthdr hdr; |
1721 | 1950 | int64_t ts; |
1722 | 1951 | int caplen; |
1723 | 1952 | |
1724 | 1953 | /* Early return in case of previous error. */ |
1725 | 1954 | if (s->fd < 0) { |
1726 | - return; | |
1955 | + return size; | |
1727 | 1956 | } |
1728 | 1957 | |
1729 | 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 | 1968 | close(s->fd); |
1740 | 1969 | s->fd = -1; |
1741 | 1970 | } |
1971 | + | |
1972 | + return size; | |
1742 | 1973 | } |
1743 | 1974 | |
1744 | 1975 | static void net_dump_cleanup(VLANClientState *vc) |
... | ... | @@ -1749,7 +1980,7 @@ static void net_dump_cleanup(VLANClientState *vc) |
1749 | 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 | 1984 | const char *name, const char *filename, int len) |
1754 | 1985 | { |
1755 | 1986 | struct pcap_file_hdr hdr; |
... | ... | @@ -1759,7 +1990,7 @@ static int net_dump_init(VLANState *vlan, const char *device, |
1759 | 1990 | |
1760 | 1991 | s->fd = open(filename, O_CREAT | O_WRONLY, 0644); |
1761 | 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 | 1994 | return -1; |
1764 | 1995 | } |
1765 | 1996 | |
... | ... | @@ -1774,13 +2005,13 @@ static int net_dump_init(VLANState *vlan, const char *device, |
1774 | 2005 | hdr.linktype = 1; |
1775 | 2006 | |
1776 | 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 | 2009 | close(s->fd); |
1779 | 2010 | qemu_free(s); |
1780 | 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 | 2015 | net_dump_cleanup, s); |
1785 | 2016 | snprintf(s->pcap_vc->info_str, sizeof(s->pcap_vc->info_str), |
1786 | 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 | 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 | 2085 | static const char * const fd_params[] = { |
1855 | 2086 | "vlan", "name", "fd", NULL |
... | ... | @@ -1866,7 +2097,7 @@ int net_client_init(const char *device, const char *p) |
1866 | 2097 | vlan = qemu_find_vlan(vlan_id); |
1867 | 2098 | |
1868 | 2099 | if (get_param_value(buf, sizeof(buf), "name", p)) { |
1869 | - name = strdup(buf); | |
2100 | + name = qemu_strdup(buf); | |
1870 | 2101 | } |
1871 | 2102 | if (!strcmp(device, "nic")) { |
1872 | 2103 | static const char * const nic_params[] = { |
... | ... | @@ -1876,12 +2107,13 @@ int net_client_init(const char *device, const char *p) |
1876 | 2107 | uint8_t *macaddr; |
1877 | 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 | 2115 | if (idx == -1 || nb_nics >= MAX_NICS) { |
1884 | - fprintf(stderr, "Too Many NICs\n"); | |
2116 | + config_error(mon, "Too Many NICs\n"); | |
1885 | 2117 | ret = -1; |
1886 | 2118 | goto out; |
1887 | 2119 | } |
... | ... | @@ -1896,7 +2128,7 @@ int net_client_init(const char *device, const char *p) |
1896 | 2128 | |
1897 | 2129 | if (get_param_value(buf, sizeof(buf), "macaddr", p)) { |
1898 | 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 | 2132 | ret = -1; |
1901 | 2133 | goto out; |
1902 | 2134 | } |
... | ... | @@ -1914,8 +2146,9 @@ int net_client_init(const char *device, const char *p) |
1914 | 2146 | } else |
1915 | 2147 | if (!strcmp(device, "none")) { |
1916 | 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 | 2153 | /* does nothing. It is needed to signal that no network cards |
1921 | 2154 | are wanted */ |
... | ... | @@ -1926,21 +2159,26 @@ int net_client_init(const char *device, const char *p) |
1926 | 2159 | static const char * const slirp_params[] = { |
1927 | 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 | 2170 | if (get_param_value(buf, sizeof(buf), "hostname", p)) { |
1934 | 2171 | pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf); |
1935 | 2172 | } |
1936 | 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 | 2176 | if (get_param_value(buf, sizeof(buf), "ip", p)) { |
1940 | - slirp_ip = strdup(buf); | |
2177 | + ip = qemu_strdup(buf); | |
1941 | 2178 | } |
1942 | 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 | 2182 | } else if (!strcmp(device, "channel")) { |
1945 | 2183 | long port; |
1946 | 2184 | char name[20], *devname; |
... | ... | @@ -1949,7 +2187,7 @@ int net_client_init(const char *device, const char *p) |
1949 | 2187 | port = strtol(p, &devname, 10); |
1950 | 2188 | devname++; |
1951 | 2189 | if (port < 1 || port > 65535) { |
1952 | - fprintf(stderr, "vmchannel wrong port number\n"); | |
2190 | + config_error(mon, "vmchannel wrong port number\n"); | |
1953 | 2191 | ret = -1; |
1954 | 2192 | goto out; |
1955 | 2193 | } |
... | ... | @@ -1957,8 +2195,8 @@ int net_client_init(const char *device, const char *p) |
1957 | 2195 | snprintf(name, 20, "vmchannel%ld", port); |
1958 | 2196 | vmc->hd = qemu_chr_open(name, devname, NULL); |
1959 | 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 | 2200 | ret = -1; |
1963 | 2201 | goto out; |
1964 | 2202 | } |
... | ... | @@ -1976,12 +2214,13 @@ int net_client_init(const char *device, const char *p) |
1976 | 2214 | }; |
1977 | 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 | 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 | 2224 | ret = -1; |
1986 | 2225 | goto out; |
1987 | 2226 | } |
... | ... | @@ -1991,14 +2230,15 @@ int net_client_init(const char *device, const char *p) |
1991 | 2230 | #elif defined (_AIX) |
1992 | 2231 | #else |
1993 | 2232 | if (!strcmp(device, "tap")) { |
1994 | - char ifname[64]; | |
2233 | + char ifname[64], chkbuf[64]; | |
1995 | 2234 | char setup_script[1024], down_script[1024]; |
1996 | 2235 | int fd; |
1997 | 2236 | vlan->nb_host_devs++; |
1998 | 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 | 2243 | fd = strtol(buf, NULL, 0); |
2004 | 2244 | fcntl(fd, F_SETFL, O_NONBLOCK); |
... | ... | @@ -2008,9 +2248,10 @@ int net_client_init(const char *device, const char *p) |
2008 | 2248 | static const char * const tap_params[] = { |
2009 | 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 | 2256 | if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) { |
2016 | 2257 | ifname[0] = '\0'; |
... | ... | @@ -2026,11 +2267,13 @@ int net_client_init(const char *device, const char *p) |
2026 | 2267 | } else |
2027 | 2268 | #endif |
2028 | 2269 | if (!strcmp(device, "socket")) { |
2270 | + char chkbuf[64]; | |
2029 | 2271 | if (get_param_value(buf, sizeof(buf), "fd", p) > 0) { |
2030 | 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 | 2278 | fd = strtol(buf, NULL, 0); |
2036 | 2279 | ret = -1; |
... | ... | @@ -2040,31 +2283,34 @@ int net_client_init(const char *device, const char *p) |
2040 | 2283 | static const char * const listen_params[] = { |
2041 | 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 | 2291 | ret = net_socket_listen_init(vlan, device, name, buf); |
2048 | 2292 | } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) { |
2049 | 2293 | static const char * const connect_params[] = { |
2050 | 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 | 2301 | ret = net_socket_connect_init(vlan, device, name, buf); |
2057 | 2302 | } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) { |
2058 | 2303 | static const char * const mcast_params[] = { |
2059 | 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 | 2311 | ret = net_socket_mcast_init(vlan, device, name, buf); |
2066 | 2312 | } else { |
2067 | - fprintf(stderr, "Unknown socket options: %s\n", p); | |
2313 | + config_error(mon, "Unknown socket options: %s\n", p); | |
2068 | 2314 | ret = -1; |
2069 | 2315 | goto out; |
2070 | 2316 | } |
... | ... | @@ -2078,9 +2324,10 @@ int net_client_init(const char *device, const char *p) |
2078 | 2324 | char vde_sock[1024], vde_group[512]; |
2079 | 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 | 2332 | vlan->nb_host_devs++; |
2086 | 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 | 2358 | if (!get_param_value(buf, sizeof(buf), "file", p)) { |
2112 | 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 | 2362 | } else { |
2116 | - fprintf(stderr, "Unknown network device: %s\n", device); | |
2363 | + config_error(mon, "Unknown network device: %s\n", device); | |
2117 | 2364 | ret = -1; |
2118 | 2365 | goto out; |
2119 | 2366 | } |
2120 | 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 | 2370 | out: |
2124 | - if (name) | |
2125 | - free(name); | |
2371 | + qemu_free(name); | |
2126 | 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 | 2406 | monitor_printf(mon, "invalid host network device %s\n", device); |
2161 | 2407 | return; |
2162 | 2408 | } |
2163 | - if (net_client_init(device, opts ? opts : "") < 0) { | |
2409 | + if (net_client_init(mon, device, opts ? opts : "") < 0) { | |
2164 | 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 | 2452 | if (*p == ',') |
2207 | 2453 | p++; |
2208 | 2454 | |
2209 | - return net_client_init(device, p); | |
2455 | + return net_client_init(NULL, device, p); | |
2210 | 2456 | } |
2211 | 2457 | |
2212 | 2458 | void do_info_network(Monitor *mon) | ... | ... |
net.h
... | ... | @@ -5,19 +5,20 @@ |
5 | 5 | |
6 | 6 | /* VLANs support */ |
7 | 7 | |
8 | -typedef ssize_t (IOReadvHandler)(void *, const struct iovec *, int); | |
9 | - | |
10 | 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 | 13 | typedef void (NetCleanup) (VLANClientState *); |
13 | 14 | typedef void (LinkStatusChanged)(VLANClientState *); |
14 | 15 | |
15 | 16 | struct VLANClientState { |
16 | - IOReadHandler *fd_read; | |
17 | - IOReadvHandler *fd_readv; | |
17 | + NetReceive *receive; | |
18 | + NetReceiveIOV *receive_iov; | |
18 | 19 | /* Packets may still be sent if this returns zero. It's used to |
19 | 20 | rate-limit the slirp code. */ |
20 | - IOCanRWHandler *fd_can_read; | |
21 | + NetCanReceive *can_receive; | |
21 | 22 | NetCleanup *cleanup; |
22 | 23 | LinkStatusChanged *link_status_changed; |
23 | 24 | int link_down; |
... | ... | @@ -31,10 +32,13 @@ struct VLANClientState { |
31 | 32 | |
32 | 33 | typedef struct VLANPacket VLANPacket; |
33 | 34 | |
35 | +typedef void (NetPacketSent) (VLANClientState *); | |
36 | + | |
34 | 37 | struct VLANPacket { |
35 | 38 | struct VLANPacket *next; |
36 | 39 | VLANClientState *sender; |
37 | 40 | int size; |
41 | + NetPacketSent *sent_cb; | |
38 | 42 | uint8_t data[0]; |
39 | 43 | }; |
40 | 44 | |
... | ... | @@ -51,8 +55,9 @@ VLANState *qemu_find_vlan(int id); |
51 | 55 | VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
52 | 56 | const char *model, |
53 | 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 | 61 | NetCleanup *cleanup, |
57 | 62 | void *opaque); |
58 | 63 | void qemu_del_vlan_client(VLANClientState *vc); |
... | ... | @@ -60,7 +65,12 @@ VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque); |
60 | 65 | int qemu_can_send_packet(VLANClientState *vc); |
61 | 66 | ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, |
62 | 67 | int iovcnt); |
68 | +ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, | |
69 | + int iovcnt, NetPacketSent *sent_cb); | |
63 | 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 | 74 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
65 | 75 | void qemu_check_nic_model(NICInfo *nd, const char *model); |
66 | 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 | 118 | void net_checksum_calculate(uint8_t *data, int length); |
109 | 119 | |
110 | 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 | 122 | void net_client_uninit(NICInfo *nd); |
113 | 123 | int net_client_parse(const char *str); |
114 | 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 | 139 | |
130 | 140 | void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr); |
131 | 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 | 145 | NetCleanup *cleanup, |
135 | 146 | void *opaque); |
136 | 147 | ... | ... |
savevm.c
... | ... | @@ -131,7 +131,7 @@ static void qemu_announce_self_once(void *opaque) |
131 | 131 | len = announce_self_create(buf, nd_table[i].macaddr); |
132 | 132 | vlan = nd_table[i].vlan; |
133 | 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 | 137 | if (count--) { | ... | ... |
slirp/libslirp.h
slirp/slirp.c
... | ... | @@ -171,7 +171,7 @@ static void slirp_cleanup(void) |
171 | 171 | static void slirp_state_save(QEMUFile *f, void *opaque); |
172 | 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 | 176 | // debug_init("/tmp/slirp.log", DEBUG_DEFAULT); |
177 | 177 | ... | ... |
sysemu.h
... | ... | @@ -270,7 +270,8 @@ void usb_info(Monitor *mon); |
270 | 270 | |
271 | 271 | int get_param_value(char *buf, int buf_size, |
272 | 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 | 276 | void register_devices(void); |
276 | 277 | ... | ... |
tap-win32.c
... | ... | @@ -650,11 +650,11 @@ static void tap_cleanup(VLANClientState *vc) |
650 | 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 | 660 | static void tap_win32_send(void *opaque) |
... | ... | @@ -684,7 +684,7 @@ int tap_win32_init(VLANState *vlan, const char *model, |
684 | 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 | 688 | NULL, tap_cleanup, s); |
689 | 689 | |
690 | 690 | snprintf(s->vc->info_str, sizeof(s->vc->info_str), | ... | ... |
vl.c
... | ... | @@ -1836,45 +1836,34 @@ int get_param_value(char *buf, int buf_size, |
1836 | 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 | 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 | 1845 | p = str; |
1856 | 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 | 1848 | if (*p != '=') { |
1859 | - ret = -1; | |
1860 | - break; | |
1849 | + return -1; | |
1861 | 1850 | } |
1862 | 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 | 1854 | break; |
1855 | + } | |
1856 | + } | |
1866 | 1857 | if (params[i] == NULL) { |
1867 | - ret = -1; | |
1868 | - break; | |
1858 | + return -1; | |
1869 | 1859 | } |
1870 | 1860 | p = get_opt_value(NULL, 0, p); |
1871 | - if (*p != ',') | |
1861 | + if (*p != ',') { | |
1872 | 1862 | break; |
1863 | + } | |
1873 | 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 | 2216 | "cache", "format", "serial", "werror", |
2228 | 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 | 2222 | return -1; |
2233 | 2223 | } |
2234 | 2224 | |
... | ... | @@ -2709,7 +2699,7 @@ static int usb_device_add(const char *devname, int is_hotplug) |
2709 | 2699 | } else if (strstart(devname, "net:", &p)) { |
2710 | 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 | 2703 | return -1; |
2714 | 2704 | nd_table[nic].model = "usb"; |
2715 | 2705 | dev = usb_net_init(&nd_table[nic]); |
... | ... | @@ -4783,7 +4773,12 @@ static void termsig_handler(int signal) |
4783 | 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 | 4783 | struct sigaction act; |
4789 | 4784 | |
... | ... | @@ -4792,6 +4787,10 @@ static void termsig_setup(void) |
4792 | 4787 | sigaction(SIGINT, &act, NULL); |
4793 | 4788 | sigaction(SIGHUP, &act, NULL); |
4794 | 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 | 4796 | #endif |
... | ... | @@ -5920,7 +5919,7 @@ int main(int argc, char **argv, char **envp) |
5920 | 5919 | |
5921 | 5920 | #ifndef _WIN32 |
5922 | 5921 | /* must be after terminal init, SDL library changes signal handlers */ |
5923 | - termsig_setup(); | |
5922 | + sighandler_setup(); | |
5924 | 5923 | #endif |
5925 | 5924 | |
5926 | 5925 | /* Maintain compatibility with multiple stdio monitors */ | ... | ... |