static void net_rx_packet(void *opaque, const uint8_t *buf, size_t size)

{

    struct XenNetDev *netdev = opaque;

    netif_rx_request_t rxreq;

    RING_IDX rc, rp;

    void *page;



    if (netdev->xendev.be_state != XenbusStateConnected)

	return;



    rc = netdev->rx_ring.req_cons;

    rp = netdev->rx_ring.sring->req_prod;

    xen_rmb(); /* Ensure we see queued requests up to 'rp'. */



    if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) {

	xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n");

	return;

    }

    if (size > XC_PAGE_SIZE - NET_IP_ALIGN) {

	xen_be_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)",

		      (unsigned long)size, XC_PAGE_SIZE - NET_IP_ALIGN);

	return;

    }



    memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));

    netdev->rx_ring.req_cons = ++rc;



    page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,

				   netdev->xendev.dom,

				   rxreq.gref, PROT_WRITE);

    if (page == NULL) {

	xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n",

                      rxreq.gref);

	net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0);

	return;

    }

    memcpy(page + NET_IP_ALIGN, buf, size);

    xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);

    net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);

}

static void net_rx_packet(void *opaque, const uint8_t *buf, size_t size)

{

    struct XenNetDev *netdev = opaque;

    netif_rx_request_t rxreq;

    RING_IDX rc, rp;

    void *page;



    if (netdev->xendev.be_state != XenbusStateConnected)

	return;



    rc = netdev->rx_ring.req_cons;

    rp = netdev->rx_ring.sring->req_prod;

    xen_rmb(); 



    if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&netdev->rx_ring, rc)) {

	xen_be_printf(&netdev->xendev, 2, "no buffer, drop packet\n");

	return;

    }

    if (size > XC_PAGE_SIZE - NET_IP_ALIGN) {

	xen_be_printf(&netdev->xendev, 0, "packet too big (%lu > %ld)",

		      (unsigned long)size, XC_PAGE_SIZE - NET_IP_ALIGN);

	return;

    }



    memcpy(&rxreq, RING_GET_REQUEST(&netdev->rx_ring, rc), sizeof(rxreq));

    netdev->rx_ring.req_cons = ++rc;



    page = xc_gnttab_map_grant_ref(netdev->xendev.gnttabdev,

				   netdev->xendev.dom,

				   rxreq.gref, PROT_WRITE);

    if (page == NULL) {

	xen_be_printf(&netdev->xendev, 0, "error: rx gref dereference failed (%d)\n",

                      rxreq.gref);

	net_rx_response(netdev, &rxreq, NETIF_RSP_ERROR, 0, 0, 0);

	return;

    }

    memcpy(page + NET_IP_ALIGN, buf, size);

    xc_gnttab_munmap(netdev->xendev.gnttabdev, page, 1);

    net_rx_response(netdev, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, size, 0);

}

static void FUNC_0(void *VAR_0, const uint8_t *VAR_1, size_t VAR_2)

{

    struct XenNetDev *VAR_3 = VAR_0;

    netif_rx_request_t rxreq;

    RING_IDX rc, rp;

    void *VAR_4;



    if (VAR_3->xendev.be_state != XenbusStateConnected)

	return;



    rc = VAR_3->rx_ring.req_cons;

    rp = VAR_3->rx_ring.sring->req_prod;

    xen_rmb(); 



    if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&VAR_3->rx_ring, rc)) {

	xen_be_printf(&VAR_3->xendev, 2, "no buffer, drop packet\n");

	return;

    }

    if (VAR_2 > XC_PAGE_SIZE - NET_IP_ALIGN) {

	xen_be_printf(&VAR_3->xendev, 0, "packet too big (%lu > %ld)",

		      (unsigned long)VAR_2, XC_PAGE_SIZE - NET_IP_ALIGN);

	return;

    }



    memcpy(&rxreq, RING_GET_REQUEST(&VAR_3->rx_ring, rc), sizeof(rxreq));

    VAR_3->rx_ring.req_cons = ++rc;



    VAR_4 = xc_gnttab_map_grant_ref(VAR_3->xendev.gnttabdev,

				   VAR_3->xendev.dom,

				   rxreq.gref, PROT_WRITE);

    if (VAR_4 == NULL) {

	xen_be_printf(&VAR_3->xendev, 0, "error: rx gref dereference failed (%d)\n",

                      rxreq.gref);

	net_rx_response(VAR_3, &rxreq, NETIF_RSP_ERROR, 0, 0, 0);

	return;

    }

    memcpy(VAR_4 + NET_IP_ALIGN, VAR_1, VAR_2);

    xc_gnttab_munmap(VAR_3->xendev.gnttabdev, VAR_4, 1);

    net_rx_response(VAR_3, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, VAR_2, 0);

}

static void FUNC_0(void *VAR_0, const uint8_t *VAR_1, size_t VAR_2)
{ struct XenNetDev *VAR_3 = VAR_0; netif_rx_request_t rxreq; RING_IDX rc, rp; void *VAR_4; if (VAR_3->xendev.be_state != XenbusStateConnected)
return; rc = VAR_3->rx_ring.req_cons; rp = VAR_3->rx_ring.sring->req_prod; xen_rmb(); if (rc == rp || RING_REQUEST_CONS_OVERFLOW(&VAR_3->rx_ring, rc)) { xen_be_printf(&VAR_3->xendev, 2, "no buffer, drop packet\n"); return; } if (VAR_2 > XC_PAGE_SIZE - NET_IP_ALIGN) { xen_be_printf(&VAR_3->xendev, 0, "packet too big (%lu > %ld)",
(unsigned long)VAR_2, XC_PAGE_SIZE - NET_IP_ALIGN); return; } memcpy(&rxreq, RING_GET_REQUEST(&VAR_3->rx_ring, rc), sizeof(rxreq)); VAR_3->rx_ring.req_cons = ++rc; VAR_4 = xc_gnttab_map_grant_ref(VAR_3->xendev.gnttabdev,
VAR_3->xendev.dom,
rxreq.gref, PROT_WRITE); if (VAR_4 == NULL) { xen_be_printf(&VAR_3->xendev, 0, "error: rx gref dereference failed (%d)\n",
rxreq.gref); net_rx_response(VAR_3, &rxreq, NETIF_RSP_ERROR, 0, 0, 0); return; } memcpy(VAR_4 + NET_IP_ALIGN, VAR_1, VAR_2); xc_gnttab_munmap(VAR_3->xendev.gnttabdev, VAR_4, 1); net_rx_response(VAR_3, &rxreq, NETIF_RSP_OKAY, NET_IP_ALIGN, VAR_2, 0); }