[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [UNIKRAFT PATCH v3 14/16] plat/tap: Support tap_netdev_recv
Implement receive on the tap device. Signed-off-by: Sharan Santhanam <sharan.santhanam@xxxxxxxxx> --- plat/drivers/include/tap/tap.h | 1 + plat/drivers/tap/tap.c | 48 +++++++++++++++++++++++++++++++++- plat/linuxu/tap_io.c | 13 +++++++++ 3 files changed, 61 insertions(+), 1 deletion(-) diff --git a/plat/drivers/include/tap/tap.h b/plat/drivers/include/tap/tap.h index 42c6d7f1..f3e1b3eb 100644 --- a/plat/drivers/include/tap/tap.h +++ b/plat/drivers/include/tap/tap.h @@ -45,5 +45,6 @@ int tap_close(int fd); int tap_dev_configure(int fd, __u32 feature_flags, void *arg); int tap_netif_configure(int fd, __u32 request, void *arg); int tap_netif_create(void); +__ssz tap_read(int fd, void *buf, size_t count); #endif /* __PLAT_DRV_TAP_H */ diff --git a/plat/drivers/tap/tap.c b/plat/drivers/tap/tap.c index b7037b64..03948150 100644 --- a/plat/drivers/tap/tap.c +++ b/plat/drivers/tap/tap.c @@ -254,12 +254,58 @@ static int tap_netdev_recv(struct uk_netdev *dev, struct uk_netdev_rx_queue *queue, struct uk_netbuf **pkt) { - int rc = -EINVAL; + int rc = 0; + struct tap_net_dev *tdev __maybe_unused; + struct uk_netbuf *_pkt = NULL; UK_ASSERT(dev); UK_ASSERT(queue && pkt); + tdev = to_tapnetdev(dev); + + if (!queue->alloc_rxpkts) + return -EINVAL; + + + /** + * Allocate the packet in which the packet will be received. + */ + rc = queue->alloc_rxpkts(queue->alloc_rxpkts_argp, &_pkt, 1); + if (rc == 0) { + uk_pr_err(DRIVER_NAME": Failed to allocate the memory\n"); + rc = -ENOMEM; + _pkt = NULL; + rc = UK_NETDEV_STATUS_UNDERRUN | UK_NETDEV_STATUS_MORE; + return rc; + } + uk_pr_debug(DRIVER_NAME": Receiving on interface %s(%d) %p(%d)\n", + tdev->name, queue->fd, _pkt->data, _pkt->len); + rc = tap_read(queue->fd, _pkt->data, _pkt->len); + + if (rc > 0) { + uk_pr_debug(DRIVER_NAME": Recv pkt size: %d\n", rc); + /* Setting the length of the packet */ + _pkt->len = rc; + rc = UK_NETDEV_STATUS_SUCCESS | UK_NETDEV_STATUS_MORE; + } else if (rc == 0 || rc == -EWOULDBLOCK || rc == -EAGAIN) { + rc = 0; + goto err_exit; + } else { + uk_pr_err(DRIVER_NAME": Failed(%d) to read the packet\n", rc); + goto err_exit; + } + uk_pr_debug("uk_netdev buf ptr: %p\n", _pkt); + + *pkt = _pkt; + +exit: return rc; + +err_exit: + if (_pkt) + uk_netbuf_free(_pkt); + *pkt = NULL; + goto exit; } static int tap_netdev_xmit(struct uk_netdev *dev, diff --git a/plat/linuxu/tap_io.c b/plat/linuxu/tap_io.c index 8c44281c..1072c60f 100644 --- a/plat/linuxu/tap_io.c +++ b/plat/linuxu/tap_io.c @@ -109,6 +109,19 @@ int tap_netif_create(void) return sys_socket(AF_INET, SOCK_DGRAM, 0); } +ssize_t tap_read(int fd, void *buf, size_t count) +{ + ssize_t rc = -EINTR; + + while (rc == -EINTR) + rc = sys_read(fd, buf, count); + + if (rc < 0) + uk_pr_err("Failed(%ld) to read from the tap device\n", rc); + + return rc; +} + int tap_close(int fd) { return sys_close(fd); -- 2.20.1
|
Lists.xenproject.org is hosted with RackSpace, monitoring our |