net: pass VLANClientState* as first arg to receive handlers

Give static type checking a chance to catch errors.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
This commit is contained in:
Mark McLoughlin 2009-05-18 13:33:03 +01:00
parent cda9046ba7
commit e3f5ec2b5e
19 changed files with 90 additions and 90 deletions

View File

@ -407,9 +407,9 @@ static void do_transmit_packets(dp8393xState *s)
if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) { if (s->regs[SONIC_RCR] & (SONIC_RCR_LB1 | SONIC_RCR_LB0)) {
/* Loopback */ /* Loopback */
s->regs[SONIC_TCR] |= SONIC_TCR_CRSL; s->regs[SONIC_TCR] |= SONIC_TCR_CRSL;
if (s->vc->fd_can_read(s)) { if (s->vc->can_receive(s->vc)) {
s->loopback_packet = 1; s->loopback_packet = 1;
s->vc->receive(s, s->tx_buffer, tx_len); s->vc->receive(s->vc, s->tx_buffer, tx_len);
} }
} else { } else {
/* Transmit packet */ /* Transmit packet */
@ -676,9 +676,9 @@ static CPUWriteMemoryFunc *dp8393x_write[3] = {
dp8393x_writel, dp8393x_writel,
}; };
static int nic_can_receive(void *opaque) static int nic_can_receive(VLANClientState *vc)
{ {
dp8393xState *s = opaque; dp8393xState *s = vc->opaque;
if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN)) if (!(s->regs[SONIC_CR] & SONIC_CR_RXEN))
return 0; return 0;
@ -725,10 +725,10 @@ static int receive_filter(dp8393xState *s, const uint8_t * buf, int size)
return -1; return -1;
} }
static void nic_receive(void *opaque, const uint8_t * buf, size_t size) static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
{ {
uint16_t data[10]; uint16_t data[10];
dp8393xState *s = opaque; dp8393xState *s = vc->opaque;
int packet_type; int packet_type;
uint32_t available, address; uint32_t available, address;
int width, rx_len = size; int width, rx_len = size;

View File

@ -592,17 +592,17 @@ e1000_set_link_status(VLANClientState *vc)
} }
static int static int
e1000_can_receive(void *opaque) e1000_can_receive(VLANClientState *vc)
{ {
E1000State *s = opaque; E1000State *s = vc->opaque;
return (s->mac_reg[RCTL] & E1000_RCTL_EN); return (s->mac_reg[RCTL] & E1000_RCTL_EN);
} }
static void static void
e1000_receive(void *opaque, const uint8_t *buf, size_t size) e1000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
E1000State *s = opaque; E1000State *s = vc->opaque;
struct e1000_rx_desc desc; struct e1000_rx_desc desc;
target_phys_addr_t base; target_phys_addr_t base;
unsigned int n, rdt; unsigned int n, rdt;

View File

@ -1433,21 +1433,21 @@ static void pci_mmio_map(PCIDevice * pci_dev, int region_num,
} }
} }
static int nic_can_receive(void *opaque) static int nic_can_receive(VLANClientState *vc)
{ {
EEPRO100State *s = opaque; EEPRO100State *s = vc->opaque;
logout("%p\n", s); logout("%p\n", s);
return get_ru_state(s) == ru_ready; return get_ru_state(s) == ru_ready;
//~ return !eepro100_buffer_full(s); //~ return !eepro100_buffer_full(s);
} }
static void nic_receive(void *opaque, const uint8_t * buf, size_t size) static void nic_receive(VLANClientState *vc, const uint8_t * buf, size_t size)
{ {
/* TODO: /* TODO:
* - Magic packets should set bit 30 in power management driver register. * - Magic packets should set bit 30 in power management driver register.
* - Interesting packets should set bit 29 in power management driver register. * - Interesting packets should set bit 29 in power management driver register.
*/ */
EEPRO100State *s = opaque; EEPRO100State *s = vc->opaque;
uint16_t rfd_status = 0xa000; uint16_t rfd_status = 0xa000;
static const uint8_t broadcast_macaddr[6] = static const uint8_t broadcast_macaddr[6] =
{ 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };

View File

@ -496,15 +496,15 @@ static int eth_match_groupaddr(struct fs_eth *eth, const unsigned char *sa)
return match; return match;
} }
static int eth_can_receive(void *opaque) static int eth_can_receive(VLANClientState *vc)
{ {
return 1; return 1;
} }
static void eth_receive(void *opaque, const uint8_t *buf, size_t size) static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; unsigned char sa_bcast[6] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
struct fs_eth *eth = opaque; struct fs_eth *eth = vc->opaque;
int use_ma0 = eth->regs[RW_REC_CTRL] & 1; int use_ma0 = eth->regs[RW_REC_CTRL] & 1;
int use_ma1 = eth->regs[RW_REC_CTRL] & 2; int use_ma1 = eth->regs[RW_REC_CTRL] & 2;
int r_bcast = eth->regs[RW_REC_CTRL] & 8; int r_bcast = eth->regs[RW_REC_CTRL] & 8;

View File

@ -347,15 +347,15 @@ static void mcf_fec_write(void *opaque, target_phys_addr_t addr, uint32_t value)
mcf_fec_update(s); mcf_fec_update(s);
} }
static int mcf_fec_can_receive(void *opaque) static int mcf_fec_can_receive(VLANClientState *vc)
{ {
mcf_fec_state *s = (mcf_fec_state *)opaque; mcf_fec_state *s = vc->opaque;
return s->rx_enabled; return s->rx_enabled;
} }
static void mcf_fec_receive(void *opaque, const uint8_t *buf, size_t size) static void mcf_fec_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
mcf_fec_state *s = (mcf_fec_state *)opaque; mcf_fec_state *s = vc->opaque;
mcf_fec_bd bd; mcf_fec_bd bd;
uint32_t flags = 0; uint32_t flags = 0;
uint32_t addr; uint32_t addr;

View File

@ -66,23 +66,23 @@ static int mipsnet_buffer_full(MIPSnetState *s)
return 0; return 0;
} }
static int mipsnet_can_receive(void *opaque) static int mipsnet_can_receive(VLANClientState *vc)
{ {
MIPSnetState *s = opaque; MIPSnetState *s = vc->opaque;
if (s->busy) if (s->busy)
return 0; return 0;
return !mipsnet_buffer_full(s); return !mipsnet_buffer_full(s);
} }
static void mipsnet_receive(void *opaque, const uint8_t *buf, size_t size) static void mipsnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
MIPSnetState *s = opaque; MIPSnetState *s = vc->opaque;
#ifdef DEBUG_MIPSNET_RECEIVE #ifdef DEBUG_MIPSNET_RECEIVE
printf("mipsnet: receiving len=%d\n", size); printf("mipsnet: receiving len=%d\n", size);
#endif #endif
if (!mipsnet_can_receive(opaque)) if (!mipsnet_can_receive(vc))
return; return;
s->busy = 1; s->busy = 1;

View File

@ -557,14 +557,14 @@ static void eth_rx_desc_get(uint32_t addr, mv88w8618_rx_desc *desc)
le32_to_cpus(&desc->next); le32_to_cpus(&desc->next);
} }
static int eth_can_receive(void *opaque) static int eth_can_receive(VLANClientState *vc)
{ {
return 1; return 1;
} }
static void eth_receive(void *opaque, const uint8_t *buf, size_t size) static void eth_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
mv88w8618_eth_state *s = opaque; mv88w8618_eth_state *s = vc->opaque;
uint32_t desc_addr; uint32_t desc_addr;
mv88w8618_rx_desc desc; mv88w8618_rx_desc desc;
int i; int i;

View File

@ -213,9 +213,9 @@ static int ne2000_buffer_full(NE2000State *s)
return 0; return 0;
} }
static int ne2000_can_receive(void *opaque) static int ne2000_can_receive(VLANClientState *vc)
{ {
NE2000State *s = opaque; NE2000State *s = vc->opaque;
if (s->cmd & E8390_STOP) if (s->cmd & E8390_STOP)
return 1; return 1;
@ -224,9 +224,9 @@ static int ne2000_can_receive(void *opaque)
#define MIN_BUF_SIZE 60 #define MIN_BUF_SIZE 60
static void ne2000_receive(void *opaque, const uint8_t *buf, size_t size) static void ne2000_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
NE2000State *s = opaque; NE2000State *s = vc->opaque;
uint8_t *p; uint8_t *p;
unsigned int total_len, next, avail, len, index, mcast_idx; unsigned int total_len, next, avail, len, index, mcast_idx;
uint8_t buf1[60]; uint8_t buf1[60];

View File

@ -1062,9 +1062,9 @@ static int pcnet_tdte_poll(PCNetState *s)
return !!(CSR_CXST(s) & 0x8000); return !!(CSR_CXST(s) & 0x8000);
} }
static int pcnet_can_receive(void *opaque) static int pcnet_can_receive(VLANClientState *vc)
{ {
PCNetState *s = opaque; PCNetState *s = vc->opaque;
if (CSR_STOP(s) || CSR_SPND(s)) if (CSR_STOP(s) || CSR_SPND(s))
return 0; return 0;
@ -1076,9 +1076,9 @@ static int pcnet_can_receive(void *opaque)
#define MIN_BUF_SIZE 60 #define MIN_BUF_SIZE 60
static void pcnet_receive(void *opaque, const uint8_t *buf, size_t size) static void pcnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
PCNetState *s = opaque; PCNetState *s = vc->opaque;
int is_padr = 0, is_bcast = 0, is_ladr = 0; int is_padr = 0, is_bcast = 0, is_ladr = 0;
uint8_t buf1[60]; uint8_t buf1[60];
int remaining; int remaining;
@ -1302,7 +1302,7 @@ static void pcnet_transmit(PCNetState *s)
if (BCR_SWSTYLE(s) == 1) if (BCR_SWSTYLE(s) == 1)
add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS); add_crc = !GET_FIELD(tmd.status, TMDS, NOFCS);
s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC; s->looptest = add_crc ? PCNET_LOOPTEST_CRC : PCNET_LOOPTEST_NOCRC;
pcnet_receive(s, s->buffer, s->xmit_pos); pcnet_receive(s->vc, s->buffer, s->xmit_pos);
s->looptest = 0; s->looptest = 0;
} else } else
if (s->vc) if (s->vc)

View File

@ -790,9 +790,9 @@ static inline target_phys_addr_t rtl8139_addr64(uint32_t low, uint32_t high)
#endif #endif
} }
static int rtl8139_can_receive(void *opaque) static int rtl8139_can_receive(VLANClientState *vc)
{ {
RTL8139State *s = opaque; RTL8139State *s = vc->opaque;
int avail; int avail;
/* Receive (drop) packets if card is disabled. */ /* Receive (drop) packets if card is disabled. */
@ -812,9 +812,9 @@ static int rtl8139_can_receive(void *opaque)
} }
} }
static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int do_interrupt) static void rtl8139_do_receive(VLANClientState *vc, const uint8_t *buf, int size, int do_interrupt)
{ {
RTL8139State *s = opaque; RTL8139State *s = vc->opaque;
uint32_t packet_header = 0; uint32_t packet_header = 0;
@ -1158,9 +1158,9 @@ static void rtl8139_do_receive(void *opaque, const uint8_t *buf, int size, int d
} }
} }
static void rtl8139_receive(void *opaque, const uint8_t *buf, size_t size) static void rtl8139_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
rtl8139_do_receive(opaque, buf, size, 1); rtl8139_do_receive(vc, buf, size, 1);
} }
static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize) static void rtl8139_reset_rxring(RTL8139State *s, uint32_t bufferSize)
@ -1757,7 +1757,7 @@ static void rtl8139_transfer_frame(RTL8139State *s, const uint8_t *buf, int size
if (TxLoopBack == (s->TxConfig & TxLoopBack)) if (TxLoopBack == (s->TxConfig & TxLoopBack))
{ {
DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n")); DEBUG_PRINT(("RTL8139: +++ transmit loopback mode\n"));
rtl8139_do_receive(s, buf, size, do_interrupt); rtl8139_do_receive(s->vc, buf, size, do_interrupt);
} }
else else
{ {

View File

@ -591,9 +591,9 @@ static uint32_t smc91c111_readl(void *opaque, target_phys_addr_t offset)
return val; return val;
} }
static int smc91c111_can_receive(void *opaque) static int smc91c111_can_receive(VLANClientState *vc)
{ {
smc91c111_state *s = (smc91c111_state *)opaque; smc91c111_state *s = vc->opaque;
if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST)) if ((s->rcr & RCR_RXEN) == 0 || (s->rcr & RCR_SOFT_RST))
return 1; return 1;
@ -602,9 +602,9 @@ static int smc91c111_can_receive(void *opaque)
return 1; return 1;
} }
static void smc91c111_receive(void *opaque, const uint8_t *buf, size_t size) static void smc91c111_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
smc91c111_state *s = (smc91c111_state *)opaque; smc91c111_state *s = vc->opaque;
int status; int status;
int packetsize; int packetsize;
uint32_t crc; uint32_t crc;

View File

@ -78,9 +78,9 @@ static void stellaris_enet_update(stellaris_enet_state *s)
} }
/* TODO: Implement MAC address filtering. */ /* TODO: Implement MAC address filtering. */
static void stellaris_enet_receive(void *opaque, const uint8_t *buf, size_t size) static void stellaris_enet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
stellaris_enet_state *s = (stellaris_enet_state *)opaque; stellaris_enet_state *s = vc->opaque;
int n; int n;
uint8_t *p; uint8_t *p;
uint32_t crc; uint32_t crc;
@ -118,9 +118,9 @@ static void stellaris_enet_receive(void *opaque, const uint8_t *buf, size_t size
stellaris_enet_update(s); stellaris_enet_update(s);
} }
static int stellaris_enet_can_receive(void *opaque) static int stellaris_enet_can_receive(VLANClientState *vc)
{ {
stellaris_enet_state *s = (stellaris_enet_state *)opaque; stellaris_enet_state *s = vc->opaque;
if ((s->rctl & SE_RCTL_RXEN) == 0) if ((s->rctl & SE_RCTL_RXEN) == 0)
return 1; return 1;
@ -128,9 +128,9 @@ static int stellaris_enet_can_receive(void *opaque)
return (s->np < 31); return (s->np < 31);
} }
static uint32_t stellaris_enet_read(void *opaque, target_phys_addr_t offset) static uint32_t stellaris_enet_read(VLANClientState *vc, target_phys_addr_t offset)
{ {
stellaris_enet_state *s = (stellaris_enet_state *)opaque; stellaris_enet_state *s = vc->opaque;
uint32_t val; uint32_t val;
switch (offset) { switch (offset) {

View File

@ -1369,9 +1369,9 @@ static int usb_net_handle_data(USBDevice *dev, USBPacket *p)
return ret; return ret;
} }
static void usbnet_receive(void *opaque, const uint8_t *buf, size_t size) static void usbnet_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
USBNetState *s = opaque; USBNetState *s = vc->opaque;
struct rndis_packet_msg_type *msg; struct rndis_packet_msg_type *msg;
if (s->rndis) { if (s->rndis) {
@ -1405,9 +1405,9 @@ static void usbnet_receive(void *opaque, const uint8_t *buf, size_t size)
s->in_ptr = 0; s->in_ptr = 0;
} }
static int usbnet_can_receive(void *opaque) static int usbnet_can_receive(VLANClientState *vc)
{ {
USBNetState *s = opaque; USBNetState *s = vc->opaque;
if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED) if (s->rndis && !s->rndis_state == RNDIS_DATA_INITIALIZED)
return 1; return 1;

View File

@ -288,9 +288,9 @@ static int do_virtio_net_can_receive(VirtIONet *n, int bufsize)
return 1; return 1;
} }
static int virtio_net_can_receive(void *opaque) static int virtio_net_can_receive(VLANClientState *vc)
{ {
VirtIONet *n = opaque; VirtIONet *n = vc->opaque;
return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE); return do_virtio_net_can_receive(n, VIRTIO_NET_MAX_BUFSIZE);
} }
@ -361,9 +361,9 @@ static int receive_filter(VirtIONet *n, const uint8_t *buf, int size)
return 0; return 0;
} }
static void virtio_net_receive(void *opaque, const uint8_t *buf, size_t size) static void virtio_net_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
VirtIONet *n = opaque; VirtIONet *n = vc->opaque;
struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL; struct virtio_net_hdr_mrg_rxbuf *mhdr = NULL;
size_t hdr_len, offset, i; size_t hdr_len, offset, i;

View File

@ -223,9 +223,9 @@ static void net_rx_response(struct XenNetDev *netdev,
#define NET_IP_ALIGN 2 #define NET_IP_ALIGN 2
static int net_rx_ok(void *opaque) static int net_rx_ok(VLANClientState *vc)
{ {
struct XenNetDev *netdev = opaque; struct XenNetDev *netdev = vc->opaque;
RING_IDX rc, rp; RING_IDX rc, rp;
if (netdev->xendev.be_state != XenbusStateConnected) if (netdev->xendev.be_state != XenbusStateConnected)
@ -243,9 +243,9 @@ static int net_rx_ok(void *opaque)
return 1; return 1;
} }
static void net_rx_packet(void *opaque, const uint8_t *buf, size_t size) static void net_rx_packet(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
struct XenNetDev *netdev = opaque; struct XenNetDev *netdev = vc->opaque;
netif_rx_request_t rxreq; netif_rx_request_t rxreq;
RING_IDX rc, rp; RING_IDX rc, rp;
void *page; void *page;

36
net.c
View File

@ -402,7 +402,7 @@ int qemu_can_send_packet(VLANClientState *sender)
} }
/* no can_receive() handler, they can always receive */ /* no can_receive() handler, they can always receive */
if (!vc->can_receive || vc->can_receive(vc->opaque)) { if (!vc->can_receive || vc->can_receive(vc)) {
return 1; return 1;
} }
} }
@ -416,7 +416,7 @@ qemu_deliver_packet(VLANClientState *sender, const uint8_t *buf, int size)
for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) { for (vc = sender->vlan->first_client; vc != NULL; vc = vc->next) {
if (vc != sender && !vc->link_down) { if (vc != sender && !vc->link_down) {
vc->receive(vc->opaque, buf, size); vc->receive(vc, buf, size);
} }
} }
} }
@ -467,7 +467,7 @@ static ssize_t vc_sendv_compat(VLANClientState *vc, const struct iovec *iov,
offset += len; offset += len;
} }
vc->receive(vc->opaque, buffer, offset); vc->receive(vc, buffer, offset);
return offset; return offset;
} }
@ -520,7 +520,7 @@ ssize_t qemu_sendv_packet(VLANClientState *sender, const struct iovec *iov,
if (vc->link_down) { if (vc->link_down) {
len = calc_iov_length(iov, iovcnt); len = calc_iov_length(iov, iovcnt);
} else if (vc->receive_iov) { } else if (vc->receive_iov) {
len = vc->receive_iov(vc->opaque, iov, iovcnt); len = vc->receive_iov(vc, iov, iovcnt);
} else if (vc->receive) { } else if (vc->receive) {
len = vc_sendv_compat(vc, iov, iovcnt); len = vc_sendv_compat(vc, iov, iovcnt);
} }
@ -593,7 +593,7 @@ int slirp_is_inited(void)
return slirp_inited; return slirp_inited;
} }
static void slirp_receive(void *opaque, const uint8_t *buf, size_t size) static void slirp_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
#ifdef DEBUG_SLIRP #ifdef DEBUG_SLIRP
printf("slirp input:\n"); printf("slirp input:\n");
@ -932,10 +932,10 @@ typedef struct TAPState {
static int launch_script(const char *setup_script, const char *ifname, int fd); static int launch_script(const char *setup_script, const char *ifname, int fd);
static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov, static ssize_t tap_receive_iov(VLANClientState *vc, const struct iovec *iov,
int iovcnt) int iovcnt)
{ {
TAPState *s = opaque; TAPState *s = vc->opaque;
ssize_t len; ssize_t len;
do { do {
@ -945,9 +945,9 @@ static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov,
return len; return len;
} }
static void tap_receive(void *opaque, const uint8_t *buf, size_t size) static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
TAPState *s = opaque; TAPState *s = vc->opaque;
int ret; int ret;
for(;;) { for(;;) {
ret = write(s->fd, buf, size); ret = write(s->fd, buf, size);
@ -1311,9 +1311,9 @@ static void vde_to_qemu(void *opaque)
} }
} }
static void vde_from_qemu(void *opaque, const uint8_t *buf, int size) static void vde_receive(VLANClientState *vc, const uint8_t *buf, int size)
{ {
VDEState *s = opaque; VDEState *s = vc->opaque;
int ret; int ret;
for(;;) { for(;;) {
ret = vde_send(s->vde, (const char *)buf, size, 0); ret = vde_send(s->vde, (const char *)buf, size, 0);
@ -1352,7 +1352,7 @@ static int net_vde_init(VLANState *vlan, const char *model,
free(s); free(s);
return -1; return -1;
} }
s->vc = qemu_new_vlan_client(vlan, model, name, NULL, vde_from_qemu, s->vc = qemu_new_vlan_client(vlan, model, name, NULL, vde_receive,
NULL, vde_cleanup, s); NULL, vde_cleanup, s);
qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d", snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
@ -1380,9 +1380,9 @@ typedef struct NetSocketListenState {
} NetSocketListenState; } NetSocketListenState;
/* XXX: we consider we can send the whole packet without blocking */ /* XXX: we consider we can send the whole packet without blocking */
static void net_socket_receive(void *opaque, const uint8_t *buf, size_t size) static void net_socket_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
NetSocketState *s = opaque; NetSocketState *s = vc->opaque;
uint32_t len; uint32_t len;
len = htonl(size); len = htonl(size);
@ -1390,9 +1390,9 @@ static void net_socket_receive(void *opaque, const uint8_t *buf, size_t size)
send_all(s->fd, buf, size); send_all(s->fd, buf, size);
} }
static void net_socket_receive_dgram(void *opaque, const uint8_t *buf, size_t size) static void net_socket_receive_dgram(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
NetSocketState *s = opaque; NetSocketState *s = vc->opaque;
sendto(s->fd, buf, size, 0, sendto(s->fd, buf, size, 0,
(struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst)); (struct sockaddr *)&s->dgram_dst, sizeof(s->dgram_dst));
} }
@ -1831,9 +1831,9 @@ struct pcap_sf_pkthdr {
uint32_t len; uint32_t len;
}; };
static void dump_receive(void *opaque, const uint8_t *buf, size_t size) static void dump_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
DumpState *s = opaque; DumpState *s = vc->opaque;
struct pcap_sf_pkthdr hdr; struct pcap_sf_pkthdr hdr;
int64_t ts; int64_t ts;
int caplen; int caplen;

6
net.h
View File

@ -7,9 +7,9 @@
typedef struct VLANClientState VLANClientState; typedef struct VLANClientState VLANClientState;
typedef int (NetCanReceive)(void *); typedef int (NetCanReceive)(VLANClientState *);
typedef void (NetReceive)(void *, const uint8_t *, size_t); typedef void (NetReceive)(VLANClientState *, const uint8_t *, size_t);
typedef ssize_t (NetReceiveIOV)(void *, const struct iovec *, int); typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
typedef void (NetCleanup) (VLANClientState *); typedef void (NetCleanup) (VLANClientState *);
typedef void (LinkStatusChanged)(VLANClientState *); typedef void (LinkStatusChanged)(VLANClientState *);

View File

@ -131,7 +131,7 @@ static void qemu_announce_self_once(void *opaque)
len = announce_self_create(buf, nd_table[i].macaddr); len = announce_self_create(buf, nd_table[i].macaddr);
vlan = nd_table[i].vlan; vlan = nd_table[i].vlan;
for(vc = vlan->first_client; vc != NULL; vc = vc->next) { for(vc = vlan->first_client; vc != NULL; vc = vc->next) {
vc->receive(vc->opaque, buf, len); vc->receive(vc, buf, len);
} }
} }
if (count--) { if (count--) {

View File

@ -650,7 +650,7 @@ static void tap_cleanup(VLANClientState *vc)
qemu_free(s); qemu_free(s);
} }
static void tap_receive(void *opaque, const uint8_t *buf, size_t size) static void tap_receive(VLANClientState *vc, const uint8_t *buf, size_t size)
{ {
TAPState *s = opaque; TAPState *s = opaque;