mirror of
https://passt.top/passt
synced 2025-10-09 00:59:13 +02:00
tcp: Pass TCP header and payload separately to tcp_fill_headers[46]()
At the moment these take separate pointers to the tap specific and IP headers, but expect the TCP header and payload as a single tcp_payload_t. As well as being slightly inconsistent, this involves some slightly iffy pointer shenanigans when called on the flags path with a tcp_flags_t instead of a tcp_payload_t. More importantly, it's inconvenient for the upcoming vhost-user case, where the TCP header and payload might not be contiguous. Furthermore, the payload itself might not be contiguous. So, pass the TCP header as its own pointer, and the TCP payload as an IO vector. Signed-off-by: David Gibson <david@gibson.dropbear.id.au> Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
This commit is contained in:
parent
2ee07697c4
commit
08ea3cc581
5 changed files with 65 additions and 75 deletions
22
tcp_buf.c
22
tcp_buf.c
|
@ -151,29 +151,27 @@ void tcp_payload_flush(const struct ctx *c)
|
|||
* tcp_buf_fill_headers() - Fill 802.3, IP, TCP headers in pre-cooked buffers
|
||||
* @conn: Connection pointer
|
||||
* @iov: Pointer to an array of iovec of TCP pre-cooked buffers
|
||||
* @dlen: TCP payload length
|
||||
* @check: Checksum, if already known
|
||||
* @seq: Sequence number for this segment
|
||||
* @no_tcp_csum: Do not set TCP checksum
|
||||
*/
|
||||
static void tcp_l2_buf_fill_headers(const struct tcp_tap_conn *conn,
|
||||
struct iovec *iov, size_t dlen,
|
||||
const uint16_t *check, uint32_t seq,
|
||||
bool no_tcp_csum)
|
||||
struct iovec *iov, const uint16_t *check,
|
||||
uint32_t seq, bool no_tcp_csum)
|
||||
{
|
||||
struct iov_tail tail = IOV_TAIL(&iov[TCP_IOV_PAYLOAD], 1, 0);
|
||||
struct tcphdr *th = IOV_REMOVE_HEADER(&tail, struct tcphdr);
|
||||
const struct flowside *tapside = TAPFLOW(conn);
|
||||
const struct in_addr *a4 = inany_v4(&tapside->oaddr);
|
||||
|
||||
if (a4) {
|
||||
tcp_fill_headers4(conn, iov[TCP_IOV_TAP].iov_base,
|
||||
iov[TCP_IOV_IP].iov_base,
|
||||
iov[TCP_IOV_PAYLOAD].iov_base, dlen,
|
||||
check, seq, no_tcp_csum);
|
||||
iov[TCP_IOV_IP].iov_base, th,
|
||||
&tail, check, seq, no_tcp_csum);
|
||||
} else {
|
||||
tcp_fill_headers6(conn, iov[TCP_IOV_TAP].iov_base,
|
||||
iov[TCP_IOV_IP].iov_base,
|
||||
iov[TCP_IOV_PAYLOAD].iov_base, dlen,
|
||||
seq, no_tcp_csum);
|
||||
iov[TCP_IOV_IP].iov_base, th,
|
||||
&tail, seq, no_tcp_csum);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -213,7 +211,7 @@ int tcp_buf_send_flag(const struct ctx *c, struct tcp_tap_conn *conn, int flags)
|
|||
tcp_payload_used++;
|
||||
l4len = optlen + sizeof(struct tcphdr);
|
||||
iov[TCP_IOV_PAYLOAD].iov_len = l4len;
|
||||
tcp_l2_buf_fill_headers(conn, iov, optlen, NULL, seq, false);
|
||||
tcp_l2_buf_fill_headers(conn, iov, NULL, seq, false);
|
||||
|
||||
if (flags & DUP_ACK) {
|
||||
struct iovec *dup_iov = tcp_l2_iov[tcp_payload_used++];
|
||||
|
@ -270,7 +268,7 @@ static void tcp_data_to_tap(const struct ctx *c, struct tcp_tap_conn *conn,
|
|||
payload->th.th_flags = 0;
|
||||
payload->th.ack = 1;
|
||||
iov[TCP_IOV_PAYLOAD].iov_len = dlen + sizeof(struct tcphdr);
|
||||
tcp_l2_buf_fill_headers(conn, iov, dlen, check, seq, false);
|
||||
tcp_l2_buf_fill_headers(conn, iov, check, seq, false);
|
||||
if (++tcp_payload_used > TCP_FRAMES_MEM - 1)
|
||||
tcp_payload_flush(c);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue