1
0
mirror of https://passt.top/passt synced 2024-07-04 17:02:40 +00:00

tcp: Combine two parts of pasta tap send path together

tcp_l2_buf_flush() open codes the loop across each frame in a group, but
but calls tcp_l2_buf_write_one() to send each frame to the pasta tuntap
device.  Combine these two pasta-specific operations into
tcp_l2_buf_flush_pasta() which is a little cleaner and will enable further
cleanups.

Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
David Gibson 2023-01-06 11:43:10 +11:00 committed by Stefano Brivio
parent a79e774770
commit e21ee41ac3

34
tcp.c
View File

@ -1395,23 +1395,25 @@ static void tcp_rst_do(struct ctx *c, struct tcp_tap_conn *conn);
} while (0) } while (0)
/** /**
* tcp_l2_buf_write_one() - Write a single buffer to tap file descriptor * tcp_l2_buf_flush_pasta() - Send frames on the pasta tap interface
* @c: Execution context * @c: Execution context
* @iov: struct iovec item pointing to buffer * @iov: Pointer to array of buffers, one per frame
* @ts: Current timestamp * @n: Number of buffers/frames to flush
*
* Return: 0 on success, negative error code on failure (tap reset possible)
*/ */
static int tcp_l2_buf_write_one(struct ctx *c, const struct iovec *iov) static void tcp_l2_buf_flush_pasta(struct ctx *c,
const struct iovec *iov, size_t n)
{ {
if (write(c->fd_tap, (char *)iov->iov_base + 4, iov->iov_len - 4) < 0) { size_t i;
for (i = 0; i < n; i++) {
if (write(c->fd_tap, (char *)iov->iov_base + 4,
iov->iov_len - 4) < 0) {
debug("tap write: %s", strerror(errno)); debug("tap write: %s", strerror(errno));
if (errno != EAGAIN && errno != EWOULDBLOCK) if (errno != EAGAIN && errno != EWOULDBLOCK)
tap_handler(c, c->fd_tap, EPOLLERR, NULL); tap_handler(c, c->fd_tap, EPOLLERR, NULL);
return -errno; i--;
}
} }
return 0;
} }
/** /**
@ -1458,19 +1460,13 @@ static void tcp_l2_buf_flush_passt(const struct ctx *c,
*/ */
static void tcp_l2_buf_flush(struct ctx *c, const struct iovec *iov, size_t n) static void tcp_l2_buf_flush(struct ctx *c, const struct iovec *iov, size_t n)
{ {
size_t i;
if (!n) if (!n)
return; return;
if (c->mode == MODE_PASST) { if (c->mode == MODE_PASST)
tcp_l2_buf_flush_passt(c, iov, n); tcp_l2_buf_flush_passt(c, iov, n);
} else { else
for (i = 0; i < n; i++) { tcp_l2_buf_flush_pasta(c, iov, n);
if (tcp_l2_buf_write_one(c, iov + i))
i--;
}
}
pcap_multiple(iov, n, sizeof(uint32_t)); pcap_multiple(iov, n, sizeof(uint32_t));
} }