From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (mail.ozlabs.org [IPv6:2404:9400:2221:ea00::3]) by passt.top (Postfix) with ESMTPS id B67C55A026B for ; Thu, 8 Dec 2022 09:56:00 +0100 (CET) Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4NSSfy4Jflz4xmp; Thu, 8 Dec 2022 19:55:54 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=201602; t=1670489754; bh=egNJSi/oz8M2/ZY6vTQ+woOtUakeHXihYJ28HanS7UY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=UozfauJ1bPI85AyniCBHThuVA54MHBu1wNmS716RBhtn1FlKAPma2ujRaBDtWYM3c prlWvT2ql49ZMovPwYQBGAyQS/Q3dXyuEzCEm9aAKUItdywLeiap7EViviZdaOqqLh zFVNkP9A0kn+dSvAY/YfKTbM7ezfJq2PDB5LbVv4= From: David Gibson To: Stefano Brivio , passt-dev@passt.top Subject: [PATCH 08/10] tcp,tap: Use different io vector bases depending on tap type Date: Thu, 8 Dec 2022 19:55:49 +1100 Message-Id: <20221208085551.1433829-9-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.38.1 In-Reply-To: <20221208085551.1433829-1-david@gibson.dropbear.id.au> References: <20221208085551.1433829-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: GEA2JP2WX2ZD6NNJLSCIFNYZHLNTR7GK X-Message-ID-Hash: GEA2JP2WX2ZD6NNJLSCIFNYZHLNTR7GK X-MailFrom: dgibson@gandalf.ozlabs.org X-Mailman-Rule-Misses: dmarc-mitigation; no-senders; approved; emergency; loop; banned-address; member-moderation; nonmember-moderation; administrivia; implicit-dest; max-recipients; max-size; news-moderation; no-subject; digests; suspicious-header CC: David Gibson X-Mailman-Version: 3.3.3 Precedence: list List-Id: Development discussion and patches for passt Archived-At: Archived-At: List-Archive: List-Archive: List-Help: List-Owner: List-Post: List-Subscribe: List-Unsubscribe: Currently tap_send_frames() expects the frames it is given to include the vnet_len field, even in pasta mode which doesn't use it (although it need not be initialized in that case). This will inconvenience future changes, so alter it to expect just the frame as appropriate for the tap backend type. We alter the TCP code which uses it to match, setting up the base of iovec to include or exclude the vnet_len as needed. Signed-off-by: David Gibson --- tap.c | 5 ++--- tcp.c | 30 ++++++++++++++++++++++-------- 2 files changed, 24 insertions(+), 11 deletions(-) diff --git a/tap.c b/tap.c index 558a734..2dd14f1 100644 --- a/tap.c +++ b/tap.c @@ -317,8 +317,7 @@ static void tap_send_frames_pasta(struct ctx *c, size_t i; for (i = 0; i < n; i++) { - if (write(c->fd_tap, (char *)iov->iov_base + 4, - iov->iov_len - 4) < 0) { + if (write(c->fd_tap, (char *)iov->iov_base, iov->iov_len) < 0) { debug("tap write: %s", strerror(errno)); if (errno != EAGAIN && errno != EWOULDBLOCK) tap_handler(c, c->fd_tap, EPOLLERR, NULL); @@ -383,7 +382,7 @@ void tap_send_frames(struct ctx *c, const struct iovec *iov, size_t n) else tap_send_frames_pasta(c, iov, n); - pcap_multiple(iov, n, sizeof(uint32_t)); + pcap_multiple(iov, n, c->mode == MODE_PASST ? sizeof(uint32_t) : 0); } PACKET_POOL_DECL(pool_l4, UIO_MAXIOV, pkt_buf); diff --git a/tcp.c b/tcp.c index f560b96..e5fa5ae 100644 --- a/tcp.c +++ b/tcp.c @@ -1053,8 +1053,9 @@ void tcp_update_l2_buf(const unsigned char *eth_d, const unsigned char *eth_s, /** * tcp_sock4_iov_init() - Initialise scatter-gather L2 buffers for IPv4 sockets + * @ctx: Execution context */ -static void tcp_sock4_iov_init(void) +static void tcp_sock4_iov_init(const struct ctx *c) { struct iovec *iov; int i; @@ -1076,18 +1077,25 @@ static void tcp_sock4_iov_init(void) } for (i = 0, iov = tcp4_l2_iov; i < TCP_FRAMES_MEM; i++, iov++) { - iov->iov_base = &tcp4_l2_buf[i].vnet_len; + if (c->mode == MODE_PASTA) + iov->iov_base = &tcp4_l2_buf[i].eh; + else + iov->iov_base = &tcp4_l2_buf[i].vnet_len; iov->iov_len = MSS_DEFAULT; } for (i = 0, iov = tcp4_l2_flags_iov; i < TCP_FRAMES_MEM; i++, iov++) - iov->iov_base = &tcp4_l2_flags_buf[i].vnet_len; + if (c->mode == MODE_PASTA) + iov->iov_base = &tcp4_l2_flags_buf[i].eh; + else + iov->iov_base = &tcp4_l2_flags_buf[i].vnet_len; } /** * tcp_sock6_iov_init() - Initialise scatter-gather L2 buffers for IPv6 sockets + * @ctx: Execution context */ -static void tcp_sock6_iov_init(void) +static void tcp_sock6_iov_init(const struct ctx *c) { struct iovec *iov; int i; @@ -1109,12 +1117,18 @@ static void tcp_sock6_iov_init(void) } for (i = 0, iov = tcp6_l2_iov; i < TCP_FRAMES_MEM; i++, iov++) { - iov->iov_base = &tcp6_l2_buf[i].vnet_len; + if (c->mode == MODE_PASTA) + iov->iov_base = &tcp6_l2_buf[i].eh; + else + iov->iov_base = &tcp6_l2_buf[i].vnet_len; iov->iov_len = MSS_DEFAULT; } for (i = 0, iov = tcp6_l2_flags_iov; i < TCP_FRAMES_MEM; i++, iov++) - iov->iov_base = &tcp6_l2_flags_buf[i].vnet_len; + if (c->mode == MODE_PASTA) + iov->iov_base = &tcp6_l2_flags_buf[i].eh; + else + iov->iov_base = &tcp6_l2_flags_buf[i].vnet_len; } /** @@ -3131,10 +3145,10 @@ int tcp_init(struct ctx *c) tcp_l2_mh[i] = (struct mmsghdr) { .msg_hdr.msg_iovlen = 1 }; if (c->ifi4) - tcp_sock4_iov_init(); + tcp_sock4_iov_init(c); if (c->ifi6) - tcp_sock6_iov_init(); + tcp_sock6_iov_init(c); memset(init_sock_pool4, 0xff, sizeof(init_sock_pool4)); memset(init_sock_pool6, 0xff, sizeof(init_sock_pool6)); -- 2.38.1