tap: Rename tap_iov_{base,len}

These two functions are typically used to calculate values to go into the
iov_base and iov_len fields of a struct iovec.  They don't have to be used
for that, though.  Rename them in terms of what they actually do: calculate
the base address and total length of the complete frame, including both L2
and tap specific headers.

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 2024-03-08 17:53:25 +11:00 committed by Stefano Brivio
parent 4db947d17c
commit d3eb0d7b59
3 changed files with 17 additions and 17 deletions

12
tap.h
View file

@ -27,29 +27,29 @@ static inline size_t tap_hdr_len_(const struct ctx *c)
} }
/** /**
* tap_iov_base() - Find start of tap frame * tap_frame_base() - Find start of tap frame
* @c: Execution context * @c: Execution context
* @taph: Pointer to L2 header buffer * @taph: Pointer to L2 and tap specific header buffer
* *
* Returns: pointer to the start of tap frame - suitable for an * Returns: pointer to the start of tap frame - suitable for an
* iov_base to be passed to tap_send_frames()) * iov_base to be passed to tap_send_frames())
*/ */
static inline void *tap_iov_base(const struct ctx *c, struct tap_hdr *taph) static inline void *tap_frame_base(const struct ctx *c, struct tap_hdr *taph)
{ {
return (char *)(taph + 1) - tap_hdr_len_(c); return (char *)(taph + 1) - tap_hdr_len_(c);
} }
/** /**
* tap_iov_len() - Finalize tap frame and return total length * tap_frame_len() - Finalize tap frame and return total length
* @c: Execution context * @c: Execution context
* @taph: Tap header to finalize * @taph: Tap header to finalize
* @plen: L2 payload length (excludes L2 and tap specific headers) * @plen: L3 packet length (excludes L2 and tap specific headers)
* *
* Returns: length of the tap frame including L2 and tap specific * Returns: length of the tap frame including L2 and tap specific
* headers - suitable for an iov_len to be passed to * headers - suitable for an iov_len to be passed to
* tap_send_frames() * tap_send_frames()
*/ */
static inline size_t tap_iov_len(const struct ctx *c, struct tap_hdr *taph, static inline size_t tap_frame_len(const struct ctx *c, struct tap_hdr *taph,
size_t plen) size_t plen)
{ {
if (c->mode == MODE_PASST) if (c->mode == MODE_PASST)

12
tcp.c
View file

@ -1014,10 +1014,10 @@ static void tcp_sock4_iov_init(const struct ctx *c)
} }
for (i = 0, iov = tcp4_l2_iov; i < TCP_FRAMES_MEM; i++, iov++) for (i = 0, iov = tcp4_l2_iov; i < TCP_FRAMES_MEM; i++, iov++)
iov->iov_base = tap_iov_base(c, &tcp4_l2_buf[i].taph); iov->iov_base = tap_frame_base(c, &tcp4_l2_buf[i].taph);
for (i = 0, iov = tcp4_l2_flags_iov; i < TCP_FRAMES_MEM; i++, iov++) for (i = 0, iov = tcp4_l2_flags_iov; i < TCP_FRAMES_MEM; i++, iov++)
iov->iov_base = tap_iov_base(c, &tcp4_l2_flags_buf[i].taph); iov->iov_base = tap_frame_base(c, &tcp4_l2_flags_buf[i].taph);
} }
/** /**
@ -1045,10 +1045,10 @@ static void tcp_sock6_iov_init(const struct ctx *c)
} }
for (i = 0, iov = tcp6_l2_iov; i < TCP_FRAMES_MEM; i++, iov++) for (i = 0, iov = tcp6_l2_iov; i < TCP_FRAMES_MEM; i++, iov++)
iov->iov_base = tap_iov_base(c, &tcp6_l2_buf[i].taph); iov->iov_base = tap_frame_base(c, &tcp6_l2_buf[i].taph);
for (i = 0, iov = tcp6_l2_flags_iov; i < TCP_FRAMES_MEM; i++, iov++) for (i = 0, iov = tcp6_l2_flags_iov; i < TCP_FRAMES_MEM; i++, iov++)
iov->iov_base = tap_iov_base(c, &tcp6_l2_flags_buf[i].taph); iov->iov_base = tap_frame_base(c, &tcp6_l2_flags_buf[i].taph);
} }
/** /**
@ -1454,14 +1454,14 @@ static size_t tcp_l2_buf_fill_headers(const struct ctx *c,
ip_len = tcp_fill_headers4(c, conn, &b->iph, &b->th, plen, ip_len = tcp_fill_headers4(c, conn, &b->iph, &b->th, plen,
check, seq); check, seq);
tlen = tap_iov_len(c, &b->taph, ip_len); tlen = tap_frame_len(c, &b->taph, ip_len);
} else { } else {
struct tcp6_l2_buf_t *b = (struct tcp6_l2_buf_t *)p; struct tcp6_l2_buf_t *b = (struct tcp6_l2_buf_t *)p;
ip_len = tcp_fill_headers6(c, conn, &b->ip6h, &b->th, plen, ip_len = tcp_fill_headers6(c, conn, &b->ip6h, &b->th, plen,
seq); seq);
tlen = tap_iov_len(c, &b->taph, ip_len); tlen = tap_frame_len(c, &b->taph, ip_len);
} }
return tlen; return tlen;

8
udp.c
View file

@ -318,7 +318,7 @@ static void udp_sock4_iov_init_one(const struct ctx *c, size_t i)
mh->msg_iov = siov; mh->msg_iov = siov;
mh->msg_iovlen = 1; mh->msg_iovlen = 1;
tiov->iov_base = tap_iov_base(c, &buf->taph); tiov->iov_base = tap_frame_base(c, &buf->taph);
} }
/** /**
@ -346,7 +346,7 @@ static void udp_sock6_iov_init_one(const struct ctx *c, size_t i)
mh->msg_iov = siov; mh->msg_iov = siov;
mh->msg_iovlen = 1; mh->msg_iovlen = 1;
tiov->iov_base = tap_iov_base(c, &buf->taph); tiov->iov_base = tap_frame_base(c, &buf->taph);
} }
/** /**
@ -606,7 +606,7 @@ static size_t udp_update_hdr4(const struct ctx *c, struct udp4_l2_buf_t *b,
b->uh.dest = htons(dstport); b->uh.dest = htons(dstport);
b->uh.len = htons(datalen + sizeof(b->uh)); b->uh.len = htons(datalen + sizeof(b->uh));
return tap_iov_len(c, &b->taph, ip_len); return tap_frame_len(c, &b->taph, ip_len);
} }
/** /**
@ -673,7 +673,7 @@ static size_t udp_update_hdr6(const struct ctx *c, struct udp6_l2_buf_t *b,
b->uh.len = b->ip6h.payload_len; b->uh.len = b->ip6h.payload_len;
csum_udp6(&b->uh, src, dst, b->data, datalen); csum_udp6(&b->uh, src, dst, b->data, datalen);
return tap_iov_len(c, &b->taph, payload_len + sizeof(b->ip6h)); return tap_frame_len(c, &b->taph, payload_len + sizeof(b->ip6h));
} }
/** /**