aboutgitcodebugslistschat
path: root/tap.h
diff options
context:
space:
mode:
authorDavid Gibson <david@gibson.dropbear.id.au>2024-05-01 16:53:51 +1000
committerStefano Brivio <sbrivio@redhat.com>2024-05-02 16:13:29 +0200
commit40f8b2976ab09c77b14238d6eabaa7793d5365e4 (patch)
tree8e9c4ea72be30c6727da572759e377ea9c494b1f /tap.h
parent68d1b0a1528d6efd0d94afa43e9fc4b4857ca694 (diff)
downloadpasst-40f8b2976ab09c77b14238d6eabaa7793d5365e4.tar
passt-40f8b2976ab09c77b14238d6eabaa7793d5365e4.tar.gz
passt-40f8b2976ab09c77b14238d6eabaa7793d5365e4.tar.bz2
passt-40f8b2976ab09c77b14238d6eabaa7793d5365e4.tar.lz
passt-40f8b2976ab09c77b14238d6eabaa7793d5365e4.tar.xz
passt-40f8b2976ab09c77b14238d6eabaa7793d5365e4.tar.zst
passt-40f8b2976ab09c77b14238d6eabaa7793d5365e4.zip
tap, tcp: (Re-)abstract TAP specific header handling
Recent changes to the TCP code (reworking of the buffer handling) have meant that it now (again) deals explicitly with the MODE_PASST specific vnet_len field, instead of using the (partial) abstractions provided by the tap layer. The abstractions we had don't work for the new TCP structure, so make some new ones that do: tap_hdr_iov() which constructs an iovec suitable for containing (just) the TAP specific header and tap_hdr_update() which updates it as necessary per-packet. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'tap.h')
-rw-r--r--tap.h27
1 files changed, 27 insertions, 0 deletions
diff --git a/tap.h b/tap.h
index 7c2e391..9216d5a 100644
--- a/tap.h
+++ b/tap.h
@@ -16,6 +16,33 @@ struct tap_hdr {
uint32_t vnet_len;
} __attribute__((packed));
+/**
+ * tap_hdr_iov() - struct iovec for a tap header
+ * @c: Execution context
+ * @taph: Pointer to tap specific header buffer
+ *
+ * Returns: A struct iovec covering the correct portion of @taph to use as the
+ * tap specific header in the current configuration.
+ */
+static inline struct iovec tap_hdr_iov(const struct ctx *c,
+ struct tap_hdr *thdr)
+{
+ return (struct iovec){
+ .iov_base = thdr,
+ .iov_len = c->mode == MODE_PASST ? sizeof(*thdr) : 0,
+ };
+}
+
+/**
+ * tap_hdr_update() - Update the tap specific header for a frame
+ * @taph: Tap specific header buffer to update
+ * @l2len: Frame length (including L2 headers)
+ */
+static inline void tap_hdr_update(struct tap_hdr *thdr, size_t l2len)
+{
+ thdr->vnet_len = htonl(l2len);
+}
+
static inline size_t tap_hdr_len_(const struct ctx *c)
{
if (c->mode == MODE_PASST)