Commit 4f1c942b7fb29864ad86cb3af9076da38f38f74e

Authored by Mark McLoughlin
1 parent e3f5ec2b

net: add return value to packet receive handler

This allows us to handle queue full conditions rather than dropping
the packet on the floor.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
hw/dp8393x.c
... ... @@ -725,7 +725,7 @@ 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(VLANClientState *vc, const uint8_t * buf, size_t 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 731 dp8393xState *s = vc->opaque;
... ... @@ -742,7 +742,7 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t 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(VLANClientState *vc, const uint8_t * buf, size_t 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(VLANClientState *vc, const uint8_t * buf, size_t 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)
... ...
hw/e1000.c
... ... @@ -599,7 +599,7 @@ e1000_can_receive(VLANClientState *vc)
599 599 return (s->mac_reg[RCTL] & E1000_RCTL_EN);
600 600 }
601 601  
602   -static void
  602 +static ssize_t
603 603 e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
604 604 {
605 605 E1000State *s = vc->opaque;
... ... @@ -611,16 +611,16 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
611 611 uint8_t vlan_status = 0, vlan_offset = 0;
612 612  
613 613 if (!(s->mac_reg[RCTL] & E1000_RCTL_EN))
614   - return;
  614 + return -1;
615 615  
616 616 if (size > s->rxbuf_size) {
617 617 DBGOUT(RX, "packet too large for buffers (%lu > %d)\n",
618 618 (unsigned long)size, s->rxbuf_size);
619   - return;
  619 + return -1;
620 620 }
621 621  
622 622 if (!receive_filter(s, buf, size))
623   - return;
  623 + return size;
624 624  
625 625 if (vlan_enabled(s) && is_vlan_packet(s, buf)) {
626 626 vlan_special = cpu_to_le16(be16_to_cpup((uint16_t *)(buf + 14)));
... ... @@ -635,7 +635,7 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
635 635 do {
636 636 if (s->mac_reg[RDH] == s->mac_reg[RDT] && s->check_rxov) {
637 637 set_ics(s, 0, E1000_ICS_RXO);
638   - return;
  638 + return -1;
639 639 }
640 640 base = ((uint64_t)s->mac_reg[RDBAH] << 32) + s->mac_reg[RDBAL] +
641 641 sizeof(desc) * s->mac_reg[RDH];
... ... @@ -659,7 +659,7 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
659 659 DBGOUT(RXERR, "RDH wraparound @%x, RDT %x, RDLEN %x\n",
660 660 rdh_start, s->mac_reg[RDT], s->mac_reg[RDLEN]);
661 661 set_ics(s, 0, E1000_ICS_RXO);
662   - return;
  662 + return -1;
663 663 }
664 664 } while (desc.buffer_addr == 0);
665 665  
... ... @@ -677,6 +677,8 @@ e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
677 677 n |= E1000_ICS_RXDMT0;
678 678  
679 679 set_ics(s, 0, n);
  680 +
  681 + return size;
680 682 }
681 683  
682 684 static uint32_t
... ...
hw/eepro100.c
... ... @@ -1441,7 +1441,7 @@ static int nic_can_receive(VLANClientState *vc)
1441 1441 //~ return !eepro100_buffer_full(s);
1442 1442 }
1443 1443  
1444   -static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t 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.
... ... @@ -1458,18 +1458,18 @@ static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t 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(VLANClientState *vc, const uint8_t * buf, size_t 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(VLANClientState *vc, const uint8_t * buf, size_t 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(VLANClientState *vc, const uint8_t * buf, size_t 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(VLANClientState *vc, const uint8_t * buf, size_t 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)
... ...
hw/etraxfs_eth.c
... ... @@ -501,7 +501,7 @@ static int eth_can_receive(VLANClientState *vc)
501 501 return 1;
502 502 }
503 503  
504   -static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t 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 507 struct fs_eth *eth = vc->opaque;
... ... @@ -510,7 +510,7 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
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(VLANClientState *vc, const uint8_t *buf, size_t 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)
... ...
hw/mcf_fec.c
... ... @@ -353,7 +353,7 @@ static int mcf_fec_can_receive(VLANClientState *vc)
353 353 return s->rx_enabled;
354 354 }
355 355  
356   -static void mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  356 +static ssize_t mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
357 357 {
358 358 mcf_fec_state *s = vc->opaque;
359 359 mcf_fec_bd bd;
... ... @@ -426,6 +426,7 @@ static void mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t 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[] = {
... ...
hw/mipsnet.c
... ... @@ -75,7 +75,7 @@ static int mipsnet_can_receive(VLANClientState *vc)
75 75 return !mipsnet_buffer_full(s);
76 76 }
77 77  
78   -static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  78 +static ssize_t mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
79 79 {
80 80 MIPSnetState *s = vc->opaque;
81 81  
... ... @@ -83,7 +83,7 @@ static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size
83 83 printf("mipsnet: receiving len=%d\n", size);
84 84 #endif
85 85 if (!mipsnet_can_receive(vc))
86   - return;
  86 + return -1;
87 87  
88 88 s->busy = 1;
89 89  
... ... @@ -98,6 +98,8 @@ static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t 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)
... ...
hw/musicpal.c
... ... @@ -562,7 +562,7 @@ static int eth_can_receive(VLANClientState *vc)
562 562 return 1;
563 563 }
564 564  
565   -static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  565 +static ssize_t eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
566 566 {
567 567 mv88w8618_eth_state *s = vc->opaque;
568 568 uint32_t desc_addr;
... ... @@ -586,11 +586,12 @@ static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t 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)
... ...
hw/ne2000.c
... ... @@ -224,9 +224,10 @@ static int ne2000_can_receive(VLANClientState *vc)
224 224  
225 225 #define MIN_BUF_SIZE 60
226 226  
227   -static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  227 +static ssize_t ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
228 228 {
229 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(VLANClientState *vc, const uint8_t *buf, size_t 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(VLANClientState *vc, const uint8_t *buf, size_t 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(VLANClientState *vc, const uint8_t *buf, size_t 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(VLANClientState *vc, const uint8_t *buf, size_t 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)
... ...
hw/pcnet.c
... ... @@ -1076,16 +1076,17 @@ static int pcnet_can_receive(VLANClientState *vc)
1076 1076  
1077 1077 #define MIN_BUF_SIZE 60
1078 1078  
1079   -static void pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  1079 +static ssize_t pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size_)
1080 1080 {
1081 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(VLANClientState *vc, const uint8_t *buf, size_t 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)
... ...
hw/rtl8139.c
... ... @@ -812,9 +812,10 @@ static int rtl8139_can_receive(VLANClientState *vc)
812 812 }
813 813 }
814 814  
815   -static void rtl8139_do_receive(VLANClientState *vc, 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 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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
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(VLANClientState *vc, const uint8_t *buf, int size
1156 1157 {
1157 1158 rtl8139_update_irq(s);
1158 1159 }
  1160 +
  1161 + return size_;
1159 1162 }
1160 1163  
1161   -static void rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  1164 +static ssize_t rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1162 1165 {
1163   - rtl8139_do_receive(vc, 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)
... ...
hw/smc91c111.c
... ... @@ -602,7 +602,7 @@ static int smc91c111_can_receive(VLANClientState *vc)
602 602 return 1;
603 603 }
604 604  
605   -static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  605 +static ssize_t smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
606 606 {
607 607 smc91c111_state *s = vc->opaque;
608 608 int status;
... ... @@ -612,7 +612,7 @@ static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t si
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(VLANClientState *vc, const uint8_t *buf, size_t si
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(VLANClientState *vc, const uint8_t *buf, size_t si
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[] = {
... ...
hw/stellaris_enet.c
... ... @@ -78,7 +78,7 @@ 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(VLANClientState *vc, const uint8_t *buf, size_t size)
  81 +static ssize_t stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
82 82 {
83 83 stellaris_enet_state *s = vc->opaque;
84 84 int n;
... ... @@ -86,10 +86,10 @@ static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size
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,6 +116,8 @@ static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, 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 123 static int stellaris_enet_can_receive(VLANClientState *vc)
... ...
hw/usb-net.c
... ... @@ -1369,7 +1369,7 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p)
1369 1369 return ret;
1370 1370 }
1371 1371  
1372   -static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  1372 +static ssize_t usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1373 1373 {
1374 1374 USBNetState *s = vc->opaque;
1375 1375 struct rndis_packet_msg_type *msg;
... ... @@ -1377,9 +1377,9 @@ static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
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,11 +1398,12 @@ static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t 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 1409 static int usbnet_can_receive(VLANClientState *vc)
... ...
hw/virtio-net.c
... ... @@ -361,17 +361,17 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
361 361 return 0;
362 362 }
363 363  
364   -static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  364 +static ssize_t virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
365 365 {
366 366 VirtIONet *n = vc->opaque;
367 367 struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
368 368 size_t hdr_len, offset, i;
369 369  
370 370 if (!do_virtio_net_can_receive(n, size))
371   - return;
  371 + return -1;
372 372  
373 373 if (!receive_filter(n, buf, size))
374   - return;
  374 + return size;
375 375  
376 376 /* hdr_len refers to the header we supply to the guest */
377 377 hdr_len = n->mergeable_rx_bufs ?
... ... @@ -389,7 +389,7 @@ static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t s
389 389 if ((i != 0 && !n->mergeable_rx_bufs) ||
390 390 virtqueue_pop(n->rx_vq, &elem) == 0) {
391 391 if (i == 0)
392   - return;
  392 + return -1;
393 393 fprintf(stderr, "virtio-net truncating packet\n");
394 394 exit(1);
395 395 }
... ... @@ -431,6 +431,8 @@ static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t s
431 431  
432 432 virtqueue_flush(n->rx_vq, i);
433 433 virtio_notify(&n->vdev, n->rx_vq);
  434 +
  435 + return size;
434 436 }
435 437  
436 438 /* TX */
... ...
hw/xen_nic.c
... ... @@ -243,7 +243,7 @@ static int net_rx_ok(VLANClientState *vc)
243 243 return 1;
244 244 }
245 245  
246   -static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
  246 +static ssize_t net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
247 247 {
248 248 struct XenNetDev *netdev = vc->opaque;
249 249 netif_rx_request_t rxreq;
... ... @@ -251,7 +251,7 @@ static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
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(VLANClientState *vc, const uint8_t *buf, size_t 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 265 xen_be_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)",
266 266 (unsigned long)size, XC_PAGE_SIZE - NET_IP_ALIGN);
267   - return;
  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(VLANClientState *vc, const uint8_t *buf, size_t 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 /* ------------------------------------------------------------- */
... ...
... ... @@ -593,13 +593,14 @@ int slirp_is_inited(void)
593 593 return slirp_inited;
594 594 }
595 595  
596   -static void slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  596 +static ssize_t slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
597 597 {
598 598 #ifdef DEBUG_SLIRP
599 599 printf("slirp input:\n");
600 600 hex_dump(stdout, buf, size);
601 601 #endif
602 602 slirp_input(buf, size);
  603 + return size;
603 604 }
604 605  
605 606 static int slirp_in_use;
... ... @@ -945,17 +946,16 @@ static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
945 946 return len;
946 947 }
947 948  
948   -static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  949 +static ssize_t tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
949 950 {
950 951 TAPState *s = vc->opaque;
951   - int ret;
952   - for(;;) {
953   - ret = write(s->fd, buf, size);
954   - if (ret < 0 && (errno == EINTR || errno == EAGAIN)) {
955   - } else {
956   - break;
957   - }
958   - }
  952 + ssize_t len;
  953 +
  954 + do {
  955 + len = write(s->fd, buf, size);
  956 + } while (len == -1 && (errno == EINTR || errno == EAGAIN));
  957 +
  958 + return len;
959 959 }
960 960  
961 961 static int tap_can_send(void *opaque)
... ... @@ -1311,17 +1311,16 @@ static void vde_to_qemu(void *opaque)
1311 1311 }
1312 1312 }
1313 1313  
1314   -static void vde_receive(VLANClientState *vc, const uint8_t *buf, int size)
  1314 +static ssize_t vde_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1315 1315 {
1316 1316 VDEState *s = vc->opaque;
1317   - int ret;
1318   - for(;;) {
1319   - ret = vde_send(s->vde, (const char *)buf, size, 0);
1320   - if (ret < 0 && errno == EINTR) {
1321   - } else {
1322   - break;
1323   - }
1324   - }
  1317 + ssize ret;
  1318 +
  1319 + do {
  1320 + ret = vde_send(s->vde, (const char *)buf, size, 0);
  1321 + } while (ret < 0 && errno == EINTR);
  1322 +
  1323 + return ret;
1325 1324 }
1326 1325  
1327 1326 static void vde_cleanup(VLANClientState *vc)
... ... @@ -1380,21 +1379,22 @@ typedef struct NetSocketListenState {
1380 1379 } NetSocketListenState;
1381 1380  
1382 1381 /* XXX: we consider we can send the whole packet without blocking */
1383   -static void net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  1382 +static ssize_t net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1384 1383 {
1385 1384 NetSocketState *s = vc->opaque;
1386 1385 uint32_t len;
1387 1386 len = htonl(size);
1388 1387  
1389 1388 send_all(s->fd, (const uint8_t *)&len, sizeof(len));
1390   - send_all(s->fd, buf, size);
  1389 + return send_all(s->fd, buf, size);
1391 1390 }
1392 1391  
1393   -static void net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
  1392 +static ssize_t net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
1394 1393 {
1395 1394 NetSocketState *s = vc->opaque;
1396   - sendto(s->fd, buf, size, 0,
1397   - (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
  1395 +
  1396 + return sendto(s->fd, buf, size, 0,
  1397 + (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
1398 1398 }
1399 1399  
1400 1400 static void net_socket_send(void *opaque)
... ... @@ -1831,7 +1831,7 @@ struct pcap_sf_pkthdr {
1831 1831 uint32_t len;
1832 1832 };
1833 1833  
1834   -static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
  1834 +static ssize_t dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1835 1835 {
1836 1836 DumpState *s = vc->opaque;
1837 1837 struct pcap_sf_pkthdr hdr;
... ... @@ -1840,7 +1840,7 @@ static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1840 1840  
1841 1841 /* Early return in case of previous error. */
1842 1842 if (s->fd < 0) {
1843   - return;
  1843 + return size;
1844 1844 }
1845 1845  
1846 1846 ts = muldiv64(qemu_get_clock(vm_clock), 1000000, ticks_per_sec);
... ... @@ -1856,6 +1856,8 @@ static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1856 1856 close(s->fd);
1857 1857 s->fd = -1;
1858 1858 }
  1859 +
  1860 + return size;
1859 1861 }
1860 1862  
1861 1863 static void net_dump_cleanup(VLANClientState *vc)
... ...
... ... @@ -8,7 +8,7 @@
8 8 typedef struct VLANClientState VLANClientState;
9 9  
10 10 typedef int (NetCanReceive)(VLANClientState *);
11   -typedef void (NetReceive)(VLANClientState *, const uint8_t *, size_t);
  11 +typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
12 12 typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
13 13 typedef void (NetCleanup) (VLANClientState *);
14 14 typedef void (LinkStatusChanged)(VLANClientState *);
... ...
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(VLANClientState *vc, const uint8_t *buf, size_t 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)
... ...