aboutgitcodebugslistschat
path: root/tap.c
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2023-11-08 14:17:54 +1100
committerStefano Brivio <sbrivio@redhat.com>2023-11-10 16:51:33 +0100
commit5ec3634b07215337c2e69d88f9b1d74711897d7d (patch)
treec4c1868e0d35ee381922469cd1490f099ed6f9fe /tap.c
parentf0776eac07cfae76a51b5f55d5f95c8a5c62640f (diff)
downloadpasst-5ec3634b07215337c2e69d88f9b1d74711897d7d.tar
passt-5ec3634b07215337c2e69d88f9b1d74711897d7d.tar.gz
passt-5ec3634b07215337c2e69d88f9b1d74711897d7d.tar.bz2
passt-5ec3634b07215337c2e69d88f9b1d74711897d7d.tar.lz
passt-5ec3634b07215337c2e69d88f9b1d74711897d7d.tar.xz
passt-5ec3634b07215337c2e69d88f9b1d74711897d7d.tar.zst
passt-5ec3634b07215337c2e69d88f9b1d74711897d7d.zip
tap, pasta: Handle short writes to /dev/tap2023_11_10.5ec3634
tap_send_frames_pasta() sends frames to the namespace by sending them to our the /dev/tap device. If that write() returns an error, we already handle it. However we don't handle the case where the write() returns short, meaning we haven't successfully transmitted the whole frame. I don't know if this can ever happen with the kernel tap device, but we should at least report the case so we don't get a cryptic failure. For the purposes of the return value for tap_send_frames_pasta() we treat this case as though it was an error (on the grounds that a partial frame is no use to the namespace). Signed-off-by: David Gibson <david@gibson.dropbear.id.au>
Diffstat (limited to 'tap.c')
-rw-r--r--tap.c8
1 files changed, 7 insertions, 1 deletions
diff --git a/tap.c b/tap.c
index 00622e7..4f11000 100644
--- a/tap.c
+++ b/tap.c
@@ -321,7 +321,9 @@ static size_t tap_send_frames_pasta(const struct ctx *c,
size_t i;
for (i = 0; i < n; i++) {
- if (write(c->fd_tap, iov[i].iov_base, iov[i].iov_len) < 0) {
+ ssize_t rc = write(c->fd_tap, iov[i].iov_base, iov[i].iov_len);
+
+ if (rc < 0) {
debug("tap write: %s", strerror(errno));
switch (errno) {
@@ -336,6 +338,10 @@ static size_t tap_send_frames_pasta(const struct ctx *c,
default:
die("Write error on tap device, exiting");
}
+ } else if ((size_t)rc < iov[i].iov_len) {
+ debug("short write on tuntap: %zd/%zu",
+ rc, iov[i].iov_len);
+ break;
}
}