Revision e3f5ec2b

b/hw/dp8393x.c
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->receive(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 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 725
    return -1;
726 726
}
727 727

  
728
static void nic_receive(void *opaque, const uint8_t * buf, size_t size)
728
static void 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;
b/hw/e1000.c
592 592
}
593 593

  
594 594
static int
595
e1000_can_receive(void *opaque)
595
e1000_can_receive(VLANClientState *vc)
596 596
{
597
    E1000State *s = opaque;
597
    E1000State *s = vc->opaque;
598 598

  
599 599
    return (s->mac_reg[RCTL] & E1000_RCTL_EN);
600 600
}
601 601

  
602 602
static void
603
e1000_receive(void *opaque, const uint8_t *buf, size_t size)
603
e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
604 604
{
605
    E1000State *s = opaque;
605
    E1000State *s = vc->opaque;
606 606
    struct e1000_rx_desc desc;
607 607
    target_phys_addr_t base;
608 608
    unsigned int n, rdt;
b/hw/eepro100.c
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, size_t size)
1444
static void 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 };
b/hw/etraxfs_eth.c
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, size_t size)
504
static void 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;
b/hw/mcf_fec.c
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, size_t size)
356
static void 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;
b/hw/mipsnet.c
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, size_t size)
78
static void 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))
85
    if (!mipsnet_can_receive(vc))
86 86
        return;
87 87

  
88 88
    s->busy = 1;
b/hw/musicpal.c
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, size_t size)
565
static void 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;
b/hw/ne2000.c
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 224

  
225 225
#define MIN_BUF_SIZE 60
226 226

  
227
static void ne2000_receive(void *opaque, const uint8_t *buf, size_t size)
227
static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
228 228
{
229
    NE2000State *s = opaque;
229
    NE2000State *s = vc->opaque;
230 230
    uint8_t *p;
231 231
    unsigned int total_len, next, avail, len, index, mcast_idx;
232 232
    uint8_t buf1[60];
b/hw/pcnet.c
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 1076

  
1077 1077
#define MIN_BUF_SIZE 60
1078 1078

  
1079
static void pcnet_receive(void *opaque, const uint8_t *buf, size_t size)
1079
static void 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;
......
1302 1302
                if (BCR_SWSTYLE(s) == 1)
1303 1303
                    add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS);
1304 1304
                s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC;
1305
                pcnet_receive(s, s->buffer, s->xmit_pos);
1305
                pcnet_receive(s->vc, s->buffer, s->xmit_pos);
1306 1306
                s->looptest = 0;
1307 1307
            } else
1308 1308
                if (s->vc)
b/hw/rtl8139.c
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 812
    }
813 813
}
814 814

  
815
static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int do_interrupt)
815
static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size, int do_interrupt)
816 816
{
817
    RTL8139State *s = opaque;
817
    RTL8139State *s = vc->opaque;
818 818

  
819 819
    uint32_t packet_header = 0;
820 820

  
......
1158 1158
    }
1159 1159
}
1160 1160

  
1161
static void rtl8139_receive(void *opaque, const uint8_t *buf, size_t size)
1161
static void rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1162 1162
{
1163
    rtl8139_do_receive(opaque, buf, size, 1);
1163
    rtl8139_do_receive(vc, buf, size, 1);
1164 1164
}
1165 1165

  
1166 1166
static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
......
1757 1757
    if (TxLoopBack == (s->TxConfig & TxLoopBack))
1758 1758
    {
1759 1759
        DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n"));
1760
        rtl8139_do_receive(s, buf, size, do_interrupt);
1760
        rtl8139_do_receive(s->vc, buf, size, do_interrupt);
1761 1761
    }
1762 1762
    else
1763 1763
    {
b/hw/smc91c111.c
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 602
    return 1;
603 603
}
604 604

  
605
static void smc91c111_receive(void *opaque, const uint8_t *buf, size_t size)
605
static void 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;
b/hw/stellaris_enet.c
78 78
}
79 79

  
80 80
/* TODO: Implement MAC address filtering.  */
81
static void stellaris_enet_receive(void *opaque, const uint8_t *buf, size_t size)
81
static void 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;
......
118 118
    stellaris_enet_update(s);
119 119
}
120 120

  
121
static int stellaris_enet_can_receive(void *opaque)
121
static int stellaris_enet_can_receive(VLANClientState *vc)
122 122
{
123
    stellaris_enet_state *s = (stellaris_enet_state *)opaque;
123
    stellaris_enet_state *s = vc->opaque;
124 124

  
125 125
    if ((s->rctl & SE_RCTL_RXEN) == 0)
126 126
        return 1;
......
128 128
    return (s->np < 31);
129 129
}
130 130

  
131
static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset)
131
static uint32_t stellaris_enet_read(VLANClientState *vc, target_phys_addr_t offset)
132 132
{
133
    stellaris_enet_state *s = (stellaris_enet_state *)opaque;
133
    stellaris_enet_state *s = vc->opaque;
134 134
    uint32_t val;
135 135

  
136 136
    switch (offset) {
b/hw/usb-net.c
1369 1369
    return ret;
1370 1370
}
1371 1371

  
1372
static void usbnet_receive(void *opaque, const uint8_t *buf, size_t size)
1372
static void 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) {
......
1405 1405
    s->in_ptr = 0;
1406 1406
}
1407 1407

  
1408
static int usbnet_can_receive(void *opaque)
1408
static int usbnet_can_receive(VLANClientState *vc)
1409 1409
{
1410
    USBNetState *s = opaque;
1410
    USBNetState *s = vc->opaque;
1411 1411

  
1412 1412
    if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED)
1413 1413
        return 1;
b/hw/virtio-net.c
288 288
    return 1;
289 289
}
290 290

  
291
static int virtio_net_can_receive(void *opaque)
291
static int virtio_net_can_receive(VLANClientState *vc)
292 292
{
293
    VirtIONet *n = opaque;
293
    VirtIONet *n = vc->opaque;
294 294

  
295 295
    return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE);
296 296
}
......
361 361
    return 0;
362 362
}
363 363

  
364
static void virtio_net_receive(void *opaque, const uint8_t *buf, size_t size)
364
static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
365 365
{
366
    VirtIONet *n = opaque;
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

  
b/hw/xen_nic.c
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 243
    return 1;
244 244
}
245 245

  
246
static void net_rx_packet(void *opaque, const uint8_t *buf, size_t size)
246
static void 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;
b/net.c
402 402
        }
403 403

  
404 404
        /* no can_receive() handler, they can always receive */
405
        if (!vc->can_receive || vc->can_receive(vc->opaque)) {
405
        if (!vc->can_receive || vc->can_receive(vc)) {
406 406
            return 1;
407 407
        }
408 408
    }
......
416 416

  
417 417
    for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
418 418
        if (vc != sender && !vc->link_down) {
419
            vc->receive(vc->opaque, buf, size);
419
            vc->receive(vc, buf, size);
420 420
        }
421 421
    }
422 422
}
......
467 467
        offset += len;
468 468
    }
469 469

  
470
    vc->receive(vc->opaque, buffer, offset);
470
    vc->receive(vc, buffer, offset);
471 471

  
472 472
    return offset;
473 473
}
......
520 520
            if (vc->link_down) {
521 521
                len = calc_iov_length(iov, iovcnt);
522 522
            } else if (vc->receive_iov) {
523
                len = vc->receive_iov(vc->opaque, iov, iovcnt);
523
                len = vc->receive_iov(vc, iov, iovcnt);
524 524
            } else if (vc->receive) {
525 525
                len = vc_sendv_compat(vc, iov, iovcnt);
526 526
            }
......
593 593
    return slirp_inited;
594 594
}
595 595

  
596
static void slirp_receive(void *opaque, const uint8_t *buf, size_t size)
596
static void slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
597 597
{
598 598
#ifdef DEBUG_SLIRP
599 599
    printf("slirp input:\n");
......
932 932

  
933 933
static int launch_script(const char *setup_script, const char *ifname, int fd);
934 934

  
935
static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov,
935
static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
936 936
                               int iovcnt)
937 937
{
938
    TAPState *s = opaque;
938
    TAPState *s = vc->opaque;
939 939
    ssize_t len;
940 940

  
941 941
    do {
......
945 945
    return len;
946 946
}
947 947

  
948
static void tap_receive(void *opaque, const uint8_t *buf, size_t size)
948
static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
949 949
{
950
    TAPState *s = opaque;
950
    TAPState *s = vc->opaque;
951 951
    int ret;
952 952
    for(;;) {
953 953
        ret = write(s->fd, buf, size);
......
1311 1311
    }
1312 1312
}
1313 1313

  
1314
static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
1314
static void vde_receive(VLANClientState *vc, const uint8_t *buf, int size)
1315 1315
{
1316
    VDEState *s = opaque;
1316
    VDEState *s = vc->opaque;
1317 1317
    int ret;
1318 1318
    for(;;) {
1319 1319
        ret = vde_send(s->vde, (const char *)buf, size, 0);
......
1352 1352
        free(s);
1353 1353
        return -1;
1354 1354
    }
1355
    s->vc = qemu_new_vlan_client(vlan, model, name, NULL, vde_from_qemu,
1355
    s->vc = qemu_new_vlan_client(vlan, model, name, NULL, vde_receive,
1356 1356
                                 NULL, vde_cleanup, s);
1357 1357
    qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
1358 1358
    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
......
1380 1380
} NetSocketListenState;
1381 1381

  
1382 1382
/* XXX: we consider we can send the whole packet without blocking */
1383
static void net_socket_receive(void *opaque, const uint8_t *buf, size_t size)
1383
static void net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1384 1384
{
1385
    NetSocketState *s = opaque;
1385
    NetSocketState *s = vc->opaque;
1386 1386
    uint32_t len;
1387 1387
    len = htonl(size);
1388 1388

  
......
1390 1390
    send_all(s->fd, buf, size);
1391 1391
}
1392 1392

  
1393
static void net_socket_receive_dgram(void *opaque, const uint8_t *buf, size_t size)
1393
static void net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
1394 1394
{
1395
    NetSocketState *s = opaque;
1395
    NetSocketState *s = vc->opaque;
1396 1396
    sendto(s->fd, buf, size, 0,
1397 1397
           (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
1398 1398
}
......
1831 1831
    uint32_t len;
1832 1832
};
1833 1833

  
1834
static void dump_receive(void *opaque, const uint8_t *buf, size_t size)
1834
static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
1835 1835
{
1836
    DumpState *s = opaque;
1836
    DumpState *s = vc->opaque;
1837 1837
    struct pcap_sf_pkthdr hdr;
1838 1838
    int64_t ts;
1839 1839
    int caplen;
b/net.h
7 7

  
8 8
typedef struct VLANClientState VLANClientState;
9 9

  
10
typedef int (NetCanReceive)(void *);
11
typedef void (NetReceive)(void *, const uint8_t *, size_t);
12
typedef ssize_t (NetReceiveIOV)(void *, const struct iovec *, int);
10
typedef int (NetCanReceive)(VLANClientState *);
11
typedef void (NetReceive)(VLANClientState *, const uint8_t *, size_t);
12
typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
13 13
typedef void (NetCleanup) (VLANClientState *);
14 14
typedef void (LinkStatusChanged)(VLANClientState *);
15 15

  
b/savevm.c
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->receive(vc->opaque, buf, len);
134
            vc->receive(vc, buf, len);
135 135
        }
136 136
    }
137 137
    if (count--) {
b/tap-win32.c
650 650
    qemu_free(s);
651 651
}
652 652

  
653
static void tap_receive(void *opaque, const uint8_t *buf, size_t size)
653
static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
654 654
{
655 655
    TAPState *s = opaque;
656 656

  

Also available in: Unified diff