From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from gandalf.ozlabs.org (gandalf.ozlabs.org [150.107.74.76]) by passt.top (Postfix) with ESMTPS id 437FB5A027D for ; Tue, 6 Feb 2024 02:17:48 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gibson.dropbear.id.au; s=202312; t=1707182260; bh=+zxgDGt/cvMYCzS7EKfVn70Xo3InYLSTj3USusDo8pY=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Y3cbes4Y8V/dltqz2fafJlNQYkx5I8CJXhe9E+jEJ/skDlMOnYkIfvxoVMID9rOwQ a3JVh6IBOKFSZeuIxRFPGZip7TkIM2/V03XAXQyMqyJGWtwRvAvJ5Jbb7lro5VeyJV rn9zJxZFqN7nqztPh79pIA0GAVGL3e4nkjGX1WNUhUEwHvyCRdWoPqB+JHh7xnom1K lPKqEYRnq5h9He9+V+j984xzFWAbitXP7Jr4+HG0169/W5an22ZMDBUoGOtH3LcupG gooTmkFtge17BWx31yzPwY5iIm/P3rEcnFzbZrKODp/KCK92cV1I3tITJqmpmo/No8 K+HiPejEH9nhA== Received: by gandalf.ozlabs.org (Postfix, from userid 1007) id 4TTQN41nR4z4x0m; Tue, 6 Feb 2024 12:17:40 +1100 (AEDT) From: David Gibson To: passt-dev@passt.top, Stefano Brivio Subject: [PATCH v2 18/22] tcp, tcp_splice: Parse listening socket epoll ref in tcp_listen_handler() Date: Tue, 6 Feb 2024 12:17:30 +1100 Message-ID: <20240206011734.884138-19-david@gibson.dropbear.id.au> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240206011734.884138-1-david@gibson.dropbear.id.au> References: <20240206011734.884138-1-david@gibson.dropbear.id.au> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Message-ID-Hash: IJT6AIXVQG27KVCHRMTEE2MD3MZAXWV6 X-Message-ID-Hash: IJT6AIXVQG27KVCHRMTEE2MD3MZAXWV6 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.8 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: tcp_listen_handler() uses the epoll reference for the listening socket it handles, and also passes on one variant of it to tcp_tap_conn_from_sock() and tcp_splice_conn_from_sock(). The latter two functions only need a couple of specific fields from the reference. Pass those specific values instead of the whole reference, which localises the handling of the listening (as opposed to accepted) socket and its reference entirely within tcp_listen_handler(). Signed-off-by: David Gibson --- tcp.c | 12 ++++++------ tcp_splice.c | 12 +++++++----- tcp_splice.h | 5 +++-- 3 files changed, 16 insertions(+), 13 deletions(-) diff --git a/tcp.c b/tcp.c index d61fb17b..31d4e87b 100644 --- a/tcp.c +++ b/tcp.c @@ -2675,14 +2675,13 @@ static void tcp_snat_inbound(const struct ctx *c, union inany_addr *addr) /** * tcp_tap_conn_from_sock() - Initialize state for non-spliced connection * @c: Execution context - * @ref: epoll reference of listening socket + * @dstport: Destination port for connection (host side) * @flow: flow to initialise * @s: Accepted socket * @sa: Peer socket address (from accept()) * @now: Current timestamp */ -static void tcp_tap_conn_from_sock(struct ctx *c, - union tcp_listen_epoll_ref ref, +static void tcp_tap_conn_from_sock(struct ctx *c, in_port_t dstport, union flow *flow, int s, const union sockaddr_inany *sa, const struct timespec *now) @@ -2695,7 +2694,7 @@ static void tcp_tap_conn_from_sock(struct ctx *c, conn_event(c, conn, SOCK_ACCEPTED); inany_from_sockaddr(&conn->faddr, &conn->fport, sa); - conn->eport = ref.port + c->tcp.fwd_in.delta[ref.port]; + conn->eport = dstport + c->tcp.fwd_in.delta[dstport]; tcp_snat_inbound(c, &conn->faddr); @@ -2733,10 +2732,11 @@ void tcp_listen_handler(struct ctx *c, union epoll_ref ref, if (s < 0) goto cancel; - if (tcp_splice_conn_from_sock(c, ref.tcp_listen, flow, s, &sa)) + if (tcp_splice_conn_from_sock(c, ref.tcp_listen.pif, + ref.tcp_listen.port, flow, s, &sa)) return; - tcp_tap_conn_from_sock(c, ref.tcp_listen, flow, s, &sa, now); + tcp_tap_conn_from_sock(c, ref.tcp_listen.port, flow, s, &sa, now); return; cancel: diff --git a/tcp_splice.c b/tcp_splice.c index 1937850f..97eecc5b 100644 --- a/tcp_splice.c +++ b/tcp_splice.c @@ -387,7 +387,8 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn, /** * tcp_splice_conn_from_sock() - Attempt to init state for a spliced connection * @c: Execution context - * @ref: epoll reference of listening socket + * @pif0: pif id of side 0 + * @dstport: Side 0 destination port of connection * @flow: flow to initialise * @s0: Accepted (side 0) socket * @sa: Peer address of connection @@ -396,12 +397,13 @@ static int tcp_splice_connect(const struct ctx *c, struct tcp_splice_conn *conn, * #syscalls:pasta setsockopt */ bool tcp_splice_conn_from_sock(const struct ctx *c, - union tcp_listen_epoll_ref ref, union flow *flow, - int s0, const union sockaddr_inany *sa) + uint8_t pif0, in_port_t dstport, + union flow *flow, int s0, + const union sockaddr_inany *sa) { - in_port_t srcport, dstport = ref.port; struct tcp_splice_conn *conn; union inany_addr src; + in_port_t srcport; sa_family_t af; uint8_t pif1; @@ -411,7 +413,7 @@ bool tcp_splice_conn_from_sock(const struct ctx *c, inany_from_sockaddr(&src, &srcport, sa); af = inany_v4(&src) ? AF_INET : AF_INET6; - switch (ref.pif) { + switch (pif0) { case PIF_SPLICE: if (!inany_is_loopback(&src)) { char str[INANY_ADDRSTRLEN]; diff --git a/tcp_splice.h b/tcp_splice.h index d0c6ff79..ed8f0c58 100644 --- a/tcp_splice.h +++ b/tcp_splice.h @@ -12,8 +12,9 @@ union sockaddr_inany; void tcp_splice_sock_handler(struct ctx *c, union epoll_ref ref, uint32_t events); bool tcp_splice_conn_from_sock(const struct ctx *c, - union tcp_listen_epoll_ref ref, union flow *flow, - int s0, const union sockaddr_inany *sa); + uint8_t pif0, in_port_t dstport, + union flow *flow, int s0, + const union sockaddr_inany *sa); void tcp_splice_init(struct ctx *c); #endif /* TCP_SPLICE_H */ -- 2.43.0