diff options
author | Simon Horman <horms@verge.net.au> | 2014-01-15 17:17:00 +0900 |
---|---|---|
committer | Ben Pfaff <blp@nicira.com> | 2014-01-16 14:37:43 -0800 |
commit | bfd3367b9e7426ffc931c9b0d010d8b1b5884ec2 (patch) | |
tree | 8585bda3f250bd05473632be532d6d8a3c3e6bbe /lib/netdev-bsd.c | |
parent | 6a62a162efeabe7ad54a82e34fe940f973792443 (diff) | |
download | openvswitch-bfd3367b9e7426ffc931c9b0d010d8b1b5884ec2.tar.gz |
netdev_class: Pass a struct ofpbuf * to rx_recv()
Update the netdev_class so that struct ofpbuf * is passed to rx_recv()
to provide both the data and size of the data to read a packet into.
On success, update struct ofpbuf size inside netdev_class rx_recv
implementation and return 0. This moves logic from the caller.
On error a positive error code is returned, whereas previously
a negative error code was returned. This is a more common convention.
This patch should not have any behavioural changes.
This patch is in preparation for the netdev-linux variant of rx_recv()
making use of headroom in the struct ofpbuf * parameter to push a VLAN tag
obtained from auxdata.
Signed-off-by: Simon Horman <horms@verge.net.au>
Co-authored-by: Ben Pfaff <blp@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
Diffstat (limited to 'lib/netdev-bsd.c')
-rw-r--r-- | lib/netdev-bsd.c | 28 |
1 files changed, 16 insertions, 12 deletions
diff --git a/lib/netdev-bsd.c b/lib/netdev-bsd.c index 4a16e5cf3..689014b90 100644 --- a/lib/netdev-bsd.c +++ b/lib/netdev-bsd.c @@ -568,20 +568,21 @@ proc_pkt(u_char *args_, const struct pcap_pkthdr *hdr, const u_char *packet) * from rx->pcap. */ static int -netdev_rx_bsd_recv_pcap(struct netdev_rx_bsd *rx, void *data, size_t size) +netdev_rx_bsd_recv_pcap(struct netdev_rx_bsd *rx, struct ofpbuf *buffer) { struct pcap_arg arg; int ret; /* prepare the pcap argument to store the packet */ - arg.size = size; - arg.data = data; + arg.size = ofpbuf_tailroom(buffer); + arg.data = buffer->data; for (;;) { ret = pcap_dispatch(rx->pcap_handle, 1, proc_pkt, (u_char *) &arg); if (ret > 0) { - return arg.retval; /* arg.retval < 0 is handled in the caller */ + buffer->size += arg.retval; + return 0; } if (ret == -1) { if (errno == EINTR) { @@ -589,7 +590,7 @@ netdev_rx_bsd_recv_pcap(struct netdev_rx_bsd *rx, void *data, size_t size) } } - return -EAGAIN; + return EAGAIN; } } @@ -599,30 +600,33 @@ netdev_rx_bsd_recv_pcap(struct netdev_rx_bsd *rx, void *data, size_t size) * 'rx->fd' is initialized with the tap file descriptor. */ static int -netdev_rx_bsd_recv_tap(struct netdev_rx_bsd *rx, void *data, size_t size) +netdev_rx_bsd_recv_tap(struct netdev_rx_bsd *rx, struct ofpbuf *buffer) { + size_t size = ofpbuf_tailroom(buffer); + for (;;) { - ssize_t retval = read(rx->fd, data, size); + ssize_t retval = read(rx->fd, buffer->data, size); if (retval >= 0) { - return retval; + buffer->size += retval; + return 0; } else if (errno != EINTR) { if (errno != EAGAIN) { VLOG_WARN_RL(&rl, "error receiving Ethernet packet on %s: %s", ovs_strerror(errno), netdev_rx_get_name(&rx->up)); } - return -errno; + return errno; } } } static int -netdev_bsd_rx_recv(struct netdev_rx *rx_, void *data, size_t size) +netdev_bsd_rx_recv(struct netdev_rx *rx_, struct ofpbuf *buffer) { struct netdev_rx_bsd *rx = netdev_rx_bsd_cast(rx_); return (rx->pcap_handle - ? netdev_rx_bsd_recv_pcap(rx, data, size) - : netdev_rx_bsd_recv_tap(rx, data, size)); + ? netdev_rx_bsd_recv_pcap(rx, buffer) + : netdev_rx_bsd_recv_tap(rx, buffer)); } /* |