aboutgitcodebugslistschat
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-01-06 11:43:10 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-01-23 18:54:39 +0100
commite21ee41ac35a268009ad616df8e9d15d99825050 (patch)
tree668a47759821a8417b009a2c40be5262ca20e4af
parenta79e77477095486b782374255b081e703a4102a9 (diff)
downloadpasst-e21ee41ac35a268009ad616df8e9d15d99825050.tar
passt-e21ee41ac35a268009ad616df8e9d15d99825050.tar.gz
passt-e21ee41ac35a268009ad616df8e9d15d99825050.tar.bz2
passt-e21ee41ac35a268009ad616df8e9d15d99825050.tar.lz
passt-e21ee41ac35a268009ad616df8e9d15d99825050.tar.xz
passt-e21ee41ac35a268009ad616df8e9d15d99825050.tar.zst
passt-e21ee41ac35a268009ad616df8e9d15d99825050.zip
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>
-rw-r--r--tcp.c40
1 files changed, 18 insertions, 22 deletions
diff --git a/tcp.c b/tcp.c
index b964018..dc74275 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1395,23 +1395,25 @@ static void tcp_rst_do(struct ctx *c, struct tcp_tap_conn *conn);
} 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
- * @iov: struct iovec item pointing to buffer
- * @ts: Current timestamp
- *
- * Return: 0 on success, negative error code on failure (tap reset possible)
+ * @iov: Pointer to array of buffers, one per frame
+ * @n: Number of buffers/frames to flush
*/
-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) {
- debug("tap write: %s", strerror(errno));
- if (errno != EAGAIN && errno != EWOULDBLOCK)
- tap_handler(c, c->fd_tap, EPOLLERR, NULL);
- return -errno;
- }
+ size_t i;
- return 0;
+ 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));
+ if (errno != EAGAIN && errno != EWOULDBLOCK)
+ tap_handler(c, c->fd_tap, EPOLLERR, NULL);
+ i--;
+ }
+ }
}
/**
@@ -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)
{
- size_t i;
-
if (!n)
return;
- if (c->mode == MODE_PASST) {
+ if (c->mode == MODE_PASST)
tcp_l2_buf_flush_passt(c, iov, n);
- } else {
- for (i = 0; i < n; i++) {
- if (tcp_l2_buf_write_one(c, iov + i))
- i--;
- }
- }
+ else
+ tcp_l2_buf_flush_pasta(c, iov, n);
pcap_multiple(iov, n, sizeof(uint32_t));
}