aboutgitcodebugslistschat
path: root/tcp.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-01-06 11:43:07 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-01-23 18:54:30 +0100
commit99f0be3cad2292c61c79cef1afeb5cc2ba8507c2 (patch)
tree11be271019cbc3c565775e16cb09e74770f32132 /tcp.c
parentd3089eb0eab412e34bd91f7853e3e72429912edb (diff)
downloadpasst-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.tar
passt-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.tar.gz
passt-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.tar.bz2
passt-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.tar.lz
passt-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.tar.xz
passt-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.tar.zst
passt-99f0be3cad2292c61c79cef1afeb5cc2ba8507c2.zip
tcp: Combine two parts of passt tap send path together
tcp_l2_buf_flush() open codes the "primary" send of message to the passt tap interface, but calls tcp_l2_buf_flush_part() to handle the case of a short send. Combine these two passt-specific operations into tcp_l2_buf_flush_passt() which is a little cleaner and will enable furrther cleanups. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tcp.c')
-rw-r--r--tcp.c20
1 files changed, 12 insertions, 8 deletions
diff --git a/tcp.c b/tcp.c
index 95db256..43f6427 100644
--- a/tcp.c
+++ b/tcp.c
@@ -1419,19 +1419,25 @@ static int tcp_l2_buf_write_one(struct ctx *c, const struct iovec *iov)
}
/**
- * tcp_l2_buf_flush_part() - Ensure a complete last message on partial sendmsg()
+ * tcp_l2_buf_flush_passt() - Send a message on the passt tap interface
* @c: Execution context
* @mh: Message header that was partially sent by sendmsg()
- * @sent: Bytes already sent
+ * @buf_bytes: Total number of bytes to send
*/
-static void tcp_l2_buf_flush_part(const struct ctx *c,
- const struct msghdr *mh, size_t sent)
+static void tcp_l2_buf_flush_passt(const struct ctx *c,
+ const struct msghdr *mh, size_t buf_bytes)
{
- size_t end = 0, missing;
+ size_t end = 0, missing, sent;
struct iovec *iov;
unsigned int i;
+ ssize_t n;
char *p;
+ n = sendmsg(c->fd_tap, mh, MSG_NOSIGNAL | MSG_DONTWAIT);
+ if (n < 0 || ((sent = (size_t)n) == buf_bytes))
+ return;
+
+ /* Ensure a complete last message on partial sendmsg() */
for (i = 0, iov = mh->msg_iov; i < mh->msg_iovlen; i++, iov++) {
end += iov->iov_len;
if (end >= sent)
@@ -1458,9 +1464,7 @@ static void tcp_l2_buf_flush(struct ctx *c, struct msghdr *mh,
return;
if (c->mode == MODE_PASST) {
- size_t n = sendmsg(c->fd_tap, mh, MSG_NOSIGNAL | MSG_DONTWAIT);
- if (n > 0 && n < *buf_bytes)
- tcp_l2_buf_flush_part(c, mh, n);
+ tcp_l2_buf_flush_passt(c, mh, *buf_bytes);
} else {
size_t i;